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