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