Eclipse SUMO - Simulation of Urban MObility
GNEInstantInductionLoopDetector.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, 0, {}, "", {}, "", false, Parameterised::Map()) {
41 // reset default values
42 resetDefaultValues();
43}
44
45
46GNEInstantInductionLoopDetector::GNEInstantInductionLoopDetector(const std::string& id, GNELane* lane, GNENet* net, const double pos, const std::string& filename, const std::vector<std::string>& vehicleTypes,
47 const std::string& name, const bool friendlyPos, const Parameterised::Map& parameters) :
49 pos, 0, {
50 lane
51}, filename, vehicleTypes, name, friendlyPos, parameters) {
52 // update centering boundary without updating grid
53 updateCenteringBoundary(false);
54}
55
56
58}
59
60
61void
63 device.openTag(getTagProperty().getTag());
64 device.writeAttr(SUMO_ATTR_ID, getID());
65 if (!myAdditionalName.empty()) {
67 }
68 device.writeAttr(SUMO_ATTR_LANE, getParentLanes().front()->getID());
70 if (myFilename.size() > 0) {
72 }
73 if (myVehicleTypes.size() > 0) {
75 }
78 }
79 // write parameters (Always after children to avoid problems with additionals.xsd)
80 writeParams(device);
81 device.closeTag();
82}
83
84
85bool
87 // with friendly position enabled position are "always fixed"
89 return true;
90 } else {
91 return fabs(myPositionOverLane) <= getParentLanes().front()->getParentEdge()->getNBEdge()->getFinalLength();
92 }
93}
94
95
96std::string
98 // obtain final length
99 const double len = getParentLanes().front()->getParentEdge()->getNBEdge()->getFinalLength();
100 // check if detector has a problem
102 return "";
103 } else {
104 // declare variable for error position
105 std::string errorPosition;
106 // check positions over lane
107 if (myPositionOverLane < 0) {
108 errorPosition = (toString(SUMO_ATTR_POSITION) + " < 0");
109 }
110 if (myPositionOverLane > len) {
111 errorPosition = (toString(SUMO_ATTR_POSITION) + " > lanes's length");
112 }
113 return errorPosition;
114 }
115}
116
117
118void
120 // declare new position
121 double newPositionOverLane = myPositionOverLane;
122 // fix pos and length checkAndFixDetectorPosition
123 double length = 0;
124 GNEAdditionalHandler::fixLanePosition(newPositionOverLane, length, getParentLanes().front()->getParentEdge()->getNBEdge()->getFinalLength());
125 // set new position
127}
128
129
130void
132 // update geometry
134 // update centering boundary without updating grid
136}
137
138
139void
141 // check if additional has to be drawn
143 // Obtain exaggeration of the draw
144 const double E1InstantExaggeration = getExaggeration(s);
145 // check exaggeration
146 if (s.drawAdditionals(E1InstantExaggeration)) {
147 // obtain scaledSize
148 const double scaledWidth = s.detectorSettings.E1InstantWidth * 0.5 * s.scale;
149 // declare colors
150 RGBColor mainColor, secondColor, textColor;
151 // set color
152 if (drawUsingSelectColor()) {
154 secondColor = mainColor.changedBrightness(-32);
155 textColor = mainColor.changedBrightness(32);
156 } else {
157 mainColor = s.detectorSettings.E1InstantColor;
158 secondColor = RGBColor::WHITE;
159 textColor = RGBColor::BLACK;
160 }
161 // draw parent and child lines
163 // start drawing
165 // push layer matrix
167 // translate to front
169 // draw E1Instant shape
170 drawE1Shape(s, E1InstantExaggeration, scaledWidth, mainColor, secondColor);
171 // Check if the distance is enought to draw details
172 if (s.drawDetail(s.detailSettings.detectorDetails, E1InstantExaggeration)) {
173 // draw E1 Logo
174 drawDetectorLogo(s, E1InstantExaggeration, "E1", textColor);
175 }
176 // pop layer matrix
178 // Pop name
180 // draw lock icon
182 // check if mouse is over element
185 // inspect contour
188 2, 1, 0, 0, myAdditionalGeometry.getShapeRotations().front(), E1InstantExaggeration);
189 }
190 // front element contour
191 if (myNet->getViewNet()->getFrontAttributeCarrier() == this) {
193 2, 1, 0, 0, myAdditionalGeometry.getShapeRotations().front(), E1InstantExaggeration);
194 }
195 // delete contour
196 if (myNet->getViewNet()->drawDeleteContour(this, this)) {
198 2, 1, 0, 0, myAdditionalGeometry.getShapeRotations().front(), E1InstantExaggeration);
199 }
200 // select contour
201 if (myNet->getViewNet()->drawSelectContour(this, this)) {
203 2, 1, 0, 0, myAdditionalGeometry.getShapeRotations().front(), E1InstantExaggeration);
204 }
205 }
206 // Draw additional ID
208 // draw additional name
210 }
211}
212
213
214std::string
216 switch (key) {
217 case SUMO_ATTR_ID:
218 return getMicrosimID();
219 case SUMO_ATTR_LANE:
220 return getParentLanes().front()->getID();
223 case SUMO_ATTR_NAME:
224 return myAdditionalName;
225 case SUMO_ATTR_FILE:
226 return myFilename;
227 case SUMO_ATTR_VTYPES:
228 return toString(myVehicleTypes);
234 return getParametersStr();
236 return "";
237 default:
238 throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
239 }
240}
241
242
243double
245 switch (key) {
247 return myPositionOverLane;
248 default:
249 throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
250 }
251}
252
253
254void
256 switch (key) {
257 case SUMO_ATTR_ID:
258 case SUMO_ATTR_LANE:
260 case SUMO_ATTR_NAME:
261 case SUMO_ATTR_FILE:
262 case SUMO_ATTR_VTYPES:
267 undoList->changeAttribute(new GNEChange_Attribute(this, key, value));
268 break;
269 default:
270 throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
271 }
272
273}
274
275
276bool
278 switch (key) {
279 case SUMO_ATTR_ID:
280 return isValidDetectorID(value);
281 case SUMO_ATTR_LANE:
282 if (myNet->getAttributeCarriers()->retrieveLane(value, false) != nullptr) {
283 return true;
284 } else {
285 return false;
286 }
288 return canParse<double>(value) && fabs(parse<double>(value)) < getParentLanes().front()->getParentEdge()->getNBEdge()->getFinalLength();
289 case SUMO_ATTR_NAME:
291 case SUMO_ATTR_FILE:
293 case SUMO_ATTR_VTYPES:
294 if (value.empty()) {
295 return true;
296 } else {
298 }
300 return canParse<bool>(value);
302 return canParse<bool>(value);
304 return areParametersValid(value);
305 default:
306 throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
307 }
308}
309
310// ===========================================================================
311// private
312// ===========================================================================
313
314void
316 switch (key) {
317 case SUMO_ATTR_ID:
318 // update microsimID
319 setMicrosimID(value);
320 break;
321 case SUMO_ATTR_LANE:
323 break;
325 myPositionOverLane = parse<double>(value);
326 break;
327 case SUMO_ATTR_NAME:
328 myAdditionalName = value;
329 break;
330 case SUMO_ATTR_FILE:
331 myFilename = value;
332 break;
333 case SUMO_ATTR_VTYPES:
334 myVehicleTypes = parse<std::vector<std::string> >(value);
335 break;
337 myFriendlyPosition = parse<bool>(value);
338 break;
340 if (parse<bool>(value)) {
342 } else {
344 }
345 break;
347 setParametersStr(value);
348 break;
351 break;
352 default:
353 throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
354 }
355}
356
357
358void
360 // change position
361 myPositionOverLane = moveResult.newFirstPos;
362 // set lateral offset
364 // update geometry
366}
367
368
369void
371 // reset lateral offset
373 // begin change attribute
374 undoList->begin(myTagProperty.getGUIIcon(), "position of " + getTagStr());
375 // set startPosition
376 setAttribute(SUMO_ATTR_POSITION, toString(moveResult.newFirstPos), undoList);
377 // check if lane has to be changed
378 if (moveResult.newFirstLane) {
379 // set new lane
380 setAttribute(SUMO_ATTR_LANE, moveResult.newFirstLane->getID(), undoList);
381 }
382 // end change attribute
383 undoList->end();
384}
385
386/****************************************************************************/
@ GLO_E1DETECTOR_INSTANT
a E1 detector
GUIIcon
An enumeration of icons used by the gui applications.
Definition: GUIIcons.h:33
@ SUMO_TAG_INSTANT_INDUCTION_LOOP
An instantenous induction loop.
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_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
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
double getAttributeDouble(SumoXMLAttr key) const
GNEInstantInductionLoopDetector(GNENet *net)
default Constructor
void setMoveShape(const GNEMoveResult &moveResult)
set move shape
bool isAdditionalValid() const
check if current additional is valid to be writed into XML
void setAttribute(SumoXMLAttr key, const std::string &value, GNEUndoList *undoList)
method for setting the attribute and letting the object perform additional changes
void drawGL(const GUIVisualizationSettings &s) const
Draws the object.
void commitMoveShape(const GNEMoveResult &moveResult, GNEUndoList *undoList)
commit move shape
std::string getAdditionalProblem() const
return a string with the current additional problem
bool isValid(SumoXMLAttr key, const std::string &value)
method for checking if the key and their correspondent attribute are valids
void updateGeometry()
update pre-computed geometry information
std::string getAttribute(SumoXMLAttr key) const
void writeAdditional(OutputDevice &device) const
write additional element into a xml file
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
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
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
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 double E1InstantWidth
E1 Instant detector widths.
static const RGBColor E1InstantColor
color for E1 Instant detectors