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