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.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 <utils/gui/div/GLHelper.h>
26 
27 #include "GNERerouterSymbol.h"
28 
29 // ===========================================================================
30 // member method definitions
31 // ===========================================================================
32 
35 {}, {}, {}, {}, {}, {}) {
36  // reset default values
37  resetDefaultValues();
38 }
39 
40 
42  GNEAdditional(rerouterParent->getNet(), GLO_REROUTER, GNE_TAG_REROUTER_SYMBOL, GUIIconSubSys::getIcon(GUIIcon::REROUTER), "",
43 {}, {edge}, {}, {rerouterParent}, {}, {}) {
44  // update centering boundary without updating grid
45  updateCenteringBoundary(false);
46 }
47 
48 
50 }
51 
52 
55  // GNERerouterSymbols cannot be moved
56  return nullptr;
57 }
58 
59 
60 void
62  // noting to write
63 }
64 
65 
66 bool
68  return true;
69 }
70 
71 
72 std::string
74  return "";
75 }
76 
77 
78 void
80  // nothing to fix
81 }
82 
83 
84 bool
86  // get edit modes
87  const auto& editModes = myNet->getViewNet()->getEditModes();
88  // check if we're in move mode
89  if (!myNet->getViewNet()->isMovingElement() && editModes.isCurrentSupermodeNetwork() &&
90  (editModes.networkEditMode == NetworkEditMode::NETWORK_MOVE) && myNet->getViewNet()->checkOverLockedElement(this, mySelected)) {
91  // only move the first element
93  } else {
94  return false;
95  }
96 }
97 
98 
99 void
101  // clear geometries
102  mySymbolGeometries.clear();
103  // iterate over all lanes
104  NBEdge* nbe = getParentEdges().front()->getNBEdge();
105  for (const auto& lane : getParentEdges().front()->getLanes()) {
106  if ((nbe->getPermissions(lane->getIndex()) & ~SVC_PEDESTRIAN) == 0) {
107  continue;
108  }
109  // declare geometry
110  GUIGeometry symbolGeometry;
111  // update it with lane and pos over lane
112  symbolGeometry.updateGeometry(lane->getLaneShape(), lane->getLaneShape().length2D() - 6, 0);
113  // add in mySymbolGeometries
114  mySymbolGeometries.push_back(symbolGeometry);
115  }
116 }
117 
118 
119 Position
121  if (mySymbolGeometries.size() > 0) {
122  return mySymbolGeometries.front().getShape().getPolygonCenter();
123  } else {
125  }
126 }
127 
128 
129 void
130 GNERerouterSymbol::updateCenteringBoundary(const bool /*updateGrid*/) {
131  // nothing to do
132 }
133 
134 
135 void
136 GNERerouterSymbol::splitEdgeGeometry(const double /*splitPosition*/, const GNENetworkElement* /*originalElement*/,
137  const GNENetworkElement* /*newElement*/, GNEUndoList* /*undoList*/) {
138  // nothing to split
139 }
140 
141 
142 std::string
144  return getParentAdditionals().at(0)->getID();
145 }
146 
147 
148 void
150  // first check if additional has to be drawn
152  // Obtain exaggeration of the draw
153  const double rerouteExaggeration = s.addSize.getExaggeration(s, getParentAdditionals().front());
154  // get detail level
155  const auto d = s.getDetailLevel(rerouteExaggeration);
156  // draw geometry only if we'rent in drawForObjectUnderCursor mode
157  if (!s.drawForViewObjectsHandler) {
158  // draw rerouter symbol
159  drawRerouterSymbol(s, d, rerouteExaggeration);
160  // draw parent and child lines
162  // draw dotted contour
164  }
165  // calculate contour rectangle shape
166  for (const auto& symbolGeometry : mySymbolGeometries) {
167  myAdditionalContour.calculateContourRectangleShape(s, d, this, symbolGeometry.getShape().front(), 1, 3, 0, 3,
168  symbolGeometry.getShapeRotations().front() + 90, rerouteExaggeration);
169  }
170  }
171 }
172 
173 
174 std::string
176  switch (key) {
177  case SUMO_ATTR_ID:
178  case SUMO_ATTR_EDGE:
179  return getParentEdges().front()->getID();
180  default:
181  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
182  }
183 }
184 
185 
186 double
188  throw InvalidArgument("Symbols cannot be edited");
189 }
190 
191 
192 const Parameterised::Map&
194  return PARAMETERS_EMPTY;
195 }
196 
197 
198 void
199 GNERerouterSymbol::setAttribute(SumoXMLAttr /*key*/, const std::string& /*value*/, GNEUndoList* /*undoList*/) {
200  throw InvalidArgument("Symbols cannot be edited");
201 }
202 
203 
204 bool
205 GNERerouterSymbol::isValid(SumoXMLAttr /*key*/, const std::string& /*value*/) {
206  throw InvalidArgument("Symbols cannot be edited");
207 }
208 
209 
210 std::string
212  return getParentEdges().front()->getPopUpID();
213 }
214 
215 
216 std::string
218  return getParentEdges().front()->getID();
219 }
220 
221 // ===========================================================================
222 // private
223 // ===========================================================================
224 
225 void
227  const double exaggeration) const {
228  // push layer matrix
230  // translate to front
232  // set color
233  RGBColor color;
236  } else {
237  color = RGBColor(255, 231, 0);
238  }
239  // draw rerouter symbol over all lanes
240  for (const auto& symbolGeometry : mySymbolGeometries) {
241  // push symbol matrix
243  // translate to position
244  glTranslated(symbolGeometry.getShape().front().x(), symbolGeometry.getShape().front().y(), 0);
245  // rotate over lane
246  GUIGeometry::rotateOverLane(symbolGeometry.getShapeRotations().front() + 90);
247  // scale
248  glScaled(exaggeration, exaggeration, 1);
249  // set color
250  GLHelper::setColor(color);
251  // set draw mode
252  glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
253  glBegin(GL_TRIANGLES);
254  // base
255  glVertex2d(0 - 1.4, 0);
256  glVertex2d(0 - 1.4, 6);
257  glVertex2d(0 + 1.4, 6);
258  glVertex2d(0 + 1.4, 0);
259  glVertex2d(0 - 1.4, 0);
260  glVertex2d(0 + 1.4, 6);
261  glEnd();
262  // draw "U"
264  // set text color
265  RGBColor textColor;
268  } else {
269  textColor = RGBColor::BLACK;
270  }
271  // get probability
272  const std::string probability = toString(getParentAdditionals().front()->getAttributeDouble(SUMO_ATTR_PROB) * 100) + "%";
273  // draw U
274  GLHelper::drawText("U", Position(0, 2), .1, 3, textColor, 180);
275  // draw Probability
276  GLHelper::drawText(probability.c_str(), Position(0, 4), .1, 0.7, textColor, 180);
277  }
278  // pop symbol matrix
280  }
281  // pop layer matrix
283 }
284 
285 
286 void
287 GNERerouterSymbol::setAttribute(SumoXMLAttr /*key*/, const std::string& /*value*/) {
288  throw InvalidArgument("Symbols cannot be edited");
289 }
290 
291 
292 void
294  // nothing to do
295 }
296 
297 
298 void
299 GNERerouterSymbol::commitMoveShape(const GNEMoveResult& /*moveResult*/, GNEUndoList* /*undoList*/) {
300  // nothing to do
301 }
302 
303 /****************************************************************************/
@ NETWORK_MOVE
mode for moving network elements
@ GLO_REROUTER
a Rerouter
GUIIcon
An enumeration of icons used by the gui applications.
Definition: GUIIcons.h:33
@ SVC_PEDESTRIAN
pedestrian
@ GNE_TAG_REROUTER_SYMBOL
Rerouter Symbol.
SumoXMLAttr
Numbers representing SUMO-XML - attributes.
@ SUMO_ATTR_EDGE
@ SUMO_ATTR_PROB
@ SUMO_ATTR_ID
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 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
An Element which don't belong to GNENet but has influence in the simulation.
Definition: GNEAdditional.h:49
GNEContour myAdditionalContour
variable used for draw additional contours
GUIGeometry myAdditionalGeometry
geometry to be precomputed in updateGeometry(...)
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
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
static const Parameterised::Map PARAMETERS_EMPTY
empty parameter maps (used by ACs without parameters)
GNENet * myNet
pointer to net
void calculateContourRectangleShape(const GUIVisualizationSettings &s, const GUIVisualizationSettings::Detail d, const GUIGlObject *glObject, const Position &pos, const double width, const double height, const double offsetX, const double offsetY, const double rot, const double scale) const
calculate contour (for rectangled elements)
Definition: GNEContour.cpp:103
void drawDottedContours(const GUIVisualizationSettings &s, const GUIVisualizationSettings::Detail d, const GNEAttributeCarrier *AC, const double lineWidth, const bool addOffset) const
drawing contour functions
Definition: GNEContour.cpp:263
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
A NBNetBuilder extended by visualisation and editing capabilities.
Definition: GNENet.h:42
GNEViewNet * getViewNet() const
get view net
Definition: GNENet.cpp:2056
const Parameterised::Map & getACParametersMap() const
get parameters map
GNEMoveOperation * getMoveOperation()
get move operation
std::string getParentName() const
Returns the name (ID) of the parent object.
bool isValid(SumoXMLAttr key, const std::string &value)
method for checking if the key and their correspondent attribute are valids
std::vector< GUIGeometry > mySymbolGeometries
symbols geometries
void drawGL(const GUIVisualizationSettings &s) const
Draws the object.
bool checkDrawMoveContour() const
check if draw move contour (red)
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
write additional element into a xml file
void drawRerouterSymbol(const GUIVisualizationSettings &s, const GUIVisualizationSettings::Detail d, const double exaggeration) const
draw rerouter symbol
void updateGeometry()
update pre-computed geometry information
std::string getAttribute(SumoXMLAttr key) const
~GNERerouterSymbol()
Destructor.
void setMoveShape(const GNEMoveResult &moveResult)
set move shape
std::string getAdditionalProblem() const
return a string with the current additional problem (must be reimplemented in all detector children)
bool isAdditionalValid() const
check if current additional is valid to be written into XML (must be reimplemented in all detector ch...
GNERerouterSymbol(GNENet *net)
default Constructor
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
void fixAdditionalProblem()
fix additional problem (must be reimplemented in all detector children)
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 GUIGlObject * getGUIGlObjectFront() const
get front attribute carrier or a pointer to nullptr
const GNEViewNetHelper::DataViewOptions & getDataViewOptions() const
get data view options
Definition: GNEViewNet.cpp:727
const GNEViewNetHelper::EditModes & getEditModes() const
get edit modes
Definition: GNEViewNet.cpp:703
void drawTranslateFrontAttributeCarrier(const GNEAttributeCarrier *AC, double typeOrLayer, const double extraOffset=0)
draw front attributeCarrier
bool isMovingElement() const
check if an element is being moved
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
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:59
Stores the information about how to visualize structures.
GUIVisualizationSizeSettings addSize
Detail getDetailLevel(const double exaggeration) const
return the detail level
GUIVisualizationColorSettings colorSettings
color settings
GUIVisualizationDottedContourSettings dottedContourSettings
dotted contour settings
bool drawForViewObjectsHandler
whether drawing is performed for the purpose of selecting objects in view using ViewObjectsHandler
GUIVisualizationAdditionalSettings additionalSettings
Additional settings.
The representation of a single edge during network building.
Definition: NBEdge.h:92
SVCPermissions getPermissions(int lane=-1) const
get the union of allowed classes over all lanes or for a specific lane
Definition: NBEdge.cpp:4306
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:61
std::map< std::string, std::string > Map
parameters map
Definition: Parameterised.h:45
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:200
bool showAdditionals() const
check if additionals has to be drawn
static const RGBColor connectionColor
connection color
RGBColor selectedAdditionalColor
additional selection color (busStops, Detectors...)
static const double segmentWidth
width of dotted contour segments
double getExaggeration(const GUIVisualizationSettings &s, const GUIGlObject *o, double factor=20) const
return the drawing size including exaggeration and constantSize values