/*========================================================================= Program: wxMaracas Module: $RCSfile: CutModel2View.cxx,v $ Language: C++ Date: $Date: 2009/11/19 15:24:56 $ Version: $Revision: 1.1 $ Copyright: (c) 2002, 2003 License: This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the above copyright notice for more information. =========================================================================*/ // EOF - wxMaracasMPR.cxx #include "CutModel2View.h" #include #include #include #include #include #include #include "vtkBoxWidget.h" #include "CutModel2MainPanel.h" CutModel2View::CutModel2View( wxWindow* parent, double* range) : wxPanel(parent, -1, wxDefaultPosition, wxDefaultSize){ wxBoxSizer* sizer = new wxBoxSizer(wxVERTICAL); this->SetSizer(sizer); sizer->Add(getBoxControls(this, range),wxSizerFlags().FixedMinSize()); sizer->AddSpacer(5); sizer->Add(getActorProperties(this),wxSizerFlags().FixedMinSize()); wxBitmap bitmapok(Ok1_xpm); wxBitmapButton* okbutton = new wxBitmapButton(this, -1, bitmapok,wxDefaultPosition,wxSize(30,30)); Connect(okbutton->GetId(), wxEVT_COMMAND_BUTTON_CLICKED, (wxObjectEventFunction)(&CutModel2ViewEventHandler::onExecute)); sizer->AddSpacer(5); sizer->Add(okbutton,wxSizerFlags().FixedMinSize()); } CutModel2View::~CutModel2View( ){ CutModel2MainPanel::getInstance()->RemoveActor(this->getId()); } wxSizer* CutModel2View::getBoxControls(wxWindow* parent,double* range){ wxBoxSizer* sizer = new wxBoxSizer(wxVERTICAL); wxCheckBox* checkbox = new wxCheckBox(parent,-1,_T("View Box")); sizer->Add(checkbox,wxSizerFlags().FixedMinSize()); checkbox->SetValue(true); Connect(checkbox->GetId(), wxEVT_COMMAND_CHECKBOX_CLICKED,(wxObjectEventFunction)(&CutModel2ViewEventHandler::onViewBoxChecked)); wxString choices1[3]; //choices1[0] = _T("Select a shape..."); choices1[0] = _T("Sphere"); choices1[1] = _T("Cylinder"); choices1[2] = _T("Cube"); wxComboBox* combo = new wxComboBox(parent, -1,_T(""),wxDefaultPosition,wxDefaultSize,3,choices1); combo->SetValue(_T("Sphere")); sizer->Add(combo,wxSizerFlags().FixedMinSize()); Connect(combo->GetId(), wxEVT_COMMAND_COMBOBOX_SELECTED,(wxObjectEventFunction)(&CutModel2ViewEventHandler::onShapeChange)); wxStaticText* labelgreyv = new wxStaticText(parent, -1, wxString(_T("Grey value range"))); _sliderrange = new wxSlider(parent, -1, range[0],range[0],range[1],wxDefaultPosition,wxDefaultSize,wxSL_LABELS|wxSL_SELRANGE); wxBoxSizer* sizergreyv = new wxBoxSizer(wxVERTICAL); sizergreyv->Add(labelgreyv,wxSizerFlags().FixedMinSize()); sizergreyv->Add(_sliderrange,wxSizerFlags().FixedMinSize()); sizer->Add(sizergreyv,wxSizerFlags().FixedMinSize().Border()); wxString choices0[2]; choices0[0] = _T("inside"); choices0[1] = _T("outside"); _radioinsideout = new wxRadioBox(parent,-1,_T(""), wxDefaultPosition, wxDefaultSize,2,choices0); sizer->Add(_radioinsideout,wxSizerFlags().FixedMinSize()); /*wxString choices[2]; choices[0] = _T("Cut"); choices[1] = _T("Statistics"); _radiocutstat = new wxRadioBox(parent,-1,_T(""), wxDefaultPosition, wxDefaultSize,2,choices); sizer->Add(_radiocutstat,wxSizerFlags().FixedMinSize());*/ wxBitmap bitmap(Statistics_xpm); wxBitmapButton* statbut = new wxBitmapButton(parent, -1, bitmap,wxDefaultPosition,wxSize(30,30)); Connect(statbut->GetId(), wxEVT_COMMAND_BUTTON_CLICKED, (wxObjectEventFunction)(&CutModel2ViewEventHandler::onStatistics)); sizer->Add(statbut,wxSizerFlags().FixedMinSize()); return sizer; } wxSizer* CutModel2View::getActorProperties(wxWindow* parent){ wxBoxSizer* sizeractorproperties = new wxBoxSizer(wxVERTICAL); wxStaticText* labelshapeactor = new wxStaticText(parent, -1, wxString(_T("Actor's properties"))); sizeractorproperties->Add(labelshapeactor,wxSizerFlags().FixedMinSize()); sizeractorproperties->Add(getColorChooseActor(parent),wxSizerFlags().FixedMinSize()); sizeractorproperties->Add(getOpacityActor(parent),wxSizerFlags().FixedMinSize()); return sizeractorproperties; } wxSizer* CutModel2View::getOpacityActor(wxWindow* parent){ wxBoxSizer* sizeropacity = new wxBoxSizer(wxVERTICAL); wxStaticText* labelopacity = new wxStaticText(parent, -1, wxString(_T("Opacity"))); wxSlider* slider0 = new wxSlider(parent, -1, 60,0,100,wxDefaultPosition,wxDefaultSize,wxSL_LABELS); Connect(slider0->GetId(), wxEVT_SCROLL_THUMBRELEASE,(wxObjectEventFunction)(&CutModel2ViewEventHandler::onOpacityChange)); sizeropacity->Add(labelopacity,wxSizerFlags().FixedMinSize()); sizeropacity->Add(slider0,wxSizerFlags().FixedMinSize()); return sizeropacity; } wxSizer* CutModel2View::getColorChooseActor(wxWindow* parent){ wxBoxSizer* sizercolor = new wxBoxSizer(wxHORIZONTAL); wxBitmap bitmap(Color_xpm); wxBitmapButton* colorchoose = new wxBitmapButton(parent, -1, bitmap,wxDefaultPosition,wxSize(30,30)); wxObjectEventFunction f = (wxObjectEventFunction)(&CutModel2ViewEventHandler::onColorChange); Connect(colorchoose->GetId(), wxEVT_COMMAND_BUTTON_CLICKED, f); _currentcolor = new wxStaticText(parent,-1,_T(""),wxDefaultPosition,wxSize(20,20)); this->SetCurrentColor(wxColour(255.0,0.0,0.0)); sizercolor->Add(colorchoose,wxSizerFlags().FixedMinSize()); sizercolor->AddSpacer(5); sizercolor->Add(_currentcolor,wxSizerFlags().FixedMinSize().Centre()); return sizercolor; } void CutModel2View::checkInvariant()throw (CutModel2Exception){ } void CutModel2View::Execute(vtkObject *wdg, unsigned long eventId, void* calldata) { // virtual //vtkBoxWidget *boxwidget = reinterpret_cast(wdg); if(eventId==vtkCommand::StartInteractionEvent){ CutModel2MainPanel::getInstance()->ShowCurrentPanel(this->getId()); }else if(eventId==vtkCommand::InteractionEvent){ CutModel2MainPanel::getInstance()->updateActorDirection(this->getId()); }else if(eventId==vtkCommand::RightButtonReleaseEvent){ // =( CutModel2MainPanel::getInstance()->ShowPopUpMenu(this->getId()); } } void CutModel2View::ExecuteCut(){ if(this->isCut()){ CutModel2MainPanel::getInstance()->ExecuteCut(this->getId(),this->getRange(),this->isInside()); }else{ } } double* CutModel2View::getRange(){ double* x = new double[3]; x[0] = 0; x[1] = _sliderrange->GetValue(); x[2] = 100000; return x; } bool CutModel2View::isCut(){ return true; //return _radiocutstat->GetSelection()==0; } bool CutModel2View::isInside(){ return _radioinsideout->GetSelection()==0; } void CutModel2View::SetCurrentColor(wxColour colour){ _currentcolor->SetBackgroundColour(colour); this->Refresh(); this->Layout(); } void CutModel2ViewEventHandler::onColorChange(wxCommandEvent& event){ CutModel2View* parent = (CutModel2View*)((wxWindow*)event.GetEventObject())->GetParent(); wxColourDialog* colourdiag = new wxColourDialog(parent); if(colourdiag->ShowModal()==wxID_OK){ wxColour colour = colourdiag->GetColourData().GetColour(); parent->SetCurrentColor(colour); double r = (double)(colour.Red())/255.0; double g = (double)(colour.Green())/255.0; double b = (double)(colour.Blue())/255.0; CutModel2MainPanel::getInstance()->changeColor(parent->getId(),r,g,b); } delete colourdiag; } void CutModel2ViewEventHandler::onOpacityChange(wxScrollEvent& event){ CutModel2View* parent = (CutModel2View*)((wxWindow*)event.GetEventObject())->GetParent(); CutModel2MainPanel::getInstance()->changeOpacity(parent->getId(),event.GetInt()); } void CutModel2ViewEventHandler::onViewBoxChecked(wxCommandEvent& event){ CutModel2View* parent = (CutModel2View*)((wxWindow*)event.GetEventObject())->GetParent(); CutModel2MainPanel::getInstance()->ShowViewBox(parent->getId(),event.IsChecked()); } void CutModel2ViewEventHandler::onShapeChange(wxCommandEvent& event){ CutModel2View* parent = (CutModel2View*)((wxWindow*)event.GetEventObject())->GetParent(); //if(event.GetSelection()>0){ //std::cout<<"id in CutModel2ViewEventHandler:: "<getId()<ChangeShape(parent->getId(),event.GetSelection()); //} } void CutModel2ViewEventHandler::onStatistics(wxCommandEvent& event){ CutModel2View* parent = (CutModel2View*)((wxWindow*)event.GetEventObject())->GetParent(); CutModel2MainPanel::getInstance()->ShowStatistics(parent->getId()); } void CutModel2ViewEventHandler::onExecute(wxCommandEvent& event){ CutModel2View* parent = (CutModel2View*)((wxWindow*)event.GetEventObject())->GetParent(); parent->ExecuteCut(); }