Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
GUIDialog_GLChosenEditor.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/****************************************************************************/
20// Editor for the list of chosen objects
21/****************************************************************************/
22#include <config.h>
23
24#include <string>
25#include <vector>
26#include <iostream>
27#include <fstream>
39
40
41// ===========================================================================
42// FOX callback mapping
43// ===========================================================================
44FXDEFMAP(GUIDialog_GLChosenEditor) GUIDialog_GLChosenEditorMap[] = {
49 FXMAPFUNC(SEL_COMMAND, MID_CANCEL, GUIDialog_GLChosenEditor::onCmdClose),
50};
51
52FXIMPLEMENT(GUIDialog_GLChosenEditor, FXMainWindow, GUIDialog_GLChosenEditorMap, ARRAYNUMBER(GUIDialog_GLChosenEditorMap))
53
54
55// ===========================================================================
56// method definitions
57// ===========================================================================
58#ifdef _MSC_VER
59#pragma warning(push)
60#pragma warning(disable: 4355) // mask warning about "this" in initializers
61#endif
63 FXMainWindow(parent->getApp(), "List of Selected Items", GUIIconSubSys::getIcon(GUIIcon::APP_SELECTOR), nullptr, GUIDesignChooserDialog),
64 GUIPersistentWindowPos(this, "DIALOG_EDIT_SELECTED", true, 20, 40, 300, 350),
65 myParent(parent), myStorage(str) {
66 myStorage->add2Update(this);
67 FXHorizontalFrame* hbox = new FXHorizontalFrame(this, GUIDesignAuxiliarFrame);
68 // create layout left
69 FXVerticalFrame* layoutLeft = new FXVerticalFrame(hbox, GUIDesignChooserLayoutLeft);
70 // create frame for list
71 FXVerticalFrame* layoutList = new FXVerticalFrame(layoutLeft, GUIDesignChooserLayoutList);
72 // build the list and rebuild it
73 myList = new FXList(layoutList, this, MID_CHOOSER_LIST, GUIDesignChooserListMultiple);
75 // build the layout
76 FXVerticalFrame* layout = new FXVerticalFrame(hbox, GUIDesignChooserLayoutRight);
77 // "Load"
79 // "Save"
81 // extra separator
82 new FXHorizontalSeparator(layout, GUIDesignHorizontalSeparator);
83 // "Deselect Chosen"
85 // "Clear List"
87 // extra separator
88 new FXHorizontalSeparator(layout, GUIDesignHorizontalSeparator);
89 // "Close"
91 myParent->addChild(this);
93}
94#ifdef _MSC_VER
95#pragma warning(pop)
96#endif
97
98
103
104
105void
107 myList->clearItems();
108 const auto& chosen = gSelected.getSelected();
109 for (auto i : chosen) {
111 if (object != nullptr) {
112 std::string name = object->getFullName();
113 FXListItem* item = myList->getItem(myList->appendItem(name.c_str()));
114 item->setData(object);
116 }
117 }
118}
119
120
121void
123 rebuildList();
124 FXMainWindow::update();
125}
126
127
128long
129GUIDialog_GLChosenEditor::onCmdLoad(FXObject*, FXSelector, void*) {
130 // get the new file name
131 FXFileDialog opendialog(this, TL("Open List of Selected Items"));
132 opendialog.setIcon(GUIIconSubSys::getIcon(GUIIcon::OPEN));
133 opendialog.setSelectMode(SELECTFILE_EXISTING);
134 opendialog.setPatternList(SUMOXMLDefinitions::TXTFileExtensions.getMultilineString().c_str());
135 if (gCurrentFolder.length() != 0) {
136 opendialog.setDirectory(gCurrentFolder);
137 }
138 if (opendialog.execute()) {
139 gCurrentFolder = opendialog.getDirectory();
140 std::string file = opendialog.getFilename().text();
141 std::string msg = gSelected.load(file);
142 if (msg != "") {
143 FXMessageBox::error(this, MBOX_OK, TL("Errors while loading Selection"), "%s", msg.c_str());
144 }
145 rebuildList();
147 }
148 return 1;
149}
150
151
152long
153GUIDialog_GLChosenEditor::onCmdSave(FXObject*, FXSelector, void*) {
154 FXString file = MFXUtils::getFilename2Write(this, TL("Save List of selected Items"),
155 SUMOXMLDefinitions::TXTFileExtensions.getMultilineString().c_str(),
157 if (file == "") {
158 return 1;
159 }
160 try {
161 gSelected.save(file.text());
162 } catch (IOError& e) {
163 FXMessageBox::error(this, MBOX_OK, TL("Storing failed!"), "%s", e.what());
164 }
165 return 1;
166}
167
168
169long
170GUIDialog_GLChosenEditor::onCmdDeselect(FXObject*, FXSelector, void*) {
171 FXint no = myList->getNumItems();
172 FXint i;
173 std::vector<GUIGlID> selected;
174 for (i = 0; i < no; ++i) {
175 if (myList->getItem(i)->isSelected()) {
176 selected.push_back(static_cast<GUIGlObject*>(myList->getItem(i)->getData())->getGlID());
177 }
178 }
179 // remove items from list
180 for (i = 0; i < (FXint) selected.size(); ++i) {
181 gSelected.deselect(selected[i]);
182 }
183 // rebuild list
184 rebuildList();
186 return 1;
187}
188
189
190long
191GUIDialog_GLChosenEditor::onCmdClear(FXObject*, FXSelector, void*) {
192 myList->clearItems();
195 return 1;
196}
197
198
199long
200GUIDialog_GLChosenEditor::onCmdClose(FXObject*, FXSelector, void*) {
201 close(true);
202 return 1;
203}
204
205
206/****************************************************************************/
@ MID_CANCEL
Cancel-button pressed.
Definition GUIAppEnum.h:308
@ MID_CHOOSEN_SAVE
Save set.
Definition GUIAppEnum.h:603
@ MID_CHOOSEN_DESELECT
Deselect selected items.
Definition GUIAppEnum.h:613
@ MID_CHOOSER_LIST
Object list.
Definition GUIAppEnum.h:585
@ MID_CHOOSEN_LOAD
Load set.
Definition GUIAppEnum.h:601
@ MID_CHOOSEN_CLEAR
Clear set.
Definition GUIAppEnum.h:605
#define GUIDesignChooserButtons
design for Chooser buttons
Definition GUIDesigns.h:648
#define GUIDesignChooserLayoutLeft
design for Chooser Layout left
Definition GUIDesigns.h:663
#define GUIDesignChooserLayoutRight
design for Chooser Layout right
Definition GUIDesigns.h:666
#define GUIDesignHorizontalSeparator
Definition GUIDesigns.h:463
#define GUIDesignChooserLayoutList
design for Chooser Layout list
Definition GUIDesigns.h:669
#define GUIDesignAuxiliarFrame
design for auxiliar (Without borders) frame extended in all directions
Definition GUIDesigns.h:390
#define GUIDesignChooserDialog
Definition GUIDesigns.h:645
#define GUIDesignChooserListMultiple
design for Chooser List
Definition GUIDesigns.h:657
FXDEFMAP(GUIDialog_GLChosenEditor) GUIDialog_GLChosenEditorMap[]
GUISelectedStorage gSelected
A global holder of selected objects.
FXString gCurrentFolder
The folder used as last.
GUIIcon
An enumeration of icons used by the gui applications.
Definition GUIIcons.h:33
@ APP_SELECTOR
@ OPEN
open icons
@ SAVE
save icons
#define TL(string)
Definition MsgHandler.h:305
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
Editor for the list of chosen objects.
FXList * myList
The list that holds the ids.
GUISelectedStorage * myStorage
The storage.
long onCmdLoad(FXObject *, FXSelector, void *)
Called when the user presses the Load-button.
long onCmdDeselect(FXObject *, FXSelector, void *)
Called when the user presses the Deselect-button.
GUIMainWindow * myParent
The parent window.
~GUIDialog_GLChosenEditor()
Destructor (Notifies both the parent and the storage about being destroyed)
long onCmdSave(FXObject *, FXSelector, void *)
Called when the user presses the Save-button.
long onCmdClose(FXObject *, FXSelector, void *)
Called when the user presses the Close-button.
void selectionUpdated()
called when selection is updated
long onCmdClear(FXObject *, FXSelector, void *)
Called when the user presses the Clear-button.
void rebuildList()
Rebuilds the entire list.
const std::string & getFullName() const
Definition GUIGlObject.h:95
GUIGlID getGlID() const
Returns the numerical id of the object.
void unblockObject(GUIGlID id)
Marks an object as unblocked.
GUIGlObject * getObjectBlocking(GUIGlID id) const
Returns the object from the container locking it.
static GUIGlObjectStorage gIDStorage
A single static instance of this class.
static FXIcon * getIcon(const GUIIcon which)
returns a icon previously defined in the enum GUIIcon
void updateChildren(int msg=MID_SIMSTEP)
update childrens
void removeChild(FXMainWindow *child)
removes the given child window from the list (FXMainWindow)
void addChild(FXMainWindow *child)
Adds a further child window to the list (FXMainWindow)
Persists window position in the registry.
Storage for "selected" objects.
void save(GUIGlObjectType type, const std::string &filename)
Saves a selection list.
void clear()
Clears the list of selected objects.
void add2Update(UpdateTarget *updateTarget)
Adds a dialog to be updated.
void remove2Update()
Removes the dialog to be updated.
void deselect(GUIGlID id)
Deselects the object with the given id.
const std::unordered_set< GUIGlID > & getSelected() const
Returns the set of ids of all selected objects.
std::string load(const std::string &filename, GUIGlObjectType type=GLO_MAX, std::ostream *dynamicNotFound=nullptr)
Loads a selection list (optionally with restricted type)
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 StringBijection< TXTFileExtension > TXTFileExtensions
TXT file Extensions.