From 774e6c1e3e9b69ea0b221c3013b58d7d5a919971 Mon Sep 17 00:00:00 2001 From: camarasu <> Date: Thu, 24 May 2012 10:31:45 +0000 Subject: [PATCH] #1351 --- .../bbtkwxGUIEditorGraphicBBS.cxx | 7 +++ .../bbtkwxGUIEditorGraphicBBS.h | 2 + .../wxBlackBoxEditionDialog.cxx | 55 +++++++++++++++++-- .../wxBlackBoxEditionDialog.h | 3 + 4 files changed, 63 insertions(+), 4 deletions(-) diff --git a/lib/EditorGraphicBBS/bbsWxGUIEditorGraphic/bbtkwxGUIEditorGraphicBBS.cxx b/lib/EditorGraphicBBS/bbsWxGUIEditorGraphic/bbtkwxGUIEditorGraphicBBS.cxx index d7ab7dd..25c4298 100644 --- a/lib/EditorGraphicBBS/bbsWxGUIEditorGraphic/bbtkwxGUIEditorGraphicBBS.cxx +++ b/lib/EditorGraphicBBS/bbsWxGUIEditorGraphic/bbtkwxGUIEditorGraphicBBS.cxx @@ -424,6 +424,13 @@ void wxGUIEditorGraphicBBS::editBlackBox(GBlackBoxModel *bbmodel) { //========================================================================= +bool wxGUIEditorGraphicBBS::boxNameExists(std::string boxname) { + + return this->_tabsMgr->getActualTabPanel()->getSceneManager()->boxExist(boxname); +} + +//========================================================================= + void wxGUIEditorGraphicBBS::updateStatusBar(std::string textStatus) { SetStatusText(crea::std2wx(textStatus)); } diff --git a/lib/EditorGraphicBBS/bbsWxGUIEditorGraphic/bbtkwxGUIEditorGraphicBBS.h b/lib/EditorGraphicBBS/bbsWxGUIEditorGraphic/bbtkwxGUIEditorGraphicBBS.h index de6021f..e34c5d4 100644 --- a/lib/EditorGraphicBBS/bbsWxGUIEditorGraphic/bbtkwxGUIEditorGraphicBBS.h +++ b/lib/EditorGraphicBBS/bbsWxGUIEditorGraphic/bbtkwxGUIEditorGraphicBBS.h @@ -123,6 +123,8 @@ namespace bbtk // Shows the dialog to change the parameters and values of the black box void editBlackBox(GBlackBoxModel *bbmodel); + bool boxNameExists(std::string boxname); + // Checks and adds if necessary the .bbg/.bbs extensions std::string CheckExtension (std::string filename, std::string extension); // Method that can be used to refresh the help and package browser diff --git a/lib/EditorGraphicBBS/bbsWxGUIEditorGraphic/wxBlackBoxEditionDialog.cxx b/lib/EditorGraphicBBS/bbsWxGUIEditorGraphic/wxBlackBoxEditionDialog.cxx index d4663da..d080363 100644 --- a/lib/EditorGraphicBBS/bbsWxGUIEditorGraphic/wxBlackBoxEditionDialog.cxx +++ b/lib/EditorGraphicBBS/bbsWxGUIEditorGraphic/wxBlackBoxEditionDialog.cxx @@ -65,16 +65,36 @@ namespace bbtk //========================================================================= + bool wxBlackBoxEditionDialog::isValidNameForABox(std::string boxname) { + + int i=0; + for (i = 0; i < boxname.size() ; i++) { + if ( (isalnum(boxname[i])==0) && (boxname.compare(i, 1, "-") != 0) && ( boxname.compare(i, 1, "_") != 0) ){ + return false; + } + } // for + + return true; + } + + //========================================================================= + void wxBlackBoxEditionDialog::constructBlackBoxEditionDialog() { wxBoxSizer *sizerDialog = new wxBoxSizer(wxVERTICAL); wxScrolledWindow *scrollWin = new wxScrolledWindow( this, -1, wxDefaultPosition, wxSize(200,200), wxVSCROLL); + wxStaticText *textBoxName = new wxStaticText(scrollWin, -1, wxT("Box Name")); + wxTextCtrl *valueBoxName = new wxTextCtrl(scrollWin, -1, _T(""), wxDefaultPosition,wxSize(300,25)); + _initBoxName = _model->getBBTKName(); + valueBoxName->SetValue(crea::std2wx(_initBoxName)); + _boxName = valueBoxName ; + wxStaticText *text = new wxStaticText(scrollWin, -1, wxT("Input Ports")); wxFont font(11, wxDEFAULT, wxNORMAL, wxBOLD); text->SetFont(font); - + textBoxName->SetFont(font); std::vector lstInputs = _model->getInputPorts(); @@ -134,6 +154,10 @@ namespace bbtk buts->Add(closeButton,0,wxCENTRE|wxEXPAND,5); sizerDialog->AddSpacer(10); + sizerDialog->Add(textBoxName,0,wxALIGN_TOP|wxALIGN_CENTER); + sizerDialog->AddSpacer(10); + sizerDialog->Add(valueBoxName, wxSizerFlags(0).Align(0).Border(wxLEFT, 100)); + sizerDialog->AddSpacer(10); sizerDialog->Add(text,0,wxALIGN_TOP|wxALIGN_CENTER); sizerDialog->AddSpacer(15); sizerDialog->Add(sizer,0,wxALIGN_CENTER| wxEXPAND); @@ -158,6 +182,7 @@ namespace bbtk void wxBlackBoxEditionDialog::onClickOk(wxCommandEvent& event) { + int closeok = 1; for(int i=0;i<(int)_lstValues.size();i++) { std::string text = wx2std(_lstValues[i]->GetValue()); @@ -167,8 +192,30 @@ namespace bbtk _model->setValueToInputPort(i,text); } } - _parent->SaveTempActualDiagram(); - Close(true); + //handle box name + std::string boxname = wx2std(_boxName->GetValue()); + if( boxname.compare(_initBoxName) != 0 ){ + if (isValidNameForABox(boxname) == true){ + if( _parent->boxNameExists(boxname) == true ){ + closeok=0; + wxMessageDialog *dial = new wxMessageDialog(NULL, + wxT("The name already exists. Please provide another name"), + wxT("Change name: name already exists"), wxOK | wxICON_EXCLAMATION | wxSTAY_ON_TOP); + dial->ShowModal(); + }else{ + _model->setBBTKName(boxname); + } + }else{ + closeok=0; + wxMessageDialog *dial = new wxMessageDialog(NULL, wxT("Please provide a valide name for your box (no spaces and only leters, digits, \"_\" or \"-\" allowed)"), wxT("Change name: invalid name"), wxOK | wxICON_EXCLAMATION | wxSTAY_ON_TOP); + dial->ShowModal(); + } + } + + if( closeok==1 ){ + _parent->SaveTempActualDiagram(); + Close(true); + } } //========================================================================= @@ -188,4 +235,4 @@ printf("EED wxBlackBoxEditionDialog::onClickClose\n"); std::string name = _tabsMgr->GetNameTabPanel(); if(name[name.length() - 1] != '*') name = name.substr(0, name.length()-2); - _tabsMgr->SetNameTabPanel(name);*/ \ No newline at end of file + _tabsMgr->SetNameTabPanel(name);*/ diff --git a/lib/EditorGraphicBBS/bbsWxGUIEditorGraphic/wxBlackBoxEditionDialog.h b/lib/EditorGraphicBBS/bbsWxGUIEditorGraphic/wxBlackBoxEditionDialog.h index be859b6..9abd697 100644 --- a/lib/EditorGraphicBBS/bbsWxGUIEditorGraphic/wxBlackBoxEditionDialog.h +++ b/lib/EditorGraphicBBS/bbsWxGUIEditorGraphic/wxBlackBoxEditionDialog.h @@ -74,6 +74,7 @@ namespace bbtk ~wxBlackBoxEditionDialog(); void constructBlackBoxEditionDialog(); + bool isValidNameForABox(std::string boxname); void onClickOk(wxCommandEvent& event); void onClickClose(wxCommandEvent& event); @@ -85,6 +86,8 @@ namespace bbtk std::vector _lstValues; std::vector _lstTypes; std::vector _lstNames; + std::string _initBoxName; + wxTextCtrl* _boxName; GBlackBoxModel *_model; -- 2.47.1