]> Creatis software - bbtkGEditor.git/blobdiff - lib/EditorGraphicBBS/bbsWxGUIEditorGraphic/bbtkwxGUIEditorGraphicBBS.cxx
Fixing last details of the edition dialog new name
[bbtkGEditor.git] / lib / EditorGraphicBBS / bbsWxGUIEditorGraphic / bbtkwxGUIEditorGraphicBBS.cxx
index 05d50997f4e099a3427ae1006042e451ffb14747..77caf4593a5f7a53a3ad334f4c5128d4c580b698 100644 (file)
@@ -1,9 +1,9 @@
 /*=========================================================================                                                                               
-  Program:   bbtk
-  Module:    $RCSfile$
-  Language:  C++
-  Date:      $Date$
-  Version:   $Revision$
+Program:   bbtk
+Module:    $RCSfile$
+Language:  C++
+Date:      $Date$
+Version:   $Revision$
 =========================================================================*/
 
 /* ---------------------------------------------------------------------
 * ------------------------------------------------------------------------ */                                                                         
 
 /**
- *  \file 
- *  \brief Class bbtk::WxInterfaceEditorGraphicBBS . 
- */
-
-
+*  \file 
+*  \brief Class bbtk::WxInterfaceEditorGraphicBBS . 
+*/
 
 #include "bbtkwxGUIEditorGraphicBBS.h"
