SUMO - Simulation of Urban MObility
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
GUIDialog_GLChosenEditor.cpp
Go to the documentation of this file.
1 /****************************************************************************/
9 // Editor for the list of chosen objects
10 /****************************************************************************/
11 // SUMO, Simulation of Urban MObility; see http://sumo-sim.org/
12 // Copyright (C) 2001-2013 DLR (http://www.dlr.de/) and contributors
13 /****************************************************************************/
14 //
15 // This file is part of SUMO.
16 // SUMO is free software: you can redistribute it and/or modify
17 // it under the terms of the GNU General Public License as published by
18 // the Free Software Foundation, either version 3 of the License, or
19 // (at your option) any later version.
20 //
21 /****************************************************************************/
22 
23 
24 // ===========================================================================
25 // included modules
26 // ===========================================================================
27 #ifdef _MSC_VER
28 #include <windows_config.h>
29 #else
30 #include <config.h>
31 #endif
32 
33 #include <string>
34 #include <vector>
35 #include <iostream>
36 #include <fstream>
46 
47 #ifdef CHECK_MEMORY_LEAKS
48 #include <foreign/nvwa/debug_new.h>
49 #endif // CHECK_MEMORY_LEAKS
50 
51 
52 // ===========================================================================
53 // FOX callback mapping
54 // ===========================================================================
55 FXDEFMAP(GUIDialog_GLChosenEditor) GUIDialog_GLChosenEditorMap[] = {
60  FXMAPFUNC(SEL_COMMAND, MID_CANCEL, GUIDialog_GLChosenEditor::onCmdClose),
61 };
62 
63 FXIMPLEMENT(GUIDialog_GLChosenEditor, FXMainWindow, GUIDialog_GLChosenEditorMap, ARRAYNUMBER(GUIDialog_GLChosenEditorMap))
64 
65 
66 // ===========================================================================
67 // method definitions
68 // ===========================================================================
70  GUISelectedStorage* str)
71  : FXMainWindow(parent->getApp(), "List of Selected Items", NULL, NULL, DECOR_ALL, 20, 20, 300, 300),
72  myParent(parent), myStorage(str) {
73  myStorage->add2Update(this);
74  FXHorizontalFrame* hbox =
75  new FXHorizontalFrame(this, LAYOUT_FILL_X | LAYOUT_FILL_Y, 0, 0, 0, 0,
76  0, 0, 0, 0);
77  // build the list
78  myList = new FXList(hbox, 0, 0,
79  LAYOUT_FILL_X | LAYOUT_FILL_Y | LIST_MULTIPLESELECT);
80  rebuildList();
81  // build the layout
82  FXVerticalFrame* layout = new FXVerticalFrame(hbox, LAYOUT_TOP, 0, 0, 0, 0,
83  4, 4, 4, 4);
84  // "Load"
85  new FXButton(layout, "Load\t\t", 0, this, MID_CHOOSEN_LOAD,
86  ICON_BEFORE_TEXT | LAYOUT_FILL_X | FRAME_THICK | FRAME_RAISED,
87  0, 0, 0, 0, 4, 4, 3, 3);
88  // "Save"
89  new FXButton(layout, "Save\t\t", 0, this, MID_CHOOSEN_SAVE,
90  ICON_BEFORE_TEXT | LAYOUT_FILL_X | FRAME_THICK | FRAME_RAISED,
91  0, 0, 0, 0, 4, 4, 3, 3);
92 
93  new FXHorizontalSeparator(layout, SEPARATOR_GROOVE | LAYOUT_FILL_X);
94 
95  // "Deselect Chosen"
96  new FXButton(layout, "Deselect Chosen\t\t", 0, this, MID_CHOOSEN_DESELECT,
97  ICON_BEFORE_TEXT | LAYOUT_FILL_X | FRAME_THICK | FRAME_RAISED,
98  0, 0, 0, 0, 4, 4, 3, 3);
99  // "Clear List"
100  new FXButton(layout, "Clear\t\t", 0, this, MID_CHOOSEN_CLEAR,
101  ICON_BEFORE_TEXT | LAYOUT_FILL_X | FRAME_THICK | FRAME_RAISED,
102  0, 0, 0, 0, 4, 4, 3, 3);
103 
104  new FXHorizontalSeparator(layout, SEPARATOR_GROOVE | LAYOUT_FILL_X);
105 
106  // "Close"
107  new FXButton(layout, "Close\t\t", 0, this, MID_CANCEL,
108  ICON_BEFORE_TEXT | LAYOUT_FILL_X | FRAME_THICK | FRAME_RAISED,
109  0, 0, 0, 0, 4, 4, 3, 3);
111  myParent->addChild(this);
112 }
113 
114 
117  myParent->removeChild(this);
118 }
119 
120 
121 void
123  myList->clearItems();
124  const std::set<GUIGlID>& chosen = gSelected.getSelected();
125  for (std::set<GUIGlID>::const_iterator i = chosen.begin(); i != chosen.end(); ++i) {
127  if (object != 0) {
128  std::string name = object->getFullName();
129  FXListItem* item = myList->getItem(myList->appendItem(name.c_str()));
130  item->setData(object);
132  }
133  }
134 }
135 
136 
137 void
139  rebuildList();
140  FXMainWindow::update();
141 }
142 
143 
144 long
146  // get the new file name
147  FXFileDialog opendialog(this, "Open List of Selected Items");
148  opendialog.setIcon(GUIIconSubSys::getIcon(ICON_EMPTY));
149  opendialog.setSelectMode(SELECTFILE_EXISTING);
150  opendialog.setPatternList("*.txt");
151  if (gCurrentFolder.length() != 0) {
152  opendialog.setDirectory(gCurrentFolder);
153  }
154  if (opendialog.execute()) {
155  gCurrentFolder = opendialog.getDirectory();
156  std::string file = opendialog.getFilename().text();
157  std::string msg = gSelected.load(file);
158  if (msg != "") {
159  FXMessageBox::error(this, MBOX_OK, "Errors while loading Selection", "%s", msg.c_str());
160  }
161  rebuildList();
162  }
163  return 1;
164 }
165 
166 
167 long
169  FXString file = MFXUtils::getFilename2Write(this, "Save List of selected Items", ".txt", GUIIconSubSys::getIcon(ICON_EMPTY), gCurrentFolder);
170  if (file == "") {
171  return 1;
172  }
173  try {
174  gSelected.save(file.text());
175  } catch (IOError& e) {
176  FXMessageBox::error(this, MBOX_OK, "Storing failed!", "%s", e.what());
177  }
178  return 1;
179 }
180 
181 
182 long
184  FXint no = myList->getNumItems();
185  FXint i;
186  std::vector<GUIGlID> selected;
187  for (i = 0; i < no; ++i) {
188  if (myList->getItem(i)->isSelected()) {
189  selected.push_back(static_cast<GUIGlObject*>(myList->getItem(i)->getData())->getGlID());
190  }
191  }
192  // remove items from list
193  for (i = 0; i < (FXint) selected.size(); ++i) {
194  gSelected.deselect(selected[i]);
195  }
196  // rebuild list
197  rebuildList();
199  return 1;
200 }
201 
202 
203 
204 long
206  myList->clearItems();
207  gSelected.clear();
209  return 1;
210 }
211 
212 
213 
214 long
216  close(true);
217  return 1;
218 }
219 
220 
221 
222 /****************************************************************************/
223