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 /****************************************************************************/
GUIParameterTableWindow
A window containing a gl-object's parameter.
Definition: GUIParameterTableWindow.h:63
WRITE_WARNING
#define WRITE_WARNING(msg)
Definition: MsgHandler.h:239
GUISUMOAbstractView
Definition: GUISUMOAbstractView.h:73
LINKSTATE_TL_OFF_BLINKING
The link is controlled by a tls which is off and blinks, has to brake.
Definition: SUMOXMLDefinitions.h:1146
GNEInternalLane.h
GNEInternalLane::myPopup
GUIGLObjectPopupMenu * myPopup
the created popup
Definition: GNEInternalLane.h:146
GUIParameterTableWindow.h
RGBColor::BLACK
static const RGBColor BLACK
Definition: RGBColor.h:198
LINKSTATE_TL_OFF_NOSIGNAL
The link is controlled by a tls which is off, not blinking, may pass.
Definition: SUMOXMLDefinitions.h:1148
GLHelper::drawBoxLines
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
GNEInternalLane::myEditor
GNETLSEditorFrame * myEditor
the editor to inform about changes
Definition: GNEInternalLane.h:140
GUIGLObjectPopupMenu.h
StringBijection::getStrings
std::vector< std::string > getStrings() const
Definition: StringBijection.h:132
LINKSTATE_TL_GREEN_MINOR
The link has green light, has to brake.
Definition: SUMOXMLDefinitions.h:1136
GLHelper.h
LINKSTATE_TL_GREEN_MAJOR
The link has green light, may pass.
Definition: SUMOXMLDefinitions.h:1134
PositionVector
A list of positions.
Definition: PositionVector.h:46
GUIGLObjectPopupMenu
The popup menu of a globject.
Definition: GUIGLObjectPopupMenu.h:48
GUIGLObjectPopupMenu::getParentView
GUISUMOAbstractView * getParentView()
return the real owner of this popup
Definition: GUIGLObjectPopupMenu.h:67
GLHelper::setColor
static void setColor(const RGBColor &c)
Sets the gl-color to this value.
Definition: GLHelper.cpp:616
PositionVector::getBoxBoundary
Boundary getBoxBoundary() const
Returns a boundary enclosing this list of lines.
Definition: PositionVector.cpp:382
GUIParameterTableWindow::closeBuilding
void closeBuilding(const Parameterised *p=0)
Closes the building of the table.
Definition: GUIParameterTableWindow.cpp:220
GLO_TLLOGIC
a tl-logic
Definition: GUIGlObjectTypes.h:57
RGBColor
Definition: RGBColor.h:40
LinkState
LinkState
The right-of-way state of a link between two lanes used when constructing a NBTrafficLightLogic,...
Definition: SUMOXMLDefinitions.h:1132
LINKSTATE_TL_YELLOW_MINOR
The link has yellow light, has to brake anyway.
Definition: SUMOXMLDefinitions.h:1144
StringBijection
Definition: StringBijection.h:44
GNEInternalLane::myState
FXuint myState
the state of the link (used for visualization)
Definition: GNEInternalLane.h:130
LINKSTATE_TL_REDYELLOW
The link has red light (must brake) but indicates upcoming green.
Definition: SUMOXMLDefinitions.h:1140
StringBijection::get
T get(const std::string &str) const
Definition: StringBijection.h:98
GUIGlObject::getGlID
GUIGlID getGlID() const
Returns the numerical id of the object.
Definition: GUIGlObject.cpp:150
Boundary
A class that stores a 2D geometrical boundary.
Definition: Boundary.h:42
GNEInternalLane::colorForLinksState
static RGBColor colorForLinksState(FXuint state)
return the color for each linkstate
Definition: GNEInternalLane.cpp:194
GNETLSEditorFrame.h
GUIVisualizationSettings::scale
double scale
information about a lane's width (temporary, used for a single view)
Definition: GUIVisualizationSettings.h:623
ProcessError
Definition: UtilExceptions.h:40
GNEInternalLane::setLinkState
void setLinkState(LinkState state)
set the linkState (controls drawing color)
Definition: GNEInternalLane.cpp:139
GNETLSEditorFrame::handleChange
void handleChange(GNEInternalLane *lane)
update phase definition for the current traffic light and phase
Definition: GNETLSEditorFrame.cpp:743
Position
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:39
Position::x
double x() const
Returns the x-position.
Definition: Position.h:57
GNEInternalLane::getTLIndex
int getTLIndex() const
get Traffic Light index
Definition: GNEInternalLane.cpp:152
GLHelper::drawLine
static void drawLine(const Position &beg, double rot, double visLength)
Draws a thin line.
Definition: GLHelper.cpp:274
GNEInternalLane::myStateTarget
FXDataTarget myStateTarget
Definition: GNEInternalLane.h:131
GUIGlObject
Definition: GUIGlObject.h:66
GNEInternalLane::~GNEInternalLane
virtual ~GNEInternalLane()
Destructor.
Definition: GNEInternalLane.cpp:97
GUIGlObject::buildPopupHeader
void buildPopupHeader(GUIGLObjectPopupMenu *ret, GUIMainWindow &app, bool addSeparator=true)
Builds the header.
Definition: GUIGlObject.cpp:208
GUIVisualizationSettings::getLinkColor
static const RGBColor & getLinkColor(const LinkState &ls)
map from LinkState to color constants
Definition: GUIVisualizationSettings.cpp:1566
Position::distanceTo2D
double distanceTo2D(const Position &p2) const
returns the euclidean distance in the x-y-plane
Definition: Position.h:244
GNEInternalLane::getPopUpMenu
GUIGLObjectPopupMenu * getPopUpMenu(GUIMainWindow &app, GUISUMOAbstractView &parent)
Returns an own popup-menu.
Definition: GNEInternalLane.cpp:158
GLIncludes.h
toString
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:48
GUIMainWindow
Definition: GUIMainWindow.h:47
Position::y
double y() const
Returns the y-position.
Definition: Position.h:62
M_PI
#define M_PI
Definition: odrSpiral.cpp:40
GNEInternalLane::drawGL
void drawGL(const GUIVisualizationSettings &s) const
Draws the object.
Definition: GNEInternalLane.cpp:121
LINKSTATE_TL_YELLOW_MAJOR
The link has yellow light, may pass.
Definition: SUMOXMLDefinitions.h:1142
GNEInternalLane::getParameterWindow
GUIParameterTableWindow * getParameterWindow(GUIMainWindow &app, GUISUMOAbstractView &parent)
Returns an own parameter window.
Definition: GNEInternalLane.cpp:176
GNEInternalLane
This object is responsible for drawing a shape and for supplying a a popup menu. Messages are routete...
Definition: GNEInternalLane.h:43
GNEInternalLane::GNEInternalLane
GNEInternalLane()
FOX needs this.
Definition: GNEInternalLane.cpp:91
GNEInternalLane::getCenteringBoundary
Boundary getCenteringBoundary() const
Returns the boundary to which the view shall be centered in order to show the object.
Definition: GNEInternalLane.cpp:186
GNEInternalLane::myOrigState
LinkState myOrigState
the original state of the link (used for tracking modification)
Definition: GNEInternalLane.h:134
GNEInternalLane::getLinkState
LinkState getLinkState() const
whether link state has been modfied
Definition: GNEInternalLane.cpp:146
GNEInternalLane::myTlIndex
int myTlIndex
the tl-index of this lane
Definition: GNEInternalLane.h:143
GNEInternalLane::myShapeRotations
std::vector< double > myShapeRotations
Definition: GNEInternalLane.h:123
config.h
GNEInternalLane::LinkStateNames
static const StringBijection< FXuint > LinkStateNames
long names for link states
Definition: GNEInternalLane.h:107
GeomHelper.h
GLO_JUNCTION
a junction
Definition: GUIGlObjectTypes.h:51
GNEInternalLane::linkStateNamesValues
static StringBijection< FXuint >::Entry linkStateNamesValues[]
linkstates names values
Definition: GNEInternalLane.h:149
GNEInternalLane::onDefault
long onDefault(FXObject *, FXSelector, void *)
multiplexes message to two targets
Definition: GNEInternalLane.cpp:101
Boundary::grow
Boundary & grow(double by)
extends the boundary by the given amount
Definition: Boundary.cpp:301
LINKSTATE_TL_RED
The link has red light (must brake)
Definition: SUMOXMLDefinitions.h:1138
GNETLSEditorFrame
Definition: GNETLSEditorFrame.h:41
MFXUtils::getFXColor
static FXColor getFXColor(const RGBColor &col)
converts FXColor to RGBColor
Definition: MFXUtils.cpp:114
GUIVisualizationSettings
Stores the information about how to visualize structures.
Definition: GUIVisualizationSettings.h:346
GUISUMOAbstractView::destroyPopup
void destroyPopup()
destoys the popup
Definition: GUISUMOAbstractView.cpp:864
GNEInternalLane::myShapeLengths
std::vector< double > myShapeLengths
The lengths of the shape parts.
Definition: GNEInternalLane.h:126
GNEInternalLane::myShape
const PositionVector myShape
the shape of the edge
Definition: GNEInternalLane.h:118
LINKSTATE_STOP
This is an uncontrolled, minor link, has to stop.
Definition: SUMOXMLDefinitions.h:1156