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