1 /*=========================================================================
7 =========================================================================*/
9 /* ---------------------------------------------------------------------
11 * Copyright (c) CREATIS-LRMN (Centre de Recherche en Imagerie Medicale)
12 * Authors : Eduardo Davila, Laurent Guigues, Jean-Pierre Roux
14 * This software is governed by the CeCILL-B license under French law and
15 * abiding by the rules of distribution of free software. You can use,
16 * modify and/ or redistribute the software under the terms of the CeCILL-B
17 * license as circulated by CEA, CNRS and INRIA at the following URL
18 * http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
19 * or in the file LICENSE.txt.
21 * As a counterpart to the access to the source code and rights to copy,
22 * modify and redistribute granted by the license, users are provided only
23 * with a limited warranty and the software's author, the holder of the
24 * economic rights, and the successive licensors have only limited
27 * The fact that you are presently reading this means that you have had
28 * knowledge of the CeCILL-B license and that you accept its terms.
29 * ------------------------------------------------------------------------ */
33 * \brief Class bbtk::WxInterfaceEditorGraphicBBS .
36 #include "bbtkwxGUIEditorGraphicBBS.h"
38 #include "creaSystem.h"
41 #include <InterpreterBBS.h>
45 //=========================================================================
46 wxGUIEditorGraphicBBS::wxGUIEditorGraphicBBS(wxFrame *parent) :
47 wxFrame(parent, -1, _T("bbtkGEditor"), wxDefaultPosition, wxSize(
50 _frameAUIMgr = new wxAuiManager(this);
52 /*std::string datadir( crea::System::GetExecutablePath() );
53 std::string datadir (".");
54 cout<<"RaC //------------------"<<endl;
55 cout<<"RaC //TODO wxGUIEditorGraphicBBS constructor.Initialize datadir with crea::System::GetExecutablePath() ."<<endl;
56 cout<<"RaC //------------------"<<endl;
58 #ifdef LINUX // assume this is OSX
59 datadir=datadir+"/../share/creaContours";
62 #ifdef MACOSX // assume this is OSX
63 datadir=datadir+"/../../../../share/creaContours";
70 initTabPanelsManager();
72 initHelpHTMLBrowser();
75 _frameAUIMgr->Update();
76 _actualPkgBrowserBoxName = "";
77 _actualPkgBrowserPkgName = "";
81 //=========================================================================
82 wxGUIEditorGraphicBBS::~wxGUIEditorGraphicBBS() {
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
158 Connect(ID_NEW, wxEVT_COMMAND_TOOL_CLICKED,
159 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnCreateNewTab));
160 Connect(ID_OPEN, wxEVT_COMMAND_TOOL_CLICKED,
161 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnOpenDiagram));
162 Connect(ID_SAVE_DIAGRAM, wxEVT_COMMAND_TOOL_CLICKED,
163 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnSaveActualDiagram)); //DFCH
164 Connect(ID_SAVE_AS_DIAGRAM, wxEVT_COMMAND_TOOL_CLICKED,
165 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnSaveAsActualDiagram)); //DFCH
168 wxEVT_COMMAND_TOOL_CLICKED,
169 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnExecuteActualDiagram));
172 wxEVT_COMMAND_TOOL_CLICKED,
173 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnDeleteAllBoxesActualDiagram));
176 wxEVT_COMMAND_TOOL_CLICKED,
177 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnCenterViewActualDiagram));
178 Connect(ID_BTNBOX, wxEVT_COMMAND_TOOL_CLICKED,
179 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnClickBtnBox));
182 wxEVT_COMMAND_TOOL_CLICKED,
183 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnClickBtnExecutableBox));
184 Connect(ID_BTNCOMPLEXBOX, wxEVT_COMMAND_TOOL_CLICKED,
185 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnClickBtnComplexBox));
186 Connect(ID_ADDCOMPLEXBOXINPUT, wxEVT_COMMAND_TOOL_CLICKED,
187 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnAddComplexBoxInput));
188 Connect(ID_ADDCOMPLEXBOXOUTPUT, wxEVT_COMMAND_TOOL_CLICKED,
189 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnAddComplexBoxOutput));
190 Connect(ID_UNDO,wxEVT_COMMAND_TOOL_CLICKED, wxCommandEventHandler(wxGUIEditorGraphicBBS::OnUndo));
191 Connect(ID_REDO,wxEVT_COMMAND_TOOL_CLICKED, wxCommandEventHandler(wxGUIEditorGraphicBBS::OnRedo));
194 //=========================================================================
195 void wxGUIEditorGraphicBBS::initHelpHTMLBrowser() {
196 //TO FIX THE PATH OF BBTK BIN IN ORDER TO USE REGENERATE EXECUTABLES
198 _helpHtmlBrowser = new WxGUIHtmlBrowser(this, wxSize(200, 0));
199 _frameAUIMgr->AddPane(_helpHtmlBrowser, wxAuiPaneInfo().Right().MinSize(
203 //=========================================================================
204 void wxGUIEditorGraphicBBS::initMenu() {
205 // Create File menu and its items
206 wxMenu *fileMenu = new wxMenu();
207 fileMenu->Append(ID_NEW, _T("New diagram"), _T("New"));
208 fileMenu->Append(ID_SAVE_DIAGRAM, _T("Save Diagram"), _T("Save Diagram")); //DFCH
209 fileMenu->Append(ID_SAVE_AS_DIAGRAM, _T("Save Diagram As"),
210 _T("Save Diagram As")); //DFCH
211 fileMenu->Append(ID_OPEN_BBS, _T("Open BBS"), _T("Open BBS"));
212 fileMenu->Append(ID_SAVE_AS_BBS, _T("Save BBS"), _T("Save BBS"));
213 fileMenu->Append(ID_SAVE_AS_COMPLEXBOX, _T("Save complex box"),
214 _T("Save complex box"));
215 fileMenu->Append(wxID_EXIT, _T("E&xit"), _T("Exit"));
217 Connect(ID_NEW, wxEVT_COMMAND_MENU_SELECTED,
218 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnCreateNewTab));
219 Connect(ID_SAVE_DIAGRAM, wxEVT_COMMAND_MENU_SELECTED,
220 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnSaveActualDiagram)); //DFCH
221 Connect(ID_SAVE_AS_DIAGRAM, wxEVT_COMMAND_MENU_SELECTED,
222 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnSaveAsActualDiagram));
223 Connect(ID_OPEN_BBS, wxEVT_COMMAND_MENU_SELECTED,
224 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnOpenBBS));
225 Connect(ID_SAVE_AS_BBS, wxEVT_COMMAND_MENU_SELECTED,
226 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnSaveActualBBS));
228 ID_SAVE_AS_COMPLEXBOX,
229 wxEVT_COMMAND_MENU_SELECTED,
230 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnSaveActualComplexBox));
231 Connect(wxID_EXIT, wxEVT_COMMAND_MENU_SELECTED,
232 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnExit));
234 // Create Help menu and its items
235 wxMenu *editMenu = new wxMenu;
236 editMenu->Append(ID_COPY_TO_COMPLEXDIAGRAM,
237 _T("Copy selected to complex box"),
238 _T("Creates a new complex box diagram with selected boxes"));
241 ID_COPY_TO_COMPLEXDIAGRAM,
242 wxEVT_COMMAND_MENU_SELECTED,
243 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnCopySelectedToComplexDiagram));
245 // Create Help menu and its items
246 wxMenu *helpMenu = new wxMenu;
247 helpMenu->Append(wxID_ABOUT, _T("&About..."), _T("About"));
248 helpMenu->Append(ID_HELP_BBEDITOR, _T("&Help..."), _T("Help"));
249 Connect(ID_HELP_BBEDITOR, wxEVT_COMMAND_MENU_SELECTED,
250 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnHelpBBeditor));
253 wxMenu *menuTools = new wxMenu;
254 menuTools->Append(ID_bbEditor_Tool_Menu_CreatePackage,
255 _T("Create &package") );
256 menuTools->Append(ID_bbEditor_Tool_Menu_CreateBlackBox,
257 _T("Create &blackbox") );
258 menuTools->Append(ID_bbEditor_Tool_Menu_PlugPackage, _T("Plug package") );
259 menuTools->Append(ID_bbEditor_Tool_Menu_EditConfig, _T("&Edit bbtk config") );
260 menuTools->Append(ID_bbEditor_Tool_Menu_ShowHTMLDoc,
261 _T("Show &HTML documentation") );
262 menuTools->Append(ID_bbEditor_Tool_Menu_CreateIndex, _T("&Generate index") );
264 Connect(ID_bbEditor_Tool_Menu_CreatePackage, wxEVT_COMMAND_MENU_SELECTED,
265 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnCreatePackage));
266 Connect(ID_bbEditor_Tool_Menu_CreateBlackBox, wxEVT_COMMAND_MENU_SELECTED,
267 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnCreateBlackBox));
268 Connect(ID_bbEditor_Tool_Menu_PlugPackage, wxEVT_COMMAND_MENU_SELECTED,
269 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnPlugPackage));
270 Connect(ID_bbEditor_Tool_Menu_EditConfig, wxEVT_COMMAND_MENU_SELECTED,
271 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnEditConfig));
272 Connect(ID_bbEditor_Tool_Menu_ShowHTMLDoc, wxEVT_COMMAND_MENU_SELECTED,
273 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnShowHTMLDoc));
274 Connect(ID_bbEditor_Tool_Menu_CreateIndex, wxEVT_COMMAND_MENU_SELECTED,
275 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnCreateIndex));
277 // Append the created menu to the menu bar
278 wxMenuBar *menuBar = new wxMenuBar();
279 menuBar->Append(fileMenu, _T("&File") );
280 menuBar->Append(editMenu, _T("&Edit") );
281 menuBar->Append(menuTools, _T("&Tool") );
282 menuBar->Append(helpMenu, _T("&Help") );
284 // Attach this menu bar to the frame
288 //=========================================================================
289 void wxGUIEditorGraphicBBS::initTabPanelsManager() {
290 _notebook = new wxAuiNotebook(this, wxID_NOTEBOOK, wxDefaultPosition,
291 wxDefaultSize, wxAUI_NB_TOP | wxAUI_NB_TAB_MOVE
292 | wxAUI_NB_CLOSE_ON_ACTIVE_TAB | wxAUI_NB_TAB_FIXED_WIDTH
293 | wxAUI_NB_WINDOWLIST_BUTTON);
294 _tabsMgr = new wxTabPanelsManager(this);
295 _frameAUIMgr->AddPane(_notebook, wxAuiPaneInfo().CenterPane());
299 //=========================================================================
300 void wxGUIEditorGraphicBBS::initPackageBrowser() {
301 _pkgBrowser = new WxGUIPackageBrowser2(this);
302 _pkgBrowser->IncludeAll();
303 _frameAUIMgr->AddPane(_pkgBrowser,
304 wxAuiPaneInfo().Left().MinSize(200, 200).CloseButton(false));
307 //================================================================
309 void wxGUIEditorGraphicBBS::DoRegeneratePackageDoc(const std::string& pack) {
310 std::string mess("Regenerating doc for package '");
314 mess = "Regenerating doc for all packages";
317 mess += " ... please wait";
319 SetStatusText(std2wx(mess));
327 command += ConfigurationFile::GetInstance().Get_bin_path();
328 command += ConfigurationFile::GetInstance().Get_file_separator();
329 command += "bbRegeneratePackageDoc";
334 command += " " + pack + " -q";
335 bbtkMessage("debug",1,"Executing system command '"<<command<<"'"<<std::endl);
337 if (!system(command.c_str())) {
338 SetStatusText(_T("Done !"));
340 wxMessageBox(_T("Done !"),_T("Regenerate package '")
341 +std2wx(pack)+_T("' doc"),
342 wxOK | wxICON_INFORMATION);
345 SetStatusText(_T("Done !"));
346 wxString err(_T("An error occured while running '"));
347 err += bbtk::std2wx(command) + _T("'");
348 wxMessageBox(err, _T("Regenerate package doc"), wxOK | wxICON_ERROR);
352 //================================================================
353 void wxGUIEditorGraphicBBS::DoRegenerateBoxesLists() {
354 SetStatusText(_T("Regenerating boxes lists ... please wait"));
361 command += ConfigurationFile::GetInstance().Get_bin_path();
362 command += ConfigurationFile::GetInstance().Get_file_separator();
363 command += "bbRegenerateBoxesLists";
370 bbtkMessage("debug",1,"Executing system command '"<<command<<"'"<<std::endl);
372 if (!system(command.c_str())) {
373 SetStatusText(_T("Done !"));
375 wxMessageBox(_T("Done !"),_T("Regenerate boxes lists"),
376 wxOK | wxICON_INFORMATION);
379 SetStatusText(_T("Done !"));
380 wxString err(_T("An error occured while running '"));
381 err += bbtk::std2wx(command) + _T("'");
382 wxMessageBox(err, _T("Regenerate boxes lists"), wxOK | wxICON_ERROR);
386 //================================================================
387 void wxGUIEditorGraphicBBS::RegenerateAll() {
388 DoRegeneratePackageDoc("-a");
389 DoRegenerateBoxesLists();
392 //================================================================
394 wxAuiNotebook* wxGUIEditorGraphicBBS::getAuiNotebook() {
398 //================================================================
400 void wxGUIEditorGraphicBBS::displayBlackBoxInfo(std::string packageName,
401 std::string boxName) {
402 if (_actualPkgBrowserPkgName != packageName || _actualPkgBrowserBoxName
404 _actualPkgBrowserPkgName = packageName;
405 _actualPkgBrowserBoxName = boxName;
407 BlackBoxDescriptor::Pointer descriptor =
408 GObjectsMVCFactory::getInstance()->getBlackBoxDescriptor(
409 packageName, boxName);
410 _pkgBrowser->WxGUIBlackBoxListUserOnSelected(descriptor.get());
414 //=========================================================================
416 void wxGUIEditorGraphicBBS::editBlackBox(GBlackBoxModel *bbmodel) {
417 wxBlackBoxEditionDialog* dialog =
418 new wxBlackBoxEditionDialog(this, bbmodel);
422 //=========================================================================
424 void wxGUIEditorGraphicBBS::updateStatusBar(std::string textStatus) {
425 SetStatusText(crea::std2wx(textStatus));
428 //=========================================================================
430 void wxGUIEditorGraphicBBS::executeScript(std::string script) {
431 std::string separator =
432 ConfigurationFile::GetInstance().Get_file_separator();
433 std::string dir = ConfigurationFile::GetInstance().Get_default_temp_dir();
434 std::string filename = dir + separator + "tmp_bbtk.bbs";
437 tempFile.open(filename.c_str());
441 std::string command = "";
444 command += "start /b ";
447 // command += "\""+ crea::System::GetExecutablePath();
449 // command += separator + "../../../bbi.app/Contents/MacOS";
453 command += "\"" + filename + "\"";
459 printf("RaC wxGUIEditorGraphicBBS::executeScript %s \n", command.c_str());
460 system(command.c_str());
463 //=========================================================================
464 std::string wxGUIEditorGraphicBBS::CheckExtension(std::string filename, std::string extension) {
465 if(filename.size() > extension.size() ){
466 if( (filename.compare(filename.size()-extension.size(), extension.size(),extension)) !=0 ){
467 filename.append(extension);
470 filename.append(extension);
474 //=========================================================================
476 //=========================================================================
478 void wxGUIEditorGraphicBBS::OnCreateNewTab(wxCommandEvent& event) {
479 _tabsMgr->addNewTab();
480 refreshGUIControls();
483 void wxGUIEditorGraphicBBS::OnUndo(wxCommandEvent& event) {
484 unsigned short disable;
485 GetToolBar()->EnableTool(ID_UNDO,_tabsMgr->loadTempDiagram(0));
486 if (GetToolBar()->GetToolEnabled(ID_REDO) == false)
487 GetToolBar()->EnableTool(ID_REDO,true);
488 refreshGUIControls();
491 void wxGUIEditorGraphicBBS::OnRedo(wxCommandEvent& event) {
492 unsigned short disable;
493 GetToolBar()->EnableTool(ID_REDO, _tabsMgr->loadTempDiagram(1));
494 if (GetToolBar()->GetToolEnabled(ID_UNDO) == false)
495 GetToolBar()->EnableTool(ID_UNDO,true);
496 refreshGUIControls();
498 //=========================================================================
500 void wxGUIEditorGraphicBBS::OnExecuteActualDiagram(wxCommandEvent& event) {
501 std::string script1 = _tabsMgr->getActualDiagramBBS(true);
502 cout << endl << "RaC wxGUIEditorGraphicBBS::executeActualDiagram SCRIPT"
504 cout << script1 << endl;
506 std::string script2 = _tabsMgr->getActualDiagramBBS(false);
507 executeScript(script2);
510 //=========================================================================
512 //=========================================================================
513 void wxGUIEditorGraphicBBS::OnOpenBBS(wxCommandEvent& event) {
514 wxFileDialog * openFileDialog = new wxFileDialog(this, wxT("Open BBS"),
515 wxEmptyString, wxT("NewBBS"), wxT("*.bbs"), wxOPEN);
516 if (openFileDialog->ShowModal() == wxID_OK) {
517 wxString fileName = openFileDialog->GetPath();
519 _tabsMgr->addNewTab(openFileDialog->GetFilename());
521 bbtk::InterpreterBBS::Pointer I = bbtk::InterpreterBBS::New(
522 this->_tabsMgr->getActualTabPanel()->getSceneManager(),
523 _pkgBrowser->GetFactory());
525 // We tell the interpreter to throw exceptions on error
527 // Interpret the file supposed to define a box called 'Processing'
528 I->InterpretFile((const char*) (fileName.mb_str()));
530 refreshGUIControls();
533 void wxGUIEditorGraphicBBS::SaveActualBBS(std::string filename) {
536 //EED file.open(fileName.c_str());
537 file.open(filename.c_str());
538 std::string content = "";
539 // writing file header
540 content += "# ----------------------------------\n";
541 content += "# - BBTKGEditor v 1.2 BBS BlackBox Script\n";
545 content += "# ----------------------------------\n";
547 content += _tabsMgr->getActualDiagramBBS();
552 void wxGUIEditorGraphicBBS::OnSaveActualBBS(wxCommandEvent& event) {
553 wxFileDialog * saveFileDialog = new wxFileDialog(this,
554 wxT("Save actual BBS"), wxEmptyString, wxT("NewBBS"),
555 wxT("*.bbs"), wxSAVE | wxOVERWRITE_PROMPT);
556 if (saveFileDialog->ShowModal() == wxID_OK) {
557 wxString fileName = saveFileDialog->GetPath();
558 std::string filename = (const char*) (fileName.mb_str());
559 filename=CheckExtension (filename, ".bbs");
560 SaveActualBBS(filename);
565 void wxGUIEditorGraphicBBS::AskComplexBoxConfiguration() {
566 std::string cbName = _tabsMgr->GetCbName();
567 std::string paName = _tabsMgr->GetCbPackageName();
569 wxTextEntryDialog *cbNameDialog = new wxTextEntryDialog(this,
570 wxT("Complex Box name"));
571 wxTextEntryDialog *paNameDialog = new wxTextEntryDialog(this,
572 wxT("Package name"));
574 cbNameDialog->SetValue(wxString(cbName.c_str(), wxConvUTF8));
575 paNameDialog->SetValue(wxString(paName.c_str(), wxConvUTF8));
577 if (cbNameDialog->ShowModal() == wxID_OK) {
578 wxString complexboxname = cbNameDialog->GetValue();
579 cbName = (const char*) (complexboxname.mb_str());
582 if (paNameDialog->ShowModal() == wxID_OK) {
583 wxString packagename = paNameDialog->GetValue();
584 paName = (const char*) (packagename.mb_str());
587 _tabsMgr->SetCbName(cbName);
588 _tabsMgr->SetCbPackageName(paName);
591 //=========================================================================
593 void wxGUIEditorGraphicBBS::SaveActualComplexBox(std::string filename) {
595 file.open(filename.c_str());
597 std::string content = "";
599 // writing file header
600 content += "# ----------------------------------\n";
601 content += "# - BBTKGEditor v 1.2 BBS BlackBox Script (Complex Box)\n";
605 content += "# ----------------------------------\n";
607 content += _tabsMgr->getActualComplexBoxBBS();
612 //=========================================================================
614 void wxGUIEditorGraphicBBS::OnSaveActualComplexBox(wxCommandEvent& event) {
615 wxFileDialog * saveFileDialog = new wxFileDialog(this,
616 wxT("Save Complex Box BBS"), wxEmptyString,
617 _T("ComplexBoxName"), wxT("*.bbs"), wxSAVE
618 | wxOVERWRITE_PROMPT);
619 if (saveFileDialog->ShowModal() == wxID_OK) {
620 wxString fileName = saveFileDialog->GetPath();
621 std::string filename = (const char*) (fileName.mb_str());
622 filename=CheckExtension (filename, ".bbs");
623 SaveActualComplexBox(filename);
627 //=========================================================================
628 void wxGUIEditorGraphicBBS::SaveActualDiagram(std::string filename) {
630 file.open(filename.c_str());
632 std::string content = "";
634 // writing file header
635 content += "# ----------------------------------\n";
636 content += "# - BBTKGEditor v 1.2 BBG BlackBox Diagram file\n";
642 content += "# ----------------------------------\n";
644 content += "APP_START\n";
645 _tabsMgr->saveActualDiagram(content, filename); //DFCH
646 content += "APP_END\n";
651 //=========================================================================
652 void wxGUIEditorGraphicBBS::SaveTempActualDiagram()
654 _tabsMgr->saveTempActualDiagram();
657 //=========================================================================
659 //The following method allows to save the current diagram asking the filename
661 void wxGUIEditorGraphicBBS::SaveCurrentDiagramAs() {
662 wxFileDialog * saveFileDialog = new wxFileDialog(this,
663 wxT("Save current diagram"), wxEmptyString, wxT("NewDiagram"),
664 wxT("*.bbg"), wxSAVE | wxOVERWRITE_PROMPT);
665 if (saveFileDialog->ShowModal() == wxID_OK) {
666 //_tabsMgr->SetNameTabPanel(saveFileDialog->GetFilename());
667 wxString pathfileName = saveFileDialog->GetPath();
668 std::string pathfilename = (const char*) (pathfileName.mb_str());
669 pathfilename=CheckExtension (pathfilename, ".bbg");
671 //modify the tab name accordingly
672 wxString fileName = saveFileDialog->GetFilename();
673 std::string filename = (const char*) (fileName.mb_str());
674 filename=CheckExtension (filename, ".bbg");
675 _tabsMgr->SetNameTabPanel( wxString (filename.c_str(), wxConvUTF8) );
677 std::string pathfilenamebbs = pathfilename;
678 pathfilenamebbs[pathfilenamebbs.length() - 1] = 's';
679 if (_tabsMgr->isActualDiagramComplexBox() == false) {
680 SaveActualDiagram(pathfilename);
681 SaveActualBBS(pathfilenamebbs);
683 AskComplexBoxConfiguration();
684 SaveActualDiagram(pathfilename);
685 SaveActualComplexBox(pathfilenamebbs);
686 } //if isActualDiagramComplexBox
687 } // if saveFileDialog
689 //=========================================================================
691 void wxGUIEditorGraphicBBS::OnSaveActualDiagram(wxCommandEvent& event) {
692 std::string pathfilename = _tabsMgr->GetCurrentTabPanelPath();
693 if (pathfilename.empty()) {
694 SaveCurrentDiagramAs();
696 std::string pathfilenamebbs = pathfilename;
697 pathfilenamebbs[pathfilenamebbs.length() - 1] = 's';
699 if (_tabsMgr->isActualDiagramComplexBox() == false) {
700 SaveActualDiagram(pathfilename);
701 SaveActualBBS(pathfilenamebbs);
703 AskComplexBoxConfiguration();
704 SaveActualDiagram(pathfilename);
705 SaveActualComplexBox(pathfilenamebbs);
706 } //if isActualDiagramComplexBox
709 //=========================================================================
711 void wxGUIEditorGraphicBBS::OnSaveAsActualDiagram(wxCommandEvent& event) {
712 SaveCurrentDiagramAs();
714 //=========================================================================
716 void wxGUIEditorGraphicBBS::refreshGUIControls() {
717 wxToolBar* toolbar = GetToolBar();
718 if (_tabsMgr->isActualDiagramComplexBox()) {
719 toolbar->ToggleTool(ID_BTNCOMPLEXBOX, true);
720 toolbar->EnableTool(ID_ADDCOMPLEXBOXINPUT, true);
721 toolbar->EnableTool(ID_ADDCOMPLEXBOXOUTPUT, true);
723 GetMenuBar()->GetMenu(0)->Enable(ID_SAVE_AS_COMPLEXBOX, true);
724 GetMenuBar()->GetMenu(0)->Enable(ID_SAVE_AS_BBS, false);
726 toolbar->ToggleTool(ID_BTNCOMPLEXBOX, false);
727 toolbar->EnableTool(ID_ADDCOMPLEXBOXINPUT, false);
728 toolbar->EnableTool(ID_ADDCOMPLEXBOXOUTPUT, false);
730 GetMenuBar()->GetMenu(0)->Enable(ID_SAVE_AS_COMPLEXBOX, false);
731 GetMenuBar()->GetMenu(0)->Enable(ID_SAVE_AS_BBS, true);
734 if (_tabsMgr->getNumActualSelectedObjects() > 0) {
735 GetMenuBar()->GetMenu(1)->Enable(ID_COPY_TO_COMPLEXDIAGRAM, true);
737 ///TODO Fix the possibility to say from the SceneManager to the GUI to refresh the options
738 GetMenuBar()->GetMenu(1)->Enable(ID_COPY_TO_COMPLEXDIAGRAM, true);
743 //=========================================================================
745 void wxGUIEditorGraphicBBS::OnDeleteAllBoxesActualDiagram(wxCommandEvent& event) {
746 wxMessageDialog *dial = new wxMessageDialog(NULL,
747 wxT("Are you sure to delete all boxes of the diagram?"),
748 wxT("Delete all boxes"), wxYES_NO | wxNO_DEFAULT
750 if (dial->ShowModal() == wxID_YES) {
751 _tabsMgr->deleteAllBoxesActualDiagram();
755 //=========================================================================
757 void wxGUIEditorGraphicBBS::OnCenterViewActualDiagram(wxCommandEvent& event) {
758 _tabsMgr->centerViewActualDiagram();
761 //=========================================================================
763 void wxGUIEditorGraphicBBS::OnOpenDiagram(wxCommandEvent& event) {
764 wxFileDialog * openFileDialog = new wxFileDialog(this, wxT("Open diagram"),
765 wxEmptyString, wxT(""), wxT("*.bbg"), wxOPEN | wxFILE_MUST_EXIST);
766 if (openFileDialog->ShowModal() == wxID_OK) {
767 wxString fileName = openFileDialog->GetPath();
768 ifstream inputStream;
769 std::string fName = (const char*) (fileName.mb_str());
770 inputStream.open(fName.c_str());
771 _tabsMgr->addNewTab(openFileDialog->GetFilename());
773 _tabsMgr->loadDiagram(inputStream, fName);
777 refreshGUIControls();
780 //=========================================================================
783 void wxGUIEditorGraphicBBS::OnClickBtnBox(wxCommandEvent& event) {
784 BlackBoxDescriptor *bbDes = _pkgBrowser->GetActualSelected();
786 std::string typeName = bbDes->GetTypeName();
787 std::string packageName = bbDes->GetPackage()->GetName();
789 wxGEditorTabPanel *pnl = this->_tabsMgr->getActualTabPanel();
791 // save empty state!!
792 /* if (_tabsMgr->getNumActualSelectedObjects() == 0)
794 SaveTempActualDiagram();
798 wxVtkSceneManager *scn = pnl->getSceneManager();
799 scn->createGBlackBox(50, 50, packageName, typeName);
802 if (GetToolBar()->GetToolEnabled(ID_UNDO) == false)
803 GetToolBar()->EnableTool(ID_UNDO,true);
804 SaveTempActualDiagram();
809 //=========================================================================
811 void wxGUIEditorGraphicBBS::OnClickBtnExecutableBox(wxCommandEvent& event) {
813 wxGEditorTabPanel *pnl = this->_tabsMgr->getActualTabPanel();
816 wxVtkSceneManager *scn = pnl->getSceneManager();
817 if( scn->MakeBoxExecutable() )
818 std::cout<<"DFCH: wxGUIEditorGraphicBBS::OnClickBtnExecutableBox...successful"<<std::endl;
820 std::cout<<"DFCH: wxGUIEditorGraphicBBS::OnClickBtnExecutableBox...Error!!"<<std::endl;
826 //=========================================================================
828 void wxGUIEditorGraphicBBS::OnClickBtnComplexBox(wxCommandEvent& event) {
829 wxToolBar* toolbar = GetToolBar();
830 bool temp = toolbar->GetToolState(ID_BTNCOMPLEXBOX);
832 _tabsMgr->setActualDiagramComplexBox(true);
834 _tabsMgr->setActualDiagramComplexBox(false);
836 refreshGUIControls();
839 //=========================================================================
841 void wxGUIEditorGraphicBBS::OnAddComplexBoxInput(wxCommandEvent& event) {
842 wxTextEntryDialog *nameDialog = new wxTextEntryDialog(this,
843 wxT("Name of input port"));
844 if (nameDialog->ShowModal() == wxID_OK) {
845 wxString fileName = nameDialog->GetValue();
846 if (!fileName.IsEmpty()) {
847 std::string portName = (const char*) (fileName.mb_str());
848 _tabsMgr->addActualDiagramComplexInputPort(portName);
853 //=========================================================================
855 void wxGUIEditorGraphicBBS::OnAddComplexBoxOutput(wxCommandEvent& event) {
856 wxTextEntryDialog *nameDialog = new wxTextEntryDialog(this,
857 wxT("Name of output port"));
858 if (nameDialog->ShowModal() == wxID_OK) {
859 wxString fileName = nameDialog->GetValue();
860 if (!fileName.IsEmpty()) {
861 std::string portName = (const char*) (fileName.mb_str());
862 _tabsMgr->addActualDiagramComplexOutputPort(portName);
867 //=========================================================================
869 void wxGUIEditorGraphicBBS::OnCopySelectedToComplexDiagram(
870 wxCommandEvent& event) {
871 _tabsMgr->copySelectedBBoxesToComplexDiagram();
874 void wxGUIEditorGraphicBBS::OnHelpBBeditor(wxCommandEvent& event) {
875 printf("wxGUIEditorGraphicBBS::OnHelpBBeditor ....not implemented..\n");
878 //=========================================================================
879 void wxGUIEditorGraphicBBS::OnCreatePackage(wxCommandEvent& event) {
881 bbtkSystemTools::CreatePackage();
884 //=========================================================================
885 void wxGUIEditorGraphicBBS::OnCreateBlackBox(wxCommandEvent& event) {
886 bbtkSystemTools::CreateBlackBox();
888 //=========================================================================
889 void wxGUIEditorGraphicBBS::OnPlugPackage(wxCommandEvent& event) {
890 printf("EED wxGUIEditorGraphicBBS::OnPlugPackage ... not implemented ..\n");
892 //=========================================================================
893 void wxGUIEditorGraphicBBS::OnEditConfig(wxCommandEvent& event) {
894 printf("EED wxGUIEditorGraphicBBS::OnEditConfig ... not implemented ..\n");
896 //=========================================================================
897 void wxGUIEditorGraphicBBS::OnShowHTMLDoc(wxCommandEvent& event) {
898 printf("EED wxGUIEditorGraphicBBS::OnShowHTMLDoc ... not implemented ..\n");
900 //=========================================================================
901 void wxGUIEditorGraphicBBS::OnCreateIndex(wxCommandEvent& event) {
902 printf("EED wxGUIEditorGraphicBBS::OnCreateIndex ... not implemented ..\n");
905 //=========================================================================
907 void wxGUIEditorGraphicBBS::OnExit(wxCommandEvent& event) {
911 //=========================================================================
913 } // EO namespace bbtk