#include <trackingmanipulator.h>
Gui parameters are used to establish connection between transformations of tracked devices and scene nodes
Definition at line 17 of file trackingmanipulator.h.
| TrackingManipulator::TrackingManipulator | ( | const MODULE_ID & | _id, | |
| const wxString & | _name, | |||
| EventHandler * | msgSink | |||
| ) |
Constructor.
Definition at line 14 of file trackingmanipulator.cpp.
00014 : 00015 SceneModule(_id, _name, 0, msgSink) 00016 { 00017 REGISTER_LISTENER(Event::EVT_INPUT_TRACKING); 00018 REGISTER_PARAM_GUI_TEXTCONTROL(sceneNodeIDParamID, wxT("sceneNodeID"), wxT("0"), wxT("ID of scene node to manipulate.")); 00019 sceneNodeID = 0; 00020 REGISTER_PARAM_GUI_TEXTCONTROL(deviceIDParamID, wxT("deviceID"), wxT("0"), wxT("ID of tracking device.")); 00021 deviceID = 0; 00022 REGISTER_PARAM_GUI_TEXTCONTROL(deviceTypeParamID, wxT("deviceType"), wxT("0"), wxT("Type of tracking device.")); 00023 deviceType = 0; 00024 REGISTER_PARAM_GUI_TEXTCONTROL(transformationModeParamID, wxT("transformationMode"), wxT("0"), wxT("transformationMode")); 00025 transformationMode = 0; 00026 REGISTER_PARAM_GUI_TEXTCONTROL(pressedButtonsParamID, wxT("pressedButtons"), wxT("0"), wxT("pressedButtons")); 00027 pressedButtons = 0; 00028 REGISTER_PARAM_GUI_TEXTCONTROL(releasedButtonsParamID, wxT("releasedButtons"), wxT("0"), wxT("releasedButtons")); 00029 releasedButtons = 0; 00030 REGISTER_PARAM_GUI_TEXTCONTROL(control1ParamID, wxT("control1"), wxT("0.0"), wxT("control1")); 00031 control1 = 0; 00032 REGISTER_PARAM_GUI_TEXTCONTROL(control2ParamID, wxT("control2"), wxT("0.0"), wxT("control2")); 00033 control2 = 0; 00034 REGISTER_PARAM_GUI_TEXTCONTROL(scaleParamID, wxT("scale"), wxT("1.0"), wxT("scale")); 00035 scale = 1; 00036 REGISTER_PARAM_GUI_BUTTON(insertParamID, wxT("insert"), wxT("insert")); 00037 REGISTER_PARAM_GUI_BUTTON(removeParamID, wxT("remove"), wxT("remove")); 00038 REGISTER_PARAM_GUI_BUTTON(clearParamID, wxT("clear"), wxT("clear")); 00039 REGISTER_PARAM_GUI_BUTTON(dumpParamID, wxT("dump"), wxT("dump")); 00040 REGISTER_PARAM_GUI_BUTTON(loadParamID, wxT("load"), wxT("load")); 00041 REGISTER_PARAM_GUI_BUTTON(saveParamID, wxT("save"), wxT("save")); 00042 00043 insert = remove = dump = load = save = clear = 0 ; 00044 eventTimeout = 20; 00045 } void TrackingManipulator::processEvent(wxCommandEvent &evt)
| TrackingManipulator::~TrackingManipulator | ( | ) | [virtual] |
| void TrackingManipulator::processEvent | ( | wxCommandEvent & | evt | ) | [protected, virtual] |
process events
Reimplemented from VRUT::SceneModule.
Definition at line 46 of file trackingmanipulator.cpp.
00047 { 00048 SceneModule::processEvent(evt); 00049 switch (evt.GetEventType()) 00050 { 00051 //Remember to process registered param update events 00052 case Event::EVT_PARAM_SET: 00053 { 00054 insert = remove = dump = load = save = clear = 0; 00055 UPDATE_PARAM_FROM_EVENT_INT(sceneNodeIDParamID, sceneNodeID, evt); 00056 UPDATE_PARAM_FROM_EVENT_INT(deviceIDParamID, deviceID, evt); 00057 UPDATE_PARAM_FROM_EVENT_INT(deviceTypeParamID, deviceType,evt); 00058 UPDATE_PARAM_FROM_EVENT_INT(transformationModeParamID, transformationMode,evt); 00059 UPDATE_PARAM_FROM_EVENT_INT(pressedButtonsParamID, pressedButtons, evt); 00060 UPDATE_PARAM_FROM_EVENT_INT(releasedButtonsParamID, releasedButtons,evt); 00061 UPDATE_PARAM_FROM_EVENT_FLOAT(control1ParamID, control1, evt); 00062 UPDATE_PARAM_FROM_EVENT_FLOAT(control2ParamID, control2, evt); 00063 UPDATE_PARAM_FROM_EVENT_FLOAT(scaleParamID, scale, evt); 00064 UPDATE_PARAM_FROM_EVENT_INT(insertParamID, insert, evt); 00065 UPDATE_PARAM_FROM_EVENT_INT(removeParamID, remove, evt); 00066 UPDATE_PARAM_FROM_EVENT_INT(dumpParamID, dump, evt); 00067 UPDATE_PARAM_FROM_EVENT_INT(loadParamID, load, evt); 00068 UPDATE_PARAM_FROM_EVENT_INT(saveParamID, save, evt); 00069 UPDATE_PARAM_FROM_EVENT_INT(clearParamID, clear, evt); 00070 00071 if (0 != insert) 00072 { 00073 if (!checkScene()) LOGWARNING(wxT("<TrackingManipulator> sceneID is not valid!")); 00074 if (!checkNodeInScene(sceneID)) LOGWARNING(wxT("<TrackingManipulator> sceneNodeID is not valid!")); 00075 bool added = mapTable.InsertLine(deviceID, (Body::BodyType)deviceType, sceneID, sceneNodeID, pressedButtons, releasedButtons, control1, control2, (TTableEntry::TransformMode)transformationMode, scale); 00076 if (added) LOG(wxT("<TrackingManipulator> Entry was inserted to table.")); 00077 else LOG(wxT("<TrackingManipulator> Entry has been already added before.")); 00078 } 00079 else if (0 != remove) 00080 { 00081 bool del = mapTable.EraseLine(deviceID, (Body::BodyType)deviceType, sceneID, sceneNodeID, pressedButtons, releasedButtons, control1, control2, (TTableEntry::TransformMode)transformationMode, scale); 00082 if(del) 00083 { 00084 LOG(wxT("<TrackingManipulator> Entry deleted from table.")); 00085 // delete all other lines (duplicities) from the table 00086 while(mapTable.EraseLine(deviceID, (Body::BodyType)deviceType, sceneID, sceneNodeID, pressedButtons, releasedButtons, control1, control2, (TTableEntry::TransformMode)transformationMode, scale)) 00087 { 00088 LOG(wxT("<TrackingManipulator> Entry deleted from table.")); 00089 } 00090 } 00091 else LOG(wxT("<TrackingManipulator> Entry is not in table.")); 00092 // remove entry from table 00093 } 00094 else if ( 0 != dump) 00095 { 00096 mapTable.WriteToLog(); 00097 //LOG(wxT("<TrackingManipulator> Table:\n scene\tnode\tdevice\ttype\tmode\tpressed\treleased\tctrl1\tctrl2\tscale\n")+ mapTable.GetAsString("\n", "\t")); 00098 } 00099 else if (0 != clear) 00100 { 00101 mapTable.ClearTable(); 00102 LOG(wxT("<TrackingManipulator> Table deleted!")); 00103 } 00104 else if (0 != save) 00105 { 00106 if (!saveTableToConfigFile()) 00107 { 00108 LOGERROR(wxT("<TrackingManipulator>Can't write to configuration file!")); 00109 } 00110 else 00111 { 00112 LOG(wxT("<TrackingManipulator> Table configuration saved")); 00113 } 00114 } 00115 else if (0 != load) 00116 { 00117 int numberOfEntries; 00118 bool loaded =loadTableFromConfigFile(numberOfEntries); 00119 if (loaded) 00120 { 00121 LOG(wxString::Format(wxT("<TrackingManipulator> Successfuly loaded table configuration. Entries: %i"), numberOfEntries)); 00122 } 00123 else 00124 { 00125 if (numberOfEntries < 0) LOGERROR(wxT("<TrackingManipulator> Table configuration file were not opened. No changes on table were done!")); 00126 else LOGWARNING(wxString::Format(wxT("<TrackingManipulator> Configuration file is corrupted! Entries successfuly load: "), numberOfEntries)); 00127 00128 } 00129 } 00130 break; 00131 } 00132 case Event::EVT_INPUT_TRACKING: 00133 { 00134 //LOG(wxT("Tracking event...")); 00135 DeviceData * data = (DeviceData *)evt.GetClientData(); 00136 mapTable.ProcessTable((Body::BodyType)data->type, data->id, data->matrix, data->buttons, data->control1, data->control2, this); 00137 break; 00138 } 00139 } 00140 }
| bool TrackingManipulator::loadTableFromConfigFile | ( | int & | entries | ) | [protected] |
load table from configuration file
this method clear table and loads from configuration file return true if configuration file is readed succesfully
| entries | is return parameter. Means number of entries loaded if entries is smaller then 0 means file were not opend and no entries added but no entries deleted |
Definition at line 154 of file trackingmanipulator.cpp.
00155 { 00156 wxFileInputStream * input = new wxFileInputStream(wxT("trackingmanipulator.cfg")); 00157 if (!input->IsOk()) 00158 { 00159 LOG(wxT("not opened")); 00160 entries = -1; 00161 delete input; 00162 return false; 00163 } 00164 //std::ifstream config; 00165 //config.open("trackingmanipulator.cfg"); 00166 //if (!config.good()) 00167 //{ 00168 // config.close(); 00169 // entries = -1; 00170 // return 0; 00171 //} 00172 //else 00173 //{ 00174 mapTable.ClearTable(); 00175 entries = 0; 00176 TextParser * parser = new TextParser(input, 10000,1000); 00177 while(1) 00178 { 00179 int sc; 00180 if(!parser->ParseInt(&sc)) 00181 { 00182 delete parser; 00183 delete input; 00184 return true; 00185 } 00186 sceneID = sc; 00187 // LOG(wxString::Format(wxT("0 %i"), sc)); 00188 if(!parser->ParseInt(&sceneNodeID)) break; 00189 // LOG(wxString::Format(wxT("1 %i"), sceneNodeID)); 00190 if(!parser->ParseInt(&deviceID)) break; 00191 // LOG(wxString::Format(wxT("2 %i"), deviceID)); 00192 if(!parser->ParseInt(&deviceType)) break; 00193 // LOG(wxString::Format(wxT("3 %i"), deviceType)); 00194 if(!parser->ParseInt(&transformationMode)) break; 00195 // LOG(wxString::Format(wxT("4 %i"), transformationMode)); 00196 if(!parser->ParseInt(&pressedButtons)) break; 00197 // LOG(wxString::Format(wxT("5 %i"), pressedButtons)); 00198 if(!parser->ParseInt(&releasedButtons)) break; 00199 // LOG(wxString::Format(wxT("6 %i"), releasedButtons)); 00200 if(!parser->ParseFloat(&control1)) break; 00201 // LOG(wxT("7")); 00202 if(!parser->ParseFloat(&control2)) break; 00203 // LOG(wxT("8")); 00204 if(!parser->ParseFloat(&scale)) break; 00205 // LOG(wxT("9")); 00206 if (mapTable.InsertLine(deviceID, (Body::BodyType)deviceType, sceneID, sceneNodeID, pressedButtons, releasedButtons, control1, control2, (TTableEntry::TransformMode)transformationMode, scale)) 00207 { 00208 entries++; 00209 } 00210 } 00211 delete parser; 00212 delete input; 00213 return false; 00214 /* while (config >> sceneID) 00215 { 00216 if ( (config >> sceneNodeID) && 00217 (config >> deviceID) && 00218 (config >> deviceType) && 00219 (config >> transformationMode) && 00220 (config >> pressedButtons) && 00221 (config >> releasedButtons) && 00222 (config >> control1) && 00223 (config >> control2) && 00224 (config >> scale)) 00225 { 00226 if (mapTable.InsertLine(deviceID, (Body::BodyType)deviceType, sceneID, sceneNodeID, pressedButtons, releasedButtons, control1, control2, (TTableEntry::TransformMode)transformationMode, scale)) 00227 entries++; 00228 } 00229 else 00230 { 00231 return false; 00232 } 00233 } 00234 return true; 00235 }*/ 00236 }
| bool TrackingManipulator::saveTableToConfigFile | ( | ) | [protected] |
rewrite the config file with new table values
Definition at line 237 of file trackingmanipulator.cpp.
00238 { 00239 wxFileOutputStream * output = new wxFileOutputStream(wxT("trackingmanipulator.cfg")); 00240 wxString dump = mapTable.GetAsString(); 00241 if(!output->IsOk()) return false; 00242 size_t length = strlen(dump.mb_str(wxConvISO8859_1)); 00243 char * string = new char[length + 1]; 00244 strcpy(string, dump.mb_str(wxConvISO8859_1)); 00245 for (char * index = string ; index < (string + length); index++) 00246 { 00247 if (',' == *index) *index = '.'; 00248 } 00249 output->Write(string,length); 00250 bool all = (output->LastWrite() == length); 00251 output->Close(); 00252 delete string; 00253 delete output; 00254 /* 00255 std::ofstream config; 00256 config.open("trackingmanipulator.cfg"); 00257 if (!config.good()) 00258 { 00259 config.close(); 00260 return false; 00261 } 00262 else 00263 { 00264 config << mapTable.GetAsString("\n","\t").ToAscii(); 00265 config.close(); 00266 return true; 00267 }*/ 00268 return all; 00269 }
| wxString TrackingManipulator::GetDesc | ( | ) | const [virtual] |
returns short description of the module
Implements VRUT::Module.
Definition at line 6 of file trackingmanipulator.cpp.
| bool TrackingManipulator::checkScene | ( | ) |
Definition at line 148 of file trackingmanipulator.cpp.
00149 { 00150 Scene * scen = GetSceneMgr()->GetScene(sceneID); 00151 if (scen == NULL) return false; 00152 else return true; 00153 }
| bool TrackingManipulator::checkNodeInScene | ( | int | idScene | ) |
Definition at line 141 of file trackingmanipulator.cpp.
00142 { 00143 Scene * scen = GetSceneMgr()->GetScene(idScene); 00144 if (scen == NULL) return false; 00145 const SceneNode * nod = scen->GetNode(sceneNodeID); 00146 return (!(nod == NULL)); 00147 }
int VRUT::TrackingManipulator::sceneNodeID [protected] |
Definition at line 22 of file trackingmanipulator.h.
int VRUT::TrackingManipulator::deviceID [protected] |
Definition at line 25 of file trackingmanipulator.h.
int VRUT::TrackingManipulator::deviceType [protected] |
Definition at line 28 of file trackingmanipulator.h.
int VRUT::TrackingManipulator::transformationMode [protected] |
Definition at line 29 of file trackingmanipulator.h.
Definition at line 30 of file trackingmanipulator.h.
int VRUT::TrackingManipulator::pressedButtons [protected] |
Definition at line 33 of file trackingmanipulator.h.
int VRUT::TrackingManipulator::releasedButtons [protected] |
Definition at line 36 of file trackingmanipulator.h.
float VRUT::TrackingManipulator::control1 [protected] |
Definition at line 39 of file trackingmanipulator.h.
float VRUT::TrackingManipulator::control2 [protected] |
Definition at line 42 of file trackingmanipulator.h.
float VRUT::TrackingManipulator::scale [protected] |
Definition at line 45 of file trackingmanipulator.h.
short VRUT::TrackingManipulator::insert [protected] |
Definition at line 48 of file trackingmanipulator.h.
short VRUT::TrackingManipulator::remove [protected] |
Definition at line 51 of file trackingmanipulator.h.
short VRUT::TrackingManipulator::dump [protected] |
Definition at line 55 of file trackingmanipulator.h.
short VRUT::TrackingManipulator::clear [protected] |
Definition at line 56 of file trackingmanipulator.h.
Definition at line 57 of file trackingmanipulator.h.
short VRUT::TrackingManipulator::load [protected] |
Definition at line 60 of file trackingmanipulator.h.
short VRUT::TrackingManipulator::save [protected] |
Definition at line 63 of file trackingmanipulator.h.
TrackingTable VRUT::TrackingManipulator::mapTable [protected] |
1.5.5