Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
eclipse
GitHub Repository: eclipse/sumo
Path: blob/main/src/netedit/elements/additional/GNEInductionLoopDetector.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 GNEInductionLoopDetector.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/frames/network/GNETLSEditorFrame.h>
25
#include <netedit/GNENet.h>
26
#include <netedit/GNETagProperties.h>
27
#include <netedit/GNEViewParent.h>
28
#include <utils/gui/div/GLHelper.h>
29
#include <utils/gui/globjects/GUIGLObjectPopupMenu.h>
30
31
#include "GNEInductionLoopDetector.h"
32
33
// ===========================================================================
34
// member method definitions
35
// ===========================================================================
36
37
GNEInductionLoopDetector::GNEInductionLoopDetector(GNENet* net) :
38
GNEDetector(net, SUMO_TAG_INDUCTION_LOOP),
39
myMoveElementLaneSingle(new GNEMoveElementLaneSingle(this, SUMO_ATTR_POSITION, myPosOverLane, myFriendlyPos,
40
GNEMoveElementLaneSingle::PositionType::SINGLE)) {
41
}
42
43
44
GNEInductionLoopDetector::GNEInductionLoopDetector(const std::string& id, GNENet* net, FileBucket* fileBucket, GNELane* lane,
45
const double pos, const SUMOTime freq, const std::string& outputFilename, const std::vector<std::string>& vehicleTypes,
46
const std::vector<std::string>& nextEdges, const std::string& detectPersons, const std::string& name, const bool friendlyPos,
47
const Parameterised::Map& parameters) :
48
GNEDetector(id, net, fileBucket, SUMO_TAG_INDUCTION_LOOP, freq, outputFilename, vehicleTypes, nextEdges,
49
detectPersons, name, parameters),
50
myPosOverLane(pos),
51
myFriendlyPos(friendlyPos),
52
myMoveElementLaneSingle(new GNEMoveElementLaneSingle(this, SUMO_ATTR_POSITION, myPosOverLane, myFriendlyPos,
53
GNEMoveElementLaneSingle::PositionType::SINGLE)) {
54
// set parents
55
setParent<GNELane*>(lane);
56
// update centering boundary without updating grid
57
updateCenteringBoundary(false);
58
}
59
60
61
GNEInductionLoopDetector::~GNEInductionLoopDetector() {
62
delete myMoveElementLaneSingle;
63
}
64
65
66
GNEMoveElement*
67
GNEInductionLoopDetector::getMoveElement() const {
68
return myMoveElementLaneSingle;
69
}
70
71
72
Parameterised*
73
GNEInductionLoopDetector::getParameters() {
74
return this;
75
}
76
77
78
void
79
GNEInductionLoopDetector::writeAdditional(OutputDevice& device) const {
80
device.openTag(getTagProperty()->getTag());
81
// write common additional attributes
82
writeAdditionalAttributes(device);
83
// write move attributes
84
myMoveElementLaneSingle->writeMoveAttributes(device);
85
// write detector attributes
86
writeDetectorValues(device);
87
// write parameters (Always after children to avoid problems with additionals.xsd)
88
writeParams(device);
89
device.closeTag();
90
}
91
92
93
bool
94
GNEInductionLoopDetector::isAdditionalValid() const {
95
// only movement problems
96
return myMoveElementLaneSingle->isMoveElementValid();
97
}
98
99
100
std::string
101
GNEInductionLoopDetector::getAdditionalProblem() const {
102
// only movement problems
103
return myMoveElementLaneSingle->getMovingProblem();
104
}
105
106
107
void
108
GNEInductionLoopDetector::fixAdditionalProblem() {
109
// only movement problems
110
myMoveElementLaneSingle->fixMovingProblem();
111
}
112
113
114
void
115
GNEInductionLoopDetector::updateGeometry() {
116
// update geometry
117
myAdditionalGeometry.updateGeometry(getParentLanes().front()->getLaneShape(), myMoveElementLaneSingle->getFixedPositionOverLane(true), myMoveElementLaneSingle->myMovingLateralOffset);
118
// update centering boundary without updating grid
119
updateCenteringBoundary(false);
120
}
121
122
123
bool
124
GNEInductionLoopDetector::checkDrawRelatedContour() const {
125
// get TLS Attributes
126
const auto& TLSAttributes = myNet->getViewParent()->getTLSEditorFrame()->getTLSAttributes();
127
// check detectors
128
if (myNet->getViewNet()->selectingDetectorsTLSMode() &&
129
(TLSAttributes->getE1Detectors().count(getParentLanes().front()->getID()) > 0) &&
130
(TLSAttributes->getE1Detectors().at(getParentLanes().front()->getID()) == getID())) {
131
return true;
132
}
133
// check opened popup
134
if (myNet->getViewNet()->getPopup()) {
135
return myNet->getViewNet()->getPopup()->getGLObject() == this;
136
}
137
return false;
138
}
139
140
141
void
142
GNEInductionLoopDetector::drawGL(const GUIVisualizationSettings& s) const {
143
// first check if additional has to be drawn
144
if (myNet->getViewNet()->getDataViewOptions().showAdditionals()) {
145
// Obtain exaggeration of the draw
146
const double E1Exaggeration = getExaggeration(s);
147
// get detail level
148
const auto d = s.getDetailLevel(E1Exaggeration);
149
// draw geometry only if we'rent in drawForObjectUnderCursor mode
150
if (s.checkDrawAdditional(d, isAttributeCarrierSelected())) {
151
// declare colors
152
RGBColor mainColor, secondColor, textColor;
153
// set color
154
if (drawUsingSelectColor()) {
155
mainColor = s.colorSettings.selectedAdditionalColor;
156
secondColor = mainColor.changedBrightness(-32);
157
textColor = mainColor.changedBrightness(32);
158
} else {
159
mainColor = s.detectorSettings.E1Color;
160
secondColor = RGBColor::WHITE;
161
textColor = RGBColor::BLACK;
162
}
163
// draw parent and child lines
164
drawParentChildLines(s, s.additionalSettings.connectionColor);
165
// push layer matrix
166
GLHelper::pushMatrix();
167
// translate to front
168
drawInLayer(GLO_E1DETECTOR);
169
// draw E1 shape
170
drawE1Shape(d, E1Exaggeration, mainColor, secondColor);
171
// draw E1 Logo
172
drawE1DetectorLogo(s, d, E1Exaggeration, "E1", textColor);
173
// pop layer matrix
174
GLHelper::popMatrix();
175
// draw lock icon
176
GNEViewNetHelper::LockIcon::drawLockIcon(d, this, getType(), myAdditionalGeometry.getShape().getCentroid(), E1Exaggeration);
177
// Draw additional ID
178
drawAdditionalID(s);
179
// draw additional name
180
drawAdditionalName(s);
181
// draw dotted contour
182
myAdditionalContour.drawDottedContours(s, d, this, s.dottedContourSettings.segmentWidth, true);
183
}
184
// calculate contour rectangle
185
myAdditionalContour.calculateContourRectangleShape(s, d, this, myAdditionalGeometry.getShape().front(), 2, 1, getType(), 0, 0,
186
myAdditionalGeometry.getShapeRotations().front(), E1Exaggeration, getParentLanes().front()->getParentEdge());
187
}
188
}
189
190
191
std::string
192
GNEInductionLoopDetector::getAttribute(SumoXMLAttr key) const {
193
return getDetectorAttribute(key);
194
}
195
196
197
double
198
GNEInductionLoopDetector::getAttributeDouble(SumoXMLAttr key) const {
199
return getDetectorAttributeDouble(key);
200
}
201
202
203
Position
204
GNEInductionLoopDetector::getAttributePosition(SumoXMLAttr key) const {
205
return getDetectorAttributePosition(key);
206
}
207
208
209
void
210
GNEInductionLoopDetector::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
211
setDetectorAttribute(key, value, undoList);
212
}
213
214
215
bool
216
GNEInductionLoopDetector::isValid(SumoXMLAttr key, const std::string& value) {
217
return isDetectorValid(key, value);
218
}
219
220
// ===========================================================================
221
// private
222
// ===========================================================================
223
224
void
225
GNEInductionLoopDetector::setAttribute(SumoXMLAttr key, const std::string& value) {
226
switch (key) {
227
case SUMO_ATTR_LANE:
228
replaceAdditionalParentLanes(value);
229
break;
230
default:
231
setDetectorAttribute(key, value);
232
break;
233
}
234
}
235
236
/****************************************************************************/
237
238