]> Creatis software - bbtkGEditor.git/blobdiff - lib/EditorGraphicBBS/bbsWxGUIEditorGraphic/bbtkwxGUIEditorGraphicBBS.cxx
Changed from GConnectorView to vtkGConnectorView ... The historique will be lost...
[bbtkGEditor.git] / lib / EditorGraphicBBS / bbsWxGUIEditorGraphic / bbtkwxGUIEditorGraphicBBS.cxx
index 9c63350ffa8a46baedc00a0693f337a46ef478ca..35c4e77cf7c07ad4bb18da7296232982a9863815 100644 (file)
@@ -34,6 +34,7 @@ Version:   $Revision$
 */
 
 #include "bbtkwxGUIEditorGraphicBBS.h"
+#include "creaWx.h"
 
 namespace bbtk
 {
@@ -46,28 +47,27 @@ namespace bbtk
                _frameAUIMgr = new wxAuiManager(this);
                
 
-               //std::string datadir( crea::System::GetExecutablePath() );
+               /*std::string datadir( crea::System::GetExecutablePath() );
                std::string datadir (".");
                cout<<"RaC //------------------"<<endl;
                cout<<"RaC //TODO wxGUIEditorGraphicBBS constructor.Initialize datadir with  crea::System::GetExecutablePath() ."<<endl;
                cout<<"RaC //------------------"<<endl;
 
-           #ifdef LINUX /* assume this is OSX */
+           #ifdef LINUX // assume this is OSX 
                   datadir=datadir+"/../share/creaContours";
            #endif // MACOSX    
        
-               #ifdef MACOSX /* assume this is OSX */
+               #ifdef MACOSX // assume this is OSX 
                        datadir=datadir+"/../../../../share/creaContours";
                #endif // MACOSX        
 
-               _dataDir = datadir;
+               _dataDir = datadir;*/
 
                initMenu();
                initToolbar();
                initTabPanelsManager();
                initPackageBrowser();
                initHelpHTMLBrowser();
-               initPropertiesPanel();
 
                CreateStatusBar();
                _frameAUIMgr->Update();
@@ -84,23 +84,36 @@ namespace bbtk
 
        //=========================================================================
        void wxGUIEditorGraphicBBS::initToolbar()
-       {       
-               //std::string filename= _dataDir + "/data/icons/wxart_new.xpm";   
+       {        
                wxBitmap bmp_new(new_xpm);
+               wxBitmap bmp_open(open_xpm);
+               wxBitmap bmp_save(save_xpm);
+               wxBitmap bmp_run(run_xpm);
+               wxBitmap bmp_delete(delete_xpm);
+               wxBitmap bmp_centerview(centerview_xpm);
 
                wxToolBar  *_toolbar = new wxToolBar(this, wxID_ANY);
 
                //Adds a tool btn to the toolbar
-               _toolbar->AddTool(1000,_T("New"),bmp_new, wxNullBitmap, wxITEM_NORMAL,_T("New tab"), _T("Create a new panel tab"));
-               _toolbar->AddTool(1001,_T("Execute"),bmp_new, wxNullBitmap, wxITEM_NORMAL,_T("Execute actual diagram"), _T("Execute actual diagram"));
+               _toolbar->AddTool(ID_NEW,_T("New"),bmp_new, wxNullBitmap, wxITEM_NORMAL,_T("New tab"), _T("Create a new panel tab"));
+               _toolbar->AddTool(ID_OPEN,_T("Open diagram"),bmp_open, wxNullBitmap, wxITEM_NORMAL,_T("Open a diagram"), _T("Open a diagram"));
+               _toolbar->AddTool(ID_SAVE,_T("Save diagram"),bmp_save, wxNullBitmap, wxITEM_NORMAL,_T("Saves actual diagram"), _T("Saves actual diagram"));
+               _toolbar->AddTool(ID_RUN,_T("Run"),bmp_run, wxNullBitmap, wxITEM_NORMAL,_T("Execute actual diagram"), _T("Execute actual diagram"));
+               _toolbar->AddTool(ID_DELETEALL,_T("Delete all"),bmp_delete, wxNullBitmap, wxITEM_NORMAL,_T("Delete all boxes"), _T("Delete all boxes"));
+               _toolbar->AddTool(ID_CENTERVIEW,_T("Center view"),bmp_centerview, wxNullBitmap, wxITEM_NORMAL,_T("Center view"), _T("Center view"));
+               
 
                _toolbar->SetMargins( 2, 2 );
                _toolbar->Realize();
                SetToolBar(_toolbar);
 
                // connect command event handlers
-               Connect(1000,wxEVT_COMMAND_TOOL_CLICKED,wxCommandEventHandler(wxGUIEditorGraphicBBS::OnToolLeftClick));
-               Connect(1001,wxEVT_COMMAND_TOOL_CLICKED,wxCommandEventHandler(wxGUIEditorGraphicBBS::OnToolLeftClick));
+               Connect(ID_NEW,wxEVT_COMMAND_TOOL_CLICKED,wxCommandEventHandler(wxGUIEditorGraphicBBS::OnCreateNewTab));
+               Connect(ID_OPEN,wxEVT_COMMAND_TOOL_CLICKED,wxCommandEventHandler(wxGUIEditorGraphicBBS::OnOpenDiagram));
+               Connect(ID_SAVE,wxEVT_COMMAND_TOOL_CLICKED,wxCommandEventHandler(wxGUIEditorGraphicBBS::OnSaveActualDiagram));
+               Connect(ID_RUN,wxEVT_COMMAND_TOOL_CLICKED,wxCommandEventHandler(wxGUIEditorGraphicBBS::OnExecuteActualDiagram));
+               Connect(ID_DELETEALL,wxEVT_COMMAND_TOOL_CLICKED,wxCommandEventHandler(wxGUIEditorGraphicBBS::OnDeleteAllBoxesActualDiagram));
+               Connect(ID_CENTERVIEW,wxEVT_COMMAND_TOOL_CLICKED,wxCommandEventHandler(wxGUIEditorGraphicBBS::OnCenterViewActualDiagram));
 
        }
        //=========================================================================
@@ -137,7 +150,7 @@ namespace bbtk
        //=========================================================================
        void wxGUIEditorGraphicBBS::initTabPanelsManager()
        {
-               _notebook = new wxAuiNotebook(this,wxID_ANY,wxDefaultPosition,wxDefaultSize,wxAUI_NB_TOP|wxAUI_NB_TAB_MOVE|wxAUI_NB_CLOSE_ON_ACTIVE_TAB|wxAUI_NB_TAB_FIXED_WIDTH|wxAUI_NB_WINDOWLIST_BUTTON);
+               _notebook = new wxAuiNotebook(this,wxID_NOTEBOOK,wxDefaultPosition,wxDefaultSize,wxAUI_NB_TOP|wxAUI_NB_TAB_MOVE|wxAUI_NB_CLOSE_ON_ACTIVE_TAB|wxAUI_NB_TAB_FIXED_WIDTH|wxAUI_NB_WINDOWLIST_BUTTON);
                _tabsMgr = new wxTabPanelsManager(this);
                _frameAUIMgr->AddPane(_notebook,wxAuiPaneInfo().CenterPane());  
 
@@ -153,14 +166,6 @@ namespace bbtk
 
        //================================================================
 
-       void wxGUIEditorGraphicBBS::initPropertiesPanel()
-       {
-               _propertiesPanel = new wxPropertiesPanel(this);
-               _frameAUIMgr->AddPane(_propertiesPanel,wxAuiPaneInfo().Right().MinSize(200,200).CloseButton(false).Floatable(false));
-       }
-
-       //================================================================
-
        void wxGUIEditorGraphicBBS::DoRegeneratePackageDoc( const std::string& pack )
        {
                std::string mess("Regenerating doc for package '");
@@ -278,20 +283,31 @@ namespace bbtk
 
        //=========================================================================
 
-       void wxGUIEditorGraphicBBS::updateStatusBar(std::string textStatus)
+       void wxGUIEditorGraphicBBS::editBlackBox(GBlackBoxModel *bbmodel)
        {
-               SetStatusText(_T(textStatus));
+               wxBlackBoxEditionDialog* dialog = new wxBlackBoxEditionDialog(this,bbmodel);
+               dialog->Show();
        }
 
        //=========================================================================
 
-       void wxGUIEditorGraphicBBS::executeActualDiagram()
+       void wxGUIEditorGraphicBBS::editDiagramParameters(wxVtkSceneManager* scene)
        {
-               std::string script = _tabsMgr->getActualDiagramScript();
-               cout<<"RaC wxGUIEditorGraphicBBS::executeActualDiagram SCRIPT"<<endl;
-               cout<<script<<endl;
+               wxBlackBoxEditionDialog* dialog = new wxBlackBoxEditionDialog(this,scene);
+               dialog->Show();
+       }
+
+       //=========================================================================
+
+       void wxGUIEditorGraphicBBS::updateStatusBar(std::string textStatus)
+       {
+               SetStatusText(crea::std2wx(textStatus));
+       }
 
+       //=========================================================================
 
+       void wxGUIEditorGraphicBBS::executeScript(std::string script)
+       {
                std::string separator = ConfigurationFile::GetInstance().Get_file_separator ();
                std::string dir = ConfigurationFile::GetInstance().Get_default_temp_dir();
                std::string filename = dir + separator + "tmp_bbtk.bbs";
@@ -308,7 +324,7 @@ namespace bbtk
                #endif
 
                //command += ConfigurationFile::GetInstance().Get_bin_path();
-               command +="C:/RaC/CREATIS/bbtkBIN/RelWithDebInfo//";
+               command +="C:/temp/bbtkBIN/RelWithDebInfo//";
 
                #ifdef MACOSX
                        command += separator + "bbi.app/Contents/MacOS/bbi\" ";
@@ -323,35 +339,112 @@ namespace bbtk
 
                command += " & ";
                  
-               printf ("RaC wxGUIEditorGraphicBBS::executeActualDiagram %s \n" , command.c_str() );
+               printf ("RaC wxGUIEditorGraphicBBS::executeScript %s \n" , command.c_str() );
                system( command.c_str() );
        }
 
        //=========================================================================
+       // EVENT HANDLERS 
+       //=========================================================================
+
+       void wxGUIEditorGraphicBBS::OnCreateNewTab(wxCommandEvent& event)
+       {
+               _tabsMgr->addNewTab();          
+       }
+
+       //=========================================================================
+
+       void wxGUIEditorGraphicBBS::OnExecuteActualDiagram(wxCommandEvent& event)
+       {
+               std::string script = _tabsMgr->getActualDiagramScript();
+               cout<<"RaC wxGUIEditorGraphicBBS::executeActualDiagram SCRIPT"<<endl;
+               cout<<script<<endl;
 
-       /*****************************************************
+               executeScript(script);          
+       }
+
+       //=========================================================================
+
+       /*****************************************************/
        /* HANDLERS 
        /*****************************************************/
+       void wxGUIEditorGraphicBBS::OnSaveActualDiagram(wxCommandEvent& event)
+       {
+               wxFileDialog * saveFileDialog = new wxFileDialog(this,wxT("Save  actual diagram"),wxEmptyString,"NewDiagram","*.bbd",wxSAVE|wxOVERWRITE_PROMPT);
+               if (saveFileDialog->ShowModal() == wxID_OK)
+               {
+                       wxString fileName = saveFileDialog->GetPath();
+                       
+                       ofstream file;
+                       file.open(fileName.c_str());
+
+                       std::string content="";
+                       
+                       // writing file header
+                       content += "# ----------------------------------\n";
+                       content += "# - BBTKGEditor v 1.0 BBD BlackBox Diagram file\n";
+                       content += "# - ";
+                       content += fileName;
+                       content += "\n";
+                       content += "# ----------------------------------\n";
+                       content += "\n";
+                       content += "APP_START\n";
+                       _tabsMgr->saveActualDiagram(content);           
+                       content += "APP_END\n";
+                       file << content;
+                       file.close();
+               }
 
-       void wxGUIEditorGraphicBBS::OnToolLeftClick(wxCommandEvent& event)
+       }
+
+       //=========================================================================
+
+       void wxGUIEditorGraphicBBS::OnDeleteAllBoxesActualDiagram(wxCommandEvent& event)
        {
-               switch (event.GetId())
+               wxMessageDialog *dial = new wxMessageDialog(NULL, wxT("Are you sure to delete all boxes of the diagram?"), wxT("Delete all boxes"), wxYES_NO | wxNO_DEFAULT | wxICON_QUESTION);
+               if(dial->ShowModal() == wxID_YES)
                {
-                       case 1000 :
-                               _tabsMgr->addNewTab();
-                       break;  
+                       _tabsMgr->deleteAllBoxesActualDiagram();
+               }
+       }
+
+       //=========================================================================
+
+       void wxGUIEditorGraphicBBS::OnCenterViewActualDiagram(wxCommandEvent& event)
+       {
+               _tabsMgr->centerViewActualDiagram();
+       }
+
+       //=========================================================================
+
+       
+       void wxGUIEditorGraphicBBS::OnOpenDiagram(wxCommandEvent& event)
+       {
+               wxFileDialog * openFileDialog = new wxFileDialog(this,wxT("Open diagram"),wxEmptyString,"","*.bbd",wxOPEN|wxFILE_MUST_EXIST);
+               if (openFileDialog->ShowModal() == wxID_OK)
+               {
+                       wxString fileName = openFileDialog->GetPath();
+                       
+                       ifstream inputStream;
+                       inputStream.open(fileName.c_str());
+
+                       _tabsMgr->addNewTab();
+                       _tabsMgr->loadDiagram(inputStream);
+                       
+                       inputStream.close();
+                       
 
-                       case 1001 :
-                               executeActualDiagram();
-                       break;  
                }
        }
 
+       //=========================================================================
+
        void wxGUIEditorGraphicBBS::OnExit(wxCommandEvent& event)
        {
                Close(true);
        }
 
+       //=========================================================================
 
 }  // EO namespace bbtk