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 bool wxGUIEditorGraphicBBS::boxNameExists(std::string boxname) {
429 return this->_tabsMgr->getActualTabPanel()->getSceneManager()->boxExist(boxname);
432 //=========================================================================
434 void wxGUIEditorGraphicBBS::updateStatusBar(std::string textStatus) {
435 SetStatusText(crea::std2wx(textStatus));
438 //=========================================================================
440 void wxGUIEditorGraphicBBS::executeScript(std::string script) {
441 std::string separator =
442 ConfigurationFile::GetInstance().Get_file_separator();
443 std::string dir = ConfigurationFile::GetInstance().Get_default_temp_dir();
444 std::string filename = dir + separator + "tmp_bbtk.bbs";
447 tempFile.open(filename.c_str());
451 std::string command = "";
454 command += "start /b ";
457 // command += "\""+ crea::System::GetExecutablePath();
459 // command += separator + "../../../bbi.app/Contents/MacOS";
463 command += "\"" + filename + "\"";
469 printf("RaC wxGUIEditorGraphicBBS::executeScript %s \n", command.c_str());
470 system(command.c_str());
473 //=========================================================================
474 std::string wxGUIEditorGraphicBBS::CheckExtension(std::string filename, std::string extension) {
475 if(filename.size() > extension.size() ){
476 if( (filename.compare(filename.size()-extension.size(), extension.size(),extension)) !=0 ){
477 filename.append(extension);
480 filename.append(extension);
484 //=========================================================================
486 //=========================================================================
488 void wxGUIEditorGraphicBBS::OnCreateNewTab(wxCommandEvent& event) {
489 _tabsMgr->addNewTab();
490 refreshGUIControls();
493 void wxGUIEditorGraphicBBS::OnUndo(wxCommandEvent& event) {
494 unsigned short disable;
495 _tabsMgr->loadTempDiagram(0);
496 disable = _tabsMgr->getUndoState();
499 std::string name = _tabsMgr->GetNameTabPanel();
500 if(name[name.length() - 1] == '*')
502 name =name.substr(0,name.length()-1);
504 _tabsMgr->SetNameTabPanel(wxString (name.c_str(), wxConvUTF8));
507 GetToolBar()->EnableTool(ID_UNDO,disable);
508 GetToolBar()->EnableTool(ID_REDO,_tabsMgr->getRedoState());
509 refreshGUIControls();
512 void wxGUIEditorGraphicBBS::OnRedo(wxCommandEvent& event) {
513 unsigned short disable;
514 _tabsMgr->loadTempDiagram(1);
515 GetToolBar()->EnableTool(ID_UNDO,_tabsMgr->getUndoState());
516 GetToolBar()->EnableTool(ID_REDO,_tabsMgr->getRedoState());
517 refreshGUIControls();
520 void wxGUIEditorGraphicBBS::OnChangeName(wxCommandEvent& event){
522 //=========================================================================
524 void wxGUIEditorGraphicBBS::OnExecuteActualDiagram(wxCommandEvent& event) {
525 std::string script1 = _tabsMgr->getActualDiagramBBS(true);
526 cout << endl << "RaC wxGUIEditorGraphicBBS::executeActualDiagram SCRIPT"
528 cout << script1 << endl;
530 std::string script2 = _tabsMgr->getActualDiagramBBS(false);
531 executeScript(script2);
534 //=========================================================================
536 //=========================================================================
537 void wxGUIEditorGraphicBBS::OnOpenBBS(wxCommandEvent& event) {
538 wxFileDialog * openFileDialog = new wxFileDialog(this, wxT("Open BBS"),
539 wxEmptyString, wxT("NewBBS"), wxT("*.bbs"), wxOPEN);
540 if (openFileDialog->ShowModal() == wxID_OK) {
541 wxString fileName = openFileDialog->GetPath();
543 _tabsMgr->addNewTab(openFileDialog->GetFilename());
545 bbtk::InterpreterBBS::Pointer I = bbtk::InterpreterBBS::New(
546 this->_tabsMgr->getActualTabPanel()->getSceneManager(),
547 _pkgBrowser->GetFactory());
549 // We tell the interpreter to throw exceptions on error
551 // Interpret the file supposed to define a box called 'Processing'
552 I->InterpretFile((const char*) (fileName.mb_str()));
554 refreshGUIControls();
557 void wxGUIEditorGraphicBBS::SaveActualBBS(std::string filename) {
560 //EED file.open(fileName.c_str());
561 file.open(filename.c_str());
562 std::string content = "";
563 // writing file header
564 content += "# ----------------------------------\n";
565 content += "# - BBTKGEditor v 1.2 BBS BlackBox Script\n";
569 content += "# ----------------------------------\n";
571 content += _tabsMgr->getActualDiagramBBS();
576 void wxGUIEditorGraphicBBS::OnSaveActualBBS(wxCommandEvent& event) {
577 wxFileDialog * saveFileDialog = new wxFileDialog(this,
578 wxT("Save actual BBS"), wxEmptyString, wxT("NewBBS"),
579 wxT("*.bbs"), wxSAVE | wxOVERWRITE_PROMPT);
580 if (saveFileDialog->ShowModal() == wxID_OK) {
581 wxString fileName = saveFileDialog->GetPath();
582 std::string filename = (const char*) (fileName.mb_str());
583 filename=CheckExtension (filename, ".bbs");
584 SaveActualBBS(filename);
589 void wxGUIEditorGraphicBBS::AskComplexBoxConfiguration() {
590 std::string cbName = _tabsMgr->GetCbName();
591 std::string paName = _tabsMgr->GetCbPackageName();
593 wxTextEntryDialog *cbNameDialog = new wxTextEntryDialog(this,
594 wxT("Complex Box name"));
595 wxTextEntryDialog *paNameDialog = new wxTextEntryDialog(this,
596 wxT("Package name"));
598 cbNameDialog->SetValue(wxString(cbName.c_str(), wxConvUTF8));
599 paNameDialog->SetValue(wxString(paName.c_str(), wxConvUTF8));
601 if (cbNameDialog->ShowModal() == wxID_OK) {
602 wxString complexboxname = cbNameDialog->GetValue();
603 cbName = (const char*) (complexboxname.mb_str());
606 if (paNameDialog->ShowModal() == wxID_OK) {
607 wxString packagename = paNameDialog->GetValue();
608 paName = (const char*) (packagename.mb_str());
611 _tabsMgr->SetCbName(cbName);
612 _tabsMgr->SetCbPackageName(paName);
615 //=========================================================================
617 void wxGUIEditorGraphicBBS::SaveActualComplexBox(std::string filename) {
619 file.open(filename.c_str());
621 std::string content = "";
623 // writing file header
624 content += "# ----------------------------------\n";
625 content += "# - BBTKGEditor v 1.2 BBS BlackBox Script (Complex Box)\n";
629 content += "# ----------------------------------\n";
631 content += _tabsMgr->getActualComplexBoxBBS();
636 //=========================================================================
638 void wxGUIEditorGraphicBBS::OnSaveActualComplexBox(wxCommandEvent& event) {
639 wxFileDialog * saveFileDialog = new wxFileDialog(this,
640 wxT("Save Complex Box BBS"), wxEmptyString,
641 _T("ComplexBoxName"), wxT("*.bbs"), wxSAVE
642 | wxOVERWRITE_PROMPT);
643 if (saveFileDialog->ShowModal() == wxID_OK) {
644 wxString fileName = saveFileDialog->GetPath();
645 std::string filename = (const char*) (fileName.mb_str());
646 filename=CheckExtension (filename, ".bbs");
647 SaveActualComplexBox(filename);
651 //=========================================================================
652 void wxGUIEditorGraphicBBS::SaveActualDiagram(std::string filename) {
654 file.open(filename.c_str());
656 std::string content = "";
658 // writing file header
659 content += "# ----------------------------------\n";
660 content += "# - BBTKGEditor v 1.2 BBG BlackBox Diagram file\n";
666 content += "# ----------------------------------\n";
668 content += "APP_START\n";
669 _tabsMgr->saveActualDiagram(content, filename); //DFCH
670 content += "APP_END\n";
675 //=========================================================================
676 void wxGUIEditorGraphicBBS::SaveTempActualDiagram()
678 std::string name = _tabsMgr->GetNameTabPanel();
679 if(name[name.length() - 1] != '*')
681 _tabsMgr->SetNameTabPanel(wxString (name.c_str(), wxConvUTF8));
682 _tabsMgr->saveTempActualDiagram();
685 //=========================================================================
687 //The following method allows to save the current diagram asking the filename
689 void wxGUIEditorGraphicBBS::SaveCurrentDiagramAs() {
690 wxFileDialog * saveFileDialog = new wxFileDialog(this,
691 wxT("Save current diagram"), wxEmptyString, wxT("NewDiagram"),
692 wxT("*.bbg"), wxSAVE | wxOVERWRITE_PROMPT);
693 if (saveFileDialog->ShowModal() == wxID_OK) {
694 //_tabsMgr->SetNameTabPanel(saveFileDialog->GetFilename());
695 wxString pathfileName = saveFileDialog->GetPath();
696 std::string pathfilename = (const char*) (pathfileName.mb_str());
697 pathfilename=CheckExtension (pathfilename, ".bbg");
699 //modify the tab name accordingly
700 wxString fileName = saveFileDialog->GetFilename();
701 std::string filename = (const char*) (fileName.mb_str());
702 filename=CheckExtension (filename, ".bbg");
703 _tabsMgr->SetNameTabPanel( wxString (filename.c_str(), wxConvUTF8) );
705 std::string pathfilenamebbs = pathfilename;
706 pathfilenamebbs[pathfilenamebbs.length() - 1] = 's';
707 if (_tabsMgr->isActualDiagramComplexBox() == false) {
708 SaveActualDiagram(pathfilename);
709 SaveActualBBS(pathfilenamebbs);
711 AskComplexBoxConfiguration();
712 SaveActualDiagram(pathfilename);
713 SaveActualComplexBox(pathfilenamebbs);
714 } //if isActualDiagramComplexBox
715 } // if saveFileDialog
717 //=========================================================================
719 void wxGUIEditorGraphicBBS::OnSaveActualDiagram(wxCommandEvent& event) {
720 std::string pathfilename = _tabsMgr->GetCurrentTabPanelPath();
721 if (pathfilename.empty()) {
722 SaveCurrentDiagramAs();
724 std::string pathfilenamebbs = pathfilename;
725 pathfilenamebbs[pathfilenamebbs.length() - 1] = 's';
727 if (_tabsMgr->isActualDiagramComplexBox() == false) {
728 SaveActualDiagram(pathfilename);
729 SaveActualBBS(pathfilenamebbs);
731 AskComplexBoxConfiguration();
732 SaveActualDiagram(pathfilename);
733 SaveActualComplexBox(pathfilenamebbs);
734 } //if isActualDiagramComplexBox
737 //=========================================================================
739 void wxGUIEditorGraphicBBS::OnSaveAsActualDiagram(wxCommandEvent& event) {
740 SaveCurrentDiagramAs();
742 //=========================================================================
744 void wxGUIEditorGraphicBBS::refreshGUIControls() {
745 wxToolBar* toolbar = GetToolBar();
746 if (_tabsMgr->isActualDiagramComplexBox()) {
747 toolbar->ToggleTool(ID_BTNCOMPLEXBOX, true);
748 toolbar->EnableTool(ID_ADDCOMPLEXBOXINPUT, true);
749 toolbar->EnableTool(ID_ADDCOMPLEXBOXOUTPUT, true);
751 GetMenuBar()->GetMenu(0)->Enable(ID_SAVE_AS_COMPLEXBOX, true);
752 GetMenuBar()->GetMenu(0)->Enable(ID_SAVE_AS_BBS, false);
754 toolbar->ToggleTool(ID_BTNCOMPLEXBOX, false);
755 toolbar->EnableTool(ID_ADDCOMPLEXBOXINPUT, false);
756 toolbar->EnableTool(ID_ADDCOMPLEXBOXOUTPUT, false);
758 GetMenuBar()->GetMenu(0)->Enable(ID_SAVE_AS_COMPLEXBOX, false);
759 GetMenuBar()->GetMenu(0)->Enable(ID_SAVE_AS_BBS, true);
762 GetToolBar()->EnableTool(ID_UNDO,_tabsMgr->getUndoState());
763 GetToolBar()->EnableTool(ID_REDO,_tabsMgr->getRedoState());
765 if (_tabsMgr->getNumActualSelectedObjects() > 0) {
766 GetMenuBar()->GetMenu(1)->Enable(ID_COPY_TO_COMPLEXDIAGRAM, true);
768 ///TODO Fix the possibility to say from the SceneManager to the GUI to refresh the options
769 GetMenuBar()->GetMenu(1)->Enable(ID_COPY_TO_COMPLEXDIAGRAM, true);
774 //=========================================================================
776 void wxGUIEditorGraphicBBS::OnDeleteAllBoxesActualDiagram(wxCommandEvent& event) {
777 wxMessageDialog *dial = new wxMessageDialog(NULL,
778 wxT("Are you sure to delete all boxes of the diagram?"),
779 wxT("Delete all boxes"), wxYES_NO | wxNO_DEFAULT
781 if (dial->ShowModal() == wxID_YES) {
782 _tabsMgr->deleteAllBoxesActualDiagram();
786 //=========================================================================
788 void wxGUIEditorGraphicBBS::OnCenterViewActualDiagram(wxCommandEvent& event) {
789 _tabsMgr->centerViewActualDiagram();
792 //=========================================================================
794 void wxGUIEditorGraphicBBS::OnOpenDiagram(wxCommandEvent& event) {
795 wxFileDialog * openFileDialog = new wxFileDialog(this, wxT("Open diagram"),
796 wxEmptyString, wxT(""), wxT("*.bbg"), wxOPEN | wxFILE_MUST_EXIST);
797 if (openFileDialog->ShowModal() == wxID_OK) {
798 wxString fileName = openFileDialog->GetPath();
799 ifstream inputStream;
800 std::string fName = (const char*) (fileName.mb_str());
802 inputStream.open(fName.c_str());
803 assert(inputStream.good()); // fails
804 _tabsMgr->addNewTab(openFileDialog->GetFilename());
805 _tabsMgr->loadDiagram(inputStream, fName);
809 refreshGUIControls();
812 //=========================================================================
815 void wxGUIEditorGraphicBBS::OnClickBtnBox(wxCommandEvent& event) {
816 BlackBoxDescriptor *bbDes = _pkgBrowser->GetActualSelected();
818 std::string typeName = bbDes->GetTypeName();
819 std::string packageName = bbDes->GetPackage()->GetName();
821 wxGEditorTabPanel *pnl = this->_tabsMgr->getActualTabPanel();
823 // save empty state!!
824 /* if (_tabsMgr->getNumActualSelectedObjects() == 0)
826 SaveTempActualDiagram();
830 wxVtkSceneManager *scn = pnl->getSceneManager();
831 scn->createGBlackBox(50, 50, packageName, typeName);
834 if (GetToolBar()->GetToolEnabled(ID_UNDO) == false)
835 GetToolBar()->EnableTool(ID_UNDO,true);
836 SaveTempActualDiagram();
841 //=========================================================================
843 void wxGUIEditorGraphicBBS::OnClickBtnExecutableBox(wxCommandEvent& event) {
845 wxGEditorTabPanel *pnl = this->_tabsMgr->getActualTabPanel();
848 wxVtkSceneManager *scn = pnl->getSceneManager();
849 if( scn->MakeBoxExecutable() )
850 std::cout<<"DFCH: wxGUIEditorGraphicBBS::OnClickBtnExecutableBox...successful"<<std::endl;
852 std::cout<<"DFCH: wxGUIEditorGraphicBBS::OnClickBtnExecutableBox...Error!!"<<std::endl;
858 //=========================================================================
860 void wxGUIEditorGraphicBBS::OnClickBtnComplexBox(wxCommandEvent& event) {
861 wxToolBar* toolbar = GetToolBar();
862 bool temp = toolbar->GetToolState(ID_BTNCOMPLEXBOX);
864 _tabsMgr->setActualDiagramComplexBox(true);
866 _tabsMgr->setActualDiagramComplexBox(false);
868 refreshGUIControls();
871 //=========================================================================
873 void wxGUIEditorGraphicBBS::OnAddComplexBoxInput(wxCommandEvent& event) {
874 wxTextEntryDialog *nameDialog = new wxTextEntryDialog(this,
875 wxT("Name of input port"));
876 if (nameDialog->ShowModal() == wxID_OK) {
877 wxString fileName = nameDialog->GetValue();
878 if (!fileName.IsEmpty()) {
879 std::string portName = (const char*) (fileName.mb_str());
880 _tabsMgr->addActualDiagramComplexInputPort(portName);
885 //=========================================================================
887 void wxGUIEditorGraphicBBS::OnAddComplexBoxOutput(wxCommandEvent& event) {
888 wxTextEntryDialog *nameDialog = new wxTextEntryDialog(this,
889 wxT("Name of output port"));
890 if (nameDialog->ShowModal() == wxID_OK) {
891 wxString fileName = nameDialog->GetValue();
892 if (!fileName.IsEmpty()) {
893 std::string portName = (const char*) (fileName.mb_str());
894 _tabsMgr->addActualDiagramComplexOutputPort(portName);
899 //=========================================================================
901 void wxGUIEditorGraphicBBS::OnCopySelectedToComplexDiagram(
902 wxCommandEvent& event) {
903 _tabsMgr->copySelectedBBoxesToComplexDiagram();
906 void wxGUIEditorGraphicBBS::OnHelpBBeditor(wxCommandEvent& event) {
907 printf("wxGUIEditorGraphicBBS::OnHelpBBeditor ....not implemented..\n");
910 //=========================================================================
911 void wxGUIEditorGraphicBBS::OnCreatePackage(wxCommandEvent& event) {
913 bbtkSystemTools::CreatePackage();
916 //=========================================================================
917 void wxGUIEditorGraphicBBS::OnCreateBlackBox(wxCommandEvent& event) {
918 bbtkSystemTools::CreateBlackBox();
920 //=========================================================================
921 void wxGUIEditorGraphicBBS::OnPlugPackage(wxCommandEvent& event) {
922 printf("EED wxGUIEditorGraphicBBS::OnPlugPackage ... not implemented ..\n");
924 //=========================================================================
925 void wxGUIEditorGraphicBBS::OnEditConfig(wxCommandEvent& event) {
926 printf("EED wxGUIEditorGraphicBBS::OnEditConfig ... not implemented ..\n");
928 //=========================================================================
930 void wxGUIEditorGraphicBBS::OnShowHTMLDoc(wxCommandEvent& event) {
932 if (_helpHtmlBrowser != NULL){
933 _frameAUIMgr->DetachPane(_helpHtmlBrowser);
934 _helpHtmlBrowser->Destroy();
936 initHelpHTMLBrowser();
937 _frameAUIMgr->AddPane(_helpHtmlBrowser, wxAuiPaneInfo().Right().MinSize(200, 200));
938 _frameAUIMgr->Update();
939 refreshGUIControls();
943 //=========================================================================
944 void wxGUIEditorGraphicBBS::OnCreateIndex(wxCommandEvent& event) {
945 printf("EED wxGUIEditorGraphicBBS::OnCreateIndex ... not implemented ..\n");
948 //=========================================================================
950 void wxGUIEditorGraphicBBS::OnExit(wxCommandEvent& event) {
956 //=========================================================================
958 } // EO namespace bbtk