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-2020 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials are made available under the
5 // terms of the Eclipse Public License 2.0 which is available at
6 // https://www.eclipse.org/legal/epl-2.0/
7 // This Source Code may also be made available under the following Secondary
8 // Licenses when the conditions for such availability set forth in the Eclipse
9 // Public License 2.0 are satisfied: GNU General Public License, version 2
10 // or later which is available at
11 // https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
12 // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
13 /****************************************************************************/
18 // A class for visualizing Inner Lanes (used when editing traffic lights)
19 /****************************************************************************/
20 #include <config.h>
21 
22 #include <netedit/GNEViewNet.h>
24 #include <utils/gui/div/GLHelper.h>
28 
29 #include "GNEInternalLane.h"
30 #include "GNEJunction.h"
31 
32 // ===========================================================================
33 // FOX callback mapping
34 // ===========================================================================
35 FXIMPLEMENT(GNEInternalLane, FXDelegator, 0, 0)
36 
37 // ===========================================================================
38 // static member definitions
39 // ===========================================================================
40 
41 StringBijection<FXuint>::Entry GNEInternalLane::linkStateNamesValues[] = {
42  { "Green-Major", LINKSTATE_TL_GREEN_MAJOR },
43  { "Green-Minor", LINKSTATE_TL_GREEN_MINOR },
44  { "Yellow-Major", LINKSTATE_TL_YELLOW_MAJOR },
45  { "Yellow-Minor", LINKSTATE_TL_YELLOW_MINOR },
46  { "Red", LINKSTATE_TL_RED },
47  { "Red-Yellow", LINKSTATE_TL_REDYELLOW },
48  { "Stop", LINKSTATE_STOP },
49  { "Off", LINKSTATE_TL_OFF_NOSIGNAL },
50  { "Off-Blinking", LINKSTATE_TL_OFF_BLINKING },
51 };
52 
55 
56 // ===========================================================================
57 // method definitions
58 // ===========================================================================
59 
61  const std::string& id, const PositionVector& shape, int tlIndex, LinkState state) :
62  GNENetworkElement(junctionParent->getNet(), id, GLO_TLLOGIC, GNE_TAG_INTERNAL_LANE,
63 {}, {}, {}, {}, {}, {}, {}, {}),
64 myJunctionParent(junctionParent),
65 myState(state),
66 myStateTarget(myState),
67 myEditor(editor),
68 myTlIndex(tlIndex),
69 myPopup(nullptr) {
70  // calculate internal lane geometry
71  myInternalLaneGeometry.updateGeometry(shape);
72  // update centering boundary without updating grid
73  updateCenteringBoundary(false);
74 }
75 
76 
78  GNENetworkElement(nullptr, "dummyInternalLane", GLO_TLLOGIC, GNE_TAG_INTERNAL_LANE,
79 {}, {}, {}, {}, {}, {}, {}, {}),
80 myJunctionParent(nullptr),
81 myState(0),
82 myEditor(0),
83 myTlIndex(0),
84 myPopup(nullptr) {
85 }
86 
87 
89 
90 
91 void
93  // nothing to update
94 }
95 
96 
100 }
101 
102 
104 GNEInternalLane::getMoveOperation(const double /*shapeOffset*/) {
105  // internal lanes cannot be moved
106  return nullptr;
107 }
108 
109 
110 void
111 GNEInternalLane::removeGeometryPoint(const Position /*clickedPosition*/, GNEUndoList* /*undolist*/) {
112  // geometry points of internal lanes cannot be removed
113 }
114 
115 
116 long
117 GNEInternalLane::onDefault(FXObject* obj, FXSelector sel, void* data) {
118  if (myEditor != nullptr) {
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 != nullptr) {
128  myPopup = nullptr;
129  }
130  }
131  }
132  return 1;
133 }
134 
135 
136 void
138  // push name
139  glPushName(getGlID());
140  // push layer matrix
141  glPushMatrix();
142  // translate to front
144  // move front again
145  glTranslated(0, 0, 0.5);
146  // set color
148  // draw lane checking whether it is not too small
149  if (s.scale < 1.) {
151  } else {
153  }
154  // pop layer matrix
155  glPopMatrix();
156  // pop name
157  glPopName();
158 }
159 
160 
161 void
163  myState = state;
164  myOrigState = state;
165 }
166 
167 
168 LinkState
170  return (LinkState)myState;
171 }
172 
173 
174 int
176  return myTlIndex;
177 }
178 
179 
182  myPopup = new GUIGLObjectPopupMenu(app, parent, *this);
184  if ((myEditor != nullptr) && (myEditor->getViewNet()->getEditModes().isCurrentSupermodeNetwork())) {
185  const std::vector<std::string> names = LinkStateNames.getStrings();
186  for (std::vector<std::string>::const_iterator it = names.begin(); it != names.end(); it++) {
187  FXuint state = LinkStateNames.get(*it);
188  std::string origHint = ((LinkState)state == myOrigState ? " (original)" : "");
189  FXMenuRadio* mc = new FXMenuRadio(myPopup, (*it + origHint).c_str(), this, FXDataTarget::ID_OPTION + state);
190  mc->setSelBackColor(MFXUtils::getFXColor(colorForLinksState(state)));
191  mc->setBackColor(MFXUtils::getFXColor(colorForLinksState(state)));
192  }
193  }
194  return myPopup;
195 }
196 
197 
200  // internal lanes don't have attributes
201  GUIParameterTableWindow* ret = new GUIParameterTableWindow(app, *this);
202  // close building
203  ret->closeBuilding();
204  return ret;
205 }
206 
207 
208 void
209 GNEInternalLane::updateCenteringBoundary(const bool /*updateGrid*/) {
211  myBoundary.grow(10);
212 }
213 
214 
215 RGBColor
217  if (state == LINKSTATE_TL_YELLOW_MINOR) {
218  // special case (default gui does not distinguish between yellow major/minor
219  return RGBColor(179, 179, 0, 255);
220  } else {
221  try {
223  } catch (ProcessError&) {
224  WRITE_WARNING("invalid link state='" + toString(state) + "'");
225  return RGBColor::BLACK;
226  }
227  }
228 }
229 
230 
231 std::string
233  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
234 }
235 
236 
237 void
238 GNEInternalLane::setAttribute(SumoXMLAttr key, const std::string& /*value*/, GNEUndoList* /*undoList*/) {
239  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
240 }
241 
242 
243 bool
244 GNEInternalLane::isValid(SumoXMLAttr key, const std::string& /*value*/) {
245  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
246 }
247 
248 
249 bool
251  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
252 }
253 
254 
255 const std::map<std::string, std::string>&
257  throw InvalidArgument(getTagStr() + " doesn't have parameters");
258 }
259 
260 
261 void
262 GNEInternalLane::setAttribute(SumoXMLAttr key, const std::string& /*value*/) {
263  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
264 }
265 
266 
267 void
269  // internal lanes cannot be moved
270 }
271 
272 
273 void
274 GNEInternalLane::commitMoveShape(const GNEMoveResult& /*moveResult*/, GNEUndoList* /*undoList*/) {
275  // internal lanes cannot be moved
276 }
277 
278 /****************************************************************************/
@ GLO_TLLOGIC
a tl-logic
#define WRITE_WARNING(msg)
Definition: MsgHandler.h:276
@ GNE_TAG_INTERNAL_LANE
LinkState
The right-of-way state of a link between two lanes used when constructing a NBTrafficLightLogic,...
@ LINKSTATE_TL_REDYELLOW
The link has red light (must brake) but indicates upcoming green.
@ LINKSTATE_STOP
This is an uncontrolled, minor link, has to stop.
@ LINKSTATE_TL_YELLOW_MAJOR
The link has yellow light, may pass.
@ LINKSTATE_TL_GREEN_MAJOR
The link has green light, may pass.
@ LINKSTATE_TL_OFF_BLINKING
The link is controlled by a tls which is off and blinks, has to brake.
@ LINKSTATE_TL_YELLOW_MINOR
The link has yellow light, has to brake anyway.
@ LINKSTATE_TL_RED
The link has red light (must brake)
@ LINKSTATE_TL_GREEN_MINOR
The link has green light, has to brake.
@ LINKSTATE_TL_OFF_NOSIGNAL
The link is controlled by a tls which is off, not blinking, may pass.
SumoXMLAttr
Numbers representing SUMO-XML - attributes.
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:44
Boundary & grow(double by)
extends the boundary by the given amount
Definition: Boundary.cpp:299
static void drawLine(const Position &beg, double rot, double visLength)
Draws a thin line.
Definition: GLHelper.cpp:273
static void setColor(const RGBColor &c)
Sets the gl-color to this value.
Definition: GLHelper.cpp:446
const std::string & getTagStr() const
get tag assigned to this object in string format
GNEViewNet * getViewNet() const
get view net
Definition: GNEFrame.cpp:133
const PositionVector & getShape() const
The shape of the additional element.
This object is responsible for drawing a shape and for supplying a a popup menu. Messages are routete...
GUIGLObjectPopupMenu * getPopUpMenu(GUIMainWindow &app, GUISUMOAbstractView &parent)
Returns an own popup-menu.
void commitMoveShape(const GNEMoveResult &moveResult, GNEUndoList *undoList)
commit move shape
void setMoveShape(const GNEMoveResult &moveResult)
set move shape
GNEInternalLane()
FOX needs this.
long onDefault(FXObject *, FXSelector, void *)
multiplexes message to two targets
static RGBColor colorForLinksState(FXuint state)
return the color for each linkstate
LinkState myOrigState
the original state of the link (used for tracking modification)
const std::map< std::string, std::string > & getACParametersMap() const
get parameters map
void updateCenteringBoundary(const bool updateGrid)
update centering boundary (implies change in RTREE)
void updateGeometry()
update pre-computed geometry information
std::string getAttribute(SumoXMLAttr key) const
const GNEJunction * myJunctionParent
pointer to junction parent
FXuint myState
the state of the link (used for visualization)
LinkState getLinkState() const
whether link state has been modfied
FXDataTarget myStateTarget
GNEMoveOperation * getMoveOperation(const double shapeOffset)
get move operation for the given shapeOffset
int myTlIndex
the tl-index of this lane
GUIGLObjectPopupMenu * myPopup
the created popup
void setAttribute(SumoXMLAttr key, const std::string &value, GNEUndoList *undoList)
GUIParameterTableWindow * getParameterWindow(GUIMainWindow &app, GUISUMOAbstractView &parent)
Returns an own parameter window.
Position getPositionInView() const
Returns position of hierarchical element in view.
void removeGeometryPoint(const Position clickedPosition, GNEUndoList *undoList)
remove geometry point in the clicked position
static StringBijection< FXuint >::Entry linkStateNamesValues[]
linkstates names values
GNEGeometry::Geometry myInternalLaneGeometry
internal lane geometry
bool isValid(SumoXMLAttr key, const std::string &value)
static const StringBijection< FXuint > LinkStateNames
long names for link states
int getTLIndex() const
get Traffic Light index
void drawGL(const GUIVisualizationSettings &s) const
Draws the object.
~GNEInternalLane()
Destructor.
void setLinkState(LinkState state)
set the linkState (controls drawing color)
GNETLSEditorFrame * myEditor
the editor to inform about changes
bool isAttributeEnabled(SumoXMLAttr key) const
Position getPositionInView() const
Returns position of hierarchical element in view.
move operation
move result
virtual void updateGeometry()=0
update pre-computed geometry information
Boundary myBoundary
object boundary
void handleChange(GNEInternalLane *lane)
update phase definition for the current traffic light and phase
const GNEViewNetHelper::EditModes & getEditModes() const
get edit modes
Definition: GNEViewNet.cpp:467
void drawTranslateFrontAttributeCarrier(const GNEAttributeCarrier *AC, GUIGlObjectType objectType, const double extraOffset=0)
draw front attributeCarrier
The popup menu of a globject.
GUISUMOAbstractView * getParentView()
return the real owner of this popup
void buildPopupHeader(GUIGLObjectPopupMenu *ret, GUIMainWindow &app, bool addSeparator=true)
Builds the header.
GUIGlID getGlID() const
Returns the numerical id of the object.
A window containing a gl-object's parameter.
void closeBuilding(const Parameterised *p=0)
Closes the building of the table.
void destroyPopup()
destoys the popup
Stores the information about how to visualize structures.
static const RGBColor & getLinkColor(const LinkState &ls)
map from LinkState to color constants
double scale
information about a lane's width (temporary, used for a single view)
static FXColor getFXColor(const RGBColor &col)
converts FXColor to RGBColor
Definition: MFXUtils.cpp:112
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:36
A list of positions.
Boundary getBoxBoundary() const
Returns a boundary enclosing this list of lines.
static const RGBColor BLACK
Definition: RGBColor.h:188
T get(const std::string &str) const
std::vector< std::string > getStrings() const
static void drawGeometry(const GNEViewNet *viewNet, const Geometry &geometry, const double width)
draw geometry
bool isCurrentSupermodeNetwork() const
@check if current supermode is Network