1 /*=========================================================================
4 Module: $RCSfile: CutModelView.cxx,v $
6 Date: $Date: 2011/02/07 09:16:28 $
7 Version: $Revision: 1.3 $
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,1, wxGROW);
90 sizer->Add(sizergreyv, 1, wxGROW);
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,1, wxGROWwxSizerFlags().FixedMinSize());
137 sizeropacity->Add(labelopacity,1, wxGROW);
138 //sizeropacity->Add(slider0,wxSizerFlags().FixedMinSize());
139 sizeropacity->Add(slider0, 1, wxGROW);
144 wxSizer* CutModelView::getColorChooseActor(wxWindow* parent){
145 wxBoxSizer* sizercolor = new wxBoxSizer(wxHORIZONTAL);
146 wxBitmap bitmap(Color_xpm);
147 wxBitmapButton* colorchoose = new wxBitmapButton(parent, -1, bitmap,wxDefaultPosition,wxSize(30,30));
148 wxObjectEventFunction f = (wxObjectEventFunction)(&CutModelViewEventHandler::onColorChange);
149 Connect(colorchoose->GetId(), wxEVT_COMMAND_BUTTON_CLICKED, f);
151 _currentcolor = new wxStaticText(parent,-1,_T(""),wxDefaultPosition,wxSize(20,20));
152 this->SetCurrentColor(wxColour(255.0,0.0,0.0));
154 sizercolor->Add(colorchoose,wxSizerFlags().FixedMinSize());
155 sizercolor->AddSpacer(5);
156 sizercolor->Add(_currentcolor,wxSizerFlags().FixedMinSize().Centre());
160 void CutModelView::checkInvariant()throw (CutModelException){
164 void CutModelView::Execute(vtkObject *wdg, unsigned long eventId, void* calldata) { // virtual
165 //vtkBoxWidget *boxwidget = reinterpret_cast<vtkBoxWidget*>(wdg);
167 if(eventId==vtkCommand::StartInteractionEvent){
168 CutModelMainPanel::getInstance()->ShowCurrentPanel(this->getId());
169 }else if(eventId==vtkCommand::InteractionEvent){
170 CutModelMainPanel::getInstance()->updateActorDirection(this->getId());
171 }else if(eventId==vtkCommand::RightButtonReleaseEvent){
173 CutModelMainPanel::getInstance()->ShowPopUpMenu(this->getId());
177 void CutModelView::ExecuteCut(){
179 CutModelMainPanel::getInstance()->ExecuteCut(this->getId(),this->getRange(),this->isInside());
185 double* CutModelView::getRange(){
186 double* x = new double[3];
188 x[1] = _sliderrange->GetValue();
193 bool CutModelView::isCut(){
195 //return _radiocutstat->GetSelection()==0;
197 bool CutModelView::isInside(){
198 return _radioinsideout->GetSelection()==0;
200 void CutModelView::SetCurrentColor(wxColour colour){
201 _currentcolor->SetBackgroundColour(colour);
207 void CutModelViewEventHandler::onColorChange(wxCommandEvent& event){
208 CutModelView* parent = (CutModelView*)((wxWindow*)event.GetEventObject())->GetParent();
209 wxColourDialog* colourdiag = new wxColourDialog(parent);
210 if(colourdiag->ShowModal()==wxID_OK){
211 wxColour colour = colourdiag->GetColourData().GetColour();
213 parent->SetCurrentColor(colour);
215 double r = (double)(colour.Red())/255.0;
216 double g = (double)(colour.Green())/255.0;
217 double b = (double)(colour.Blue())/255.0;
218 CutModelMainPanel::getInstance()->changeColor(parent->getId(),r,g,b);
225 void CutModelViewEventHandler::onOpacityChange(wxScrollEvent& event){
226 CutModelView* parent = (CutModelView*)((wxWindow*)event.GetEventObject())->GetParent();
228 CutModelMainPanel::getInstance()->changeOpacity(parent->getId(),event.GetInt());
230 void CutModelViewEventHandler::onViewBoxChecked(wxCommandEvent& event){
231 CutModelView* parent = (CutModelView*)((wxWindow*)event.GetEventObject())->GetParent();
233 CutModelMainPanel::getInstance()->ShowViewBox(parent->getId(),event.IsChecked());
235 void CutModelViewEventHandler::onShapeChange(wxCommandEvent& event){
236 CutModelView* parent = (CutModelView*)((wxWindow*)event.GetEventObject())->GetParent();
238 //if(event.GetSelection()>0){
239 //std::cout<<"id in CutModelViewEventHandler:: "<<parent->getId()<<std::endl;
240 CutModelMainPanel::getInstance()->ChangeShape(parent->getId(),event.GetSelection());
243 void CutModelViewEventHandler::onStatistics(wxCommandEvent& event){
244 CutModelView* parent = (CutModelView*)((wxWindow*)event.GetEventObject())->GetParent();
245 CutModelMainPanel::getInstance()->ShowStatistics(parent->getId());
247 void CutModelViewEventHandler::onExecute(wxCommandEvent& event){
248 CutModelView* parent = (CutModelView*)((wxWindow*)event.GetEventObject())->GetParent();
250 parent->ExecuteCut();