Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
eclipse
GitHub Repository: eclipse/sumo
Path: blob/main/src/netedit/elements/network/GNEInternalLane.cpp
185790 views
1
/****************************************************************************/
2
// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3
// Copyright (C) 2001-2025 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
/****************************************************************************/
14
/// @file GNEInternalLane.cpp
15
/// @author Jakob Erdmann
16
/// @date June 2011
17
///
18
// A class for visualizing Inner Lanes (used when editing traffic lights)
19
/****************************************************************************/
20
21
#include <netedit/GNENet.h>
22
#include <netedit/frames/network/GNETLSEditorFrame.h>
23
#include <utils/gui/div/GLHelper.h>
24
#include <utils/gui/div/GUIParameterTableWindow.h>
25
#include <utils/gui/globjects/GUIGLObjectPopupMenu.h>
26
27
#include "GNEInternalLane.h"
28
29
// ===========================================================================
30
// FOX callback mapping
31
// ===========================================================================
32
33
FXIMPLEMENT(GNEInternalLane, FXDelegator, 0, 0)
34
35
// ===========================================================================
36
// static member definitions
37
// ===========================================================================
38
39
StringBijection<FXuint>::Entry GNEInternalLane::linkStateNamesValues[] = {
40
{ "Green-Major", LINKSTATE_TL_GREEN_MAJOR },
41
{ "Green-Minor", LINKSTATE_TL_GREEN_MINOR },
42
//{ "Yellow-Major", LINKSTATE_TL_YELLOW_MAJOR }, (should not be used)
43
{ "Yellow", LINKSTATE_TL_YELLOW_MINOR },
44
{ "Red", LINKSTATE_TL_RED },
45
{ "Red-Yellow", LINKSTATE_TL_REDYELLOW },
46
{ "Stop", LINKSTATE_STOP },
47
{ "Off", LINKSTATE_TL_OFF_NOSIGNAL },
48
{ "Off-Blinking", LINKSTATE_TL_OFF_BLINKING },
49
};
50
51
const StringBijection<FXuint> GNEInternalLane::LinkStateNames(
52
GNEInternalLane::linkStateNamesValues, LINKSTATE_TL_OFF_BLINKING);
53
54
// ===========================================================================
55
// method definitions
56
// ===========================================================================
57
58
GNEInternalLane::GNEInternalLane(GNETLSEditorFrame* editor, GNEJunction* junctionParent,
59
const std::string& id, const PositionVector& shape, int tlIndex, LinkState state) :
60
GNENetworkElement(junctionParent->getNet(), id, GNE_TAG_INTERNAL_LANE),
61
myJunctionParent(junctionParent),
62
myState(state),
63
myStateTarget(myState),
64
myEditor(editor),
65
myTlIndex(tlIndex),
66
myPopup(nullptr) {
67
// calculate internal lane geometry
68
myInternalLaneGeometry.updateGeometry(shape);
69
// update centering boundary without updating grid
70
updateCenteringBoundary(false);
71
// vinculate this internal lane with their junction parent
72
myJunctionParent->addInternalLane(this);
73
}
74
75
76
GNEInternalLane::GNEInternalLane() :
77
GNENetworkElement(nullptr, "dummyInternalLane", GNE_TAG_INTERNAL_LANE),
78
myJunctionParent(nullptr),
79
myState(0),
80
myEditor(0),
81
myTlIndex(0),
82
myPopup(nullptr) {
83
}
84
85
86
GNEInternalLane::~GNEInternalLane() {
87
// remove this internal lane from junction parent
88
myJunctionParent->removeInternalLane(this);
89
}
90
91
92
GNEMoveElement*
93
GNEInternalLane::getMoveElement() const {
94
return nullptr;
95
}
96
97
98
Parameterised*
99
GNEInternalLane::getParameters() {
100
return nullptr;
101
}
102
103
104
const Parameterised*
105
GNEInternalLane::getParameters() const {
106
return nullptr;
107
}
108
109
110
void
111
GNEInternalLane::updateGeometry() {
112
// nothing to update
113
}
114
115
116
Position
117
GNEInternalLane::getPositionInView() const {
118
return myJunctionParent->getPositionInView();
119
}
120
121
122
bool
123
GNEInternalLane::checkDrawFromContour() const {
124
return false;
125
}
126
127
128
bool
129
GNEInternalLane::checkDrawToContour() const {
130
return false;
131
}
132
133
134
bool
135
GNEInternalLane::checkDrawRelatedContour() const {
136
// check opened popup
137
if (myNet->getViewNet()->getPopup()) {
138
return myNet->getViewNet()->getPopup()->getGLObject() == this;
139
}
140
return false;
141
}
142
143
144
bool
145
GNEInternalLane::checkDrawOverContour() const {
146
return myNet->getViewNet()->getViewObjectsSelector().getGUIGlObjectFront() == this;
147
}
148
149
150
bool
151
GNEInternalLane::checkDrawDeleteContour() const {
152
return false;
153
}
154
155
156
bool
157
GNEInternalLane::checkDrawDeleteContourSmall() const {
158
return false;
159
}
160
161
162
bool
163
GNEInternalLane::checkDrawSelectContour() const {
164
return false;
165
}
166
167
168
bool
169
GNEInternalLane::checkDrawMoveContour() const {
170
return false;
171
}
172
173
174
long
175
GNEInternalLane::onDefault(FXObject* obj, FXSelector sel, void* data) {
176
if (myEditor != nullptr) {
177
FXuint before = myState;
178
myStateTarget.handle(obj, sel, data);
179
if (myState != before) {
180
myEditor->handleChange(this);
181
}
182
// let GUISUMOAbstractView know about clicks so that the popup is properly destroyed
183
if (FXSELTYPE(sel) == SEL_COMMAND) {
184
if (myPopup != nullptr) {
185
myPopup->getParentView()->destroyPopup();
186
myPopup = nullptr;
187
}
188
}
189
}
190
return 1;
191
}
192
193
194
void
195
GNEInternalLane::drawGL(const GUIVisualizationSettings& s) const {
196
// only draw if we're not selecting E1 detectors in TLS Mode
197
if (!myNet->getViewNet()->selectingDetectorsTLSMode()) {
198
// get detail level
199
const auto d = s.getDetailLevel(1);
200
// draw geometry only if we'rent in drawForObjectUnderCursor mode
201
if (!s.drawForViewObjectsHandler) {
202
// get link state color
203
const auto linkStateColor = colorForLinksState(myState);
204
// push layer matrix
205
GLHelper::pushMatrix();
206
// translate to front
207
myJunctionParent->drawInLayer(GLO_TLLOGIC);
208
// move front again
209
glTranslated(0, 0, 0.5);
210
// set color
211
GLHelper::setColor(linkStateColor);
212
// draw geometry
213
GUIGeometry::drawGeometry(d, myInternalLaneGeometry,
214
s.connectionSettings.connectionWidth);
215
// pop layer matrix
216
GLHelper::popMatrix();
217
// draw dotted contour
218
myNetworkElementContour.drawDottedContours(s, d, this, s.dottedContourSettings.segmentWidth, true);
219
}
220
// calculate contour
221
myNetworkElementContour.calculateContourExtrudedShape(s, d, this, myInternalLaneGeometry.getShape(), getType(),
222
s.connectionSettings.connectionWidth, 1, true, true, 0, nullptr, myJunctionParent);
223
}
224
}
225
226
227
void
228
GNEInternalLane::deleteGLObject() {
229
// Internal lanes cannot be removed
230
}
231
232
233
void
234
GNEInternalLane::updateGLObject() {
235
updateGeometry();
236
}
237
238
239
void
240
GNEInternalLane::setLinkState(LinkState state) {
241
myState = state;
242
myOrigState = state;
243
}
244
245
246
LinkState
247
GNEInternalLane::getLinkState() const {
248
return (LinkState)myState;
249
}
250
251
252
int
253
GNEInternalLane::getTLIndex() const {
254
return myTlIndex;
255
}
256
257
258
GUIGLObjectPopupMenu*
259
GNEInternalLane::getPopUpMenu(GUIMainWindow& app, GUISUMOAbstractView& parent) {
260
myPopup = new GUIGLObjectPopupMenu(app, parent, this);
261
buildPopupHeader(myPopup, app);
262
if ((myEditor != nullptr) && (myEditor->getViewNet()->getEditModes().isCurrentSupermodeNetwork())) {
263
const std::vector<std::string> names = LinkStateNames.getStrings();
264
for (std::vector<std::string>::const_iterator it = names.begin(); it != names.end(); it++) {
265
FXuint state = LinkStateNames.get(*it);
266
std::string origHint = ((LinkState)state == myOrigState ? " (original)" : "");
267
FXMenuRadio* mc = new FXMenuRadio(myPopup, (*it + origHint).c_str(), this, FXDataTarget::ID_OPTION + state);
268
mc->setSelBackColor(MFXUtils::getFXColor(colorForLinksState(state)));
269
mc->setBackColor(MFXUtils::getFXColor(colorForLinksState(state)));
270
}
271
}
272
return myPopup;
273
}
274
275
276
GUIParameterTableWindow*
277
GNEInternalLane::getParameterWindow(GUIMainWindow& app, GUISUMOAbstractView&) {
278
// internal lanes don't have attributes
279
GUIParameterTableWindow* ret = new GUIParameterTableWindow(app, *this);
280
// close building
281
ret->closeBuilding();
282
return ret;
283
}
284
285
286
Boundary
287
GNEInternalLane::getCenteringBoundary() const {
288
return myNetworkElementContour.getContourBoundary();
289
}
290
291
292
void
293
GNEInternalLane::updateCenteringBoundary(const bool /*updateGrid*/) {
294
// nothing to update
295
}
296
297
298
RGBColor
299
GNEInternalLane::colorForLinksState(FXuint state) {
300
try {
301
return GUIVisualizationSettings::getLinkColor((LinkState)state);
302
} catch (ProcessError&) {
303
WRITE_WARNINGF(TL("invalid link state='%'"), toString(state));
304
return RGBColor::BLACK;
305
}
306
}
307
308
309
std::string
310
GNEInternalLane::getAttribute(SumoXMLAttr key) const {
311
return getCommonAttribute(key);
312
}
313
314
315
double
316
GNEInternalLane::getAttributeDouble(SumoXMLAttr key) const {
317
return getCommonAttributeDouble(key);
318
}
319
320
321
Position
322
GNEInternalLane::getAttributePosition(SumoXMLAttr key) const {
323
return getCommonAttributePosition(key);
324
}
325
326
327
PositionVector
328
GNEInternalLane::getAttributePositionVector(SumoXMLAttr key) const {
329
return getCommonAttributePositionVector(key);
330
}
331
332
333
void
334
GNEInternalLane::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
335
setCommonAttribute(key, value, undoList);
336
}
337
338
339
bool
340
GNEInternalLane::isValid(SumoXMLAttr key, const std::string& value) {
341
return isCommonAttributeValid(key, value);
342
}
343
344
345
void
346
GNEInternalLane::setAttribute(SumoXMLAttr key, const std::string& value) {
347
setCommonAttribute(key, value);
348
}
349
350
/****************************************************************************/
351
352