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