Line data Source code
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 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 22725 : 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 : * @param[in] height polygon height
59 : */
60 : TesselatedPolygon(const std::string& id, const std::string& type, const RGBColor& color, const PositionVector& shape,
61 : const bool geo, const bool fill,
62 : const double lineWidth = DEFAULT_LINEWIDTH,
63 : const double layer = DEFAULT_LAYER,
64 : const double angle = DEFAULT_ANGLE,
65 : const std::string& imgFile = DEFAULT_IMG_FILE,
66 : const std::string& name = DEFAULT_NAME,
67 : const double height = DEFAULT_HEIGHT,
68 126732 : const Parameterised::Map& parameters = DEFAULT_PARAMETERS):
69 126732 : SUMOPolygon(id, type, color, shape, geo, fill, lineWidth, layer, angle, imgFile, name, height, parameters)
70 : {}
71 :
72 : /// @brief Destructor
73 126452 : ~TesselatedPolygon() {}
74 :
75 : /// @brief perform the tesselation / drawing
76 : void drawTesselation(const PositionVector& shape) const;
77 :
78 : /// @brief id of the display list for the cached tesselation
79 : mutable std::vector<GLPrimitive> myTesselation;
80 : };
81 :
82 : /*
83 : * @class GUIPolygon
84 : * @brief The GUI-version of a polygon
85 : */
86 : class GUIPolygon : public TesselatedPolygon, public GUIGlObject_AbstractAdd {
87 :
88 : public:
89 : /** @brief Constructor
90 : * @param[in] id The name of the polygon
91 : * @param[in] type The (abstract) type of the polygon
92 : * @param[in] color The color of the polygon
93 : * @param[in] layer The layer of the polygon
94 : * @param[in] angle The rotation of the polygon
95 : * @param[in] imgFile The raster image of the polygon
96 : * @param[in] shape The shape of the polygon
97 : * @param[in] geo specify if shape was loaded as GEO
98 : * @param[in] fill Whether the polygon shall be filled
99 : * @param[in] lineWidth Line width when drawing unfilled polygon
100 : */
101 : GUIPolygon(const std::string& id, const std::string& type, const RGBColor& color, const PositionVector& shape,
102 : bool geo, bool fill, double lineWidth, double layer = 0, double angle = 0, const std::string& imgFile = "",
103 : const std::string& name = DEFAULT_NAME);
104 :
105 : /// @brief Destructor
106 : ~GUIPolygon();
107 :
108 : /// @name inherited from GUIGlObject
109 : //@{
110 :
111 : /** @brief Returns an own popup-menu
112 : *
113 : * @param[in] app The application needed to build the popup-menu
114 : * @param[in] parent The parent window needed to build the popup-menu
115 : * @return The built popup-menu
116 : * @see GUIGlObject::getPopUpMenu
117 : */
118 : GUIGLObjectPopupMenu* getPopUpMenu(GUIMainWindow& app, GUISUMOAbstractView& parent) override;
119 :
120 : /** @brief Returns an own parameter window
121 : *
122 : * @param[in] app The application needed to build the parameter window
123 : * @param[in] parent The parent window needed to build the parameter window
124 : * @return The built parameter window
125 : * @see GUIGlObject::getParameterWindow
126 : */
127 : GUIParameterTableWindow* getParameterWindow(GUIMainWindow& app, GUISUMOAbstractView& parent) override;
128 :
129 : /// @brief return exaggeration associated with this GLObject
130 : double getExaggeration(const GUIVisualizationSettings& s) const override;
131 :
132 : /** @brief Returns the boundary to which the view shall be centered in order to show the object
133 : *
134 : * @return The boundary the object is within
135 : * @see GUIGlObject::getCenteringBoundary
136 : */
137 : Boundary getCenteringBoundary() const override;
138 :
139 : /** @brief Draws the object
140 : * @param[in] s The settings for the current view (may influence drawing)
141 : * @see GUIGlObject::drawGL
142 : */
143 : virtual void drawGL(const GUIVisualizationSettings& s) const override;
144 :
145 0 : double getClickPriority() const override {
146 0 : return getShapeLayer();
147 : }
148 :
149 : /// @brief Returns the name of the object (default "")
150 0 : virtual const std::string getOptionalName() const override {
151 0 : return getShapeName();
152 : }
153 : //@}
154 :
155 : /// @brief set a new shape and update the tesselation
156 : virtual void setShape(const PositionVector& shape) override;
157 :
158 : /** @brief Sets a new angle in navigational degrees
159 : * @param[in] layer The new angle to use
160 : */
161 0 : virtual void setShapeNaviDegree(const double angle) override {
162 0 : SUMOPolygon::setShapeNaviDegree(angle);
163 0 : if (angle != 0.) {
164 0 : setShape(myShape);
165 : }
166 0 : }
167 :
168 : /// @brief set color
169 : static RGBColor setColor(const GUIVisualizationSettings& s, const SUMOPolygon* polygon, const GUIGlObject* o, bool disableSelectionColor, int alphaOverride);
170 :
171 : /// @brief check if Polygon can be drawn
172 : static bool checkDraw(const GUIVisualizationSettings& s, const SUMOPolygon* polygon, const GUIGlObject* o);
173 :
174 : /// @brief draw inner Polygon (before pushName() )
175 : static void drawInnerPolygon(const GUIVisualizationSettings& s, const TesselatedPolygon* polygon, const GUIGlObject* o,
176 : const PositionVector shape, const double layer, const bool fill,
177 : const bool disableSelectionColor = false,
178 : const int alphaOverride = -1,
179 : const bool disableText = false);
180 :
181 : inline void activate(bool isActive) {
182 116 : myIsActive = isActive;
183 : }
184 :
185 : inline bool isActive(void) const {
186 : return myIsActive;
187 : }
188 :
189 : private:
190 : /// The mutex used to avoid concurrent updates of the shape
191 : mutable FXMutex myLock;
192 :
193 : /// @brief shape rotated on the centroid, if rotation is needed, nullptr otherwise
194 : PositionVector* myRotatedShape;
195 :
196 : /// @brief Is the polygon will be drawn or not
197 : bool myIsActive;
198 : };
|