]> Creatis software - creaMaracasVisu.git/blobdiff - lib/maracasVisuLib/src/interface/wxWindows/widgets/wxMaracasIRMView.cxx
no newline at end of file
[creaMaracasVisu.git] / lib / maracasVisuLib / src / interface / wxWindows / widgets / wxMaracasIRMView.cxx
index 01f52a75873a6559f839ef3cb39e71e80b964823..f0d135c07ad67331b497bc839146ef74e9f64251 100644 (file)
@@ -3,8 +3,8 @@
   Program:   wxMaracas
   Module:    $RCSfile: wxMaracasIRMView.cxx,v $
   Language:  C++
-  Date:      $Date: 2009/04/01 16:16:59 $
-  Version:   $Revision: 1.1 $
+  Date:      $Date: 2009/06/16 13:25:58 $
+  Version:   $Revision: 1.11 $
 
   Copyright: (c) 2002, 2003
   License:
 =========================================================================*/
 
 
+
 // EOF - wxMaracasMPR.cxx
 
 #include "wxMaracasIRMView.h"
+//#include "wxMaracasIRMViewPanel.h"
+#include "wxMaracasIRMViewProp3DMHD.h"
+#include "wxMaracasIRMViewProp3D.h"
+
+#include <wx/colordlg.h>
+#include <wx/bmpbuttn.h>
+
+#include <OpenImage.xpm>
+#include <Color.xpm>
 
 wxMaracasIRMView* wxMaracasIRMView::instance=NULL;
 
