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 GUITriggeredRerouter.h 15 : /// @author Daniel Krajzewicz 16 : /// @author Jakob Erdmann 17 : /// @author Michael Behrisch 18 : /// @date Mon, 25.07.2005 19 : /// 20 : // Reroutes vehicles passing an edge (gui-version) 21 : /****************************************************************************/ 22 : #pragma once 23 : #include <config.h> 24 : 25 : #include <vector> 26 : #include <string> 27 : #include <foreign/rtree/SUMORTree.h> 28 : #include <microsim/trigger/MSTriggeredRerouter.h> 29 : #include <utils/gui/globjects/GUIGlObject_AbstractAdd.h> 30 : #include <utils/gui/globjects/GUIGLObjectPopupMenu.h> 31 : #include <gui/GUIManipulator.h> 32 : 33 : // =========================================================================== 34 : // class declarations 35 : // =========================================================================== 36 : class GUIEdge; 37 : 38 : // =========================================================================== 39 : // class definitions 40 : // =========================================================================== 41 : /** 42 : * @class GUITriggeredRerouter 43 : * @brief Reroutes vehicles passing an edge 44 : * One rerouter can be active on multiple edges. To reduce drawing load we 45 : * instantiate GUIGlObjects for every edge 46 : * XXX multiple rerouters active on the same edge are problematic 47 : */ 48 : class GUITriggeredRerouter 49 : : public MSTriggeredRerouter, 50 : public GUIGlObject_AbstractAdd { 51 : public: 52 : /** @brief Constructor 53 : * @param[in] id The id of the rerouter 54 : * @param[in] edges The edges the rerouter is placed at 55 : * @param[in] prob The probability to reroute vehicles 56 : * @param[in] off Whether the rerouter is off (not working) initially 57 : */ 58 : GUITriggeredRerouter(const std::string& id, const MSEdgeVector& edges, double prob, 59 : bool off, bool optional, SUMOTime timeThreshold, const std::string& vTypes, const Position& pos, 60 : SUMORTree& rtree); 61 : 62 : 63 : /// @brief Destructor 64 : ~GUITriggeredRerouter(); 65 : 66 : 67 : /** @brief Called when a closing tag occurs 68 : * 69 : * @param[in] element ID of the currently opened element 70 : * @exception ProcessError If something fails 71 : * @see GenericSAXHandler::myEndElement 72 : */ 73 : void myEndElement(int element); 74 : 75 : /// @name inherited from GUIGlObject 76 : //@{ 77 : 78 : /** @brief Returns an own popup-menu 79 : * 80 : * @param[in] app The application needed to build the popup-menu 81 : * @param[in] parent The parent window needed to build the popup-menu 82 : * @return The built popup-menu 83 : * @see GUIGlObject::getPopUpMenu 84 : */ 85 : GUIGLObjectPopupMenu* getPopUpMenu(GUIMainWindow& app, 86 : GUISUMOAbstractView& parent); 87 : 88 : /** @brief Returns an own parameter window 89 : * 90 : * @param[in] app The application needed to build the parameter window 91 : * @param[in] parent The parent window needed to build the parameter window 92 : * @return The built parameter window 93 : * @see GUIGlObject::getParameterWindow 94 : */ 95 : GUIParameterTableWindow* getParameterWindow(GUIMainWindow& app, 96 : GUISUMOAbstractView& parent); 97 : 98 : /// @brief return exaggeration associated with this GLObject 99 : double getExaggeration(const GUIVisualizationSettings& s) const; 100 : 101 : /** @brief Returns the boundary to which the view shall be centered in order to show the object 102 : * 103 : * @return The boundary the object is within 104 : * @see GUIGlObject::getCenteringBoundary 105 : */ 106 : Boundary getCenteringBoundary() const; 107 : 108 : /** @brief Draws the object 109 : * @param[in] s The settings for the current view (may influence drawing) 110 : * @see GUIGlObject::drawGL 111 : */ 112 : void drawGL(const GUIVisualizationSettings& s) const; 113 : //@} 114 : 115 : GUIManipulator* openManipulator(GUIMainWindow& app, 116 : GUISUMOAbstractView& parent); 117 : 118 : /// @brief shift route probabilities 119 : void shiftProbs(); 120 : 121 : public: 122 : 123 : enum RerouterEdgeType { 124 : REROUTER_TRIGGER_EDGE, 125 : REROUTER_CLOSED_EDGE, 126 : REROUTER_SWITCH_EDGE 127 : }; 128 : 129 : class GUITriggeredRerouterEdge : public GUIGlObject { 130 : 131 : public: 132 : GUITriggeredRerouterEdge(GUIEdge* edge, GUITriggeredRerouter* parent, RerouterEdgeType edgeType, int distIndex = -1); 133 : 134 : virtual ~GUITriggeredRerouterEdge(); 135 : 136 : /// @name inherited from GUIGlObject 137 : //@{ 138 : 139 : /** @brief Returns an own popup-menu 140 : * 141 : * @param[in] app The application needed to build the popup-menu 142 : * @param[in] parent The parent window needed to build the popup-menu 143 : * @return The built popup-menu 144 : * @see GUIGlObject::getPopUpMenu 145 : */ 146 : GUIGLObjectPopupMenu* getPopUpMenu(GUIMainWindow& app, 147 : GUISUMOAbstractView& parent); 148 : 149 : /** @brief Returns an own parameter window 150 : * 151 : * @param[in] app The application needed to build the parameter window 152 : * @param[in] parent The parent window needed to build the parameter window 153 : * @return The built parameter window 154 : * @see GUIGlObject::getParameterWindow 155 : */ 156 : GUIParameterTableWindow* getParameterWindow(GUIMainWindow& app, 157 : GUISUMOAbstractView& parent); 158 : 159 : /// @brief return exaggeration associated with this GLObject 160 : double getExaggeration(const GUIVisualizationSettings& s) const; 161 : 162 : /** @brief Returns the boundary to which the view shall be centered in order to show the object 163 : * 164 : * @return The boundary the object is within 165 : * @see GUIGlObject::getCenteringBoundary 166 : */ 167 : Boundary getCenteringBoundary() const; 168 : 169 : /** @brief Draws the object 170 : * @param[in] s The settings for the current view (may influence drawing) 171 : * @see GUIGlObject::drawGL 172 : */ 173 : void drawGL(const GUIVisualizationSettings& s) const; 174 : 175 : void onLeftBtnPress(void* data); 176 : 177 : RerouterEdgeType getRerouterEdgeType() const { 178 0 : return myEdgeType; 179 : } 180 : 181 : const MSEdge* getEdge() const { 182 0 : return myEdge; 183 : } 184 : //@} 185 : 186 : private: 187 : /// Definition of a positions container 188 : typedef std::vector<Position> PosCont; 189 : 190 : /// Definition of a rotation container 191 : typedef std::vector<double> RotCont; 192 : 193 : private: 194 : /// The parent rerouter to which this edge instance belongs 195 : GUITriggeredRerouter* myParent; 196 : 197 : /// The edge for which this visualization applies 198 : MSEdge* myEdge; 199 : 200 : /// whether this edge instance visualizes a closed edge 201 : const RerouterEdgeType myEdgeType; 202 : 203 : /// The positions in full-geometry mode 204 : PosCont myFGPositions; 205 : 206 : /// The rotations in full-geometry mode 207 : RotCont myFGRotations; 208 : 209 : /// The boundary of this rerouter 210 : Boundary myBoundary; 211 : 212 : /// The sign half-widths 213 : std::vector<double> myHalfWidths; 214 : 215 : /// @brief the index for this in edge in routeProbs 216 : int myDistIndex; 217 : }; 218 : 219 : public: 220 : class GUITriggeredRerouterPopupMenu : public GUIGLObjectPopupMenu { 221 0 : FXDECLARE(GUITriggeredRerouterPopupMenu) 222 : public: 223 : 224 : GUITriggeredRerouterPopupMenu(GUIMainWindow& app, 225 : GUISUMOAbstractView& parent, GUIGlObject& o); 226 : 227 : ~GUITriggeredRerouterPopupMenu(); 228 : 229 : /** @brief Called if the object's manipulator shall be shown */ 230 : long onCmdOpenManip(FXObject*, FXSelector, void*); 231 : 232 : protected: 233 0 : GUITriggeredRerouterPopupMenu() { } 234 : 235 : }; 236 : 237 : 238 : class GUIManip_TriggeredRerouter : public GUIManipulator { 239 0 : FXDECLARE(GUIManip_TriggeredRerouter) 240 : public: 241 : enum { 242 : MID_USER_DEF = FXDialogBox::ID_LAST, 243 : MID_PRE_DEF, 244 : MID_OPTION, 245 : MID_CLOSE, 246 : MID_SHIFT_PROBS, 247 : ID_LAST 248 : }; 249 : /// Constructor 250 : GUIManip_TriggeredRerouter(GUIMainWindow& app, const std::string& name, GUITriggeredRerouter& o); 251 : 252 : /// Destructor 253 : virtual ~GUIManip_TriggeredRerouter(); 254 : 255 : long onCmdClose(FXObject*, FXSelector, void*); 256 : long onCmdUserDef(FXObject*, FXSelector, void*); 257 : long onUpdUserDef(FXObject*, FXSelector, void*); 258 : long onCmdChangeOption(FXObject*, FXSelector, void*); 259 : long onCmdShiftProbs(FXObject*, FXSelector, void*); 260 : 261 : private: 262 : GUIMainWindow* myParent; 263 : 264 : FXint myChosenValue; 265 : 266 : FXDataTarget myChosenTarget; 267 : 268 : double myUsageProbability; 269 : 270 : FXRealSpinner* myUsageProbabilityDial; 271 : 272 : FXDataTarget myUsageProbabilityTarget; 273 : 274 : GUITriggeredRerouter* myObject; 275 : 276 : protected: 277 0 : GUIManip_TriggeredRerouter() { } 278 : 279 : }; 280 : 281 : 282 : private: 283 : /// The boundary of this rerouter 284 : Boundary myBoundary; 285 : 286 : std::vector<GUITriggeredRerouterEdge*> myEdgeVisualizations; 287 : 288 : int myShiftProbDistIndex; 289 : };