]> Creatis software - bbtkGEditor.git/blob - lib/EditorGraphicBBS/bbsWxGUIEditorGraphic/bbtkwxGUIEditorGraphicBBS.cxx
no message
[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
40 #include <InterpreterBBS.h>
41
42
43
44 namespace bbtk
45 {
46
47
48         //=========================================================================
49         wxGUIEditorGraphicBBS::wxGUIEditorGraphicBBS(wxFrame *parent)
50                 : wxFrame(parent, -1, _T("bbtkGEditor"),wxDefaultPosition, wxSize(1200,800))
51         {
52
53                 _frameAUIMgr = new wxAuiManager(this);
54                 
55
56                 /*std::string datadir( crea::System::GetExecutablePath() );
57                 std::string datadir (".");
58                 cout<<"RaC //------------------"<<endl;
59                 cout<<"RaC //TODO wxGUIEditorGraphicBBS constructor.Initialize datadir with  crea::System::GetExecutablePath() ."<<endl;
60                 cout<<"RaC //------------------"<<endl;
61
62             #ifdef LINUX // assume this is OSX 
63                    datadir=datadir+"/../share/creaContours";
64             #endif // MACOSX    
65         
66                 #ifdef MACOSX // assume this is OSX 
67                         datadir=datadir+"/../../../../share/creaContours";
68                 #endif // MACOSX        
69
70                 _dataDir = datadir;*/
71
72                 initMenu();
73                 initToolbar();
74                 initTabPanelsManager();
75                 initPackageBrowser();
76                 initHelpHTMLBrowser();
77
78                 CreateStatusBar();
79                 _frameAUIMgr->Update();
80                 _actualPkgBrowserBoxName="";
81                 _actualPkgBrowserPkgName="";
82                 refreshGUIControls();
83         }
84
85
86         //=========================================================================
87         wxGUIEditorGraphicBBS::~wxGUIEditorGraphicBBS()
88         {
89                 printf ("EED %p ~wxGUIEditorGraphicBBS()\n" , this );
90
91 //EED02JUIN2010         delete _tabsMgr;
92
93             _frameAUIMgr->UnInit();
94
95
96         }
97
98         //=========================================================================
99         void wxGUIEditorGraphicBBS::initToolbar()
100         {        
101                 wxBitmap bmp_new(new_xpm);
102                 wxBitmap bmp_open(open_xpm);
103                 wxBitmap bmp_save(save_xpm);
104                 wxBitmap bmp_run(run_xpm);
105                 wxBitmap bmp_delete(delete_xpm);
106                 wxBitmap bmp_centerview(centerview_xpm);
107                 wxBitmap bmp_complexbox(complexbox_xpm);
108                 wxBitmap bmp_complexinputport(complexinputport_xpm);
109                 wxBitmap bmp_complexoutputport(complexoutputport_xpm);
110
111                 wxToolBar  *toolbar = new wxToolBar(this, wxID_ANY);
112
113                 //Adds a tool btn to the toolbar
114                 toolbar->AddTool(ID_NEW,_T("New"),bmp_new, wxNullBitmap, wxITEM_NORMAL,_T("New tab"), _T("Create a new panel tab"));
115                 toolbar->AddTool(ID_OPEN,_T("Open diagram"),bmp_open, wxNullBitmap, wxITEM_NORMAL,_T("Open a diagram"), _T("Open a diagram"));
116                 toolbar->AddTool(ID_SAVE_AS_DIAGRAM,_T("Save diagram"),bmp_save, wxNullBitmap, wxITEM_NORMAL,_T("Saves actual diagram"), _T("Saves actual diagram"));
117                 toolbar->AddTool(ID_RUN,_T("Run"),bmp_run, wxNullBitmap, wxITEM_NORMAL,_T("Execute actual diagram"), _T("Execute actual diagram"));
118                 toolbar->AddTool(ID_DELETEALL,_T("Delete all"),bmp_delete, wxNullBitmap, wxITEM_NORMAL,_T("Delete all boxes"), _T("Delete all boxes"));
119                 toolbar->AddTool(ID_CENTERVIEW,_T("Center view"),bmp_centerview, wxNullBitmap, wxITEM_NORMAL,_T("Center view"), _T("Center view"));
120                 toolbar->AddSeparator();
121                 toolbar->AddTool(ID_BTNCOMPLEXBOX,_T("Complex box"),complexbox_xpm, wxNullBitmap, wxITEM_NORMAL,_T("Complex box"), _T("Complex box"));
122                 toolbar->SetToggle(ID_BTNCOMPLEXBOX,true);
123                 toolbar->AddTool(ID_ADDCOMPLEXBOXINPUT,_T("Add input to Complex box"),bmp_complexinputport, wxNullBitmap, wxITEM_NORMAL,_T("Add input to Complex box"), _T("Add input to Complex box"));
124                 toolbar->AddTool(ID_ADDCOMPLEXBOXOUTPUT,_T("Add output to Complex box"),bmp_complexoutputport, wxNullBitmap, wxITEM_NORMAL,_T("Add output Complex box"), _T("Add output Complex box"));
125                 toolbar->EnableTool(ID_ADDCOMPLEXBOXINPUT,false);
126                 toolbar->EnableTool(ID_ADDCOMPLEXBOXOUTPUT,false);
127                 
128                 toolbar->SetMargins( 2, 2 );
129                 toolbar->Realize();
130                 SetToolBar(toolbar);
131
132                 // connect command event handlers
133                 Connect(ID_NEW,wxEVT_COMMAND_TOOL_CLICKED,wxCommandEventHandler(wxGUIEditorGraphicBBS::OnCreateNewTab));
134                 Connect(ID_OPEN,wxEVT_COMMAND_TOOL_CLICKED,wxCommandEventHandler(wxGUIEditorGraphicBBS::OnOpenDiagram));
135                 Connect(ID_SAVE_AS_DIAGRAM,wxEVT_COMMAND_TOOL_CLICKED,wxCommandEventHandler(wxGUIEditorGraphicBBS::OnSaveActualDiagram));
136                 Connect(ID_RUN,wxEVT_COMMAND_TOOL_CLICKED,wxCommandEventHandler(wxGUIEditorGraphicBBS::OnExecuteActualDiagram));
137                 Connect(ID_DELETEALL,wxEVT_COMMAND_TOOL_CLICKED,wxCommandEventHandler(wxGUIEditorGraphicBBS::OnDeleteAllBoxesActualDiagram));
138                 Connect(ID_CENTERVIEW,wxEVT_COMMAND_TOOL_CLICKED,wxCommandEventHandler(wxGUIEditorGraphicBBS::OnCenterViewActualDiagram));
139                 Connect(ID_BTNCOMPLEXBOX,wxEVT_COMMAND_TOOL_CLICKED,wxCommandEventHandler(wxGUIEditorGraphicBBS::OnClickBtnComplexBox));
140                 Connect(ID_ADDCOMPLEXBOXINPUT,wxEVT_COMMAND_TOOL_CLICKED,wxCommandEventHandler(wxGUIEditorGraphicBBS::OnAddComplexBoxInput));
141                 Connect(ID_ADDCOMPLEXBOXOUTPUT,wxEVT_COMMAND_TOOL_CLICKED,wxCommandEventHandler(wxGUIEditorGraphicBBS::OnAddComplexBoxOutput));
142
143         }
144         //=========================================================================
145         void wxGUIEditorGraphicBBS::initHelpHTMLBrowser()
146         {
147                 //TO FIX THE PATH OF BBTK BIN  IN ORDER TO USE REGENERATE EXECUTABLES
148                 //RegenerateAll();
149                 _helpHtmlBrowser = new WxGUIHtmlBrowser(this,wxSize(200,0));
150                 _frameAUIMgr->AddPane(_helpHtmlBrowser,wxAuiPaneInfo().Right().MinSize(200,200));       
151         }
152
153         //=========================================================================
154         void wxGUIEditorGraphicBBS::initMenu()
155         {
156                 // Create File menu and its items
157                 wxMenu *fileMenu = new wxMenu();
158                 fileMenu->Append(ID_NEW, _T("New diagram"), _T("New"));
159                 fileMenu->Append(ID_SAVE_AS_DIAGRAM, _T("Save diagram"), _T("Save diagram"));
160                 fileMenu->Append(ID_OPEN_BBS, _T("Open BBS"), _T("Open BBS"));
161                 fileMenu->Append(ID_SAVE_AS_BBS, _T("Save BBS"), _T("Save BBS"));
162                 fileMenu->Append(ID_SAVE_AS_COMPLEXBOX, _T("Save complex box"), _T("Save complex box"));
163                 fileMenu->Append(wxID_EXIT, _T("E&xit"), _T("Exit"));
164
165                 Connect(ID_NEW,wxEVT_COMMAND_MENU_SELECTED,wxCommandEventHandler(wxGUIEditorGraphicBBS::OnCreateNewTab));
166                 Connect(ID_SAVE_AS_DIAGRAM,wxEVT_COMMAND_MENU_SELECTED,wxCommandEventHandler(wxGUIEditorGraphicBBS::OnSaveActualDiagram));
167                 Connect(ID_OPEN_BBS,wxEVT_COMMAND_MENU_SELECTED,wxCommandEventHandler(wxGUIEditorGraphicBBS::OnOpenBBS));
168                 Connect(ID_SAVE_AS_BBS,wxEVT_COMMAND_MENU_SELECTED,wxCommandEventHandler(wxGUIEditorGraphicBBS::OnSaveActualBBS));
169                 Connect(ID_SAVE_AS_COMPLEXBOX,wxEVT_COMMAND_MENU_SELECTED,wxCommandEventHandler(wxGUIEditorGraphicBBS::OnSaveActualComplexBox));
170                 Connect(wxID_EXIT,wxEVT_COMMAND_MENU_SELECTED,wxCommandEventHandler(wxGUIEditorGraphicBBS::OnExit));
171
172                 // Create Help menu and its items
173                 wxMenu *editMenu = new wxMenu;
174                 editMenu->Append(ID_COPY_TO_COMPLEXDIAGRAM, _T("Copy selected to complex box"), _T("Creates a new complex box diagram with selected boxes"));   
175
176                 Connect(ID_COPY_TO_COMPLEXDIAGRAM,wxEVT_COMMAND_MENU_SELECTED,wxCommandEventHandler(wxGUIEditorGraphicBBS::OnCopySelectedToComplexDiagram));
177
178                 // Create Help menu and its items
179                 wxMenu *helpMenu = new wxMenu;
180                 helpMenu->Append(wxID_ABOUT, _T("&About..."), _T("About"));             
181
182                 // Append the created menu to the menu bar
183                 wxMenuBar *menuBar = new wxMenuBar();
184                 menuBar->Append(fileMenu, _T("&File"));
185                 menuBar->Append(editMenu, _T("&Edit"));
186                 menuBar->Append(helpMenu, _T("&Help"));
187
188                 // Attach this menu bar to the frame
189                 SetMenuBar(menuBar);            
190         }
191
192         //=========================================================================
193         void wxGUIEditorGraphicBBS::initTabPanelsManager()
194         {
195                 _notebook = new wxAuiNotebook(this,wxID_NOTEBOOK,wxDefaultPosition,wxDefaultSize,wxAUI_NB_TOP|wxAUI_NB_TAB_MOVE|wxAUI_NB_CLOSE_ON_ACTIVE_TAB|wxAUI_NB_TAB_FIXED_WIDTH|wxAUI_NB_WINDOWLIST_BUTTON);
196                 _tabsMgr = new wxTabPanelsManager(this);
197                 _frameAUIMgr->AddPane(_notebook,wxAuiPaneInfo().CenterPane());  
198
199         }
200         
201         //=========================================================================
202         void wxGUIEditorGraphicBBS::initPackageBrowser()
203         {
204                 _pkgBrowser = new WxGUIPackageBrowser2(this);
205                 _pkgBrowser->IncludeAll();
206                 _frameAUIMgr->AddPane(_pkgBrowser,wxAuiPaneInfo().Left().MinSize(200,200).CloseButton(false));          
207         }
208
209         //================================================================
210
211         void wxGUIEditorGraphicBBS::DoRegeneratePackageDoc( const std::string& pack )
212         {
213                 std::string mess("Regenerating doc for package '");
214                 if (pack!="-a"){
215                         mess += pack + "'";
216                 }
217                 else
218                 {
219                         mess = "Regenerating doc for all packages";
220                 }
221                 
222                 mess += " ... please wait";             
223
224                 SetStatusText( std2wx(mess) );
225
226                 //BBTK_BUSY_CURSOR;
227
228                 std::string command;
229                 #if defined(WIN32)
230                         command = "\"";
231                 #endif
232                         command += ConfigurationFile::GetInstance().Get_bin_path();
233                         command += ConfigurationFile::GetInstance().Get_file_separator();
234                         command += "bbRegeneratePackageDoc";
235                 #if defined(WIN32)
236                         command += "\"";
237                 #endif
238
239                 command += " " + pack + " -q";
240             bbtkMessage("debug",1,"Executing system command '"<<command<<"'"<<std::endl);
241
242                 if ( ! system ( command.c_str() ) )
243                 {
244                         SetStatusText( _T("Done !"));
245                         /*
246                         wxMessageBox(_T("Done !"),_T("Regenerate package '")
247                                          +std2wx(pack)+_T("' doc"),
248                                          wxOK | wxICON_INFORMATION);
249                         */
250                 }
251                 else 
252                 {
253                         SetStatusText( _T("Done !"));
254                         wxString err(_T("An error occured while running '"));
255                         err +=  bbtk::std2wx(command) + _T("'");
256                         wxMessageBox(err,_T("Regenerate package doc"),wxOK | wxICON_ERROR);      
257             }
258         }
259
260         //================================================================
261         void wxGUIEditorGraphicBBS::DoRegenerateBoxesLists()
262         {
263                 SetStatusText( _T("Regenerating boxes lists ... please wait") );
264                 //BBTK_BUSY_CURSOR ;
265
266                 std::string command;
267                 #if defined(WIN32)
268                         command = "\"";
269                 #endif
270                         command += ConfigurationFile::GetInstance().Get_bin_path();
271                         command += ConfigurationFile::GetInstance().Get_file_separator();
272                         command += "bbRegenerateBoxesLists";
273
274                 #if defined(WIN32)
275                         command += "\"";
276                 #endif
277                         command += " -q";
278
279                 bbtkMessage("debug",1,"Executing system command '"<<command<<"'"<<std::endl);
280
281                 if ( ! system ( command.c_str() ) )
282                 {
283                         SetStatusText( _T("Done !"));
284                         /*
285                         wxMessageBox(_T("Done !"),_T("Regenerate boxes lists"),
286                                          wxOK | wxICON_INFORMATION);
287                         */
288                 }
289                 else 
290                 {
291                         SetStatusText( _T("Done !"));
292                         wxString err(_T("An error occured while running '"));
293                         err +=  bbtk::std2wx(command) + _T("'");
294                         wxMessageBox(err,_T("Regenerate boxes lists"),wxOK | wxICON_ERROR);      
295                 }
296         }
297         
298   //================================================================
299         void wxGUIEditorGraphicBBS::RegenerateAll()
300         {
301                 DoRegeneratePackageDoc("-a");   
302                 DoRegenerateBoxesLists();
303         }
304
305         //================================================================
306
307         wxAuiNotebook* wxGUIEditorGraphicBBS::getAuiNotebook()
308         {
309                 return _notebook;
310         }
311
312         //================================================================
313
314         void wxGUIEditorGraphicBBS::displayBlackBoxInfo(std::string packageName, std::string boxName)
315         {
316                 if(_actualPkgBrowserPkgName != packageName || _actualPkgBrowserBoxName != boxName )
317                 {
318                         _actualPkgBrowserPkgName = packageName;
319                         _actualPkgBrowserBoxName = boxName;
320
321                         BlackBoxDescriptor::Pointer descriptor = GObjectsMVCFactory::getInstance()->getBlackBoxDescriptor(packageName, boxName);
322                         _pkgBrowser->WxGUIBlackBoxListUserOnSelected(descriptor.get());
323                 }
324         }
325
326         //=========================================================================
327
328         void wxGUIEditorGraphicBBS::editBlackBox(GBlackBoxModel *bbmodel)
329         {
330                 wxBlackBoxEditionDialog* dialog = new wxBlackBoxEditionDialog(this,bbmodel);
331                 dialog->Show();
332         }
333
334         //=========================================================================
335
336         void wxGUIEditorGraphicBBS::updateStatusBar(std::string textStatus)
337         {
338                 SetStatusText(crea::std2wx(textStatus));
339         }
340
341         //=========================================================================
342
343         void wxGUIEditorGraphicBBS::executeScript(std::string script)
344         {
345                 std::string separator = ConfigurationFile::GetInstance().Get_file_separator ();
346                 std::string dir = ConfigurationFile::GetInstance().Get_default_temp_dir();
347                 std::string filename = dir + separator + "tmp_bbtk.bbs";
348                 
349                 ofstream tempFile;
350                 tempFile.open(filename.c_str());
351                 tempFile << script;
352                 tempFile.close();
353
354                 std::string command = "\""+ crea::System::GetExecutablePath();
355
356                 
357 #ifdef MACOSX
358                 command += separator + "../../../bbi.app/Contents/MacOS";
359 #endif
360                 
361                 #ifdef WIN32
362                         command += "\"";
363                 #endif
364                 
365                 /*              
366                 
367                 //command += ConfigurationFile::GetInstance().Get_bin_path();
368 //EED           command +="C:/temp/bbtkBIN/RelWithDebInfo//";
369 //EED           command +="C:/Program Files/CreaTools/bbtk-0.9.5/bin";
370
371
372                 #ifdef MACOSX
373                         command += separator + "usr/local/bin/bbi.app/Contents/MacOS/bbi\" ";
374                 #else 
375                     command +=".";
376                         command += separator + "bbi\" ";
377                 #endif
378  */
379                 command += separator + "bbi\" ";
380                 command += "\""+filename + "\"";
381                 #ifdef WIN32
382                         command += "\"";
383                 #endif
384
385                 command += " & ";
386                   
387                 printf ("RaC wxGUIEditorGraphicBBS::executeScript %s \n" , command.c_str() );
388                 system( command.c_str() );
389         }
390
391         //=========================================================================
392         // EVENT HANDLERS 
393         //=========================================================================
394
395         void wxGUIEditorGraphicBBS::OnCreateNewTab(wxCommandEvent& event)
396         {
397                 _tabsMgr->addNewTab();  
398                 refreshGUIControls();
399         }
400
401         //=========================================================================
402
403         void wxGUIEditorGraphicBBS::OnExecuteActualDiagram(wxCommandEvent& event)
404         {
405                 std::string script = _tabsMgr->getActualDiagramBBS();
406                 cout<<"RaC wxGUIEditorGraphicBBS::executeActualDiagram SCRIPT"<<endl;
407                 cout<<script<<endl;
408
409                 executeScript(script);          
410         }
411
412         
413         //=========================================================================
414         // HANDLERS 
415         //=========================================================================
416         void wxGUIEditorGraphicBBS::OnOpenBBS(wxCommandEvent& event)
417         {
418                 wxFileDialog * openFileDialog = new wxFileDialog(this,wxT("Open BBS"),wxEmptyString,wxT("NewBBS"),wxT("*.bbs"),wxOPEN);
419                 if (openFileDialog->ShowModal() == wxID_OK)
420                 {
421                         wxString fileName = openFileDialog->GetPath(  );
422 printf("EED wxGUIEditorGraphicBBS::OnOpenBBS  file=%s\n", (const char*) (fileName.mb_str()) );
423                         
424                         
425                         _tabsMgr->addNewTab();
426
427                         
428 //                      bbtk::EExecuterBBSG::Pointer exe = bbtk::EExecuterBBSG::New( this->_tabsMgr->getActualTabPanel()->getSceneManager() , _pkgBrowser->GetFactory() );
429                         bbtk::InterpreterBBS::Pointer I = bbtk::InterpreterBBS::New( this->_tabsMgr->getActualTabPanel()->getSceneManager() , _pkgBrowser->GetFactory());                       
430                         
431                         // We tell the interpreter to throw exceptions on error
432                         I->SetThrow(true);
433                         // Interpret the file supposed to define a box called 'Processing'
434                         I->InterpretFile( (const char*) (fileName.mb_str()) );
435                 }
436                 refreshGUIControls();
437         }
438
439         void wxGUIEditorGraphicBBS::OnSaveActualBBS(wxCommandEvent& event)
440         {
441                 wxFileDialog * saveFileDialog = new wxFileDialog(this,wxT("Save  actual BBS"),wxEmptyString,wxT("NewBBS"),wxT("*.bbs"),wxSAVE|wxOVERWRITE_PROMPT);
442                 if (saveFileDialog->ShowModal() == wxID_OK)
443                 {
444                         wxString fileName = saveFileDialog->GetPath(  );
445                         
446                         ofstream file;
447
448 //EED                   file.open(fileName.c_str()); 
449                         file.open( (const char*) (fileName.mb_str()) );
450
451                         std::string content="";
452                         
453                         // writing file header
454                         content += "# ----------------------------------\n";
455                         content += "# - BBTKGEditor v 1.0 BBS BlackBox Script\n";
456                         content += "# ----------------------------------\n";
457                         content += "\n";
458                         content += _tabsMgr->getActualDiagramBBS();
459                         file << content;
460                         file.close();
461                 }
462
463         }
464
465         //=========================================================================
466
467         void wxGUIEditorGraphicBBS::OnSaveActualComplexBox(wxCommandEvent& event)
468         {
469                 wxTextEntryDialog *nameDialog = new wxTextEntryDialog(this,wxT("Name of complex box"));
470                 std::string cbName="";
471                 if (nameDialog->ShowModal() == wxID_OK)
472                 {
473                         wxString fileName = nameDialog->GetValue();
474                         cbName=(const char*) (fileName.mb_str());
475                 }               
476
477                 if(!cbName.empty())
478                 {                               
479                         wxFileDialog * saveFileDialog = new wxFileDialog(this ,wxT("Save Complex Box BBS") ,wxEmptyString, wxString( cbName.c_str(), wxConvUTF8),wxT("*.bbs"), wxSAVE | wxOVERWRITE_PROMPT);
480                         if (saveFileDialog->ShowModal() == wxID_OK)
481                         {
482                                 wxString fileName = saveFileDialog->GetPath();
483                                 
484                                 ofstream file;
485                                 file.open( (const char*) (fileName.mb_str()) );
486
487                                 std::string content="";
488                                 
489                                 // writing file header
490                                 content += "# ----------------------------------\n";
491                                 content += "# - BBTKGEditor v 1.1 BBS BlackBox Script (Complex Box)\n";
492                                 content += "# ----------------------------------\n";
493                                 content += "\n";
494                                 content += _tabsMgr->getActualComplexBoxBBS(cbName);
495                                 file << content;
496                                 file.close();
497                         }
498                 }
499
500         }
501
502         //=========================================================================
503
504         void wxGUIEditorGraphicBBS::OnSaveActualDiagram(wxCommandEvent& event)
505         {
506                 wxFileDialog * saveFileDialog = new wxFileDialog(this,wxT("Save  actual diagram"),wxEmptyString,wxT("NewDiagram"),wxT("*.bbg"),wxSAVE|wxOVERWRITE_PROMPT);
507                 if (saveFileDialog->ShowModal() == wxID_OK)
508                 {
509                         wxString fileName = saveFileDialog->GetPath();
510                         
511                         ofstream file;
512                         file.open( (const char*) (fileName.mb_str()) );
513
514                         std::string content="";
515                         
516                         // writing file header
517                         content += "# ----------------------------------\n";
518                         content += "# - BBTKGEditor v 1.0 BBG BlackBox Diagram file\n";
519                         content += "# - ";
520
521                         content += (const char*) (fileName.mb_str());
522
523                         content += "\n";
524                         content += "# ----------------------------------\n";
525                         content += "\n";
526                         content += "APP_START\n";
527                         _tabsMgr->saveActualDiagram(content);           
528                         content += "APP_END\n";
529                         file << content;
530                         file.close();
531                 }
532
533         }
534
535         //=========================================================================
536
537         void wxGUIEditorGraphicBBS::refreshGUIControls()
538         {
539                 wxToolBar* toolbar = GetToolBar();
540                 if(_tabsMgr->isActualDiagramComplexBox())
541                 {
542                         toolbar->ToggleTool(ID_BTNCOMPLEXBOX,true);
543                         toolbar->EnableTool(ID_ADDCOMPLEXBOXINPUT,true);
544                         toolbar->EnableTool(ID_ADDCOMPLEXBOXOUTPUT,true);
545                         
546                         GetMenuBar()->GetMenu(0)->Enable(ID_SAVE_AS_COMPLEXBOX,true);
547                         GetMenuBar()->GetMenu(0)->Enable(ID_SAVE_AS_BBS,false);
548                 }
549                 else
550                 {
551                         toolbar->ToggleTool(ID_BTNCOMPLEXBOX,false);
552                         toolbar->EnableTool(ID_ADDCOMPLEXBOXINPUT,false);
553                         toolbar->EnableTool(ID_ADDCOMPLEXBOXOUTPUT,false);
554
555                         GetMenuBar()->GetMenu(0)->Enable(ID_SAVE_AS_COMPLEXBOX,false);
556                         GetMenuBar()->GetMenu(0)->Enable(ID_SAVE_AS_BBS,true);
557                 }
558                 
559                 if(_tabsMgr->getNumActualSelectedObjects()>0)
560                 {
561                         GetMenuBar()->GetMenu(1)->Enable(ID_COPY_TO_COMPLEXDIAGRAM,true);
562                 }
563                 else
564                 {
565                         ///TODO Fix the possibility to say from the SceneManager to the GUI to refresh the options
566                         GetMenuBar()->GetMenu(1)->Enable(ID_COPY_TO_COMPLEXDIAGRAM,true);
567                 }
568
569         }
570
571         //=========================================================================
572
573         void wxGUIEditorGraphicBBS::OnDeleteAllBoxesActualDiagram(wxCommandEvent& event)
574         {
575                 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);
576                 if(dial->ShowModal() == wxID_YES)
577                 {
578                         _tabsMgr->deleteAllBoxesActualDiagram();
579                 }
580         }
581
582         //=========================================================================
583
584         void wxGUIEditorGraphicBBS::OnCenterViewActualDiagram(wxCommandEvent& event)
585         {
586                 _tabsMgr->centerViewActualDiagram();
587         }
588
589         //=========================================================================
590
591         
592         void wxGUIEditorGraphicBBS::OnOpenDiagram(wxCommandEvent& event)
593         {
594                 wxFileDialog * openFileDialog = new wxFileDialog(this,wxT("Open diagram"),wxEmptyString,wxT(""),wxT("*.bbg"),wxOPEN|wxFILE_MUST_EXIST);
595                 if (openFileDialog->ShowModal() == wxID_OK)
596                 {
597                         wxString fileName = openFileDialog->GetPath();
598                         
599                         ifstream inputStream;
600
601 //EED                   inputStream.open(fileName.c_str());
602                         inputStream.open( (const char*) (fileName.mb_str()) );
603
604
605
606                         _tabsMgr->addNewTab();
607                         _tabsMgr->loadDiagram(inputStream);
608                         
609                         inputStream.close();
610                 }
611                 refreshGUIControls();
612         }
613
614         //=========================================================================
615
616         void wxGUIEditorGraphicBBS::OnClickBtnComplexBox(wxCommandEvent& event)
617         {
618                 wxToolBar* toolbar = GetToolBar();
619                 bool temp = toolbar->GetToolState(ID_BTNCOMPLEXBOX);
620                 if(temp)
621                 {
622                         _tabsMgr->setActualDiagramComplexBox(true);
623                 }
624                 else
625                 {
626                         _tabsMgr->setActualDiagramComplexBox(false);
627                 }
628                 refreshGUIControls();           
629         }
630
631         //=========================================================================
632
633         void wxGUIEditorGraphicBBS::OnAddComplexBoxInput(wxCommandEvent& event)
634         {               
635                 wxTextEntryDialog *nameDialog = new wxTextEntryDialog(this,wxT("Name of input port"));
636                 if (nameDialog->ShowModal() == wxID_OK)
637                 {
638                         wxString fileName = nameDialog->GetValue();
639                         if(!fileName.IsEmpty())
640                         {
641                                 std::string portName=(const char*) (fileName.mb_str());
642                                 _tabsMgr->addActualDiagramComplexInputPort(portName);
643                         }
644                 }               
645         }
646
647         //=========================================================================
648
649         void wxGUIEditorGraphicBBS::OnAddComplexBoxOutput(wxCommandEvent& event)
650         {
651                 wxTextEntryDialog *nameDialog = new wxTextEntryDialog(this,wxT("Name of output port"));
652                 if (nameDialog->ShowModal() == wxID_OK)
653                 {
654                         wxString fileName = nameDialog->GetValue();
655                         if(!fileName.IsEmpty())
656                         {
657                                 std::string portName=(const char*) (fileName.mb_str());
658                                 _tabsMgr->addActualDiagramComplexOutputPort(portName);
659                         }
660                 }       
661         }
662
663         //=========================================================================
664
665         void wxGUIEditorGraphicBBS::OnCopySelectedToComplexDiagram(wxCommandEvent& event)
666         {
667                 _tabsMgr->copySelectedBBoxesToComplexDiagram();
668         }
669
670         //=========================================================================
671
672         void wxGUIEditorGraphicBBS::OnExit(wxCommandEvent& event)
673         {
674                 Close(true);
675         }
676
677         //=========================================================================
678
679 }  // EO namespace bbtk
680
681 // EOF
682