1 // Copyright (C) 2011-2015 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, or (at your option) any later version.
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
20 #include "MonEditHypothesis.h"
21 #include "MonEditListGroup.h"
23 #include "SalomeApp_Tools.h"
24 #include "HOMARDGUI_Utils.h"
25 #include "HomardQtCommun.h"
27 #include <utilities.h>
31 // ----------------------------------------------------------------------------
32 MonEditHypothesis::MonEditHypothesis( MonCreateIteration* parent, bool modal,
33 HOMARD::HOMARD_Gen_var myHomardGen,
35 QString caseName, QString aFieldFile ):
36 // ----------------------------------------------------------------------------
37 /* Constructs a MonEditHypothesis
38 herite de MonCreateHypothesis
40 MonCreateHypothesis(parent, modal,myHomardGen, Name, caseName, aFieldFile)
42 MESSAGE("Hypothese " << Name.toStdString().c_str());
43 setWindowTitle(QObject::tr("HOM_HYPO_EDIT_WINDOW_TITLE"));
44 aHypothesis = myHomardGen->GetHypothesis(_Name.toStdString().c_str());
45 if (caseName == QString("") ){ _aCaseName = aHypothesis->GetCaseCreation();}
49 // ------------------------------
50 MonEditHypothesis::~MonEditHypothesis()
51 // ------------------------------
54 // ------------------------------
55 void MonEditHypothesis::InitGroupes()
56 // ------------------------------
58 HOMARD::ListGroupType_var maListe = aHypothesis->GetGroups();
59 for ( int i = 0; i < maListe->length(); i++ )
60 _aListeGroupes << QString(maListe[i]);
62 if (maListe->length() == 0) { CBGroupe->hide();}
65 // ------------------------------
66 void MonEditHypothesis::InitValEdit()
67 // ------------------------------
69 MESSAGE("Debut de InitValEdit");
70 LEName->setText(_Name);
71 LEName->setReadOnly(true);
72 HOMARD::listeTypes_var ListTypes (aHypothesis->GetAdapRefinUnRef());
73 ASSERT( ListTypes->length()==3) ;
74 _aTypeAdap = ListTypes[0];
75 _aTypeRaff = ListTypes[1];
76 _aTypeDera = ListTypes[2];
78 if (_aTypeAdap == -1) InitAdaptUniforme();
79 if (_aTypeAdap == 0) InitAdaptZone();
80 if (_aTypeAdap == 1) InitAdaptChamps();
82 RBUniDera->setDisabled(true);
83 RBUniRaff->setDisabled(true);
87 if (_aTypeAdap == 1 || _TypeFieldInterp >= 1 )
89 if (_aFieldFile == QString("")) { GBFieldFile->setVisible(0); }
92 GBFieldFile->setVisible(1);
93 LEFieldFile->setText(_aFieldFile);
94 LEFieldFile->setReadOnly(1);
99 GBFieldFile->setVisible(0);
101 // Les options avancees (non modifiables)
102 CBAdvanced->setVisible(0) ;
103 int NivMax = aHypothesis->GetNivMax();
104 double DiamMin = aHypothesis->GetDiamMin();
105 int AdapInit = aHypothesis->GetAdapInit();
106 int ExtraOutput = aHypothesis->GetExtraOutput();
107 if ( NivMax > 0 || DiamMin > 0 || AdapInit != 0 || ExtraOutput != 1 )
108 { GBAdvancedOptions->setVisible(1);
110 { SpinBoxNivMax->setValue(NivMax);
111 SpinBoxNivMax->setDisabled(true); }
113 { TLMaximalLevel->setVisible(0);
114 SpinBoxNivMax->setVisible(0); }
116 { doubleSpinBoxDiamMin->setValue(DiamMin);
117 doubleSpinBoxDiamMin->setDisabled(true); }
119 { TLMinimalDiameter->setVisible(0);
120 doubleSpinBoxDiamMin->setVisible(0); }
124 { RBAIR->setChecked(true); }
126 { RBAID->setChecked(true); }
127 RBAIN->setEnabled(false);
128 RBAIR->setEnabled(false);
129 RBAID->setEnabled(false);
132 { GBAdapInit->setVisible(0) ;
134 if ( ExtraOutput % 2 == 0 )
136 CBOutputLevel->setChecked(true);
137 CBOutputLevel->setEnabled(false);
139 else { CBOutputLevel->setVisible(0) ; }
140 if ( ExtraOutput % 3 == 0 )
142 CBOutputQuality->setChecked(true);
143 CBOutputQuality->setEnabled(false);
145 else { CBOutputQuality->setVisible(0) ; }
146 if ( ExtraOutput % 5 == 0 )
148 CBOutputDiameter->setChecked(true);
149 CBOutputDiameter->setEnabled(false);
151 else { CBOutputDiameter->setVisible(0) ; }
152 /* if ( ExtraOutput % 7 == 0 )
154 CBOutputParent->setChecked(true);
155 CBOutputParent->setEnabled(false);
157 else { CBOutputParent->setVisible(0) ; }*/
160 { GBAdvancedOptions->setVisible(0); }
163 // ----------------------------------------
164 void MonEditHypothesis::InitAdaptUniforme()
165 // ----------------------------------------
166 // Affichage des informations pour une adaptation uniforme
168 // Choix des options generales
169 GBFieldManagement->setVisible(0);
170 GBAreaManagement->setVisible(0);
171 GBUniform->setVisible(1);
172 RBUniforme->setChecked(true);
173 RBUniforme->setEnabled(false);
174 RBChamp->setEnabled(false);
175 RBZone->setEnabled(false);
177 // Raffinement ou deraffinement ?
180 VERIFICATION(_aTypeRaff==1);
181 RBUniDera->setChecked(false);
182 RBUniRaff->setChecked(true);
186 VERIFICATION(_aTypeRaff==0);
187 RBUniDera->setChecked(true);
188 RBUniRaff->setChecked(false);
194 // -------------------------------------
195 void MonEditHypothesis::InitAdaptZone()
196 // -------------------------------------
197 // Affichage des informations pour une adaptation selon des zones :
199 MESSAGE ("Debut de InitAdaptZone");
200 // Choix des options generales
201 GBUniform->setVisible(0);
202 GBFieldManagement->setVisible(0);
203 GBAreaManagement->setVisible(1);
204 RBZone->setChecked(true);
205 RBChamp->setEnabled(false);
206 RBUniforme->setEnabled(false);
207 RBZone->setEnabled(false);
209 // Recuperation de toutes les zones decrites et notation de celles retenues
211 HOMARD::listeZonesHypo_var mesZonesAvant = aHypothesis->GetZones();
212 for (int i=0; i<mesZonesAvant->length(); i++)
214 MESSAGE ("i"<<i<<", zone :"<<string(mesZonesAvant[i])<<", type :"<<string(mesZonesAvant[i+1]));
215 for ( int j =0 ; j < TWZone->rowCount(); j++)
217 MESSAGE (". j"<<j<<", zone :"<<TWZone->item(j,2)->text().toStdString());
218 if ( TWZone->item(j,2)->text().toStdString() == string(mesZonesAvant[i]) )
220 MESSAGE ("OK avec "<<string(mesZonesAvant[i]));
221 if ( string(mesZonesAvant[i+1]) == "1" )
223 MESSAGE ("... RAFF");
224 TWZone->item( j,0 )->setCheckState( Qt::Checked );
225 TWZone->item( j,1 )->setCheckState( Qt::Unchecked ); }
228 MESSAGE ("... DERA");
229 TWZone->item( j,0 )->setCheckState( Qt::Unchecked );
230 TWZone->item( j,1 )->setCheckState( Qt::Checked ); }
237 // Inactivation des choix
238 for ( int j =0 ; j < TWZone->rowCount(); j++)
240 TWZone->item( j, 0 )->setFlags(0);
241 TWZone->item( j, 1 )->setFlags(0);
243 PBZoneNew->setVisible(0);
248 // -------------------------------------
249 void MonEditHypothesis::InitAdaptChamps()
250 // -------------------------------------
251 // Affichage des informations pour une adaptation selon un champ :
257 MESSAGE ("Debut de InitAdaptChamps");
258 // Choix des options generales
259 GBUniform->setVisible(0);
260 GBAreaManagement->setVisible(0);
261 GBFieldManagement->setVisible(1);
262 RBChamp->setChecked(true);
263 RBUniforme->setEnabled(false);
264 RBChamp->setEnabled(false);
265 RBZone->setEnabled(false);
267 HOMARD::InfosHypo_var aInfosHypo = aHypothesis->GetField();
268 _aFieldName = aInfosHypo->FieldName;
269 _TypeThR = aInfosHypo->TypeThR;
270 _ThreshR = aInfosHypo->ThreshR;
271 _TypeThC = aInfosHypo->TypeThC;
272 _ThreshC = aInfosHypo->ThreshC;
273 _UsField = aInfosHypo->UsField;
274 _UsCmpI = aInfosHypo->UsCmpI;
276 CBFieldName->insertItem(0,_aFieldName);
277 CBFieldName->setCurrentIndex(0);
278 CBFieldName->setEnabled(false);
279 //SetFieldName(Qt::Unchecked);
281 HOMARD::listeComposantsHypo_var mesComposantsAvant = aHypothesis->GetComps();
283 TWCMP->setRowCount(0);
284 TWCMP->resizeRowsToContents();
285 for (int i=0; i<mesComposantsAvant->length(); i++)
288 TWCMP->setItem( 0, 0, new QTableWidgetItem( QString ("") ) );
289 TWCMP->item( 0, 0 )->setFlags( Qt::ItemIsUserCheckable|Qt::ItemIsEnabled);
290 TWCMP->item( 0, 0 )->setCheckState(Qt::Checked );
291 TWCMP->item( 0, 0 )->setFlags( 0 );
292 TWCMP->setItem( 0, 1, new QTableWidgetItem(QString(mesComposantsAvant[i]).trimmed()));
293 TWCMP->item( 0, 1 )->setFlags( Qt::ItemIsEnabled |Qt::ItemIsSelectable );
295 TWCMP->resizeColumnsToContents();
296 TWCMP->resizeRowsToContents();
297 TWCMP->clearSelection();
299 // Les seuils de raffinement
300 RBRAbs->setEnabled(false) ;
301 RBRRel->setEnabled(false) ;
302 RBRPE->setEnabled(false) ;
303 RBRMuSigma->setEnabled(false) ;
304 RBRNo->setEnabled(false) ;
308 RBRNo->setEnabled(true) ;
312 if ( _TypeThR == 1 ) { SpinBox_RAbs->setValue(_ThreshR); SetRAbs(); RBRAbs->setEnabled(true);}
313 if ( _TypeThR == 2 ) { SpinBox_RRel->setValue(_ThreshR); SetRRel(); RBRRel->setEnabled(true);}
314 if ( _TypeThR == 3 ) { SpinBox_RPE->setValue(_ThreshR); SetRPE(); RBRPE->setEnabled(true);}
315 if ( _TypeThR == 4 ) { SpinBox_RMuSigma->setValue(_ThreshR); SetRMS(); RBRMuSigma->setEnabled(true);}
318 // Les seuils de deraffinement
319 RBCAbs->setEnabled(false) ;
320 RBCRel->setEnabled(false) ;
321 RBCPE->setEnabled(false) ;
322 RBCMuSigma->setEnabled(false) ;
323 RBCNo->setEnabled(false) ;
327 RBCNo->setEnabled(true) ;
331 if ( _TypeThC == 1 ) { SpinBox_CAbs->setValue(_ThreshC); SetCAbs(); RBCAbs->setEnabled(true);}
332 if ( _TypeThC == 2 ) { SpinBox_CRel->setValue(_ThreshC); SetCRel(); RBCRel->setEnabled(true);}
333 if ( _TypeThC == 3 ) { SpinBox_CPE->setValue(_ThreshC); SetCPE(); RBCPE->setEnabled(true);}
334 if ( _TypeThC == 4 ) { SpinBox_CMuSigma->setValue(_ThreshC); SetCMS(); RBCMuSigma->setEnabled(true);}
336 // Le choix de la prise en compte des composantes
337 if ( TWCMP->rowCount() == 1 )
338 { RBL2->setText(QObject::tr("HOM_HYPO_NORM_ABS"));
339 RBInf->setText(QObject::tr("HOM_HYPO_NORM_REL"));
342 { RBL2->setText(QObject::tr("HOM_HYPO_NORM_L2"));
343 RBInf->setText(QObject::tr("HOM_HYPO_NORM_INF"));
345 if ( _UsField == 0 ) { CBJump->hide(); }
348 CBJump->setChecked(true);
349 CBJump->setEnabled(false);
353 RBL2->setChecked(true);
354 RBL2->setEnabled(true);
355 RBInf->setEnabled(false) ;
359 RBL2->setEnabled(false) ;
360 RBInf->setChecked(true);
361 RBInf->setEnabled(true);
366 // -------------------------------------
367 void MonEditHypothesis::InitFieldInterp()
368 // -------------------------------------
369 // Affichage des informations pour les interpolations
371 MESSAGE ("Debut de InitFieldInterp");
372 // Choix des options generales
373 _TypeFieldInterp = aHypothesis->GetTypeFieldInterp();
374 MESSAGE ("_TypeFieldInterp = " << _TypeFieldInterp);
376 // Aucune interpolation
377 if ( _TypeFieldInterp == 0 )
379 RBFieldNo->setChecked(true);
380 TWField->setVisible(0);
382 // Interpolation de tous les champs
383 if ( _TypeFieldInterp == 1 )
385 RBFieldAll->setChecked(true);
386 TWField->setVisible(0);
388 // Interpolation de champs choisis
389 if ( _TypeFieldInterp == 2 )
391 RBFieldChosen->setChecked(true);
393 TWField->setVisible(1);
394 HOMARD::listeFieldInterpsHypo_var mesChampsAvant = aHypothesis->GetFieldInterps();
396 TWField->setRowCount(0);
397 TWField->resizeRowsToContents();
398 for (int iaux=0; iaux<mesChampsAvant->length(); iaux++)
400 TWField->insertRow(0);
401 TWField->setItem( 0, 0, new QTableWidgetItem( QString ("") ) );
402 TWField->item( 0, 0 )->setFlags( Qt::ItemIsUserCheckable|Qt::ItemIsEnabled);
403 TWField->item( 0, 0 )->setCheckState(Qt::Checked );
404 TWField->item( 0, 0 )->setFlags( 0 );
405 TWField->setItem( 0, 1, new QTableWidgetItem(QString(mesChampsAvant[iaux]).trimmed()));
406 TWField->item( 0, 1 )->setFlags( Qt::ItemIsEnabled |Qt::ItemIsSelectable );
409 TWField->resizeColumnsToContents();
410 TWField->resizeRowsToContents();
411 TWField->clearSelection();
413 RBFieldNo->setEnabled(false) ;
414 RBFieldAll->setEnabled(false) ;
415 RBFieldChosen->setEnabled(false) ;
418 // -------------------------------------
419 bool MonEditHypothesis::PushOnApply()
420 // -------------------------------------
422 // Pour du raffinement selon un champ, les seuils ont-ils change ?
423 if ( _aTypeAdap == 1 )
427 if (_TypeThR == 1) { _ThreshR = SpinBox_RAbs->value(); }
428 if (_TypeThR == 2) { _ThreshR = SpinBox_RRel->value(); }
429 if (_TypeThR == 3) { _ThreshR = SpinBox_RPE->value(); }
430 if (_TypeThR == 4) { _ThreshR = SpinBox_RMuSigma->value(); }
431 aHypothesis->SetRefinThr(_TypeThR, _ThreshR) ;
435 if (_TypeThC == 1) { _ThreshC = SpinBox_CAbs->value() ; }
436 if (_TypeThC == 2) { _ThreshC = SpinBox_CRel->value() ; }
437 if (_TypeThC == 3) { _ThreshC = SpinBox_CPE->value() ; }
438 if (_TypeThC == 4) { _ThreshC = SpinBox_CMuSigma->value() ; }
439 aHypothesis->SetUnRefThr(_TypeThC, _ThreshC) ;
442 myHomardGen->InvalideHypo(_Name.toStdString().c_str());
443 HOMARD_UTILS::updateObjBrowser();
447 // ------------------------------------------------------------------------
448 void MonEditHypothesis::SetFiltrage()
449 // ------------------------------------------------------------------------
451 if (CBGroupe->isChecked())
453 MonEditListGroup *aDlg = new MonEditListGroup(this, NULL, true, HOMARD::HOMARD_Gen::_duplicate(myHomardGen),_aCaseName, _aListeGroupes) ;