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"
39 //must go #include "bbtkUtilities.h"
40 //must go #include "bbtkConfigurationFile.h"
43 #include <InterpreterBBS.h>
47 //=========================================================================
48 wxGUIEditorGraphicBBS::wxGUIEditorGraphicBBS(wxFrame *parent) :
49 wxFrame(parent, -1, _T("bbtkGEditor"), wxDefaultPosition, wxSize(
52 _frameAUIMgr = new wxAuiManager(this);
54 /*std::string datadir( crea::System::GetExecutablePath() );
55 std::string datadir (".");
56 cout<<"RaC //------------------"<<endl;
57 cout<<"RaC //TODO wxGUIEditorGraphicBBS constructor.Initialize datadir with crea::System::GetExecutablePath() ."<<endl;
58 cout<<"RaC //------------------"<<endl;
60 #ifdef LINUX // assume this is OSX
61 datadir=datadir+"/../share/creaContours";
64 #ifdef MACOSX // assume this is OSX
65 datadir=datadir+"/../../../../share/creaContours";
72 initTabPanelsManager();
74 // JGGR & CM initHelpHTMLBrowser();
75 _helpHtmlBrowser = NULL;
77 _frameAUIMgr->Update();
78 _actualPkgBrowserBoxName = "";
79 _actualPkgBrowserPkgName = "";
83 //=========================================================================
84 wxGUIEditorGraphicBBS::~wxGUIEditorGraphicBBS() {
86 printf("EED %p ~wxGUIEditorGraphicBBS()\n", this);
88 //EED02JUIN2010 delete _tabsMgr;
90 _frameAUIMgr->UnInit();
98 //=========================================================================
99 void wxGUIEditorGraphicBBS::initToolbar() {
100 wxBitmap bmp_new(new_xpm);
101 wxBitmap bmp_open(open_xpm);
102 wxBitmap bmp_save(save_xpm);
103 wxBitmap bmp_run(run_xpm);
104 wxBitmap bmp_delete(delete_xpm);
105 wxBitmap bmp_centerview(centerview_xpm);
106 wxBitmap bmp_box(box_xpm);
107 wxBitmap bmp_executablebox(executablebox_xpm);
108 wxBitmap bmp_complexbox(complexbox_xpm);
109 wxBitmap bmp_complexinputport(complexinputport_xpm);
110 wxBitmap bmp_complexoutputport(complexoutputport_xpm);
111 wxBitmap bmp_undo(undo_xpm);
112 wxBitmap bmp_redo(redo_xpm);
113 wxToolBar *toolbar = new wxToolBar(this, wxID_ANY);
115 //Adds a tool btn to the toolbar
116 toolbar->AddTool(ID_NEW, _T("New"), bmp_new, wxNullBitmap, wxITEM_NORMAL,
117 _T("New tab"), _T("Create a new panel tab"));
118 toolbar->AddTool(ID_OPEN, _T("Open diagram"), bmp_open, wxNullBitmap,
119 wxITEM_NORMAL, _T("Open a diagram"), _T("Open a diagram"));
120 toolbar->AddTool(ID_SAVE_DIAGRAM, _T("Save Diagram"), bmp_save,
121 wxNullBitmap, wxITEM_NORMAL, _T("Saves the current diagram"),
122 _T("Saves the current diagram")); //DFCH
123 //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
124 toolbar->AddTool(ID_RUN, _T("Run"), bmp_run, wxNullBitmap, wxITEM_NORMAL,
125 _T("Execute actual diagram"), _T("Execute actual diagram"));
126 toolbar->AddTool(ID_DELETEALL, _T("Delete all"), bmp_delete, wxNullBitmap,
127 wxITEM_NORMAL, _T("Delete all boxes"), _T("Delete all boxes"));
128 toolbar->AddTool(ID_CENTERVIEW, _T("Center view"), bmp_centerview,
129 wxNullBitmap, wxITEM_NORMAL, _T("Center view"), _T("Center view"));
130 toolbar->AddSeparator();
131 toolbar->AddTool(ID_BTNBOX, _T("New Box"), bmp_box, wxNullBitmap,
132 wxITEM_NORMAL, _T("New Box"), _T("Nex Box"));
133 toolbar->AddSeparator();
134 toolbar->AddTool(ID_BTEXECUTABLEBOX, _T("Select as executable Box"),
135 bmp_executablebox, wxNullBitmap, wxITEM_NORMAL,
136 _T("Select as executable Box"), _T("Select as executable Box"));
137 toolbar->AddSeparator();
138 toolbar->AddTool(ID_BTNCOMPLEXBOX, _T("Complex box"), complexbox_xpm,
139 wxNullBitmap, wxITEM_NORMAL, _T("Complex box"), _T("Complex box"));
140 toolbar->SetToggle(ID_BTNCOMPLEXBOX, true);
141 toolbar->AddTool(ID_ADDCOMPLEXBOXINPUT, _T("Add input to Complex box"),
142 bmp_complexinputport, wxNullBitmap, wxITEM_NORMAL,
143 _T("Add input to Complex box"), _T("Add input to Complex box"));
144 toolbar->AddTool(ID_ADDCOMPLEXBOXOUTPUT, _T("Add output to Complex box"),
145 bmp_complexoutputport, wxNullBitmap, wxITEM_NORMAL,
146 _T("Add output Complex box"), _T("Add output Complex box"));
147 toolbar->EnableTool(ID_ADDCOMPLEXBOXINPUT, false);
148 toolbar->EnableTool(ID_ADDCOMPLEXBOXOUTPUT, false);
149 toolbar->AddSeparator();
150 toolbar->AddTool(ID_UNDO, _T("Undo"),bmp_undo, wxNullBitmap, wxITEM_NORMAL, _T("Undo"), _T("Undo"));
151 toolbar->AddTool(ID_REDO, _T("Redo"),bmp_redo, wxNullBitmap, wxITEM_NORMAL, _T("Redo"), _T("Redo"));
153 toolbar->EnableTool(ID_UNDO, false);
154 toolbar->EnableTool(ID_REDO, false);
155 toolbar->SetMargins(2, 2);
160 // connect command event handlers
162 Connect(ID_NEW, wxEVT_COMMAND_TOOL_CLICKED,
163 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnCreateNewTab));
164 Connect(ID_OPEN, wxEVT_COMMAND_TOOL_CLICKED,
165 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnOpenDiagram));
166 Connect(ID_SAVE_DIAGRAM, wxEVT_COMMAND_TOOL_CLICKED,
167 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnSaveActualDiagram)); //DFCH
168 Connect(ID_SAVE_AS_DIAGRAM, wxEVT_COMMAND_TOOL_CLICKED,
169 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnSaveAsActualDiagram)); //DFCH
172 wxEVT_COMMAND_TOOL_CLICKED,
173 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnExecuteActualDiagram));
176 wxEVT_COMMAND_TOOL_CLICKED,
177 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnDeleteAllBoxesActualDiagram));
180 wxEVT_COMMAND_TOOL_CLICKED,
181 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnCenterViewActualDiagram));
182 Connect(ID_BTNBOX, wxEVT_COMMAND_TOOL_CLICKED,
183 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnClickBtnBox));
186 wxEVT_COMMAND_TOOL_CLICKED,
187 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnClickBtnExecutableBox));
188 Connect(ID_BTNCOMPLEXBOX, wxEVT_COMMAND_TOOL_CLICKED,
189 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnClickBtnComplexBox));
190 Connect(ID_ADDCOMPLEXBOXINPUT, wxEVT_COMMAND_TOOL_CLICKED,
191 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnAddComplexBoxInput));
192 Connect(ID_ADDCOMPLEXBOXOUTPUT, wxEVT_COMMAND_TOOL_CLICKED,
193 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnAddComplexBoxOutput));
194 Connect(ID_UNDO,wxEVT_COMMAND_TOOL_CLICKED, wxCommandEventHandler(wxGUIEditorGraphicBBS::OnUndo));
195 Connect(ID_REDO,wxEVT_COMMAND_TOOL_CLICKED, wxCommandEventHandler(wxGUIEditorGraphicBBS::OnRedo));
196 Connect(ID_CHANGENAME, wxEVT_COMMAND_RIGHT_CLICK, wxCommandEventHandler(wxGUIEditorGraphicBBS::OnChangeName));
198 //=========================================================================
199 void wxGUIEditorGraphicBBS::initHelpHTMLBrowser() {
201 _helpHtmlBrowser = new WxGUIHtmlBrowser(this, wxSize(200, 0));
207 //=========================================================================
208 void wxGUIEditorGraphicBBS::initMenu() {
209 // Create File menu and its items
210 wxMenu *fileMenu = new wxMenu();
211 fileMenu->Append(ID_NEW, _T("New diagram"), _T("New"));
212 fileMenu->Append(ID_SAVE_DIAGRAM, _T("Save Diagram"), _T("Save Diagram")); //DFCH
213 fileMenu->Append(ID_SAVE_AS_DIAGRAM, _T("Save Diagram As"),
214 _T("Save Diagram As")); //DFCH
215 fileMenu->Append(ID_OPEN_BBS, _T("Open BBS"), _T("Open BBS"));
217 fileMenu->Append(ID_OPEN, _T("Open a diagram"), _T("Open a diagram"));
218 fileMenu->Append(ID_SAVE_AS_BBS, _T("Save BBS"), _T("Save BBS"));
219 fileMenu->Append(ID_SAVE_AS_COMPLEXBOX, _T("Save complex box"),
220 _T("Save complex box"));
221 fileMenu->Append(wxID_EXIT, _T("E&xit"), _T("Exit"));
223 Connect(ID_NEW, wxEVT_COMMAND_MENU_SELECTED,
224 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnCreateNewTab));
225 Connect(ID_SAVE_DIAGRAM, wxEVT_COMMAND_MENU_SELECTED,
226 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnSaveActualDiagram)); //DFCH
227 Connect(ID_SAVE_AS_DIAGRAM, wxEVT_COMMAND_MENU_SELECTED,
228 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnSaveAsActualDiagram));
229 Connect(ID_OPEN_BBS, wxEVT_COMMAND_MENU_SELECTED,
230 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnOpenBBS));
231 Connect(ID_SAVE_AS_BBS, wxEVT_COMMAND_MENU_SELECTED,
232 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnSaveActualBBS));
234 ID_SAVE_AS_COMPLEXBOX,
235 wxEVT_COMMAND_MENU_SELECTED,
236 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnSaveActualComplexBox));
237 Connect(wxID_EXIT, wxEVT_COMMAND_MENU_SELECTED,
238 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnExit));
240 // Create Help menu and its items
241 wxMenu *editMenu = new wxMenu;
242 editMenu->Append(ID_COPY_TO_COMPLEXDIAGRAM,
243 _T("Copy selected to complex box"),
244 _T("Creates a new complex box diagram with selected boxes"));
247 ID_COPY_TO_COMPLEXDIAGRAM,
248 wxEVT_COMMAND_MENU_SELECTED,
249 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnCopySelectedToComplexDiagram));
251 // Create Help menu and its items
252 wxMenu *helpMenu = new wxMenu;
253 helpMenu->Append(wxID_ABOUT, _T("&About..."), _T("About"));
254 helpMenu->Append(ID_HELP_BBEDITOR, _T("&Help..."), _T("Help"));
255 Connect(ID_HELP_BBEDITOR, wxEVT_COMMAND_MENU_SELECTED,
256 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnHelpBBeditor));
259 wxMenu *menuTools = new wxMenu;
260 menuTools->Append(ID_bbEditor_Tool_Menu_CreatePackage,
261 _T("Create &package") );
262 menuTools->Append(ID_bbEditor_Tool_Menu_CreateBlackBox,
263 _T("Create &blackbox") );
264 menuTools->Append(ID_bbEditor_Tool_Menu_PlugPackage, _T("Plug package") );
265 menuTools->Append(ID_bbEditor_Tool_Menu_EditConfig, _T("&Edit bbtk config") );
266 menuTools->Append(ID_bbEditor_Tool_Menu_ShowHTMLDoc,
267 _T("Show &HTML documentation") );
268 menuTools->Append(ID_bbEditor_Tool_Menu_CreateIndex, _T("&Generate index") );
270 Connect(ID_bbEditor_Tool_Menu_CreatePackage, wxEVT_COMMAND_MENU_SELECTED,
271 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnCreatePackage));
272 Connect(ID_bbEditor_Tool_Menu_CreateBlackBox, wxEVT_COMMAND_MENU_SELECTED,
273 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnCreateBlackBox));
274 Connect(ID_bbEditor_Tool_Menu_PlugPackage, wxEVT_COMMAND_MENU_SELECTED,
275 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnPlugPackage));
276 Connect(ID_bbEditor_Tool_Menu_EditConfig, wxEVT_COMMAND_MENU_SELECTED,
277 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnEditConfig));
278 Connect(ID_bbEditor_Tool_Menu_ShowHTMLDoc, wxEVT_COMMAND_MENU_SELECTED,
279 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnShowHTMLDoc));
280 Connect(ID_bbEditor_Tool_Menu_CreateIndex, wxEVT_COMMAND_MENU_SELECTED,
281 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnCreateIndex));
283 // Append the created menu to the menu bar
284 wxMenuBar *menuBar = new wxMenuBar();
285 menuBar->Append(fileMenu, _T("&File") );
286 menuBar->Append(editMenu, _T("&Edit") );
287 menuBar->Append(menuTools, _T("&Tool") );
288 menuBar->Append(helpMenu, _T("&Help") );
290 // Attach this menu bar to the frame
294 //=========================================================================
295 void wxGUIEditorGraphicBBS::initTabPanelsManager()
297 _notebook = new wxAuiNotebook(this, wxID_NOTEBOOK, wxDefaultPosition,
298 wxDefaultSize, wxAUI_NB_TOP | wxAUI_NB_TAB_MOVE
299 | wxAUI_NB_CLOSE_ON_ACTIVE_TAB | wxAUI_NB_TAB_FIXED_WIDTH
300 | wxAUI_NB_WINDOWLIST_BUTTON);
301 _tabsMgr = new wxTabPanelsManager(this);
302 _frameAUIMgr->AddPane(_notebook, wxAuiPaneInfo().CenterPane());
305 //=========================================================================
306 void wxGUIEditorGraphicBBS::initPackageBrowser()
308 _pkgBrowser = new WxGUIPackageBrowser2(this);
309 _pkgBrowser->IncludeAll();
310 _frameAUIMgr->AddPane(_pkgBrowser, wxAuiPaneInfo().Left().MinSize(30, 500).BestSize(750,500).CloseButton(false));
313 //================================================================
315 void wxGUIEditorGraphicBBS::DoRegeneratePackageDoc(const std::string& pack)
317 std::string mess("Regenerating doc for package '");
321 mess = "Regenerating doc for all packages";
324 mess += " ... please wait";
326 SetStatusText(std2wx(mess));
334 command += ConfigurationFile::GetInstance().Get_bin_path();
335 command += ConfigurationFile::GetInstance().Get_file_separator();
336 command += "bbRegeneratePackageDoc";
341 command += " " + pack + " -q";
342 bbtkMessage("debug",1,"Executing system command '"<<command<<"'"<<std::endl);
344 if (!system(command.c_str())) {
345 SetStatusText(_T("Done !"));
347 wxMessageBox(_T("Done !"),_T("Regenerate package '")
348 +std2wx(pack)+_T("' doc"),
349 wxOK | wxICON_INFORMATION);
352 SetStatusText(_T("Done !"));
353 wxString err(_T("An error occured while running '"));
354 err += bbtk::std2wx(command) + _T("'");
355 wxMessageBox(err, _T("Regenerate package doc"), wxOK | wxICON_ERROR);
359 //================================================================
360 void wxGUIEditorGraphicBBS::DoRegenerateBoxesLists() {
361 SetStatusText(_T("Regenerating boxes lists ... please wait"));
368 command += ConfigurationFile::GetInstance().Get_bin_path();
369 command += ConfigurationFile::GetInstance().Get_file_separator();
370 command += "bbRegenerateBoxesLists";
377 bbtkMessage("debug",1,"Executing system command '"<<command<<"'"<<std::endl);
379 if (!system(command.c_str())) {
380 SetStatusText(_T("Done !"));
382 wxMessageBox(_T("Done !"),_T("Regenerate boxes lists"),
383 wxOK | wxICON_INFORMATION);
386 SetStatusText(_T("Done !"));
387 wxString err(_T("An error occured while running '"));
388 err += bbtk::std2wx(command) + _T("'");
389 wxMessageBox(err, _T("Regenerate boxes lists"), wxOK | wxICON_ERROR);
393 //================================================================
394 void wxGUIEditorGraphicBBS::RegenerateAll() {
395 DoRegeneratePackageDoc("-a");
396 DoRegenerateBoxesLists();
399 //================================================================
401 wxAuiNotebook* wxGUIEditorGraphicBBS::getAuiNotebook() {
405 //================================================================
407 void wxGUIEditorGraphicBBS::displayBlackBoxInfo(std::string packageName,
408 std::string boxName) {
409 if (_actualPkgBrowserPkgName != packageName || _actualPkgBrowserBoxName
411 _actualPkgBrowserPkgName = packageName;
412 _actualPkgBrowserBoxName = boxName;
414 BlackBoxDescriptor::Pointer descriptor =
415 GObjectsMVCFactory::getInstance()->getBlackBoxDescriptor(
416 packageName, boxName);
417 _pkgBrowser->WxGUIBlackBoxListUserOnSelected(descriptor.get());
421 //=========================================================================
423 void wxGUIEditorGraphicBBS::editBlackBox(GBlackBoxModel *bbmodel) {
424 wxBlackBoxEditionDialog* dialog =
425 new wxBlackBoxEditionDialog(this, bbmodel);
429 //=========================================================================
431 bool wxGUIEditorGraphicBBS::boxNameExists(std::string boxname) {
433 return this->_tabsMgr->getActualTabPanel()->getSceneManager()->boxExist(boxname);
436 //=========================================================================
438 void wxGUIEditorGraphicBBS::updateStatusBar(std::string textStatus) {
439 SetStatusText(crea::std2wx(textStatus));
442 //=========================================================================
444 void wxGUIEditorGraphicBBS::executeScript(std::string script) {
445 std::string separator =
446 ConfigurationFile::GetInstance().Get_file_separator();
447 std::string dir = ConfigurationFile::GetInstance().Get_default_temp_dir();
448 std::string filename = dir + separator + "tmp_bbtk.bbs";
451 tempFile.open(filename.c_str());
455 std::string command = "";
458 command += "start /b ";
461 // command += "\""+ crea::System::GetExecutablePath();
463 // command += separator + "../../../bbi.app/Contents/MacOS";
467 command += "\"" + filename + "\"";
473 printf("RaC wxGUIEditorGraphicBBS::executeScript %s \n", command.c_str());
474 system(command.c_str());
477 //=========================================================================
478 std::string wxGUIEditorGraphicBBS::CheckExtension(std::string filename, std::string extension) {
479 if(filename.size() > extension.size() ){
480 if( (filename.compare(filename.size()-extension.size(), extension.size(),extension)) !=0 ){
481 filename.append(extension);
484 filename.append(extension);
488 //=========================================================================
490 //=========================================================================
492 void wxGUIEditorGraphicBBS::OnCreateNewTab(wxCommandEvent& event) {
493 _tabsMgr->addNewTab();
494 refreshGUIControls();
497 void wxGUIEditorGraphicBBS::OnUndo(wxCommandEvent& event) {
498 unsigned short disable;
502 _tabsMgr->loadTempDiagram(0);
503 disable = _tabsMgr->getUndoState(stundo);
506 std::string name = _tabsMgr->GetNameTabPanel();
507 if(name[name.length() - 1] == '*')
509 name =name.substr(0,name.length()-1);
511 _tabsMgr->SetNameTabPanel(wxString (name.c_str(), wxConvUTF8));
514 GetToolBar()->EnableTool(ID_UNDO,disable);
515 GetToolBar()->SetToolShortHelp(ID_UNDO,crea::std2wx(stundo));
516 GetToolBar()->EnableTool(ID_REDO,_tabsMgr->getRedoState(stredo));
517 GetToolBar()->SetToolShortHelp(ID_REDO,crea::std2wx(stredo));
518 refreshGUIControls();
521 void wxGUIEditorGraphicBBS::OnRedo(wxCommandEvent& event) {
522 unsigned short disable;
526 _tabsMgr->loadTempDiagram(1);
527 std::string name = _tabsMgr->GetNameTabPanel();
528 if(name[name.length() - 1] != '*')
530 _tabsMgr->SetNameTabPanel(wxString (name.c_str(), wxConvUTF8));
531 GetToolBar()->EnableTool(ID_UNDO,_tabsMgr->getUndoState(stundo));
532 GetToolBar()->SetToolShortHelp(ID_UNDO,crea::std2wx(stundo));
533 GetToolBar()->EnableTool(ID_REDO,_tabsMgr->getRedoState(stredo));
534 GetToolBar()->SetToolShortHelp(ID_REDO,crea::std2wx(stredo));
535 refreshGUIControls();
538 void wxGUIEditorGraphicBBS::OnChangeName(wxCommandEvent& event){
540 //=========================================================================
542 void wxGUIEditorGraphicBBS::OnExecuteActualDiagram(wxCommandEvent& event) {
543 std::string script1 = _tabsMgr->getActualDiagramBBS(true);
544 cout << endl << "RaC wxGUIEditorGraphicBBS::executeActualDiagram SCRIPT"
546 cout << script1 << endl;
548 std::string script2 = _tabsMgr->getActualDiagramBBS(false);
549 executeScript(script2);
552 //=========================================================================
554 //=========================================================================
555 void wxGUIEditorGraphicBBS::OnOpenBBS(wxCommandEvent& event) {
556 wxFileDialog * openFileDialog = new wxFileDialog(this, wxT("Open BBS"),
557 wxEmptyString, wxT("NewBBS"), wxT("*.bbs"), wxOPEN);
558 if (openFileDialog->ShowModal() == wxID_OK) {
559 wxString fileName = openFileDialog->GetPath();
561 _tabsMgr->addNewTab(openFileDialog->GetFilename());
563 bbtk::InterpreterBBS::Pointer I = bbtk::InterpreterBBS::New(
564 this->_tabsMgr->getActualTabPanel()->getSceneManager(),
565 _pkgBrowser->GetFactory());
567 // We tell the interpreter to throw exceptions on error
569 // Interpret the file supposed to define a box called 'Processing'
570 I->InterpretFile((const char*) (fileName.mb_str()));
572 refreshGUIControls();
575 void wxGUIEditorGraphicBBS::SaveActualBBS(std::string filename) {
578 //EED file.open(fileName.c_str());
579 file.open(filename.c_str());
580 std::string content = "";
581 // writing file header
582 content += "# ----------------------------------\n";
583 content += "# - BBTKGEditor v 1.3 BBS BlackBox Script\n";
587 content += "# ----------------------------------\n";
589 content += _tabsMgr->getActualDiagramBBS();
594 void wxGUIEditorGraphicBBS::OnSaveActualBBS(wxCommandEvent& event) {
595 wxFileDialog * saveFileDialog = new wxFileDialog(this,
596 wxT("Save actual BBS"), wxEmptyString, wxT("NewBBS"),
597 wxT("*.bbs"), wxSAVE | wxOVERWRITE_PROMPT);
598 if (saveFileDialog->ShowModal() == wxID_OK) {
599 wxString fileName = saveFileDialog->GetPath();
600 std::string filename = (const char*) (fileName.mb_str());
601 filename=CheckExtension (filename, ".bbs");
602 SaveActualBBS(filename);
607 void wxGUIEditorGraphicBBS::AskComplexBoxConfiguration() {
608 std::string cbName = _tabsMgr->GetCbName();
609 std::string paName = _tabsMgr->GetCbPackageName();
611 wxTextEntryDialog *cbNameDialog = new wxTextEntryDialog(this,
612 wxT("Complex Box name"));
613 wxTextEntryDialog *paNameDialog = new wxTextEntryDialog(this,
614 wxT("Package name"));
616 cbNameDialog->SetValue(wxString(cbName.c_str(), wxConvUTF8));
617 paNameDialog->SetValue(wxString(paName.c_str(), wxConvUTF8));
619 if (cbNameDialog->ShowModal() == wxID_OK) {
620 wxString complexboxname = cbNameDialog->GetValue();
621 cbName = (const char*) (complexboxname.mb_str());
624 if (paNameDialog->ShowModal() == wxID_OK) {
625 wxString packagename = paNameDialog->GetValue();
626 paName = (const char*) (packagename.mb_str());
629 _tabsMgr->SetCbName(cbName);
630 _tabsMgr->SetCbPackageName(paName);
633 //=========================================================================
635 void wxGUIEditorGraphicBBS::SaveActualComplexBox(std::string filename) {
637 file.open(filename.c_str());
639 std::string content = "";
641 // writing file header
642 content += "# ----------------------------------\n";
643 content += "# - BBTKGEditor v 1.3 BBS BlackBox Script (Complex Box)\n";
647 content += "# ----------------------------------\n";
649 content += _tabsMgr->getActualComplexBoxBBS();
654 //=========================================================================
656 void wxGUIEditorGraphicBBS::OnSaveActualComplexBox(wxCommandEvent& event) {
657 wxFileDialog * saveFileDialog = new wxFileDialog(this,
658 wxT("Save Complex Box BBS"), wxEmptyString,
659 _T("ComplexBoxName"), wxT("*.bbs"), wxSAVE
660 | wxOVERWRITE_PROMPT);
661 if (saveFileDialog->ShowModal() == wxID_OK) {
662 wxString fileName = saveFileDialog->GetPath();
663 std::string filename = (const char*) (fileName.mb_str());
664 filename=CheckExtension (filename, ".bbs");
665 SaveActualComplexBox(filename);
669 //=========================================================================
670 void wxGUIEditorGraphicBBS::SaveActualDiagram(std::string filename) {
672 file.open(filename.c_str());
674 std::string content = "";
676 // writing file header
677 content += "# ----------------------------------\n";
678 content += "# - BBTKGEditor v 1.3 BBG BlackBox Diagram file\n";
684 content += "# ----------------------------------\n";
686 content += "APP_START\n";
687 _tabsMgr->saveActualDiagram(content, filename); //DFCH
688 content += "APP_END\n";
693 //=========================================================================
694 void wxGUIEditorGraphicBBS::SaveTempActualDiagram(const std::string &action)
698 std::string name = _tabsMgr->GetNameTabPanel();
699 if(name[name.length() - 1] != '*')
701 _tabsMgr->SetNameTabPanel(wxString (name.c_str(), wxConvUTF8));
702 _tabsMgr->saveTempActualDiagram(action);
703 GetToolBar()->EnableTool(ID_UNDO,_tabsMgr->getUndoState(stundo));
704 GetToolBar()->SetToolShortHelp(ID_UNDO,crea::std2wx(stundo));
705 GetToolBar()->EnableTool(ID_REDO,_tabsMgr->getRedoState(stredo));
706 GetToolBar()->SetToolShortHelp(ID_REDO,crea::std2wx(stredo));
709 //=========================================================================
711 //The following method allows to save the current diagram asking the filename
713 void wxGUIEditorGraphicBBS::SaveCurrentDiagramAs() {
714 wxFileDialog * saveFileDialog = new wxFileDialog(this,
715 wxT("Save current diagram"), wxEmptyString, wxT("NewDiagram"),
716 wxT("*.bbg"), wxSAVE | wxOVERWRITE_PROMPT);
717 if (saveFileDialog->ShowModal() == wxID_OK) {
718 //_tabsMgr->SetNameTabPanel(saveFileDialog->GetFilename());
719 wxString pathfileName = saveFileDialog->GetPath();
720 std::string pathfilename = (const char*) (pathfileName.mb_str());
721 pathfilename=CheckExtension (pathfilename, ".bbg");
723 //modify the tab name accordingly
724 wxString fileName = saveFileDialog->GetFilename();
725 std::string filename = (const char*) (fileName.mb_str());
726 filename=CheckExtension (filename, ".bbg");
727 _tabsMgr->SetNameTabPanel( wxString (filename.c_str(), wxConvUTF8) );
729 std::string pathfilenamebbs = pathfilename;
730 pathfilenamebbs[pathfilenamebbs.length() - 1] = 's';
731 if (_tabsMgr->isActualDiagramComplexBox() == false) {
732 SaveActualDiagram(pathfilename);
733 SaveActualBBS(pathfilenamebbs);
735 AskComplexBoxConfiguration();
736 SaveActualDiagram(pathfilename);
737 SaveActualComplexBox(pathfilenamebbs);
738 } //if isActualDiagramComplexBox
739 } // if saveFileDialog
741 //=========================================================================
743 void wxGUIEditorGraphicBBS::OnSaveActualDiagram(wxCommandEvent& event) {
744 std::string pathfilename = _tabsMgr->GetCurrentTabPanelPath();
745 if (pathfilename.empty()) {
746 SaveCurrentDiagramAs();
748 std::string pathfilenamebbs = pathfilename;
749 pathfilenamebbs[pathfilenamebbs.length() - 1] = 's';
751 if (_tabsMgr->isActualDiagramComplexBox() == false) {
752 std::string name = _tabsMgr->GetNameTabPanel();
753 if(name[name.length() - 1] == '*')
755 name =name.substr(0,name.length()-1);
757 _tabsMgr->SetNameTabPanel(wxString (name.c_str(), wxConvUTF8));
758 SaveActualDiagram(pathfilename);
759 SaveActualBBS(pathfilenamebbs);
761 AskComplexBoxConfiguration();
762 SaveActualDiagram(pathfilename);
763 SaveActualComplexBox(pathfilenamebbs);
764 } //if isActualDiagramComplexBox
767 //=========================================================================
769 void wxGUIEditorGraphicBBS::OnSaveAsActualDiagram(wxCommandEvent& event) {
770 SaveCurrentDiagramAs();
772 //=========================================================================
774 void wxGUIEditorGraphicBBS::refreshGUIControls() {
777 wxToolBar* toolbar = GetToolBar();
778 if (_tabsMgr->isActualDiagramComplexBox()) {
779 toolbar->ToggleTool(ID_BTNCOMPLEXBOX, true);
780 toolbar->EnableTool(ID_ADDCOMPLEXBOXINPUT, true);
781 toolbar->EnableTool(ID_ADDCOMPLEXBOXOUTPUT, true);
783 GetMenuBar()->GetMenu(0)->Enable(ID_SAVE_AS_COMPLEXBOX, true);
784 GetMenuBar()->GetMenu(0)->Enable(ID_SAVE_AS_BBS, false);
786 toolbar->ToggleTool(ID_BTNCOMPLEXBOX, false);
787 toolbar->EnableTool(ID_ADDCOMPLEXBOXINPUT, false);
788 toolbar->EnableTool(ID_ADDCOMPLEXBOXOUTPUT, false);
790 GetMenuBar()->GetMenu(0)->Enable(ID_SAVE_AS_COMPLEXBOX, false);
791 GetMenuBar()->GetMenu(0)->Enable(ID_SAVE_AS_BBS, true);
794 GetToolBar()->EnableTool(ID_UNDO,_tabsMgr->getUndoState(stundo));
795 GetToolBar()->SetToolShortHelp(ID_UNDO,crea::std2wx(stundo));
796 GetToolBar()->EnableTool(ID_REDO,_tabsMgr->getRedoState(stredo));
797 GetToolBar()->SetToolShortHelp(ID_REDO,crea::std2wx(stredo));
799 if (_tabsMgr->getNumActualSelectedObjects() > 0) {
800 GetMenuBar()->GetMenu(1)->Enable(ID_COPY_TO_COMPLEXDIAGRAM, true);
802 ///TODO Fix the possibility to say from the SceneManager to the GUI to refresh the options
803 GetMenuBar()->GetMenu(1)->Enable(ID_COPY_TO_COMPLEXDIAGRAM, true);
808 //=========================================================================
810 void wxGUIEditorGraphicBBS::OnDeleteAllBoxesActualDiagram(wxCommandEvent& event) {
811 wxMessageDialog *dial = new wxMessageDialog(NULL,
812 wxT("Are you sure to delete all boxes of the diagram?"),
813 wxT("Delete all boxes"), wxYES_NO | wxNO_DEFAULT
815 if (dial->ShowModal() == wxID_YES) {
816 _tabsMgr->deleteAllBoxesActualDiagram();
820 //=========================================================================
822 void wxGUIEditorGraphicBBS::OnCenterViewActualDiagram(wxCommandEvent& event) {
823 _tabsMgr->centerViewActualDiagram();
826 //=========================================================================
828 void wxGUIEditorGraphicBBS::OnOpenDiagram(wxCommandEvent& event) {
829 wxFileDialog * openFileDialog = new wxFileDialog(this, wxT("Open diagram"),
830 wxEmptyString, wxT(""), wxT("*.bbg"), wxOPEN | wxFILE_MUST_EXIST);
831 printf("SCP: wxGUIEditorGraphicBBS::OnOpenDiagram \n");
832 if (openFileDialog->ShowModal() == wxID_OK) {
833 wxString fileName = openFileDialog->GetPath();
834 ifstream inputStream;
835 std::string fName = (const char*) (fileName.mb_str());
837 inputStream.open(fName.c_str());
838 assert(inputStream.good()); // fails
839 _tabsMgr->addNewTab(openFileDialog->GetFilename());
840 _tabsMgr->loadDiagram(inputStream, fName);
841 _tabsMgr->saveTempActualDiagram("load diagram");
842 GetToolBar()->EnableTool(ID_UNDO, false);
843 GetToolBar()->EnableTool(ID_UNDO, false);
846 refreshGUIControls();
849 //=========================================================================
852 void wxGUIEditorGraphicBBS::OnClickBtnBox(wxCommandEvent& event) {
853 BlackBoxDescriptor *bbDes = _pkgBrowser->GetActualSelected();
855 std::string typeName = bbDes->GetTypeName();
856 std::string packageName = bbDes->GetPackage()->GetName();
858 wxGEditorTabPanel *pnl = this->_tabsMgr->getActualTabPanel();
862 wxVtkSceneManager *scn = pnl->getSceneManager();
863 scn->createGBlackBox(50, 50, packageName, typeName);
867 SaveTempActualDiagram("New Box");
872 //=========================================================================
874 void wxGUIEditorGraphicBBS::OnClickBtnExecutableBox(wxCommandEvent& event) {
876 wxGEditorTabPanel *pnl = this->_tabsMgr->getActualTabPanel();
879 wxVtkSceneManager *scn = pnl->getSceneManager();
880 if( scn->MakeBoxExecutable() )
881 std::cout<<"DFCH: wxGUIEditorGraphicBBS::OnClickBtnExecutableBox...successful"<<std::endl;
883 std::cout<<"DFCH: wxGUIEditorGraphicBBS::OnClickBtnExecutableBox...Error!!"<<std::endl;
889 //=========================================================================
891 void wxGUIEditorGraphicBBS::OnClickBtnComplexBox(wxCommandEvent& event) {
892 wxToolBar* toolbar = GetToolBar();
893 bool temp = toolbar->GetToolState(ID_BTNCOMPLEXBOX);
895 _tabsMgr->setActualDiagramComplexBox(true);
897 _tabsMgr->setActualDiagramComplexBox(false);
899 refreshGUIControls();
902 //=========================================================================
904 void wxGUIEditorGraphicBBS::OnAddComplexBoxInput(wxCommandEvent& event) {
905 wxTextEntryDialog *nameDialog = new wxTextEntryDialog(this,
906 wxT("Name of input port"));
907 if (nameDialog->ShowModal() == wxID_OK) {
908 wxString fileName = nameDialog->GetValue();
909 if (!fileName.IsEmpty()) {
910 std::string portName = (const char*) (fileName.mb_str());
911 _tabsMgr->addActualDiagramComplexInputPort(portName);
916 //=========================================================================
918 void wxGUIEditorGraphicBBS::OnAddComplexBoxOutput(wxCommandEvent& event) {
919 wxTextEntryDialog *nameDialog = new wxTextEntryDialog(this,
920 wxT("Name of output port"));
921 if (nameDialog->ShowModal() == wxID_OK) {
922 wxString fileName = nameDialog->GetValue();
923 if (!fileName.IsEmpty()) {
924 std::string portName = (const char*) (fileName.mb_str());
925 _tabsMgr->addActualDiagramComplexOutputPort(portName);
930 //=========================================================================
932 void wxGUIEditorGraphicBBS::OnCopySelectedToComplexDiagram(
933 wxCommandEvent& event) {
934 _tabsMgr->copySelectedBBoxesToComplexDiagram();
937 void wxGUIEditorGraphicBBS::OnHelpBBeditor(wxCommandEvent& event) {
938 printf("wxGUIEditorGraphicBBS::OnHelpBBeditor ....not implemented..\n");
941 //=========================================================================
942 void wxGUIEditorGraphicBBS::OnCreatePackage(wxCommandEvent& event) {
944 bbtkSystemTools::CreatePackage();
947 //=========================================================================
948 void wxGUIEditorGraphicBBS::OnCreateBlackBox(wxCommandEvent& event) {
949 bbtkSystemTools::CreateBlackBox();
951 //=========================================================================
952 void wxGUIEditorGraphicBBS::OnPlugPackage(wxCommandEvent& event) {
953 //printf("EED wxGUIEditorGraphicBBS::OnPlugPackage ... not implemented ..\n");
954 //this is the right code but it's left to include the corresponding commented libraries
955 long style = wxDD_DEFAULT_STYLE | wxDD_DIR_MUST_EXIST;
958 _T("Select package directory"),
964 userResponse = FD->ShowModal();
965 if(userResponse==wxID_OK)
967 std::string path = wx2std (FD->GetPath()) ;
968 std::string fname = path + "/bbtkPackage";
969 std::cout << "Path chosen = \"" << FD->GetPath() << "\"" << std::endl;
970 if ( Utilities::FileExists( fname ) )
973 f.open(fname.c_str());
978 bbtk::ConfigurationFile::GetInstance().AddPackagePathsAndWrite( path );
980 DoRegeneratePackageDoc(pname);
981 DoRegenerateBoxesLists();
983 _pkgBrowser->RebuildList();
985 wxMessageBox(_T("Package successfully plugged. Please restart bbEditor to see the new package in the package browser."),_T("Plug package"),wxOK | wxICON_INFORMATION);
986 userResponse = wxID_CANCEL;
990 std::string err = "The directory \"" + path + "\" does not contain a 'bbtkPackage' file.";
993 err += "\nNote: If you are on Linux please select the folder and click \"Open\", don't enter in it.";
998 wxMessageBox(_T(err),_T("Plug package"),wxOK | wxICON_ERROR);
1001 }while(userResponse != wxID_CANCEL);
1004 //=========================================================================
1005 void wxGUIEditorGraphicBBS::OnEditConfig(wxCommandEvent& event) {
1006 printf("EED wxGUIEditorGraphicBBS::OnEditConfig ... not implemented ..\n");
1008 //=========================================================================
1010 void wxGUIEditorGraphicBBS::OnShowHTMLDoc(wxCommandEvent& event) {
1012 if (_helpHtmlBrowser != NULL){
1013 _frameAUIMgr->DetachPane(_helpHtmlBrowser);
1014 _helpHtmlBrowser->Destroy();
1016 initHelpHTMLBrowser();
1017 _frameAUIMgr->AddPane(_helpHtmlBrowser, wxAuiPaneInfo().Right().MinSize(200, 200));
1018 _frameAUIMgr->Update();
1019 refreshGUIControls();
1023 //=========================================================================
1024 void wxGUIEditorGraphicBBS::OnCreateIndex(wxCommandEvent& event) {
1025 printf("EED wxGUIEditorGraphicBBS::OnCreateIndex ... not implemented ..\n");
1028 //=========================================================================
1030 void wxGUIEditorGraphicBBS::OnExit(wxCommandEvent& event) {
1036 //=========================================================================
1038 } // EO namespace bbtk