Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
GNEFixDemandElementsDialog.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 demand elements during saving
19/****************************************************************************/
20
22#include <netedit/GNENet.h>
24#include <netedit/GNEUndoList.h>
25
27
28// ===========================================================================
29// FOX callback mapping
30// ===========================================================================
31
35
39
43
47
48// Object abstract implementation
49FXIMPLEMENT(GNEFixDemandElementsDialog::FixRouteOptions, MFXGroupBoxModule, FixRouteOptionsMap, ARRAYNUMBER(FixRouteOptionsMap))
50FXIMPLEMENT(GNEFixDemandElementsDialog::FixVehicleOptions, MFXGroupBoxModule, FixVehicleOptionsMap, ARRAYNUMBER(FixVehicleOptionsMap))
51FXIMPLEMENT(GNEFixDemandElementsDialog::FixStopPositionOptions, MFXGroupBoxModule, FixStopPositionOptionsMap, ARRAYNUMBER(FixStopPositionOptionsMap))
52FXIMPLEMENT(GNEFixDemandElementsDialog::FixPlanOptions, MFXGroupBoxModule, FixPlanOptionsMap, ARRAYNUMBER(FixPlanOptionsMap))
53
54// ===========================================================================
55// member method definitions
56// ===========================================================================
57
58// ---------------------------------------------------------------------------
59// GNEFixDemandElementsDialog::FixRouteOptions - methods
60// ---------------------------------------------------------------------------
61
63 FixOptions(fixDemandElementsParent, fixDemandElementsParent->myLeftFrame, TL("Routes")) {
64 // Remove invalid routes
65 myRemoveInvalidRoutes = GUIDesigns::buildFXRadioButton(myLeftFrameOptions,
66 TL("Remove invalid routes"), "",
67 TL("Remove invalid routes and save"),
69 // Save invalid routes
70 mySaveInvalidRoutes = GUIDesigns::buildFXRadioButton(myLeftFrameOptions,
71 TL("Save invalid routes"), "",
72 TL("Save invalid routes"),
74 // Select invalid routes
75 mySelectRouteInvalids = GUIDesigns::buildFXRadioButton(myRightFrameOptions,
76 TL("Select invalid routes"), "",
77 TL("Select invalid routes and stop saving"),
79 // Remove stops out of route
80 myRemoveStopsOutOfRoute = GUIDesigns::buildFXCheckButton(myRightFrameOptions,
81 TL("Remove stops out of route"), "",
82 TL("Remove stops out of route"),
84 // register options
85 registerOption(myRemoveInvalidRoutes);
86 registerOption(mySaveInvalidRoutes);
87 registerOption(mySelectRouteInvalids);
88 registerOption(myRemoveStopsOutOfRoute);
89 // leave option "removeInvalidRoutes" as default
90 myRemoveInvalidRoutes->setCheck(true);
91 // ... and remove stops out of route
92 myRemoveStopsOutOfRoute->setCheck(TRUE);
93}
94
95
96void
98 // choose solution
99 if (solution == "saveRouteInvalids") {
100 mySaveInvalidRoutes->setCheck(TRUE, TRUE);
101 } else if (solution == "removeRouteInvalids") {
102 myRemoveInvalidRoutes->setCheck(TRUE, TRUE);
103 } else if (solution == "selectRouteInvalids") {
104 mySelectRouteInvalids->setCheck(TRUE, TRUE);
105 }
106}
107
108
109bool
111 if (myConflictedElements.size() > 0) {
112 auto net = myFixElementDialogParent->getApplicationWindow()->getViewNet()->getNet();
113 auto undoList = myFixElementDialogParent->getApplicationWindow()->getUndoList();
114 // continue depending of solution
115 if (myRemoveInvalidRoutes->getCheck() == TRUE) {
116 // begin undo list
117 undoList->begin(GUIIcon::ROUTE, TL("delete invalid routes"));
118 // iterate over invalid routes to delete it
119 for (const auto& conflictedElement : myConflictedElements) {
120 // special case for embedded routes
121 if (conflictedElement.getElement()->getTagProperty()->getTag() == GNE_TAG_ROUTE_EMBEDDED) {
122 net->deleteDemandElement(conflictedElement.getElement()->getParentDemandElements().front(), undoList);
123 } else {
124 net->deleteDemandElement(conflictedElement.getElement(), undoList);
125 }
126 }
127 // end undo list
128 undoList->end();
129 } else if (mySelectRouteInvalids->getCheck() == TRUE) {
130 // begin undo list
131 undoList->begin(GUIIcon::ROUTE, TL("select invalid routes"));
132 // iterate over invalid single lane elements to select all elements
133 for (const auto& conflictedElement : myConflictedElements) {
134 conflictedElement.getElement()->setAttribute(GNE_ATTR_SELECTED, "true", undoList);
135 }
136 // end undo list
137 undoList->end();
138 // abort saving
139 return false;
140 }
141 // check if remove stops
142 if (myRemoveStopsOutOfRoute->getCheck() == TRUE) {
143 // get all stops to remove
144 std::vector<GNEDemandElement*> stopsToRemove;
145 for (const auto& conflictedElement : myConflictedElements) {
146 const auto invaldstops = conflictedElement.getElement()->getInvalidStops();
147 // append to stopsToRemove
148 stopsToRemove.insert(stopsToRemove.end(), invaldstops.begin(), invaldstops.end());
149 }
150 // begin undo list
151 undoList->begin(GUIIcon::STOP, TL("delete invalid stops"));
152 // remove all
153 for (const auto& stopToRemove : stopsToRemove) {
154 net->deleteDemandElement(stopToRemove, undoList);
155 }
156 // end undo list
157 undoList->end();
158 }
159 }
160 return true;
161}
162
163
164long
166 if (obj == myRemoveInvalidRoutes) {
167 myRemoveInvalidRoutes->setCheck(true);
168 mySaveInvalidRoutes->setCheck(false);
169 mySelectRouteInvalids->setCheck(false);
170 } else if (obj == mySaveInvalidRoutes) {
171 myRemoveInvalidRoutes->setCheck(false);
172 mySaveInvalidRoutes->setCheck(true);
173 mySelectRouteInvalids->setCheck(false);
174 } else if (obj == mySelectRouteInvalids) {
175 myRemoveInvalidRoutes->setCheck(false);
176 mySaveInvalidRoutes->setCheck(false);
177 mySelectRouteInvalids->setCheck(true);
178 }
179 return 1;
180}
181
182// ---------------------------------------------------------------------------
183// GNEFixDemandElementsDialog::FixVehicleOptions - methods
184// ---------------------------------------------------------------------------
185
187 FixOptions(fixDemandElementsParent, fixDemandElementsParent->myLeftFrame, TL("Vehicles")) {
188 // Remove invalid vehicles
190 TL("Remove invalid vehicles"), "",
191 TL("Remove invalid vehicles and save"),
193 // Save invalid vehicles
195 TL("Save invalid vehicles"), "",
196 TL("Save invalid vehicles"),
198 // Select invalid vehicle
200 TL("Select invalid vehicles"), "",
201 TL("Select invalid vehicles and stop saving"),
203 // Remove stops out of route
205 TL("Remove stops out of route"), "",
206 TL("Remove stops out of vehicle's route"),
208 // register options
213 // by default remove invalid vehicles
214 myRemoveInvalidVehicles->setCheck(TRUE);
215 // ... and remove stops out of route
216 myRemoveStopsOutOfVehicle->setCheck(TRUE);
217}
218
219
220void
223
224
225bool
227 if (myConflictedElements.size() > 0) {
228 auto net = myFixElementDialogParent->getApplicationWindow()->getViewNet()->getNet();
229 auto undoList = myFixElementDialogParent->getApplicationWindow()->getUndoList();
230 // continue depending of solution
231 if (myRemoveInvalidVehicles->getCheck() == TRUE) {
232 // begin undo list
233 undoList->begin(GUIIcon::VEHICLE, TL("delete invalid vehicles"));
234 // iterate over invalid vehicles to delete it
235 for (const auto& conflictedElement : myConflictedElements) {
236 // check that vehicle was not removed previously in cascade
237 if (net->getAttributeCarriers()->retrieveDemandElement(conflictedElement.getElement()->getTagProperty()->getTag(), conflictedElement.getID(), false) != nullptr) {
238 net->deleteDemandElement(conflictedElement.getElement(), undoList);
239 }
240 }
241 // end undo list
242 undoList->end();
243 } else if (mySelectInvalidVehicles->getCheck() == TRUE) {
244 // begin undo list
245 undoList->begin(GUIIcon::ROUTE, TL("select invalid routes"));
246 // iterate over invalid single lane elements to select all elements
247 for (const auto& conflictedElement : myConflictedElements) {
248 conflictedElement.getElement()->setAttribute(GNE_ATTR_SELECTED, "true", undoList);
249 }
250 // end undo list
251 undoList->end();
252 // abort saving
253 return false;
254 }
255 // check if remove stops
256 if (myRemoveStopsOutOfVehicle->getCheck() == TRUE) {
257 // get all stops to remove
258 std::vector<GNEDemandElement*> stopsToRemove;
259 for (const auto& conflictedElement : myConflictedElements) {
260 const auto invaldstops = conflictedElement.getElement()->getInvalidStops();
261 // append to stopsToRemove
262 stopsToRemove.insert(stopsToRemove.end(), invaldstops.begin(), invaldstops.end());
263 }
264 // begin undo list
265 undoList->begin(GUIIcon::STOP, TL("delete invalid stops"));
266 // remove all
267 for (const auto& stopToRemove : stopsToRemove) {
268 net->deleteDemandElement(stopToRemove, undoList);
269 }
270 // end undo list
271 undoList->end();
272 }
273 }
274 return true;
275}
276
277
278long
280 if (obj == myRemoveInvalidVehicles) {
281 myRemoveInvalidVehicles->setCheck(true);
282 mySaveInvalidVehicles->setCheck(false);
283 mySelectInvalidVehicles->setCheck(false);
284 } else if (obj == mySaveInvalidVehicles) {
285 myRemoveInvalidVehicles->setCheck(false);
286 mySaveInvalidVehicles->setCheck(true);
287 mySelectInvalidVehicles->setCheck(false);
288 } else if (obj == mySelectInvalidVehicles) {
289 myRemoveInvalidVehicles->setCheck(false);
290 mySaveInvalidVehicles->setCheck(false);
291 mySelectInvalidVehicles->setCheck(true);
292 }
293 return 1;
294}
295
296// ---------------------------------------------------------------------------
297// GNEFixDemandElementsDialog::FixStopPositionOptions - methods
298// ---------------------------------------------------------------------------
299
301 FixOptions(fixDemandElementsParent, fixDemandElementsParent->myRightFrame, TL("Stop positions")) {
302 // Activate friendlyPos and save
304 TL("Activate friendlyPos"), "",
305 TL("Activate friendlyPos and save"),
307 // Save invalid position
309 TL("Save invalid stops"), "",
310 TL("Save elements with invalid positions"),
312 // Select invalid Stops
314 TL("Select conflicted stops"), "",
315 TL("Select conflicted stops and abort saving"),
317 // Fix positions and save
319 TL("Fix positions and save"), "",
320 TL("Fix stop positions and save"),
322 // register options
327 // leave option "activateFriendlyPositionAndSave" as default
328 myActivateFriendlyPosition->setCheck(true);
329}
330
331
332void
335
336
337bool
339 // check options for stops
340 if (myConflictedElements.size() > 0) {
341 auto undoList = myFixElementDialogParent->getApplicationWindow()->getUndoList();
342 // continue depending of solution
343 if (myActivateFriendlyPosition->getCheck() == TRUE) {
344 // begin undo list
345 undoList->begin(GUIIcon::STOP, TLF("change % of invalid stops", toString(SUMO_ATTR_FRIENDLY_POS)));
346 // iterate over invalid stops to enable friendly position
347 for (const auto& conflictedElement : myConflictedElements) {
348 conflictedElement.getElement()->setAttribute(SUMO_ATTR_FRIENDLY_POS, "true", undoList);
349 }
350 undoList->end();
351 } else if (myFixPositions->getCheck() == TRUE) {
352 undoList->begin(GUIIcon::STOP, TL("fix positions of invalid stops"));
353 // iterate over invalid stops to fix positions
354 for (const auto& conflictedElement : myConflictedElements) {
355 conflictedElement.getElement()->fixDemandElementProblem();
356 }
357 undoList->end();
358 } else if (mySelectInvalidStops->getCheck() == TRUE) {
359 undoList->begin(GUIIcon::STOP, TL("select invalid stops"));
360 // iterate over invalid stops to select all elements
361 for (const auto& conflictedElement : myConflictedElements) {
362 conflictedElement.getElement()->setAttribute(GNE_ATTR_SELECTED, "true", undoList);
363 }
364 // end undo list
365 undoList->end();
366 // abort saving
367 return false;
368 }
369 }
370 return true;
371}
372
373
374long
376 if (obj == myActivateFriendlyPosition) {
377 myActivateFriendlyPosition->setCheck(true);
378 myFixPositions->setCheck(false);
379 mySaveInvalid->setCheck(false);
380 mySelectInvalidStops->setCheck(false);
381 } else if (obj == myFixPositions) {
382 myActivateFriendlyPosition->setCheck(false);
383 myFixPositions->setCheck(true);
384 mySaveInvalid->setCheck(false);
385 mySelectInvalidStops->setCheck(false);
386 } else if (obj == mySaveInvalid) {
387 myActivateFriendlyPosition->setCheck(false);
388 myFixPositions->setCheck(false);
389 mySaveInvalid->setCheck(true);
390 mySelectInvalidStops->setCheck(false);
391 } else if (obj == mySelectInvalidStops) {
392 myActivateFriendlyPosition->setCheck(false);
393 myFixPositions->setCheck(false);
394 mySaveInvalid->setCheck(false);
395 mySelectInvalidStops->setCheck(true);
396 }
397 return 1;
398}
399
400// ---------------------------------------------------------------------------
401// GNEFixDemandElementsDialog::FixPlanOptions - methods
402// ---------------------------------------------------------------------------
403
405 FixOptions(fixDemandElementsParent, fixDemandElementsParent->myRightFrame, TL("Person/container plans")) {
406 // Delete person plan
408 TL("Remove invalid plans"), "",
409 TL("Remove invalid plans"),
411 // Save invalid person plans
413 TL("Save invalid plans"), "",
414 TL("Save invalid plans"),
416 // Select invalid person plans
418 TL("Select conflicted plans"), "",
419 TL("Select conflicted plans and abort saving"),
421 // register options
425 // set option "activateFriendlyPositionAndSave" as default
426 myRemoveInvalidPlan->setCheck(true);
427}
428
429
430void
433
434
435bool
437 // check options for person plans
438 if (myConflictedElements.size() > 0) {
439 auto net = myFixElementDialogParent->getApplicationWindow()->getViewNet()->getNet();
440 auto undoList = myFixElementDialogParent->getApplicationWindow()->getUndoList();
441 // continue depending of solution
442 if (myRemoveInvalidPlan->getCheck() == TRUE) {
443 // begin undo list
444 undoList->begin(GUIIcon::MODEPERSONPLAN, TL("delete invalid person plans"));
445 // remove all invalid person plans
446 for (const auto& conflictedElement : myConflictedElements) {
447 net->deleteDemandElement(conflictedElement.getElement(), undoList);
448 }
449 undoList->end();
450 } else if (mySelectInvalidPlans->getCheck() == TRUE) {
451 undoList->begin(GUIIcon::MODEPERSONPLAN, TL("select invalid person plans"));
452 // iterate over invalid person plans to select all elements
453 for (const auto& conflictedElement : myConflictedElements) {
454 conflictedElement.getElement()->setAttribute(GNE_ATTR_SELECTED, "true", undoList);
455 }
456 // end undo list
457 undoList->end();
458 // abort saving
459 return false;
460 }
461 }
462 return true;
463}
464
465
466long
468 if (obj == myRemoveInvalidPlan) {
469 myRemoveInvalidPlan->setCheck(true);
470 mySaveInvalid->setCheck(false);
471 mySelectInvalidPlans->setCheck(false);
472 } else if (obj == mySaveInvalid) {
473 myRemoveInvalidPlan->setCheck(false);
474 mySaveInvalid->setCheck(true);
475 mySelectInvalidPlans->setCheck(false);
476 } else if (obj == mySelectInvalidPlans) {
477 myRemoveInvalidPlan->setCheck(false);
478 mySaveInvalid->setCheck(false);
479 mySelectInvalidPlans->setCheck(true);
480 }
481 return true;
482}
483
484// ---------------------------------------------------------------------------
485// GNEFixDemandElementsDialog - methods
486// ---------------------------------------------------------------------------
487
489 const std::vector<GNEDemandElement*>& elements) :
490 GNEFixElementsDialog(mainWindow, TL("Fix demand elements problems"), GUIIcon::SUPERMODEDEMAND) {
491 // create fix route options
493 // create fix vehicle options
495 // create fix stops options
497 // create fix person plans options
499 // split invalidDemandElements in four groups
500 std::vector<ConflictElement> invalidRoutes, invalidVehicles, invalidStops, invalidPlans;
501 // fill groups
502 for (const auto& invalidDemandElement : elements) {
503 // create conflict element
504 auto fixElement = ConflictElement(invalidDemandElement,
505 invalidDemandElement->getID(),
506 invalidDemandElement->getACIcon(),
507 invalidDemandElement->getDemandElementProblem());
508 // add depending of element type
509 if (invalidDemandElement->getTagProperty()->isRoute()) {
510 invalidRoutes.push_back(fixElement);
511 } else if (invalidDemandElement->getTagProperty()->isVehicle()) {
512 invalidVehicles.push_back(fixElement);
513 } else if (invalidDemandElement->getTagProperty()->isVehicleStop()) {
514 invalidStops.push_back(fixElement);
515 } else {
516 invalidPlans.push_back(fixElement);
517 }
518 }
519 // fill options
521 myFixVehicleOptions->setInvalidElements(invalidVehicles);
524 // open modal dialog
525 openDialog();
526}
527
528
531
532/****************************************************************************/
FXDEFMAP(GNEFixDemandElementsDialog::FixRouteOptions) FixRouteOptionsMap[]
@ MID_CHOOSEN_OPERATION
set type of selection
Definition GUIAppEnum.h:597
#define GUIDesignRadioButtonFix
design for radio button with fixed height (used in fix elements dialogs)
Definition GUIDesigns.h:237
#define GUIDesignCheckButtonFix
design for check button with fixed height (used in fix elements dialogs)
Definition GUIDesigns.h:212
GUIIcon
An enumeration of icons used by the gui applications.
Definition GUIIcons.h:33
@ MODEPERSONPLAN
@ SUPERMODEDEMAND
#define TL(string)
Definition MsgHandler.h:305
#define TLF(string,...)
Definition MsgHandler.h:307
@ GNE_TAG_ROUTE_EMBEDDED
embedded route
@ GNE_ATTR_SELECTED
element is selected
@ SUMO_ATTR_FRIENDLY_POS
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition ToString.h:46
The main window of Netedit.
void openDialog(FXWindow *focusableElement=nullptr)
open dialog
groupbox for all radio buttons related with fix person plan options
FXRadioButton * mySelectInvalidPlans
Option "Select invalid person plans and cancel".
void selectInternalTestSolution(const std::string &solution)
select internal test solution
FixPlanOptions(GNEFixDemandElementsDialog *fixDemandElementsParent)
FOX-declaration.
long onCmdSelectOption(FXObject *obj, FXSelector, void *)
called when user select a option
FXRadioButton * mySaveInvalid
Option "Save invalid".
groupbox for all radio buttons related with fix route options
FXRadioButton * mySelectRouteInvalids
Option "Select invalid routes and cancel".
FXRadioButton * mySaveInvalidRoutes
Option "Save invalid routes".
long onCmdSelectOption(FXObject *obj, FXSelector, void *)
called when user select a option
void selectInternalTestSolution(const std::string &solution)
select internal test solution
groupbox for all radio buttons related with fix stop options
long onCmdSelectOption(FXObject *obj, FXSelector, void *)
called when user select a option
FXRadioButton * myFixPositions
Option "Fix Positions and save".
void selectInternalTestSolution(const std::string &solution)
select internal test solution
FXRadioButton * mySelectInvalidStops
Option "Select invalid stops and cancel".
FixStopPositionOptions(GNEFixDemandElementsDialog *fixDemandElementsParent)
FOX-declaration.
groupbox for all radio buttons related with fix vehicle options
void selectInternalTestSolution(const std::string &solution)
select internal test solution
FixVehicleOptions(GNEFixDemandElementsDialog *fixDemandElementsParent)
FOX-declaration.
FXRadioButton * mySelectInvalidVehicles
Option "Select invalid vehicles and cancel".
long onCmdSelectOption(FXObject *obj, FXSelector, void *)
called when user select a option
FXCheckButton * myRemoveStopsOutOfVehicle
Option "Remove stops out of vehicle".
FXRadioButton * mySaveInvalidVehicles
Option "save invalid vehicles".
GNEFixDemandElementsDialog(GNEApplicationWindow *mainWindow, const std::vector< GNEDemandElement * > &elements)
Constructor.
FixPlanOptions * myFixPlanOptions
fix person plan options
FixRouteOptions * myFixRouteOptions
fix route options
FixStopPositionOptions * myFixStopPositionOptions
fix stop options
FixVehicleOptions * myFixVehicleOptions
fix vehicle options
void registerOption(FXWindow *option)
add option to options container (used for adjust width and enable/disable)
void setInvalidElements(const std::vector< ConflictElement > &conflictedElements)
set invalid elements to fix
FXVerticalFrame * myRightFrameOptions
vertical right frame for options
FXVerticalFrame * myLeftFrameOptions
vertical left frame for options
FXVerticalFrame * myRightFrame
right frame for fix options
FXVerticalFrame * myLeftFrame
left frame for fix options
static FXCheckButton * buildFXCheckButton(FXComposite *p, const std::string &text, const std::string &tip, const std::string &help, FXObject *tgt, FXSelector sel, FXuint opts=CHECKBUTTON_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 check 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
MFXGroupBoxModule (based on FXGroupBox)