]> Creatis software - creaMaracasVisu.git/blob - lib/maracasVisuLib/src/CutModule/interface/CutModelView.cxx
b95a815a835d42ac0b41e937c5801eccf33aaead
[creaMaracasVisu.git] / lib / maracasVisuLib / src / CutModule / interface / CutModelView.cxx
1 /*=========================================================================
2
3   Program:   wxMaracas
4   Module:    $RCSfile: CutModelView.cxx,v $
5   Language:  C++
6   Date:      $Date: 2009/09/01 14:01:35 $
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 "CutModelView.h"
23
24
25 #include <wx/colordlg.h>
26 #include <wx/bmpbuttn.h>
27
28 #include <OpenImage.xpm>
29 #include <Color.xpm>
30 #include <Ok1.xpm>
31 #include <Statistics.xpm>
32
33 #include "vtkBoxWidget.h"
34
35 #include "CutModelMainPanel.h"
36
37 CutModelView::CutModelView( wxWindow* parent, double* range)
38 : wxPanel(parent, -1, wxDefaultPosition, wxDefaultSize){
39
40         wxBoxSizer* sizer = new wxBoxSizer(wxVERTICAL);
41
42         this->SetSizer(sizer);  
43         
44         sizer->Add(getBoxControls(this, range),wxSizerFlags().FixedMinSize());  
45
46         sizer->AddSpacer(5);
47
48         sizer->Add(getActorProperties(this),wxSizerFlags().FixedMinSize());     
49
50
51         wxBitmap bitmapok(Ok1_xpm);
52         wxBitmapButton* okbutton = new wxBitmapButton(this, -1, bitmapok,wxDefaultPosition,wxSize(30,30));                      
53         Connect(okbutton->GetId(), wxEVT_COMMAND_BUTTON_CLICKED, (wxObjectEventFunction)(&CutModelViewEventHandler::onExecute));        
54         
55         sizer->AddSpacer(5);
56         sizer->Add(okbutton,wxSizerFlags().FixedMinSize());
57
58
59         
60
61
62 }
63 CutModelView::~CutModelView( ){
64         CutModelMainPanel::getInstance()->RemoveActor(this->getId());
65 }
66
67 wxSizer* CutModelView::getBoxControls(wxWindow* parent,double* range){
68
69         wxBoxSizer* sizer = new wxBoxSizer(wxVERTICAL);
70         wxCheckBox* checkbox = new wxCheckBox(parent,-1,_T("View Box"));
71         sizer->Add(checkbox,wxSizerFlags().FixedMinSize());
72         checkbox->SetValue(true);
73         Connect(checkbox->GetId(), wxEVT_COMMAND_CHECKBOX_CLICKED,(wxObjectEventFunction)(&CutModelViewEventHandler::onViewBoxChecked));
74
75         wxString choices1[3];
76         //choices1[0] = _T("Select a shape...");
77         choices1[0] = _T("Sphere");
78         choices1[1] = _T("Cylinder");
79         choices1[2] = _T("Cube");
80         wxComboBox* combo = new wxComboBox(parent, -1,_T(""),wxDefaultPosition,wxDefaultSize,3,choices1);
81         combo->SetValue(_T("Sphere"));
82         sizer->Add(combo,wxSizerFlags().FixedMinSize());
83         Connect(combo->GetId(), wxEVT_COMMAND_COMBOBOX_SELECTED,(wxObjectEventFunction)(&CutModelViewEventHandler::onShapeChange));
84
85         wxStaticText* labelgreyv = new wxStaticText(parent, -1, wxString(_T("Grey value range")));      
86         _sliderrange = new wxSlider(parent, -1, range[0],range[0],range[1],wxDefaultPosition,wxDefaultSize,wxSL_LABELS|wxSL_SELRANGE);
87         wxBoxSizer* sizergreyv = new wxBoxSizer(wxVERTICAL);
88         sizergreyv->Add(labelgreyv,wxSizerFlags().FixedMinSize());
89         sizergreyv->Add(_sliderrange,wxSizerFlags().FixedMinSize());
90         sizer->Add(sizergreyv,wxSizerFlags().FixedMinSize().Border());
91         
92         wxString choices0[2];
93         choices0[0] = _T("inside");
94         choices0[1] = _T("outside");
95         _radioinsideout = new  wxRadioBox(parent,-1,_T(""), wxDefaultPosition, wxDefaultSize,2,choices0);
96         sizer->Add(_radioinsideout,wxSizerFlags().FixedMinSize());
97
98         /*wxString choices[2];
99         choices[0] = _T("Cut");
100         choices[1] = _T("Statistics");
101         _radiocutstat = new  wxRadioBox(parent,-1,_T(""), wxDefaultPosition, wxDefaultSize,2,choices);
102         sizer->Add(_radiocutstat,wxSizerFlags().FixedMinSize());*/
103
104         wxBitmap bitmap(Statistics_xpm);
105         wxBitmapButton* statbut = new wxBitmapButton(parent, -1, bitmap,wxDefaultPosition,wxSize(30,30));                       
106         Connect(statbut->GetId(), wxEVT_COMMAND_BUTTON_CLICKED, (wxObjectEventFunction)(&CutModelViewEventHandler::onStatistics));      
107     sizer->Add(statbut,wxSizerFlags().FixedMinSize());
108
109         
110
111         return sizer;
112 }
113 wxSizer* CutModelView::getActorProperties(wxWindow* parent){
114
115         wxBoxSizer* sizeractorproperties = new wxBoxSizer(wxVERTICAL);  
116
117         wxStaticText* labelshapeactor = new wxStaticText(parent, -1, wxString(_T("Actor's properties")));
118
119         sizeractorproperties->Add(labelshapeactor,wxSizerFlags().FixedMinSize());
120
121         sizeractorproperties->Add(getColorChooseActor(parent),wxSizerFlags().FixedMinSize());
122
123         sizeractorproperties->Add(getOpacityActor(parent),wxSizerFlags().FixedMinSize());
124
125         return sizeractorproperties;
126         
127 }
128
129 wxSizer* CutModelView::getOpacityActor(wxWindow* parent){
130         wxBoxSizer* sizeropacity = new wxBoxSizer(wxVERTICAL);  
131
132         wxStaticText* labelopacity = new wxStaticText(parent, -1, wxString(_T("Opacity")));
133         wxSlider* slider0 = new wxSlider(parent, -1, 60,0,100,wxDefaultPosition,wxDefaultSize,wxSL_LABELS);
134         Connect(slider0->GetId(), wxEVT_SCROLL_THUMBRELEASE,(wxObjectEventFunction)(&CutModelViewEventHandler::onOpacityChange));       
135         
136         sizeropacity->Add(labelopacity,wxSizerFlags().FixedMinSize());
137         sizeropacity->Add(slider0,wxSizerFlags().FixedMinSize());
138
139         return sizeropacity;
140 }
141
142 wxSizer* CutModelView::getColorChooseActor(wxWindow* parent){
143     wxBoxSizer* sizercolor = new wxBoxSizer(wxHORIZONTAL);
144         wxBitmap bitmap(Color_xpm);
145         wxBitmapButton* colorchoose = new wxBitmapButton(parent, -1, bitmap,wxDefaultPosition,wxSize(30,30));            
146         wxObjectEventFunction f = (wxObjectEventFunction)(&CutModelViewEventHandler::onColorChange);    
147         Connect(colorchoose->GetId(), wxEVT_COMMAND_BUTTON_CLICKED, f); 
148
149         _currentcolor = new wxStaticText(parent,-1,_T(""),wxDefaultPosition,wxSize(20,20));
150         this->SetCurrentColor(wxColour(255.0,0.0,0.0));
151
152         sizercolor->Add(colorchoose,wxSizerFlags().FixedMinSize());
153         sizercolor->AddSpacer(5);
154         sizercolor->Add(_currentcolor,wxSizerFlags().FixedMinSize().Centre());
155         return sizercolor;
156 }
157
158 void CutModelView::checkInvariant()throw (CutModelException){
159         
160 }
161
162 void CutModelView::Execute(vtkObject *wdg, unsigned long eventId, void* calldata) {  // virtual
163         //vtkBoxWidget *boxwidget = reinterpret_cast<vtkBoxWidget*>(wdg);
164
165         if(eventId==vtkCommand::StartInteractionEvent){
166         CutModelMainPanel::getInstance()->ShowCurrentPanel(this->getId());
167         }else if(eventId==vtkCommand::InteractionEvent){
168                 CutModelMainPanel::getInstance()->updateActorDirection(this->getId());
169         }else if(eventId==vtkCommand::RightButtonReleaseEvent){
170                 //  =(
171         CutModelMainPanel::getInstance()->ShowPopUpMenu(this->getId());
172         }
173 }
174
175 void CutModelView::ExecuteCut(){        
176         if(this->isCut()){
177                 CutModelMainPanel::getInstance()->ExecuteCut(this->getId(),this->getRange(),this->isInside());
178         }else{
179         }
180         
181 }
182
183 double* CutModelView::getRange(){
184         double* x = new double[3];
185         x[0] = 0;
186         x[1] = _sliderrange->GetValue();
187         x[2] = 100000;
188
189         return x;
190 }
191 bool CutModelView::isCut(){
192         return true;
193         //return _radiocutstat->GetSelection()==0;
194 }
195 bool CutModelView::isInside(){
196         return _radioinsideout->GetSelection()==0;
197 }
198 void CutModelView::SetCurrentColor(wxColour colour){
199         _currentcolor->SetBackgroundColour(colour);
200
201         this->Refresh();
202         this->Layout();
203 }
204
205 void CutModelViewEventHandler::onColorChange(wxCommandEvent& event){
206         CutModelView* parent = (CutModelView*)((wxWindow*)event.GetEventObject())->GetParent();
207         wxColourDialog* colourdiag = new wxColourDialog(parent);
208         if(colourdiag->ShowModal()==wxID_OK){
209                 wxColour colour = colourdiag->GetColourData().GetColour();
210                 
211                 parent->SetCurrentColor(colour);
212
213                 double r = (double)(colour.Red())/255.0;
214                 double g = (double)(colour.Green())/255.0;
215                 double b = (double)(colour.Blue())/255.0;               
216                 CutModelMainPanel::getInstance()->changeColor(parent->getId(),r,g,b);
217
218
219         }
220         delete colourdiag;
221 }
222
223 void CutModelViewEventHandler::onOpacityChange(wxScrollEvent& event){
224         CutModelView* parent = (CutModelView*)((wxWindow*)event.GetEventObject())->GetParent();
225
226         CutModelMainPanel::getInstance()->changeOpacity(parent->getId(),event.GetInt());
227 }
228 void CutModelViewEventHandler::onViewBoxChecked(wxCommandEvent& event){
229     CutModelView* parent = (CutModelView*)((wxWindow*)event.GetEventObject())->GetParent();
230
231         CutModelMainPanel::getInstance()->ShowViewBox(parent->getId(),event.IsChecked());
232 }
233 void CutModelViewEventHandler::onShapeChange(wxCommandEvent& event){
234         CutModelView* parent = (CutModelView*)((wxWindow*)event.GetEventObject())->GetParent();
235
236         //if(event.GetSelection()>0){
237                 //std::cout<<"id in CutModelViewEventHandler:: "<<parent->getId()<<std::endl;
238         CutModelMainPanel::getInstance()->ChangeShape(parent->getId(),event.GetSelection());
239         //}
240 }
241 void CutModelViewEventHandler::onStatistics(wxCommandEvent& event){
242         CutModelView* parent = (CutModelView*)((wxWindow*)event.GetEventObject())->GetParent();
243         CutModelMainPanel::getInstance()->ShowStatistics(parent->getId());
244 }
245 void CutModelViewEventHandler::onExecute(wxCommandEvent& event){
246      CutModelView* parent = (CutModelView*)((wxWindow*)event.GetEventObject())->GetParent();
247
248          parent->ExecuteCut();
249          
250 }