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