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.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>
24 #include <netedit/GNEViewParent.h>
27 #include <utils/gui/div/GLHelper.h>
29 
31 #include "GNEAdditionalHandler.h"
32 
33 
34 // ===========================================================================
35 // member method definitions
36 // ===========================================================================
37 
40  0, 0, {}, "", {}, {}, "", "", false, Parameterised::Map()) {
41  // reset default values
42  resetDefaultValues();
43 }
44 
45 
47  const double pos, 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  pos, 0, {
52  lane
53 }, filename, vehicleTypes, nextEdges, detectPersons, name, friendlyPos, parameters) {
54  // update centering boundary without updating grid
55  updateCenteringBoundary(false);
56 }
57 
58 
60 }
61 
62 
63 void
65  device.openTag(getTagProperty().getTag());
66  device.writeAttr(SUMO_ATTR_ID, getID());
67  device.writeAttr(SUMO_ATTR_LANE, getParentLanes().front()->getID());
69  // write common detector parameters
70  writeDetectorValues(device);
71  // write parameters (Always after children to avoid problems with additionals.xsd)
72  writeParams(device);
73  device.closeTag();
74 }
75 
76 
77 bool
79  // with friendly position enabled position are "always fixed"
80  if (myFriendlyPosition) {
81  return true;
82  } else {
83  return fabs(myPositionOverLane) <= getParentLanes().front()->getParentEdge()->getNBEdge()->getFinalLength();
84  }
85 }
86 
87 
88 std::string
90  // obtain final length
91  const double len = getParentLanes().front()->getParentEdge()->getNBEdge()->getFinalLength();
92  // check if detector has a problem
94  return "";
95  } else {
96  // declare variable for error position
97  std::string errorPosition;
98  // check positions over lane
99  if (myPositionOverLane < 0) {
100  errorPosition = (toString(SUMO_ATTR_POSITION) + " < 0");
101  }
102  if (myPositionOverLane > len) {
103  errorPosition = (toString(SUMO_ATTR_POSITION) + TL(" > lanes's length"));
104  }
105  return errorPosition;
106  }
107 }
108 
109 
110 void
112  // declare new position
113  double newPositionOverLane = myPositionOverLane;
114  // fix pos and length checkAndFixDetectorPosition
115  double length = 0;
116  GNEAdditionalHandler::fixLanePosition(newPositionOverLane, length, getParentLanes().front()->getParentEdge()->getNBEdge()->getFinalLength());
117  // set new position
118  setAttribute(SUMO_ATTR_POSITION, toString(newPositionOverLane), myNet->getViewNet()->getUndoList());
119 }
120 
121 
122 void
124  // update geometry
126  // update centering boundary without updating grid
128 }
129 
130 
131 void
133  // check if additional has to be drawn
136  // Obtain exaggeration of the draw
137  const double E1InstantExaggeration = getExaggeration(s);
138  // get detail level
139  const auto d = s.getDetailLevel(E1InstantExaggeration);
140  // draw geometry only if we'rent in drawForObjectUnderCursor mode
142  // declare colors
143  RGBColor mainColor, secondColor, textColor;
144  // set color
145  if (drawUsingSelectColor()) {
147  secondColor = mainColor.changedBrightness(-32);
148  textColor = mainColor.changedBrightness(32);
149  } else {
150  mainColor = s.detectorSettings.E1InstantColor;
151  secondColor = RGBColor::WHITE;
152  textColor = RGBColor::BLACK;
153  }
154  // draw parent and child lines
156  // push layer matrix
158  // translate to front
160  // draw E1Instant shape
161  drawE1Shape(d, E1InstantExaggeration, mainColor, secondColor);
162  // draw E1 Logo
163  drawE1DetectorLogo(s, d, E1InstantExaggeration, "E1", textColor);
164  // pop layer matrix
166  // draw lock icon
168  // Draw additional ID
169  drawAdditionalID(s);
170  // draw additional name
172  // draw dotted contour
174  }
175  // draw dotted contour
177  myAdditionalGeometry.getShapeRotations().front(), E1InstantExaggeration);
178  }
179 }
180 
181 
182 std::string
184  return getDetectorAttribute(key);
185 }
186 
187 
188 double
190  return getDetectorAttributeDouble(key);
191 }
192 
193 
194 void
195 GNEInstantInductionLoopDetector::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
196  setDetectorAttribute(key, value, undoList);
197 }
198 
199 
200 bool
202  return isDetectorValid(key, value);
203 }
204 
205 // ===========================================================================
206 // private
207 // ===========================================================================
208 
209 void
211  setDetectorAttribute(key, value);
212 }
213 
214 
215 void
217  // change position
218  myPositionOverLane = moveResult.newFirstPos;
219  // set lateral offset
221  // update geometry
222  updateGeometry();
223 }
224 
225 
226 void
228  // reset lateral offset
230  // begin change attribute
231  undoList->begin(this, "position of " + getTagStr());
232  // set startPosition
233  setAttribute(SUMO_ATTR_POSITION, toString(moveResult.newFirstPos), undoList);
234  // check if lane has to be changed
235  if (moveResult.newFirstLane) {
236  // set new lane
237  setAttribute(SUMO_ATTR_LANE, moveResult.newFirstLane->getID(), undoList);
238  }
239  // end change attribute
240  undoList->end();
241 }
242 
243 /****************************************************************************/
@ 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:315
@ SUMO_TAG_INSTANT_INDUCTION_LOOP
An instantenous induction loop.
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:130
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
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.
GNENet * myNet
pointer to net
void calculateContourRectangleShape(const GUIVisualizationSettings &s, const GUIVisualizationSettings::Detail d, const GUIGlObject *glObject, const Position &pos, const double width, const double height, const double offsetX, const double offsetY, const double rot, const double scale) const
calculate contour (for rectangled elements)
Definition: GNEContour.cpp:103
void drawDottedContours(const GUIVisualizationSettings &s, const GUIVisualizationSettings::Detail d, const GNEAttributeCarrier *AC, const double lineWidth, const bool addOffset) const
drawing contour functions
Definition: GNEContour.cpp:265
double myPositionOverLane
position of detector over Lane
Definition: GNEDetector.h:191
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.
Definition: GNEDetector.h:209
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
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 written 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
A NBNetBuilder extended by visualisation and editing capabilities.
Definition: GNENet.h:42
GNEViewNet * getViewNet() const
get view net
Definition: GNENet.cpp:2136
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
Definition: GNEViewNet.cpp:747
void drawTranslateFrontAttributeCarrier(const GNEAttributeCarrier *AC, double typeOrLayer, const double extraOffset=0)
draw front attributeCarrier
GNEUndoList * getUndoList() const
get the undoList object
bool selectingDetectorsTLSMode() const
check if we're selecting detectors in TLS mode
Definition: GNEViewNet.cpp:940
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:59
GUIGlObjectType getType() const
Returns the type of the object as coded in GUIGlObjectType.
Definition: GUIGlObject.h:156
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.
Definition: OutputDevice.h:61
OutputDevice & openTag(const std::string &xmlElement)
Opens an XML tag.
OutputDevice & writeAttr(const SumoXMLAttr attr, const T &val)
writes a named attribute
Definition: OutputDevice.h:254
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
Definition: Parameterised.h:45
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 E1InstantColor
color for E1 Instant detectors
static const double segmentWidth
width of dotted contour segments