1 /*=========================================================================
4 Module: $RCSfile: bbtkWxGUIScriptingInterface.cxx,v $
6 Date: $Date: 2008/10/08 12:19:56 $
7 Version: $Revision: 1.23 $
9 Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
10 l'Image). All rights reserved. See Doc/License.txt or
11 http://www.creatis.insa-lyon.fr/Public/bbtk/License.html for details.
13 This software is distributed WITHOUT ANY WARRANTY; without even
14 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 PURPOSE. See the above copyright notices for more information.
17 =========================================================================*//**
18 * \brief Short description in one line
20 * Long description which
21 * can span multiple lines
33 #ifdef _USE_WXWIDGETS_
36 #include "bbtkWxGUIScriptingInterface.h"
37 #include "bbtkWxBlackBox.h"
38 #include "bbtkConfigurationFile.h"
39 #include "bbtkWxStreamRedirector.h"
40 #include "bbtkUtilities.h"
42 #include <wx/tipwin.h>
44 //#include "icons/cc_run.xpm"
54 ID_Menu_CreatePackage,
55 ID_Menu_CreateBlackBox,
56 ID_Menu_ShowImageGraph,
57 ID_Menu_RegeneratePackageDoc,
58 ID_Menu_RegenerateBoxesLists,
59 ID_Menu_RegenerateAll,
60 ID_Menu_Windows_Files,
62 ID_Menu_Windows_Messages,
63 ID_Menu_Windows_Command,
65 ID_Menu_Windows_PackageBrowser
70 //================================================================
71 WxGUIScriptingInterface::WxGUIScriptingInterface( wxWindow *parent )
72 : wxFrame((wxFrame *)parent, -1, _T("bbStudio"),
73 wxDefaultPosition, wxSize(1200,800) )
75 // m_mgr = new wxAuiManager(this);
76 m_mgr.SetManagedWindow(this);
78 mInterpreter = bbtk::Interpreter::New();
79 mInterpreter->SetUser(this);
80 mInterpreter->SetCommandLine(true);
81 mInterpreter->SetThrow(true);
85 wxInitAllImageHandlers();
87 wxMenu *menuFile = new wxMenu;
88 menuFile->Append( ID_Menu_EditConfig, _T("Open bbtk &Config file") );
89 menuFile->Append( ID_Menu_Quit, _T("&Quit") );
91 wxMenu *menuAbout = new wxMenu;
92 menuAbout->Append( ID_Menu_About, _T("&About...") );
94 wxMenu *menuTools = new wxMenu;
95 menuTools->Append( ID_Menu_CreatePackage, _T("Create &package") );
96 menuTools->Append( ID_Menu_CreateBlackBox, _T("Create &black box") );
97 menuTools->Append( ID_Menu_ShowImageGraph, _T("&Show last image graph") );
98 menuTools->AppendSeparator();
99 menuTools->Append( ID_Menu_RegeneratePackageDoc,_T("&Regenerate package doc") );
100 menuTools->Append( ID_Menu_RegenerateBoxesLists,_T("&Regenerate boxes lists") );
101 menuTools->Append( ID_Menu_RegenerateAll,_T("&Regenerate all") );
104 wxMenu *menuWindows = new wxMenu;
105 menuWindows->AppendCheckItem(ID_Menu_Windows_Files,
106 _T("Show 'files' panel") )->Check();
107 menuWindows->AppendCheckItem(ID_Menu_Windows_Help,
108 _T("Show 'help' panel") )->Check();
109 menuWindows->AppendCheckItem(ID_Menu_Windows_Messages,
110 _T("Show 'messages' panel") )->Check();
111 menuWindows->AppendCheckItem(ID_Menu_Windows_Command,
112 _T("Show 'command' panel") )->Check();
113 menuWindows->AppendSeparator();
114 menuWindows->Append( ID_Menu_Windows_PackageBrowser, _T("Launch Package &Browser") );
116 // menuWindows->AppendSeparator();
117 // menuWindows->Append ( ID_Menu_Windows_Save, _T("Save interface configuration"));
119 wxMenu *menuOptions = new wxMenu;
120 mwxMenuItemReset = menuOptions->AppendCheckItem(-1,
121 _T("Reset before running") );
122 mwxMenuItemReset->Check();
124 wxMenuBar *menuBar = new wxMenuBar;
125 menuBar->Append( menuFile, _T("&File") );
126 menuBar->Append( menuTools, _T("&Tools") );
127 menuBar->Append( menuOptions, _T("&Options") );
128 menuBar->Append( menuWindows, _T("&Windows") );
129 menuBar->Append( menuAbout, _T("About") );
131 SetMenuBar( menuBar );
136 SetStatusText( _T("Welcome to bbStudio !") );
139 // Panes (Files, Messages, Help, Command)
140 mWxGUITextEditor = new WxGUITextEditor(this,this);
141 mWxGUITextEditor->SetFileNameFilter("*.bbs");
143 mWxGUIHtmlBrowser = new WxGUIHtmlBrowser(this,wxSize(200,0),this);
145 mWxGUIOutputMessages = new WxGUIOutputMessages(this);
147 mWxGUICommand = new WxGUICommand(this,this);
149 mWxGUICommand->SetFocus();
154 mwxNotebook = new wxAuiNotebook(this,
160 | wxAUI_NB_TAB_EXTERNAL_MOVE
161 //| wxAUI_NB_WINDOWLIST_BUTTON
162 //|wxAUI_NB_SCROLL_BUTTONS
163 // | wxAUI_NB_CLOSE_BUTTON
164 //| wxAUI_NB_CLOSE_ON_ACTIVE_TAB
165 //| wxAUI_NB_CLOSE_ON_ALL_TABS
169 mwxNotebook->AddPage(mWxGUITextEditor,_T("Files"),true);
170 mwxNotebook->AddPage(mWxGUIHtmlBrowser,_T("Help"),true);
172 mwxNotebook->AddPage(mWxGUIOutputMessages,_T("Messages"),true);
174 mwxNotebook->AddPage(mWxGUICommand,_T("Command"),true);
177 m_mgr.AddPane(mwxNotebook,
178 wxAuiPaneInfo().Name(wxT("nb"))
179 .CaptionVisible(false)
180 .MinimizeButton(false)
181 .MaximizeButton(false)
183 // .MinSize(wxSize(100,100))
188 m_mgr.AddPane(mWxGUITextEditor,
189 wxAuiPaneInfo().Name(wxT("editor_content"))
190 .Caption(wxT("Files"))
191 .MinimizeButton(true)
192 .MaximizeButton(true)
194 .MinSize(wxSize(100,100))
197 m_mgr.AddPane(mWxGUIHtmlBrowser,
198 wxAuiPaneInfo().Name(wxT("browser_content"))
199 .Caption(wxT("Help"))
200 .MinimizeButton(true)
201 .MaximizeButton(true)
204 .MinSize(wxSize(400,100))
207 m_mgr.AddPane(mWxGUIOutputMessages,
208 wxAuiPaneInfo().Name(wxT("messages_content"))
209 .Caption(wxT("Messages"))
210 .MinimizeButton(true)
211 .MaximizeButton(true)
213 .MinSize(wxSize(100,100))
215 m_mgr.AddPane(mWxGUICommand,
216 wxAuiPaneInfo().Name(wxT("command_content"))
217 .Caption(wxT("Command"))
218 .MinimizeButton(true)
219 .MaximizeButton(true)
222 .MinSize(wxSize(100,100))
226 // parent window of all bbtk windows will be a child of this
227 Wx::SetTopWindowParent(this);
228 // Add the method OnWxSignal as a Wx::Signal observer
229 //bbtkAddWxSignalObserver(WxGUIPackageBrowser2Window::OnWxSignal);
231 //.PaneBorder(false));
232 // Load the interface appearance saved on last closing
235 // Done in LoadPerspective
240 // mwxNotebook->SetSelection(1);
241 mWxGUIHtmlBrowser->GoHome();
244 // LoadPerspective();
247 wxTipWindow* tip = new wxTipWindow(this,
248 _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);
249 tip->CenterOnParent();
252 //================================================================
254 //================================================================
255 WxGUIScriptingInterface::~WxGUIScriptingInterface()
260 //================================================================
262 //================================================================
263 void WxGUIScriptingInterface::Open(const std::string& filename)
265 mWxGUITextEditor->Open(filename);
267 //================================================================
269 #define CATCH_MACRO \
270 catch (QuitException e) \
272 std::cout << "* quit exception caught"<<std::endl; \
274 catch (InterpreterError e) \
276 std::cerr << "* IERROR : "<<e.GetErrorMessage()<<std::endl; \
277 if (e.IsInScriptFile()) \
278 std::cerr << "* FILE : '"<<e.GetScriptFile()<<"'"<<std::endl; \
279 std::cerr << "* LINE : "<<e.GetScriptLine()<<std::endl; \
280 int lev = bbtk::MessageManager::GetMessageLevel("Error"); \
282 std::cerr << "* Exception thrown : "<<std::endl; \
283 std::cerr << "* OBJECT : " <<e.GetObject()<<std::endl; \
284 std::cerr << "* FILE : " <<e.GetSourceFile()<<std::endl; \
288 //================================================================
289 void WxGUIScriptingInterface::WxGUICommandEnter(const std::string& command)
293 mWxGUIOutputMessages->Print(s,wxRED);
297 mInterpreter->InterpretLine( command );
301 //================================================================
303 //================================================================
304 /// Runs the interpretation of a file
305 bool WxGUIScriptingInterface::InterpretFile( const std::string& filename)
309 mInterpreter->InterpretFile(filename);
314 //================================================================
316 //================================================================
317 void WxGUIScriptingInterface::WxGUITextEditorRun()
319 // wxString temp = mWxGUIHtmlBrowser->GetCurrentPage();
320 std::stringstream* buf = new std::stringstream;
321 (*buf) << mWxGUITextEditor->GetCurrentPage()->GetText();
324 // std::cout << "RUN"<<std::endl;
325 if (mwxMenuItemReset->IsChecked()) WxGUICommandEnter("reset");
326 mInterpreter->InterpretBuffer(buf);
327 // std::cout << "EO RUN"<<std::endl;
330 // std::cout << "EO RUN 3"<<std::endl;
332 //================================================================
334 //================================================================
335 void WxGUIScriptingInterface::OnMenuQuit(wxCommandEvent& WXUNUSED(event))
337 if (!mWxGUITextEditor->CloseAllPages()) return;
340 //================================================================
343 //================================================================
344 void WxGUIScriptingInterface::OnMenuAbout(wxCommandEvent& WXUNUSED(event))
348 wxMessageBox(_T(" bbStudio\nThe Black Box Toolkit Development Studio\n(c) CREATIS-LRMN 2008"),
349 _T("About ..."), wxOK | wxICON_INFORMATION,
352 //================================================================
355 //================================================================
356 void WxGUIScriptingInterface::OnMenuEditConfig(wxCommandEvent& WXUNUSED(event))
358 std::string configFile =
359 ConfigurationFile::GetInstance().Get_config_xml_full_path();
362 //================================================================
364 //================================================================
365 void WxGUIScriptingInterface::OnMenuWindowsPackageBrowser(wxCommandEvent& WXUNUSED(event))
368 WxGUIPackageBrowser2Window *helpbrowser = new
369 WxGUIPackageBrowser2Window(this,_T("Package Browser"), wxSize(600,600) );
374 WxGUIPackageBrowser2 *browser = new WxGUIPackageBrowser2(this);
375 browser->IncludeAll();
378 // mwxNotebook->AddPage(browser,_T("Package Browser"),true);
381 m_mgr.AddPane(browser,
382 wxAuiPaneInfo().Name(wxT("package_brower"))
383 .Caption(wxT("Package browser"))
384 .MinimizeButton(true)
385 .MaximizeButton(true)
388 .MinSize(wxSize(100,100))
393 //================================================================
397 //================================================================
398 void WxGUIScriptingInterface::OnMenuCreatePackage(wxCommandEvent& WXUNUSED(event))
401 std::string command("toolsbbtk/appli/GUICreatePackage");
402 bbtkMessage("Debug",1,"Executing : '"<<command<<"'"<<std::endl);
404 Interpreter::Pointer I = Interpreter::New();
405 I->InterpretFile(command);
408 //================================================================
411 //================================================================
412 void WxGUIScriptingInterface::OnMenuCreateBlackBox(wxCommandEvent& WXUNUSED(event))
414 std::string command("toolsbbtk/appli/GUICreateBlackBox");
415 bbtkMessage("Debug",1,"Executing : '"<<command<<"'"<<std::endl);
417 Interpreter::Pointer I = Interpreter::New();
418 I->InterpretFile(command);
420 //================================================================
422 //================================================================
423 void WxGUIScriptingInterface::OnMenuShowImageGraph(wxCommandEvent& WXUNUSED(event))
425 std::string default_temp_dir = ConfigurationFile::GetInstance().Get_default_temp_dir();
428 std::string strappli="start ";
430 std::string strappli="gnome-open ";
432 std::string strcommand = strappli +default_temp_dir+"/temp_dir/workspace_workspacePrototype.png";
433 // std::cout << "system: " << strcommand << std::endl;
434 system ( strcommand.c_str() );
437 //================================================================
439 //================================================================
440 void WxGUIScriptingInterface::OnMenuRegeneratePackageDoc(wxCommandEvent& WXUNUSED(event))
442 wxString name = wxGetTextFromUser(_T("Enter package name (* for all)"),
443 _T("Regenerate package doc"),
445 if (name.IsEmpty()) return;
446 std::string pack = bbtk::wx2std(name);
448 std::string command("cd \"");
449 command += ConfigurationFile::GetInstance().Get_bin_path();
450 command += "\" && bbRegeneratePackageDoc " + pack;
451 bbtkMessage("debug",1,"Executing system command '"<<command<<"'"<<std::endl);
453 if ( ! system ( command.c_str() ) )
455 wxMessageBox(_T("Done !"),_T("Regenerate package '")+name+_T("' doc"),
456 wxOK | wxICON_INFORMATION);
460 wxString err(_T("An error occured while running '"));
461 err += bbtk::std2wx(command) + _T("'");
462 wxMessageBox(err,_T("Regenerate package doc"),wxOK | wxICON_ERROR);
465 //================================================================
467 //================================================================
468 void WxGUIScriptingInterface::OnMenuRegenerateBoxesLists(wxCommandEvent& WXUNUSED(event))
470 std::string command("cd \"");
471 command += ConfigurationFile::GetInstance().Get_bin_path();
472 command += "\" && bbRegenerateBoxesLists";
473 bbtkMessage("debug",1,"Executing system command '"<<command<<"'"<<std::endl);
475 if ( ! system ( command.c_str() ) )
477 wxMessageBox(_T("Done !"),_T("Regenerate boxes lists"),
478 wxOK | wxICON_INFORMATION);
482 wxString err(_T("An error occured while running '"));
483 err += bbtk::std2wx(command) + _T("'");
484 wxMessageBox(err,_T("Regenerate boxes lists"),wxOK | wxICON_ERROR);
487 //================================================================
489 //================================================================
490 void WxGUIScriptingInterface::OnMenuRegenerateAll(wxCommandEvent& WXUNUSED(event))
492 std::string command("cd \"");
493 command += ConfigurationFile::GetInstance().Get_bin_path();
494 command += "\" && bbRegeneratePackageDoc * && bbRegenerateBoxesLists";
495 bbtkMessage("debug",1,"Executing system command '"<<command<<"'"<<std::endl);
497 if ( ! system ( command.c_str() ) )
499 wxMessageBox(_T("Done !"),_T("Regenerate all"),
500 wxOK | wxICON_INFORMATION);
504 wxString err(_T("An error occured while running '"));
505 err += bbtk::std2wx(command) + _T("'");
506 wxMessageBox(err,_T("Regenerate all"),wxOK | wxICON_ERROR);
509 //================================================================
513 //================================================================
514 void WxGUIScriptingInterface::InterpreterUserViewHtmlPage(const std::string& page)
517 // std::cout << "WxGUIScriptingInterface::ShowHtmlPage('"<<page<<"')"<<std::endl;
518 if (mWxGUIHtmlBrowser->GoTo(s))
520 //EED mwxNotebook->ChangeSelection(1);
521 // mwxNotebook->SetSelection(1);
525 // std::cout << "ERROR html"<<std::endl;
528 //================================================================
530 //================================================================
531 bool WxGUIScriptingInterface::WxGUIHtmlBrowserUserOnLinkClicked(const std::string& target)
533 size_t s = target.length();
534 if ((s>3) && (target[s-1]=='s')
535 && (target[s-2]=='b')
536 && (target[s-3]=='b')
537 && (target[s-4]=='.'))
539 mWxGUITextEditor->Open(target);
541 mwxNotebook->SetSelection(0);
543 mWxGUITextEditor->SetFocus();
548 //================================================================
550 void WxGUIScriptingInterface::OnMenuWindowsCheck( wxCommandEvent& event,
553 bool checked = event.IsChecked();
554 bool shown = m_mgr.GetPane(w).IsShown();
555 // std::cout << "checked = "<<checked<<" - shown = "<<shown<<std::endl;
558 m_mgr.GetPane(w).Show(checked);
564 //================================================================
565 void WxGUIScriptingInterface::OnMenuWindowsFiles(wxCommandEvent& event)
567 OnMenuWindowsCheck(event,mWxGUITextEditor);
569 //================================================================
571 //================================================================
572 void WxGUIScriptingInterface::OnMenuWindowsHelp(wxCommandEvent& event)
574 OnMenuWindowsCheck(event,mWxGUIHtmlBrowser);
576 //================================================================
578 //================================================================
579 void WxGUIScriptingInterface::OnMenuWindowsMessages(wxCommandEvent& event)
581 OnMenuWindowsCheck(event,mWxGUIOutputMessages);
583 //================================================================
585 //================================================================
586 void WxGUIScriptingInterface::OnMenuWindowsCommand(wxCommandEvent& event)
588 OnMenuWindowsCheck(event,mWxGUICommand);
590 //================================================================
592 //================================================================
593 void WxGUIScriptingInterface::OnMenuWindowsSave( wxCommandEvent& WXUNUSED(event))
597 //================================================================
599 //================================================================
600 void WxGUIScriptingInterface::SavePerspective()
602 // std::cout << "Saving configuration..."<<std::endl;
603 std::string conf = wx2std(m_mgr.SavePerspective());
604 std::string fname = Utilities::MakeUserSettingsFullFileName("bbStudio.aui");
606 f.open(fname.c_str(), std::ios::out );
607 f << conf << std::endl;
610 // GetPosition(&x,&y);
611 // f << x << " " << y << std::endl;
617 f << w << " " << h << std::endl;
621 //================================================================
623 //================================================================
624 void WxGUIScriptingInterface::LoadPerspective()
627 Utilities::MakeUserSettingsFullFileName("bbStudio.aui");
628 if ( Utilities::FileExists( fname ))
630 // std::cout << "Loading configuration..."<<std::endl;
633 f.open(fname.c_str());
645 // std::cout << conf << std::endl;
649 m_mgr.LoadPerspective(std2wx(conf));
656 //================================================================
658 //================================================================
659 void WxGUIScriptingInterface::OnPaneClose(wxAuiManagerEvent& evt)
661 std::cout << "Closing panel '"<<evt.pane->name<<"'"<<std::endl;
663 // OnMenuWindowsCheck( wxCommandEvent& event, wxWindow* w);
665 //================================================================
668 //================================================================
669 BEGIN_EVENT_TABLE(WxGUIScriptingInterface, wxFrame)
670 EVT_MENU(ID_Menu_Quit, WxGUIScriptingInterface::OnMenuQuit)
671 EVT_MENU(ID_Menu_About, WxGUIScriptingInterface::OnMenuAbout)
672 EVT_MENU(ID_Menu_EditConfig, WxGUIScriptingInterface::OnMenuEditConfig)
673 EVT_MENU(ID_Menu_CreatePackage, WxGUIScriptingInterface::OnMenuCreatePackage)
674 EVT_MENU(ID_Menu_CreateBlackBox, WxGUIScriptingInterface::OnMenuCreateBlackBox)
675 EVT_MENU(ID_Menu_ShowImageGraph, WxGUIScriptingInterface::OnMenuShowImageGraph)
676 EVT_MENU(ID_Menu_RegeneratePackageDoc, WxGUIScriptingInterface::OnMenuRegeneratePackageDoc)
677 EVT_MENU(ID_Menu_RegenerateBoxesLists, WxGUIScriptingInterface::OnMenuRegenerateBoxesLists)
678 EVT_MENU(ID_Menu_RegenerateAll, WxGUIScriptingInterface::OnMenuRegenerateAll)
679 EVT_MENU(ID_Menu_Windows_Files, WxGUIScriptingInterface::OnMenuWindowsFiles)
680 EVT_MENU(ID_Menu_Windows_Help, WxGUIScriptingInterface::OnMenuWindowsHelp)
681 EVT_MENU(ID_Menu_Windows_Messages, WxGUIScriptingInterface::OnMenuWindowsMessages)
682 EVT_MENU(ID_Menu_Windows_Command, WxGUIScriptingInterface::OnMenuWindowsCommand)
683 EVT_MENU(ID_Menu_Windows_Save, WxGUIScriptingInterface::OnMenuWindowsSave)
684 EVT_MENU(ID_Menu_Windows_PackageBrowser, WxGUIScriptingInterface::OnMenuWindowsPackageBrowser)
685 EVT_AUI_PANE_CLOSE(WxGUIScriptingInterface::OnPaneClose)
686 // EVT_BUTTON(ID_Button_Run, WxGUIScriptingInterface::OnButtonRun )
688 //================================================================
693 #endif //_USE_WXWIDGETS_