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 GUILane.h
15 : /// @author Daniel Krajzewicz
16 : /// @author Jakob Erdmann
17 : /// @author Michael Behrisch
18 : /// @date Sept 2002
19 : ///
20 : // Representation of a lane in the micro simulation (gui-version)
21 : /****************************************************************************/
22 : #pragma once
23 : #include <config.h>
24 :
25 : #include <utils/foxtools/fxheader.h>
26 : #include <string>
27 : #include <utility>
28 : #include <microsim/MSLane.h>
29 : #include <microsim/MSEdge.h>
30 : #include <utils/geom/Position.h>
31 : #include <utils/geom/PositionVector.h>
32 : #include <utils/gui/globjects/GUIGlObject.h>
33 : #include <utils/gui/settings/GUIPropertySchemeStorage.h>
34 :
35 :
36 : // ===========================================================================
37 : // class declarations
38 : // ===========================================================================
39 : class GUINet;
40 : class MSVehicle;
41 : class MSNet;
42 : class TesselatedPolygon;
43 : #ifdef HAVE_OSG
44 : namespace osg {
45 : class Geometry;
46 : }
47 : #endif
48 :
49 : // ===========================================================================
50 : // class definitions
51 : // ===========================================================================
52 : /**
53 : * @class GUILane
54 : * @brief Representation of a lane in the micro simulation (gui-version)
55 : *
56 : * An extended MSLane. A mechanism to avoid concurrent
57 : * visualisation and simulation what may cause problems when vehicles
58 : * disappear is implemented using a mutex.
59 : */
60 : class GUILane : public MSLane, public GUIGlObject {
61 : public:
62 : /** @brief Constructor
63 : *
64 : * @param[in] id The lane's id
65 : * @param[in] maxSpeed The speed allowed on this lane
66 : * @param[in] friction The initial friction on this lane
67 : * @param[in] length The lane's length
68 : * @param[in] edge The edge this lane belongs to
69 : * @param[in] numericalID The numerical id of the lane
70 : * @param[in] shape The shape of the lane
71 : * @param[in] width The width of the lane
72 : * @param[in] permissions Encoding of vehicle classes that may drive on this lane
73 : * @see SUMOVehicleClass
74 : * @see MSLane
75 : */
76 : GUILane(const std::string& id, double maxSpeed, double friction,
77 : double length, MSEdge* const edge, int numericalID,
78 : const PositionVector& shape, double width,
79 : SVCPermissions permissions,
80 : SVCPermissions changeLeft, SVCPermissions changeRight,
81 : int index, bool isRampAccel,
82 : const std::string& type,
83 : const PositionVector& outlineShape);
84 :
85 :
86 : /// @brief Destructor
87 : ~GUILane();
88 :
89 : /** @brief Returns the name of the parent object (if any)
90 : * @note Inherited from GUIGlObject
91 : * @return This object's parent id
92 : */
93 0 : std::string getParentName() const override {
94 0 : return getEdge().getID();
95 : }
96 :
97 : void addSecondaryShape(const PositionVector& shape) override;
98 :
99 8981033 : double getLengthGeometryFactor(bool secondaryShape) const override {
100 8981033 : return secondaryShape ? myLengthGeometryFactor2 : myLengthGeometryFactor;
101 : }
102 :
103 : /// @name Access to vehicles
104 : /// @{
105 :
106 : /** @brief Returns the vehicles container; locks it for microsimulation
107 : *
108 : * Locks "myLock" preventing usage by microsimulation.
109 : *
110 : * Please note that it is necessary to release the vehicles container
111 : * afterwards using "releaseVehicles".
112 : * @return The vehicles on this lane
113 : * @see MSLane::getVehiclesSecure
114 : */
115 : const VehCont& getVehiclesSecure() const override;
116 :
117 :
118 : /** @brief Allows to use the container for microsimulation again
119 : *
120 : * Unlocks "myLock" preventing usage by microsimulation.
121 : * @see MSLane::releaseVehicles
122 : */
123 : void releaseVehicles() const override;
124 : /// @}
125 :
126 :
127 :
128 : /// @name Vehicle movement (longitudinal)
129 : /// @{
130 :
131 : /** the same as in MSLane, but locks the access for the visualisation
132 : first; the access will be granted at the end of this method */
133 : void planMovements(const SUMOTime t) override;
134 :
135 : /** the same as in MSLane, but locks the access for the visualisation
136 : first; the access will be granted at the end of this method */
137 : void setJunctionApproaches(const SUMOTime t) const override;
138 :
139 : /** the same as in MSLane, but locks the access for the visualisation
140 : first; the access will be granted at the end of this method */
141 : void executeMovements(const SUMOTime t) override;
142 :
143 : /** the same as in MSLane, but locks the access for the visualisation
144 : first; the access will be granted at the end of this method */
145 : void integrateNewVehicles() override;
146 : ///@}
147 :
148 :
149 : /** the same as in MSLane, but locks the access for the visualisation
150 : first; the access will be granted at the end of this method */
151 : void detectCollisions(SUMOTime timestep, const std::string& stage) override;
152 :
153 :
154 : /** the same as in MSLane, but locks the access for the visualisation
155 : first; the access will be granted at the end of this method */
156 : MSVehicle* removeVehicle(MSVehicle* remVehicle, MSMoveReminder::Notification notification, bool notify) override;
157 :
158 : /// @brief remove parking vehicle
159 : void removeParking(MSBaseVehicle* veh) override;
160 :
161 : /** @brief Sets the information about a vehicle lapping into this lane
162 : *
163 : * This vehicle is added to myVehicles and may be distinguished from regular
164 : * vehicles by the disparity between this lane and v->getLane()
165 : * @param[in] v The vehicle which laps into this lane
166 : * @return This lane's length
167 : */
168 : double setPartialOccupation(MSVehicle* v) override;
169 :
170 : /** @brief Removes the information about a vehicle lapping into this lane
171 : * @param[in] v The vehicle which laps into this lane
172 : */
173 : void resetPartialOccupation(MSVehicle* v) override;
174 :
175 : /// @name inherited from GUIGlObject
176 : //@{
177 :
178 : /** @brief Returns an own popup-menu
179 : *
180 : * @param[in] app The application needed to build the popup-menu
181 : * @param[in] parent The parent window needed to build the popup-menu
182 : * @return The built popup-menu
183 : * @see GUIGlObject::getPopUpMenu
184 : */
185 : GUIGLObjectPopupMenu* getPopUpMenu(GUIMainWindow& app, GUISUMOAbstractView& parent) override;
186 :
187 : /** @brief Returns an own parameter window
188 : *
189 : * @param[in] app The application needed to build the parameter window
190 : * @param[in] parent The parent window needed to build the parameter window
191 : * @return The built parameter window
192 : * @see GUIGlObject::getParameterWindow
193 : */
194 : GUIParameterTableWindow* getParameterWindow(GUIMainWindow& app, GUISUMOAbstractView& parent) override;
195 :
196 : /** @brief Returns the boundary to which the view shall be centered in order to show the object
197 : *
198 : * @return The boundary the object is within
199 : * @see GUIGlObject::getCenteringBoundary
200 : */
201 : Boundary getCenteringBoundary() const override;
202 :
203 : /** @brief Draws the object
204 : * @param[in] s The settings for the current view (may influence drawing)
205 : * @see GUIGlObject::drawGL
206 : */
207 : void drawGL(const GUIVisualizationSettings& s) const override;
208 :
209 : double getClickPriority() const override;
210 : //@}
211 :
212 : const PositionVector& getShape(bool secondary) const override;
213 : const std::vector<double>& getShapeRotations(bool secondary) const;
214 : const std::vector<double>& getShapeLengths(bool secondary) const;
215 :
216 : double firstWaitingTime() const;
217 :
218 : /// @brief whether any of the neighboring lanes is not a bidi-lane
219 : bool neighLaneNotBidi() const;
220 :
221 : /// @brief draw lane borders and white markings
222 : void drawMarkings(const GUIVisualizationSettings& s, double scale) const;
223 :
224 : /// @brief bike lane markings on top of an intersection
225 : void drawBikeMarkings() const;
226 :
227 : /// @brief bike lane markings on top of an intersection
228 : void drawJunctionChangeProhibitions() const;
229 :
230 : /// @brief direction indicators for lanes
231 : void drawDirectionIndicators(double exaggeration, bool spreadSuperposed, bool s2) const;
232 :
233 : /// @brief draw intersection positions of foe internal lanes with this one
234 : void debugDrawFoeIntersections() const;
235 :
236 : double getEdgeLaneNumber() const;
237 :
238 : /** @brief Returns the stored traveltime for the edge of this lane
239 : */
240 : double getStoredEdgeTravelTime() const;
241 :
242 : /** @brief Returns the loaded weight (effort) for the edge of this lane
243 : */
244 : double getLoadedEdgeWeight() const;
245 :
246 : void setReachability(double value) {
247 0 : myReachability = value;
248 0 : }
249 :
250 : double getReachability() const {
251 : return myReachability;
252 : }
253 :
254 : #ifdef HAVE_OSG
255 : void setGeometry(osg::Geometry* geom) {
256 5602 : myGeom = geom;
257 : }
258 :
259 : void updateColor(const GUIVisualizationSettings& s);
260 :
261 : #endif
262 :
263 : /// @brief close this lane for traffic
264 : void closeTraffic(bool rebuildAllowed = true);
265 :
266 : bool isClosed() const {
267 0 : return myAmClosed;
268 : }
269 :
270 : /// @brief gets the color value according to the current scheme index
271 : double getColorValue(const GUIVisualizationSettings& s, int activeScheme) const override;
272 :
273 : /// @brief gets the color value according to the current scheme index including values for things that set the color indirectly
274 : double getColorValueWithFunctional(const GUIVisualizationSettings& s, int activeScheme) const;
275 :
276 : /// @brief return color value based on cached settings
277 : double getColorValueForTracker() const;
278 :
279 : /// @brief gets the scaling value according to the current scheme index
280 : double getScaleValue(const GUIVisualizationSettings& s, int activeScheme, bool s2) const;
281 :
282 : /// @brief whether this lane is selected in the GUI
283 : bool isSelected() const override;
284 :
285 : /* @brief sets the color according to the current scheme index and some lane function
286 : * @param[in] id override active scheme when calling from meso gui
287 : */
288 : bool setFunctionalColor(const GUIColorer& c, RGBColor& col, int activeScheme = -1) const;
289 :
290 : /// @brief whether to draw this lane as a railway
291 : bool drawAsRailway(const GUIVisualizationSettings& s) const;
292 :
293 : protected:
294 : /// moves myTmpVehicles int myVehicles after a lane change procedure
295 : void swapAfterLaneChange(SUMOTime t) override;
296 :
297 : /** @brief Inserts the vehicle into this lane, and informs it about entering the network
298 : *
299 : * Calls the vehicles enterLaneAtInsertion function,
300 : * updates statistics and modifies the active state as needed
301 : * @param[in] veh The vehicle to be incorporated
302 : * @param[in] pos The position of the vehicle
303 : * @param[in] speed The speed of the vehicle
304 : * @param[in] posLat The lateral position of the vehicle
305 : * @param[in] at
306 : * @param[in] notification The cause of insertion (i.e. departure, teleport, parking) defaults to departure
307 : * @see MSLane::incorporateVehicle
308 : */
309 : void incorporateVehicle(MSVehicle* veh, double pos, double speed, double posLat,
310 : const MSLane::VehCont::iterator& at,
311 : MSMoveReminder::Notification notification = MSMoveReminder::NOTIFICATION_DEPARTED) override;
312 :
313 : private:
314 : /// @brief helper methods
315 : void drawLinkNo(const GUIVisualizationSettings& s) const;
316 : void drawTLSLinkNo(const GUIVisualizationSettings& s, const GUINet& net) const;
317 : void drawLinkRules(const GUIVisualizationSettings& s, const GUINet& net) const;
318 : void drawLinkRule(const GUIVisualizationSettings& s, const GUINet& net, const MSLink* link,
319 : const PositionVector& shape, double x1, double x2) const;
320 : void drawArrows(bool secondaryShape) const;
321 : void drawLane2LaneConnections(double exaggeration, bool s2) const;
322 :
323 :
324 : /// @brief add intermediate points at segment borders
325 : PositionVector splitAtSegments(const PositionVector& shape);
326 :
327 : /// @brief get number of vehicles waiting for departure on this lane
328 : double getPendingEmits() const;
329 :
330 : private:
331 : void initRotations(const PositionVector& shape,
332 : std::vector<double>& rotations,
333 : std::vector<double>& lengths,
334 : std::vector<RGBColor>& colors);
335 :
336 : /// @brief sets multiple colors according to the current scheme index and some lane function
337 : bool setMultiColor(const GUIVisualizationSettings& s, const GUIColorer& c, RGBColor& col) const;
338 :
339 : /// @brief sets the color according to the currente settings
340 : RGBColor setColor(const GUIVisualizationSettings& s) const;
341 :
342 : /// @brief whether to draw this lane as a waterway
343 : bool drawAsWaterway(const GUIVisualizationSettings& s) const;
344 :
345 : /// @brief whether this lane or its parent edge is selected in the GUI
346 : bool isLaneOrEdgeSelected() const;
347 :
348 : std::vector<RGBColor>& getShapeColors(bool secondary) const;
349 :
350 : /// The rotations of the shape parts
351 : std::vector<double> myShapeRotations;
352 : std::vector<double> myShapeRotations2;
353 :
354 : /// The lengths of the shape parts
355 : std::vector<double> myShapeLengths;
356 : std::vector<double> myShapeLengths2;
357 :
358 : /// The color of the shape parts (cached)
359 : mutable std::vector<RGBColor> myShapeColors;
360 : mutable std::vector<RGBColor> myShapeColors2;
361 :
362 : /// @brief the meso segment index for each geometry segment
363 : std::vector<int> myShapeSegments;
364 : /// @brief the shape indices where the meso segment changes (for segmentsIndex > 0)
365 : std::vector<int> mySegmentStartIndex;
366 :
367 : /// @brief Half of lane width, for speed-up
368 : double myHalfLaneWidth;
369 :
370 : /// @brief Quarter of lane width, for speed-up
371 : double myQuarterLaneWidth;
372 :
373 : /// @brief the time distance from a particular edge
374 : double myReachability = INVALID_DOUBLE;
375 :
376 : /// @brief list of parkingAreas on this lane
377 : mutable std::vector<MSParkingArea*>* myParkingAreas;
378 :
379 : /// @brief An object that stores the tesselation
380 : mutable TesselatedPolygon* myTesselation;
381 :
382 : #ifdef HAVE_OSG
383 : osg::Geometry* myGeom;
384 : #endif
385 :
386 : /// @brief state for dynamic lane closings
387 : bool myAmClosed;
388 :
389 : /// @brief secondary shape for visualization
390 : PositionVector myShape2;
391 : double myLengthGeometryFactor2;
392 :
393 : /// @brief cached for tracking color value
394 : static GUIVisualizationSettings* myCachedGUISettings;
395 :
396 : private:
397 : /// The mutex used to avoid concurrent updates of the vehicle buffer
398 : mutable FXMutex myLock;
399 :
400 : /// @brief special color to signify alternative coloring scheme
401 : static const RGBColor MESO_USE_LANE_COLOR;
402 :
403 :
404 : };
|