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 printf("EED %p ~wxGUIEditorGraphicBBS()\n", this);
118 //EED02JUIN2010 delete _tabsMgr;
120 _frameAUIMgr->UnInit();
128 //=========================================================================
129 void wxGUIEditorGraphicBBS::initToolbar() {
130 wxBitmap bmp_new(new_xpm);
131 wxBitmap bmp_open(open_xpm);
132 wxBitmap bmp_save(save_xpm);
133 wxBitmap bmp_run(run_xpm);
134 wxBitmap bmp_delete(delete_xpm);
135 wxBitmap bmp_centerview(centerview_xpm);
136 wxBitmap bmp_box(box_xpm);
137 wxBitmap bmp_executablebox(executablebox_xpm);
138 wxBitmap bmp_complexbox(complexbox_xpm);
139 wxBitmap bmp_complexinputport(complexinputport_xpm);
140 wxBitmap bmp_complexoutputport(complexoutputport_xpm);
141 wxBitmap bmp_undo(undo_xpm);
142 wxBitmap bmp_redo(redo_xpm);
143 wxBitmap bmp_editProperties(editProperties_xpm);
144 wxToolBar *toolbar = new wxToolBar(this, wxID_ANY);
146 //Adds a tool btn to the toolbar
147 toolbar->AddTool(ID_NEW, _T("New"), bmp_new, wxNullBitmap, wxITEM_NORMAL,
148 _T("New tab"), _T("Create a new panel tab"));
149 toolbar->AddTool(ID_OPEN, _T("Open diagram"), bmp_open, wxNullBitmap,
150 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"));
171 toolbar->SetToggle(ID_BTNCOMPLEXBOX, true);
173 // RaC 2012 2nd HackFest - Now Complex inputs are any external input
174 // toolbar->AddTool(ID_ADDCOMPLEXBOXINPUT, _T("Add input to Complex box"),
175 // bmp_complexinputport, wxNullBitmap, wxITEM_NORMAL,
176 // _T("Add input to Complex box"), _T("Add input to Complex box"));
177 toolbar->AddTool(ID_ADDCOMPLEXBOXINPUT, _T("Add external input (Complex box or console app)"),
178 bmp_complexinputport, wxNullBitmap, wxITEM_NORMAL,
179 _T("Add external input (Complex box or console app)"), _T("Add external input (Complex box or console app)"));
181 toolbar->AddTool(ID_ADDCOMPLEXBOXOUTPUT, _T("Add output to Complex box"),
182 bmp_complexoutputport, wxNullBitmap, wxITEM_NORMAL,
183 _T("Add output Complex box"), _T("Add output Complex box"));
185 // toolbar->EnableTool(ID_ADDCOMPLEXBOXINPUT, false); RaC2012 2nd HackFest
186 toolbar->EnableTool(ID_ADDCOMPLEXBOXINPUT, true);
188 toolbar->EnableTool(ID_ADDCOMPLEXBOXOUTPUT, false);
189 toolbar->AddSeparator();
190 toolbar->AddTool(ID_UNDO, _T("Undo"),bmp_undo, wxNullBitmap, wxITEM_NORMAL, _T("Undo"), _T("Undo"));
191 toolbar->AddTool(ID_REDO, _T("Redo"),bmp_redo, wxNullBitmap, wxITEM_NORMAL, _T("Redo"), _T("Redo"));
192 toolbar->AddSeparator();
193 toolbar->AddTool(ID_EDITPROPERTIES, _T("Edit diagram properties"),bmp_editProperties, wxNullBitmap, wxITEM_NORMAL, _T("Edit diagram properties"), _T("Edit diagram properties"));
194 toolbar->EnableTool(ID_EDITPROPERTIES, false);
196 toolbar->EnableTool(ID_UNDO, false);
197 toolbar->EnableTool(ID_REDO, false);
198 toolbar->SetMargins(2, 2);
203 // connect command event handlers
205 Connect(ID_NEW, wxEVT_COMMAND_TOOL_CLICKED,
206 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnCreateNewTab));
207 Connect(ID_OPEN, wxEVT_COMMAND_TOOL_CLICKED,
208 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnOpenDiagram));
209 Connect(ID_SAVE_DIAGRAM, wxEVT_COMMAND_TOOL_CLICKED,
210 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnSaveActualDiagram)); //DFCH
211 Connect(ID_SAVE_AS_DIAGRAM, wxEVT_COMMAND_TOOL_CLICKED,
212 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnSaveAsActualDiagram)); //DFCH
215 wxEVT_COMMAND_TOOL_CLICKED,
216 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnExecuteActualDiagram));
219 wxEVT_COMMAND_TOOL_CLICKED,
220 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnDeleteAllBoxesActualDiagram));
223 wxEVT_COMMAND_TOOL_CLICKED,
224 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnCenterViewActualDiagram));
225 Connect(ID_BTNBOX, wxEVT_COMMAND_TOOL_CLICKED,
226 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnClickBtnBox));
229 wxEVT_COMMAND_TOOL_CLICKED,
230 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnClickBtnExecutableBox));
231 Connect(ID_BTNCOMPLEXBOX, wxEVT_COMMAND_TOOL_CLICKED,
232 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnClickBtnComplexBox));
233 Connect(ID_ADDCOMPLEXBOXINPUT, wxEVT_COMMAND_TOOL_CLICKED,
234 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnAddComplexBoxInput));
235 Connect(ID_ADDCOMPLEXBOXOUTPUT, wxEVT_COMMAND_TOOL_CLICKED,
236 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnAddComplexBoxOutput));
237 Connect(ID_UNDO,wxEVT_COMMAND_TOOL_CLICKED, wxCommandEventHandler(wxGUIEditorGraphicBBS::OnUndo));
238 Connect(ID_REDO,wxEVT_COMMAND_TOOL_CLICKED, wxCommandEventHandler(wxGUIEditorGraphicBBS::OnRedo));
239 Connect(ID_CHANGENAME, wxEVT_COMMAND_RIGHT_CLICK, wxCommandEventHandler(wxGUIEditorGraphicBBS::OnChangeName));
240 Connect(ID_EDITPROPERTIES,wxEVT_COMMAND_TOOL_CLICKED, wxCommandEventHandler(wxGUIEditorGraphicBBS::OnEditDiagramProperties));
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)
456 _actualPkgBrowserPkgName = packageName;
457 _actualPkgBrowserBoxName = boxName;
459 //EED 15 oct 2012 BlackBoxDescriptor::Pointer descriptor = GObjectsMVCFactory::getInstance()->getBlackBoxDescriptor(packageName, boxName);
462 //EED ComplexBlackBoxDescriptor::Pointer descriptor;
463 BlackBoxDescriptor::Pointer descriptor;
465 std::map< std::string, BlackBoxDescriptor::Pointer> mapDesc;
466 k = _pkgBrowser->GetFactory()->GetPackage(packageName);
467 mapDesc = k->GetDescriptorMap();
468 descriptor = mapDesc[boxName];
469 std::vector<std::string> temp;
470 descriptor->GetBoxesInside(tree,temp,1);
475 for(int i = 0 ; i < temp.size() ; i++){
476 std::cout<< " "<< temp[i] << std::endl;
481 std::cout<< "CAJAS # " << (temp.size()- 3) << std::endl;
482 for(int i = 0 ; i < temp.size()-1 ; i++){
483 if(i<3){std::cout<< " "<< temp[i] << std::endl;}
484 else{std::cout<< i+1 << " "<< temp[i] << " " <<temp[i+1] << std::endl;}
488 std::cout<< " Not Complex " << std::endl;
493 BlackBoxDescriptor::Pointer descriptor;
494 std::map< std::string, BlackBoxDescriptor::Pointer> mapDesc;
495 k = _pkgBrowser->GetFactory()->GetPackage(packageName);
496 std::vector<std::string> temp;
497 _pkgBrowser->GetFactory()->GetPackagesList(temp);
498 for(int ii = 0 ; ii < temp.size() ; ii++)
500 std::cout << " packs "<< temp[ii]<< std::endl;
502 mapDesc = k->GetDescriptorMap();
503 descriptor = mapDesc[boxName];
505 _pkgBrowser->WxGUIBlackBoxListUserOnSelected(descriptor.get());
509 //=========================================================================
511 void wxGUIEditorGraphicBBS::editBlackBox(GBlackBoxModel *bbmodel) {
512 wxBlackBoxEditionDialog* dialog =
513 new wxBlackBoxEditionDialog(this, bbmodel);
517 //=========================================================================
519 bool wxGUIEditorGraphicBBS::boxNameExists(std::string boxname) {
521 return this->_tabsMgr->getActualTabPanel()->getSceneManager()->boxExist(boxname);
524 //=========================================================================
526 void wxGUIEditorGraphicBBS::updateStatusBar(std::string textStatus) {
527 SetStatusText(crea::std2wx(textStatus));
530 //=========================================================================
532 void wxGUIEditorGraphicBBS::executeScript(std::string script) {
533 std::string separator =
534 ConfigurationFile::GetInstance().Get_file_separator();
535 std::string dir = ConfigurationFile::GetInstance().Get_default_temp_dir();
536 std::string filename = dir + separator + "tmp_bbtk.bbs";
539 tempFile.open(filename.c_str());
543 std::string command = "";
546 command += "start /b ";
549 // command += "\""+ crea::System::GetExecutablePath();
551 // command += separator + "../../../bbi.app/Contents/MacOS";
555 command += "\"" + filename + "\"";
561 printf("RaC wxGUIEditorGraphicBBS::executeScript %s \n", command.c_str());
562 system(command.c_str());
565 //=========================================================================
566 std::string wxGUIEditorGraphicBBS::CheckExtension(std::string filename, std::string extension) {
567 if(filename.size() > extension.size() ){
568 if( (filename.compare(filename.size()-extension.size(), extension.size(),extension)) !=0 ){
569 filename.append(extension);
572 filename.append(extension);
576 //=========================================================================
578 //=========================================================================
580 void wxGUIEditorGraphicBBS::OnCreateNewTab(wxCommandEvent& event) {
581 _tabsMgr->addNewTab();
582 refreshGUIControls();
585 void wxGUIEditorGraphicBBS::OnUndo(wxCommandEvent& event) {
586 unsigned short disable;
590 _tabsMgr->loadTempDiagram(0);
591 disable = _tabsMgr->getUndoState(stundo);
594 std::string name = _tabsMgr->GetNameTabPanel();
595 if(name[name.length() - 1] == '*')
597 name =name.substr(0,name.length()-1);
599 _tabsMgr->SetNameTabPanel(wxString (name.c_str(), wxConvUTF8));
602 GetToolBar()->EnableTool(ID_UNDO,disable);
603 GetToolBar()->SetToolShortHelp(ID_UNDO,crea::std2wx(stundo));
604 GetToolBar()->EnableTool(ID_REDO,_tabsMgr->getRedoState(stredo));
605 GetToolBar()->SetToolShortHelp(ID_REDO,crea::std2wx(stredo));
606 refreshGUIControls();
609 //=========================================================================
611 void wxGUIEditorGraphicBBS::OnRedo(wxCommandEvent& event) {
612 unsigned short disable;
616 _tabsMgr->loadTempDiagram(1);
617 std::string name = _tabsMgr->GetNameTabPanel();
618 if(name[name.length() - 1] != '*')
620 _tabsMgr->SetNameTabPanel(wxString (name.c_str(), wxConvUTF8));
621 GetToolBar()->EnableTool(ID_UNDO,_tabsMgr->getUndoState(stundo));
622 GetToolBar()->SetToolShortHelp(ID_UNDO,crea::std2wx(stundo));
623 GetToolBar()->EnableTool(ID_REDO,_tabsMgr->getRedoState(stredo));
624 GetToolBar()->SetToolShortHelp(ID_REDO,crea::std2wx(stredo));
625 refreshGUIControls();
628 void wxGUIEditorGraphicBBS::OnChangeName(wxCommandEvent& event){
631 //=========================================================================
633 void wxGUIEditorGraphicBBS::OnEditDiagramProperties(wxCommandEvent& event)
635 wxDiagramPropertiesEditionDialog* dialog =
636 new wxDiagramPropertiesEditionDialog(this, tree);
640 //=========================================================================
642 void wxGUIEditorGraphicBBS::OnExecuteActualDiagram(wxCommandEvent& event) {
643 std::string script1 = _tabsMgr->getActualDiagramBBS(true);
644 cout << endl << "RaC wxGUIEditorGraphicBBS::executeActualDiagram SCRIPT"
646 cout << script1 << endl;
648 std::string script2 = _tabsMgr->getActualDiagramBBS(false);
649 executeScript(script2);
653 //=========================================================================
654 void wxGUIEditorGraphicBBS::OpenBBS(std::string filePathName, std::string fileName)
656 _tabsMgr->addNewTab( crea::std2wx(fileName) );
657 bbtk::InterpreterBBS::Pointer I = bbtk::InterpreterBBS::New( this->_tabsMgr->getActualTabPanel()->getSceneManager(), _pkgBrowser->GetFactory());
658 // We tell the interpreter to throw exceptions on error
660 // Interpret the file supposed to define a box called 'Processing'
661 I->InterpretFile( filePathName );
662 refreshGUIControls();
665 //=========================================================================
667 //=========================================================================
668 void wxGUIEditorGraphicBBS::OnOpenBBS(wxCommandEvent& event)
670 wxFileDialog * openFileDialog = new wxFileDialog(this, wxT("Open BBS"), wxEmptyString, wxT("NewBBS"), wxT("*.bbs"), wxOPEN);
672 if (openFileDialog->ShowModal() == wxID_OK)
674 OpenBBS( crea::wx2std(openFileDialog->GetPath()) , crea::wx2std(openFileDialog->GetFilename()) );
678 if (openFileDialog->ShowModal() == wxID_OK)
680 wxString fileName = openFileDialog->GetPath();
681 _tabsMgr->addNewTab(openFileDialog->GetFilename());
682 bbtk::InterpreterBBS::Pointer I = bbtk::InterpreterBBS::New( this->_tabsMgr->getActualTabPanel()->getSceneManager(), _pkgBrowser->GetFactory());
683 // We tell the interpreter to throw exceptions on error
685 // Interpret the file supposed to define a box called 'Processing'
686 I->InterpretFile((const char*) (fileName.mb_str()));
688 refreshGUIControls();
692 //=========================================================================
693 void wxGUIEditorGraphicBBS::SaveActualBBS(std::string filename) {
696 //EED file.open(fileName.c_str());
697 file.open(filename.c_str());
698 std::string content = "";
699 // writing file header
700 content += "# ----------------------------------\n";
701 content += "# - BBTKGEditor v ";
702 content += _currentBBGversion; //VERSION
703 content += " BBS BlackBox Script\n";
707 content += "# ----------------------------------\n";
709 content += _tabsMgr->getActualDiagramBBS();
714 void wxGUIEditorGraphicBBS::OnSaveActualBBS(wxCommandEvent& event) {
715 wxFileDialog * saveFileDialog = new wxFileDialog(this,
716 wxT("Save actual BBS"), wxEmptyString, wxT("NewBBS"),
717 wxT("*.bbs"), wxSAVE | wxOVERWRITE_PROMPT);
718 if (saveFileDialog->ShowModal() == wxID_OK) {
719 wxString fileName = saveFileDialog->GetPath();
720 std::string filename = (const char*) (fileName.mb_str());
721 filename=CheckExtension (filename, ".bbs");
722 SaveActualBBS(filename);
727 void wxGUIEditorGraphicBBS::AskComplexBoxConfiguration() {
728 std::string cbName = _tabsMgr->GetCbName();
729 std::string paName = _tabsMgr->GetCbPackageName();
731 wxTextEntryDialog *cbNameDialog = new wxTextEntryDialog(this,
732 wxT("Complex Box name"));
733 wxTextEntryDialog *paNameDialog = new wxTextEntryDialog(this,
734 wxT("Package name"));
736 cbNameDialog->SetValue(wxString(cbName.c_str(), wxConvUTF8));
737 paNameDialog->SetValue(wxString(paName.c_str(), wxConvUTF8));
739 if (cbNameDialog->ShowModal() == wxID_OK) {
740 wxString complexboxname = cbNameDialog->GetValue();
741 cbName = (const char*) (complexboxname.mb_str());
744 if (paNameDialog->ShowModal() == wxID_OK) {
745 wxString packagename = paNameDialog->GetValue();
746 paName = (const char*) (packagename.mb_str());
749 _tabsMgr->SetCbName(cbName);
750 _tabsMgr->SetCbPackageName(paName);
753 //=========================================================================
755 void wxGUIEditorGraphicBBS::SaveActualComplexBox(std::string filename) {
757 file.open(filename.c_str());
759 std::string content = "";
761 // writing file header
762 content += "# ----------------------------------\n";
763 content += "# - BBTKGEditor v ";
764 content += _currentBBGversion;//VERSION
765 content += " BBS BlackBox Script (Complex Box)\n";
769 content += "# ----------------------------------\n";
771 content += _tabsMgr->getActualComplexBoxBBS();
776 //=========================================================================
778 void wxGUIEditorGraphicBBS::OnSaveActualComplexBox(wxCommandEvent& event) {
779 wxFileDialog * saveFileDialog = new wxFileDialog(this,
780 wxT("Save Complex Box BBS"), wxEmptyString,
781 _T("ComplexBoxName"), wxT("*.bbs"), wxSAVE
782 | wxOVERWRITE_PROMPT);
783 if (saveFileDialog->ShowModal() == wxID_OK) {
784 wxString fileName = saveFileDialog->GetPath();
785 std::string filename = (const char*) (fileName.mb_str());
786 filename=CheckExtension (filename, ".bbs");
787 SaveActualComplexBox(filename);
791 //=========================================================================
792 void wxGUIEditorGraphicBBS::SaveActualDiagram(std::string filename) {
794 file.open(filename.c_str());
796 std::string content = "";
798 // writing file header
799 content += "# ----------------------------------\n";
800 content += "# - BBTKGEditor v ";
801 content += _currentBBGversion; //VERSION
802 content += " BBG BlackBox Diagram file\n";
808 content += "# ----------------------------------\n";
810 content += "APP_START\n";
811 _tabsMgr->saveActualDiagram(content, filename); //DFCH
812 content += "APP_END\n";
817 //=========================================================================
818 void wxGUIEditorGraphicBBS::SaveTempActualDiagram(const std::string &action)
822 std::string name = _tabsMgr->GetNameTabPanel();
823 if(name[name.length() - 1] != '*')
825 _tabsMgr->SetNameTabPanel(wxString (name.c_str(), wxConvUTF8));
826 _tabsMgr->saveTempActualDiagram(action);
827 GetToolBar()->EnableTool(ID_UNDO,_tabsMgr->getUndoState(stundo));
828 GetToolBar()->SetToolShortHelp(ID_UNDO,crea::std2wx(stundo));
829 GetToolBar()->EnableTool(ID_REDO,_tabsMgr->getRedoState(stredo));
830 GetToolBar()->SetToolShortHelp(ID_REDO,crea::std2wx(stredo));
833 //=========================================================================
835 //The following method allows to save the current diagram asking the filename
837 void wxGUIEditorGraphicBBS::SaveCurrentDiagramAs() {
838 wxFileDialog * saveFileDialog = new wxFileDialog(this,
839 wxT("Save current diagram"), wxEmptyString, wxT("NewDiagram"),
840 wxT("*.bbg"), wxSAVE | wxOVERWRITE_PROMPT);
841 if (saveFileDialog->ShowModal() == wxID_OK) {
842 //_tabsMgr->SetNameTabPanel(saveFileDialog->GetFilename());
843 wxString pathfileName = saveFileDialog->GetPath();
844 std::string pathfilename = (const char*) (pathfileName.mb_str());
845 pathfilename=CheckExtension (pathfilename, ".bbg");
847 //modify the tab name accordingly
848 wxString fileName = saveFileDialog->GetFilename();
849 std::string filename = (const char*) (fileName.mb_str());
850 filename=CheckExtension (filename, ".bbg");
851 _tabsMgr->SetNameTabPanel( wxString (filename.c_str(), wxConvUTF8) );
853 std::string pathfilenamebbs = pathfilename;
854 pathfilenamebbs[pathfilenamebbs.length() - 1] = 's';
855 if (_tabsMgr->isActualDiagramComplexBox() == false) {
856 SaveActualDiagram(pathfilename);
857 SaveActualBBS(pathfilenamebbs);
859 AskComplexBoxConfiguration();
860 SaveActualDiagram(pathfilename);
861 SaveActualComplexBox(pathfilenamebbs);
862 } //if isActualDiagramComplexBox
863 } // if saveFileDialog
865 //=========================================================================
867 void wxGUIEditorGraphicBBS::OnSaveActualDiagram(wxCommandEvent& event) {
868 std::string pathfilename = _tabsMgr->GetCurrentTabPanelPath();
869 if (pathfilename.empty()) {
870 SaveCurrentDiagramAs();
872 std::string pathfilenamebbs = pathfilename;
873 pathfilenamebbs[pathfilenamebbs.length() - 1] = 's';
875 if (_tabsMgr->isActualDiagramComplexBox() == false) {
876 std::string name = _tabsMgr->GetNameTabPanel();
877 if(name[name.length() - 1] == '*')
879 name =name.substr(0,name.length()-1);
881 _tabsMgr->SetNameTabPanel(wxString (name.c_str(), wxConvUTF8));
882 SaveActualDiagram(pathfilename);
883 SaveActualBBS(pathfilenamebbs);
885 AskComplexBoxConfiguration();
886 SaveActualDiagram(pathfilename);
887 SaveActualComplexBox(pathfilenamebbs);
888 } //if isActualDiagramComplexBox
891 //=========================================================================
893 void wxGUIEditorGraphicBBS::OnSaveAsActualDiagram(wxCommandEvent& event) {
894 SaveCurrentDiagramAs();
897 //=========================================================================
898 void wxGUIEditorGraphicBBS::OnExportConsoleExecCommand(wxCommandEvent& event)
900 wxFileDialog * saveFileDialog = new wxFileDialog(this,
901 wxT("Export console command"), wxEmptyString, wxT("ConsoleApp.txt"),
902 wxT("*.txt;*.bbs;*.bbg;*.sh;*.bat"), wxSAVE | wxOVERWRITE_PROMPT);
904 if (saveFileDialog->ShowModal() == wxID_OK)
906 wxString fileName = saveFileDialog->GetPath();
907 std::string filename = (const char*) (fileName.mb_str());
908 filename=CheckExtension (filename, ".txt");
911 file.open(filename.c_str());
913 std::vector<std::string> extInputs = _tabsMgr->getActualTabPanel()->getSceneManager()->GetExternalInputsNames();
915 //TODO PUT IN A METHOD OF A FILES AND TEXT MANAGER CLASS !!!
916 //std::string inputsInCommentsWin="";
917 //std::string inputsInCommentsUnix="";
918 //std::string inputsInOneLineWin="";
919 std::string inputsInOneLineUnix="";
920 for (unsigned int i = 0; i < extInputs.size(); ++i)
922 /* No gusto la idea al jefe pero por si acaso ...
923 * RaC 2012 2nd HackFest
925 inputsInCommentsWin+="REM ";
926 inputsInCommentsWin+=extInputs[i];
927 inputsInCommentsWin+="=\"value\"\n";
928 inputsInCommentsUnix+="# ";
929 inputsInCommentsUnix+=extInputs[i];
930 inputsInCommentsUnix+="=\"value\"\n";
933 sprintf (buffer, "%d", (i+1));
934 inputsInOneLineWin+=extInputs[i];
935 inputsInOneLineWin+="=\"%";
936 inputsInOneLineWin+=buffer;
937 inputsInOneLineWin+="\" ";
939 inputsInOneLineUnix+=extInputs[i];
940 inputsInOneLineUnix+="=\"<value>\" ";
945 std::string content = "";
946 // writing file header
947 content += "# ----------------------------------\n";
948 content += "# - BBTKGEditor v ";
949 content += _currentBBGversion; //VERSION
950 content += " Console Commands to execute BBS application\n";
954 content += "# ----------------------------------\n";
957 content += "# Command to execute bbi\n";
958 content += "bbi <bbs_path> ";
959 content += inputsInOneLineUnix;
961 /* No gusto la idea al jefe pero por si acaso ...
962 * RaC 2012 2nd HackFest
963 content += "# For Windows (copy the following lines to a .bat file)\n";
964 content += "REM BBS application\n";
965 content += "REM Inputs:\n";
966 content += inputsInCommentsWin;
967 content += "REM To use previous inputs, put %$inputName% in the corresponding input of the execution bbi line\n";
968 content += "bbi applicationBBS.bbs ";
969 content += inputsInOneLineWin;
972 content += "# For Linux or Mac (copy the following lines to a .sh file)\n";
973 content += "#!/bin/bash\n";
974 content += "# BBS application\n";
975 content += "# Inputs:\n";
976 content += inputsInCommentsUnix;
977 content += "# To use previous inputs, put $inputName in the corresponding input of the execution bbi line\n";
978 content += "bbi applicationBBS.bbs ";
979 content += inputsInOneLineUnix;
990 //=========================================================================
992 void wxGUIEditorGraphicBBS::refreshGUIControls() {
995 //RaC2012 2ndHackFest Next line seems weird ... To keep in mind for other devels
996 wxToolBar* toolbar = GetToolBar();
997 if (_tabsMgr->isActualDiagramComplexBox()) {
998 toolbar->ToggleTool(ID_BTNCOMPLEXBOX, true);
999 //toolbar->EnableTool(ID_ADDCOMPLEXBOXINPUT, true); RaC2012 2nd HackFest
1000 toolbar->EnableTool(ID_ADDCOMPLEXBOXOUTPUT, true);
1002 GetMenuBar()->GetMenu(0)->Enable(ID_SAVE_AS_COMPLEXBOX, true);
1003 GetMenuBar()->GetMenu(0)->Enable(ID_SAVE_AS_BBS, false);
1004 GetMenuBar()->GetMenu(0)->Enable(ID_EXPORT_CONSOLEAPP, false);
1006 toolbar->ToggleTool(ID_BTNCOMPLEXBOX, false);
1007 //toolbar->EnableTool(ID_ADDCOMPLEXBOXINPUT, false); RaC2012 2nd HackFest
1008 toolbar->EnableTool(ID_ADDCOMPLEXBOXOUTPUT, false);
1010 GetMenuBar()->GetMenu(0)->Enable(ID_SAVE_AS_COMPLEXBOX, false);
1011 GetMenuBar()->GetMenu(0)->Enable(ID_SAVE_AS_BBS, true);
1012 GetMenuBar()->GetMenu(0)->Enable(ID_EXPORT_CONSOLEAPP, true);
1015 //RaC2012 2ndHackFest
1016 GetToolBar()->EnableTool(ID_EDITPROPERTIES,true);
1018 GetToolBar()->EnableTool(ID_UNDO,_tabsMgr->getUndoState(stundo));
1019 GetToolBar()->SetToolShortHelp(ID_UNDO,crea::std2wx(stundo));
1020 GetToolBar()->EnableTool(ID_REDO,_tabsMgr->getRedoState(stredo));
1021 GetToolBar()->SetToolShortHelp(ID_REDO,crea::std2wx(stredo));
1023 if (_tabsMgr->getNumActualSelectedObjects() > 0) {
1024 GetMenuBar()->GetMenu(1)->Enable(ID_COPY_TO_COMPLEXDIAGRAM, true);
1026 ///TODO Fix the possibility to say from the SceneManager to the GUI to refresh the options
1027 GetMenuBar()->GetMenu(1)->Enable(ID_COPY_TO_COMPLEXDIAGRAM, true);
1032 //=========================================================================
1034 void wxGUIEditorGraphicBBS::OnDeleteAllBoxesActualDiagram(wxCommandEvent& event)
1036 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);
1037 if (dial->ShowModal() == wxID_YES)
1039 _tabsMgr->deleteAllBoxesActualDiagram();
1043 //=========================================================================
1045 void wxGUIEditorGraphicBBS::OnCenterViewActualDiagram(wxCommandEvent& event)
1047 _tabsMgr->centerViewActualDiagram();
1050 //=========================================================================
1051 void wxGUIEditorGraphicBBS::OpenDiagram(std::string filePathName, std::string fileName)
1053 ifstream inputStream;
1054 inputStream.open(filePathName.c_str());
1055 assert(inputStream.good()); // fails
1057 if(_tabsMgr->FindTab(filePathName)!=-1) //RaC2012 avoid opening same diagram twice
1059 inputStream.close();
1060 printf("RaC: Diagram already opened\n");
1063 _tabsMgr->addNewTab( crea::std2wx(fileName) );
1064 _tabsMgr->loadDiagram(inputStream, filePathName);
1065 _tabsMgr->saveTempActualDiagram("load diagram");
1066 GetToolBar()->EnableTool(ID_UNDO, false);
1067 GetToolBar()->EnableTool(ID_UNDO, false);
1068 inputStream.close();
1069 refreshGUIControls();
1072 //=========================================================================
1074 void wxGUIEditorGraphicBBS::OnOpenDiagram(wxCommandEvent& event)
1076 wxFileDialog * openFileDialog = new wxFileDialog(this, wxT("Open diagram"), wxEmptyString, wxT(""), wxT("*.bbg"), wxOPEN | wxFILE_MUST_EXIST);
1077 if (openFileDialog->ShowModal() == wxID_OK)
1079 wxString filePath = openFileDialog->GetPath();
1080 wxString fileName = openFileDialog->GetFilename();
1081 OpenDiagram( crea::wx2std(filePath) , crea::wx2std(fileName) );
1085 //=========================================================================
1086 void wxGUIEditorGraphicBBS::OnClickBtnBox(wxCommandEvent& event)
1088 BlackBoxDescriptor *bbDes = _pkgBrowser->GetActualSelected();
1089 if (bbDes != NULL) {
1090 std::string typeName = bbDes->GetTypeName();
1091 std::string packageName = bbDes->GetPackage()->GetName();
1092 wxGEditorTabPanel *pnl = this->_tabsMgr->getActualTabPanel();
1094 wxVtkSceneManager *scn = pnl->getSceneManager();
1095 scn->createGBlackBox(50, 50, packageName, typeName);
1098 SaveTempActualDiagram("New Box");
1103 //=========================================================================
1105 void wxGUIEditorGraphicBBS::OnClickBtnExecutableBox(wxCommandEvent& event)
1108 wxGEditorTabPanel *pnl = this->_tabsMgr->getActualTabPanel();
1111 wxVtkSceneManager *scn = pnl->getSceneManager();
1112 if( scn->MakeBoxExecutable() )
1113 std::cout<<"DFCH: wxGUIEditorGraphicBBS::OnClickBtnExecutableBox...successful"<<std::endl;
1115 std::cout<<"DFCH: wxGUIEditorGraphicBBS::OnClickBtnExecutableBox...Error!!"<<std::endl;
1121 //=========================================================================
1122 void wxGUIEditorGraphicBBS::OnClickBtnComplexBox(wxCommandEvent& event)
1124 wxToolBar* toolbar = GetToolBar();
1125 bool temp = toolbar->GetToolState(ID_BTNCOMPLEXBOX);
1129 disableComplexBox();
1133 //=========================================================================
1135 void wxGUIEditorGraphicBBS::OnAddComplexBoxInput(wxCommandEvent& event)
1137 wxTextEntryDialog *nameDialog = new wxTextEntryDialog(this,
1138 wxT("Name of input port"));
1139 if (nameDialog->ShowModal() == wxID_OK)
1141 wxString fileName = nameDialog->GetValue();
1142 if (!fileName.IsEmpty())
1144 std::string portName = (const char*) (fileName.mb_str());
1145 if ( !boxNameExists(portName) )
1147 _tabsMgr->addActualDiagramComplexInputPort(portName);
1149 wxMessageDialog *dial = new wxMessageDialog(NULL,
1150 wxT("Impossible to create Box. The name already exists. Please provide another name"),
1151 wxT("Change name: name already exists"), wxOK | wxICON_EXCLAMATION | wxSTAY_ON_TOP);
1158 //=========================================================================
1159 void wxGUIEditorGraphicBBS::OnAddComplexBoxOutput(wxCommandEvent& event)
1161 wxTextEntryDialog *nameDialog = new wxTextEntryDialog(this,
1162 wxT("Name of output port"));
1163 if (nameDialog->ShowModal() == wxID_OK)
1165 wxString fileName = nameDialog->GetValue();
1166 if (!fileName.IsEmpty())
1168 std::string portName = (const char*) (fileName.mb_str());
1169 if ( !boxNameExists(portName) )
1171 _tabsMgr->addActualDiagramComplexOutputPort(portName);
1173 wxMessageDialog *dial = new wxMessageDialog(NULL,
1174 wxT("Impossible to create Box. The name already exists. Please provide another name"),
1175 wxT("Change name: name already exists"), wxOK | wxICON_EXCLAMATION | wxSTAY_ON_TOP);
1183 //=========================================================================
1184 void wxGUIEditorGraphicBBS::OnCopySelectedToComplexDiagram(
1185 wxCommandEvent& event)
1187 _tabsMgr->copySelectedBBoxesToComplexDiagram();
1190 //=========================================================================
1191 void wxGUIEditorGraphicBBS::OnHelpBBeditor(wxCommandEvent& event)
1193 printf("wxGUIEditorGraphicBBS::OnHelpBBeditor ....not implemented..\n");
1196 //=========================================================================
1197 void wxGUIEditorGraphicBBS::OnCreatePackage(wxCommandEvent& event)
1199 bbtkSystemTools::CreatePackage();
1202 //=========================================================================
1203 void wxGUIEditorGraphicBBS::OnCreateBlackBox(wxCommandEvent& event)
1205 bbtkSystemTools::CreateBlackBox();
1208 //=========================================================================
1209 void wxGUIEditorGraphicBBS::OnPlugPackage(wxCommandEvent& event)
1211 //DFGO2012 Plug Package functionnalities
1212 long style = wxDD_DEFAULT_STYLE | wxDD_DIR_MUST_EXIST;
1215 _T("Select package directory"),
1221 userResponse = FD->ShowModal();
1222 if(userResponse==wxID_OK)
1224 std::string path = wx2std (FD->GetPath()) ;
1226 std::string fname = path + "\\bbtkPackage";
1228 std::string fname = path + "/bbtkPackage";
1231 std::cout << "Path chosen = \"" << FD->GetPath() << "\"" << std::endl;
1232 if ( Utilities::FileExists( fname ) )
1235 f.open(fname.c_str());
1238 while(pname[0] == '#')
1240 getline(f, pname, '\n');
1245 bbtk::ConfigurationFile::GetInstance().AddPackagePathsAndWrite( path );
1247 DoRegeneratePackageDoc(pname);
1248 DoRegenerateBoxesLists();
1250 _pkgBrowser->RebuildList();
1252 wxMessageBox(_T("Package successfully plugged. Please restart bbEditor to see the new package in the package browser."),_T("Plug package"),wxOK | wxICON_INFORMATION);
1253 userResponse = wxID_CANCEL;
1257 std::string err = "The directory \"" + path + "\" does not contain a 'bbtkPackage' file.";
1260 err += "\nNote: If you are on Linux please select the folder and click \"Open\", don't enter in it.";
1264 wxMessageBox(crea::std2wx(err), _T("Plug package"),wxOK | wxICON_ERROR);
1265 // THE FOLLOWING LINE GIVES ERRORS BECAUSE IT IS NECESSARY TO USE std2wx
1266 //wxMessageBox( _T( err) , _T("Plug package"),wxOK | wxICON_ERROR);
1269 }while(userResponse != wxID_CANCEL);
1273 //=========================================================================
1274 void wxGUIEditorGraphicBBS::OnEditConfig(wxCommandEvent& event)
1276 std::string commandStr;
1277 std::string configFile = ConfigurationFile::GetInstance().Get_config_xml_full_path();
1279 commandStr = "notepad.exe ";
1281 commandStr = "gedit ";
1283 commandStr = commandStr + configFile;
1284 std::cout << "system: " << commandStr << std::endl;
1285 system ( commandStr.c_str() );
1288 //=========================================================================
1289 void wxGUIEditorGraphicBBS::OnShowHTMLDoc(wxCommandEvent& event)
1292 if (_helpHtmlBrowser != NULL){
1293 _frameAUIMgr->DetachPane(_helpHtmlBrowser);
1294 _helpHtmlBrowser->Destroy();
1296 initHelpHTMLBrowser();
1297 _frameAUIMgr->AddPane(_helpHtmlBrowser, wxAuiPaneInfo().Right().MinSize(200, 200));
1298 _frameAUIMgr->Update();
1299 refreshGUIControls();
1304 //=========================================================================
1305 void wxGUIEditorGraphicBBS::OnCreateIndex(wxCommandEvent& event)
1307 printf("EED wxGUIEditorGraphicBBS::OnCreateIndex ... not implemented ..\n");
1311 //=========================================================================
1312 void wxGUIEditorGraphicBBS::OnEditComplexBoxScript(wxCommandEvent& event)
1314 BlackBoxDescriptor *bbDes = _pkgBrowser->GetActualSelected();
1317 std::string packageName = bbDes->GetPackage()->GetName();
1318 std::string typeName = bbDes->GetTypeName();
1319 if (!TryToOpenScriptComplexBox(packageName ,typeName))
1321 wxMessageDialog windowMessage1(NULL,_T("This is not a ComplexBox script."), _T("Alert !"), wxOK);
1322 windowMessage1.ShowModal();
1327 //=========================================================================
1328 void wxGUIEditorGraphicBBS::OnExit(wxCommandEvent& event)
1333 Factory::Pointer wxGUIEditorGraphicBBS::GetBBTKFactory()
1335 if (_pkgBrowser==NULL)
1337 printf ("EED ERROR! wxGUIEditorGraphicBBS::GetBBTKFactory _pkgBrowser = NULL\n");
1339 return _pkgBrowser->GetFactory();
1342 //=========================================================================
1343 void wxGUIEditorGraphicBBS::enableComplexBox()
1345 _tabsMgr->setActualDiagramComplexBox(true);
1346 refreshGUIControls();
1349 //=========================================================================
1351 void wxGUIEditorGraphicBBS::disableComplexBox()
1353 _tabsMgr->setActualDiagramComplexBox(false);
1354 refreshGUIControls();
1357 //=========================================================================
1358 void wxGUIEditorGraphicBBS::setCurrentDiagramDescription(std::string description)
1360 _tabsMgr->SetDescription(description);
1363 //=========================================================================
1364 void wxGUIEditorGraphicBBS::setCurrentDiagramAuthor(std::string author)
1366 _tabsMgr->SetAuthor(author);
1369 //=========================================================================
1370 void wxGUIEditorGraphicBBS::setCurrentDiagramCategory(std::string category)
1372 _tabsMgr->SetCategory(category);
1375 //=========================================================================
1376 std::string wxGUIEditorGraphicBBS::getCurrentDiagramDescription()
1378 return _tabsMgr->GetDescription();
1381 //=========================================================================
1382 std::string wxGUIEditorGraphicBBS::getCurrentDiagramAuthor()
1384 return _tabsMgr->GetAuthor();
1387 //=========================================================================
1388 std::string wxGUIEditorGraphicBBS::getCurrentDiagramCategory()
1390 return _tabsMgr->GetCategory();
1394 //=========================================================================
1395 bool wxGUIEditorGraphicBBS::isCurrentDiagramComplexBox()
1397 return _tabsMgr->isActualDiagramComplexBox();
1401 //=========================================================================
1402 void wxGUIEditorGraphicBBS::OpenScript(std::string filePathNameBBS ,std::string boxType)
1404 std::string fileName = boxType+".bbg";
1405 std::string filePathNameBBG = filePathNameBBS;
1406 filePathNameBBG[ filePathNameBBG.length()-1 ] = 'g';
1408 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);
1409 windowMessage1.ShowModal();
1411 if ( Utilities::FileExists( filePathNameBBG ) )
1413 OpenDiagram( filePathNameBBG , fileName );
1415 if ( Utilities::FileExists( filePathNameBBS ) )
1417 OpenBBS( filePathNameBBS , fileName );
1419 wxMessageDialog windowMessage1(NULL,_T("..ERROR.. loading script bbg/bbs."), _T("Alert !"), wxOK);
1420 windowMessage1.ShowModal();
1427 //=========================================================================
1428 bool wxGUIEditorGraphicBBS::TryToOpenScriptApplication(std::string packageName ,std::string boxType)
1430 return TryToOpenScript(packageName ,boxType, true, false);
1433 //=========================================================================
1434 bool wxGUIEditorGraphicBBS::TryToOpenScriptComplexBox(std::string packageName ,std::string boxType)
1436 return TryToOpenScript(packageName ,boxType, false, true);
1440 //=========================================================================
1441 bool wxGUIEditorGraphicBBS::TryToOpenScript(std::string packageName ,std::string boxType,bool scriptApplication, bool scriptComplexBox)
1444 std::map< std::string, BlackBoxDescriptor::Pointer> mapDesc;
1445 BlackBoxDescriptor::Pointer descriptor;
1446 k = GetBBTKFactory()->GetPackage(packageName);
1447 mapDesc = k->GetDescriptorMap();
1448 descriptor = mapDesc[boxType];
1453 ((descriptor->IsTypeOfScript_Application()==true) && (scriptApplication==true))
1455 ((descriptor->IsTypeOfScript_ComplexBox()==true) && (scriptComplexBox==true))
1459 OpenScript(descriptor->GetScriptFileName(),boxType);
1465 } // EO namespace bbtk