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.dev/sumo
3 // Copyright (C) 2001-2024 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 
23 #include <netedit/GNENet.h>
24 #include <netedit/GNEViewNet.h>
25 #include <netedit/GNEUndoList.h>
26 
28 
29 
30 // ===========================================================================
31 // FOX callback mapping
32 // ===========================================================================
33 
34 FXDEFMAP(GNEFixAdditionalElements) GNEFixAdditionalElementsMap[] = {
38 };
39 
40 // Object implementation
41 FXIMPLEMENT(GNEFixAdditionalElements, FXDialogBox, GNEFixAdditionalElementsMap, ARRAYNUMBER(GNEFixAdditionalElementsMap))
42 
43 // ===========================================================================
44 // member method definitions
45 // ===========================================================================
46 
47 GNEFixAdditionalElements::GNEFixAdditionalElements(GNEViewNet* viewNet, const std::vector<GNEAdditional*>& invalidSingleLaneAdditionals, const std::vector<GNEAdditional*>& invalidMultiLaneAdditionals) :
48  FXDialogBox(viewNet->getApp(), ("Fix additional problems"), GUIDesignDialogBoxExplicitStretchable(500, 380)),
49  myViewNet(viewNet) {
50  // set busStop icon for this dialog
52  // create main frame
53  myMainFrame = new FXVerticalFrame(this, GUIDesignAuxiliarFrame);
54  // create AdditionalList
55  myAdditionalList = new AdditionalList(this, invalidSingleLaneAdditionals, invalidMultiLaneAdditionals);
56  // create position options
57  myPositionOptions = new PositionOptions(this);
58  // create consecutive lane options
59  myConsecutiveLaneOptions = new ConsecutiveLaneOptions(this);
60  // check if position options has to be disabled
61  if (myAdditionalList->myInvalidSingleLaneAdditionals.empty()) {
62  myPositionOptions->disablePositionOptions();
63  }
64  // check if consecutive lane options has to be disabled
65  if (myAdditionalList->myInvalidMultiLaneAdditionals.empty()) {
66  myConsecutiveLaneOptions->disableConsecutiveLaneOptions();
67  }
68  // create dialog buttons bot centered
69  FXHorizontalFrame* buttonsFrame = new FXHorizontalFrame(myMainFrame, GUIDesignHorizontalFrame);
70  new FXHorizontalFrame(buttonsFrame, GUIDesignAuxiliarHorizontalFrame);
71  myAcceptButton = GUIDesigns::buildFXButton(buttonsFrame, TL("&Accept"), "", "", GUIIconSubSys::getIcon(GUIIcon::ACCEPT), this, MID_GNE_BUTTON_ACCEPT, GUIDesignButtonAccept);
72  myCancelButton = GUIDesigns::buildFXButton(buttonsFrame, TL("&Cancel"), "", "", GUIIconSubSys::getIcon(GUIIcon::CANCEL), this, MID_GNE_BUTTON_CANCEL, GUIDesignButtonCancel);
73  new FXHorizontalFrame(buttonsFrame, GUIDesignAuxiliarHorizontalFrame);
74  // set focus in accept button
75  myAcceptButton->setFocus();
76 }
77 
78 
80 }
81 
82 
83 long
84 GNEFixAdditionalElements::onCmdSelectOption(FXObject* obj, FXSelector, void*) {
87  return 1;
88 }
89 
90 
91 long
92 GNEFixAdditionalElements::onCmdAccept(FXObject*, FXSelector, void*) {
93  bool continueSaving = true;
94  // first check options from single lane additionals
96  if (myPositionOptions->activateFriendlyPositionAndSave->getCheck() == TRUE) {
98  "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  }
103  myViewNet->getUndoList()->end();
104  } else if (myPositionOptions->fixPositionsAndSave->getCheck() == TRUE) {
106  "fix positions of invalid additionals");
107  // iterate over invalid single lane elements to fix positions
109  i->fixAdditionalProblem();
110  }
111  myViewNet->getUndoList()->end();
112  } else if (myPositionOptions->selectInvalidStopsAndCancel->getCheck() == TRUE) {
114  "select invalid additionals");
115  // iterate over invalid single lane elements to select all elements
117  i->setAttribute(GNE_ATTR_SELECTED, "true", myViewNet->getUndoList());
118  }
119  myViewNet->getUndoList()->end();
120  // abort saving
121  continueSaving = false;
122  }
123  }
124  // now check options from multi lane additionals
127  "fix multilane additionals problems");
128  // fix problems of consecutive lanes
129  if (myConsecutiveLaneOptions->buildConnectionBetweenLanes->getCheck() == TRUE) {
130  // iterate over invalid single lane elements to enable friendly position
132  i->fixAdditionalProblem();
133  }
134  // we need to check if after first fix there is still Invalid MultiL-ane Additionals with errors
135  auto copyOfInvalidMultiLaneAdditionals = myAdditionalList->myInvalidMultiLaneAdditionals;
137  for (auto i : copyOfInvalidMultiLaneAdditionals) {
138  if (!i->isAdditionalValid()) {
140  }
141  }
142  } else if (myConsecutiveLaneOptions->removeInvalidElements->getCheck() == TRUE) {
143  // iterate over invalid single lane elements to fix positions
146  }
147  // clear myInvalidMultiLaneAdditionals due there isn't more invalid multi lane additionals
149  }
150  // fix problem of positions
151  if (myPositionOptions->activateFriendlyPositionAndSave->getCheck() == TRUE) {
152  // iterate over invalid single lane elements to enable friendly position
154  i->setAttribute(SUMO_ATTR_FRIENDLY_POS, "true", myViewNet->getUndoList());
155  }
156  } else if (myPositionOptions->fixPositionsAndSave->getCheck() == TRUE) {
157  // iterate over invalid single lane elements to fix positions
159  i->fixAdditionalProblem();
160  }
161  }
162  myViewNet->getUndoList()->end();
163  }
164  if (continueSaving) {
165  // stop modal with TRUE (continue saving)
166  getApp()->stopModal(this, TRUE);
167  } else {
168  // stop modal with TRUE (abort saving)
169  getApp()->stopModal(this, FALSE);
170  }
171  return 1;
172 }
173 
174 
175 long
176 GNEFixAdditionalElements::onCmdCancel(FXObject*, FXSelector, void*) {
177  // Stop Modal (abort saving)
178  getApp()->stopModal(this, FALSE);
179  return 1;
180 }
181 
182 // ---------------------------------------------------------------------------
183 // GNEFixDemandElements::DemandList - methods
184 // ---------------------------------------------------------------------------
185 
186 GNEFixAdditionalElements::AdditionalList::AdditionalList(GNEFixAdditionalElements* fixAdditionalPositions, const std::vector<GNEAdditional*>& invalidSingleLaneAdditionals, const std::vector<GNEAdditional*>& invalidMultiLaneAdditionals) :
187  FXGroupBox(fixAdditionalPositions->myMainFrame, "Stopping places and E2 detectors with conflicts", GUIDesignGroupBoxFrameFill),
188  myInvalidSingleLaneAdditionals(invalidSingleLaneAdditionals),
189  myInvalidMultiLaneAdditionals(invalidMultiLaneAdditionals) {
190  // Create table, copy intervals and update table
192  myTable->setSelBackColor(FXRGBA(255, 255, 255, 255));
193  myTable->setSelTextColor(FXRGBA(0, 0, 0, 255));
194  myTable->setEditable(false);
195  // clear table
196  myTable->clearItems();
197  // set number of rows
198  myTable->setTableSize(int(myInvalidSingleLaneAdditionals.size() + myInvalidMultiLaneAdditionals.size()), 3);
199  // Configure list
200  myTable->setVisibleColumns(4);
201  myTable->setColumnWidth(0, GUIDesignHeight);
202  myTable->setColumnWidth(1, 160);
203  myTable->setColumnWidth(2, 280);
204  myTable->setColumnText(0, "");
205  myTable->setColumnText(1, toString(SUMO_ATTR_ID).c_str());
206  myTable->setColumnText(2, "Conflict");
207  myTable->getRowHeader()->setWidth(0);
208  // Declare index for rows and pointer to FXTableItem
209  int indexRow = 0;
210  FXTableItem* item = nullptr;
211  // iterate over single lane additionals
212  for (auto i : myInvalidSingleLaneAdditionals) {
213  // Set icon
214  item = new FXTableItem("", i->getACIcon());
215  item->setIconPosition(FXTableItem::CENTER_X);
216  myTable->setItem(indexRow, 0, item);
217  // Set ID
218  item = new FXTableItem(i->getID().c_str());
219  item->setJustify(FXTableItem::LEFT | FXTableItem::CENTER_Y);
220  myTable->setItem(indexRow, 1, item);
221  // Set conflict
222  item = new FXTableItem(i->getAdditionalProblem().c_str());
223  item->setJustify(FXTableItem::LEFT | FXTableItem::CENTER_Y);
224  myTable->setItem(indexRow, 2, item);
225  // Update index
226  indexRow++;
227  }
228  // iterate over multi lane additionals
229  for (auto i : myInvalidMultiLaneAdditionals) {
230  // Set icon
231  item = new FXTableItem("", i->getACIcon());
232  item->setIconPosition(FXTableItem::CENTER_X);
233  myTable->setItem(indexRow, 0, item);
234  // Set ID
235  item = new FXTableItem(i->getID().c_str());
236  item->setJustify(FXTableItem::LEFT | FXTableItem::CENTER_Y);
237  myTable->setItem(indexRow, 1, item);
238  // set conflict
239  item = new FXTableItem((i->getAdditionalProblem()).c_str());
240  item->setJustify(FXTableItem::LEFT | FXTableItem::CENTER_Y);
241  myTable->setItem(indexRow, 2, item);
242  // Update index
243  indexRow++;
244  }
245 }
246 
247 // ---------------------------------------------------------------------------
248 // GNEFixAdditionalElements::PositionOptions - methods
249 // ---------------------------------------------------------------------------
250 
252  MFXGroupBoxModule(fixAdditionalPositions->myMainFrame, "Select a solution for StoppingPlaces and E2 detectors") {
253  // create horizontal frames for radio buttons
254  FXHorizontalFrame* RadioButtons = new FXHorizontalFrame(this, GUIDesignHorizontalFrame);
255  // create Vertical Frame for left options
256  FXVerticalFrame* RadioButtonsLeft = new FXVerticalFrame(RadioButtons, GUIDesignAuxiliarVerticalFrame);
257  activateFriendlyPositionAndSave = GUIDesigns::buildFXRadioButton(RadioButtonsLeft, TL("Activate friendlyPos and save"), "", TL("Friendly pos parameter will be activated in all stopping places and E2 detectors"),
258  fixAdditionalPositions, MID_CHOOSEN_OPERATION, GUIDesignRadioButton);
259  saveInvalid = GUIDesigns::buildFXRadioButton(RadioButtonsLeft, TL("Save invalid positions"), "", TL("Save stopping places and E2 detectors with invalid positions"),
260  fixAdditionalPositions, MID_CHOOSEN_OPERATION, GUIDesignRadioButton);
261  // create Vertical Frame for right options
262  FXVerticalFrame* RadioButtonsRight = new FXVerticalFrame(RadioButtons, GUIDesignAuxiliarVerticalFrame);
263  fixPositionsAndSave = GUIDesigns::buildFXRadioButton(RadioButtonsRight, TL("Fix positions and save"), "", TL("Position of stopping places and E2 detectors will be fixed"),
264  fixAdditionalPositions, MID_CHOOSEN_OPERATION, GUIDesignRadioButton);
265  selectInvalidStopsAndCancel = GUIDesigns::buildFXRadioButton(RadioButtonsRight, TL("Select invalid additionals"), "", TL("Cancel saving of additionals and select invalid stopping places and E2 detectors"),
266  fixAdditionalPositions, MID_CHOOSEN_OPERATION, GUIDesignRadioButton);
267  // leave option "activateFriendlyPositionAndSave" as default
268  activateFriendlyPositionAndSave->setCheck(true);
269 }
270 
271 
272 void
274  if (option == activateFriendlyPositionAndSave) {
275  activateFriendlyPositionAndSave->setCheck(true);
276  fixPositionsAndSave->setCheck(false);
277  saveInvalid->setCheck(false);
278  selectInvalidStopsAndCancel->setCheck(false);
279  } else if (option == fixPositionsAndSave) {
280  activateFriendlyPositionAndSave->setCheck(false);
281  fixPositionsAndSave->setCheck(true);
282  saveInvalid->setCheck(false);
283  selectInvalidStopsAndCancel->setCheck(false);
284  } else if (option == saveInvalid) {
285  activateFriendlyPositionAndSave->setCheck(false);
286  fixPositionsAndSave->setCheck(false);
287  saveInvalid->setCheck(true);
288  selectInvalidStopsAndCancel->setCheck(false);
289  } else if (option == selectInvalidStopsAndCancel) {
290  activateFriendlyPositionAndSave->setCheck(false);
291  fixPositionsAndSave->setCheck(false);
292  saveInvalid->setCheck(false);
293  selectInvalidStopsAndCancel->setCheck(true);
294  }
295 }
296 
297 
298 void
300  activateFriendlyPositionAndSave->enable();
301  fixPositionsAndSave->enable();
302  saveInvalid->enable();
303  selectInvalidStopsAndCancel->enable();
304 }
305 
306 
307 void
309  activateFriendlyPositionAndSave->disable();
310  fixPositionsAndSave->disable();
311  saveInvalid->disable();
312  selectInvalidStopsAndCancel->disable();
313 }
314 
315 // ---------------------------------------------------------------------------
316 // GNEFixAdditionalElements::ConsecutiveLaneOptions - methods
317 // ---------------------------------------------------------------------------
318 
320  MFXGroupBoxModule(fixAdditionalPositions->myMainFrame, "Select a solution for Multilane E2 detectors") {
321  // create horizontal frames for radio buttons
322  FXHorizontalFrame* RadioButtons = new FXHorizontalFrame(this, GUIDesignHorizontalFrame);
323  // create Vertical Frame for left options
324  FXVerticalFrame* RadioButtonsLeft = new FXVerticalFrame(RadioButtons, GUIDesignAuxiliarVerticalFrame);
325  buildConnectionBetweenLanes = GUIDesigns::buildFXRadioButton(RadioButtonsLeft, TL("Build connections between lanes"), "", TL("New connections will be created between non-connected lanes"),
326  fixAdditionalPositions, MID_CHOOSEN_OPERATION, GUIDesignRadioButton);
327  removeInvalidElements = GUIDesigns::buildFXRadioButton(RadioButtonsLeft, TL("Remove invalid E2 detectors"), "", TL("Remove Multilane E2 Detectors with non-connected lanes"),
328  fixAdditionalPositions, MID_CHOOSEN_OPERATION, GUIDesignRadioButton);
329  // add a vertical separator between both options
330  new FXVerticalSeparator(RadioButtons, GUIDesignVerticalSeparator);
331  // create Vertical Frame for right options
332  FXVerticalFrame* RadioButtonsRight = new FXVerticalFrame(RadioButtons, GUIDesignAuxiliarVerticalFrame);
333  activateFriendlyPositionAndSave = GUIDesigns::buildFXRadioButton(RadioButtonsRight, TL("Activate friendlyPos and save"), "", TL("Friendly pos parameter will be activated in all stopping places and E2 detectors"),
334  fixAdditionalPositions, MID_CHOOSEN_OPERATION, GUIDesignRadioButton);
335  fixPositionsAndSave = GUIDesigns::buildFXRadioButton(RadioButtonsRight, TL("Fix positions and save"), "", TL("Position of stopping places and E2 detectors will be fixed"),
336  fixAdditionalPositions, MID_CHOOSEN_OPERATION, GUIDesignRadioButton);
337  // leave option "buildConnectionBetweenLanes" and "activateFriendlyPositionAndSave" as default
338  buildConnectionBetweenLanes->setCheck(true);
339  activateFriendlyPositionAndSave->setCheck(true);
340 }
341 
342 
343 void
345  // set top buttons
346  if (option == buildConnectionBetweenLanes) {
347  buildConnectionBetweenLanes->setCheck(true);
348  removeInvalidElements->setCheck(false);
349  } else if (option == removeInvalidElements) {
350  buildConnectionBetweenLanes->setCheck(false);
351  removeInvalidElements->setCheck(true);
352  }
353  // set down buttons
354  if (option == activateFriendlyPositionAndSave) {
355  activateFriendlyPositionAndSave->setCheck(true);
356  fixPositionsAndSave->setCheck(false);
357  } else if (option == fixPositionsAndSave) {
358  activateFriendlyPositionAndSave->setCheck(false);
359  fixPositionsAndSave->setCheck(true);
360  }
361 }
362 
363 
364 void
366  buildConnectionBetweenLanes->enable();
367  removeInvalidElements->enable();
368  activateFriendlyPositionAndSave->enable();
369  fixPositionsAndSave->enable();
370 }
371 
372 
373 void
375  buildConnectionBetweenLanes->disable();
376  removeInvalidElements->disable();
377  activateFriendlyPositionAndSave->disable();
378  fixPositionsAndSave->disable();
379 }
380 
381 
382 /****************************************************************************/
FXDEFMAP(GNEFixAdditionalElements) GNEFixAdditionalElementsMap[]
@ MID_GNE_BUTTON_CANCEL
cancel button
Definition: GUIAppEnum.h:1394
@ MID_CHOOSEN_OPERATION
set type of selection
Definition: GUIAppEnum.h:593
@ MID_GNE_FIXSTOPPINGPLACES_CHANGE
FixStoppingPlaces dialog.
Definition: GUIAppEnum.h:1509
@ MID_GNE_BUTTON_ACCEPT
accept button
Definition: GUIAppEnum.h:1392
#define GUIDesignTableAdditionals
design for tables used in additional dialogs
Definition: GUIDesigns.h:637
#define GUIDesignButtonAccept
Accept Button.
Definition: GUIDesigns.h:162
#define GUIDesignButtonCancel
Cancel Button.
Definition: GUIDesigns.h:168
#define GUIDesignAuxiliarHorizontalFrame
design for auxiliar (Without borders) horizontal frame used to pack another frames
Definition: GUIDesigns.h:405
#define GUIDesignVerticalSeparator
vertical separator
Definition: GUIDesigns.h:469
#define GUIDesignAuxiliarVerticalFrame
design for auxiliar (Without borders) horizontal frame used to pack another frames
Definition: GUIDesigns.h:411
#define GUIDesignGroupBoxFrameFill
Group box design extended over frame (X and Y)
Definition: GUIDesigns.h:355
#define GUIDesignRadioButton
Definition: GUIDesigns.h:235
#define GUIDesignAuxiliarFrame
design for auxiliar (Without borders) frame extended in all directions
Definition: GUIDesigns.h:396
#define GUIDesignHorizontalFrame
Horizontal frame extended over frame parent with padding and spacing.
Definition: GUIDesigns.h:334
#define GUIDesignDialogBoxExplicitStretchable(width, height)
design for dialog box with specific width and height that can be stretched (But not shrunk)
Definition: GUIDesigns.h:620
#define TL(string)
Definition: MsgHandler.h:315
@ GNE_ATTR_SELECTED
element is selected
@ SUMO_ATTR_FRIENDLY_POS
@ SUMO_ATTR_ID
int GUIDesignHeight
the default size for GUI elements
Definition: StdDefs.cpp:34
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:46
An Element which don't belong to GNENet but has influence in the simulation.
Definition: GNEAdditional.h:49
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:650
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 FXButton * buildFXButton(FXComposite *p, const std::string &text, const std::string &tip, const std::string &help, FXIcon *ic, FXObject *tgt, FXSelector sel, FXuint opts=BUTTON_NORMAL, FXint x=0, FXint y=0, FXint w=0, FXint h=0, FXint pl=DEFAULT_PAD, FXint pr=DEFAULT_PAD, FXint pt=DEFAULT_PAD, FXint pb=DEFAULT_PAD)
build button
Definition: GUIDesigns.cpp:128
static FXRadioButton * buildFXRadioButton(FXComposite *p, const std::string &text, const std::string &tip, const std::string &help, FXObject *tgt, FXSelector sel, FXuint opts=RADIOBUTTON_NORMAL, FXint x=0, FXint y=0, FXint w=0, FXint h=0, FXint pl=DEFAULT_PAD, FXint pr=DEFAULT_PAD, FXint pt=DEFAULT_PAD, FXint pb=DEFAULT_PAD)
build radio button
Definition: GUIDesigns.cpp:138
static FXIcon * getIcon(const GUIIcon which)
returns a icon previously defined in the enum GUIIcon
MFXGroupBoxModule (based on FXGroupBox)
Definition: json.hpp:4471