]> Creatis software - creaMaracasVisu.git/blob - lib/maracasVisuLib/src/CutModule/interface/CutModelView.cxx
Support #1768 CREATIS Licence insertion
[creaMaracasVisu.git] / lib / maracasVisuLib / src / CutModule / interface / CutModelView.cxx
1 /*# ---------------------------------------------------------------------
2 #
3 # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
4 #                        pour la Sant�)
5 # Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton
6 # Previous Authors : Laurent Guigues, Jean-Pierre Roux
7 # CreaTools website : www.creatis.insa-lyon.fr/site/fr/creatools_accueil
8 #
9 #  This software is governed by the CeCILL-B license under French law and
10 #  abiding by the rules of distribution of free software. You can  use,
11 #  modify and/ or redistribute the software under the terms of the CeCILL-B
12 #  license as circulated by CEA, CNRS and INRIA at the following URL
13 #  http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
14 #  or in the file LICENSE.txt.
15 #
16 #  As a counterpart to the access to the source code and  rights to copy,
17 #  modify and redistribute granted by the license, users are provided only
18 #  with a limited warranty  and the software's author,  the holder of the
19 #  economic rights,  and the successive licensors  have only  limited
20 #  liability.
21 #
22 #  The fact that you are presently reading this means that you have had
23 #  knowledge of the CeCILL-B license and that you accept its terms.
24 # ------------------------------------------------------------------------ */
25
26 /*=========================================================================
27
28   Program:   wxMaracas
29   Module:    $RCSfile: CutModelView.cxx,v $
30   Language:  C++
31   Date:      $Date: 2012/11/15 14:16:20 $
32   Version:   $Revision: 1.4 $
33
34   Copyright: (c) 2002, 2003
35   License:
36
37      This software is distributed WITHOUT ANY WARRANTY; without even
38      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
39      PURPOSE.  See the above copyright notice for more information.
40
41 =========================================================================*/
42
43
44
45 // EOF - wxMaracasMPR.cxx
46
47 #include "CutModelView.h"
48
49
50 #include <wx/colordlg.h>
51 #include <wx/bmpbuttn.h>
52
53 #include <OpenImage.xpm>
54 #include <Color.xpm>
55 #include <Ok1.xpm>
56 #include <Statistics.xpm>
57
58 #include "vtkBoxWidget.h"
59
60 #include "CutModelMainPanel.h"
61
62 CutModelView::CutModelView( wxWindow* parent, double* range)
63 : wxPanel(parent, -1, wxDefaultPosition, wxDefaultSize){
64
65         wxBoxSizer* sizer = new wxBoxSizer(wxVERTICAL);
66
67         this->SetSizer(sizer);  
68         
69         sizer->Add(getBoxControls(this, range),wxSizerFlags().FixedMinSize());  
70
71         sizer->AddSpacer(5);
72
73         sizer->Add(getActorProperties(this),wxSizerFlags().FixedMinSize());     
74
75
76         wxBitmap bitmapok(Ok1_xpm);
77         wxBitmapButton* okbutton = new wxBitmapButton(this, -1, bitmapok,wxDefaultPosition,wxSize(30,30));                      
78         Connect(okbutton->GetId(), wxEVT_COMMAND_BUTTON_CLICKED, (wxObjectEventFunction)(&CutModelViewEventHandler::onExecute));        
79         
80         sizer->AddSpacer(5);
81         sizer->Add(okbutton,wxSizerFlags().FixedMinSize());
82
83
84         
85
86
87 }
88 CutModelView::~CutModelView( ){
89         CutModelMainPanel::getInstance()->RemoveActor(this->getId());
90 }
91
92 wxSizer* CutModelView::getBoxControls(wxWindow* parent,double* range){
93
94         wxBoxSizer* sizer = new wxBoxSizer(wxVERTICAL);
95         wxCheckBox* checkbox = new wxCheckBox(parent,-1,_T("View Box"));
96         sizer->Add(checkbox,wxSizerFlags().FixedMinSize());
97         checkbox->SetValue(true);
98         Connect(checkbox->GetId(), wxEVT_COMMAND_CHECKBOX_CLICKED,(wxObjectEventFunction)(&CutModelViewEventHandler::onViewBoxChecked));
99
100         wxString choices1[3];
101         //choices1[0] = _T("Select a shape...");
102         choices1[0] = _T("Sphere");
103         choices1[1] = _T("Cylinder");
104         choices1[2] = _T("Cube");
105         wxComboBox* combo = new wxComboBox(parent, -1,_T(""),wxDefaultPosition,wxDefaultSize,3,choices1);
106         combo->SetValue(_T("Sphere"));
107         sizer->Add(combo,wxSizerFlags().FixedMinSize());
108         Connect(combo->GetId(), wxEVT_COMMAND_COMBOBOX_SELECTED,(wxObjectEventFunction)(&CutModelViewEventHandler::onShapeChange));
109
110         wxStaticText* labelgreyv = new wxStaticText(parent, -1, wxString(_T("Grey value range")));      
111         _sliderrange = new wxSlider(parent, -1, range[0],range[0],range[1],wxDefaultPosition,wxDefaultSize,wxSL_LABELS|wxSL_SELRANGE);
112         wxBoxSizer* sizergreyv = new wxBoxSizer(wxVERTICAL);
113         sizergreyv->Add(labelgreyv,wxSizerFlags().FixedMinSize());
114         sizergreyv->Add(_sliderrange,1, wxGROW);
115         sizer->Add(sizergreyv, 1, wxGROW);
116         
117         wxString choices0[2];
118         choices0[0] = _T("inside");
119         choices0[1] = _T("outside");
120         _radioinsideout = new  wxRadioBox(parent,-1,_T(""), wxDefaultPosition, wxDefaultSize,2,choices0);
121         sizer->Add(_radioinsideout,wxSizerFlags().FixedMinSize());
122
123         /*wxString choices[2];
124         choices[0] = _T("Cut");
125         choices[1] = _T("Statistics");
126         _radiocutstat = new  wxRadioBox(parent,-1,_T(""), wxDefaultPosition, wxDefaultSize,2,choices);
127         sizer->Add(_radiocutstat,wxSizerFlags().FixedMinSize());*/
128
129         wxBitmap bitmap(Statistics_xpm);
130         wxBitmapButton* statbut = new wxBitmapButton(parent, -1, bitmap,wxDefaultPosition,wxSize(30,30));                       
131         Connect(statbut->GetId(), wxEVT_COMMAND_BUTTON_CLICKED, (wxObjectEventFunction)(&CutModelViewEventHandler::onStatistics));      
132     sizer->Add(statbut,wxSizerFlags().FixedMinSize());
133
134         
135
136         return sizer;
137 }
138 wxSizer* CutModelView::getActorProperties(wxWindow* parent){
139
140         wxBoxSizer* sizeractorproperties = new wxBoxSizer(wxVERTICAL);  
141
142         wxStaticText* labelshapeactor = new wxStaticText(parent, -1, wxString(_T("Actor's properties")));
143
144         sizeractorproperties->Add(labelshapeactor,wxSizerFlags().FixedMinSize());
145
146         sizeractorproperties->Add(getColorChooseActor(parent),wxSizerFlags().FixedMinSize());
147
148         sizeractorproperties->Add(getOpacityActor(parent),wxSizerFlags().FixedMinSize());
149
150         return sizeractorproperties;
151         
152 }
153
154 wxSizer* CutModelView::getOpacityActor(wxWindow* parent){
155         wxBoxSizer* sizeropacity = new wxBoxSizer(wxVERTICAL);  
156
157         wxStaticText* labelopacity = new wxStaticText(parent, -1, wxString(_T("Opacity")));
158         wxSlider* slider0 = new wxSlider(parent, -1, 60,0,100,wxDefaultPosition,wxDefaultSize,wxSL_LABELS);
159         Connect(slider0->GetId(), wxEVT_SCROLL_THUMBRELEASE,(wxObjectEventFunction)(&CutModelViewEventHandler::onOpacityChange));       
160         
161         //sizeropacity->Add(labelopacity,1, wxGROWwxSizerFlags().FixedMinSize());
162         sizeropacity->Add(labelopacity,1, wxGROW);
163         //sizeropacity->Add(slider0,wxSizerFlags().FixedMinSize());
164         sizeropacity->Add(slider0, 1, wxGROW);
165
166         return sizeropacity;
167 }
168
169 wxSizer* CutModelView::getColorChooseActor(wxWindow* parent){
170     wxBoxSizer* sizercolor = new wxBoxSizer(wxHORIZONTAL);
171         wxBitmap bitmap(Color_xpm);
172         wxBitmapButton* colorchoose = new wxBitmapButton(parent, -1, bitmap,wxDefaultPosition,wxSize(30,30));            
173         wxObjectEventFunction f = (wxObjectEventFunction)(&CutModelViewEventHandler::onColorChange);    
174         Connect(colorchoose->GetId(), wxEVT_COMMAND_BUTTON_CLICKED, f); 
175
176         _currentcolor = new wxStaticText(parent,-1,_T(""),wxDefaultPosition,wxSize(20,20));
177         this->SetCurrentColor(wxColour(255.0,0.0,0.0));
178
179         sizercolor->Add(colorchoose,wxSizerFlags().FixedMinSize());
180         sizercolor->AddSpacer(5);
181         sizercolor->Add(_currentcolor,wxSizerFlags().FixedMinSize().Centre());
182         return sizercolor;
183 }
184
185 void CutModelView::checkInvariant()throw (CutModelException){
186         
187 }
188
189 void CutModelView::Execute(vtkObject *wdg, unsigned long eventId, void* calldata) {  // virtual
190         //vtkBoxWidget *boxwidget = reinterpret_cast<vtkBoxWidget*>(wdg);
191
192         if(eventId==vtkCommand::StartInteractionEvent){
193         CutModelMainPanel::getInstance()->ShowCurrentPanel(this->getId());
194         }else if(eventId==vtkCommand::InteractionEvent){
195                 CutModelMainPanel::getInstance()->updateActorDirection(this->getId());
196         }else if(eventId==vtkCommand::RightButtonReleaseEvent){
197                 //  =(
198         CutModelMainPanel::getInstance()->ShowPopUpMenu(this->getId());
199         }
200 }
201
202 void CutModelView::ExecuteCut(){        
203         if(this->isCut()){
204                 CutModelMainPanel::getInstance()->ExecuteCut(this->getId(),this->getRange(),this->isInside());
205         }else{
206         }
207         
208 }
209
210 double* CutModelView::getRange(){
211         double* x = new double[3];
212         x[0] = 0;
213         x[1] = _sliderrange->GetValue();
214         x[2] = 100000;
215
216         return x;
217 }
218 bool CutModelView::isCut(){
219         return true;
220         //return _radiocutstat->GetSelection()==0;
221 }
222 bool CutModelView::isInside(){
223         return _radioinsideout->GetSelection()==0;
224 }
225 void CutModelView::SetCurrentColor(wxColour colour){
226         _currentcolor->SetBackgroundColour(colour);
227
228         this->Refresh();
229         this->Layout();
230 }
231
232 void CutModelViewEventHandler::onColorChange(wxCommandEvent& event){
233         CutModelView* parent = (CutModelView*)((wxWindow*)event.GetEventObject())->GetParent();
234         wxColourDialog* colourdiag = new wxColourDialog(parent);
235         if(colourdiag->ShowModal()==wxID_OK){
236                 wxColour colour = colourdiag->GetColourData().GetColour();
237                 
238                 parent->SetCurrentColor(colour);
239
240                 double r = (double)(colour.Red())/255.0;
241                 double g = (double)(colour.Green())/255.0;
242                 double b = (double)(colour.Blue())/255.0;               
243                 CutModelMainPanel::getInstance()->changeColor(parent->getId(),r,g,b);
244
245
246         }
247         delete colourdiag;
248 }
249
250 void CutModelViewEventHandler::onOpacityChange(wxScrollEvent& event){
251         CutModelView* parent = (CutModelView*)((wxWindow*)event.GetEventObject())->GetParent();
252
253         CutModelMainPanel::getInstance()->changeOpacity(parent->getId(),event.GetInt());
254 }
255 void CutModelViewEventHandler::onViewBoxChecked(wxCommandEvent& event){
256     CutModelView* parent = (CutModelView*)((wxWindow*)event.GetEventObject())->GetParent();
257
258         CutModelMainPanel::getInstance()->ShowViewBox(parent->getId(),event.IsChecked());
259 }
260 void CutModelViewEventHandler::onShapeChange(wxCommandEvent& event){
261         CutModelView* parent = (CutModelView*)((wxWindow*)event.GetEventObject())->GetParent();
262
263         //if(event.GetSelection()>0){
264                 //std::cout<<"id in CutModelViewEventHandler:: "<<parent->getId()<<std::endl;
265         CutModelMainPanel::getInstance()->ChangeShape(parent->getId(),event.GetSelection());
266         //}
267 }
268 void CutModelViewEventHandler::onStatistics(wxCommandEvent& event){
269         CutModelView* parent = (CutModelView*)((wxWindow*)event.GetEventObject())->GetParent();
270         CutModelMainPanel::getInstance()->ShowStatistics(parent->getId());
271 }
272 void CutModelViewEventHandler::onExecute(wxCommandEvent& event){
273      CutModelView* parent = (CutModelView*)((wxWindow*)event.GetEventObject())->GetParent();
274
275          parent->ExecuteCut();
276          
277 }