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.4";
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_executablebox(executablebox_xpm);
135 wxBitmap bmp_complexbox(complexbox_xpm);
136 wxBitmap bmp_complexinputport(complexinputport_xpm);
137 wxBitmap bmp_complexoutputport(complexoutputport_xpm);
138 wxBitmap bmp_undo(undo_xpm);
139 wxBitmap bmp_redo(redo_xpm);
140 wxBitmap bmp_editProperties(editProperties_xpm);
141 wxBitmap bmp_showTree(showTree_xpm);
143 // wxToolBar *toolbar = new wxToolBar(this, wxID_ANY);
144 wxToolBar *toolbar = CreateToolBar();
146 //Adds a tool btn to the toolbar
147 toolbar->AddTool(ID_NEW, _T("New"), bmp_new, wxNullBitmap, wxITEM_NORMAL,
148 _T("New tab"), _T("Create a new panel tab"));
150 toolbar->AddTool(ID_OPEN, _T("Open diagram"), bmp_open, wxNullBitmap,
151 wxITEM_NORMAL, _T("Open a diagram"), _T("Open a diagram"));
153 toolbar->AddTool(ID_SAVE_DIAGRAM, _T("Save Diagram"), bmp_save,
154 wxNullBitmap, wxITEM_NORMAL, _T("Saves the current diagram"),
155 _T("Saves the current diagram")); //DFCH
156 //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
157 toolbar->AddTool(ID_RUN, _T("Run"), bmp_run, wxNullBitmap, wxITEM_NORMAL,
158 _T("Execute actual diagram"), _T("Execute actual diagram"));
159 toolbar->AddTool(ID_DELETEALL, _T("Delete all"), bmp_delete, wxNullBitmap,
160 wxITEM_NORMAL, _T("Delete all boxes"), _T("Delete all boxes"));
161 toolbar->AddTool(ID_CENTERVIEW, _T("Center view"), bmp_centerview,
162 wxNullBitmap, wxITEM_NORMAL, _T("Center view"), _T("Center view"));
163 toolbar->AddSeparator();
164 toolbar->AddTool(ID_BTNBOX, _T("New Box"), bmp_box, wxNullBitmap,
165 wxITEM_NORMAL, _T("New Box"), _T("Nex Box"));
166 toolbar->AddSeparator();
167 toolbar->AddTool(ID_BTEXECUTABLEBOX, _T("Select as executable Box"),
168 bmp_executablebox, wxNullBitmap, wxITEM_NORMAL,
169 _T("Select as executable Box"), _T("Select as executable Box"));
170 toolbar->AddSeparator();
171 toolbar->AddTool(ID_BTNCOMPLEXBOX, _T("Complex box"), complexbox_xpm,
172 wxNullBitmap, wxITEM_NORMAL, _T("Complex box"), _T("Complex box"));
174 //EED 2017-09-16 Migration wxWidgets 2.8 to 3.0
175 #if wxMAJOR_VERSION <= 2
176 toolbar->SetToggle(ID_BTNCOMPLEXBOX, true);
178 printf ("EED Warnning. wxGUIEditorGraphicBBS::initToolbar >>> toolbar->SetToggle \n ");
182 // RaC 2012 2nd HackFest - Now Complex inputs are any external input
183 // toolbar->AddTool(ID_ADDCOMPLEXBOXINPUT, _T("Add input to Complex box"),
184 // bmp_complexinputport, wxNullBitmap, wxITEM_NORMAL,
185 // _T("Add input to Complex box"), _T("Add input to Complex box"));
186 toolbar->AddTool(ID_ADDCOMPLEXBOXINPUT, _T("Add external input (Complex box or console app)"),
187 bmp_complexinputport, wxNullBitmap, wxITEM_NORMAL,
188 _T("Add external input (Complex box or console app)"), _T("Add external input (Complex box or console app)"));
190 toolbar->AddTool(ID_ADDCOMPLEXBOXOUTPUT, _T("Add output to Complex box"),
191 bmp_complexoutputport, wxNullBitmap, wxITEM_NORMAL,
192 _T("Add output Complex box"), _T("Add output Complex box"));
194 // toolbar->EnableTool(ID_ADDCOMPLEXBOXINPUT, false); RaC2012 2nd HackFest
195 toolbar->EnableTool(ID_ADDCOMPLEXBOXINPUT, true);
197 toolbar->EnableTool(ID_ADDCOMPLEXBOXOUTPUT, false);
198 toolbar->AddSeparator();
199 toolbar->AddTool(ID_UNDO, _T("Undo"),bmp_undo, wxNullBitmap, wxITEM_NORMAL, _T("Undo"), _T("Undo"));
200 toolbar->AddTool(ID_REDO, _T("Redo"),bmp_redo, wxNullBitmap, wxITEM_NORMAL, _T("Redo"), _T("Redo"));
201 toolbar->AddSeparator();
202 toolbar->AddTool(ID_EDITPROPERTIES, _T("Edit diagram properties"),bmp_editProperties, wxNullBitmap, wxITEM_NORMAL, _T("Edit diagram properties"), _T("Edit diagram properties"));
203 toolbar->EnableTool(ID_EDITPROPERTIES, false);
205 toolbar->AddTool(ID_SHOWTREE, _T("Show tree"),bmp_showTree, wxNullBitmap, wxITEM_NORMAL, _T("Show tree"), _T("Show tree"));
208 toolbar->EnableTool(ID_UNDO, false);
209 toolbar->EnableTool(ID_REDO, false);
210 toolbar->SetMargins(2, 2);
216 // connect command event handlers
218 Connect(ID_NEW, wxEVT_COMMAND_TOOL_CLICKED,
219 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnCreateNewTab));
220 Connect(ID_OPEN, wxEVT_COMMAND_TOOL_CLICKED,
221 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnOpenDiagram));
222 Connect(ID_SAVE_DIAGRAM, wxEVT_COMMAND_TOOL_CLICKED,
223 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnSaveActualDiagram)); //DFCH
224 Connect(ID_SAVE_AS_DIAGRAM, wxEVT_COMMAND_TOOL_CLICKED,
225 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnSaveAsActualDiagram)); //DFCH
228 wxEVT_COMMAND_TOOL_CLICKED,
229 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnExecuteActualDiagram));
232 wxEVT_COMMAND_TOOL_CLICKED,
233 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnDeleteAllBoxesActualDiagram));
236 wxEVT_COMMAND_TOOL_CLICKED,
237 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnCenterViewActualDiagram));
238 Connect(ID_BTNBOX, wxEVT_COMMAND_TOOL_CLICKED,
239 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnClickBtnBox));
242 wxEVT_COMMAND_TOOL_CLICKED,
243 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnClickBtnExecutableBox));
244 Connect(ID_BTNCOMPLEXBOX, wxEVT_COMMAND_TOOL_CLICKED,
245 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnClickBtnComplexBox));
246 Connect(ID_ADDCOMPLEXBOXINPUT, wxEVT_COMMAND_TOOL_CLICKED,
247 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnAddComplexBoxInput));
248 Connect(ID_ADDCOMPLEXBOXOUTPUT, wxEVT_COMMAND_TOOL_CLICKED,
249 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnAddComplexBoxOutput));
250 Connect(ID_UNDO,wxEVT_COMMAND_TOOL_CLICKED, wxCommandEventHandler(wxGUIEditorGraphicBBS::OnUndo));
251 Connect(ID_REDO,wxEVT_COMMAND_TOOL_CLICKED, wxCommandEventHandler(wxGUIEditorGraphicBBS::OnRedo));
252 Connect(ID_CHANGENAME, wxEVT_COMMAND_RIGHT_CLICK, wxCommandEventHandler(wxGUIEditorGraphicBBS::OnChangeName));
253 Connect(ID_EDITPROPERTIES,wxEVT_COMMAND_TOOL_CLICKED, wxCommandEventHandler(wxGUIEditorGraphicBBS::OnEditDiagramProperties));
254 Connect(ID_SHOWTREE,wxEVT_COMMAND_TOOL_CLICKED, wxCommandEventHandler(wxGUIEditorGraphicBBS::OnShowTree));
258 //=========================================================================
259 void wxGUIEditorGraphicBBS::initHelpHTMLBrowser() {
261 _helpHtmlBrowser = new WxGUIHtmlBrowser(this, wxSize(200, 0));
267 //=========================================================================
268 void wxGUIEditorGraphicBBS::initMenu() {
269 // Create File menu and its items
270 wxMenu *fileMenu = new wxMenu();
271 fileMenu->Append(ID_NEW, _T("New diagram"), _T("New"));
272 fileMenu->Append(ID_SAVE_DIAGRAM, _T("Save Diagram"), _T("Save Diagram")); //DFCH
273 fileMenu->Append(ID_SAVE_AS_DIAGRAM, _T("Save Diagram As"),
274 _T("Save Diagram As")); //DFCH
275 fileMenu->Append(ID_OPEN_BBS, _T("Open BBS"), _T("Open BBS"));
277 fileMenu->Append(ID_OPEN, _T("Open a diagram"), _T("Open a diagram"));
278 fileMenu->Append(ID_SAVE_AS_BBS, _T("Save BBS"), _T("Save BBS"));
279 fileMenu->Append(ID_SAVE_AS_COMPLEXBOX, _T("Save complex box"),
280 _T("Save complex box"));
281 fileMenu->Append(ID_EXPORT_CONSOLEAPP, _T("Export console commands"),
282 _T("Export console execution commands"));
283 fileMenu->Append(wxID_EXIT, _T("E&xit"), _T("Exit"));
285 Connect(ID_NEW, wxEVT_COMMAND_MENU_SELECTED,
286 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnCreateNewTab));
287 Connect(ID_SAVE_DIAGRAM, wxEVT_COMMAND_MENU_SELECTED,
288 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnSaveActualDiagram)); //DFCH
289 Connect(ID_SAVE_AS_DIAGRAM, wxEVT_COMMAND_MENU_SELECTED,
290 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnSaveAsActualDiagram));
291 Connect(ID_OPEN_BBS, wxEVT_COMMAND_MENU_SELECTED,
292 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnOpenBBS));
293 Connect(ID_SAVE_AS_BBS, wxEVT_COMMAND_MENU_SELECTED,
294 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnSaveActualBBS));
295 Connect( ID_SAVE_AS_COMPLEXBOX, wxEVT_COMMAND_MENU_SELECTED,
296 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnSaveActualComplexBox));
297 Connect( ID_EXPORT_CONSOLEAPP, wxEVT_COMMAND_MENU_SELECTED,
298 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnExportConsoleExecCommand));
299 Connect(wxID_EXIT, wxEVT_COMMAND_MENU_SELECTED,
300 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnExit));
302 // Create Edit menu and its items
303 wxMenu *editMenu = new wxMenu;
304 editMenu->Append(ID_COPY_TO_COMPLEXDIAGRAM, _T("Copy selected to complex box"), _T("Creates a new complex box diagram with selected boxes"));
305 editMenu->Append(ID_EDIT_COMPLEXBOX_SCRIPT, _T("Edit Complex Box"), _T("Edit Complex Box"));
306 Connect( ID_COPY_TO_COMPLEXDIAGRAM, wxEVT_COMMAND_MENU_SELECTED,
307 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnCopySelectedToComplexDiagram));
308 Connect( ID_EDIT_COMPLEXBOX_SCRIPT, wxEVT_COMMAND_MENU_SELECTED,
309 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnEditComplexBoxScript));
311 // Create Help menu and its items
312 wxMenu *helpMenu = new wxMenu;
313 helpMenu->Append(wxID_ABOUT, _T("&About..."), _T("About"));
314 helpMenu->Append(ID_HELP_BBEDITOR, _T("&Help..."), _T("Help"));
315 Connect(ID_HELP_BBEDITOR, wxEVT_COMMAND_MENU_SELECTED,
316 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnHelpBBeditor));
319 wxMenu *menuTools = new wxMenu;
320 menuTools->Append(ID_bbEditor_Tool_Menu_CreatePackage,
321 _T("Create &package") );
322 menuTools->Append(ID_bbEditor_Tool_Menu_CreateBlackBox,
323 _T("Create &blackbox") );
324 menuTools->Append(ID_bbEditor_Tool_Menu_PlugPackage, _T("Plug package") );
325 menuTools->Append(ID_bbEditor_Tool_Menu_EditConfig, _T("&Edit bbtk config") );
326 menuTools->Append(ID_bbEditor_Tool_Menu_ShowHTMLDoc,
327 _T("Show &HTML documentation") );
328 menuTools->Append(ID_bbEditor_Tool_Menu_CreateIndex, _T("&Generate index") );
330 Connect(ID_bbEditor_Tool_Menu_CreatePackage, wxEVT_COMMAND_MENU_SELECTED,
331 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnCreatePackage));
332 Connect(ID_bbEditor_Tool_Menu_CreateBlackBox, wxEVT_COMMAND_MENU_SELECTED,
333 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnCreateBlackBox));
334 Connect(ID_bbEditor_Tool_Menu_PlugPackage, wxEVT_COMMAND_MENU_SELECTED,
335 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnPlugPackage));
336 Connect(ID_bbEditor_Tool_Menu_EditConfig, wxEVT_COMMAND_MENU_SELECTED,
337 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnEditConfig));
338 Connect(ID_bbEditor_Tool_Menu_ShowHTMLDoc, wxEVT_COMMAND_MENU_SELECTED,
339 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnShowHTMLDoc));
340 Connect(ID_bbEditor_Tool_Menu_CreateIndex, wxEVT_COMMAND_MENU_SELECTED,
341 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnCreateIndex));
343 // Append the created menu to the menu bar
344 wxMenuBar *menuBar = new wxMenuBar();
345 menuBar->Append(fileMenu, _T("&File") );
346 menuBar->Append(editMenu, _T("&Edit") );
347 menuBar->Append(menuTools, _T("&Tool") );
348 menuBar->Append(helpMenu, _T("&Help") );
350 // Attach this menu bar to the frame
354 //=========================================================================
355 void wxGUIEditorGraphicBBS::initTabPanelsManager()
357 _notebook = new wxAuiNotebook(this, wxID_NOTEBOOK, wxDefaultPosition,
358 wxDefaultSize, wxAUI_NB_TOP | wxAUI_NB_TAB_MOVE
359 | wxAUI_NB_CLOSE_ON_ACTIVE_TAB | wxAUI_NB_TAB_FIXED_WIDTH
360 | wxAUI_NB_WINDOWLIST_BUTTON);
361 _tabsMgr = new wxTabPanelsManager(this);
362 _frameAUIMgr->AddPane(_notebook, wxAuiPaneInfo().CenterPane());
365 //=========================================================================
366 void wxGUIEditorGraphicBBS::initPackageBrowser()
368 _pkgBrowser = new WxGUIPackageBrowser2(this);
369 _pkgBrowser->IncludeAll();
370 _frameAUIMgr->AddPane(_pkgBrowser, wxAuiPaneInfo().Left().MinSize(30, 500).BestSize(750,500).CloseButton(false));
373 //================================================================
375 void wxGUIEditorGraphicBBS::DoRegeneratePackageDoc(const std::string& pack)
377 std::string mess("Regenerating doc for package '");
381 mess = "Regenerating doc for all packages";
384 mess += " ... please wait";
386 SetStatusText(std2wx(mess));
394 command += ConfigurationFile::GetInstance().Get_bin_path();
395 command += ConfigurationFile::GetInstance().Get_file_separator();
396 command += "bbRegeneratePackageDoc";
401 command += " " + pack + " -q";
402 bbtkMessage("debug",1,"Executing system command '"<<command<<"'"<<std::endl);
404 if (!system(command.c_str())) {
405 SetStatusText(_T("Done !"));
407 wxMessageBox(_T("Done !"),_T("Regenerate package '")
408 +std2wx(pack)+_T("' doc"),
409 wxOK | wxICON_INFORMATION);
412 SetStatusText(_T("Done !"));
413 wxString err(_T("An error occured while running '"));
414 err += bbtk::std2wx(command) + _T("'");
415 wxMessageBox(err, _T("Regenerate package doc"), wxOK | wxICON_ERROR);
419 //================================================================
420 void wxGUIEditorGraphicBBS::DoRegenerateBoxesLists() {
421 SetStatusText(_T("Regenerating boxes lists ... please wait"));
428 command += ConfigurationFile::GetInstance().Get_bin_path();
429 command += ConfigurationFile::GetInstance().Get_file_separator();
430 command += "bbRegenerateBoxesLists";
437 bbtkMessage("debug",1,"Executing system command '"<<command<<"'"<<std::endl);
439 if (!system(command.c_str())) {
440 SetStatusText(_T("Done !"));
442 wxMessageBox(_T("Done !"),_T("Regenerate boxes lists"),
443 wxOK | wxICON_INFORMATION);
446 SetStatusText(_T("Done !"));
447 wxString err(_T("An error occured while running '"));
448 err += bbtk::std2wx(command) + _T("'");
449 wxMessageBox(err, _T("Regenerate boxes lists"), wxOK | wxICON_ERROR);
453 //================================================================
454 void wxGUIEditorGraphicBBS::RegenerateAll() {
455 DoRegeneratePackageDoc("-a");
456 DoRegenerateBoxesLists();
459 //================================================================
461 wxAuiNotebook* wxGUIEditorGraphicBBS::getAuiNotebook() {
465 //================================================================
467 void wxGUIEditorGraphicBBS::displayBlackBoxInfo(std::string packageName, std::string boxName)
469 if (_actualPkgBrowserPkgName != packageName || _actualPkgBrowserBoxName != boxName)
472 _actualPkgBrowserPkgName = packageName;
473 _actualPkgBrowserBoxName = boxName;
475 //EED 15 oct 2012 BlackBoxDescriptor::Pointer descriptor = GObjectsMVCFactory::getInstance()->getBlackBoxDescriptor(packageName, boxName);
478 //EED ComplexBlackBoxDescriptor::Pointer descriptor;
479 BlackBoxDescriptor::Pointer descriptor;
481 std::map< std::string, BlackBoxDescriptor::Pointer> mapDesc;
482 k = _pkgBrowser->GetFactory()->GetPackage(_actualPkgBrowserPkgName);
483 mapDesc = k->GetDescriptorMap();
484 descriptor = mapDesc[_actualPkgBrowserBoxName];
490 descriptor->GetBoxesInside(tree, 0);
493 //std::vector<std::string> boxesDiagram = _sceneM->boxesDiagram;
494 //for(int i=0;i<boxesDiagram.size();i++){
495 // std::cout<<"caja: "<<boxesDiagram[i]<<std::endl;
498 _actualPkgBrowserPkgName = "";
499 _actualPkgBrowserBoxName = "";
503 BlackBoxDescriptor::Pointer descriptor;
504 std::map< std::string, BlackBoxDescriptor::Pointer> mapDesc;
505 k = _pkgBrowser->GetFactory()->GetPackage(packageName);
506 std::vector<std::string> temp;
507 _pkgBrowser->GetFactory()->GetPackagesList(temp);
508 for(int ii = 0 ; ii < temp.size() ; ii++)
510 std::cout << " packs "<< temp[ii]<< std::endl;
512 mapDesc = k->GetDescriptorMap();
513 descriptor = mapDesc[boxName];
515 _pkgBrowser->WxGUIBlackBoxListUserOnSelected(descriptor.get());
519 //=========================================================================
521 void wxGUIEditorGraphicBBS::editBlackBox(GBlackBoxModel *bbmodel) {
522 wxBlackBoxEditionDialog* dialog =
523 new wxBlackBoxEditionDialog(this, bbmodel);
527 //=========================================================================
529 bool wxGUIEditorGraphicBBS::boxNameExists(std::string boxname) {
531 return this->_tabsMgr->getActualTabPanel()->getSceneManager()->boxExist(boxname);
534 //=========================================================================
536 void wxGUIEditorGraphicBBS::updateStatusBar(std::string textStatus) {
537 SetStatusText(crea::std2wx(textStatus));
540 //=========================================================================
542 void wxGUIEditorGraphicBBS::executeScript(std::string script) {
543 std::string separator =
544 ConfigurationFile::GetInstance().Get_file_separator();
545 std::string dir = ConfigurationFile::GetInstance().Get_default_temp_dir();
546 std::string filename = dir + separator + "tmp_bbtk.bbs";
549 tempFile.open(filename.c_str());
553 std::string command = "";
556 command += "start /b ";
559 // command += "\""+ crea::System::GetExecutablePath();
561 // command += separator + "../../../bbi.app/Contents/MacOS";
565 command += "\"" + filename + "\"";
572 command = "source ~/.bbtk/profile_creatools; "+command;
576 printf("RaC wxGUIEditorGraphicBBS::executeScript %s \n", command.c_str());
577 system(command.c_str());
580 //=========================================================================
581 std::string wxGUIEditorGraphicBBS::CheckExtension(std::string filename, std::string extension) {
582 if(filename.size() > extension.size() ){
583 if( (filename.compare(filename.size()-extension.size(), extension.size(),extension)) !=0 ){
584 filename.append(extension);
587 filename.append(extension);
591 //=========================================================================
593 //=========================================================================
595 void wxGUIEditorGraphicBBS::OnCreateNewTab(wxCommandEvent& event) {
596 _tabsMgr->addNewTab();
597 refreshGUIControls();
600 void wxGUIEditorGraphicBBS::OnUndo(wxCommandEvent& event) {
601 unsigned short disable;
605 _tabsMgr->loadTempDiagram(0);
606 disable = _tabsMgr->getUndoState(stundo);
609 std::string name = _tabsMgr->GetNameTabPanel();
610 if(name[name.length() - 1] == '*')
612 name =name.substr(0,name.length()-1);
614 _tabsMgr->SetNameTabPanel(wxString (name.c_str(), wxConvUTF8));
617 GetToolBar()->EnableTool(ID_UNDO,disable);
618 GetToolBar()->SetToolShortHelp(ID_UNDO,crea::std2wx(stundo));
619 GetToolBar()->EnableTool(ID_REDO,_tabsMgr->getRedoState(stredo));
620 GetToolBar()->SetToolShortHelp(ID_REDO,crea::std2wx(stredo));
621 refreshGUIControls();
624 //=========================================================================
626 void wxGUIEditorGraphicBBS::OnRedo(wxCommandEvent& event) {
627 unsigned short disable;
631 _tabsMgr->loadTempDiagram(1);
632 std::string name = _tabsMgr->GetNameTabPanel();
633 if(name[name.length() - 1] != '*')
635 _tabsMgr->SetNameTabPanel(wxString (name.c_str(), wxConvUTF8));
636 GetToolBar()->EnableTool(ID_UNDO,_tabsMgr->getUndoState(stundo));
637 GetToolBar()->SetToolShortHelp(ID_UNDO,crea::std2wx(stundo));
638 GetToolBar()->EnableTool(ID_REDO,_tabsMgr->getRedoState(stredo));
639 GetToolBar()->SetToolShortHelp(ID_REDO,crea::std2wx(stredo));
640 refreshGUIControls();
643 void wxGUIEditorGraphicBBS::OnChangeName(wxCommandEvent& event){
645 //=========================================================================
647 void wxGUIEditorGraphicBBS::OnShowTree(wxCommandEvent& event){
648 std::cout << "wxGUIEditorGraphicBBS::OnShowTree"<<std::endl;
649 if (_actualPkgBrowserPkgName !="" || _actualPkgBrowserBoxName != "")
652 //EED ComplexBlackBoxDescriptor::Pointer descriptor;
653 BlackBoxDescriptor::Pointer descriptor;
655 std::map< std::string, BlackBoxDescriptor::Pointer> mapDesc;
656 k = _pkgBrowser->GetFactory()->GetPackage(_actualPkgBrowserPkgName);
657 mapDesc = k->GetDescriptorMap();
658 descriptor = mapDesc[_actualPkgBrowserBoxName];
664 descriptor->GetBoxesInside(tree, 0);
666 _actualPkgBrowserPkgName = "";
667 _actualPkgBrowserBoxName = "";
671 std::cout<<"Select a Box"<<std::endl;
675 //=========================================================================
677 void wxGUIEditorGraphicBBS::OnEditDiagramProperties(wxCommandEvent& event)
679 wxDiagramPropertiesEditionDialog* dialog =
680 new wxDiagramPropertiesEditionDialog(this, tree);
684 //=========================================================================
686 void wxGUIEditorGraphicBBS::OnExecuteActualDiagram(wxCommandEvent& event) {
687 std::string script1 = _tabsMgr->getActualDiagramBBS(true);
688 cout << endl << "RaC wxGUIEditorGraphicBBS::executeActualDiagram SCRIPT"
690 cout << script1 << endl;
692 std::string script2 = _tabsMgr->getActualDiagramBBS(false);
693 executeScript(script2);
697 //=========================================================================
698 void wxGUIEditorGraphicBBS::OpenBBS(std::string filePathName, std::string fileName)
700 _tabsMgr->addNewTab( crea::std2wx(fileName) );
701 bbtk::InterpreterBBS::Pointer I = bbtk::InterpreterBBS::New( this->_tabsMgr->getActualTabPanel()->getSceneManager(), _pkgBrowser->GetFactory());
702 // We tell the interpreter to throw exceptions on error
704 // Interpret the file supposed to define a box called 'Processing'
705 I->InterpretFile( filePathName );
706 refreshGUIControls();
709 //=========================================================================
711 //=========================================================================
712 void wxGUIEditorGraphicBBS::OnOpenBBS(wxCommandEvent& event)
714 //EED 2017-09-16 Migration wxWidgets 2.8 to 3.0
715 #if wxMAJOR_VERSION <= 2
716 wxFileDialog * openFileDialog = new wxFileDialog(this, wxT("Open BBS"), wxEmptyString, wxT("NewBBS"), wxT("*.bbs"), wxOPEN);
718 wxFileDialog * openFileDialog = new wxFileDialog(this, wxT("Open BBS"), wxEmptyString, wxT("NewBBS"), wxT("*.bbs"), wxFD_OPEN);
721 if (openFileDialog->ShowModal() == wxID_OK)
723 OpenBBS( crea::wx2std(openFileDialog->GetPath()) , crea::wx2std(openFileDialog->GetFilename()) );
727 if (openFileDialog->ShowModal() == wxID_OK)
729 wxString fileName = openFileDialog->GetPath();
730 _tabsMgr->addNewTab(openFileDialog->GetFilename());
731 bbtk::InterpreterBBS::Pointer I = bbtk::InterpreterBBS::New( this->_tabsMgr->getActualTabPanel()->getSceneManager(), _pkgBrowser->GetFactory());
732 // We tell the interpreter to throw exceptions on error
734 // Interpret the file supposed to define a box called 'Processing'
735 I->InterpretFile((const char*) (fileName.mb_str()));
737 refreshGUIControls();
741 //=========================================================================
742 void wxGUIEditorGraphicBBS::SaveActualBBS(std::string filename) {
745 //EED file.open(fileName.c_str());
746 file.open(filename.c_str());
747 std::string content = "";
748 // writing file header
749 content += "# ----------------------------------\n";
750 content += "# - BBTKGEditor v ";
751 content += _currentBBGversion; //VERSION
752 content += " BBS BlackBox Script\n";
756 content += "# ----------------------------------\n";
758 content += _tabsMgr->getActualDiagramBBS();
763 void wxGUIEditorGraphicBBS::OnSaveActualBBS(wxCommandEvent& event) {
765 //EED 2017-09-16 Migration wxWidgets 2.8 to 3.0
766 #if wxMAJOR_VERSION <= 2
767 wxFileDialog * saveFileDialog = new wxFileDialog(this,
768 wxT("Save actual BBS"), wxEmptyString, wxT("NewBBS"),
769 wxT("*.bbs"), wxSAVE | wxOVERWRITE_PROMPT);
771 wxFileDialog * saveFileDialog = new wxFileDialog(this,
772 wxT("Save actual BBS"), wxEmptyString, wxT("NewBBS"),
773 wxT("*.bbs"), wxFD_SAVE | wxFD_OVERWRITE_PROMPT);
776 if (saveFileDialog->ShowModal() == wxID_OK) {
777 wxString fileName = saveFileDialog->GetPath();
778 std::string filename = (const char*) (fileName.mb_str());
779 filename=CheckExtension (filename, ".bbs");
780 SaveActualBBS(filename);
785 void wxGUIEditorGraphicBBS::AskComplexBoxConfiguration() {
786 std::string cbName = _tabsMgr->GetCbName();
787 std::string paName = _tabsMgr->GetCbPackageName();
789 wxTextEntryDialog *cbNameDialog = new wxTextEntryDialog(this,
790 wxT("Complex Box name"));
791 wxTextEntryDialog *paNameDialog = new wxTextEntryDialog(this,
792 wxT("Package name"));
794 cbNameDialog->SetValue(wxString(cbName.c_str(), wxConvUTF8));
795 paNameDialog->SetValue(wxString(paName.c_str(), wxConvUTF8));
797 if (cbNameDialog->ShowModal() == wxID_OK) {
798 wxString complexboxname = cbNameDialog->GetValue();
799 cbName = (const char*) (complexboxname.mb_str());
802 if (paNameDialog->ShowModal() == wxID_OK) {
803 wxString packagename = paNameDialog->GetValue();
804 paName = (const char*) (packagename.mb_str());
807 _tabsMgr->SetCbName(cbName);
808 _tabsMgr->SetCbPackageName(paName);
811 //=========================================================================
813 void wxGUIEditorGraphicBBS::SaveActualComplexBox(std::string filename) {
815 file.open(filename.c_str());
817 std::string content = "";
819 // writing file header
820 content += "# ----------------------------------\n";
821 content += "# - BBTKGEditor v ";
822 content += _currentBBGversion;//VERSION
823 content += " BBS BlackBox Script (Complex Box)\n";
827 content += "# ----------------------------------\n";
829 content += _tabsMgr->getActualComplexBoxBBS();
834 //=========================================================================
836 void wxGUIEditorGraphicBBS::OnSaveActualComplexBox(wxCommandEvent& event)
838 //EED 2017-09-16 Migration wxWidgets 2.8 to 3.0
839 #if wxMAJOR_VERSION <= 2
840 wxFileDialog * saveFileDialog = new wxFileDialog(this,
841 wxT("Save Complex Box BBS"), wxEmptyString,
842 _T("ComplexBoxName"), wxT("*.bbs"), wxSAVE
843 | wxOVERWRITE_PROMPT);
845 wxFileDialog * saveFileDialog = new wxFileDialog(this,
846 wxT("Save Complex Box BBS"), wxEmptyString,
847 _T("ComplexBoxName"), wxT("*.bbs"), wxFD_SAVE
848 | wxFD_OVERWRITE_PROMPT);
851 if (saveFileDialog->ShowModal() == wxID_OK) {
852 wxString fileName = saveFileDialog->GetPath();
853 std::string filename = (const char*) (fileName.mb_str());
854 filename=CheckExtension (filename, ".bbs");
855 SaveActualComplexBox(filename);
859 //=========================================================================
860 void wxGUIEditorGraphicBBS::SaveActualDiagram(std::string filename) {
862 file.open(filename.c_str());
864 std::string content = "";
866 // writing file header
867 content += "# ----------------------------------\n";
868 content += "# - BBTKGEditor v ";
869 content += _currentBBGversion; //VERSION
870 content += " BBG BlackBox Diagram file\n";
876 content += "# ----------------------------------\n";
878 content += "APP_START\n";
879 _tabsMgr->saveActualDiagram(content, filename); //DFCH
880 content += "APP_END\n";
885 //=========================================================================
886 void wxGUIEditorGraphicBBS::SaveTempActualDiagram(const std::string &action)
890 std::string name = _tabsMgr->GetNameTabPanel();
891 if(name[name.length() - 1] != '*')
893 _tabsMgr->SetNameTabPanel(wxString (name.c_str(), wxConvUTF8));
894 _tabsMgr->saveTempActualDiagram(action);
895 GetToolBar()->EnableTool(ID_UNDO,_tabsMgr->getUndoState(stundo));
896 GetToolBar()->SetToolShortHelp(ID_UNDO,crea::std2wx(stundo));
897 GetToolBar()->EnableTool(ID_REDO,_tabsMgr->getRedoState(stredo));
898 GetToolBar()->SetToolShortHelp(ID_REDO,crea::std2wx(stredo));
901 //=========================================================================
903 //The following method allows to save the current diagram asking the filename
905 void wxGUIEditorGraphicBBS::SaveCurrentDiagramAs()
908 //EED 2017-09-16 Migration wxWidgets 2.8 to 3.0
909 #if wxMAJOR_VERSION <= 2
910 wxFileDialog * saveFileDialog = new wxFileDialog(this,
911 wxT("Save current diagram"), wxEmptyString, wxT("NewDiagram"),
912 wxT("*.bbg"), wxSAVE | wxOVERWRITE_PROMPT);
914 wxFileDialog * saveFileDialog = new wxFileDialog(this,
915 wxT("Save current diagram"), wxEmptyString, wxT("NewDiagram"),
916 wxT("*.bbg"), wxFD_SAVE | wxFD_OVERWRITE_PROMPT);
919 if (saveFileDialog->ShowModal() == wxID_OK) {
920 //_tabsMgr->SetNameTabPanel(saveFileDialog->GetFilename());
921 wxString pathfileName = saveFileDialog->GetPath();
922 std::string pathfilename = (const char*) (pathfileName.mb_str());
923 pathfilename=CheckExtension (pathfilename, ".bbg");
925 //modify the tab name accordingly
926 wxString fileName = saveFileDialog->GetFilename();
927 std::string filename = (const char*) (fileName.mb_str());
928 filename=CheckExtension (filename, ".bbg");
929 _tabsMgr->SetNameTabPanel( wxString (filename.c_str(), wxConvUTF8) );
931 std::string pathfilenamebbs = pathfilename;
932 pathfilenamebbs[pathfilenamebbs.length() - 1] = 's';
933 if (_tabsMgr->isActualDiagramComplexBox() == false) {
934 SaveActualDiagram(pathfilename);
935 SaveActualBBS(pathfilenamebbs);
937 AskComplexBoxConfiguration();
938 SaveActualDiagram(pathfilename);
939 SaveActualComplexBox(pathfilenamebbs);
940 } //if isActualDiagramComplexBox
941 } // if saveFileDialog
943 //=========================================================================
945 void wxGUIEditorGraphicBBS::OnSaveActualDiagram(wxCommandEvent& event) {
946 std::string pathfilename = _tabsMgr->GetCurrentTabPanelPath();
947 if (pathfilename.empty()) {
948 SaveCurrentDiagramAs();
950 std::string pathfilenamebbs = pathfilename;
951 pathfilenamebbs[pathfilenamebbs.length() - 1] = 's';
953 if (_tabsMgr->isActualDiagramComplexBox() == false) {
954 std::string name = _tabsMgr->GetNameTabPanel();
955 if(name[name.length() - 1] == '*')
957 name =name.substr(0,name.length()-1);
959 _tabsMgr->SetNameTabPanel(wxString (name.c_str(), wxConvUTF8));
960 SaveActualDiagram(pathfilename);
961 SaveActualBBS(pathfilenamebbs);
963 AskComplexBoxConfiguration();
964 SaveActualDiagram(pathfilename);
965 SaveActualComplexBox(pathfilenamebbs);
966 } //if isActualDiagramComplexBox
969 //=========================================================================
971 void wxGUIEditorGraphicBBS::OnSaveAsActualDiagram(wxCommandEvent& event) {
972 SaveCurrentDiagramAs();
975 //=========================================================================
976 void wxGUIEditorGraphicBBS::OnExportConsoleExecCommand(wxCommandEvent& event)
978 //EED 2017-09-16 Migration wxWidgets 2.8 to 3.0
979 #if wxMAJOR_VERSION <= 2
980 wxFileDialog * saveFileDialog = new wxFileDialog(this,
981 wxT("Export console command"), wxEmptyString, wxT("ConsoleApp.txt"),
982 wxT("*.txt;*.bbs;*.bbg;*.sh;*.bat"), wxSAVE | wxOVERWRITE_PROMPT);
984 wxFileDialog * saveFileDialog = new wxFileDialog(this,
985 wxT("Export console command"), wxEmptyString, wxT("ConsoleApp.txt"),
986 wxT("*.txt;*.bbs;*.bbg;*.sh;*.bat"), wxFD_SAVE | wxFD_OVERWRITE_PROMPT);
990 if (saveFileDialog->ShowModal() == wxID_OK)
992 wxString fileName = saveFileDialog->GetPath();
993 std::string filename = (const char*) (fileName.mb_str());
994 filename=CheckExtension (filename, ".txt");
997 file.open(filename.c_str());
999 std::vector<std::string> extInputs = _tabsMgr->getActualTabPanel()->getSceneManager()->GetExternalInputsNames();
1001 //TODO PUT IN A METHOD OF A FILES AND TEXT MANAGER CLASS !!!
1002 //std::string inputsInCommentsWin="";
1003 //std::string inputsInCommentsUnix="";
1004 //std::string inputsInOneLineWin="";
1005 std::string inputsInOneLineUnix="";
1006 for (unsigned int i = 0; i < extInputs.size(); ++i)
1008 /* No gusto la idea al jefe pero por si acaso ...
1009 * RaC 2012 2nd HackFest
1011 inputsInCommentsWin+="REM ";
1012 inputsInCommentsWin+=extInputs[i];
1013 inputsInCommentsWin+="=\"value\"\n";
1014 inputsInCommentsUnix+="# ";
1015 inputsInCommentsUnix+=extInputs[i];
1016 inputsInCommentsUnix+="=\"value\"\n";
1019 sprintf (buffer, "%d", (i+1));
1020 inputsInOneLineWin+=extInputs[i];
1021 inputsInOneLineWin+="=\"%";
1022 inputsInOneLineWin+=buffer;
1023 inputsInOneLineWin+="\" ";
1025 inputsInOneLineUnix+=extInputs[i];
1026 inputsInOneLineUnix+="=\"<value>\" ";
1031 std::string content = "";
1032 // writing file header
1033 content += "# ----------------------------------\n";
1034 content += "# - BBTKGEditor v ";
1035 content += _currentBBGversion; //VERSION
1036 content += " Console Commands to execute BBS application\n";
1038 content += filename;
1040 content += "# ----------------------------------\n";
1043 content += "# Command to execute bbi\n";
1044 content += "bbi <bbs_path> ";
1045 content += inputsInOneLineUnix;
1047 /* No gusto la idea al jefe pero por si acaso ...
1048 * RaC 2012 2nd HackFest
1049 content += "# For Windows (copy the following lines to a .bat file)\n";
1050 content += "REM BBS application\n";
1051 content += "REM Inputs:\n";
1052 content += inputsInCommentsWin;
1053 content += "REM To use previous inputs, put %$inputName% in the corresponding input of the execution bbi line\n";
1054 content += "bbi applicationBBS.bbs ";
1055 content += inputsInOneLineWin;
1058 content += "# For Linux or Mac (copy the following lines to a .sh file)\n";
1059 content += "#!/bin/bash\n";
1060 content += "# BBS application\n";
1061 content += "# Inputs:\n";
1062 content += inputsInCommentsUnix;
1063 content += "# To use previous inputs, put $inputName in the corresponding input of the execution bbi line\n";
1064 content += "bbi applicationBBS.bbs ";
1065 content += inputsInOneLineUnix;
1076 //=========================================================================
1078 void wxGUIEditorGraphicBBS::refreshGUIControls()
1082 //RaC2012 2ndHackFest Next line seems weird ... To keep in mind for other devels
1083 wxToolBar* toolbar = GetToolBar();
1084 if (_tabsMgr->isActualDiagramComplexBox())
1086 toolbar->ToggleTool(ID_BTNCOMPLEXBOX, true);
1087 //toolbar->EnableTool(ID_ADDCOMPLEXBOXINPUT, true); RaC2012 2nd HackFest
1088 toolbar->EnableTool(ID_ADDCOMPLEXBOXOUTPUT, true);
1090 GetMenuBar()->GetMenu(0)->Enable(ID_SAVE_AS_COMPLEXBOX, true);
1091 GetMenuBar()->GetMenu(0)->Enable(ID_SAVE_AS_BBS, false);
1092 GetMenuBar()->GetMenu(0)->Enable(ID_EXPORT_CONSOLEAPP, false);
1094 toolbar->ToggleTool(ID_BTNCOMPLEXBOX, false);
1095 //toolbar->EnableTool(ID_ADDCOMPLEXBOXINPUT, false); RaC2012 2nd HackFest
1096 toolbar->EnableTool(ID_ADDCOMPLEXBOXOUTPUT, false);
1098 GetMenuBar()->GetMenu(0)->Enable(ID_SAVE_AS_COMPLEXBOX, false);
1099 GetMenuBar()->GetMenu(0)->Enable(ID_SAVE_AS_BBS, true);
1100 GetMenuBar()->GetMenu(0)->Enable(ID_EXPORT_CONSOLEAPP, true);
1103 //RaC2012 2ndHackFest
1104 GetToolBar()->EnableTool(ID_EDITPROPERTIES,true);
1106 GetToolBar()->EnableTool(ID_UNDO,_tabsMgr->getUndoState(stundo));
1107 GetToolBar()->SetToolShortHelp(ID_UNDO,crea::std2wx(stundo));
1108 GetToolBar()->EnableTool(ID_REDO,_tabsMgr->getRedoState(stredo));
1109 GetToolBar()->SetToolShortHelp(ID_REDO,crea::std2wx(stredo));
1111 if (_tabsMgr->getNumActualSelectedObjects() > 0) {
1112 GetMenuBar()->GetMenu(1)->Enable(ID_COPY_TO_COMPLEXDIAGRAM, true);
1114 ///TODO Fix the possibility to say from the SceneManager to the GUI to refresh the options
1115 GetMenuBar()->GetMenu(1)->Enable(ID_COPY_TO_COMPLEXDIAGRAM, true);
1120 //=========================================================================
1122 void wxGUIEditorGraphicBBS::OnDeleteAllBoxesActualDiagram(wxCommandEvent& event)
1124 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);
1125 if (dial->ShowModal() == wxID_YES)
1127 _tabsMgr->deleteAllBoxesActualDiagram();
1131 //=========================================================================
1133 void wxGUIEditorGraphicBBS::OnCenterViewActualDiagram(wxCommandEvent& event)
1135 _tabsMgr->centerViewActualDiagram();
1138 //=========================================================================
1139 void wxGUIEditorGraphicBBS::OpenDiagram(std::string filePathName, std::string fileName)
1141 ifstream inputStream;
1142 inputStream.open(filePathName.c_str());
1143 assert(inputStream.good()); // fails
1145 if(_tabsMgr->FindTab(filePathName)!=-1) //RaC2012 avoid opening same diagram twice
1147 inputStream.close();
1148 printf("RaC: Diagram already opened\n");
1151 _tabsMgr->addNewTab( crea::std2wx(fileName) );
1152 _tabsMgr->loadDiagram(inputStream, filePathName);
1154 _tabsMgr->saveTempActualDiagram("load diagram");
1155 GetToolBar()->EnableTool(ID_UNDO, false);
1156 GetToolBar()->EnableTool(ID_UNDO, false);
1157 inputStream.close();
1158 refreshGUIControls();
1161 //=========================================================================
1163 void wxGUIEditorGraphicBBS::OnOpenDiagram(wxCommandEvent& event)
1166 //EED 2017-09-16 Migration wxWidgets 2.8 to 3.0
1167 #if wxMAJOR_VERSION <= 2
1168 wxFileDialog * openFileDialog = new wxFileDialog(this, wxT("Open diagram"), wxEmptyString, wxT(""), wxT("*.bbg"), wxOPEN | wxFILE_MUST_EXIST);
1170 wxFileDialog * openFileDialog = new wxFileDialog(this, wxT("Open diagram"), wxEmptyString, wxT(""), wxT("*.bbg"), wxFD_OPEN | wxFD_FILE_MUST_EXIST);
1173 if (openFileDialog->ShowModal() == wxID_OK)
1175 wxString filePath = openFileDialog->GetPath();
1176 wxString fileName = openFileDialog->GetFilename();
1177 OpenDiagram( crea::wx2std(filePath) , crea::wx2std(fileName) );
1181 //=========================================================================
1182 void wxGUIEditorGraphicBBS::OnClickBtnBox(wxCommandEvent& event)
1184 std::cout<<"wxGUIEditorGraphicBBS::OnClickBtnBox"<<std::endl;
1185 BlackBoxDescriptor *bbDes = _pkgBrowser->GetActualSelected();
1186 if (bbDes != NULL) {
1187 std::string typeName = bbDes->GetTypeName();
1188 std::string packageName = bbDes->GetPackage()->GetName();
1189 wxGEditorTabPanel *pnl = this->_tabsMgr->getActualTabPanel();
1191 wxVtkSceneManager *scn = pnl->getSceneManager();
1192 scn->createGBlackBox(50, 50, packageName, typeName);
1195 SaveTempActualDiagram("New Box");
1200 //=========================================================================
1202 void wxGUIEditorGraphicBBS::OnClickBtnExecutableBox(wxCommandEvent& event)
1205 wxGEditorTabPanel *pnl = this->_tabsMgr->getActualTabPanel();
1208 wxVtkSceneManager *scn = pnl->getSceneManager();
1209 if( scn->MakeBoxExecutable() )
1210 std::cout<<"DFCH: wxGUIEditorGraphicBBS::OnClickBtnExecutableBox...successful"<<std::endl;
1212 std::cout<<"DFCH: wxGUIEditorGraphicBBS::OnClickBtnExecutableBox...Error!!"<<std::endl;
1218 //=========================================================================
1219 void wxGUIEditorGraphicBBS::OnClickBtnComplexBox(wxCommandEvent& event)
1221 std::cout<<"wxGUIEditorGraphicBBS::OnClickBtnComplexBox"<<std::endl;
1222 wxToolBar* toolbar = GetToolBar();
1223 bool temp = toolbar->GetToolState(ID_BTNCOMPLEXBOX);
1227 disableComplexBox();
1231 //=========================================================================
1233 void wxGUIEditorGraphicBBS::OnAddComplexBoxInput(wxCommandEvent& event)
1235 wxTextEntryDialog *nameDialog = new wxTextEntryDialog(this,
1236 wxT("Name of input port"));
1237 if (nameDialog->ShowModal() == wxID_OK)
1239 wxString fileName = nameDialog->GetValue();
1240 if (!fileName.IsEmpty())
1242 std::string portName = (const char*) (fileName.mb_str());
1243 if ( !boxNameExists(portName) )
1245 _tabsMgr->addActualDiagramComplexInputPort(portName);
1247 wxMessageDialog *dial = new wxMessageDialog(NULL,
1248 wxT("Impossible to create Box. The name already exists. Please provide another name"),
1249 wxT("Change name: name already exists"), wxOK | wxICON_EXCLAMATION | wxSTAY_ON_TOP);
1256 //=========================================================================
1257 void wxGUIEditorGraphicBBS::OnAddComplexBoxOutput(wxCommandEvent& event)
1259 wxTextEntryDialog *nameDialog = new wxTextEntryDialog(this,
1260 wxT("Name of output port"));
1261 if (nameDialog->ShowModal() == wxID_OK)
1263 wxString fileName = nameDialog->GetValue();
1264 if (!fileName.IsEmpty())
1266 std::string portName = (const char*) (fileName.mb_str());
1267 if ( !boxNameExists(portName) )
1269 _tabsMgr->addActualDiagramComplexOutputPort(portName);
1271 wxMessageDialog *dial = new wxMessageDialog(NULL,
1272 wxT("Impossible to create Box. The name already exists. Please provide another name"),
1273 wxT("Change name: name already exists"), wxOK | wxICON_EXCLAMATION | wxSTAY_ON_TOP);
1281 //=========================================================================
1282 void wxGUIEditorGraphicBBS::OnCopySelectedToComplexDiagram(
1283 wxCommandEvent& event)
1285 _tabsMgr->copySelectedBBoxesToComplexDiagram();
1288 //=========================================================================
1289 void wxGUIEditorGraphicBBS::OnHelpBBeditor(wxCommandEvent& event)
1291 printf("wxGUIEditorGraphicBBS::OnHelpBBeditor ....not implemented..\n");
1294 //=========================================================================
1295 void wxGUIEditorGraphicBBS::OnCreatePackage(wxCommandEvent& event)
1297 bbtkSystemTools::CreatePackage();
1300 //=========================================================================
1301 void wxGUIEditorGraphicBBS::OnCreateBlackBox(wxCommandEvent& event)
1303 bbtkSystemTools::CreateBlackBox();
1306 //=========================================================================
1307 void wxGUIEditorGraphicBBS::OnPlugPackage(wxCommandEvent& event)
1309 //DFGO2012 Plug Package functionnalities
1310 long style = wxDD_DEFAULT_STYLE | wxDD_DIR_MUST_EXIST;
1313 _T("Select package directory"),
1319 userResponse = FD->ShowModal();
1320 if(userResponse==wxID_OK)
1322 std::string path = wx2std (FD->GetPath()) ;
1324 std::string fname = path + "\\bbtkPackage";
1326 std::string fname = path + "/bbtkPackage";
1329 std::cout << "Path chosen = \"" << FD->GetPath() << "\"" << std::endl;
1330 if ( Utilities::FileExists( fname ) )
1333 f.open(fname.c_str());
1336 while(pname[0] == '#')
1338 getline(f, pname, '\n');
1343 bbtk::ConfigurationFile::GetInstance().AddPackagePathsAndWrite( path );
1345 DoRegeneratePackageDoc(pname);
1346 DoRegenerateBoxesLists();
1348 _pkgBrowser->RebuildList();
1350 wxMessageBox(_T("Package successfully plugged. Please restart bbEditor to see the new package in the package browser."),_T("Plug package"),wxOK | wxICON_INFORMATION);
1351 userResponse = wxID_CANCEL;
1355 std::string err = "The directory \"" + path + "\" does not contain a 'bbtkPackage' file.";
1358 err += "\nNote: If you are on Linux please select the folder and click \"Open\", don't enter in it.";
1362 wxMessageBox(crea::std2wx(err), _T("Plug package"),wxOK | wxICON_ERROR);
1363 // THE FOLLOWING LINE GIVES ERRORS BECAUSE IT IS NECESSARY TO USE std2wx
1364 //wxMessageBox( _T( err) , _T("Plug package"),wxOK | wxICON_ERROR);
1367 }while(userResponse != wxID_CANCEL);
1371 //=========================================================================
1372 void wxGUIEditorGraphicBBS::OnEditConfig(wxCommandEvent& event)
1374 std::string commandStr;
1375 std::string configFile = ConfigurationFile::GetInstance().Get_config_xml_full_path();
1377 commandStr = "notepad.exe ";
1379 commandStr = "gedit ";
1381 commandStr = commandStr + configFile;
1382 std::cout << "system: " << commandStr << std::endl;
1383 system ( commandStr.c_str() );
1386 //=========================================================================
1387 void wxGUIEditorGraphicBBS::OnShowHTMLDoc(wxCommandEvent& event)
1390 if (_helpHtmlBrowser != NULL){
1391 _frameAUIMgr->DetachPane(_helpHtmlBrowser);
1392 _helpHtmlBrowser->Destroy();
1394 initHelpHTMLBrowser();
1395 _frameAUIMgr->AddPane(_helpHtmlBrowser, wxAuiPaneInfo().Right().MinSize(200, 200));
1396 _frameAUIMgr->Update();
1397 refreshGUIControls();
1402 //=========================================================================
1403 void wxGUIEditorGraphicBBS::OnCreateIndex(wxCommandEvent& event)
1405 printf("EED wxGUIEditorGraphicBBS::OnCreateIndex ... not implemented ..\n");
1409 //=========================================================================
1410 void wxGUIEditorGraphicBBS::OnEditComplexBoxScript(wxCommandEvent& event)
1412 BlackBoxDescriptor *bbDes = _pkgBrowser->GetActualSelected();
1415 std::string packageName = bbDes->GetPackage()->GetName();
1416 std::string typeName = bbDes->GetTypeName();
1417 if (!TryToOpenScriptComplexBox(packageName ,typeName))
1419 wxMessageDialog windowMessage1(NULL,_T("This is not a ComplexBox script."), _T("Alert !"), wxOK);
1420 windowMessage1.ShowModal();
1425 //=========================================================================
1426 void wxGUIEditorGraphicBBS::OnExit(wxCommandEvent& event)
1431 Factory::Pointer wxGUIEditorGraphicBBS::GetBBTKFactory()
1433 if (_pkgBrowser==NULL)
1435 printf ("EED ERROR! wxGUIEditorGraphicBBS::GetBBTKFactory _pkgBrowser = NULL\n");
1437 return _pkgBrowser->GetFactory();
1440 //=========================================================================
1441 void wxGUIEditorGraphicBBS::enableComplexBox()
1443 _tabsMgr->setActualDiagramComplexBox(true);
1444 refreshGUIControls();
1447 //=========================================================================
1449 void wxGUIEditorGraphicBBS::disableComplexBox()
1451 _tabsMgr->setActualDiagramComplexBox(false);
1452 refreshGUIControls();
1455 //=========================================================================
1456 void wxGUIEditorGraphicBBS::setCurrentDiagramDescription(std::string description)
1458 _tabsMgr->SetDescription(description);
1461 //=========================================================================
1462 void wxGUIEditorGraphicBBS::setCurrentDiagramAuthor(std::string author)
1464 _tabsMgr->SetAuthor(author);
1467 //=========================================================================
1468 void wxGUIEditorGraphicBBS::setCurrentDiagramCategory(std::string category)
1470 _tabsMgr->SetCategory(category);
1473 //=========================================================================
1474 void wxGUIEditorGraphicBBS::setCurrentDiagramMessageKind(std::string kind){
1475 _tabsMgr->SetMessageKind(kind);
1478 //=========================================================================
1479 void wxGUIEditorGraphicBBS::setCurrentDiagramMessageLevel(std::string level){
1480 _tabsMgr->SetMessageLevel(level);
1483 //=========================================================================
1484 std::string wxGUIEditorGraphicBBS::getCurrentDiagramDescription()
1486 return _tabsMgr->GetDescription();
1489 //=========================================================================
1490 std::string wxGUIEditorGraphicBBS::getCurrentDiagramAuthor()
1492 return _tabsMgr->GetAuthor();
1495 //=========================================================================
1496 std::string wxGUIEditorGraphicBBS::getCurrentDiagramCategory()
1498 return _tabsMgr->GetCategory();
1501 //=========================================================================
1502 std::string wxGUIEditorGraphicBBS::getCurrentDiagramMessageKind(){
1503 return _tabsMgr->GetMessageKind();
1506 //=========================================================================
1507 std::string wxGUIEditorGraphicBBS::getCurrentDiagramMessageLevel(){
1508 return _tabsMgr->GetMessageLevel();
1511 //=========================================================================
1512 bool wxGUIEditorGraphicBBS::isCurrentDiagramComplexBox()
1514 return _tabsMgr->isActualDiagramComplexBox();
1518 //=========================================================================
1519 void wxGUIEditorGraphicBBS::OpenScript(std::string filePathNameBBS ,std::string boxType)
1521 std::string fileName = boxType+".bbg";
1522 std::string filePathNameBBG = filePathNameBBS;
1523 filePathNameBBG[ filePathNameBBG.length()-1 ] = 'g';
1525 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);
1526 windowMessage1.ShowModal();
1528 if ( Utilities::FileExists( filePathNameBBG ) )
1530 OpenDiagram( filePathNameBBG , fileName );
1532 if ( Utilities::FileExists( filePathNameBBS ) )
1534 OpenBBS( filePathNameBBS , fileName );
1536 wxMessageDialog windowMessage1(NULL,_T("..ERROR.. loading script bbg/bbs."), _T("Alert !"), wxOK);
1537 windowMessage1.ShowModal();
1544 //=========================================================================
1545 bool wxGUIEditorGraphicBBS::TryToOpenScriptApplication(std::string packageName ,std::string boxType)
1547 return TryToOpenScript(packageName ,boxType, true, false);
1550 //=========================================================================
1551 bool wxGUIEditorGraphicBBS::TryToOpenScriptComplexBox(std::string packageName ,std::string boxType)
1553 return TryToOpenScript(packageName ,boxType, false, true);
1557 //=========================================================================
1558 bool wxGUIEditorGraphicBBS::TryToOpenScript(std::string packageName ,std::string boxType,bool scriptApplication, bool scriptComplexBox)
1561 std::map< std::string, BlackBoxDescriptor::Pointer> mapDesc;
1562 BlackBoxDescriptor::Pointer descriptor;
1563 k = GetBBTKFactory()->GetPackage(packageName);
1564 mapDesc = k->GetDescriptorMap();
1565 descriptor = mapDesc[boxType];
1568 descriptor->IsTypeOfScript_Application();
1569 if (descriptor!=NULL)
1572 ((descriptor->IsTypeOfScript_Application()==true) && (scriptApplication==true))
1574 ((descriptor->IsTypeOfScript_ComplexBox()==true) && (scriptComplexBox==true))
1578 OpenScript(descriptor->GetScriptFileName(),boxType);
1579 } // if descriptor Type
1581 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() );
1582 } // if descriptor NULL
1587 } // EO namespace bbtk