Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
eclipse
GitHub Repository: eclipse/sumo
Path: blob/main/src/netedit/elements/demand/GNEDemandElement.h
185790 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 GNEDemandElement.h
15
/// @author Pablo Alvarez Lopez
16
/// @date Dec 2018
17
///
18
// A abstract class for demand elements
19
/****************************************************************************/
20
#pragma once
21
#include <config.h>
22
23
#include <netedit/elements/GNEAttributeCarrier.h>
24
#include <netedit/elements/GNEHierarchicalElement.h>
25
#include <netedit/elements/GNEPathElement.h>
26
#include <utils/gui/div/GUIGeometry.h>
27
#include <utils/gui/globjects/GUIGlObject.h>
28
29
// ===========================================================================
30
// class declarations
31
// ===========================================================================
32
33
class SUMOVehicleParameter;
34
35
// ===========================================================================
36
// class definitions
37
// ===========================================================================
38
39
class GNEDemandElement : public GNEAttributeCarrier, public GNEHierarchicalElement, public GUIGlObject, public GNEPathElement {
40
41
public:
42
/// @brief friend declaration (needed for vTypes)
43
friend class GNERouteHandler;
44
friend class GNEDemandElementFlow;
45
friend class GNEDemandElementPlan;
46
47
/// @brief enum class for demandElement problems
48
enum class Problem {
49
OK, // There is no problem
50
INVALID_ELEMENT, // Element is invalid (for example, a route without edges)
51
INVALID_PATH, // Path (route, trip... ) is not valid (i.e is empty)
52
DISCONNECTED_PLAN, // Plan element (person, containers) is not connected with the previous or next plan
53
INVALID_STOPPOSITION, // StopPosition is invalid (only used in stops over edges or lanes
54
STOP_DOWNSTREAM, // Stops don't follow their route parent
55
REPEATEDROUTE_DISCONNECTED, // Repeated route is disconnected
56
NO_PLANS // Person or container doesn't have a plan
57
};
58
59
/**@brief Constructor for templates
60
* @param[in] tag Type of xml tag that define the demand element element (SUMO_TAG_ROUTE, SUMO_TAG_VEHICLE, etc...)
61
*/
62
GNEDemandElement(GNENet* net, SumoXMLTag tag);
63
64
/**@brief Constructor
65
* @param[in] id Gl-id of the demand element element (Must be unique)
66
* @param[in] tag SUMO Tag assigned to this type of object
67
* @param[in] net GNENet in which this AttributeCarrier is stored
68
* @param[in] fileBucket bucket in which this AttributeCarrier is stored
69
*/
70
GNEDemandElement(const std::string& id, GNENet* net, SumoXMLTag tag, FileBucket* fileBucket);
71
72
/**@brief Constructor
73
* @param[in] demandElementParent pointer to parent demand element pointer
74
* @param[in] tag Type of xml tag that define the demand element element (SUMO_TAG_ROUTE, SUMO_TAG_VEHICLE, etc...)
75
*/
76
GNEDemandElement(GNEDemandElement* demandElementParent, SumoXMLTag tag);
77
78
/// @brief Destructor
79
virtual ~GNEDemandElement();
80
81
/// @brief methods to retrieve the elements linked to this GNEDemandElement
82
/// @{
83
84
/// @brief get GNEHierarchicalElement associated with this GNEDemandElement
85
GNEHierarchicalElement* getHierarchicalElement() override;
86
87
/// @brief get GUIGlObject associated with this GNEDemandElement
88
GUIGlObject* getGUIGlObject() override;
89
90
/// @brief get GUIGlObject associated with this GNEDemandElement (constant)
91
const GUIGlObject* getGUIGlObject() const override;
92
93
/// @}
94
95
/// @brief get reference to fileBucket in which save this AC
96
FileBucket* getFileBucket() const override;
97
98
/// @brief change filebucket manually (used only during calibratorFlows creation)
99
void changeFileBucket(FileBucket* fileBucket);
100
101
/// @brief get demand element geometry (stacked)
102
const GUIGeometry& getDemandElementGeometry();
103
104
/// @brief get previous child demand element to the given demand element
105
GNEDemandElement* getPreviousChildDemandElement(const GNEDemandElement* demandElement) const;
106
107
/// @brief get next child demand element to the given demand element
108
GNEDemandElement* getNextChildDemandElement(const GNEDemandElement* demandElement) const;
109
110
/// @brief update element stacked geometry (stacked)
111
void updateDemandElementGeometry(const GNELane* lane, const double posOverLane);
112
113
/// @brief update stack label
114
void updateDemandElementStackLabel(const int stack);
115
116
/// @brief update element spread geometry
117
void updateDemandElementSpreadGeometry(const GNELane* lane, const double posOverLane);
118
119
/// @name members and functions relative to elements common to all demand elements
120
/// @{
121
122
/// @brief obtain VClass related with this demand element
123
virtual SUMOVehicleClass getVClass() const = 0;
124
125
/// @brief get color
126
virtual const RGBColor& getColor() const = 0;
127
128
/// @}
129
130
/// @name members and functions relative to write demand elements into XML
131
/// @{
132
133
/**@brief write demand element element into a xml file
134
* @param[in] device device in which write parameters of demand element element
135
*/
136
virtual void writeDemandElement(OutputDevice& device) const = 0;
137
138
/// @brief check if current demand element is valid to be written into XML (by default true, can be reimplemented in children)
139
virtual Problem isDemandElementValid() const = 0;
140
141
/// @brief return a string with the current demand element problem (by default empty, can be reimplemented in children)
142
virtual std::string getDemandElementProblem() const = 0;
143
144
/// @brief fix demand element problem (by default throw an exception, has to be reimplemented in children)
145
virtual void fixDemandElementProblem() = 0;
146
147
/// @}
148
149
/**@brief open DemandElement Dialog
150
* @note: if demand element needs an demand element dialog, this function has to be implemented in childrens (see GNERerouter and GNEVariableSpeedSign)
151
* @throw invalid argument if demand element doesn't have an demand element Dialog
152
*/
153
virtual void openDemandElementDialog();
154
155
/// @name Functions related with geometry of element
156
/// @{
157
158
/// @brief Returns position of demand element in view
159
virtual Position getPositionInView() const = 0;
160
161
/// @brief split geometry
162
virtual void splitEdgeGeometry(const double splitPosition, const GNENetworkElement* originalElement, const GNENetworkElement* newElement, GNEUndoList* undoList) = 0;
163
164
/// @brief get demand element geometry
165
const GUIGeometry& getDemandElementGeometry() const;
166
167
/// @}
168
169
/// @name Function related with contour drawing
170
/// @{
171
172
/// @brief check if draw from contour (green)
173
bool checkDrawFromContour() const override;
174
175
/// @brief check if draw from contour (magenta)
176
bool checkDrawToContour() const override;
177
178
/// @brief check if draw related contour (cyan)
179
bool checkDrawRelatedContour() const override;
180
181
/// @brief check if draw over contour (orange)
182
bool checkDrawOverContour() const override;
183
184
/// @brief check if draw delete contour (pink/white)
185
bool checkDrawDeleteContour() const override;
186
187
/// @brief check if draw delete contour small (pink/white)
188
bool checkDrawDeleteContourSmall() const override;
189
190
/// @brief check if draw select contour (blue)
191
bool checkDrawSelectContour() const override;
192
193
/// @brief check if draw move contour (red)
194
bool checkDrawMoveContour() const override;
195
196
/// @}
197
198
/// @name inherited from GUIGlObject
199
/// @{
200
201
/**@brief Returns an own popup-menu
202
*
203
* @param[in] app The application needed to build the popup-menu
204
* @param[in] parent The parent window needed to build the popup-menu
205
* @return The built popup-menu
206
* @see GUIGlObject::getPopUpMenu
207
*/
208
virtual GUIGLObjectPopupMenu* getPopUpMenu(GUIMainWindow& app, GUISUMOAbstractView& parent) override;
209
210
/**@brief Returns an own parameter window
211
*
212
* @param[in] app The application needed to build the parameter window
213
* @param[in] parent The parent window needed to build the parameter window
214
* @return The built parameter window
215
* @see GUIGlObject::getParameterWindow
216
*/
217
GUIParameterTableWindow* getParameterWindow(GUIMainWindow& app, GUISUMOAbstractView& parent) override;
218
219
/// @brief check if element is locked
220
bool isGLObjectLocked() const override;
221
222
/// @brief mark element as front element
223
void markAsFrontElement() override;
224
225
/// @brief delete element
226
void deleteGLObject() override;
227
228
/// @brief select element
229
void selectGLObject() override;
230
231
/// @brief update GLObject (geometry, ID, etc.)
232
void updateGLObject() override;
233
234
/// @}
235
236
/// @name inherited from GNEAttributeCarrier
237
/// @{
238
239
/* @brief method for getting the Attribute of an XML key in position format
240
* @param[in] key The attribute key
241
* @return position with the value associated to key
242
*/
243
Position getAttributePosition(SumoXMLAttr key) const override;
244
245
/* @brief method for getting the Attribute of an XML key in positionVector format
246
* @param[in] key The attribute key
247
* @return positionVector with the value associated to key
248
*/
249
PositionVector getAttributePositionVector(SumoXMLAttr key) const override;
250
251
/// @}
252
253
/// @name inherited from GNEPathElement
254
/// @{
255
256
/// @brief check if path element is selected
257
bool isPathElementSelected() const override;
258
259
/// @}
260
261
/// @brief get invalid stops
262
std::vector<GNEDemandElement*> getInvalidStops() const;
263
264
protected:
265
/// @brief demand element geometry (also called "stacked geometry")
266
GUIGeometry myDemandElementGeometry;
267
268
/// @brief demand element spread geometry (Only used by vehicles and pedestrians)
269
GUIGeometry mySpreadGeometry;
270
271
/// @brief stacked label number
272
int myStackedLabelNumber = 0;
273
274
/// @brief check if a new demand element ID is valid
275
bool isValidDemandElementID(const std::string& value) const;
276
277
/// @brief check if a new demand element ID is valid
278
bool isValidDemandElementID(const std::vector<SumoXMLTag>& tags, const std::string& value) const;
279
280
/// @brief set demand element id
281
void setDemandElementID(const std::string& newID);
282
283
/// @brief get type parent (needed because first parent can be either type or typeDistribution)
284
GNEDemandElement* getTypeParent() const;
285
286
/// @brief get route parent (always the second parent demand element)
287
GNEDemandElement* getRouteParent() const;
288
289
/// @brief draw line between junctions
290
void drawJunctionLine(const GNEDemandElement* element) const;
291
292
/// @brief draw stack label
293
void drawStackLabel(const int number, const std::string& element, const Position& position, const double rotation,
294
const double width, const double length, const double exaggeration) const;
295
296
/// @name replace parent elements
297
/// @{
298
299
/// @brief all edges
300
void replaceParentEdges(const std::string& value);
301
302
/// @brief replace the first parent lane
303
void replaceFirstParentLane(const std::string& value);
304
305
/// @brief replace the first parent junction
306
void replaceFirstParentJunction(const std::string& value);
307
308
/// @brief replace the last parent junction
309
void replaceLastParentJunction(const std::string& value);
310
311
/// @brief replace the first parent edge
312
void replaceFirstParentEdge(const std::string& value);
313
314
/// @brief replace the last parent edge
315
void replaceLastParentEdge(const std::string& value);
316
317
/// @brief replace the first parent additional
318
void replaceFirstParentAdditional(SumoXMLTag tag, const std::string& value);
319
320
/// @brief replace the last parent additional
321
void replaceLastParentAdditional(SumoXMLTag tag, const std::string& value);
322
323
/// @brief replace demand element parent
324
void replaceDemandElementParent(const std::vector<SumoXMLTag> tags, const std::string& value, const int parentIndex);
325
326
/// @}
327
328
/// @brief auxiliar struct used for calculate pathStopIndex
329
struct EdgeStopIndex {
330
331
/// @brief constructor
332
EdgeStopIndex(GNEEdge* edge_, GNEDemandElement* stop) :
333
edge(edge_),
334
stops({stop}) {}
335
336
/// @brief edge (obtained from segment)
337
const GNEEdge* edge = nullptr;
338
339
/// @brief list of stops placed in the edge
340
std::vector<GNEDemandElement*> stops;
341
342
/// @brief stopIndex (-1 menans out of route)
343
int stopIndex = -1;
344
345
private:
346
/// @brief default constructor (disabled)
347
EdgeStopIndex() {}
348
};
349
350
/// @brief get edgeStopIndex
351
std::vector<EdgeStopIndex> getEdgeStopIndex() const;
352
353
/// @brief get color by scheme (used by vehicles, persons and containers)
354
RGBColor getColorByScheme(const GUIColorer& c, const SUMOVehicleParameter* parameters) const;
355
356
/// @brief build menu command route length
357
void buildMenuCommandRouteLength(GUIGLObjectPopupMenu* ret) const;
358
359
/// @brief build menu command route length
360
void buildMenuAddReverse(GUIGLObjectPopupMenu* ret) const;
361
362
private:
363
/**@brief check restriction with the number of children
364
* @throw ProcessError if itis called without be reimplemented in child class
365
*/
366
virtual bool checkChildDemandElementRestriction() const;
367
368
/// @brief Invalidated copy constructor.
369
GNEDemandElement(const GNEDemandElement&) = delete;
370
371
/// @brief Invalidated assignment operator.
372
GNEDemandElement& operator=(const GNEDemandElement&) = delete;
373
};
374
375