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