]> Creatis software - creaMaracasVisu.git/blob - lib/maracasVisuLib/src/interface/wxWindows/widgets/wxMaracasIRMView.cxx
4242c4f20a8da4e61a0ba503d38b3e445239ae3c
[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 14:48:07 $
7   Version:   $Revision: 1.4 $
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
218         Connect(checkbox->GetId(), wxEVT_COMMAND_CHECKBOX_CLICKED, (wxObjectEventFunction)&wxMaracasIRMViewProp3D::onCheckBoxChange);   
219         checkbox->SetValue(true);       
220         
221         std::string iconfile = wxMaracasIRMView::getInstance()->getPath();
222         iconfile+= "/Data/Icons/Color.png";
223         wxBitmap* bitmap = new wxBitmap(wxString(iconfile.c_str(),wxConvUTF8), wxBITMAP_TYPE_PNG);      
224         _colorchoose = new wxBitmapButton(this, -1, *bitmap,wxDefaultPosition,wxSize(30,30));   
225         Connect(_colorchoose->GetId(), wxEVT_COMMAND_BUTTON_CLICKED, (wxObjectEventFunction)&wxMaracasIRMViewProp3D::onColorChange);            
226
227         wxBoxSizer* sizercolor = new wxBoxSizer(wxVERTICAL);
228         sizercolor->Add(checkbox,wxFIXED_MINSIZE);
229         sizercolor->Add(_colorchoose,wxFIXED_MINSIZE);
230         this->addControl(sizercolor);
231
232         
233         wxStaticText* label = new wxStaticText(this, -1, wxString(_T("Opacity")));              
234         opacity = new wxSlider(this, -1,100,0,100,wxDefaultPosition,wxDefaultSize,wxSL_HORIZONTAL|wxSL_LABELS); 
235         Connect(opacity->GetId(), wxEVT_SCROLL_CHANGED, (wxObjectEventFunction)&wxMaracasIRMViewProp3D::onOpacityRelease);      
236         wxBoxSizer* sizeropacity = new wxBoxSizer(wxVERTICAL);  
237         sizeropacity->Add(label,wxFIXED_MINSIZE);
238         sizeropacity->Add(opacity,wxFIXED_MINSIZE);
239         this->addControl(sizeropacity);
240         
241 }
242 void wxMaracasIRMViewProp3D::onCheckBoxChange(wxCommandEvent& event){   
243         wxMaracasIRMView::getInstance()->addRemoveActor(this->getPropId(), checkbox->GetValue());
244 }
245 void wxMaracasIRMViewProp3D::onColorChange(wxCommandEvent& event){
246         wxColourDialog* colourdiag = new wxColourDialog(this);
247         if(colourdiag->ShowModal()==wxID_OK){
248                 wxColour colour = colourdiag->GetColourData().GetColour();
249                 _colorchoose->SetBackgroundColour(colour);
250
251                 float r = colour.Red()/255;
252                 float g = colour.Green()/255;
253                 float b = colour.Blue()/255;
254                 
255                 wxMaracasIRMView::getInstance()->changeColor(this->getPropId(),r,g,b);
256         }
257         delete colourdiag;
258 }
259 /*void wxMaracasIRMViewProp3D::onActionButtonPressedEliminate( wxCommandEvent& event ){ 
260
261 }*/
262
263 void wxMaracasIRMViewProp3D::onOpacityRelease(wxScrollEvent& event ){
264
265         wxMaracasIRMView::getInstance()->changeOpacity(this->getPropId(),opacity->GetValue());
266
267 }
268
269
270 /**
271 **      IRM viewProp3DMHD implementation
272 **/
273 wxMaracasIRMViewProp3DMHD::wxMaracasIRMViewProp3DMHD(wxWindow* parent, int propid)
274 : wxMaracasIRMViewProp3D(parent, propid)
275 {
276         
277 }
278 wxMaracasIRMViewProp3DMHD::~wxMaracasIRMViewProp3DMHD(){
279
280 }
281 void wxMaracasIRMViewProp3DMHD::createControls(int maxisovalue){
282
283         wxBoxSizer* sizer = new wxBoxSizer(wxVERTICAL);
284
285         wxStaticText* label = new wxStaticText(this, -1, wxString(_T("IsoValue")));
286         sizer->Add(label, wxGROW);
287         //this->addControl(label);
288         isovalue = new wxSlider(this, -1,maxisovalue,0,maxisovalue,wxDefaultPosition,wxDefaultSize,wxSL_HORIZONTAL|wxSL_LABELS);
289         sizer->Add(isovalue, wxGROW);
290         //this->addControl(isovalue);
291
292         this->addControl(sizer);        
293         Connect(isovalue->GetId(), wxEVT_SCROLL_CHANGED, (wxObjectEventFunction)&wxMaracasIRMViewProp3DMHD::onIsoValueRelease); 
294 }
295
296 void wxMaracasIRMViewProp3DMHD::onIsoValueRelease(wxScrollEvent& event ){
297
298         wxMaracasIRMView::getInstance()->changeIsoValue(this->getPropId(), isovalue->GetValue());
299         
300 }
301 /**
302 **
303 **/
304
305 ToolBar::ToolBar(wxWindow * parent,std::string iconsdir)
306 : wxToolBar(parent, -1, wxDefaultPosition, wxDefaultSize)
307 {    
308
309
310         std::string iconfil = iconsdir;
311
312         iconfil+= "/OpenImage.png";
313         wxBitmap* bitmap0 = new wxBitmap(wxString(iconfil.c_str(),wxConvUTF8), wxBITMAP_TYPE_PNG);
314         this->AddTool(0, wxString(_T("test")),*bitmap0);
315
316         /*iconfil+= "/Open.png";
317         wxBitmap* bitmap2 = new wxBitmap(wxString(iconfil.c_str(),wxConvUTF8), wxBITMAP_TYPE_PNG);
318         this->AddTool(2, wxString(_T("test")),*bitmap2);        */      
319
320         /*iconfil = iconsdir;
321         iconfil+= "/Open.png";
322         wxBitmap* bitmap30 = new wxBitmap(wxString(iconfil.c_str(),wxConvUTF8), wxBITMAP_TYPE_PNG);
323         this->AddTool(30, wxString(_T("test")),*bitmap30);*/
324         
325         this->Realize();
326         
327         
328 }
329
330 ToolBar::~ToolBar(void){
331 }
332 void ToolBar::onLoadImageFile(wxCommandEvent& event){
333         wxMaracasIRMView::getInstance()->onLoadImageFile();
334 }
335
336
337
338 BEGIN_EVENT_TABLE(ToolBar, wxToolBar)   
339         EVT_MENU(0, ToolBar::onLoadImageFile)    
340            
341 END_EVENT_TABLE()