Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
eclipse
GitHub Repository: eclipse/sumo
Path: blob/main/src/netedit/elements/demand/GNEVehicle.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 GNEVehicle.h
15
/// @author Pablo Alvarez Lopez
16
/// @date Jan 2019
17
///
18
// Representation of vehicles in netedit
19
/****************************************************************************/
20
#pragma once
21
#include <config.h>
22
#include <utils/gui/globjects/GUIGLObjectPopupMenu.h>
23
24
#include "GNEDemandElement.h"
25
#include "GNEDemandElementFlow.h"
26
27
// ===========================================================================
28
// class declaration
29
// ===========================================================================
30
31
class GNEMoveElementVehicle;
32
class GNEMoveElementView;
33
34
// ===========================================================================
35
// class definitions
36
// ===========================================================================
37
38
class GNEVehicle : public GNEDemandElement, public GNEDemandElementFlow {
39
40
public:
41
/// @brief class used in GUIGLObjectPopupMenu for single vehicle transformations
42
class GNESingleVehiclePopupMenu : public GUIGLObjectPopupMenu {
43
FXDECLARE(GNESingleVehiclePopupMenu)
44
45
public:
46
/** @brief Constructor
47
* @param[in] vehicle GNEVehicle to be transformed
48
* @param[in] app The main window for instantiation of other windows
49
* @param[in] parent The parent view for changing it
50
*/
51
GNESingleVehiclePopupMenu(GNEVehicle* vehicle, GUIMainWindow& app, GUISUMOAbstractView& parent);
52
53
/// @brief Destructor
54
~GNESingleVehiclePopupMenu();
55
56
/// @brief Called to transform the current vehicle to another vehicle type
57
long onCmdTransform(FXObject*, FXSelector sel, void*);
58
59
protected:
60
/// @brief default constructor needed by FOX
61
FOX_CONSTRUCTOR(GNESingleVehiclePopupMenu);
62
63
private:
64
/// @brief current vehicle
65
GNEVehicle* myVehicle;
66
};
67
68
/// @brief class used in GUIGLObjectPopupMenu for single vehicle transformations
69
class GNESelectedVehiclesPopupMenu : public GUIGLObjectPopupMenu {
70
FXDECLARE(GNESelectedVehiclesPopupMenu)
71
72
public:
73
/** @brief Constructor
74
* @param[in] vehicle clicked GNEVehicle
75
* @param[in] selectedVehicle vector with selected GNEVehicle
76
* @param[in] app The main window for instantiation of other windows
77
* @param[in] parent The parent view for changing it
78
*/
79
GNESelectedVehiclesPopupMenu(GNEVehicle* vehicle, const std::vector<GNEVehicle*>& selectedVehicle,
80
GUIMainWindow& app, GUISUMOAbstractView& parent);
81
82
/// @brief Destructor
83
~GNESelectedVehiclesPopupMenu();
84
85
/// @brief Called to transform the current vehicle to another vehicle type
86
long onCmdTransform(FXObject* obj, FXSelector sel, void*);
87
88
protected:
89
/// @brief default constructor needed by FOX
90
FOX_CONSTRUCTOR(GNESelectedVehiclesPopupMenu);
91
92
private:
93
/// @brief current selected vehicles
94
std::vector<GNEVehicle*> mySelectedVehicles;
95
96
/// @brief selected menu commands
97
std::map<FXObject*, SumoXMLTag> myRestrictedMenuCommands;
98
99
/// @brief tag of clicked vehicle
100
SumoXMLTag myVehicleTag;
101
};
102
103
/// @brief default constructor
104
GNEVehicle(SumoXMLTag tag, GNENet* net);
105
106
/// @brief default constructor for vehicles and routeFlows without embedded routes
107
GNEVehicle(SumoXMLTag tag, const std::string& vehicleID, GNENet* net, FileBucket* fileBucket,
108
GNEDemandElement* vehicleType, GNEDemandElement* route);
109
110
/// @brief parameter constructor for vehicles and routeFlows without embedded routes
111
GNEVehicle(SumoXMLTag tag, GNENet* net, FileBucket* fileBucket, GNEDemandElement* vehicleType,
112
GNEDemandElement* route, const SUMOVehicleParameter& vehicleParameters);
113
114
/// @brief parameter constructor for vehicles and routeFlows with embedded routes (note: After creation create immediately a embedded route referencing this vehicle)
115
GNEVehicle(SumoXMLTag tag, GNENet* net, FileBucket* fileBucket, GNEDemandElement* vehicleType,
116
const SUMOVehicleParameter& vehicleParameters);
117
118
/// @brief default constructor for trips and Flows over edges
119
GNEVehicle(SumoXMLTag tag, const std::string& vehicleID, GNENet* net, FileBucket* fileBucket,
120
GNEDemandElement* vehicleType, GNEEdge* fromEdge, GNEEdge* toEdge);
121
122
/// @brief parameter constructor for trips and Flows over junctions
123
GNEVehicle(SumoXMLTag tag, GNENet* net, FileBucket* fileBucket, GNEDemandElement* vehicleType,
124
GNEEdge* fromEdge, GNEEdge* toEdge, const SUMOVehicleParameter& vehicleParameters);
125
126
/// @brief default constructor for trips and Flows over junctions
127
GNEVehicle(SumoXMLTag tag, const std::string& vehicleID, GNENet* net, FileBucket* fileBucket,
128
GNEDemandElement* vehicleType, GNEJunction* fromJunction, GNEJunction* toJunction);
129
130
/// @brief parameter constructor for trips and Flows over junctions
131
GNEVehicle(SumoXMLTag tag, GNENet* net, FileBucket* fileBucket, GNEDemandElement* vehicleType,
132
GNEJunction* fromJunction, GNEJunction* toJunction, const SUMOVehicleParameter& vehicleParameters);
133
134
/// @brief parameter constructor for trips and Flows over TAZs
135
GNEVehicle(SumoXMLTag tag, GNENet* net, FileBucket* fileBucket, GNEDemandElement* vehicleType,
136
GNEAdditional* fromTAZ, GNEAdditional* toTAZ, const SUMOVehicleParameter& vehicleParameters);
137
138
/// @brief destructor
139
~GNEVehicle();
140
141
/// @brief methods to retrieve the elements linked to this vehicle
142
/// @{
143
144
/// @brief get GNEMoveElement associated with this vehicle
145
GNEMoveElement* getMoveElement() const override;
146
147
/// @brief get parameters associated with this vehicle
148
Parameterised* getParameters() override;
149
150
/// @brief get parameters associated with this vehicle (constant)
151
const Parameterised* getParameters() const override;
152
153
/// @}
154
155
/**@brief write demand element element into a xml file
156
* @param[in] device device in which write parameters of demand element element
157
*/
158
void writeDemandElement(OutputDevice& device) const override;
159
160
/// @brief check if current demand element is valid to be written into XML (by default true, can be reimplemented in children)
161
Problem isDemandElementValid() const override;
162
163
/// @brief return a string with the current demand element problem (by default empty, can be reimplemented in children)
164
std::string getDemandElementProblem() const override;
165
166
/// @brief fix demand element problem (by default throw an exception, has to be reimplemented in children)
167
void fixDemandElementProblem() override;
168
169
/// @name members and functions relative to elements common to all demand elements
170
/// @{
171
/// @brief obtain VClass related with this demand element
172
SUMOVehicleClass getVClass() const override;
173
174
/// @brief get color
175
const RGBColor& getColor() const override;
176
177
/// @}
178
179
/// @name Functions related with geometry of element
180
/// @{
181
/// @brief update pre-computed geometry information
182
void updateGeometry() override;
183
184
/// @brief Returns position of demand element in view
185
Position getPositionInView() const override;
186
187
/// @}
188
189
/// @name Function related with drawing
190
/// @{
191
/// @brief check if draw related contour (cyan)
192
bool checkDrawRelatedContour() const override;
193
194
/// @}
195
196
/// @name inherited from GUIGlObject
197
/// @{
198
/**@brief Returns an own popup-menu
199
*
200
* @param[in] app The application needed to build the popup-menu
201
* @param[in] parent The parent window needed to build the popup-menu
202
* @return The built popup-menu
203
* @see GUIGlObject::getPopUpMenu
204
*/
205
GUIGLObjectPopupMenu* getPopUpMenu(GUIMainWindow& app, GUISUMOAbstractView& parent) override;
206
207
/**@brief Returns the name of the parent object
208
* @return This object's parent id
209
*/
210
std::string getParentName() const override;
211
212
/// @brief return exaggeration associated with this GLObject
213
double getExaggeration(const GUIVisualizationSettings& s) const override;
214
215
/**@brief Returns the boundary to which the view shall be centered in order to show the object
216
* @return The boundary the object is within
217
*/
218
Boundary getCenteringBoundary() const override;
219
220
/// @brief split geometry
221
void splitEdgeGeometry(const double splitPosition, const GNENetworkElement* originalElement, const GNENetworkElement* newElement, GNEUndoList* undoList) override;
222
223
/**@brief Draws the object
224
* @param[in] s The settings for the current view (may influence drawing)
225
* @see GUIGlObject::drawGL
226
*/
227
void drawGL(const GUIVisualizationSettings& s) const override;
228
229
/// @}
230
231
/// @name inherited from GNEPathElement
232
/// @{
233
234
/// @brief compute pathElement
235
void computePathElement() override;
236
237
/**@brief Draws partial object over lane
238
* @param[in] s The settings for the current view (may influence drawing)
239
* @param[in] segment lane segment
240
* @param[in] offsetFront front offset
241
*/
242
void drawLanePartialGL(const GUIVisualizationSettings& s, const GNESegment* segment, const double offsetFront) const override;
243
244
/**@brief Draws partial object over junction
245
* @param[in] s The settings for the current view (may influence drawing)
246
* @param[in] segment junction segment
247
* @param[in] offsetFront front offset
248
*/
249
void drawJunctionPartialGL(const GUIVisualizationSettings& s, const GNESegment* segment, const double offsetFront) const override;
250
251
/// @brief get first path lane
252
GNELane* getFirstPathLane() const override;
253
254
/// @brief get last path lane
255
GNELane* getLastPathLane() const override;
256
/// @}
257
258
/// @brief inherited from GNEAttributeCarrier
259
/// @{
260
/* @brief method for getting the Attribute of an XML key
261
* @param[in] key The attribute key
262
* @return string with the value associated to key
263
*/
264
std::string getAttribute(SumoXMLAttr key) const override;
265
266
/* @brief method for getting the Attribute of an XML key in double format
267
* @param[in] key The attribute key
268
* @return double with the value associated to key
269
*/
270
double getAttributeDouble(SumoXMLAttr key) const override;
271
272
/* @brief method for getting the Attribute of an XML key in position format
273
* @param[in] key The attribute key
274
* @return position with the value associated to key
275
*/
276
Position getAttributePosition(SumoXMLAttr key) const override;
277
278
/* @brief method for setting the attribute and letting the object perform demand element changes
279
* @param[in] key The attribute key
280
* @param[in] value The new value
281
* @param[in] undoList The undoList on which to register changes
282
* @param[in] net optionally the GNENet to inform about gui updates
283
*/
284
void setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) override;
285
286
/* @brief method for setting the attribute and letting the object perform demand element changes
287
* @param[in] key The attribute key
288
* @param[in] value The new value
289
* @param[in] undoList The undoList on which to register changes
290
*/
291
bool isValid(SumoXMLAttr key, const std::string& value) override;
292
293
/* @brief method for enable attribute
294
* @param[in] key The attribute key
295
* @param[in] undoList The undoList on which to register changes
296
* @note certain attributes can be only enabled, and can produce the disabling of other attributes
297
*/
298
void enableAttribute(SumoXMLAttr key, GNEUndoList* undoList) override;
299
300
/* @brief method for disable attribute
301
* @param[in] key The attribute key
302
* @param[in] undoList The undoList on which to register changes
303
* @note certain attributes can be only enabled, and can produce the disabling of other attributes
304
*/
305
void disableAttribute(SumoXMLAttr key, GNEUndoList* undoList) override;
306
307
/* @brief method for check if the value for certain attribute is set
308
* @param[in] key The attribute key
309
*/
310
bool isAttributeEnabled(SumoXMLAttr key) const override;
311
312
/// @brief get PopPup ID (Used in AC Hierarchy)
313
std::string getPopUpID() const override;
314
315
/// @brief get Hierarchy Name (Used in AC Hierarchy)
316
std::string getHierarchyName() const override;
317
318
/// @}
319
320
/// @brief create a copy of the given vehicle
321
static GNEDemandElement* copyVehicle(const GNEVehicle* originalVehicle);
322
323
protected:
324
/// @brief move element vehicle over lanes
325
GNEMoveElementVehicle* myMoveElementVehicle = nullptr;
326
327
/// @brief move element over view
328
GNEMoveElementView* myMoveElementView = nullptr;
329
330
/// @brief position over view
331
Position myPosOverView;
332
333
/// @brief variable used for draw vehicle contours
334
GNEContour myVehicleContour;
335
336
/// @brief get drawing color
337
RGBColor getDrawingColor(const GUIVisualizationSettings& s) const;
338
339
/// @brier get sumo vehicle parameter
340
const SUMOVehicleParameter& getSUMOVehicleParameter() const;
341
342
private:
343
/// @brief method for setting the attribute and nothing else
344
void setAttribute(SumoXMLAttr key, const std::string& value) override;
345
346
/// @brief method for enable or disable the attribute and nothing else (used in GNEChange_ToggleAttribute)
347
void toggleAttribute(SumoXMLAttr key, const bool value) override;
348
349
/// @brief Invalidated copy constructor.
350
GNEVehicle(const GNEVehicle&) = delete;
351
352
/// @brief Invalidated assignment operator
353
GNEVehicle& operator=(const GNEVehicle&) = delete;
354
};
355
356