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-2020 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, "", false,
35 {}, {edge}, {}, {rerouterParent}, {}, {}, {}, {}) {
36  // update centering boundary without updating grid
37  updateCenteringBoundary(false);
38 }
39 
40 
42 }
43 
44 
46 GNERerouterSymbol::getMoveOperation(const double /*shapeOffset*/) {
47  // GNERerouterSymbols cannot be moved
48  return nullptr;
49 }
50 
51 
52 void
54  // clear geometries
55  mySymbolGeometries.clear();
56  // iterate over all lanes
57  for (const auto& lane : getParentEdges().front()->getLanes()) {
58  // declare geometry
59  GNEGeometry::Geometry symbolGeometry;
60  // update it with lane and pos over lane
61  symbolGeometry.updateGeometry(lane, lane->getLaneShape().length2D() - 6);
62  // add in mySymbolGeometries
63  mySymbolGeometries.push_back(symbolGeometry);
64  }
65  // add shape boundary
66  myBoundary = mySymbolGeometries.front().getShape().getBoxBoundary();
67  // grow
68  myBoundary.grow(10);
69  // update connections
70  getParentAdditionals().front()->updateHierarchicalConnections();
71 }
72 
73 
74 void
75 GNERerouterSymbol::updateCenteringBoundary(const bool /*updateGrid*/) {
76  // just update geometry
78 }
79 
80 
81 void
82 GNERerouterSymbol::splitEdgeGeometry(const double /*splitPosition*/, const GNENetworkElement* /*originalElement*/,
83  const GNENetworkElement* /*newElement*/, GNEUndoList* /*undoList*/) {
84  // nothing to split
85 }
86 
87 
88 std::string
90  return getParentAdditionals().at(0)->getID();
91 }
92 
93 
94 void
96  // Obtain exaggeration of the draw
97  const double rerouteExaggeration = s.addSize.getExaggeration(s, getParentAdditionals().front());
98  // first check if additional has to be drawn
99  if (s.drawAdditionals(rerouteExaggeration) && myNet->getViewNet()->getDataViewOptions().showAdditionals()) {
100  // Start drawing adding an gl identificator (except in Move mode)
102  glPushName(getParentAdditionals().front()->getGlID());
103  }
104  // push layer matrix
105  glPushMatrix();
106  // translate to front
108  // draw rerouter symbol over all lanes
109  for (const auto& symbolGeometry : mySymbolGeometries) {
110  // push symbol matrix
111  glPushMatrix();
112  // translate to position
113  glTranslated(symbolGeometry.getShape().front().x(), symbolGeometry.getShape().front().y(), 0);
114  // rotate over lane
115  GNEGeometry::rotateOverLane(symbolGeometry.getShapeRotations().front() + 90);
116  // scale
117  glScaled(rerouteExaggeration, rerouteExaggeration, 1);
118  // set color
121  } else {
122  glColor3d(1, .8f, 0);
123  }
124  // set draw mode
125  glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
126  glBegin(GL_TRIANGLES);
127  // base
128  glVertex2d(0 - 1.4, 0);
129  glVertex2d(0 - 1.4, 6);
130  glVertex2d(0 + 1.4, 6);
131  glVertex2d(0 + 1.4, 0);
132  glVertex2d(0 - 1.4, 0);
133  glVertex2d(0 + 1.4, 6);
134  glEnd();
135  // draw "U"
136  if (!s.drawForPositionSelection) {
137  // set text color
138  RGBColor textColor;
141  } else {
142  textColor = RGBColor::BLACK;
143  }
144  // get probability
145  const std::string probability = toString(getParentAdditionals().front()->getAttributeDouble(SUMO_ATTR_PROB) * 100) + "%";
146  // draw U
147  GLHelper::drawText("U", Position(0, 2), .1, 3, textColor, 180);
148  // draw Probability
149  GLHelper::drawText(probability.c_str(), Position(0, 4), .1, 0.7, textColor, 180);
150  }
151  // pop symbol matrix
152  glPopMatrix();
153  }
154  // pop layer matrix
155  glPopMatrix();
156  // Pop name
158  glPopName();
159  }
160  // check if dotted contour has to be drawn
162  // iterate over symbol geometries
163  for (const auto& symbolGeometry : mySymbolGeometries) {
164  GNEGeometry::drawDottedSquaredShape(GNEGeometry::DottedContourType::INSPECT, s, symbolGeometry.getShape().front(), 1, 3, 0, 3, symbolGeometry.getShapeRotations().front() + 90, rerouteExaggeration);
165  }
166  }
168  // iterate over symbol geometries
169  for (const auto& symbolGeometry : mySymbolGeometries) {
170  GNEGeometry::drawDottedSquaredShape(GNEGeometry::DottedContourType::FRONT, s, symbolGeometry.getShape().front(), 1, 3, 0, 3, symbolGeometry.getShapeRotations().front() + 90, rerouteExaggeration);
171  }
172  }
173  }
174 }
175 
176 
177 std::string
179  switch (key) {
180  case SUMO_ATTR_EDGE:
181  return getParentEdges().front()->getID();
182  default:
183  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
184  }
185 }
186 
187 
188 double
190  throw InvalidArgument("Symbols cannot be edited");
191 }
192 
193 
194 void
195 GNERerouterSymbol::setAttribute(SumoXMLAttr /*key*/, const std::string& /*value*/, GNEUndoList* /*undoList*/) {
196  throw InvalidArgument("Symbols cannot be edited");
197 }
198 
199 
200 bool
201 GNERerouterSymbol::isValid(SumoXMLAttr /*key*/, const std::string& /*value*/) {
202  throw InvalidArgument("Symbols cannot be edited");
203 }
204 
205 
206 bool
208  return true;
209 }
210 
211 
212 std::string
214  return getParentAdditionals().at(0)->getPopUpID();
215 }
216 
217 
218 std::string
220  return getParentAdditionals().at(0)->getHierarchyName();
221 }
222 
223 // ===========================================================================
224 // private
225 // ===========================================================================
226 
227 void
228 GNERerouterSymbol::setAttribute(SumoXMLAttr /*key*/, const std::string& /*value*/) {
229  throw InvalidArgument("Symbols cannot be edited");
230 }
231 
232 
233 void
235  // nothing to do
236 }
237 
238 
239 void
240 GNERerouterSymbol::commitMoveShape(const GNEMoveResult& /*moveResult*/, GNEUndoList* /*undoList*/) {
241  // nothing to do
242 }
243 
244 /****************************************************************************/
@ NETWORK_MOVE
mode for moving network elements
@ GLO_REROUTER
a Rerouter
@ 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:44
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:446
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:498
An Element which don't belongs to GNENet but has influency in the simulation.
Definition: GNEAdditional.h:47
Boundary myBoundary
Additional Boundary.
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:49
class for NETEDIT geometries over lanes
Definition: GNEGeometry.h:76
void updateGeometry(const PositionVector &shape, double startPos=-1, double endPos=-1, const Position &extraFirstPosition=Position::INVALID, const Position &extraLastPosition=Position::INVALID)
update geometry shape
Definition: GNEGeometry.cpp:81
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:2245
std::vector< GNEGeometry::Geometry > mySymbolGeometries
symbols geometries
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
void drawGL(const GUIVisualizationSettings &s) const
Draws the object.
GNEMoveOperation * getMoveOperation(const double shapeOffset)
get move operation for the given shapeOffset
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 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)
double getAttributeDouble(SumoXMLAttr key) const
const GNEViewNetHelper::DataViewOptions & getDataViewOptions() const
get data view options
Definition: GNEViewNet.cpp:491
const GNEAttributeCarrier * getFrontAttributeCarrier() const
get front attributeCarrier
const GNEViewNetHelper::EditModes & getEditModes() const
get edit modes
Definition: GNEViewNet.cpp:467
bool isAttributeCarrierInspected(const GNEAttributeCarrier *AC) const
check if attribute carrier is being inspected
void drawTranslateFrontAttributeCarrier(const GNEAttributeCarrier *AC, GUIGlObjectType objectType, const double extraOffset=0)
draw front attributeCarrier
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 drawDottedContour() const
check if dotted contour can be drawn
bool drawAdditionals(const double exaggeration) const
check if additionals must be drawn
GUIVisualizationColorSettings colorSettings
color settings
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:36
static const RGBColor BLACK
Definition: RGBColor.h:188
RGBColor changedBrightness(int change, int toChange=3) const
Returns a new color with altered brightness.
Definition: RGBColor.cpp:145
static void rotateOverLane(const double rot)
rotate over lane (used by Lock icons, detector logos, etc.)
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)
bool showAdditionals() const
check if additionals has to be drawn
NetworkEditMode networkEditMode
the current Network edit mode
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