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.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 /****************************************************************************/
19 // The gui-version of a MSOverheadWire
20 /****************************************************************************/
21 #include <config.h>
22 
23 #include <string>
26 #include <utils/geom/Boundary.h>
27 #include <utils/geom/GeomHelper.h>
28 #include <utils/gui/div/GLHelper.h>
29 #include <utils/common/ToString.h>
31 #include <microsim/MSNet.h>
32 #include <microsim/MSLane.h>
33 #include <microsim/MSEdge.h>
36 #include <gui/GUIGlobals.h>
44 #include <microsim/MSVehicleType.h>
45 #include "GUINet.h"
46 #include "GUIEdge.h"
47 #include "GUIPerson.h"
48 #include "GUIOverheadWire.h"
49 
50 
51 // ===========================================================================
52 // method definitions
53 // ===========================================================================
54 GUIOverheadWire::GUIOverheadWire(const std::string& id, MSLane& lane, double frompos, double topos, bool voltageSource) :
55  MSOverheadWire(id, lane, frompos, topos, voltageSource),
57  myFGShape = lane.getShape();
59  lane.interpolateLanePosToGeometryPos(frompos),
61  myFGShapeRotations.reserve(myFGShape.size() - 1);
62  myFGShapeLengths.reserve(myFGShape.size() - 1);
63  int e = (int)myFGShape.size() - 1;
64  for (int i = 0; i < e; ++i) {
65  const Position& f = myFGShape[i];
66  const Position& s = myFGShape[i + 1];
67  myFGShapeLengths.push_back(f.distanceTo(s));
68  myFGShapeRotations.push_back((double)atan2((s.x() - f.x()), (f.y() - s.y())) * (double) 180.0 / (double)M_PI);
69  }
71  tmp.move2side(1.5);
72 
73  // position of the centre of the lane + move2side
74  //myFGSignPos = tmp.getLineCenter();
75 
76  // position of beginning of the lane + move2side (2 equivallent commands ?)
77  //myFGSignPos = tmp.positionAtOffset(double(0.0));
78  myFGSignPos = tmp[0];
79 
80  myFGSignRot = 0;
81  if (tmp.length() != 0) {
83  myFGSignRot -= 90;
84  }
85 }
86 
87 
89 }
90 
91 GUIOverheadWireClamp::GUIOverheadWireClamp(const std::string& id, MSLane& lane_start, MSLane& lane_end) :
93  myFGShape.clear();
94  myFGShape.push_back(lane_start.getShape().front());
95  myFGShape.push_back(lane_end.getShape().back());
96 }
97 
99 }
100 
103  // Create table items
104  GUIParameterTableWindow* ret = new GUIParameterTableWindow(app, *this);
105 
106  // add items
107  ret->mkItem("begin position [m]", false, myBegPos);
108  ret->mkItem("end position [m]", false, myEndPos);
109  //ret->mkItem("voltage [V]", false, myVoltage);
110 
111  // close building
112  ret->closeBuilding();
113  return ret;
114 }
115 
116 
119  GUIGLObjectPopupMenu* ret = new GUIGLObjectPopupMenu(app, parent, *this);
120  buildPopupHeader(ret, app);
125  buildPositionCopyEntry(ret, false);
126  return ret;
127 }
128 
129 
130 double
132  return s.addSize.getExaggeration(s, this);
133 }
134 
135 
136 Boundary
139  b.grow(20);
140  return b;
141 }
142 
143 
144 void
146  // Draw overhead wire segment
149  RGBColor lightgray(211, 211, 211, 255);
150  RGBColor green(76, 170, 50, 255);
151  RGBColor yellow(255, 235, 0, 255);
152  RGBColor yellowCharge(255, 180, 0, 255);
153  RGBColor redCharge(255, 51, 51, 255);
154  RGBColor redChargeOverheadWire(180, 0, 0, 255);
155 
156  GUIColorScheme scheme = GUIColorScheme("by overhead wire current", RGBColor::BLACK, "road", true);
157  double range = 200;
158  scheme.clear();
159  scheme.addColor(RGBColor::RED, (0));
160  scheme.addColor(RGBColor::ORANGE, (range * 1 / 6.0));
161  scheme.addColor(RGBColor::YELLOW, (range * 2 / 6.0));
162  scheme.addColor(RGBColor::GREEN, (range * 3 / 6.0));
163  scheme.addColor(RGBColor::CYAN, (range * 4 / 6.0));
164  scheme.addColor(RGBColor::BLUE, (range * 5 / 6.0));
165  scheme.addColor(RGBColor::MAGENTA, (200));
166 
167  // draw the area depending if the vehicle is charging
168  glTranslated(0, 0, getType());
169 
170  // get relative line thickness
171  const double exaggeration = getExaggeration(s);
172 
173  //right catenary
174  double toPos = getEndLanePosition();
175  double fromPos = 0;
176  PositionVector myFGShape_aux = myFGShape;
177  const MSLane& lane_aux = getLane();
178  std::vector<double> myFGShapeRotations_aux;
179  std::vector<double> myFGShapeLengths_aux;
180  int e_aux = 0;
181  Node* node = NULL;
182  double voltage = 0;
183 
184  if (myCircuitStartNodePos != NULL) {
185  voltage = myCircuitStartNodePos->getVoltage();
186  GLHelper::setColor(scheme.getColor(MAX2(0.0, voltage - 400)));
187  }
188 
189  Circuit* circuit = getCircuit();
190  // loop over charging vehicles under the overhead wire segment to color the wire segment parts according to the voltage level
191  // lock access to myChargingVehicles
192  lock();
193  for (auto it = myChargingVehicles.begin(); it != myChargingVehicles.end(); ++it) {
194  // position of the vehicle on the lane
195  fromPos = (*it)->getPositionOnLane() - ((*it)->getVehicleType().getLength() / 2);
196  if (fromPos < 0) {
197  fromPos = 0;
198  };
199 
200  myFGShape_aux = myFGShape;
201  myFGShape_aux = myFGShape_aux.getSubpart(
202  lane_aux.interpolateLanePosToGeometryPos(fromPos),
203  lane_aux.interpolateLanePosToGeometryPos(toPos));
204 
205  myFGShapeRotations_aux.clear();
206  myFGShapeLengths_aux.clear();
207 
208  myFGShapeRotations_aux.reserve(myFGShape.size() - 1);
209  myFGShapeLengths_aux.reserve(myFGShape.size() - 1);
210 
211  e_aux = (int)myFGShape_aux.size() - 1;
212  for (int i = 0; i < e_aux; ++i) {
213  const Position& f_aux = myFGShape_aux[i];
214  const Position& s_aux = myFGShape_aux[i + 1];
215  myFGShapeLengths_aux.push_back(f_aux.distanceTo(s_aux));
216  myFGShapeRotations_aux.push_back((double)atan2((s_aux.x() - f_aux.x()), (f_aux.y() - s_aux.y())) * (double) 180.0 / (double)M_PI);
217  }
218 
219  voltage = 0;
220  if (circuit != nullptr) {
221  // RICE_CHECK: it caused crash of SUMO GUI often in debug mode and
222  // vector "_STL_VERIFY(_Mycont->_Myfirst <= _Ptr && _Ptr < _Mycont->_Mylast,
223  // "can't dereference out of range vector iterator"); "
224  circuit->lock();
225  node = circuit->getNode("pos_" + (*it)->getID());
226  if (node != nullptr) {
227  voltage = node->getVoltage();
228  }
229  circuit->unlock();
230  }
231  GLHelper::setColor(scheme.getColor(MAX2(0.0, voltage - 400)));
232  GLHelper::drawBoxLines(myFGShape_aux, myFGShapeRotations_aux, myFGShapeLengths_aux, exaggeration / 8, 0, 0.5);
233 
234  toPos = fromPos;
235  }
236  unlock();
237 
238  // coloring the last remaining part of wire's segment
239  myFGShape_aux = myFGShape;
240 
241  myFGShape_aux = myFGShape_aux.getSubpart(
243  lane_aux.interpolateLanePosToGeometryPos(toPos));
244 
245  myFGShapeRotations_aux.clear();
246  myFGShapeLengths_aux.clear();
247 
248  myFGShapeRotations_aux.reserve(myFGShape.size() - 1);
249  myFGShapeLengths_aux.reserve(myFGShape.size() - 1);
250 
251  e_aux = (int)myFGShape_aux.size() - 1;
252  for (int i = 0; i < e_aux; ++i) {
253  const Position& f_aux = myFGShape_aux[i];
254  const Position& s_aux = myFGShape_aux[i + 1];
255  myFGShapeLengths_aux.push_back(f_aux.distanceTo(s_aux));
256  myFGShapeRotations_aux.push_back((double)atan2((s_aux.x() - f_aux.x()), (f_aux.y() - s_aux.y())) * (double) 180.0 / (double)M_PI);
257  }
258  GLHelper::drawBoxLines(myFGShape_aux, myFGShapeRotations_aux, myFGShapeLengths_aux, exaggeration / 8, 0, 0.5);
259 
260 
261  //left catenary
262  //coloring of left-side overhead wire segment in case of
263  // * a vehicle is under the segment
264  // * a vehicle is at least under the traction substation of the segment
265  // * no vehicle is connected to the traction substation of the segment
266  if (getElecHybridCount() > 0) {
267  GLHelper::setColor(redChargeOverheadWire);
268  } else if (myTractionSubstation != NULL && myTractionSubstation->getElecHybridCount() > 0) {
269  GLHelper::setColor(yellowCharge);
270  } else {
271  GLHelper::setColor(green);
272  }
274 
275 
276  // draw details unless zoomed out to far
277  if (s.scale * exaggeration >= 10 && myVoltageSource) {
278 
279  // push charging power matrix
281  // draw charging power
282  GLHelper::drawText((toString(getTractionSubstation()->getSubstationVoltage()) + " V").c_str(), myFGSignPos + Position(1.2, 0), .1, 1.f, RGBColor(114, 210, 252), myFGSignRot, FONS_ALIGN_LEFT);
283  // pop charging power matrix
285 
286  // draw the sign
287  glTranslated(myFGSignPos.x(), myFGSignPos.y(), 0);
288  int noPoints = 9;
289  if (s.scale * exaggeration > 25) {
290  noPoints = MIN2((int)(9.0 + (s.scale * exaggeration) / 10.0), 36);
291  }
292 
293  glScaled(exaggeration, exaggeration, 1);
294  GLHelper::drawFilledCircle((double) 1.1, noPoints);
295  glTranslated(0, 0, .1);
296 
297  GLHelper::setColor(yellow);
298  GLHelper::drawFilledCircle((double) 0.9, noPoints);
299 
300  if (s.scale * exaggeration >= 4.5) {
301  GLHelper::drawText("C", Position(), .1, 1.6, lightgray, myFGSignRot);
302  }
303 
304  glTranslated(5, 0, 0);
305 
306  }
307 
308 
311  drawName(getCenteringBoundary().getCenter(), s.scale, s.addName);
312 }
313 
314 
317  // Create table items
318  GUIParameterTableWindow* ret = new GUIParameterTableWindow(app, *this);
319 
320  // add items
321  //ret->mkItem("begin position [m]", false, NAN);
322  //ret->mkItem("end position [m]", false, NAN);
323  //ret->mkItem("voltage [V]", false, NAN);
324 
325  // close building
326  ret->closeBuilding();
327  return ret;
328 }
329 
330 
333  GUIGLObjectPopupMenu* ret = new GUIGLObjectPopupMenu(app, parent, *this);
334  buildPopupHeader(ret, app);
339  buildPositionCopyEntry(ret, false);
340  return ret;
341 }
342 
343 
344 double
346  return s.addSize.getExaggeration(s, this);
347 }
348 
349 
350 Boundary
353  b.grow(20);
354  return b;
355 }
356 
357 
358 void
360  // Draw overhead wire segment
363  RGBColor lightgray(211, 211, 211, 255);
364  RGBColor green(76, 170, 50, 255);
365  RGBColor yellow(255, 235, 0, 255);
366  RGBColor yellowCharge(255, 180, 0, 255);
367  RGBColor redCharge(255, 51, 51, 255);
368  RGBColor redChargeOverheadWire(180, 0, 0, 255);
369 
370  // draw the area depending if the vehicle is charging
371  glTranslated(0, 0, getType());
372 
373 
374  GLHelper::setColor(redChargeOverheadWire);
375 
376 
377  const double exaggeration = getExaggeration(s);
378  //exaggeration - wide of line
379 
380 
381 
382  PositionVector myFGShape_aux = myFGShape;
383  std::vector<double> myFGShapeRotations_aux;
384  std::vector<double> myFGShapeLengths_aux;
385 
386  myFGShapeRotations_aux.clear();
387  myFGShapeLengths_aux.clear();
388 
389  myFGShapeRotations_aux.reserve(myFGShape.size() - 1);
390  myFGShapeLengths_aux.reserve(myFGShape.size() - 1);
391 
392  int e_aux = (int)myFGShape_aux.size() - 1;
393  for (int i = 0; i < e_aux; ++i) {
394  const Position& f_aux = myFGShape_aux[i];
395  const Position& s_aux = myFGShape_aux[i + 1];
396  myFGShapeLengths_aux.push_back(f_aux.distanceTo(s_aux));
397  myFGShapeRotations_aux.push_back((double)atan2((s_aux.x() - f_aux.x()), (f_aux.y() - s_aux.y())) * (double) 180.0 / (double)M_PI);
398  }
399 
400  //GLHelper::setColor(green);
401  GLHelper::drawBoxLines(myFGShape_aux, myFGShapeRotations_aux, myFGShapeLengths_aux, exaggeration / 8, 0, 0.5);
402 
403  //GLHelper::drawBoxLines(myFGShape, myFGShapeRotations, myFGShapeLengths, exaggeration / 8, 0, -0.5);
404 
405 
406 
409  drawName(getCenteringBoundary().getCenter(), s.scale, s.addName);
410 }
411 
412 
413 /****************************************************************************/
@ GLO_OVERHEAD_WIRE_SEGMENT
a segment of an overhead line
GUIPropertyScheme< RGBColor > GUIColorScheme
T MIN2(T a, T b)
Definition: StdDefs.h:74
T MAX2(T a, T b)
Definition: StdDefs.h:80
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:299
void unlock()
Definition: Circuit.cpp:206
void lock()
Definition: Circuit.cpp:202
Node * getNode(std::string name)
Definition: Circuit.cpp:111
static void setColor(const RGBColor &c)
Sets the gl-color to this value.
Definition: GLHelper.cpp:507
static void drawFilledCircle(double width, int steps=8)
Draws a filled circle around (0,0)
Definition: GLHelper.cpp:431
static void pushName(unsigned int name)
push Name
Definition: GLHelper.cpp:132
static void popMatrix()
pop matrix
Definition: GLHelper.cpp:123
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:277
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
The popup menu of a globject.
void buildPositionCopyEntry(GUIGLObjectPopupMenu *ret, bool addSeparator=true)
Builds an entry which allows to copy the cursor position if geo projection is used,...
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.
void buildSelectionPopupEntry(GUIGLObjectPopupMenu *ret, bool addSeparator=true)
Builds an entry which allows to (de)select the object.
GUIGlID getGlID() const
Returns the numerical id of the object.
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 asociated 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 asociated 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.
const 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)
Representation of a lane in the micro simulation.
Definition: MSLane.h:82
const PositionVector & getShape() const
Returns this lane's shape.
Definition: MSLane.h:478
double interpolateLanePosToGeometryPos(double lanePos) const
Definition: MSLane.h:499
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:52
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 dimension
Definition: Position.h:242
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 ammount
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:40
double getExaggeration(const GUIVisualizationSettings &s, const GUIGlObject *o, double factor=20) const
return the drawing size including exaggeration and constantSize values