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 GUIEdge.h
15 : /// @author Daniel Krajzewicz
16 : /// @author Jakob Erdmann
17 : /// @author Sascha Krieg
18 : /// @author Michael Behrisch
19 : /// @date Sept 2002
20 : ///
21 : // A road/street connecting two junctions (gui-version)
22 : /****************************************************************************/
23 : #pragma once
24 : #include <config.h>
25 :
26 : #include <vector>
27 : #include <string>
28 : #include <utils/foxtools/fxheader.h>
29 : #include <microsim/MSEdge.h>
30 : #include <utils/gui/globjects/GUIGlObject.h>
31 : #include <utils/gui/settings/GUIPropertySchemeStorage.h>
32 :
33 :
34 : // ===========================================================================
35 : // class declarations
36 : // ===========================================================================
37 : class MESegment;
38 : class MSBaseVehicle;
39 : class GUILane;
40 :
41 :
42 : // ===========================================================================
43 : // class definitions
44 : // ===========================================================================
45 : /**
46 : * @class GUIEdge
47 : * @brief A road/street connecting two junctions (gui-version)
48 : *
49 : * @see MSEdge
50 : */
51 : class GUIEdge : public MSEdge, public GUIGlObject {
52 : public:
53 : /** @brief Constructor.
54 : * @param[in] id The id of the edge
55 : * @param[in] numericalID The numerical id (index) of the edge
56 : * @see MSEdge
57 : */
58 : GUIEdge(const std::string& id, int numericalID,
59 : const SumoXMLEdgeFunc function,
60 : const std::string& streetName, const std::string& edgeType,
61 : const std::string& routingType, int priority,
62 : double distance);
63 :
64 :
65 : /// @brief Destructor.
66 : ~GUIEdge();
67 :
68 : /// Has to be called after all edges were built and all connections were set
69 : virtual void closeBuilding() override;
70 :
71 : /* @brief Returns the gl-ids of all known edges
72 : * @param[in] includeInternal Whether to include ids of internal edges
73 : */
74 : static std::vector<GUIGlID> getIDs(bool includeInternal);
75 :
76 : /* @brief Returns the combined length of all edges
77 : * @param[in] includeInternal Whether to include lengths of internal edges
78 : * @param[in] eachLane Whether to count each lane separately
79 : */
80 : static double getTotalLength(bool includeInternal, bool eachLane);
81 :
82 : /// Returns the street's geometry
83 : Boundary getBoundary() const;
84 :
85 : /// returns the enumerated lane (!!! why not private with a friend?)
86 : MSLane& getLane(int laneNo);
87 :
88 : /** returns the position on the line given by the coordinates where "prev"
89 : is the length of the line and "wanted" the distance from the begin
90 : !!! should be within another class */
91 : static std::pair<double, double> getLaneOffsets(double x1, double y1,
92 : double x2, double y2, double prev, double wanted);
93 :
94 :
95 : /// @name inherited from GUIGlObject
96 : //@{
97 :
98 : /** @brief Returns an own popup-menu
99 : *
100 : * @param[in] app The application needed to build the popup-menu
101 : * @param[in] parent The parent window needed to build the popup-menu
102 : * @return The built popup-menu
103 : * @see GUIGlObject::getPopUpMenu
104 : */
105 : virtual GUIGLObjectPopupMenu* getPopUpMenu(GUIMainWindow& app, GUISUMOAbstractView& parent) override;
106 :
107 :
108 : /** @brief Returns an own parameter window
109 : *
110 : * @param[in] app The application needed to build the parameter window
111 : * @param[in] parent The parent window needed to build the parameter window
112 : * @return The built parameter window
113 : * @see GUIGlObject::getParameterWindow
114 : */
115 : virtual GUIParameterTableWindow* getParameterWindow(GUIMainWindow& app, GUISUMOAbstractView& parent) override;
116 :
117 : /** @brief Returns an own type parameter window
118 : *
119 : * @param[in] app The application needed to build the parameter window
120 : * @param[in] parent The parent window needed to build the parameter window
121 : * @return The built parameter window
122 : */
123 : GUIParameterTableWindow* getTypeParameterWindow(GUIMainWindow& app, GUISUMOAbstractView& parent) 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 Returns the street name
133 : const std::string getOptionalName() const override;
134 :
135 : /** @brief Draws the object
136 : * @param[in] s The settings for the current view (may influence drawing)
137 : * @see GUIGlObject::drawGL
138 : */
139 : void drawGL(const GUIVisualizationSettings& s) const override;
140 : //@}
141 :
142 : double getClickPriority() const override;
143 :
144 68476 : void addTransportable(MSTransportable* t) const override {
145 68476 : FXMutexLock locker(myLock);
146 68476 : MSEdge::addTransportable(t);
147 68476 : }
148 :
149 126979 : void removeTransportable(MSTransportable* t) const override {
150 126979 : FXMutexLock locker(myLock);
151 126979 : MSEdge::removeTransportable(t);
152 126979 : }
153 :
154 : /// @name Access to persons
155 : /// @{
156 :
157 : /** @brief Returns this edge's persons set; locks it for microsimulation
158 : * @brief Avoids the creation of new vector as in getSortedPersons
159 : *
160 : * @return
161 : * Please note that it is necessary to release the person container
162 : * afterwards using "releasePersons".
163 : * @return This edge's persons.
164 : */
165 : const std::set<MSTransportable*, ComparatorNumericalIdLess>& getPersonsSecure() const {
166 543790 : myLock.lock();
167 : return myPersons;
168 : }
169 :
170 : /** @brief Allows to use the container for microsimulation again
171 : *
172 : * Unlocks "myLock" preventing usage by microsimulation.
173 : */
174 : void releasePersons() const {
175 543790 : myLock.unlock();
176 : }
177 : /// @}
178 :
179 : double getAllowedSpeed() const;
180 : /// @brief return meanSpead divided by allowedSpeed
181 : double getRelativeSpeed() const;
182 :
183 : /// @brief sets the color according to the currente settings
184 : void setColor(const GUIVisualizationSettings& s) const;
185 :
186 : /// @brief sets the color according to the current scheme index and some edge function
187 : bool setFunctionalColor(const GUIColorer& c) const;
188 :
189 : /// @brief sets multiple colors according to the current scheme index and edge function
190 : bool setMultiColor(const GUIColorer& c) const;
191 :
192 : /// @brief gets the color value according to the current scheme index
193 : double getColorValue(const GUIVisualizationSettings& s, int activeScheme) const override;
194 :
195 : /// @brief gets the scaling value according to the current scheme index
196 : double getScaleValue(const GUIVisualizationSettings& s, int activeScheme) const;
197 :
198 : /// @brief returns the segment closest to the given position
199 : MESegment* getSegmentAtPosition(const Position& pos);
200 :
201 : void drawMesoVehicles(const GUIVisualizationSettings& s) const;
202 :
203 : /// @brief grant exclusive access to the mesoscopic state
204 13851035 : void lock() const override {
205 13851035 : myLock.lock();
206 13851035 : }
207 :
208 : /// @brief release exclusive access to the mesoscopic state
209 13851035 : void unlock() const override {
210 13851035 : myLock.unlock();
211 13851035 : }
212 :
213 : /// @brief close this edge for traffic
214 : void closeTraffic(const GUILane* lane);
215 :
216 : /// @brief add a rerouter
217 : void addRerouter();
218 :
219 : /// @brief return segment colors (meso)
220 : const std::vector<RGBColor>& getSegmentColors() const {
221 : return mySegmentColors;
222 : }
223 :
224 : RGBColor getMesoColor() const {
225 3304449 : return myMesoColor;
226 : }
227 :
228 : bool showDeadEnd() const {
229 133565 : return myShowDeadEnd;
230 : }
231 :
232 : /// @brief whether this lane is selected in the GUI
233 : bool isSelected() const override;
234 :
235 : /// The color of the segments (cached)
236 : mutable std::vector<RGBColor> mySegmentColors;
237 :
238 : /// @brief whether to highlight this edge as a dead-end edge
239 : bool myShowDeadEnd;
240 :
241 : /// @brief get number of vehicles waiting for departure on this edge
242 : double getPendingEmits() const;
243 :
244 : private:
245 : /// @brief invalidated copy constructor
246 : GUIEdge(const GUIEdge& s);
247 :
248 : /// @brief invalidated assignment operator
249 : GUIEdge& operator=(const GUIEdge& s);
250 :
251 :
252 : private:
253 : /// The mutex used to avoid concurrent updates of myPersons/ myContainers
254 : mutable FXMutex myLock;
255 :
256 : mutable RGBColor myMesoColor;
257 :
258 : };
|