SUMO - Simulation of Urban MObility
GNETLSEditorFrame.cpp
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3 // Copyright (C) 2001-2018 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 /****************************************************************************/
15 // The Widget for modifying traffic lights
16 /****************************************************************************/
17 
18 
19 // ===========================================================================
20 // included modules
21 // ===========================================================================
22 #include <config.h>
23 
29 #include <utils/xml/XMLSubSys.h>
32 #include <netedit/GNENet.h>
36 #include <netedit/GNEUndoList.h>
39 
40 #include "GNETLSEditorFrame.h"
41 
42 // ===========================================================================
43 // FOX callback mapping
44 // ===========================================================================
45 
46 FXDEFMAP(GNETLSEditorFrame) GNETLSEditorFrameMap[] = {
47  FXMAPFUNC(SEL_COMMAND, MID_CANCEL, GNETLSEditorFrame::onCmdCancel),
48  FXMAPFUNC(SEL_UPDATE, MID_CANCEL, GNETLSEditorFrame::onUpdModified),
49  FXMAPFUNC(SEL_COMMAND, MID_OK, GNETLSEditorFrame::onCmdOK),
50  FXMAPFUNC(SEL_UPDATE, MID_OK, GNETLSEditorFrame::onUpdModified),
75 };
76 
77 FXDEFMAP(GNETLSEditorFrame::TLSFile) TLSFileMap[] = {
82 };
83 
84 // Object implementation
85 FXIMPLEMENT(GNETLSEditorFrame, FXVerticalFrame, GNETLSEditorFrameMap, ARRAYNUMBER(GNETLSEditorFrameMap))
86 FXIMPLEMENT(GNETLSEditorFrame::TLSFile, FXGroupBox, TLSFileMap, ARRAYNUMBER(TLSFileMap))
87 
88 
89 // ===========================================================================
90 // method definitions
91 // ===========================================================================
92 
93 GNETLSEditorFrame::GNETLSEditorFrame(FXHorizontalFrame* horizontalFrameParent, GNEViewNet* viewNet):
94  GNEFrame(horizontalFrameParent, viewNet, "Edit Traffic Light"),
95  myEditedDef(nullptr) {
96 
97  // create TLSJunction modul
98  myTLSJunction = new GNETLSEditorFrame::TLSJunction(this);
99 
100  // create TLSDefinition modul
101  myTLSDefinition = new GNETLSEditorFrame::TLSDefinition(this);
102 
103  // create TLSAttributes modul
104  myTLSAttributes = new GNETLSEditorFrame::TLSAttributes(this);
105 
106  // create TLSModifications modul
107  myTLSModifications = new GNETLSEditorFrame::TLSModifications(this);
108 
109  // create TLSPhases modul
110  myTLSPhases = new GNETLSEditorFrame::TLSPhases(this);
111 
112  // create TLSFile modul
113  myTLSFile = new GNETLSEditorFrame::TLSFile(this);
114 
115  // "Add 'off' program"
116  /*
117  new FXButton(myContentFrame, "Add \"Off\"-Program\t\tAdds a program for switching off this traffic light",
118  0, this, MID_GNE_TLSFRAME_ADDOFF, GUIDesignButton);
119  */
120 }
121 
122 
124  cleanup();
125 }
126 
127 
128 void
131  onCmdCancel(nullptr, 0, nullptr);
132  myViewNet->getUndoList()->p_begin("modifying traffic light definition");
137  } else {
138  myViewNet->setStatusBarText("Unsaved modifications. Abort or Save");
139  }
140 }
141 
142 
143 bool
146  // write warning if netedit is running in testing mode
147  WRITE_DEBUG("Opening question FXMessageBox 'save TLS'");
148  // open question box
149  FXuint answer = FXMessageBox::question(this, MBOX_YES_NO_CANCEL,
150  "Save TLS Changes", "%s",
151  "There is unsaved changes in current edited traffic light.\nDo you want to save it before changing mode?");
152  if (answer == MBOX_CLICKED_YES) { //1:yes, 2:no, 4:esc/cancel
153  // write warning if netedit is running in testing mode
154  WRITE_DEBUG("Closed FXMessageBox 'save TLS' with 'YES'");
155  // save modifications
156  onCmdOK(nullptr, 0, nullptr);
157  return true;
158  } else if (answer == MBOX_CLICKED_NO) {
159  // write warning if netedit is running in testing mode
160  WRITE_DEBUG("Closed FXMessageBox 'save TLS' with 'No'");
161  // cancel modifications
162  onCmdCancel(nullptr, 0, nullptr);
163  return true;
164  } else {
165  // write warning if netedit is running in testing mode
166  WRITE_DEBUG("Closed FXMessageBox 'save TLS' with 'Cancel'");
167  // abort changing mode
168  return false;
169  }
170  } else {
171  return true;
172  }
173 }
174 
175 
176 bool
177 GNETLSEditorFrame::parseTLSPrograms(const std::string& file) {
179  NBTrafficLightLogicCont tmpTLLCont;;
180  NIXMLTrafficLightsHandler tllHandler(tmpTLLCont, myViewNet->getNet()->getEdgeCont());
181  // existing definitions must be available to update their programs
182  std::set<NBTrafficLightDefinition*> origDefs;
183  for (NBTrafficLightDefinition* def : tllCont.getDefinitions()) {
184  // make a copy of every program
185  NBTrafficLightLogic* logic = tllCont.getLogic(def->getID(), def->getProgramID());
186  if (logic != nullptr) {
187  NBTrafficLightDefinition* copy = new NBLoadedSUMOTLDef(def, logic);
188  std::vector<NBNode*> nodes = def->getNodes();
189  for (auto it_node : nodes) {
190  GNEJunction* junction = myViewNet->getNet()->retrieveJunction(it_node->getID());
191  myViewNet->getUndoList()->add(new GNEChange_TLS(junction, def, false, false), true);
192  myViewNet->getUndoList()->add(new GNEChange_TLS(junction, copy, true), true);
193  }
194  tmpTLLCont.insert(copy);
195  origDefs.insert(copy);
196  } else {
197  WRITE_WARNING("tlLogic '" + def->getID() + "', program '" + def->getProgramID() + "' could not be built");
198  }
199  }
200  //std::cout << " initialized tmpCont with " << origDefs.size() << " defs\n";
201  XMLSubSys::runParser(tllHandler, file);
202 
203  std::vector<NBLoadedSUMOTLDef*> loadedTLS;
204  for (NBTrafficLightDefinition* def : tmpTLLCont.getDefinitions()) {
205  NBLoadedSUMOTLDef* sdef = dynamic_cast<NBLoadedSUMOTLDef*>(def);
206  if (sdef != nullptr) {
207  loadedTLS.push_back(sdef);
208  }
209  }
210  myViewNet->setStatusBarText("Loaded " + toString(loadedTLS.size()) + " programs");
211  for (auto def : loadedTLS) {
212  if (origDefs.count(def) != 0) {
213  // already add to undolist before
214  //std::cout << " skip " << def->getDescription() << "\n";
215  continue;
216  }
217  std::vector<NBNode*> nodes = def->getNodes();
218  //std::cout << " add " << def->getDescription() << " for nodes=" << toString(nodes) << "\n";
219  for (auto it_node : nodes) {
220  GNEJunction* junction = myViewNet->getNet()->retrieveJunction(it_node->getID());
221  //myViewNet->getUndoList()->add(new GNEChange_TLS(junction, myTLSEditorParent->myEditedDef, false), true);
222  myViewNet->getUndoList()->add(new GNEChange_TLS(junction, def, true), true);
223  }
224  }
225  // clean up temporary container to avoid deletion of defs when it's destruct is called
226  for (NBTrafficLightDefinition* def : tmpTLLCont.getDefinitions()) {
227  tmpTLLCont.removeProgram(def->getID(), def->getProgramID(), false);
228  }
229  return true;
230 }
231 
232 
233 long
234 GNETLSEditorFrame::onCmdCancel(FXObject*, FXSelector, void*) {
235  if (myTLSJunction->getCurrentJunction() != nullptr) {
237  cleanup();
238  myViewNet->update();
239  }
240  return 1;
241 }
242 
243 
244 long
245 GNETLSEditorFrame::onCmdOK(FXObject*, FXSelector, void*) {
246  if (myTLSJunction->getCurrentJunction() != nullptr) {
249  std::vector<NBNode*> nodes = oldDefinition->getNodes();
250  for (auto it : nodes) {
251  GNEJunction* junction = myViewNet->getNet()->retrieveJunction(it->getID());
252  myViewNet->getUndoList()->add(new GNEChange_TLS(junction, oldDefinition, false), true);
253  myViewNet->getUndoList()->add(new GNEChange_TLS(junction, myEditedDef, true), true);
254  }
255  myEditedDef = nullptr;
257  cleanup();
258  myViewNet->update();
259  } else {
260  onCmdCancel(nullptr, 0, nullptr);
261  }
262  }
263  return 1;
264 }
265 
266 
267 long
268 GNETLSEditorFrame::onCmdDefCreate(FXObject*, FXSelector, void*) {
270  // abort because we onCmdOk assumes we wish to save an edited definition
271  onCmdCancel(nullptr, 0, nullptr);
272  // check that current junction has two or more edges
273  if ((junction->getGNEIncomingEdges().size() > 0) && (junction->getGNEOutgoingEdges().size() > 0)) {
276  } else {
277  myViewNet->getUndoList()->add(new GNEChange_TLS(junction, nullptr, true, true), true);
278  }
279  editJunction(junction);
280  } else {
281  // write warning if netedit is running in testing mode
282  WRITE_DEBUG("Opening warning FXMessageBox 'invalid TLS'");
283  // open question box
284  FXMessageBox::warning(this, MBOX_OK,
285  "TLS cannot be created", "%s",
286  "Traffic Light cannot be created because junction must have\n at least one incoming edge and one outgoing edge.");
287  // write warning if netedit is running in testing mode
288  WRITE_DEBUG("Closed FXMessageBox 'invalid TLS'");
289  }
290  return 1;
291 }
292 
293 
294 long
295 GNETLSEditorFrame::onCmdDefDelete(FXObject*, FXSelector, void*) {
297  const bool changeType = myTLSAttributes->getNumberOfTLSDefinitions() == 1;
299  onCmdCancel(nullptr, 0, nullptr); // abort because onCmdOk assumes we wish to save an edited definition
300  if (changeType) {
302  } else {
303  myViewNet->getUndoList()->add(new GNEChange_TLS(junction, tlDef, false), true);
304  }
305  return 1;
306 }
307 
308 
309 long
310 GNETLSEditorFrame::onCmdDefSwitch(FXObject*, FXSelector, void*) {
311  assert(myTLSJunction->getCurrentJunction() != 0);
314  // logic may not have been recomputed yet. recompute to be sure
317  NBTrafficLightLogic* tllogic = tllCont.getLogic(tlDef->getID(), tlDef->getProgramID());
318  if (tllogic != nullptr) {
319  // now we can be sure that the tlDef is up to date (i.e. re-guessed)
320  buildIinternalLanes(tlDef);
321  // create working copy from original def
322  delete myEditedDef;
323  myEditedDef = new NBLoadedSUMOTLDef(tlDef, tllogic);
328  } else {
329  // tlDef has no valid logic (probably because id does not control any links
330  onCmdCancel(nullptr, 0, nullptr);
331  myViewNet->setStatusBarText("Traffic light does not control any links");
332  }
333  return 1;
334 }
335 
336 
337 long
338 GNETLSEditorFrame::onUpdDefSwitch(FXObject* o, FXSelector, void*) {
340  o->handle(this, FXSEL(SEL_COMMAND, enable ? FXWindow::ID_ENABLE : FXWindow::ID_DISABLE), nullptr);
341  return 1;
342 }
343 
344 
345 long
346 GNETLSEditorFrame::onUpdNeedsDef(FXObject* o, FXSelector, void*) {
347  const bool enable = myTLSAttributes->getNumberOfTLSDefinitions() > 0;
348  o->handle(this, FXSEL(SEL_COMMAND, enable ? FXWindow::ID_ENABLE : FXWindow::ID_DISABLE), nullptr);
349  return 1;
350 }
351 
352 
353 long
354 GNETLSEditorFrame::onUpdNeedsDefAndPhase(FXObject* o, FXSelector, void*) {
355  // do not delete the last phase
356  const bool enable = myTLSAttributes->getNumberOfTLSDefinitions() > 0 && myTLSPhases->getPhaseTable()->getNumRows() > 1;
357  o->handle(this, FXSEL(SEL_COMMAND, enable ? FXWindow::ID_ENABLE : FXWindow::ID_DISABLE), nullptr);
358  return 1;
359 }
360 
361 
362 long
363 GNETLSEditorFrame::onUpdDefCreate(FXObject* o, FXSelector, void*) {
364  const bool enable = myTLSJunction->getCurrentJunction() != nullptr && !myTLSModifications->checkHaveModifications();
365  o->handle(this, FXSEL(SEL_COMMAND, enable ? FXWindow::ID_ENABLE : FXWindow::ID_DISABLE), nullptr);
366  return 1;
367 }
368 
369 
370 long
371 GNETLSEditorFrame::onUpdModified(FXObject* o, FXSelector, void*) {
373  o->handle(this, FXSEL(SEL_COMMAND, enable ? FXWindow::ID_ENABLE : FXWindow::ID_DISABLE), nullptr);
374  return 1;
375 }
376 
377 
378 
379 long
380 GNETLSEditorFrame::onCmdDefOffset(FXObject*, FXSelector, void*) {
383  return 1;
384 }
385 
386 
387 long
388 GNETLSEditorFrame::onCmdDefRename(FXObject*, FXSelector, void*) {
389  return 1;
390 }
391 
392 
393 long
394 GNETLSEditorFrame::onCmdDefSubRename(FXObject*, FXSelector, void*) {
395  return 1;
396 }
397 
398 
399 long
400 GNETLSEditorFrame::onCmdDefAddOff(FXObject*, FXSelector, void*) {
401  return 1;
402 }
403 
404 
405 long
406 GNETLSEditorFrame::onCmdGuess(FXObject*, FXSelector, void*) {
407  return 1;
408 }
409 
410 
411 long
412 GNETLSEditorFrame::onCmdPhaseSwitch(FXObject*, FXSelector, void*) {
413  const int index = myTLSPhases->getPhaseTable()->getCurrentRow();
414  const NBTrafficLightLogic::PhaseDefinition& phase = getPhases()[index];
415  myTLSPhases->getPhaseTable()->selectRow(index);
416  // need not hold since links could have been deleted somewhere else and indices may be reused
417  // assert(phase.state.size() == myInternalLanes.size());
418  for (auto it : myInternalLanes) {
419  int tlIndex = it.first;
420  std::vector<GNEInternalLane*> lanes = it.second;
422  if (tlIndex >= 0 && tlIndex < (int)phase.state.size()) {
423  state = (LinkState)phase.state[tlIndex];
424  }
425  for (auto it_lane : lanes) {
426  it_lane->setLinkState(state);
427  }
428  }
429  myViewNet->update();
430  return 1;
431 }
432 
433 
434 long
435 GNETLSEditorFrame::onCmdPhaseCreate(FXObject*, FXSelector, void*) {
437  // allows insertion at first position by deselecting via arrow keys
438  int newIndex = myTLSPhases->getPhaseTable()->getSelStartRow() + 1;
439  int oldIndex = MAX2(0, myTLSPhases->getPhaseTable()->getSelStartRow());
440  // copy current row
441  const bool fixed = myEditedDef->getType() == TLTYPE_STATIC;
442  SUMOTime duration = getSUMOTime(myTLSPhases->getPhaseTable()->getItemText(oldIndex, 0));
443  std::string state = myTLSPhases->getPhaseTable()->getItemText(oldIndex, fixed ? 1 : 3).text();
444 
445  std::set<int> crossingIndices;
446  for (NBNode* n : myEditedDef->getNodes()) {
447  for (NBNode::Crossing* c : n->getCrossings()) {
448  crossingIndices.insert(c->tlLinkIndex);
449  crossingIndices.insert(c->tlLinkIndex2);
450  }
451  }
452 
453  // smart adapations for new state
454  bool haveGreen = false;
455  bool haveYellow = false;
456  for (char c : state) {
458  haveGreen = true;
459  } else if (c == LINKSTATE_TL_YELLOW_MAJOR || c == LINKSTATE_TL_YELLOW_MINOR) {
460  haveYellow = true;
461  }
462  }
463  const OptionsCont& oc = OptionsCont::getOptions();
464  if (haveGreen && haveYellow) {
465  // guess left-mover state
466  duration = TIME2STEPS(oc.getInt("tls.left-green.time"));
467  for (int i = 0; i < (int)state.size(); i++) {
468  if (state[i] == LINKSTATE_TL_YELLOW_MAJOR || state[i] == LINKSTATE_TL_YELLOW_MINOR) {
469  state[i] = LINKSTATE_TL_RED;
470  } else if (state[i] == LINKSTATE_TL_GREEN_MINOR) {
471  state[i] = LINKSTATE_TL_GREEN_MAJOR;
472  }
473  }
474  } else if (haveGreen) {
475  // guess yellow state
477  duration = TIME2STEPS(myEditedDef->computeBrakingTime(oc.getFloat("tls.yellow.min-decel")));
478  for (int i = 0; i < (int)state.size(); i++) {
479  if (state[i] == LINKSTATE_TL_GREEN_MAJOR || state[i] == LINKSTATE_TL_GREEN_MINOR) {
480  if (crossingIndices.count(i) == 0) {
481  state[i] = LINKSTATE_TL_YELLOW_MINOR;
482  } else {
483  state[i] = LINKSTATE_TL_RED;
484  }
485  }
486  }
487  } else if (haveYellow) {
488  duration = TIME2STEPS(oc.isDefault("tls.allred.time") ? 2 : oc.getInt("tls.allred.time"));
489  // guess all-red state
490  for (int i = 0; i < (int)state.size(); i++) {
491  if (state[i] == LINKSTATE_TL_YELLOW_MAJOR || state[i] == LINKSTATE_TL_YELLOW_MINOR) {
492  state[i] = LINKSTATE_TL_RED;
493  }
494  }
495  }
496 
497  myEditedDef->getLogic()->addStep(duration, state, newIndex);
498  myTLSPhases->getPhaseTable()->setCurrentItem(newIndex, 0);
499  myTLSPhases->initPhaseTable(newIndex);
500  myTLSPhases->getPhaseTable()->setFocus();
501  return 1;
502 }
503 
504 
505 long
506 GNETLSEditorFrame::onCmdPhaseDelete(FXObject*, FXSelector, void*) {
508  const int newRow = MAX2((int)0, (int)myTLSPhases->getPhaseTable()->getCurrentRow() - 1);
509  myEditedDef->getLogic()->deletePhase(myTLSPhases->getPhaseTable()->getCurrentRow());
510  myTLSPhases->initPhaseTable(newRow);
511  myTLSPhases->getPhaseTable()->setFocus();
512  return 1;
513 }
514 
515 
516 long
517 GNETLSEditorFrame::onCmdCleanup(FXObject*, FXSelector, void*) {
520  myTLSPhases->getPhaseTable()->setFocus();
521  return 1;
522 }
523 
524 
525 long
526 GNETLSEditorFrame::onCmdAddUnused(FXObject*, FXSelector, void*) {
528  myEditedDef->getLogic()->getNumLinks() + 1);
531  myTLSPhases->getPhaseTable()->setFocus();
532  return 1;
533 }
534 
535 
536 long
537 GNETLSEditorFrame::onCmdPhaseEdit(FXObject*, FXSelector, void* ptr) {
538  /* @note: there is a bug when copying/pasting rows: when this handler is
539  * called the value of the cell is not yet updated. This means you have to
540  * click inside the cell and hit enter to actually update the value */
541  FXTablePos* tp = (FXTablePos*)ptr;
542  FXString value = myTLSPhases->getPhaseTable()->getItemText(tp->row, tp->col);
543  const bool fixed = myEditedDef->getType() == TLTYPE_STATIC;
544  if (tp->col == 0) {
545  // duration edited
546  if (GNEAttributeCarrier::canParse<double>(value.text())) {
547  SUMOTime duration = getSUMOTime(value);
548  if (duration > 0) {
549  myEditedDef->getLogic()->setPhaseDuration(tp->row, duration);
552  return 1;
553  }
554  }
555  // input error, reset value
556  myTLSPhases->getPhaseTable()->setItemText(tp->row, 0, toString(STEPS2TIME(getPhases()[tp->row].duration)).c_str());
557  } else if (!fixed && tp->col == 1) {
558  // minDur edited
559  if (GNEAttributeCarrier::canParse<double>(value.text())) {
560  SUMOTime minDur = getSUMOTime(value);
561  if (minDur > 0) {
562  myEditedDef->getLogic()->setPhaseMinDuration(tp->row, minDur);
564  return 1;
565  }
566  } else if (StringUtils::prune(value.text()).empty()) {
569  return 1;
570  }
571  // input error, reset value
572  myTLSPhases->getPhaseTable()->setItemText(tp->row, 1, varDurString(getPhases()[tp->row].minDur).c_str());
573  } else if (!fixed && tp->col == 2) {
574  // minDur edited
575  if (GNEAttributeCarrier::canParse<double>(value.text())) {
576  SUMOTime maxDur = getSUMOTime(value);
577  if (maxDur > 0) {
578  myEditedDef->getLogic()->setPhaseMaxDuration(tp->row, maxDur);
580  return 1;
581  }
582  } else if (StringUtils::prune(value.text()).empty()) {
585  return 1;
586  }
587  // input error, reset value
588  myTLSPhases->getPhaseTable()->setItemText(tp->row, 2, varDurString(getPhases()[tp->row].maxDur).c_str());
589  } else {
590  // state edited
591  try {
592  // insert phase with new step and delete the old phase
593  myEditedDef->getLogic()->addStep(getPhases()[tp->row].duration, value.text(), tp->row);
594  myEditedDef->getLogic()->deletePhase(tp->row + 1);
596  onCmdPhaseSwitch(nullptr, 0, nullptr);
597  } catch (ProcessError&) {
598  // input error, reset value
599  myTLSPhases->getPhaseTable()->setItemText(tp->row, 1, getPhases()[tp->row].state.c_str());
600  }
601  }
602  return 1;
603 }
604 
605 
606 void
610  }
611  // clean data structures
614  delete myEditedDef;
615  myEditedDef = nullptr;
616  buildIinternalLanes(nullptr); // only clears
617  // clean up controls
619  myTLSPhases->initPhaseTable(); // only clears when there are no definitions
622 }
623 
624 
625 void
628  // clean up previous objects
629  for (auto it : myInternalLanes) {
630  for (auto it_intLanes : it.second) {
631  rtree.removeAdditionalGLObject(it_intLanes);
632  delete it_intLanes;
633  }
634  }
635  myInternalLanes.clear();
636  // create new internal lanes
637  if (tlDef != nullptr) {
638  const int NUM_POINTS = 10;
641  std::string innerID = ":" + nbn->getID(); // see NWWriter_SUMO::writeInternalEdges
642  const NBConnectionVector& links = tlDef->getControlledLinks();
643  for (auto it : links) {
644  int tlIndex = it.getTLIndex();
645  PositionVector shape = it.getFrom()->getToNode()->computeInternalLaneShape(it.getFrom(), NBEdge::Connection(it.getFromLane(),
646  it.getTo(), it.getToLane()), NUM_POINTS);
647  GNEInternalLane* ilane = new GNEInternalLane(this, innerID + '_' + toString(tlIndex), shape, tlIndex);
648  rtree.addAdditionalGLObject(ilane);
649  myInternalLanes[tlIndex].push_back(ilane);
650  }
651  for (NBNode* nbn : tlDef->getNodes()) {
652  for (auto c : nbn->getCrossings()) {
653  if (c->tlLinkIndex2 > 0 && c->tlLinkIndex2 != c->tlLinkIndex) {
654  // draw both directions
655  PositionVector forward = c->shape;
656  forward.move2side(c->width / 4);
657  GNEInternalLane* ilane = new GNEInternalLane(this, c->id, forward, c->tlLinkIndex);
658  rtree.addAdditionalGLObject(ilane);
659  myInternalLanes[c->tlLinkIndex].push_back(ilane);
660 
661  PositionVector backward = c->shape.reverse();
662  backward.move2side(c->width / 4);
663  GNEInternalLane* ilane2 = new GNEInternalLane(this, c->id + "_r", backward, c->tlLinkIndex2);
664  rtree.addAdditionalGLObject(ilane2);
665  myInternalLanes[c->tlLinkIndex2].push_back(ilane2);
666  } else {
667  // draw only one lane for both directions
668  GNEInternalLane* ilane = new GNEInternalLane(this, c->id, c->shape, c->tlLinkIndex);
669  rtree.addAdditionalGLObject(ilane);
670  myInternalLanes[c->tlLinkIndex].push_back(ilane);
671  }
672  }
673  }
674  }
675 }
676 
677 
678 std::string
681 }
682 
683 
684 const std::vector<NBTrafficLightLogic::PhaseDefinition>&
686  return myEditedDef->getLogic()->getPhases();
687 }
688 
689 
690 void
693  if (myViewNet->changeAllPhases()) {
694  const std::vector<NBTrafficLightLogic::PhaseDefinition>& phases = getPhases();
695  for (int row = 0; row < (int)phases.size(); row++) {
696  myEditedDef->getLogic()->setPhaseState(row, lane->getTLIndex(), lane->getLinkState());
697  }
698  } else {
699  myEditedDef->getLogic()->setPhaseState(myTLSPhases->getPhaseTable()->getCurrentRow(), lane->getTLIndex(), lane->getLinkState());
700  }
701  myTLSPhases->initPhaseTable(myTLSPhases->getPhaseTable()->getCurrentRow());
702  myTLSPhases->getPhaseTable()->setFocus();
703 }
704 
705 
706 void
707 GNETLSEditorFrame::handleMultiChange(GNELane* lane, FXObject* obj, FXSelector sel, void* eventData) {
708  if (myEditedDef != nullptr) {
711  std::set<std::string> fromIDs;
712  fromIDs.insert(lane->getMicrosimID());
713  GNEEdge& edge = lane->getParentEdge();
714  // if neither the lane nor its edge are selected, apply changes to the whole edge
715  if (!edge.isAttributeCarrierSelected() && !lane->isAttributeCarrierSelected()) {
716  for (auto it_lane : edge.getLanes()) {
717  fromIDs.insert(it_lane->getMicrosimID());
718  }
719  } else {
720  // if the edge is selected, apply changes to all lanes of all selected edges
721  if (edge.isAttributeCarrierSelected()) {
722  std::vector<GNEEdge*> edges = myViewNet->getNet()->retrieveEdges(true);
723  for (auto it : edges) {
724  for (auto it_lane : it->getLanes()) {
725  fromIDs.insert(it_lane->getMicrosimID());
726  }
727  }
728  }
729  // if the lane is selected, apply changes to all selected lanes
730  if (lane->isAttributeCarrierSelected()) {
731  std::vector<GNELane*> lanes = myViewNet->getNet()->retrieveLanes(true);
732  for (auto it_lane : lanes) {
733  fromIDs.insert(it_lane->getMicrosimID());
734  }
735  }
736 
737  }
738  // set new state for all connections from the chosen lane IDs
739  for (auto it : links) {
740  if (fromIDs.count(it.getFrom()->getLaneID(it.getFromLane())) > 0) {
741  std::vector<GNEInternalLane*> lanes = myInternalLanes[it.getTLIndex()];
742  for (auto it_lane : lanes) {
743  it_lane->onDefault(obj, sel, eventData);
744  }
745  }
746  }
747  }
748 }
749 
750 
751 bool
753  if (myEditedDef != nullptr) {
755  for (auto it : links) {
756  if (it.getFrom()->getID() == edge.getMicrosimID()) {
757  return true;
758  }
759  }
760  }
761  return false;
762 }
763 
764 
765 SUMOTime
766 GNETLSEditorFrame::getSUMOTime(const FXString& string) {
767  assert(GNEAttributeCarrier::canParse<double>(string.text()));
768  return TIME2STEPS(GNEAttributeCarrier::parse<double>(string.text()));
769 }
770 
771 // ---------------------------------------------------------------------------
772 // GNETLSEditorFrame::TLSAttributes - methods
773 // ---------------------------------------------------------------------------
774 
776  FXGroupBox(TLSEditorParent->myContentFrame, "Traffic light Attributes", GUIDesignGroupBoxFrame),
777  myTLSEditorParent(TLSEditorParent) {
778 
779  // create frame, label and textfield for name (By default disabled)
780  FXHorizontalFrame* nameFrame = new FXHorizontalFrame(this, GUIDesignAuxiliarHorizontalFrame);
781  myNameLabel = new FXLabel(nameFrame, "ID", nullptr, GUIDesignLabelAttribute);
783  myNameTextField->disable();
784 
785  // create frame, label and comboBox for Program (By default hidden)
786  FXHorizontalFrame* programFrame = new FXHorizontalFrame(this, GUIDesignAuxiliarHorizontalFrame);
787  myProgramLabel = new FXLabel(programFrame, "Program", nullptr, GUIDesignLabelAttribute);
789  myProgramComboBox->disable();
790 
791  // create frame, label and TextField for Offset (By default disabled)
792  FXHorizontalFrame* offsetFrame = new FXHorizontalFrame(this, GUIDesignAuxiliarHorizontalFrame);
793  myOffsetLabel = new FXLabel(offsetFrame, "Offset", nullptr, GUIDesignLabelAttribute);
795  myOffsetTextField->disable();
796 }
797 
798 
800 
801 
802 void
804  assert(junction);
805  myTLSDefinitions.clear();
806  // enable name TextField
807  myNameTextField->enable();
808  // enable Offset
809  myOffsetTextField->enable();
810  // obtain TLSs
811  for (auto it : junction->getNBNode()->getControllingTLS()) {
812  myTLSDefinitions.push_back(it);
813  myNameTextField->setText(it->getID().c_str());
814  myNameTextField->enable();
815  myProgramComboBox->appendItem(it->getProgramID().c_str());
816  }
817  if (myTLSDefinitions.size() > 0) {
818  myProgramComboBox->enable();
819  myProgramComboBox->setCurrentItem(0);
820  myProgramComboBox->setNumVisible(myProgramComboBox->getNumItems());
821  myTLSEditorParent->onCmdDefSwitch(nullptr, 0, nullptr);
822  }
823 }
824 
825 
826 void
828  // clear definitions
829  myTLSDefinitions.clear();
830  // clear and disable name TextField
831  myNameTextField->setText("");
832  myNameTextField->disable();
833  // clear and disable myProgramComboBox
834  myProgramComboBox->clearItems();
835  myProgramComboBox->disable();
836  // clear and disable Offset TextField
837  myOffsetTextField->setText("");
838  myOffsetTextField->disable();
839 }
840 
841 
844  return myTLSDefinitions.at(myProgramComboBox->getCurrentItem());
845 }
846 
847 
848 int
850  return (int)myTLSDefinitions.size();
851 }
852 
853 
854 int
856  return myProgramComboBox->getNumItems();
857 }
858 
859 
860 SUMOTime
862  return getSUMOTime(myOffsetTextField->getText());
863 }
864 
865 
866 void
868  myOffsetTextField->setText(toString(STEPS2TIME(offset)).c_str());
869 }
870 
871 // ---------------------------------------------------------------------------
872 // GNETLSEditorFrame::TLSJunction - methods
873 // ---------------------------------------------------------------------------
874 
876  FXGroupBox(TLSEditorParent->myContentFrame, "Junction", GUIDesignGroupBoxFrame),
877  myTLSEditorParent(TLSEditorParent),
878  myCurrentJunction(nullptr) {
879  // Create frame for junction ID
880  FXHorizontalFrame* junctionIDFrame = new FXHorizontalFrame(this, GUIDesignAuxiliarHorizontalFrame);
881  myLabelJunctionID = new FXLabel(junctionIDFrame, "Junction ID", nullptr, GUIDesignLabelAttribute);
883  myTextFieldJunctionID->setEditable(false);
884  // create frame for junction status
885  FXHorizontalFrame* junctionIDStatus = new FXHorizontalFrame(this, GUIDesignAuxiliarHorizontalFrame);
886  myLabelJunctionStatus = new FXLabel(junctionIDStatus, "Status", nullptr, GUIDesignLabelAttribute);
888  myTextFieldJunctionStatus->setEditable(false);
889  // update junction description after creation
891  // show TLS Junction
892  show();
893 }
894 
895 
897 
898 
901  return myCurrentJunction;
902 }
903 
904 
905 void
907  myCurrentJunction = junction;
908 }
909 
910 
911 void
913  if (myCurrentJunction == nullptr) {
914  myTextFieldJunctionID->setText("");
915  myTextFieldJunctionStatus->setText("");
916  } else {
918  myTextFieldJunctionID->setText(nbn->getID().c_str());
919  if (!nbn->isTLControlled()) {
920  myTextFieldJunctionStatus->setText("uncontrolled");
921  } else {
923  }
924  }
925 }
926 
927 // ---------------------------------------------------------------------------
928 // GNETLSEditorFrame::TLSDefinition - methods
929 // ---------------------------------------------------------------------------
930 
932  FXGroupBox(TLSEditorParent->myContentFrame, "Traffic lights definition", GUIDesignGroupBoxFrame),
933  myTLSEditorParent(TLSEditorParent) {
934  // create create tlDef button
935  myNewTLProgram = new FXButton(this, "Create TLS\t\tCreate a new traffic light program",
937  // create delete tlDef button
938  myDeleteTLProgram = new FXButton(this, "Delete TLS\t\tDelete a traffic light program. If all programs are deleted the junction turns into a priority junction.",
940  // show TLS TLSDefinition
941  show();
942 }
943 
944 
946 
947 // ---------------------------------------------------------------------------
948 // GNETLSEditorFrame::TLSPhases - methods
949 // ---------------------------------------------------------------------------
950 
952  FXGroupBox(TLSEditorParent->myContentFrame, "Phases", GUIDesignGroupBoxFrame),
953  myTLSEditorParent(TLSEditorParent),
954  myTableFont(new FXFont(getApp(), "Courier New", 9)) {
955 
956  // create and configure phase table
957  myTableScroll = new FXScrollWindow(this, LAYOUT_FILL_X | LAYOUT_FIX_HEIGHT);
959  myPhaseTable->setColumnHeaderMode(LAYOUT_FIX_HEIGHT);
960  myPhaseTable->setColumnHeaderHeight(0);
961  myPhaseTable->setRowHeaderMode(LAYOUT_FIX_WIDTH);
962  myPhaseTable->setRowHeaderWidth(0);
963  myPhaseTable->hide();
964  myPhaseTable->setFont(myTableFont);
965  myPhaseTable->setHelpText("phase duration in seconds | phase state");
966 
967  // create total duration info label
968  myCycleDuration = new FXLabel(this, "", nullptr, GUIDesignLabelLeft);
969 
970  // create new phase button
971  myInsertDuplicateButton = new FXButton(this, "Insert Phase\t\tInsert new phase after the selected phase. The new state is deduced from the selected phase.", nullptr, myTLSEditorParent, MID_GNE_TLSFRAME_PHASE_CREATE, GUIDesignButton);
972 
973  // create delete phase button
974  myDeleteSelectedPhaseButton = new FXButton(this, "Delete Phase\t\tDelete selected phase", nullptr, myTLSEditorParent, MID_GNE_TLSFRAME_PHASE_DELETE, GUIDesignButton);
975 
976  // create cleanup states button
977  new FXButton(this, "Cleanup States\t\tClean unused states from all phase.", nullptr, myTLSEditorParent, MID_GNE_TLSFRAME_CLEANUP, GUIDesignButton);
978 
979  // add unused states button
980  new FXButton(this, "Add Unused States\t\tExtend the state vector for all phases by one entry.", nullptr, myTLSEditorParent, MID_GNE_TLSFRAME_ADDUNUSED, GUIDesignButton);
981 
982  // show TLSFile
983  show();
984 }
985 
986 
988  delete myTableFont;
989 }
990 
991 
992 FXTable*
994  return myPhaseTable;
995 }
996 
997 
998 void
1000  myPhaseTable->setVisibleRows(1);
1001  myPhaseTable->setVisibleColumns(2);
1002  myPhaseTable->hide();
1004  const bool fixed = myTLSEditorParent->myEditedDef->getType() == TLTYPE_STATIC;
1005  const std::vector<NBTrafficLightLogic::PhaseDefinition>& phases = myTLSEditorParent->getPhases();
1006  myPhaseTable->setTableSize((int)phases.size(), fixed ? 2 : 4);
1007  myPhaseTable->setVisibleRows((int)phases.size());
1008  myPhaseTable->setVisibleColumns(fixed ? 2 : 4);
1009  for (int row = 0; row < (int)phases.size(); row++) {
1010  myPhaseTable->setItemText(row, 0, toString(STEPS2TIME(phases[row].duration)).c_str());
1011  if (!fixed) {
1012  myPhaseTable->setItemText(row, 1, varDurString(phases[row].minDur).c_str());
1013  myPhaseTable->setItemText(row, 2, varDurString(phases[row].maxDur).c_str());
1014  }
1015  myPhaseTable->setItemText(row, fixed ? 1 : 3, phases[row].state.c_str());
1016  myPhaseTable->getItem(row, 1)->setJustify(FXTableItem::LEFT);
1017  }
1018  myPhaseTable->fitColumnsToContents(0, fixed ? 2 : 4);
1019  myPhaseTable->setHeight((int)phases.size() * 21); // experimental
1020  myPhaseTable->setCurrentItem(index, 0);
1021  myPhaseTable->selectRow(index, true);
1022  myPhaseTable->show();
1023  myPhaseTable->setFocus();
1024  myTableScroll->setHeight(myPhaseTable->getHeight() + 10);
1025  }
1026  update();
1027 }
1028 
1029 
1030 void
1032  myCycleDuration->show();
1033 }
1034 
1035 
1036 void
1038  myCycleDuration->hide();
1039 }
1040 
1041 void
1043  SUMOTime cycleDuration = 0;
1044  for (auto it : myTLSEditorParent->getPhases()) {
1045  cycleDuration += it.duration;
1046  }
1047  std::string text = "Cycle time: " + toString(STEPS2TIME(cycleDuration));
1048  myCycleDuration->setText(text.c_str());
1049 }
1050 
1051 // ---------------------------------------------------------------------------
1052 // GNETLSEditorFrame::TLSModifications - methods
1053 // ---------------------------------------------------------------------------
1054 
1056  FXGroupBox(TLSEditorParent->myContentFrame, "Modifications", GUIDesignGroupBoxFrame),
1057  myTLSEditorParent(TLSEditorParent),
1058  myHaveModifications(false) {
1059  // create save modifications button
1060  mySaveModificationsButtons = new FXButton(this, "Save\t\tSave program modifications (Enter)",
1062  // create discard modifications buttons
1063  myDiscardModificationsButtons = new FXButton(this, "Cancel\t\tDiscard program modifications (Esc)",
1065  // show TLSModifications
1066  show();
1067 }
1068 
1069 
1071 
1072 
1073 bool
1075  return myHaveModifications;
1076 }
1077 
1078 
1079 void
1081  myHaveModifications = value;
1082 }
1083 
1084 // ---------------------------------------------------------------------------
1085 // GNETLSEditorFrame::TLSFile - methods
1086 // ---------------------------------------------------------------------------
1087 
1089  FXGroupBox(TLSEditorParent->myContentFrame, "TLS Program", GUIDesignGroupBoxFrame),
1090  myTLSEditorParent(TLSEditorParent) {
1091  // create create tlDef button
1092  myLoadTLSProgramButton = new FXButton(this, "Load TLS Program", nullptr, this, MID_GNE_TLSFRAME_LOAD_PROGRAM, GUIDesignButton);
1093  // create create tlDef button
1094  mySaveTLSProgramButton = new FXButton(this, "Save TLS Program", nullptr, this, MID_GNE_TLSFRAME_SAVE_PROGRAM, GUIDesignButton);
1095  // show TLSFile
1096  show();
1097 }
1098 
1099 
1101 
1102 
1103 long
1105  FXFileDialog opendialog(this, "Load TLS Program");
1106  opendialog.setIcon(GUIIconSubSys::getIcon(ICON_MODETLS));
1107  opendialog.setSelectMode(SELECTFILE_EXISTING);
1108  opendialog.setPatternList("*.xml");
1109  if (gCurrentFolder.length() != 0) {
1110  opendialog.setDirectory(gCurrentFolder);
1111  }
1112  if (opendialog.execute()) {
1113  // run parser
1114  NBTrafficLightLogicCont tmpTLLCont;;
1115  NIXMLTrafficLightsHandler tllHandler(tmpTLLCont, myTLSEditorParent->myViewNet->getNet()->getEdgeCont(), true);
1116  tmpTLLCont.insert(myTLSEditorParent->myEditedDef);
1117  XMLSubSys::runParser(tllHandler, opendialog.getFilename().text());
1118 
1119  NBLoadedSUMOTLDef* newDefSameProgram = nullptr;
1120  std::set<NBLoadedSUMOTLDef*> newDefsOtherProgram;
1121  for (auto item : tmpTLLCont.getPrograms(myTLSEditorParent->myEditedDef->getID())) {
1122  if (item.second != myTLSEditorParent->myEditedDef) {
1123  NBLoadedSUMOTLDef* sdef = dynamic_cast<NBLoadedSUMOTLDef*>(item.second);
1124  if (item.first == myTLSEditorParent->myEditedDef->getProgramID()) {
1125  newDefSameProgram = sdef;
1126  } else {
1127  newDefsOtherProgram.insert(sdef);
1128  }
1129  }
1130  }
1131  const int newPrograms = (int)newDefsOtherProgram.size();
1132  if (newPrograms > 0 || newDefSameProgram != nullptr) {
1133  std::vector<NBNode*> nodes = myTLSEditorParent->myEditedDef->getNodes();
1134  for (auto newProg : newDefsOtherProgram) {
1135  for (auto it_node : nodes) {
1136  GNEJunction* junction = myTLSEditorParent->getViewNet()->getNet()->retrieveJunction(it_node->getID());
1137  myTLSEditorParent->getViewNet()->getUndoList()->add(new GNEChange_TLS(junction, newProg, true), true);
1138  }
1139  }
1140  if (newPrograms > 0) {
1141  WRITE_MESSAGE("Loaded " + toString(newPrograms) + " new programs for tlLogic '" + myTLSEditorParent->myEditedDef->getID() + "'");
1142  }
1143  if (newDefSameProgram != nullptr) {
1144  // replace old program when loading the same program ID
1145  myTLSEditorParent->myEditedDef = newDefSameProgram;
1146  WRITE_MESSAGE("Updated program '" + newDefSameProgram->getProgramID() + "' for tlLogic '" + myTLSEditorParent->myEditedDef->getID() + "'");
1147  }
1148  } else {
1149  myTLSEditorParent->getViewNet()->setStatusBarText("No programs found for traffic light '" + myTLSEditorParent->myEditedDef->getID() + "'");
1150  }
1151 
1152  // clean up temporary container to avoid deletion of defs when it's destruct is called
1153  for (NBTrafficLightDefinition* def : tmpTLLCont.getDefinitions()) {
1154  tmpTLLCont.removeProgram(def->getID(), def->getProgramID(), false);
1155  }
1156 
1159  }
1160  return 0;
1161 }
1162 
1163 
1164 long
1166  FXString file = MFXUtils::getFilename2Write(this,
1167  "Save TLS Program as", ".xml",
1169  gCurrentFolder);
1170  if (file == "") {
1171  return 1;
1172  }
1173  OutputDevice& device = OutputDevice::getDevice(file.text());
1174 
1175  // save program
1176  device.writeXMLHeader("additional", "additional_file.xsd");
1177  device.openTag(SUMO_TAG_TLLOGIC);
1182  // write the phases
1183  const bool varPhaseLength = myTLSEditorParent->myEditedDef->getLogic()->getType() != TLTYPE_STATIC;
1184  const std::vector<NBTrafficLightLogic::PhaseDefinition>& phases = myTLSEditorParent->myEditedDef->getLogic()->getPhases();
1185  for (auto j : phases) {
1186  device.openTag(SUMO_TAG_PHASE);
1187  device.writeAttr(SUMO_ATTR_DURATION, writeSUMOTime(j.duration));
1188  device.writeAttr(SUMO_ATTR_STATE, j.state);
1189  if (varPhaseLength) {
1191  device.writeAttr(SUMO_ATTR_MINDURATION, writeSUMOTime(j.minDur));
1192  }
1194  device.writeAttr(SUMO_ATTR_MAXDURATION, writeSUMOTime(j.maxDur));
1195  }
1196  }
1197  device.closeTag();
1198  }
1199  device.close();
1200  return 1;
1201 }
1202 
1203 
1204 std::string
1206  double time = STEPS2TIME(steps);
1207  if (time == std::floor(time)) {
1208  return toString(int(time));
1209  } else {
1210  return toString(time);
1211  }
1212 }
1213 
1214 long
1215 GNETLSEditorFrame::TLSFile::onUpdNeedsDef(FXObject* o, FXSelector, void*) {
1216  const bool enable = myTLSEditorParent->myTLSAttributes->getNumberOfTLSDefinitions() > 0;
1217  o->handle(this, FXSEL(SEL_COMMAND, enable ? FXWindow::ID_ENABLE : FXWindow::ID_DISABLE), nullptr);
1218  return 1;
1219 }
1220 /****************************************************************************/
int NUM_POINTS
GNETLSEditorFrame::TLSModifications * myTLSModifications
modul for load/Save TLS Modifications
TLIndexMap myInternalLanes
FXLabel * myLabelJunctionStatus
label for junction status
const std::map< std::string, NBTrafficLightDefinition * > & getPrograms(const std::string &id) const
Returns all programs for the given tl-id.
The link has green light, may pass.
long onCmdGuess(FXObject *, FXSelector, void *)
Called when the user presses the button Guess.
OutputDevice & writeAttr(const SumoXMLAttr attr, const T &val)
writes a named attribute
Definition: OutputDevice.h:256
virtual void setParticipantsInformation()
Builds the list of participating nodes/edges/links.
std::vector< GNELane * > retrieveLanes(bool onlySelected=false)
return all lanes
Definition: GNENet.cpp:1044
void close()
Closes the device and removes it from the dictionary.
TLSDefinition(GNETLSEditorFrame *TLSEditorParent)
constructor
void setAttribute(SumoXMLAttr key, const std::string &value, GNEUndoList *undoList)
A structure which describes a connection between edges or lanes.
Definition: NBEdge.h:160
#define GUIDesignComboBoxNCol
number of column of every combo box
Definition: GUIDesigns.h:205
long long int SUMOTime
Definition: SUMOTime.h:36
FXLabel * myCycleDuration
label with the cycle duration
long onUpdNeedsDefAndPhase(FXObject *, FXSelector, void *)
Called when occurs an update of needs definition an dphase.
long onCmdPhaseDelete(FXObject *, FXSelector, void *)
Called when the user deletes a Phase.
GNETLSEditorFrame::TLSPhases * myTLSPhases
modul for TLS Phases
bool removeProgram(const std::string id, const std::string programID, bool del=true)
Removes a program of a logic definition from the dictionary.
SUMOTime getOffset() const
Returns the offset of first switch.
GNETLSEditorFrame * myTLSEditorParent
pointer to TLSEditor Parent
bool parseTLSPrograms(const std::string &file)
parse TLS Programs from a file
int getInt(const std::string &name) const
Returns the int-value of the named option (only for Option_Integer)
const std::vector< GNEEdge * > & getGNEOutgoingEdges() const
Returns incoming GNEEdges.
long onCmdDefCreate(FXObject *, FXSelector, void *)
Called when the user creates a TLS.
FXButton * myDiscardModificationsButtons
button for cancel modifications
void setPhaseMaxDuration(int phaseIndex, SUMOTime duration)
FXLabel * myOffsetLabel
offset label
long onCmdSaveTLSProgram(FXObject *, FXSelector, void *)
save TLS Programm to an additional file
cleanup unused states
Definition: GUIAppEnum.h:647
void setOffset(SUMOTime offset)
Sets the offset of this tls.
int getNumLinks()
Returns the number of participating links.
A loaded (complete) traffic light logic.
FXFont * myTableFont
font for the phase table
GNEJunction * getCurrentJunction() const
get current modified junction
void setPhaseState(int phaseIndex, int tlIndex, LinkState linkState)
Modifies the state for an existing phase (used by NETEDIT)
A container for traffic light definitions and built programs.
A SUMO-compliant built logic for a traffic light.
#define GUIDesignTableLimitedHeight
design for table extended over frame but with limited Height
Definition: GUIDesigns.h:444
#define GUIDesignComboBoxAttribute
Combo box static (cannot be edited) extended over the matrix column.
Definition: GUIDesigns.h:201
The link has green light, has to brake.
long onCmdPhaseSwitch(FXObject *, FXSelector, void *)
Called when the user switchs a Phase.
TrafficLightType getType() const
get the algorithm type (static etc..)
FXTextField * myTextFieldJunctionStatus
text field for junction status
selected junction von TLS
Definition: GUIAppEnum.h:613
const std::vector< PhaseDefinition > & getPhases() const
Returns the phases.
This object is responsible for drawing a shape and for supplying a a popup menu. Messages are routete...
const NBConnectionVector & getControlledLinks() const
returns the controlled links (depends on previous call to collectLinks)
void removeAdditionalGLObject(GUIGlObject *o)
Removes an additional object (detector/shape/trigger) from being visualised.
Definition: SUMORTree.h:152
select phase thable
Definition: GUIAppEnum.h:633
The base class for traffic light logic definitions.
void setPhaseMinDuration(int phaseIndex, SUMOTime duration)
This is a dead end link.
FXComboBox * myProgramComboBox
the comboBox for selecting the tl-definition to edit
T MAX2(T a, T b)
Definition: StdDefs.h:76
bool isTLSSaved()
check if modifications in TLS was saved
static const SUMOTime UNSPECIFIED_DURATION
This lane is powered by an underlying GNEEdge and basically knows how to draw itself.
Definition: GNELane.h:47
void editJunction(GNEJunction *junction)
edits the traffic light for the given junction
long onCmdLoadTLSProgram(FXObject *, FXSelector, void *)
void initPhaseTable(int index=0)
initialies the phase table
void p_begin(const std::string &description)
Begin undo command sub-group. This begins a new group of commands that are treated as a single comman...
Definition: GNEUndoList.cpp:73
PositionVector reverse() const
reverse position vector
FXString gCurrentFolder
The folder used as last.
int computeBrakingTime(double minDecel) const
Computes the time vehicles may need to brake.
const std::string & getProgramID() const
Returns the ProgramID.
add off to TLS
Definition: GUIAppEnum.h:631
void selectTLS(bool selected)
notify the junction of being selected in tls-mode. (used to control drawing)
definition related controls
Definition: GUIAppEnum.h:619
FXButton * mySaveTLSProgramButton
button for save TLS Programs
maximum duration of a phase
const std::string & getID() const
Returns the id.
Definition: Named.h:78
#define TIME2STEPS(x)
Definition: SUMOTime.h:60
void handleMultiChange(GNELane *lane, FXObject *obj, FXSelector sel, void *data)
update phase definition for the current traffic light and phase
bool isDefault(const std::string &name) const
Returns the information whether the named option has still the default value.
The definition of a single phase of the logic.
FXLabel * myProgramLabel
program label
TLSJunction(GNETLSEditorFrame *TLSEditorParent)
constructor
long onUpdNeedsDef(FXObject *, FXSelector, void *)
Called when occurs an update of needs definition.
static bool runParser(GenericSAXHandler &handler, const std::string &file, const bool isNet=false)
Runs the given handler on the given file; returns if everything&#39;s ok.
Definition: XMLSubSys.cpp:113
A RT-tree for efficient storing of SUMO&#39;s GL-objects.
Definition: SUMORTree.h:69
long onCmdCleanup(FXObject *, FXSelector, void *)
Called when the user cleans up states.
static FXString getFilename2Write(FXWindow *parent, const FXString &header, const FXString &extension, FXIcon *icon, FXString &currentFolder)
Returns the file name to write.
Definition: MFXUtils.cpp:84
bool myHaveModifications
whether the current tls was modified
LinkState getLinkState() const
whether link state has been modfied
long onCmdDefDelete(FXObject *, FXSelector, void *)
Called when the user deletes a TLS.
GNEViewNet * getViewNet() const
get view net
Definition: GNEFrame.cpp:1720
long onCmdDefOffset(FXObject *, FXSelector, void *)
Called when the user changes the offset of a TLS.
#define WRITE_WARNING(msg)
Definition: MsgHandler.h:241
FXButton * myDeleteSelectedPhaseButton
delete phase button
long onCmdDefSwitch(FXObject *, FXSelector, void *)
Called when the user switchs a TLS.
long onCmdDefAddOff(FXObject *, FXSelector, void *)
Called when the user adds a OFF.
static OptionsCont & getOptions()
Retrieves the options.
Definition: OptionsCont.cpp:58
delete phase thable
Definition: GUIAppEnum.h:637
bool changeAllPhases() const
change all phases
Definition: GNEViewNet.cpp:775
GNEViewNet * myViewNet
View Net for changes.
Definition: GNEFrame.h:612
The state of a link.
GNETLSEditorFrame * myTLSEditorParent
pointer to TLSEditor Parent
FXScrollWindow * myTableScroll
window for oversized phase tables
GNETLSEditorFrame * myTLSEditorParent
pointer to TLSEditor Parent
void clearTLSAttributes()
clear TLS attributes
bool isTLControlled() const
Returns whether this node is controlled by any tls.
Definition: NBNode.h:303
std::string getAttribute(SumoXMLAttr key) const
GNEUndoList * getUndoList() const
get the undoList object
FXTable * getPhaseTable() const
get phase table
void hideCycleDuration()
hide cycle duration
GNETLSEditorFrame * myTLSEditorParent
pointer to TLSEditorParent
FXTextField * myNameTextField
name text field
#define GUIDesignTextField
Definition: GUIDesigns.h:34
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:49
FXVerticalFrame * myContentFrame
Vertical frame that holds all widgets of frame.
Definition: GNEFrame.h:615
void initTLSAttributes(GNEJunction *junction)
initializes the definitions and corresponding listbox
long onCmdCancel(FXObject *, FXSelector, void *)
Called when the user presses the Cancel-button.
GNEEdge & getParentEdge()
Returns underlying parent edge.
Definition: GNELane.cpp:1260
NBEdgeCont & getEdgeCont()
returns the NBEdgeCont of the underlying netbuilder
Definition: GNENet.cpp:1755
NBTrafficLightDefinition * getCurrentTLSDefinition() const
get current definition
GNETLSEditorFrame::TLSJunction * myTLSJunction
modul for TLS Junction
const std::vector< GNEEdge * > & getGNEIncomingEdges() const
Returns incoming GNEEdges.
bool writeXMLHeader(const std::string &rootElement, const std::string &schemaFile, std::map< SumoXMLAttr, std::string > attrs=std::map< SumoXMLAttr, std::string >())
Writes an XML header with optional configuration.
void p_end()
End undo command sub-group. If the sub-group is still empty, it will be deleted; otherwise, the sub-group will be added as a new command into parent group. A matching begin() must have been called previously.
Definition: GNEUndoList.cpp:80
GNEJunction * retrieveJunction(const std::string &id, bool failHard=true)
get junction by id
Definition: GNENet.cpp:887
TLSAttributes(GNETLSEditorFrame *TLSEditorParent)
constructor
#define GUIDesignAuxiliarHorizontalFrame
design for auxiliar (Without borders) horizontal frame used to pack another frames ...
Definition: GUIDesigns.h:261
A list of positions.
bool controlsEdge(GNEEdge &edge) const
whether the given edge is controlled by the currently edited tlDef
GNETLSEditorFrame::TLSAttributes * myTLSAttributes
modul for TLS attributes
long onUpdDefCreate(FXObject *, FXSelector, void *)
Called when occurs an update of create definition.
void buildIinternalLanes(NBTrafficLightDefinition *tlDef)
builds internal lanes for the given tlDef
replace program with a newly guessed program
Definition: GUIAppEnum.h:617
cleanup unused states
Definition: GUIAppEnum.h:639
TLSPhases(GNETLSEditorFrame *TLSEditorParent)
constructor
bool checkHaveModifications() const
check if current TLS was modified
long onCmdPhaseEdit(FXObject *, FXSelector, void *)
Called when the user edits a Phase.
#define STEPS2TIME(x)
Definition: SUMOTime.h:58
std::string state
The state definition.
LinkState
The right-of-way state of a link between two lanes used when constructing a NBTrafficLightLogic, in MSLink and GNEInternalLane.
void computeJunction(GNEJunction *junction)
trigger recomputation of junction shape and logic param[in] window The window to inform about delay ...
Definition: GNENet.cpp:1351
~GNETLSEditorFrame()
Destructor.
void handleChange(GNEInternalLane *lane)
update phase definition for the current traffic light and phase
int getTLIndex() const
get Traffic Light index
NBTrafficLightLogic * getLogic()
Returns the internal logic.
GNETLSEditorFrame * myTLSEditorParent
pointer to TLSEditor Parent
virtual const std::string & getMicrosimID() const
Returns the id of the object as known to microsim.
FXDEFMAP(GNETLSEditorFrame) GNETLSEditorFrameMap[]
#define WRITE_DEBUG(msg)
Definition: MsgHandler.h:248
const std::string & getProgramID() const
Returns the ProgramID.
void p_abort()
reverts and discards ALL active command groups
Definition: GNEUndoList.cpp:94
double getFloat(const std::string &name) const
Returns the double-value of the named option (only for Option_Float)
void move2side(double amount)
move position vector to side using certain ammount
SUMORTree & getVisualisationSpeedUp()
Returns the RTree used for visualisation speed-up.
Definition: GNENet.cpp:280
std::vector< NBConnection > NBConnectionVector
Definition of a connection vector.
long onCmdAddUnused(FXObject *, FXSelector, void *)
Called when the user cleans up states.
FXTable * myPhaseTable
table for selecting and rearranging phases and for changing duration
static SUMOTime getSUMOTime(const FXString &string)
converts to SUMOTime
A road/street connecting two junctions (netedit-version)
Definition: GNEEdge.h:50
int getNumberOfTLSDefinitions() const
get number of definitions
#define GUIDesignTextFieldNCol
Num of column of text field.
Definition: GUIDesigns.h:46
long onUpdDefSwitch(FXObject *, FXSelector, void *)
Called when occurs an update of switch definition.
create phase thable
Definition: GUIAppEnum.h:635
#define GUIDesignButton
Definition: GUIDesigns.h:54
GNEJunction * myCurrentJunction
the junction of the tls is being modified
static std::string varDurString(SUMOTime dur)
convert duration (potentially undefined) to string
static std::string prune(const std::string &str)
Removes trailing and leading whitechars.
Definition: StringUtils.cpp:47
FXButton * myLoadTLSProgramButton
button for load TLS Programs
const std::vector< GNELane * > & getLanes()
returns a reference to the lane vector
Definition: GNEEdge.cpp:873
void showCycleDuration()
show cycle duration
virtual void show()
show Frame
Definition: GNEFrame.cpp:1695
void updateCycleDuration()
recomputes cycle duration and updates label
int getNumberOfPrograms() const
get number of programs
std::vector< GNEEdge * > retrieveEdges(bool onlySelected=false)
return all edges
Definition: GNENet.cpp:1031
The link has yellow light, may pass.
void addAdditionalGLObject(GUIGlObject *o)
Adds an additional object (detector/shape/trigger) for visualisation.
Definition: SUMORTree.h:124
#define GUIDesignGroupBoxFrame
Group box design extended over frame.
Definition: GUIDesigns.h:227
static OutputDevice & getDevice(const std::string &name)
Returns the described OutputDevice.
const std::set< NBTrafficLightDefinition * > & getControllingTLS() const
Returns the traffic lights that were assigned to this node (The set of tls that control this node) ...
Definition: NBNode.h:308
TrafficLightType getType() const
get the algorithm type (static etc..)
long onCmdOK(FXObject *, FXSelector, void *)
SUMOTime getOffset() const
get current offset in SUMOTIme
void updateJunctionDescription() const
update descrition
const std::vector< NBNode * > & getNodes() const
Returns the list of controlled nodes.
long onCmdDefSubRename(FXObject *, FXSelector, void *)
Called when the user sub-renames a TLS.
The link has red light (must brake)
A storage for options typed value containers)
Definition: OptionsCont.h:92
void setOffset(SUMOTime offset)
set new offset
Ok-button pressed.
Definition: GUIAppEnum.h:56
const std::vector< NBTrafficLightLogic::PhaseDefinition > & getPhases()
the phase of the current traffic light
void setPhaseDuration(int phaseIndex, SUMOTime duration)
Modifies the duration for an existing phase (used by NETEDIT)
Cancel-button pressed.
Definition: GUIAppEnum.h:58
GNENet * getNet() const
get the net object
#define GUIDesignTextFieldReal
text field extended over Frame with thick frame and limited to Doubles/doubles
Definition: GUIDesigns.h:40
long onCmdPhaseCreate(FXObject *, FXSelector, void *)
Called when the user creates a Phase.
FXButton * mySaveModificationsButtons
button for save modifications
Represents a single node (junction) during network building.
Definition: NBNode.h:68
long onUpdNeedsDef(FXObject *, FXSelector, void *)
enable buttons, only when a tlLogic is being edited
void setHaveModifications(bool value)
set if current TLS was modified
void setCurrentJunction(GNEJunction *junction)
set current junction
A definition of a pedestrian crossing.
Definition: NBNode.h:125
void setStatusBarText(const std::string &text)
set staturBar text
Definition: GNEViewNet.cpp:727
bool insert(NBTrafficLightDefinition *logic, bool forceInsert=false)
Adds a logic definition to the dictionary.
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:64
bool closeTag(const std::string &comment="")
Closes the most recently opened tag and optionally adds a comment.
void setStateLength(int numLinks, LinkState fill=LINKSTATE_TL_RED)
std::string writeSUMOTime(SUMOTime steps)
convert SUMOTime into string
Importer for edge connections stored in XML.
a traffic light logic
#define GUIDesignLabelLeft
Definition: GUIDesigns.h:145
The link has yellow light, has to brake anyway.
void addStep(SUMOTime duration, const std::string &state, int index=-1)
Adds a phase to the logic.
FXLabel * myLabelJunctionID
label for junction ID
long onCmdDefRename(FXObject *, FXSelector, void *)
Called when the user renames a TLS.
long onUpdModified(FXObject *, FXSelector, void *)
Called when occurs an update of modified.
GNETLSEditorFrame * myTLSEditorParent
pointer to TLSEditor Parent
FXButton * myInsertDuplicateButton
insert new phase button
#define GUIDesignLabelAttribute
label extended over the matrix column with thick frame and height of 23
Definition: GUIDesigns.h:166
FXButton * myNewTLProgram
button for create new Traffic light program
#define WRITE_MESSAGE(msg)
Definition: MsgHandler.h:242
FXTextField * myOffsetTextField
the control for modifying offset
FXButton * myDeleteTLProgram
button for delete traffic light program
NBNode * getNBNode() const
Return net build node.
NBTrafficLightLogic * getLogic(const std::string &id, const std::string &programID) const
Returns the computed logic for the given name.
FXTextField * myTextFieldJunctionID
text field for junction ID
mark unused states
Definition: GUIAppEnum.h:643
NBTrafficLightLogicCont & getTLLogicCont()
returns the tllcont of the underlying netbuilder
Definition: GNENet.cpp:1750
NBLoadedSUMOTLDef * myEditedDef
the traffic light definition being edited
static FXIcon * getIcon(GUIIcon which)
returns a icon previously defined in the enum GUIIcon
std::vector< NBTrafficLightDefinition * > myTLSDefinitions
the list of Definitions for the current junction
a single phase description
void cleanup()
cleans up previous lanes
TLSModifications(GNETLSEditorFrame *TLSEditorParent)
constructor
switch between programs
Definition: GUIAppEnum.h:621
bool isAttributeCarrierSelected() const
check if attribute carrier is selected
OutputDevice & openTag(const std::string &xmlElement)
Opens an XML tag.