]> Creatis software - bbtk.git/blob - kernel/src/bbtkWxGUIScriptingInterface.cxx
*** empty log message ***
[bbtk.git] / kernel / src / bbtkWxGUIScriptingInterface.cxx
1 /*=========================================================================                                                                               
2   Program:   bbtk
3   Module:    $RCSfile: bbtkWxGUIScriptingInterface.cxx,v $
4   Language:  C++
5   Date:      $Date: 2009/11/05 16:47:42 $
6   Version:   $Revision: 1.39 $
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 //#include "icons/cc_run.xpm"
61
62 namespace bbtk
63 {
64
65     enum
66     {
67       ID_Menu_Quit = 1,
68       ID_Menu_About,
69       ID_Menu_EditConfig,
70       ID_Menu_CreatePackage,
71       ID_Menu_CreateBlackBox,
72       ID_Menu_ShowImageGraph,
73       ID_Menu_RegeneratePackageDoc,
74       ID_Menu_RegenerateBoxesLists,
75       ID_Menu_RegenerateAll,
76       ID_Menu_PlugPackage,
77       ID_Menu_Windows_Files,
78       ID_Menu_Windows_Help,
79       ID_Menu_Windows_Messages,
80       ID_Menu_Windows_Command,
81       ID_Menu_Windows_Save,
82       ID_Menu_Windows_PackageBrowser
83       //      ID_Button_Run
84     };
85     
86   
87   //================================================================
88   WxGUIScriptingInterface::WxGUIScriptingInterface( wxWindow *parent )
89     : wxFrame((wxFrame *)parent, -1, _T("bbStudio"), 
90               wxDefaultPosition, wxSize(1200,800) )
91   {     
92     m_mgr.SetManagedWindow(this);
93     
94     mInterpreter = bbtk::Interpreter::New();
95     mInterpreter->SetUser(this);
96         mInterpreter->SetCommandLine(true);
97     mInterpreter->SetThrow(true);
98     //    mInterpreter->AddBreakObserver
99     //boost::bind( &WxGUIScriptingInterface::InterpreterUserOnBreak, this ));
100     //==============
101     // Menu
102     wxInitAllImageHandlers();
103     
104     wxMenu *menuFile = new wxMenu;
105     menuFile->Append( ID_Menu_EditConfig, _T("Open bbtk &Config file") );
106     menuFile->Append( ID_Menu_Quit, _T("&Quit") );
107     
108     wxMenu *menuAbout = new wxMenu;
109     menuAbout->Append( ID_Menu_About, _T("&About...") );
110
111     wxMenu *menuTools = new wxMenu;
112     menuTools->Append( ID_Menu_CreatePackage, _T("Create &package") );
113     menuTools->Append( ID_Menu_CreateBlackBox, _T("Create &black box") );
114     menuTools->Append( ID_Menu_PlugPackage, _T("&Plug package") );
115     menuTools->AppendSeparator();
116     menuTools->Append( ID_Menu_RegeneratePackageDoc,_T("Regenerate package &doc") );
117     menuTools->Append( ID_Menu_RegenerateBoxesLists,_T("Regenerate boxes &lists") );
118     menuTools->Append( ID_Menu_RegenerateAll,_T("Regenerate &all") );
119     menuTools->AppendSeparator();
120     menuTools->Append( ID_Menu_ShowImageGraph, _T("&Show last graph") );
121
122     wxMenu *menuWindows = new wxMenu;
123     menuWindows->AppendCheckItem(ID_Menu_Windows_Files,
124                                  _T("Show 'files' panel") )->Check();
125     menuWindows->AppendCheckItem(ID_Menu_Windows_Help,
126                                  _T("Show 'help' panel") )->Check();
127     menuWindows->AppendCheckItem(ID_Menu_Windows_Messages,
128                                  _T("Show 'messages' panel") )->Check();
129     menuWindows->AppendCheckItem(ID_Menu_Windows_Command,
130                                  _T("Show 'command' panel") )->Check();
131     menuWindows->AppendSeparator();
132     menuWindows->Append( ID_Menu_Windows_PackageBrowser, _T("Start Package &Browser") );
133     
134     //    menuWindows->AppendSeparator();
135     //    menuWindows->Append ( ID_Menu_Windows_Save, _T("Save interface configuration"));
136
137     wxMenu *menuOptions = new wxMenu;
138     mwxMenuItemReset = menuOptions->AppendCheckItem(-1,
139                                                     _T("Reset before running") );
140     mwxMenuItemReset->Check();
141
142     wxMenuBar *menuBar = new wxMenuBar;
143     menuBar->Append( menuFile, _T("&File") );
144     menuBar->Append( menuTools, _T("&Tools") );
145     menuBar->Append( menuOptions, _T("&Options") );
146     menuBar->Append( menuWindows, _T("&Windows") );
147     menuBar->Append( menuAbout, _T("About") );
148     
149     SetMenuBar( menuBar );
150     
151     //=== 
152     // Status bar
153     CreateStatusBar();
154     SetStatusText( _T("Welcome to bbStudio !") );
155     
156     //===
157     // Panes (Files, Messages, Help, Command)
158     mWxGUITextEditor = new WxGUITextEditor(this,this);
159     mWxGUITextEditor->SetFileNameFilter("*.bbs");
160         
161     mWxGUIHtmlBrowser = new WxGUIHtmlBrowser(this,wxSize(200,0),this);
162
163     mWxGUIOutputMessages = new WxGUIOutputMessages(this);
164
165     mWxGUICommand = new WxGUICommand(this,this);
166    
167     mWxGUICommand->SetFocus();
168
169  
170 #if NOTEBOOK
171
172     mwxNotebook = new wxAuiNotebook(this,  
173                                     -1,
174                                     wxPoint(0, 0),
175                                     wxSize(500,500),
176                                     wxAUI_NB_TAB_SPLIT 
177                                     | wxAUI_NB_TAB_MOVE
178                                     | wxAUI_NB_TAB_EXTERNAL_MOVE
179                                     //| wxAUI_NB_WINDOWLIST_BUTTON
180                                     //|wxAUI_NB_SCROLL_BUTTONS
181                                     // | wxAUI_NB_CLOSE_BUTTON 
182                                     //| wxAUI_NB_CLOSE_ON_ACTIVE_TAB
183                                     //| wxAUI_NB_CLOSE_ON_ALL_TABS
184                                     | wxNO_BORDER);
185   
186
187     mwxNotebook->AddPage(mWxGUITextEditor,_T("Files"),true);
188     mwxNotebook->AddPage(mWxGUIHtmlBrowser,_T("Help"),true);
189
190     mwxNotebook->AddPage(mWxGUIOutputMessages,_T("Messages"),true);
191
192     mwxNotebook->AddPage(mWxGUICommand,_T("Command"),true);
193
194
195     m_mgr.AddPane(mwxNotebook,
196                   wxAuiPaneInfo().Name(wxT("nb"))
197                   .CaptionVisible(false)
198                   .MinimizeButton(false)
199                   .MaximizeButton(false)
200                   .Center()
201                   //              .MinSize(wxSize(100,100))
202                   );   
203 #else 
204
205     //
206     m_mgr.AddPane(mWxGUITextEditor,
207                   wxAuiPaneInfo().Name(wxT("editor_content"))
208                   .Caption(wxT("Files"))
209                   .MinimizeButton(true)
210                   .MaximizeButton(true)
211                   .Center()
212                   .MinSize(wxSize(100,100))
213                   );   
214   
215     m_mgr.AddPane(mWxGUIHtmlBrowser,
216                   wxAuiPaneInfo().Name(wxT("browser_content"))
217                   .Caption(wxT("Help"))
218                   .MinimizeButton(true)
219                   .MaximizeButton(true)
220                   .Right()
221                   .Layer(2)
222                   .MinSize(wxSize(400,100))
223                   );
224
225     m_mgr.AddPane(mWxGUIOutputMessages,
226                   wxAuiPaneInfo().Name(wxT("messages_content"))
227                   .Caption(wxT("Messages"))
228                   .MinimizeButton(true)
229                   .MaximizeButton(true)
230                   .Bottom()
231                   .MinSize(wxSize(100,100))
232                   );
233           
234     m_mgr.AddPane(mWxGUICommand,
235                   wxAuiPaneInfo().Name(wxT("command_content"))
236                   .Caption(wxT("Command"))
237                   .MinimizeButton(true)
238                   .MaximizeButton(true)
239                   .Bottom()
240                   .Layer(1)
241                   .MinSize(wxSize(100,100))
242                   );     
243 #endif
244
245     // parent window of all bbtk windows will be a child of this
246     //    Wx::SetTopWindowParent(this);
247     Wx::SetTopWindow(this);
248     // Wx::SetAutoDestroyTopWindow(false);
249   // Add the method OnWxSignal as a Wx::Signal observer 
250     //bbtkAddWxSignalObserver(WxGUIPackageBrowser2Window::OnWxSignal);
251
252     //.PaneBorder(false)); 
253     // Load the interface appearance saved on last closing
254     LoadPerspective();
255
256     // Done in LoadPerspective
257     //    m_mgr.Update();
258         
259     SetAutoLayout(true);
260     Layout();
261     //    mwxNotebook->SetSelection(1);
262     mWxGUIHtmlBrowser->GoHome();
263 //    Refresh();
264     m_mgr.Update();
265     //   LoadPerspective();
266
267     mBreaked = false;   
268
269     wxBitmap bitmap;   
270     wxSplashScreen* splash;
271     long style = wxSPLASH_CENTRE_ON_SCREEN | wxSPLASH_TIMEOUT;
272     if (ConfigurationFile::GetInstance().DotBbtkIsNew())
273       style = wxSPLASH_CENTRE_ON_SCREEN | wxSPLASH_NO_TIMEOUT;
274     std::string splash_file = ConfigurationFile::GetInstance().Get_data_path();
275     splash_file += "/kernel/icons/bbStudioSplashScreen.png";
276
277     if (bitmap.LoadFile(std2wx(splash_file),wxBITMAP_TYPE_PNG))
278       splash = 
279         new wxSplashScreen(bitmap,
280                            style,
281                            1000, 0, -1, wxDefaultPosition, wxDefaultSize,
282                            wxSIMPLE_BORDER|wxSTAY_ON_TOP);
283         
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           command += ConfigurationFile::GetInstance().Get_bin_path();
445 #ifdef MACOSX
446           command += separator + "bbi.app/Contents/MacOS/bbi\" ";
447 #else 
448           command += separator + "bbi\" ";
449 #endif
450           command += "\""+filename + "\"";
451           command += " & ";
452           
453           printf ("EED WxGUIScriptingInterface::WxGUITextEditorRunBBI %s \n" , command.c_str() );
454           system( command.c_str() );
455         }
456         //================================================================
457         
458         
459   //================================================================
460   void WxGUIScriptingInterface::WxGUITextEditorRun()
461   {
462     //    wxString temp = mWxGUIHtmlBrowser->GetCurrentPage();
463     std::stringstream* buf = new std::stringstream;
464     (*buf) << mWxGUITextEditor->GetCurrentPage()->GetText();
465     try 
466       {
467         if (!mBreaked)
468           {
469             if (mwxMenuItemReset->IsChecked()) WxGUICommandEnter("reset");
470             mInterpreter->InterpretBuffer(buf);
471           }
472         else 
473           {
474             mBreaked = false;
475             mInterpreter->InterpretCurrentStreams();
476           }
477         //      std::cout << "EO RUN"<<std::endl;
478       }
479     CATCH_MACRO;
480     //    std::cout << "EO RUN 3"<<std::endl;
481   }
482   //================================================================  
483
484   //================================================================
485   void WxGUIScriptingInterface::OnMenuQuit(wxCommandEvent& WXUNUSED(event))
486   {
487     if (!mWxGUITextEditor->CloseAllPages()) return;
488     Close(true);
489   }
490   //================================================================
491
492
493   //================================================================
494   void WxGUIScriptingInterface::OnMenuAbout(wxCommandEvent& WXUNUSED(event))
495   {
496     m_mgr.Update();
497         Refresh();
498     wxMessageBox(_T("  bbStudio\nThe Black Box Toolkit Development Studio\n(c) CREATIS-LRMN 2008"),
499                  _T("About ..."), wxOK | wxICON_INFORMATION,
500                  this);
501   }
502   //================================================================
503
504
505   //================================================================
506   void WxGUIScriptingInterface::OnMenuEditConfig(wxCommandEvent& WXUNUSED(event))
507   {
508
509     std::string configFile = 
510       ConfigurationFile::GetInstance().Get_config_xml_full_path();
511     Open(configFile);
512         wxMessageDialog ww(NULL,_T("If you change the bbtk_config.xml, you have to reinicialice this appliaction..."), _T("Alert !"), wxOK);
513         ww.ShowModal();
514   }
515   //================================================================
516
517   //================================================================
518   void WxGUIScriptingInterface::OnMenuWindowsPackageBrowser(wxCommandEvent& WXUNUSED(event))
519   {
520     wxBusyCursor wait;
521     WxGUIPackageBrowser2Window *helpbrowser = new
522       WxGUIPackageBrowser2Window(this,_T("Package Browser"), wxSize(600,600) );
523     helpbrowser->Show();
524     
525     /*
526     wxBusyCursor wait;
527     WxGUIPackageBrowser2 *browser = new WxGUIPackageBrowser2(this);
528     browser->IncludeAll();
529     */
530 #if NOTEBOOK
531     //     mwxNotebook->AddPage(browser,_T("Package Browser"),true);
532 #else
533      /*
534      m_mgr.AddPane(browser,
535                    wxAuiPaneInfo().Name(wxT("package_brower"))
536                    .Caption(wxT("Package browser"))
537                    .MinimizeButton(true)
538                    .MaximizeButton(true)
539                    .Bottom()
540                    .Position(1)
541                    .MinSize(wxSize(100,100))
542                    );     
543      */
544 #endif
545   }
546   //================================================================
547
548
549
550   //================================================================
551   void WxGUIScriptingInterface::OnMenuCreatePackage(wxCommandEvent& WXUNUSED(event))
552   {
553 /*
554     std::string command("toolsbbtk/appli/GUICreatePackage");
555     bbtkMessage("Debug",1,"Executing : '"<<command<<"'"<<std::endl);
556   
557         Interpreter::Pointer I = Interpreter::New();    
558     I->InterpretFile(command);
559 */
560     std::string command("reset");
561         mWxGUICommand->SendCommand(command);
562     command = "include toolsbbtk/appli/GUICreatePackage";
563     bbtkMessage("Debug",1,"Executing : '"<<command<<"'"<<std::endl);
564         mWxGUICommand->SendCommand(command);
565
566   }
567   //================================================================
568
569
570   //================================================================
571   void WxGUIScriptingInterface::OnMenuCreateBlackBox(wxCommandEvent& WXUNUSED(event))
572   {
573           /*
574     std::string command("toolsbbtk/appli/GUICreateBlackBox");
575     bbtkMessage("Debug",1,"Executing : '"<<command<<"'"<<std::endl);
576     
577     Interpreter::Pointer I = Interpreter::New();    
578     I->InterpretFile(command);
579 */
580     std::string command("reset");
581         mWxGUICommand->SendCommand(command);
582     command = "include toolsbbtk/appli/GUICreateBlackBox";
583     bbtkMessage("Debug",1,"Executing : '"<<command<<"'"<<std::endl);
584         mWxGUICommand->SendCommand(command);
585   }
586   //================================================================
587   
588   //================================================================
589   void WxGUIScriptingInterface::OnMenuShowImageGraph(wxCommandEvent& WXUNUSED(event))
590   {
591
592       std::string doc_path = bbtk::ConfigurationFile::GetInstance().Get_doc_path();
593       doc_path += bbtk::ConfigurationFile::GetInstance().Get_file_separator();
594       doc_path += "bbdoc";
595       doc_path += bbtk::ConfigurationFile::GetInstance().Get_file_separator();
596           
597           std::string pack_name("User");
598           std::string pack_path = doc_path + pack_name;
599           
600           
601 #if defined(WIN32)
602     std::string strappli="start ";
603 #else
604   #if defined(MACOSX)
605       std::string strappli="open ";
606   #else
607       std::string strappli="gnome-open ";         
608   #endif
609 #endif
610           
611           std::string strcommand = strappli +pack_path+"/workspace_workspacePrototype.png";
612     //  std::cout << "system: " << strcommand << std::endl;
613     system ( strcommand.c_str() );
614
615   }
616   //================================================================
617
618   void WxGUIScriptingInterface::DoRegeneratePackageDoc( const std::string& pack )
619   {
620     std::string mess("Regenerating doc for package '");
621     if (pack!="-a") 
622       mess += pack + "'";
623     else 
624       mess = "Regenerating doc for all packages";
625     mess += " ... please wait";
626
627     SetStatusText( std2wx(mess) );
628
629     BBTK_BUSY_CURSOR;
630
631     std::string command;
632 #if defined(WIN32)
633     command = "\"";
634 #endif
635     command += ConfigurationFile::GetInstance().Get_bin_path();
636     command += ConfigurationFile::GetInstance().Get_file_separator();
637     command += "bbRegeneratePackageDoc";
638 #if defined(WIN32)
639         command += "\"";
640 #endif
641         command += " " + pack + " -q";
642     bbtkMessage("debug",1,"Executing system command '"<<command<<"'"<<std::endl);
643
644
645     if ( ! system ( command.c_str() ) )
646       {
647         SetStatusText( _T("Done !"));
648         /*
649         wxMessageBox(_T("Done !"),_T("Regenerate package '")
650                      +std2wx(pack)+_T("' doc"),
651                      wxOK | wxICON_INFORMATION);
652         */
653       }
654     else 
655       {
656         SetStatusText( _T("Done !"));
657         wxString err(_T("An error occured while running '"));
658         err +=  bbtk::std2wx(command) + _T("'");
659         wxMessageBox(err,_T("Regenerate package doc"),wxOK | wxICON_ERROR);      
660       }
661
662
663
664   }
665
666
667   //================================================================
668   void WxGUIScriptingInterface::OnMenuRegeneratePackageDoc(wxCommandEvent& WXUNUSED(event))
669   {
670     wxString name = wxGetTextFromUser(_T("Enter package name (-a for all)"),
671                                       _T("Regenerate package doc"),
672                                       _T(""));
673     if (name.IsEmpty()) return;
674     std::string pack = bbtk::wx2std(name);
675     
676         DoRegeneratePackageDoc(pack);
677   }
678   //================================================================
679
680
681   //================================================================
682   void WxGUIScriptingInterface::DoRegenerateBoxesLists()
683   {
684     SetStatusText( _T("Regenerating boxes lists ... please wait") );
685     BBTK_BUSY_CURSOR ;
686
687     std::string command;
688 #if defined(WIN32)
689         command = "\"";
690 #endif
691     command += ConfigurationFile::GetInstance().Get_bin_path();
692     command += ConfigurationFile::GetInstance().Get_file_separator();
693     command += "bbRegenerateBoxesLists";
694 #if defined(WIN32)
695         command += "\"";
696 #endif
697         command += " -q";
698         bbtkMessage("debug",1,"Executing system command '"<<command<<"'"<<std::endl);
699
700
701
702     if ( ! system ( command.c_str() ) )
703       {
704         SetStatusText( _T("Done !"));
705         /*
706         wxMessageBox(_T("Done !"),_T("Regenerate boxes lists"),
707                      wxOK | wxICON_INFORMATION);
708         */
709       }
710     else 
711       {
712         SetStatusText( _T("Done !"));
713         wxString err(_T("An error occured while running '"));
714         err +=  bbtk::std2wx(command) + _T("'");
715         wxMessageBox(err,_T("Regenerate boxes lists"),wxOK | wxICON_ERROR);      
716       }
717   }
718   //================================================================
719
720
721   //================================================================
722   void WxGUIScriptingInterface::OnMenuRegenerateBoxesLists(wxCommandEvent& WXUNUSED(event))
723   {
724         DoRegenerateBoxesLists();
725   }
726   //================================================================
727
728   //================================================================
729   void WxGUIScriptingInterface::OnMenuRegenerateAll(wxCommandEvent& WXUNUSED(event))
730   {
731         
732     DoRegeneratePackageDoc("-a");       
733         DoRegenerateBoxesLists();
734   }
735   //================================================================
736
737  
738   //================================================================
739   void WxGUIScriptingInterface::OnMenuPlugPackage(wxCommandEvent& WXUNUSED(event))
740   {
741     long style = wxDD_DEFAULT_STYLE | wxDD_DIR_MUST_EXIST;
742     wxDirDialog* FD = 
743       new wxDirDialog( 0, 
744                        _T("Select package directory"),
745                        _T(""),
746                        style);
747     
748     if (FD->ShowModal()==wxID_OK)
749       {
750         std::string path = wx2std (FD->GetPath()) ;
751         std::string fname = path + "/bbtkPackage"; 
752         if ( ! Utilities::FileExists( fname ) )
753           {
754             wxString err(_T("The directory does not contain a 'bbtkPackage' file"));
755             wxMessageBox(err,_T("Plug package"),wxOK | wxICON_ERROR);      
756             return;
757           }
758         
759         std::ifstream f;
760         f.open(fname.c_str());
761         std::string pname;
762         f >> pname;
763         f.close();
764         
765         
766         bbtk::ConfigurationFile::GetInstance().AddPackagePathsAndWrite( path );
767         
768         DoRegeneratePackageDoc(pname);
769         DoRegenerateBoxesLists();
770
771           }     
772   }
773   //================================================================
774
775   //================================================================
776   void WxGUIScriptingInterface::InterpreterUserViewHtmlPage(const std::string& page)
777   {
778     std::string s(page);
779     //  std::cout << "WxGUIScriptingInterface::ShowHtmlPage('"<<page<<"')"<<std::endl;
780     if (mWxGUIHtmlBrowser->GoTo(s)) 
781       {
782 //EED   mwxNotebook->ChangeSelection(1);
783 //      mwxNotebook->SetSelection(1);
784       }
785     else 
786       {
787          // std::cout << "ERROR html"<<std::endl;
788       }
789   } 
790   //================================================================  
791   
792   /*
793   //================================================================
794   void WxGUIScriptingInterface::InterpreterUserOnBreak()
795   {
796     //    std::cout << "Break" << std::endl;
797     
798   }
799   //================================================================
800   */
801
802   //================================================================  
803   bool WxGUIScriptingInterface::WxGUIHtmlBrowserUserOnLinkClicked(const std::string& target)
804   {
805     size_t s = target.length();
806     if ((s>3) && (target[s-1]=='s')
807         && (target[s-2]=='b')
808         && (target[s-3]=='b')
809         && (target[s-4]=='.'))
810       {
811         mWxGUITextEditor->Open(target);
812 #if NOTEBOOK
813         mwxNotebook->SetSelection(0);
814 #endif
815         mWxGUITextEditor->SetFocus();
816         return false;
817       }
818     return true;
819   }
820   //================================================================  
821
822   void WxGUIScriptingInterface::OnMenuWindowsCheck( wxCommandEvent& event, 
823                                                     wxWindow* w)
824   {
825     bool checked = event.IsChecked();
826     bool shown = m_mgr.GetPane(w).IsShown();
827     //    std::cout << "checked = "<<checked<<" - shown = "<<shown<<std::endl;
828     if (checked ^ shown) 
829       {
830         m_mgr.GetPane(w).Show(checked);
831         m_mgr.Update();
832       }
833   }
834
835
836   //================================================================  
837   void WxGUIScriptingInterface::OnMenuWindowsFiles(wxCommandEvent& event)
838   {
839     OnMenuWindowsCheck(event,mWxGUITextEditor);
840   }
841   //================================================================  
842
843   //================================================================  
844   void  WxGUIScriptingInterface::OnMenuWindowsHelp(wxCommandEvent& event)
845   {
846     OnMenuWindowsCheck(event,mWxGUIHtmlBrowser);
847   }
848   //================================================================  
849
850   //================================================================  
851   void  WxGUIScriptingInterface::OnMenuWindowsMessages(wxCommandEvent& event)
852   {
853     OnMenuWindowsCheck(event,mWxGUIOutputMessages);
854   }
855   //================================================================  
856
857   //================================================================  
858   void  WxGUIScriptingInterface::OnMenuWindowsCommand(wxCommandEvent& event)
859   {
860     OnMenuWindowsCheck(event,mWxGUICommand);
861   }
862   //================================================================  
863
864   //================================================================  
865   void WxGUIScriptingInterface::OnMenuWindowsSave( wxCommandEvent& WXUNUSED(event))
866   {
867     SavePerspective();
868   }
869   //================================================================  
870
871   //================================================================  
872   void WxGUIScriptingInterface::SavePerspective()
873   {
874     //    std::cout  << "Saving configuration..."<<std::endl;
875     std::string conf = wx2std(m_mgr.SavePerspective());
876     std::string fname = Utilities::MakeUserSettingsFullFileName("bbStudio.aui");
877     std::ofstream f;
878     f.open(fname.c_str(), std::ios::out );
879     f << conf << std::endl;
880
881     //    int x,y;
882     //    GetPosition(&x,&y);
883     //    f << x << "  " << y << std::endl;
884
885
886     int w,h;
887     GetSize(&w,&h);
888
889     f << w << " " << h << std::endl;
890
891     f.close();
892   }
893   //================================================================  
894
895   //================================================================  
896   void WxGUIScriptingInterface::LoadPerspective()
897   {
898     std::string fname = 
899       Utilities::MakeUserSettingsFullFileName("bbStudio.aui");
900     if ( Utilities::FileExists( fname ))
901       {
902         //      std::cout  << "Loading configuration..."<<std::endl;
903
904         std::ifstream f;
905         f.open(fname.c_str());
906         std::string conf;
907         f >> conf;
908
909         //      int x,y;
910         //      f >> x >> y ;
911
912         int w,h;
913         f >> w >> h ;
914
915         f.close();
916         
917         //      std::cout << conf << std::endl;
918
919         //      Move(x,y);
920         SetSize(w,h);
921         m_mgr.LoadPerspective(std2wx(conf));
922       }
923     else 
924       {
925         m_mgr.Update();
926       }
927   }
928   //================================================================  
929
930   //================================================================  
931   void WxGUIScriptingInterface::OnPaneClose(wxAuiManagerEvent& evt)
932   {
933     std::cout  << "Closing panel '"<<evt.pane->name<<"'"<<std::endl;
934     // TO DO : Uncheck 
935     //    OnMenuWindowsCheck( wxCommandEvent& event, wxWindow* w);
936   }
937   //================================================================  
938
939   
940   //================================================================  
941   BEGIN_EVENT_TABLE(WxGUIScriptingInterface, wxFrame)
942     EVT_CLOSE(  WxGUIScriptingInterface::OnClose)
943     EVT_MENU(ID_Menu_Quit, WxGUIScriptingInterface::OnMenuQuit)
944     EVT_MENU(ID_Menu_About, WxGUIScriptingInterface::OnMenuAbout)
945     EVT_MENU(ID_Menu_EditConfig, WxGUIScriptingInterface::OnMenuEditConfig)
946     EVT_MENU(ID_Menu_CreatePackage, WxGUIScriptingInterface::OnMenuCreatePackage)
947     EVT_MENU(ID_Menu_CreateBlackBox, WxGUIScriptingInterface::OnMenuCreateBlackBox)
948     EVT_MENU(ID_Menu_ShowImageGraph, WxGUIScriptingInterface::OnMenuShowImageGraph)
949     EVT_MENU(ID_Menu_RegeneratePackageDoc, WxGUIScriptingInterface::OnMenuRegeneratePackageDoc)
950     EVT_MENU(ID_Menu_RegenerateBoxesLists, WxGUIScriptingInterface::OnMenuRegenerateBoxesLists)
951     EVT_MENU(ID_Menu_RegenerateAll, WxGUIScriptingInterface::OnMenuRegenerateAll)
952     EVT_MENU(ID_Menu_PlugPackage, WxGUIScriptingInterface::OnMenuPlugPackage)
953     EVT_MENU(ID_Menu_Windows_Files, WxGUIScriptingInterface::OnMenuWindowsFiles)
954     EVT_MENU(ID_Menu_Windows_Help, WxGUIScriptingInterface::OnMenuWindowsHelp)
955     EVT_MENU(ID_Menu_Windows_Messages, WxGUIScriptingInterface::OnMenuWindowsMessages)
956     EVT_MENU(ID_Menu_Windows_Command, WxGUIScriptingInterface::OnMenuWindowsCommand)
957     EVT_MENU(ID_Menu_Windows_Save, WxGUIScriptingInterface::OnMenuWindowsSave)
958     EVT_MENU(ID_Menu_Windows_PackageBrowser, WxGUIScriptingInterface::OnMenuWindowsPackageBrowser)
959     EVT_AUI_PANE_CLOSE(WxGUIScriptingInterface::OnPaneClose)
960   //    EVT_BUTTON(ID_Button_Run, WxGUIScriptingInterface::OnButtonRun )
961     END_EVENT_TABLE()
962   //================================================================
963
964 } // namespace bbtk
965
966
967 #endif //_USE_WXWIDGETS_