Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
eclipse
GitHub Repository: eclipse/sumo
Path: blob/main/src/utils/gui/globjects/GUIPolygon.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 GUIPolygon.h
15
/// @author Daniel Krajzewicz
16
/// @author Jakob Erdmann
17
/// @author Michael Behrisch
18
/// @date June 2006
19
///
20
// The GUI-version of a polygon
21
/****************************************************************************/
22
#pragma once
23
#include <config.h>
24
25
#include <string>
26
#include <utils/shapes/SUMOPolygon.h>
27
#include <utils/gui/globjects/GUIGlObject_AbstractAdd.h>
28
#include <utils/gui/globjects/GLIncludes.h>
29
#include <utils/gui/settings/GUIVisualizationSettings.h>
30
31
32
// ===========================================================================
33
// class definitions
34
// ===========================================================================
35
36
/// @brief most likely I'm reinventing the wheel here
37
struct GLPrimitive {
38
GLenum type;
39
std::vector<Position> vert;
40
};
41
42
43
class TesselatedPolygon : public SUMOPolygon {
44
45
public:
46
47
/**@brief Constructor
48
* @param[in] id The name of the polygon
49
* @param[in] type The (abstract) type of the polygon
50
* @param[in] color The color of the polygon
51
* @param[in] layer The layer of the polygon
52
* @param[in] angle The rotation of the polygon
53
* @param[in] imgFile The raster image of the polygon
54
* @param[in] shape The shape of the polygon
55
* @param[in] geo specify if shape was loaded as GEO
56
* @param[in] fill Whether the polygon shall be filled
57
* @param[in] lineWidth Line width when drawing unfilled polygon
58
*/
59
TesselatedPolygon(const std::string& id, const std::string& type, const RGBColor& color, const PositionVector& shape,
60
bool geo, bool fill, double lineWidth, double layer = 0, double angle = 0, const std::string& imgFile = "",
61
const std::string& name = DEFAULT_NAME, const Parameterised::Map& parameters = DEFAULT_PARAMETERS):
62
SUMOPolygon(id, type, color, shape, geo, fill, lineWidth, layer, angle, imgFile, name, parameters)
63
{}
64
65
/// @brief Destructor
66
~TesselatedPolygon() {}
67
68
/// @brief perform the tesselation / drawing
69
void drawTesselation(const PositionVector& shape) const;
70
71
/// @brief id of the display list for the cached tesselation
72
mutable std::vector<GLPrimitive> myTesselation;
73
};
74
75
/*
76
* @class GUIPolygon
77
* @brief The GUI-version of a polygon
78
*/
79
class GUIPolygon : public TesselatedPolygon, public GUIGlObject_AbstractAdd {
80
81
public:
82
/** @brief Constructor
83
* @param[in] id The name of the polygon
84
* @param[in] type The (abstract) type of the polygon
85
* @param[in] color The color of the polygon
86
* @param[in] layer The layer of the polygon
87
* @param[in] angle The rotation of the polygon
88
* @param[in] imgFile The raster image of the polygon
89
* @param[in] shape The shape of the polygon
90
* @param[in] geo specify if shape was loaded as GEO
91
* @param[in] fill Whether the polygon shall be filled
92
* @param[in] lineWidth Line width when drawing unfilled polygon
93
*/
94
GUIPolygon(const std::string& id, const std::string& type, const RGBColor& color, const PositionVector& shape,
95
bool geo, bool fill, double lineWidth, double layer = 0, double angle = 0, const std::string& imgFile = "",
96
const std::string& name = DEFAULT_NAME);
97
98
/// @brief Destructor
99
~GUIPolygon();
100
101
/// @name inherited from GUIGlObject
102
//@{
103
104
/** @brief Returns an own popup-menu
105
*
106
* @param[in] app The application needed to build the popup-menu
107
* @param[in] parent The parent window needed to build the popup-menu
108
* @return The built popup-menu
109
* @see GUIGlObject::getPopUpMenu
110
*/
111
GUIGLObjectPopupMenu* getPopUpMenu(GUIMainWindow& app, GUISUMOAbstractView& parent) override;
112
113
/** @brief Returns an own parameter window
114
*
115
* @param[in] app The application needed to build the parameter window
116
* @param[in] parent The parent window needed to build the parameter window
117
* @return The built parameter window
118
* @see GUIGlObject::getParameterWindow
119
*/
120
GUIParameterTableWindow* getParameterWindow(GUIMainWindow& app, GUISUMOAbstractView& parent) override;
121
122
/// @brief return exaggeration associated with this GLObject
123
double getExaggeration(const GUIVisualizationSettings& s) const override;
124
125
/** @brief Returns the boundary to which the view shall be centered in order to show the object
126
*
127
* @return The boundary the object is within
128
* @see GUIGlObject::getCenteringBoundary
129
*/
130
Boundary getCenteringBoundary() const override;
131
132
/** @brief Draws the object
133
* @param[in] s The settings for the current view (may influence drawing)
134
* @see GUIGlObject::drawGL
135
*/
136
virtual void drawGL(const GUIVisualizationSettings& s) const override;
137
138
double getClickPriority() const override {
139
return getShapeLayer();
140
}
141
142
/// @brief Returns the name of the object (default "")
143
virtual const std::string getOptionalName() const override {
144
return getShapeName();
145
}
146
//@}
147
148
/// @brief set a new shape and update the tesselation
149
virtual void setShape(const PositionVector& shape) override;
150
151
/** @brief Sets a new angle in navigational degrees
152
* @param[in] layer The new angle to use
153
*/
154
virtual void setShapeNaviDegree(const double angle) override {
155
SUMOPolygon::setShapeNaviDegree(angle);
156
if (angle != 0.) {
157
setShape(myShape);
158
}
159
}
160
161
/// @brief set color
162
static RGBColor setColor(const GUIVisualizationSettings& s, const SUMOPolygon* polygon, const GUIGlObject* o, bool disableSelectionColor, int alphaOverride);
163
164
/// @brief check if Polygon can be drawn
165
static bool checkDraw(const GUIVisualizationSettings& s, const SUMOPolygon* polygon, const GUIGlObject* o);
166
167
/// @brief draw inner Polygon (before pushName() )
168
static void drawInnerPolygon(const GUIVisualizationSettings& s, const TesselatedPolygon* polygon, const GUIGlObject* o,
169
const PositionVector shape, const double layer, const bool fill,
170
const bool disableSelectionColor = false,
171
const int alphaOverride = -1,
172
const bool disableText = false);
173
174
inline void activate(bool isActive) {
175
myIsActive = isActive;
176
}
177
178
inline bool isActive(void) const {
179
return myIsActive;
180
}
181
182
private:
183
/// The mutex used to avoid concurrent updates of the shape
184
mutable FXMutex myLock;
185
186
/// @brief shape rotated on the centroid, if rotation is needed, nullptr otherwise
187
PositionVector* myRotatedShape;
188
189
/// @brief Is the polygon will be drawn or not
190
bool myIsActive;
191
};
192
193