SUMO - Simulation of Urban MObility
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
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-2016 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 #ifdef CHECK_MEMORY_LEAKS
58 #include <foreign/nvwa/debug_new.h>
59 #endif // CHECK_MEMORY_LEAKS
60 
61 
62 // ===========================================================================
63 // FOX callback mapping
64 // ===========================================================================
66 /*
67 FXDEFMAP(GNEInternalLane) GNEInternalLaneMap[]= {
68  //FXMAPFUNC(SEL_COMMAND, MID_GNE_PHASE_DURATION, GNETLSEditorFrame::onDefault),
69 };
70 */
71 
72 // Object implementation
73 //FXIMPLEMENT(GNEInternalLane, FXDelegator, GNEInternalLaneMap, ARRAYNUMBER(GNEInternalLaneMap))
74 FXIMPLEMENT(GNEInternalLane, FXDelegator, 0, 0)
75 
76 // ===========================================================================
77 // static member definitions
78 // ===========================================================================
79 
80 StringBijection<FXuint>::Entry GNEInternalLane::linkStateNamesValues[] = {
81  { "Green-Major", LINKSTATE_TL_GREEN_MAJOR },
82  { "Green-Minor", LINKSTATE_TL_GREEN_MINOR },
83  { "Yellow-Major", LINKSTATE_TL_YELLOW_MAJOR },
84  { "Yellow-Minor", LINKSTATE_TL_YELLOW_MINOR },
85  { "Red", LINKSTATE_TL_RED },
86  { "Red-Yellow", LINKSTATE_TL_REDYELLOW },
87  { "Stop", LINKSTATE_STOP },
88  { "Off", LINKSTATE_TL_OFF_NOSIGNAL },
89  { "Off-Blinking", LINKSTATE_TL_OFF_BLINKING },
90 };
91 
94 
95 // ===========================================================================
96 // method definitions
97 // ===========================================================================
98 GNEInternalLane::GNEInternalLane(GNETLSEditorFrame* editor, const std::string& id, const PositionVector& shape, int tlIndex, LinkState state) :
99  GUIGlObject(editor == 0 ? GLO_JUNCTION : GLO_TLLOGIC, id),
100  myShape(shape),
101  myState(state),
102  myStateTarget(myState),
103  myEditor(editor),
104  myTlIndex(tlIndex),
105  myPopup(0) {
106  int segments = (int) myShape.size() - 1;
107  if (segments >= 0) {
108  myShapeRotations.reserve(segments);
109  myShapeLengths.reserve(segments);
110  for (int i = 0; i < segments; ++i) {
111  const Position& f = myShape[i];
112  const Position& s = myShape[i + 1];
113  myShapeLengths.push_back(f.distanceTo2D(s));
114  myShapeRotations.push_back((SUMOReal) atan2((s.x() - f.x()), (f.y() - s.y())) * (SUMOReal) 180.0 / (SUMOReal) PI);
115  }
116  }
117 }
118 
119 
121  GUIGlObject(GLO_TLLOGIC, "dummyInternalLane") {
122  assert(false);
123 }
124 
125 
127 
128 
129 long
130 GNEInternalLane::onDefault(FXObject* obj, FXSelector sel, void* data) {
131  if (myEditor != 0) {
132  FXuint before = myState;
133  myStateTarget.handle(obj, sel, data);
134  if (myState != before) {
135  myEditor->handleChange(this);
136  }
137  // let GUISUMOAbstractView know about clicks so that the popup is properly destroyed
138  if (FXSELTYPE(sel) == SEL_COMMAND) {
139  if (myPopup != 0) {
141  myPopup = 0;
142  }
143  }
144  }
145  return 1;
146 }
147 
148 
149 void
151  glPushMatrix();
152  glPushName(getGlID());
153  glTranslated(0, 0, GLO_JUNCTION + 0.1); // must draw on top of junction
155  // draw lane
156  // check whether it is not too small
157  if (s.scale < 1.) {
159  } else {
161  }
162  glPopName();
163  glPopMatrix();
164 }
165 
166 
167 void
169  myState = state;
170  myOrigState = state;
171 }
172 
173 
174 LinkState
176  return (LinkState)myState;
177 }
178 
179 
180 int
182  return myTlIndex;
183 }
184 
185 
188  myPopup = new GUIGLObjectPopupMenu(app, parent, *this);
190  if (myEditor != 0) {
191  const std::vector<std::string> names = LinkStateNames.getStrings();
192  for (std::vector<std::string>::const_iterator it = names.begin(); it != names.end(); it++) {
193  FXuint state = LinkStateNames.get(*it);
194  std::string origHint = ((LinkState)state == myOrigState ? " (original)" : "");
195  FXMenuRadio* mc = new FXMenuRadio(myPopup, (*it + origHint).c_str(), this, FXDataTarget::ID_OPTION + state);
196  mc->setSelBackColor(MFXUtils::getFXColor(colorForLinksState(state)));
197  mc->setBackColor(MFXUtils::getFXColor(colorForLinksState(state)));
198  }
199  }
200  return myPopup;
201 }
202 
203 
207  new GUIParameterTableWindow(app, *this, 2);
208  // add items
209  // close building
210  ret->closeBuilding();
211  return ret;
212 }
213 
214 
215 Boundary
218  b.grow(10);
219  return b;
220 }
221 
222 
223 RGBColor
225  if (state == LINKSTATE_TL_YELLOW_MINOR) {
226  // special case (default gui does not distinguish between yellow major/minor
227  return RGBColor(179, 179, 0, 255);
228  } else {
229  return getLinkColor((LinkState)state);
230  }
231 }
232 
233 /****************************************************************************/
The link has green light, may pass.
GUISUMOAbstractView * getParentView()
return the real owner of this popup
GUIParameterTableWindow * getParameterWindow(GUIMainWindow &app, GUISUMOAbstractView &parent)
Returns an own parameter window.
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.
const RGBColor & getLinkColor(const LinkState &ls)
Definition: StdDefs.cpp:53
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...
int myTlIndex
the tl-index of this lane
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
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.
SUMOReal x() const
Returns the x-position.
Definition: Position.h:63
GUIGlID getGlID() const
Returns the numerical id of the object.
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)
FXDataTarget myStateTarget
LinkState myOrigState
the original state of the link (used for tracking modification)
std::vector< std::string > getStrings() const
#define PI
Definition: polyfonts.c:61
static void setColor(const RGBColor &c)
Sets the gl-color to this value.
Definition: GLHelper.cpp:443
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:46
A list of positions.
std::vector< SUMOReal > myShapeLengths
The lengths of the shape parts.
std::vector< SUMOReal > myShapeRotations
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
GNETLSEditorFrame * myEditor
the editor to inform about changes
void destroyPopup()
destoys the popup
long onDefault(FXObject *, FXSelector, void *)
multiplexes message to two targets
void drawGL(const GUIVisualizationSettings &s) const
Draws the object.
virtual ~GNEInternalLane()
Destructor.
Boundary & grow(SUMOReal by)
extends the boundary by the given amount
Definition: Boundary.cpp:232
The link has yellow light, may pass.
The link is controlled by a tls which is off and blinks, has to brake.
SUMOReal y() const
Returns the y-position.
Definition: Position.h:68
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:125
T get(const std::string &str) const
SUMOReal distanceTo2D(const Position &p2) const
returns the euclidean distance in the x-y-plane
Definition: Position.h:232
static void drawLine(const Position &beg, SUMOReal rot, SUMOReal visLength)
Draws a thin line.
Definition: GLHelper.cpp:269
#define SUMOReal
Definition: config.h:214
GUIGLObjectPopupMenu * getPopUpMenu(GUIMainWindow &app, GUISUMOAbstractView &parent)
Returns an own popup-menu.
Boundary getCenteringBoundary() const
Returns the boundary to which the view shall be centered in order to show the object.
GNEInternalLane()
FOX needs this.
The link has yellow light, has to brake anyway.
Boundary getBoxBoundary() const
Returns a boundary enclosing this list of lines.
void closeBuilding()
Closes the building of the table.
A window containing a gl-object's parameter.
The link has red light (must brake) but indicates upcoming green.
LinkState getLinkState() const
whether link state has been modfied
FXuint myState
the state of the link (used for visualization)
void buildPopupHeader(GUIGLObjectPopupMenu *ret, GUIMainWindow &app, bool addSeparator=true)
Builds the header.
a junction