Line data Source code
1 : /****************************************************************************/
2 : // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3 : // Copyright (C) 2001-2024 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 GUIGlObjectStorage.h
15 : /// @author Daniel Krajzewicz
16 : /// @author Jakob Erdmann
17 : /// @author Michael Behrisch
18 : /// @date Oct 2002
19 : ///
20 : // A storage for displayed objects via their numerical id
21 : /****************************************************************************/
22 : #pragma once
23 : #include <config.h>
24 :
25 : #include <map>
26 : #include <string>
27 : #include <set>
28 : #include <utils/foxtools/fxheader.h>
29 : #include "GUIGlObject.h"
30 :
31 :
32 : // ===========================================================================
33 : // class definitions
34 : // ===========================================================================
35 : /**
36 : * @class GUIGlObjectStorage
37 : * @brief A storage for of displayed objects via their numerical id
38 : *
39 : * This is a container for GUIGlObject - objects, which may be displayed
40 : * and due to this may generate tooltips or be grapped in other ways.
41 : *
42 : * As in case of vehicles (other, later implemented objects may have this
43 : * property, too) they may be deleted by the simulation while being accessed
44 : * - for example using a property window or something like that - this
45 : * container posesses three storages: one containing all objects that are not
46 : * accessed at all, one for objects currently accessed and one for objects that
47 : * are accessed but shall be deleted.
48 : */
49 : class GUIGlObjectStorage {
50 : public:
51 : /// @brief Constructor
52 : GUIGlObjectStorage();
53 :
54 :
55 : /// @brief Destructor
56 : ~GUIGlObjectStorage();
57 :
58 :
59 : /** @brief Registers an object
60 : *
61 : * This is done within the constructor of the GUIGlObject.
62 : * The next free id is calculated as well.
63 : *
64 : * @param[in] object The object to register
65 : */
66 : GUIGlID registerObject(GUIGlObject* object);
67 :
68 : void changeName(GUIGlObject* object, const std::string& fullName);
69 :
70 : /** @brief Returns the object from the container locking it
71 : *
72 : * The lock prevents the object from being deleted while it is accessed.
73 : *
74 : * @param[in] id The id of the object to return
75 : * @return The object with the given id or nullptr if no such object is known
76 : */
77 : GUIGlObject* getObjectBlocking(GUIGlID id) const;
78 :
79 : /** @brief Returns the object from the container locking it
80 : *
81 : * The lock prevents the object from being deleted while it is accessed.
82 : *
83 : * @param[in] id The id of the object to return
84 : * @return The object with the given id or nullptr if no such object is known
85 : */
86 : GUIGlObject* getObjectBlocking(const std::string& fullName) const;
87 :
88 : /** @brief Removes the named object from this container
89 : *
90 : * This function returns true if the object may be deleted;
91 : * otherwise it's kept in an internal storage (for visualisation etc.)
92 : * and will be removed by this class
93 : *
94 : * @param[in] id The id of the object to remove
95 : * @return Whether the object could be removed (and may be deleted)
96 : */
97 : bool remove(GUIGlID id);
98 :
99 : /** @brief Clears this container
100 : *
101 : * The objects are not deleted.
102 : */
103 : void clear();
104 :
105 :
106 : /** @brief Marks an object as unblocked
107 : *
108 : * The object is moved from "myBlocked" to "myMap".
109 : * @param[in] id The id of the object to unblock
110 : */
111 : void unblockObject(GUIGlID id);
112 :
113 :
114 : /** @brief Sets the given object as the "network" object
115 : * @param[in] object The object to set as network object
116 : */
117 : void setNetObject(GUIGlObject* object) {
118 7525 : myNetObject = object;
119 : }
120 :
121 : /** @brief Returns the network object
122 : * @return The network object
123 : */
124 : GUIGlObject* getNetObject() const {
125 0 : return myNetObject;
126 : }
127 :
128 : /// @brief A single static instance of this class
129 : static GUIGlObjectStorage gIDStorage;
130 :
131 : /// @brief Returns the set of all known objects
132 : const std::vector<GUIGlObject*>& getAllGLObjects() const;
133 :
134 : private:
135 : /// @brief The known objects
136 : std::vector<GUIGlObject*> myObjects;
137 :
138 : /// @brief The known objects by their full name
139 : std::map<std::string, GUIGlObject*> myFullNameMap;
140 :
141 : /// @brief The next id to give; initially one, increased by one with each object registration
142 : GUIGlID myNextID;
143 :
144 : /// @brief A lock to avoid parallel access on the storages
145 : mutable FXMutex myLock;
146 :
147 : /// @brief The network object
148 : GUIGlObject* myNetObject;
149 :
150 : private:
151 : /// @brief invalidated copy constructor
152 : GUIGlObjectStorage(const GUIGlObjectStorage& s) = delete;
153 :
154 : /// @brief invalidate assignment operator
155 : GUIGlObjectStorage& operator=(const GUIGlObjectStorage& s) = delete;
156 : };
|