Line data Source code
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 GUIGlObject.h
15 : /// @author Daniel Krajzewicz
16 : /// @author Jakob Erdmann
17 : /// @author Michael Behrisch
18 : /// @author Laura Bieker
19 : /// @date Oct 2002
20 : ///
21 : // Base class for all objects that may be displayed within the openGL-gui
22 : /****************************************************************************/
23 : #pragma once
24 : #include <config.h>
25 :
26 : #include <string>
27 : #include <set>
28 :
29 : #include <utils/geom/Boundary.h>
30 : #include <utils/common/StdDefs.h>
31 : #include <utils/common/StringUtils.h>
32 : #include <utils/common/StringBijection.h>
33 : #include <utils/common/RGBColor.h>
34 : #include <utils/foxtools/fxheader.h>
35 : #include <utils/xml/SUMOXMLDefinitions.h>
36 :
37 : #include "GUIGlObjectTypes.h"
38 :
39 :
40 : // ===========================================================================
41 : // definitions
42 : // ===========================================================================
43 :
44 : typedef unsigned int GUIGlID;
45 :
46 : // ===========================================================================
47 : // class declarations
48 : // ===========================================================================
49 :
50 : class GUIGlObjectStorage;
51 : class GUIParameterTableWindow;
52 : class GUIMainWindow;
53 : class GUIGLObjectPopupMenu;
54 : class GUISUMOAbstractView;
55 : class GUIVisualizationSettings;
56 : struct GUIVisualizationTextSettings;
57 :
58 : #ifdef HAVE_OSG
59 : namespace osg {
60 : class Node;
61 : }
62 : #endif
63 :
64 : // ===========================================================================
65 : // class definitions
66 : // ===========================================================================
67 :
68 : class GUIGlObject {
69 :
70 : public:
71 : /// @brief associates object types with strings
72 : static StringBijection<GUIGlObjectType> TypeNames;
73 : static const GUIGlID INVALID_ID;
74 : static const double INVALID_PRIORITY;
75 :
76 : /** @brief Constructor
77 : *
78 : * This is the standard constructor that assures that the object is known
79 : * and its id is unique. Use it always :-)
80 : *
81 : * @param[in] type The GUIGlObjectType type
82 : * @param[in] microsimID unique ID
83 : * @param[in] icon optional icon associated with this GUIGLObject
84 : * @see GUIGlObjectStorage
85 : */
86 : GUIGlObject(GUIGlObjectType type, const std::string& microsimID, FXIcon* icon);
87 :
88 : /// @brief Destructor
89 : virtual ~GUIGlObject();
90 :
91 : /// @name getter methods
92 : /// @{
93 : /// @brief Returns the full name appearing in the tool tip
94 : /// @return This object's typed id
95 : inline const std::string& getFullName() const {
96 3347618 : return myFullName;
97 : }
98 :
99 : /// @brief Returns the name of the parent object (if any)
100 : /// @return This object's parent id
101 : virtual std::string getParentName() const;
102 :
103 : /// @brief Returns the numerical id of the object
104 : /// @return This object's gl-id
105 : inline GUIGlID getGlID() const {
106 136413270 : return myGlID;
107 : }
108 :
109 : /// @brief get icon associated with this GL Object
110 : FXIcon* getGLIcon() const;
111 :
112 : /// @}
113 :
114 : /// @name interfaces to be implemented by derived classes
115 : /// @{
116 : /** @brief Returns an own popup-menu
117 : *
118 : * @param[in] app The application needed to build the popup-menu
119 : * @param[in] parent The parent window needed to build the popup-menu
120 : * @return The built popup-menu
121 : */
122 : virtual GUIGLObjectPopupMenu* getPopUpMenu(GUIMainWindow& app, GUISUMOAbstractView& parent) = 0;
123 :
124 : /// @brief notify object about popup menu removal
125 0 : virtual void removedPopupMenu() {}
126 :
127 : /** @brief Returns an own parameter window
128 : *
129 : * @param[in] app The application needed to build the parameter window
130 : * @param[in] parent The parent window needed to build the parameter window
131 : * @return The built parameter window
132 : */
133 : virtual GUIParameterTableWindow* getParameterWindow(GUIMainWindow& app, GUISUMOAbstractView& parent) = 0;
134 :
135 : /** @brief Returns an own type parameter window (optional)
136 : *
137 : * @param[in] app The application needed to build the parameter window
138 : * @param[in] parent The parent window needed to build the parameter window
139 : * @return The built parameter window
140 : */
141 : virtual GUIParameterTableWindow* getTypeParameterWindow(GUIMainWindow& app, GUISUMOAbstractView& parent);
142 :
143 : /// @brief Returns the id of the object as known to microsim
144 : inline const std::string& getMicrosimID() const {
145 4632 : return myMicrosimID;
146 : }
147 :
148 : /// @brief Returns the name of the object (default "")
149 : virtual const std::string getOptionalName() const;
150 :
151 : /// @brief Changes the microsimID of the object
152 : /// @note happens in netedit
153 : virtual void setMicrosimID(const std::string& newID);
154 :
155 : /// @brief Returns the type of the object as coded in GUIGlObjectType
156 : /// @see GUIGlObjectType
157 : inline GUIGlObjectType getType() const {
158 112519423 : return myGLObjectType;
159 : }
160 :
161 : /// @brief Returns the priority of receiving mouse clicks
162 0 : virtual double getClickPriority() const {
163 0 : return (double)myGLObjectType;
164 : }
165 :
166 : /// @brief get blocking status
167 : inline bool isBlocked() const {
168 1669855 : return myAmBlocked;
169 : }
170 :
171 : /// @brief set blocking status
172 : inline void setBlocked(const bool state = true) {
173 29007 : myAmBlocked = state;
174 28999 : }
175 :
176 : /// @brief return exaggeration associated with this GLObject
177 0 : virtual double getExaggeration(const GUIVisualizationSettings& s) const {
178 : UNUSED_PARAMETER(s);
179 0 : return 1.;
180 : }
181 :
182 : //// @brief Returns the boundary to which the view shall be centered in order to show the object
183 : virtual Boundary getCenteringBoundary() const = 0;
184 :
185 0 : virtual Position getCenter() const {
186 0 : return getCenteringBoundary().getCenter();
187 : }
188 :
189 : /// @brief return individual scaling factor for this object
190 7433084 : virtual double getScaleVisual() const {
191 7433084 : return 1;
192 : }
193 :
194 : /// @brief Draws the object
195 : /// @param[in] s The settings for the current view (may influence drawing)
196 : virtual void drawGL(const GUIVisualizationSettings& s) const = 0;
197 :
198 : /// @brief check if element is locked (Currently used only in netedit)
199 : virtual bool isGLObjectLocked() const;
200 :
201 : /// @brief mark element as front element (Currently used only in netedit)
202 : virtual void markAsFrontElement();
203 :
204 : /// @brief delete GLObject (Currently used only in netedit)
205 : virtual void deleteGLObject();
206 :
207 : /// @brief select GLObject (Currently used only in netedit)
208 : virtual void selectGLObject();
209 :
210 : /// @brief update GLObject (geometry, ID, etc.) (optional)
211 : virtual void updateGLObject();
212 :
213 0 : virtual double getColorValue(const GUIVisualizationSettings& /*s*/, int /*activeScheme*/) const {
214 0 : return 0;
215 : }
216 : /// @}
217 :
218 : /** @brief Draws additional, user-triggered visualisations
219 : * @param[in] parent The view
220 : * @param[in] s The settings for the current view (may influence drawing)
221 : */
222 : virtual void drawGLAdditional(GUISUMOAbstractView* const parent, const GUIVisualizationSettings& s) const;
223 :
224 : /// @brief remove additional user-griggered visualisations
225 0 : virtual void removeActiveAddVisualisation(GUISUMOAbstractView* const /*parent*/, int /*which*/) {}
226 :
227 : /// @brief notify object about left click
228 0 : virtual void onLeftBtnPress(void* /*data*/) {}
229 :
230 : #ifdef HAVE_OSG
231 : /// @brief get OSG Node
232 : osg::Node* getNode() const;
233 :
234 : /// @brief set OSG Node
235 : void setNode(osg::Node* node);
236 : #endif
237 :
238 : /// @name Parameter table window I/O
239 : /// @{
240 : /// @brief Lets this object know a parameter window showing the object's values was opened
241 : /// @param[in] w The opened parameter window
242 : void addParameterTable(GUIParameterTableWindow* w);
243 :
244 : /// @brief Lets this object know a parameter window showing the object's values was closed
245 : /// @param[in] w The closed parameter window
246 : void removeParameterTable(GUIParameterTableWindow* w);
247 : /// @}
248 :
249 : /// @brief draw name of item
250 : void drawName(const Position& pos, const double scale, const GUIVisualizationTextSettings& settings, const double angle = 0, bool forceShow = false) const;
251 :
252 : protected:
253 : /// @name helper methods for building popup-menus
254 : /// @{
255 : /// @brief build common popup options
256 : void buildPopUpMenuCommonOptions(GUIGLObjectPopupMenu* ret, GUIMainWindow& app, GUISUMOAbstractView* parent, const SumoXMLTag tag,
257 : const bool selected, bool addSeparator = true);
258 :
259 : /** @brief Builds the header
260 : * @param[in, filled] ret The popup menu to add the entry to
261 : * @param[in] addSeparator Whether a separator shall be added, too
262 : */
263 : void buildPopupHeader(GUIGLObjectPopupMenu* ret, GUIMainWindow& app, bool addSeparator = true);
264 :
265 : /** @brief Builds an entry which allows to center to the object
266 : * @param[in, filled] ret The popup menu to add the entry to
267 : * @param[in] addSeparator Whether a separator shall be added, too
268 : */
269 : void buildCenterPopupEntry(GUIGLObjectPopupMenu* ret, bool addSeparator = true);
270 :
271 : /** @brief Builds entries which allow to copy the name / typed name into the clipboard
272 : * @param[in, filled] ret The popup menu to add the entry to
273 : * @param[in] addSeparator Whether a separator shall be added, too
274 : */
275 : void buildNameCopyPopupEntry(GUIGLObjectPopupMenu* ret, bool addSeparator = true);
276 :
277 : /** @brief Builds an entry which allows to (de)select the object
278 : * @param[in, filled] ret The popup menu to add the entry to
279 : * @param[in] addSeparator Whether a separator shall be added, too
280 : */
281 : void buildSelectionPopupEntry(GUIGLObjectPopupMenu* ret, bool addSeparator = true);
282 :
283 : /** @brief Builds an entry which allows to open the parameter window
284 : * @param[in, filled] ret The popup menu to add the entry to
285 : * @param[in] addSeparator Whether a separator shall be added, too
286 : */
287 : void buildShowParamsPopupEntry(GUIGLObjectPopupMenu* ret, bool addSeparator = true);
288 :
289 : /** @brief Builds an entry which allows to open the type parameter window
290 : * @param[in, filled] ret The popup menu to add the entry to
291 : * @param[in] addSeparator Whether a separator shall be added, too
292 : */
293 : void buildShowTypeParamsPopupEntry(GUIGLObjectPopupMenu* ret, bool addSeparator = true);
294 :
295 : /** @brief Builds an entry which allows to copy the cursor position
296 : * if geo projection is used, also builds an entry for copying the geo-position
297 : * @param[in, filled] ret The popup menu to add the entry to
298 : * @param[in] addSeparator Whether a separator shall be added, too
299 : */
300 : void buildPositionCopyEntry(GUIGLObjectPopupMenu* ret, const GUIMainWindow& app, bool addSeparator = true) const;
301 :
302 : /** @brief Builds an entry which allows to open the manipulator window
303 : * @param[in, filled] ret The popup menu to add the entry to
304 : * @param[in] addSeparator Whether a separator shall be added, too
305 : */
306 : void buildShowManipulatorPopupEntry(GUIGLObjectPopupMenu* ret, bool addSeparator = true);
307 :
308 : /// @}
309 :
310 : /// @brief build basic shape popup options. Used to unify pop-ups menu in netedit and SUMO-GUI
311 : void buildShapePopupOptions(GUIMainWindow& app, GUIGLObjectPopupMenu* ret, const std::string& type);
312 :
313 : /// @brief build basic additional popup options. Used to unify pop-ups menu in netedit and SUMO-GUI
314 : void buildAdditionalsPopupOptions(GUIMainWindow& app, GUIGLObjectPopupMenu* ret, const std::string& type);
315 :
316 : private:
317 : /// @brief The numerical id of the object
318 : const GUIGlID myGlID;
319 :
320 : /// @brief The type of the object
321 : const GUIGlObjectType myGLObjectType;
322 :
323 : /// @brief ID of GL object
324 : std::string myMicrosimID;
325 :
326 : /// @brief full name of GL Object
327 : std::string myFullName;
328 :
329 : /// @brief icon associatd with this GL Object
330 : FXIcon* myIcon;
331 :
332 : /// @brief whether the object can be deleted
333 : bool myAmBlocked = false;
334 :
335 : /// @brief Parameter table windows which refer to this object
336 : std::set<GUIParameterTableWindow*> myParamWindows;
337 :
338 : #ifdef HAVE_OSG
339 : /// @brief OSG Node of this GL object
340 : osg::Node* myOSGNode = nullptr;
341 : #endif
342 :
343 : /// @brief create full name
344 : std::string createFullName() const;
345 :
346 : /// @brief vector for TypeNames Initializer
347 : static StringBijection<GUIGlObjectType>::Entry GUIGlObjectTypeNamesInitializer[];
348 :
349 : /// @brief Invalidated copy constructor.
350 : GUIGlObject(const GUIGlObject&) = delete;
351 :
352 : /// @brief Invalidated assignment operator.
353 : GUIGlObject& operator=(const GUIGlObject&) = delete;
354 : };
|