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 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, int priority,
61 : double distance);
62 :
63 :
64 : /// @brief Destructor.
65 : ~GUIEdge();
66 :
67 : /// Has to be called after all edges were built and all connections were set
68 : virtual void closeBuilding() override;
69 :
70 : /* @brief Returns the gl-ids of all known edges
71 : * @param[in] includeInternal Whether to include ids of internal edges
72 : */
73 : static std::vector<GUIGlID> getIDs(bool includeInternal);
74 :
75 : /* @brief Returns the combined length of all edges
76 : * @param[in] includeInternal Whether to include lengths of internal edges
77 : * @param[in] eachLane Whether to count each lane separately
78 : */
79 : static double getTotalLength(bool includeInternal, bool eachLane);
80 :
81 : /// Returns the street's geometry
82 : Boundary getBoundary() const;
83 :
84 : /// returns the enumerated lane (!!! why not private with a friend?)
85 : MSLane& getLane(int laneNo);
86 :
87 : /** returns the position on the line given by the coordinates where "prev"
88 : is the length of the line and "wanted" the distance from the begin
89 : !!! should be within another class */
90 : static std::pair<double, double> getLaneOffsets(double x1, double y1,
91 : double x2, double y2, double prev, double wanted);
92 :
93 :
94 : /// @name inherited from GUIGlObject
95 : //@{
96 :
97 : /** @brief Returns an own popup-menu
98 : *
99 : * @param[in] app The application needed to build the popup-menu
100 : * @param[in] parent The parent window needed to build the popup-menu
101 : * @return The built popup-menu
102 : * @see GUIGlObject::getPopUpMenu
103 : */
104 : virtual GUIGLObjectPopupMenu* getPopUpMenu(GUIMainWindow& app, GUISUMOAbstractView& parent) override;
105 :
106 :
107 : /** @brief Returns an own parameter window
108 : *
109 : * @param[in] app The application needed to build the parameter window
110 : * @param[in] parent The parent window needed to build the parameter window
111 : * @return The built parameter window
112 : * @see GUIGlObject::getParameterWindow
113 : */
114 : virtual GUIParameterTableWindow* getParameterWindow(GUIMainWindow& app, GUISUMOAbstractView& parent) override;
115 :
116 : /** @brief Returns an own type parameter window
117 : *
118 : * @param[in] app The application needed to build the parameter window
119 : * @param[in] parent The parent window needed to build the parameter window
120 : * @return The built parameter window
121 : */
122 : GUIParameterTableWindow* getTypeParameterWindow(GUIMainWindow& app, GUISUMOAbstractView& parent) override;
123 :
124 : /** @brief Returns the boundary to which the view shall be centered in order to show the object
125 : *
126 : * @return The boundary the object is within
127 : * @see GUIGlObject::getCenteringBoundary
128 : */
129 : Boundary getCenteringBoundary() const override;
130 :
131 : /// @brief Returns the street name
132 : const std::string getOptionalName() const override;
133 :
134 : /** @brief Draws the object
135 : * @param[in] s The settings for the current view (may influence drawing)
136 : * @see GUIGlObject::drawGL
137 : */
138 : void drawGL(const GUIVisualizationSettings& s) const override;
139 : //@}
140 :
141 : double getClickPriority() const override;
142 :
143 63637 : void addTransportable(MSTransportable* t) const override {
144 63637 : FXMutexLock locker(myLock);
145 63637 : MSEdge::addTransportable(t);
146 63637 : }
147 :
148 118365 : void removeTransportable(MSTransportable* t) const override {
149 118365 : FXMutexLock locker(myLock);
150 118365 : MSEdge::removeTransportable(t);
151 118365 : }
152 :
153 : /// @name Access to persons
154 : /// @{
155 :
156 : /** @brief Returns this edge's persons set; locks it for microsimulation
157 : * @brief Avoids the creation of new vector as in getSortedPersons
158 : *
159 : * @return
160 : * Please note that it is necessary to release the person container
161 : * afterwards using "releasePersons".
162 : * @return This edge's persons.
163 : */
164 : const std::set<MSTransportable*, ComparatorNumericalIdLess>& getPersonsSecure() const {
165 283724 : myLock.lock();
166 : return myPersons;
167 : }
168 :
169 : /** @brief Allows to use the container for microsimulation again
170 : *
171 : * Unlocks "myLock" preventing usage by microsimulation.
172 : */
173 : void releasePersons() const {
174 283724 : myLock.unlock();
175 : }
176 : /// @}
177 :
178 : double getAllowedSpeed() const;
179 : /// @brief return meanSpead divided by allowedSpeed
180 : double getRelativeSpeed() const;
181 :
182 : /// @brief sets the color according to the currente settings
183 : void setColor(const GUIVisualizationSettings& s) const;
184 :
185 : /// @brief sets the color according to the current scheme index and some edge function
186 : bool setFunctionalColor(const GUIColorer& c) const;
187 :
188 : /// @brief sets multiple colors according to the current scheme index and edge function
189 : bool setMultiColor(const GUIColorer& c) const;
190 :
191 : /// @brief gets the color value according to the current scheme index
192 : double getColorValue(const GUIVisualizationSettings& s, int activeScheme) const override;
193 :
194 : /// @brief gets the scaling value according to the current scheme index
195 : double getScaleValue(const GUIVisualizationSettings& s, int activeScheme) const;
196 :
197 : /// @brief returns the segment closest to the given position
198 : MESegment* getSegmentAtPosition(const Position& pos);
199 :
200 : void drawMesoVehicles(const GUIVisualizationSettings& s) const;
201 :
202 : /// @brief grant exclusive access to the mesoscopic state
203 13658597 : void lock() const override {
204 13658597 : myLock.lock();
205 13658597 : }
206 :
207 : /// @brief release exclusive access to the mesoscopic state
208 13658597 : void unlock() const override {
209 13658597 : myLock.unlock();
210 13658597 : }
211 :
212 : /// @brief close this edge for traffic
213 : void closeTraffic(const GUILane* lane);
214 :
215 : /// @brief add a rerouter
216 : void addRerouter();
217 :
218 : /// @brief return segment colors (meso)
219 : const std::vector<RGBColor>& getSegmentColors() const {
220 : return mySegmentColors;
221 : }
222 :
223 : RGBColor getMesoColor() const {
224 2452567 : return myMesoColor;
225 : }
226 :
227 : bool showDeadEnd() const {
228 126704 : return myShowDeadEnd;
229 : }
230 :
231 : /// @brief whether this lane is selected in the GUI
232 : bool isSelected() const override;
233 :
234 : /// The color of the segments (cached)
235 : mutable std::vector<RGBColor> mySegmentColors;
236 :
237 : /// @brief whether to highlight this edge as a dead-end edge
238 : bool myShowDeadEnd;
239 :
240 : /// @brief get number of vehicles waiting for departure on this edge
241 : double getPendingEmits() const;
242 :
243 : private:
244 : /// @brief invalidated copy constructor
245 : GUIEdge(const GUIEdge& s);
246 :
247 : /// @brief invalidated assignment operator
248 : GUIEdge& operator=(const GUIEdge& s);
249 :
250 :
251 : private:
252 : /// The mutex used to avoid concurrent updates of myPersons/ myContainers
253 : mutable FXMutex myLock;
254 :
255 : mutable RGBColor myMesoColor;
256 :
257 : };
|