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"
41 #include <InterpreterBBS.h>
45 //=========================================================================
46 wxGUIEditorGraphicBBS::wxGUIEditorGraphicBBS(wxFrame *parent) :
47 wxFrame(parent, -1, _T("bbtkGEditor"), wxDefaultPosition, wxSize(
50 _frameAUIMgr = new wxAuiManager(this);
52 /*std::string datadir( crea::System::GetExecutablePath() );
53 std::string datadir (".");
54 cout<<"RaC //------------------"<<endl;
55 cout<<"RaC //TODO wxGUIEditorGraphicBBS constructor.Initialize datadir with crea::System::GetExecutablePath() ."<<endl;
56 cout<<"RaC //------------------"<<endl;
58 #ifdef LINUX // assume this is OSX
59 datadir=datadir+"/../share/creaContours";
62 #ifdef MACOSX // assume this is OSX
63 datadir=datadir+"/../../../../share/creaContours";
70 initTabPanelsManager();
72 // JGGR & CM initHelpHTMLBrowser();
73 _helpHtmlBrowser = NULL;
75 _frameAUIMgr->Update();
76 _actualPkgBrowserBoxName = "";
77 _actualPkgBrowserPkgName = "";
81 //=========================================================================
82 wxGUIEditorGraphicBBS::~wxGUIEditorGraphicBBS() {
84 printf("EED %p ~wxGUIEditorGraphicBBS()\n", this);
86 //EED02JUIN2010 delete _tabsMgr;
88 _frameAUIMgr->UnInit();
96 //=========================================================================
97 void wxGUIEditorGraphicBBS::initToolbar() {
98 wxBitmap bmp_new(new_xpm);
99 wxBitmap bmp_open(open_xpm);
100 wxBitmap bmp_save(save_xpm);
101 wxBitmap bmp_run(run_xpm);
102 wxBitmap bmp_delete(delete_xpm);
103 wxBitmap bmp_centerview(centerview_xpm);
104 wxBitmap bmp_box(box_xpm);
105 wxBitmap bmp_executablebox(executablebox_xpm);
106 wxBitmap bmp_complexbox(complexbox_xpm);
107 wxBitmap bmp_complexinputport(complexinputport_xpm);
108 wxBitmap bmp_complexoutputport(complexoutputport_xpm);
109 wxBitmap bmp_undo(undo_xpm);
110 wxBitmap bmp_redo(redo_xpm);
111 wxToolBar *toolbar = new wxToolBar(this, wxID_ANY);
113 //Adds a tool btn to the toolbar
114 toolbar->AddTool(ID_NEW, _T("New"), bmp_new, wxNullBitmap, wxITEM_NORMAL,
115 _T("New tab"), _T("Create a new panel tab"));
116 toolbar->AddTool(ID_OPEN, _T("Open diagram"), bmp_open, wxNullBitmap,
117 wxITEM_NORMAL, _T("Open a diagram"), _T("Open a diagram"));
118 toolbar->AddTool(ID_SAVE_DIAGRAM, _T("Save Diagram"), bmp_save,
119 wxNullBitmap, wxITEM_NORMAL, _T("Saves the current diagram"),
120 _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,
123 _T("Execute actual diagram"), _T("Execute actual diagram"));
124 toolbar->AddTool(ID_DELETEALL, _T("Delete all"), bmp_delete, wxNullBitmap,
125 wxITEM_NORMAL, _T("Delete all boxes"), _T("Delete all boxes"));
126 toolbar->AddTool(ID_CENTERVIEW, _T("Center view"), bmp_centerview,
127 wxNullBitmap, wxITEM_NORMAL, _T("Center view"), _T("Center view"));
128 toolbar->AddSeparator();
129 toolbar->AddTool(ID_BTNBOX, _T("New Box"), bmp_box, wxNullBitmap,
130 wxITEM_NORMAL, _T("New Box"), _T("Nex Box"));
131 toolbar->AddSeparator();
132 toolbar->AddTool(ID_BTEXECUTABLEBOX, _T("Select as executable Box"),
133 bmp_executablebox, wxNullBitmap, wxITEM_NORMAL,
134 _T("Select as executable Box"), _T("Select as executable Box"));
135 toolbar->AddSeparator();
136 toolbar->AddTool(ID_BTNCOMPLEXBOX, _T("Complex box"), complexbox_xpm,
137 wxNullBitmap, wxITEM_NORMAL, _T("Complex box"), _T("Complex box"));
138 toolbar->SetToggle(ID_BTNCOMPLEXBOX, true);
139 toolbar->AddTool(ID_ADDCOMPLEXBOXINPUT, _T("Add input to Complex box"),
140 bmp_complexinputport, wxNullBitmap, wxITEM_NORMAL,
141 _T("Add input to Complex box"), _T("Add input to Complex box"));
142 toolbar->AddTool(ID_ADDCOMPLEXBOXOUTPUT, _T("Add output to Complex box"),
143 bmp_complexoutputport, wxNullBitmap, wxITEM_NORMAL,
144 _T("Add output Complex box"), _T("Add output Complex box"));
145 toolbar->EnableTool(ID_ADDCOMPLEXBOXINPUT, false);
146 toolbar->EnableTool(ID_ADDCOMPLEXBOXOUTPUT, false);
147 toolbar->AddSeparator();
148 toolbar->AddTool(ID_UNDO, _T("Undo"),bmp_undo, wxNullBitmap, wxITEM_NORMAL, _T("Undo"), _T("Undo"));
149 toolbar->AddTool(ID_REDO, _T("Redo"),bmp_redo, wxNullBitmap, wxITEM_NORMAL, _T("Redo"), _T("Redo"));
150 //toolbar->EnableTool(ID_UNDO, false);
151 //toolbar->EnableTool(ID_REDO, false);
152 toolbar->SetMargins(2, 2);
157 // connect command event handlers
159 Connect(ID_NEW, wxEVT_COMMAND_TOOL_CLICKED,
160 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnCreateNewTab));
161 Connect(ID_OPEN, wxEVT_COMMAND_TOOL_CLICKED,
162 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnOpenDiagram));
163 Connect(ID_SAVE_DIAGRAM, wxEVT_COMMAND_TOOL_CLICKED,
164 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnSaveActualDiagram)); //DFCH
165 Connect(ID_SAVE_AS_DIAGRAM, wxEVT_COMMAND_TOOL_CLICKED,
166 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnSaveAsActualDiagram)); //DFCH
169 wxEVT_COMMAND_TOOL_CLICKED,
170 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnExecuteActualDiagram));
173 wxEVT_COMMAND_TOOL_CLICKED,
174 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnDeleteAllBoxesActualDiagram));
177 wxEVT_COMMAND_TOOL_CLICKED,
178 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnCenterViewActualDiagram));
179 Connect(ID_BTNBOX, wxEVT_COMMAND_TOOL_CLICKED,
180 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnClickBtnBox));
183 wxEVT_COMMAND_TOOL_CLICKED,
184 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnClickBtnExecutableBox));
185 Connect(ID_BTNCOMPLEXBOX, wxEVT_COMMAND_TOOL_CLICKED,
186 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnClickBtnComplexBox));
187 Connect(ID_ADDCOMPLEXBOXINPUT, wxEVT_COMMAND_TOOL_CLICKED,
188 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnAddComplexBoxInput));
189 Connect(ID_ADDCOMPLEXBOXOUTPUT, wxEVT_COMMAND_TOOL_CLICKED,
190 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnAddComplexBoxOutput));
191 Connect(ID_UNDO,wxEVT_COMMAND_TOOL_CLICKED, wxCommandEventHandler(wxGUIEditorGraphicBBS::OnUndo));
192 Connect(ID_REDO,wxEVT_COMMAND_TOOL_CLICKED, wxCommandEventHandler(wxGUIEditorGraphicBBS::OnRedo));
195 //=========================================================================
196 void wxGUIEditorGraphicBBS::initHelpHTMLBrowser() {
198 _helpHtmlBrowser = new WxGUIHtmlBrowser(this, wxSize(200, 0));
204 //=========================================================================
205 void wxGUIEditorGraphicBBS::initMenu() {
206 // Create File menu and its items
207 wxMenu *fileMenu = new wxMenu();
208 fileMenu->Append(ID_NEW, _T("New diagram"), _T("New"));
209 fileMenu->Append(ID_SAVE_DIAGRAM, _T("Save Diagram"), _T("Save Diagram")); //DFCH
210 fileMenu->Append(ID_SAVE_AS_DIAGRAM, _T("Save Diagram As"),
211 _T("Save Diagram As")); //DFCH
212 fileMenu->Append(ID_OPEN_BBS, _T("Open BBS"), _T("Open BBS"));
213 fileMenu->Append(ID_SAVE_AS_BBS, _T("Save BBS"), _T("Save BBS"));
214 fileMenu->Append(ID_SAVE_AS_COMPLEXBOX, _T("Save complex box"),
215 _T("Save complex box"));
216 fileMenu->Append(wxID_EXIT, _T("E&xit"), _T("Exit"));
218 Connect(ID_NEW, wxEVT_COMMAND_MENU_SELECTED,
219 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnCreateNewTab));
220 Connect(ID_SAVE_DIAGRAM, wxEVT_COMMAND_MENU_SELECTED,
221 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnSaveActualDiagram)); //DFCH
222 Connect(ID_SAVE_AS_DIAGRAM, wxEVT_COMMAND_MENU_SELECTED,
223 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnSaveAsActualDiagram));
224 Connect(ID_OPEN_BBS, wxEVT_COMMAND_MENU_SELECTED,
225 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnOpenBBS));
226 Connect(ID_SAVE_AS_BBS, wxEVT_COMMAND_MENU_SELECTED,
227 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnSaveActualBBS));
229 ID_SAVE_AS_COMPLEXBOX,
230 wxEVT_COMMAND_MENU_SELECTED,
231 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnSaveActualComplexBox));
232 Connect(wxID_EXIT, wxEVT_COMMAND_MENU_SELECTED,
233 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnExit));
235 // Create Help menu and its items
236 wxMenu *editMenu = new wxMenu;
237 editMenu->Append(ID_COPY_TO_COMPLEXDIAGRAM,
238 _T("Copy selected to complex box"),
239 _T("Creates a new complex box diagram with selected boxes"));
242 ID_COPY_TO_COMPLEXDIAGRAM,
243 wxEVT_COMMAND_MENU_SELECTED,
244 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnCopySelectedToComplexDiagram));
246 // Create Help menu and its items
247 wxMenu *helpMenu = new wxMenu;
248 helpMenu->Append(wxID_ABOUT, _T("&About..."), _T("About"));
249 helpMenu->Append(ID_HELP_BBEDITOR, _T("&Help..."), _T("Help"));
250 Connect(ID_HELP_BBEDITOR, wxEVT_COMMAND_MENU_SELECTED,
251 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnHelpBBeditor));
254 wxMenu *menuTools = new wxMenu;
255 menuTools->Append(ID_bbEditor_Tool_Menu_CreatePackage,
256 _T("Create &package") );
257 menuTools->Append(ID_bbEditor_Tool_Menu_CreateBlackBox,
258 _T("Create &blackbox") );
259 menuTools->Append(ID_bbEditor_Tool_Menu_PlugPackage, _T("Plug package") );
260 menuTools->Append(ID_bbEditor_Tool_Menu_EditConfig, _T("&Edit bbtk config") );
261 menuTools->Append(ID_bbEditor_Tool_Menu_ShowHTMLDoc,
262 _T("Show &HTML documentation") );
263 menuTools->Append(ID_bbEditor_Tool_Menu_CreateIndex, _T("&Generate index") );
265 Connect(ID_bbEditor_Tool_Menu_CreatePackage, wxEVT_COMMAND_MENU_SELECTED,
266 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnCreatePackage));
267 Connect(ID_bbEditor_Tool_Menu_CreateBlackBox, wxEVT_COMMAND_MENU_SELECTED,
268 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnCreateBlackBox));
269 Connect(ID_bbEditor_Tool_Menu_PlugPackage, wxEVT_COMMAND_MENU_SELECTED,
270 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnPlugPackage));
271 Connect(ID_bbEditor_Tool_Menu_EditConfig, wxEVT_COMMAND_MENU_SELECTED,
272 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnEditConfig));
273 Connect(ID_bbEditor_Tool_Menu_ShowHTMLDoc, wxEVT_COMMAND_MENU_SELECTED,
274 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnShowHTMLDoc));
275 Connect(ID_bbEditor_Tool_Menu_CreateIndex, wxEVT_COMMAND_MENU_SELECTED,
276 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnCreateIndex));
278 // Append the created menu to the menu bar
279 wxMenuBar *menuBar = new wxMenuBar();
280 menuBar->Append(fileMenu, _T("&File") );
281 menuBar->Append(editMenu, _T("&Edit") );
282 menuBar->Append(menuTools, _T("&Tool") );
283 menuBar->Append(helpMenu, _T("&Help") );
285 // Attach this menu bar to the frame
289 //=========================================================================
290 void wxGUIEditorGraphicBBS::initTabPanelsManager() {
291 _notebook = new wxAuiNotebook(this, wxID_NOTEBOOK, wxDefaultPosition,
292 wxDefaultSize, wxAUI_NB_TOP | wxAUI_NB_TAB_MOVE
293 | wxAUI_NB_CLOSE_ON_ACTIVE_TAB | wxAUI_NB_TAB_FIXED_WIDTH
294 | wxAUI_NB_WINDOWLIST_BUTTON);
295 _tabsMgr = new wxTabPanelsManager(this);
296 _frameAUIMgr->AddPane(_notebook, wxAuiPaneInfo().CenterPane());
300 //=========================================================================
301 void wxGUIEditorGraphicBBS::initPackageBrowser() {
302 _pkgBrowser = new WxGUIPackageBrowser2(this);
303 _pkgBrowser->IncludeAll();
304 _frameAUIMgr->AddPane(_pkgBrowser,
305 wxAuiPaneInfo().Left().MinSize(200, 200).CloseButton(false));
308 //================================================================
310 void wxGUIEditorGraphicBBS::DoRegeneratePackageDoc(const std::string& pack) {
311 std::string mess("Regenerating doc for package '");
315 mess = "Regenerating doc for all packages";
318 mess += " ... please wait";
320 SetStatusText(std2wx(mess));
328 command += ConfigurationFile::GetInstance().Get_bin_path();
329 command += ConfigurationFile::GetInstance().Get_file_separator();
330 command += "bbRegeneratePackageDoc";
335 command += " " + pack + " -q";
336 bbtkMessage("debug",1,"Executing system command '"<<command<<"'"<<std::endl);
338 if (!system(command.c_str())) {
339 SetStatusText(_T("Done !"));
341 wxMessageBox(_T("Done !"),_T("Regenerate package '")
342 +std2wx(pack)+_T("' doc"),
343 wxOK | wxICON_INFORMATION);
346 SetStatusText(_T("Done !"));
347 wxString err(_T("An error occured while running '"));
348 err += bbtk::std2wx(command) + _T("'");
349 wxMessageBox(err, _T("Regenerate package doc"), wxOK | wxICON_ERROR);
353 //================================================================
354 void wxGUIEditorGraphicBBS::DoRegenerateBoxesLists() {
355 SetStatusText(_T("Regenerating boxes lists ... please wait"));
362 command += ConfigurationFile::GetInstance().Get_bin_path();
363 command += ConfigurationFile::GetInstance().Get_file_separator();
364 command += "bbRegenerateBoxesLists";
371 bbtkMessage("debug",1,"Executing system command '"<<command<<"'"<<std::endl);
373 if (!system(command.c_str())) {
374 SetStatusText(_T("Done !"));
376 wxMessageBox(_T("Done !"),_T("Regenerate boxes lists"),
377 wxOK | wxICON_INFORMATION);
380 SetStatusText(_T("Done !"));
381 wxString err(_T("An error occured while running '"));
382 err += bbtk::std2wx(command) + _T("'");
383 wxMessageBox(err, _T("Regenerate boxes lists"), wxOK | wxICON_ERROR);
387 //================================================================
388 void wxGUIEditorGraphicBBS::RegenerateAll() {
389 DoRegeneratePackageDoc("-a");
390 DoRegenerateBoxesLists();
393 //================================================================
395 wxAuiNotebook* wxGUIEditorGraphicBBS::getAuiNotebook() {
399 //================================================================
401 void wxGUIEditorGraphicBBS::displayBlackBoxInfo(std::string packageName,
402 std::string boxName) {
403 if (_actualPkgBrowserPkgName != packageName || _actualPkgBrowserBoxName
405 _actualPkgBrowserPkgName = packageName;
406 _actualPkgBrowserBoxName = boxName;
408 BlackBoxDescriptor::Pointer descriptor =
409 GObjectsMVCFactory::getInstance()->getBlackBoxDescriptor(
410 packageName, boxName);
411 _pkgBrowser->WxGUIBlackBoxListUserOnSelected(descriptor.get());
415 //=========================================================================
417 void wxGUIEditorGraphicBBS::editBlackBox(GBlackBoxModel *bbmodel) {
418 wxBlackBoxEditionDialog* dialog =
419 new wxBlackBoxEditionDialog(this, bbmodel);
423 //=========================================================================
425 void wxGUIEditorGraphicBBS::updateStatusBar(std::string textStatus) {
426 SetStatusText(crea::std2wx(textStatus));
429 //=========================================================================
431 void wxGUIEditorGraphicBBS::executeScript(std::string script) {
432 std::string separator =
433 ConfigurationFile::GetInstance().Get_file_separator();
434 std::string dir = ConfigurationFile::GetInstance().Get_default_temp_dir();
435 std::string filename = dir + separator + "tmp_bbtk.bbs";
438 tempFile.open(filename.c_str());
442 std::string command = "";
445 command += "start /b ";
448 // command += "\""+ crea::System::GetExecutablePath();
450 // command += separator + "../../../bbi.app/Contents/MacOS";
454 command += "\"" + filename + "\"";
460 printf("RaC wxGUIEditorGraphicBBS::executeScript %s \n", command.c_str());
461 system(command.c_str());
464 //=========================================================================
465 std::string wxGUIEditorGraphicBBS::CheckExtension(std::string filename, std::string extension) {
466 if(filename.size() > extension.size() ){
467 if( (filename.compare(filename.size()-extension.size(), extension.size(),extension)) !=0 ){
468 filename.append(extension);
471 filename.append(extension);
475 //=========================================================================
477 //=========================================================================
479 void wxGUIEditorGraphicBBS::OnCreateNewTab(wxCommandEvent& event) {
480 _tabsMgr->addNewTab();
481 refreshGUIControls();
484 void wxGUIEditorGraphicBBS::OnUndo(wxCommandEvent& event) {
485 unsigned short disable;
486 GetToolBar()->EnableTool(ID_UNDO,_tabsMgr->loadTempDiagram(0));
487 if (GetToolBar()->GetToolEnabled(ID_REDO) == false)
488 GetToolBar()->EnableTool(ID_REDO,true);
489 refreshGUIControls();
492 void wxGUIEditorGraphicBBS::OnRedo(wxCommandEvent& event) {
493 unsigned short disable;
494 GetToolBar()->EnableTool(ID_REDO, _tabsMgr->loadTempDiagram(1));
495 if (GetToolBar()->GetToolEnabled(ID_UNDO) == false)
496 GetToolBar()->EnableTool(ID_UNDO,true);
497 refreshGUIControls();
499 //=========================================================================
501 void wxGUIEditorGraphicBBS::OnExecuteActualDiagram(wxCommandEvent& event) {
502 std::string script1 = _tabsMgr->getActualDiagramBBS(true);
503 cout << endl << "RaC wxGUIEditorGraphicBBS::executeActualDiagram SCRIPT"
505 cout << script1 << endl;
507 std::string script2 = _tabsMgr->getActualDiagramBBS(false);
508 executeScript(script2);
511 //=========================================================================
513 //=========================================================================
514 void wxGUIEditorGraphicBBS::OnOpenBBS(wxCommandEvent& event) {
515 wxFileDialog * openFileDialog = new wxFileDialog(this, wxT("Open BBS"),
516 wxEmptyString, wxT("NewBBS"), wxT("*.bbs"), wxOPEN);
517 if (openFileDialog->ShowModal() == wxID_OK) {
518 wxString fileName = openFileDialog->GetPath();
520 _tabsMgr->addNewTab(openFileDialog->GetFilename());
522 bbtk::InterpreterBBS::Pointer I = bbtk::InterpreterBBS::New(
523 this->_tabsMgr->getActualTabPanel()->getSceneManager(),
524 _pkgBrowser->GetFactory());
526 // We tell the interpreter to throw exceptions on error
528 // Interpret the file supposed to define a box called 'Processing'
529 I->InterpretFile((const char*) (fileName.mb_str()));
531 refreshGUIControls();
534 void wxGUIEditorGraphicBBS::SaveActualBBS(std::string filename) {
537 //EED file.open(fileName.c_str());
538 file.open(filename.c_str());
539 std::string content = "";
540 // writing file header
541 content += "# ----------------------------------\n";
542 content += "# - BBTKGEditor v 1.2 BBS BlackBox Script\n";
546 content += "# ----------------------------------\n";
548 content += _tabsMgr->getActualDiagramBBS();
553 void wxGUIEditorGraphicBBS::OnSaveActualBBS(wxCommandEvent& event) {
554 wxFileDialog * saveFileDialog = new wxFileDialog(this,
555 wxT("Save actual BBS"), wxEmptyString, wxT("NewBBS"),
556 wxT("*.bbs"), wxSAVE | wxOVERWRITE_PROMPT);
557 if (saveFileDialog->ShowModal() == wxID_OK) {
558 wxString fileName = saveFileDialog->GetPath();
559 std::string filename = (const char*) (fileName.mb_str());
560 filename=CheckExtension (filename, ".bbs");
561 SaveActualBBS(filename);
566 void wxGUIEditorGraphicBBS::AskComplexBoxConfiguration() {
567 std::string cbName = _tabsMgr->GetCbName();
568 std::string paName = _tabsMgr->GetCbPackageName();
570 wxTextEntryDialog *cbNameDialog = new wxTextEntryDialog(this,
571 wxT("Complex Box name"));
572 wxTextEntryDialog *paNameDialog = new wxTextEntryDialog(this,
573 wxT("Package name"));
575 cbNameDialog->SetValue(wxString(cbName.c_str(), wxConvUTF8));
576 paNameDialog->SetValue(wxString(paName.c_str(), wxConvUTF8));
578 if (cbNameDialog->ShowModal() == wxID_OK) {
579 wxString complexboxname = cbNameDialog->GetValue();
580 cbName = (const char*) (complexboxname.mb_str());
583 if (paNameDialog->ShowModal() == wxID_OK) {
584 wxString packagename = paNameDialog->GetValue();
585 paName = (const char*) (packagename.mb_str());
588 _tabsMgr->SetCbName(cbName);
589 _tabsMgr->SetCbPackageName(paName);
592 //=========================================================================
594 void wxGUIEditorGraphicBBS::SaveActualComplexBox(std::string filename) {
596 file.open(filename.c_str());
598 std::string content = "";
600 // writing file header
601 content += "# ----------------------------------\n";
602 content += "# - BBTKGEditor v 1.2 BBS BlackBox Script (Complex Box)\n";
606 content += "# ----------------------------------\n";
608 content += _tabsMgr->getActualComplexBoxBBS();
613 //=========================================================================
615 void wxGUIEditorGraphicBBS::OnSaveActualComplexBox(wxCommandEvent& event) {
616 wxFileDialog * saveFileDialog = new wxFileDialog(this,
617 wxT("Save Complex Box BBS"), wxEmptyString,
618 _T("ComplexBoxName"), wxT("*.bbs"), wxSAVE
619 | wxOVERWRITE_PROMPT);
620 if (saveFileDialog->ShowModal() == wxID_OK) {
621 wxString fileName = saveFileDialog->GetPath();
622 std::string filename = (const char*) (fileName.mb_str());
623 filename=CheckExtension (filename, ".bbs");
624 SaveActualComplexBox(filename);
628 //=========================================================================
629 void wxGUIEditorGraphicBBS::SaveActualDiagram(std::string filename) {
631 file.open(filename.c_str());
633 std::string content = "";
635 // writing file header
636 content += "# ----------------------------------\n";
637 content += "# - BBTKGEditor v 1.2 BBG BlackBox Diagram file\n";
643 content += "# ----------------------------------\n";
645 content += "APP_START\n";
646 _tabsMgr->saveActualDiagram(content, filename); //DFCH
647 content += "APP_END\n";
652 //=========================================================================
653 void wxGUIEditorGraphicBBS::SaveTempActualDiagram()
655 _tabsMgr->saveTempActualDiagram();
658 //=========================================================================
660 //The following method allows to save the current diagram asking the filename
662 void wxGUIEditorGraphicBBS::SaveCurrentDiagramAs() {
663 wxFileDialog * saveFileDialog = new wxFileDialog(this,
664 wxT("Save current diagram"), wxEmptyString, wxT("NewDiagram"),
665 wxT("*.bbg"), wxSAVE | wxOVERWRITE_PROMPT);
666 if (saveFileDialog->ShowModal() == wxID_OK) {
667 //_tabsMgr->SetNameTabPanel(saveFileDialog->GetFilename());
668 wxString pathfileName = saveFileDialog->GetPath();
669 std::string pathfilename = (const char*) (pathfileName.mb_str());
670 pathfilename=CheckExtension (pathfilename, ".bbg");
672 //modify the tab name accordingly
673 wxString fileName = saveFileDialog->GetFilename();
674 std::string filename = (const char*) (fileName.mb_str());
675 filename=CheckExtension (filename, ".bbg");
676 _tabsMgr->SetNameTabPanel( wxString (filename.c_str(), wxConvUTF8) );
678 std::string pathfilenamebbs = pathfilename;
679 pathfilenamebbs[pathfilenamebbs.length() - 1] = 's';
680 if (_tabsMgr->isActualDiagramComplexBox() == false) {
681 SaveActualDiagram(pathfilename);
682 SaveActualBBS(pathfilenamebbs);
684 AskComplexBoxConfiguration();
685 SaveActualDiagram(pathfilename);
686 SaveActualComplexBox(pathfilenamebbs);
687 } //if isActualDiagramComplexBox
688 } // if saveFileDialog
690 //=========================================================================
692 void wxGUIEditorGraphicBBS::OnSaveActualDiagram(wxCommandEvent& event) {
693 std::string pathfilename = _tabsMgr->GetCurrentTabPanelPath();
694 if (pathfilename.empty()) {
695 SaveCurrentDiagramAs();
697 std::string pathfilenamebbs = pathfilename;
698 pathfilenamebbs[pathfilenamebbs.length() - 1] = 's';
700 if (_tabsMgr->isActualDiagramComplexBox() == false) {
701 SaveActualDiagram(pathfilename);
702 SaveActualBBS(pathfilenamebbs);
704 AskComplexBoxConfiguration();
705 SaveActualDiagram(pathfilename);
706 SaveActualComplexBox(pathfilenamebbs);
707 } //if isActualDiagramComplexBox
710 //=========================================================================
712 void wxGUIEditorGraphicBBS::OnSaveAsActualDiagram(wxCommandEvent& event) {
713 SaveCurrentDiagramAs();
715 //=========================================================================
717 void wxGUIEditorGraphicBBS::refreshGUIControls() {
718 wxToolBar* toolbar = GetToolBar();
719 if (_tabsMgr->isActualDiagramComplexBox()) {
720 toolbar->ToggleTool(ID_BTNCOMPLEXBOX, true);
721 toolbar->EnableTool(ID_ADDCOMPLEXBOXINPUT, true);
722 toolbar->EnableTool(ID_ADDCOMPLEXBOXOUTPUT, true);
724 GetMenuBar()->GetMenu(0)->Enable(ID_SAVE_AS_COMPLEXBOX, true);
725 GetMenuBar()->GetMenu(0)->Enable(ID_SAVE_AS_BBS, false);
727 toolbar->ToggleTool(ID_BTNCOMPLEXBOX, false);
728 toolbar->EnableTool(ID_ADDCOMPLEXBOXINPUT, false);
729 toolbar->EnableTool(ID_ADDCOMPLEXBOXOUTPUT, false);
731 GetMenuBar()->GetMenu(0)->Enable(ID_SAVE_AS_COMPLEXBOX, false);
732 GetMenuBar()->GetMenu(0)->Enable(ID_SAVE_AS_BBS, true);
735 if (_tabsMgr->getNumActualSelectedObjects() > 0) {
736 GetMenuBar()->GetMenu(1)->Enable(ID_COPY_TO_COMPLEXDIAGRAM, true);
738 ///TODO Fix the possibility to say from the SceneManager to the GUI to refresh the options
739 GetMenuBar()->GetMenu(1)->Enable(ID_COPY_TO_COMPLEXDIAGRAM, true);
744 //=========================================================================
746 void wxGUIEditorGraphicBBS::OnDeleteAllBoxesActualDiagram(wxCommandEvent& event) {
747 wxMessageDialog *dial = new wxMessageDialog(NULL,
748 wxT("Are you sure to delete all boxes of the diagram?"),
749 wxT("Delete all boxes"), wxYES_NO | wxNO_DEFAULT
751 if (dial->ShowModal() == wxID_YES) {
752 _tabsMgr->deleteAllBoxesActualDiagram();
756 //=========================================================================
758 void wxGUIEditorGraphicBBS::OnCenterViewActualDiagram(wxCommandEvent& event) {
759 _tabsMgr->centerViewActualDiagram();
762 //=========================================================================
764 void wxGUIEditorGraphicBBS::OnOpenDiagram(wxCommandEvent& event) {
765 wxFileDialog * openFileDialog = new wxFileDialog(this, wxT("Open diagram"),
766 wxEmptyString, wxT(""), wxT("*.bbg"), wxOPEN | wxFILE_MUST_EXIST);
767 if (openFileDialog->ShowModal() == wxID_OK) {
768 wxString fileName = openFileDialog->GetPath();
769 ifstream inputStream;
770 std::string fName = (const char*) (fileName.mb_str());
772 inputStream.open(fName.c_str());
773 assert(inputStream.good()); // fails
774 _tabsMgr->addNewTab(openFileDialog->GetFilename());
775 _tabsMgr->loadDiagram(inputStream, fName);
779 refreshGUIControls();
782 //=========================================================================
785 void wxGUIEditorGraphicBBS::OnClickBtnBox(wxCommandEvent& event) {
786 BlackBoxDescriptor *bbDes = _pkgBrowser->GetActualSelected();
788 std::string typeName = bbDes->GetTypeName();
789 std::string packageName = bbDes->GetPackage()->GetName();
791 wxGEditorTabPanel *pnl = this->_tabsMgr->getActualTabPanel();
793 // save empty state!!
794 /* if (_tabsMgr->getNumActualSelectedObjects() == 0)
796 SaveTempActualDiagram();
800 wxVtkSceneManager *scn = pnl->getSceneManager();
801 scn->createGBlackBox(50, 50, packageName, typeName);
804 if (GetToolBar()->GetToolEnabled(ID_UNDO) == false)
805 GetToolBar()->EnableTool(ID_UNDO,true);
806 SaveTempActualDiagram();
811 //=========================================================================
813 void wxGUIEditorGraphicBBS::OnClickBtnExecutableBox(wxCommandEvent& event) {
815 wxGEditorTabPanel *pnl = this->_tabsMgr->getActualTabPanel();
818 wxVtkSceneManager *scn = pnl->getSceneManager();
819 if( scn->MakeBoxExecutable() )
820 std::cout<<"DFCH: wxGUIEditorGraphicBBS::OnClickBtnExecutableBox...successful"<<std::endl;
822 std::cout<<"DFCH: wxGUIEditorGraphicBBS::OnClickBtnExecutableBox...Error!!"<<std::endl;
828 //=========================================================================
830 void wxGUIEditorGraphicBBS::OnClickBtnComplexBox(wxCommandEvent& event) {
831 wxToolBar* toolbar = GetToolBar();
832 bool temp = toolbar->GetToolState(ID_BTNCOMPLEXBOX);
834 _tabsMgr->setActualDiagramComplexBox(true);
836 _tabsMgr->setActualDiagramComplexBox(false);
838 refreshGUIControls();
841 //=========================================================================
843 void wxGUIEditorGraphicBBS::OnAddComplexBoxInput(wxCommandEvent& event) {
844 wxTextEntryDialog *nameDialog = new wxTextEntryDialog(this,
845 wxT("Name of input port"));
846 if (nameDialog->ShowModal() == wxID_OK) {
847 wxString fileName = nameDialog->GetValue();
848 if (!fileName.IsEmpty()) {
849 std::string portName = (const char*) (fileName.mb_str());
850 _tabsMgr->addActualDiagramComplexInputPort(portName);
855 //=========================================================================
857 void wxGUIEditorGraphicBBS::OnAddComplexBoxOutput(wxCommandEvent& event) {
858 wxTextEntryDialog *nameDialog = new wxTextEntryDialog(this,
859 wxT("Name of output port"));
860 if (nameDialog->ShowModal() == wxID_OK) {
861 wxString fileName = nameDialog->GetValue();
862 if (!fileName.IsEmpty()) {
863 std::string portName = (const char*) (fileName.mb_str());
864 _tabsMgr->addActualDiagramComplexOutputPort(portName);
869 //=========================================================================
871 void wxGUIEditorGraphicBBS::OnCopySelectedToComplexDiagram(
872 wxCommandEvent& event) {
873 _tabsMgr->copySelectedBBoxesToComplexDiagram();
876 void wxGUIEditorGraphicBBS::OnHelpBBeditor(wxCommandEvent& event) {
877 printf("wxGUIEditorGraphicBBS::OnHelpBBeditor ....not implemented..\n");
880 //=========================================================================
881 void wxGUIEditorGraphicBBS::OnCreatePackage(wxCommandEvent& event) {
883 bbtkSystemTools::CreatePackage();
886 //=========================================================================
887 void wxGUIEditorGraphicBBS::OnCreateBlackBox(wxCommandEvent& event) {
888 bbtkSystemTools::CreateBlackBox();
890 //=========================================================================
891 void wxGUIEditorGraphicBBS::OnPlugPackage(wxCommandEvent& event) {
892 printf("EED wxGUIEditorGraphicBBS::OnPlugPackage ... not implemented ..\n");
894 //=========================================================================
895 void wxGUIEditorGraphicBBS::OnEditConfig(wxCommandEvent& event) {
896 printf("EED wxGUIEditorGraphicBBS::OnEditConfig ... not implemented ..\n");
898 //=========================================================================
900 void wxGUIEditorGraphicBBS::OnShowHTMLDoc(wxCommandEvent& event) {
902 if (_helpHtmlBrowser != NULL){
903 _frameAUIMgr->DetachPane(_helpHtmlBrowser);
904 _helpHtmlBrowser->Destroy();
906 initHelpHTMLBrowser();
907 _frameAUIMgr->AddPane(_helpHtmlBrowser, wxAuiPaneInfo().Right().MinSize(200, 200));
908 _frameAUIMgr->Update();
909 refreshGUIControls();
913 //=========================================================================
914 void wxGUIEditorGraphicBBS::OnCreateIndex(wxCommandEvent& event) {
915 printf("EED wxGUIEditorGraphicBBS::OnCreateIndex ... not implemented ..\n");
918 //=========================================================================
920 void wxGUIEditorGraphicBBS::OnExit(wxCommandEvent& event) {
926 //=========================================================================
928 } // EO namespace bbtk