]> Creatis software - bbtkGEditor.git/blob - lib/EditorGraphicBBS/bbsWxGUIEditorGraphic/bbtkwxGUIEditorGraphicBBS.cxx
*** empty log message ***
[bbtkGEditor.git] / lib / EditorGraphicBBS / bbsWxGUIEditorGraphic / bbtkwxGUIEditorGraphicBBS.cxx
1 /*=========================================================================
2 Program:   bbtk
3 Module:    $RCSfile$
4 Language:  C++
5 Date:      $Date$
6 Version:   $Revision$
7 =========================================================================*/
8
9 /* ---------------------------------------------------------------------
10
11 * Copyright (c) CREATIS-LRMN (Centre de Recherche en Imagerie Medicale)
12 * Authors : Eduardo Davila, Laurent Guigues, Jean-Pierre Roux
13 *
14 *  This software is governed by the CeCILL-B license under French law and
15 *  abiding by the rules of distribution of free software. You can  use,
16 *  modify and/ or redistribute the software under the terms of the CeCILL-B
17 *  license as circulated by CEA, CNRS and INRIA at the following URL
18 *  http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
19 *  or in the file LICENSE.txt.
20 *
21 *  As a counterpart to the access to the source code and  rights to copy,
22 *  modify and redistribute granted by the license, users are provided only
23 *  with a limited warranty  and the software's author,  the holder of the
24 *  economic rights,  and the successive licensors  have only  limited
25 *  liability.
26 *
27 *  The fact that you are presently reading this means that you have had
28 *  knowledge of the CeCILL-B license and that you accept its terms.
29 * ------------------------------------------------------------------------ */
30
31 /**
32 *  \file
33 *  \brief Class bbtk::WxInterfaceEditorGraphicBBS .
34 */
35
36 #include "bbtkwxGUIEditorGraphicBBS.h"
37 #include "creaWx.h"
38 #include "creaSystem.h"
39
40 #include <InterpreterBBS.h>
41
42
43
44 namespace bbtk
45 {
46
47
48         //=========================================================================
49         wxGUIEditorGraphicBBS::wxGUIEditorGraphicBBS(wxFrame *parent)
50                 : wxFrame(parent, -1, _T("bbtkGEditor"),wxDefaultPosition, wxSize(1200,800))
51         {
52
53                 _frameAUIMgr = new wxAuiManager(this);
54
55
56                 /*std::string datadir( crea::System::GetExecutablePath() );
57                 std::string datadir (".");
58                 cout<<"RaC //------------------"<<endl;
59                 cout<<"RaC //TODO wxGUIEditorGraphicBBS constructor.Initialize datadir with  crea::System::GetExecutablePath() ."<<endl;
60                 cout<<"RaC //------------------"<<endl;
61
62             #ifdef LINUX // assume this is OSX
63                    datadir=datadir+"/../share/creaContours";
64             #endif // MACOSX
65
66                 #ifdef MACOSX // assume this is OSX
67                         datadir=datadir+"/../../../../share/creaContours";
68                 #endif // MACOSX
69
70                 _dataDir = datadir;*/
71
72                 initMenu();
73                 initToolbar();
74                 initTabPanelsManager();
75                 initPackageBrowser();
76                 initHelpHTMLBrowser();
77
78                 CreateStatusBar();
79                 _frameAUIMgr->Update();
80                 _actualPkgBrowserBoxName="";
81                 _actualPkgBrowserPkgName="";
82                 refreshGUIControls();
83         }
84
85
86         //=========================================================================
87         wxGUIEditorGraphicBBS::~wxGUIEditorGraphicBBS()
88         {
89                 printf ("EED %p ~wxGUIEditorGraphicBBS()\n" , this );
90
91 //EED02JUIN2010         delete _tabsMgr;
92
93             _frameAUIMgr->UnInit();
94
95
96         }
97
98         //=========================================================================
99         void wxGUIEditorGraphicBBS::initToolbar()
100         {
101                 wxBitmap bmp_new(new_xpm);
102                 wxBitmap bmp_open(open_xpm);
103                 wxBitmap bmp_save(save_xpm);
104                 wxBitmap bmp_run(run_xpm);
105                 wxBitmap bmp_delete(delete_xpm);
106                 wxBitmap bmp_centerview(centerview_xpm);
107                 wxBitmap bmp_box(box_xpm);
108                 wxBitmap bmp_complexbox(complexbox_xpm);
109                 wxBitmap bmp_complexinputport(complexinputport_xpm);
110                 wxBitmap bmp_complexoutputport(complexoutputport_xpm);
111
112                 wxToolBar  *toolbar = new wxToolBar(this, wxID_ANY);
113
114                 //Adds a tool btn to the toolbar
115                 toolbar->AddTool(ID_NEW,_T("New"),bmp_new, wxNullBitmap, wxITEM_NORMAL,_T("New tab"), _T("Create a new panel tab"));
116                 toolbar->AddTool(ID_OPEN,_T("Open diagram"),bmp_open, wxNullBitmap, wxITEM_NORMAL,_T("Open a diagram"), _T("Open a diagram"));
117                 toolbar->AddTool(ID_SAVE_AS_DIAGRAM,_T("Save diagram"),bmp_save, wxNullBitmap, wxITEM_NORMAL,_T("Saves actual diagram"), _T("Saves actual diagram"));
118                 toolbar->AddTool(ID_RUN,_T("Run"),bmp_run, wxNullBitmap, wxITEM_NORMAL,_T("Execute actual diagram"), _T("Execute actual diagram"));
119                 toolbar->AddTool(ID_DELETEALL,_T("Delete all"),bmp_delete, wxNullBitmap, wxITEM_NORMAL,_T("Delete all boxes"), _T("Delete all boxes"));
120                 toolbar->AddTool(ID_CENTERVIEW,_T("Center view"),bmp_centerview, wxNullBitmap, wxITEM_NORMAL,_T("Center view"), _T("Center view"));
121                 toolbar->AddSeparator();
122                 toolbar->AddTool(ID_BTNBOX,_T("New Box"),bmp_box, wxNullBitmap, wxITEM_NORMAL,_T("New Box"), _T("Nex Box"));
123                 toolbar->AddSeparator();
124                 toolbar->AddTool(ID_BTNCOMPLEXBOX,_T("Complex box"),complexbox_xpm, wxNullBitmap, wxITEM_NORMAL,_T("Complex box"), _T("Complex box"));
125                 toolbar->SetToggle(ID_BTNCOMPLEXBOX,true);
126                 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"));
127                 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"));
128                 toolbar->EnableTool(ID_ADDCOMPLEXBOXINPUT,false);
129                 toolbar->EnableTool(ID_ADDCOMPLEXBOXOUTPUT,false);
130
131                 toolbar->SetMargins( 2, 2 );
132                 toolbar->Realize();
133                 SetToolBar(toolbar);
134
135                 // connect command event handlers
136                 Connect(ID_NEW,wxEVT_COMMAND_TOOL_CLICKED,wxCommandEventHandler(wxGUIEditorGraphicBBS::OnCreateNewTab));
137                 Connect(ID_OPEN,wxEVT_COMMAND_TOOL_CLICKED,wxCommandEventHandler(wxGUIEditorGraphicBBS::OnOpenDiagram));
138                 Connect(ID_SAVE_AS_DIAGRAM,wxEVT_COMMAND_TOOL_CLICKED,wxCommandEventHandler(wxGUIEditorGraphicBBS::OnSaveActualDiagram));
139                 Connect(ID_RUN,wxEVT_COMMAND_TOOL_CLICKED,wxCommandEventHandler(wxGUIEditorGraphicBBS::OnExecuteActualDiagram));
140                 Connect(ID_DELETEALL,wxEVT_COMMAND_TOOL_CLICKED,wxCommandEventHandler(wxGUIEditorGraphicBBS::OnDeleteAllBoxesActualDiagram));
141                 Connect(ID_CENTERVIEW,wxEVT_COMMAND_TOOL_CLICKED,wxCommandEventHandler(wxGUIEditorGraphicBBS::OnCenterViewActualDiagram));
142                 Connect(ID_BTNBOX,wxEVT_COMMAND_TOOL_CLICKED,wxCommandEventHandler(wxGUIEditorGraphicBBS::OnClickBtnBox));
143                 Connect(ID_BTNCOMPLEXBOX,wxEVT_COMMAND_TOOL_CLICKED,wxCommandEventHandler(wxGUIEditorGraphicBBS::OnClickBtnComplexBox));
144                 Connect(ID_ADDCOMPLEXBOXINPUT,wxEVT_COMMAND_TOOL_CLICKED,wxCommandEventHandler(wxGUIEditorGraphicBBS::OnAddComplexBoxInput));
145                 Connect(ID_ADDCOMPLEXBOXOUTPUT,wxEVT_COMMAND_TOOL_CLICKED,wxCommandEventHandler(wxGUIEditorGraphicBBS::OnAddComplexBoxOutput));
146
147         }
148         //=========================================================================
149         void wxGUIEditorGraphicBBS::initHelpHTMLBrowser()
150         {
151                 //TO FIX THE PATH OF BBTK BIN  IN ORDER TO USE REGENERATE EXECUTABLES
152                 //RegenerateAll();
153                 _helpHtmlBrowser = new WxGUIHtmlBrowser(this,wxSize(200,0));
154                 _frameAUIMgr->AddPane(_helpHtmlBrowser,wxAuiPaneInfo().Right().MinSize(200,200));
155         }
156
157         //=========================================================================
158         void wxGUIEditorGraphicBBS::initMenu()
159         {
160                 // Create File menu and its items
161                 wxMenu *fileMenu = new wxMenu();
162                 fileMenu->Append(ID_NEW, _T("New diagram"), _T("New"));
163                 fileMenu->Append(ID_SAVE_AS_DIAGRAM, _T("Save diagram"), _T("Save diagram"));
164                 fileMenu->Append(ID_OPEN_BBS, _T("Open BBS"), _T("Open BBS"));
165                 fileMenu->Append(ID_SAVE_AS_BBS, _T("Save BBS"), _T("Save BBS"));
166                 fileMenu->Append(ID_SAVE_AS_COMPLEXBOX, _T("Save complex box"), _T("Save complex box"));
167                 fileMenu->Append(wxID_EXIT, _T("E&xit"), _T("Exit"));
168
169                 Connect(ID_NEW,wxEVT_COMMAND_MENU_SELECTED,wxCommandEventHandler(wxGUIEditorGraphicBBS::OnCreateNewTab));
170                 Connect(ID_SAVE_AS_DIAGRAM,wxEVT_COMMAND_MENU_SELECTED,wxCommandEventHandler(wxGUIEditorGraphicBBS::OnSaveActualDiagram));
171                 Connect(ID_OPEN_BBS,wxEVT_COMMAND_MENU_SELECTED,wxCommandEventHandler(wxGUIEditorGraphicBBS::OnOpenBBS));
172                 Connect(ID_SAVE_AS_BBS,wxEVT_COMMAND_MENU_SELECTED,wxCommandEventHandler(wxGUIEditorGraphicBBS::OnSaveActualBBS));
173                 Connect(ID_SAVE_AS_COMPLEXBOX,wxEVT_COMMAND_MENU_SELECTED,wxCommandEventHandler(wxGUIEditorGraphicBBS::OnSaveActualComplexBox));
174                 Connect(wxID_EXIT,wxEVT_COMMAND_MENU_SELECTED,wxCommandEventHandler(wxGUIEditorGraphicBBS::OnExit));
175
176                 // Create Help menu and its items
177                 wxMenu *editMenu = new wxMenu;
178                 editMenu->Append(ID_COPY_TO_COMPLEXDIAGRAM, _T("Copy selected to complex box"), _T("Creates a new complex box diagram with selected boxes"));
179
180                 Connect(ID_COPY_TO_COMPLEXDIAGRAM,wxEVT_COMMAND_MENU_SELECTED,wxCommandEventHandler(wxGUIEditorGraphicBBS::OnCopySelectedToComplexDiagram));
181
182                 // Create Help menu and its items
183                 wxMenu *helpMenu = new wxMenu;
184                 helpMenu->Append(wxID_ABOUT, _T("&About..."), _T("About"));
185                 helpMenu->Append(ID_HELP_BBEDITOR, _T("&Help..."), _T("Help"));
186                 Connect(ID_HELP_BBEDITOR,wxEVT_COMMAND_MENU_SELECTED,wxCommandEventHandler(wxGUIEditorGraphicBBS::OnHelpBBeditor));
187
188                 // Append the created menu to the menu bar
189                 wxMenuBar *menuBar = new wxMenuBar();
190                 menuBar->Append(fileMenu, _T("&File"));
191                 menuBar->Append(editMenu, _T("&Edit"));
192                 menuBar->Append(helpMenu, _T("&Help"));
193
194                 // Attach this menu bar to the frame
195                 SetMenuBar(menuBar);
196         }
197
198         //=========================================================================
199         void wxGUIEditorGraphicBBS::initTabPanelsManager()
200         {
201                 _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);
202                 _tabsMgr = new wxTabPanelsManager(this);
203                 _frameAUIMgr->AddPane(_notebook,wxAuiPaneInfo().CenterPane());
204
205         }
206
207         //=========================================================================
208         void wxGUIEditorGraphicBBS::initPackageBrowser()
209         {
210                 _pkgBrowser = new WxGUIPackageBrowser2(this);
211                 _pkgBrowser->IncludeAll();
212                 _frameAUIMgr->AddPane(_pkgBrowser,wxAuiPaneInfo().Left().MinSize(200,200).CloseButton(false));
213         }
214
215         //================================================================
216
217         void wxGUIEditorGraphicBBS::DoRegeneratePackageDoc( const std::string& pack )
218         {
219                 std::string mess("Regenerating doc for package '");
220                 if (pack!="-a"){
221                         mess += pack + "'";
222                 }
223                 else
224                 {
225                         mess = "Regenerating doc for all packages";
226                 }
227
228                 mess += " ... please wait";
229
230                 SetStatusText( std2wx(mess) );
231
232                 //BBTK_BUSY_CURSOR;
233
234                 std::string command;
235                 #if defined(WIN32)
236                         command = "\"";
237                 #endif
238                         command += ConfigurationFile::GetInstance().Get_bin_path();
239                         command += ConfigurationFile::GetInstance().Get_file_separator();
240                         command += "bbRegeneratePackageDoc";
241                 #if defined(WIN32)
242                         command += "\"";
243                 #endif
244
245                 command += " " + pack + " -q";
246             bbtkMessage("debug",1,"Executing system command '"<<command<<"'"<<std::endl);
247
248                 if ( ! system ( command.c_str() ) )
249                 {
250                         SetStatusText( _T("Done !"));
251                         /*
252                         wxMessageBox(_T("Done !"),_T("Regenerate package '")
253                                          +std2wx(pack)+_T("' doc"),
254                                          wxOK | wxICON_INFORMATION);
255                         */
256                 }
257                 else
258                 {
259                         SetStatusText( _T("Done !"));
260                         wxString err(_T("An error occured while running '"));
261                         err +=  bbtk::std2wx(command) + _T("'");
262                         wxMessageBox(err,_T("Regenerate package doc"),wxOK | wxICON_ERROR);
263             }
264         }
265
266         //================================================================
267         void wxGUIEditorGraphicBBS::DoRegenerateBoxesLists()
268         {
269                 SetStatusText( _T("Regenerating boxes lists ... please wait") );
270                 //BBTK_BUSY_CURSOR ;
271
272                 std::string command;
273                 #if defined(WIN32)
274                         command = "\"";
275                 #endif
276                         command += ConfigurationFile::GetInstance().Get_bin_path();
277                         command += ConfigurationFile::GetInstance().Get_file_separator();
278                         command += "bbRegenerateBoxesLists";
279
280                 #if defined(WIN32)
281                         command += "\"";
282                 #endif
283                         command += " -q";
284
285                 bbtkMessage("debug",1,"Executing system command '"<<command<<"'"<<std::endl);
286
287                 if ( ! system ( command.c_str() ) )
288                 {
289                         SetStatusText( _T("Done !"));
290                         /*
291                         wxMessageBox(_T("Done !"),_T("Regenerate boxes lists"),
292                                          wxOK | wxICON_INFORMATION);
293                         */
294                 }
295                 else
296                 {
297                         SetStatusText( _T("Done !"));
298                         wxString err(_T("An error occured while running '"));
299                         err +=  bbtk::std2wx(command) + _T("'");
300                         wxMessageBox(err,_T("Regenerate boxes lists"),wxOK | wxICON_ERROR);
301                 }
302         }
303
304   //================================================================
305         void wxGUIEditorGraphicBBS::RegenerateAll()
306         {
307                 DoRegeneratePackageDoc("-a");
308                 DoRegenerateBoxesLists();
309         }
310
311         //================================================================
312
313         wxAuiNotebook* wxGUIEditorGraphicBBS::getAuiNotebook()
314         {
315                 return _notebook;
316         }
317
318         //================================================================
319
320         void wxGUIEditorGraphicBBS::displayBlackBoxInfo(std::string packageName, std::string boxName)
321         {
322                 if(_actualPkgBrowserPkgName != packageName || _actualPkgBrowserBoxName != boxName )
323                 {
324                         _actualPkgBrowserPkgName = packageName;
325                         _actualPkgBrowserBoxName = boxName;
326
327                         BlackBoxDescriptor::Pointer descriptor = GObjectsMVCFactory::getInstance()->getBlackBoxDescriptor(packageName, boxName);
328                         _pkgBrowser->WxGUIBlackBoxListUserOnSelected(descriptor.get());
329                 }
330         }
331
332         //=========================================================================
333
334         void wxGUIEditorGraphicBBS::editBlackBox(GBlackBoxModel *bbmodel)
335         {
336                 wxBlackBoxEditionDialog* dialog = new wxBlackBoxEditionDialog(this,bbmodel);
337                 dialog->Show();
338         }
339
340         //=========================================================================
341
342         void wxGUIEditorGraphicBBS::updateStatusBar(std::string textStatus)
343         {
344                 SetStatusText(crea::std2wx(textStatus));
345         }
346
347         //=========================================================================
348
349         void wxGUIEditorGraphicBBS::executeScript(std::string script)
350         {
351                 std::string separator = ConfigurationFile::GetInstance().Get_file_separator ();
352                 std::string dir = ConfigurationFile::GetInstance().Get_default_temp_dir();
353                 std::string filename = dir + separator + "tmp_bbtk.bbs";
354
355                 ofstream tempFile;
356                 tempFile.open(filename.c_str());
357                 tempFile << script;
358                 tempFile.close();
359
360                 std::string command = "\""+ crea::System::GetExecutablePath();
361
362
363 #ifdef MACOSX
364                 command += separator + "../../../bbi.app/Contents/MacOS";
365 #endif
366
367                 #ifdef WIN32
368                         command += "\"";
369                 #endif
370
371                 /*
372
373                 //command += ConfigurationFile::GetInstance().Get_bin_path();
374 //EED           command +="C:/temp/bbtkBIN/RelWithDebInfo//";
375 //EED           command +="C:/Program Files/CreaTools/bbtk-0.9.5/bin";
376
377
378                 #ifdef MACOSX
379                         command += separator + "usr/local/bin/bbi.app/Contents/MacOS/bbi\" ";
380                 #else
381                     command +=".";
382                         command += separator + "bbi\" ";
383                 #endif
384  */
385                 command += separator + "bbi\" ";
386                 command += "\""+filename + "\"";
387                 #ifdef WIN32
388         //              command += "\"";
389                 #endif
390
391         #ifndef WIN32
392             command += " & ";
393                 #endif
394
395                 printf ("RaC wxGUIEditorGraphicBBS::executeScript %s \n" , command.c_str() );
396                 system( command.c_str() );
397         }
398
399         //=========================================================================
400         // EVENT HANDLERS
401         //=========================================================================
402
403         void wxGUIEditorGraphicBBS::OnCreateNewTab(wxCommandEvent& event)
404         {
405                 _tabsMgr->addNewTab();
406                 refreshGUIControls();
407         }
408
409         //=========================================================================
410
411         void wxGUIEditorGraphicBBS::OnExecuteActualDiagram(wxCommandEvent& event)
412         {
413                 std::string script1 = _tabsMgr->getActualDiagramBBS(true);
414                 cout<<endl<<"RaC wxGUIEditorGraphicBBS::executeActualDiagram SCRIPT"<<endl<<endl;
415                 cout<<script1<<endl;
416
417                 std::string script2 = _tabsMgr->getActualDiagramBBS(false);
418                 executeScript(script2);
419         }
420
421
422         //=========================================================================
423         // HANDLERS
424         //=========================================================================
425         void wxGUIEditorGraphicBBS::OnOpenBBS(wxCommandEvent& event)
426         {
427                 wxFileDialog * openFileDialog = new wxFileDialog(this,wxT("Open BBS"),wxEmptyString,wxT("NewBBS"),wxT("*.bbs"),wxOPEN);
428                 if (openFileDialog->ShowModal() == wxID_OK)
429                 {
430                         wxString fileName = openFileDialog->GetPath(  );
431
432
433                         _tabsMgr->addNewTab(  openFileDialog->GetFilename()  );
434
435                         bbtk::InterpreterBBS::Pointer I = bbtk::InterpreterBBS::New( this->_tabsMgr->getActualTabPanel()->getSceneManager() , _pkgBrowser->GetFactory());
436
437                         // We tell the interpreter to throw exceptions on error
438                         I->SetThrow(true);
439                         // Interpret the file supposed to define a box called 'Processing'
440                         I->InterpretFile( (const char*) (fileName.mb_str()) );
441                 }
442                 refreshGUIControls();
443         }
444
445
446
447     void wxGUIEditorGraphicBBS::SaveActualBBS(std::string filename)
448         {
449         ofstream file;
450
451 //EED           file.open(fileName.c_str());
452         file.open( filename.c_str() );
453         std::string content="";
454         // writing file header
455         content += "# ----------------------------------\n";
456         content += "# - BBTKGEditor v 1.2 BBS BlackBox Script\n";
457         content += "# - ";
458         content += filename;
459         content += "\n";
460         content += "# ----------------------------------\n";
461         content += "\n";
462         content += _tabsMgr->getActualDiagramBBS();
463         file << content;
464         file.close();
465         }
466
467
468         void wxGUIEditorGraphicBBS::OnSaveActualBBS(wxCommandEvent& event)
469         {
470                 wxFileDialog * saveFileDialog = new wxFileDialog(this,wxT("Save  actual BBS"),wxEmptyString,wxT("NewBBS"),wxT("*.bbs"),wxSAVE|wxOVERWRITE_PROMPT);
471                 if (saveFileDialog->ShowModal() == wxID_OK)
472                 {
473                         wxString fileName = saveFileDialog->GetPath(  );
474             SaveActualBBS( (const char*) (fileName.mb_str())  );
475                 }
476
477         }
478
479
480     void wxGUIEditorGraphicBBS::AskComplexBoxConfiguration()
481     {
482                 std::string cbName = _tabsMgr->GetCbName();
483                 std::string paName = _tabsMgr->GetCbPackageName();
484
485                 wxTextEntryDialog *cbNameDialog = new wxTextEntryDialog(this,wxT("Complex Box name"));
486                 wxTextEntryDialog *paNameDialog = new wxTextEntryDialog(this,wxT("Package name"));
487
488                 cbNameDialog->SetValue( wxString(cbName.c_str(),wxConvUTF8) );
489                 paNameDialog->SetValue( wxString(paName.c_str(),wxConvUTF8) );
490
491                 if (cbNameDialog->ShowModal() == wxID_OK)
492                 {
493                         wxString complexboxname = cbNameDialog->GetValue();
494                         cbName=(const char*) (complexboxname.mb_str());
495                 }
496
497
498                 if (paNameDialog->ShowModal() == wxID_OK)
499                 {
500                         wxString packagename = paNameDialog->GetValue();
501                         paName=(const char*) (packagename.mb_str());
502                 }
503
504         _tabsMgr->SetCbName(cbName);
505         _tabsMgr->SetCbPackageName(paName);
506     }
507
508         //=========================================================================
509
510         void wxGUIEditorGraphicBBS::SaveActualComplexBox(std::string filename)
511         {
512         ofstream file;
513         file.open( filename.c_str() );
514
515         std::string content="";
516
517         // writing file header
518         content += "# ----------------------------------\n";
519         content += "# - BBTKGEditor v 1.2 BBS BlackBox Script (Complex Box)\n";
520         content += "# - ";
521         content += filename;
522         content += "\n";
523         content += "# ----------------------------------\n";
524         content += "\n";
525         content += _tabsMgr->getActualComplexBoxBBS();
526         file << content;
527         file.close();
528         }
529
530         //=========================================================================
531
532         void wxGUIEditorGraphicBBS::OnSaveActualComplexBox(wxCommandEvent& event)
533         {
534         wxFileDialog * saveFileDialog = new wxFileDialog(this ,wxT("Save Complex Box BBS") ,wxEmptyString, _T("ComplexBoxName") ,wxT("*.bbs"), wxSAVE | wxOVERWRITE_PROMPT);
535         if (saveFileDialog->ShowModal() == wxID_OK)
536         {
537             wxString fileName = saveFileDialog->GetPath();
538             SaveActualComplexBox( (const char*) (fileName.mb_str()) );
539         }
540         }
541
542         //=========================================================================
543         void wxGUIEditorGraphicBBS::SaveActualDiagram(std::string filename)
544         {
545         ofstream file;
546         file.open( filename.c_str() );
547
548         std::string content="";
549
550         // writing file header
551         content += "# ----------------------------------\n";
552         content += "# - BBTKGEditor v 1.2 BBG BlackBox Diagram file\n";
553         content += "# - ";
554
555         content += filename;
556
557         content += "\n";
558         content += "# ----------------------------------\n";
559         content += "\n";
560         content += "APP_START\n";
561         _tabsMgr->saveActualDiagram(content);
562         content += "APP_END\n";
563         file << content;
564         file.close();
565     }
566
567
568         //=========================================================================
569         void wxGUIEditorGraphicBBS::OnSaveActualDiagram(wxCommandEvent& event)
570         {
571                 wxFileDialog * saveFileDialog = new wxFileDialog(this,wxT("Save  actual diagram"),wxEmptyString,wxT("NewDiagram"),wxT("*.bbg"),wxSAVE|wxOVERWRITE_PROMPT);
572                 if (saveFileDialog->ShowModal() == wxID_OK)
573                 {
574             _tabsMgr->SetNameTabPanel( saveFileDialog->GetFilename() );
575
576                         wxString pathfileName       = saveFileDialog->GetPath();
577                         std::string pathfilename    = (const char*) (pathfileName.mb_str());
578             std::string pathfilenamebbs = pathfilename;
579             pathfilenamebbs[pathfilenamebbs.length()-1]='s';
580
581             if (_tabsMgr->isActualDiagramComplexBox()==false)
582             {
583                 SaveActualDiagram( pathfilename );
584                 SaveActualBBS(pathfilenamebbs);
585             } else {
586                 AskComplexBoxConfiguration();
587                 SaveActualDiagram( pathfilename );
588                 SaveActualComplexBox(pathfilenamebbs);
589             } //if isActualDiagramComplexBox
590                 } // if saveFileDialog
591         }
592
593         //=========================================================================
594
595         void wxGUIEditorGraphicBBS::refreshGUIControls()
596         {
597                 wxToolBar* toolbar = GetToolBar();
598                 if(_tabsMgr->isActualDiagramComplexBox())
599                 {
600                         toolbar->ToggleTool(ID_BTNCOMPLEXBOX,true);
601                         toolbar->EnableTool(ID_ADDCOMPLEXBOXINPUT,true);
602                         toolbar->EnableTool(ID_ADDCOMPLEXBOXOUTPUT,true);
603
604                         GetMenuBar()->GetMenu(0)->Enable(ID_SAVE_AS_COMPLEXBOX,true);
605                         GetMenuBar()->GetMenu(0)->Enable(ID_SAVE_AS_BBS,false);
606                 }
607                 else
608                 {
609                         toolbar->ToggleTool(ID_BTNCOMPLEXBOX,false);
610                         toolbar->EnableTool(ID_ADDCOMPLEXBOXINPUT,false);
611                         toolbar->EnableTool(ID_ADDCOMPLEXBOXOUTPUT,false);
612
613                         GetMenuBar()->GetMenu(0)->Enable(ID_SAVE_AS_COMPLEXBOX,false);
614                         GetMenuBar()->GetMenu(0)->Enable(ID_SAVE_AS_BBS,true);
615                 }
616
617                 if(_tabsMgr->getNumActualSelectedObjects()>0)
618                 {
619                         GetMenuBar()->GetMenu(1)->Enable(ID_COPY_TO_COMPLEXDIAGRAM,true);
620                 }
621                 else
622                 {
623                         ///TODO Fix the possibility to say from the SceneManager to the GUI to refresh the options
624                         GetMenuBar()->GetMenu(1)->Enable(ID_COPY_TO_COMPLEXDIAGRAM,true);
625                 }
626
627         }
628
629         //=========================================================================
630
631         void wxGUIEditorGraphicBBS::OnDeleteAllBoxesActualDiagram(wxCommandEvent& event)
632         {
633                 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);
634                 if(dial->ShowModal() == wxID_YES)
635                 {
636                         _tabsMgr->deleteAllBoxesActualDiagram();
637                 }
638         }
639
640         //=========================================================================
641
642         void wxGUIEditorGraphicBBS::OnCenterViewActualDiagram(wxCommandEvent& event)
643         {
644                 _tabsMgr->centerViewActualDiagram();
645         }
646
647         //=========================================================================
648
649         void wxGUIEditorGraphicBBS::OnOpenDiagram(wxCommandEvent& event)
650         {
651                 wxFileDialog * openFileDialog = new wxFileDialog(this,wxT("Open diagram"),wxEmptyString,wxT(""),wxT("*.bbg"),wxOPEN|wxFILE_MUST_EXIST);
652                 if (openFileDialog->ShowModal() == wxID_OK)
653                 {
654                         wxString fileName = openFileDialog->GetPath();
655                         ifstream inputStream;
656                         std::string fName=(const char*) (fileName.mb_str());
657                         inputStream.open( fName.c_str() );
658                         _tabsMgr->addNewTab( openFileDialog->GetFilename() );
659
660                         _tabsMgr->loadDiagram(inputStream);
661
662                         inputStream.close();
663                 }
664                 refreshGUIControls();
665         }
666
667         //=========================================================================
668
669
670         void wxGUIEditorGraphicBBS::OnClickBtnBox(wxCommandEvent& event)
671         {
672                 BlackBoxDescriptor      *bbDes = _pkgBrowser->GetActualSelected();
673         if (bbDes!=NULL)
674         {
675             std::string                 typeName        = bbDes->GetTypeName();
676             std::string                 packageName = bbDes->GetPackage()->GetName();
677
678
679             wxGEditorTabPanel *pnl = this->_tabsMgr->getActualTabPanel();
680
681             if (pnl!=NULL)
682             {
683                 wxVtkSceneManager *scn = pnl->getSceneManager();
684                 scn->createGBlackBox(50,50,packageName, typeName);
685                 scn->refresh();
686             } // if pnl
687         }// if bbDes
688         }
689
690         //=========================================================================
691
692
693         void wxGUIEditorGraphicBBS::OnClickBtnComplexBox(wxCommandEvent& event)
694         {
695                 wxToolBar* toolbar = GetToolBar();
696                 bool temp = toolbar->GetToolState(ID_BTNCOMPLEXBOX);
697                 if(temp)
698                 {
699                         _tabsMgr->setActualDiagramComplexBox(true);
700                 }
701                 else
702                 {
703                         _tabsMgr->setActualDiagramComplexBox(false);
704                 }
705                 refreshGUIControls();
706         }
707
708         //=========================================================================
709
710         void wxGUIEditorGraphicBBS::OnAddComplexBoxInput(wxCommandEvent& event)
711         {
712                 wxTextEntryDialog *nameDialog = new wxTextEntryDialog(this,wxT("Name of input port"));
713                 if (nameDialog->ShowModal() == wxID_OK)
714                 {
715                         wxString fileName = nameDialog->GetValue();
716                         if(!fileName.IsEmpty())
717                         {
718                                 std::string portName=(const char*) (fileName.mb_str());
719                                 _tabsMgr->addActualDiagramComplexInputPort(portName);
720                         }
721                 }
722         }
723
724         //=========================================================================
725
726         void wxGUIEditorGraphicBBS::OnAddComplexBoxOutput(wxCommandEvent& event)
727         {
728                 wxTextEntryDialog *nameDialog = new wxTextEntryDialog(this,wxT("Name of output port"));
729                 if (nameDialog->ShowModal() == wxID_OK)
730                 {
731                         wxString fileName = nameDialog->GetValue();
732                         if(!fileName.IsEmpty())
733                         {
734                                 std::string portName=(const char*) (fileName.mb_str());
735                                 _tabsMgr->addActualDiagramComplexOutputPort(portName);
736                         }
737                 }
738         }
739
740         //=========================================================================
741
742         void wxGUIEditorGraphicBBS::OnCopySelectedToComplexDiagram(wxCommandEvent& event)
743         {
744                 _tabsMgr->copySelectedBBoxesToComplexDiagram();
745         }
746
747
748         void wxGUIEditorGraphicBBS::OnHelpBBeditor(wxCommandEvent& event)
749         {
750                 printf("wxGUIEditorGraphicBBS::OnHelpBBeditor ......\n");
751         }
752
753
754
755         //=========================================================================
756
757         void wxGUIEditorGraphicBBS::OnExit(wxCommandEvent& event)
758         {
759                 Close(true);
760         }
761
762
763
764         //=========================================================================
765
766 }  // EO namespace bbtk
767
768 // EOF
769