1 /****************************************************************************/ 2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo 3 // Copyright (C) 2001-2019 German Aerospace Center (DLR) and others. 4 // This program and the accompanying materials 5 // are made available under the terms of the Eclipse Public License v2.0 6 // which accompanies this distribution, and is available at 7 // http://www.eclipse.org/legal/epl-v20.html 8 // SPDX-License-Identifier: EPL-2.0 9 /****************************************************************************/ 10 /// @file GUIEdge.h 11 /// @author Daniel Krajzewicz 12 /// @author Jakob Erdmann 13 /// @author Sascha Krieg 14 /// @author Michael Behrisch 15 /// @date Sept 2002 16 /// @version $Id$ 17 /// 18 // A road/street connecting two junctions (gui-version) 19 /****************************************************************************/ 20 #ifndef GUIEdge_h 21 #define GUIEdge_h 22 23 24 // =========================================================================== 25 // included modules 26 // =========================================================================== 27 #include <config.h> 28 29 #include <vector> 30 #include <string> 31 #include <fx.h> 32 #include <microsim/MSEdge.h> 33 #include <utils/gui/globjects/GUIGlObject.h> 34 #include <utils/gui/settings/GUIPropertySchemeStorage.h> 35 36 37 // =========================================================================== 38 // class declarations 39 // =========================================================================== 40 class MESegment; 41 class MSBaseVehicle; 42 class GUILane; 43 44 // =========================================================================== 45 // class definitions 46 // =========================================================================== 47 /** 48 * @class GUIEdge 49 * @brief A road/street connecting two junctions (gui-version) 50 * 51 * @see MSEdge 52 */ 53 class GUIEdge : public MSEdge, public GUIGlObject { 54 public: 55 /** @brief Constructor. 56 * @param[in] id The id of the edge 57 * @param[in] numericalID The numerical id (index) of the edge 58 * @see MSEdge 59 */ 60 GUIEdge(const std::string& id, int numericalID, 61 const SumoXMLEdgeFunc function, 62 const std::string& streetName, const std::string& edgeType, int priority); 63 64 65 /// @brief Destructor. 66 ~GUIEdge(); 67 68 69 /* @brief Returns the gl-ids of all known edges 70 * @param[in] includeInternal Whether to include ids of internal edges 71 */ 72 static std::vector<GUIGlID> getIDs(bool includeInternal); 73 74 /* @brief Returns the combined length of all edges 75 * @param[in] includeInternal Whether to include lengths of internal edges 76 * @param[in] eachLane Whether to count each lane separately 77 */ 78 static double getTotalLength(bool includeInternal, bool eachLane); 79 80 /// Returns the street's geometry 81 Boundary getBoundary() const; 82 83 /// returns the enumerated lane (!!! why not private with a friend?) 84 MSLane& getLane(int laneNo); 85 86 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, 106 GUISUMOAbstractView& parent); 107 108 109 /** @brief Returns an own parameter window 110 * 111 * @param[in] app The application needed to build the parameter window 112 * @param[in] parent The parent window needed to build the parameter window 113 * @return The built parameter window 114 * @see GUIGlObject::getParameterWindow 115 */ 116 virtual GUIParameterTableWindow* getParameterWindow(GUIMainWindow& app, 117 GUISUMOAbstractView& parent); 118 119 120 /** @brief Returns the boundary to which the view shall be centered in order to show the object 121 * 122 * @return The boundary the object is within 123 * @see GUIGlObject::getCenteringBoundary 124 */ 125 Boundary getCenteringBoundary() const; 126 127 /// @brief Returns the street name 128 const std::string getOptionalName() const; 129 130 /** @brief Draws the object 131 * @param[in] s The settings for the current view (may influence drawing) 132 * @see GUIGlObject::drawGL 133 */ 134 void drawGL(const GUIVisualizationSettings& s) const; 135 //@} 136 137 addPerson(MSTransportable * p)138 void addPerson(MSTransportable* p) const { 139 FXMutexLock locker(myLock); 140 MSEdge::addPerson(p); 141 } 142 removePerson(MSTransportable * p)143 void removePerson(MSTransportable* p) const { 144 FXMutexLock locker(myLock); 145 MSEdge::removePerson(p); 146 } 147 148 addContainer(MSTransportable * c)149 void addContainer(MSTransportable* c) const { 150 FXMutexLock locker(myLock); 151 MSEdge::addContainer(c); 152 } 153 removeContainer(MSTransportable * c)154 void removeContainer(MSTransportable* c) const { 155 FXMutexLock locker(myLock); 156 MSEdge::removeContainer(c); 157 } 158 159 int getVehicleNo() const; 160 std::string getVehicleIDs() const; 161 double getBruttoOccupancy() const; 162 double getAllowedSpeed() const; 163 /// @brief return flow based on meanSpead @note: may produced incorrect results when jammed 164 double getFlow() const; 165 /// @brief return meanSpead divided by allowedSpeed 166 double getRelativeSpeed() const; 167 168 /// @brief sets the color according to the currente settings 169 void setColor(const GUIVisualizationSettings& s) const; 170 171 /// @brief sets the color according to the current scheme index and some edge function 172 bool setFunctionalColor(const GUIColorer& c) const; 173 174 /// @brief sets multiple colors according to the current scheme index and edge function 175 bool setMultiColor(const GUIColorer& c) const; 176 177 /// @brief gets the color value according to the current scheme index 178 double getColorValue(const GUIVisualizationSettings& s, int activeScheme) const; 179 180 /// @brief gets the scaling value according to the current scheme index 181 double getScaleValue(int activeScheme) const; 182 183 /// @brief returns the segment closest to the given position 184 MESegment* getSegmentAtPosition(const Position& pos); 185 186 void drawMesoVehicles(const GUIVisualizationSettings& s) const; 187 188 /// @brief grant exclusive access to the mesoscopic state lock()189 void lock() const { 190 myLock.lock(); 191 } 192 193 /// @brief release exclusive access to the mesoscopic state unlock()194 void unlock() const { 195 myLock.unlock(); 196 } 197 198 /// @brief close this edge for traffic 199 void closeTraffic(const GUILane* lane); 200 201 /// @brief add a rerouter 202 void addRerouter(); 203 204 /// @brief return segment colors (meso) getSegmentColors()205 const std::vector<RGBColor>& getSegmentColors() const { 206 return mySegmentColors; 207 } 208 getMesoColor()209 RGBColor getMesoColor() const { 210 return myMesoColor; 211 } 212 213 /// @brief whether this lane is selected in the GUI 214 bool isSelected() const; 215 216 /// The color of the segments (cached) 217 mutable std::vector<RGBColor> mySegmentColors; 218 219 220 221 private: 222 /// @brief invalidated copy constructor 223 GUIEdge(const GUIEdge& s); 224 225 /// @brief invalidated assignment operator 226 GUIEdge& operator=(const GUIEdge& s); 227 228 229 private: 230 /// The mutex used to avoid concurrent updates of myPersons/ myContainers 231 mutable FXMutex myLock; 232 233 mutable RGBColor myMesoColor; 234 235 }; 236 237 238 #endif 239 240 /****************************************************************************/ 241 242