Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
eclipse
GitHub Repository: eclipse/sumo
Path: blob/main/src/utils/gui/div/GUIDialog_GLChosenEditor.cpp
169684 views
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
/****************************************************************************/
14
/// @file GUIDialog_GLChosenEditor.cpp
15
/// @author Daniel Krajzewicz
16
/// @author Jakob Erdmann
17
/// @author Michael Behrisch
18
/// @date Thu, 11.03.2004
19
///
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>
29
#include <utils/common/MsgHandler.h>
30
#include <utils/gui/windows/GUIAppEnum.h>
31
#include <utils/gui/globjects/GUIGlObject.h>
32
#include <utils/foxtools/MFXUtils.h>
33
#include "GUIDialog_GLChosenEditor.h"
34
#include <utils/gui/div/GUIGlobalSelection.h>
35
#include <utils/gui/globjects/GUIGlObjectStorage.h>
36
#include <utils/gui/div/GUIIOGlobals.h>
37
#include <utils/gui/div/GUIDesigns.h>
38
#include <utils/gui/windows/GUIMainWindow.h>
39
#include <utils/gui/images/GUIIconSubSys.h>
40
41
42
// ===========================================================================
43
// FOX callback mapping
44
// ===========================================================================
45
FXDEFMAP(GUIDialog_GLChosenEditor) GUIDialog_GLChosenEditorMap[] = {
46
FXMAPFUNC(SEL_COMMAND, MID_CHOOSEN_LOAD, GUIDialog_GLChosenEditor::onCmdLoad),
47
FXMAPFUNC(SEL_COMMAND, MID_CHOOSEN_SAVE, GUIDialog_GLChosenEditor::onCmdSave),
48
FXMAPFUNC(SEL_COMMAND, MID_CHOOSEN_DESELECT, GUIDialog_GLChosenEditor::onCmdDeselect),
49
FXMAPFUNC(SEL_COMMAND, MID_CHOOSEN_CLEAR, GUIDialog_GLChosenEditor::onCmdClear),
50
FXMAPFUNC(SEL_COMMAND, MID_CANCEL, GUIDialog_GLChosenEditor::onCmdClose),
51
FXMAPFUNC(SEL_KEYPRESS, 0, GUIDialog_GLChosenEditor::onKeyPress),
52
};
53
54
FXIMPLEMENT(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
64
GUIDialog_GLChosenEditor::GUIDialog_GLChosenEditor(GUIMainWindow* parent, GUISelectedStorage* str) :
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);
76
rebuildList();
77
// build the layout
78
FXVerticalFrame* layout = new FXVerticalFrame(hbox, GUIDesignChooserLayoutRight);
79
// "Load"
80
GUIDesigns::buildFXButton(layout, TL("&Load selection"), "", "", GUIIconSubSys::getIcon(GUIIcon::OPEN), this, MID_CHOOSEN_LOAD, GUIDesignChooserButtons);
81
// "Save"
82
GUIDesigns::buildFXButton(layout, TL("&Save selection"), "", "", GUIIconSubSys::getIcon(GUIIcon::SAVE), this, MID_CHOOSEN_SAVE, GUIDesignChooserButtons);
83
// extra separator
84
new FXHorizontalSeparator(layout, GUIDesignHorizontalSeparator);
85
// "Deselect Chosen"
86
GUIDesigns::buildFXButton(layout, TL("&Deselect chosen"), "", "", GUIIconSubSys::getIcon(GUIIcon::FLAG), this, MID_CHOOSEN_DESELECT, GUIDesignChooserButtons);
87
// "Clear List"
88
GUIDesigns::buildFXButton(layout, TL("&Clear selection"), "", "", GUIIconSubSys::getIcon(GUIIcon::FLAG), this, MID_CHOOSEN_CLEAR, GUIDesignChooserButtons);
89
// extra separator
90
new FXHorizontalSeparator(layout, GUIDesignHorizontalSeparator);
91
// "Close"
92
GUIDesigns::buildFXButton(layout, TL("Cl&ose"), "", "", GUIIconSubSys::getIcon(GUIIcon::NO), this, MID_CANCEL, GUIDesignChooserButtons);
93
myParent->addChild(this);
94
loadWindowPos();
95
}
96
#ifdef _MSC_VER
97
#pragma warning(pop)
98
#endif
99
100
101
GUIDialog_GLChosenEditor::~GUIDialog_GLChosenEditor() {
102
myStorage->remove2Update();
103
myParent->removeChild(this);
104
}
105
106
107
void
108
GUIDialog_GLChosenEditor::rebuildList() {
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
123
void
124
GUIDialog_GLChosenEditor::selectionUpdated() {
125
rebuildList();
126
FXMainWindow::update();
127
}
128
129
130
long
131
GUIDialog_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
154
long
155
GUIDialog_GLChosenEditor::onCmdSave(FXObject*, FXSelector, void*) {
156
FXString file = MFXUtils::getFilename2Write(this, TL("Save List of selected Items"),
157
SUMOXMLDefinitions::TXTFileExtensions.getMultilineString().c_str(),
158
GUIIconSubSys::getIcon(GUIIcon::SAVE), gCurrentFolder);
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
171
long
172
GUIDialog_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
192
long
193
GUIDialog_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
203
long
204
GUIDialog_GLChosenEditor::onCmdClear(FXObject*, FXSelector, void*) {
205
myList->clearItems();
206
gSelected.clear();
207
myParent->updateChildren();
208
return 1;
209
}
210
211
212
long
213
GUIDialog_GLChosenEditor::onCmdClose(FXObject*, FXSelector, void*) {
214
close(true);
215
return 1;
216
}
217
218
219
/****************************************************************************/
220
221