Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
GNEInstantInductionLoopDetector.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, 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
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) + TL(" > 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 // avoid draw invisible elements
162 if (mainColor.alpha() != 0) {
163 // draw parent and child lines
165 // start drawing
167 // push layer matrix
169 // translate to front
171 // draw E1Instant shape
172 drawE1Shape(s, E1InstantExaggeration, scaledWidth, mainColor, secondColor);
173 // Check if the distance is enought to draw details
174 if (s.drawDetail(s.detailSettings.detectorDetails, E1InstantExaggeration)) {
175 // draw E1 Logo
176 drawE1DetectorLogo(s, E1InstantExaggeration, "E1", textColor);
177 }
178 // pop layer matrix
180 // Pop name
182 // draw lock icon
184 }
185 // check if mouse is over element
188 // inspect contour
191 2, 1, 0, 0, myAdditionalGeometry.getShapeRotations().front(), E1InstantExaggeration);
192 }
193 // front element contour
194 if (myNet->getViewNet()->getFrontAttributeCarrier() == this) {
196 2, 1, 0, 0, myAdditionalGeometry.getShapeRotations().front(), E1InstantExaggeration);
197 }
198 // delete contour
199 if (myNet->getViewNet()->drawDeleteContour(this, this)) {
201 2, 1, 0, 0, myAdditionalGeometry.getShapeRotations().front(), E1InstantExaggeration);
202 }
203 // select contour
204 if (myNet->getViewNet()->drawSelectContour(this, this)) {
206 2, 1, 0, 0, myAdditionalGeometry.getShapeRotations().front(), E1InstantExaggeration);
207 }
208 }
209 // Draw additional ID
211 // draw additional name
213 }
214}
215
216
217std::string
219 switch (key) {
220 case SUMO_ATTR_ID:
221 return getMicrosimID();
222 case SUMO_ATTR_LANE:
223 return getParentLanes().front()->getID();
226 case SUMO_ATTR_NAME:
227 return myAdditionalName;
228 case SUMO_ATTR_FILE:
229 return myFilename;
230 case SUMO_ATTR_VTYPES:
231 return toString(myVehicleTypes);
237 return getParametersStr();
239 return "";
240 default:
241 throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
242 }
243}
244
245
246double
248 switch (key) {
250 return myPositionOverLane;
251 default:
252 throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
253 }
254}
255
256
257void
259 switch (key) {
260 case SUMO_ATTR_ID:
261 case SUMO_ATTR_LANE:
263 case SUMO_ATTR_NAME:
264 case SUMO_ATTR_FILE:
265 case SUMO_ATTR_VTYPES:
270 undoList->changeAttribute(new GNEChange_Attribute(this, key, value));
271 break;
272 default:
273 throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
274 }
275
276}
277
278
279bool
281 switch (key) {
282 case SUMO_ATTR_ID:
283 return isValidDetectorID(value);
284 case SUMO_ATTR_LANE:
285 if (myNet->getAttributeCarriers()->retrieveLane(value, false) != nullptr) {
286 return true;
287 } else {
288 return false;
289 }
291 return canParse<double>(value) && fabs(parse<double>(value)) < getParentLanes().front()->getParentEdge()->getNBEdge()->getFinalLength();
292 case SUMO_ATTR_NAME:
294 case SUMO_ATTR_FILE:
296 case SUMO_ATTR_VTYPES:
297 if (value.empty()) {
298 return true;
299 } else {
301 }
303 return canParse<bool>(value);
305 return canParse<bool>(value);
307 return areParametersValid(value);
308 default:
309 throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
310 }
311}
312
313// ===========================================================================
314// private
315// ===========================================================================
316
317void
319 switch (key) {
320 case SUMO_ATTR_ID:
321 // update microsimID
322 setMicrosimID(value);
323 break;
324 case SUMO_ATTR_LANE:
326 break;
328 myPositionOverLane = parse<double>(value);
329 break;
330 case SUMO_ATTR_NAME:
331 myAdditionalName = value;
332 break;
333 case SUMO_ATTR_FILE:
334 myFilename = value;
335 break;
336 case SUMO_ATTR_VTYPES:
337 myVehicleTypes = parse<std::vector<std::string> >(value);
338 break;
340 myFriendlyPosition = parse<bool>(value);
341 break;
343 if (parse<bool>(value)) {
345 } else {
347 }
348 break;
350 setParametersStr(value);
351 break;
354 break;
355 default:
356 throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
357 }
358}
359
360
361void
363 // change position
364 myPositionOverLane = moveResult.newFirstPos;
365 // set lateral offset
367 // update geometry
369}
370
371
372void
374 // reset lateral offset
376 // begin change attribute
377 undoList->begin(myTagProperty.getGUIIcon(), "position of " + getTagStr());
378 // set startPosition
379 setAttribute(SUMO_ATTR_POSITION, toString(moveResult.newFirstPos), undoList);
380 // check if lane has to be changed
381 if (moveResult.newFirstLane) {
382 // set new lane
383 setAttribute(SUMO_ATTR_LANE, moveResult.newFirstLane->getID(), undoList);
384 }
385 // end change attribute
386 undoList->end();
387}
388
389/****************************************************************************/
@ GLO_E1DETECTOR_INSTANT
a E1 detector
GUIIcon
An enumeration of icons used by the gui applications.
Definition GUIIcons.h:33
#define TL(string)
Definition MsgHandler.h:287
@ 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
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)
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
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:120
GNEViewNet * getViewNet() const
get view net
Definition GNENet.cpp:2030
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
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
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 double E1InstantWidth
E1 Instant detector widths.
static const RGBColor E1InstantColor
color for E1 Instant detectors