Structural deformable models
sensordlg.cpp
Go to the documentation of this file.
1 #include <iostream>
2 #include <sstream>
3 #include "sensordlg.h"
4 #include "common.h"
5 #include <FXInputDialog.h>
6 #include "deform.h"
7 
8 using namespace std;
9 
10 // Message Map
11 FXDEFMAP(SensorDialog) SensorDialogMap[]={
12  //____Message_Type______________ID_______________Message_Handler___
13  FXMAPFUNC(SEL_COMMAND, SensorDialog::ID_SENSEDIT, SensorDialog::onEdit),
14  FXMAPFUNC(SEL_COMMAND, SensorDialog::ID_SENSSEL, SensorDialog::onEdit)
15 };
16 
17 // SensorDialog implementation
18 FXIMPLEMENT(SensorDialog,FXDialogBox,SensorDialogMap,
19  ARRAYNUMBER(SensorDialogMap))
20 
21 
23 : FXDialogBox (a, "Sensor Editor",DECOR_TITLE|DECOR_BORDER,0,0,400,0),
24  m_Sensors(sc), m_SList(NULL), m_ImgWin(iw), m_PGeomMutex(NULL)
25 {
26  FXHorizontalFrame* contents=new FXHorizontalFrame(
27  this,LAYOUT_SIDE_TOP|LAYOUT_FILL_X|LAYOUT_FILL_Y,0,0,0,0, 0,0,0,0);
28  m_SList = new FXListBox(contents, this, ID_SENSSEL,
29  LISTBOX_NORMAL|LAYOUT_FILL_X);
30  m_SList->setNumVisible(5);
31  m_SList->setWidth(400);
32  new FXButton(contents, "&Edit",NULL, this, ID_SENSEDIT);
33  new FXButton(contents, "&Hide",NULL, this, ID_HIDE);
34  updateStrings();
35 }
36 
38 {
39  if(m_SList) { delete m_SList; m_SList = NULL; }
40 }
41 
42 long SensorDialog::onEdit(FXObject*,FXSelector sel,void* ptr)
43 {
44  if(sel == MKUINT(ID_SENSSEL,SEL_COMMAND)) {
45  vuMutex blah;
46  vuLock(m_PGeomMutex ? *m_PGeomMutex : blah);
47  if(m_ImgWin) m_ImgWin->selectSensor(getSelectedSensor());
48  } else {
49  FXInputDialog inpd(this, "Edit Sensor", "Sensor string");
50  inpd.setText(m_SList->getItem(m_SList->getCurrentItem()));
51  if(inpd.execute()) {
52  vuMutex blah;
53  vuLock(m_PGeomMutex ? *m_PGeomMutex : blah);
54  stringstream ss;
55  ss << inpd.getText().text();
56  ParseFile pf(ss);
57  sensor_ptr sensor = m_Sensors.readSensor(pf);
58  if(sensor) {
59  sensor = m_Sensors.addSensor(sensor);
60  m_Sensors.updateModels();
61  //if(m_ImgWin) m_ImgWin->selectSensor(getSelectedSensor());
62  //m_SList->setItemText(m_SList->getCurrentItem(),
63  // inpd.getText());
64  updateStrings();
65  }
66  }
67  }
68  return 1;
69 }
70 
72 {
73  m_SIndices.clear();
74  m_SList->clearItems();
75  int sid=0;
76  for(SensorCollection::const_iterator s=m_Sensors.begin();
77  s!=m_Sensors.end();s++,sid++)
78  {
79  if(s->second->getID() != "0" && // zero sensor
80  s->second->getID() != "d0" &&
81  !s->second->getID().empty())
82  {
83  stringstream ss;
84  s->second->print(ss);
85  m_SList->appendItem(ss.str().c_str());
86  //cout << sid <<": " << ss.str() << endl;
87  m_SIndices.push_back(sid);
88  }
89  }
90  m_SList->appendItem("# new sensor #");
91  m_SIndices.push_back(sid);
92  m_SList->setNumVisible(m_SList->getNumItems());
93 
94 }
95 
97  return shown() ? m_SIndices[m_SList->getCurrentItem()] : -1;
98 }
#define NULL
Definition: simpletypes.h:9
STL namespace.
Definition: Sensor.h:21
std::shared_ptr< Sensor > sensor_ptr
Definition: types_fwd.h:15
FXIMPLEMENT(SensorDialog, FXDialogBox, SensorDialogMap, ARRAYNUMBER(SensorDialogMap)) SensorDialog
Definition: sensordlg.cpp:18
virtual ~SensorDialog()
Definition: sensordlg.cpp:37
int getSelectedSensor() const
Definition: sensordlg.cpp:96
void updateStrings()
Definition: sensordlg.cpp:71
long onEdit(FXObject *, FXSelector, void *ptr)
Definition: sensordlg.cpp:42
FXDEFMAP(SensorDialog) SensorDialogMap[]