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