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>
28#include <fxkeys.h>
40
41
42// ===========================================================================
43// FOX callback mapping
44// ===========================================================================
45FXDEFMAP(GUIDialog_GLChosenEditor) GUIDialog_GLChosenEditorMap[] = {
50 FXMAPFUNC(SEL_COMMAND, MID_CANCEL, GUIDialog_GLChosenEditor::onCmdClose),
51 FXMAPFUNC(SEL_KEYPRESS, 0, GUIDialog_GLChosenEditor::onKeyPress),
52};
53
54FXIMPLEMENT(GUIDialog_GLChosenEditor, FXMainWindow, GUIDialog_GLChosenEditorMap, ARRAYNUMBER(GUIDialog_GLChosenEditorMap))
55
56
57// ===========================================================================
58// method definitions
59// ===========================================================================
60#ifdef _MSC_VER
61#pragma warning(push)
62#pragma warning(disable: 4355) // mask warning about "this" in initializers
63#endif
65 FXMainWindow(parent->getApp(), "List of Selected Items", GUIIconSubSys::getIcon(GUIIcon::APP_SELECTOR), nullptr, GUIDesignChooserDialog),
66 GUIPersistentWindowPos(this, "DIALOG_EDIT_SELECTED", true, 20, 40, 300, 350),
67 myParent(parent), myStorage(str) {
68 myStorage->add2Update(this);
69 FXHorizontalFrame* hbox = new FXHorizontalFrame(this, GUIDesignAuxiliarFrame);
70 // create layout left
71 FXVerticalFrame* layoutLeft = new FXVerticalFrame(hbox, GUIDesignChooserLayoutLeft);
72 // create frame for list
73 FXVerticalFrame* layoutList = new FXVerticalFrame(layoutLeft, GUIDesignChooserLayoutList);
74 // build the list and rebuild it
75 myList = new FXList(layoutList, this, MID_CHOOSER_LIST, GUIDesignChooserListMultiple);
77 // build the layout
78 FXVerticalFrame* layout = new FXVerticalFrame(hbox, GUIDesignChooserLayoutRight);
79 // "Load"
81 // "Save"
83 // extra separator
84 new FXHorizontalSeparator(layout, GUIDesignHorizontalSeparator);
85 // "Deselect Chosen"
87 // "Clear List"
89 // extra separator
90 new FXHorizontalSeparator(layout, GUIDesignHorizontalSeparator);
91 // "Close"
93 myParent->addChild(this);
95}
96#ifdef _MSC_VER
97#pragma warning(pop)
98#endif
99
100
102 myStorage->remove2Update();
103 myParent->removeChild(this);
104}
105
106
107void
109 myList->clearItems();
110 const auto& chosen = gSelected.getSelected();
111 for (auto i : chosen) {
112 GUIGlObject* object = GUIGlObjectStorage::gIDStorage.getObjectBlocking(i);
113 if (object != nullptr) {
114 std::string name = object->getFullName();
115 FXListItem* item = myList->getItem(myList->appendItem(name.c_str()));
116 item->setData(object);
117 GUIGlObjectStorage::gIDStorage.unblockObject(i);
118 }
119 }
120}
121
122
123void
125 rebuildList();
126 FXMainWindow::update();
127}
128
129
130long
131GUIDialog_GLChosenEditor::onCmdLoad(FXObject*, FXSelector, void*) {
132 // get the new file name
133 FXFileDialog opendialog(this, TL("Open List of Selected Items"));
134 opendialog.setIcon(GUIIconSubSys::getIcon(GUIIcon::OPEN));
135 opendialog.setSelectMode(SELECTFILE_EXISTING);
136 opendialog.setPatternList(SUMOXMLDefinitions::TXTFileExtensions.getMultilineString().c_str());
137 if (gCurrentFolder.length() != 0) {
138 opendialog.setDirectory(gCurrentFolder);
139 }
140 if (opendialog.execute()) {
141 gCurrentFolder = opendialog.getDirectory();
142 std::string file = opendialog.getFilename().text();
143 std::string msg = gSelected.load(file);
144 if (msg != "") {
145 FXMessageBox::error(this, MBOX_OK, TL("Errors while loading Selection"), "%s", msg.c_str());
146 }
147 rebuildList();
148 myParent->updateChildren();
149 }
150 return 1;
151}
152
153
154long
155GUIDialog_GLChosenEditor::onCmdSave(FXObject*, FXSelector, void*) {
156 FXString file = MFXUtils::getFilename2Write(this, TL("Save List of selected Items"),
157 SUMOXMLDefinitions::TXTFileExtensions.getMultilineString().c_str(),
159 if (file == "") {
160 return 1;
161 }
162 try {
163 gSelected.save(file.text());
164 } catch (IOError& e) {
165 FXMessageBox::error(this, MBOX_OK, TL("Storing failed!"), "%s", e.what());
166 }
167 return 1;
168}
169
170
171long
172GUIDialog_GLChosenEditor::onCmdDeselect(FXObject*, FXSelector, void*) {
173 FXint no = myList->getNumItems();
174 FXint i;
175 std::vector<GUIGlID> selected;
176 for (i = 0; i < no; ++i) {
177 if (myList->getItem(i)->isSelected()) {
178 selected.push_back(static_cast<GUIGlObject*>(myList->getItem(i)->getData())->getGlID());
179 }
180 }
181 // remove items from list
182 for (i = 0; i < (FXint) selected.size(); ++i) {
183 gSelected.deselect(selected[i]);
184 }
185 // rebuild list
186 rebuildList();
187 myParent->updateChildren();
188 return 1;
189}
190
191
192long
193GUIDialog_GLChosenEditor::onKeyPress(FXObject* o, FXSelector sel, void* ptr) {
194 const FXEvent* e = (FXEvent*) ptr;
195 if(e->code==KEY_Escape){
196 onCmdClose(nullptr, 0, nullptr);
197 return 1;
198 }
199 return FXMainWindow::onKeyPress(o, sel, ptr);
200}
201
202
203long
204GUIDialog_GLChosenEditor::onCmdClear(FXObject*, FXSelector, void*) {
205 myList->clearItems();
206 gSelected.clear();
207 myParent->updateChildren();
208 return 1;
209}
210
211
212long
213GUIDialog_GLChosenEditor::onCmdClose(FXObject*, FXSelector, void*) {
214 close(true);
215 return 1;
216}
217
218
219/****************************************************************************/
@ MID_CANCEL
Cancel-button pressed.
Definition GUIAppEnum.h:310
@ MID_CHOOSEN_SAVE
Save set.
Definition GUIAppEnum.h:605
@ MID_CHOOSEN_DESELECT
Deselect selected items.
Definition GUIAppEnum.h:615
@ MID_CHOOSER_LIST
Object list.
Definition GUIAppEnum.h:587
@ MID_CHOOSEN_LOAD
Load set.
Definition GUIAppEnum.h:603
@ MID_CHOOSEN_CLEAR
Clear set.
Definition GUIAppEnum.h:607
#define GUIDesignChooserButtons
design for Chooser buttons
Definition GUIDesigns.h:664
#define GUIDesignChooserLayoutLeft
design for Chooser Layout left
Definition GUIDesigns.h:679
#define GUIDesignChooserLayoutRight
design for Chooser Layout right
Definition GUIDesigns.h:682
#define GUIDesignHorizontalSeparator
Definition GUIDesigns.h:494
#define GUIDesignChooserLayoutList
design for Chooser Layout list
Definition GUIDesigns.h:685
#define GUIDesignAuxiliarFrame
design for auxiliar (Without borders) frame extended in all directions
Definition GUIDesigns.h:409
#define GUIDesignChooserDialog
Definition GUIDesigns.h:661
#define GUIDesignChooserListMultiple
design for Chooser List
Definition GUIDesigns.h:673
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
Definition GUIIcons.h:203
@ OPEN
open icons
Definition GUIIcons.h:77
@ SAVE
save icons
Definition GUIIcons.h:90
#define TL(string)
Definition MsgHandler.h:304
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.
long onKeyPress(FXObject *o, FXSelector sel, void *data)
keyboard functions
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.
GUIGlID getGlID() const
Returns the numerical id of the object.
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
GUIPersistentWindowPos(FXWindow *parent, const std::string &name, bool storeSize, int x=150, int y=150, int width=700, int height=500, int minSize=400, int minTitlebarHeight=20)
Constructor (Notifies both the parent and the storage about being initialised).
Storage for "selected" objects.
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.