From 55e1200cbdf41538bcac294e3ac42f68ad0c991d Mon Sep 17 00:00:00 2001 From: perez Date: Thu, 19 Nov 2009 16:34:43 +0000 Subject: [PATCH] *** empty log message *** --- .../interface/CutModel2MainPanel.cxx | 378 ++++++++++++++++++ .../CutModule/interface/CutModel2MainPanel.h | 151 +++++++ 2 files changed, 529 insertions(+) create mode 100644 lib/maracasVisuLib/src/CutModule/interface/CutModel2MainPanel.cxx create mode 100644 lib/maracasVisuLib/src/CutModule/interface/CutModel2MainPanel.h diff --git a/lib/maracasVisuLib/src/CutModule/interface/CutModel2MainPanel.cxx b/lib/maracasVisuLib/src/CutModule/interface/CutModel2MainPanel.cxx new file mode 100644 index 0000000..4b0367f --- /dev/null +++ b/lib/maracasVisuLib/src/CutModule/interface/CutModel2MainPanel.cxx @@ -0,0 +1,378 @@ +/*========================================================================= + + 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() + diff --git a/lib/maracasVisuLib/src/CutModule/interface/CutModel2MainPanel.h b/lib/maracasVisuLib/src/CutModule/interface/CutModel2MainPanel.h new file mode 100644 index 0000000..286f686 --- /dev/null +++ b/lib/maracasVisuLib/src/CutModule/interface/CutModel2MainPanel.h @@ -0,0 +1,151 @@ +/*========================================================================= + + Program: wxMaracas + Module: $RCSfile: CutModel2MainPanel.h,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. + +=========================================================================*/ + +#ifndef __CutModel2MainPanelPanelH__ +#define __CutModel2MainPanelPanelH__ + +#include +#include +#include +#include "wx/aui/aui.h" +#include +#include +#include "marTypes.h" + + +#include "CutModel2Manager.h" +#include "CutModel2Exception.h" +#include "CutModel2View.h" + +#include "vtkImageData.h" +#include "vtkRenderWindowInteractor.h" + + +class creaMaracasVisu_EXPORT CutModel2MainPanel : public wxPanel +{ + +public: + + ~CutModel2MainPanel( ); + + static CutModel2MainPanel* getInstance(wxWindow* parent=NULL, std::string path =""); + + //static CutModel2MainPanel* getInstance(); + + void setImageData(vtkImageData* img); + + void setInteractor(vtkRenderWindowInteractor* interactor); + + void setRenderer(vtkRenderer* renderer); + + void initialize(std::string path); + + void onAddCutModel2(); + + void onUndo(); + + void onRedo(); + + void changeOpacity(int id,int opacity); + + void ShowViewBox(int id,bool check); + + void ChangeShape(int id,int selection); + + void changeColor(int id,double r,double g,double b); + + void updateActorDirection(int id); + + void RemoveActor(int id); + + void ExecuteCut(int id, double* range, bool isinside); + + void ExecuteAll(); + + vtkImageData* GetResultImage(); + + void ShowCurrentPanel(int id); + + void ShowPopUpMenu(int id); + + void ShowStatistics(int id); + + +private: + + CutModel2MainPanel( wxWindow* parent, std::string path); + + static CutModel2MainPanel* instance; + + CutModelManager* cutmanager; + + void checkInvariant() throw( CutModelException); + + void showErrorDialog(std::string str); + + void SaveCutModel2Data(std::string filename); + + void LoadCutModel2Data(std::string filename); + + std::vector viewpanels; + + wxAuiManager* _wxauimanager; + + + int addNewViewPanel()throw( CutModel2Exception); + + CutModelView* getModelView(int id)throw( CutModelException); + + int _panelid; +}; + + +class ToolBarEventHandlerCutModel2 : public wxEvtHandler{ + + public: + ToolBarEventHandlerCutModel2(); + ~ToolBarEventHandlerCutModel2(); + + void onAdd(wxCommandEvent& event); + + void onUndo(wxCommandEvent& event); + + void onRedo(wxCommandEvent& event); + + void onExecuteAll(wxCommandEvent& event); + + private: + + DECLARE_EVENT_TABLE() + }; + +class ToolBarCutModel2 : public wxToolBar{ + + +public: + ToolBarCutModel2(wxWindow * parent); + ~ToolBarCutModel2(void); + + +private: + + ToolBarEventHandlerCutModel2* _evthand; + +}; + +#endif + -- 2.46.0