SUMO - Simulation of Urban MObility
GNEInternalLane.cpp
Go to the documentation of this file.
1 /****************************************************************************/
7 // A class for visualizing Inner Lanes (used when editing traffic lights)
8 /****************************************************************************/
9 // SUMO, Simulation of Urban MObility; see http://sumo.dlr.de/
10 // Copyright (C) 2001-2017 DLR (http://www.dlr.de/) and contributors
11 /****************************************************************************/
12 //
13 // This file is part of SUMO.
14 // SUMO is free software: you can redistribute it and/or modify
15 // it under the terms of the GNU General Public License as published by
16 // the Free Software Foundation, either version 3 of the License, or
17 // (at your option) any later version.
18 //
19 /****************************************************************************/
20 
21 
22 // ===========================================================================
23 // included modules
24 // ===========================================================================
25 #ifdef _MSC_VER
26 #include <windows_config.h>
27 #else
28 #include <config.h>
29 #endif
30 
31 #include <string>
32 #include <iostream>
33 #include <utility>
34 #include <time.h>
39 #include <utils/common/ToString.h>
40 #include <utils/geom/GeomHelper.h>
47 #include <utils/gui/div/GLHelper.h>
50 
51 #include "GNENet.h"
52 #include "GNEChange_Attribute.h"
53 #include "GNEViewNet.h"
54 #include "GNEInternalLane.h"
55 #include "GNETLSEditorFrame.h"
56 
57 
58 // ===========================================================================
59 // FOX callback mapping
60 // ===========================================================================
62 /*
63 FXDEFMAP(GNEInternalLane) GNEInternalLaneMap[]= {
64  //FXMAPFUNC(SEL_COMMAND, MID_GNE_PHASE_DURATION, GNETLSEditorFrame::onDefault),
65 };
66 */
67 
68 // Object implementation
69 //FXIMPLEMENT(GNEInternalLane, FXDelegator, GNEInternalLaneMap, ARRAYNUMBER(GNEInternalLaneMap))
70 FXIMPLEMENT(GNEInternalLane, FXDelegator, 0, 0)
71 
72 // ===========================================================================
73 // static member definitions
74 // ===========================================================================
75 
76 StringBijection<FXuint>::Entry GNEInternalLane::linkStateNamesValues[] = {
77  { "Green-Major", LINKSTATE_TL_GREEN_MAJOR },
78  { "Green-Minor", LINKSTATE_TL_GREEN_MINOR },
79  { "Yellow-Major", LINKSTATE_TL_YELLOW_MAJOR },
80  { "Yellow-Minor", LINKSTATE_TL_YELLOW_MINOR },
81  { "Red", LINKSTATE_TL_RED },
82  { "Red-Yellow", LINKSTATE_TL_REDYELLOW },
83  { "Stop", LINKSTATE_STOP },
84  { "Off", LINKSTATE_TL_OFF_NOSIGNAL },
85  { "Off-Blinking", LINKSTATE_TL_OFF_BLINKING },
86 };
87 
90 
91 // ===========================================================================
92 // method definitions
93 // ===========================================================================
94 GNEInternalLane::GNEInternalLane(GNETLSEditorFrame* editor, const std::string& id, const PositionVector& shape, int tlIndex, LinkState state) :
95  GUIGlObject(editor == 0 ? GLO_JUNCTION : GLO_TLLOGIC, id),
96  myShape(shape),
97  myState(state),
98  myStateTarget(myState),
99  myEditor(editor),
100  myTlIndex(tlIndex),
101  myPopup(0) {
102  int segments = (int) myShape.size() - 1;
103  if (segments >= 0) {
104  myShapeRotations.reserve(segments);
105  myShapeLengths.reserve(segments);
106  for (int i = 0; i < segments; ++i) {
107  const Position& f = myShape[i];
108  const Position& s = myShape[i + 1];
109  myShapeLengths.push_back(f.distanceTo2D(s));
110  myShapeRotations.push_back((double) atan2((s.x() - f.x()), (f.y() - s.y())) * (double) 180.0 / (double) PI);
111  }
112  }
113 }
114 
115 
117  GUIGlObject(GLO_TLLOGIC, "dummyInternalLane") {
118  assert(false);
119 }
120 
121 
123 
124 
125 long
126 GNEInternalLane::onDefault(FXObject* obj, FXSelector sel, void* data) {
127  if (myEditor != 0) {
128  FXuint before = myState;
129  myStateTarget.handle(obj, sel, data);
130  if (myState != before) {
131  myEditor->handleChange(this);
132  }
133  // let GUISUMOAbstractView know about clicks so that the popup is properly destroyed
134  if (FXSELTYPE(sel) == SEL_COMMAND) {
135  if (myPopup != 0) {
137  myPopup = 0;
138  }
139  }
140  }
141  return 1;
142 }
143 
144 
145 void
147  glPushMatrix();
148  glPushName(getGlID());
149  glTranslated(0, 0, GLO_JUNCTION + 0.1); // must draw on top of junction
151  // draw lane
152  // check whether it is not too small
153  if (s.scale < 1.) {
155  } else {
157  }
158  glPopName();
159  glPopMatrix();
160 }
161 
162 
163 void
165  myState = state;
166  myOrigState = state;
167 }
168 
169 
170 LinkState
172  return (LinkState)myState;
173 }
174 
175 
176 int
178  return myTlIndex;
179 }
180 
181 
184  myPopup = new GUIGLObjectPopupMenu(app, parent, *this);
186  if (myEditor != 0) {
187  const std::vector<std::string> names = LinkStateNames.getStrings();
188  for (std::vector<std::string>::const_iterator it = names.begin(); it != names.end(); it++) {
189  FXuint state = LinkStateNames.get(*it);
190  std::string origHint = ((LinkState)state == myOrigState ? " (original)" : "");
191  FXMenuRadio* mc = new FXMenuRadio(myPopup, (*it + origHint).c_str(), this, FXDataTarget::ID_OPTION + state);
192  mc->setSelBackColor(MFXUtils::getFXColor(colorForLinksState(state)));
193  mc->setBackColor(MFXUtils::getFXColor(colorForLinksState(state)));
194  }
195  }
196  return myPopup;
197 }
198 
199 
203  new GUIParameterTableWindow(app, *this, 2);
204  // add items
205  // close building
206  ret->closeBuilding();
207  return ret;
208 }
209 
210 
211 Boundary
214  b.grow(10);
215  return b;
216 }
217 
218 
219 RGBColor
221  if (state == LINKSTATE_TL_YELLOW_MINOR) {
222  // special case (default gui does not distinguish between yellow major/minor
223  return RGBColor(179, 179, 0, 255);
224  } else {
226  }
227 }
228 
229 /****************************************************************************/
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)
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:172
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:250
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:68
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:63
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:48
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
#define PI
Definition: polyfonts.c:61
static void setColor(const RGBColor &c)
Sets the gl-color to this value.
Definition: GLHelper.cpp:439
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:46
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:234
static void drawLine(const Position &beg, double rot, double visLength)
Draws a thin line.
Definition: GLHelper.cpp:265
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.
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:121
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.
void closeBuilding()
Closes the building of the table.
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