2 # ---------------------------------------------------------------------
4 # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
6 # Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton
7 # Previous Authors : Laurent Guigues, Jean-Pierre Roux
8 # CreaTools website : www.creatis.insa-lyon.fr/site/fr/creatools_accueil
10 # This software is governed by the CeCILL-B license under French law and
11 # abiding by the rules of distribution of free software. You can use,
12 # modify and/ or redistribute the software under the terms of the CeCILL-B
13 # license as circulated by CEA, CNRS and INRIA at the following URL
14 # http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
15 # or in the file LICENSE.txt.
17 # As a counterpart to the access to the source code and rights to copy,
18 # modify and redistribute granted by the license, users are provided only
19 # with a limited warranty and the software's author, the holder of the
20 # economic rights, and the successive licensors have only limited
23 # The fact that you are presently reading this means that you have had
24 # knowledge of the CeCILL-B license and that you accept its terms.
25 # ------------------------------------------------------------------------ */
28 /*=========================================================================
30 Module: $RCSfile: bbtkWxGUIConsole.cxx,v $
32 Date: $Date: 2012/11/16 08:49:01 $
33 Version: $Revision: 1.18 $
34 =========================================================================*/
40 * \brief Short description in one line
42 * Long description which
43 * can span multiple lines
55 #ifdef _USE_WXWIDGETS_
58 #include "bbtkWxGUIConsole.h"
59 #include "bbtkWxBlackBox.h"
60 #include "bbtkConfigurationFile.h"
61 #include "bbtkWxStreamRedirector.h"
64 #include "icons/cc_run.xpm"
74 ID_Menu_CreatePackage,
75 ID_Menu_CreateBlackBox,
76 ID_Menu_ShowImageGraph,
83 //================================================================
84 WxGUIConsole::WxGUIConsole( wxWindow *parent, wxString title, wxSize size)
85 : wxFrame((wxFrame *)parent, -1, title, wxDefaultPosition, size)
87 printf( "EED WxGUIConsole Start \n" );
88 // m_mgr = new wxAuiManager(this);
89 m_mgr.SetManagedWindow(this);
90 printf( "EED WxGUIConsole 0.1 \n" );
92 mInterpreter = bbtk::Interpreter::New();
93 printf( "EED WxGUIConsole 0.2 \n" );
94 mInterpreter->SetUser(this);
95 printf( "EED WxGUIConsole 0.3 \n" );
96 mInterpreter->SetCommandLine(true);
97 printf( "EED WxGUIConsole 0.4 \n" );
98 mInterpreter->SetThrow(false);
99 printf( "EED WxGUIConsole 1\n" );
103 wxInitAllImageHandlers();
105 wxMenu *menuFile = new wxMenu;
106 menuFile->Append( ID_Menu_Quit, _T("&Quit") );
108 wxMenu *menuAbout = new wxMenu;
109 menuAbout->Append( ID_Menu_About, _T("&About...") );
111 wxMenu *menuTools = new wxMenu;
112 menuTools->Append( ID_Menu_EditConfig, _T("&Edit bbtk config") );
113 menuTools->Append( ID_Menu_CreatePackage, _T("Create &package") );
114 menuTools->Append( ID_Menu_CreateBlackBox, _T("Create &blackbox") );
115 menuTools->Append( ID_Menu_ShowImageGraph, _T("&Show last image graph") );
116 menuTools->Append( ID_Menu_ShowHTMLDoc, _T("Show &HTML documentation") );
117 menuTools->Append( ID_Menu_CreateIndex, _T("&Generate index") );
120 wxMenuBar *menuBar = new wxMenuBar;
121 menuBar->Append( menuFile, _T("&File") );
122 menuBar->Append( menuTools, _T("&Tools") );
123 menuBar->Append( menuAbout, _T("About") );
125 SetMenuBar( menuBar );
128 SetStatusText( _T("Welcome to bbi !") );
129 printf( "EED WxGUIConsole 2\n" );
134 // wxFlexGridSizer *sizer = new wxFlexGridSizer(1);
136 //EED wxBoxSizer* sizer = new wxBoxSizer(wxVERTICAL);
137 // mwxNotebook = new wxNotebook(this,-1,wxDefaultPosition, wxDefaultSize, 0);
138 mwxNotebook = new wxAuiNotebook(this,
142 wxAUI_NB_TAB_SPLIT | wxAUI_NB_TAB_EXTERNAL_MOVE | wxNO_BORDER);
144 mwxPageCommand = new wxPanel(mwxNotebook,-1);
145 mwxPageHelp = new wxPanel(mwxNotebook,-1);
148 wxBoxSizer *cmdsizer = new wxBoxSizer(wxVERTICAL);
150 mwxPageCommand->SetAutoLayout(true);
151 mwxPageCommand->SetSizer(cmdsizer);
152 cmdsizer->Fit(mwxPageCommand);
153 cmdsizer->SetSizeHints(mwxPageCommand);
155 wxBoxSizer *helpsizer = new wxBoxSizer(wxVERTICAL);
157 mwxPageHelp->SetAutoLayout(true);
158 mwxPageHelp->SetSizer(helpsizer);
159 helpsizer->Fit(mwxPageHelp);
160 helpsizer->SetSizeHints(mwxPageHelp);
161 printf( "EED WxGUIConsole 3\n" );
163 mWxGUIHtmlBrowser = new WxGUIHtmlBrowser(mwxPageHelp,
164 //EED wxSize(1200,0));
167 // mWxGUIHtmlBrowser->SetSize(wxSize(800,1000));
168 helpsizer->Add (mWxGUIHtmlBrowser,1, wxGROW|wxLEFT|wxRIGHT|wxTOP, 5 );
169 // helpsizer->Add ( new wxButton(mwxPageHelp,-1,"perro"), 0, wxEXPAND );
170 wxBitmap bmp_run(cc_run_xpm);
171 mwxButtonRun = new wxBitmapButton( mwxPageHelp,ID_Button_Run,bmp_run);//_T("Run") );
172 helpsizer->Add( mwxButtonRun, 0, wxALL, 5 );
177 mWxGUIOutputMessages = new WxGUIOutputMessages(mwxPageCommand);
179 mWxGUICommand = new WxGUICommand(mwxPageCommand,this);
181 mWxGUICommand->SetFocus();
183 cmdsizer->Add (mWxGUIOutputMessages, 1, wxALL | wxGROW, 5);
184 cmdsizer->Add (mWxGUICommand, 0, wxALL | wxGROW, 5);
186 printf( "EED WxGUIConsole 4\n" );
188 // Set the parent window of all bbtk windows as a child of this
189 // bbtk::Wx::SetTopWindowParent(this);
190 bbtk::Wx::SetTopWindow(this);
191 // Top Window Auto Destroys when no more black box window alive
192 // : this is the default
193 // bbtk::Wx::SetAutoDestroyTopWindow(true);
194 // Add the method OnWxSignal as a Wx::Signal observer
195 bbtkAddWxSignalObserver(WxGUIConsole::OnWxSignal);
199 //EED SetSizer(sizer);
201 mwxNotebook->AddPage( mwxPageCommand, _T("Command"));
202 mwxNotebook->AddPage( mwxPageHelp, _T("Help"));
203 m_mgr.AddPane(mwxNotebook, wxAuiPaneInfo().Name(wxT("notebook_content")).CenterPane().PaneBorder(false));
210 printf( "EED WxGUIConsole End\n" );
213 //================================================================
215 //================================================================
216 WxGUIConsole::~WxGUIConsole()
220 //================================================================
222 //================================================================
223 void WxGUIConsole::OnClose(wxCloseEvent& event)
225 bbtkDebugMessage("widget",9,"bbi::OnClose()"<<std::endl);
226 //Wx::SetWindowsHaveBeenDestroyedByParent();
227 //mInterpreter.reset();
228 wxWindowList& list = GetChildren();
229 wxWindowList::iterator iter;
230 for (iter = list.begin(); iter != list.end(); ++iter)
236 //================================================================
238 //================================================================
239 void WxGUIConsole::OnWxSignal()
241 if ((!bbtk::Wx::IsSomeWindowAlive())&&(!IsShown()))
243 bbtkDebugMessage("wx",2," --> bbtk top window destroyed and WxGUIConsole not shown => destructing"<<std::endl);
245 wxWindowList& list = GetChildren();
246 wxWindowList::iterator iter;
247 for (iter = list.begin(); iter != list.end(); ++iter)
255 //================================================================
257 //================================================================
258 void WxGUIConsole::WxGUICommandEnter(const std::string& command)
262 mWxGUIOutputMessages->Print(s,wxRED);
264 if ( mInterpreter->InterpretLine( command ) ==
265 Interpreter::Interpreter_QUIT )
270 //================================================================
272 //================================================================
273 /// Runs the interpretation of a file
274 bool WxGUIConsole::InterpretFile( const std::string& filename)
276 if ( mInterpreter->InterpretFile(filename) ==
277 Interpreter::Interpreter_ERROR )
283 //================================================================
285 //================================================================
286 void WxGUIConsole::OnButtonRun(wxCommandEvent& WXUNUSED(event))
288 // wxString temp = mWxGUIHtmlBrowser->GetCurrentPage();
289 std::string filename = mWxGUIHtmlBrowser->GetCurrentPage();//wx2std(temp);
290 size_t s = filename.length();
292 Interpreter::Pointer I = Interpreter::New();
294 if ((s>3) && (filename[s-1]=='s')
295 && (filename[s-2]=='b')
296 && (filename[s-3]=='b')
297 && (filename[s-4]=='.'))
299 std::string tmp("Executing ");
301 SetStatusText(std2wx(tmp));
302 I->InterpretFile(filename);
306 SetStatusText(_T("The current page is not a bbs file : cannot execute it"));
310 //================================================================
312 //================================================================
313 void WxGUIConsole::OnMenuQuit(wxCommandEvent& WXUNUSED(event))
317 //================================================================
320 //================================================================
321 void WxGUIConsole::OnMenuAbout(wxCommandEvent& WXUNUSED(event))
325 wxMessageBox(_T(" bbi\nThe Black Box Toolkit interpreter\n(c) CREATIS 2008"),
326 _T("About ..."), wxOK | wxICON_INFORMATION,
329 //================================================================
332 //================================================================
333 void WxGUIConsole::OnMenuEditConfig(wxCommandEvent& WXUNUSED(event))
335 std::string commandStr;
336 std::string configFile = ConfigurationFile::GetInstance().Get_config_xml_full_path();
338 commandStr = "notepad.exe ";
340 commandStr = "gedit ";
342 commandStr = commandStr + configFile;
343 std::cout << "system: " << commandStr << std::endl;
344 system ( commandStr.c_str() );
346 //================================================================
349 //================================================================
350 void WxGUIConsole::OnMenuCreatePackage(wxCommandEvent& WXUNUSED(event))
352 std::string command("toolsbbtk/appli/GUICreatePackage");
354 bbtkMessage("Debug",1,"Executing : '"<<command<<"'"<<std::endl);
355 Interpreter::Pointer I = Interpreter::New();
356 I->InterpretFile(command);
358 //================================================================
361 //================================================================
362 void WxGUIConsole::OnMenuCreateBlackBox(wxCommandEvent& WXUNUSED(event))
364 std::string command("toolsbbtk/appli/GUICreateBlackBox");
365 bbtkMessage("Debug",1,"Executing : '"<<command<<"'"<<std::endl);
366 Interpreter::Pointer I = Interpreter::New();
367 I->InterpretFile(command);
369 //================================================================
371 //================================================================
372 void WxGUIConsole::OnMenuShowImageGraph(wxCommandEvent& WXUNUSED(event))
374 std::string default_temp_dir = ConfigurationFile::GetInstance().Get_default_temp_dir();
377 std::string strappli="start ";
379 std::string strappli="gnome-open ";
381 std::string strcommand0 = "cd \"" + default_temp_dir+"/temp_dir/" +"\"";
382 std::string strcommand1 = strappli + "workspace_workspacePrototype.png";
383 std::string strcommand = strcommand0 + " && " + strcommand1;
384 std::cout << "system: " << strcommand << std::endl;
385 system ( strcommand.c_str() );
388 //================================================================
390 //================================================================
391 void WxGUIConsole::OnMenuShowHTMLDoc(wxCommandEvent& WXUNUSED(event))
393 std::string doc_path = ConfigurationFile::GetInstance().Get_doc_path();
396 std::string strappli="start ";
398 std::string strappli="gnome-open ";
400 std::string strcommand0 = "cd \"" + doc_path+"\"";
401 std::string strcommand1 = strappli + "index.html";
402 std::string strcommand = strcommand0 + " && " + strcommand1;
403 std::cout << "system: " << strcommand << std::endl;
404 system ( strcommand.c_str() );
407 //================================================================
411 //================================================================
412 void WxGUIConsole::OnMenuCreateIndex(wxCommandEvent& WXUNUSED(event))
415 std::string doc_path = ConfigurationFile::GetInstance().Get_doc_path();
416 std::string filepath = doc_path+"/bbdoc/make-index.bbs";
417 Interpreter* I = new Interpreter;
418 I->InterpretLine( "exec freeze");
419 I->InterpretLine( "include *");
420 I->InterpretLine( "help packages");
421 I->InterpretLine( "index "+doc_path+"/bbdoc/index-alpha.html Initials");
422 I->InterpretLine( "index "+doc_path+"/bbdoc/index-package.html Packages");
423 I->InterpretLine( "index "+doc_path+"/bbdoc/index-category.html Categories");
424 I->InterpretLine( "index "+doc_path+"/bbdoc/index-adaptors.html Adaptors");
428 std::string bin_path = ConfigurationFile::GetInstance().Get_bin_path();
429 std::string doc_path = ConfigurationFile::GetInstance().Get_doc_path();
430 std::string bbdoc_path = doc_path+"/bbdoc";
431 std::string make_index_path = "\"" + bbdoc_path+"/make-index.bbs\"";
433 std::string strcommand0 = "cd "+bbdoc_path+" && mkdir tmp && cd tmp";
435 std::string strcommand1 = "cd "+bbdoc_path+"/tmp";
436 std::string strcommand2 = "\""+bin_path+"/bbi\" -N "+make_index_path;
438 std::string strcommand3 = "move index*.html ../.";
440 std::string strcommand3 = "mv index*.html ../.";
443 std::string strcommand = strcommand1 +" && "+
447 std::cout << "system: " << strcommand0 << std::endl;
448 std::cout << "system: " << strcommand << std::endl;
450 system ( strcommand0.c_str() );
451 system ( strcommand.c_str() );
453 //================================================================
456 //================================================================
457 void WxGUIConsole::InterpreterUserViewHtmlPage(const std::string& page)
460 // std::cout << "WxGUIConsole::ShowHtmlPage('"<<page<<"')"<<std::endl;
461 if (mWxGUIHtmlBrowser->GoTo(s))
463 //EED mwxNotebook->ChangeSelection(1);
464 mwxNotebook->SetSelection(1);
468 // std::cout << "ERROR html"<<std::endl;
471 //================================================================
473 //================================================================
474 // Overloaded Show method to handle bbtk::Wx::TopWindow auto-destruction
476 bool WxGUIConsole::Show(bool show)
478 // bbtk::Wx::SetAutoDestroyTopWindow(!show);
479 return wxFrame::Show(show);
481 //================================================================
483 //================================================================
484 BEGIN_EVENT_TABLE(WxGUIConsole, wxFrame)
485 EVT_CLOSE( WxGUIConsole::OnClose)
486 EVT_MENU(ID_Menu_Quit , WxGUIConsole::OnMenuQuit)
487 EVT_MENU(ID_Menu_About , WxGUIConsole::OnMenuAbout)
488 EVT_MENU(ID_Menu_EditConfig , WxGUIConsole::OnMenuEditConfig)
489 EVT_MENU(ID_Menu_CreatePackage , WxGUIConsole::OnMenuCreatePackage)
490 EVT_MENU(ID_Menu_CreateBlackBox , WxGUIConsole::OnMenuCreateBlackBox)
491 EVT_MENU(ID_Menu_ShowImageGraph , WxGUIConsole::OnMenuShowImageGraph)
492 EVT_MENU(ID_Menu_ShowHTMLDoc , WxGUIConsole::OnMenuShowHTMLDoc)
493 EVT_MENU(ID_Menu_CreateIndex , WxGUIConsole::OnMenuCreateIndex)
494 EVT_BUTTON(ID_Button_Run , WxGUIConsole::OnButtonRun )
496 //================================================================
501 #endif //_USE_WXWIDGETS_