Eclipse SUMO - Simulation of Urban MObility
GNEDetector.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 #include <config.h>
21 
22 #include <netedit/GNENet.h>
23 #include <netedit/GNEViewNet.h>
24 #include <netedit/GNEViewParent.h>
27 #include <utils/gui/div/GLHelper.h>
29 
30 #include "GNEDetector.h"
31 
32 
33 // ===========================================================================
34 // member method definitions
35 // ===========================================================================
36 
37 GNEDetector::GNEDetector(const std::string& id, GNENet* net, GUIGlObjectType type, SumoXMLTag tag, FXIcon* icon, double pos, const SUMOTime period,
38  const std::vector<GNELane*>& parentLanes, const std::string& filename, const std::vector<std::string>& vehicleTypes, const std::string& name,
39  const bool friendlyPos, const Parameterised::Map& parameters) :
40  GNEAdditional(id, net, type, tag, icon, name, {}, {}, parentLanes, {}, {}, {}),
41  Parameterised(parameters),
42  myPositionOverLane(pos),
43  myPeriod(period),
44  myFilename(filename),
45  myVehicleTypes(vehicleTypes),
46 myFriendlyPosition(friendlyPos) {
47 }
48 
49 
50 GNEDetector::GNEDetector(GNEAdditional* additionalParent, GNENet* net, GUIGlObjectType type, SumoXMLTag tag, FXIcon* icon,
51  const double pos, const SUMOTime period, const std::vector<GNELane*>& parentLanes, const std::string& filename,
52  const std::string& name, const bool friendlyPos, const Parameterised::Map& parameters) :
53  GNEAdditional(net, type, tag, icon, name, {}, {}, parentLanes, {additionalParent}, {}, {}),
54 Parameterised(parameters),
55 myPositionOverLane(pos),
56 myPeriod(period),
57 myFilename(filename),
58 myFriendlyPosition(friendlyPos) {
59 }
60 
61 
63 
64 
67  // check modes and detector type
69  return nullptr;
74  } else {
75  // return move operation for detectors with single position placed over shape (E1, EntryExits..)
76  return new GNEMoveOperation(this, getParentLanes().front(), myPositionOverLane,
78  }
79 }
80 
81 
82 double
84  return myPositionOverLane;
85 }
86 
87 
88 bool
90  // get edit modes
91  const auto& editModes = myNet->getViewNet()->getEditModes();
92  // check if we're in move mode
93  if (!myNet->getViewNet()->isMovingElement() && editModes.isCurrentSupermodeNetwork() &&
94  (editModes.networkEditMode == NetworkEditMode::NETWORK_MOVE) && myNet->getViewNet()->checkOverLockedElement(this, mySelected)) {
95  // only move the first element
97  } else {
98  return false;
99  }
100 }
101 
102 
103 GNELane*
105  return getParentLanes().front();
106 }
107 
108 
109 Position
112 }
113 
114 
115 void
116 GNEDetector::updateCenteringBoundary(const bool /*updateGrid*/) {
117  // nothing to update
118 }
119 
120 void
121 GNEDetector::splitEdgeGeometry(const double splitPosition, const GNENetworkElement* originalElement,
122  const GNENetworkElement* newElement, GNEUndoList* undoList) {
123  // only split geometry of E2 multilane detectors
125  // obtain new list of E2 lanes
126  std::string newE2Lanes = getNewListOfParents(originalElement, newElement);
127  // update E2 Lanes
128  if (newE2Lanes.size() > 0) {
129  setAttribute(SUMO_ATTR_LANES, newE2Lanes, undoList);
130  }
131  } else if (splitPosition < myPositionOverLane) {
132  // change lane
133  setAttribute(SUMO_ATTR_LANE, newElement->getID(), undoList);
134  // now adjust start position
135  setAttribute(SUMO_ATTR_POSITION, toString(myPositionOverLane - splitPosition), undoList);
136  }
137 }
138 
139 
140 double
142  double fixedPos = myPositionOverLane;
143  const double len = getLane()->getParentEdge()->getNBEdge()->getFinalLength();
144  double length = 0;
145  GNEAdditionalHandler::fixLanePosition(fixedPos, length, len);
146  return (fixedPos * getLane()->getLengthGeometryFactor());
147 }
148 
149 
150 
151 std::string
153  return getLane()->getID();
154 }
155 
156 
157 const Parameterised::Map&
159  return getParametersMap();
160 }
161 
162 
163 std::string
165  return getTagStr() + ": " + getID();
166 }
167 
168 
169 std::string
171  return getTagStr();
172 }
173 
174 
175 void
177  const RGBColor& mainColor, const RGBColor& secondColor) const {
178  // push matrix
180  // set line width
181  glLineWidth(1.0);
182  // translate to center geometry
183  glTranslated(myAdditionalGeometry.getShape().front().x(), myAdditionalGeometry.getShape().front().y(), 0);
184  // rotate over lane
186  // scale
187  glScaled(exaggeration, exaggeration, 1);
188  // set main color
189  GLHelper::setColor(mainColor);
190  // begin draw square
191  glBegin(GL_QUADS);
192  // draw square
193  glVertex2d(-1.0, 2);
194  glVertex2d(-1.0, -2);
195  glVertex2d(1.0, -2);
196  glVertex2d(1.0, 2);
197  // end draw square
198  glEnd();
199  // move top
200  glTranslated(0, 0, .01);
201  // begin draw line
202  glBegin(GL_LINES);
203  // draw lines
204  glVertex2d(0, 2 - .1);
205  glVertex2d(0, -2 + .1);
206  // end draw line
207  glEnd();
208  // draw center only in draw in level 2
210  // set main color
211  GLHelper::setColor(secondColor);
212  // set polygon mode
213  glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
214  // begin draw square
215  glBegin(GL_QUADS);
216  // draw square
217  glVertex2f(-1.0, 2);
218  glVertex2f(-1.0, -2);
219  glVertex2f(1.0, -2);
220  glVertex2f(1.0, 2);
221  // end draw square
222  glEnd();
223  // rotate 90 degrees
224  glRotated(90, 0, 0, -1);
225  //set polygon mode
226  glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
227  // begin draw line
228  glBegin(GL_LINES);
229  // draw line
230  glVertex2d(0, 1.7);
231  glVertex2d(0, -1.7);
232  // end draw line
233  glEnd();
234  //arrow
235  glTranslated(2, 0, 0);
236  GLHelper::setColor(mainColor);
237  GLHelper::drawTriangleAtEnd(Position(0, 0), Position(0.5, 0), (double) 0.5, (double) 1);
238  }
239  // pop matrix
241 }
242 
243 
244 void
246  const double exaggeration, const std::string& logo, const RGBColor& textColor) const {
247  // only draw in level 2
249  // calculate position
250  const Position pos = myAdditionalGeometry.getShape().front();
251  // calculate rotation
252  const double rot = s.getTextAngle(myAdditionalGeometry.getShapeRotations().front() + 90);
253  // Start pushing matrix
255  // Traslate to position
256  glTranslated(pos.x(), pos.y(), 0.1);
257  // scale text
258  glScaled(exaggeration, exaggeration, 1);
259  // draw E1 logo
260  GLHelper::drawText(logo + " ", Position(), .1, 1.5, textColor, rot);
261  // pop matrix
263  }
264 }
265 
266 
267 void
269  const double exaggeration, const std::string& logo, const RGBColor& textColor) const {
270  // only draw in level 2
272  // calculate middle point
273  const double middlePoint = (myAdditionalGeometry.getShape().length2D() * 0.5);
274  // calculate position
275  const Position pos = myAdditionalGeometry.getShape().positionAtOffset2D(middlePoint);
276  // calculate rotation
277  const double rot = s.getTextAngle(myAdditionalGeometry.getShape().rotationDegreeAtOffset(middlePoint) + 90);
278  // Start pushing matrix
280  // Traslate to position
281  glTranslated(pos.x(), pos.y(), 0.1);
282  // scale text
283  glScaled(exaggeration, exaggeration, 1);
284  // draw E1 logo
285  GLHelper::drawText(logo, Position(), .1, 1.5, textColor, rot);
286  // pop matrix
288  }
289 }
290 
291 /****************************************************************************/
@ NETWORK_MOVE
mode for moving network elements
long long int SUMOTime
Definition: GUI.h:35
GUIGlObjectType
SumoXMLTag
Numbers representing SUMO-XML - element names.
@ GNE_TAG_MULTI_LANE_AREA_DETECTOR
an e2 detector over multiple lanes (placed here due create Additional Frame)
@ SUMO_TAG_LANE_AREA_DETECTOR
alternative tag for e2 detector
@ SUMO_ATTR_LANE
@ SUMO_ATTR_ENDPOS
@ SUMO_ATTR_LANES
@ SUMO_ATTR_POSITION
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:46
static void setColor(const RGBColor &c)
Sets the gl-color to this value.
Definition: GLHelper.cpp:655
static void drawTriangleAtEnd(const Position &p1, const Position &p2, double tLength, double tWidth, const double extraOffset=0)
Draws a triangle at the end of the given line.
Definition: GLHelper.cpp:630
static void popMatrix()
pop matrix
Definition: GLHelper.cpp:130
static void pushMatrix()
push matrix
Definition: GLHelper.cpp:117
static void drawText(const std::string &text, const Position &pos, const double layer, const double size, const RGBColor &col=RGBColor::BLACK, const double angle=0, const int align=0, double width=-1)
Definition: GLHelper.cpp:757
static void fixLanePosition(double &pos, double &length, const double laneLength)
fix given position over lane
An Element which don't belong to GNENet but has influence in the simulation.
Definition: GNEAdditional.h:49
GUIGeometry myAdditionalGeometry
geometry to be precomputed in updateGeometry(...)
GNEMoveOperation * getMoveOperationMultiLane(const double startPos, const double endPos)
get moveOperation for an element over multi lane
GNEMoveOperation * getMoveOperationSingleLane(const double startPos, const double endPos)
get moveOperation for an element over single lane
const std::string getID() const
get ID (all Attribute Carriers have one)
bool mySelected
boolean to check if this AC is selected (instead of GUIGlObjectStorage)
const std::string & getTagStr() const
get tag assigned to this object in string format
GNENet * myNet
pointer to net
const GNETagProperties & myTagProperty
reference to tagProperty associated with this attribute carrier
void drawE2DetectorLogo(const GUIVisualizationSettings &s, const GUIVisualizationSettings::Detail d, const double exaggeration, const std::string &logo, const RGBColor &textColor) const
draw E2 detector Logo
double myPositionOverLane
position of detector over Lane
Definition: GNEDetector.h:188
Position getPositionInView() const
Returns position of additional in view.
std::string getHierarchyName() const
get Hierarchy Name (Used in AC Hierarchy)
~GNEDetector()
Destructor.
Definition: GNEDetector.cpp:62
double getPositionOverLane() const
get position over lane
Definition: GNEDetector.cpp:83
double getGeometryPositionOverLane() const
get position over lane that is applicable to the shape
GNELane * getLane() const
get lane
virtual double getAttributeDouble(SumoXMLAttr key) const =0
GNEMoveOperation * getMoveOperation()
get move operation
Definition: GNEDetector.cpp:66
void drawE1Shape(const GUIVisualizationSettings::Detail d, const double exaggeration, const RGBColor &mainColor, const RGBColor &secondColor) const
draw E1 shape
const Parameterised::Map & getACParametersMap() const
get parameters map
bool checkDrawMoveContour() const
check if draw move contour (red)
Definition: GNEDetector.cpp:89
void splitEdgeGeometry(const double splitPosition, const GNENetworkElement *originalElement, const GNENetworkElement *newElement, GNEUndoList *undoList)
split geometry
void updateCenteringBoundary(const bool updateGrid)
update centering boundary (implies change in RTREE)
GNEDetector(const std::string &id, GNENet *net, GUIGlObjectType type, SumoXMLTag tag, FXIcon *icon, const double pos, const SUMOTime period, const std::vector< GNELane * > &parentLanes, const std::string &filename, const std::vector< std::string > &vehicleTypes, const std::string &name, const bool friendlyPos, const Parameterised::Map &parameters)
Constructor.
Definition: GNEDetector.cpp:37
std::string getPopUpID() const
get PopPup ID (Used in AC Hierarchy)
void drawE1DetectorLogo(const GUIVisualizationSettings &s, const GUIVisualizationSettings::Detail d, const double exaggeration, const std::string &logo, const RGBColor &textColor) const
draw E1 detector Logo
virtual void setAttribute(SumoXMLAttr key, const std::string &value, GNEUndoList *undoList)=0
method for setting the attribute and letting the object perform additional changes
std::string getParentName() const
Returns the name of the parent object.
NBEdge * getNBEdge() const
returns the internal NBEdge
Definition: GNEEdge.cpp:683
std::string getNewListOfParents(const GNENetworkElement *currentElement, const GNENetworkElement *newNextElement) const
if use edge/parent lanes as a list of consecutive elements, obtain a list of IDs of elements after in...
const std::vector< GNELane * > & getParentLanes() const
get parent lanes
This lane is powered by an underlying GNEEdge and basically knows how to draw itself.
Definition: GNELane.h:46
GNEEdge * getParentEdge() const
get parent edge
Definition: GNELane.cpp:196
bool getAllowChangeLane() const
allow change lane
CommonModeOptions * getCommonModeOptions() const
get common mode options
move operation
A NBNetBuilder extended by visualisation and editing capabilities.
Definition: GNENet.h:42
GNEViewNet * getViewNet() const
get view net
Definition: GNENet.cpp:2022
SumoXMLTag getTag() const
get Tag vinculated with this attribute Property
const GUIGlObject * getGUIGlObjectFront() const
get front attribute carrier or a pointer to nullptr
const GNEViewNetHelper::EditModes & getEditModes() const
get edit modes
Definition: GNEViewNet.cpp:703
bool isMovingElement() const
check if an element is being moved
GNEViewParent * getViewParent() const
get the net object
bool checkOverLockedElement(const GUIGlObject *GLObject, const bool isSelected) const
check if given element is locked (used for drawing select and delete contour)
const GNEViewNetHelper::ViewObjectsSelector & getViewObjectsSelector() const
get objects under cursor
Definition: GNEViewNet.cpp:468
GNEMoveFrame * getMoveFrame() const
get frame for move elements
static void rotateOverLane(const double rot)
rotate over lane (used by Lock icons, detector logos, etc.)
const std::vector< double > & getShapeRotations() const
The rotations of the single shape parts.
const PositionVector & getShape() const
The shape of the additional element.
Stores the information about how to visualize structures.
double getTextAngle(double objectAngle) const
return an angle that is suitable for reading text aligned with the given angle (degrees)
double getFinalLength() const
get length that will be assigned to the lanes in the final network
Definition: NBEdge.cpp:4642
An upper class for objects with additional parameters.
Definition: Parameterised.h:41
std::map< std::string, std::string > Map
parameters map
Definition: Parameterised.h:45
const Parameterised::Map & getParametersMap() const
Returns the inner key/value map.
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:37
double x() const
Returns the x-position.
Definition: Position.h:55
double y() const
Returns the y-position.
Definition: Position.h:60
double length2D() const
Returns the length.
Position getPolygonCenter() const
Returns the arithmetic of all corner points.
double rotationDegreeAtOffset(double pos) const
Returns the rotation at the given length.
Position positionAtOffset2D(double pos, double lateralOffset=0) const
Returns the position at the given length.
NetworkEditMode networkEditMode
the current Network edit mode
bool isCurrentSupermodeNetwork() const
@check if current supermode is Network