Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
GNEInductionLoopDetector.cpp
Go to the documentation of this file.
1/****************************************************************************/
2// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3// Copyright (C) 2001-2023 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
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) + TL(" > 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 // avoid draw invisible elements
166 if (mainColor.alpha() != 0) {
167 // draw parent and child lines
169 // start drawing
171 // push layer matrix
173 // translate to front
175 // draw E1 shape
176 drawE1Shape(s, E1Exaggeration, scaledWidth, mainColor, secondColor);
177 // Check if the distance is enought to draw details
178 if (s.drawDetail(s.detailSettings.detectorDetails, E1Exaggeration)) {
179 // draw E1 Logo
180 drawE1DetectorLogo(s, E1Exaggeration, "E1", textColor);
181 }
182 // pop layer matrix
184 // Pop name
186 // draw lock icon
188 }
189 // check if mouse is over element
191 2, 1, 0, 0, myAdditionalGeometry.getShapeRotations().front());
192 // inspect contour
195 2, 1, 0, 0, myAdditionalGeometry.getShapeRotations().front(), E1Exaggeration);
196 }
197 // front contour
198 if (myNet->getViewNet()->getFrontAttributeCarrier() == this) {
200 2, 1, 0, 0, myAdditionalGeometry.getShapeRotations().front(), E1Exaggeration);
201 }
202 // delete contour
203 if (myNet->getViewNet()->drawDeleteContour(this, this)) {
205 2, 1, 0, 0, myAdditionalGeometry.getShapeRotations().front(), E1Exaggeration);
206 }
207 // select contour
208 if (myNet->getViewNet()->drawSelectContour(this, this)) {
210 2, 1, 0, 0, myAdditionalGeometry.getShapeRotations().front(), E1Exaggeration);
211 }
212 const auto& TLSAttributes = myNet->getViewNet()->getViewParent()->getTLSEditorFrame()->getTLSAttributes();
213 // check if orange dotted contour must be drawn
215 (TLSAttributes->getE1Detectors().count(getParentLanes().front()->getID()) > 0) &&
216 (TLSAttributes->getE1Detectors().at(getParentLanes().front()->getID()) == getID())) {
218 }
219 }
220 // Draw additional ID
222 // draw additional name
224 }
225}
226
227
228std::string
230 switch (key) {
231 case SUMO_ATTR_ID:
232 return getMicrosimID();
233 case SUMO_ATTR_LANE:
234 return getParentLanes().front()->getID();
237 case SUMO_ATTR_PERIOD:
239 return "";
240 } else {
241 return time2string(myPeriod);
242 }
243 case SUMO_ATTR_NAME:
244 return myAdditionalName;
245 case SUMO_ATTR_FILE:
246 return myFilename;
247 case SUMO_ATTR_VTYPES:
248 return toString(myVehicleTypes);
254 return getParametersStr();
256 return "";
257 default:
258 throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
259 }
260}
261
262
263double
265 switch (key) {
267 return myPositionOverLane;
268 default:
269 throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
270 }
271}
272
273
274void
275GNEInductionLoopDetector::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
276 switch (key) {
277 case SUMO_ATTR_ID:
278 case SUMO_ATTR_LANE:
280 case SUMO_ATTR_PERIOD:
281 case SUMO_ATTR_NAME:
282 case SUMO_ATTR_FILE:
283 case SUMO_ATTR_VTYPES:
288 undoList->changeAttribute(new GNEChange_Attribute(this, key, value));
289 break;
290 default:
291 throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
292 }
293}
294
295
296bool
297GNEInductionLoopDetector::isValid(SumoXMLAttr key, const std::string& value) {
298 switch (key) {
299 case SUMO_ATTR_ID:
300 return isValidDetectorID(value);
301 case SUMO_ATTR_LANE:
302 if (myNet->getAttributeCarriers()->retrieveLane(value, false) != nullptr) {
303 return true;
304 } else {
305 return false;
306 }
308 return canParse<double>(value) && fabs(parse<double>(value)) < getParentLanes().front()->getParentEdge()->getNBEdge()->getFinalLength();
309 case SUMO_ATTR_PERIOD:
310 if (value.empty()) {
311 return true;
312 } else {
313 return (canParse<double>(value) && (parse<double>(value) >= 0));
314 }
315 case SUMO_ATTR_NAME:
317 case SUMO_ATTR_FILE:
319 case SUMO_ATTR_VTYPES:
320 if (value.empty()) {
321 return true;
322 } else {
324 }
326 return canParse<bool>(value);
328 return canParse<bool>(value);
330 return areParametersValid(value);
331 default:
332 throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
333 }
334}
335
336// ===========================================================================
337// private
338// ===========================================================================
339
340void
342 switch (key) {
343 case SUMO_ATTR_ID:
344 // update microsimID
345 setMicrosimID(value);
346 break;
347 case SUMO_ATTR_LANE:
349 break;
351 myPositionOverLane = parse<double>(value);
352 break;
353 case SUMO_ATTR_PERIOD:
354 if (value.empty()) {
356 } else {
357 myPeriod = string2time(value);
358 }
359 break;
360 case SUMO_ATTR_FILE:
361 myFilename = value;
362 break;
363 case SUMO_ATTR_NAME:
364 myAdditionalName = value;
365 break;
366 case SUMO_ATTR_VTYPES:
367 myVehicleTypes = parse<std::vector<std::string> >(value);
368 break;
370 myFriendlyPosition = parse<bool>(value);
371 break;
373 if (parse<bool>(value)) {
375 } else {
377 }
378 break;
380 setParametersStr(value);
381 break;
384 break;
385 default:
386 throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
387 }
388}
389
390
391void
393 // change position
394 myPositionOverLane = moveResult.newFirstPos;
395 // set lateral offset
397 // update geometry
399}
400
401
402void
404 // reset lateral offset
406 // begin change attribute
407 undoList->begin(myTagProperty.getGUIIcon(), "position of " + getTagStr());
408 // set startPosition
409 setAttribute(SUMO_ATTR_POSITION, toString(moveResult.newFirstPos), undoList);
410 // check if lane has to be changed
411 if (moveResult.newFirstLane) {
412 // set new lane
413 setAttribute(SUMO_ATTR_LANE, moveResult.newFirstLane->getID(), undoList);
414 }
415 // end change attribute
416 undoList->end();
417}
418
419/****************************************************************************/
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
#define TL(string)
Definition MsgHandler.h:287
SUMOTime string2time(const std::string &r)
convert string to SUMOTime
Definition SUMOTime.cpp:46
std::string time2string(SUMOTime t, bool humanReadable)
convert SUMOTime to string (independently of global format setting)
Definition SUMOTime.cpp:69
#define SUMOTime_MAX_PERIOD
Definition SUMOTime.h:36
@ 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
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
the function-object for an editing operation (abstract base)
SUMOTime myPeriod
The aggregation period the values the detector collects shall be summed up.
std::string myFilename
The path to the output file.
double myPositionOverLane
position of detector over Lane
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
void drawE1DetectorLogo(const GUIVisualizationSettings &s, const double exaggeration, const std::string &logo, const RGBColor &textColor) const
draw E1 detector Logo
bool myFriendlyPosition
Flag for friendly position.
void updateCenteringBoundary(const bool updateGrid)
update centering boundary (implies change in RTREE)
std::vector< std::string > myVehicleTypes
attribute vehicle types
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:120
GNEViewNet * getViewNet() const
get view net
Definition GNENet.cpp:2030
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
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
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
const std::string & getMicrosimID() const
Returns the id of the object as known to microsim.
virtual void setMicrosimID(const std::string &newID)
Changes the microsimID of the object.
GUIGlObjectType getType() const
Returns the type of the object as coded in GUIGlObjectType.
bool mouseWithinGeometry(const Position center, const double radius) const
check if mouse is within elements geometry (for circles)
GUIGlID getGlID() const
Returns the numerical id of the object.
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.
OutputDevice & writeAttr(const SumoXMLAttr attr, const T &val)
writes a named attribute
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
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
unsigned char alpha() const
Returns the alpha-amount of the color.
Definition RGBColor.cpp:92
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.