]> Creatis software - bbtkGEditor.git/blob - lib/EditorGraphicBBS/bbsWxGUIEditorGraphic/bbtkwxGUIEditorGraphicBBS.cxx
Clean code for Python
[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.5";
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                 
952                 if (_tabsMgr->isActualDiagramComplexBox() == false) {
953                         std::string name = _tabsMgr->GetNameTabPanel();
954                         if(name[name.length() - 1] == '*')
955                         {
956                                 name =name.substr(0,name.length()-1);
957                         }
958                         _tabsMgr->SetNameTabPanel(wxString (name.c_str(), wxConvUTF8));
959                         SaveActualDiagram(pathfilename);
960                         SaveActualBBS(pathfilenamebbs);
961                 } else {
962                         AskComplexBoxConfiguration();
963                         SaveActualDiagram(pathfilename);
964                         SaveActualComplexBox(pathfilenamebbs);
965                 } //if isActualDiagramComplexBox
966         std::string pathfilenamepy = pathfilenamebbs;
967         pathfilenamepy.replace( pathfilenamepy.length()-3, 3 , "py");
968         std::string cmdPy("source ~/.bashrc;  bbs2 "+pathfilenamebbs+" "+pathfilenamepy);
969         printf("EED wxGUIEditorGraphicBBS::OnSaveActualDiagram cmd:%s\n", cmdPy.c_str() );
970         system( cmdPy.c_str() );
971         std::string pathfilenamejs = pathfilenamebbs;
972         pathfilenamejs.replace( pathfilenamejs.length()-3, 3 , "js");
973         std::string cmdjs("source ~/.bashrc;  bbs2 "+pathfilenamebbs+" "+pathfilenamejs);
974         printf("EED wxGUIEditorGraphicBBS::OnSaveActualDiagram cmd:%s\n", cmdjs.c_str() );
975         system( cmdjs.c_str() );
976         }
977 }
978 //=========================================================================
979 //DFCH
980 void wxGUIEditorGraphicBBS::OnSaveAsActualDiagram(wxCommandEvent& event) {
981         SaveCurrentDiagramAs();
982 }
983
984 //=========================================================================
985 void wxGUIEditorGraphicBBS::OnExportConsoleExecCommand(wxCommandEvent& event)
986 {
987 //EED 2017-09-16 Migration wxWidgets 2.8 to 3.0
988 #if wxMAJOR_VERSION <= 2
989         wxFileDialog * saveFileDialog = new wxFileDialog(this,
990                         wxT("Export console command"), wxEmptyString, wxT("ConsoleApp.txt"),
991                         wxT("*.txt;*.bbs;*.bbg;*.sh;*.bat"), wxSAVE | wxOVERWRITE_PROMPT);
992 #else
993         wxFileDialog * saveFileDialog = new wxFileDialog(this,
994                         wxT("Export console command"), wxEmptyString, wxT("ConsoleApp.txt"),
995                         wxT("*.txt;*.bbs;*.bbg;*.sh;*.bat"), wxFD_SAVE | wxFD_OVERWRITE_PROMPT);
996 #endif
997
998
999         if (saveFileDialog->ShowModal() == wxID_OK)
1000         {
1001                 wxString fileName = saveFileDialog->GetPath();
1002                 std::string filename = (const char*) (fileName.mb_str());
1003                 filename=CheckExtension (filename, ".txt");
1004
1005                 ofstream file;
1006                 file.open(filename.c_str());
1007
1008                 std::vector<std::string> extInputs = _tabsMgr->getActualTabPanel()->getSceneManager()->GetExternalInputsNames();
1009
1010                 //TODO PUT IN A METHOD OF A FILES AND TEXT MANAGER CLASS !!!
1011                 //std::string inputsInCommentsWin="";
1012                 //std::string inputsInCommentsUnix="";
1013                 //std::string inputsInOneLineWin="";
1014                 std::string inputsInOneLineUnix="";
1015                 for (unsigned int i = 0; i < extInputs.size(); ++i)
1016                 {
1017                         /* No gusto la idea al jefe pero por si acaso ...
1018                         * RaC 2012 2nd HackFest
1019                         *
1020                         inputsInCommentsWin+="REM ";
1021                         inputsInCommentsWin+=extInputs[i];
1022                         inputsInCommentsWin+="=\"value\"\n";
1023                         inputsInCommentsUnix+="# ";
1024                         inputsInCommentsUnix+=extInputs[i];
1025                         inputsInCommentsUnix+="=\"value\"\n";
1026
1027                         char buffer [50];
1028                         sprintf (buffer, "%d", (i+1));
1029                         inputsInOneLineWin+=extInputs[i];
1030                         inputsInOneLineWin+="=\"%";
1031                         inputsInOneLineWin+=buffer;
1032                         inputsInOneLineWin+="\" ";
1033                         */
1034                         inputsInOneLineUnix+=extInputs[i];
1035                         inputsInOneLineUnix+="=\"<value>\" ";
1036
1037                 }
1038
1039
1040                 std::string content = "";
1041                 // writing file header
1042                 content += "# ----------------------------------\n";
1043                 content += "# - BBTKGEditor v ";
1044                 content += _currentBBGversion; //VERSION
1045                 content += " Console Commands to execute BBS application\n";
1046                 content += "# - ";
1047                 content += filename;
1048                 content += "\n";
1049                 content += "# ----------------------------------\n";
1050                 content += "\n";
1051                 content += "\n";
1052                 content += "# Command to execute bbi\n";
1053                 content += "bbi <bbs_path> ";
1054                 content += inputsInOneLineUnix;
1055
1056                 /* No gusto la idea al jefe pero por si acaso ...
1057                  * RaC 2012 2nd HackFest
1058                  content += "# For Windows (copy the following lines to a .bat file)\n";
1059                  content += "REM BBS application\n";
1060                  content += "REM Inputs:\n";
1061                  content += inputsInCommentsWin;
1062                  content += "REM To use previous inputs, put %$inputName% in the corresponding input of the execution bbi line\n";
1063                  content += "bbi applicationBBS.bbs ";
1064                  content += inputsInOneLineWin;
1065                  content += "\n";
1066                  content += "\n";
1067                  content += "# For Linux or Mac (copy the following lines to a .sh file)\n";
1068                  content += "#!/bin/bash\n";
1069                  content += "# BBS application\n";
1070                  content += "# Inputs:\n";
1071                  content += inputsInCommentsUnix;
1072                  content += "# To use previous inputs, put $inputName in the corresponding input of the execution bbi line\n";
1073                  content += "bbi applicationBBS.bbs ";
1074                  content += inputsInOneLineUnix;
1075                  content += "\n";
1076                 */
1077
1078                 file << content;
1079                 file.close();
1080         }
1081
1082
1083 }
1084
1085 //=========================================================================
1086
1087 void wxGUIEditorGraphicBBS::refreshGUIControls() 
1088 {
1089         std::string stundo;
1090         std::string stredo;
1091         //RaC2012 2ndHackFest Next line seems weird ... To keep in mind for other devels
1092         wxToolBar* toolbar = GetToolBar();
1093         if (_tabsMgr->isActualDiagramComplexBox()) 
1094         {
1095                 toolbar->ToggleTool(ID_BTNCOMPLEXBOX, true);
1096                 //toolbar->EnableTool(ID_ADDCOMPLEXBOXINPUT, true); RaC2012 2nd HackFest
1097                 toolbar->EnableTool(ID_ADDCOMPLEXBOXOUTPUT, true);
1098
1099                 GetMenuBar()->GetMenu(0)->Enable(ID_SAVE_AS_COMPLEXBOX, true);
1100                 GetMenuBar()->GetMenu(0)->Enable(ID_SAVE_AS_BBS, false);
1101                 GetMenuBar()->GetMenu(0)->Enable(ID_EXPORT_CONSOLEAPP, false);
1102         } else {
1103                 toolbar->ToggleTool(ID_BTNCOMPLEXBOX, false);
1104                 //toolbar->EnableTool(ID_ADDCOMPLEXBOXINPUT, false); RaC2012 2nd HackFest
1105                 toolbar->EnableTool(ID_ADDCOMPLEXBOXOUTPUT, false);
1106
1107                 GetMenuBar()->GetMenu(0)->Enable(ID_SAVE_AS_COMPLEXBOX, false);
1108                 GetMenuBar()->GetMenu(0)->Enable(ID_SAVE_AS_BBS, true);
1109                 GetMenuBar()->GetMenu(0)->Enable(ID_EXPORT_CONSOLEAPP, true);
1110         }
1111
1112         //RaC2012 2ndHackFest
1113         GetToolBar()->EnableTool(ID_EDITPROPERTIES,true);
1114
1115         GetToolBar()->EnableTool(ID_UNDO,_tabsMgr->getUndoState(stundo));
1116         GetToolBar()->SetToolShortHelp(ID_UNDO,crea::std2wx(stundo));
1117         GetToolBar()->EnableTool(ID_REDO,_tabsMgr->getRedoState(stredo));
1118         GetToolBar()->SetToolShortHelp(ID_REDO,crea::std2wx(stredo));
1119
1120         if (_tabsMgr->getNumActualSelectedObjects() > 0) {
1121                 GetMenuBar()->GetMenu(1)->Enable(ID_COPY_TO_COMPLEXDIAGRAM, true);
1122         } else {
1123                 ///TODO Fix the possibility to say from the SceneManager to the GUI to refresh the options
1124                 GetMenuBar()->GetMenu(1)->Enable(ID_COPY_TO_COMPLEXDIAGRAM, true);
1125         }
1126
1127 }
1128
1129 //=========================================================================
1130
1131 void wxGUIEditorGraphicBBS::OnDeleteAllBoxesActualDiagram(wxCommandEvent& event) 
1132 {
1133         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);
1134         if (dial->ShowModal() == wxID_YES)
1135         {
1136                 _tabsMgr->deleteAllBoxesActualDiagram();
1137         }
1138 }
1139
1140 //=========================================================================
1141
1142 void wxGUIEditorGraphicBBS::OnCenterViewActualDiagram(wxCommandEvent& event) 
1143 {
1144         _tabsMgr->centerViewActualDiagram();
1145 }
1146
1147 //=========================================================================
1148 void wxGUIEditorGraphicBBS::OpenDiagram(std::string filePathName, std::string fileName) 
1149 {
1150         ifstream inputStream;   
1151         inputStream.open(filePathName.c_str());
1152         assert(inputStream.good()); // fails
1153         
1154         if(_tabsMgr->FindTab(filePathName)!=-1) //RaC2012 avoid opening same diagram twice
1155         {
1156                 inputStream.close();
1157                 printf("RaC: Diagram already opened\n");
1158                 return;
1159         }
1160         _tabsMgr->addNewTab( crea::std2wx(fileName) );
1161         _tabsMgr->loadDiagram(inputStream, filePathName);
1162
1163         _tabsMgr->saveTempActualDiagram("load diagram");
1164         GetToolBar()->EnableTool(ID_UNDO, false);
1165         GetToolBar()->EnableTool(ID_UNDO, false);
1166         inputStream.close();
1167         refreshGUIControls();
1168 }
1169         
1170 //=========================================================================
1171
1172 void wxGUIEditorGraphicBBS::OnOpenDiagram(wxCommandEvent& event) 
1173 {
1174
1175 //EED 2017-09-16 Migration wxWidgets 2.8 to 3.0
1176 #if wxMAJOR_VERSION <= 2
1177         wxFileDialog * openFileDialog = new wxFileDialog(this, wxT("Open diagram"), wxEmptyString, wxT(""), wxT("*.bbg"), wxOPEN | wxFILE_MUST_EXIST);
1178 #else
1179         wxFileDialog * openFileDialog = new wxFileDialog(this, wxT("Open diagram"), wxEmptyString, wxT(""), wxT("*.bbg"), wxFD_OPEN | wxFD_FILE_MUST_EXIST);
1180 #endif
1181
1182         if (openFileDialog->ShowModal() == wxID_OK) 
1183         {
1184                 wxString filePath = openFileDialog->GetPath();
1185                 wxString fileName = openFileDialog->GetFilename();
1186                 OpenDiagram( crea::wx2std(filePath) , crea::wx2std(fileName) );                                 
1187         }
1188 }
1189
1190 //=========================================================================
1191 void wxGUIEditorGraphicBBS::OnClickBtnBox(wxCommandEvent& event) 
1192 {
1193         std::cout<<"wxGUIEditorGraphicBBS::OnClickBtnBox"<<std::endl;
1194         BlackBoxDescriptor *bbDes = _pkgBrowser->GetActualSelected();
1195         if (bbDes != NULL) {
1196                 std::string typeName = bbDes->GetTypeName();
1197                 std::string packageName = bbDes->GetPackage()->GetName();
1198                 wxGEditorTabPanel *pnl = this->_tabsMgr->getActualTabPanel();
1199                 if (pnl != NULL) {
1200                         wxVtkSceneManager *scn = pnl->getSceneManager();
1201                         scn->createGBlackBox(50, 50, packageName, typeName);
1202                         scn->refresh();
1203                 }
1204                 SaveTempActualDiagram("New Box");
1205                 // if pnl
1206         }// if bbDes
1207 }
1208
1209 //=========================================================================
1210 //2022-10-28
1211 void wxGUIEditorGraphicBBS::OnClickBtnSelectBoxes(wxCommandEvent& event)
1212 {
1213    std::string nameFilter = _pkgBrowser->GetNameFilter();
1214    _tabsMgr->SelectBoxWithPossibleName( nameFilter );
1215 }
1216
1217 //=========================================================================
1218
1219 void wxGUIEditorGraphicBBS::OnClickBtnExecutableBox(wxCommandEvent& event) 
1220 {
1221         //DFCH
1222         wxGEditorTabPanel *pnl = this->_tabsMgr->getActualTabPanel();
1223
1224         if (pnl != NULL) {
1225                 wxVtkSceneManager *scn = pnl->getSceneManager();
1226                 if( scn->MakeBoxExecutable() )
1227                         std::cout<<"DFCH: wxGUIEditorGraphicBBS::OnClickBtnExecutableBox...successful"<<std::endl;
1228                 else
1229                         std::cout<<"DFCH: wxGUIEditorGraphicBBS::OnClickBtnExecutableBox...Error!!"<<std::endl;
1230         }
1231         //DFCH
1232
1233 }
1234
1235 //=========================================================================
1236 void wxGUIEditorGraphicBBS::OnClickBtnComplexBox(wxCommandEvent& event) 
1237 {
1238         std::cout<<"wxGUIEditorGraphicBBS::OnClickBtnComplexBox"<<std::endl;
1239         wxToolBar* toolbar = GetToolBar();
1240         bool temp = toolbar->GetToolState(ID_BTNCOMPLEXBOX);
1241         if (temp) {
1242                 enableComplexBox();
1243         } else {
1244                 disableComplexBox();
1245         }
1246 }
1247
1248 //=========================================================================
1249 //EED01
1250 void wxGUIEditorGraphicBBS::OnAddComplexBoxInput(wxCommandEvent& event) 
1251 {
1252         wxTextEntryDialog *nameDialog = new wxTextEntryDialog(this,
1253                         wxT("Name of input port"));
1254         if (nameDialog->ShowModal() == wxID_OK) 
1255         {
1256                 wxString fileName = nameDialog->GetValue();
1257                 if (!fileName.IsEmpty()) 
1258                 {
1259                         std::string portName = (const char*) (fileName.mb_str());
1260                         if ( !boxNameExists(portName) )
1261                         {
1262                            _tabsMgr->addActualDiagramComplexInputPort(portName);
1263                         } else {
1264                            wxMessageDialog *dial = new wxMessageDialog(NULL,
1265                                        wxT("Impossible to create Box. The name already exists. Please provide another name"),
1266                                        wxT("Change name: name already exists"), wxOK | wxICON_EXCLAMATION | wxSTAY_ON_TOP);
1267                            dial->ShowModal();
1268                         }
1269                 } // if !fileName
1270         } // if namaDialog
1271 }
1272
1273 //=========================================================================
1274 void wxGUIEditorGraphicBBS::OnAddComplexBoxOutput(wxCommandEvent& event) 
1275 {
1276         wxTextEntryDialog *nameDialog = new wxTextEntryDialog(this,
1277                         wxT("Name of output port"));
1278         if (nameDialog->ShowModal() == wxID_OK) 
1279         {
1280                 wxString fileName = nameDialog->GetValue();
1281                 if (!fileName.IsEmpty()) 
1282                 {
1283                         std::string portName = (const char*) (fileName.mb_str());
1284                         if ( !boxNameExists(portName) )
1285                         {
1286                         _tabsMgr->addActualDiagramComplexOutputPort(portName);
1287                         } else {
1288                            wxMessageDialog *dial = new wxMessageDialog(NULL,
1289                                        wxT("Impossible to create Box. The name already exists. Please provide another name"),
1290                                        wxT("Change name: name already exists"), wxOK | wxICON_EXCLAMATION | wxSTAY_ON_TOP);
1291                            dial->ShowModal();
1292                         }
1293
1294                 } // if !filename
1295         } // namaDialog
1296 }
1297
1298 //=========================================================================
1299 void wxGUIEditorGraphicBBS::OnCopySelectedToComplexDiagram(
1300                 wxCommandEvent& event) 
1301 {
1302         _tabsMgr->copySelectedBBoxesToComplexDiagram();
1303 }
1304
1305 //=========================================================================
1306 void wxGUIEditorGraphicBBS::OnHelpBBeditor(wxCommandEvent& event) 
1307 {
1308         printf("wxGUIEditorGraphicBBS::OnHelpBBeditor ....not implemented..\n");
1309 }
1310
1311 //=========================================================================
1312 void wxGUIEditorGraphicBBS::OnCreatePackage(wxCommandEvent& event) 
1313 {
1314         bbtkSystemTools::CreatePackage();
1315 }
1316
1317 //=========================================================================
1318 void wxGUIEditorGraphicBBS::OnCreateBlackBox(wxCommandEvent& event) 
1319 {
1320         bbtkSystemTools::CreateBlackBox();
1321 }
1322         
1323 //=========================================================================
1324 void wxGUIEditorGraphicBBS::OnPlugPackage(wxCommandEvent& event) 
1325 {
1326         //DFGO2012 Plug Package functionnalities
1327         long style = wxDD_DEFAULT_STYLE | wxDD_DIR_MUST_EXIST;
1328         wxDirDialog* FD =
1329           new wxDirDialog( 0,
1330                            _T("Select package directory"),
1331                            _T(""),
1332                            style);
1333         long userResponse;
1334         do
1335         {
1336                 userResponse = FD->ShowModal();
1337                 if(userResponse==wxID_OK)
1338                 {
1339                         std::string path = wx2std (FD->GetPath()) ;
1340                         #ifdef WIN32
1341                         std::string fname = path + "\\bbtkPackage";
1342                         #else
1343                         std::string fname = path + "/bbtkPackage";
1344                         #endif
1345                         
1346                         std::cout << "Path chosen = \"" << FD->GetPath() << "\"" << std::endl;
1347                         if ( Utilities::FileExists( fname ) )
1348                         {
1349                                 std::ifstream f;
1350                                 f.open(fname.c_str());
1351                                 std::string pname;
1352                                 f >> pname;
1353                                 while(pname[0] == '#')
1354                                 {
1355                                         getline(f, pname, '\n');
1356                                         f >> pname;
1357                                 }
1358                                 f.close();
1359
1360                                 bbtk::ConfigurationFile::GetInstance().AddPackagePathsAndWrite( path );
1361
1362                                 DoRegeneratePackageDoc(pname);
1363                                 DoRegenerateBoxesLists();
1364
1365                                 _pkgBrowser->RebuildList();
1366
1367                                 wxMessageBox(_T("Package successfully plugged. Please restart bbEditor to see the new package in the package browser."),_T("Plug package"),wxOK | wxICON_INFORMATION);
1368                                 userResponse = wxID_CANCEL;
1369                         }
1370                         else
1371                         {
1372                                 std::string err = "The directory \"" + path + "\" does not contain a 'bbtkPackage' file.";
1373                                 #ifndef WIN32
1374                                         #ifndef MACOSX
1375                                                 err += "\nNote: If you are on Linux please select the folder and click \"Open\", don't enter in it.";
1376                                         #endif
1377                                 #endif
1378
1379                                 wxMessageBox(crea::std2wx(err), _T("Plug package"),wxOK | wxICON_ERROR);
1380                                 // THE FOLLOWING LINE GIVES ERRORS BECAUSE IT IS NECESSARY TO USE std2wx
1381                                 //wxMessageBox( _T( err) , _T("Plug package"),wxOK | wxICON_ERROR);
1382                         }
1383                 }
1384         }while(userResponse != wxID_CANCEL);
1385
1386 }
1387         
1388 //=========================================================================
1389 void wxGUIEditorGraphicBBS::OnEditConfig(wxCommandEvent& event) 
1390 {
1391         std::string commandStr;
1392             std::string configFile = ConfigurationFile::GetInstance().Get_config_xml_full_path();
1393         #ifdef WIN32
1394                 commandStr = "notepad.exe ";
1395         #else
1396                 commandStr = "gedit ";
1397         #endif
1398                 commandStr = commandStr + configFile;
1399                 std::cout << "system: " << commandStr << std::endl;
1400                 system ( commandStr.c_str() );
1401 }
1402         
1403 //=========================================================================
1404 void wxGUIEditorGraphicBBS::OnShowHTMLDoc(wxCommandEvent& event) 
1405 {
1406         // JGRR & CM WH
1407         if (_helpHtmlBrowser != NULL){
1408              _frameAUIMgr->DetachPane(_helpHtmlBrowser);
1409             _helpHtmlBrowser->Destroy();   
1410         }
1411         initHelpHTMLBrowser();
1412         _frameAUIMgr->AddPane(_helpHtmlBrowser, wxAuiPaneInfo().Right().MinSize(200, 200));
1413         _frameAUIMgr->Update();
1414         refreshGUIControls();
1415         
1416         // EO JGRR    & CM WH       
1417 }
1418         
1419 //=========================================================================
1420 void wxGUIEditorGraphicBBS::OnCreateIndex(wxCommandEvent& event) 
1421 {
1422         printf("EED wxGUIEditorGraphicBBS::OnCreateIndex ... not implemented ..\n");
1423 }
1424
1425         
1426 //=========================================================================
1427 void wxGUIEditorGraphicBBS::OnEditComplexBoxScript(wxCommandEvent& event)
1428 {
1429         BlackBoxDescriptor *bbDes = _pkgBrowser->GetActualSelected();
1430         if (bbDes != NULL) 
1431         {
1432                 std::string packageName = bbDes->GetPackage()->GetName();
1433                 std::string typeName = bbDes->GetTypeName();
1434                 if (!TryToOpenScriptComplexBox(packageName ,typeName))
1435                 {
1436                         wxMessageDialog windowMessage1(NULL,_T("This is not a ComplexBox script."), _T("Alert !"), wxOK);
1437                         windowMessage1.ShowModal();
1438                 }
1439         }// if bbDes
1440 }
1441
1442 //=========================================================================
1443 void wxGUIEditorGraphicBBS::OnExit(wxCommandEvent& event) 
1444 {
1445         Close(true);
1446 }
1447
1448 Factory::Pointer wxGUIEditorGraphicBBS::GetBBTKFactory()
1449 {
1450         if (_pkgBrowser==NULL) 
1451         {
1452                 printf ("EED ERROR! wxGUIEditorGraphicBBS::GetBBTKFactory _pkgBrowser = NULL\n");
1453         }
1454         return _pkgBrowser->GetFactory();
1455 }
1456
1457 //=========================================================================
1458 void wxGUIEditorGraphicBBS::enableComplexBox() 
1459 {
1460         _tabsMgr->setActualDiagramComplexBox(true);
1461         refreshGUIControls();
1462 }
1463
1464 //=========================================================================
1465
1466 void wxGUIEditorGraphicBBS::disableComplexBox() 
1467 {
1468         _tabsMgr->setActualDiagramComplexBox(false);
1469         refreshGUIControls();
1470 }
1471
1472 //=========================================================================
1473 void wxGUIEditorGraphicBBS::setCurrentDiagramDescription(std::string description)
1474 {
1475         _tabsMgr->SetDescription(description);
1476 }
1477
1478 //=========================================================================
1479 void wxGUIEditorGraphicBBS::setCurrentDiagramAuthor(std::string author)
1480 {
1481         _tabsMgr->SetAuthor(author);
1482 }
1483
1484 //=========================================================================
1485 void wxGUIEditorGraphicBBS::setCurrentDiagramCategory(std::string category)
1486 {
1487         _tabsMgr->SetCategory(category);
1488 }
1489
1490 //=========================================================================
1491 void wxGUIEditorGraphicBBS::setCurrentDiagramMessageKind(std::string kind){
1492         _tabsMgr->SetMessageKind(kind); 
1493 }
1494
1495 //=========================================================================
1496 void wxGUIEditorGraphicBBS::setCurrentDiagramMessageLevel(std::string level){
1497         _tabsMgr->SetMessageLevel(level);       
1498 }
1499
1500 //=========================================================================
1501 std::string wxGUIEditorGraphicBBS::getCurrentDiagramDescription()
1502 {
1503         return _tabsMgr->GetDescription();
1504 }
1505
1506 //=========================================================================
1507 std::string wxGUIEditorGraphicBBS::getCurrentDiagramAuthor()
1508 {
1509         return _tabsMgr->GetAuthor();
1510 }
1511
1512 //=========================================================================
1513 std::string wxGUIEditorGraphicBBS::getCurrentDiagramCategory()
1514 {
1515         return _tabsMgr->GetCategory();
1516 }
1517
1518 //=========================================================================
1519 std::string wxGUIEditorGraphicBBS::getCurrentDiagramMessageKind(){
1520         return _tabsMgr->GetMessageKind();
1521 }
1522
1523 //=========================================================================
1524 std::string wxGUIEditorGraphicBBS::getCurrentDiagramMessageLevel(){
1525         return _tabsMgr->GetMessageLevel();
1526 }
1527
1528 //=========================================================================
1529 bool wxGUIEditorGraphicBBS::isCurrentDiagramComplexBox()
1530 {
1531         return _tabsMgr->isActualDiagramComplexBox();
1532 }
1533
1534
1535 //=========================================================================
1536 void wxGUIEditorGraphicBBS::OpenScript(std::string filePathNameBBS ,std::string boxType)
1537 {       
1538         std::string fileName                                                    = boxType+".bbg";
1539         std::string filePathNameBBG                                             = filePathNameBBS;
1540         filePathNameBBG[ filePathNameBBG.length()-1 ]   = 'g';
1541         
1542         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);
1543         windowMessage1.ShowModal();
1544         
1545         if ( Utilities::FileExists( filePathNameBBG ) )
1546         {
1547                 OpenDiagram( filePathNameBBG , fileName );     
1548         } else {
1549                 if ( Utilities::FileExists( filePathNameBBS ) )
1550                 {
1551                         OpenBBS( filePathNameBBS , fileName );     
1552                 } else {
1553                         wxMessageDialog windowMessage1(NULL,_T("..ERROR.. loading script bbg/bbs."), _T("Alert !"), wxOK);
1554                         windowMessage1.ShowModal();
1555                 } // FileExists BBS
1556         } // FieExists BBG
1557 } //OpenScript
1558         
1559         
1560         
1561 //=========================================================================
1562 bool wxGUIEditorGraphicBBS::TryToOpenScriptApplication(std::string packageName ,std::string boxType)
1563 {       
1564         return TryToOpenScript(packageName ,boxType, true, false);
1565 }               
1566
1567 //=========================================================================
1568 bool wxGUIEditorGraphicBBS::TryToOpenScriptComplexBox(std::string packageName ,std::string boxType)
1569 {       
1570         return TryToOpenScript(packageName ,boxType, false, true);
1571 }               
1572         
1573         
1574 //=========================================================================
1575 bool wxGUIEditorGraphicBBS::TryToOpenScript(std::string packageName ,std::string boxType,bool scriptApplication, bool scriptComplexBox)
1576 {       
1577         Package::Pointer k;
1578         std::map< std::string, BlackBoxDescriptor::Pointer> mapDesc;
1579         BlackBoxDescriptor::Pointer descriptor;
1580         k                       = GetBBTKFactory()->GetPackage(packageName);
1581         mapDesc         = k->GetDescriptorMap();
1582         descriptor      = mapDesc[boxType];
1583
1584         bool result=false;
1585     descriptor->IsTypeOfScript_Application();   
1586         if (descriptor!=NULL)
1587         {
1588                 if ( 
1589                         ((descriptor->IsTypeOfScript_Application()==true) && (scriptApplication==true))
1590                         ||
1591                         ((descriptor->IsTypeOfScript_ComplexBox()==true) && (scriptComplexBox==true))           
1592                         )
1593                 {
1594                         result=true;
1595                         OpenScript(descriptor->GetScriptFileName(),boxType);
1596                 } // if descriptor Type
1597         } else {
1598                 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() );
1599         }  // if descriptor NULL
1600         
1601         return result;
1602 }       
1603         
1604 } // EO namespace bbtk
1605
1606 // EOF
1607