1 /*=========================================================================
7 =========================================================================*/
9 /* ---------------------------------------------------------------------
11 * Copyright (c) CREATIS-LRMN (Centre de Recherche en Imagerie Medicale)
12 * Authors : Eduardo Davila, Laurent Guigues, Jean-Pierre Roux
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.
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
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 * ------------------------------------------------------------------------ */
33 * \brief Class bbtk::WxInterfaceEditorGraphicBBS .
36 #include "bbtkwxGUIEditorGraphicBBS.h"
38 #include "creaSystem.h"
40 #include <InterpreterBBS.h>
46 //=========================================================================
47 wxGUIEditorGraphicBBS::wxGUIEditorGraphicBBS(wxFrame *parent)
48 : wxFrame(parent, -1, _T("bbtkGEditor"),wxDefaultPosition, wxSize(1200,800))
51 _frameAUIMgr = new wxAuiManager(this);
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;
60 #ifdef LINUX // assume this is OSX
61 datadir=datadir+"/../share/creaContours";
64 #ifdef MACOSX // assume this is OSX
65 datadir=datadir+"/../../../../share/creaContours";
72 initTabPanelsManager();
74 initHelpHTMLBrowser();
77 _frameAUIMgr->Update();
78 _actualPkgBrowserBoxName="";
79 _actualPkgBrowserPkgName="";
84 //=========================================================================
85 wxGUIEditorGraphicBBS::~wxGUIEditorGraphicBBS()
87 printf ("EED %p ~wxGUIEditorGraphicBBS()\n" , this );
89 //EED02JUIN2010 delete _tabsMgr;
91 _frameAUIMgr->UnInit();
100 //=========================================================================
101 void wxGUIEditorGraphicBBS::initToolbar()
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_complexbox(complexbox_xpm);
111 wxBitmap bmp_complexinputport(complexinputport_xpm);
112 wxBitmap bmp_complexoutputport(complexoutputport_xpm);
114 wxToolBar *toolbar = new wxToolBar(this, wxID_ANY);
116 //Adds a tool btn to the toolbar
117 toolbar->AddTool(ID_NEW,_T("New"),bmp_new, wxNullBitmap, wxITEM_NORMAL,_T("New tab"), _T("Create a new panel tab"));
118 toolbar->AddTool(ID_OPEN,_T("Open diagram"),bmp_open, wxNullBitmap, wxITEM_NORMAL,_T("Open a diagram"), _T("Open a diagram"));
119 toolbar->AddTool(ID_SAVE_DIAGRAM,_T("Save Diagram"),bmp_save, wxNullBitmap, wxITEM_NORMAL,_T("Saves the current diagram"), _T("Saves the current diagram")); //DFCH
120 //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
121 toolbar->AddTool(ID_RUN,_T("Run"),bmp_run, wxNullBitmap, wxITEM_NORMAL,_T("Execute actual diagram"), _T("Execute actual diagram"));
122 toolbar->AddTool(ID_DELETEALL,_T("Delete all"),bmp_delete, wxNullBitmap, wxITEM_NORMAL,_T("Delete all boxes"), _T("Delete all boxes"));
123 toolbar->AddTool(ID_CENTERVIEW,_T("Center view"),bmp_centerview, wxNullBitmap, wxITEM_NORMAL,_T("Center view"), _T("Center view"));
124 toolbar->AddSeparator();
125 toolbar->AddTool(ID_BTNBOX,_T("New Box"),bmp_box, wxNullBitmap, wxITEM_NORMAL,_T("New Box"), _T("Nex Box"));
126 toolbar->AddSeparator();
127 toolbar->AddTool(ID_BTNCOMPLEXBOX,_T("Complex box"),complexbox_xpm, wxNullBitmap, wxITEM_NORMAL,_T("Complex box"), _T("Complex box"));
128 toolbar->SetToggle(ID_BTNCOMPLEXBOX,true);
129 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"));
130 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"));
131 toolbar->EnableTool(ID_ADDCOMPLEXBOXINPUT,false);
132 toolbar->EnableTool(ID_ADDCOMPLEXBOXOUTPUT,false);
134 toolbar->SetMargins( 2, 2 );
138 // connect command event handlers
139 Connect(ID_NEW,wxEVT_COMMAND_TOOL_CLICKED,wxCommandEventHandler(wxGUIEditorGraphicBBS::OnCreateNewTab));
140 Connect(ID_OPEN,wxEVT_COMMAND_TOOL_CLICKED,wxCommandEventHandler(wxGUIEditorGraphicBBS::OnOpenDiagram));
141 Connect(ID_SAVE_DIAGRAM,wxEVT_COMMAND_TOOL_CLICKED,wxCommandEventHandler(wxGUIEditorGraphicBBS::OnSaveActualDiagram)); //DFCH
142 Connect(ID_SAVE_AS_DIAGRAM,wxEVT_COMMAND_TOOL_CLICKED,wxCommandEventHandler(wxGUIEditorGraphicBBS::OnSaveAsActualDiagram)); //DFCH
143 Connect(ID_RUN,wxEVT_COMMAND_TOOL_CLICKED,wxCommandEventHandler(wxGUIEditorGraphicBBS::OnExecuteActualDiagram));
144 Connect(ID_DELETEALL,wxEVT_COMMAND_TOOL_CLICKED,wxCommandEventHandler(wxGUIEditorGraphicBBS::OnDeleteAllBoxesActualDiagram));
145 Connect(ID_CENTERVIEW,wxEVT_COMMAND_TOOL_CLICKED,wxCommandEventHandler(wxGUIEditorGraphicBBS::OnCenterViewActualDiagram));
146 Connect(ID_BTNBOX,wxEVT_COMMAND_TOOL_CLICKED,wxCommandEventHandler(wxGUIEditorGraphicBBS::OnClickBtnBox));
147 Connect(ID_BTNCOMPLEXBOX,wxEVT_COMMAND_TOOL_CLICKED,wxCommandEventHandler(wxGUIEditorGraphicBBS::OnClickBtnComplexBox));
148 Connect(ID_ADDCOMPLEXBOXINPUT,wxEVT_COMMAND_TOOL_CLICKED,wxCommandEventHandler(wxGUIEditorGraphicBBS::OnAddComplexBoxInput));
149 Connect(ID_ADDCOMPLEXBOXOUTPUT,wxEVT_COMMAND_TOOL_CLICKED,wxCommandEventHandler(wxGUIEditorGraphicBBS::OnAddComplexBoxOutput));
152 //=========================================================================
153 void wxGUIEditorGraphicBBS::initHelpHTMLBrowser()
155 //TO FIX THE PATH OF BBTK BIN IN ORDER TO USE REGENERATE EXECUTABLES
157 _helpHtmlBrowser = new WxGUIHtmlBrowser(this,wxSize(200,0));
158 _frameAUIMgr->AddPane(_helpHtmlBrowser,wxAuiPaneInfo().Right().MinSize(200,200));
161 //=========================================================================
162 void wxGUIEditorGraphicBBS::initMenu()
164 // Create File menu and its items
165 wxMenu *fileMenu = new wxMenu();
166 fileMenu->Append(ID_NEW, _T("New diagram"), _T("New"));
167 fileMenu->Append(ID_SAVE_DIAGRAM, _T("Save Diagram"), _T("Save Diagram")); //DFCH
168 fileMenu->Append(ID_SAVE_AS_DIAGRAM, _T("Save Diagram As"), _T("Save Diagram As")); //DFCH
169 fileMenu->Append(ID_OPEN_BBS, _T("Open BBS"), _T("Open BBS"));
170 fileMenu->Append(ID_SAVE_AS_BBS, _T("Save BBS"), _T("Save BBS"));
171 fileMenu->Append(ID_SAVE_AS_COMPLEXBOX, _T("Save complex box"), _T("Save complex box"));
172 fileMenu->Append(wxID_EXIT, _T("E&xit"), _T("Exit"));
174 Connect(ID_NEW,wxEVT_COMMAND_MENU_SELECTED,wxCommandEventHandler(wxGUIEditorGraphicBBS::OnCreateNewTab));
175 Connect(ID_SAVE_DIAGRAM,wxEVT_COMMAND_MENU_SELECTED,wxCommandEventHandler(wxGUIEditorGraphicBBS::OnSaveActualDiagram)); //DFCH
176 Connect(ID_SAVE_AS_DIAGRAM,wxEVT_COMMAND_MENU_SELECTED,wxCommandEventHandler(wxGUIEditorGraphicBBS::OnSaveAsActualDiagram));
177 Connect(ID_OPEN_BBS,wxEVT_COMMAND_MENU_SELECTED,wxCommandEventHandler(wxGUIEditorGraphicBBS::OnOpenBBS));
178 Connect(ID_SAVE_AS_BBS,wxEVT_COMMAND_MENU_SELECTED,wxCommandEventHandler(wxGUIEditorGraphicBBS::OnSaveActualBBS));
179 Connect(ID_SAVE_AS_COMPLEXBOX,wxEVT_COMMAND_MENU_SELECTED,wxCommandEventHandler(wxGUIEditorGraphicBBS::OnSaveActualComplexBox));
180 Connect(wxID_EXIT,wxEVT_COMMAND_MENU_SELECTED,wxCommandEventHandler(wxGUIEditorGraphicBBS::OnExit));
182 // Create Help menu and its items
183 wxMenu *editMenu = new wxMenu;
184 editMenu->Append(ID_COPY_TO_COMPLEXDIAGRAM, _T("Copy selected to complex box"), _T("Creates a new complex box diagram with selected boxes"));
186 Connect(ID_COPY_TO_COMPLEXDIAGRAM,wxEVT_COMMAND_MENU_SELECTED,wxCommandEventHandler(wxGUIEditorGraphicBBS::OnCopySelectedToComplexDiagram));
188 // Create Help menu and its items
189 wxMenu *helpMenu = new wxMenu;
190 helpMenu->Append(wxID_ABOUT, _T("&About..."), _T("About"));
191 helpMenu->Append(ID_HELP_BBEDITOR, _T("&Help..."), _T("Help"));
192 Connect(ID_HELP_BBEDITOR,wxEVT_COMMAND_MENU_SELECTED,wxCommandEventHandler(wxGUIEditorGraphicBBS::OnHelpBBeditor));
194 // Append the created menu to the menu bar
195 wxMenuBar *menuBar = new wxMenuBar();
196 menuBar->Append(fileMenu, _T("&File"));
197 menuBar->Append(editMenu, _T("&Edit"));
198 menuBar->Append(helpMenu, _T("&Help"));
200 // Attach this menu bar to the frame
204 //=========================================================================
205 void wxGUIEditorGraphicBBS::initTabPanelsManager()
207 _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);
208 _tabsMgr = new wxTabPanelsManager(this);
209 _frameAUIMgr->AddPane(_notebook,wxAuiPaneInfo().CenterPane());
213 //=========================================================================
214 void wxGUIEditorGraphicBBS::initPackageBrowser()
216 _pkgBrowser = new WxGUIPackageBrowser2(this);
217 _pkgBrowser->IncludeAll();
218 _frameAUIMgr->AddPane(_pkgBrowser,wxAuiPaneInfo().Left().MinSize(200,200).CloseButton(false));
221 //================================================================
223 void wxGUIEditorGraphicBBS::DoRegeneratePackageDoc( const std::string& pack )
225 std::string mess("Regenerating doc for package '");
231 mess = "Regenerating doc for all packages";
234 mess += " ... please wait";
236 SetStatusText( std2wx(mess) );
244 command += ConfigurationFile::GetInstance().Get_bin_path();
245 command += ConfigurationFile::GetInstance().Get_file_separator();
246 command += "bbRegeneratePackageDoc";
251 command += " " + pack + " -q";
252 bbtkMessage("debug",1,"Executing system command '"<<command<<"'"<<std::endl);
254 if ( ! system ( command.c_str() ) )
256 SetStatusText( _T("Done !"));
258 wxMessageBox(_T("Done !"),_T("Regenerate package '")
259 +std2wx(pack)+_T("' doc"),
260 wxOK | wxICON_INFORMATION);
265 SetStatusText( _T("Done !"));
266 wxString err(_T("An error occured while running '"));
267 err += bbtk::std2wx(command) + _T("'");
268 wxMessageBox(err,_T("Regenerate package doc"),wxOK | wxICON_ERROR);
272 //================================================================
273 void wxGUIEditorGraphicBBS::DoRegenerateBoxesLists()
275 SetStatusText( _T("Regenerating boxes lists ... please wait") );
282 command += ConfigurationFile::GetInstance().Get_bin_path();
283 command += ConfigurationFile::GetInstance().Get_file_separator();
284 command += "bbRegenerateBoxesLists";
291 bbtkMessage("debug",1,"Executing system command '"<<command<<"'"<<std::endl);
293 if ( ! system ( command.c_str() ) )
295 SetStatusText( _T("Done !"));
297 wxMessageBox(_T("Done !"),_T("Regenerate boxes lists"),
298 wxOK | wxICON_INFORMATION);
303 SetStatusText( _T("Done !"));
304 wxString err(_T("An error occured while running '"));
305 err += bbtk::std2wx(command) + _T("'");
306 wxMessageBox(err,_T("Regenerate boxes lists"),wxOK | wxICON_ERROR);
310 //================================================================
311 void wxGUIEditorGraphicBBS::RegenerateAll()
313 DoRegeneratePackageDoc("-a");
314 DoRegenerateBoxesLists();
317 //================================================================
319 wxAuiNotebook* wxGUIEditorGraphicBBS::getAuiNotebook()
324 //================================================================
326 void wxGUIEditorGraphicBBS::displayBlackBoxInfo(std::string packageName, std::string boxName)
328 if(_actualPkgBrowserPkgName != packageName || _actualPkgBrowserBoxName != boxName )
330 _actualPkgBrowserPkgName = packageName;
331 _actualPkgBrowserBoxName = boxName;
333 BlackBoxDescriptor::Pointer descriptor = GObjectsMVCFactory::getInstance()->getBlackBoxDescriptor(packageName, boxName);
334 _pkgBrowser->WxGUIBlackBoxListUserOnSelected(descriptor.get());
338 //=========================================================================
340 void wxGUIEditorGraphicBBS::editBlackBox(GBlackBoxModel *bbmodel)
342 wxBlackBoxEditionDialog* dialog = new wxBlackBoxEditionDialog(this,bbmodel);
346 //=========================================================================
348 void wxGUIEditorGraphicBBS::updateStatusBar(std::string textStatus)
350 SetStatusText(crea::std2wx(textStatus));
353 //=========================================================================
355 void wxGUIEditorGraphicBBS::executeScript(std::string script)
357 std::string separator = ConfigurationFile::GetInstance().Get_file_separator ();
358 std::string dir = ConfigurationFile::GetInstance().Get_default_temp_dir();
359 std::string filename = dir + separator + "tmp_bbtk.bbs";
362 tempFile.open(filename.c_str());
366 std::string command = "";
371 command += "\""+ crea::System::GetExecutablePath();
375 command += separator + "../../../bbi.app/Contents/MacOS";
381 //command += ConfigurationFile::GetInstance().Get_bin_path();
382 //EED command +="C:/temp/bbtkBIN/RelWithDebInfo//";
383 //EED command +="C:/Program Files/CreaTools/bbtk-0.9.5/bin";
387 command += separator + "usr/local/bin/bbi.app/Contents/MacOS/bbi\" ";
390 command += separator + "bbi\" ";
393 command += separator + "bbi\" ";
394 command += "\""+filename + "\"";
403 printf ("RaC wxGUIEditorGraphicBBS::executeScript %s \n" , command.c_str() );
404 system( command.c_str() );
407 //=========================================================================
409 //=========================================================================
411 void wxGUIEditorGraphicBBS::OnCreateNewTab(wxCommandEvent& event)
413 _tabsMgr->addNewTab();
414 refreshGUIControls();
417 //=========================================================================
419 void wxGUIEditorGraphicBBS::OnExecuteActualDiagram(wxCommandEvent& event)
421 std::string script1 = _tabsMgr->getActualDiagramBBS(true);
422 cout<<endl<<"RaC wxGUIEditorGraphicBBS::executeActualDiagram SCRIPT"<<endl<<endl;
425 std::string script2 = _tabsMgr->getActualDiagramBBS(false);
426 executeScript(script2);
430 //=========================================================================
432 //=========================================================================
433 void wxGUIEditorGraphicBBS::OnOpenBBS(wxCommandEvent& event)
435 wxFileDialog * openFileDialog = new wxFileDialog(this,wxT("Open BBS"),wxEmptyString,wxT("NewBBS"),wxT("*.bbs"),wxOPEN);
436 if (openFileDialog->ShowModal() == wxID_OK)
438 wxString fileName = openFileDialog->GetPath( );
441 _tabsMgr->addNewTab( openFileDialog->GetFilename() );
443 bbtk::InterpreterBBS::Pointer I = bbtk::InterpreterBBS::New( this->_tabsMgr->getActualTabPanel()->getSceneManager() , _pkgBrowser->GetFactory());
445 // We tell the interpreter to throw exceptions on error
447 // Interpret the file supposed to define a box called 'Processing'
448 I->InterpretFile( (const char*) (fileName.mb_str()) );
450 refreshGUIControls();
455 void wxGUIEditorGraphicBBS::SaveActualBBS(std::string filename)
459 //EED file.open(fileName.c_str());
460 file.open( filename.c_str() );
461 std::string content="";
462 // writing file header
463 content += "# ----------------------------------\n";
464 content += "# - BBTKGEditor v 1.2 BBS BlackBox Script\n";
468 content += "# ----------------------------------\n";
470 content += _tabsMgr->getActualDiagramBBS();
476 void wxGUIEditorGraphicBBS::OnSaveActualBBS(wxCommandEvent& event)
478 wxFileDialog * saveFileDialog = new wxFileDialog(this,wxT("Save actual BBS"),wxEmptyString,wxT("NewBBS"),wxT("*.bbs"),wxSAVE|wxOVERWRITE_PROMPT);
479 if (saveFileDialog->ShowModal() == wxID_OK)
481 wxString fileName = saveFileDialog->GetPath( );
482 SaveActualBBS( (const char*) (fileName.mb_str()) );
488 void wxGUIEditorGraphicBBS::AskComplexBoxConfiguration()
490 std::string cbName = _tabsMgr->GetCbName();
491 std::string paName = _tabsMgr->GetCbPackageName();
493 wxTextEntryDialog *cbNameDialog = new wxTextEntryDialog(this,wxT("Complex Box name"));
494 wxTextEntryDialog *paNameDialog = new wxTextEntryDialog(this,wxT("Package name"));
496 cbNameDialog->SetValue( wxString(cbName.c_str(),wxConvUTF8) );
497 paNameDialog->SetValue( wxString(paName.c_str(),wxConvUTF8) );
499 if (cbNameDialog->ShowModal() == wxID_OK)
501 wxString complexboxname = cbNameDialog->GetValue();
502 cbName=(const char*) (complexboxname.mb_str());
506 if (paNameDialog->ShowModal() == wxID_OK)
508 wxString packagename = paNameDialog->GetValue();
509 paName=(const char*) (packagename.mb_str());
512 _tabsMgr->SetCbName(cbName);
513 _tabsMgr->SetCbPackageName(paName);
516 //=========================================================================
518 void wxGUIEditorGraphicBBS::SaveActualComplexBox(std::string filename)
521 file.open( filename.c_str() );
523 std::string content="";
525 // writing file header
526 content += "# ----------------------------------\n";
527 content += "# - BBTKGEditor v 1.2 BBS BlackBox Script (Complex Box)\n";
531 content += "# ----------------------------------\n";
533 content += _tabsMgr->getActualComplexBoxBBS();
538 //=========================================================================
540 void wxGUIEditorGraphicBBS::OnSaveActualComplexBox(wxCommandEvent& event)
542 wxFileDialog * saveFileDialog = new wxFileDialog(this ,wxT("Save Complex Box BBS") ,wxEmptyString, _T("ComplexBoxName") ,wxT("*.bbs"), wxSAVE | wxOVERWRITE_PROMPT);
543 if (saveFileDialog->ShowModal() == wxID_OK)
545 wxString fileName = saveFileDialog->GetPath();
546 SaveActualComplexBox( (const char*) (fileName.mb_str()) );
550 //=========================================================================
551 void wxGUIEditorGraphicBBS::SaveActualDiagram(std::string filename)
554 file.open( filename.c_str() );
556 std::string content="";
558 // writing file header
559 content += "# ----------------------------------\n";
560 content += "# - BBTKGEditor v 1.2 BBG BlackBox Diagram file\n";
566 content += "# ----------------------------------\n";
568 content += "APP_START\n";
569 _tabsMgr->saveActualDiagram(content);
570 content += "APP_END\n";
575 //=========================================================================
577 //The following method allows to save the current diagram asking the filename
579 void wxGUIEditorGraphicBBS::SaveCurrentDiagramAs( )
581 wxFileDialog * saveFileDialog = new wxFileDialog(this,wxT("Save current diagram"),wxEmptyString,wxT("NewDiagram"),wxT("*.bbg"),wxSAVE|wxOVERWRITE_PROMPT);
582 if (saveFileDialog->ShowModal() == wxID_OK)
584 _tabsMgr->SetNameTabPanel( saveFileDialog->GetFilename() );
585 wxString pathfileName = saveFileDialog->GetPath();
586 std::string pathfilename = (const char*) (pathfileName.mb_str());
587 std::string pathfilenamebbs = pathfilename;
588 pathfilenamebbs[pathfilenamebbs.length()-1]='s';
589 if (_tabsMgr->isActualDiagramComplexBox()==false)
591 SaveActualDiagram( pathfilename );
592 SaveActualBBS(pathfilenamebbs);
594 AskComplexBoxConfiguration();
595 SaveActualDiagram( pathfilename );
596 SaveActualComplexBox(pathfilenamebbs);
597 } //if isActualDiagramComplexBox
598 } // if saveFileDialog
600 //=========================================================================
602 void wxGUIEditorGraphicBBS::OnSaveActualDiagram(wxCommandEvent& event)
604 std::string pathfilename = _tabsMgr->GetCurrentTabPanelPath();
605 if( pathfilename.empty() )
607 SaveCurrentDiagramAs();
611 std::string pathfilenamebbs = pathfilename;
612 pathfilenamebbs[pathfilenamebbs.length()-1]='s';
614 if (_tabsMgr->isActualDiagramComplexBox()==false)
616 SaveActualDiagram( pathfilename );
617 SaveActualBBS(pathfilenamebbs);
619 AskComplexBoxConfiguration();
620 SaveActualDiagram( pathfilename );
621 SaveActualComplexBox(pathfilenamebbs);
622 } //if isActualDiagramComplexBox
625 //=========================================================================
627 void wxGUIEditorGraphicBBS::OnSaveAsActualDiagram(wxCommandEvent& event)
629 SaveCurrentDiagramAs();
631 //=========================================================================
633 void wxGUIEditorGraphicBBS::refreshGUIControls()
635 wxToolBar* toolbar = GetToolBar();
636 if(_tabsMgr->isActualDiagramComplexBox())
638 toolbar->ToggleTool(ID_BTNCOMPLEXBOX,true);
639 toolbar->EnableTool(ID_ADDCOMPLEXBOXINPUT,true);
640 toolbar->EnableTool(ID_ADDCOMPLEXBOXOUTPUT,true);
642 GetMenuBar()->GetMenu(0)->Enable(ID_SAVE_AS_COMPLEXBOX,true);
643 GetMenuBar()->GetMenu(0)->Enable(ID_SAVE_AS_BBS,false);
647 toolbar->ToggleTool(ID_BTNCOMPLEXBOX,false);
648 toolbar->EnableTool(ID_ADDCOMPLEXBOXINPUT,false);
649 toolbar->EnableTool(ID_ADDCOMPLEXBOXOUTPUT,false);
651 GetMenuBar()->GetMenu(0)->Enable(ID_SAVE_AS_COMPLEXBOX,false);
652 GetMenuBar()->GetMenu(0)->Enable(ID_SAVE_AS_BBS,true);
655 if(_tabsMgr->getNumActualSelectedObjects()>0)
657 GetMenuBar()->GetMenu(1)->Enable(ID_COPY_TO_COMPLEXDIAGRAM,true);
661 ///TODO Fix the possibility to say from the SceneManager to the GUI to refresh the options
662 GetMenuBar()->GetMenu(1)->Enable(ID_COPY_TO_COMPLEXDIAGRAM,true);
667 //=========================================================================
669 void wxGUIEditorGraphicBBS::OnDeleteAllBoxesActualDiagram(wxCommandEvent& event)
671 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);
672 if(dial->ShowModal() == wxID_YES)
674 _tabsMgr->deleteAllBoxesActualDiagram();
678 //=========================================================================
680 void wxGUIEditorGraphicBBS::OnCenterViewActualDiagram(wxCommandEvent& event)
682 _tabsMgr->centerViewActualDiagram();
685 //=========================================================================
687 void wxGUIEditorGraphicBBS::OnOpenDiagram(wxCommandEvent& event)
689 wxFileDialog * openFileDialog = new wxFileDialog(this,wxT("Open diagram"),wxEmptyString,wxT(""),wxT("*.bbg"),wxOPEN|wxFILE_MUST_EXIST);
690 if (openFileDialog->ShowModal() == wxID_OK)
692 wxString fileName = openFileDialog->GetPath();
693 ifstream inputStream;
694 std::string fName=(const char*) (fileName.mb_str());
695 inputStream.open( fName.c_str() );
696 _tabsMgr->addNewTab( openFileDialog->GetFilename() );
698 _tabsMgr->loadDiagram(inputStream);
702 refreshGUIControls();
705 //=========================================================================
708 void wxGUIEditorGraphicBBS::OnClickBtnBox(wxCommandEvent& event)
710 BlackBoxDescriptor *bbDes = _pkgBrowser->GetActualSelected();
713 std::string typeName = bbDes->GetTypeName();
714 std::string packageName = bbDes->GetPackage()->GetName();
717 wxGEditorTabPanel *pnl = this->_tabsMgr->getActualTabPanel();
721 wxVtkSceneManager *scn = pnl->getSceneManager();
722 scn->createGBlackBox(50,50,packageName, typeName);
728 //=========================================================================
731 void wxGUIEditorGraphicBBS::OnClickBtnComplexBox(wxCommandEvent& event)
733 wxToolBar* toolbar = GetToolBar();
734 bool temp = toolbar->GetToolState(ID_BTNCOMPLEXBOX);
737 _tabsMgr->setActualDiagramComplexBox(true);
741 _tabsMgr->setActualDiagramComplexBox(false);
743 refreshGUIControls();
746 //=========================================================================
748 void wxGUIEditorGraphicBBS::OnAddComplexBoxInput(wxCommandEvent& event)
750 wxTextEntryDialog *nameDialog = new wxTextEntryDialog(this,wxT("Name of input port"));
751 if (nameDialog->ShowModal() == wxID_OK)
753 wxString fileName = nameDialog->GetValue();
754 if(!fileName.IsEmpty())
756 std::string portName=(const char*) (fileName.mb_str());
757 _tabsMgr->addActualDiagramComplexInputPort(portName);
762 //=========================================================================
764 void wxGUIEditorGraphicBBS::OnAddComplexBoxOutput(wxCommandEvent& event)
766 wxTextEntryDialog *nameDialog = new wxTextEntryDialog(this,wxT("Name of output port"));
767 if (nameDialog->ShowModal() == wxID_OK)
769 wxString fileName = nameDialog->GetValue();
770 if(!fileName.IsEmpty())
772 std::string portName=(const char*) (fileName.mb_str());
773 _tabsMgr->addActualDiagramComplexOutputPort(portName);
778 //=========================================================================
780 void wxGUIEditorGraphicBBS::OnCopySelectedToComplexDiagram(wxCommandEvent& event)
782 _tabsMgr->copySelectedBBoxesToComplexDiagram();
786 void wxGUIEditorGraphicBBS::OnHelpBBeditor(wxCommandEvent& event)
788 printf("wxGUIEditorGraphicBBS::OnHelpBBeditor ......\n");
793 //=========================================================================
795 void wxGUIEditorGraphicBBS::OnExit(wxCommandEvent& event)
802 //=========================================================================
804 } // EO namespace bbtk