SUMO - Simulation of Urban MObility
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.dlr.de/
12 // Copyright (C) 2001-2015 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  const std::vector<GUIGlID>& ids,
74  GUIGlObjectStorage& glStorage):
75  FXMainWindow(parent->getApp(), title, icon, NULL, DECOR_ALL, 20, 20, 300, 300),
76  myParent(parent) {
77  FXHorizontalFrame* hbox = new FXHorizontalFrame(this, LAYOUT_FILL_X | LAYOUT_FILL_Y, 0, 0, 0, 0, 0, 0, 0, 0);
78  // build the list
79  FXVerticalFrame* layout1 = new FXVerticalFrame(hbox, LAYOUT_FILL_X | LAYOUT_FILL_Y | LAYOUT_TOP, 0, 0, 0, 0, 4, 4, 4, 4);
80  myTextEntry = new FXTextField(layout1, 0, this, MID_CHOOSER_TEXT, LAYOUT_FILL_X | FRAME_THICK | FRAME_SUNKEN);
81  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);
82  myList = new FXList(style1, this, MID_CHOOSER_LIST, LAYOUT_FILL_X | LAYOUT_FILL_Y | LIST_SINGLESELECT | FRAME_SUNKEN | FRAME_THICK);
83  for (std::vector<GUIGlID>::const_iterator i = ids.begin(); i != ids.end(); ++i) {
84  GUIGlObject* o = glStorage.getObjectBlocking(*i);
85  if (o == 0) {
86  continue;
87  }
88  const std::string& name = o->getMicrosimID();
89  bool selected = myParent->isSelected(o);
90  FXIcon* icon = selected ? GUIIconSubSys::getIcon(ICON_FLAG) : 0;
91  myIDs.insert(o->getGlID());
92  myList->appendItem(name.c_str(), icon, (void*) & (*myIDs.find(o->getGlID())));
93  glStorage.unblockObject(*i);
94  }
95  // build the buttons
96  FXVerticalFrame* layout = new FXVerticalFrame(hbox, LAYOUT_TOP, 0, 0, 0, 0, 4, 4, 4, 4);
97  myCenterButton = new FXButton(layout, "Center\t\t", GUIIconSubSys::getIcon(ICON_RECENTERVIEW),
98  this, MID_CHOOSER_CENTER, ICON_BEFORE_TEXT | LAYOUT_FILL_X | FRAME_THICK | FRAME_RAISED,
99  0, 0, 0, 0, 4, 4, 4, 4);
100  new FXHorizontalSeparator(layout, SEPARATOR_GROOVE | LAYOUT_FILL_X);
101  new FXButton(layout, "Hide Unselected\t\t", GUIIconSubSys::getIcon(ICON_FLAG),
102  this, MID_CHOOSER_FILTER, ICON_BEFORE_TEXT | LAYOUT_FILL_X | FRAME_THICK | FRAME_RAISED,
103  0, 0, 0, 0, 4, 4, 4, 4);
104  new FXHorizontalSeparator(layout, SEPARATOR_GROOVE | LAYOUT_FILL_X);
105  new FXButton(layout, "Close\t\t", GUIIconSubSys::getIcon(ICON_NO),
106  this, MID_CANCEL, ICON_BEFORE_TEXT | LAYOUT_FILL_X | FRAME_THICK | FRAME_RAISED,
107  0, 0, 0, 0, 4, 4, 4, 4);
108 
109  myParent->getParent()->addChild(this);
110 }
111 
112 
114  myParent->getParent()->removeChild(this);
115 }
116 
117 
118 void
120  FXMainWindow::show();
121  myTextEntry->setFocus();
122 }
123 
124 
125 long
127  int selected = myList->getCurrentItem();
128  if (selected >= 0) {
129  myParent->setView(*static_cast<GUIGlID*>(myList->getItemData(selected)));
130  }
131  return 1;
132 }
133 
134 
135 long
137  close(true);
138  return 1;
139 }
140 
141 
142 long
144  int id = myList->findItem(myTextEntry->getText(), -1, SEARCH_PREFIX);
145  if (id < 0) {
146  if (myList->getNumItems() > 0) {
147  myList->deselectItem(myList->getCurrentItem());
148  }
149  myCenterButton->disable();
150  return 1;
151  }
152  myList->deselectItem(myList->getCurrentItem());
153  myList->makeItemVisible(id);
154  myList->selectItem(id);
155  myList->setCurrentItem(id, true);
156  myCenterButton->enable();
157  return 1;
158 }
159 
160 
161 long
163  int current = myList->getCurrentItem();
164  if (current >= 0 && myList->isItemSelected(current)) {
165  myParent->setView(*static_cast<GUIGlID*>(myList->getItemData(current)));
166  }
167  return 1;
168 }
169 
170 
171 
172 long
174  FXEvent* event = (FXEvent*)ptr;
175  switch (event->code) {
176  case KEY_Return:
177  onCmdText(0, 0, 0);
178  break;
179  default:
180  break;
181  }
182  return 1;
183 }
184 
185 
186 long
189  std::vector<GUIGlID> selectedGlIDs;
190  std::vector<FXString> selectedMicrosimIDs;
191  const int numItems = myList->getNumItems();
192  for (int i = 0; i < numItems; i++) {
193  const GUIGlID glID = *static_cast<GUIGlID*>(myList->getItemData(i));
194  if (myList->getItemIcon(i) == flag) {
195  selectedGlIDs.push_back(glID);
196  selectedMicrosimIDs.push_back(myList->getItemText(i));
197  }
198  }
199  myList->clearItems();
200  const int numSelected = (const int)selectedGlIDs.size();
201  for (int i = 0; i < numSelected; i++) {
202  myList->appendItem(selectedMicrosimIDs[i], flag, (void*) & (*myIDs.find(selectedGlIDs[i])));
203  }
204  myList->update();
205  return 1;
206 }
207 
208 
209 /****************************************************************************/
210 
void show()
sets the focus after the window is created to work-around bug in libfox
long onCmdFilter(FXObject *, FXSelector, void *)
Callback: Hides unselected items if pressed.
Object list.
Definition: GUIAppEnum.h:307
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:24
GUIMainWindow * getParent()
Returns the main window.
FXList * myList
The list that holds the ids.
Cancel-button pressed.
Definition: GUIAppEnum.h:65
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.
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
Center object.
Definition: GUIAppEnum.h:303
Text entry.
Definition: GUIAppEnum.h:305
long onListKeyPress(FXObject *, FXSelector, void *)
Callback: Selects to current item if enter is pressed.
Filter selected.
Definition: GUIAppEnum.h:309
static FXIcon * getIcon(GUIIcon which)
FXTextField * myTextEntry
The text field.
long onChgText(FXObject *, FXSelector, void *)
Callback: Something has been typed into the the field.