1 /*=========================================================================
4 Module: $RCSfile: bbtkWxGUIScriptingInterface.cxx,v $
6 Date: $Date: 2008/10/08 14:46:42 $
7 Version: $Revision: 1.24 $
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 (-a for all)"),
443 _T("Regenerate package doc"),
445 if (name.IsEmpty()) return;
446 std::string pack = bbtk::wx2std(name);
449 command = ConfigurationFile::GetInstance().Get_bin_path();
450 command += ConfigurationFile::GetInstance().Get_file_separator();
451 command += "bbRegeneratePackageDoc " + pack;
452 bbtkMessage("debug",1,"Executing system command '"<<command<<"'"<<std::endl);
454 if ( ! system ( command.c_str() ) )
456 wxMessageBox(_T("Done !"),_T("Regenerate package '")+name+_T("' doc"),
457 wxOK | wxICON_INFORMATION);
461 wxString err(_T("An error occured while running '"));
462 err += bbtk::std2wx(command) + _T("'");
463 wxMessageBox(err,_T("Regenerate package doc"),wxOK | wxICON_ERROR);
466 //================================================================
468 //================================================================
469 void WxGUIScriptingInterface::OnMenuRegenerateBoxesLists(wxCommandEvent& WXUNUSED(event))
472 command = ConfigurationFile::GetInstance().Get_bin_path();
473 command += ConfigurationFile::GetInstance().Get_file_separator();
474 command += "bbRegenerateBoxesLists";
475 bbtkMessage("debug",1,"Executing system command '"<<command<<"'"<<std::endl);
477 if ( ! system ( command.c_str() ) )
479 wxMessageBox(_T("Done !"),_T("Regenerate boxes lists"),
480 wxOK | wxICON_INFORMATION);
484 wxString err(_T("An error occured while running '"));
485 err += bbtk::std2wx(command) + _T("'");
486 wxMessageBox(err,_T("Regenerate boxes lists"),wxOK | wxICON_ERROR);
489 //================================================================
491 //================================================================
492 void WxGUIScriptingInterface::OnMenuRegenerateAll(wxCommandEvent& WXUNUSED(event))
495 command = ConfigurationFile::GetInstance().Get_bin_path();
496 command += ConfigurationFile::GetInstance().Get_file_separator();
497 command += "bbRegeneratePackageDoc * && ";
498 command = ConfigurationFile::GetInstance().Get_bin_path();
499 command += ConfigurationFile::GetInstance().Get_file_separator();
500 command += "bbRegenerateBoxesLists";
501 bbtkMessage("debug",1,"Executing system command '"<<command<<"'"<<std::endl);
503 if ( ! system ( command.c_str() ) )
505 wxMessageBox(_T("Done !"),_T("Regenerate all"),
506 wxOK | wxICON_INFORMATION);
510 wxString err(_T("An error occured while running '"));
511 err += bbtk::std2wx(command) + _T("'");
512 wxMessageBox(err,_T("Regenerate all"),wxOK | wxICON_ERROR);
515 //================================================================
519 //================================================================
520 void WxGUIScriptingInterface::InterpreterUserViewHtmlPage(const std::string& page)
523 // std::cout << "WxGUIScriptingInterface::ShowHtmlPage('"<<page<<"')"<<std::endl;
524 if (mWxGUIHtmlBrowser->GoTo(s))
526 //EED mwxNotebook->ChangeSelection(1);
527 // mwxNotebook->SetSelection(1);
531 // std::cout << "ERROR html"<<std::endl;
534 //================================================================
536 //================================================================
537 bool WxGUIScriptingInterface::WxGUIHtmlBrowserUserOnLinkClicked(const std::string& target)
539 size_t s = target.length();
540 if ((s>3) && (target[s-1]=='s')
541 && (target[s-2]=='b')
542 && (target[s-3]=='b')
543 && (target[s-4]=='.'))
545 mWxGUITextEditor->Open(target);
547 mwxNotebook->SetSelection(0);
549 mWxGUITextEditor->SetFocus();
554 //================================================================
556 void WxGUIScriptingInterface::OnMenuWindowsCheck( wxCommandEvent& event,
559 bool checked = event.IsChecked();
560 bool shown = m_mgr.GetPane(w).IsShown();
561 // std::cout << "checked = "<<checked<<" - shown = "<<shown<<std::endl;
564 m_mgr.GetPane(w).Show(checked);
570 //================================================================
571 void WxGUIScriptingInterface::OnMenuWindowsFiles(wxCommandEvent& event)
573 OnMenuWindowsCheck(event,mWxGUITextEditor);
575 //================================================================
577 //================================================================
578 void WxGUIScriptingInterface::OnMenuWindowsHelp(wxCommandEvent& event)
580 OnMenuWindowsCheck(event,mWxGUIHtmlBrowser);
582 //================================================================
584 //================================================================
585 void WxGUIScriptingInterface::OnMenuWindowsMessages(wxCommandEvent& event)
587 OnMenuWindowsCheck(event,mWxGUIOutputMessages);
589 //================================================================
591 //================================================================
592 void WxGUIScriptingInterface::OnMenuWindowsCommand(wxCommandEvent& event)
594 OnMenuWindowsCheck(event,mWxGUICommand);
596 //================================================================
598 //================================================================
599 void WxGUIScriptingInterface::OnMenuWindowsSave( wxCommandEvent& WXUNUSED(event))
603 //================================================================
605 //================================================================
606 void WxGUIScriptingInterface::SavePerspective()
608 // std::cout << "Saving configuration..."<<std::endl;
609 std::string conf = wx2std(m_mgr.SavePerspective());
610 std::string fname = Utilities::MakeUserSettingsFullFileName("bbStudio.aui");
612 f.open(fname.c_str(), std::ios::out );
613 f << conf << std::endl;
616 // GetPosition(&x,&y);
617 // f << x << " " << y << std::endl;
623 f << w << " " << h << std::endl;
627 //================================================================
629 //================================================================
630 void WxGUIScriptingInterface::LoadPerspective()
633 Utilities::MakeUserSettingsFullFileName("bbStudio.aui");
634 if ( Utilities::FileExists( fname ))
636 // std::cout << "Loading configuration..."<<std::endl;
639 f.open(fname.c_str());
651 // std::cout << conf << std::endl;
655 m_mgr.LoadPerspective(std2wx(conf));
662 //================================================================
664 //================================================================
665 void WxGUIScriptingInterface::OnPaneClose(wxAuiManagerEvent& evt)
667 std::cout << "Closing panel '"<<evt.pane->name<<"'"<<std::endl;
669 // OnMenuWindowsCheck( wxCommandEvent& event, wxWindow* w);
671 //================================================================
674 //================================================================
675 BEGIN_EVENT_TABLE(WxGUIScriptingInterface, wxFrame)
676 EVT_MENU(ID_Menu_Quit, WxGUIScriptingInterface::OnMenuQuit)
677 EVT_MENU(ID_Menu_About, WxGUIScriptingInterface::OnMenuAbout)
678 EVT_MENU(ID_Menu_EditConfig, WxGUIScriptingInterface::OnMenuEditConfig)
679 EVT_MENU(ID_Menu_CreatePackage, WxGUIScriptingInterface::OnMenuCreatePackage)
680 EVT_MENU(ID_Menu_CreateBlackBox, WxGUIScriptingInterface::OnMenuCreateBlackBox)
681 EVT_MENU(ID_Menu_ShowImageGraph, WxGUIScriptingInterface::OnMenuShowImageGraph)
682 EVT_MENU(ID_Menu_RegeneratePackageDoc, WxGUIScriptingInterface::OnMenuRegeneratePackageDoc)
683 EVT_MENU(ID_Menu_RegenerateBoxesLists, WxGUIScriptingInterface::OnMenuRegenerateBoxesLists)
684 EVT_MENU(ID_Menu_RegenerateAll, WxGUIScriptingInterface::OnMenuRegenerateAll)
685 EVT_MENU(ID_Menu_Windows_Files, WxGUIScriptingInterface::OnMenuWindowsFiles)
686 EVT_MENU(ID_Menu_Windows_Help, WxGUIScriptingInterface::OnMenuWindowsHelp)
687 EVT_MENU(ID_Menu_Windows_Messages, WxGUIScriptingInterface::OnMenuWindowsMessages)
688 EVT_MENU(ID_Menu_Windows_Command, WxGUIScriptingInterface::OnMenuWindowsCommand)
689 EVT_MENU(ID_Menu_Windows_Save, WxGUIScriptingInterface::OnMenuWindowsSave)
690 EVT_MENU(ID_Menu_Windows_PackageBrowser, WxGUIScriptingInterface::OnMenuWindowsPackageBrowser)
691 EVT_AUI_PANE_CLOSE(WxGUIScriptingInterface::OnPaneClose)
692 // EVT_BUTTON(ID_Button_Run, WxGUIScriptingInterface::OnButtonRun )
694 //================================================================
699 #endif //_USE_WXWIDGETS_