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);
143 //toolbar->AddTool(ID_ADDCOMPLEXBOXINPUT, _T("Add input to Complex box"),
144 // bmp_complexinputport, wxNullBitmap, wxITEM_NORMAL,
145 // _T("Add input to Complex box"), _T("Add input to Complex box"));
146 toolbar->AddTool(ID_ADDCOMPLEXBOXINPUT, _T("Add external input (Complex box or console app)"),
147 bmp_complexinputport, wxNullBitmap, wxITEM_NORMAL,
148 _T("Add external input (Complex box or console app)"), _T("Add external input (Complex box or console app)"));
150 toolbar->AddTool(ID_ADDCOMPLEXBOXOUTPUT, _T("Add output to Complex box"),
151 bmp_complexoutputport, wxNullBitmap, wxITEM_NORMAL,
152 _T("Add output Complex box"), _T("Add output Complex box"));
154 // toolbar->EnableTool(ID_ADDCOMPLEXBOXINPUT, false); RaC2012 2nd HackFest
155 toolbar->EnableTool(ID_ADDCOMPLEXBOXINPUT, true);
157 toolbar->EnableTool(ID_ADDCOMPLEXBOXOUTPUT, false);
158 toolbar->AddSeparator();
159 toolbar->AddTool(ID_UNDO, _T("Undo"),bmp_undo, wxNullBitmap, wxITEM_NORMAL, _T("Undo"), _T("Undo"));
160 toolbar->AddTool(ID_REDO, _T("Redo"),bmp_redo, wxNullBitmap, wxITEM_NORMAL, _T("Redo"), _T("Redo"));
161 toolbar->AddSeparator();
162 toolbar->AddTool(ID_EDITPROPERTIES, _T("Edit diagram properties"),bmp_editProperties, wxNullBitmap, wxITEM_NORMAL, _T("Edit diagram properties"), _T("Edit diagram properties"));
163 toolbar->EnableTool(ID_EDITPROPERTIES, false);
165 toolbar->EnableTool(ID_UNDO, false);
166 toolbar->EnableTool(ID_REDO, false);
167 toolbar->SetMargins(2, 2);
172 // connect command event handlers
174 Connect(ID_NEW, wxEVT_COMMAND_TOOL_CLICKED,
175 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnCreateNewTab));
176 Connect(ID_OPEN, wxEVT_COMMAND_TOOL_CLICKED,
177 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnOpenDiagram));
178 Connect(ID_SAVE_DIAGRAM, wxEVT_COMMAND_TOOL_CLICKED,
179 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnSaveActualDiagram)); //DFCH
180 Connect(ID_SAVE_AS_DIAGRAM, wxEVT_COMMAND_TOOL_CLICKED,
181 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnSaveAsActualDiagram)); //DFCH
184 wxEVT_COMMAND_TOOL_CLICKED,
185 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnExecuteActualDiagram));
188 wxEVT_COMMAND_TOOL_CLICKED,
189 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnDeleteAllBoxesActualDiagram));
192 wxEVT_COMMAND_TOOL_CLICKED,
193 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnCenterViewActualDiagram));
194 Connect(ID_BTNBOX, wxEVT_COMMAND_TOOL_CLICKED,
195 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnClickBtnBox));
198 wxEVT_COMMAND_TOOL_CLICKED,
199 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnClickBtnExecutableBox));
200 Connect(ID_BTNCOMPLEXBOX, wxEVT_COMMAND_TOOL_CLICKED,
201 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnClickBtnComplexBox));
202 Connect(ID_ADDCOMPLEXBOXINPUT, wxEVT_COMMAND_TOOL_CLICKED,
203 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnAddComplexBoxInput));
204 Connect(ID_ADDCOMPLEXBOXOUTPUT, wxEVT_COMMAND_TOOL_CLICKED,
205 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnAddComplexBoxOutput));
206 Connect(ID_UNDO,wxEVT_COMMAND_TOOL_CLICKED, wxCommandEventHandler(wxGUIEditorGraphicBBS::OnUndo));
207 Connect(ID_REDO,wxEVT_COMMAND_TOOL_CLICKED, wxCommandEventHandler(wxGUIEditorGraphicBBS::OnRedo));
208 Connect(ID_CHANGENAME, wxEVT_COMMAND_RIGHT_CLICK, wxCommandEventHandler(wxGUIEditorGraphicBBS::OnChangeName));
209 Connect(ID_EDITPROPERTIES,wxEVT_COMMAND_TOOL_CLICKED, wxCommandEventHandler(wxGUIEditorGraphicBBS::OnEditDiagramProperties));
212 //=========================================================================
213 void wxGUIEditorGraphicBBS::initHelpHTMLBrowser() {
215 _helpHtmlBrowser = new WxGUIHtmlBrowser(this, wxSize(200, 0));
221 //=========================================================================
222 void wxGUIEditorGraphicBBS::initMenu() {
223 // Create File menu and its items
224 wxMenu *fileMenu = new wxMenu();
225 fileMenu->Append(ID_NEW, _T("New diagram"), _T("New"));
226 fileMenu->Append(ID_SAVE_DIAGRAM, _T("Save Diagram"), _T("Save Diagram")); //DFCH
227 fileMenu->Append(ID_SAVE_AS_DIAGRAM, _T("Save Diagram As"),
228 _T("Save Diagram As")); //DFCH
229 fileMenu->Append(ID_OPEN_BBS, _T("Open BBS"), _T("Open BBS"));
231 fileMenu->Append(ID_OPEN, _T("Open a diagram"), _T("Open a diagram"));
232 fileMenu->Append(ID_SAVE_AS_BBS, _T("Save BBS"), _T("Save BBS"));
233 fileMenu->Append(ID_SAVE_AS_COMPLEXBOX, _T("Save complex box"),
234 _T("Save complex box"));
235 fileMenu->Append(wxID_EXIT, _T("E&xit"), _T("Exit"));
237 Connect(ID_NEW, wxEVT_COMMAND_MENU_SELECTED,
238 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnCreateNewTab));
239 Connect(ID_SAVE_DIAGRAM, wxEVT_COMMAND_MENU_SELECTED,
240 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnSaveActualDiagram)); //DFCH
241 Connect(ID_SAVE_AS_DIAGRAM, wxEVT_COMMAND_MENU_SELECTED,
242 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnSaveAsActualDiagram));
243 Connect(ID_OPEN_BBS, wxEVT_COMMAND_MENU_SELECTED,
244 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnOpenBBS));
245 Connect(ID_SAVE_AS_BBS, wxEVT_COMMAND_MENU_SELECTED,
246 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnSaveActualBBS));
248 ID_SAVE_AS_COMPLEXBOX,
249 wxEVT_COMMAND_MENU_SELECTED,
250 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnSaveActualComplexBox));
251 Connect(wxID_EXIT, wxEVT_COMMAND_MENU_SELECTED,
252 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnExit));
254 // Create Help menu and its items
255 wxMenu *editMenu = new wxMenu;
256 editMenu->Append(ID_COPY_TO_COMPLEXDIAGRAM,
257 _T("Copy selected to complex box"),
258 _T("Creates a new complex box diagram with selected boxes"));
261 ID_COPY_TO_COMPLEXDIAGRAM,
262 wxEVT_COMMAND_MENU_SELECTED,
263 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnCopySelectedToComplexDiagram));
265 // Create Help menu and its items
266 wxMenu *helpMenu = new wxMenu;
267 helpMenu->Append(wxID_ABOUT, _T("&About..."), _T("About"));
268 helpMenu->Append(ID_HELP_BBEDITOR, _T("&Help..."), _T("Help"));
269 Connect(ID_HELP_BBEDITOR, wxEVT_COMMAND_MENU_SELECTED,
270 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnHelpBBeditor));
273 wxMenu *menuTools = new wxMenu;
274 menuTools->Append(ID_bbEditor_Tool_Menu_CreatePackage,
275 _T("Create &package") );
276 menuTools->Append(ID_bbEditor_Tool_Menu_CreateBlackBox,
277 _T("Create &blackbox") );
278 menuTools->Append(ID_bbEditor_Tool_Menu_PlugPackage, _T("Plug package") );
279 menuTools->Append(ID_bbEditor_Tool_Menu_EditConfig, _T("&Edit bbtk config") );
280 menuTools->Append(ID_bbEditor_Tool_Menu_ShowHTMLDoc,
281 _T("Show &HTML documentation") );
282 menuTools->Append(ID_bbEditor_Tool_Menu_CreateIndex, _T("&Generate index") );
284 Connect(ID_bbEditor_Tool_Menu_CreatePackage, wxEVT_COMMAND_MENU_SELECTED,
285 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnCreatePackage));
286 Connect(ID_bbEditor_Tool_Menu_CreateBlackBox, wxEVT_COMMAND_MENU_SELECTED,
287 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnCreateBlackBox));
288 Connect(ID_bbEditor_Tool_Menu_PlugPackage, wxEVT_COMMAND_MENU_SELECTED,
289 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnPlugPackage));
290 Connect(ID_bbEditor_Tool_Menu_EditConfig, wxEVT_COMMAND_MENU_SELECTED,
291 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnEditConfig));
292 Connect(ID_bbEditor_Tool_Menu_ShowHTMLDoc, wxEVT_COMMAND_MENU_SELECTED,
293 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnShowHTMLDoc));
294 Connect(ID_bbEditor_Tool_Menu_CreateIndex, wxEVT_COMMAND_MENU_SELECTED,
295 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnCreateIndex));
297 // Append the created menu to the menu bar
298 wxMenuBar *menuBar = new wxMenuBar();
299 menuBar->Append(fileMenu, _T("&File") );
300 menuBar->Append(editMenu, _T("&Edit") );
301 menuBar->Append(menuTools, _T("&Tool") );
302 menuBar->Append(helpMenu, _T("&Help") );
304 // Attach this menu bar to the frame
308 //=========================================================================
309 void wxGUIEditorGraphicBBS::initTabPanelsManager()
311 _notebook = new wxAuiNotebook(this, wxID_NOTEBOOK, wxDefaultPosition,
312 wxDefaultSize, wxAUI_NB_TOP | wxAUI_NB_TAB_MOVE
313 | wxAUI_NB_CLOSE_ON_ACTIVE_TAB | wxAUI_NB_TAB_FIXED_WIDTH
314 | wxAUI_NB_WINDOWLIST_BUTTON);
315 _tabsMgr = new wxTabPanelsManager(this);
316 _frameAUIMgr->AddPane(_notebook, wxAuiPaneInfo().CenterPane());
319 //=========================================================================
320 void wxGUIEditorGraphicBBS::initPackageBrowser()
322 _pkgBrowser = new WxGUIPackageBrowser2(this);
323 _pkgBrowser->IncludeAll();
324 _frameAUIMgr->AddPane(_pkgBrowser, wxAuiPaneInfo().Left().MinSize(30, 500).BestSize(750,500).CloseButton(false));
327 //================================================================
329 void wxGUIEditorGraphicBBS::DoRegeneratePackageDoc(const std::string& pack)
331 std::string mess("Regenerating doc for package '");
335 mess = "Regenerating doc for all packages";
338 mess += " ... please wait";
340 SetStatusText(std2wx(mess));
348 command += ConfigurationFile::GetInstance().Get_bin_path();
349 command += ConfigurationFile::GetInstance().Get_file_separator();
350 command += "bbRegeneratePackageDoc";
355 command += " " + pack + " -q";
356 bbtkMessage("debug",1,"Executing system command '"<<command<<"'"<<std::endl);
358 if (!system(command.c_str())) {
359 SetStatusText(_T("Done !"));
361 wxMessageBox(_T("Done !"),_T("Regenerate package '")
362 +std2wx(pack)+_T("' doc"),
363 wxOK | wxICON_INFORMATION);
366 SetStatusText(_T("Done !"));
367 wxString err(_T("An error occured while running '"));
368 err += bbtk::std2wx(command) + _T("'");
369 wxMessageBox(err, _T("Regenerate package doc"), wxOK | wxICON_ERROR);
373 //================================================================
374 void wxGUIEditorGraphicBBS::DoRegenerateBoxesLists() {
375 SetStatusText(_T("Regenerating boxes lists ... please wait"));
382 command += ConfigurationFile::GetInstance().Get_bin_path();
383 command += ConfigurationFile::GetInstance().Get_file_separator();
384 command += "bbRegenerateBoxesLists";
391 bbtkMessage("debug",1,"Executing system command '"<<command<<"'"<<std::endl);
393 if (!system(command.c_str())) {
394 SetStatusText(_T("Done !"));
396 wxMessageBox(_T("Done !"),_T("Regenerate boxes lists"),
397 wxOK | wxICON_INFORMATION);
400 SetStatusText(_T("Done !"));
401 wxString err(_T("An error occured while running '"));
402 err += bbtk::std2wx(command) + _T("'");
403 wxMessageBox(err, _T("Regenerate boxes lists"), wxOK | wxICON_ERROR);
407 //================================================================
408 void wxGUIEditorGraphicBBS::RegenerateAll() {
409 DoRegeneratePackageDoc("-a");
410 DoRegenerateBoxesLists();
413 //================================================================
415 wxAuiNotebook* wxGUIEditorGraphicBBS::getAuiNotebook() {
419 //================================================================
421 void wxGUIEditorGraphicBBS::displayBlackBoxInfo(std::string packageName,
422 std::string boxName) {
423 if (_actualPkgBrowserPkgName != packageName || _actualPkgBrowserBoxName
425 _actualPkgBrowserPkgName = packageName;
426 _actualPkgBrowserBoxName = boxName;
428 BlackBoxDescriptor::Pointer descriptor =
429 GObjectsMVCFactory::getInstance()->getBlackBoxDescriptor(
430 packageName, boxName);
431 _pkgBrowser->WxGUIBlackBoxListUserOnSelected(descriptor.get());
435 //=========================================================================
437 void wxGUIEditorGraphicBBS::editBlackBox(GBlackBoxModel *bbmodel) {
438 wxBlackBoxEditionDialog* dialog =
439 new wxBlackBoxEditionDialog(this, bbmodel);
443 //=========================================================================
445 bool wxGUIEditorGraphicBBS::boxNameExists(std::string boxname) {
447 return this->_tabsMgr->getActualTabPanel()->getSceneManager()->boxExist(boxname);
450 //=========================================================================
452 void wxGUIEditorGraphicBBS::updateStatusBar(std::string textStatus) {
453 SetStatusText(crea::std2wx(textStatus));
456 //=========================================================================
458 void wxGUIEditorGraphicBBS::executeScript(std::string script) {
459 std::string separator =
460 ConfigurationFile::GetInstance().Get_file_separator();
461 std::string dir = ConfigurationFile::GetInstance().Get_default_temp_dir();
462 std::string filename = dir + separator + "tmp_bbtk.bbs";
465 tempFile.open(filename.c_str());
469 std::string command = "";
472 command += "start /b ";
475 // command += "\""+ crea::System::GetExecutablePath();
477 // command += separator + "../../../bbi.app/Contents/MacOS";
481 command += "\"" + filename + "\"";
487 printf("RaC wxGUIEditorGraphicBBS::executeScript %s \n", command.c_str());
488 system(command.c_str());
491 //=========================================================================
492 std::string wxGUIEditorGraphicBBS::CheckExtension(std::string filename, std::string extension) {
493 if(filename.size() > extension.size() ){
494 if( (filename.compare(filename.size()-extension.size(), extension.size(),extension)) !=0 ){
495 filename.append(extension);
498 filename.append(extension);
502 //=========================================================================
504 //=========================================================================
506 void wxGUIEditorGraphicBBS::OnCreateNewTab(wxCommandEvent& event) {
507 _tabsMgr->addNewTab();
508 refreshGUIControls();
511 void wxGUIEditorGraphicBBS::OnUndo(wxCommandEvent& event) {
512 unsigned short disable;
516 _tabsMgr->loadTempDiagram(0);
517 disable = _tabsMgr->getUndoState(stundo);
520 std::string name = _tabsMgr->GetNameTabPanel();
521 if(name[name.length() - 1] == '*')
523 name =name.substr(0,name.length()-1);
525 _tabsMgr->SetNameTabPanel(wxString (name.c_str(), wxConvUTF8));
528 GetToolBar()->EnableTool(ID_UNDO,disable);
529 GetToolBar()->SetToolShortHelp(ID_UNDO,crea::std2wx(stundo));
530 GetToolBar()->EnableTool(ID_REDO,_tabsMgr->getRedoState(stredo));
531 GetToolBar()->SetToolShortHelp(ID_REDO,crea::std2wx(stredo));
532 refreshGUIControls();
535 //=========================================================================
537 void wxGUIEditorGraphicBBS::OnRedo(wxCommandEvent& event) {
538 unsigned short disable;
542 _tabsMgr->loadTempDiagram(1);
543 std::string name = _tabsMgr->GetNameTabPanel();
544 if(name[name.length() - 1] != '*')
546 _tabsMgr->SetNameTabPanel(wxString (name.c_str(), wxConvUTF8));
547 GetToolBar()->EnableTool(ID_UNDO,_tabsMgr->getUndoState(stundo));
548 GetToolBar()->SetToolShortHelp(ID_UNDO,crea::std2wx(stundo));
549 GetToolBar()->EnableTool(ID_REDO,_tabsMgr->getRedoState(stredo));
550 GetToolBar()->SetToolShortHelp(ID_REDO,crea::std2wx(stredo));
551 refreshGUIControls();
554 void wxGUIEditorGraphicBBS::OnChangeName(wxCommandEvent& event){
557 //=========================================================================
559 void wxGUIEditorGraphicBBS::OnEditDiagramProperties(wxCommandEvent& event)
561 wxDiagramPropertiesEditionDialog* dialog =
562 new wxDiagramPropertiesEditionDialog(this);
566 //=========================================================================
568 void wxGUIEditorGraphicBBS::OnExecuteActualDiagram(wxCommandEvent& event) {
569 std::string script1 = _tabsMgr->getActualDiagramBBS(true);
570 cout << endl << "RaC wxGUIEditorGraphicBBS::executeActualDiagram SCRIPT"
572 cout << script1 << endl;
574 std::string script2 = _tabsMgr->getActualDiagramBBS(false);
575 executeScript(script2);
578 //=========================================================================
580 //=========================================================================
581 void wxGUIEditorGraphicBBS::OnOpenBBS(wxCommandEvent& event) {
582 wxFileDialog * openFileDialog = new wxFileDialog(this, wxT("Open BBS"),
583 wxEmptyString, wxT("NewBBS"), wxT("*.bbs"), wxOPEN);
584 if (openFileDialog->ShowModal() == wxID_OK) {
585 wxString fileName = openFileDialog->GetPath();
587 _tabsMgr->addNewTab(openFileDialog->GetFilename());
589 bbtk::InterpreterBBS::Pointer I = bbtk::InterpreterBBS::New(
590 this->_tabsMgr->getActualTabPanel()->getSceneManager(),
591 _pkgBrowser->GetFactory());
593 // We tell the interpreter to throw exceptions on error
595 // Interpret the file supposed to define a box called 'Processing'
596 I->InterpretFile((const char*) (fileName.mb_str()));
598 refreshGUIControls();
601 void wxGUIEditorGraphicBBS::SaveActualBBS(std::string filename) {
604 //EED file.open(fileName.c_str());
605 file.open(filename.c_str());
606 std::string content = "";
607 // writing file header
608 content += "# ----------------------------------\n";
609 content += "# - BBTKGEditor v 1.3 BBS BlackBox Script\n";
613 content += "# ----------------------------------\n";
615 content += _tabsMgr->getActualDiagramBBS();
620 void wxGUIEditorGraphicBBS::OnSaveActualBBS(wxCommandEvent& event) {
621 wxFileDialog * saveFileDialog = new wxFileDialog(this,
622 wxT("Save actual BBS"), wxEmptyString, wxT("NewBBS"),
623 wxT("*.bbs"), wxSAVE | wxOVERWRITE_PROMPT);
624 if (saveFileDialog->ShowModal() == wxID_OK) {
625 wxString fileName = saveFileDialog->GetPath();
626 std::string filename = (const char*) (fileName.mb_str());
627 filename=CheckExtension (filename, ".bbs");
628 SaveActualBBS(filename);
633 void wxGUIEditorGraphicBBS::AskComplexBoxConfiguration() {
634 std::string cbName = _tabsMgr->GetCbName();
635 std::string paName = _tabsMgr->GetCbPackageName();
637 wxTextEntryDialog *cbNameDialog = new wxTextEntryDialog(this,
638 wxT("Complex Box name"));
639 wxTextEntryDialog *paNameDialog = new wxTextEntryDialog(this,
640 wxT("Package name"));
642 cbNameDialog->SetValue(wxString(cbName.c_str(), wxConvUTF8));
643 paNameDialog->SetValue(wxString(paName.c_str(), wxConvUTF8));
645 if (cbNameDialog->ShowModal() == wxID_OK) {
646 wxString complexboxname = cbNameDialog->GetValue();
647 cbName = (const char*) (complexboxname.mb_str());
650 if (paNameDialog->ShowModal() == wxID_OK) {
651 wxString packagename = paNameDialog->GetValue();
652 paName = (const char*) (packagename.mb_str());
655 _tabsMgr->SetCbName(cbName);
656 _tabsMgr->SetCbPackageName(paName);
659 //=========================================================================
661 void wxGUIEditorGraphicBBS::SaveActualComplexBox(std::string filename) {
663 file.open(filename.c_str());
665 std::string content = "";
667 // writing file header
668 content += "# ----------------------------------\n";
669 content += "# - BBTKGEditor v 1.3 BBS BlackBox Script (Complex Box)\n";
673 content += "# ----------------------------------\n";
675 content += _tabsMgr->getActualComplexBoxBBS();
680 //=========================================================================
682 void wxGUIEditorGraphicBBS::OnSaveActualComplexBox(wxCommandEvent& event) {
683 wxFileDialog * saveFileDialog = new wxFileDialog(this,
684 wxT("Save Complex Box BBS"), wxEmptyString,
685 _T("ComplexBoxName"), wxT("*.bbs"), wxSAVE
686 | wxOVERWRITE_PROMPT);
687 if (saveFileDialog->ShowModal() == wxID_OK) {
688 wxString fileName = saveFileDialog->GetPath();
689 std::string filename = (const char*) (fileName.mb_str());
690 filename=CheckExtension (filename, ".bbs");
691 SaveActualComplexBox(filename);
695 //=========================================================================
696 void wxGUIEditorGraphicBBS::SaveActualDiagram(std::string filename) {
698 file.open(filename.c_str());
700 std::string content = "";
702 // writing file header
703 content += "# ----------------------------------\n";
704 content += "# - BBTKGEditor v 1.3 BBG BlackBox Diagram file\n";
710 content += "# ----------------------------------\n";
712 content += "APP_START\n";
713 _tabsMgr->saveActualDiagram(content, filename); //DFCH
714 content += "APP_END\n";
719 //=========================================================================
720 void wxGUIEditorGraphicBBS::SaveTempActualDiagram(const std::string &action)
724 std::string name = _tabsMgr->GetNameTabPanel();
725 if(name[name.length() - 1] != '*')
727 _tabsMgr->SetNameTabPanel(wxString (name.c_str(), wxConvUTF8));
728 _tabsMgr->saveTempActualDiagram(action);
729 GetToolBar()->EnableTool(ID_UNDO,_tabsMgr->getUndoState(stundo));
730 GetToolBar()->SetToolShortHelp(ID_UNDO,crea::std2wx(stundo));
731 GetToolBar()->EnableTool(ID_REDO,_tabsMgr->getRedoState(stredo));
732 GetToolBar()->SetToolShortHelp(ID_REDO,crea::std2wx(stredo));
735 //=========================================================================
737 //The following method allows to save the current diagram asking the filename
739 void wxGUIEditorGraphicBBS::SaveCurrentDiagramAs() {
740 wxFileDialog * saveFileDialog = new wxFileDialog(this,
741 wxT("Save current diagram"), wxEmptyString, wxT("NewDiagram"),
742 wxT("*.bbg"), wxSAVE | wxOVERWRITE_PROMPT);
743 if (saveFileDialog->ShowModal() == wxID_OK) {
744 //_tabsMgr->SetNameTabPanel(saveFileDialog->GetFilename());
745 wxString pathfileName = saveFileDialog->GetPath();
746 std::string pathfilename = (const char*) (pathfileName.mb_str());
747 pathfilename=CheckExtension (pathfilename, ".bbg");
749 //modify the tab name accordingly
750 wxString fileName = saveFileDialog->GetFilename();
751 std::string filename = (const char*) (fileName.mb_str());
752 filename=CheckExtension (filename, ".bbg");
753 _tabsMgr->SetNameTabPanel( wxString (filename.c_str(), wxConvUTF8) );
755 std::string pathfilenamebbs = pathfilename;
756 pathfilenamebbs[pathfilenamebbs.length() - 1] = 's';
757 if (_tabsMgr->isActualDiagramComplexBox() == false) {
758 SaveActualDiagram(pathfilename);
759 SaveActualBBS(pathfilenamebbs);
761 AskComplexBoxConfiguration();
762 SaveActualDiagram(pathfilename);
763 SaveActualComplexBox(pathfilenamebbs);
764 } //if isActualDiagramComplexBox
765 } // if saveFileDialog
767 //=========================================================================
769 void wxGUIEditorGraphicBBS::OnSaveActualDiagram(wxCommandEvent& event) {
770 std::string pathfilename = _tabsMgr->GetCurrentTabPanelPath();
771 if (pathfilename.empty()) {
772 SaveCurrentDiagramAs();
774 std::string pathfilenamebbs = pathfilename;
775 pathfilenamebbs[pathfilenamebbs.length() - 1] = 's';
777 if (_tabsMgr->isActualDiagramComplexBox() == false) {
778 std::string name = _tabsMgr->GetNameTabPanel();
779 if(name[name.length() - 1] == '*')
781 name =name.substr(0,name.length()-1);
783 _tabsMgr->SetNameTabPanel(wxString (name.c_str(), wxConvUTF8));
784 SaveActualDiagram(pathfilename);
785 SaveActualBBS(pathfilenamebbs);
787 AskComplexBoxConfiguration();
788 SaveActualDiagram(pathfilename);
789 SaveActualComplexBox(pathfilenamebbs);
790 } //if isActualDiagramComplexBox
793 //=========================================================================
795 void wxGUIEditorGraphicBBS::OnSaveAsActualDiagram(wxCommandEvent& event) {
796 SaveCurrentDiagramAs();
798 //=========================================================================
800 void wxGUIEditorGraphicBBS::refreshGUIControls() {
803 //RaC2012 2ndHackFest Next line seems weird ... To keep in mind for other devels
804 wxToolBar* toolbar = GetToolBar();
805 if (_tabsMgr->isActualDiagramComplexBox()) {
806 toolbar->ToggleTool(ID_BTNCOMPLEXBOX, true);
807 toolbar->EnableTool(ID_ADDCOMPLEXBOXINPUT, true);
808 toolbar->EnableTool(ID_ADDCOMPLEXBOXOUTPUT, true);
810 GetMenuBar()->GetMenu(0)->Enable(ID_SAVE_AS_COMPLEXBOX, true);
811 GetMenuBar()->GetMenu(0)->Enable(ID_SAVE_AS_BBS, false);
813 toolbar->ToggleTool(ID_BTNCOMPLEXBOX, false);
814 toolbar->EnableTool(ID_ADDCOMPLEXBOXINPUT, false);
815 toolbar->EnableTool(ID_ADDCOMPLEXBOXOUTPUT, false);
817 GetMenuBar()->GetMenu(0)->Enable(ID_SAVE_AS_COMPLEXBOX, false);
818 GetMenuBar()->GetMenu(0)->Enable(ID_SAVE_AS_BBS, true);
821 //RaC2012 2ndHackFest
822 GetToolBar()->EnableTool(ID_EDITPROPERTIES,true);
824 GetToolBar()->EnableTool(ID_UNDO,_tabsMgr->getUndoState(stundo));
825 GetToolBar()->SetToolShortHelp(ID_UNDO,crea::std2wx(stundo));
826 GetToolBar()->EnableTool(ID_REDO,_tabsMgr->getRedoState(stredo));
827 GetToolBar()->SetToolShortHelp(ID_REDO,crea::std2wx(stredo));
829 if (_tabsMgr->getNumActualSelectedObjects() > 0) {
830 GetMenuBar()->GetMenu(1)->Enable(ID_COPY_TO_COMPLEXDIAGRAM, true);
832 ///TODO Fix the possibility to say from the SceneManager to the GUI to refresh the options
833 GetMenuBar()->GetMenu(1)->Enable(ID_COPY_TO_COMPLEXDIAGRAM, true);
838 //=========================================================================
840 void wxGUIEditorGraphicBBS::OnDeleteAllBoxesActualDiagram(wxCommandEvent& event) {
841 wxMessageDialog *dial = new wxMessageDialog(NULL,
842 wxT("Are you sure to delete all boxes of the diagram?"),
843 wxT("Delete all boxes"), wxYES_NO | wxNO_DEFAULT
845 if (dial->ShowModal() == wxID_YES) {
846 _tabsMgr->deleteAllBoxesActualDiagram();
850 //=========================================================================
852 void wxGUIEditorGraphicBBS::OnCenterViewActualDiagram(wxCommandEvent& event) {
853 _tabsMgr->centerViewActualDiagram();
856 //=========================================================================
858 void wxGUIEditorGraphicBBS::OnOpenDiagram(wxCommandEvent& event) {
859 wxFileDialog * openFileDialog = new wxFileDialog(this, wxT("Open diagram"),
860 wxEmptyString, wxT(""), wxT("*.bbg"), wxOPEN | wxFILE_MUST_EXIST);
861 printf("SCP: wxGUIEditorGraphicBBS::OnOpenDiagram \n");
862 if (openFileDialog->ShowModal() == wxID_OK) {
863 wxString fileName = openFileDialog->GetPath();
864 ifstream inputStream;
865 std::string fName = (const char*) (fileName.mb_str());
867 inputStream.open(fName.c_str());
868 assert(inputStream.good()); // fails
869 _tabsMgr->addNewTab(openFileDialog->GetFilename());
870 _tabsMgr->loadDiagram(inputStream, fName);
871 _tabsMgr->saveTempActualDiagram("load diagram");
872 GetToolBar()->EnableTool(ID_UNDO, false);
873 GetToolBar()->EnableTool(ID_UNDO, false);
876 refreshGUIControls();
879 //=========================================================================
882 void wxGUIEditorGraphicBBS::OnClickBtnBox(wxCommandEvent& event) {
883 BlackBoxDescriptor *bbDes = _pkgBrowser->GetActualSelected();
885 std::string typeName = bbDes->GetTypeName();
886 std::string packageName = bbDes->GetPackage()->GetName();
888 wxGEditorTabPanel *pnl = this->_tabsMgr->getActualTabPanel();
892 wxVtkSceneManager *scn = pnl->getSceneManager();
893 scn->createGBlackBox(50, 50, packageName, typeName);
897 SaveTempActualDiagram("New Box");
902 //=========================================================================
904 void wxGUIEditorGraphicBBS::OnClickBtnExecutableBox(wxCommandEvent& event) {
906 wxGEditorTabPanel *pnl = this->_tabsMgr->getActualTabPanel();
909 wxVtkSceneManager *scn = pnl->getSceneManager();
910 if( scn->MakeBoxExecutable() )
911 std::cout<<"DFCH: wxGUIEditorGraphicBBS::OnClickBtnExecutableBox...successful"<<std::endl;
913 std::cout<<"DFCH: wxGUIEditorGraphicBBS::OnClickBtnExecutableBox...Error!!"<<std::endl;
919 //=========================================================================
921 void wxGUIEditorGraphicBBS::OnClickBtnComplexBox(wxCommandEvent& event) {
922 wxToolBar* toolbar = GetToolBar();
923 bool temp = toolbar->GetToolState(ID_BTNCOMPLEXBOX);
931 //=========================================================================
933 void wxGUIEditorGraphicBBS::OnAddComplexBoxInput(wxCommandEvent& event) {
934 wxTextEntryDialog *nameDialog = new wxTextEntryDialog(this,
935 wxT("Name of input port"));
936 if (nameDialog->ShowModal() == wxID_OK) {
937 wxString fileName = nameDialog->GetValue();
938 if (!fileName.IsEmpty()) {
939 std::string portName = (const char*) (fileName.mb_str());
940 _tabsMgr->addActualDiagramComplexInputPort(portName);
945 //=========================================================================
947 void wxGUIEditorGraphicBBS::OnAddComplexBoxOutput(wxCommandEvent& event) {
948 wxTextEntryDialog *nameDialog = new wxTextEntryDialog(this,
949 wxT("Name of output port"));
950 if (nameDialog->ShowModal() == wxID_OK) {
951 wxString fileName = nameDialog->GetValue();
952 if (!fileName.IsEmpty()) {
953 std::string portName = (const char*) (fileName.mb_str());
954 _tabsMgr->addActualDiagramComplexOutputPort(portName);
959 //=========================================================================
961 void wxGUIEditorGraphicBBS::OnCopySelectedToComplexDiagram(
962 wxCommandEvent& event) {
963 _tabsMgr->copySelectedBBoxesToComplexDiagram();
966 void wxGUIEditorGraphicBBS::OnHelpBBeditor(wxCommandEvent& event) {
967 printf("wxGUIEditorGraphicBBS::OnHelpBBeditor ....not implemented..\n");
970 //=========================================================================
971 void wxGUIEditorGraphicBBS::OnCreatePackage(wxCommandEvent& event) {
973 bbtkSystemTools::CreatePackage();
976 //=========================================================================
977 void wxGUIEditorGraphicBBS::OnCreateBlackBox(wxCommandEvent& event) {
978 bbtkSystemTools::CreateBlackBox();
980 //=========================================================================
981 void wxGUIEditorGraphicBBS::OnPlugPackage(wxCommandEvent& event) {
982 //DFGO2012 Plug Package functionnalities
983 long style = wxDD_DEFAULT_STYLE | wxDD_DIR_MUST_EXIST;
986 _T("Select package directory"),
992 userResponse = FD->ShowModal();
993 if(userResponse==wxID_OK)
995 std::string path = wx2std (FD->GetPath()) ;
996 std::string fname = path + "/bbtkPackage";
997 std::cout << "Path chosen = \"" << FD->GetPath() << "\"" << std::endl;
998 if ( Utilities::FileExists( fname ) )
1001 f.open(fname.c_str());
1006 bbtk::ConfigurationFile::GetInstance().AddPackagePathsAndWrite( path );
1008 DoRegeneratePackageDoc(pname);
1009 DoRegenerateBoxesLists();
1011 _pkgBrowser->RebuildList();
1013 wxMessageBox(_T("Package successfully plugged. Please restart bbEditor to see the new package in the package browser."),_T("Plug package"),wxOK | wxICON_INFORMATION);
1014 userResponse = wxID_CANCEL;
1018 std::string err = "The directory \"" + path + "\" does not contain a 'bbtkPackage' file.";
1021 err += "\nNote: If you are on Linux please select the folder and click \"Open\", don't enter in it.";
1025 wxMessageBox(crea::std2wx(err), _T("Plug package"),wxOK | wxICON_ERROR);
1026 // THE FOLLOWING LINE GIVES ERRORS BECAUSE IT IS NECESSARY TO USE std2wx
1027 //wxMessageBox( _T( err) , _T("Plug package"),wxOK | wxICON_ERROR);
1030 }while(userResponse != wxID_CANCEL);
1033 //=========================================================================
1034 void wxGUIEditorGraphicBBS::OnEditConfig(wxCommandEvent& event) {
1035 std::string commandStr;
1036 std::string configFile = ConfigurationFile::GetInstance().Get_config_xml_full_path();
1038 commandStr = "notepad.exe ";
1040 commandStr = "gedit ";
1042 commandStr = commandStr + configFile;
1043 std::cout << "system: " << commandStr << std::endl;
1044 system ( commandStr.c_str() );
1046 //=========================================================================
1048 void wxGUIEditorGraphicBBS::OnShowHTMLDoc(wxCommandEvent& event) {
1050 if (_helpHtmlBrowser != NULL){
1051 _frameAUIMgr->DetachPane(_helpHtmlBrowser);
1052 _helpHtmlBrowser->Destroy();
1054 initHelpHTMLBrowser();
1055 _frameAUIMgr->AddPane(_helpHtmlBrowser, wxAuiPaneInfo().Right().MinSize(200, 200));
1056 _frameAUIMgr->Update();
1057 refreshGUIControls();
1061 //=========================================================================
1062 void wxGUIEditorGraphicBBS::OnCreateIndex(wxCommandEvent& event) {
1063 printf("EED wxGUIEditorGraphicBBS::OnCreateIndex ... not implemented ..\n");
1066 //=========================================================================
1068 void wxGUIEditorGraphicBBS::OnExit(wxCommandEvent& event) {
1072 //=========================================================================
1074 void wxGUIEditorGraphicBBS::enableComplexBox() {
1075 _tabsMgr->setActualDiagramComplexBox(true);
1076 refreshGUIControls();
1079 //=========================================================================
1081 void wxGUIEditorGraphicBBS::disableComplexBox() {
1082 _tabsMgr->setActualDiagramComplexBox(false);
1083 refreshGUIControls();
1086 //=========================================================================
1088 void wxGUIEditorGraphicBBS::setCurrentDiagramDescription(std::string description)
1090 _tabsMgr->SetDescription(description);
1093 //=========================================================================
1095 void wxGUIEditorGraphicBBS::setCurrentDiagramAuthor(std::string author)
1097 _tabsMgr->SetAuthor(author);
1100 //=========================================================================
1102 void wxGUIEditorGraphicBBS::setCurrentDiagramCategory(std::string category)
1104 _tabsMgr->SetCategory(category);
1107 //=========================================================================
1109 std::string wxGUIEditorGraphicBBS::getCurrentDiagramDescription()
1111 return _tabsMgr->GetDescription();
1114 //=========================================================================
1116 std::string wxGUIEditorGraphicBBS::getCurrentDiagramAuthor()
1118 return _tabsMgr->GetAuthor();
1121 //=========================================================================
1124 std::string wxGUIEditorGraphicBBS::getCurrentDiagramCategory()
1126 return _tabsMgr->GetCategory();
1129 //=========================================================================
1131 bool wxGUIEditorGraphicBBS::isCurrentDiagramComplexBox()
1133 return _tabsMgr->isActualDiagramComplexBox();
1137 } // EO namespace bbtk