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-2024 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::vector<std::string>& nextEdges, const std::string& detectPersons, const std::string& name,
49 const bool friendlyPos, const Parameterised::Map& parameters) :
51 lane
52}, filename, vehicleTypes, nextEdges, detectPersons, 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 device.writeAttr(SUMO_ATTR_LANE, getParentLanes().front()->getID());
68 // write common parameters
69 writeDetectorValues(device);
70 // write parameters (Always after children to avoid problems with additionals.xsd)
71 writeParams(device);
72 device.closeTag();
73}
74
75
76bool
78 // with friendly position enabled position are "always fixed"
80 return true;
81 } else {
82 return fabs(myPositionOverLane) <= getParentLanes().front()->getParentEdge()->getNBEdge()->getFinalLength();
83 }
84}
85
86
87std::string
89 // obtain final length
90 const double len = getParentLanes().front()->getParentEdge()->getNBEdge()->getFinalLength();
91 // check if detector has a problem
93 return "";
94 } else {
95 // declare variable for error position
96 std::string errorPosition;
97 // check positions over lane
98 if (myPositionOverLane < 0) {
99 errorPosition = (toString(SUMO_ATTR_POSITION) + " < 0");
100 }
101 if (myPositionOverLane > len) {
102 errorPosition = (toString(SUMO_ATTR_POSITION) + TL(" > lanes's length"));
103 }
104 return errorPosition;
105 }
106}
107
108
109void
111 // declare new position
112 double newPositionOverLane = myPositionOverLane;
113 // fix pos and length checkAndFixDetectorPosition
114 double length = 0;
115 GNEAdditionalHandler::fixLanePosition(newPositionOverLane, length, getParentLanes().front()->getParentEdge()->getNBEdge()->getFinalLength());
116 // set new position
118}
119
120
121void
123 // update geometry
125 // update centering boundary without updating grid
127}
128
129
130bool
132 // get TLS Attributes
133 const auto& TLSAttributes = myNet->getViewNet()->getViewParent()->getTLSEditorFrame()->getTLSAttributes();
134 // check detectors
136 (TLSAttributes->getE1Detectors().count(getParentLanes().front()->getID()) > 0) &&
137 (TLSAttributes->getE1Detectors().at(getParentLanes().front()->getID()) == getID())) {
138 return true;
139 } else {
140 return false;
141 }
142}
143
144
145void
147 // first check if additional has to be drawn
149 // Obtain exaggeration of the draw
150 const double E1Exaggeration = getExaggeration(s);
151 // get detail level
152 const auto d = s.getDetailLevel(E1Exaggeration);
153 // draw geometry only if we'rent in drawForObjectUnderCursor mode
155 // declare colors
156 RGBColor mainColor, secondColor, textColor;
157 // set color
158 if (drawUsingSelectColor()) {
160 secondColor = mainColor.changedBrightness(-32);
161 textColor = mainColor.changedBrightness(32);
162 } else {
163 mainColor = s.detectorSettings.E1Color;
164 secondColor = RGBColor::WHITE;
165 textColor = RGBColor::BLACK;
166 }
167 // draw parent and child lines
169 // push layer matrix
171 // translate to front
173 // draw E1 shape
174 drawE1Shape(d, E1Exaggeration, mainColor, secondColor);
175 // draw E1 Logo
176 drawE1DetectorLogo(s, d, E1Exaggeration, "E1", textColor);
177 // pop layer matrix
179 // draw lock icon
181 // Draw additional ID
183 // draw additional name
185 // draw dotted contour
187 }
188 // calculate contour rectangle
190 myAdditionalGeometry.getShapeRotations().front(), E1Exaggeration, getParentLanes().front()->getParentEdge());
191 }
192}
193
194
195std::string
199
200
201double
205
206
207void
208GNEInductionLoopDetector::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
209 setDetectorAttribute(key, value, undoList);
210}
211
212
213bool
214GNEInductionLoopDetector::isValid(SumoXMLAttr key, const std::string& value) {
215 return isDetectorValid(key, value);
216}
217
218// ===========================================================================
219// private
220// ===========================================================================
221
222void
224 setDetectorAttribute(key, value);
225}
226
227
228void
230 // change position
231 myPositionOverLane = moveResult.newFirstPos;
232 // set lateral offset
234 // update geometry
236}
237
238
239void
241 // reset lateral offset
243 // begin change attribute
244 undoList->begin(this, "position of " + getTagStr());
245 // set startPosition
246 setAttribute(SUMO_ATTR_POSITION, toString(moveResult.newFirstPos), undoList);
247 // check if lane has to be changed
248 if (moveResult.newFirstLane) {
249 // set new lane
250 setAttribute(SUMO_ATTR_LANE, moveResult.newFirstLane->getID(), undoList);
251 }
252 // end change attribute
253 undoList->end();
254}
255
256/****************************************************************************/
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:315
@ SUMO_TAG_INDUCTION_LOOP
alternative tag for e1 detector
SumoXMLAttr
Numbers representing SUMO-XML - attributes.
@ SUMO_ATTR_LANE
@ SUMO_ATTR_ID
@ SUMO_ATTR_POSITION
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition ToString.h:46
static void popMatrix()
pop matrix
Definition GLHelper.cpp:131
static void pushMatrix()
push matrix
Definition GLHelper.cpp:118
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
GNEContour myAdditionalContour
variable used for draw additional contours
GUIGeometry myAdditionalGeometry
geometry to be precomputed in updateGeometry(...)
void drawAdditionalID(const GUIVisualizationSettings &s) const
draw additional ID
double getExaggeration(const GUIVisualizationSettings &s) const
return exaggeration associated with this GLObject
void drawAdditionalName(const GUIVisualizationSettings &s) const
draw additional name
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
bool drawUsingSelectColor() const
check if attribute carrier must be drawn using selecting color.
void drawInLayer(const double typeOrLayer, const double extraOffset=0) const
draw element in the given layer, or in front if corresponding flag is enabled
GNENet * myNet
pointer to net
bool drawDottedContours(const GUIVisualizationSettings &s, const GUIVisualizationSettings::Detail d, const GNEAttributeCarrier *AC, const double lineWidth, const bool addOffset) const
draw dotted contours (basics, select, delete, inspect...)
void calculateContourRectangleShape(const GUIVisualizationSettings &s, const GUIVisualizationSettings::Detail d, const GUIGlObject *glObject, const Position &pos, const double width, const double height, const double layer, const double offsetX, const double offsetY, const double rot, const double scale, const GUIGlObject *boundaryParent) const
calculate contour (for rectangled elements)
double myPositionOverLane
position of detector over Lane
bool isDetectorValid(SumoXMLAttr key, const std::string &value)
double getGeometryPositionOverLane() const
get position over lane that is applicable to the shape
void setDetectorAttribute(SumoXMLAttr key, const std::string &value, GNEUndoList *undoList)
void drawE1Shape(const GUIVisualizationSettings::Detail d, const double exaggeration, const RGBColor &mainColor, const RGBColor &secondColor) const
draw E1 shape
double getDetectorAttributeDouble(SumoXMLAttr key) const
void writeDetectorValues(OutputDevice &device) const
write additional element into a xml file
bool myFriendlyPosition
Flag for friendly position.
void updateCenteringBoundary(const bool updateGrid)
update centering boundary (implies change in RTREE)
std::string getDetectorAttribute(SumoXMLAttr key) const
void drawE1DetectorLogo(const GUIVisualizationSettings &s, const GUIVisualizationSettings::Detail d, const double exaggeration, const std::string &logo, const RGBColor &textColor) const
draw E1 detector Logo
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 written 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
bool checkDrawRelatedContour() const
check if draw related contour (cyan)
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
A NBNetBuilder extended by visualisation and editing capabilities.
Definition GNENet.h:42
GNEViewNet * getViewNet() const
get view net
Definition GNENet.cpp:2163
GNETLSEditorFrame::TLSAttributes * getTLSAttributes() const
get module for TLS attributes
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...
const GNEViewNetHelper::DataViewOptions & getDataViewOptions() const
get data view options
GNEViewParent * getViewParent() const
get the net object
GNEUndoList * getUndoList() const
get the undoList object
bool selectingDetectorsTLSMode() const
check if we're selecting detectors in TLS mode
GNETLSEditorFrame * getTLSEditorFrame() const
get frame for NETWORK_TLS
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
GUIGlObjectType getType() const
Returns the type of the object as coded in GUIGlObjectType.
Stores the information about how to visualize structures.
bool checkDrawAdditional(Detail d, const bool selected) const
check if draw additionals
Detail getDetailLevel(const double exaggeration) const
return the detail level
GUIVisualizationColorSettings colorSettings
color settings
GUIVisualizationDottedContourSettings dottedContourSettings
dotted contour settings
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.
std::map< std::string, std::string > Map
parameters map
void writeParams(OutputDevice &device) const
write Params in the given outputdevice
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
bool showAdditionals() const
check if additionals has to be drawn
static void drawLockIcon(const GUIVisualizationSettings::Detail d, const GNEAttributeCarrier *AC, GUIGlObjectType type, const Position position, 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 RGBColor E1Color
color for E1 detectors
static const double segmentWidth
width of dotted contour segments