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