00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00036 #include "bbtkwxGUIEditorGraphicBBS.h"
00037 #include "creaWx.h"
00038 #include "creaSystem.h"
00039 #include <wx/defs.h>
00040
00041 #include <InterpreterBBS.h>
00042
00043 namespace bbtk {
00044
00045
00046 wxGUIEditorGraphicBBS::wxGUIEditorGraphicBBS(wxFrame *parent) :
00047 wxFrame(parent, -1, _T("bbtkGEditor"), wxDefaultPosition, wxSize(
00048 1200, 800)) {
00049
00050 _frameAUIMgr = new wxAuiManager(this);
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068 initMenu();
00069 initToolbar();
00070 initTabPanelsManager();
00071 initPackageBrowser();
00072
00073 _helpHtmlBrowser = NULL;
00074 CreateStatusBar();
00075 _frameAUIMgr->Update();
00076 _actualPkgBrowserBoxName = "";
00077 _actualPkgBrowserPkgName = "";
00078 refreshGUIControls();
00079 }
00080
00081
00082 wxGUIEditorGraphicBBS::~wxGUIEditorGraphicBBS() {
00083
00084 printf("EED %p ~wxGUIEditorGraphicBBS()\n", this);
00085
00086
00087
00088 _frameAUIMgr->UnInit();
00089
00090 delete _frameAUIMgr;
00091 delete _notebook;
00092 delete _tabsMgr;
00093
00094 }
00095
00096
00097 void wxGUIEditorGraphicBBS::initToolbar() {
00098 wxBitmap bmp_new(new_xpm);
00099 wxBitmap bmp_open(open_xpm);
00100 wxBitmap bmp_save(save_xpm);
00101 wxBitmap bmp_run(run_xpm);
00102 wxBitmap bmp_delete(delete_xpm);
00103 wxBitmap bmp_centerview(centerview_xpm);
00104 wxBitmap bmp_box(box_xpm);
00105 wxBitmap bmp_executablebox(executablebox_xpm);
00106 wxBitmap bmp_complexbox(complexbox_xpm);
00107 wxBitmap bmp_complexinputport(complexinputport_xpm);
00108 wxBitmap bmp_complexoutputport(complexoutputport_xpm);
00109 wxBitmap bmp_undo(undo_xpm);
00110 wxBitmap bmp_redo(redo_xpm);
00111 wxToolBar *toolbar = new wxToolBar(this, wxID_ANY);
00112
00113
00114 toolbar->AddTool(ID_NEW, _T("New"), bmp_new, wxNullBitmap, wxITEM_NORMAL,
00115 _T("New tab"), _T("Create a new panel tab"));
00116 toolbar->AddTool(ID_OPEN, _T("Open diagram"), bmp_open, wxNullBitmap,
00117 wxITEM_NORMAL, _T("Open a diagram"), _T("Open a diagram"));
00118 toolbar->AddTool(ID_SAVE_DIAGRAM, _T("Save Diagram"), bmp_save,
00119 wxNullBitmap, wxITEM_NORMAL, _T("Saves the current diagram"),
00120 _T("Saves the current diagram"));
00121
00122 toolbar->AddTool(ID_RUN, _T("Run"), bmp_run, wxNullBitmap, wxITEM_NORMAL,
00123 _T("Execute actual diagram"), _T("Execute actual diagram"));
00124 toolbar->AddTool(ID_DELETEALL, _T("Delete all"), bmp_delete, wxNullBitmap,
00125 wxITEM_NORMAL, _T("Delete all boxes"), _T("Delete all boxes"));
00126 toolbar->AddTool(ID_CENTERVIEW, _T("Center view"), bmp_centerview,
00127 wxNullBitmap, wxITEM_NORMAL, _T("Center view"), _T("Center view"));
00128 toolbar->AddSeparator();
00129 toolbar->AddTool(ID_BTNBOX, _T("New Box"), bmp_box, wxNullBitmap,
00130 wxITEM_NORMAL, _T("New Box"), _T("Nex Box"));
00131 toolbar->AddSeparator();
00132 toolbar->AddTool(ID_BTEXECUTABLEBOX, _T("Select as executable Box"),
00133 bmp_executablebox, wxNullBitmap, wxITEM_NORMAL,
00134 _T("Select as executable Box"), _T("Select as executable Box"));
00135 toolbar->AddSeparator();
00136 toolbar->AddTool(ID_BTNCOMPLEXBOX, _T("Complex box"), complexbox_xpm,
00137 wxNullBitmap, wxITEM_NORMAL, _T("Complex box"), _T("Complex box"));
00138 toolbar->SetToggle(ID_BTNCOMPLEXBOX, true);
00139 toolbar->AddTool(ID_ADDCOMPLEXBOXINPUT, _T("Add input to Complex box"),
00140 bmp_complexinputport, wxNullBitmap, wxITEM_NORMAL,
00141 _T("Add input to Complex box"), _T("Add input to Complex box"));
00142 toolbar->AddTool(ID_ADDCOMPLEXBOXOUTPUT, _T("Add output to Complex box"),
00143 bmp_complexoutputport, wxNullBitmap, wxITEM_NORMAL,
00144 _T("Add output Complex box"), _T("Add output Complex box"));
00145 toolbar->EnableTool(ID_ADDCOMPLEXBOXINPUT, false);
00146 toolbar->EnableTool(ID_ADDCOMPLEXBOXOUTPUT, false);
00147 toolbar->AddSeparator();
00148 toolbar->AddTool(ID_UNDO, _T("Undo"),bmp_undo, wxNullBitmap, wxITEM_NORMAL, _T("Undo"), _T("Undo"));
00149 toolbar->AddTool(ID_REDO, _T("Redo"),bmp_redo, wxNullBitmap, wxITEM_NORMAL, _T("Redo"), _T("Redo"));
00150
00151 toolbar->EnableTool(ID_UNDO, false);
00152 toolbar->EnableTool(ID_REDO, false);
00153 toolbar->SetMargins(2, 2);
00154 toolbar->Realize();
00155 SetToolBar(toolbar);
00156
00157
00158
00159
00160 Connect(ID_NEW, wxEVT_COMMAND_TOOL_CLICKED,
00161 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnCreateNewTab));
00162 Connect(ID_OPEN, wxEVT_COMMAND_TOOL_CLICKED,
00163 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnOpenDiagram));
00164 Connect(ID_SAVE_DIAGRAM, wxEVT_COMMAND_TOOL_CLICKED,
00165 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnSaveActualDiagram));
00166 Connect(ID_SAVE_AS_DIAGRAM, wxEVT_COMMAND_TOOL_CLICKED,
00167 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnSaveAsActualDiagram));
00168 Connect(
00169 ID_RUN,
00170 wxEVT_COMMAND_TOOL_CLICKED,
00171 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnExecuteActualDiagram));
00172 Connect(
00173 ID_DELETEALL,
00174 wxEVT_COMMAND_TOOL_CLICKED,
00175 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnDeleteAllBoxesActualDiagram));
00176 Connect(
00177 ID_CENTERVIEW,
00178 wxEVT_COMMAND_TOOL_CLICKED,
00179 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnCenterViewActualDiagram));
00180 Connect(ID_BTNBOX, wxEVT_COMMAND_TOOL_CLICKED,
00181 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnClickBtnBox));
00182 Connect(
00183 ID_BTEXECUTABLEBOX,
00184 wxEVT_COMMAND_TOOL_CLICKED,
00185 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnClickBtnExecutableBox));
00186 Connect(ID_BTNCOMPLEXBOX, wxEVT_COMMAND_TOOL_CLICKED,
00187 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnClickBtnComplexBox));
00188 Connect(ID_ADDCOMPLEXBOXINPUT, wxEVT_COMMAND_TOOL_CLICKED,
00189 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnAddComplexBoxInput));
00190 Connect(ID_ADDCOMPLEXBOXOUTPUT, wxEVT_COMMAND_TOOL_CLICKED,
00191 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnAddComplexBoxOutput));
00192 Connect(ID_UNDO,wxEVT_COMMAND_TOOL_CLICKED, wxCommandEventHandler(wxGUIEditorGraphicBBS::OnUndo));
00193 Connect(ID_REDO,wxEVT_COMMAND_TOOL_CLICKED, wxCommandEventHandler(wxGUIEditorGraphicBBS::OnRedo));
00194 Connect(ID_CHANGENAME, wxEVT_COMMAND_RIGHT_CLICK, wxCommandEventHandler(wxGUIEditorGraphicBBS::OnChangeName));
00195 }
00196
00197 void wxGUIEditorGraphicBBS::initHelpHTMLBrowser() {
00198
00199 _helpHtmlBrowser = new WxGUIHtmlBrowser(this, wxSize(200, 0));
00200
00201
00202
00203 }
00204
00205
00206 void wxGUIEditorGraphicBBS::initMenu() {
00207
00208 wxMenu *fileMenu = new wxMenu();
00209 fileMenu->Append(ID_NEW, _T("New diagram"), _T("New"));
00210 fileMenu->Append(ID_SAVE_DIAGRAM, _T("Save Diagram"), _T("Save Diagram"));
00211 fileMenu->Append(ID_SAVE_AS_DIAGRAM, _T("Save Diagram As"),
00212 _T("Save Diagram As"));
00213 fileMenu->Append(ID_OPEN_BBS, _T("Open BBS"), _T("Open BBS"));
00214
00215 fileMenu->Append(ID_OPEN, _T("Open a diagram"), _T("Open a diagram"));
00216 fileMenu->Append(ID_SAVE_AS_BBS, _T("Save BBS"), _T("Save BBS"));
00217 fileMenu->Append(ID_SAVE_AS_COMPLEXBOX, _T("Save complex box"),
00218 _T("Save complex box"));
00219 fileMenu->Append(wxID_EXIT, _T("E&xit"), _T("Exit"));
00220
00221 Connect(ID_NEW, wxEVT_COMMAND_MENU_SELECTED,
00222 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnCreateNewTab));
00223 Connect(ID_SAVE_DIAGRAM, wxEVT_COMMAND_MENU_SELECTED,
00224 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnSaveActualDiagram));
00225 Connect(ID_SAVE_AS_DIAGRAM, wxEVT_COMMAND_MENU_SELECTED,
00226 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnSaveAsActualDiagram));
00227 Connect(ID_OPEN_BBS, wxEVT_COMMAND_MENU_SELECTED,
00228 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnOpenBBS));
00229 Connect(ID_SAVE_AS_BBS, wxEVT_COMMAND_MENU_SELECTED,
00230 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnSaveActualBBS));
00231 Connect(
00232 ID_SAVE_AS_COMPLEXBOX,
00233 wxEVT_COMMAND_MENU_SELECTED,
00234 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnSaveActualComplexBox));
00235 Connect(wxID_EXIT, wxEVT_COMMAND_MENU_SELECTED,
00236 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnExit));
00237
00238
00239 wxMenu *editMenu = new wxMenu;
00240 editMenu->Append(ID_COPY_TO_COMPLEXDIAGRAM,
00241 _T("Copy selected to complex box"),
00242 _T("Creates a new complex box diagram with selected boxes"));
00243
00244 Connect(
00245 ID_COPY_TO_COMPLEXDIAGRAM,
00246 wxEVT_COMMAND_MENU_SELECTED,
00247 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnCopySelectedToComplexDiagram));
00248
00249
00250 wxMenu *helpMenu = new wxMenu;
00251 helpMenu->Append(wxID_ABOUT, _T("&About..."), _T("About"));
00252 helpMenu->Append(ID_HELP_BBEDITOR, _T("&Help..."), _T("Help"));
00253 Connect(ID_HELP_BBEDITOR, wxEVT_COMMAND_MENU_SELECTED,
00254 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnHelpBBeditor));
00255
00256
00257 wxMenu *menuTools = new wxMenu;
00258 menuTools->Append(ID_bbEditor_Tool_Menu_CreatePackage,
00259 _T("Create &package") );
00260 menuTools->Append(ID_bbEditor_Tool_Menu_CreateBlackBox,
00261 _T("Create &blackbox") );
00262 menuTools->Append(ID_bbEditor_Tool_Menu_PlugPackage, _T("Plug package") );
00263 menuTools->Append(ID_bbEditor_Tool_Menu_EditConfig, _T("&Edit bbtk config") );
00264 menuTools->Append(ID_bbEditor_Tool_Menu_ShowHTMLDoc,
00265 _T("Show &HTML documentation") );
00266 menuTools->Append(ID_bbEditor_Tool_Menu_CreateIndex, _T("&Generate index") );
00267
00268 Connect(ID_bbEditor_Tool_Menu_CreatePackage, wxEVT_COMMAND_MENU_SELECTED,
00269 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnCreatePackage));
00270 Connect(ID_bbEditor_Tool_Menu_CreateBlackBox, wxEVT_COMMAND_MENU_SELECTED,
00271 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnCreateBlackBox));
00272 Connect(ID_bbEditor_Tool_Menu_PlugPackage, wxEVT_COMMAND_MENU_SELECTED,
00273 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnPlugPackage));
00274 Connect(ID_bbEditor_Tool_Menu_EditConfig, wxEVT_COMMAND_MENU_SELECTED,
00275 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnEditConfig));
00276 Connect(ID_bbEditor_Tool_Menu_ShowHTMLDoc, wxEVT_COMMAND_MENU_SELECTED,
00277 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnShowHTMLDoc));
00278 Connect(ID_bbEditor_Tool_Menu_CreateIndex, wxEVT_COMMAND_MENU_SELECTED,
00279 wxCommandEventHandler(wxGUIEditorGraphicBBS::OnCreateIndex));
00280
00281
00282 wxMenuBar *menuBar = new wxMenuBar();
00283 menuBar->Append(fileMenu, _T("&File") );
00284 menuBar->Append(editMenu, _T("&Edit") );
00285 menuBar->Append(menuTools, _T("&Tool") );
00286 menuBar->Append(helpMenu, _T("&Help") );
00287
00288
00289 SetMenuBar(menuBar);
00290 }
00291
00292
00293 void wxGUIEditorGraphicBBS::initTabPanelsManager() {
00294 _notebook = new wxAuiNotebook(this, wxID_NOTEBOOK, wxDefaultPosition,
00295 wxDefaultSize, wxAUI_NB_TOP | wxAUI_NB_TAB_MOVE
00296 | wxAUI_NB_CLOSE_ON_ACTIVE_TAB | wxAUI_NB_TAB_FIXED_WIDTH
00297 | wxAUI_NB_WINDOWLIST_BUTTON);
00298 _tabsMgr = new wxTabPanelsManager(this);
00299 _frameAUIMgr->AddPane(_notebook, wxAuiPaneInfo().CenterPane());
00300
00301 }
00302
00303
00304 void wxGUIEditorGraphicBBS::initPackageBrowser() {
00305 _pkgBrowser = new WxGUIPackageBrowser2(this);
00306 _pkgBrowser->IncludeAll();
00307 _frameAUIMgr->AddPane(_pkgBrowser,
00308 wxAuiPaneInfo().Left().MinSize(480, 400).CloseButton(false));
00309 }
00310
00311
00312
00313 void wxGUIEditorGraphicBBS::DoRegeneratePackageDoc(const std::string& pack) {
00314 std::string mess("Regenerating doc for package '");
00315 if (pack != "-a") {
00316 mess += pack + "'";
00317 } else {
00318 mess = "Regenerating doc for all packages";
00319 }
00320
00321 mess += " ... please wait";
00322
00323 SetStatusText(std2wx(mess));
00324
00325
00326
00327 std::string command;
00328 #if defined(WIN32)
00329 command = "\"";
00330 #endif
00331 command += ConfigurationFile::GetInstance().Get_bin_path();
00332 command += ConfigurationFile::GetInstance().Get_file_separator();
00333 command += "bbRegeneratePackageDoc";
00334 #if defined(WIN32)
00335 command += "\"";
00336 #endif
00337
00338 command += " " + pack + " -q";
00339 bbtkMessage("debug",1,"Executing system command '"<<command<<"'"<<std::endl);
00340
00341 if (!system(command.c_str())) {
00342 SetStatusText(_T("Done !"));
00343
00344
00345
00346
00347
00348 } else {
00349 SetStatusText(_T("Done !"));
00350 wxString err(_T("An error occured while running '"));
00351 err += bbtk::std2wx(command) + _T("'");
00352 wxMessageBox(err, _T("Regenerate package doc"), wxOK | wxICON_ERROR);
00353 }
00354 }
00355
00356
00357 void wxGUIEditorGraphicBBS::DoRegenerateBoxesLists() {
00358 SetStatusText(_T("Regenerating boxes lists ... please wait"));
00359
00360
00361 std::string command;
00362 #if defined(WIN32)
00363 command = "\"";
00364 #endif
00365 command += ConfigurationFile::GetInstance().Get_bin_path();
00366 command += ConfigurationFile::GetInstance().Get_file_separator();
00367 command += "bbRegenerateBoxesLists";
00368
00369 #if defined(WIN32)
00370 command += "\"";
00371 #endif
00372 command += " -q";
00373
00374 bbtkMessage("debug",1,"Executing system command '"<<command<<"'"<<std::endl);
00375
00376 if (!system(command.c_str())) {
00377 SetStatusText(_T("Done !"));
00378
00379
00380
00381
00382 } else {
00383 SetStatusText(_T("Done !"));
00384 wxString err(_T("An error occured while running '"));
00385 err += bbtk::std2wx(command) + _T("'");
00386 wxMessageBox(err, _T("Regenerate boxes lists"), wxOK | wxICON_ERROR);
00387 }
00388 }
00389
00390
00391 void wxGUIEditorGraphicBBS::RegenerateAll() {
00392 DoRegeneratePackageDoc("-a");
00393 DoRegenerateBoxesLists();
00394 }
00395
00396
00397
00398 wxAuiNotebook* wxGUIEditorGraphicBBS::getAuiNotebook() {
00399 return _notebook;
00400 }
00401
00402
00403
00404 void wxGUIEditorGraphicBBS::displayBlackBoxInfo(std::string packageName,
00405 std::string boxName) {
00406 if (_actualPkgBrowserPkgName != packageName || _actualPkgBrowserBoxName
00407 != boxName) {
00408 _actualPkgBrowserPkgName = packageName;
00409 _actualPkgBrowserBoxName = boxName;
00410
00411 BlackBoxDescriptor::Pointer descriptor =
00412 GObjectsMVCFactory::getInstance()->getBlackBoxDescriptor(
00413 packageName, boxName);
00414 _pkgBrowser->WxGUIBlackBoxListUserOnSelected(descriptor.get());
00415 }
00416 }
00417
00418
00419
00420 void wxGUIEditorGraphicBBS::editBlackBox(GBlackBoxModel *bbmodel) {
00421 wxBlackBoxEditionDialog* dialog =
00422 new wxBlackBoxEditionDialog(this, bbmodel);
00423 dialog->Show();
00424 }
00425
00426
00427
00428 bool wxGUIEditorGraphicBBS::boxNameExists(std::string boxname) {
00429
00430 return this->_tabsMgr->getActualTabPanel()->getSceneManager()->boxExist(boxname);
00431 }
00432
00433
00434
00435 void wxGUIEditorGraphicBBS::updateStatusBar(std::string textStatus) {
00436 SetStatusText(crea::std2wx(textStatus));
00437 }
00438
00439
00440
00441 void wxGUIEditorGraphicBBS::executeScript(std::string script) {
00442 std::string separator =
00443 ConfigurationFile::GetInstance().Get_file_separator();
00444 std::string dir = ConfigurationFile::GetInstance().Get_default_temp_dir();
00445 std::string filename = dir + separator + "tmp_bbtk.bbs";
00446
00447 ofstream tempFile;
00448 tempFile.open(filename.c_str());
00449 tempFile << script;
00450 tempFile.close();
00451
00452 std::string command = "";
00453
00454 #ifdef WIN32
00455 command += "start /b ";
00456 #endif
00457
00458
00459
00460
00461
00462
00463 command += "bbi ";
00464 command += "\"" + filename + "\"";
00465
00466 #ifndef WIN32
00467 command += " & ";
00468 #endif
00469
00470 printf("RaC wxGUIEditorGraphicBBS::executeScript %s \n", command.c_str());
00471 system(command.c_str());
00472 }
00473
00474
00475 std::string wxGUIEditorGraphicBBS::CheckExtension(std::string filename, std::string extension) {
00476 if(filename.size() > extension.size() ){
00477 if( (filename.compare(filename.size()-extension.size(), extension.size(),extension)) !=0 ){
00478 filename.append(extension);
00479 }
00480 }else{
00481 filename.append(extension);
00482 }
00483 return filename;
00484 }
00485
00486
00487
00488
00489 void wxGUIEditorGraphicBBS::OnCreateNewTab(wxCommandEvent& event) {
00490 _tabsMgr->addNewTab();
00491 refreshGUIControls();
00492 }
00493
00494 void wxGUIEditorGraphicBBS::OnUndo(wxCommandEvent& event) {
00495 unsigned short disable;
00496 std::string stundo;
00497 std::string stredo;
00498
00499 _tabsMgr->loadTempDiagram(0);
00500 disable = _tabsMgr->getUndoState(stundo);
00501 if(disable == 0)
00502 {
00503 std::string name = _tabsMgr->GetNameTabPanel();
00504 if(name[name.length() - 1] == '*')
00505 {
00506 name =name.substr(0,name.length()-1);
00507 }
00508 _tabsMgr->SetNameTabPanel(wxString (name.c_str(), wxConvUTF8));
00509 }
00510
00511 GetToolBar()->EnableTool(ID_UNDO,disable);
00512 GetToolBar()->SetToolShortHelp(ID_UNDO,crea::std2wx(stundo));
00513 GetToolBar()->EnableTool(ID_REDO,_tabsMgr->getRedoState(stredo));
00514 GetToolBar()->SetToolShortHelp(ID_REDO,crea::std2wx(stredo));
00515 refreshGUIControls();
00516 }
00517
00518 void wxGUIEditorGraphicBBS::OnRedo(wxCommandEvent& event) {
00519 unsigned short disable;
00520 std::string stundo;
00521 std::string stredo;
00522
00523 _tabsMgr->loadTempDiagram(1);
00524 std::string name = _tabsMgr->GetNameTabPanel();
00525 if(name[name.length() - 1] != '*')
00526 name +="*";
00527 _tabsMgr->SetNameTabPanel(wxString (name.c_str(), wxConvUTF8));
00528 GetToolBar()->EnableTool(ID_UNDO,_tabsMgr->getUndoState(stundo));
00529 GetToolBar()->SetToolShortHelp(ID_UNDO,crea::std2wx(stundo));
00530 GetToolBar()->EnableTool(ID_REDO,_tabsMgr->getRedoState(stredo));
00531 GetToolBar()->SetToolShortHelp(ID_REDO,crea::std2wx(stredo));
00532 refreshGUIControls();
00533 }
00534
00535 void wxGUIEditorGraphicBBS::OnChangeName(wxCommandEvent& event){
00536 }
00537
00538
00539 void wxGUIEditorGraphicBBS::OnExecuteActualDiagram(wxCommandEvent& event) {
00540 std::string script1 = _tabsMgr->getActualDiagramBBS(true);
00541 cout << endl << "RaC wxGUIEditorGraphicBBS::executeActualDiagram SCRIPT"
00542 << endl << endl;
00543 cout << script1 << endl;
00544
00545 std::string script2 = _tabsMgr->getActualDiagramBBS(false);
00546 executeScript(script2);
00547 }
00548
00549
00550
00551
00552 void wxGUIEditorGraphicBBS::OnOpenBBS(wxCommandEvent& event) {
00553 wxFileDialog * openFileDialog = new wxFileDialog(this, wxT("Open BBS"),
00554 wxEmptyString, wxT("NewBBS"), wxT("*.bbs"), wxOPEN);
00555 if (openFileDialog->ShowModal() == wxID_OK) {
00556 wxString fileName = openFileDialog->GetPath();
00557
00558 _tabsMgr->addNewTab(openFileDialog->GetFilename());
00559
00560 bbtk::InterpreterBBS::Pointer I = bbtk::InterpreterBBS::New(
00561 this->_tabsMgr->getActualTabPanel()->getSceneManager(),
00562 _pkgBrowser->GetFactory());
00563
00564
00565 I->SetThrow(true);
00566
00567 I->InterpretFile((const char*) (fileName.mb_str()));
00568 }
00569 refreshGUIControls();
00570 }
00571
00572 void wxGUIEditorGraphicBBS::SaveActualBBS(std::string filename) {
00573 ofstream file;
00574
00575
00576 file.open(filename.c_str());
00577 std::string content = "";
00578
00579 content += "# ----------------------------------\n";
00580 content += "# - BBTKGEditor v 1.2 BBS BlackBox Script\n";
00581 content += "# - ";
00582 content += filename;
00583 content += "\n";
00584 content += "# ----------------------------------\n";
00585 content += "\n";
00586 content += _tabsMgr->getActualDiagramBBS();
00587 file << content;
00588 file.close();
00589 }
00590
00591 void wxGUIEditorGraphicBBS::OnSaveActualBBS(wxCommandEvent& event) {
00592 wxFileDialog * saveFileDialog = new wxFileDialog(this,
00593 wxT("Save actual BBS"), wxEmptyString, wxT("NewBBS"),
00594 wxT("*.bbs"), wxSAVE | wxOVERWRITE_PROMPT);
00595 if (saveFileDialog->ShowModal() == wxID_OK) {
00596 wxString fileName = saveFileDialog->GetPath();
00597 std::string filename = (const char*) (fileName.mb_str());
00598 filename=CheckExtension (filename, ".bbs");
00599 SaveActualBBS(filename);
00600 }
00601
00602 }
00603
00604 void wxGUIEditorGraphicBBS::AskComplexBoxConfiguration() {
00605 std::string cbName = _tabsMgr->GetCbName();
00606 std::string paName = _tabsMgr->GetCbPackageName();
00607
00608 wxTextEntryDialog *cbNameDialog = new wxTextEntryDialog(this,
00609 wxT("Complex Box name"));
00610 wxTextEntryDialog *paNameDialog = new wxTextEntryDialog(this,
00611 wxT("Package name"));
00612
00613 cbNameDialog->SetValue(wxString(cbName.c_str(), wxConvUTF8));
00614 paNameDialog->SetValue(wxString(paName.c_str(), wxConvUTF8));
00615
00616 if (cbNameDialog->ShowModal() == wxID_OK) {
00617 wxString complexboxname = cbNameDialog->GetValue();
00618 cbName = (const char*) (complexboxname.mb_str());
00619 }
00620
00621 if (paNameDialog->ShowModal() == wxID_OK) {
00622 wxString packagename = paNameDialog->GetValue();
00623 paName = (const char*) (packagename.mb_str());
00624 }
00625
00626 _tabsMgr->SetCbName(cbName);
00627 _tabsMgr->SetCbPackageName(paName);
00628 }
00629
00630
00631
00632 void wxGUIEditorGraphicBBS::SaveActualComplexBox(std::string filename) {
00633 ofstream file;
00634 file.open(filename.c_str());
00635
00636 std::string content = "";
00637
00638
00639 content += "# ----------------------------------\n";
00640 content += "# - BBTKGEditor v 1.2 BBS BlackBox Script (Complex Box)\n";
00641 content += "# - ";
00642 content += filename;
00643 content += "\n";
00644 content += "# ----------------------------------\n";
00645 content += "\n";
00646 content += _tabsMgr->getActualComplexBoxBBS();
00647 file << content;
00648 file.close();
00649 }
00650
00651
00652
00653 void wxGUIEditorGraphicBBS::OnSaveActualComplexBox(wxCommandEvent& event) {
00654 wxFileDialog * saveFileDialog = new wxFileDialog(this,
00655 wxT("Save Complex Box BBS"), wxEmptyString,
00656 _T("ComplexBoxName"), wxT("*.bbs"), wxSAVE
00657 | wxOVERWRITE_PROMPT);
00658 if (saveFileDialog->ShowModal() == wxID_OK) {
00659 wxString fileName = saveFileDialog->GetPath();
00660 std::string filename = (const char*) (fileName.mb_str());
00661 filename=CheckExtension (filename, ".bbs");
00662 SaveActualComplexBox(filename);
00663 }
00664 }
00665
00666
00667 void wxGUIEditorGraphicBBS::SaveActualDiagram(std::string filename) {
00668 ofstream file;
00669 file.open(filename.c_str());
00670
00671 std::string content = "";
00672
00673
00674 content += "# ----------------------------------\n";
00675 content += "# - BBTKGEditor v 1.2 BBG BlackBox Diagram file\n";
00676 content += "# - ";
00677
00678 content += filename;
00679
00680 content += "\n";
00681 content += "# ----------------------------------\n";
00682 content += "\n";
00683 content += "APP_START\n";
00684 _tabsMgr->saveActualDiagram(content, filename);
00685 content += "APP_END\n";
00686 file << content;
00687 file.close();
00688 }
00689
00690
00691 void wxGUIEditorGraphicBBS::SaveTempActualDiagram(const std::string &action)
00692 {
00693 std::string stundo;
00694 std::string stredo;
00695 std::string name = _tabsMgr->GetNameTabPanel();
00696 if(name[name.length() - 1] != '*')
00697 name +="*";
00698 _tabsMgr->SetNameTabPanel(wxString (name.c_str(), wxConvUTF8));
00699 _tabsMgr->saveTempActualDiagram(action);
00700 GetToolBar()->EnableTool(ID_UNDO,_tabsMgr->getUndoState(stundo));
00701 GetToolBar()->SetToolShortHelp(ID_UNDO,crea::std2wx(stundo));
00702 GetToolBar()->EnableTool(ID_REDO,_tabsMgr->getRedoState(stredo));
00703 GetToolBar()->SetToolShortHelp(ID_REDO,crea::std2wx(stredo));
00704 }
00705
00706
00707
00708
00709
00710 void wxGUIEditorGraphicBBS::SaveCurrentDiagramAs() {
00711 wxFileDialog * saveFileDialog = new wxFileDialog(this,
00712 wxT("Save current diagram"), wxEmptyString, wxT("NewDiagram"),
00713 wxT("*.bbg"), wxSAVE | wxOVERWRITE_PROMPT);
00714 if (saveFileDialog->ShowModal() == wxID_OK) {
00715
00716 wxString pathfileName = saveFileDialog->GetPath();
00717 std::string pathfilename = (const char*) (pathfileName.mb_str());
00718 pathfilename=CheckExtension (pathfilename, ".bbg");
00719
00720
00721 wxString fileName = saveFileDialog->GetFilename();
00722 std::string filename = (const char*) (fileName.mb_str());
00723 filename=CheckExtension (filename, ".bbg");
00724 _tabsMgr->SetNameTabPanel( wxString (filename.c_str(), wxConvUTF8) );
00725
00726 std::string pathfilenamebbs = pathfilename;
00727 pathfilenamebbs[pathfilenamebbs.length() - 1] = 's';
00728 if (_tabsMgr->isActualDiagramComplexBox() == false) {
00729 SaveActualDiagram(pathfilename);
00730 SaveActualBBS(pathfilenamebbs);
00731 } else {
00732 AskComplexBoxConfiguration();
00733 SaveActualDiagram(pathfilename);
00734 SaveActualComplexBox(pathfilenamebbs);
00735 }
00736 }
00737 }
00738
00739
00740 void wxGUIEditorGraphicBBS::OnSaveActualDiagram(wxCommandEvent& event) {
00741 std::string pathfilename = _tabsMgr->GetCurrentTabPanelPath();
00742 if (pathfilename.empty()) {
00743 SaveCurrentDiagramAs();
00744 } else {
00745 std::string pathfilenamebbs = pathfilename;
00746 pathfilenamebbs[pathfilenamebbs.length() - 1] = 's';
00747
00748 if (_tabsMgr->isActualDiagramComplexBox() == false) {
00749 std::string name = _tabsMgr->GetNameTabPanel();
00750 if(name[name.length() - 1] == '*')
00751 {
00752 name =name.substr(0,name.length()-1);
00753 }
00754 _tabsMgr->SetNameTabPanel(wxString (name.c_str(), wxConvUTF8));
00755 SaveActualDiagram(pathfilename);
00756 SaveActualBBS(pathfilenamebbs);
00757 } else {
00758 AskComplexBoxConfiguration();
00759 SaveActualDiagram(pathfilename);
00760 SaveActualComplexBox(pathfilenamebbs);
00761 }
00762 }
00763 }
00764
00765
00766 void wxGUIEditorGraphicBBS::OnSaveAsActualDiagram(wxCommandEvent& event) {
00767 SaveCurrentDiagramAs();
00768 }
00769
00770
00771 void wxGUIEditorGraphicBBS::refreshGUIControls() {
00772 std::string stundo;
00773 std::string stredo;
00774 wxToolBar* toolbar = GetToolBar();
00775 if (_tabsMgr->isActualDiagramComplexBox()) {
00776 toolbar->ToggleTool(ID_BTNCOMPLEXBOX, true);
00777 toolbar->EnableTool(ID_ADDCOMPLEXBOXINPUT, true);
00778 toolbar->EnableTool(ID_ADDCOMPLEXBOXOUTPUT, true);
00779
00780 GetMenuBar()->GetMenu(0)->Enable(ID_SAVE_AS_COMPLEXBOX, true);
00781 GetMenuBar()->GetMenu(0)->Enable(ID_SAVE_AS_BBS, false);
00782 } else {
00783 toolbar->ToggleTool(ID_BTNCOMPLEXBOX, false);
00784 toolbar->EnableTool(ID_ADDCOMPLEXBOXINPUT, false);
00785 toolbar->EnableTool(ID_ADDCOMPLEXBOXOUTPUT, false);
00786
00787 GetMenuBar()->GetMenu(0)->Enable(ID_SAVE_AS_COMPLEXBOX, false);
00788 GetMenuBar()->GetMenu(0)->Enable(ID_SAVE_AS_BBS, true);
00789 }
00790
00791 GetToolBar()->EnableTool(ID_UNDO,_tabsMgr->getUndoState(stundo));
00792 GetToolBar()->SetToolShortHelp(ID_UNDO,crea::std2wx(stundo));
00793 GetToolBar()->EnableTool(ID_REDO,_tabsMgr->getRedoState(stredo));
00794 GetToolBar()->SetToolShortHelp(ID_REDO,crea::std2wx(stredo));
00795
00796 if (_tabsMgr->getNumActualSelectedObjects() > 0) {
00797 GetMenuBar()->GetMenu(1)->Enable(ID_COPY_TO_COMPLEXDIAGRAM, true);
00798 } else {
00800 GetMenuBar()->GetMenu(1)->Enable(ID_COPY_TO_COMPLEXDIAGRAM, true);
00801 }
00802
00803 }
00804
00805
00806
00807 void wxGUIEditorGraphicBBS::OnDeleteAllBoxesActualDiagram(wxCommandEvent& event) {
00808 wxMessageDialog *dial = new wxMessageDialog(NULL,
00809 wxT("Are you sure to delete all boxes of the diagram?"),
00810 wxT("Delete all boxes"), wxYES_NO | wxNO_DEFAULT
00811 | wxICON_QUESTION);
00812 if (dial->ShowModal() == wxID_YES) {
00813 _tabsMgr->deleteAllBoxesActualDiagram();
00814 }
00815 }
00816
00817
00818
00819 void wxGUIEditorGraphicBBS::OnCenterViewActualDiagram(wxCommandEvent& event) {
00820 _tabsMgr->centerViewActualDiagram();
00821 }
00822
00823
00824
00825 void wxGUIEditorGraphicBBS::OnOpenDiagram(wxCommandEvent& event) {
00826 wxFileDialog * openFileDialog = new wxFileDialog(this, wxT("Open diagram"),
00827 wxEmptyString, wxT(""), wxT("*.bbg"), wxOPEN | wxFILE_MUST_EXIST);
00828 printf("SCP: wxGUIEditorGraphicBBS::OnOpenDiagram \n");
00829 if (openFileDialog->ShowModal() == wxID_OK) {
00830 wxString fileName = openFileDialog->GetPath();
00831 ifstream inputStream;
00832 std::string fName = (const char*) (fileName.mb_str());
00833
00834 inputStream.open(fName.c_str());
00835 assert(inputStream.good());
00836 _tabsMgr->addNewTab(openFileDialog->GetFilename());
00837 _tabsMgr->loadDiagram(inputStream, fName);
00838 _tabsMgr->saveTempActualDiagram("load diagram");
00839 GetToolBar()->EnableTool(ID_UNDO, false);
00840 GetToolBar()->EnableTool(ID_UNDO, false);
00841 inputStream.close();
00842 }
00843 refreshGUIControls();
00844 }
00845
00846
00847
00848
00849 void wxGUIEditorGraphicBBS::OnClickBtnBox(wxCommandEvent& event) {
00850 BlackBoxDescriptor *bbDes = _pkgBrowser->GetActualSelected();
00851 if (bbDes != NULL) {
00852 std::string typeName = bbDes->GetTypeName();
00853 std::string packageName = bbDes->GetPackage()->GetName();
00854
00855 wxGEditorTabPanel *pnl = this->_tabsMgr->getActualTabPanel();
00856
00857
00858 if (pnl != NULL) {
00859 wxVtkSceneManager *scn = pnl->getSceneManager();
00860 scn->createGBlackBox(50, 50, packageName, typeName);
00861 scn->refresh();
00862 }
00863
00864 SaveTempActualDiagram("New Box");
00865
00866 }
00867 }
00868
00869
00870
00871 void wxGUIEditorGraphicBBS::OnClickBtnExecutableBox(wxCommandEvent& event) {
00872
00873 wxGEditorTabPanel *pnl = this->_tabsMgr->getActualTabPanel();
00874
00875 if (pnl != NULL) {
00876 wxVtkSceneManager *scn = pnl->getSceneManager();
00877 if( scn->MakeBoxExecutable() )
00878 std::cout<<"DFCH: wxGUIEditorGraphicBBS::OnClickBtnExecutableBox...successful"<<std::endl;
00879 else
00880 std::cout<<"DFCH: wxGUIEditorGraphicBBS::OnClickBtnExecutableBox...Error!!"<<std::endl;
00881 }
00882
00883
00884 }
00885
00886
00887
00888 void wxGUIEditorGraphicBBS::OnClickBtnComplexBox(wxCommandEvent& event) {
00889 wxToolBar* toolbar = GetToolBar();
00890 bool temp = toolbar->GetToolState(ID_BTNCOMPLEXBOX);
00891 if (temp) {
00892 _tabsMgr->setActualDiagramComplexBox(true);
00893 } else {
00894 _tabsMgr->setActualDiagramComplexBox(false);
00895 }
00896 refreshGUIControls();
00897 }
00898
00899
00900
00901 void wxGUIEditorGraphicBBS::OnAddComplexBoxInput(wxCommandEvent& event) {
00902 wxTextEntryDialog *nameDialog = new wxTextEntryDialog(this,
00903 wxT("Name of input port"));
00904 if (nameDialog->ShowModal() == wxID_OK) {
00905 wxString fileName = nameDialog->GetValue();
00906 if (!fileName.IsEmpty()) {
00907 std::string portName = (const char*) (fileName.mb_str());
00908 _tabsMgr->addActualDiagramComplexInputPort(portName);
00909 }
00910 }
00911 }
00912
00913
00914
00915 void wxGUIEditorGraphicBBS::OnAddComplexBoxOutput(wxCommandEvent& event) {
00916 wxTextEntryDialog *nameDialog = new wxTextEntryDialog(this,
00917 wxT("Name of output port"));
00918 if (nameDialog->ShowModal() == wxID_OK) {
00919 wxString fileName = nameDialog->GetValue();
00920 if (!fileName.IsEmpty()) {
00921 std::string portName = (const char*) (fileName.mb_str());
00922 _tabsMgr->addActualDiagramComplexOutputPort(portName);
00923 }
00924 }
00925 }
00926
00927
00928
00929 void wxGUIEditorGraphicBBS::OnCopySelectedToComplexDiagram(
00930 wxCommandEvent& event) {
00931 _tabsMgr->copySelectedBBoxesToComplexDiagram();
00932 }
00933
00934 void wxGUIEditorGraphicBBS::OnHelpBBeditor(wxCommandEvent& event) {
00935 printf("wxGUIEditorGraphicBBS::OnHelpBBeditor ....not implemented..\n");
00936 }
00937
00938
00939 void wxGUIEditorGraphicBBS::OnCreatePackage(wxCommandEvent& event) {
00940
00941 bbtkSystemTools::CreatePackage();
00942 }
00943
00944
00945 void wxGUIEditorGraphicBBS::OnCreateBlackBox(wxCommandEvent& event) {
00946 bbtkSystemTools::CreateBlackBox();
00947 }
00948
00949 void wxGUIEditorGraphicBBS::OnPlugPackage(wxCommandEvent& event) {
00950 printf("EED wxGUIEditorGraphicBBS::OnPlugPackage ... not implemented ..\n");
00951 }
00952
00953 void wxGUIEditorGraphicBBS::OnEditConfig(wxCommandEvent& event) {
00954 printf("EED wxGUIEditorGraphicBBS::OnEditConfig ... not implemented ..\n");
00955 }
00956
00957
00958 void wxGUIEditorGraphicBBS::OnShowHTMLDoc(wxCommandEvent& event) {
00959
00960 if (_helpHtmlBrowser != NULL){
00961 _frameAUIMgr->DetachPane(_helpHtmlBrowser);
00962 _helpHtmlBrowser->Destroy();
00963 }
00964 initHelpHTMLBrowser();
00965 _frameAUIMgr->AddPane(_helpHtmlBrowser, wxAuiPaneInfo().Right().MinSize(200, 200));
00966 _frameAUIMgr->Update();
00967 refreshGUIControls();
00968
00969
00970 }
00971
00972 void wxGUIEditorGraphicBBS::OnCreateIndex(wxCommandEvent& event) {
00973 printf("EED wxGUIEditorGraphicBBS::OnCreateIndex ... not implemented ..\n");
00974 }
00975
00976
00977
00978 void wxGUIEditorGraphicBBS::OnExit(wxCommandEvent& event) {
00979 Close(true);
00980 }
00981
00982
00983
00984
00985
00986 }
00987
00988
00989