Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
eclipse
GitHub Repository: eclipse/sumo
Path: blob/main/src/netedit/elements/additional/GNEAdditional.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 GNEAdditional.h
15
/// @author Pablo Alvarez Lopez
16
/// @date Jan 2016
17
///
18
// A abstract class for representation of additional elements
19
/****************************************************************************/
20
#pragma once
21
#include <config.h>
22
23
#include <netedit/elements/GNEAttributeCarrier.h>
24
#include <netedit/elements/GNEContour.h>
25
#include <netedit/elements/GNEHierarchicalElement.h>
26
#include <netedit/elements/GNEMoveElement.h>
27
#include <netedit/elements/GNEPathElement.h>
28
#include <utils/gui/globjects/GUIGlObject.h>
29
#include <utils/gui/images/GUITextureSubSys.h>
30
31
// ===========================================================================
32
// class declarations
33
// ===========================================================================
34
35
class GNENetworkElement;
36
class GUIGLObjectPopupMenu;
37
38
// ===========================================================================
39
// class definitions
40
// ===========================================================================
41
42
class GNEAdditional : public GNEAttributeCarrier, public GNEHierarchicalElement, public GUIGlObject, public GNEPathElement, public GNEMoveElement {
43
44
public:
45
/**@brief Constructor
46
* @param[in] id Gl-id of the additional element (Must be unique)
47
* @param[in] net pointer to GNENet of this additional element belongs
48
* @param[in] filename file in which this AttributeCarrier is stored
49
* @param[in] tag Type of xml tag that define the additional element (SUMO_TAG_BUS_STOP, SUMO_TAG_REROUTER, etc...)
50
* @param[in] additionalName Additional name
51
*/
52
GNEAdditional(const std::string& id, GNENet* net, const std::string& filename,
53
SumoXMLTag tag, const std::string& additionalName);
54
55
/**@brief Constructor for additional with parents
56
* @param[in] additionalParent pointer to additional parent
57
* @param[in] tag Type of xml tag that define the additional element (SUMO_TAG_BUS_STOP, SUMO_TAG_REROUTER, etc...)
58
* @param[in] additionalName Additional name
59
*/
60
GNEAdditional(GNEAdditional* additionalParent, SumoXMLTag tag, const std::string& additionalName);
61
62
/// @brief Destructor
63
~GNEAdditional();
64
65
/// @brief get GNEHierarchicalElement associated with this AttributeCarrier
66
GNEHierarchicalElement* getHierarchicalElement();
67
68
/**@brief get move operation
69
* @note returned GNEMoveOperation can be nullptr
70
*/
71
virtual GNEMoveOperation* getMoveOperation() = 0;
72
73
/// @brief remove geometry point in the clicked position (Currently unused in shapes)
74
void removeGeometryPoint(const Position clickedPosition, GNEUndoList* undoList);
75
76
/// @brief get GUIGlObject associated with this AttributeCarrier
77
GUIGlObject* getGUIGlObject();
78
79
/// @brief get GUIGlObject associated with this AttributeCarrier (constant)
80
const GUIGlObject* getGUIGlObject() const;
81
82
/// @brief Returns the name of the object (default "")
83
virtual const std::string getOptionalName() const;
84
85
/// @brief obtain additional geometry
86
const GUIGeometry& getAdditionalGeometry() const;
87
88
/// @brief set special color
89
void setSpecialColor(const RGBColor* color);
90
91
/// @brief reset additional contour
92
void resetAdditionalContour();
93
94
/// @name members and functions relative to write additionals into XML
95
/// @{
96
97
/**@brief write additional element into a xml file
98
* @param[in] device device in which write parameters of additional element
99
*/
100
virtual void writeAdditional(OutputDevice& device) const = 0;
101
102
/// @brief check if current additional is valid to be written into XML (by default true, can be reimplemented in children)
103
virtual bool isAdditionalValid() const = 0;
104
105
/// @brief return a string with the current additional problem (by default empty, can be reimplemented in children)
106
virtual std::string getAdditionalProblem() const = 0;
107
108
/// @brief fix additional problem (by default throw an exception, has to be reimplemented in children)
109
virtual void fixAdditionalProblem() = 0;
110
111
/// @}
112
113
/// @name functions related with geometry
114
/// @{
115
116
/**@brief open Additional Dialog
117
* @note: if additional needs an additional dialog, this function has to be implemented in childrens (see GNERerouter and GNEVariableSpeedSign)
118
* @throw invalid argument if additional doesn't have an additional Dialog
119
*/
120
virtual void openAdditionalDialog();
121
122
/// @brief update pre-computed geometry information
123
virtual void updateGeometry() = 0;
124
125
/// @brief Returns position of additional in view
126
virtual Position getPositionInView() const = 0;
127
128
/// @brief return exaggeration associated with this GLObject
129
double getExaggeration(const GUIVisualizationSettings& s) const;
130
131
/// @brief Returns the boundary to which the view shall be centered in order to show the object
132
Boundary getCenteringBoundary() const;
133
134
/// @brief update centering boundary (implies change in RTREE)
135
virtual void updateCenteringBoundary(const bool updateGrid) = 0;
136
137
/// @brief split geometry
138
virtual void splitEdgeGeometry(const double splitPosition, const GNENetworkElement* originalElement, const GNENetworkElement* newElement, GNEUndoList* undoList) = 0;
139
140
/// @}
141
142
/// @name Function related with contour drawing
143
/// @{
144
145
/// @brief check if draw from contour (green)
146
bool checkDrawFromContour() const;
147
148
/// @brief check if draw from contour (magenta)
149
bool checkDrawToContour() const;
150
151
/// @brief check if draw related contour (cyan)
152
bool checkDrawRelatedContour() const;
153
154
/// @brief check if draw over contour (orange)
155
bool checkDrawOverContour() const;
156
157
/// @brief check if draw delete contour (pink/white)
158
bool checkDrawDeleteContour() const;
159
160
/// @brief check if draw delete contour small (pink/white)
161
bool checkDrawDeleteContourSmall() const;
162
163
/// @brief check if draw select contour (blue)
164
bool checkDrawSelectContour() const;
165
166
/// @brief check if draw move contour (red)
167
virtual bool checkDrawMoveContour() const = 0;
168
169
/// @}
170
171
/// @name inherited from GUIGlObject
172
/// @{
173
174
/**@brief Returns an own popup-menu
175
*
176
* @param[in] app The application needed to build the popup-menu
177
* @param[in] parent The parent window needed to build the popup-menu
178
* @return The built popup-menu
179
* @see GUIGlObject::getPopUpMenu
180
*/
181
virtual GUIGLObjectPopupMenu* getPopUpMenu(GUIMainWindow& app, GUISUMOAbstractView& parent);
182
183
/**@brief Returns an own parameter window
184
*
185
* @param[in] app The application needed to build the parameter window
186
* @param[in] parent The parent window needed to build the parameter window
187
* @return The built parameter window
188
* @see GUIGlObject::getParameterWindow
189
*/
190
GUIParameterTableWindow* getParameterWindow(GUIMainWindow& app, GUISUMOAbstractView& parent);
191
192
/// @brief Returns the additional name
193
const std::string& getOptionalAdditionalName() const;
194
195
/**@brief Draws the object
196
* @param[in] s The settings for the current view (may influence drawing)
197
* @see GUIGlObject::drawGL
198
*/
199
virtual void drawGL(const GUIVisualizationSettings& s) const = 0;
200
201
/// @brief check if element is locked
202
bool isGLObjectLocked() const;
203
204
/// @brief mark element as front element
205
void markAsFrontElement();
206
207
/// @brief delete element
208
void deleteGLObject();
209
210
/// @brief select element
211
void selectGLObject();
212
213
/// @brief update GLObject (geometry, ID, etc.)
214
void updateGLObject();
215
216
/// @}
217
218
/// @name inherited from GNEPathElement
219
/// @{
220
221
/// @brief compute pathElement
222
virtual void computePathElement();
223
224
/// @brief check if path element is selected
225
bool isPathElementSelected() const;
226
227
/**@brief Draws partial object over lane
228
* @param[in] s The settings for the current view (may influence drawing)
229
* @param[in] segment lane segment
230
* @param[in] offsetFront front offset
231
*/
232
virtual void drawLanePartialGL(const GUIVisualizationSettings& s, const GNESegment* segment, const double offsetFront) const;
233
234
/**@brief Draws partial object over junction
235
* @param[in] s The settings for the current view (may influence drawing)
236
* @param[in] segment junction segment
237
* @param[in] offsetFront front offset
238
*/
239
virtual void drawJunctionPartialGL(const GUIVisualizationSettings& s, const GNESegment* segment, const double offsetFront) const;
240
241
/// @brief get first path lane
242
GNELane* getFirstPathLane() const;
243
244
/// @brief get last path lane
245
GNELane* getLastPathLane() const;
246
247
/// @}
248
249
/// @name inherited from GNEAttributeCarrier
250
/// @{
251
252
/* @brief method for getting the Attribute of an XML key
253
* @param[in] key The attribute key
254
* @return string with the value associated to key
255
*/
256
virtual std::string getAttribute(SumoXMLAttr key) const = 0;
257
258
/* @brief method for getting the Attribute of an XML key in double format (to avoid unnecessary parse<double>(...) for certain attributes)
259
* @param[in] key The attribute key
260
* @return double with the value associated to key
261
*/
262
virtual double getAttributeDouble(SumoXMLAttr key) const = 0;
263
264
/* @brief method for getting the Attribute of an XML key in position format (to avoid unnecessary parse<position>(...) for certain attributes)
265
* @param[in] key The attribute key
266
* @return double with the value associated to key
267
*/
268
virtual Position getAttributePosition(SumoXMLAttr key) const;
269
270
/// @brief get parameters map
271
virtual const Parameterised::Map& getACParametersMap() const = 0;
272
273
/**@brief method for setting the attribute and letting the object perform additional changes
274
* @param[in] key The attribute key
275
* @param[in] value The new value
276
* @param[in] undoList The undoList on which to register changes
277
*/
278
virtual void setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) = 0;
279
280
/**@brief method for checking if the key and their correspondent attribute are valids
281
* @param[in] key The attribute key
282
* @param[in] value The value associated to key key
283
* @return true if the value is valid, false in other case
284
*/
285
virtual bool isValid(SumoXMLAttr key, const std::string& value) = 0;
286
287
/// @brief get PopPup ID (Used in AC Hierarchy)
288
virtual std::string getPopUpID() const = 0;
289
290
/// @brief get Hierarchy Name (Used in AC Hierarchy)
291
virtual std::string getHierarchyName() const = 0;
292
293
/// @}
294
295
/// @brief draw parent and child lines
296
void drawParentChildLines(const GUIVisualizationSettings& s, const RGBColor& color, const bool onlySymbols = false) const;
297
298
/// @brief draw up geometry point
299
void drawUpGeometryPoint(const GUIVisualizationSettings& s, const GUIVisualizationSettings::Detail d, const Position& pos,
300
const double rot, const RGBColor& baseColor, const bool ignoreShift = false) const;
301
302
/// @brief draw down geometry point
303
void drawDownGeometryPoint(const GUIVisualizationSettings& s, const GUIVisualizationSettings::Detail d, const Position& pos,
304
const double rot, const RGBColor& baseColor, const bool ignoreShift = false) const;
305
306
/// @brief draw left geometry point
307
void drawLeftGeometryPoint(const GUIVisualizationSettings& s, const GUIVisualizationSettings::Detail d, const Position& pos,
308
const double rot, const RGBColor& baseColor, const bool ignoreShift = false) const;
309
310
/// @brief draw right geometry point
311
void drawRightGeometryPoint(const GUIVisualizationSettings& s, const GUIVisualizationSettings::Detail d, const Position& pos,
312
const double rot, const RGBColor& baseColor, const bool ignoreShift = false) const;
313
314
/// @brief get draw position index (used in rerouters and VSS)
315
int getDrawPositionIndex() const;
316
317
/// @brief check if the given lanes are consecutive
318
static bool areLaneConsecutives(const std::vector<GNELane*>& lanes);
319
320
/// @brief check if the given lanes are connected
321
static bool areLaneConnected(const std::vector<GNELane*>& lanes);
322
323
protected:
324
/// @brief Additional Boundary (used only by additionals placed over grid)
325
Boundary myAdditionalBoundary;
326
327
/// @brief geometry to be precomputed in updateGeometry(...)
328
GUIGeometry myAdditionalGeometry;
329
330
/// @brief variable used for draw additional contours
331
GNEContour myAdditionalContour;
332
333
/// @brief name of additional
334
std::string myAdditionalName;
335
336
/// @brief pointer to special color (used for drawing Additional with a certain color, mainly used for selections)
337
const RGBColor* mySpecialColor = nullptr;
338
339
/// @name Functions relative to change values in setAttribute(...)
340
/// @{
341
342
/// @brief check if a new additional ID is valid
343
bool isValidAdditionalID(const std::string& value) const;
344
345
/// @brief check if a new additional ID is valid
346
bool isValidAdditionalID(const std::vector<SumoXMLTag>& tags, const std::string& value) const;
347
348
/// @brief check if a new detector ID is valid
349
bool isValidDetectorID(const std::string& value) const;
350
351
/// @brief check if a new detector ID is valid
352
bool isValidDetectorID(const std::vector<SumoXMLTag>& tags, const std::string& value) const;
353
354
/// @brief set additional ID
355
void setAdditionalID(const std::string& newID);
356
357
/// @}
358
359
/// @brief draw additional ID
360
void drawAdditionalID(const GUIVisualizationSettings& s) const;
361
362
/// @brief draw additional name
363
void drawAdditionalName(const GUIVisualizationSettings& s) const;
364
365
/// @brief replace additional parent edges
366
void replaceAdditionalParentEdges(const std::string& value);
367
368
/// @brief replace additional parent lanes
369
void replaceAdditionalParentLanes(const std::string& value);
370
371
/// @brief replace additional child edges
372
void replaceAdditionalChildEdges(const std::string& value);
373
374
/// @brief replace additional child lanes
375
void replaceAdditionalChildLanes(const std::string& value);
376
377
/// @brief replace additional parent
378
void replaceAdditionalParent(SumoXMLTag tag, const std::string& value, const int parentIndex);
379
380
/// @brief replace demand element parent
381
void replaceDemandElementParent(SumoXMLTag tag, const std::string& value, const int parentIndex);
382
383
/// @brief shift lane index
384
void shiftLaneIndex();
385
386
/// @brief calculate perpendicular line between lane parents
387
void calculatePerpendicularLine(const double endLaneposition);
388
389
/// @brief draw squared additional
390
void drawSquaredAdditional(const GUIVisualizationSettings& s, const Position& pos, const double size,
391
GUITexture texture, GUITexture selectedTexture) const;
392
393
/// @brief draw listed additional
394
void drawListedAdditional(const GUIVisualizationSettings& s, const Position& parentPosition, const double offsetX,
395
const double extraOffsetY, const RGBColor baseCol, const RGBColor textCol, GUITexture texture,
396
const std::string text) const;
397
398
/// @brief check if draw additional extrem geometry points
399
bool drawMovingGeometryPoints(const bool ignoreShift) const;
400
401
/// @brief draw demand element children
402
void drawDemandElementChildren(const GUIVisualizationSettings& s) const;
403
404
/// @brief get moveOperation for an element over single lane
405
GNEMoveOperation* getMoveOperationSingleLane(const double startPos, const double endPos);
406
407
/// @brief get moveOperation for an element over multi lane
408
GNEMoveOperation* getMoveOperationMultiLane(const double startPos, const double endPos);
409
410
/// @name JuPedSim values
411
/// @{
412
413
/// @brief get JuPedSim type
414
static std::string getJuPedSimType(SumoXMLTag tag);
415
416
/// @brief get JuPedSim color
417
static RGBColor getJuPedSimColor(SumoXMLTag tag);
418
419
/// @brief get JuPedSim fill
420
static bool getJuPedSimFill(SumoXMLTag tag);
421
422
/// @brief get JuPedSim color
423
static double getJuPedSimLayer(SumoXMLTag tag);
424
425
/// @}
426
427
/// @name calculate contours
428
/// @{
429
430
/// @brief calculate contour for polygons
431
void calculateContourPolygons(const GUIVisualizationSettings& s, const GUIVisualizationSettings::Detail d,
432
const double layer, const double exaggeration, const bool filledShape) const;
433
434
/// @}
435
436
private:
437
/**@brief check restriction with the number of children
438
* @throw ProcessError if is called without be reimplemented in child class
439
*/
440
virtual bool checkChildAdditionalRestriction() const;
441
442
/// @brief method for setting the attribute and nothing else (used in GNEChange_Attribute)
443
virtual void setAttribute(SumoXMLAttr key, const std::string& value) = 0;
444
445
/// @brief set move shape
446
virtual void setMoveShape(const GNEMoveResult& moveResult) = 0;
447
448
/// @brief commit move shape
449
virtual void commitMoveShape(const GNEMoveResult& moveResult, GNEUndoList* undoList) = 0;
450
451
/// @brief draw geometry point
452
void drawSemiCircleGeometryPoint(const GUIVisualizationSettings& s, const GUIVisualizationSettings::Detail d,
453
const Position& pos, const double rot, const RGBColor& baseColor,
454
const double fromAngle, const double toAngle, const bool ignoreShift) const;
455
456
/// @brief adjust listed additional text
457
std::string adjustListedAdditionalText(const std::string& text) const;
458
459
/// @brief Invalidated copy constructor.
460
GNEAdditional(const GNEAdditional&) = delete;
461
462
/// @brief Invalidated assignment operator.
463
GNEAdditional& operator=(const GNEAdditional&) = delete;
464
};
465
466