1 // Copyright (C) 2011-2013 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 int LevelOutput = _aHypothesis->GetLevelOutput();
105 if ( NivMax > 0 or DiamMin > 0 or AdapInit != 0 or LevelOutput != 0 )
106 { GBAdvancedOptions->setVisible(1);
108 { spinBoxNivMax->setValue(NivMax);
109 spinBoxNivMax->setDisabled(true); }
111 { TLMaximalLevel->setVisible(0);
112 spinBoxNivMax->setVisible(0); }
114 { doubleSpinBoxDiamMin->setValue(DiamMin);
115 doubleSpinBoxDiamMin->setDisabled(true); }
117 { TLMinimalDiameter->setVisible(0);
118 doubleSpinBoxDiamMin->setVisible(0); }
122 { RBAIR->setChecked(true); }
124 { RBAID->setChecked(true); }
125 RBAIN->setEnabled(false);
126 RBAIR->setEnabled(false);
127 RBAID->setEnabled(false);
130 { GBAdapInit->setVisible(0) ;
132 if ( LevelOutput != 0 )
134 CBLevelOutput->setChecked(true);
135 CBLevelOutput->setEnabled(false);
138 { CBLevelOutput->setVisible(0) ;
142 { GBAdvancedOptions->setVisible(0); }
146 // ----------------------------------------
147 void MonEditHypothesis::InitAdaptUniforme()
148 // ----------------------------------------
149 // Affichage des informations pour une adaptation uniforme
151 // Choix des options generales
152 GBFieldManagement->setVisible(0);
153 GBAreaManagement->setVisible(0);
154 GBUniform->setVisible(1);
156 RBUniforme->setChecked(true);
157 RBUniforme->setEnabled(false);
158 RBChamp->setEnabled(false);
159 RBZone->setEnabled(false);
161 // Raffinement ou deraffinement ?
164 ASSERT(_aTypeRaff==1);
165 RBUniDera->setChecked(false);
166 RBUniRaff->setChecked(true);
170 ASSERT(_aTypeRaff==0);
171 RBUniDera->setChecked(true);
172 RBUniRaff->setChecked(false);
176 // -------------------------------------
177 void MonEditHypothesis::InitAdaptZone()
178 // -------------------------------------
179 // Affichage des informations pour une adaptation selon des zones :
181 MESSAGE ("Debut de InitAdaptZone");
182 // Choix des options generales
183 GBUniform->setVisible(0);
184 GBFieldManagement->setVisible(0);
185 GBAreaManagement->setVisible(1);
187 RBZone->setChecked(true);
188 RBChamp->setEnabled(false);
189 RBUniforme->setEnabled(false);
190 RBZone->setEnabled(false);
192 // Recuperation de toutes les zones decrites et notation de celles retenues
194 HOMARD::listeZonesHypo_var mesZonesAvant = _aHypothesis->GetZones();
195 for (int i=0; i<mesZonesAvant->length(); i++)
197 MESSAGE ("i"<<i<<", zone :"<<string(mesZonesAvant[i])<<", type :"<<string(mesZonesAvant[i+1]));
198 for ( int j =0 ; j < TWZone->rowCount(); j++)
200 MESSAGE (". j"<<j<<", zone :"<<TWZone->item(j,2)->text().toStdString());
201 if ( TWZone->item(j,2)->text().toStdString() == string(mesZonesAvant[i]) )
203 MESSAGE ("OK avec "<<string(mesZonesAvant[i]));
204 if ( string(mesZonesAvant[i+1]) == "1" )
206 MESSAGE ("... RAFF");
207 TWZone->item( j,0 )->setCheckState( Qt::Checked );
208 TWZone->item( j,1 )->setCheckState( Qt::Unchecked ); }
211 MESSAGE ("... DERA");
212 TWZone->item( j,0 )->setCheckState( Qt::Unchecked );
213 TWZone->item( j,1 )->setCheckState( Qt::Checked ); }
220 // Inactivation des choix
221 for ( int j =0 ; j < TWZone->rowCount(); j++)
223 TWZone->item( j, 0 )->setFlags(0);
224 TWZone->item( j, 1 )->setFlags(0);
226 PBZoneNew->setVisible(0);
229 // -------------------------------------
230 void MonEditHypothesis::InitAdaptChamps()
231 // -------------------------------------
232 // Affichage des informations pour une adaptation selon un champ :
238 MESSAGE ("Debut de InitAdaptChamps");
239 // Choix des options generales
240 GBUniform->setVisible(0);
241 GBAreaManagement->setVisible(0);
242 GBFieldManagement->setVisible(1);
244 RBChamp->setChecked(true);
245 RBUniforme->setEnabled(false);
246 RBChamp->setEnabled(false);
247 RBZone->setEnabled(false);
249 HOMARD::InfosHypo_var aInfosHypo = _aHypothesis->GetField();
250 _aFieldName = aInfosHypo->FieldName;
251 _TypeThR = aInfosHypo->TypeThR;
252 _ThreshR = aInfosHypo->ThreshR;
253 _TypeThC = aInfosHypo->TypeThC;
254 _ThreshC = aInfosHypo->ThreshC;
255 _UsField = aInfosHypo->UsField;
256 _UsCmpI = aInfosHypo->UsCmpI;
258 CBFieldName->insertItem(0,_aFieldName);
259 CBFieldName->setCurrentIndex(0);
260 CBFieldName->setEnabled(false);
261 //SetFieldName(Qt::Unchecked);
263 HOMARD::listeComposantsHypo_var mesComposantsAvant = _aHypothesis->GetListComp();
265 TWCMP->setRowCount(0);
266 TWCMP->resizeRowsToContents();
267 for (int i=0; i<mesComposantsAvant->length(); i++)
270 TWCMP->setItem( 0, 0, new QTableWidgetItem( QString ("") ) );
271 TWCMP->item( 0, 0 )->setFlags( Qt::ItemIsUserCheckable|Qt::ItemIsEnabled);
272 TWCMP->item( 0, 0 )->setCheckState(Qt::Checked );
273 TWCMP->item( 0, 0 )->setFlags( 0 );
274 TWCMP->setItem( 0, 1, new QTableWidgetItem(QString(mesComposantsAvant[i]).trimmed()));
275 TWCMP->item( 0, 1 )->setFlags( Qt::ItemIsEnabled |Qt::ItemIsSelectable );
277 TWCMP->resizeColumnsToContents();
278 TWCMP->resizeRowsToContents();
279 TWCMP->clearSelection();
281 // Les seuils de raffinement
282 RBRAbs->setEnabled(false) ;
283 RBRRel->setEnabled(false) ;
284 RBRPE->setEnabled(false) ;
285 RBRMuSigma->setEnabled(false) ;
286 RBRNo->setEnabled(false) ;
290 RBRNo->setEnabled(true) ;
294 if ( _TypeThR == 1 ) { SpinBox_RAbs->setValue(_ThreshR); SetRAbs(); RBRAbs->setEnabled(true);}
295 if ( _TypeThR == 2 ) { SpinBox_RRel->setValue(_ThreshR); SetRRel(); RBRRel->setEnabled(true);}
296 if ( _TypeThR == 3 ) { SpinBox_RPE->setValue(_ThreshR); SetRPE(); RBRPE->setEnabled(true);}
297 if ( _TypeThR == 4 ) { SpinBox_RMuSigma->setValue(_ThreshR); SetRMS(); RBRMuSigma->setEnabled(true);}
300 // Les seuils de deraffinement
301 RBCAbs->setEnabled(false) ;
302 RBCRel->setEnabled(false) ;
303 RBCPE->setEnabled(false) ;
304 RBCMuSigma->setEnabled(false) ;
305 RBCNo->setEnabled(false) ;
309 RBCNo->setEnabled(true) ;
313 if ( _TypeThC == 1 ) { SpinBox_CAbs->setValue(_ThreshC); SetCAbs(); RBCAbs->setEnabled(true);}
314 if ( _TypeThC == 2 ) { SpinBox_CRel->setValue(_ThreshC); SetCRel(); RBCRel->setEnabled(true);}
315 if ( _TypeThC == 3 ) { SpinBox_CPE->setValue(_ThreshC); SetCPE(); RBCPE->setEnabled(true);}
316 if ( _TypeThC == 4 ) { SpinBox_CMuSigma->setValue(_ThreshC); SetCMS(); RBCMuSigma->setEnabled(true);}
318 // Le choix de la prise en compte des composantes
319 if ( TWCMP->rowCount() == 1 )
320 { RBL2->setText(QObject::tr("HOM_HYPO_NORM_ABS"));
321 RBInf->setText(QObject::tr("HOM_HYPO_NORM_REL"));
324 { RBL2->setText(QObject::tr("HOM_HYPO_NORM_L2"));
325 RBInf->setText(QObject::tr("HOM_HYPO_NORM_INF"));
327 if ( _UsField == 0 ) { CBJump->hide(); }
330 CBJump->setChecked(true);
331 CBJump->setEnabled(false);
335 RBL2->setChecked(true);
336 RBL2->setEnabled(true);
337 RBInf->setEnabled(false) ;
341 RBL2->setEnabled(false) ;
342 RBInf->setChecked(true);
343 RBInf->setEnabled(true);
346 // -------------------------------------
347 void MonEditHypothesis::InitFieldInterp()
348 // -------------------------------------
349 // Affichage des informations pour les interpolations
351 MESSAGE ("Debut de InitFieldInterp");
352 // Choix des options generales
353 _TypeFieldInterp = _aHypothesis->GetTypeFieldInterp();
354 MESSAGE ("_TypeFieldInterp = " << _TypeFieldInterp);
356 // Aucune interpolation
357 if ( _TypeFieldInterp == 0 )
359 RBFieldNo->setChecked(true);
360 TWField->setVisible(0);
362 // Interpolation de tous les champs
363 if ( _TypeFieldInterp == 1 )
365 RBFieldAll->setChecked(true);
366 TWField->setVisible(0);
368 // Interpolation de champs choisis
369 if ( _TypeFieldInterp == 2 )
371 RBFieldChosen->setChecked(true);
373 TWField->setVisible(1);
374 HOMARD::listFieldInterpHypo_var mesChampsAvant = _aHypothesis->GetListFieldInterp();
376 TWField->setRowCount(0);
377 TWField->resizeRowsToContents();
378 for (int i=0; i<mesChampsAvant->length(); i++)
380 TWField->insertRow(0);
381 TWField->setItem( 0, 0, new QTableWidgetItem( QString ("") ) );
382 TWField->item( 0, 0 )->setFlags( Qt::ItemIsUserCheckable|Qt::ItemIsEnabled);
383 TWField->item( 0, 0 )->setCheckState(Qt::Checked );
384 TWField->item( 0, 0 )->setFlags( 0 );
385 TWField->setItem( 0, 1, new QTableWidgetItem(QString(mesChampsAvant[i]).trimmed()));
386 TWField->item( 0, 1 )->setFlags( Qt::ItemIsEnabled |Qt::ItemIsSelectable );
388 TWField->resizeColumnsToContents();
389 TWField->resizeRowsToContents();
390 TWField->clearSelection();
392 RBFieldNo->setEnabled(false) ;
393 RBFieldAll->setEnabled(false) ;
394 RBFieldChosen->setEnabled(false) ;
397 // -------------------------------------
398 bool MonEditHypothesis::PushOnApply()
399 // -------------------------------------
401 // Pour du raffinement selon un champ, les seuils ont-ils change ?
402 if ( _aTypeAdap == 1 )
406 if (_TypeThR == 1) { _ThreshR = SpinBox_RAbs->value(); }
407 if (_TypeThR == 2) { _ThreshR = SpinBox_RRel->value(); }
408 if (_TypeThR == 3) { _ThreshR = SpinBox_RPE->value(); }
409 if (_TypeThR == 4) { _ThreshR = SpinBox_RMuSigma->value(); }
410 _aHypothesis->SetRefinThr(_TypeThR, _ThreshR) ;
414 if (_TypeThC == 1) { _ThreshC = SpinBox_CAbs->value() ; }
415 if (_TypeThC == 2) { _ThreshC = SpinBox_CRel->value() ; }
416 if (_TypeThC == 3) { _ThreshC = SpinBox_CPE->value() ; }
417 if (_TypeThC == 4) { _ThreshC = SpinBox_CMuSigma->value() ; }
418 _aHypothesis->SetUnRefThr(_TypeThC, _ThreshC) ;
421 _myHomardGen->InvalideHypo(_aHypothesisName.toStdString().c_str());
422 HOMARD_UTILS::updateObjBrowser();
426 // ------------------------------------------------------------------------
427 void MonEditHypothesis::SetFiltrage()
428 // ------------------------------------------------------------------------
430 if (CBGroupe->isChecked())
432 MonEditListGroup *aDlg = new MonEditListGroup(this, NULL, TRUE, HOMARD::HOMARD_Gen::_duplicate(_myHomardGen),_aCaseName, _aListeGroupes) ;