Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
eclipse
GitHub Repository: eclipse/sumo
Path: blob/main/src/netedit/elements/additional/GNEAdditional.h
193904 views
1
/****************************************************************************/
2
// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3
// Copyright (C) 2001-2026 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/GNEPathElement.h>
27
#include <netedit/elements/moving/GNEMoveElement.h>
28
#include <utils/gui/div/GUIGeometry.h>
29
#include <utils/gui/globjects/GUIGlObject.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 {
43
44
public:
45
/// @brief declare friend class
46
friend class GNEAdditionalListed;
47
friend class GNEAdditionalSquared;
48
49
/**@brief Constructor for templates
50
* @param[in] tag SUMO Tag assigned to this type of object
51
* @param[in] net GNENet in which this AttributeCarrier is stored
52
*/
53
GNEAdditional(GNENet* net, SumoXMLTag tag);
54
55
/**@brief Constructor
56
* @param[in] id Gl-id of the additional element (Must be unique)
57
* @param[in] tag SUMO Tag assigned to this type of object
58
* @param[in] net GNENet in which this AttributeCarrier is stored
59
* @param[in] fileBucket bucket in which this AttributeCarrier is stored
60
* @param[in] name Additional name
61
*/
62
GNEAdditional(const std::string& id, GNENet* net, SumoXMLTag tag, FileBucket* fileBucket, const std::string& name);
63
64
/**@brief Constructor for additional with parents
65
* @param[in] additionalParent pointer to additional parent
66
* @param[in] tag Type of xml tag that define the additional element (SUMO_TAG_BUS_STOP, SUMO_TAG_REROUTER, etc...)
67
* @param[in] name Additional name
68
*/
69
GNEAdditional(GNEAdditional* additionalParent, SumoXMLTag tag, const std::string& name);
70
71
/// @brief Destructor
72
~GNEAdditional();
73
74
/// @brief methods to retrieve the elements linked to this additional
75
/// @{
76
77
/// @brief get GNEHierarchicalElement associated with this additional
78
GNEHierarchicalElement* getHierarchicalElement() override;
79
80
/// @brief get GUIGlObject associated with this additional
81
GUIGlObject* getGUIGlObject() override;
82
83
/// @brief get GUIGlObject associated with this additional (constant)
84
const GUIGlObject* getGUIGlObject() const override;
85
86
/// @}
87
88
/// @brief get reference to fileBucket in which save this AC
89
FileBucket* getFileBucket() const override;
90
91
/// @brief Returns the name of the object (default "")
92
virtual const std::string getOptionalName() const override;
93
94
/// @brief obtain additional geometry
95
const GUIGeometry& getAdditionalGeometry() const;
96
97
/// @brief set special color
98
void setSpecialColor(const RGBColor* color);
99
100
/// @brief reset additional contour
101
void resetAdditionalContour();
102
103
/// @name members and functions relative to write additionals into XML
104
/// @{
105
106
/**@brief write additional element into a xml file
107
* @param[in] device device in which write parameters of additional element
108
*/
109
virtual void writeAdditional(OutputDevice& device) const = 0;
110
111
/// @brief check if current additional is valid to be written into XML (by default true, can be reimplemented in children)
112
virtual bool isAdditionalValid() const = 0;
113
114
/// @brief return a string with the current additional problem (by default empty, can be reimplemented in children)
115
virtual std::string getAdditionalProblem() const = 0;
116
117
/// @brief fix additional problem (by default throw an exception, has to be reimplemented in children)
118
virtual void fixAdditionalProblem() = 0;
119
120
/// @}
121
122
/// @name functions related with geometry
123
/// @{
124
125
/**@brief open Additional Dialog
126
* @note: if additional needs an additional dialog, this function has to be implemented in childrens (see GNERerouter and GNEVariableSpeedSign)
127
* @throw invalid argument if additional doesn't have an additional Dialog
128
*/
129
virtual void openAdditionalDialog(FXWindow* restoringFocusWindow);
130
131
/// @brief Returns position of additional in view
132
virtual Position getPositionInView() const = 0;
133
134
/// @brief return exaggeration associated with this GLObject
135
double getExaggeration(const GUIVisualizationSettings& s) const override;
136
137
/// @brief Returns the boundary to which the view shall be centered in order to show the object
138
Boundary getCenteringBoundary() const override;
139
140
/// @brief update centering boundary (implies change in RTREE)
141
virtual void updateCenteringBoundary(const bool updateGrid) = 0;
142
143
/// @brief split geometry
144
virtual void splitEdgeGeometry(const double splitPosition, const GNENetworkElement* originalElement, const GNENetworkElement* newElement, GNEUndoList* undoList) = 0;
145
146
/// @}
147
148
/// @name Function related with contour drawing
149
/// @{
150
151
/// @brief check if draw from contour (green)
152
bool checkDrawFromContour() const override;
153
154
/// @brief check if draw from contour (magenta)
155
bool checkDrawToContour() const override;
156
157
/// @brief check if draw related contour (cyan)
158
bool checkDrawRelatedContour() const override;
159
160
/// @brief check if draw over contour (orange)
161
bool checkDrawOverContour() const override;
162
163
/// @brief check if draw delete contour (pink/white)
164
bool checkDrawDeleteContour() const override;
165
166
/// @brief check if draw delete contour small (pink/white)
167
bool checkDrawDeleteContourSmall() const override;
168
169
/// @brief check if draw select contour (blue)
170
bool checkDrawSelectContour() const override;
171
172
/// @}
173
174
/// @name inherited from GUIGlObject
175
/// @{
176
177
/**@brief Returns an own popup-menu
178
*
179
* @param[in] app The application needed to build the popup-menu
180
* @param[in] parent The parent window needed to build the popup-menu
181
* @return The built popup-menu
182
* @see GUIGlObject::getPopUpMenu
183
*/
184
virtual GUIGLObjectPopupMenu* getPopUpMenu(GUIMainWindow& app, GUISUMOAbstractView& parent) override;
185
186
/**@brief Returns an own parameter window
187
*
188
* @param[in] app The application needed to build the parameter window
189
* @param[in] parent The parent window needed to build the parameter window
190
* @return The built parameter window
191
* @see GUIGlObject::getParameterWindow
192
*/
193
GUIParameterTableWindow* getParameterWindow(GUIMainWindow& app, GUISUMOAbstractView& parent) override;
194
195
/// @brief Returns the additional name
196
const std::string& getOptionalAdditionalName() const;
197
198
/// @brief check if element is locked
199
bool isGLObjectLocked() const override;
200
201
/// @brief mark element as front element
202
void markAsFrontElement() override;
203
204
/// @brief delete element
205
void deleteGLObject() override;
206
207
/// @brief select element
208
void selectGLObject() override;
209
210
/// @brief update GLObject (geometry, ID, etc.)
211
void updateGLObject() override;
212
213
/// @}
214
215
/// @name inherited from GNEPathElement
216
/// @{
217
218
/// @brief compute pathElement
219
virtual void computePathElement() override;
220
221
/// @brief check if path element is selected
222
bool isPathElementSelected() const override;
223
224
/**@brief Draws partial object over lane
225
* @param[in] s The settings for the current view (may influence drawing)
226
* @param[in] segment lane segment
227
* @param[in] offsetFront front offset
228
*/
229
virtual void drawLanePartialGL(const GUIVisualizationSettings& s, const GNESegment* segment, const double offsetFront) const override;
230
231
/**@brief Draws partial object over junction
232
* @param[in] s The settings for the current view (may influence drawing)
233
* @param[in] segment junction segment
234
* @param[in] offsetFront front offset
235
*/
236
virtual void drawJunctionPartialGL(const GUIVisualizationSettings& s, const GNESegment* segment, const double offsetFront) const override;
237
238
/// @brief get first path lane
239
GNELane* getFirstPathLane() const override;
240
241
/// @brief get last path lane
242
GNELane* getLastPathLane() const override;
243
244
/// @}
245
246
/// @brief draw parent and child lines
247
void drawParentChildLines(const GUIVisualizationSettings& s, const RGBColor& color, const bool onlySymbols = false) const;
248
249
/// @brief draw up geometry point
250
void drawUpGeometryPoint(const GUIVisualizationSettings& s, const GUIVisualizationSettings::Detail d, const Position& pos,
251
const double rot, const RGBColor& baseColor, const bool ignoreShift = false) const;
252
253
/// @brief draw down geometry point
254
void drawDownGeometryPoint(const GUIVisualizationSettings& s, const GUIVisualizationSettings::Detail d, const Position& pos,
255
const double rot, const RGBColor& baseColor, const bool ignoreShift = false) const;
256
257
/// @brief draw left geometry point
258
void drawLeftGeometryPoint(const GUIVisualizationSettings& s, const GUIVisualizationSettings::Detail d, const Position& pos,
259
const double rot, const RGBColor& baseColor, const bool ignoreShift = false) const;
260
261
/// @brief draw right geometry point
262
void drawRightGeometryPoint(const GUIVisualizationSettings& s, const GUIVisualizationSettings::Detail d, const Position& pos,
263
const double rot, const RGBColor& baseColor, const bool ignoreShift = false) const;
264
265
/// @brief check if the given lanes are consecutive
266
static bool areLaneConsecutives(const std::vector<GNELane*>& lanes);
267
268
/// @brief check if the given lanes are connected
269
static bool areLaneConnected(const std::vector<GNELane*>& lanes);
270
271
protected:
272
/// @brief Additional Boundary (used only by additionals placed over grid)
273
Boundary myAdditionalBoundary;
274
275
/// @brief geometry to be precomputed in updateGeometry(...)
276
GUIGeometry myAdditionalGeometry;
277
278
/// @brief variable used for draw additional contours
279
GNEContour myAdditionalContour;
280
281
/// @brief name of additional
282
std::string myAdditionalName;
283
284
/// @brief pointer to special color (used for drawing Additional with a certain color, mainly used for selections)
285
const RGBColor* mySpecialColor = nullptr;
286
287
/// @brief write common additional attributes
288
void writeAdditionalAttributes(OutputDevice& device) const;
289
290
/// @name Functions relative to change values in setAttribute(...)
291
/// @{
292
293
/// @brief check if a new additional ID is valid
294
bool isValidAdditionalID(const std::string& value) const;
295
296
/// @brief check if a new additional ID is valid
297
bool isValidAdditionalID(const std::vector<SumoXMLTag>& tags, const std::string& value) const;
298
299
/// @brief check if a new detector ID is valid
300
bool isValidDetectorID(const std::string& value) const;
301
302
/// @brief check if a new detector ID is valid
303
bool isValidDetectorID(const std::vector<SumoXMLTag>& tags, const std::string& value) const;
304
305
/// @brief set additional ID
306
void setAdditionalID(const std::string& newID);
307
308
/// @}
309
310
/// @brief draw additional ID
311
void drawAdditionalID(const GUIVisualizationSettings& s) const;
312
313
/// @brief draw additional name
314
void drawAdditionalName(const GUIVisualizationSettings& s) const;
315
316
/// @brief replace additional parent edges
317
void replaceAdditionalParentEdges(const std::string& value);
318
319
/// @brief replace additional parent lanes
320
void replaceAdditionalParentLanes(const std::string& value);
321
322
/// @brief replace additional child edges
323
void replaceAdditionalChildEdges(const std::string& value);
324
325
/// @brief replace additional child lanes
326
void replaceAdditionalChildLanes(const std::string& value);
327
328
/// @brief replace additional parent
329
void replaceAdditionalParent(SumoXMLTag tag, const std::string& value, const int parentIndex);
330
331
/// @brief replace demand element parent
332
void replaceDemandElementParent(SumoXMLTag tag, const std::string& value, const int parentIndex);
333
334
/// @brief shift lane index
335
void shiftLaneIndex();
336
337
/// @brief calculate perpendicular line between lane parents
338
void calculatePerpendicularLine(const double endLaneposition);
339
340
/// @brief draw demand element children
341
void drawDemandElementChildren(const GUIVisualizationSettings& s) const;
342
343
/// @name JuPedSim values
344
/// @{
345
346
/// @brief get JuPedSim type
347
static std::string getJuPedSimType(SumoXMLTag tag);
348
349
/// @brief get JuPedSim color
350
static RGBColor getJuPedSimColor(SumoXMLTag tag);
351
352
/// @brief get JuPedSim fill
353
static bool getJuPedSimFill(SumoXMLTag tag);
354
355
/// @brief get JuPedSim color
356
static double getJuPedSimLayer(SumoXMLTag tag);
357
358
/// @}
359
360
/// @name calculate contours
361
/// @{
362
363
/// @brief calculate contour for polygons
364
void calculateContourPolygons(const GUIVisualizationSettings& s, const GUIVisualizationSettings::Detail d,
365
const double layer, const double exaggeration, const bool filledShape) const;
366
367
/// @}
368
369
private:
370
/**@brief check restriction with the number of children
371
* @throw ProcessError if is called without be reimplemented in child class
372
*/
373
virtual bool checkChildAdditionalRestriction() const;
374
375
/// @brief draw geometry point
376
void drawSemiCircleGeometryPoint(const GUIVisualizationSettings& s, const GUIVisualizationSettings::Detail d,
377
const Position& pos, const double rot, const RGBColor& baseColor,
378
const double fromAngle, const double toAngle, const bool ignoreShift) const;
379
380
/// @brief Invalidated copy constructor.
381
GNEAdditional(const GNEAdditional&) = delete;
382
383
/// @brief Invalidated assignment operator.
384
GNEAdditional& operator=(const GNEAdditional&) = delete;
385
};
386
387