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.org/sumo
3// Copyright (C) 2001-2022 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>
29
30#include "GNEDetector.h"
31
32
33// ===========================================================================
34// member method definitions
35// ===========================================================================
36
37GNEDetector::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),
46myFriendlyPosition(friendlyPos) {
47}
48
49
50GNEDetector::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}, {}, {}),
54Parameterised(parameters),
55myPositionOverLane(pos),
56myPeriod(period),
57myFilename(filename),
58myFriendlyPosition(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
82double
84 return myPositionOverLane;
85}
86
87
90 return getParentLanes().front();
91}
92
93
97}
98
99
100void
101GNEDetector::updateCenteringBoundary(const bool /*updateGrid*/) {
103 // add center
105 // grow
107}
108
109void
110GNEDetector::splitEdgeGeometry(const double splitPosition, const GNENetworkElement* originalElement,
111 const GNENetworkElement* newElement, GNEUndoList* undoList) {
112 // only split geometry of E2 multilane detectors
114 // obtain new list of E2 lanes
115 std::string newE2Lanes = getNewListOfParents(originalElement, newElement);
116 // update E2 Lanes
117 if (newE2Lanes.size() > 0) {
118 setAttribute(SUMO_ATTR_LANES, newE2Lanes, undoList);
119 }
120 } else if (splitPosition < myPositionOverLane) {
121 // change lane
122 setAttribute(SUMO_ATTR_LANE, newElement->getID(), undoList);
123 // now adjust start position
124 setAttribute(SUMO_ATTR_POSITION, toString(myPositionOverLane - splitPosition), undoList);
125 }
126}
127
128
129double
131 double fixedPos = myPositionOverLane;
132 const double len = getLane()->getParentEdge()->getNBEdge()->getFinalLength();
133 double length = 0;
134 GNEAdditionalHandler::fixLanePosition(fixedPos, length, len);
135 return (fixedPos * getLane()->getLengthGeometryFactor());
136}
137
138
139
140std::string
142 return getLane()->getID();
143}
144
145
148 return getParametersMap();
149}
150
151
152std::string
154 return getTagStr() + ": " + getID();
155}
156
157
158std::string
160 return getTagStr();
161}
162
163
164void
165GNEDetector::drawE1Shape(const GUIVisualizationSettings& s, const double exaggeration, const double scaledWidth,
166 const RGBColor& mainColor, const RGBColor& secondColor) const {
167 // push matrix
169 // set line width
170 glLineWidth(1.0);
171 // translate to center geometry
172 glTranslated(myAdditionalGeometry.getShape().front().x(), myAdditionalGeometry.getShape().front().y(), 0);
173 // rotate over lane
175 // scale
176 glScaled(exaggeration, exaggeration, 1);
177 // set main color
178 GLHelper::setColor(mainColor);
179 // begin draw square
180 glBegin(GL_QUADS);
181 // draw square
182 glVertex2d(-1.0, 2);
183 glVertex2d(-1.0, -2);
184 glVertex2d(1.0, -2);
185 glVertex2d(1.0, 2);
186 // end draw square
187 glEnd();
188 // move top
189 glTranslated(0, 0, .01);
190 // begin draw line
191 glBegin(GL_LINES);
192 // draw lines
193 glVertex2d(0, 2 - .1);
194 glVertex2d(0, -2 + .1);
195 // end draw line
196 glEnd();
197 // outline if isn't being drawn for selecting
198 if ((scaledWidth * exaggeration > 1) && !s.drawForRectangleSelection) {
199 // set main color
200 GLHelper::setColor(secondColor);
201 // set polygon mode
202 glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
203 // begin draw square
204 glBegin(GL_QUADS);
205 // draw square
206 glVertex2f(-1.0, 2);
207 glVertex2f(-1.0, -2);
208 glVertex2f(1.0, -2);
209 glVertex2f(1.0, 2);
210 // end draw square
211 glEnd();
212 // rotate 90 degrees
213 glRotated(90, 0, 0, -1);
214 //set polygon mode
215 glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
216 // begin draw line
217 glBegin(GL_LINES);
218 // draw line
219 glVertex2d(0, 1.7);
220 glVertex2d(0, -1.7);
221 // end draw line
222 glEnd();
223 }
224 // pop matrix
226}
227
228
229void
230GNEDetector::drawDetectorLogo(const GUIVisualizationSettings& s, const double exaggeration,
231 const std::string& logo, const RGBColor& textColor) const {
233 // calculate middle point
234 const double middlePoint = (myAdditionalGeometry.getShape().length2D() * 0.5);
235 // calculate position
237 // calculate rotation
238 double rot = 0;
239 if (myAdditionalGeometry.getShapeRotations().size() > 0) {
241 } else if (myAdditionalGeometry.getShape().size() > 1) {
243 }
244 // Start pushing matrix
246 // Traslate to position
247 glTranslated(pos.x(), pos.y(), 0.1);
248 // rotate over lane
250 // move
251 glTranslated(-1, 0, 0);
252 // scale text
253 glScaled(exaggeration, exaggeration, 1);
254 // draw E1 logo
255 GLHelper::drawText(logo, Position(), .1, 1.5, textColor);
256 // pop matrix
258 }
259}
260
261/****************************************************************************/
@ NETWORK_MOVE
mode for moving network elements
long long int SUMOTime
Definition: GUI.h:36
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
void add(double x, double y, double z=0)
Makes the boundary include the given coordinate.
Definition: Boundary.cpp:78
void reset()
Resets the boundary.
Definition: Boundary.cpp:66
Boundary & grow(double by)
extends the boundary by the given amount
Definition: Boundary.cpp:300
static void setColor(const RGBColor &c)
Sets the gl-color to this value.
Definition: GLHelper.cpp:583
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:685
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:48
GUIGeometry myAdditionalGeometry
geometry to be precomputed in updateGeometry(...)
GNEMoveOperation * getMoveOperationMultiLane(const double startPos, const double endPos)
get moveOperation for an element over multi lane
Boundary myAdditionalBoundary
Additional Boundary.
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)
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
double myPositionOverLane
position of detector over Lane
Definition: GNEDetector.h:172
Position getPositionInView() const
Returns position of additional in view.
Definition: GNEDetector.cpp:95
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
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
GNELane * getLane() const
get lane
Definition: GNEDetector.cpp:89
virtual double getAttributeDouble(SumoXMLAttr key) const =0
GNEMoveOperation * getMoveOperation()
get move operation
Definition: GNEDetector.cpp:66
const Parameterised::Map & getACParametersMap() const
get parameters map
void splitEdgeGeometry(const double splitPosition, const GNENetworkElement *originalElement, const GNENetworkElement *newElement, GNEUndoList *undoList)
split geometry
void drawDetectorLogo(const GUIVisualizationSettings &s, const double exaggeration, const std::string &logo, const RGBColor &textColor) const
draw detector Logo
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)
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:481
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:124
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:1987
SumoXMLTag getTag() const
get Tag vinculated with this attribute Property
const GNEViewNetHelper::EditModes & getEditModes() const
get edit modes
Definition: GNEViewNet.cpp:632
GNEViewParent * getViewParent() const
get the net object
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.
bool drawForRectangleSelection
whether drawing is performed for the purpose of selecting objects using a rectangle
bool drawForPositionSelection
whether drawing is performed for the purpose of selecting objects with a single click
double getFinalLength() const
get length that will be assigned to the lanes in the final network
Definition: NBEdge.cpp:4469
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