]> 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 #include "creaSystem.h"
39
40 #include <InterpreterBBS.h>
41
42 namespace bbtk
43 {
44
45
46         //=========================================================================
47         wxGUIEditorGraphicBBS::wxGUIEditorGraphicBBS(wxFrame *parent)
48                 : wxFrame(parent, -1, _T("bbtkGEditor"),wxDefaultPosition, wxSize(1200,800))
49         {
50
51                 _frameAUIMgr = new wxAuiManager(this);
52
53
54                 /*std::string datadir( crea::System::GetExecutablePath() );
55                 std::string datadir (".");
56                 cout<<"RaC //------------------"<<endl;
57                 cout<<"RaC //TODO wxGUIEditorGraphicBBS constructor.Initialize datadir with  crea::System::GetExecutablePath() ."<<endl;
58                 cout<<"RaC //------------------"<<endl;
59
60             #ifdef LINUX // assume this is OSX
61                    datadir=datadir+"/../share/creaContours";
62             #endif // MACOSX
63
64                 #ifdef MACOSX // assume this is OSX
65                         datadir=datadir+"/../../../../share/creaContours";
66                 #endif // MACOSX
67
68                 _dataDir = datadir;*/
69
70                 initMenu();
71                 initToolbar();
72                 initTabPanelsManager();
73                 initPackageBrowser();
74                 initHelpHTMLBrowser();
75
76                 CreateStatusBar();
77                 _frameAUIMgr->Update();
78                 _actualPkgBrowserBoxName="";
79                 _actualPkgBrowserPkgName="";
80                 refreshGUIControls();
81         }
82
83
84         //=========================================================================
85         wxGUIEditorGraphicBBS::~wxGUIEditorGraphicBBS()
86         {
87                 printf ("EED %p ~wxGUIEditorGraphicBBS()\n" , this );
88
89 //EED02JUIN2010         delete _tabsMgr;
90
91             _frameAUIMgr->UnInit();
92                 // FCY memory leaks
93                 delete _frameAUIMgr;
94                 delete _notebook;
95                 delete _tabsMgr;
96
97
98         }
99
100         //=========================================================================
101         void wxGUIEditorGraphicBBS::initToolbar()
102         {
103                 wxBitmap bmp_new(new_xpm);
104                 wxBitmap bmp_open(open_xpm);
105                 wxBitmap bmp_save(save_xpm);
106                 wxBitmap bmp_run(run_xpm);
107                 wxBitmap bmp_delete(delete_xpm);
108                 wxBitmap bmp_centerview(centerview_xpm);
109                 wxBitmap bmp_box(box_xpm);
110                 wxBitmap bmp_executablebox(executablebox_xpm);
111                 wxBitmap bmp_complexbox(complexbox_xpm);
112                 wxBitmap bmp_complexinputport(complexinputport_xpm);
113                 wxBitmap bmp_complexoutputport(complexoutputport_xpm);
114
115                 wxToolBar  *toolbar = new wxToolBar(this, wxID_ANY);
116
117                 //Adds a tool btn to the toolbar
118                 toolbar->AddTool(ID_NEW,_T("New"),bmp_new, wxNullBitmap, wxITEM_NORMAL,_T("New tab"), _T("Create a new panel tab"));
119                 toolbar->AddTool(ID_OPEN,_T("Open diagram"),bmp_open, wxNullBitmap, wxITEM_NORMAL,_T("Open a diagram"), _T("Open a diagram"));
120                 toolbar->AddTool(ID_SAVE_DIAGRAM,_T("Save Diagram"),bmp_save, wxNullBitmap, wxITEM_NORMAL,_T("Saves the current diagram"), _T("Saves the current diagram")); //DFCH
121                 //toolbar->AddTool(ID_SAVE_AS_DIAGRAM,_T("Save Diagram As"),bmp_save, wxNullBitmap, wxITEM_NORMAL,_T("Saves the current diagram"), _T("Saves the current diagram")); //DFCH
122                 toolbar->AddTool(ID_RUN,_T("Run"),bmp_run, wxNullBitmap, wxITEM_NORMAL,_T("Execute actual diagram"), _T("Execute actual diagram"));
123                 toolbar->AddTool(ID_DELETEALL,_T("Delete all"),bmp_delete, wxNullBitmap, wxITEM_NORMAL,_T("Delete all boxes"), _T("Delete all boxes"));
124                 toolbar->AddTool(ID_CENTERVIEW,_T("Center view"),bmp_centerview, wxNullBitmap, wxITEM_NORMAL,_T("Center view"), _T("Center view"));
125                 toolbar->AddSeparator();
126                 toolbar->AddTool(ID_BTNBOX,_T("New Box"),bmp_box, wxNullBitmap, wxITEM_NORMAL,_T("New Box"), _T("Nex Box"));
127                 toolbar->AddSeparator();
128                 toolbar->AddTool(ID_BTEXECUTABLEBOX,_T("Select as executable Box"),bmp_executablebox, wxNullBitmap, wxITEM_NORMAL,_T("Select as executable Box"), _T("Select as executable Box"));
129                 toolbar->AddSeparator();
130                 toolbar->AddTool(ID_BTNCOMPLEXBOX,_T("Complex box"),complexbox_xpm, wxNullBitmap, wxITEM_NORMAL,_T("Complex box"), _T("Complex box"));
131                 toolbar->SetToggle(ID_BTNCOMPLEXBOX,true);
132                 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"));
133                 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"));
134                 toolbar->EnableTool(ID_ADDCOMPLEXBOXINPUT,false);
135                 toolbar->EnableTool(ID_ADDCOMPLEXBOXOUTPUT,false);
136
137                 toolbar->SetMargins( 2, 2 );
138                 toolbar->Realize();
139                 SetToolBar(toolbar);
140
141                 // connect command event handlers
142                 Connect(ID_NEW,wxEVT_COMMAND_TOOL_CLICKED,wxCommandEventHandler(wxGUIEditorGraphicBBS::OnCreateNewTab));
143                 Connect(ID_OPEN,wxEVT_COMMAND_TOOL_CLICKED,wxCommandEventHandler(wxGUIEditorGraphicBBS::OnOpenDiagram));
144                 Connect(ID_SAVE_DIAGRAM,wxEVT_COMMAND_TOOL_CLICKED,wxCommandEventHandler(wxGUIEditorGraphicBBS::OnSaveActualDiagram)); //DFCH
145                 Connect(ID_SAVE_AS_DIAGRAM,wxEVT_COMMAND_TOOL_CLICKED,wxCommandEventHandler(wxGUIEditorGraphicBBS::OnSaveAsActualDiagram)); //DFCH
146                 Connect(ID_RUN,wxEVT_COMMAND_TOOL_CLICKED,wxCommandEventHandler(wxGUIEditorGraphicBBS::OnExecuteActualDiagram));
147                 Connect(ID_DELETEALL,wxEVT_COMMAND_TOOL_CLICKED,wxCommandEventHandler(wxGUIEditorGraphicBBS::OnDeleteAllBoxesActualDiagram));
148                 Connect(ID_CENTERVIEW,wxEVT_COMMAND_TOOL_CLICKED,wxCommandEventHandler(wxGUIEditorGraphicBBS::OnCenterViewActualDiagram));
149                 Connect(ID_BTNBOX,wxEVT_COMMAND_TOOL_CLICKED,wxCommandEventHandler(wxGUIEditorGraphicBBS::OnClickBtnBox));
150                 Connect(ID_BTEXECUTABLEBOX,wxEVT_COMMAND_TOOL_CLICKED,wxCommandEventHandler(wxGUIEditorGraphicBBS::OnClickBtnExecutableBox));
151                 Connect(ID_BTNCOMPLEXBOX,wxEVT_COMMAND_TOOL_CLICKED,wxCommandEventHandler(wxGUIEditorGraphicBBS::OnClickBtnComplexBox));
152                 Connect(ID_ADDCOMPLEXBOXINPUT,wxEVT_COMMAND_TOOL_CLICKED,wxCommandEventHandler(wxGUIEditorGraphicBBS::OnAddComplexBoxInput));
153                 Connect(ID_ADDCOMPLEXBOXOUTPUT,wxEVT_COMMAND_TOOL_CLICKED,wxCommandEventHandler(wxGUIEditorGraphicBBS::OnAddComplexBoxOutput));
154
155         }
156         //=========================================================================
157         void wxGUIEditorGraphicBBS::initHelpHTMLBrowser()
158         {
159                 //TO FIX THE PATH OF BBTK BIN  IN ORDER TO USE REGENERATE EXECUTABLES
160                 //RegenerateAll();
161                 _helpHtmlBrowser = new WxGUIHtmlBrowser(this,wxSize(200,0));
162                 _frameAUIMgr->AddPane(_helpHtmlBrowser,wxAuiPaneInfo().Right().MinSize(200,200));
163         }
164
165         //=========================================================================
166         void wxGUIEditorGraphicBBS::initMenu()
167         {
168                 // Create File menu and its items
169                 wxMenu *fileMenu = new wxMenu();
170                 fileMenu->Append(ID_NEW, _T("New diagram"), _T("New"));
171                 fileMenu->Append(ID_SAVE_DIAGRAM, _T("Save Diagram"), _T("Save Diagram")); //DFCH
172                 fileMenu->Append(ID_SAVE_AS_DIAGRAM, _T("Save Diagram As"), _T("Save Diagram As")); //DFCH
173                 fileMenu->Append(ID_OPEN_BBS, _T("Open BBS"), _T("Open BBS"));
174                 fileMenu->Append(ID_SAVE_AS_BBS, _T("Save BBS"), _T("Save BBS"));
175                 fileMenu->Append(ID_SAVE_AS_COMPLEXBOX, _T("Save complex box"), _T("Save complex box"));
176                 fileMenu->Append(wxID_EXIT, _T("E&xit"), _T("Exit"));
177
178                 Connect(ID_NEW,wxEVT_COMMAND_MENU_SELECTED,wxCommandEventHandler(wxGUIEditorGraphicBBS::OnCreateNewTab));
179                 Connect(ID_SAVE_DIAGRAM,wxEVT_COMMAND_MENU_SELECTED,wxCommandEventHandler(wxGUIEditorGraphicBBS::OnSaveActualDiagram)); //DFCH
180                 Connect(ID_SAVE_AS_DIAGRAM,wxEVT_COMMAND_MENU_SELECTED,wxCommandEventHandler(wxGUIEditorGraphicBBS::OnSaveAsActualDiagram));
181                 Connect(ID_OPEN_BBS,wxEVT_COMMAND_MENU_SELECTED,wxCommandEventHandler(wxGUIEditorGraphicBBS::OnOpenBBS));
182                 Connect(ID_SAVE_AS_BBS,wxEVT_COMMAND_MENU_SELECTED,wxCommandEventHandler(wxGUIEditorGraphicBBS::OnSaveActualBBS));
183                 Connect(ID_SAVE_AS_COMPLEXBOX,wxEVT_COMMAND_MENU_SELECTED,wxCommandEventHandler(wxGUIEditorGraphicBBS::OnSaveActualComplexBox));
184                 Connect(wxID_EXIT,wxEVT_COMMAND_MENU_SELECTED,wxCommandEventHandler(wxGUIEditorGraphicBBS::OnExit));
185
186                 // Create Help menu and its items
187                 wxMenu *editMenu = new wxMenu;
188                 editMenu->Append(ID_COPY_TO_COMPLEXDIAGRAM, _T("Copy selected to complex box"), _T("Creates a new complex box diagram with selected boxes"));
189
190                 Connect(ID_COPY_TO_COMPLEXDIAGRAM,wxEVT_COMMAND_MENU_SELECTED,wxCommandEventHandler(wxGUIEditorGraphicBBS::OnCopySelectedToComplexDiagram));
191
192                 // Create Help menu and its items
193                 wxMenu *helpMenu = new wxMenu;
194                 helpMenu->Append(wxID_ABOUT, _T("&About..."), _T("About"));
195                 helpMenu->Append(ID_HELP_BBEDITOR, _T("&Help..."), _T("Help"));
196                 Connect(ID_HELP_BBEDITOR,wxEVT_COMMAND_MENU_SELECTED,wxCommandEventHandler(wxGUIEditorGraphicBBS::OnHelpBBeditor));
197
198                 // Create Tool menu
199                 wxMenu *menuTools = new wxMenu;
200                 menuTools->Append( ID_bbEditor_Tool_Menu_CreatePackage, _T("Create &package") );
201                 menuTools->Append( ID_bbEditor_Tool_Menu_CreateBlackBox, _T("Create &blackbox") );
202                 menuTools->Append( ID_bbEditor_Tool_Menu_PlugPackage, _T("Plug package") );
203                 menuTools->Append( ID_bbEditor_Tool_Menu_EditConfig, _T("&Edit bbtk config") );
204                 menuTools->Append( ID_bbEditor_Tool_Menu_ShowHTMLDoc, _T("Show &HTML documentation") );
205                 menuTools->Append( ID_bbEditor_Tool_Menu_CreateIndex, _T("&Generate index") );
206                 
207                 Connect(ID_bbEditor_Tool_Menu_CreatePackage,wxEVT_COMMAND_MENU_SELECTED,wxCommandEventHandler(wxGUIEditorGraphicBBS::OnCreatePackage));
208                 Connect(ID_bbEditor_Tool_Menu_CreateBlackBox,wxEVT_COMMAND_MENU_SELECTED,wxCommandEventHandler(wxGUIEditorGraphicBBS::OnCreateBlackBox));
209                 Connect(ID_bbEditor_Tool_Menu_PlugPackage,wxEVT_COMMAND_MENU_SELECTED,wxCommandEventHandler(wxGUIEditorGraphicBBS::OnPlugPackage));
210                 Connect(ID_bbEditor_Tool_Menu_EditConfig,wxEVT_COMMAND_MENU_SELECTED,wxCommandEventHandler(wxGUIEditorGraphicBBS::OnEditConfig));
211                 Connect(ID_bbEditor_Tool_Menu_ShowHTMLDoc,wxEVT_COMMAND_MENU_SELECTED,wxCommandEventHandler(wxGUIEditorGraphicBBS::OnShowHTMLDoc));
212                 Connect(ID_bbEditor_Tool_Menu_CreateIndex,wxEVT_COMMAND_MENU_SELECTED,wxCommandEventHandler(wxGUIEditorGraphicBBS::OnCreateIndex));
213                 
214                 // Append the created menu to the menu bar
215                 wxMenuBar *menuBar = new wxMenuBar();
216                 menuBar->Append( fileMenu,      _T("&File") );
217                 menuBar->Append( editMenu,      _T("&Edit") );
218                 menuBar->Append( menuTools,     _T("&Tool") );
219                 menuBar->Append( helpMenu,      _T("&Help") );
220
221                 // Attach this menu bar to the frame
222                 SetMenuBar(menuBar);
223         }
224
225         //=========================================================================
226         void wxGUIEditorGraphicBBS::initTabPanelsManager()
227         {
228                 _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);
229                 _tabsMgr = new wxTabPanelsManager(this);
230                 _frameAUIMgr->AddPane(_notebook,wxAuiPaneInfo().CenterPane());
231
232         }
233
234         //=========================================================================
235         void wxGUIEditorGraphicBBS::initPackageBrowser()
236         {
237                 _pkgBrowser = new WxGUIPackageBrowser2(this);
238                 _pkgBrowser->IncludeAll();
239                 _frameAUIMgr->AddPane(_pkgBrowser,wxAuiPaneInfo().Left().MinSize(200,200).CloseButton(false));
240         }
241
242         //================================================================
243
244         void wxGUIEditorGraphicBBS::DoRegeneratePackageDoc( const std::string& pack )
245         {
246                 std::string mess("Regenerating doc for package '");
247                 if (pack!="-a"){
248                         mess += pack + "'";
249                 }
250                 else
251                 {
252                         mess = "Regenerating doc for all packages";
253                 }
254
255                 mess += " ... please wait";
256
257                 SetStatusText( std2wx(mess) );
258
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 += "bbRegeneratePackageDoc";
268                 #if defined(WIN32)
269                         command += "\"";
270                 #endif
271
272                 command += " " + pack + " -q";
273             bbtkMessage("debug",1,"Executing system command '"<<command<<"'"<<std::endl);
274
275                 if ( ! system ( command.c_str() ) )
276                 {
277                         SetStatusText( _T("Done !"));
278                         /*
279                         wxMessageBox(_T("Done !"),_T("Regenerate package '")
280                                          +std2wx(pack)+_T("' doc"),
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 package doc"),wxOK | wxICON_ERROR);
290             }
291         }
292
293         //================================================================
294         void wxGUIEditorGraphicBBS::DoRegenerateBoxesLists()
295         {
296                 SetStatusText( _T("Regenerating boxes lists ... please wait") );
297                 //BBTK_BUSY_CURSOR ;
298
299                 std::string command;
300                 #if defined(WIN32)
301                         command = "\"";
302                 #endif
303                         command += ConfigurationFile::GetInstance().Get_bin_path();
304                         command += ConfigurationFile::GetInstance().Get_file_separator();
305                         command += "bbRegenerateBoxesLists";
306
307                 #if defined(WIN32)
308                         command += "\"";
309                 #endif
310                         command += " -q";
311
312                 bbtkMessage("debug",1,"Executing system command '"<<command<<"'"<<std::endl);
313
314                 if ( ! system ( command.c_str() ) )
315                 {
316                         SetStatusText( _T("Done !"));
317                         /*
318                         wxMessageBox(_T("Done !"),_T("Regenerate boxes lists"),
319                                          wxOK | wxICON_INFORMATION);
320                         */
321                 }
322                 else
323                 {
324                         SetStatusText( _T("Done !"));
325                         wxString err(_T("An error occured while running '"));
326                         err +=  bbtk::std2wx(command) + _T("'");
327                         wxMessageBox(err,_T("Regenerate boxes lists"),wxOK | wxICON_ERROR);
328                 }
329         }
330
331   //================================================================
332         void wxGUIEditorGraphicBBS::RegenerateAll()
333         {
334                 DoRegeneratePackageDoc("-a");
335                 DoRegenerateBoxesLists();
336         }
337
338         //================================================================
339
340         wxAuiNotebook* wxGUIEditorGraphicBBS::getAuiNotebook()
341         {
342                 return _notebook;
343         }
344
345         //================================================================
346
347         void wxGUIEditorGraphicBBS::displayBlackBoxInfo(std::string packageName, std::string boxName)
348         {
349                 if(_actualPkgBrowserPkgName != packageName || _actualPkgBrowserBoxName != boxName )
350                 {
351                         _actualPkgBrowserPkgName = packageName;
352                         _actualPkgBrowserBoxName = boxName;
353
354                         BlackBoxDescriptor::Pointer descriptor = GObjectsMVCFactory::getInstance()->getBlackBoxDescriptor(packageName, boxName);
355                         _pkgBrowser->WxGUIBlackBoxListUserOnSelected(descriptor.get());
356                 }
357         }
358
359         //=========================================================================
360
361         void wxGUIEditorGraphicBBS::editBlackBox(GBlackBoxModel *bbmodel)
362         {
363                 wxBlackBoxEditionDialog* dialog = new wxBlackBoxEditionDialog(this,bbmodel);
364                 dialog->Show();
365         }
366
367         //=========================================================================
368
369         void wxGUIEditorGraphicBBS::updateStatusBar(std::string textStatus)
370         {
371                 SetStatusText(crea::std2wx(textStatus));
372         }
373
374         //=========================================================================
375
376         void wxGUIEditorGraphicBBS::executeScript(std::string script)
377         {
378                 std::string separator   = ConfigurationFile::GetInstance().Get_file_separator ();
379                 std::string dir                 = ConfigurationFile::GetInstance().Get_default_temp_dir();
380                 std::string filename    = dir + separator + "tmp_bbtk.bbs";
381
382                 ofstream tempFile;
383                 tempFile.open(filename.c_str());
384                 tempFile << script;
385                 tempFile.close();
386
387                 std::string command = "";
388                 
389 #ifdef WIN32
390                 command += "start /b ";
391 #endif
392                 
393                 
394 //              command += "\""+ crea::System::GetExecutablePath();
395 //#ifdef MACOSX
396 //              command += separator + "../../../bbi.app/Contents/MacOS";
397 //#endif
398
399
400                 /*
401
402                 //command += ConfigurationFile::GetInstance().Get_bin_path();
403 //EED           command +="C:/temp/bbtkBIN/RelWithDebInfo//";
404 //EED           command +="C:/Program Files/CreaTools/bbtk-0.9.5/bin";
405
406
407                 #ifdef MACOSX
408                         command += separator + "usr/local/bin/bbi.app/Contents/MacOS/bbi\" ";
409                 #else
410                     command +=".";
411                         command += separator + "bbi\" ";
412                 #endif
413  */
414                 
415 //#ifndef WIN32
416 //              command += separator;
417 //#endif
418                 
419                 
420                 command +=  "bbi ";
421                 command += "\""+filename + "\"";
422                 
423 //              #ifdef WIN32
424 //                      command += "\"";
425 //              #endif
426
427         #ifndef WIN32
428             command += " & ";
429                 #endif
430
431                 printf ("RaC wxGUIEditorGraphicBBS::executeScript %s \n" , command.c_str() );
432                 system( command.c_str() );
433         }
434
435         //=========================================================================
436         // EVENT HANDLERS
437         //=========================================================================
438
439         void wxGUIEditorGraphicBBS::OnCreateNewTab(wxCommandEvent& event)
440         {
441                 _tabsMgr->addNewTab();
442                 refreshGUIControls();
443         }
444
445         //=========================================================================
446
447         void wxGUIEditorGraphicBBS::OnExecuteActualDiagram(wxCommandEvent& event)
448         {
449                 std::string script1 = _tabsMgr->getActualDiagramBBS(true);
450                 cout<<endl<<"RaC wxGUIEditorGraphicBBS::executeActualDiagram SCRIPT"<<endl<<endl;
451                 cout<<script1<<endl;
452
453                 std::string script2 = _tabsMgr->getActualDiagramBBS(false);
454                 executeScript(script2);
455         }
456
457
458         //=========================================================================
459         // HANDLERS
460         //=========================================================================
461         void wxGUIEditorGraphicBBS::OnOpenBBS(wxCommandEvent& event)
462         {
463                 wxFileDialog * openFileDialog = new wxFileDialog(this,wxT("Open BBS"),wxEmptyString,wxT("NewBBS"),wxT("*.bbs"),wxOPEN);
464                 if (openFileDialog->ShowModal() == wxID_OK)
465                 {
466                         wxString fileName = openFileDialog->GetPath(  );
467
468
469                         _tabsMgr->addNewTab(  openFileDialog->GetFilename()  );
470
471                         bbtk::InterpreterBBS::Pointer I = bbtk::InterpreterBBS::New( this->_tabsMgr->getActualTabPanel()->getSceneManager() , _pkgBrowser->GetFactory());
472
473                         // We tell the interpreter to throw exceptions on error
474                         I->SetThrow(true);
475                         // Interpret the file supposed to define a box called 'Processing'
476                         I->InterpretFile( (const char*) (fileName.mb_str()) );
477                 }
478                 refreshGUIControls();
479         }
480
481
482
483     void wxGUIEditorGraphicBBS::SaveActualBBS(std::string filename)
484         {
485         ofstream file;
486
487 //EED           file.open(fileName.c_str());
488         file.open( filename.c_str() );
489         std::string content="";
490         // writing file header
491         content += "# ----------------------------------\n";
492         content += "# - BBTKGEditor v 1.2 BBS BlackBox Script\n";
493         content += "# - ";
494         content += filename;
495         content += "\n";
496         content += "# ----------------------------------\n";
497         content += "\n";
498         content += _tabsMgr->getActualDiagramBBS();
499         file << content;
500         file.close();
501         }
502
503
504         void wxGUIEditorGraphicBBS::OnSaveActualBBS(wxCommandEvent& event)
505         {
506                 wxFileDialog * saveFileDialog = new wxFileDialog(this,wxT("Save  actual BBS"),wxEmptyString,wxT("NewBBS"),wxT("*.bbs"),wxSAVE|wxOVERWRITE_PROMPT);
507                 if (saveFileDialog->ShowModal() == wxID_OK)
508                 {
509                         wxString fileName = saveFileDialog->GetPath(  );
510             SaveActualBBS( (const char*) (fileName.mb_str())  );
511                 }
512
513         }
514
515
516     void wxGUIEditorGraphicBBS::AskComplexBoxConfiguration()
517     {
518                 std::string cbName = _tabsMgr->GetCbName();
519                 std::string paName = _tabsMgr->GetCbPackageName();
520
521                 wxTextEntryDialog *cbNameDialog = new wxTextEntryDialog(this,wxT("Complex Box name"));
522                 wxTextEntryDialog *paNameDialog = new wxTextEntryDialog(this,wxT("Package name"));
523
524                 cbNameDialog->SetValue( wxString(cbName.c_str(),wxConvUTF8) );
525                 paNameDialog->SetValue( wxString(paName.c_str(),wxConvUTF8) );
526
527                 if (cbNameDialog->ShowModal() == wxID_OK)
528                 {
529                         wxString complexboxname = cbNameDialog->GetValue();
530                         cbName=(const char*) (complexboxname.mb_str());
531                 }
532
533
534                 if (paNameDialog->ShowModal() == wxID_OK)
535                 {
536                         wxString packagename = paNameDialog->GetValue();
537                         paName=(const char*) (packagename.mb_str());
538                 }
539
540         _tabsMgr->SetCbName(cbName);
541         _tabsMgr->SetCbPackageName(paName);
542     }
543
544         //=========================================================================
545
546         void wxGUIEditorGraphicBBS::SaveActualComplexBox(std::string filename)
547         {
548         ofstream file;
549         file.open( filename.c_str() );
550
551         std::string content="";
552
553         // writing file header
554         content += "# ----------------------------------\n";
555         content += "# - BBTKGEditor v 1.2 BBS BlackBox Script (Complex Box)\n";
556         content += "# - ";
557         content += filename;
558         content += "\n";
559         content += "# ----------------------------------\n";
560         content += "\n";
561         content += _tabsMgr->getActualComplexBoxBBS();
562         file << content;
563         file.close();
564         }
565
566         //=========================================================================
567
568         void wxGUIEditorGraphicBBS::OnSaveActualComplexBox(wxCommandEvent& event)
569         {
570         wxFileDialog * saveFileDialog = new wxFileDialog(this ,wxT("Save Complex Box BBS") ,wxEmptyString, _T("ComplexBoxName") ,wxT("*.bbs"), wxSAVE | wxOVERWRITE_PROMPT);
571         if (saveFileDialog->ShowModal() == wxID_OK)
572         {
573             wxString fileName = saveFileDialog->GetPath();
574             SaveActualComplexBox( (const char*) (fileName.mb_str()) );
575         }
576         }
577
578         //=========================================================================
579         void wxGUIEditorGraphicBBS::SaveActualDiagram(std::string filename)
580         {
581         ofstream file;
582         file.open( filename.c_str() );
583
584         std::string content="";
585
586         // writing file header
587         content += "# ----------------------------------\n";
588         content += "# - BBTKGEditor v 1.2 BBG BlackBox Diagram file\n";
589         content += "# - ";
590
591         content += filename;
592
593         content += "\n";
594         content += "# ----------------------------------\n";
595         content += "\n";
596         content += "APP_START\n";
597         _tabsMgr->saveActualDiagram(content, filename); //DFCH
598         content += "APP_END\n";
599         file << content;
600         file.close();
601     }
602
603         //=========================================================================
604         
605         //The following method allows to save the current diagram asking the filename
606         //DFCH
607         void wxGUIEditorGraphicBBS::SaveCurrentDiagramAs( )
608         {
609                 wxFileDialog * saveFileDialog = new wxFileDialog(this,wxT("Save current diagram"),wxEmptyString,wxT("NewDiagram"),wxT("*.bbg"),wxSAVE|wxOVERWRITE_PROMPT);
610                 if (saveFileDialog->ShowModal() == wxID_OK)
611                 {
612                         _tabsMgr->SetNameTabPanel( saveFileDialog->GetFilename() );
613                         wxString pathfileName       = saveFileDialog->GetPath();
614                         std::string pathfilename    = (const char*) (pathfileName.mb_str());
615             std::string pathfilenamebbs = pathfilename;
616             pathfilenamebbs[pathfilenamebbs.length()-1]='s';
617             if (_tabsMgr->isActualDiagramComplexBox()==false)
618             {
619                 SaveActualDiagram( pathfilename );
620                 SaveActualBBS(pathfilenamebbs);
621             } else {
622                 AskComplexBoxConfiguration();
623                 SaveActualDiagram( pathfilename );
624                 SaveActualComplexBox(pathfilenamebbs);
625             } //if isActualDiagramComplexBox
626                 } // if saveFileDialog
627         }
628         //=========================================================================
629         //DFCH
630         void wxGUIEditorGraphicBBS::OnSaveActualDiagram(wxCommandEvent& event)
631         {
632                 std::string pathfilename = _tabsMgr->GetCurrentTabPanelPath();
633                 if( pathfilename.empty() )
634                 {
635                         SaveCurrentDiagramAs();
636                 }
637                 else
638                 {
639                         std::string pathfilenamebbs = pathfilename;
640             pathfilenamebbs[pathfilenamebbs.length()-1]='s';
641
642             if (_tabsMgr->isActualDiagramComplexBox()==false)
643             {
644                 SaveActualDiagram( pathfilename );
645                 SaveActualBBS(pathfilenamebbs);
646             } else {
647                 AskComplexBoxConfiguration();
648                 SaveActualDiagram( pathfilename );
649                 SaveActualComplexBox(pathfilenamebbs);
650             } //if isActualDiagramComplexBox
651                 }               
652         }
653         //=========================================================================
654         //DFCH
655         void wxGUIEditorGraphicBBS::OnSaveAsActualDiagram(wxCommandEvent& event)
656         {
657                 SaveCurrentDiagramAs();
658         }
659         //=========================================================================
660
661         void wxGUIEditorGraphicBBS::refreshGUIControls()
662         {
663                 wxToolBar* toolbar = GetToolBar();
664                 if(_tabsMgr->isActualDiagramComplexBox())
665                 {
666                         toolbar->ToggleTool(ID_BTNCOMPLEXBOX,true);
667                         toolbar->EnableTool(ID_ADDCOMPLEXBOXINPUT,true);
668                         toolbar->EnableTool(ID_ADDCOMPLEXBOXOUTPUT,true);
669
670                         GetMenuBar()->GetMenu(0)->Enable(ID_SAVE_AS_COMPLEXBOX,true);
671                         GetMenuBar()->GetMenu(0)->Enable(ID_SAVE_AS_BBS,false);
672                 }
673                 else
674                 {
675                         toolbar->ToggleTool(ID_BTNCOMPLEXBOX,false);
676                         toolbar->EnableTool(ID_ADDCOMPLEXBOXINPUT,false);
677                         toolbar->EnableTool(ID_ADDCOMPLEXBOXOUTPUT,false);
678
679                         GetMenuBar()->GetMenu(0)->Enable(ID_SAVE_AS_COMPLEXBOX,false);
680                         GetMenuBar()->GetMenu(0)->Enable(ID_SAVE_AS_BBS,true);
681                 }
682
683                 if(_tabsMgr->getNumActualSelectedObjects()>0)
684                 {
685                         GetMenuBar()->GetMenu(1)->Enable(ID_COPY_TO_COMPLEXDIAGRAM,true);
686                 }
687                 else
688                 {
689                         ///TODO Fix the possibility to say from the SceneManager to the GUI to refresh the options
690                         GetMenuBar()->GetMenu(1)->Enable(ID_COPY_TO_COMPLEXDIAGRAM,true);
691                 }
692
693         }
694
695         //=========================================================================
696
697         void wxGUIEditorGraphicBBS::OnDeleteAllBoxesActualDiagram(wxCommandEvent& event)
698         {
699                 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);
700                 if(dial->ShowModal() == wxID_YES)
701                 {
702                         _tabsMgr->deleteAllBoxesActualDiagram();
703                 }
704         }
705
706         //=========================================================================
707
708         void wxGUIEditorGraphicBBS::OnCenterViewActualDiagram(wxCommandEvent& event)
709         {
710                 _tabsMgr->centerViewActualDiagram();
711         }
712
713         //=========================================================================
714
715         void wxGUIEditorGraphicBBS::OnOpenDiagram(wxCommandEvent& event)
716         {
717                 wxFileDialog * openFileDialog = new wxFileDialog(this,wxT("Open diagram"),wxEmptyString,wxT(""),wxT("*.bbg"),wxOPEN|wxFILE_MUST_EXIST);
718                 if (openFileDialog->ShowModal() == wxID_OK)
719                 {
720                         wxString fileName = openFileDialog->GetPath();
721                         ifstream inputStream;
722                         std::string fName=(const char*) (fileName.mb_str());
723                         inputStream.open( fName.c_str() );
724                         _tabsMgr->addNewTab( openFileDialog->GetFilename() );
725
726                         _tabsMgr->loadDiagram(inputStream, fName);
727
728                         inputStream.close();
729                 }
730                 refreshGUIControls();
731         }
732
733         //=========================================================================
734
735
736         void wxGUIEditorGraphicBBS::OnClickBtnBox(wxCommandEvent& event)
737         {
738                 BlackBoxDescriptor      *bbDes = _pkgBrowser->GetActualSelected();
739         if (bbDes!=NULL)
740         {
741             std::string                 typeName        = bbDes->GetTypeName();
742             std::string                 packageName = bbDes->GetPackage()->GetName();
743
744
745             wxGEditorTabPanel *pnl = this->_tabsMgr->getActualTabPanel();
746
747             if (pnl!=NULL)
748             {
749                 wxVtkSceneManager *scn = pnl->getSceneManager();
750                 scn->createGBlackBox(50,50,packageName, typeName);
751                 scn->refresh();
752             } // if pnl
753         }// if bbDes
754         }
755
756         //=========================================================================
757
758         void wxGUIEditorGraphicBBS::OnClickBtnExecutableBox(wxCommandEvent& event)
759         {
760                 printf("EED  wxGUIEditorGraphicBBS::OnClickBtnExecutableBox  .... not implemented ...\n");
761         }
762         
763         //=========================================================================
764
765         void wxGUIEditorGraphicBBS::OnClickBtnComplexBox(wxCommandEvent& event)
766         {
767                 wxToolBar* toolbar = GetToolBar();
768                 bool temp = toolbar->GetToolState(ID_BTNCOMPLEXBOX);
769                 if(temp)
770                 {
771                         _tabsMgr->setActualDiagramComplexBox(true);
772                 }
773                 else
774                 {
775                         _tabsMgr->setActualDiagramComplexBox(false);
776                 }
777                 refreshGUIControls();
778         }
779
780         //=========================================================================
781
782         void wxGUIEditorGraphicBBS::OnAddComplexBoxInput(wxCommandEvent& event)
783         {
784                 wxTextEntryDialog *nameDialog = new wxTextEntryDialog(this,wxT("Name of input port"));
785                 if (nameDialog->ShowModal() == wxID_OK)
786                 {
787                         wxString fileName = nameDialog->GetValue();
788                         if(!fileName.IsEmpty())
789                         {
790                                 std::string portName=(const char*) (fileName.mb_str());
791                                 _tabsMgr->addActualDiagramComplexInputPort(portName);
792                         }
793                 }
794         }
795
796         //=========================================================================
797
798         void wxGUIEditorGraphicBBS::OnAddComplexBoxOutput(wxCommandEvent& event)
799         {
800                 wxTextEntryDialog *nameDialog = new wxTextEntryDialog(this,wxT("Name of output port"));
801                 if (nameDialog->ShowModal() == wxID_OK)
802                 {
803                         wxString fileName = nameDialog->GetValue();
804                         if(!fileName.IsEmpty())
805                         {
806                                 std::string portName=(const char*) (fileName.mb_str());
807                                 _tabsMgr->addActualDiagramComplexOutputPort(portName);
808                         }
809                 }
810         }
811
812         //=========================================================================
813
814         void wxGUIEditorGraphicBBS::OnCopySelectedToComplexDiagram(wxCommandEvent& event)
815         {
816                 _tabsMgr->copySelectedBBoxesToComplexDiagram();
817         }
818
819
820         void wxGUIEditorGraphicBBS::OnHelpBBeditor(wxCommandEvent& event)
821         {
822                 printf("wxGUIEditorGraphicBBS::OnHelpBBeditor ....not implemented..\n");
823         }
824
825
826         //=========================================================================     
827         void wxGUIEditorGraphicBBS::OnCreatePackage(wxCommandEvent& event)
828         {
829                 printf("EED wxGUIEditorGraphicBBS::OnCreatePackag ... not implemented ..\n");
830         }
831         
832
833         //=========================================================================     
834         void wxGUIEditorGraphicBBS::OnCreateBlackBox(wxCommandEvent& event)
835         {
836                 printf("EED wxGUIEditorGraphicBBS::OnCreateBlackBox ... not implemented ..\n");
837         }
838         //=========================================================================     
839         void wxGUIEditorGraphicBBS::OnPlugPackage(wxCommandEvent& event)
840         {
841                 printf("EED wxGUIEditorGraphicBBS::OnPlugPackage ... not implemented ..\n");
842         }
843         //=========================================================================     
844         void wxGUIEditorGraphicBBS::OnEditConfig(wxCommandEvent& event)
845         {
846                 printf("EED wxGUIEditorGraphicBBS::OnEditConfig ... not implemented ..\n");
847         }
848         //=========================================================================     
849         void wxGUIEditorGraphicBBS::OnShowHTMLDoc(wxCommandEvent& event)
850         {
851                 printf("EED wxGUIEditorGraphicBBS::OnShowHTMLDoc ... not implemented ..\n");
852         }
853         //=========================================================================     
854         void wxGUIEditorGraphicBBS::OnCreateIndex(wxCommandEvent& event)
855         {
856                 printf("EED wxGUIEditorGraphicBBS::OnCreateIndex ... not implemented ..\n");
857         }
858         
859         
860         
861
862         //=========================================================================
863
864         void wxGUIEditorGraphicBBS::OnExit(wxCommandEvent& event)
865         {
866                 Close(true);
867         }
868
869
870
871         //=========================================================================
872
873 }  // EO namespace bbtk
874
875 // EOF
876