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-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 /****************************************************************************/
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/gui/div/GLHelper.h>
28 #include <utils/common/ToString.h>
29 #include <microsim/MSNet.h>
30 #include <microsim/MSLane.h>
31 #include <microsim/MSEdge.h>
32 #include "GUINet.h"
33 #include "GUIEdge.h"
34 #include "GUIPerson.h"
35 #include "GUIOverheadWire.h"
38 #include <gui/GUIGlobals.h>
44 #include <utils/geom/GeomHelper.h>
47 #include <microsim/MSVehicleType.h>
48 
49 
50 // ===========================================================================
51 // method definitions
52 // ===========================================================================
53 GUIOverheadWire::GUIOverheadWire(const std::string& id, MSLane& lane, double frompos, double topos, bool voltageSource) :
54  MSOverheadWire(id, lane, frompos, topos, voltageSource),
56  myFGShape = lane.getShape();
58  lane.interpolateLanePosToGeometryPos(frompos),
60  myFGShapeRotations.reserve(myFGShape.size() - 1);
61  myFGShapeLengths.reserve(myFGShape.size() - 1);
62  int e = (int)myFGShape.size() - 1;
63  for (int i = 0; i < e; ++i) {
64  const Position& f = myFGShape[i];
65  const Position& s = myFGShape[i + 1];
66  myFGShapeLengths.push_back(f.distanceTo(s));
67  myFGShapeRotations.push_back((double)atan2((s.x() - f.x()), (f.y() - s.y())) * (double) 180.0 / (double)M_PI);
68  }
70  tmp.move2side(1.5);
71 
72  // position of the centre of the lane + move2side
73  //myFGSignPos = tmp.getLineCenter();
74 
75  // position of beginning of the lane + move2side (2 equivallent commands ?)
76  //myFGSignPos = tmp.positionAtOffset(double(0.0));
77  myFGSignPos = tmp[0];
78 
79  myFGSignRot = 0;
80  if (tmp.length() != 0) {
82  myFGSignRot -= 90;
83  }
84 }
85 
86 
88 }
89 
90 GUIOverheadWireClamp::GUIOverheadWireClamp(const std::string& id, MSLane& lane_start, MSLane& lane_end) :
92  myFGShape.clear();
93  myFGShape.push_back(lane_start.getShape().front());
94  myFGShape.push_back(lane_end.getShape().back());
95 }
96 
98 }
99 
102  // Create table items
103  GUIParameterTableWindow* ret = new GUIParameterTableWindow(app, *this);
104 
105  // add items
106  ret->mkItem("begin position [m]", false, myBegPos);
107  ret->mkItem("end position [m]", false, myEndPos);
108  //ret->mkItem("voltage [V]", false, myVoltage);
109 
110  // close building
111  ret->closeBuilding();
112  return ret;
113 }
114 
115 
118  GUIGLObjectPopupMenu* ret = new GUIGLObjectPopupMenu(app, parent, *this);
119  buildPopupHeader(ret, app);
124  buildPositionCopyEntry(ret, false);
125  return ret;
126 }
127 
128 Boundary
131  b.grow(20);
132  return b;
133 }
134 
135 
136 void
138  // Draw overhead wire segment
139  glPushName(getGlID());
140  glPushMatrix();
141  RGBColor lightgray(211, 211, 211, 255);
142  RGBColor green(76, 170, 50, 255);
143  RGBColor yellow(255, 235, 0, 255);
144  RGBColor yellowCharge(255, 180, 0, 255);
145  RGBColor redCharge(255, 51, 51, 255);
146  RGBColor redChargeOverheadWire(180, 0, 0, 255);
147 
148  GUIColorScheme scheme = GUIColorScheme("by overhead wire current", RGBColor::BLACK, "road", true);
149  double range = 200;
150  scheme.clear();
151  scheme.addColor(RGBColor::RED, (0));
152  scheme.addColor(RGBColor::ORANGE, (range * 1 / 6.0));
153  scheme.addColor(RGBColor::YELLOW, (range * 2 / 6.0));
154  scheme.addColor(RGBColor::GREEN, (range * 3 / 6.0));
155  scheme.addColor(RGBColor::CYAN, (range * 4 / 6.0));
156  scheme.addColor(RGBColor::BLUE, (range * 5 / 6.0));
157  scheme.addColor(RGBColor::MAGENTA, (200));
158 
159  // draw the area depending if the vehicle is charging
160  glTranslated(0, 0, getType());
161 
162  //right catenary
163  if (getElecHybridCount() > 0) {
164  GLHelper::setColor(redChargeOverheadWire);
165  } else if (myTractionSubstation != NULL && myTractionSubstation->getElecHybridCount() > 0) {
166  //GLHelper::setColor(redCharge);
167  GLHelper::setColor(yellowCharge);
168  } else {
169  //GLHelper::setColor(lightgray);
170  GLHelper::setColor(green);
171  }
172 
173  const double exaggeration = s.addSize.getExaggeration(s, this);
174  //exaggeration - wide of line
175 
176 
177  //right catenary
178  double toPos = getEndLanePosition();
179  double fromPos = 0;
180  PositionVector myFGShape_aux = myFGShape;
181  const MSLane& lane_aux = getLane();
182  std::vector<double> myFGShapeRotations_aux;
183  std::vector<double> myFGShapeLengths_aux;
184  int e_aux = 0;
185  Node* node = NULL;
186  double voltage = 0;
187 
188  if (myCircuitStartNodePos != NULL) {
189  voltage = myCircuitStartNodePos->getVoltage();
190  GLHelper::setColor(scheme.getColor(MAX2(0.0, voltage - 400)));
191  }
192 
193  //TODORICE
194  //for (auto it = myChargingVehicles.begin(); it != myChargingVehicles.end(); ++it) {
195  for (std::vector<SUMOVehicle*>::const_iterator it = myChargingVehicles.begin(); it != myChargingVehicles.end(); ++it) {
196  fromPos = (*it)->getPositionOnLane() - ((*it)->getVehicleType().getLength() / 2);
197  if (fromPos < 0) {
198  fromPos = 0;
199  };
200 
201  myFGShape_aux = myFGShape;
202  myFGShape_aux = myFGShape_aux.getSubpart(
203  lane_aux.interpolateLanePosToGeometryPos(fromPos),
204  lane_aux.interpolateLanePosToGeometryPos(toPos));
205 
206  myFGShapeRotations_aux.clear();
207  myFGShapeLengths_aux.clear();
208 
209  myFGShapeRotations_aux.reserve(myFGShape.size() - 1);
210  myFGShapeLengths_aux.reserve(myFGShape.size() - 1);
211 
212  e_aux = (int)myFGShape_aux.size() - 1;
213  for (int i = 0; i < e_aux; ++i) {
214  const Position& f_aux = myFGShape_aux[i];
215  const Position& s_aux = myFGShape_aux[i + 1];
216  myFGShapeLengths_aux.push_back(f_aux.distanceTo(s_aux));
217  myFGShapeRotations_aux.push_back((double)atan2((s_aux.x() - f_aux.x()), (f_aux.y() - s_aux.y())) * (double) 180.0 / (double)M_PI);
218  }
219 
220  voltage = 0;
221  if (getCircuit() != nullptr) {
222  //TODORICE it causes crash of SUMO GUI often in debug mode and
223  // vector "_STL_VERIFY(_Mycont->_Myfirst <= _Ptr && _Ptr < _Mycont->_Mylast,
224  //"can't dereference out of range vector iterator"); "
225  node = getCircuit()->getNode("pos_" + (*it)->getID());
226  if (node != nullptr) {
227  voltage = node->getVoltage();
228  }
229  }
230  GLHelper::setColor(scheme.getColor(MAX2(0.0, voltage - 400)));
231  GLHelper::drawBoxLines(myFGShape_aux, myFGShapeRotations_aux, myFGShapeLengths_aux, exaggeration / 8, 0, 0.5);
232 
233  toPos = fromPos;
234  }
235 
236  myFGShape_aux = myFGShape;
237 
238  myFGShape_aux = myFGShape_aux.getSubpart(
240  lane_aux.interpolateLanePosToGeometryPos(toPos));
241 
242  myFGShapeRotations_aux.clear();
243  myFGShapeLengths_aux.clear();
244 
245  myFGShapeRotations_aux.reserve(myFGShape.size() - 1);
246  myFGShapeLengths_aux.reserve(myFGShape.size() - 1);
247 
248  e_aux = (int)myFGShape_aux.size() - 1;
249  for (int i = 0; i < e_aux; ++i) {
250  const Position& f_aux = myFGShape_aux[i];
251  const Position& s_aux = myFGShape_aux[i + 1];
252  myFGShapeLengths_aux.push_back(f_aux.distanceTo(s_aux));
253  myFGShapeRotations_aux.push_back((double)atan2((s_aux.x() - f_aux.x()), (f_aux.y() - s_aux.y())) * (double) 180.0 / (double)M_PI);
254  }
255 
256  //GLHelper::setColor(green);
257  GLHelper::drawBoxLines(myFGShape_aux, myFGShapeRotations_aux, myFGShapeLengths_aux, exaggeration / 8, 0, 0.5);
258 
259 
260  //left catenary
261  if (getElecHybridCount() > 0) {
262  //GLHelper::setColor(yellowCharge);
263  GLHelper::setColor(redChargeOverheadWire);
264  } else if (myTractionSubstation != NULL && myTractionSubstation->getElecHybridCount() > 0) {
265  //GLHelper::setColor(yellow);
266  GLHelper::setColor(yellowCharge);
267  } else {
268  //GLHelper::setColor(lightgray);
269  GLHelper::setColor(green);
270  }
272 
273  //a catenary in the centre of lane
274  //GLHelper::drawBoxLines(myFGShape, myFGShapeRotations, myFGShapeLengths, exaggeration / 4);
275 
276  // draw details unless zoomed out to far
277  if (s.scale * exaggeration >= 10 && myVoltageSource) {
278 
279  // push charging power matrix
280  glPushMatrix();
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
284  glPopMatrix();
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 
309  glPopMatrix();
310  glPopName();
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 Boundary
347  b.grow(20);
348  return b;
349 }
350 
351 
352 void
354  // Draw overhead wire segment
355  glPushName(getGlID());
356  glPushMatrix();
357  RGBColor lightgray(211, 211, 211, 255);
358  RGBColor green(76, 170, 50, 255);
359  RGBColor yellow(255, 235, 0, 255);
360  RGBColor yellowCharge(255, 180, 0, 255);
361  RGBColor redCharge(255, 51, 51, 255);
362  RGBColor redChargeOverheadWire(180, 0, 0, 255);
363 
364  // draw the area depending if the vehicle is charging
365  glTranslated(0, 0, getType());
366 
367 
368  GLHelper::setColor(redChargeOverheadWire);
369 
370 
371  const double exaggeration = s.addSize.getExaggeration(s, this);
372  //exaggeration - wide of line
373 
374 
375 
376  PositionVector myFGShape_aux = myFGShape;
377  std::vector<double> myFGShapeRotations_aux;
378  std::vector<double> myFGShapeLengths_aux;
379 
380  myFGShapeRotations_aux.clear();
381  myFGShapeLengths_aux.clear();
382 
383  myFGShapeRotations_aux.reserve(myFGShape.size() - 1);
384  myFGShapeLengths_aux.reserve(myFGShape.size() - 1);
385 
386  int e_aux = (int)myFGShape_aux.size() - 1;
387  for (int i = 0; i < e_aux; ++i) {
388  const Position& f_aux = myFGShape_aux[i];
389  const Position& s_aux = myFGShape_aux[i + 1];
390  myFGShapeLengths_aux.push_back(f_aux.distanceTo(s_aux));
391  myFGShapeRotations_aux.push_back((double)atan2((s_aux.x() - f_aux.x()), (f_aux.y() - s_aux.y())) * (double) 180.0 / (double)M_PI);
392  }
393 
394  //GLHelper::setColor(green);
395  GLHelper::drawBoxLines(myFGShape_aux, myFGShapeRotations_aux, myFGShapeLengths_aux, exaggeration / 8, 0, 0.5);
396 
397  //GLHelper::drawBoxLines(myFGShape, myFGShapeRotations, myFGShapeLengths, exaggeration / 8, 0, -0.5);
398 
399 
400 
401  glPopMatrix();
402  glPopName();
403  drawName(getCenteringBoundary().getCenter(), s.scale, s.addName);
404 }
405 
406 
407 /****************************************************************************/
@ GLO_OVERHEAD_WIRE_SEGMENT
a segment of an overhead line
GUIPropertyScheme< RGBColor > GUIColorScheme
T MIN2(T a, T b)
Definition: StdDefs.h:73
T MAX2(T a, T b)
Definition: StdDefs.h:79
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:44
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
Node * getNode(string name)
Definition: Circuit.cpp:98
static void setColor(const RGBColor &c)
Sets the gl-color to this value.
Definition: GLHelper.cpp:446
static void drawFilledCircle(double width, int steps=8)
Draws a filled circle around (0,0)
Definition: GLHelper.cpp:347
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:181
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
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) const
draw name of item
PositionVector myFGShape
The shape.
~GUIOverheadWireClamp()
Destructor.
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 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:476
double interpolateLanePosToGeometryPos(double lanePos) const
Definition: MSLane.h:497
Definition of overhead wire segment.
int getElecHybridCount() const
Node * myCircuitStartNodePos
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:31
double getVoltage()
Definition: Node.cpp:51
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:36
double distanceTo(const Position &p2) const
returns the euclidean distance in 3 dimension
Definition: Position.h:231
double x() const
Returns the x-position.
Definition: Position.h:54
double y() const
Returns the y-position.
Definition: Position.h:59
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:182
static const RGBColor YELLOW
Definition: RGBColor.h:183
static const RGBColor ORANGE
Definition: RGBColor.h:186
static const RGBColor CYAN
Definition: RGBColor.h:184
static const RGBColor GREEN
Definition: RGBColor.h:181
static const RGBColor BLACK
Definition: RGBColor.h:188
static const RGBColor MAGENTA
Definition: RGBColor.h:185
static const RGBColor RED
named colors
Definition: RGBColor.h:180
@ 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