wxBlackBoxEditionDialog.cxx

Go to the documentation of this file.
00001 /*=========================================================================
00002 Program:   bbtk
00003 Module:    $RCSfile: wxBlackBoxEditionDialog.cxx,v $
00004 Language:  C++
00005 Date:      $Date: 2012/05/30 17:18:01 $
00006 Version:   $Revision: 1.20 $
00007 =========================================================================*/
00008 
00009 /* ---------------------------------------------------------------------
00010 
00011 * Copyright (c) CREATIS-LRMN (Centre de Recherche en Imagerie Medicale)
00012 * Authors : Eduardo Davila, Laurent Guigues, Jean-Pierre Roux
00013 *
00014 *  This software is governed by the CeCILL-B license under French law and
00015 *  abiding by the rules of distribution of free software. You can  use,
00016 *  modify and/ or redistribute the software under the terms of the CeCILL-B
00017 *  license as circulated by CEA, CNRS and INRIA at the following URL
00018 *  http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
00019 *  or in the file LICENSE.txt.
00020 *
00021 *  As a counterpart to the access to the source code and  rights to copy,
00022 *  modify and redistribute granted by the license, users are provided only
00023 *  with a limited warranty  and the software's author,  the holder of the
00024 *  economic rights,  and the successive licensors  have only  limited
00025 *  liability.
00026 *
00027 *  The fact that you are presently reading this means that you have had
00028 *  knowledge of the CeCILL-B license and that you accept its terms.
00029 * ------------------------------------------------------------------------ */
00030 
00036 #include "wxBlackBoxEditionDialog.h"
00037 #include "creaWx.h"
00038 
00039 namespace bbtk
00040 {
00041         //=========================================================================
00042 
00043         wxBlackBoxEditionDialog::wxBlackBoxEditionDialog(wxGUIEditorGraphicBBS *parent,GBlackBoxModel *model):wxDialog(parent,wxID_ANY,_T(""), wxDefaultPosition, wxSize(520, 640),wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER) 
00044         {
00045                 _model=model;
00046                 _parent = parent;
00047                 std::string title("BlackBox Editing - ");
00048                 title+=_model->getBBTKPackage();
00049                 title+=":";
00050                 title+=_model->getBBTKType();
00051                 title+=":";
00052                 title+=_model->getBBTKName();
00053                 SetTitle(std2wx(title));
00054 
00055                 constructBlackBoxEditionDialog();
00056         }
00057 
00058         //=========================================================================
00059 
00060 
00061         wxBlackBoxEditionDialog::~wxBlackBoxEditionDialog()
00062         {
00063 
00064         }
00065 
00066         //=========================================================================
00067 
00068         bool wxBlackBoxEditionDialog::isValidNameForABox(std::string boxname) {
00069 
00070                 int i=0;
00071                 for (i = 0; i < boxname.size() ; i++) {
00072                         if ( (isalnum(boxname[i])==0) && (boxname.compare(i, 1, "-") != 0) && ( boxname.compare(i, 1, "_") != 0) ){
00073                                 return false;
00074                         }
00075                 } // for
00076  
00077                 return true;
00078         }
00079 
00080         //=========================================================================
00081 
00082         void wxBlackBoxEditionDialog::constructBlackBoxEditionDialog()
00083         {
00084                 wxBoxSizer *sizerDialog = new wxBoxSizer(wxVERTICAL);
00085 
00086         wxScrolledWindow *scrollWin = new wxScrolledWindow( this, -1, wxDefaultPosition,  wxSize(200,200), wxVSCROLL);
00087 
00088                 wxStaticText *textBoxName = new wxStaticText(scrollWin, -1, wxT("Box Name"));
00089                 wxTextCtrl *valueBoxName  = new wxTextCtrl(scrollWin, -1, _T(""), wxDefaultPosition,wxSize(300,25));
00090                 _initBoxName = _model->getBBTKName();
00091                 valueBoxName->SetValue(crea::std2wx(_initBoxName));
00092                 _boxName = valueBoxName ;
00093 
00094                 wxStaticText *text = new wxStaticText(scrollWin, -1, wxT("Input Ports"));
00095                 wxFont font(11, wxDEFAULT, wxNORMAL, wxBOLD);
00096                 text->SetFont(font);
00097                 textBoxName->SetFont(font);
00098 
00099 
00100                 std::vector<GPortModel*> lstInputs = _model->getInputPorts();
00101                 wxFlexGridSizer *sizer = new wxFlexGridSizer(lstInputs.size(),3,5,5);
00102                 sizer->AddGrowableCol(0);
00103                 sizer->AddGrowableCol(1);
00104                 sizer->AddGrowableCol(2);
00105                 
00106                 for(int i = 0;i<(int)lstInputs.size();i++)
00107                 {
00108                         sizer->AddGrowableRow(i);
00109                         GPortModel* port        = lstInputs[i];
00110                         std::string type        = port->getBBTKType();
00111                         wxStaticText *lblName   = new wxStaticText(scrollWin, -1, std2wx(port->getBBTKName()),wxDefaultPosition,wxSize(100,25));
00112                         wxStaticText *lblType   = new wxStaticText(scrollWin, -1, std2wx(type),wxDefaultPosition,wxSize(250,25));
00113                         wxTextCtrl *txtValue    = new wxTextCtrl(scrollWin, -1, _T(""),wxDefaultPosition,wxSize(300,25));
00114 
00115                         if(port->getValue()!="")
00116                         {
00117                                 std::string text = port->getValue();
00118                                 if(text.length()>0)
00119                                         addDoubleQuotes(text);
00120                                 txtValue->SetValue(crea::std2wx(text));
00121                         }
00122 
00123                         if(port->isConnected())
00124                         {
00125                                 std::string connected("--Port Connected--");
00126                                 txtValue->SetValue(crea::std2wx(connected));
00127                                 txtValue->SetEditable(false);
00128                         }
00129 
00130                         char et = '*';
00131                         if(type.find(et)!=-1)
00132                         {
00133                                 std::string noEditable("--No editable--");
00134                                 txtValue->SetValue(crea::std2wx(noEditable));
00135                                 txtValue->SetEditable(false);
00136                         }
00137 
00138                         _lstNames.push_back(lblName);
00139                         _lstValues.push_back(txtValue);
00140                         _lstTypes.push_back(lblType);
00141 
00142                         sizer->Add(lblName,1,wxEXPAND,5);
00143                         sizer->Add(txtValue,1,wxEXPAND,5);
00144                         sizer->Add(lblType,1,wxCENTRE|wxEXPAND,5);
00145                 }
00146 
00147 
00148                 wxBoxSizer *buts        = new wxBoxSizer(wxHORIZONTAL);
00149                 wxButton *okButton      = new wxButton(scrollWin, -1, _T("Ok"),wxDefaultPosition, wxSize(70, 30));
00150                 wxButton *closeButton   = new wxButton(scrollWin, -1, _T("Close"), wxDefaultPosition, wxSize(70, 30));
00151 
00152                 // connect command event handlers
00153                 Connect(okButton->GetId(),wxEVT_COMMAND_BUTTON_CLICKED,wxCommandEventHandler(wxBlackBoxEditionDialog::onClickOk));
00154                 Connect(closeButton->GetId(),wxEVT_COMMAND_BUTTON_CLICKED,wxCommandEventHandler(wxBlackBoxEditionDialog::onClickClose));
00155 
00156                 buts->Add(okButton,0,wxCENTRE|wxEXPAND,5);
00157                 buts->Add(closeButton,0,wxCENTRE|wxEXPAND,5);
00158 
00159                 sizerDialog->AddSpacer(10);
00160                 sizerDialog->Add(textBoxName,0,wxALIGN_TOP|wxALIGN_CENTER);
00161                 sizerDialog->AddSpacer(10);
00162                 sizerDialog->Add(valueBoxName, wxSizerFlags(0).Align(0).Border(wxLEFT, 100));
00163                 sizerDialog->AddSpacer(10);
00164                 sizerDialog->Add(text,0,wxALIGN_TOP|wxALIGN_CENTER);
00165                 sizerDialog->AddSpacer(15);
00166                 sizerDialog->Add(sizer,0,wxALIGN_CENTER| wxEXPAND);
00167                 sizerDialog->AddSpacer(15);
00168                 sizerDialog->Add(buts,0,wxALIGN_CENTER | wxTOP | wxBOTTOM);
00169 
00170                 scrollWin->SetSizer(sizerDialog);
00171                 scrollWin->Centre();
00172 
00173 
00174         scrollWin->SetVirtualSize(400,400);
00175         scrollWin->SetSize(300,300);
00176         scrollWin->SetScrollbars(10, 10, 50, 50);
00177 //        scrollWin->SetSizer(sizer);
00178 
00179 
00180                 ShowModal();
00181                 Destroy();
00182         }
00183 
00184         //=========================================================================
00185 
00186         void wxBlackBoxEditionDialog::onClickOk(wxCommandEvent& event)
00187         {
00188                 int closeok = 1;
00189                 for(int i=0;i<(int)_lstValues.size();i++)
00190                 {
00191                         std::string text = wx2std(_lstValues[i]->GetValue());
00192                         //TOFIX Search a better alternative
00193                         if(text!="--No editable--" && text!="--Port Connected--")
00194                         {
00195                                 _model->setValueToInputPort(i,text);
00196                         }
00197                 }
00198                 //handle box name
00199                 std::string boxname = wx2std(_boxName->GetValue());
00200                 if( boxname.compare(_initBoxName) != 0 ){
00201                         if (isValidNameForABox(boxname) == true){
00202                                 if( _parent->boxNameExists(boxname) == true ){
00203                                         closeok=0;
00204                                         wxMessageDialog *dial = new wxMessageDialog(NULL,
00205                          wxT("The name already exists. Please provide another name"),
00206                          wxT("Change name: name already exists"), wxOK | wxICON_EXCLAMATION | wxSTAY_ON_TOP);
00207                                         dial->ShowModal();
00208                                 }else{
00209                                         _model->setBBTKName(boxname);
00210                                 }
00211                         }else{
00212                                 closeok=0;
00213                                 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);
00214                                 dial->ShowModal();
00215                         }
00216                 }
00217  
00218                 if( closeok==1 ){
00219                         _parent->SaveTempActualDiagram("edit values");
00220                         Close(true);
00221                 }
00222         }
00223 
00224         //=========================================================================
00225 
00226         void wxBlackBoxEditionDialog::onClickClose(wxCommandEvent& event)
00227         {
00228 printf("EED wxBlackBoxEditionDialog::onClickClose\n");
00229                 Close(true);
00230         }
00231 
00232         //=========================================================================
00233 
00234         //=========================================================================
00235         
00236         void wxBlackBoxEditionDialog::addDoubleQuotes(std::string &text)
00237         {
00238                 
00239                 //We add the double quotes at the beginning
00240                 if(text[0] != '"' )
00241                         text = "\"" + text;
00242                 
00243                 //We add the double quotes at the end
00244                 if(text[text.length()-1] != '"')        
00245                         text+= "\"";
00246                 
00247         }
00248         
00249 
00250         //=========================================================================
00251         void wxBlackBoxEditionDialog::removeDoubleQuotes(std::string &text)
00252         {
00253                 if(text[0]== '"' )
00254                         text.replace(0, 1,"");
00255                 if(text[text.length()-1] == '"')        
00256                         text.replace(text.length()-1, 1,"");
00257                 
00258         }
00259         
00260         
00261         
00262 }  // EO namespace bbtk
00263 
00264 // EOF
00265 /*      // remove * from the name
00266                 std::string name = _tabsMgr->GetNameTabPanel();
00267                 if(name[name.length() - 1] != '*')
00268                         name = name.substr(0, name.length()-2);
00269                 _tabsMgr->SetNameTabPanel(name);*/

Generated on Thu May 31 15:12:19 2012 for bbtkGEditor by  doxygen 1.5.7.1