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-2022 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/GNENet.h>
23 #include <netedit/GNEViewNet.h>
25 #include <utils/gui/div/GLHelper.h>
29 
30 #include "GNEInternalLane.h"
31 #include "GNEJunction.h"
32 
33 // ===========================================================================
34 // FOX callback mapping
35 // ===========================================================================
36 FXIMPLEMENT(GNEInternalLane, FXDelegator, 0, 0)
37 
38 // ===========================================================================
39 // static member definitions
40 // ===========================================================================
41 
42 StringBijection<FXuint>::Entry GNEInternalLane::linkStateNamesValues[] = {
43  { "Green-Major", LINKSTATE_TL_GREEN_MAJOR },
44  { "Green-Minor", LINKSTATE_TL_GREEN_MINOR },
45  { "Yellow-Major", LINKSTATE_TL_YELLOW_MAJOR },
46  { "Yellow-Minor", LINKSTATE_TL_YELLOW_MINOR },
47  { "Red", LINKSTATE_TL_RED },
48  { "Red-Yellow", LINKSTATE_TL_REDYELLOW },
49  { "Stop", LINKSTATE_STOP },
50  { "Off", LINKSTATE_TL_OFF_NOSIGNAL },
51  { "Off-Blinking", LINKSTATE_TL_OFF_BLINKING },
52 };
53 
56 
57 // ===========================================================================
58 // method definitions
59 // ===========================================================================
60 
62  const std::string& id, const PositionVector& shape, int tlIndex, LinkState state) :
63  GNENetworkElement(junctionParent->getNet(), id, GLO_TLLOGIC, GNE_TAG_INTERNAL_LANE,
64 {}, {}, {}, {}, {}, {}, {}, {}),
65 myJunctionParent(junctionParent),
66 myState(state),
67 myStateTarget(myState),
68 myEditor(editor),
69 myTlIndex(tlIndex),
70 myPopup(nullptr) {
71  // calculate internal lane geometry
72  myInternalLaneGeometry.updateGeometry(shape);
73  // update centering boundary without updating grid
74  updateCenteringBoundary(false);
75 }
76 
77 
79  GNENetworkElement(nullptr, "dummyInternalLane", GLO_TLLOGIC, GNE_TAG_INTERNAL_LANE,
80 {}, {}, {}, {}, {}, {}, {}, {}),
81 myJunctionParent(nullptr),
82 myState(0),
83 myEditor(0),
84 myTlIndex(0),
85 myPopup(nullptr) {
86 }
87 
88 
90 
91 
92 void
94  // nothing to update
95 }
96 
97 
101 }
102 
103 
106  // internal lanes cannot be moved
107  return nullptr;
108 }
109 
110 
111 void
112 GNEInternalLane::removeGeometryPoint(const Position /*clickedPosition*/, GNEUndoList* /*undolist*/) {
113  // geometry points of internal lanes cannot be removed
114 }
115 
116 
117 long
118 GNEInternalLane::onDefault(FXObject* obj, FXSelector sel, void* data) {
119  if (myEditor != nullptr) {
120  FXuint before = myState;
121  myStateTarget.handle(obj, sel, data);
122  if (myState != before) {
123  myEditor->handleChange(this);
124  }
125  // let GUISUMOAbstractView know about clicks so that the popup is properly destroyed
126  if (FXSELTYPE(sel) == SEL_COMMAND) {
127  if (myPopup != nullptr) {
129  myPopup = nullptr;
130  }
131  }
132  }
133  return 1;
134 }
135 
136 
137 void
139  // push name
141  // push layer matrix
143  // translate to front
145  // move front again
146  glTranslated(0, 0, 0.5);
147  // set color
149  // draw lane checking whether it is not too small
150  if (s.scale < 1.) {
152  } else {
154  }
155  // pop layer matrix
157  // pop name
159 }
160 
161 
162 void
164  myState = state;
165  myOrigState = state;
166 }
167 
168 
169 LinkState
171  return (LinkState)myState;
172 }
173 
174 
175 int
177  return myTlIndex;
178 }
179 
180 
183  myPopup = new GUIGLObjectPopupMenu(app, parent, *this);
185  if ((myEditor != nullptr) && (myEditor->getViewNet()->getEditModes().isCurrentSupermodeNetwork())) {
186  const std::vector<std::string> names = LinkStateNames.getStrings();
187  for (std::vector<std::string>::const_iterator it = names.begin(); it != names.end(); it++) {
188  FXuint state = LinkStateNames.get(*it);
189  std::string origHint = ((LinkState)state == myOrigState ? " (original)" : "");
190  FXMenuRadio* mc = new FXMenuRadio(myPopup, (*it + origHint).c_str(), this, FXDataTarget::ID_OPTION + state);
191  mc->setSelBackColor(MFXUtils::getFXColor(colorForLinksState(state)));
192  mc->setBackColor(MFXUtils::getFXColor(colorForLinksState(state)));
193  }
194  }
195  return myPopup;
196 }
197 
198 
201  // internal lanes don't have attributes
202  GUIParameterTableWindow* ret = new GUIParameterTableWindow(app, *this);
203  // close building
204  ret->closeBuilding();
205  return ret;
206 }
207 
208 
209 double
211  return 1;
212 }
213 
214 
215 void
216 GNEInternalLane::updateCenteringBoundary(const bool /*updateGrid*/) {
218  myBoundary.grow(10);
219 }
220 
221 
222 RGBColor
224  if (state == LINKSTATE_TL_YELLOW_MINOR) {
225  // special case (default gui does not distinguish between yellow major/minor
226  return RGBColor(179, 179, 0, 255);
227  } else {
228  try {
230  } catch (ProcessError&) {
231  WRITE_WARNING("invalid link state='" + toString(state) + "'");
232  return RGBColor::BLACK;
233  }
234  }
235 }
236 
237 
238 std::string
240  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
241 }
242 
243 
244 void
245 GNEInternalLane::setAttribute(SumoXMLAttr key, const std::string& /*value*/, GNEUndoList* /*undoList*/) {
246  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
247 }
248 
249 
250 bool
251 GNEInternalLane::isValid(SumoXMLAttr key, const std::string& /*value*/) {
252  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
253 }
254 
255 
256 bool
258  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
259 }
260 
261 
262 bool
264  return false;
265 }
266 
267 
268 const std::map<std::string, std::string>&
270  throw InvalidArgument(getTagStr() + " doesn't have parameters");
271 }
272 
273 
274 void
275 GNEInternalLane::setAttribute(SumoXMLAttr key, const std::string& /*value*/) {
276  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
277 }
278 
279 
280 void
282  // internal lanes cannot be moved
283 }
284 
285 
286 void
287 GNEInternalLane::commitMoveShape(const GNEMoveResult& /*moveResult*/, GNEUndoList* /*undoList*/) {
288  // internal lanes cannot be moved
289 }
290 
291 /****************************************************************************/
@ GLO_TLLOGIC
a tl-logic
#define WRITE_WARNING(msg)
Definition: MsgHandler.h:280
@ 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:46
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:369
static void setColor(const RGBColor &c)
Sets the gl-color to this value.
Definition: GLHelper.cpp:507
static void pushName(unsigned int name)
push Name
Definition: GLHelper.cpp:132
static void popMatrix()
pop matrix
Definition: GLHelper.cpp:123
static void popName()
pop Name
Definition: GLHelper.cpp:141
static void pushMatrix()
push matrix
Definition: GLHelper.cpp:114
const std::string & getTagStr() const
get tag assigned to this object in string format
GNENet * myNet
pointer to net
GNEViewNet * getViewNet() const
get view net
Definition: GNEFrame.cpp:133
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
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.
double getExaggeration(const GUIVisualizationSettings &s) const
return exaggeration asociated with this GLObject
void removeGeometryPoint(const Position clickedPosition, GNEUndoList *undoList)
remove geometry point in the clicked position
GNEMoveOperation * getMoveOperation()
get move operation
static StringBijection< FXuint >::Entry linkStateNamesValues[]
linkstates names values
bool isAttributeComputed(SumoXMLAttr key) const
GUIGeometry 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
GNEViewNet * getViewNet() const
get view net
Definition: GNENet.cpp:1964
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:513
void drawTranslateFrontAttributeCarrier(const GNEAttributeCarrier *AC, double typeOrLayer, const double extraOffset=0)
draw front attributeCarrier
The popup menu of a globject.
GUISUMOAbstractView * getParentView()
return the real owner of this popup
static void drawGeometry(const GUIVisualizationSettings &s, const Position &mousePos, const GUIGeometry &geometry, const double width, double offset=0)
draw geometry
const PositionVector & getShape() const
The shape of the additional element.
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
Position getPositionInformation() const
Returns the cursor's x/y position within the network.
Stores the information about how to visualize structures.
static const RGBColor & getLinkColor(const LinkState &ls, bool realistic=false)
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:37
A list of positions.
Boundary getBoxBoundary() const
Returns a boundary enclosing this list of lines.
static const RGBColor BLACK
Definition: RGBColor.h:193
T get(const std::string &str) const
std::vector< std::string > getStrings() const
bool isCurrentSupermodeNetwork() const
@check if current supermode is Network