Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
GNEFixElementsDialog.h
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// template used to fix elements during saving
19/****************************************************************************/
20#pragma once
21#include <config.h>
22
28
29// ===========================================================================
30// class definitions
31// ===========================================================================
32
33template <typename T>
35
36public:
39
40 public:
42 ConflictElement(T element, const std::string& id, FXIcon* icon, const std::string& description) :
43 myElement(element),
44 myID(id),
45 myIcon(icon),
46 myDescription(description) {}
47
50
52 T getElement() const {
53 return myElement;
54 }
55
57 const std::string& getID() const {
58 return myID;
59 }
60
62 FXIcon* getIcon() const {
63 return myIcon;
64 }
65
67 const std::string& getDescription() const {
68 return myDescription;
69 }
70
71 private:
74
76 std::string myID;
77
79 FXIcon* myIcon = nullptr;
80
82 std::string myDescription;
83
85 ConflictElement() = delete;
86 };
87
90
91 public:
93 FixOptions(GNEFixElementsDialog<T>* fixElementDialog, FXVerticalFrame* frameParent, const std::string& title) :
94 MFXGroupBoxModule(frameParent, title, MFXGroupBoxModule::Options::SAVE),
95 myFixElementDialogParent(fixElementDialog) {
96 // register this fix option to list of fix options
97 fixElementDialog->registerFixOptions(this);
98 // Create table
100 // create frames for options
101 FXHorizontalFrame* optionsFrame = new FXHorizontalFrame(getCollapsableFrame(), GUIDesignAuxiliarHorizontalFrame);
102 myLeftFrameOptions = new FXVerticalFrame(optionsFrame, GUIDesignAuxiliarFrameFixedWidth(int(myTable->getWidth() * 0.5)));
103 myRightFrameOptions = new FXVerticalFrame(optionsFrame, GUIDesignAuxiliarFrameFixedWidth(int(myTable->getWidth() * 0.5)));
104 }
105
107 virtual void selectInternalTestSolution(const std::string& solution) = 0;
108
110 virtual bool applyFixOption() = 0;
111
114
116 virtual long onCmdSelectOption(FXObject*, FXSelector, void*) = 0;
117
119
121 void setInvalidElements(const std::vector<ConflictElement>& conflictedElements) {
122 // parse invalid elements
123 myConflictedElements = conflictedElements;
124 // configure table
125 myTable->setTableSize((int)(myConflictedElements.size()), 3);
126 myTable->setSelBackColor(FXRGBA(255, 255, 255, 255));
127 myTable->setSelTextColor(FXRGBA(0, 0, 0, 255));
128 myTable->setEditable(false);
129 // configure header
130 myTable->setVisibleColumns(4);
131 myTable->setColumnHeaderHeight(GUIDesignHeight);
132 myTable->getRowHeader()->setWidth(0);
133 // icon
134 myTable->setColumnWidth(0, GUIDesignHeight);
135 myTable->setColumnText(0, "");
136 // ID
137 myTable->setColumnWidth(1, 110);
138 myTable->setColumnText(1, toString(SUMO_ATTR_ID).c_str());
139 // description
140 myTable->setColumnWidth(2, myTable->getWidth() - GUIDesignHeight - 110 - 15);
141 myTable->setColumnText(2, TL("Conflict"));
142 // Declare pointer to FXTableItem
143 FXTableItem* item = nullptr;
144 // iterate over invalid edges
145 for (int i = 0; i < (int)myConflictedElements.size(); i++) {
146 // Set icon
147 item = new FXTableItem("", myConflictedElements.at(i).getIcon());
148 item->setIconPosition(FXTableItem::CENTER_X);
149 myTable->setItem(i, 0, item);
150 // Set ID
151 item = new FXTableItem(myConflictedElements.at(i).getID().c_str());
152 item->setJustify(FXTableItem::LEFT | FXTableItem::CENTER_Y);
153 myTable->setItem(i, 1, item);
154 // Set conflict
155 item = new FXTableItem(myConflictedElements.at(i).getDescription().c_str());
156 item->setJustify(FXTableItem::LEFT | FXTableItem::CENTER_Y);
157 myTable->setItem(i, 2, item);
158 // set row height
159 myTable->setRowHeight(i, GUIDesignHeight);
160 }
161 // check if enable or disable options
162 if (myConflictedElements.size() > 0) {
164 } else {
166 }
167 }
168
169 protected:
172
174 FXTable* myTable = nullptr;
175
177 FXVerticalFrame* myLeftFrameOptions = nullptr;
178
180 FXVerticalFrame* myRightFrameOptions = nullptr;
181
183 std::vector<ConflictElement> myConflictedElements;
184
188 }
189
191 void registerOption(FXWindow* option) {
192 myOptions.push_back(option);
193 // adjust width
194 option->setWidth(int(myTable->getWidth() * 0.5));
195 }
196
197 private:
199 std::vector<FXWindow*> myOptions;
200
203 // enable each option
204 for (auto option : myOptions) {
205 option->enable();
206 }
207 }
208
211 // disable each option
212 for (auto option : myOptions) {
213 option->disable();
214 }
215 }
216
218 bool saveContents() const {
219 // open file dialog to save list of conflicted items
220 const FXString file = MFXUtils::getFilename2Write(myTable,
221 TL("Save list of conflicted items"),
222 SUMOXMLDefinitions::TXTFileExtensions.getMultilineString().c_str(),
224 // continue if file is not empty
225 if (file == "") {
226 return false;
227 } else {
228 try {
229 // open output device
230 OutputDevice& device = OutputDevice::getDevice(file.text());
231 // get invalid element ID and problem
232 for (const auto& conflictedElement : myConflictedElements) {
233 device << conflictedElement.getID() << ":" << conflictedElement.getDescription() << "\n";
234 }
235 // close output device
236 device.close();
237 // open information message box
239 TL("Saving successfully"),
240 TL("List of conflicted items was successfully saved"));
241 return true;
242 } catch (IOError& e) {
243 // open message box error
245 TL("Saving list of conflicted items failed"), e.what());
246 return false;
247 }
248 }
249 }
250
252 FixOptions(const FixOptions&) = delete;
253
255 FixOptions& operator=(const FixOptions&) = delete;
256 };
257
259 GNEFixElementsDialog(GNEApplicationWindow* mainWindow, const std::string title, GUIIcon icon):
260 GNEDialog(mainWindow, title.c_str(), icon, GNEDialog::Buttons::ACCEPT_CANCEL,
262 // create left and right frames
263 FXHorizontalFrame* columnFrame = new FXHorizontalFrame(myContentFrame, GUIDesignAuxiliarHorizontalFrame);
264 myLeftFrame = new FXVerticalFrame(columnFrame, GUIDesignAuxiliarVerticalFrame);
265 myRightFrame = new FXVerticalFrame(columnFrame, GUIDesignAuxiliarVerticalFrame);
266 }
267
270
275
277 void registerFixOptions(FixOptions* fixOptions) {
278 myFixOptions.push_back(fixOptions);
279 }
280
283 // run internal test for each fix option
284 for (auto fixOption : myFixOptions) {
285 fixOption->selectInternalTestSolution(dialogArgument->getCustomAction());
286 }
287 }
288
291
293 long onCmdAccept(FXObject*, FXSelector, void*) {
294 bool abortSaving = false;
295 // apply each fix option in their correspond fixOption
296 for (auto fixOption : myFixOptions) {
297 // if applyFixOption returns false, abort saving (usually for selecting invalid elements)
298 if (fixOption->applyFixOption() == false) {
299 abortSaving = true;
300 }
301 }
302 // continue depending of abortSaving
303 if (abortSaving == false) {
304 return closeDialogAccepting();
305 } else {
306 return closeDialogCanceling();
307 }
308 }
309
311
312protected:
314 std::vector<GNEFixElementsDialog::FixOptions*> myFixOptions;
315
317 FXVerticalFrame* myLeftFrame = nullptr;
318
320 FXVerticalFrame* myRightFrame = nullptr;
321
322private:
325
328};
@ MID_TABLE
The Table.
Definition GUIAppEnum.h:539
#define GUIDesignAuxiliarHorizontalFrame
design for auxiliar (Without borders) horizontal frame used to pack another frames
Definition GUIDesigns.h:430
#define GUIDesignAuxiliarFrameFixedWidth(width)
design for auxiliar (Without borders) frame with fixed width and extended height
Definition GUIDesigns.h:415
#define GUIDesignAuxiliarVerticalFrame
design for auxiliar (Without borders) horizontal frame used to pack another frames
Definition GUIDesigns.h:439
#define GUIDesignTableFixElements
design for tables used in GNEFixDemandElementsDialog dialogs
Definition GUIDesigns.h:653
FXString gCurrentFolder
The folder used as last.
GUIIcon
An enumeration of icons used by the gui applications.
Definition GUIIcons.h:33
@ SAVE
save icons
#define TL(string)
Definition MsgHandler.h:305
@ SUMO_ATTR_ID
int GUIDesignHeight
the default height for GUI elements
Definition StdDefs.cpp:37
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition ToString.h:46
The main window of Netedit.
FXVerticalFrame * myContentFrame
content frame
Definition GNEDialog.h:135
GNEApplicationWindow * myApplicationWindow
FOX needs this.
Definition GNEDialog.h:132
long closeDialogAccepting()
close dialog accepting the changes
OpenType
Open dialog type.
Definition GNEDialog.h:55
long closeDialogCanceling()
close dialog declining the changes
const std::string & getID() const
get element ID
ConflictElement(T element, const std::string &id, FXIcon *icon, const std::string &description)
constructor
FXIcon * getIcon() const
get element icon
std::string myDescription
conflict description
ConflictElement()=delete
invalidate default constructor
const std::string & getDescription() const
get conflict description
bool saveContents() const
save save list of conflicted items to a file (Reimplemented from MFXGroupBoxModule)
FixOptions & operator=(const FixOptions &)=delete
Invalidated assignment operator.
void registerOption(FXWindow *option)
add option to options container (used for adjust width and enable/disable)
virtual long onCmdSelectOption(FXObject *, FXSelector, void *)=0
called when user select a option
std::vector< ConflictElement > myConflictedElements
list of elements to fix
void setInvalidElements(const std::vector< ConflictElement > &conflictedElements)
set invalid elements to fix
FXVerticalFrame * myRightFrameOptions
vertical right frame for options
virtual bool applyFixOption()=0
apply selected fix option
FXTable * myTable
Table with the demand elements.
GNEFixElementsDialog * myFixElementDialogParent
pointer to the parent dialog
FixOptions(GNEFixElementsDialog< T > *fixElementDialog, FXVerticalFrame *frameParent, const std::string &title)
constructor
FixOptions(const FixOptions &)=delete
Invalidated copy constructor.
std::vector< FXWindow * > myOptions
list of options
FXVerticalFrame * myLeftFrameOptions
vertical left frame for options
virtual void selectInternalTestSolution(const std::string &solution)=0
select internal test solution (used in internal tests)
GNEFixElementsDialog(GNEApplicationWindow *mainWindow, const std::string title, GUIIcon icon)
Constructor.
GNEApplicationWindow * getApplicationWindow()
pointer to the main window
FXVerticalFrame * myRightFrame
right frame for fix options
GNEFixElementsDialog & operator=(const GNEFixElementsDialog &)=delete
Invalidated assignment operator.
GNEFixElementsDialog(const GNEFixElementsDialog &)=delete
Invalidated copy constructor.
long onCmdAccept(FXObject *, FXSelector, void *)
event after press accept button
std::vector< GNEFixElementsDialog::FixOptions * > myFixOptions
vector with all fix options
void runInternalTest(const InternalTestStep::DialogArgument *dialogArgument)
run internal test
void registerFixOptions(FixOptions *fixOptions)
register fix options to the dialog (called automatically during FixOptions constructor)
FXVerticalFrame * myLeftFrame
left frame for fix options
static FXIcon * getIcon(const GUIIcon which)
returns a icon previously defined in the enum GUIIcon
dialog arguments, used for certain modal dialogs that can not be edited using tab
const std::string & getCustomAction() const
get custom action
MFXGroupBoxModule (based on FXGroupBox)
FXVerticalFrame * getCollapsableFrame()
get collapsable frame (used by all elements that will be collapsed if button is toggled)
Options
GroupBoxModule options.
static FXString getFilename2Write(FXWindow *parent, const FXString &header, const FXString &extensions, FXIcon *icon, FXString &currentFolder)
Returns the file name to write.
Definition MFXUtils.cpp:116
Static storage of an output device and its base (abstract) implementation.
void close()
Closes the device and removes it from the dictionary.
static OutputDevice & getDevice(const std::string &name, bool usePrefix=true)
Returns the described OutputDevice.
static StringBijection< TXTFileExtension > TXTFileExtensions
TXT file Extensions.