Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
GNEInternalLane.cpp
Go to the documentation of this file.
1/****************************************************************************/
2// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3// Copyright (C) 2001-2023 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>
29
30#include "GNEInternalLane.h"
31#include "GNEJunction.h"
32
33// ===========================================================================
34// FOX callback mapping
35// ===========================================================================
36FXIMPLEMENT(GNEInternalLane, FXDelegator, 0, 0)
37
38// ===========================================================================
39// static member definitions
40// ===========================================================================
41
42StringBijection<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 }, (should not be used)
46 { "Yellow", LINKSTATE_TL_YELLOW_MINOR },
47 { "Red", LINKSTATE_TL_RED },
48 { "Red-Yellow", LINKSTATE_TL_REDYELLOW },
49 { "Stop", LINKSTATE_STOP },
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 GUIIconSubSys::getIcon(GUIIcon::LANE), {}, {}, {}, {}, {}, {}),
65 myJunctionParent(junctionParent),
66 myState(state),
67 myStateTarget(myState),
68 myEditor(editor),
69 myTlIndex(tlIndex),
70myPopup(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 GUIIconSubSys::getIcon(GUIIcon::LANE), {}, {}, {}, {}, {}, {}),
81myJunctionParent(nullptr),
82myState(0),
83myEditor(0),
84myTlIndex(0),
85myPopup(nullptr) {
86}
87
88
90
91
92void
94 // nothing to update
95}
96
97
102
103
106 // internal lanes cannot be moved
107 return nullptr;
108}
109
110
111void
112GNEInternalLane::removeGeometryPoint(const Position /*clickedPosition*/, GNEUndoList* /*undolist*/) {
113 // geometry points of internal lanes cannot be removed
114}
115
116
117long
118GNEInternalLane::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
137void
139 // only draw if we're not selecting E1 detectors in TLS Mode
141 // get link state color
142 const auto linkStateColor = colorForLinksState(myState);
143 // avoid draw invisible elements
144 if (linkStateColor.alpha() != 0) {
145 // push name
147 // push layer matrix
149 // translate to front
151 // move front again
152 glTranslated(0, 0, 0.5);
153 // set color
154 GLHelper::setColor(linkStateColor);
155 // draw lane checking whether it is not too small
156 if (s.scale < 1.) {
158 } else {
160 }
161 // pop layer matrix
163 // pop name
165 }
166 }
167}
168
169
170void
172 // Internal lanes cannot be removed
173}
174
175
176void
180
181
182void
184 myState = state;
185 myOrigState = state;
186}
187
188
193
194
195int
197 return myTlIndex;
198}
199
200
203 myPopup = new GUIGLObjectPopupMenu(app, parent, *this);
205 if ((myEditor != nullptr) && (myEditor->getViewNet()->getEditModes().isCurrentSupermodeNetwork())) {
206 const std::vector<std::string> names = LinkStateNames.getStrings();
207 for (std::vector<std::string>::const_iterator it = names.begin(); it != names.end(); it++) {
208 FXuint state = LinkStateNames.get(*it);
209 std::string origHint = ((LinkState)state == myOrigState ? " (original)" : "");
210 FXMenuRadio* mc = new FXMenuRadio(myPopup, (*it + origHint).c_str(), this, FXDataTarget::ID_OPTION + state);
211 mc->setSelBackColor(MFXUtils::getFXColor(colorForLinksState(state)));
212 mc->setBackColor(MFXUtils::getFXColor(colorForLinksState(state)));
213 }
214 }
215 return myPopup;
216}
217
218
221 // internal lanes don't have attributes
223 // close building
224 ret->closeBuilding();
225 return ret;
226}
227
228
229void
234
235
238 try {
240 } catch (ProcessError&) {
241 WRITE_WARNINGF(TL("invalid link state='%'"), toString(state));
242 return RGBColor::BLACK;
243 }
244}
245
246
247std::string
249 throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
250}
251
252
253void
254GNEInternalLane::setAttribute(SumoXMLAttr key, const std::string& /*value*/, GNEUndoList* /*undoList*/) {
255 throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
256}
257
258
259bool
260GNEInternalLane::isValid(SumoXMLAttr key, const std::string& /*value*/) {
261 throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
262}
263
264
265bool
267 throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
268}
269
270
273 throw InvalidArgument(getTagStr() + " doesn't have parameters");
274}
275
276
277void
278GNEInternalLane::setAttribute(SumoXMLAttr key, const std::string& /*value*/) {
279 throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
280}
281
282
283void
285 // internal lanes cannot be moved
286}
287
288
289void
290GNEInternalLane::commitMoveShape(const GNEMoveResult& /*moveResult*/, GNEUndoList* /*undoList*/) {
291 // internal lanes cannot be moved
292}
293
294/****************************************************************************/
@ GLO_TLLOGIC
a tl-logic
GUIIcon
An enumeration of icons used by the gui applications.
Definition GUIIcons.h:33
#define WRITE_WARNINGF(...)
Definition MsgHandler.h:271
#define TL(string)
Definition MsgHandler.h:287
@ GNE_TAG_INTERNAL_LANE
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_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:300
static void drawLine(const Position &beg, double rot, double visLength)
Draws a thin line.
Definition GLHelper.cpp:421
static void setColor(const RGBColor &c)
Sets the gl-color to this value.
Definition GLHelper.cpp:583
static void pushName(unsigned int name)
push Name
Definition GLHelper.cpp:139
static void popMatrix()
pop matrix
Definition GLHelper.cpp:130
static void popName()
pop Name
Definition GLHelper.cpp:148
static void pushMatrix()
push matrix
Definition GLHelper.cpp:117
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:150
This object is responsible for drawing a shape and for supplying a a popup menu. Messages are routete...
void deleteGLObject()
delete element
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)
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 modified
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.
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
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
const Parameterised::Map & getACParametersMap() const
get parameters map
void drawGL(const GUIVisualizationSettings &s) const
Draws the object.
void updateGLObject()
update GLObject (geometry, ID, etc.)
~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:2030
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
void drawTranslateFrontAttributeCarrier(const GNEAttributeCarrier *AC, double typeOrLayer, const double extraOffset=0)
draw front attributeCarrier
bool selectingDetectorsTLSMode() const
check if we're selecting detectors in TLS mode
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()
destroys the popup
virtual 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
std::map< std::string, std::string > Map
parameters map
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
std::vector< std::string > getStrings() const
T get(const std::string &str) const
bool isCurrentSupermodeNetwork() const
@check if current supermode is Network