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