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 wxFileDialog * openFileDialog = new wxFileDialog(this, wxT("Open BBS"), wxEmptyString, wxT("NewBBS"), wxT("*.bbs"), wxOPEN);
696 if (openFileDialog->ShowModal() == wxID_OK)
698 OpenBBS( crea::wx2std(openFileDialog->GetPath()) , crea::wx2std(openFileDialog->GetFilename()) );
702 if (openFileDialog->ShowModal() == wxID_OK)
704 wxString fileName = openFileDialog->GetPath();
705 _tabsMgr->addNewTab(openFileDialog->GetFilename());
706 bbtk::InterpreterBBS::Pointer I = bbtk::InterpreterBBS::New( this->_tabsMgr->getActualTabPanel()->getSceneManager(), _pkgBrowser->GetFactory());
707 // We tell the interpreter to throw exceptions on error
709 // Interpret the file supposed to define a box called 'Processing'
710 I->InterpretFile((const char*) (fileName.mb_str()));
712 refreshGUIControls();
716 //=========================================================================
717 void wxGUIEditorGraphicBBS::SaveActualBBS(std::string filename) {
720 //EED file.open(fileName.c_str());
721 file.open(filename.c_str());
722 std::string content = "";
723 // writing file header
724 content += "# ----------------------------------\n";
725 content += "# - BBTKGEditor v ";
726 content += _currentBBGversion; //VERSION
727 content += " BBS BlackBox Script\n";
731 content += "# ----------------------------------\n";
733 content += _tabsMgr->getActualDiagramBBS();
738 void wxGUIEditorGraphicBBS::OnSaveActualBBS(wxCommandEvent& event) {
739 wxFileDialog * saveFileDialog = new wxFileDialog(this,
740 wxT("Save actual BBS"), wxEmptyString, wxT("NewBBS"),
741 wxT("*.bbs"), wxSAVE | wxOVERWRITE_PROMPT);
742 if (saveFileDialog->ShowModal() == wxID_OK) {
743 wxString fileName = saveFileDialog->GetPath();
744 std::string filename = (const char*) (fileName.mb_str());
745 filename=CheckExtension (filename, ".bbs");
746 SaveActualBBS(filename);
751 void wxGUIEditorGraphicBBS::AskComplexBoxConfiguration() {
752 std::string cbName = _tabsMgr->GetCbName();
753 std::string paName = _tabsMgr->GetCbPackageName();
755 wxTextEntryDialog *cbNameDialog = new wxTextEntryDialog(this,
756 wxT("Complex Box name"));
757 wxTextEntryDialog *paNameDialog = new wxTextEntryDialog(this,
758 wxT("Package name"));
760 cbNameDialog->SetValue(wxString(cbName.c_str(), wxConvUTF8));
761 paNameDialog->SetValue(wxString(paName.c_str(), wxConvUTF8));
763 if (cbNameDialog->ShowModal() == wxID_OK) {
764 wxString complexboxname = cbNameDialog->GetValue();
765 cbName = (const char*) (complexboxname.mb_str());
768 if (paNameDialog->ShowModal() == wxID_OK) {
769 wxString packagename = paNameDialog->GetValue();
770 paName = (const char*) (packagename.mb_str());
773 _tabsMgr->SetCbName(cbName);
774 _tabsMgr->SetCbPackageName(paName);
777 //=========================================================================
779 void wxGUIEditorGraphicBBS::SaveActualComplexBox(std::string filename) {
781 file.open(filename.c_str());
783 std::string content = "";
785 // writing file header
786 content += "# ----------------------------------\n";
787 content += "# - BBTKGEditor v ";
788 content += _currentBBGversion;//VERSION
789 content += " BBS BlackBox Script (Complex Box)\n";
793 content += "# ----------------------------------\n";
795 content += _tabsMgr->getActualComplexBoxBBS();
800 //=========================================================================
802 void wxGUIEditorGraphicBBS::OnSaveActualComplexBox(wxCommandEvent& event) {
803 wxFileDialog * saveFileDialog = new wxFileDialog(this,
804 wxT("Save Complex Box BBS"), wxEmptyString,
805 _T("ComplexBoxName"), wxT("*.bbs"), wxSAVE
806 | wxOVERWRITE_PROMPT);
807 if (saveFileDialog->ShowModal() == wxID_OK) {
808 wxString fileName = saveFileDialog->GetPath();
809 std::string filename = (const char*) (fileName.mb_str());
810 filename=CheckExtension (filename, ".bbs");
811 SaveActualComplexBox(filename);
815 //=========================================================================
816 void wxGUIEditorGraphicBBS::SaveActualDiagram(std::string filename) {
818 file.open(filename.c_str());
820 std::string content = "";
822 // writing file header
823 content += "# ----------------------------------\n";
824 content += "# - BBTKGEditor v ";
825 content += _currentBBGversion; //VERSION
826 content += " BBG BlackBox Diagram file\n";
832 content += "# ----------------------------------\n";
834 content += "APP_START\n";
835 _tabsMgr->saveActualDiagram(content, filename); //DFCH
836 content += "APP_END\n";
841 //=========================================================================
842 void wxGUIEditorGraphicBBS::SaveTempActualDiagram(const std::string &action)
846 std::string name = _tabsMgr->GetNameTabPanel();
847 if(name[name.length() - 1] != '*')
849 _tabsMgr->SetNameTabPanel(wxString (name.c_str(), wxConvUTF8));
850 _tabsMgr->saveTempActualDiagram(action);
851 GetToolBar()->EnableTool(ID_UNDO,_tabsMgr->getUndoState(stundo));
852 GetToolBar()->SetToolShortHelp(ID_UNDO,crea::std2wx(stundo));
853 GetToolBar()->EnableTool(ID_REDO,_tabsMgr->getRedoState(stredo));
854 GetToolBar()->SetToolShortHelp(ID_REDO,crea::std2wx(stredo));
857 //=========================================================================
859 //The following method allows to save the current diagram asking the filename
861 void wxGUIEditorGraphicBBS::SaveCurrentDiagramAs() {
862 wxFileDialog * saveFileDialog = new wxFileDialog(this,
863 wxT("Save current diagram"), wxEmptyString, wxT("NewDiagram"),
864 wxT("*.bbg"), wxSAVE | wxOVERWRITE_PROMPT);
865 if (saveFileDialog->ShowModal() == wxID_OK) {
866 //_tabsMgr->SetNameTabPanel(saveFileDialog->GetFilename());
867 wxString pathfileName = saveFileDialog->GetPath();
868 std::string pathfilename = (const char*) (pathfileName.mb_str());
869 pathfilename=CheckExtension (pathfilename, ".bbg");
871 //modify the tab name accordingly
872 wxString fileName = saveFileDialog->GetFilename();
873 std::string filename = (const char*) (fileName.mb_str());
874 filename=CheckExtension (filename, ".bbg");
875 _tabsMgr->SetNameTabPanel( wxString (filename.c_str(), wxConvUTF8) );
877 std::string pathfilenamebbs = pathfilename;
878 pathfilenamebbs[pathfilenamebbs.length() - 1] = 's';
879 if (_tabsMgr->isActualDiagramComplexBox() == false) {
880 SaveActualDiagram(pathfilename);
881 SaveActualBBS(pathfilenamebbs);
883 AskComplexBoxConfiguration();
884 SaveActualDiagram(pathfilename);
885 SaveActualComplexBox(pathfilenamebbs);
886 } //if isActualDiagramComplexBox
887 } // if saveFileDialog
889 //=========================================================================
891 void wxGUIEditorGraphicBBS::OnSaveActualDiagram(wxCommandEvent& event) {
892 std::string pathfilename = _tabsMgr->GetCurrentTabPanelPath();
893 if (pathfilename.empty()) {
894 SaveCurrentDiagramAs();
896 std::string pathfilenamebbs = pathfilename;
897 pathfilenamebbs[pathfilenamebbs.length() - 1] = 's';
899 if (_tabsMgr->isActualDiagramComplexBox() == false) {
900 std::string name = _tabsMgr->GetNameTabPanel();
901 if(name[name.length() - 1] == '*')
903 name =name.substr(0,name.length()-1);
905 _tabsMgr->SetNameTabPanel(wxString (name.c_str(), wxConvUTF8));
906 SaveActualDiagram(pathfilename);
907 SaveActualBBS(pathfilenamebbs);
909 AskComplexBoxConfiguration();
910 SaveActualDiagram(pathfilename);
911 SaveActualComplexBox(pathfilenamebbs);
912 } //if isActualDiagramComplexBox
915 //=========================================================================
917 void wxGUIEditorGraphicBBS::OnSaveAsActualDiagram(wxCommandEvent& event) {
918 SaveCurrentDiagramAs();
921 //=========================================================================
922 void wxGUIEditorGraphicBBS::OnExportConsoleExecCommand(wxCommandEvent& event)
924 wxFileDialog * saveFileDialog = new wxFileDialog(this,
925 wxT("Export console command"), wxEmptyString, wxT("ConsoleApp.txt"),
926 wxT("*.txt;*.bbs;*.bbg;*.sh;*.bat"), wxSAVE | wxOVERWRITE_PROMPT);
928 if (saveFileDialog->ShowModal() == wxID_OK)
930 wxString fileName = saveFileDialog->GetPath();
931 std::string filename = (const char*) (fileName.mb_str());
932 filename=CheckExtension (filename, ".txt");
935 file.open(filename.c_str());
937 std::vector<std::string> extInputs = _tabsMgr->getActualTabPanel()->getSceneManager()->GetExternalInputsNames();
939 //TODO PUT IN A METHOD OF A FILES AND TEXT MANAGER CLASS !!!
940 //std::string inputsInCommentsWin="";
941 //std::string inputsInCommentsUnix="";
942 //std::string inputsInOneLineWin="";
943 std::string inputsInOneLineUnix="";
944 for (unsigned int i = 0; i < extInputs.size(); ++i)
946 /* No gusto la idea al jefe pero por si acaso ...
947 * RaC 2012 2nd HackFest
949 inputsInCommentsWin+="REM ";
950 inputsInCommentsWin+=extInputs[i];
951 inputsInCommentsWin+="=\"value\"\n";
952 inputsInCommentsUnix+="# ";
953 inputsInCommentsUnix+=extInputs[i];
954 inputsInCommentsUnix+="=\"value\"\n";
957 sprintf (buffer, "%d", (i+1));
958 inputsInOneLineWin+=extInputs[i];
959 inputsInOneLineWin+="=\"%";
960 inputsInOneLineWin+=buffer;
961 inputsInOneLineWin+="\" ";
963 inputsInOneLineUnix+=extInputs[i];
964 inputsInOneLineUnix+="=\"<value>\" ";
969 std::string content = "";
970 // writing file header
971 content += "# ----------------------------------\n";
972 content += "# - BBTKGEditor v ";
973 content += _currentBBGversion; //VERSION
974 content += " Console Commands to execute BBS application\n";
978 content += "# ----------------------------------\n";
981 content += "# Command to execute bbi\n";
982 content += "bbi <bbs_path> ";
983 content += inputsInOneLineUnix;
985 /* No gusto la idea al jefe pero por si acaso ...
986 * RaC 2012 2nd HackFest
987 content += "# For Windows (copy the following lines to a .bat file)\n";
988 content += "REM BBS application\n";
989 content += "REM Inputs:\n";
990 content += inputsInCommentsWin;
991 content += "REM To use previous inputs, put %$inputName% in the corresponding input of the execution bbi line\n";
992 content += "bbi applicationBBS.bbs ";
993 content += inputsInOneLineWin;
996 content += "# For Linux or Mac (copy the following lines to a .sh file)\n";
997 content += "#!/bin/bash\n";
998 content += "# BBS application\n";
999 content += "# Inputs:\n";
1000 content += inputsInCommentsUnix;
1001 content += "# To use previous inputs, put $inputName in the corresponding input of the execution bbi line\n";
1002 content += "bbi applicationBBS.bbs ";
1003 content += inputsInOneLineUnix;
1014 //=========================================================================
1016 void wxGUIEditorGraphicBBS::refreshGUIControls()
1020 //RaC2012 2ndHackFest Next line seems weird ... To keep in mind for other devels
1021 wxToolBar* toolbar = GetToolBar();
1022 if (_tabsMgr->isActualDiagramComplexBox())
1024 toolbar->ToggleTool(ID_BTNCOMPLEXBOX, true);
1025 //toolbar->EnableTool(ID_ADDCOMPLEXBOXINPUT, true); RaC2012 2nd HackFest
1026 toolbar->EnableTool(ID_ADDCOMPLEXBOXOUTPUT, true);
1028 GetMenuBar()->GetMenu(0)->Enable(ID_SAVE_AS_COMPLEXBOX, true);
1029 GetMenuBar()->GetMenu(0)->Enable(ID_SAVE_AS_BBS, false);
1030 GetMenuBar()->GetMenu(0)->Enable(ID_EXPORT_CONSOLEAPP, false);
1032 toolbar->ToggleTool(ID_BTNCOMPLEXBOX, false);
1033 //toolbar->EnableTool(ID_ADDCOMPLEXBOXINPUT, false); RaC2012 2nd HackFest
1034 toolbar->EnableTool(ID_ADDCOMPLEXBOXOUTPUT, false);
1036 GetMenuBar()->GetMenu(0)->Enable(ID_SAVE_AS_COMPLEXBOX, false);
1037 GetMenuBar()->GetMenu(0)->Enable(ID_SAVE_AS_BBS, true);
1038 GetMenuBar()->GetMenu(0)->Enable(ID_EXPORT_CONSOLEAPP, true);
1041 //RaC2012 2ndHackFest
1042 GetToolBar()->EnableTool(ID_EDITPROPERTIES,true);
1044 GetToolBar()->EnableTool(ID_UNDO,_tabsMgr->getUndoState(stundo));
1045 GetToolBar()->SetToolShortHelp(ID_UNDO,crea::std2wx(stundo));
1046 GetToolBar()->EnableTool(ID_REDO,_tabsMgr->getRedoState(stredo));
1047 GetToolBar()->SetToolShortHelp(ID_REDO,crea::std2wx(stredo));
1049 if (_tabsMgr->getNumActualSelectedObjects() > 0) {
1050 GetMenuBar()->GetMenu(1)->Enable(ID_COPY_TO_COMPLEXDIAGRAM, true);
1052 ///TODO Fix the possibility to say from the SceneManager to the GUI to refresh the options
1053 GetMenuBar()->GetMenu(1)->Enable(ID_COPY_TO_COMPLEXDIAGRAM, true);
1058 //=========================================================================
1060 void wxGUIEditorGraphicBBS::OnDeleteAllBoxesActualDiagram(wxCommandEvent& event)
1062 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);
1063 if (dial->ShowModal() == wxID_YES)
1065 _tabsMgr->deleteAllBoxesActualDiagram();
1069 //=========================================================================
1071 void wxGUIEditorGraphicBBS::OnCenterViewActualDiagram(wxCommandEvent& event)
1073 _tabsMgr->centerViewActualDiagram();
1076 //=========================================================================
1077 void wxGUIEditorGraphicBBS::OpenDiagram(std::string filePathName, std::string fileName)
1079 ifstream inputStream;
1080 inputStream.open(filePathName.c_str());
1081 assert(inputStream.good()); // fails
1083 if(_tabsMgr->FindTab(filePathName)!=-1) //RaC2012 avoid opening same diagram twice
1085 inputStream.close();
1086 printf("RaC: Diagram already opened\n");
1089 _tabsMgr->addNewTab( crea::std2wx(fileName) );
1090 _tabsMgr->loadDiagram(inputStream, filePathName);
1092 _tabsMgr->saveTempActualDiagram("load diagram");
1093 GetToolBar()->EnableTool(ID_UNDO, false);
1094 GetToolBar()->EnableTool(ID_UNDO, false);
1095 inputStream.close();
1096 refreshGUIControls();
1099 //=========================================================================
1101 void wxGUIEditorGraphicBBS::OnOpenDiagram(wxCommandEvent& event)
1103 wxFileDialog * openFileDialog = new wxFileDialog(this, wxT("Open diagram"), wxEmptyString, wxT(""), wxT("*.bbg"), wxOPEN | wxFILE_MUST_EXIST);
1104 if (openFileDialog->ShowModal() == wxID_OK)
1106 wxString filePath = openFileDialog->GetPath();
1107 wxString fileName = openFileDialog->GetFilename();
1108 OpenDiagram( crea::wx2std(filePath) , crea::wx2std(fileName) );
1112 //=========================================================================
1113 void wxGUIEditorGraphicBBS::OnClickBtnBox(wxCommandEvent& event)
1115 std::cout<<"wxGUIEditorGraphicBBS::OnClickBtnBox"<<std::endl;
1116 BlackBoxDescriptor *bbDes = _pkgBrowser->GetActualSelected();
1117 if (bbDes != NULL) {
1118 std::string typeName = bbDes->GetTypeName();
1119 std::string packageName = bbDes->GetPackage()->GetName();
1120 wxGEditorTabPanel *pnl = this->_tabsMgr->getActualTabPanel();
1122 wxVtkSceneManager *scn = pnl->getSceneManager();
1123 scn->createGBlackBox(50, 50, packageName, typeName);
1126 SaveTempActualDiagram("New Box");
1131 //=========================================================================
1133 void wxGUIEditorGraphicBBS::OnClickBtnExecutableBox(wxCommandEvent& event)
1136 wxGEditorTabPanel *pnl = this->_tabsMgr->getActualTabPanel();
1139 wxVtkSceneManager *scn = pnl->getSceneManager();
1140 if( scn->MakeBoxExecutable() )
1141 std::cout<<"DFCH: wxGUIEditorGraphicBBS::OnClickBtnExecutableBox...successful"<<std::endl;
1143 std::cout<<"DFCH: wxGUIEditorGraphicBBS::OnClickBtnExecutableBox...Error!!"<<std::endl;
1149 //=========================================================================
1150 void wxGUIEditorGraphicBBS::OnClickBtnComplexBox(wxCommandEvent& event)
1152 std::cout<<"wxGUIEditorGraphicBBS::OnClickBtnComplexBox"<<std::endl;
1153 wxToolBar* toolbar = GetToolBar();
1154 bool temp = toolbar->GetToolState(ID_BTNCOMPLEXBOX);
1158 disableComplexBox();
1162 //=========================================================================
1164 void wxGUIEditorGraphicBBS::OnAddComplexBoxInput(wxCommandEvent& event)
1166 wxTextEntryDialog *nameDialog = new wxTextEntryDialog(this,
1167 wxT("Name of input port"));
1168 if (nameDialog->ShowModal() == wxID_OK)
1170 wxString fileName = nameDialog->GetValue();
1171 if (!fileName.IsEmpty())
1173 std::string portName = (const char*) (fileName.mb_str());
1174 if ( !boxNameExists(portName) )
1176 _tabsMgr->addActualDiagramComplexInputPort(portName);
1178 wxMessageDialog *dial = new wxMessageDialog(NULL,
1179 wxT("Impossible to create Box. The name already exists. Please provide another name"),
1180 wxT("Change name: name already exists"), wxOK | wxICON_EXCLAMATION | wxSTAY_ON_TOP);
1187 //=========================================================================
1188 void wxGUIEditorGraphicBBS::OnAddComplexBoxOutput(wxCommandEvent& event)
1190 wxTextEntryDialog *nameDialog = new wxTextEntryDialog(this,
1191 wxT("Name of output port"));
1192 if (nameDialog->ShowModal() == wxID_OK)
1194 wxString fileName = nameDialog->GetValue();
1195 if (!fileName.IsEmpty())
1197 std::string portName = (const char*) (fileName.mb_str());
1198 if ( !boxNameExists(portName) )
1200 _tabsMgr->addActualDiagramComplexOutputPort(portName);
1202 wxMessageDialog *dial = new wxMessageDialog(NULL,
1203 wxT("Impossible to create Box. The name already exists. Please provide another name"),
1204 wxT("Change name: name already exists"), wxOK | wxICON_EXCLAMATION | wxSTAY_ON_TOP);
1212 //=========================================================================
1213 void wxGUIEditorGraphicBBS::OnCopySelectedToComplexDiagram(
1214 wxCommandEvent& event)
1216 _tabsMgr->copySelectedBBoxesToComplexDiagram();
1219 //=========================================================================
1220 void wxGUIEditorGraphicBBS::OnHelpBBeditor(wxCommandEvent& event)
1222 printf("wxGUIEditorGraphicBBS::OnHelpBBeditor ....not implemented..\n");
1225 //=========================================================================
1226 void wxGUIEditorGraphicBBS::OnCreatePackage(wxCommandEvent& event)
1228 bbtkSystemTools::CreatePackage();
1231 //=========================================================================
1232 void wxGUIEditorGraphicBBS::OnCreateBlackBox(wxCommandEvent& event)
1234 bbtkSystemTools::CreateBlackBox();
1237 //=========================================================================
1238 void wxGUIEditorGraphicBBS::OnPlugPackage(wxCommandEvent& event)
1240 //DFGO2012 Plug Package functionnalities
1241 long style = wxDD_DEFAULT_STYLE | wxDD_DIR_MUST_EXIST;
1244 _T("Select package directory"),
1250 userResponse = FD->ShowModal();
1251 if(userResponse==wxID_OK)
1253 std::string path = wx2std (FD->GetPath()) ;
1255 std::string fname = path + "\\bbtkPackage";
1257 std::string fname = path + "/bbtkPackage";
1260 std::cout << "Path chosen = \"" << FD->GetPath() << "\"" << std::endl;
1261 if ( Utilities::FileExists( fname ) )
1264 f.open(fname.c_str());
1267 while(pname[0] == '#')
1269 getline(f, pname, '\n');
1274 bbtk::ConfigurationFile::GetInstance().AddPackagePathsAndWrite( path );
1276 DoRegeneratePackageDoc(pname);
1277 DoRegenerateBoxesLists();
1279 _pkgBrowser->RebuildList();
1281 wxMessageBox(_T("Package successfully plugged. Please restart bbEditor to see the new package in the package browser."),_T("Plug package"),wxOK | wxICON_INFORMATION);
1282 userResponse = wxID_CANCEL;
1286 std::string err = "The directory \"" + path + "\" does not contain a 'bbtkPackage' file.";
1289 err += "\nNote: If you are on Linux please select the folder and click \"Open\", don't enter in it.";
1293 wxMessageBox(crea::std2wx(err), _T("Plug package"),wxOK | wxICON_ERROR);
1294 // THE FOLLOWING LINE GIVES ERRORS BECAUSE IT IS NECESSARY TO USE std2wx
1295 //wxMessageBox( _T( err) , _T("Plug package"),wxOK | wxICON_ERROR);
1298 }while(userResponse != wxID_CANCEL);
1302 //=========================================================================
1303 void wxGUIEditorGraphicBBS::OnEditConfig(wxCommandEvent& event)
1305 std::string commandStr;
1306 std::string configFile = ConfigurationFile::GetInstance().Get_config_xml_full_path();
1308 commandStr = "notepad.exe ";
1310 commandStr = "gedit ";
1312 commandStr = commandStr + configFile;
1313 std::cout << "system: " << commandStr << std::endl;
1314 system ( commandStr.c_str() );
1317 //=========================================================================
1318 void wxGUIEditorGraphicBBS::OnShowHTMLDoc(wxCommandEvent& event)
1321 if (_helpHtmlBrowser != NULL){
1322 _frameAUIMgr->DetachPane(_helpHtmlBrowser);
1323 _helpHtmlBrowser->Destroy();
1325 initHelpHTMLBrowser();
1326 _frameAUIMgr->AddPane(_helpHtmlBrowser, wxAuiPaneInfo().Right().MinSize(200, 200));
1327 _frameAUIMgr->Update();
1328 refreshGUIControls();
1333 //=========================================================================
1334 void wxGUIEditorGraphicBBS::OnCreateIndex(wxCommandEvent& event)
1336 printf("EED wxGUIEditorGraphicBBS::OnCreateIndex ... not implemented ..\n");
1340 //=========================================================================
1341 void wxGUIEditorGraphicBBS::OnEditComplexBoxScript(wxCommandEvent& event)
1343 BlackBoxDescriptor *bbDes = _pkgBrowser->GetActualSelected();
1346 std::string packageName = bbDes->GetPackage()->GetName();
1347 std::string typeName = bbDes->GetTypeName();
1348 if (!TryToOpenScriptComplexBox(packageName ,typeName))
1350 wxMessageDialog windowMessage1(NULL,_T("This is not a ComplexBox script."), _T("Alert !"), wxOK);
1351 windowMessage1.ShowModal();
1356 //=========================================================================
1357 void wxGUIEditorGraphicBBS::OnExit(wxCommandEvent& event)
1362 Factory::Pointer wxGUIEditorGraphicBBS::GetBBTKFactory()
1364 if (_pkgBrowser==NULL)
1366 printf ("EED ERROR! wxGUIEditorGraphicBBS::GetBBTKFactory _pkgBrowser = NULL\n");
1368 return _pkgBrowser->GetFactory();
1371 //=========================================================================
1372 void wxGUIEditorGraphicBBS::enableComplexBox()
1374 _tabsMgr->setActualDiagramComplexBox(true);
1375 refreshGUIControls();
1378 //=========================================================================
1380 void wxGUIEditorGraphicBBS::disableComplexBox()
1382 _tabsMgr->setActualDiagramComplexBox(false);
1383 refreshGUIControls();
1386 //=========================================================================
1387 void wxGUIEditorGraphicBBS::setCurrentDiagramDescription(std::string description)
1389 _tabsMgr->SetDescription(description);
1392 //=========================================================================
1393 void wxGUIEditorGraphicBBS::setCurrentDiagramAuthor(std::string author)
1395 _tabsMgr->SetAuthor(author);
1398 //=========================================================================
1399 void wxGUIEditorGraphicBBS::setCurrentDiagramCategory(std::string category)
1401 _tabsMgr->SetCategory(category);
1404 //=========================================================================
1405 void wxGUIEditorGraphicBBS::setCurrentDiagramMessageKind(std::string kind){
1406 _tabsMgr->SetMessageKind(kind);
1409 //=========================================================================
1410 void wxGUIEditorGraphicBBS::setCurrentDiagramMessageLevel(std::string level){
1411 _tabsMgr->SetMessageLevel(level);
1414 //=========================================================================
1415 std::string wxGUIEditorGraphicBBS::getCurrentDiagramDescription()
1417 return _tabsMgr->GetDescription();
1420 //=========================================================================
1421 std::string wxGUIEditorGraphicBBS::getCurrentDiagramAuthor()
1423 return _tabsMgr->GetAuthor();
1426 //=========================================================================
1427 std::string wxGUIEditorGraphicBBS::getCurrentDiagramCategory()
1429 return _tabsMgr->GetCategory();
1432 //=========================================================================
1433 std::string wxGUIEditorGraphicBBS::getCurrentDiagramMessageKind(){
1434 return _tabsMgr->GetMessageKind();
1437 //=========================================================================
1438 std::string wxGUIEditorGraphicBBS::getCurrentDiagramMessageLevel(){
1439 return _tabsMgr->GetMessageLevel();
1442 //=========================================================================
1443 bool wxGUIEditorGraphicBBS::isCurrentDiagramComplexBox()
1445 return _tabsMgr->isActualDiagramComplexBox();
1449 //=========================================================================
1450 void wxGUIEditorGraphicBBS::OpenScript(std::string filePathNameBBS ,std::string boxType)
1452 std::string fileName = boxType+".bbg";
1453 std::string filePathNameBBG = filePathNameBBS;
1454 filePathNameBBG[ filePathNameBBG.length()-1 ] = 'g';
1456 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);
1457 windowMessage1.ShowModal();
1459 if ( Utilities::FileExists( filePathNameBBG ) )
1461 OpenDiagram( filePathNameBBG , fileName );
1463 if ( Utilities::FileExists( filePathNameBBS ) )
1465 OpenBBS( filePathNameBBS , fileName );
1467 wxMessageDialog windowMessage1(NULL,_T("..ERROR.. loading script bbg/bbs."), _T("Alert !"), wxOK);
1468 windowMessage1.ShowModal();
1475 //=========================================================================
1476 bool wxGUIEditorGraphicBBS::TryToOpenScriptApplication(std::string packageName ,std::string boxType)
1478 return TryToOpenScript(packageName ,boxType, true, false);
1481 //=========================================================================
1482 bool wxGUIEditorGraphicBBS::TryToOpenScriptComplexBox(std::string packageName ,std::string boxType)
1484 return TryToOpenScript(packageName ,boxType, false, true);
1488 //=========================================================================
1489 bool wxGUIEditorGraphicBBS::TryToOpenScript(std::string packageName ,std::string boxType,bool scriptApplication, bool scriptComplexBox)
1492 std::map< std::string, BlackBoxDescriptor::Pointer> mapDesc;
1493 BlackBoxDescriptor::Pointer descriptor;
1494 k = GetBBTKFactory()->GetPackage(packageName);
1495 mapDesc = k->GetDescriptorMap();
1496 descriptor = mapDesc[boxType];
1501 ((descriptor->IsTypeOfScript_Application()==true) && (scriptApplication==true))
1503 ((descriptor->IsTypeOfScript_ComplexBox()==true) && (scriptComplexBox==true))
1507 OpenScript(descriptor->GetScriptFileName(),boxType);
1513 } // EO namespace bbtk