Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
eclipse
GitHub Repository: eclipse/sumo
Path: blob/main/src/netedit/elements/additional/GNEEntryExitDetector.cpp
193871 views
1
/****************************************************************************/
2
// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3
// Copyright (C) 2001-2026 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 GNEEntryExitDetector.cpp
15
/// @author Pablo Alvarez Lopez
16
/// @date Nov 2015
17
///
18
//
19
/****************************************************************************/
20
#include <config.h>
21
22
#include <netedit/changes/GNEChange_Attribute.h>
23
#include <netedit/elements/moving/GNEMoveElementLaneSingle.h>
24
#include <netedit/GNENet.h>
25
#include <netedit/GNETagProperties.h>
26
#include <utils/gui/div/GLHelper.h>
27
28
#include "GNEEntryExitDetector.h"
29
30
// ===========================================================================
31
// member method definitions
32
// ===========================================================================
33
34
GNEEntryExitDetector::GNEEntryExitDetector(SumoXMLTag entryExitTag, GNENet* net) :
35
GNEDetector(net, entryExitTag),
36
myMoveElementLaneSingle(new GNEMoveElementLaneSingle(this, SUMO_ATTR_POSITION, myPosOverLane, myFriendlyPos,
37
GNEMoveElementLaneSingle::PositionType::SINGLE)) {
38
}
39
40
41
GNEEntryExitDetector::GNEEntryExitDetector(SumoXMLTag entryExitTag, GNEAdditional* parent, GNELane* lane, const double pos,
42
const bool friendlyPos, const Parameterised::Map& parameters) :
43
GNEDetector(parent, entryExitTag, 0, "", "", parameters),
44
myPosOverLane(pos),
45
myFriendlyPos(friendlyPos),
46
myMoveElementLaneSingle(new GNEMoveElementLaneSingle(this, SUMO_ATTR_POSITION, myPosOverLane, myFriendlyPos,
47
GNEMoveElementLaneSingle::PositionType::SINGLE)) {
48
// set parents
49
setParent<GNELane*>(lane);
50
// update centering boundary without updating grid
51
updateCenteringBoundary(false);
52
}
53
54
55
GNEEntryExitDetector::~GNEEntryExitDetector() {
56
delete myMoveElementLaneSingle;
57
}
58
59
60
GNEMoveElement*
61
GNEEntryExitDetector::getMoveElement() const {
62
return myMoveElementLaneSingle;
63
}
64
65
66
void
67
GNEEntryExitDetector::writeAdditional(OutputDevice& device) const {
68
device.openTag(getTagProperty()->getTag());
69
// write common additional attributes
70
writeAdditionalAttributes(device);
71
// write move attributes
72
myMoveElementLaneSingle->writeMoveAttributes(device);
73
// write common detector parameters
74
writeDetectorValues(device);
75
// write parameters
76
writeParams(device);
77
device.closeTag();
78
}
79
80
81
bool
82
GNEEntryExitDetector::isAdditionalValid() const {
83
// only movement problems
84
return myMoveElementLaneSingle->isMoveElementValid();
85
}
86
87
88
std::string
89
GNEEntryExitDetector::getAdditionalProblem() const {
90
// only movement problems
91
return myMoveElementLaneSingle->getMovingProblem();
92
}
93
94
95
void
96
GNEEntryExitDetector::fixAdditionalProblem() {
97
// only movement problems
98
myMoveElementLaneSingle->fixMovingProblem();
99
}
100
101
102
void
103
GNEEntryExitDetector::updateGeometry() {
104
// update geometry
105
myAdditionalGeometry.updateGeometry(getParentLanes().front()->getLaneShape(), myMoveElementLaneSingle->getFixedPositionOverLane(true), myMoveElementLaneSingle->myMovingLateralOffset);
106
// update centering boundary without updating grid
107
updateCenteringBoundary(false);
108
}
109
110
111
void
112
GNEEntryExitDetector::drawGL(const GUIVisualizationSettings& s) const {
113
// first check if additional has to be drawn
114
if (myNet->getViewNet()->getDataViewOptions().showAdditionals() &&
115
!myNet->getViewNet()->selectingDetectorsTLSMode()) {
116
// Set initial values
117
const double entryExitExaggeration = getExaggeration(s);
118
// get detail level
119
const auto d = s.getDetailLevel(entryExitExaggeration);
120
// draw geometry only if we'rent in drawForObjectUnderCursor mode
121
if (s.checkDrawAdditional(d, isAttributeCarrierSelected())) {
122
// draw parent and child lines
123
drawParentChildLines(s, s.additionalSettings.connectionColor);
124
// Push layer matrix
125
GLHelper::pushMatrix();
126
// translate to front
127
drawInLayer(GLO_DET_ENTRY);
128
// Set color
129
RGBColor color;
130
if (drawUsingSelectColor()) {
131
color = s.colorSettings.selectedAdditionalColor;
132
} else if (myTagProperty->getTag() == SUMO_TAG_DET_ENTRY) {
133
color = s.detectorSettings.E3EntryColor;
134
} else if (myTagProperty->getTag() == SUMO_TAG_DET_EXIT) {
135
color = s.detectorSettings.E3ExitColor;
136
}
137
// draw parts
138
drawBody(d, color, entryExitExaggeration);
139
drawEntryLogo(d, color, entryExitExaggeration);
140
drawE3Logo(d, color, entryExitExaggeration);
141
// pop layer matrix
142
GLHelper::popMatrix();
143
// draw additional name
144
drawAdditionalName(s);
145
// draw lock icon
146
GNEViewNetHelper::LockIcon::drawLockIcon(d, this, getType(), myAdditionalGeometry.getShape().getCentroid(),
147
entryExitExaggeration);
148
// draw dotted contour
149
myAdditionalContour.drawDottedContours(s, d, this, s.dottedContourSettings.segmentWidth, true);
150
}
151
// calculate contour
152
myAdditionalContour.calculateContourRectangleShape(s, d, this, myAdditionalGeometry.getShape().front(), 2.7, 1.6,
153
getType(), 2, 0, myAdditionalGeometry.getShapeRotations().front(), entryExitExaggeration,
154
getParentLanes().front()->getParentEdge());
155
}
156
}
157
158
159
std::string
160
GNEEntryExitDetector::getAttribute(SumoXMLAttr key) const {
161
switch (key) {
162
case GNE_ATTR_PARENT:
163
return getParentAdditionals().at(0)->getID();
164
default:
165
return getDetectorAttribute(key);
166
}
167
}
168
169
170
double
171
GNEEntryExitDetector::getAttributeDouble(SumoXMLAttr key) const {
172
return getDetectorAttributeDouble(key);
173
}
174
175
176
Position
177
GNEEntryExitDetector::getAttributePosition(SumoXMLAttr key) const {
178
return getDetectorAttributePosition(key);
179
}
180
181
182
void
183
GNEEntryExitDetector::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
184
switch (key) {
185
case GNE_ATTR_PARENT:
186
GNEChange_Attribute::changeAttribute(this, key, value, undoList);
187
break;
188
default:
189
setDetectorAttribute(key, value, undoList);
190
break;
191
}
192
}
193
194
195
bool
196
GNEEntryExitDetector::isValid(SumoXMLAttr key, const std::string& value) {
197
switch (key) {
198
case GNE_ATTR_PARENT:
199
return (myNet->getAttributeCarriers()->retrieveAdditional(SUMO_TAG_ENTRY_EXIT_DETECTOR, value, false) != nullptr);
200
default:
201
return isDetectorValid(key, value);
202
}
203
}
204
205
206
void
207
GNEEntryExitDetector::drawBody(const GUIVisualizationSettings::Detail d,
208
const RGBColor& color, const double exaggeration) const {
209
// check detail level
210
if (d <= GUIVisualizationSettings::Detail::Additionals) {
211
// Push polygon matrix
212
GLHelper::pushMatrix();
213
// set color
214
GLHelper::setColor(color);
215
// set polygon mode
216
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
217
// move to position
218
glTranslated(myAdditionalGeometry.getShape().front().x(), myAdditionalGeometry.getShape().front().y(), 0);
219
// rotate over lane
220
GUIGeometry::rotateOverLane(myAdditionalGeometry.getShapeRotations().front() + 90);
221
// scale
222
glScaled(exaggeration, exaggeration, 1);
223
// check detail level
224
if (d <= GUIVisualizationSettings::Detail::AdditionalDetails) {
225
// Draw polygon
226
glBegin(GL_LINES);
227
glVertex2d(1.7, 0);
228
glVertex2d(-1.7, 0);
229
glEnd();
230
glBegin(GL_QUADS);
231
glVertex2d(-1.7, .5);
232
glVertex2d(-1.7, -.5);
233
glVertex2d(1.7, -.5);
234
glVertex2d(1.7, .5);
235
glEnd();
236
// first Arrow
237
glTranslated(1.5, 0, 0);
238
GLHelper::drawBoxLine(Position(0, 4), 0, 2, .05);
239
GLHelper::drawTriangleAtEnd(Position(0, 4), Position(0, 1), (double) 1, (double) .25);
240
// second Arrow
241
glTranslated(-3, 0, 0);
242
GLHelper::drawBoxLine(Position(0, 4), 0, 2, .05);
243
GLHelper::drawTriangleAtEnd(Position(0, 4), Position(0, 1), (double) 1, (double) .25);
244
} else {
245
// Draw square in drawy for selecting mode
246
glBegin(GL_QUADS);
247
glVertex2d(-1.7, 4.3);
248
glVertex2d(-1.7, -.5);
249
glVertex2d(1.7, -.5);
250
glVertex2d(1.7, 4.3);
251
glEnd();
252
}
253
// Pop polygon matrix
254
GLHelper::popMatrix();
255
}
256
}
257
258
259
void
260
GNEEntryExitDetector::drawEntryLogo(const GUIVisualizationSettings::Detail d,
261
const RGBColor& color, const double exaggeration) const {
262
// check detail level
263
if (d <= GUIVisualizationSettings::Detail::AdditionalDetails) {
264
// Push matrix
265
GLHelper::pushMatrix();
266
// set color
267
GLHelper::setColor(color);
268
// Traslate to center of detector
269
glTranslated(myAdditionalGeometry.getShape().front().x(), myAdditionalGeometry.getShape().front().y(), getType() + 0.1);
270
// rotate over lane
271
GUIGeometry::rotateOverLane(myAdditionalGeometry.getShapeRotations().front());
272
//move to logo position
273
glTranslated(1.9, 0, 0);
274
// scale
275
glScaled(exaggeration, exaggeration, 1);
276
//move to logo position
277
glTranslated(1.7, 0, 0);
278
// rotate 90 degrees lane
279
glRotated(90, 0, 0, 1);
280
// draw Entry or Exit text if isn't being drawn for selecting
281
if (d <= GUIVisualizationSettings::Detail::Text) {
282
if (myTagProperty->getTag() == SUMO_TAG_DET_ENTRY) {
283
GLHelper::drawText("Entry", Position(), .1, 1, color, 180);
284
} else if (myTagProperty->getTag() == SUMO_TAG_DET_EXIT) {
285
GLHelper::drawText("Exit", Position(), .1, 1, color, 180);
286
}
287
} else {
288
GLHelper::drawBoxLine(Position(0, 1), 0, 2, 1);
289
}
290
// pop matrix
291
GLHelper::popMatrix();
292
}
293
}
294
295
296
void
297
GNEEntryExitDetector::drawE3Logo(const GUIVisualizationSettings::Detail d,
298
const RGBColor& color, const double exaggeration) const {
299
// check detail level
300
if (d <= GUIVisualizationSettings::Detail::Text) {
301
// Push matrix
302
GLHelper::pushMatrix();
303
// set color
304
GLHelper::setColor(color);
305
// Traslate to center of detector
306
glTranslated(myAdditionalGeometry.getShape().front().x(), myAdditionalGeometry.getShape().front().y(), getType() + 0.1);
307
// rotate over lane
308
GUIGeometry::rotateOverLane(myAdditionalGeometry.getShapeRotations().front());
309
//move to logo position
310
glTranslated(1.9, 0, 0);
311
// scale
312
glScaled(exaggeration, exaggeration, 1);
313
// draw E3 logo
314
GLHelper::drawText("E3", Position(0, 0), .1, 2.8, color);
315
// pop matrix
316
GLHelper::popMatrix();
317
}
318
}
319
320
321
void
322
GNEEntryExitDetector::setAttribute(SumoXMLAttr key, const std::string& value) {
323
switch (key) {
324
case SUMO_ATTR_LANE:
325
// set hier because GNEHierarchicalElement is a template
326
replaceAdditionalParentLanes(value);
327
break;
328
case GNE_ATTR_PARENT:
329
replaceAdditionalParent(SUMO_TAG_ENTRY_EXIT_DETECTOR, value, 0);
330
break;
331
default:
332
setDetectorAttribute(key, value);
333
break;
334
}
335
}
336
337
/****************************************************************************/
338
339