Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
GNEFixNetworkElements.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 network 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
40// Object abstract implementation
41FXIMPLEMENT(GNEFixNetworkElements::FixEdgeOptions, MFXGroupBoxModule, FixEdgeOptionsMap, ARRAYNUMBER(FixEdgeOptionsMap))
42FXIMPLEMENT(GNEFixNetworkElements::FixCrossingOptions, MFXGroupBoxModule, FixCrossingOptionsMap, ARRAYNUMBER(FixCrossingOptionsMap))
43
44// ===========================================================================
45// member method definitions
46// ===========================================================================
47
48// ---------------------------------------------------------------------------
49// GNEFixNetworkElements::FixEdgeOptions - methods
50// ---------------------------------------------------------------------------
51
53 GNEFixElementsDialog<GNENetworkElement*>::FixOptions(fixNetworkElementsParent, fixNetworkElementsParent->myLeftFrame, "Edges") {
54 // Remove invalid edges
55 myRemoveInvalidEdges = GUIDesigns::buildFXRadioButton(myLeftFrameOptions,
56 TL("Remove invalid edges"), "",
57 TL("Remove invalid edges"),
59 // Save invalid edges
60 mySaveInvalidEdges = GUIDesigns::buildFXRadioButton(myLeftFrameOptions,
61 TL("Save invalid edges"), "",
62 TL("Save invalid edges"),
64 // Select invalid edges
65 mySelectInvalidEdges = GUIDesigns::buildFXRadioButton(myRightFrameOptions,
66 TL("Select invalid edges"), "",
67 TL("Select invalid edges and abort saving"),
69 // register options
70 registerOption(myRemoveInvalidEdges);
71 registerOption(mySaveInvalidEdges);
72 registerOption(mySelectInvalidEdges);
73 // set option "removeInvalidEdges" as default
74 myRemoveInvalidEdges->setCheck(true);
75}
76
77
78void
80 // finish
81}
82
83
84bool
86 if (myConflictedElements.size() > 0) {
87 auto net = myFixElementDialogParent->getApplicationWindow()->getViewNet()->getNet();
88 auto undoList = myFixElementDialogParent->getApplicationWindow()->getUndoList();
89 // continue depending of solution
90 if (myRemoveInvalidEdges->getCheck() == TRUE) {
91 // begin undo list
92 undoList->begin(GUIIcon::EDGE, TL("delete invalid edges"));
93 // iterate over invalid edges to delete it
94 for (const auto& conflictedElement : myConflictedElements) {
95 net->deleteEdge(net->getAttributeCarriers()->retrieveEdge(conflictedElement.getID()), undoList, false);
96 }
97 // end undo list
98 undoList->end();
99 } else if (mySelectInvalidEdges->getCheck() == TRUE) {
100 // begin undo list
101 undoList->begin(GUIIcon::EDGE, TL("select invalid edges"));
102 // iterate over invalid single lane elements to select all elements
103 for (const auto& conflictedElement : myConflictedElements) {
104 conflictedElement.getElement()->setAttribute(GNE_ATTR_SELECTED, "true", undoList);
105 }
106 // end undo list
107 undoList->end();
108 // abort saving
109 return false;
110 }
111 }
112 return true;
113}
114
115
116long
118 if (obj == myRemoveInvalidEdges) {
119 myRemoveInvalidEdges->setCheck(true);
120 mySaveInvalidEdges->setCheck(false);
121 mySelectInvalidEdges->setCheck(false);
122 } else if (obj == mySaveInvalidEdges) {
123 myRemoveInvalidEdges->setCheck(false);
124 mySaveInvalidEdges->setCheck(true);
125 mySelectInvalidEdges->setCheck(false);
126 } else if (obj == mySelectInvalidEdges) {
127 myRemoveInvalidEdges->setCheck(false);
128 mySaveInvalidEdges->setCheck(false);
129 mySelectInvalidEdges->setCheck(true);
130 }
131 return 1;
132}
133
134// ---------------------------------------------------------------------------
135// GNEFixNetworkElements::FixCrossingOptions - methods
136// ---------------------------------------------------------------------------
137
139 GNEFixElementsDialog<GNENetworkElement*>::FixOptions(fixNetworkElementsParent, fixNetworkElementsParent->myLeftFrame, "Crossings") {
140 // Remove invalid crossings
142 TL("Remove invalid crossings"), "",
143 TL("Remove invalid crossings"),
145 // Save invalid crossings
147 TL("Save invalid crossings"), "",
148 TL("Save invalid crossings"),
150 // Select invalid crossing
152 TL("Select invalid crossing"), "",
153 TL("Select invalid crossing and abort saving"),
155 // register options
159 // by default remove invalid crossings
160 myRemoveInvalidCrossings->setCheck(TRUE);
161}
162
163
164void
166 // choose solution
167 if (solution == "removeInvalidCrossings") {
168 myRemoveInvalidCrossings->setCheck(TRUE, TRUE);
169 } else if (solution == "saveInvalidCrossings") {
170 mySaveInvalidCrossings->setCheck(TRUE, TRUE);
171 } else if (solution == "selectInvalidCrossings") {
172 mySelectInvalidCrossings->setCheck(TRUE, TRUE);
173 }
174}
175
176
177bool
179 if (myConflictedElements.size() > 0) {
180 auto net = myFixElementDialogParent->getApplicationWindow()->getViewNet()->getNet();
181 auto undoList = myFixElementDialogParent->getApplicationWindow()->getUndoList();
182 // continue depending of solution
183 if (myRemoveInvalidCrossings->getCheck() == TRUE) {
184 // begin undo list
185 undoList->begin(GUIIcon::CROSSING, TL("delete invalid crossings"));
186 // iterate over invalid crossings to delete it
187 for (const auto& conflictedElement : myConflictedElements) {
188 net->deleteCrossing(net->getAttributeCarriers()->retrieveCrossing(conflictedElement.getElement()), undoList);
189 }
190 // end undo list
191 undoList->end();
192 } else if (mySelectInvalidCrossings->getCheck() == TRUE) {
193 // begin undo list
194 undoList->begin(GUIIcon::CROSSING, TL("select invalid crossings"));
195 // iterate over invalid single lane elements to select all elements
196 for (const auto& conflictedElement : myConflictedElements) {
197 conflictedElement.getElement()->setAttribute(GNE_ATTR_SELECTED, "true", undoList);
198 }
199 // end undo list
200 undoList->end();
201 // abort saving
202 return false;
203 }
204 }
205 return true;
206}
207
208
209long
211 if (obj == myRemoveInvalidCrossings) {
212 myRemoveInvalidCrossings->setCheck(true);
213 mySaveInvalidCrossings->setCheck(false);
214 mySelectInvalidCrossings->setCheck(false);
215 } else if (obj == mySaveInvalidCrossings) {
216 myRemoveInvalidCrossings->setCheck(false);
217 mySaveInvalidCrossings->setCheck(true);
218 mySelectInvalidCrossings->setCheck(false);
219 } else if (obj == mySelectInvalidCrossings) {
220 myRemoveInvalidCrossings->setCheck(false);
221 mySaveInvalidCrossings->setCheck(false);
222 mySelectInvalidCrossings->setCheck(true);
223 }
224 return 1;
225}
226
227// ---------------------------------------------------------------------------
228// GNEFixNetworkElements - methods
229// ---------------------------------------------------------------------------
230
232 const std::vector<GNENetworkElement*>& elements) :
233 GNEFixElementsDialog(mainWindow, TL("Fix network elements problems"), GUIIcon::SUPERMODENETWORK) {
234 // create fix edge options
236 // create fix crossing options
238 // split invalidNetworkElements in four groups
239 std::vector<ConflictElement> invalidEdges, invalidCrossings;
240 // fill groups
241 for (const auto& invalidNetworkElement : elements) {
242 // create conflict element
243 auto fixElement = ConflictElement(invalidNetworkElement,
244 invalidNetworkElement->getID(),
245 invalidNetworkElement->getACIcon(),
246 invalidNetworkElement->getNetworkElementProblem());
247 // add depending of element type
248 if (invalidNetworkElement->getTagProperty()->getTag() == SUMO_TAG_EDGE) {
249 invalidEdges.push_back(fixElement);
250 } else if (invalidNetworkElement->getTagProperty()->getTag() == SUMO_TAG_CROSSING) {
251 invalidCrossings.push_back(fixElement);
252 }
253 }
254 // fill options
256 myFixCrossingOptions->setInvalidElements(invalidCrossings);
257 // open modal dialog
258 openDialog();
259}
260
261
263
264/****************************************************************************/
FXDEFMAP(GNEFixNetworkElements::FixEdgeOptions) FixEdgeOptionsMap[]
@ 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
GUIIcon
An enumeration of icons used by the gui applications.
Definition GUIIcons.h:33
@ SUPERMODENETWORK
#define TL(string)
Definition MsgHandler.h:305
@ SUMO_TAG_CROSSING
crossing between edges for pedestrians
@ SUMO_TAG_EDGE
begin/end of the description of an edge
@ GNE_ATTR_SELECTED
element is selected
The main window of Netedit.
void openDialog(FXWindow *focusableElement=nullptr)
open dialog
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 * myLeftFrame
left frame for fix options
groupbox for all radio buttons related with fix crossing options
FixCrossingOptions(GNEFixNetworkElements *fixNetworkElementsParent)
FOX-declaration.
FXRadioButton * mySelectInvalidCrossings
Option "Select invalid crossings and cancel".
long onCmdSelectOption(FXObject *obj, FXSelector, void *)
called when user select a option
void selectInternalTestSolution(const std::string &solution)
select internal test solution
FXRadioButton * myRemoveInvalidCrossings
FOX needs this.
FXRadioButton * mySaveInvalidCrossings
Option "save invalid crossings".
groupbox for all radio buttons related with fix edges options
void selectInternalTestSolution(const std::string &solution)
select internal test solution
bool applyFixOption()
apply selected fix option
long onCmdSelectOption(FXObject *obj, FXSelector, void *)
called when user select a option
FixEdgeOptions * myFixEdgeOptions
fix edge options
FixCrossingOptions * myFixCrossingOptions
fix crossing options
GNEFixNetworkElements(GNEApplicationWindow *mainWindow, const std::vector< GNENetworkElement * > &elements)
Constructor.
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)