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