]> Creatis software - bbtkGEditor.git/blob - lib/EditorGraphicBBS/bbsWxGUIEditorGraphic/bbtkwxGUIEditorGraphicBBS.cxx
Display of the tree obtained in the information dialog window in BBEditor. 12/05...
[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 //EED           ComplexBlackBoxDescriptor::Pointer descriptor;
463                 BlackBoxDescriptor::Pointer descriptor;
464
465                 std::map< std::string, BlackBoxDescriptor::Pointer> mapDesc;
466                 k                       = _pkgBrowser->GetFactory()->GetPackage(packageName);
467                 mapDesc         = k->GetDescriptorMap();                
468                 descriptor      = mapDesc[boxName];
469                 std::vector<std::string> temp;
470                 descriptor->GetBoxesInside(tree,temp,1);
471
472
473
474 /*CFT
475                 for(int i = 0 ; i < temp.size() ; i++){
476                                         std::cout<< "  "<< temp[i] << std::endl;
477                 }       
478
479
480                 if(temp.size()>=1){
481                                 std::cout<< "CAJAS # " << (temp.size()- 3) << std::endl;                        
482                                 for(int i = 0 ; i < temp.size()-1 ; i++){
483                                         if(i<3){std::cout<< "  "<< temp[i] << std::endl;}
484                                         else{std::cout<< i+1 << "  "<< temp[i] << " " <<temp[i+1] << std::endl;}
485                                 }       
486                         }               
487                 if (temp.size()==0){
488                                 std::cout<< " Not Complex " << std::endl;
489                         }
490 */
491                 /*
492                 Package::Pointer k;
493                 BlackBoxDescriptor::Pointer descriptor;
494                 std::map< std::string, BlackBoxDescriptor::Pointer> mapDesc;
495                 k                       = _pkgBrowser->GetFactory()->GetPackage(packageName);
496                 std::vector<std::string> temp;
497                 _pkgBrowser->GetFactory()->GetPackagesList(temp);
498                 for(int ii = 0 ; ii < temp.size() ; ii++)
499                 {
500                                 std::cout << " packs "<< temp[ii]<< std::endl;
501                 }
502                 mapDesc         = k->GetDescriptorMap();                
503                 descriptor      = mapDesc[boxName];
504                 */
505                 _pkgBrowser->WxGUIBlackBoxListUserOnSelected(descriptor.get());
506         }
507 }
508
509 //=========================================================================
510
511 void wxGUIEditorGraphicBBS::editBlackBox(GBlackBoxModel *bbmodel) {
512         wxBlackBoxEditionDialog* dialog =
513                         new wxBlackBoxEditionDialog(this, bbmodel);
514         dialog->Show();
515 }
516
517 //=========================================================================
518
519 bool wxGUIEditorGraphicBBS::boxNameExists(std::string boxname) {
520  
521         return this->_tabsMgr->getActualTabPanel()->getSceneManager()->boxExist(boxname);
522 }
523
524 //=========================================================================
525
526 void wxGUIEditorGraphicBBS::updateStatusBar(std::string textStatus) {
527         SetStatusText(crea::std2wx(textStatus));
528 }
529
530 //=========================================================================
531
532 void wxGUIEditorGraphicBBS::executeScript(std::string script) {
533         std::string separator =
534                         ConfigurationFile::GetInstance().Get_file_separator();
535         std::string dir = ConfigurationFile::GetInstance().Get_default_temp_dir();
536         std::string filename = dir + separator + "tmp_bbtk.bbs";
537
538         ofstream tempFile;
539         tempFile.open(filename.c_str());
540         tempFile << script;
541         tempFile.close();
542
543         std::string command = "";
544
545 #ifdef WIN32
546         command += "start /b ";
547 #endif
548
549         //              command += "\""+ crea::System::GetExecutablePath();
550         //#ifdef MACOSX
551         //              command += separator + "../../../bbi.app/Contents/MacOS";
552         //#endif
553
554         command += "bbi ";
555         command += "\"" + filename + "\"";
556
557 #ifndef WIN32
558         command += " & ";
559 #endif
560
561         printf("RaC wxGUIEditorGraphicBBS::executeScript %s \n", command.c_str());
562         system(command.c_str());
563 }
564
565 //=========================================================================
566 std::string wxGUIEditorGraphicBBS::CheckExtension(std::string filename, std::string extension) {
567         if(filename.size() > extension.size() ){
568                 if( (filename.compare(filename.size()-extension.size(), extension.size(),extension)) !=0 ){
569                         filename.append(extension);
570                 }
571         }else{
572                 filename.append(extension);
573         }
574         return filename;
575 }
576 //=========================================================================
577 // EVENT HANDLERS
578 //=========================================================================
579
580 void wxGUIEditorGraphicBBS::OnCreateNewTab(wxCommandEvent& event) {
581         _tabsMgr->addNewTab();
582         refreshGUIControls();
583 }
584
585 void wxGUIEditorGraphicBBS::OnUndo(wxCommandEvent& event) {
586         unsigned short disable;
587         std::string stundo;
588         std::string stredo;
589
590         _tabsMgr->loadTempDiagram(0);
591         disable = _tabsMgr->getUndoState(stundo);
592         if(disable == 0)
593         {
594                 std::string name = _tabsMgr->GetNameTabPanel();
595                 if(name[name.length() - 1] == '*')
596                 {
597                         name =name.substr(0,name.length()-1);
598                 }
599                 _tabsMgr->SetNameTabPanel(wxString (name.c_str(), wxConvUTF8));
600         }
601
602         GetToolBar()->EnableTool(ID_UNDO,disable);
603         GetToolBar()->SetToolShortHelp(ID_UNDO,crea::std2wx(stundo));
604         GetToolBar()->EnableTool(ID_REDO,_tabsMgr->getRedoState(stredo));
605         GetToolBar()->SetToolShortHelp(ID_REDO,crea::std2wx(stredo));
606         refreshGUIControls();
607 }
608
609 //=========================================================================
610
611 void wxGUIEditorGraphicBBS::OnRedo(wxCommandEvent& event) {
612         unsigned short disable;
613         std::string stundo;
614         std::string stredo;
615
616         _tabsMgr->loadTempDiagram(1);
617         std::string name = _tabsMgr->GetNameTabPanel();
618         if(name[name.length() - 1] != '*')
619                 name +="*";
620         _tabsMgr->SetNameTabPanel(wxString (name.c_str(), wxConvUTF8));
621         GetToolBar()->EnableTool(ID_UNDO,_tabsMgr->getUndoState(stundo));
622         GetToolBar()->SetToolShortHelp(ID_UNDO,crea::std2wx(stundo));
623         GetToolBar()->EnableTool(ID_REDO,_tabsMgr->getRedoState(stredo));
624         GetToolBar()->SetToolShortHelp(ID_REDO,crea::std2wx(stredo));
625         refreshGUIControls();
626 }
627
628 void wxGUIEditorGraphicBBS::OnChangeName(wxCommandEvent& event){
629 }
630
631 //=========================================================================
632
633 void wxGUIEditorGraphicBBS::OnEditDiagramProperties(wxCommandEvent& event)
634 {
635         wxDiagramPropertiesEditionDialog* dialog =
636                                 new wxDiagramPropertiesEditionDialog(this, tree);
637         dialog->Show();
638 }
639
640 //=========================================================================
641
642 void wxGUIEditorGraphicBBS::OnExecuteActualDiagram(wxCommandEvent& event) {
643         std::string script1 = _tabsMgr->getActualDiagramBBS(true);
644         cout << endl << "RaC wxGUIEditorGraphicBBS::executeActualDiagram SCRIPT"
645                         << endl << endl;
646         cout << script1 << endl;
647
648         std::string script2 = _tabsMgr->getActualDiagramBBS(false);
649         executeScript(script2);
650 }
651
652         
653 //=========================================================================
654 void wxGUIEditorGraphicBBS::OpenBBS(std::string filePathName, std::string fileName) 
655 {
656         _tabsMgr->addNewTab( crea::std2wx(fileName) );
657         bbtk::InterpreterBBS::Pointer I = bbtk::InterpreterBBS::New( this->_tabsMgr->getActualTabPanel()->getSceneManager(), _pkgBrowser->GetFactory());
658         // We tell the interpreter to throw exceptions on error
659         I->SetThrow(true);
660         // Interpret the file supposed to define a box called 'Processing'
661         I->InterpretFile( filePathName );
662         refreshGUIControls();
663 }
664         
665 //=========================================================================
666 // HANDLERS
667 //=========================================================================
668 void wxGUIEditorGraphicBBS::OnOpenBBS(wxCommandEvent& event) 
669 {
670         wxFileDialog * openFileDialog = new wxFileDialog(this, wxT("Open BBS"), wxEmptyString, wxT("NewBBS"), wxT("*.bbs"), wxOPEN);
671
672         if (openFileDialog->ShowModal() == wxID_OK) 
673         {
674                 OpenBBS( crea::wx2std(openFileDialog->GetPath()) , crea::wx2std(openFileDialog->GetFilename())  );
675         }
676         
677 /*EED Borrame   
678         if (openFileDialog->ShowModal() == wxID_OK) 
679         {
680                 wxString fileName = openFileDialog->GetPath();
681                 _tabsMgr->addNewTab(openFileDialog->GetFilename());
682                 bbtk::InterpreterBBS::Pointer I = bbtk::InterpreterBBS::New( this->_tabsMgr->getActualTabPanel()->getSceneManager(), _pkgBrowser->GetFactory());
683                 // We tell the interpreter to throw exceptions on error
684                 I->SetThrow(true);
685                 // Interpret the file supposed to define a box called 'Processing'
686                 I->InterpretFile((const char*) (fileName.mb_str()));
687         }
688         refreshGUIControls();
689 */ 
690 }
691
692 //=========================================================================
693 void wxGUIEditorGraphicBBS::SaveActualBBS(std::string filename) {
694         ofstream file;
695
696         //EED           file.open(fileName.c_str());
697         file.open(filename.c_str());
698         std::string content = "";
699         // writing file header
700         content += "# ----------------------------------\n";
701         content += "# - BBTKGEditor v ";
702         content += _currentBBGversion; //VERSION
703         content += " BBS BlackBox Script\n";
704         content += "# - ";
705         content += filename;
706         content += "\n";
707         content += "# ----------------------------------\n";
708         content += "\n";
709         content += _tabsMgr->getActualDiagramBBS();
710         file << content;
711         file.close();
712 }
713
714 void wxGUIEditorGraphicBBS::OnSaveActualBBS(wxCommandEvent& event) {
715         wxFileDialog * saveFileDialog = new wxFileDialog(this,
716                         wxT("Save  actual BBS"), wxEmptyString, wxT("NewBBS"),
717                         wxT("*.bbs"), wxSAVE | wxOVERWRITE_PROMPT);
718         if (saveFileDialog->ShowModal() == wxID_OK) {
719                 wxString fileName = saveFileDialog->GetPath();
720                 std::string filename = (const char*) (fileName.mb_str());
721                 filename=CheckExtension (filename, ".bbs");
722                 SaveActualBBS(filename);
723         }
724
725 }
726
727 void wxGUIEditorGraphicBBS::AskComplexBoxConfiguration() {
728         std::string cbName = _tabsMgr->GetCbName();
729         std::string paName = _tabsMgr->GetCbPackageName();
730
731         wxTextEntryDialog *cbNameDialog = new wxTextEntryDialog(this,
732                         wxT("Complex Box name"));
733         wxTextEntryDialog *paNameDialog = new wxTextEntryDialog(this,
734                         wxT("Package name"));
735
736         cbNameDialog->SetValue(wxString(cbName.c_str(), wxConvUTF8));
737         paNameDialog->SetValue(wxString(paName.c_str(), wxConvUTF8));
738
739         if (cbNameDialog->ShowModal() == wxID_OK) {
740                 wxString complexboxname = cbNameDialog->GetValue();
741                 cbName = (const char*) (complexboxname.mb_str());
742         }
743
744         if (paNameDialog->ShowModal() == wxID_OK) {
745                 wxString packagename = paNameDialog->GetValue();
746                 paName = (const char*) (packagename.mb_str());
747         }
748
749         _tabsMgr->SetCbName(cbName);
750         _tabsMgr->SetCbPackageName(paName);
751 }
752
753 //=========================================================================
754
755 void wxGUIEditorGraphicBBS::SaveActualComplexBox(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 += " BBS BlackBox Script (Complex Box)\n";
766         content += "# - ";
767         content += filename;
768         content += "\n";
769         content += "# ----------------------------------\n";
770         content += "\n";
771         content += _tabsMgr->getActualComplexBoxBBS();
772         file << content;
773         file.close();
774 }
775
776 //=========================================================================
777
778 void wxGUIEditorGraphicBBS::OnSaveActualComplexBox(wxCommandEvent& event) {
779         wxFileDialog * saveFileDialog = new wxFileDialog(this,
780                         wxT("Save Complex Box BBS"), wxEmptyString,
781                         _T("ComplexBoxName"), wxT("*.bbs"), wxSAVE
782                                         | wxOVERWRITE_PROMPT);
783         if (saveFileDialog->ShowModal() == wxID_OK) {
784                 wxString fileName = saveFileDialog->GetPath();
785                 std::string filename = (const char*) (fileName.mb_str());
786                 filename=CheckExtension (filename, ".bbs");
787                 SaveActualComplexBox(filename);
788         }
789 }
790
791 //=========================================================================
792 void wxGUIEditorGraphicBBS::SaveActualDiagram(std::string filename) {
793         ofstream file;
794         file.open(filename.c_str());
795
796         std::string content = "";
797
798         // writing file header
799         content += "# ----------------------------------\n";
800         content += "# - BBTKGEditor v ";
801         content += _currentBBGversion; //VERSION
802         content += " BBG BlackBox Diagram file\n";
803         content += "# - ";
804
805         content += filename;
806
807         content += "\n";
808         content += "# ----------------------------------\n";
809         content += "\n";
810         content += "APP_START\n";
811         _tabsMgr->saveActualDiagram(content, filename); //DFCH
812         content += "APP_END\n";
813         file << content;
814         file.close();
815 }
816
817 //=========================================================================
818 void wxGUIEditorGraphicBBS::SaveTempActualDiagram(const std::string &action) 
819 {
820         std::string stundo;
821         std::string stredo;
822         std::string name = _tabsMgr->GetNameTabPanel();
823         if(name[name.length() - 1] != '*')
824                 name +="*";
825         _tabsMgr->SetNameTabPanel(wxString (name.c_str(), wxConvUTF8));
826         _tabsMgr->saveTempActualDiagram(action);
827         GetToolBar()->EnableTool(ID_UNDO,_tabsMgr->getUndoState(stundo));
828         GetToolBar()->SetToolShortHelp(ID_UNDO,crea::std2wx(stundo));
829         GetToolBar()->EnableTool(ID_REDO,_tabsMgr->getRedoState(stredo));
830         GetToolBar()->SetToolShortHelp(ID_REDO,crea::std2wx(stredo));
831 }
832
833 //=========================================================================
834
835 //The following method allows to save the current diagram asking the filename
836 //DFCH
837 void wxGUIEditorGraphicBBS::SaveCurrentDiagramAs() {
838         wxFileDialog * saveFileDialog = new wxFileDialog(this,
839                         wxT("Save current diagram"), wxEmptyString, wxT("NewDiagram"),
840                         wxT("*.bbg"), wxSAVE | wxOVERWRITE_PROMPT);
841         if (saveFileDialog->ShowModal() == wxID_OK) {
842                 //_tabsMgr->SetNameTabPanel(saveFileDialog->GetFilename());
843                 wxString pathfileName = saveFileDialog->GetPath();
844                 std::string pathfilename = (const char*) (pathfileName.mb_str());
845                 pathfilename=CheckExtension (pathfilename, ".bbg");
846
847                 //modify the tab name accordingly
848                 wxString fileName = saveFileDialog->GetFilename();
849                 std::string filename = (const char*) (fileName.mb_str());
850                 filename=CheckExtension (filename, ".bbg");
851                 _tabsMgr->SetNameTabPanel( wxString (filename.c_str(), wxConvUTF8) );
852
853                 std::string pathfilenamebbs = pathfilename;
854                 pathfilenamebbs[pathfilenamebbs.length() - 1] = 's';
855                 if (_tabsMgr->isActualDiagramComplexBox() == false) {
856                         SaveActualDiagram(pathfilename);
857                         SaveActualBBS(pathfilenamebbs);
858                 } else {
859                         AskComplexBoxConfiguration();
860                         SaveActualDiagram(pathfilename);
861                         SaveActualComplexBox(pathfilenamebbs);
862                 } //if isActualDiagramComplexBox
863         } // if saveFileDialog
864 }
865 //=========================================================================
866 //DFCH
867 void wxGUIEditorGraphicBBS::OnSaveActualDiagram(wxCommandEvent& event) {
868         std::string pathfilename = _tabsMgr->GetCurrentTabPanelPath();
869         if (pathfilename.empty()) {
870                 SaveCurrentDiagramAs();
871         } else {
872                 std::string pathfilenamebbs = pathfilename;
873                 pathfilenamebbs[pathfilenamebbs.length() - 1] = 's';
874                 
875                 if (_tabsMgr->isActualDiagramComplexBox() == false) {
876                         std::string name = _tabsMgr->GetNameTabPanel();
877                         if(name[name.length() - 1] == '*')
878                         {
879                                 name =name.substr(0,name.length()-1);
880                         }
881                         _tabsMgr->SetNameTabPanel(wxString (name.c_str(), wxConvUTF8));
882                         SaveActualDiagram(pathfilename);
883                         SaveActualBBS(pathfilenamebbs);
884                 } else {
885                         AskComplexBoxConfiguration();
886                         SaveActualDiagram(pathfilename);
887                         SaveActualComplexBox(pathfilenamebbs);
888                 } //if isActualDiagramComplexBox
889         }
890 }
891 //=========================================================================
892 //DFCH
893 void wxGUIEditorGraphicBBS::OnSaveAsActualDiagram(wxCommandEvent& event) {
894         SaveCurrentDiagramAs();
895 }
896
897 //=========================================================================
898 void wxGUIEditorGraphicBBS::OnExportConsoleExecCommand(wxCommandEvent& event)
899 {
900         wxFileDialog * saveFileDialog = new wxFileDialog(this,
901                         wxT("Export console command"), wxEmptyString, wxT("ConsoleApp.txt"),
902                         wxT("*.txt;*.bbs;*.bbg;*.sh;*.bat"), wxSAVE | wxOVERWRITE_PROMPT);
903
904         if (saveFileDialog->ShowModal() == wxID_OK)
905         {
906                 wxString fileName = saveFileDialog->GetPath();
907                 std::string filename = (const char*) (fileName.mb_str());
908                 filename=CheckExtension (filename, ".txt");
909
910                 ofstream file;
911                 file.open(filename.c_str());
912
913                 std::vector<std::string> extInputs = _tabsMgr->getActualTabPanel()->getSceneManager()->GetExternalInputsNames();
914
915                 //TODO PUT IN A METHOD OF A FILES AND TEXT MANAGER CLASS !!!
916                 //std::string inputsInCommentsWin="";
917                 //std::string inputsInCommentsUnix="";
918                 //std::string inputsInOneLineWin="";
919                 std::string inputsInOneLineUnix="";
920                 for (unsigned int i = 0; i < extInputs.size(); ++i)
921                 {
922                         /* No gusto la idea al jefe pero por si acaso ...
923                         * RaC 2012 2nd HackFest
924                         *
925                         inputsInCommentsWin+="REM ";
926                         inputsInCommentsWin+=extInputs[i];
927                         inputsInCommentsWin+="=\"value\"\n";
928                         inputsInCommentsUnix+="# ";
929                         inputsInCommentsUnix+=extInputs[i];
930                         inputsInCommentsUnix+="=\"value\"\n";
931
932                         char buffer [50];
933                         sprintf (buffer, "%d", (i+1));
934                         inputsInOneLineWin+=extInputs[i];
935                         inputsInOneLineWin+="=\"%";
936                         inputsInOneLineWin+=buffer;
937                         inputsInOneLineWin+="\" ";
938                         */
939                         inputsInOneLineUnix+=extInputs[i];
940                         inputsInOneLineUnix+="=\"<value>\" ";
941
942                 }
943
944
945                 std::string content = "";
946                 // writing file header
947                 content += "# ----------------------------------\n";
948                 content += "# - BBTKGEditor v ";
949                 content += _currentBBGversion; //VERSION
950                 content += " Console Commands to execute BBS application\n";
951                 content += "# - ";
952                 content += filename;
953                 content += "\n";
954                 content += "# ----------------------------------\n";
955                 content += "\n";
956                 content += "\n";
957                 content += "# Command to execute bbi\n";
958                 content += "bbi <bbs_path> ";
959                 content += inputsInOneLineUnix;
960
961                 /* No gusto la idea al jefe pero por si acaso ...
962                  * RaC 2012 2nd HackFest
963                  content += "# For Windows (copy the following lines to a .bat file)\n";
964                  content += "REM BBS application\n";
965                  content += "REM Inputs:\n";
966                  content += inputsInCommentsWin;
967                  content += "REM To use previous inputs, put %$inputName% in the corresponding input of the execution bbi line\n";
968                  content += "bbi applicationBBS.bbs ";
969                  content += inputsInOneLineWin;
970                  content += "\n";
971                  content += "\n";
972                  content += "# For Linux or Mac (copy the following lines to a .sh file)\n";
973                  content += "#!/bin/bash\n";
974                  content += "# BBS application\n";
975                  content += "# Inputs:\n";
976                  content += inputsInCommentsUnix;
977                  content += "# To use previous inputs, put $inputName in the corresponding input of the execution bbi line\n";
978                  content += "bbi applicationBBS.bbs ";
979                  content += inputsInOneLineUnix;
980                  content += "\n";
981                 */
982
983                 file << content;
984                 file.close();
985         }
986
987
988 }
989
990 //=========================================================================
991
992 void wxGUIEditorGraphicBBS::refreshGUIControls() {
993         std::string stundo;
994         std::string stredo;
995         //RaC2012 2ndHackFest Next line seems weird ... To keep in mind for other devels
996         wxToolBar* toolbar = GetToolBar();
997         if (_tabsMgr->isActualDiagramComplexBox()) {
998                 toolbar->ToggleTool(ID_BTNCOMPLEXBOX, true);
999                 //toolbar->EnableTool(ID_ADDCOMPLEXBOXINPUT, true); RaC2012 2nd HackFest
1000                 toolbar->EnableTool(ID_ADDCOMPLEXBOXOUTPUT, true);
1001
1002                 GetMenuBar()->GetMenu(0)->Enable(ID_SAVE_AS_COMPLEXBOX, true);
1003                 GetMenuBar()->GetMenu(0)->Enable(ID_SAVE_AS_BBS, false);
1004                 GetMenuBar()->GetMenu(0)->Enable(ID_EXPORT_CONSOLEAPP, false);
1005         } else {
1006                 toolbar->ToggleTool(ID_BTNCOMPLEXBOX, false);
1007                 //toolbar->EnableTool(ID_ADDCOMPLEXBOXINPUT, false); RaC2012 2nd HackFest
1008                 toolbar->EnableTool(ID_ADDCOMPLEXBOXOUTPUT, false);
1009
1010                 GetMenuBar()->GetMenu(0)->Enable(ID_SAVE_AS_COMPLEXBOX, false);
1011                 GetMenuBar()->GetMenu(0)->Enable(ID_SAVE_AS_BBS, true);
1012                 GetMenuBar()->GetMenu(0)->Enable(ID_EXPORT_CONSOLEAPP, true);
1013         }
1014
1015         //RaC2012 2ndHackFest
1016         GetToolBar()->EnableTool(ID_EDITPROPERTIES,true);
1017
1018         GetToolBar()->EnableTool(ID_UNDO,_tabsMgr->getUndoState(stundo));
1019         GetToolBar()->SetToolShortHelp(ID_UNDO,crea::std2wx(stundo));
1020         GetToolBar()->EnableTool(ID_REDO,_tabsMgr->getRedoState(stredo));
1021         GetToolBar()->SetToolShortHelp(ID_REDO,crea::std2wx(stredo));
1022
1023         if (_tabsMgr->getNumActualSelectedObjects() > 0) {
1024                 GetMenuBar()->GetMenu(1)->Enable(ID_COPY_TO_COMPLEXDIAGRAM, true);
1025         } else {
1026                 ///TODO Fix the possibility to say from the SceneManager to the GUI to refresh the options
1027                 GetMenuBar()->GetMenu(1)->Enable(ID_COPY_TO_COMPLEXDIAGRAM, true);
1028         }
1029
1030 }
1031
1032 //=========================================================================
1033
1034 void wxGUIEditorGraphicBBS::OnDeleteAllBoxesActualDiagram(wxCommandEvent& event) 
1035 {
1036         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);
1037         if (dial->ShowModal() == wxID_YES)
1038         {
1039                 _tabsMgr->deleteAllBoxesActualDiagram();
1040         }
1041 }
1042
1043 //=========================================================================
1044
1045 void wxGUIEditorGraphicBBS::OnCenterViewActualDiagram(wxCommandEvent& event) 
1046 {
1047         _tabsMgr->centerViewActualDiagram();
1048 }
1049
1050 //=========================================================================
1051 void wxGUIEditorGraphicBBS::OpenDiagram(std::string filePathName, std::string fileName) 
1052 {
1053         ifstream inputStream;   
1054         inputStream.open(filePathName.c_str());
1055         assert(inputStream.good()); // fails
1056         
1057         if(_tabsMgr->FindTab(filePathName)!=-1) //RaC2012 avoid opening same diagram twice
1058         {
1059                 inputStream.close();
1060                 printf("RaC: Diagram already opened\n");
1061                 return;
1062         }
1063         _tabsMgr->addNewTab( crea::std2wx(fileName) );
1064         _tabsMgr->loadDiagram(inputStream, filePathName);
1065         _tabsMgr->saveTempActualDiagram("load diagram");
1066         GetToolBar()->EnableTool(ID_UNDO, false);
1067         GetToolBar()->EnableTool(ID_UNDO, false);
1068         inputStream.close();
1069         refreshGUIControls();
1070 }
1071         
1072 //=========================================================================
1073
1074 void wxGUIEditorGraphicBBS::OnOpenDiagram(wxCommandEvent& event) 
1075 {
1076         wxFileDialog * openFileDialog = new wxFileDialog(this, wxT("Open diagram"), wxEmptyString, wxT(""), wxT("*.bbg"), wxOPEN | wxFILE_MUST_EXIST);
1077         if (openFileDialog->ShowModal() == wxID_OK) 
1078         {
1079                 wxString filePath = openFileDialog->GetPath();
1080                 wxString fileName = openFileDialog->GetFilename();
1081                 OpenDiagram( crea::wx2std(filePath) , crea::wx2std(fileName) );                                 
1082         }
1083 }
1084
1085 //=========================================================================
1086 void wxGUIEditorGraphicBBS::OnClickBtnBox(wxCommandEvent& event) 
1087 {
1088         BlackBoxDescriptor *bbDes = _pkgBrowser->GetActualSelected();
1089         if (bbDes != NULL) {
1090                 std::string typeName = bbDes->GetTypeName();
1091                 std::string packageName = bbDes->GetPackage()->GetName();
1092                 wxGEditorTabPanel *pnl = this->_tabsMgr->getActualTabPanel();
1093                 if (pnl != NULL) {
1094                         wxVtkSceneManager *scn = pnl->getSceneManager();
1095                         scn->createGBlackBox(50, 50, packageName, typeName);
1096                         scn->refresh();
1097                 }
1098                 SaveTempActualDiagram("New Box");
1099                 // if pnl
1100         }// if bbDes
1101 }
1102
1103 //=========================================================================
1104
1105 void wxGUIEditorGraphicBBS::OnClickBtnExecutableBox(wxCommandEvent& event) 
1106 {
1107         //DFCH
1108         wxGEditorTabPanel *pnl = this->_tabsMgr->getActualTabPanel();
1109
1110         if (pnl != NULL) {
1111                 wxVtkSceneManager *scn = pnl->getSceneManager();
1112                 if( scn->MakeBoxExecutable() )
1113                         std::cout<<"DFCH: wxGUIEditorGraphicBBS::OnClickBtnExecutableBox...successful"<<std::endl;
1114                 else
1115                         std::cout<<"DFCH: wxGUIEditorGraphicBBS::OnClickBtnExecutableBox...Error!!"<<std::endl;
1116         }
1117         //DFCH
1118
1119 }
1120
1121 //=========================================================================
1122 void wxGUIEditorGraphicBBS::OnClickBtnComplexBox(wxCommandEvent& event) 
1123 {
1124         wxToolBar* toolbar = GetToolBar();
1125         bool temp = toolbar->GetToolState(ID_BTNCOMPLEXBOX);
1126         if (temp) {
1127                 enableComplexBox();
1128         } else {
1129                 disableComplexBox();
1130         }
1131 }
1132
1133 //=========================================================================
1134 //EED01
1135 void wxGUIEditorGraphicBBS::OnAddComplexBoxInput(wxCommandEvent& event) 
1136 {
1137         wxTextEntryDialog *nameDialog = new wxTextEntryDialog(this,
1138                         wxT("Name of input port"));
1139         if (nameDialog->ShowModal() == wxID_OK) 
1140         {
1141                 wxString fileName = nameDialog->GetValue();
1142                 if (!fileName.IsEmpty()) 
1143                 {
1144                         std::string portName = (const char*) (fileName.mb_str());
1145                         if ( !boxNameExists(portName) )
1146                         {
1147                            _tabsMgr->addActualDiagramComplexInputPort(portName);
1148                         } else {
1149                            wxMessageDialog *dial = new wxMessageDialog(NULL,
1150                                        wxT("Impossible to create Box. The name already exists. Please provide another name"),
1151                                        wxT("Change name: name already exists"), wxOK | wxICON_EXCLAMATION | wxSTAY_ON_TOP);
1152                            dial->ShowModal();
1153                         }
1154                 } // if !fileName
1155         } // if namaDialog
1156 }
1157
1158 //=========================================================================
1159 void wxGUIEditorGraphicBBS::OnAddComplexBoxOutput(wxCommandEvent& event) 
1160 {
1161         wxTextEntryDialog *nameDialog = new wxTextEntryDialog(this,
1162                         wxT("Name of output port"));
1163         if (nameDialog->ShowModal() == wxID_OK) 
1164         {
1165                 wxString fileName = nameDialog->GetValue();
1166                 if (!fileName.IsEmpty()) 
1167                 {
1168                         std::string portName = (const char*) (fileName.mb_str());
1169                         if ( !boxNameExists(portName) )
1170                         {
1171                         _tabsMgr->addActualDiagramComplexOutputPort(portName);
1172                         } else {
1173                            wxMessageDialog *dial = new wxMessageDialog(NULL,
1174                                        wxT("Impossible to create Box. The name already exists. Please provide another name"),
1175                                        wxT("Change name: name already exists"), wxOK | wxICON_EXCLAMATION | wxSTAY_ON_TOP);
1176                            dial->ShowModal();
1177                         }
1178
1179                 } // if !filename
1180         } // namaDialog
1181 }
1182
1183 //=========================================================================
1184 void wxGUIEditorGraphicBBS::OnCopySelectedToComplexDiagram(
1185                 wxCommandEvent& event) 
1186 {
1187         _tabsMgr->copySelectedBBoxesToComplexDiagram();
1188 }
1189
1190 //=========================================================================
1191 void wxGUIEditorGraphicBBS::OnHelpBBeditor(wxCommandEvent& event) 
1192 {
1193         printf("wxGUIEditorGraphicBBS::OnHelpBBeditor ....not implemented..\n");
1194 }
1195
1196 //=========================================================================
1197 void wxGUIEditorGraphicBBS::OnCreatePackage(wxCommandEvent& event) 
1198 {
1199         bbtkSystemTools::CreatePackage();
1200 }
1201
1202 //=========================================================================
1203 void wxGUIEditorGraphicBBS::OnCreateBlackBox(wxCommandEvent& event) 
1204 {
1205         bbtkSystemTools::CreateBlackBox();
1206 }
1207         
1208 //=========================================================================
1209 void wxGUIEditorGraphicBBS::OnPlugPackage(wxCommandEvent& event) 
1210 {
1211         //DFGO2012 Plug Package functionnalities
1212         long style = wxDD_DEFAULT_STYLE | wxDD_DIR_MUST_EXIST;
1213         wxDirDialog* FD =
1214           new wxDirDialog( 0,
1215                            _T("Select package directory"),
1216                            _T(""),
1217                            style);
1218         long userResponse;
1219         do
1220         {
1221                 userResponse = FD->ShowModal();
1222                 if(userResponse==wxID_OK)
1223                 {
1224                         std::string path = wx2std (FD->GetPath()) ;
1225                         #ifdef WIN32
1226                         std::string fname = path + "\\bbtkPackage";
1227                         #else
1228                         std::string fname = path + "/bbtkPackage";
1229                         #endif
1230                         
1231                         std::cout << "Path chosen = \"" << FD->GetPath() << "\"" << std::endl;
1232                         if ( Utilities::FileExists( fname ) )
1233                         {
1234                                 std::ifstream f;
1235                                 f.open(fname.c_str());
1236                                 std::string pname;
1237                                 f >> pname;
1238                                 while(pname[0] == '#')
1239                                 {
1240                                         getline(f, pname, '\n');
1241                                         f >> pname;
1242                                 }
1243                                 f.close();
1244
1245                                 bbtk::ConfigurationFile::GetInstance().AddPackagePathsAndWrite( path );
1246
1247                                 DoRegeneratePackageDoc(pname);
1248                                 DoRegenerateBoxesLists();
1249
1250                                 _pkgBrowser->RebuildList();
1251
1252                                 wxMessageBox(_T("Package successfully plugged. Please restart bbEditor to see the new package in the package browser."),_T("Plug package"),wxOK | wxICON_INFORMATION);
1253                                 userResponse = wxID_CANCEL;
1254                         }
1255                         else
1256                         {
1257                                 std::string err = "The directory \"" + path + "\" does not contain a 'bbtkPackage' file.";
1258                                 #ifndef WIN32
1259                                         #ifndef MACOSX
1260                                                 err += "\nNote: If you are on Linux please select the folder and click \"Open\", don't enter in it.";
1261                                         #endif
1262                                 #endif
1263
1264                                 wxMessageBox(crea::std2wx(err), _T("Plug package"),wxOK | wxICON_ERROR);
1265                                 // THE FOLLOWING LINE GIVES ERRORS BECAUSE IT IS NECESSARY TO USE std2wx
1266                                 //wxMessageBox( _T( err) , _T("Plug package"),wxOK | wxICON_ERROR);
1267                         }
1268                 }
1269         }while(userResponse != wxID_CANCEL);
1270
1271 }
1272         
1273 //=========================================================================
1274 void wxGUIEditorGraphicBBS::OnEditConfig(wxCommandEvent& event) 
1275 {
1276         std::string commandStr;
1277             std::string configFile = ConfigurationFile::GetInstance().Get_config_xml_full_path();
1278         #ifdef WIN32
1279                 commandStr = "notepad.exe ";
1280         #else
1281                 commandStr = "gedit ";
1282         #endif
1283                 commandStr = commandStr + configFile;
1284                 std::cout << "system: " << commandStr << std::endl;
1285                 system ( commandStr.c_str() );
1286 }
1287         
1288 //=========================================================================
1289 void wxGUIEditorGraphicBBS::OnShowHTMLDoc(wxCommandEvent& event) 
1290 {
1291         // JGRR & CM WH
1292         if (_helpHtmlBrowser != NULL){
1293              _frameAUIMgr->DetachPane(_helpHtmlBrowser);
1294             _helpHtmlBrowser->Destroy();   
1295         }
1296         initHelpHTMLBrowser();
1297         _frameAUIMgr->AddPane(_helpHtmlBrowser, wxAuiPaneInfo().Right().MinSize(200, 200));
1298         _frameAUIMgr->Update();
1299         refreshGUIControls();
1300         
1301         // EO JGRR    & CM WH       
1302 }
1303         
1304 //=========================================================================
1305 void wxGUIEditorGraphicBBS::OnCreateIndex(wxCommandEvent& event) 
1306 {
1307         printf("EED wxGUIEditorGraphicBBS::OnCreateIndex ... not implemented ..\n");
1308 }
1309
1310         
1311 //=========================================================================
1312 void wxGUIEditorGraphicBBS::OnEditComplexBoxScript(wxCommandEvent& event)
1313 {
1314         BlackBoxDescriptor *bbDes = _pkgBrowser->GetActualSelected();
1315         if (bbDes != NULL) 
1316         {
1317                 std::string packageName = bbDes->GetPackage()->GetName();
1318                 std::string typeName = bbDes->GetTypeName();
1319                 if (!TryToOpenScriptComplexBox(packageName ,typeName))
1320                 {
1321                         wxMessageDialog windowMessage1(NULL,_T("This is not a ComplexBox script."), _T("Alert !"), wxOK);
1322                         windowMessage1.ShowModal();
1323                 }
1324         }// if bbDes
1325 }
1326
1327 //=========================================================================
1328 void wxGUIEditorGraphicBBS::OnExit(wxCommandEvent& event) 
1329 {
1330         Close(true);
1331 }
1332
1333 Factory::Pointer wxGUIEditorGraphicBBS::GetBBTKFactory()
1334 {
1335         if (_pkgBrowser==NULL) 
1336         {
1337                 printf ("EED ERROR! wxGUIEditorGraphicBBS::GetBBTKFactory _pkgBrowser = NULL\n");
1338         }
1339         return _pkgBrowser->GetFactory();
1340 }
1341
1342 //=========================================================================
1343 void wxGUIEditorGraphicBBS::enableComplexBox() 
1344 {
1345         _tabsMgr->setActualDiagramComplexBox(true);
1346         refreshGUIControls();
1347 }
1348
1349 //=========================================================================
1350
1351 void wxGUIEditorGraphicBBS::disableComplexBox() 
1352 {
1353         _tabsMgr->setActualDiagramComplexBox(false);
1354         refreshGUIControls();
1355 }
1356
1357 //=========================================================================
1358 void wxGUIEditorGraphicBBS::setCurrentDiagramDescription(std::string description)
1359 {
1360         _tabsMgr->SetDescription(description);
1361 }
1362
1363 //=========================================================================
1364 void wxGUIEditorGraphicBBS::setCurrentDiagramAuthor(std::string author)
1365 {
1366         _tabsMgr->SetAuthor(author);
1367 }
1368
1369 //=========================================================================
1370 void wxGUIEditorGraphicBBS::setCurrentDiagramCategory(std::string category)
1371 {
1372         _tabsMgr->SetCategory(category);
1373 }
1374
1375 //=========================================================================
1376 std::string wxGUIEditorGraphicBBS::getCurrentDiagramDescription()
1377 {
1378         return _tabsMgr->GetDescription();
1379 }
1380
1381 //=========================================================================
1382 std::string wxGUIEditorGraphicBBS::getCurrentDiagramAuthor()
1383 {
1384         return _tabsMgr->GetAuthor();
1385 }
1386
1387 //=========================================================================
1388 std::string wxGUIEditorGraphicBBS::getCurrentDiagramCategory()
1389 {
1390         return _tabsMgr->GetCategory();
1391 }
1392
1393         
1394 //=========================================================================
1395 bool wxGUIEditorGraphicBBS::isCurrentDiagramComplexBox()
1396 {
1397         return _tabsMgr->isActualDiagramComplexBox();
1398 }
1399
1400
1401 //=========================================================================
1402 void wxGUIEditorGraphicBBS::OpenScript(std::string filePathNameBBS ,std::string boxType)
1403 {       
1404         std::string fileName                                                    = boxType+".bbg";
1405         std::string filePathNameBBG                                             = filePathNameBBS;
1406         filePathNameBBG[ filePathNameBBG.length()-1 ]   = 'g';
1407         
1408         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);
1409         windowMessage1.ShowModal();
1410         
1411         if ( Utilities::FileExists( filePathNameBBG ) )
1412         {
1413                 OpenDiagram( filePathNameBBG , fileName );     
1414         } else {
1415                 if ( Utilities::FileExists( filePathNameBBS ) )
1416                 {
1417                         OpenBBS( filePathNameBBS , fileName );     
1418                 } else {
1419                         wxMessageDialog windowMessage1(NULL,_T("..ERROR.. loading script bbg/bbs."), _T("Alert !"), wxOK);
1420                         windowMessage1.ShowModal();
1421                 } // FileExists BBS
1422         } // FieExists BBG
1423 } //OpenScript
1424         
1425         
1426         
1427 //=========================================================================
1428 bool wxGUIEditorGraphicBBS::TryToOpenScriptApplication(std::string packageName ,std::string boxType)
1429 {       
1430         return TryToOpenScript(packageName ,boxType, true, false);
1431 }               
1432
1433 //=========================================================================
1434 bool wxGUIEditorGraphicBBS::TryToOpenScriptComplexBox(std::string packageName ,std::string boxType)
1435 {       
1436         return TryToOpenScript(packageName ,boxType, false, true);
1437 }               
1438         
1439         
1440 //=========================================================================
1441 bool wxGUIEditorGraphicBBS::TryToOpenScript(std::string packageName ,std::string boxType,bool scriptApplication, bool scriptComplexBox)
1442 {       
1443         Package::Pointer k;
1444         std::map< std::string, BlackBoxDescriptor::Pointer> mapDesc;
1445         BlackBoxDescriptor::Pointer descriptor;
1446         k                       = GetBBTKFactory()->GetPackage(packageName);
1447         mapDesc         = k->GetDescriptorMap();
1448         descriptor      = mapDesc[boxType];
1449
1450         bool result=false;
1451         
1452         if (
1453                 ((descriptor->IsTypeOfScript_Application()==true) && (scriptApplication==true))
1454                 ||
1455                 ((descriptor->IsTypeOfScript_ComplexBox()==true) && (scriptComplexBox==true))           
1456                 )
1457         {
1458                 result=true;
1459                 OpenScript(descriptor->GetScriptFileName(),boxType);
1460         }
1461         
1462         return result;
1463 }       
1464         
1465 } // EO namespace bbtk
1466
1467 // EOF
1468