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"
29 #include <utilities.h>
30 // ----------------------------------------------------------------------------
31 MonEditHypothesis::MonEditHypothesis( MonCreateIteration* parent, bool modal,
32 HOMARD::HOMARD_Gen_var myHomardGen,
34 QString caseName, QString aFieldFile ):
35 // ----------------------------------------------------------------------------
36 /* Constructs a MonEditHypothesis
37 herite de MonCreateHypothesis
39 MonCreateHypothesis(parent, modal,myHomardGen, Name, caseName, aFieldFile)
41 MESSAGE("Hypothese " << Name.toStdString().c_str());
42 setWindowTitle(QObject::tr("HOM_HYPO_EDIT_WINDOW_TITLE"));
43 aHypothesis = myHomardGen->GetHypothesis(_Name.toStdString().c_str());
44 if (caseName == QString("") ){ _aCaseName = aHypothesis->GetCaseCreation();}
48 // ------------------------------
49 MonEditHypothesis::~MonEditHypothesis()
50 // ------------------------------
53 // ------------------------------
54 void MonEditHypothesis::InitGroupes()
55 // ------------------------------
57 HOMARD::ListGroupType_var maListe = aHypothesis->GetGroups();
58 for ( int i = 0; i < maListe->length(); i++ )
59 _aListeGroupes << QString(maListe[i]);
61 if (maListe->length() == 0) { CBGroupe->hide();}
64 // ------------------------------
65 void MonEditHypothesis::InitValEdit()
66 // ------------------------------
68 MESSAGE("Debut de InitValEdit");
69 LEName->setText(_Name);
70 LEName->setReadOnly(true);
71 HOMARD::listeTypes_var ListTypes (aHypothesis->GetAdapRefinUnRef());
72 ASSERT( ListTypes->length()==3) ;
73 _aTypeAdap = ListTypes[0];
74 _aTypeRaff = ListTypes[1];
75 _aTypeDera = ListTypes[2];
77 if (_aTypeAdap == -1) InitAdaptUniforme();
78 if (_aTypeAdap == 0) InitAdaptZone();
79 if (_aTypeAdap == 1) InitAdaptChamps();
81 RBUniDera->setDisabled(true);
82 RBUniRaff->setDisabled(true);
86 if (_aTypeAdap == 1 or _TypeFieldInterp >= 1 )
88 if (_aFieldFile == QString("")) { GBFieldFile->setVisible(0); }
91 GBFieldFile->setVisible(1);
92 LEFieldFile->setText(_aFieldFile);
93 LEFieldFile->setReadOnly(1);
98 GBFieldFile->setVisible(0);
100 // Les options avancees (non modifiables)
101 CBAdvanced->setVisible(0) ;
102 int NivMax = aHypothesis->GetNivMax();
103 double DiamMin = aHypothesis->GetDiamMin();
104 int AdapInit = aHypothesis->GetAdapInit();
105 int LevelOutput = aHypothesis->GetLevelOutput();
106 if ( NivMax > 0 or DiamMin > 0 or AdapInit != 0 or LevelOutput != 0 )
107 { GBAdvancedOptions->setVisible(1);
109 { spinBoxNivMax->setValue(NivMax);
110 spinBoxNivMax->setDisabled(true); }
112 { TLMaximalLevel->setVisible(0);
113 spinBoxNivMax->setVisible(0); }
115 { doubleSpinBoxDiamMin->setValue(DiamMin);
116 doubleSpinBoxDiamMin->setDisabled(true); }
118 { TLMinimalDiameter->setVisible(0);
119 doubleSpinBoxDiamMin->setVisible(0); }
123 { RBAIR->setChecked(true); }
125 { RBAID->setChecked(true); }
126 RBAIN->setEnabled(false);
127 RBAIR->setEnabled(false);
128 RBAID->setEnabled(false);
131 { GBAdapInit->setVisible(0) ;
133 if ( LevelOutput != 0 )
135 CBLevelOutput->setChecked(true);
136 CBLevelOutput->setEnabled(false);
139 { CBLevelOutput->setVisible(0) ;
143 { GBAdvancedOptions->setVisible(0); }
147 // ----------------------------------------
148 void MonEditHypothesis::InitAdaptUniforme()
149 // ----------------------------------------
150 // Affichage des informations pour une adaptation uniforme
152 // Choix des options generales
153 GBFieldManagement->setVisible(0);
154 GBAreaManagement->setVisible(0);
155 GBUniform->setVisible(1);
157 RBUniforme->setChecked(true);
158 RBUniforme->setEnabled(false);
159 RBChamp->setEnabled(false);
160 RBZone->setEnabled(false);
162 // Raffinement ou deraffinement ?
165 VERIFICATION(_aTypeRaff==1);
166 RBUniDera->setChecked(false);
167 RBUniRaff->setChecked(true);
171 VERIFICATION(_aTypeRaff==0);
172 RBUniDera->setChecked(true);
173 RBUniRaff->setChecked(false);
177 // -------------------------------------
178 void MonEditHypothesis::InitAdaptZone()
179 // -------------------------------------
180 // Affichage des informations pour une adaptation selon des zones :
182 MESSAGE ("Debut de InitAdaptZone");
183 // Choix des options generales
184 GBUniform->setVisible(0);
185 GBFieldManagement->setVisible(0);
186 GBAreaManagement->setVisible(1);
188 RBZone->setChecked(true);
189 RBChamp->setEnabled(false);
190 RBUniforme->setEnabled(false);
191 RBZone->setEnabled(false);
193 // Recuperation de toutes les zones decrites et notation de celles retenues
195 HOMARD::listeZonesHypo_var mesZonesAvant = aHypothesis->GetZones();
196 for (int i=0; i<mesZonesAvant->length(); i++)
198 MESSAGE ("i"<<i<<", zone :"<<string(mesZonesAvant[i])<<", type :"<<string(mesZonesAvant[i+1]));
199 for ( int j =0 ; j < TWZone->rowCount(); j++)
201 MESSAGE (". j"<<j<<", zone :"<<TWZone->item(j,2)->text().toStdString());
202 if ( TWZone->item(j,2)->text().toStdString() == string(mesZonesAvant[i]) )
204 MESSAGE ("OK avec "<<string(mesZonesAvant[i]));
205 if ( string(mesZonesAvant[i+1]) == "1" )
207 MESSAGE ("... RAFF");
208 TWZone->item( j,0 )->setCheckState( Qt::Checked );
209 TWZone->item( j,1 )->setCheckState( Qt::Unchecked ); }
212 MESSAGE ("... DERA");
213 TWZone->item( j,0 )->setCheckState( Qt::Unchecked );
214 TWZone->item( j,1 )->setCheckState( Qt::Checked ); }
221 // Inactivation des choix
222 for ( int j =0 ; j < TWZone->rowCount(); j++)
224 TWZone->item( j, 0 )->setFlags(0);
225 TWZone->item( j, 1 )->setFlags(0);
227 PBZoneNew->setVisible(0);
230 // -------------------------------------
231 void MonEditHypothesis::InitAdaptChamps()
232 // -------------------------------------
233 // Affichage des informations pour une adaptation selon un champ :
239 MESSAGE ("Debut de InitAdaptChamps");
240 // Choix des options generales
241 GBUniform->setVisible(0);
242 GBAreaManagement->setVisible(0);
243 GBFieldManagement->setVisible(1);
245 RBChamp->setChecked(true);
246 RBUniforme->setEnabled(false);
247 RBChamp->setEnabled(false);
248 RBZone->setEnabled(false);
250 HOMARD::InfosHypo_var aInfosHypo = aHypothesis->GetField();
251 _aFieldName = aInfosHypo->FieldName;
252 _TypeThR = aInfosHypo->TypeThR;
253 _ThreshR = aInfosHypo->ThreshR;
254 _TypeThC = aInfosHypo->TypeThC;
255 _ThreshC = aInfosHypo->ThreshC;
256 _UsField = aInfosHypo->UsField;
257 _UsCmpI = aInfosHypo->UsCmpI;
259 CBFieldName->insertItem(0,_aFieldName);
260 CBFieldName->setCurrentIndex(0);
261 CBFieldName->setEnabled(false);
262 //SetFieldName(Qt::Unchecked);
264 HOMARD::listeComposantsHypo_var mesComposantsAvant = aHypothesis->GetComps();
266 TWCMP->setRowCount(0);
267 TWCMP->resizeRowsToContents();
268 for (int i=0; i<mesComposantsAvant->length(); i++)
271 TWCMP->setItem( 0, 0, new QTableWidgetItem( QString ("") ) );
272 TWCMP->item( 0, 0 )->setFlags( Qt::ItemIsUserCheckable|Qt::ItemIsEnabled);
273 TWCMP->item( 0, 0 )->setCheckState(Qt::Checked );
274 TWCMP->item( 0, 0 )->setFlags( 0 );
275 TWCMP->setItem( 0, 1, new QTableWidgetItem(QString(mesComposantsAvant[i]).trimmed()));
276 TWCMP->item( 0, 1 )->setFlags( Qt::ItemIsEnabled |Qt::ItemIsSelectable );
278 TWCMP->resizeColumnsToContents();
279 TWCMP->resizeRowsToContents();
280 TWCMP->clearSelection();
282 // Les seuils de raffinement
283 RBRAbs->setEnabled(false) ;
284 RBRRel->setEnabled(false) ;
285 RBRPE->setEnabled(false) ;
286 RBRMuSigma->setEnabled(false) ;
287 RBRNo->setEnabled(false) ;
291 RBRNo->setEnabled(true) ;
295 if ( _TypeThR == 1 ) { SpinBox_RAbs->setValue(_ThreshR); SetRAbs(); RBRAbs->setEnabled(true);}
296 if ( _TypeThR == 2 ) { SpinBox_RRel->setValue(_ThreshR); SetRRel(); RBRRel->setEnabled(true);}
297 if ( _TypeThR == 3 ) { SpinBox_RPE->setValue(_ThreshR); SetRPE(); RBRPE->setEnabled(true);}
298 if ( _TypeThR == 4 ) { SpinBox_RMuSigma->setValue(_ThreshR); SetRMS(); RBRMuSigma->setEnabled(true);}
301 // Les seuils de deraffinement
302 RBCAbs->setEnabled(false) ;
303 RBCRel->setEnabled(false) ;
304 RBCPE->setEnabled(false) ;
305 RBCMuSigma->setEnabled(false) ;
306 RBCNo->setEnabled(false) ;
310 RBCNo->setEnabled(true) ;
314 if ( _TypeThC == 1 ) { SpinBox_CAbs->setValue(_ThreshC); SetCAbs(); RBCAbs->setEnabled(true);}
315 if ( _TypeThC == 2 ) { SpinBox_CRel->setValue(_ThreshC); SetCRel(); RBCRel->setEnabled(true);}
316 if ( _TypeThC == 3 ) { SpinBox_CPE->setValue(_ThreshC); SetCPE(); RBCPE->setEnabled(true);}
317 if ( _TypeThC == 4 ) { SpinBox_CMuSigma->setValue(_ThreshC); SetCMS(); RBCMuSigma->setEnabled(true);}
319 // Le choix de la prise en compte des composantes
320 if ( TWCMP->rowCount() == 1 )
321 { RBL2->setText(QObject::tr("HOM_HYPO_NORM_ABS"));
322 RBInf->setText(QObject::tr("HOM_HYPO_NORM_REL"));
325 { RBL2->setText(QObject::tr("HOM_HYPO_NORM_L2"));
326 RBInf->setText(QObject::tr("HOM_HYPO_NORM_INF"));
328 if ( _UsField == 0 ) { CBJump->hide(); }
331 CBJump->setChecked(true);
332 CBJump->setEnabled(false);
336 RBL2->setChecked(true);
337 RBL2->setEnabled(true);
338 RBInf->setEnabled(false) ;
342 RBL2->setEnabled(false) ;
343 RBInf->setChecked(true);
344 RBInf->setEnabled(true);
347 // -------------------------------------
348 void MonEditHypothesis::InitFieldInterp()
349 // -------------------------------------
350 // Affichage des informations pour les interpolations
352 MESSAGE ("Debut de InitFieldInterp");
353 // Choix des options generales
354 _TypeFieldInterp = aHypothesis->GetTypeFieldInterp();
355 MESSAGE ("_TypeFieldInterp = " << _TypeFieldInterp);
357 // Aucune interpolation
358 if ( _TypeFieldInterp == 0 )
360 RBFieldNo->setChecked(true);
361 TWField->setVisible(0);
363 // Interpolation de tous les champs
364 if ( _TypeFieldInterp == 1 )
366 RBFieldAll->setChecked(true);
367 TWField->setVisible(0);
369 // Interpolation de champs choisis
370 if ( _TypeFieldInterp == 2 )
372 RBFieldChosen->setChecked(true);
374 TWField->setVisible(1);
375 HOMARD::listeFieldInterpsHypo_var mesChampsAvant = aHypothesis->GetFieldInterps();
377 TWField->setRowCount(0);
378 TWField->resizeRowsToContents();
379 for (int iaux=0; iaux<mesChampsAvant->length(); iaux++)
381 TWField->insertRow(0);
382 TWField->setItem( 0, 0, new QTableWidgetItem( QString ("") ) );
383 TWField->item( 0, 0 )->setFlags( Qt::ItemIsUserCheckable|Qt::ItemIsEnabled);
384 TWField->item( 0, 0 )->setCheckState(Qt::Checked );
385 TWField->item( 0, 0 )->setFlags( 0 );
386 TWField->setItem( 0, 1, new QTableWidgetItem(QString(mesChampsAvant[iaux]).trimmed()));
387 TWField->item( 0, 1 )->setFlags( Qt::ItemIsEnabled |Qt::ItemIsSelectable );
390 TWField->resizeColumnsToContents();
391 TWField->resizeRowsToContents();
392 TWField->clearSelection();
394 RBFieldNo->setEnabled(false) ;
395 RBFieldAll->setEnabled(false) ;
396 RBFieldChosen->setEnabled(false) ;
399 // -------------------------------------
400 bool MonEditHypothesis::PushOnApply()
401 // -------------------------------------
403 // Pour du raffinement selon un champ, les seuils ont-ils change ?
404 if ( _aTypeAdap == 1 )
408 if (_TypeThR == 1) { _ThreshR = SpinBox_RAbs->value(); }
409 if (_TypeThR == 2) { _ThreshR = SpinBox_RRel->value(); }
410 if (_TypeThR == 3) { _ThreshR = SpinBox_RPE->value(); }
411 if (_TypeThR == 4) { _ThreshR = SpinBox_RMuSigma->value(); }
412 aHypothesis->SetRefinThr(_TypeThR, _ThreshR) ;
416 if (_TypeThC == 1) { _ThreshC = SpinBox_CAbs->value() ; }
417 if (_TypeThC == 2) { _ThreshC = SpinBox_CRel->value() ; }
418 if (_TypeThC == 3) { _ThreshC = SpinBox_CPE->value() ; }
419 if (_TypeThC == 4) { _ThreshC = SpinBox_CMuSigma->value() ; }
420 aHypothesis->SetUnRefThr(_TypeThC, _ThreshC) ;
423 myHomardGen->InvalideHypo(_Name.toStdString().c_str());
424 HOMARD_UTILS::updateObjBrowser();
428 // ------------------------------------------------------------------------
429 void MonEditHypothesis::SetFiltrage()
430 // ------------------------------------------------------------------------
432 if (CBGroupe->isChecked())
434 MonEditListGroup *aDlg = new MonEditListGroup(this, NULL, TRUE, HOMARD::HOMARD_Gen::_duplicate(myHomardGen),_aCaseName, _aListeGroupes) ;