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 /****************************************************************************/
14 // A class for visualizing Inner Lanes (used when editing traffic lights)
15 /****************************************************************************/
16 
17 
18 // ===========================================================================
19 // included modules
20 // ===========================================================================
21 #include <config.h>
22 
23 #include <utils/geom/GeomHelper.h>
26 #include <utils/gui/div/GLHelper.h>
28 #include <netedit/GNEViewNet.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  myState(state),
72  myStateTarget(myState),
73  myEditor(editor),
74  myTlIndex(tlIndex),
75  myPopup(nullptr) {
76  // calculate internal lane geometry
78 }
79 
80 
82  GUIGlObject(GLO_TLLOGIC, "dummyInternalLane") {
83  assert(false);
84 }
85 
86 
88 
89 
90 long
91 GNEInternalLane::onDefault(FXObject* obj, FXSelector sel, void* data) {
92  if (myEditor != nullptr) {
93  FXuint before = myState;
94  myStateTarget.handle(obj, sel, data);
95  if (myState != before) {
96  myEditor->handleChange(this);
97  }
98  // let GUISUMOAbstractView know about clicks so that the popup is properly destroyed
99  if (FXSELTYPE(sel) == SEL_COMMAND) {
100  if (myPopup != nullptr) {
102  myPopup = nullptr;
103  }
104  }
105  }
106  return 1;
107 }
108 
109 
110 void
112  glPushMatrix();
113  glPushName(getGlID());
114  glTranslated(0, 0, GLO_JUNCTION + 0.1); // must draw on top of junction
116  // draw lane
117  // check whether it is not too small
118  if (s.scale < 1.) {
120  } else {
122  }
123  glPopName();
124  glPopMatrix();
125 }
126 
127 
128 void
130  myState = state;
131  myOrigState = state;
132 }
133 
134 
135 LinkState
137  return (LinkState)myState;
138 }
139 
140 
141 int
143  return myTlIndex;
144 }
145 
146 
149  myPopup = new GUIGLObjectPopupMenu(app, parent, *this);
152  const std::vector<std::string> names = LinkStateNames.getStrings();
153  for (std::vector<std::string>::const_iterator it = names.begin(); it != names.end(); it++) {
154  FXuint state = LinkStateNames.get(*it);
155  std::string origHint = ((LinkState)state == myOrigState ? " (original)" : "");
156  FXMenuRadio* mc = new FXMenuRadio(myPopup, (*it + origHint).c_str(), this, FXDataTarget::ID_OPTION + state);
157  mc->setSelBackColor(MFXUtils::getFXColor(colorForLinksState(state)));
158  mc->setBackColor(MFXUtils::getFXColor(colorForLinksState(state)));
159  }
160  }
161  return myPopup;
162 }
163 
164 
167  // internal lanes don't have attributes
168  GUIParameterTableWindow* ret = new GUIParameterTableWindow(app, *this, 2);
169  // close building
170  ret->closeBuilding();
171  return ret;
172 }
173 
174 
175 Boundary
178  b.grow(10);
179  return b;
180 }
181 
182 
183 RGBColor
185  if (state == LINKSTATE_TL_YELLOW_MINOR) {
186  // special case (default gui does not distinguish between yellow major/minor
187  return RGBColor(179, 179, 0, 255);
188  } else {
189  try {
191  } catch (ProcessError&) {
192  WRITE_WARNING("invalid link state='" + toString(state) + "'");
193  return RGBColor::BLACK;
194  }
195  }
196 }
197 
198 /****************************************************************************/
GUIParameterTableWindow
A window containing a gl-object's parameter.
Definition: GUIParameterTableWindow.h:62
WRITE_WARNING
#define WRITE_WARNING(msg)
Definition: MsgHandler.h:275
GNEGeometry::Geometry::updateGeometryShape
void updateGeometryShape(const PositionVector &shape, double startPos=-1, double endPos=-1, const Position &extraFirstPosition=Position::INVALID, const Position &extraLastPosition=Position::INVALID)
update geometry shape
Definition: GNEGeometry.cpp:48
GUISUMOAbstractView
Definition: GUISUMOAbstractView.h:72
LINKSTATE_TL_OFF_BLINKING
The link is controlled by a tls which is off and blinks, has to brake.
Definition: SUMOXMLDefinitions.h:1151
GNEInternalLane.h
GNEInternalLane::myPopup
GUIGLObjectPopupMenu * myPopup
the created popup
Definition: GNEInternalLane.h:136
GUIParameterTableWindow.h
RGBColor::BLACK
static const RGBColor BLACK
Definition: RGBColor.h:197
LINKSTATE_TL_OFF_NOSIGNAL
The link is controlled by a tls which is off, not blinking, may pass.
Definition: SUMOXMLDefinitions.h:1153
GNEInternalLane::myEditor
GNETLSEditorFrame * myEditor
the editor to inform about changes
Definition: GNEInternalLane.h:130
GNEFrame::getViewNet
GNEViewNet * getViewNet() const
get view net
Definition: GNEFrame.cpp:132
GUIGLObjectPopupMenu.h
StringBijection::getStrings
std::vector< std::string > getStrings() const
Definition: StringBijection.h:131
LINKSTATE_TL_GREEN_MINOR
The link has green light, has to brake.
Definition: SUMOXMLDefinitions.h:1141
GLHelper.h
LINKSTATE_TL_GREEN_MAJOR
The link has green light, may pass.
Definition: SUMOXMLDefinitions.h:1139
PositionVector
A list of positions.
Definition: PositionVector.h:45
GUIGLObjectPopupMenu
The popup menu of a globject.
Definition: GUIGLObjectPopupMenu.h:47
GUIGLObjectPopupMenu::getParentView
GUISUMOAbstractView * getParentView()
return the real owner of this popup
Definition: GUIGLObjectPopupMenu.h:66
GLHelper::setColor
static void setColor(const RGBColor &c)
Sets the gl-color to this value.
Definition: GLHelper.cpp:621
PositionVector::getBoxBoundary
Boundary getBoxBoundary() const
Returns a boundary enclosing this list of lines.
Definition: PositionVector.cpp:390
GUIParameterTableWindow::closeBuilding
void closeBuilding(const Parameterised *p=0)
Closes the building of the table.
Definition: GUIParameterTableWindow.cpp:219
GLO_TLLOGIC
a tl-logic
Definition: GUIGlObjectTypes.h:56
RGBColor
Definition: RGBColor.h:39
LinkState
LinkState
The right-of-way state of a link between two lanes used when constructing a NBTrafficLightLogic,...
Definition: SUMOXMLDefinitions.h:1137
LINKSTATE_TL_YELLOW_MINOR
The link has yellow light, has to brake anyway.
Definition: SUMOXMLDefinitions.h:1149
StringBijection
Definition: StringBijection.h:43
GNEGeometry::Geometry::getShape
const PositionVector & getShape() const
The shape of the additional element.
Definition: GNEGeometry.cpp:147
GNEInternalLane::myState
FXuint myState
the state of the link (used for visualization)
Definition: GNEInternalLane.h:120
LINKSTATE_TL_REDYELLOW
The link has red light (must brake) but indicates upcoming green.
Definition: SUMOXMLDefinitions.h:1145
StringBijection::get
T get(const std::string &str) const
Definition: StringBijection.h:97
GNEViewNet.h
GUIGlObject::getGlID
GUIGlID getGlID() const
Returns the numerical id of the object.
Definition: GUIGlObject.cpp:149
GNEInternalLane::myInternalLaneGeometry
GNEGeometry::Geometry myInternalLaneGeometry
internal lane geometry
Definition: GNEInternalLane.h:117
Boundary
A class that stores a 2D geometrical boundary.
Definition: Boundary.h:41
GNEInternalLane::colorForLinksState
static RGBColor colorForLinksState(FXuint state)
return the color for each linkstate
Definition: GNEInternalLane.cpp:184
GNETLSEditorFrame.h
GNEGeometry::drawGeometry
static void drawGeometry(const GNEViewNet *viewNet, const Geometry &geometry, const double width)
draw geometry
Definition: GNEGeometry.cpp:795
GUIVisualizationSettings::scale
double scale
information about a lane's width (temporary, used for a single view)
Definition: GUIVisualizationSettings.h:632
GNE_SUPERMODE_NETWORK
Network mode (Edges, junctions, etc..)
Definition: GNEViewNetHelper.h:46
ProcessError
Definition: UtilExceptions.h:39
GNEViewNetHelper::EditModes::currentSupermode
Supermode currentSupermode
the current supermode
Definition: GNEViewNetHelper.h:305
GNEInternalLane::setLinkState
void setLinkState(LinkState state)
set the linkState (controls drawing color)
Definition: GNEInternalLane.cpp:129
GNETLSEditorFrame::handleChange
void handleChange(GNEInternalLane *lane)
update phase definition for the current traffic light and phase
Definition: GNETLSEditorFrame.cpp:758
GNEInternalLane::getTLIndex
int getTLIndex() const
get Traffic Light index
Definition: GNEInternalLane.cpp:142
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:121
GUIGlObject
Definition: GUIGlObject.h:65
GNEInternalLane::~GNEInternalLane
virtual ~GNEInternalLane()
Destructor.
Definition: GNEInternalLane.cpp:87
GUIGlObject::buildPopupHeader
void buildPopupHeader(GUIGLObjectPopupMenu *ret, GUIMainWindow &app, bool addSeparator=true)
Builds the header.
Definition: GUIGlObject.cpp:207
GUIVisualizationSettings::getLinkColor
static const RGBColor & getLinkColor(const LinkState &ls)
map from LinkState to color constants
Definition: GUIVisualizationSettings.cpp:1608
GNEInternalLane::getPopUpMenu
GUIGLObjectPopupMenu * getPopUpMenu(GUIMainWindow &app, GUISUMOAbstractView &parent)
Returns an own popup-menu.
Definition: GNEInternalLane.cpp:148
GLIncludes.h
toString
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:47
GUIMainWindow
Definition: GUIMainWindow.h:46
GNEInternalLane::drawGL
void drawGL(const GUIVisualizationSettings &s) const
Draws the object.
Definition: GNEInternalLane.cpp:111
LINKSTATE_TL_YELLOW_MAJOR
The link has yellow light, may pass.
Definition: SUMOXMLDefinitions.h:1147
GNEInternalLane::getParameterWindow
GUIParameterTableWindow * getParameterWindow(GUIMainWindow &app, GUISUMOAbstractView &parent)
Returns an own parameter window.
Definition: GNEInternalLane.cpp:166
GNEInternalLane
This object is responsible for drawing a shape and for supplying a a popup menu. Messages are routete...
Definition: GNEInternalLane.h:42
GNEInternalLane::GNEInternalLane
GNEInternalLane()
FOX needs this.
Definition: GNEInternalLane.cpp:81
GNEInternalLane::getCenteringBoundary
Boundary getCenteringBoundary() const
Returns the boundary to which the view shall be centered in order to show the object.
Definition: GNEInternalLane.cpp:176
GNEInternalLane::myOrigState
LinkState myOrigState
the original state of the link (used for tracking modification)
Definition: GNEInternalLane.h:124
GNEInternalLane::getLinkState
LinkState getLinkState() const
whether link state has been modfied
Definition: GNEInternalLane.cpp:136
GNEInternalLane::myTlIndex
int myTlIndex
the tl-index of this lane
Definition: GNEInternalLane.h:133
config.h
GNEInternalLane::LinkStateNames
static const StringBijection< FXuint > LinkStateNames
long names for link states
Definition: GNEInternalLane.h:106
GeomHelper.h
GLO_JUNCTION
a junction
Definition: GUIGlObjectTypes.h:50
GNEViewNet::getEditModes
const GNEViewNetHelper::EditModes & getEditModes() const
get edit modes
Definition: GNEViewNet.cpp:434
GNEInternalLane::linkStateNamesValues
static StringBijection< FXuint >::Entry linkStateNamesValues[]
linkstates names values
Definition: GNEInternalLane.h:139
GNEInternalLane::onDefault
long onDefault(FXObject *, FXSelector, void *)
multiplexes message to two targets
Definition: GNEInternalLane.cpp:91
Boundary::grow
Boundary & grow(double by)
extends the boundary by the given amount
Definition: Boundary.cpp:300
LINKSTATE_TL_RED
The link has red light (must brake)
Definition: SUMOXMLDefinitions.h:1143
GNETLSEditorFrame
Definition: GNETLSEditorFrame.h:40
MFXUtils::getFXColor
static FXColor getFXColor(const RGBColor &col)
converts FXColor to RGBColor
Definition: MFXUtils.cpp:113
GUIVisualizationSettings
Stores the information about how to visualize structures.
Definition: GUIVisualizationSettings.h:345
GUISUMOAbstractView::destroyPopup
void destroyPopup()
destoys the popup
Definition: GUISUMOAbstractView.cpp:884
LINKSTATE_STOP
This is an uncontrolled, minor link, has to stop.
Definition: SUMOXMLDefinitions.h:1161