]> Creatis software - creaMaracasVisu.git/blob - lib/maracasVisuLib/src/interface/wxWindows/widgets/wxMaracas_N_ViewersWidget.cxx
*** empty log message ***
[creaMaracasVisu.git] / lib / maracasVisuLib / src / interface / wxWindows / widgets / wxMaracas_N_ViewersWidget.cxx
1 /*=========================================================================
2
3   Program:   wxMaracas
4   Module:    $RCSfile: wxMaracas_N_ViewersWidget.cxx,v $
5   Language:  C++
6   Date:      $Date: 2009/03/24 10:49:21 $
7   Version:   $Revision: 1.3 $
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 // Definition includes
20 //------------------------------------------------------------------------------------------------------------
21 #include "wxMaracas_N_ViewersWidget.h"
22
23 //------------------------------------------------------------------------------------------------------------
24 // Other includes
25 //------------------------------------------------------------------------------------------------------------
26
27
28         //------------------------------------------------------------------------------------------------------------
29         // Constructors & Destructors
30         //------------------------------------------------------------------------------------------------------------
31
32
33         BEGIN_EVENT_TABLE( wxMaracas_N_ViewersWidget, wxPanel )
34                 EVT_MENU( 12121, wxMaracas_N_ViewersWidget::OnRefreshView )
35                 EVT_MENU( 12122, wxMaracas_N_ViewersWidget::OnDClickLeft  )
36         END_EVENT_TABLE( );
37
38         
39         //------------------------------------------------------------------------------------------------------------
40         // Constructors & Destructors
41         //------------------------------------------------------------------------------------------------------------
42
43
44
45         wxMaracas_N_ViewersWidget::wxMaracas_N_ViewersWidget(wxWindow *parent, vtkImageData* imagedata, std::vector<int> *nTypeView)
46                 : wxPanel( parent, -1, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL)
47         {
48                 wxwindow1       = NULL;
49                 wxwindow2       = NULL;
50                 wxwindow3       = NULL;
51                 wxwindow4       = NULL;
52                 currentwxwindow = NULL;
53
54                 wxSizer *sizer  = new wxBoxSizer(wxVERTICAL);
55                 this->SetSizer(sizer);
56                 this->SetAutoLayout(true);
57                 
58                 
59                 if(imagedata!=NULL && nTypeView!=NULL ){
60                         this->SetType(nTypeView);
61                         this->UpdateLayout(imagedata);
62                 }
63
64                 
65         }
66         //-------------------------------------------------------------------------
67           
68         wxMaracas_N_ViewersWidget::~wxMaracas_N_ViewersWidget()
69         {
70         }
71         //------------------------------------------------------------------------------------------------------------
72         // Methods
73         //------------------------------------------------------------------------------------------------------------
74
75
76         //-------------------------------------------------------------------------
77
78         void wxMaracas_N_ViewersWidget::Update()
79         {
80                 //wxvtkrenderwindowinteractor->Render();
81         //    wxvtkrenderwindowinteractor->Refresh();
82         //    Refresh();
83         }
84
85         //-------------------------------------------------------------------------
86
87         void wxMaracas_N_ViewersWidget::OnRefreshView(wxCommandEvent & event) 
88         {
89                 RefreshView();
90         }
91         //----------------------------------------------------------------------------
92         void wxMaracas_N_ViewersWidget::OnDClickLeft(wxCommandEvent & event) 
93         {
94                 RefreshView();
95         }
96
97                 //-------------------------------------------------------------------------
98
99         vtkRenderer *wxMaracas_N_ViewersWidget::GetRenderer()
100         {
101                 return NULL; //renderer;
102         }
103
104         void wxMaracas_N_ViewersWidget::RefreshView()
105         {
106                 if (wxwindow1!=NULL) {wxwindow1->RefreshView(); }
107                 if (wxwindow2!=NULL) {wxwindow2->RefreshView(); }
108                 if (wxwindow3!=NULL) {wxwindow3->RefreshView(); }
109                 if (wxwindow4!=NULL) {wxwindow4->RefreshView(); }
110         }
111
112         //-------------------------------------------------------------------------
113         wxMaracas_ViewerWidget *wxMaracas_N_ViewersWidget::GetWindow(int iWin)  
114         {
115                 wxMaracas_ViewerWidget *tmpWin=NULL;
116                 if  (iWin==1)
117                 {
118                         tmpWin=wxwindow1;
119                 }
120                 if  (iWin==2)
121                 {
122                         tmpWin=wxwindow2;
123                 }
124                 if  (iWin==3)
125                 {
126                         tmpWin=wxwindow3;
127                 }
128                 if  (iWin==4)
129                 {
130                         tmpWin=wxwindow4;
131                 }
132                 return tmpWin;
133         }
134
135         //-------------------------------------------------------------------------
136         wxVtkBaseView *wxMaracas_N_ViewersWidget::GetwxVtkBaseView(int iWin)
137         { 
138                 wxVtkBaseView *wxvtkbaseview=NULL;
139                 wxMaracas_ViewerWidget *tmpWin=GetWindow(iWin);
140                 if (tmpWin!=NULL){  wxvtkbaseview = tmpWin->GetwxVtkBaseView();  }
141                 return wxvtkbaseview;
142         }
143    
144         //-------------------------------------------------------------------------
145  void wxMaracas_N_ViewersWidget::Refresh(bool eraseBackground, const wxRect* rect )
146  {
147          wxPanel::Refresh(false);
148  }
149
150  void wxMaracas_N_ViewersWidget::UpdateLayout(vtkImageData* imagedata){
151
152                 wxPanel                         *panel          = this;
153                 wxWindow                                *wxwindow       = NULL;
154                 wxSizer *sizer  = panel->GetSizer();
155         
156                 if(currentwxwindow!=NULL){
157                         sizer->Remove(currentwxwindow);                 
158                         delete currentwxwindow;
159                 }
160
161                 //std::cout<<"size "<<nTypeView->size()<<std::endl;
162                 if (nTypeView->size()==1)
163                 {
164
165                         std::cout<<"type "<<(*nTypeView)[0]<<std::endl;
166                         wxwindow1 = new wxMaracas_ViewerWidget(panel, imagedata, (*nTypeView)[0]);
167                         wxwindow1->ConfigureVTK();
168                         wxwindow = wxwindow1;
169                 }else   if (nTypeView->size()==2)       {
170
171                         
172                         wxSplitterWindow        *spliter        = new wxSplitterWindow( panel , -1);
173                         wxwindow1 = new wxMaracas_ViewerWidget(spliter, imagedata, (*nTypeView)[0]);
174                         wxwindow2 = new wxMaracas_ViewerWidget(spliter, imagedata, (*nTypeView)[1]);
175                         wxwindow1->ConfigureVTK();
176                         wxwindow2->ConfigureVTK();
177                         spliter -> SplitVertically( wxwindow1 , wxwindow2  );
178                         wxwindow = spliter;
179                 }else if (nTypeView->size()==3)
180                 {
181                         wxSplitterWindow        *spliter        = new wxSplitterWindow( panel , -1);
182                         wxSplitterWindow        *spliterA       = new wxSplitterWindow( spliter , -1);
183                         wxwindow1 = new wxMaracas_ViewerWidget(spliter , imagedata, (*nTypeView)[0]);
184                         wxwindow2 = new wxMaracas_ViewerWidget(spliterA, imagedata, (*nTypeView)[1]);
185                         wxwindow3 = new wxMaracas_ViewerWidget(spliterA, imagedata, (*nTypeView)[2]);
186                         wxwindow1->ConfigureVTK();
187                         wxwindow2->ConfigureVTK();
188                         wxwindow3->ConfigureVTK();
189                         spliter -> SplitVertically( wxwindow1 , spliterA   );
190                         spliterA-> SplitHorizontally( wxwindow2 , wxwindow3  );
191                         wxwindow = spliter;
192                 }else if (nTypeView->size()>=4){
193                         wxSplitterWindow        *spliter        = new wxSplitterWindow( panel , -1);
194                         wxSplitterWindow        *spliterA       = new wxSplitterWindow( spliter , -1);
195                         wxSplitterWindow        *spliterB       = new wxSplitterWindow( spliter , -1);
196                         wxwindow1 = new wxMaracas_ViewerWidget(spliterA, imagedata, (*nTypeView)[0]);
197                         wxwindow2 = new wxMaracas_ViewerWidget(spliterA, imagedata, (*nTypeView)[1]);
198                         wxwindow3 = new wxMaracas_ViewerWidget(spliterB, imagedata, (*nTypeView)[2]);
199                         wxwindow4 = new wxMaracas_ViewerWidget(spliterB, imagedata, (*nTypeView)[3]);
200                         wxwindow1->ConfigureVTK();
201                         wxwindow2->ConfigureVTK();
202                         wxwindow3->ConfigureVTK();
203                         wxwindow4->ConfigureVTK();
204                         spliter -> SplitVertically( spliterA , spliterB   );
205                         spliterA-> SplitHorizontally( wxwindow1 , wxwindow2  );
206                         spliterB-> SplitHorizontally( wxwindow3 , wxwindow4  );
207                         wxwindow = spliter;
208                 }
209                 
210                 //panel->SetDimension()
211                 sizer->Add( wxwindow , 1, wxGROW);
212                 sizer->Layout();
213                 currentwxwindow = wxwindow;             
214                 currentwxwindow->Show(true);
215                 
216                 this->Layout();
217                 this->Refresh();
218
219  }
220
221  void wxMaracas_N_ViewersWidget::SetType(std::vector<int>* type){
222          nTypeView = type;
223  }
224  void wxMaracas_N_ViewersWidget::SetImage( vtkImageData *image  )
225  {
226          if (wxwindow1!=NULL) { 
227                  
228                 wxwindow1->SetImage(image); 
229         }
230          if (wxwindow2!=NULL) { wxwindow2->SetImage(image); } 
231          if (wxwindow3!=NULL) { wxwindow3->SetImage(image); }
232          if (wxwindow4!=NULL) { wxwindow4->SetImage(image); }
233
234
235  }
236
237
238 double wxMaracas_N_ViewersWidget :: GetX()
239 {
240         return wxwindow1->GetX();
241 }
242
243 double wxMaracas_N_ViewersWidget :: GetY()
244 {
245         return wxwindow1->GetY();
246 }
247
248
249 double wxMaracas_N_ViewersWidget :: GetZ()
250 {
251         return wxwindow1->GetZ();
252 }
253
254
255 /*
256 double wxMaracas_N_ViewersWidget :: GetZ(int iWin)
257         {
258                 double answerVal = 0.0;
259                 if  (iWin==1)
260                 {
261                         answerVal = wxwindow1->GetZ();
262                 }
263                 if  (iWin==2)
264                 {
265                         answerVal = wxwindow2->GetZ();
266                 }
267                 if  (iWin==3)
268                 {
269                         answerVal = wxwindow3->GetZ();
270                 }
271                 if  (iWin==4)
272                 {
273                         answerVal = wxwindow4->GetZ();
274                 }
275                 return answerVal;
276         }
277 */