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::wxBlackBoxEditionDialog .
61 #include "wxBlackBoxEditionDialog.h"
66 //=========================================================================
68 wxBlackBoxEditionDialog::wxBlackBoxEditionDialog(wxGUIEditorGraphicBBS *parent,GBlackBoxModel *model)
69 :wxDialog(parent,wxID_ANY,_T(""), wxDefaultPosition, wxSize(520, 640),wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER)
73 std::string title("BlackBox Editing - ");
74 title+=_model->getBBTKPackage();
76 title+=_model->getBBTKType();
78 title+=_model->getBBTKName();
79 SetTitle(std2wx(title));
81 constructBlackBoxEditionDialog();
84 //=========================================================================
87 wxBlackBoxEditionDialog::~wxBlackBoxEditionDialog()
92 //=========================================================================
94 bool wxBlackBoxEditionDialog::isValidNameForABox(std::string boxname) {
97 for (i = 0; i < boxname.size() ; i++) {
98 if ( (isalnum(boxname[i])==0) && (boxname.compare(i, 1, "-") != 0) && ( boxname.compare(i, 1, "_") != 0) ){
106 //=========================================================================
108 void wxBlackBoxEditionDialog::constructBlackBoxEditionDialog()
110 wxBoxSizer *sizerDialog = new wxBoxSizer(wxVERTICAL);
112 wxScrolledWindow *scrollWin = new wxScrolledWindow( this, -1, wxDefaultPosition, wxSize(200,200), wxVSCROLL);
114 wxString boxtype( crea::std2wx( _model->getBBTKType() ) );
116 wxStaticText *textBoxName = new wxStaticText(scrollWin, -1, wxT("Box Name"));
117 wxStaticText *textBoxType = new wxStaticText(scrollWin, -1, boxtype+wxT(": ") );
118 wxTextCtrl *valueBoxName = new wxTextCtrl(scrollWin, -1, _T(""), wxDefaultPosition,wxSize(300,25));
119 _initBoxName = _model->getBBTKName();
120 valueBoxName->SetValue(crea::std2wx(_initBoxName));
121 _boxName = valueBoxName ;
123 wxBoxSizer *boxnameSizer = new wxBoxSizer(wxHORIZONTAL);
124 boxnameSizer->Add(textBoxType,0,wxEXPAND,5);
125 boxnameSizer->Add(valueBoxName,0,wxEXPAND,5);
126 boxnameSizer->Add( new wxStaticText(scrollWin, -1, wxT(" ")) ,0,wxCENTRE|wxEXPAND,5);
130 wxStaticText *text = new wxStaticText(scrollWin, -1, wxT("Input Ports"));
131 wxFont font(11, wxDEFAULT, wxNORMAL, wxBOLD);
133 textBoxName->SetFont(font);
136 std::vector<GPortModel*> lstInputs = _model->getInputPorts();
137 wxFlexGridSizer *sizer = new wxFlexGridSizer(lstInputs.size(),3,5,5);
138 sizer->AddGrowableCol(0);
139 sizer->AddGrowableCol(1);
140 sizer->AddGrowableCol(2);
142 for(int i = 0;i<(int)lstInputs.size();i++)
144 sizer->AddGrowableRow(i);
145 GPortModel *port = lstInputs[i];
146 std::string type = port->getBBTKType();
147 wxStaticText *lblName = new wxStaticText(scrollWin, -1, std2wx(port->getBBTKName()),wxDefaultPosition,wxSize(100,25));
148 wxStaticText *lblType = new wxStaticText(scrollWin, -1, std2wx(type),wxDefaultPosition,wxSize(250,25));
149 wxTextCtrl *txtValue = new wxTextCtrl(scrollWin, -1, _T(""),wxDefaultPosition,wxSize(300,25));
151 lblName->SetToolTip( std2wx(port->getBBTKDescription()) );
152 txtValue->SetToolTip( std2wx(port->getBBTKDescription()) );
155 if(port->getValue()!="")
157 std::string text = port->getValue();
159 addDoubleQuotes(text);
160 txtValue->SetValue(crea::std2wx(text));
163 if(port->isConnected())
165 std::string connected("--Port Connected--");
166 txtValue->SetValue(crea::std2wx(connected));
167 txtValue->SetEditable(false);
171 if(type.find(et)!=-1)
173 std::string noEditable("--No editable--");
174 txtValue->SetValue(crea::std2wx(noEditable));
175 txtValue->SetEditable(false);
178 _lstNames.push_back(lblName);
179 _lstValues.push_back(txtValue);
180 _lstTypes.push_back(lblType);
182 sizer->Add(lblName,1,wxEXPAND,5);
183 sizer->Add(txtValue,1,wxEXPAND,5);
184 sizer->Add(lblType,1,wxCENTRE|wxEXPAND,5);
188 wxBoxSizer *buts = new wxBoxSizer(wxHORIZONTAL);
189 wxButton *okButton = new wxButton(scrollWin, -1, _T("Ok"),wxDefaultPosition, wxSize(70, 30));
190 wxButton *closeButton = new wxButton(scrollWin, -1, _T("Close"), wxDefaultPosition, wxSize(70, 30));
192 // connect command event handlers
193 Connect(okButton->GetId(),wxEVT_COMMAND_BUTTON_CLICKED,wxCommandEventHandler(wxBlackBoxEditionDialog::onClickOk));
194 Connect(closeButton->GetId(),wxEVT_COMMAND_BUTTON_CLICKED,wxCommandEventHandler(wxBlackBoxEditionDialog::onClickClose));
196 buts->Add(okButton,0,wxCENTRE|wxEXPAND,5);
197 buts->Add(closeButton,0,wxCENTRE|wxEXPAND,5);
199 sizerDialog->AddSpacer(10);
200 sizerDialog->Add(textBoxName,0,wxALIGN_TOP|wxALIGN_CENTER);
201 sizerDialog->AddSpacer(10);
202 sizerDialog->Add(boxnameSizer, wxSizerFlags(0).Align(0).Border(wxLEFT, 100));
203 sizerDialog->AddSpacer(10);
204 sizerDialog->Add(text,0,wxALIGN_TOP|wxALIGN_CENTER);
205 sizerDialog->AddSpacer(15);
206 sizerDialog->Add(sizer,0,wxALIGN_CENTER| wxEXPAND);
207 sizerDialog->AddSpacer(15);
208 sizerDialog->Add(buts,0,wxALIGN_CENTER | wxTOP | wxBOTTOM);
210 scrollWin->SetSizer(sizerDialog);
214 scrollWin->SetVirtualSize(400,400);
215 scrollWin->SetSize(300,300);
216 scrollWin->SetScrollbars(10, 10, 50, 50);
217 // scrollWin->SetSizer(sizer);
224 //=========================================================================
226 void wxBlackBoxEditionDialog::onClickOk(wxCommandEvent& event)
229 for(int i=0;i<(int)_lstValues.size();i++)
231 std::string text = wx2std(_lstValues[i]->GetValue());
232 //TOFIX Search a better alternative
233 if(text!="--No editable--" && text!="--Port Connected--")
235 //JPRG: When executing, add double quotes if necessary
238 addDoubleQuotes(text);
240 _model->setValueToInputPort(i,text);
244 std::string boxname = wx2std(_boxName->GetValue());
245 if( boxname.compare(_initBoxName) != 0 ){
246 if (isValidNameForABox(boxname) == true){
247 if( _parent->boxNameExists(boxname) == true ){
249 wxMessageDialog *dial = new wxMessageDialog(NULL,
250 wxT("The name already exists. Please provide another name"),
251 wxT("Change name: name already exists"), wxOK | wxICON_EXCLAMATION | wxSTAY_ON_TOP);
254 _model->setBBTKName(boxname);
258 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);
264 _parent->SaveTempActualDiagram("edit values");
269 //=========================================================================
271 void wxBlackBoxEditionDialog::onClickClose(wxCommandEvent& event)
276 //=========================================================================
278 //=========================================================================
280 void wxBlackBoxEditionDialog::addDoubleQuotes(std::string &text)
283 //We add the double quotes at the beginning
287 //We add the double quotes at the end
288 if(text[text.length()-1] != '"')
294 //=========================================================================
295 void wxBlackBoxEditionDialog::removeDoubleQuotes(std::string &text)
298 text.replace(0, 1,"");
299 if(text[text.length()-1] == '"')
300 text.replace(text.length()-1, 1,"");
306 } // EO namespace bbtk
309 /* // remove * from the name
310 std::string name = _tabsMgr->GetNameTabPanel();
311 if(name[name.length() - 1] != '*')
312 name = name.substr(0, name.length()-2);
313 _tabsMgr->SetNameTabPanel(name);*/