1 /*=========================================================================
7 =========================================================================*/
9 /* ---------------------------------------------------------------------
11 * Copyright (c) CREATIS-LRMN (Centre de Recherche en Imagerie Medicale)
12 * Authors : Eduardo Davila, Laurent Guigues, Jean-Pierre Roux
14 * This software is governed by the CeCILL-B license under French law and
15 * abiding by the rules of distribution of free software. You can use,
16 * modify and/ or redistribute the software under the terms of the CeCILL-B
17 * license as circulated by CEA, CNRS and INRIA at the following URL
18 * http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
19 * or in the file LICENSE.txt.
21 * As a counterpart to the access to the source code and rights to copy,
22 * modify and redistribute granted by the license, users are provided only
23 * with a limited warranty and the software's author, the holder of the
24 * economic rights, and the successive licensors have only limited
27 * The fact that you are presently reading this means that you have had
28 * knowledge of the CeCILL-B license and that you accept its terms.
29 * ------------------------------------------------------------------------ */
33 * \brief Class bbtk::WxInterfaceEditorGraphicBBS .
36 #include "bbtkwxGUIEditorGraphicBBS.h"
38 #include "creaSystem.h"
41 #include <InterpreterBBS.h>
45 //=========================================================================
46 wxGUIEditorGraphicBBS::wxGUIEditorGraphicBBS(wxFrame *parent) :
47 wxFrame(parent, -1, _T("bbtkGEditor"), wxDefaultPosition, wxSize(
50 _frameAUIMgr = new wxAuiManager(this);
52 /*std::string datadir( crea::System::GetExecutablePath() );
53 std::string datadir (".");
54 cout<<"RaC //------------------"<<endl;
55 cout<<"RaC //TODO wxGUIEditorGraphicBBS constructor.Initialize datadir with crea::System::GetExecutablePath() ."<<endl;
56 cout<<"RaC //------------------"<<endl;
58 #ifdef LINUX // assume this is OSX
59 datadir=datadir+"/../share/creaContours";
62 #ifdef MACOSX // assume this is OSX
63 datadir=datadir+"/../../../../share/creaContours";
70 initTabPanelsManager();
72 // JGGR & CM initHelpHTMLBrowser();
73 _helpHtmlBrowser = NULL;
75 _frameAUIMgr->Update();
76 _actualPkgBrowserBoxName = "";
77 _actualPkgBrowserPkgName = "";
81 //=========================================================================
82 wxGUIEditorGraphicBBS::~wxGUIEditorGraphicBBS() {
84 printf("EED %p ~wxGUIEditorGraphicBBS()\n", this);
86 //EED02JUIN2010 delete _tabsMgr;
88 _frameAUIMgr->UnInit();
96 //=========================================================================
97 void wxGUIEditorGraphicBBS::initToolbar() {
98 wxBitmap bmp_new(new_xpm);
99 wxBitmap bmp_open(open_xpm);
100 wxBitmap bmp_save(save_xpm);
101 wxBitmap bmp_run(run_xpm);
102 wxBitmap bmp_delete(delete_xpm);
103 wxBitmap bmp_centerview(centerview_xpm);
104 wxBitmap bmp_box(box_xpm);
105 wxBitmap bmp_executablebox(executablebox_xpm);
106 wxBitmap bmp_complexbox(complexbox_xpm);
107 wxBitmap bmp_complexinputport(complexinputport_xpm);
108 wxBitmap bmp_complexoutputport(complexoutputport_xpm);
109 wxBitmap bmp_undo(undo_xpm);
110 wxBitmap bmp_redo(redo_xpm);
111 wxToolBar *toolbar = new wxToolBar(this, wxID_ANY);
113 //Adds a tool btn to the toolbar
114 toolbar->AddTool(ID_NEW, _T("New"), bmp_new, wxNullBitmap, wxITEM_NORMAL,
115 _T("New tab"), _T("Create a new panel tab"));
116 toolbar->AddTool(ID_OPEN, _T("Open diagram"), bmp_open, wxNullBitmap,
117 wxITEM_NORMAL, _T("Open a diagram"), _T("Open a diagram"));
118 toolbar->AddTool(ID_SAVE_DIAGRAM, _T("Save Diagram"), bmp_save,
119 wxNullBitmap, wxITEM_NORMAL, _T("Saves the current diagram"),
120 _T("Saves the current diagram")); //DFCH
121 //toolbar->AddTool(ID_SAVE_AS_DIAGRAM,_T("Save Diagram As"),bmp_save, wxNullBitmap, wxITEM_NORMAL,_T("Saves the current diagram"), _T("Saves the current diagram")); //DFCH
122 toolbar->AddTool(ID_RUN, _T("Run"), bmp_run, wxNullBitmap, wxITEM_NORMAL,
123 _T("Execute actual diagram"), _T("Execute actual diagram"));
124 toolbar->AddTool(ID_DELETEALL, _T("Delete all"), bmp_delete, wxNullBitmap,
125 wxITEM_NORMAL, _T("Delete all boxes"), _T("Delete all boxes"));
126 toolbar->AddTool(ID_CENTERVIEW, _T("Center view"), bmp_centerview,
127 wxNullBitmap, wxITEM_NORMAL, _T("Center view"), _T("Center view"));
128 toolbar->AddSeparator();
129 toolbar->AddTool(ID_BTNBOX, _T("New Box"), bmp_box, wxNullBitmap,
130 wxITEM_NORMAL, _T("New Box"), _T("Nex Box"));
131 toolbar->AddSeparator();
132 toolbar->AddTool(ID_BTEXECUTABLEBOX, _T("Select as executable Box"),
133 bmp_executablebox, wxNullBitmap, wxITEM_NORMAL,
134 _T("Select as executable Box"), _T("Select as executable Box"));
135 toolbar->AddSeparator();
136 toolbar->AddTool(ID_BTNCOMPLEXBOX, _T("Complex box"), complexbox_xpm,
137 wxNullBitmap, wxITEM_NORMAL, _T("Complex box"), _T("Complex box"));
138 toolbar->SetToggle(ID_BTNCOMPLEXBOX, true);
139 toolbar->AddTool(ID_ADDCOMPLEXBOXINPUT, _T("Add input to Complex box"),
140 bmp_complexinputport, wxNullBitmap, wxITEM_NORMAL,
141 _T("Add input to Complex box"), _T("Add input to Complex box"));
142 toolbar->AddTool(ID_ADDCOMPLEXBOXOUTPUT, _T("Add output to Complex box"),
143 bmp_complexoutputport, wxNullBitmap, wxITEM_NORMAL,
144 _T("Add output Complex box"), _T("Add output Complex box"));
145 toolbar->EnableTool(ID_ADDCOMPLEXBOXINPUT, false);
146 toolbar->EnableTool(ID_ADDCOMPLEXBOXOUTPUT, false);
147 toolbar->AddSeparator();
148 toolbar->AddTool(ID_UNDO, _T("Undo"),bmp_undo, wxNullBitmap, wxITEM_NORMAL, _T("Undo"), _T("Undo"));
149 toolbar->AddTool(ID_REDO, _T("Redo"),bmp_redo, wxNullBitmap, wxITEM_NORMAL, _T("Redo"), _T("Redo"));
150 toolbar->EnableTool(ID_UNDO, false);
151 toolbar->EnableTool(ID_REDO, false);
152 toolbar->SetMargins(2, 2);
157 // connect command event handlers
159 Connect(ID_NEW, wxEVT_COMMAND_TOOL_CLICKED,
160 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnCreateNewTab));
161 Connect(ID_OPEN, wxEVT_COMMAND_TOOL_CLICKED,
162 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnOpenDiagram));
163 Connect(ID_SAVE_DIAGRAM, wxEVT_COMMAND_TOOL_CLICKED,
164 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnSaveActualDiagram)); //DFCH
165 Connect(ID_SAVE_AS_DIAGRAM, wxEVT_COMMAND_TOOL_CLICKED,
166 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnSaveAsActualDiagram)); //DFCH
169 wxEVT_COMMAND_TOOL_CLICKED,
170 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnExecuteActualDiagram));
173 wxEVT_COMMAND_TOOL_CLICKED,
174 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnDeleteAllBoxesActualDiagram));
177 wxEVT_COMMAND_TOOL_CLICKED,
178 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnCenterViewActualDiagram));
179 Connect(ID_BTNBOX, wxEVT_COMMAND_TOOL_CLICKED,
180 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnClickBtnBox));
183 wxEVT_COMMAND_TOOL_CLICKED,
184 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnClickBtnExecutableBox));
185 Connect(ID_BTNCOMPLEXBOX, wxEVT_COMMAND_TOOL_CLICKED,
186 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnClickBtnComplexBox));
187 Connect(ID_ADDCOMPLEXBOXINPUT, wxEVT_COMMAND_TOOL_CLICKED,
188 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnAddComplexBoxInput));
189 Connect(ID_ADDCOMPLEXBOXOUTPUT, wxEVT_COMMAND_TOOL_CLICKED,
190 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnAddComplexBoxOutput));
191 Connect(ID_UNDO,wxEVT_COMMAND_TOOL_CLICKED, wxCommandEventHandler(wxGUIEditorGraphicBBS::OnUndo));
192 Connect(ID_REDO,wxEVT_COMMAND_TOOL_CLICKED, wxCommandEventHandler(wxGUIEditorGraphicBBS::OnRedo));
193 Connect(ID_CHANGENAME, wxEVT_COMMAND_RIGHT_CLICK, wxCommandEventHandler(wxGUIEditorGraphicBBS::OnChangeName));
195 //=========================================================================
196 void wxGUIEditorGraphicBBS::initHelpHTMLBrowser() {
198 _helpHtmlBrowser = new WxGUIHtmlBrowser(this, wxSize(200, 0));
204 //=========================================================================
205 void wxGUIEditorGraphicBBS::initMenu() {
206 // Create File menu and its items
207 wxMenu *fileMenu = new wxMenu();
208 fileMenu->Append(ID_NEW, _T("New diagram"), _T("New"));
209 fileMenu->Append(ID_SAVE_DIAGRAM, _T("Save Diagram"), _T("Save Diagram")); //DFCH
210 fileMenu->Append(ID_SAVE_AS_DIAGRAM, _T("Save Diagram As"),
211 _T("Save Diagram As")); //DFCH
212 fileMenu->Append(ID_OPEN_BBS, _T("Open BBS"), _T("Open BBS"));
214 fileMenu->Append(ID_OPEN, _T("Open a diagram"), _T("Open a diagram"));
215 fileMenu->Append(ID_SAVE_AS_BBS, _T("Save BBS"), _T("Save BBS"));
216 fileMenu->Append(ID_SAVE_AS_COMPLEXBOX, _T("Save complex box"),
217 _T("Save complex box"));
218 fileMenu->Append(wxID_EXIT, _T("E&xit"), _T("Exit"));
220 Connect(ID_NEW, wxEVT_COMMAND_MENU_SELECTED,
221 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnCreateNewTab));
222 Connect(ID_SAVE_DIAGRAM, wxEVT_COMMAND_MENU_SELECTED,
223 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnSaveActualDiagram)); //DFCH
224 Connect(ID_SAVE_AS_DIAGRAM, wxEVT_COMMAND_MENU_SELECTED,
225 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnSaveAsActualDiagram));
226 Connect(ID_OPEN_BBS, wxEVT_COMMAND_MENU_SELECTED,
227 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnOpenBBS));
228 Connect(ID_SAVE_AS_BBS, wxEVT_COMMAND_MENU_SELECTED,
229 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnSaveActualBBS));
231 ID_SAVE_AS_COMPLEXBOX,
232 wxEVT_COMMAND_MENU_SELECTED,
233 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnSaveActualComplexBox));
234 Connect(wxID_EXIT, wxEVT_COMMAND_MENU_SELECTED,
235 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnExit));
237 // Create Help menu and its items
238 wxMenu *editMenu = new wxMenu;
239 editMenu->Append(ID_COPY_TO_COMPLEXDIAGRAM,
240 _T("Copy selected to complex box"),
241 _T("Creates a new complex box diagram with selected boxes"));
244 ID_COPY_TO_COMPLEXDIAGRAM,
245 wxEVT_COMMAND_MENU_SELECTED,
246 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnCopySelectedToComplexDiagram));
248 // Create Help menu and its items
249 wxMenu *helpMenu = new wxMenu;
250 helpMenu->Append(wxID_ABOUT, _T("&About..."), _T("About"));
251 helpMenu->Append(ID_HELP_BBEDITOR, _T("&Help..."), _T("Help"));
252 Connect(ID_HELP_BBEDITOR, wxEVT_COMMAND_MENU_SELECTED,
253 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnHelpBBeditor));
256 wxMenu *menuTools = new wxMenu;
257 menuTools->Append(ID_bbEditor_Tool_Menu_CreatePackage,
258 _T("Create &package") );
259 menuTools->Append(ID_bbEditor_Tool_Menu_CreateBlackBox,
260 _T("Create &blackbox") );
261 menuTools->Append(ID_bbEditor_Tool_Menu_PlugPackage, _T("Plug package") );
262 menuTools->Append(ID_bbEditor_Tool_Menu_EditConfig, _T("&Edit bbtk config") );
263 menuTools->Append(ID_bbEditor_Tool_Menu_ShowHTMLDoc,
264 _T("Show &HTML documentation") );
265 menuTools->Append(ID_bbEditor_Tool_Menu_CreateIndex, _T("&Generate index") );
267 Connect(ID_bbEditor_Tool_Menu_CreatePackage, wxEVT_COMMAND_MENU_SELECTED,
268 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnCreatePackage));
269 Connect(ID_bbEditor_Tool_Menu_CreateBlackBox, wxEVT_COMMAND_MENU_SELECTED,
270 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnCreateBlackBox));
271 Connect(ID_bbEditor_Tool_Menu_PlugPackage, wxEVT_COMMAND_MENU_SELECTED,
272 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnPlugPackage));
273 Connect(ID_bbEditor_Tool_Menu_EditConfig, wxEVT_COMMAND_MENU_SELECTED,
274 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnEditConfig));
275 Connect(ID_bbEditor_Tool_Menu_ShowHTMLDoc, wxEVT_COMMAND_MENU_SELECTED,
276 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnShowHTMLDoc));
277 Connect(ID_bbEditor_Tool_Menu_CreateIndex, wxEVT_COMMAND_MENU_SELECTED,
278 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnCreateIndex));
280 // Append the created menu to the menu bar
281 wxMenuBar *menuBar = new wxMenuBar();
282 menuBar->Append(fileMenu, _T("&File") );
283 menuBar->Append(editMenu, _T("&Edit") );
284 menuBar->Append(menuTools, _T("&Tool") );
285 menuBar->Append(helpMenu, _T("&Help") );
287 // Attach this menu bar to the frame
291 //=========================================================================
292 void wxGUIEditorGraphicBBS::initTabPanelsManager() {
293 _notebook = new wxAuiNotebook(this, wxID_NOTEBOOK, wxDefaultPosition,
294 wxDefaultSize, wxAUI_NB_TOP | wxAUI_NB_TAB_MOVE
295 | wxAUI_NB_CLOSE_ON_ACTIVE_TAB | wxAUI_NB_TAB_FIXED_WIDTH
296 | wxAUI_NB_WINDOWLIST_BUTTON);
297 _tabsMgr = new wxTabPanelsManager(this);
298 _frameAUIMgr->AddPane(_notebook, wxAuiPaneInfo().CenterPane());
302 //=========================================================================
303 void wxGUIEditorGraphicBBS::initPackageBrowser() {
304 _pkgBrowser = new WxGUIPackageBrowser2(this);
305 _pkgBrowser->IncludeAll();
306 _frameAUIMgr->AddPane(_pkgBrowser,
307 wxAuiPaneInfo().Left().MinSize(200, 200).CloseButton(false));
310 //================================================================
312 void wxGUIEditorGraphicBBS::DoRegeneratePackageDoc(const std::string& pack) {
313 std::string mess("Regenerating doc for package '");
317 mess = "Regenerating doc for all packages";
320 mess += " ... please wait";
322 SetStatusText(std2wx(mess));
330 command += ConfigurationFile::GetInstance().Get_bin_path();
331 command += ConfigurationFile::GetInstance().Get_file_separator();
332 command += "bbRegeneratePackageDoc";
337 command += " " + pack + " -q";
338 bbtkMessage("debug",1,"Executing system command '"<<command<<"'"<<std::endl);
340 if (!system(command.c_str())) {
341 SetStatusText(_T("Done !"));
343 wxMessageBox(_T("Done !"),_T("Regenerate package '")
344 +std2wx(pack)+_T("' doc"),
345 wxOK | wxICON_INFORMATION);
348 SetStatusText(_T("Done !"));
349 wxString err(_T("An error occured while running '"));
350 err += bbtk::std2wx(command) + _T("'");
351 wxMessageBox(err, _T("Regenerate package doc"), wxOK | wxICON_ERROR);
355 //================================================================
356 void wxGUIEditorGraphicBBS::DoRegenerateBoxesLists() {
357 SetStatusText(_T("Regenerating boxes lists ... please wait"));
364 command += ConfigurationFile::GetInstance().Get_bin_path();
365 command += ConfigurationFile::GetInstance().Get_file_separator();
366 command += "bbRegenerateBoxesLists";
373 bbtkMessage("debug",1,"Executing system command '"<<command<<"'"<<std::endl);
375 if (!system(command.c_str())) {
376 SetStatusText(_T("Done !"));
378 wxMessageBox(_T("Done !"),_T("Regenerate boxes lists"),
379 wxOK | wxICON_INFORMATION);
382 SetStatusText(_T("Done !"));
383 wxString err(_T("An error occured while running '"));
384 err += bbtk::std2wx(command) + _T("'");
385 wxMessageBox(err, _T("Regenerate boxes lists"), wxOK | wxICON_ERROR);
389 //================================================================
390 void wxGUIEditorGraphicBBS::RegenerateAll() {
391 DoRegeneratePackageDoc("-a");
392 DoRegenerateBoxesLists();
395 //================================================================
397 wxAuiNotebook* wxGUIEditorGraphicBBS::getAuiNotebook() {
401 //================================================================
403 void wxGUIEditorGraphicBBS::displayBlackBoxInfo(std::string packageName,
404 std::string boxName) {
405 if (_actualPkgBrowserPkgName != packageName || _actualPkgBrowserBoxName
407 _actualPkgBrowserPkgName = packageName;
408 _actualPkgBrowserBoxName = boxName;
410 BlackBoxDescriptor::Pointer descriptor =
411 GObjectsMVCFactory::getInstance()->getBlackBoxDescriptor(
412 packageName, boxName);
413 _pkgBrowser->WxGUIBlackBoxListUserOnSelected(descriptor.get());
417 //=========================================================================
419 void wxGUIEditorGraphicBBS::editBlackBox(GBlackBoxModel *bbmodel) {
420 wxBlackBoxEditionDialog* dialog =
421 new wxBlackBoxEditionDialog(this, bbmodel);
425 //=========================================================================
427 void wxGUIEditorGraphicBBS::updateStatusBar(std::string textStatus) {
428 SetStatusText(crea::std2wx(textStatus));
431 //=========================================================================
433 void wxGUIEditorGraphicBBS::executeScript(std::string script) {
434 std::string separator =
435 ConfigurationFile::GetInstance().Get_file_separator();
436 std::string dir = ConfigurationFile::GetInstance().Get_default_temp_dir();
437 std::string filename = dir + separator + "tmp_bbtk.bbs";
440 tempFile.open(filename.c_str());
444 std::string command = "";
447 command += "start /b ";
450 // command += "\""+ crea::System::GetExecutablePath();
452 // command += separator + "../../../bbi.app/Contents/MacOS";
456 command += "\"" + filename + "\"";
462 printf("RaC wxGUIEditorGraphicBBS::executeScript %s \n", command.c_str());
463 system(command.c_str());
466 //=========================================================================
467 std::string wxGUIEditorGraphicBBS::CheckExtension(std::string filename, std::string extension) {
468 if(filename.size() > extension.size() ){
469 if( (filename.compare(filename.size()-extension.size(), extension.size(),extension)) !=0 ){
470 filename.append(extension);
473 filename.append(extension);
477 //=========================================================================
479 //=========================================================================
481 void wxGUIEditorGraphicBBS::OnCreateNewTab(wxCommandEvent& event) {
482 _tabsMgr->addNewTab();
483 refreshGUIControls();
486 void wxGUIEditorGraphicBBS::OnUndo(wxCommandEvent& event) {
487 unsigned short disable;
488 _tabsMgr->loadTempDiagram(0);
489 disable = _tabsMgr->getUndoState();
492 std::string name = _tabsMgr->GetNameTabPanel();
493 if(name[name.length() - 1] == '*')
495 name =name.substr(0,name.length()-1);
497 _tabsMgr->SetNameTabPanel(wxString (name.c_str(), wxConvUTF8));
500 GetToolBar()->EnableTool(ID_UNDO,disable);
501 GetToolBar()->EnableTool(ID_REDO,_tabsMgr->getRedoState());
502 refreshGUIControls();
505 void wxGUIEditorGraphicBBS::OnRedo(wxCommandEvent& event) {
506 unsigned short disable;
507 _tabsMgr->loadTempDiagram(1);
508 GetToolBar()->EnableTool(ID_UNDO,_tabsMgr->getUndoState());
509 GetToolBar()->EnableTool(ID_REDO,_tabsMgr->getRedoState());
510 refreshGUIControls();
513 void wxGUIEditorGraphicBBS::OnChangeName(wxCommandEvent& event){
515 //=========================================================================
517 void wxGUIEditorGraphicBBS::OnExecuteActualDiagram(wxCommandEvent& event) {
518 std::string script1 = _tabsMgr->getActualDiagramBBS(true);
519 cout << endl << "RaC wxGUIEditorGraphicBBS::executeActualDiagram SCRIPT"
521 cout << script1 << endl;
523 std::string script2 = _tabsMgr->getActualDiagramBBS(false);
524 executeScript(script2);
527 //=========================================================================
529 //=========================================================================
530 void wxGUIEditorGraphicBBS::OnOpenBBS(wxCommandEvent& event) {
531 wxFileDialog * openFileDialog = new wxFileDialog(this, wxT("Open BBS"),
532 wxEmptyString, wxT("NewBBS"), wxT("*.bbs"), wxOPEN);
533 if (openFileDialog->ShowModal() == wxID_OK) {
534 wxString fileName = openFileDialog->GetPath();
536 _tabsMgr->addNewTab(openFileDialog->GetFilename());
538 bbtk::InterpreterBBS::Pointer I = bbtk::InterpreterBBS::New(
539 this->_tabsMgr->getActualTabPanel()->getSceneManager(),
540 _pkgBrowser->GetFactory());
542 // We tell the interpreter to throw exceptions on error
544 // Interpret the file supposed to define a box called 'Processing'
545 I->InterpretFile((const char*) (fileName.mb_str()));
547 refreshGUIControls();
550 void wxGUIEditorGraphicBBS::SaveActualBBS(std::string filename) {
553 //EED file.open(fileName.c_str());
554 file.open(filename.c_str());
555 std::string content = "";
556 // writing file header
557 content += "# ----------------------------------\n";
558 content += "# - BBTKGEditor v 1.2 BBS BlackBox Script\n";
562 content += "# ----------------------------------\n";
564 content += _tabsMgr->getActualDiagramBBS();
569 void wxGUIEditorGraphicBBS::OnSaveActualBBS(wxCommandEvent& event) {
570 wxFileDialog * saveFileDialog = new wxFileDialog(this,
571 wxT("Save actual BBS"), wxEmptyString, wxT("NewBBS"),
572 wxT("*.bbs"), wxSAVE | wxOVERWRITE_PROMPT);
573 if (saveFileDialog->ShowModal() == wxID_OK) {
574 wxString fileName = saveFileDialog->GetPath();
575 std::string filename = (const char*) (fileName.mb_str());
576 filename=CheckExtension (filename, ".bbs");
577 SaveActualBBS(filename);
582 void wxGUIEditorGraphicBBS::AskComplexBoxConfiguration() {
583 std::string cbName = _tabsMgr->GetCbName();
584 std::string paName = _tabsMgr->GetCbPackageName();
586 wxTextEntryDialog *cbNameDialog = new wxTextEntryDialog(this,
587 wxT("Complex Box name"));
588 wxTextEntryDialog *paNameDialog = new wxTextEntryDialog(this,
589 wxT("Package name"));
591 cbNameDialog->SetValue(wxString(cbName.c_str(), wxConvUTF8));
592 paNameDialog->SetValue(wxString(paName.c_str(), wxConvUTF8));
594 if (cbNameDialog->ShowModal() == wxID_OK) {
595 wxString complexboxname = cbNameDialog->GetValue();
596 cbName = (const char*) (complexboxname.mb_str());
599 if (paNameDialog->ShowModal() == wxID_OK) {
600 wxString packagename = paNameDialog->GetValue();
601 paName = (const char*) (packagename.mb_str());
604 _tabsMgr->SetCbName(cbName);
605 _tabsMgr->SetCbPackageName(paName);
608 //=========================================================================
610 void wxGUIEditorGraphicBBS::SaveActualComplexBox(std::string filename) {
612 file.open(filename.c_str());
614 std::string content = "";
616 // writing file header
617 content += "# ----------------------------------\n";
618 content += "# - BBTKGEditor v 1.2 BBS BlackBox Script (Complex Box)\n";
622 content += "# ----------------------------------\n";
624 content += _tabsMgr->getActualComplexBoxBBS();
629 //=========================================================================
631 void wxGUIEditorGraphicBBS::OnSaveActualComplexBox(wxCommandEvent& event) {
632 wxFileDialog * saveFileDialog = new wxFileDialog(this,
633 wxT("Save Complex Box BBS"), wxEmptyString,
634 _T("ComplexBoxName"), wxT("*.bbs"), wxSAVE
635 | wxOVERWRITE_PROMPT);
636 if (saveFileDialog->ShowModal() == wxID_OK) {
637 wxString fileName = saveFileDialog->GetPath();
638 std::string filename = (const char*) (fileName.mb_str());
639 filename=CheckExtension (filename, ".bbs");
640 SaveActualComplexBox(filename);
644 //=========================================================================
645 void wxGUIEditorGraphicBBS::SaveActualDiagram(std::string filename) {
647 file.open(filename.c_str());
649 std::string content = "";
651 // writing file header
652 content += "# ----------------------------------\n";
653 content += "# - BBTKGEditor v 1.2 BBG BlackBox Diagram file\n";
659 content += "# ----------------------------------\n";
661 content += "APP_START\n";
662 _tabsMgr->saveActualDiagram(content, filename); //DFCH
663 content += "APP_END\n";
668 //=========================================================================
669 void wxGUIEditorGraphicBBS::SaveTempActualDiagram()
671 std::string name = _tabsMgr->GetNameTabPanel();
672 if(name[name.length() - 1] != '*')
674 _tabsMgr->SetNameTabPanel(wxString (name.c_str(), wxConvUTF8));
675 _tabsMgr->saveTempActualDiagram();
678 //=========================================================================
680 //The following method allows to save the current diagram asking the filename
682 void wxGUIEditorGraphicBBS::SaveCurrentDiagramAs() {
683 wxFileDialog * saveFileDialog = new wxFileDialog(this,
684 wxT("Save current diagram"), wxEmptyString, wxT("NewDiagram"),
685 wxT("*.bbg"), wxSAVE | wxOVERWRITE_PROMPT);
686 if (saveFileDialog->ShowModal() == wxID_OK) {
687 //_tabsMgr->SetNameTabPanel(saveFileDialog->GetFilename());
688 wxString pathfileName = saveFileDialog->GetPath();
689 std::string pathfilename = (const char*) (pathfileName.mb_str());
690 pathfilename=CheckExtension (pathfilename, ".bbg");
692 //modify the tab name accordingly
693 wxString fileName = saveFileDialog->GetFilename();
694 std::string filename = (const char*) (fileName.mb_str());
695 filename=CheckExtension (filename, ".bbg");
696 _tabsMgr->SetNameTabPanel( wxString (filename.c_str(), wxConvUTF8) );
698 std::string pathfilenamebbs = pathfilename;
699 pathfilenamebbs[pathfilenamebbs.length() - 1] = 's';
700 if (_tabsMgr->isActualDiagramComplexBox() == false) {
701 SaveActualDiagram(pathfilename);
702 SaveActualBBS(pathfilenamebbs);
704 AskComplexBoxConfiguration();
705 SaveActualDiagram(pathfilename);
706 SaveActualComplexBox(pathfilenamebbs);
707 } //if isActualDiagramComplexBox
708 } // if saveFileDialog
710 //=========================================================================
712 void wxGUIEditorGraphicBBS::OnSaveActualDiagram(wxCommandEvent& event) {
713 std::string pathfilename = _tabsMgr->GetCurrentTabPanelPath();
714 if (pathfilename.empty()) {
715 SaveCurrentDiagramAs();
717 std::string pathfilenamebbs = pathfilename;
718 pathfilenamebbs[pathfilenamebbs.length() - 1] = 's';
720 if (_tabsMgr->isActualDiagramComplexBox() == false) {
721 SaveActualDiagram(pathfilename);
722 SaveActualBBS(pathfilenamebbs);
724 AskComplexBoxConfiguration();
725 SaveActualDiagram(pathfilename);
726 SaveActualComplexBox(pathfilenamebbs);
727 } //if isActualDiagramComplexBox
730 //=========================================================================
732 void wxGUIEditorGraphicBBS::OnSaveAsActualDiagram(wxCommandEvent& event) {
733 SaveCurrentDiagramAs();
735 //=========================================================================
737 void wxGUIEditorGraphicBBS::refreshGUIControls() {
738 wxToolBar* toolbar = GetToolBar();
739 if (_tabsMgr->isActualDiagramComplexBox()) {
740 toolbar->ToggleTool(ID_BTNCOMPLEXBOX, true);
741 toolbar->EnableTool(ID_ADDCOMPLEXBOXINPUT, true);
742 toolbar->EnableTool(ID_ADDCOMPLEXBOXOUTPUT, true);
744 GetMenuBar()->GetMenu(0)->Enable(ID_SAVE_AS_COMPLEXBOX, true);
745 GetMenuBar()->GetMenu(0)->Enable(ID_SAVE_AS_BBS, false);
747 toolbar->ToggleTool(ID_BTNCOMPLEXBOX, false);
748 toolbar->EnableTool(ID_ADDCOMPLEXBOXINPUT, false);
749 toolbar->EnableTool(ID_ADDCOMPLEXBOXOUTPUT, false);
751 GetMenuBar()->GetMenu(0)->Enable(ID_SAVE_AS_COMPLEXBOX, false);
752 GetMenuBar()->GetMenu(0)->Enable(ID_SAVE_AS_BBS, true);
755 GetToolBar()->EnableTool(ID_UNDO,_tabsMgr->getUndoState());
756 GetToolBar()->EnableTool(ID_REDO,_tabsMgr->getRedoState());
758 if (_tabsMgr->getNumActualSelectedObjects() > 0) {
759 GetMenuBar()->GetMenu(1)->Enable(ID_COPY_TO_COMPLEXDIAGRAM, true);
761 ///TODO Fix the possibility to say from the SceneManager to the GUI to refresh the options
762 GetMenuBar()->GetMenu(1)->Enable(ID_COPY_TO_COMPLEXDIAGRAM, true);
767 //=========================================================================
769 void wxGUIEditorGraphicBBS::OnDeleteAllBoxesActualDiagram(wxCommandEvent& event) {
770 wxMessageDialog *dial = new wxMessageDialog(NULL,
771 wxT("Are you sure to delete all boxes of the diagram?"),
772 wxT("Delete all boxes"), wxYES_NO | wxNO_DEFAULT
774 if (dial->ShowModal() == wxID_YES) {
775 _tabsMgr->deleteAllBoxesActualDiagram();
779 //=========================================================================
781 void wxGUIEditorGraphicBBS::OnCenterViewActualDiagram(wxCommandEvent& event) {
782 _tabsMgr->centerViewActualDiagram();
785 //=========================================================================
787 void wxGUIEditorGraphicBBS::OnOpenDiagram(wxCommandEvent& event) {
788 wxFileDialog * openFileDialog = new wxFileDialog(this, wxT("Open diagram"),
789 wxEmptyString, wxT(""), wxT("*.bbg"), wxOPEN | wxFILE_MUST_EXIST);
790 if (openFileDialog->ShowModal() == wxID_OK) {
791 wxString fileName = openFileDialog->GetPath();
792 ifstream inputStream;
793 std::string fName = (const char*) (fileName.mb_str());
795 inputStream.open(fName.c_str());
796 assert(inputStream.good()); // fails
797 _tabsMgr->addNewTab(openFileDialog->GetFilename());
798 _tabsMgr->loadDiagram(inputStream, fName);
802 refreshGUIControls();
805 //=========================================================================
808 void wxGUIEditorGraphicBBS::OnClickBtnBox(wxCommandEvent& event) {
809 BlackBoxDescriptor *bbDes = _pkgBrowser->GetActualSelected();
811 std::string typeName = bbDes->GetTypeName();
812 std::string packageName = bbDes->GetPackage()->GetName();
814 wxGEditorTabPanel *pnl = this->_tabsMgr->getActualTabPanel();
816 // save empty state!!
817 /* if (_tabsMgr->getNumActualSelectedObjects() == 0)
819 SaveTempActualDiagram();
823 wxVtkSceneManager *scn = pnl->getSceneManager();
824 scn->createGBlackBox(50, 50, packageName, typeName);
827 if (GetToolBar()->GetToolEnabled(ID_UNDO) == false)
828 GetToolBar()->EnableTool(ID_UNDO,true);
829 SaveTempActualDiagram();
834 //=========================================================================
836 void wxGUIEditorGraphicBBS::OnClickBtnExecutableBox(wxCommandEvent& event) {
838 wxGEditorTabPanel *pnl = this->_tabsMgr->getActualTabPanel();
841 wxVtkSceneManager *scn = pnl->getSceneManager();
842 if( scn->MakeBoxExecutable() )
843 std::cout<<"DFCH: wxGUIEditorGraphicBBS::OnClickBtnExecutableBox...successful"<<std::endl;
845 std::cout<<"DFCH: wxGUIEditorGraphicBBS::OnClickBtnExecutableBox...Error!!"<<std::endl;
851 //=========================================================================
853 void wxGUIEditorGraphicBBS::OnClickBtnComplexBox(wxCommandEvent& event) {
854 wxToolBar* toolbar = GetToolBar();
855 bool temp = toolbar->GetToolState(ID_BTNCOMPLEXBOX);
857 _tabsMgr->setActualDiagramComplexBox(true);
859 _tabsMgr->setActualDiagramComplexBox(false);
861 refreshGUIControls();
864 //=========================================================================
866 void wxGUIEditorGraphicBBS::OnAddComplexBoxInput(wxCommandEvent& event) {
867 wxTextEntryDialog *nameDialog = new wxTextEntryDialog(this,
868 wxT("Name of input port"));
869 if (nameDialog->ShowModal() == wxID_OK) {
870 wxString fileName = nameDialog->GetValue();
871 if (!fileName.IsEmpty()) {
872 std::string portName = (const char*) (fileName.mb_str());
873 _tabsMgr->addActualDiagramComplexInputPort(portName);
878 //=========================================================================
880 void wxGUIEditorGraphicBBS::OnAddComplexBoxOutput(wxCommandEvent& event) {
881 wxTextEntryDialog *nameDialog = new wxTextEntryDialog(this,
882 wxT("Name of output port"));
883 if (nameDialog->ShowModal() == wxID_OK) {
884 wxString fileName = nameDialog->GetValue();
885 if (!fileName.IsEmpty()) {
886 std::string portName = (const char*) (fileName.mb_str());
887 _tabsMgr->addActualDiagramComplexOutputPort(portName);
892 //=========================================================================
894 void wxGUIEditorGraphicBBS::OnCopySelectedToComplexDiagram(
895 wxCommandEvent& event) {
896 _tabsMgr->copySelectedBBoxesToComplexDiagram();
899 void wxGUIEditorGraphicBBS::OnHelpBBeditor(wxCommandEvent& event) {
900 printf("wxGUIEditorGraphicBBS::OnHelpBBeditor ....not implemented..\n");
903 //=========================================================================
904 void wxGUIEditorGraphicBBS::OnCreatePackage(wxCommandEvent& event) {
906 bbtkSystemTools::CreatePackage();
909 //=========================================================================
910 void wxGUIEditorGraphicBBS::OnCreateBlackBox(wxCommandEvent& event) {
911 bbtkSystemTools::CreateBlackBox();
913 //=========================================================================
914 void wxGUIEditorGraphicBBS::OnPlugPackage(wxCommandEvent& event) {
915 printf("EED wxGUIEditorGraphicBBS::OnPlugPackage ... not implemented ..\n");
917 //=========================================================================
918 void wxGUIEditorGraphicBBS::OnEditConfig(wxCommandEvent& event) {
919 printf("EED wxGUIEditorGraphicBBS::OnEditConfig ... not implemented ..\n");
921 //=========================================================================
923 void wxGUIEditorGraphicBBS::OnShowHTMLDoc(wxCommandEvent& event) {
925 if (_helpHtmlBrowser != NULL){
926 _frameAUIMgr->DetachPane(_helpHtmlBrowser);
927 _helpHtmlBrowser->Destroy();
929 initHelpHTMLBrowser();
930 _frameAUIMgr->AddPane(_helpHtmlBrowser, wxAuiPaneInfo().Right().MinSize(200, 200));
931 _frameAUIMgr->Update();
932 refreshGUIControls();
936 //=========================================================================
937 void wxGUIEditorGraphicBBS::OnCreateIndex(wxCommandEvent& event) {
938 printf("EED wxGUIEditorGraphicBBS::OnCreateIndex ... not implemented ..\n");
941 //=========================================================================
943 void wxGUIEditorGraphicBBS::OnExit(wxCommandEvent& event) {
949 //=========================================================================
951 } // EO namespace bbtk