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  std::set<int> crossingIndices;
415  for (NBNode* n : myEditedDef->getNodes()) {
416  for (NBNode::Crossing* c : n->getCrossings()) {
417  crossingIndices.insert(c->tlLinkIndex);
418  crossingIndices.insert(c->tlLinkIndex2);
419  }
420  }
421 
422  // smart adapations for new state
423  bool haveGreen = false;
424  bool haveYellow = false;
425  for (char c : state) {
427  haveGreen = true;
428  } else if (c == LINKSTATE_TL_YELLOW_MAJOR || c == LINKSTATE_TL_YELLOW_MINOR) {
429  haveYellow = true;
430  }
431  }
432  const OptionsCont& oc = OptionsCont::getOptions();
433  if (haveGreen && haveYellow) {
434  // guess left-mover state
435  duration = TIME2STEPS(oc.getInt("tls.left-green.time"));
436  for (int i = 0; i < (int)state.size(); i++) {
437  if (state[i] == LINKSTATE_TL_YELLOW_MAJOR || state[i] == LINKSTATE_TL_YELLOW_MINOR) {
438  state[i] = LINKSTATE_TL_RED;
439  } else if (state[i] == LINKSTATE_TL_GREEN_MINOR) {
440  state[i] = LINKSTATE_TL_GREEN_MAJOR;
441  }
442  }
443  } else if (haveGreen) {
444  // guess yellow state
446  duration = TIME2STEPS(myEditedDef->computeBrakingTime(oc.getFloat("tls.yellow.min-decel")));
447  for (int i = 0; i < (int)state.size(); i++) {
448  if (state[i] == LINKSTATE_TL_GREEN_MAJOR || state[i] == LINKSTATE_TL_GREEN_MINOR) {
449  if (crossingIndices.count(i) == 0) {
450  state[i] = LINKSTATE_TL_YELLOW_MINOR;
451  } else {
452  state[i] = LINKSTATE_TL_RED;
453  }
454  }
455  }
456  } else if (haveYellow) {
457  duration = TIME2STEPS(oc.isDefault("tls.allred.time") ? 2 : oc.getInt("tls.allred.time"));
458  // guess all-red state
459  for (int i = 0; i < (int)state.size(); i++) {
460  if (state[i] == LINKSTATE_TL_YELLOW_MAJOR || state[i] == LINKSTATE_TL_YELLOW_MINOR) {
461  state[i] = LINKSTATE_TL_RED;
462  }
463  }
464  }
465 
466  myEditedDef->getLogic()->addStep(duration, state, newIndex);
467  myTLSPhases->getPhaseTable()->setCurrentItem(newIndex, 0);
468  myTLSPhases->initPhaseTable(newIndex);
469  myTLSPhases->getPhaseTable()->setFocus();
470  return 1;
471 }
472 
473 
474 long
475 GNETLSEditorFrame::onCmdPhaseDelete(FXObject*, FXSelector, void*) {
477  const int newRow = MAX2((int)0, (int)myTLSPhases->getPhaseTable()->getCurrentRow() - 1);
478  myEditedDef->getLogic()->deletePhase(myTLSPhases->getPhaseTable()->getCurrentRow());
479  myTLSPhases->initPhaseTable(newRow);
480  myTLSPhases->getPhaseTable()->setFocus();
481  return 1;
482 }
483 
484 
485 long
486 GNETLSEditorFrame::onCmdCleanup(FXObject*, FXSelector, void*) {
489  myTLSPhases->getPhaseTable()->setFocus();
490  return 1;
491 }
492 
493 
494 long
495 GNETLSEditorFrame::onCmdAddUnused(FXObject*, FXSelector, void*) {
497  myEditedDef->getLogic()->getNumLinks() + 1);
500  myTLSPhases->getPhaseTable()->setFocus();
501  return 1;
502 }
503 
504 
505 long
506 GNETLSEditorFrame::onCmdPhaseEdit(FXObject*, FXSelector, void* ptr) {
507  /* @note: there is a bug when copying/pasting rows: when this handler is
508  * called the value of the cell is not yet updated. This means you have to
509  * click inside the cell and hit enter to actually update the value */
510  FXTablePos* tp = (FXTablePos*)ptr;
511  FXString value = myTLSPhases->getPhaseTable()->getItemText(tp->row, tp->col);
512  const bool fixed = myEditedDef->getType() == TLTYPE_STATIC;
513  if (tp->col == 0) {
514  // duration edited
515  if (GNEAttributeCarrier::canParse<double>(value.text())) {
516  SUMOTime duration = getSUMOTime(value);
517  if (duration > 0) {
518  myEditedDef->getLogic()->setPhaseDuration(tp->row, duration);
521  return 1;
522  }
523  }
524  // input error, reset value
525  myTLSPhases->getPhaseTable()->setItemText(tp->row, 0, toString(STEPS2TIME(getPhases()[tp->row].duration)).c_str());
526  } else if (!fixed && tp->col == 1) {
527  // minDur edited
528  if (GNEAttributeCarrier::canParse<double>(value.text())) {
529  SUMOTime minDur = getSUMOTime(value);
530  if (minDur > 0) {
531  myEditedDef->getLogic()->setPhaseMinDuration(tp->row, minDur);
533  return 1;
534  }
535  } else if (StringUtils::prune(value.text()).empty()) {
538  return 1;
539  }
540  // input error, reset value
541  myTLSPhases->getPhaseTable()->setItemText(tp->row, 1, varDurString(getPhases()[tp->row].minDur).c_str());
542  } else if (!fixed && tp->col == 2) {
543  // minDur edited
544  if (GNEAttributeCarrier::canParse<double>(value.text())) {
545  SUMOTime maxDur = getSUMOTime(value);
546  if (maxDur > 0) {
547  myEditedDef->getLogic()->setPhaseMaxDuration(tp->row, maxDur);
549  return 1;
550  }
551  } else if (StringUtils::prune(value.text()).empty()) {
554  return 1;
555  }
556  // input error, reset value
557  myTLSPhases->getPhaseTable()->setItemText(tp->row, 2, varDurString(getPhases()[tp->row].maxDur).c_str());
558  } else {
559  // state edited
560  try {
561  // insert phase with new step and delete the old phase
562  myEditedDef->getLogic()->addStep(getPhases()[tp->row].duration, value.text(), tp->row);
563  myEditedDef->getLogic()->deletePhase(tp->row + 1);
565  onCmdPhaseSwitch(0, 0, 0);
566  } catch (ProcessError&) {
567  // input error, reset value
568  myTLSPhases->getPhaseTable()->setItemText(tp->row, 1, getPhases()[tp->row].state.c_str());
569  }
570  }
571  return 1;
572 }
573 
574 
575 void
579  }
580  // clean data structures
583  delete myEditedDef;
584  myEditedDef = nullptr;
585  buildIinternalLanes(0); // only clears
586  // clean up controls
588  myTLSPhases->initPhaseTable(); // only clears when there are no definitions
591 }
592 
593 
594 void
597  // clean up previous objects
598  for (auto it : myInternalLanes) {
599  for (auto it_intLanes : it.second) {
600  rtree.removeAdditionalGLObject(it_intLanes);
601  delete it_intLanes;
602  }
603  }
604  myInternalLanes.clear();
605  // create new internal lanes
606  if (tlDef != 0) {
607  const int NUM_POINTS = 10;
610  std::string innerID = ":" + nbn->getID(); // see NWWriter_SUMO::writeInternalEdges
611  const NBConnectionVector& links = tlDef->getControlledLinks();
612  for (auto it : links) {
613  int tlIndex = it.getTLIndex();
614  PositionVector shape = it.getFrom()->getToNode()->computeInternalLaneShape(it.getFrom(), NBEdge::Connection(it.getFromLane(),
615  it.getTo(), it.getToLane()), NUM_POINTS);
616  GNEInternalLane* ilane = new GNEInternalLane(this, innerID + '_' + toString(tlIndex), shape, tlIndex);
617  rtree.addAdditionalGLObject(ilane);
618  myInternalLanes[tlIndex].push_back(ilane);
619  }
620  for (NBNode* nbn : tlDef->getNodes()) {
621  for (auto c : nbn->getCrossings()) {
622  if (c->tlLinkIndex2 > 0 && c->tlLinkIndex2 != c->tlLinkIndex) {
623  // draw both directions
624  PositionVector forward = c->shape;
625  forward.move2side(c->width / 4);
626  GNEInternalLane* ilane = new GNEInternalLane(this, c->id, forward, c->tlLinkIndex);
627  rtree.addAdditionalGLObject(ilane);
628  myInternalLanes[c->tlLinkIndex].push_back(ilane);
629 
630  PositionVector backward = c->shape.reverse();
631  backward.move2side(c->width / 4);
632  GNEInternalLane* ilane2 = new GNEInternalLane(this, c->id + "_r", backward, c->tlLinkIndex2);
633  rtree.addAdditionalGLObject(ilane2);
634  myInternalLanes[c->tlLinkIndex2].push_back(ilane2);
635  } else {
636  // draw only one lane for both directions
637  GNEInternalLane* ilane = new GNEInternalLane(this, c->id, c->shape, c->tlLinkIndex);
638  rtree.addAdditionalGLObject(ilane);
639  myInternalLanes[c->tlLinkIndex].push_back(ilane);
640  }
641  }
642  }
643  }
644 }
645 
646 
647 std::string
650 }
651 
652 
653 const std::vector<NBTrafficLightLogic::PhaseDefinition>&
655  return myEditedDef->getLogic()->getPhases();
656 }
657 
658 
659 void
662  if (myViewNet->changeAllPhases()) {
663  const std::vector<NBTrafficLightLogic::PhaseDefinition>& phases = getPhases();
664  for (int row = 0; row < (int)phases.size(); row++) {
665  myEditedDef->getLogic()->setPhaseState(row, lane->getTLIndex(), lane->getLinkState());
666  }
667  } else {
668  myEditedDef->getLogic()->setPhaseState(myTLSPhases->getPhaseTable()->getCurrentRow(), lane->getTLIndex(), lane->getLinkState());
669  }
670  myTLSPhases->initPhaseTable(myTLSPhases->getPhaseTable()->getCurrentRow());
671  myTLSPhases->getPhaseTable()->setFocus();
672 }
673 
674 
675 void
676 GNETLSEditorFrame::handleMultiChange(GNELane* lane, FXObject* obj, FXSelector sel, void* eventData) {
677  if (myEditedDef != 0) {
680  std::set<std::string> fromIDs;
681  fromIDs.insert(lane->getMicrosimID());
682  GNEEdge& edge = lane->getParentEdge();
683  // if neither the lane nor its edge are selected, apply changes to the whole edge
684  if (!edge.isAttributeCarrierSelected() && !lane->isAttributeCarrierSelected()) {
685  for (auto it_lane : edge.getLanes()) {
686  fromIDs.insert(it_lane->getMicrosimID());
687  }
688  } else {
689  // if the edge is selected, apply changes to all lanes of all selected edges
690  if (edge.isAttributeCarrierSelected()) {
691  std::vector<GNEEdge*> edges = myViewNet->getNet()->retrieveEdges(true);
692  for (auto it : edges) {
693  for (auto it_lane : it->getLanes()) {
694  fromIDs.insert(it_lane->getMicrosimID());
695  }
696  }
697  }
698  // if the lane is selected, apply changes to all selected lanes
699  if (lane->isAttributeCarrierSelected()) {
700  std::vector<GNELane*> lanes = myViewNet->getNet()->retrieveLanes(true);
701  for (auto it_lane : lanes) {
702  fromIDs.insert(it_lane->getMicrosimID());
703  }
704  }
705 
706  }
707  // set new state for all connections from the chosen lane IDs
708  for (auto it : links) {
709  if (fromIDs.count(it.getFrom()->getLaneID(it.getFromLane())) > 0) {
710  std::vector<GNEInternalLane*> lanes = myInternalLanes[it.getTLIndex()];
711  for (auto it_lane : lanes) {
712  it_lane->onDefault(obj, sel, eventData);
713  }
714  }
715  }
716  }
717 }
718 
719 
720 bool
722  if (myEditedDef != 0) {
724  for (auto it : links) {
725  if (it.getFrom()->getID() == edge.getMicrosimID()) {
726  return true;
727  }
728  }
729  }
730  return false;
731 }
732 
733 
734 SUMOTime
735 GNETLSEditorFrame::getSUMOTime(const FXString& string) {
736  assert(GNEAttributeCarrier::canParse<double>(string.text()));
737  return TIME2STEPS(GNEAttributeCarrier::parse<double>(string.text()));
738 }
739 
740 // ---------------------------------------------------------------------------
741 // GNETLSEditorFrame::TLSAttributes - methods
742 // ---------------------------------------------------------------------------
743 
745  FXGroupBox(TLSEditorParent->myContentFrame, "Traffic light Attributes", GUIDesignGroupBoxFrame),
746  myTLSEditorParent(TLSEditorParent) {
747 
748  // create frame, label and textfield for name (By default disabled)
749  FXHorizontalFrame* nameFrame = new FXHorizontalFrame(this, GUIDesignAuxiliarHorizontalFrame);
750  myNameLabel = new FXLabel(nameFrame, "ID", 0, GUIDesignLabelAttribute);
752  myNameTextField->disable();
753 
754  // create frame, label and comboBox for Program (By default hidden)
755  FXHorizontalFrame* programFrame = new FXHorizontalFrame(this, GUIDesignAuxiliarHorizontalFrame);
756  myProgramLabel = new FXLabel(programFrame, "Program", 0, GUIDesignLabelAttribute);
758  myProgramComboBox->disable();
759 
760  // create frame, label and TextField for Offset (By default disabled)
761  FXHorizontalFrame* offsetFrame = new FXHorizontalFrame(this, GUIDesignAuxiliarHorizontalFrame);
762  myOffsetLabel = new FXLabel(offsetFrame, "Offset", 0, GUIDesignLabelAttribute);
764  myOffsetTextField->disable();
765 }
766 
767 
769 
770 
771 void
773  assert(junction);
774  myTLSDefinitions.clear();
775  // enable name TextField
776  myNameTextField->enable();
777  // enable Offset
778  myOffsetTextField->enable();
779  // obtain TLSs
780  for (auto it : junction->getNBNode()->getControllingTLS()) {
781  myTLSDefinitions.push_back(it);
782  myNameTextField->setText(it->getID().c_str());
783  myNameTextField->enable();
784  myProgramComboBox->appendItem(it->getProgramID().c_str());
785  // enable TLS
787  }
788  if (myTLSDefinitions.size() > 0) {
789  myProgramComboBox->enable();
790  myProgramComboBox->setCurrentItem(0);
791  myProgramComboBox->setNumVisible(myProgramComboBox->getNumItems());
793  // enable TLS
795  }
796 }
797 
798 
799 void
801  // clear definitions
802  myTLSDefinitions.clear();
803  // clear and disable name TextField
804  myNameTextField->setText("");
805  myNameTextField->disable();
806  // clear and disable myProgramComboBox
807  myProgramComboBox->clearItems();
808  myProgramComboBox->disable();
809  // clear and disable Offset TextField
810  myOffsetTextField->setText("");
811  myOffsetTextField->disable();
812 }
813 
814 
817  return myTLSDefinitions.at(myProgramComboBox->getCurrentItem());
818 }
819 
820 
821 int
823  return (int)myTLSDefinitions.size();
824 }
825 
826 
827 int
829  return myProgramComboBox->getNumItems();
830 }
831 
832 
833 SUMOTime
835  return getSUMOTime(myOffsetTextField->getText());
836 }
837 
838 
839 void
841  myOffsetTextField->setText(toString(STEPS2TIME(offset)).c_str());
842 }
843 
844 // ---------------------------------------------------------------------------
845 // GNETLSEditorFrame::TLSJunction - methods
846 // ---------------------------------------------------------------------------
847 
849  FXGroupBox(TLSEditorParent->myContentFrame, "Junction", GUIDesignGroupBoxFrame),
850  myTLSEditorParent(TLSEditorParent),
851  myCurrentJunction(nullptr) {
852  // Create frame for junction ID
853  FXHorizontalFrame* junctionIDFrame = new FXHorizontalFrame(this, GUIDesignAuxiliarHorizontalFrame);
854  myLabelJunctionID = new FXLabel(junctionIDFrame, "Junction ID", 0, GUIDesignLabelAttribute);
856  myTextFieldJunctionID->setEditable(false);
857  // create frame for junction status
858  FXHorizontalFrame* junctionIDStatus = new FXHorizontalFrame(this, GUIDesignAuxiliarHorizontalFrame);
859  myLabelJunctionStatus = new FXLabel(junctionIDStatus, "Status", 0, GUIDesignLabelAttribute);
861  myTextFieldJunctionStatus->setEditable(false);
862  // update junction description after creation
864  // show TLS Junction
865  show();
866 }
867 
868 
870 
871 
874  return myCurrentJunction;
875 }
876 
877 
878 void
880  myCurrentJunction = junction;
881 }
882 
883 
884 void
886  if (myCurrentJunction == 0) {
887  myTextFieldJunctionID->setText("");
888  myTextFieldJunctionStatus->setText("");
889  } else {
891  myTextFieldJunctionID->setText(nbn->getID().c_str());
892  if (!nbn->isTLControlled()) {
893  myTextFieldJunctionStatus->setText("uncontrolled");
894  } else {
896  }
897  }
898 }
899 
900 // ---------------------------------------------------------------------------
901 // GNETLSEditorFrame::TLSDefinition - methods
902 // ---------------------------------------------------------------------------
903 
905  FXGroupBox(TLSEditorParent->myContentFrame, "Traffic lights definition", GUIDesignGroupBoxFrame),
906  myTLSEditorParent(TLSEditorParent) {
907  // create create tlDef button
908  myNewTLProgram = new FXButton(this, "Create TLS\t\tCreate a new traffic light program",
910  // create delete tlDef button
911  myDeleteTLProgram = new FXButton(this, "Delete TLS\t\tDelete a traffic light program. If all programs are deleted the junction turns into a priority junction.",
913  // show TLS TLSDefinition
914  show();
915 }
916 
917 
919 
920 // ---------------------------------------------------------------------------
921 // GNETLSEditorFrame::TLSPhases - methods
922 // ---------------------------------------------------------------------------
923 
925  FXGroupBox(TLSEditorParent->myContentFrame, "Phases", GUIDesignGroupBoxFrame),
926  myTLSEditorParent(TLSEditorParent),
927  myTableFont(new FXFont(getApp(), "Courier New", 9)) {
928 
929  // create and configure phase table
930  myTableScroll = new FXScrollWindow(this, LAYOUT_FILL_X | LAYOUT_FIX_HEIGHT);
932  myPhaseTable->setColumnHeaderMode(LAYOUT_FIX_HEIGHT);
933  myPhaseTable->setColumnHeaderHeight(0);
934  myPhaseTable->setRowHeaderMode(LAYOUT_FIX_WIDTH);
935  myPhaseTable->setRowHeaderWidth(0);
936  myPhaseTable->hide();
937  myPhaseTable->setFont(myTableFont);
938  myPhaseTable->setHelpText("phase duration in seconds | phase state");
939 
940  // create total duration info label
941  myCycleDuration = new FXLabel(this, "", 0, GUIDesignLabelLeft);
942 
943  // create new phase button
944  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);
945 
946  // create delete phase button
947  myDeleteSelectedPhaseButton = new FXButton(this, "Delete Phase\t\tDelete selected phase", 0, myTLSEditorParent, MID_GNE_TLSFRAME_PHASE_DELETE, GUIDesignButton);
948 
949  // create cleanup states button
950  new FXButton(this, "Cleanup States\t\tClean unused states from all phase.", 0, myTLSEditorParent, MID_GNE_TLSFRAME_CLEANUP, GUIDesignButton);
951 
952  // add unused states button
953  new FXButton(this, "Add Unused States\t\tExtend the state vector for all phases by one entry.", 0, myTLSEditorParent, MID_GNE_TLSFRAME_ADDUNUSED, GUIDesignButton);
954 
955  // show TLSFile
956  show();
957 }
958 
959 
961  delete myTableFont;
962 }
963 
964 
965 FXTable*
967  return myPhaseTable;
968 }
969 
970 
971 void
973  myPhaseTable->setVisibleRows(1);
974  myPhaseTable->setVisibleColumns(2);
975  myPhaseTable->hide();
977  const bool fixed = myTLSEditorParent->myEditedDef->getType() == TLTYPE_STATIC;
978  const std::vector<NBTrafficLightLogic::PhaseDefinition>& phases = myTLSEditorParent->getPhases();
979  myPhaseTable->setTableSize((int)phases.size(), fixed ? 2 : 4);
980  myPhaseTable->setVisibleRows((int)phases.size());
981  myPhaseTable->setVisibleColumns(fixed ? 2 : 4);
982  for (int row = 0; row < (int)phases.size(); row++) {
983  myPhaseTable->setItemText(row, 0, toString(STEPS2TIME(phases[row].duration)).c_str());
984  if (!fixed) {
985  myPhaseTable->setItemText(row, 1, varDurString(phases[row].minDur).c_str());
986  myPhaseTable->setItemText(row, 2, varDurString(phases[row].maxDur).c_str());
987  }
988  myPhaseTable->setItemText(row, fixed ? 1 : 3, phases[row].state.c_str());
989  myPhaseTable->getItem(row, 1)->setJustify(FXTableItem::LEFT);
990  }
991  myPhaseTable->fitColumnsToContents(0, fixed ? 2 : 4);
992  myPhaseTable->setHeight((int)phases.size() * 21); // experimental
993  myPhaseTable->setCurrentItem(index, 0);
994  myPhaseTable->selectRow(index, true);
995  myPhaseTable->show();
996  myPhaseTable->setFocus();
997  myTableScroll->setHeight(myPhaseTable->getHeight() + 10);
998  }
999  update();
1000 }
1001 
1002 
1003 void
1005  myCycleDuration->show();
1006 }
1007 
1008 
1009 void
1011  myCycleDuration->hide();
1012 }
1013 
1014 void
1016  SUMOTime cycleDuration = 0;
1017  for (auto it : myTLSEditorParent->getPhases()) {
1018  cycleDuration += it.duration;
1019  }
1020  std::string text = "Cycle time: " + toString(STEPS2TIME(cycleDuration));
1021  myCycleDuration->setText(text.c_str());
1022 }
1023 
1024 // ---------------------------------------------------------------------------
1025 // GNETLSEditorFrame::TLSModifications - methods
1026 // ---------------------------------------------------------------------------
1027 
1029  FXGroupBox(TLSEditorParent->myContentFrame, "Modifications", GUIDesignGroupBoxFrame),
1030  myTLSEditorParent(TLSEditorParent),
1031  myHaveModifications(false) {
1032  // create save modifications button
1033  mySaveModificationsButtons = new FXButton(this, "Save\t\tSave program modifications (Enter)",
1035  // create discard modifications buttons
1036  myDiscardModificationsButtons = new FXButton(this, "Cancel\t\tDiscard program modifications (Esc)",
1038  // show TLSModifications
1039  show();
1040 }
1041 
1042 
1044 
1045 
1046 bool
1048  return myHaveModifications;
1049 }
1050 
1051 
1052 void
1054  myHaveModifications = value;
1055 }
1056 
1057 // ---------------------------------------------------------------------------
1058 // GNETLSEditorFrame::TLSFile - methods
1059 // ---------------------------------------------------------------------------
1060 
1062  FXGroupBox(TLSEditorParent->myContentFrame, "TLS Program", GUIDesignGroupBoxFrame),
1063  SUMOSAXHandler("TLS-Program"),
1064  myTLSEditorParent(TLSEditorParent) {
1065  // create create tlDef button
1066  myLoadTLSProgramButton = new FXButton(this, "Load TLS Program", 0, this, MID_GNE_TLSFRAME_LOAD_PROGRAM, GUIDesignButton);
1067  // create create tlDef button
1068  mySaveTLSProgramButton = new FXButton(this, "Save TLS Program", 0, this, MID_GNE_TLSFRAME_SAVE_PROGRAM, GUIDesignButton);
1069  // by default TLSFile is disabled
1070  disableTLSFile();
1071  // show TLSFile
1072  show();
1073 }
1074 
1075 
1077 
1078 
1079 void
1081  bool ok = true;
1082  switch (element) {
1083  case SUMO_TAG_TLLOGIC: {
1084  std::string id = attrs.get<std::string>(SUMO_ATTR_ID, 0, ok);
1085  if (myTLSEditorParent->getViewNet()->getNet()->retrieveJunction(id, false) == nullptr) {
1086  WRITE_ERROR("ERROR, Junction doesn't exist");
1087  } else {
1088  std::string programID = attrs.getOpt<std::string>(SUMO_ATTR_PROGRAMID, id.c_str(), ok, "<unknown>");
1090  std::string typeS = attrs.get<std::string>(SUMO_ATTR_TYPE, 0, ok);
1091  if (SUMOXMLDefinitions::TrafficLightTypes.hasString(typeS)) {
1093  } else {
1094  WRITE_ERROR("Traffic light '" + id + "' has unknown type '" + typeS + "'.");
1095  }
1096  const SUMOTime offset = attrs.getOptSUMOTimeReporting(SUMO_ATTR_OFFSET, id.c_str(), ok, 0);
1097  // avoid to insert duplicated TLSs
1098  myLoadedTLS.push_back(new NBLoadedSUMOTLDef(id, programID, offset, type));
1099  }
1100  break;
1101  }
1102  case SUMO_TAG_PHASE: {
1103  if (myLoadedTLS.size() > 0) {
1104  double duration = attrs.get<double>(SUMO_ATTR_DURATION, 0, ok);
1105  std::string state = attrs.get<std::string>(SUMO_ATTR_STATE, 0, ok);
1106  myLoadedTLS.back()->getLogic()->addStep(TIME2STEPS(duration), state);
1107  break;
1108  }
1109  }
1110  default:
1111  break;
1112  }
1113 }
1114 
1115 
1116 void
1118  // enable buttons
1119  myLoadTLSProgramButton->enable();
1120  mySaveTLSProgramButton->enable();
1121 }
1122 
1123 
1124 void
1126  // disable buttons
1127  myLoadTLSProgramButton->disable();
1128  mySaveTLSProgramButton->disable();
1129 }
1130 
1131 
1132 void
1134  for (auto i : myLoadedTLS) {
1135  delete i;
1136  }
1137  myLoadedTLS.clear();
1138 }
1139 
1140 
1141 const std::vector<NBLoadedSUMOTLDef*>&
1143  return myLoadedTLS;
1144 }
1145 
1146 
1147 bool
1149  std::vector<NBLoadedSUMOTLDef*> definitionsJunctionsWithoutTL;
1150  for (auto i : myLoadedTLS) {
1151  if (myTLSEditorParent->getViewNet()->getNet()->retrieveJunction(i->getID())->getNBNode()->isTLControlled() == false) {
1152  definitionsJunctionsWithoutTL.push_back(i);
1153  }
1154  }
1155  // check if there is definitions loaded with an uncontrolled junction asociated
1156  if (definitionsJunctionsWithoutTL.size() > 0) {
1157  // write warning if netedit is running in testing mode
1158  WRITE_DEBUG("Opening question FXMessageBox 'create TLS in uncontrolled junctions'");
1159  // open question box
1160  FXuint answer = FXMessageBox::question(myTLSEditorParent, MBOX_YES_NO_CANCEL,
1161  "Create TLS", "%s",
1162  ("There is " + toString(definitionsJunctionsWithoutTL.size()) + " TLS without controlled junction.\nDo you want to create TLSs in uncontrolled Junctions?").c_str());
1163  if (answer == MBOX_CLICKED_YES) { //1:yes, 2:no, 4:esc/cancel
1164  // write warning if netedit is running in testing mode
1165  WRITE_DEBUG("Closed FXMessageBox 'create TLS in uncontrolled junctions' with 'Yes'");
1166  // convert Junctions in TLS
1167  for (auto i : definitionsJunctionsWithoutTL) {
1168  GNEJunction* junction = myTLSEditorParent->getViewNet()->getNet()->retrieveJunction(i->getID());
1169  junction->setAttribute(SUMO_ATTR_TYPE, "traffic_light", myTLSEditorParent->getViewNet()->getUndoList());
1170  }
1171  } else if (answer == MBOX_CLICKED_NO) {
1172  // write warning if netedit is running in testing mode
1173  WRITE_DEBUG("Closed FXMessageBox 'create TLS in uncontrolled junctions' with 'No'");
1174  // delete loaded TLSs without associated controlled Junction
1175  for (auto i : definitionsJunctionsWithoutTL) {
1176  myLoadedTLS.erase(std::find(myLoadedTLS.begin(), myLoadedTLS.end(), i));
1177  delete i;
1178  }
1179  } else {
1180  // write warning if netedit is running in testing mode
1181  WRITE_DEBUG("Closed FXMessageBox 'create TLS in uncontrolled junctions' with 'Cancel'");
1182  // return false to abort loading of TLSs
1183  return false;
1184  }
1185  }
1186 
1187  // return true to continue loading TLSs
1188  return true;
1189 }
1190 
1191 
1192 long
1194  FXFileDialog opendialog(this, "Load TLS Program");
1195  opendialog.setIcon(GUIIconSubSys::getIcon(ICON_MODETLS));
1196  opendialog.setSelectMode(SELECTFILE_EXISTING);
1197  opendialog.setPatternList("*.xml");
1198  if (gCurrentFolder.length() != 0) {
1199  opendialog.setDirectory(gCurrentFolder);
1200  }
1201  if (opendialog.execute()) {
1202  // first clear loaded phases
1203  clearLoadedTLS();
1204  // run parser
1205  XMLSubSys::runParser(*this, opendialog.getFilename().text(), true);
1206 
1208 
1209  // check that only a phase was loaded
1210  /* for(auto i : myLoadedTLS) {
1211  if(i->getID() == myTLSEditorParent->myTLSJunction->getCurrentJunction()->getID()) {
1212  myTLSEditorParent->myEditedDef->getProgramID();
1213 
1214  for (auto j : i.second) {
1215  myTLSEditorParent->myEditedDef->getLogic()->addStep(j.duration, j.state, j.minDur, j.maxDur);
1216  }
1217 
1218  }
1219  }
1220  */
1223  }
1224  return 0;
1225 }
1226 
1227 
1228 long
1230  FXString file = MFXUtils::getFilename2Write(this,
1231  "Save TLS Program as", ".xml",
1233  gCurrentFolder);
1234  if (file == "") {
1235  return 1;
1236  }
1237  OutputDevice& device = OutputDevice::getDevice(file.text());
1238 
1239  // save program
1240  device.openTag(SUMO_TAG_TLLOGIC);
1245  // write the phases
1246  const bool varPhaseLength = myTLSEditorParent->myEditedDef->getLogic()->getType() != TLTYPE_STATIC;
1247  const std::vector<NBTrafficLightLogic::PhaseDefinition>& phases = myTLSEditorParent->myEditedDef->getLogic()->getPhases();
1248  for (auto j : phases) {
1249  device.openTag(SUMO_TAG_PHASE);
1250  device.writeAttr(SUMO_ATTR_DURATION, writeSUMOTime(j.duration));
1251  device.writeAttr(SUMO_ATTR_STATE, j.state);
1252  if (varPhaseLength) {
1254  device.writeAttr(SUMO_ATTR_MINDURATION, writeSUMOTime(j.minDur));
1255  }
1257  device.writeAttr(SUMO_ATTR_MAXDURATION, writeSUMOTime(j.maxDur));
1258  }
1259  }
1260  device.closeTag();
1261  }
1262  device.close();
1263  return 1;
1264 }
1265 
1266 
1267 std::string
1269  double time = STEPS2TIME(steps);
1270  if (time == std::floor(time)) {
1271  return toString(int(time));
1272  } else {
1273  return toString(time);
1274  }
1275 }
1276 /****************************************************************************/
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:1059
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: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: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:369
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:1298
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:902
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:1366
~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:1046
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
A definition of a pedestrian crossing.
Definition: NBNode.h:125
void setStatusBarText(const std::string &text)
set staturBar text
Definition: GNEViewNet.cpp:331
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:1765
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