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