CutModelView.cxx

Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Program:   wxMaracas
00004   Module:    $RCSfile: CutModelView.cxx,v $
00005   Language:  C++
00006   Date:      $Date: 2009/09/01 14:01:35 $
00007   Version:   $Revision: 1.2 $
00008 
00009   Copyright: (c) 2002, 2003
00010   License:
00011 
00012      This software is distributed WITHOUT ANY WARRANTY; without even
00013      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
00014      PURPOSE.  See the above copyright notice for more information.
00015 
00016 =========================================================================*/
00017 
00018 
00019 
00020 // EOF - wxMaracasMPR.cxx
00021 
00022 #include "CutModelView.h"
00023 
00024 
00025 #include <wx/colordlg.h>
00026 #include <wx/bmpbuttn.h>
00027 
00028 #include <OpenImage.xpm>
00029 #include <Color.xpm>
00030 #include <Ok1.xpm>
00031 #include <Statistics.xpm>
00032 
00033 #include "vtkBoxWidget.h"
00034 
00035 #include "CutModelMainPanel.h"
00036 
00037 CutModelView::CutModelView( wxWindow* parent, double* range)
00038 : wxPanel(parent, -1, wxDefaultPosition, wxDefaultSize){
00039 
00040         wxBoxSizer* sizer = new wxBoxSizer(wxVERTICAL);
00041 
00042         this->SetSizer(sizer);  
00043         
00044         sizer->Add(getBoxControls(this, range),wxSizerFlags().FixedMinSize());  
00045 
00046         sizer->AddSpacer(5);
00047 
00048         sizer->Add(getActorProperties(this),wxSizerFlags().FixedMinSize());     
00049 
00050 
00051         wxBitmap bitmapok(Ok1_xpm);
00052         wxBitmapButton* okbutton = new wxBitmapButton(this, -1, bitmapok,wxDefaultPosition,wxSize(30,30));                      
00053         Connect(okbutton->GetId(), wxEVT_COMMAND_BUTTON_CLICKED, (wxObjectEventFunction)(&CutModelViewEventHandler::onExecute));        
00054         
00055         sizer->AddSpacer(5);
00056         sizer->Add(okbutton,wxSizerFlags().FixedMinSize());
00057 
00058 
00059         
00060 
00061 
00062 }
00063 CutModelView::~CutModelView( ){
00064         CutModelMainPanel::getInstance()->RemoveActor(this->getId());
00065 }
00066 
00067 wxSizer* CutModelView::getBoxControls(wxWindow* parent,double* range){
00068 
00069         wxBoxSizer* sizer = new wxBoxSizer(wxVERTICAL);
00070         wxCheckBox* checkbox = new wxCheckBox(parent,-1,_T("View Box"));
00071         sizer->Add(checkbox,wxSizerFlags().FixedMinSize());
00072         checkbox->SetValue(true);
00073         Connect(checkbox->GetId(), wxEVT_COMMAND_CHECKBOX_CLICKED,(wxObjectEventFunction)(&CutModelViewEventHandler::onViewBoxChecked));
00074 
00075         wxString choices1[3];
00076         //choices1[0] = _T("Select a shape...");
00077         choices1[0] = _T("Sphere");
00078         choices1[1] = _T("Cylinder");
00079         choices1[2] = _T("Cube");
00080         wxComboBox* combo = new wxComboBox(parent, -1,_T(""),wxDefaultPosition,wxDefaultSize,3,choices1);
00081         combo->SetValue(_T("Sphere"));
00082         sizer->Add(combo,wxSizerFlags().FixedMinSize());
00083         Connect(combo->GetId(), wxEVT_COMMAND_COMBOBOX_SELECTED,(wxObjectEventFunction)(&CutModelViewEventHandler::onShapeChange));
00084 
00085         wxStaticText* labelgreyv = new wxStaticText(parent, -1, wxString(_T("Grey value range")));      
00086         _sliderrange = new wxSlider(parent, -1, range[0],range[0],range[1],wxDefaultPosition,wxDefaultSize,wxSL_LABELS|wxSL_SELRANGE);
00087         wxBoxSizer* sizergreyv = new wxBoxSizer(wxVERTICAL);
00088         sizergreyv->Add(labelgreyv,wxSizerFlags().FixedMinSize());
00089         sizergreyv->Add(_sliderrange,wxSizerFlags().FixedMinSize());
00090         sizer->Add(sizergreyv,wxSizerFlags().FixedMinSize().Border());
00091         
00092         wxString choices0[2];
00093         choices0[0] = _T("inside");
00094         choices0[1] = _T("outside");
00095         _radioinsideout = new  wxRadioBox(parent,-1,_T(""), wxDefaultPosition, wxDefaultSize,2,choices0);
00096         sizer->Add(_radioinsideout,wxSizerFlags().FixedMinSize());
00097 
00098         /*wxString choices[2];
00099         choices[0] = _T("Cut");
00100         choices[1] = _T("Statistics");
00101         _radiocutstat = new  wxRadioBox(parent,-1,_T(""), wxDefaultPosition, wxDefaultSize,2,choices);
00102         sizer->Add(_radiocutstat,wxSizerFlags().FixedMinSize());*/
00103 
00104         wxBitmap bitmap(Statistics_xpm);
00105         wxBitmapButton* statbut = new wxBitmapButton(parent, -1, bitmap,wxDefaultPosition,wxSize(30,30));                       
00106         Connect(statbut->GetId(), wxEVT_COMMAND_BUTTON_CLICKED, (wxObjectEventFunction)(&CutModelViewEventHandler::onStatistics));      
00107     sizer->Add(statbut,wxSizerFlags().FixedMinSize());
00108 
00109         
00110 
00111         return sizer;
00112 }
00113 wxSizer* CutModelView::getActorProperties(wxWindow* parent){
00114 
00115         wxBoxSizer* sizeractorproperties = new wxBoxSizer(wxVERTICAL);  
00116 
00117         wxStaticText* labelshapeactor = new wxStaticText(parent, -1, wxString(_T("Actor's properties")));
00118 
00119         sizeractorproperties->Add(labelshapeactor,wxSizerFlags().FixedMinSize());
00120 
00121         sizeractorproperties->Add(getColorChooseActor(parent),wxSizerFlags().FixedMinSize());
00122 
00123         sizeractorproperties->Add(getOpacityActor(parent),wxSizerFlags().FixedMinSize());
00124 
00125         return sizeractorproperties;
00126         
00127 }
00128 
00129 wxSizer* CutModelView::getOpacityActor(wxWindow* parent){
00130         wxBoxSizer* sizeropacity = new wxBoxSizer(wxVERTICAL);  
00131 
00132         wxStaticText* labelopacity = new wxStaticText(parent, -1, wxString(_T("Opacity")));
00133         wxSlider* slider0 = new wxSlider(parent, -1, 60,0,100,wxDefaultPosition,wxDefaultSize,wxSL_LABELS);
00134         Connect(slider0->GetId(), wxEVT_SCROLL_THUMBRELEASE,(wxObjectEventFunction)(&CutModelViewEventHandler::onOpacityChange));       
00135         
00136         sizeropacity->Add(labelopacity,wxSizerFlags().FixedMinSize());
00137         sizeropacity->Add(slider0,wxSizerFlags().FixedMinSize());
00138 
00139         return sizeropacity;
00140 }
00141 
00142 wxSizer* CutModelView::getColorChooseActor(wxWindow* parent){
00143     wxBoxSizer* sizercolor = new wxBoxSizer(wxHORIZONTAL);
00144         wxBitmap bitmap(Color_xpm);
00145         wxBitmapButton* colorchoose = new wxBitmapButton(parent, -1, bitmap,wxDefaultPosition,wxSize(30,30));            
00146         wxObjectEventFunction f = (wxObjectEventFunction)(&CutModelViewEventHandler::onColorChange);    
00147         Connect(colorchoose->GetId(), wxEVT_COMMAND_BUTTON_CLICKED, f); 
00148 
00149         _currentcolor = new wxStaticText(parent,-1,_T(""),wxDefaultPosition,wxSize(20,20));
00150         this->SetCurrentColor(wxColour(255.0,0.0,0.0));
00151 
00152         sizercolor->Add(colorchoose,wxSizerFlags().FixedMinSize());
00153         sizercolor->AddSpacer(5);
00154         sizercolor->Add(_currentcolor,wxSizerFlags().FixedMinSize().Centre());
00155         return sizercolor;
00156 }
00157 
00158 void CutModelView::checkInvariant()throw (CutModelException){
00159         
00160 }
00161 
00162 void CutModelView::Execute(vtkObject *wdg, unsigned long eventId, void* calldata) {  // virtual
00163         //vtkBoxWidget *boxwidget = reinterpret_cast<vtkBoxWidget*>(wdg);
00164 
00165         if(eventId==vtkCommand::StartInteractionEvent){
00166         CutModelMainPanel::getInstance()->ShowCurrentPanel(this->getId());
00167         }else if(eventId==vtkCommand::InteractionEvent){
00168                 CutModelMainPanel::getInstance()->updateActorDirection(this->getId());
00169         }else if(eventId==vtkCommand::RightButtonReleaseEvent){
00170                 //  =(
00171         CutModelMainPanel::getInstance()->ShowPopUpMenu(this->getId());
00172         }
00173 }
00174 
00175 void CutModelView::ExecuteCut(){        
00176         if(this->isCut()){
00177                 CutModelMainPanel::getInstance()->ExecuteCut(this->getId(),this->getRange(),this->isInside());
00178         }else{
00179         }
00180         
00181 }
00182 
00183 double* CutModelView::getRange(){
00184         double* x = new double[3];
00185         x[0] = 0;
00186         x[1] = _sliderrange->GetValue();
00187         x[2] = 100000;
00188 
00189         return x;
00190 }
00191 bool CutModelView::isCut(){
00192         return true;
00193         //return _radiocutstat->GetSelection()==0;
00194 }
00195 bool CutModelView::isInside(){
00196         return _radioinsideout->GetSelection()==0;
00197 }
00198 void CutModelView::SetCurrentColor(wxColour colour){
00199         _currentcolor->SetBackgroundColour(colour);
00200 
00201         this->Refresh();
00202         this->Layout();
00203 }
00204 
00205 void CutModelViewEventHandler::onColorChange(wxCommandEvent& event){
00206         CutModelView* parent = (CutModelView*)((wxWindow*)event.GetEventObject())->GetParent();
00207         wxColourDialog* colourdiag = new wxColourDialog(parent);
00208         if(colourdiag->ShowModal()==wxID_OK){
00209                 wxColour colour = colourdiag->GetColourData().GetColour();
00210                 
00211                 parent->SetCurrentColor(colour);
00212 
00213                 double r = (double)(colour.Red())/255.0;
00214                 double g = (double)(colour.Green())/255.0;
00215                 double b = (double)(colour.Blue())/255.0;               
00216                 CutModelMainPanel::getInstance()->changeColor(parent->getId(),r,g,b);
00217 
00218 
00219         }
00220         delete colourdiag;
00221 }
00222 
00223 void CutModelViewEventHandler::onOpacityChange(wxScrollEvent& event){
00224         CutModelView* parent = (CutModelView*)((wxWindow*)event.GetEventObject())->GetParent();
00225 
00226         CutModelMainPanel::getInstance()->changeOpacity(parent->getId(),event.GetInt());
00227 }
00228 void CutModelViewEventHandler::onViewBoxChecked(wxCommandEvent& event){
00229     CutModelView* parent = (CutModelView*)((wxWindow*)event.GetEventObject())->GetParent();
00230 
00231         CutModelMainPanel::getInstance()->ShowViewBox(parent->getId(),event.IsChecked());
00232 }
00233 void CutModelViewEventHandler::onShapeChange(wxCommandEvent& event){
00234         CutModelView* parent = (CutModelView*)((wxWindow*)event.GetEventObject())->GetParent();
00235 
00236         //if(event.GetSelection()>0){
00237                 //std::cout<<"id in CutModelViewEventHandler:: "<<parent->getId()<<std::endl;
00238         CutModelMainPanel::getInstance()->ChangeShape(parent->getId(),event.GetSelection());
00239         //}
00240 }
00241 void CutModelViewEventHandler::onStatistics(wxCommandEvent& event){
00242         CutModelView* parent = (CutModelView*)((wxWindow*)event.GetEventObject())->GetParent();
00243         CutModelMainPanel::getInstance()->ShowStatistics(parent->getId());
00244 }
00245 void CutModelViewEventHandler::onExecute(wxCommandEvent& event){
00246      CutModelView* parent = (CutModelView*)((wxWindow*)event.GetEventObject())->GetParent();
00247 
00248          parent->ExecuteCut();
00249          
00250 }

Generated on 18 Mar 2010 for creaMaracasVisu_lib by  doxygen 1.6.1