2 # ---------------------------------------------------------------------
4 # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
6 # Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton
8 # This software is governed by the CeCILL-B license under French law and
9 # abiding by the rules of distribution of free software. You can use,
10 # modify and/ or redistribute the software under the terms of the CeCILL-B
11 # license as circulated by CEA, CNRS and INRIA at the following URL
12 # http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
13 # or in the file LICENSE.txt.
15 # As a counterpart to the access to the source code and rights to copy,
16 # modify and redistribute granted by the license, users are provided only
17 # with a limited warranty and the software's author, the holder of the
18 # economic rights, and the successive licensors have only limited
21 # The fact that you are presently reading this means that you have had
22 # knowledge of the CeCILL-B license and that you accept its terms.
23 # ------------------------------------------------------------------------
26 /*=========================================================================
32 =========================================================================*/
34 /* ---------------------------------------------------------------------
36 * Copyright (c) CREATIS-LRMN (Centre de Recherche en Imagerie Medicale)
37 * Authors : Eduardo Davila, Laurent Guigues, Jean-Pierre Roux
39 * This software is governed by the CeCILL-B license under French law and
40 * abiding by the rules of distribution of free software. You can use,
41 * modify and/ or redistribute the software under the terms of the CeCILL-B
42 * license as circulated by CEA, CNRS and INRIA at the following URL
43 * http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
44 * or in the file LICENSE.txt.
46 * As a counterpart to the access to the source code and rights to copy,
47 * modify and redistribute granted by the license, users are provided only
48 * with a limited warranty and the software's author, the holder of the
49 * economic rights, and the successive licensors have only limited
52 * The fact that you are presently reading this means that you have had
53 * knowledge of the CeCILL-B license and that you accept its terms.
54 * ------------------------------------------------------------------------ */
58 * \brief Class bbtk::WxInterfaceEditorGraphicBBS .
61 #include "bbtkwxGUIEditorGraphicBBS.h"
63 #include "creaSystem.h"
64 //must go #include "bbtkUtilities.h"
65 //must go #include "bbtkConfigurationFile.h"
68 #include <InterpreterBBS.h>
72 //=========================================================================
73 wxGUIEditorGraphicBBS::wxGUIEditorGraphicBBS(wxFrame *parent)
74 : wxFrame( parent, -1, _T("bbtkGEditor"), wxDefaultPosition, wxSize(1200,800) )
77 _frameAUIMgr = new wxAuiManager(this);
79 /*std::string datadir( crea::System::GetExecutablePath() );
80 std::string datadir (".");
81 cout<<"RaC //------------------"<<endl;
82 cout<<"RaC //TODO wxGUIEditorGraphicBBS constructor.Initialize datadir with crea::System::GetExecutablePath() ."<<endl;
83 cout<<"RaC //------------------"<<endl;
85 #ifdef LINUX // assume this is OSX
86 datadir=datadir+"/../share/creaContours";
89 #ifdef MACOSX // assume this is OSX
90 datadir=datadir+"/../../../../share/creaContours";
98 initTabPanelsManager();
99 // JGGR & CM initHelpHTMLBrowser();
100 _helpHtmlBrowser = NULL;
102 _frameAUIMgr->Update();
103 _actualPkgBrowserBoxName = "";
104 _actualPkgBrowserPkgName = "";
105 refreshGUIControls();
107 /////////////////////////////////
108 /// IMPORTANT!! FOR SAVE&LOAD PROCESSES THE VERSION IS VERY IMPORTANT.
109 /// RaC 2012 2nd Hackfest
110 _currentBBGversion="1.4";
113 //=========================================================================
114 wxGUIEditorGraphicBBS::~wxGUIEditorGraphicBBS() {
116 printf("EED %p ~wxGUIEditorGraphicBBS()\n", this);
118 //EED02JUIN2010 delete _tabsMgr;
120 _frameAUIMgr->UnInit();
128 //=========================================================================
129 void wxGUIEditorGraphicBBS::initToolbar() {
130 wxBitmap bmp_new(new_xpm);
131 wxBitmap bmp_open(open_xpm);
132 wxBitmap bmp_save(save_xpm);
133 wxBitmap bmp_run(run_xpm);
134 wxBitmap bmp_delete(delete_xpm);
135 wxBitmap bmp_centerview(centerview_xpm);
136 wxBitmap bmp_box(box_xpm);
137 wxBitmap bmp_executablebox(executablebox_xpm);
138 wxBitmap bmp_complexbox(complexbox_xpm);
139 wxBitmap bmp_complexinputport(complexinputport_xpm);
140 wxBitmap bmp_complexoutputport(complexoutputport_xpm);
141 wxBitmap bmp_undo(undo_xpm);
142 wxBitmap bmp_redo(redo_xpm);
143 wxBitmap bmp_editProperties(editProperties_xpm);
144 wxToolBar *toolbar = new wxToolBar(this, wxID_ANY);
146 //Adds a tool btn to the toolbar
147 toolbar->AddTool(ID_NEW, _T("New"), bmp_new, wxNullBitmap, wxITEM_NORMAL,
148 _T("New tab"), _T("Create a new panel tab"));
149 toolbar->AddTool(ID_OPEN, _T("Open diagram"), bmp_open, wxNullBitmap,
150 wxITEM_NORMAL, _T("Open a diagram"), _T("Open a diagram"));
151 toolbar->AddTool(ID_SAVE_DIAGRAM, _T("Save Diagram"), bmp_save,
152 wxNullBitmap, wxITEM_NORMAL, _T("Saves the current diagram"),
153 _T("Saves the current diagram")); //DFCH
154 //toolbar->AddTool(ID_SAVE_AS_DIAGRAM,_T("Save Diagram As"),bmp_save, wxNullBitmap, wxITEM_NORMAL,_T("Saves the current diagram"), _T("Saves the current diagram")); //DFCH
155 toolbar->AddTool(ID_RUN, _T("Run"), bmp_run, wxNullBitmap, wxITEM_NORMAL,
156 _T("Execute actual diagram"), _T("Execute actual diagram"));
157 toolbar->AddTool(ID_DELETEALL, _T("Delete all"), bmp_delete, wxNullBitmap,
158 wxITEM_NORMAL, _T("Delete all boxes"), _T("Delete all boxes"));
159 toolbar->AddTool(ID_CENTERVIEW, _T("Center view"), bmp_centerview,
160 wxNullBitmap, wxITEM_NORMAL, _T("Center view"), _T("Center view"));
161 toolbar->AddSeparator();
162 toolbar->AddTool(ID_BTNBOX, _T("New Box"), bmp_box, wxNullBitmap,
163 wxITEM_NORMAL, _T("New Box"), _T("Nex Box"));
164 toolbar->AddSeparator();
165 toolbar->AddTool(ID_BTEXECUTABLEBOX, _T("Select as executable Box"),
166 bmp_executablebox, wxNullBitmap, wxITEM_NORMAL,
167 _T("Select as executable Box"), _T("Select as executable Box"));
168 toolbar->AddSeparator();
169 toolbar->AddTool(ID_BTNCOMPLEXBOX, _T("Complex box"), complexbox_xpm,
170 wxNullBitmap, wxITEM_NORMAL, _T("Complex box"), _T("Complex box"));
171 toolbar->SetToggle(ID_BTNCOMPLEXBOX, true);
173 // RaC 2012 2nd HackFest - Now Complex inputs are any external input
174 // toolbar->AddTool(ID_ADDCOMPLEXBOXINPUT, _T("Add input to Complex box"),
175 // bmp_complexinputport, wxNullBitmap, wxITEM_NORMAL,
176 // _T("Add input to Complex box"), _T("Add input to Complex box"));
177 toolbar->AddTool(ID_ADDCOMPLEXBOXINPUT, _T("Add external input (Complex box or console app)"),
178 bmp_complexinputport, wxNullBitmap, wxITEM_NORMAL,
179 _T("Add external input (Complex box or console app)"), _T("Add external input (Complex box or console app)"));
181 toolbar->AddTool(ID_ADDCOMPLEXBOXOUTPUT, _T("Add output to Complex box"),
182 bmp_complexoutputport, wxNullBitmap, wxITEM_NORMAL,
183 _T("Add output Complex box"), _T("Add output Complex box"));
185 // toolbar->EnableTool(ID_ADDCOMPLEXBOXINPUT, false); RaC2012 2nd HackFest
186 toolbar->EnableTool(ID_ADDCOMPLEXBOXINPUT, true);
188 toolbar->EnableTool(ID_ADDCOMPLEXBOXOUTPUT, false);
189 toolbar->AddSeparator();
190 toolbar->AddTool(ID_UNDO, _T("Undo"),bmp_undo, wxNullBitmap, wxITEM_NORMAL, _T("Undo"), _T("Undo"));
191 toolbar->AddTool(ID_REDO, _T("Redo"),bmp_redo, wxNullBitmap, wxITEM_NORMAL, _T("Redo"), _T("Redo"));
192 toolbar->AddSeparator();
193 toolbar->AddTool(ID_EDITPROPERTIES, _T("Edit diagram properties"),bmp_editProperties, wxNullBitmap, wxITEM_NORMAL, _T("Edit diagram properties"), _T("Edit diagram properties"));
194 toolbar->EnableTool(ID_EDITPROPERTIES, false);
196 toolbar->EnableTool(ID_UNDO, false);
197 toolbar->EnableTool(ID_REDO, false);
198 toolbar->SetMargins(2, 2);
203 // connect command event handlers
205 Connect(ID_NEW, wxEVT_COMMAND_TOOL_CLICKED,
206 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnCreateNewTab));
207 Connect(ID_OPEN, wxEVT_COMMAND_TOOL_CLICKED,
208 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnOpenDiagram));
209 Connect(ID_SAVE_DIAGRAM, wxEVT_COMMAND_TOOL_CLICKED,
210 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnSaveActualDiagram)); //DFCH
211 Connect(ID_SAVE_AS_DIAGRAM, wxEVT_COMMAND_TOOL_CLICKED,
212 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnSaveAsActualDiagram)); //DFCH
215 wxEVT_COMMAND_TOOL_CLICKED,
216 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnExecuteActualDiagram));
219 wxEVT_COMMAND_TOOL_CLICKED,
220 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnDeleteAllBoxesActualDiagram));
223 wxEVT_COMMAND_TOOL_CLICKED,
224 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnCenterViewActualDiagram));
225 Connect(ID_BTNBOX, wxEVT_COMMAND_TOOL_CLICKED,
226 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnClickBtnBox));
229 wxEVT_COMMAND_TOOL_CLICKED,
230 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnClickBtnExecutableBox));
231 Connect(ID_BTNCOMPLEXBOX, wxEVT_COMMAND_TOOL_CLICKED,
232 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnClickBtnComplexBox));
233 Connect(ID_ADDCOMPLEXBOXINPUT, wxEVT_COMMAND_TOOL_CLICKED,
234 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnAddComplexBoxInput));
235 Connect(ID_ADDCOMPLEXBOXOUTPUT, wxEVT_COMMAND_TOOL_CLICKED,
236 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnAddComplexBoxOutput));
237 Connect(ID_UNDO,wxEVT_COMMAND_TOOL_CLICKED, wxCommandEventHandler(wxGUIEditorGraphicBBS::OnUndo));
238 Connect(ID_REDO,wxEVT_COMMAND_TOOL_CLICKED, wxCommandEventHandler(wxGUIEditorGraphicBBS::OnRedo));
239 Connect(ID_CHANGENAME, wxEVT_COMMAND_RIGHT_CLICK, wxCommandEventHandler(wxGUIEditorGraphicBBS::OnChangeName));
240 Connect(ID_EDITPROPERTIES,wxEVT_COMMAND_TOOL_CLICKED, wxCommandEventHandler(wxGUIEditorGraphicBBS::OnEditDiagramProperties));
243 //=========================================================================
244 void wxGUIEditorGraphicBBS::initHelpHTMLBrowser() {
246 _helpHtmlBrowser = new WxGUIHtmlBrowser(this, wxSize(200, 0));
252 //=========================================================================
253 void wxGUIEditorGraphicBBS::initMenu() {
254 // Create File menu and its items
255 wxMenu *fileMenu = new wxMenu();
256 fileMenu->Append(ID_NEW, _T("New diagram"), _T("New"));
257 fileMenu->Append(ID_SAVE_DIAGRAM, _T("Save Diagram"), _T("Save Diagram")); //DFCH
258 fileMenu->Append(ID_SAVE_AS_DIAGRAM, _T("Save Diagram As"),
259 _T("Save Diagram As")); //DFCH
260 fileMenu->Append(ID_OPEN_BBS, _T("Open BBS"), _T("Open BBS"));
262 fileMenu->Append(ID_OPEN, _T("Open a diagram"), _T("Open a diagram"));
263 fileMenu->Append(ID_SAVE_AS_BBS, _T("Save BBS"), _T("Save BBS"));
264 fileMenu->Append(ID_SAVE_AS_COMPLEXBOX, _T("Save complex box"),
265 _T("Save complex box"));
266 fileMenu->Append(ID_EXPORT_CONSOLEAPP, _T("Export console commands"),
267 _T("Export console execution commands"));
268 fileMenu->Append(wxID_EXIT, _T("E&xit"), _T("Exit"));
270 Connect(ID_NEW, wxEVT_COMMAND_MENU_SELECTED,
271 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnCreateNewTab));
272 Connect(ID_SAVE_DIAGRAM, wxEVT_COMMAND_MENU_SELECTED,
273 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnSaveActualDiagram)); //DFCH
274 Connect(ID_SAVE_AS_DIAGRAM, wxEVT_COMMAND_MENU_SELECTED,
275 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnSaveAsActualDiagram));
276 Connect(ID_OPEN_BBS, wxEVT_COMMAND_MENU_SELECTED,
277 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnOpenBBS));
278 Connect(ID_SAVE_AS_BBS, wxEVT_COMMAND_MENU_SELECTED,
279 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnSaveActualBBS));
280 Connect( ID_SAVE_AS_COMPLEXBOX, wxEVT_COMMAND_MENU_SELECTED,
281 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnSaveActualComplexBox));
282 Connect( ID_EXPORT_CONSOLEAPP, wxEVT_COMMAND_MENU_SELECTED,
283 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnExportConsoleExecCommand));
284 Connect(wxID_EXIT, wxEVT_COMMAND_MENU_SELECTED,
285 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnExit));
287 // Create Edit menu and its items
288 wxMenu *editMenu = new wxMenu;
289 editMenu->Append(ID_COPY_TO_COMPLEXDIAGRAM, _T("Copy selected to complex box"), _T("Creates a new complex box diagram with selected boxes"));
290 editMenu->Append(ID_EDIT_COMPLEXBOX_SCRIPT, _T("Edit Complex Box"), _T("Edit Complex Box"));
291 Connect( ID_COPY_TO_COMPLEXDIAGRAM, wxEVT_COMMAND_MENU_SELECTED,
292 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnCopySelectedToComplexDiagram));
293 Connect( ID_EDIT_COMPLEXBOX_SCRIPT, wxEVT_COMMAND_MENU_SELECTED,
294 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnEditComplexBoxScript));
296 // Create Help menu and its items
297 wxMenu *helpMenu = new wxMenu;
298 helpMenu->Append(wxID_ABOUT, _T("&About..."), _T("About"));
299 helpMenu->Append(ID_HELP_BBEDITOR, _T("&Help..."), _T("Help"));
300 Connect(ID_HELP_BBEDITOR, wxEVT_COMMAND_MENU_SELECTED,
301 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnHelpBBeditor));
304 wxMenu *menuTools = new wxMenu;
305 menuTools->Append(ID_bbEditor_Tool_Menu_CreatePackage,
306 _T("Create &package") );
307 menuTools->Append(ID_bbEditor_Tool_Menu_CreateBlackBox,
308 _T("Create &blackbox") );
309 menuTools->Append(ID_bbEditor_Tool_Menu_PlugPackage, _T("Plug package") );
310 menuTools->Append(ID_bbEditor_Tool_Menu_EditConfig, _T("&Edit bbtk config") );
311 menuTools->Append(ID_bbEditor_Tool_Menu_ShowHTMLDoc,
312 _T("Show &HTML documentation") );
313 menuTools->Append(ID_bbEditor_Tool_Menu_CreateIndex, _T("&Generate index") );
315 Connect(ID_bbEditor_Tool_Menu_CreatePackage, wxEVT_COMMAND_MENU_SELECTED,
316 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnCreatePackage));
317 Connect(ID_bbEditor_Tool_Menu_CreateBlackBox, wxEVT_COMMAND_MENU_SELECTED,
318 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnCreateBlackBox));
319 Connect(ID_bbEditor_Tool_Menu_PlugPackage, wxEVT_COMMAND_MENU_SELECTED,
320 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnPlugPackage));
321 Connect(ID_bbEditor_Tool_Menu_EditConfig, wxEVT_COMMAND_MENU_SELECTED,
322 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnEditConfig));
323 Connect(ID_bbEditor_Tool_Menu_ShowHTMLDoc, wxEVT_COMMAND_MENU_SELECTED,
324 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnShowHTMLDoc));
325 Connect(ID_bbEditor_Tool_Menu_CreateIndex, wxEVT_COMMAND_MENU_SELECTED,
326 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnCreateIndex));
328 // Append the created menu to the menu bar
329 wxMenuBar *menuBar = new wxMenuBar();
330 menuBar->Append(fileMenu, _T("&File") );
331 menuBar->Append(editMenu, _T("&Edit") );
332 menuBar->Append(menuTools, _T("&Tool") );
333 menuBar->Append(helpMenu, _T("&Help") );
335 // Attach this menu bar to the frame
339 //=========================================================================
340 void wxGUIEditorGraphicBBS::initTabPanelsManager()
342 _notebook = new wxAuiNotebook(this, wxID_NOTEBOOK, wxDefaultPosition,
343 wxDefaultSize, wxAUI_NB_TOP | wxAUI_NB_TAB_MOVE
344 | wxAUI_NB_CLOSE_ON_ACTIVE_TAB | wxAUI_NB_TAB_FIXED_WIDTH
345 | wxAUI_NB_WINDOWLIST_BUTTON);
346 _tabsMgr = new wxTabPanelsManager(this);
347 _frameAUIMgr->AddPane(_notebook, wxAuiPaneInfo().CenterPane());
350 //=========================================================================
351 void wxGUIEditorGraphicBBS::initPackageBrowser()
353 _pkgBrowser = new WxGUIPackageBrowser2(this);
354 _pkgBrowser->IncludeAll();
355 _frameAUIMgr->AddPane(_pkgBrowser, wxAuiPaneInfo().Left().MinSize(30, 500).BestSize(750,500).CloseButton(false));
358 //================================================================
360 void wxGUIEditorGraphicBBS::DoRegeneratePackageDoc(const std::string& pack)
362 std::string mess("Regenerating doc for package '");
366 mess = "Regenerating doc for all packages";
369 mess += " ... please wait";
371 SetStatusText(std2wx(mess));
379 command += ConfigurationFile::GetInstance().Get_bin_path();
380 command += ConfigurationFile::GetInstance().Get_file_separator();
381 command += "bbRegeneratePackageDoc";
386 command += " " + pack + " -q";
387 bbtkMessage("debug",1,"Executing system command '"<<command<<"'"<<std::endl);
389 if (!system(command.c_str())) {
390 SetStatusText(_T("Done !"));
392 wxMessageBox(_T("Done !"),_T("Regenerate package '")
393 +std2wx(pack)+_T("' doc"),
394 wxOK | wxICON_INFORMATION);
397 SetStatusText(_T("Done !"));
398 wxString err(_T("An error occured while running '"));
399 err += bbtk::std2wx(command) + _T("'");
400 wxMessageBox(err, _T("Regenerate package doc"), wxOK | wxICON_ERROR);
404 //================================================================
405 void wxGUIEditorGraphicBBS::DoRegenerateBoxesLists() {
406 SetStatusText(_T("Regenerating boxes lists ... please wait"));
413 command += ConfigurationFile::GetInstance().Get_bin_path();
414 command += ConfigurationFile::GetInstance().Get_file_separator();
415 command += "bbRegenerateBoxesLists";
422 bbtkMessage("debug",1,"Executing system command '"<<command<<"'"<<std::endl);
424 if (!system(command.c_str())) {
425 SetStatusText(_T("Done !"));
427 wxMessageBox(_T("Done !"),_T("Regenerate boxes lists"),
428 wxOK | wxICON_INFORMATION);
431 SetStatusText(_T("Done !"));
432 wxString err(_T("An error occured while running '"));
433 err += bbtk::std2wx(command) + _T("'");
434 wxMessageBox(err, _T("Regenerate boxes lists"), wxOK | wxICON_ERROR);
438 //================================================================
439 void wxGUIEditorGraphicBBS::RegenerateAll() {
440 DoRegeneratePackageDoc("-a");
441 DoRegenerateBoxesLists();
444 //================================================================
446 wxAuiNotebook* wxGUIEditorGraphicBBS::getAuiNotebook() {
450 //================================================================
452 void wxGUIEditorGraphicBBS::displayBlackBoxInfo(std::string packageName, std::string boxName)
454 if (_actualPkgBrowserPkgName != packageName || _actualPkgBrowserBoxName != boxName)
456 _actualPkgBrowserPkgName = packageName;
457 _actualPkgBrowserBoxName = boxName;
459 //EED 15 oct 2012 BlackBoxDescriptor::Pointer descriptor = GObjectsMVCFactory::getInstance()->getBlackBoxDescriptor(packageName, boxName);
462 BlackBoxDescriptor::Pointer descriptor;
463 std::map< std::string, BlackBoxDescriptor::Pointer> mapDesc;
464 k = _pkgBrowser->GetFactory()->GetPackage(packageName);
465 mapDesc = k->GetDescriptorMap();
466 descriptor = mapDesc[boxName];
468 _pkgBrowser->WxGUIBlackBoxListUserOnSelected(descriptor.get());
472 //=========================================================================
474 void wxGUIEditorGraphicBBS::editBlackBox(GBlackBoxModel *bbmodel) {
475 wxBlackBoxEditionDialog* dialog =
476 new wxBlackBoxEditionDialog(this, bbmodel);
480 //=========================================================================
482 bool wxGUIEditorGraphicBBS::boxNameExists(std::string boxname) {
484 return this->_tabsMgr->getActualTabPanel()->getSceneManager()->boxExist(boxname);
487 //=========================================================================
489 void wxGUIEditorGraphicBBS::updateStatusBar(std::string textStatus) {
490 SetStatusText(crea::std2wx(textStatus));
493 //=========================================================================
495 void wxGUIEditorGraphicBBS::executeScript(std::string script) {
496 std::string separator =
497 ConfigurationFile::GetInstance().Get_file_separator();
498 std::string dir = ConfigurationFile::GetInstance().Get_default_temp_dir();
499 std::string filename = dir + separator + "tmp_bbtk.bbs";
502 tempFile.open(filename.c_str());
506 std::string command = "";
509 command += "start /b ";
512 // command += "\""+ crea::System::GetExecutablePath();
514 // command += separator + "../../../bbi.app/Contents/MacOS";
518 command += "\"" + filename + "\"";
524 printf("RaC wxGUIEditorGraphicBBS::executeScript %s \n", command.c_str());
525 system(command.c_str());
528 //=========================================================================
529 std::string wxGUIEditorGraphicBBS::CheckExtension(std::string filename, std::string extension) {
530 if(filename.size() > extension.size() ){
531 if( (filename.compare(filename.size()-extension.size(), extension.size(),extension)) !=0 ){
532 filename.append(extension);
535 filename.append(extension);
539 //=========================================================================
541 //=========================================================================
543 void wxGUIEditorGraphicBBS::OnCreateNewTab(wxCommandEvent& event) {
544 _tabsMgr->addNewTab();
545 refreshGUIControls();
548 void wxGUIEditorGraphicBBS::OnUndo(wxCommandEvent& event) {
549 unsigned short disable;
553 _tabsMgr->loadTempDiagram(0);
554 disable = _tabsMgr->getUndoState(stundo);
557 std::string name = _tabsMgr->GetNameTabPanel();
558 if(name[name.length() - 1] == '*')
560 name =name.substr(0,name.length()-1);
562 _tabsMgr->SetNameTabPanel(wxString (name.c_str(), wxConvUTF8));
565 GetToolBar()->EnableTool(ID_UNDO,disable);
566 GetToolBar()->SetToolShortHelp(ID_UNDO,crea::std2wx(stundo));
567 GetToolBar()->EnableTool(ID_REDO,_tabsMgr->getRedoState(stredo));
568 GetToolBar()->SetToolShortHelp(ID_REDO,crea::std2wx(stredo));
569 refreshGUIControls();
572 //=========================================================================
574 void wxGUIEditorGraphicBBS::OnRedo(wxCommandEvent& event) {
575 unsigned short disable;
579 _tabsMgr->loadTempDiagram(1);
580 std::string name = _tabsMgr->GetNameTabPanel();
581 if(name[name.length() - 1] != '*')
583 _tabsMgr->SetNameTabPanel(wxString (name.c_str(), wxConvUTF8));
584 GetToolBar()->EnableTool(ID_UNDO,_tabsMgr->getUndoState(stundo));
585 GetToolBar()->SetToolShortHelp(ID_UNDO,crea::std2wx(stundo));
586 GetToolBar()->EnableTool(ID_REDO,_tabsMgr->getRedoState(stredo));
587 GetToolBar()->SetToolShortHelp(ID_REDO,crea::std2wx(stredo));
588 refreshGUIControls();
591 void wxGUIEditorGraphicBBS::OnChangeName(wxCommandEvent& event){
594 //=========================================================================
596 void wxGUIEditorGraphicBBS::OnEditDiagramProperties(wxCommandEvent& event)
598 wxDiagramPropertiesEditionDialog* dialog =
599 new wxDiagramPropertiesEditionDialog(this);
603 //=========================================================================
605 void wxGUIEditorGraphicBBS::OnExecuteActualDiagram(wxCommandEvent& event) {
606 std::string script1 = _tabsMgr->getActualDiagramBBS(true);
607 cout << endl << "RaC wxGUIEditorGraphicBBS::executeActualDiagram SCRIPT"
609 cout << script1 << endl;
611 std::string script2 = _tabsMgr->getActualDiagramBBS(false);
612 executeScript(script2);
616 //=========================================================================
617 void wxGUIEditorGraphicBBS::OpenBBS(std::string filePathName, std::string fileName)
619 _tabsMgr->addNewTab( crea::std2wx(fileName) );
620 bbtk::InterpreterBBS::Pointer I = bbtk::InterpreterBBS::New( this->_tabsMgr->getActualTabPanel()->getSceneManager(), _pkgBrowser->GetFactory());
621 // We tell the interpreter to throw exceptions on error
623 // Interpret the file supposed to define a box called 'Processing'
624 I->InterpretFile( filePathName );
625 refreshGUIControls();
628 //=========================================================================
630 //=========================================================================
631 void wxGUIEditorGraphicBBS::OnOpenBBS(wxCommandEvent& event)
633 wxFileDialog * openFileDialog = new wxFileDialog(this, wxT("Open BBS"), wxEmptyString, wxT("NewBBS"), wxT("*.bbs"), wxOPEN);
635 if (openFileDialog->ShowModal() == wxID_OK)
637 OpenBBS( crea::wx2std(openFileDialog->GetPath()) , crea::wx2std(openFileDialog->GetFilename()) );
641 if (openFileDialog->ShowModal() == wxID_OK)
643 wxString fileName = openFileDialog->GetPath();
644 _tabsMgr->addNewTab(openFileDialog->GetFilename());
645 bbtk::InterpreterBBS::Pointer I = bbtk::InterpreterBBS::New( this->_tabsMgr->getActualTabPanel()->getSceneManager(), _pkgBrowser->GetFactory());
646 // We tell the interpreter to throw exceptions on error
648 // Interpret the file supposed to define a box called 'Processing'
649 I->InterpretFile((const char*) (fileName.mb_str()));
651 refreshGUIControls();
655 //=========================================================================
656 void wxGUIEditorGraphicBBS::SaveActualBBS(std::string filename) {
659 //EED file.open(fileName.c_str());
660 file.open(filename.c_str());
661 std::string content = "";
662 // writing file header
663 content += "# ----------------------------------\n";
664 content += "# - BBTKGEditor v ";
665 content += _currentBBGversion; //VERSION
666 content += " BBS BlackBox Script\n";
670 content += "# ----------------------------------\n";
672 content += _tabsMgr->getActualDiagramBBS();
677 void wxGUIEditorGraphicBBS::OnSaveActualBBS(wxCommandEvent& event) {
678 wxFileDialog * saveFileDialog = new wxFileDialog(this,
679 wxT("Save actual BBS"), wxEmptyString, wxT("NewBBS"),
680 wxT("*.bbs"), wxSAVE | wxOVERWRITE_PROMPT);
681 if (saveFileDialog->ShowModal() == wxID_OK) {
682 wxString fileName = saveFileDialog->GetPath();
683 std::string filename = (const char*) (fileName.mb_str());
684 filename=CheckExtension (filename, ".bbs");
685 SaveActualBBS(filename);
690 void wxGUIEditorGraphicBBS::AskComplexBoxConfiguration() {
691 std::string cbName = _tabsMgr->GetCbName();
692 std::string paName = _tabsMgr->GetCbPackageName();
694 wxTextEntryDialog *cbNameDialog = new wxTextEntryDialog(this,
695 wxT("Complex Box name"));
696 wxTextEntryDialog *paNameDialog = new wxTextEntryDialog(this,
697 wxT("Package name"));
699 cbNameDialog->SetValue(wxString(cbName.c_str(), wxConvUTF8));
700 paNameDialog->SetValue(wxString(paName.c_str(), wxConvUTF8));
702 if (cbNameDialog->ShowModal() == wxID_OK) {
703 wxString complexboxname = cbNameDialog->GetValue();
704 cbName = (const char*) (complexboxname.mb_str());
707 if (paNameDialog->ShowModal() == wxID_OK) {
708 wxString packagename = paNameDialog->GetValue();
709 paName = (const char*) (packagename.mb_str());
712 _tabsMgr->SetCbName(cbName);
713 _tabsMgr->SetCbPackageName(paName);
716 //=========================================================================
718 void wxGUIEditorGraphicBBS::SaveActualComplexBox(std::string filename) {
720 file.open(filename.c_str());
722 std::string content = "";
724 // writing file header
725 content += "# ----------------------------------\n";
726 content += "# - BBTKGEditor v ";
727 content += _currentBBGversion;//VERSION
728 content += " BBS BlackBox Script (Complex Box)\n";
732 content += "# ----------------------------------\n";
734 content += _tabsMgr->getActualComplexBoxBBS();
739 //=========================================================================
741 void wxGUIEditorGraphicBBS::OnSaveActualComplexBox(wxCommandEvent& event) {
742 wxFileDialog * saveFileDialog = new wxFileDialog(this,
743 wxT("Save Complex Box BBS"), wxEmptyString,
744 _T("ComplexBoxName"), wxT("*.bbs"), wxSAVE
745 | 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 SaveActualComplexBox(filename);
754 //=========================================================================
755 void wxGUIEditorGraphicBBS::SaveActualDiagram(std::string filename) {
757 file.open(filename.c_str());
759 std::string content = "";
761 // writing file header
762 content += "# ----------------------------------\n";
763 content += "# - BBTKGEditor v ";
764 content += _currentBBGversion; //VERSION
765 content += " BBG BlackBox Diagram file\n";
771 content += "# ----------------------------------\n";
773 content += "APP_START\n";
774 _tabsMgr->saveActualDiagram(content, filename); //DFCH
775 content += "APP_END\n";
780 //=========================================================================
781 void wxGUIEditorGraphicBBS::SaveTempActualDiagram(const std::string &action)
785 std::string name = _tabsMgr->GetNameTabPanel();
786 if(name[name.length() - 1] != '*')
788 _tabsMgr->SetNameTabPanel(wxString (name.c_str(), wxConvUTF8));
789 _tabsMgr->saveTempActualDiagram(action);
790 GetToolBar()->EnableTool(ID_UNDO,_tabsMgr->getUndoState(stundo));
791 GetToolBar()->SetToolShortHelp(ID_UNDO,crea::std2wx(stundo));
792 GetToolBar()->EnableTool(ID_REDO,_tabsMgr->getRedoState(stredo));
793 GetToolBar()->SetToolShortHelp(ID_REDO,crea::std2wx(stredo));
796 //=========================================================================
798 //The following method allows to save the current diagram asking the filename
800 void wxGUIEditorGraphicBBS::SaveCurrentDiagramAs() {
801 wxFileDialog * saveFileDialog = new wxFileDialog(this,
802 wxT("Save current diagram"), wxEmptyString, wxT("NewDiagram"),
803 wxT("*.bbg"), wxSAVE | wxOVERWRITE_PROMPT);
804 if (saveFileDialog->ShowModal() == wxID_OK) {
805 //_tabsMgr->SetNameTabPanel(saveFileDialog->GetFilename());
806 wxString pathfileName = saveFileDialog->GetPath();
807 std::string pathfilename = (const char*) (pathfileName.mb_str());
808 pathfilename=CheckExtension (pathfilename, ".bbg");
810 //modify the tab name accordingly
811 wxString fileName = saveFileDialog->GetFilename();
812 std::string filename = (const char*) (fileName.mb_str());
813 filename=CheckExtension (filename, ".bbg");
814 _tabsMgr->SetNameTabPanel( wxString (filename.c_str(), wxConvUTF8) );
816 std::string pathfilenamebbs = pathfilename;
817 pathfilenamebbs[pathfilenamebbs.length() - 1] = 's';
818 if (_tabsMgr->isActualDiagramComplexBox() == false) {
819 SaveActualDiagram(pathfilename);
820 SaveActualBBS(pathfilenamebbs);
822 AskComplexBoxConfiguration();
823 SaveActualDiagram(pathfilename);
824 SaveActualComplexBox(pathfilenamebbs);
825 } //if isActualDiagramComplexBox
826 } // if saveFileDialog
828 //=========================================================================
830 void wxGUIEditorGraphicBBS::OnSaveActualDiagram(wxCommandEvent& event) {
831 std::string pathfilename = _tabsMgr->GetCurrentTabPanelPath();
832 if (pathfilename.empty()) {
833 SaveCurrentDiagramAs();
835 std::string pathfilenamebbs = pathfilename;
836 pathfilenamebbs[pathfilenamebbs.length() - 1] = 's';
838 if (_tabsMgr->isActualDiagramComplexBox() == false) {
839 std::string name = _tabsMgr->GetNameTabPanel();
840 if(name[name.length() - 1] == '*')
842 name =name.substr(0,name.length()-1);
844 _tabsMgr->SetNameTabPanel(wxString (name.c_str(), wxConvUTF8));
845 SaveActualDiagram(pathfilename);
846 SaveActualBBS(pathfilenamebbs);
848 AskComplexBoxConfiguration();
849 SaveActualDiagram(pathfilename);
850 SaveActualComplexBox(pathfilenamebbs);
851 } //if isActualDiagramComplexBox
854 //=========================================================================
856 void wxGUIEditorGraphicBBS::OnSaveAsActualDiagram(wxCommandEvent& event) {
857 SaveCurrentDiagramAs();
860 //=========================================================================
861 void wxGUIEditorGraphicBBS::OnExportConsoleExecCommand(wxCommandEvent& event)
863 wxFileDialog * saveFileDialog = new wxFileDialog(this,
864 wxT("Export console command"), wxEmptyString, wxT("ConsoleApp.txt"),
865 wxT("*.txt;*.bbs;*.bbg;*.sh;*.bat"), wxSAVE | wxOVERWRITE_PROMPT);
867 if (saveFileDialog->ShowModal() == wxID_OK)
869 wxString fileName = saveFileDialog->GetPath();
870 std::string filename = (const char*) (fileName.mb_str());
871 filename=CheckExtension (filename, ".txt");
874 file.open(filename.c_str());
876 std::vector<std::string> extInputs = _tabsMgr->getActualTabPanel()->getSceneManager()->GetExternalInputsNames();
878 //TODO PUT IN A METHOD OF A FILES AND TEXT MANAGER CLASS !!!
879 //std::string inputsInCommentsWin="";
880 //std::string inputsInCommentsUnix="";
881 //std::string inputsInOneLineWin="";
882 std::string inputsInOneLineUnix="";
883 for (unsigned int i = 0; i < extInputs.size(); ++i)
885 /* No gusto la idea al jefe pero por si acaso ...
886 * RaC 2012 2nd HackFest
888 inputsInCommentsWin+="REM ";
889 inputsInCommentsWin+=extInputs[i];
890 inputsInCommentsWin+="=\"value\"\n";
891 inputsInCommentsUnix+="# ";
892 inputsInCommentsUnix+=extInputs[i];
893 inputsInCommentsUnix+="=\"value\"\n";
896 sprintf (buffer, "%d", (i+1));
897 inputsInOneLineWin+=extInputs[i];
898 inputsInOneLineWin+="=\"%";
899 inputsInOneLineWin+=buffer;
900 inputsInOneLineWin+="\" ";
902 inputsInOneLineUnix+=extInputs[i];
903 inputsInOneLineUnix+="=\"<value>\" ";
908 std::string content = "";
909 // writing file header
910 content += "# ----------------------------------\n";
911 content += "# - BBTKGEditor v ";
912 content += _currentBBGversion; //VERSION
913 content += " Console Commands to execute BBS application\n";
917 content += "# ----------------------------------\n";
920 content += "# Command to execute bbi\n";
921 content += "bbi <bbs_path> ";
922 content += inputsInOneLineUnix;
924 /* No gusto la idea al jefe pero por si acaso ...
925 * RaC 2012 2nd HackFest
926 content += "# For Windows (copy the following lines to a .bat file)\n";
927 content += "REM BBS application\n";
928 content += "REM Inputs:\n";
929 content += inputsInCommentsWin;
930 content += "REM To use previous inputs, put %$inputName% in the corresponding input of the execution bbi line\n";
931 content += "bbi applicationBBS.bbs ";
932 content += inputsInOneLineWin;
935 content += "# For Linux or Mac (copy the following lines to a .sh file)\n";
936 content += "#!/bin/bash\n";
937 content += "# BBS application\n";
938 content += "# Inputs:\n";
939 content += inputsInCommentsUnix;
940 content += "# To use previous inputs, put $inputName in the corresponding input of the execution bbi line\n";
941 content += "bbi applicationBBS.bbs ";
942 content += inputsInOneLineUnix;
953 //=========================================================================
955 void wxGUIEditorGraphicBBS::refreshGUIControls() {
958 //RaC2012 2ndHackFest Next line seems weird ... To keep in mind for other devels
959 wxToolBar* toolbar = GetToolBar();
960 if (_tabsMgr->isActualDiagramComplexBox()) {
961 toolbar->ToggleTool(ID_BTNCOMPLEXBOX, true);
962 //toolbar->EnableTool(ID_ADDCOMPLEXBOXINPUT, true); RaC2012 2nd HackFest
963 toolbar->EnableTool(ID_ADDCOMPLEXBOXOUTPUT, true);
965 GetMenuBar()->GetMenu(0)->Enable(ID_SAVE_AS_COMPLEXBOX, true);
966 GetMenuBar()->GetMenu(0)->Enable(ID_SAVE_AS_BBS, false);
967 GetMenuBar()->GetMenu(0)->Enable(ID_EXPORT_CONSOLEAPP, false);
969 toolbar->ToggleTool(ID_BTNCOMPLEXBOX, false);
970 //toolbar->EnableTool(ID_ADDCOMPLEXBOXINPUT, false); RaC2012 2nd HackFest
971 toolbar->EnableTool(ID_ADDCOMPLEXBOXOUTPUT, false);
973 GetMenuBar()->GetMenu(0)->Enable(ID_SAVE_AS_COMPLEXBOX, false);
974 GetMenuBar()->GetMenu(0)->Enable(ID_SAVE_AS_BBS, true);
975 GetMenuBar()->GetMenu(0)->Enable(ID_EXPORT_CONSOLEAPP, true);
978 //RaC2012 2ndHackFest
979 GetToolBar()->EnableTool(ID_EDITPROPERTIES,true);
981 GetToolBar()->EnableTool(ID_UNDO,_tabsMgr->getUndoState(stundo));
982 GetToolBar()->SetToolShortHelp(ID_UNDO,crea::std2wx(stundo));
983 GetToolBar()->EnableTool(ID_REDO,_tabsMgr->getRedoState(stredo));
984 GetToolBar()->SetToolShortHelp(ID_REDO,crea::std2wx(stredo));
986 if (_tabsMgr->getNumActualSelectedObjects() > 0) {
987 GetMenuBar()->GetMenu(1)->Enable(ID_COPY_TO_COMPLEXDIAGRAM, true);
989 ///TODO Fix the possibility to say from the SceneManager to the GUI to refresh the options
990 GetMenuBar()->GetMenu(1)->Enable(ID_COPY_TO_COMPLEXDIAGRAM, true);
995 //=========================================================================
997 void wxGUIEditorGraphicBBS::OnDeleteAllBoxesActualDiagram(wxCommandEvent& event)
999 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);
1000 if (dial->ShowModal() == wxID_YES)
1002 _tabsMgr->deleteAllBoxesActualDiagram();
1006 //=========================================================================
1008 void wxGUIEditorGraphicBBS::OnCenterViewActualDiagram(wxCommandEvent& event)
1010 _tabsMgr->centerViewActualDiagram();
1013 //=========================================================================
1014 void wxGUIEditorGraphicBBS::OpenDiagram(std::string filePathName, std::string fileName)
1016 ifstream inputStream;
1017 inputStream.open(filePathName.c_str());
1018 assert(inputStream.good()); // fails
1020 if(_tabsMgr->FindTab(filePathName)!=-1) //RaC2012 avoid opening same diagram twice
1022 inputStream.close();
1023 printf("RaC: Diagram already opened\n");
1026 _tabsMgr->addNewTab( crea::std2wx(fileName) );
1027 _tabsMgr->loadDiagram(inputStream, filePathName);
1028 _tabsMgr->saveTempActualDiagram("load diagram");
1029 GetToolBar()->EnableTool(ID_UNDO, false);
1030 GetToolBar()->EnableTool(ID_UNDO, false);
1031 inputStream.close();
1032 refreshGUIControls();
1035 //=========================================================================
1037 void wxGUIEditorGraphicBBS::OnOpenDiagram(wxCommandEvent& event)
1039 wxFileDialog * openFileDialog = new wxFileDialog(this, wxT("Open diagram"), wxEmptyString, wxT(""), wxT("*.bbg"), wxOPEN | wxFILE_MUST_EXIST);
1040 if (openFileDialog->ShowModal() == wxID_OK)
1042 wxString filePath = openFileDialog->GetPath();
1043 wxString fileName = openFileDialog->GetFilename();
1044 OpenDiagram( crea::wx2std(filePath) , crea::wx2std(fileName) );
1048 //=========================================================================
1049 void wxGUIEditorGraphicBBS::OnClickBtnBox(wxCommandEvent& event)
1051 BlackBoxDescriptor *bbDes = _pkgBrowser->GetActualSelected();
1052 if (bbDes != NULL) {
1053 std::string typeName = bbDes->GetTypeName();
1054 std::string packageName = bbDes->GetPackage()->GetName();
1055 wxGEditorTabPanel *pnl = this->_tabsMgr->getActualTabPanel();
1057 wxVtkSceneManager *scn = pnl->getSceneManager();
1058 scn->createGBlackBox(50, 50, packageName, typeName);
1061 SaveTempActualDiagram("New Box");
1066 //=========================================================================
1068 void wxGUIEditorGraphicBBS::OnClickBtnExecutableBox(wxCommandEvent& event)
1071 wxGEditorTabPanel *pnl = this->_tabsMgr->getActualTabPanel();
1074 wxVtkSceneManager *scn = pnl->getSceneManager();
1075 if( scn->MakeBoxExecutable() )
1076 std::cout<<"DFCH: wxGUIEditorGraphicBBS::OnClickBtnExecutableBox...successful"<<std::endl;
1078 std::cout<<"DFCH: wxGUIEditorGraphicBBS::OnClickBtnExecutableBox...Error!!"<<std::endl;
1084 //=========================================================================
1085 void wxGUIEditorGraphicBBS::OnClickBtnComplexBox(wxCommandEvent& event)
1087 wxToolBar* toolbar = GetToolBar();
1088 bool temp = toolbar->GetToolState(ID_BTNCOMPLEXBOX);
1092 disableComplexBox();
1096 //=========================================================================
1098 void wxGUIEditorGraphicBBS::OnAddComplexBoxInput(wxCommandEvent& event)
1100 wxTextEntryDialog *nameDialog = new wxTextEntryDialog(this,
1101 wxT("Name of input port"));
1102 if (nameDialog->ShowModal() == wxID_OK)
1104 wxString fileName = nameDialog->GetValue();
1105 if (!fileName.IsEmpty())
1107 std::string portName = (const char*) (fileName.mb_str());
1108 if ( !boxNameExists(portName) )
1110 _tabsMgr->addActualDiagramComplexInputPort(portName);
1112 wxMessageDialog *dial = new wxMessageDialog(NULL,
1113 wxT("Impossible to create Box. The name already exists. Please provide another name"),
1114 wxT("Change name: name already exists"), wxOK | wxICON_EXCLAMATION | wxSTAY_ON_TOP);
1121 //=========================================================================
1122 void wxGUIEditorGraphicBBS::OnAddComplexBoxOutput(wxCommandEvent& event)
1124 wxTextEntryDialog *nameDialog = new wxTextEntryDialog(this,
1125 wxT("Name of output port"));
1126 if (nameDialog->ShowModal() == wxID_OK)
1128 wxString fileName = nameDialog->GetValue();
1129 if (!fileName.IsEmpty())
1131 std::string portName = (const char*) (fileName.mb_str());
1132 if ( !boxNameExists(portName) )
1134 _tabsMgr->addActualDiagramComplexOutputPort(portName);
1136 wxMessageDialog *dial = new wxMessageDialog(NULL,
1137 wxT("Impossible to create Box. The name already exists. Please provide another name"),
1138 wxT("Change name: name already exists"), wxOK | wxICON_EXCLAMATION | wxSTAY_ON_TOP);
1146 //=========================================================================
1147 void wxGUIEditorGraphicBBS::OnCopySelectedToComplexDiagram(
1148 wxCommandEvent& event)
1150 _tabsMgr->copySelectedBBoxesToComplexDiagram();
1153 //=========================================================================
1154 void wxGUIEditorGraphicBBS::OnHelpBBeditor(wxCommandEvent& event)
1156 printf("wxGUIEditorGraphicBBS::OnHelpBBeditor ....not implemented..\n");
1159 //=========================================================================
1160 void wxGUIEditorGraphicBBS::OnCreatePackage(wxCommandEvent& event)
1162 bbtkSystemTools::CreatePackage();
1165 //=========================================================================
1166 void wxGUIEditorGraphicBBS::OnCreateBlackBox(wxCommandEvent& event)
1168 bbtkSystemTools::CreateBlackBox();
1171 //=========================================================================
1172 void wxGUIEditorGraphicBBS::OnPlugPackage(wxCommandEvent& event)
1174 //DFGO2012 Plug Package functionnalities
1175 long style = wxDD_DEFAULT_STYLE | wxDD_DIR_MUST_EXIST;
1178 _T("Select package directory"),
1184 userResponse = FD->ShowModal();
1185 if(userResponse==wxID_OK)
1187 std::string path = wx2std (FD->GetPath()) ;
1189 std::string fname = path + "\\bbtkPackage";
1191 std::string fname = path + "/bbtkPackage";
1194 std::cout << "Path chosen = \"" << FD->GetPath() << "\"" << std::endl;
1195 if ( Utilities::FileExists( fname ) )
1198 f.open(fname.c_str());
1201 while(pname[0] == '#')
1203 getline(f, pname, '\n');
1208 bbtk::ConfigurationFile::GetInstance().AddPackagePathsAndWrite( path );
1210 DoRegeneratePackageDoc(pname);
1211 DoRegenerateBoxesLists();
1213 _pkgBrowser->RebuildList();
1215 wxMessageBox(_T("Package successfully plugged. Please restart bbEditor to see the new package in the package browser."),_T("Plug package"),wxOK | wxICON_INFORMATION);
1216 userResponse = wxID_CANCEL;
1220 std::string err = "The directory \"" + path + "\" does not contain a 'bbtkPackage' file.";
1223 err += "\nNote: If you are on Linux please select the folder and click \"Open\", don't enter in it.";
1227 wxMessageBox(crea::std2wx(err), _T("Plug package"),wxOK | wxICON_ERROR);
1228 // THE FOLLOWING LINE GIVES ERRORS BECAUSE IT IS NECESSARY TO USE std2wx
1229 //wxMessageBox( _T( err) , _T("Plug package"),wxOK | wxICON_ERROR);
1232 }while(userResponse != wxID_CANCEL);
1236 //=========================================================================
1237 void wxGUIEditorGraphicBBS::OnEditConfig(wxCommandEvent& event)
1239 std::string commandStr;
1240 std::string configFile = ConfigurationFile::GetInstance().Get_config_xml_full_path();
1242 commandStr = "notepad.exe ";
1244 commandStr = "gedit ";
1246 commandStr = commandStr + configFile;
1247 std::cout << "system: " << commandStr << std::endl;
1248 system ( commandStr.c_str() );
1251 //=========================================================================
1252 void wxGUIEditorGraphicBBS::OnShowHTMLDoc(wxCommandEvent& event)
1255 if (_helpHtmlBrowser != NULL){
1256 _frameAUIMgr->DetachPane(_helpHtmlBrowser);
1257 _helpHtmlBrowser->Destroy();
1259 initHelpHTMLBrowser();
1260 _frameAUIMgr->AddPane(_helpHtmlBrowser, wxAuiPaneInfo().Right().MinSize(200, 200));
1261 _frameAUIMgr->Update();
1262 refreshGUIControls();
1267 //=========================================================================
1268 void wxGUIEditorGraphicBBS::OnCreateIndex(wxCommandEvent& event)
1270 printf("EED wxGUIEditorGraphicBBS::OnCreateIndex ... not implemented ..\n");
1274 //=========================================================================
1275 void wxGUIEditorGraphicBBS::OnEditComplexBoxScript(wxCommandEvent& event)
1277 BlackBoxDescriptor *bbDes = _pkgBrowser->GetActualSelected();
1280 std::string packageName = bbDes->GetPackage()->GetName();
1281 std::string typeName = bbDes->GetTypeName();
1282 if (!TryToOpenScriptComplexBox(packageName ,typeName))
1284 wxMessageDialog windowMessage1(NULL,_T("This is not a ComplexBox script."), _T("Alert !"), wxOK);
1285 windowMessage1.ShowModal();
1290 //=========================================================================
1291 void wxGUIEditorGraphicBBS::OnExit(wxCommandEvent& event)
1296 Factory::Pointer wxGUIEditorGraphicBBS::GetBBTKFactory()
1298 if (_pkgBrowser==NULL)
1300 printf ("EED ERROR! wxGUIEditorGraphicBBS::GetBBTKFactory _pkgBrowser = NULL\n");
1302 return _pkgBrowser->GetFactory();
1305 //=========================================================================
1306 void wxGUIEditorGraphicBBS::enableComplexBox()
1308 _tabsMgr->setActualDiagramComplexBox(true);
1309 refreshGUIControls();
1312 //=========================================================================
1314 void wxGUIEditorGraphicBBS::disableComplexBox()
1316 _tabsMgr->setActualDiagramComplexBox(false);
1317 refreshGUIControls();
1320 //=========================================================================
1321 void wxGUIEditorGraphicBBS::setCurrentDiagramDescription(std::string description)
1323 _tabsMgr->SetDescription(description);
1326 //=========================================================================
1327 void wxGUIEditorGraphicBBS::setCurrentDiagramAuthor(std::string author)
1329 _tabsMgr->SetAuthor(author);
1332 //=========================================================================
1333 void wxGUIEditorGraphicBBS::setCurrentDiagramCategory(std::string category)
1335 _tabsMgr->SetCategory(category);
1338 //=========================================================================
1339 std::string wxGUIEditorGraphicBBS::getCurrentDiagramDescription()
1341 return _tabsMgr->GetDescription();
1344 //=========================================================================
1345 std::string wxGUIEditorGraphicBBS::getCurrentDiagramAuthor()
1347 return _tabsMgr->GetAuthor();
1350 //=========================================================================
1351 std::string wxGUIEditorGraphicBBS::getCurrentDiagramCategory()
1353 return _tabsMgr->GetCategory();
1357 //=========================================================================
1358 bool wxGUIEditorGraphicBBS::isCurrentDiagramComplexBox()
1360 return _tabsMgr->isActualDiagramComplexBox();
1364 //=========================================================================
1365 void wxGUIEditorGraphicBBS::OpenScript(std::string filePathNameBBS ,std::string boxType)
1367 std::string fileName = boxType+".bbg";
1368 std::string filePathNameBBG = filePathNameBBS;
1369 filePathNameBBG[ filePathNameBBG.length()-1 ] = 'g';
1371 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);
1372 windowMessage1.ShowModal();
1374 if ( Utilities::FileExists( filePathNameBBG ) )
1376 OpenDiagram( filePathNameBBG , fileName );
1378 if ( Utilities::FileExists( filePathNameBBS ) )
1380 OpenBBS( filePathNameBBS , fileName );
1382 wxMessageDialog windowMessage1(NULL,_T("..ERROR.. loading script bbg/bbs."), _T("Alert !"), wxOK);
1383 windowMessage1.ShowModal();
1390 //=========================================================================
1391 bool wxGUIEditorGraphicBBS::TryToOpenScriptApplication(std::string packageName ,std::string boxType)
1393 return TryToOpenScript(packageName ,boxType, true, false);
1396 //=========================================================================
1397 bool wxGUIEditorGraphicBBS::TryToOpenScriptComplexBox(std::string packageName ,std::string boxType)
1399 return TryToOpenScript(packageName ,boxType, false, true);
1403 //=========================================================================
1404 bool wxGUIEditorGraphicBBS::TryToOpenScript(std::string packageName ,std::string boxType,bool scriptApplication, bool scriptComplexBox)
1407 std::map< std::string, BlackBoxDescriptor::Pointer> mapDesc;
1408 BlackBoxDescriptor::Pointer descriptor;
1409 k = GetBBTKFactory()->GetPackage(packageName);
1410 mapDesc = k->GetDescriptorMap();
1411 descriptor = mapDesc[boxType];
1416 ((descriptor->IsTypeOfScript_Application()==true) && (scriptApplication==true))
1418 ((descriptor->IsTypeOfScript_ComplexBox()==true) && (scriptComplexBox==true))
1422 OpenScript(descriptor->GetScriptFileName(),boxType);
1428 } // EO namespace bbtk