]> Creatis software - bbtk.git/blob - kernel/src/bbtkWxGUIScriptingInterface.cxx
49bc3460c4b27219bd8b51e26ae56fb3ecea7d24
[bbtk.git] / kernel / src / bbtkWxGUIScriptingInterface.cxx
1 /*=========================================================================                                                                               
2   Program:   bbtk
3   Module:    $RCSfile: bbtkWxGUIScriptingInterface.cxx,v $
4   Language:  C++
5   Date:      $Date: 2009/01/27 14:22:57 $
6   Version:   $Revision: 1.33 $
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     m_mgr.AddPane(mWxGUICommand,
234                   wxAuiPaneInfo().Name(wxT("command_content"))
235                   .Caption(wxT("Command"))
236                   .MinimizeButton(true)
237                   .MaximizeButton(true)
238                   .Bottom()
239                   .Layer(1)
240                   .MinSize(wxSize(100,100))
241                   );     
242 #endif
243
244     // parent window of all bbtk windows will be a child of this
245     Wx::SetTopWindowParent(this);
246     // Add the method OnWxSignal as a Wx::Signal observer 
247     //bbtkAddWxSignalObserver(WxGUIPackageBrowser2Window::OnWxSignal);
248
249     //.PaneBorder(false)); 
250     // Load the interface appearance saved on last closing
251     LoadPerspective();
252
253     // Done in LoadPerspective
254     //    m_mgr.Update();
255         
256     SetAutoLayout(true);
257     Layout();
258     //    mwxNotebook->SetSelection(1);
259     mWxGUIHtmlBrowser->GoHome();
260 //    Refresh();
261     m_mgr.Update();
262     //   LoadPerspective();
263
264     mBreaked = false;   
265
266     wxBitmap bitmap;   
267     wxSplashScreen* splash;
268     long style = wxSPLASH_CENTRE_ON_SCREEN | wxSPLASH_TIMEOUT;
269     if (ConfigurationFile::GetInstance().DotBbtkIsNew())
270       style = wxSPLASH_CENTRE_ON_SCREEN | wxSPLASH_NO_TIMEOUT;
271     std::string splash_file = ConfigurationFile::GetInstance().Get_data_path();
272     splash_file += "/kernel/icons/bbStudioSplashScreen.png";
273
274     if (bitmap.LoadFile(std2wx(splash_file),wxBITMAP_TYPE_PNG))
275       splash = 
276         new wxSplashScreen(bitmap,
277                            style,
278                            1000, 0, -1, wxDefaultPosition, wxDefaultSize,
279                            wxSIMPLE_BORDER|wxSTAY_ON_TOP);
280         
281     
282     if (ConfigurationFile::GetInstance().DotBbtkIsNew())
283       {
284
285         DoRegeneratePackageDoc("-a");   
286         DoRegenerateBoxesLists();
287
288         /*
289         wxTipWindow* tip = new wxTipWindow(this,
290                                            _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);
291         tip->CenterOnParent();
292         tip->Show();
293         */
294         if (splash) splash->Destroy();
295       }
296
297   }
298   //================================================================
299
300  //================================================================
301   WxGUIScriptingInterface::~WxGUIScriptingInterface()
302   {
303     SavePerspective();
304     m_mgr.UnInit();
305   }
306   //================================================================
307
308   //================================================================
309   void WxGUIScriptingInterface::Open(const std::string& filename)
310   {
311     mWxGUITextEditor->Open(filename);
312   }
313   //================================================================
314   /*
315   catch (BreakException e)                                              \
316     {                                                                   \
317       std::cout << "* BREAK"<<std::endl;                                \
318       if (e.IsInScriptFile())                                           \
319         std::cout << "* FILE   : '"<<e.GetScriptFile()<<"'"<<std::endl; \
320       std::cout << "* LINE   : "<<e.GetScriptLine()<<std::endl;         \
321     }                                                                   \
322   catch (QuitException e)                                               \
323     {                                                                   \
324       std::cout << "* QUIT"<<std::endl;                                 \
325       if (e.IsInScriptFile())                                           \
326         std::cout << "* FILE   : '"<<e.GetScriptFile()<<"'"<<std::endl; \
327       std::cout << "* LINE   : "<<e.GetScriptLine()<<std::endl;         \
328     }                                                                   \
329 */
330   
331 #define CATCH_MACRO                                                     \
332   catch (InterpreterException e)                                        \
333     {                                                                   \
334       if (e.GetErrorMessage()=="quit")                                  \
335         {                                                               \
336           std::cerr << "* QUIT ENCOUNTERED"<<std::endl;                 \
337           if (e.IsInScriptFile())                                       \
338             std::cerr << "* FILE   : '"<<e.GetScriptFile()<<"'"<<std::endl; \
339           std::cerr << "* LINE   : "<<e.GetScriptLine()<<std::endl;     \
340         }                                                               \
341       else if (e.GetErrorMessage()=="break")                            \
342         {                                                               \
343           mBreaked = true;                                              \
344           std::cerr << "* BREAK"<<std::endl;                            \
345           if (e.IsInScriptFile())                                       \
346             std::cerr << "* FILE   : '"<<e.GetScriptFile()<<"'"<<std::endl; \
347           std::cerr << "* LINE   : "<<e.GetScriptLine()<<std::endl;     \
348         }                                                               \
349       else                                                              \
350         {                                                               \
351           std::cerr << "* ERROR : "<<e.GetErrorMessage()<<std::endl;    \
352           if (e.IsInScriptFile())                                       \
353             std::cerr << "* FILE   : '"<<e.GetScriptFile()<<"'"<<std::endl; \
354           std::cerr << "* LINE   : "<<e.GetScriptLine()<<std::endl;     \
355           int lev = bbtk::MessageManager::GetMessageLevel("Error");     \
356           if (lev > 0) {                                                \
357             std::cerr << "* Exception thrown : "<<std::endl;            \
358             std::cerr << "*  OBJECT : " <<e.GetObject()<<std::endl;     \
359             std::cerr << "*  FILE   : " <<e.GetSourceFile()<<std::endl; \
360           }                                                             \
361         }                                                               \
362     }
363   
364   //================================================================
365   void WxGUIScriptingInterface::WxGUICommandEnter(const std::string& command)
366   {
367     std::string s("> ");
368     s += command + "\n";
369     mWxGUIOutputMessages->Print(s,wxRED);
370     
371     try
372       {
373         mInterpreter->InterpretLine( command );
374       }
375     CATCH_MACRO;
376   }
377   //================================================================
378   
379   //================================================================
380   /// Runs the interpretation of a file
381   bool WxGUIScriptingInterface::InterpretFile( const std::string& filename) 
382   { 
383     try
384       {
385         mInterpreter->InterpretFile(filename);
386       }
387     CATCH_MACRO;
388     return true;
389   }
390   //================================================================
391  
392   //================================================================
393   void WxGUIScriptingInterface::WxGUITextEditorRun()
394   {
395     //    wxString temp = mWxGUIHtmlBrowser->GetCurrentPage();
396     std::stringstream* buf = new std::stringstream;
397     (*buf) << mWxGUITextEditor->GetCurrentPage()->GetText();
398     try 
399       {
400         if (!mBreaked)
401           {
402             if (mwxMenuItemReset->IsChecked()) WxGUICommandEnter("reset");
403             mInterpreter->InterpretBuffer(buf);
404           }
405         else 
406           {
407             mBreaked = false;
408             mInterpreter->InterpretCurrentStreams();
409           }
410         //      std::cout << "EO RUN"<<std::endl;
411       }
412     CATCH_MACRO;
413     //    std::cout << "EO RUN 3"<<std::endl;
414   }
415   //================================================================  
416
417   //================================================================
418   void WxGUIScriptingInterface::OnMenuQuit(wxCommandEvent& WXUNUSED(event))
419   {
420     if (!mWxGUITextEditor->CloseAllPages()) return;
421     Close(true);
422   }
423   //================================================================
424
425
426   //================================================================
427   void WxGUIScriptingInterface::OnMenuAbout(wxCommandEvent& WXUNUSED(event))
428   {
429     m_mgr.Update();
430         Refresh();
431     wxMessageBox(_T("  bbStudio\nThe Black Box Toolkit Development Studio\n(c) CREATIS-LRMN 2008"),
432                  _T("About ..."), wxOK | wxICON_INFORMATION,
433                  this);
434   }
435   //================================================================
436
437
438   //================================================================
439   void WxGUIScriptingInterface::OnMenuEditConfig(wxCommandEvent& WXUNUSED(event))
440   {
441     std::string configFile = 
442       ConfigurationFile::GetInstance().Get_config_xml_full_path();
443     Open(configFile);
444   }
445   //================================================================
446
447   //================================================================
448   void WxGUIScriptingInterface::OnMenuWindowsPackageBrowser(wxCommandEvent& WXUNUSED(event))
449   {
450     wxBusyCursor wait;
451     WxGUIPackageBrowser2Window *helpbrowser = new
452       WxGUIPackageBrowser2Window(this,_T("Package Browser"), wxSize(600,600) );
453     helpbrowser->Show();
454     
455     /*
456     wxBusyCursor wait;
457     WxGUIPackageBrowser2 *browser = new WxGUIPackageBrowser2(this);
458     browser->IncludeAll();
459     */
460 #if NOTEBOOK
461     //     mwxNotebook->AddPage(browser,_T("Package Browser"),true);
462 #else
463      /*
464      m_mgr.AddPane(browser,
465                    wxAuiPaneInfo().Name(wxT("package_brower"))
466                    .Caption(wxT("Package browser"))
467                    .MinimizeButton(true)
468                    .MaximizeButton(true)
469                    .Bottom()
470                    .Position(1)
471                    .MinSize(wxSize(100,100))
472                    );     
473      */
474 #endif
475   }
476   //================================================================
477
478
479
480   //================================================================
481   void WxGUIScriptingInterface::OnMenuCreatePackage(wxCommandEvent& WXUNUSED(event))
482   {
483 /*
484     std::string command("toolsbbtk/appli/GUICreatePackage");
485     bbtkMessage("Debug",1,"Executing : '"<<command<<"'"<<std::endl);
486   
487         Interpreter::Pointer I = Interpreter::New();    
488     I->InterpretFile(command);
489 */
490     std::string command("reset");
491         mWxGUICommand->SendCommand(command);
492     command = "include toolsbbtk/appli/GUICreatePackage";
493     bbtkMessage("Debug",1,"Executing : '"<<command<<"'"<<std::endl);
494         mWxGUICommand->SendCommand(command);
495
496   }
497   //================================================================
498
499
500   //================================================================
501   void WxGUIScriptingInterface::OnMenuCreateBlackBox(wxCommandEvent& WXUNUSED(event))
502   {
503           /*
504     std::string command("toolsbbtk/appli/GUICreateBlackBox");
505     bbtkMessage("Debug",1,"Executing : '"<<command<<"'"<<std::endl);
506     
507     Interpreter::Pointer I = Interpreter::New();    
508     I->InterpretFile(command);
509 */
510     std::string command("reset");
511         mWxGUICommand->SendCommand(command);
512     command = "include toolsbbtk/appli/GUICreateBlackBox";
513     bbtkMessage("Debug",1,"Executing : '"<<command<<"'"<<std::endl);
514         mWxGUICommand->SendCommand(command);
515   }
516   //================================================================
517   
518   //================================================================
519   void WxGUIScriptingInterface::OnMenuShowImageGraph(wxCommandEvent& WXUNUSED(event))
520   {
521     std::string default_temp_dir = ConfigurationFile::GetInstance().Get_default_temp_dir();
522
523 #if defined(WIN32)
524     std::string strappli="start ";
525 #else
526     std::string strappli="gnome-open ";
527 #endif
528     std::string strcommand = strappli +default_temp_dir+"/temp_dir/workspace_workspacePrototype.png";
529     //  std::cout << "system: " << strcommand << std::endl;
530     system ( strcommand.c_str() );
531
532   }
533   //================================================================
534
535   void WxGUIScriptingInterface::DoRegeneratePackageDoc( const std::string& pack )
536   {
537     std::string mess("Regenerating doc for package '");
538     if (pack!="-a") 
539       mess += pack + "'";
540     else 
541       mess = "Regenerating doc for all packages";
542     mess += " ... please wait";
543
544     SetStatusText( std2wx(mess) );
545
546     BBTK_BUSY_CURSOR;
547
548     std::string command;
549 #if defined(WIN32)
550     command = "\"";
551 #endif
552     command += ConfigurationFile::GetInstance().Get_bin_path();
553     command += ConfigurationFile::GetInstance().Get_file_separator();
554     command += "bbRegeneratePackageDoc";
555 #if defined(WIN32)
556         command += "\"";
557 #endif
558         command += " " + pack + " -q";
559     bbtkMessage("debug",1,"Executing system command '"<<command<<"'"<<std::endl);
560     
561
562     if ( ! system ( command.c_str() ) )
563       {
564         SetStatusText( _T("Done !"));
565         /*
566         wxMessageBox(_T("Done !"),_T("Regenerate package '")
567                      +std2wx(pack)+_T("' doc"),
568                      wxOK | wxICON_INFORMATION);
569         */
570       }
571     else 
572       {
573         SetStatusText( _T("Done !"));
574         wxString err(_T("An error occured while running '"));
575         err +=  bbtk::std2wx(command) + _T("'");
576         wxMessageBox(err,_T("Regenerate package doc"),wxOK | wxICON_ERROR);      
577       }
578
579
580
581   }
582
583
584   //================================================================
585   void WxGUIScriptingInterface::OnMenuRegeneratePackageDoc(wxCommandEvent& WXUNUSED(event))
586   {
587     wxString name = wxGetTextFromUser(_T("Enter package name (-a for all)"),
588                                       _T("Regenerate package doc"),
589                                       _T(""));
590     if (name.IsEmpty()) return;
591     std::string pack = bbtk::wx2std(name);
592     
593         DoRegeneratePackageDoc(pack);
594   }
595   //================================================================
596
597
598   //================================================================
599   void WxGUIScriptingInterface::DoRegenerateBoxesLists()
600   {
601     SetStatusText( _T("Regenerating boxes lists ... please wait") );
602     BBTK_BUSY_CURSOR ;
603
604     std::string command;
605 #if defined(WIN32)
606         command = "\"";
607 #endif
608     command += ConfigurationFile::GetInstance().Get_bin_path();
609     command += ConfigurationFile::GetInstance().Get_file_separator();
610     command += "bbRegenerateBoxesLists";
611 #if defined(WIN32)
612         command += "\"";
613 #endif
614         command += " -q";
615         bbtkMessage("debug",1,"Executing system command '"<<command<<"'"<<std::endl);
616
617
618
619     if ( ! system ( command.c_str() ) )
620       {
621         SetStatusText( _T("Done !"));
622         /*
623         wxMessageBox(_T("Done !"),_T("Regenerate boxes lists"),
624                      wxOK | wxICON_INFORMATION);
625         */
626       }
627     else 
628       {
629         SetStatusText( _T("Done !"));
630         wxString err(_T("An error occured while running '"));
631         err +=  bbtk::std2wx(command) + _T("'");
632         wxMessageBox(err,_T("Regenerate boxes lists"),wxOK | wxICON_ERROR);      
633       }
634   }
635   //================================================================
636
637
638   //================================================================
639   void WxGUIScriptingInterface::OnMenuRegenerateBoxesLists(wxCommandEvent& WXUNUSED(event))
640   {
641         DoRegenerateBoxesLists();
642   }
643   //================================================================
644
645   //================================================================
646   void WxGUIScriptingInterface::OnMenuRegenerateAll(wxCommandEvent& WXUNUSED(event))
647   {
648         
649     DoRegeneratePackageDoc("-a");       
650         DoRegenerateBoxesLists();
651   }
652   //================================================================
653
654  
655   //================================================================
656   void WxGUIScriptingInterface::OnMenuPlugPackage(wxCommandEvent& WXUNUSED(event))
657   {
658     long style = wxDD_DEFAULT_STYLE | wxDD_DIR_MUST_EXIST;
659     wxDirDialog* FD = 
660       new wxDirDialog( 0, 
661                        _T("Select package directory"),
662                        _T(""),
663                        style);
664     
665     if (FD->ShowModal()==wxID_OK)
666       {
667         std::string path = wx2std (FD->GetPath()) ;
668         std::string fname = path + "/bbtkPackage"; 
669         if ( ! Utilities::FileExists( fname ) )
670           {
671             wxString err(_T("The directory does not contain a 'bbtkPackage' file"));
672             wxMessageBox(err,_T("Plug package"),wxOK | wxICON_ERROR);      
673             return;
674           }
675         
676         std::ifstream f;
677         f.open(fname.c_str());
678         std::string pname;
679         f >> pname;
680         f.close();
681         
682         
683         bbtk::ConfigurationFile::GetInstance().AddPackagePathsAndWrite( path );
684         
685         DoRegeneratePackageDoc(pname);
686         DoRegenerateBoxesLists();
687
688           }     
689   }
690   //================================================================
691
692   //================================================================
693   void WxGUIScriptingInterface::InterpreterUserViewHtmlPage(const std::string& page)
694   {
695     std::string s(page);
696     //  std::cout << "WxGUIScriptingInterface::ShowHtmlPage('"<<page<<"')"<<std::endl;
697     if (mWxGUIHtmlBrowser->GoTo(s)) 
698       {
699 //EED   mwxNotebook->ChangeSelection(1);
700 //      mwxNotebook->SetSelection(1);
701       }
702     else 
703       {
704          // std::cout << "ERROR html"<<std::endl;
705       }
706   } 
707   //================================================================  
708   
709   /*
710   //================================================================
711   void WxGUIScriptingInterface::InterpreterUserOnBreak()
712   {
713     //    std::cout << "Break" << std::endl;
714     
715   }
716   //================================================================
717   */
718
719   //================================================================  
720   bool WxGUIScriptingInterface::WxGUIHtmlBrowserUserOnLinkClicked(const std::string& target)
721   {
722     size_t s = target.length();
723     if ((s>3) && (target[s-1]=='s')
724         && (target[s-2]=='b')
725         && (target[s-3]=='b')
726         && (target[s-4]=='.'))
727       {
728         mWxGUITextEditor->Open(target);
729 #if NOTEBOOK
730         mwxNotebook->SetSelection(0);
731 #endif
732         mWxGUITextEditor->SetFocus();
733         return false;
734       }
735     return true;
736   }
737   //================================================================  
738
739   void WxGUIScriptingInterface::OnMenuWindowsCheck( wxCommandEvent& event, 
740                                                     wxWindow* w)
741   {
742     bool checked = event.IsChecked();
743     bool shown = m_mgr.GetPane(w).IsShown();
744     //    std::cout << "checked = "<<checked<<" - shown = "<<shown<<std::endl;
745     if (checked ^ shown) 
746       {
747         m_mgr.GetPane(w).Show(checked);
748         m_mgr.Update();
749       }
750   }
751
752
753   //================================================================  
754   void WxGUIScriptingInterface::OnMenuWindowsFiles(wxCommandEvent& event)
755   {
756     OnMenuWindowsCheck(event,mWxGUITextEditor);
757   }
758   //================================================================  
759
760   //================================================================  
761   void  WxGUIScriptingInterface::OnMenuWindowsHelp(wxCommandEvent& event)
762   {
763     OnMenuWindowsCheck(event,mWxGUIHtmlBrowser);
764   }
765   //================================================================  
766
767   //================================================================  
768   void  WxGUIScriptingInterface::OnMenuWindowsMessages(wxCommandEvent& event)
769   {
770     OnMenuWindowsCheck(event,mWxGUIOutputMessages);
771   }
772   //================================================================  
773
774   //================================================================  
775   void  WxGUIScriptingInterface::OnMenuWindowsCommand(wxCommandEvent& event)
776   {
777     OnMenuWindowsCheck(event,mWxGUICommand);
778   }
779   //================================================================  
780
781   //================================================================  
782   void WxGUIScriptingInterface::OnMenuWindowsSave( wxCommandEvent& WXUNUSED(event))
783   {
784     SavePerspective();
785   }
786   //================================================================  
787
788   //================================================================  
789   void WxGUIScriptingInterface::SavePerspective()
790   {
791     //    std::cout  << "Saving configuration..."<<std::endl;
792     std::string conf = wx2std(m_mgr.SavePerspective());
793     std::string fname = Utilities::MakeUserSettingsFullFileName("bbStudio.aui");
794     std::ofstream f;
795     f.open(fname.c_str(), std::ios::out );
796     f << conf << std::endl;
797
798     //    int x,y;
799     //    GetPosition(&x,&y);
800     //    f << x << "  " << y << std::endl;
801
802
803     int w,h;
804     GetSize(&w,&h);
805
806     f << w << " " << h << std::endl;
807
808     f.close();
809   }
810   //================================================================  
811
812   //================================================================  
813   void WxGUIScriptingInterface::LoadPerspective()
814   {
815     std::string fname = 
816       Utilities::MakeUserSettingsFullFileName("bbStudio.aui");
817     if ( Utilities::FileExists( fname ))
818       {
819         //      std::cout  << "Loading configuration..."<<std::endl;
820
821         std::ifstream f;
822         f.open(fname.c_str());
823         std::string conf;
824         f >> conf;
825
826         //      int x,y;
827         //      f >> x >> y ;
828
829         int w,h;
830         f >> w >> h ;
831
832         f.close();
833         
834         //      std::cout << conf << std::endl;
835
836         //      Move(x,y);
837         SetSize(w,h);
838         m_mgr.LoadPerspective(std2wx(conf));
839       }
840     else 
841       {
842         m_mgr.Update();
843       }
844   }
845   //================================================================  
846
847   //================================================================  
848   void WxGUIScriptingInterface::OnPaneClose(wxAuiManagerEvent& evt)
849   {
850     std::cout  << "Closing panel '"<<evt.pane->name<<"'"<<std::endl;
851     // TO DO : Uncheck 
852     //    OnMenuWindowsCheck( wxCommandEvent& event, wxWindow* w);
853   }
854   //================================================================  
855
856   
857   //================================================================  
858   BEGIN_EVENT_TABLE(WxGUIScriptingInterface, wxFrame)
859     EVT_MENU(ID_Menu_Quit, WxGUIScriptingInterface::OnMenuQuit)
860     EVT_MENU(ID_Menu_About, WxGUIScriptingInterface::OnMenuAbout)
861     EVT_MENU(ID_Menu_EditConfig, WxGUIScriptingInterface::OnMenuEditConfig)
862     EVT_MENU(ID_Menu_CreatePackage, WxGUIScriptingInterface::OnMenuCreatePackage)
863     EVT_MENU(ID_Menu_CreateBlackBox, WxGUIScriptingInterface::OnMenuCreateBlackBox)
864     EVT_MENU(ID_Menu_ShowImageGraph, WxGUIScriptingInterface::OnMenuShowImageGraph)
865     EVT_MENU(ID_Menu_RegeneratePackageDoc, WxGUIScriptingInterface::OnMenuRegeneratePackageDoc)
866     EVT_MENU(ID_Menu_RegenerateBoxesLists, WxGUIScriptingInterface::OnMenuRegenerateBoxesLists)
867     EVT_MENU(ID_Menu_RegenerateAll, WxGUIScriptingInterface::OnMenuRegenerateAll)
868     EVT_MENU(ID_Menu_PlugPackage, WxGUIScriptingInterface::OnMenuPlugPackage)
869     EVT_MENU(ID_Menu_Windows_Files, WxGUIScriptingInterface::OnMenuWindowsFiles)
870     EVT_MENU(ID_Menu_Windows_Help, WxGUIScriptingInterface::OnMenuWindowsHelp)
871     EVT_MENU(ID_Menu_Windows_Messages, WxGUIScriptingInterface::OnMenuWindowsMessages)
872     EVT_MENU(ID_Menu_Windows_Command, WxGUIScriptingInterface::OnMenuWindowsCommand)
873     EVT_MENU(ID_Menu_Windows_Save, WxGUIScriptingInterface::OnMenuWindowsSave)
874     EVT_MENU(ID_Menu_Windows_PackageBrowser, WxGUIScriptingInterface::OnMenuWindowsPackageBrowser)
875     EVT_AUI_PANE_CLOSE(WxGUIScriptingInterface::OnPaneClose)
876   //    EVT_BUTTON(ID_Button_Run, WxGUIScriptingInterface::OnButtonRun )
877     END_EVENT_TABLE()
878   //================================================================
879
880 } // namespace bbtk
881
882
883 #endif //_USE_WXWIDGETS_