-wxMaracasIRMView::wxMaracasIRMView( wxWindow* parent
+wxMaracasIRMView::wxMaracasIRMView( wxWindow* parent,std::string path)
 : wxPanel(parent, -1, wxDefaultPosition, wxDefaultSize){
 
-       //createControls();
-       irmmanager = new wxMaracasIRMViewManager();             
+       irmmanager = new wxMaracasIRMViewManager();
+
+       wxauimanager = new wxAuiManager(this);
 
-       wxauimanager = new wxAuiManager(this);          
+       _path = path;
 
-       std::string iconsdir = "/";//defaultdir;
-       iconsdir+= "/Icons";
-       wxToolBar* toolbar = new ToolBar(this,iconsdir);
-       wxAuiPaneInfo paneinfo; 
-       wxauimanager->AddPane(toolbar,paneinfo.ToolbarPane().Top());                    
+       std::string iconsdir = path;
+       iconsdir+="/data/Icons";
+       this->_toolb = new ToolBar(this,iconsdir);
+       wxAuiPaneInfo paneinfo;
+       wxauimanager->AddPane(_toolb,paneinfo.ToolbarPane().Top());
 
        wxauimanager->Update();
        createFileChooser();
 
+
 }
 wxMaracasIRMView::~wxMaracasIRMView( ){
 
+       delete _toolb;
 
 }
 
-void wxMaracasIRMView::loadProp3D(){   
-       
-       wxFileDialog* fildial = new wxFileDialog(this, wxString(_T("Select a STL file")),wxString(_T("")),
-               wxString(_T("")),wxString(_T("*.stl")));
-       if(fildial->ShowModal()==wxID_OK){
-               
-               wxString filename(fildial->GetDirectory() + "/"+fildial->GetFilename() );
-               vtkProp3D* prop3D = irmmanager->getProp3D(filename.c_str());
-               if(prop3D != NULL){
-                       this->addProp3D(prop3D);
-               }
-               
-       }
-       delete fildial;
-       
+std::string wxMaracasIRMView::getPath(){
+       return _path;
 }
 
+
+
 void wxMaracasIRMView::createFileChooser(){
-    
+
 }
 
-wxMaracasIRMView* wxMaracasIRMView::getInstance(wxWindow* parent){
+wxMaracasIRMView* wxMaracasIRMView::getInstance(wxWindow* parent,std::string path){
        if(instance==NULL){
-               instance = new wxMaracasIRMView(parent);
+               instance = new wxMaracasIRMView(parent,path);
        }
        return instance;
 }
@@ -81,105 +83,186 @@ void wxMaracasIRMView::setRenderer(vtkRenderer*  renderer){
        irmmanager->setRenderer(renderer);
 }
 
+void wxMaracasIRMView::addRemoveActor(int propid, bool addremove){
+       irmmanager->addRemoveActor(propid, addremove);
+}
+
 void wxMaracasIRMView::changeOpacity(int _propid, int value){
        irmmanager->changeOpacity(_propid,value);
 }
 
-void wxMaracasIRMView::changeIsoValue(int _propid, int value){
-
+void wxMaracasIRMView::changeIsoValue(int propid, double value){
+       irmmanager->changeIsoValue(propid, value);
 }
 
-void wxMaracasIRMView::addProp3D(vtkProp3D* prop3D){
-       int id = irmmanager->addProp3D(prop3D);
-       if(id!=-1){
-               wxMaracasIRMViewProp3D* controlpan = new wxMaracasIRMViewProp3D(this, id);
-               wxAuiPaneInfo paneinfo; 
-               wxauimanager->AddPane(controlpan);              
-               
+void wxMaracasIRMView::changeColor(int propid, double red, double green, double blue){
+       try{
+               irmmanager->changeColor(propid, red, green, blue);
+
+       }catch(char* str){
+
+               wxString s( str,wxConvUTF8 );
+               wxMessageDialog* diag = new wxMessageDialog(this, s, s, wxICON_ERROR);
+               diag->ShowModal();
+               delete diag;
+
        }
-       
 }
 
-/**
-**     Implementation of viewProp3D
-**/
+void wxMaracasIRMView::onLoadImageFile(){
+
+       wxString mhd(_T("mhd"));
+       wxString stl(_T("stl"));
+
+       wxFileDialog* fildial = new wxFileDialog(this, wxString(_T("Select a STL file")),wxString(_T("")),
+               wxString(_T("")),wxString(_T("STL files (*.stl)|*.stl|MHD files (*.mhd)|*.mhd")) );
+
+       if(fildial->ShowModal()==wxID_OK){
+        wxString filename = fildial->GetFilename();
+               wxString pathfile(fildial->GetDirectory() + _T("/") + filename);
+
+
+               if(filename.EndsWith(mhd)){
+                       loadPropMHD(pathfile,filename);
+               }else if(filename.EndsWith(stl)){
+            loadProp3D(pathfile,filename);
+               }
+       }
+       delete fildial;
 
-wxMaracasIRMViewProp3D::wxMaracasIRMViewProp3D(wxWindow* parent,int propid)
-:wxMaracasIRMViewPanel(parent){
-       createControls();
-       this->_propid = propid;
 }
+void wxMaracasIRMView::loadPropMHD(wxString filename, wxString dataname){
+
+       std::string s = std::string(filename.mb_str());
+       vtkImageData* img = irmmanager->getImageData(s);
+       if(img!=NULL){
+               s = std::string(dataname.mb_str());
+               addPropMHD(img, s);
+       }
+
+
 
-wxMaracasIRMViewProp3D::~wxMaracasIRMViewProp3D(){
 }
 
-void wxMaracasIRMViewProp3D::createControls(){
+void wxMaracasIRMView::addPropMHD(vtkImageData* imgdata, std::string dataname){
+       try{
+               int id = irmmanager->addPropMHD(imgdata,dataname);
+               if(id!=-1){
 
-       wxString choices[2];
-       choices[0] = "On";
-       choices[1] = "Off";
-       radiob = new  wxRadioBox(this,-1,wxString(_T("Actor")),wxDefaultPosition,wxDefaultSize,2,choices,1,wxRA_SPECIFY_COLS);
-       this->addControl(radiob);
-       Connect(radiob->GetId(), wxEVT_COMMAND_RADIOBOX_SELECTED, (wxObjectEventFunction)&wxMaracasIRMViewProp3D::onRadioBoxChange);    
-               
+                       wxMaracasIRMViewPanel* controlpan = new wxMaracasIRMViewProp3DMHD(this, id);
+                       int maxiso = irmmanager->getMaxIsoValue(id);
+                       ((wxMaracasIRMViewProp3DMHD*)controlpan)->createControls(maxiso);
+                       addIRMViewPanel(controlpan, dataname);
+               }
 
+       }catch(char* str){
 
-       opacity = new wxSlider(this, -1,0,0,100);
-       this->addControl(opacity);
-       Connect(opacity->GetId(), wxEVT_SCROLL_CHANGED, (wxObjectEventFunction)&wxMaracasIRMViewProp3D::onOpacityRelease);      
+               std::cout << "Exception : " << str << '\n';
+               wxMessageDialog* diag = new wxMessageDialog(this, wxString( str,wxConvUTF8 ), wxString( str,wxConvUTF8 ), wxICON_ERROR);
+               diag->ShowModal();
 
-       isovalue = new wxSlider(this, -1,0,0,100);
-       this->addControl(isovalue);
-       Connect(isovalue->GetId(), wxEVT_SCROLL_CHANGED, (wxObjectEventFunction)&wxMaracasIRMViewProp3D::onIsoValueRelease);    
+       }
 }
-void wxMaracasIRMViewProp3D::onRadioBoxChange(wxCommandEvent& event){
+
+void wxMaracasIRMView::loadProp3D(wxString filename, wxString dataname){
+       std::string s = std::string(filename.mb_str());
+       vtkProp3D* prop3D = irmmanager->getProp3D(s);
+       if(prop3D != NULL){
+               s = std::string(dataname.mb_str() );
+               this->addProp3D(prop3D,s);
+       }else{
+               //TODO msj to the user indicating error in file
+       }
+
+
 
 }
-void wxMaracasIRMViewProp3D::onActionButtonPressedEliminate( wxCommandEvent& event ){  
+
+void wxMaracasIRMView::addProp3D(vtkProp3D* prop3D, std::string dataname){
+       try{
+               int id = irmmanager->addProp3D(prop3D,dataname);
+               if(id!=-1){
+                       wxMaracasIRMViewPanel* controlpan = new wxMaracasIRMViewProp3D(this, id);
+                       addIRMViewPanel(controlpan, dataname);
+               }
+       }catch(char* str){
+               std::cout << "Exception : " << str << '\n';
+               wxMessageDialog* diag = new wxMessageDialog(this, wxString(str,wxConvUTF8 ), wxString(str,wxConvUTF8 ), wxICON_ERROR);
+               diag->ShowModal();
+       }
 
 }
+void wxMaracasIRMView::addIRMViewPanel(wxMaracasIRMViewPanel* irmview, std::string dataname){
 
-void wxMaracasIRMViewProp3D::onOpacityRelease(wxScrollEvent& event ){
+       wxString s(dataname.c_str(),wxConvUTF8 );
+       wxAuiPaneInfo paneinfo;
+       wxauimanager->AddPane(irmview, paneinfo.DefaultPane().Centre().DestroyOnClose().Caption(s));
+       wxauimanager->Update();
 
-       wxMaracasIRMView::getInstance()->changeOpacity(_propid,opacity->GetValue());
 
 }
 
-void wxMaracasIRMViewProp3D::onIsoValueRelease(wxScrollEvent& event ){
-
-       wxMaracasIRMView::getInstance()->changeIsoValue(_propid,isovalue->GetValue());
+void wxMaracasIRMView::deleteActor(int propid){
+       try{
+               irmmanager->deleteActor(propid);
+       }catch(char* e){
 
+       }
 }
 
 
+
+
+
 /**
 **
 **/
 
 ToolBar::ToolBar(wxWindow * parent,std::string iconsdir)
 : wxToolBar(parent, -1, wxDefaultPosition, wxDefaultSize)
-{    
+{
 
 
        std::string iconfil = iconsdir;
 
-       iconfil+= "/Open.png";
+       //iconfil+= "/OpenImage.png";
+       //wxBitmap* bitmap0 = new wxBitmap(wxString(iconfil.c_str(),wxConvUTF8), wxBITMAP_TYPE_PNG);
+       wxBitmap bitmap0(OpenImage_xpm);
+       this->AddTool(1, wxString(_T("test")),bitmap0);
+
+       /*iconfil+= "/Open.png";
        wxBitmap* bitmap2 = new wxBitmap(wxString(iconfil.c_str(),wxConvUTF8), wxBITMAP_TYPE_PNG);
-       this->AddTool(2, wxString(_T("test")),*bitmap2);                
-       
+       this->AddTool(2, wxString(_T("test")),*bitmap2);        */
+
+       /*iconfil = iconsdir;
+       iconfil+= "/Open.png";
+       wxBitmap* bitmap30 = new wxBitmap(wxString(iconfil.c_str(),wxConvUTF8), wxBITMAP_TYPE_PNG);
+       this->AddTool(30, wxString(_T("test")),*bitmap30);*/
+
        this->Realize();
-       
-       
+
+       _evthand = new ToolBarEventHandler();
+       this->SetEventHandler(_evthand);
+
 }
 
 ToolBar::~ToolBar(void){
 }
 
+ToolBarEventHandler::ToolBarEventHandler()
+: wxEvtHandler(){
+}
+ToolBarEventHandler::~ToolBarEventHandler(){
+}
 
-void ToolBar::onLoadConfig(wxCommandEvent& event){
-       wxMaracasIRMView::getInstance()->loadProp3D();
+void ToolBarEventHandler::onLoadImageFile(wxCommandEvent& event){
+       wxMaracasIRMView::getInstance()->onLoadImageFile();
 }
 
-BEGIN_EVENT_TABLE(ToolBar, wxToolBar)  
-       EVT_MENU(2, ToolBar::onLoadConfig)    
+
+
+BEGIN_EVENT_TABLE(ToolBarEventHandler, wxEvtHandler)
+       EVT_MENU(1, ToolBarEventHandler::onLoadImageFile)
 END_EVENT_TABLE()
+
+