2 # ---------------------------------------------------------------------
4 # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
6 # Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton
8 # This software is governed by the CeCILL-B license under French law and
9 # abiding by the rules of distribution of free software. You can use,
10 # modify and/ or redistribute the software under the terms of the CeCILL-B
11 # license as circulated by CEA, CNRS and INRIA at the following URL
12 # http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
13 # or in the file LICENSE.txt.
15 # As a counterpart to the access to the source code and rights to copy,
16 # modify and redistribute granted by the license, users are provided only
17 # with a limited warranty and the software's author, the holder of the
18 # economic rights, and the successive licensors have only limited
21 # The fact that you are presently reading this means that you have had
22 # knowledge of the CeCILL-B license and that you accept its terms.
23 # ------------------------------------------------------------------------
26 /*=========================================================================
32 =========================================================================*/
34 /* ---------------------------------------------------------------------
36 * Copyright (c) CREATIS-LRMN (Centre de Recherche en Imagerie Medicale)
37 * Authors : Eduardo Davila, Laurent Guigues, Jean-Pierre Roux
39 * This software is governed by the CeCILL-B license under French law and
40 * abiding by the rules of distribution of free software. You can use,
41 * modify and/ or redistribute the software under the terms of the CeCILL-B
42 * license as circulated by CEA, CNRS and INRIA at the following URL
43 * http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
44 * or in the file LICENSE.txt.
46 * As a counterpart to the access to the source code and rights to copy,
47 * modify and redistribute granted by the license, users are provided only
48 * with a limited warranty and the software's author, the holder of the
49 * economic rights, and the successive licensors have only limited
52 * The fact that you are presently reading this means that you have had
53 * knowledge of the CeCILL-B license and that you accept its terms.
54 * ------------------------------------------------------------------------ */
58 * \brief Class bbtk::WxInterfaceEditorGraphicBBS .
61 #include "bbtkwxGUIEditorGraphicBBS.h"
63 #include "creaSystem.h"
64 //must go #include "bbtkUtilities.h"
65 //must go #include "bbtkConfigurationFile.h"
68 #include <InterpreterBBS.h>
72 //=========================================================================
73 wxGUIEditorGraphicBBS::wxGUIEditorGraphicBBS(wxFrame *parent)
74 : wxFrame( parent, -1, _T("bbtkGEditor"), wxDefaultPosition, wxSize(1200,800) )
77 _frameAUIMgr = new wxAuiManager(this);
79 /*std::string datadir( crea::System::GetExecutablePath() );
80 std::string datadir (".");
81 cout<<"RaC //------------------"<<endl;
82 cout<<"RaC //TODO wxGUIEditorGraphicBBS constructor.Initialize datadir with crea::System::GetExecutablePath() ."<<endl;
83 cout<<"RaC //------------------"<<endl;
85 #ifdef LINUX // assume this is OSX
86 datadir=datadir+"/../share/creaContours";
89 #ifdef MACOSX // assume this is OSX
90 datadir=datadir+"/../../../../share/creaContours";
98 initTabPanelsManager();
99 // JGGR & CM initHelpHTMLBrowser();
100 _helpHtmlBrowser = NULL;
102 _frameAUIMgr->Update();
103 _actualPkgBrowserBoxName = "";
104 _actualPkgBrowserPkgName = "";
105 refreshGUIControls();
107 /////////////////////////////////
108 /// IMPORTANT!! FOR SAVE&LOAD PROCESSES THE VERSION IS VERY IMPORTANT.
109 /// RaC 2012 2nd Hackfest
110 _currentBBGversion="1.6";
113 //=========================================================================
114 wxGUIEditorGraphicBBS::~wxGUIEditorGraphicBBS()
116 //EED02JUIN2010 delete _tabsMgr;
117 _frameAUIMgr->UnInit();
124 //=========================================================================
125 void wxGUIEditorGraphicBBS::initToolbar()
127 wxBitmap bmp_new(new_xpm);
128 wxBitmap bmp_open(open_xpm);
129 wxBitmap bmp_save(save_xpm);
130 wxBitmap bmp_run(run_xpm);
131 wxBitmap bmp_delete(delete_xpm);
132 wxBitmap bmp_centerview(centerview_xpm);
133 wxBitmap bmp_box(box_xpm);
134 wxBitmap bmp_find(find_xpm);
135 wxBitmap bmp_executablebox(executablebox_xpm);
136 wxBitmap bmp_complexbox(complexbox_xpm);
137 wxBitmap bmp_complexinputport(complexinputport_xpm);
138 wxBitmap bmp_complexoutputport(complexoutputport_xpm);
139 wxBitmap bmp_undo(undo_xpm);
140 wxBitmap bmp_redo(redo_xpm);
141 wxBitmap bmp_editProperties(editProperties_xpm);
142 wxBitmap bmp_showTree(showTree_xpm);
144 // wxToolBar *toolbar = new wxToolBar(this, wxID_ANY);
145 wxToolBar *toolbar = CreateToolBar();
147 //Adds a tool btn to the toolbar
148 toolbar->AddTool(ID_NEW, _T("New"), bmp_new, wxNullBitmap, wxITEM_NORMAL,
149 _T("New tab"), _T("Create a new panel tab"));
151 toolbar->AddTool(ID_OPEN, _T("Open diagram"), bmp_open, wxNullBitmap,
152 wxITEM_NORMAL, _T("Open a diagram"), _T("Open a diagram"));
154 toolbar->AddTool(ID_SAVE_DIAGRAM, _T("Save Diagram"), bmp_save,
155 wxNullBitmap, wxITEM_NORMAL, _T("Saves the current diagram"),
156 _T("Saves the current diagram")); //DFCH
157 //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
158 toolbar->AddTool(ID_RUN, _T("Run"), bmp_run, wxNullBitmap, wxITEM_NORMAL,
159 _T("Execute actual diagram"), _T("Execute actual diagram"));
160 toolbar->AddTool(ID_DELETEALL, _T("Delete all"), bmp_delete, wxNullBitmap,
161 wxITEM_NORMAL, _T("Delete all boxes"), _T("Delete all boxes"));
162 toolbar->AddTool(ID_CENTERVIEW, _T("Center view"), bmp_centerview,
163 wxNullBitmap, wxITEM_NORMAL, _T("Center view"), _T("Center view"));
164 toolbar->AddSeparator();
165 toolbar->AddTool(ID_BTNBOX, _T("New Box"), bmp_box, wxNullBitmap,wxITEM_NORMAL, _T("New Box"), _T("Nex Box"));
166 toolbar->AddTool(ID_BTNSELETBOXES, _T("Select Boxes"), bmp_find, wxNullBitmap,wxITEM_NORMAL, _T("Select Boxes"), _T("Select Boxes"));
167 toolbar->AddSeparator();
168 toolbar->AddTool(ID_BTEXECUTABLEBOX, _T("Select as executable Box"),
169 bmp_executablebox, wxNullBitmap, wxITEM_NORMAL,
170 _T("Select as executable Box"), _T("Select as executable Box"));
171 toolbar->AddSeparator();
172 toolbar->AddTool(ID_BTNCOMPLEXBOX, _T("Complex box"), complexbox_xpm,
173 wxNullBitmap, wxITEM_NORMAL, _T("Complex box"), _T("Complex box"));
175 //EED 2017-09-16 Migration wxWidgets 2.8 to 3.0
176 #if wxMAJOR_VERSION <= 2
177 toolbar->SetToggle(ID_BTNCOMPLEXBOX, true);
179 printf ("EED Warnning. wxGUIEditorGraphicBBS::initToolbar >>> toolbar->SetToggle \n ");
183 // RaC 2012 2nd HackFest - Now Complex inputs are any external input
184 // toolbar->AddTool(ID_ADDCOMPLEXBOXINPUT, _T("Add input to Complex box"),
185 // bmp_complexinputport, wxNullBitmap, wxITEM_NORMAL,
186 // _T("Add input to Complex box"), _T("Add input to Complex box"));
187 toolbar->AddTool(ID_ADDCOMPLEXBOXINPUT, _T("Add external input (Complex box or console app)"),
188 bmp_complexinputport, wxNullBitmap, wxITEM_NORMAL,
189 _T("Add external input (Complex box or console app)"), _T("Add external input (Complex box or console app)"));
191 toolbar->AddTool(ID_ADDCOMPLEXBOXOUTPUT, _T("Add output to Complex box"),
192 bmp_complexoutputport, wxNullBitmap, wxITEM_NORMAL,
193 _T("Add output Complex box"), _T("Add output Complex box"));
195 // toolbar->EnableTool(ID_ADDCOMPLEXBOXINPUT, false); RaC2012 2nd HackFest
196 toolbar->EnableTool(ID_ADDCOMPLEXBOXINPUT, true);
198 toolbar->EnableTool(ID_ADDCOMPLEXBOXOUTPUT, false);
199 toolbar->AddSeparator();
200 toolbar->AddTool(ID_UNDO, _T("Undo"),bmp_undo, wxNullBitmap, wxITEM_NORMAL, _T("Undo"), _T("Undo"));
201 toolbar->AddTool(ID_REDO, _T("Redo"),bmp_redo, wxNullBitmap, wxITEM_NORMAL, _T("Redo"), _T("Redo"));
202 toolbar->AddSeparator();
203 toolbar->AddTool(ID_EDITPROPERTIES, _T("Edit diagram properties"),bmp_editProperties, wxNullBitmap, wxITEM_NORMAL, _T("Edit diagram properties"), _T("Edit diagram properties"));
204 toolbar->EnableTool(ID_EDITPROPERTIES, false);
206 toolbar->AddTool(ID_SHOWTREE, _T("Show tree"),bmp_showTree, wxNullBitmap, wxITEM_NORMAL, _T("Show tree"), _T("Show tree"));
209 toolbar->EnableTool(ID_UNDO, false);
210 toolbar->EnableTool(ID_REDO, false);
211 toolbar->SetMargins(2, 2);
217 // connect command event handlers
219 Connect(ID_NEW, wxEVT_COMMAND_TOOL_CLICKED,
220 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnCreateNewTab));
221 Connect(ID_OPEN, wxEVT_COMMAND_TOOL_CLICKED,
222 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnOpenDiagram));
223 Connect(ID_SAVE_DIAGRAM, wxEVT_COMMAND_TOOL_CLICKED,
224 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnSaveActualDiagram)); //DFCH
225 Connect(ID_SAVE_AS_DIAGRAM, wxEVT_COMMAND_TOOL_CLICKED,
226 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnSaveAsActualDiagram)); //DFCH
229 wxEVT_COMMAND_TOOL_CLICKED,
230 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnExecuteActualDiagram));
233 wxEVT_COMMAND_TOOL_CLICKED,
234 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnDeleteAllBoxesActualDiagram));
237 wxEVT_COMMAND_TOOL_CLICKED,
238 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnCenterViewActualDiagram));
239 Connect(ID_BTNBOX, wxEVT_COMMAND_TOOL_CLICKED,wxCommandEventHandler(wxGUIEditorGraphicBBS::OnClickBtnBox));
240 Connect(ID_BTNSELETBOXES, wxEVT_COMMAND_TOOL_CLICKED , wxCommandEventHandler(wxGUIEditorGraphicBBS::OnClickBtnSelectBoxes) );
243 wxEVT_COMMAND_TOOL_CLICKED,
244 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnClickBtnExecutableBox));
245 Connect(ID_BTNCOMPLEXBOX, wxEVT_COMMAND_TOOL_CLICKED,
246 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnClickBtnComplexBox));
247 Connect(ID_ADDCOMPLEXBOXINPUT, wxEVT_COMMAND_TOOL_CLICKED,
248 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnAddComplexBoxInput));
249 Connect(ID_ADDCOMPLEXBOXOUTPUT, wxEVT_COMMAND_TOOL_CLICKED,
250 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnAddComplexBoxOutput));
251 Connect(ID_UNDO,wxEVT_COMMAND_TOOL_CLICKED, wxCommandEventHandler(wxGUIEditorGraphicBBS::OnUndo));
252 Connect(ID_REDO,wxEVT_COMMAND_TOOL_CLICKED, wxCommandEventHandler(wxGUIEditorGraphicBBS::OnRedo));
253 Connect(ID_CHANGENAME, wxEVT_COMMAND_RIGHT_CLICK, wxCommandEventHandler(wxGUIEditorGraphicBBS::OnChangeName));
254 Connect(ID_EDITPROPERTIES,wxEVT_COMMAND_TOOL_CLICKED, wxCommandEventHandler(wxGUIEditorGraphicBBS::OnEditDiagramProperties));
255 Connect(ID_SHOWTREE,wxEVT_COMMAND_TOOL_CLICKED, wxCommandEventHandler(wxGUIEditorGraphicBBS::OnShowTree));
259 //=========================================================================
260 void wxGUIEditorGraphicBBS::initHelpHTMLBrowser() {
262 _helpHtmlBrowser = new WxGUIHtmlBrowser(this, wxSize(200, 0));
268 //=========================================================================
269 void wxGUIEditorGraphicBBS::initMenu() {
270 // Create File menu and its items
271 wxMenu *fileMenu = new wxMenu();
272 fileMenu->Append(ID_NEW, _T("New diagram"), _T("New"));
273 fileMenu->Append(ID_SAVE_DIAGRAM, _T("Save Diagram"), _T("Save Diagram")); //DFCH
274 fileMenu->Append(ID_SAVE_AS_DIAGRAM, _T("Save Diagram As"),
275 _T("Save Diagram As")); //DFCH
276 fileMenu->Append(ID_OPEN_BBS, _T("Open BBS"), _T("Open BBS"));
278 fileMenu->Append(ID_OPEN, _T("Open a diagram"), _T("Open a diagram"));
279 fileMenu->Append(ID_SAVE_AS_BBS, _T("Save BBS"), _T("Save BBS"));
280 fileMenu->Append(ID_SAVE_AS_COMPLEXBOX, _T("Save complex box"),
281 _T("Save complex box"));
282 fileMenu->Append(ID_EXPORT_CONSOLEAPP, _T("Export console commands"),
283 _T("Export console execution commands"));
284 fileMenu->Append(wxID_EXIT, _T("E&xit"), _T("Exit"));
286 Connect(ID_NEW, wxEVT_COMMAND_MENU_SELECTED,
287 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnCreateNewTab));
288 Connect(ID_SAVE_DIAGRAM, wxEVT_COMMAND_MENU_SELECTED,
289 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnSaveActualDiagram)); //DFCH
290 Connect(ID_SAVE_AS_DIAGRAM, wxEVT_COMMAND_MENU_SELECTED,
291 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnSaveAsActualDiagram));
292 Connect(ID_OPEN_BBS, wxEVT_COMMAND_MENU_SELECTED,
293 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnOpenBBS));
294 Connect(ID_SAVE_AS_BBS, wxEVT_COMMAND_MENU_SELECTED,
295 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnSaveActualBBS));
296 Connect( ID_SAVE_AS_COMPLEXBOX, wxEVT_COMMAND_MENU_SELECTED,
297 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnSaveActualComplexBox));
298 Connect( ID_EXPORT_CONSOLEAPP, wxEVT_COMMAND_MENU_SELECTED,
299 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnExportConsoleExecCommand));
300 Connect(wxID_EXIT, wxEVT_COMMAND_MENU_SELECTED,
301 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnExit));
303 // Create Edit menu and its items
304 wxMenu *editMenu = new wxMenu;
305 editMenu->Append(ID_COPY_TO_COMPLEXDIAGRAM, _T("Copy selected to complex box"), _T("Creates a new complex box diagram with selected boxes"));
306 editMenu->Append(ID_EDIT_COMPLEXBOX_SCRIPT, _T("Edit Complex Box"), _T("Edit Complex Box"));
307 Connect( ID_COPY_TO_COMPLEXDIAGRAM, wxEVT_COMMAND_MENU_SELECTED,
308 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnCopySelectedToComplexDiagram));
309 Connect( ID_EDIT_COMPLEXBOX_SCRIPT, wxEVT_COMMAND_MENU_SELECTED,
310 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnEditComplexBoxScript));
312 // Create Help menu and its items
313 wxMenu *helpMenu = new wxMenu;
314 helpMenu->Append(wxID_ABOUT, _T("&About..."), _T("About"));
315 helpMenu->Append(ID_HELP_BBEDITOR, _T("&Help..."), _T("Help"));
316 Connect(ID_HELP_BBEDITOR, wxEVT_COMMAND_MENU_SELECTED,
317 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnHelpBBeditor));
320 wxMenu *menuTools = new wxMenu;
321 menuTools->Append(ID_bbEditor_Tool_Menu_CreatePackage,
322 _T("Create &package") );
323 menuTools->Append(ID_bbEditor_Tool_Menu_CreateBlackBox,
324 _T("Create &blackbox") );
325 menuTools->Append(ID_bbEditor_Tool_Menu_PlugPackage, _T("Plug package") );
326 menuTools->Append(ID_bbEditor_Tool_Menu_EditConfig, _T("&Edit bbtk config") );
327 menuTools->Append(ID_bbEditor_Tool_Menu_ShowHTMLDoc,
328 _T("Show &HTML documentation") );
329 menuTools->Append(ID_bbEditor_Tool_Menu_CreateIndex, _T("&Generate index") );
331 Connect(ID_bbEditor_Tool_Menu_CreatePackage, wxEVT_COMMAND_MENU_SELECTED,
332 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnCreatePackage));
333 Connect(ID_bbEditor_Tool_Menu_CreateBlackBox, wxEVT_COMMAND_MENU_SELECTED,
334 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnCreateBlackBox));
335 Connect(ID_bbEditor_Tool_Menu_PlugPackage, wxEVT_COMMAND_MENU_SELECTED,
336 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnPlugPackage));
337 Connect(ID_bbEditor_Tool_Menu_EditConfig, wxEVT_COMMAND_MENU_SELECTED,
338 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnEditConfig));
339 Connect(ID_bbEditor_Tool_Menu_ShowHTMLDoc, wxEVT_COMMAND_MENU_SELECTED,
340 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnShowHTMLDoc));
341 Connect(ID_bbEditor_Tool_Menu_CreateIndex, wxEVT_COMMAND_MENU_SELECTED,
342 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnCreateIndex));
344 // Append the created menu to the menu bar
345 wxMenuBar *menuBar = new wxMenuBar();
346 menuBar->Append(fileMenu, _T("&File") );
347 menuBar->Append(editMenu, _T("&Edit") );
348 menuBar->Append(menuTools, _T("&Tool") );
349 menuBar->Append(helpMenu, _T("&Help") );
351 // Attach this menu bar to the frame
355 //=========================================================================
356 void wxGUIEditorGraphicBBS::initTabPanelsManager()
358 _notebook = new wxAuiNotebook(this, wxID_NOTEBOOK, wxDefaultPosition,
359 wxDefaultSize, wxAUI_NB_TOP | wxAUI_NB_TAB_MOVE
360 | wxAUI_NB_CLOSE_ON_ACTIVE_TAB | wxAUI_NB_TAB_FIXED_WIDTH
361 | wxAUI_NB_WINDOWLIST_BUTTON);
362 _tabsMgr = new wxTabPanelsManager(this);
363 _frameAUIMgr->AddPane(_notebook, wxAuiPaneInfo().CenterPane());
366 //=========================================================================
367 void wxGUIEditorGraphicBBS::initPackageBrowser()
369 _pkgBrowser = new WxGUIPackageBrowser2(this);
370 _pkgBrowser->IncludeAll();
371 _frameAUIMgr->AddPane(_pkgBrowser, wxAuiPaneInfo().Left().MinSize(30, 500).BestSize(750,500).CloseButton(false));
374 //================================================================
376 void wxGUIEditorGraphicBBS::DoRegeneratePackageDoc(const std::string& pack)
378 std::string mess("Regenerating doc for package '");
382 mess = "Regenerating doc for all packages";
385 mess += " ... please wait";
387 SetStatusText(std2wx(mess));
395 command += ConfigurationFile::GetInstance().Get_bin_path();
396 command += ConfigurationFile::GetInstance().Get_file_separator();
397 command += "bbRegeneratePackageDoc";
402 command += " " + pack + " -q";
403 bbtkMessage("debug",1,"Executing system command '"<<command<<"'"<<std::endl);
405 if (!system(command.c_str())) {
406 SetStatusText(_T("Done !"));
408 wxMessageBox(_T("Done !"),_T("Regenerate package '")
409 +std2wx(pack)+_T("' doc"),
410 wxOK | wxICON_INFORMATION);
413 SetStatusText(_T("Done !"));
414 wxString err(_T("An error occured while running '"));
415 err += bbtk::std2wx(command) + _T("'");
416 wxMessageBox(err, _T("Regenerate package doc"), wxOK | wxICON_ERROR);
420 //================================================================
421 void wxGUIEditorGraphicBBS::DoRegenerateBoxesLists() {
422 SetStatusText(_T("Regenerating boxes lists ... please wait"));
429 command += ConfigurationFile::GetInstance().Get_bin_path();
430 command += ConfigurationFile::GetInstance().Get_file_separator();
431 command += "bbRegenerateBoxesLists";
438 bbtkMessage("debug",1,"Executing system command '"<<command<<"'"<<std::endl);
440 if (!system(command.c_str())) {
441 SetStatusText(_T("Done !"));
443 wxMessageBox(_T("Done !"),_T("Regenerate boxes lists"),
444 wxOK | wxICON_INFORMATION);
447 SetStatusText(_T("Done !"));
448 wxString err(_T("An error occured while running '"));
449 err += bbtk::std2wx(command) + _T("'");
450 wxMessageBox(err, _T("Regenerate boxes lists"), wxOK | wxICON_ERROR);
454 //================================================================
455 void wxGUIEditorGraphicBBS::RegenerateAll() {
456 DoRegeneratePackageDoc("-a");
457 DoRegenerateBoxesLists();
460 //================================================================
462 wxAuiNotebook* wxGUIEditorGraphicBBS::getAuiNotebook() {
466 //================================================================
468 void wxGUIEditorGraphicBBS::displayBlackBoxInfo(std::string packageName, std::string boxName)
470 if (_actualPkgBrowserPkgName != packageName || _actualPkgBrowserBoxName != boxName)
473 _actualPkgBrowserPkgName = packageName;
474 _actualPkgBrowserBoxName = boxName;
476 //EED 15 oct 2012 BlackBoxDescriptor::Pointer descriptor = GObjectsMVCFactory::getInstance()->getBlackBoxDescriptor(packageName, boxName);
479 //EED ComplexBlackBoxDescriptor::Pointer descriptor;
480 BlackBoxDescriptor::Pointer descriptor;
482 std::map< std::string, BlackBoxDescriptor::Pointer> mapDesc;
483 k = _pkgBrowser->GetFactory()->GetPackage(_actualPkgBrowserPkgName);
484 mapDesc = k->GetDescriptorMap();
485 descriptor = mapDesc[_actualPkgBrowserBoxName];
491 descriptor->GetBoxesInside(tree, 0);
494 //std::vector<std::string> boxesDiagram = _sceneM->boxesDiagram;
495 //for(int i=0;i<boxesDiagram.size();i++){
496 // std::cout<<"caja: "<<boxesDiagram[i]<<std::endl;
499 _actualPkgBrowserPkgName = "";
500 _actualPkgBrowserBoxName = "";
504 BlackBoxDescriptor::Pointer descriptor;
505 std::map< std::string, BlackBoxDescriptor::Pointer> mapDesc;
506 k = _pkgBrowser->GetFactory()->GetPackage(packageName);
507 std::vector<std::string> temp;
508 _pkgBrowser->GetFactory()->GetPackagesList(temp);
509 for(int ii = 0 ; ii < temp.size() ; ii++)
511 std::cout << " packs "<< temp[ii]<< std::endl;
513 mapDesc = k->GetDescriptorMap();
514 descriptor = mapDesc[boxName];
516 _pkgBrowser->WxGUIBlackBoxListUserOnSelected(descriptor.get());
520 //=========================================================================
522 void wxGUIEditorGraphicBBS::editBlackBox(GBlackBoxModel *bbmodel) {
523 wxBlackBoxEditionDialog* dialog =
524 new wxBlackBoxEditionDialog(this, bbmodel);
528 //=========================================================================
530 bool wxGUIEditorGraphicBBS::boxNameExists(std::string boxname) {
532 return this->_tabsMgr->getActualTabPanel()->getSceneManager()->boxExist(boxname);
535 //=========================================================================
537 void wxGUIEditorGraphicBBS::updateStatusBar(std::string textStatus) {
538 SetStatusText(crea::std2wx(textStatus));
541 //=========================================================================
543 void wxGUIEditorGraphicBBS::executeScript(std::string script) {
544 std::string separator =
545 ConfigurationFile::GetInstance().Get_file_separator();
546 std::string dir = ConfigurationFile::GetInstance().Get_default_temp_dir();
547 std::string filename = dir + separator + "tmp_bbtk.bbs";
550 tempFile.open(filename.c_str());
554 std::string command = "";
557 command += "start /b ";
560 // command += "\""+ crea::System::GetExecutablePath();
562 // command += separator + "../../../bbi.app/Contents/MacOS";
566 command += "\"" + filename + "\"";
573 command = "source ~/.bashrc ; "+command;
577 printf("RaC wxGUIEditorGraphicBBS::executeScript %s \n", command.c_str());
578 system(command.c_str());
581 //=========================================================================
582 std::string wxGUIEditorGraphicBBS::CheckExtension(std::string filename, std::string extension) {
583 if(filename.size() > extension.size() ){
584 if( (filename.compare(filename.size()-extension.size(), extension.size(),extension)) !=0 ){
585 filename.append(extension);
588 filename.append(extension);
592 //=========================================================================
594 //=========================================================================
596 void wxGUIEditorGraphicBBS::OnCreateNewTab(wxCommandEvent& event) {
597 _tabsMgr->addNewTab();
598 refreshGUIControls();
601 void wxGUIEditorGraphicBBS::OnUndo(wxCommandEvent& event) {
602 unsigned short disable;
606 _tabsMgr->loadTempDiagram(0);
607 disable = _tabsMgr->getUndoState(stundo);
610 std::string name = _tabsMgr->GetNameTabPanel();
611 if(name[name.length() - 1] == '*')
613 name =name.substr(0,name.length()-1);
615 _tabsMgr->SetNameTabPanel(wxString (name.c_str(), wxConvUTF8));
618 GetToolBar()->EnableTool(ID_UNDO,disable);
619 GetToolBar()->SetToolShortHelp(ID_UNDO,crea::std2wx(stundo));
620 GetToolBar()->EnableTool(ID_REDO,_tabsMgr->getRedoState(stredo));
621 GetToolBar()->SetToolShortHelp(ID_REDO,crea::std2wx(stredo));
622 refreshGUIControls();
625 //=========================================================================
627 void wxGUIEditorGraphicBBS::OnRedo(wxCommandEvent& event) {
628 unsigned short disable;
632 _tabsMgr->loadTempDiagram(1);
633 std::string name = _tabsMgr->GetNameTabPanel();
634 if(name[name.length() - 1] != '*')
636 _tabsMgr->SetNameTabPanel(wxString (name.c_str(), wxConvUTF8));
637 GetToolBar()->EnableTool(ID_UNDO,_tabsMgr->getUndoState(stundo));
638 GetToolBar()->SetToolShortHelp(ID_UNDO,crea::std2wx(stundo));
639 GetToolBar()->EnableTool(ID_REDO,_tabsMgr->getRedoState(stredo));
640 GetToolBar()->SetToolShortHelp(ID_REDO,crea::std2wx(stredo));
641 refreshGUIControls();
644 void wxGUIEditorGraphicBBS::OnChangeName(wxCommandEvent& event){
646 //=========================================================================
648 void wxGUIEditorGraphicBBS::OnShowTree(wxCommandEvent& event){
649 std::cout << "wxGUIEditorGraphicBBS::OnShowTree"<<std::endl;
650 if (_actualPkgBrowserPkgName !="" || _actualPkgBrowserBoxName != "")
653 //EED ComplexBlackBoxDescriptor::Pointer descriptor;
654 BlackBoxDescriptor::Pointer descriptor;
656 std::map< std::string, BlackBoxDescriptor::Pointer> mapDesc;
657 k = _pkgBrowser->GetFactory()->GetPackage(_actualPkgBrowserPkgName);
658 mapDesc = k->GetDescriptorMap();
659 descriptor = mapDesc[_actualPkgBrowserBoxName];
665 descriptor->GetBoxesInside(tree, 0);
667 _actualPkgBrowserPkgName = "";
668 _actualPkgBrowserBoxName = "";
672 std::cout<<"Select a Box"<<std::endl;
676 //=========================================================================
678 void wxGUIEditorGraphicBBS::OnEditDiagramProperties(wxCommandEvent& event)
680 wxDiagramPropertiesEditionDialog* dialog =
681 new wxDiagramPropertiesEditionDialog(this, tree);
685 //=========================================================================
686 void wxGUIEditorGraphicBBS::OnExecuteActualDiagram(wxCommandEvent& event)
688 std::string script1 = _tabsMgr->getActualDiagramBBS(true);
689 cout << endl << "RaC wxGUIEditorGraphicBBS::executeActualDiagram SCRIPT"
691 cout << script1 << endl;
692 std::string script2 = _tabsMgr->getActualDiagramBBS(false);
693 executeScript(script2);
696 //=========================================================================
697 void wxGUIEditorGraphicBBS::OpenBBS(std::string filePathName, std::string fileName)
699 _tabsMgr->addNewTab( crea::std2wx(fileName) );
700 bbtk::InterpreterBBS::Pointer I = bbtk::InterpreterBBS::New( this->_tabsMgr->getActualTabPanel()->getSceneManager(), _pkgBrowser->GetFactory());
701 // We tell the interpreter to throw exceptions on error
703 // Interpret the file supposed to define a box called 'Processing'
704 I->InterpretFile( filePathName );
705 refreshGUIControls();
708 //=========================================================================
710 //=========================================================================
711 void wxGUIEditorGraphicBBS::OnOpenBBS(wxCommandEvent& event)
713 //EED 2017-09-16 Migration wxWidgets 2.8 to 3.0
714 #if wxMAJOR_VERSION <= 2
715 wxFileDialog * openFileDialog = new wxFileDialog(this, wxT("Open BBS"), wxEmptyString, wxT("NewBBS"), wxT("*.bbs"), wxOPEN);
717 wxFileDialog * openFileDialog = new wxFileDialog(this, wxT("Open BBS"), wxEmptyString, wxT("NewBBS"), wxT("*.bbs"), wxFD_OPEN);
720 if (openFileDialog->ShowModal() == wxID_OK)
722 OpenBBS( crea::wx2std(openFileDialog->GetPath()) , crea::wx2std(openFileDialog->GetFilename()) );
726 if (openFileDialog->ShowModal() == wxID_OK)
728 wxString fileName = openFileDialog->GetPath();
729 _tabsMgr->addNewTab(openFileDialog->GetFilename());
730 bbtk::InterpreterBBS::Pointer I = bbtk::InterpreterBBS::New( this->_tabsMgr->getActualTabPanel()->getSceneManager(), _pkgBrowser->GetFactory());
731 // We tell the interpreter to throw exceptions on error
733 // Interpret the file supposed to define a box called 'Processing'
734 I->InterpretFile((const char*) (fileName.mb_str()));
736 refreshGUIControls();
740 //=========================================================================
741 void wxGUIEditorGraphicBBS::SaveActualBBS(std::string filename) {
744 //EED file.open(fileName.c_str());
745 file.open(filename.c_str());
746 std::string content = "";
747 // writing file header
748 content += "# ----------------------------------\n";
749 content += "# - BBTKGEditor v ";
750 content += _currentBBGversion; //VERSION
751 content += " BBS BlackBox Script\n";
755 content += "# ----------------------------------\n";
757 content += _tabsMgr->getActualDiagramBBS();
762 void wxGUIEditorGraphicBBS::OnSaveActualBBS(wxCommandEvent& event) {
764 //EED 2017-09-16 Migration wxWidgets 2.8 to 3.0
765 #if wxMAJOR_VERSION <= 2
766 wxFileDialog * saveFileDialog = new wxFileDialog(this,
767 wxT("Save actual BBS"), wxEmptyString, wxT("NewBBS"),
768 wxT("*.bbs"), wxSAVE | wxOVERWRITE_PROMPT);
770 wxFileDialog * saveFileDialog = new wxFileDialog(this,
771 wxT("Save actual BBS"), wxEmptyString, wxT("NewBBS"),
772 wxT("*.bbs"), wxFD_SAVE | wxFD_OVERWRITE_PROMPT);
775 if (saveFileDialog->ShowModal() == wxID_OK) {
776 wxString fileName = saveFileDialog->GetPath();
777 std::string filename = (const char*) (fileName.mb_str());
778 filename=CheckExtension (filename, ".bbs");
779 SaveActualBBS(filename);
784 void wxGUIEditorGraphicBBS::AskComplexBoxConfiguration() {
785 std::string cbName = _tabsMgr->GetCbName();
786 std::string paName = _tabsMgr->GetCbPackageName();
788 wxTextEntryDialog *cbNameDialog = new wxTextEntryDialog(this,
789 wxT("Complex Box name"));
790 wxTextEntryDialog *paNameDialog = new wxTextEntryDialog(this,
791 wxT("Package name"));
793 cbNameDialog->SetValue(wxString(cbName.c_str(), wxConvUTF8));
794 paNameDialog->SetValue(wxString(paName.c_str(), wxConvUTF8));
796 if (cbNameDialog->ShowModal() == wxID_OK) {
797 wxString complexboxname = cbNameDialog->GetValue();
798 cbName = (const char*) (complexboxname.mb_str());
801 if (paNameDialog->ShowModal() == wxID_OK) {
802 wxString packagename = paNameDialog->GetValue();
803 paName = (const char*) (packagename.mb_str());
806 _tabsMgr->SetCbName(cbName);
807 _tabsMgr->SetCbPackageName(paName);
810 //=========================================================================
812 void wxGUIEditorGraphicBBS::SaveActualComplexBox(std::string filename) {
814 file.open(filename.c_str());
816 std::string content = "";
818 // writing file header
819 content += "# ----------------------------------\n";
820 content += "# - BBTKGEditor v ";
821 content += _currentBBGversion;//VERSION
822 content += " BBS BlackBox Script (Complex Box)\n";
826 content += "# ----------------------------------\n";
828 content += _tabsMgr->getActualComplexBoxBBS();
833 //=========================================================================
835 void wxGUIEditorGraphicBBS::OnSaveActualComplexBox(wxCommandEvent& event)
837 //EED 2017-09-16 Migration wxWidgets 2.8 to 3.0
838 #if wxMAJOR_VERSION <= 2
839 wxFileDialog * saveFileDialog = new wxFileDialog(this,
840 wxT("Save Complex Box BBS"), wxEmptyString,
841 _T("ComplexBoxName"), wxT("*.bbs"), wxSAVE
842 | wxOVERWRITE_PROMPT);
844 wxFileDialog * saveFileDialog = new wxFileDialog(this,
845 wxT("Save Complex Box BBS"), wxEmptyString,
846 _T("ComplexBoxName"), wxT("*.bbs"), wxFD_SAVE
847 | wxFD_OVERWRITE_PROMPT);
850 if (saveFileDialog->ShowModal() == wxID_OK) {
851 wxString fileName = saveFileDialog->GetPath();
852 std::string filename = (const char*) (fileName.mb_str());
853 filename=CheckExtension (filename, ".bbs");
854 SaveActualComplexBox(filename);
858 //=========================================================================
859 void wxGUIEditorGraphicBBS::SaveActualDiagram(std::string filename) {
861 file.open(filename.c_str());
863 std::string content = "";
865 // writing file header
866 content += "# ----------------------------------\n";
867 content += "# - BBTKGEditor v ";
868 content += _currentBBGversion; //VERSION
869 content += " BBG BlackBox Diagram file\n";
875 content += "# ----------------------------------\n";
877 content += "APP_START\n";
878 _tabsMgr->saveActualDiagram(content, filename); //DFCH
879 content += "APP_END\n";
884 //=========================================================================
885 void wxGUIEditorGraphicBBS::SaveTempActualDiagram(const std::string &action)
889 std::string name = _tabsMgr->GetNameTabPanel();
890 if(name[name.length() - 1] != '*')
892 _tabsMgr->SetNameTabPanel(wxString (name.c_str(), wxConvUTF8));
893 _tabsMgr->saveTempActualDiagram(action);
894 GetToolBar()->EnableTool(ID_UNDO,_tabsMgr->getUndoState(stundo));
895 GetToolBar()->SetToolShortHelp(ID_UNDO,crea::std2wx(stundo));
896 GetToolBar()->EnableTool(ID_REDO,_tabsMgr->getRedoState(stredo));
897 GetToolBar()->SetToolShortHelp(ID_REDO,crea::std2wx(stredo));
900 //=========================================================================
902 //The following method allows to save the current diagram asking the filename
904 void wxGUIEditorGraphicBBS::SaveCurrentDiagramAs()
907 //EED 2017-09-16 Migration wxWidgets 2.8 to 3.0
908 #if wxMAJOR_VERSION <= 2
909 wxFileDialog * saveFileDialog = new wxFileDialog(this,
910 wxT("Save current diagram"), wxEmptyString, wxT("NewDiagram"),
911 wxT("*.bbg"), wxSAVE | wxOVERWRITE_PROMPT);
913 wxFileDialog * saveFileDialog = new wxFileDialog(this,
914 wxT("Save current diagram"), wxEmptyString, wxT("NewDiagram"),
915 wxT("*.bbg"), wxFD_SAVE | wxFD_OVERWRITE_PROMPT);
918 if (saveFileDialog->ShowModal() == wxID_OK) {
919 //_tabsMgr->SetNameTabPanel(saveFileDialog->GetFilename());
920 wxString pathfileName = saveFileDialog->GetPath();
921 std::string pathfilename = (const char*) (pathfileName.mb_str());
922 pathfilename=CheckExtension (pathfilename, ".bbg");
924 //modify the tab name accordingly
925 wxString fileName = saveFileDialog->GetFilename();
926 std::string filename = (const char*) (fileName.mb_str());
927 filename=CheckExtension (filename, ".bbg");
928 _tabsMgr->SetNameTabPanel( wxString (filename.c_str(), wxConvUTF8) );
930 std::string pathfilenamebbs = pathfilename;
931 pathfilenamebbs[pathfilenamebbs.length() - 1] = 's';
932 if (_tabsMgr->isActualDiagramComplexBox() == false) {
933 SaveActualDiagram(pathfilename);
934 SaveActualBBS(pathfilenamebbs);
936 AskComplexBoxConfiguration();
937 SaveActualDiagram(pathfilename);
938 SaveActualComplexBox(pathfilenamebbs);
939 } //if isActualDiagramComplexBox
940 } // if saveFileDialog
942 //=========================================================================
944 void wxGUIEditorGraphicBBS::OnSaveActualDiagram(wxCommandEvent& event) {
945 std::string pathfilename = _tabsMgr->GetCurrentTabPanelPath();
946 if (pathfilename.empty()) {
947 SaveCurrentDiagramAs();
949 std::string pathfilenamebbs = pathfilename;
950 pathfilenamebbs[pathfilenamebbs.length() - 1] = 's';
951 if (_tabsMgr->isActualDiagramComplexBox() == false) {
952 std::string name = _tabsMgr->GetNameTabPanel();
953 if(name[name.length() - 1] == '*')
955 name =name.substr(0,name.length()-1);
957 _tabsMgr->SetNameTabPanel(wxString (name.c_str(), wxConvUTF8));
958 SaveActualDiagram(pathfilename);
959 SaveActualBBS(pathfilenamebbs);
961 AskComplexBoxConfiguration();
962 SaveActualDiagram(pathfilename);
963 SaveActualComplexBox(pathfilenamebbs);
964 } //if isActualDiagramComplexBox
965 if ((getCurrentDiagramExportFormat()==1) || (getCurrentDiagramExportFormat()==2) ) // 1:All 2:bbs,Python
967 std::string pathfilenamepy = pathfilenamebbs;
968 pathfilenamepy.replace( pathfilenamepy.length()-3, 3 , "py");
969 std::string cmdPy("source ~/.bashrc; bbs2 "+pathfilenamebbs+" "+pathfilenamepy);
970 printf("EED wxGUIEditorGraphicBBS::OnSaveActualDiagram cmd:%s\n", cmdPy.c_str() );
971 system( cmdPy.c_str() );
972 } // ExportFormat 1 or 2 All and Python
973 if ((getCurrentDiagramExportFormat()==1) || (getCurrentDiagramExportFormat()==3) ) // 1:All 3:bbs,JavaScript
975 std::string pathfilenamejs = pathfilenamebbs;
976 pathfilenamejs.replace( pathfilenamejs.length()-3, 3 , "js");
977 std::string cmdjs("source ~/.bashrc; bbs2 "+pathfilenamebbs+" "+pathfilenamejs);
978 printf("EED wxGUIEditorGraphicBBS::OnSaveActualDiagram cmd:%s\n", cmdjs.c_str() );
979 system( cmdjs.c_str() );
980 } // ExportFormat 1 or 3 All and JavaScript
981 } // if pathfilename empty
983 //=========================================================================
985 void wxGUIEditorGraphicBBS::OnSaveAsActualDiagram(wxCommandEvent& event) {
986 SaveCurrentDiagramAs();
989 //=========================================================================
990 void wxGUIEditorGraphicBBS::OnExportConsoleExecCommand(wxCommandEvent& event)
992 //EED 2017-09-16 Migration wxWidgets 2.8 to 3.0
993 #if wxMAJOR_VERSION <= 2
994 wxFileDialog * saveFileDialog = new wxFileDialog(this,
995 wxT("Export console command"), wxEmptyString, wxT("ConsoleApp.txt"),
996 wxT("*.txt;*.bbs;*.bbg;*.sh;*.bat"), wxSAVE | wxOVERWRITE_PROMPT);
998 wxFileDialog * saveFileDialog = new wxFileDialog(this,
999 wxT("Export console command"), wxEmptyString, wxT("ConsoleApp.txt"),
1000 wxT("*.txt;*.bbs;*.bbg;*.sh;*.bat"), wxFD_SAVE | wxFD_OVERWRITE_PROMPT);
1004 if (saveFileDialog->ShowModal() == wxID_OK)
1006 wxString fileName = saveFileDialog->GetPath();
1007 std::string filename = (const char*) (fileName.mb_str());
1008 filename=CheckExtension (filename, ".txt");
1011 file.open(filename.c_str());
1013 std::vector<std::string> extInputs = _tabsMgr->getActualTabPanel()->getSceneManager()->GetExternalInputsNames();
1015 //TODO PUT IN A METHOD OF A FILES AND TEXT MANAGER CLASS !!!
1016 //std::string inputsInCommentsWin="";
1017 //std::string inputsInCommentsUnix="";
1018 //std::string inputsInOneLineWin="";
1019 std::string inputsInOneLineUnix="";
1020 for (unsigned int i = 0; i < extInputs.size(); ++i)
1022 /* No gusto la idea al jefe pero por si acaso ...
1023 * RaC 2012 2nd HackFest
1025 inputsInCommentsWin+="REM ";
1026 inputsInCommentsWin+=extInputs[i];
1027 inputsInCommentsWin+="=\"value\"\n";
1028 inputsInCommentsUnix+="# ";
1029 inputsInCommentsUnix+=extInputs[i];
1030 inputsInCommentsUnix+="=\"value\"\n";
1033 sprintf (buffer, "%d", (i+1));
1034 inputsInOneLineWin+=extInputs[i];
1035 inputsInOneLineWin+="=\"%";
1036 inputsInOneLineWin+=buffer;
1037 inputsInOneLineWin+="\" ";
1039 inputsInOneLineUnix+=extInputs[i];
1040 inputsInOneLineUnix+="=\"<value>\" ";
1045 std::string content = "";
1046 // writing file header
1047 content += "# ----------------------------------\n";
1048 content += "# - BBTKGEditor v ";
1049 content += _currentBBGversion; //VERSION
1050 content += " Console Commands to execute BBS application\n";
1052 content += filename;
1054 content += "# ----------------------------------\n";
1057 content += "# Command to execute bbi\n";
1058 content += "bbi <bbs_path> ";
1059 content += inputsInOneLineUnix;
1061 /* No gusto la idea al jefe pero por si acaso ...
1062 * RaC 2012 2nd HackFest
1063 content += "# For Windows (copy the following lines to a .bat file)\n";
1064 content += "REM BBS application\n";
1065 content += "REM Inputs:\n";
1066 content += inputsInCommentsWin;
1067 content += "REM To use previous inputs, put %$inputName% in the corresponding input of the execution bbi line\n";
1068 content += "bbi applicationBBS.bbs ";
1069 content += inputsInOneLineWin;
1072 content += "# For Linux or Mac (copy the following lines to a .sh file)\n";
1073 content += "#!/bin/bash\n";
1074 content += "# BBS application\n";
1075 content += "# Inputs:\n";
1076 content += inputsInCommentsUnix;
1077 content += "# To use previous inputs, put $inputName in the corresponding input of the execution bbi line\n";
1078 content += "bbi applicationBBS.bbs ";
1079 content += inputsInOneLineUnix;
1090 //=========================================================================
1092 void wxGUIEditorGraphicBBS::refreshGUIControls()
1096 //RaC2012 2ndHackFest Next line seems weird ... To keep in mind for other devels
1097 wxToolBar* toolbar = GetToolBar();
1098 if (_tabsMgr->isActualDiagramComplexBox())
1100 toolbar->ToggleTool(ID_BTNCOMPLEXBOX, true);
1101 //toolbar->EnableTool(ID_ADDCOMPLEXBOXINPUT, true); RaC2012 2nd HackFest
1102 toolbar->EnableTool(ID_ADDCOMPLEXBOXOUTPUT, true);
1104 GetMenuBar()->GetMenu(0)->Enable(ID_SAVE_AS_COMPLEXBOX, true);
1105 GetMenuBar()->GetMenu(0)->Enable(ID_SAVE_AS_BBS, false);
1106 GetMenuBar()->GetMenu(0)->Enable(ID_EXPORT_CONSOLEAPP, false);
1108 toolbar->ToggleTool(ID_BTNCOMPLEXBOX, false);
1109 //toolbar->EnableTool(ID_ADDCOMPLEXBOXINPUT, false); RaC2012 2nd HackFest
1110 toolbar->EnableTool(ID_ADDCOMPLEXBOXOUTPUT, false);
1112 GetMenuBar()->GetMenu(0)->Enable(ID_SAVE_AS_COMPLEXBOX, false);
1113 GetMenuBar()->GetMenu(0)->Enable(ID_SAVE_AS_BBS, true);
1114 GetMenuBar()->GetMenu(0)->Enable(ID_EXPORT_CONSOLEAPP, true);
1117 //RaC2012 2ndHackFest
1118 GetToolBar()->EnableTool(ID_EDITPROPERTIES,true);
1120 GetToolBar()->EnableTool(ID_UNDO,_tabsMgr->getUndoState(stundo));
1121 GetToolBar()->SetToolShortHelp(ID_UNDO,crea::std2wx(stundo));
1122 GetToolBar()->EnableTool(ID_REDO,_tabsMgr->getRedoState(stredo));
1123 GetToolBar()->SetToolShortHelp(ID_REDO,crea::std2wx(stredo));
1125 if (_tabsMgr->getNumActualSelectedObjects() > 0) {
1126 GetMenuBar()->GetMenu(1)->Enable(ID_COPY_TO_COMPLEXDIAGRAM, true);
1128 ///TODO Fix the possibility to say from the SceneManager to the GUI to refresh the options
1129 GetMenuBar()->GetMenu(1)->Enable(ID_COPY_TO_COMPLEXDIAGRAM, true);
1134 //=========================================================================
1136 void wxGUIEditorGraphicBBS::OnDeleteAllBoxesActualDiagram(wxCommandEvent& event)
1138 wxMessageDialog *dial = new wxMessageDialog(NULL,wxT("Are you sure to delete all boxes of the diagram?"),wxT("Delete all boxes"), wxYES_NO | wxNO_DEFAULT| wxICON_QUESTION);
1139 if (dial->ShowModal() == wxID_YES)
1141 _tabsMgr->deleteAllBoxesActualDiagram();
1145 //=========================================================================
1147 void wxGUIEditorGraphicBBS::OnCenterViewActualDiagram(wxCommandEvent& event)
1149 _tabsMgr->centerViewActualDiagram();
1152 //=========================================================================
1153 void wxGUIEditorGraphicBBS::OpenDiagram(std::string filePathName, std::string fileName)
1155 ifstream inputStream;
1156 inputStream.open(filePathName.c_str());
1157 assert(inputStream.good()); // fails
1159 if(_tabsMgr->FindTab(filePathName)!=-1) //RaC2012 avoid opening same diagram twice
1161 inputStream.close();
1162 printf("RaC: Diagram already opened\n");
1165 _tabsMgr->addNewTab( crea::std2wx(fileName) );
1166 _tabsMgr->loadDiagram(inputStream, filePathName);
1168 _tabsMgr->saveTempActualDiagram("load diagram");
1169 GetToolBar()->EnableTool(ID_UNDO, false);
1170 GetToolBar()->EnableTool(ID_UNDO, false);
1171 inputStream.close();
1172 refreshGUIControls();
1175 //=========================================================================
1177 void wxGUIEditorGraphicBBS::OnOpenDiagram(wxCommandEvent& event)
1180 //EED 2017-09-16 Migration wxWidgets 2.8 to 3.0
1181 #if wxMAJOR_VERSION <= 2
1182 wxFileDialog * openFileDialog = new wxFileDialog(this, wxT("Open diagram"), wxEmptyString, wxT(""), wxT("*.bbg"), wxOPEN | wxFILE_MUST_EXIST);
1184 wxFileDialog * openFileDialog = new wxFileDialog(this, wxT("Open diagram"), wxEmptyString, wxT(""), wxT("*.bbg"), wxFD_OPEN | wxFD_FILE_MUST_EXIST);
1187 if (openFileDialog->ShowModal() == wxID_OK)
1189 wxString filePath = openFileDialog->GetPath();
1190 wxString fileName = openFileDialog->GetFilename();
1191 OpenDiagram( crea::wx2std(filePath) , crea::wx2std(fileName) );
1195 //=========================================================================
1196 void wxGUIEditorGraphicBBS::OnClickBtnBox(wxCommandEvent& event)
1198 std::cout<<"wxGUIEditorGraphicBBS::OnClickBtnBox"<<std::endl;
1199 BlackBoxDescriptor *bbDes = _pkgBrowser->GetActualSelected();
1200 if (bbDes != NULL) {
1201 std::string typeName = bbDes->GetTypeName();
1202 std::string packageName = bbDes->GetPackage()->GetName();
1203 wxGEditorTabPanel *pnl = this->_tabsMgr->getActualTabPanel();
1205 wxVtkSceneManager *scn = pnl->getSceneManager();
1206 scn->createGBlackBox(50, 50, packageName, typeName);
1209 SaveTempActualDiagram("New Box");
1214 //=========================================================================
1216 void wxGUIEditorGraphicBBS::OnClickBtnSelectBoxes(wxCommandEvent& event)
1218 std::string nameFilter = _pkgBrowser->GetNameFilter();
1219 _tabsMgr->SelectBoxWithPossibleName( nameFilter );
1222 //=========================================================================
1224 void wxGUIEditorGraphicBBS::OnClickBtnExecutableBox(wxCommandEvent& event)
1227 wxGEditorTabPanel *pnl = this->_tabsMgr->getActualTabPanel();
1230 wxVtkSceneManager *scn = pnl->getSceneManager();
1231 if( scn->MakeBoxExecutable() )
1232 std::cout<<"DFCH: wxGUIEditorGraphicBBS::OnClickBtnExecutableBox...successful"<<std::endl;
1234 std::cout<<"DFCH: wxGUIEditorGraphicBBS::OnClickBtnExecutableBox...Error!!"<<std::endl;
1240 //=========================================================================
1241 void wxGUIEditorGraphicBBS::OnClickBtnComplexBox(wxCommandEvent& event)
1243 std::cout<<"wxGUIEditorGraphicBBS::OnClickBtnComplexBox"<<std::endl;
1244 wxToolBar* toolbar = GetToolBar();
1245 bool temp = toolbar->GetToolState(ID_BTNCOMPLEXBOX);
1249 disableComplexBox();
1253 //=========================================================================
1255 void wxGUIEditorGraphicBBS::OnAddComplexBoxInput(wxCommandEvent& event)
1257 wxTextEntryDialog *nameDialog = new wxTextEntryDialog(this,
1258 wxT("Name of input port"));
1259 if (nameDialog->ShowModal() == wxID_OK)
1261 wxString fileName = nameDialog->GetValue();
1262 if (!fileName.IsEmpty())
1264 std::string portName = (const char*) (fileName.mb_str());
1265 if ( !boxNameExists(portName) )
1267 _tabsMgr->addActualDiagramComplexInputPort(portName);
1269 wxMessageDialog *dial = new wxMessageDialog(NULL,
1270 wxT("Impossible to create Box. The name already exists. Please provide another name"),
1271 wxT("Change name: name already exists"), wxOK | wxICON_EXCLAMATION | wxSTAY_ON_TOP);
1278 //=========================================================================
1279 void wxGUIEditorGraphicBBS::OnAddComplexBoxOutput(wxCommandEvent& event)
1281 wxTextEntryDialog *nameDialog = new wxTextEntryDialog(this,
1282 wxT("Name of output port"));
1283 if (nameDialog->ShowModal() == wxID_OK)
1285 wxString fileName = nameDialog->GetValue();
1286 if (!fileName.IsEmpty())
1288 std::string portName = (const char*) (fileName.mb_str());
1289 if ( !boxNameExists(portName) )
1291 _tabsMgr->addActualDiagramComplexOutputPort(portName);
1293 wxMessageDialog *dial = new wxMessageDialog(NULL,
1294 wxT("Impossible to create Box. The name already exists. Please provide another name"),
1295 wxT("Change name: name already exists"), wxOK | wxICON_EXCLAMATION | wxSTAY_ON_TOP);
1303 //=========================================================================
1304 void wxGUIEditorGraphicBBS::OnCopySelectedToComplexDiagram(
1305 wxCommandEvent& event)
1307 _tabsMgr->copySelectedBBoxesToComplexDiagram();
1310 //=========================================================================
1311 void wxGUIEditorGraphicBBS::OnHelpBBeditor(wxCommandEvent& event)
1313 printf("wxGUIEditorGraphicBBS::OnHelpBBeditor ....not implemented..\n");
1316 //=========================================================================
1317 void wxGUIEditorGraphicBBS::OnCreatePackage(wxCommandEvent& event)
1319 bbtkSystemTools::CreatePackage();
1322 //=========================================================================
1323 void wxGUIEditorGraphicBBS::OnCreateBlackBox(wxCommandEvent& event)
1325 bbtkSystemTools::CreateBlackBox();
1328 //=========================================================================
1329 void wxGUIEditorGraphicBBS::OnPlugPackage(wxCommandEvent& event)
1331 //DFGO2012 Plug Package functionnalities
1332 long style = wxDD_DEFAULT_STYLE | wxDD_DIR_MUST_EXIST;
1335 _T("Select package directory"),
1341 userResponse = FD->ShowModal();
1342 if(userResponse==wxID_OK)
1344 std::string path = wx2std (FD->GetPath()) ;
1346 std::string fname = path + "\\bbtkPackage";
1348 std::string fname = path + "/bbtkPackage";
1351 std::cout << "Path chosen = \"" << FD->GetPath() << "\"" << std::endl;
1352 if ( Utilities::FileExists( fname ) )
1355 f.open(fname.c_str());
1358 while(pname[0] == '#')
1360 getline(f, pname, '\n');
1365 bbtk::ConfigurationFile::GetInstance().AddPackagePathsAndWrite( path );
1367 DoRegeneratePackageDoc(pname);
1368 DoRegenerateBoxesLists();
1370 _pkgBrowser->RebuildList();
1372 wxMessageBox(_T("Package successfully plugged. Please restart bbEditor to see the new package in the package browser."),_T("Plug package"),wxOK | wxICON_INFORMATION);
1373 userResponse = wxID_CANCEL;
1377 std::string err = "The directory \"" + path + "\" does not contain a 'bbtkPackage' file.";
1380 err += "\nNote: If you are on Linux please select the folder and click \"Open\", don't enter in it.";
1384 wxMessageBox(crea::std2wx(err), _T("Plug package"),wxOK | wxICON_ERROR);
1385 // THE FOLLOWING LINE GIVES ERRORS BECAUSE IT IS NECESSARY TO USE std2wx
1386 //wxMessageBox( _T( err) , _T("Plug package"),wxOK | wxICON_ERROR);
1389 }while(userResponse != wxID_CANCEL);
1393 //=========================================================================
1394 void wxGUIEditorGraphicBBS::OnEditConfig(wxCommandEvent& event)
1396 std::string commandStr;
1397 std::string configFile = ConfigurationFile::GetInstance().Get_config_xml_full_path();
1399 commandStr = "notepad.exe ";
1401 commandStr = "gedit ";
1403 commandStr = commandStr + configFile;
1404 std::cout << "system: " << commandStr << std::endl;
1405 system ( commandStr.c_str() );
1408 //=========================================================================
1409 void wxGUIEditorGraphicBBS::OnShowHTMLDoc(wxCommandEvent& event)
1412 if (_helpHtmlBrowser != NULL){
1413 _frameAUIMgr->DetachPane(_helpHtmlBrowser);
1414 _helpHtmlBrowser->Destroy();
1416 initHelpHTMLBrowser();
1417 _frameAUIMgr->AddPane(_helpHtmlBrowser, wxAuiPaneInfo().Right().MinSize(200, 200));
1418 _frameAUIMgr->Update();
1419 refreshGUIControls();
1424 //=========================================================================
1425 void wxGUIEditorGraphicBBS::OnCreateIndex(wxCommandEvent& event)
1427 printf("EED wxGUIEditorGraphicBBS::OnCreateIndex ... not implemented ..\n");
1431 //=========================================================================
1432 void wxGUIEditorGraphicBBS::OnEditComplexBoxScript(wxCommandEvent& event)
1434 BlackBoxDescriptor *bbDes = _pkgBrowser->GetActualSelected();
1437 std::string packageName = bbDes->GetPackage()->GetName();
1438 std::string typeName = bbDes->GetTypeName();
1439 if (!TryToOpenScriptComplexBox(packageName ,typeName))
1441 wxMessageDialog windowMessage1(NULL,_T("This is not a ComplexBox script."), _T("Alert !"), wxOK);
1442 windowMessage1.ShowModal();
1447 //=========================================================================
1448 void wxGUIEditorGraphicBBS::OnExit(wxCommandEvent& event)
1453 Factory::Pointer wxGUIEditorGraphicBBS::GetBBTKFactory()
1455 if (_pkgBrowser==NULL)
1457 printf ("EED ERROR! wxGUIEditorGraphicBBS::GetBBTKFactory _pkgBrowser = NULL\n");
1459 return _pkgBrowser->GetFactory();
1462 //=========================================================================
1463 void wxGUIEditorGraphicBBS::enableComplexBox()
1465 _tabsMgr->setActualDiagramComplexBox(true);
1466 refreshGUIControls();
1469 //=========================================================================
1471 void wxGUIEditorGraphicBBS::disableComplexBox()
1473 _tabsMgr->setActualDiagramComplexBox(false);
1474 refreshGUIControls();
1477 //=========================================================================
1478 void wxGUIEditorGraphicBBS::setCurrentDiagramDescription(std::string description)
1480 _tabsMgr->SetDescription(description);
1483 //=========================================================================
1484 void wxGUIEditorGraphicBBS::setCurrentDiagramAuthor(std::string author)
1486 _tabsMgr->SetAuthor(author);
1489 //=========================================================================
1490 void wxGUIEditorGraphicBBS::setCurrentDiagramExportFormat(int exportformat)
1492 _tabsMgr->SetExportFormat( exportformat );
1495 //=========================================================================
1496 void wxGUIEditorGraphicBBS::setCurrentDiagramCategory(std::string category)
1498 _tabsMgr->SetCategory(category);
1501 //=========================================================================
1502 void wxGUIEditorGraphicBBS::setCurrentDiagramMessageKind(std::string kind){
1503 _tabsMgr->SetMessageKind(kind);
1506 //=========================================================================
1507 void wxGUIEditorGraphicBBS::setCurrentDiagramMessageLevel(std::string level){
1508 _tabsMgr->SetMessageLevel(level);
1511 //=========================================================================
1512 std::string wxGUIEditorGraphicBBS::getCurrentDiagramDescription()
1514 return _tabsMgr->GetDescription();
1517 //=========================================================================
1518 std::string wxGUIEditorGraphicBBS::getCurrentDiagramAuthor()
1520 return _tabsMgr->GetAuthor();
1523 //=========================================================================
1524 int wxGUIEditorGraphicBBS::getCurrentDiagramExportFormat()
1526 return _tabsMgr->GetExportFormat();
1529 //=========================================================================
1530 std::string wxGUIEditorGraphicBBS::getCurrentDiagramCategory()
1532 return _tabsMgr->GetCategory();
1535 //=========================================================================
1536 std::string wxGUIEditorGraphicBBS::getCurrentDiagramMessageKind(){
1537 return _tabsMgr->GetMessageKind();
1540 //=========================================================================
1541 std::string wxGUIEditorGraphicBBS::getCurrentDiagramMessageLevel(){
1542 return _tabsMgr->GetMessageLevel();
1545 //=========================================================================
1546 bool wxGUIEditorGraphicBBS::isCurrentDiagramComplexBox()
1548 return _tabsMgr->isActualDiagramComplexBox();
1552 //=========================================================================
1553 void wxGUIEditorGraphicBBS::OpenScript(std::string filePathNameBBS ,std::string boxType)
1555 std::string fileName = boxType+".bbg";
1556 std::string filePathNameBBG = filePathNameBBS;
1557 filePathNameBBG[ filePathNameBBG.length()-1 ] = 'g';
1559 wxMessageDialog windowMessage1(NULL,_T("The system is going to open a bbg or bbs for you. Be careful if you save this file."), _T("Alert !"), wxOK);
1560 windowMessage1.ShowModal();
1562 if ( Utilities::FileExists( filePathNameBBG ) )
1564 OpenDiagram( filePathNameBBG , fileName );
1566 if ( Utilities::FileExists( filePathNameBBS ) )
1568 OpenBBS( filePathNameBBS , fileName );
1570 wxMessageDialog windowMessage1(NULL,_T("..ERROR.. loading script bbg/bbs."), _T("Alert !"), wxOK);
1571 windowMessage1.ShowModal();
1578 //=========================================================================
1579 bool wxGUIEditorGraphicBBS::TryToOpenScriptApplication(std::string packageName ,std::string boxType)
1581 return TryToOpenScript(packageName ,boxType, true, false);
1584 //=========================================================================
1585 bool wxGUIEditorGraphicBBS::TryToOpenScriptComplexBox(std::string packageName ,std::string boxType)
1587 return TryToOpenScript(packageName ,boxType, false, true);
1591 //=========================================================================
1592 bool wxGUIEditorGraphicBBS::TryToOpenScript(std::string packageName ,std::string boxType,bool scriptApplication, bool scriptComplexBox)
1595 std::map< std::string, BlackBoxDescriptor::Pointer> mapDesc;
1596 BlackBoxDescriptor::Pointer descriptor;
1597 k = GetBBTKFactory()->GetPackage(packageName);
1598 mapDesc = k->GetDescriptorMap();
1599 descriptor = mapDesc[boxType];
1602 descriptor->IsTypeOfScript_Application();
1603 if (descriptor!=NULL)
1606 ((descriptor->IsTypeOfScript_Application()==true) && (scriptApplication==true))
1608 ((descriptor->IsTypeOfScript_ComplexBox()==true) && (scriptComplexBox==true))
1612 OpenScript(descriptor->GetScriptFileName(),boxType);
1613 } // if descriptor Type
1615 printf("EED ERROR wxGUIEditorGraphicBBS::TryToOpenScript >> The descriptor of this box not exists (packageName:%s boxType:%s) this is not normal\n",packageName.c_str(), boxType.c_str() );
1616 } // if descriptor NULL
1621 } // EO namespace bbtk