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.5";
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';
952 if (_tabsMgr->isActualDiagramComplexBox() == false) {
953 std::string name = _tabsMgr->GetNameTabPanel();
954 if(name[name.length() - 1] == '*')
956 name =name.substr(0,name.length()-1);
958 _tabsMgr->SetNameTabPanel(wxString (name.c_str(), wxConvUTF8));
959 SaveActualDiagram(pathfilename);
960 SaveActualBBS(pathfilenamebbs);
962 AskComplexBoxConfiguration();
963 SaveActualDiagram(pathfilename);
964 SaveActualComplexBox(pathfilenamebbs);
965 } //if isActualDiagramComplexBox
966 std::string cmdPy("source ~/.bashrc; bbs2 "+pathfilenamebbs+" py" );
967 printf("EED wxGUIEditorGraphicBBS::OnSaveActualDiagram cmd:%s\n", cmdPy.c_str() );
968 system( cmdPy.c_str() );
969 std::string cmdjs("source ~/.bashrc; bbs2 "+pathfilenamebbs+" js" );
970 printf("EED wxGUIEditorGraphicBBS::OnSaveActualDiagram cmd:%s\n", cmdjs.c_str() );
971 system( cmdjs.c_str() );
974 //=========================================================================
976 void wxGUIEditorGraphicBBS::OnSaveAsActualDiagram(wxCommandEvent& event) {
977 SaveCurrentDiagramAs();
980 //=========================================================================
981 void wxGUIEditorGraphicBBS::OnExportConsoleExecCommand(wxCommandEvent& event)
983 //EED 2017-09-16 Migration wxWidgets 2.8 to 3.0
984 #if wxMAJOR_VERSION <= 2
985 wxFileDialog * saveFileDialog = new wxFileDialog(this,
986 wxT("Export console command"), wxEmptyString, wxT("ConsoleApp.txt"),
987 wxT("*.txt;*.bbs;*.bbg;*.sh;*.bat"), wxSAVE | wxOVERWRITE_PROMPT);
989 wxFileDialog * saveFileDialog = new wxFileDialog(this,
990 wxT("Export console command"), wxEmptyString, wxT("ConsoleApp.txt"),
991 wxT("*.txt;*.bbs;*.bbg;*.sh;*.bat"), wxFD_SAVE | wxFD_OVERWRITE_PROMPT);
995 if (saveFileDialog->ShowModal() == wxID_OK)
997 wxString fileName = saveFileDialog->GetPath();
998 std::string filename = (const char*) (fileName.mb_str());
999 filename=CheckExtension (filename, ".txt");
1002 file.open(filename.c_str());
1004 std::vector<std::string> extInputs = _tabsMgr->getActualTabPanel()->getSceneManager()->GetExternalInputsNames();
1006 //TODO PUT IN A METHOD OF A FILES AND TEXT MANAGER CLASS !!!
1007 //std::string inputsInCommentsWin="";
1008 //std::string inputsInCommentsUnix="";
1009 //std::string inputsInOneLineWin="";
1010 std::string inputsInOneLineUnix="";
1011 for (unsigned int i = 0; i < extInputs.size(); ++i)
1013 /* No gusto la idea al jefe pero por si acaso ...
1014 * RaC 2012 2nd HackFest
1016 inputsInCommentsWin+="REM ";
1017 inputsInCommentsWin+=extInputs[i];
1018 inputsInCommentsWin+="=\"value\"\n";
1019 inputsInCommentsUnix+="# ";
1020 inputsInCommentsUnix+=extInputs[i];
1021 inputsInCommentsUnix+="=\"value\"\n";
1024 sprintf (buffer, "%d", (i+1));
1025 inputsInOneLineWin+=extInputs[i];
1026 inputsInOneLineWin+="=\"%";
1027 inputsInOneLineWin+=buffer;
1028 inputsInOneLineWin+="\" ";
1030 inputsInOneLineUnix+=extInputs[i];
1031 inputsInOneLineUnix+="=\"<value>\" ";
1036 std::string content = "";
1037 // writing file header
1038 content += "# ----------------------------------\n";
1039 content += "# - BBTKGEditor v ";
1040 content += _currentBBGversion; //VERSION
1041 content += " Console Commands to execute BBS application\n";
1043 content += filename;
1045 content += "# ----------------------------------\n";
1048 content += "# Command to execute bbi\n";
1049 content += "bbi <bbs_path> ";
1050 content += inputsInOneLineUnix;
1052 /* No gusto la idea al jefe pero por si acaso ...
1053 * RaC 2012 2nd HackFest
1054 content += "# For Windows (copy the following lines to a .bat file)\n";
1055 content += "REM BBS application\n";
1056 content += "REM Inputs:\n";
1057 content += inputsInCommentsWin;
1058 content += "REM To use previous inputs, put %$inputName% in the corresponding input of the execution bbi line\n";
1059 content += "bbi applicationBBS.bbs ";
1060 content += inputsInOneLineWin;
1063 content += "# For Linux or Mac (copy the following lines to a .sh file)\n";
1064 content += "#!/bin/bash\n";
1065 content += "# BBS application\n";
1066 content += "# Inputs:\n";
1067 content += inputsInCommentsUnix;
1068 content += "# To use previous inputs, put $inputName in the corresponding input of the execution bbi line\n";
1069 content += "bbi applicationBBS.bbs ";
1070 content += inputsInOneLineUnix;
1081 //=========================================================================
1083 void wxGUIEditorGraphicBBS::refreshGUIControls()
1087 //RaC2012 2ndHackFest Next line seems weird ... To keep in mind for other devels
1088 wxToolBar* toolbar = GetToolBar();
1089 if (_tabsMgr->isActualDiagramComplexBox())
1091 toolbar->ToggleTool(ID_BTNCOMPLEXBOX, true);
1092 //toolbar->EnableTool(ID_ADDCOMPLEXBOXINPUT, true); RaC2012 2nd HackFest
1093 toolbar->EnableTool(ID_ADDCOMPLEXBOXOUTPUT, true);
1095 GetMenuBar()->GetMenu(0)->Enable(ID_SAVE_AS_COMPLEXBOX, true);
1096 GetMenuBar()->GetMenu(0)->Enable(ID_SAVE_AS_BBS, false);
1097 GetMenuBar()->GetMenu(0)->Enable(ID_EXPORT_CONSOLEAPP, false);
1099 toolbar->ToggleTool(ID_BTNCOMPLEXBOX, false);
1100 //toolbar->EnableTool(ID_ADDCOMPLEXBOXINPUT, false); RaC2012 2nd HackFest
1101 toolbar->EnableTool(ID_ADDCOMPLEXBOXOUTPUT, false);
1103 GetMenuBar()->GetMenu(0)->Enable(ID_SAVE_AS_COMPLEXBOX, false);
1104 GetMenuBar()->GetMenu(0)->Enable(ID_SAVE_AS_BBS, true);
1105 GetMenuBar()->GetMenu(0)->Enable(ID_EXPORT_CONSOLEAPP, true);
1108 //RaC2012 2ndHackFest
1109 GetToolBar()->EnableTool(ID_EDITPROPERTIES,true);
1111 GetToolBar()->EnableTool(ID_UNDO,_tabsMgr->getUndoState(stundo));
1112 GetToolBar()->SetToolShortHelp(ID_UNDO,crea::std2wx(stundo));
1113 GetToolBar()->EnableTool(ID_REDO,_tabsMgr->getRedoState(stredo));
1114 GetToolBar()->SetToolShortHelp(ID_REDO,crea::std2wx(stredo));
1116 if (_tabsMgr->getNumActualSelectedObjects() > 0) {
1117 GetMenuBar()->GetMenu(1)->Enable(ID_COPY_TO_COMPLEXDIAGRAM, true);
1119 ///TODO Fix the possibility to say from the SceneManager to the GUI to refresh the options
1120 GetMenuBar()->GetMenu(1)->Enable(ID_COPY_TO_COMPLEXDIAGRAM, true);
1125 //=========================================================================
1127 void wxGUIEditorGraphicBBS::OnDeleteAllBoxesActualDiagram(wxCommandEvent& event)
1129 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);
1130 if (dial->ShowModal() == wxID_YES)
1132 _tabsMgr->deleteAllBoxesActualDiagram();
1136 //=========================================================================
1138 void wxGUIEditorGraphicBBS::OnCenterViewActualDiagram(wxCommandEvent& event)
1140 _tabsMgr->centerViewActualDiagram();
1143 //=========================================================================
1144 void wxGUIEditorGraphicBBS::OpenDiagram(std::string filePathName, std::string fileName)
1146 ifstream inputStream;
1147 inputStream.open(filePathName.c_str());
1148 assert(inputStream.good()); // fails
1150 if(_tabsMgr->FindTab(filePathName)!=-1) //RaC2012 avoid opening same diagram twice
1152 inputStream.close();
1153 printf("RaC: Diagram already opened\n");
1156 _tabsMgr->addNewTab( crea::std2wx(fileName) );
1157 _tabsMgr->loadDiagram(inputStream, filePathName);
1159 _tabsMgr->saveTempActualDiagram("load diagram");
1160 GetToolBar()->EnableTool(ID_UNDO, false);
1161 GetToolBar()->EnableTool(ID_UNDO, false);
1162 inputStream.close();
1163 refreshGUIControls();
1166 //=========================================================================
1168 void wxGUIEditorGraphicBBS::OnOpenDiagram(wxCommandEvent& event)
1171 //EED 2017-09-16 Migration wxWidgets 2.8 to 3.0
1172 #if wxMAJOR_VERSION <= 2
1173 wxFileDialog * openFileDialog = new wxFileDialog(this, wxT("Open diagram"), wxEmptyString, wxT(""), wxT("*.bbg"), wxOPEN | wxFILE_MUST_EXIST);
1175 wxFileDialog * openFileDialog = new wxFileDialog(this, wxT("Open diagram"), wxEmptyString, wxT(""), wxT("*.bbg"), wxFD_OPEN | wxFD_FILE_MUST_EXIST);
1178 if (openFileDialog->ShowModal() == wxID_OK)
1180 wxString filePath = openFileDialog->GetPath();
1181 wxString fileName = openFileDialog->GetFilename();
1182 OpenDiagram( crea::wx2std(filePath) , crea::wx2std(fileName) );
1186 //=========================================================================
1187 void wxGUIEditorGraphicBBS::OnClickBtnBox(wxCommandEvent& event)
1189 std::cout<<"wxGUIEditorGraphicBBS::OnClickBtnBox"<<std::endl;
1190 BlackBoxDescriptor *bbDes = _pkgBrowser->GetActualSelected();
1191 if (bbDes != NULL) {
1192 std::string typeName = bbDes->GetTypeName();
1193 std::string packageName = bbDes->GetPackage()->GetName();
1194 wxGEditorTabPanel *pnl = this->_tabsMgr->getActualTabPanel();
1196 wxVtkSceneManager *scn = pnl->getSceneManager();
1197 scn->createGBlackBox(50, 50, packageName, typeName);
1200 SaveTempActualDiagram("New Box");
1205 //=========================================================================
1207 void wxGUIEditorGraphicBBS::OnClickBtnSelectBoxes(wxCommandEvent& event)
1209 std::string nameFilter = _pkgBrowser->GetNameFilter();
1210 _tabsMgr->SelectBoxWithPossibleName( nameFilter );
1213 //=========================================================================
1215 void wxGUIEditorGraphicBBS::OnClickBtnExecutableBox(wxCommandEvent& event)
1218 wxGEditorTabPanel *pnl = this->_tabsMgr->getActualTabPanel();
1221 wxVtkSceneManager *scn = pnl->getSceneManager();
1222 if( scn->MakeBoxExecutable() )
1223 std::cout<<"DFCH: wxGUIEditorGraphicBBS::OnClickBtnExecutableBox...successful"<<std::endl;
1225 std::cout<<"DFCH: wxGUIEditorGraphicBBS::OnClickBtnExecutableBox...Error!!"<<std::endl;
1231 //=========================================================================
1232 void wxGUIEditorGraphicBBS::OnClickBtnComplexBox(wxCommandEvent& event)
1234 std::cout<<"wxGUIEditorGraphicBBS::OnClickBtnComplexBox"<<std::endl;
1235 wxToolBar* toolbar = GetToolBar();
1236 bool temp = toolbar->GetToolState(ID_BTNCOMPLEXBOX);
1240 disableComplexBox();
1244 //=========================================================================
1246 void wxGUIEditorGraphicBBS::OnAddComplexBoxInput(wxCommandEvent& event)
1248 wxTextEntryDialog *nameDialog = new wxTextEntryDialog(this,
1249 wxT("Name of input port"));
1250 if (nameDialog->ShowModal() == wxID_OK)
1252 wxString fileName = nameDialog->GetValue();
1253 if (!fileName.IsEmpty())
1255 std::string portName = (const char*) (fileName.mb_str());
1256 if ( !boxNameExists(portName) )
1258 _tabsMgr->addActualDiagramComplexInputPort(portName);
1260 wxMessageDialog *dial = new wxMessageDialog(NULL,
1261 wxT("Impossible to create Box. The name already exists. Please provide another name"),
1262 wxT("Change name: name already exists"), wxOK | wxICON_EXCLAMATION | wxSTAY_ON_TOP);
1269 //=========================================================================
1270 void wxGUIEditorGraphicBBS::OnAddComplexBoxOutput(wxCommandEvent& event)
1272 wxTextEntryDialog *nameDialog = new wxTextEntryDialog(this,
1273 wxT("Name of output port"));
1274 if (nameDialog->ShowModal() == wxID_OK)
1276 wxString fileName = nameDialog->GetValue();
1277 if (!fileName.IsEmpty())
1279 std::string portName = (const char*) (fileName.mb_str());
1280 if ( !boxNameExists(portName) )
1282 _tabsMgr->addActualDiagramComplexOutputPort(portName);
1284 wxMessageDialog *dial = new wxMessageDialog(NULL,
1285 wxT("Impossible to create Box. The name already exists. Please provide another name"),
1286 wxT("Change name: name already exists"), wxOK | wxICON_EXCLAMATION | wxSTAY_ON_TOP);
1294 //=========================================================================
1295 void wxGUIEditorGraphicBBS::OnCopySelectedToComplexDiagram(
1296 wxCommandEvent& event)
1298 _tabsMgr->copySelectedBBoxesToComplexDiagram();
1301 //=========================================================================
1302 void wxGUIEditorGraphicBBS::OnHelpBBeditor(wxCommandEvent& event)
1304 printf("wxGUIEditorGraphicBBS::OnHelpBBeditor ....not implemented..\n");
1307 //=========================================================================
1308 void wxGUIEditorGraphicBBS::OnCreatePackage(wxCommandEvent& event)
1310 bbtkSystemTools::CreatePackage();
1313 //=========================================================================
1314 void wxGUIEditorGraphicBBS::OnCreateBlackBox(wxCommandEvent& event)
1316 bbtkSystemTools::CreateBlackBox();
1319 //=========================================================================
1320 void wxGUIEditorGraphicBBS::OnPlugPackage(wxCommandEvent& event)
1322 //DFGO2012 Plug Package functionnalities
1323 long style = wxDD_DEFAULT_STYLE | wxDD_DIR_MUST_EXIST;
1326 _T("Select package directory"),
1332 userResponse = FD->ShowModal();
1333 if(userResponse==wxID_OK)
1335 std::string path = wx2std (FD->GetPath()) ;
1337 std::string fname = path + "\\bbtkPackage";
1339 std::string fname = path + "/bbtkPackage";
1342 std::cout << "Path chosen = \"" << FD->GetPath() << "\"" << std::endl;
1343 if ( Utilities::FileExists( fname ) )
1346 f.open(fname.c_str());
1349 while(pname[0] == '#')
1351 getline(f, pname, '\n');
1356 bbtk::ConfigurationFile::GetInstance().AddPackagePathsAndWrite( path );
1358 DoRegeneratePackageDoc(pname);
1359 DoRegenerateBoxesLists();
1361 _pkgBrowser->RebuildList();
1363 wxMessageBox(_T("Package successfully plugged. Please restart bbEditor to see the new package in the package browser."),_T("Plug package"),wxOK | wxICON_INFORMATION);
1364 userResponse = wxID_CANCEL;
1368 std::string err = "The directory \"" + path + "\" does not contain a 'bbtkPackage' file.";
1371 err += "\nNote: If you are on Linux please select the folder and click \"Open\", don't enter in it.";
1375 wxMessageBox(crea::std2wx(err), _T("Plug package"),wxOK | wxICON_ERROR);
1376 // THE FOLLOWING LINE GIVES ERRORS BECAUSE IT IS NECESSARY TO USE std2wx
1377 //wxMessageBox( _T( err) , _T("Plug package"),wxOK | wxICON_ERROR);
1380 }while(userResponse != wxID_CANCEL);
1384 //=========================================================================
1385 void wxGUIEditorGraphicBBS::OnEditConfig(wxCommandEvent& event)
1387 std::string commandStr;
1388 std::string configFile = ConfigurationFile::GetInstance().Get_config_xml_full_path();
1390 commandStr = "notepad.exe ";
1392 commandStr = "gedit ";
1394 commandStr = commandStr + configFile;
1395 std::cout << "system: " << commandStr << std::endl;
1396 system ( commandStr.c_str() );
1399 //=========================================================================
1400 void wxGUIEditorGraphicBBS::OnShowHTMLDoc(wxCommandEvent& event)
1403 if (_helpHtmlBrowser != NULL){
1404 _frameAUIMgr->DetachPane(_helpHtmlBrowser);
1405 _helpHtmlBrowser->Destroy();
1407 initHelpHTMLBrowser();
1408 _frameAUIMgr->AddPane(_helpHtmlBrowser, wxAuiPaneInfo().Right().MinSize(200, 200));
1409 _frameAUIMgr->Update();
1410 refreshGUIControls();
1415 //=========================================================================
1416 void wxGUIEditorGraphicBBS::OnCreateIndex(wxCommandEvent& event)
1418 printf("EED wxGUIEditorGraphicBBS::OnCreateIndex ... not implemented ..\n");
1422 //=========================================================================
1423 void wxGUIEditorGraphicBBS::OnEditComplexBoxScript(wxCommandEvent& event)
1425 BlackBoxDescriptor *bbDes = _pkgBrowser->GetActualSelected();
1428 std::string packageName = bbDes->GetPackage()->GetName();
1429 std::string typeName = bbDes->GetTypeName();
1430 if (!TryToOpenScriptComplexBox(packageName ,typeName))
1432 wxMessageDialog windowMessage1(NULL,_T("This is not a ComplexBox script."), _T("Alert !"), wxOK);
1433 windowMessage1.ShowModal();
1438 //=========================================================================
1439 void wxGUIEditorGraphicBBS::OnExit(wxCommandEvent& event)
1444 Factory::Pointer wxGUIEditorGraphicBBS::GetBBTKFactory()
1446 if (_pkgBrowser==NULL)
1448 printf ("EED ERROR! wxGUIEditorGraphicBBS::GetBBTKFactory _pkgBrowser = NULL\n");
1450 return _pkgBrowser->GetFactory();
1453 //=========================================================================
1454 void wxGUIEditorGraphicBBS::enableComplexBox()
1456 _tabsMgr->setActualDiagramComplexBox(true);
1457 refreshGUIControls();
1460 //=========================================================================
1462 void wxGUIEditorGraphicBBS::disableComplexBox()
1464 _tabsMgr->setActualDiagramComplexBox(false);
1465 refreshGUIControls();
1468 //=========================================================================
1469 void wxGUIEditorGraphicBBS::setCurrentDiagramDescription(std::string description)
1471 _tabsMgr->SetDescription(description);
1474 //=========================================================================
1475 void wxGUIEditorGraphicBBS::setCurrentDiagramAuthor(std::string author)
1477 _tabsMgr->SetAuthor(author);
1480 //=========================================================================
1481 void wxGUIEditorGraphicBBS::setCurrentDiagramCategory(std::string category)
1483 _tabsMgr->SetCategory(category);
1486 //=========================================================================
1487 void wxGUIEditorGraphicBBS::setCurrentDiagramMessageKind(std::string kind){
1488 _tabsMgr->SetMessageKind(kind);
1491 //=========================================================================
1492 void wxGUIEditorGraphicBBS::setCurrentDiagramMessageLevel(std::string level){
1493 _tabsMgr->SetMessageLevel(level);
1496 //=========================================================================
1497 std::string wxGUIEditorGraphicBBS::getCurrentDiagramDescription()
1499 return _tabsMgr->GetDescription();
1502 //=========================================================================
1503 std::string wxGUIEditorGraphicBBS::getCurrentDiagramAuthor()
1505 return _tabsMgr->GetAuthor();
1508 //=========================================================================
1509 std::string wxGUIEditorGraphicBBS::getCurrentDiagramCategory()
1511 return _tabsMgr->GetCategory();
1514 //=========================================================================
1515 std::string wxGUIEditorGraphicBBS::getCurrentDiagramMessageKind(){
1516 return _tabsMgr->GetMessageKind();
1519 //=========================================================================
1520 std::string wxGUIEditorGraphicBBS::getCurrentDiagramMessageLevel(){
1521 return _tabsMgr->GetMessageLevel();
1524 //=========================================================================
1525 bool wxGUIEditorGraphicBBS::isCurrentDiagramComplexBox()
1527 return _tabsMgr->isActualDiagramComplexBox();
1531 //=========================================================================
1532 void wxGUIEditorGraphicBBS::OpenScript(std::string filePathNameBBS ,std::string boxType)
1534 std::string fileName = boxType+".bbg";
1535 std::string filePathNameBBG = filePathNameBBS;
1536 filePathNameBBG[ filePathNameBBG.length()-1 ] = 'g';
1538 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);
1539 windowMessage1.ShowModal();
1541 if ( Utilities::FileExists( filePathNameBBG ) )
1543 OpenDiagram( filePathNameBBG , fileName );
1545 if ( Utilities::FileExists( filePathNameBBS ) )
1547 OpenBBS( filePathNameBBS , fileName );
1549 wxMessageDialog windowMessage1(NULL,_T("..ERROR.. loading script bbg/bbs."), _T("Alert !"), wxOK);
1550 windowMessage1.ShowModal();
1557 //=========================================================================
1558 bool wxGUIEditorGraphicBBS::TryToOpenScriptApplication(std::string packageName ,std::string boxType)
1560 return TryToOpenScript(packageName ,boxType, true, false);
1563 //=========================================================================
1564 bool wxGUIEditorGraphicBBS::TryToOpenScriptComplexBox(std::string packageName ,std::string boxType)
1566 return TryToOpenScript(packageName ,boxType, false, true);
1570 //=========================================================================
1571 bool wxGUIEditorGraphicBBS::TryToOpenScript(std::string packageName ,std::string boxType,bool scriptApplication, bool scriptComplexBox)
1574 std::map< std::string, BlackBoxDescriptor::Pointer> mapDesc;
1575 BlackBoxDescriptor::Pointer descriptor;
1576 k = GetBBTKFactory()->GetPackage(packageName);
1577 mapDesc = k->GetDescriptorMap();
1578 descriptor = mapDesc[boxType];
1581 descriptor->IsTypeOfScript_Application();
1582 if (descriptor!=NULL)
1585 ((descriptor->IsTypeOfScript_Application()==true) && (scriptApplication==true))
1587 ((descriptor->IsTypeOfScript_ComplexBox()==true) && (scriptComplexBox==true))
1591 OpenScript(descriptor->GetScriptFileName(),boxType);
1592 } // if descriptor Type
1594 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() );
1595 } // if descriptor NULL
1600 } // EO namespace bbtk