]> 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/09 13:58:38 $
7   Version:   $Revision: 1.2 $
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                 std::cout << "Exception : " << str << '\n';
98                 wxMessageDialog* diag = new wxMessageDialog(this, wxString(str), wxString(str), wxICON_ERROR);
99                 diag->ShowModal();
100
101         }
102 }
103
104 void wxMaracasIRMView::onLoadImageFile(){
105
106         wxString mhd(_T("mhd"));
107         wxString stl(_T("stl"));
108
109         wxFileDialog* fildial = new wxFileDialog(this, wxString(_T("Select a STL file")),wxString(_T("")),
110                 wxString(_T("")),"STL files (*.stl)|*.stl|MHD files (*.mhd)|*.mhd" );
111
112         if(fildial->ShowModal()==wxID_OK){
113         wxString filename = fildial->GetFilename();
114                 wxString pathfile(fildial->GetDirectory() + _T("/") + filename);        
115                 
116
117                 if(filename.EndsWith(mhd)){                     
118                         loadPropMHD(pathfile,filename);
119                 }else if(filename.EndsWith(stl)){
120             loadProp3D(pathfile,filename);
121                 }
122         }
123         delete fildial;
124
125 }
126 void wxMaracasIRMView::loadPropMHD(wxString filename, wxString dataname){               
127                 
128                 
129         vtkImageData* img = irmmanager->getImageData(filename.c_str());
130         if(img!=NULL){
131                 addPropMHD(img, dataname.c_str());
132         }
133         
134         
135
136 }
137
138 void wxMaracasIRMView::addPropMHD(vtkImageData* imgdata, std::string dataname){
139         try{
140                 int id = irmmanager->addPropMHD(imgdata,dataname);              
141                 if(id!=-1){
142                         
143                         wxMaracasIRMViewPanel* controlpan = new wxMaracasIRMViewProp3DMHD(this, id);
144                         int maxiso = irmmanager->getMaxIsoValue(id);
145                         ((wxMaracasIRMViewProp3DMHD*)controlpan)->createControls(maxiso);
146                         addIRMViewPanel(controlpan, dataname);
147                 }
148
149         }catch(char* str){
150
151                 std::cout << "Exception : " << str << '\n';
152                 wxMessageDialog* diag = new wxMessageDialog(this, wxString(str), wxString(str), wxICON_ERROR);
153                 diag->ShowModal();
154
155         }
156 }
157
158 void wxMaracasIRMView::loadProp3D(wxString filename, wxString dataname){                        
159         
160         vtkProp3D* prop3D = irmmanager->getProp3D(filename.c_str());
161         if(prop3D != NULL){
162                 this->addProp3D(prop3D,dataname.c_str());
163         }else{
164                 //TODO msj to the user indicating error in file
165         }
166                 
167         
168         
169 }
170
171 void wxMaracasIRMView::addProp3D(vtkProp3D* prop3D, std::string dataname){
172         try{
173                 int id = irmmanager->addProp3D(prop3D,dataname);
174                 if(id!=-1){
175                         wxMaracasIRMViewPanel* controlpan = new wxMaracasIRMViewProp3D(this, id);
176                         addIRMViewPanel(controlpan, dataname);
177                 }
178         }catch(char* str){
179                 std::cout << "Exception : " << str << '\n';
180                 wxMessageDialog* diag = new wxMessageDialog(this, wxString(str), wxString(str), wxICON_ERROR);
181                 diag->ShowModal();              
182         }
183         
184 }
185 void wxMaracasIRMView::addIRMViewPanel(wxMaracasIRMViewPanel* irmview, std::string dataname){
186
187         wxString s(dataname.c_str());
188         wxAuiPaneInfo paneinfo; 
189         wxauimanager->AddPane(irmview, paneinfo.DefaultPane().Centre().DestroyOnClose().Caption(s));
190         wxauimanager->Update();
191
192 }
193
194 /**
195 **      Implementation of viewProp3D
196 **/
197
198 wxMaracasIRMViewProp3D::wxMaracasIRMViewProp3D(wxWindow* parent,int propid)
199 :wxMaracasIRMViewPanel(parent, propid){
200         createControls();       
201 }
202
203 wxMaracasIRMViewProp3D::~wxMaracasIRMViewProp3D(){
204         wxMaracasIRMView::getInstance()->addRemoveActor(_propid, false);
205 }
206
207 void wxMaracasIRMViewProp3D::createControls(){
208
209         wxString choices[2];
210         choices[0] = "On";
211         choices[1] = "Off";
212         checkbox = new  wxCheckBox(this,-1,wxString(_T("Show Actor")));
213         this->addControl(checkbox);
214         Connect(checkbox->GetId(), wxEVT_COMMAND_CHECKBOX_CLICKED, (wxObjectEventFunction)&wxMaracasIRMViewProp3D::onCheckBoxChange);   
215         checkbox->SetValue(true);
216
217         
218         wxBoxSizer* sizercolor = new wxBoxSizer(wxVERTICAL);
219         std::string iconfile = wxMaracasIRMView::getInstance()->getPath();
220         iconfile+= "/Data/Icons/Color.png";
221         wxBitmap* bitmap = new wxBitmap(wxString(iconfile.c_str(),wxConvUTF8), wxBITMAP_TYPE_PNG);      
222         _colorchoose = new wxBitmapButton(this, -1, *bitmap);   
223         sizercolor->Add(_colorchoose,wxFIXED_MINSIZE);
224         Connect(_colorchoose->GetId(), wxEVT_COMMAND_BUTTON_CLICKED, (wxObjectEventFunction)&wxMaracasIRMViewProp3D::onColorChange);            
225
226         this->addControl(sizercolor);
227         
228
229         wxBoxSizer* sizeropacity = new wxBoxSizer(wxVERTICAL);  
230         wxStaticText* label = new wxStaticText(this, -1, wxString(_T("Opacity")));      
231         sizeropacity->Add(label,wxFIXED_MINSIZE);
232         opacity = new wxSlider(this, -1,100,0,100,wxDefaultPosition,wxDefaultSize,wxSL_HORIZONTAL|wxSL_LABELS);
233         sizeropacity->Add(opacity,wxFIXED_MINSIZE);
234         Connect(opacity->GetId(), wxEVT_SCROLL_CHANGED, (wxObjectEventFunction)&wxMaracasIRMViewProp3D::onOpacityRelease);      
235
236         this->addControl(sizeropacity);
237         
238
239         /*isovalue = new wxSlider(this, -1,0,0,100);
240         this->addControl(isovalue);
241         Connect(isovalue->GetId(), wxEVT_SCROLL_CHANGED, (wxObjectEventFunction)&wxMaracasIRMViewProp3D::onIsoValueRelease);    */
242 }
243 void wxMaracasIRMViewProp3D::onCheckBoxChange(wxCommandEvent& event){   
244         wxMaracasIRMView::getInstance()->addRemoveActor(this->getPropId(), checkbox->GetValue());
245 }
246 void wxMaracasIRMViewProp3D::onColorChange(wxCommandEvent& event){
247         wxColourDialog* colourdiag = new wxColourDialog(this);
248         if(colourdiag->ShowModal()==wxID_OK){
249                 wxColour colour = colourdiag->GetColourData().GetColour();
250                 _colorchoose->SetBackgroundColour(colour);
251
252                 float r = colour.Red()/255;
253                 float g = colour.Green()/255;
254                 float b = colour.Blue()/255;
255                 
256                 wxMaracasIRMView::getInstance()->changeColor(this->getPropId(),r,g,b);
257         }
258         delete colourdiag;
259 }
260 /*void wxMaracasIRMViewProp3D::onActionButtonPressedEliminate( wxCommandEvent& event ){ 
261
262 }*/
263
264 void wxMaracasIRMViewProp3D::onOpacityRelease(wxScrollEvent& event ){
265
266         wxMaracasIRMView::getInstance()->changeOpacity(this->getPropId(),opacity->GetValue());
267
268 }
269
270
271 /**
272 **      IRM viewProp3DMHD implementation
273 **/
274 wxMaracasIRMViewProp3DMHD::wxMaracasIRMViewProp3DMHD(wxWindow* parent, int propid)
275 : wxMaracasIRMViewProp3D(parent, propid)
276 {
277         
278 }
279 wxMaracasIRMViewProp3DMHD::~wxMaracasIRMViewProp3DMHD(){
280
281 }
282 void wxMaracasIRMViewProp3DMHD::createControls(int maxisovalue){
283
284         wxBoxSizer* sizer = new wxBoxSizer(wxVERTICAL);
285
286         wxStaticText* label = new wxStaticText(this, -1, wxString(_T("IsoValue")));
287         sizer->Add(label, wxGROW);
288         //this->addControl(label);
289         isovalue = new wxSlider(this, -1,maxisovalue,0,maxisovalue,wxDefaultPosition,wxDefaultSize,wxSL_HORIZONTAL|wxSL_LABELS);
290         sizer->Add(isovalue, wxGROW);
291         //this->addControl(isovalue);
292
293         this->addControl(sizer);        
294         Connect(isovalue->GetId(), wxEVT_SCROLL_CHANGED, (wxObjectEventFunction)&wxMaracasIRMViewProp3DMHD::onIsoValueRelease); 
295 }
296
297 void wxMaracasIRMViewProp3DMHD::onIsoValueRelease(wxScrollEvent& event ){
298
299         wxMaracasIRMView::getInstance()->changeIsoValue(this->getPropId(), isovalue->GetValue());
300         
301 }
302 /**
303 **
304 **/
305
306 ToolBar::ToolBar(wxWindow * parent,std::string iconsdir)
307 : wxToolBar(parent, -1, wxDefaultPosition, wxDefaultSize)
308 {    
309
310
311         std::string iconfil = iconsdir;
312
313         iconfil+= "/OpenImage.png";
314         wxBitmap* bitmap0 = new wxBitmap(wxString(iconfil.c_str(),wxConvUTF8), wxBITMAP_TYPE_PNG);
315         this->AddTool(0, wxString(_T("test")),*bitmap0);
316
317         /*iconfil+= "/Open.png";
318         wxBitmap* bitmap2 = new wxBitmap(wxString(iconfil.c_str(),wxConvUTF8), wxBITMAP_TYPE_PNG);
319         this->AddTool(2, wxString(_T("test")),*bitmap2);        */      
320
321         /*iconfil = iconsdir;
322         iconfil+= "/Open.png";
323         wxBitmap* bitmap30 = new wxBitmap(wxString(iconfil.c_str(),wxConvUTF8), wxBITMAP_TYPE_PNG);
324         this->AddTool(30, wxString(_T("test")),*bitmap30);*/
325         
326         this->Realize();
327         
328         
329 }
330
331 ToolBar::~ToolBar(void){
332 }
333 void ToolBar::onLoadImageFile(wxCommandEvent& event){
334         wxMaracasIRMView::getInstance()->onLoadImageFile();
335 }
336
337
338
339 BEGIN_EVENT_TABLE(ToolBar, wxToolBar)   
340         EVT_MENU(0, ToolBar::onLoadImageFile)    
341            
342 END_EVENT_TABLE()