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