Eclipse SUMO - Simulation of Urban MObility
GUIOverheadWire.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 /****************************************************************************/
20 // The gui-version of a MSOverheadWire
21 /****************************************************************************/
22 #include <config.h>
23 
24 #include <string>
27 #include <utils/geom/Boundary.h>
28 #include <utils/geom/GeomHelper.h>
29 #include <utils/gui/div/GLHelper.h>
30 #include <utils/common/ToString.h>
32 #include <microsim/MSNet.h>
33 #include <microsim/MSLane.h>
34 #include <microsim/MSEdge.h>
37 #include <gui/GUIGlobals.h>
45 #include <microsim/MSVehicleType.h>
46 #include "GUINet.h"
47 #include "GUIEdge.h"
48 #include "GUIPerson.h"
49 #include "GUIOverheadWire.h"
50 
51 
52 // ===========================================================================
53 // method definitions
54 // ===========================================================================
55 GUIOverheadWire::GUIOverheadWire(const std::string& id, MSLane& lane, double frompos, double topos, bool voltageSource) :
56  MSOverheadWire(id, lane, frompos, topos, voltageSource),
58  myFGShape = lane.getShape();
60  lane.interpolateLanePosToGeometryPos(frompos),
62  myFGShapeRotations.reserve(myFGShape.size() - 1);
63  myFGShapeLengths.reserve(myFGShape.size() - 1);
64  int e = (int)myFGShape.size() - 1;
65  for (int i = 0; i < e; ++i) {
66  const Position& f = myFGShape[i];
67  const Position& s = myFGShape[i + 1];
68  myFGShapeLengths.push_back(f.distanceTo(s));
69  myFGShapeRotations.push_back((double)atan2((s.x() - f.x()), (f.y() - s.y())) * (double) 180.0 / (double)M_PI);
70  }
72  tmp.move2side(1.5);
73 
74  // position of the centre of the lane + move2side
75  //myFGSignPos = tmp.getLineCenter();
76 
77  // position of beginning of the lane + move2side (2 equivallent commands ?)
78  //myFGSignPos = tmp.positionAtOffset(double(0.0));
79  myFGSignPos = tmp[0];
80 
81  myFGSignRot = 0;
82  if (tmp.length() != 0) {
84  const double rotSign = MSGlobals::gLefthand ? -1 : 1;
85  myFGSignRot -= 90 * rotSign;
86  }
87 }
88 
89 
91 }
92 
93 GUIOverheadWireClamp::GUIOverheadWireClamp(const std::string& id, MSLane& lane_start, MSLane& lane_end) :
95  myFGShape.clear();
96  myFGShape.push_back(lane_start.getShape().front());
97  myFGShape.push_back(lane_end.getShape().back());
98 }
99 
101 }
102 
105  // Create table items
106  GUIParameterTableWindow* ret = new GUIParameterTableWindow(app, *this);
107 
108  // add items
109  ret->mkItem(TL("begin position [m]"), false, myBegPos);
110  ret->mkItem(TL("end position [m]"), false, myEndPos);
111  //ret->mkItem(TL("voltage [V]"), false, myVoltage);
112 
113  // close building
114  ret->closeBuilding();
115  return ret;
116 }
117 
118 
121  GUIGLObjectPopupMenu* ret = new GUIGLObjectPopupMenu(app, parent, *this);
122  buildPopupHeader(ret, app);
127  buildPositionCopyEntry(ret, app);
128  return ret;
129 }
130 
131 
132 double
134  return s.addSize.getExaggeration(s, this);
135 }
136 
137 
138 Boundary
141  b.grow(20);
142  return b;
143 }
144 
145 
146 void
148  // Draw overhead wire segment
151  RGBColor lightgray(211, 211, 211, 255);
152  RGBColor green(76, 170, 50, 255);
153  RGBColor yellow(255, 235, 0, 255);
154  RGBColor yellowCharge(255, 180, 0, 255);
155  RGBColor redCharge(255, 51, 51, 255);
156  RGBColor redChargeOverheadWire(180, 0, 0, 255);
157 
158  GUIColorScheme scheme = GUIColorScheme("by overhead wire current", RGBColor::BLACK, "road", true);
159  double range = 200;
160  scheme.clear();
161  scheme.addColor(RGBColor::RED, (0));
162  scheme.addColor(RGBColor::ORANGE, (range * 1 / 6.0));
163  scheme.addColor(RGBColor::YELLOW, (range * 2 / 6.0));
164  scheme.addColor(RGBColor::GREEN, (range * 3 / 6.0));
165  scheme.addColor(RGBColor::CYAN, (range * 4 / 6.0));
166  scheme.addColor(RGBColor::BLUE, (range * 5 / 6.0));
167  scheme.addColor(RGBColor::MAGENTA, (200));
168 
169  // draw the area depending if the vehicle is charging
170  glTranslated(0, 0, getType());
171 
172  // get relative line thickness
173  const double exaggeration = getExaggeration(s);
174 
175  //right catenary
176  double toPos = getEndLanePosition();
177  double fromPos = 0;
178  PositionVector myFGShape_aux = myFGShape;
179  const MSLane& lane_aux = getLane();
180  std::vector<double> myFGShapeRotations_aux;
181  std::vector<double> myFGShapeLengths_aux;
182  int e_aux = 0;
183  Node* node = NULL;
184  double voltage = 0;
185 
186  if (myCircuitStartNodePos != NULL) {
187  voltage = myCircuitStartNodePos->getVoltage();
188  GLHelper::setColor(scheme.getColor(MAX2(0.0, voltage - 400)));
189  }
190 
191  Circuit* circuit = getCircuit();
192  // loop over charging vehicles under the overhead wire segment to color the wire segment parts according to the voltage level
193  // lock access to myChargingVehicles
194  lock();
195  for (auto it = myChargingVehicles.begin(); it != myChargingVehicles.end(); ++it) {
196  // position of the vehicle on the lane
197  fromPos = (*it)->getPositionOnLane() - ((*it)->getVehicleType().getLength() / 2);
198  if (fromPos < 0) {
199  fromPos = 0;
200  };
201 
202  myFGShape_aux = myFGShape;
203  myFGShape_aux = myFGShape_aux.getSubpart(
204  lane_aux.interpolateLanePosToGeometryPos(fromPos),
205  lane_aux.interpolateLanePosToGeometryPos(toPos));
206 
207  myFGShapeRotations_aux.clear();
208  myFGShapeLengths_aux.clear();
209 
210  myFGShapeRotations_aux.reserve(myFGShape.size() - 1);
211  myFGShapeLengths_aux.reserve(myFGShape.size() - 1);
212 
213  e_aux = (int)myFGShape_aux.size() - 1;
214  for (int i = 0; i < e_aux; ++i) {
215  const Position& f_aux = myFGShape_aux[i];
216  const Position& s_aux = myFGShape_aux[i + 1];
217  myFGShapeLengths_aux.push_back(f_aux.distanceTo(s_aux));
218  myFGShapeRotations_aux.push_back((double)atan2((s_aux.x() - f_aux.x()), (f_aux.y() - s_aux.y())) * (double) 180.0 / (double)M_PI);
219  }
220 
221  voltage = 0;
222  if (circuit != nullptr) {
223  // RICE_CHECK: it caused crash of SUMO GUI often in debug mode and
224  // vector "_STL_VERIFY(_Mycont->_Myfirst <= _Ptr && _Ptr < _Mycont->_Mylast,
225  // "can't dereference out of range vector iterator"); "
226  circuit->lock();
227  node = circuit->getNode("pos_" + (*it)->getID());
228  if (node != nullptr) {
229  voltage = node->getVoltage();
230  }
231  circuit->unlock();
232  }
233  GLHelper::setColor(scheme.getColor(MAX2(0.0, voltage - 400)));
234  GLHelper::drawBoxLines(myFGShape_aux, myFGShapeRotations_aux, myFGShapeLengths_aux, exaggeration / 8, 0, 0.5);
235 
236  toPos = fromPos;
237  }
238  unlock();
239 
240  // coloring the last remaining part of wire's segment
241  myFGShape_aux = myFGShape;
242 
243  myFGShape_aux = myFGShape_aux.getSubpart(
245  lane_aux.interpolateLanePosToGeometryPos(toPos));
246 
247  myFGShapeRotations_aux.clear();
248  myFGShapeLengths_aux.clear();
249 
250  myFGShapeRotations_aux.reserve(myFGShape.size() - 1);
251  myFGShapeLengths_aux.reserve(myFGShape.size() - 1);
252 
253  e_aux = (int)myFGShape_aux.size() - 1;
254  for (int i = 0; i < e_aux; ++i) {
255  const Position& f_aux = myFGShape_aux[i];
256  const Position& s_aux = myFGShape_aux[i + 1];
257  myFGShapeLengths_aux.push_back(f_aux.distanceTo(s_aux));
258  myFGShapeRotations_aux.push_back((double)atan2((s_aux.x() - f_aux.x()), (f_aux.y() - s_aux.y())) * (double) 180.0 / (double)M_PI);
259  }
260  GLHelper::drawBoxLines(myFGShape_aux, myFGShapeRotations_aux, myFGShapeLengths_aux, exaggeration / 8, 0, 0.5);
261 
262 
263  //left catenary
264  //coloring of left-side overhead wire segment in case of
265  // * a vehicle is under the segment
266  // * a vehicle is at least under the traction substation of the segment
267  // * no vehicle is connected to the traction substation of the segment
268  if (getElecHybridCount() > 0) {
269  GLHelper::setColor(redChargeOverheadWire);
270  } else if (myTractionSubstation != NULL && myTractionSubstation->getElecHybridCount() > 0) {
271  GLHelper::setColor(yellowCharge);
272  } else {
273  GLHelper::setColor(green);
274  }
276 
277 
278  // draw details unless zoomed out to far
279  if (s.scale * exaggeration >= 10 && myVoltageSource) {
280 
281  // push charging power matrix
283  // draw charging power
284  const double lineAngle = s.getTextAngle(myFGSignRot);
285  glTranslated(myFGSignPos.x(), myFGSignPos.y(), 0);
286  glRotated(-lineAngle, 0, 0, 1);
287  GLHelper::drawText((toString(getTractionSubstation()->getSubstationVoltage()) + " V").c_str(), Position(1.2, 0), .1, 1.f, RGBColor(114, 210, 252), 0, FONS_ALIGN_LEFT);
288  // pop charging power matrix
290 
291  // draw the sign
292  glTranslated(myFGSignPos.x(), myFGSignPos.y(), 0);
293  int noPoints = 9;
294  if (s.scale * exaggeration > 25) {
295  noPoints = MIN2((int)(9.0 + (s.scale * exaggeration) / 10.0), 36);
296  }
297 
298  glScaled(exaggeration, exaggeration, 1);
299  GLHelper::drawFilledCircle((double) 1.1, noPoints);
300  glTranslated(0, 0, .1);
301 
302  GLHelper::setColor(yellow);
303  GLHelper::drawFilledCircle((double) 0.9, noPoints);
304 
305  if (s.scale * exaggeration >= 4.5) {
306  GLHelper::drawText("C", Position(), .1, 1.6, lightgray, myFGSignRot);
307  }
308 
309  glTranslated(5, 0, 0);
310 
311  }
312 
313 
316  drawName(getCenteringBoundary().getCenter(), s.scale, s.addName);
317 }
318 
319 
322  // Create table items
323  GUIParameterTableWindow* ret = new GUIParameterTableWindow(app, *this);
324 
325  // add items
326  //ret->mkItem(TL("begin position [m]"), false, NAN);
327  //ret->mkItem(TL("end position [m]"), false, NAN);
328  //ret->mkItem(TL("voltage [V]"), false, NAN);
329 
330  // close building
331  ret->closeBuilding();
332  return ret;
333 }
334 
335 
338  GUIGLObjectPopupMenu* ret = new GUIGLObjectPopupMenu(app, parent, *this);
339  buildPopupHeader(ret, app);
344  buildPositionCopyEntry(ret, app);
345  return ret;
346 }
347 
348 
349 double
351  return s.addSize.getExaggeration(s, this);
352 }
353 
354 
355 Boundary
358  b.grow(20);
359  return b;
360 }
361 
362 
363 void
365  // Draw overhead wire segment
368  RGBColor lightgray(211, 211, 211, 255);
369  RGBColor green(76, 170, 50, 255);
370  RGBColor yellow(255, 235, 0, 255);
371  RGBColor yellowCharge(255, 180, 0, 255);
372  RGBColor redCharge(255, 51, 51, 255);
373  RGBColor redChargeOverheadWire(180, 0, 0, 255);
374 
375  // draw the area depending if the vehicle is charging
376  glTranslated(0, 0, getType());
377 
378 
379  GLHelper::setColor(redChargeOverheadWire);
380 
381 
382  const double exaggeration = getExaggeration(s);
383  //exaggeration - wide of line
384 
385 
386 
387  PositionVector myFGShape_aux = myFGShape;
388  std::vector<double> myFGShapeRotations_aux;
389  std::vector<double> myFGShapeLengths_aux;
390 
391  myFGShapeRotations_aux.clear();
392  myFGShapeLengths_aux.clear();
393 
394  myFGShapeRotations_aux.reserve(myFGShape.size() - 1);
395  myFGShapeLengths_aux.reserve(myFGShape.size() - 1);
396 
397  int e_aux = (int)myFGShape_aux.size() - 1;
398  for (int i = 0; i < e_aux; ++i) {
399  const Position& f_aux = myFGShape_aux[i];
400  const Position& s_aux = myFGShape_aux[i + 1];
401  myFGShapeLengths_aux.push_back(f_aux.distanceTo(s_aux));
402  myFGShapeRotations_aux.push_back((double)atan2((s_aux.x() - f_aux.x()), (f_aux.y() - s_aux.y())) * (double) 180.0 / (double)M_PI);
403  }
404 
405  //GLHelper::setColor(green);
406  GLHelper::drawBoxLines(myFGShape_aux, myFGShapeRotations_aux, myFGShapeLengths_aux, exaggeration / 8, 0, 0.5);
407 
408  //GLHelper::drawBoxLines(myFGShape, myFGShapeRotations, myFGShapeLengths, exaggeration / 8, 0, -0.5);
409 
410 
411 
414  drawName(getCenteringBoundary().getCenter(), s.scale, s.addName);
415 }
416 
417 
418 /****************************************************************************/
@ GLO_OVERHEAD_WIRE_SEGMENT
a segment of an overhead line
GUIIcon
An enumeration of icons used by the gui applications.
Definition: GUIIcons.h:33
@ OVERHEADWIRE
@ OVERHEADWIRE_CLAMP
GUIPropertyScheme< RGBColor > GUIColorScheme
#define TL(string)
Definition: MsgHandler.h:315
T MIN2(T a, T b)
Definition: StdDefs.h:76
T MAX2(T a, T b)
Definition: StdDefs.h:82
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:46
A class that stores a 2D geometrical boundary.
Definition: Boundary.h:39
Boundary & grow(double by)
extends the boundary by the given amount
Definition: Boundary.cpp:319
void unlock()
Definition: Circuit.cpp:193
void lock()
Definition: Circuit.cpp:189
Node * getNode(std::string name)
Definition: Circuit.cpp:98
static void setColor(const RGBColor &c)
Sets the gl-color to this value.
Definition: GLHelper.cpp:654
static void pushName(unsigned int name)
push Name
Definition: GLHelper.cpp:139
static void drawFilledCircle(const double widradiusth, const int steps=8)
Draws a filled circle around (0,0)
Definition: GLHelper.cpp:569
static void popMatrix()
pop matrix
Definition: GLHelper.cpp:130
static void drawBoxLines(const PositionVector &geom, const std::vector< double > &rots, const std::vector< double > &lengths, double width, int cornerDetail=0, double offset=0)
Draws thick lines.
Definition: GLHelper.cpp:347
static void popName()
pop Name
Definition: GLHelper.cpp:148
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:756
The popup menu of a globject.
void buildShowParamsPopupEntry(GUIGLObjectPopupMenu *ret, bool addSeparator=true)
Builds an entry which allows to open the parameter window.
void buildCenterPopupEntry(GUIGLObjectPopupMenu *ret, bool addSeparator=true)
Builds an entry which allows to center to the object.
void buildNameCopyPopupEntry(GUIGLObjectPopupMenu *ret, bool addSeparator=true)
Builds entries which allow to copy the name / typed name into the clipboard.
void buildPopupHeader(GUIGLObjectPopupMenu *ret, GUIMainWindow &app, bool addSeparator=true)
Builds the header.
GUIGlObjectType getType() const
Returns the type of the object as coded in GUIGlObjectType.
Definition: GUIGlObject.h:156
void buildSelectionPopupEntry(GUIGLObjectPopupMenu *ret, bool addSeparator=true)
Builds an entry which allows to (de)select the object.
void buildPositionCopyEntry(GUIGLObjectPopupMenu *ret, const GUIMainWindow &app) const
Builds an entry which allows to copy the cursor position if geo projection is used,...
GUIGlID getGlID() const
Returns the numerical id of the object.
Definition: GUIGlObject.h:104
void drawName(const Position &pos, const double scale, const GUIVisualizationTextSettings &settings, const double angle=0, bool forceShow=false) const
draw name of item
PositionVector myFGShape
The shape.
~GUIOverheadWireClamp()
Destructor.
double getExaggeration(const GUIVisualizationSettings &s) const
return exaggeration associated with this GLObject
Boundary getCenteringBoundary() const
Returns the boundary to which the view shall be centered in order to show the object.
GUIOverheadWireClamp(const std::string &id, MSLane &lane_start, MSLane &lane_end)
Constructor.
GUIGLObjectPopupMenu * getPopUpMenu(GUIMainWindow &app, GUISUMOAbstractView &parent)
Returns an own popup-menu.
void drawGL(const GUIVisualizationSettings &s) const
Draws the object.
GUIParameterTableWindow * getParameterWindow(GUIMainWindow &app, GUISUMOAbstractView &parent)
Returns an own parameter window.
PositionVector myFGShape
The shape.
~GUIOverheadWire()
Destructor.
void drawGL(const GUIVisualizationSettings &s) const
Draws the object.
std::vector< double > myFGShapeRotations
The rotations of the shape parts.
GUIGLObjectPopupMenu * getPopUpMenu(GUIMainWindow &app, GUISUMOAbstractView &parent)
Returns an own popup-menu.
GUIParameterTableWindow * getParameterWindow(GUIMainWindow &app, GUISUMOAbstractView &parent)
Returns an own parameter window.
GUIOverheadWire(const std::string &id, MSLane &lane, double frompos, double topos, bool voltageSource)
Constructor.
double getExaggeration(const GUIVisualizationSettings &s) const
return exaggeration associated with this GLObject
double myFGSignRot
The rotation of the sign.
Boundary getCenteringBoundary() const
Returns the boundary to which the view shall be centered in order to show the object.
std::vector< double > myFGShapeLengths
The lengths of the shape parts.
Position myFGSignPos
The position of the sign.
A window containing a gl-object's parameter.
void mkItem(const char *name, bool dynamic, ValueSource< T > *src)
Adds a row which obtains its value from a ValueSource.
void closeBuilding(const Parameterised *p=0)
Closes the building of the table.
T getColor(const double value) const
int addColor(const T &color, const double threshold, const std::string &name="")
Stores the information about how to visualize structures.
GUIVisualizationTextSettings addName
GUIVisualizationSizeSettings addSize
double scale
information about a lane's width (temporary, used for a single view)
double getTextAngle(double objectAngle) const
return an angle that is suitable for reading text aligned with the given angle (degrees)
static bool gLefthand
Whether lefthand-drive is being simulated.
Definition: MSGlobals.h:171
Representation of a lane in the micro simulation.
Definition: MSLane.h:84
double interpolateLanePosToGeometryPos(double lanePos) const
Definition: MSLane.h:546
virtual const PositionVector & getShape(bool) const
Definition: MSLane.h:294
Definition of overhead wire segment.
void unlock() const
int getElecHybridCount() const
Node * myCircuitStartNodePos
void lock() const
Circuit * getCircuit() const
MSTractionSubstation * getTractionSubstation() const
MSTractionSubstation * myTractionSubstation
Parameter, Pointer to the electrical substation (by default is nullptr)
std::vector< SUMOVehicle * > myChargingVehicles
const double myBegPos
The begin position this bus stop is located at.
double getBeginLanePosition() const
Returns the begin position of this stop.
const double myEndPos
The end position this bus stop is located at.
double getEndLanePosition() const
Returns the end position of this stop.
const MSLane & getLane() const
Returns the lane this stop is located at.
int getElecHybridCount() const
Definition: Node.h:39
double getVoltage()
Definition: Node.cpp:53
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:37
double distanceTo(const Position &p2) const
returns the euclidean distance in 3 dimensions
Definition: Position.h:266
double x() const
Returns the x-position.
Definition: Position.h:55
double y() const
Returns the y-position.
Definition: Position.h:60
A list of positions.
double length() const
Returns the length.
double rotationDegreeAtOffset(double pos) const
Returns the rotation at the given length.
void move2side(double amount, double maxExtension=100)
move position vector to side using certain amount
Boundary getBoxBoundary() const
Returns a boundary enclosing this list of lines.
PositionVector getSubpart(double beginOffset, double endOffset) const
get subpart of a position vector
static const RGBColor BLUE
Definition: RGBColor.h:187
static const RGBColor YELLOW
Definition: RGBColor.h:188
static const RGBColor ORANGE
Definition: RGBColor.h:191
static const RGBColor CYAN
Definition: RGBColor.h:189
static const RGBColor GREEN
Definition: RGBColor.h:186
static const RGBColor BLACK
Definition: RGBColor.h:193
static const RGBColor MAGENTA
Definition: RGBColor.h:190
static const RGBColor RED
named colors
Definition: RGBColor.h:185
@ FONS_ALIGN_LEFT
Definition: fontstash.h:42
#define M_PI
Definition: odrSpiral.cpp:45
double getExaggeration(const GUIVisualizationSettings &s, const GUIGlObject *o, double factor=20) const
return the drawing size including exaggeration and constantSize values