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>
44 //=========================================================================
45 wxGUIEditorGraphicBBS::wxGUIEditorGraphicBBS(wxFrame *parent) :
46 wxFrame(parent, -1, _T("bbtkGEditor"), wxDefaultPosition, wxSize(
49 _frameAUIMgr = new wxAuiManager(this);
51 /*std::string datadir( crea::System::GetExecutablePath() );
52 std::string datadir (".");
53 cout<<"RaC //------------------"<<endl;
54 cout<<"RaC //TODO wxGUIEditorGraphicBBS constructor.Initialize datadir with crea::System::GetExecutablePath() ."<<endl;
55 cout<<"RaC //------------------"<<endl;
57 #ifdef LINUX // assume this is OSX
58 datadir=datadir+"/../share/creaContours";
61 #ifdef MACOSX // assume this is OSX
62 datadir=datadir+"/../../../../share/creaContours";
69 initTabPanelsManager();
71 initHelpHTMLBrowser();
74 _frameAUIMgr->Update();
75 _actualPkgBrowserBoxName = "";
76 _actualPkgBrowserPkgName = "";
80 //=========================================================================
81 wxGUIEditorGraphicBBS::~wxGUIEditorGraphicBBS() {
82 printf("EED %p ~wxGUIEditorGraphicBBS()\n", this);
84 //EED02JUIN2010 delete _tabsMgr;
86 _frameAUIMgr->UnInit();
94 //=========================================================================
95 void wxGUIEditorGraphicBBS::initToolbar() {
96 wxBitmap bmp_new(new_xpm);
97 wxBitmap bmp_open(open_xpm);
98 wxBitmap bmp_save(save_xpm);
99 wxBitmap bmp_run(run_xpm);
100 wxBitmap bmp_delete(delete_xpm);
101 wxBitmap bmp_centerview(centerview_xpm);
102 wxBitmap bmp_box(box_xpm);
103 wxBitmap bmp_executablebox(executablebox_xpm);
104 wxBitmap bmp_complexbox(complexbox_xpm);
105 wxBitmap bmp_complexinputport(complexinputport_xpm);
106 wxBitmap bmp_complexoutputport(complexoutputport_xpm);
108 wxToolBar *toolbar = new wxToolBar(this, wxID_ANY);
110 //Adds a tool btn to the toolbar
111 toolbar->AddTool(ID_NEW, _T("New"), bmp_new, wxNullBitmap, wxITEM_NORMAL,
112 _T("New tab"), _T("Create a new panel tab"));
113 toolbar->AddTool(ID_OPEN, _T("Open diagram"), bmp_open, wxNullBitmap,
114 wxITEM_NORMAL, _T("Open a diagram"), _T("Open a diagram"));
115 toolbar->AddTool(ID_SAVE_DIAGRAM, _T("Save Diagram"), bmp_save,
116 wxNullBitmap, wxITEM_NORMAL, _T("Saves the current diagram"),
117 _T("Saves the current diagram")); //DFCH
118 //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
119 toolbar->AddTool(ID_RUN, _T("Run"), bmp_run, wxNullBitmap, wxITEM_NORMAL,
120 _T("Execute actual diagram"), _T("Execute actual diagram"));
121 toolbar->AddTool(ID_DELETEALL, _T("Delete all"), bmp_delete, wxNullBitmap,
122 wxITEM_NORMAL, _T("Delete all boxes"), _T("Delete all boxes"));
123 toolbar->AddTool(ID_CENTERVIEW, _T("Center view"), bmp_centerview,
124 wxNullBitmap, wxITEM_NORMAL, _T("Center view"), _T("Center view"));
125 toolbar->AddSeparator();
126 toolbar->AddTool(ID_BTNBOX, _T("New Box"), bmp_box, wxNullBitmap,
127 wxITEM_NORMAL, _T("New Box"), _T("Nex Box"));
128 toolbar->AddSeparator();
129 toolbar->AddTool(ID_BTEXECUTABLEBOX, _T("Select as executable Box"),
130 bmp_executablebox, wxNullBitmap, wxITEM_NORMAL,
131 _T("Select as executable Box"), _T("Select as executable Box"));
132 toolbar->AddSeparator();
133 toolbar->AddTool(ID_BTNCOMPLEXBOX, _T("Complex box"), complexbox_xpm,
134 wxNullBitmap, wxITEM_NORMAL, _T("Complex box"), _T("Complex box"));
135 toolbar->SetToggle(ID_BTNCOMPLEXBOX, true);
136 toolbar->AddTool(ID_ADDCOMPLEXBOXINPUT, _T("Add input to Complex box"),
137 bmp_complexinputport, wxNullBitmap, wxITEM_NORMAL,
138 _T("Add input to Complex box"), _T("Add input to Complex box"));
139 toolbar->AddTool(ID_ADDCOMPLEXBOXOUTPUT, _T("Add output to Complex box"),
140 bmp_complexoutputport, wxNullBitmap, wxITEM_NORMAL,
141 _T("Add output Complex box"), _T("Add output Complex box"));
142 toolbar->EnableTool(ID_ADDCOMPLEXBOXINPUT, false);
143 toolbar->EnableTool(ID_ADDCOMPLEXBOXOUTPUT, false);
145 toolbar->SetMargins(2, 2);
149 // connect command event handlers
150 Connect(ID_NEW, wxEVT_COMMAND_TOOL_CLICKED,
151 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnCreateNewTab));
152 Connect(ID_OPEN, wxEVT_COMMAND_TOOL_CLICKED,
153 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnOpenDiagram));
154 Connect(ID_SAVE_DIAGRAM, wxEVT_COMMAND_TOOL_CLICKED,
155 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnSaveActualDiagram)); //DFCH
156 Connect(ID_SAVE_AS_DIAGRAM, wxEVT_COMMAND_TOOL_CLICKED,
157 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnSaveAsActualDiagram)); //DFCH
160 wxEVT_COMMAND_TOOL_CLICKED,
161 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnExecuteActualDiagram));
164 wxEVT_COMMAND_TOOL_CLICKED,
165 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnDeleteAllBoxesActualDiagram));
168 wxEVT_COMMAND_TOOL_CLICKED,
169 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnCenterViewActualDiagram));
170 Connect(ID_BTNBOX, wxEVT_COMMAND_TOOL_CLICKED,
171 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnClickBtnBox));
174 wxEVT_COMMAND_TOOL_CLICKED,
175 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnClickBtnExecutableBox));
176 Connect(ID_BTNCOMPLEXBOX, wxEVT_COMMAND_TOOL_CLICKED,
177 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnClickBtnComplexBox));
178 Connect(ID_ADDCOMPLEXBOXINPUT, wxEVT_COMMAND_TOOL_CLICKED,
179 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnAddComplexBoxInput));
180 Connect(ID_ADDCOMPLEXBOXOUTPUT, wxEVT_COMMAND_TOOL_CLICKED,
181 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnAddComplexBoxOutput));
184 //=========================================================================
185 void wxGUIEditorGraphicBBS::initHelpHTMLBrowser() {
186 //TO FIX THE PATH OF BBTK BIN IN ORDER TO USE REGENERATE EXECUTABLES
188 _helpHtmlBrowser = new WxGUIHtmlBrowser(this, wxSize(200, 0));
189 _frameAUIMgr->AddPane(_helpHtmlBrowser, wxAuiPaneInfo().Right().MinSize(
193 //=========================================================================
194 void wxGUIEditorGraphicBBS::initMenu() {
195 // Create File menu and its items
196 wxMenu *fileMenu = new wxMenu();
197 fileMenu->Append(ID_NEW, _T("New diagram"), _T("New"));
198 fileMenu->Append(ID_SAVE_DIAGRAM, _T("Save Diagram"), _T("Save Diagram")); //DFCH
199 fileMenu->Append(ID_SAVE_AS_DIAGRAM, _T("Save Diagram As"),
200 _T("Save Diagram As")); //DFCH
201 fileMenu->Append(ID_OPEN_BBS, _T("Open BBS"), _T("Open BBS"));
202 fileMenu->Append(ID_SAVE_AS_BBS, _T("Save BBS"), _T("Save BBS"));
203 fileMenu->Append(ID_SAVE_AS_COMPLEXBOX, _T("Save complex box"),
204 _T("Save complex box"));
205 fileMenu->Append(wxID_EXIT, _T("E&xit"), _T("Exit"));
207 Connect(ID_NEW, wxEVT_COMMAND_MENU_SELECTED,
208 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnCreateNewTab));
209 Connect(ID_SAVE_DIAGRAM, wxEVT_COMMAND_MENU_SELECTED,
210 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnSaveActualDiagram)); //DFCH
211 Connect(ID_SAVE_AS_DIAGRAM, wxEVT_COMMAND_MENU_SELECTED,
212 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnSaveAsActualDiagram));
213 Connect(ID_OPEN_BBS, wxEVT_COMMAND_MENU_SELECTED,
214 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnOpenBBS));
215 Connect(ID_SAVE_AS_BBS, wxEVT_COMMAND_MENU_SELECTED,
216 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnSaveActualBBS));
218 ID_SAVE_AS_COMPLEXBOX,
219 wxEVT_COMMAND_MENU_SELECTED,
220 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnSaveActualComplexBox));
221 Connect(wxID_EXIT, wxEVT_COMMAND_MENU_SELECTED,
222 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnExit));
224 // Create Help menu and its items
225 wxMenu *editMenu = new wxMenu;
226 editMenu->Append(ID_COPY_TO_COMPLEXDIAGRAM,
227 _T("Copy selected to complex box"),
228 _T("Creates a new complex box diagram with selected boxes"));
231 ID_COPY_TO_COMPLEXDIAGRAM,
232 wxEVT_COMMAND_MENU_SELECTED,
233 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnCopySelectedToComplexDiagram));
235 // Create Help menu and its items
236 wxMenu *helpMenu = new wxMenu;
237 helpMenu->Append(wxID_ABOUT, _T("&About..."), _T("About"));
238 helpMenu->Append(ID_HELP_BBEDITOR, _T("&Help..."), _T("Help"));
239 Connect(ID_HELP_BBEDITOR, wxEVT_COMMAND_MENU_SELECTED,
240 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnHelpBBeditor));
243 wxMenu *menuTools = new wxMenu;
244 menuTools->Append(ID_bbEditor_Tool_Menu_CreatePackage,
245 _T("Create &package") );
246 menuTools->Append(ID_bbEditor_Tool_Menu_CreateBlackBox,
247 _T("Create &blackbox") );
248 menuTools->Append(ID_bbEditor_Tool_Menu_PlugPackage, _T("Plug package") );
249 menuTools->Append(ID_bbEditor_Tool_Menu_EditConfig, _T("&Edit bbtk config") );
250 menuTools->Append(ID_bbEditor_Tool_Menu_ShowHTMLDoc,
251 _T("Show &HTML documentation") );
252 menuTools->Append(ID_bbEditor_Tool_Menu_CreateIndex, _T("&Generate index") );
254 Connect(ID_bbEditor_Tool_Menu_CreatePackage, wxEVT_COMMAND_MENU_SELECTED,
255 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnCreatePackage));
256 Connect(ID_bbEditor_Tool_Menu_CreateBlackBox, wxEVT_COMMAND_MENU_SELECTED,
257 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnCreateBlackBox));
258 Connect(ID_bbEditor_Tool_Menu_PlugPackage, wxEVT_COMMAND_MENU_SELECTED,
259 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnPlugPackage));
260 Connect(ID_bbEditor_Tool_Menu_EditConfig, wxEVT_COMMAND_MENU_SELECTED,
261 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnEditConfig));
262 Connect(ID_bbEditor_Tool_Menu_ShowHTMLDoc, wxEVT_COMMAND_MENU_SELECTED,
263 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnShowHTMLDoc));
264 Connect(ID_bbEditor_Tool_Menu_CreateIndex, wxEVT_COMMAND_MENU_SELECTED,
265 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnCreateIndex));
267 // Append the created menu to the menu bar
268 wxMenuBar *menuBar = new wxMenuBar();
269 menuBar->Append(fileMenu, _T("&File") );
270 menuBar->Append(editMenu, _T("&Edit") );
271 menuBar->Append(menuTools, _T("&Tool") );
272 menuBar->Append(helpMenu, _T("&Help") );
274 // Attach this menu bar to the frame
278 //=========================================================================
279 void wxGUIEditorGraphicBBS::initTabPanelsManager() {
280 _notebook = new wxAuiNotebook(this, wxID_NOTEBOOK, wxDefaultPosition,
281 wxDefaultSize, wxAUI_NB_TOP | wxAUI_NB_TAB_MOVE
282 | wxAUI_NB_CLOSE_ON_ACTIVE_TAB | wxAUI_NB_TAB_FIXED_WIDTH
283 | wxAUI_NB_WINDOWLIST_BUTTON);
284 _tabsMgr = new wxTabPanelsManager(this);
285 _frameAUIMgr->AddPane(_notebook, wxAuiPaneInfo().CenterPane());
289 //=========================================================================
290 void wxGUIEditorGraphicBBS::initPackageBrowser() {
291 _pkgBrowser = new WxGUIPackageBrowser2(this);
292 _pkgBrowser->IncludeAll();
293 _frameAUIMgr->AddPane(_pkgBrowser,
294 wxAuiPaneInfo().Left().MinSize(200, 200).CloseButton(false));
297 //================================================================
299 void wxGUIEditorGraphicBBS::DoRegeneratePackageDoc(const std::string& pack) {
300 std::string mess("Regenerating doc for package '");
304 mess = "Regenerating doc for all packages";
307 mess += " ... please wait";
309 SetStatusText(std2wx(mess));
317 command += ConfigurationFile::GetInstance().Get_bin_path();
318 command += ConfigurationFile::GetInstance().Get_file_separator();
319 command += "bbRegeneratePackageDoc";
324 command += " " + pack + " -q";
325 bbtkMessage("debug",1,"Executing system command '"<<command<<"'"<<std::endl);
327 if (!system(command.c_str())) {
328 SetStatusText(_T("Done !"));
330 wxMessageBox(_T("Done !"),_T("Regenerate package '")
331 +std2wx(pack)+_T("' doc"),
332 wxOK | wxICON_INFORMATION);
335 SetStatusText(_T("Done !"));
336 wxString err(_T("An error occured while running '"));
337 err += bbtk::std2wx(command) + _T("'");
338 wxMessageBox(err, _T("Regenerate package doc"), wxOK | wxICON_ERROR);
342 //================================================================
343 void wxGUIEditorGraphicBBS::DoRegenerateBoxesLists() {
344 SetStatusText(_T("Regenerating boxes lists ... please wait"));
351 command += ConfigurationFile::GetInstance().Get_bin_path();
352 command += ConfigurationFile::GetInstance().Get_file_separator();
353 command += "bbRegenerateBoxesLists";
360 bbtkMessage("debug",1,"Executing system command '"<<command<<"'"<<std::endl);
362 if (!system(command.c_str())) {
363 SetStatusText(_T("Done !"));
365 wxMessageBox(_T("Done !"),_T("Regenerate boxes lists"),
366 wxOK | wxICON_INFORMATION);
369 SetStatusText(_T("Done !"));
370 wxString err(_T("An error occured while running '"));
371 err += bbtk::std2wx(command) + _T("'");
372 wxMessageBox(err, _T("Regenerate boxes lists"), wxOK | wxICON_ERROR);
376 //================================================================
377 void wxGUIEditorGraphicBBS::RegenerateAll() {
378 DoRegeneratePackageDoc("-a");
379 DoRegenerateBoxesLists();
382 //================================================================
384 wxAuiNotebook* wxGUIEditorGraphicBBS::getAuiNotebook() {
388 //================================================================
390 void wxGUIEditorGraphicBBS::displayBlackBoxInfo(std::string packageName,
391 std::string boxName) {
392 if (_actualPkgBrowserPkgName != packageName || _actualPkgBrowserBoxName
394 _actualPkgBrowserPkgName = packageName;
395 _actualPkgBrowserBoxName = boxName;
397 BlackBoxDescriptor::Pointer descriptor =
398 GObjectsMVCFactory::getInstance()->getBlackBoxDescriptor(
399 packageName, boxName);
400 _pkgBrowser->WxGUIBlackBoxListUserOnSelected(descriptor.get());
404 //=========================================================================
406 void wxGUIEditorGraphicBBS::editBlackBox(GBlackBoxModel *bbmodel) {
407 wxBlackBoxEditionDialog* dialog =
408 new wxBlackBoxEditionDialog(this, bbmodel);
412 //=========================================================================
414 void wxGUIEditorGraphicBBS::updateStatusBar(std::string textStatus) {
415 SetStatusText(crea::std2wx(textStatus));
418 //=========================================================================
420 void wxGUIEditorGraphicBBS::executeScript(std::string script) {
421 std::string separator =
422 ConfigurationFile::GetInstance().Get_file_separator();
423 std::string dir = ConfigurationFile::GetInstance().Get_default_temp_dir();
424 std::string filename = dir + separator + "tmp_bbtk.bbs";
427 tempFile.open(filename.c_str());
431 std::string command = "";
434 command += "start /b ";
437 // command += "\""+ crea::System::GetExecutablePath();
439 // command += separator + "../../../bbi.app/Contents/MacOS";
443 command += "\"" + filename + "\"";
449 printf("RaC wxGUIEditorGraphicBBS::executeScript %s \n", command.c_str());
450 system(command.c_str());
453 //=========================================================================
455 //=========================================================================
457 void wxGUIEditorGraphicBBS::OnCreateNewTab(wxCommandEvent& event) {
458 _tabsMgr->addNewTab();
459 refreshGUIControls();
462 //=========================================================================
464 void wxGUIEditorGraphicBBS::OnExecuteActualDiagram(wxCommandEvent& event) {
465 std::string script1 = _tabsMgr->getActualDiagramBBS(true);
466 cout << endl << "RaC wxGUIEditorGraphicBBS::executeActualDiagram SCRIPT"
468 cout << script1 << endl;
470 std::string script2 = _tabsMgr->getActualDiagramBBS(false);
471 executeScript(script2);
474 //=========================================================================
476 //=========================================================================
477 void wxGUIEditorGraphicBBS::OnOpenBBS(wxCommandEvent& event) {
478 wxFileDialog * openFileDialog = new wxFileDialog(this, wxT("Open BBS"),
479 wxEmptyString, wxT("NewBBS"), wxT("*.bbs"), wxOPEN);
480 if (openFileDialog->ShowModal() == wxID_OK) {
481 wxString fileName = openFileDialog->GetPath();
483 _tabsMgr->addNewTab(openFileDialog->GetFilename());
485 bbtk::InterpreterBBS::Pointer I = bbtk::InterpreterBBS::New(
486 this->_tabsMgr->getActualTabPanel()->getSceneManager(),
487 _pkgBrowser->GetFactory());
489 // We tell the interpreter to throw exceptions on error
491 // Interpret the file supposed to define a box called 'Processing'
492 I->InterpretFile((const char*) (fileName.mb_str()));
494 refreshGUIControls();
497 void wxGUIEditorGraphicBBS::SaveActualBBS(std::string filename) {
500 //EED file.open(fileName.c_str());
501 file.open(filename.c_str());
502 std::string content = "";
503 // writing file header
504 content += "# ----------------------------------\n";
505 content += "# - BBTKGEditor v 1.2 BBS BlackBox Script\n";
509 content += "# ----------------------------------\n";
511 content += _tabsMgr->getActualDiagramBBS();
516 void wxGUIEditorGraphicBBS::OnSaveActualBBS(wxCommandEvent& event) {
517 wxFileDialog * saveFileDialog = new wxFileDialog(this,
518 wxT("Save actual BBS"), wxEmptyString, wxT("NewBBS"),
519 wxT("*.bbs"), wxSAVE | wxOVERWRITE_PROMPT);
520 if (saveFileDialog->ShowModal() == wxID_OK) {
521 wxString fileName = saveFileDialog->GetPath();
522 SaveActualBBS((const char*) (fileName.mb_str()));
527 void wxGUIEditorGraphicBBS::AskComplexBoxConfiguration() {
528 std::string cbName = _tabsMgr->GetCbName();
529 std::string paName = _tabsMgr->GetCbPackageName();
531 wxTextEntryDialog *cbNameDialog = new wxTextEntryDialog(this,
532 wxT("Complex Box name"));
533 wxTextEntryDialog *paNameDialog = new wxTextEntryDialog(this,
534 wxT("Package name"));
536 cbNameDialog->SetValue(wxString(cbName.c_str(), wxConvUTF8));
537 paNameDialog->SetValue(wxString(paName.c_str(), wxConvUTF8));
539 if (cbNameDialog->ShowModal() == wxID_OK) {
540 wxString complexboxname = cbNameDialog->GetValue();
541 cbName = (const char*) (complexboxname.mb_str());
544 if (paNameDialog->ShowModal() == wxID_OK) {
545 wxString packagename = paNameDialog->GetValue();
546 paName = (const char*) (packagename.mb_str());
549 _tabsMgr->SetCbName(cbName);
550 _tabsMgr->SetCbPackageName(paName);
553 //=========================================================================
555 void wxGUIEditorGraphicBBS::SaveActualComplexBox(std::string filename) {
557 file.open(filename.c_str());
559 std::string content = "";
561 // writing file header
562 content += "# ----------------------------------\n";
563 content += "# - BBTKGEditor v 1.2 BBS BlackBox Script (Complex Box)\n";
567 content += "# ----------------------------------\n";
569 content += _tabsMgr->getActualComplexBoxBBS();
574 //=========================================================================
576 void wxGUIEditorGraphicBBS::OnSaveActualComplexBox(wxCommandEvent& event) {
577 wxFileDialog * saveFileDialog = new wxFileDialog(this,
578 wxT("Save Complex Box BBS"), wxEmptyString,
579 _T("ComplexBoxName"), wxT("*.bbs"), wxSAVE
580 | wxOVERWRITE_PROMPT);
581 if (saveFileDialog->ShowModal() == wxID_OK) {
582 wxString fileName = saveFileDialog->GetPath();
583 SaveActualComplexBox((const char*) (fileName.mb_str()));
587 //=========================================================================
588 void wxGUIEditorGraphicBBS::SaveActualDiagram(std::string filename) {
590 file.open(filename.c_str());
592 std::string content = "";
594 // writing file header
595 content += "# ----------------------------------\n";
596 content += "# - BBTKGEditor v 1.2 BBG BlackBox Diagram file\n";
602 content += "# ----------------------------------\n";
604 content += "APP_START\n";
605 _tabsMgr->saveActualDiagram(content, filename); //DFCH
606 content += "APP_END\n";
611 //=========================================================================
613 //The following method allows to save the current diagram asking the filename
615 void wxGUIEditorGraphicBBS::SaveCurrentDiagramAs() {
616 wxFileDialog * saveFileDialog = new wxFileDialog(this,
617 wxT("Save current diagram"), wxEmptyString, wxT("NewDiagram"),
618 wxT("*.bbg"), wxSAVE | wxOVERWRITE_PROMPT);
619 if (saveFileDialog->ShowModal() == wxID_OK) {
620 _tabsMgr->SetNameTabPanel(saveFileDialog->GetFilename());
621 wxString pathfileName = saveFileDialog->GetPath();
622 std::string pathfilename = (const char*) (pathfileName.mb_str());
623 std::string pathfilenamebbs = pathfilename;
624 pathfilenamebbs[pathfilenamebbs.length() - 1] = 's';
625 if (_tabsMgr->isActualDiagramComplexBox() == false) {
626 SaveActualDiagram(pathfilename);
627 SaveActualBBS(pathfilenamebbs);
629 AskComplexBoxConfiguration();
630 SaveActualDiagram(pathfilename);
631 SaveActualComplexBox(pathfilenamebbs);
632 } //if isActualDiagramComplexBox
633 } // if saveFileDialog
635 //=========================================================================
637 void wxGUIEditorGraphicBBS::OnSaveActualDiagram(wxCommandEvent& event) {
638 std::string pathfilename = _tabsMgr->GetCurrentTabPanelPath();
639 if (pathfilename.empty()) {
640 SaveCurrentDiagramAs();
642 std::string pathfilenamebbs = pathfilename;
643 pathfilenamebbs[pathfilenamebbs.length() - 1] = 's';
645 if (_tabsMgr->isActualDiagramComplexBox() == false) {
646 SaveActualDiagram(pathfilename);
647 SaveActualBBS(pathfilenamebbs);
649 AskComplexBoxConfiguration();
650 SaveActualDiagram(pathfilename);
651 SaveActualComplexBox(pathfilenamebbs);
652 } //if isActualDiagramComplexBox
655 //=========================================================================
657 void wxGUIEditorGraphicBBS::OnSaveAsActualDiagram(wxCommandEvent& event) {
658 SaveCurrentDiagramAs();
660 //=========================================================================
662 void wxGUIEditorGraphicBBS::refreshGUIControls() {
663 wxToolBar* toolbar = GetToolBar();
664 if (_tabsMgr->isActualDiagramComplexBox()) {
665 toolbar->ToggleTool(ID_BTNCOMPLEXBOX, true);
666 toolbar->EnableTool(ID_ADDCOMPLEXBOXINPUT, true);
667 toolbar->EnableTool(ID_ADDCOMPLEXBOXOUTPUT, true);
669 GetMenuBar()->GetMenu(0)->Enable(ID_SAVE_AS_COMPLEXBOX, true);
670 GetMenuBar()->GetMenu(0)->Enable(ID_SAVE_AS_BBS, false);
672 toolbar->ToggleTool(ID_BTNCOMPLEXBOX, false);
673 toolbar->EnableTool(ID_ADDCOMPLEXBOXINPUT, false);
674 toolbar->EnableTool(ID_ADDCOMPLEXBOXOUTPUT, false);
676 GetMenuBar()->GetMenu(0)->Enable(ID_SAVE_AS_COMPLEXBOX, false);
677 GetMenuBar()->GetMenu(0)->Enable(ID_SAVE_AS_BBS, true);
680 if (_tabsMgr->getNumActualSelectedObjects() > 0) {
681 GetMenuBar()->GetMenu(1)->Enable(ID_COPY_TO_COMPLEXDIAGRAM, true);
683 ///TODO Fix the possibility to say from the SceneManager to the GUI to refresh the options
684 GetMenuBar()->GetMenu(1)->Enable(ID_COPY_TO_COMPLEXDIAGRAM, true);
689 //=========================================================================
691 void wxGUIEditorGraphicBBS::OnDeleteAllBoxesActualDiagram(wxCommandEvent& event) {
692 wxMessageDialog *dial = new wxMessageDialog(NULL,
693 wxT("Are you sure to delete all boxes of the diagram?"),
694 wxT("Delete all boxes"), wxYES_NO | wxNO_DEFAULT
696 if (dial->ShowModal() == wxID_YES) {
697 _tabsMgr->deleteAllBoxesActualDiagram();
701 //=========================================================================
703 void wxGUIEditorGraphicBBS::OnCenterViewActualDiagram(wxCommandEvent& event) {
704 _tabsMgr->centerViewActualDiagram();
707 //=========================================================================
709 void wxGUIEditorGraphicBBS::OnOpenDiagram(wxCommandEvent& event) {
710 wxFileDialog * openFileDialog = new wxFileDialog(this, wxT("Open diagram"),
711 wxEmptyString, wxT(""), wxT("*.bbg"), wxOPEN | wxFILE_MUST_EXIST);
712 if (openFileDialog->ShowModal() == wxID_OK) {
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());
719 _tabsMgr->loadDiagram(inputStream, fName);
723 refreshGUIControls();
726 //=========================================================================
729 void wxGUIEditorGraphicBBS::OnClickBtnBox(wxCommandEvent& event) {
730 BlackBoxDescriptor *bbDes = _pkgBrowser->GetActualSelected();
732 std::string typeName = bbDes->GetTypeName();
733 std::string packageName = bbDes->GetPackage()->GetName();
735 wxGEditorTabPanel *pnl = this->_tabsMgr->getActualTabPanel();
738 wxVtkSceneManager *scn = pnl->getSceneManager();
739 scn->createGBlackBox(50, 50, packageName, typeName);
745 //=========================================================================
747 void wxGUIEditorGraphicBBS::OnClickBtnExecutableBox(wxCommandEvent& event) {
749 wxGEditorTabPanel *pnl = this->_tabsMgr->getActualTabPanel();
752 wxVtkSceneManager *scn = pnl->getSceneManager();
753 if( scn->MakeBoxExecutable() )
754 std::cout<<"DFCH: wxGUIEditorGraphicBBS::OnClickBtnExecutableBox...successful"<<std::endl;
756 std::cout<<"DFCH: wxGUIEditorGraphicBBS::OnClickBtnExecutableBox...Error!!"<<std::endl;
762 //=========================================================================
764 void wxGUIEditorGraphicBBS::OnClickBtnComplexBox(wxCommandEvent& event) {
765 wxToolBar* toolbar = GetToolBar();
766 bool temp = toolbar->GetToolState(ID_BTNCOMPLEXBOX);
768 _tabsMgr->setActualDiagramComplexBox(true);
770 _tabsMgr->setActualDiagramComplexBox(false);
772 refreshGUIControls();
775 //=========================================================================
777 void wxGUIEditorGraphicBBS::OnAddComplexBoxInput(wxCommandEvent& event) {
778 wxTextEntryDialog *nameDialog = new wxTextEntryDialog(this,
779 wxT("Name of input port"));
780 if (nameDialog->ShowModal() == wxID_OK) {
781 wxString fileName = nameDialog->GetValue();
782 if (!fileName.IsEmpty()) {
783 std::string portName = (const char*) (fileName.mb_str());
784 _tabsMgr->addActualDiagramComplexInputPort(portName);
789 //=========================================================================
791 void wxGUIEditorGraphicBBS::OnAddComplexBoxOutput(wxCommandEvent& event) {
792 wxTextEntryDialog *nameDialog = new wxTextEntryDialog(this,
793 wxT("Name of output port"));
794 if (nameDialog->ShowModal() == wxID_OK) {
795 wxString fileName = nameDialog->GetValue();
796 if (!fileName.IsEmpty()) {
797 std::string portName = (const char*) (fileName.mb_str());
798 _tabsMgr->addActualDiagramComplexOutputPort(portName);
803 //=========================================================================
805 void wxGUIEditorGraphicBBS::OnCopySelectedToComplexDiagram(
806 wxCommandEvent& event) {
807 _tabsMgr->copySelectedBBoxesToComplexDiagram();
810 void wxGUIEditorGraphicBBS::OnHelpBBeditor(wxCommandEvent& event) {
811 printf("wxGUIEditorGraphicBBS::OnHelpBBeditor ....not implemented..\n");
814 //=========================================================================
815 void wxGUIEditorGraphicBBS::OnCreatePackage(wxCommandEvent& event) {
816 printf("EED wxGUIEditorGraphicBBS::OnCreatePackag ... not implemented ..\n");
819 //=========================================================================
820 void wxGUIEditorGraphicBBS::OnCreateBlackBox(wxCommandEvent& event) {
822 "EED wxGUIEditorGraphicBBS::OnCreateBlackBox ... not implemented ..\n");
824 //=========================================================================
825 void wxGUIEditorGraphicBBS::OnPlugPackage(wxCommandEvent& event) {
826 printf("EED wxGUIEditorGraphicBBS::OnPlugPackage ... not implemented ..\n");
828 //=========================================================================
829 void wxGUIEditorGraphicBBS::OnEditConfig(wxCommandEvent& event) {
830 printf("EED wxGUIEditorGraphicBBS::OnEditConfig ... not implemented ..\n");
832 //=========================================================================
833 void wxGUIEditorGraphicBBS::OnShowHTMLDoc(wxCommandEvent& event) {
834 printf("EED wxGUIEditorGraphicBBS::OnShowHTMLDoc ... not implemented ..\n");
836 //=========================================================================
837 void wxGUIEditorGraphicBBS::OnCreateIndex(wxCommandEvent& event) {
838 printf("EED wxGUIEditorGraphicBBS::OnCreateIndex ... not implemented ..\n");
841 //=========================================================================
843 void wxGUIEditorGraphicBBS::OnExit(wxCommandEvent& event) {
847 //=========================================================================
849 } // EO namespace bbtk