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