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 
24 #include <iostream>
33 #include <utils/xml/XMLSubSys.h>
34 #include <netwrite/NWWriter_SUMO.h>
36 #include <netbuild/NBEdgeCont.h>
37 #include <netbuild/NBNetBuilder.h>
38 #include <netbuild/NBOwnTLDef.h>
40 #include <netedit/GNEViewNet.h>
41 #include <netedit/GNEViewParent.h>
42 #include <netedit/GNENet.h>
46 #include <netedit/GNEUndoList.h>
48 
49 #include "GNETLSEditorFrame.h"
50 
51 // ===========================================================================
52 // FOX callback mapping
53 // ===========================================================================
54 
55 FXDEFMAP(GNETLSEditorFrame) GNETLSEditorFrameMap[] = {
56  FXMAPFUNC(SEL_COMMAND, MID_CANCEL, GNETLSEditorFrame::onCmdCancel),
57  FXMAPFUNC(SEL_UPDATE, MID_CANCEL, GNETLSEditorFrame::onUpdModified),
58  FXMAPFUNC(SEL_COMMAND, MID_OK, GNETLSEditorFrame::onCmdOK),
59  FXMAPFUNC(SEL_UPDATE, MID_OK, GNETLSEditorFrame::onUpdModified),
84 };
85 
86 FXDEFMAP(GNETLSEditorFrame::TLSFile) TLSFileMap[] = {
89 };
90 
91 // Object implementation
92 FXIMPLEMENT(GNETLSEditorFrame, FXVerticalFrame, GNETLSEditorFrameMap, ARRAYNUMBER(GNETLSEditorFrameMap))
93 FXIMPLEMENT(GNETLSEditorFrame::TLSFile, FXGroupBox, TLSFileMap, ARRAYNUMBER(TLSFileMap))
94 
95 
96 // ===========================================================================
97 // method definitions
98 // ===========================================================================
99 
100 GNETLSEditorFrame::GNETLSEditorFrame(FXHorizontalFrame* horizontalFrameParent, GNEViewNet* viewNet):
101  GNEFrame(horizontalFrameParent, viewNet, "Edit Traffic Light"),
102  myEditedDef(0) {
103 
104  // create TLSJunction modul
105  myTLSJunction = new GNETLSEditorFrame::TLSJunction(this);
106 
107  // create TLSDefinition modul
108  myTLSDefinition = new GNETLSEditorFrame::TLSDefinition(this);
109 
110  // create TLSAttributes modul
111  myTLSAttributes = new GNETLSEditorFrame::TLSAttributes(this);
112 
113  // create TLSModifications modul
114  myTLSModifications = new GNETLSEditorFrame::TLSModifications(this);
115 
116  // create TLSPhases modul
117  myTLSPhases = new GNETLSEditorFrame::TLSPhases(this);
118 
119  // create TLSFile modul
120  myTLSFile = new GNETLSEditorFrame::TLSFile(this);
121 
122  // "Add 'off' program"
123  /*
124  new FXButton(myContentFrame, "Add \"Off\"-Program\t\tAdds a program for switching off this traffic light",
125  0, this, MID_GNE_TLSFRAME_ADDOFF, GUIDesignButton);
126  */
127 }
128 
129 
131  cleanup();
132 }
133 
134 
135 void
138  onCmdCancel(0, 0, 0);
139  myViewNet->getUndoList()->p_begin("modifying traffic light definition");
144  } else {
145  myViewNet->setStatusBarText("Unsaved modifications. Abort or Save");
146  }
147 }
148 
149 
150 bool
153  // write warning if netedit is running in testing mode
154  WRITE_DEBUG("Opening question FXMessageBox 'save TLS'");
155  // open question box
156  FXuint answer = FXMessageBox::question(this, MBOX_YES_NO_CANCEL,
157  "Save TLS Changes", "%s",
158  "There is unsaved changes in current edited traffic light.\nDo you want to save it before changing mode?");
159  if (answer == MBOX_CLICKED_YES) { //1:yes, 2:no, 4:esc/cancel
160  // write warning if netedit is running in testing mode
161  WRITE_DEBUG("Closed FXMessageBox 'save TLS' with 'YES'");
162  // save modifications
163  onCmdOK(0, 0, 0);
164  return true;
165  } else if (answer == MBOX_CLICKED_NO) {
166  // write warning if netedit is running in testing mode
167  WRITE_DEBUG("Closed FXMessageBox 'save TLS' with 'No'");
168  // cancel modifications
169  onCmdCancel(0, 0, 0);
170  return true;
171  } else {
172  // write warning if netedit is running in testing mode
173  WRITE_DEBUG("Closed FXMessageBox 'save TLS' with 'Cancel'");
174  // abort changing mode
175  return false;
176  }
177  } else {
178  return true;
179  }
180 }
181 
182 
183 bool
184 GNETLSEditorFrame::parseTLSPrograms(const std::string& file) {
185  myViewNet->getUndoList()->p_begin("Loading TLS");
187  if (myTLSFile->checkTLSValids()) {
188  for (auto i : myTLSFile->getLoadedTLS()) {
189  GNEJunction* junction = myViewNet->getNet()->retrieveJunction(i->getID());
190  myViewNet->getUndoList()->add(new GNEChange_TLS(junction, i, true), true);
191  }
193  } else {
195  }
196  return true;
197 }
198 
199 
200 long
201 GNETLSEditorFrame::onCmdCancel(FXObject*, FXSelector, void*) {
202  if (myTLSJunction->getCurrentJunction() != 0) {
204  cleanup();
205  myViewNet->update();
206  // disable TLS File
208  }
209  return 1;
210 }
211 
212 
213 long
214 GNETLSEditorFrame::onCmdOK(FXObject*, FXSelector, void*) {
215  if (myTLSJunction->getCurrentJunction() != 0) {
218  std::vector<NBNode*> nodes = oldDefinition->getNodes();
219  for (auto it : nodes) {
220  GNEJunction* junction = myViewNet->getNet()->retrieveJunction(it->getID());
221  myViewNet->getUndoList()->add(new GNEChange_TLS(junction, oldDefinition, false), true);
222  myViewNet->getUndoList()->add(new GNEChange_TLS(junction, myEditedDef, true), true);
223  }
224  myEditedDef = nullptr;
226  cleanup();
227  myViewNet->update();
228  } else {
229  onCmdCancel(0, 0, 0);
230  }
231  }
232  return 1;
233 }
234 
235 
236 long
237 GNETLSEditorFrame::onCmdDefCreate(FXObject*, FXSelector, void*) {
239  // abort because we onCmdOk assumes we wish to save an edited definition
240  onCmdCancel(0, 0, 0);
241  // check that current junction has two or more edges
242  if ((junction->getGNEIncomingEdges().size() > 0) && (junction->getGNEOutgoingEdges().size() > 0)) {
245  } else {
246  myViewNet->getUndoList()->add(new GNEChange_TLS(junction, 0, true, true), true);
247  }
248  editJunction(junction);
249  } else {
250  // write warning if netedit is running in testing mode
251  WRITE_DEBUG("Opening warning FXMessageBox 'invalid TLS'");
252  // open question box
253  FXMessageBox::warning(this, MBOX_OK,
254  "TLS cannot be created", "%s",
255  "Traffic Light cannot be created because junction must have\n at least one incoming edge and one outgoing edge.");
256  // write warning if netedit is running in testing mode
257  WRITE_DEBUG("Closed FXMessageBox 'invalid TLS'");
258  }
259  return 1;
260 }
261 
262 
263 long
264 GNETLSEditorFrame::onCmdDefDelete(FXObject*, FXSelector, void*) {
266  const bool changeType = myTLSAttributes->getNumberOfTLSDefinitions() == 1;
268  onCmdCancel(0, 0, 0); // abort because onCmdOk assumes we wish to save an edited definition
269  if (changeType) {
271  } else {
272  myViewNet->getUndoList()->add(new GNEChange_TLS(junction, tlDef, false), true);
273  }
274  return 1;
275 }
276 
277 
278 long
279 GNETLSEditorFrame::onCmdDefSwitch(FXObject*, FXSelector, void*) {
280  assert(myTLSJunction->getCurrentJunction() != 0);
283  // logic may not have been recomputed yet. recompute to be sure
286  NBTrafficLightLogic* tllogic = tllCont.getLogic(tlDef->getID(), tlDef->getProgramID());
287  if (tllogic != 0) {
288  // now we can be sure that the tlDef is up to date (i.e. re-guessed)
289  buildIinternalLanes(tlDef);
290  // create working copy from original def
291  delete myEditedDef;
292  myEditedDef = new NBLoadedSUMOTLDef(tlDef, tllogic);
297  } else {
298  // tlDef has no valid logic (probably because id does not control any links
299  onCmdCancel(0, 0, 0);
300  myViewNet->setStatusBarText("Traffic light does not control any links");
301  }
302  return 1;
303 }
304 
305 
306 long
307 GNETLSEditorFrame::onUpdDefSwitch(FXObject* o, FXSelector, void*) {
309  o->handle(this, FXSEL(SEL_COMMAND, enable ? FXWindow::ID_ENABLE : FXWindow::ID_DISABLE), 0);
310  return 1;
311 }
312 
313 
314 long
315 GNETLSEditorFrame::onUpdNeedsDef(FXObject* o, FXSelector, void*) {
316  const bool enable = myTLSAttributes->getNumberOfTLSDefinitions() > 0;
317  o->handle(this, FXSEL(SEL_COMMAND, enable ? FXWindow::ID_ENABLE : FXWindow::ID_DISABLE), 0);
318  return 1;
319 }
320 
321 
322 long
323 GNETLSEditorFrame::onUpdNeedsDefAndPhase(FXObject* o, FXSelector, void*) {
324  // do not delete the last phase
325  const bool enable = myTLSAttributes->getNumberOfTLSDefinitions() > 0 && myTLSPhases->getPhaseTable()->getNumRows() > 1;
326  o->handle(this, FXSEL(SEL_COMMAND, enable ? FXWindow::ID_ENABLE : FXWindow::ID_DISABLE), 0);
327  return 1;
328 }
329 
330 
331 long
332 GNETLSEditorFrame::onUpdDefCreate(FXObject* o, FXSelector, void*) {
334  o->handle(this, FXSEL(SEL_COMMAND, enable ? FXWindow::ID_ENABLE : FXWindow::ID_DISABLE), 0);
335  return 1;
336 }
337 
338 
339 long
340 GNETLSEditorFrame::onUpdModified(FXObject* o, FXSelector, void*) {
342  o->handle(this, FXSEL(SEL_COMMAND, enable ? FXWindow::ID_ENABLE : FXWindow::ID_DISABLE), 0);
343  return 1;
344 }
345 
346 
347 
348 long
349 GNETLSEditorFrame::onCmdDefOffset(FXObject*, FXSelector, void*) {
352  return 1;
353 }
354 
355 
356 long
357 GNETLSEditorFrame::onCmdDefRename(FXObject*, FXSelector, void*) {
358  return 1;
359 }
360 
361 
362 long
363 GNETLSEditorFrame::onCmdDefSubRename(FXObject*, FXSelector, void*) {
364  return 1;
365 }
366 
367 
368 long
369 GNETLSEditorFrame::onCmdDefAddOff(FXObject*, FXSelector, void*) {
370  return 1;
371 }
372 
373 
374 long
375 GNETLSEditorFrame::onCmdGuess(FXObject*, FXSelector, void*) {
376  return 1;
377 }
378 
379 
380 long
381 GNETLSEditorFrame::onCmdPhaseSwitch(FXObject*, FXSelector, void*) {
382  const int index = myTLSPhases->getPhaseTable()->getCurrentRow();
383  const NBTrafficLightLogic::PhaseDefinition& phase = getPhases()[index];
384  myTLSPhases->getPhaseTable()->selectRow(index);
385  // need not hold since links could have been deleted somewhere else and indices may be reused
386  // assert(phase.state.size() == myInternalLanes.size());
387  for (auto it : myInternalLanes) {
388  int tlIndex = it.first;
389  std::vector<GNEInternalLane*> lanes = it.second;
391  if (tlIndex >= 0 && tlIndex < (int)phase.state.size()) {
392  state = (LinkState)phase.state[tlIndex];
393  }
394  for (auto it_lane : lanes) {
395  it_lane->setLinkState(state);
396  }
397  }
398  myViewNet->update();
399  return 1;
400 }
401 
402 
403 long
404 GNETLSEditorFrame::onCmdPhaseCreate(FXObject*, FXSelector, void*) {
406  // allows insertion at first position by deselecting via arrow keys
407  int newIndex = myTLSPhases->getPhaseTable()->getSelStartRow() + 1;
408  int oldIndex = MAX2(0, myTLSPhases->getPhaseTable()->getSelStartRow());
409  // copy current row
410  const bool fixed = myEditedDef->getType() == TLTYPE_STATIC;
411  SUMOTime duration = getSUMOTime(myTLSPhases->getPhaseTable()->getItemText(oldIndex, 0));
412  std::string state = myTLSPhases->getPhaseTable()->getItemText(oldIndex, fixed ? 1 : 3).text();
413 
414  // smart adapations for new state
415  bool haveGreen = false;
416  bool haveYellow = false;
417  for (char c : state) {
419  haveGreen = true;
420  } else if (c == LINKSTATE_TL_YELLOW_MAJOR || c == LINKSTATE_TL_YELLOW_MINOR) {
421  haveYellow = true;
422  }
423  }
424  const OptionsCont& oc = OptionsCont::getOptions();
425  if (haveGreen && haveYellow) {
426  // guess left-mover state
427  duration = TIME2STEPS(oc.getInt("tls.left-green.time"));
428  for (int i = 0; i < (int)state.size(); i++) {
429  if (state[i] == LINKSTATE_TL_YELLOW_MAJOR || state[i] == LINKSTATE_TL_YELLOW_MINOR) {
430  state[i] = LINKSTATE_TL_RED;
431  } else if (state[i] == LINKSTATE_TL_GREEN_MINOR) {
432  state[i] = LINKSTATE_TL_GREEN_MAJOR;
433  }
434  }
435  } else if (haveGreen) {
436  // guess yellow state
438  duration = TIME2STEPS(myEditedDef->computeBrakingTime(oc.getFloat("tls.yellow.min-decel")));
439  for (int i = 0; i < (int)state.size(); i++) {
440  if (state[i] == LINKSTATE_TL_GREEN_MAJOR || state[i] == LINKSTATE_TL_GREEN_MINOR) {
441  state[i] = LINKSTATE_TL_YELLOW_MINOR;
442  }
443  }
444  } else if (haveYellow) {
445  duration = TIME2STEPS(oc.isDefault("tls.allred.time") ? 2 : oc.getInt("tls.allred.time"));
446  // guess all-red state
447  for (int i = 0; i < (int)state.size(); i++) {
448  if (state[i] == LINKSTATE_TL_YELLOW_MAJOR || state[i] == LINKSTATE_TL_YELLOW_MINOR) {
449  state[i] = LINKSTATE_TL_RED;
450  }
451  }
452  }
453 
454  myEditedDef->getLogic()->addStep(duration, state, newIndex);
455  myTLSPhases->getPhaseTable()->setCurrentItem(newIndex, 0);
456  myTLSPhases->initPhaseTable(newIndex);
457  myTLSPhases->getPhaseTable()->setFocus();
458  return 1;
459 }
460 
461 
462 long
463 GNETLSEditorFrame::onCmdPhaseDelete(FXObject*, FXSelector, void*) {
465  const int newRow = MAX2((int)0, (int)myTLSPhases->getPhaseTable()->getCurrentRow() - 1);
466  myEditedDef->getLogic()->deletePhase(myTLSPhases->getPhaseTable()->getCurrentRow());
467  myTLSPhases->initPhaseTable(newRow);
468  myTLSPhases->getPhaseTable()->setFocus();
469  return 1;
470 }
471 
472 
473 long
474 GNETLSEditorFrame::onCmdCleanup(FXObject*, FXSelector, void*) {
477  myTLSPhases->getPhaseTable()->setFocus();
478  return 1;
479 }
480 
481 
482 long
483 GNETLSEditorFrame::onCmdAddUnused(FXObject*, FXSelector, void*) {
485  myEditedDef->getLogic()->getNumLinks() + 1);
488  myTLSPhases->getPhaseTable()->setFocus();
489  return 1;
490 }
491 
492 
493 long
494 GNETLSEditorFrame::onCmdPhaseEdit(FXObject*, FXSelector, void* ptr) {
495  /* @note: there is a bug when copying/pasting rows: when this handler is
496  * called the value of the cell is not yet updated. This means you have to
497  * click inside the cell and hit enter to actually update the value */
498  FXTablePos* tp = (FXTablePos*)ptr;
499  FXString value = myTLSPhases->getPhaseTable()->getItemText(tp->row, tp->col);
500  const bool fixed = myEditedDef->getType() == TLTYPE_STATIC;
501  if (tp->col == 0) {
502  // duration edited
503  if (GNEAttributeCarrier::canParse<double>(value.text())) {
504  SUMOTime duration = getSUMOTime(value);
505  if (duration > 0) {
506  myEditedDef->getLogic()->setPhaseDuration(tp->row, duration);
509  return 1;
510  }
511  }
512  // input error, reset value
513  myTLSPhases->getPhaseTable()->setItemText(tp->row, 0, toString(STEPS2TIME(getPhases()[tp->row].duration)).c_str());
514  } else if (!fixed && tp->col == 1) {
515  // minDur edited
516  if (GNEAttributeCarrier::canParse<double>(value.text())) {
517  SUMOTime minDur = getSUMOTime(value);
518  if (minDur > 0) {
519  myEditedDef->getLogic()->setPhaseMinDuration(tp->row, minDur);
521  return 1;
522  }
523  } else if (StringUtils::prune(value.text()).empty()) {
526  return 1;
527  }
528  // input error, reset value
529  myTLSPhases->getPhaseTable()->setItemText(tp->row, 1, varDurString(getPhases()[tp->row].minDur).c_str());
530  } else if (!fixed && tp->col == 2) {
531  // minDur edited
532  if (GNEAttributeCarrier::canParse<double>(value.text())) {
533  SUMOTime maxDur = getSUMOTime(value);
534  if (maxDur > 0) {
535  myEditedDef->getLogic()->setPhaseMaxDuration(tp->row, maxDur);
537  return 1;
538  }
539  } else if (StringUtils::prune(value.text()).empty()) {
542  return 1;
543  }
544  // input error, reset value
545  myTLSPhases->getPhaseTable()->setItemText(tp->row, 2, varDurString(getPhases()[tp->row].maxDur).c_str());
546  } else {
547  // state edited
548  try {
549  // insert phase with new step and delete the old phase
550  myEditedDef->getLogic()->addStep(getPhases()[tp->row].duration, value.text(), tp->row);
551  myEditedDef->getLogic()->deletePhase(tp->row + 1);
553  onCmdPhaseSwitch(0, 0, 0);
554  } catch (ProcessError&) {
555  // input error, reset value
556  myTLSPhases->getPhaseTable()->setItemText(tp->row, 1, getPhases()[tp->row].state.c_str());
557  }
558  }
559  return 1;
560 }
561 
562 
563 void
567  }
568  // clean data structures
571  delete myEditedDef;
572  myEditedDef = nullptr;
573  buildIinternalLanes(0); // only clears
574  // clean up controls
576  myTLSPhases->initPhaseTable(); // only clears when there are no definitions
579 }
580 
581 
582 void
585  // clean up previous objects
586  for (auto it : myInternalLanes) {
587  for (auto it_intLanes : it.second) {
588  rtree.removeAdditionalGLObject(it_intLanes);
589  delete it_intLanes;
590  }
591  }
592  myInternalLanes.clear();
593  // create new internal lanes
594  if (tlDef != 0) {
595  const int NUM_POINTS = 10;
598  std::string innerID = ":" + nbn->getID(); // see NWWriter_SUMO::writeInternalEdges
599  const NBConnectionVector& links = tlDef->getControlledLinks();
600  for (auto it : links) {
601  int tlIndex = it.getTLIndex();
602  PositionVector shape = it.getFrom()->getToNode()->computeInternalLaneShape(it.getFrom(), NBEdge::Connection(it.getFromLane(),
603  it.getTo(), it.getToLane()), NUM_POINTS);
604  GNEInternalLane* ilane = new GNEInternalLane(this, innerID + '_' + toString(tlIndex), shape, tlIndex);
605  rtree.addAdditionalGLObject(ilane);
606  myInternalLanes[tlIndex].push_back(ilane);
607  }
608  for (auto c : nbn->getCrossings()) {
609  if (c->tlLinkIndex2 > 0 && c->tlLinkIndex2 != c->tlLinkIndex) {
610  // draw both directions
611  PositionVector forward = c->shape;
612  forward.move2side(c->width / 4);
613  GNEInternalLane* ilane = new GNEInternalLane(this, c->id, forward, c->tlLinkIndex);
614  rtree.addAdditionalGLObject(ilane);
615  myInternalLanes[c->tlLinkIndex].push_back(ilane);
616 
617  PositionVector backward = c->shape.reverse();
618  backward.move2side(c->width / 4);
619  GNEInternalLane* ilane2 = new GNEInternalLane(this, c->id + "_r", backward, c->tlLinkIndex2);
620  rtree.addAdditionalGLObject(ilane2);
621  myInternalLanes[c->tlLinkIndex2].push_back(ilane2);
622  } else {
623  // draw only one lane for both directions
624  GNEInternalLane* ilane = new GNEInternalLane(this, c->id, c->shape, c->tlLinkIndex);
625  rtree.addAdditionalGLObject(ilane);
626  myInternalLanes[c->tlLinkIndex].push_back(ilane);
627  }
628  }
629  }
630 }
631 
632 
633 std::string
636 }
637 
638 
639 const std::vector<NBTrafficLightLogic::PhaseDefinition>&
641  return myEditedDef->getLogic()->getPhases();
642 }
643 
644 
645 void
648  if (myViewNet->changeAllPhases()) {
649  const std::vector<NBTrafficLightLogic::PhaseDefinition>& phases = getPhases();
650  for (int row = 0; row < (int)phases.size(); row++) {
651  myEditedDef->getLogic()->setPhaseState(row, lane->getTLIndex(), lane->getLinkState());
652  }
653  } else {
654  myEditedDef->getLogic()->setPhaseState(myTLSPhases->getPhaseTable()->getCurrentRow(), lane->getTLIndex(), lane->getLinkState());
655  }
656  myTLSPhases->initPhaseTable(myTLSPhases->getPhaseTable()->getCurrentRow());
657  myTLSPhases->getPhaseTable()->setFocus();
658 }
659 
660 
661 void
662 GNETLSEditorFrame::handleMultiChange(GNELane* lane, FXObject* obj, FXSelector sel, void* eventData) {
663  if (myEditedDef != 0) {
666  std::set<std::string> fromIDs;
667  fromIDs.insert(lane->getMicrosimID());
668  GNEEdge& edge = lane->getParentEdge();
669  // if neither the lane nor its edge are selected, apply changes to the whole edge
670  if (!edge.isAttributeCarrierSelected() && !lane->isAttributeCarrierSelected()) {
671  for (auto it_lane : edge.getLanes()) {
672  fromIDs.insert(it_lane->getMicrosimID());
673  }
674  } else {
675  // if the edge is selected, apply changes to all lanes of all selected edges
676  if (edge.isAttributeCarrierSelected()) {
677  std::vector<GNEEdge*> edges = myViewNet->getNet()->retrieveEdges(true);
678  for (auto it : edges) {
679  for (auto it_lane : it->getLanes()) {
680  fromIDs.insert(it_lane->getMicrosimID());
681  }
682  }
683  }
684  // if the lane is selected, apply changes to all selected lanes
685  if (lane->isAttributeCarrierSelected()) {
686  std::vector<GNELane*> lanes = myViewNet->getNet()->retrieveLanes(true);
687  for (auto it_lane : lanes) {
688  fromIDs.insert(it_lane->getMicrosimID());
689  }
690  }
691 
692  }
693  // set new state for all connections from the chosen lane IDs
694  for (auto it : links) {
695  if (fromIDs.count(it.getFrom()->getLaneID(it.getFromLane())) > 0) {
696  std::vector<GNEInternalLane*> lanes = myInternalLanes[it.getTLIndex()];
697  for (auto it_lane : lanes) {
698  it_lane->onDefault(obj, sel, eventData);
699  }
700  }
701  }
702  }
703 }
704 
705 
706 bool
708  if (myEditedDef != 0) {
710  for (auto it : links) {
711  if (it.getFrom()->getID() == edge.getMicrosimID()) {
712  return true;
713  }
714  }
715  }
716  return false;
717 }
718 
719 
720 SUMOTime
721 GNETLSEditorFrame::getSUMOTime(const FXString& string) {
722  assert(GNEAttributeCarrier::canParse<double>(string.text()));
723  return TIME2STEPS(GNEAttributeCarrier::parse<double>(string.text()));
724 }
725 
726 // ---------------------------------------------------------------------------
727 // GNETLSEditorFrame::TLSAttributes - methods
728 // ---------------------------------------------------------------------------
729 
731  FXGroupBox(TLSEditorParent->myContentFrame, "Traffic light Attributes", GUIDesignGroupBoxFrame),
732  myTLSEditorParent(TLSEditorParent) {
733 
734  // create frame, label and textfield for name (By default disabled)
735  FXHorizontalFrame* nameFrame = new FXHorizontalFrame(this, GUIDesignAuxiliarHorizontalFrame);
736  myNameLabel = new FXLabel(nameFrame, "ID", 0, GUIDesignLabelAttribute);
738  myNameTextField->disable();
739 
740  // create frame, label and comboBox for Program (By default hidden)
741  FXHorizontalFrame* programFrame = new FXHorizontalFrame(this, GUIDesignAuxiliarHorizontalFrame);
742  myProgramLabel = new FXLabel(programFrame, "Program", 0, GUIDesignLabelAttribute);
744  myProgramComboBox->disable();
745 
746  // create frame, label and TextField for Offset (By default disabled)
747  FXHorizontalFrame* offsetFrame = new FXHorizontalFrame(this, GUIDesignAuxiliarHorizontalFrame);
748  myOffsetLabel = new FXLabel(offsetFrame, "Offset", 0, GUIDesignLabelAttribute);
750  myOffsetTextField->disable();
751 }
752 
753 
755 
756 
757 void
759  assert(junction);
760  myTLSDefinitions.clear();
761  // enable name TextField
762  myNameTextField->enable();
763  // enable Offset
764  myOffsetTextField->enable();
765  // obtain TLSs
766  for (auto it : junction->getNBNode()->getControllingTLS()) {
767  myTLSDefinitions.push_back(it);
768  myNameTextField->setText(it->getID().c_str());
769  myNameTextField->enable();
770  myProgramComboBox->appendItem(it->getProgramID().c_str());
771  // enable TLS
773  }
774  if (myTLSDefinitions.size() > 0) {
775  myProgramComboBox->enable();
776  myProgramComboBox->setCurrentItem(0);
777  myProgramComboBox->setNumVisible(myProgramComboBox->getNumItems());
779  // enable TLS
781  }
782 }
783 
784 
785 void
787  // clear definitions
788  myTLSDefinitions.clear();
789  // clear and disable name TextField
790  myNameTextField->setText("");
791  myNameTextField->disable();
792  // clear and disable myProgramComboBox
793  myProgramComboBox->clearItems();
794  myProgramComboBox->disable();
795  // clear and disable Offset TextField
796  myOffsetTextField->setText("");
797  myOffsetTextField->disable();
798 }
799 
800 
803  return myTLSDefinitions.at(myProgramComboBox->getCurrentItem());
804 }
805 
806 
807 int
809  return (int)myTLSDefinitions.size();
810 }
811 
812 
813 int
815  return myProgramComboBox->getNumItems();
816 }
817 
818 
819 SUMOTime
821  return getSUMOTime(myOffsetTextField->getText());
822 }
823 
824 
825 void
827  myOffsetTextField->setText(toString(STEPS2TIME(offset)).c_str());
828 }
829 
830 // ---------------------------------------------------------------------------
831 // GNETLSEditorFrame::TLSJunction - methods
832 // ---------------------------------------------------------------------------
833 
835  FXGroupBox(TLSEditorParent->myContentFrame, "Junction", GUIDesignGroupBoxFrame),
836  myTLSEditorParent(TLSEditorParent),
837  myCurrentJunction(nullptr) {
838  // Create frame for junction ID
839  FXHorizontalFrame* junctionIDFrame = new FXHorizontalFrame(this, GUIDesignAuxiliarHorizontalFrame);
840  myLabelJunctionID = new FXLabel(junctionIDFrame, "Junction ID", 0, GUIDesignLabelAttribute);
842  myTextFieldJunctionID->setEditable(false);
843  // create frame for junction status
844  FXHorizontalFrame* junctionIDStatus = new FXHorizontalFrame(this, GUIDesignAuxiliarHorizontalFrame);
845  myLabelJunctionStatus = new FXLabel(junctionIDStatus, "Status", 0, GUIDesignLabelAttribute);
847  myTextFieldJunctionStatus->setEditable(false);
848  // update junction description after creation
850  // show TLS Junction
851  show();
852 }
853 
854 
856 
857 
860  return myCurrentJunction;
861 }
862 
863 
864 void
866  myCurrentJunction = junction;
867 }
868 
869 
870 void
872  if (myCurrentJunction == 0) {
873  myTextFieldJunctionID->setText("");
874  myTextFieldJunctionStatus->setText("");
875  } else {
877  myTextFieldJunctionID->setText(nbn->getID().c_str());
878  if (!nbn->isTLControlled()) {
879  myTextFieldJunctionStatus->setText("uncontrolled");
880  } else {
882  }
883  }
884 }
885 
886 // ---------------------------------------------------------------------------
887 // GNETLSEditorFrame::TLSDefinition - methods
888 // ---------------------------------------------------------------------------
889 
891  FXGroupBox(TLSEditorParent->myContentFrame, "Traffic lights definition", GUIDesignGroupBoxFrame),
892  myTLSEditorParent(TLSEditorParent) {
893  // create create tlDef button
894  myNewTLProgram = new FXButton(this, "Create TLS\t\tCreate a new traffic light program",
896  // create delete tlDef button
897  myDeleteTLProgram = new FXButton(this, "Delete TLS\t\tDelete a traffic light program. If all programs are deleted the junction turns into a priority junction.",
899  // show TLS TLSDefinition
900  show();
901 }
902 
903 
905 
906 // ---------------------------------------------------------------------------
907 // GNETLSEditorFrame::TLSPhases - methods
908 // ---------------------------------------------------------------------------
909 
911  FXGroupBox(TLSEditorParent->myContentFrame, "Phases", GUIDesignGroupBoxFrame),
912  myTLSEditorParent(TLSEditorParent),
913  myTableFont(new FXFont(getApp(), "Courier New", 9)) {
914 
915  // create and configure phase table
916  myTableScroll = new FXScrollWindow(this, LAYOUT_FILL_X | LAYOUT_FIX_HEIGHT);
918  myPhaseTable->setColumnHeaderMode(LAYOUT_FIX_HEIGHT);
919  myPhaseTable->setColumnHeaderHeight(0);
920  myPhaseTable->setRowHeaderMode(LAYOUT_FIX_WIDTH);
921  myPhaseTable->setRowHeaderWidth(0);
922  myPhaseTable->hide();
923  myPhaseTable->setFont(myTableFont);
924  myPhaseTable->setHelpText("phase duration in seconds | phase state");
925 
926  // create total duration info label
927  myCycleDuration = new FXLabel(this, "", 0, GUIDesignLabelLeft);
928 
929  // create new phase button
930  myInsertDuplicateButton = new FXButton(this, "Insert Phase\t\tInsert new phase after the selected phase. The new state is deduced from the selected phase.", 0, myTLSEditorParent, MID_GNE_TLSFRAME_PHASE_CREATE, GUIDesignButton);
931 
932  // create delete phase button
933  myDeleteSelectedPhaseButton = new FXButton(this, "Delete Phase\t\tDelete selected phase", 0, myTLSEditorParent, MID_GNE_TLSFRAME_PHASE_DELETE, GUIDesignButton);
934 
935  // create cleanup states button
936  new FXButton(this, "Cleanup States\t\tClean unused states from all phase.", 0, myTLSEditorParent, MID_GNE_TLSFRAME_CLEANUP, GUIDesignButton);
937 
938  // add unused states button
939  new FXButton(this, "Add Unused States\t\tExtend the state vector for all phases by one entry.", 0, myTLSEditorParent, MID_GNE_TLSFRAME_ADDUNUSED, GUIDesignButton);
940 
941  // show TLSFile
942  show();
943 }
944 
945 
947  delete myTableFont;
948 }
949 
950 
951 FXTable*
953  return myPhaseTable;
954 }
955 
956 
957 void
959  myPhaseTable->setVisibleRows(1);
960  myPhaseTable->setVisibleColumns(2);
961  myPhaseTable->hide();
963  const bool fixed = myTLSEditorParent->myEditedDef->getType() == TLTYPE_STATIC;
964  const std::vector<NBTrafficLightLogic::PhaseDefinition>& phases = myTLSEditorParent->getPhases();
965  myPhaseTable->setTableSize((int)phases.size(), fixed ? 2 : 4);
966  myPhaseTable->setVisibleRows((int)phases.size());
967  myPhaseTable->setVisibleColumns(fixed ? 2 : 4);
968  for (int row = 0; row < (int)phases.size(); row++) {
969  myPhaseTable->setItemText(row, 0, toString(STEPS2TIME(phases[row].duration)).c_str());
970  if (!fixed) {
971  myPhaseTable->setItemText(row, 1, varDurString(phases[row].minDur).c_str());
972  myPhaseTable->setItemText(row, 2, varDurString(phases[row].maxDur).c_str());
973  }
974  myPhaseTable->setItemText(row, fixed ? 1 : 3, phases[row].state.c_str());
975  myPhaseTable->getItem(row, 1)->setJustify(FXTableItem::LEFT);
976  }
977  myPhaseTable->fitColumnsToContents(0, fixed ? 2 : 4);
978  myPhaseTable->setHeight((int)phases.size() * 21); // experimental
979  myPhaseTable->setCurrentItem(index, 0);
980  myPhaseTable->selectRow(index, true);
981  myPhaseTable->show();
982  myPhaseTable->setFocus();
983  myTableScroll->setHeight(myPhaseTable->getHeight() + 10);
984  }
985  update();
986 }
987 
988 
989 void
991  myCycleDuration->show();
992 }
993 
994 
995 void
997  myCycleDuration->hide();
998 }
999 
1000 void
1002  SUMOTime cycleDuration = 0;
1003  for (auto it : myTLSEditorParent->getPhases()) {
1004  cycleDuration += it.duration;
1005  }
1006  std::string text = "Cycle time: " + toString(STEPS2TIME(cycleDuration));
1007  myCycleDuration->setText(text.c_str());
1008 }
1009 
1010 // ---------------------------------------------------------------------------
1011 // GNETLSEditorFrame::TLSModifications - methods
1012 // ---------------------------------------------------------------------------
1013 
1015  FXGroupBox(TLSEditorParent->myContentFrame, "Modifications", GUIDesignGroupBoxFrame),
1016  myTLSEditorParent(TLSEditorParent),
1017  myHaveModifications(false) {
1018  // create save modifications button
1019  mySaveModificationsButtons = new FXButton(this, "Save\t\tSave program modifications (Enter)",
1021  // create discard modifications buttons
1022  myDiscardModificationsButtons = new FXButton(this, "Cancel\t\tDiscard program modifications (Esc)",
1024  // show TLSModifications
1025  show();
1026 }
1027 
1028 
1030 
1031 
1032 bool
1034  return myHaveModifications;
1035 }
1036 
1037 
1038 void
1040  myHaveModifications = value;
1041 }
1042 
1043 // ---------------------------------------------------------------------------
1044 // GNETLSEditorFrame::TLSFile - methods
1045 // ---------------------------------------------------------------------------
1046 
1048  FXGroupBox(TLSEditorParent->myContentFrame, "TLS Program", GUIDesignGroupBoxFrame),
1049  SUMOSAXHandler("TLS-Program"),
1050  myTLSEditorParent(TLSEditorParent) {
1051  // create create tlDef button
1052  myLoadTLSProgramButton = new FXButton(this, "Load TLS Program", 0, this, MID_GNE_TLSFRAME_LOAD_PROGRAM, GUIDesignButton);
1053  // create create tlDef button
1054  mySaveTLSProgramButton = new FXButton(this, "Save TLS Program", 0, this, MID_GNE_TLSFRAME_SAVE_PROGRAM, GUIDesignButton);
1055  // by default TLSFile is disabled
1056  disableTLSFile();
1057  // show TLSFile
1058  show();
1059 }
1060 
1061 
1063 
1064 
1065 void
1067  bool ok = true;
1068  switch (element) {
1069  case SUMO_TAG_TLLOGIC: {
1070  std::string id = attrs.get<std::string>(SUMO_ATTR_ID, 0, ok);
1071  if (myTLSEditorParent->getViewNet()->getNet()->retrieveJunction(id, false) == nullptr) {
1072  WRITE_ERROR("ERROR, Junction doesn't exist");
1073  } else {
1074  std::string programID = attrs.getOpt<std::string>(SUMO_ATTR_PROGRAMID, id.c_str(), ok, "<unknown>");
1076  std::string typeS = attrs.get<std::string>(SUMO_ATTR_TYPE, 0, ok);
1077  if (SUMOXMLDefinitions::TrafficLightTypes.hasString(typeS)) {
1079  } else {
1080  WRITE_ERROR("Traffic light '" + id + "' has unknown type '" + typeS + "'.");
1081  }
1082  const SUMOTime offset = attrs.getOptSUMOTimeReporting(SUMO_ATTR_OFFSET, id.c_str(), ok, 0);
1083  // avoid to insert duplicated TLSs
1084  myLoadedTLS.push_back(new NBLoadedSUMOTLDef(id, programID, offset, type));
1085  }
1086  break;
1087  }
1088  case SUMO_TAG_PHASE: {
1089  if (myLoadedTLS.size() > 0) {
1090  double duration = attrs.get<double>(SUMO_ATTR_DURATION, 0, ok);
1091  std::string state = attrs.get<std::string>(SUMO_ATTR_STATE, 0, ok);
1092  myLoadedTLS.back()->getLogic()->addStep(TIME2STEPS(duration), state);
1093  break;
1094  }
1095  }
1096  default:
1097  break;
1098  }
1099 }
1100 
1101 
1102 void
1104  // enable buttons
1105  myLoadTLSProgramButton->enable();
1106  mySaveTLSProgramButton->enable();
1107 }
1108 
1109 
1110 void
1112  // disable buttons
1113  myLoadTLSProgramButton->disable();
1114  mySaveTLSProgramButton->disable();
1115 }
1116 
1117 
1118 void
1120  for (auto i : myLoadedTLS) {
1121  delete i;
1122  }
1123  myLoadedTLS.clear();
1124 }
1125 
1126 
1127 const std::vector<NBLoadedSUMOTLDef*>&
1129  return myLoadedTLS;
1130 }
1131 
1132 
1133 bool
1135  std::vector<NBLoadedSUMOTLDef*> definitionsJunctionsWithoutTL;
1136  for (auto i : myLoadedTLS) {
1137  if (myTLSEditorParent->getViewNet()->getNet()->retrieveJunction(i->getID())->getNBNode()->isTLControlled() == false) {
1138  definitionsJunctionsWithoutTL.push_back(i);
1139  }
1140  }
1141  // check if there is definitions loaded with an uncontrolled junction asociated
1142  if (definitionsJunctionsWithoutTL.size() > 0) {
1143  // write warning if netedit is running in testing mode
1144  WRITE_DEBUG("Opening question FXMessageBox 'create TLS in uncontrolled junctions'");
1145  // open question box
1146  FXuint answer = FXMessageBox::question(myTLSEditorParent, MBOX_YES_NO_CANCEL,
1147  "Create TLS", "%s",
1148  ("There is " + toString(definitionsJunctionsWithoutTL.size()) + " TLS without controlled junction.\nDo you want to create TLSs in uncontrolled Junctions?").c_str());
1149  if (answer == MBOX_CLICKED_YES) { //1:yes, 2:no, 4:esc/cancel
1150  // write warning if netedit is running in testing mode
1151  WRITE_DEBUG("Closed FXMessageBox 'create TLS in uncontrolled junctions' with 'Yes'");
1152  // convert Junctions in TLS
1153  for (auto i : definitionsJunctionsWithoutTL) {
1154  GNEJunction* junction = myTLSEditorParent->getViewNet()->getNet()->retrieveJunction(i->getID());
1155  junction->setAttribute(SUMO_ATTR_TYPE, "traffic_light", myTLSEditorParent->getViewNet()->getUndoList());
1156  }
1157  } else if (answer == MBOX_CLICKED_NO) {
1158  // write warning if netedit is running in testing mode
1159  WRITE_DEBUG("Closed FXMessageBox 'create TLS in uncontrolled junctions' with 'No'");
1160  // delete loaded TLSs without associated controlled Junction
1161  for (auto i : definitionsJunctionsWithoutTL) {
1162  myLoadedTLS.erase(std::find(myLoadedTLS.begin(), myLoadedTLS.end(), i));
1163  delete i;
1164  }
1165  } else {
1166  // write warning if netedit is running in testing mode
1167  WRITE_DEBUG("Closed FXMessageBox 'create TLS in uncontrolled junctions' with 'Cancel'");
1168  // return false to abort loading of TLSs
1169  return false;
1170  }
1171  }
1172 
1173  // return true to continue loading TLSs
1174  return true;
1175 }
1176 
1177 
1178 long
1180  FXFileDialog opendialog(this, "Load TLS Program");
1181  opendialog.setIcon(GUIIconSubSys::getIcon(ICON_MODETLS));
1182  opendialog.setSelectMode(SELECTFILE_EXISTING);
1183  opendialog.setPatternList("*.xml");
1184  if (gCurrentFolder.length() != 0) {
1185  opendialog.setDirectory(gCurrentFolder);
1186  }
1187  if (opendialog.execute()) {
1188  // first clear loaded phases
1189  clearLoadedTLS();
1190  // run parser
1191  XMLSubSys::runParser(*this, opendialog.getFilename().text(), true);
1192 
1194 
1195  // check that only a phase was loaded
1196  /* for(auto i : myLoadedTLS) {
1197  if(i->getID() == myTLSEditorParent->myTLSJunction->getCurrentJunction()->getID()) {
1198  myTLSEditorParent->myEditedDef->getProgramID();
1199 
1200  for (auto j : i.second) {
1201  myTLSEditorParent->myEditedDef->getLogic()->addStep(j.duration, j.state, j.minDur, j.maxDur);
1202  }
1203 
1204  }
1205  }
1206  */
1209  }
1210  return 0;
1211 }
1212 
1213 
1214 long
1216  FXString file = MFXUtils::getFilename2Write(this,
1217  "Save TLS Program as", ".xml",
1219  gCurrentFolder);
1220  if (file == "") {
1221  return 1;
1222  }
1223  OutputDevice& device = OutputDevice::getDevice(file.text());
1224 
1225  // save program
1226  device.openTag(SUMO_TAG_TLLOGIC);
1231  // write the phases
1232  const bool varPhaseLength = myTLSEditorParent->myEditedDef->getLogic()->getType() != TLTYPE_STATIC;
1233  const std::vector<NBTrafficLightLogic::PhaseDefinition>& phases = myTLSEditorParent->myEditedDef->getLogic()->getPhases();
1234  for (auto j : phases) {
1235  device.openTag(SUMO_TAG_PHASE);
1236  device.writeAttr(SUMO_ATTR_DURATION, writeSUMOTime(j.duration));
1237  device.writeAttr(SUMO_ATTR_STATE, j.state);
1238  if (varPhaseLength) {
1240  device.writeAttr(SUMO_ATTR_MINDURATION, writeSUMOTime(j.minDur));
1241  }
1243  device.writeAttr(SUMO_ATTR_MAXDURATION, writeSUMOTime(j.maxDur));
1244  }
1245  }
1246  device.closeTag();
1247  }
1248  device.close();
1249  return 1;
1250 }
1251 
1252 
1253 std::string
1255  double time = STEPS2TIME(steps);
1256  if (time == std::floor(time)) {
1257  return toString(int(time));
1258  } else {
1259  return toString(time);
1260  }
1261 }
1262 /****************************************************************************/
int NUM_POINTS
GNETLSEditorFrame::TLSModifications * myTLSModifications
modul for load/Save TLS Modifications
TLIndexMap myInternalLanes
FXLabel * myLabelJunctionStatus
label for junction status
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:1051
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
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:631
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:441
#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:597
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:154
select phase thable
Definition: GUIAppEnum.h:617
void enableTLSFile()
enable all elements TLSFile
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:68
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:78
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:615
void selectTLS(bool selected)
notify the junction of being selected in tls-mode. (used to control drawing)
definition related controls
Definition: GUIAppEnum.h:603
FXButton * mySaveTLSProgramButton
button for save TLS Programs
maximum duration of a phase
const std::string & getID() const
Returns the id.
Definition: Named.h:69
#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
void myStartElement(int element, const SUMOSAXAttributes &attrs)
Called on the opening of a tag.
SAX-handler base for SUMO-files.
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:766
long onCmdDefOffset(FXObject *, FXSelector, void *)
Called when the user changes the offset of a TLS.
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
void disableTLSFile()
disable all elements TLSFile
delete phase thable
Definition: GUIAppEnum.h:621
bool changeAllPhases() const
change all phases
Definition: GNEViewNet.cpp:349
GNEViewNet * myViewNet
View Net for changes.
Definition: GNEFrame.h:232
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:297
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:235
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:1230
Encapsulated SAX-Attributes.
NBTrafficLightDefinition * getCurrentTLSDefinition() const
get current definition
GNETLSEditorFrame::TLSJunction * myTLSJunction
modul for TLS Junction
const std::vector< GNEEdge * > & getGNEIncomingEdges() const
Returns incoming GNEEdges.
static StringBijection< TrafficLightType > TrafficLightTypes
traffic light types
T get(int attr, const char *objectid, bool &ok, bool report=true) const
Tries to read given attribute assuming it is an int.
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:85
GNEJunction * retrieveJunction(const std::string &id, bool failHard=true)
get junction by id
Definition: GNENet.cpp:894
TLSAttributes(GNETLSEditorFrame *TLSEditorParent)
constructor
#define GUIDesignAuxiliarHorizontalFrame
design for auxiliar (Without borders) horizontal frame used to pack another frames ...
Definition: GUIDesigns.h:258
A list of positions.
bool controlsEdge(GNEEdge &edge) const
whether the given edge is controlled by the currently edited tlDef
GNETLSEditorFrame::TLSFile * myTLSFile
modul for load/Save TLS Programs
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:601
T get(const std::string &str) const
cleanup unused states
Definition: GUIAppEnum.h:623
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:1358
~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:249
void p_abort()
reverts and discards ALL active command groups
Definition: GNEUndoList.cpp:99
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:304
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
#define WRITE_ERROR(msg)
Definition: MsgHandler.h:248
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:619
#define GUIDesignButton
Definition: GUIDesigns.h:54
GNEJunction * myCurrentJunction
the junction of the tls is being modified
T getOpt(int attr, const char *objectid, bool &ok, T defaultValue, bool report=true) const
Tries to read given attribute assuming it is an int.
static std::string varDurString(SUMOTime dur)
convert duration (potentially undefined) to string
const std::vector< NBLoadedSUMOTLDef * > & getLoadedTLS() const
get loaded phases
static std::string prune(const std::string &str)
Removes trailing and leading whitechars.
Definition: StringUtils.cpp:45
FXButton * myLoadTLSProgramButton
button for load TLS Programs
const std::vector< GNELane * > & getLanes()
returns a reference to the lane vector
Definition: GNEEdge.cpp:832
void showCycleDuration()
show cycle duration
virtual void show()
show Frame
Definition: GNEFrame.cpp:741
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:1038
bool checkTLSValids()
check if loaded TrafficLights corresponds to a TL controled junction in net
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:302
TrafficLightType getType() const
get the algorithm type (static etc..)
long onCmdOK(FXObject *, FXSelector, void *)
SUMOTime getOffset() const
get current offset in SUMOTIme
SUMOTime getOptSUMOTimeReporting(int attr, const char *objectid, bool &ok, SUMOTime defaultValue, bool report=true) const
Tries to read given attribute assuming it is a 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
void setHaveModifications(bool value)
set if current TLS was modified
void setCurrentJunction(GNEJunction *junction)
set current junction
void setStatusBarText(const std::string &text)
set staturBar text
Definition: GNEViewNet.cpp:311
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 clearLoadedTLS()
clear loaded phases
void setStateLength(int numLinks, LinkState fill=LINKSTATE_TL_RED)
std::string writeSUMOTime(SUMOTime steps)
convert SUMOTime into string
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
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:627
NBTrafficLightLogicCont & getTLLogicCont()
returns the tllcont of the underlying netbuilder
Definition: GNENet.cpp:1757
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:605
bool isAttributeCarrierSelected() const
check if attribute carrier is selected
OutputDevice & openTag(const std::string &xmlElement)
Opens an XML tag.
std::vector< NBLoadedSUMOTLDef * > myLoadedTLS
container used to save loaded TLSs
TrafficLightType