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.sourceforge.net/
12 // Copyright (C) 2001-2012 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 _WIN32
48 #include <windows.h>
49 #endif
50 
51 #include <GL/gl.h>
52 
53 #ifdef CHECK_MEMORY_LEAKS
54 #include <foreign/nvwa/debug_new.h>
55 #endif // CHECK_MEMORY_LEAKS
56 
57 
58 // ===========================================================================
59 // FOX callback mapping
60 // ===========================================================================
61 FXDEFMAP(GUIDialog_GLChosenEditor) GUIDialog_GLChosenEditorMap[] = {
66  FXMAPFUNC(SEL_COMMAND, MID_CANCEL, GUIDialog_GLChosenEditor::onCmdClose),
67 };
68 
69 FXIMPLEMENT(GUIDialog_GLChosenEditor, FXMainWindow, GUIDialog_GLChosenEditorMap, ARRAYNUMBER(GUIDialog_GLChosenEditorMap))
70 
71 
72 // ===========================================================================
73 // method definitions
74 // ===========================================================================
76  GUISelectedStorage* str)
77  : FXMainWindow(parent->getApp(), "List of Selected Items", NULL, NULL, DECOR_ALL, 20, 20, 300, 300),
78  myParent(parent), myStorage(str) {
79  myStorage->add2Update(this);
80  FXHorizontalFrame* hbox =
81  new FXHorizontalFrame(this, LAYOUT_FILL_X | LAYOUT_FILL_Y, 0, 0, 0, 0,
82  0, 0, 0, 0);
83  // build the list
84  myList = new FXList(hbox, 0, 0,
85  LAYOUT_FILL_X | LAYOUT_FILL_Y | LIST_MULTIPLESELECT);
86  rebuildList();
87  // build the layout
88  FXVerticalFrame* layout = new FXVerticalFrame(hbox, LAYOUT_TOP, 0, 0, 0, 0,
89  4, 4, 4, 4);
90  // "Load"
91  new FXButton(layout, "Load\t\t", 0, this, MID_CHOOSEN_LOAD,
92  ICON_BEFORE_TEXT | LAYOUT_FILL_X | FRAME_THICK | FRAME_RAISED,
93  0, 0, 0, 0, 4, 4, 3, 3);
94  // "Save"
95  new FXButton(layout, "Save\t\t", 0, this, MID_CHOOSEN_SAVE,
96  ICON_BEFORE_TEXT | LAYOUT_FILL_X | FRAME_THICK | FRAME_RAISED,
97  0, 0, 0, 0, 4, 4, 3, 3);
98 
99  new FXHorizontalSeparator(layout, SEPARATOR_GROOVE | LAYOUT_FILL_X);
100 
101  // "Deselect Chosen"
102  new FXButton(layout, "Deselect Chosen\t\t", 0, this, MID_CHOOSEN_DESELECT,
103  ICON_BEFORE_TEXT | LAYOUT_FILL_X | FRAME_THICK | FRAME_RAISED,
104  0, 0, 0, 0, 4, 4, 3, 3);
105  // "Clear List"
106  new FXButton(layout, "Clear\t\t", 0, this, MID_CHOOSEN_CLEAR,
107  ICON_BEFORE_TEXT | LAYOUT_FILL_X | FRAME_THICK | FRAME_RAISED,
108  0, 0, 0, 0, 4, 4, 3, 3);
109 
110  new FXHorizontalSeparator(layout, SEPARATOR_GROOVE | LAYOUT_FILL_X);
111 
112  // "Close"
113  new FXButton(layout, "Close\t\t", 0, this, MID_CANCEL,
114  ICON_BEFORE_TEXT | LAYOUT_FILL_X | FRAME_THICK | FRAME_RAISED,
115  0, 0, 0, 0, 4, 4, 3, 3);
117  myParent->addChild(this);
118 }
119 
120 
123  myParent->removeChild(this);
124 }
125 
126 
127 void
129  myList->clearItems();
130  const std::set<GUIGlID> &chosen = gSelected.getSelected();
131  for (std::set<GUIGlID>::const_iterator i = chosen.begin(); i != chosen.end(); ++i) {
133  if (object != 0) {
134  std::string name = object->getFullName();
135  FXListItem* item = myList->getItem(myList->appendItem(name.c_str()));
136  item->setData(object);
138  }
139  }
140 }
141 
142 
143 void
145  rebuildList();
146  FXMainWindow::update();
147 }
148 
149 
150 long
152  // get the new file name
153  FXFileDialog opendialog(this, "Open List of Selected Items");
154  opendialog.setIcon(GUIIconSubSys::getIcon(ICON_EMPTY));
155  opendialog.setSelectMode(SELECTFILE_EXISTING);
156  opendialog.setPatternList("*.txt");
157  if (gCurrentFolder.length() != 0) {
158  opendialog.setDirectory(gCurrentFolder);
159  }
160  if (opendialog.execute()) {
161  gCurrentFolder = opendialog.getDirectory();
162  std::string file = opendialog.getFilename().text();
163  std::string msg = gSelected.load(file);
164  if (msg != "") {
165  FXMessageBox::error(this, MBOX_OK, "Errors while loading Selection", "%s", msg.c_str());
166  }
167  rebuildList();
168  }
169  return 1;
170 }
171 
172 
173 long
175  FXString file = MFXUtils::getFilename2Write(this, "Save List of selected Items", ".txt", GUIIconSubSys::getIcon(ICON_EMPTY), gCurrentFolder);
176  if (file == "") {
177  return 1;
178  }
179  try {
180  gSelected.save(file.text());
181  } catch (IOError& e) {
182  FXMessageBox::error(this, MBOX_OK, "Storing failed!", "%s", e.what());
183  }
184  return 1;
185 }
186 
187 
188 long
190  FXint no = myList->getNumItems();
191  FXint i;
192  std::vector<GUIGlID> selected;
193  for (i = 0; i < no; ++i) {
194  if (myList->getItem(i)->isSelected()) {
195  selected.push_back(static_cast<GUIGlObject*>(myList->getItem(i)->getData())->getGlID());
196  }
197  }
198  // remove items from list
199  for (i = 0; i < (FXint) selected.size(); ++i) {
200  gSelected.deselect(selected[i]);
201  }
202  // rebuild list
203  rebuildList();
205  return 1;
206 }
207 
208 
209 
210 long
212  myList->clearItems();
213  gSelected.clear();
215  return 1;
216 }
217 
218 
219 
220 long
222  close(true);
223  return 1;
224 }
225 
226 
227 
228 /****************************************************************************/
229