1 /*=========================================================================
4 Module: $RCSfile: CutModelView.cxx,v $
6 Date: $Date: 2009/09/01 14:01:35 $
7 Version: $Revision: 1.2 $
9 Copyright: (c) 2002, 2003
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.
16 =========================================================================*/
20 // EOF - wxMaracasMPR.cxx
22 #include "CutModelView.h"
25 #include <wx/colordlg.h>
26 #include <wx/bmpbuttn.h>
28 #include <OpenImage.xpm>
31 #include <Statistics.xpm>
33 #include "vtkBoxWidget.h"
35 #include "CutModelMainPanel.h"
37 CutModelView::CutModelView( wxWindow* parent, double* range)
38 : wxPanel(parent, -1, wxDefaultPosition, wxDefaultSize){
40 wxBoxSizer* sizer = new wxBoxSizer(wxVERTICAL);
42 this->SetSizer(sizer);
44 sizer->Add(getBoxControls(this, range),wxSizerFlags().FixedMinSize());
48 sizer->Add(getActorProperties(this),wxSizerFlags().FixedMinSize());
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));
56 sizer->Add(okbutton,wxSizerFlags().FixedMinSize());
63 CutModelView::~CutModelView( ){
64 CutModelMainPanel::getInstance()->RemoveActor(this->getId());
67 wxSizer* CutModelView::getBoxControls(wxWindow* parent,double* range){
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));
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));
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());
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());
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());*/
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());
113 wxSizer* CutModelView::getActorProperties(wxWindow* parent){
115 wxBoxSizer* sizeractorproperties = new wxBoxSizer(wxVERTICAL);
117 wxStaticText* labelshapeactor = new wxStaticText(parent, -1, wxString(_T("Actor's properties")));
119 sizeractorproperties->Add(labelshapeactor,wxSizerFlags().FixedMinSize());
121 sizeractorproperties->Add(getColorChooseActor(parent),wxSizerFlags().FixedMinSize());
123 sizeractorproperties->Add(getOpacityActor(parent),wxSizerFlags().FixedMinSize());
125 return sizeractorproperties;
129 wxSizer* CutModelView::getOpacityActor(wxWindow* parent){
130 wxBoxSizer* sizeropacity = new wxBoxSizer(wxVERTICAL);
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));
136 sizeropacity->Add(labelopacity,wxSizerFlags().FixedMinSize());
137 sizeropacity->Add(slider0,wxSizerFlags().FixedMinSize());
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);
149 _currentcolor = new wxStaticText(parent,-1,_T(""),wxDefaultPosition,wxSize(20,20));
150 this->SetCurrentColor(wxColour(255.0,0.0,0.0));
152 sizercolor->Add(colorchoose,wxSizerFlags().FixedMinSize());
153 sizercolor->AddSpacer(5);
154 sizercolor->Add(_currentcolor,wxSizerFlags().FixedMinSize().Centre());
158 void CutModelView::checkInvariant()throw (CutModelException){
162 void CutModelView::Execute(vtkObject *wdg, unsigned long eventId, void* calldata) { // virtual
163 //vtkBoxWidget *boxwidget = reinterpret_cast<vtkBoxWidget*>(wdg);
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){
171 CutModelMainPanel::getInstance()->ShowPopUpMenu(this->getId());
175 void CutModelView::ExecuteCut(){
177 CutModelMainPanel::getInstance()->ExecuteCut(this->getId(),this->getRange(),this->isInside());
183 double* CutModelView::getRange(){
184 double* x = new double[3];
186 x[1] = _sliderrange->GetValue();
191 bool CutModelView::isCut(){
193 //return _radiocutstat->GetSelection()==0;
195 bool CutModelView::isInside(){
196 return _radioinsideout->GetSelection()==0;
198 void CutModelView::SetCurrentColor(wxColour colour){
199 _currentcolor->SetBackgroundColour(colour);
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();
211 parent->SetCurrentColor(colour);
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);
223 void CutModelViewEventHandler::onOpacityChange(wxScrollEvent& event){
224 CutModelView* parent = (CutModelView*)((wxWindow*)event.GetEventObject())->GetParent();
226 CutModelMainPanel::getInstance()->changeOpacity(parent->getId(),event.GetInt());
228 void CutModelViewEventHandler::onViewBoxChecked(wxCommandEvent& event){
229 CutModelView* parent = (CutModelView*)((wxWindow*)event.GetEventObject())->GetParent();
231 CutModelMainPanel::getInstance()->ShowViewBox(parent->getId(),event.IsChecked());
233 void CutModelViewEventHandler::onShapeChange(wxCommandEvent& event){
234 CutModelView* parent = (CutModelView*)((wxWindow*)event.GetEventObject())->GetParent();
236 //if(event.GetSelection()>0){
237 //std::cout<<"id in CutModelViewEventHandler:: "<<parent->getId()<<std::endl;
238 CutModelMainPanel::getInstance()->ChangeShape(parent->getId(),event.GetSelection());
241 void CutModelViewEventHandler::onStatistics(wxCommandEvent& event){
242 CutModelView* parent = (CutModelView*)((wxWindow*)event.GetEventObject())->GetParent();
243 CutModelMainPanel::getInstance()->ShowStatistics(parent->getId());
245 void CutModelViewEventHandler::onExecute(wxCommandEvent& event){
246 CutModelView* parent = (CutModelView*)((wxWindow*)event.GetEventObject())->GetParent();
248 parent->ExecuteCut();