-#include "bbtkwxGUIEditorGraphicContainer.h"
-
-#include <bbtkWxGUIPackageBrowser2.h>
-
+#include "creaWx.h"
 
 namespace bbtk
 {
 
 
-  //=========================================================================
+       //=========================================================================
        wxGUIEditorGraphicBBS::wxGUIEditorGraphicBBS(wxFrame *parent)
-    : wxFrame(parent, -1, _T("bbEditor"),wxDefaultPosition, wxSize(1200,800))
-  {
-         m_mgr.SetManagedWindow(this);
-         editorgraphiccontainer = new wxGUIEditorGraphicContainer(this);
-         
-         wxPanel *mWxGUIGrapphicEditorPanel = new wxPanel(this,-1);
-         wxPanel *mWxGUIBoxBrowserPanel = new wxPanel(this,-1);
-         wxPanel *mWxGUIConfigurationGraphicEditorPanel = new wxPanel(this,-1);
-         
-         mWxGUIGrapphicEditorPanel->SetBackgroundColour( wxColor(255,0,0) );
-         mWxGUIBoxBrowserPanel->SetBackgroundColour( wxColor(0,255,0) );
-         mWxGUIConfigurationGraphicEditorPanel->SetBackgroundColour( wxColor(255,0,255) );
-         
-         //
-         m_mgr.AddPane(mWxGUIGrapphicEditorPanel,
-                                       wxAuiPaneInfo().Name(wxT("graphic_editor_content"))
-                                       .Caption(wxT("Graphic editor"))
-                                       .MinimizeButton(true)
-                                       .MaximizeButton(true)
-                                       .Center()
-                                       .MinSize(wxSize(100,100))
-                                       );   
-         
-         m_mgr.AddPane(mWxGUIBoxBrowserPanel,
-                                       wxAuiPaneInfo().Name(wxT("box_browser_content"))
-                                       .Caption(wxT("Box browser"))
-                                       .MinimizeButton(true)
-                                       .MaximizeButton(true)
-                                       .Right()
-                                       .Layer(2)
-                                       .MinSize(wxSize(400,100))
-                                       );
-         
-         m_mgr.AddPane(mWxGUIConfigurationGraphicEditorPanel,
-                                       wxAuiPaneInfo().Name(wxT("configuration_graphic_editor_content"))
-                                       .Caption(wxT("Messages"))
-                                       .MinimizeButton(true)
-                                       .MaximizeButton(true)
-                                       .Bottom()
-                                       .MinSize(wxSize(100,100))
-                                       );
-         
-         SetAutoLayout(true);
-         Layout();
-         m_mgr.Update();
-
-               WxGUIPackageBrowser2 *bb= new WxGUIPackageBrowser2(this);
+               : wxFrame(parent, -1, _T("bbtkGEditor"),wxDefaultPosition, wxSize(1200,800))
+       {
+               _frameAUIMgr = new wxAuiManager(this);
+               
+
+               //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 */
+                  datadir=datadir+"/../share/creaContours";
+           #endif // MACOSX    
        
-  }
+               #ifdef MACOSX /* assume this is OSX */
+                       datadir=datadir+"/../../../../share/creaContours";
+               #endif // MACOSX        
+
+               _dataDir = datadir;
+
+               initMenu();
+               initToolbar();
+               initTabPanelsManager();
+               initPackageBrowser();
+               initHelpHTMLBrowser();
+
+               CreateStatusBar();
+               _frameAUIMgr->Update();
+               _actualPkgBrowserBoxName="";
+               _actualPkgBrowserPkgName="";
+       }
+
+
+       //=========================================================================
+       wxGUIEditorGraphicBBS::~wxGUIEditorGraphicBBS()
+       {
+               _frameAUIMgr->UnInit();
+       }
+
+       //=========================================================================
+       void wxGUIEditorGraphicBBS::initToolbar()
+       {       
+               //std::string filename= _dataDir + "/data/icons/wxart_new.xpm";   
+               wxBitmap bmp_new(new_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->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));
+
+       }
+       //=========================================================================
+       void wxGUIEditorGraphicBBS::initHelpHTMLBrowser()
+       {
+               //TO FIX THE PATH OF BBTK BIN  IN ORDER TO USE REGENERATE EXECUTABLES
+               //RegenerateAll();
+               _helpHtmlBrowser = new WxGUIHtmlBrowser(this,wxSize(200,0));
+               _frameAUIMgr->AddPane(_helpHtmlBrowser,wxAuiPaneInfo().Right().MinSize(200,200));       
+       }
+
+       //=========================================================================
+       void wxGUIEditorGraphicBBS::initMenu()
+       {
+               // create a menu bar
+               wxMenu *fileMenu = new wxMenu;
+
+               // the "About" item should be in the help menu
+               wxMenu *helpMenu = new wxMenu;
+               helpMenu->Append(wxID_ABOUT, _T("&About..."), _T("About"));
+               fileMenu->Append(wxID_EXIT, _T("E&xit"), _T("Exit"));
+
+               Connect(wxID_EXIT,wxEVT_COMMAND_MENU_SELECTED,wxCommandEventHandler(wxGUIEditorGraphicBBS::OnExit));
+
+               // now append the freshly created menu to the menu bar...
+               wxMenuBar *menuBar = new wxMenuBar();
+               menuBar->Append(fileMenu, _T("&File"));
+               menuBar->Append(helpMenu, _T("&Help"));
+
+               // attach this menu bar to the frame
+               SetMenuBar(menuBar);
+       }
+
+       //=========================================================================
+       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);
+               _tabsMgr = new wxTabPanelsManager(this);
+               _frameAUIMgr->AddPane(_notebook,wxAuiPaneInfo().CenterPane());  
+
+       }
+       
+       //=========================================================================
+       void wxGUIEditorGraphicBBS::initPackageBrowser()
+       {
+               _pkgBrowser = new WxGUIPackageBrowser2(this);
+               _pkgBrowser->IncludeAll();
+               _frameAUIMgr->AddPane(_pkgBrowser,wxAuiPaneInfo().Left().MinSize(200,200).CloseButton(false));          
+       }
+
+       //================================================================
+
+       void wxGUIEditorGraphicBBS::DoRegeneratePackageDoc( const std::string& pack )
+       {
+               std::string mess("Regenerating doc for package '");
+               if (pack!="-a"){
+                       mess += pack + "'";
+               }
+               else
+               {
+                       mess = "Regenerating doc for all packages";
+               }
+               
+               mess += " ... please wait";             
+
+               SetStatusText( std2wx(mess) );
+
+               //BBTK_BUSY_CURSOR;
+
+               std::string command;
+               #if defined(WIN32)
+                       command = "\"";
+               #endif
+                       command += ConfigurationFile::GetInstance().Get_bin_path();
+                       command += ConfigurationFile::GetInstance().Get_file_separator();
+                       command += "bbRegeneratePackageDoc";
+               #if defined(WIN32)
+                       command += "\"";
+               #endif
+
+               command += " " + pack + " -q";
+           bbtkMessage("debug",1,"Executing system command '"<<command<<"'"<<std::endl);
+
+               if ( ! system ( command.c_str() ) )
+               {
+                       SetStatusText( _T("Done !"));
+                       /*
+                       wxMessageBox(_T("Done !"),_T("Regenerate package '")
+                                        +std2wx(pack)+_T("' doc"),
+                                        wxOK | wxICON_INFORMATION);
+                       */
+               }
+               else 
+               {
+                       SetStatusText( _T("Done !"));
+                       wxString err(_T("An error occured while running '"));
+                       err +=  bbtk::std2wx(command) + _T("'");
+                       wxMessageBox(err,_T("Regenerate package doc"),wxOK | wxICON_ERROR);      
+           }
+       }
+
+       //================================================================
+       void wxGUIEditorGraphicBBS::DoRegenerateBoxesLists()
+       {
+               SetStatusText( _T("Regenerating boxes lists ... please wait") );
+               //BBTK_BUSY_CURSOR ;
+
+               std::string command;
+               #if defined(WIN32)
+                       command = "\"";
+               #endif
+                       command += ConfigurationFile::GetInstance().Get_bin_path();
+                       command += ConfigurationFile::GetInstance().Get_file_separator();
+                       command += "bbRegenerateBoxesLists";
+
+               #if defined(WIN32)
+                       command += "\"";
+               #endif
+                       command += " -q";
+
+               bbtkMessage("debug",1,"Executing system command '"<<command<<"'"<<std::endl);
+
+               if ( ! system ( command.c_str() ) )
+               {
+                       SetStatusText( _T("Done !"));
+                       /*
+                       wxMessageBox(_T("Done !"),_T("Regenerate boxes lists"),
+                                        wxOK | wxICON_INFORMATION);
+                       */
+               }
+               else 
+               {
+                       SetStatusText( _T("Done !"));
+                       wxString err(_T("An error occured while running '"));
+                       err +=  bbtk::std2wx(command) + _T("'");
+                       wxMessageBox(err,_T("Regenerate boxes lists"),wxOK | wxICON_ERROR);      
+               }
+       }
+       
+  //================================================================
+       void wxGUIEditorGraphicBBS::RegenerateAll()
+       {
+               DoRegeneratePackageDoc("-a");   
+               DoRegenerateBoxesLists();
+       }
+
+       //================================================================
+
+       wxAuiNotebook* wxGUIEditorGraphicBBS::getAuiNotebook()
+       {
+               return _notebook;
+       }
+
+       //================================================================
+
+       void wxGUIEditorGraphicBBS::displayBlackBoxInfo(std::string packageName, std::string boxName)
+       {
+               if(_actualPkgBrowserPkgName != packageName || _actualPkgBrowserBoxName != boxName )
+               {
+                       _actualPkgBrowserPkgName = packageName;
+                       _actualPkgBrowserBoxName = boxName;
+
+                       BlackBoxDescriptor::Pointer descriptor = GObjectsMVCFactory::getInstance()->getBlackBoxDescriptor(packageName, boxName);
+                       _pkgBrowser->WxGUIBlackBoxListUserOnSelected(descriptor.get());
+               }
+       }
+
+       //=========================================================================
+
+       void wxGUIEditorGraphicBBS::editBlackBox(GBlackBoxModel *bbmodel)
+       {
+               wxBlackBoxEditionDialog* dialog = new wxBlackBoxEditionDialog(this,bbmodel);
+               dialog->Show();
+       }
+
+       //=========================================================================
+
+       void wxGUIEditorGraphicBBS::editDiagramParameters(wxVtkSceneManager* scene)
+       {
+               wxBlackBoxEditionDialog* dialog = new wxBlackBoxEditionDialog(this,scene);
+               dialog->Show();
+       }
+
+       //=========================================================================
+
+       void wxGUIEditorGraphicBBS::updateStatusBar(std::string textStatus)
+       {
+               SetStatusText(crea::std2wx(textStatus));
+       }
+
+       //=========================================================================
+
+       void wxGUIEditorGraphicBBS::executeActualDiagram()
+       {
+               std::string script = _tabsMgr->getActualDiagramScript();
+               cout<<"RaC wxGUIEditorGraphicBBS::executeActualDiagram SCRIPT"<<endl;
+               cout<<script<<endl;
+
+
+               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";
+               
+               ofstream tempFile;
+               tempFile.open(filename.c_str());
+               tempFile << script;
+               tempFile.close();
+               
+               std::string command = "\"";
+
+               #ifdef WIN32
+                       command += "\"";
+               #endif
+
+               //command += ConfigurationFile::GetInstance().Get_bin_path();
+               command +="C:/RaC/CREATIS/bbtkBIN/RelWithDebInfo//";
+
+               #ifdef MACOSX
+                       command += separator + "bbi.app/Contents/MacOS/bbi\" ";
+               #else 
+                       command += separator + "bbi\" ";
+               #endif
+               command += "\""+filename + "\"";
+
+               #ifdef WIN32
+                       command += "\"";
+               #endif
+
+               command += " & ";
+                 
+               printf ("RaC wxGUIEditorGraphicBBS::executeActualDiagram %s \n" , command.c_str() );
+               system( command.c_str() );
+       }
+
+       //=========================================================================
+
+       /*****************************************************
+       /* HANDLERS 
+       /*****************************************************/
+
+       void wxGUIEditorGraphicBBS::OnToolLeftClick(wxCommandEvent& event)
+       {
+               switch (event.GetId())
+               {
+                       case 1000 :
+                               _tabsMgr->addNewTab();
+                       break;  
 
-  //=========================================================================
-  wxGUIEditorGraphicBBS::~wxGUIEditorGraphicBBS()
-  {
-         delete editorgraphiccontainer;
-         m_mgr.UnInit();
-  }
-  //=========================================================================
+                       case 1001 :
+                               executeActualDiagram();
+                       break;  
+               }
+       }
 
+       void wxGUIEditorGraphicBBS::OnExit(wxCommandEvent& event)
+       {
+               Close(true);
+       }
 
 
 }  // EO namespace bbtk