SUMO - Simulation of Urban MObility
GNETLSEditorFrame.cpp
Go to the documentation of this file.
1 /****************************************************************************/
7 // The Widget for modifying traffic lights
8 /****************************************************************************/
9 // SUMO, Simulation of Urban MObility; see http://sumo.dlr.de/
10 // Copyright (C) 2001-2017 DLR (http://www.dlr.de/) and contributors
11 /****************************************************************************/
12 //
13 // This file is part of SUMO.
14 // SUMO is free software: you can redistribute it and/or modify
15 // it under the terms of the GNU General Public License as published by
16 // the Free Software Foundation, either version 3 of the License, or
17 // (at your option) any later version.
18 //
19 /****************************************************************************/
20 
21 
22 // ===========================================================================
23 // included modules
24 // ===========================================================================
25 #ifdef _MSC_VER
26 #include <windows_config.h>
27 #else
28 #include <config.h>
29 #endif
30 
31 #include <iostream>
41 
42 #include "GNETLSEditorFrame.h"
43 #include "GNEViewNet.h"
44 #include "GNEViewParent.h"
45 #include "GNENet.h"
46 #include "GNEJunction.h"
47 #include "GNEEdge.h"
48 #include "GNELane.h"
49 #include "GNEUndoList.h"
50 #include "GNEInternalLane.h"
51 #include "GNEChange_TLS.h"
52 
53 // ===========================================================================
54 // FOX callback mapping
55 // ===========================================================================
56 FXDEFMAP(GNETLSEditorFrame) GNETLSEditorFrameMap[] = {
57  FXMAPFUNC(SEL_COMMAND, MID_CANCEL, GNETLSEditorFrame::onCmdCancel),
58  FXMAPFUNC(SEL_COMMAND, MID_OK, GNETLSEditorFrame::onCmdOK),
70  FXMAPFUNC(SEL_DESELECTED, MID_GNE_PHASE_TABLE, GNETLSEditorFrame::onCmdPhaseSwitch),
79  FXMAPFUNC(SEL_UPDATE, MID_CANCEL, GNETLSEditorFrame::onUpdModified),
80  FXMAPFUNC(SEL_UPDATE, MID_OK, GNETLSEditorFrame::onUpdModified),
81 };
82 
83 
84 // Object implementation
85 FXIMPLEMENT(GNETLSEditorFrame, FXVerticalFrame, GNETLSEditorFrameMap, ARRAYNUMBER(GNETLSEditorFrameMap))
86 
87 // ===========================================================================
88 // method definitions
89 // ===========================================================================
90 GNETLSEditorFrame::GNETLSEditorFrame(FXHorizontalFrame* horizontalFrameParent, GNEViewNet* viewNet):
91  GNEFrame(horizontalFrameParent, viewNet, "Edit Traffic Light"),
92  myTableFont(new FXFont(getApp(), "Courier New", 9)),
93  myCurrentJunction(0),
94  myHaveModifications(false),
95  myEditedDef(0) {
96  // create groupbox for description
97  myGroupBoxJunction = new FXGroupBox(myContentFrame, "Junction", GUIDesignGroupBoxFrame);
98 
99  // create description label
100  myDescription = new FXLabel(myGroupBoxJunction, "No Junction Selected\n", 0, GUIDesignLabelLeft);
101 
102  // create groupbox for tl df
103  myGroupBoxTLSDef = new FXGroupBox(myContentFrame, "Traffic lights definition", GUIDesignGroupBoxFrame);
104 
105  // create create tlDef button
106  myNewTLProgram = new FXButton(myGroupBoxTLSDef, "Create TLS\t\tCreate a new traffic light program", 0, this, MID_GNE_DEF_CREATE, GUIDesignButton);
107 
108  // create delete tlDef button
109  myDeleteTLProgram = new FXButton(myGroupBoxTLSDef, "Delete TLS\t\tDelete a traffic light program. If all programs are deleted the junction turns into a priority junction.", 0, this, MID_GNE_DEF_DELETE, GUIDesignButton);
110 
111  // create groupbox for phases
112  myGroupBoxAttributes = new FXGroupBox(myContentFrame, "Attributes", GUIDesignGroupBoxFrame);
113 
114  // Create matrix
115  myAttributeMatrix = new FXMatrix(myGroupBoxAttributes, 2, GUIDesignMatrixAttributes);
116 
117  // create label for name
118  myNameLabel = new FXLabel(myAttributeMatrix, "Name", 0, GUIDesignLabelAttribute);
119 
120  // create text field for name
121  myNameTextField = new FXTextField(myAttributeMatrix, GUIDesignTextFieldNCol, this, MID_GNE_DEF_SWITCH, GUIDesignTextField);
122 
123  // create label for program
124  myProgramLabel = new FXLabel(myAttributeMatrix, "Program", 0, GUIDesignLabelAttribute);
125 
126  // create combo box for program
127  myProgramComboBox = new FXComboBox(myAttributeMatrix, GUIDesignComboBoxNCol, this, MID_GNE_DEF_SWITCH, GUIDesignComboBoxAttribute);
128 
129  // create offset control
130  myOffsetLabel = new FXLabel(myAttributeMatrix, "Offset", 0, GUIDesignLabelAttribute);
131  myOffset = new FXTextField(myAttributeMatrix, GUIDesignTextFieldNCol, this, MID_GNE_DEF_OFFSET, GUIDesignTextFieldReal);
132 
133  // create groupbox for phases
134  myGroupBoxPhases = new FXGroupBox(myContentFrame, "Phases", GUIDesignGroupBoxFrame);
135 
136  // create and configure phase table
137  myPhaseTable = new FXTable(myGroupBoxPhases, this, MID_GNE_PHASE_TABLE, GUIDesignTableLimitedHeight);
138  myPhaseTable->setColumnHeaderMode(LAYOUT_FIX_HEIGHT);
139  myPhaseTable->setColumnHeaderHeight(0);
140  myPhaseTable->setRowHeaderMode(LAYOUT_FIX_WIDTH);
141  myPhaseTable->setRowHeaderWidth(0);
142  myPhaseTable->hide();
143  myPhaseTable->setFont(myTableFont);
144  myPhaseTable->setHelpText("phase duration in seconds | phase state");
145 
146  // create total duration info label
147  myCycleDuration = new FXLabel(myGroupBoxPhases, "", 0, GUIDesignLabelLeft);
148 
149  // create new phase button
150  myInsertDuplicateButton = new FXButton(myGroupBoxPhases, "Copy Phase\t\tInsert duplicate phase after selected phase", 0, this, MID_GNE_PHASE_CREATE, GUIDesignButton);
151 
152  // create delete phase button
153  myDeleteSelectedPhaseButton = new FXButton(myGroupBoxPhases, "Delete Phase\t\tDelete selected phase", 0, this, MID_GNE_PHASE_DELETE, GUIDesignButton);
154 
155  // create groupbox for modifications
156  myGroupBoxModifications = new FXGroupBox(myContentFrame, "Modifications", GUIDesignGroupBoxFrame);
157 
158  // create discard modifications buttons
159  myDiscardModificationsButtons = new FXButton(myGroupBoxModifications, "Cancel\t\tDiscard program modifications (Esc)", 0, this, MID_CANCEL, GUIDesignButton);
160 
161  // create save modifications button
162  mySaveModificationsButtons = new FXButton(myGroupBoxModifications, "Save\t\tSave program modifications (Enter)", 0, this, MID_OK, GUIDesignButton);
163 
164 
165  // "Add 'off' program"
166  /*
167  new FXButton(myContentFrame, "Add \"Off\"-Program\t\tAdds a program for switching off this traffic light",
168  0, this, MID_GNE_DEF_ADDOFF, GUIDesignButton);
169  */
170 }
171 
172 
174  delete myTableFont;
175  cleanup();
176 }
177 
178 
179 void
181  if (myCurrentJunction == 0 || (!myHaveModifications && (junction != myCurrentJunction))) {
182  onCmdCancel(0, 0, 0);
183  myViewNet->getUndoList()->p_begin("modifying traffic light definition");
184  myCurrentJunction = junction;
186  initDefinitions();
187  } else {
188  myViewNet->setStatusBarText("Unsaved modifications. Abort or Save");
189  }
190 }
191 
192 
193 long
194 GNETLSEditorFrame::onCmdCancel(FXObject*, FXSelector, void*) {
195  if (myCurrentJunction != 0) {
197  cleanup();
198  myViewNet->update();
199  }
200  return 1;
201 }
202 
203 
204 long
205 GNETLSEditorFrame::onCmdOK(FXObject*, FXSelector, void*) {
206  if (myCurrentJunction != 0) {
207  if (myHaveModifications) {
208  NBTrafficLightDefinition* old = myDefinitions[myProgramComboBox->getCurrentItem()];
209  std::vector<NBNode*> nodes = old->getNodes();
210  for (std::vector<NBNode*>::iterator it = nodes.begin(); it != nodes.end(); it++) {
211  GNEJunction* junction = myViewNet->getNet()->retrieveJunction((*it)->getID());
212  myViewNet->getUndoList()->add(new GNEChange_TLS(junction, old, false), true);
213  myViewNet->getUndoList()->add(new GNEChange_TLS(junction, myEditedDef, true), true);
214  }
215  myEditedDef = 0;
217  cleanup();
218  myViewNet->update();
219  } else {
220  onCmdCancel(0, 0, 0);
221  }
222  }
223  return 1;
224 }
225 
226 
227 long
228 GNETLSEditorFrame::onCmdDefCreate(FXObject*, FXSelector, void*) {
229  GNEJunction* junction = myCurrentJunction;
230  onCmdCancel(0, 0, 0); // abort because we onCmdOk assumes we wish to save an edited definition
233  } else {
234  myViewNet->getUndoList()->add(new GNEChange_TLS(junction, 0, true, true), true);
235  }
236  editJunction(junction);
237  return 1;
238 }
239 
240 
241 long
242 GNETLSEditorFrame::onCmdDefDelete(FXObject*, FXSelector, void*) {
243  GNEJunction* junction = myCurrentJunction;
244  const bool changeType = myDefinitions.size() == 1;
245  onCmdCancel(0, 0, 0); // abort because onCmdOk assumes we wish to save an edited definition
246  if (changeType) {
248  } else {
249  NBTrafficLightDefinition* tlDef = myDefinitions[myProgramComboBox->getCurrentItem()];
250  myViewNet->getUndoList()->add(new GNEChange_TLS(junction, tlDef, false), true);
251  }
252  return 1;
253 }
254 
255 
256 long
257 GNETLSEditorFrame::onCmdDefSwitch(FXObject*, FXSelector, void*) {
258  assert(myCurrentJunction != 0);
259  assert((int)myDefinitions.size() == myProgramComboBox->getNumItems());
260  NBTrafficLightDefinition* tlDef = myDefinitions[myProgramComboBox->getCurrentItem()];
261  // logic may not have been recomputed yet. recompute to be sure
264  NBTrafficLightLogic* tllogic = tllCont.getLogic(tlDef->getID(), tlDef->getProgramID());
265  if (tllogic != 0) {
266  // now we can be sure that the tlDef is up to date (i.e. re-guessed)
267  buildIinternalLanes(tlDef);
268  // create working copy from original def
269  delete myEditedDef;
270  myEditedDef = new NBLoadedSUMOTLDef(tlDef, tllogic);
271  myOffset->setText(toString(STEPS2TIME(myEditedDef->getLogic()->getOffset())).c_str());
272  initPhaseTable();
274  } else {
275  // tlDef has no valid logic (probably because id does not control any links
276  onCmdCancel(0, 0, 0);
277  myViewNet->setStatusBarText("Traffic light does not control any links");
278  }
279  return 1;
280 }
281 
282 
283 long
284 GNETLSEditorFrame::onUpdDefSwitch(FXObject* o, FXSelector, void*) {
285  const bool enable = myDefinitions.size() > 0 && !myHaveModifications;
286  o->handle(this, FXSEL(SEL_COMMAND, enable ? FXWindow::ID_ENABLE : FXWindow::ID_DISABLE), 0);
287  return 1;
288 }
289 
290 
291 long
292 GNETLSEditorFrame::onUpdNeedsDef(FXObject* o, FXSelector, void*) {
293  const bool enable = myDefinitions.size() > 0;
294  o->handle(this, FXSEL(SEL_COMMAND, enable ? FXWindow::ID_ENABLE : FXWindow::ID_DISABLE), 0);
295  return 1;
296 }
297 
298 
299 long
300 GNETLSEditorFrame::onUpdNeedsDefAndPhase(FXObject* o, FXSelector, void*) {
301  // do not delete the last phase
302  const bool enable = myDefinitions.size() > 0 && myPhaseTable->getNumRows() > 1;
303  o->handle(this, FXSEL(SEL_COMMAND, enable ? FXWindow::ID_ENABLE : FXWindow::ID_DISABLE), 0);
304  return 1;
305 }
306 
307 
308 long
309 GNETLSEditorFrame::onUpdDefCreate(FXObject* o, FXSelector, void*) {
310  const bool enable = myCurrentJunction != 0 && !myHaveModifications;
311  o->handle(this, FXSEL(SEL_COMMAND, enable ? FXWindow::ID_ENABLE : FXWindow::ID_DISABLE), 0);
312  return 1;
313 }
314 
315 
316 long
317 GNETLSEditorFrame::onUpdModified(FXObject* o, FXSelector, void*) {
318  bool enable = myHaveModifications;
319  o->handle(this, FXSEL(SEL_COMMAND, enable ? FXWindow::ID_ENABLE : FXWindow::ID_DISABLE), 0);
320  return 1;
321 }
322 
323 
324 
325 long
326 GNETLSEditorFrame::onCmdDefOffset(FXObject*, FXSelector, void*) {
327  myHaveModifications = true;
329  return 1;
330 }
331 
332 
333 long
334 GNETLSEditorFrame::onCmdDefRename(FXObject*, FXSelector, void*) {
335  return 1;
336 }
337 
338 
339 long
340 GNETLSEditorFrame::onCmdDefSubRename(FXObject*, FXSelector, void*) {
341  return 1;
342 }
343 
344 
345 long
346 GNETLSEditorFrame::onCmdDefAddOff(FXObject*, FXSelector, void*) {
347  return 1;
348 }
349 
350 
351 long
352 GNETLSEditorFrame::onCmdGuess(FXObject*, FXSelector, void*) {
353  return 1;
354 }
355 
356 
357 long
358 GNETLSEditorFrame::onCmdPhaseSwitch(FXObject*, FXSelector, void*) {
359  const int index = myPhaseTable->getCurrentRow();
360  const NBTrafficLightLogic::PhaseDefinition& phase = getPhases()[index];
361  myPhaseTable->selectRow(index);
362  // need not hold since links could have been deleted somewhere else and indices may be reused
363  // assert(phase.state.size() == myInternalLanes.size());
364  for (TLIndexMap::iterator it = myInternalLanes.begin(); it != myInternalLanes.end(); it++) {
365  int tlIndex = it->first;
366  std::vector<GNEInternalLane*> lanes = it->second;
367  assert(tlIndex >= 0);
368  assert(tlIndex < (int)phase.state.size());
369  for (std::vector<GNEInternalLane*>::iterator it_lane = lanes.begin(); it_lane != lanes.end(); it_lane++) {
370  (*it_lane)->setLinkState((LinkState)phase.state[tlIndex]);
371  }
372  }
373  myViewNet->update();
374  return 1;
375 }
376 
377 
378 long
379 GNETLSEditorFrame::onCmdPhaseCreate(FXObject*, FXSelector, void*) {
380  myHaveModifications = true;
381  // allows insertion at first position by deselecting via arrow keys
382  int newIndex = myPhaseTable->getSelStartRow() + 1;
383  int oldIndex = MAX2(0, myPhaseTable->getSelStartRow());
384  // copy current row
385  const SUMOTime duration = getSUMOTime(myPhaseTable->getItemText(oldIndex, 0));
386  const std::string state = myPhaseTable->getItemText(oldIndex, 1).text();
387  myEditedDef->getLogic()->addStep(duration, state, newIndex);
388  myPhaseTable->setCurrentItem(newIndex, 0);
389  initPhaseTable(newIndex);
390  myPhaseTable->setFocus();
391  return 1;
392 }
393 
394 
395 long
396 GNETLSEditorFrame::onCmdPhaseDelete(FXObject*, FXSelector, void*) {
397  myHaveModifications = true;
398  const int newRow = MAX2((int)0, (int)myPhaseTable->getCurrentRow() - 1);
399  myEditedDef->getLogic()->deletePhase(myPhaseTable->getCurrentRow());
400  initPhaseTable(newRow);
401  myPhaseTable->setFocus();
402  return 1;
403 }
404 
405 
406 long
407 GNETLSEditorFrame::onCmdPhaseEdit(FXObject*, FXSelector, void* ptr) {
408  /* @note: there is a bug when copying/pasting rows: when this handler is
409  * called the value of the cell is not yet updated. This means you have to
410  * click inside the cell and hit enter to actually update the value */
411  FXTablePos* tp = (FXTablePos*)ptr;
412  FXString value = myPhaseTable->getItemText(tp->row, tp->col);
413  if (tp->col == 0) {
414  // duration edited
415  if (GNEAttributeCarrier::canParse<double>(value.text())) {
416  SUMOTime duration = getSUMOTime(value);
417  if (duration > 0) {
418  myEditedDef->getLogic()->setPhaseDuration(tp->row, duration);
419  myHaveModifications = true;
421  return 1;
422  }
423  }
424  // input error, reset value
425  myPhaseTable->setItemText(tp->row, 0, toString(STEPS2TIME(getPhases()[tp->row].duration)).c_str());
426  } else {
427  // state edited
428  try {
429  // insert phase with new step and delete the old phase
430  myEditedDef->getLogic()->addStep(getPhases()[tp->row].duration, value.text(), tp->row);
431  myEditedDef->getLogic()->deletePhase(tp->row + 1);
432  myHaveModifications = true;
433  onCmdPhaseSwitch(0, 0, 0);
434  } catch (ProcessError) {
435  // input error, reset value
436  myPhaseTable->setItemText(tp->row, 1, getPhases()[tp->row].state.c_str());
437  }
438  }
439  return 1;
440 }
441 
442 
443 void
445  std::string description;
446  if (myCurrentJunction == 0) {
447  description = "No Junction Selected\n";
448  } else {
450  description = "Current junction: " + nbn->getID() + "\n(";
451  if (!nbn->isTLControlled()) {
452  description += "uncontrolled, ";
453  }
454  description += (myHaveModifications ? "modified)" : "unmodified)");
455  }
456  myDescription->setText(description.c_str());
457 }
458 
459 
460 void
462  if (myCurrentJunction) {
464  }
465  // clean data structures
466  myCurrentJunction = 0;
467  myHaveModifications = false;
468  delete myEditedDef;
469  myEditedDef = 0;
470  buildIinternalLanes(0); // only clears
471  // clean up controls
472  myNameTextField->setText("");
473  myOffset->setText("");
474  myDefinitions.clear();
475  myProgramComboBox->hide();
476  initPhaseTable(); // only clears when there are no definitions
477  myCycleDuration->hide();
479 }
480 
481 
482 void
484  // clean up previous objects
486  for (TLIndexMap::iterator it = myInternalLanes.begin(); it != myInternalLanes.end(); it++) {
487  std::vector<GNEInternalLane*> lanes = it->second;
488  for (std::vector<GNEInternalLane*>::iterator it_lane = lanes.begin(); it_lane != lanes.end(); it_lane++) {
489  rtree.removeAdditionalGLObject(*it_lane);
490  delete *it_lane;
491  }
492  }
493  myInternalLanes.clear();
494  if (tlDef != 0) {
495  const int NUM_POINTS = 10;
496  assert(myCurrentJunction);
499  std::string innerID = ":" + nbn->getID(); // see NWWriter_SUMO::writeInternalEdges
500  const NBConnectionVector& links = tlDef->getControlledLinks();
501  for (NBConnectionVector::const_iterator it = links.begin(); it != links.end(); it++) {
502  int tlIndex = it->getTLIndex();
503  PositionVector shape = nbn->computeInternalLaneShape(it->getFrom(), NBEdge::Connection(it->getFromLane(),
504  it->getTo(), it->getToLane()), NUM_POINTS);
505  GNEInternalLane* ilane = new GNEInternalLane(this, innerID + '_' + toString(tlIndex), shape, tlIndex);
506  rtree.addAdditionalGLObject(ilane);
507  myInternalLanes[tlIndex].push_back(ilane);
508  }
509  const std::vector<NBNode::Crossing>& crossings = nbn->getCrossings();
510  for (std::vector<NBNode::Crossing>::const_iterator it = crossings.begin(); it != crossings.end(); it++) {
511  const NBNode::Crossing& c = *it;
512  GNEInternalLane* ilane = new GNEInternalLane(this, c.id, c.shape, c.tlLinkNo);
513  rtree.addAdditionalGLObject(ilane);
514  myInternalLanes[c.tlLinkNo].push_back(ilane);
515  }
516  }
517 }
518 
519 
520 void
522  myDefinitions.clear();
523  myNameTextField->setText("");
524  myProgramComboBox->clearItems();
525  assert(myCurrentJunction);
527  std::set<NBTrafficLightDefinition*> tldefs = nbn->getControllingTLS();
528  for (std::set<NBTrafficLightDefinition*>::iterator it = tldefs.begin(); it != tldefs.end(); it++) {
529  myDefinitions.push_back(*it);
530  myNameTextField->setText((*it)->getID().c_str());
531  myProgramComboBox->appendItem((*it)->getProgramID().c_str());
532  }
533  if (myDefinitions.size() > 0) {
534  myProgramComboBox->setCurrentItem(0);
535  myProgramComboBox->setNumVisible(myProgramComboBox->getNumItems());
536  myProgramComboBox->show();
537  onCmdDefSwitch(0, 0, 0);
538  }
540 }
541 
542 
543 void
545  myPhaseTable->setVisibleRows(1);
546  myPhaseTable->setVisibleColumns(2);
547  myPhaseTable->hide();
548  if (myDefinitions.size() > 0) {
549  const std::vector<NBTrafficLightLogic::PhaseDefinition>& phases = getPhases();
550  myPhaseTable->setTableSize((int)phases.size(), 2);
551  myPhaseTable->setVisibleRows((int)phases.size());
552  myPhaseTable->setVisibleColumns(2);
553  for (int row = 0; row < (int)phases.size(); row++) {
554  myPhaseTable->setItemText(row, 0, toString(STEPS2TIME(phases[row].duration)).c_str());
555  myPhaseTable->setItemText(row, 1, phases[row].state.c_str());
556  myPhaseTable->getItem(row, 1)->setJustify(FXTableItem::LEFT);
557  }
558  myPhaseTable->fitColumnsToContents(0, 2);
559  myPhaseTable->setHeight((int)phases.size() * 21); // experimental
560  myPhaseTable->setCurrentItem(index, 0);
561  myPhaseTable->selectRow(index, true);
562  myPhaseTable->show();
563  myPhaseTable->setFocus();
564  }
565  update();
566 }
567 
568 
569 const std::vector<NBTrafficLightLogic::PhaseDefinition>&
571  return myEditedDef->getLogic()->getPhases();
572 }
573 
574 
575 void
577  myHaveModifications = true;
578  if (myViewNet->changeAllPhases()) {
579  const std::vector<NBTrafficLightLogic::PhaseDefinition>& phases = getPhases();
580  for (int row = 0; row < (int)phases.size(); row++) {
581  myEditedDef->getLogic()->setPhaseState(row, lane->getTLIndex(), lane->getLinkState());
582  }
583  } else {
584  myEditedDef->getLogic()->setPhaseState(myPhaseTable->getCurrentRow(), lane->getTLIndex(), lane->getLinkState());
585  }
586  initPhaseTable(myPhaseTable->getCurrentRow());
587  myPhaseTable->setFocus();
588 }
589 
590 
591 void
592 GNETLSEditorFrame::handleMultiChange(GNELane* lane, FXObject* obj, FXSelector sel, void* data) {
593  if (myEditedDef != 0) {
594  myHaveModifications = true;
596  std::set<std::string> fromIDs;
597  fromIDs.insert(lane->getMicrosimID());
598  GNEEdge& edge = lane->getParentEdge();
599  // if neither the lane nor its edge are selected, apply changes to the whole edge
601  for (GNEEdge::LaneVector::const_iterator it_lane = edge.getLanes().begin(); it_lane != edge.getLanes().end(); it_lane++) {
602  fromIDs.insert((*it_lane)->getMicrosimID());
603  }
604  } else {
605  // if the edge is selected, apply changes to all lanes of all selected edges
606  if (gSelected.isSelected(GLO_EDGE, edge.getGlID())) {
607  std::vector<GNEEdge*> edges = myViewNet->getNet()->retrieveEdges(true);
608  for (std::vector<GNEEdge*>::iterator it = edges.begin(); it != edges.end(); it++) {
609  for (GNEEdge::LaneVector::const_iterator it_lane = (*it)->getLanes().begin(); it_lane != (*it)->getLanes().end(); it_lane++) {
610  fromIDs.insert((*it_lane)->getMicrosimID());
611  }
612  }
613  }
614  // if the lane is selected, apply changes to all selected lanes
615  if (gSelected.isSelected(GLO_LANE, lane->getGlID())) {
616  std::vector<GNELane*> lanes = myViewNet->getNet()->retrieveLanes(true);
617  for (std::vector<GNELane*>::iterator it_lane = lanes.begin(); it_lane != lanes.end(); it_lane++) {
618  fromIDs.insert((*it_lane)->getMicrosimID());
619  }
620  }
621 
622  }
623  // set new state for all connections from the chosen lane IDs
624  for (NBConnectionVector::const_iterator it = links.begin(); it != links.end(); it++) {
625  const NBConnection& c = *it;
626  if (fromIDs.count(c.getFrom()->getLaneID(c.getFromLane())) > 0) {
627  std::vector<GNEInternalLane*> lanes = myInternalLanes[c.getTLIndex()];
628  for (std::vector<GNEInternalLane*>::iterator it_lane = lanes.begin(); it_lane != lanes.end(); it_lane++) {
629  (*it_lane)->onDefault(obj, sel, data);
630  }
631  }
632  }
633  }
634 }
635 
636 
637 bool
639  if (myEditedDef != 0) {
641  for (NBConnectionVector::const_iterator it = links.begin(); it != links.end(); it++) {
642  if ((*it).getFrom()->getID() == edge.getMicrosimID()) {
643  return true;
644  }
645  }
646  }
647  return false;
648 }
649 
650 
651 SUMOTime
652 GNETLSEditorFrame::getSUMOTime(const FXString& string) {
653  assert(GNEAttributeCarrier::canParse<double>(string.text()));
654  return TIME2STEPS(GNEAttributeCarrier::parse<double>(string.text()));
655 }
656 
657 
658 void
660  SUMOTime cycleDuration = 0;
661  for (std::vector<NBTrafficLightLogic::PhaseDefinition>::const_iterator it = getPhases().begin(); it != getPhases().end(); it++) {
662  cycleDuration += it->duration;
663  }
664  std::string text = "Cycle time: " + toString(STEPS2TIME(cycleDuration));
665  myCycleDuration->setText(text.c_str());
666 }
667 
668 
669 /****************************************************************************/
int NUM_POINTS
replace program with a newly guessed program
Definition: GUIAppEnum.h:523
TLIndexMap myInternalLanes
long onCmdGuess(FXObject *, FXSelector, void *)
Called when the user presses the button Guess.
std::vector< NBTrafficLightDefinition * > myDefinitions
the list of Definitions for the current junction
std::vector< GNELane * > retrieveLanes(bool onlySelected=false)
return all lanes
Definition: GNENet.cpp:770
void setAttribute(SumoXMLAttr key, const std::string &value, GNEUndoList *undoList)
A structure which describes a connection between edges or lanes.
Definition: NBEdge.h:164
#define GUIDesignComboBoxNCol
number of column of every combo box
Definition: GUIDesigns.h:197
FXLabel * myDescription
the label that shows the current editing state
FXTable * myPhaseTable
table for selecting and rearranging phases and for changing 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.
SUMOTime getOffset() const
Returns the offset of first switch.
long onCmdDefCreate(FXObject *, FXSelector, void *)
Called when the user creates a TLS.
std::string id
the (edge)-id of this crossing
Definition: NBNode.h:153
void setOffset(SUMOTime offset)
Sets the offset of this tls.
A loaded (complete) traffic light logic.
Ok-button pressed.
Definition: GUIAppEnum.h:63
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:406
PositionVector computeInternalLaneShape(NBEdge *fromE, const NBEdge::Connection &con, int numPoints, NBNode *recordError=0) const
Compute the shape for an internal lane.
Definition: NBNode.cpp:627
#define GUIDesignComboBoxAttribute
Combo box static (cannot be edited) extended over the matrix column.
Definition: GUIDesigns.h:193
long onCmdPhaseSwitch(FXObject *, FXSelector, void *)
Called when the user switchs a Phase.
const std::vector< Crossing > & getCrossings() const
return this junctions pedestrian crossings
Definition: NBNode.h:620
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:141
The base class for traffic light logic definitions.
T MAX2(T a, T b)
Definition: StdDefs.h:70
bool isSelected(GUIGlObjectType type, GUIGlID id)
Returns the information whether the object with the given type and id is selected.
This lane is powered by an underlying GNEEdge and basically knows how to draw itself.
Definition: GNELane.h:54
PositionVector shape
The lane&#39;s shape.
Definition: NBNode.h:149
void editJunction(GNEJunction *junction)
edits the traffic light for the given junction
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:82
Cancel-button pressed.
Definition: GUIAppEnum.h:65
NBEdge * getFrom() const
returns the from-edge (start of the connection)
void selectTLS(bool selected)
notify the junction of being selected in tls-mode. (used to control drawing)
const std::string & getID() const
Returns the id.
Definition: Named.h:66
#define TIME2STEPS(x)
Definition: SUMOTime.h:66
void handleMultiChange(GNELane *lane, FXObject *obj, FXSelector sel, void *data)
update phase definition for the current traffic light and phase
The definition of a single phase of the logic.
long onUpdNeedsDef(FXObject *, FXSelector, void *)
Called when occurs an update of needs definition.
A RT-tree for efficient storing of SUMO&#39;s GL-objects.
Definition: SUMORTree.h:74
FXFont * myTableFont
font for the phase table
LinkState getLinkState() const
whether link state has been modfied
#define GUIDesignMatrixAttributes
Matrix design extended over Frame and used for represent attributes and their values (Deprecated) ...
Definition: GUIDesigns.h:225
long onCmdDefDelete(FXObject *, FXSelector, void *)
Called when the user deletes a TLS.
long onCmdDefOffset(FXObject *, FXSelector, void *)
Called when the user changes the offset of a TLS.
long onCmdDefSwitch(FXObject *, FXSelector, void *)
Called when the user switchs a TLS.
long onCmdDefAddOff(FXObject *, FXSelector, void *)
Called when the user adds a OFF.
bool changeAllPhases() const
change all phases
Definition: GNEViewNet.cpp:393
GNEViewNet * myViewNet
the window to inform when the tls is modfied
Definition: GNEFrame.h:95
FXTextField * myNameTextField
name text field
bool isTLControlled() const
Returns whether this node is controlled by any tls.
Definition: NBNode.h:288
std::string getAttribute(SumoXMLAttr key) const
GNEUndoList * getUndoList() const
get the undoList object
#define GUIDesignTextField
Definition: GUIDesigns.h:41
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:56
long onCmdCancel(FXObject *, FXSelector, void *)
Called when the user presses the Cancel-button.
GNEEdge & getParentEdge()
Returns underlying parent edge.
Definition: GNELane.cpp:1078
std::string getLaneID(int lane) const
get Lane ID (Secure)
Definition: NBEdge.cpp:2679
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:89
GNEJunction * retrieveJunction(const std::string &id, bool failHard=true)
get junction by id
Definition: GNENet.cpp:730
A list of positions.
bool controlsEdge(GNEEdge &edge) const
whether the given edge is controlled by the currently edited tlDef
long onUpdDefCreate(FXObject *, FXSelector, void *)
Called when occurs an update of create definition.
void buildIinternalLanes(NBTrafficLightDefinition *tlDef)
builds internal lanes for the given tlDef
bool myHaveModifications
whether the current tls was modified
definition related controls
Definition: GUIAppEnum.h:525
long onCmdPhaseEdit(FXObject *, FXSelector, void *)
Called when the user edits a Phase.
#define STEPS2TIME(x)
Definition: SUMOTime.h:65
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)
Definition: GNENet.cpp:1005
~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.
virtual const std::string & getMicrosimID() const
Returns the id of the object as known to microsim.
FXDEFMAP(GNETLSEditorFrame) GNETLSEditorFrameMap[]
void p_abort()
reverts and discards ALL active command groups
SUMORTree & getVisualisationSpeedUp()
Returns the RTree used for visualisation speed-up.
Definition: GNENet.cpp:228
std::vector< NBConnection > NBConnectionVector
Definition of a connection vector.
FXTextField * myOffset
the control for modifying offset
delete phase thable
Definition: GUIAppEnum.h:541
static SUMOTime getSUMOTime(const FXString &string)
converts to SUMOTime
A road/street connecting two junctions (netedit-version)
Definition: GNEEdge.h:57
#define GUIDesignTextFieldNCol
Num of column of text field.
Definition: GUIDesigns.h:50
long onUpdDefSwitch(FXObject *, FXSelector, void *)
Called when occurs an update of switch definition.
#define GUIDesignButton
Definition: GUIDesigns.h:57
void updateCycleDuration()
recomputes cycle duration and updates label
const std::vector< GNELane * > & getLanes()
returns a reference to the lane vector
Definition: GNEEdge.cpp:543
void initDefinitions()
initializes the definitions and corresponding listbox
std::vector< GNEEdge * > retrieveEdges(bool onlySelected=false)
return all edges
Definition: GNENet.cpp:758
void addAdditionalGLObject(GUIGlObject *o)
Adds an additional object (detector/shape/trigger) for visualisation.
Definition: SUMORTree.h:129
#define GUIDesignGroupBoxFrame
Group box design extended over frame.
Definition: GUIDesigns.h:219
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:298
int tlLinkNo
the traffic light index of this crossing (if controlled)
Definition: NBNode.h:161
long onCmdOK(FXObject *, FXSelector, void *)
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.
an edge
FXComboBox * myProgramComboBox
the comboBox for selecting the tl-definition to edit
GNEJunction * myCurrentJunction
the junction of the tls is being modified
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)
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:47
long onCmdPhaseCreate(FXObject *, FXSelector, void *)
Called when the user creates a Phase.
int getFromLane() const
returns the from-lane
Represents a single node (junction) during network building.
Definition: NBNode.h:75
GUIGlID getGlID() const
Returns the numerical id of the object.
A definition of a pedestrian crossing.
Definition: NBNode.h:135
void setStatusBarText(const std::string &text)
set staturBar text
Definition: GNEViewNet.cpp:357
long long int SUMOTime
Definition: TraCIDefs.h:52
int getTLIndex() const
returns the index within the controlling tls or InvalidTLIndex if this link is unontrolled ...
Definition: NBConnection.h:100
#define GUIDesignLabelLeft
Definition: GUIDesigns.h:144
void addStep(SUMOTime duration, const std::string &state, int index=-1)
Adds a phase to the logic.
long onCmdDefRename(FXObject *, FXSelector, void *)
Called when the user renames a TLS.
long onUpdModified(FXObject *, FXSelector, void *)
Called when occurs an update of modified.
#define GUIDesignLabelAttribute
label extended over the matrix column with thick frame
Definition: GUIDesigns.h:165
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.
GUISelectedStorage gSelected
A global holder of selected objects.
create phase thable
Definition: GUIAppEnum.h:539
NBTrafficLightLogicCont & getTLLogicCont()
returns the tllcont of the underlying netbuilder
Definition: GNENet.cpp:1171
NBLoadedSUMOTLDef * myEditedDef
the traffic light definition being edited
void updateDescription() const
update descrition
void cleanup()
cleans up previous lanes
FXLabel * myCycleDuration
label with the cycle duration
void initPhaseTable(int index=0)
initialies the phase table