]> Creatis software - creaMaracasVisu.git/blob - lib/maracasVisuLib/src/interface/wxWindows/widgets/wxMaracasIRMView.cxx
No newline at eof
[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/05/29 13:39:56 $
7   Version:   $Revision: 1.9 $
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 //#include "wxMaracasIRMViewPanel.h"
24 #include "wxMaracasIRMViewProp3DMHD.h"
25 #include "wxMaracasIRMViewProp3D.h"
26
27 #include <wx/colordlg.h>
28 #include <wx/bmpbuttn.h>
29
30 #include <OpenImage.xpm>
31 #include <Color.xpm>
32
33 wxMaracasIRMView* wxMaracasIRMView::instance=NULL;
34
35 wxMaracasIRMView::wxMaracasIRMView( wxWindow* parent,std::string path) 
36 : wxPanel(parent, -1, wxDefaultPosition, wxDefaultSize){        
37         
38         irmmanager = new wxMaracasIRMViewManager();             
39
40         wxauimanager = new wxAuiManager(this);          
41
42         _path = path;
43
44         std::string iconsdir = path;
45         iconsdir+="/data/Icons";
46         wxToolBar* toolbar = new ToolBar(this,iconsdir);
47         wxAuiPaneInfo paneinfo; 
48         wxauimanager->AddPane(toolbar,paneinfo.ToolbarPane().Top());                    
49
50         wxauimanager->Update();
51         createFileChooser();
52
53
54 }
55 wxMaracasIRMView::~wxMaracasIRMView( ){
56
57
58 }
59
60 std::string wxMaracasIRMView::getPath(){
61         return _path;
62 }
63
64
65
66 void wxMaracasIRMView::createFileChooser(){
67     
68 }
69
70 wxMaracasIRMView* wxMaracasIRMView::getInstance(wxWindow* parent,std::string path){
71         if(instance==NULL){
72                 instance = new wxMaracasIRMView(parent,path);
73         }
74         return instance;
75 }
76
77 wxMaracasIRMView* wxMaracasIRMView::getInstance(){
78         return instance;
79 }
80
81 void wxMaracasIRMView::setRenderer(vtkRenderer*  renderer){
82         irmmanager->setRenderer(renderer);
83 }
84
85 void wxMaracasIRMView::addRemoveActor(int propid, bool addremove){
86         irmmanager->addRemoveActor(propid, addremove);
87 }
88
89 void wxMaracasIRMView::changeOpacity(int _propid, int value){
90         irmmanager->changeOpacity(_propid,value);
91 }
92
93 void wxMaracasIRMView::changeIsoValue(int propid, double value){        
94         irmmanager->changeIsoValue(propid, value);
95 }
96
97 void wxMaracasIRMView::changeColor(int propid, double red, double green, double blue){
98         try{
99                 irmmanager->changeColor(propid, red, green, blue);
100
101         }catch(char* str){
102
103                 wxString s( str,wxConvUTF8 );
104                 wxMessageDialog* diag = new wxMessageDialog(this, s, s, wxICON_ERROR);
105                 diag->ShowModal();
106                 delete diag;
107
108         }
109 }
110
111 void wxMaracasIRMView::onLoadImageFile(){
112
113         wxString mhd(_T("mhd"));
114         wxString stl(_T("stl"));
115
116         wxFileDialog* fildial = new wxFileDialog(this, wxString(_T("Select a STL file")),wxString(_T("")),
117                 wxString(_T("")),wxString(_T("STL files (*.stl)|*.stl|MHD files (*.mhd)|*.mhd")) );
118
119         if(fildial->ShowModal()==wxID_OK){
120         wxString filename = fildial->GetFilename();
121                 wxString pathfile(fildial->GetDirectory() + _T("/") + filename);        
122                 
123
124                 if(filename.EndsWith(mhd)){                     
125                         loadPropMHD(pathfile,filename);
126                 }else if(filename.EndsWith(stl)){
127             loadProp3D(pathfile,filename);
128                 }
129         }
130         delete fildial;
131
132 }
133 void wxMaracasIRMView::loadPropMHD(wxString filename, wxString dataname){               
134                 
135         std::string s = std::string(filename.mb_str());
136         vtkImageData* img = irmmanager->getImageData(s);
137         if(img!=NULL){
138                 s = std::string(dataname.mb_str());
139                 addPropMHD(img, s);
140         }
141         
142         
143
144 }
145
146 void wxMaracasIRMView::addPropMHD(vtkImageData* imgdata, std::string dataname){
147         try{
148                 int id = irmmanager->addPropMHD(imgdata,dataname);              
149                 if(id!=-1){
150                         
151                         wxMaracasIRMViewPanel* controlpan = new wxMaracasIRMViewProp3DMHD(this, id);
152                         int maxiso = irmmanager->getMaxIsoValue(id);
153                         ((wxMaracasIRMViewProp3DMHD*)controlpan)->createControls(maxiso);
154                         addIRMViewPanel(controlpan, dataname);
155                 }
156
157         }catch(char* str){
158
159                 std::cout << "Exception : " << str << '\n';
160                 wxMessageDialog* diag = new wxMessageDialog(this, wxString( str,wxConvUTF8 ), wxString( str,wxConvUTF8 ), wxICON_ERROR);
161                 diag->ShowModal();
162
163         }
164 }
165
166 void wxMaracasIRMView::loadProp3D(wxString filename, wxString dataname){                        
167         std::string s = std::string(filename.mb_str());
168         vtkProp3D* prop3D = irmmanager->getProp3D(s);
169         if(prop3D != NULL){
170                 s = std::string(dataname.mb_str() );
171                 this->addProp3D(prop3D,s);
172         }else{
173                 //TODO msj to the user indicating error in file
174         }
175                 
176         
177         
178 }
179
180 void wxMaracasIRMView::addProp3D(vtkProp3D* prop3D, std::string dataname){
181         try{
182                 int id = irmmanager->addProp3D(prop3D,dataname);
183                 if(id!=-1){
184                         wxMaracasIRMViewPanel* controlpan = new wxMaracasIRMViewProp3D(this, id);
185                         addIRMViewPanel(controlpan, dataname);
186                 }
187         }catch(char* str){
188                 std::cout << "Exception : " << str << '\n';
189                 wxMessageDialog* diag = new wxMessageDialog(this, wxString(str,wxConvUTF8 ), wxString(str,wxConvUTF8 ), wxICON_ERROR);
190                 diag->ShowModal();              
191         }
192         
193 }
194 void wxMaracasIRMView::addIRMViewPanel(wxMaracasIRMViewPanel* irmview, std::string dataname){
195
196         wxString s(dataname.c_str(),wxConvUTF8 );
197         wxAuiPaneInfo paneinfo; 
198         wxauimanager->AddPane(irmview, paneinfo.DefaultPane().Centre().DestroyOnClose().Caption(s));
199         wxauimanager->Update();
200         
201         
202 }
203
204 void wxMaracasIRMView::deleteActor(int propid){
205         try{
206                 irmmanager->deleteActor(propid);
207         }catch(char* e){
208                 
209         }
210 }
211
212
213
214
215
216 /**
217 **
218 **/
219
220 ToolBar::ToolBar(wxWindow * parent,std::string iconsdir)
221 : wxToolBar(parent, -1, wxDefaultPosition, wxDefaultSize)
222 {    
223
224
225         std::string iconfil = iconsdir;
226
227         //iconfil+= "/OpenImage.png";
228         //wxBitmap* bitmap0 = new wxBitmap(wxString(iconfil.c_str(),wxConvUTF8), wxBITMAP_TYPE_PNG);
229         wxBitmap bitmap0(OpenImage_xpm);
230         this->AddTool(0, wxString(_T("test")),bitmap0);
231
232         /*iconfil+= "/Open.png";
233         wxBitmap* bitmap2 = new wxBitmap(wxString(iconfil.c_str(),wxConvUTF8), wxBITMAP_TYPE_PNG);
234         this->AddTool(2, wxString(_T("test")),*bitmap2);        */      
235
236         /*iconfil = iconsdir;
237         iconfil+= "/Open.png";
238         wxBitmap* bitmap30 = new wxBitmap(wxString(iconfil.c_str(),wxConvUTF8), wxBITMAP_TYPE_PNG);
239         this->AddTool(30, wxString(_T("test")),*bitmap30);*/
240         
241         this->Realize();
242         
243         
244 }
245
246 ToolBar::~ToolBar(void){
247 }
248 void ToolBar::onLoadImageFile(wxCommandEvent& event){
249         wxMaracasIRMView::getInstance()->onLoadImageFile();
250 }
251
252
253
254 BEGIN_EVENT_TABLE(ToolBar, wxToolBar)   
255         EVT_MENU(0, ToolBar::onLoadImageFile)    
256            
257 END_EVENT_TABLE()
258
259