1 // Copyright (C) 2011-2012 CEA/DEN, EDF R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 #include "MonEditHypothesis.h"
23 #include "MonEditListGroup.h"
25 #include "SalomeApp_Tools.h"
26 #include "HOMARDGUI_Utils.h"
27 #include "HomardQtCommun.h"
28 #include <utilities.h>
29 // ----------------------------------------------------------------------------
30 MonEditHypothesis::MonEditHypothesis( MonCreateIteration* parent, bool modal,
31 HOMARD::HOMARD_Gen_var myHomardGen,
32 QString aHypothesisName,
33 QString caseName, QString aFieldFile ):
34 // ----------------------------------------------------------------------------
35 /* Constructs a MonEditHypothesis
36 herite de MonCreateHypothesis
38 MonCreateHypothesis(parent, modal,myHomardGen, aHypothesisName, caseName, aFieldFile)
40 MESSAGE("Hypothese " << aHypothesisName.toStdString().c_str());
41 setWindowTitle(QObject::tr("HOM_HYPO_EDIT_WINDOW_TITLE"));
42 _aHypothesis = _myHomardGen->GetHypothesis(_aHypothesisName.toStdString().c_str());
43 if (caseName == QString("") ){ _aCaseName = _aHypothesis->GetCaseCreation();}
47 // ------------------------------
48 MonEditHypothesis::~MonEditHypothesis()
49 // ------------------------------
52 // ------------------------------
53 void MonEditHypothesis::InitGroupes()
54 // ------------------------------
56 HOMARD::ListGroupType_var maListe = _aHypothesis->GetGroups();
57 for ( int i = 0; i < maListe->length(); i++ )
58 _aListeGroupes << QString(maListe[i]);
60 if (maListe->length() == 0) { CBGroupe->hide();}
63 // ------------------------------
64 void MonEditHypothesis::InitValEdit()
65 // ------------------------------
67 MESSAGE("Debut de InitValEdit");
68 LEHypothesisName->setText(_aHypothesisName);
69 LEHypothesisName->setReadOnly(true);
70 HOMARD::listeTypes_var ListTypes (_aHypothesis->GetAdapRefinUnRef());
71 ASSERT( ListTypes->length()==3) ;
72 _aTypeAdap = ListTypes[0];
73 _aTypeRaff = ListTypes[1];
74 _aTypeDera = ListTypes[2];
76 if (_aTypeAdap == -1) InitAdaptUniforme();
77 if (_aTypeAdap == 0) InitAdaptZone();
78 if (_aTypeAdap == 1) InitAdaptChamps();
80 RBUniDera->setDisabled(true);
81 RBUniRaff->setDisabled(true);
85 if (_aTypeAdap == 1 or _TypeFieldInterp >= 1 )
87 if (_aFieldFile == QString("")) { GBFieldFile->setVisible(0); }
90 GBFieldFile->setVisible(1);
91 LEFieldFile->setText(_aFieldFile);
92 LEFieldFile->setReadOnly(1);
97 GBFieldFile->setVisible(0);
99 // Les options avancees (non modifiables)
100 CBAdvanced->setVisible(0) ;
101 int NivMax = _aHypothesis->GetNivMax();
102 double DiamMin = _aHypothesis->GetDiamMin();
103 int AdapInit = _aHypothesis->GetAdapInit();
104 if ( NivMax > 0 or DiamMin > 0 or AdapInit != 0 )
105 { GBAdvancedOptions->setVisible(1);
107 { spinBoxNivMax->setValue(NivMax);
108 spinBoxNivMax->setDisabled(true); }
110 { TLMaximalLevel->setVisible(0);
111 spinBoxNivMax->setVisible(0); }
113 { doubleSpinBoxDiamMin->setValue(DiamMin);
114 doubleSpinBoxDiamMin->setDisabled(true); }
116 { TLMinimalDiameter->setVisible(0);
117 doubleSpinBoxDiamMin->setVisible(0); }
121 { RBAIR->setChecked(true); }
123 { RBAID->setChecked(true); }
124 RBAIN->setEnabled(false);
125 RBAIR->setEnabled(false);
126 RBAID->setEnabled(false);
129 { GBAdapInit->setVisible(0) ;
133 { GBAdvancedOptions->setVisible(0); }
137 // ----------------------------------------
138 void MonEditHypothesis::InitAdaptUniforme()
139 // ----------------------------------------
140 // Affichage des informations pour une adaptation uniforme
142 // Choix des options generales
143 GBFieldManagement->setVisible(0);
144 GBAreaManagement->setVisible(0);
145 GBUniform->setVisible(1);
147 RBUniforme->setChecked(true);
148 RBUniforme->setEnabled(false);
149 RBChamp->setEnabled(false);
150 RBZone->setEnabled(false);
152 // Raffinement ou deraffinement ?
155 ASSERT(_aTypeRaff==1);
156 RBUniDera->setChecked(false);
157 RBUniRaff->setChecked(true);
161 ASSERT(_aTypeRaff==0);
162 RBUniDera->setChecked(true);
163 RBUniRaff->setChecked(false);
167 // -------------------------------------
168 void MonEditHypothesis::InitAdaptZone()
169 // -------------------------------------
170 // Affichage des informations pour une adaptation selon des zones :
172 MESSAGE ("Debut de InitAdaptZone");
173 // Choix des options generales
174 GBUniform->setVisible(0);
175 GBFieldManagement->setVisible(0);
176 GBAreaManagement->setVisible(1);
178 RBZone->setChecked(true);
179 RBChamp->setEnabled(false);
180 RBUniforme->setEnabled(false);
181 RBZone->setEnabled(false);
183 // Recuperation de toutes les zones decrites et notation de celles retenues
185 HOMARD::listeZonesHypo_var mesZonesAvant = _aHypothesis->GetZones();
186 for (int i=0; i<mesZonesAvant->length(); i++)
188 MESSAGE ("i"<<i<<", zone :"<<string(mesZonesAvant[i])<<", type :"<<string(mesZonesAvant[i+1]));
189 for ( int j =0 ; j < TWZone->rowCount(); j++)
191 MESSAGE (". j"<<j<<", zone :"<<TWZone->item(j,2)->text().toStdString());
192 if ( TWZone->item(j,2)->text().toStdString() == string(mesZonesAvant[i]) )
194 MESSAGE ("OK avec "<<string(mesZonesAvant[i]));
195 if ( string(mesZonesAvant[i+1]) == "1" )
197 MESSAGE ("... RAFF");
198 TWZone->item( j,0 )->setCheckState( Qt::Checked );
199 TWZone->item( j,1 )->setCheckState( Qt::Unchecked ); }
202 MESSAGE ("... DERA");
203 TWZone->item( j,0 )->setCheckState( Qt::Unchecked );
204 TWZone->item( j,1 )->setCheckState( Qt::Checked ); }
211 // Inactivation des choix
212 for ( int j =0 ; j < TWZone->rowCount(); j++)
214 TWZone->item( j, 0 )->setFlags(0);
215 TWZone->item( j, 1 )->setFlags(0);
217 PBZoneNew->setVisible(0);
220 // -------------------------------------
221 void MonEditHypothesis::InitAdaptChamps()
222 // -------------------------------------
223 // Affichage des informations pour une adaptation selon un champ :
229 MESSAGE ("Debut de InitAdaptChamps");
230 // Choix des options generales
231 GBUniform->setVisible(0);
232 GBAreaManagement->setVisible(0);
233 GBFieldManagement->setVisible(1);
235 RBChamp->setChecked(true);
236 RBUniforme->setEnabled(false);
237 RBChamp->setEnabled(false);
238 RBZone->setEnabled(false);
242 HOMARD::InfosHypo_var aInfosHypo = _aHypothesis->GetField();
243 _aFieldName = aInfosHypo->FieldName;
244 _TypeThR = aInfosHypo->TypeThR;
245 _ThreshR = aInfosHypo->ThreshR;
246 _TypeThC = aInfosHypo->TypeThC;
247 _ThreshC = aInfosHypo->ThreshC;
248 _UsField = aInfosHypo->UsField;
249 _UsCmpI = aInfosHypo->UsCmpI;
252 CBFieldName->insertItem(0,_aFieldName);
253 CBFieldName->setCurrentIndex(0);
254 CBFieldName->setEnabled(false);
255 //SetFieldName(Qt::Unchecked);
257 HOMARD::listeComposantsHypo_var mesComposantsAvant = _aHypothesis->GetListComp();
259 TWCMP->setRowCount(0);
260 TWCMP->resizeRowsToContents();
261 for (int i=0; i<mesComposantsAvant->length(); i++)
264 TWCMP->setItem( 0, 0, new QTableWidgetItem( QString ("") ) );
265 TWCMP->item( 0, 0 )->setFlags( Qt::ItemIsUserCheckable|Qt::ItemIsEnabled);
266 TWCMP->item( 0, 0 )->setCheckState(Qt::Checked );
267 TWCMP->item( 0, 0 )->setFlags( 0 );
268 TWCMP->setItem( 0, 1, new QTableWidgetItem(QString(mesComposantsAvant[i]).trimmed()));
269 TWCMP->item( 0, 1 )->setFlags( Qt::ItemIsEnabled |Qt::ItemIsSelectable );
271 TWCMP->resizeColumnsToContents();
272 TWCMP->resizeRowsToContents();
273 TWCMP->clearSelection();
275 // Les seuils de raffinement
276 RBRAbs->setEnabled(false) ;
277 RBRRel->setEnabled(false) ;
278 RBRPE->setEnabled(false) ;
279 RBRNo->setEnabled(false) ;
283 RBRNo->setEnabled(true) ;
287 if ( _TypeThR == 1 ) { SpinBox_RAbs->setValue(_ThreshR); SetRAbs(); RBRAbs->setEnabled(true);}
288 if ( _TypeThR == 2 ) { SpinBox_RRel->setValue(_ThreshR); SetRRel(); RBRRel->setEnabled(true);}
289 if ( _TypeThR == 3 ) { SpinBox_RPE->setValue(_ThreshR); SetRPE(); RBRPE->setEnabled(true);}
292 // Les seuils de deraffinement
293 RBCAbs->setEnabled(false) ;
294 RBCRel->setEnabled(false) ;
295 RBCPE->setEnabled(false) ;
296 RBCNo->setEnabled(false) ;
300 RBCNo->setEnabled(true) ;
304 if ( _TypeThC == 1 ) { SpinBox_CAbs->setValue(_ThreshC); SetCAbs(); RBCAbs->setEnabled(true);}
305 if ( _TypeThC == 2 ) { SpinBox_CRel->setValue(_ThreshC); SetCRel(); RBCRel->setEnabled(true);}
306 if ( _TypeThC == 3 ) { SpinBox_CPE->setValue(_ThreshC); SetCPE(); RBCPE->setEnabled(true);}
308 // Le choix de la prise en compte des composantes
309 if ( TWCMP->rowCount() == 1 )
310 { RBL2->setText(QObject::tr("HOM_HYPO_NORM_ABS"));
311 RBInf->setText(QObject::tr("HOM_HYPO_NORM_REL"));
314 { RBL2->setText(QObject::tr("HOM_HYPO_NORM_L2"));
315 RBInf->setText(QObject::tr("HOM_HYPO_NORM_INF"));
317 if ( _UsField == 0 ) { CBJump->hide(); }
320 CBJump->setChecked(true);
321 CBJump->setEnabled(false);
325 RBL2->setChecked(true);
326 RBL2->setEnabled(true);
327 RBInf->setEnabled(false) ;
331 RBL2->setEnabled(false) ;
332 RBInf->setChecked(true);
333 RBInf->setEnabled(true);
336 // -------------------------------------
337 void MonEditHypothesis::InitFieldInterp()
338 // -------------------------------------
339 // Affichage des informations pour les interpolations
341 MESSAGE ("Debut de InitFieldInterp");
342 // Choix des options generales
343 _TypeFieldInterp = _aHypothesis->GetTypeFieldInterp();
344 MESSAGE ("_TypeFieldInterp = " << _TypeFieldInterp);
346 // Aucune interpolation
347 if ( _TypeFieldInterp == 0 )
349 RBFieldNo->setChecked(true);
350 TWField->setVisible(0);
352 // Interpolation de tous les champs
353 if ( _TypeFieldInterp == 1 )
355 RBFieldAll->setChecked(true);
356 TWField->setVisible(0);
358 // Interpolation de champs choisis
359 if ( _TypeFieldInterp == 2 )
361 RBFieldChosen->setChecked(true);
363 TWField->setVisible(1);
364 HOMARD::listFieldInterpHypo_var mesChampsAvant = _aHypothesis->GetListFieldInterp();
366 TWField->setRowCount(0);
367 TWField->resizeRowsToContents();
368 for (int i=0; i<mesChampsAvant->length(); i++)
370 TWField->insertRow(0);
371 TWField->setItem( 0, 0, new QTableWidgetItem( QString ("") ) );
372 TWField->item( 0, 0 )->setFlags( Qt::ItemIsUserCheckable|Qt::ItemIsEnabled);
373 TWField->item( 0, 0 )->setCheckState(Qt::Checked );
374 TWField->item( 0, 0 )->setFlags( 0 );
375 TWField->setItem( 0, 1, new QTableWidgetItem(QString(mesChampsAvant[i]).trimmed()));
376 TWField->item( 0, 1 )->setFlags( Qt::ItemIsEnabled |Qt::ItemIsSelectable );
378 TWField->resizeColumnsToContents();
379 TWField->resizeRowsToContents();
380 TWField->clearSelection();
382 RBFieldNo->setEnabled(false) ;
383 RBFieldAll->setEnabled(false) ;
384 RBFieldChosen->setEnabled(false) ;
387 // -------------------------------------
388 bool MonEditHypothesis::PushOnApply()
389 // -------------------------------------
391 // Pour du raffinement selon un champ, les seuils ont-ils change ?
392 if ( _aTypeAdap == 1 )
396 if (_TypeThR == 1) { _ThreshR = SpinBox_RAbs->value(); }
397 if (_TypeThR == 2) { _ThreshR = SpinBox_RRel->value(); }
398 if (_TypeThR == 3) { _ThreshR = SpinBox_RPE->value(); }
399 _aHypothesis->SetRefinThr(_TypeThR, _ThreshR) ;
403 if (_TypeThC == 1) { _ThreshC = SpinBox_CAbs->value() ; }
404 if (_TypeThC == 2) { _ThreshC = SpinBox_CRel->value() ; }
405 if (_TypeThC == 3) { _ThreshC = SpinBox_CPE->value() ; }
406 _aHypothesis->SetUnRefThr(_TypeThC, _ThreshC) ;
409 _myHomardGen->InvalideHypo(_aHypothesisName.toStdString().c_str());
410 HOMARD_UTILS::updateObjBrowser();
414 // ------------------------------------------------------------------------
415 void MonEditHypothesis::SetFiltrage()
416 // ------------------------------------------------------------------------
418 if (CBGroupe->isChecked())
420 MonEditListGroup *aDlg = new MonEditListGroup(this, NULL, TRUE, HOMARD::HOMARD_Gen::_duplicate(_myHomardGen),_aCaseName, _aListeGroupes) ;