]> Creatis software - creaMaracasVisu.git/blob - lib/maracasVisuLib/src/CutModule/interface/CutModel2View.cxx
*** empty log message ***
[creaMaracasVisu.git] / lib / maracasVisuLib / src / CutModule / interface / CutModel2View.cxx
1 /*=========================================================================
2
3   Program:   wxMaracas
4   Module:    $RCSfile: CutModel2View.cxx,v $
5   Language:  C++
6   Date:      $Date: 2009/11/19 15:00:32 $
7   Version:   $Revision: 1.1 $
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 "CutModel2View.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 "CutModel2MainPanel.h"
36
37 CutModel2View::CutModel2View( 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)(&CutModel2ViewEventHandler::onExecute));       
54         
55         sizer->AddSpacer(5);
56         sizer->Add(okbutton,wxSizerFlags().FixedMinSize());
57
58
59         
60
61
62 }
63 CutModel2View::~CutModel2View( ){
64         CutModel2MainPanel::getInstance()->RemoveActor(this->getId());
65 }
66
67 wxSizer* CutModel2View::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)(&CutModel2ViewEventHandler::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)(&CutModel2ViewEventHandler::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)(&CutModel2ViewEventHandler::onStatistics));     
107     sizer->Add(statbut,wxSizerFlags().FixedMinSize());
108
109         
110
111         return sizer;
112 }
113 wxSizer* CutModel2View::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* CutModel2View::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)(&CutModel2ViewEventHandler::onOpacityChange));      
135         
136         sizeropacity->Add(labelopacity,wxSizerFlags().FixedMinSize());
137         sizeropacity->Add(slider0,wxSizerFlags().FixedMinSize());
138
139         return sizeropacity;
140 }
141
142 wxSizer* CutModel2View::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)(&CutModel2ViewEventHandler::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 CutModel2View::checkInvariant()throw (CutModel2Exception){
159         
160 }
161
162 void CutModel2View::Execute(vtkObject *wdg, unsigned long eventId, void* calldata) {  // virtual
163         //vtkBoxWidget *boxwidget = reinterpret_cast<vtkBoxWidget*>(wdg);
164
165         if(eventId==vtkCommand::StartInteractionEvent){
166         CutModel2MainPanel::getInstance()->ShowCurrentPanel(this->getId());
167         }else if(eventId==vtkCommand::InteractionEvent){
168                 CutModel2MainPanel::getInstance()->updateActorDirection(this->getId());
169         }else if(eventId==vtkCommand::RightButtonReleaseEvent){
170                 //  =(
171         CutModel2MainPanel::getInstance()->ShowPopUpMenu(this->getId());
172         }
173 }
174
175 void CutModel2View::ExecuteCut(){       
176         if(this->isCut()){
177                 CutModel2MainPanel::getInstance()->ExecuteCut(this->getId(),this->getRange(),this->isInside());
178         }else{
179         }
180         
181 }
182
183 double* CutModel2View::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 CutModel2View::isCut(){
192         return true;
193         //return _radiocutstat->GetSelection()==0;
194 }
195 bool CutModel2View::isInside(){
196         return _radioinsideout->GetSelection()==0;
197 }
198 void CutModel2View::SetCurrentColor(wxColour colour){
199         _currentcolor->SetBackgroundColour(colour);
200
201         this->Refresh();
202         this->Layout();
203 }
204
205 void CutModel2ViewEventHandler::onColorChange(wxCommandEvent& event){
206         CutModel2View* parent = (CutModel2View*)((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                 CutModel2MainPanel::getInstance()->changeColor(parent->getId(),r,g,b);
217
218
219         }
220         delete colourdiag;
221 }
222
223 void CutModel2ViewEventHandler::onOpacityChange(wxScrollEvent& event){
224         CutModel2View* parent = (CutModel2View*)((wxWindow*)event.GetEventObject())->GetParent();
225
226         CutModel2MainPanel::getInstance()->changeOpacity(parent->getId(),event.GetInt());
227 }
228 void CutModel2ViewEventHandler::onViewBoxChecked(wxCommandEvent& event){
229     CutModel2View* parent = (CutModel2View*)((wxWindow*)event.GetEventObject())->GetParent();
230
231         CutModel2MainPanel::getInstance()->ShowViewBox(parent->getId(),event.IsChecked());
232 }
233 void CutModel2ViewEventHandler::onShapeChange(wxCommandEvent& event){
234         CutModel2View* parent = (CutModel2View*)((wxWindow*)event.GetEventObject())->GetParent();
235
236         //if(event.GetSelection()>0){
237                 //std::cout<<"id in CutModel2ViewEventHandler:: "<<parent->getId()<<std::endl;
238         CutModel2MainPanel::getInstance()->ChangeShape(parent->getId(),event.GetSelection());
239         //}
240 }
241 void CutModel2ViewEventHandler::onStatistics(wxCommandEvent& event){
242         CutModel2View* parent = (CutModel2View*)((wxWindow*)event.GetEventObject())->GetParent();
243         CutModel2MainPanel::getInstance()->ShowStatistics(parent->getId());
244 }
245 void CutModel2ViewEventHandler::onExecute(wxCommandEvent& event){
246      CutModel2View* parent = (CutModel2View*)((wxWindow*)event.GetEventObject())->GetParent();
247
248          parent->ExecuteCut();
249          
250 }