Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
eclipse
GitHub Repository: eclipse/sumo
Path: blob/main/src/netedit/elements/additional/GNEInstantInductionLoopDetector.cpp
169684 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 GNEInstantInductionLoopDetector.cpp
15
/// @author Pablo Alvarez Lopez
16
/// @date Jun 2018
17
///
18
//
19
/****************************************************************************/
20
#include <config.h>
21
22
#include <netedit/GNENet.h>
23
#include <netedit/GNETagProperties.h>
24
#include <netedit/GNEUndoList.h>
25
#include <netedit/GNEViewNet.h>
26
#include <netedit/GNEViewParent.h>
27
#include <netedit/changes/GNEChange_Attribute.h>
28
#include <netedit/frames/network/GNETLSEditorFrame.h>
29
#include <utils/gui/div/GLHelper.h>
30
#include <utils/gui/div/GUIGlobalViewObjectsHandler.h>
31
32
#include "GNEInstantInductionLoopDetector.h"
33
#include "GNEAdditionalHandler.h"
34
35
// ===========================================================================
36
// member method definitions
37
// ===========================================================================
38
39
GNEInstantInductionLoopDetector::GNEInstantInductionLoopDetector(GNENet* net) :
40
GNEDetector(net, SUMO_TAG_INSTANT_INDUCTION_LOOP) {
41
}
42
43
44
GNEInstantInductionLoopDetector::GNEInstantInductionLoopDetector(const std::string& id, GNENet* net, const std::string& filename, GNELane* lane,
45
const double pos, const std::string& outputFilename, const std::vector<std::string>& vehicleTypes, const std::vector<std::string>& nextEdges,
46
const std::string& detectPersons, const std::string& name, const bool friendlyPos, const Parameterised::Map& parameters) :
47
GNEDetector(id, net, filename, SUMO_TAG_INSTANT_INDUCTION_LOOP, pos, 0, lane, outputFilename,
48
vehicleTypes, nextEdges, detectPersons, name, friendlyPos, parameters) {
49
// update centering boundary without updating grid
50
updateCenteringBoundary(false);
51
}
52
53
54
GNEInstantInductionLoopDetector::~GNEInstantInductionLoopDetector() {
55
}
56
57
58
void
59
GNEInstantInductionLoopDetector::writeAdditional(OutputDevice& device) const {
60
device.openTag(getTagProperty()->getTag());
61
device.writeAttr(SUMO_ATTR_ID, getID());
62
device.writeAttr(SUMO_ATTR_LANE, getParentLanes().front()->getID());
63
device.writeAttr(SUMO_ATTR_POSITION, myPositionOverLane);
64
// write common detector parameters
65
writeDetectorValues(device);
66
// write parameters (Always after children to avoid problems with additionals.xsd)
67
writeParams(device);
68
device.closeTag();
69
}
70
71
72
bool
73
GNEInstantInductionLoopDetector::isAdditionalValid() const {
74
// with friendly position enabled position are "always fixed"
75
if (myFriendlyPosition) {
76
return true;
77
} else {
78
return fabs(myPositionOverLane) <= getParentLanes().front()->getParentEdge()->getNBEdge()->getFinalLength();
79
}
80
}
81
82
83
std::string
84
GNEInstantInductionLoopDetector::getAdditionalProblem() const {
85
// obtain final length
86
const double len = getParentLanes().front()->getParentEdge()->getNBEdge()->getFinalLength();
87
// check if detector has a problem
88
if (GNEAdditionalHandler::checkLanePosition(myPositionOverLane, 0, len, myFriendlyPosition)) {
89
return "";
90
} else {
91
// declare variable for error position
92
std::string errorPosition;
93
// check positions over lane
94
if (myPositionOverLane < 0) {
95
errorPosition = (toString(SUMO_ATTR_POSITION) + " < 0");
96
}
97
if (myPositionOverLane > len) {
98
errorPosition = (toString(SUMO_ATTR_POSITION) + TL(" > lanes's length"));
99
}
100
return errorPosition;
101
}
102
}
103
104
105
void
106
GNEInstantInductionLoopDetector::fixAdditionalProblem() {
107
// declare new position
108
double newPositionOverLane = myPositionOverLane;
109
// fix pos and length checkAndFixDetectorPosition
110
double length = 0;
111
GNEAdditionalHandler::fixLanePosition(newPositionOverLane, length, getParentLanes().front()->getParentEdge()->getNBEdge()->getFinalLength());
112
// set new position
113
setAttribute(SUMO_ATTR_POSITION, toString(newPositionOverLane), myNet->getViewNet()->getUndoList());
114
}
115
116
117
void
118
GNEInstantInductionLoopDetector::updateGeometry() {
119
// update geometry
120
myAdditionalGeometry.updateGeometry(getParentLanes().front()->getLaneShape(), getGeometryPositionOverLane(), myMoveElementLateralOffset);
121
// update centering boundary without updating grid
122
updateCenteringBoundary(false);
123
}
124
125
126
void
127
GNEInstantInductionLoopDetector::drawGL(const GUIVisualizationSettings& s) const {
128
// check if additional has to be drawn
129
if (myNet->getViewNet()->getDataViewOptions().showAdditionals() &&
130
!myNet->getViewNet()->selectingDetectorsTLSMode()) {
131
// Obtain exaggeration of the draw
132
const double E1InstantExaggeration = getExaggeration(s);
133
// get detail level
134
const auto d = s.getDetailLevel(E1InstantExaggeration);
135
// draw geometry only if we'rent in drawForObjectUnderCursor mode
136
if (s.checkDrawAdditional(d, isAttributeCarrierSelected())) {
137
// declare colors
138
RGBColor mainColor, secondColor, textColor;
139
// set color
140
if (drawUsingSelectColor()) {
141
mainColor = s.colorSettings.selectedAdditionalColor;
142
secondColor = mainColor.changedBrightness(-32);
143
textColor = mainColor.changedBrightness(32);
144
} else {
145
mainColor = s.detectorSettings.E1InstantColor;
146
secondColor = RGBColor::WHITE;
147
textColor = RGBColor::BLACK;
148
}
149
// draw parent and child lines
150
drawParentChildLines(s, s.additionalSettings.connectionColor);
151
// push layer matrix
152
GLHelper::pushMatrix();
153
// translate to front
154
drawInLayer(GLO_E1DETECTOR_INSTANT);
155
// draw E1Instant shape
156
drawE1Shape(d, E1InstantExaggeration, mainColor, secondColor);
157
// draw E1 Logo
158
drawE1DetectorLogo(s, d, E1InstantExaggeration, "E1", textColor);
159
// pop layer matrix
160
GLHelper::popMatrix();
161
// draw lock icon
162
GNEViewNetHelper::LockIcon::drawLockIcon(d, this, getType(), myAdditionalGeometry.getShape().getCentroid(),
163
E1InstantExaggeration);
164
// Draw additional ID
165
drawAdditionalID(s);
166
// draw additional name
167
drawAdditionalName(s);
168
// draw dotted contour
169
myAdditionalContour.drawDottedContours(s, d, this, s.dottedContourSettings.segmentWidth, true);
170
}
171
// draw dotted contour
172
myAdditionalContour.calculateContourRectangleShape(s, d, this, myAdditionalGeometry.getShape().front(), 2, 1, getType(), 0, 0,
173
myAdditionalGeometry.getShapeRotations().front(), E1InstantExaggeration, getParentLanes().front()->getParentEdge());
174
}
175
}
176
177
178
std::string
179
GNEInstantInductionLoopDetector::getAttribute(SumoXMLAttr key) const {
180
return getDetectorAttribute(key);
181
}
182
183
184
double
185
GNEInstantInductionLoopDetector::getAttributeDouble(SumoXMLAttr key) const {
186
return getDetectorAttributeDouble(key);
187
}
188
189
190
void
191
GNEInstantInductionLoopDetector::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
192
setDetectorAttribute(key, value, undoList);
193
}
194
195
196
bool
197
GNEInstantInductionLoopDetector::isValid(SumoXMLAttr key, const std::string& value) {
198
return isDetectorValid(key, value);
199
}
200
201
// ===========================================================================
202
// private
203
// ===========================================================================
204
205
void
206
GNEInstantInductionLoopDetector::setAttribute(SumoXMLAttr key, const std::string& value) {
207
setDetectorAttribute(key, value);
208
}
209
210
211
void
212
GNEInstantInductionLoopDetector::setMoveShape(const GNEMoveResult& moveResult) {
213
// change position
214
myPositionOverLane = moveResult.newFirstPos;
215
// set lateral offset
216
myMoveElementLateralOffset = moveResult.firstLaneOffset;
217
// update geometry
218
updateGeometry();
219
}
220
221
222
void
223
GNEInstantInductionLoopDetector::commitMoveShape(const GNEMoveResult& moveResult, GNEUndoList* undoList) {
224
// reset lateral offset
225
myMoveElementLateralOffset = 0;
226
// begin change attribute
227
undoList->begin(this, "position of " + getTagStr());
228
// set startPosition
229
setAttribute(SUMO_ATTR_POSITION, toString(moveResult.newFirstPos), undoList);
230
// check if lane has to be changed
231
if (moveResult.newFirstLane) {
232
// set new lane
233
setAttribute(SUMO_ATTR_LANE, moveResult.newFirstLane->getID(), undoList);
234
}
235
// end change attribute
236
undoList->end();
237
}
238
239
/****************************************************************************/
240
241