]> Creatis software - bbtkGEditor.git/blob - lib/EditorGraphicBBS/bbsWxGUIEditorGraphic/bbtkwxGUIEditorGraphicBBS.cxx
*** empty log 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                 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::editDiagramParameters(wxVtkSceneManager* scene)
332         {
333                 wxBlackBoxEditionDialog* dialog = new wxBlackBoxEditionDialog(this,scene);
334                 dialog->Show();
335         }
336
337         //=========================================================================
338
339         void wxGUIEditorGraphicBBS::updateStatusBar(std::string textStatus)
340         {
341                 SetStatusText(crea::std2wx(textStatus));
342         }
343
344         //=========================================================================
345
346         void wxGUIEditorGraphicBBS::executeScript(std::string script)
347         {
348                 std::string separator = ConfigurationFile::GetInstance().Get_file_separator ();
349                 std::string dir = ConfigurationFile::GetInstance().Get_default_temp_dir();
350                 std::string filename = dir + separator + "tmp_bbtk.bbs";
351                 
352                 ofstream tempFile;
353                 tempFile.open(filename.c_str());
354                 tempFile << script;
355                 tempFile.close();
356                 
357                 std::string command = "\"";
358
359                 #ifdef WIN32
360                         command += "\"";
361                 #endif
362
363                 //command += ConfigurationFile::GetInstance().Get_bin_path();
364 //EED           command +="C:/temp/bbtkBIN/RelWithDebInfo//";
365 //EED           command +="C:/Program Files/CreaTools/bbtk-0.9.5/bin";
366                 command +=".";
367
368
369                 #ifdef MACOSX
370                         command += separator + "bbi.app/Contents/MacOS/bbi\" ";
371                 #else 
372                         command += separator + "bbi\" ";
373                 #endif
374                 command += "\""+filename + "\"";
375
376                 #ifdef WIN32
377                         command += "\"";
378                 #endif
379
380                 command += " & ";
381                   
382                 printf ("RaC wxGUIEditorGraphicBBS::executeScript %s \n" , command.c_str() );
383                 system( command.c_str() );
384         }
385
386         //=========================================================================
387         // EVENT HANDLERS 
388         //=========================================================================
389
390         void wxGUIEditorGraphicBBS::OnCreateNewTab(wxCommandEvent& event)
391         {
392                 _tabsMgr->addNewTab();  
393                 refreshGUIControls();
394         }
395
396         //=========================================================================
397
398         void wxGUIEditorGraphicBBS::OnExecuteActualDiagram(wxCommandEvent& event)
399         {
400                 std::string script = _tabsMgr->getActualDiagramBBS();
401                 cout<<"RaC wxGUIEditorGraphicBBS::executeActualDiagram SCRIPT"<<endl;
402                 cout<<script<<endl;
403
404                 executeScript(script);          
405         }
406
407         //=========================================================================
408         // HANDLERS 
409         //=========================================================================
410
411         void wxGUIEditorGraphicBBS::OnSaveActualBBS(wxCommandEvent& event)
412         {
413                 wxFileDialog * saveFileDialog = new wxFileDialog(this,wxT("Save  actual BBS"),wxEmptyString,wxT("NewBBS"),wxT("*.bbs"),wxSAVE|wxOVERWRITE_PROMPT);
414                 if (saveFileDialog->ShowModal() == wxID_OK)
415                 {
416                         wxString fileName = saveFileDialog->GetPath();
417                         
418                         ofstream file;
419
420 //EED                   file.open(fileName.c_str()); 
421                         file.open( (const char*) (fileName.mb_str()) );
422
423                         std::string content="";
424                         
425                         // writing file header
426                         content += "# ----------------------------------\n";
427                         content += "# - BBTKGEditor v 1.0 BBS BlackBox Script\n";
428                         content += "# ----------------------------------\n";
429                         content += "\n";
430                         content += _tabsMgr->getActualDiagramBBS();
431                         file << content;
432                         file.close();
433                 }
434
435         }
436
437         //=========================================================================
438
439         void wxGUIEditorGraphicBBS::OnSaveActualComplexBox(wxCommandEvent& event)
440         {
441                 wxTextEntryDialog *nameDialog = new wxTextEntryDialog(this,wxT("Name of complex box"));
442                 std::string cbName="";
443                 if (nameDialog->ShowModal() == wxID_OK)
444                 {
445                         wxString fileName = nameDialog->GetValue();
446 //EED                   cbName=fileName;
447                         cbName=(const char*) (fileName.mb_str());
448                 }               
449
450                 if(!cbName.empty())
451                 {       
452                         wxFileDialog * saveFileDialog = new wxFileDialog( this , _T("Save Complex Box BBS") ,_T(""), wxString( cbName.c_str(), wxConvUTF8),_T(""), wxSAVE | wxOVERWRITE_PROMPT);
453                         if (saveFileDialog->ShowModal() == wxID_OK)
454                         {
455                                 wxString fileName = saveFileDialog->GetPath();
456                                 
457                                 ofstream file;
458 //EED                           file.open(fileName.c_str());
459                                 file.open( (const char*) (fileName.mb_str()) );
460
461                                 std::string content="";
462                                 
463                                 // writing file header
464                                 content += "# ----------------------------------\n";
465                                 content += "# - BBTKGEditor v 1.1 BBS BlackBox Script (Complex Box)\n";
466                                 content += "# ----------------------------------\n";
467                                 content += "\n";
468                                 content += _tabsMgr->getActualComplexBoxBBS(cbName);
469                                 file << content;
470                                 file.close();
471                         }
472                 }
473
474         }
475
476         //=========================================================================
477
478         void wxGUIEditorGraphicBBS::OnSaveActualDiagram(wxCommandEvent& event)
479         {
480                 wxFileDialog * saveFileDialog = new wxFileDialog(this,wxT("Save  actual diagram"),wxEmptyString,wxT("NewDiagram"),wxT("*.bbg"),wxSAVE|wxOVERWRITE_PROMPT);
481                 if (saveFileDialog->ShowModal() == wxID_OK)
482                 {
483                         wxString fileName = saveFileDialog->GetPath();
484                         
485                         ofstream file;
486 //EED                   file.open(fileName.c_str());
487                         file.open( (const char*) (fileName.mb_str()) );
488
489                         std::string content="";
490                         
491                         // writing file header
492                         content += "# ----------------------------------\n";
493                         content += "# - BBTKGEditor v 1.0 BBG BlackBox Diagram file\n";
494                         content += "# - ";
495
496 //EED                   content += fileName;
497                         content += (const char*) (fileName.mb_str());
498
499                         content += "\n";
500                         content += "# ----------------------------------\n";
501                         content += "\n";
502                         content += "APP_START\n";
503                         _tabsMgr->saveActualDiagram(content);           
504                         content += "APP_END\n";
505                         file << content;
506                         file.close();
507                 }
508
509         }
510
511         //=========================================================================
512
513         void wxGUIEditorGraphicBBS::refreshGUIControls()
514         {
515                 wxToolBar* toolbar = GetToolBar();
516                 if(_tabsMgr->isActualDiagramComplexBox())
517                 {
518                         toolbar->ToggleTool(ID_BTNCOMPLEXBOX,true);
519                         toolbar->EnableTool(ID_ADDCOMPLEXBOXINPUT,true);
520                         toolbar->EnableTool(ID_ADDCOMPLEXBOXOUTPUT,true);
521                         
522                         GetMenuBar()->GetMenu(0)->Enable(ID_SAVE_AS_COMPLEXBOX,true);
523                         GetMenuBar()->GetMenu(0)->Enable(ID_SAVE_AS_BBS,false);
524                 }
525                 else
526                 {
527                         toolbar->ToggleTool(ID_BTNCOMPLEXBOX,false);
528                         toolbar->EnableTool(ID_ADDCOMPLEXBOXINPUT,false);
529                         toolbar->EnableTool(ID_ADDCOMPLEXBOXOUTPUT,false);
530
531                         GetMenuBar()->GetMenu(0)->Enable(ID_SAVE_AS_COMPLEXBOX,false);
532                         GetMenuBar()->GetMenu(0)->Enable(ID_SAVE_AS_BBS,true);
533                 }
534                 
535                 if(_tabsMgr->getNumActualSelectedObjects()>0)
536                 {
537                         GetMenuBar()->GetMenu(1)->Enable(ID_COPY_TO_COMPLEXDIAGRAM,true);
538                 }
539                 else
540                 {
541                         ///TODO Fix the possibility to say from the SceneManager to the GUI to refresh the options
542                         GetMenuBar()->GetMenu(1)->Enable(ID_COPY_TO_COMPLEXDIAGRAM,true);
543                 }
544
545         }
546
547         //=========================================================================
548
549         void wxGUIEditorGraphicBBS::OnDeleteAllBoxesActualDiagram(wxCommandEvent& event)
550         {
551                 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);
552                 if(dial->ShowModal() == wxID_YES)
553                 {
554                         _tabsMgr->deleteAllBoxesActualDiagram();
555                 }
556         }
557
558         //=========================================================================
559
560         void wxGUIEditorGraphicBBS::OnCenterViewActualDiagram(wxCommandEvent& event)
561         {
562                 _tabsMgr->centerViewActualDiagram();
563         }
564
565         //=========================================================================
566
567         
568         void wxGUIEditorGraphicBBS::OnOpenDiagram(wxCommandEvent& event)
569         {
570                 wxFileDialog * openFileDialog = new wxFileDialog(this,wxT("Open diagram"),wxEmptyString,wxT(""),wxT("*.bbg"),wxOPEN|wxFILE_MUST_EXIST);
571                 if (openFileDialog->ShowModal() == wxID_OK)
572                 {
573                         wxString fileName = openFileDialog->GetPath();
574                         
575                         ifstream inputStream;
576
577 //EED                   inputStream.open(fileName.c_str());
578                         inputStream.open( (const char*) (fileName.mb_str()) );
579
580
581
582                         _tabsMgr->addNewTab();
583                         _tabsMgr->loadDiagram(inputStream);
584                         
585                         inputStream.close();
586                 }
587                 refreshGUIControls();
588         }
589
590         //=========================================================================
591
592         void wxGUIEditorGraphicBBS::OnClickBtnComplexBox(wxCommandEvent& event)
593         {
594                 wxToolBar* toolbar = GetToolBar();
595                 bool temp = toolbar->GetToolState(ID_BTNCOMPLEXBOX);
596                 if(temp)
597                 {
598                         _tabsMgr->setActualDiagramComplexBox(true);
599                 }
600                 else
601                 {
602                         _tabsMgr->setActualDiagramComplexBox(false);
603                 }
604                 refreshGUIControls();           
605         }
606
607         //=========================================================================
608
609         void wxGUIEditorGraphicBBS::OnAddComplexBoxInput(wxCommandEvent& event)
610         {               
611                 wxTextEntryDialog *nameDialog = new wxTextEntryDialog(this,wxT("Name of input port"));
612                 if (nameDialog->ShowModal() == wxID_OK)
613                 {
614                         wxString fileName = nameDialog->GetValue();
615                         if(!fileName.IsEmpty())
616                         {
617                                 std::string portName=(const char*) (fileName.mb_str());
618                                 _tabsMgr->addActualDiagramComplexInputPort(portName);
619                         }
620                 }               
621         }
622
623         //=========================================================================
624
625         void wxGUIEditorGraphicBBS::OnAddComplexBoxOutput(wxCommandEvent& event)
626         {
627                 wxTextEntryDialog *nameDialog = new wxTextEntryDialog(this,wxT("Name of output port"));
628                 if (nameDialog->ShowModal() == wxID_OK)
629                 {
630                         wxString fileName = nameDialog->GetValue();
631                         if(!fileName.IsEmpty())
632                         {
633                                 std::string portName=(const char*) (fileName.mb_str());
634                                 _tabsMgr->addActualDiagramComplexOutputPort(portName);
635                         }
636                 }       
637         }
638
639         //=========================================================================
640
641         void wxGUIEditorGraphicBBS::OnCopySelectedToComplexDiagram(wxCommandEvent& event)
642         {
643                 _tabsMgr->copySelectedBBoxesToComplexDiagram();
644         }
645
646         //=========================================================================
647
648         void wxGUIEditorGraphicBBS::OnExit(wxCommandEvent& event)
649         {
650                 Close(true);
651         }
652
653         //=========================================================================
654
655 }  // EO namespace bbtk
656
657 // EOF
658