]> Creatis software - bbtkGEditor.git/blob - lib/EditorGraphicBBS/bbsWxGUIEditorGraphic/bbtkwxGUIEditorGraphicBBS.cxx
#3259 Export Format Python and JavaScript
[bbtkGEditor.git] / lib / EditorGraphicBBS / bbsWxGUIEditorGraphic / bbtkwxGUIEditorGraphicBBS.cxx
1 /*
2 # ---------------------------------------------------------------------
3 #
4 # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image 
5 #                        pour la Santé)
6 # Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton
7 #
8 #  This software is governed by the CeCILL-B license under French law and 
9 #  abiding by the rules of distribution of free software. You can  use, 
10 #  modify and/ or redistribute the software under the terms of the CeCILL-B 
11 #  license as circulated by CEA, CNRS and INRIA at the following URL 
12 #  http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html 
13 #  or in the file LICENSE.txt.
14 #
15 #  As a counterpart to the access to the source code and  rights to copy,
16 #  modify and redistribute granted by the license, users are provided only
17 #  with a limited warranty  and the software's author,  the holder of the
18 #  economic rights,  and the successive licensors  have only  limited
19 #  liability. 
20 #
21 #  The fact that you are presently reading this means that you have had
22 #  knowledge of the CeCILL-B license and that you accept its terms.
23 # ------------------------------------------------------------------------  
24 */
25
26 /*=========================================================================
27  Program:   bbtk
28  Module:    $RCSfile$
29  Language:  C++
30  Date:      $Date$
31  Version:   $Revision$
32  =========================================================================*/
33
34 /* ---------------------------------------------------------------------
35
36  * Copyright (c) CREATIS-LRMN (Centre de Recherche en Imagerie Medicale)
37  * Authors : Eduardo Davila, Laurent Guigues, Jean-Pierre Roux
38  *
39  *  This software is governed by the CeCILL-B license under French law and
40  *  abiding by the rules of distribution of free software. You can  use,
41  *  modify and/ or redistribute the software under the terms of the CeCILL-B
42  *  license as circulated by CEA, CNRS and INRIA at the following URL
43  *  http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
44  *  or in the file LICENSE.txt.
45  *
46  *  As a counterpart to the access to the source code and  rights to copy,
47  *  modify and redistribute granted by the license, users are provided only
48  *  with a limited warranty  and the software's author,  the holder of the
49  *  economic rights,  and the successive licensors  have only  limited
50  *  liability.
51  *
52  *  The fact that you are presently reading this means that you have had
53  *  knowledge of the CeCILL-B license and that you accept its terms.
54  * ------------------------------------------------------------------------ */
55
56 /**
57  *  \file
58  *  \brief Class bbtk::WxInterfaceEditorGraphicBBS .
59  */
60
61 #include "bbtkwxGUIEditorGraphicBBS.h"
62 #include "creaWx.h"
63 #include "creaSystem.h"
64 //must go #include "bbtkUtilities.h"
65 //must go #include "bbtkConfigurationFile.h"
66 #include <wx/defs.h>
67
68 #include <InterpreterBBS.h>
69
70 namespace bbtk {
71
72 //=========================================================================
73 wxGUIEditorGraphicBBS::wxGUIEditorGraphicBBS(wxFrame *parent) 
74         : wxFrame( parent, -1, _T("bbtkGEditor"), wxDefaultPosition, wxSize(1200,800) ) 
75 {
76         _pkgBrowser = NULL;
77         _frameAUIMgr = new wxAuiManager(this);
78
79         /*std::string datadir( crea::System::GetExecutablePath() );
80          std::string datadir (".");
81          cout<<"RaC //------------------"<<endl;
82          cout<<"RaC //TODO wxGUIEditorGraphicBBS constructor.Initialize datadir with  crea::System::GetExecutablePath() ."<<endl;
83          cout<<"RaC //------------------"<<endl;
84
85          #ifdef LINUX // assume this is OSX
86          datadir=datadir+"/../share/creaContours";
87          #endif // MACOSX
88
89          #ifdef MACOSX // assume this is OSX
90          datadir=datadir+"/../../../../share/creaContours";
91          #endif // MACOSX
92
93          _dataDir = datadir;*/
94
95         initMenu();
96         initToolbar();
97         initPackageBrowser();
98         initTabPanelsManager();
99     // JGGR & CM  initHelpHTMLBrowser();
100     _helpHtmlBrowser = NULL;
101         CreateStatusBar();
102         _frameAUIMgr->Update();
103         _actualPkgBrowserBoxName = "";
104         _actualPkgBrowserPkgName = "";
105         refreshGUIControls();
106
107         /////////////////////////////////
108         /// IMPORTANT!! FOR SAVE&LOAD PROCESSES THE VERSION IS VERY IMPORTANT.
109         /// RaC 2012 2nd Hackfest
110         _currentBBGversion="1.6";
111 }
112
113 //=========================================================================
114 wxGUIEditorGraphicBBS::~wxGUIEditorGraphicBBS() 
115 {
116         //EED02JUIN2010         delete _tabsMgr;
117         _frameAUIMgr->UnInit();
118         // FCY memory leaks
119         delete _frameAUIMgr;
120         delete _notebook;
121         delete _tabsMgr;
122 }
123
124 //=========================================================================
125 void wxGUIEditorGraphicBBS::initToolbar() 
126 {
127         wxBitmap bmp_new(new_xpm);
128         wxBitmap bmp_open(open_xpm);
129         wxBitmap bmp_save(save_xpm);
130         wxBitmap bmp_run(run_xpm);
131         wxBitmap bmp_delete(delete_xpm);
132         wxBitmap bmp_centerview(centerview_xpm);
133         wxBitmap bmp_box(box_xpm);
134         wxBitmap bmp_find(find_xpm);
135         wxBitmap bmp_executablebox(executablebox_xpm);
136         wxBitmap bmp_complexbox(complexbox_xpm);
137         wxBitmap bmp_complexinputport(complexinputport_xpm);
138         wxBitmap bmp_complexoutputport(complexoutputport_xpm);
139         wxBitmap bmp_undo(undo_xpm);
140         wxBitmap bmp_redo(redo_xpm);
141         wxBitmap bmp_editProperties(editProperties_xpm);
142         wxBitmap bmp_showTree(showTree_xpm);
143         
144 //      wxToolBar *toolbar = new wxToolBar(this, wxID_ANY);
145         wxToolBar *toolbar =    CreateToolBar();
146
147         //Adds a tool btn to the toolbar
148         toolbar->AddTool(ID_NEW, _T("New"), bmp_new, wxNullBitmap, wxITEM_NORMAL,
149                         _T("New tab"), _T("Create a new panel tab"));
150
151         toolbar->AddTool(ID_OPEN, _T("Open diagram"), bmp_open, wxNullBitmap,
152                         wxITEM_NORMAL, _T("Open a diagram"), _T("Open a diagram"));
153
154         toolbar->AddTool(ID_SAVE_DIAGRAM, _T("Save Diagram"), bmp_save,
155                         wxNullBitmap, wxITEM_NORMAL, _T("Saves the current diagram"),
156                         _T("Saves the current diagram")); //DFCH
157         //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
158         toolbar->AddTool(ID_RUN, _T("Run"), bmp_run, wxNullBitmap, wxITEM_NORMAL,
159                         _T("Execute actual diagram"), _T("Execute actual diagram"));
160         toolbar->AddTool(ID_DELETEALL, _T("Delete all"), bmp_delete, wxNullBitmap,
161                         wxITEM_NORMAL, _T("Delete all boxes"), _T("Delete all boxes"));
162         toolbar->AddTool(ID_CENTERVIEW, _T("Center view"), bmp_centerview,
163                         wxNullBitmap, wxITEM_NORMAL, _T("Center view"), _T("Center view"));
164         toolbar->AddSeparator();
165     toolbar->AddTool(ID_BTNBOX, _T("New Box"), bmp_box, wxNullBitmap,wxITEM_NORMAL, _T("New Box"), _T("Nex Box"));
166         toolbar->AddTool(ID_BTNSELETBOXES, _T("Select Boxes"), bmp_find, wxNullBitmap,wxITEM_NORMAL, _T("Select Boxes"), _T("Select Boxes"));
167         toolbar->AddSeparator();
168         toolbar->AddTool(ID_BTEXECUTABLEBOX, _T("Select as executable Box"),
169                         bmp_executablebox, wxNullBitmap, wxITEM_NORMAL,
170                         _T("Select as executable Box"), _T("Select as executable Box"));
171         toolbar->AddSeparator();
172         toolbar->AddTool(ID_BTNCOMPLEXBOX, _T("Complex box"), complexbox_xpm,
173                         wxNullBitmap, wxITEM_NORMAL, _T("Complex box"), _T("Complex box"));
174
175 //EED 2017-09-16 Migration wxWidgets 2.8 to 3.0
176 #if wxMAJOR_VERSION <= 2
177         toolbar->SetToggle(ID_BTNCOMPLEXBOX, true);
178 #else
179         printf ("EED Warnning. wxGUIEditorGraphicBBS::initToolbar       >>>   toolbar->SetToggle  \n ");
180         // ..
181 #endif
182
183         // RaC 2012 2nd HackFest - Now Complex inputs are any external input
184         //              toolbar->AddTool(ID_ADDCOMPLEXBOXINPUT, _T("Add input to Complex box"),
185         //              bmp_complexinputport, wxNullBitmap, wxITEM_NORMAL,
186         //              _T("Add input to Complex box"), _T("Add input to Complex box"));
187         toolbar->AddTool(ID_ADDCOMPLEXBOXINPUT, _T("Add external input (Complex box or console app)"),
188                         bmp_complexinputport, wxNullBitmap, wxITEM_NORMAL,
189                         _T("Add external input (Complex box or console app)"), _T("Add external input (Complex box or console app)"));
190
191         toolbar->AddTool(ID_ADDCOMPLEXBOXOUTPUT, _T("Add output to Complex box"),
192                         bmp_complexoutputport, wxNullBitmap, wxITEM_NORMAL,
193                         _T("Add output Complex box"), _T("Add output Complex box"));
194
195         // toolbar->EnableTool(ID_ADDCOMPLEXBOXINPUT, false); RaC2012 2nd HackFest
196         toolbar->EnableTool(ID_ADDCOMPLEXBOXINPUT, true);
197
198         toolbar->EnableTool(ID_ADDCOMPLEXBOXOUTPUT, false);
199         toolbar->AddSeparator();
200         toolbar->AddTool(ID_UNDO, _T("Undo"),bmp_undo, wxNullBitmap, wxITEM_NORMAL,     _T("Undo"), _T("Undo"));
201         toolbar->AddTool(ID_REDO, _T("Redo"),bmp_redo, wxNullBitmap, wxITEM_NORMAL,     _T("Redo"), _T("Redo"));
202         toolbar->AddSeparator();
203         toolbar->AddTool(ID_EDITPROPERTIES, _T("Edit diagram properties"),bmp_editProperties, wxNullBitmap, wxITEM_NORMAL,      _T("Edit diagram properties"), _T("Edit diagram properties"));
204         toolbar->EnableTool(ID_EDITPROPERTIES, false);
205
206         toolbar->AddTool(ID_SHOWTREE, _T("Show tree"),bmp_showTree, wxNullBitmap, wxITEM_NORMAL,        _T("Show tree"), _T("Show tree"));
207
208         
209         toolbar->EnableTool(ID_UNDO, false);
210         toolbar->EnableTool(ID_REDO, false);
211         toolbar->SetMargins(2, 2);
212         toolbar->Realize();
213         SetToolBar(toolbar);
214
215
216         
217         // connect command event handlers
218
219         Connect(ID_NEW, wxEVT_COMMAND_TOOL_CLICKED,
220                         wxCommandEventHandler(wxGUIEditorGraphicBBS::OnCreateNewTab));
221         Connect(ID_OPEN, wxEVT_COMMAND_TOOL_CLICKED,
222                         wxCommandEventHandler(wxGUIEditorGraphicBBS::OnOpenDiagram));
223         Connect(ID_SAVE_DIAGRAM, wxEVT_COMMAND_TOOL_CLICKED,
224                         wxCommandEventHandler(wxGUIEditorGraphicBBS::OnSaveActualDiagram)); //DFCH
225         Connect(ID_SAVE_AS_DIAGRAM, wxEVT_COMMAND_TOOL_CLICKED,
226                         wxCommandEventHandler(wxGUIEditorGraphicBBS::OnSaveAsActualDiagram)); //DFCH
227         Connect(
228                         ID_RUN,
229                         wxEVT_COMMAND_TOOL_CLICKED,
230                         wxCommandEventHandler(wxGUIEditorGraphicBBS::OnExecuteActualDiagram));
231         Connect(
232                         ID_DELETEALL,
233                         wxEVT_COMMAND_TOOL_CLICKED,
234                         wxCommandEventHandler(wxGUIEditorGraphicBBS::OnDeleteAllBoxesActualDiagram));
235         Connect(
236                         ID_CENTERVIEW,
237                         wxEVT_COMMAND_TOOL_CLICKED,
238                         wxCommandEventHandler(wxGUIEditorGraphicBBS::OnCenterViewActualDiagram));
239         Connect(ID_BTNBOX, wxEVT_COMMAND_TOOL_CLICKED,wxCommandEventHandler(wxGUIEditorGraphicBBS::OnClickBtnBox));
240     Connect(ID_BTNSELETBOXES, wxEVT_COMMAND_TOOL_CLICKED , wxCommandEventHandler(wxGUIEditorGraphicBBS::OnClickBtnSelectBoxes) );
241         Connect(
242                         ID_BTEXECUTABLEBOX,
243                         wxEVT_COMMAND_TOOL_CLICKED,
244                         wxCommandEventHandler(wxGUIEditorGraphicBBS::OnClickBtnExecutableBox));
245         Connect(ID_BTNCOMPLEXBOX, wxEVT_COMMAND_TOOL_CLICKED,
246                         wxCommandEventHandler(wxGUIEditorGraphicBBS::OnClickBtnComplexBox));
247         Connect(ID_ADDCOMPLEXBOXINPUT, wxEVT_COMMAND_TOOL_CLICKED,
248                         wxCommandEventHandler(wxGUIEditorGraphicBBS::OnAddComplexBoxInput));
249         Connect(ID_ADDCOMPLEXBOXOUTPUT, wxEVT_COMMAND_TOOL_CLICKED,
250                         wxCommandEventHandler(wxGUIEditorGraphicBBS::OnAddComplexBoxOutput));
251         Connect(ID_UNDO,wxEVT_COMMAND_TOOL_CLICKED,     wxCommandEventHandler(wxGUIEditorGraphicBBS::OnUndo));
252         Connect(ID_REDO,wxEVT_COMMAND_TOOL_CLICKED,     wxCommandEventHandler(wxGUIEditorGraphicBBS::OnRedo));
253         Connect(ID_CHANGENAME, wxEVT_COMMAND_RIGHT_CLICK, wxCommandEventHandler(wxGUIEditorGraphicBBS::OnChangeName));
254         Connect(ID_EDITPROPERTIES,wxEVT_COMMAND_TOOL_CLICKED, wxCommandEventHandler(wxGUIEditorGraphicBBS::OnEditDiagramProperties));
255         Connect(ID_SHOWTREE,wxEVT_COMMAND_TOOL_CLICKED, wxCommandEventHandler(wxGUIEditorGraphicBBS::OnShowTree));
256
257
258 }
259 //=========================================================================
260 void wxGUIEditorGraphicBBS::initHelpHTMLBrowser() {
261         // JGRR & CM 
262         _helpHtmlBrowser = new WxGUIHtmlBrowser(this, wxSize(200, 0));
263    
264         // EO JGRR & CM 
265         
266 }
267
268 //=========================================================================
269 void wxGUIEditorGraphicBBS::initMenu() {
270         // Create File menu and its items
271         wxMenu *fileMenu = new wxMenu();
272         fileMenu->Append(ID_NEW, _T("New diagram"), _T("New"));
273         fileMenu->Append(ID_SAVE_DIAGRAM, _T("Save Diagram"), _T("Save Diagram")); //DFCH
274         fileMenu->Append(ID_SAVE_AS_DIAGRAM, _T("Save Diagram As"),
275                         _T("Save Diagram As")); //DFCH
276         fileMenu->Append(ID_OPEN_BBS, _T("Open BBS"), _T("Open BBS"));
277         // CM
278         fileMenu->Append(ID_OPEN, _T("Open a diagram"), _T("Open a diagram"));
279         fileMenu->Append(ID_SAVE_AS_BBS, _T("Save BBS"), _T("Save BBS"));
280         fileMenu->Append(ID_SAVE_AS_COMPLEXBOX, _T("Save complex box"),
281                         _T("Save complex box"));
282         fileMenu->Append(ID_EXPORT_CONSOLEAPP, _T("Export console commands"),
283                                 _T("Export console execution commands"));
284         fileMenu->Append(wxID_EXIT, _T("E&xit"), _T("Exit"));
285
286         Connect(ID_NEW, wxEVT_COMMAND_MENU_SELECTED,
287                         wxCommandEventHandler(wxGUIEditorGraphicBBS::OnCreateNewTab));
288         Connect(ID_SAVE_DIAGRAM, wxEVT_COMMAND_MENU_SELECTED,
289                         wxCommandEventHandler(wxGUIEditorGraphicBBS::OnSaveActualDiagram)); //DFCH
290         Connect(ID_SAVE_AS_DIAGRAM, wxEVT_COMMAND_MENU_SELECTED,
291                         wxCommandEventHandler(wxGUIEditorGraphicBBS::OnSaveAsActualDiagram));
292         Connect(ID_OPEN_BBS, wxEVT_COMMAND_MENU_SELECTED,
293                         wxCommandEventHandler(wxGUIEditorGraphicBBS::OnOpenBBS));
294         Connect(ID_SAVE_AS_BBS, wxEVT_COMMAND_MENU_SELECTED,
295                         wxCommandEventHandler(wxGUIEditorGraphicBBS::OnSaveActualBBS));
296         Connect( ID_SAVE_AS_COMPLEXBOX, wxEVT_COMMAND_MENU_SELECTED,
297                         wxCommandEventHandler(wxGUIEditorGraphicBBS::OnSaveActualComplexBox));
298         Connect( ID_EXPORT_CONSOLEAPP, wxEVT_COMMAND_MENU_SELECTED,
299                                 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnExportConsoleExecCommand));
300         Connect(wxID_EXIT, wxEVT_COMMAND_MENU_SELECTED,
301                         wxCommandEventHandler(wxGUIEditorGraphicBBS::OnExit));
302
303         // Create Edit menu and its items
304         wxMenu *editMenu = new wxMenu;
305         editMenu->Append(ID_COPY_TO_COMPLEXDIAGRAM, _T("Copy selected to complex box"), _T("Creates a new complex box diagram with selected boxes"));
306         editMenu->Append(ID_EDIT_COMPLEXBOX_SCRIPT, _T("Edit Complex Box"), _T("Edit Complex Box"));
307         Connect( ID_COPY_TO_COMPLEXDIAGRAM, wxEVT_COMMAND_MENU_SELECTED,
308                          wxCommandEventHandler(wxGUIEditorGraphicBBS::OnCopySelectedToComplexDiagram));
309         Connect( ID_EDIT_COMPLEXBOX_SCRIPT, wxEVT_COMMAND_MENU_SELECTED,
310                         wxCommandEventHandler(wxGUIEditorGraphicBBS::OnEditComplexBoxScript));
311
312         // Create Help menu and its items
313         wxMenu *helpMenu = new wxMenu;
314         helpMenu->Append(wxID_ABOUT, _T("&About..."), _T("About"));
315         helpMenu->Append(ID_HELP_BBEDITOR, _T("&Help..."), _T("Help"));
316         Connect(ID_HELP_BBEDITOR, wxEVT_COMMAND_MENU_SELECTED,
317                         wxCommandEventHandler(wxGUIEditorGraphicBBS::OnHelpBBeditor));
318
319         // Create Tool menu
320         wxMenu *menuTools = new wxMenu;
321         menuTools->Append(ID_bbEditor_Tool_Menu_CreatePackage,
322                         _T("Create &package") );
323         menuTools->Append(ID_bbEditor_Tool_Menu_CreateBlackBox,
324                         _T("Create &blackbox") );
325         menuTools->Append(ID_bbEditor_Tool_Menu_PlugPackage, _T("Plug package") );
326         menuTools->Append(ID_bbEditor_Tool_Menu_EditConfig, _T("&Edit bbtk config") );
327         menuTools->Append(ID_bbEditor_Tool_Menu_ShowHTMLDoc,
328                         _T("Show &HTML documentation") );
329         menuTools->Append(ID_bbEditor_Tool_Menu_CreateIndex, _T("&Generate index") );
330
331         Connect(ID_bbEditor_Tool_Menu_CreatePackage, wxEVT_COMMAND_MENU_SELECTED,
332                         wxCommandEventHandler(wxGUIEditorGraphicBBS::OnCreatePackage));
333         Connect(ID_bbEditor_Tool_Menu_CreateBlackBox, wxEVT_COMMAND_MENU_SELECTED,
334                         wxCommandEventHandler(wxGUIEditorGraphicBBS::OnCreateBlackBox));
335         Connect(ID_bbEditor_Tool_Menu_PlugPackage, wxEVT_COMMAND_MENU_SELECTED,
336                         wxCommandEventHandler(wxGUIEditorGraphicBBS::OnPlugPackage));
337         Connect(ID_bbEditor_Tool_Menu_EditConfig, wxEVT_COMMAND_MENU_SELECTED,
338                         wxCommandEventHandler(wxGUIEditorGraphicBBS::OnEditConfig));
339         Connect(ID_bbEditor_Tool_Menu_ShowHTMLDoc, wxEVT_COMMAND_MENU_SELECTED,
340                         wxCommandEventHandler(wxGUIEditorGraphicBBS::OnShowHTMLDoc));
341         Connect(ID_bbEditor_Tool_Menu_CreateIndex, wxEVT_COMMAND_MENU_SELECTED,
342                         wxCommandEventHandler(wxGUIEditorGraphicBBS::OnCreateIndex));
343
344         // Append the created menu to the menu bar
345         wxMenuBar *menuBar = new wxMenuBar();
346         menuBar->Append(fileMenu, _T("&File") );
347         menuBar->Append(editMenu, _T("&Edit") );
348         menuBar->Append(menuTools, _T("&Tool") );
349         menuBar->Append(helpMenu, _T("&Help") );
350
351         // Attach this menu bar to the frame
352         SetMenuBar(menuBar);
353 }
354
355 //=========================================================================
356 void wxGUIEditorGraphicBBS::initTabPanelsManager() 
357 {
358         _notebook = new wxAuiNotebook(this, wxID_NOTEBOOK, wxDefaultPosition,
359                         wxDefaultSize, wxAUI_NB_TOP | wxAUI_NB_TAB_MOVE
360                                         | wxAUI_NB_CLOSE_ON_ACTIVE_TAB | wxAUI_NB_TAB_FIXED_WIDTH
361                                         | wxAUI_NB_WINDOWLIST_BUTTON);
362         _tabsMgr = new wxTabPanelsManager(this);
363         _frameAUIMgr->AddPane(_notebook, wxAuiPaneInfo().CenterPane());
364 }
365
366 //=========================================================================
367 void wxGUIEditorGraphicBBS::initPackageBrowser() 
368 {
369         _pkgBrowser = new WxGUIPackageBrowser2(this);
370         _pkgBrowser->IncludeAll();
371         _frameAUIMgr->AddPane(_pkgBrowser, wxAuiPaneInfo().Left().MinSize(30, 500).BestSize(750,500).CloseButton(false));
372 }
373
374 //================================================================
375
376 void wxGUIEditorGraphicBBS::DoRegeneratePackageDoc(const std::string& pack) 
377 {
378         std::string mess("Regenerating doc for package '");
379         if (pack != "-a") {
380                 mess += pack + "'";
381         } else {
382                 mess = "Regenerating doc for all packages";
383         }
384
385         mess += " ... please wait";
386
387         SetStatusText(std2wx(mess));
388
389         //BBTK_BUSY_CURSOR;
390
391         std::string command;
392 #if defined(WIN32)
393         command = "\"";
394 #endif
395         command += ConfigurationFile::GetInstance().Get_bin_path();
396         command += ConfigurationFile::GetInstance().Get_file_separator();
397         command += "bbRegeneratePackageDoc";
398 #if defined(WIN32)
399         command += "\"";
400 #endif
401
402         command += " " + pack + " -q";
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 package '")
409                  +std2wx(pack)+_T("' doc"),
410                  wxOK | wxICON_INFORMATION);
411                  */
412         } else {
413                 SetStatusText(_T("Done !"));
414                 wxString err(_T("An error occured while running '"));
415                 err += bbtk::std2wx(command) + _T("'");
416                 wxMessageBox(err, _T("Regenerate package doc"), wxOK | wxICON_ERROR);
417         }
418 }
419
420 //================================================================
421 void wxGUIEditorGraphicBBS::DoRegenerateBoxesLists() {
422         SetStatusText(_T("Regenerating boxes lists ... please wait"));
423         //BBTK_BUSY_CURSOR ;
424
425         std::string command;
426 #if defined(WIN32)
427         command = "\"";
428 #endif
429         command += ConfigurationFile::GetInstance().Get_bin_path();
430         command += ConfigurationFile::GetInstance().Get_file_separator();
431         command += "bbRegenerateBoxesLists";
432
433 #if defined(WIN32)
434         command += "\"";
435 #endif
436         command += " -q";
437
438         bbtkMessage("debug",1,"Executing system command '"<<command<<"'"<<std::endl);
439
440         if (!system(command.c_str())) {
441                 SetStatusText(_T("Done !"));
442                 /*
443                  wxMessageBox(_T("Done !"),_T("Regenerate boxes lists"),
444                  wxOK | wxICON_INFORMATION);
445                  */
446         } else {
447                 SetStatusText(_T("Done !"));
448                 wxString err(_T("An error occured while running '"));
449                 err += bbtk::std2wx(command) + _T("'");
450                 wxMessageBox(err, _T("Regenerate boxes lists"), wxOK | wxICON_ERROR);
451         }
452 }
453
454 //================================================================
455 void wxGUIEditorGraphicBBS::RegenerateAll() {
456         DoRegeneratePackageDoc("-a");
457         DoRegenerateBoxesLists();
458 }
459
460 //================================================================
461
462 wxAuiNotebook* wxGUIEditorGraphicBBS::getAuiNotebook() {
463         return _notebook;
464 }
465
466 //================================================================
467
468 void wxGUIEditorGraphicBBS::displayBlackBoxInfo(std::string packageName, std::string boxName) 
469 {
470         if (_actualPkgBrowserPkgName != packageName || _actualPkgBrowserBoxName != boxName) 
471         {
472
473                 _actualPkgBrowserPkgName = packageName;
474                 _actualPkgBrowserBoxName = boxName;
475
476 //EED 15 oct 2012               BlackBoxDescriptor::Pointer descriptor = GObjectsMVCFactory::getInstance()->getBlackBoxDescriptor(packageName, boxName);
477                 
478                 Package::Pointer k;
479 //EED           ComplexBlackBoxDescriptor::Pointer descriptor;
480                 BlackBoxDescriptor::Pointer descriptor;
481
482                 std::map< std::string, BlackBoxDescriptor::Pointer> mapDesc;
483                 k                       = _pkgBrowser->GetFactory()->GetPackage(_actualPkgBrowserPkgName);
484                 mapDesc         = k->GetDescriptorMap();                
485                 descriptor      = mapDesc[_actualPkgBrowserBoxName];
486 /*
487                 tree.treeTour(0);               
488
489                 tree.deleteTree();
490
491                 descriptor->GetBoxesInside(tree, 0);
492
493                 //tree.treeTour(0);
494                 //std::vector<std::string> boxesDiagram = _sceneM->boxesDiagram;
495                 //for(int i=0;i<boxesDiagram.size();i++){
496                 //      std::cout<<"caja: "<<boxesDiagram[i]<<std::endl;
497                 //}             
498                 
499                 _actualPkgBrowserPkgName = "";
500                 _actualPkgBrowserBoxName = "";
501 */
502                 /*
503                 Package::Pointer k;
504                 BlackBoxDescriptor::Pointer descriptor;
505                 std::map< std::string, BlackBoxDescriptor::Pointer> mapDesc;
506                 k                       = _pkgBrowser->GetFactory()->GetPackage(packageName);
507                 std::vector<std::string> temp;
508                 _pkgBrowser->GetFactory()->GetPackagesList(temp);
509                 for(int ii = 0 ; ii < temp.size() ; ii++)
510                 {
511                                 std::cout << " packs "<< temp[ii]<< std::endl;
512                 }
513                 mapDesc         = k->GetDescriptorMap();                
514                 descriptor      = mapDesc[boxName];
515                 */
516                 _pkgBrowser->WxGUIBlackBoxListUserOnSelected(descriptor.get());
517         }
518 }
519
520 //=========================================================================
521
522 void wxGUIEditorGraphicBBS::editBlackBox(GBlackBoxModel *bbmodel) {
523         wxBlackBoxEditionDialog* dialog =
524                         new wxBlackBoxEditionDialog(this, bbmodel);
525         dialog->Show();
526 }
527
528 //=========================================================================
529
530 bool wxGUIEditorGraphicBBS::boxNameExists(std::string boxname) {
531  
532         return this->_tabsMgr->getActualTabPanel()->getSceneManager()->boxExist(boxname);
533 }
534
535 //=========================================================================
536
537 void wxGUIEditorGraphicBBS::updateStatusBar(std::string textStatus) {
538         SetStatusText(crea::std2wx(textStatus));
539 }
540
541 //=========================================================================
542
543 void wxGUIEditorGraphicBBS::executeScript(std::string script) {
544         std::string separator =
545                         ConfigurationFile::GetInstance().Get_file_separator();
546         std::string dir = ConfigurationFile::GetInstance().Get_default_temp_dir();
547         std::string filename = dir + separator + "tmp_bbtk.bbs";
548
549         ofstream tempFile;
550         tempFile.open(filename.c_str());
551         tempFile << script;
552         tempFile.close();
553
554         std::string command = "";
555
556 #ifdef WIN32
557         command += "start /b ";
558 #endif
559
560         //              command += "\""+ crea::System::GetExecutablePath();
561         //#ifdef MACOSX
562         //              command += separator + "../../../bbi.app/Contents/MacOS";
563         //#endif
564
565         command += "bbi ";
566         command += "\"" + filename + "\"";
567
568 #ifndef WIN32
569         command += " & ";
570 #endif
571
572 #ifdef __APPLE__
573     command = "source ~/.bashrc ; "+command;
574 #endif
575
576
577         printf("RaC wxGUIEditorGraphicBBS::executeScript %s \n", command.c_str());
578         system(command.c_str());
579 }
580
581 //=========================================================================
582 std::string wxGUIEditorGraphicBBS::CheckExtension(std::string filename, std::string extension) {
583         if(filename.size() > extension.size() ){
584                 if( (filename.compare(filename.size()-extension.size(), extension.size(),extension)) !=0 ){
585                         filename.append(extension);
586                 }
587         }else{
588                 filename.append(extension);
589         }
590         return filename;
591 }
592 //=========================================================================
593 // EVENT HANDLERS
594 //=========================================================================
595
596 void wxGUIEditorGraphicBBS::OnCreateNewTab(wxCommandEvent& event) {
597         _tabsMgr->addNewTab();
598         refreshGUIControls();
599 }
600
601 void wxGUIEditorGraphicBBS::OnUndo(wxCommandEvent& event) {
602         unsigned short disable;
603         std::string stundo;
604         std::string stredo;
605
606         _tabsMgr->loadTempDiagram(0);
607         disable = _tabsMgr->getUndoState(stundo);
608         if(disable == 0)
609         {
610                 std::string name = _tabsMgr->GetNameTabPanel();
611                 if(name[name.length() - 1] == '*')
612                 {
613                         name =name.substr(0,name.length()-1);
614                 }
615                 _tabsMgr->SetNameTabPanel(wxString (name.c_str(), wxConvUTF8));
616         }
617
618         GetToolBar()->EnableTool(ID_UNDO,disable);
619         GetToolBar()->SetToolShortHelp(ID_UNDO,crea::std2wx(stundo));
620         GetToolBar()->EnableTool(ID_REDO,_tabsMgr->getRedoState(stredo));
621         GetToolBar()->SetToolShortHelp(ID_REDO,crea::std2wx(stredo));
622         refreshGUIControls();
623 }
624
625 //=========================================================================
626
627 void wxGUIEditorGraphicBBS::OnRedo(wxCommandEvent& event) {
628         unsigned short disable;
629         std::string stundo;
630         std::string stredo;
631
632         _tabsMgr->loadTempDiagram(1);
633         std::string name = _tabsMgr->GetNameTabPanel();
634         if(name[name.length() - 1] != '*')
635                 name +="*";
636         _tabsMgr->SetNameTabPanel(wxString (name.c_str(), wxConvUTF8));
637         GetToolBar()->EnableTool(ID_UNDO,_tabsMgr->getUndoState(stundo));
638         GetToolBar()->SetToolShortHelp(ID_UNDO,crea::std2wx(stundo));
639         GetToolBar()->EnableTool(ID_REDO,_tabsMgr->getRedoState(stredo));
640         GetToolBar()->SetToolShortHelp(ID_REDO,crea::std2wx(stredo));
641         refreshGUIControls();
642 }
643
644 void wxGUIEditorGraphicBBS::OnChangeName(wxCommandEvent& event){
645 }
646 //=========================================================================
647
648 void wxGUIEditorGraphicBBS::OnShowTree(wxCommandEvent& event){
649                 std::cout <<  "wxGUIEditorGraphicBBS::OnShowTree"<<std::endl;
650 if (_actualPkgBrowserPkgName !="" || _actualPkgBrowserBoxName != "") 
651         {
652                 Package::Pointer k;
653 //EED           ComplexBlackBoxDescriptor::Pointer descriptor;
654                 BlackBoxDescriptor::Pointer descriptor;
655
656                 std::map< std::string, BlackBoxDescriptor::Pointer> mapDesc;
657                 k                       = _pkgBrowser->GetFactory()->GetPackage(_actualPkgBrowserPkgName);
658                 mapDesc         = k->GetDescriptorMap();                
659                 descriptor      = mapDesc[_actualPkgBrowserBoxName];
660
661                 tree.treeTour(0);               
662
663                 tree.deleteTree();
664
665                 descriptor->GetBoxesInside(tree, 0);
666                 
667                 _actualPkgBrowserPkgName = "";
668                 _actualPkgBrowserBoxName = "";
669         }
670 else
671         {
672                 std::cout<<"Select a Box"<<std::endl;
673         }
674 }
675
676 //=========================================================================
677
678 void wxGUIEditorGraphicBBS::OnEditDiagramProperties(wxCommandEvent& event)
679 {
680         wxDiagramPropertiesEditionDialog* dialog =
681                                 new wxDiagramPropertiesEditionDialog(this, tree);
682         dialog->Show();
683 }
684
685 //=========================================================================
686 void wxGUIEditorGraphicBBS::OnExecuteActualDiagram(wxCommandEvent& event)
687 {
688         std::string script1 = _tabsMgr->getActualDiagramBBS(true);
689         cout << endl << "RaC wxGUIEditorGraphicBBS::executeActualDiagram SCRIPT"
690                         << endl << endl;
691         cout << script1 << endl;
692         std::string script2 = _tabsMgr->getActualDiagramBBS(false);
693         executeScript(script2);
694 }
695
696 //=========================================================================
697 void wxGUIEditorGraphicBBS::OpenBBS(std::string filePathName, std::string fileName) 
698 {
699         _tabsMgr->addNewTab( crea::std2wx(fileName) );
700         bbtk::InterpreterBBS::Pointer I = bbtk::InterpreterBBS::New( this->_tabsMgr->getActualTabPanel()->getSceneManager(), _pkgBrowser->GetFactory());
701         // We tell the interpreter to throw exceptions on error
702         I->SetThrow(true);
703         // Interpret the file supposed to define a box called 'Processing'
704         I->InterpretFile( filePathName );
705         refreshGUIControls();
706 }
707         
708 //=========================================================================
709 // HANDLERS
710 //=========================================================================
711 void wxGUIEditorGraphicBBS::OnOpenBBS(wxCommandEvent& event) 
712 {
713 //EED 2017-09-16 Migration wxWidgets 2.8 to 3.0
714 #if wxMAJOR_VERSION <= 2
715         wxFileDialog * openFileDialog = new wxFileDialog(this, wxT("Open BBS"), wxEmptyString, wxT("NewBBS"), wxT("*.bbs"), wxOPEN);
716 #else
717         wxFileDialog * openFileDialog = new wxFileDialog(this, wxT("Open BBS"), wxEmptyString, wxT("NewBBS"), wxT("*.bbs"), wxFD_OPEN);
718 #endif
719
720         if (openFileDialog->ShowModal() == wxID_OK) 
721         {
722                 OpenBBS( crea::wx2std(openFileDialog->GetPath()) , crea::wx2std(openFileDialog->GetFilename())  );
723         }
724         
725 /*EED Borrame   
726         if (openFileDialog->ShowModal() == wxID_OK) 
727         {
728                 wxString fileName = openFileDialog->GetPath();
729                 _tabsMgr->addNewTab(openFileDialog->GetFilename());
730                 bbtk::InterpreterBBS::Pointer I = bbtk::InterpreterBBS::New( this->_tabsMgr->getActualTabPanel()->getSceneManager(), _pkgBrowser->GetFactory());
731                 // We tell the interpreter to throw exceptions on error
732                 I->SetThrow(true);
733                 // Interpret the file supposed to define a box called 'Processing'
734                 I->InterpretFile((const char*) (fileName.mb_str()));
735         }
736         refreshGUIControls();
737 */ 
738 }
739
740 //=========================================================================
741 void wxGUIEditorGraphicBBS::SaveActualBBS(std::string filename) {
742         ofstream file;
743
744         //EED           file.open(fileName.c_str());
745         file.open(filename.c_str());
746         std::string content = "";
747         // writing file header
748         content += "# ----------------------------------\n";
749         content += "# - BBTKGEditor v ";
750         content += _currentBBGversion; //VERSION
751         content += " BBS BlackBox Script\n";
752         content += "# - ";
753         content += filename;
754         content += "\n";
755         content += "# ----------------------------------\n";
756         content += "\n";
757         content += _tabsMgr->getActualDiagramBBS();
758         file << content;
759         file.close();
760 }
761
762 void wxGUIEditorGraphicBBS::OnSaveActualBBS(wxCommandEvent& event) {
763
764 //EED 2017-09-16 Migration wxWidgets 2.8 to 3.0
765 #if wxMAJOR_VERSION <= 2
766         wxFileDialog * saveFileDialog = new wxFileDialog(this,
767                         wxT("Save  actual BBS"), wxEmptyString, wxT("NewBBS"),
768                         wxT("*.bbs"), wxSAVE | wxOVERWRITE_PROMPT);
769 #else
770         wxFileDialog * saveFileDialog = new wxFileDialog(this,
771                         wxT("Save  actual BBS"), wxEmptyString, wxT("NewBBS"),
772                         wxT("*.bbs"), wxFD_SAVE | wxFD_OVERWRITE_PROMPT);
773 #endif
774
775         if (saveFileDialog->ShowModal() == wxID_OK) {
776                 wxString fileName = saveFileDialog->GetPath();
777                 std::string filename = (const char*) (fileName.mb_str());
778                 filename=CheckExtension (filename, ".bbs");
779                 SaveActualBBS(filename);
780         }
781
782 }
783
784 void wxGUIEditorGraphicBBS::AskComplexBoxConfiguration() {
785         std::string cbName = _tabsMgr->GetCbName();
786         std::string paName = _tabsMgr->GetCbPackageName();
787
788         wxTextEntryDialog *cbNameDialog = new wxTextEntryDialog(this,
789                         wxT("Complex Box name"));
790         wxTextEntryDialog *paNameDialog = new wxTextEntryDialog(this,
791                         wxT("Package name"));
792
793         cbNameDialog->SetValue(wxString(cbName.c_str(), wxConvUTF8));
794         paNameDialog->SetValue(wxString(paName.c_str(), wxConvUTF8));
795
796         if (cbNameDialog->ShowModal() == wxID_OK) {
797                 wxString complexboxname = cbNameDialog->GetValue();
798                 cbName = (const char*) (complexboxname.mb_str());
799         }
800
801         if (paNameDialog->ShowModal() == wxID_OK) {
802                 wxString packagename = paNameDialog->GetValue();
803                 paName = (const char*) (packagename.mb_str());
804         }
805
806         _tabsMgr->SetCbName(cbName);
807         _tabsMgr->SetCbPackageName(paName);
808 }
809
810 //=========================================================================
811
812 void wxGUIEditorGraphicBBS::SaveActualComplexBox(std::string filename) {
813         ofstream file;
814         file.open(filename.c_str());
815
816         std::string content = "";
817
818         // writing file header
819         content += "# ----------------------------------\n";
820         content += "# - BBTKGEditor v ";
821         content += _currentBBGversion;//VERSION
822         content += " BBS BlackBox Script (Complex Box)\n";
823         content += "# - ";
824         content += filename;
825         content += "\n";
826         content += "# ----------------------------------\n";
827         content += "\n";
828         content += _tabsMgr->getActualComplexBoxBBS();
829         file << content;
830         file.close();
831 }
832
833 //=========================================================================
834
835 void wxGUIEditorGraphicBBS::OnSaveActualComplexBox(wxCommandEvent& event) 
836 {
837 //EED 2017-09-16 Migration wxWidgets 2.8 to 3.0
838 #if wxMAJOR_VERSION <= 2
839         wxFileDialog * saveFileDialog = new wxFileDialog(this,
840                         wxT("Save Complex Box BBS"), wxEmptyString,
841                         _T("ComplexBoxName"), wxT("*.bbs"), wxSAVE
842                                         | wxOVERWRITE_PROMPT);
843 #else
844         wxFileDialog * saveFileDialog = new wxFileDialog(this,
845                         wxT("Save Complex Box BBS"), wxEmptyString,
846                         _T("ComplexBoxName"), wxT("*.bbs"), wxFD_SAVE
847                                         | wxFD_OVERWRITE_PROMPT);
848 #endif
849
850         if (saveFileDialog->ShowModal() == wxID_OK) {
851                 wxString fileName = saveFileDialog->GetPath();
852                 std::string filename = (const char*) (fileName.mb_str());
853                 filename=CheckExtension (filename, ".bbs");
854                 SaveActualComplexBox(filename);
855         }
856 }
857
858 //=========================================================================
859 void wxGUIEditorGraphicBBS::SaveActualDiagram(std::string filename) {
860         ofstream file;
861         file.open(filename.c_str());
862
863         std::string content = "";
864
865         // writing file header
866         content += "# ----------------------------------\n";
867         content += "# - BBTKGEditor v ";
868         content += _currentBBGversion; //VERSION
869         content += " BBG BlackBox Diagram file\n";
870         content += "# - ";
871
872         content += filename;
873
874         content += "\n";
875         content += "# ----------------------------------\n";
876         content += "\n";
877         content += "APP_START\n";
878         _tabsMgr->saveActualDiagram(content, filename); //DFCH
879         content += "APP_END\n";
880         file << content;
881         file.close();
882 }
883
884 //=========================================================================
885 void wxGUIEditorGraphicBBS::SaveTempActualDiagram(const std::string &action) 
886 {
887         std::string stundo;
888         std::string stredo;
889         std::string name = _tabsMgr->GetNameTabPanel();
890         if(name[name.length() - 1] != '*')
891                 name +="*";
892         _tabsMgr->SetNameTabPanel(wxString (name.c_str(), wxConvUTF8));
893         _tabsMgr->saveTempActualDiagram(action);
894         GetToolBar()->EnableTool(ID_UNDO,_tabsMgr->getUndoState(stundo));
895         GetToolBar()->SetToolShortHelp(ID_UNDO,crea::std2wx(stundo));
896         GetToolBar()->EnableTool(ID_REDO,_tabsMgr->getRedoState(stredo));
897         GetToolBar()->SetToolShortHelp(ID_REDO,crea::std2wx(stredo));
898 }
899
900 //=========================================================================
901
902 //The following method allows to save the current diagram asking the filename
903 //DFCH
904 void wxGUIEditorGraphicBBS::SaveCurrentDiagramAs() 
905 {
906
907 //EED 2017-09-16 Migration wxWidgets 2.8 to 3.0
908 #if wxMAJOR_VERSION <= 2
909         wxFileDialog * saveFileDialog = new wxFileDialog(this,
910                         wxT("Save current diagram"), wxEmptyString, wxT("NewDiagram"),
911                         wxT("*.bbg"), wxSAVE | wxOVERWRITE_PROMPT);
912 #else
913         wxFileDialog * saveFileDialog = new wxFileDialog(this,
914                         wxT("Save current diagram"), wxEmptyString, wxT("NewDiagram"),
915                         wxT("*.bbg"), wxFD_SAVE | wxFD_OVERWRITE_PROMPT);
916 #endif
917
918         if (saveFileDialog->ShowModal() == wxID_OK) {
919                 //_tabsMgr->SetNameTabPanel(saveFileDialog->GetFilename());
920                 wxString pathfileName = saveFileDialog->GetPath();
921                 std::string pathfilename = (const char*) (pathfileName.mb_str());
922                 pathfilename=CheckExtension (pathfilename, ".bbg");
923
924                 //modify the tab name accordingly
925                 wxString fileName = saveFileDialog->GetFilename();
926                 std::string filename = (const char*) (fileName.mb_str());
927                 filename=CheckExtension (filename, ".bbg");
928                 _tabsMgr->SetNameTabPanel( wxString (filename.c_str(), wxConvUTF8) );
929
930                 std::string pathfilenamebbs = pathfilename;
931                 pathfilenamebbs[pathfilenamebbs.length() - 1] = 's';
932                 if (_tabsMgr->isActualDiagramComplexBox() == false) {
933                         SaveActualDiagram(pathfilename);
934                         SaveActualBBS(pathfilenamebbs);
935                 } else {
936                         AskComplexBoxConfiguration();
937                         SaveActualDiagram(pathfilename);
938                         SaveActualComplexBox(pathfilenamebbs);
939                 } //if isActualDiagramComplexBox
940         } // if saveFileDialog
941 }
942 //=========================================================================
943 //DFCH
944 void wxGUIEditorGraphicBBS::OnSaveActualDiagram(wxCommandEvent& event) {
945         std::string pathfilename = _tabsMgr->GetCurrentTabPanelPath();
946         if (pathfilename.empty()) {
947                 SaveCurrentDiagramAs();
948         } else {
949                 std::string pathfilenamebbs = pathfilename;
950                 pathfilenamebbs[pathfilenamebbs.length() - 1] = 's';
951                 if (_tabsMgr->isActualDiagramComplexBox() == false) {
952                         std::string name = _tabsMgr->GetNameTabPanel();
953                         if(name[name.length() - 1] == '*')
954                         {
955                                 name =name.substr(0,name.length()-1);
956                         }
957                         _tabsMgr->SetNameTabPanel(wxString (name.c_str(), wxConvUTF8));
958                         SaveActualDiagram(pathfilename);
959                         SaveActualBBS(pathfilenamebbs);
960                 } else {
961                         AskComplexBoxConfiguration();
962                         SaveActualDiagram(pathfilename);
963                         SaveActualComplexBox(pathfilenamebbs);
964                 } //if isActualDiagramComplexBox
965         if ((getCurrentDiagramExportFormat()==1) || (getCurrentDiagramExportFormat()==2) ) // 1:All 2:bbs,Python
966         {
967             std::string pathfilenamepy = pathfilenamebbs;
968             pathfilenamepy.replace( pathfilenamepy.length()-3, 3 , "py");
969             std::string cmdPy("source ~/.bashrc;  bbs2 "+pathfilenamebbs+" "+pathfilenamepy);
970             printf("EED wxGUIEditorGraphicBBS::OnSaveActualDiagram cmd:%s\n", cmdPy.c_str() );
971             system( cmdPy.c_str() );
972         } // ExportFormat 1 or 2  All and Python
973         if ((getCurrentDiagramExportFormat()==1) || (getCurrentDiagramExportFormat()==3) ) // 1:All 3:bbs,JavaScript
974         {
975             std::string pathfilenamejs = pathfilenamebbs;
976             pathfilenamejs.replace( pathfilenamejs.length()-3, 3 , "js");
977             std::string cmdjs("source ~/.bashrc;  bbs2 "+pathfilenamebbs+" "+pathfilenamejs);
978             printf("EED wxGUIEditorGraphicBBS::OnSaveActualDiagram cmd:%s\n", cmdjs.c_str() );
979             system( cmdjs.c_str() );
980         } // ExportFormat 1 or 3  All and JavaScript
981         } // if pathfilename empty
982 }
983 //=========================================================================
984 //DFCH
985 void wxGUIEditorGraphicBBS::OnSaveAsActualDiagram(wxCommandEvent& event) {
986         SaveCurrentDiagramAs();
987 }
988
989 //=========================================================================
990 void wxGUIEditorGraphicBBS::OnExportConsoleExecCommand(wxCommandEvent& event)
991 {
992 //EED 2017-09-16 Migration wxWidgets 2.8 to 3.0
993 #if wxMAJOR_VERSION <= 2
994         wxFileDialog * saveFileDialog = new wxFileDialog(this,
995                         wxT("Export console command"), wxEmptyString, wxT("ConsoleApp.txt"),
996                         wxT("*.txt;*.bbs;*.bbg;*.sh;*.bat"), wxSAVE | wxOVERWRITE_PROMPT);
997 #else
998         wxFileDialog * saveFileDialog = new wxFileDialog(this,
999                         wxT("Export console command"), wxEmptyString, wxT("ConsoleApp.txt"),
1000                         wxT("*.txt;*.bbs;*.bbg;*.sh;*.bat"), wxFD_SAVE | wxFD_OVERWRITE_PROMPT);
1001 #endif
1002
1003
1004         if (saveFileDialog->ShowModal() == wxID_OK)
1005         {
1006                 wxString fileName = saveFileDialog->GetPath();
1007                 std::string filename = (const char*) (fileName.mb_str());
1008                 filename=CheckExtension (filename, ".txt");
1009
1010                 ofstream file;
1011                 file.open(filename.c_str());
1012
1013                 std::vector<std::string> extInputs = _tabsMgr->getActualTabPanel()->getSceneManager()->GetExternalInputsNames();
1014
1015                 //TODO PUT IN A METHOD OF A FILES AND TEXT MANAGER CLASS !!!
1016                 //std::string inputsInCommentsWin="";
1017                 //std::string inputsInCommentsUnix="";
1018                 //std::string inputsInOneLineWin="";
1019                 std::string inputsInOneLineUnix="";
1020                 for (unsigned int i = 0; i < extInputs.size(); ++i)
1021                 {
1022                         /* No gusto la idea al jefe pero por si acaso ...
1023                         * RaC 2012 2nd HackFest
1024                         *
1025                         inputsInCommentsWin+="REM ";
1026                         inputsInCommentsWin+=extInputs[i];
1027                         inputsInCommentsWin+="=\"value\"\n";
1028                         inputsInCommentsUnix+="# ";
1029                         inputsInCommentsUnix+=extInputs[i];
1030                         inputsInCommentsUnix+="=\"value\"\n";
1031
1032                         char buffer [50];
1033                         sprintf (buffer, "%d", (i+1));
1034                         inputsInOneLineWin+=extInputs[i];
1035                         inputsInOneLineWin+="=\"%";
1036                         inputsInOneLineWin+=buffer;
1037                         inputsInOneLineWin+="\" ";
1038                         */
1039                         inputsInOneLineUnix+=extInputs[i];
1040                         inputsInOneLineUnix+="=\"<value>\" ";
1041
1042                 }
1043
1044
1045                 std::string content = "";
1046                 // writing file header
1047                 content += "# ----------------------------------\n";
1048                 content += "# - BBTKGEditor v ";
1049                 content += _currentBBGversion; //VERSION
1050                 content += " Console Commands to execute BBS application\n";
1051                 content += "# - ";
1052                 content += filename;
1053                 content += "\n";
1054                 content += "# ----------------------------------\n";
1055                 content += "\n";
1056                 content += "\n";
1057                 content += "# Command to execute bbi\n";
1058                 content += "bbi <bbs_path> ";
1059                 content += inputsInOneLineUnix;
1060
1061                 /* No gusto la idea al jefe pero por si acaso ...
1062                  * RaC 2012 2nd HackFest
1063                  content += "# For Windows (copy the following lines to a .bat file)\n";
1064                  content += "REM BBS application\n";
1065                  content += "REM Inputs:\n";
1066                  content += inputsInCommentsWin;
1067                  content += "REM To use previous inputs, put %$inputName% in the corresponding input of the execution bbi line\n";
1068                  content += "bbi applicationBBS.bbs ";
1069                  content += inputsInOneLineWin;
1070                  content += "\n";
1071                  content += "\n";
1072                  content += "# For Linux or Mac (copy the following lines to a .sh file)\n";
1073                  content += "#!/bin/bash\n";
1074                  content += "# BBS application\n";
1075                  content += "# Inputs:\n";
1076                  content += inputsInCommentsUnix;
1077                  content += "# To use previous inputs, put $inputName in the corresponding input of the execution bbi line\n";
1078                  content += "bbi applicationBBS.bbs ";
1079                  content += inputsInOneLineUnix;
1080                  content += "\n";
1081                 */
1082
1083                 file << content;
1084                 file.close();
1085         }
1086
1087
1088 }
1089
1090 //=========================================================================
1091
1092 void wxGUIEditorGraphicBBS::refreshGUIControls() 
1093 {
1094         std::string stundo;
1095         std::string stredo;
1096         //RaC2012 2ndHackFest Next line seems weird ... To keep in mind for other devels
1097         wxToolBar* toolbar = GetToolBar();
1098         if (_tabsMgr->isActualDiagramComplexBox()) 
1099         {
1100                 toolbar->ToggleTool(ID_BTNCOMPLEXBOX, true);
1101                 //toolbar->EnableTool(ID_ADDCOMPLEXBOXINPUT, true); RaC2012 2nd HackFest
1102                 toolbar->EnableTool(ID_ADDCOMPLEXBOXOUTPUT, true);
1103
1104                 GetMenuBar()->GetMenu(0)->Enable(ID_SAVE_AS_COMPLEXBOX, true);
1105                 GetMenuBar()->GetMenu(0)->Enable(ID_SAVE_AS_BBS, false);
1106                 GetMenuBar()->GetMenu(0)->Enable(ID_EXPORT_CONSOLEAPP, false);
1107         } else {
1108                 toolbar->ToggleTool(ID_BTNCOMPLEXBOX, false);
1109                 //toolbar->EnableTool(ID_ADDCOMPLEXBOXINPUT, false); RaC2012 2nd HackFest
1110                 toolbar->EnableTool(ID_ADDCOMPLEXBOXOUTPUT, false);
1111
1112                 GetMenuBar()->GetMenu(0)->Enable(ID_SAVE_AS_COMPLEXBOX, false);
1113                 GetMenuBar()->GetMenu(0)->Enable(ID_SAVE_AS_BBS, true);
1114                 GetMenuBar()->GetMenu(0)->Enable(ID_EXPORT_CONSOLEAPP, true);
1115         }
1116
1117         //RaC2012 2ndHackFest
1118         GetToolBar()->EnableTool(ID_EDITPROPERTIES,true);
1119
1120         GetToolBar()->EnableTool(ID_UNDO,_tabsMgr->getUndoState(stundo));
1121         GetToolBar()->SetToolShortHelp(ID_UNDO,crea::std2wx(stundo));
1122         GetToolBar()->EnableTool(ID_REDO,_tabsMgr->getRedoState(stredo));
1123         GetToolBar()->SetToolShortHelp(ID_REDO,crea::std2wx(stredo));
1124
1125         if (_tabsMgr->getNumActualSelectedObjects() > 0) {
1126                 GetMenuBar()->GetMenu(1)->Enable(ID_COPY_TO_COMPLEXDIAGRAM, true);
1127         } else {
1128                 ///TODO Fix the possibility to say from the SceneManager to the GUI to refresh the options
1129                 GetMenuBar()->GetMenu(1)->Enable(ID_COPY_TO_COMPLEXDIAGRAM, true);
1130         }
1131
1132 }
1133
1134 //=========================================================================
1135
1136 void wxGUIEditorGraphicBBS::OnDeleteAllBoxesActualDiagram(wxCommandEvent& event) 
1137 {
1138         wxMessageDialog *dial = new wxMessageDialog(NULL,wxT("Are you sure to delete all boxes of the diagram?"),wxT("Delete all boxes"), wxYES_NO | wxNO_DEFAULT| wxICON_QUESTION);
1139         if (dial->ShowModal() == wxID_YES)
1140         {
1141                 _tabsMgr->deleteAllBoxesActualDiagram();
1142         }
1143 }
1144
1145 //=========================================================================
1146
1147 void wxGUIEditorGraphicBBS::OnCenterViewActualDiagram(wxCommandEvent& event) 
1148 {
1149         _tabsMgr->centerViewActualDiagram();
1150 }
1151
1152 //=========================================================================
1153 void wxGUIEditorGraphicBBS::OpenDiagram(std::string filePathName, std::string fileName) 
1154 {
1155         ifstream inputStream;   
1156         inputStream.open(filePathName.c_str());
1157         assert(inputStream.good()); // fails
1158         
1159         if(_tabsMgr->FindTab(filePathName)!=-1) //RaC2012 avoid opening same diagram twice
1160         {
1161                 inputStream.close();
1162                 printf("RaC: Diagram already opened\n");
1163                 return;
1164         }
1165         _tabsMgr->addNewTab( crea::std2wx(fileName) );
1166         _tabsMgr->loadDiagram(inputStream, filePathName);
1167
1168         _tabsMgr->saveTempActualDiagram("load diagram");
1169         GetToolBar()->EnableTool(ID_UNDO, false);
1170         GetToolBar()->EnableTool(ID_UNDO, false);
1171         inputStream.close();
1172         refreshGUIControls();
1173 }
1174         
1175 //=========================================================================
1176
1177 void wxGUIEditorGraphicBBS::OnOpenDiagram(wxCommandEvent& event) 
1178 {
1179
1180 //EED 2017-09-16 Migration wxWidgets 2.8 to 3.0
1181 #if wxMAJOR_VERSION <= 2
1182         wxFileDialog * openFileDialog = new wxFileDialog(this, wxT("Open diagram"), wxEmptyString, wxT(""), wxT("*.bbg"), wxOPEN | wxFILE_MUST_EXIST);
1183 #else
1184         wxFileDialog * openFileDialog = new wxFileDialog(this, wxT("Open diagram"), wxEmptyString, wxT(""), wxT("*.bbg"), wxFD_OPEN | wxFD_FILE_MUST_EXIST);
1185 #endif
1186
1187         if (openFileDialog->ShowModal() == wxID_OK) 
1188         {
1189                 wxString filePath = openFileDialog->GetPath();
1190                 wxString fileName = openFileDialog->GetFilename();
1191                 OpenDiagram( crea::wx2std(filePath) , crea::wx2std(fileName) );                                 
1192         }
1193 }
1194
1195 //=========================================================================
1196 void wxGUIEditorGraphicBBS::OnClickBtnBox(wxCommandEvent& event) 
1197 {
1198         std::cout<<"wxGUIEditorGraphicBBS::OnClickBtnBox"<<std::endl;
1199         BlackBoxDescriptor *bbDes = _pkgBrowser->GetActualSelected();
1200         if (bbDes != NULL) {
1201                 std::string typeName = bbDes->GetTypeName();
1202                 std::string packageName = bbDes->GetPackage()->GetName();
1203                 wxGEditorTabPanel *pnl = this->_tabsMgr->getActualTabPanel();
1204                 if (pnl != NULL) {
1205                         wxVtkSceneManager *scn = pnl->getSceneManager();
1206                         scn->createGBlackBox(50, 50, packageName, typeName);
1207                         scn->refresh();
1208                 }
1209                 SaveTempActualDiagram("New Box");
1210                 // if pnl
1211         }// if bbDes
1212 }
1213
1214 //=========================================================================
1215 //2022-10-28
1216 void wxGUIEditorGraphicBBS::OnClickBtnSelectBoxes(wxCommandEvent& event)
1217 {
1218    std::string nameFilter = _pkgBrowser->GetNameFilter();
1219    _tabsMgr->SelectBoxWithPossibleName( nameFilter );
1220 }
1221
1222 //=========================================================================
1223
1224 void wxGUIEditorGraphicBBS::OnClickBtnExecutableBox(wxCommandEvent& event) 
1225 {
1226         //DFCH
1227         wxGEditorTabPanel *pnl = this->_tabsMgr->getActualTabPanel();
1228
1229         if (pnl != NULL) {
1230                 wxVtkSceneManager *scn = pnl->getSceneManager();
1231                 if( scn->MakeBoxExecutable() )
1232                         std::cout<<"DFCH: wxGUIEditorGraphicBBS::OnClickBtnExecutableBox...successful"<<std::endl;
1233                 else
1234                         std::cout<<"DFCH: wxGUIEditorGraphicBBS::OnClickBtnExecutableBox...Error!!"<<std::endl;
1235         }
1236         //DFCH
1237
1238 }
1239
1240 //=========================================================================
1241 void wxGUIEditorGraphicBBS::OnClickBtnComplexBox(wxCommandEvent& event) 
1242 {
1243         std::cout<<"wxGUIEditorGraphicBBS::OnClickBtnComplexBox"<<std::endl;
1244         wxToolBar* toolbar = GetToolBar();
1245         bool temp = toolbar->GetToolState(ID_BTNCOMPLEXBOX);
1246         if (temp) {
1247                 enableComplexBox();
1248         } else {
1249                 disableComplexBox();
1250         }
1251 }
1252
1253 //=========================================================================
1254 //EED01
1255 void wxGUIEditorGraphicBBS::OnAddComplexBoxInput(wxCommandEvent& event) 
1256 {
1257         wxTextEntryDialog *nameDialog = new wxTextEntryDialog(this,
1258                         wxT("Name of input port"));
1259         if (nameDialog->ShowModal() == wxID_OK) 
1260         {
1261                 wxString fileName = nameDialog->GetValue();
1262                 if (!fileName.IsEmpty()) 
1263                 {
1264                         std::string portName = (const char*) (fileName.mb_str());
1265                         if ( !boxNameExists(portName) )
1266                         {
1267                            _tabsMgr->addActualDiagramComplexInputPort(portName);
1268                         } else {
1269                            wxMessageDialog *dial = new wxMessageDialog(NULL,
1270                                        wxT("Impossible to create Box. The name already exists. Please provide another name"),
1271                                        wxT("Change name: name already exists"), wxOK | wxICON_EXCLAMATION | wxSTAY_ON_TOP);
1272                            dial->ShowModal();
1273                         }
1274                 } // if !fileName
1275         } // if namaDialog
1276 }
1277
1278 //=========================================================================
1279 void wxGUIEditorGraphicBBS::OnAddComplexBoxOutput(wxCommandEvent& event) 
1280 {
1281         wxTextEntryDialog *nameDialog = new wxTextEntryDialog(this,
1282                         wxT("Name of output port"));
1283         if (nameDialog->ShowModal() == wxID_OK) 
1284         {
1285                 wxString fileName = nameDialog->GetValue();
1286                 if (!fileName.IsEmpty()) 
1287                 {
1288                         std::string portName = (const char*) (fileName.mb_str());
1289                         if ( !boxNameExists(portName) )
1290                         {
1291                         _tabsMgr->addActualDiagramComplexOutputPort(portName);
1292                         } else {
1293                            wxMessageDialog *dial = new wxMessageDialog(NULL,
1294                                        wxT("Impossible to create Box. The name already exists. Please provide another name"),
1295                                        wxT("Change name: name already exists"), wxOK | wxICON_EXCLAMATION | wxSTAY_ON_TOP);
1296                            dial->ShowModal();
1297                         }
1298
1299                 } // if !filename
1300         } // namaDialog
1301 }
1302
1303 //=========================================================================
1304 void wxGUIEditorGraphicBBS::OnCopySelectedToComplexDiagram(
1305                 wxCommandEvent& event) 
1306 {
1307         _tabsMgr->copySelectedBBoxesToComplexDiagram();
1308 }
1309
1310 //=========================================================================
1311 void wxGUIEditorGraphicBBS::OnHelpBBeditor(wxCommandEvent& event) 
1312 {
1313         printf("wxGUIEditorGraphicBBS::OnHelpBBeditor ....not implemented..\n");
1314 }
1315
1316 //=========================================================================
1317 void wxGUIEditorGraphicBBS::OnCreatePackage(wxCommandEvent& event) 
1318 {
1319         bbtkSystemTools::CreatePackage();
1320 }
1321
1322 //=========================================================================
1323 void wxGUIEditorGraphicBBS::OnCreateBlackBox(wxCommandEvent& event) 
1324 {
1325         bbtkSystemTools::CreateBlackBox();
1326 }
1327         
1328 //=========================================================================
1329 void wxGUIEditorGraphicBBS::OnPlugPackage(wxCommandEvent& event) 
1330 {
1331         //DFGO2012 Plug Package functionnalities
1332         long style = wxDD_DEFAULT_STYLE | wxDD_DIR_MUST_EXIST;
1333         wxDirDialog* FD =
1334           new wxDirDialog( 0,
1335                            _T("Select package directory"),
1336                            _T(""),
1337                            style);
1338         long userResponse;
1339         do
1340         {
1341                 userResponse = FD->ShowModal();
1342                 if(userResponse==wxID_OK)
1343                 {
1344                         std::string path = wx2std (FD->GetPath()) ;
1345                         #ifdef WIN32
1346                         std::string fname = path + "\\bbtkPackage";
1347                         #else
1348                         std::string fname = path + "/bbtkPackage";
1349                         #endif
1350                         
1351                         std::cout << "Path chosen = \"" << FD->GetPath() << "\"" << std::endl;
1352                         if ( Utilities::FileExists( fname ) )
1353                         {
1354                                 std::ifstream f;
1355                                 f.open(fname.c_str());
1356                                 std::string pname;
1357                                 f >> pname;
1358                                 while(pname[0] == '#')
1359                                 {
1360                                         getline(f, pname, '\n');
1361                                         f >> pname;
1362                                 }
1363                                 f.close();
1364
1365                                 bbtk::ConfigurationFile::GetInstance().AddPackagePathsAndWrite( path );
1366
1367                                 DoRegeneratePackageDoc(pname);
1368                                 DoRegenerateBoxesLists();
1369
1370                                 _pkgBrowser->RebuildList();
1371
1372                                 wxMessageBox(_T("Package successfully plugged. Please restart bbEditor to see the new package in the package browser."),_T("Plug package"),wxOK | wxICON_INFORMATION);
1373                                 userResponse = wxID_CANCEL;
1374                         }
1375                         else
1376                         {
1377                                 std::string err = "The directory \"" + path + "\" does not contain a 'bbtkPackage' file.";
1378                                 #ifndef WIN32
1379                                         #ifndef MACOSX
1380                                                 err += "\nNote: If you are on Linux please select the folder and click \"Open\", don't enter in it.";
1381                                         #endif
1382                                 #endif
1383
1384                                 wxMessageBox(crea::std2wx(err), _T("Plug package"),wxOK | wxICON_ERROR);
1385                                 // THE FOLLOWING LINE GIVES ERRORS BECAUSE IT IS NECESSARY TO USE std2wx
1386                                 //wxMessageBox( _T( err) , _T("Plug package"),wxOK | wxICON_ERROR);
1387                         }
1388                 }
1389         }while(userResponse != wxID_CANCEL);
1390
1391 }
1392         
1393 //=========================================================================
1394 void wxGUIEditorGraphicBBS::OnEditConfig(wxCommandEvent& event) 
1395 {
1396         std::string commandStr;
1397             std::string configFile = ConfigurationFile::GetInstance().Get_config_xml_full_path();
1398         #ifdef WIN32
1399                 commandStr = "notepad.exe ";
1400         #else
1401                 commandStr = "gedit ";
1402         #endif
1403                 commandStr = commandStr + configFile;
1404                 std::cout << "system: " << commandStr << std::endl;
1405                 system ( commandStr.c_str() );
1406 }
1407         
1408 //=========================================================================
1409 void wxGUIEditorGraphicBBS::OnShowHTMLDoc(wxCommandEvent& event) 
1410 {
1411         // JGRR & CM WH
1412         if (_helpHtmlBrowser != NULL){
1413              _frameAUIMgr->DetachPane(_helpHtmlBrowser);
1414             _helpHtmlBrowser->Destroy();   
1415         }
1416         initHelpHTMLBrowser();
1417         _frameAUIMgr->AddPane(_helpHtmlBrowser, wxAuiPaneInfo().Right().MinSize(200, 200));
1418         _frameAUIMgr->Update();
1419         refreshGUIControls();
1420         
1421         // EO JGRR    & CM WH       
1422 }
1423         
1424 //=========================================================================
1425 void wxGUIEditorGraphicBBS::OnCreateIndex(wxCommandEvent& event) 
1426 {
1427         printf("EED wxGUIEditorGraphicBBS::OnCreateIndex ... not implemented ..\n");
1428 }
1429
1430         
1431 //=========================================================================
1432 void wxGUIEditorGraphicBBS::OnEditComplexBoxScript(wxCommandEvent& event)
1433 {
1434         BlackBoxDescriptor *bbDes = _pkgBrowser->GetActualSelected();
1435         if (bbDes != NULL) 
1436         {
1437                 std::string packageName = bbDes->GetPackage()->GetName();
1438                 std::string typeName = bbDes->GetTypeName();
1439                 if (!TryToOpenScriptComplexBox(packageName ,typeName))
1440                 {
1441                         wxMessageDialog windowMessage1(NULL,_T("This is not a ComplexBox script."), _T("Alert !"), wxOK);
1442                         windowMessage1.ShowModal();
1443                 }
1444         }// if bbDes
1445 }
1446
1447 //=========================================================================
1448 void wxGUIEditorGraphicBBS::OnExit(wxCommandEvent& event) 
1449 {
1450         Close(true);
1451 }
1452
1453 Factory::Pointer wxGUIEditorGraphicBBS::GetBBTKFactory()
1454 {
1455         if (_pkgBrowser==NULL) 
1456         {
1457                 printf ("EED ERROR! wxGUIEditorGraphicBBS::GetBBTKFactory _pkgBrowser = NULL\n");
1458         }
1459         return _pkgBrowser->GetFactory();
1460 }
1461
1462 //=========================================================================
1463 void wxGUIEditorGraphicBBS::enableComplexBox() 
1464 {
1465         _tabsMgr->setActualDiagramComplexBox(true);
1466         refreshGUIControls();
1467 }
1468
1469 //=========================================================================
1470
1471 void wxGUIEditorGraphicBBS::disableComplexBox() 
1472 {
1473         _tabsMgr->setActualDiagramComplexBox(false);
1474         refreshGUIControls();
1475 }
1476
1477 //=========================================================================
1478 void wxGUIEditorGraphicBBS::setCurrentDiagramDescription(std::string description)
1479 {
1480         _tabsMgr->SetDescription(description);
1481 }
1482
1483 //=========================================================================
1484 void wxGUIEditorGraphicBBS::setCurrentDiagramAuthor(std::string author)
1485 {
1486         _tabsMgr->SetAuthor(author);
1487 }
1488
1489 //=========================================================================
1490 void wxGUIEditorGraphicBBS::setCurrentDiagramExportFormat(int exportformat)
1491 {
1492     _tabsMgr->SetExportFormat( exportformat );
1493 }
1494
1495 //=========================================================================
1496 void wxGUIEditorGraphicBBS::setCurrentDiagramCategory(std::string category)
1497 {
1498         _tabsMgr->SetCategory(category);
1499 }
1500
1501 //=========================================================================
1502 void wxGUIEditorGraphicBBS::setCurrentDiagramMessageKind(std::string kind){
1503         _tabsMgr->SetMessageKind(kind); 
1504 }
1505
1506 //=========================================================================
1507 void wxGUIEditorGraphicBBS::setCurrentDiagramMessageLevel(std::string level){
1508         _tabsMgr->SetMessageLevel(level);       
1509 }
1510
1511 //=========================================================================
1512 std::string wxGUIEditorGraphicBBS::getCurrentDiagramDescription()
1513 {
1514         return _tabsMgr->GetDescription();
1515 }
1516
1517 //=========================================================================
1518 std::string wxGUIEditorGraphicBBS::getCurrentDiagramAuthor()
1519 {
1520         return _tabsMgr->GetAuthor();
1521 }
1522
1523 //=========================================================================
1524 int wxGUIEditorGraphicBBS::getCurrentDiagramExportFormat()
1525 {
1526     return _tabsMgr->GetExportFormat();
1527 }
1528
1529 //=========================================================================
1530 std::string wxGUIEditorGraphicBBS::getCurrentDiagramCategory()
1531 {
1532         return _tabsMgr->GetCategory();
1533 }
1534
1535 //=========================================================================
1536 std::string wxGUIEditorGraphicBBS::getCurrentDiagramMessageKind(){
1537         return _tabsMgr->GetMessageKind();
1538 }
1539
1540 //=========================================================================
1541 std::string wxGUIEditorGraphicBBS::getCurrentDiagramMessageLevel(){
1542         return _tabsMgr->GetMessageLevel();
1543 }
1544
1545 //=========================================================================
1546 bool wxGUIEditorGraphicBBS::isCurrentDiagramComplexBox()
1547 {
1548         return _tabsMgr->isActualDiagramComplexBox();
1549 }
1550
1551
1552 //=========================================================================
1553 void wxGUIEditorGraphicBBS::OpenScript(std::string filePathNameBBS ,std::string boxType)
1554 {       
1555         std::string fileName                                                    = boxType+".bbg";
1556         std::string filePathNameBBG                                             = filePathNameBBS;
1557         filePathNameBBG[ filePathNameBBG.length()-1 ]   = 'g';
1558         
1559         wxMessageDialog windowMessage1(NULL,_T("The system is going to open a bbg or bbs for you. Be careful if you save this file."), _T("Alert !"), wxOK);
1560         windowMessage1.ShowModal();
1561         
1562         if ( Utilities::FileExists( filePathNameBBG ) )
1563         {
1564                 OpenDiagram( filePathNameBBG , fileName );     
1565         } else {
1566                 if ( Utilities::FileExists( filePathNameBBS ) )
1567                 {
1568                         OpenBBS( filePathNameBBS , fileName );     
1569                 } else {
1570                         wxMessageDialog windowMessage1(NULL,_T("..ERROR.. loading script bbg/bbs."), _T("Alert !"), wxOK);
1571                         windowMessage1.ShowModal();
1572                 } // FileExists BBS
1573         } // FieExists BBG
1574 } //OpenScript
1575         
1576         
1577         
1578 //=========================================================================
1579 bool wxGUIEditorGraphicBBS::TryToOpenScriptApplication(std::string packageName ,std::string boxType)
1580 {       
1581         return TryToOpenScript(packageName ,boxType, true, false);
1582 }               
1583
1584 //=========================================================================
1585 bool wxGUIEditorGraphicBBS::TryToOpenScriptComplexBox(std::string packageName ,std::string boxType)
1586 {       
1587         return TryToOpenScript(packageName ,boxType, false, true);
1588 }               
1589         
1590         
1591 //=========================================================================
1592 bool wxGUIEditorGraphicBBS::TryToOpenScript(std::string packageName ,std::string boxType,bool scriptApplication, bool scriptComplexBox)
1593 {       
1594         Package::Pointer k;
1595         std::map< std::string, BlackBoxDescriptor::Pointer> mapDesc;
1596         BlackBoxDescriptor::Pointer descriptor;
1597         k                       = GetBBTKFactory()->GetPackage(packageName);
1598         mapDesc         = k->GetDescriptorMap();
1599         descriptor      = mapDesc[boxType];
1600
1601         bool result=false;
1602     descriptor->IsTypeOfScript_Application();   
1603         if (descriptor!=NULL)
1604         {
1605                 if ( 
1606                         ((descriptor->IsTypeOfScript_Application()==true) && (scriptApplication==true))
1607                         ||
1608                         ((descriptor->IsTypeOfScript_ComplexBox()==true) && (scriptComplexBox==true))           
1609                         )
1610                 {
1611                         result=true;
1612                         OpenScript(descriptor->GetScriptFileName(),boxType);
1613                 } // if descriptor Type
1614         } else {
1615                 printf("EED ERROR wxGUIEditorGraphicBBS::TryToOpenScript >> The descriptor of this box not exists (packageName:%s  boxType:%s) this is not normal\n",packageName.c_str(), boxType.c_str() );
1616         }  // if descriptor NULL
1617         
1618         return result;
1619 }       
1620         
1621 } // EO namespace bbtk
1622
1623 // EOF
1624