bbtkWxGUIScriptingInterface.cxx

Go to the documentation of this file.
00001 /*=========================================================================                                                                               
00002   Program:   bbtk
00003   Module:    $RCSfile: bbtkWxGUIScriptingInterface.cxx,v $
00004   Language:  C++
00005   Date:      $Date: 2011/03/21 11:18:00 $
00006   Version:   $Revision: 1.45 $
00007 =========================================================================*/
00008 
00009 /* ---------------------------------------------------------------------
00010 
00011 * Copyright (c) CREATIS-LRMN (Centre de Recherche en Imagerie Medicale)
00012 * Authors : Eduardo Davila, Laurent Guigues, Jean-Pierre Roux
00013 *
00014 *  This software is governed by the CeCILL-B license under French law and 
00015 *  abiding by the rules of distribution of free software. You can  use, 
00016 *  modify and/ or redistribute the software under the terms of the CeCILL-B 
00017 *  license as circulated by CEA, CNRS and INRIA at the following URL 
00018 *  http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html 
00019 *  or in the file LICENSE.txt.
00020 *
00021 *  As a counterpart to the access to the source code and  rights to copy,
00022 *  modify and redistribute granted by the license, users are provided only
00023 *  with a limited warranty  and the software's author,  the holder of the
00024 *  economic rights,  and the successive licensors  have only  limited
00025 *  liability. 
00026 *
00027 *  The fact that you are presently reading this means that you have had
00028 *  knowledge of the CeCILL-B license and that you accept its terms.
00029 * ------------------------------------------------------------------------ */                                                                         
00030    
00031 
00048 #ifdef _USE_WXWIDGETS_
00049 
00050 #include <iostream>     
00051 #include "bbtkWxGUIScriptingInterface.h"
00052 #include "bbtkWxBlackBox.h"
00053 #include "bbtkConfigurationFile.h"
00054 #include "bbtkWxStreamRedirector.h"
00055 #include "bbtkUtilities.h"
00056 
00057 #include <wx/tipwin.h>
00058 #include <wx/splash.h>
00059 
00060 
00061 //#include "icons/cc_run.xpm"
00062 
00063 namespace bbtk
00064 {
00065 
00066     enum
00067     {
00068       ID_Menu_Quit = 1,
00069       ID_Menu_About,
00070       ID_Menu_EditConfig,
00071       ID_Menu_CreatePackage,
00072       ID_Menu_CreateBlackBox,
00073       ID_Menu_ShowImageGraph,
00074       ID_Menu_RegeneratePackageDoc,
00075       ID_Menu_RegenerateBoxesLists,
00076       ID_Menu_RegenerateAll,
00077       ID_Menu_PlugPackage,
00078       ID_Menu_Windows_Files,
00079       ID_Menu_Windows_Help,
00080       ID_Menu_Windows_Messages,
00081       ID_Menu_Windows_Command,
00082       ID_Menu_Windows_Save,
00083       ID_Menu_Windows_PackageBrowser
00084       //      ID_Button_Run
00085     };
00086     
00087   
00088   //================================================================
00089   WxGUIScriptingInterface::WxGUIScriptingInterface( wxWindow *parent )
00090     : wxFrame((wxFrame *)parent, -1, _T("bbStudio"), 
00091               wxDefaultPosition, wxSize(1200,800) )
00092   {     
00093     m_mgr.SetManagedWindow(this);
00094     
00095     mInterpreter = bbtk::Interpreter::New();
00096     mInterpreter->SetUser(this);
00097         mInterpreter->SetCommandLine(true);
00098     mInterpreter->SetThrow(true);
00099     //    mInterpreter->AddBreakObserver
00100     //boost::bind( &WxGUIScriptingInterface::InterpreterUserOnBreak, this ));
00101     //==============
00102     // Menu
00103     wxInitAllImageHandlers();
00104     
00105     wxMenu *menuFile = new wxMenu;
00106     menuFile->Append( ID_Menu_EditConfig, _T("Open bbtk &Config file") );
00107     menuFile->Append( ID_Menu_Quit, _T("&Quit") );
00108     
00109     wxMenu *menuAbout = new wxMenu;
00110     menuAbout->Append( ID_Menu_About, _T("&About...") );
00111 
00112     wxMenu *menuTools = new wxMenu;
00113     menuTools->Append( ID_Menu_CreatePackage,  _T("Create &package") );
00114     menuTools->Append( ID_Menu_CreateBlackBox, _T("Create &black box") );
00115     menuTools->Append( ID_Menu_PlugPackage,    _T("&Plug package") );
00116     menuTools->AppendSeparator();
00117     menuTools->Append( ID_Menu_RegeneratePackageDoc,_T("Regenerate package &doc") );
00118     menuTools->Append( ID_Menu_RegenerateBoxesLists,_T("Regenerate boxes &lists") );
00119     menuTools->Append( ID_Menu_RegenerateAll,       _T("Regenerate &all") );
00120     menuTools->AppendSeparator();
00121     menuTools->Append( ID_Menu_ShowImageGraph, _T("&Show last graph") );
00122 
00123     wxMenu *menuWindows = new wxMenu;
00124     menuWindows->AppendCheckItem(ID_Menu_Windows_Files,
00125                                  _T("Show 'files' panel") )->Check();
00126     menuWindows->AppendCheckItem(ID_Menu_Windows_Help,
00127                                  _T("Show 'help' panel") )->Check();
00128     menuWindows->AppendCheckItem(ID_Menu_Windows_Messages,
00129                                  _T("Show 'messages' panel") )->Check();
00130     menuWindows->AppendCheckItem(ID_Menu_Windows_Command,
00131                                  _T("Show 'command' panel") )->Check();
00132     menuWindows->AppendSeparator();
00133     menuWindows->Append( ID_Menu_Windows_PackageBrowser, _T("Start Package &Browser") );
00134     
00135     //    menuWindows->AppendSeparator();
00136     //    menuWindows->Append ( ID_Menu_Windows_Save, _T("Save interface configuration"));
00137 
00138     wxMenu *menuOptions = new wxMenu;
00139     mwxMenuItemReset = menuOptions->AppendCheckItem(-1,
00140                                                     _T("Reset before running") );
00141     mwxMenuItemReset->Check();
00142 
00143     wxMenuBar *menuBar = new wxMenuBar;
00144     menuBar->Append( menuFile, _T("&File") );
00145     menuBar->Append( menuTools, _T("&Tools") );
00146     menuBar->Append( menuOptions, _T("&Options") );
00147     menuBar->Append( menuWindows, _T("&Windows") );
00148     menuBar->Append( menuAbout, _T("About") );
00149     
00150     SetMenuBar( menuBar );
00151     
00152     //=== 
00153     // Status bar
00154     CreateStatusBar();
00155     SetStatusText( _T("Welcome to bbStudio !") );
00156     
00157     //===
00158     // Panes (Files, Messages, Help, Command)
00159     mWxGUITextEditor = new WxGUITextEditor(this,this);
00160     mWxGUITextEditor->SetFileNameFilter("*.bbs");
00161         
00162     mWxGUIHtmlBrowser = new WxGUIHtmlBrowser(this,wxSize(200,0),this);
00163 
00164     mWxGUIOutputMessages = new WxGUIOutputMessages(this);
00165 
00166     mWxGUICommand = new WxGUICommand(this,this);
00167    
00168     mWxGUICommand->SetFocus();
00169 
00170  
00171 #if NOTEBOOK
00172 
00173     mwxNotebook = new wxAuiNotebook(this,  
00174                                     -1,
00175                                     wxPoint(0, 0),
00176                                     wxSize(500,500),
00177                                     wxAUI_NB_TAB_SPLIT 
00178                                     | wxAUI_NB_TAB_MOVE
00179                                     | wxAUI_NB_TAB_EXTERNAL_MOVE
00180                                     //| wxAUI_NB_WINDOWLIST_BUTTON
00181                                     //|wxAUI_NB_SCROLL_BUTTONS
00182                                     // | wxAUI_NB_CLOSE_BUTTON 
00183                                     //| wxAUI_NB_CLOSE_ON_ACTIVE_TAB
00184                                     //| wxAUI_NB_CLOSE_ON_ALL_TABS
00185                                     | wxNO_BORDER);
00186   
00187 
00188     mwxNotebook->AddPage(mWxGUITextEditor,_T("Files"),true);
00189     mwxNotebook->AddPage(mWxGUIHtmlBrowser,_T("Help"),true);
00190 
00191     mwxNotebook->AddPage(mWxGUIOutputMessages,_T("Messages"),true);
00192 
00193     mwxNotebook->AddPage(mWxGUICommand,_T("Command"),true);
00194 
00195 
00196     m_mgr.AddPane(mwxNotebook,
00197                   wxAuiPaneInfo().Name(wxT("nb"))
00198                   .CaptionVisible(false)
00199                   .MinimizeButton(false)
00200                   .MaximizeButton(false)
00201                   .Center()
00202                   //              .MinSize(wxSize(100,100))
00203                   );   
00204 #else 
00205 
00206     //
00207     m_mgr.AddPane(mWxGUITextEditor,
00208                   wxAuiPaneInfo().Name(wxT("editor_content"))
00209                   .Caption(wxT("Files"))
00210                   .MinimizeButton(true)
00211                   .MaximizeButton(true)
00212                   .Center()
00213                   .MinSize(wxSize(100,100))
00214                   );   
00215   
00216     m_mgr.AddPane(mWxGUIHtmlBrowser,
00217                   wxAuiPaneInfo().Name(wxT("browser_content"))
00218                   .Caption(wxT("Help"))
00219                   .MinimizeButton(true)
00220                   .MaximizeButton(true)
00221                   .Right()
00222                   .Layer(2)
00223                   .MinSize(wxSize(400,100))
00224                   );
00225 
00226     m_mgr.AddPane(mWxGUIOutputMessages,
00227                   wxAuiPaneInfo().Name(wxT("messages_content"))
00228                   .Caption(wxT("Messages"))
00229                   .MinimizeButton(true)
00230                   .MaximizeButton(true)
00231                   .Bottom()
00232                   .MinSize(wxSize(100,100))
00233                   );
00234           
00235     m_mgr.AddPane(mWxGUICommand,
00236                   wxAuiPaneInfo().Name(wxT("command_content"))
00237                   .Caption(wxT("Command"))
00238                   .MinimizeButton(true)
00239                   .MaximizeButton(true)
00240                   .Bottom()
00241                   .Layer(1)
00242                   .MinSize(wxSize(100,100))
00243                   );     
00244 #endif
00245 
00246     // parent window of all bbtk windows will be a child of this
00247     //    Wx::SetTopWindowParent(this);
00248     Wx::SetTopWindow(this);
00249     // Wx::SetAutoDestroyTopWindow(false);
00250   // Add the method OnWxSignal as a Wx::Signal observer 
00251     //bbtkAddWxSignalObserver(WxGUIPackageBrowser2Window::OnWxSignal);
00252 
00253     //.PaneBorder(false)); 
00254     // Load the interface appearance saved on last closing
00255     LoadPerspective();
00256 
00257     // Done in LoadPerspective
00258     //    m_mgr.Update();
00259         
00260     SetAutoLayout(true);
00261     Layout();
00262     //    mwxNotebook->SetSelection(1);
00263     mWxGUIHtmlBrowser->GoHome();
00264 //    Refresh();
00265     m_mgr.Update();
00266     //   LoadPerspective();
00267 
00268     mBreaked = false;   
00269 
00270     wxBitmap bitmap;   
00271     wxSplashScreen* splash;
00272     long style = wxSPLASH_CENTRE_ON_SCREEN | wxSPLASH_TIMEOUT;
00273     if (ConfigurationFile::GetInstance().DotBbtkIsNew())
00274       style = wxSPLASH_CENTRE_ON_SCREEN | wxSPLASH_NO_TIMEOUT;
00275     std::string splash_file = ConfigurationFile::GetInstance().Get_data_path();
00276     splash_file += "/kernel/icons/bbStudioSplashScreen.png";
00277 
00278     if (bitmap.LoadFile(std2wx(splash_file),wxBITMAP_TYPE_PNG))
00279       splash = 
00280         new wxSplashScreen(bitmap,
00281                            style,
00282                            1000, 0, -1, wxDefaultPosition, wxDefaultSize,
00283                            wxSIMPLE_BORDER|wxSTAY_ON_TOP);
00284 
00285     if (ConfigurationFile::GetInstance().DotBbtkIsNew())
00286       {
00287 
00288         DoRegeneratePackageDoc("-a");   
00289         DoRegenerateBoxesLists();
00290 
00291         /*
00292         wxTipWindow* tip = new wxTipWindow(this,
00293                                            _T("\n                  Welcome to bbStudio !\n\n   To run a demo or example:\n     1. click on the 'Demos' or 'Examples' link\n     2. select a demo or example\n     3. click on the '[source]' link : the source file is loaded in bbStudio\n     4. click on the 'Run' button (the arrow at the bottom right of the source file)   \n"),1000);
00294         tip->CenterOnParent();
00295         tip->Show();
00296         */
00297         if (splash) splash->Destroy();
00298       }
00299 
00300   }
00301   //================================================================
00302 
00303  //================================================================
00304   WxGUIScriptingInterface::~WxGUIScriptingInterface()
00305   {
00306   bbtkDebugMessage("widget",9,"bbStudio::~bbStudio()"<<std::endl);
00307     SavePerspective();
00308     m_mgr.UnInit();
00309   }
00310   //================================================================
00311 
00312   //================================================================
00313   void WxGUIScriptingInterface::OnClose(wxCloseEvent& event)
00314   {
00315     bbtkDebugMessage("widget",9,"bbStudio::OnClose()"<<std::endl);
00316     //Wx::SetWindowsHaveBeenDestroyedByParent();
00317     //mInterpreter.reset();
00318     wxWindowList& list = GetChildren();
00319     wxWindowList::iterator iter;
00320     for (iter = list.begin(); iter != list.end(); ++iter)
00321       {
00322         (*iter)->Close();
00323       }
00324     this->Destroy();
00325   }
00326   //================================================================
00327 
00328 
00329   //================================================================
00330   void WxGUIScriptingInterface::Open(const std::string& filename)
00331   {
00332     mWxGUITextEditor->Open(filename);
00333   }
00334   //================================================================
00335   /*
00336   catch (BreakException e)                                              \
00337     {                                                                   \
00338       std::cout << "* BREAK"<<std::endl;                                \
00339       if (e.IsInScriptFile())                                           \
00340         std::cout << "* FILE   : '"<<e.GetScriptFile()<<"'"<<std::endl; \
00341       std::cout << "* LINE   : "<<e.GetScriptLine()<<std::endl;         \
00342     }                                                                   \
00343   catch (QuitException e)                                               \
00344     {                                                                   \
00345       std::cout << "* QUIT"<<std::endl;                                 \
00346       if (e.IsInScriptFile())                                           \
00347         std::cout << "* FILE   : '"<<e.GetScriptFile()<<"'"<<std::endl; \
00348       std::cout << "* LINE   : "<<e.GetScriptLine()<<std::endl;         \
00349     }                                                                   \
00350 */
00351   
00352 #define CATCH_MACRO                                                     \
00353   catch (InterpreterException e)                                        \
00354     {                                                                   \
00355       if (e.GetErrorMessage()=="quit")                                  \
00356         {                                                               \
00357           std::cerr << "* QUIT ENCOUNTERED"<<std::endl;                 \
00358           if (e.IsInScriptFile())                                       \
00359             std::cerr << "* FILE   : '"<<e.GetScriptFile()<<"'"<<std::endl; \
00360           std::cerr << "* LINE   : "<<e.GetScriptLine()<<std::endl;     \
00361         }                                                               \
00362       else if (e.GetErrorMessage()=="break")                            \
00363         {                                                               \
00364           mBreaked = true;                                              \
00365           std::cerr << "* BREAK"<<std::endl;                            \
00366           if (e.IsInScriptFile())                                       \
00367             std::cerr << "* FILE   : '"<<e.GetScriptFile()<<"'"<<std::endl; \
00368           std::cerr << "* LINE   : "<<e.GetScriptLine()<<std::endl;     \
00369         }                                                               \
00370       else                                                              \
00371         {                                                               \
00372           std::cerr << "* ERROR : "<<e.GetErrorMessage()<<std::endl;    \
00373           if (e.IsInScriptFile())                                       \
00374             std::cerr << "* FILE   : '"<<e.GetScriptFile()<<"'"<<std::endl; \
00375           std::cerr << "* LINE   : "<<e.GetScriptLine()<<std::endl;     \
00376           int lev = bbtk::MessageManager::GetMessageLevel("Error");     \
00377           if (lev > 0) {                                                \
00378             std::cerr << "* Exception thrown : "<<std::endl;            \
00379             std::cerr << "*  OBJECT : " <<e.GetObject()<<std::endl;     \
00380             std::cerr << "*  FILE   : " <<e.GetSourceFile()<<std::endl; \
00381           }                                                             \
00382         }                                                               \
00383     }
00384   
00385   //================================================================
00386   void WxGUIScriptingInterface::WxGUICommandEnter(const std::string& command)
00387   {
00388     std::string s("> ");
00389     s += command + "\n";
00390     mWxGUIOutputMessages->Print(s,wxRED);
00391     
00392     try
00393       {
00394         mInterpreter->InterpretLine( command );
00395       }
00396     CATCH_MACRO;
00397   }
00398   //================================================================
00399   
00400   //================================================================
00402   bool WxGUIScriptingInterface::InterpretFile( const std::string& filename) 
00403   { 
00404     try
00405       {
00406         mInterpreter->InterpretFile(filename);
00407       }
00408     CATCH_MACRO;
00409     return true;
00410   }
00411   //================================================================
00412  
00413         
00414   //================================================================
00415         void WxGUIScriptingInterface::WxGUITextEditorGraphSimple()
00416         {
00417                 WxGUICommandEnter("exec freeze_no_error");
00418                 WxGUITextEditorRun();
00419                 WxGUICommandEnter("exec unfreeze");
00420                 WxGUICommandEnter("graph");
00421         }
00422   //================================================================
00423         
00424         //================================================================
00425         void WxGUIScriptingInterface::WxGUITextEditorGraphDetail()
00426         {
00427                 WxGUICommandEnter("exec freeze_no_error");
00428                 WxGUITextEditorRun();
00429                 WxGUICommandEnter("exec unfreeze");
00430                 WxGUICommandEnter("graph . 1");
00431         }
00432         //================================================================
00433 
00434         
00435         //================================================================
00436         void WxGUIScriptingInterface::WxGUITextEditorRunBBI()
00437         {
00438           std::string separator = ConfigurationFile::GetInstance().Get_file_separator ();
00439           std::string dir = ConfigurationFile::GetInstance().Get_default_temp_dir();
00440           std::string filename = dir + separator + "tmp_bbtk.bbs";
00441           mWxGUITextEditor->GetCurrentPage()->SaveFile(filename);
00442         
00443         std::string command = "\"";
00444 
00445 #ifdef WIN32
00446         command += "\"";
00447 #endif
00448 
00449           command += ConfigurationFile::GetInstance().Get_bin_path();
00450 #ifdef MACOSX
00451           command += separator + "bbi.app/Contents/MacOS/bbi\" ";
00452 #else 
00453           command += separator + "bbi\" ";
00454 #endif
00455           command += "\""+filename + "\"";
00456 
00457 #ifdef WIN32
00458         command += "\"";
00459 #endif
00460 
00461           command += " & ";
00462           
00463           printf ("EED WxGUIScriptingInterface::WxGUITextEditorRunBBI %s \n" , command.c_str() );
00464           system( command.c_str() );
00465         }
00466         //================================================================
00467         
00468         
00469   //================================================================
00470   void WxGUIScriptingInterface::WxGUITextEditorRun()
00471   {
00472     //    wxString temp = mWxGUIHtmlBrowser->GetCurrentPage();
00473     std::stringstream* buf = new std::stringstream;
00474     (*buf) << mWxGUITextEditor->GetCurrentPage()->GetText();
00475     try 
00476       {
00477         if (!mBreaked)
00478           {
00479             if (mwxMenuItemReset->IsChecked()) WxGUICommandEnter("reset");
00480             mInterpreter->InterpretBuffer(buf);
00481           }
00482         else 
00483           {
00484             mBreaked = false;
00485             mInterpreter->InterpretCurrentStreams();
00486           }
00487         //      std::cout << "EO RUN"<<std::endl;
00488       }
00489     CATCH_MACRO;
00490     //    std::cout << "EO RUN 3"<<std::endl;
00491   }
00492   //================================================================  
00493 
00494   //================================================================
00495   void WxGUIScriptingInterface::OnMenuQuit(wxCommandEvent& WXUNUSED(event))
00496   {
00497     if (!mWxGUITextEditor->CloseAllPages()) return;
00498     Close(true);
00499   }
00500   //================================================================
00501 
00502 
00503   //================================================================
00504   void WxGUIScriptingInterface::OnMenuAbout(wxCommandEvent& WXUNUSED(event))
00505   {
00506     m_mgr.Update();
00507     Refresh();
00508     wxMessageBox(_T("  bbStudio\nThe Black Box Toolkit Development Studio\n(c) CREATIS-LRMN 2008\n\n http://www.creatis.insa-lyon.fr/site/en/CreaTools_home"),
00509                  _T("About ..."), wxOK | wxICON_INFORMATION,
00510                  this);
00511   }
00512   //================================================================
00513 
00514 
00515   //================================================================
00516   void WxGUIScriptingInterface::OnMenuEditConfig(wxCommandEvent& WXUNUSED(event))
00517   {
00518 
00519     std::string configFile = 
00520       ConfigurationFile::GetInstance().Get_config_xml_full_path();
00521     Open(configFile);
00522         wxMessageDialog ww(NULL,_T("If you change the bbtk_config.xml, you have to restart this appliaction..."), _T("Alert !"), wxOK);
00523         ww.ShowModal();
00524   }
00525   //================================================================
00526 
00527   //================================================================
00528   void WxGUIScriptingInterface::OnMenuWindowsPackageBrowser(wxCommandEvent& WXUNUSED(event))
00529   {
00530     wxBusyCursor wait;
00531     WxGUIPackageBrowser2Window *helpbrowser = new
00532       WxGUIPackageBrowser2Window(this,_T("Package Browser"), wxSize(600,600) );
00533     helpbrowser->Show();
00534     
00535     /*
00536     wxBusyCursor wait;
00537     WxGUIPackageBrowser2 *browser = new WxGUIPackageBrowser2(this);
00538     browser->IncludeAll();
00539     */
00540 #if NOTEBOOK
00541     //     mwxNotebook->AddPage(browser,_T("Package Browser"),true);
00542 #else
00543      /*
00544      m_mgr.AddPane(browser,
00545                    wxAuiPaneInfo().Name(wxT("package_brower"))
00546                    .Caption(wxT("Package browser"))
00547                    .MinimizeButton(true)
00548                    .MaximizeButton(true)
00549                    .Bottom()
00550                    .Position(1)
00551                    .MinSize(wxSize(100,100))
00552                    );     
00553      */
00554 #endif
00555   }
00556   //================================================================
00557 
00558 
00559 
00560   //================================================================
00561   void WxGUIScriptingInterface::OnMenuCreatePackage(wxCommandEvent& WXUNUSED(event))
00562   {
00563 /*
00564     std::string command("toolsbbtk/appli/GUICreatePackage");
00565     bbtkMessage("Debug",1,"Executing : '"<<command<<"'"<<std::endl);
00566   
00567         Interpreter::Pointer I = Interpreter::New();    
00568     I->InterpretFile(command);
00569 */
00570     std::string command("reset");
00571         mWxGUICommand->SendCommand(command);
00572     command = "include toolsbbtk/appli/GUICreatePackage";
00573     bbtkMessage("Debug",1,"Executing : '"<<command<<"'"<<std::endl);
00574         mWxGUICommand->SendCommand(command);
00575   }
00576   //================================================================
00577 
00578 
00579   //================================================================
00580   void WxGUIScriptingInterface::OnMenuCreateBlackBox(wxCommandEvent& WXUNUSED(event))
00581   {
00582           /*
00583     std::string command("toolsbbtk/appli/GUICreateBlackBox");
00584     bbtkMessage("Debug",1,"Executing : '"<<command<<"'"<<std::endl);
00585     
00586     Interpreter::Pointer I = Interpreter::New();    
00587     I->InterpretFile(command);
00588 */
00589     std::string command("reset");
00590         mWxGUICommand->SendCommand(command);
00591     command = "include toolsbbtk/appli/GUICreateBlackBox";
00592     bbtkMessage("Debug",1,"Executing : '"<<command<<"'"<<std::endl);
00593         mWxGUICommand->SendCommand(command);
00594   }
00595   //================================================================
00596   
00597   //================================================================
00598   void WxGUIScriptingInterface::OnMenuShowImageGraph(wxCommandEvent& WXUNUSED(event))
00599   {
00600 
00601       std::string doc_path = bbtk::ConfigurationFile::GetInstance().Get_doc_path();
00602       doc_path += bbtk::ConfigurationFile::GetInstance().Get_file_separator();
00603       doc_path += "bbdoc";
00604       doc_path += bbtk::ConfigurationFile::GetInstance().Get_file_separator();
00605           
00606           std::string pack_name("User");
00607           std::string pack_path = doc_path + pack_name;   
00608           
00609 #if defined(WIN32)
00610     std::string strappli="start ";
00611 #else
00612   #if defined(MACOSX)
00613       std::string strappli="open ";
00614   #else
00615       std::string strappli="gnome-open ";         
00616   #endif
00617 #endif    
00618           std::string strcommand = strappli +pack_path+"/workspace_workspacePrototype.png";
00619     //  std::cout << "system: " << strcommand << std::endl;
00620     system ( strcommand.c_str() );
00621 
00622   }
00623   //================================================================
00624 
00625   void WxGUIScriptingInterface::DoRegeneratePackageDoc( const std::string& pack )
00626   {
00627     std::string mess("Regenerating doc for package '");
00628     if (pack!="-a") 
00629       mess += pack + "'";
00630     else 
00631       mess = "Regenerating doc for all packages";
00632     mess += " ... please wait";
00633 
00634     SetStatusText( std2wx(mess) );
00635 
00636     BBTK_BUSY_CURSOR;
00637 
00638     std::string command;
00639 #if defined(WIN32)
00640     command = "\"";
00641 #endif
00642     command += ConfigurationFile::GetInstance().Get_bin_path();
00643     command += ConfigurationFile::GetInstance().Get_file_separator();
00644     command += "bbRegeneratePackageDoc";
00645 #if defined(WIN32)
00646         command += "\"";
00647 #endif
00648         command += " " + pack + " -q";
00649     bbtkMessage("debug",1,"Executing system command '"<<command<<"'"<<std::endl);
00650 
00651 
00652     if ( ! system ( command.c_str() ) )
00653       {
00654         SetStatusText( _T("Done !"));
00655         /*
00656         wxMessageBox(_T("Done !"),_T("Regenerate package '")
00657                      +std2wx(pack)+_T("' doc"),
00658                      wxOK | wxICON_INFORMATION);
00659         */
00660       }
00661     else 
00662       {
00663         SetStatusText( _T("Done !"));
00664         wxString err(_T("An error occured while running '"));
00665         err +=  bbtk::std2wx(command) + _T("'");
00666         wxMessageBox(err,_T("Regenerate package doc"),wxOK | wxICON_ERROR);      
00667       }
00668   }
00669 
00670 
00671   //================================================================
00672   void WxGUIScriptingInterface::OnMenuRegeneratePackageDoc(wxCommandEvent& WXUNUSED(event))
00673   {
00674     wxString name = wxGetTextFromUser(_T("Enter package name (-a for all)"),
00675                                       _T("Regenerate package doc"),
00676                                       _T(""));
00677     if (name.IsEmpty()) return;
00678     std::string pack = bbtk::wx2std(name);
00679     
00680         DoRegeneratePackageDoc(pack);
00681   }
00682   //================================================================
00683 
00684 
00685   //================================================================
00686   void WxGUIScriptingInterface::DoRegenerateBoxesLists()
00687   {
00688     SetStatusText( _T("Regenerating boxes lists ... please wait") );
00689     BBTK_BUSY_CURSOR ;
00690 
00691     std::string command;
00692 #if defined(WIN32)
00693         command = "\"";
00694 #endif
00695     command += ConfigurationFile::GetInstance().Get_bin_path();
00696     command += ConfigurationFile::GetInstance().Get_file_separator();
00697     command += "bbRegenerateBoxesLists";
00698 #if defined(WIN32)
00699         command += "\"";
00700 #endif
00701         command += " -q";
00702         bbtkMessage("debug",1,"Executing system command '"<<command<<"'"<<std::endl);
00703 
00704 std::cout << "==========================================================================================================" << command.c_str() << std::endl;
00705     if ( ! system ( command.c_str() ) )
00706       {
00707         SetStatusText( _T("Done !"));
00708         /*
00709         wxMessageBox(_T("Done !"),_T("Regenerate boxes lists"),
00710                      wxOK | wxICON_INFORMATION);
00711         */
00712       }
00713     else 
00714       {
00715         SetStatusText( _T("Done !"));
00716         wxString err(_T("An error occured while running '"));
00717         err +=  bbtk::std2wx(command) + _T("'");
00718         wxMessageBox(err,_T("Regenerate boxes lists"),wxOK | wxICON_ERROR);      
00719       }
00720   }
00721   //================================================================
00722 
00723 
00724   //================================================================
00725   void WxGUIScriptingInterface::OnMenuRegenerateBoxesLists(wxCommandEvent& WXUNUSED(event))
00726   {
00727         DoRegenerateBoxesLists();
00728   }
00729   //================================================================
00730 
00731   //================================================================
00732   void WxGUIScriptingInterface::OnMenuRegenerateAll(wxCommandEvent& WXUNUSED(event))
00733   {
00734         
00735     DoRegeneratePackageDoc("-a");       
00736         DoRegenerateBoxesLists();
00737   }
00738   //================================================================
00739 
00740  
00741   //================================================================
00742   void WxGUIScriptingInterface::OnMenuPlugPackage(wxCommandEvent& WXUNUSED(event))
00743   {
00744     long style = wxDD_DEFAULT_STYLE | wxDD_DIR_MUST_EXIST;
00745     wxDirDialog* FD = 
00746       new wxDirDialog( 0, 
00747                        _T("Select package directory"),
00748                        _T(""),
00749                        style);
00750     
00751     if (FD->ShowModal()==wxID_OK)
00752       {
00753         std::string path = wx2std (FD->GetPath()) ;
00754         std::string fname = path + "/bbtkPackage"; 
00755         if ( ! Utilities::FileExists( fname ) )
00756           {
00757             wxString err(_T("The directory does not contain a 'bbtkPackage' file"));
00758             wxMessageBox(err,_T("Plug package"),wxOK | wxICON_ERROR);      
00759             return;
00760           }
00761         
00762         std::ifstream f;
00763         f.open(fname.c_str());
00764         std::string pname;
00765         f >> pname;
00766         f.close();
00767         
00768         bbtk::ConfigurationFile::GetInstance().AddPackagePathsAndWrite( path );
00769         
00770         DoRegeneratePackageDoc(pname);
00771         DoRegenerateBoxesLists();
00772       } 
00773   }
00774   //================================================================
00775 
00776   //================================================================
00777   void WxGUIScriptingInterface::InterpreterUserViewHtmlPage(const std::string& page)
00778   {
00779     std::string s(page);
00780     //  std::cout << "WxGUIScriptingInterface::ShowHtmlPage('"<<page<<"')"<<std::endl;
00781     if (mWxGUIHtmlBrowser->GoTo(s)) 
00782       {
00783 //EED   mwxNotebook->ChangeSelection(1);
00784 //      mwxNotebook->SetSelection(1);
00785       }
00786     else 
00787       {
00788          // std::cout << "ERROR html"<<std::endl;
00789       }
00790   } 
00791   //================================================================  
00792   
00793   /*
00794   //================================================================
00795   void WxGUIScriptingInterface::InterpreterUserOnBreak()
00796   {
00797     //    std::cout << "Break" << std::endl;
00798     
00799   }
00800   //================================================================
00801   */
00802 
00803   //================================================================  
00804   bool WxGUIScriptingInterface::WxGUIHtmlBrowserUserOnLinkClicked(const std::string& target)
00805   {
00806     size_t s = target.length();
00807     if ((s>3) && (target[s-1]=='s')
00808               && (target[s-2]=='b')
00809               && (target[s-3]=='b')
00810               && (target[s-4]=='.'))
00811         {
00812                         mWxGUITextEditor->Open(target);
00813                         #if NOTEBOOK
00814                                 mwxNotebook->SetSelection(0);
00815                         #endif
00816                         mWxGUITextEditor->SetFocus();
00817                         return false;
00818         }
00819 
00820         if ((s>3) && (target[s-1]=='f')
00821                   && (target[s-2]=='d')
00822                   && (target[s-3]=='p')
00823                   && (target[s-4]=='.'))
00824         {
00825 
00826                 // Open pdf in linux
00827                   // gnome-open target
00828 
00829                 // Open pdf in macOS
00830 
00831                 // Open pdf in windows
00832                         int size=target.size();
00833                         int pos=target.rfind("\\");
00834                         std::string commandStart("start ");
00835                         std::string commandPath("/D \""+target.substr(0,pos) +"\"");
00836                         std::string commandPDF( target.substr(pos+1,size-pos+1) );
00837 
00838                         printf("EED WxGUIScriptingInterface::WxGUIHtmlBrowserUserOnLinkClicked cc %s \n",commandPath.c_str() );
00839                         // cleanning path
00840                         while (commandPath.rfind("\\\\")!=-1 )
00841                         {
00842                                 commandPath.erase( commandPath.rfind("\\\\") , 1 );
00843                         printf("EED WxGUIScriptingInterface::WxGUIHtmlBrowserUserOnLinkClicked cc %s \n",commandPath.c_str() );
00844                         }
00845 
00846                         std::string command = commandStart+commandPath+" "+commandPDF;
00847                         printf("EED WxGUIScriptingInterface::WxGUIHtmlBrowserUserOnLinkClicked BB %s \n",command.c_str() );
00848                         system( command.c_str() );
00849                         return false;
00850      }
00851     return true;
00852   }
00853   //================================================================  
00854 
00855   void WxGUIScriptingInterface::OnMenuWindowsCheck( wxCommandEvent& event, 
00856                                                     wxWindow* w)
00857   {
00858     bool checked = event.IsChecked();
00859     bool shown = m_mgr.GetPane(w).IsShown();
00860     //    std::cout << "checked = "<<checked<<" - shown = "<<shown<<std::endl;
00861     if (checked ^ shown) 
00862       {
00863         m_mgr.GetPane(w).Show(checked);
00864         m_mgr.Update();
00865       }
00866   }
00867 
00868   //================================================================  
00869   void WxGUIScriptingInterface::OnMenuWindowsFiles(wxCommandEvent& event)
00870   {
00871     OnMenuWindowsCheck(event,mWxGUITextEditor);
00872   }
00873   //================================================================  
00874 
00875   //================================================================  
00876   void  WxGUIScriptingInterface::OnMenuWindowsHelp(wxCommandEvent& event)
00877   {
00878     OnMenuWindowsCheck(event,mWxGUIHtmlBrowser);
00879   }
00880   //================================================================  
00881 
00882   //================================================================  
00883   void  WxGUIScriptingInterface::OnMenuWindowsMessages(wxCommandEvent& event)
00884   {
00885     OnMenuWindowsCheck(event,mWxGUIOutputMessages);
00886   }
00887   //================================================================  
00888 
00889   //================================================================  
00890   void  WxGUIScriptingInterface::OnMenuWindowsCommand(wxCommandEvent& event)
00891   {
00892     OnMenuWindowsCheck(event,mWxGUICommand);
00893   }
00894   //================================================================  
00895 
00896   //================================================================  
00897   void WxGUIScriptingInterface::OnMenuWindowsSave( wxCommandEvent& WXUNUSED(event))
00898   {
00899     SavePerspective();
00900   }
00901   //================================================================  
00902 
00903   //================================================================  
00904   void WxGUIScriptingInterface::SavePerspective()
00905   {
00906     //    std::cout  << "Saving configuration..."<<std::endl;
00907     std::string conf = wx2std(m_mgr.SavePerspective());
00908     std::string fname = Utilities::MakeUserSettingsFullFileName("bbStudio.aui");
00909     std::ofstream f;
00910     f.open(fname.c_str(), std::ios::out );
00911     f << conf << std::endl;
00912 
00913     //    int x,y;
00914     //    GetPosition(&x,&y);
00915     //    f << x << "  " << y << std::endl;
00916 
00917 
00918     int w,h;
00919     GetSize(&w,&h);
00920 
00921     f << w << " " << h << std::endl;
00922 
00923     f.close();
00924   }
00925   //================================================================  
00926 
00927   //================================================================  
00928   void WxGUIScriptingInterface::LoadPerspective()
00929   {
00930     std::string fname = 
00931       Utilities::MakeUserSettingsFullFileName("bbStudio.aui");
00932     if ( Utilities::FileExists( fname ))
00933       {
00934         //      std::cout  << "Loading configuration..."<<std::endl;
00935 
00936         std::ifstream f;
00937         f.open(fname.c_str());
00938         std::string conf;
00939         f >> conf;
00940 
00941         //      int x,y;
00942         //      f >> x >> y ;
00943 
00944         int w,h;
00945         f >> w >> h ;
00946 
00947         f.close();
00948         
00949         //      std::cout << conf << std::endl;
00950 
00951         //      Move(x,y);
00952         SetSize(w,h);
00953         m_mgr.LoadPerspective(std2wx(conf));
00954       }
00955     else 
00956       {
00957         m_mgr.Update();
00958       }
00959   }
00960   //================================================================  
00961 
00962   //================================================================  
00963   void WxGUIScriptingInterface::OnPaneClose(wxAuiManagerEvent& evt)
00964   {
00965     std::cout  << "Closing panel '"<<evt.pane->name<<"'"<<std::endl;
00966     // TO DO : Uncheck 
00967     //    OnMenuWindowsCheck( wxCommandEvent& event, wxWindow* w);
00968   }
00969   //================================================================  
00970 
00971   
00972   //================================================================  
00973   BEGIN_EVENT_TABLE(WxGUIScriptingInterface, wxFrame)
00974     EVT_CLOSE(  WxGUIScriptingInterface::OnClose)
00975     EVT_MENU(ID_Menu_Quit, WxGUIScriptingInterface::OnMenuQuit)
00976     EVT_MENU(ID_Menu_About, WxGUIScriptingInterface::OnMenuAbout)
00977     EVT_MENU(ID_Menu_EditConfig, WxGUIScriptingInterface::OnMenuEditConfig)
00978     EVT_MENU(ID_Menu_CreatePackage, WxGUIScriptingInterface::OnMenuCreatePackage)
00979     EVT_MENU(ID_Menu_CreateBlackBox, WxGUIScriptingInterface::OnMenuCreateBlackBox)
00980     EVT_MENU(ID_Menu_ShowImageGraph, WxGUIScriptingInterface::OnMenuShowImageGraph)
00981     EVT_MENU(ID_Menu_RegeneratePackageDoc, WxGUIScriptingInterface::OnMenuRegeneratePackageDoc)
00982     EVT_MENU(ID_Menu_RegenerateBoxesLists, WxGUIScriptingInterface::OnMenuRegenerateBoxesLists)
00983     EVT_MENU(ID_Menu_RegenerateAll, WxGUIScriptingInterface::OnMenuRegenerateAll)
00984     EVT_MENU(ID_Menu_PlugPackage, WxGUIScriptingInterface::OnMenuPlugPackage)
00985     EVT_MENU(ID_Menu_Windows_Files, WxGUIScriptingInterface::OnMenuWindowsFiles)
00986     EVT_MENU(ID_Menu_Windows_Help, WxGUIScriptingInterface::OnMenuWindowsHelp)
00987     EVT_MENU(ID_Menu_Windows_Messages, WxGUIScriptingInterface::OnMenuWindowsMessages)
00988     EVT_MENU(ID_Menu_Windows_Command, WxGUIScriptingInterface::OnMenuWindowsCommand)
00989     EVT_MENU(ID_Menu_Windows_Save, WxGUIScriptingInterface::OnMenuWindowsSave)
00990     EVT_MENU(ID_Menu_Windows_PackageBrowser, WxGUIScriptingInterface::OnMenuWindowsPackageBrowser)
00991     EVT_AUI_PANE_CLOSE(WxGUIScriptingInterface::OnPaneClose)
00992   //    EVT_BUTTON(ID_Button_Run, WxGUIScriptingInterface::OnButtonRun )
00993     END_EVENT_TABLE()
00994   //================================================================
00995 
00996 } // namespace bbtk
00997 
00998 
00999 #endif //_USE_WXWIDGETS_

Generated on Thu May 31 14:12:03 2012 for BBTK by  doxygen 1.5.7.1