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"));
153 toolbar->EnableTool(ID_ADDCOMPLEXBOXINPUT, false);
154 toolbar->EnableTool(ID_ADDCOMPLEXBOXOUTPUT, false);
155 toolbar->AddSeparator();
156 toolbar->AddTool(ID_UNDO, _T("Undo"),bmp_undo, wxNullBitmap, wxITEM_NORMAL, _T("Undo"), _T("Undo"));
157 toolbar->AddTool(ID_REDO, _T("Redo"),bmp_redo, wxNullBitmap, wxITEM_NORMAL, _T("Redo"), _T("Redo"));
158 toolbar->AddSeparator();
159 toolbar->AddTool(ID_EDITPROPERTIES, _T("Edit diagram properties"),bmp_editProperties, wxNullBitmap, wxITEM_NORMAL, _T("Edit diagram properties"), _T("Edit diagram properties"));
160 toolbar->EnableTool(ID_EDITPROPERTIES, false);
162 toolbar->EnableTool(ID_UNDO, false);
163 toolbar->EnableTool(ID_REDO, false);
164 toolbar->SetMargins(2, 2);
169 // connect command event handlers
171 Connect(ID_NEW, wxEVT_COMMAND_TOOL_CLICKED,
172 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnCreateNewTab));
173 Connect(ID_OPEN, wxEVT_COMMAND_TOOL_CLICKED,
174 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnOpenDiagram));
175 Connect(ID_SAVE_DIAGRAM, wxEVT_COMMAND_TOOL_CLICKED,
176 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnSaveActualDiagram)); //DFCH
177 Connect(ID_SAVE_AS_DIAGRAM, wxEVT_COMMAND_TOOL_CLICKED,
178 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnSaveAsActualDiagram)); //DFCH
181 wxEVT_COMMAND_TOOL_CLICKED,
182 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnExecuteActualDiagram));
185 wxEVT_COMMAND_TOOL_CLICKED,
186 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnDeleteAllBoxesActualDiagram));
189 wxEVT_COMMAND_TOOL_CLICKED,
190 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnCenterViewActualDiagram));
191 Connect(ID_BTNBOX, wxEVT_COMMAND_TOOL_CLICKED,
192 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnClickBtnBox));
195 wxEVT_COMMAND_TOOL_CLICKED,
196 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnClickBtnExecutableBox));
197 Connect(ID_BTNCOMPLEXBOX, wxEVT_COMMAND_TOOL_CLICKED,
198 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnClickBtnComplexBox));
199 Connect(ID_ADDCOMPLEXBOXINPUT, wxEVT_COMMAND_TOOL_CLICKED,
200 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnAddComplexBoxInput));
201 Connect(ID_ADDCOMPLEXBOXOUTPUT, wxEVT_COMMAND_TOOL_CLICKED,
202 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnAddComplexBoxOutput));
203 Connect(ID_UNDO,wxEVT_COMMAND_TOOL_CLICKED, wxCommandEventHandler(wxGUIEditorGraphicBBS::OnUndo));
204 Connect(ID_REDO,wxEVT_COMMAND_TOOL_CLICKED, wxCommandEventHandler(wxGUIEditorGraphicBBS::OnRedo));
205 Connect(ID_CHANGENAME, wxEVT_COMMAND_RIGHT_CLICK, wxCommandEventHandler(wxGUIEditorGraphicBBS::OnChangeName));
206 Connect(ID_EDITPROPERTIES,wxEVT_COMMAND_TOOL_CLICKED, wxCommandEventHandler(wxGUIEditorGraphicBBS::OnEditDiagramProperties));
209 //=========================================================================
210 void wxGUIEditorGraphicBBS::initHelpHTMLBrowser() {
212 _helpHtmlBrowser = new WxGUIHtmlBrowser(this, wxSize(200, 0));
218 //=========================================================================
219 void wxGUIEditorGraphicBBS::initMenu() {
220 // Create File menu and its items
221 wxMenu *fileMenu = new wxMenu();
222 fileMenu->Append(ID_NEW, _T("New diagram"), _T("New"));
223 fileMenu->Append(ID_SAVE_DIAGRAM, _T("Save Diagram"), _T("Save Diagram")); //DFCH
224 fileMenu->Append(ID_SAVE_AS_DIAGRAM, _T("Save Diagram As"),
225 _T("Save Diagram As")); //DFCH
226 fileMenu->Append(ID_OPEN_BBS, _T("Open BBS"), _T("Open BBS"));
228 fileMenu->Append(ID_OPEN, _T("Open a diagram"), _T("Open a diagram"));
229 fileMenu->Append(ID_SAVE_AS_BBS, _T("Save BBS"), _T("Save BBS"));
230 fileMenu->Append(ID_SAVE_AS_COMPLEXBOX, _T("Save complex box"),
231 _T("Save complex box"));
232 fileMenu->Append(wxID_EXIT, _T("E&xit"), _T("Exit"));
234 Connect(ID_NEW, wxEVT_COMMAND_MENU_SELECTED,
235 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnCreateNewTab));
236 Connect(ID_SAVE_DIAGRAM, wxEVT_COMMAND_MENU_SELECTED,
237 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnSaveActualDiagram)); //DFCH
238 Connect(ID_SAVE_AS_DIAGRAM, wxEVT_COMMAND_MENU_SELECTED,
239 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnSaveAsActualDiagram));
240 Connect(ID_OPEN_BBS, wxEVT_COMMAND_MENU_SELECTED,
241 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnOpenBBS));
242 Connect(ID_SAVE_AS_BBS, wxEVT_COMMAND_MENU_SELECTED,
243 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnSaveActualBBS));
245 ID_SAVE_AS_COMPLEXBOX,
246 wxEVT_COMMAND_MENU_SELECTED,
247 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnSaveActualComplexBox));
248 Connect(wxID_EXIT, wxEVT_COMMAND_MENU_SELECTED,
249 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnExit));
251 // Create Help menu and its items
252 wxMenu *editMenu = new wxMenu;
253 editMenu->Append(ID_COPY_TO_COMPLEXDIAGRAM,
254 _T("Copy selected to complex box"),
255 _T("Creates a new complex box diagram with selected boxes"));
258 ID_COPY_TO_COMPLEXDIAGRAM,
259 wxEVT_COMMAND_MENU_SELECTED,
260 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnCopySelectedToComplexDiagram));
262 // Create Help menu and its items
263 wxMenu *helpMenu = new wxMenu;
264 helpMenu->Append(wxID_ABOUT, _T("&About..."), _T("About"));
265 helpMenu->Append(ID_HELP_BBEDITOR, _T("&Help..."), _T("Help"));
266 Connect(ID_HELP_BBEDITOR, wxEVT_COMMAND_MENU_SELECTED,
267 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnHelpBBeditor));
270 wxMenu *menuTools = new wxMenu;
271 menuTools->Append(ID_bbEditor_Tool_Menu_CreatePackage,
272 _T("Create &package") );
273 menuTools->Append(ID_bbEditor_Tool_Menu_CreateBlackBox,
274 _T("Create &blackbox") );
275 menuTools->Append(ID_bbEditor_Tool_Menu_PlugPackage, _T("Plug package") );
276 menuTools->Append(ID_bbEditor_Tool_Menu_EditConfig, _T("&Edit bbtk config") );
277 menuTools->Append(ID_bbEditor_Tool_Menu_ShowHTMLDoc,
278 _T("Show &HTML documentation") );
279 menuTools->Append(ID_bbEditor_Tool_Menu_CreateIndex, _T("&Generate index") );
281 Connect(ID_bbEditor_Tool_Menu_CreatePackage, wxEVT_COMMAND_MENU_SELECTED,
282 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnCreatePackage));
283 Connect(ID_bbEditor_Tool_Menu_CreateBlackBox, wxEVT_COMMAND_MENU_SELECTED,
284 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnCreateBlackBox));
285 Connect(ID_bbEditor_Tool_Menu_PlugPackage, wxEVT_COMMAND_MENU_SELECTED,
286 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnPlugPackage));
287 Connect(ID_bbEditor_Tool_Menu_EditConfig, wxEVT_COMMAND_MENU_SELECTED,
288 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnEditConfig));
289 Connect(ID_bbEditor_Tool_Menu_ShowHTMLDoc, wxEVT_COMMAND_MENU_SELECTED,
290 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnShowHTMLDoc));
291 Connect(ID_bbEditor_Tool_Menu_CreateIndex, wxEVT_COMMAND_MENU_SELECTED,
292 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnCreateIndex));
294 // Append the created menu to the menu bar
295 wxMenuBar *menuBar = new wxMenuBar();
296 menuBar->Append(fileMenu, _T("&File") );
297 menuBar->Append(editMenu, _T("&Edit") );
298 menuBar->Append(menuTools, _T("&Tool") );
299 menuBar->Append(helpMenu, _T("&Help") );
301 // Attach this menu bar to the frame
305 //=========================================================================
306 void wxGUIEditorGraphicBBS::initTabPanelsManager()
308 _notebook = new wxAuiNotebook(this, wxID_NOTEBOOK, wxDefaultPosition,
309 wxDefaultSize, wxAUI_NB_TOP | wxAUI_NB_TAB_MOVE
310 | wxAUI_NB_CLOSE_ON_ACTIVE_TAB | wxAUI_NB_TAB_FIXED_WIDTH
311 | wxAUI_NB_WINDOWLIST_BUTTON);
312 _tabsMgr = new wxTabPanelsManager(this);
313 _frameAUIMgr->AddPane(_notebook, wxAuiPaneInfo().CenterPane());
316 //=========================================================================
317 void wxGUIEditorGraphicBBS::initPackageBrowser()
319 _pkgBrowser = new WxGUIPackageBrowser2(this);
320 _pkgBrowser->IncludeAll();
321 _frameAUIMgr->AddPane(_pkgBrowser, wxAuiPaneInfo().Left().MinSize(30, 500).BestSize(750,500).CloseButton(false));
324 //================================================================
326 void wxGUIEditorGraphicBBS::DoRegeneratePackageDoc(const std::string& pack)
328 std::string mess("Regenerating doc for package '");
332 mess = "Regenerating doc for all packages";
335 mess += " ... please wait";
337 SetStatusText(std2wx(mess));
345 command += ConfigurationFile::GetInstance().Get_bin_path();
346 command += ConfigurationFile::GetInstance().Get_file_separator();
347 command += "bbRegeneratePackageDoc";
352 command += " " + pack + " -q";
353 bbtkMessage("debug",1,"Executing system command '"<<command<<"'"<<std::endl);
355 if (!system(command.c_str())) {
356 SetStatusText(_T("Done !"));
358 wxMessageBox(_T("Done !"),_T("Regenerate package '")
359 +std2wx(pack)+_T("' doc"),
360 wxOK | wxICON_INFORMATION);
363 SetStatusText(_T("Done !"));
364 wxString err(_T("An error occured while running '"));
365 err += bbtk::std2wx(command) + _T("'");
366 wxMessageBox(err, _T("Regenerate package doc"), wxOK | wxICON_ERROR);
370 //================================================================
371 void wxGUIEditorGraphicBBS::DoRegenerateBoxesLists() {
372 SetStatusText(_T("Regenerating boxes lists ... please wait"));
379 command += ConfigurationFile::GetInstance().Get_bin_path();
380 command += ConfigurationFile::GetInstance().Get_file_separator();
381 command += "bbRegenerateBoxesLists";
388 bbtkMessage("debug",1,"Executing system command '"<<command<<"'"<<std::endl);
390 if (!system(command.c_str())) {
391 SetStatusText(_T("Done !"));
393 wxMessageBox(_T("Done !"),_T("Regenerate boxes lists"),
394 wxOK | wxICON_INFORMATION);
397 SetStatusText(_T("Done !"));
398 wxString err(_T("An error occured while running '"));
399 err += bbtk::std2wx(command) + _T("'");
400 wxMessageBox(err, _T("Regenerate boxes lists"), wxOK | wxICON_ERROR);
404 //================================================================
405 void wxGUIEditorGraphicBBS::RegenerateAll() {
406 DoRegeneratePackageDoc("-a");
407 DoRegenerateBoxesLists();
410 //================================================================
412 wxAuiNotebook* wxGUIEditorGraphicBBS::getAuiNotebook() {
416 //================================================================
418 void wxGUIEditorGraphicBBS::displayBlackBoxInfo(std::string packageName,
419 std::string boxName) {
420 if (_actualPkgBrowserPkgName != packageName || _actualPkgBrowserBoxName
422 _actualPkgBrowserPkgName = packageName;
423 _actualPkgBrowserBoxName = boxName;
425 BlackBoxDescriptor::Pointer descriptor =
426 GObjectsMVCFactory::getInstance()->getBlackBoxDescriptor(
427 packageName, boxName);
428 _pkgBrowser->WxGUIBlackBoxListUserOnSelected(descriptor.get());
432 //=========================================================================
434 void wxGUIEditorGraphicBBS::editBlackBox(GBlackBoxModel *bbmodel) {
435 wxBlackBoxEditionDialog* dialog =
436 new wxBlackBoxEditionDialog(this, bbmodel);
440 //=========================================================================
442 bool wxGUIEditorGraphicBBS::boxNameExists(std::string boxname) {
444 return this->_tabsMgr->getActualTabPanel()->getSceneManager()->boxExist(boxname);
447 //=========================================================================
449 void wxGUIEditorGraphicBBS::updateStatusBar(std::string textStatus) {
450 SetStatusText(crea::std2wx(textStatus));
453 //=========================================================================
455 void wxGUIEditorGraphicBBS::executeScript(std::string script) {
456 std::string separator =
457 ConfigurationFile::GetInstance().Get_file_separator();
458 std::string dir = ConfigurationFile::GetInstance().Get_default_temp_dir();
459 std::string filename = dir + separator + "tmp_bbtk.bbs";
462 tempFile.open(filename.c_str());
466 std::string command = "";
469 command += "start /b ";
472 // command += "\""+ crea::System::GetExecutablePath();
474 // command += separator + "../../../bbi.app/Contents/MacOS";
478 command += "\"" + filename + "\"";
484 printf("RaC wxGUIEditorGraphicBBS::executeScript %s \n", command.c_str());
485 system(command.c_str());
488 //=========================================================================
489 std::string wxGUIEditorGraphicBBS::CheckExtension(std::string filename, std::string extension) {
490 if(filename.size() > extension.size() ){
491 if( (filename.compare(filename.size()-extension.size(), extension.size(),extension)) !=0 ){
492 filename.append(extension);
495 filename.append(extension);
499 //=========================================================================
501 //=========================================================================
503 void wxGUIEditorGraphicBBS::OnCreateNewTab(wxCommandEvent& event) {
504 _tabsMgr->addNewTab();
505 refreshGUIControls();
508 void wxGUIEditorGraphicBBS::OnUndo(wxCommandEvent& event) {
509 unsigned short disable;
513 _tabsMgr->loadTempDiagram(0);
514 disable = _tabsMgr->getUndoState(stundo);
517 std::string name = _tabsMgr->GetNameTabPanel();
518 if(name[name.length() - 1] == '*')
520 name =name.substr(0,name.length()-1);
522 _tabsMgr->SetNameTabPanel(wxString (name.c_str(), wxConvUTF8));
525 GetToolBar()->EnableTool(ID_UNDO,disable);
526 GetToolBar()->SetToolShortHelp(ID_UNDO,crea::std2wx(stundo));
527 GetToolBar()->EnableTool(ID_REDO,_tabsMgr->getRedoState(stredo));
528 GetToolBar()->SetToolShortHelp(ID_REDO,crea::std2wx(stredo));
529 refreshGUIControls();
532 //=========================================================================
534 void wxGUIEditorGraphicBBS::OnRedo(wxCommandEvent& event) {
535 unsigned short disable;
539 _tabsMgr->loadTempDiagram(1);
540 std::string name = _tabsMgr->GetNameTabPanel();
541 if(name[name.length() - 1] != '*')
543 _tabsMgr->SetNameTabPanel(wxString (name.c_str(), wxConvUTF8));
544 GetToolBar()->EnableTool(ID_UNDO,_tabsMgr->getUndoState(stundo));
545 GetToolBar()->SetToolShortHelp(ID_UNDO,crea::std2wx(stundo));
546 GetToolBar()->EnableTool(ID_REDO,_tabsMgr->getRedoState(stredo));
547 GetToolBar()->SetToolShortHelp(ID_REDO,crea::std2wx(stredo));
548 refreshGUIControls();
551 void wxGUIEditorGraphicBBS::OnChangeName(wxCommandEvent& event){
554 //=========================================================================
556 void wxGUIEditorGraphicBBS::OnEditDiagramProperties(wxCommandEvent& event)
558 wxDiagramPropertiesEditionDialog* dialog =
559 new wxDiagramPropertiesEditionDialog(this);
563 //=========================================================================
565 void wxGUIEditorGraphicBBS::OnExecuteActualDiagram(wxCommandEvent& event) {
566 std::string script1 = _tabsMgr->getActualDiagramBBS(true);
567 cout << endl << "RaC wxGUIEditorGraphicBBS::executeActualDiagram SCRIPT"
569 cout << script1 << endl;
571 std::string script2 = _tabsMgr->getActualDiagramBBS(false);
572 executeScript(script2);
575 //=========================================================================
577 //=========================================================================
578 void wxGUIEditorGraphicBBS::OnOpenBBS(wxCommandEvent& event) {
579 wxFileDialog * openFileDialog = new wxFileDialog(this, wxT("Open BBS"),
580 wxEmptyString, wxT("NewBBS"), wxT("*.bbs"), wxOPEN);
581 if (openFileDialog->ShowModal() == wxID_OK) {
582 wxString fileName = openFileDialog->GetPath();
584 _tabsMgr->addNewTab(openFileDialog->GetFilename());
586 bbtk::InterpreterBBS::Pointer I = bbtk::InterpreterBBS::New(
587 this->_tabsMgr->getActualTabPanel()->getSceneManager(),
588 _pkgBrowser->GetFactory());
590 // We tell the interpreter to throw exceptions on error
592 // Interpret the file supposed to define a box called 'Processing'
593 I->InterpretFile((const char*) (fileName.mb_str()));
595 refreshGUIControls();
598 void wxGUIEditorGraphicBBS::SaveActualBBS(std::string filename) {
601 //EED file.open(fileName.c_str());
602 file.open(filename.c_str());
603 std::string content = "";
604 // writing file header
605 content += "# ----------------------------------\n";
606 content += "# - BBTKGEditor v 1.3 BBS BlackBox Script\n";
610 content += "# ----------------------------------\n";
612 content += _tabsMgr->getActualDiagramBBS();
617 void wxGUIEditorGraphicBBS::OnSaveActualBBS(wxCommandEvent& event) {
618 wxFileDialog * saveFileDialog = new wxFileDialog(this,
619 wxT("Save actual BBS"), wxEmptyString, wxT("NewBBS"),
620 wxT("*.bbs"), wxSAVE | wxOVERWRITE_PROMPT);
621 if (saveFileDialog->ShowModal() == wxID_OK) {
622 wxString fileName = saveFileDialog->GetPath();
623 std::string filename = (const char*) (fileName.mb_str());
624 filename=CheckExtension (filename, ".bbs");
625 SaveActualBBS(filename);
630 void wxGUIEditorGraphicBBS::AskComplexBoxConfiguration() {
631 std::string cbName = _tabsMgr->GetCbName();
632 std::string paName = _tabsMgr->GetCbPackageName();
634 wxTextEntryDialog *cbNameDialog = new wxTextEntryDialog(this,
635 wxT("Complex Box name"));
636 wxTextEntryDialog *paNameDialog = new wxTextEntryDialog(this,
637 wxT("Package name"));
639 cbNameDialog->SetValue(wxString(cbName.c_str(), wxConvUTF8));
640 paNameDialog->SetValue(wxString(paName.c_str(), wxConvUTF8));
642 if (cbNameDialog->ShowModal() == wxID_OK) {
643 wxString complexboxname = cbNameDialog->GetValue();
644 cbName = (const char*) (complexboxname.mb_str());
647 if (paNameDialog->ShowModal() == wxID_OK) {
648 wxString packagename = paNameDialog->GetValue();
649 paName = (const char*) (packagename.mb_str());
652 _tabsMgr->SetCbName(cbName);
653 _tabsMgr->SetCbPackageName(paName);
656 //=========================================================================
658 void wxGUIEditorGraphicBBS::SaveActualComplexBox(std::string filename) {
660 file.open(filename.c_str());
662 std::string content = "";
664 // writing file header
665 content += "# ----------------------------------\n";
666 content += "# - BBTKGEditor v 1.3 BBS BlackBox Script (Complex Box)\n";
670 content += "# ----------------------------------\n";
672 content += _tabsMgr->getActualComplexBoxBBS();
677 //=========================================================================
679 void wxGUIEditorGraphicBBS::OnSaveActualComplexBox(wxCommandEvent& event) {
680 wxFileDialog * saveFileDialog = new wxFileDialog(this,
681 wxT("Save Complex Box BBS"), wxEmptyString,
682 _T("ComplexBoxName"), wxT("*.bbs"), wxSAVE
683 | wxOVERWRITE_PROMPT);
684 if (saveFileDialog->ShowModal() == wxID_OK) {
685 wxString fileName = saveFileDialog->GetPath();
686 std::string filename = (const char*) (fileName.mb_str());
687 filename=CheckExtension (filename, ".bbs");
688 SaveActualComplexBox(filename);
692 //=========================================================================
693 void wxGUIEditorGraphicBBS::SaveActualDiagram(std::string filename) {
695 file.open(filename.c_str());
697 std::string content = "";
699 // writing file header
700 content += "# ----------------------------------\n";
701 content += "# - BBTKGEditor v 1.3 BBG BlackBox Diagram file\n";
707 content += "# ----------------------------------\n";
709 content += "APP_START\n";
710 _tabsMgr->saveActualDiagram(content, filename); //DFCH
711 content += "APP_END\n";
716 //=========================================================================
717 void wxGUIEditorGraphicBBS::SaveTempActualDiagram(const std::string &action)
721 std::string name = _tabsMgr->GetNameTabPanel();
722 if(name[name.length() - 1] != '*')
724 _tabsMgr->SetNameTabPanel(wxString (name.c_str(), wxConvUTF8));
725 _tabsMgr->saveTempActualDiagram(action);
726 GetToolBar()->EnableTool(ID_UNDO,_tabsMgr->getUndoState(stundo));
727 GetToolBar()->SetToolShortHelp(ID_UNDO,crea::std2wx(stundo));
728 GetToolBar()->EnableTool(ID_REDO,_tabsMgr->getRedoState(stredo));
729 GetToolBar()->SetToolShortHelp(ID_REDO,crea::std2wx(stredo));
732 //=========================================================================
734 //The following method allows to save the current diagram asking the filename
736 void wxGUIEditorGraphicBBS::SaveCurrentDiagramAs() {
737 wxFileDialog * saveFileDialog = new wxFileDialog(this,
738 wxT("Save current diagram"), wxEmptyString, wxT("NewDiagram"),
739 wxT("*.bbg"), wxSAVE | wxOVERWRITE_PROMPT);
740 if (saveFileDialog->ShowModal() == wxID_OK) {
741 //_tabsMgr->SetNameTabPanel(saveFileDialog->GetFilename());
742 wxString pathfileName = saveFileDialog->GetPath();
743 std::string pathfilename = (const char*) (pathfileName.mb_str());
744 pathfilename=CheckExtension (pathfilename, ".bbg");
746 //modify the tab name accordingly
747 wxString fileName = saveFileDialog->GetFilename();
748 std::string filename = (const char*) (fileName.mb_str());
749 filename=CheckExtension (filename, ".bbg");
750 _tabsMgr->SetNameTabPanel( wxString (filename.c_str(), wxConvUTF8) );
752 std::string pathfilenamebbs = pathfilename;
753 pathfilenamebbs[pathfilenamebbs.length() - 1] = 's';
754 if (_tabsMgr->isActualDiagramComplexBox() == false) {
755 SaveActualDiagram(pathfilename);
756 SaveActualBBS(pathfilenamebbs);
758 AskComplexBoxConfiguration();
759 SaveActualDiagram(pathfilename);
760 SaveActualComplexBox(pathfilenamebbs);
761 } //if isActualDiagramComplexBox
762 } // if saveFileDialog
764 //=========================================================================
766 void wxGUIEditorGraphicBBS::OnSaveActualDiagram(wxCommandEvent& event) {
767 std::string pathfilename = _tabsMgr->GetCurrentTabPanelPath();
768 if (pathfilename.empty()) {
769 SaveCurrentDiagramAs();
771 std::string pathfilenamebbs = pathfilename;
772 pathfilenamebbs[pathfilenamebbs.length() - 1] = 's';
774 if (_tabsMgr->isActualDiagramComplexBox() == false) {
775 std::string name = _tabsMgr->GetNameTabPanel();
776 if(name[name.length() - 1] == '*')
778 name =name.substr(0,name.length()-1);
780 _tabsMgr->SetNameTabPanel(wxString (name.c_str(), wxConvUTF8));
781 SaveActualDiagram(pathfilename);
782 SaveActualBBS(pathfilenamebbs);
784 AskComplexBoxConfiguration();
785 SaveActualDiagram(pathfilename);
786 SaveActualComplexBox(pathfilenamebbs);
787 } //if isActualDiagramComplexBox
790 //=========================================================================
792 void wxGUIEditorGraphicBBS::OnSaveAsActualDiagram(wxCommandEvent& event) {
793 SaveCurrentDiagramAs();
795 //=========================================================================
797 void wxGUIEditorGraphicBBS::refreshGUIControls() {
800 //RaC2012 2ndHackFest Next line seems weird ... To keep in mind for other devels
801 wxToolBar* toolbar = GetToolBar();
802 if (_tabsMgr->isActualDiagramComplexBox()) {
803 toolbar->ToggleTool(ID_BTNCOMPLEXBOX, true);
804 toolbar->EnableTool(ID_ADDCOMPLEXBOXINPUT, true);
805 toolbar->EnableTool(ID_ADDCOMPLEXBOXOUTPUT, true);
807 GetMenuBar()->GetMenu(0)->Enable(ID_SAVE_AS_COMPLEXBOX, true);
808 GetMenuBar()->GetMenu(0)->Enable(ID_SAVE_AS_BBS, false);
810 toolbar->ToggleTool(ID_BTNCOMPLEXBOX, false);
811 toolbar->EnableTool(ID_ADDCOMPLEXBOXINPUT, false);
812 toolbar->EnableTool(ID_ADDCOMPLEXBOXOUTPUT, false);
814 GetMenuBar()->GetMenu(0)->Enable(ID_SAVE_AS_COMPLEXBOX, false);
815 GetMenuBar()->GetMenu(0)->Enable(ID_SAVE_AS_BBS, true);
818 //RaC2012 2ndHackFest
819 GetToolBar()->EnableTool(ID_EDITPROPERTIES,true);
821 GetToolBar()->EnableTool(ID_UNDO,_tabsMgr->getUndoState(stundo));
822 GetToolBar()->SetToolShortHelp(ID_UNDO,crea::std2wx(stundo));
823 GetToolBar()->EnableTool(ID_REDO,_tabsMgr->getRedoState(stredo));
824 GetToolBar()->SetToolShortHelp(ID_REDO,crea::std2wx(stredo));
826 if (_tabsMgr->getNumActualSelectedObjects() > 0) {
827 GetMenuBar()->GetMenu(1)->Enable(ID_COPY_TO_COMPLEXDIAGRAM, true);
829 ///TODO Fix the possibility to say from the SceneManager to the GUI to refresh the options
830 GetMenuBar()->GetMenu(1)->Enable(ID_COPY_TO_COMPLEXDIAGRAM, true);
835 //=========================================================================
837 void wxGUIEditorGraphicBBS::OnDeleteAllBoxesActualDiagram(wxCommandEvent& event) {
838 wxMessageDialog *dial = new wxMessageDialog(NULL,
839 wxT("Are you sure to delete all boxes of the diagram?"),
840 wxT("Delete all boxes"), wxYES_NO | wxNO_DEFAULT
842 if (dial->ShowModal() == wxID_YES) {
843 _tabsMgr->deleteAllBoxesActualDiagram();
847 //=========================================================================
849 void wxGUIEditorGraphicBBS::OnCenterViewActualDiagram(wxCommandEvent& event) {
850 _tabsMgr->centerViewActualDiagram();
853 //=========================================================================
855 void wxGUIEditorGraphicBBS::OnOpenDiagram(wxCommandEvent& event) {
856 wxFileDialog * openFileDialog = new wxFileDialog(this, wxT("Open diagram"),
857 wxEmptyString, wxT(""), wxT("*.bbg"), wxOPEN | wxFILE_MUST_EXIST);
858 printf("SCP: wxGUIEditorGraphicBBS::OnOpenDiagram \n");
859 if (openFileDialog->ShowModal() == wxID_OK) {
860 wxString fileName = openFileDialog->GetPath();
861 ifstream inputStream;
862 std::string fName = (const char*) (fileName.mb_str());
864 inputStream.open(fName.c_str());
865 assert(inputStream.good()); // fails
866 _tabsMgr->addNewTab(openFileDialog->GetFilename());
867 _tabsMgr->loadDiagram(inputStream, fName);
868 _tabsMgr->saveTempActualDiagram("load diagram");
869 GetToolBar()->EnableTool(ID_UNDO, false);
870 GetToolBar()->EnableTool(ID_UNDO, false);
873 refreshGUIControls();
876 //=========================================================================
879 void wxGUIEditorGraphicBBS::OnClickBtnBox(wxCommandEvent& event) {
880 BlackBoxDescriptor *bbDes = _pkgBrowser->GetActualSelected();
882 std::string typeName = bbDes->GetTypeName();
883 std::string packageName = bbDes->GetPackage()->GetName();
885 wxGEditorTabPanel *pnl = this->_tabsMgr->getActualTabPanel();
889 wxVtkSceneManager *scn = pnl->getSceneManager();
890 scn->createGBlackBox(50, 50, packageName, typeName);
894 SaveTempActualDiagram("New Box");
899 //=========================================================================
901 void wxGUIEditorGraphicBBS::OnClickBtnExecutableBox(wxCommandEvent& event) {
903 wxGEditorTabPanel *pnl = this->_tabsMgr->getActualTabPanel();
906 wxVtkSceneManager *scn = pnl->getSceneManager();
907 if( scn->MakeBoxExecutable() )
908 std::cout<<"DFCH: wxGUIEditorGraphicBBS::OnClickBtnExecutableBox...successful"<<std::endl;
910 std::cout<<"DFCH: wxGUIEditorGraphicBBS::OnClickBtnExecutableBox...Error!!"<<std::endl;
916 //=========================================================================
918 void wxGUIEditorGraphicBBS::OnClickBtnComplexBox(wxCommandEvent& event) {
919 wxToolBar* toolbar = GetToolBar();
920 bool temp = toolbar->GetToolState(ID_BTNCOMPLEXBOX);
928 //=========================================================================
930 void wxGUIEditorGraphicBBS::OnAddComplexBoxInput(wxCommandEvent& event) {
931 wxTextEntryDialog *nameDialog = new wxTextEntryDialog(this,
932 wxT("Name of input port"));
933 if (nameDialog->ShowModal() == wxID_OK) {
934 wxString fileName = nameDialog->GetValue();
935 if (!fileName.IsEmpty()) {
936 std::string portName = (const char*) (fileName.mb_str());
937 _tabsMgr->addActualDiagramComplexInputPort(portName);
942 //=========================================================================
944 void wxGUIEditorGraphicBBS::OnAddComplexBoxOutput(wxCommandEvent& event) {
945 wxTextEntryDialog *nameDialog = new wxTextEntryDialog(this,
946 wxT("Name of output port"));
947 if (nameDialog->ShowModal() == wxID_OK) {
948 wxString fileName = nameDialog->GetValue();
949 if (!fileName.IsEmpty()) {
950 std::string portName = (const char*) (fileName.mb_str());
951 _tabsMgr->addActualDiagramComplexOutputPort(portName);
956 //=========================================================================
958 void wxGUIEditorGraphicBBS::OnCopySelectedToComplexDiagram(
959 wxCommandEvent& event) {
960 _tabsMgr->copySelectedBBoxesToComplexDiagram();
963 void wxGUIEditorGraphicBBS::OnHelpBBeditor(wxCommandEvent& event) {
964 printf("wxGUIEditorGraphicBBS::OnHelpBBeditor ....not implemented..\n");
967 //=========================================================================
968 void wxGUIEditorGraphicBBS::OnCreatePackage(wxCommandEvent& event) {
970 bbtkSystemTools::CreatePackage();
973 //=========================================================================
974 void wxGUIEditorGraphicBBS::OnCreateBlackBox(wxCommandEvent& event) {
975 bbtkSystemTools::CreateBlackBox();
977 //=========================================================================
978 void wxGUIEditorGraphicBBS::OnPlugPackage(wxCommandEvent& event) {
979 //DFGO2012 Plug Package functionnalities
980 long style = wxDD_DEFAULT_STYLE | wxDD_DIR_MUST_EXIST;
983 _T("Select package directory"),
989 userResponse = FD->ShowModal();
990 if(userResponse==wxID_OK)
992 std::string path = wx2std (FD->GetPath()) ;
993 std::string fname = path + "/bbtkPackage";
994 std::cout << "Path chosen = \"" << FD->GetPath() << "\"" << std::endl;
995 if ( Utilities::FileExists( fname ) )
998 f.open(fname.c_str());
1003 bbtk::ConfigurationFile::GetInstance().AddPackagePathsAndWrite( path );
1005 DoRegeneratePackageDoc(pname);
1006 DoRegenerateBoxesLists();
1008 _pkgBrowser->RebuildList();
1010 wxMessageBox(_T("Package successfully plugged. Please restart bbEditor to see the new package in the package browser."),_T("Plug package"),wxOK | wxICON_INFORMATION);
1011 userResponse = wxID_CANCEL;
1015 std::string err = "The directory \"" + path + "\" does not contain a 'bbtkPackage' file.";
1018 err += "\nNote: If you are on Linux please select the folder and click \"Open\", don't enter in it.";
1022 wxMessageBox(crea::std2wx(err), _T("Plug package"),wxOK | wxICON_ERROR);
1023 // THE FOLLOWING LINE GIVES ERRORS BECAUSE IT IS NECESSARY TO USE std2wx
1024 //wxMessageBox( _T( err) , _T("Plug package"),wxOK | wxICON_ERROR);
1027 }while(userResponse != wxID_CANCEL);
1030 //=========================================================================
1031 void wxGUIEditorGraphicBBS::OnEditConfig(wxCommandEvent& event) {
1032 printf("EED wxGUIEditorGraphicBBS::OnEditConfig ... not implemented ..\n");
1034 //=========================================================================
1036 void wxGUIEditorGraphicBBS::OnShowHTMLDoc(wxCommandEvent& event) {
1038 if (_helpHtmlBrowser != NULL){
1039 _frameAUIMgr->DetachPane(_helpHtmlBrowser);
1040 _helpHtmlBrowser->Destroy();
1042 initHelpHTMLBrowser();
1043 _frameAUIMgr->AddPane(_helpHtmlBrowser, wxAuiPaneInfo().Right().MinSize(200, 200));
1044 _frameAUIMgr->Update();
1045 refreshGUIControls();
1049 //=========================================================================
1050 void wxGUIEditorGraphicBBS::OnCreateIndex(wxCommandEvent& event) {
1051 printf("EED wxGUIEditorGraphicBBS::OnCreateIndex ... not implemented ..\n");
1054 //=========================================================================
1056 void wxGUIEditorGraphicBBS::OnExit(wxCommandEvent& event) {
1060 //=========================================================================
1062 void wxGUIEditorGraphicBBS::enableComplexBox() {
1063 _tabsMgr->setActualDiagramComplexBox(true);
1064 refreshGUIControls();
1067 //=========================================================================
1069 void wxGUIEditorGraphicBBS::disableComplexBox() {
1070 _tabsMgr->setActualDiagramComplexBox(false);
1071 refreshGUIControls();
1074 //=========================================================================
1076 void wxGUIEditorGraphicBBS::setCurrentDiagramDescription(std::string description)
1078 _tabsMgr->SetDescription(description);
1081 //=========================================================================
1083 void wxGUIEditorGraphicBBS::setCurrentDiagramAuthor(std::string author)
1085 _tabsMgr->SetAuthor(author);
1088 //=========================================================================
1090 void wxGUIEditorGraphicBBS::setCurrentDiagramCategory(std::string category)
1092 _tabsMgr->SetCategory(category);
1095 //=========================================================================
1097 std::string wxGUIEditorGraphicBBS::getCurrentDiagramDescription()
1099 return _tabsMgr->GetDescription();
1102 //=========================================================================
1104 std::string wxGUIEditorGraphicBBS::getCurrentDiagramAuthor()
1106 return _tabsMgr->GetAuthor();
1109 //=========================================================================
1112 std::string wxGUIEditorGraphicBBS::getCurrentDiagramCategory()
1114 return _tabsMgr->GetCategory();
1117 //=========================================================================
1119 bool wxGUIEditorGraphicBBS::isCurrentDiagramComplexBox()
1121 return _tabsMgr->isActualDiagramComplexBox();
1125 } // EO namespace bbtk