]> Creatis software - creaMaracasVisu.git/blob - lib/maracasVisuLib/src/interface/wxWindows/widgets/wxMaracasIRMView.cxx
c13e1571fa78b0a206e73f89f061d945217603a2
[creaMaracasVisu.git] / lib / maracasVisuLib / src / interface / wxWindows / widgets / wxMaracasIRMView.cxx
1 /*=========================================================================
2
3   Program:   wxMaracas
4   Module:    $RCSfile: wxMaracasIRMView.cxx,v $
5   Language:  C++
6   Date:      $Date: 2009/04/14 12:47:30 $
7   Version:   $Revision: 1.3 $
8
9   Copyright: (c) 2002, 2003
10   License:
11
12      This software is distributed WITHOUT ANY WARRANTY; without even
13      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14      PURPOSE.  See the above copyright notice for more information.
15
16 =========================================================================*/
17
18
19
20 // EOF - wxMaracasMPR.cxx
21
22 #include "wxMaracasIRMView.h"
23
24 #include <wx/colordlg.h>
25 #include <wx/bmpbuttn.h>
26
27 wxMaracasIRMView* wxMaracasIRMView::instance=NULL;
28
29 wxMaracasIRMView::wxMaracasIRMView( wxWindow* parent,std::string path) 
30 : wxPanel(parent, -1, wxDefaultPosition, wxDefaultSize){        
31         
32         irmmanager = new wxMaracasIRMViewManager();             
33
34         wxauimanager = new wxAuiManager(this);          
35
36         _path = path;
37
38         std::string iconsdir = path;
39         iconsdir+="/Data/Icons";
40         wxToolBar* toolbar = new ToolBar(this,iconsdir);
41         wxAuiPaneInfo paneinfo; 
42         wxauimanager->AddPane(toolbar,paneinfo.ToolbarPane().Top());                    
43
44         wxauimanager->Update();
45         createFileChooser();
46
47
48 }
49 wxMaracasIRMView::~wxMaracasIRMView( ){
50
51
52 }
53
54 std::string wxMaracasIRMView::getPath(){
55         return _path;
56 }
57
58
59
60 void wxMaracasIRMView::createFileChooser(){
61     
62 }
63
64 wxMaracasIRMView* wxMaracasIRMView::getInstance(wxWindow* parent,std::string path){
65         if(instance==NULL){
66                 instance = new wxMaracasIRMView(parent,path);
67         }
68         return instance;
69 }
70
71 wxMaracasIRMView* wxMaracasIRMView::getInstance(){
72         return instance;
73 }
74
75 void wxMaracasIRMView::setRenderer(vtkRenderer*  renderer){
76         irmmanager->setRenderer(renderer);
77 }
78
79 void wxMaracasIRMView::addRemoveActor(int propid, bool addremove){
80         irmmanager->addRemoveActor(propid, addremove);
81 }
82
83 void wxMaracasIRMView::changeOpacity(int _propid, int value){
84         irmmanager->changeOpacity(_propid,value);
85 }
86
87 void wxMaracasIRMView::changeIsoValue(int propid, int value){   
88         irmmanager->changeIsoValue(propid, value);
89 }
90
91 void wxMaracasIRMView::changeColor(int propid, double red, double green, double blue){
92         try{
93                 irmmanager->changeColor(propid, red, green, blue);
94
95         }catch(char* str){
96
97                 wxString s( str,wxConvUTF8 );
98                 wxMessageDialog* diag = new wxMessageDialog(this, s, s, wxICON_ERROR);
99                 diag->ShowModal();
100                 delete diag;
101
102         }
103 }
104
105 void wxMaracasIRMView::onLoadImageFile(){
106
107         wxString mhd(_T("mhd"));
108         wxString stl(_T("stl"));
109
110         wxFileDialog* fildial = new wxFileDialog(this, wxString(_T("Select a STL file")),wxString(_T("")),
111                 wxString(_T("")),wxString(_T("STL files (*.stl)|*.stl|MHD files (*.mhd)|*.mhd")) );
112
113         if(fildial->ShowModal()==wxID_OK){
114         wxString filename = fildial->GetFilename();
115                 wxString pathfile(fildial->GetDirectory() + _T("/") + filename);        
116                 
117
118                 if(filename.EndsWith(mhd)){                     
119                         loadPropMHD(pathfile,filename);
120                 }else if(filename.EndsWith(stl)){
121             loadProp3D(pathfile,filename);
122                 }
123         }
124         delete fildial;
125
126 }
127 void wxMaracasIRMView::loadPropMHD(wxString filename, wxString dataname){               
128                 
129         std::string s = std::string(filename.mb_str());
130         vtkImageData* img = irmmanager->getImageData(s);
131         if(img!=NULL){
132                 s = std::string(dataname.mb_str());
133                 addPropMHD(img, s);
134         }
135         
136         
137
138 }
139
140 void wxMaracasIRMView::addPropMHD(vtkImageData* imgdata, std::string dataname){
141         try{
142                 int id = irmmanager->addPropMHD(imgdata,dataname);              
143                 if(id!=-1){
144                         
145                         wxMaracasIRMViewPanel* controlpan = new wxMaracasIRMViewProp3DMHD(this, id);
146                         int maxiso = irmmanager->getMaxIsoValue(id);
147                         ((wxMaracasIRMViewProp3DMHD*)controlpan)->createControls(maxiso);
148                         addIRMViewPanel(controlpan, dataname);
149                 }
150
151         }catch(char* str){
152
153                 std::cout << "Exception : " << str << '\n';
154                 wxMessageDialog* diag = new wxMessageDialog(this, wxString( str,wxConvUTF8 ), wxString( str,wxConvUTF8 ), wxICON_ERROR);
155                 diag->ShowModal();
156
157         }
158 }
159
160 void wxMaracasIRMView::loadProp3D(wxString filename, wxString dataname){                        
161         std::string s = std::string(filename.mb_str());
162         vtkProp3D* prop3D = irmmanager->getProp3D(s);
163         if(prop3D != NULL){
164                 s = std::string(dataname.mb_str() );
165                 this->addProp3D(prop3D,s);
166         }else{
167                 //TODO msj to the user indicating error in file
168         }
169                 
170         
171         
172 }
173
174 void wxMaracasIRMView::addProp3D(vtkProp3D* prop3D, std::string dataname){
175         try{
176                 int id = irmmanager->addProp3D(prop3D,dataname);
177                 if(id!=-1){
178                         wxMaracasIRMViewPanel* controlpan = new wxMaracasIRMViewProp3D(this, id);
179                         addIRMViewPanel(controlpan, dataname);
180                 }
181         }catch(char* str){
182                 std::cout << "Exception : " << str << '\n';
183                 wxMessageDialog* diag = new wxMessageDialog(this, wxString(str,wxConvUTF8 ), wxString(str,wxConvUTF8 ), wxICON_ERROR);
184                 diag->ShowModal();              
185         }
186         
187 }
188 void wxMaracasIRMView::addIRMViewPanel(wxMaracasIRMViewPanel* irmview, std::string dataname){
189
190         wxString s(dataname.c_str(),wxConvUTF8 );
191         wxAuiPaneInfo paneinfo; 
192         wxauimanager->AddPane(irmview, paneinfo.DefaultPane().Centre().DestroyOnClose().Caption(s));
193         wxauimanager->Update();
194
195 }
196
197 /**
198 **      Implementation of viewProp3D
199 **/
200
201 wxMaracasIRMViewProp3D::wxMaracasIRMViewProp3D(wxWindow* parent,int propid)
202 :wxMaracasIRMViewPanel(parent, propid){
203         createControls();       
204 }
205
206 wxMaracasIRMViewProp3D::~wxMaracasIRMViewProp3D(){
207         wxMaracasIRMView::getInstance()->addRemoveActor(_propid, false);
208 }
209
210 void wxMaracasIRMViewProp3D::createControls(){
211
212         wxString choices[2];
213         choices[0] = wxString(_T("On"));
214         choices[1] = wxString(_T("Off"));
215         checkbox = new  wxCheckBox(this,-1,wxString(_T("Show Actor")));
216         this->addControl(checkbox);
217         Connect(checkbox->GetId(), wxEVT_COMMAND_CHECKBOX_CLICKED, (wxObjectEventFunction)&wxMaracasIRMViewProp3D::onCheckBoxChange);   
218         checkbox->SetValue(true);
219
220         
221         wxBoxSizer* sizercolor = new wxBoxSizer(wxVERTICAL);
222         std::string iconfile = wxMaracasIRMView::getInstance()->getPath();
223         iconfile+= "/Data/Icons/Color.png";
224         wxBitmap* bitmap = new wxBitmap(wxString(iconfile.c_str(),wxConvUTF8), wxBITMAP_TYPE_PNG);      
225         _colorchoose = new wxBitmapButton(this, -1, *bitmap);   
226         sizercolor->Add(_colorchoose,wxFIXED_MINSIZE);
227         Connect(_colorchoose->GetId(), wxEVT_COMMAND_BUTTON_CLICKED, (wxObjectEventFunction)&wxMaracasIRMViewProp3D::onColorChange);            
228
229         this->addControl(sizercolor);
230         
231
232         wxBoxSizer* sizeropacity = new wxBoxSizer(wxVERTICAL);  
233         wxStaticText* label = new wxStaticText(this, -1, wxString(_T("Opacity")));      
234         sizeropacity->Add(label,wxFIXED_MINSIZE);
235         opacity = new wxSlider(this, -1,100,0,100,wxDefaultPosition,wxDefaultSize,wxSL_HORIZONTAL|wxSL_LABELS);
236         sizeropacity->Add(opacity,wxFIXED_MINSIZE);
237         Connect(opacity->GetId(), wxEVT_SCROLL_CHANGED, (wxObjectEventFunction)&wxMaracasIRMViewProp3D::onOpacityRelease);      
238
239         this->addControl(sizeropacity);
240         
241
242         /*isovalue = new wxSlider(this, -1,0,0,100);
243         this->addControl(isovalue);
244         Connect(isovalue->GetId(), wxEVT_SCROLL_CHANGED, (wxObjectEventFunction)&wxMaracasIRMViewProp3D::onIsoValueRelease);    */
245 }
246 void wxMaracasIRMViewProp3D::onCheckBoxChange(wxCommandEvent& event){   
247         wxMaracasIRMView::getInstance()->addRemoveActor(this->getPropId(), checkbox->GetValue());
248 }
249 void wxMaracasIRMViewProp3D::onColorChange(wxCommandEvent& event){
250         wxColourDialog* colourdiag = new wxColourDialog(this);
251         if(colourdiag->ShowModal()==wxID_OK){
252                 wxColour colour = colourdiag->GetColourData().GetColour();
253                 _colorchoose->SetBackgroundColour(colour);
254
255                 float r = colour.Red()/255;
256                 float g = colour.Green()/255;
257                 float b = colour.Blue()/255;
258                 
259                 wxMaracasIRMView::getInstance()->changeColor(this->getPropId(),r,g,b);
260         }
261         delete colourdiag;
262 }
263 /*void wxMaracasIRMViewProp3D::onActionButtonPressedEliminate( wxCommandEvent& event ){ 
264
265 }*/
266
267 void wxMaracasIRMViewProp3D::onOpacityRelease(wxScrollEvent& event ){
268
269         wxMaracasIRMView::getInstance()->changeOpacity(this->getPropId(),opacity->GetValue());
270
271 }
272
273
274 /**
275 **      IRM viewProp3DMHD implementation
276 **/
277 wxMaracasIRMViewProp3DMHD::wxMaracasIRMViewProp3DMHD(wxWindow* parent, int propid)
278 : wxMaracasIRMViewProp3D(parent, propid)
279 {
280         
281 }
282 wxMaracasIRMViewProp3DMHD::~wxMaracasIRMViewProp3DMHD(){
283
284 }
285 void wxMaracasIRMViewProp3DMHD::createControls(int maxisovalue){
286
287         wxBoxSizer* sizer = new wxBoxSizer(wxVERTICAL);
288
289         wxStaticText* label = new wxStaticText(this, -1, wxString(_T("IsoValue")));
290         sizer->Add(label, wxGROW);
291         //this->addControl(label);
292         isovalue = new wxSlider(this, -1,maxisovalue,0,maxisovalue,wxDefaultPosition,wxDefaultSize,wxSL_HORIZONTAL|wxSL_LABELS);
293         sizer->Add(isovalue, wxGROW);
294         //this->addControl(isovalue);
295
296         this->addControl(sizer);        
297         Connect(isovalue->GetId(), wxEVT_SCROLL_CHANGED, (wxObjectEventFunction)&wxMaracasIRMViewProp3DMHD::onIsoValueRelease); 
298 }
299
300 void wxMaracasIRMViewProp3DMHD::onIsoValueRelease(wxScrollEvent& event ){
301
302         wxMaracasIRMView::getInstance()->changeIsoValue(this->getPropId(), isovalue->GetValue());
303         
304 }
305 /**
306 **
307 **/
308
309 ToolBar::ToolBar(wxWindow * parent,std::string iconsdir)
310 : wxToolBar(parent, -1, wxDefaultPosition, wxDefaultSize)
311 {    
312
313
314         std::string iconfil = iconsdir;
315
316         iconfil+= "/OpenImage.png";
317         wxBitmap* bitmap0 = new wxBitmap(wxString(iconfil.c_str(),wxConvUTF8), wxBITMAP_TYPE_PNG);
318         this->AddTool(0, wxString(_T("test")),*bitmap0);
319
320         /*iconfil+= "/Open.png";
321         wxBitmap* bitmap2 = new wxBitmap(wxString(iconfil.c_str(),wxConvUTF8), wxBITMAP_TYPE_PNG);
322         this->AddTool(2, wxString(_T("test")),*bitmap2);        */      
323
324         /*iconfil = iconsdir;
325         iconfil+= "/Open.png";
326         wxBitmap* bitmap30 = new wxBitmap(wxString(iconfil.c_str(),wxConvUTF8), wxBITMAP_TYPE_PNG);
327         this->AddTool(30, wxString(_T("test")),*bitmap30);*/
328         
329         this->Realize();
330         
331         
332 }
333
334 ToolBar::~ToolBar(void){
335 }
336 void ToolBar::onLoadImageFile(wxCommandEvent& event){
337         wxMaracasIRMView::getInstance()->onLoadImageFile();
338 }
339
340
341
342 BEGIN_EVENT_TABLE(ToolBar, wxToolBar)   
343         EVT_MENU(0, ToolBar::onLoadImageFile)    
344            
345 END_EVENT_TABLE()