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"));
213 fileMenu->Append(ID_SAVE_AS_BBS, _T("Save BBS"), _T("Save BBS"));
214 fileMenu->Append(ID_SAVE_AS_COMPLEXBOX, _T("Save complex box"),
215 _T("Save complex box"));
216 fileMenu->Append(wxID_EXIT, _T("E&xit"), _T("Exit"));
218 Connect(ID_NEW, wxEVT_COMMAND_MENU_SELECTED,
219 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnCreateNewTab));
220 Connect(ID_SAVE_DIAGRAM, wxEVT_COMMAND_MENU_SELECTED,
221 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnSaveActualDiagram)); //DFCH
222 Connect(ID_SAVE_AS_DIAGRAM, wxEVT_COMMAND_MENU_SELECTED,
223 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnSaveAsActualDiagram));
224 Connect(ID_OPEN_BBS, wxEVT_COMMAND_MENU_SELECTED,
225 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnOpenBBS));
226 Connect(ID_SAVE_AS_BBS, wxEVT_COMMAND_MENU_SELECTED,
227 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnSaveActualBBS));
229 ID_SAVE_AS_COMPLEXBOX,
230 wxEVT_COMMAND_MENU_SELECTED,
231 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnSaveActualComplexBox));
232 Connect(wxID_EXIT, wxEVT_COMMAND_MENU_SELECTED,
233 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnExit));
235 // Create Help menu and its items
236 wxMenu *editMenu = new wxMenu;
237 editMenu->Append(ID_COPY_TO_COMPLEXDIAGRAM,
238 _T("Copy selected to complex box"),
239 _T("Creates a new complex box diagram with selected boxes"));
242 ID_COPY_TO_COMPLEXDIAGRAM,
243 wxEVT_COMMAND_MENU_SELECTED,
244 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnCopySelectedToComplexDiagram));
246 // Create Help menu and its items
247 wxMenu *helpMenu = new wxMenu;
248 helpMenu->Append(wxID_ABOUT, _T("&About..."), _T("About"));
249 helpMenu->Append(ID_HELP_BBEDITOR, _T("&Help..."), _T("Help"));
250 Connect(ID_HELP_BBEDITOR, wxEVT_COMMAND_MENU_SELECTED,
251 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnHelpBBeditor));
254 wxMenu *menuTools = new wxMenu;
255 menuTools->Append(ID_bbEditor_Tool_Menu_CreatePackage,
256 _T("Create &package") );
257 menuTools->Append(ID_bbEditor_Tool_Menu_CreateBlackBox,
258 _T("Create &blackbox") );
259 menuTools->Append(ID_bbEditor_Tool_Menu_PlugPackage, _T("Plug package") );
260 menuTools->Append(ID_bbEditor_Tool_Menu_EditConfig, _T("&Edit bbtk config") );
261 menuTools->Append(ID_bbEditor_Tool_Menu_ShowHTMLDoc,
262 _T("Show &HTML documentation") );
263 menuTools->Append(ID_bbEditor_Tool_Menu_CreateIndex, _T("&Generate index") );
265 Connect(ID_bbEditor_Tool_Menu_CreatePackage, wxEVT_COMMAND_MENU_SELECTED,
266 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnCreatePackage));
267 Connect(ID_bbEditor_Tool_Menu_CreateBlackBox, wxEVT_COMMAND_MENU_SELECTED,
268 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnCreateBlackBox));
269 Connect(ID_bbEditor_Tool_Menu_PlugPackage, wxEVT_COMMAND_MENU_SELECTED,
270 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnPlugPackage));
271 Connect(ID_bbEditor_Tool_Menu_EditConfig, wxEVT_COMMAND_MENU_SELECTED,
272 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnEditConfig));
273 Connect(ID_bbEditor_Tool_Menu_ShowHTMLDoc, wxEVT_COMMAND_MENU_SELECTED,
274 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnShowHTMLDoc));
275 Connect(ID_bbEditor_Tool_Menu_CreateIndex, wxEVT_COMMAND_MENU_SELECTED,
276 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnCreateIndex));
278 // Append the created menu to the menu bar
279 wxMenuBar *menuBar = new wxMenuBar();
280 menuBar->Append(fileMenu, _T("&File") );
281 menuBar->Append(editMenu, _T("&Edit") );
282 menuBar->Append(menuTools, _T("&Tool") );
283 menuBar->Append(helpMenu, _T("&Help") );
285 // Attach this menu bar to the frame
289 //=========================================================================
290 void wxGUIEditorGraphicBBS::initTabPanelsManager() {
291 _notebook = new wxAuiNotebook(this, wxID_NOTEBOOK, wxDefaultPosition,
292 wxDefaultSize, wxAUI_NB_TOP | wxAUI_NB_TAB_MOVE
293 | wxAUI_NB_CLOSE_ON_ACTIVE_TAB | wxAUI_NB_TAB_FIXED_WIDTH
294 | wxAUI_NB_WINDOWLIST_BUTTON);
295 _tabsMgr = new wxTabPanelsManager(this);
296 _frameAUIMgr->AddPane(_notebook, wxAuiPaneInfo().CenterPane());
300 //=========================================================================
301 void wxGUIEditorGraphicBBS::initPackageBrowser() {
302 _pkgBrowser = new WxGUIPackageBrowser2(this);
303 _pkgBrowser->IncludeAll();
304 _frameAUIMgr->AddPane(_pkgBrowser,
305 wxAuiPaneInfo().Left().MinSize(200, 200).CloseButton(false));
308 //================================================================
310 void wxGUIEditorGraphicBBS::DoRegeneratePackageDoc(const std::string& pack) {
311 std::string mess("Regenerating doc for package '");
315 mess = "Regenerating doc for all packages";
318 mess += " ... please wait";
320 SetStatusText(std2wx(mess));
328 command += ConfigurationFile::GetInstance().Get_bin_path();
329 command += ConfigurationFile::GetInstance().Get_file_separator();
330 command += "bbRegeneratePackageDoc";
335 command += " " + pack + " -q";
336 bbtkMessage("debug",1,"Executing system command '"<<command<<"'"<<std::endl);
338 if (!system(command.c_str())) {
339 SetStatusText(_T("Done !"));
341 wxMessageBox(_T("Done !"),_T("Regenerate package '")
342 +std2wx(pack)+_T("' doc"),
343 wxOK | wxICON_INFORMATION);
346 SetStatusText(_T("Done !"));
347 wxString err(_T("An error occured while running '"));
348 err += bbtk::std2wx(command) + _T("'");
349 wxMessageBox(err, _T("Regenerate package doc"), wxOK | wxICON_ERROR);
353 //================================================================
354 void wxGUIEditorGraphicBBS::DoRegenerateBoxesLists() {
355 SetStatusText(_T("Regenerating boxes lists ... please wait"));
362 command += ConfigurationFile::GetInstance().Get_bin_path();
363 command += ConfigurationFile::GetInstance().Get_file_separator();
364 command += "bbRegenerateBoxesLists";
371 bbtkMessage("debug",1,"Executing system command '"<<command<<"'"<<std::endl);
373 if (!system(command.c_str())) {
374 SetStatusText(_T("Done !"));
376 wxMessageBox(_T("Done !"),_T("Regenerate boxes lists"),
377 wxOK | wxICON_INFORMATION);
380 SetStatusText(_T("Done !"));
381 wxString err(_T("An error occured while running '"));
382 err += bbtk::std2wx(command) + _T("'");
383 wxMessageBox(err, _T("Regenerate boxes lists"), wxOK | wxICON_ERROR);
387 //================================================================
388 void wxGUIEditorGraphicBBS::RegenerateAll() {
389 DoRegeneratePackageDoc("-a");
390 DoRegenerateBoxesLists();
393 //================================================================
395 wxAuiNotebook* wxGUIEditorGraphicBBS::getAuiNotebook() {
399 //================================================================
401 void wxGUIEditorGraphicBBS::displayBlackBoxInfo(std::string packageName,
402 std::string boxName) {
403 if (_actualPkgBrowserPkgName != packageName || _actualPkgBrowserBoxName
405 _actualPkgBrowserPkgName = packageName;
406 _actualPkgBrowserBoxName = boxName;
408 BlackBoxDescriptor::Pointer descriptor =
409 GObjectsMVCFactory::getInstance()->getBlackBoxDescriptor(
410 packageName, boxName);
411 _pkgBrowser->WxGUIBlackBoxListUserOnSelected(descriptor.get());
415 //=========================================================================
417 void wxGUIEditorGraphicBBS::editBlackBox(GBlackBoxModel *bbmodel) {
418 wxBlackBoxEditionDialog* dialog =
419 new wxBlackBoxEditionDialog(this, bbmodel);
423 //=========================================================================
425 void wxGUIEditorGraphicBBS::updateStatusBar(std::string textStatus) {
426 SetStatusText(crea::std2wx(textStatus));
429 //=========================================================================
431 void wxGUIEditorGraphicBBS::executeScript(std::string script) {
432 std::string separator =
433 ConfigurationFile::GetInstance().Get_file_separator();
434 std::string dir = ConfigurationFile::GetInstance().Get_default_temp_dir();
435 std::string filename = dir + separator + "tmp_bbtk.bbs";
438 tempFile.open(filename.c_str());
442 std::string command = "";
445 command += "start /b ";
448 // command += "\""+ crea::System::GetExecutablePath();
450 // command += separator + "../../../bbi.app/Contents/MacOS";
454 command += "\"" + filename + "\"";
460 printf("RaC wxGUIEditorGraphicBBS::executeScript %s \n", command.c_str());
461 system(command.c_str());
464 //=========================================================================
465 std::string wxGUIEditorGraphicBBS::CheckExtension(std::string filename, std::string extension) {
466 if(filename.size() > extension.size() ){
467 if( (filename.compare(filename.size()-extension.size(), extension.size(),extension)) !=0 ){
468 filename.append(extension);
471 filename.append(extension);
475 //=========================================================================
477 //=========================================================================
479 void wxGUIEditorGraphicBBS::OnCreateNewTab(wxCommandEvent& event) {
480 _tabsMgr->addNewTab();
481 refreshGUIControls();
484 void wxGUIEditorGraphicBBS::OnUndo(wxCommandEvent& event) {
485 unsigned short disable;
486 _tabsMgr->loadTempDiagram(0);
487 disable = _tabsMgr->getUndoState();
490 std::string name = _tabsMgr->GetNameTabPanel();
491 if(name[name.length() - 1] == '*')
493 name =name.substr(0,name.length()-1);
495 _tabsMgr->SetNameTabPanel(wxString (name.c_str(), wxConvUTF8));
498 GetToolBar()->EnableTool(ID_UNDO,disable);
499 GetToolBar()->EnableTool(ID_REDO,_tabsMgr->getRedoState());
500 refreshGUIControls();
503 void wxGUIEditorGraphicBBS::OnRedo(wxCommandEvent& event) {
504 unsigned short disable;
505 _tabsMgr->loadTempDiagram(1);
506 GetToolBar()->EnableTool(ID_UNDO,_tabsMgr->getUndoState());
507 GetToolBar()->EnableTool(ID_REDO,_tabsMgr->getRedoState());
508 refreshGUIControls();
511 void wxGUIEditorGraphicBBS::OnChangeName(wxCommandEvent& event){
513 //=========================================================================
515 void wxGUIEditorGraphicBBS::OnExecuteActualDiagram(wxCommandEvent& event) {
516 std::string script1 = _tabsMgr->getActualDiagramBBS(true);
517 cout << endl << "RaC wxGUIEditorGraphicBBS::executeActualDiagram SCRIPT"
519 cout << script1 << endl;
521 std::string script2 = _tabsMgr->getActualDiagramBBS(false);
522 executeScript(script2);
525 //=========================================================================
527 //=========================================================================
528 void wxGUIEditorGraphicBBS::OnOpenBBS(wxCommandEvent& event) {
529 wxFileDialog * openFileDialog = new wxFileDialog(this, wxT("Open BBS"),
530 wxEmptyString, wxT("NewBBS"), wxT("*.bbs"), wxOPEN);
531 if (openFileDialog->ShowModal() == wxID_OK) {
532 wxString fileName = openFileDialog->GetPath();
534 _tabsMgr->addNewTab(openFileDialog->GetFilename());
536 bbtk::InterpreterBBS::Pointer I = bbtk::InterpreterBBS::New(
537 this->_tabsMgr->getActualTabPanel()->getSceneManager(),
538 _pkgBrowser->GetFactory());
540 // We tell the interpreter to throw exceptions on error
542 // Interpret the file supposed to define a box called 'Processing'
543 I->InterpretFile((const char*) (fileName.mb_str()));
545 refreshGUIControls();
548 void wxGUIEditorGraphicBBS::SaveActualBBS(std::string filename) {
551 //EED file.open(fileName.c_str());
552 file.open(filename.c_str());
553 std::string content = "";
554 // writing file header
555 content += "# ----------------------------------\n";
556 content += "# - BBTKGEditor v 1.2 BBS BlackBox Script\n";
560 content += "# ----------------------------------\n";
562 content += _tabsMgr->getActualDiagramBBS();
567 void wxGUIEditorGraphicBBS::OnSaveActualBBS(wxCommandEvent& event) {
568 wxFileDialog * saveFileDialog = new wxFileDialog(this,
569 wxT("Save actual BBS"), wxEmptyString, wxT("NewBBS"),
570 wxT("*.bbs"), wxSAVE | wxOVERWRITE_PROMPT);
571 if (saveFileDialog->ShowModal() == wxID_OK) {
572 wxString fileName = saveFileDialog->GetPath();
573 std::string filename = (const char*) (fileName.mb_str());
574 filename=CheckExtension (filename, ".bbs");
575 SaveActualBBS(filename);
580 void wxGUIEditorGraphicBBS::AskComplexBoxConfiguration() {
581 std::string cbName = _tabsMgr->GetCbName();
582 std::string paName = _tabsMgr->GetCbPackageName();
584 wxTextEntryDialog *cbNameDialog = new wxTextEntryDialog(this,
585 wxT("Complex Box name"));
586 wxTextEntryDialog *paNameDialog = new wxTextEntryDialog(this,
587 wxT("Package name"));
589 cbNameDialog->SetValue(wxString(cbName.c_str(), wxConvUTF8));
590 paNameDialog->SetValue(wxString(paName.c_str(), wxConvUTF8));
592 if (cbNameDialog->ShowModal() == wxID_OK) {
593 wxString complexboxname = cbNameDialog->GetValue();
594 cbName = (const char*) (complexboxname.mb_str());
597 if (paNameDialog->ShowModal() == wxID_OK) {
598 wxString packagename = paNameDialog->GetValue();
599 paName = (const char*) (packagename.mb_str());
602 _tabsMgr->SetCbName(cbName);
603 _tabsMgr->SetCbPackageName(paName);
606 //=========================================================================
608 void wxGUIEditorGraphicBBS::SaveActualComplexBox(std::string filename) {
610 file.open(filename.c_str());
612 std::string content = "";
614 // writing file header
615 content += "# ----------------------------------\n";
616 content += "# - BBTKGEditor v 1.2 BBS BlackBox Script (Complex Box)\n";
620 content += "# ----------------------------------\n";
622 content += _tabsMgr->getActualComplexBoxBBS();
627 //=========================================================================
629 void wxGUIEditorGraphicBBS::OnSaveActualComplexBox(wxCommandEvent& event) {
630 wxFileDialog * saveFileDialog = new wxFileDialog(this,
631 wxT("Save Complex Box BBS"), wxEmptyString,
632 _T("ComplexBoxName"), wxT("*.bbs"), wxSAVE
633 | wxOVERWRITE_PROMPT);
634 if (saveFileDialog->ShowModal() == wxID_OK) {
635 wxString fileName = saveFileDialog->GetPath();
636 std::string filename = (const char*) (fileName.mb_str());
637 filename=CheckExtension (filename, ".bbs");
638 SaveActualComplexBox(filename);
642 //=========================================================================
643 void wxGUIEditorGraphicBBS::SaveActualDiagram(std::string filename) {
645 file.open(filename.c_str());
647 std::string content = "";
649 // writing file header
650 content += "# ----------------------------------\n";
651 content += "# - BBTKGEditor v 1.2 BBG BlackBox Diagram file\n";
657 content += "# ----------------------------------\n";
659 content += "APP_START\n";
660 _tabsMgr->saveActualDiagram(content, filename); //DFCH
661 content += "APP_END\n";
666 //=========================================================================
667 void wxGUIEditorGraphicBBS::SaveTempActualDiagram()
669 std::string name = _tabsMgr->GetNameTabPanel();
670 if(name[name.length() - 1] != '*')
672 _tabsMgr->SetNameTabPanel(wxString (name.c_str(), wxConvUTF8));
673 _tabsMgr->saveTempActualDiagram();
676 //=========================================================================
678 //The following method allows to save the current diagram asking the filename
680 void wxGUIEditorGraphicBBS::SaveCurrentDiagramAs() {
681 wxFileDialog * saveFileDialog = new wxFileDialog(this,
682 wxT("Save current diagram"), wxEmptyString, wxT("NewDiagram"),
683 wxT("*.bbg"), wxSAVE | wxOVERWRITE_PROMPT);
684 if (saveFileDialog->ShowModal() == wxID_OK) {
685 //_tabsMgr->SetNameTabPanel(saveFileDialog->GetFilename());
686 wxString pathfileName = saveFileDialog->GetPath();
687 std::string pathfilename = (const char*) (pathfileName.mb_str());
688 pathfilename=CheckExtension (pathfilename, ".bbg");
690 //modify the tab name accordingly
691 wxString fileName = saveFileDialog->GetFilename();
692 std::string filename = (const char*) (fileName.mb_str());
693 filename=CheckExtension (filename, ".bbg");
694 _tabsMgr->SetNameTabPanel( wxString (filename.c_str(), wxConvUTF8) );
696 std::string pathfilenamebbs = pathfilename;
697 pathfilenamebbs[pathfilenamebbs.length() - 1] = 's';
698 if (_tabsMgr->isActualDiagramComplexBox() == false) {
699 SaveActualDiagram(pathfilename);
700 SaveActualBBS(pathfilenamebbs);
702 AskComplexBoxConfiguration();
703 SaveActualDiagram(pathfilename);
704 SaveActualComplexBox(pathfilenamebbs);
705 } //if isActualDiagramComplexBox
706 } // if saveFileDialog
708 //=========================================================================
710 void wxGUIEditorGraphicBBS::OnSaveActualDiagram(wxCommandEvent& event) {
711 std::string pathfilename = _tabsMgr->GetCurrentTabPanelPath();
712 if (pathfilename.empty()) {
713 SaveCurrentDiagramAs();
715 std::string pathfilenamebbs = pathfilename;
716 pathfilenamebbs[pathfilenamebbs.length() - 1] = 's';
718 if (_tabsMgr->isActualDiagramComplexBox() == false) {
719 SaveActualDiagram(pathfilename);
720 SaveActualBBS(pathfilenamebbs);
722 AskComplexBoxConfiguration();
723 SaveActualDiagram(pathfilename);
724 SaveActualComplexBox(pathfilenamebbs);
725 } //if isActualDiagramComplexBox
728 //=========================================================================
730 void wxGUIEditorGraphicBBS::OnSaveAsActualDiagram(wxCommandEvent& event) {
731 SaveCurrentDiagramAs();
733 //=========================================================================
735 void wxGUIEditorGraphicBBS::refreshGUIControls() {
736 wxToolBar* toolbar = GetToolBar();
737 if (_tabsMgr->isActualDiagramComplexBox()) {
738 toolbar->ToggleTool(ID_BTNCOMPLEXBOX, true);
739 toolbar->EnableTool(ID_ADDCOMPLEXBOXINPUT, true);
740 toolbar->EnableTool(ID_ADDCOMPLEXBOXOUTPUT, true);
742 GetMenuBar()->GetMenu(0)->Enable(ID_SAVE_AS_COMPLEXBOX, true);
743 GetMenuBar()->GetMenu(0)->Enable(ID_SAVE_AS_BBS, false);
745 toolbar->ToggleTool(ID_BTNCOMPLEXBOX, false);
746 toolbar->EnableTool(ID_ADDCOMPLEXBOXINPUT, false);
747 toolbar->EnableTool(ID_ADDCOMPLEXBOXOUTPUT, false);
749 GetMenuBar()->GetMenu(0)->Enable(ID_SAVE_AS_COMPLEXBOX, false);
750 GetMenuBar()->GetMenu(0)->Enable(ID_SAVE_AS_BBS, true);
753 GetToolBar()->EnableTool(ID_UNDO,_tabsMgr->getUndoState());
754 GetToolBar()->EnableTool(ID_REDO,_tabsMgr->getRedoState());
756 if (_tabsMgr->getNumActualSelectedObjects() > 0) {
757 GetMenuBar()->GetMenu(1)->Enable(ID_COPY_TO_COMPLEXDIAGRAM, true);
759 ///TODO Fix the possibility to say from the SceneManager to the GUI to refresh the options
760 GetMenuBar()->GetMenu(1)->Enable(ID_COPY_TO_COMPLEXDIAGRAM, true);
765 //=========================================================================
767 void wxGUIEditorGraphicBBS::OnDeleteAllBoxesActualDiagram(wxCommandEvent& event) {
768 wxMessageDialog *dial = new wxMessageDialog(NULL,
769 wxT("Are you sure to delete all boxes of the diagram?"),
770 wxT("Delete all boxes"), wxYES_NO | wxNO_DEFAULT
772 if (dial->ShowModal() == wxID_YES) {
773 _tabsMgr->deleteAllBoxesActualDiagram();
777 //=========================================================================
779 void wxGUIEditorGraphicBBS::OnCenterViewActualDiagram(wxCommandEvent& event) {
780 _tabsMgr->centerViewActualDiagram();
783 //=========================================================================
785 void wxGUIEditorGraphicBBS::OnOpenDiagram(wxCommandEvent& event) {
786 wxFileDialog * openFileDialog = new wxFileDialog(this, wxT("Open diagram"),
787 wxEmptyString, wxT(""), wxT("*.bbg"), wxOPEN | wxFILE_MUST_EXIST);
788 if (openFileDialog->ShowModal() == wxID_OK) {
789 wxString fileName = openFileDialog->GetPath();
790 ifstream inputStream;
791 std::string fName = (const char*) (fileName.mb_str());
793 inputStream.open(fName.c_str());
794 assert(inputStream.good()); // fails
795 _tabsMgr->addNewTab(openFileDialog->GetFilename());
796 _tabsMgr->loadDiagram(inputStream, fName);
800 refreshGUIControls();
803 //=========================================================================
806 void wxGUIEditorGraphicBBS::OnClickBtnBox(wxCommandEvent& event) {
807 BlackBoxDescriptor *bbDes = _pkgBrowser->GetActualSelected();
809 std::string typeName = bbDes->GetTypeName();
810 std::string packageName = bbDes->GetPackage()->GetName();
812 wxGEditorTabPanel *pnl = this->_tabsMgr->getActualTabPanel();
814 // save empty state!!
815 /* if (_tabsMgr->getNumActualSelectedObjects() == 0)
817 SaveTempActualDiagram();
821 wxVtkSceneManager *scn = pnl->getSceneManager();
822 scn->createGBlackBox(50, 50, packageName, typeName);
825 if (GetToolBar()->GetToolEnabled(ID_UNDO) == false)
826 GetToolBar()->EnableTool(ID_UNDO,true);
827 SaveTempActualDiagram();
832 //=========================================================================
834 void wxGUIEditorGraphicBBS::OnClickBtnExecutableBox(wxCommandEvent& event) {
836 wxGEditorTabPanel *pnl = this->_tabsMgr->getActualTabPanel();
839 wxVtkSceneManager *scn = pnl->getSceneManager();
840 if( scn->MakeBoxExecutable() )
841 std::cout<<"DFCH: wxGUIEditorGraphicBBS::OnClickBtnExecutableBox...successful"<<std::endl;
843 std::cout<<"DFCH: wxGUIEditorGraphicBBS::OnClickBtnExecutableBox...Error!!"<<std::endl;
849 //=========================================================================
851 void wxGUIEditorGraphicBBS::OnClickBtnComplexBox(wxCommandEvent& event) {
852 wxToolBar* toolbar = GetToolBar();
853 bool temp = toolbar->GetToolState(ID_BTNCOMPLEXBOX);
855 _tabsMgr->setActualDiagramComplexBox(true);
857 _tabsMgr->setActualDiagramComplexBox(false);
859 refreshGUIControls();
862 //=========================================================================
864 void wxGUIEditorGraphicBBS::OnAddComplexBoxInput(wxCommandEvent& event) {
865 wxTextEntryDialog *nameDialog = new wxTextEntryDialog(this,
866 wxT("Name of input port"));
867 if (nameDialog->ShowModal() == wxID_OK) {
868 wxString fileName = nameDialog->GetValue();
869 if (!fileName.IsEmpty()) {
870 std::string portName = (const char*) (fileName.mb_str());
871 _tabsMgr->addActualDiagramComplexInputPort(portName);
876 //=========================================================================
878 void wxGUIEditorGraphicBBS::OnAddComplexBoxOutput(wxCommandEvent& event) {
879 wxTextEntryDialog *nameDialog = new wxTextEntryDialog(this,
880 wxT("Name of output port"));
881 if (nameDialog->ShowModal() == wxID_OK) {
882 wxString fileName = nameDialog->GetValue();
883 if (!fileName.IsEmpty()) {
884 std::string portName = (const char*) (fileName.mb_str());
885 _tabsMgr->addActualDiagramComplexOutputPort(portName);
890 //=========================================================================
892 void wxGUIEditorGraphicBBS::OnCopySelectedToComplexDiagram(
893 wxCommandEvent& event) {
894 _tabsMgr->copySelectedBBoxesToComplexDiagram();
897 void wxGUIEditorGraphicBBS::OnHelpBBeditor(wxCommandEvent& event) {
898 printf("wxGUIEditorGraphicBBS::OnHelpBBeditor ....not implemented..\n");
901 //=========================================================================
902 void wxGUIEditorGraphicBBS::OnCreatePackage(wxCommandEvent& event) {
904 bbtkSystemTools::CreatePackage();
907 //=========================================================================
908 void wxGUIEditorGraphicBBS::OnCreateBlackBox(wxCommandEvent& event) {
909 bbtkSystemTools::CreateBlackBox();
911 //=========================================================================
912 void wxGUIEditorGraphicBBS::OnPlugPackage(wxCommandEvent& event) {
913 printf("EED wxGUIEditorGraphicBBS::OnPlugPackage ... not implemented ..\n");
915 //=========================================================================
916 void wxGUIEditorGraphicBBS::OnEditConfig(wxCommandEvent& event) {
917 printf("EED wxGUIEditorGraphicBBS::OnEditConfig ... not implemented ..\n");
919 //=========================================================================
921 void wxGUIEditorGraphicBBS::OnShowHTMLDoc(wxCommandEvent& event) {
923 if (_helpHtmlBrowser != NULL){
924 _frameAUIMgr->DetachPane(_helpHtmlBrowser);
925 _helpHtmlBrowser->Destroy();
927 initHelpHTMLBrowser();
928 _frameAUIMgr->AddPane(_helpHtmlBrowser, wxAuiPaneInfo().Right().MinSize(200, 200));
929 _frameAUIMgr->Update();
930 refreshGUIControls();
934 //=========================================================================
935 void wxGUIEditorGraphicBBS::OnCreateIndex(wxCommandEvent& event) {
936 printf("EED wxGUIEditorGraphicBBS::OnCreateIndex ... not implemented ..\n");
939 //=========================================================================
941 void wxGUIEditorGraphicBBS::OnExit(wxCommandEvent& event) {
947 //=========================================================================
949 } // EO namespace bbtk