Eclipse SUMO - Simulation of Urban MObility
GNEFixAdditionalElements.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-2022 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials are made available under the
5 // terms of the Eclipse Public License 2.0 which is available at
6 // https://www.eclipse.org/legal/epl-2.0/
7 // This Source Code may also be made available under the following Secondary
8 // Licenses when the conditions for such availability set forth in the Eclipse
9 // Public License 2.0 are satisfied: GNU General Public License, version 2
10 // or later which is available at
11 // https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
12 // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
13 /****************************************************************************/
18 // Dialog used to fix additional elements
19 /****************************************************************************/
20 #include <config.h>
21 
24 #include <netedit/GNENet.h>
25 #include <netedit/GNEViewNet.h>
26 #include <netedit/GNEUndoList.h>
27 
29 
30 
31 // ===========================================================================
32 // FOX callback mapping
33 // ===========================================================================
34 
35 FXDEFMAP(GNEFixAdditionalElements) GNEFixAdditionalElementsMap[] = {
39 };
40 
41 // Object implementation
42 FXIMPLEMENT(GNEFixAdditionalElements, FXDialogBox, GNEFixAdditionalElementsMap, ARRAYNUMBER(GNEFixAdditionalElementsMap))
43 
44 // ===========================================================================
45 // member method definitions
46 // ===========================================================================
47 
48 GNEFixAdditionalElements::GNEFixAdditionalElements(GNEViewNet* viewNet, const std::vector<GNEAdditional*>& invalidSingleLaneAdditionals, const std::vector<GNEAdditional*>& invalidMultiLaneAdditionals) :
49  FXDialogBox(viewNet->getApp(), ("Fix additional problems"), GUIDesignDialogBoxExplicit(500, 380)),
50  myViewNet(viewNet) {
51  // set busStop icon for this dialog
53  // create main frame
54  myMainFrame = new FXVerticalFrame(this, GUIDesignAuxiliarFrame);
55  // create AdditionalList
56  myAdditionalList = new AdditionalList(this, invalidSingleLaneAdditionals, invalidMultiLaneAdditionals);
57  // create position options
58  myPositionOptions = new PositionOptions(this);
59  // create consecutive lane options
60  myConsecutiveLaneOptions = new ConsecutiveLaneOptions(this);
61  // check if position options has to be disabled
62  if (myAdditionalList->myInvalidSingleLaneAdditionals.empty()) {
63  myPositionOptions->disablePositionOptions();
64  }
65  // check if consecutive lane options has to be disabled
66  if (myAdditionalList->myInvalidMultiLaneAdditionals.empty()) {
67  myConsecutiveLaneOptions->disableConsecutiveLaneOptions();
68  }
69  // create dialog buttons bot centered
70  FXHorizontalFrame* buttonsFrame = new FXHorizontalFrame(myMainFrame, GUIDesignHorizontalFrame);
71  new FXHorizontalFrame(buttonsFrame, GUIDesignAuxiliarHorizontalFrame);
72  myAcceptButton = new FXButton(buttonsFrame, FXWindow::tr("&Accept"), GUIIconSubSys::getIcon(GUIIcon::ACCEPT), this, MID_GNE_BUTTON_ACCEPT, GUIDesignButtonAccept);
73  myCancelButton = new FXButton(buttonsFrame, FXWindow::tr("&Cancel"), GUIIconSubSys::getIcon(GUIIcon::CANCEL), this, MID_GNE_BUTTON_CANCEL, GUIDesignButtonCancel);
74  new FXHorizontalFrame(buttonsFrame, GUIDesignAuxiliarHorizontalFrame);
75  // set focus in accept button
76  myAcceptButton->setFocus();
77 }
78 
79 
81 }
82 
83 
84 long
85 GNEFixAdditionalElements::onCmdSelectOption(FXObject* obj, FXSelector, void*) {
88  return 1;
89 }
90 
91 
92 long
93 GNEFixAdditionalElements::onCmdAccept(FXObject*, FXSelector, void*) {
94  bool continueSaving = true;
95  // first check options from single lane additionals
97  if (myPositionOptions->activateFriendlyPositionAndSave->getCheck() == TRUE) {
98  myViewNet->getUndoList()->begin(myAdditionalList->myInvalidSingleLaneAdditionals.front()->getTagProperty().getGUIIcon(),
99  "change " + toString(SUMO_ATTR_FRIENDLY_POS) + " of invalid additionals");
100  // iterate over invalid single lane elements to enable friendly position
102  i->setAttribute(SUMO_ATTR_FRIENDLY_POS, "true", myViewNet->getUndoList());
103  }
104  myViewNet->getUndoList()->end();
105  } else if (myPositionOptions->fixPositionsAndSave->getCheck() == TRUE) {
106  myViewNet->getUndoList()->begin(myAdditionalList->myInvalidSingleLaneAdditionals.front()->getTagProperty().getGUIIcon(),
107  "fix positions of invalid additionals");
108  // iterate over invalid single lane elements to fix positions
110  i->fixAdditionalProblem();
111  }
112  myViewNet->getUndoList()->end();
113  } else if (myPositionOptions->selectInvalidStopsAndCancel->getCheck() == TRUE) {
114  myViewNet->getUndoList()->begin(myAdditionalList->myInvalidSingleLaneAdditionals.front()->getTagProperty().getGUIIcon(),
115  "select invalid additionals");
116  // iterate over invalid single lane elements to select all elements
118  i->setAttribute(GNE_ATTR_SELECTED, "true", myViewNet->getUndoList());
119  }
120  myViewNet->getUndoList()->end();
121  // abort saving
122  continueSaving = false;
123  }
124  }
125  // now check options from multi lane additionals
127  myViewNet->getUndoList()->begin(myAdditionalList->myInvalidMultiLaneAdditionals.front()->getTagProperty().getGUIIcon(),
128  "fix multilane additionals problems");
129  // fix problems of consecutive lanes
130  if (myConsecutiveLaneOptions->buildConnectionBetweenLanes->getCheck() == TRUE) {
131  // iterate over invalid single lane elements to enable friendly position
133  i->fixAdditionalProblem();
134  }
135  // we need to check if after first fix there is still Invalid MultiL-ane Additionals with errors
136  auto copyOfInvalidMultiLaneAdditionals = myAdditionalList->myInvalidMultiLaneAdditionals;
138  for (auto i : copyOfInvalidMultiLaneAdditionals) {
139  if (!i->isAdditionalValid()) {
141  }
142  }
143  } else if (myConsecutiveLaneOptions->removeInvalidElements->getCheck() == TRUE) {
144  // iterate over invalid single lane elements to fix positions
147  }
148  // clear myInvalidMultiLaneAdditionals due there isn't more invalid multi lane additionals
150  }
151  // fix problem of positions
152  if (myPositionOptions->activateFriendlyPositionAndSave->getCheck() == TRUE) {
153  // iterate over invalid single lane elements to enable friendly position
155  i->setAttribute(SUMO_ATTR_FRIENDLY_POS, "true", myViewNet->getUndoList());
156  }
157  } else if (myPositionOptions->fixPositionsAndSave->getCheck() == TRUE) {
158  // iterate over invalid single lane elements to fix positions
160  i->fixAdditionalProblem();
161  }
162  }
163  myViewNet->getUndoList()->end();
164  }
165  if (continueSaving) {
166  // stop modal with TRUE (continue saving)
167  getApp()->stopModal(this, TRUE);
168  } else {
169  // stop modal with TRUE (abort saving)
170  getApp()->stopModal(this, FALSE);
171  }
172  return 1;
173 }
174 
175 
176 long
177 GNEFixAdditionalElements::onCmdCancel(FXObject*, FXSelector, void*) {
178  // Stop Modal (abort saving)
179  getApp()->stopModal(this, FALSE);
180  return 1;
181 }
182 
183 // ---------------------------------------------------------------------------
184 // GNEFixDemandElements::DemandList - methods
185 // ---------------------------------------------------------------------------
186 
187 GNEFixAdditionalElements::AdditionalList::AdditionalList(GNEFixAdditionalElements* fixAdditionalPositions, const std::vector<GNEAdditional*>& invalidSingleLaneAdditionals, const std::vector<GNEAdditional*>& invalidMultiLaneAdditionals) :
188  FXGroupBox(fixAdditionalPositions->myMainFrame, "Stopping places and E2 detectors with conflicts", GUIDesignGroupBoxFrameFill),
189  myInvalidSingleLaneAdditionals(invalidSingleLaneAdditionals),
190  myInvalidMultiLaneAdditionals(invalidMultiLaneAdditionals) {
191  // Create table, copy intervals and update table
193  myTable->setSelBackColor(FXRGBA(255, 255, 255, 255));
194  myTable->setSelTextColor(FXRGBA(0, 0, 0, 255));
195  myTable->setEditable(false);
196  // clear table
197  myTable->clearItems();
198  // set number of rows
199  myTable->setTableSize(int(myInvalidSingleLaneAdditionals.size() + myInvalidMultiLaneAdditionals.size()), 3);
200  // Configure list
201  myTable->setVisibleColumns(4);
202  myTable->setColumnWidth(0, GUIDesignHeight);
203  myTable->setColumnWidth(1, 160);
204  myTable->setColumnWidth(2, 280);
205  myTable->setColumnText(0, "");
206  myTable->setColumnText(1, toString(SUMO_ATTR_ID).c_str());
207  myTable->setColumnText(2, "Conflict");
208  myTable->getRowHeader()->setWidth(0);
209  // Declare index for rows and pointer to FXTableItem
210  int indexRow = 0;
211  FXTableItem* item = nullptr;
212  // iterate over single lane additionals
213  for (auto i : myInvalidSingleLaneAdditionals) {
214  // Set icon
215  item = new FXTableItem("", i->getIcon());
216  item->setIconPosition(FXTableItem::CENTER_X);
217  myTable->setItem(indexRow, 0, item);
218  // Set ID
219  item = new FXTableItem(i->getID().c_str());
220  item->setJustify(FXTableItem::LEFT | FXTableItem::CENTER_Y);
221  myTable->setItem(indexRow, 1, item);
222  // Set conflict
223  item = new FXTableItem(i->getAdditionalProblem().c_str());
224  item->setJustify(FXTableItem::LEFT | FXTableItem::CENTER_Y);
225  myTable->setItem(indexRow, 2, item);
226  // Update index
227  indexRow++;
228  }
229  // iterate over multi lane additionals
230  for (auto i : myInvalidMultiLaneAdditionals) {
231  // Set icon
232  item = new FXTableItem("", i->getIcon());
233  item->setIconPosition(FXTableItem::CENTER_X);
234  myTable->setItem(indexRow, 0, item);
235  // Set ID
236  item = new FXTableItem(i->getID().c_str());
237  item->setJustify(FXTableItem::LEFT | FXTableItem::CENTER_Y);
238  myTable->setItem(indexRow, 1, item);
239  // set conflict
240  item = new FXTableItem((i->getAdditionalProblem()).c_str());
241  item->setJustify(FXTableItem::LEFT | FXTableItem::CENTER_Y);
242  myTable->setItem(indexRow, 2, item);
243  // Update index
244  indexRow++;
245  }
246 }
247 
248 // ---------------------------------------------------------------------------
249 // GNEFixAdditionalElements::PositionOptions - methods
250 // ---------------------------------------------------------------------------
251 
253  FXGroupBoxModule(fixAdditionalPositions->myMainFrame, "Select a solution for StoppingPlaces and E2 detectors", FXGroupBoxModule::Options::NOTHING) {
254  // create horizontal frames for radio buttons
255  FXHorizontalFrame* RadioButtons = new FXHorizontalFrame(this, GUIDesignHorizontalFrame);
256  // create Vertical Frame for left options
257  FXVerticalFrame* RadioButtonsLeft = new FXVerticalFrame(RadioButtons, GUIDesignAuxiliarVerticalFrame);
258  activateFriendlyPositionAndSave = new FXRadioButton(RadioButtonsLeft, "Activate friendlyPos and save\t\tFriendly pos parameter will be activated in all stopping places and E2 detectors",
259  fixAdditionalPositions, MID_CHOOSEN_OPERATION, GUIDesignRadioButton);
260  saveInvalid = new FXRadioButton(RadioButtonsLeft, "Save invalid positions\t\tSave stopping places and E2 detectors with invalid positions",
261  fixAdditionalPositions, MID_CHOOSEN_OPERATION, GUIDesignRadioButton);
262  // create Vertical Frame for right options
263  FXVerticalFrame* RadioButtonsRight = new FXVerticalFrame(RadioButtons, GUIDesignAuxiliarVerticalFrame);
264  fixPositionsAndSave = new FXRadioButton(RadioButtonsRight, "Fix positions and save\t\tPosition of stopping places and E2 detectors will be fixed",
265  fixAdditionalPositions, MID_CHOOSEN_OPERATION, GUIDesignRadioButton);
266  selectInvalidStopsAndCancel = new FXRadioButton(RadioButtonsRight, "Select invalid additionals\t\tCancel saving of additionals and select invalid stopping places and E2 detectors",
267  fixAdditionalPositions, MID_CHOOSEN_OPERATION, GUIDesignRadioButton);
268  // leave option "activateFriendlyPositionAndSave" as default
269  activateFriendlyPositionAndSave->setCheck(true);
270 }
271 
272 
273 void
275  if (option == activateFriendlyPositionAndSave) {
276  activateFriendlyPositionAndSave->setCheck(true);
277  fixPositionsAndSave->setCheck(false);
278  saveInvalid->setCheck(false);
279  selectInvalidStopsAndCancel->setCheck(false);
280  } else if (option == fixPositionsAndSave) {
281  activateFriendlyPositionAndSave->setCheck(false);
282  fixPositionsAndSave->setCheck(true);
283  saveInvalid->setCheck(false);
284  selectInvalidStopsAndCancel->setCheck(false);
285  } else if (option == saveInvalid) {
286  activateFriendlyPositionAndSave->setCheck(false);
287  fixPositionsAndSave->setCheck(false);
288  saveInvalid->setCheck(true);
289  selectInvalidStopsAndCancel->setCheck(false);
290  } else if (option == selectInvalidStopsAndCancel) {
291  activateFriendlyPositionAndSave->setCheck(false);
292  fixPositionsAndSave->setCheck(false);
293  saveInvalid->setCheck(false);
294  selectInvalidStopsAndCancel->setCheck(true);
295  }
296 }
297 
298 
299 void
301  activateFriendlyPositionAndSave->enable();
302  fixPositionsAndSave->enable();
303  saveInvalid->enable();
304  selectInvalidStopsAndCancel->enable();
305 }
306 
307 
308 void
310  activateFriendlyPositionAndSave->disable();
311  fixPositionsAndSave->disable();
312  saveInvalid->disable();
313  selectInvalidStopsAndCancel->disable();
314 }
315 
316 // ---------------------------------------------------------------------------
317 // GNEFixAdditionalElements::ConsecutiveLaneOptions - methods
318 // ---------------------------------------------------------------------------
319 
321  FXGroupBoxModule(fixAdditionalPositions->myMainFrame, "Select a solution for Multilane E2 detectors", FXGroupBoxModule::Options::NOTHING) {
322  // create horizontal frames for radio buttons
323  FXHorizontalFrame* RadioButtons = new FXHorizontalFrame(this, 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 
383 /****************************************************************************/
FXDEFMAP(GNEFixAdditionalElements) GNEFixAdditionalElementsMap[]
@ MID_GNE_BUTTON_CANCEL
cancel button
Definition: GUIAppEnum.h:1193
@ MID_CHOOSEN_OPERATION
set type of selection
Definition: GUIAppEnum.h:551
@ MID_GNE_FIXSTOPPINGPLACES_CHANGE
FixStoppingPlaces dialog.
Definition: GUIAppEnum.h:1290
@ MID_GNE_BUTTON_ACCEPT
accept button
Definition: GUIAppEnum.h:1191
#define GUIDesignDialogBoxExplicit(width, height)
design for dialog box with specift width and height (for example, additional dialogs)
Definition: GUIDesigns.h:539
#define GUIDesignTableAdditionals
design for tables used in additional dialogs
Definition: GUIDesigns.h:559
#define GUIDesignButtonAccept
Accept Button.
Definition: GUIDesigns.h:127
#define GUIDesignButtonCancel
Cancel Button.
Definition: GUIDesigns.h:130
#define GUIDesignHeight
define a standard height for all elements (Change it carefully)
Definition: GUIDesigns.h:37
#define GUIDesignAuxiliarHorizontalFrame
design for auxiliar (Without borders) horizontal frame used to pack another frames
Definition: GUIDesigns.h:343
#define GUIDesignVerticalSeparator
vertical separator
Definition: GUIDesigns.h:398
#define GUIDesignAuxiliarVerticalFrame
design for auxiliar (Without borders) horizontal frame used to pack another frames
Definition: GUIDesigns.h:346
#define GUIDesignGroupBoxFrameFill
Group box design extended over frame (X and Y)
Definition: GUIDesigns.h:311
#define GUIDesignRadioButton
Definition: GUIDesigns.h:179
#define GUIDesignAuxiliarFrame
design for auxiliar (Without borders) frames used to pack another frames extended in all directions
Definition: GUIDesigns.h:340
#define GUIDesignHorizontalFrame
Definition: GUIDesigns.h:293
@ GNE_ATTR_SELECTED
element is selected
@ SUMO_ATTR_FRIENDLY_POS
@ SUMO_ATTR_ID
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:46
FXGroupBoxModule (based on FXGroupBox)
Options
GroupBoxModule options.
An Element which don't belongs to GNENet but has influency in the simulation.
Definition: GNEAdditional.h:48
std::vector< GNEAdditional * > myInvalidMultiLaneAdditionals
vector with the invalid multi-lane additionals
AdditionalList(GNEFixAdditionalElements *fixAdditionalPositions, const std::vector< GNEAdditional * > &invalidSingleLaneAdditionals, const std::vector< GNEAdditional * > &invalidMultiLaneAdditionals)
constructor
FXTable * myTable
list with the stoppingPlaces and detectors
std::vector< GNEAdditional * > myInvalidSingleLaneAdditionals
vector with the invalid single-lane additionals
groupbox for group all radio buttons related to additionals with consecutive lanes
FXRadioButton * activateFriendlyPositionAndSave
Option "Activate friendlyPos and save".
ConsecutiveLaneOptions(GNEFixAdditionalElements *fixAdditionalPositions)
build consecutive lane Options
FXRadioButton * removeInvalidElements
Option "remove invalid elements".
FXRadioButton * fixPositionsAndSave
Option "Fix Positions and save".
FXRadioButton * buildConnectionBetweenLanes
Option "build connections between lanes".
void disableConsecutiveLaneOptions()
disable consecutive lane options
void enableConsecutiveLaneOptions()
enable consecutive lane options
groupbox for group all radio buttons related to additionals with single lanes
FXRadioButton * fixPositionsAndSave
Option "Fix Positions and save".
FXRadioButton * selectInvalidStopsAndCancel
Option "Select invalid stops and cancel".
FXRadioButton * activateFriendlyPositionAndSave
Option "Activate friendlyPos and save".
void disablePositionOptions()
disable position options
PositionOptions(GNEFixAdditionalElements *fixAdditionalPositions)
build Position Options
void selectOption(FXObject *option)
select option
FXRadioButton * saveInvalid
Option "Save invalid".
Dialog for edit rerouters.
PositionOptions * myPositionOptions
position options
long onCmdSelectOption(FXObject *obj, FXSelector, void *)
ConsecutiveLaneOptions * myConsecutiveLaneOptions
consecutive lane options
long onCmdCancel(FXObject *, FXSelector, void *)
event after press cancel button
AdditionalList * myAdditionalList
Additional List.
FXVerticalFrame * myMainFrame
main
long onCmdAccept(FXObject *, FXSelector, void *)
event after press accept button
void deleteAdditional(GNEAdditional *additional, GNEUndoList *undoList)
remove additional
Definition: GNENet.cpp:579
void end()
End undo command sub-group. If the sub-group is still empty, it will be deleted; otherwise,...
void begin(GUIIcon icon, const std::string &description)
Begin undo command sub-group with current supermode. This begins a new group of commands that are tre...
GNENet * getNet() const
get the net object
GNEUndoList * getUndoList() const
get the undoList object
static FXIcon * getIcon(const GUIIcon which)
returns a icon previously defined in the enum GUIIcon