Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
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-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#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
86
87
90 return getParentLanes().front();
91}
92
93
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
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 //arrow
225 glTranslated(2, 0, 0);
226 GLHelper::setColor(mainColor);
227 GLHelper::drawTriangleAtEnd(Position(0, 0), Position(0.5, 0), (double) 0.5, (double) 1);
228 // pop matrix
230}
231
232
233void
235 const std::string& logo, const RGBColor& textColor) const {
237 // calculate position
238 const Position pos = myAdditionalGeometry.getShape().front();
239 // calculate rotation
240 const double rot = s.getTextAngle(myAdditionalGeometry.getShapeRotations().front() + 90);
241 // Start pushing matrix
243 // Traslate to position
244 glTranslated(pos.x(), pos.y(), 0.1);
245 // scale text
246 glScaled(exaggeration, exaggeration, 1);
247 // draw E1 logo
248 GLHelper::drawText(logo + " ", Position(), .1, 1.5, textColor, rot);
249 // pop matrix
251 }
252}
253
254
255void
257 const std::string& logo, const RGBColor& textColor) const {
259 // calculate middle point
260 const double middlePoint = (myAdditionalGeometry.getShape().length2D() * 0.5);
261 // calculate position
262 const Position pos = myAdditionalGeometry.getShape().positionAtOffset2D(middlePoint);
263 // calculate rotation
264 const double rot = s.getTextAngle(myAdditionalGeometry.getShape().rotationDegreeAtOffset(middlePoint) + 90);
265 // Start pushing matrix
267 // Traslate to position
268 glTranslated(pos.x(), pos.y(), 0.1);
269 // scale text
270 glScaled(exaggeration, exaggeration, 1);
271 // draw E1 logo
272 GLHelper::drawText(logo, Position(), .1, 1.5, textColor, rot);
273 // pop matrix
275 }
276}
277
278/****************************************************************************/
@ 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 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:558
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.
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
Position getPositionInView() const
Returns position of additional in view.
std::string getHierarchyName() const
get Hierarchy Name (Used in AC Hierarchy)
~GNEDetector()
Destructor.
double getPositionOverLane() const
get position 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
GNELane * getLane() const
get lane
void drawE2DetectorLogo(const GUIVisualizationSettings &s, const double exaggeration, const std::string &logo, const RGBColor &textColor) const
draw E2 detector Logo
virtual double getAttributeDouble(SumoXMLAttr key) const =0
void drawE1DetectorLogo(const GUIVisualizationSettings &s, const double exaggeration, const std::string &logo, const RGBColor &textColor) const
draw E1 detector Logo
GNEMoveOperation * getMoveOperation()
get move operation
const Parameterised::Map & getACParametersMap() const
get parameters map
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.
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:480
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:118
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:2030
SumoXMLTag getTag() const
get Tag vinculated with this attribute Property
const GNEViewNetHelper::EditModes & getEditModes() const
get edit modes
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 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:4564
An upper class for objects with additional parameters.
std::map< std::string, std::string > Map
parameters map
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