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(1200, 1200),wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER)
70 :wxDialog(NULL,wxID_ANY,_T(""), wxDefaultPosition, wxSize(1200, 1200),wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER)
74 std::string title("BlackBox Editing - ");
75 title+=_model->getBBTKPackage();
77 title+=_model->getBBTKType();
79 title+=_model->getBBTKName();
80 SetTitle(std2wx(title));
82 constructBlackBoxEditionDialog();
85 //=========================================================================
88 wxBlackBoxEditionDialog::~wxBlackBoxEditionDialog()
93 //=========================================================================
95 bool wxBlackBoxEditionDialog::isValidNameForABox(std::string boxname) {
98 for (i = 0; i < boxname.size() ; i++) {
99 if ( (isalnum(boxname[i])==0) && (boxname.compare(i, 1, "-") != 0) && ( boxname.compare(i, 1, "_") != 0) ){
107 //=========================================================================
109 void wxBlackBoxEditionDialog::constructBlackBoxEditionDialog()
111 wxBoxSizer *sizerDialog = new wxBoxSizer(wxVERTICAL);
113 wxScrolledWindow *scrollWin = new wxScrolledWindow( this, -1, wxDefaultPosition, wxSize(200,200), wxVSCROLL);
115 wxString boxtype( crea::std2wx( _model->getBBTKType() ) );
117 wxStaticText *textBoxName = new wxStaticText(scrollWin, -1, wxT("Box Name"));
118 wxStaticText *textBoxType = new wxStaticText(scrollWin, -1, boxtype+wxT(": ") );
119 wxTextCtrl *valueBoxName = new wxTextCtrl(scrollWin, -1, _T(""), wxDefaultPosition,wxSize(300,25));
120 _initBoxName = _model->getBBTKName();
121 valueBoxName->SetValue(crea::std2wx(_initBoxName));
122 _boxName = valueBoxName ;
124 wxBoxSizer *boxnameSizer = new wxBoxSizer(wxHORIZONTAL);
125 boxnameSizer->Add(textBoxType,0,wxEXPAND,5);
126 boxnameSizer->Add(valueBoxName,0,wxEXPAND,5);
127 boxnameSizer->Add( new wxStaticText(scrollWin, -1, wxT(" ")) ,0,wxCENTRE|wxEXPAND,5);
131 wxStaticText *text = new wxStaticText(scrollWin, -1, wxT("Input Ports"));
132 wxFont font(11, wxDEFAULT, wxNORMAL, wxBOLD);
134 textBoxName->SetFont(font);
137 std::vector<GPortModel*> lstInputs = _model->getInputPorts();
138 wxFlexGridSizer *sizer = new wxFlexGridSizer(lstInputs.size(),3,5,5);
139 sizer->AddGrowableCol(0);
140 sizer->AddGrowableCol(1);
141 sizer->AddGrowableCol(2);
143 for(int i = 0;i<(int)lstInputs.size();i++)
145 sizer->AddGrowableRow(i);
146 GPortModel *port = lstInputs[i];
147 std::string type = port->getBBTKType();
148 wxStaticText *lblName = new wxStaticText(scrollWin, -1, std2wx(port->getBBTKName()),wxDefaultPosition,wxDefaultSize);
149 wxStaticText *lblType = new wxStaticText(scrollWin, -1, std2wx(type),wxDefaultPosition,wxSize(250,25));
150 wxTextCtrl *txtValue = new wxTextCtrl(scrollWin, -1, _T(""),wxDefaultPosition,wxDefaultSize);
154 lblName->SetToolTip( std2wx(port->getBBTKDescription()) );
155 txtValue->SetToolTip( std2wx(port->getBBTKDescription()) );
158 if(port->getValue()!="")
160 std::string text = port->getValue();
162 addDoubleQuotes(text);
163 txtValue->SetValue(crea::std2wx(text));
166 if(port->isConnected())
168 std::string connected("--Port Connected--");
169 txtValue->SetValue(crea::std2wx(connected));
170 txtValue->SetEditable(false);
174 if(type.find(et)!=-1)
176 std::string noEditable("--No editable--");
177 txtValue->SetValue(crea::std2wx(noEditable));
178 txtValue->SetEditable(false);
181 _lstNames.push_back(lblName);
182 _lstValues.push_back(txtValue);
183 _lstTypes.push_back(lblType);
185 sizer->Add(lblName,1,wxEXPAND,5);
186 sizer->Add(txtValue,1,wxEXPAND,5);
187 sizer->Add(lblType,1,wxCENTRE|wxEXPAND,5);
191 wxBoxSizer *buts = new wxBoxSizer(wxHORIZONTAL);
192 wxButton *okButton = new wxButton(scrollWin, -1, _T("Ok"),wxDefaultPosition, wxSize(70, 30));
193 wxButton *closeButton = new wxButton(scrollWin, -1, _T("Close"), wxDefaultPosition, wxSize(70, 30));
195 // connect command event handlers
196 Connect(okButton->GetId(),wxEVT_COMMAND_BUTTON_CLICKED,wxCommandEventHandler(wxBlackBoxEditionDialog::onClickOk));
197 Connect(closeButton->GetId(),wxEVT_COMMAND_BUTTON_CLICKED,wxCommandEventHandler(wxBlackBoxEditionDialog::onClickClose));
199 buts->Add(okButton,0,wxCENTRE|wxEXPAND,5);
200 buts->Add(closeButton,0,wxCENTRE|wxEXPAND,5);
202 sizerDialog->AddSpacer(10);
203 sizerDialog->Add(textBoxName,0,wxALIGN_TOP|wxALIGN_CENTER);
204 sizerDialog->AddSpacer(10);
205 sizerDialog->Add(boxnameSizer, wxSizerFlags(0).Align(0).Border(wxLEFT, 100));
206 sizerDialog->AddSpacer(10);
207 sizerDialog->Add(text,0,wxALIGN_TOP|wxALIGN_CENTER);
208 sizerDialog->AddSpacer(15);
209 sizerDialog->Add(sizer,0,wxALIGN_CENTER| wxEXPAND);
210 sizerDialog->AddSpacer(15);
211 sizerDialog->Add(buts,0,wxALIGN_CENTER | wxTOP | wxBOTTOM);
213 scrollWin->SetSizer(sizerDialog);
217 scrollWin->SetVirtualSize(400,400);
218 scrollWin->SetSize(300,300);
219 scrollWin->SetScrollbars(10, 10, 50, 50);
220 // scrollWin->SetSizer(sizer);
227 //=========================================================================
229 void wxBlackBoxEditionDialog::onClickOk(wxCommandEvent& event)
232 for(int i=0;i<(int)_lstValues.size();i++)
234 std::string text = wx2std(_lstValues[i]->GetValue());
235 //TOFIX Search a better alternative
236 if(text!="--No editable--" && text!="--Port Connected--")
238 //JPRG: When executing, add double quotes if necessary
241 addDoubleQuotes(text);
243 _model->setValueToInputPort(i,text);
247 std::string boxname = wx2std(_boxName->GetValue());
248 if( boxname.compare(_initBoxName) != 0 ){
249 if (isValidNameForABox(boxname) == true){
250 if( _parent->boxNameExists(boxname) == true ){
252 wxMessageDialog *dial = new wxMessageDialog(NULL,
253 wxT("The name already exists. Please provide another name"),
254 wxT("Change name: name already exists"), wxOK | wxICON_EXCLAMATION | wxSTAY_ON_TOP);
257 _model->setBBTKName(boxname);
261 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);
267 _parent->SaveTempActualDiagram("edit values");
272 //=========================================================================
274 void wxBlackBoxEditionDialog::onClickClose(wxCommandEvent& event)
279 //=========================================================================
281 //=========================================================================
283 void wxBlackBoxEditionDialog::addDoubleQuotes(std::string &text)
286 //We add the double quotes at the beginning
290 //We add the double quotes at the end
291 if(text[text.length()-1] != '"')
297 //=========================================================================
298 void wxBlackBoxEditionDialog::removeDoubleQuotes(std::string &text)
301 text.replace(0, 1,"");
302 if(text[text.length()-1] == '"')
303 text.replace(text.length()-1, 1,"");
309 } // EO namespace bbtk
312 /* // remove * from the name
313 std::string name = _tabsMgr->GetNameTabPanel();
314 if(name[name.length() - 1] != '*')
315 name = name.substr(0, name.length()-2);
316 _tabsMgr->SetNameTabPanel(name);*/