]> Creatis software - bbtk.git/blob - kernel/src/bbtkWxGUIScriptingInterface.cxx
4c4854574e473fc8a168724975f6bb4f5ad729b4
[bbtk.git] / kernel / src / bbtkWxGUIScriptingInterface.cxx
1 /*=========================================================================                                                                               
2   Program:   bbtk
3   Module:    $RCSfile: bbtkWxGUIScriptingInterface.cxx,v $
4   Language:  C++
5   Date:      $Date: 2011/03/21 11:18:00 $
6   Version:   $Revision: 1.45 $
7 =========================================================================*/
8
9 /* ---------------------------------------------------------------------
10
11 * Copyright (c) CREATIS-LRMN (Centre de Recherche en Imagerie Medicale)
12 * Authors : Eduardo Davila, Laurent Guigues, Jean-Pierre Roux
13 *
14 *  This software is governed by the CeCILL-B license under French law and 
15 *  abiding by the rules of distribution of free software. You can  use, 
16 *  modify and/ or redistribute the software under the terms of the CeCILL-B 
17 *  license as circulated by CEA, CNRS and INRIA at the following URL 
18 *  http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html 
19 *  or in the file LICENSE.txt.
20 *
21 *  As a counterpart to the access to the source code and  rights to copy,
22 *  modify and redistribute granted by the license, users are provided only
23 *  with a limited warranty  and the software's author,  the holder of the
24 *  economic rights,  and the successive licensors  have only  limited
25 *  liability. 
26 *
27 *  The fact that you are presently reading this means that you have had
28 *  knowledge of the CeCILL-B license and that you accept its terms.
29 * ------------------------------------------------------------------------ */                                                                         
30    
31
32 /**
33  * \brief Short description in one line
34  * 
35  * Long description which 
36  * can span multiple lines
37  */
38 /**
39  * \file 
40  * \brief 
41  */
42 /**
43  * \class bbtk::
44  * \brief 
45  */
46
47
48 #ifdef _USE_WXWIDGETS_
49
50 #include <iostream>     
51 #include "bbtkWxGUIScriptingInterface.h"
52 #include "bbtkWxBlackBox.h"
53 #include "bbtkConfigurationFile.h"
54 #include "bbtkWxStreamRedirector.h"
55 #include "bbtkUtilities.h"
56
57 #include <wx/tipwin.h>
58 #include <wx/splash.h>
59
60
61 //#include "icons/cc_run.xpm"
62
63 namespace bbtk
64 {
65
66     enum
67     {
68       ID_Menu_Quit = 1,
69       ID_Menu_About,
70       ID_Menu_EditConfig,
71       ID_Menu_CreatePackage,
72       ID_Menu_CreateBlackBox,
73       ID_Menu_ShowImageGraph,
74       ID_Menu_RegeneratePackageDoc,
75       ID_Menu_RegenerateBoxesLists,
76       ID_Menu_RegenerateAll,
77       ID_Menu_PlugPackage,
78       ID_Menu_Windows_Files,
79       ID_Menu_Windows_Help,
80       ID_Menu_Windows_Messages,
81       ID_Menu_Windows_Command,
82       ID_Menu_Windows_Save,
83       ID_Menu_Windows_PackageBrowser
84       //      ID_Button_Run
85     };
86     
87   
88   //================================================================
89   WxGUIScriptingInterface::WxGUIScriptingInterface( wxWindow *parent )
90     : wxFrame((wxFrame *)parent, -1, _T("bbStudio"), 
91               wxDefaultPosition, wxSize(1200,800) )
92   {     
93     m_mgr.SetManagedWindow(this);
94     
95     mInterpreter = bbtk::Interpreter::New();
96     mInterpreter->SetUser(this);
97         mInterpreter->SetCommandLine(true);
98     mInterpreter->SetThrow(true);
99     //    mInterpreter->AddBreakObserver
100     //boost::bind( &WxGUIScriptingInterface::InterpreterUserOnBreak, this ));
101     //==============
102     // Menu
103     wxInitAllImageHandlers();
104     
105     wxMenu *menuFile = new wxMenu;
106     menuFile->Append( ID_Menu_EditConfig, _T("Open bbtk &Config file") );
107     menuFile->Append( ID_Menu_Quit, _T("&Quit") );
108     
109     wxMenu *menuAbout = new wxMenu;
110     menuAbout->Append( ID_Menu_About, _T("&About...") );
111
112     wxMenu *menuTools = new wxMenu;
113     menuTools->Append( ID_Menu_CreatePackage,  _T("Create &package") );
114     menuTools->Append( ID_Menu_CreateBlackBox, _T("Create &black box") );
115     menuTools->Append( ID_Menu_PlugPackage,    _T("&Plug package") );
116     menuTools->AppendSeparator();
117     menuTools->Append( ID_Menu_RegeneratePackageDoc,_T("Regenerate package &doc") );
118     menuTools->Append( ID_Menu_RegenerateBoxesLists,_T("Regenerate boxes &lists") );
119     menuTools->Append( ID_Menu_RegenerateAll,       _T("Regenerate &all") );
120     menuTools->AppendSeparator();
121     menuTools->Append( ID_Menu_ShowImageGraph, _T("&Show last graph") );
122
123     wxMenu *menuWindows = new wxMenu;
124     menuWindows->AppendCheckItem(ID_Menu_Windows_Files,
125                                  _T("Show 'files' panel") )->Check();
126     menuWindows->AppendCheckItem(ID_Menu_Windows_Help,
127                                  _T("Show 'help' panel") )->Check();
128     menuWindows->AppendCheckItem(ID_Menu_Windows_Messages,
129                                  _T("Show 'messages' panel") )->Check();
130     menuWindows->AppendCheckItem(ID_Menu_Windows_Command,
131                                  _T("Show 'command' panel") )->Check();
132     menuWindows->AppendSeparator();
133     menuWindows->Append( ID_Menu_Windows_PackageBrowser, _T("Start Package &Browser") );
134     
135     //    menuWindows->AppendSeparator();
136     //    menuWindows->Append ( ID_Menu_Windows_Save, _T("Save interface configuration"));
137
138     wxMenu *menuOptions = new wxMenu;
139     mwxMenuItemReset = menuOptions->AppendCheckItem(-1,
140                                                     _T("Reset before running") );
141     mwxMenuItemReset->Check();
142
143     wxMenuBar *menuBar = new wxMenuBar;
144     menuBar->Append( menuFile, _T("&File") );
145     menuBar->Append( menuTools, _T("&Tools") );
146     menuBar->Append( menuOptions, _T("&Options") );
147     menuBar->Append( menuWindows, _T("&Windows") );
148     menuBar->Append( menuAbout, _T("About") );
149     
150     SetMenuBar( menuBar );
151     
152     //=== 
153     // Status bar
154     CreateStatusBar();
155     SetStatusText( _T("Welcome to bbStudio !") );
156     
157     //===
158     // Panes (Files, Messages, Help, Command)
159     mWxGUITextEditor = new WxGUITextEditor(this,this);
160     mWxGUITextEditor->SetFileNameFilter("*.bbs");
161         
162     mWxGUIHtmlBrowser = new WxGUIHtmlBrowser(this,wxSize(200,0),this);
163
164     mWxGUIOutputMessages = new WxGUIOutputMessages(this);
165
166     mWxGUICommand = new WxGUICommand(this,this);
167    
168     mWxGUICommand->SetFocus();
169
170  
171 #if NOTEBOOK
172
173     mwxNotebook = new wxAuiNotebook(this,  
174                                     -1,
175                                     wxPoint(0, 0),
176                                     wxSize(500,500),
177                                     wxAUI_NB_TAB_SPLIT 
178                                     | wxAUI_NB_TAB_MOVE
179                                     | wxAUI_NB_TAB_EXTERNAL_MOVE
180                                     //| wxAUI_NB_WINDOWLIST_BUTTON
181                                     //|wxAUI_NB_SCROLL_BUTTONS
182                                     // | wxAUI_NB_CLOSE_BUTTON 
183                                     //| wxAUI_NB_CLOSE_ON_ACTIVE_TAB
184                                     //| wxAUI_NB_CLOSE_ON_ALL_TABS
185                                     | wxNO_BORDER);
186   
187
188     mwxNotebook->AddPage(mWxGUITextEditor,_T("Files"),true);
189     mwxNotebook->AddPage(mWxGUIHtmlBrowser,_T("Help"),true);
190
191     mwxNotebook->AddPage(mWxGUIOutputMessages,_T("Messages"),true);
192
193     mwxNotebook->AddPage(mWxGUICommand,_T("Command"),true);
194
195
196     m_mgr.AddPane(mwxNotebook,
197                   wxAuiPaneInfo().Name(wxT("nb"))
198                   .CaptionVisible(false)
199                   .MinimizeButton(false)
200                   .MaximizeButton(false)
201                   .Center()
202                   //              .MinSize(wxSize(100,100))
203                   );   
204 #else 
205
206     //
207     m_mgr.AddPane(mWxGUITextEditor,
208                   wxAuiPaneInfo().Name(wxT("editor_content"))
209                   .Caption(wxT("Files"))
210                   .MinimizeButton(true)
211                   .MaximizeButton(true)
212                   .Center()
213                   .MinSize(wxSize(100,100))
214                   );   
215   
216     m_mgr.AddPane(mWxGUIHtmlBrowser,
217                   wxAuiPaneInfo().Name(wxT("browser_content"))
218                   .Caption(wxT("Help"))
219                   .MinimizeButton(true)
220                   .MaximizeButton(true)
221                   .Right()
222                   .Layer(2)
223                   .MinSize(wxSize(400,100))
224                   );
225
226     m_mgr.AddPane(mWxGUIOutputMessages,
227                   wxAuiPaneInfo().Name(wxT("messages_content"))
228                   .Caption(wxT("Messages"))
229                   .MinimizeButton(true)
230                   .MaximizeButton(true)
231                   .Bottom()
232                   .MinSize(wxSize(100,100))
233                   );
234           
235     m_mgr.AddPane(mWxGUICommand,
236                   wxAuiPaneInfo().Name(wxT("command_content"))
237                   .Caption(wxT("Command"))
238                   .MinimizeButton(true)
239                   .MaximizeButton(true)
240                   .Bottom()
241                   .Layer(1)
242                   .MinSize(wxSize(100,100))
243                   );     
244 #endif
245
246     // parent window of all bbtk windows will be a child of this
247     //    Wx::SetTopWindowParent(this);
248     Wx::SetTopWindow(this);
249     // Wx::SetAutoDestroyTopWindow(false);
250   // Add the method OnWxSignal as a Wx::Signal observer 
251     //bbtkAddWxSignalObserver(WxGUIPackageBrowser2Window::OnWxSignal);
252
253     //.PaneBorder(false)); 
254     // Load the interface appearance saved on last closing
255     LoadPerspective();
256
257     // Done in LoadPerspective
258     //    m_mgr.Update();
259         
260     SetAutoLayout(true);
261     Layout();
262     //    mwxNotebook->SetSelection(1);
263     mWxGUIHtmlBrowser->GoHome();
264 //    Refresh();
265     m_mgr.Update();
266     //   LoadPerspective();
267
268     mBreaked = false;   
269
270     wxBitmap bitmap;   
271     wxSplashScreen* splash;
272     long style = wxSPLASH_CENTRE_ON_SCREEN | wxSPLASH_TIMEOUT;
273     if (ConfigurationFile::GetInstance().DotBbtkIsNew())
274       style = wxSPLASH_CENTRE_ON_SCREEN | wxSPLASH_NO_TIMEOUT;
275     std::string splash_file = ConfigurationFile::GetInstance().Get_data_path();
276     splash_file += "/kernel/icons/bbStudioSplashScreen.png";
277
278     if (bitmap.LoadFile(std2wx(splash_file),wxBITMAP_TYPE_PNG))
279       splash = 
280         new wxSplashScreen(bitmap,
281                            style,
282                            1000, 0, -1, wxDefaultPosition, wxDefaultSize,
283                            wxSIMPLE_BORDER|wxSTAY_ON_TOP);
284
285     if (ConfigurationFile::GetInstance().DotBbtkIsNew())
286       {
287
288         DoRegeneratePackageDoc("-a");   
289         DoRegenerateBoxesLists();
290
291         /*
292         wxTipWindow* tip = new wxTipWindow(this,
293                                            _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);
294         tip->CenterOnParent();
295         tip->Show();
296         */
297         if (splash) splash->Destroy();
298       }
299
300   }
301   //================================================================
302
303  //================================================================
304   WxGUIScriptingInterface::~WxGUIScriptingInterface()
305   {
306   bbtkDebugMessage("widget",9,"bbStudio::~bbStudio()"<<std::endl);
307     SavePerspective();
308     m_mgr.UnInit();
309   }
310   //================================================================
311
312   //================================================================
313   void WxGUIScriptingInterface::OnClose(wxCloseEvent& event)
314   {
315     bbtkDebugMessage("widget",9,"bbStudio::OnClose()"<<std::endl);
316     //Wx::SetWindowsHaveBeenDestroyedByParent();
317     //mInterpreter.reset();
318     wxWindowList& list = GetChildren();
319     wxWindowList::iterator iter;
320     for (iter = list.begin(); iter != list.end(); ++iter)
321       {
322         (*iter)->Close();
323       }
324     this->Destroy();
325   }
326   //================================================================
327
328
329   //================================================================
330   void WxGUIScriptingInterface::Open(const std::string& filename)
331   {
332     mWxGUITextEditor->Open(filename);
333   }
334   //================================================================
335   /*
336   catch (BreakException e)                                              \
337     {                                                                   \
338       std::cout << "* BREAK"<<std::endl;                                \
339       if (e.IsInScriptFile())                                           \
340         std::cout << "* FILE   : '"<<e.GetScriptFile()<<"'"<<std::endl; \
341       std::cout << "* LINE   : "<<e.GetScriptLine()<<std::endl;         \
342     }                                                                   \
343   catch (QuitException e)                                               \
344     {                                                                   \
345       std::cout << "* QUIT"<<std::endl;                                 \
346       if (e.IsInScriptFile())                                           \
347         std::cout << "* FILE   : '"<<e.GetScriptFile()<<"'"<<std::endl; \
348       std::cout << "* LINE   : "<<e.GetScriptLine()<<std::endl;         \
349     }                                                                   \
350 */
351   
352 #define CATCH_MACRO                                                     \
353   catch (InterpreterException e)                                        \
354     {                                                                   \
355       if (e.GetErrorMessage()=="quit")                                  \
356         {                                                               \
357           std::cerr << "* QUIT ENCOUNTERED"<<std::endl;                 \
358           if (e.IsInScriptFile())                                       \
359             std::cerr << "* FILE   : '"<<e.GetScriptFile()<<"'"<<std::endl; \
360           std::cerr << "* LINE   : "<<e.GetScriptLine()<<std::endl;     \
361         }                                                               \
362       else if (e.GetErrorMessage()=="break")                            \
363         {                                                               \
364           mBreaked = true;                                              \
365           std::cerr << "* BREAK"<<std::endl;                            \
366           if (e.IsInScriptFile())                                       \
367             std::cerr << "* FILE   : '"<<e.GetScriptFile()<<"'"<<std::endl; \
368           std::cerr << "* LINE   : "<<e.GetScriptLine()<<std::endl;     \
369         }                                                               \
370       else                                                              \
371         {                                                               \
372           std::cerr << "* ERROR : "<<e.GetErrorMessage()<<std::endl;    \
373           if (e.IsInScriptFile())                                       \
374             std::cerr << "* FILE   : '"<<e.GetScriptFile()<<"'"<<std::endl; \
375           std::cerr << "* LINE   : "<<e.GetScriptLine()<<std::endl;     \
376           int lev = bbtk::MessageManager::GetMessageLevel("Error");     \
377           if (lev > 0) {                                                \
378             std::cerr << "* Exception thrown : "<<std::endl;            \
379             std::cerr << "*  OBJECT : " <<e.GetObject()<<std::endl;     \
380             std::cerr << "*  FILE   : " <<e.GetSourceFile()<<std::endl; \
381           }                                                             \
382         }                                                               \
383     }
384   
385   //================================================================
386   void WxGUIScriptingInterface::WxGUICommandEnter(const std::string& command)
387   {
388     std::string s("> ");
389     s += command + "\n";
390     mWxGUIOutputMessages->Print(s,wxRED);
391     
392     try
393       {
394         mInterpreter->InterpretLine( command );
395       }
396     CATCH_MACRO;
397   }
398   //================================================================
399   
400   //================================================================
401   /// Runs the interpretation of a file
402   bool WxGUIScriptingInterface::InterpretFile( const std::string& filename) 
403   { 
404     try
405       {
406         mInterpreter->InterpretFile(filename);
407       }
408     CATCH_MACRO;
409     return true;
410   }
411   //================================================================
412  
413         
414   //================================================================
415         void WxGUIScriptingInterface::WxGUITextEditorGraphSimple()
416         {
417                 WxGUICommandEnter("exec freeze_no_error");
418                 WxGUITextEditorRun();
419                 WxGUICommandEnter("exec unfreeze");
420                 WxGUICommandEnter("graph");
421         }
422   //================================================================
423         
424         //================================================================
425         void WxGUIScriptingInterface::WxGUITextEditorGraphDetail()
426         {
427                 WxGUICommandEnter("exec freeze_no_error");
428                 WxGUITextEditorRun();
429                 WxGUICommandEnter("exec unfreeze");
430                 WxGUICommandEnter("graph . 1");
431         }
432         //================================================================
433
434         
435         //================================================================
436         void WxGUIScriptingInterface::WxGUITextEditorRunBBI()
437         {
438           std::string separator = ConfigurationFile::GetInstance().Get_file_separator ();
439           std::string dir = ConfigurationFile::GetInstance().Get_default_temp_dir();
440           std::string filename = dir + separator + "tmp_bbtk.bbs";
441           mWxGUITextEditor->GetCurrentPage()->SaveFile(filename);
442         
443         std::string command = "\"";
444
445 #ifdef WIN32
446         command += "\"";
447 #endif
448
449           command += ConfigurationFile::GetInstance().Get_bin_path();
450 #ifdef MACOSX
451           command += separator + "bbi.app/Contents/MacOS/bbi\" ";
452 #else 
453           command += separator + "bbi\" ";
454 #endif
455           command += "\""+filename + "\"";
456
457 #ifdef WIN32
458         command += "\"";
459 #endif
460
461           command += " & ";
462           
463           printf ("EED WxGUIScriptingInterface::WxGUITextEditorRunBBI %s \n" , command.c_str() );
464           system( command.c_str() );
465         }
466         //================================================================
467         
468         
469   //================================================================
470   void WxGUIScriptingInterface::WxGUITextEditorRun()
471   {
472     //    wxString temp = mWxGUIHtmlBrowser->GetCurrentPage();
473     std::stringstream* buf = new std::stringstream;
474     (*buf) << mWxGUITextEditor->GetCurrentPage()->GetText();
475     try 
476       {
477         if (!mBreaked)
478           {
479             if (mwxMenuItemReset->IsChecked()) WxGUICommandEnter("reset");
480             mInterpreter->InterpretBuffer(buf);
481           }
482         else 
483           {
484             mBreaked = false;
485             mInterpreter->InterpretCurrentStreams();
486           }
487         //      std::cout << "EO RUN"<<std::endl;
488       }
489     CATCH_MACRO;
490     //    std::cout << "EO RUN 3"<<std::endl;
491   }
492   //================================================================  
493
494   //================================================================
495   void WxGUIScriptingInterface::OnMenuQuit(wxCommandEvent& WXUNUSED(event))
496   {
497     if (!mWxGUITextEditor->CloseAllPages()) return;
498     Close(true);
499   }
500   //================================================================
501
502
503   //================================================================
504   void WxGUIScriptingInterface::OnMenuAbout(wxCommandEvent& WXUNUSED(event))
505   {
506     m_mgr.Update();
507     Refresh();
508     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"),
509                  _T("About ..."), wxOK | wxICON_INFORMATION,
510                  this);
511   }
512   //================================================================
513
514
515   //================================================================
516   void WxGUIScriptingInterface::OnMenuEditConfig(wxCommandEvent& WXUNUSED(event))
517   {
518
519     std::string configFile = 
520       ConfigurationFile::GetInstance().Get_config_xml_full_path();
521     Open(configFile);
522         wxMessageDialog ww(NULL,_T("If you change the bbtk_config.xml, you have to restart this appliaction..."), _T("Alert !"), wxOK);
523         ww.ShowModal();
524   }
525   //================================================================
526
527   //================================================================
528   void WxGUIScriptingInterface::OnMenuWindowsPackageBrowser(wxCommandEvent& WXUNUSED(event))
529   {
530     wxBusyCursor wait;
531     WxGUIPackageBrowser2Window *helpbrowser = new
532       WxGUIPackageBrowser2Window(this,_T("Package Browser"), wxSize(600,600) );
533     helpbrowser->Show();
534     
535     /*
536     wxBusyCursor wait;
537     WxGUIPackageBrowser2 *browser = new WxGUIPackageBrowser2(this);
538     browser->IncludeAll();
539     */
540 #if NOTEBOOK
541     //     mwxNotebook->AddPage(browser,_T("Package Browser"),true);
542 #else
543      /*
544      m_mgr.AddPane(browser,
545                    wxAuiPaneInfo().Name(wxT("package_brower"))
546                    .Caption(wxT("Package browser"))
547                    .MinimizeButton(true)
548                    .MaximizeButton(true)
549                    .Bottom()
550                    .Position(1)
551                    .MinSize(wxSize(100,100))
552                    );     
553      */
554 #endif
555   }
556   //================================================================
557
558
559
560   //================================================================
561   void WxGUIScriptingInterface::OnMenuCreatePackage(wxCommandEvent& WXUNUSED(event))
562   {
563 /*
564     std::string command("toolsbbtk/appli/GUICreatePackage");
565     bbtkMessage("Debug",1,"Executing : '"<<command<<"'"<<std::endl);
566   
567         Interpreter::Pointer I = Interpreter::New();    
568     I->InterpretFile(command);
569 */
570     std::string command("reset");
571         mWxGUICommand->SendCommand(command);
572     command = "include toolsbbtk/appli/GUICreatePackage";
573     bbtkMessage("Debug",1,"Executing : '"<<command<<"'"<<std::endl);
574         mWxGUICommand->SendCommand(command);
575   }
576   //================================================================
577
578
579   //================================================================
580   void WxGUIScriptingInterface::OnMenuCreateBlackBox(wxCommandEvent& WXUNUSED(event))
581   {
582           /*
583     std::string command("toolsbbtk/appli/GUICreateBlackBox");
584     bbtkMessage("Debug",1,"Executing : '"<<command<<"'"<<std::endl);
585     
586     Interpreter::Pointer I = Interpreter::New();    
587     I->InterpretFile(command);
588 */
589     std::string command("reset");
590         mWxGUICommand->SendCommand(command);
591     command = "include toolsbbtk/appli/GUICreateBlackBox";
592     bbtkMessage("Debug",1,"Executing : '"<<command<<"'"<<std::endl);
593         mWxGUICommand->SendCommand(command);
594   }
595   //================================================================
596   
597   //================================================================
598   void WxGUIScriptingInterface::OnMenuShowImageGraph(wxCommandEvent& WXUNUSED(event))
599   {
600
601       std::string doc_path = bbtk::ConfigurationFile::GetInstance().Get_doc_path();
602       doc_path += bbtk::ConfigurationFile::GetInstance().Get_file_separator();
603       doc_path += "bbdoc";
604       doc_path += bbtk::ConfigurationFile::GetInstance().Get_file_separator();
605           
606           std::string pack_name("User");
607           std::string pack_path = doc_path + pack_name;   
608           
609 #if defined(WIN32)
610     std::string strappli="start ";
611 #else
612   #if defined(MACOSX)
613       std::string strappli="open ";
614   #else
615       std::string strappli="gnome-open ";         
616   #endif
617 #endif    
618           std::string strcommand = strappli +pack_path+"/workspace_workspacePrototype.png";
619     //  std::cout << "system: " << strcommand << std::endl;
620     system ( strcommand.c_str() );
621
622   }
623   //================================================================
624
625   void WxGUIScriptingInterface::DoRegeneratePackageDoc( const std::string& pack )
626   {
627     std::string mess("Regenerating doc for package '");
628     if (pack!="-a") 
629       mess += pack + "'";
630     else 
631       mess = "Regenerating doc for all packages";
632     mess += " ... please wait";
633
634     SetStatusText( std2wx(mess) );
635
636     BBTK_BUSY_CURSOR;
637
638     std::string command;
639 #if defined(WIN32)
640     command = "\"";
641 #endif
642     command += ConfigurationFile::GetInstance().Get_bin_path();
643     command += ConfigurationFile::GetInstance().Get_file_separator();
644     command += "bbRegeneratePackageDoc";
645 #if defined(WIN32)
646         command += "\"";
647 #endif
648         command += " " + pack + " -q";
649     bbtkMessage("debug",1,"Executing system command '"<<command<<"'"<<std::endl);
650
651
652     if ( ! system ( command.c_str() ) )
653       {
654         SetStatusText( _T("Done !"));
655         /*
656         wxMessageBox(_T("Done !"),_T("Regenerate package '")
657                      +std2wx(pack)+_T("' doc"),
658                      wxOK | wxICON_INFORMATION);
659         */
660       }
661     else 
662       {
663         SetStatusText( _T("Done !"));
664         wxString err(_T("An error occured while running '"));
665         err +=  bbtk::std2wx(command) + _T("'");
666         wxMessageBox(err,_T("Regenerate package doc"),wxOK | wxICON_ERROR);      
667       }
668   }
669
670
671   //================================================================
672   void WxGUIScriptingInterface::OnMenuRegeneratePackageDoc(wxCommandEvent& WXUNUSED(event))
673   {
674     wxString name = wxGetTextFromUser(_T("Enter package name (-a for all)"),
675                                       _T("Regenerate package doc"),
676                                       _T(""));
677     if (name.IsEmpty()) return;
678     std::string pack = bbtk::wx2std(name);
679     
680         DoRegeneratePackageDoc(pack);
681   }
682   //================================================================
683
684
685   //================================================================
686   void WxGUIScriptingInterface::DoRegenerateBoxesLists()
687   {
688     SetStatusText( _T("Regenerating boxes lists ... please wait") );
689     BBTK_BUSY_CURSOR ;
690
691     std::string command;
692 #if defined(WIN32)
693         command = "\"";
694 #endif
695     command += ConfigurationFile::GetInstance().Get_bin_path();
696     command += ConfigurationFile::GetInstance().Get_file_separator();
697     command += "bbRegenerateBoxesLists";
698 #if defined(WIN32)
699         command += "\"";
700 #endif
701         command += " -q";
702         bbtkMessage("debug",1,"Executing system command '"<<command<<"'"<<std::endl);
703
704 std::cout << "==========================================================================================================" << command.c_str() << std::endl;
705     if ( ! system ( command.c_str() ) )
706       {
707         SetStatusText( _T("Done !"));
708         /*
709         wxMessageBox(_T("Done !"),_T("Regenerate boxes lists"),
710                      wxOK | wxICON_INFORMATION);
711         */
712       }
713     else 
714       {
715         SetStatusText( _T("Done !"));
716         wxString err(_T("An error occured while running '"));
717         err +=  bbtk::std2wx(command) + _T("'");
718         wxMessageBox(err,_T("Regenerate boxes lists"),wxOK | wxICON_ERROR);      
719       }
720   }
721   //================================================================
722
723
724   //================================================================
725   void WxGUIScriptingInterface::OnMenuRegenerateBoxesLists(wxCommandEvent& WXUNUSED(event))
726   {
727         DoRegenerateBoxesLists();
728   }
729   //================================================================
730
731   //================================================================
732   void WxGUIScriptingInterface::OnMenuRegenerateAll(wxCommandEvent& WXUNUSED(event))
733   {
734         
735     DoRegeneratePackageDoc("-a");       
736         DoRegenerateBoxesLists();
737   }
738   //================================================================
739
740  
741   //================================================================
742   void WxGUIScriptingInterface::OnMenuPlugPackage(wxCommandEvent& WXUNUSED(event))
743   {
744     long style = wxDD_DEFAULT_STYLE | wxDD_DIR_MUST_EXIST;
745     wxDirDialog* FD = 
746       new wxDirDialog( 0, 
747                        _T("Select package directory"),
748                        _T(""),
749                        style);
750     
751     if (FD->ShowModal()==wxID_OK)
752       {
753         std::string path = wx2std (FD->GetPath()) ;
754         std::string fname = path + "/bbtkPackage"; 
755         if ( ! Utilities::FileExists( fname ) )
756           {
757             wxString err(_T("The directory does not contain a 'bbtkPackage' file"));
758             wxMessageBox(err,_T("Plug package"),wxOK | wxICON_ERROR);      
759             return;
760           }
761         
762         std::ifstream f;
763         f.open(fname.c_str());
764         std::string pname;
765         f >> pname;
766         f.close();
767         
768         bbtk::ConfigurationFile::GetInstance().AddPackagePathsAndWrite( path );
769         
770         DoRegeneratePackageDoc(pname);
771         DoRegenerateBoxesLists();
772       } 
773   }
774   //================================================================
775
776   //================================================================
777   void WxGUIScriptingInterface::InterpreterUserViewHtmlPage(const std::string& page)
778   {
779     std::string s(page);
780     //  std::cout << "WxGUIScriptingInterface::ShowHtmlPage('"<<page<<"')"<<std::endl;
781     if (mWxGUIHtmlBrowser->GoTo(s)) 
782       {
783 //EED   mwxNotebook->ChangeSelection(1);
784 //      mwxNotebook->SetSelection(1);
785       }
786     else 
787       {
788          // std::cout << "ERROR html"<<std::endl;
789       }
790   } 
791   //================================================================  
792   
793   /*
794   //================================================================
795   void WxGUIScriptingInterface::InterpreterUserOnBreak()
796   {
797     //    std::cout << "Break" << std::endl;
798     
799   }
800   //================================================================
801   */
802
803   //================================================================  
804   bool WxGUIScriptingInterface::WxGUIHtmlBrowserUserOnLinkClicked(const std::string& target)
805   {
806     size_t s = target.length();
807     if ((s>3) && (target[s-1]=='s')
808               && (target[s-2]=='b')
809               && (target[s-3]=='b')
810               && (target[s-4]=='.'))
811         {
812                         mWxGUITextEditor->Open(target);
813                         #if NOTEBOOK
814                                 mwxNotebook->SetSelection(0);
815                         #endif
816                         mWxGUITextEditor->SetFocus();
817                         return false;
818         }
819
820         if ((s>3) && (target[s-1]=='f')
821                   && (target[s-2]=='d')
822                   && (target[s-3]=='p')
823                   && (target[s-4]=='.'))
824         {
825
826                 // Open pdf in linux
827                   // gnome-open target
828
829                 // Open pdf in macOS
830
831                 // Open pdf in windows
832                         int size=target.size();
833                         int pos=target.rfind("\\");
834                         std::string commandStart("start ");
835                         std::string commandPath("/D \""+target.substr(0,pos) +"\"");
836                         std::string commandPDF( target.substr(pos+1,size-pos+1) );
837
838                         printf("EED WxGUIScriptingInterface::WxGUIHtmlBrowserUserOnLinkClicked cc %s \n",commandPath.c_str() );
839                         // cleanning path
840                         while (commandPath.rfind("\\\\")!=-1 )
841                         {
842                                 commandPath.erase( commandPath.rfind("\\\\") , 1 );
843                         printf("EED WxGUIScriptingInterface::WxGUIHtmlBrowserUserOnLinkClicked cc %s \n",commandPath.c_str() );
844                         }
845
846                         std::string command = commandStart+commandPath+" "+commandPDF;
847                         printf("EED WxGUIScriptingInterface::WxGUIHtmlBrowserUserOnLinkClicked BB %s \n",command.c_str() );
848                         system( command.c_str() );
849                         return false;
850      }
851     return true;
852   }
853   //================================================================  
854
855   void WxGUIScriptingInterface::OnMenuWindowsCheck( wxCommandEvent& event, 
856                                                     wxWindow* w)
857   {
858     bool checked = event.IsChecked();
859     bool shown = m_mgr.GetPane(w).IsShown();
860     //    std::cout << "checked = "<<checked<<" - shown = "<<shown<<std::endl;
861     if (checked ^ shown) 
862       {
863         m_mgr.GetPane(w).Show(checked);
864         m_mgr.Update();
865       }
866   }
867
868   //================================================================  
869   void WxGUIScriptingInterface::OnMenuWindowsFiles(wxCommandEvent& event)
870   {
871     OnMenuWindowsCheck(event,mWxGUITextEditor);
872   }
873   //================================================================  
874
875   //================================================================  
876   void  WxGUIScriptingInterface::OnMenuWindowsHelp(wxCommandEvent& event)
877   {
878     OnMenuWindowsCheck(event,mWxGUIHtmlBrowser);
879   }
880   //================================================================  
881
882   //================================================================  
883   void  WxGUIScriptingInterface::OnMenuWindowsMessages(wxCommandEvent& event)
884   {
885     OnMenuWindowsCheck(event,mWxGUIOutputMessages);
886   }
887   //================================================================  
888
889   //================================================================  
890   void  WxGUIScriptingInterface::OnMenuWindowsCommand(wxCommandEvent& event)
891   {
892     OnMenuWindowsCheck(event,mWxGUICommand);
893   }
894   //================================================================  
895
896   //================================================================  
897   void WxGUIScriptingInterface::OnMenuWindowsSave( wxCommandEvent& WXUNUSED(event))
898   {
899     SavePerspective();
900   }
901   //================================================================  
902
903   //================================================================  
904   void WxGUIScriptingInterface::SavePerspective()
905   {
906     //    std::cout  << "Saving configuration..."<<std::endl;
907     std::string conf = wx2std(m_mgr.SavePerspective());
908     std::string fname = Utilities::MakeUserSettingsFullFileName("bbStudio.aui");
909     std::ofstream f;
910     f.open(fname.c_str(), std::ios::out );
911     f << conf << std::endl;
912
913     //    int x,y;
914     //    GetPosition(&x,&y);
915     //    f << x << "  " << y << std::endl;
916
917
918     int w,h;
919     GetSize(&w,&h);
920
921     f << w << " " << h << std::endl;
922
923     f.close();
924   }
925   //================================================================  
926
927   //================================================================  
928   void WxGUIScriptingInterface::LoadPerspective()
929   {
930     std::string fname = 
931       Utilities::MakeUserSettingsFullFileName("bbStudio.aui");
932     if ( Utilities::FileExists( fname ))
933       {
934         //      std::cout  << "Loading configuration..."<<std::endl;
935
936         std::ifstream f;
937         f.open(fname.c_str());
938         std::string conf;
939         f >> conf;
940
941         //      int x,y;
942         //      f >> x >> y ;
943
944         int w,h;
945         f >> w >> h ;
946
947         f.close();
948         
949         //      std::cout << conf << std::endl;
950
951         //      Move(x,y);
952         SetSize(w,h);
953         m_mgr.LoadPerspective(std2wx(conf));
954       }
955     else 
956       {
957         m_mgr.Update();
958       }
959   }
960   //================================================================  
961
962   //================================================================  
963   void WxGUIScriptingInterface::OnPaneClose(wxAuiManagerEvent& evt)
964   {
965     std::cout  << "Closing panel '"<<evt.pane->name<<"'"<<std::endl;
966     // TO DO : Uncheck 
967     //    OnMenuWindowsCheck( wxCommandEvent& event, wxWindow* w);
968   }
969   //================================================================  
970
971   
972   //================================================================  
973   BEGIN_EVENT_TABLE(WxGUIScriptingInterface, wxFrame)
974     EVT_CLOSE(  WxGUIScriptingInterface::OnClose)
975     EVT_MENU(ID_Menu_Quit, WxGUIScriptingInterface::OnMenuQuit)
976     EVT_MENU(ID_Menu_About, WxGUIScriptingInterface::OnMenuAbout)
977     EVT_MENU(ID_Menu_EditConfig, WxGUIScriptingInterface::OnMenuEditConfig)
978     EVT_MENU(ID_Menu_CreatePackage, WxGUIScriptingInterface::OnMenuCreatePackage)
979     EVT_MENU(ID_Menu_CreateBlackBox, WxGUIScriptingInterface::OnMenuCreateBlackBox)
980     EVT_MENU(ID_Menu_ShowImageGraph, WxGUIScriptingInterface::OnMenuShowImageGraph)
981     EVT_MENU(ID_Menu_RegeneratePackageDoc, WxGUIScriptingInterface::OnMenuRegeneratePackageDoc)
982     EVT_MENU(ID_Menu_RegenerateBoxesLists, WxGUIScriptingInterface::OnMenuRegenerateBoxesLists)
983     EVT_MENU(ID_Menu_RegenerateAll, WxGUIScriptingInterface::OnMenuRegenerateAll)
984     EVT_MENU(ID_Menu_PlugPackage, WxGUIScriptingInterface::OnMenuPlugPackage)
985     EVT_MENU(ID_Menu_Windows_Files, WxGUIScriptingInterface::OnMenuWindowsFiles)
986     EVT_MENU(ID_Menu_Windows_Help, WxGUIScriptingInterface::OnMenuWindowsHelp)
987     EVT_MENU(ID_Menu_Windows_Messages, WxGUIScriptingInterface::OnMenuWindowsMessages)
988     EVT_MENU(ID_Menu_Windows_Command, WxGUIScriptingInterface::OnMenuWindowsCommand)
989     EVT_MENU(ID_Menu_Windows_Save, WxGUIScriptingInterface::OnMenuWindowsSave)
990     EVT_MENU(ID_Menu_Windows_PackageBrowser, WxGUIScriptingInterface::OnMenuWindowsPackageBrowser)
991     EVT_AUI_PANE_CLOSE(WxGUIScriptingInterface::OnPaneClose)
992   //    EVT_BUTTON(ID_Button_Run, WxGUIScriptingInterface::OnButtonRun )
993     END_EVENT_TABLE()
994   //================================================================
995
996 } // namespace bbtk
997
998
999 #endif //_USE_WXWIDGETS_