]> Creatis software - bbtkGEditor.git/commitdiff
#1351
authorcamarasu <>
Thu, 24 May 2012 10:31:45 +0000 (10:31 +0000)
committercamarasu <>
Thu, 24 May 2012 10:31:45 +0000 (10:31 +0000)
lib/EditorGraphicBBS/bbsWxGUIEditorGraphic/bbtkwxGUIEditorGraphicBBS.cxx
lib/EditorGraphicBBS/bbsWxGUIEditorGraphic/bbtkwxGUIEditorGraphicBBS.h
lib/EditorGraphicBBS/bbsWxGUIEditorGraphic/wxBlackBoxEditionDialog.cxx
lib/EditorGraphicBBS/bbsWxGUIEditorGraphic/wxBlackBoxEditionDialog.h

index d7ab7dd65975a89cb03b99d23b3946587a8b2cfb..25c4298571c017fe73111c325ae3b4d81f171053 100644 (file)
@@ -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));
 }
index de6021fa11467ce212140cf5348bb23dd9f38c87..e34c5d44d3263fe5792eec29a91ee810077d5d14 100644 (file)
@@ -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
index d4663da4fe07641a1b45214de44f740253a48794..d080363abb24c79ad2c57842fe62180ac928a3af 100644 (file)
@@ -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<GPortModel*> 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);*/
index be859b614ebc5387be52b39626be5e55fdefe8fd..9abd697a40d8de3ecbd7b7b56379993f44bbdea0 100644 (file)
@@ -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<wxTextCtrl*> _lstValues;
                std::vector<wxStaticText*> _lstTypes;
                std::vector<wxStaticText*> _lstNames;
+               std::string _initBoxName;
+               wxTextCtrl* _boxName;
 
                GBlackBoxModel *_model;