1 /*# ---------------------------------------------------------------------
3 # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
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
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.
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
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 # ------------------------------------------------------------------------ */
26 /*=========================================================================
29 Module: $RCSfile: CutModelView.cxx,v $
31 Date: $Date: 2012/11/15 14:16:20 $
32 Version: $Revision: 1.4 $
34 Copyright: (c) 2002, 2003
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.
41 =========================================================================*/
45 // EOF - wxMaracasMPR.cxx
47 #include "CutModelView.h"
50 #include <wx/colordlg.h>
51 #include <wx/bmpbuttn.h>
53 #include <OpenImage.xpm>
56 #include <Statistics.xpm>
58 #include "vtkBoxWidget.h"
60 #include "CutModelMainPanel.h"
62 CutModelView::CutModelView( wxWindow* parent, double* range)
63 : wxPanel(parent, -1, wxDefaultPosition, wxDefaultSize){
65 wxBoxSizer* sizer = new wxBoxSizer(wxVERTICAL);
67 this->SetSizer(sizer);
69 sizer->Add(getBoxControls(this, range),wxSizerFlags().FixedMinSize());
73 sizer->Add(getActorProperties(this),wxSizerFlags().FixedMinSize());
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));
81 sizer->Add(okbutton,wxSizerFlags().FixedMinSize());
88 CutModelView::~CutModelView( ){
89 CutModelMainPanel::getInstance()->RemoveActor(this->getId());
92 wxSizer* CutModelView::getBoxControls(wxWindow* parent,double* range){
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));
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));
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);
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());
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());*/
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());
138 wxSizer* CutModelView::getActorProperties(wxWindow* parent){
140 wxBoxSizer* sizeractorproperties = new wxBoxSizer(wxVERTICAL);
142 wxStaticText* labelshapeactor = new wxStaticText(parent, -1, wxString(_T("Actor's properties")));
144 sizeractorproperties->Add(labelshapeactor,wxSizerFlags().FixedMinSize());
146 sizeractorproperties->Add(getColorChooseActor(parent),wxSizerFlags().FixedMinSize());
148 sizeractorproperties->Add(getOpacityActor(parent),wxSizerFlags().FixedMinSize());
150 return sizeractorproperties;
154 wxSizer* CutModelView::getOpacityActor(wxWindow* parent){
155 wxBoxSizer* sizeropacity = new wxBoxSizer(wxVERTICAL);
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));
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);
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);
176 _currentcolor = new wxStaticText(parent,-1,_T(""),wxDefaultPosition,wxSize(20,20));
177 this->SetCurrentColor(wxColour(255.0,0.0,0.0));
179 sizercolor->Add(colorchoose,wxSizerFlags().FixedMinSize());
180 sizercolor->AddSpacer(5);
181 sizercolor->Add(_currentcolor,wxSizerFlags().FixedMinSize().Centre());
185 void CutModelView::checkInvariant()throw (CutModelException){
189 void CutModelView::Execute(vtkObject *wdg, unsigned long eventId, void* calldata) { // virtual
190 //vtkBoxWidget *boxwidget = reinterpret_cast<vtkBoxWidget*>(wdg);
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){
198 CutModelMainPanel::getInstance()->ShowPopUpMenu(this->getId());
202 void CutModelView::ExecuteCut(){
204 CutModelMainPanel::getInstance()->ExecuteCut(this->getId(),this->getRange(),this->isInside());
210 double* CutModelView::getRange(){
211 double* x = new double[3];
213 x[1] = _sliderrange->GetValue();
218 bool CutModelView::isCut(){
220 //return _radiocutstat->GetSelection()==0;
222 bool CutModelView::isInside(){
223 return _radioinsideout->GetSelection()==0;
225 void CutModelView::SetCurrentColor(wxColour colour){
226 _currentcolor->SetBackgroundColour(colour);
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();
238 parent->SetCurrentColor(colour);
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);
250 void CutModelViewEventHandler::onOpacityChange(wxScrollEvent& event){
251 CutModelView* parent = (CutModelView*)((wxWindow*)event.GetEventObject())->GetParent();
253 CutModelMainPanel::getInstance()->changeOpacity(parent->getId(),event.GetInt());
255 void CutModelViewEventHandler::onViewBoxChecked(wxCommandEvent& event){
256 CutModelView* parent = (CutModelView*)((wxWindow*)event.GetEventObject())->GetParent();
258 CutModelMainPanel::getInstance()->ShowViewBox(parent->getId(),event.IsChecked());
260 void CutModelViewEventHandler::onShapeChange(wxCommandEvent& event){
261 CutModelView* parent = (CutModelView*)((wxWindow*)event.GetEventObject())->GetParent();
263 //if(event.GetSelection()>0){
264 //std::cout<<"id in CutModelViewEventHandler:: "<<parent->getId()<<std::endl;
265 CutModelMainPanel::getInstance()->ChangeShape(parent->getId(),event.GetSelection());
268 void CutModelViewEventHandler::onStatistics(wxCommandEvent& event){
269 CutModelView* parent = (CutModelView*)((wxWindow*)event.GetEventObject())->GetParent();
270 CutModelMainPanel::getInstance()->ShowStatistics(parent->getId());
272 void CutModelViewEventHandler::onExecute(wxCommandEvent& event){
273 CutModelView* parent = (CutModelView*)((wxWindow*)event.GetEventObject())->GetParent();
275 parent->ExecuteCut();