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);
142 wxToolBar *toolbar = new wxToolBar(this, wxID_ANY);
144 //Adds a tool btn to the toolbar
145 toolbar->AddTool(ID_NEW, _T("New"), bmp_new, wxNullBitmap, wxITEM_NORMAL,
146 _T("New tab"), _T("Create a new panel tab"));
148 toolbar->AddTool(ID_OPEN, _T("Open diagram"), bmp_open, wxNullBitmap,
149 wxITEM_NORMAL, _T("Open a diagram"), _T("Open a diagram"));
151 toolbar->AddTool(ID_SAVE_DIAGRAM, _T("Save Diagram"), bmp_save,
152 wxNullBitmap, wxITEM_NORMAL, _T("Saves the current diagram"),
153 _T("Saves the current diagram")); //DFCH
154 //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
155 toolbar->AddTool(ID_RUN, _T("Run"), bmp_run, wxNullBitmap, wxITEM_NORMAL,
156 _T("Execute actual diagram"), _T("Execute actual diagram"));
157 toolbar->AddTool(ID_DELETEALL, _T("Delete all"), bmp_delete, wxNullBitmap,
158 wxITEM_NORMAL, _T("Delete all boxes"), _T("Delete all boxes"));
159 toolbar->AddTool(ID_CENTERVIEW, _T("Center view"), bmp_centerview,
160 wxNullBitmap, wxITEM_NORMAL, _T("Center view"), _T("Center view"));
161 toolbar->AddSeparator();
162 toolbar->AddTool(ID_BTNBOX, _T("New Box"), bmp_box, wxNullBitmap,
163 wxITEM_NORMAL, _T("New Box"), _T("Nex Box"));
164 toolbar->AddSeparator();
165 toolbar->AddTool(ID_BTEXECUTABLEBOX, _T("Select as executable Box"),
166 bmp_executablebox, wxNullBitmap, wxITEM_NORMAL,
167 _T("Select as executable Box"), _T("Select as executable Box"));
168 toolbar->AddSeparator();
169 toolbar->AddTool(ID_BTNCOMPLEXBOX, _T("Complex box"), complexbox_xpm,
170 wxNullBitmap, wxITEM_NORMAL, _T("Complex box"), _T("Complex box"));
172 //EED 2017-09-16 Migration wxWidgets 2.8 to 3.0
173 #if wxMAJOR_VERSION <= 2
174 toolbar->SetToggle(ID_BTNCOMPLEXBOX, true);
176 printf ("EED Warnning. wxGUIEditorGraphicBBS::initToolbar >>> toolbar->SetToggle \n ");
180 // RaC 2012 2nd HackFest - Now Complex inputs are any external input
181 // toolbar->AddTool(ID_ADDCOMPLEXBOXINPUT, _T("Add input to Complex box"),
182 // bmp_complexinputport, wxNullBitmap, wxITEM_NORMAL,
183 // _T("Add input to Complex box"), _T("Add input to Complex box"));
184 toolbar->AddTool(ID_ADDCOMPLEXBOXINPUT, _T("Add external input (Complex box or console app)"),
185 bmp_complexinputport, wxNullBitmap, wxITEM_NORMAL,
186 _T("Add external input (Complex box or console app)"), _T("Add external input (Complex box or console app)"));
188 toolbar->AddTool(ID_ADDCOMPLEXBOXOUTPUT, _T("Add output to Complex box"),
189 bmp_complexoutputport, wxNullBitmap, wxITEM_NORMAL,
190 _T("Add output Complex box"), _T("Add output Complex box"));
192 // toolbar->EnableTool(ID_ADDCOMPLEXBOXINPUT, false); RaC2012 2nd HackFest
193 toolbar->EnableTool(ID_ADDCOMPLEXBOXINPUT, true);
195 toolbar->EnableTool(ID_ADDCOMPLEXBOXOUTPUT, false);
196 toolbar->AddSeparator();
197 toolbar->AddTool(ID_UNDO, _T("Undo"),bmp_undo, wxNullBitmap, wxITEM_NORMAL, _T("Undo"), _T("Undo"));
198 toolbar->AddTool(ID_REDO, _T("Redo"),bmp_redo, wxNullBitmap, wxITEM_NORMAL, _T("Redo"), _T("Redo"));
199 toolbar->AddSeparator();
200 toolbar->AddTool(ID_EDITPROPERTIES, _T("Edit diagram properties"),bmp_editProperties, wxNullBitmap, wxITEM_NORMAL, _T("Edit diagram properties"), _T("Edit diagram properties"));
201 toolbar->EnableTool(ID_EDITPROPERTIES, false);
203 toolbar->AddTool(ID_SHOWTREE, _T("Show tree"),bmp_showTree, wxNullBitmap, wxITEM_NORMAL, _T("Show tree"), _T("Show tree"));
206 toolbar->EnableTool(ID_UNDO, false);
207 toolbar->EnableTool(ID_REDO, false);
208 toolbar->SetMargins(2, 2);
214 // connect command event handlers
216 Connect(ID_NEW, wxEVT_COMMAND_TOOL_CLICKED,
217 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnCreateNewTab));
218 Connect(ID_OPEN, wxEVT_COMMAND_TOOL_CLICKED,
219 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnOpenDiagram));
220 Connect(ID_SAVE_DIAGRAM, wxEVT_COMMAND_TOOL_CLICKED,
221 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnSaveActualDiagram)); //DFCH
222 Connect(ID_SAVE_AS_DIAGRAM, wxEVT_COMMAND_TOOL_CLICKED,
223 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnSaveAsActualDiagram)); //DFCH
226 wxEVT_COMMAND_TOOL_CLICKED,
227 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnExecuteActualDiagram));
230 wxEVT_COMMAND_TOOL_CLICKED,
231 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnDeleteAllBoxesActualDiagram));
234 wxEVT_COMMAND_TOOL_CLICKED,
235 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnCenterViewActualDiagram));
236 Connect(ID_BTNBOX, wxEVT_COMMAND_TOOL_CLICKED,
237 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnClickBtnBox));
240 wxEVT_COMMAND_TOOL_CLICKED,
241 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnClickBtnExecutableBox));
242 Connect(ID_BTNCOMPLEXBOX, wxEVT_COMMAND_TOOL_CLICKED,
243 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnClickBtnComplexBox));
244 Connect(ID_ADDCOMPLEXBOXINPUT, wxEVT_COMMAND_TOOL_CLICKED,
245 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnAddComplexBoxInput));
246 Connect(ID_ADDCOMPLEXBOXOUTPUT, wxEVT_COMMAND_TOOL_CLICKED,
247 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnAddComplexBoxOutput));
248 Connect(ID_UNDO,wxEVT_COMMAND_TOOL_CLICKED, wxCommandEventHandler(wxGUIEditorGraphicBBS::OnUndo));
249 Connect(ID_REDO,wxEVT_COMMAND_TOOL_CLICKED, wxCommandEventHandler(wxGUIEditorGraphicBBS::OnRedo));
250 Connect(ID_CHANGENAME, wxEVT_COMMAND_RIGHT_CLICK, wxCommandEventHandler(wxGUIEditorGraphicBBS::OnChangeName));
251 Connect(ID_EDITPROPERTIES,wxEVT_COMMAND_TOOL_CLICKED, wxCommandEventHandler(wxGUIEditorGraphicBBS::OnEditDiagramProperties));
252 Connect(ID_SHOWTREE,wxEVT_COMMAND_TOOL_CLICKED, wxCommandEventHandler(wxGUIEditorGraphicBBS::OnShowTree));
256 //=========================================================================
257 void wxGUIEditorGraphicBBS::initHelpHTMLBrowser() {
259 _helpHtmlBrowser = new WxGUIHtmlBrowser(this, wxSize(200, 0));
265 //=========================================================================
266 void wxGUIEditorGraphicBBS::initMenu() {
267 // Create File menu and its items
268 wxMenu *fileMenu = new wxMenu();
269 fileMenu->Append(ID_NEW, _T("New diagram"), _T("New"));
270 fileMenu->Append(ID_SAVE_DIAGRAM, _T("Save Diagram"), _T("Save Diagram")); //DFCH
271 fileMenu->Append(ID_SAVE_AS_DIAGRAM, _T("Save Diagram As"),
272 _T("Save Diagram As")); //DFCH
273 fileMenu->Append(ID_OPEN_BBS, _T("Open BBS"), _T("Open BBS"));
275 fileMenu->Append(ID_OPEN, _T("Open a diagram"), _T("Open a diagram"));
276 fileMenu->Append(ID_SAVE_AS_BBS, _T("Save BBS"), _T("Save BBS"));
277 fileMenu->Append(ID_SAVE_AS_COMPLEXBOX, _T("Save complex box"),
278 _T("Save complex box"));
279 fileMenu->Append(ID_EXPORT_CONSOLEAPP, _T("Export console commands"),
280 _T("Export console execution commands"));
281 fileMenu->Append(wxID_EXIT, _T("E&xit"), _T("Exit"));
283 Connect(ID_NEW, wxEVT_COMMAND_MENU_SELECTED,
284 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnCreateNewTab));
285 Connect(ID_SAVE_DIAGRAM, wxEVT_COMMAND_MENU_SELECTED,
286 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnSaveActualDiagram)); //DFCH
287 Connect(ID_SAVE_AS_DIAGRAM, wxEVT_COMMAND_MENU_SELECTED,
288 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnSaveAsActualDiagram));
289 Connect(ID_OPEN_BBS, wxEVT_COMMAND_MENU_SELECTED,
290 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnOpenBBS));
291 Connect(ID_SAVE_AS_BBS, wxEVT_COMMAND_MENU_SELECTED,
292 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnSaveActualBBS));
293 Connect( ID_SAVE_AS_COMPLEXBOX, wxEVT_COMMAND_MENU_SELECTED,
294 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnSaveActualComplexBox));
295 Connect( ID_EXPORT_CONSOLEAPP, wxEVT_COMMAND_MENU_SELECTED,
296 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnExportConsoleExecCommand));
297 Connect(wxID_EXIT, wxEVT_COMMAND_MENU_SELECTED,
298 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnExit));
300 // Create Edit menu and its items
301 wxMenu *editMenu = new wxMenu;
302 editMenu->Append(ID_COPY_TO_COMPLEXDIAGRAM, _T("Copy selected to complex box"), _T("Creates a new complex box diagram with selected boxes"));
303 editMenu->Append(ID_EDIT_COMPLEXBOX_SCRIPT, _T("Edit Complex Box"), _T("Edit Complex Box"));
304 Connect( ID_COPY_TO_COMPLEXDIAGRAM, wxEVT_COMMAND_MENU_SELECTED,
305 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnCopySelectedToComplexDiagram));
306 Connect( ID_EDIT_COMPLEXBOX_SCRIPT, wxEVT_COMMAND_MENU_SELECTED,
307 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnEditComplexBoxScript));
309 // Create Help menu and its items
310 wxMenu *helpMenu = new wxMenu;
311 helpMenu->Append(wxID_ABOUT, _T("&About..."), _T("About"));
312 helpMenu->Append(ID_HELP_BBEDITOR, _T("&Help..."), _T("Help"));
313 Connect(ID_HELP_BBEDITOR, wxEVT_COMMAND_MENU_SELECTED,
314 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnHelpBBeditor));
317 wxMenu *menuTools = new wxMenu;
318 menuTools->Append(ID_bbEditor_Tool_Menu_CreatePackage,
319 _T("Create &package") );
320 menuTools->Append(ID_bbEditor_Tool_Menu_CreateBlackBox,
321 _T("Create &blackbox") );
322 menuTools->Append(ID_bbEditor_Tool_Menu_PlugPackage, _T("Plug package") );
323 menuTools->Append(ID_bbEditor_Tool_Menu_EditConfig, _T("&Edit bbtk config") );
324 menuTools->Append(ID_bbEditor_Tool_Menu_ShowHTMLDoc,
325 _T("Show &HTML documentation") );
326 menuTools->Append(ID_bbEditor_Tool_Menu_CreateIndex, _T("&Generate index") );
328 Connect(ID_bbEditor_Tool_Menu_CreatePackage, wxEVT_COMMAND_MENU_SELECTED,
329 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnCreatePackage));
330 Connect(ID_bbEditor_Tool_Menu_CreateBlackBox, wxEVT_COMMAND_MENU_SELECTED,
331 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnCreateBlackBox));
332 Connect(ID_bbEditor_Tool_Menu_PlugPackage, wxEVT_COMMAND_MENU_SELECTED,
333 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnPlugPackage));
334 Connect(ID_bbEditor_Tool_Menu_EditConfig, wxEVT_COMMAND_MENU_SELECTED,
335 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnEditConfig));
336 Connect(ID_bbEditor_Tool_Menu_ShowHTMLDoc, wxEVT_COMMAND_MENU_SELECTED,
337 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnShowHTMLDoc));
338 Connect(ID_bbEditor_Tool_Menu_CreateIndex, wxEVT_COMMAND_MENU_SELECTED,
339 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnCreateIndex));
341 // Append the created menu to the menu bar
342 wxMenuBar *menuBar = new wxMenuBar();
343 menuBar->Append(fileMenu, _T("&File") );
344 menuBar->Append(editMenu, _T("&Edit") );
345 menuBar->Append(menuTools, _T("&Tool") );
346 menuBar->Append(helpMenu, _T("&Help") );
348 // Attach this menu bar to the frame
352 //=========================================================================
353 void wxGUIEditorGraphicBBS::initTabPanelsManager()
355 _notebook = new wxAuiNotebook(this, wxID_NOTEBOOK, wxDefaultPosition,
356 wxDefaultSize, wxAUI_NB_TOP | wxAUI_NB_TAB_MOVE
357 | wxAUI_NB_CLOSE_ON_ACTIVE_TAB | wxAUI_NB_TAB_FIXED_WIDTH
358 | wxAUI_NB_WINDOWLIST_BUTTON);
359 _tabsMgr = new wxTabPanelsManager(this);
360 _frameAUIMgr->AddPane(_notebook, wxAuiPaneInfo().CenterPane());
363 //=========================================================================
364 void wxGUIEditorGraphicBBS::initPackageBrowser()
366 _pkgBrowser = new WxGUIPackageBrowser2(this);
367 _pkgBrowser->IncludeAll();
368 _frameAUIMgr->AddPane(_pkgBrowser, wxAuiPaneInfo().Left().MinSize(30, 500).BestSize(750,500).CloseButton(false));
371 //================================================================
373 void wxGUIEditorGraphicBBS::DoRegeneratePackageDoc(const std::string& pack)
375 std::string mess("Regenerating doc for package '");
379 mess = "Regenerating doc for all packages";
382 mess += " ... please wait";
384 SetStatusText(std2wx(mess));
392 command += ConfigurationFile::GetInstance().Get_bin_path();
393 command += ConfigurationFile::GetInstance().Get_file_separator();
394 command += "bbRegeneratePackageDoc";
399 command += " " + pack + " -q";
400 bbtkMessage("debug",1,"Executing system command '"<<command<<"'"<<std::endl);
402 if (!system(command.c_str())) {
403 SetStatusText(_T("Done !"));
405 wxMessageBox(_T("Done !"),_T("Regenerate package '")
406 +std2wx(pack)+_T("' doc"),
407 wxOK | wxICON_INFORMATION);
410 SetStatusText(_T("Done !"));
411 wxString err(_T("An error occured while running '"));
412 err += bbtk::std2wx(command) + _T("'");
413 wxMessageBox(err, _T("Regenerate package doc"), wxOK | wxICON_ERROR);
417 //================================================================
418 void wxGUIEditorGraphicBBS::DoRegenerateBoxesLists() {
419 SetStatusText(_T("Regenerating boxes lists ... please wait"));
426 command += ConfigurationFile::GetInstance().Get_bin_path();
427 command += ConfigurationFile::GetInstance().Get_file_separator();
428 command += "bbRegenerateBoxesLists";
435 bbtkMessage("debug",1,"Executing system command '"<<command<<"'"<<std::endl);
437 if (!system(command.c_str())) {
438 SetStatusText(_T("Done !"));
440 wxMessageBox(_T("Done !"),_T("Regenerate boxes lists"),
441 wxOK | wxICON_INFORMATION);
444 SetStatusText(_T("Done !"));
445 wxString err(_T("An error occured while running '"));
446 err += bbtk::std2wx(command) + _T("'");
447 wxMessageBox(err, _T("Regenerate boxes lists"), wxOK | wxICON_ERROR);
451 //================================================================
452 void wxGUIEditorGraphicBBS::RegenerateAll() {
453 DoRegeneratePackageDoc("-a");
454 DoRegenerateBoxesLists();
457 //================================================================
459 wxAuiNotebook* wxGUIEditorGraphicBBS::getAuiNotebook() {
463 //================================================================
465 void wxGUIEditorGraphicBBS::displayBlackBoxInfo(std::string packageName, std::string boxName)
467 if (_actualPkgBrowserPkgName != packageName || _actualPkgBrowserBoxName != boxName)
470 _actualPkgBrowserPkgName = packageName;
471 _actualPkgBrowserBoxName = boxName;
473 //EED 15 oct 2012 BlackBoxDescriptor::Pointer descriptor = GObjectsMVCFactory::getInstance()->getBlackBoxDescriptor(packageName, boxName);
476 //EED ComplexBlackBoxDescriptor::Pointer descriptor;
477 BlackBoxDescriptor::Pointer descriptor;
479 std::map< std::string, BlackBoxDescriptor::Pointer> mapDesc;
480 k = _pkgBrowser->GetFactory()->GetPackage(_actualPkgBrowserPkgName);
481 mapDesc = k->GetDescriptorMap();
482 descriptor = mapDesc[_actualPkgBrowserBoxName];
488 descriptor->GetBoxesInside(tree, 0);
491 //std::vector<std::string> boxesDiagram = _sceneM->boxesDiagram;
492 //for(int i=0;i<boxesDiagram.size();i++){
493 // std::cout<<"caja: "<<boxesDiagram[i]<<std::endl;
496 _actualPkgBrowserPkgName = "";
497 _actualPkgBrowserBoxName = "";
501 BlackBoxDescriptor::Pointer descriptor;
502 std::map< std::string, BlackBoxDescriptor::Pointer> mapDesc;
503 k = _pkgBrowser->GetFactory()->GetPackage(packageName);
504 std::vector<std::string> temp;
505 _pkgBrowser->GetFactory()->GetPackagesList(temp);
506 for(int ii = 0 ; ii < temp.size() ; ii++)
508 std::cout << " packs "<< temp[ii]<< std::endl;
510 mapDesc = k->GetDescriptorMap();
511 descriptor = mapDesc[boxName];
513 _pkgBrowser->WxGUIBlackBoxListUserOnSelected(descriptor.get());
517 //=========================================================================
519 void wxGUIEditorGraphicBBS::editBlackBox(GBlackBoxModel *bbmodel) {
520 wxBlackBoxEditionDialog* dialog =
521 new wxBlackBoxEditionDialog(this, bbmodel);
525 //=========================================================================
527 bool wxGUIEditorGraphicBBS::boxNameExists(std::string boxname) {
529 return this->_tabsMgr->getActualTabPanel()->getSceneManager()->boxExist(boxname);
532 //=========================================================================
534 void wxGUIEditorGraphicBBS::updateStatusBar(std::string textStatus) {
535 SetStatusText(crea::std2wx(textStatus));
538 //=========================================================================
540 void wxGUIEditorGraphicBBS::executeScript(std::string script) {
541 std::string separator =
542 ConfigurationFile::GetInstance().Get_file_separator();
543 std::string dir = ConfigurationFile::GetInstance().Get_default_temp_dir();
544 std::string filename = dir + separator + "tmp_bbtk.bbs";
547 tempFile.open(filename.c_str());
551 std::string command = "";
554 command += "start /b ";
557 // command += "\""+ crea::System::GetExecutablePath();
559 // command += separator + "../../../bbi.app/Contents/MacOS";
563 command += "\"" + filename + "\"";
569 printf("RaC wxGUIEditorGraphicBBS::executeScript %s \n", command.c_str());
570 system(command.c_str());
573 //=========================================================================
574 std::string wxGUIEditorGraphicBBS::CheckExtension(std::string filename, std::string extension) {
575 if(filename.size() > extension.size() ){
576 if( (filename.compare(filename.size()-extension.size(), extension.size(),extension)) !=0 ){
577 filename.append(extension);
580 filename.append(extension);
584 //=========================================================================
586 //=========================================================================
588 void wxGUIEditorGraphicBBS::OnCreateNewTab(wxCommandEvent& event) {
589 _tabsMgr->addNewTab();
590 refreshGUIControls();
593 void wxGUIEditorGraphicBBS::OnUndo(wxCommandEvent& event) {
594 unsigned short disable;
598 _tabsMgr->loadTempDiagram(0);
599 disable = _tabsMgr->getUndoState(stundo);
602 std::string name = _tabsMgr->GetNameTabPanel();
603 if(name[name.length() - 1] == '*')
605 name =name.substr(0,name.length()-1);
607 _tabsMgr->SetNameTabPanel(wxString (name.c_str(), wxConvUTF8));
610 GetToolBar()->EnableTool(ID_UNDO,disable);
611 GetToolBar()->SetToolShortHelp(ID_UNDO,crea::std2wx(stundo));
612 GetToolBar()->EnableTool(ID_REDO,_tabsMgr->getRedoState(stredo));
613 GetToolBar()->SetToolShortHelp(ID_REDO,crea::std2wx(stredo));
614 refreshGUIControls();
617 //=========================================================================
619 void wxGUIEditorGraphicBBS::OnRedo(wxCommandEvent& event) {
620 unsigned short disable;
624 _tabsMgr->loadTempDiagram(1);
625 std::string name = _tabsMgr->GetNameTabPanel();
626 if(name[name.length() - 1] != '*')
628 _tabsMgr->SetNameTabPanel(wxString (name.c_str(), wxConvUTF8));
629 GetToolBar()->EnableTool(ID_UNDO,_tabsMgr->getUndoState(stundo));
630 GetToolBar()->SetToolShortHelp(ID_UNDO,crea::std2wx(stundo));
631 GetToolBar()->EnableTool(ID_REDO,_tabsMgr->getRedoState(stredo));
632 GetToolBar()->SetToolShortHelp(ID_REDO,crea::std2wx(stredo));
633 refreshGUIControls();
636 void wxGUIEditorGraphicBBS::OnChangeName(wxCommandEvent& event){
638 //=========================================================================
640 void wxGUIEditorGraphicBBS::OnShowTree(wxCommandEvent& event){
641 std::cout << "wxGUIEditorGraphicBBS::OnShowTree"<<std::endl;
642 if (_actualPkgBrowserPkgName !="" || _actualPkgBrowserBoxName != "")
645 //EED ComplexBlackBoxDescriptor::Pointer descriptor;
646 BlackBoxDescriptor::Pointer descriptor;
648 std::map< std::string, BlackBoxDescriptor::Pointer> mapDesc;
649 k = _pkgBrowser->GetFactory()->GetPackage(_actualPkgBrowserPkgName);
650 mapDesc = k->GetDescriptorMap();
651 descriptor = mapDesc[_actualPkgBrowserBoxName];
657 descriptor->GetBoxesInside(tree, 0);
659 _actualPkgBrowserPkgName = "";
660 _actualPkgBrowserBoxName = "";
664 std::cout<<"Select a Box"<<std::endl;
668 //=========================================================================
670 void wxGUIEditorGraphicBBS::OnEditDiagramProperties(wxCommandEvent& event)
672 wxDiagramPropertiesEditionDialog* dialog =
673 new wxDiagramPropertiesEditionDialog(this, tree);
677 //=========================================================================
679 void wxGUIEditorGraphicBBS::OnExecuteActualDiagram(wxCommandEvent& event) {
680 std::string script1 = _tabsMgr->getActualDiagramBBS(true);
681 cout << endl << "RaC wxGUIEditorGraphicBBS::executeActualDiagram SCRIPT"
683 cout << script1 << endl;
685 std::string script2 = _tabsMgr->getActualDiagramBBS(false);
686 executeScript(script2);
690 //=========================================================================
691 void wxGUIEditorGraphicBBS::OpenBBS(std::string filePathName, std::string fileName)
693 _tabsMgr->addNewTab( crea::std2wx(fileName) );
694 bbtk::InterpreterBBS::Pointer I = bbtk::InterpreterBBS::New( this->_tabsMgr->getActualTabPanel()->getSceneManager(), _pkgBrowser->GetFactory());
695 // We tell the interpreter to throw exceptions on error
697 // Interpret the file supposed to define a box called 'Processing'
698 I->InterpretFile( filePathName );
699 refreshGUIControls();
702 //=========================================================================
704 //=========================================================================
705 void wxGUIEditorGraphicBBS::OnOpenBBS(wxCommandEvent& event)
707 //EED 2017-09-16 Migration wxWidgets 2.8 to 3.0
708 #if wxMAJOR_VERSION <= 2
709 wxFileDialog * openFileDialog = new wxFileDialog(this, wxT("Open BBS"), wxEmptyString, wxT("NewBBS"), wxT("*.bbs"), wxOPEN);
711 wxFileDialog * openFileDialog = new wxFileDialog(this, wxT("Open BBS"), wxEmptyString, wxT("NewBBS"), wxT("*.bbs"), wxFD_OPEN);
714 if (openFileDialog->ShowModal() == wxID_OK)
716 OpenBBS( crea::wx2std(openFileDialog->GetPath()) , crea::wx2std(openFileDialog->GetFilename()) );
720 if (openFileDialog->ShowModal() == wxID_OK)
722 wxString fileName = openFileDialog->GetPath();
723 _tabsMgr->addNewTab(openFileDialog->GetFilename());
724 bbtk::InterpreterBBS::Pointer I = bbtk::InterpreterBBS::New( this->_tabsMgr->getActualTabPanel()->getSceneManager(), _pkgBrowser->GetFactory());
725 // We tell the interpreter to throw exceptions on error
727 // Interpret the file supposed to define a box called 'Processing'
728 I->InterpretFile((const char*) (fileName.mb_str()));
730 refreshGUIControls();
734 //=========================================================================
735 void wxGUIEditorGraphicBBS::SaveActualBBS(std::string filename) {
738 //EED file.open(fileName.c_str());
739 file.open(filename.c_str());
740 std::string content = "";
741 // writing file header
742 content += "# ----------------------------------\n";
743 content += "# - BBTKGEditor v ";
744 content += _currentBBGversion; //VERSION
745 content += " BBS BlackBox Script\n";
749 content += "# ----------------------------------\n";
751 content += _tabsMgr->getActualDiagramBBS();
756 void wxGUIEditorGraphicBBS::OnSaveActualBBS(wxCommandEvent& event) {
758 //EED 2017-09-16 Migration wxWidgets 2.8 to 3.0
759 #if wxMAJOR_VERSION <= 2
760 wxFileDialog * saveFileDialog = new wxFileDialog(this,
761 wxT("Save actual BBS"), wxEmptyString, wxT("NewBBS"),
762 wxT("*.bbs"), wxSAVE | wxOVERWRITE_PROMPT);
764 wxFileDialog * saveFileDialog = new wxFileDialog(this,
765 wxT("Save actual BBS"), wxEmptyString, wxT("NewBBS"),
766 wxT("*.bbs"), wxFD_SAVE | wxFD_OVERWRITE_PROMPT);
769 if (saveFileDialog->ShowModal() == wxID_OK) {
770 wxString fileName = saveFileDialog->GetPath();
771 std::string filename = (const char*) (fileName.mb_str());
772 filename=CheckExtension (filename, ".bbs");
773 SaveActualBBS(filename);
778 void wxGUIEditorGraphicBBS::AskComplexBoxConfiguration() {
779 std::string cbName = _tabsMgr->GetCbName();
780 std::string paName = _tabsMgr->GetCbPackageName();
782 wxTextEntryDialog *cbNameDialog = new wxTextEntryDialog(this,
783 wxT("Complex Box name"));
784 wxTextEntryDialog *paNameDialog = new wxTextEntryDialog(this,
785 wxT("Package name"));
787 cbNameDialog->SetValue(wxString(cbName.c_str(), wxConvUTF8));
788 paNameDialog->SetValue(wxString(paName.c_str(), wxConvUTF8));
790 if (cbNameDialog->ShowModal() == wxID_OK) {
791 wxString complexboxname = cbNameDialog->GetValue();
792 cbName = (const char*) (complexboxname.mb_str());
795 if (paNameDialog->ShowModal() == wxID_OK) {
796 wxString packagename = paNameDialog->GetValue();
797 paName = (const char*) (packagename.mb_str());
800 _tabsMgr->SetCbName(cbName);
801 _tabsMgr->SetCbPackageName(paName);
804 //=========================================================================
806 void wxGUIEditorGraphicBBS::SaveActualComplexBox(std::string filename) {
808 file.open(filename.c_str());
810 std::string content = "";
812 // writing file header
813 content += "# ----------------------------------\n";
814 content += "# - BBTKGEditor v ";
815 content += _currentBBGversion;//VERSION
816 content += " BBS BlackBox Script (Complex Box)\n";
820 content += "# ----------------------------------\n";
822 content += _tabsMgr->getActualComplexBoxBBS();
827 //=========================================================================
829 void wxGUIEditorGraphicBBS::OnSaveActualComplexBox(wxCommandEvent& event)
831 //EED 2017-09-16 Migration wxWidgets 2.8 to 3.0
832 #if wxMAJOR_VERSION <= 2
833 wxFileDialog * saveFileDialog = new wxFileDialog(this,
834 wxT("Save Complex Box BBS"), wxEmptyString,
835 _T("ComplexBoxName"), wxT("*.bbs"), wxSAVE
836 | wxOVERWRITE_PROMPT);
838 wxFileDialog * saveFileDialog = new wxFileDialog(this,
839 wxT("Save Complex Box BBS"), wxEmptyString,
840 _T("ComplexBoxName"), wxT("*.bbs"), wxFD_SAVE
841 | wxFD_OVERWRITE_PROMPT);
844 if (saveFileDialog->ShowModal() == wxID_OK) {
845 wxString fileName = saveFileDialog->GetPath();
846 std::string filename = (const char*) (fileName.mb_str());
847 filename=CheckExtension (filename, ".bbs");
848 SaveActualComplexBox(filename);
852 //=========================================================================
853 void wxGUIEditorGraphicBBS::SaveActualDiagram(std::string filename) {
855 file.open(filename.c_str());
857 std::string content = "";
859 // writing file header
860 content += "# ----------------------------------\n";
861 content += "# - BBTKGEditor v ";
862 content += _currentBBGversion; //VERSION
863 content += " BBG BlackBox Diagram file\n";
869 content += "# ----------------------------------\n";
871 content += "APP_START\n";
872 _tabsMgr->saveActualDiagram(content, filename); //DFCH
873 content += "APP_END\n";
878 //=========================================================================
879 void wxGUIEditorGraphicBBS::SaveTempActualDiagram(const std::string &action)
883 std::string name = _tabsMgr->GetNameTabPanel();
884 if(name[name.length() - 1] != '*')
886 _tabsMgr->SetNameTabPanel(wxString (name.c_str(), wxConvUTF8));
887 _tabsMgr->saveTempActualDiagram(action);
888 GetToolBar()->EnableTool(ID_UNDO,_tabsMgr->getUndoState(stundo));
889 GetToolBar()->SetToolShortHelp(ID_UNDO,crea::std2wx(stundo));
890 GetToolBar()->EnableTool(ID_REDO,_tabsMgr->getRedoState(stredo));
891 GetToolBar()->SetToolShortHelp(ID_REDO,crea::std2wx(stredo));
894 //=========================================================================
896 //The following method allows to save the current diagram asking the filename
898 void wxGUIEditorGraphicBBS::SaveCurrentDiagramAs()
901 //EED 2017-09-16 Migration wxWidgets 2.8 to 3.0
902 #if wxMAJOR_VERSION <= 2
903 wxFileDialog * saveFileDialog = new wxFileDialog(this,
904 wxT("Save current diagram"), wxEmptyString, wxT("NewDiagram"),
905 wxT("*.bbg"), wxSAVE | wxOVERWRITE_PROMPT);
907 wxFileDialog * saveFileDialog = new wxFileDialog(this,
908 wxT("Save current diagram"), wxEmptyString, wxT("NewDiagram"),
909 wxT("*.bbg"), wxFD_SAVE | wxFD_OVERWRITE_PROMPT);
912 if (saveFileDialog->ShowModal() == wxID_OK) {
913 //_tabsMgr->SetNameTabPanel(saveFileDialog->GetFilename());
914 wxString pathfileName = saveFileDialog->GetPath();
915 std::string pathfilename = (const char*) (pathfileName.mb_str());
916 pathfilename=CheckExtension (pathfilename, ".bbg");
918 //modify the tab name accordingly
919 wxString fileName = saveFileDialog->GetFilename();
920 std::string filename = (const char*) (fileName.mb_str());
921 filename=CheckExtension (filename, ".bbg");
922 _tabsMgr->SetNameTabPanel( wxString (filename.c_str(), wxConvUTF8) );
924 std::string pathfilenamebbs = pathfilename;
925 pathfilenamebbs[pathfilenamebbs.length() - 1] = 's';
926 if (_tabsMgr->isActualDiagramComplexBox() == false) {
927 SaveActualDiagram(pathfilename);
928 SaveActualBBS(pathfilenamebbs);
930 AskComplexBoxConfiguration();
931 SaveActualDiagram(pathfilename);
932 SaveActualComplexBox(pathfilenamebbs);
933 } //if isActualDiagramComplexBox
934 } // if saveFileDialog
936 //=========================================================================
938 void wxGUIEditorGraphicBBS::OnSaveActualDiagram(wxCommandEvent& event) {
939 std::string pathfilename = _tabsMgr->GetCurrentTabPanelPath();
940 if (pathfilename.empty()) {
941 SaveCurrentDiagramAs();
943 std::string pathfilenamebbs = pathfilename;
944 pathfilenamebbs[pathfilenamebbs.length() - 1] = 's';
946 if (_tabsMgr->isActualDiagramComplexBox() == false) {
947 std::string name = _tabsMgr->GetNameTabPanel();
948 if(name[name.length() - 1] == '*')
950 name =name.substr(0,name.length()-1);
952 _tabsMgr->SetNameTabPanel(wxString (name.c_str(), wxConvUTF8));
953 SaveActualDiagram(pathfilename);
954 SaveActualBBS(pathfilenamebbs);
956 AskComplexBoxConfiguration();
957 SaveActualDiagram(pathfilename);
958 SaveActualComplexBox(pathfilenamebbs);
959 } //if isActualDiagramComplexBox
962 //=========================================================================
964 void wxGUIEditorGraphicBBS::OnSaveAsActualDiagram(wxCommandEvent& event) {
965 SaveCurrentDiagramAs();
968 //=========================================================================
969 void wxGUIEditorGraphicBBS::OnExportConsoleExecCommand(wxCommandEvent& event)
971 //EED 2017-09-16 Migration wxWidgets 2.8 to 3.0
972 #if wxMAJOR_VERSION <= 2
973 wxFileDialog * saveFileDialog = new wxFileDialog(this,
974 wxT("Export console command"), wxEmptyString, wxT("ConsoleApp.txt"),
975 wxT("*.txt;*.bbs;*.bbg;*.sh;*.bat"), wxSAVE | wxOVERWRITE_PROMPT);
977 wxFileDialog * saveFileDialog = new wxFileDialog(this,
978 wxT("Export console command"), wxEmptyString, wxT("ConsoleApp.txt"),
979 wxT("*.txt;*.bbs;*.bbg;*.sh;*.bat"), wxFD_SAVE | wxFD_OVERWRITE_PROMPT);
983 if (saveFileDialog->ShowModal() == wxID_OK)
985 wxString fileName = saveFileDialog->GetPath();
986 std::string filename = (const char*) (fileName.mb_str());
987 filename=CheckExtension (filename, ".txt");
990 file.open(filename.c_str());
992 std::vector<std::string> extInputs = _tabsMgr->getActualTabPanel()->getSceneManager()->GetExternalInputsNames();
994 //TODO PUT IN A METHOD OF A FILES AND TEXT MANAGER CLASS !!!
995 //std::string inputsInCommentsWin="";
996 //std::string inputsInCommentsUnix="";
997 //std::string inputsInOneLineWin="";
998 std::string inputsInOneLineUnix="";
999 for (unsigned int i = 0; i < extInputs.size(); ++i)
1001 /* No gusto la idea al jefe pero por si acaso ...
1002 * RaC 2012 2nd HackFest
1004 inputsInCommentsWin+="REM ";
1005 inputsInCommentsWin+=extInputs[i];
1006 inputsInCommentsWin+="=\"value\"\n";
1007 inputsInCommentsUnix+="# ";
1008 inputsInCommentsUnix+=extInputs[i];
1009 inputsInCommentsUnix+="=\"value\"\n";
1012 sprintf (buffer, "%d", (i+1));
1013 inputsInOneLineWin+=extInputs[i];
1014 inputsInOneLineWin+="=\"%";
1015 inputsInOneLineWin+=buffer;
1016 inputsInOneLineWin+="\" ";
1018 inputsInOneLineUnix+=extInputs[i];
1019 inputsInOneLineUnix+="=\"<value>\" ";
1024 std::string content = "";
1025 // writing file header
1026 content += "# ----------------------------------\n";
1027 content += "# - BBTKGEditor v ";
1028 content += _currentBBGversion; //VERSION
1029 content += " Console Commands to execute BBS application\n";
1031 content += filename;
1033 content += "# ----------------------------------\n";
1036 content += "# Command to execute bbi\n";
1037 content += "bbi <bbs_path> ";
1038 content += inputsInOneLineUnix;
1040 /* No gusto la idea al jefe pero por si acaso ...
1041 * RaC 2012 2nd HackFest
1042 content += "# For Windows (copy the following lines to a .bat file)\n";
1043 content += "REM BBS application\n";
1044 content += "REM Inputs:\n";
1045 content += inputsInCommentsWin;
1046 content += "REM To use previous inputs, put %$inputName% in the corresponding input of the execution bbi line\n";
1047 content += "bbi applicationBBS.bbs ";
1048 content += inputsInOneLineWin;
1051 content += "# For Linux or Mac (copy the following lines to a .sh file)\n";
1052 content += "#!/bin/bash\n";
1053 content += "# BBS application\n";
1054 content += "# Inputs:\n";
1055 content += inputsInCommentsUnix;
1056 content += "# To use previous inputs, put $inputName in the corresponding input of the execution bbi line\n";
1057 content += "bbi applicationBBS.bbs ";
1058 content += inputsInOneLineUnix;
1069 //=========================================================================
1071 void wxGUIEditorGraphicBBS::refreshGUIControls()
1075 //RaC2012 2ndHackFest Next line seems weird ... To keep in mind for other devels
1076 wxToolBar* toolbar = GetToolBar();
1077 if (_tabsMgr->isActualDiagramComplexBox())
1079 toolbar->ToggleTool(ID_BTNCOMPLEXBOX, true);
1080 //toolbar->EnableTool(ID_ADDCOMPLEXBOXINPUT, true); RaC2012 2nd HackFest
1081 toolbar->EnableTool(ID_ADDCOMPLEXBOXOUTPUT, true);
1083 GetMenuBar()->GetMenu(0)->Enable(ID_SAVE_AS_COMPLEXBOX, true);
1084 GetMenuBar()->GetMenu(0)->Enable(ID_SAVE_AS_BBS, false);
1085 GetMenuBar()->GetMenu(0)->Enable(ID_EXPORT_CONSOLEAPP, false);
1087 toolbar->ToggleTool(ID_BTNCOMPLEXBOX, false);
1088 //toolbar->EnableTool(ID_ADDCOMPLEXBOXINPUT, false); RaC2012 2nd HackFest
1089 toolbar->EnableTool(ID_ADDCOMPLEXBOXOUTPUT, false);
1091 GetMenuBar()->GetMenu(0)->Enable(ID_SAVE_AS_COMPLEXBOX, false);
1092 GetMenuBar()->GetMenu(0)->Enable(ID_SAVE_AS_BBS, true);
1093 GetMenuBar()->GetMenu(0)->Enable(ID_EXPORT_CONSOLEAPP, true);
1096 //RaC2012 2ndHackFest
1097 GetToolBar()->EnableTool(ID_EDITPROPERTIES,true);
1099 GetToolBar()->EnableTool(ID_UNDO,_tabsMgr->getUndoState(stundo));
1100 GetToolBar()->SetToolShortHelp(ID_UNDO,crea::std2wx(stundo));
1101 GetToolBar()->EnableTool(ID_REDO,_tabsMgr->getRedoState(stredo));
1102 GetToolBar()->SetToolShortHelp(ID_REDO,crea::std2wx(stredo));
1104 if (_tabsMgr->getNumActualSelectedObjects() > 0) {
1105 GetMenuBar()->GetMenu(1)->Enable(ID_COPY_TO_COMPLEXDIAGRAM, true);
1107 ///TODO Fix the possibility to say from the SceneManager to the GUI to refresh the options
1108 GetMenuBar()->GetMenu(1)->Enable(ID_COPY_TO_COMPLEXDIAGRAM, true);
1113 //=========================================================================
1115 void wxGUIEditorGraphicBBS::OnDeleteAllBoxesActualDiagram(wxCommandEvent& event)
1117 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);
1118 if (dial->ShowModal() == wxID_YES)
1120 _tabsMgr->deleteAllBoxesActualDiagram();
1124 //=========================================================================
1126 void wxGUIEditorGraphicBBS::OnCenterViewActualDiagram(wxCommandEvent& event)
1128 _tabsMgr->centerViewActualDiagram();
1131 //=========================================================================
1132 void wxGUIEditorGraphicBBS::OpenDiagram(std::string filePathName, std::string fileName)
1134 ifstream inputStream;
1135 inputStream.open(filePathName.c_str());
1136 assert(inputStream.good()); // fails
1138 if(_tabsMgr->FindTab(filePathName)!=-1) //RaC2012 avoid opening same diagram twice
1140 inputStream.close();
1141 printf("RaC: Diagram already opened\n");
1144 _tabsMgr->addNewTab( crea::std2wx(fileName) );
1145 _tabsMgr->loadDiagram(inputStream, filePathName);
1147 _tabsMgr->saveTempActualDiagram("load diagram");
1148 GetToolBar()->EnableTool(ID_UNDO, false);
1149 GetToolBar()->EnableTool(ID_UNDO, false);
1150 inputStream.close();
1151 refreshGUIControls();
1154 //=========================================================================
1156 void wxGUIEditorGraphicBBS::OnOpenDiagram(wxCommandEvent& event)
1159 //EED 2017-09-16 Migration wxWidgets 2.8 to 3.0
1160 #if wxMAJOR_VERSION <= 2
1161 wxFileDialog * openFileDialog = new wxFileDialog(this, wxT("Open diagram"), wxEmptyString, wxT(""), wxT("*.bbg"), wxOPEN | wxFILE_MUST_EXIST);
1163 wxFileDialog * openFileDialog = new wxFileDialog(this, wxT("Open diagram"), wxEmptyString, wxT(""), wxT("*.bbg"), wxFD_OPEN | wxFD_FILE_MUST_EXIST);
1166 if (openFileDialog->ShowModal() == wxID_OK)
1168 wxString filePath = openFileDialog->GetPath();
1169 wxString fileName = openFileDialog->GetFilename();
1170 OpenDiagram( crea::wx2std(filePath) , crea::wx2std(fileName) );
1174 //=========================================================================
1175 void wxGUIEditorGraphicBBS::OnClickBtnBox(wxCommandEvent& event)
1177 std::cout<<"wxGUIEditorGraphicBBS::OnClickBtnBox"<<std::endl;
1178 BlackBoxDescriptor *bbDes = _pkgBrowser->GetActualSelected();
1179 if (bbDes != NULL) {
1180 std::string typeName = bbDes->GetTypeName();
1181 std::string packageName = bbDes->GetPackage()->GetName();
1182 wxGEditorTabPanel *pnl = this->_tabsMgr->getActualTabPanel();
1184 wxVtkSceneManager *scn = pnl->getSceneManager();
1185 scn->createGBlackBox(50, 50, packageName, typeName);
1188 SaveTempActualDiagram("New Box");
1193 //=========================================================================
1195 void wxGUIEditorGraphicBBS::OnClickBtnExecutableBox(wxCommandEvent& event)
1198 wxGEditorTabPanel *pnl = this->_tabsMgr->getActualTabPanel();
1201 wxVtkSceneManager *scn = pnl->getSceneManager();
1202 if( scn->MakeBoxExecutable() )
1203 std::cout<<"DFCH: wxGUIEditorGraphicBBS::OnClickBtnExecutableBox...successful"<<std::endl;
1205 std::cout<<"DFCH: wxGUIEditorGraphicBBS::OnClickBtnExecutableBox...Error!!"<<std::endl;
1211 //=========================================================================
1212 void wxGUIEditorGraphicBBS::OnClickBtnComplexBox(wxCommandEvent& event)
1214 std::cout<<"wxGUIEditorGraphicBBS::OnClickBtnComplexBox"<<std::endl;
1215 wxToolBar* toolbar = GetToolBar();
1216 bool temp = toolbar->GetToolState(ID_BTNCOMPLEXBOX);
1220 disableComplexBox();
1224 //=========================================================================
1226 void wxGUIEditorGraphicBBS::OnAddComplexBoxInput(wxCommandEvent& event)
1228 wxTextEntryDialog *nameDialog = new wxTextEntryDialog(this,
1229 wxT("Name of input port"));
1230 if (nameDialog->ShowModal() == wxID_OK)
1232 wxString fileName = nameDialog->GetValue();
1233 if (!fileName.IsEmpty())
1235 std::string portName = (const char*) (fileName.mb_str());
1236 if ( !boxNameExists(portName) )
1238 _tabsMgr->addActualDiagramComplexInputPort(portName);
1240 wxMessageDialog *dial = new wxMessageDialog(NULL,
1241 wxT("Impossible to create Box. The name already exists. Please provide another name"),
1242 wxT("Change name: name already exists"), wxOK | wxICON_EXCLAMATION | wxSTAY_ON_TOP);
1249 //=========================================================================
1250 void wxGUIEditorGraphicBBS::OnAddComplexBoxOutput(wxCommandEvent& event)
1252 wxTextEntryDialog *nameDialog = new wxTextEntryDialog(this,
1253 wxT("Name of output port"));
1254 if (nameDialog->ShowModal() == wxID_OK)
1256 wxString fileName = nameDialog->GetValue();
1257 if (!fileName.IsEmpty())
1259 std::string portName = (const char*) (fileName.mb_str());
1260 if ( !boxNameExists(portName) )
1262 _tabsMgr->addActualDiagramComplexOutputPort(portName);
1264 wxMessageDialog *dial = new wxMessageDialog(NULL,
1265 wxT("Impossible to create Box. The name already exists. Please provide another name"),
1266 wxT("Change name: name already exists"), wxOK | wxICON_EXCLAMATION | wxSTAY_ON_TOP);
1274 //=========================================================================
1275 void wxGUIEditorGraphicBBS::OnCopySelectedToComplexDiagram(
1276 wxCommandEvent& event)
1278 _tabsMgr->copySelectedBBoxesToComplexDiagram();
1281 //=========================================================================
1282 void wxGUIEditorGraphicBBS::OnHelpBBeditor(wxCommandEvent& event)
1284 printf("wxGUIEditorGraphicBBS::OnHelpBBeditor ....not implemented..\n");
1287 //=========================================================================
1288 void wxGUIEditorGraphicBBS::OnCreatePackage(wxCommandEvent& event)
1290 bbtkSystemTools::CreatePackage();
1293 //=========================================================================
1294 void wxGUIEditorGraphicBBS::OnCreateBlackBox(wxCommandEvent& event)
1296 bbtkSystemTools::CreateBlackBox();
1299 //=========================================================================
1300 void wxGUIEditorGraphicBBS::OnPlugPackage(wxCommandEvent& event)
1302 //DFGO2012 Plug Package functionnalities
1303 long style = wxDD_DEFAULT_STYLE | wxDD_DIR_MUST_EXIST;
1306 _T("Select package directory"),
1312 userResponse = FD->ShowModal();
1313 if(userResponse==wxID_OK)
1315 std::string path = wx2std (FD->GetPath()) ;
1317 std::string fname = path + "\\bbtkPackage";
1319 std::string fname = path + "/bbtkPackage";
1322 std::cout << "Path chosen = \"" << FD->GetPath() << "\"" << std::endl;
1323 if ( Utilities::FileExists( fname ) )
1326 f.open(fname.c_str());
1329 while(pname[0] == '#')
1331 getline(f, pname, '\n');
1336 bbtk::ConfigurationFile::GetInstance().AddPackagePathsAndWrite( path );
1338 DoRegeneratePackageDoc(pname);
1339 DoRegenerateBoxesLists();
1341 _pkgBrowser->RebuildList();
1343 wxMessageBox(_T("Package successfully plugged. Please restart bbEditor to see the new package in the package browser."),_T("Plug package"),wxOK | wxICON_INFORMATION);
1344 userResponse = wxID_CANCEL;
1348 std::string err = "The directory \"" + path + "\" does not contain a 'bbtkPackage' file.";
1351 err += "\nNote: If you are on Linux please select the folder and click \"Open\", don't enter in it.";
1355 wxMessageBox(crea::std2wx(err), _T("Plug package"),wxOK | wxICON_ERROR);
1356 // THE FOLLOWING LINE GIVES ERRORS BECAUSE IT IS NECESSARY TO USE std2wx
1357 //wxMessageBox( _T( err) , _T("Plug package"),wxOK | wxICON_ERROR);
1360 }while(userResponse != wxID_CANCEL);
1364 //=========================================================================
1365 void wxGUIEditorGraphicBBS::OnEditConfig(wxCommandEvent& event)
1367 std::string commandStr;
1368 std::string configFile = ConfigurationFile::GetInstance().Get_config_xml_full_path();
1370 commandStr = "notepad.exe ";
1372 commandStr = "gedit ";
1374 commandStr = commandStr + configFile;
1375 std::cout << "system: " << commandStr << std::endl;
1376 system ( commandStr.c_str() );
1379 //=========================================================================
1380 void wxGUIEditorGraphicBBS::OnShowHTMLDoc(wxCommandEvent& event)
1383 if (_helpHtmlBrowser != NULL){
1384 _frameAUIMgr->DetachPane(_helpHtmlBrowser);
1385 _helpHtmlBrowser->Destroy();
1387 initHelpHTMLBrowser();
1388 _frameAUIMgr->AddPane(_helpHtmlBrowser, wxAuiPaneInfo().Right().MinSize(200, 200));
1389 _frameAUIMgr->Update();
1390 refreshGUIControls();
1395 //=========================================================================
1396 void wxGUIEditorGraphicBBS::OnCreateIndex(wxCommandEvent& event)
1398 printf("EED wxGUIEditorGraphicBBS::OnCreateIndex ... not implemented ..\n");
1402 //=========================================================================
1403 void wxGUIEditorGraphicBBS::OnEditComplexBoxScript(wxCommandEvent& event)
1405 BlackBoxDescriptor *bbDes = _pkgBrowser->GetActualSelected();
1408 std::string packageName = bbDes->GetPackage()->GetName();
1409 std::string typeName = bbDes->GetTypeName();
1410 if (!TryToOpenScriptComplexBox(packageName ,typeName))
1412 wxMessageDialog windowMessage1(NULL,_T("This is not a ComplexBox script."), _T("Alert !"), wxOK);
1413 windowMessage1.ShowModal();
1418 //=========================================================================
1419 void wxGUIEditorGraphicBBS::OnExit(wxCommandEvent& event)
1424 Factory::Pointer wxGUIEditorGraphicBBS::GetBBTKFactory()
1426 if (_pkgBrowser==NULL)
1428 printf ("EED ERROR! wxGUIEditorGraphicBBS::GetBBTKFactory _pkgBrowser = NULL\n");
1430 return _pkgBrowser->GetFactory();
1433 //=========================================================================
1434 void wxGUIEditorGraphicBBS::enableComplexBox()
1436 _tabsMgr->setActualDiagramComplexBox(true);
1437 refreshGUIControls();
1440 //=========================================================================
1442 void wxGUIEditorGraphicBBS::disableComplexBox()
1444 _tabsMgr->setActualDiagramComplexBox(false);
1445 refreshGUIControls();
1448 //=========================================================================
1449 void wxGUIEditorGraphicBBS::setCurrentDiagramDescription(std::string description)
1451 _tabsMgr->SetDescription(description);
1454 //=========================================================================
1455 void wxGUIEditorGraphicBBS::setCurrentDiagramAuthor(std::string author)
1457 _tabsMgr->SetAuthor(author);
1460 //=========================================================================
1461 void wxGUIEditorGraphicBBS::setCurrentDiagramCategory(std::string category)
1463 _tabsMgr->SetCategory(category);
1466 //=========================================================================
1467 void wxGUIEditorGraphicBBS::setCurrentDiagramMessageKind(std::string kind){
1468 _tabsMgr->SetMessageKind(kind);
1471 //=========================================================================
1472 void wxGUIEditorGraphicBBS::setCurrentDiagramMessageLevel(std::string level){
1473 _tabsMgr->SetMessageLevel(level);
1476 //=========================================================================
1477 std::string wxGUIEditorGraphicBBS::getCurrentDiagramDescription()
1479 return _tabsMgr->GetDescription();
1482 //=========================================================================
1483 std::string wxGUIEditorGraphicBBS::getCurrentDiagramAuthor()
1485 return _tabsMgr->GetAuthor();
1488 //=========================================================================
1489 std::string wxGUIEditorGraphicBBS::getCurrentDiagramCategory()
1491 return _tabsMgr->GetCategory();
1494 //=========================================================================
1495 std::string wxGUIEditorGraphicBBS::getCurrentDiagramMessageKind(){
1496 return _tabsMgr->GetMessageKind();
1499 //=========================================================================
1500 std::string wxGUIEditorGraphicBBS::getCurrentDiagramMessageLevel(){
1501 return _tabsMgr->GetMessageLevel();
1504 //=========================================================================
1505 bool wxGUIEditorGraphicBBS::isCurrentDiagramComplexBox()
1507 return _tabsMgr->isActualDiagramComplexBox();
1511 //=========================================================================
1512 void wxGUIEditorGraphicBBS::OpenScript(std::string filePathNameBBS ,std::string boxType)
1514 std::string fileName = boxType+".bbg";
1515 std::string filePathNameBBG = filePathNameBBS;
1516 filePathNameBBG[ filePathNameBBG.length()-1 ] = 'g';
1518 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);
1519 windowMessage1.ShowModal();
1521 if ( Utilities::FileExists( filePathNameBBG ) )
1523 OpenDiagram( filePathNameBBG , fileName );
1525 if ( Utilities::FileExists( filePathNameBBS ) )
1527 OpenBBS( filePathNameBBS , fileName );
1529 wxMessageDialog windowMessage1(NULL,_T("..ERROR.. loading script bbg/bbs."), _T("Alert !"), wxOK);
1530 windowMessage1.ShowModal();
1537 //=========================================================================
1538 bool wxGUIEditorGraphicBBS::TryToOpenScriptApplication(std::string packageName ,std::string boxType)
1540 return TryToOpenScript(packageName ,boxType, true, false);
1543 //=========================================================================
1544 bool wxGUIEditorGraphicBBS::TryToOpenScriptComplexBox(std::string packageName ,std::string boxType)
1546 return TryToOpenScript(packageName ,boxType, false, true);
1550 //=========================================================================
1551 bool wxGUIEditorGraphicBBS::TryToOpenScript(std::string packageName ,std::string boxType,bool scriptApplication, bool scriptComplexBox)
1554 std::map< std::string, BlackBoxDescriptor::Pointer> mapDesc;
1555 BlackBoxDescriptor::Pointer descriptor;
1556 k = GetBBTKFactory()->GetPackage(packageName);
1557 mapDesc = k->GetDescriptorMap();
1558 descriptor = mapDesc[boxType];
1563 ((descriptor->IsTypeOfScript_Application()==true) && (scriptApplication==true))
1565 ((descriptor->IsTypeOfScript_ComplexBox()==true) && (scriptComplexBox==true))
1569 OpenScript(descriptor->GetScriptFileName(),boxType);
1575 } // EO namespace bbtk