SUMO - Simulation of Urban MObility
GNEDialog_FixAdditionalPositions.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 // Dialog used to fix invalid stopping places
16 /****************************************************************************/
17 
18 // ===========================================================================
19 // included modules
20 // ===========================================================================
21 #include <config.h>
22 
23 #include <iostream>
24 #include <netbuild/NBEdge.h>
28 #include <utils/common/ToString.h>
34 #include <netedit/GNEViewNet.h>
35 #include <netedit/GNEViewParent.h>
36 #include <netedit/GNEUndoList.h>
40 
42 
43 
44 // ===========================================================================
45 // FOX callback mapping
46 // ===========================================================================
47 
48 FXDEFMAP(GNEDialog_FixAdditionalPositions) GNEDialog_FixAdditionalPositionsMap[] = {
52 };
53 
54 // Object implementation
55 FXIMPLEMENT(GNEDialog_FixAdditionalPositions, FXDialogBox, GNEDialog_FixAdditionalPositionsMap, ARRAYNUMBER(GNEDialog_FixAdditionalPositionsMap))
56 
57 // ===========================================================================
58 // member method definitions
59 // ===========================================================================
60 
61 GNEDialog_FixAdditionalPositions::GNEDialog_FixAdditionalPositions(GNEViewNet* viewNet, const std::vector<GNEAdditional*>& invalidSingleLaneAdditionals, const std::vector<GNEAdditional*>& invalidMultiLaneAdditionals) :
62  FXDialogBox(viewNet->getApp(), ("Fix additional problems"), GUIDesignDialogBoxExplicit, 0, 0, 478, 350, 0, 0, 0, 0),
63  myViewNet(viewNet),
64  myInvalidSingleLaneAdditionals(invalidSingleLaneAdditionals),
65  myInvalidMultiLaneAdditionals(invalidMultiLaneAdditionals) {
66  // set busStop icon for this dialog
68  // create main frame
69  FXVerticalFrame* mainFrame = new FXVerticalFrame(this, GUIDesignAuxiliarFrame);
70  // create label for table
71  new FXLabel(mainFrame, "List of Stopping places and E2 detectors with conflicts", nullptr, GUIDesignLabelCenterThick);
72  // Create table, copy intervals and update table
73  myTable = new FXTable(mainFrame, this, MID_GNE_FIXSTOPPINGPLACES_CHANGE, GUIDesignTableAdditionals);
74  myTable->setSelBackColor(FXRGBA(255, 255, 255, 255));
75  myTable->setSelTextColor(FXRGBA(0, 0, 0, 255));
76  myTable->setEditable(false);
77  // clear table
78  myTable->clearItems();
79  // set number of rows
80  myTable->setTableSize(int(myInvalidSingleLaneAdditionals.size() + myInvalidMultiLaneAdditionals.size()), 3);
81  // Configure list
82  myTable->setVisibleColumns(4);
83  myTable->setColumnWidth(0, GUIDesignTableIconCellWidth);
84  myTable->setColumnWidth(1, 160);
85  myTable->setColumnWidth(2, 280);
86  myTable->setColumnText(0, "");
87  myTable->setColumnText(1, toString(SUMO_ATTR_ID).c_str());
88  myTable->setColumnText(2, "Conflict");
89  myTable->getRowHeader()->setWidth(0);
90  // Declare index for rows and pointer to FXTableItem
91  int indexRow = 0;
92  FXTableItem* item = nullptr;
93  // iterate over single lane additionals
94  for (auto i : myInvalidSingleLaneAdditionals) {
95  // Set icon
96  item = new FXTableItem("", i->getIcon());
97  item->setIconPosition(FXTableItem::CENTER_X);
98  myTable->setItem(indexRow, 0, item);
99  // Set ID
100  item = new FXTableItem(i->getID().c_str());
101  item->setJustify(FXTableItem::LEFT | FXTableItem::CENTER_Y);
102  myTable->setItem(indexRow, 1, item);
103  // Set conflict
104  item = new FXTableItem(i->getAdditionalProblem().c_str());
105  item->setJustify(FXTableItem::LEFT | FXTableItem::CENTER_Y);
106  myTable->setItem(indexRow, 2, item);
107  // Update index
108  indexRow++;
109  }
110  // iterate over multi lane additionals
111  for (auto i : myInvalidMultiLaneAdditionals) {
112  // Set icon
113  item = new FXTableItem("", i->getIcon());
114  item->setIconPosition(FXTableItem::CENTER_X);
115  myTable->setItem(indexRow, 0, item);
116  // Set ID
117  item = new FXTableItem(i->getID().c_str());
118  item->setJustify(FXTableItem::LEFT | FXTableItem::CENTER_Y);
119  myTable->setItem(indexRow, 1, item);
120  // set conflict
121  item = new FXTableItem((i->getAdditionalProblem()).c_str());
122  item->setJustify(FXTableItem::LEFT | FXTableItem::CENTER_Y);
123  myTable->setItem(indexRow, 2, item);
124  // Update index
125  indexRow++;
126  }
127  // create position options
128  myPositionOptions.buildPositionOptions(this, mainFrame);
129  // check if position options has to be disabled
130  if(myInvalidSingleLaneAdditionals.empty()) {
131  myPositionOptions.disablePositionOptions();
132  }
133  // create consecutive lane options
134  myConsecutiveLaneOptions.buildConsecutiveLaneOptions(this, mainFrame);
135  // check if consecutive lane options has to be disabled
136  if(myInvalidMultiLaneAdditionals.empty()) {
137  myConsecutiveLaneOptions.disableConsecutiveLaneOptions();
138  }
139  // create dialog buttons bot centered
140  new FXHorizontalSeparator(mainFrame, GUIDesignHorizontalSeparator);
141  FXHorizontalFrame* buttonsFrame = new FXHorizontalFrame(mainFrame, GUIDesignHorizontalFrame);
142  new FXHorizontalFrame(buttonsFrame, GUIDesignAuxiliarHorizontalFrame);
143  myAcceptButton = new FXButton(buttonsFrame, FXWindow::tr("&Accept"), GUIIconSubSys::getIcon(ICON_ACCEPT), this, MID_GNE_ADDITIONALDIALOG_BUTTONACCEPT, GUIDesignButtonAccept);
144  myCancelButton = new FXButton(buttonsFrame, FXWindow::tr("&Cancel"), GUIIconSubSys::getIcon(ICON_CANCEL), this, MID_GNE_ADDITIONALDIALOG_BUTTONCANCEL, GUIDesignButtonCancel);
145  new FXHorizontalFrame(buttonsFrame, GUIDesignAuxiliarHorizontalFrame);
146  // set focus in accept button
147  myAcceptButton->setFocus();
148 }
149 
150 
152 }
153 
154 
155 long
156 GNEDialog_FixAdditionalPositions::onCmdSelectOption(FXObject* obj, FXSelector, void*) {
159  return 1;
160 }
161 
162 
163 long
164 GNEDialog_FixAdditionalPositions::onCmdAccept(FXObject*, FXSelector, void*) {
165  bool continueSaving = true;
166  // first check options from single lane additionals
167  if(myInvalidSingleLaneAdditionals.size() > 0) {
168  if (myPositionOptions.activateFriendlyPositionAndSave->getCheck() == TRUE) {
169  myViewNet->getUndoList()->p_begin("change " + toString(SUMO_ATTR_FRIENDLY_POS) + " of invalid additionals");
170  // iterate over invalid single lane elements to enable friendly position
171  for (auto i : myInvalidSingleLaneAdditionals) {
172  i->setAttribute(SUMO_ATTR_FRIENDLY_POS, "true", myViewNet->getUndoList());
173  }
175  } else if (myPositionOptions.fixPositionsAndSave->getCheck() == TRUE) {
176  myViewNet->getUndoList()->p_begin("fix positions of invalid additionals");
177  // iterate over invalid single lane elements to fix positions
178  for (auto i : myInvalidSingleLaneAdditionals) {
179  i->fixAdditionalProblem();
180  }
182  } else if (myPositionOptions.selectInvalidStopsAndCancel->getCheck() == TRUE) {
183  myViewNet->getUndoList()->p_begin("select invalid additionals");
184  // iterate over invalid single lane elements to select all elements
185  for (auto i : myInvalidSingleLaneAdditionals) {
186  i->setAttribute(GNE_ATTR_SELECTED, "true", myViewNet->getUndoList());
187  }
189  // abort saving
190  continueSaving = false;
191  }
192  }
193  // now check options from multi lane additionals
194  if(myInvalidMultiLaneAdditionals.size() > 0) {
195  myViewNet->getUndoList()->p_begin("fix multilane additionals problems");
196  // fix problems of consecutive lanes
197  if (myConsecutiveLaneOptions.buildConnectionBetweenLanes->getCheck() == TRUE) {
198  // iterate over invalid single lane elements to enable friendly position
199  for (auto i : myInvalidMultiLaneAdditionals) {
200  i->fixAdditionalProblem();
201  }
202  // we need to check if after first fix there is still Invalid MultiL-ane Additionals with errors
203  auto copyOfInvalidMultiLaneAdditionals = myInvalidMultiLaneAdditionals;
204  myInvalidMultiLaneAdditionals.clear();
205  for (auto i : copyOfInvalidMultiLaneAdditionals) {
206  if(!i->isAdditionalValid()) {
207  myInvalidMultiLaneAdditionals.push_back(i);
208  }
209  }
210  } else if (myConsecutiveLaneOptions.removeInvalidElements->getCheck() == TRUE) {
211  // iterate over invalid single lane elements to fix positions
212  for (auto i : myInvalidMultiLaneAdditionals) {
214  }
215  // clear myInvalidMultiLaneAdditionals due tere isn't more invalid multi lane additionals
216  myInvalidMultiLaneAdditionals.clear();
217  }
218  // fix problem of positions
219  if (myPositionOptions.activateFriendlyPositionAndSave->getCheck() == TRUE) {
220  // iterate over invalid single lane elements to enable friendly position
221  for (auto i : myInvalidSingleLaneAdditionals) {
222  i->setAttribute(SUMO_ATTR_FRIENDLY_POS, "true", myViewNet->getUndoList());
223  }
224  } else if (myPositionOptions.fixPositionsAndSave->getCheck() == TRUE) {
225  // iterate over invalid single lane elements to fix positions
226  for (auto i : myInvalidSingleLaneAdditionals) {
227  i->fixAdditionalProblem();
228  }
229  }
231  }
232  if(continueSaving) {
233  // stop modal with TRUE (continue saving)
234  getApp()->stopModal(this, TRUE);
235  } else {
236  // stop modal with TRUE (abort saving)
237  getApp()->stopModal(this, FALSE);
238  }
239  return 1;
240 }
241 
242 
243 long
244 GNEDialog_FixAdditionalPositions::onCmdCancel(FXObject*, FXSelector, void*) {
245  // Stop Modal (abort saving)
246  getApp()->stopModal(this, FALSE);
247  return 1;
248 }
249 
250 
251 void
253  // create label for elements
254  new FXLabel(mainFrame, "Select a solution for StoppingPlaces and E2 detectors:", nullptr, GUIDesignLabelCenterThick);
255  // create horizontal frames for radio buttons
256  FXHorizontalFrame* RadioButtons = new FXHorizontalFrame(mainFrame, GUIDesignHorizontalFrame);
257  // create Vertical Frame for left options
258  FXVerticalFrame* RadioButtonsLeft = new FXVerticalFrame(RadioButtons, GUIDesignAuxiliarVerticalFrame);
259  activateFriendlyPositionAndSave = new FXRadioButton(RadioButtonsLeft, "Activate friendlyPos and save\t\tFriendly pos parameter will be activated in all stopping places and E2 detectors",
260  fixAdditionalPositions, MID_CHOOSEN_OPERATION, GUIDesignRadioButton);
261  saveInvalid = new FXRadioButton(RadioButtonsLeft, "Save invalid positions\t\tSave stopping places and E2 detectors with invalid positions",
262  fixAdditionalPositions, MID_CHOOSEN_OPERATION, GUIDesignRadioButton);
263  // create Vertical Frame for right options
264  FXVerticalFrame* RadioButtonsRight = new FXVerticalFrame(RadioButtons, GUIDesignAuxiliarVerticalFrame);
265  fixPositionsAndSave = new FXRadioButton(RadioButtonsRight, "Fix positions and save\t\tPosition of stopping places and E2 detectors will be fixed",
266  fixAdditionalPositions, MID_CHOOSEN_OPERATION, GUIDesignRadioButton);
267  selectInvalidStopsAndCancel = new FXRadioButton(RadioButtonsRight, "Select invalid additionals\t\tCancel saving of additionals and select invalid stopping places and E2 detectors",
268  fixAdditionalPositions, MID_CHOOSEN_OPERATION, GUIDesignRadioButton);
269  // leave option "activateFriendlyPositionAndSave" as default
270  activateFriendlyPositionAndSave->setCheck(true);
271 }
272 
273 
274 void
276  if (option == activateFriendlyPositionAndSave) {
277  activateFriendlyPositionAndSave->setCheck(true);
278  fixPositionsAndSave->setCheck(false);
279  saveInvalid->setCheck(false);
280  selectInvalidStopsAndCancel->setCheck(false);
281  } else if (option == fixPositionsAndSave) {
282  activateFriendlyPositionAndSave->setCheck(false);
283  fixPositionsAndSave->setCheck(true);
284  saveInvalid->setCheck(false);
285  selectInvalidStopsAndCancel->setCheck(false);
286  } else if (option == saveInvalid) {
287  activateFriendlyPositionAndSave->setCheck(false);
288  fixPositionsAndSave->setCheck(false);
289  saveInvalid->setCheck(true);
290  selectInvalidStopsAndCancel->setCheck(false);
291  } else if (option == selectInvalidStopsAndCancel) {
292  activateFriendlyPositionAndSave->setCheck(false);
293  fixPositionsAndSave->setCheck(false);
294  saveInvalid->setCheck(false);
295  selectInvalidStopsAndCancel->setCheck(true);
296  }
297 }
298 
299 
300 void
302  activateFriendlyPositionAndSave->enable();
303  fixPositionsAndSave->enable();
304  saveInvalid->enable();
305  selectInvalidStopsAndCancel->enable();
306 }
307 
308 
309 void
311  activateFriendlyPositionAndSave->disable();
312  fixPositionsAndSave->disable();
313  saveInvalid->disable();
314  selectInvalidStopsAndCancel->disable();
315 }
316 
317 
318 void
320  // create label for elements
321  new FXLabel(mainFrame, "Select a solution for Multilane E2 detectors:", nullptr, GUIDesignLabelCenterThick);
322  // create horizontal frames for radio buttons
323  FXHorizontalFrame* RadioButtons = new FXHorizontalFrame(mainFrame, GUIDesignHorizontalFrame);
324  // create Vertical Frame for left options
325  FXVerticalFrame* RadioButtonsLeft = new FXVerticalFrame(RadioButtons, GUIDesignAuxiliarVerticalFrame);
326  buildConnectionBetweenLanes = new FXRadioButton(RadioButtonsLeft, "Build connections between lanes\t\tNew connections will be created between non-connected lanes",
327  fixAdditionalPositions, MID_CHOOSEN_OPERATION, GUIDesignRadioButton);
328  removeInvalidElements = new FXRadioButton(RadioButtonsLeft, "Remove invalid E2 detectors\t\tRemove Multilane E2 Detectors with non-connected lanes",
329  fixAdditionalPositions, MID_CHOOSEN_OPERATION, GUIDesignRadioButton);
330  // add a vertical separator beween both options
331  new FXVerticalSeparator(RadioButtons, GUIDesignVerticalSeparator);
332  // create Vertical Frame for right options
333  FXVerticalFrame* RadioButtonsRight = new FXVerticalFrame(RadioButtons, GUIDesignAuxiliarVerticalFrame);
334  activateFriendlyPositionAndSave = new FXRadioButton(RadioButtonsRight, "Activate friendlyPos and save\t\tFriendly pos parameter will be activated in all stopping places and E2 detectors",
335  fixAdditionalPositions, MID_CHOOSEN_OPERATION, GUIDesignRadioButton);
336  fixPositionsAndSave = new FXRadioButton(RadioButtonsRight, "Fix positions and save\t\tPosition of stopping places and E2 detectors will be fixed",
337  fixAdditionalPositions, MID_CHOOSEN_OPERATION, GUIDesignRadioButton);
338  // leave option "buildConnectionBetweenLanes" and "activateFriendlyPositionAndSave" as default
339  buildConnectionBetweenLanes->setCheck(true);
340  activateFriendlyPositionAndSave->setCheck(true);
341 }
342 
343 
344 void
346  // set top buttons
347  if (option == buildConnectionBetweenLanes) {
348  buildConnectionBetweenLanes->setCheck(true);
349  removeInvalidElements->setCheck(false);
350  } else if (option == removeInvalidElements) {
351  buildConnectionBetweenLanes->setCheck(false);
352  removeInvalidElements->setCheck(true);
353  }
354  // set down buttons
355  if (option == activateFriendlyPositionAndSave) {
356  activateFriendlyPositionAndSave->setCheck(true);
357  fixPositionsAndSave->setCheck(false);
358  } else if (option == fixPositionsAndSave) {
359  activateFriendlyPositionAndSave->setCheck(false);
360  fixPositionsAndSave->setCheck(true);
361  }
362 }
363 
364 
365 void
367  buildConnectionBetweenLanes->enable();
368  removeInvalidElements->enable();
369  activateFriendlyPositionAndSave->enable();
370  fixPositionsAndSave->enable();
371 }
372 
373 
374 void
376  buildConnectionBetweenLanes->disable();
377  removeInvalidElements->disable();
378  activateFriendlyPositionAndSave->disable();
379  fixPositionsAndSave->disable();
380 }
381 
382 /****************************************************************************/
void buildConsecutiveLaneOptions(GNEDialog_FixAdditionalPositions *fixAdditionalPositions, FXVerticalFrame *mainFrame)
build consecutive lane Options
#define GUIDesignTableIconCellWidth
width of cells that only contains an Icon
Definition: GUIDesigns.h:450
#define GUIDesignHorizontalFrame
Definition: GUIDesigns.h:212
void buildPositionOptions(GNEDialog_FixAdditionalPositions *fixAdditionalPositions, FXVerticalFrame *mainFrame)
build Position Options
long onCmdAccept(FXObject *, FXSelector, void *)
event after press accept button
#define GUIDesignVerticalSeparator
vertical separator
Definition: GUIDesigns.h:301
GNEViewParent * getViewParent() const
get the net object
#define GUIDesignButtonCancel
Cancel Button.
Definition: GUIDesigns.h:102
void p_begin(const std::string &description)
Begin undo command sub-group. This begins a new group of commands that are treated as a single comman...
Definition: GNEUndoList.cpp:73
FXRadioButton * buildConnectionBetweenLanes
Option "build connections between lanes".
FixStoppingPlaces dialog.
Definition: GUIAppEnum.h:905
GNEAdditionalFrame * getAdditionalFrame() const
get frame for GNE_MODE_ADDITIONAL
GNEUndoList * getUndoList() const
get the undoList object
set type of selection
Definition: GUIAppEnum.h:344
#define GUIDesignAuxiliarFrame
design for auxiliar (Without borders) frames used to pack another frames extended in all directions ...
Definition: GUIDesigns.h:258
#define GUIDesignHorizontalSeparator
Definition: GUIDesigns.h:298
#define GUIDesignDialogBoxExplicit
design for dialog box with specift width and height (for example, additional dialogs) ...
Definition: GUIDesigns.h:422
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:49
void p_end()
End undo command sub-group. If the sub-group is still empty, it will be deleted; otherwise, the sub-group will be added as a new command into parent group. A matching begin() must have been called previously.
Definition: GNEUndoList.cpp:80
#define GUIDesignAuxiliarHorizontalFrame
design for auxiliar (Without borders) horizontal frame used to pack another frames ...
Definition: GUIDesigns.h:261
void removeAdditional(GNEAdditional *additional)
remove an additional element previously added
#define GUIDesignTableAdditionals
design for tables used in additional dialogs
Definition: GUIDesigns.h:447
#define GUIDesignAuxiliarVerticalFrame
design for auxiliar (Without borders) horizontal frame used to pack another frames ...
Definition: GUIDesigns.h:264
#define GUIDesignButtonAccept
Accept Button.
Definition: GUIDesigns.h:99
FXRadioButton * activateFriendlyPositionAndSave
Option "Activate friendlyPos and save".
#define GUIDesignLabelCenterThick
label extended over frame with thick and with text justify to center and height of 23 ...
Definition: GUIDesigns.h:163
FXRadioButton * removeInvalidElements
Option "remove invalid elements".
An Element which don&#39;t belongs to GNENet but has influency in the simulation.
Definition: GNEAdditional.h:48
PositionOptions myPositionOptions
struct with position options
element is selected
ConsecutiveLaneOptions myConsecutiveLaneOptions
struct with the consecutive lane options
std::vector< GNEAdditional * > myInvalidMultiLaneAdditionals
vector with the invalid multi-lane additionals
FXDEFMAP(GNEDialog_FixAdditionalPositions) GNEDialog_FixAdditionalPositionsMap[]
FXRadioButton * fixPositionsAndSave
Option "Fix Positions and save".
FXRadioButton * selectInvalidStopsAndCancel
Option "Select invalid stops and cancel".
long onCmdCancel(FXObject *, FXSelector, void *)
event after press cancel button
#define GUIDesignRadioButton
Definition: GUIDesigns.h:135
long onCmdSelectOption(FXObject *obj, FXSelector, void *)
static FXIcon * getIcon(GUIIcon which)
returns a icon previously defined in the enum GUIIcon
std::vector< GNEAdditional * > myInvalidSingleLaneAdditionals
vector with the invalid single-lane additionals