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-2018 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials
5 // are made available under the terms of the Eclipse Public License v2.0
6 // which accompanies this distribution, and is available at
7 // http://www.eclipse.org/legal/epl-v20.html
8 // SPDX-License-Identifier: EPL-2.0
9 /****************************************************************************/
15 // A class for visualizing Inner Lanes (used when editing traffic lights)
16 /****************************************************************************/
17 
18 
19 // ===========================================================================
20 // included modules
21 // ===========================================================================
22 #include <config.h>
23 
24 #include <string>
25 #include <iostream>
26 #include <utility>
27 #include <time.h>
31 #include <utils/common/ToString.h>
32 #include <utils/geom/GeomHelper.h>
38 #include <utils/gui/div/GLHelper.h>
41 #include <netedit/GNENet.h>
43 #include <netedit/GNEViewNet.h>
45 
46 #include "GNEInternalLane.h"
47 
48 
49 // ===========================================================================
50 // FOX callback mapping
51 // ===========================================================================
53 /*
54 FXDEFMAP(GNEInternalLane) GNEInternalLaneMap[]= {
55  //FXMAPFUNC(SEL_COMMAND, MID_GNE_TLSFRAME_PHASE_DURATION, GNETLSEditorFrame::onDefault),
56 };
57 */
58 
59 // Object implementation
60 //FXIMPLEMENT(GNEInternalLane, FXDelegator, GNEInternalLaneMap, ARRAYNUMBER(GNEInternalLaneMap))
61 FXIMPLEMENT(GNEInternalLane, FXDelegator, 0, 0)
62 
63 // ===========================================================================
64 // static member definitions
65 // ===========================================================================
66 
67 StringBijection<FXuint>::Entry GNEInternalLane::linkStateNamesValues[] = {
68  { "Green-Major", LINKSTATE_TL_GREEN_MAJOR },
69  { "Green-Minor", LINKSTATE_TL_GREEN_MINOR },
70  { "Yellow-Major", LINKSTATE_TL_YELLOW_MAJOR },
71  { "Yellow-Minor", LINKSTATE_TL_YELLOW_MINOR },
72  { "Red", LINKSTATE_TL_RED },
73  { "Red-Yellow", LINKSTATE_TL_REDYELLOW },
74  { "Stop", LINKSTATE_STOP },
75  { "Off", LINKSTATE_TL_OFF_NOSIGNAL },
76  { "Off-Blinking", LINKSTATE_TL_OFF_BLINKING },
77 };
78 
81 
82 // ===========================================================================
83 // method definitions
84 // ===========================================================================
85 GNEInternalLane::GNEInternalLane(GNETLSEditorFrame* editor, const std::string& id, const PositionVector& shape, int tlIndex, LinkState state) :
86  GUIGlObject(editor == 0 ? GLO_JUNCTION : GLO_TLLOGIC, id),
87  myShape(shape),
88  myState(state),
89  myStateTarget(myState),
90  myEditor(editor),
91  myTlIndex(tlIndex),
92  myPopup(0) {
93  int segments = (int) myShape.size() - 1;
94  if (segments >= 0) {
95  myShapeRotations.reserve(segments);
96  myShapeLengths.reserve(segments);
97  for (int i = 0; i < segments; ++i) {
98  const Position& f = myShape[i];
99  const Position& s = myShape[i + 1];
100  myShapeLengths.push_back(f.distanceTo2D(s));
101  myShapeRotations.push_back((double) atan2((s.x() - f.x()), (f.y() - s.y())) * (double) 180.0 / (double) M_PI);
102  }
103  }
104 }
105 
106 
108  GUIGlObject(GLO_TLLOGIC, "dummyInternalLane") {
109  assert(false);
110 }
111 
112 
114 
115 
116 long
117 GNEInternalLane::onDefault(FXObject* obj, FXSelector sel, void* data) {
118  if (myEditor != 0) {
119  FXuint before = myState;
120  myStateTarget.handle(obj, sel, data);
121  if (myState != before) {
122  myEditor->handleChange(this);
123  }
124  // let GUISUMOAbstractView know about clicks so that the popup is properly destroyed
125  if (FXSELTYPE(sel) == SEL_COMMAND) {
126  if (myPopup != 0) {
128  myPopup = 0;
129  }
130  }
131  }
132  return 1;
133 }
134 
135 
136 void
138  glPushMatrix();
139  glPushName(getGlID());
140  glTranslated(0, 0, GLO_JUNCTION + 0.1); // must draw on top of junction
142  // draw lane
143  // check whether it is not too small
144  if (s.scale < 1.) {
146  } else {
148  }
149  glPopName();
150  glPopMatrix();
151 }
152 
153 
154 void
156  myState = state;
157  myOrigState = state;
158 }
159 
160 
161 LinkState
163  return (LinkState)myState;
164 }
165 
166 
167 int
169  return myTlIndex;
170 }
171 
172 
175  myPopup = new GUIGLObjectPopupMenu(app, parent, *this);
177  if (myEditor != 0) {
178  const std::vector<std::string> names = LinkStateNames.getStrings();
179  for (std::vector<std::string>::const_iterator it = names.begin(); it != names.end(); it++) {
180  FXuint state = LinkStateNames.get(*it);
181  std::string origHint = ((LinkState)state == myOrigState ? " (original)" : "");
182  FXMenuRadio* mc = new FXMenuRadio(myPopup, (*it + origHint).c_str(), this, FXDataTarget::ID_OPTION + state);
183  mc->setSelBackColor(MFXUtils::getFXColor(colorForLinksState(state)));
184  mc->setBackColor(MFXUtils::getFXColor(colorForLinksState(state)));
185  }
186  }
187  return myPopup;
188 }
189 
190 
193  // internal lanes don't have attributes
194  GUIParameterTableWindow* ret = new GUIParameterTableWindow(app, *this, 2);
195  // close building
196  ret->closeBuilding();
197  return ret;
198 }
199 
200 
201 Boundary
204  b.grow(10);
205  return b;
206 }
207 
208 
209 RGBColor
211  if (state == LINKSTATE_TL_YELLOW_MINOR) {
212  // special case (default gui does not distinguish between yellow major/minor
213  return RGBColor(179, 179, 0, 255);
214  } else {
215  try {
217  } catch (ProcessError&) {
218  std::cout << "invalid link state='" << state << "'\n";
219  return RGBColor::BLACK;
220  }
221  }
222 }
223 
224 /****************************************************************************/
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:178
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:243
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:61
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:56
int myTlIndex
the tl-index of this lane
const PositionVector myShape
the shape of the edge
static StringBijection< FXuint >::Entry linkStateNamesValues[]
linkstates names values
static const RGBColor BLACK
Definition: RGBColor.h:180
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:42
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:573
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:39
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:270
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:114
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)
map from LinkState to color constants
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