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 initHelpHTMLBrowser();
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
158 Connect(ID_NEW, wxEVT_COMMAND_TOOL_CLICKED,
159 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnCreateNewTab));
160 Connect(ID_OPEN, wxEVT_COMMAND_TOOL_CLICKED,
161 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnOpenDiagram));
162 Connect(ID_SAVE_DIAGRAM, wxEVT_COMMAND_TOOL_CLICKED,
163 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnSaveActualDiagram)); //DFCH
164 Connect(ID_SAVE_AS_DIAGRAM, wxEVT_COMMAND_TOOL_CLICKED,
165 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnSaveAsActualDiagram)); //DFCH
168 wxEVT_COMMAND_TOOL_CLICKED,
169 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnExecuteActualDiagram));
172 wxEVT_COMMAND_TOOL_CLICKED,
173 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnDeleteAllBoxesActualDiagram));
176 wxEVT_COMMAND_TOOL_CLICKED,
177 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnCenterViewActualDiagram));
178 Connect(ID_BTNBOX, wxEVT_COMMAND_TOOL_CLICKED,
179 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnClickBtnBox));
182 wxEVT_COMMAND_TOOL_CLICKED,
183 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnClickBtnExecutableBox));
184 Connect(ID_BTNCOMPLEXBOX, wxEVT_COMMAND_TOOL_CLICKED,
185 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnClickBtnComplexBox));
186 Connect(ID_ADDCOMPLEXBOXINPUT, wxEVT_COMMAND_TOOL_CLICKED,
187 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnAddComplexBoxInput));
188 Connect(ID_ADDCOMPLEXBOXOUTPUT, wxEVT_COMMAND_TOOL_CLICKED,
189 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnAddComplexBoxOutput));
190 Connect(ID_UNDO,wxEVT_COMMAND_TOOL_CLICKED, wxCommandEventHandler(wxGUIEditorGraphicBBS::OnUndo));
191 Connect(ID_REDO,wxEVT_COMMAND_TOOL_CLICKED, wxCommandEventHandler(wxGUIEditorGraphicBBS::OnRedo));
194 //=========================================================================
195 void wxGUIEditorGraphicBBS::initHelpHTMLBrowser() {
196 //TO FIX THE PATH OF BBTK BIN IN ORDER TO USE REGENERATE EXECUTABLES
198 _helpHtmlBrowser = new WxGUIHtmlBrowser(this, wxSize(200, 0));
199 _frameAUIMgr->AddPane(_helpHtmlBrowser, wxAuiPaneInfo().Right().MinSize(
203 //=========================================================================
204 void wxGUIEditorGraphicBBS::initMenu() {
205 // Create File menu and its items
206 wxMenu *fileMenu = new wxMenu();
207 fileMenu->Append(ID_NEW, _T("New diagram"), _T("New"));
208 fileMenu->Append(ID_SAVE_DIAGRAM, _T("Save Diagram"), _T("Save Diagram")); //DFCH
209 fileMenu->Append(ID_SAVE_AS_DIAGRAM, _T("Save Diagram As"),
210 _T("Save Diagram As")); //DFCH
211 fileMenu->Append(ID_OPEN_BBS, _T("Open BBS"), _T("Open BBS"));
212 fileMenu->Append(ID_SAVE_AS_BBS, _T("Save BBS"), _T("Save BBS"));
213 fileMenu->Append(ID_SAVE_AS_COMPLEXBOX, _T("Save complex box"),
214 _T("Save complex box"));
215 fileMenu->Append(wxID_EXIT, _T("E&xit"), _T("Exit"));
217 Connect(ID_NEW, wxEVT_COMMAND_MENU_SELECTED,
218 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnCreateNewTab));
219 Connect(ID_SAVE_DIAGRAM, wxEVT_COMMAND_MENU_SELECTED,
220 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnSaveActualDiagram)); //DFCH
221 Connect(ID_SAVE_AS_DIAGRAM, wxEVT_COMMAND_MENU_SELECTED,
222 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnSaveAsActualDiagram));
223 Connect(ID_OPEN_BBS, wxEVT_COMMAND_MENU_SELECTED,
224 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnOpenBBS));
225 Connect(ID_SAVE_AS_BBS, wxEVT_COMMAND_MENU_SELECTED,
226 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnSaveActualBBS));
228 ID_SAVE_AS_COMPLEXBOX,
229 wxEVT_COMMAND_MENU_SELECTED,
230 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnSaveActualComplexBox));
231 Connect(wxID_EXIT, wxEVT_COMMAND_MENU_SELECTED,
232 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnExit));
234 // Create Help menu and its items
235 wxMenu *editMenu = new wxMenu;
236 editMenu->Append(ID_COPY_TO_COMPLEXDIAGRAM,
237 _T("Copy selected to complex box"),
238 _T("Creates a new complex box diagram with selected boxes"));
241 ID_COPY_TO_COMPLEXDIAGRAM,
242 wxEVT_COMMAND_MENU_SELECTED,
243 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnCopySelectedToComplexDiagram));
245 // Create Help menu and its items
246 wxMenu *helpMenu = new wxMenu;
247 helpMenu->Append(wxID_ABOUT, _T("&About..."), _T("About"));
248 helpMenu->Append(ID_HELP_BBEDITOR, _T("&Help..."), _T("Help"));
249 Connect(ID_HELP_BBEDITOR, wxEVT_COMMAND_MENU_SELECTED,
250 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnHelpBBeditor));
253 wxMenu *menuTools = new wxMenu;
254 menuTools->Append(ID_bbEditor_Tool_Menu_CreatePackage,
255 _T("Create &package") );
256 menuTools->Append(ID_bbEditor_Tool_Menu_CreateBlackBox,
257 _T("Create &blackbox") );
258 menuTools->Append(ID_bbEditor_Tool_Menu_PlugPackage, _T("Plug package") );
259 menuTools->Append(ID_bbEditor_Tool_Menu_EditConfig, _T("&Edit bbtk config") );
260 menuTools->Append(ID_bbEditor_Tool_Menu_ShowHTMLDoc,
261 _T("Show &HTML documentation") );
262 menuTools->Append(ID_bbEditor_Tool_Menu_CreateIndex, _T("&Generate index") );
264 Connect(ID_bbEditor_Tool_Menu_CreatePackage, wxEVT_COMMAND_MENU_SELECTED,
265 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnCreatePackage));
266 Connect(ID_bbEditor_Tool_Menu_CreateBlackBox, wxEVT_COMMAND_MENU_SELECTED,
267 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnCreateBlackBox));
268 Connect(ID_bbEditor_Tool_Menu_PlugPackage, wxEVT_COMMAND_MENU_SELECTED,
269 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnPlugPackage));
270 Connect(ID_bbEditor_Tool_Menu_EditConfig, wxEVT_COMMAND_MENU_SELECTED,
271 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnEditConfig));
272 Connect(ID_bbEditor_Tool_Menu_ShowHTMLDoc, wxEVT_COMMAND_MENU_SELECTED,
273 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnShowHTMLDoc));
274 Connect(ID_bbEditor_Tool_Menu_CreateIndex, wxEVT_COMMAND_MENU_SELECTED,
275 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnCreateIndex));
277 // Append the created menu to the menu bar
278 wxMenuBar *menuBar = new wxMenuBar();
279 menuBar->Append(fileMenu, _T("&File") );
280 menuBar->Append(editMenu, _T("&Edit") );
281 menuBar->Append(menuTools, _T("&Tool") );
282 menuBar->Append(helpMenu, _T("&Help") );
284 // Attach this menu bar to the frame
288 //=========================================================================
289 void wxGUIEditorGraphicBBS::initTabPanelsManager() {
290 _notebook = new wxAuiNotebook(this, wxID_NOTEBOOK, wxDefaultPosition,
291 wxDefaultSize, wxAUI_NB_TOP | wxAUI_NB_TAB_MOVE
292 | wxAUI_NB_CLOSE_ON_ACTIVE_TAB | wxAUI_NB_TAB_FIXED_WIDTH
293 | wxAUI_NB_WINDOWLIST_BUTTON);
294 _tabsMgr = new wxTabPanelsManager(this);
295 _frameAUIMgr->AddPane(_notebook, wxAuiPaneInfo().CenterPane());
299 //=========================================================================
300 void wxGUIEditorGraphicBBS::initPackageBrowser() {
301 _pkgBrowser = new WxGUIPackageBrowser2(this);
302 _pkgBrowser->IncludeAll();
303 _frameAUIMgr->AddPane(_pkgBrowser,
304 wxAuiPaneInfo().Left().MinSize(200, 200).CloseButton(false));
307 //================================================================
309 void wxGUIEditorGraphicBBS::DoRegeneratePackageDoc(const std::string& pack) {
310 std::string mess("Regenerating doc for package '");
314 mess = "Regenerating doc for all packages";
317 mess += " ... please wait";
319 SetStatusText(std2wx(mess));
327 command += ConfigurationFile::GetInstance().Get_bin_path();
328 command += ConfigurationFile::GetInstance().Get_file_separator();
329 command += "bbRegeneratePackageDoc";
334 command += " " + pack + " -q";
335 bbtkMessage("debug",1,"Executing system command '"<<command<<"'"<<std::endl);
337 if (!system(command.c_str())) {
338 SetStatusText(_T("Done !"));
340 wxMessageBox(_T("Done !"),_T("Regenerate package '")
341 +std2wx(pack)+_T("' doc"),
342 wxOK | wxICON_INFORMATION);
345 SetStatusText(_T("Done !"));
346 wxString err(_T("An error occured while running '"));
347 err += bbtk::std2wx(command) + _T("'");
348 wxMessageBox(err, _T("Regenerate package doc"), wxOK | wxICON_ERROR);
352 //================================================================
353 void wxGUIEditorGraphicBBS::DoRegenerateBoxesLists() {
354 SetStatusText(_T("Regenerating boxes lists ... please wait"));
361 command += ConfigurationFile::GetInstance().Get_bin_path();
362 command += ConfigurationFile::GetInstance().Get_file_separator();
363 command += "bbRegenerateBoxesLists";
370 bbtkMessage("debug",1,"Executing system command '"<<command<<"'"<<std::endl);
372 if (!system(command.c_str())) {
373 SetStatusText(_T("Done !"));
375 wxMessageBox(_T("Done !"),_T("Regenerate boxes lists"),
376 wxOK | wxICON_INFORMATION);
379 SetStatusText(_T("Done !"));
380 wxString err(_T("An error occured while running '"));
381 err += bbtk::std2wx(command) + _T("'");
382 wxMessageBox(err, _T("Regenerate boxes lists"), wxOK | wxICON_ERROR);
386 //================================================================
387 void wxGUIEditorGraphicBBS::RegenerateAll() {
388 DoRegeneratePackageDoc("-a");
389 DoRegenerateBoxesLists();
392 //================================================================
394 wxAuiNotebook* wxGUIEditorGraphicBBS::getAuiNotebook() {
398 //================================================================
400 void wxGUIEditorGraphicBBS::displayBlackBoxInfo(std::string packageName,
401 std::string boxName) {
402 if (_actualPkgBrowserPkgName != packageName || _actualPkgBrowserBoxName
404 _actualPkgBrowserPkgName = packageName;
405 _actualPkgBrowserBoxName = boxName;
407 BlackBoxDescriptor::Pointer descriptor =
408 GObjectsMVCFactory::getInstance()->getBlackBoxDescriptor(
409 packageName, boxName);
410 _pkgBrowser->WxGUIBlackBoxListUserOnSelected(descriptor.get());
414 //=========================================================================
416 void wxGUIEditorGraphicBBS::editBlackBox(GBlackBoxModel *bbmodel) {
417 wxBlackBoxEditionDialog* dialog =
418 new wxBlackBoxEditionDialog(this, bbmodel);
422 //=========================================================================
424 void wxGUIEditorGraphicBBS::updateStatusBar(std::string textStatus) {
425 SetStatusText(crea::std2wx(textStatus));
428 //=========================================================================
430 void wxGUIEditorGraphicBBS::executeScript(std::string script) {
431 std::string separator =
432 ConfigurationFile::GetInstance().Get_file_separator();
433 std::string dir = ConfigurationFile::GetInstance().Get_default_temp_dir();
434 std::string filename = dir + separator + "tmp_bbtk.bbs";
437 tempFile.open(filename.c_str());
441 std::string command = "";
444 command += "start /b ";
447 // command += "\""+ crea::System::GetExecutablePath();
449 // command += separator + "../../../bbi.app/Contents/MacOS";
453 command += "\"" + filename + "\"";
459 printf("RaC wxGUIEditorGraphicBBS::executeScript %s \n", command.c_str());
460 system(command.c_str());
463 //=========================================================================
464 std::string wxGUIEditorGraphicBBS::CheckExtension(std::string filename, std::string extension) {
465 if(extension.size() != 4){
466 printf("CheckExtension Warning! Extension size != 4\n");
468 if(filename.size() > 4){
469 if( (filename.compare(filename.size()-4,4,extension)) !=0 ){
470 filename.append(extension);
473 filename.append(extension);
478 //=========================================================================
480 //=========================================================================
482 void wxGUIEditorGraphicBBS::OnCreateNewTab(wxCommandEvent& event) {
483 _tabsMgr->addNewTab();
484 refreshGUIControls();
487 void wxGUIEditorGraphicBBS::OnUndo(wxCommandEvent& event) {
488 unsigned short disable;
489 GetToolBar()->EnableTool(ID_UNDO,_tabsMgr->loadTempDiagram(0));
490 if (GetToolBar()->GetToolEnabled(ID_REDO) == false)
491 GetToolBar()->EnableTool(ID_REDO,true);
492 refreshGUIControls();
495 void wxGUIEditorGraphicBBS::OnRedo(wxCommandEvent& event) {
496 unsigned short disable;
497 GetToolBar()->EnableTool(ID_REDO, _tabsMgr->loadTempDiagram(1));
498 if (GetToolBar()->GetToolEnabled(ID_UNDO) == false)
499 GetToolBar()->EnableTool(ID_UNDO,true);
500 refreshGUIControls();
502 //=========================================================================
504 void wxGUIEditorGraphicBBS::OnExecuteActualDiagram(wxCommandEvent& event) {
505 std::string script1 = _tabsMgr->getActualDiagramBBS(true);
506 cout << endl << "RaC wxGUIEditorGraphicBBS::executeActualDiagram SCRIPT"
508 cout << script1 << endl;
510 std::string script2 = _tabsMgr->getActualDiagramBBS(false);
511 executeScript(script2);
514 //=========================================================================
516 //=========================================================================
517 void wxGUIEditorGraphicBBS::OnOpenBBS(wxCommandEvent& event) {
518 wxFileDialog * openFileDialog = new wxFileDialog(this, wxT("Open BBS"),
519 wxEmptyString, wxT("NewBBS"), wxT("*.bbs"), wxOPEN);
520 if (openFileDialog->ShowModal() == wxID_OK) {
521 wxString fileName = openFileDialog->GetPath();
523 _tabsMgr->addNewTab(openFileDialog->GetFilename());
525 bbtk::InterpreterBBS::Pointer I = bbtk::InterpreterBBS::New(
526 this->_tabsMgr->getActualTabPanel()->getSceneManager(),
527 _pkgBrowser->GetFactory());
529 // We tell the interpreter to throw exceptions on error
531 // Interpret the file supposed to define a box called 'Processing'
532 I->InterpretFile((const char*) (fileName.mb_str()));
534 refreshGUIControls();
537 void wxGUIEditorGraphicBBS::SaveActualBBS(std::string filename) {
540 //EED file.open(fileName.c_str());
541 file.open(filename.c_str());
542 std::string content = "";
543 // writing file header
544 content += "# ----------------------------------\n";
545 content += "# - BBTKGEditor v 1.2 BBS BlackBox Script\n";
549 content += "# ----------------------------------\n";
551 content += _tabsMgr->getActualDiagramBBS();
556 void wxGUIEditorGraphicBBS::OnSaveActualBBS(wxCommandEvent& event) {
557 wxFileDialog * saveFileDialog = new wxFileDialog(this,
558 wxT("Save actual BBS"), wxEmptyString, wxT("NewBBS"),
559 wxT("*.bbs"), wxSAVE | wxOVERWRITE_PROMPT);
560 if (saveFileDialog->ShowModal() == wxID_OK) {
561 wxString fileName = saveFileDialog->GetPath();
562 std::string filename = (const char*) (fileName.mb_str());
563 filename=CheckExtension (filename, ".bbs");
564 SaveActualBBS(filename);
569 void wxGUIEditorGraphicBBS::AskComplexBoxConfiguration() {
570 std::string cbName = _tabsMgr->GetCbName();
571 std::string paName = _tabsMgr->GetCbPackageName();
573 wxTextEntryDialog *cbNameDialog = new wxTextEntryDialog(this,
574 wxT("Complex Box name"));
575 wxTextEntryDialog *paNameDialog = new wxTextEntryDialog(this,
576 wxT("Package name"));
578 cbNameDialog->SetValue(wxString(cbName.c_str(), wxConvUTF8));
579 paNameDialog->SetValue(wxString(paName.c_str(), wxConvUTF8));
581 if (cbNameDialog->ShowModal() == wxID_OK) {
582 wxString complexboxname = cbNameDialog->GetValue();
583 cbName = (const char*) (complexboxname.mb_str());
586 if (paNameDialog->ShowModal() == wxID_OK) {
587 wxString packagename = paNameDialog->GetValue();
588 paName = (const char*) (packagename.mb_str());
591 _tabsMgr->SetCbName(cbName);
592 _tabsMgr->SetCbPackageName(paName);
595 //=========================================================================
597 void wxGUIEditorGraphicBBS::SaveActualComplexBox(std::string filename) {
599 file.open(filename.c_str());
601 std::string content = "";
603 // writing file header
604 content += "# ----------------------------------\n";
605 content += "# - BBTKGEditor v 1.2 BBS BlackBox Script (Complex Box)\n";
609 content += "# ----------------------------------\n";
611 content += _tabsMgr->getActualComplexBoxBBS();
616 //=========================================================================
618 void wxGUIEditorGraphicBBS::OnSaveActualComplexBox(wxCommandEvent& event) {
619 wxFileDialog * saveFileDialog = new wxFileDialog(this,
620 wxT("Save Complex Box BBS"), wxEmptyString,
621 _T("ComplexBoxName"), wxT("*.bbs"), wxSAVE
622 | wxOVERWRITE_PROMPT);
623 if (saveFileDialog->ShowModal() == wxID_OK) {
624 wxString fileName = saveFileDialog->GetPath();
625 std::string filename = (const char*) (fileName.mb_str());
626 filename=CheckExtension (filename, ".bbs");
627 SaveActualComplexBox(filename);
631 //=========================================================================
632 void wxGUIEditorGraphicBBS::SaveActualDiagram(std::string filename) {
634 file.open(filename.c_str());
636 std::string content = "";
638 // writing file header
639 content += "# ----------------------------------\n";
640 content += "# - BBTKGEditor v 1.2 BBG BlackBox Diagram file\n";
646 content += "# ----------------------------------\n";
648 content += "APP_START\n";
649 _tabsMgr->saveActualDiagram(content, filename); //DFCH
650 content += "APP_END\n";
655 //=========================================================================
656 void wxGUIEditorGraphicBBS::SaveTempActualDiagram()
658 _tabsMgr->saveTempActualDiagram();
661 //=========================================================================
663 //The following method allows to save the current diagram asking the filename
665 void wxGUIEditorGraphicBBS::SaveCurrentDiagramAs() {
666 wxFileDialog * saveFileDialog = new wxFileDialog(this,
667 wxT("Save current diagram"), wxEmptyString, wxT("NewDiagram"),
668 wxT("*.bbg"), wxSAVE | wxOVERWRITE_PROMPT);
669 if (saveFileDialog->ShowModal() == wxID_OK) {
670 //_tabsMgr->SetNameTabPanel(saveFileDialog->GetFilename());
671 wxString pathfileName = saveFileDialog->GetPath();
672 std::string pathfilename = (const char*) (pathfileName.mb_str());
673 pathfilename=CheckExtension (pathfilename, ".bbg");
675 //modify the tab name accordingly
676 wxString fileName = saveFileDialog->GetFilename();
677 std::string filename = (const char*) (fileName.mb_str());
678 filename=CheckExtension (filename, ".bbg");
679 _tabsMgr->SetNameTabPanel( wxString (filename.c_str(), wxConvUTF8) );
681 std::string pathfilenamebbs = pathfilename;
682 pathfilenamebbs[pathfilenamebbs.length() - 1] = 's';
683 if (_tabsMgr->isActualDiagramComplexBox() == false) {
684 SaveActualDiagram(pathfilename);
685 SaveActualBBS(pathfilenamebbs);
687 AskComplexBoxConfiguration();
688 SaveActualDiagram(pathfilename);
689 SaveActualComplexBox(pathfilenamebbs);
690 } //if isActualDiagramComplexBox
691 } // if saveFileDialog
693 //=========================================================================
695 void wxGUIEditorGraphicBBS::OnSaveActualDiagram(wxCommandEvent& event) {
696 std::string pathfilename = _tabsMgr->GetCurrentTabPanelPath();
697 if (pathfilename.empty()) {
698 SaveCurrentDiagramAs();
700 std::string pathfilenamebbs = pathfilename;
701 pathfilenamebbs[pathfilenamebbs.length() - 1] = 's';
703 if (_tabsMgr->isActualDiagramComplexBox() == false) {
704 SaveActualDiagram(pathfilename);
705 SaveActualBBS(pathfilenamebbs);
707 AskComplexBoxConfiguration();
708 SaveActualDiagram(pathfilename);
709 SaveActualComplexBox(pathfilenamebbs);
710 } //if isActualDiagramComplexBox
713 //=========================================================================
715 void wxGUIEditorGraphicBBS::OnSaveAsActualDiagram(wxCommandEvent& event) {
716 SaveCurrentDiagramAs();
718 //=========================================================================
720 void wxGUIEditorGraphicBBS::refreshGUIControls() {
721 wxToolBar* toolbar = GetToolBar();
722 if (_tabsMgr->isActualDiagramComplexBox()) {
723 toolbar->ToggleTool(ID_BTNCOMPLEXBOX, true);
724 toolbar->EnableTool(ID_ADDCOMPLEXBOXINPUT, true);
725 toolbar->EnableTool(ID_ADDCOMPLEXBOXOUTPUT, true);
727 GetMenuBar()->GetMenu(0)->Enable(ID_SAVE_AS_COMPLEXBOX, true);
728 GetMenuBar()->GetMenu(0)->Enable(ID_SAVE_AS_BBS, false);
730 toolbar->ToggleTool(ID_BTNCOMPLEXBOX, false);
731 toolbar->EnableTool(ID_ADDCOMPLEXBOXINPUT, false);
732 toolbar->EnableTool(ID_ADDCOMPLEXBOXOUTPUT, false);
734 GetMenuBar()->GetMenu(0)->Enable(ID_SAVE_AS_COMPLEXBOX, false);
735 GetMenuBar()->GetMenu(0)->Enable(ID_SAVE_AS_BBS, true);
738 if (_tabsMgr->getNumActualSelectedObjects() > 0) {
739 GetMenuBar()->GetMenu(1)->Enable(ID_COPY_TO_COMPLEXDIAGRAM, true);
741 ///TODO Fix the possibility to say from the SceneManager to the GUI to refresh the options
742 GetMenuBar()->GetMenu(1)->Enable(ID_COPY_TO_COMPLEXDIAGRAM, true);
747 //=========================================================================
749 void wxGUIEditorGraphicBBS::OnDeleteAllBoxesActualDiagram(wxCommandEvent& event) {
750 wxMessageDialog *dial = new wxMessageDialog(NULL,
751 wxT("Are you sure to delete all boxes of the diagram?"),
752 wxT("Delete all boxes"), wxYES_NO | wxNO_DEFAULT
754 if (dial->ShowModal() == wxID_YES) {
755 _tabsMgr->deleteAllBoxesActualDiagram();
759 //=========================================================================
761 void wxGUIEditorGraphicBBS::OnCenterViewActualDiagram(wxCommandEvent& event) {
762 _tabsMgr->centerViewActualDiagram();
765 //=========================================================================
767 void wxGUIEditorGraphicBBS::OnOpenDiagram(wxCommandEvent& event) {
768 wxFileDialog * openFileDialog = new wxFileDialog(this, wxT("Open diagram"),
769 wxEmptyString, wxT(""), wxT("*.bbg"), wxOPEN | wxFILE_MUST_EXIST);
770 if (openFileDialog->ShowModal() == wxID_OK) {
771 wxString fileName = openFileDialog->GetPath();
772 ifstream inputStream;
773 std::string fName = (const char*) (fileName.mb_str());
774 inputStream.open(fName.c_str());
775 _tabsMgr->addNewTab(openFileDialog->GetFilename());
777 _tabsMgr->loadDiagram(inputStream, fName);
781 refreshGUIControls();
784 //=========================================================================
787 void wxGUIEditorGraphicBBS::OnClickBtnBox(wxCommandEvent& event) {
788 BlackBoxDescriptor *bbDes = _pkgBrowser->GetActualSelected();
790 std::string typeName = bbDes->GetTypeName();
791 std::string packageName = bbDes->GetPackage()->GetName();
793 wxGEditorTabPanel *pnl = this->_tabsMgr->getActualTabPanel();
795 // save empty state!!
796 /* if (_tabsMgr->getNumActualSelectedObjects() == 0)
798 SaveTempActualDiagram();
802 wxVtkSceneManager *scn = pnl->getSceneManager();
803 scn->createGBlackBox(50, 50, packageName, typeName);
806 if (GetToolBar()->GetToolEnabled(ID_UNDO) == false)
807 GetToolBar()->EnableTool(ID_UNDO,true);
808 SaveTempActualDiagram();
813 //=========================================================================
815 void wxGUIEditorGraphicBBS::OnClickBtnExecutableBox(wxCommandEvent& event) {
817 wxGEditorTabPanel *pnl = this->_tabsMgr->getActualTabPanel();
820 wxVtkSceneManager *scn = pnl->getSceneManager();
821 if( scn->MakeBoxExecutable() )
822 std::cout<<"DFCH: wxGUIEditorGraphicBBS::OnClickBtnExecutableBox...successful"<<std::endl;
824 std::cout<<"DFCH: wxGUIEditorGraphicBBS::OnClickBtnExecutableBox...Error!!"<<std::endl;
830 //=========================================================================
832 void wxGUIEditorGraphicBBS::OnClickBtnComplexBox(wxCommandEvent& event) {
833 wxToolBar* toolbar = GetToolBar();
834 bool temp = toolbar->GetToolState(ID_BTNCOMPLEXBOX);
836 _tabsMgr->setActualDiagramComplexBox(true);
838 _tabsMgr->setActualDiagramComplexBox(false);
840 refreshGUIControls();
843 //=========================================================================
845 void wxGUIEditorGraphicBBS::OnAddComplexBoxInput(wxCommandEvent& event) {
846 wxTextEntryDialog *nameDialog = new wxTextEntryDialog(this,
847 wxT("Name of input port"));
848 if (nameDialog->ShowModal() == wxID_OK) {
849 wxString fileName = nameDialog->GetValue();
850 if (!fileName.IsEmpty()) {
851 std::string portName = (const char*) (fileName.mb_str());
852 _tabsMgr->addActualDiagramComplexInputPort(portName);
857 //=========================================================================
859 void wxGUIEditorGraphicBBS::OnAddComplexBoxOutput(wxCommandEvent& event) {
860 wxTextEntryDialog *nameDialog = new wxTextEntryDialog(this,
861 wxT("Name of output port"));
862 if (nameDialog->ShowModal() == wxID_OK) {
863 wxString fileName = nameDialog->GetValue();
864 if (!fileName.IsEmpty()) {
865 std::string portName = (const char*) (fileName.mb_str());
866 _tabsMgr->addActualDiagramComplexOutputPort(portName);
871 //=========================================================================
873 void wxGUIEditorGraphicBBS::OnCopySelectedToComplexDiagram(
874 wxCommandEvent& event) {
875 _tabsMgr->copySelectedBBoxesToComplexDiagram();
878 void wxGUIEditorGraphicBBS::OnHelpBBeditor(wxCommandEvent& event) {
879 printf("wxGUIEditorGraphicBBS::OnHelpBBeditor ....not implemented..\n");
882 //=========================================================================
883 void wxGUIEditorGraphicBBS::OnCreatePackage(wxCommandEvent& event) {
885 bbtkSystemTools::CreatePackage();
888 //=========================================================================
889 void wxGUIEditorGraphicBBS::OnCreateBlackBox(wxCommandEvent& event) {
890 bbtkSystemTools::CreateBlackBox();
892 //=========================================================================
893 void wxGUIEditorGraphicBBS::OnPlugPackage(wxCommandEvent& event) {
894 printf("EED wxGUIEditorGraphicBBS::OnPlugPackage ... not implemented ..\n");
896 //=========================================================================
897 void wxGUIEditorGraphicBBS::OnEditConfig(wxCommandEvent& event) {
898 printf("EED wxGUIEditorGraphicBBS::OnEditConfig ... not implemented ..\n");
900 //=========================================================================
901 void wxGUIEditorGraphicBBS::OnShowHTMLDoc(wxCommandEvent& event) {
902 printf("EED wxGUIEditorGraphicBBS::OnShowHTMLDoc ... not implemented ..\n");
904 //=========================================================================
905 void wxGUIEditorGraphicBBS::OnCreateIndex(wxCommandEvent& event) {
906 printf("EED wxGUIEditorGraphicBBS::OnCreateIndex ... not implemented ..\n");
909 //=========================================================================
911 void wxGUIEditorGraphicBBS::OnExit(wxCommandEvent& event) {
915 //=========================================================================
917 } // EO namespace bbtk