SUMO - Simulation of Urban MObility
GNEInternalLane.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-2017 German Aerospace Center (DLR) and others.
4 /****************************************************************************/
5 //
6 // This program and the accompanying materials
7 // are made available under the terms of the Eclipse Public License v2.0
8 // which accompanies this distribution, and is available at
9 // http://www.eclipse.org/legal/epl-v20.html
10 //
11 /****************************************************************************/
17 // A class for visualizing Inner Lanes (used when editing traffic lights)
18 /****************************************************************************/
19 
20 
21 // ===========================================================================
22 // included modules
23 // ===========================================================================
24 #ifdef _MSC_VER
25 #include <windows_config.h>
26 #else
27 #include <config.h>
28 #endif
29 
30 #include <string>
31 #include <iostream>
32 #include <utility>
33 #include <time.h>
37 #include <utils/common/ToString.h>
38 #include <utils/geom/GeomHelper.h>
45 #include <utils/gui/div/GLHelper.h>
48 
49 #include "GNENet.h"
50 #include "GNEChange_Attribute.h"
51 #include "GNEViewNet.h"
52 #include "GNEInternalLane.h"
53 #include "GNETLSEditorFrame.h"
54 
55 
56 // ===========================================================================
57 // FOX callback mapping
58 // ===========================================================================
60 /*
61 FXDEFMAP(GNEInternalLane) GNEInternalLaneMap[]= {
62  //FXMAPFUNC(SEL_COMMAND, MID_GNE_TLSFRAME_PHASE_DURATION, GNETLSEditorFrame::onDefault),
63 };
64 */
65 
66 // Object implementation
67 //FXIMPLEMENT(GNEInternalLane, FXDelegator, GNEInternalLaneMap, ARRAYNUMBER(GNEInternalLaneMap))
68 FXIMPLEMENT(GNEInternalLane, FXDelegator, 0, 0)
69 
70 // ===========================================================================
71 // static member definitions
72 // ===========================================================================
73 
74 StringBijection<FXuint>::Entry GNEInternalLane::linkStateNamesValues[] = {
75  { "Green-Major", LINKSTATE_TL_GREEN_MAJOR },
76  { "Green-Minor", LINKSTATE_TL_GREEN_MINOR },
77  { "Yellow-Major", LINKSTATE_TL_YELLOW_MAJOR },
78  { "Yellow-Minor", LINKSTATE_TL_YELLOW_MINOR },
79  { "Red", LINKSTATE_TL_RED },
80  { "Red-Yellow", LINKSTATE_TL_REDYELLOW },
81  { "Stop", LINKSTATE_STOP },
82  { "Off", LINKSTATE_TL_OFF_NOSIGNAL },
83  { "Off-Blinking", LINKSTATE_TL_OFF_BLINKING },
84 };
85 
88 
89 // ===========================================================================
90 // method definitions
91 // ===========================================================================
92 GNEInternalLane::GNEInternalLane(GNETLSEditorFrame* editor, const std::string& id, const PositionVector& shape, int tlIndex, LinkState state) :
93  GUIGlObject(editor == 0 ? GLO_JUNCTION : GLO_TLLOGIC, id),
94  myShape(shape),
95  myState(state),
96  myStateTarget(myState),
97  myEditor(editor),
98  myTlIndex(tlIndex),
99  myPopup(0) {
100  int segments = (int) myShape.size() - 1;
101  if (segments >= 0) {
102  myShapeRotations.reserve(segments);
103  myShapeLengths.reserve(segments);
104  for (int i = 0; i < segments; ++i) {
105  const Position& f = myShape[i];
106  const Position& s = myShape[i + 1];
107  myShapeLengths.push_back(f.distanceTo2D(s));
108  myShapeRotations.push_back((double) atan2((s.x() - f.x()), (f.y() - s.y())) * (double) 180.0 / (double) M_PI);
109  }
110  }
111 }
112 
113 
115  GUIGlObject(GLO_TLLOGIC, "dummyInternalLane") {
116  assert(false);
117 }
118 
119 
121 
122 
123 long
124 GNEInternalLane::onDefault(FXObject* obj, FXSelector sel, void* data) {
125  if (myEditor != 0) {
126  FXuint before = myState;
127  myStateTarget.handle(obj, sel, data);
128  if (myState != before) {
129  myEditor->handleChange(this);
130  }
131  // let GUISUMOAbstractView know about clicks so that the popup is properly destroyed
132  if (FXSELTYPE(sel) == SEL_COMMAND) {
133  if (myPopup != 0) {
135  myPopup = 0;
136  }
137  }
138  }
139  return 1;
140 }
141 
142 
143 void
145  glPushMatrix();
146  glPushName(getGlID());
147  glTranslated(0, 0, GLO_JUNCTION + 0.1); // must draw on top of junction
149  // draw lane
150  // check whether it is not too small
151  if (s.scale < 1.) {
153  } else {
155  }
156  glPopName();
157  glPopMatrix();
158 }
159 
160 
161 void
163  myState = state;
164  myOrigState = state;
165 }
166 
167 
168 LinkState
170  return (LinkState)myState;
171 }
172 
173 
174 int
176  return myTlIndex;
177 }
178 
179 
182  myPopup = new GUIGLObjectPopupMenu(app, parent, *this);
184  if (myEditor != 0) {
185  const std::vector<std::string> names = LinkStateNames.getStrings();
186  for (std::vector<std::string>::const_iterator it = names.begin(); it != names.end(); it++) {
187  FXuint state = LinkStateNames.get(*it);
188  std::string origHint = ((LinkState)state == myOrigState ? " (original)" : "");
189  FXMenuRadio* mc = new FXMenuRadio(myPopup, (*it + origHint).c_str(), this, FXDataTarget::ID_OPTION + state);
190  mc->setSelBackColor(MFXUtils::getFXColor(colorForLinksState(state)));
191  mc->setBackColor(MFXUtils::getFXColor(colorForLinksState(state)));
192  }
193  }
194  return myPopup;
195 }
196 
197 
200  // internal lanes don't have attributes
201  GUIParameterTableWindow* ret = new GUIParameterTableWindow(app, *this, 2);
202  // close building
203  ret->closeBuilding();
204  return ret;
205 }
206 
207 
208 Boundary
211  b.grow(10);
212  return b;
213 }
214 
215 
216 RGBColor
218  if (state == LINKSTATE_TL_YELLOW_MINOR) {
219  // special case (default gui does not distinguish between yellow major/minor
220  return RGBColor(179, 179, 0, 255);
221  } else {
223  }
224 }
225 
226 /****************************************************************************/
The link has green light, may pass.
GUISUMOAbstractView * getParentView()
return the real owner of this popup
double scale
information about a lane&#39;s width (temporary, used for a single view)
void closeBuilding(const Parameterised *p=0)
Closes the building of the table.
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:183
GUIParameterTableWindow * getParameterWindow(GUIMainWindow &app, GUISUMOAbstractView &parent)
Returns an own parameter window.
double distanceTo2D(const Position &p2) const
returns the euclidean distance in the x-y-plane
Definition: Position.h:249
The link has green light, has to brake.
Stores the information about how to visualize structures.
This is an uncontrolled, minor link, has to stop.
double y() const
Returns the y-position.
Definition: Position.h:67
static RGBColor colorForLinksState(FXuint state)
return the color for each linkstate
This object is responsible for drawing a shape and for supplying a a popup menu. Messages are routete...
double x() const
Returns the x-position.
Definition: Position.h:62
int myTlIndex
the tl-index of this lane
const PositionVector myShape
the shape of the edge
static StringBijection< FXuint >::Entry linkStateNamesValues[]
linkstates names values
The link is controlled by a tls which is off, not blinking, may pass.
LinkState getLinkState() const
whether link state has been modfied
A class that stores a 2D geometrical boundary.
Definition: Boundary.h:47
std::vector< std::string > getStrings() const
FXDataTarget myStateTarget
LinkState myOrigState
the original state of the link (used for tracking modification)
Boundary getCenteringBoundary() const
Returns the boundary to which the view shall be centered in order to show the object.
std::vector< double > myShapeRotations
static void setColor(const RGBColor &c)
Sets the gl-color to this value.
Definition: GLHelper.cpp:449
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:45
A list of positions.
T get(const std::string &str) const
a tl-logic
LinkState
The right-of-way state of a link between two lanes used when constructing a NBTrafficLightLogic, in MSLink and GNEInternalLane.
void handleChange(GNEInternalLane *lane)
update phase definition for the current traffic light and phase
int getTLIndex() const
get Traffic Light index
Boundary & grow(double by)
extends the boundary by the given amount
Definition: Boundary.cpp:301
static void drawLine(const Position &beg, double rot, double visLength)
Draws a thin line.
Definition: GLHelper.cpp:276
GNETLSEditorFrame * myEditor
the editor to inform about changes
void destroyPopup()
destoys the popup
long onDefault(FXObject *, FXSelector, void *)
multiplexes message to two targets
virtual ~GNEInternalLane()
Destructor.
std::vector< double > myShapeLengths
The lengths of the shape parts.
#define M_PI
Definition: odrSpiral.cpp:40
The link has yellow light, may pass.
void drawGL(const GUIVisualizationSettings &s) const
Draws the object.
The link is controlled by a tls which is off and blinks, has to brake.
The link has red light (must brake)
The popup menu of a globject.
void setLinkState(LinkState state)
set the linkState (controls drawing color)
GUIGLObjectPopupMenu * myPopup
the created popup
static const StringBijection< FXuint > LinkStateNames
long names for link states
static FXColor getFXColor(const RGBColor &col)
converts FXColor to RGBColor
Definition: MFXUtils.cpp:120
GUIGlID getGlID() const
Returns the numerical id of the object.
GUIGLObjectPopupMenu * getPopUpMenu(GUIMainWindow &app, GUISUMOAbstractView &parent)
Returns an own popup-menu.
Boundary getBoxBoundary() const
Returns a boundary enclosing this list of lines.
GNEInternalLane()
FOX needs this.
The link has yellow light, has to brake anyway.
A window containing a gl-object&#39;s parameter.
static const RGBColor & getLinkColor(const LinkState &ls)
The link has red light (must brake) but indicates upcoming green.
FXuint myState
the state of the link (used for visualization)
void buildPopupHeader(GUIGLObjectPopupMenu *ret, GUIMainWindow &app, bool addSeparator=true)
Builds the header.
a junction