Eclipse SUMO - Simulation of Urban MObility
GNERerouterSymbol.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>
24 #include <utils/gui/div/GLHelper.h>
26 
27 #include "GNERerouterSymbol.h"
28 
29 // ===========================================================================
30 // member method definitions
31 // ===========================================================================
32 
34  GNEAdditional(rerouterParent->getNet(), GLO_REROUTER, GNE_TAG_REROUTER_SYMBOL, "",
35 {}, {edge}, {}, {rerouterParent}, {}, {}, {}, {},
36 std::map<std::string, std::string>()) {
37  // update centering boundary without updating grid
38  updateCenteringBoundary(false);
39 }
40 
41 
43 }
44 
45 
48  // GNERerouterSymbols cannot be moved
49  return nullptr;
50 }
51 
52 
53 void
55  // noting to write
56 }
57 
58 
59 void
61  // clear geometries
62  mySymbolGeometries.clear();
63  // iterate over all lanes
64  NBEdge* nbe = getParentEdges().front()->getNBEdge();
65  for (const auto& lane : getParentEdges().front()->getLanes()) {
66  if ((nbe->getPermissions(lane->getIndex()) & ~SVC_PEDESTRIAN) == 0) {
67  continue;
68  }
69  // declare geometry
70  GUIGeometry symbolGeometry;
71  // update it with lane and pos over lane
72  symbolGeometry.updateGeometry(lane->getLaneShape(), lane->getLaneShape().length2D() - 6, 0);
73  // add in mySymbolGeometries
74  mySymbolGeometries.push_back(symbolGeometry);
75  }
76 }
77 
78 
81  if (mySymbolGeometries.size() > 0) {
82  return mySymbolGeometries.front().getShape().getPolygonCenter();
83  } else {
85  }
86 }
87 
88 
89 void
90 GNERerouterSymbol::updateCenteringBoundary(const bool /*updateGrid*/) {
92  // add center
94  // grow
96 }
97 
98 
99 void
100 GNERerouterSymbol::splitEdgeGeometry(const double /*splitPosition*/, const GNENetworkElement* /*originalElement*/,
101  const GNENetworkElement* /*newElement*/, GNEUndoList* /*undoList*/) {
102  // nothing to split
103 }
104 
105 
106 std::string
108  return getParentAdditionals().at(0)->getID();
109 }
110 
111 
112 void
114  // Obtain exaggeration of the draw
115  const double rerouteExaggeration = s.addSize.getExaggeration(s, getParentAdditionals().front());
116  // first check if additional has to be drawn
117  if (s.drawAdditionals(rerouteExaggeration) && myNet->getViewNet()->getDataViewOptions().showAdditionals()) {
118  // draw parent and child lines
120  // Start drawing adding an gl identificator (except in Move mode)
123  }
124  // push layer matrix
126  // translate to front
128  // draw rerouter symbol over all lanes
129  for (const auto& symbolGeometry : mySymbolGeometries) {
130  // push symbol matrix
132  // translate to position
133  glTranslated(symbolGeometry.getShape().front().x(), symbolGeometry.getShape().front().y(), 0);
134  // rotate over lane
135  GUIGeometry::rotateOverLane(symbolGeometry.getShapeRotations().front() + 90);
136  // scale
137  glScaled(rerouteExaggeration, rerouteExaggeration, 1);
138  // set color
141  } else {
142  glColor3d(1, .8f, 0);
143  }
144  // set draw mode
145  glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
146  glBegin(GL_TRIANGLES);
147  // base
148  glVertex2d(0 - 1.4, 0);
149  glVertex2d(0 - 1.4, 6);
150  glVertex2d(0 + 1.4, 6);
151  glVertex2d(0 + 1.4, 0);
152  glVertex2d(0 - 1.4, 0);
153  glVertex2d(0 + 1.4, 6);
154  glEnd();
155  // draw "U"
156  if (!s.drawForPositionSelection) {
157  // set text color
158  RGBColor textColor;
161  } else {
162  textColor = RGBColor::BLACK;
163  }
164  // get probability
165  const std::string probability = toString(getParentAdditionals().front()->getAttributeDouble(SUMO_ATTR_PROB) * 100) + "%";
166  // draw U
167  GLHelper::drawText("U", Position(0, 2), .1, 3, textColor, 180);
168  // draw Probability
169  GLHelper::drawText(probability.c_str(), Position(0, 4), .1, 0.7, textColor, 180);
170  }
171  // pop symbol matrix
173  }
174  // pop layer matrix
176  // Pop name
179  }
180  // check if dotted contour has to be drawn
182  // iterate over symbol geometries
183  for (const auto& symbolGeometry : mySymbolGeometries) {
184  GUIDottedGeometry::drawDottedSquaredShape(GUIDottedGeometry::DottedContourType::INSPECT, s, symbolGeometry.getShape().front(), 1, 3, 0, 3, symbolGeometry.getShapeRotations().front() + 90, rerouteExaggeration);
185  }
186  }
188  // iterate over symbol geometries
189  for (const auto& symbolGeometry : mySymbolGeometries) {
190  GUIDottedGeometry::drawDottedSquaredShape(GUIDottedGeometry::DottedContourType::FRONT, s, symbolGeometry.getShape().front(), 1, 3, 0, 3, symbolGeometry.getShapeRotations().front() + 90, rerouteExaggeration);
191  }
192  }
193  }
194 }
195 
196 
197 std::string
199  switch (key) {
200  case SUMO_ATTR_EDGE:
201  return getParentEdges().front()->getID();
202  default:
203  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
204  }
205 }
206 
207 
208 double
210  throw InvalidArgument("Symbols cannot be edited");
211 }
212 
213 
214 void
215 GNERerouterSymbol::setAttribute(SumoXMLAttr /*key*/, const std::string& /*value*/, GNEUndoList* /*undoList*/) {
216  throw InvalidArgument("Symbols cannot be edited");
217 }
218 
219 
220 bool
221 GNERerouterSymbol::isValid(SumoXMLAttr /*key*/, const std::string& /*value*/) {
222  throw InvalidArgument("Symbols cannot be edited");
223 }
224 
225 
226 bool
228  return true;
229 }
230 
231 
232 std::string
234  return getParentEdges().front()->getPopUpID();
235 }
236 
237 
238 std::string
240  return getParentEdges().front()->getID();
241 }
242 
243 // ===========================================================================
244 // private
245 // ===========================================================================
246 
247 void
248 GNERerouterSymbol::setAttribute(SumoXMLAttr /*key*/, const std::string& /*value*/) {
249  throw InvalidArgument("Symbols cannot be edited");
250 }
251 
252 
253 void
255  // nothing to do
256 }
257 
258 
259 void
260 GNERerouterSymbol::commitMoveShape(const GNEMoveResult& /*moveResult*/, GNEUndoList* /*undoList*/) {
261  // nothing to do
262 }
263 
264 /****************************************************************************/
@ NETWORK_MOVE
mode for moving network elements
@ GLO_REROUTER
a Rerouter
@ SVC_PEDESTRIAN
pedestrian
@ GNE_TAG_REROUTER_SYMBOL
Rerouter Symbol.
SumoXMLAttr
Numbers representing SUMO-XML - attributes.
@ SUMO_ATTR_EDGE
@ SUMO_ATTR_PROB
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:77
void reset()
Resets the boundary.
Definition: Boundary.cpp:65
Boundary & grow(double by)
extends the boundary by the given amount
Definition: Boundary.cpp:299
static void setColor(const RGBColor &c)
Sets the gl-color to this value.
Definition: GLHelper.cpp:507
static void pushName(unsigned int name)
push Name
Definition: GLHelper.cpp:132
static void popMatrix()
pop matrix
Definition: GLHelper.cpp:123
static void popName()
pop Name
Definition: GLHelper.cpp:141
static void pushMatrix()
push matrix
Definition: GLHelper.cpp:114
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:609
An Element which don't belongs to GNENet but has influency in the simulation.
Definition: GNEAdditional.h:48
GUIGeometry myAdditionalGeometry
geometry to be precomputed in updateGeometry(...)
Boundary myAdditionalBoundary
Additional Boundary.
void drawParentChildLines(const GUIVisualizationSettings &s, const RGBColor &color, const bool onlySymbols=false) const
draw parent and child lines
bool isAttributeCarrierSelected() const
check if attribute carrier is selected
const std::string & getTagStr() const
get tag assigned to this object in string format
GNENet * myNet
pointer to net
A road/street connecting two junctions (netedit-version)
Definition: GNEEdge.h:53
const std::vector< GNEAdditional * > & getParentAdditionals() const
get parent additionals
const std::vector< GNEEdge * > & getParentEdges() const
get parent edges
move operation
move result
GNEViewNet * getViewNet() const
get view net
Definition: GNENet.cpp:1964
GNEMoveOperation * getMoveOperation()
get move operation
std::string getParentName() const
Returns the name of the parent object (if any)
bool isValid(SumoXMLAttr key, const std::string &value)
method for checking if the key and their conrrespond attribute are valids
std::vector< GUIGeometry > mySymbolGeometries
symbols geometries
void drawGL(const GUIVisualizationSettings &s) const
Draws the object.
void setAttribute(SumoXMLAttr key, const std::string &value, GNEUndoList *undoList)
method for setting the attribute and letting the object perform additional changes
void commitMoveShape(const GNEMoveResult &moveResult, GNEUndoList *undoList)
commit move shape
void updateCenteringBoundary(const bool updateGrid)
update centering boundary (implies change in RTREE)
void writeAdditional(OutputDevice &device) const
writte additional element into a xml file
void updateGeometry()
update pre-computed geometry information
bool isAttributeEnabled(SumoXMLAttr key) const
std::string getAttribute(SumoXMLAttr key) const
~GNERerouterSymbol()
Destructor.
void setMoveShape(const GNEMoveResult &moveResult)
set move shape
std::string getPopUpID() const
get PopPup ID (Used in AC Hierarchy)
void splitEdgeGeometry(const double splitPosition, const GNENetworkElement *originalElement, const GNENetworkElement *newElement, GNEUndoList *undoList)
split geometry
GNERerouterSymbol(GNEAdditional *rerouterParent, GNEEdge *edge)
Constructor.
std::string getHierarchyName() const
get Hierarchy Name (Used in AC Hierarchy)
Position getPositionInView() const
Returns position of additional in view.
double getAttributeDouble(SumoXMLAttr key) const
const GNEViewNetHelper::DataViewOptions & getDataViewOptions() const
get data view options
Definition: GNEViewNet.cpp:537
const GNEAttributeCarrier * getFrontAttributeCarrier() const
get front attributeCarrier
const GNEViewNetHelper::EditModes & getEditModes() const
get edit modes
Definition: GNEViewNet.cpp:513
void drawTranslateFrontAttributeCarrier(const GNEAttributeCarrier *AC, double typeOrLayer, const double extraOffset=0)
draw front attributeCarrier
bool isAttributeCarrierInspected(const GNEAttributeCarrier *AC) const
check if attribute carrier is being inspected
static void drawDottedSquaredShape(const DottedContourType type, const GUIVisualizationSettings &s, const Position &pos, const double width, const double height, const double offsetX, const double offsetY, const double rot, const double exaggeration)
draw dotted squared contour (used by additionals and demand elements)
static void rotateOverLane(const double rot)
rotate over lane (used by Lock icons, detector logos, etc.)
const PositionVector & getShape() const
The shape of the additional element.
void updateGeometry(const PositionVector &shape)
update entire geometry
Definition: GUIGeometry.cpp:58
GUIGlID getGlID() const
Returns the numerical id of the object.
Stores the information about how to visualize structures.
GUIVisualizationSizeSettings addSize
bool drawForPositionSelection
whether drawing is performed for the purpose of selecting objects with a single click
bool drawAdditionals(const double exaggeration) const
check if additionals must be drawn
GUIVisualizationColorSettings colorSettings
color settings
GUIVisualizationAdditionalSettings additionalSettings
Additional settings.
The representation of a single edge during network building.
Definition: NBEdge.h:91
SVCPermissions getPermissions(int lane=-1) const
get the union of allowed classes over all lanes or for a specific lane
Definition: NBEdge.cpp:4022
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:61
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:37
Position getPolygonCenter() const
Returns the arithmetic of all corner points.
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:197
bool showAdditionals() const
check if additionals has to be drawn
NetworkEditMode networkEditMode
the current Network edit mode
static const RGBColor connectionColor
connection color
RGBColor selectedAdditionalColor
additional selection color (busStops, Detectors...)
double getExaggeration(const GUIVisualizationSettings &s, const GUIGlObject *o, double factor=20) const
return the drawing size including exaggeration and constantSize values