]> 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 += "\"";
391                 #endif
392                 command += "\""+ crea::System::GetExecutablePath();
393
394
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                 command += separator + "bbi\" ";
415                 command += "\""+filename + "\"";
416                 #ifdef WIN32
417                         command += "\"";
418                 #endif
419
420         #ifndef WIN32
421             command += " & ";
422                 #endif
423
424                 printf ("RaC wxGUIEditorGraphicBBS::executeScript %s \n" , command.c_str() );
425                 system( command.c_str() );
426         }
427
428         //=========================================================================
429         // EVENT HANDLERS
430         //=========================================================================
431
432         void wxGUIEditorGraphicBBS::OnCreateNewTab(wxCommandEvent& event)
433         {
434                 _tabsMgr->addNewTab();
435                 refreshGUIControls();
436         }
437
438         //=========================================================================
439
440         void wxGUIEditorGraphicBBS::OnExecuteActualDiagram(wxCommandEvent& event)
441         {
442                 std::string script1 = _tabsMgr->getActualDiagramBBS(true);
443                 cout<<endl<<"RaC wxGUIEditorGraphicBBS::executeActualDiagram SCRIPT"<<endl<<endl;
444                 cout<<script1<<endl;
445
446                 std::string script2 = _tabsMgr->getActualDiagramBBS(false);
447                 executeScript(script2);
448         }
449
450
451         //=========================================================================
452         // HANDLERS
453         //=========================================================================
454         void wxGUIEditorGraphicBBS::OnOpenBBS(wxCommandEvent& event)
455         {
456                 wxFileDialog * openFileDialog = new wxFileDialog(this,wxT("Open BBS"),wxEmptyString,wxT("NewBBS"),wxT("*.bbs"),wxOPEN);
457                 if (openFileDialog->ShowModal() == wxID_OK)
458                 {
459                         wxString fileName = openFileDialog->GetPath(  );
460
461
462                         _tabsMgr->addNewTab(  openFileDialog->GetFilename()  );
463
464                         bbtk::InterpreterBBS::Pointer I = bbtk::InterpreterBBS::New( this->_tabsMgr->getActualTabPanel()->getSceneManager() , _pkgBrowser->GetFactory());
465
466                         // We tell the interpreter to throw exceptions on error
467                         I->SetThrow(true);
468                         // Interpret the file supposed to define a box called 'Processing'
469                         I->InterpretFile( (const char*) (fileName.mb_str()) );
470                 }
471                 refreshGUIControls();
472         }
473
474
475
476     void wxGUIEditorGraphicBBS::SaveActualBBS(std::string filename)
477         {
478         ofstream file;
479
480 //EED           file.open(fileName.c_str());
481         file.open( filename.c_str() );
482         std::string content="";
483         // writing file header
484         content += "# ----------------------------------\n";
485         content += "# - BBTKGEditor v 1.2 BBS BlackBox Script\n";
486         content += "# - ";
487         content += filename;
488         content += "\n";
489         content += "# ----------------------------------\n";
490         content += "\n";
491         content += _tabsMgr->getActualDiagramBBS();
492         file << content;
493         file.close();
494         }
495
496
497         void wxGUIEditorGraphicBBS::OnSaveActualBBS(wxCommandEvent& event)
498         {
499                 wxFileDialog * saveFileDialog = new wxFileDialog(this,wxT("Save  actual BBS"),wxEmptyString,wxT("NewBBS"),wxT("*.bbs"),wxSAVE|wxOVERWRITE_PROMPT);
500                 if (saveFileDialog->ShowModal() == wxID_OK)
501                 {
502                         wxString fileName = saveFileDialog->GetPath(  );
503             SaveActualBBS( (const char*) (fileName.mb_str())  );
504                 }
505
506         }
507
508
509     void wxGUIEditorGraphicBBS::AskComplexBoxConfiguration()
510     {
511                 std::string cbName = _tabsMgr->GetCbName();
512                 std::string paName = _tabsMgr->GetCbPackageName();
513
514                 wxTextEntryDialog *cbNameDialog = new wxTextEntryDialog(this,wxT("Complex Box name"));
515                 wxTextEntryDialog *paNameDialog = new wxTextEntryDialog(this,wxT("Package name"));
516
517                 cbNameDialog->SetValue( wxString(cbName.c_str(),wxConvUTF8) );
518                 paNameDialog->SetValue( wxString(paName.c_str(),wxConvUTF8) );
519
520                 if (cbNameDialog->ShowModal() == wxID_OK)
521                 {
522                         wxString complexboxname = cbNameDialog->GetValue();
523                         cbName=(const char*) (complexboxname.mb_str());
524                 }
525
526
527                 if (paNameDialog->ShowModal() == wxID_OK)
528                 {
529                         wxString packagename = paNameDialog->GetValue();
530                         paName=(const char*) (packagename.mb_str());
531                 }
532
533         _tabsMgr->SetCbName(cbName);
534         _tabsMgr->SetCbPackageName(paName);
535     }
536
537         //=========================================================================
538
539         void wxGUIEditorGraphicBBS::SaveActualComplexBox(std::string filename)
540         {
541         ofstream file;
542         file.open( filename.c_str() );
543
544         std::string content="";
545
546         // writing file header
547         content += "# ----------------------------------\n";
548         content += "# - BBTKGEditor v 1.2 BBS BlackBox Script (Complex Box)\n";
549         content += "# - ";
550         content += filename;
551         content += "\n";
552         content += "# ----------------------------------\n";
553         content += "\n";
554         content += _tabsMgr->getActualComplexBoxBBS();
555         file << content;
556         file.close();
557         }
558
559         //=========================================================================
560
561         void wxGUIEditorGraphicBBS::OnSaveActualComplexBox(wxCommandEvent& event)
562         {
563         wxFileDialog * saveFileDialog = new wxFileDialog(this ,wxT("Save Complex Box BBS") ,wxEmptyString, _T("ComplexBoxName") ,wxT("*.bbs"), wxSAVE | wxOVERWRITE_PROMPT);
564         if (saveFileDialog->ShowModal() == wxID_OK)
565         {
566             wxString fileName = saveFileDialog->GetPath();
567             SaveActualComplexBox( (const char*) (fileName.mb_str()) );
568         }
569         }
570
571         //=========================================================================
572         void wxGUIEditorGraphicBBS::SaveActualDiagram(std::string filename)
573         {
574         ofstream file;
575         file.open( filename.c_str() );
576
577         std::string content="";
578
579         // writing file header
580         content += "# ----------------------------------\n";
581         content += "# - BBTKGEditor v 1.2 BBG BlackBox Diagram file\n";
582         content += "# - ";
583
584         content += filename;
585
586         content += "\n";
587         content += "# ----------------------------------\n";
588         content += "\n";
589         content += "APP_START\n";
590         _tabsMgr->saveActualDiagram(content, filename); //DFCH
591         content += "APP_END\n";
592         file << content;
593         file.close();
594     }
595
596         //=========================================================================
597         
598         //The following method allows to save the current diagram asking the filename
599         //DFCH
600         void wxGUIEditorGraphicBBS::SaveCurrentDiagramAs( )
601         {
602                 wxFileDialog * saveFileDialog = new wxFileDialog(this,wxT("Save current diagram"),wxEmptyString,wxT("NewDiagram"),wxT("*.bbg"),wxSAVE|wxOVERWRITE_PROMPT);
603                 if (saveFileDialog->ShowModal() == wxID_OK)
604                 {
605                         _tabsMgr->SetNameTabPanel( saveFileDialog->GetFilename() );
606                         wxString pathfileName       = saveFileDialog->GetPath();
607                         std::string pathfilename    = (const char*) (pathfileName.mb_str());
608             std::string pathfilenamebbs = pathfilename;
609             pathfilenamebbs[pathfilenamebbs.length()-1]='s';
610             if (_tabsMgr->isActualDiagramComplexBox()==false)
611             {
612                 SaveActualDiagram( pathfilename );
613                 SaveActualBBS(pathfilenamebbs);
614             } else {
615                 AskComplexBoxConfiguration();
616                 SaveActualDiagram( pathfilename );
617                 SaveActualComplexBox(pathfilenamebbs);
618             } //if isActualDiagramComplexBox
619                 } // if saveFileDialog
620         }
621         //=========================================================================
622         //DFCH
623         void wxGUIEditorGraphicBBS::OnSaveActualDiagram(wxCommandEvent& event)
624         {
625                 std::string pathfilename = _tabsMgr->GetCurrentTabPanelPath();
626                 if( pathfilename.empty() )
627                 {
628                         SaveCurrentDiagramAs();
629                 }
630                 else
631                 {
632                         std::string pathfilenamebbs = pathfilename;
633             pathfilenamebbs[pathfilenamebbs.length()-1]='s';
634
635             if (_tabsMgr->isActualDiagramComplexBox()==false)
636             {
637                 SaveActualDiagram( pathfilename );
638                 SaveActualBBS(pathfilenamebbs);
639             } else {
640                 AskComplexBoxConfiguration();
641                 SaveActualDiagram( pathfilename );
642                 SaveActualComplexBox(pathfilenamebbs);
643             } //if isActualDiagramComplexBox
644                 }               
645         }
646         //=========================================================================
647         //DFCH
648         void wxGUIEditorGraphicBBS::OnSaveAsActualDiagram(wxCommandEvent& event)
649         {
650                 SaveCurrentDiagramAs();
651         }
652         //=========================================================================
653
654         void wxGUIEditorGraphicBBS::refreshGUIControls()
655         {
656                 wxToolBar* toolbar = GetToolBar();
657                 if(_tabsMgr->isActualDiagramComplexBox())
658                 {
659                         toolbar->ToggleTool(ID_BTNCOMPLEXBOX,true);
660                         toolbar->EnableTool(ID_ADDCOMPLEXBOXINPUT,true);
661                         toolbar->EnableTool(ID_ADDCOMPLEXBOXOUTPUT,true);
662
663                         GetMenuBar()->GetMenu(0)->Enable(ID_SAVE_AS_COMPLEXBOX,true);
664                         GetMenuBar()->GetMenu(0)->Enable(ID_SAVE_AS_BBS,false);
665                 }
666                 else
667                 {
668                         toolbar->ToggleTool(ID_BTNCOMPLEXBOX,false);
669                         toolbar->EnableTool(ID_ADDCOMPLEXBOXINPUT,false);
670                         toolbar->EnableTool(ID_ADDCOMPLEXBOXOUTPUT,false);
671
672                         GetMenuBar()->GetMenu(0)->Enable(ID_SAVE_AS_COMPLEXBOX,false);
673                         GetMenuBar()->GetMenu(0)->Enable(ID_SAVE_AS_BBS,true);
674                 }
675
676                 if(_tabsMgr->getNumActualSelectedObjects()>0)
677                 {
678                         GetMenuBar()->GetMenu(1)->Enable(ID_COPY_TO_COMPLEXDIAGRAM,true);
679                 }
680                 else
681                 {
682                         ///TODO Fix the possibility to say from the SceneManager to the GUI to refresh the options
683                         GetMenuBar()->GetMenu(1)->Enable(ID_COPY_TO_COMPLEXDIAGRAM,true);
684                 }
685
686         }
687
688         //=========================================================================
689
690         void wxGUIEditorGraphicBBS::OnDeleteAllBoxesActualDiagram(wxCommandEvent& event)
691         {
692                 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);
693                 if(dial->ShowModal() == wxID_YES)
694                 {
695                         _tabsMgr->deleteAllBoxesActualDiagram();
696                 }
697         }
698
699         //=========================================================================
700
701         void wxGUIEditorGraphicBBS::OnCenterViewActualDiagram(wxCommandEvent& event)
702         {
703                 _tabsMgr->centerViewActualDiagram();
704         }
705
706         //=========================================================================
707
708         void wxGUIEditorGraphicBBS::OnOpenDiagram(wxCommandEvent& event)
709         {
710                 wxFileDialog * openFileDialog = new wxFileDialog(this,wxT("Open diagram"),wxEmptyString,wxT(""),wxT("*.bbg"),wxOPEN|wxFILE_MUST_EXIST);
711                 if (openFileDialog->ShowModal() == wxID_OK)
712                 {
713                         wxString fileName = openFileDialog->GetPath();
714                         ifstream inputStream;
715                         std::string fName=(const char*) (fileName.mb_str());
716                         inputStream.open( fName.c_str() );
717                         _tabsMgr->addNewTab( openFileDialog->GetFilename() );
718
719                         _tabsMgr->loadDiagram(inputStream, fName);
720
721                         inputStream.close();
722                 }
723                 refreshGUIControls();
724         }
725
726         //=========================================================================
727
728
729         void wxGUIEditorGraphicBBS::OnClickBtnBox(wxCommandEvent& event)
730         {
731                 BlackBoxDescriptor      *bbDes = _pkgBrowser->GetActualSelected();
732         if (bbDes!=NULL)
733         {
734             std::string                 typeName        = bbDes->GetTypeName();
735             std::string                 packageName = bbDes->GetPackage()->GetName();
736
737
738             wxGEditorTabPanel *pnl = this->_tabsMgr->getActualTabPanel();
739
740             if (pnl!=NULL)
741             {
742                 wxVtkSceneManager *scn = pnl->getSceneManager();
743                 scn->createGBlackBox(50,50,packageName, typeName);
744                 scn->refresh();
745             } // if pnl
746         }// if bbDes
747         }
748
749         //=========================================================================
750
751         void wxGUIEditorGraphicBBS::OnClickBtnExecutableBox(wxCommandEvent& event)
752         {
753                 printf("EED  wxGUIEditorGraphicBBS::OnClickBtnExecutableBox  .... not implemented ...\n");
754         }
755         
756         //=========================================================================
757
758         void wxGUIEditorGraphicBBS::OnClickBtnComplexBox(wxCommandEvent& event)
759         {
760                 wxToolBar* toolbar = GetToolBar();
761                 bool temp = toolbar->GetToolState(ID_BTNCOMPLEXBOX);
762                 if(temp)
763                 {
764                         _tabsMgr->setActualDiagramComplexBox(true);
765                 }
766                 else
767                 {
768                         _tabsMgr->setActualDiagramComplexBox(false);
769                 }
770                 refreshGUIControls();
771         }
772
773         //=========================================================================
774
775         void wxGUIEditorGraphicBBS::OnAddComplexBoxInput(wxCommandEvent& event)
776         {
777                 wxTextEntryDialog *nameDialog = new wxTextEntryDialog(this,wxT("Name of input port"));
778                 if (nameDialog->ShowModal() == wxID_OK)
779                 {
780                         wxString fileName = nameDialog->GetValue();
781                         if(!fileName.IsEmpty())
782                         {
783                                 std::string portName=(const char*) (fileName.mb_str());
784                                 _tabsMgr->addActualDiagramComplexInputPort(portName);
785                         }
786                 }
787         }
788
789         //=========================================================================
790
791         void wxGUIEditorGraphicBBS::OnAddComplexBoxOutput(wxCommandEvent& event)
792         {
793                 wxTextEntryDialog *nameDialog = new wxTextEntryDialog(this,wxT("Name of output port"));
794                 if (nameDialog->ShowModal() == wxID_OK)
795                 {
796                         wxString fileName = nameDialog->GetValue();
797                         if(!fileName.IsEmpty())
798                         {
799                                 std::string portName=(const char*) (fileName.mb_str());
800                                 _tabsMgr->addActualDiagramComplexOutputPort(portName);
801                         }
802                 }
803         }
804
805         //=========================================================================
806
807         void wxGUIEditorGraphicBBS::OnCopySelectedToComplexDiagram(wxCommandEvent& event)
808         {
809                 _tabsMgr->copySelectedBBoxesToComplexDiagram();
810         }
811
812
813         void wxGUIEditorGraphicBBS::OnHelpBBeditor(wxCommandEvent& event)
814         {
815                 printf("wxGUIEditorGraphicBBS::OnHelpBBeditor ....not implemented..\n");
816         }
817
818
819         //=========================================================================     
820         void wxGUIEditorGraphicBBS::OnCreatePackage(wxCommandEvent& event)
821         {
822                 printf("EED wxGUIEditorGraphicBBS::OnCreatePackag ... not implemented ..\n");
823         }
824         
825
826         //=========================================================================     
827         void wxGUIEditorGraphicBBS::OnCreateBlackBox(wxCommandEvent& event)
828         {
829                 printf("EED wxGUIEditorGraphicBBS::OnCreateBlackBox ... not implemented ..\n");
830         }
831         //=========================================================================     
832         void wxGUIEditorGraphicBBS::OnPlugPackage(wxCommandEvent& event)
833         {
834                 printf("EED wxGUIEditorGraphicBBS::OnPlugPackage ... not implemented ..\n");
835         }
836         //=========================================================================     
837         void wxGUIEditorGraphicBBS::OnEditConfig(wxCommandEvent& event)
838         {
839                 printf("EED wxGUIEditorGraphicBBS::OnEditConfig ... not implemented ..\n");
840         }
841         //=========================================================================     
842         void wxGUIEditorGraphicBBS::OnShowHTMLDoc(wxCommandEvent& event)
843         {
844                 printf("EED wxGUIEditorGraphicBBS::OnShowHTMLDoc ... not implemented ..\n");
845         }
846         //=========================================================================     
847         void wxGUIEditorGraphicBBS::OnCreateIndex(wxCommandEvent& event)
848         {
849                 printf("EED wxGUIEditorGraphicBBS::OnCreateIndex ... not implemented ..\n");
850         }
851         
852         
853         
854
855         //=========================================================================
856
857         void wxGUIEditorGraphicBBS::OnExit(wxCommandEvent& event)
858         {
859                 Close(true);
860         }
861
862
863
864         //=========================================================================
865
866 }  // EO namespace bbtk
867
868 // EOF
869