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 wxBitmap bmp_showTree(showTree_xpm);
145 wxToolBar *toolbar = new wxToolBar(this, wxID_ANY);
147 //Adds a tool btn to the toolbar
148 toolbar->AddTool(ID_NEW, _T("New"), bmp_new, wxNullBitmap, wxITEM_NORMAL,
149 _T("New tab"), _T("Create a new panel tab"));
150 toolbar->AddTool(ID_OPEN, _T("Open diagram"), bmp_open, wxNullBitmap,
151 wxITEM_NORMAL, _T("Open a diagram"), _T("Open a diagram"));
152 toolbar->AddTool(ID_SAVE_DIAGRAM, _T("Save Diagram"), bmp_save,
153 wxNullBitmap, wxITEM_NORMAL, _T("Saves the current diagram"),
154 _T("Saves the current diagram")); //DFCH
155 //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
156 toolbar->AddTool(ID_RUN, _T("Run"), bmp_run, wxNullBitmap, wxITEM_NORMAL,
157 _T("Execute actual diagram"), _T("Execute actual diagram"));
158 toolbar->AddTool(ID_DELETEALL, _T("Delete all"), bmp_delete, wxNullBitmap,
159 wxITEM_NORMAL, _T("Delete all boxes"), _T("Delete all boxes"));
160 toolbar->AddTool(ID_CENTERVIEW, _T("Center view"), bmp_centerview,
161 wxNullBitmap, wxITEM_NORMAL, _T("Center view"), _T("Center view"));
162 toolbar->AddSeparator();
163 toolbar->AddTool(ID_BTNBOX, _T("New Box"), bmp_box, wxNullBitmap,
164 wxITEM_NORMAL, _T("New Box"), _T("Nex Box"));
165 toolbar->AddSeparator();
166 toolbar->AddTool(ID_BTEXECUTABLEBOX, _T("Select as executable Box"),
167 bmp_executablebox, wxNullBitmap, wxITEM_NORMAL,
168 _T("Select as executable Box"), _T("Select as executable Box"));
169 toolbar->AddSeparator();
170 toolbar->AddTool(ID_BTNCOMPLEXBOX, _T("Complex box"), complexbox_xpm,
171 wxNullBitmap, wxITEM_NORMAL, _T("Complex box"), _T("Complex box"));
172 toolbar->SetToggle(ID_BTNCOMPLEXBOX, true);
174 // RaC 2012 2nd HackFest - Now Complex inputs are any external input
175 // toolbar->AddTool(ID_ADDCOMPLEXBOXINPUT, _T("Add input to Complex box"),
176 // bmp_complexinputport, wxNullBitmap, wxITEM_NORMAL,
177 // _T("Add input to Complex box"), _T("Add input to Complex box"));
178 toolbar->AddTool(ID_ADDCOMPLEXBOXINPUT, _T("Add external input (Complex box or console app)"),
179 bmp_complexinputport, wxNullBitmap, wxITEM_NORMAL,
180 _T("Add external input (Complex box or console app)"), _T("Add external input (Complex box or console app)"));
182 toolbar->AddTool(ID_ADDCOMPLEXBOXOUTPUT, _T("Add output to Complex box"),
183 bmp_complexoutputport, wxNullBitmap, wxITEM_NORMAL,
184 _T("Add output Complex box"), _T("Add output Complex box"));
186 // toolbar->EnableTool(ID_ADDCOMPLEXBOXINPUT, false); RaC2012 2nd HackFest
187 toolbar->EnableTool(ID_ADDCOMPLEXBOXINPUT, true);
189 toolbar->EnableTool(ID_ADDCOMPLEXBOXOUTPUT, false);
190 toolbar->AddSeparator();
191 toolbar->AddTool(ID_UNDO, _T("Undo"),bmp_undo, wxNullBitmap, wxITEM_NORMAL, _T("Undo"), _T("Undo"));
192 toolbar->AddTool(ID_REDO, _T("Redo"),bmp_redo, wxNullBitmap, wxITEM_NORMAL, _T("Redo"), _T("Redo"));
193 toolbar->AddSeparator();
194 toolbar->AddTool(ID_EDITPROPERTIES, _T("Edit diagram properties"),bmp_editProperties, wxNullBitmap, wxITEM_NORMAL, _T("Edit diagram properties"), _T("Edit diagram properties"));
195 toolbar->EnableTool(ID_EDITPROPERTIES, false);
197 toolbar->AddTool(ID_SHOWTREE, _T("Show tree"),bmp_showTree, wxNullBitmap, wxITEM_NORMAL, _T("Show tree"), _T("Show tree"));
199 toolbar->EnableTool(ID_UNDO, false);
200 toolbar->EnableTool(ID_REDO, false);
201 toolbar->SetMargins(2, 2);
206 // connect command event handlers
208 Connect(ID_NEW, wxEVT_COMMAND_TOOL_CLICKED,
209 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnCreateNewTab));
210 Connect(ID_OPEN, wxEVT_COMMAND_TOOL_CLICKED,
211 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnOpenDiagram));
212 Connect(ID_SAVE_DIAGRAM, wxEVT_COMMAND_TOOL_CLICKED,
213 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnSaveActualDiagram)); //DFCH
214 Connect(ID_SAVE_AS_DIAGRAM, wxEVT_COMMAND_TOOL_CLICKED,
215 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnSaveAsActualDiagram)); //DFCH
218 wxEVT_COMMAND_TOOL_CLICKED,
219 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnExecuteActualDiagram));
222 wxEVT_COMMAND_TOOL_CLICKED,
223 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnDeleteAllBoxesActualDiagram));
226 wxEVT_COMMAND_TOOL_CLICKED,
227 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnCenterViewActualDiagram));
228 Connect(ID_BTNBOX, wxEVT_COMMAND_TOOL_CLICKED,
229 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnClickBtnBox));
232 wxEVT_COMMAND_TOOL_CLICKED,
233 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnClickBtnExecutableBox));
234 Connect(ID_BTNCOMPLEXBOX, wxEVT_COMMAND_TOOL_CLICKED,
235 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnClickBtnComplexBox));
236 Connect(ID_ADDCOMPLEXBOXINPUT, wxEVT_COMMAND_TOOL_CLICKED,
237 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnAddComplexBoxInput));
238 Connect(ID_ADDCOMPLEXBOXOUTPUT, wxEVT_COMMAND_TOOL_CLICKED,
239 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnAddComplexBoxOutput));
240 Connect(ID_UNDO,wxEVT_COMMAND_TOOL_CLICKED, wxCommandEventHandler(wxGUIEditorGraphicBBS::OnUndo));
241 Connect(ID_REDO,wxEVT_COMMAND_TOOL_CLICKED, wxCommandEventHandler(wxGUIEditorGraphicBBS::OnRedo));
242 Connect(ID_CHANGENAME, wxEVT_COMMAND_RIGHT_CLICK, wxCommandEventHandler(wxGUIEditorGraphicBBS::OnChangeName));
243 Connect(ID_EDITPROPERTIES,wxEVT_COMMAND_TOOL_CLICKED, wxCommandEventHandler(wxGUIEditorGraphicBBS::OnEditDiagramProperties));
244 Connect(ID_SHOWTREE,wxEVT_COMMAND_TOOL_CLICKED, wxCommandEventHandler(wxGUIEditorGraphicBBS::OnShowTree));
247 //=========================================================================
248 void wxGUIEditorGraphicBBS::initHelpHTMLBrowser() {
250 _helpHtmlBrowser = new WxGUIHtmlBrowser(this, wxSize(200, 0));
256 //=========================================================================
257 void wxGUIEditorGraphicBBS::initMenu() {
258 // Create File menu and its items
259 wxMenu *fileMenu = new wxMenu();
260 fileMenu->Append(ID_NEW, _T("New diagram"), _T("New"));
261 fileMenu->Append(ID_SAVE_DIAGRAM, _T("Save Diagram"), _T("Save Diagram")); //DFCH
262 fileMenu->Append(ID_SAVE_AS_DIAGRAM, _T("Save Diagram As"),
263 _T("Save Diagram As")); //DFCH
264 fileMenu->Append(ID_OPEN_BBS, _T("Open BBS"), _T("Open BBS"));
266 fileMenu->Append(ID_OPEN, _T("Open a diagram"), _T("Open a diagram"));
267 fileMenu->Append(ID_SAVE_AS_BBS, _T("Save BBS"), _T("Save BBS"));
268 fileMenu->Append(ID_SAVE_AS_COMPLEXBOX, _T("Save complex box"),
269 _T("Save complex box"));
270 fileMenu->Append(ID_EXPORT_CONSOLEAPP, _T("Export console commands"),
271 _T("Export console execution commands"));
272 fileMenu->Append(wxID_EXIT, _T("E&xit"), _T("Exit"));
274 Connect(ID_NEW, wxEVT_COMMAND_MENU_SELECTED,
275 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnCreateNewTab));
276 Connect(ID_SAVE_DIAGRAM, wxEVT_COMMAND_MENU_SELECTED,
277 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnSaveActualDiagram)); //DFCH
278 Connect(ID_SAVE_AS_DIAGRAM, wxEVT_COMMAND_MENU_SELECTED,
279 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnSaveAsActualDiagram));
280 Connect(ID_OPEN_BBS, wxEVT_COMMAND_MENU_SELECTED,
281 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnOpenBBS));
282 Connect(ID_SAVE_AS_BBS, wxEVT_COMMAND_MENU_SELECTED,
283 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnSaveActualBBS));
284 Connect( ID_SAVE_AS_COMPLEXBOX, wxEVT_COMMAND_MENU_SELECTED,
285 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnSaveActualComplexBox));
286 Connect( ID_EXPORT_CONSOLEAPP, wxEVT_COMMAND_MENU_SELECTED,
287 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnExportConsoleExecCommand));
288 Connect(wxID_EXIT, wxEVT_COMMAND_MENU_SELECTED,
289 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnExit));
291 // Create Edit menu and its items
292 wxMenu *editMenu = new wxMenu;
293 editMenu->Append(ID_COPY_TO_COMPLEXDIAGRAM, _T("Copy selected to complex box"), _T("Creates a new complex box diagram with selected boxes"));
294 editMenu->Append(ID_EDIT_COMPLEXBOX_SCRIPT, _T("Edit Complex Box"), _T("Edit Complex Box"));
295 Connect( ID_COPY_TO_COMPLEXDIAGRAM, wxEVT_COMMAND_MENU_SELECTED,
296 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnCopySelectedToComplexDiagram));
297 Connect( ID_EDIT_COMPLEXBOX_SCRIPT, wxEVT_COMMAND_MENU_SELECTED,
298 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnEditComplexBoxScript));
300 // Create Help menu and its items
301 wxMenu *helpMenu = new wxMenu;
302 helpMenu->Append(wxID_ABOUT, _T("&About..."), _T("About"));
303 helpMenu->Append(ID_HELP_BBEDITOR, _T("&Help..."), _T("Help"));
304 Connect(ID_HELP_BBEDITOR, wxEVT_COMMAND_MENU_SELECTED,
305 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnHelpBBeditor));
308 wxMenu *menuTools = new wxMenu;
309 menuTools->Append(ID_bbEditor_Tool_Menu_CreatePackage,
310 _T("Create &package") );
311 menuTools->Append(ID_bbEditor_Tool_Menu_CreateBlackBox,
312 _T("Create &blackbox") );
313 menuTools->Append(ID_bbEditor_Tool_Menu_PlugPackage, _T("Plug package") );
314 menuTools->Append(ID_bbEditor_Tool_Menu_EditConfig, _T("&Edit bbtk config") );
315 menuTools->Append(ID_bbEditor_Tool_Menu_ShowHTMLDoc,
316 _T("Show &HTML documentation") );
317 menuTools->Append(ID_bbEditor_Tool_Menu_CreateIndex, _T("&Generate index") );
319 Connect(ID_bbEditor_Tool_Menu_CreatePackage, wxEVT_COMMAND_MENU_SELECTED,
320 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnCreatePackage));
321 Connect(ID_bbEditor_Tool_Menu_CreateBlackBox, wxEVT_COMMAND_MENU_SELECTED,
322 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnCreateBlackBox));
323 Connect(ID_bbEditor_Tool_Menu_PlugPackage, wxEVT_COMMAND_MENU_SELECTED,
324 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnPlugPackage));
325 Connect(ID_bbEditor_Tool_Menu_EditConfig, wxEVT_COMMAND_MENU_SELECTED,
326 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnEditConfig));
327 Connect(ID_bbEditor_Tool_Menu_ShowHTMLDoc, wxEVT_COMMAND_MENU_SELECTED,
328 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnShowHTMLDoc));
329 Connect(ID_bbEditor_Tool_Menu_CreateIndex, wxEVT_COMMAND_MENU_SELECTED,
330 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnCreateIndex));
332 // Append the created menu to the menu bar
333 wxMenuBar *menuBar = new wxMenuBar();
334 menuBar->Append(fileMenu, _T("&File") );
335 menuBar->Append(editMenu, _T("&Edit") );
336 menuBar->Append(menuTools, _T("&Tool") );
337 menuBar->Append(helpMenu, _T("&Help") );
339 // Attach this menu bar to the frame
343 //=========================================================================
344 void wxGUIEditorGraphicBBS::initTabPanelsManager()
346 _notebook = new wxAuiNotebook(this, wxID_NOTEBOOK, wxDefaultPosition,
347 wxDefaultSize, wxAUI_NB_TOP | wxAUI_NB_TAB_MOVE
348 | wxAUI_NB_CLOSE_ON_ACTIVE_TAB | wxAUI_NB_TAB_FIXED_WIDTH
349 | wxAUI_NB_WINDOWLIST_BUTTON);
350 _tabsMgr = new wxTabPanelsManager(this);
351 _frameAUIMgr->AddPane(_notebook, wxAuiPaneInfo().CenterPane());
354 //=========================================================================
355 void wxGUIEditorGraphicBBS::initPackageBrowser()
357 _pkgBrowser = new WxGUIPackageBrowser2(this);
358 _pkgBrowser->IncludeAll();
359 _frameAUIMgr->AddPane(_pkgBrowser, wxAuiPaneInfo().Left().MinSize(30, 500).BestSize(750,500).CloseButton(false));
362 //================================================================
364 void wxGUIEditorGraphicBBS::DoRegeneratePackageDoc(const std::string& pack)
366 std::string mess("Regenerating doc for package '");
370 mess = "Regenerating doc for all packages";
373 mess += " ... please wait";
375 SetStatusText(std2wx(mess));
383 command += ConfigurationFile::GetInstance().Get_bin_path();
384 command += ConfigurationFile::GetInstance().Get_file_separator();
385 command += "bbRegeneratePackageDoc";
390 command += " " + pack + " -q";
391 bbtkMessage("debug",1,"Executing system command '"<<command<<"'"<<std::endl);
393 if (!system(command.c_str())) {
394 SetStatusText(_T("Done !"));
396 wxMessageBox(_T("Done !"),_T("Regenerate package '")
397 +std2wx(pack)+_T("' doc"),
398 wxOK | wxICON_INFORMATION);
401 SetStatusText(_T("Done !"));
402 wxString err(_T("An error occured while running '"));
403 err += bbtk::std2wx(command) + _T("'");
404 wxMessageBox(err, _T("Regenerate package doc"), wxOK | wxICON_ERROR);
408 //================================================================
409 void wxGUIEditorGraphicBBS::DoRegenerateBoxesLists() {
410 SetStatusText(_T("Regenerating boxes lists ... please wait"));
417 command += ConfigurationFile::GetInstance().Get_bin_path();
418 command += ConfigurationFile::GetInstance().Get_file_separator();
419 command += "bbRegenerateBoxesLists";
426 bbtkMessage("debug",1,"Executing system command '"<<command<<"'"<<std::endl);
428 if (!system(command.c_str())) {
429 SetStatusText(_T("Done !"));
431 wxMessageBox(_T("Done !"),_T("Regenerate boxes lists"),
432 wxOK | wxICON_INFORMATION);
435 SetStatusText(_T("Done !"));
436 wxString err(_T("An error occured while running '"));
437 err += bbtk::std2wx(command) + _T("'");
438 wxMessageBox(err, _T("Regenerate boxes lists"), wxOK | wxICON_ERROR);
442 //================================================================
443 void wxGUIEditorGraphicBBS::RegenerateAll() {
444 DoRegeneratePackageDoc("-a");
445 DoRegenerateBoxesLists();
448 //================================================================
450 wxAuiNotebook* wxGUIEditorGraphicBBS::getAuiNotebook() {
454 //================================================================
456 void wxGUIEditorGraphicBBS::displayBlackBoxInfo(std::string packageName, std::string boxName)
458 if (_actualPkgBrowserPkgName != packageName || _actualPkgBrowserBoxName != boxName)
461 _actualPkgBrowserPkgName = packageName;
462 _actualPkgBrowserBoxName = boxName;
464 //EED 15 oct 2012 BlackBoxDescriptor::Pointer descriptor = GObjectsMVCFactory::getInstance()->getBlackBoxDescriptor(packageName, boxName);
467 //EED ComplexBlackBoxDescriptor::Pointer descriptor;
468 BlackBoxDescriptor::Pointer descriptor;
470 std::map< std::string, BlackBoxDescriptor::Pointer> mapDesc;
471 k = _pkgBrowser->GetFactory()->GetPackage(_actualPkgBrowserPkgName);
472 mapDesc = k->GetDescriptorMap();
473 descriptor = mapDesc[_actualPkgBrowserBoxName];
479 descriptor->GetBoxesInside(tree, 0);
482 //std::vector<std::string> boxesDiagram = _sceneM->boxesDiagram;
483 //for(int i=0;i<boxesDiagram.size();i++){
484 // std::cout<<"caja: "<<boxesDiagram[i]<<std::endl;
487 _actualPkgBrowserPkgName = "";
488 _actualPkgBrowserBoxName = "";
492 BlackBoxDescriptor::Pointer descriptor;
493 std::map< std::string, BlackBoxDescriptor::Pointer> mapDesc;
494 k = _pkgBrowser->GetFactory()->GetPackage(packageName);
495 std::vector<std::string> temp;
496 _pkgBrowser->GetFactory()->GetPackagesList(temp);
497 for(int ii = 0 ; ii < temp.size() ; ii++)
499 std::cout << " packs "<< temp[ii]<< std::endl;
501 mapDesc = k->GetDescriptorMap();
502 descriptor = mapDesc[boxName];
504 _pkgBrowser->WxGUIBlackBoxListUserOnSelected(descriptor.get());
508 //=========================================================================
510 void wxGUIEditorGraphicBBS::editBlackBox(GBlackBoxModel *bbmodel) {
511 wxBlackBoxEditionDialog* dialog =
512 new wxBlackBoxEditionDialog(this, bbmodel);
516 //=========================================================================
518 bool wxGUIEditorGraphicBBS::boxNameExists(std::string boxname) {
520 return this->_tabsMgr->getActualTabPanel()->getSceneManager()->boxExist(boxname);
523 //=========================================================================
525 void wxGUIEditorGraphicBBS::updateStatusBar(std::string textStatus) {
526 SetStatusText(crea::std2wx(textStatus));
529 //=========================================================================
531 void wxGUIEditorGraphicBBS::executeScript(std::string script) {
532 std::string separator =
533 ConfigurationFile::GetInstance().Get_file_separator();
534 std::string dir = ConfigurationFile::GetInstance().Get_default_temp_dir();
535 std::string filename = dir + separator + "tmp_bbtk.bbs";
538 tempFile.open(filename.c_str());
542 std::string command = "";
545 command += "start /b ";
548 // command += "\""+ crea::System::GetExecutablePath();
550 // command += separator + "../../../bbi.app/Contents/MacOS";
554 command += "\"" + filename + "\"";
560 printf("RaC wxGUIEditorGraphicBBS::executeScript %s \n", command.c_str());
561 system(command.c_str());
564 //=========================================================================
565 std::string wxGUIEditorGraphicBBS::CheckExtension(std::string filename, std::string extension) {
566 if(filename.size() > extension.size() ){
567 if( (filename.compare(filename.size()-extension.size(), extension.size(),extension)) !=0 ){
568 filename.append(extension);
571 filename.append(extension);
575 //=========================================================================
577 //=========================================================================
579 void wxGUIEditorGraphicBBS::OnCreateNewTab(wxCommandEvent& event) {
580 _tabsMgr->addNewTab();
581 refreshGUIControls();
584 void wxGUIEditorGraphicBBS::OnUndo(wxCommandEvent& event) {
585 unsigned short disable;
589 _tabsMgr->loadTempDiagram(0);
590 disable = _tabsMgr->getUndoState(stundo);
593 std::string name = _tabsMgr->GetNameTabPanel();
594 if(name[name.length() - 1] == '*')
596 name =name.substr(0,name.length()-1);
598 _tabsMgr->SetNameTabPanel(wxString (name.c_str(), wxConvUTF8));
601 GetToolBar()->EnableTool(ID_UNDO,disable);
602 GetToolBar()->SetToolShortHelp(ID_UNDO,crea::std2wx(stundo));
603 GetToolBar()->EnableTool(ID_REDO,_tabsMgr->getRedoState(stredo));
604 GetToolBar()->SetToolShortHelp(ID_REDO,crea::std2wx(stredo));
605 refreshGUIControls();
608 //=========================================================================
610 void wxGUIEditorGraphicBBS::OnRedo(wxCommandEvent& event) {
611 unsigned short disable;
615 _tabsMgr->loadTempDiagram(1);
616 std::string name = _tabsMgr->GetNameTabPanel();
617 if(name[name.length() - 1] != '*')
619 _tabsMgr->SetNameTabPanel(wxString (name.c_str(), wxConvUTF8));
620 GetToolBar()->EnableTool(ID_UNDO,_tabsMgr->getUndoState(stundo));
621 GetToolBar()->SetToolShortHelp(ID_UNDO,crea::std2wx(stundo));
622 GetToolBar()->EnableTool(ID_REDO,_tabsMgr->getRedoState(stredo));
623 GetToolBar()->SetToolShortHelp(ID_REDO,crea::std2wx(stredo));
624 refreshGUIControls();
627 void wxGUIEditorGraphicBBS::OnChangeName(wxCommandEvent& event){
629 //=========================================================================
631 void wxGUIEditorGraphicBBS::OnShowTree(wxCommandEvent& event){
632 std::cout << "wxGUIEditorGraphicBBS::OnShowTree"<<std::endl;
633 if (_actualPkgBrowserPkgName !="" || _actualPkgBrowserBoxName != "")
636 //EED ComplexBlackBoxDescriptor::Pointer descriptor;
637 BlackBoxDescriptor::Pointer descriptor;
639 std::map< std::string, BlackBoxDescriptor::Pointer> mapDesc;
640 k = _pkgBrowser->GetFactory()->GetPackage(_actualPkgBrowserPkgName);
641 mapDesc = k->GetDescriptorMap();
642 descriptor = mapDesc[_actualPkgBrowserBoxName];
648 descriptor->GetBoxesInside(tree, 0);
650 _actualPkgBrowserPkgName = "";
651 _actualPkgBrowserBoxName = "";
655 std::cout<<"Select a Box"<<std::endl;
659 //=========================================================================
661 void wxGUIEditorGraphicBBS::OnEditDiagramProperties(wxCommandEvent& event)
663 wxDiagramPropertiesEditionDialog* dialog =
664 new wxDiagramPropertiesEditionDialog(this, tree);
668 //=========================================================================
670 void wxGUIEditorGraphicBBS::OnExecuteActualDiagram(wxCommandEvent& event) {
671 std::string script1 = _tabsMgr->getActualDiagramBBS(true);
672 cout << endl << "RaC wxGUIEditorGraphicBBS::executeActualDiagram SCRIPT"
674 cout << script1 << endl;
676 std::string script2 = _tabsMgr->getActualDiagramBBS(false);
677 executeScript(script2);
681 //=========================================================================
682 void wxGUIEditorGraphicBBS::OpenBBS(std::string filePathName, std::string fileName)
684 _tabsMgr->addNewTab( crea::std2wx(fileName) );
685 bbtk::InterpreterBBS::Pointer I = bbtk::InterpreterBBS::New( this->_tabsMgr->getActualTabPanel()->getSceneManager(), _pkgBrowser->GetFactory());
686 // We tell the interpreter to throw exceptions on error
688 // Interpret the file supposed to define a box called 'Processing'
689 I->InterpretFile( filePathName );
690 refreshGUIControls();
693 //=========================================================================
695 //=========================================================================
696 void wxGUIEditorGraphicBBS::OnOpenBBS(wxCommandEvent& event)
698 wxFileDialog * openFileDialog = new wxFileDialog(this, wxT("Open BBS"), wxEmptyString, wxT("NewBBS"), wxT("*.bbs"), wxOPEN);
700 if (openFileDialog->ShowModal() == wxID_OK)
702 OpenBBS( crea::wx2std(openFileDialog->GetPath()) , crea::wx2std(openFileDialog->GetFilename()) );
706 if (openFileDialog->ShowModal() == wxID_OK)
708 wxString fileName = openFileDialog->GetPath();
709 _tabsMgr->addNewTab(openFileDialog->GetFilename());
710 bbtk::InterpreterBBS::Pointer I = bbtk::InterpreterBBS::New( this->_tabsMgr->getActualTabPanel()->getSceneManager(), _pkgBrowser->GetFactory());
711 // We tell the interpreter to throw exceptions on error
713 // Interpret the file supposed to define a box called 'Processing'
714 I->InterpretFile((const char*) (fileName.mb_str()));
716 refreshGUIControls();
720 //=========================================================================
721 void wxGUIEditorGraphicBBS::SaveActualBBS(std::string filename) {
724 //EED file.open(fileName.c_str());
725 file.open(filename.c_str());
726 std::string content = "";
727 // writing file header
728 content += "# ----------------------------------\n";
729 content += "# - BBTKGEditor v ";
730 content += _currentBBGversion; //VERSION
731 content += " BBS BlackBox Script\n";
735 content += "# ----------------------------------\n";
737 content += _tabsMgr->getActualDiagramBBS();
742 void wxGUIEditorGraphicBBS::OnSaveActualBBS(wxCommandEvent& event) {
743 wxFileDialog * saveFileDialog = new wxFileDialog(this,
744 wxT("Save actual BBS"), wxEmptyString, wxT("NewBBS"),
745 wxT("*.bbs"), wxSAVE | wxOVERWRITE_PROMPT);
746 if (saveFileDialog->ShowModal() == wxID_OK) {
747 wxString fileName = saveFileDialog->GetPath();
748 std::string filename = (const char*) (fileName.mb_str());
749 filename=CheckExtension (filename, ".bbs");
750 SaveActualBBS(filename);
755 void wxGUIEditorGraphicBBS::AskComplexBoxConfiguration() {
756 std::string cbName = _tabsMgr->GetCbName();
757 std::string paName = _tabsMgr->GetCbPackageName();
759 wxTextEntryDialog *cbNameDialog = new wxTextEntryDialog(this,
760 wxT("Complex Box name"));
761 wxTextEntryDialog *paNameDialog = new wxTextEntryDialog(this,
762 wxT("Package name"));
764 cbNameDialog->SetValue(wxString(cbName.c_str(), wxConvUTF8));
765 paNameDialog->SetValue(wxString(paName.c_str(), wxConvUTF8));
767 if (cbNameDialog->ShowModal() == wxID_OK) {
768 wxString complexboxname = cbNameDialog->GetValue();
769 cbName = (const char*) (complexboxname.mb_str());
772 if (paNameDialog->ShowModal() == wxID_OK) {
773 wxString packagename = paNameDialog->GetValue();
774 paName = (const char*) (packagename.mb_str());
777 _tabsMgr->SetCbName(cbName);
778 _tabsMgr->SetCbPackageName(paName);
781 //=========================================================================
783 void wxGUIEditorGraphicBBS::SaveActualComplexBox(std::string filename) {
785 file.open(filename.c_str());
787 std::string content = "";
789 // writing file header
790 content += "# ----------------------------------\n";
791 content += "# - BBTKGEditor v ";
792 content += _currentBBGversion;//VERSION
793 content += " BBS BlackBox Script (Complex Box)\n";
797 content += "# ----------------------------------\n";
799 content += _tabsMgr->getActualComplexBoxBBS();
804 //=========================================================================
806 void wxGUIEditorGraphicBBS::OnSaveActualComplexBox(wxCommandEvent& event) {
807 wxFileDialog * saveFileDialog = new wxFileDialog(this,
808 wxT("Save Complex Box BBS"), wxEmptyString,
809 _T("ComplexBoxName"), wxT("*.bbs"), wxSAVE
810 | wxOVERWRITE_PROMPT);
811 if (saveFileDialog->ShowModal() == wxID_OK) {
812 wxString fileName = saveFileDialog->GetPath();
813 std::string filename = (const char*) (fileName.mb_str());
814 filename=CheckExtension (filename, ".bbs");
815 SaveActualComplexBox(filename);
819 //=========================================================================
820 void wxGUIEditorGraphicBBS::SaveActualDiagram(std::string filename) {
822 file.open(filename.c_str());
824 std::string content = "";
826 // writing file header
827 content += "# ----------------------------------\n";
828 content += "# - BBTKGEditor v ";
829 content += _currentBBGversion; //VERSION
830 content += " BBG BlackBox Diagram file\n";
836 content += "# ----------------------------------\n";
838 content += "APP_START\n";
839 _tabsMgr->saveActualDiagram(content, filename); //DFCH
840 content += "APP_END\n";
845 //=========================================================================
846 void wxGUIEditorGraphicBBS::SaveTempActualDiagram(const std::string &action)
850 std::string name = _tabsMgr->GetNameTabPanel();
851 if(name[name.length() - 1] != '*')
853 _tabsMgr->SetNameTabPanel(wxString (name.c_str(), wxConvUTF8));
854 _tabsMgr->saveTempActualDiagram(action);
855 GetToolBar()->EnableTool(ID_UNDO,_tabsMgr->getUndoState(stundo));
856 GetToolBar()->SetToolShortHelp(ID_UNDO,crea::std2wx(stundo));
857 GetToolBar()->EnableTool(ID_REDO,_tabsMgr->getRedoState(stredo));
858 GetToolBar()->SetToolShortHelp(ID_REDO,crea::std2wx(stredo));
861 //=========================================================================
863 //The following method allows to save the current diagram asking the filename
865 void wxGUIEditorGraphicBBS::SaveCurrentDiagramAs() {
866 wxFileDialog * saveFileDialog = new wxFileDialog(this,
867 wxT("Save current diagram"), wxEmptyString, wxT("NewDiagram"),
868 wxT("*.bbg"), wxSAVE | wxOVERWRITE_PROMPT);
869 if (saveFileDialog->ShowModal() == wxID_OK) {
870 //_tabsMgr->SetNameTabPanel(saveFileDialog->GetFilename());
871 wxString pathfileName = saveFileDialog->GetPath();
872 std::string pathfilename = (const char*) (pathfileName.mb_str());
873 pathfilename=CheckExtension (pathfilename, ".bbg");
875 //modify the tab name accordingly
876 wxString fileName = saveFileDialog->GetFilename();
877 std::string filename = (const char*) (fileName.mb_str());
878 filename=CheckExtension (filename, ".bbg");
879 _tabsMgr->SetNameTabPanel( wxString (filename.c_str(), wxConvUTF8) );
881 std::string pathfilenamebbs = pathfilename;
882 pathfilenamebbs[pathfilenamebbs.length() - 1] = 's';
883 if (_tabsMgr->isActualDiagramComplexBox() == false) {
884 SaveActualDiagram(pathfilename);
885 SaveActualBBS(pathfilenamebbs);
887 AskComplexBoxConfiguration();
888 SaveActualDiagram(pathfilename);
889 SaveActualComplexBox(pathfilenamebbs);
890 } //if isActualDiagramComplexBox
891 } // if saveFileDialog
893 //=========================================================================
895 void wxGUIEditorGraphicBBS::OnSaveActualDiagram(wxCommandEvent& event) {
896 std::string pathfilename = _tabsMgr->GetCurrentTabPanelPath();
897 if (pathfilename.empty()) {
898 SaveCurrentDiagramAs();
900 std::string pathfilenamebbs = pathfilename;
901 pathfilenamebbs[pathfilenamebbs.length() - 1] = 's';
903 if (_tabsMgr->isActualDiagramComplexBox() == false) {
904 std::string name = _tabsMgr->GetNameTabPanel();
905 if(name[name.length() - 1] == '*')
907 name =name.substr(0,name.length()-1);
909 _tabsMgr->SetNameTabPanel(wxString (name.c_str(), wxConvUTF8));
910 SaveActualDiagram(pathfilename);
911 SaveActualBBS(pathfilenamebbs);
913 AskComplexBoxConfiguration();
914 SaveActualDiagram(pathfilename);
915 SaveActualComplexBox(pathfilenamebbs);
916 } //if isActualDiagramComplexBox
919 //=========================================================================
921 void wxGUIEditorGraphicBBS::OnSaveAsActualDiagram(wxCommandEvent& event) {
922 SaveCurrentDiagramAs();
925 //=========================================================================
926 void wxGUIEditorGraphicBBS::OnExportConsoleExecCommand(wxCommandEvent& event)
928 wxFileDialog * saveFileDialog = new wxFileDialog(this,
929 wxT("Export console command"), wxEmptyString, wxT("ConsoleApp.txt"),
930 wxT("*.txt;*.bbs;*.bbg;*.sh;*.bat"), wxSAVE | wxOVERWRITE_PROMPT);
932 if (saveFileDialog->ShowModal() == wxID_OK)
934 wxString fileName = saveFileDialog->GetPath();
935 std::string filename = (const char*) (fileName.mb_str());
936 filename=CheckExtension (filename, ".txt");
939 file.open(filename.c_str());
941 std::vector<std::string> extInputs = _tabsMgr->getActualTabPanel()->getSceneManager()->GetExternalInputsNames();
943 //TODO PUT IN A METHOD OF A FILES AND TEXT MANAGER CLASS !!!
944 //std::string inputsInCommentsWin="";
945 //std::string inputsInCommentsUnix="";
946 //std::string inputsInOneLineWin="";
947 std::string inputsInOneLineUnix="";
948 for (unsigned int i = 0; i < extInputs.size(); ++i)
950 /* No gusto la idea al jefe pero por si acaso ...
951 * RaC 2012 2nd HackFest
953 inputsInCommentsWin+="REM ";
954 inputsInCommentsWin+=extInputs[i];
955 inputsInCommentsWin+="=\"value\"\n";
956 inputsInCommentsUnix+="# ";
957 inputsInCommentsUnix+=extInputs[i];
958 inputsInCommentsUnix+="=\"value\"\n";
961 sprintf (buffer, "%d", (i+1));
962 inputsInOneLineWin+=extInputs[i];
963 inputsInOneLineWin+="=\"%";
964 inputsInOneLineWin+=buffer;
965 inputsInOneLineWin+="\" ";
967 inputsInOneLineUnix+=extInputs[i];
968 inputsInOneLineUnix+="=\"<value>\" ";
973 std::string content = "";
974 // writing file header
975 content += "# ----------------------------------\n";
976 content += "# - BBTKGEditor v ";
977 content += _currentBBGversion; //VERSION
978 content += " Console Commands to execute BBS application\n";
982 content += "# ----------------------------------\n";
985 content += "# Command to execute bbi\n";
986 content += "bbi <bbs_path> ";
987 content += inputsInOneLineUnix;
989 /* No gusto la idea al jefe pero por si acaso ...
990 * RaC 2012 2nd HackFest
991 content += "# For Windows (copy the following lines to a .bat file)\n";
992 content += "REM BBS application\n";
993 content += "REM Inputs:\n";
994 content += inputsInCommentsWin;
995 content += "REM To use previous inputs, put %$inputName% in the corresponding input of the execution bbi line\n";
996 content += "bbi applicationBBS.bbs ";
997 content += inputsInOneLineWin;
1000 content += "# For Linux or Mac (copy the following lines to a .sh file)\n";
1001 content += "#!/bin/bash\n";
1002 content += "# BBS application\n";
1003 content += "# Inputs:\n";
1004 content += inputsInCommentsUnix;
1005 content += "# To use previous inputs, put $inputName in the corresponding input of the execution bbi line\n";
1006 content += "bbi applicationBBS.bbs ";
1007 content += inputsInOneLineUnix;
1018 //=========================================================================
1020 void wxGUIEditorGraphicBBS::refreshGUIControls() {
1023 //RaC2012 2ndHackFest Next line seems weird ... To keep in mind for other devels
1024 wxToolBar* toolbar = GetToolBar();
1025 if (_tabsMgr->isActualDiagramComplexBox()) {
1026 toolbar->ToggleTool(ID_BTNCOMPLEXBOX, true);
1027 //toolbar->EnableTool(ID_ADDCOMPLEXBOXINPUT, true); RaC2012 2nd HackFest
1028 toolbar->EnableTool(ID_ADDCOMPLEXBOXOUTPUT, true);
1030 GetMenuBar()->GetMenu(0)->Enable(ID_SAVE_AS_COMPLEXBOX, true);
1031 GetMenuBar()->GetMenu(0)->Enable(ID_SAVE_AS_BBS, false);
1032 GetMenuBar()->GetMenu(0)->Enable(ID_EXPORT_CONSOLEAPP, false);
1034 toolbar->ToggleTool(ID_BTNCOMPLEXBOX, false);
1035 //toolbar->EnableTool(ID_ADDCOMPLEXBOXINPUT, false); RaC2012 2nd HackFest
1036 toolbar->EnableTool(ID_ADDCOMPLEXBOXOUTPUT, false);
1038 GetMenuBar()->GetMenu(0)->Enable(ID_SAVE_AS_COMPLEXBOX, false);
1039 GetMenuBar()->GetMenu(0)->Enable(ID_SAVE_AS_BBS, true);
1040 GetMenuBar()->GetMenu(0)->Enable(ID_EXPORT_CONSOLEAPP, true);
1043 //RaC2012 2ndHackFest
1044 GetToolBar()->EnableTool(ID_EDITPROPERTIES,true);
1046 GetToolBar()->EnableTool(ID_UNDO,_tabsMgr->getUndoState(stundo));
1047 GetToolBar()->SetToolShortHelp(ID_UNDO,crea::std2wx(stundo));
1048 GetToolBar()->EnableTool(ID_REDO,_tabsMgr->getRedoState(stredo));
1049 GetToolBar()->SetToolShortHelp(ID_REDO,crea::std2wx(stredo));
1051 if (_tabsMgr->getNumActualSelectedObjects() > 0) {
1052 GetMenuBar()->GetMenu(1)->Enable(ID_COPY_TO_COMPLEXDIAGRAM, true);
1054 ///TODO Fix the possibility to say from the SceneManager to the GUI to refresh the options
1055 GetMenuBar()->GetMenu(1)->Enable(ID_COPY_TO_COMPLEXDIAGRAM, true);
1060 //=========================================================================
1062 void wxGUIEditorGraphicBBS::OnDeleteAllBoxesActualDiagram(wxCommandEvent& event)
1064 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);
1065 if (dial->ShowModal() == wxID_YES)
1067 _tabsMgr->deleteAllBoxesActualDiagram();
1071 //=========================================================================
1073 void wxGUIEditorGraphicBBS::OnCenterViewActualDiagram(wxCommandEvent& event)
1075 _tabsMgr->centerViewActualDiagram();
1078 //=========================================================================
1079 void wxGUIEditorGraphicBBS::OpenDiagram(std::string filePathName, std::string fileName)
1081 ifstream inputStream;
1082 inputStream.open(filePathName.c_str());
1083 assert(inputStream.good()); // fails
1085 if(_tabsMgr->FindTab(filePathName)!=-1) //RaC2012 avoid opening same diagram twice
1087 inputStream.close();
1088 printf("RaC: Diagram already opened\n");
1091 _tabsMgr->addNewTab( crea::std2wx(fileName) );
1092 _tabsMgr->loadDiagram(inputStream, filePathName);
1093 _tabsMgr->saveTempActualDiagram("load diagram");
1094 GetToolBar()->EnableTool(ID_UNDO, false);
1095 GetToolBar()->EnableTool(ID_UNDO, false);
1096 inputStream.close();
1097 refreshGUIControls();
1100 //=========================================================================
1102 void wxGUIEditorGraphicBBS::OnOpenDiagram(wxCommandEvent& event)
1104 wxFileDialog * openFileDialog = new wxFileDialog(this, wxT("Open diagram"), wxEmptyString, wxT(""), wxT("*.bbg"), wxOPEN | wxFILE_MUST_EXIST);
1105 if (openFileDialog->ShowModal() == wxID_OK)
1107 wxString filePath = openFileDialog->GetPath();
1108 wxString fileName = openFileDialog->GetFilename();
1109 OpenDiagram( crea::wx2std(filePath) , crea::wx2std(fileName) );
1113 //=========================================================================
1114 void wxGUIEditorGraphicBBS::OnClickBtnBox(wxCommandEvent& event)
1116 std::cout<<"wxGUIEditorGraphicBBS::OnClickBtnBox"<<std::endl;
1117 BlackBoxDescriptor *bbDes = _pkgBrowser->GetActualSelected();
1118 if (bbDes != NULL) {
1119 std::string typeName = bbDes->GetTypeName();
1120 std::string packageName = bbDes->GetPackage()->GetName();
1121 wxGEditorTabPanel *pnl = this->_tabsMgr->getActualTabPanel();
1123 wxVtkSceneManager *scn = pnl->getSceneManager();
1124 scn->createGBlackBox(50, 50, packageName, typeName);
1127 SaveTempActualDiagram("New Box");
1132 //=========================================================================
1134 void wxGUIEditorGraphicBBS::OnClickBtnExecutableBox(wxCommandEvent& event)
1137 wxGEditorTabPanel *pnl = this->_tabsMgr->getActualTabPanel();
1140 wxVtkSceneManager *scn = pnl->getSceneManager();
1141 if( scn->MakeBoxExecutable() )
1142 std::cout<<"DFCH: wxGUIEditorGraphicBBS::OnClickBtnExecutableBox...successful"<<std::endl;
1144 std::cout<<"DFCH: wxGUIEditorGraphicBBS::OnClickBtnExecutableBox...Error!!"<<std::endl;
1150 //=========================================================================
1151 void wxGUIEditorGraphicBBS::OnClickBtnComplexBox(wxCommandEvent& event)
1153 std::cout<<"wxGUIEditorGraphicBBS::OnClickBtnComplexBox"<<std::endl;
1154 wxToolBar* toolbar = GetToolBar();
1155 bool temp = toolbar->GetToolState(ID_BTNCOMPLEXBOX);
1159 disableComplexBox();
1163 //=========================================================================
1165 void wxGUIEditorGraphicBBS::OnAddComplexBoxInput(wxCommandEvent& event)
1167 wxTextEntryDialog *nameDialog = new wxTextEntryDialog(this,
1168 wxT("Name of input port"));
1169 if (nameDialog->ShowModal() == wxID_OK)
1171 wxString fileName = nameDialog->GetValue();
1172 if (!fileName.IsEmpty())
1174 std::string portName = (const char*) (fileName.mb_str());
1175 if ( !boxNameExists(portName) )
1177 _tabsMgr->addActualDiagramComplexInputPort(portName);
1179 wxMessageDialog *dial = new wxMessageDialog(NULL,
1180 wxT("Impossible to create Box. The name already exists. Please provide another name"),
1181 wxT("Change name: name already exists"), wxOK | wxICON_EXCLAMATION | wxSTAY_ON_TOP);
1188 //=========================================================================
1189 void wxGUIEditorGraphicBBS::OnAddComplexBoxOutput(wxCommandEvent& event)
1191 wxTextEntryDialog *nameDialog = new wxTextEntryDialog(this,
1192 wxT("Name of output port"));
1193 if (nameDialog->ShowModal() == wxID_OK)
1195 wxString fileName = nameDialog->GetValue();
1196 if (!fileName.IsEmpty())
1198 std::string portName = (const char*) (fileName.mb_str());
1199 if ( !boxNameExists(portName) )
1201 _tabsMgr->addActualDiagramComplexOutputPort(portName);
1203 wxMessageDialog *dial = new wxMessageDialog(NULL,
1204 wxT("Impossible to create Box. The name already exists. Please provide another name"),
1205 wxT("Change name: name already exists"), wxOK | wxICON_EXCLAMATION | wxSTAY_ON_TOP);
1213 //=========================================================================
1214 void wxGUIEditorGraphicBBS::OnCopySelectedToComplexDiagram(
1215 wxCommandEvent& event)
1217 _tabsMgr->copySelectedBBoxesToComplexDiagram();
1220 //=========================================================================
1221 void wxGUIEditorGraphicBBS::OnHelpBBeditor(wxCommandEvent& event)
1223 printf("wxGUIEditorGraphicBBS::OnHelpBBeditor ....not implemented..\n");
1226 //=========================================================================
1227 void wxGUIEditorGraphicBBS::OnCreatePackage(wxCommandEvent& event)
1229 bbtkSystemTools::CreatePackage();
1232 //=========================================================================
1233 void wxGUIEditorGraphicBBS::OnCreateBlackBox(wxCommandEvent& event)
1235 bbtkSystemTools::CreateBlackBox();
1238 //=========================================================================
1239 void wxGUIEditorGraphicBBS::OnPlugPackage(wxCommandEvent& event)
1241 //DFGO2012 Plug Package functionnalities
1242 long style = wxDD_DEFAULT_STYLE | wxDD_DIR_MUST_EXIST;
1245 _T("Select package directory"),
1251 userResponse = FD->ShowModal();
1252 if(userResponse==wxID_OK)
1254 std::string path = wx2std (FD->GetPath()) ;
1256 std::string fname = path + "\\bbtkPackage";
1258 std::string fname = path + "/bbtkPackage";
1261 std::cout << "Path chosen = \"" << FD->GetPath() << "\"" << std::endl;
1262 if ( Utilities::FileExists( fname ) )
1265 f.open(fname.c_str());
1268 while(pname[0] == '#')
1270 getline(f, pname, '\n');
1275 bbtk::ConfigurationFile::GetInstance().AddPackagePathsAndWrite( path );
1277 DoRegeneratePackageDoc(pname);
1278 DoRegenerateBoxesLists();
1280 _pkgBrowser->RebuildList();
1282 wxMessageBox(_T("Package successfully plugged. Please restart bbEditor to see the new package in the package browser."),_T("Plug package"),wxOK | wxICON_INFORMATION);
1283 userResponse = wxID_CANCEL;
1287 std::string err = "The directory \"" + path + "\" does not contain a 'bbtkPackage' file.";
1290 err += "\nNote: If you are on Linux please select the folder and click \"Open\", don't enter in it.";
1294 wxMessageBox(crea::std2wx(err), _T("Plug package"),wxOK | wxICON_ERROR);
1295 // THE FOLLOWING LINE GIVES ERRORS BECAUSE IT IS NECESSARY TO USE std2wx
1296 //wxMessageBox( _T( err) , _T("Plug package"),wxOK | wxICON_ERROR);
1299 }while(userResponse != wxID_CANCEL);
1303 //=========================================================================
1304 void wxGUIEditorGraphicBBS::OnEditConfig(wxCommandEvent& event)
1306 std::string commandStr;
1307 std::string configFile = ConfigurationFile::GetInstance().Get_config_xml_full_path();
1309 commandStr = "notepad.exe ";
1311 commandStr = "gedit ";
1313 commandStr = commandStr + configFile;
1314 std::cout << "system: " << commandStr << std::endl;
1315 system ( commandStr.c_str() );
1318 //=========================================================================
1319 void wxGUIEditorGraphicBBS::OnShowHTMLDoc(wxCommandEvent& event)
1322 if (_helpHtmlBrowser != NULL){
1323 _frameAUIMgr->DetachPane(_helpHtmlBrowser);
1324 _helpHtmlBrowser->Destroy();
1326 initHelpHTMLBrowser();
1327 _frameAUIMgr->AddPane(_helpHtmlBrowser, wxAuiPaneInfo().Right().MinSize(200, 200));
1328 _frameAUIMgr->Update();
1329 refreshGUIControls();
1334 //=========================================================================
1335 void wxGUIEditorGraphicBBS::OnCreateIndex(wxCommandEvent& event)
1337 printf("EED wxGUIEditorGraphicBBS::OnCreateIndex ... not implemented ..\n");
1341 //=========================================================================
1342 void wxGUIEditorGraphicBBS::OnEditComplexBoxScript(wxCommandEvent& event)
1344 BlackBoxDescriptor *bbDes = _pkgBrowser->GetActualSelected();
1347 std::string packageName = bbDes->GetPackage()->GetName();
1348 std::string typeName = bbDes->GetTypeName();
1349 if (!TryToOpenScriptComplexBox(packageName ,typeName))
1351 wxMessageDialog windowMessage1(NULL,_T("This is not a ComplexBox script."), _T("Alert !"), wxOK);
1352 windowMessage1.ShowModal();
1357 //=========================================================================
1358 void wxGUIEditorGraphicBBS::OnExit(wxCommandEvent& event)
1363 Factory::Pointer wxGUIEditorGraphicBBS::GetBBTKFactory()
1365 if (_pkgBrowser==NULL)
1367 printf ("EED ERROR! wxGUIEditorGraphicBBS::GetBBTKFactory _pkgBrowser = NULL\n");
1369 return _pkgBrowser->GetFactory();
1372 //=========================================================================
1373 void wxGUIEditorGraphicBBS::enableComplexBox()
1375 _tabsMgr->setActualDiagramComplexBox(true);
1376 refreshGUIControls();
1379 //=========================================================================
1381 void wxGUIEditorGraphicBBS::disableComplexBox()
1383 _tabsMgr->setActualDiagramComplexBox(false);
1384 refreshGUIControls();
1387 //=========================================================================
1388 void wxGUIEditorGraphicBBS::setCurrentDiagramDescription(std::string description)
1390 _tabsMgr->SetDescription(description);
1393 //=========================================================================
1394 void wxGUIEditorGraphicBBS::setCurrentDiagramAuthor(std::string author)
1396 _tabsMgr->SetAuthor(author);
1399 //=========================================================================
1400 void wxGUIEditorGraphicBBS::setCurrentDiagramCategory(std::string category)
1402 _tabsMgr->SetCategory(category);
1405 //=========================================================================
1406 void wxGUIEditorGraphicBBS::setCurrentDiagramMessageKind(std::string kind){
1407 _tabsMgr->SetMessageKind(kind);
1410 //=========================================================================
1411 void wxGUIEditorGraphicBBS::setCurrentDiagramMessageLevel(std::string level){
1412 _tabsMgr->SetMessageLevel(level);
1415 //=========================================================================
1416 std::string wxGUIEditorGraphicBBS::getCurrentDiagramDescription()
1418 return _tabsMgr->GetDescription();
1421 //=========================================================================
1422 std::string wxGUIEditorGraphicBBS::getCurrentDiagramAuthor()
1424 return _tabsMgr->GetAuthor();
1427 //=========================================================================
1428 std::string wxGUIEditorGraphicBBS::getCurrentDiagramCategory()
1430 return _tabsMgr->GetCategory();
1433 //=========================================================================
1434 std::string wxGUIEditorGraphicBBS::getCurrentDiagramMessageKind(){
1435 return _tabsMgr->GetMessageKind();
1438 //=========================================================================
1439 std::string wxGUIEditorGraphicBBS::getCurrentDiagramMessageLevel(){
1440 return _tabsMgr->GetMessageLevel();
1443 //=========================================================================
1444 bool wxGUIEditorGraphicBBS::isCurrentDiagramComplexBox()
1446 return _tabsMgr->isActualDiagramComplexBox();
1450 //=========================================================================
1451 void wxGUIEditorGraphicBBS::OpenScript(std::string filePathNameBBS ,std::string boxType)
1453 std::string fileName = boxType+".bbg";
1454 std::string filePathNameBBG = filePathNameBBS;
1455 filePathNameBBG[ filePathNameBBG.length()-1 ] = 'g';
1457 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);
1458 windowMessage1.ShowModal();
1460 if ( Utilities::FileExists( filePathNameBBG ) )
1462 OpenDiagram( filePathNameBBG , fileName );
1464 if ( Utilities::FileExists( filePathNameBBS ) )
1466 OpenBBS( filePathNameBBS , fileName );
1468 wxMessageDialog windowMessage1(NULL,_T("..ERROR.. loading script bbg/bbs."), _T("Alert !"), wxOK);
1469 windowMessage1.ShowModal();
1476 //=========================================================================
1477 bool wxGUIEditorGraphicBBS::TryToOpenScriptApplication(std::string packageName ,std::string boxType)
1479 return TryToOpenScript(packageName ,boxType, true, false);
1482 //=========================================================================
1483 bool wxGUIEditorGraphicBBS::TryToOpenScriptComplexBox(std::string packageName ,std::string boxType)
1485 return TryToOpenScript(packageName ,boxType, false, true);
1489 //=========================================================================
1490 bool wxGUIEditorGraphicBBS::TryToOpenScript(std::string packageName ,std::string boxType,bool scriptApplication, bool scriptComplexBox)
1493 std::map< std::string, BlackBoxDescriptor::Pointer> mapDesc;
1494 BlackBoxDescriptor::Pointer descriptor;
1495 k = GetBBTKFactory()->GetPackage(packageName);
1496 mapDesc = k->GetDescriptorMap();
1497 descriptor = mapDesc[boxType];
1502 ((descriptor->IsTypeOfScript_Application()==true) && (scriptApplication==true))
1504 ((descriptor->IsTypeOfScript_ComplexBox()==true) && (scriptComplexBox==true))
1508 OpenScript(descriptor->GetScriptFileName(),boxType);
1514 } // EO namespace bbtk