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() {
126 wxBitmap bmp_new(new_xpm);
127 wxBitmap bmp_open(open_xpm);
128 wxBitmap bmp_save(save_xpm);
129 wxBitmap bmp_run(run_xpm);
130 wxBitmap bmp_delete(delete_xpm);
131 wxBitmap bmp_centerview(centerview_xpm);
132 wxBitmap bmp_box(box_xpm);
133 wxBitmap bmp_executablebox(executablebox_xpm);
134 wxBitmap bmp_complexbox(complexbox_xpm);
135 wxBitmap bmp_complexinputport(complexinputport_xpm);
136 wxBitmap bmp_complexoutputport(complexoutputport_xpm);
137 wxBitmap bmp_undo(undo_xpm);
138 wxBitmap bmp_redo(redo_xpm);
139 wxBitmap bmp_editProperties(editProperties_xpm);
140 wxBitmap bmp_showTree(showTree_xpm);
141 wxToolBar *toolbar = new wxToolBar(this, wxID_ANY);
143 //Adds a tool btn to the toolbar
144 toolbar->AddTool(ID_NEW, _T("New"), bmp_new, wxNullBitmap, wxITEM_NORMAL,
145 _T("New tab"), _T("Create a new panel tab"));
146 toolbar->AddTool(ID_OPEN, _T("Open diagram"), bmp_open, wxNullBitmap,
147 wxITEM_NORMAL, _T("Open a diagram"), _T("Open a diagram"));
148 toolbar->AddTool(ID_SAVE_DIAGRAM, _T("Save Diagram"), bmp_save,
149 wxNullBitmap, wxITEM_NORMAL, _T("Saves the current diagram"),
150 _T("Saves the current diagram")); //DFCH
151 //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
152 toolbar->AddTool(ID_RUN, _T("Run"), bmp_run, wxNullBitmap, wxITEM_NORMAL,
153 _T("Execute actual diagram"), _T("Execute actual diagram"));
154 toolbar->AddTool(ID_DELETEALL, _T("Delete all"), bmp_delete, wxNullBitmap,
155 wxITEM_NORMAL, _T("Delete all boxes"), _T("Delete all boxes"));
156 toolbar->AddTool(ID_CENTERVIEW, _T("Center view"), bmp_centerview,
157 wxNullBitmap, wxITEM_NORMAL, _T("Center view"), _T("Center view"));
158 toolbar->AddSeparator();
159 toolbar->AddTool(ID_BTNBOX, _T("New Box"), bmp_box, wxNullBitmap,
160 wxITEM_NORMAL, _T("New Box"), _T("Nex Box"));
161 toolbar->AddSeparator();
162 toolbar->AddTool(ID_BTEXECUTABLEBOX, _T("Select as executable Box"),
163 bmp_executablebox, wxNullBitmap, wxITEM_NORMAL,
164 _T("Select as executable Box"), _T("Select as executable Box"));
165 toolbar->AddSeparator();
166 toolbar->AddTool(ID_BTNCOMPLEXBOX, _T("Complex box"), complexbox_xpm,
167 wxNullBitmap, wxITEM_NORMAL, _T("Complex box"), _T("Complex box"));
168 toolbar->SetToggle(ID_BTNCOMPLEXBOX, true);
170 // RaC 2012 2nd HackFest - Now Complex inputs are any external input
171 // toolbar->AddTool(ID_ADDCOMPLEXBOXINPUT, _T("Add input to Complex box"),
172 // bmp_complexinputport, wxNullBitmap, wxITEM_NORMAL,
173 // _T("Add input to Complex box"), _T("Add input to Complex box"));
174 toolbar->AddTool(ID_ADDCOMPLEXBOXINPUT, _T("Add external input (Complex box or console app)"),
175 bmp_complexinputport, wxNullBitmap, wxITEM_NORMAL,
176 _T("Add external input (Complex box or console app)"), _T("Add external input (Complex box or console app)"));
178 toolbar->AddTool(ID_ADDCOMPLEXBOXOUTPUT, _T("Add output to Complex box"),
179 bmp_complexoutputport, wxNullBitmap, wxITEM_NORMAL,
180 _T("Add output Complex box"), _T("Add output Complex box"));
182 // toolbar->EnableTool(ID_ADDCOMPLEXBOXINPUT, false); RaC2012 2nd HackFest
183 toolbar->EnableTool(ID_ADDCOMPLEXBOXINPUT, true);
185 toolbar->EnableTool(ID_ADDCOMPLEXBOXOUTPUT, false);
186 toolbar->AddSeparator();
187 toolbar->AddTool(ID_UNDO, _T("Undo"),bmp_undo, wxNullBitmap, wxITEM_NORMAL, _T("Undo"), _T("Undo"));
188 toolbar->AddTool(ID_REDO, _T("Redo"),bmp_redo, wxNullBitmap, wxITEM_NORMAL, _T("Redo"), _T("Redo"));
189 toolbar->AddSeparator();
190 toolbar->AddTool(ID_EDITPROPERTIES, _T("Edit diagram properties"),bmp_editProperties, wxNullBitmap, wxITEM_NORMAL, _T("Edit diagram properties"), _T("Edit diagram properties"));
191 toolbar->EnableTool(ID_EDITPROPERTIES, false);
193 toolbar->AddTool(ID_SHOWTREE, _T("Show tree"),bmp_showTree, wxNullBitmap, wxITEM_NORMAL, _T("Show tree"), _T("Show tree"));
195 toolbar->EnableTool(ID_UNDO, false);
196 toolbar->EnableTool(ID_REDO, false);
197 toolbar->SetMargins(2, 2);
202 // connect command event handlers
204 Connect(ID_NEW, wxEVT_COMMAND_TOOL_CLICKED,
205 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnCreateNewTab));
206 Connect(ID_OPEN, wxEVT_COMMAND_TOOL_CLICKED,
207 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnOpenDiagram));
208 Connect(ID_SAVE_DIAGRAM, wxEVT_COMMAND_TOOL_CLICKED,
209 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnSaveActualDiagram)); //DFCH
210 Connect(ID_SAVE_AS_DIAGRAM, wxEVT_COMMAND_TOOL_CLICKED,
211 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnSaveAsActualDiagram)); //DFCH
214 wxEVT_COMMAND_TOOL_CLICKED,
215 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnExecuteActualDiagram));
218 wxEVT_COMMAND_TOOL_CLICKED,
219 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnDeleteAllBoxesActualDiagram));
222 wxEVT_COMMAND_TOOL_CLICKED,
223 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnCenterViewActualDiagram));
224 Connect(ID_BTNBOX, wxEVT_COMMAND_TOOL_CLICKED,
225 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnClickBtnBox));
228 wxEVT_COMMAND_TOOL_CLICKED,
229 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnClickBtnExecutableBox));
230 Connect(ID_BTNCOMPLEXBOX, wxEVT_COMMAND_TOOL_CLICKED,
231 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnClickBtnComplexBox));
232 Connect(ID_ADDCOMPLEXBOXINPUT, wxEVT_COMMAND_TOOL_CLICKED,
233 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnAddComplexBoxInput));
234 Connect(ID_ADDCOMPLEXBOXOUTPUT, wxEVT_COMMAND_TOOL_CLICKED,
235 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnAddComplexBoxOutput));
236 Connect(ID_UNDO,wxEVT_COMMAND_TOOL_CLICKED, wxCommandEventHandler(wxGUIEditorGraphicBBS::OnUndo));
237 Connect(ID_REDO,wxEVT_COMMAND_TOOL_CLICKED, wxCommandEventHandler(wxGUIEditorGraphicBBS::OnRedo));
238 Connect(ID_CHANGENAME, wxEVT_COMMAND_RIGHT_CLICK, wxCommandEventHandler(wxGUIEditorGraphicBBS::OnChangeName));
239 Connect(ID_EDITPROPERTIES,wxEVT_COMMAND_TOOL_CLICKED, wxCommandEventHandler(wxGUIEditorGraphicBBS::OnEditDiagramProperties));
240 Connect(ID_SHOWTREE,wxEVT_COMMAND_TOOL_CLICKED, wxCommandEventHandler(wxGUIEditorGraphicBBS::OnShowTree));
243 //=========================================================================
244 void wxGUIEditorGraphicBBS::initHelpHTMLBrowser() {
246 _helpHtmlBrowser = new WxGUIHtmlBrowser(this, wxSize(200, 0));
252 //=========================================================================
253 void wxGUIEditorGraphicBBS::initMenu() {
254 // Create File menu and its items
255 wxMenu *fileMenu = new wxMenu();
256 fileMenu->Append(ID_NEW, _T("New diagram"), _T("New"));
257 fileMenu->Append(ID_SAVE_DIAGRAM, _T("Save Diagram"), _T("Save Diagram")); //DFCH
258 fileMenu->Append(ID_SAVE_AS_DIAGRAM, _T("Save Diagram As"),
259 _T("Save Diagram As")); //DFCH
260 fileMenu->Append(ID_OPEN_BBS, _T("Open BBS"), _T("Open BBS"));
262 fileMenu->Append(ID_OPEN, _T("Open a diagram"), _T("Open a diagram"));
263 fileMenu->Append(ID_SAVE_AS_BBS, _T("Save BBS"), _T("Save BBS"));
264 fileMenu->Append(ID_SAVE_AS_COMPLEXBOX, _T("Save complex box"),
265 _T("Save complex box"));
266 fileMenu->Append(ID_EXPORT_CONSOLEAPP, _T("Export console commands"),
267 _T("Export console execution commands"));
268 fileMenu->Append(wxID_EXIT, _T("E&xit"), _T("Exit"));
270 Connect(ID_NEW, wxEVT_COMMAND_MENU_SELECTED,
271 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnCreateNewTab));
272 Connect(ID_SAVE_DIAGRAM, wxEVT_COMMAND_MENU_SELECTED,
273 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnSaveActualDiagram)); //DFCH
274 Connect(ID_SAVE_AS_DIAGRAM, wxEVT_COMMAND_MENU_SELECTED,
275 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnSaveAsActualDiagram));
276 Connect(ID_OPEN_BBS, wxEVT_COMMAND_MENU_SELECTED,
277 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnOpenBBS));
278 Connect(ID_SAVE_AS_BBS, wxEVT_COMMAND_MENU_SELECTED,
279 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnSaveActualBBS));
280 Connect( ID_SAVE_AS_COMPLEXBOX, wxEVT_COMMAND_MENU_SELECTED,
281 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnSaveActualComplexBox));
282 Connect( ID_EXPORT_CONSOLEAPP, wxEVT_COMMAND_MENU_SELECTED,
283 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnExportConsoleExecCommand));
284 Connect(wxID_EXIT, wxEVT_COMMAND_MENU_SELECTED,
285 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnExit));
287 // Create Edit menu and its items
288 wxMenu *editMenu = new wxMenu;
289 editMenu->Append(ID_COPY_TO_COMPLEXDIAGRAM, _T("Copy selected to complex box"), _T("Creates a new complex box diagram with selected boxes"));
290 editMenu->Append(ID_EDIT_COMPLEXBOX_SCRIPT, _T("Edit Complex Box"), _T("Edit Complex Box"));
291 Connect( ID_COPY_TO_COMPLEXDIAGRAM, wxEVT_COMMAND_MENU_SELECTED,
292 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnCopySelectedToComplexDiagram));
293 Connect( ID_EDIT_COMPLEXBOX_SCRIPT, wxEVT_COMMAND_MENU_SELECTED,
294 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnEditComplexBoxScript));
296 // Create Help menu and its items
297 wxMenu *helpMenu = new wxMenu;
298 helpMenu->Append(wxID_ABOUT, _T("&About..."), _T("About"));
299 helpMenu->Append(ID_HELP_BBEDITOR, _T("&Help..."), _T("Help"));
300 Connect(ID_HELP_BBEDITOR, wxEVT_COMMAND_MENU_SELECTED,
301 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnHelpBBeditor));
304 wxMenu *menuTools = new wxMenu;
305 menuTools->Append(ID_bbEditor_Tool_Menu_CreatePackage,
306 _T("Create &package") );
307 menuTools->Append(ID_bbEditor_Tool_Menu_CreateBlackBox,
308 _T("Create &blackbox") );
309 menuTools->Append(ID_bbEditor_Tool_Menu_PlugPackage, _T("Plug package") );
310 menuTools->Append(ID_bbEditor_Tool_Menu_EditConfig, _T("&Edit bbtk config") );
311 menuTools->Append(ID_bbEditor_Tool_Menu_ShowHTMLDoc,
312 _T("Show &HTML documentation") );
313 menuTools->Append(ID_bbEditor_Tool_Menu_CreateIndex, _T("&Generate index") );
315 Connect(ID_bbEditor_Tool_Menu_CreatePackage, wxEVT_COMMAND_MENU_SELECTED,
316 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnCreatePackage));
317 Connect(ID_bbEditor_Tool_Menu_CreateBlackBox, wxEVT_COMMAND_MENU_SELECTED,
318 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnCreateBlackBox));
319 Connect(ID_bbEditor_Tool_Menu_PlugPackage, wxEVT_COMMAND_MENU_SELECTED,
320 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnPlugPackage));
321 Connect(ID_bbEditor_Tool_Menu_EditConfig, wxEVT_COMMAND_MENU_SELECTED,
322 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnEditConfig));
323 Connect(ID_bbEditor_Tool_Menu_ShowHTMLDoc, wxEVT_COMMAND_MENU_SELECTED,
324 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnShowHTMLDoc));
325 Connect(ID_bbEditor_Tool_Menu_CreateIndex, wxEVT_COMMAND_MENU_SELECTED,
326 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnCreateIndex));
328 // Append the created menu to the menu bar
329 wxMenuBar *menuBar = new wxMenuBar();
330 menuBar->Append(fileMenu, _T("&File") );
331 menuBar->Append(editMenu, _T("&Edit") );
332 menuBar->Append(menuTools, _T("&Tool") );
333 menuBar->Append(helpMenu, _T("&Help") );
335 // Attach this menu bar to the frame
339 //=========================================================================
340 void wxGUIEditorGraphicBBS::initTabPanelsManager()
342 _notebook = new wxAuiNotebook(this, wxID_NOTEBOOK, wxDefaultPosition,
343 wxDefaultSize, wxAUI_NB_TOP | wxAUI_NB_TAB_MOVE
344 | wxAUI_NB_CLOSE_ON_ACTIVE_TAB | wxAUI_NB_TAB_FIXED_WIDTH
345 | wxAUI_NB_WINDOWLIST_BUTTON);
346 _tabsMgr = new wxTabPanelsManager(this);
347 _frameAUIMgr->AddPane(_notebook, wxAuiPaneInfo().CenterPane());
350 //=========================================================================
351 void wxGUIEditorGraphicBBS::initPackageBrowser()
353 _pkgBrowser = new WxGUIPackageBrowser2(this);
354 _pkgBrowser->IncludeAll();
355 _frameAUIMgr->AddPane(_pkgBrowser, wxAuiPaneInfo().Left().MinSize(30, 500).BestSize(750,500).CloseButton(false));
358 //================================================================
360 void wxGUIEditorGraphicBBS::DoRegeneratePackageDoc(const std::string& pack)
362 std::string mess("Regenerating doc for package '");
366 mess = "Regenerating doc for all packages";
369 mess += " ... please wait";
371 SetStatusText(std2wx(mess));
379 command += ConfigurationFile::GetInstance().Get_bin_path();
380 command += ConfigurationFile::GetInstance().Get_file_separator();
381 command += "bbRegeneratePackageDoc";
386 command += " " + pack + " -q";
387 bbtkMessage("debug",1,"Executing system command '"<<command<<"'"<<std::endl);
389 if (!system(command.c_str())) {
390 SetStatusText(_T("Done !"));
392 wxMessageBox(_T("Done !"),_T("Regenerate package '")
393 +std2wx(pack)+_T("' doc"),
394 wxOK | wxICON_INFORMATION);
397 SetStatusText(_T("Done !"));
398 wxString err(_T("An error occured while running '"));
399 err += bbtk::std2wx(command) + _T("'");
400 wxMessageBox(err, _T("Regenerate package doc"), wxOK | wxICON_ERROR);
404 //================================================================
405 void wxGUIEditorGraphicBBS::DoRegenerateBoxesLists() {
406 SetStatusText(_T("Regenerating boxes lists ... please wait"));
413 command += ConfigurationFile::GetInstance().Get_bin_path();
414 command += ConfigurationFile::GetInstance().Get_file_separator();
415 command += "bbRegenerateBoxesLists";
422 bbtkMessage("debug",1,"Executing system command '"<<command<<"'"<<std::endl);
424 if (!system(command.c_str())) {
425 SetStatusText(_T("Done !"));
427 wxMessageBox(_T("Done !"),_T("Regenerate boxes lists"),
428 wxOK | wxICON_INFORMATION);
431 SetStatusText(_T("Done !"));
432 wxString err(_T("An error occured while running '"));
433 err += bbtk::std2wx(command) + _T("'");
434 wxMessageBox(err, _T("Regenerate boxes lists"), wxOK | wxICON_ERROR);
438 //================================================================
439 void wxGUIEditorGraphicBBS::RegenerateAll() {
440 DoRegeneratePackageDoc("-a");
441 DoRegenerateBoxesLists();
444 //================================================================
446 wxAuiNotebook* wxGUIEditorGraphicBBS::getAuiNotebook() {
450 //================================================================
452 void wxGUIEditorGraphicBBS::displayBlackBoxInfo(std::string packageName, std::string boxName)
454 if (_actualPkgBrowserPkgName != packageName || _actualPkgBrowserBoxName != boxName)
457 _actualPkgBrowserPkgName = packageName;
458 _actualPkgBrowserBoxName = boxName;
460 //EED 15 oct 2012 BlackBoxDescriptor::Pointer descriptor = GObjectsMVCFactory::getInstance()->getBlackBoxDescriptor(packageName, boxName);
463 //EED ComplexBlackBoxDescriptor::Pointer descriptor;
464 BlackBoxDescriptor::Pointer descriptor;
466 std::map< std::string, BlackBoxDescriptor::Pointer> mapDesc;
467 k = _pkgBrowser->GetFactory()->GetPackage(_actualPkgBrowserPkgName);
468 mapDesc = k->GetDescriptorMap();
469 descriptor = mapDesc[_actualPkgBrowserBoxName];
475 descriptor->GetBoxesInside(tree, 0);
478 //std::vector<std::string> boxesDiagram = _sceneM->boxesDiagram;
479 //for(int i=0;i<boxesDiagram.size();i++){
480 // std::cout<<"caja: "<<boxesDiagram[i]<<std::endl;
483 _actualPkgBrowserPkgName = "";
484 _actualPkgBrowserBoxName = "";
488 BlackBoxDescriptor::Pointer descriptor;
489 std::map< std::string, BlackBoxDescriptor::Pointer> mapDesc;
490 k = _pkgBrowser->GetFactory()->GetPackage(packageName);
491 std::vector<std::string> temp;
492 _pkgBrowser->GetFactory()->GetPackagesList(temp);
493 for(int ii = 0 ; ii < temp.size() ; ii++)
495 std::cout << " packs "<< temp[ii]<< std::endl;
497 mapDesc = k->GetDescriptorMap();
498 descriptor = mapDesc[boxName];
500 _pkgBrowser->WxGUIBlackBoxListUserOnSelected(descriptor.get());
504 //=========================================================================
506 void wxGUIEditorGraphicBBS::editBlackBox(GBlackBoxModel *bbmodel) {
507 wxBlackBoxEditionDialog* dialog =
508 new wxBlackBoxEditionDialog(this, bbmodel);
512 //=========================================================================
514 bool wxGUIEditorGraphicBBS::boxNameExists(std::string boxname) {
516 return this->_tabsMgr->getActualTabPanel()->getSceneManager()->boxExist(boxname);
519 //=========================================================================
521 void wxGUIEditorGraphicBBS::updateStatusBar(std::string textStatus) {
522 SetStatusText(crea::std2wx(textStatus));
525 //=========================================================================
527 void wxGUIEditorGraphicBBS::executeScript(std::string script) {
528 std::string separator =
529 ConfigurationFile::GetInstance().Get_file_separator();
530 std::string dir = ConfigurationFile::GetInstance().Get_default_temp_dir();
531 std::string filename = dir + separator + "tmp_bbtk.bbs";
534 tempFile.open(filename.c_str());
538 std::string command = "";
541 command += "start /b ";
544 // command += "\""+ crea::System::GetExecutablePath();
546 // command += separator + "../../../bbi.app/Contents/MacOS";
550 command += "\"" + filename + "\"";
556 printf("RaC wxGUIEditorGraphicBBS::executeScript %s \n", command.c_str());
557 system(command.c_str());
560 //=========================================================================
561 std::string wxGUIEditorGraphicBBS::CheckExtension(std::string filename, std::string extension) {
562 if(filename.size() > extension.size() ){
563 if( (filename.compare(filename.size()-extension.size(), extension.size(),extension)) !=0 ){
564 filename.append(extension);
567 filename.append(extension);
571 //=========================================================================
573 //=========================================================================
575 void wxGUIEditorGraphicBBS::OnCreateNewTab(wxCommandEvent& event) {
576 _tabsMgr->addNewTab();
577 refreshGUIControls();
580 void wxGUIEditorGraphicBBS::OnUndo(wxCommandEvent& event) {
581 unsigned short disable;
585 _tabsMgr->loadTempDiagram(0);
586 disable = _tabsMgr->getUndoState(stundo);
589 std::string name = _tabsMgr->GetNameTabPanel();
590 if(name[name.length() - 1] == '*')
592 name =name.substr(0,name.length()-1);
594 _tabsMgr->SetNameTabPanel(wxString (name.c_str(), wxConvUTF8));
597 GetToolBar()->EnableTool(ID_UNDO,disable);
598 GetToolBar()->SetToolShortHelp(ID_UNDO,crea::std2wx(stundo));
599 GetToolBar()->EnableTool(ID_REDO,_tabsMgr->getRedoState(stredo));
600 GetToolBar()->SetToolShortHelp(ID_REDO,crea::std2wx(stredo));
601 refreshGUIControls();
604 //=========================================================================
606 void wxGUIEditorGraphicBBS::OnRedo(wxCommandEvent& event) {
607 unsigned short disable;
611 _tabsMgr->loadTempDiagram(1);
612 std::string name = _tabsMgr->GetNameTabPanel();
613 if(name[name.length() - 1] != '*')
615 _tabsMgr->SetNameTabPanel(wxString (name.c_str(), wxConvUTF8));
616 GetToolBar()->EnableTool(ID_UNDO,_tabsMgr->getUndoState(stundo));
617 GetToolBar()->SetToolShortHelp(ID_UNDO,crea::std2wx(stundo));
618 GetToolBar()->EnableTool(ID_REDO,_tabsMgr->getRedoState(stredo));
619 GetToolBar()->SetToolShortHelp(ID_REDO,crea::std2wx(stredo));
620 refreshGUIControls();
623 void wxGUIEditorGraphicBBS::OnChangeName(wxCommandEvent& event){
625 //=========================================================================
627 void wxGUIEditorGraphicBBS::OnShowTree(wxCommandEvent& event){
628 std::cout << "wxGUIEditorGraphicBBS::OnShowTree"<<std::endl;
629 if (_actualPkgBrowserPkgName !="" || _actualPkgBrowserBoxName != "")
632 //EED ComplexBlackBoxDescriptor::Pointer descriptor;
633 BlackBoxDescriptor::Pointer descriptor;
635 std::map< std::string, BlackBoxDescriptor::Pointer> mapDesc;
636 k = _pkgBrowser->GetFactory()->GetPackage(_actualPkgBrowserPkgName);
637 mapDesc = k->GetDescriptorMap();
638 descriptor = mapDesc[_actualPkgBrowserBoxName];
644 descriptor->GetBoxesInside(tree, 0);
646 _actualPkgBrowserPkgName = "";
647 _actualPkgBrowserBoxName = "";
651 std::cout<<"Select a Box"<<std::endl;
655 //=========================================================================
657 void wxGUIEditorGraphicBBS::OnEditDiagramProperties(wxCommandEvent& event)
659 wxDiagramPropertiesEditionDialog* dialog =
660 new wxDiagramPropertiesEditionDialog(this, tree);
664 //=========================================================================
666 void wxGUIEditorGraphicBBS::OnExecuteActualDiagram(wxCommandEvent& event) {
667 std::string script1 = _tabsMgr->getActualDiagramBBS(true);
668 cout << endl << "RaC wxGUIEditorGraphicBBS::executeActualDiagram SCRIPT"
670 cout << script1 << endl;
672 std::string script2 = _tabsMgr->getActualDiagramBBS(false);
673 executeScript(script2);
677 //=========================================================================
678 void wxGUIEditorGraphicBBS::OpenBBS(std::string filePathName, std::string fileName)
680 _tabsMgr->addNewTab( crea::std2wx(fileName) );
681 bbtk::InterpreterBBS::Pointer I = bbtk::InterpreterBBS::New( this->_tabsMgr->getActualTabPanel()->getSceneManager(), _pkgBrowser->GetFactory());
682 // We tell the interpreter to throw exceptions on error
684 // Interpret the file supposed to define a box called 'Processing'
685 I->InterpretFile( filePathName );
686 refreshGUIControls();
689 //=========================================================================
691 //=========================================================================
692 void wxGUIEditorGraphicBBS::OnOpenBBS(wxCommandEvent& event)
694 //EED 2017-09-16 Migration wxWidgets 2.8 to 3.0
695 #if wxMAJOR_VERSION <= 2
696 wxFileDialog * openFileDialog = new wxFileDialog(this, wxT("Open BBS"), wxEmptyString, wxT("NewBBS"), wxT("*.bbs"), wxOPEN);
698 wxFileDialog * openFileDialog = new wxFileDialog(this, wxT("Open BBS"), wxEmptyString, wxT("NewBBS"), wxT("*.bbs"), wxFD_OPEN);
701 if (openFileDialog->ShowModal() == wxID_OK)
703 OpenBBS( crea::wx2std(openFileDialog->GetPath()) , crea::wx2std(openFileDialog->GetFilename()) );
707 if (openFileDialog->ShowModal() == wxID_OK)
709 wxString fileName = openFileDialog->GetPath();
710 _tabsMgr->addNewTab(openFileDialog->GetFilename());
711 bbtk::InterpreterBBS::Pointer I = bbtk::InterpreterBBS::New( this->_tabsMgr->getActualTabPanel()->getSceneManager(), _pkgBrowser->GetFactory());
712 // We tell the interpreter to throw exceptions on error
714 // Interpret the file supposed to define a box called 'Processing'
715 I->InterpretFile((const char*) (fileName.mb_str()));
717 refreshGUIControls();
721 //=========================================================================
722 void wxGUIEditorGraphicBBS::SaveActualBBS(std::string filename) {
725 //EED file.open(fileName.c_str());
726 file.open(filename.c_str());
727 std::string content = "";
728 // writing file header
729 content += "# ----------------------------------\n";
730 content += "# - BBTKGEditor v ";
731 content += _currentBBGversion; //VERSION
732 content += " BBS BlackBox Script\n";
736 content += "# ----------------------------------\n";
738 content += _tabsMgr->getActualDiagramBBS();
743 void wxGUIEditorGraphicBBS::OnSaveActualBBS(wxCommandEvent& event) {
745 //EED 2017-09-16 Migration wxWidgets 2.8 to 3.0
746 #if wxMAJOR_VERSION <= 2
747 wxFileDialog * saveFileDialog = new wxFileDialog(this,
748 wxT("Save actual BBS"), wxEmptyString, wxT("NewBBS"),
749 wxT("*.bbs"), wxSAVE | wxOVERWRITE_PROMPT);
751 wxFileDialog * saveFileDialog = new wxFileDialog(this,
752 wxT("Save actual BBS"), wxEmptyString, wxT("NewBBS"),
753 wxT("*.bbs"), wxFD_SAVE | wxFD_OVERWRITE_PROMPT);
756 if (saveFileDialog->ShowModal() == wxID_OK) {
757 wxString fileName = saveFileDialog->GetPath();
758 std::string filename = (const char*) (fileName.mb_str());
759 filename=CheckExtension (filename, ".bbs");
760 SaveActualBBS(filename);
765 void wxGUIEditorGraphicBBS::AskComplexBoxConfiguration() {
766 std::string cbName = _tabsMgr->GetCbName();
767 std::string paName = _tabsMgr->GetCbPackageName();
769 wxTextEntryDialog *cbNameDialog = new wxTextEntryDialog(this,
770 wxT("Complex Box name"));
771 wxTextEntryDialog *paNameDialog = new wxTextEntryDialog(this,
772 wxT("Package name"));
774 cbNameDialog->SetValue(wxString(cbName.c_str(), wxConvUTF8));
775 paNameDialog->SetValue(wxString(paName.c_str(), wxConvUTF8));
777 if (cbNameDialog->ShowModal() == wxID_OK) {
778 wxString complexboxname = cbNameDialog->GetValue();
779 cbName = (const char*) (complexboxname.mb_str());
782 if (paNameDialog->ShowModal() == wxID_OK) {
783 wxString packagename = paNameDialog->GetValue();
784 paName = (const char*) (packagename.mb_str());
787 _tabsMgr->SetCbName(cbName);
788 _tabsMgr->SetCbPackageName(paName);
791 //=========================================================================
793 void wxGUIEditorGraphicBBS::SaveActualComplexBox(std::string filename) {
795 file.open(filename.c_str());
797 std::string content = "";
799 // writing file header
800 content += "# ----------------------------------\n";
801 content += "# - BBTKGEditor v ";
802 content += _currentBBGversion;//VERSION
803 content += " BBS BlackBox Script (Complex Box)\n";
807 content += "# ----------------------------------\n";
809 content += _tabsMgr->getActualComplexBoxBBS();
814 //=========================================================================
816 void wxGUIEditorGraphicBBS::OnSaveActualComplexBox(wxCommandEvent& event)
818 //EED 2017-09-16 Migration wxWidgets 2.8 to 3.0
819 #if wxMAJOR_VERSION <= 2
820 wxFileDialog * saveFileDialog = new wxFileDialog(this,
821 wxT("Save Complex Box BBS"), wxEmptyString,
822 _T("ComplexBoxName"), wxT("*.bbs"), wxSAVE
823 | wxOVERWRITE_PROMPT);
825 wxFileDialog * saveFileDialog = new wxFileDialog(this,
826 wxT("Save Complex Box BBS"), wxEmptyString,
827 _T("ComplexBoxName"), wxT("*.bbs"), wxFD_SAVE
828 | wxFD_OVERWRITE_PROMPT);
831 if (saveFileDialog->ShowModal() == wxID_OK) {
832 wxString fileName = saveFileDialog->GetPath();
833 std::string filename = (const char*) (fileName.mb_str());
834 filename=CheckExtension (filename, ".bbs");
835 SaveActualComplexBox(filename);
839 //=========================================================================
840 void wxGUIEditorGraphicBBS::SaveActualDiagram(std::string filename) {
842 file.open(filename.c_str());
844 std::string content = "";
846 // writing file header
847 content += "# ----------------------------------\n";
848 content += "# - BBTKGEditor v ";
849 content += _currentBBGversion; //VERSION
850 content += " BBG BlackBox Diagram file\n";
856 content += "# ----------------------------------\n";
858 content += "APP_START\n";
859 _tabsMgr->saveActualDiagram(content, filename); //DFCH
860 content += "APP_END\n";
865 //=========================================================================
866 void wxGUIEditorGraphicBBS::SaveTempActualDiagram(const std::string &action)
870 std::string name = _tabsMgr->GetNameTabPanel();
871 if(name[name.length() - 1] != '*')
873 _tabsMgr->SetNameTabPanel(wxString (name.c_str(), wxConvUTF8));
874 _tabsMgr->saveTempActualDiagram(action);
875 GetToolBar()->EnableTool(ID_UNDO,_tabsMgr->getUndoState(stundo));
876 GetToolBar()->SetToolShortHelp(ID_UNDO,crea::std2wx(stundo));
877 GetToolBar()->EnableTool(ID_REDO,_tabsMgr->getRedoState(stredo));
878 GetToolBar()->SetToolShortHelp(ID_REDO,crea::std2wx(stredo));
881 //=========================================================================
883 //The following method allows to save the current diagram asking the filename
885 void wxGUIEditorGraphicBBS::SaveCurrentDiagramAs()
888 //EED 2017-09-16 Migration wxWidgets 2.8 to 3.0
889 #if wxMAJOR_VERSION <= 2
890 wxFileDialog * saveFileDialog = new wxFileDialog(this,
891 wxT("Save current diagram"), wxEmptyString, wxT("NewDiagram"),
892 wxT("*.bbg"), wxSAVE | wxOVERWRITE_PROMPT);
894 wxFileDialog * saveFileDialog = new wxFileDialog(this,
895 wxT("Save current diagram"), wxEmptyString, wxT("NewDiagram"),
896 wxT("*.bbg"), wxFD_SAVE | wxFD_OVERWRITE_PROMPT);
899 if (saveFileDialog->ShowModal() == wxID_OK) {
900 //_tabsMgr->SetNameTabPanel(saveFileDialog->GetFilename());
901 wxString pathfileName = saveFileDialog->GetPath();
902 std::string pathfilename = (const char*) (pathfileName.mb_str());
903 pathfilename=CheckExtension (pathfilename, ".bbg");
905 //modify the tab name accordingly
906 wxString fileName = saveFileDialog->GetFilename();
907 std::string filename = (const char*) (fileName.mb_str());
908 filename=CheckExtension (filename, ".bbg");
909 _tabsMgr->SetNameTabPanel( wxString (filename.c_str(), wxConvUTF8) );
911 std::string pathfilenamebbs = pathfilename;
912 pathfilenamebbs[pathfilenamebbs.length() - 1] = 's';
913 if (_tabsMgr->isActualDiagramComplexBox() == false) {
914 SaveActualDiagram(pathfilename);
915 SaveActualBBS(pathfilenamebbs);
917 AskComplexBoxConfiguration();
918 SaveActualDiagram(pathfilename);
919 SaveActualComplexBox(pathfilenamebbs);
920 } //if isActualDiagramComplexBox
921 } // if saveFileDialog
923 //=========================================================================
925 void wxGUIEditorGraphicBBS::OnSaveActualDiagram(wxCommandEvent& event) {
926 std::string pathfilename = _tabsMgr->GetCurrentTabPanelPath();
927 if (pathfilename.empty()) {
928 SaveCurrentDiagramAs();
930 std::string pathfilenamebbs = pathfilename;
931 pathfilenamebbs[pathfilenamebbs.length() - 1] = 's';
933 if (_tabsMgr->isActualDiagramComplexBox() == false) {
934 std::string name = _tabsMgr->GetNameTabPanel();
935 if(name[name.length() - 1] == '*')
937 name =name.substr(0,name.length()-1);
939 _tabsMgr->SetNameTabPanel(wxString (name.c_str(), wxConvUTF8));
940 SaveActualDiagram(pathfilename);
941 SaveActualBBS(pathfilenamebbs);
943 AskComplexBoxConfiguration();
944 SaveActualDiagram(pathfilename);
945 SaveActualComplexBox(pathfilenamebbs);
946 } //if isActualDiagramComplexBox
949 //=========================================================================
951 void wxGUIEditorGraphicBBS::OnSaveAsActualDiagram(wxCommandEvent& event) {
952 SaveCurrentDiagramAs();
955 //=========================================================================
956 void wxGUIEditorGraphicBBS::OnExportConsoleExecCommand(wxCommandEvent& event)
958 //EED 2017-09-16 Migration wxWidgets 2.8 to 3.0
959 #if wxMAJOR_VERSION <= 2
960 wxFileDialog * saveFileDialog = new wxFileDialog(this,
961 wxT("Export console command"), wxEmptyString, wxT("ConsoleApp.txt"),
962 wxT("*.txt;*.bbs;*.bbg;*.sh;*.bat"), wxSAVE | wxOVERWRITE_PROMPT);
964 wxFileDialog * saveFileDialog = new wxFileDialog(this,
965 wxT("Export console command"), wxEmptyString, wxT("ConsoleApp.txt"),
966 wxT("*.txt;*.bbs;*.bbg;*.sh;*.bat"), wxFD_SAVE | wxFD_OVERWRITE_PROMPT);
970 if (saveFileDialog->ShowModal() == wxID_OK)
972 wxString fileName = saveFileDialog->GetPath();
973 std::string filename = (const char*) (fileName.mb_str());
974 filename=CheckExtension (filename, ".txt");
977 file.open(filename.c_str());
979 std::vector<std::string> extInputs = _tabsMgr->getActualTabPanel()->getSceneManager()->GetExternalInputsNames();
981 //TODO PUT IN A METHOD OF A FILES AND TEXT MANAGER CLASS !!!
982 //std::string inputsInCommentsWin="";
983 //std::string inputsInCommentsUnix="";
984 //std::string inputsInOneLineWin="";
985 std::string inputsInOneLineUnix="";
986 for (unsigned int i = 0; i < extInputs.size(); ++i)
988 /* No gusto la idea al jefe pero por si acaso ...
989 * RaC 2012 2nd HackFest
991 inputsInCommentsWin+="REM ";
992 inputsInCommentsWin+=extInputs[i];
993 inputsInCommentsWin+="=\"value\"\n";
994 inputsInCommentsUnix+="# ";
995 inputsInCommentsUnix+=extInputs[i];
996 inputsInCommentsUnix+="=\"value\"\n";
999 sprintf (buffer, "%d", (i+1));
1000 inputsInOneLineWin+=extInputs[i];
1001 inputsInOneLineWin+="=\"%";
1002 inputsInOneLineWin+=buffer;
1003 inputsInOneLineWin+="\" ";
1005 inputsInOneLineUnix+=extInputs[i];
1006 inputsInOneLineUnix+="=\"<value>\" ";
1011 std::string content = "";
1012 // writing file header
1013 content += "# ----------------------------------\n";
1014 content += "# - BBTKGEditor v ";
1015 content += _currentBBGversion; //VERSION
1016 content += " Console Commands to execute BBS application\n";
1018 content += filename;
1020 content += "# ----------------------------------\n";
1023 content += "# Command to execute bbi\n";
1024 content += "bbi <bbs_path> ";
1025 content += inputsInOneLineUnix;
1027 /* No gusto la idea al jefe pero por si acaso ...
1028 * RaC 2012 2nd HackFest
1029 content += "# For Windows (copy the following lines to a .bat file)\n";
1030 content += "REM BBS application\n";
1031 content += "REM Inputs:\n";
1032 content += inputsInCommentsWin;
1033 content += "REM To use previous inputs, put %$inputName% in the corresponding input of the execution bbi line\n";
1034 content += "bbi applicationBBS.bbs ";
1035 content += inputsInOneLineWin;
1038 content += "# For Linux or Mac (copy the following lines to a .sh file)\n";
1039 content += "#!/bin/bash\n";
1040 content += "# BBS application\n";
1041 content += "# Inputs:\n";
1042 content += inputsInCommentsUnix;
1043 content += "# To use previous inputs, put $inputName in the corresponding input of the execution bbi line\n";
1044 content += "bbi applicationBBS.bbs ";
1045 content += inputsInOneLineUnix;
1056 //=========================================================================
1058 void wxGUIEditorGraphicBBS::refreshGUIControls()
1062 //RaC2012 2ndHackFest Next line seems weird ... To keep in mind for other devels
1063 wxToolBar* toolbar = GetToolBar();
1064 if (_tabsMgr->isActualDiagramComplexBox())
1066 toolbar->ToggleTool(ID_BTNCOMPLEXBOX, true);
1067 //toolbar->EnableTool(ID_ADDCOMPLEXBOXINPUT, true); RaC2012 2nd HackFest
1068 toolbar->EnableTool(ID_ADDCOMPLEXBOXOUTPUT, true);
1070 GetMenuBar()->GetMenu(0)->Enable(ID_SAVE_AS_COMPLEXBOX, true);
1071 GetMenuBar()->GetMenu(0)->Enable(ID_SAVE_AS_BBS, false);
1072 GetMenuBar()->GetMenu(0)->Enable(ID_EXPORT_CONSOLEAPP, false);
1074 toolbar->ToggleTool(ID_BTNCOMPLEXBOX, false);
1075 //toolbar->EnableTool(ID_ADDCOMPLEXBOXINPUT, false); RaC2012 2nd HackFest
1076 toolbar->EnableTool(ID_ADDCOMPLEXBOXOUTPUT, false);
1078 GetMenuBar()->GetMenu(0)->Enable(ID_SAVE_AS_COMPLEXBOX, false);
1079 GetMenuBar()->GetMenu(0)->Enable(ID_SAVE_AS_BBS, true);
1080 GetMenuBar()->GetMenu(0)->Enable(ID_EXPORT_CONSOLEAPP, true);
1083 //RaC2012 2ndHackFest
1084 GetToolBar()->EnableTool(ID_EDITPROPERTIES,true);
1086 GetToolBar()->EnableTool(ID_UNDO,_tabsMgr->getUndoState(stundo));
1087 GetToolBar()->SetToolShortHelp(ID_UNDO,crea::std2wx(stundo));
1088 GetToolBar()->EnableTool(ID_REDO,_tabsMgr->getRedoState(stredo));
1089 GetToolBar()->SetToolShortHelp(ID_REDO,crea::std2wx(stredo));
1091 if (_tabsMgr->getNumActualSelectedObjects() > 0) {
1092 GetMenuBar()->GetMenu(1)->Enable(ID_COPY_TO_COMPLEXDIAGRAM, true);
1094 ///TODO Fix the possibility to say from the SceneManager to the GUI to refresh the options
1095 GetMenuBar()->GetMenu(1)->Enable(ID_COPY_TO_COMPLEXDIAGRAM, true);
1100 //=========================================================================
1102 void wxGUIEditorGraphicBBS::OnDeleteAllBoxesActualDiagram(wxCommandEvent& event)
1104 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);
1105 if (dial->ShowModal() == wxID_YES)
1107 _tabsMgr->deleteAllBoxesActualDiagram();
1111 //=========================================================================
1113 void wxGUIEditorGraphicBBS::OnCenterViewActualDiagram(wxCommandEvent& event)
1115 _tabsMgr->centerViewActualDiagram();
1118 //=========================================================================
1119 void wxGUIEditorGraphicBBS::OpenDiagram(std::string filePathName, std::string fileName)
1121 ifstream inputStream;
1122 inputStream.open(filePathName.c_str());
1123 assert(inputStream.good()); // fails
1125 if(_tabsMgr->FindTab(filePathName)!=-1) //RaC2012 avoid opening same diagram twice
1127 inputStream.close();
1128 printf("RaC: Diagram already opened\n");
1131 _tabsMgr->addNewTab( crea::std2wx(fileName) );
1132 _tabsMgr->loadDiagram(inputStream, filePathName);
1134 _tabsMgr->saveTempActualDiagram("load diagram");
1135 GetToolBar()->EnableTool(ID_UNDO, false);
1136 GetToolBar()->EnableTool(ID_UNDO, false);
1137 inputStream.close();
1138 refreshGUIControls();
1141 //=========================================================================
1143 void wxGUIEditorGraphicBBS::OnOpenDiagram(wxCommandEvent& event)
1146 //EED 2017-09-16 Migration wxWidgets 2.8 to 3.0
1147 #if wxMAJOR_VERSION <= 2
1148 wxFileDialog * openFileDialog = new wxFileDialog(this, wxT("Open diagram"), wxEmptyString, wxT(""), wxT("*.bbg"), wxOPEN | wxFILE_MUST_EXIST);
1150 wxFileDialog * openFileDialog = new wxFileDialog(this, wxT("Open diagram"), wxEmptyString, wxT(""), wxT("*.bbg"), wxFD_OPEN | wxFD_FILE_MUST_EXIST);
1153 if (openFileDialog->ShowModal() == wxID_OK)
1155 wxString filePath = openFileDialog->GetPath();
1156 wxString fileName = openFileDialog->GetFilename();
1157 OpenDiagram( crea::wx2std(filePath) , crea::wx2std(fileName) );
1161 //=========================================================================
1162 void wxGUIEditorGraphicBBS::OnClickBtnBox(wxCommandEvent& event)
1164 std::cout<<"wxGUIEditorGraphicBBS::OnClickBtnBox"<<std::endl;
1165 BlackBoxDescriptor *bbDes = _pkgBrowser->GetActualSelected();
1166 if (bbDes != NULL) {
1167 std::string typeName = bbDes->GetTypeName();
1168 std::string packageName = bbDes->GetPackage()->GetName();
1169 wxGEditorTabPanel *pnl = this->_tabsMgr->getActualTabPanel();
1171 wxVtkSceneManager *scn = pnl->getSceneManager();
1172 scn->createGBlackBox(50, 50, packageName, typeName);
1175 SaveTempActualDiagram("New Box");
1180 //=========================================================================
1182 void wxGUIEditorGraphicBBS::OnClickBtnExecutableBox(wxCommandEvent& event)
1185 wxGEditorTabPanel *pnl = this->_tabsMgr->getActualTabPanel();
1188 wxVtkSceneManager *scn = pnl->getSceneManager();
1189 if( scn->MakeBoxExecutable() )
1190 std::cout<<"DFCH: wxGUIEditorGraphicBBS::OnClickBtnExecutableBox...successful"<<std::endl;
1192 std::cout<<"DFCH: wxGUIEditorGraphicBBS::OnClickBtnExecutableBox...Error!!"<<std::endl;
1198 //=========================================================================
1199 void wxGUIEditorGraphicBBS::OnClickBtnComplexBox(wxCommandEvent& event)
1201 std::cout<<"wxGUIEditorGraphicBBS::OnClickBtnComplexBox"<<std::endl;
1202 wxToolBar* toolbar = GetToolBar();
1203 bool temp = toolbar->GetToolState(ID_BTNCOMPLEXBOX);
1207 disableComplexBox();
1211 //=========================================================================
1213 void wxGUIEditorGraphicBBS::OnAddComplexBoxInput(wxCommandEvent& event)
1215 wxTextEntryDialog *nameDialog = new wxTextEntryDialog(this,
1216 wxT("Name of input port"));
1217 if (nameDialog->ShowModal() == wxID_OK)
1219 wxString fileName = nameDialog->GetValue();
1220 if (!fileName.IsEmpty())
1222 std::string portName = (const char*) (fileName.mb_str());
1223 if ( !boxNameExists(portName) )
1225 _tabsMgr->addActualDiagramComplexInputPort(portName);
1227 wxMessageDialog *dial = new wxMessageDialog(NULL,
1228 wxT("Impossible to create Box. The name already exists. Please provide another name"),
1229 wxT("Change name: name already exists"), wxOK | wxICON_EXCLAMATION | wxSTAY_ON_TOP);
1236 //=========================================================================
1237 void wxGUIEditorGraphicBBS::OnAddComplexBoxOutput(wxCommandEvent& event)
1239 wxTextEntryDialog *nameDialog = new wxTextEntryDialog(this,
1240 wxT("Name of output port"));
1241 if (nameDialog->ShowModal() == wxID_OK)
1243 wxString fileName = nameDialog->GetValue();
1244 if (!fileName.IsEmpty())
1246 std::string portName = (const char*) (fileName.mb_str());
1247 if ( !boxNameExists(portName) )
1249 _tabsMgr->addActualDiagramComplexOutputPort(portName);
1251 wxMessageDialog *dial = new wxMessageDialog(NULL,
1252 wxT("Impossible to create Box. The name already exists. Please provide another name"),
1253 wxT("Change name: name already exists"), wxOK | wxICON_EXCLAMATION | wxSTAY_ON_TOP);
1261 //=========================================================================
1262 void wxGUIEditorGraphicBBS::OnCopySelectedToComplexDiagram(
1263 wxCommandEvent& event)
1265 _tabsMgr->copySelectedBBoxesToComplexDiagram();
1268 //=========================================================================
1269 void wxGUIEditorGraphicBBS::OnHelpBBeditor(wxCommandEvent& event)
1271 printf("wxGUIEditorGraphicBBS::OnHelpBBeditor ....not implemented..\n");
1274 //=========================================================================
1275 void wxGUIEditorGraphicBBS::OnCreatePackage(wxCommandEvent& event)
1277 bbtkSystemTools::CreatePackage();
1280 //=========================================================================
1281 void wxGUIEditorGraphicBBS::OnCreateBlackBox(wxCommandEvent& event)
1283 bbtkSystemTools::CreateBlackBox();
1286 //=========================================================================
1287 void wxGUIEditorGraphicBBS::OnPlugPackage(wxCommandEvent& event)
1289 //DFGO2012 Plug Package functionnalities
1290 long style = wxDD_DEFAULT_STYLE | wxDD_DIR_MUST_EXIST;
1293 _T("Select package directory"),
1299 userResponse = FD->ShowModal();
1300 if(userResponse==wxID_OK)
1302 std::string path = wx2std (FD->GetPath()) ;
1304 std::string fname = path + "\\bbtkPackage";
1306 std::string fname = path + "/bbtkPackage";
1309 std::cout << "Path chosen = \"" << FD->GetPath() << "\"" << std::endl;
1310 if ( Utilities::FileExists( fname ) )
1313 f.open(fname.c_str());
1316 while(pname[0] == '#')
1318 getline(f, pname, '\n');
1323 bbtk::ConfigurationFile::GetInstance().AddPackagePathsAndWrite( path );
1325 DoRegeneratePackageDoc(pname);
1326 DoRegenerateBoxesLists();
1328 _pkgBrowser->RebuildList();
1330 wxMessageBox(_T("Package successfully plugged. Please restart bbEditor to see the new package in the package browser."),_T("Plug package"),wxOK | wxICON_INFORMATION);
1331 userResponse = wxID_CANCEL;
1335 std::string err = "The directory \"" + path + "\" does not contain a 'bbtkPackage' file.";
1338 err += "\nNote: If you are on Linux please select the folder and click \"Open\", don't enter in it.";
1342 wxMessageBox(crea::std2wx(err), _T("Plug package"),wxOK | wxICON_ERROR);
1343 // THE FOLLOWING LINE GIVES ERRORS BECAUSE IT IS NECESSARY TO USE std2wx
1344 //wxMessageBox( _T( err) , _T("Plug package"),wxOK | wxICON_ERROR);
1347 }while(userResponse != wxID_CANCEL);
1351 //=========================================================================
1352 void wxGUIEditorGraphicBBS::OnEditConfig(wxCommandEvent& event)
1354 std::string commandStr;
1355 std::string configFile = ConfigurationFile::GetInstance().Get_config_xml_full_path();
1357 commandStr = "notepad.exe ";
1359 commandStr = "gedit ";
1361 commandStr = commandStr + configFile;
1362 std::cout << "system: " << commandStr << std::endl;
1363 system ( commandStr.c_str() );
1366 //=========================================================================
1367 void wxGUIEditorGraphicBBS::OnShowHTMLDoc(wxCommandEvent& event)
1370 if (_helpHtmlBrowser != NULL){
1371 _frameAUIMgr->DetachPane(_helpHtmlBrowser);
1372 _helpHtmlBrowser->Destroy();
1374 initHelpHTMLBrowser();
1375 _frameAUIMgr->AddPane(_helpHtmlBrowser, wxAuiPaneInfo().Right().MinSize(200, 200));
1376 _frameAUIMgr->Update();
1377 refreshGUIControls();
1382 //=========================================================================
1383 void wxGUIEditorGraphicBBS::OnCreateIndex(wxCommandEvent& event)
1385 printf("EED wxGUIEditorGraphicBBS::OnCreateIndex ... not implemented ..\n");
1389 //=========================================================================
1390 void wxGUIEditorGraphicBBS::OnEditComplexBoxScript(wxCommandEvent& event)
1392 BlackBoxDescriptor *bbDes = _pkgBrowser->GetActualSelected();
1395 std::string packageName = bbDes->GetPackage()->GetName();
1396 std::string typeName = bbDes->GetTypeName();
1397 if (!TryToOpenScriptComplexBox(packageName ,typeName))
1399 wxMessageDialog windowMessage1(NULL,_T("This is not a ComplexBox script."), _T("Alert !"), wxOK);
1400 windowMessage1.ShowModal();
1405 //=========================================================================
1406 void wxGUIEditorGraphicBBS::OnExit(wxCommandEvent& event)
1411 Factory::Pointer wxGUIEditorGraphicBBS::GetBBTKFactory()
1413 if (_pkgBrowser==NULL)
1415 printf ("EED ERROR! wxGUIEditorGraphicBBS::GetBBTKFactory _pkgBrowser = NULL\n");
1417 return _pkgBrowser->GetFactory();
1420 //=========================================================================
1421 void wxGUIEditorGraphicBBS::enableComplexBox()
1423 _tabsMgr->setActualDiagramComplexBox(true);
1424 refreshGUIControls();
1427 //=========================================================================
1429 void wxGUIEditorGraphicBBS::disableComplexBox()
1431 _tabsMgr->setActualDiagramComplexBox(false);
1432 refreshGUIControls();
1435 //=========================================================================
1436 void wxGUIEditorGraphicBBS::setCurrentDiagramDescription(std::string description)
1438 _tabsMgr->SetDescription(description);
1441 //=========================================================================
1442 void wxGUIEditorGraphicBBS::setCurrentDiagramAuthor(std::string author)
1444 _tabsMgr->SetAuthor(author);
1447 //=========================================================================
1448 void wxGUIEditorGraphicBBS::setCurrentDiagramCategory(std::string category)
1450 _tabsMgr->SetCategory(category);
1453 //=========================================================================
1454 void wxGUIEditorGraphicBBS::setCurrentDiagramMessageKind(std::string kind){
1455 _tabsMgr->SetMessageKind(kind);
1458 //=========================================================================
1459 void wxGUIEditorGraphicBBS::setCurrentDiagramMessageLevel(std::string level){
1460 _tabsMgr->SetMessageLevel(level);
1463 //=========================================================================
1464 std::string wxGUIEditorGraphicBBS::getCurrentDiagramDescription()
1466 return _tabsMgr->GetDescription();
1469 //=========================================================================
1470 std::string wxGUIEditorGraphicBBS::getCurrentDiagramAuthor()
1472 return _tabsMgr->GetAuthor();
1475 //=========================================================================
1476 std::string wxGUIEditorGraphicBBS::getCurrentDiagramCategory()
1478 return _tabsMgr->GetCategory();
1481 //=========================================================================
1482 std::string wxGUIEditorGraphicBBS::getCurrentDiagramMessageKind(){
1483 return _tabsMgr->GetMessageKind();
1486 //=========================================================================
1487 std::string wxGUIEditorGraphicBBS::getCurrentDiagramMessageLevel(){
1488 return _tabsMgr->GetMessageLevel();
1491 //=========================================================================
1492 bool wxGUIEditorGraphicBBS::isCurrentDiagramComplexBox()
1494 return _tabsMgr->isActualDiagramComplexBox();
1498 //=========================================================================
1499 void wxGUIEditorGraphicBBS::OpenScript(std::string filePathNameBBS ,std::string boxType)
1501 std::string fileName = boxType+".bbg";
1502 std::string filePathNameBBG = filePathNameBBS;
1503 filePathNameBBG[ filePathNameBBG.length()-1 ] = 'g';
1505 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);
1506 windowMessage1.ShowModal();
1508 if ( Utilities::FileExists( filePathNameBBG ) )
1510 OpenDiagram( filePathNameBBG , fileName );
1512 if ( Utilities::FileExists( filePathNameBBS ) )
1514 OpenBBS( filePathNameBBS , fileName );
1516 wxMessageDialog windowMessage1(NULL,_T("..ERROR.. loading script bbg/bbs."), _T("Alert !"), wxOK);
1517 windowMessage1.ShowModal();
1524 //=========================================================================
1525 bool wxGUIEditorGraphicBBS::TryToOpenScriptApplication(std::string packageName ,std::string boxType)
1527 return TryToOpenScript(packageName ,boxType, true, false);
1530 //=========================================================================
1531 bool wxGUIEditorGraphicBBS::TryToOpenScriptComplexBox(std::string packageName ,std::string boxType)
1533 return TryToOpenScript(packageName ,boxType, false, true);
1537 //=========================================================================
1538 bool wxGUIEditorGraphicBBS::TryToOpenScript(std::string packageName ,std::string boxType,bool scriptApplication, bool scriptComplexBox)
1541 std::map< std::string, BlackBoxDescriptor::Pointer> mapDesc;
1542 BlackBoxDescriptor::Pointer descriptor;
1543 k = GetBBTKFactory()->GetPackage(packageName);
1544 mapDesc = k->GetDescriptorMap();
1545 descriptor = mapDesc[boxType];
1550 ((descriptor->IsTypeOfScript_Application()==true) && (scriptApplication==true))
1552 ((descriptor->IsTypeOfScript_ComplexBox()==true) && (scriptComplexBox==true))
1556 OpenScript(descriptor->GetScriptFileName(),boxType);
1562 } // EO namespace bbtk