SUMO - Simulation of Urban MObility
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
GUIDialog_GLObjChooser.cpp
Go to the documentation of this file.
1 /****************************************************************************/
9 // Class for the window that allows to choose a street, junction or vehicle
10 /****************************************************************************/
11 // SUMO, Simulation of Urban MObility; see http://sumo-sim.org/
12 // Copyright (C) 2001-2014 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 <fxkeys.h>
44 #include "GUIDialog_GLObjChooser.h"
45 
46 #ifdef CHECK_MEMORY_LEAKS
47 #include <foreign/nvwa/debug_new.h>
48 #endif // CHECK_MEMORY_LEAKS
49 
50 
51 // ===========================================================================
52 // FOX callback mapping
53 // ===========================================================================
54 FXDEFMAP(GUIDialog_GLObjChooser) GUIDialog_GLObjChooserMap[] = {
56  FXMAPFUNC(SEL_COMMAND, MID_CANCEL, GUIDialog_GLObjChooser::onCmdClose),
57  FXMAPFUNC(SEL_CHANGED, MID_CHOOSER_TEXT, GUIDialog_GLObjChooser::onChgText),
58  FXMAPFUNC(SEL_COMMAND, MID_CHOOSER_TEXT, GUIDialog_GLObjChooser::onCmdText),
61 };
62 
63 FXIMPLEMENT(GUIDialog_GLObjChooser, FXMainWindow, GUIDialog_GLObjChooserMap, ARRAYNUMBER(GUIDialog_GLObjChooserMap))
64 
65 
66 // ===========================================================================
67 // method definitions
68 // ===========================================================================
70  GUIGlChildWindow* parent,
71  FXIcon* icon,
72  const FXString& title,
73  GUIGlObjectType type,
74  const std::vector<GUIGlID>& ids,
75  GUIGlObjectStorage& glStorage):
76  FXMainWindow(parent->getApp(), title, icon, NULL, DECOR_ALL, 20, 20, 300, 300),
77  myObjectType(type),
78  myParent(parent) {
79  FXHorizontalFrame* hbox = new FXHorizontalFrame(this, LAYOUT_FILL_X | LAYOUT_FILL_Y, 0, 0, 0, 0, 0, 0, 0, 0);
80  // build the list
81  FXVerticalFrame* layout1 = new FXVerticalFrame(hbox, LAYOUT_FILL_X | LAYOUT_FILL_Y | LAYOUT_TOP, 0, 0, 0, 0, 4, 4, 4, 4);
82  myTextEntry = new FXTextField(layout1, 0, this, MID_CHOOSER_TEXT, LAYOUT_FILL_X | FRAME_THICK | FRAME_SUNKEN);
83  FXVerticalFrame* style1 = new FXVerticalFrame(layout1, LAYOUT_FILL_X | LAYOUT_FILL_Y | LAYOUT_TOP | FRAME_THICK | FRAME_SUNKEN, 0, 0, 0, 0, 0, 0, 0, 0);
84  myList = new FXList(style1, this, MID_CHOOSER_LIST, LAYOUT_FILL_X | LAYOUT_FILL_Y | LIST_SINGLESELECT | FRAME_SUNKEN | FRAME_THICK);
85  for (std::vector<GUIGlID>::const_iterator i = ids.begin(); i != ids.end(); ++i) {
86  GUIGlObject* o = glStorage.getObjectBlocking(*i);
87  if (o == 0) {
88  continue;
89  }
90  const std::string& name = o->getMicrosimID();
91  bool selected = myParent->isSelected(o);
92  FXIcon* icon = selected ? GUIIconSubSys::getIcon(ICON_FLAG) : 0;
93  myIDs.insert(o->getGlID());
94  myList->appendItem(name.c_str(), icon, (void*) & (*myIDs.find(o->getGlID())));
95  glStorage.unblockObject(*i);
96  }
97  // build the buttons
98  FXVerticalFrame* layout = new FXVerticalFrame(hbox, LAYOUT_TOP, 0, 0, 0, 0, 4, 4, 4, 4);
99  myCenterButton = new FXButton(layout, "Center\t\t", GUIIconSubSys::getIcon(ICON_RECENTERVIEW),
100  this, MID_CHOOSER_CENTER, ICON_BEFORE_TEXT | LAYOUT_FILL_X | FRAME_THICK | FRAME_RAISED,
101  0, 0, 0, 0, 4, 4, 4, 4);
102  new FXHorizontalSeparator(layout, SEPARATOR_GROOVE | LAYOUT_FILL_X);
103  new FXButton(layout, "Hide Unselected\t\t", GUIIconSubSys::getIcon(ICON_FLAG),
104  this, MID_CHOOSER_FILTER, ICON_BEFORE_TEXT | LAYOUT_FILL_X | FRAME_THICK | FRAME_RAISED,
105  0, 0, 0, 0, 4, 4, 4, 4);
106  new FXHorizontalSeparator(layout, SEPARATOR_GROOVE | LAYOUT_FILL_X);
107  new FXButton(layout, "Close\t\t", GUIIconSubSys::getIcon(ICON_NO),
108  this, MID_CANCEL, ICON_BEFORE_TEXT | LAYOUT_FILL_X | FRAME_THICK | FRAME_RAISED,
109  0, 0, 0, 0, 4, 4, 4, 4);
110 
111  myParent->getParent()->addChild(this);
112 }
113 
114 
116  myParent->getParent()->removeChild(this);
117 }
118 
119 
120 void
122  FXMainWindow::show();
123  myTextEntry->setFocus();
124 }
125 
126 
127 long
129  int selected = myList->getCurrentItem();
130  if (selected >= 0) {
131  myParent->setView(*static_cast<GUIGlID*>(myList->getItemData(selected)));
132  }
133  return 1;
134 }
135 
136 
137 long
139  close(true);
140  return 1;
141 }
142 
143 
144 long
146  int id = myList->findItem(myTextEntry->getText(), -1, SEARCH_PREFIX);
147  if (id < 0) {
148  if (myList->getNumItems() > 0) {
149  myList->deselectItem(myList->getCurrentItem());
150  }
151  myCenterButton->disable();
152  return 1;
153  }
154  myList->deselectItem(myList->getCurrentItem());
155  myList->makeItemVisible(id);
156  myList->selectItem(id);
157  myList->setCurrentItem(id, true);
158  myCenterButton->enable();
159  return 1;
160 }
161 
162 
163 long
165  int current = myList->getCurrentItem();
166  if (current >= 0 && myList->isItemSelected(current)) {
167  myParent->setView(*static_cast<GUIGlID*>(myList->getItemData(current)));
168  }
169  return 1;
170 }
171 
172 
173 
174 long
176  FXEvent* event = (FXEvent*)ptr;
177  switch (event->code) {
178  case KEY_Return:
179  onCmdText(0, 0, 0);
180  break;
181  default:
182  break;
183  }
184  return 1;
185 }
186 
187 
188 long
191  std::vector<GUIGlID> selectedGlIDs;
192  std::vector<FXString> selectedMicrosimIDs;
193  const int numItems = myList->getNumItems();
194  for (int i = 0; i < numItems; i++) {
195  const GUIGlID glID = *static_cast<GUIGlID*>(myList->getItemData(i));
196  if (myList->getItemIcon(i) == flag) {
197  selectedGlIDs.push_back(glID);
198  selectedMicrosimIDs.push_back(myList->getItemText(i));
199  }
200  }
201  myList->clearItems();
202  const int numSelected = (const int)selectedGlIDs.size();
203  for (int i = 0; i < numSelected; i++) {
204  myList->appendItem(selectedMicrosimIDs[i], flag, (void*) & (*myIDs.find(selectedGlIDs[i])));
205  }
206  myList->update();
207  return 1;
208 }
209 
210 
211 /****************************************************************************/
212 
Filter selected.
Definition: GUIAppEnum.h:299
void show()
sets the focus after the window is created to work-around bug in libfox
GUIGlObjectType
long onCmdFilter(FXObject *, FXSelector, void *)
Callback: Hides unselected items if pressed.
const std::string & getMicrosimID() const
Returns the id of the object as known to microsim.
Definition: GUIGlObject.h:146
long onCmdCenter(FXObject *, FXSelector, void *)
Callback: The selected item shall be centered within the calling view.
FXDEFMAP(GUIDialog_GLObjChooser) GUIDialog_GLObjChooserMap[]
long onCmdText(FXObject *, FXSelector, void *)
Callback: Selects to current item if enter is pressed.
GUIGlID getGlID() const
Returns the numerical id of the object.
Definition: GUIGlObject.h:115
const unsigned char flag[]
Definition: flag.cpp:4
Object list.
Definition: GUIAppEnum.h:297
Text entry.
Definition: GUIAppEnum.h:295
GUIMainWindow * getParent()
Returns the main window.
FXList * myList
The list that holds the ids.
GUIGlChildWindow * myParent
The parent window.
void removeChild(FXMDIChild *child)
removes the given child window from the list
A storage for of displayed objects via their numerical id.
long onCmdClose(FXObject *, FXSelector, void *)
Callback: The dialog shall be closed.
Cancel-button pressed.
Definition: GUIAppEnum.h:65
unsigned int GUIGlID
Definition: GUIGlObject.h:48
void setView(GUIGlID id)
Centers the view onto the given artifact.
FXButton * myCenterButton
The button that triggers centering on the select object.
std::set< GUIGlID > myIDs
myList contains (void) pointers to elements of myIDs instead of the more
long onListKeyPress(FXObject *, FXSelector, void *)
Callback: Selects to current item if enter is pressed.
Center object.
Definition: GUIAppEnum.h:293
static FXIcon * getIcon(GUIIcon which)
FXTextField * myTextEntry
The text field.
long onChgText(FXObject *, FXSelector, void *)
Callback: Something has been typed into the the field.