/*========================================================================= Program: wxMaracas Module: $RCSfile: CutModel2MainPanel.cxx,v $ Language: C++ Date: $Date: 2009/11/19 16:34:43 $ Version: $Revision: 1.3 $ 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 "CutModel2MainPanel.h" #include "HistogramDialog.h" #include "creaSystem.h" #include #include #include #include #include #include CutModel2MainPanel* CutModel2MainPanel::instance=NULL; CutModel2MainPanel::CutModel2MainPanel( wxWindow* parent, std::string path) : wxPanel(parent, -1, wxDefaultPosition, wxDefaultSize){ cutmanager=NULL; initialize(path); } CutModel2MainPanel::~CutModel2MainPanel( ){ delete cutmanager; } void CutModel2MainPanel::initialize(std::string path){ cutmanager = new CutModelManager(path); _panelid = 0; _wxauimanager = new wxAuiManager(this); wxAuiPaneInfo paneinfo; _wxauimanager->AddPane(new ToolBarCutModel2(this),paneinfo.ToolbarPane().Top()); _wxauimanager->Update(); } CutModel2MainPanel* CutModel2MainPanel::getInstance(wxWindow* parent, std::string path){ if(instance==NULL){ if(parent == NULL){ parent = new wxFrame(); } instance = new CutModel2MainPanel(parent, path); } return instance; } /*CutModel2MainPanel* CutModel2MainPanel::getInstance(){ return instance; }*/ void CutModel2MainPanel::setImageData(vtkImageData* img){ try{ checkInvariant(); cutmanager->setImageData(img); }catch(CutModel2Exception e){ showErrorDialog(e.getCause()); } } void CutModel2MainPanel::setInteractor(vtkRenderWindowInteractor* interactor){ try{ checkInvariant(); cutmanager->setInteractor(interactor); }catch(CutModelException e){ showErrorDialog(e.getCause()); } } void CutModel2MainPanel::setRenderer(vtkRenderer* renderer){ try{ checkInvariant(); cutmanager->setRenderer(renderer); }catch(CutModel2Exception e){ showErrorDialog(e.getCause()); } } void CutModel2MainPanel::checkInvariant()throw (CutModelException){ if(cutmanager==NULL){ throw CutModelException("The manager is not initialize"); } } void CutModel2MainPanel::showErrorDialog(std::string str){ wxMessageDialog* diag = new wxMessageDialog(this, wxString(str.c_str(),wxConvUTF8 ), wxString(str.c_str(),wxConvUTF8 ), wxICON_ERROR); diag->ShowModal(); } void CutModel2MainPanel::RemoveActor(int id){ try{ checkInvariant(); for(int i = 0; i < viewpanels.size()-1;i++){ if(viewpanels[i]->getId()==id){ for(int j = i; j < viewpanels.size()-1;j++){ viewpanels[j]=viewpanels[j+1]; } i = viewpanels.size(); } } viewpanels.pop_back(); cutmanager->RemoveActor(id); }catch(CutModel2Exception e){ showErrorDialog(e.getCause()); } } void CutModel2MainPanel::onAddCutModel2(){ try{ checkInvariant(); int id = addNewViewPanel(); cutmanager->onAddCutModel(id, getModelView(id)); _panelid++; ShowCurrentPanel(id); }catch(CutModel2Exception e){ showErrorDialog(e.getCause()); } } void CutModel2MainPanel::ShowCurrentPanel(int id){ for(int i = 0; i < viewpanels.size();i++){ if(viewpanels[i]->getId()==id){ _wxauimanager->GetPane(viewpanels[i]).Show(true); cutmanager->RefreshActor(id); }else{ _wxauimanager->GetPane(viewpanels[i]).Show(false); } } _wxauimanager->Update(); } int CutModel2MainPanel::addNewViewPanel()throw( CutModelException){ CutModelView* viewpanel = new CutModelView(this,cutmanager->getImageRange()); wxAuiPaneInfo paneinfo0; _wxauimanager->AddPane(viewpanel, paneinfo0.DefaultPane().DestroyOnClose().Centre()); _wxauimanager->Update(); viewpanel->setId(_panelid); viewpanels.push_back(viewpanel); return viewpanel->getId(); } CutModel2View* CutModel2MainPanel::getModelView(int id)throw( CutModel2Exception){ CutModelView* current = NULL; for(int i = 0; i < viewpanels.size();i++){ if(viewpanels[i]->getId()==id){ current = viewpanels[i]; } } if(current == NULL){ std::string s = "Id not found"; throw CutModel2Exception(s); } return current; } void CutModel2MainPanel::onUndo(){ try{ checkInvariant(); int result = cutmanager->Undo(); }catch(CutModelException e){ showErrorDialog(e.getCause()); } } void CutModel2MainPanel::onRedo(){ try{ checkInvariant(); int result = cutmanager->Redo(); }catch(CutModelException e){ showErrorDialog(e.getCause()); } } void CutModel2MainPanel::changeOpacity(int id,int opacity){ try{ checkInvariant(); cutmanager->changeOpacity(id, opacity); }catch(CutModelException e){ showErrorDialog(e.getCause()); } } void CutModel2MainPanel::ShowViewBox(int id,bool check){ try{ checkInvariant(); cutmanager->ShowViewBox(id, check); }catch(CutModelException e){ showErrorDialog(e.getCause()); } } void CutModel2MainPanel::ShowPopUpMenu(int id){ showErrorDialog("test"); } void CutModel2MainPanel::changeColor(int id,double r,double g,double b){ try{ checkInvariant(); cutmanager->changeColor(id, r, g, b); }catch(CutModel2Exception e){ showErrorDialog(e.getCause()); } } void CutModel2MainPanel::ChangeShape(int id,int selection){ try{ checkInvariant(); cutmanager->ChangeShape(id, selection); }catch(CutModel2Exception e){ showErrorDialog(e.getCause()); } } void CutModel2MainPanel::updateActorDirection(int id){ try{ checkInvariant(); cutmanager->updateActorDirection(id); }catch(CutModel2Exception e){ showErrorDialog(e.getCause()); } } void CutModel2MainPanel::ExecuteCut(int id, double* range, bool isinside){ try{ checkInvariant(); cutmanager->ExecuteCut(id, range, isinside); }catch(CutModelException e){ showErrorDialog(e.getCause()); } } void CutModel2MainPanel::ExecuteAll(){ for(int i = 0; i < viewpanels.size();i++){ viewpanels[i]->ExecuteCut(); } } vtkImageData* CutModel2MainPanel::GetResultImage(){ try{ checkInvariant(); return cutmanager->GetResultImage(); }catch(CutModel2Exception e){ showErrorDialog(e.getCause()); } return NULL; } void CutModel2MainPanel::ShowStatistics(int id){ checkInvariant(); HistogramDialog *histo = new HistogramDialog(this, _T("Statistics")); histo->initializeHistogram(cutmanager->GetResultImage()); histo->ShowModal(); delete histo; } void CutModel2MainPanel::SaveCutModel2Data(std::string filename){ cutmanager->SaveCutModelData(filename); } void CutModel2MainPanel::LoadCutModel2Data(std::string filename){ cutmanager->LoadCutModelData(filename); } /** ** **/ ToolBarCutModel2::ToolBarCutModel2(wxWindow * parent) : wxToolBar(parent, -1, wxDefaultPosition, wxDefaultSize) { wxBitmap bitmap10(Add_xpm); this->AddTool(10, wxString(_T("Add")),bitmap10); this->AddSeparator(); wxBitmap bitmap20(Undo_xpm); this->AddTool(20, wxString(_T("Undo")),bitmap20); wxBitmap bitmap30(Redo_xpm); this->AddTool(30, wxString(_T("Redo")),bitmap30); this->AddSeparator(); wxBitmap bitmap40(OkAll_xpm); this->AddTool(40, wxString(_T("Ok All")),bitmap40); this->Realize(); _evthand = new ToolBarEventHandlerCutModel2(); this->SetEventHandler(_evthand); } ToolBarCutModel2::~ToolBarCutModel2(void){ } ToolBarEventHandlerCutModel2::ToolBarEventHandlerCutModel2() : wxEvtHandler(){ } ToolBarEventHandlerCutModel2::~ToolBarEventHandlerCutModel2(){ } void ToolBarEventHandlerCutModel2::onAdd(wxCommandEvent& event){ CutModel2MainPanel::getInstance()->onAddCutModel2(); } void ToolBarEventHandlerCutModel2::onUndo(wxCommandEvent& event){ CutModel2MainPanel::getInstance()->onUndo(); } void ToolBarEventHandlerCutModel2::onRedo(wxCommandEvent& event){ CutModel2MainPanel::getInstance()->onRedo(); } void ToolBarEventHandlerCutModel2::onExecuteAll(wxCommandEvent& event){ CutModel2MainPanel::getInstance()->ExecuteAll(); } BEGIN_EVENT_TABLE(ToolBarEventHandlerCutModel2, wxEvtHandler) EVT_MENU(10, ToolBarEventHandlerCutModel2::onAdd) EVT_MENU(20, ToolBarEventHandlerCutModel2::onUndo) EVT_MENU(30, ToolBarEventHandlerCutModel2::onRedo) EVT_MENU(40, ToolBarEventHandlerCutModel2::onExecuteAll) END_EVENT_TABLE()