Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
eclipse
GitHub Repository: eclipse/sumo
Path: blob/main/src/netedit/elements/additional/GNEDetector.h
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 GNEDetector.h
15
/// @author Pablo Alvarez Lopez
16
/// @date Nov 2015
17
///
18
// A abstract class to define common parameters of detectors placed over lanes
19
/****************************************************************************/
20
#pragma once
21
#include <config.h>
22
23
#include "GNEAdditional.h"
24
25
// ===========================================================================
26
// class definitions
27
// ===========================================================================
28
29
class GNEDetector : public GNEAdditional, public Parameterised {
30
31
public:
32
/**@brief Default constructor
33
* @param[in] net pointer to GNENet of this additional element belongs
34
* @param[in] tag Type of xml tag that define the detector (SUMO_TAG_INDUCTION_LOOP, SUMO_TAG_LANE_AREA_DETECTOR, etc...)
35
*/
36
GNEDetector(GNENet* net, SumoXMLTag tag);
37
38
/**@brief Constructor
39
* @param[in] id Gl-id of the detector (Must be unique)
40
* @param[in] net pointer to GNENet of this additional element belongs
41
* @param[in] filename file in which this AttributeCarrier is stored
42
* @param[in] tag Type of xml tag that define the detector (SUMO_TAG_INDUCTION_LOOP, SUMO_TAG_LANE_AREA_DETECTOR, etc...)
43
* @param[in] pos position of the detector on the lane
44
* @param[in] period the aggregation period the values the detector collects shall be summed up.
45
* @param[in] lane parent lane
46
* @param[in] vehicleTypes space separated list of vehicle type ids to consider
47
* @param[in] nextEdges list of edge ids that must all be part of the future route of the vehicle to qualify for detection
48
* @param[in] detectPersons detect persons instead of vehicles (pedestrians or passengers)
49
* @param[in] outputFilename The path to the output file.
50
* @param[in] name detector name
51
* @param[in] friendlyPos enable or disable friendly positions
52
* @param[in] parameters generic parameters
53
*/
54
GNEDetector(const std::string& id, GNENet* net, const std::string& filename, SumoXMLTag tag,
55
const double pos, const SUMOTime period, GNELane* lane, const std::string& outputFilename,
56
const std::vector<std::string>& vehicleTypes, const std::vector<std::string>& nextEdges,
57
const std::string& detectPersons, const std::string& name, const bool friendlyPos,
58
const Parameterised::Map& parameters);
59
60
/**@brief Constructor
61
* @param[in] id Gl-id of the detector (Must be unique)
62
* @param[in] net pointer to GNENet of this additional element belongs
63
* @param[in] filename file in which this AttributeCarrier is stored
64
* @param[in] tag Type of xml tag that define the detector (SUMO_TAG_INDUCTION_LOOP, SUMO_TAG_LANE_AREA_DETECTOR, etc...)
65
* @param[in] pos position of the detector on the lane
66
* @param[in] period the aggregation period the values the detector collects shall be summed up.
67
* @param[in] lanes vector of parent lanes
68
* @param[in] vehicleTypes space separated list of vehicle type ids to consider
69
* @param[in] nextEdges list of edge ids that must all be part of the future route of the vehicle to qualify for detection
70
* @param[in] detectPersons detect persons instead of vehicles (pedestrians or passengers)
71
* @param[in] outputFilename The path to the output file.
72
* @param[in] name detector name
73
* @param[in] friendlyPos enable or disable friendly positions
74
* @param[in] parameters generic parameters
75
*/
76
GNEDetector(const std::string& id, GNENet* net, const std::string& filename, SumoXMLTag tag, const double pos,
77
const SUMOTime period, const std::vector<GNELane*>& lanes, const std::string& outputFilename,
78
const std::vector<std::string>& vehicleTypes, const std::vector<std::string>& nextEdges,
79
const std::string& detectPersons, const std::string& name, const bool friendlyPos,
80
const Parameterised::Map& parameters);
81
82
/**@brief Constructor
83
* @param[in] additionalParent parent additional of this detector (ID will be generated automatically)
84
* @param[in] tag Type of xml tag that define the detector (SUMO_TAG_INDUCTION_LOOP, SUMO_TAG_LANE_AREA_DETECTOR, etc...)
85
* @param[in] pos position of the detector on the lane
86
* @param[in] period the aggregation period the values the detector collects shall be summed up.
87
* @param[in] parentLanes vector of parent lanes
88
* @param[in] outputFilename The path to the output file.
89
* @param[in] name detector name
90
* @param[in] friendlyPos enable or disable friendly positions
91
* @param[in] parameters generic parameters
92
*/
93
GNEDetector(GNEAdditional* additionalParent, SumoXMLTag tag, const double pos, const SUMOTime period, GNELane* lane,
94
const std::string& outputFilename, const std::string& name, const bool friendlyPos, const Parameterised::Map& parameters);
95
96
/// @brief Destructor
97
~GNEDetector();
98
99
/**@brief get move operation
100
* @note returned GNEMoveOperation can be nullptr
101
*/
102
GNEMoveOperation* getMoveOperation();
103
104
/// @name members and functions relative to write additionals into XML
105
/// @{
106
107
/**@brief write additional element into a xml file
108
* @param[in] device device in which write parameters of additional element
109
*/
110
virtual void writeAdditional(OutputDevice& device) const = 0;
111
112
/// @brief check if current additional is valid to be written into XML (must be reimplemented in all detector children)
113
virtual bool isAdditionalValid() const = 0;
114
115
/// @brief return a string with the current additional problem (must be reimplemented in all detector children)
116
virtual std::string getAdditionalProblem() const = 0;
117
118
/// @brief fix additional problem (must be reimplemented in all detector children)
119
virtual void fixAdditionalProblem() = 0;
120
121
/// @}
122
123
/// @name Function related with contour drawing
124
/// @{
125
126
/// @brief check if draw move contour (red)
127
bool checkDrawMoveContour() const;
128
129
/// @}
130
131
/// @brief get lane
132
GNELane* getLane() const;
133
134
/// @brief get position over lane
135
double getPositionOverLane() const;
136
137
/// @brief get position over lane that is applicable to the shape
138
double getGeometryPositionOverLane() const;
139
140
/// @name Functions related with geometry of element
141
/// @{
142
143
/// @brief update pre-computed geometry information
144
virtual void updateGeometry() = 0;
145
146
/// @brief Returns position of additional in view
147
Position getPositionInView() const;
148
149
/// @brief update centering boundary (implies change in RTREE)
150
void updateCenteringBoundary(const bool updateGrid);
151
152
/// @brief split geometry
153
void splitEdgeGeometry(const double splitPosition, const GNENetworkElement* originalElement, const GNENetworkElement* newElement, GNEUndoList* undoList);
154
155
/// @}
156
157
/// @name inherited from GUIGLObject
158
/// @{
159
160
/**@brief Returns the name of the parent object
161
* @return This object's parent id
162
*/
163
std::string getParentName() const;
164
165
/**@brief Draws the object
166
* @param[in] s The settings for the current view (may influence drawing)
167
* @see GUIGlObject::drawGL
168
*/
169
virtual void drawGL(const GUIVisualizationSettings& s) const = 0;
170
171
/// @}
172
173
/// @name inherited from GNEAttributeCarrier
174
/// @{
175
176
/* @brief method for getting the Attribute of an XML key
177
* @param[in] key The attribute key
178
* @return string with the value associated to key
179
*/
180
virtual std::string getAttribute(SumoXMLAttr key) const = 0;
181
182
/* @brief method for getting the Attribute of an XML key in double format (to avoid unnecessary parse<double>(...) for certain attributes)
183
* @param[in] key The attribute key
184
* @return double with the value associated to key
185
*/
186
virtual double getAttributeDouble(SumoXMLAttr key) const = 0;
187
188
/// @brief get parameters map
189
const Parameterised::Map& getACParametersMap() const;
190
191
/* @brief method for setting the attribute and letting the object perform additional changes
192
* @param[in] key The attribute key
193
* @param[in] value The new value
194
* @param[in] undoList The undoList on which to register changes
195
*/
196
virtual void setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) = 0;
197
198
/* @brief method for checking if the key and their conrrespond attribute are valids
199
* @param[in] key The attribute key
200
* @param[in] value The value associated to key key
201
* @return true if the value is valid, false in other case
202
*/
203
virtual bool isValid(SumoXMLAttr key, const std::string& value) = 0;
204
205
/// @brief get PopPup ID (Used in AC Hierarchy)
206
std::string getPopUpID() const;
207
208
/// @brief get Hierarchy Name (Used in AC Hierarchy)
209
std::string getHierarchyName() const;
210
211
/// @}
212
213
protected:
214
/// @brief position of detector over Lane
215
double myPositionOverLane = 0;
216
217
/// @brief The aggregation period the values the detector collects shall be summed up.
218
SUMOTime myPeriod = 0;
219
220
/// @brief The path to the output file
221
std::string myOutputFilename;
222
223
/// @brief attribute vehicle types
224
std::vector<std::string> myVehicleTypes;
225
226
/// @brief next edges
227
std::vector<std::string> myNextEdges;
228
229
/// @brief detect persons
230
std::string myDetectPersons;
231
232
/// @brief Flag for friendly position
233
bool myFriendlyPosition = false;
234
235
/* @brief method for getting the Attribute of an XML key
236
* @param[in] key The attribute key
237
* @return string with the value associated to key
238
*/
239
std::string getDetectorAttribute(SumoXMLAttr key) const;
240
241
/* @brief method for getting the Attribute of an XML key in double format (to avoid unnecessary parse<double>(...) for certain attributes)
242
* @param[in] key The attribute key
243
* @return double with the value associated to key
244
*/
245
double getDetectorAttributeDouble(SumoXMLAttr key) const;
246
247
/* @brief method for setting the attribute and letting the object perform additional changes
248
* @param[in] key The attribute key
249
* @param[in] value The new value
250
* @param[in] undoList The undoList on which to register changes
251
*/
252
void setDetectorAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList);
253
254
/* @brief method for checking if the key and their conrrespond attribute are valids
255
* @param[in] key The attribute key
256
* @param[in] value The value associated to key key
257
* @return true if the value is valid, false in other case
258
*/
259
bool isDetectorValid(SumoXMLAttr key, const std::string& value);
260
261
/**@brief write additional element into a xml file
262
* @param[in] device device in which write parameters of additional element
263
*/
264
void writeDetectorValues(OutputDevice& device) const;
265
266
/// @brief set attribute after validation
267
void setDetectorAttribute(SumoXMLAttr key, const std::string& value);
268
269
/// @brief draw E1 shape
270
void drawE1Shape(const GUIVisualizationSettings::Detail d, const double exaggeration,
271
const RGBColor& mainColor, const RGBColor& secondColor) const;
272
273
/// @brief draw E1 detector Logo
274
void drawE1DetectorLogo(const GUIVisualizationSettings& s, const GUIVisualizationSettings::Detail d,
275
const double exaggeration, const std::string& logo, const RGBColor& textColor) const;
276
277
/// @brief draw E2 detector Logo
278
void drawE2DetectorLogo(const GUIVisualizationSettings& s, const GUIVisualizationSettings::Detail d,
279
const double exaggeration, const std::string& logo, const RGBColor& textColor) const;
280
281
private:
282
/// @brief set attribute after validation
283
virtual void setAttribute(SumoXMLAttr key, const std::string& value) = 0;
284
285
/// @brief set move shape
286
virtual void setMoveShape(const GNEMoveResult& moveResult) = 0;
287
288
/// @brief commit move shape
289
virtual void commitMoveShape(const GNEMoveResult& moveResult, GNEUndoList* undoList) = 0;
290
291
/// @brief Invalidate return position of additional
292
const Position& getPosition() const = delete;
293
294
/// @brief Invalidate set new position in the view
295
void setPosition(const Position& pos) = delete;
296
};
297
298