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-2020 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()->p_begin("change " + toString(SUMO_ATTR_FRIENDLY_POS) + " of invalid additionals");
99  // iterate over invalid single lane elements to enable friendly position
101  i->setAttribute(SUMO_ATTR_FRIENDLY_POS, "true", myViewNet->getUndoList());
102  }
104  } else if (myPositionOptions->fixPositionsAndSave->getCheck() == TRUE) {
105  myViewNet->getUndoList()->p_begin("fix positions of invalid additionals");
106  // iterate over invalid single lane elements to fix positions
108  i->fixAdditionalProblem();
109  }
111  } else if (myPositionOptions->selectInvalidStopsAndCancel->getCheck() == TRUE) {
112  myViewNet->getUndoList()->p_begin("select invalid additionals");
113  // iterate over invalid single lane elements to select all elements
115  i->setAttribute(GNE_ATTR_SELECTED, "true", myViewNet->getUndoList());
116  }
118  // abort saving
119  continueSaving = false;
120  }
121  }
122  // now check options from multi lane additionals
124  myViewNet->getUndoList()->p_begin("fix multilane additionals problems");
125  // fix problems of consecutive lanes
126  if (myConsecutiveLaneOptions->buildConnectionBetweenLanes->getCheck() == TRUE) {
127  // iterate over invalid single lane elements to enable friendly position
129  i->fixAdditionalProblem();
130  }
131  // we need to check if after first fix there is still Invalid MultiL-ane Additionals with errors
132  auto copyOfInvalidMultiLaneAdditionals = myAdditionalList->myInvalidMultiLaneAdditionals;
134  for (auto i : copyOfInvalidMultiLaneAdditionals) {
135  if (!i->isAdditionalValid()) {
137  }
138  }
139  } else if (myConsecutiveLaneOptions->removeInvalidElements->getCheck() == TRUE) {
140  // iterate over invalid single lane elements to fix positions
143  }
144  // clear myInvalidMultiLaneAdditionals due there isn't more invalid multi lane additionals
146  }
147  // fix problem of positions
148  if (myPositionOptions->activateFriendlyPositionAndSave->getCheck() == TRUE) {
149  // iterate over invalid single lane elements to enable friendly position
151  i->setAttribute(SUMO_ATTR_FRIENDLY_POS, "true", myViewNet->getUndoList());
152  }
153  } else if (myPositionOptions->fixPositionsAndSave->getCheck() == TRUE) {
154  // iterate over invalid single lane elements to fix positions
156  i->fixAdditionalProblem();
157  }
158  }
160  }
161  if (continueSaving) {
162  // stop modal with TRUE (continue saving)
163  getApp()->stopModal(this, TRUE);
164  } else {
165  // stop modal with TRUE (abort saving)
166  getApp()->stopModal(this, FALSE);
167  }
168  return 1;
169 }
170 
171 
172 long
173 GNEFixAdditionalElements::onCmdCancel(FXObject*, FXSelector, void*) {
174  // Stop Modal (abort saving)
175  getApp()->stopModal(this, FALSE);
176  return 1;
177 }
178 
179 // ---------------------------------------------------------------------------
180 // GNEFixDemandElements::DemandList - methods
181 // ---------------------------------------------------------------------------
182 
183 GNEFixAdditionalElements::AdditionalList::AdditionalList(GNEFixAdditionalElements* fixAdditionalPositions, const std::vector<GNEAdditional*>& invalidSingleLaneAdditionals, const std::vector<GNEAdditional*>& invalidMultiLaneAdditionals) :
184  FXGroupBox(fixAdditionalPositions->myMainFrame, "Stopping places and E2 detectors with conflicts", GUIDesignGroupBoxFrameFill),
185  myInvalidSingleLaneAdditionals(invalidSingleLaneAdditionals),
186  myInvalidMultiLaneAdditionals(invalidMultiLaneAdditionals) {
187  // Create table, copy intervals and update table
189  myTable->setSelBackColor(FXRGBA(255, 255, 255, 255));
190  myTable->setSelTextColor(FXRGBA(0, 0, 0, 255));
191  myTable->setEditable(false);
192  // clear table
193  myTable->clearItems();
194  // set number of rows
195  myTable->setTableSize(int(myInvalidSingleLaneAdditionals.size() + myInvalidMultiLaneAdditionals.size()), 3);
196  // Configure list
197  myTable->setVisibleColumns(4);
198  myTable->setColumnWidth(0, GUIDesignHeight);
199  myTable->setColumnWidth(1, 160);
200  myTable->setColumnWidth(2, 280);
201  myTable->setColumnText(0, "");
202  myTable->setColumnText(1, toString(SUMO_ATTR_ID).c_str());
203  myTable->setColumnText(2, "Conflict");
204  myTable->getRowHeader()->setWidth(0);
205  // Declare index for rows and pointer to FXTableItem
206  int indexRow = 0;
207  FXTableItem* item = nullptr;
208  // iterate over single lane additionals
209  for (auto i : myInvalidSingleLaneAdditionals) {
210  // Set icon
211  item = new FXTableItem("", i->getIcon());
212  item->setIconPosition(FXTableItem::CENTER_X);
213  myTable->setItem(indexRow, 0, item);
214  // Set ID
215  item = new FXTableItem(i->getID().c_str());
216  item->setJustify(FXTableItem::LEFT | FXTableItem::CENTER_Y);
217  myTable->setItem(indexRow, 1, item);
218  // Set conflict
219  item = new FXTableItem(i->getAdditionalProblem().c_str());
220  item->setJustify(FXTableItem::LEFT | FXTableItem::CENTER_Y);
221  myTable->setItem(indexRow, 2, item);
222  // Update index
223  indexRow++;
224  }
225  // iterate over multi lane additionals
226  for (auto i : myInvalidMultiLaneAdditionals) {
227  // Set icon
228  item = new FXTableItem("", i->getIcon());
229  item->setIconPosition(FXTableItem::CENTER_X);
230  myTable->setItem(indexRow, 0, item);
231  // Set ID
232  item = new FXTableItem(i->getID().c_str());
233  item->setJustify(FXTableItem::LEFT | FXTableItem::CENTER_Y);
234  myTable->setItem(indexRow, 1, item);
235  // set conflict
236  item = new FXTableItem((i->getAdditionalProblem()).c_str());
237  item->setJustify(FXTableItem::LEFT | FXTableItem::CENTER_Y);
238  myTable->setItem(indexRow, 2, item);
239  // Update index
240  indexRow++;
241  }
242 }
243 
244 // ---------------------------------------------------------------------------
245 // GNEFixAdditionalElements::PositionOptions - methods
246 // ---------------------------------------------------------------------------
247 
249  FXGroupBox(fixAdditionalPositions->myMainFrame, "Select a solution for StoppingPlaces and E2 detectors", GUIDesignGroupBoxFrame) {
250  // create horizontal frames for radio buttons
251  FXHorizontalFrame* RadioButtons = new FXHorizontalFrame(this, GUIDesignHorizontalFrame);
252  // create Vertical Frame for left options
253  FXVerticalFrame* RadioButtonsLeft = new FXVerticalFrame(RadioButtons, GUIDesignAuxiliarVerticalFrame);
254  activateFriendlyPositionAndSave = new FXRadioButton(RadioButtonsLeft, "Activate friendlyPos and save\t\tFriendly pos parameter will be activated in all stopping places and E2 detectors",
255  fixAdditionalPositions, MID_CHOOSEN_OPERATION, GUIDesignRadioButton);
256  saveInvalid = new FXRadioButton(RadioButtonsLeft, "Save invalid positions\t\tSave stopping places and E2 detectors with invalid positions",
257  fixAdditionalPositions, MID_CHOOSEN_OPERATION, GUIDesignRadioButton);
258  // create Vertical Frame for right options
259  FXVerticalFrame* RadioButtonsRight = new FXVerticalFrame(RadioButtons, GUIDesignAuxiliarVerticalFrame);
260  fixPositionsAndSave = new FXRadioButton(RadioButtonsRight, "Fix positions and save\t\tPosition of stopping places and E2 detectors will be fixed",
261  fixAdditionalPositions, MID_CHOOSEN_OPERATION, GUIDesignRadioButton);
262  selectInvalidStopsAndCancel = new FXRadioButton(RadioButtonsRight, "Select invalid additionals\t\tCancel saving of additionals and select invalid stopping places and E2 detectors",
263  fixAdditionalPositions, MID_CHOOSEN_OPERATION, GUIDesignRadioButton);
264  // leave option "activateFriendlyPositionAndSave" as default
265  activateFriendlyPositionAndSave->setCheck(true);
266 }
267 
268 
269 void
271  if (option == activateFriendlyPositionAndSave) {
272  activateFriendlyPositionAndSave->setCheck(true);
273  fixPositionsAndSave->setCheck(false);
274  saveInvalid->setCheck(false);
275  selectInvalidStopsAndCancel->setCheck(false);
276  } else if (option == fixPositionsAndSave) {
277  activateFriendlyPositionAndSave->setCheck(false);
278  fixPositionsAndSave->setCheck(true);
279  saveInvalid->setCheck(false);
280  selectInvalidStopsAndCancel->setCheck(false);
281  } else if (option == saveInvalid) {
282  activateFriendlyPositionAndSave->setCheck(false);
283  fixPositionsAndSave->setCheck(false);
284  saveInvalid->setCheck(true);
285  selectInvalidStopsAndCancel->setCheck(false);
286  } else if (option == selectInvalidStopsAndCancel) {
287  activateFriendlyPositionAndSave->setCheck(false);
288  fixPositionsAndSave->setCheck(false);
289  saveInvalid->setCheck(false);
290  selectInvalidStopsAndCancel->setCheck(true);
291  }
292 }
293 
294 
295 void
297  activateFriendlyPositionAndSave->enable();
298  fixPositionsAndSave->enable();
299  saveInvalid->enable();
300  selectInvalidStopsAndCancel->enable();
301 }
302 
303 
304 void
306  activateFriendlyPositionAndSave->disable();
307  fixPositionsAndSave->disable();
308  saveInvalid->disable();
309  selectInvalidStopsAndCancel->disable();
310 }
311 
312 // ---------------------------------------------------------------------------
313 // GNEFixAdditionalElements::ConsecutiveLaneOptions - methods
314 // ---------------------------------------------------------------------------
315 
317  FXGroupBox(fixAdditionalPositions->myMainFrame, "Select a solution for Multilane E2 detectors", GUIDesignGroupBoxFrame) {
318  // create horizontal frames for radio buttons
319  FXHorizontalFrame* RadioButtons = new FXHorizontalFrame(this, GUIDesignHorizontalFrame);
320  // create Vertical Frame for left options
321  FXVerticalFrame* RadioButtonsLeft = new FXVerticalFrame(RadioButtons, GUIDesignAuxiliarVerticalFrame);
322  buildConnectionBetweenLanes = new FXRadioButton(RadioButtonsLeft, "Build connections between lanes\t\tNew connections will be created between non-connected lanes",
323  fixAdditionalPositions, MID_CHOOSEN_OPERATION, GUIDesignRadioButton);
324  removeInvalidElements = new FXRadioButton(RadioButtonsLeft, "Remove invalid E2 detectors\t\tRemove Multilane E2 Detectors with non-connected lanes",
325  fixAdditionalPositions, MID_CHOOSEN_OPERATION, GUIDesignRadioButton);
326  // add a vertical separator beween both options
327  new FXVerticalSeparator(RadioButtons, GUIDesignVerticalSeparator);
328  // create Vertical Frame for right options
329  FXVerticalFrame* RadioButtonsRight = new FXVerticalFrame(RadioButtons, GUIDesignAuxiliarVerticalFrame);
330  activateFriendlyPositionAndSave = new FXRadioButton(RadioButtonsRight, "Activate friendlyPos and save\t\tFriendly pos parameter will be activated in all stopping places and E2 detectors",
331  fixAdditionalPositions, MID_CHOOSEN_OPERATION, GUIDesignRadioButton);
332  fixPositionsAndSave = new FXRadioButton(RadioButtonsRight, "Fix positions and save\t\tPosition of stopping places and E2 detectors will be fixed",
333  fixAdditionalPositions, MID_CHOOSEN_OPERATION, GUIDesignRadioButton);
334  // leave option "buildConnectionBetweenLanes" and "activateFriendlyPositionAndSave" as default
335  buildConnectionBetweenLanes->setCheck(true);
336  activateFriendlyPositionAndSave->setCheck(true);
337 }
338 
339 
340 void
342  // set top buttons
343  if (option == buildConnectionBetweenLanes) {
344  buildConnectionBetweenLanes->setCheck(true);
345  removeInvalidElements->setCheck(false);
346  } else if (option == removeInvalidElements) {
347  buildConnectionBetweenLanes->setCheck(false);
348  removeInvalidElements->setCheck(true);
349  }
350  // set down buttons
351  if (option == activateFriendlyPositionAndSave) {
352  activateFriendlyPositionAndSave->setCheck(true);
353  fixPositionsAndSave->setCheck(false);
354  } else if (option == fixPositionsAndSave) {
355  activateFriendlyPositionAndSave->setCheck(false);
356  fixPositionsAndSave->setCheck(true);
357  }
358 }
359 
360 
361 void
363  buildConnectionBetweenLanes->enable();
364  removeInvalidElements->enable();
365  activateFriendlyPositionAndSave->enable();
366  fixPositionsAndSave->enable();
367 }
368 
369 
370 void
372  buildConnectionBetweenLanes->disable();
373  removeInvalidElements->disable();
374  activateFriendlyPositionAndSave->disable();
375  fixPositionsAndSave->disable();
376 }
377 
378 
379 /****************************************************************************/
FXDEFMAP(GNEFixAdditionalElements) GNEFixAdditionalElementsMap[]
@ MID_GNE_BUTTON_CANCEL
cancel button
Definition: GUIAppEnum.h:1094
@ MID_CHOOSEN_OPERATION
set type of selection
Definition: GUIAppEnum.h:535
@ MID_GNE_FIXSTOPPINGPLACES_CHANGE
FixStoppingPlaces dialog.
Definition: GUIAppEnum.h:1189
@ MID_GNE_BUTTON_ACCEPT
accept button
Definition: GUIAppEnum.h:1092
#define GUIDesignDialogBoxExplicit(width, height)
design for dialog box with specift width and height (for example, additional dialogs)
Definition: GUIDesigns.h:506
#define GUIDesignTableAdditionals
design for tables used in additional dialogs
Definition: GUIDesigns.h:526
#define GUIDesignButtonAccept
Accept Button.
Definition: GUIDesigns.h:118
#define GUIDesignButtonCancel
Cancel Button.
Definition: GUIDesigns.h:121
#define GUIDesignHeight
define a standard height for all elements (Change it carefully)
Definition: GUIDesigns.h:31
#define GUIDesignAuxiliarHorizontalFrame
design for auxiliar (Without borders) horizontal frame used to pack another frames
Definition: GUIDesigns.h:313
#define GUIDesignVerticalSeparator
vertical separator
Definition: GUIDesigns.h:365
#define GUIDesignGroupBoxFrame
Group box design extended over frame.
Definition: GUIDesigns.h:278
#define GUIDesignAuxiliarVerticalFrame
design for auxiliar (Without borders) horizontal frame used to pack another frames
Definition: GUIDesigns.h:316
#define GUIDesignGroupBoxFrameFill
Group box design extended over frame (X and Y)
Definition: GUIDesigns.h:281
#define GUIDesignRadioButton
Definition: GUIDesigns.h:164
#define GUIDesignAuxiliarFrame
design for auxiliar (Without borders) frames used to pack another frames extended in all directions
Definition: GUIDesigns.h:310
#define GUIDesignHorizontalFrame
Definition: GUIDesigns.h:263
@ 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:44
An Element which don't belongs to GNENet but has influency in the simulation.
Definition: GNEAdditional.h:47
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:527
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:71
void p_end()
End undo command sub-group. If the sub-group is still empty, it will be deleted; otherwise,...
Definition: GNEUndoList.cpp:78
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