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 GNETLSEditorFrame.h 11 /// @author Jakob Erdmann 12 /// @date May 2011 13 /// @version $Id$ 14 /// 15 // The Widget for modifying traffic lights 16 /****************************************************************************/ 17 #ifndef GNETLSEditorFrame_h 18 #define GNETLSEditorFrame_h 19 20 // =========================================================================== 21 // included modules 22 // =========================================================================== 23 #include "GNEFrame.h" 24 #include <netbuild/NBTrafficLightLogic.h> 25 26 // =========================================================================== 27 // class declarations 28 // =========================================================================== 29 class NBTrafficLightDefinition; 30 class NBLoadedSUMOTLDef; 31 class NBOwnTLDef; 32 class GNEInternalLane; 33 34 // =========================================================================== 35 // class definitions 36 // =========================================================================== 37 /** 38 * @class GNETLSEditorFrame 39 * The Widget for modifying Traffic Lights (TLS) 40 */ 41 class GNETLSEditorFrame : public GNEFrame { 42 /// @brief FOX-declaration FXDECLARE(GNETLSEditorFrame)43 FXDECLARE(GNETLSEditorFrame) 44 45 public: 46 47 // =========================================================================== 48 // class TLSJunction 49 // =========================================================================== 50 51 class TLSJunction : protected FXGroupBox { 52 53 public: 54 /// @brief constructor 55 TLSJunction(GNETLSEditorFrame* TLSEditorParent); 56 57 /// @brief destructor 58 ~TLSJunction(); 59 60 /// @brief get current modified junction 61 GNEJunction* getCurrentJunction() const; 62 63 /// @brief set current junction 64 void setCurrentJunction(GNEJunction* junction); 65 66 /// @brief update descrition 67 void updateJunctionDescription() const; 68 69 private: 70 /// @brief pointer to TLSEditor Parent 71 GNETLSEditorFrame* myTLSEditorParent; 72 73 /// @brief label for junction ID 74 FXLabel* myLabelJunctionID; 75 76 /// @brief text field for junction ID 77 FXTextField* myTextFieldJunctionID; 78 79 /// @brief label for junction status 80 FXLabel* myLabelJunctionStatus; 81 82 /// @brief text field for junction status 83 FXTextField* myTextFieldJunctionStatus; 84 85 /// @brief the junction of the tls is being modified 86 GNEJunction* myCurrentJunction; 87 }; 88 89 // =========================================================================== 90 // class TLSDefinition 91 // =========================================================================== 92 93 class TLSDefinition : protected FXGroupBox { 94 95 public: 96 /// @brief constructor 97 TLSDefinition(GNETLSEditorFrame* TLSEditorParent); 98 99 /// @brief destructor 100 ~TLSDefinition(); 101 102 private: 103 /// @brief pointer to TLSEditor Parent 104 GNETLSEditorFrame* myTLSEditorParent; 105 106 /// @brief button for create new Traffic light program 107 FXButton* myNewTLProgram; 108 109 /// @brief button for delete traffic light program 110 FXButton* myDeleteTLProgram; 111 }; 112 113 // =========================================================================== 114 // class TLSAttributes 115 // =========================================================================== 116 117 class TLSAttributes : protected FXGroupBox { 118 119 public: 120 /// @brief constructor 121 TLSAttributes(GNETLSEditorFrame* TLSEditorParent); 122 123 /// @brief destructor 124 ~TLSAttributes(); 125 126 /// @brief initializes the definitions and corresponding listbox 127 void initTLSAttributes(GNEJunction* junction); 128 129 /// @brief clear TLS attributes 130 void clearTLSAttributes(); 131 132 /// @brief get current definition 133 NBTrafficLightDefinition* getCurrentTLSDefinition() const; 134 135 /// @brief get current offset in SUMOTIme 136 SUMOTime getOffset() const; 137 138 /// @brief set new offset 139 void setOffset(SUMOTime offset); 140 141 /// @brief get number of definitions 142 int getNumberOfTLSDefinitions() const; 143 144 /// @brief get number of programs 145 int getNumberOfPrograms() const; 146 147 private: 148 /// @brief pointer to TLSEditorParent 149 GNETLSEditorFrame* myTLSEditorParent; 150 151 /// @brief the list of Definitions for the current junction 152 std::vector<NBTrafficLightDefinition*> myTLSDefinitions; 153 154 /// @brief name label 155 FXLabel* myNameLabel; 156 157 /// @brief name text field 158 FXTextField* myNameTextField; 159 160 /// @brief program label 161 FXLabel* myProgramLabel; 162 163 /// @brief the comboBox for selecting the tl-definition to edit 164 FXComboBox* myProgramComboBox; 165 166 /// @brief offset label 167 FXLabel* myOffsetLabel; 168 169 /// @brief the control for modifying offset 170 FXTextField* myOffsetTextField; 171 }; 172 173 // =========================================================================== 174 // class TLSPhases 175 // =========================================================================== 176 177 class TLSPhases : protected FXGroupBox { 178 179 public: 180 /// @brief constructor 181 TLSPhases(GNETLSEditorFrame* TLSEditorParent); 182 183 /// @brief destructor 184 ~TLSPhases(); 185 186 /// @brief get phase table 187 FXTable* getPhaseTable() const; 188 189 /**@brief initialies the phase table 190 * @param[in] index The index to select 191 */ 192 void initPhaseTable(int index = 0); 193 194 /// @brief show cycle duration 195 void showCycleDuration(); 196 197 /// @brief hide cycle duration 198 void hideCycleDuration(); 199 200 /// @brief recomputes cycle duration and updates label 201 void updateCycleDuration(); 202 203 private: 204 /// @brief pointer to TLSEditor Parent 205 GNETLSEditorFrame* myTLSEditorParent; 206 207 /// @brief font for the phase table 208 FXFont* myTableFont; 209 210 /// @brief window for oversized phase tables 211 FXScrollWindow* myTableScroll; 212 213 /// @brief table for selecting and rearranging phases and for changing duration 214 FXTable* myPhaseTable; 215 216 /// @brief label with the cycle duration 217 FXLabel* myCycleDuration; 218 219 /// @brief insert new phase button 220 FXButton* myInsertDuplicateButton; 221 222 /// @brief delete phase button 223 FXButton* myDeleteSelectedPhaseButton; 224 }; 225 226 // =========================================================================== 227 // class TLSModifications 228 // =========================================================================== 229 230 class TLSModifications : protected FXGroupBox { 231 232 public: 233 /// @brief constructor 234 TLSModifications(GNETLSEditorFrame* TLSEditorParent); 235 236 /// @brief destructor 237 ~TLSModifications(); 238 239 /// @brief check if current TLS was modified 240 bool checkHaveModifications() const; 241 242 /// @brief set if current TLS was modified 243 void setHaveModifications(bool value); 244 245 private: 246 /// @brief pointer to TLSEditor Parent 247 GNETLSEditorFrame* myTLSEditorParent; 248 249 /// @brief button for cancel modifications 250 FXButton* myDiscardModificationsButtons; 251 252 /// @brief button for save modifications 253 FXButton* mySaveModificationsButtons; 254 255 /// @brief whether the current tls was modified 256 bool myHaveModifications; 257 }; 258 259 // =========================================================================== 260 // class TLSFile 261 // =========================================================================== 262 263 class TLSFile : protected FXGroupBox { 264 /// @brief FOX-declaration 265 FXDECLARE(GNETLSEditorFrame::TLSFile) 266 267 public: 268 /// @brief constructor 269 TLSFile(GNETLSEditorFrame* TLSEditorParent); 270 271 /// @brief destructor 272 ~TLSFile(); 273 274 /// @name FOX-callbacks 275 /// @{ 276 /// @brief load TLS Program from an additional file 277 long onCmdLoadTLSProgram(FXObject*, FXSelector, void*); 278 279 /// @brief save TLS Programm to an additional file 280 long onCmdSaveTLSProgram(FXObject*, FXSelector, void*); 281 282 /// @brief enable buttons, only when a tlLogic is being edited 283 long onUpdNeedsDef(FXObject*, FXSelector, void*); 284 /// @} 285 286 protected: 287 /// @brief FOX needs this TLSFile()288 TLSFile() {} 289 290 private: 291 /// @brief pointer to TLSEditor Parent 292 GNETLSEditorFrame* myTLSEditorParent; 293 294 /// @brief button for load TLS Programs 295 FXButton* myLoadTLSProgramButton; 296 297 /// @brief button for save TLS Programs 298 FXButton* mySaveTLSProgramButton; 299 300 /// @brief convert SUMOTime into string 301 std::string writeSUMOTime(SUMOTime steps); 302 }; 303 304 305 /**@brief Constructor 306 * @brief parent FXHorizontalFrame in which this GNEFrame is placed 307 * @brief viewNet viewNet that uses this GNEFrame 308 */ 309 GNETLSEditorFrame(FXHorizontalFrame* horizontalFrameParent, GNEViewNet* viewNet); 310 311 /// @brief Destructor 312 ~GNETLSEditorFrame(); 313 314 /// @brief edits the traffic light for the given junction 315 /// @param[in] junction The junction of which the traffic light shall be edited 316 void editJunction(GNEJunction* junction); 317 318 /// @brief check if modifications in TLS was saved 319 bool isTLSSaved(); 320 321 /// @brief parse TLS Programs from a file 322 bool parseTLSPrograms(const std::string& file); 323 324 /// @name FOX-callbacks 325 /// @{ 326 /// @brief Called when the user presses the OK-Button 327 /// @note saves any modifications 328 long onCmdOK(FXObject*, FXSelector, void*); 329 330 /// @brief Called when the user presses the Cancel-button 331 /// @note discards any modifications 332 long onCmdCancel(FXObject*, FXSelector, void*); 333 334 /// @brief Called when the user presses the button Toogle 335 long onCmdToggle(FXObject*, FXSelector, void*); 336 337 /// @brief Called when the user presses the button Guess 338 long onCmdGuess(FXObject*, FXSelector, void*); 339 340 /// @brief Called when the user creates a TLS 341 long onCmdDefCreate(FXObject*, FXSelector, void*); 342 343 /// @brief Called when the user deletes a TLS 344 long onCmdDefDelete(FXObject*, FXSelector, void*); 345 346 /// @brief Called when the user changes the offset of a TLS 347 long onCmdDefOffset(FXObject*, FXSelector, void*); 348 349 /// @brief Called when the user switchs a TLS 350 long onCmdDefSwitch(FXObject*, FXSelector, void*); 351 352 /// @brief Called when the user renames a TLS 353 long onCmdDefRename(FXObject*, FXSelector, void*); 354 355 /// @brief Called when the user sub-renames a TLS 356 long onCmdDefSubRename(FXObject*, FXSelector, void*); 357 358 /// @brief Called when the user adds a OFF 359 long onCmdDefAddOff(FXObject*, FXSelector, void*); 360 361 /// @brief Called when the user switchs a Phase 362 long onCmdPhaseSwitch(FXObject*, FXSelector, void*); 363 364 /// @brief Called when the user creates a Phase 365 long onCmdPhaseCreate(FXObject*, FXSelector, void*); 366 367 /// @brief Called when the user deletes a Phase 368 long onCmdPhaseDelete(FXObject*, FXSelector, void*); 369 370 /// @brief Called when the user cleans up states 371 long onCmdCleanup(FXObject*, FXSelector, void*); 372 373 /// @brief Called when the user cleans up states 374 long onCmdAddUnused(FXObject*, FXSelector, void*); 375 376 /// @brief Called when the user edits a Phase 377 long onCmdPhaseEdit(FXObject*, FXSelector, void*); 378 379 /// @brief Called when the user makes RILSA 380 long onCmdMakeRILSAConforming(FXObject*, FXSelector, void*); 381 382 /// @brief Called when occurs an update of switch definition 383 long onUpdDefSwitch(FXObject*, FXSelector, void*); 384 385 /// @brief Called when occurs an update of needs definition 386 long onUpdNeedsDef(FXObject*, FXSelector, void*); 387 388 /// @brief Called when occurs an update of needs definition an dphase 389 long onUpdNeedsDefAndPhase(FXObject*, FXSelector, void*); 390 391 /// @brief Called when occurs an update of create definition 392 long onUpdDefCreate(FXObject*, FXSelector, void*); 393 394 /// @brief Called when occurs an update of modified 395 long onUpdModified(FXObject*, FXSelector, void*); 396 /// @} 397 398 /// @brief update phase definition for the current traffic light and phase 399 void handleChange(GNEInternalLane* lane); 400 401 /// @brief update phase definition for the current traffic light and phase 402 void handleMultiChange(GNELane* lane, FXObject* obj, FXSelector sel, void* data); 403 404 /// @brief whether the given edge is controlled by the currently edited tlDef 405 bool controlsEdge(GNEEdge& edge) const; 406 407 /// @brief whether the current traffic light uses fixed phase durations 408 bool fixedDuration() const; 409 410 protected: 411 /// @brief FOX needs this GNETLSEditorFrame()412 GNETLSEditorFrame() {} 413 414 /// @brief converts to SUMOTime 415 static SUMOTime getSUMOTime(const FXString& string); 416 417 private: 418 /// @brief modul for TLS Junction 419 GNETLSEditorFrame::TLSJunction* myTLSJunction; 420 421 /// @brief modul for TLS Definition 422 GNETLSEditorFrame::TLSDefinition* myTLSDefinition; 423 424 /// @brief modul for TLS attributes 425 GNETLSEditorFrame::TLSAttributes* myTLSAttributes; 426 427 /// @brief modul for load/Save TLS Modifications 428 GNETLSEditorFrame::TLSModifications* myTLSModifications; 429 430 /// @brief modul for TLS Phases 431 GNETLSEditorFrame::TLSPhases* myTLSPhases; 432 433 /// @brief modul for load/Save TLS Programs 434 GNETLSEditorFrame::TLSFile* myTLSFile; 435 436 /// @brief the internal lanes belonging the the current junction indexed by their tl-index 437 typedef std::map<int, std::vector<GNEInternalLane*> > TLIndexMap; 438 TLIndexMap myInternalLanes; 439 440 /// @brief the traffic light definition being edited 441 NBLoadedSUMOTLDef* myEditedDef; 442 443 /// @brief index of the phase being shown 444 int myPhaseIndex; 445 446 /// @brief cleans up previous lanes 447 void cleanup(); 448 449 /// @brief builds internal lanes for the given tlDef 450 void buildIinternalLanes(NBTrafficLightDefinition* tlDef); 451 452 /// @brief the phase of the current traffic light 453 const std::vector<NBTrafficLightLogic::PhaseDefinition>& getPhases(); 454 455 /// @brief convert duration (potentially undefined) to string 456 static std::string varDurString(SUMOTime dur); 457 }; 458 459 460 #endif 461 462 /****************************************************************************/ 463 464