Eclipse SUMO - Simulation of Urban MObility
GNEInductionLoopDetector.cpp
Go to the documentation of this file.
1/****************************************************************************/
2// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3// Copyright (C) 2001-2022 German Aerospace Center (DLR) and others.
4// This program and the accompanying materials are made available under the
5// terms of the Eclipse Public License 2.0 which is available at
6// https://www.eclipse.org/legal/epl-2.0/
7// This Source Code may also be made available under the following Secondary
8// Licenses when the conditions for such availability set forth in the Eclipse
9// Public License 2.0 are satisfied: GNU General Public License, version 2
10// or later which is available at
11// https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
12// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
13/****************************************************************************/
18//
19/****************************************************************************/
20
21#include <netedit/GNENet.h>
22#include <netedit/GNEUndoList.h>
23#include <netedit/GNEViewNet.h>
29
32
33
34// ===========================================================================
35// member method definitions
36// ===========================================================================
37
40 0, {}, "", {}, "", false, Parameterised::Map()) {
41 // reset default values
42 resetDefaultValues();
43}
44
45
46GNEInductionLoopDetector::GNEInductionLoopDetector(const std::string& id, GNELane* lane, GNENet* net, const double pos,
47 const SUMOTime freq, const std::string& filename, const std::vector<std::string>& vehicleTypes,
48 const std::string& name, bool friendlyPos, const Parameterised::Map& parameters) :
50 freq, {
51 lane
52}, filename, vehicleTypes, name, friendlyPos, parameters) {
53 // update centering boundary without updating grid
54 updateCenteringBoundary(false);
55}
56
57
59}
60
61
62void
64 device.openTag(getTagProperty().getTag());
65 device.writeAttr(SUMO_ATTR_ID, getID());
66 if (!myAdditionalName.empty()) {
68 }
69 device.writeAttr(SUMO_ATTR_LANE, getParentLanes().front()->getID());
71 if (getAttribute(SUMO_ATTR_PERIOD).size() > 0) {
73 }
74 if (myFilename.size() > 0) {
76 }
77 if (myVehicleTypes.size() > 0) {
79 }
82 }
83 // write parameters (Always after children to avoid problems with additionals.xsd)
84 writeParams(device);
85 device.closeTag();
86}
87
88
89bool
91 // with friendly position enabled position are "always fixed"
93 return true;
94 } else {
95 return fabs(myPositionOverLane) <= getParentLanes().front()->getParentEdge()->getNBEdge()->getFinalLength();
96 }
97}
98
99
100std::string
102 // obtain final length
103 const double len = getParentLanes().front()->getParentEdge()->getNBEdge()->getFinalLength();
104 // check if detector has a problem
106 return "";
107 } else {
108 // declare variable for error position
109 std::string errorPosition;
110 // check positions over lane
111 if (myPositionOverLane < 0) {
112 errorPosition = (toString(SUMO_ATTR_POSITION) + " < 0");
113 }
114 if (myPositionOverLane > len) {
115 errorPosition = (toString(SUMO_ATTR_POSITION) + " > lanes's length");
116 }
117 return errorPosition;
118 }
119}
120
121
122void
124 // declare new position
125 double newPositionOverLane = myPositionOverLane;
126 // fix pos and length checkAndFixDetectorPosition
127 double length = 0;
128 GNEAdditionalHandler::fixLanePosition(newPositionOverLane, length, getParentLanes().front()->getParentEdge()->getNBEdge()->getFinalLength());
129 // set new position
131}
132
133
134void
136 // update geometry
138 // update centering boundary without updating grid
140}
141
142
143void
145 // first check if additional has to be drawn
147 // Obtain exaggeration of the draw
148 const double E1Exaggeration = getExaggeration(s);
149 // check exaggeration
150 if (s.drawAdditionals(E1Exaggeration)) {
151 // obtain scaledSize
152 const double scaledWidth = s.detectorSettings.E1Width * 0.5 * s.scale;
153 // declare colors
154 RGBColor mainColor, secondColor, textColor;
155 // set color
156 if (drawUsingSelectColor()) {
158 secondColor = mainColor.changedBrightness(-32);
159 textColor = mainColor.changedBrightness(32);
160 } else {
161 mainColor = s.detectorSettings.E1Color;
162 secondColor = RGBColor::WHITE;
163 textColor = RGBColor::BLACK;
164 }
165 // draw parent and child lines
167 // start drawing
169 // push layer matrix
171 // translate to front
173 // draw E1 shape
174 drawE1Shape(s, E1Exaggeration, scaledWidth, mainColor, secondColor);
175 // Check if the distance is enought to draw details
176 if (s.drawDetail(s.detailSettings.detectorDetails, E1Exaggeration)) {
177 // draw E1 Logo
178 drawDetectorLogo(s, E1Exaggeration, "E1", textColor);
179 }
180 // pop layer matrix
182 // Pop name
184 // draw lock icon
186 // check if mouse is over element
188 2, 1, 0, 0, myAdditionalGeometry.getShapeRotations().front());
189 // inspect contour
192 2, 1, 0, 0, myAdditionalGeometry.getShapeRotations().front(), E1Exaggeration);
193 }
194 // front contour
195 if (myNet->getViewNet()->getFrontAttributeCarrier() == this) {
197 2, 1, 0, 0, myAdditionalGeometry.getShapeRotations().front(), E1Exaggeration);
198 }
199 // delete contour
200 if (myNet->getViewNet()->drawDeleteContour(this, this)) {
202 2, 1, 0, 0, myAdditionalGeometry.getShapeRotations().front(), E1Exaggeration);
203 }
204 // select contour
205 if (myNet->getViewNet()->drawSelectContour(this, this)) {
207 2, 1, 0, 0, myAdditionalGeometry.getShapeRotations().front(), E1Exaggeration);
208 }
209 const auto& TLSAttributes = myNet->getViewNet()->getViewParent()->getTLSEditorFrame()->getTLSAttributes();
210 // check if orange dotted contour must be drawn
212 (TLSAttributes->getE1Detectors().count(getParentLanes().front()->getID()) > 0) &&
213 (TLSAttributes->getE1Detectors().at(getParentLanes().front()->getID()) == getID())) {
215 }
216 }
217 // Draw additional ID
219 // draw additional name
221 }
222}
223
224
225std::string
227 switch (key) {
228 case SUMO_ATTR_ID:
229 return getMicrosimID();
230 case SUMO_ATTR_LANE:
231 return getParentLanes().front()->getID();
234 case SUMO_ATTR_PERIOD:
236 return "";
237 } else {
238 return time2string(myPeriod);
239 }
240 case SUMO_ATTR_NAME:
241 return myAdditionalName;
242 case SUMO_ATTR_FILE:
243 return myFilename;
244 case SUMO_ATTR_VTYPES:
245 return toString(myVehicleTypes);
251 return getParametersStr();
253 return "";
254 default:
255 throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
256 }
257}
258
259
260double
262 switch (key) {
264 return myPositionOverLane;
265 default:
266 throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
267 }
268}
269
270
271void
272GNEInductionLoopDetector::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
273 switch (key) {
274 case SUMO_ATTR_ID:
275 case SUMO_ATTR_LANE:
277 case SUMO_ATTR_PERIOD:
278 case SUMO_ATTR_NAME:
279 case SUMO_ATTR_FILE:
280 case SUMO_ATTR_VTYPES:
285 undoList->changeAttribute(new GNEChange_Attribute(this, key, value));
286 break;
287 default:
288 throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
289 }
290}
291
292
293bool
294GNEInductionLoopDetector::isValid(SumoXMLAttr key, const std::string& value) {
295 switch (key) {
296 case SUMO_ATTR_ID:
297 return isValidDetectorID(value);
298 case SUMO_ATTR_LANE:
299 if (myNet->getAttributeCarriers()->retrieveLane(value, false) != nullptr) {
300 return true;
301 } else {
302 return false;
303 }
305 return canParse<double>(value) && fabs(parse<double>(value)) < getParentLanes().front()->getParentEdge()->getNBEdge()->getFinalLength();
306 case SUMO_ATTR_PERIOD:
307 if (value.empty()) {
308 return true;
309 } else {
310 return (canParse<double>(value) && (parse<double>(value) >= 0));
311 }
312 case SUMO_ATTR_NAME:
314 case SUMO_ATTR_FILE:
316 case SUMO_ATTR_VTYPES:
317 if (value.empty()) {
318 return true;
319 } else {
321 }
323 return canParse<bool>(value);
325 return canParse<bool>(value);
327 return areParametersValid(value);
328 default:
329 throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
330 }
331}
332
333// ===========================================================================
334// private
335// ===========================================================================
336
337void
339 switch (key) {
340 case SUMO_ATTR_ID:
341 // update microsimID
342 setMicrosimID(value);
343 break;
344 case SUMO_ATTR_LANE:
346 break;
348 myPositionOverLane = parse<double>(value);
349 break;
350 case SUMO_ATTR_PERIOD:
351 if (value.empty()) {
353 } else {
354 myPeriod = string2time(value);
355 }
356 break;
357 case SUMO_ATTR_FILE:
358 myFilename = value;
359 break;
360 case SUMO_ATTR_NAME:
361 myAdditionalName = value;
362 break;
363 case SUMO_ATTR_VTYPES:
364 myVehicleTypes = parse<std::vector<std::string> >(value);
365 break;
367 myFriendlyPosition = parse<bool>(value);
368 break;
370 if (parse<bool>(value)) {
372 } else {
374 }
375 break;
377 setParametersStr(value);
378 break;
381 break;
382 default:
383 throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
384 }
385}
386
387
388void
390 // change position
391 myPositionOverLane = moveResult.newFirstPos;
392 // set lateral offset
394 // update geometry
396}
397
398
399void
401 // reset lateral offset
403 // begin change attribute
404 undoList->begin(myTagProperty.getGUIIcon(), "position of " + getTagStr());
405 // set startPosition
406 setAttribute(SUMO_ATTR_POSITION, toString(moveResult.newFirstPos), undoList);
407 // check if lane has to be changed
408 if (moveResult.newFirstLane) {
409 // set new lane
410 setAttribute(SUMO_ATTR_LANE, moveResult.newFirstLane->getID(), undoList);
411 }
412 // end change attribute
413 undoList->end();
414}
415
416/****************************************************************************/
long long int SUMOTime
Definition: GUI.h:36
@ GLO_E1DETECTOR
a E1 detector
GUIIcon
An enumeration of icons used by the gui applications.
Definition: GUIIcons.h:33
std::string time2string(SUMOTime t)
convert SUMOTime to string
Definition: SUMOTime.cpp:68
SUMOTime string2time(const std::string &r)
convert string to SUMOTime
Definition: SUMOTime.cpp:45
#define SUMOTime_MAX_PERIOD
Definition: SUMOTime.h:35
@ SUMO_TAG_INDUCTION_LOOP
alternative tag for e1 detector
SumoXMLAttr
Numbers representing SUMO-XML - attributes.
@ SUMO_ATTR_LANE
@ SUMO_ATTR_FILE
@ GNE_ATTR_SELECTED
element is selected
@ GNE_ATTR_PARAMETERS
parameters "key1=value1|key2=value2|...|keyN=valueN"
@ SUMO_ATTR_VTYPES
@ SUMO_ATTR_NAME
@ SUMO_ATTR_PERIOD
@ SUMO_ATTR_FRIENDLY_POS
@ SUMO_ATTR_ID
@ SUMO_ATTR_POSITION
@ GNE_ATTR_SHIFTLANEINDEX
shift lane index (only used by elements over lanes)
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:46
static void pushName(unsigned int name)
push Name
Definition: GLHelper.cpp:139
static void popMatrix()
pop matrix
Definition: GLHelper.cpp:130
static void popName()
pop Name
Definition: GLHelper.cpp:148
static void pushMatrix()
push matrix
Definition: GLHelper.cpp:117
static bool checkLanePosition(double pos, const double length, const double laneLength, const bool friendlyPos)
check if the given position over a lane is valid
static void fixLanePosition(double &pos, double &length, const double laneLength)
fix given position over lane
GUIGeometry myAdditionalGeometry
geometry to be precomputed in updateGeometry(...)
void drawAdditionalID(const GUIVisualizationSettings &s) const
draw additional ID
void replaceAdditionalParentLanes(const std::string &value)
replace additional parent lanes
void shiftLaneIndex()
shift lane index
double getExaggeration(const GUIVisualizationSettings &s) const
return exaggeration associated with this GLObject
std::string myAdditionalName
name of additional
void drawAdditionalName(const GUIVisualizationSettings &s) const
draw additional name
bool isValidDetectorID(const std::string &newID) const
check if a new detector ID is valid
void drawParentChildLines(const GUIVisualizationSettings &s, const RGBColor &color, const bool onlySymbols=false) const
draw parent and child lines
const std::string getID() const
get ID (all Attribute Carriers have one)
bool isAttributeCarrierSelected() const
check if attribute carrier is selected
friend class GNEChange_Attribute
declare friend class
const std::string & getTagStr() const
get tag assigned to this object in string format
const GNETagProperties & getTagProperty() const
get tagProperty associated with this Attribute Carrier
void unselectAttributeCarrier(const bool changeFlag=true)
unselect attribute carrier using GUIGlobalSelection
bool drawUsingSelectColor() const
check if attribute carrier must be drawn using selecting color.
GNENet * myNet
pointer to net
void selectAttributeCarrier(const bool changeFlag=true)
select attribute carrier using GUIGlobalSelection
const GNETagProperties & myTagProperty
reference to tagProperty associated with this attribute carrier
SUMOTime myPeriod
The aggregation period the values the detector collects shall be summed up.
Definition: GNEDetector.h:175
std::string myFilename
The path to the output file.
Definition: GNEDetector.h:178
double myPositionOverLane
position of detector over Lane
Definition: GNEDetector.h:172
void drawE1Shape(const GUIVisualizationSettings &s, const double exaggeration, const double scaledWidth, const RGBColor &mainColor, const RGBColor &secondColor) const
draw E1 shape
double getGeometryPositionOverLane() const
get position over lane that is applicable to the shape
bool myFriendlyPosition
Flag for friendly position.
Definition: GNEDetector.h:184
void drawDetectorLogo(const GUIVisualizationSettings &s, const double exaggeration, const std::string &logo, const RGBColor &textColor) const
draw detector Logo
void updateCenteringBoundary(const bool updateGrid)
update centering boundary (implies change in RTREE)
std::vector< std::string > myVehicleTypes
attribute vehicle types
Definition: GNEDetector.h:181
const std::vector< GNELane * > & getParentLanes() const
get parent lanes
bool isValid(SumoXMLAttr key, const std::string &value)
method for checking if the key and their correspondent attribute are valids
void fixAdditionalProblem()
fix additional problem
void commitMoveShape(const GNEMoveResult &moveResult, GNEUndoList *undoList)
commit move shape
double getAttributeDouble(SumoXMLAttr key) const
void drawGL(const GUIVisualizationSettings &s) const
Draws the object.
GNEInductionLoopDetector(GNENet *net)
default constructor
void writeAdditional(OutputDevice &device) const
write additional element into a xml file
bool isAdditionalValid() const
check if current additional is valid to be writed into XML
void setMoveShape(const GNEMoveResult &moveResult)
set move shape
void updateGeometry()
update pre-computed geometry information
std::string getAttribute(SumoXMLAttr key) const
std::string getAdditionalProblem() const
return a string with the current additional problem
void setAttribute(SumoXMLAttr key, const std::string &value, GNEUndoList *undoList)
method for setting the attribute and letting the object perform additional changes
This lane is powered by an underlying GNEEdge and basically knows how to draw itself.
Definition: GNELane.h:46
double myMoveElementLateralOffset
move element lateral offset (used by elements placed over lanes
move result
const GNELane * newFirstLane
new first Lane
double newFirstPos
new first position
double firstLaneOffset
lane offset
GNELane * retrieveLane(const std::string &id, bool hardFail=true, bool checkVolatileChange=false) const
get lane by id
A NBNetBuilder extended by visualisation and editing capabilities.
Definition: GNENet.h:42
GNENetHelper::AttributeCarriers * getAttributeCarriers() const
get all attribute carriers used in this net
Definition: GNENet.cpp:132
GNEViewNet * getViewNet() const
get view net
Definition: GNENet.cpp:1987
GNETLSEditorFrame::TLSAttributes * getTLSAttributes() const
get module for TLS attributes
GUIIcon getGUIIcon() const
get GUI icon associated to this Tag
void end()
End undo command sub-group. If the sub-group is still empty, it will be deleted; otherwise,...
void begin(GUIIcon icon, const std::string &description)
Begin undo command sub-group with current supermode. This begins a new group of commands that are tre...
void changeAttribute(GNEChange_Attribute *change)
special method for change attributes, avoid empty changes, always execute
const GNEViewNetHelper::DataViewOptions & getDataViewOptions() const
get data view options
Definition: GNEViewNet.cpp:656
const GNEAttributeCarrier * getFrontAttributeCarrier() const
get front attributeCarrier
bool drawSelectContour(const GUIGlObject *GLObject, const GNEAttributeCarrier *AC) const
check if draw select contour
bool drawDeleteContour(const GUIGlObject *GLObject, const GNEAttributeCarrier *AC) const
check if draw delete contour
void drawTranslateFrontAttributeCarrier(const GNEAttributeCarrier *AC, double typeOrLayer, const double extraOffset=0)
draw front attributeCarrier
GNEViewParent * getViewParent() const
get the net object
GNEUndoList * getUndoList() const
get the undoList object
bool isAttributeCarrierInspected(const GNEAttributeCarrier *AC) const
check if attribute carrier is being inspected
bool selectingDetectorsTLSMode() const
check if we're selecting detectors in TLS mode
Definition: GNEViewNet.cpp:874
GNETLSEditorFrame * getTLSEditorFrame() const
get frame for NETWORK_TLS
static void drawDottedSquaredShape(const GUIVisualizationSettings &s, const DottedContourType type, const Position &pos, const double width, const double height, const double offsetX, const double offsetY, const double rot, const double exaggeration)
draw dotted squared contour (used by additionals and demand elements)
const std::vector< double > & getShapeRotations() const
The rotations of the single shape parts.
const PositionVector & getShape() const
The shape of the additional element.
void updateGeometry(const PositionVector &shape)
update entire geometry
Definition: GUIGeometry.cpp:58
const std::string & getMicrosimID() const
Returns the id of the object as known to microsim.
Definition: GUIGlObject.h:141
virtual void setMicrosimID(const std::string &newID)
Changes the microsimID of the object.
void mouseWithinGeometry(const Position center, const double radius) const
check if mouse is within elements geometry (for circles)
GUIGlObjectType getType() const
Returns the type of the object as coded in GUIGlObjectType.
Definition: GUIGlObject.h:154
GUIGlID getGlID() const
Returns the numerical id of the object.
Definition: GUIGlObject.h:102
Stores the information about how to visualize structures.
GUIVisualizationDetailSettings detailSettings
detail settings
bool drawAdditionals(const double exaggeration) const
check if additionals must be drawn
GUIVisualizationColorSettings colorSettings
color settings
double scale
information about a lane's width (temporary, used for a single view)
bool drawDetail(const double detail, const double exaggeration) const
check if details can be drawn for the given GUIVisualizationDetailSettings and current scale and exxa...
GUIVisualizationAdditionalSettings additionalSettings
Additional settings.
GUIVisualizationDetectorSettings detectorSettings
Detector settings.
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:61
OutputDevice & writeAttr(const SumoXMLAttr attr, const T &val)
writes a named attribute
Definition: OutputDevice.h:251
OutputDevice & openTag(const std::string &xmlElement)
Opens an XML tag.
bool closeTag(const std::string &comment="")
Closes the most recently opened tag and optionally adds a comment.
static bool areParametersValid(const std::string &value, bool report=false, const std::string kvsep="=", const std::string sep="|")
check if given string can be parsed to a parameters map "key1=value1|key2=value2|....
std::map< std::string, std::string > Map
parameters map
Definition: Parameterised.h:45
void setParametersStr(const std::string &paramsString, const std::string kvsep="=", const std::string sep="|")
set the inner key/value map in string format "key1=value1|key2=value2|...|keyN=valueN"
void writeParams(OutputDevice &device) const
write Params in the given outputdevice
std::string getParametersStr(const std::string kvsep="=", const std::string sep="|") const
Returns the inner key/value map in string format "key1=value1|key2=value2|...|keyN=valueN".
Position getCentroid() const
Returns the centroid (closes the polygon if unclosed)
static const RGBColor WHITE
Definition: RGBColor.h:192
static const RGBColor BLACK
Definition: RGBColor.h:193
RGBColor changedBrightness(int change, int toChange=3) const
Returns a new color with altered brightness.
Definition: RGBColor.cpp:200
static bool isValidFilename(const std::string &value)
whether the given string is a valid attribute for a filename (for example, a name)
static bool isValidListOfTypeID(const std::string &value)
whether the given string is a valid list of ids for an edge or vehicle type (empty aren't allowed)
static bool isValidAttribute(const std::string &value)
whether the given string is a valid attribute for a certain key (for example, a name)
static std::string escapeXML(const std::string &orig, const bool maskDoubleHyphen=false)
Replaces the standard escapes by their XML entities.
bool showAdditionals() const
check if additionals has to be drawn
static void drawLockIcon(const GNEAttributeCarrier *AC, GUIGlObjectType type, const Position viewPosition, const double exaggeration, const double size=0.5, const double offsetx=0, const double offsety=0)
draw lock icon
static const RGBColor connectionColor
connection color
RGBColor selectedAdditionalColor
additional selection color (busStops, Detectors...)
static const double detectorDetails
details for detectors
static const RGBColor E1Color
color for E1 detectors
static const double E1Width
E1 detector widths.