bbtkWxGUIConsole.cxx

Go to the documentation of this file.
00001 /*=========================================================================                                                                               
00002   Program:   bbtk
00003   Module:    $RCSfile: bbtkWxGUIConsole.cxx,v $
00004   Language:  C++
00005   Date:      $Date: 2008/10/17 08:18:15 $
00006   Version:   $Revision: 1.15 $
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 "bbtkWxGUIConsole.h"
00052 #include "bbtkWxBlackBox.h"
00053 #include "bbtkConfigurationFile.h"
00054 #include "bbtkWxStreamRedirector.h"
00055  
00056 
00057 #include "icons/cc_run.xpm"
00058 
00059 namespace bbtk
00060 {
00061 
00062     enum
00063     {
00064       ID_Menu_Quit = 1,
00065       ID_Menu_About,
00066       ID_Menu_EditConfig,
00067       ID_Menu_CreatePackage,
00068       ID_Menu_CreateBlackBox,
00069       ID_Menu_ShowImageGraph,
00070       ID_Menu_ShowHTMLDoc,
00071       ID_Menu_CreateIndex,
00072       ID_Button_Run
00073     };
00074     
00075   
00076   //================================================================
00077   WxGUIConsole::WxGUIConsole( wxWindow *parent, wxString title, wxSize size)
00078     : wxFrame((wxFrame *)parent, -1, title, wxDefaultPosition, size)
00079   {     
00080 //    m_mgr = new wxAuiManager(this);
00081         m_mgr.SetManagedWindow(this);
00082    
00083         mInterpreter = bbtk::Interpreter::New();
00084     mInterpreter->SetUser(this);
00085     mInterpreter->SetCommandLine(true);
00086     mInterpreter->SetThrow(false);
00087     //==============
00088     // Menu
00089     wxInitAllImageHandlers();
00090     
00091     wxMenu *menuFile = new wxMenu;
00092     menuFile->Append( ID_Menu_Quit, _T("&Quit") );
00093     
00094     wxMenu *menuAbout = new wxMenu;
00095     menuAbout->Append( ID_Menu_About, _T("&About...") );
00096 
00097     wxMenu *menuTools = new wxMenu;
00098     menuTools->Append( ID_Menu_EditConfig, _T("&Edit bbtk config") );
00099     menuTools->Append( ID_Menu_CreatePackage, _T("Create &package") );
00100     menuTools->Append( ID_Menu_CreateBlackBox, _T("Create &blackbox") );
00101     menuTools->Append( ID_Menu_ShowImageGraph, _T("&Show last image graph") );
00102     menuTools->Append( ID_Menu_ShowHTMLDoc, _T("Show &HTML documentation") );
00103     menuTools->Append( ID_Menu_CreateIndex, _T("&Generate index") );
00104     
00105     
00106     wxMenuBar *menuBar = new wxMenuBar;
00107     menuBar->Append( menuFile, _T("&File") );
00108     menuBar->Append( menuTools, _T("&Tools") );
00109     menuBar->Append( menuAbout, _T("About") );
00110     
00111     SetMenuBar( menuBar );
00112     
00113     CreateStatusBar();
00114     SetStatusText( _T("Welcome to bbi !") );
00115     
00116     //==============
00117     // Notebook
00118     
00119     //    wxFlexGridSizer *sizer = new wxFlexGridSizer(1);
00120     
00121 //EED    wxBoxSizer* sizer = new wxBoxSizer(wxVERTICAL);
00122 //    mwxNotebook = new wxNotebook(this,-1,wxDefaultPosition, wxDefaultSize, 0);
00123     mwxNotebook = new wxAuiNotebook(this,  
00124                                     -1,
00125                                     wxPoint(0, 0),
00126                                     wxSize(500,500),
00127                                     wxAUI_NB_TAB_SPLIT | wxAUI_NB_TAB_EXTERNAL_MOVE | wxNO_BORDER);
00128     
00129     mwxPageCommand = new wxPanel(mwxNotebook,-1);        
00130     mwxPageHelp = new wxPanel(mwxNotebook,-1);    
00131     
00132     
00133     wxBoxSizer *cmdsizer = new wxBoxSizer(wxVERTICAL);
00134     
00135     mwxPageCommand->SetAutoLayout(true);    
00136     mwxPageCommand->SetSizer(cmdsizer);
00137     cmdsizer->Fit(mwxPageCommand);
00138     cmdsizer->SetSizeHints(mwxPageCommand);
00139 
00140     wxBoxSizer *helpsizer = new wxBoxSizer(wxVERTICAL);
00141     
00142     mwxPageHelp->SetAutoLayout(true);    
00143     mwxPageHelp->SetSizer(helpsizer);
00144     helpsizer->Fit(mwxPageHelp);
00145     helpsizer->SetSizeHints(mwxPageHelp);
00146    
00147     mWxGUIHtmlBrowser = new WxGUIHtmlBrowser(mwxPageHelp,
00148                                              //EED                                wxSize(1200,0));
00149                                              wxSize(200,0));
00150 
00151     //    mWxGUIHtmlBrowser->SetSize(wxSize(800,1000));
00152     helpsizer->Add (mWxGUIHtmlBrowser,1, wxGROW|wxLEFT|wxRIGHT|wxTOP, 5  );
00153 //    helpsizer->Add ( new wxButton(mwxPageHelp,-1,"perro"), 0,  wxEXPAND  );
00154     wxBitmap bmp_run(cc_run_xpm);
00155     mwxButtonRun = new wxBitmapButton( mwxPageHelp,ID_Button_Run,bmp_run);//_T("Run")  );
00156     helpsizer->Add( mwxButtonRun, 0, wxALL, 5  );
00157 
00158   
00159     //==============
00160     // Command page 
00161     mWxGUIOutputMessages = new WxGUIOutputMessages(mwxPageCommand);
00162 
00163     mWxGUICommand = new WxGUICommand(mwxPageCommand,this);
00164    
00165     mWxGUICommand->SetFocus();
00166 
00167     cmdsizer->Add (mWxGUIOutputMessages, 1, wxALL | wxGROW, 5);
00168     cmdsizer->Add (mWxGUICommand, 0, wxALL | wxGROW, 5);
00169 
00170         
00171     // Set the parent window of all bbtk windows as a child of this
00172     bbtk::Wx::SetTopWindowParent(this);
00173     // Top Window Auto Destroys when no more black box window alive 
00174     // : this is the default 
00175     //    bbtk::Wx::SetAutoDestroyTopWindow(true);
00176     // Add the method OnWxSignal as a Wx::Signal observer 
00177     bbtkAddWxSignalObserver(WxGUIConsole::OnWxSignal);
00178 
00179 
00180     // Layout
00181 //EED    SetSizer(sizer);
00182 
00183     mwxNotebook->AddPage( mwxPageCommand, _T("Command"));
00184     mwxNotebook->AddPage( mwxPageHelp, _T("Help"));
00185     m_mgr.AddPane(mwxNotebook, wxAuiPaneInfo().Name(wxT("notebook_content")).CenterPane().PaneBorder(false)); 
00186     m_mgr.Update();
00187         
00188     SetAutoLayout(true);
00189     Layout();
00190 //    Refresh();
00191 //    m_mgr.Update();
00192   }
00193   //================================================================
00194 
00195  //================================================================
00196   WxGUIConsole::~WxGUIConsole()
00197   {
00198     m_mgr.UnInit();
00199   }
00200   //================================================================
00201 
00202   //================================================================
00203   void WxGUIConsole::OnWxSignal()
00204   {
00205     if ((!Wx::TopWindowExists())&&(!IsShown())) 
00206       {
00207         bbtkDebugMessage("wx",2,"  --> bbtk top window destroyed and WxGUIConsole not shown => destructing"<<std::endl);
00208         Close();
00209       }
00210   }
00211   //================================================================
00212 
00213   //================================================================
00214   void WxGUIConsole::WxGUICommandEnter(const std::string& command)
00215   {
00216     std::string s("> ");
00217     s += command + "\n";
00218     mWxGUIOutputMessages->Print(s,wxRED);
00219 
00220     if (  mInterpreter->InterpretLine( command ) == 
00221           Interpreter::Interpreter_QUIT )
00222       {
00223         Close(true); 
00224       }
00225   }
00226   //================================================================
00227 
00228   //================================================================
00230   bool WxGUIConsole::InterpretFile( const std::string& filename) 
00231   { 
00232     if ( mInterpreter->InterpretFile(filename) ==
00233          Interpreter::Interpreter_ERROR ) 
00234       {
00235         return false;
00236       }
00237     return true;
00238   }
00239   //================================================================
00240  
00241   //================================================================
00242   void WxGUIConsole::OnButtonRun(wxCommandEvent& WXUNUSED(event))
00243   {
00244 //    wxString temp = mWxGUIHtmlBrowser->GetCurrentPage();
00245     std::string filename = mWxGUIHtmlBrowser->GetCurrentPage();//wx2std(temp);
00246     size_t s = filename.length();
00247 
00248     Interpreter::Pointer I = Interpreter::New();
00249     
00250     if ((s>3) && (filename[s-1]=='s')
00251         && (filename[s-2]=='b')
00252         && (filename[s-3]=='b')
00253         && (filename[s-4]=='.'))
00254       {
00255         std::string tmp("Executing ");
00256         tmp += filename;
00257         SetStatusText(std2wx(tmp));
00258         I->InterpretFile(filename);
00259       }
00260     else
00261       {
00262         SetStatusText(_T("The current page is not a bbs file : cannot execute it"));
00263       }
00264 
00265   }
00266   //================================================================  
00267 
00268   //================================================================
00269   void WxGUIConsole::OnMenuQuit(wxCommandEvent& WXUNUSED(event))
00270   {
00271     Close(true);
00272   }
00273   //================================================================
00274 
00275 
00276   //================================================================
00277   void WxGUIConsole::OnMenuAbout(wxCommandEvent& WXUNUSED(event))
00278   {
00279     m_mgr.Update();
00280         Refresh();
00281     wxMessageBox(_T("  bbi\nThe Black Box Toolkit interpreter\n(c) CREATIS-LRMN 2008"),
00282                  _T("About ..."), wxOK | wxICON_INFORMATION,
00283                  this);
00284   }
00285   //================================================================
00286 
00287 
00288   //================================================================
00289   void WxGUIConsole::OnMenuEditConfig(wxCommandEvent& WXUNUSED(event))
00290   {
00291         std::string commandStr;
00292     std::string configFile = ConfigurationFile::GetInstance().Get_config_xml_full_path();
00293 #ifdef WIN32
00294         commandStr = "notepad.exe ";
00295 #else
00296         commandStr = "gedit ";
00297 #endif 
00298         commandStr = commandStr + configFile;
00299         std::cout << "system: " << commandStr << std::endl;
00300         system ( commandStr.c_str() );
00301   }
00302   //================================================================
00303 
00304 
00305   //================================================================
00306   void WxGUIConsole::OnMenuCreatePackage(wxCommandEvent& WXUNUSED(event))
00307   {
00308     std::string command("toolsbbtk/appli/GUICreatePackage");
00309 
00310     bbtkMessage("Debug",1,"Executing : '"<<command<<"'"<<std::endl);
00311     Interpreter::Pointer I = Interpreter::New();    
00312     I->InterpretFile(command);
00313   }
00314   //================================================================
00315 
00316 
00317   //================================================================
00318   void WxGUIConsole::OnMenuCreateBlackBox(wxCommandEvent& WXUNUSED(event))
00319   {
00320     std::string command("toolsbbtk/appli/GUICreateBlackBox");
00321     bbtkMessage("Debug",1,"Executing : '"<<command<<"'"<<std::endl);
00322     Interpreter::Pointer I = Interpreter::New();    
00323     I->InterpretFile(command);
00324   }
00325   //================================================================
00326   
00327   //================================================================
00328   void WxGUIConsole::OnMenuShowImageGraph(wxCommandEvent& WXUNUSED(event))
00329   {
00330     std::string default_temp_dir = ConfigurationFile::GetInstance().Get_default_temp_dir();
00331 
00332 #if defined(WIN32)
00333     std::string strappli="start ";
00334 #else
00335     std::string strappli="gnome-open ";
00336 #endif
00337     std::string strcommand0 = "cd \"" + default_temp_dir+"/temp_dir/" +"\"";
00338     std::string strcommand1 = strappli + "workspace_workspacePrototype.png";
00339     std::string strcommand = strcommand0 + " && " + strcommand1;
00340         std::cout << "system: " << strcommand << std::endl;
00341     system ( strcommand.c_str() );
00342 
00343   }
00344   //================================================================
00345 
00346   //================================================================
00347   void WxGUIConsole::OnMenuShowHTMLDoc(wxCommandEvent& WXUNUSED(event))
00348   {
00349         std::string doc_path            = ConfigurationFile::GetInstance().Get_doc_path();
00350 
00351 #if defined(WIN32)
00352     std::string strappli="start ";
00353 #else
00354     std::string strappli="gnome-open ";
00355 #endif
00356     std::string strcommand0 = "cd \"" + doc_path+"\"";
00357     std::string strcommand1 = strappli + "index.html";
00358     std::string strcommand = strcommand0 + " && " + strcommand1;
00359         std::cout << "system: " << strcommand << std::endl;
00360     system ( strcommand.c_str() );
00361 
00362   }
00363   //================================================================
00364 
00365 
00366 
00367   //================================================================
00368   void WxGUIConsole::OnMenuCreateIndex(wxCommandEvent& WXUNUSED(event))
00369   {
00370 /*
00371     std::string doc_path = ConfigurationFile::GetInstance().Get_doc_path();
00372     std::string filepath = doc_path+"/bbdoc/make-index.bbs";
00373     Interpreter* I = new Interpreter;    
00374     I->InterpretLine( "exec freeze");
00375     I->InterpretLine( "include *");
00376     I->InterpretLine( "help packages");
00377     I->InterpretLine( "index "+doc_path+"/bbdoc/index-alpha.html Initials");
00378     I->InterpretLine( "index "+doc_path+"/bbdoc/index-package.html Packages");
00379     I->InterpretLine( "index "+doc_path+"/bbdoc/index-category.html Categories");
00380     I->InterpretLine( "index "+doc_path+"/bbdoc/index-adaptors.html Adaptors");    
00381     delete I;
00382 */
00383 
00384         std::string bin_path            = ConfigurationFile::GetInstance().Get_bin_path();
00385         std::string doc_path            = ConfigurationFile::GetInstance().Get_doc_path();
00386         std::string bbdoc_path          = doc_path+"/bbdoc";
00387     std::string make_index_path = "\"" + bbdoc_path+"/make-index.bbs\"";
00388 
00389         std::string strcommand0         = "cd "+bbdoc_path+" && mkdir tmp && cd tmp";
00390 
00391         std::string strcommand1         = "cd "+bbdoc_path+"/tmp";
00392     std::string strcommand2             = "\""+bin_path+"/bbi\" -N "+make_index_path;
00393 #ifdef WIN32 
00394     std::string strcommand3             = "move index*.html ../.";
00395 #else
00396     std::string strcommand3             = "mv index*.html ../.";
00397 #endif
00398 
00399         std::string strcommand          =       strcommand1 +" && "+
00400                                                                         strcommand2 +" && "+
00401                                                                         strcommand3;
00402 
00403         std::cout << "system: " << strcommand0 << std::endl;
00404         std::cout << "system: " << strcommand << std::endl;
00405 
00406         system ( strcommand0.c_str() );
00407         system ( strcommand.c_str() );
00408   }
00409   //================================================================
00410 
00411 
00412   //================================================================
00413   void WxGUIConsole::InterpreterUserViewHtmlPage(const std::string& page)
00414   {
00415     std::string s(page);
00416     //  std::cout << "WxGUIConsole::ShowHtmlPage('"<<page<<"')"<<std::endl;
00417     if (mWxGUIHtmlBrowser->GoTo(s)) 
00418       {
00419 //EED   mwxNotebook->ChangeSelection(1);
00420         mwxNotebook->SetSelection(1);
00421       }
00422     else 
00423       {
00424          // std::cout << "ERROR html"<<std::endl;
00425       }
00426   } 
00427   //================================================================  
00428   
00429   //================================================================  
00430   // Overloaded Show method to handle bbtk::Wx::TopWindow auto-destruction
00431   bool WxGUIConsole::Show(bool show)
00432   {
00433     bbtk::Wx::SetAutoDestroyTopWindow(!show);
00434     return wxFrame::Show(show);
00435   }
00436   //================================================================  
00437    
00438   //================================================================  
00439   BEGIN_EVENT_TABLE(WxGUIConsole, wxFrame)
00440     EVT_MENU(ID_Menu_Quit                       , WxGUIConsole::OnMenuQuit)
00441     EVT_MENU(ID_Menu_About                      , WxGUIConsole::OnMenuAbout)
00442     EVT_MENU(ID_Menu_EditConfig         , WxGUIConsole::OnMenuEditConfig)
00443     EVT_MENU(ID_Menu_CreatePackage      , WxGUIConsole::OnMenuCreatePackage)
00444     EVT_MENU(ID_Menu_CreateBlackBox     , WxGUIConsole::OnMenuCreateBlackBox)
00445     EVT_MENU(ID_Menu_ShowImageGraph     , WxGUIConsole::OnMenuShowImageGraph)
00446     EVT_MENU(ID_Menu_ShowHTMLDoc        , WxGUIConsole::OnMenuShowHTMLDoc)
00447     EVT_MENU(ID_Menu_CreateIndex        , WxGUIConsole::OnMenuCreateIndex)
00448     EVT_BUTTON(ID_Button_Run            , WxGUIConsole::OnButtonRun )
00449     END_EVENT_TABLE()
00450   //================================================================
00451 
00452 } // namespace bbtk
00453 
00454 
00455 #endif //_USE_WXWIDGETS_

Generated on Wed Nov 12 11:37:08 2008 for BBTK by  doxygen 1.5.6