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() {
83 printf("EED %p ~wxGUIEditorGraphicBBS()\n", this);
85 //EED02JUIN2010 delete _tabsMgr;
87 _frameAUIMgr->UnInit();
95 //=========================================================================
96 void wxGUIEditorGraphicBBS::initToolbar() {
97 wxBitmap bmp_new(new_xpm);
98 wxBitmap bmp_open(open_xpm);
99 wxBitmap bmp_save(save_xpm);
100 wxBitmap bmp_run(run_xpm);
101 wxBitmap bmp_delete(delete_xpm);
102 wxBitmap bmp_centerview(centerview_xpm);
103 wxBitmap bmp_box(box_xpm);
104 wxBitmap bmp_executablebox(executablebox_xpm);
105 wxBitmap bmp_complexbox(complexbox_xpm);
106 wxBitmap bmp_complexinputport(complexinputport_xpm);
107 wxBitmap bmp_complexoutputport(complexoutputport_xpm);
108 wxBitmap bmp_undo(undo_xpm);
109 wxBitmap bmp_redo(redo_xpm);
110 wxToolBar *toolbar = new wxToolBar(this, wxID_ANY);
112 //Adds a tool btn to the toolbar
113 toolbar->AddTool(ID_NEW, _T("New"), bmp_new, wxNullBitmap, wxITEM_NORMAL,
114 _T("New tab"), _T("Create a new panel tab"));
115 toolbar->AddTool(ID_OPEN, _T("Open diagram"), bmp_open, wxNullBitmap,
116 wxITEM_NORMAL, _T("Open a diagram"), _T("Open a diagram"));
117 toolbar->AddTool(ID_SAVE_DIAGRAM, _T("Save Diagram"), bmp_save,
118 wxNullBitmap, wxITEM_NORMAL, _T("Saves the current diagram"),
119 _T("Saves the current diagram")); //DFCH
120 //toolbar->AddTool(ID_SAVE_AS_DIAGRAM,_T("Save Diagram As"),bmp_save, wxNullBitmap, wxITEM_NORMAL,_T("Saves the current diagram"), _T("Saves the current diagram")); //DFCH
121 toolbar->AddTool(ID_RUN, _T("Run"), bmp_run, wxNullBitmap, wxITEM_NORMAL,
122 _T("Execute actual diagram"), _T("Execute actual diagram"));
123 toolbar->AddTool(ID_DELETEALL, _T("Delete all"), bmp_delete, wxNullBitmap,
124 wxITEM_NORMAL, _T("Delete all boxes"), _T("Delete all boxes"));
125 toolbar->AddTool(ID_CENTERVIEW, _T("Center view"), bmp_centerview,
126 wxNullBitmap, wxITEM_NORMAL, _T("Center view"), _T("Center view"));
127 toolbar->AddSeparator();
128 toolbar->AddTool(ID_BTNBOX, _T("New Box"), bmp_box, wxNullBitmap,
129 wxITEM_NORMAL, _T("New Box"), _T("Nex Box"));
130 toolbar->AddSeparator();
131 toolbar->AddTool(ID_BTEXECUTABLEBOX, _T("Select as executable Box"),
132 bmp_executablebox, wxNullBitmap, wxITEM_NORMAL,
133 _T("Select as executable Box"), _T("Select as executable Box"));
134 toolbar->AddSeparator();
135 toolbar->AddTool(ID_BTNCOMPLEXBOX, _T("Complex box"), complexbox_xpm,
136 wxNullBitmap, wxITEM_NORMAL, _T("Complex box"), _T("Complex box"));
137 toolbar->SetToggle(ID_BTNCOMPLEXBOX, true);
138 toolbar->AddTool(ID_ADDCOMPLEXBOXINPUT, _T("Add input to Complex box"),
139 bmp_complexinputport, wxNullBitmap, wxITEM_NORMAL,
140 _T("Add input to Complex box"), _T("Add input to Complex box"));
141 toolbar->AddTool(ID_ADDCOMPLEXBOXOUTPUT, _T("Add output to Complex box"),
142 bmp_complexoutputport, wxNullBitmap, wxITEM_NORMAL,
143 _T("Add output Complex box"), _T("Add output Complex box"));
144 toolbar->EnableTool(ID_ADDCOMPLEXBOXINPUT, false);
145 toolbar->EnableTool(ID_ADDCOMPLEXBOXOUTPUT, false);
146 toolbar->AddSeparator();
147 toolbar->AddTool(ID_UNDO, _T("Undo"),bmp_undo, wxNullBitmap, wxITEM_NORMAL, _T("Undo"), _T("Undo"));
148 toolbar->AddTool(ID_REDO, _T("Redo"),bmp_redo, wxNullBitmap, wxITEM_NORMAL, _T("Redo"), _T("Redo"));
149 //toolbar->EnableTool(ID_UNDO, false);
150 //toolbar->EnableTool(ID_REDO, false);
151 toolbar->SetMargins(2, 2);
156 // connect command event handlers
157 Connect(ID_NEW, wxEVT_COMMAND_TOOL_CLICKED,
158 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnCreateNewTab));
159 Connect(ID_OPEN, wxEVT_COMMAND_TOOL_CLICKED,
160 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnOpenDiagram));
161 Connect(ID_SAVE_DIAGRAM, wxEVT_COMMAND_TOOL_CLICKED,
162 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnSaveActualDiagram)); //DFCH
163 Connect(ID_SAVE_AS_DIAGRAM, wxEVT_COMMAND_TOOL_CLICKED,
164 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnSaveAsActualDiagram)); //DFCH
167 wxEVT_COMMAND_TOOL_CLICKED,
168 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnExecuteActualDiagram));
171 wxEVT_COMMAND_TOOL_CLICKED,
172 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnDeleteAllBoxesActualDiagram));
175 wxEVT_COMMAND_TOOL_CLICKED,
176 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnCenterViewActualDiagram));
177 Connect(ID_BTNBOX, wxEVT_COMMAND_TOOL_CLICKED,
178 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnClickBtnBox));
181 wxEVT_COMMAND_TOOL_CLICKED,
182 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnClickBtnExecutableBox));
183 Connect(ID_BTNCOMPLEXBOX, wxEVT_COMMAND_TOOL_CLICKED,
184 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnClickBtnComplexBox));
185 Connect(ID_ADDCOMPLEXBOXINPUT, wxEVT_COMMAND_TOOL_CLICKED,
186 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnAddComplexBoxInput));
187 Connect(ID_ADDCOMPLEXBOXOUTPUT, wxEVT_COMMAND_TOOL_CLICKED,
188 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnAddComplexBoxOutput));
189 Connect(ID_UNDO,wxEVT_COMMAND_TOOL_CLICKED, wxCommandEventHandler(wxGUIEditorGraphicBBS::OnUndo));
190 Connect(ID_REDO,wxEVT_COMMAND_TOOL_CLICKED, wxCommandEventHandler(wxGUIEditorGraphicBBS::OnRedo));
193 //=========================================================================
194 void wxGUIEditorGraphicBBS::initHelpHTMLBrowser() {
195 //TO FIX THE PATH OF BBTK BIN IN ORDER TO USE REGENERATE EXECUTABLES
197 _helpHtmlBrowser = new WxGUIHtmlBrowser(this, wxSize(200, 0));
198 _frameAUIMgr->AddPane(_helpHtmlBrowser, wxAuiPaneInfo().Right().MinSize(
202 //=========================================================================
203 void wxGUIEditorGraphicBBS::initMenu() {
204 // Create File menu and its items
205 wxMenu *fileMenu = new wxMenu();
206 fileMenu->Append(ID_NEW, _T("New diagram"), _T("New"));
207 fileMenu->Append(ID_SAVE_DIAGRAM, _T("Save Diagram"), _T("Save Diagram")); //DFCH
208 fileMenu->Append(ID_SAVE_AS_DIAGRAM, _T("Save Diagram As"),
209 _T("Save Diagram As")); //DFCH
210 fileMenu->Append(ID_OPEN_BBS, _T("Open BBS"), _T("Open BBS"));
211 fileMenu->Append(ID_SAVE_AS_BBS, _T("Save BBS"), _T("Save BBS"));
212 fileMenu->Append(ID_SAVE_AS_COMPLEXBOX, _T("Save complex box"),
213 _T("Save complex box"));
214 fileMenu->Append(wxID_EXIT, _T("E&xit"), _T("Exit"));
216 Connect(ID_NEW, wxEVT_COMMAND_MENU_SELECTED,
217 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnCreateNewTab));
218 Connect(ID_SAVE_DIAGRAM, wxEVT_COMMAND_MENU_SELECTED,
219 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnSaveActualDiagram)); //DFCH
220 Connect(ID_SAVE_AS_DIAGRAM, wxEVT_COMMAND_MENU_SELECTED,
221 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnSaveAsActualDiagram));
222 Connect(ID_OPEN_BBS, wxEVT_COMMAND_MENU_SELECTED,
223 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnOpenBBS));
224 Connect(ID_SAVE_AS_BBS, wxEVT_COMMAND_MENU_SELECTED,
225 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnSaveActualBBS));
227 ID_SAVE_AS_COMPLEXBOX,
228 wxEVT_COMMAND_MENU_SELECTED,
229 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnSaveActualComplexBox));
230 Connect(wxID_EXIT, wxEVT_COMMAND_MENU_SELECTED,
231 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnExit));
233 // Create Help menu and its items
234 wxMenu *editMenu = new wxMenu;
235 editMenu->Append(ID_COPY_TO_COMPLEXDIAGRAM,
236 _T("Copy selected to complex box"),
237 _T("Creates a new complex box diagram with selected boxes"));
240 ID_COPY_TO_COMPLEXDIAGRAM,
241 wxEVT_COMMAND_MENU_SELECTED,
242 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnCopySelectedToComplexDiagram));
244 // Create Help menu and its items
245 wxMenu *helpMenu = new wxMenu;
246 helpMenu->Append(wxID_ABOUT, _T("&About..."), _T("About"));
247 helpMenu->Append(ID_HELP_BBEDITOR, _T("&Help..."), _T("Help"));
248 Connect(ID_HELP_BBEDITOR, wxEVT_COMMAND_MENU_SELECTED,
249 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnHelpBBeditor));
252 wxMenu *menuTools = new wxMenu;
253 menuTools->Append(ID_bbEditor_Tool_Menu_CreatePackage,
254 _T("Create &package") );
255 menuTools->Append(ID_bbEditor_Tool_Menu_CreateBlackBox,
256 _T("Create &blackbox") );
257 menuTools->Append(ID_bbEditor_Tool_Menu_PlugPackage, _T("Plug package") );
258 menuTools->Append(ID_bbEditor_Tool_Menu_EditConfig, _T("&Edit bbtk config") );
259 menuTools->Append(ID_bbEditor_Tool_Menu_ShowHTMLDoc,
260 _T("Show &HTML documentation") );
261 menuTools->Append(ID_bbEditor_Tool_Menu_CreateIndex, _T("&Generate index") );
263 Connect(ID_bbEditor_Tool_Menu_CreatePackage, wxEVT_COMMAND_MENU_SELECTED,
264 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnCreatePackage));
265 Connect(ID_bbEditor_Tool_Menu_CreateBlackBox, wxEVT_COMMAND_MENU_SELECTED,
266 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnCreateBlackBox));
267 Connect(ID_bbEditor_Tool_Menu_PlugPackage, wxEVT_COMMAND_MENU_SELECTED,
268 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnPlugPackage));
269 Connect(ID_bbEditor_Tool_Menu_EditConfig, wxEVT_COMMAND_MENU_SELECTED,
270 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnEditConfig));
271 Connect(ID_bbEditor_Tool_Menu_ShowHTMLDoc, wxEVT_COMMAND_MENU_SELECTED,
272 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnShowHTMLDoc));
273 Connect(ID_bbEditor_Tool_Menu_CreateIndex, wxEVT_COMMAND_MENU_SELECTED,
274 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnCreateIndex));
276 // Append the created menu to the menu bar
277 wxMenuBar *menuBar = new wxMenuBar();
278 menuBar->Append(fileMenu, _T("&File") );
279 menuBar->Append(editMenu, _T("&Edit") );
280 menuBar->Append(menuTools, _T("&Tool") );
281 menuBar->Append(helpMenu, _T("&Help") );
283 // Attach this menu bar to the frame
287 //=========================================================================
288 void wxGUIEditorGraphicBBS::initTabPanelsManager() {
289 _notebook = new wxAuiNotebook(this, wxID_NOTEBOOK, wxDefaultPosition,
290 wxDefaultSize, wxAUI_NB_TOP | wxAUI_NB_TAB_MOVE
291 | wxAUI_NB_CLOSE_ON_ACTIVE_TAB | wxAUI_NB_TAB_FIXED_WIDTH
292 | wxAUI_NB_WINDOWLIST_BUTTON);
293 _tabsMgr = new wxTabPanelsManager(this);
294 _frameAUIMgr->AddPane(_notebook, wxAuiPaneInfo().CenterPane());
298 //=========================================================================
299 void wxGUIEditorGraphicBBS::initPackageBrowser() {
300 _pkgBrowser = new WxGUIPackageBrowser2(this);
301 _pkgBrowser->IncludeAll();
302 _frameAUIMgr->AddPane(_pkgBrowser,
303 wxAuiPaneInfo().Left().MinSize(200, 200).CloseButton(false));
306 //================================================================
308 void wxGUIEditorGraphicBBS::DoRegeneratePackageDoc(const std::string& pack) {
309 std::string mess("Regenerating doc for package '");
313 mess = "Regenerating doc for all packages";
316 mess += " ... please wait";
318 SetStatusText(std2wx(mess));
326 command += ConfigurationFile::GetInstance().Get_bin_path();
327 command += ConfigurationFile::GetInstance().Get_file_separator();
328 command += "bbRegeneratePackageDoc";
333 command += " " + pack + " -q";
334 bbtkMessage("debug",1,"Executing system command '"<<command<<"'"<<std::endl);
336 if (!system(command.c_str())) {
337 SetStatusText(_T("Done !"));
339 wxMessageBox(_T("Done !"),_T("Regenerate package '")
340 +std2wx(pack)+_T("' doc"),
341 wxOK | wxICON_INFORMATION);
344 SetStatusText(_T("Done !"));
345 wxString err(_T("An error occured while running '"));
346 err += bbtk::std2wx(command) + _T("'");
347 wxMessageBox(err, _T("Regenerate package doc"), wxOK | wxICON_ERROR);
351 //================================================================
352 void wxGUIEditorGraphicBBS::DoRegenerateBoxesLists() {
353 SetStatusText(_T("Regenerating boxes lists ... please wait"));
360 command += ConfigurationFile::GetInstance().Get_bin_path();
361 command += ConfigurationFile::GetInstance().Get_file_separator();
362 command += "bbRegenerateBoxesLists";
369 bbtkMessage("debug",1,"Executing system command '"<<command<<"'"<<std::endl);
371 if (!system(command.c_str())) {
372 SetStatusText(_T("Done !"));
374 wxMessageBox(_T("Done !"),_T("Regenerate boxes lists"),
375 wxOK | wxICON_INFORMATION);
378 SetStatusText(_T("Done !"));
379 wxString err(_T("An error occured while running '"));
380 err += bbtk::std2wx(command) + _T("'");
381 wxMessageBox(err, _T("Regenerate boxes lists"), wxOK | wxICON_ERROR);
385 //================================================================
386 void wxGUIEditorGraphicBBS::RegenerateAll() {
387 DoRegeneratePackageDoc("-a");
388 DoRegenerateBoxesLists();
391 //================================================================
393 wxAuiNotebook* wxGUIEditorGraphicBBS::getAuiNotebook() {
397 //================================================================
399 void wxGUIEditorGraphicBBS::displayBlackBoxInfo(std::string packageName,
400 std::string boxName) {
401 if (_actualPkgBrowserPkgName != packageName || _actualPkgBrowserBoxName
403 _actualPkgBrowserPkgName = packageName;
404 _actualPkgBrowserBoxName = boxName;
406 BlackBoxDescriptor::Pointer descriptor =
407 GObjectsMVCFactory::getInstance()->getBlackBoxDescriptor(
408 packageName, boxName);
409 _pkgBrowser->WxGUIBlackBoxListUserOnSelected(descriptor.get());
413 //=========================================================================
415 void wxGUIEditorGraphicBBS::editBlackBox(GBlackBoxModel *bbmodel) {
416 wxBlackBoxEditionDialog* dialog =
417 new wxBlackBoxEditionDialog(this, bbmodel);
421 //=========================================================================
423 void wxGUIEditorGraphicBBS::updateStatusBar(std::string textStatus) {
424 SetStatusText(crea::std2wx(textStatus));
427 //=========================================================================
429 void wxGUIEditorGraphicBBS::executeScript(std::string script) {
430 std::string separator =
431 ConfigurationFile::GetInstance().Get_file_separator();
432 std::string dir = ConfigurationFile::GetInstance().Get_default_temp_dir();
433 std::string filename = dir + separator + "tmp_bbtk.bbs";
436 tempFile.open(filename.c_str());
440 std::string command = "";
443 command += "start /b ";
446 // command += "\""+ crea::System::GetExecutablePath();
448 // command += separator + "../../../bbi.app/Contents/MacOS";
452 command += "\"" + filename + "\"";
458 printf("RaC wxGUIEditorGraphicBBS::executeScript %s \n", command.c_str());
459 system(command.c_str());
462 //=========================================================================
464 //=========================================================================
466 void wxGUIEditorGraphicBBS::OnCreateNewTab(wxCommandEvent& event) {
467 _tabsMgr->addNewTab();
468 refreshGUIControls();
471 void wxGUIEditorGraphicBBS::OnUndo(wxCommandEvent& event) {
472 unsigned short disable;
473 GetToolBar()->EnableTool(ID_UNDO,_tabsMgr->loadTempDiagram(0));
474 if (GetToolBar()->GetToolEnabled(ID_REDO) == false)
475 GetToolBar()->EnableTool(ID_REDO,true);
476 refreshGUIControls();
479 void wxGUIEditorGraphicBBS::OnRedo(wxCommandEvent& event) {
480 unsigned short disable;
481 GetToolBar()->EnableTool(ID_REDO, _tabsMgr->loadTempDiagram(1));
482 if (GetToolBar()->GetToolEnabled(ID_UNDO) == false)
483 GetToolBar()->EnableTool(ID_UNDO,true);
484 refreshGUIControls();
486 //=========================================================================
488 void wxGUIEditorGraphicBBS::OnExecuteActualDiagram(wxCommandEvent& event) {
489 std::string script1 = _tabsMgr->getActualDiagramBBS(true);
490 cout << endl << "RaC wxGUIEditorGraphicBBS::executeActualDiagram SCRIPT"
492 cout << script1 << endl;
494 std::string script2 = _tabsMgr->getActualDiagramBBS(false);
495 executeScript(script2);
498 //=========================================================================
500 //=========================================================================
501 void wxGUIEditorGraphicBBS::OnOpenBBS(wxCommandEvent& event) {
502 wxFileDialog * openFileDialog = new wxFileDialog(this, wxT("Open BBS"),
503 wxEmptyString, wxT("NewBBS"), wxT("*.bbs"), wxOPEN);
504 if (openFileDialog->ShowModal() == wxID_OK) {
505 wxString fileName = openFileDialog->GetPath();
507 _tabsMgr->addNewTab(openFileDialog->GetFilename());
509 bbtk::InterpreterBBS::Pointer I = bbtk::InterpreterBBS::New(
510 this->_tabsMgr->getActualTabPanel()->getSceneManager(),
511 _pkgBrowser->GetFactory());
513 // We tell the interpreter to throw exceptions on error
515 // Interpret the file supposed to define a box called 'Processing'
516 I->InterpretFile((const char*) (fileName.mb_str()));
518 refreshGUIControls();
521 void wxGUIEditorGraphicBBS::SaveActualBBS(std::string filename) {
524 //EED file.open(fileName.c_str());
525 file.open(filename.c_str());
526 std::string content = "";
527 // writing file header
528 content += "# ----------------------------------\n";
529 content += "# - BBTKGEditor v 1.2 BBS BlackBox Script\n";
533 content += "# ----------------------------------\n";
535 content += _tabsMgr->getActualDiagramBBS();
540 void wxGUIEditorGraphicBBS::OnSaveActualBBS(wxCommandEvent& event) {
541 wxFileDialog * saveFileDialog = new wxFileDialog(this,
542 wxT("Save actual BBS"), wxEmptyString, wxT("NewBBS"),
543 wxT("*.bbs"), wxSAVE | wxOVERWRITE_PROMPT);
544 if (saveFileDialog->ShowModal() == wxID_OK) {
545 wxString fileName = saveFileDialog->GetPath();
546 SaveActualBBS((const char*) (fileName.mb_str()));
551 void wxGUIEditorGraphicBBS::AskComplexBoxConfiguration() {
552 std::string cbName = _tabsMgr->GetCbName();
553 std::string paName = _tabsMgr->GetCbPackageName();
555 wxTextEntryDialog *cbNameDialog = new wxTextEntryDialog(this,
556 wxT("Complex Box name"));
557 wxTextEntryDialog *paNameDialog = new wxTextEntryDialog(this,
558 wxT("Package name"));
560 cbNameDialog->SetValue(wxString(cbName.c_str(), wxConvUTF8));
561 paNameDialog->SetValue(wxString(paName.c_str(), wxConvUTF8));
563 if (cbNameDialog->ShowModal() == wxID_OK) {
564 wxString complexboxname = cbNameDialog->GetValue();
565 cbName = (const char*) (complexboxname.mb_str());
568 if (paNameDialog->ShowModal() == wxID_OK) {
569 wxString packagename = paNameDialog->GetValue();
570 paName = (const char*) (packagename.mb_str());
573 _tabsMgr->SetCbName(cbName);
574 _tabsMgr->SetCbPackageName(paName);
577 //=========================================================================
579 void wxGUIEditorGraphicBBS::SaveActualComplexBox(std::string filename) {
581 file.open(filename.c_str());
583 std::string content = "";
585 // writing file header
586 content += "# ----------------------------------\n";
587 content += "# - BBTKGEditor v 1.2 BBS BlackBox Script (Complex Box)\n";
591 content += "# ----------------------------------\n";
593 content += _tabsMgr->getActualComplexBoxBBS();
598 //=========================================================================
600 void wxGUIEditorGraphicBBS::OnSaveActualComplexBox(wxCommandEvent& event) {
601 wxFileDialog * saveFileDialog = new wxFileDialog(this,
602 wxT("Save Complex Box BBS"), wxEmptyString,
603 _T("ComplexBoxName"), wxT("*.bbs"), wxSAVE
604 | wxOVERWRITE_PROMPT);
605 if (saveFileDialog->ShowModal() == wxID_OK) {
606 wxString fileName = saveFileDialog->GetPath();
607 SaveActualComplexBox((const char*) (fileName.mb_str()));
611 //=========================================================================
612 void wxGUIEditorGraphicBBS::SaveActualDiagram(std::string filename) {
614 file.open(filename.c_str());
616 std::string content = "";
618 // writing file header
619 content += "# ----------------------------------\n";
620 content += "# - BBTKGEditor v 1.2 BBG BlackBox Diagram file\n";
626 content += "# ----------------------------------\n";
628 content += "APP_START\n";
629 _tabsMgr->saveActualDiagram(content, filename); //DFCH
630 content += "APP_END\n";
635 //=========================================================================
636 void wxGUIEditorGraphicBBS::SaveTempActualDiagram()
638 _tabsMgr->saveTempActualDiagram();
641 //=========================================================================
643 //The following method allows to save the current diagram asking the filename
645 void wxGUIEditorGraphicBBS::SaveCurrentDiagramAs() {
646 wxFileDialog * saveFileDialog = new wxFileDialog(this,
647 wxT("Save current diagram"), wxEmptyString, wxT("NewDiagram"),
648 wxT("*.bbg"), wxSAVE | wxOVERWRITE_PROMPT);
649 if (saveFileDialog->ShowModal() == wxID_OK) {
650 _tabsMgr->SetNameTabPanel(saveFileDialog->GetFilename());
651 wxString pathfileName = saveFileDialog->GetPath();
652 std::string pathfilename = (const char*) (pathfileName.mb_str());
653 std::string pathfilenamebbs = pathfilename;
654 pathfilenamebbs[pathfilenamebbs.length() - 1] = 's';
655 if (_tabsMgr->isActualDiagramComplexBox() == false) {
656 SaveActualDiagram(pathfilename);
657 SaveActualBBS(pathfilenamebbs);
659 AskComplexBoxConfiguration();
660 SaveActualDiagram(pathfilename);
661 SaveActualComplexBox(pathfilenamebbs);
662 } //if isActualDiagramComplexBox
663 } // if saveFileDialog
665 //=========================================================================
667 void wxGUIEditorGraphicBBS::OnSaveActualDiagram(wxCommandEvent& event) {
668 std::string pathfilename = _tabsMgr->GetCurrentTabPanelPath();
669 if (pathfilename.empty()) {
670 SaveCurrentDiagramAs();
672 std::string pathfilenamebbs = pathfilename;
673 pathfilenamebbs[pathfilenamebbs.length() - 1] = 's';
675 if (_tabsMgr->isActualDiagramComplexBox() == false) {
676 SaveActualDiagram(pathfilename);
677 SaveActualBBS(pathfilenamebbs);
679 AskComplexBoxConfiguration();
680 SaveActualDiagram(pathfilename);
681 SaveActualComplexBox(pathfilenamebbs);
682 } //if isActualDiagramComplexBox
685 //=========================================================================
687 void wxGUIEditorGraphicBBS::OnSaveAsActualDiagram(wxCommandEvent& event) {
688 SaveCurrentDiagramAs();
690 //=========================================================================
692 void wxGUIEditorGraphicBBS::refreshGUIControls() {
693 wxToolBar* toolbar = GetToolBar();
694 if (_tabsMgr->isActualDiagramComplexBox()) {
695 toolbar->ToggleTool(ID_BTNCOMPLEXBOX, true);
696 toolbar->EnableTool(ID_ADDCOMPLEXBOXINPUT, true);
697 toolbar->EnableTool(ID_ADDCOMPLEXBOXOUTPUT, true);
699 GetMenuBar()->GetMenu(0)->Enable(ID_SAVE_AS_COMPLEXBOX, true);
700 GetMenuBar()->GetMenu(0)->Enable(ID_SAVE_AS_BBS, false);
702 toolbar->ToggleTool(ID_BTNCOMPLEXBOX, false);
703 toolbar->EnableTool(ID_ADDCOMPLEXBOXINPUT, false);
704 toolbar->EnableTool(ID_ADDCOMPLEXBOXOUTPUT, false);
706 GetMenuBar()->GetMenu(0)->Enable(ID_SAVE_AS_COMPLEXBOX, false);
707 GetMenuBar()->GetMenu(0)->Enable(ID_SAVE_AS_BBS, true);
710 if (_tabsMgr->getNumActualSelectedObjects() > 0) {
711 GetMenuBar()->GetMenu(1)->Enable(ID_COPY_TO_COMPLEXDIAGRAM, true);
713 ///TODO Fix the possibility to say from the SceneManager to the GUI to refresh the options
714 GetMenuBar()->GetMenu(1)->Enable(ID_COPY_TO_COMPLEXDIAGRAM, true);
719 //=========================================================================
721 void wxGUIEditorGraphicBBS::OnDeleteAllBoxesActualDiagram(wxCommandEvent& event) {
722 wxMessageDialog *dial = new wxMessageDialog(NULL,
723 wxT("Are you sure to delete all boxes of the diagram?"),
724 wxT("Delete all boxes"), wxYES_NO | wxNO_DEFAULT
726 if (dial->ShowModal() == wxID_YES) {
727 _tabsMgr->deleteAllBoxesActualDiagram();
731 //=========================================================================
733 void wxGUIEditorGraphicBBS::OnCenterViewActualDiagram(wxCommandEvent& event) {
734 _tabsMgr->centerViewActualDiagram();
737 //=========================================================================
739 void wxGUIEditorGraphicBBS::OnOpenDiagram(wxCommandEvent& event) {
740 wxFileDialog * openFileDialog = new wxFileDialog(this, wxT("Open diagram"),
741 wxEmptyString, wxT(""), wxT("*.bbg"), wxOPEN | wxFILE_MUST_EXIST);
742 if (openFileDialog->ShowModal() == wxID_OK) {
743 wxString fileName = openFileDialog->GetPath();
744 ifstream inputStream;
745 std::string fName = (const char*) (fileName.mb_str());
746 inputStream.open(fName.c_str());
747 _tabsMgr->addNewTab(openFileDialog->GetFilename());
749 _tabsMgr->loadDiagram(inputStream, fName);
753 refreshGUIControls();
756 //=========================================================================
759 void wxGUIEditorGraphicBBS::OnClickBtnBox(wxCommandEvent& event) {
760 BlackBoxDescriptor *bbDes = _pkgBrowser->GetActualSelected();
762 std::string typeName = bbDes->GetTypeName();
763 std::string packageName = bbDes->GetPackage()->GetName();
765 wxGEditorTabPanel *pnl = this->_tabsMgr->getActualTabPanel();
767 // save empty state!!
768 /* if (_tabsMgr->getNumActualSelectedObjects() == 0)
770 SaveTempActualDiagram();
774 wxVtkSceneManager *scn = pnl->getSceneManager();
775 scn->createGBlackBox(50, 50, packageName, typeName);
778 if (GetToolBar()->GetToolEnabled(ID_UNDO) == false)
779 GetToolBar()->EnableTool(ID_UNDO,true);
780 SaveTempActualDiagram();
785 //=========================================================================
787 void wxGUIEditorGraphicBBS::OnClickBtnExecutableBox(wxCommandEvent& event) {
789 wxGEditorTabPanel *pnl = this->_tabsMgr->getActualTabPanel();
792 wxVtkSceneManager *scn = pnl->getSceneManager();
793 if( scn->MakeBoxExecutable() )
794 std::cout<<"DFCH: wxGUIEditorGraphicBBS::OnClickBtnExecutableBox...successful"<<std::endl;
796 std::cout<<"DFCH: wxGUIEditorGraphicBBS::OnClickBtnExecutableBox...Error!!"<<std::endl;
802 //=========================================================================
804 void wxGUIEditorGraphicBBS::OnClickBtnComplexBox(wxCommandEvent& event) {
805 wxToolBar* toolbar = GetToolBar();
806 bool temp = toolbar->GetToolState(ID_BTNCOMPLEXBOX);
808 _tabsMgr->setActualDiagramComplexBox(true);
810 _tabsMgr->setActualDiagramComplexBox(false);
812 refreshGUIControls();
815 //=========================================================================
817 void wxGUIEditorGraphicBBS::OnAddComplexBoxInput(wxCommandEvent& event) {
818 wxTextEntryDialog *nameDialog = new wxTextEntryDialog(this,
819 wxT("Name of input port"));
820 if (nameDialog->ShowModal() == wxID_OK) {
821 wxString fileName = nameDialog->GetValue();
822 if (!fileName.IsEmpty()) {
823 std::string portName = (const char*) (fileName.mb_str());
824 _tabsMgr->addActualDiagramComplexInputPort(portName);
829 //=========================================================================
831 void wxGUIEditorGraphicBBS::OnAddComplexBoxOutput(wxCommandEvent& event) {
832 wxTextEntryDialog *nameDialog = new wxTextEntryDialog(this,
833 wxT("Name of output port"));
834 if (nameDialog->ShowModal() == wxID_OK) {
835 wxString fileName = nameDialog->GetValue();
836 if (!fileName.IsEmpty()) {
837 std::string portName = (const char*) (fileName.mb_str());
838 _tabsMgr->addActualDiagramComplexOutputPort(portName);
843 //=========================================================================
845 void wxGUIEditorGraphicBBS::OnCopySelectedToComplexDiagram(
846 wxCommandEvent& event) {
847 _tabsMgr->copySelectedBBoxesToComplexDiagram();
850 void wxGUIEditorGraphicBBS::OnHelpBBeditor(wxCommandEvent& event) {
851 printf("wxGUIEditorGraphicBBS::OnHelpBBeditor ....not implemented..\n");
854 //=========================================================================
855 void wxGUIEditorGraphicBBS::OnCreatePackage(wxCommandEvent& event) {
857 bbtkSystemTools::CreatePackage();
860 //=========================================================================
861 void wxGUIEditorGraphicBBS::OnCreateBlackBox(wxCommandEvent& event) {
862 bbtkSystemTools::CreateBlackBox();
864 //=========================================================================
865 void wxGUIEditorGraphicBBS::OnPlugPackage(wxCommandEvent& event) {
866 printf("EED wxGUIEditorGraphicBBS::OnPlugPackage ... not implemented ..\n");
868 //=========================================================================
869 void wxGUIEditorGraphicBBS::OnEditConfig(wxCommandEvent& event) {
870 printf("EED wxGUIEditorGraphicBBS::OnEditConfig ... not implemented ..\n");
872 //=========================================================================
873 void wxGUIEditorGraphicBBS::OnShowHTMLDoc(wxCommandEvent& event) {
874 printf("EED wxGUIEditorGraphicBBS::OnShowHTMLDoc ... not implemented ..\n");
876 //=========================================================================
877 void wxGUIEditorGraphicBBS::OnCreateIndex(wxCommandEvent& event) {
878 printf("EED wxGUIEditorGraphicBBS::OnCreateIndex ... not implemented ..\n");
881 //=========================================================================
883 void wxGUIEditorGraphicBBS::OnExit(wxCommandEvent& event) {
887 //=========================================================================
889 } // EO namespace bbtk