SUMO - Simulation of Urban MObility
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
GUIContainerStop.cpp
Go to the documentation of this file.
1 /****************************************************************************/
8 // A lane area vehicles can halt at (gui-version)
9 /****************************************************************************/
10 // SUMO, Simulation of Urban MObility; see http://sumo.dlr.de/
11 // Copyright (C) 2001-2015 DLR (http://www.dlr.de/) and contributors
12 /****************************************************************************/
13 //
14 // This file is part of SUMO.
15 // SUMO is free software: you can redistribute it and/or modify
16 // it under the terms of the GNU General Public License as published by
17 // the Free Software Foundation, either version 3 of the License, or
18 // (at your option) any later version.
19 //
20 /****************************************************************************/
21 
22 
23 // ===========================================================================
24 // included modules
25 // ===========================================================================
26 #ifdef _MSC_VER
27 #include <windows_config.h>
28 #else
29 #include <config.h>
30 #endif
31 
32 #include <string>
35 #include <utils/geom/Line.h>
36 #include <utils/geom/Boundary.h>
37 #include <utils/gui/div/GLHelper.h>
38 #include <utils/common/ToString.h>
39 #include <microsim/MSNet.h>
40 #include <microsim/MSLane.h>
41 #include <microsim/MSEdge.h>
42 #include "GUINet.h"
43 #include "GUIEdge.h"
44 #include "GUIContainer.h"
45 #include "GUIContainerStop.h"
48 #include <gui/GUIGlobals.h>
54 #include <utils/geom/GeomHelper.h>
57 
58 #ifdef CHECK_MEMORY_LEAKS
59 #include <foreign/nvwa/debug_new.h>
60 #endif // CHECK_MEMORY_LEAKS
61 
62 
63 // ===========================================================================
64 // method definitions
65 // ===========================================================================
66 GUIContainerStop::GUIContainerStop(const std::string& id, const std::vector<std::string>& lines, MSLane& lane,
67  SUMOReal frompos, SUMOReal topos)
68  : MSContainerStop(id, lines, lane, frompos, topos),
69  GUIGlObject_AbstractAdd("containerStop", GLO_TRIGGER, id) {
70  myFGShape = lane.getShape();
72  myFGShape = myFGShape.getSubpart(frompos, topos);
73  myFGShapeRotations.reserve(myFGShape.size() - 1);
74  myFGShapeLengths.reserve(myFGShape.size() - 1);
75  int e = (int) myFGShape.size() - 1;
76  for (int i = 0; i < e; ++i) {
77  const Position& f = myFGShape[i];
78  const Position& s = myFGShape[i + 1];
79  myFGShapeLengths.push_back(f.distanceTo(s));
80  myFGShapeRotations.push_back((SUMOReal) atan2((s.x() - f.x()), (f.y() - s.y())) * (SUMOReal) 180.0 / (SUMOReal) PI);
81  }
83  tmp.move2side(1.5);
84  myFGSignPos = tmp.getLineCenter();
85  myFGSignRot = 0;
86  if (tmp.length() != 0) {
88  myFGSignRot -= 90;
89  }
90 }
91 
92 
94 
95 
98  GUISUMOAbstractView& parent) {
99  GUIGLObjectPopupMenu* ret = new GUIGLObjectPopupMenu(app, parent, *this);
100  buildPopupHeader(ret, app);
105  buildPositionCopyEntry(ret, false);
106  return ret;
107 }
108 
109 
114  new GUIParameterTableWindow(app, *this, 4);
115  // add items
116  ret->mkItem("begin position [m]", false, myBegPos);
117  ret->mkItem("end position [m]", false, myEndPos);
119  // close building
120  ret->closeBuilding();
121  return ret;
122 }
123 
124 
125 void
127  glPushName(getGlID());
128  glPushMatrix();
129  RGBColor grey(177, 184, 186, 171);
130  RGBColor blue(83, 89, 172, 255);
131  // draw the area
132  size_t i;
133  glTranslated(0, 0, getType());
134  GLHelper::setColor(blue);
136  // draw details unless zoomed out to far
137  const SUMOReal exaggeration = s.addSize.getExaggeration(s);
138  if (s.scale * exaggeration >= 10) {
139  // draw the lines
140  for (i = 0; i != myLines.size(); ++i) {
141  glPushMatrix();
142  glTranslated(myFGSignPos.x(), myFGSignPos.y(), 0);
143  glRotated(180, 1, 0, 0);
144  glRotated(myFGSignRot, 0, 0, 1);
145  glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
146  pfSetPosition(0, 0);
147  pfSetScale(1.f);
148  glScaled(exaggeration, exaggeration, 1);
149  glTranslated(1.2, -(double)i, 0);
150  pfDrawString(myLines[i].c_str());
151  glPopMatrix();
152  }
153  // draw the sign
154  glTranslated(myFGSignPos.x(), myFGSignPos.y(), 0);
155  int noPoints = 9;
156  if (s.scale * exaggeration > 25) {
157  noPoints = MIN2((int)(9.0 + (s.scale * exaggeration) / 10.0), 36);
158  }
159  glScaled(exaggeration, exaggeration, 1);
160  GLHelper::drawFilledCircle((SUMOReal) 1.1, noPoints);
161  glTranslated(0, 0, .1);
162  GLHelper::setColor(grey);
163  GLHelper::drawFilledCircle((SUMOReal) 0.9, noPoints);
164  if (s.scale * exaggeration >= 4.5) {
165  GLHelper::drawText("C", Position(), .1, 1.6 * exaggeration, blue, myFGSignRot);
166  }
167  }
168  glPopMatrix();
169  glPopName();
170  drawName(getCenteringBoundary().getCenter(), s.scale, s.addName);
171  for (std::vector<MSContainer*>::const_iterator i = myWaitingContainers.begin(); i != myWaitingContainers.end(); ++i) {
172  glTranslated(0, 1, 0); // make multiple containers viewable
173  static_cast<GUIContainer*>(*i)->drawGL(s);
174  }
175 }
176 
177 
178 Boundary
181  b.grow(20);
182  return b;
183 }
184 
185 
186 
187 /****************************************************************************/
188 
PositionVector myFGShape
The shape.
int pfDrawString(const char *c)
Definition: polyfonts.c:1074
a lane speed trigger,
A lane area vehicles can halt at and load and unload containers.
GUIVisualizationTextSettings addName
void buildNameCopyPopupEntry(GUIGLObjectPopupMenu *ret, bool addSeparator=true)
Builds entries which allow to copy the name / typed name into the clipboard.
SUMOReal myFGSignRot
The rotation of the sign.
SUMOReal myBegPos
The begin position this stop is located at.
Stores the information about how to visualize structures.
SUMOReal myEndPos
The end position this stop is located at.
~GUIContainerStop()
Destructor.
void pfSetPosition(SUMOReal x, SUMOReal y)
Definition: polyfonts.c:480
static void drawBoxLines(const PositionVector &geom, const std::vector< SUMOReal > &rots, const std::vector< SUMOReal > &lengths, SUMOReal width, int cornerDetail=0, SUMOReal offset=0)
Draws thick lines.
Definition: GLHelper.cpp:176
void buildCenterPopupEntry(GUIGLObjectPopupMenu *ret, bool addSeparator=true)
Builds an entry which allows to center to the object.
SUMOReal distanceTo(const Position &p2) const
returns the euclidean distance in 3 dimension
Definition: Position.h:229
static void drawText(const std::string &text, const Position &pos, const SUMOReal layer, const SUMOReal size, const RGBColor &col=RGBColor::BLACK, const SUMOReal angle=0)
draw Text with given parameters
Definition: GLHelper.cpp:459
void buildShowParamsPopupEntry(GUIGLObjectPopupMenu *ret, bool addSeparator=true)
Builds an entry which allows to open the parameter window.
std::vector< MSContainer * > myWaitingContainers
Containers waiting at this stop.
SUMOReal x() const
Returns the x-position.
Definition: Position.h:63
void buildPositionCopyEntry(GUIGLObjectPopupMenu *ret, bool addSeparator=true)
Builds an entry which allows to copy the cursor position if geo projection is used, also builds an entry for copying the geo-position.
GUIGlID getGlID() const
Returns the numerical id of the object.
Definition: GUIGlObject.h:115
A class that stores a 2D geometrical boundary.
Definition: Boundary.h:48
SUMOReal scale
information about a lane's width (temporary, used for a single view)
Boundary getCenteringBoundary() const
Returns the boundary to which the view shall be centered in order to show the object.
static void drawFilledCircle(SUMOReal width, int steps=8)
Draws a filled circle around (0,0)
Definition: GLHelper.cpp:344
GUIVisualizationSizeSettings addSize
GUIGlObjectType getType() const
Returns the type of the object as coded in GUIGlObjectType.
Definition: GUIGlObject.h:159
unsigned int getContainerNumber() const
Returns the number of containers waiting on this stop.
#define PI
Definition: polyfonts.c:61
static void setColor(const RGBColor &c)
Sets the gl-color to this value.
Definition: GLHelper.cpp:442
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:46
A list of positions.
std::vector< SUMOReal > myFGShapeLengths
The lengths of the shape parts.
GUIParameterTableWindow * getParameterWindow(GUIMainWindow &app, GUISUMOAbstractView &parent)
Returns an own parameter window.
Position myFGSignPos
The position of the sign.
std::vector< SUMOReal > myFGShapeRotations
The rotations of the shape parts.
T MIN2(T a, T b)
Definition: StdDefs.h:68
GUIGLObjectPopupMenu * getPopUpMenu(GUIMainWindow &app, GUISUMOAbstractView &parent)
Returns an own popup-menu.
void drawName(const Position &pos, const SUMOReal scale, const GUIVisualizationTextSettings &settings, const SUMOReal angle=0) const
GUIContainerStop(const std::string &id, const std::vector< std::string > &lines, MSLane &lane, SUMOReal frompos, SUMOReal topos)
Constructor.
SUMOReal length() const
Returns the length.
SUMOReal rotationDegreeAtOffset(SUMOReal pos) const
Returns the rotation at the given length.
Boundary & grow(SUMOReal by)
extends the boundary by the given amount
Definition: Boundary.cpp:200
void pfSetScale(SUMOReal s)
Definition: polyfonts.c:465
SUMOReal y() const
Returns the y-position.
Definition: Position.h:68
The popup menu of a globject.
std::vector< std::string > myLines
The list of lines that are assigned to this stop.
void buildSelectionPopupEntry(GUIGLObjectPopupMenu *ret, bool addSeparator=true)
Builds an entry which allows to (de)select the object.
Position getLineCenter() const
const PositionVector & getShape() const
Returns this lane's shape.
Definition: MSLane.h:323
void move2side(SUMOReal amount)
#define SUMOReal
Definition: config.h:218
void drawGL(const GUIVisualizationSettings &s) const
Draws the object.
Boundary getBoxBoundary() const
Returns a boundary enclosing this list of lines.
void mkItem(const char *name, bool dynamic, ValueSource< unsigned > *src)
Adds a row which obtains its value from an unsigned-ValueSource.
void closeBuilding()
Closes the building of the table.
Representation of a lane in the micro simulation.
Definition: MSLane.h:77
A window containing a gl-object's parameter.
PositionVector getSubpart(SUMOReal beginOffset, SUMOReal endOffset) const
void drawGL(const GUIVisualizationSettings &s) const
Draws the object.
SUMOReal getExaggeration(const GUIVisualizationSettings &s) const
return the drawing size including exaggeration and constantSize values
void buildPopupHeader(GUIGLObjectPopupMenu *ret, GUIMainWindow &app, bool addSeparator=true)
Builds the header.