]> Creatis software - bbtkGEditor.git/blob - lib/EditorGraphicBBS/bbsWxGUIEditorGraphic/bbtkwxGUIEditorGraphicBBS.cxx
Feature #1674 . RaC
[bbtkGEditor.git] / lib / EditorGraphicBBS / bbsWxGUIEditorGraphic / bbtkwxGUIEditorGraphicBBS.cxx
1 /*=========================================================================
2  Program:   bbtk
3  Module:    $RCSfile$
4  Language:  C++
5  Date:      $Date$
6  Version:   $Revision$
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  *  \file
33  *  \brief Class bbtk::WxInterfaceEditorGraphicBBS .
34  */
35
36 #include "bbtkwxGUIEditorGraphicBBS.h"
37 #include "creaWx.h"
38 #include "creaSystem.h"
39 //must go #include "bbtkUtilities.h"
40 //must go #include "bbtkConfigurationFile.h"
41 #include <wx/defs.h>
42
43 #include <InterpreterBBS.h>
44
45 namespace bbtk {
46
47 //=========================================================================
48 wxGUIEditorGraphicBBS::wxGUIEditorGraphicBBS(wxFrame *parent) :
49                         wxFrame(parent, -1, _T("bbtkGEditor"), wxDefaultPosition, wxSize(
50                                         1200, 800)) {
51
52         _frameAUIMgr = new wxAuiManager(this);
53
54         /*std::string datadir( crea::System::GetExecutablePath() );
55          std::string datadir (".");
56          cout<<"RaC //------------------"<<endl;
57          cout<<"RaC //TODO wxGUIEditorGraphicBBS constructor.Initialize datadir with  crea::System::GetExecutablePath() ."<<endl;
58          cout<<"RaC //------------------"<<endl;
59
60          #ifdef LINUX // assume this is OSX
61          datadir=datadir+"/../share/creaContours";
62          #endif // MACOSX
63
64          #ifdef MACOSX // assume this is OSX
65          datadir=datadir+"/../../../../share/creaContours";
66          #endif // MACOSX
67
68          _dataDir = datadir;*/
69
70         initMenu();
71         initToolbar();
72         initTabPanelsManager();
73         initPackageBrowser();
74         // JGGR & CM  initHelpHTMLBrowser();
75         _helpHtmlBrowser = NULL;
76         CreateStatusBar();
77         _frameAUIMgr->Update();
78         _actualPkgBrowserBoxName = "";
79         _actualPkgBrowserPkgName = "";
80         refreshGUIControls();
81
82         /////////////////////////////////
83         /// IMPORTANT!! FOR SAVE&LOAD PROCESSES THE VERSION IS VERY IMPORTANT.
84         /// RaC 2012 2nd Hackfest
85         _currentBBGversion="1.4";
86 }
87
88 //=========================================================================
89 wxGUIEditorGraphicBBS::~wxGUIEditorGraphicBBS() {
90
91         printf("EED %p ~wxGUIEditorGraphicBBS()\n", this);
92
93         //EED02JUIN2010         delete _tabsMgr;
94
95         _frameAUIMgr->UnInit();
96         // FCY memory leaks
97         delete _frameAUIMgr;
98         delete _notebook;
99         delete _tabsMgr;
100
101 }
102
103 //=========================================================================
104 void wxGUIEditorGraphicBBS::initToolbar() {
105         wxBitmap bmp_new(new_xpm);
106         wxBitmap bmp_open(open_xpm);
107         wxBitmap bmp_save(save_xpm);
108         wxBitmap bmp_run(run_xpm);
109         wxBitmap bmp_delete(delete_xpm);
110         wxBitmap bmp_centerview(centerview_xpm);
111         wxBitmap bmp_box(box_xpm);
112         wxBitmap bmp_executablebox(executablebox_xpm);
113         wxBitmap bmp_complexbox(complexbox_xpm);
114         wxBitmap bmp_complexinputport(complexinputport_xpm);
115         wxBitmap bmp_complexoutputport(complexoutputport_xpm);
116         wxBitmap bmp_undo(undo_xpm);
117         wxBitmap bmp_redo(redo_xpm);
118         wxBitmap bmp_editProperties(editProperties_xpm);
119         wxToolBar *toolbar = new wxToolBar(this, wxID_ANY);
120
121         //Adds a tool btn to the toolbar
122         toolbar->AddTool(ID_NEW, _T("New"), bmp_new, wxNullBitmap, wxITEM_NORMAL,
123                         _T("New tab"), _T("Create a new panel tab"));
124         toolbar->AddTool(ID_OPEN, _T("Open diagram"), bmp_open, wxNullBitmap,
125                         wxITEM_NORMAL, _T("Open a diagram"), _T("Open a diagram"));
126         toolbar->AddTool(ID_SAVE_DIAGRAM, _T("Save Diagram"), bmp_save,
127                         wxNullBitmap, wxITEM_NORMAL, _T("Saves the current diagram"),
128                         _T("Saves the current diagram")); //DFCH
129         //toolbar->AddTool(ID_SAVE_AS_DIAGRAM,_T("Save Diagram As"),bmp_save, wxNullBitmap, wxITEM_NORMAL,_T("Saves the current diagram"), _T("Saves the current diagram")); //DFCH
130         toolbar->AddTool(ID_RUN, _T("Run"), bmp_run, wxNullBitmap, wxITEM_NORMAL,
131                         _T("Execute actual diagram"), _T("Execute actual diagram"));
132         toolbar->AddTool(ID_DELETEALL, _T("Delete all"), bmp_delete, wxNullBitmap,
133                         wxITEM_NORMAL, _T("Delete all boxes"), _T("Delete all boxes"));
134         toolbar->AddTool(ID_CENTERVIEW, _T("Center view"), bmp_centerview,
135                         wxNullBitmap, wxITEM_NORMAL, _T("Center view"), _T("Center view"));
136         toolbar->AddSeparator();
137         toolbar->AddTool(ID_BTNBOX, _T("New Box"), bmp_box, wxNullBitmap,
138                         wxITEM_NORMAL, _T("New Box"), _T("Nex Box"));
139         toolbar->AddSeparator();
140         toolbar->AddTool(ID_BTEXECUTABLEBOX, _T("Select as executable Box"),
141                         bmp_executablebox, wxNullBitmap, wxITEM_NORMAL,
142                         _T("Select as executable Box"), _T("Select as executable Box"));
143         toolbar->AddSeparator();
144         toolbar->AddTool(ID_BTNCOMPLEXBOX, _T("Complex box"), complexbox_xpm,
145                         wxNullBitmap, wxITEM_NORMAL, _T("Complex box"), _T("Complex box"));
146         toolbar->SetToggle(ID_BTNCOMPLEXBOX, true);
147
148         // RaC 2012 2nd HackFest - Now Complex inputs are any external input
149         //              toolbar->AddTool(ID_ADDCOMPLEXBOXINPUT, _T("Add input to Complex box"),
150         //              bmp_complexinputport, wxNullBitmap, wxITEM_NORMAL,
151         //              _T("Add input to Complex box"), _T("Add input to Complex box"));
152         toolbar->AddTool(ID_ADDCOMPLEXBOXINPUT, _T("Add external input (Complex box or console app)"),
153                         bmp_complexinputport, wxNullBitmap, wxITEM_NORMAL,
154                         _T("Add external input (Complex box or console app)"), _T("Add external input (Complex box or console app)"));
155
156         toolbar->AddTool(ID_ADDCOMPLEXBOXOUTPUT, _T("Add output to Complex box"),
157                         bmp_complexoutputport, wxNullBitmap, wxITEM_NORMAL,
158                         _T("Add output Complex box"), _T("Add output Complex box"));
159
160         // toolbar->EnableTool(ID_ADDCOMPLEXBOXINPUT, false); RaC2012 2nd HackFest
161         toolbar->EnableTool(ID_ADDCOMPLEXBOXINPUT, true);
162
163         toolbar->EnableTool(ID_ADDCOMPLEXBOXOUTPUT, false);
164         toolbar->AddSeparator();
165         toolbar->AddTool(ID_UNDO, _T("Undo"),bmp_undo, wxNullBitmap, wxITEM_NORMAL,     _T("Undo"), _T("Undo"));
166         toolbar->AddTool(ID_REDO, _T("Redo"),bmp_redo, wxNullBitmap, wxITEM_NORMAL,     _T("Redo"), _T("Redo"));
167         toolbar->AddSeparator();
168         toolbar->AddTool(ID_EDITPROPERTIES, _T("Edit diagram properties"),bmp_editProperties, wxNullBitmap, wxITEM_NORMAL,      _T("Edit diagram properties"), _T("Edit diagram properties"));
169         toolbar->EnableTool(ID_EDITPROPERTIES, false);
170         
171         toolbar->EnableTool(ID_UNDO, false);
172         toolbar->EnableTool(ID_REDO, false);
173         toolbar->SetMargins(2, 2);
174         toolbar->Realize();
175         SetToolBar(toolbar);
176
177         
178         // connect command event handlers
179
180         Connect(ID_NEW, wxEVT_COMMAND_TOOL_CLICKED,
181                         wxCommandEventHandler(wxGUIEditorGraphicBBS::OnCreateNewTab));
182         Connect(ID_OPEN, wxEVT_COMMAND_TOOL_CLICKED,
183                         wxCommandEventHandler(wxGUIEditorGraphicBBS::OnOpenDiagram));
184         Connect(ID_SAVE_DIAGRAM, wxEVT_COMMAND_TOOL_CLICKED,
185                         wxCommandEventHandler(wxGUIEditorGraphicBBS::OnSaveActualDiagram)); //DFCH
186         Connect(ID_SAVE_AS_DIAGRAM, wxEVT_COMMAND_TOOL_CLICKED,
187                         wxCommandEventHandler(wxGUIEditorGraphicBBS::OnSaveAsActualDiagram)); //DFCH
188         Connect(
189                         ID_RUN,
190                         wxEVT_COMMAND_TOOL_CLICKED,
191                         wxCommandEventHandler(wxGUIEditorGraphicBBS::OnExecuteActualDiagram));
192         Connect(
193                         ID_DELETEALL,
194                         wxEVT_COMMAND_TOOL_CLICKED,
195                         wxCommandEventHandler(wxGUIEditorGraphicBBS::OnDeleteAllBoxesActualDiagram));
196         Connect(
197                         ID_CENTERVIEW,
198                         wxEVT_COMMAND_TOOL_CLICKED,
199                         wxCommandEventHandler(wxGUIEditorGraphicBBS::OnCenterViewActualDiagram));
200         Connect(ID_BTNBOX, wxEVT_COMMAND_TOOL_CLICKED,
201                         wxCommandEventHandler(wxGUIEditorGraphicBBS::OnClickBtnBox));
202         Connect(
203                         ID_BTEXECUTABLEBOX,
204                         wxEVT_COMMAND_TOOL_CLICKED,
205                         wxCommandEventHandler(wxGUIEditorGraphicBBS::OnClickBtnExecutableBox));
206         Connect(ID_BTNCOMPLEXBOX, wxEVT_COMMAND_TOOL_CLICKED,
207                         wxCommandEventHandler(wxGUIEditorGraphicBBS::OnClickBtnComplexBox));
208         Connect(ID_ADDCOMPLEXBOXINPUT, wxEVT_COMMAND_TOOL_CLICKED,
209                         wxCommandEventHandler(wxGUIEditorGraphicBBS::OnAddComplexBoxInput));
210         Connect(ID_ADDCOMPLEXBOXOUTPUT, wxEVT_COMMAND_TOOL_CLICKED,
211                         wxCommandEventHandler(wxGUIEditorGraphicBBS::OnAddComplexBoxOutput));
212         Connect(ID_UNDO,wxEVT_COMMAND_TOOL_CLICKED,     wxCommandEventHandler(wxGUIEditorGraphicBBS::OnUndo));
213         Connect(ID_REDO,wxEVT_COMMAND_TOOL_CLICKED,     wxCommandEventHandler(wxGUIEditorGraphicBBS::OnRedo));
214         Connect(ID_CHANGENAME, wxEVT_COMMAND_RIGHT_CLICK, wxCommandEventHandler(wxGUIEditorGraphicBBS::OnChangeName));
215         Connect(ID_EDITPROPERTIES,wxEVT_COMMAND_TOOL_CLICKED, wxCommandEventHandler(wxGUIEditorGraphicBBS::OnEditDiagramProperties));
216
217 }
218 //=========================================================================
219 void wxGUIEditorGraphicBBS::initHelpHTMLBrowser() {
220         // JGRR & CM 
221         _helpHtmlBrowser = new WxGUIHtmlBrowser(this, wxSize(200, 0));
222    
223         // EO JGRR & CM 
224         
225 }
226
227 //=========================================================================
228 void wxGUIEditorGraphicBBS::initMenu() {
229         // Create File menu and its items
230         wxMenu *fileMenu = new wxMenu();
231         fileMenu->Append(ID_NEW, _T("New diagram"), _T("New"));
232         fileMenu->Append(ID_SAVE_DIAGRAM, _T("Save Diagram"), _T("Save Diagram")); //DFCH
233         fileMenu->Append(ID_SAVE_AS_DIAGRAM, _T("Save Diagram As"),
234                         _T("Save Diagram As")); //DFCH
235         fileMenu->Append(ID_OPEN_BBS, _T("Open BBS"), _T("Open BBS"));
236         // CM
237         fileMenu->Append(ID_OPEN, _T("Open a diagram"), _T("Open a diagram"));
238         fileMenu->Append(ID_SAVE_AS_BBS, _T("Save BBS"), _T("Save BBS"));
239         fileMenu->Append(ID_SAVE_AS_COMPLEXBOX, _T("Save complex box"),
240                         _T("Save complex box"));
241         fileMenu->Append(ID_EXPORT_CONSOLEAPP, _T("Export console commands"),
242                                 _T("Export console execution commands"));
243         fileMenu->Append(wxID_EXIT, _T("E&xit"), _T("Exit"));
244
245         Connect(ID_NEW, wxEVT_COMMAND_MENU_SELECTED,
246                         wxCommandEventHandler(wxGUIEditorGraphicBBS::OnCreateNewTab));
247         Connect(ID_SAVE_DIAGRAM, wxEVT_COMMAND_MENU_SELECTED,
248                         wxCommandEventHandler(wxGUIEditorGraphicBBS::OnSaveActualDiagram)); //DFCH
249         Connect(ID_SAVE_AS_DIAGRAM, wxEVT_COMMAND_MENU_SELECTED,
250                         wxCommandEventHandler(wxGUIEditorGraphicBBS::OnSaveAsActualDiagram));
251         Connect(ID_OPEN_BBS, wxEVT_COMMAND_MENU_SELECTED,
252                         wxCommandEventHandler(wxGUIEditorGraphicBBS::OnOpenBBS));
253         Connect(ID_SAVE_AS_BBS, wxEVT_COMMAND_MENU_SELECTED,
254                         wxCommandEventHandler(wxGUIEditorGraphicBBS::OnSaveActualBBS));
255         Connect(
256                         ID_SAVE_AS_COMPLEXBOX,
257                         wxEVT_COMMAND_MENU_SELECTED,
258                         wxCommandEventHandler(wxGUIEditorGraphicBBS::OnSaveActualComplexBox));
259         Connect(
260                         ID_EXPORT_CONSOLEAPP,
261                                 wxEVT_COMMAND_MENU_SELECTED,
262                                 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnExportConsoleExecCommand));
263         Connect(wxID_EXIT, wxEVT_COMMAND_MENU_SELECTED,
264                         wxCommandEventHandler(wxGUIEditorGraphicBBS::OnExit));
265
266         // Create Help menu and its items
267         wxMenu *editMenu = new wxMenu;
268         editMenu->Append(ID_COPY_TO_COMPLEXDIAGRAM,
269                         _T("Copy selected to complex box"),
270                         _T("Creates a new complex box diagram with selected boxes"));
271
272         Connect(
273                         ID_COPY_TO_COMPLEXDIAGRAM,
274                         wxEVT_COMMAND_MENU_SELECTED,
275                         wxCommandEventHandler(wxGUIEditorGraphicBBS::OnCopySelectedToComplexDiagram));
276
277         // Create Help menu and its items
278         wxMenu *helpMenu = new wxMenu;
279         helpMenu->Append(wxID_ABOUT, _T("&About..."), _T("About"));
280         helpMenu->Append(ID_HELP_BBEDITOR, _T("&Help..."), _T("Help"));
281         Connect(ID_HELP_BBEDITOR, wxEVT_COMMAND_MENU_SELECTED,
282                         wxCommandEventHandler(wxGUIEditorGraphicBBS::OnHelpBBeditor));
283
284         // Create Tool menu
285         wxMenu *menuTools = new wxMenu;
286         menuTools->Append(ID_bbEditor_Tool_Menu_CreatePackage,
287                         _T("Create &package") );
288         menuTools->Append(ID_bbEditor_Tool_Menu_CreateBlackBox,
289                         _T("Create &blackbox") );
290         menuTools->Append(ID_bbEditor_Tool_Menu_PlugPackage, _T("Plug package") );
291         menuTools->Append(ID_bbEditor_Tool_Menu_EditConfig, _T("&Edit bbtk config") );
292         menuTools->Append(ID_bbEditor_Tool_Menu_ShowHTMLDoc,
293                         _T("Show &HTML documentation") );
294         menuTools->Append(ID_bbEditor_Tool_Menu_CreateIndex, _T("&Generate index") );
295
296         Connect(ID_bbEditor_Tool_Menu_CreatePackage, wxEVT_COMMAND_MENU_SELECTED,
297                         wxCommandEventHandler(wxGUIEditorGraphicBBS::OnCreatePackage));
298         Connect(ID_bbEditor_Tool_Menu_CreateBlackBox, wxEVT_COMMAND_MENU_SELECTED,
299                         wxCommandEventHandler(wxGUIEditorGraphicBBS::OnCreateBlackBox));
300         Connect(ID_bbEditor_Tool_Menu_PlugPackage, wxEVT_COMMAND_MENU_SELECTED,
301                         wxCommandEventHandler(wxGUIEditorGraphicBBS::OnPlugPackage));
302         Connect(ID_bbEditor_Tool_Menu_EditConfig, wxEVT_COMMAND_MENU_SELECTED,
303                         wxCommandEventHandler(wxGUIEditorGraphicBBS::OnEditConfig));
304         Connect(ID_bbEditor_Tool_Menu_ShowHTMLDoc, wxEVT_COMMAND_MENU_SELECTED,
305                         wxCommandEventHandler(wxGUIEditorGraphicBBS::OnShowHTMLDoc));
306         Connect(ID_bbEditor_Tool_Menu_CreateIndex, wxEVT_COMMAND_MENU_SELECTED,
307                         wxCommandEventHandler(wxGUIEditorGraphicBBS::OnCreateIndex));
308
309         // Append the created menu to the menu bar
310         wxMenuBar *menuBar = new wxMenuBar();
311         menuBar->Append(fileMenu, _T("&File") );
312         menuBar->Append(editMenu, _T("&Edit") );
313         menuBar->Append(menuTools, _T("&Tool") );
314         menuBar->Append(helpMenu, _T("&Help") );
315
316         // Attach this menu bar to the frame
317         SetMenuBar(menuBar);
318 }
319
320 //=========================================================================
321 void wxGUIEditorGraphicBBS::initTabPanelsManager() 
322 {
323         _notebook = new wxAuiNotebook(this, wxID_NOTEBOOK, wxDefaultPosition,
324                         wxDefaultSize, wxAUI_NB_TOP | wxAUI_NB_TAB_MOVE
325                                         | wxAUI_NB_CLOSE_ON_ACTIVE_TAB | wxAUI_NB_TAB_FIXED_WIDTH
326                                         | wxAUI_NB_WINDOWLIST_BUTTON);
327         _tabsMgr = new wxTabPanelsManager(this);
328         _frameAUIMgr->AddPane(_notebook, wxAuiPaneInfo().CenterPane());
329 }
330
331 //=========================================================================
332 void wxGUIEditorGraphicBBS::initPackageBrowser() 
333 {
334         _pkgBrowser = new WxGUIPackageBrowser2(this);
335         _pkgBrowser->IncludeAll();
336         _frameAUIMgr->AddPane(_pkgBrowser, wxAuiPaneInfo().Left().MinSize(30, 500).BestSize(750,500).CloseButton(false));
337 }
338
339 //================================================================
340
341 void wxGUIEditorGraphicBBS::DoRegeneratePackageDoc(const std::string& pack) 
342 {
343         std::string mess("Regenerating doc for package '");
344         if (pack != "-a") {
345                 mess += pack + "'";
346         } else {
347                 mess = "Regenerating doc for all packages";
348         }
349
350         mess += " ... please wait";
351
352         SetStatusText(std2wx(mess));
353
354         //BBTK_BUSY_CURSOR;
355
356         std::string command;
357 #if defined(WIN32)
358         command = "\"";
359 #endif
360         command += ConfigurationFile::GetInstance().Get_bin_path();
361         command += ConfigurationFile::GetInstance().Get_file_separator();
362         command += "bbRegeneratePackageDoc";
363 #if defined(WIN32)
364         command += "\"";
365 #endif
366
367         command += " " + pack + " -q";
368         bbtkMessage("debug",1,"Executing system command '"<<command<<"'"<<std::endl);
369
370         if (!system(command.c_str())) {
371                 SetStatusText(_T("Done !"));
372                 /*
373                  wxMessageBox(_T("Done !"),_T("Regenerate package '")
374                  +std2wx(pack)+_T("' doc"),
375                  wxOK | wxICON_INFORMATION);
376                  */
377         } else {
378                 SetStatusText(_T("Done !"));
379                 wxString err(_T("An error occured while running '"));
380                 err += bbtk::std2wx(command) + _T("'");
381                 wxMessageBox(err, _T("Regenerate package doc"), wxOK | wxICON_ERROR);
382         }
383 }
384
385 //================================================================
386 void wxGUIEditorGraphicBBS::DoRegenerateBoxesLists() {
387         SetStatusText(_T("Regenerating boxes lists ... please wait"));
388         //BBTK_BUSY_CURSOR ;
389
390         std::string command;
391 #if defined(WIN32)
392         command = "\"";
393 #endif
394         command += ConfigurationFile::GetInstance().Get_bin_path();
395         command += ConfigurationFile::GetInstance().Get_file_separator();
396         command += "bbRegenerateBoxesLists";
397
398 #if defined(WIN32)
399         command += "\"";
400 #endif
401         command += " -q";
402
403         bbtkMessage("debug",1,"Executing system command '"<<command<<"'"<<std::endl);
404
405         if (!system(command.c_str())) {
406                 SetStatusText(_T("Done !"));
407                 /*
408                  wxMessageBox(_T("Done !"),_T("Regenerate boxes lists"),
409                  wxOK | wxICON_INFORMATION);
410                  */
411         } else {
412                 SetStatusText(_T("Done !"));
413                 wxString err(_T("An error occured while running '"));
414                 err += bbtk::std2wx(command) + _T("'");
415                 wxMessageBox(err, _T("Regenerate boxes lists"), wxOK | wxICON_ERROR);
416         }
417 }
418
419 //================================================================
420 void wxGUIEditorGraphicBBS::RegenerateAll() {
421         DoRegeneratePackageDoc("-a");
422         DoRegenerateBoxesLists();
423 }
424
425 //================================================================
426
427 wxAuiNotebook* wxGUIEditorGraphicBBS::getAuiNotebook() {
428         return _notebook;
429 }
430
431 //================================================================
432
433 void wxGUIEditorGraphicBBS::displayBlackBoxInfo(std::string packageName,
434                 std::string boxName) {
435         if (_actualPkgBrowserPkgName != packageName || _actualPkgBrowserBoxName
436                         != boxName) {
437                 _actualPkgBrowserPkgName = packageName;
438                 _actualPkgBrowserBoxName = boxName;
439
440                 BlackBoxDescriptor::Pointer descriptor =
441                                 GObjectsMVCFactory::getInstance()->getBlackBoxDescriptor(
442                                                 packageName, boxName);
443                 _pkgBrowser->WxGUIBlackBoxListUserOnSelected(descriptor.get());
444         }
445 }
446
447 //=========================================================================
448
449 void wxGUIEditorGraphicBBS::editBlackBox(GBlackBoxModel *bbmodel) {
450         wxBlackBoxEditionDialog* dialog =
451                         new wxBlackBoxEditionDialog(this, bbmodel);
452         dialog->Show();
453 }
454
455 //=========================================================================
456
457 bool wxGUIEditorGraphicBBS::boxNameExists(std::string boxname) {
458  
459         return this->_tabsMgr->getActualTabPanel()->getSceneManager()->boxExist(boxname);
460 }
461
462 //=========================================================================
463
464 void wxGUIEditorGraphicBBS::updateStatusBar(std::string textStatus) {
465         SetStatusText(crea::std2wx(textStatus));
466 }
467
468 //=========================================================================
469
470 void wxGUIEditorGraphicBBS::executeScript(std::string script) {
471         std::string separator =
472                         ConfigurationFile::GetInstance().Get_file_separator();
473         std::string dir = ConfigurationFile::GetInstance().Get_default_temp_dir();
474         std::string filename = dir + separator + "tmp_bbtk.bbs";
475
476         ofstream tempFile;
477         tempFile.open(filename.c_str());
478         tempFile << script;
479         tempFile.close();
480
481         std::string command = "";
482
483 #ifdef WIN32
484         command += "start /b ";
485 #endif
486
487         //              command += "\""+ crea::System::GetExecutablePath();
488         //#ifdef MACOSX
489         //              command += separator + "../../../bbi.app/Contents/MacOS";
490         //#endif
491
492         command += "bbi ";
493         command += "\"" + filename + "\"";
494
495 #ifndef WIN32
496         command += " & ";
497 #endif
498
499         printf("RaC wxGUIEditorGraphicBBS::executeScript %s \n", command.c_str());
500         system(command.c_str());
501 }
502
503 //=========================================================================
504 std::string wxGUIEditorGraphicBBS::CheckExtension(std::string filename, std::string extension) {
505         if(filename.size() > extension.size() ){
506                 if( (filename.compare(filename.size()-extension.size(), extension.size(),extension)) !=0 ){
507                         filename.append(extension);
508                 }
509         }else{
510                 filename.append(extension);
511         }
512         return filename;
513 }
514 //=========================================================================
515 // EVENT HANDLERS
516 //=========================================================================
517
518 void wxGUIEditorGraphicBBS::OnCreateNewTab(wxCommandEvent& event) {
519         _tabsMgr->addNewTab();
520         refreshGUIControls();
521 }
522
523 void wxGUIEditorGraphicBBS::OnUndo(wxCommandEvent& event) {
524         unsigned short disable;
525         std::string stundo;
526         std::string stredo;
527
528         _tabsMgr->loadTempDiagram(0);
529         disable = _tabsMgr->getUndoState(stundo);
530         if(disable == 0)
531         {
532                 std::string name = _tabsMgr->GetNameTabPanel();
533                 if(name[name.length() - 1] == '*')
534                 {
535                         name =name.substr(0,name.length()-1);
536                 }
537                 _tabsMgr->SetNameTabPanel(wxString (name.c_str(), wxConvUTF8));
538         }
539
540         GetToolBar()->EnableTool(ID_UNDO,disable);
541         GetToolBar()->SetToolShortHelp(ID_UNDO,crea::std2wx(stundo));
542         GetToolBar()->EnableTool(ID_REDO,_tabsMgr->getRedoState(stredo));
543         GetToolBar()->SetToolShortHelp(ID_REDO,crea::std2wx(stredo));
544         refreshGUIControls();
545 }
546
547 //=========================================================================
548
549 void wxGUIEditorGraphicBBS::OnRedo(wxCommandEvent& event) {
550         unsigned short disable;
551         std::string stundo;
552         std::string stredo;
553
554         _tabsMgr->loadTempDiagram(1);
555         std::string name = _tabsMgr->GetNameTabPanel();
556         if(name[name.length() - 1] != '*')
557                 name +="*";
558         _tabsMgr->SetNameTabPanel(wxString (name.c_str(), wxConvUTF8));
559         GetToolBar()->EnableTool(ID_UNDO,_tabsMgr->getUndoState(stundo));
560         GetToolBar()->SetToolShortHelp(ID_UNDO,crea::std2wx(stundo));
561         GetToolBar()->EnableTool(ID_REDO,_tabsMgr->getRedoState(stredo));
562         GetToolBar()->SetToolShortHelp(ID_REDO,crea::std2wx(stredo));
563         refreshGUIControls();
564 }
565
566 void wxGUIEditorGraphicBBS::OnChangeName(wxCommandEvent& event){
567 }
568
569 //=========================================================================
570
571 void wxGUIEditorGraphicBBS::OnEditDiagramProperties(wxCommandEvent& event)
572 {
573         wxDiagramPropertiesEditionDialog* dialog =
574                                 new wxDiagramPropertiesEditionDialog(this);
575         dialog->Show();
576 }
577
578 //=========================================================================
579
580 void wxGUIEditorGraphicBBS::OnExecuteActualDiagram(wxCommandEvent& event) {
581         std::string script1 = _tabsMgr->getActualDiagramBBS(true);
582         cout << endl << "RaC wxGUIEditorGraphicBBS::executeActualDiagram SCRIPT"
583                         << endl << endl;
584         cout << script1 << endl;
585
586         std::string script2 = _tabsMgr->getActualDiagramBBS(false);
587         executeScript(script2);
588 }
589
590 //=========================================================================
591 // HANDLERS
592 //=========================================================================
593 void wxGUIEditorGraphicBBS::OnOpenBBS(wxCommandEvent& event) {
594         wxFileDialog * openFileDialog = new wxFileDialog(this, wxT("Open BBS"),
595                         wxEmptyString, wxT("NewBBS"), wxT("*.bbs"), wxOPEN);
596         if (openFileDialog->ShowModal() == wxID_OK) {
597                 wxString fileName = openFileDialog->GetPath();
598
599                 _tabsMgr->addNewTab(openFileDialog->GetFilename());
600
601                 bbtk::InterpreterBBS::Pointer I = bbtk::InterpreterBBS::New(
602                                 this->_tabsMgr->getActualTabPanel()->getSceneManager(),
603                                 _pkgBrowser->GetFactory());
604
605                 // We tell the interpreter to throw exceptions on error
606                 I->SetThrow(true);
607                 // Interpret the file supposed to define a box called 'Processing'
608                 I->InterpretFile((const char*) (fileName.mb_str()));
609         }
610         refreshGUIControls();
611 }
612
613 void wxGUIEditorGraphicBBS::SaveActualBBS(std::string filename) {
614         ofstream file;
615
616         //EED           file.open(fileName.c_str());
617         file.open(filename.c_str());
618         std::string content = "";
619         // writing file header
620         content += "# ----------------------------------\n";
621         content += "# - BBTKGEditor v ";
622         content += _currentBBGversion; //VERSION
623         content += " BBS BlackBox Script\n";
624         content += "# - ";
625         content += filename;
626         content += "\n";
627         content += "# ----------------------------------\n";
628         content += "\n";
629         content += _tabsMgr->getActualDiagramBBS();
630         file << content;
631         file.close();
632 }
633
634 void wxGUIEditorGraphicBBS::OnSaveActualBBS(wxCommandEvent& event) {
635         wxFileDialog * saveFileDialog = new wxFileDialog(this,
636                         wxT("Save  actual BBS"), wxEmptyString, wxT("NewBBS"),
637                         wxT("*.bbs"), wxSAVE | wxOVERWRITE_PROMPT);
638         if (saveFileDialog->ShowModal() == wxID_OK) {
639                 wxString fileName = saveFileDialog->GetPath();
640                 std::string filename = (const char*) (fileName.mb_str());
641                 filename=CheckExtension (filename, ".bbs");
642                 SaveActualBBS(filename);
643         }
644
645 }
646
647 void wxGUIEditorGraphicBBS::AskComplexBoxConfiguration() {
648         std::string cbName = _tabsMgr->GetCbName();
649         std::string paName = _tabsMgr->GetCbPackageName();
650
651         wxTextEntryDialog *cbNameDialog = new wxTextEntryDialog(this,
652                         wxT("Complex Box name"));
653         wxTextEntryDialog *paNameDialog = new wxTextEntryDialog(this,
654                         wxT("Package name"));
655
656         cbNameDialog->SetValue(wxString(cbName.c_str(), wxConvUTF8));
657         paNameDialog->SetValue(wxString(paName.c_str(), wxConvUTF8));
658
659         if (cbNameDialog->ShowModal() == wxID_OK) {
660                 wxString complexboxname = cbNameDialog->GetValue();
661                 cbName = (const char*) (complexboxname.mb_str());
662         }
663
664         if (paNameDialog->ShowModal() == wxID_OK) {
665                 wxString packagename = paNameDialog->GetValue();
666                 paName = (const char*) (packagename.mb_str());
667         }
668
669         _tabsMgr->SetCbName(cbName);
670         _tabsMgr->SetCbPackageName(paName);
671 }
672
673 //=========================================================================
674
675 void wxGUIEditorGraphicBBS::SaveActualComplexBox(std::string filename) {
676         ofstream file;
677         file.open(filename.c_str());
678
679         std::string content = "";
680
681         // writing file header
682         content += "# ----------------------------------\n";
683         content += "# - BBTKGEditor v ";
684         content += _currentBBGversion;//VERSION
685         content += " BBS BlackBox Script (Complex Box)\n";
686         content += "# - ";
687         content += filename;
688         content += "\n";
689         content += "# ----------------------------------\n";
690         content += "\n";
691         content += _tabsMgr->getActualComplexBoxBBS();
692         file << content;
693         file.close();
694 }
695
696 //=========================================================================
697
698 void wxGUIEditorGraphicBBS::OnSaveActualComplexBox(wxCommandEvent& event) {
699         wxFileDialog * saveFileDialog = new wxFileDialog(this,
700                         wxT("Save Complex Box BBS"), wxEmptyString,
701                         _T("ComplexBoxName"), wxT("*.bbs"), wxSAVE
702                                         | wxOVERWRITE_PROMPT);
703         if (saveFileDialog->ShowModal() == wxID_OK) {
704                 wxString fileName = saveFileDialog->GetPath();
705                 std::string filename = (const char*) (fileName.mb_str());
706                 filename=CheckExtension (filename, ".bbs");
707                 SaveActualComplexBox(filename);
708         }
709 }
710
711 //=========================================================================
712 void wxGUIEditorGraphicBBS::SaveActualDiagram(std::string filename) {
713         ofstream file;
714         file.open(filename.c_str());
715
716         std::string content = "";
717
718         // writing file header
719         content += "# ----------------------------------\n";
720         content += "# - BBTKGEditor v ";
721         content += _currentBBGversion; //VERSION
722         content += " BBG BlackBox Diagram file\n";
723         content += "# - ";
724
725         content += filename;
726
727         content += "\n";
728         content += "# ----------------------------------\n";
729         content += "\n";
730         content += "APP_START\n";
731         _tabsMgr->saveActualDiagram(content, filename); //DFCH
732         content += "APP_END\n";
733         file << content;
734         file.close();
735 }
736
737 //=========================================================================
738 void wxGUIEditorGraphicBBS::SaveTempActualDiagram(const std::string &action) 
739 {
740         std::string stundo;
741         std::string stredo;
742         std::string name = _tabsMgr->GetNameTabPanel();
743         if(name[name.length() - 1] != '*')
744                 name +="*";
745         _tabsMgr->SetNameTabPanel(wxString (name.c_str(), wxConvUTF8));
746         _tabsMgr->saveTempActualDiagram(action);
747         GetToolBar()->EnableTool(ID_UNDO,_tabsMgr->getUndoState(stundo));
748         GetToolBar()->SetToolShortHelp(ID_UNDO,crea::std2wx(stundo));
749         GetToolBar()->EnableTool(ID_REDO,_tabsMgr->getRedoState(stredo));
750         GetToolBar()->SetToolShortHelp(ID_REDO,crea::std2wx(stredo));
751 }
752
753 //=========================================================================
754
755 //The following method allows to save the current diagram asking the filename
756 //DFCH
757 void wxGUIEditorGraphicBBS::SaveCurrentDiagramAs() {
758         wxFileDialog * saveFileDialog = new wxFileDialog(this,
759                         wxT("Save current diagram"), wxEmptyString, wxT("NewDiagram"),
760                         wxT("*.bbg"), wxSAVE | wxOVERWRITE_PROMPT);
761         if (saveFileDialog->ShowModal() == wxID_OK) {
762                 //_tabsMgr->SetNameTabPanel(saveFileDialog->GetFilename());
763                 wxString pathfileName = saveFileDialog->GetPath();
764                 std::string pathfilename = (const char*) (pathfileName.mb_str());
765                 pathfilename=CheckExtension (pathfilename, ".bbg");
766
767                 //modify the tab name accordingly
768                 wxString fileName = saveFileDialog->GetFilename();
769                 std::string filename = (const char*) (fileName.mb_str());
770                 filename=CheckExtension (filename, ".bbg");
771                 _tabsMgr->SetNameTabPanel( wxString (filename.c_str(), wxConvUTF8) );
772
773                 std::string pathfilenamebbs = pathfilename;
774                 pathfilenamebbs[pathfilenamebbs.length() - 1] = 's';
775                 if (_tabsMgr->isActualDiagramComplexBox() == false) {
776                         SaveActualDiagram(pathfilename);
777                         SaveActualBBS(pathfilenamebbs);
778                 } else {
779                         AskComplexBoxConfiguration();
780                         SaveActualDiagram(pathfilename);
781                         SaveActualComplexBox(pathfilenamebbs);
782                 } //if isActualDiagramComplexBox
783         } // if saveFileDialog
784 }
785 //=========================================================================
786 //DFCH
787 void wxGUIEditorGraphicBBS::OnSaveActualDiagram(wxCommandEvent& event) {
788         std::string pathfilename = _tabsMgr->GetCurrentTabPanelPath();
789         if (pathfilename.empty()) {
790                 SaveCurrentDiagramAs();
791         } else {
792                 std::string pathfilenamebbs = pathfilename;
793                 pathfilenamebbs[pathfilenamebbs.length() - 1] = 's';
794                 
795                 if (_tabsMgr->isActualDiagramComplexBox() == false) {
796                         std::string name = _tabsMgr->GetNameTabPanel();
797                         if(name[name.length() - 1] == '*')
798                         {
799                                 name =name.substr(0,name.length()-1);
800                         }
801                         _tabsMgr->SetNameTabPanel(wxString (name.c_str(), wxConvUTF8));
802                         SaveActualDiagram(pathfilename);
803                         SaveActualBBS(pathfilenamebbs);
804                 } else {
805                         AskComplexBoxConfiguration();
806                         SaveActualDiagram(pathfilename);
807                         SaveActualComplexBox(pathfilenamebbs);
808                 } //if isActualDiagramComplexBox
809         }
810 }
811 //=========================================================================
812 //DFCH
813 void wxGUIEditorGraphicBBS::OnSaveAsActualDiagram(wxCommandEvent& event) {
814         SaveCurrentDiagramAs();
815 }
816
817 //=========================================================================
818 void wxGUIEditorGraphicBBS::OnExportConsoleExecCommand(wxCommandEvent& event)
819 {
820         wxFileDialog * saveFileDialog = new wxFileDialog(this,
821                         wxT("Export console command"), wxEmptyString, wxT("ConsoleApp.txt"),
822                         wxT("*.txt;*.bbs;*.bbg;*.sh;*.bat"), wxSAVE | wxOVERWRITE_PROMPT);
823
824         if (saveFileDialog->ShowModal() == wxID_OK)
825         {
826                 wxString fileName = saveFileDialog->GetPath();
827                 std::string filename = (const char*) (fileName.mb_str());
828                 filename=CheckExtension (filename, ".txt");
829
830                 ofstream file;
831                 file.open(filename.c_str());
832
833                 std::vector<std::string> extInputs = _tabsMgr->getActualTabPanel()->getSceneManager()->GetExternalInputsNames();
834
835                 //TODO PUT IN A METHOD OF A FILES AND TEXT MANAGER CLASS !!!
836                 //std::string inputsInCommentsWin="";
837                 //std::string inputsInCommentsUnix="";
838                 //std::string inputsInOneLineWin="";
839                 std::string inputsInOneLineUnix="";
840                 for (unsigned int i = 0; i < extInputs.size(); ++i)
841                 {
842                         /* No gusto la idea al jefe pero por si acaso ...
843                         * RaC 2012 2nd HackFest
844                         *
845                         inputsInCommentsWin+="REM ";
846                         inputsInCommentsWin+=extInputs[i];
847                         inputsInCommentsWin+="=\"value\"\n";
848                         inputsInCommentsUnix+="# ";
849                         inputsInCommentsUnix+=extInputs[i];
850                         inputsInCommentsUnix+="=\"value\"\n";
851
852                         char buffer [50];
853                         sprintf (buffer, "%d", (i+1));
854                         inputsInOneLineWin+=extInputs[i];
855                         inputsInOneLineWin+="=\"%";
856                         inputsInOneLineWin+=buffer;
857                         inputsInOneLineWin+="\" ";
858                         */
859                         inputsInOneLineUnix+=extInputs[i];
860                         inputsInOneLineUnix+="=\"<value>\" ";
861
862                 }
863
864
865                 std::string content = "";
866                 // writing file header
867                 content += "# ----------------------------------\n";
868                 content += "# - BBTKGEditor v ";
869                 content += _currentBBGversion; //VERSION
870                 content += " Console Commands to execute BBS application\n";
871                 content += "# - ";
872                 content += filename;
873                 content += "\n";
874                 content += "# ----------------------------------\n";
875                 content += "\n";
876                 content += "\n";
877                 content += "# Command to execute bbi\n";
878                 content += "bbi <bbs_path> ";
879                 content += inputsInOneLineUnix;
880
881                 /* No gusto la idea al jefe pero por si acaso ...
882                  * RaC 2012 2nd HackFest
883                  content += "# For Windows (copy the following lines to a .bat file)\n";
884                  content += "REM BBS application\n";
885                  content += "REM Inputs:\n";
886                  content += inputsInCommentsWin;
887                  content += "REM To use previous inputs, put %$inputName% in the corresponding input of the execution bbi line\n";
888                  content += "bbi applicationBBS.bbs ";
889                  content += inputsInOneLineWin;
890                  content += "\n";
891                  content += "\n";
892                  content += "# For Linux or Mac (copy the following lines to a .sh file)\n";
893                  content += "#!/bin/bash\n";
894                  content += "# BBS application\n";
895                  content += "# Inputs:\n";
896                  content += inputsInCommentsUnix;
897                  content += "# To use previous inputs, put $inputName in the corresponding input of the execution bbi line\n";
898                  content += "bbi applicationBBS.bbs ";
899                  content += inputsInOneLineUnix;
900                  content += "\n";
901                 */
902
903                 file << content;
904                 file.close();
905         }
906
907
908 }
909
910 //=========================================================================
911
912 void wxGUIEditorGraphicBBS::refreshGUIControls() {
913         std::string stundo;
914         std::string stredo;
915         //RaC2012 2ndHackFest Next line seems weird ... To keep in mind for other devels
916         wxToolBar* toolbar = GetToolBar();
917         if (_tabsMgr->isActualDiagramComplexBox()) {
918                 toolbar->ToggleTool(ID_BTNCOMPLEXBOX, true);
919                 //toolbar->EnableTool(ID_ADDCOMPLEXBOXINPUT, true); RaC2012 2nd HackFest
920                 toolbar->EnableTool(ID_ADDCOMPLEXBOXOUTPUT, true);
921
922                 GetMenuBar()->GetMenu(0)->Enable(ID_SAVE_AS_COMPLEXBOX, true);
923                 GetMenuBar()->GetMenu(0)->Enable(ID_SAVE_AS_BBS, false);
924                 GetMenuBar()->GetMenu(0)->Enable(ID_EXPORT_CONSOLEAPP, false);
925         } else {
926                 toolbar->ToggleTool(ID_BTNCOMPLEXBOX, false);
927                 //toolbar->EnableTool(ID_ADDCOMPLEXBOXINPUT, false); RaC2012 2nd HackFest
928                 toolbar->EnableTool(ID_ADDCOMPLEXBOXOUTPUT, false);
929
930                 GetMenuBar()->GetMenu(0)->Enable(ID_SAVE_AS_COMPLEXBOX, false);
931                 GetMenuBar()->GetMenu(0)->Enable(ID_SAVE_AS_BBS, true);
932                 GetMenuBar()->GetMenu(0)->Enable(ID_EXPORT_CONSOLEAPP, true);
933         }
934
935         //RaC2012 2ndHackFest
936         GetToolBar()->EnableTool(ID_EDITPROPERTIES,true);
937
938         GetToolBar()->EnableTool(ID_UNDO,_tabsMgr->getUndoState(stundo));
939         GetToolBar()->SetToolShortHelp(ID_UNDO,crea::std2wx(stundo));
940         GetToolBar()->EnableTool(ID_REDO,_tabsMgr->getRedoState(stredo));
941         GetToolBar()->SetToolShortHelp(ID_REDO,crea::std2wx(stredo));
942
943         if (_tabsMgr->getNumActualSelectedObjects() > 0) {
944                 GetMenuBar()->GetMenu(1)->Enable(ID_COPY_TO_COMPLEXDIAGRAM, true);
945         } else {
946                 ///TODO Fix the possibility to say from the SceneManager to the GUI to refresh the options
947                 GetMenuBar()->GetMenu(1)->Enable(ID_COPY_TO_COMPLEXDIAGRAM, true);
948         }
949
950 }
951
952 //=========================================================================
953
954 void wxGUIEditorGraphicBBS::OnDeleteAllBoxesActualDiagram(wxCommandEvent& event) {
955         wxMessageDialog *dial = new wxMessageDialog(NULL,
956                         wxT("Are you sure to delete all boxes of the diagram?"),
957                         wxT("Delete all boxes"), wxYES_NO | wxNO_DEFAULT
958                                         | wxICON_QUESTION);
959         if (dial->ShowModal() == wxID_YES) {
960                 _tabsMgr->deleteAllBoxesActualDiagram();
961         }
962 }
963
964 //=========================================================================
965
966 void wxGUIEditorGraphicBBS::OnCenterViewActualDiagram(wxCommandEvent& event) {
967         _tabsMgr->centerViewActualDiagram();
968 }
969
970 //=========================================================================
971
972 void wxGUIEditorGraphicBBS::OnOpenDiagram(wxCommandEvent& event) {
973         wxFileDialog * openFileDialog = new wxFileDialog(this, wxT("Open diagram"),
974                         wxEmptyString, wxT(""), wxT("*.bbg"), wxOPEN | wxFILE_MUST_EXIST);
975         printf("SCP: wxGUIEditorGraphicBBS::OnOpenDiagram  \n");
976         if (openFileDialog->ShowModal() == wxID_OK) {
977                 wxString fileName = openFileDialog->GetPath();
978                 ifstream inputStream;
979                 std::string fName = (const char*) (fileName.mb_str());
980
981                 inputStream.open(fName.c_str());
982                 assert(inputStream.good()); // fails
983                 _tabsMgr->addNewTab(openFileDialog->GetFilename());
984                 _tabsMgr->loadDiagram(inputStream, fName);
985                 _tabsMgr->saveTempActualDiagram("load diagram");
986                 GetToolBar()->EnableTool(ID_UNDO, false);
987                 GetToolBar()->EnableTool(ID_UNDO, false);
988                 inputStream.close();
989         }
990         refreshGUIControls();
991 }
992
993 //=========================================================================
994
995
996 void wxGUIEditorGraphicBBS::OnClickBtnBox(wxCommandEvent& event) {
997         BlackBoxDescriptor *bbDes = _pkgBrowser->GetActualSelected();
998         if (bbDes != NULL) {
999                 std::string typeName = bbDes->GetTypeName();
1000                 std::string packageName = bbDes->GetPackage()->GetName();
1001
1002                 wxGEditorTabPanel *pnl = this->_tabsMgr->getActualTabPanel();
1003                 
1004
1005                 if (pnl != NULL) {
1006                         wxVtkSceneManager *scn = pnl->getSceneManager();
1007                         scn->createGBlackBox(50, 50, packageName, typeName);
1008                         scn->refresh();
1009                 }
1010
1011                 SaveTempActualDiagram("New Box");
1012                 // if pnl
1013         }// if bbDes
1014 }
1015
1016 //=========================================================================
1017
1018 void wxGUIEditorGraphicBBS::OnClickBtnExecutableBox(wxCommandEvent& event) {
1019         //DFCH
1020         wxGEditorTabPanel *pnl = this->_tabsMgr->getActualTabPanel();
1021
1022         if (pnl != NULL) {
1023                 wxVtkSceneManager *scn = pnl->getSceneManager();
1024                 if( scn->MakeBoxExecutable() )
1025                         std::cout<<"DFCH: wxGUIEditorGraphicBBS::OnClickBtnExecutableBox...successful"<<std::endl;
1026                 else
1027                         std::cout<<"DFCH: wxGUIEditorGraphicBBS::OnClickBtnExecutableBox...Error!!"<<std::endl;
1028         }
1029         //DFCH
1030
1031 }
1032
1033 //=========================================================================
1034
1035 void wxGUIEditorGraphicBBS::OnClickBtnComplexBox(wxCommandEvent& event) {
1036         wxToolBar* toolbar = GetToolBar();
1037         bool temp = toolbar->GetToolState(ID_BTNCOMPLEXBOX);
1038         if (temp) {
1039                 enableComplexBox();
1040         } else {
1041                 disableComplexBox();
1042         }
1043 }
1044
1045 //=========================================================================
1046
1047 void wxGUIEditorGraphicBBS::OnAddComplexBoxInput(wxCommandEvent& event) {
1048         wxTextEntryDialog *nameDialog = new wxTextEntryDialog(this,
1049                         wxT("Name of input port"));
1050         if (nameDialog->ShowModal() == wxID_OK) {
1051                 wxString fileName = nameDialog->GetValue();
1052                 if (!fileName.IsEmpty()) {
1053                         std::string portName = (const char*) (fileName.mb_str());
1054                         _tabsMgr->addActualDiagramComplexInputPort(portName);
1055                 }
1056         }
1057 }
1058
1059 //=========================================================================
1060
1061 void wxGUIEditorGraphicBBS::OnAddComplexBoxOutput(wxCommandEvent& event) {
1062         wxTextEntryDialog *nameDialog = new wxTextEntryDialog(this,
1063                         wxT("Name of output port"));
1064         if (nameDialog->ShowModal() == wxID_OK) {
1065                 wxString fileName = nameDialog->GetValue();
1066                 if (!fileName.IsEmpty()) {
1067                         std::string portName = (const char*) (fileName.mb_str());
1068                         _tabsMgr->addActualDiagramComplexOutputPort(portName);
1069                 }
1070         }
1071 }
1072
1073 //=========================================================================
1074
1075 void wxGUIEditorGraphicBBS::OnCopySelectedToComplexDiagram(
1076                 wxCommandEvent& event) {
1077         _tabsMgr->copySelectedBBoxesToComplexDiagram();
1078 }
1079
1080 void wxGUIEditorGraphicBBS::OnHelpBBeditor(wxCommandEvent& event) {
1081         printf("wxGUIEditorGraphicBBS::OnHelpBBeditor ....not implemented..\n");
1082 }
1083
1084 //=========================================================================
1085 void wxGUIEditorGraphicBBS::OnCreatePackage(wxCommandEvent& event) {
1086
1087         bbtkSystemTools::CreatePackage();
1088 }
1089
1090 //=========================================================================
1091 void wxGUIEditorGraphicBBS::OnCreateBlackBox(wxCommandEvent& event) {
1092         bbtkSystemTools::CreateBlackBox();
1093 }
1094 //=========================================================================
1095 void wxGUIEditorGraphicBBS::OnPlugPackage(wxCommandEvent& event) {
1096         //DFGO2012 Plug Package functionnalities
1097         long style = wxDD_DEFAULT_STYLE | wxDD_DIR_MUST_EXIST;
1098         wxDirDialog* FD =
1099           new wxDirDialog( 0,
1100                            _T("Select package directory"),
1101                            _T(""),
1102                            style);
1103         long userResponse;
1104         do
1105         {
1106                 userResponse = FD->ShowModal();
1107                 if(userResponse==wxID_OK)
1108                 {
1109                         std::string path = wx2std (FD->GetPath()) ;
1110                         std::string fname = path + "/bbtkPackage";
1111                         std::cout << "Path chosen = \"" << FD->GetPath() << "\"" << std::endl;
1112                         if ( Utilities::FileExists( fname ) )
1113                         {
1114                                 std::ifstream f;
1115                                 f.open(fname.c_str());
1116                                 std::string pname;
1117                                 f >> pname;
1118                                 f.close();
1119
1120                                 bbtk::ConfigurationFile::GetInstance().AddPackagePathsAndWrite( path );
1121
1122                                 DoRegeneratePackageDoc(pname);
1123                                 DoRegenerateBoxesLists();
1124
1125                                 _pkgBrowser->RebuildList();
1126
1127                                 wxMessageBox(_T("Package successfully plugged. Please restart bbEditor to see the new package in the package browser."),_T("Plug package"),wxOK | wxICON_INFORMATION);
1128                                 userResponse = wxID_CANCEL;
1129                         }
1130                         else
1131                         {
1132                                 std::string err = "The directory \"" + path + "\" does not contain a 'bbtkPackage' file.";
1133                                 #ifndef WIN32
1134                                         #ifndef MACOSX
1135                                                 err += "\nNote: If you are on Linux please select the folder and click \"Open\", don't enter in it.";
1136                                         #endif
1137                                 #endif
1138
1139                                 wxMessageBox(crea::std2wx(err), _T("Plug package"),wxOK | wxICON_ERROR);
1140                                 // THE FOLLOWING LINE GIVES ERRORS BECAUSE IT IS NECESSARY TO USE std2wx
1141                                 //wxMessageBox( _T( err) , _T("Plug package"),wxOK | wxICON_ERROR);
1142                         }
1143                 }
1144         }while(userResponse != wxID_CANCEL);
1145
1146 }
1147 //=========================================================================
1148 void wxGUIEditorGraphicBBS::OnEditConfig(wxCommandEvent& event) {
1149         std::string commandStr;
1150             std::string configFile = ConfigurationFile::GetInstance().Get_config_xml_full_path();
1151         #ifdef WIN32
1152                 commandStr = "notepad.exe ";
1153         #else
1154                 commandStr = "gedit ";
1155         #endif
1156                 commandStr = commandStr + configFile;
1157                 std::cout << "system: " << commandStr << std::endl;
1158                 system ( commandStr.c_str() );
1159     }
1160     //=========================================================================
1161
1162     void wxGUIEditorGraphicBBS::OnShowHTMLDoc(wxCommandEvent& event) {
1163         // JGRR & CM WH
1164         if (_helpHtmlBrowser != NULL){
1165              _frameAUIMgr->DetachPane(_helpHtmlBrowser);
1166             _helpHtmlBrowser->Destroy();   
1167         }
1168         initHelpHTMLBrowser();
1169         _frameAUIMgr->AddPane(_helpHtmlBrowser, wxAuiPaneInfo().Right().MinSize(200, 200));
1170         _frameAUIMgr->Update();
1171         refreshGUIControls();
1172         
1173         // EO JGRR    & CM WH       
1174 }
1175 //=========================================================================
1176 void wxGUIEditorGraphicBBS::OnCreateIndex(wxCommandEvent& event) {
1177         printf("EED wxGUIEditorGraphicBBS::OnCreateIndex ... not implemented ..\n");
1178 }
1179
1180 //=========================================================================
1181
1182 void wxGUIEditorGraphicBBS::OnExit(wxCommandEvent& event) {
1183         Close(true);
1184 }
1185
1186 //=========================================================================
1187
1188 void wxGUIEditorGraphicBBS::enableComplexBox() {
1189         _tabsMgr->setActualDiagramComplexBox(true);
1190         refreshGUIControls();
1191 }
1192
1193 //=========================================================================
1194
1195 void wxGUIEditorGraphicBBS::disableComplexBox() {
1196         _tabsMgr->setActualDiagramComplexBox(false);
1197         refreshGUIControls();
1198 }
1199
1200 //=========================================================================
1201
1202 void wxGUIEditorGraphicBBS::setCurrentDiagramDescription(std::string description)
1203 {
1204         _tabsMgr->SetDescription(description);
1205 }
1206
1207 //=========================================================================
1208
1209 void wxGUIEditorGraphicBBS::setCurrentDiagramAuthor(std::string author)
1210 {
1211         _tabsMgr->SetAuthor(author);
1212 }
1213
1214 //=========================================================================
1215
1216 void wxGUIEditorGraphicBBS::setCurrentDiagramCategory(std::string category)
1217 {
1218         _tabsMgr->SetCategory(category);
1219 }
1220
1221 //=========================================================================
1222
1223 std::string wxGUIEditorGraphicBBS::getCurrentDiagramDescription()
1224 {
1225         return _tabsMgr->GetDescription();
1226 }
1227
1228 //=========================================================================
1229
1230 std::string wxGUIEditorGraphicBBS::getCurrentDiagramAuthor()
1231 {
1232         return _tabsMgr->GetAuthor();
1233 }
1234
1235 //=========================================================================
1236
1237
1238 std::string wxGUIEditorGraphicBBS::getCurrentDiagramCategory()
1239 {
1240         return _tabsMgr->GetCategory();
1241 }
1242
1243 //=========================================================================
1244
1245 bool wxGUIEditorGraphicBBS::isCurrentDiagramComplexBox()
1246 {
1247         return _tabsMgr->isActualDiagramComplexBox();
1248 }
1249
1250
1251 } // EO namespace bbtk
1252
1253 // EOF
1254