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