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 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 4109312 : 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 222607625 : return myGlID;
107 : }
108 :
109 : /// @brief get icon associated with this GL Object
110 : FXIcon* getGLIcon() const;
111 :
112 : /// @brief notify object about popup menu removal
113 : GUIGlObject* getGLObjectParent();
114 :
115 : /// @brief notify object about popup menu removal
116 : void setGLObjectParent(GUIGlObject* parent);
117 :
118 : /// @}
119 :
120 : /// @name interfaces to be implemented by derived classes
121 : /// @{
122 : /** @brief Returns an own popup-menu
123 : *
124 : * @param[in] app The application needed to build the popup-menu
125 : * @param[in] parent The parent window needed to build the popup-menu
126 : * @return The built popup-menu
127 : */
128 : virtual GUIGLObjectPopupMenu* getPopUpMenu(GUIMainWindow& app, GUISUMOAbstractView& parent) = 0;
129 :
130 : /// @brief notify object about popup menu removal
131 0 : virtual void removedPopupMenu() {}
132 :
133 : /** @brief Returns an own parameter window
134 : *
135 : * @param[in] app The application needed to build the parameter window
136 : * @param[in] parent The parent window needed to build the parameter window
137 : * @return The built parameter window
138 : */
139 : virtual GUIParameterTableWindow* getParameterWindow(GUIMainWindow& app, GUISUMOAbstractView& parent) = 0;
140 :
141 : /** @brief Returns an own type parameter window (optional)
142 : *
143 : * @param[in] app The application needed to build the parameter window
144 : * @param[in] parent The parent window needed to build the parameter window
145 : * @return The built parameter window
146 : */
147 : virtual GUIParameterTableWindow* getTypeParameterWindow(GUIMainWindow& app, GUISUMOAbstractView& parent);
148 :
149 : /// @brief Returns the id of the object as known to microsim
150 : inline const std::string& getMicrosimID() const {
151 4734 : return myMicrosimID;
152 : }
153 :
154 : /// @brief Returns the name of the object (default "")
155 : virtual const std::string getOptionalName() const;
156 :
157 : /// @brief Changes the microsimID of the object
158 : /// @note happens in netedit
159 : virtual void setMicrosimID(const std::string& newID);
160 :
161 : /// @brief Returns the type of the object as coded in GUIGlObjectType
162 : /// @see GUIGlObjectType
163 : inline GUIGlObjectType getType() const {
164 159074970 : return myGLObjectType;
165 : }
166 :
167 : /// @brief Returns the priority of receiving mouse clicks
168 0 : virtual double getClickPriority() const {
169 0 : return (double)myGLObjectType;
170 : }
171 :
172 : /// @brief get blocking status
173 : inline bool isBlocked() const {
174 2048917 : return myAmBlocked;
175 : }
176 :
177 : /// @brief set blocking status
178 : inline void setBlocked(const bool state = true) {
179 32158 : myAmBlocked = state;
180 32136 : }
181 :
182 : /// @brief return exaggeration associated with this GLObject
183 0 : virtual double getExaggeration(const GUIVisualizationSettings& s) const {
184 : UNUSED_PARAMETER(s);
185 0 : return 1.;
186 : }
187 :
188 : //// @brief Returns the boundary to which the view shall be centered in order to show the object
189 : virtual Boundary getCenteringBoundary() const = 0;
190 :
191 0 : virtual Position getCenter() const {
192 0 : return getCenteringBoundary().getCenter();
193 : }
194 :
195 : /// @brief return individual scaling factor for this object
196 9936920 : virtual double getScaleVisual() const {
197 9936920 : return 1;
198 : }
199 :
200 : /// @brief Draws the object
201 : /// @param[in] s The settings for the current view (may influence drawing)
202 : virtual void drawGL(const GUIVisualizationSettings& s) const = 0;
203 :
204 : /// @brief check if element is locked (Currently used only in netedit)
205 : virtual bool isGLObjectLocked() const;
206 :
207 : /// @brief mark element as front element (Currently used only in netedit)
208 : virtual void markAsFrontElement();
209 :
210 : /// @brief delete GLObject (Currently used only in netedit)
211 : virtual void deleteGLObject();
212 :
213 : /// @brief select GLObject (Currently used only in netedit)
214 : virtual void selectGLObject();
215 :
216 : /// @brief update GLObject (geometry, ID, etc.) (optional)
217 : virtual void updateGLObject();
218 :
219 : /// @brief check if object is visible (Currently used only in netedit)
220 0 : virtual bool isVisible(const GUIVisualizationSettings& /*s*/) const {
221 0 : return true;
222 : }
223 :
224 0 : virtual double getColorValue(const GUIVisualizationSettings& /*s*/, int /*activeScheme*/) const {
225 0 : return 0;
226 : }
227 : /// @}
228 :
229 : /** @brief Draws additional, user-triggered visualisations
230 : * @param[in] parent The view
231 : * @param[in] s The settings for the current view (may influence drawing)
232 : */
233 : virtual void drawGLAdditional(GUISUMOAbstractView* const parent, const GUIVisualizationSettings& s) const;
234 :
235 : /// @brief remove additional user-griggered visualisations
236 0 : virtual void removeActiveAddVisualisation(GUISUMOAbstractView* const /*parent*/, int /*which*/) {}
237 :
238 : /// @brief notify object about left click
239 0 : virtual void onLeftBtnPress(void* /*data*/) {}
240 :
241 : #ifdef HAVE_OSG
242 : /// @brief get OSG Node
243 : osg::Node* getNode() const;
244 :
245 : /// @brief set OSG Node
246 : void setNode(osg::Node* node);
247 : #endif
248 :
249 : /// @name Parameter table window I/O
250 : /// @{
251 : /// @brief Lets this object know a parameter window showing the object's values was opened
252 : /// @param[in] w The opened parameter window
253 : void addParameterTable(GUIParameterTableWindow* w);
254 :
255 : /// @brief Lets this object know a parameter window showing the object's values was closed
256 : /// @param[in] w The closed parameter window
257 : void removeParameterTable(GUIParameterTableWindow* w);
258 : /// @}
259 :
260 : /// @brief draw name of item
261 : void drawName(const Position& pos, const double scale, const GUIVisualizationTextSettings& settings, const double angle = 0, bool forceShow = false) const;
262 :
263 : protected:
264 : /// @name helper methods for building popup-menus
265 : /// @{
266 : /// @brief build common popup options
267 : void buildPopUpMenuCommonOptions(GUIGLObjectPopupMenu* ret, GUIMainWindow& app, GUISUMOAbstractView* parent, const SumoXMLTag tag,
268 : const bool selected, const bool allowDelete, const bool addSeparator);
269 :
270 : /** @brief Builds the header
271 : * @param[in, filled] ret The popup menu to add the entry to
272 : * @param[in] addSeparator Whether a separator shall be added, too
273 : */
274 : void buildPopupHeader(GUIGLObjectPopupMenu* ret, GUIMainWindow& app, bool addSeparator = true);
275 :
276 : /** @brief Builds an entry which allows to center to the object
277 : * @param[in, filled] ret The popup menu to add the entry to
278 : * @param[in] addSeparator Whether a separator shall be added, too
279 : */
280 : void buildCenterPopupEntry(GUIGLObjectPopupMenu* ret, bool addSeparator = true);
281 :
282 : /** @brief Builds entries which allow to copy the name / typed name into the clipboard
283 : * @param[in, filled] ret The popup menu to add the entry to
284 : * @param[in] addSeparator Whether a separator shall be added, too
285 : */
286 : void buildNameCopyPopupEntry(GUIGLObjectPopupMenu* ret, bool addSeparator = true);
287 :
288 : /** @brief Builds an entry which allows to (de)select the object
289 : * @param[in, filled] ret The popup menu to add the entry to
290 : * @param[in] addSeparator Whether a separator shall be added, too
291 : */
292 : void buildSelectionPopupEntry(GUIGLObjectPopupMenu* ret, bool addSeparator = true);
293 :
294 : /** @brief Builds an entry which allows to open the parameter window
295 : * @param[in, filled] ret The popup menu to add the entry to
296 : * @param[in] addSeparator Whether a separator shall be added, too
297 : */
298 : void buildShowParamsPopupEntry(GUIGLObjectPopupMenu* ret, bool addSeparator = true);
299 :
300 : /** @brief Builds an entry which allows to open the type parameter window
301 : * @param[in, filled] ret The popup menu to add the entry to
302 : * @param[in] addSeparator Whether a separator shall be added, too
303 : */
304 : void buildShowTypeParamsPopupEntry(GUIGLObjectPopupMenu* ret, bool addSeparator = true);
305 :
306 : /** @brief Builds an entry which allows to copy the cursor position
307 : * if geo projection is used, also builds an entry for copying the geo-position
308 : * @param[in, filled] ret The popup menu to add the entry to
309 : * @param[in] addSeparator Whether a separator shall be added, too
310 : */
311 : void buildPositionCopyEntry(GUIGLObjectPopupMenu* ret, const GUIMainWindow& app, bool addSeparator = true) const;
312 :
313 : /** @brief Builds an entry which allows to open the manipulator window
314 : * @param[in, filled] ret The popup menu to add the entry to
315 : * @param[in] addSeparator Whether a separator shall be added, too
316 : */
317 : void buildShowManipulatorPopupEntry(GUIGLObjectPopupMenu* ret, bool addSeparator = true);
318 :
319 : /// @}
320 :
321 : /// @brief build basic shape popup options. Used to unify pop-ups menu in netedit and SUMO-GUI
322 : void buildShapePopupOptions(GUIMainWindow& app, GUIGLObjectPopupMenu* ret, const std::string& type);
323 :
324 : /// @brief build basic additional popup options. Used to unify pop-ups menu in netedit and SUMO-GUI
325 : void buildAdditionalsPopupOptions(GUIMainWindow& app, GUIGLObjectPopupMenu* ret, const std::string& type);
326 :
327 : /// @brief to be called by child class to ensure cleanup in correct order
328 : void cleanupOnDestruction();
329 :
330 : private:
331 : /// @brief The numerical id of the object
332 : const GUIGlID myGlID;
333 :
334 : /// @brief The type of the object
335 : const GUIGlObjectType myGLObjectType;
336 :
337 : /// @brief ID of GL object
338 : std::string myMicrosimID;
339 :
340 : /// @brief full name of GL Object
341 : std::string myFullName;
342 :
343 : /// @brief icon associatd with this GL Object
344 : FXIcon* myIcon;
345 :
346 : /// @brief whether the object can be deleted
347 : bool myAmBlocked = false;
348 :
349 : /// @brief parent of this GLObject (usually used for lanes and edges)
350 : GUIGlObject* myParent = nullptr;
351 :
352 : /// @brief Parameter table windows which refer to this object
353 : std::set<GUIParameterTableWindow*> myParamWindows;
354 :
355 : #ifdef HAVE_OSG
356 : /// @brief OSG Node of this GL object
357 : osg::Node* myOSGNode = nullptr;
358 : #endif
359 :
360 : /// @brief create full name
361 : std::string createFullName() const;
362 :
363 : /// @brief vector for TypeNames Initializer
364 : static StringBijection<GUIGlObjectType>::Entry GUIGlObjectTypeNamesInitializer[];
365 :
366 : /// @brief Invalidated copy constructor.
367 : GUIGlObject(const GUIGlObject&) = delete;
368 :
369 : /// @brief Invalidated assignment operator.
370 : GUIGlObject& operator=(const GUIGlObject&) = delete;
371 : };
|