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 
25 #include <utils/geom/GeomHelper.h>
28 #include <utils/gui/div/GLHelper.h>
31 
32 #include "GNEInternalLane.h"
33 
34 // ===========================================================================
35 // FOX callback mapping
36 // ===========================================================================
38 /*
39 FXDEFMAP(GNEInternalLane) GNEInternalLaneMap[]= {
40  //FXMAPFUNC(SEL_COMMAND, MID_GNE_TLSFRAME_PHASE_DURATION, GNETLSEditorFrame::onDefault),
41 };
42 */
43 
44 // Object implementation
45 //FXIMPLEMENT(GNEInternalLane, FXDelegator, GNEInternalLaneMap, ARRAYNUMBER(GNEInternalLaneMap))
46 FXIMPLEMENT(GNEInternalLane, FXDelegator, 0, 0)
47 
48 // ===========================================================================
49 // static member definitions
50 // ===========================================================================
51 
52 StringBijection<FXuint>::Entry GNEInternalLane::linkStateNamesValues[] = {
53  { "Green-Major", LINKSTATE_TL_GREEN_MAJOR },
54  { "Green-Minor", LINKSTATE_TL_GREEN_MINOR },
55  { "Yellow-Major", LINKSTATE_TL_YELLOW_MAJOR },
56  { "Yellow-Minor", LINKSTATE_TL_YELLOW_MINOR },
57  { "Red", LINKSTATE_TL_RED },
58  { "Red-Yellow", LINKSTATE_TL_REDYELLOW },
59  { "Stop", LINKSTATE_STOP },
60  { "Off", LINKSTATE_TL_OFF_NOSIGNAL },
61  { "Off-Blinking", LINKSTATE_TL_OFF_BLINKING },
62 };
63 
66 
67 // ===========================================================================
68 // method definitions
69 // ===========================================================================
70 GNEInternalLane::GNEInternalLane(GNETLSEditorFrame* editor, const std::string& id, const PositionVector& shape, int tlIndex, LinkState state) :
71  GUIGlObject(editor == nullptr ? GLO_JUNCTION : GLO_TLLOGIC, id),
72  myShape(shape),
73  myState(state),
74  myStateTarget(myState),
75  myEditor(editor),
76  myTlIndex(tlIndex),
77  myPopup(nullptr) {
78  int segments = (int) myShape.size() - 1;
79  if (segments >= 0) {
80  myShapeRotations.reserve(segments);
81  myShapeLengths.reserve(segments);
82  for (int i = 0; i < segments; ++i) {
83  const Position& f = myShape[i];
84  const Position& s = myShape[i + 1];
85  myShapeLengths.push_back(f.distanceTo2D(s));
86  myShapeRotations.push_back((double) atan2((s.x() - f.x()), (f.y() - s.y())) * (double) 180.0 / (double) M_PI);
87  }
88  }
89 }
90 
91 
93  GUIGlObject(GLO_TLLOGIC, "dummyInternalLane") {
94  assert(false);
95 }
96 
97 
99 
100 
101 long
102 GNEInternalLane::onDefault(FXObject* obj, FXSelector sel, void* data) {
103  if (myEditor != nullptr) {
104  FXuint before = myState;
105  myStateTarget.handle(obj, sel, data);
106  if (myState != before) {
107  myEditor->handleChange(this);
108  }
109  // let GUISUMOAbstractView know about clicks so that the popup is properly destroyed
110  if (FXSELTYPE(sel) == SEL_COMMAND) {
111  if (myPopup != nullptr) {
113  myPopup = nullptr;
114  }
115  }
116  }
117  return 1;
118 }
119 
120 
121 void
123  glPushMatrix();
124  glPushName(getGlID());
125  glTranslated(0, 0, GLO_JUNCTION + 0.1); // must draw on top of junction
127  // draw lane
128  // check whether it is not too small
129  if (s.scale < 1.) {
131  } else {
133  }
134  glPopName();
135  glPopMatrix();
136 }
137 
138 
139 void
141  myState = state;
142  myOrigState = state;
143 }
144 
145 
146 LinkState
148  return (LinkState)myState;
149 }
150 
151 
152 int
154  return myTlIndex;
155 }
156 
157 
160  myPopup = new GUIGLObjectPopupMenu(app, parent, *this);
162  if (myEditor != nullptr) {
163  const std::vector<std::string> names = LinkStateNames.getStrings();
164  for (std::vector<std::string>::const_iterator it = names.begin(); it != names.end(); it++) {
165  FXuint state = LinkStateNames.get(*it);
166  std::string origHint = ((LinkState)state == myOrigState ? " (original)" : "");
167  FXMenuRadio* mc = new FXMenuRadio(myPopup, (*it + origHint).c_str(), this, FXDataTarget::ID_OPTION + state);
168  mc->setSelBackColor(MFXUtils::getFXColor(colorForLinksState(state)));
169  mc->setBackColor(MFXUtils::getFXColor(colorForLinksState(state)));
170  }
171  }
172  return myPopup;
173 }
174 
175 
178  // internal lanes don't have attributes
179  GUIParameterTableWindow* ret = new GUIParameterTableWindow(app, *this, 2);
180  // close building
181  ret->closeBuilding();
182  return ret;
183 }
184 
185 
186 Boundary
189  b.grow(10);
190  return b;
191 }
192 
193 
194 RGBColor
196  if (state == LINKSTATE_TL_YELLOW_MINOR) {
197  // special case (default gui does not distinguish between yellow major/minor
198  return RGBColor(179, 179, 0, 255);
199  } else {
200  try {
202  } catch (ProcessError&) {
203  std::cout << "invalid link state='" << state << "'\n";
204  return RGBColor::BLACK;
205  }
206  }
207 }
208 
209 /****************************************************************************/
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:244
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:62
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:57
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:192
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