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"));
151 toolbar->EnableTool(ID_UNDO, false);
152 toolbar->EnableTool(ID_REDO, false);
153 toolbar->SetMargins(2, 2);
158 // connect command event handlers
160 Connect(ID_NEW, wxEVT_COMMAND_TOOL_CLICKED,
161 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnCreateNewTab));
162 Connect(ID_OPEN, wxEVT_COMMAND_TOOL_CLICKED,
163 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnOpenDiagram));
164 Connect(ID_SAVE_DIAGRAM, wxEVT_COMMAND_TOOL_CLICKED,
165 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnSaveActualDiagram)); //DFCH
166 Connect(ID_SAVE_AS_DIAGRAM, wxEVT_COMMAND_TOOL_CLICKED,
167 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnSaveAsActualDiagram)); //DFCH
170 wxEVT_COMMAND_TOOL_CLICKED,
171 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnExecuteActualDiagram));
174 wxEVT_COMMAND_TOOL_CLICKED,
175 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnDeleteAllBoxesActualDiagram));
178 wxEVT_COMMAND_TOOL_CLICKED,
179 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnCenterViewActualDiagram));
180 Connect(ID_BTNBOX, wxEVT_COMMAND_TOOL_CLICKED,
181 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnClickBtnBox));
184 wxEVT_COMMAND_TOOL_CLICKED,
185 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnClickBtnExecutableBox));
186 Connect(ID_BTNCOMPLEXBOX, wxEVT_COMMAND_TOOL_CLICKED,
187 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnClickBtnComplexBox));
188 Connect(ID_ADDCOMPLEXBOXINPUT, wxEVT_COMMAND_TOOL_CLICKED,
189 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnAddComplexBoxInput));
190 Connect(ID_ADDCOMPLEXBOXOUTPUT, wxEVT_COMMAND_TOOL_CLICKED,
191 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnAddComplexBoxOutput));
192 Connect(ID_UNDO,wxEVT_COMMAND_TOOL_CLICKED, wxCommandEventHandler(wxGUIEditorGraphicBBS::OnUndo));
193 Connect(ID_REDO,wxEVT_COMMAND_TOOL_CLICKED, wxCommandEventHandler(wxGUIEditorGraphicBBS::OnRedo));
194 Connect(ID_CHANGENAME, wxEVT_COMMAND_RIGHT_CLICK, wxCommandEventHandler(wxGUIEditorGraphicBBS::OnChangeName));
196 //=========================================================================
197 void wxGUIEditorGraphicBBS::initHelpHTMLBrowser() {
199 _helpHtmlBrowser = new WxGUIHtmlBrowser(this, wxSize(200, 0));
205 //=========================================================================
206 void wxGUIEditorGraphicBBS::initMenu() {
207 // Create File menu and its items
208 wxMenu *fileMenu = new wxMenu();
209 fileMenu->Append(ID_NEW, _T("New diagram"), _T("New"));
210 fileMenu->Append(ID_SAVE_DIAGRAM, _T("Save Diagram"), _T("Save Diagram")); //DFCH
211 fileMenu->Append(ID_SAVE_AS_DIAGRAM, _T("Save Diagram As"),
212 _T("Save Diagram As")); //DFCH
213 fileMenu->Append(ID_OPEN_BBS, _T("Open BBS"), _T("Open BBS"));
215 fileMenu->Append(ID_OPEN, _T("Open a diagram"), _T("Open a diagram"));
216 fileMenu->Append(ID_SAVE_AS_BBS, _T("Save BBS"), _T("Save BBS"));
217 fileMenu->Append(ID_SAVE_AS_COMPLEXBOX, _T("Save complex box"),
218 _T("Save complex box"));
219 fileMenu->Append(wxID_EXIT, _T("E&xit"), _T("Exit"));
221 Connect(ID_NEW, wxEVT_COMMAND_MENU_SELECTED,
222 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnCreateNewTab));
223 Connect(ID_SAVE_DIAGRAM, wxEVT_COMMAND_MENU_SELECTED,
224 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnSaveActualDiagram)); //DFCH
225 Connect(ID_SAVE_AS_DIAGRAM, wxEVT_COMMAND_MENU_SELECTED,
226 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnSaveAsActualDiagram));
227 Connect(ID_OPEN_BBS, wxEVT_COMMAND_MENU_SELECTED,
228 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnOpenBBS));
229 Connect(ID_SAVE_AS_BBS, wxEVT_COMMAND_MENU_SELECTED,
230 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnSaveActualBBS));
232 ID_SAVE_AS_COMPLEXBOX,
233 wxEVT_COMMAND_MENU_SELECTED,
234 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnSaveActualComplexBox));
235 Connect(wxID_EXIT, wxEVT_COMMAND_MENU_SELECTED,
236 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnExit));
238 // Create Help menu and its items
239 wxMenu *editMenu = new wxMenu;
240 editMenu->Append(ID_COPY_TO_COMPLEXDIAGRAM,
241 _T("Copy selected to complex box"),
242 _T("Creates a new complex box diagram with selected boxes"));
245 ID_COPY_TO_COMPLEXDIAGRAM,
246 wxEVT_COMMAND_MENU_SELECTED,
247 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnCopySelectedToComplexDiagram));
249 // Create Help menu and its items
250 wxMenu *helpMenu = new wxMenu;
251 helpMenu->Append(wxID_ABOUT, _T("&About..."), _T("About"));
252 helpMenu->Append(ID_HELP_BBEDITOR, _T("&Help..."), _T("Help"));
253 Connect(ID_HELP_BBEDITOR, wxEVT_COMMAND_MENU_SELECTED,
254 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnHelpBBeditor));
257 wxMenu *menuTools = new wxMenu;
258 menuTools->Append(ID_bbEditor_Tool_Menu_CreatePackage,
259 _T("Create &package") );
260 menuTools->Append(ID_bbEditor_Tool_Menu_CreateBlackBox,
261 _T("Create &blackbox") );
262 menuTools->Append(ID_bbEditor_Tool_Menu_PlugPackage, _T("Plug package") );
263 menuTools->Append(ID_bbEditor_Tool_Menu_EditConfig, _T("&Edit bbtk config") );
264 menuTools->Append(ID_bbEditor_Tool_Menu_ShowHTMLDoc,
265 _T("Show &HTML documentation") );
266 menuTools->Append(ID_bbEditor_Tool_Menu_CreateIndex, _T("&Generate index") );
268 Connect(ID_bbEditor_Tool_Menu_CreatePackage, wxEVT_COMMAND_MENU_SELECTED,
269 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnCreatePackage));
270 Connect(ID_bbEditor_Tool_Menu_CreateBlackBox, wxEVT_COMMAND_MENU_SELECTED,
271 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnCreateBlackBox));
272 Connect(ID_bbEditor_Tool_Menu_PlugPackage, wxEVT_COMMAND_MENU_SELECTED,
273 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnPlugPackage));
274 Connect(ID_bbEditor_Tool_Menu_EditConfig, wxEVT_COMMAND_MENU_SELECTED,
275 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnEditConfig));
276 Connect(ID_bbEditor_Tool_Menu_ShowHTMLDoc, wxEVT_COMMAND_MENU_SELECTED,
277 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnShowHTMLDoc));
278 Connect(ID_bbEditor_Tool_Menu_CreateIndex, wxEVT_COMMAND_MENU_SELECTED,
279 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnCreateIndex));
281 // Append the created menu to the menu bar
282 wxMenuBar *menuBar = new wxMenuBar();
283 menuBar->Append(fileMenu, _T("&File") );
284 menuBar->Append(editMenu, _T("&Edit") );
285 menuBar->Append(menuTools, _T("&Tool") );
286 menuBar->Append(helpMenu, _T("&Help") );
288 // Attach this menu bar to the frame
292 //=========================================================================
293 void wxGUIEditorGraphicBBS::initTabPanelsManager() {
294 _notebook = new wxAuiNotebook(this, wxID_NOTEBOOK, wxDefaultPosition,
295 wxDefaultSize, wxAUI_NB_TOP | wxAUI_NB_TAB_MOVE
296 | wxAUI_NB_CLOSE_ON_ACTIVE_TAB | wxAUI_NB_TAB_FIXED_WIDTH
297 | wxAUI_NB_WINDOWLIST_BUTTON);
298 _tabsMgr = new wxTabPanelsManager(this);
299 _frameAUIMgr->AddPane(_notebook, wxAuiPaneInfo().CenterPane());
303 //=========================================================================
304 void wxGUIEditorGraphicBBS::initPackageBrowser() {
305 _pkgBrowser = new WxGUIPackageBrowser2(this);
306 _pkgBrowser->IncludeAll();
307 _frameAUIMgr->AddPane(_pkgBrowser,
308 wxAuiPaneInfo().Left().MinSize(480, 400).CloseButton(false));
311 //================================================================
313 void wxGUIEditorGraphicBBS::DoRegeneratePackageDoc(const std::string& pack) {
314 std::string mess("Regenerating doc for package '");
318 mess = "Regenerating doc for all packages";
321 mess += " ... please wait";
323 SetStatusText(std2wx(mess));
331 command += ConfigurationFile::GetInstance().Get_bin_path();
332 command += ConfigurationFile::GetInstance().Get_file_separator();
333 command += "bbRegeneratePackageDoc";
338 command += " " + pack + " -q";
339 bbtkMessage("debug",1,"Executing system command '"<<command<<"'"<<std::endl);
341 if (!system(command.c_str())) {
342 SetStatusText(_T("Done !"));
344 wxMessageBox(_T("Done !"),_T("Regenerate package '")
345 +std2wx(pack)+_T("' doc"),
346 wxOK | wxICON_INFORMATION);
349 SetStatusText(_T("Done !"));
350 wxString err(_T("An error occured while running '"));
351 err += bbtk::std2wx(command) + _T("'");
352 wxMessageBox(err, _T("Regenerate package doc"), wxOK | wxICON_ERROR);
356 //================================================================
357 void wxGUIEditorGraphicBBS::DoRegenerateBoxesLists() {
358 SetStatusText(_T("Regenerating boxes lists ... please wait"));
365 command += ConfigurationFile::GetInstance().Get_bin_path();
366 command += ConfigurationFile::GetInstance().Get_file_separator();
367 command += "bbRegenerateBoxesLists";
374 bbtkMessage("debug",1,"Executing system command '"<<command<<"'"<<std::endl);
376 if (!system(command.c_str())) {
377 SetStatusText(_T("Done !"));
379 wxMessageBox(_T("Done !"),_T("Regenerate boxes lists"),
380 wxOK | wxICON_INFORMATION);
383 SetStatusText(_T("Done !"));
384 wxString err(_T("An error occured while running '"));
385 err += bbtk::std2wx(command) + _T("'");
386 wxMessageBox(err, _T("Regenerate boxes lists"), wxOK | wxICON_ERROR);
390 //================================================================
391 void wxGUIEditorGraphicBBS::RegenerateAll() {
392 DoRegeneratePackageDoc("-a");
393 DoRegenerateBoxesLists();
396 //================================================================
398 wxAuiNotebook* wxGUIEditorGraphicBBS::getAuiNotebook() {
402 //================================================================
404 void wxGUIEditorGraphicBBS::displayBlackBoxInfo(std::string packageName,
405 std::string boxName) {
406 if (_actualPkgBrowserPkgName != packageName || _actualPkgBrowserBoxName
408 _actualPkgBrowserPkgName = packageName;
409 _actualPkgBrowserBoxName = boxName;
411 BlackBoxDescriptor::Pointer descriptor =
412 GObjectsMVCFactory::getInstance()->getBlackBoxDescriptor(
413 packageName, boxName);
414 _pkgBrowser->WxGUIBlackBoxListUserOnSelected(descriptor.get());
418 //=========================================================================
420 void wxGUIEditorGraphicBBS::editBlackBox(GBlackBoxModel *bbmodel) {
421 wxBlackBoxEditionDialog* dialog =
422 new wxBlackBoxEditionDialog(this, bbmodel);
426 //=========================================================================
428 bool wxGUIEditorGraphicBBS::boxNameExists(std::string boxname) {
430 return this->_tabsMgr->getActualTabPanel()->getSceneManager()->boxExist(boxname);
433 //=========================================================================
435 void wxGUIEditorGraphicBBS::updateStatusBar(std::string textStatus) {
436 SetStatusText(crea::std2wx(textStatus));
439 //=========================================================================
441 void wxGUIEditorGraphicBBS::executeScript(std::string script) {
442 std::string separator =
443 ConfigurationFile::GetInstance().Get_file_separator();
444 std::string dir = ConfigurationFile::GetInstance().Get_default_temp_dir();
445 std::string filename = dir + separator + "tmp_bbtk.bbs";
448 tempFile.open(filename.c_str());
452 std::string command = "";
455 command += "start /b ";
458 // command += "\""+ crea::System::GetExecutablePath();
460 // command += separator + "../../../bbi.app/Contents/MacOS";
464 command += "\"" + filename + "\"";
470 printf("RaC wxGUIEditorGraphicBBS::executeScript %s \n", command.c_str());
471 system(command.c_str());
474 //=========================================================================
475 std::string wxGUIEditorGraphicBBS::CheckExtension(std::string filename, std::string extension) {
476 if(filename.size() > extension.size() ){
477 if( (filename.compare(filename.size()-extension.size(), extension.size(),extension)) !=0 ){
478 filename.append(extension);
481 filename.append(extension);
485 //=========================================================================
487 //=========================================================================
489 void wxGUIEditorGraphicBBS::OnCreateNewTab(wxCommandEvent& event) {
490 _tabsMgr->addNewTab();
491 refreshGUIControls();
494 void wxGUIEditorGraphicBBS::OnUndo(wxCommandEvent& event) {
495 unsigned short disable;
499 _tabsMgr->loadTempDiagram(0);
500 disable = _tabsMgr->getUndoState(stundo);
503 std::string name = _tabsMgr->GetNameTabPanel();
504 if(name[name.length() - 1] == '*')
506 name =name.substr(0,name.length()-1);
508 _tabsMgr->SetNameTabPanel(wxString (name.c_str(), wxConvUTF8));
511 GetToolBar()->EnableTool(ID_UNDO,disable);
512 GetToolBar()->SetToolShortHelp(ID_UNDO,crea::std2wx(stundo));
513 GetToolBar()->EnableTool(ID_REDO,_tabsMgr->getRedoState(stredo));
514 GetToolBar()->SetToolShortHelp(ID_REDO,crea::std2wx(stredo));
515 refreshGUIControls();
518 void wxGUIEditorGraphicBBS::OnRedo(wxCommandEvent& event) {
519 unsigned short disable;
523 _tabsMgr->loadTempDiagram(1);
524 std::string name = _tabsMgr->GetNameTabPanel();
525 if(name[name.length() - 1] != '*')
527 _tabsMgr->SetNameTabPanel(wxString (name.c_str(), wxConvUTF8));
528 GetToolBar()->EnableTool(ID_UNDO,_tabsMgr->getUndoState(stundo));
529 GetToolBar()->SetToolShortHelp(ID_UNDO,crea::std2wx(stundo));
530 GetToolBar()->EnableTool(ID_REDO,_tabsMgr->getRedoState(stredo));
531 GetToolBar()->SetToolShortHelp(ID_REDO,crea::std2wx(stredo));
532 refreshGUIControls();
535 void wxGUIEditorGraphicBBS::OnChangeName(wxCommandEvent& event){
537 //=========================================================================
539 void wxGUIEditorGraphicBBS::OnExecuteActualDiagram(wxCommandEvent& event) {
540 std::string script1 = _tabsMgr->getActualDiagramBBS(true);
541 cout << endl << "RaC wxGUIEditorGraphicBBS::executeActualDiagram SCRIPT"
543 cout << script1 << endl;
545 std::string script2 = _tabsMgr->getActualDiagramBBS(false);
546 executeScript(script2);
549 //=========================================================================
551 //=========================================================================
552 void wxGUIEditorGraphicBBS::OnOpenBBS(wxCommandEvent& event) {
553 wxFileDialog * openFileDialog = new wxFileDialog(this, wxT("Open BBS"),
554 wxEmptyString, wxT("NewBBS"), wxT("*.bbs"), wxOPEN);
555 if (openFileDialog->ShowModal() == wxID_OK) {
556 wxString fileName = openFileDialog->GetPath();
558 _tabsMgr->addNewTab(openFileDialog->GetFilename());
560 bbtk::InterpreterBBS::Pointer I = bbtk::InterpreterBBS::New(
561 this->_tabsMgr->getActualTabPanel()->getSceneManager(),
562 _pkgBrowser->GetFactory());
564 // We tell the interpreter to throw exceptions on error
566 // Interpret the file supposed to define a box called 'Processing'
567 I->InterpretFile((const char*) (fileName.mb_str()));
569 refreshGUIControls();
572 void wxGUIEditorGraphicBBS::SaveActualBBS(std::string filename) {
575 //EED file.open(fileName.c_str());
576 file.open(filename.c_str());
577 std::string content = "";
578 // writing file header
579 content += "# ----------------------------------\n";
580 content += "# - BBTKGEditor v 1.3 BBS BlackBox Script\n";
584 content += "# ----------------------------------\n";
586 content += _tabsMgr->getActualDiagramBBS();
591 void wxGUIEditorGraphicBBS::OnSaveActualBBS(wxCommandEvent& event) {
592 wxFileDialog * saveFileDialog = new wxFileDialog(this,
593 wxT("Save actual BBS"), wxEmptyString, wxT("NewBBS"),
594 wxT("*.bbs"), wxSAVE | wxOVERWRITE_PROMPT);
595 if (saveFileDialog->ShowModal() == wxID_OK) {
596 wxString fileName = saveFileDialog->GetPath();
597 std::string filename = (const char*) (fileName.mb_str());
598 filename=CheckExtension (filename, ".bbs");
599 SaveActualBBS(filename);
604 void wxGUIEditorGraphicBBS::AskComplexBoxConfiguration() {
605 std::string cbName = _tabsMgr->GetCbName();
606 std::string paName = _tabsMgr->GetCbPackageName();
608 wxTextEntryDialog *cbNameDialog = new wxTextEntryDialog(this,
609 wxT("Complex Box name"));
610 wxTextEntryDialog *paNameDialog = new wxTextEntryDialog(this,
611 wxT("Package name"));
613 cbNameDialog->SetValue(wxString(cbName.c_str(), wxConvUTF8));
614 paNameDialog->SetValue(wxString(paName.c_str(), wxConvUTF8));
616 if (cbNameDialog->ShowModal() == wxID_OK) {
617 wxString complexboxname = cbNameDialog->GetValue();
618 cbName = (const char*) (complexboxname.mb_str());
621 if (paNameDialog->ShowModal() == wxID_OK) {
622 wxString packagename = paNameDialog->GetValue();
623 paName = (const char*) (packagename.mb_str());
626 _tabsMgr->SetCbName(cbName);
627 _tabsMgr->SetCbPackageName(paName);
630 //=========================================================================
632 void wxGUIEditorGraphicBBS::SaveActualComplexBox(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.3 BBS BlackBox Script (Complex Box)\n";
644 content += "# ----------------------------------\n";
646 content += _tabsMgr->getActualComplexBoxBBS();
651 //=========================================================================
653 void wxGUIEditorGraphicBBS::OnSaveActualComplexBox(wxCommandEvent& event) {
654 wxFileDialog * saveFileDialog = new wxFileDialog(this,
655 wxT("Save Complex Box BBS"), wxEmptyString,
656 _T("ComplexBoxName"), wxT("*.bbs"), wxSAVE
657 | wxOVERWRITE_PROMPT);
658 if (saveFileDialog->ShowModal() == wxID_OK) {
659 wxString fileName = saveFileDialog->GetPath();
660 std::string filename = (const char*) (fileName.mb_str());
661 filename=CheckExtension (filename, ".bbs");
662 SaveActualComplexBox(filename);
666 //=========================================================================
667 void wxGUIEditorGraphicBBS::SaveActualDiagram(std::string filename) {
669 file.open(filename.c_str());
671 std::string content = "";
673 // writing file header
674 content += "# ----------------------------------\n";
675 content += "# - BBTKGEditor v 1.3 BBG BlackBox Diagram file\n";
681 content += "# ----------------------------------\n";
683 content += "APP_START\n";
684 _tabsMgr->saveActualDiagram(content, filename); //DFCH
685 content += "APP_END\n";
690 //=========================================================================
691 void wxGUIEditorGraphicBBS::SaveTempActualDiagram(const std::string &action)
695 std::string name = _tabsMgr->GetNameTabPanel();
696 if(name[name.length() - 1] != '*')
698 _tabsMgr->SetNameTabPanel(wxString (name.c_str(), wxConvUTF8));
699 _tabsMgr->saveTempActualDiagram(action);
700 GetToolBar()->EnableTool(ID_UNDO,_tabsMgr->getUndoState(stundo));
701 GetToolBar()->SetToolShortHelp(ID_UNDO,crea::std2wx(stundo));
702 GetToolBar()->EnableTool(ID_REDO,_tabsMgr->getRedoState(stredo));
703 GetToolBar()->SetToolShortHelp(ID_REDO,crea::std2wx(stredo));
706 //=========================================================================
708 //The following method allows to save the current diagram asking the filename
710 void wxGUIEditorGraphicBBS::SaveCurrentDiagramAs() {
711 wxFileDialog * saveFileDialog = new wxFileDialog(this,
712 wxT("Save current diagram"), wxEmptyString, wxT("NewDiagram"),
713 wxT("*.bbg"), wxSAVE | wxOVERWRITE_PROMPT);
714 if (saveFileDialog->ShowModal() == wxID_OK) {
715 //_tabsMgr->SetNameTabPanel(saveFileDialog->GetFilename());
716 wxString pathfileName = saveFileDialog->GetPath();
717 std::string pathfilename = (const char*) (pathfileName.mb_str());
718 pathfilename=CheckExtension (pathfilename, ".bbg");
720 //modify the tab name accordingly
721 wxString fileName = saveFileDialog->GetFilename();
722 std::string filename = (const char*) (fileName.mb_str());
723 filename=CheckExtension (filename, ".bbg");
724 _tabsMgr->SetNameTabPanel( wxString (filename.c_str(), wxConvUTF8) );
726 std::string pathfilenamebbs = pathfilename;
727 pathfilenamebbs[pathfilenamebbs.length() - 1] = 's';
728 if (_tabsMgr->isActualDiagramComplexBox() == false) {
729 SaveActualDiagram(pathfilename);
730 SaveActualBBS(pathfilenamebbs);
732 AskComplexBoxConfiguration();
733 SaveActualDiagram(pathfilename);
734 SaveActualComplexBox(pathfilenamebbs);
735 } //if isActualDiagramComplexBox
736 } // if saveFileDialog
738 //=========================================================================
740 void wxGUIEditorGraphicBBS::OnSaveActualDiagram(wxCommandEvent& event) {
741 std::string pathfilename = _tabsMgr->GetCurrentTabPanelPath();
742 if (pathfilename.empty()) {
743 SaveCurrentDiagramAs();
745 std::string pathfilenamebbs = pathfilename;
746 pathfilenamebbs[pathfilenamebbs.length() - 1] = 's';
748 if (_tabsMgr->isActualDiagramComplexBox() == false) {
749 std::string name = _tabsMgr->GetNameTabPanel();
750 if(name[name.length() - 1] == '*')
752 name =name.substr(0,name.length()-1);
754 _tabsMgr->SetNameTabPanel(wxString (name.c_str(), wxConvUTF8));
755 SaveActualDiagram(pathfilename);
756 SaveActualBBS(pathfilenamebbs);
758 AskComplexBoxConfiguration();
759 SaveActualDiagram(pathfilename);
760 SaveActualComplexBox(pathfilenamebbs);
761 } //if isActualDiagramComplexBox
764 //=========================================================================
766 void wxGUIEditorGraphicBBS::OnSaveAsActualDiagram(wxCommandEvent& event) {
767 SaveCurrentDiagramAs();
769 //=========================================================================
771 void wxGUIEditorGraphicBBS::refreshGUIControls() {
774 wxToolBar* toolbar = GetToolBar();
775 if (_tabsMgr->isActualDiagramComplexBox()) {
776 toolbar->ToggleTool(ID_BTNCOMPLEXBOX, true);
777 toolbar->EnableTool(ID_ADDCOMPLEXBOXINPUT, true);
778 toolbar->EnableTool(ID_ADDCOMPLEXBOXOUTPUT, true);
780 GetMenuBar()->GetMenu(0)->Enable(ID_SAVE_AS_COMPLEXBOX, true);
781 GetMenuBar()->GetMenu(0)->Enable(ID_SAVE_AS_BBS, false);
783 toolbar->ToggleTool(ID_BTNCOMPLEXBOX, false);
784 toolbar->EnableTool(ID_ADDCOMPLEXBOXINPUT, false);
785 toolbar->EnableTool(ID_ADDCOMPLEXBOXOUTPUT, false);
787 GetMenuBar()->GetMenu(0)->Enable(ID_SAVE_AS_COMPLEXBOX, false);
788 GetMenuBar()->GetMenu(0)->Enable(ID_SAVE_AS_BBS, true);
791 GetToolBar()->EnableTool(ID_UNDO,_tabsMgr->getUndoState(stundo));
792 GetToolBar()->SetToolShortHelp(ID_UNDO,crea::std2wx(stundo));
793 GetToolBar()->EnableTool(ID_REDO,_tabsMgr->getRedoState(stredo));
794 GetToolBar()->SetToolShortHelp(ID_REDO,crea::std2wx(stredo));
796 if (_tabsMgr->getNumActualSelectedObjects() > 0) {
797 GetMenuBar()->GetMenu(1)->Enable(ID_COPY_TO_COMPLEXDIAGRAM, true);
799 ///TODO Fix the possibility to say from the SceneManager to the GUI to refresh the options
800 GetMenuBar()->GetMenu(1)->Enable(ID_COPY_TO_COMPLEXDIAGRAM, true);
805 //=========================================================================
807 void wxGUIEditorGraphicBBS::OnDeleteAllBoxesActualDiagram(wxCommandEvent& event) {
808 wxMessageDialog *dial = new wxMessageDialog(NULL,
809 wxT("Are you sure to delete all boxes of the diagram?"),
810 wxT("Delete all boxes"), wxYES_NO | wxNO_DEFAULT
812 if (dial->ShowModal() == wxID_YES) {
813 _tabsMgr->deleteAllBoxesActualDiagram();
817 //=========================================================================
819 void wxGUIEditorGraphicBBS::OnCenterViewActualDiagram(wxCommandEvent& event) {
820 _tabsMgr->centerViewActualDiagram();
823 //=========================================================================
825 void wxGUIEditorGraphicBBS::OnOpenDiagram(wxCommandEvent& event) {
826 wxFileDialog * openFileDialog = new wxFileDialog(this, wxT("Open diagram"),
827 wxEmptyString, wxT(""), wxT("*.bbg"), wxOPEN | wxFILE_MUST_EXIST);
828 printf("SCP: wxGUIEditorGraphicBBS::OnOpenDiagram \n");
829 if (openFileDialog->ShowModal() == wxID_OK) {
830 wxString fileName = openFileDialog->GetPath();
831 ifstream inputStream;
832 std::string fName = (const char*) (fileName.mb_str());
834 inputStream.open(fName.c_str());
835 assert(inputStream.good()); // fails
836 _tabsMgr->addNewTab(openFileDialog->GetFilename());
837 _tabsMgr->loadDiagram(inputStream, fName);
838 _tabsMgr->saveTempActualDiagram("load diagram");
839 GetToolBar()->EnableTool(ID_UNDO, false);
840 GetToolBar()->EnableTool(ID_UNDO, false);
843 refreshGUIControls();
846 //=========================================================================
849 void wxGUIEditorGraphicBBS::OnClickBtnBox(wxCommandEvent& event) {
850 BlackBoxDescriptor *bbDes = _pkgBrowser->GetActualSelected();
852 std::string typeName = bbDes->GetTypeName();
853 std::string packageName = bbDes->GetPackage()->GetName();
855 wxGEditorTabPanel *pnl = this->_tabsMgr->getActualTabPanel();
859 wxVtkSceneManager *scn = pnl->getSceneManager();
860 scn->createGBlackBox(50, 50, packageName, typeName);
864 SaveTempActualDiagram("New Box");
869 //=========================================================================
871 void wxGUIEditorGraphicBBS::OnClickBtnExecutableBox(wxCommandEvent& event) {
873 wxGEditorTabPanel *pnl = this->_tabsMgr->getActualTabPanel();
876 wxVtkSceneManager *scn = pnl->getSceneManager();
877 if( scn->MakeBoxExecutable() )
878 std::cout<<"DFCH: wxGUIEditorGraphicBBS::OnClickBtnExecutableBox...successful"<<std::endl;
880 std::cout<<"DFCH: wxGUIEditorGraphicBBS::OnClickBtnExecutableBox...Error!!"<<std::endl;
886 //=========================================================================
888 void wxGUIEditorGraphicBBS::OnClickBtnComplexBox(wxCommandEvent& event) {
889 wxToolBar* toolbar = GetToolBar();
890 bool temp = toolbar->GetToolState(ID_BTNCOMPLEXBOX);
892 _tabsMgr->setActualDiagramComplexBox(true);
894 _tabsMgr->setActualDiagramComplexBox(false);
896 refreshGUIControls();
899 //=========================================================================
901 void wxGUIEditorGraphicBBS::OnAddComplexBoxInput(wxCommandEvent& event) {
902 wxTextEntryDialog *nameDialog = new wxTextEntryDialog(this,
903 wxT("Name of input port"));
904 if (nameDialog->ShowModal() == wxID_OK) {
905 wxString fileName = nameDialog->GetValue();
906 if (!fileName.IsEmpty()) {
907 std::string portName = (const char*) (fileName.mb_str());
908 _tabsMgr->addActualDiagramComplexInputPort(portName);
913 //=========================================================================
915 void wxGUIEditorGraphicBBS::OnAddComplexBoxOutput(wxCommandEvent& event) {
916 wxTextEntryDialog *nameDialog = new wxTextEntryDialog(this,
917 wxT("Name of output port"));
918 if (nameDialog->ShowModal() == wxID_OK) {
919 wxString fileName = nameDialog->GetValue();
920 if (!fileName.IsEmpty()) {
921 std::string portName = (const char*) (fileName.mb_str());
922 _tabsMgr->addActualDiagramComplexOutputPort(portName);
927 //=========================================================================
929 void wxGUIEditorGraphicBBS::OnCopySelectedToComplexDiagram(
930 wxCommandEvent& event) {
931 _tabsMgr->copySelectedBBoxesToComplexDiagram();
934 void wxGUIEditorGraphicBBS::OnHelpBBeditor(wxCommandEvent& event) {
935 printf("wxGUIEditorGraphicBBS::OnHelpBBeditor ....not implemented..\n");
938 //=========================================================================
939 void wxGUIEditorGraphicBBS::OnCreatePackage(wxCommandEvent& event) {
941 bbtkSystemTools::CreatePackage();
944 //=========================================================================
945 void wxGUIEditorGraphicBBS::OnCreateBlackBox(wxCommandEvent& event) {
946 bbtkSystemTools::CreateBlackBox();
948 //=========================================================================
949 void wxGUIEditorGraphicBBS::OnPlugPackage(wxCommandEvent& event) {
950 printf("EED wxGUIEditorGraphicBBS::OnPlugPackage ... not implemented ..\n");
952 //=========================================================================
953 void wxGUIEditorGraphicBBS::OnEditConfig(wxCommandEvent& event) {
954 printf("EED wxGUIEditorGraphicBBS::OnEditConfig ... not implemented ..\n");
956 //=========================================================================
958 void wxGUIEditorGraphicBBS::OnShowHTMLDoc(wxCommandEvent& event) {
960 if (_helpHtmlBrowser != NULL){
961 _frameAUIMgr->DetachPane(_helpHtmlBrowser);
962 _helpHtmlBrowser->Destroy();
964 initHelpHTMLBrowser();
965 _frameAUIMgr->AddPane(_helpHtmlBrowser, wxAuiPaneInfo().Right().MinSize(200, 200));
966 _frameAUIMgr->Update();
967 refreshGUIControls();
971 //=========================================================================
972 void wxGUIEditorGraphicBBS::OnCreateIndex(wxCommandEvent& event) {
973 printf("EED wxGUIEditorGraphicBBS::OnCreateIndex ... not implemented ..\n");
976 //=========================================================================
978 void wxGUIEditorGraphicBBS::OnExit(wxCommandEvent& event) {
984 //=========================================================================
986 } // EO namespace bbtk