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 wxBitmap bmp_editProperties(editProperties_xpm);
114 wxToolBar *toolbar = new wxToolBar(this, wxID_ANY);
116 //Adds a tool btn to the toolbar
117 toolbar->AddTool(ID_NEW, _T("New"), bmp_new, wxNullBitmap, wxITEM_NORMAL,
118 _T("New tab"), _T("Create a new panel tab"));
119 toolbar->AddTool(ID_OPEN, _T("Open diagram"), bmp_open, wxNullBitmap,
120 wxITEM_NORMAL, _T("Open a diagram"), _T("Open a diagram"));
121 toolbar->AddTool(ID_SAVE_DIAGRAM, _T("Save Diagram"), bmp_save,
122 wxNullBitmap, wxITEM_NORMAL, _T("Saves the current diagram"),
123 _T("Saves the current diagram")); //DFCH
124 //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
125 toolbar->AddTool(ID_RUN, _T("Run"), bmp_run, wxNullBitmap, wxITEM_NORMAL,
126 _T("Execute actual diagram"), _T("Execute actual diagram"));
127 toolbar->AddTool(ID_DELETEALL, _T("Delete all"), bmp_delete, wxNullBitmap,
128 wxITEM_NORMAL, _T("Delete all boxes"), _T("Delete all boxes"));
129 toolbar->AddTool(ID_CENTERVIEW, _T("Center view"), bmp_centerview,
130 wxNullBitmap, wxITEM_NORMAL, _T("Center view"), _T("Center view"));
131 toolbar->AddSeparator();
132 toolbar->AddTool(ID_BTNBOX, _T("New Box"), bmp_box, wxNullBitmap,
133 wxITEM_NORMAL, _T("New Box"), _T("Nex Box"));
134 toolbar->AddSeparator();
135 toolbar->AddTool(ID_BTEXECUTABLEBOX, _T("Select as executable Box"),
136 bmp_executablebox, wxNullBitmap, wxITEM_NORMAL,
137 _T("Select as executable Box"), _T("Select as executable Box"));
138 toolbar->AddSeparator();
139 toolbar->AddTool(ID_BTNCOMPLEXBOX, _T("Complex box"), complexbox_xpm,
140 wxNullBitmap, wxITEM_NORMAL, _T("Complex box"), _T("Complex box"));
141 toolbar->SetToggle(ID_BTNCOMPLEXBOX, true);
142 toolbar->AddTool(ID_ADDCOMPLEXBOXINPUT, _T("Add input to Complex box"),
143 bmp_complexinputport, wxNullBitmap, wxITEM_NORMAL,
144 _T("Add input to Complex box"), _T("Add input to Complex box"));
145 toolbar->AddTool(ID_ADDCOMPLEXBOXOUTPUT, _T("Add output to Complex box"),
146 bmp_complexoutputport, wxNullBitmap, wxITEM_NORMAL,
147 _T("Add output Complex box"), _T("Add output Complex box"));
148 toolbar->EnableTool(ID_ADDCOMPLEXBOXINPUT, false);
149 toolbar->EnableTool(ID_ADDCOMPLEXBOXOUTPUT, false);
150 toolbar->AddSeparator();
151 toolbar->AddTool(ID_UNDO, _T("Undo"),bmp_undo, wxNullBitmap, wxITEM_NORMAL, _T("Undo"), _T("Undo"));
152 toolbar->AddTool(ID_REDO, _T("Redo"),bmp_redo, wxNullBitmap, wxITEM_NORMAL, _T("Redo"), _T("Redo"));
153 toolbar->AddSeparator();
154 toolbar->AddTool(ID_EDIT, _T("Edit diagram properties"),bmp_editProperties, wxNullBitmap, wxITEM_NORMAL, _T("Edit diagram properties"), _T("Edit diagram properties"));
156 toolbar->EnableTool(ID_UNDO, false);
157 toolbar->EnableTool(ID_REDO, false);
158 toolbar->SetMargins(2, 2);
163 // connect command event handlers
165 Connect(ID_NEW, wxEVT_COMMAND_TOOL_CLICKED,
166 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnCreateNewTab));
167 Connect(ID_OPEN, wxEVT_COMMAND_TOOL_CLICKED,
168 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnOpenDiagram));
169 Connect(ID_SAVE_DIAGRAM, wxEVT_COMMAND_TOOL_CLICKED,
170 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnSaveActualDiagram)); //DFCH
171 Connect(ID_SAVE_AS_DIAGRAM, wxEVT_COMMAND_TOOL_CLICKED,
172 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnSaveAsActualDiagram)); //DFCH
175 wxEVT_COMMAND_TOOL_CLICKED,
176 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnExecuteActualDiagram));
179 wxEVT_COMMAND_TOOL_CLICKED,
180 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnDeleteAllBoxesActualDiagram));
183 wxEVT_COMMAND_TOOL_CLICKED,
184 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnCenterViewActualDiagram));
185 Connect(ID_BTNBOX, wxEVT_COMMAND_TOOL_CLICKED,
186 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnClickBtnBox));
189 wxEVT_COMMAND_TOOL_CLICKED,
190 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnClickBtnExecutableBox));
191 Connect(ID_BTNCOMPLEXBOX, wxEVT_COMMAND_TOOL_CLICKED,
192 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnClickBtnComplexBox));
193 Connect(ID_ADDCOMPLEXBOXINPUT, wxEVT_COMMAND_TOOL_CLICKED,
194 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnAddComplexBoxInput));
195 Connect(ID_ADDCOMPLEXBOXOUTPUT, wxEVT_COMMAND_TOOL_CLICKED,
196 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnAddComplexBoxOutput));
197 Connect(ID_UNDO,wxEVT_COMMAND_TOOL_CLICKED, wxCommandEventHandler(wxGUIEditorGraphicBBS::OnUndo));
198 Connect(ID_REDO,wxEVT_COMMAND_TOOL_CLICKED, wxCommandEventHandler(wxGUIEditorGraphicBBS::OnRedo));
199 Connect(ID_CHANGENAME, wxEVT_COMMAND_RIGHT_CLICK, wxCommandEventHandler(wxGUIEditorGraphicBBS::OnChangeName));
200 Connect(ID_EDIT,wxEVT_COMMAND_TOOL_CLICKED, wxCommandEventHandler(wxGUIEditorGraphicBBS::OnEditDiagramProperties));
203 //=========================================================================
204 void wxGUIEditorGraphicBBS::initHelpHTMLBrowser() {
206 _helpHtmlBrowser = new WxGUIHtmlBrowser(this, wxSize(200, 0));
212 //=========================================================================
213 void wxGUIEditorGraphicBBS::initMenu() {
214 // Create File menu and its items
215 wxMenu *fileMenu = new wxMenu();
216 fileMenu->Append(ID_NEW, _T("New diagram"), _T("New"));
217 fileMenu->Append(ID_SAVE_DIAGRAM, _T("Save Diagram"), _T("Save Diagram")); //DFCH
218 fileMenu->Append(ID_SAVE_AS_DIAGRAM, _T("Save Diagram As"),
219 _T("Save Diagram As")); //DFCH
220 fileMenu->Append(ID_OPEN_BBS, _T("Open BBS"), _T("Open BBS"));
222 fileMenu->Append(ID_OPEN, _T("Open a diagram"), _T("Open a diagram"));
223 fileMenu->Append(ID_SAVE_AS_BBS, _T("Save BBS"), _T("Save BBS"));
224 fileMenu->Append(ID_SAVE_AS_COMPLEXBOX, _T("Save complex box"),
225 _T("Save complex box"));
226 fileMenu->Append(wxID_EXIT, _T("E&xit"), _T("Exit"));
228 Connect(ID_NEW, wxEVT_COMMAND_MENU_SELECTED,
229 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnCreateNewTab));
230 Connect(ID_SAVE_DIAGRAM, wxEVT_COMMAND_MENU_SELECTED,
231 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnSaveActualDiagram)); //DFCH
232 Connect(ID_SAVE_AS_DIAGRAM, wxEVT_COMMAND_MENU_SELECTED,
233 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnSaveAsActualDiagram));
234 Connect(ID_OPEN_BBS, wxEVT_COMMAND_MENU_SELECTED,
235 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnOpenBBS));
236 Connect(ID_SAVE_AS_BBS, wxEVT_COMMAND_MENU_SELECTED,
237 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnSaveActualBBS));
239 ID_SAVE_AS_COMPLEXBOX,
240 wxEVT_COMMAND_MENU_SELECTED,
241 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnSaveActualComplexBox));
242 Connect(wxID_EXIT, wxEVT_COMMAND_MENU_SELECTED,
243 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnExit));
245 // Create Help menu and its items
246 wxMenu *editMenu = new wxMenu;
247 editMenu->Append(ID_COPY_TO_COMPLEXDIAGRAM,
248 _T("Copy selected to complex box"),
249 _T("Creates a new complex box diagram with selected boxes"));
252 ID_COPY_TO_COMPLEXDIAGRAM,
253 wxEVT_COMMAND_MENU_SELECTED,
254 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnCopySelectedToComplexDiagram));
256 // Create Help menu and its items
257 wxMenu *helpMenu = new wxMenu;
258 helpMenu->Append(wxID_ABOUT, _T("&About..."), _T("About"));
259 helpMenu->Append(ID_HELP_BBEDITOR, _T("&Help..."), _T("Help"));
260 Connect(ID_HELP_BBEDITOR, wxEVT_COMMAND_MENU_SELECTED,
261 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnHelpBBeditor));
264 wxMenu *menuTools = new wxMenu;
265 menuTools->Append(ID_bbEditor_Tool_Menu_CreatePackage,
266 _T("Create &package") );
267 menuTools->Append(ID_bbEditor_Tool_Menu_CreateBlackBox,
268 _T("Create &blackbox") );
269 menuTools->Append(ID_bbEditor_Tool_Menu_PlugPackage, _T("Plug package") );
270 menuTools->Append(ID_bbEditor_Tool_Menu_EditConfig, _T("&Edit bbtk config") );
271 menuTools->Append(ID_bbEditor_Tool_Menu_ShowHTMLDoc,
272 _T("Show &HTML documentation") );
273 menuTools->Append(ID_bbEditor_Tool_Menu_CreateIndex, _T("&Generate index") );
275 Connect(ID_bbEditor_Tool_Menu_CreatePackage, wxEVT_COMMAND_MENU_SELECTED,
276 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnCreatePackage));
277 Connect(ID_bbEditor_Tool_Menu_CreateBlackBox, wxEVT_COMMAND_MENU_SELECTED,
278 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnCreateBlackBox));
279 Connect(ID_bbEditor_Tool_Menu_PlugPackage, wxEVT_COMMAND_MENU_SELECTED,
280 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnPlugPackage));
281 Connect(ID_bbEditor_Tool_Menu_EditConfig, wxEVT_COMMAND_MENU_SELECTED,
282 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnEditConfig));
283 Connect(ID_bbEditor_Tool_Menu_ShowHTMLDoc, wxEVT_COMMAND_MENU_SELECTED,
284 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnShowHTMLDoc));
285 Connect(ID_bbEditor_Tool_Menu_CreateIndex, wxEVT_COMMAND_MENU_SELECTED,
286 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnCreateIndex));
288 // Append the created menu to the menu bar
289 wxMenuBar *menuBar = new wxMenuBar();
290 menuBar->Append(fileMenu, _T("&File") );
291 menuBar->Append(editMenu, _T("&Edit") );
292 menuBar->Append(menuTools, _T("&Tool") );
293 menuBar->Append(helpMenu, _T("&Help") );
295 // Attach this menu bar to the frame
299 //=========================================================================
300 void wxGUIEditorGraphicBBS::initTabPanelsManager()
302 _notebook = new wxAuiNotebook(this, wxID_NOTEBOOK, wxDefaultPosition,
303 wxDefaultSize, wxAUI_NB_TOP | wxAUI_NB_TAB_MOVE
304 | wxAUI_NB_CLOSE_ON_ACTIVE_TAB | wxAUI_NB_TAB_FIXED_WIDTH
305 | wxAUI_NB_WINDOWLIST_BUTTON);
306 _tabsMgr = new wxTabPanelsManager(this);
307 _frameAUIMgr->AddPane(_notebook, wxAuiPaneInfo().CenterPane());
310 //=========================================================================
311 void wxGUIEditorGraphicBBS::initPackageBrowser()
313 _pkgBrowser = new WxGUIPackageBrowser2(this);
314 _pkgBrowser->IncludeAll();
315 _frameAUIMgr->AddPane(_pkgBrowser, wxAuiPaneInfo().Left().MinSize(30, 500).BestSize(750,500).CloseButton(false));
318 //================================================================
320 void wxGUIEditorGraphicBBS::DoRegeneratePackageDoc(const std::string& pack)
322 std::string mess("Regenerating doc for package '");
326 mess = "Regenerating doc for all packages";
329 mess += " ... please wait";
331 SetStatusText(std2wx(mess));
339 command += ConfigurationFile::GetInstance().Get_bin_path();
340 command += ConfigurationFile::GetInstance().Get_file_separator();
341 command += "bbRegeneratePackageDoc";
346 command += " " + pack + " -q";
347 bbtkMessage("debug",1,"Executing system command '"<<command<<"'"<<std::endl);
349 if (!system(command.c_str())) {
350 SetStatusText(_T("Done !"));
352 wxMessageBox(_T("Done !"),_T("Regenerate package '")
353 +std2wx(pack)+_T("' doc"),
354 wxOK | wxICON_INFORMATION);
357 SetStatusText(_T("Done !"));
358 wxString err(_T("An error occured while running '"));
359 err += bbtk::std2wx(command) + _T("'");
360 wxMessageBox(err, _T("Regenerate package doc"), wxOK | wxICON_ERROR);
364 //================================================================
365 void wxGUIEditorGraphicBBS::DoRegenerateBoxesLists() {
366 SetStatusText(_T("Regenerating boxes lists ... please wait"));
373 command += ConfigurationFile::GetInstance().Get_bin_path();
374 command += ConfigurationFile::GetInstance().Get_file_separator();
375 command += "bbRegenerateBoxesLists";
382 bbtkMessage("debug",1,"Executing system command '"<<command<<"'"<<std::endl);
384 if (!system(command.c_str())) {
385 SetStatusText(_T("Done !"));
387 wxMessageBox(_T("Done !"),_T("Regenerate boxes lists"),
388 wxOK | wxICON_INFORMATION);
391 SetStatusText(_T("Done !"));
392 wxString err(_T("An error occured while running '"));
393 err += bbtk::std2wx(command) + _T("'");
394 wxMessageBox(err, _T("Regenerate boxes lists"), wxOK | wxICON_ERROR);
398 //================================================================
399 void wxGUIEditorGraphicBBS::RegenerateAll() {
400 DoRegeneratePackageDoc("-a");
401 DoRegenerateBoxesLists();
404 //================================================================
406 wxAuiNotebook* wxGUIEditorGraphicBBS::getAuiNotebook() {
410 //================================================================
412 void wxGUIEditorGraphicBBS::displayBlackBoxInfo(std::string packageName,
413 std::string boxName) {
414 if (_actualPkgBrowserPkgName != packageName || _actualPkgBrowserBoxName
416 _actualPkgBrowserPkgName = packageName;
417 _actualPkgBrowserBoxName = boxName;
419 BlackBoxDescriptor::Pointer descriptor =
420 GObjectsMVCFactory::getInstance()->getBlackBoxDescriptor(
421 packageName, boxName);
422 _pkgBrowser->WxGUIBlackBoxListUserOnSelected(descriptor.get());
426 //=========================================================================
428 void wxGUIEditorGraphicBBS::editBlackBox(GBlackBoxModel *bbmodel) {
429 wxBlackBoxEditionDialog* dialog =
430 new wxBlackBoxEditionDialog(this, bbmodel);
434 //=========================================================================
436 bool wxGUIEditorGraphicBBS::boxNameExists(std::string boxname) {
438 return this->_tabsMgr->getActualTabPanel()->getSceneManager()->boxExist(boxname);
441 //=========================================================================
443 void wxGUIEditorGraphicBBS::updateStatusBar(std::string textStatus) {
444 SetStatusText(crea::std2wx(textStatus));
447 //=========================================================================
449 void wxGUIEditorGraphicBBS::executeScript(std::string script) {
450 std::string separator =
451 ConfigurationFile::GetInstance().Get_file_separator();
452 std::string dir = ConfigurationFile::GetInstance().Get_default_temp_dir();
453 std::string filename = dir + separator + "tmp_bbtk.bbs";
456 tempFile.open(filename.c_str());
460 std::string command = "";
463 command += "start /b ";
466 // command += "\""+ crea::System::GetExecutablePath();
468 // command += separator + "../../../bbi.app/Contents/MacOS";
472 command += "\"" + filename + "\"";
478 printf("RaC wxGUIEditorGraphicBBS::executeScript %s \n", command.c_str());
479 system(command.c_str());
482 //=========================================================================
483 std::string wxGUIEditorGraphicBBS::CheckExtension(std::string filename, std::string extension) {
484 if(filename.size() > extension.size() ){
485 if( (filename.compare(filename.size()-extension.size(), extension.size(),extension)) !=0 ){
486 filename.append(extension);
489 filename.append(extension);
493 //=========================================================================
495 //=========================================================================
497 void wxGUIEditorGraphicBBS::OnCreateNewTab(wxCommandEvent& event) {
498 _tabsMgr->addNewTab();
499 refreshGUIControls();
502 void wxGUIEditorGraphicBBS::OnUndo(wxCommandEvent& event) {
503 unsigned short disable;
507 _tabsMgr->loadTempDiagram(0);
508 disable = _tabsMgr->getUndoState(stundo);
511 std::string name = _tabsMgr->GetNameTabPanel();
512 if(name[name.length() - 1] == '*')
514 name =name.substr(0,name.length()-1);
516 _tabsMgr->SetNameTabPanel(wxString (name.c_str(), wxConvUTF8));
519 GetToolBar()->EnableTool(ID_UNDO,disable);
520 GetToolBar()->SetToolShortHelp(ID_UNDO,crea::std2wx(stundo));
521 GetToolBar()->EnableTool(ID_REDO,_tabsMgr->getRedoState(stredo));
522 GetToolBar()->SetToolShortHelp(ID_REDO,crea::std2wx(stredo));
523 refreshGUIControls();
526 //=========================================================================
528 void wxGUIEditorGraphicBBS::OnRedo(wxCommandEvent& event) {
529 unsigned short disable;
533 _tabsMgr->loadTempDiagram(1);
534 std::string name = _tabsMgr->GetNameTabPanel();
535 if(name[name.length() - 1] != '*')
537 _tabsMgr->SetNameTabPanel(wxString (name.c_str(), wxConvUTF8));
538 GetToolBar()->EnableTool(ID_UNDO,_tabsMgr->getUndoState(stundo));
539 GetToolBar()->SetToolShortHelp(ID_UNDO,crea::std2wx(stundo));
540 GetToolBar()->EnableTool(ID_REDO,_tabsMgr->getRedoState(stredo));
541 GetToolBar()->SetToolShortHelp(ID_REDO,crea::std2wx(stredo));
542 refreshGUIControls();
545 void wxGUIEditorGraphicBBS::OnChangeName(wxCommandEvent& event){
548 //=========================================================================
550 void wxGUIEditorGraphicBBS::OnEditDiagramProperties(wxCommandEvent& event)
552 wxDiagramPropertiesEditionDialog* dialog =
553 new wxDiagramPropertiesEditionDialog(this);
557 //=========================================================================
559 void wxGUIEditorGraphicBBS::OnExecuteActualDiagram(wxCommandEvent& event) {
560 std::string script1 = _tabsMgr->getActualDiagramBBS(true);
561 cout << endl << "RaC wxGUIEditorGraphicBBS::executeActualDiagram SCRIPT"
563 cout << script1 << endl;
565 std::string script2 = _tabsMgr->getActualDiagramBBS(false);
566 executeScript(script2);
569 //=========================================================================
571 //=========================================================================
572 void wxGUIEditorGraphicBBS::OnOpenBBS(wxCommandEvent& event) {
573 wxFileDialog * openFileDialog = new wxFileDialog(this, wxT("Open BBS"),
574 wxEmptyString, wxT("NewBBS"), wxT("*.bbs"), wxOPEN);
575 if (openFileDialog->ShowModal() == wxID_OK) {
576 wxString fileName = openFileDialog->GetPath();
578 _tabsMgr->addNewTab(openFileDialog->GetFilename());
580 bbtk::InterpreterBBS::Pointer I = bbtk::InterpreterBBS::New(
581 this->_tabsMgr->getActualTabPanel()->getSceneManager(),
582 _pkgBrowser->GetFactory());
584 // We tell the interpreter to throw exceptions on error
586 // Interpret the file supposed to define a box called 'Processing'
587 I->InterpretFile((const char*) (fileName.mb_str()));
589 refreshGUIControls();
592 void wxGUIEditorGraphicBBS::SaveActualBBS(std::string filename) {
595 //EED file.open(fileName.c_str());
596 file.open(filename.c_str());
597 std::string content = "";
598 // writing file header
599 content += "# ----------------------------------\n";
600 content += "# - BBTKGEditor v 1.3 BBS BlackBox Script\n";
604 content += "# ----------------------------------\n";
606 content += _tabsMgr->getActualDiagramBBS();
611 void wxGUIEditorGraphicBBS::OnSaveActualBBS(wxCommandEvent& event) {
612 wxFileDialog * saveFileDialog = new wxFileDialog(this,
613 wxT("Save actual BBS"), wxEmptyString, wxT("NewBBS"),
614 wxT("*.bbs"), wxSAVE | wxOVERWRITE_PROMPT);
615 if (saveFileDialog->ShowModal() == wxID_OK) {
616 wxString fileName = saveFileDialog->GetPath();
617 std::string filename = (const char*) (fileName.mb_str());
618 filename=CheckExtension (filename, ".bbs");
619 SaveActualBBS(filename);
624 void wxGUIEditorGraphicBBS::AskComplexBoxConfiguration() {
625 std::string cbName = _tabsMgr->GetCbName();
626 std::string paName = _tabsMgr->GetCbPackageName();
628 wxTextEntryDialog *cbNameDialog = new wxTextEntryDialog(this,
629 wxT("Complex Box name"));
630 wxTextEntryDialog *paNameDialog = new wxTextEntryDialog(this,
631 wxT("Package name"));
633 cbNameDialog->SetValue(wxString(cbName.c_str(), wxConvUTF8));
634 paNameDialog->SetValue(wxString(paName.c_str(), wxConvUTF8));
636 if (cbNameDialog->ShowModal() == wxID_OK) {
637 wxString complexboxname = cbNameDialog->GetValue();
638 cbName = (const char*) (complexboxname.mb_str());
641 if (paNameDialog->ShowModal() == wxID_OK) {
642 wxString packagename = paNameDialog->GetValue();
643 paName = (const char*) (packagename.mb_str());
646 _tabsMgr->SetCbName(cbName);
647 _tabsMgr->SetCbPackageName(paName);
650 //=========================================================================
652 void wxGUIEditorGraphicBBS::SaveActualComplexBox(std::string filename) {
654 file.open(filename.c_str());
656 std::string content = "";
658 // writing file header
659 content += "# ----------------------------------\n";
660 content += "# - BBTKGEditor v 1.3 BBS BlackBox Script (Complex Box)\n";
664 content += "# ----------------------------------\n";
666 content += _tabsMgr->getActualComplexBoxBBS();
671 //=========================================================================
673 void wxGUIEditorGraphicBBS::OnSaveActualComplexBox(wxCommandEvent& event) {
674 wxFileDialog * saveFileDialog = new wxFileDialog(this,
675 wxT("Save Complex Box BBS"), wxEmptyString,
676 _T("ComplexBoxName"), wxT("*.bbs"), wxSAVE
677 | wxOVERWRITE_PROMPT);
678 if (saveFileDialog->ShowModal() == wxID_OK) {
679 wxString fileName = saveFileDialog->GetPath();
680 std::string filename = (const char*) (fileName.mb_str());
681 filename=CheckExtension (filename, ".bbs");
682 SaveActualComplexBox(filename);
686 //=========================================================================
687 void wxGUIEditorGraphicBBS::SaveActualDiagram(std::string filename) {
689 file.open(filename.c_str());
691 std::string content = "";
693 // writing file header
694 content += "# ----------------------------------\n";
695 content += "# - BBTKGEditor v 1.3 BBG BlackBox Diagram file\n";
701 content += "# ----------------------------------\n";
703 content += "APP_START\n";
704 _tabsMgr->saveActualDiagram(content, filename); //DFCH
705 content += "APP_END\n";
710 //=========================================================================
711 void wxGUIEditorGraphicBBS::SaveTempActualDiagram(const std::string &action)
715 std::string name = _tabsMgr->GetNameTabPanel();
716 if(name[name.length() - 1] != '*')
718 _tabsMgr->SetNameTabPanel(wxString (name.c_str(), wxConvUTF8));
719 _tabsMgr->saveTempActualDiagram(action);
720 GetToolBar()->EnableTool(ID_UNDO,_tabsMgr->getUndoState(stundo));
721 GetToolBar()->SetToolShortHelp(ID_UNDO,crea::std2wx(stundo));
722 GetToolBar()->EnableTool(ID_REDO,_tabsMgr->getRedoState(stredo));
723 GetToolBar()->SetToolShortHelp(ID_REDO,crea::std2wx(stredo));
726 //=========================================================================
728 //The following method allows to save the current diagram asking the filename
730 void wxGUIEditorGraphicBBS::SaveCurrentDiagramAs() {
731 wxFileDialog * saveFileDialog = new wxFileDialog(this,
732 wxT("Save current diagram"), wxEmptyString, wxT("NewDiagram"),
733 wxT("*.bbg"), wxSAVE | wxOVERWRITE_PROMPT);
734 if (saveFileDialog->ShowModal() == wxID_OK) {
735 //_tabsMgr->SetNameTabPanel(saveFileDialog->GetFilename());
736 wxString pathfileName = saveFileDialog->GetPath();
737 std::string pathfilename = (const char*) (pathfileName.mb_str());
738 pathfilename=CheckExtension (pathfilename, ".bbg");
740 //modify the tab name accordingly
741 wxString fileName = saveFileDialog->GetFilename();
742 std::string filename = (const char*) (fileName.mb_str());
743 filename=CheckExtension (filename, ".bbg");
744 _tabsMgr->SetNameTabPanel( wxString (filename.c_str(), wxConvUTF8) );
746 std::string pathfilenamebbs = pathfilename;
747 pathfilenamebbs[pathfilenamebbs.length() - 1] = 's';
748 if (_tabsMgr->isActualDiagramComplexBox() == false) {
749 SaveActualDiagram(pathfilename);
750 SaveActualBBS(pathfilenamebbs);
752 AskComplexBoxConfiguration();
753 SaveActualDiagram(pathfilename);
754 SaveActualComplexBox(pathfilenamebbs);
755 } //if isActualDiagramComplexBox
756 } // if saveFileDialog
758 //=========================================================================
760 void wxGUIEditorGraphicBBS::OnSaveActualDiagram(wxCommandEvent& event) {
761 std::string pathfilename = _tabsMgr->GetCurrentTabPanelPath();
762 if (pathfilename.empty()) {
763 SaveCurrentDiagramAs();
765 std::string pathfilenamebbs = pathfilename;
766 pathfilenamebbs[pathfilenamebbs.length() - 1] = 's';
768 if (_tabsMgr->isActualDiagramComplexBox() == false) {
769 std::string name = _tabsMgr->GetNameTabPanel();
770 if(name[name.length() - 1] == '*')
772 name =name.substr(0,name.length()-1);
774 _tabsMgr->SetNameTabPanel(wxString (name.c_str(), wxConvUTF8));
775 SaveActualDiagram(pathfilename);
776 SaveActualBBS(pathfilenamebbs);
778 AskComplexBoxConfiguration();
779 SaveActualDiagram(pathfilename);
780 SaveActualComplexBox(pathfilenamebbs);
781 } //if isActualDiagramComplexBox
784 //=========================================================================
786 void wxGUIEditorGraphicBBS::OnSaveAsActualDiagram(wxCommandEvent& event) {
787 SaveCurrentDiagramAs();
789 //=========================================================================
791 void wxGUIEditorGraphicBBS::refreshGUIControls() {
794 wxToolBar* toolbar = GetToolBar();
795 if (_tabsMgr->isActualDiagramComplexBox()) {
796 toolbar->ToggleTool(ID_BTNCOMPLEXBOX, true);
797 toolbar->EnableTool(ID_ADDCOMPLEXBOXINPUT, true);
798 toolbar->EnableTool(ID_ADDCOMPLEXBOXOUTPUT, true);
800 GetMenuBar()->GetMenu(0)->Enable(ID_SAVE_AS_COMPLEXBOX, true);
801 GetMenuBar()->GetMenu(0)->Enable(ID_SAVE_AS_BBS, false);
803 toolbar->ToggleTool(ID_BTNCOMPLEXBOX, false);
804 toolbar->EnableTool(ID_ADDCOMPLEXBOXINPUT, false);
805 toolbar->EnableTool(ID_ADDCOMPLEXBOXOUTPUT, false);
807 GetMenuBar()->GetMenu(0)->Enable(ID_SAVE_AS_COMPLEXBOX, false);
808 GetMenuBar()->GetMenu(0)->Enable(ID_SAVE_AS_BBS, true);
811 GetToolBar()->EnableTool(ID_UNDO,_tabsMgr->getUndoState(stundo));
812 GetToolBar()->SetToolShortHelp(ID_UNDO,crea::std2wx(stundo));
813 GetToolBar()->EnableTool(ID_REDO,_tabsMgr->getRedoState(stredo));
814 GetToolBar()->SetToolShortHelp(ID_REDO,crea::std2wx(stredo));
816 if (_tabsMgr->getNumActualSelectedObjects() > 0) {
817 GetMenuBar()->GetMenu(1)->Enable(ID_COPY_TO_COMPLEXDIAGRAM, true);
819 ///TODO Fix the possibility to say from the SceneManager to the GUI to refresh the options
820 GetMenuBar()->GetMenu(1)->Enable(ID_COPY_TO_COMPLEXDIAGRAM, true);
825 //=========================================================================
827 void wxGUIEditorGraphicBBS::OnDeleteAllBoxesActualDiagram(wxCommandEvent& event) {
828 wxMessageDialog *dial = new wxMessageDialog(NULL,
829 wxT("Are you sure to delete all boxes of the diagram?"),
830 wxT("Delete all boxes"), wxYES_NO | wxNO_DEFAULT
832 if (dial->ShowModal() == wxID_YES) {
833 _tabsMgr->deleteAllBoxesActualDiagram();
837 //=========================================================================
839 void wxGUIEditorGraphicBBS::OnCenterViewActualDiagram(wxCommandEvent& event) {
840 _tabsMgr->centerViewActualDiagram();
843 //=========================================================================
845 void wxGUIEditorGraphicBBS::OnOpenDiagram(wxCommandEvent& event) {
846 wxFileDialog * openFileDialog = new wxFileDialog(this, wxT("Open diagram"),
847 wxEmptyString, wxT(""), wxT("*.bbg"), wxOPEN | wxFILE_MUST_EXIST);
848 printf("SCP: wxGUIEditorGraphicBBS::OnOpenDiagram \n");
849 if (openFileDialog->ShowModal() == wxID_OK) {
850 wxString fileName = openFileDialog->GetPath();
851 ifstream inputStream;
852 std::string fName = (const char*) (fileName.mb_str());
854 inputStream.open(fName.c_str());
855 assert(inputStream.good()); // fails
856 _tabsMgr->addNewTab(openFileDialog->GetFilename());
857 _tabsMgr->loadDiagram(inputStream, fName);
858 _tabsMgr->saveTempActualDiagram("load diagram");
859 GetToolBar()->EnableTool(ID_UNDO, false);
860 GetToolBar()->EnableTool(ID_UNDO, false);
863 refreshGUIControls();
866 //=========================================================================
869 void wxGUIEditorGraphicBBS::OnClickBtnBox(wxCommandEvent& event) {
870 BlackBoxDescriptor *bbDes = _pkgBrowser->GetActualSelected();
872 std::string typeName = bbDes->GetTypeName();
873 std::string packageName = bbDes->GetPackage()->GetName();
875 wxGEditorTabPanel *pnl = this->_tabsMgr->getActualTabPanel();
879 wxVtkSceneManager *scn = pnl->getSceneManager();
880 scn->createGBlackBox(50, 50, packageName, typeName);
884 SaveTempActualDiagram("New Box");
889 //=========================================================================
891 void wxGUIEditorGraphicBBS::OnClickBtnExecutableBox(wxCommandEvent& event) {
893 wxGEditorTabPanel *pnl = this->_tabsMgr->getActualTabPanel();
896 wxVtkSceneManager *scn = pnl->getSceneManager();
897 if( scn->MakeBoxExecutable() )
898 std::cout<<"DFCH: wxGUIEditorGraphicBBS::OnClickBtnExecutableBox...successful"<<std::endl;
900 std::cout<<"DFCH: wxGUIEditorGraphicBBS::OnClickBtnExecutableBox...Error!!"<<std::endl;
906 //=========================================================================
908 void wxGUIEditorGraphicBBS::OnClickBtnComplexBox(wxCommandEvent& event) {
909 wxToolBar* toolbar = GetToolBar();
910 bool temp = toolbar->GetToolState(ID_BTNCOMPLEXBOX);
912 _tabsMgr->setActualDiagramComplexBox(true);
914 _tabsMgr->setActualDiagramComplexBox(false);
916 refreshGUIControls();
919 //=========================================================================
921 void wxGUIEditorGraphicBBS::OnAddComplexBoxInput(wxCommandEvent& event) {
922 wxTextEntryDialog *nameDialog = new wxTextEntryDialog(this,
923 wxT("Name of input port"));
924 if (nameDialog->ShowModal() == wxID_OK) {
925 wxString fileName = nameDialog->GetValue();
926 if (!fileName.IsEmpty()) {
927 std::string portName = (const char*) (fileName.mb_str());
928 _tabsMgr->addActualDiagramComplexInputPort(portName);
933 //=========================================================================
935 void wxGUIEditorGraphicBBS::OnAddComplexBoxOutput(wxCommandEvent& event) {
936 wxTextEntryDialog *nameDialog = new wxTextEntryDialog(this,
937 wxT("Name of output port"));
938 if (nameDialog->ShowModal() == wxID_OK) {
939 wxString fileName = nameDialog->GetValue();
940 if (!fileName.IsEmpty()) {
941 std::string portName = (const char*) (fileName.mb_str());
942 _tabsMgr->addActualDiagramComplexOutputPort(portName);
947 //=========================================================================
949 void wxGUIEditorGraphicBBS::OnCopySelectedToComplexDiagram(
950 wxCommandEvent& event) {
951 _tabsMgr->copySelectedBBoxesToComplexDiagram();
954 void wxGUIEditorGraphicBBS::OnHelpBBeditor(wxCommandEvent& event) {
955 printf("wxGUIEditorGraphicBBS::OnHelpBBeditor ....not implemented..\n");
958 //=========================================================================
959 void wxGUIEditorGraphicBBS::OnCreatePackage(wxCommandEvent& event) {
961 bbtkSystemTools::CreatePackage();
964 //=========================================================================
965 void wxGUIEditorGraphicBBS::OnCreateBlackBox(wxCommandEvent& event) {
966 bbtkSystemTools::CreateBlackBox();
968 //=========================================================================
969 void wxGUIEditorGraphicBBS::OnPlugPackage(wxCommandEvent& event) {
970 //printf("EED wxGUIEditorGraphicBBS::OnPlugPackage ... not implemented ..\n");
971 //this is the right code but it's left to include the corresponding commented libraries
972 long style = wxDD_DEFAULT_STYLE | wxDD_DIR_MUST_EXIST;
975 _T("Select package directory"),
981 userResponse = FD->ShowModal();
982 if(userResponse==wxID_OK)
984 std::string path = wx2std (FD->GetPath()) ;
985 std::string fname = path + "/bbtkPackage";
986 std::cout << "Path chosen = \"" << FD->GetPath() << "\"" << std::endl;
987 if ( Utilities::FileExists( fname ) )
990 f.open(fname.c_str());
995 bbtk::ConfigurationFile::GetInstance().AddPackagePathsAndWrite( path );
997 DoRegeneratePackageDoc(pname);
998 DoRegenerateBoxesLists();
1000 _pkgBrowser->RebuildList();
1002 wxMessageBox(_T("Package successfully plugged. Please restart bbEditor to see the new package in the package browser."),_T("Plug package"),wxOK | wxICON_INFORMATION);
1003 userResponse = wxID_CANCEL;
1007 std::string err = "The directory \"" + path + "\" does not contain a 'bbtkPackage' file.";
1010 err += "\nNote: If you are on Linux please select the folder and click \"Open\", don't enter in it.";
1015 wxMessageBox(_T(err),_T("Plug package"),wxOK | wxICON_ERROR);
1018 }while(userResponse != wxID_CANCEL);
1021 //=========================================================================
1022 void wxGUIEditorGraphicBBS::OnEditConfig(wxCommandEvent& event) {
1023 printf("EED wxGUIEditorGraphicBBS::OnEditConfig ... not implemented ..\n");
1025 //=========================================================================
1027 void wxGUIEditorGraphicBBS::OnShowHTMLDoc(wxCommandEvent& event) {
1029 if (_helpHtmlBrowser != NULL){
1030 _frameAUIMgr->DetachPane(_helpHtmlBrowser);
1031 _helpHtmlBrowser->Destroy();
1033 initHelpHTMLBrowser();
1034 _frameAUIMgr->AddPane(_helpHtmlBrowser, wxAuiPaneInfo().Right().MinSize(200, 200));
1035 _frameAUIMgr->Update();
1036 refreshGUIControls();
1040 //=========================================================================
1041 void wxGUIEditorGraphicBBS::OnCreateIndex(wxCommandEvent& event) {
1042 printf("EED wxGUIEditorGraphicBBS::OnCreateIndex ... not implemented ..\n");
1045 //=========================================================================
1047 void wxGUIEditorGraphicBBS::OnExit(wxCommandEvent& event) {
1051 //=========================================================================
1054 void wxGUIEditorGraphicBBS::setCurrentDiagramDescription(std::string description)
1056 _tabsMgr->SetDescription(description);
1059 //=========================================================================
1061 void wxGUIEditorGraphicBBS::setCurrentDiagramAuthor(std::string author)
1063 _tabsMgr->SetAuthor(author);
1066 //=========================================================================
1068 void wxGUIEditorGraphicBBS::setCurrentDiagramCategory(std::string category)
1070 _tabsMgr->SetCategory(category);
1073 //=========================================================================
1075 std::string wxGUIEditorGraphicBBS::getCurrentDiagramDescription()
1077 return _tabsMgr->GetDescription();
1080 //=========================================================================
1082 std::string wxGUIEditorGraphicBBS::getCurrentDiagramAuthor()
1084 return _tabsMgr->GetAuthor();
1087 //=========================================================================
1090 std::string wxGUIEditorGraphicBBS::getCurrentDiagramCategory()
1092 return _tabsMgr->GetCategory();
1096 } // EO namespace bbtk