Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
eclipse
GitHub Repository: eclipse/sumo
Path: blob/main/src/netedit/elements/additional/GNEPoly.h
193674 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 GNEPoly.h
15
/// @author Pablo Alvarez Lopez
16
/// @date Jun 2017
17
///
18
// A class for visualizing and editing POIS in netedit (adapted from
19
// GUIPolygon and NLHandler)
20
/****************************************************************************/
21
#pragma once
22
#include <config.h>
23
24
#include <utils/gui/globjects/GUIPolygon.h>
25
#include <utils/xml/CommonXMLStructure.h>
26
27
#include "GNEAdditional.h"
28
29
// ===========================================================================
30
// class declarations
31
// ===========================================================================
32
33
class GeoConvHelper;
34
class GNEMoveElementShape;
35
class GNENetworkElement;
36
37
// ===========================================================================
38
// class definitions
39
// ===========================================================================
40
41
class GNEPoly : public TesselatedPolygon, public GNEAdditional {
42
43
public:
44
/// @brief needed to avoid diamond problem between SUMOPolygon and GNEAdditional
45
using GNEAdditional::getID;
46
47
/// @brief default Constructor
48
GNEPoly(SumoXMLTag tag, GNENet* net);
49
50
/** @brief Constructor for polygons
51
* @param[in] id The name of the polygon
52
* @param[in] net net in which this polygon is placed
53
* @param[in] fileBucket file in which this element is stored
54
* @param[in] type The (abstract) type of the polygon
55
* @param[in] shape The shape of the polygon
56
* @param[in] geo specify if shape was loaded as GEO
57
* @param[in] color The color of the polygon
58
* @param[in] layer The layer of the polygon
59
* @param[in] angle The rotation of the polygon
60
* @param[in] imgFile The raster image of the polygon
61
* @param[in] fill Whether the polygon shall be filled
62
* @param[in] lineWidth Line width when drawing unfilled polygon
63
* @param[in] name Poly's name
64
* @param[in] parameters generic parameters
65
*/
66
GNEPoly(const std::string& id, GNENet* net, FileBucket* fileBucket, const std::string& type, const PositionVector& shape,
67
bool geo, bool fill, double lineWidth, const RGBColor& color, double layer, double angle, const std::string& imgFile,
68
const std::string& name, const Parameterised::Map& parameters);
69
70
/** @brief Constructor for JuPedSim elements
71
* @param[in] id The name of the polygon
72
* @param[in] net net in which this polygon is placed
73
* @param[in] fileBucket file in which this element is stored
74
* @param[in] shape The shape of the polygon
75
* @param[in] geo specify if shape was loaded as GEO
76
* @param[in] name Poly's name
77
* @param[in] parameters generic parameters
78
*/
79
GNEPoly(SumoXMLTag tag, const std::string& id, GNENet* net, FileBucket* fileBucket, const PositionVector& shape,
80
bool geo, const std::string& name, const Parameterised::Map& parameters);
81
82
/// @brief Destructor
83
~GNEPoly();
84
85
/// @brief methods to retrieve the elements linked to this poly
86
/// @{
87
88
/// @brief get GNEMoveElement associated with this poly
89
GNEMoveElement* getMoveElement() const override;
90
91
/// @brief get parameters associated with this poly
92
Parameterised* getParameters() override;
93
94
/// @brief get parameters associated with this poly (constant)
95
const Parameterised* getParameters() const override;
96
97
/// @}
98
99
/// @brief gererate a new ID for an element child
100
std::string generateChildID(SumoXMLTag childTag);
101
102
/// @name inherited from GNEAdditional
103
/// @{
104
/// @brief update pre-computed geometry information
105
void updateGeometry() override;
106
107
/// @brief Returns position of shape in view
108
Position getPositionInView() const override;
109
110
/// @brief return exaggeration associated with this GLObject
111
double getExaggeration(const GUIVisualizationSettings& s) const override;
112
113
/// @brief update centering boundary (implies change in RTREE)
114
void updateCenteringBoundary(const bool updateGrid) override;
115
116
/// @brief split geometry
117
void splitEdgeGeometry(const double splitPosition, const GNENetworkElement* originalElement,
118
const GNENetworkElement* newElement, GNEUndoList* undoList) override;
119
120
/**@brief write additional element into a xml file
121
* @param[in] device device in which write parameters of additional element
122
*/
123
void writeAdditional(OutputDevice& device) const override;
124
125
/// @brief check if current additional is valid to be written into XML (must be reimplemented in all detector children)
126
bool isAdditionalValid() const override;
127
128
/// @brief return a string with the current additional problem (must be reimplemented in all detector children)
129
std::string getAdditionalProblem() const override;
130
131
/// @brief fix additional problem (must be reimplemented in all detector children)
132
void fixAdditionalProblem() override;
133
134
/// @brief Returns the numerical id of the object
135
GUIGlID getGlID() const;
136
137
/// @}
138
139
/// @name Function related with contour drawing
140
/// @{
141
142
/// @brief check if draw move contour (red)
143
bool checkDrawMoveContour() const override;
144
145
/// @}
146
147
/// @name inherited from GUIGlObject
148
/// @{
149
/**@brief Returns the name of the parent object
150
* @return This object's parent id
151
*/
152
std::string getParentName() const override;
153
154
/**@brief Returns an own popup-menu
155
*
156
* @param[in] app The application needed to build the popup-menu
157
* @param[in] parent The parent window needed to build the popup-menu
158
* @return The built popup-menu
159
* @see GUIGlObject::getPopUpMenu
160
*/
161
GUIGLObjectPopupMenu* getPopUpMenu(GUIMainWindow& app, GUISUMOAbstractView& parent) override;
162
163
/**@brief Draws the object
164
* @param[in] s The settings for the current view (may influence drawing)
165
* @see GUIGlObject::drawGL
166
*/
167
void drawGL(const GUIVisualizationSettings& s) const override;
168
169
/// @}
170
171
/// @name inherited from GNEAttributeCarrier
172
/// @{
173
/* @brief method for getting the Attribute of an XML key
174
* @param[in] key The attribute key
175
* @return string with the value associated to key
176
*/
177
std::string getAttribute(SumoXMLAttr key) const override;
178
179
/* @brief method for getting the Attribute of an XML key in double format
180
* @param[in] key The attribute key
181
* @return double with the value associated to key
182
*/
183
double getAttributeDouble(SumoXMLAttr key) const override;
184
185
/* @brief method for getting the Attribute of an XML key in position format
186
* @param[in] key The attribute key
187
* @return position with the value associated to key
188
*/
189
Position getAttributePosition(SumoXMLAttr key) const override;
190
191
/* @brief method for getting the Attribute of an XML key in positionVector format
192
* @param[in] key The attribute key
193
* @return positionVector with the value associated to key
194
*/
195
PositionVector getAttributePositionVector(SumoXMLAttr key) const override;
196
197
/**@brief method for setting the attribute and letting the object perform additional changes
198
* @param[in] key The attribute key
199
* @param[in] value The new value
200
* @param[in] undoList The undoList on which to register changes
201
*/
202
void setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) override;
203
204
/**@brief method for checking if the key and their conrrespond attribute are valids
205
* @param[in] key The attribute key
206
* @param[in] value The value associated to key key
207
* @return true if the value is valid, false in other case
208
*/
209
bool isValid(SumoXMLAttr key, const std::string& value) override;
210
211
/* @brief method for check if the value for certain attribute is set
212
* @param[in] key The attribute key
213
*/
214
bool isAttributeEnabled(SumoXMLAttr key) const override;
215
/// @}
216
217
/// @brief get PopPup ID (Used in AC Hierarchy)
218
std::string getPopUpID() const override;
219
220
/// @brief get Hierarchy Name (Used in AC Hierarchy)
221
std::string getHierarchyName() const override;
222
223
/**@brief return index of a vertex of shape, or of a new vertex if position is over an shape's edge
224
* @param pos position of new/existent vertex
225
* @param snapToGrid enable or disable snapToActiveGrid
226
* @return index of position vector
227
*/
228
int getVertexIndex(Position pos, bool snapToGrid);
229
230
/// @brief delete the geometry point closest to the given pos
231
void deleteGeometryPoint(const Position& pos, bool allowUndo = true);
232
233
/// @brief check if polygon is closed
234
bool isPolygonClosed() const;
235
236
/// @brief open polygon
237
void openPolygon(bool allowUndo = true);
238
239
/// @brief close polygon
240
void closePolygon(bool allowUndo = true);
241
242
/// @brief change first geometry point
243
void changeFirstGeometryPoint(int oldIndex, bool allowUndo = true);
244
245
/// @brief replace the current shape with a rectangle
246
void simplifyShape(bool allowUndo = true);
247
248
/// @brief get SUMOBaseObject with all polygon attributes
249
CommonXMLStructure::SumoBaseObject* getSumoBaseObject() const;
250
251
protected:
252
/// @brief move element shape
253
GNEMoveElementShape* myMoveElementShape = nullptr;
254
255
/// @brief Latitude of Polygon
256
PositionVector myGeoShape;
257
258
/// @brief flag to indicate if polygon is closed
259
bool myClosedShape = false;
260
261
/// @brief flag to indicate if polygon is simplified
262
bool mySimplifiedShape = false;
263
264
private:
265
/// @brief set attribute after validation
266
void setAttribute(SumoXMLAttr key, const std::string& value) override;
267
268
/// @brief draw polygon
269
void drawPolygon(const GUIVisualizationSettings& s, const GUIVisualizationSettings::Detail d,
270
const RGBColor& color, const double exaggeration) const;
271
272
/// @brief draw contour
273
void drawPolygonContour(const GUIVisualizationSettings& s, const GUIVisualizationSettings::Detail d,
274
const RGBColor& color, const double exaggeration) const;
275
276
/// @brief draw geometry points
277
void drawGeometryPoints(const GUIVisualizationSettings& s, const GUIVisualizationSettings::Detail d,
278
const RGBColor& color, const double exaggeration) const;
279
280
/// @brief draw polygon name and type
281
void drawPolygonNameAndType(const GUIVisualizationSettings& s) const;
282
283
/// @brief Invalidated copy constructor.
284
GNEPoly(const GNEPoly&) = delete;
285
286
/// @brief Invalidated assignment operator.
287
GNEPoly& operator=(const GNEPoly&) = delete;
288
};
289
290