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