00001 00002 // Name: wxGuiTest/VtkWxGuiTesting/VtkWxGuiTestHelper.cpp 00003 // Author: Reinhold Fuereder 00004 // Created: 2004 00005 // Copyright: (c) 2005 Reinhold Fuereder 00006 // Licence: wxWindows licence 00007 // 00008 // $Id$ 00010 00011 #ifdef __GNUG__ 00012 #pragma implementation "VtkWxGuiTestHelper.h" 00013 #endif 00014 00015 #include <wxGuiTest/VtkGuiTesting/VtkWxGuiTestHelper.h> 00016 00017 #include <wxGuiTest/VtkGuiTesting/VtkInteractorEventRecorder.h> 00018 00019 namespace wxTst { 00020 00021 00022 // Init single instance: 00023 VtkWxGuiTestHelper *VtkWxGuiTestHelper::ms_instance = NULL; 00024 00025 // Set default settings for normal application logic: 00026 bool VtkWxGuiTestHelper::ms_useWxVtkInteractionRecording = false; 00027 00028 00029 VtkWxGuiTestHelper::VtkWxGuiTestHelper () 00030 { 00031 // Nothing to do 00032 } 00033 00034 00035 VtkWxGuiTestHelper::~VtkWxGuiTestHelper () 00036 { 00037 RecorderMap::iterator it; 00038 for (it = m_recorderMap.begin (); it != m_recorderMap.end (); it++) { 00039 00040 (*it).second->Off (); 00041 (*it).second->Delete (); 00042 } 00043 m_recorderMap.clear (); 00044 } 00045 00046 00047 VtkWxGuiTestHelper * VtkWxGuiTestHelper::GetInstance () 00048 { 00049 if (ms_instance == NULL) { 00050 00051 ms_instance = new VtkWxGuiTestHelper (); 00052 } 00053 return ms_instance; 00054 } 00055 00056 00057 void VtkWxGuiTestHelper::Destroy () 00058 { 00059 if (ms_instance != NULL) { 00060 00061 delete ms_instance; 00062 ms_instance = NULL; 00063 } 00064 } 00065 00066 00067 void VtkWxGuiTestHelper::SetUseWxVtkInteractionRecording (bool use) 00068 { 00069 ms_useWxVtkInteractionRecording = use; 00070 } 00071 00072 00073 bool VtkWxGuiTestHelper::GetUseWxVtkInteractionRecording () 00074 { 00075 return ms_useWxVtkInteractionRecording; 00076 } 00077 00078 00079 void VtkWxGuiTestHelper::RegisterForRecording ( 00080 wxVTKRenderWindowInteractor *wxVtkRwi, const wxString &recorderId, 00081 const wxString &wxVtkId) 00082 { 00083 if (!ms_useWxVtkInteractionRecording) { 00084 00085 return; 00086 } 00087 00088 WxVtkInteractorEventRecorder *recorder = NULL; 00089 recorder = this->GetWxVtkRecorder (recorderId); 00090 if (recorder == NULL) { 00091 00092 recorder = WxVtkInteractorEventRecorder::New (); 00093 m_recorderMap[recorderId] = recorder; 00094 recorder->SetFileName (wxConvCurrent->cWX2MB (wxString::Format ( 00095 _T("%s_wxVtk.rec"), recorderId.c_str ()))); 00096 } 00097 wxASSERT (recorder != NULL); 00098 recorder->AddInteractor (wxVtkId, wxVtkRwi); 00099 } 00100 00101 00102 WxVtkInteractorEventRecorder * VtkWxGuiTestHelper::GetWxVtkRecorder ( 00103 const wxString &recorderId) const 00104 { 00105 RecorderMap::const_iterator it; 00106 00107 it = m_recorderMap.find (recorderId); 00108 return (it == m_recorderMap.end () ? NULL : (*it).second); 00109 } 00110 00111 00112 VtkWxGuiTestHelper::RecorderMap & VtkWxGuiTestHelper::GetWxVtkRecorders () 00113 { 00114 return m_recorderMap; 00115 } 00116 00117 } // End namespace wxTst