/*========================================================================= Program: wxMaracas Module: $RCSfile: CutModelMainPanel.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 "CutModelMainPanel.h" #include "HistogramDialog.h" #include "creaSystem.h" #include #include #include #include #include #include CutModelMainPanel* CutModelMainPanel::instance=NULL; CutModelMainPanel::CutModelMainPanel( wxWindow* parent, std::string path) : wxPanel(parent, -1, wxDefaultPosition, wxDefaultSize){ cutmanager=NULL; initialize(path); } CutModelMainPanel::~CutModelMainPanel( ){ delete cutmanager; } void CutModelMainPanel::initialize(std::string path){ cutmanager = new CutModelManager(path); _panelid = 0; _wxauimanager = new wxAuiManager(this); wxAuiPaneInfo paneinfo; _wxauimanager->AddPane(new ToolBarCutModel(this),paneinfo.ToolbarPane().Top()); _wxauimanager->Update(); } CutModelMainPanel* CutModelMainPanel::getInstance(wxWindow* parent, std::string path){ if(instance==NULL){ if(parent == NULL){ parent = new wxFrame(); } instance = new CutModelMainPanel(parent, path); } return instance; } /*CutModelMainPanel* CutModelMainPanel::getInstance(){ return instance; }*/ void CutModelMainPanel::setImageData(vtkImageData* img){ try{ checkInvariant(); cutmanager->setImageData(img); }catch(CutModelException e){ showErrorDialog(e.getCause()); } } void CutModelMainPanel::setInteractor(vtkRenderWindowInteractor* interactor){ try{ checkInvariant(); cutmanager->setInteractor(interactor); }catch(CutModelException e){ showErrorDialog(e.getCause()); } } void CutModelMainPanel::setRenderer(vtkRenderer* renderer){ try{ checkInvariant(); cutmanager->setRenderer(renderer); }catch(CutModelException e){ showErrorDialog(e.getCause()); } } void CutModelMainPanel::checkInvariant()throw (CutModelException){ if(cutmanager==NULL){ throw CutModelException("The manager is not initialize"); } } void CutModelMainPanel::showErrorDialog(std::string str){ wxMessageDialog* diag = new wxMessageDialog(this, wxString(str.c_str(),wxConvUTF8 ), wxString(str.c_str(),wxConvUTF8 ), wxICON_ERROR); diag->ShowModal(); } void CutModelMainPanel::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(CutModelException e){ showErrorDialog(e.getCause()); } } void CutModelMainPanel::onAddCutModel(){ try{ checkInvariant(); int id = addNewViewPanel(); cutmanager->onAddCutModel(id, getModelView(id)); _panelid++; ShowCurrentPanel(id); }catch(CutModelException e){ showErrorDialog(e.getCause()); } } void CutModelMainPanel::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 CutModelMainPanel::addNewViewPanel()throw( CutModelException){ CutModelView* viewpanel = new CutModelView(this,cutmanager->getImageRange()); wxAuiPaneInfo paneinfo0; _wxauimanager->AddPane(viewpanel, paneinfo0.DefaultPane().DestroyOnClose().Centre()); viewpanel->setId(_panelid); viewpanels.push_back(viewpanel); return viewpanel->getId(); } CutModelView* CutModelMainPanel::getModelView(int id)throw( CutModelException){ 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 CutModelException(s); } return current; } void CutModelMainPanel::onUndo(){ try{ checkInvariant(); int result = cutmanager->Undo(); }catch(CutModelException e){ showErrorDialog(e.getCause()); } } void CutModelMainPanel::onRedo(){ try{ checkInvariant(); int result = cutmanager->Redo(); }catch(CutModelException e){ showErrorDialog(e.getCause()); } } void CutModelMainPanel::changeOpacity(int id,int opacity){ try{ checkInvariant(); cutmanager->changeOpacity(id, opacity); }catch(CutModelException e){ showErrorDialog(e.getCause()); } } void CutModelMainPanel::ShowViewBox(int id,bool check){ try{ checkInvariant(); cutmanager->ShowViewBox(id, check); }catch(CutModelException e){ showErrorDialog(e.getCause()); } } void CutModelMainPanel::ShowPopUpMenu(int id){ showErrorDialog("test"); } void CutModelMainPanel::changeColor(int id,double r,double g,double b){ try{ checkInvariant(); cutmanager->changeColor(id, r, g, b); }catch(CutModelException e){ showErrorDialog(e.getCause()); } } void CutModelMainPanel::ChangeShape(int id,int selection){ try{ checkInvariant(); cutmanager->ChangeShape(id, selection); }catch(CutModelException e){ showErrorDialog(e.getCause()); } } void CutModelMainPanel::updateActorDirection(int id){ try{ checkInvariant(); cutmanager->updateActorDirection(id); }catch(CutModelException e){ showErrorDialog(e.getCause()); } } void CutModelMainPanel::ExecuteCut(int id, double* range, bool isinside){ try{ checkInvariant(); cutmanager->ExecuteCut(id, range, isinside); }catch(CutModelException e){ showErrorDialog(e.getCause()); } } void CutModelMainPanel::ExecuteAll(){ for(int i = 0; i < viewpanels.size();i++){ viewpanels[i]->ExecuteCut(); } } vtkImageData* CutModelMainPanel::GetResultImage(){ try{ checkInvariant(); return cutmanager->GetResultImage(); }catch(CutModelException e){ showErrorDialog(e.getCause()); } return NULL; } void CutModelMainPanel::ShowStatistics(int id){ checkInvariant(); HistogramDialog *histo = new HistogramDialog(this, _T("Statistics")); histo->initializeHistogram(cutmanager->GetResultImage()); histo->ShowModal(); delete histo; } void CutModelMainPanel::SaveCutModelData(std::string filename){ cutmanager->SaveCutModelData(filename); } void CutModelMainPanel::LoadCutModelData(std::string filename){ cutmanager->LoadCutModelData(filename); } /** ** **/ ToolBarCutModel::ToolBarCutModel(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 ToolBarEventHandlerCutModel(); this->SetEventHandler(_evthand); } ToolBarCutModel::~ToolBarCutModel(void){ } ToolBarEventHandlerCutModel::ToolBarEventHandlerCutModel() : wxEvtHandler(){ } ToolBarEventHandlerCutModel::~ToolBarEventHandlerCutModel(){ } void ToolBarEventHandlerCutModel::onAdd(wxCommandEvent& event){ CutModelMainPanel::getInstance()->onAddCutModel(); } void ToolBarEventHandlerCutModel::onUndo(wxCommandEvent& event){ CutModelMainPanel::getInstance()->onUndo(); } void ToolBarEventHandlerCutModel::onRedo(wxCommandEvent& event){ CutModelMainPanel::getInstance()->onRedo(); } void ToolBarEventHandlerCutModel::onExecuteAll(wxCommandEvent& event){ CutModelMainPanel::getInstance()->ExecuteAll(); } BEGIN_EVENT_TABLE(ToolBarEventHandlerCutModel, wxEvtHandler) EVT_MENU(10, ToolBarEventHandlerCutModel::onAdd) EVT_MENU(20, ToolBarEventHandlerCutModel::onUndo) EVT_MENU(30, ToolBarEventHandlerCutModel::onRedo) EVT_MENU(40, ToolBarEventHandlerCutModel::onExecuteAll) END_EVENT_TABLE()