1 // Copyright (C) 2011-2020 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 ADAPT::ADAPT_Gen_var myAdaptGen,
35 QString caseName, QString aFieldFile ):
36 // ----------------------------------------------------------------------------
37 /* Constructs a MonEditHypothesis
38 herite de MonCreateHypothesis
40 MonCreateHypothesis(parent, modal,myAdaptGen, Name, caseName, aFieldFile)
42 MESSAGE("Hypothese " << Name.toStdString().c_str());
43 setWindowTitle(QObject::tr("HOM_HYPO_EDIT_WINDOW_TITLE"));
44 aHypothesis = myAdaptGen->GetHypothesis(_Name.toStdString().c_str());
45 if (caseName == QString("") ){ _aCaseName = aHypothesis->GetCaseCreation();}
49 // ------------------------------
50 MonEditHypothesis::~MonEditHypothesis()
51 // ------------------------------
54 // ------------------------------
55 void MonEditHypothesis::InitGroupes()
56 // ------------------------------
58 ADAPT::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 ADAPT::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) ; }
158 if ( ExtraOutput % 11 == 0 )
160 CBOutputVoisins->setChecked(true);
161 CBOutputVoisins->setEnabled(false);
163 else { CBOutputVoisins->setVisible(0) ; }
166 { GBAdvancedOptions->setVisible(0); }
169 // ----------------------------------------
170 void MonEditHypothesis::InitAdaptUniforme()
171 // ----------------------------------------
172 // Affichage des informations pour une adaptation uniforme
174 // Choix des options generales
175 GBFieldManagement->setVisible(0);
176 GBAreaManagement->setVisible(0);
177 GBUniform->setVisible(1);
178 RBUniforme->setChecked(true);
179 RBUniforme->setEnabled(false);
180 RBChamp->setEnabled(false);
181 RBZone->setEnabled(false);
183 // Raffinement ou deraffinement ?
186 VERIFICATION(_aTypeRaff==1);
187 RBUniDera->setChecked(false);
188 RBUniRaff->setChecked(true);
192 VERIFICATION(_aTypeRaff==0);
193 RBUniDera->setChecked(true);
194 RBUniRaff->setChecked(false);
200 // -------------------------------------
201 void MonEditHypothesis::InitAdaptZone()
202 // -------------------------------------
203 // Affichage des informations pour une adaptation selon des zones :
205 MESSAGE ("Debut de InitAdaptZone");
206 // Choix des options generales
207 GBUniform->setVisible(0);
208 GBFieldManagement->setVisible(0);
209 GBAreaManagement->setVisible(1);
210 RBZone->setChecked(true);
211 RBChamp->setEnabled(false);
212 RBUniforme->setEnabled(false);
213 RBZone->setEnabled(false);
215 // Recuperation de toutes les zones decrites et notation de celles retenues
217 ADAPT::listeZonesHypo_var mesZonesAvant = aHypothesis->GetZones();
218 for (int i=0; i<mesZonesAvant->length(); i++)
220 MESSAGE ("i"<<i<<", zone :"<<string(mesZonesAvant[i])<<", type :"<<string(mesZonesAvant[i+1]));
221 for ( int j =0 ; j < TWZone->rowCount(); j++)
223 MESSAGE (". j"<<j<<", zone :"<<TWZone->item(j,2)->text().toStdString());
224 if ( TWZone->item(j,2)->text().toStdString() == string(mesZonesAvant[i]) )
226 MESSAGE ("OK avec "<<string(mesZonesAvant[i]));
227 if ( string(mesZonesAvant[i+1]) == "1" )
229 MESSAGE ("... RAFF");
230 TWZone->item( j,0 )->setCheckState( Qt::Checked );
231 TWZone->item( j,1 )->setCheckState( Qt::Unchecked ); }
234 MESSAGE ("... DERA");
235 TWZone->item( j,0 )->setCheckState( Qt::Unchecked );
236 TWZone->item( j,1 )->setCheckState( Qt::Checked ); }
243 // Inactivation des choix
244 for ( int j =0 ; j < TWZone->rowCount(); j++)
246 TWZone->item( j, 0 )->setFlags(0);
247 TWZone->item( j, 1 )->setFlags(0);
249 PBZoneNew->setVisible(0);
254 // -------------------------------------
255 void MonEditHypothesis::InitAdaptChamps()
256 // -------------------------------------
257 // Affichage des informations pour une adaptation selon un champ :
263 MESSAGE ("Debut de InitAdaptChamps");
264 // Choix des options generales
265 GBUniform->setVisible(0);
266 GBAreaManagement->setVisible(0);
267 GBFieldManagement->setVisible(1);
268 RBChamp->setChecked(true);
269 RBUniforme->setEnabled(false);
270 RBChamp->setEnabled(false);
271 RBZone->setEnabled(false);
273 ADAPT::InfosHypo_var aInfosHypo = aHypothesis->GetField();
274 _aFieldName = aInfosHypo->FieldName;
275 _TypeThR = aInfosHypo->TypeThR;
276 _ThreshR = aInfosHypo->ThreshR;
277 _TypeThC = aInfosHypo->TypeThC;
278 _ThreshC = aInfosHypo->ThreshC;
279 _UsField = aInfosHypo->UsField;
280 _UsCmpI = aInfosHypo->UsCmpI;
282 CBFieldName->insertItem(0,_aFieldName);
283 CBFieldName->setCurrentIndex(0);
284 CBFieldName->setEnabled(false);
285 //SetFieldName(Qt::Unchecked);
287 ADAPT::listeComposantsHypo_var mesComposantsAvant = aHypothesis->GetComps();
289 TWCMP->setRowCount(0);
290 TWCMP->resizeRowsToContents();
291 for (int i=0; i<mesComposantsAvant->length(); i++)
294 TWCMP->setItem( 0, 0, new QTableWidgetItem( QString ("") ) );
295 TWCMP->item( 0, 0 )->setFlags( Qt::ItemIsUserCheckable|Qt::ItemIsEnabled);
296 TWCMP->item( 0, 0 )->setCheckState(Qt::Checked );
297 TWCMP->item( 0, 0 )->setFlags( 0 );
298 TWCMP->setItem( 0, 1, new QTableWidgetItem(QString(mesComposantsAvant[i]).trimmed()));
299 TWCMP->item( 0, 1 )->setFlags( Qt::ItemIsEnabled |Qt::ItemIsSelectable );
301 TWCMP->resizeColumnsToContents();
302 TWCMP->resizeRowsToContents();
303 TWCMP->clearSelection();
305 // Les seuils de raffinement
306 RBRAbs->setEnabled(false) ;
307 RBRRel->setEnabled(false) ;
308 RBRPE->setEnabled(false) ;
309 RBRMuSigma->setEnabled(false) ;
310 RBRNo->setEnabled(false) ;
314 RBRNo->setEnabled(true) ;
318 if ( _TypeThR == 1 ) { SpinBox_RAbs->setValue(_ThreshR); SetRAbs(); RBRAbs->setEnabled(true);}
319 if ( _TypeThR == 2 ) { SpinBox_RRel->setValue(_ThreshR); SetRRel(); RBRRel->setEnabled(true);}
320 if ( _TypeThR == 3 ) { SpinBox_RPE->setValue(_ThreshR); SetRPE(); RBRPE->setEnabled(true);}
321 if ( _TypeThR == 4 ) { SpinBox_RMuSigma->setValue(_ThreshR); SetRMS(); RBRMuSigma->setEnabled(true);}
324 // Les seuils de deraffinement
325 RBCAbs->setEnabled(false) ;
326 RBCRel->setEnabled(false) ;
327 RBCPE->setEnabled(false) ;
328 RBCMuSigma->setEnabled(false) ;
329 RBCNo->setEnabled(false) ;
333 RBCNo->setEnabled(true) ;
337 if ( _TypeThC == 1 ) { SpinBox_CAbs->setValue(_ThreshC); SetCAbs(); RBCAbs->setEnabled(true);}
338 if ( _TypeThC == 2 ) { SpinBox_CRel->setValue(_ThreshC); SetCRel(); RBCRel->setEnabled(true);}
339 if ( _TypeThC == 3 ) { SpinBox_CPE->setValue(_ThreshC); SetCPE(); RBCPE->setEnabled(true);}
340 if ( _TypeThC == 4 ) { SpinBox_CMuSigma->setValue(_ThreshC); SetCMS(); RBCMuSigma->setEnabled(true);}
342 // Le choix de la prise en compte des composantes
343 if ( TWCMP->rowCount() == 1 )
344 { RBL2->setText(QObject::tr("HOM_HYPO_NORM_ABS"));
345 RBInf->setText(QObject::tr("HOM_HYPO_NORM_REL"));
348 { RBL2->setText(QObject::tr("HOM_HYPO_NORM_L2"));
349 RBInf->setText(QObject::tr("HOM_HYPO_NORM_INF"));
351 if ( _UsField == 0 ) { CBJump->hide(); }
354 CBJump->setChecked(true);
355 CBJump->setEnabled(false);
359 RBL2->setChecked(true);
360 RBL2->setEnabled(true);
361 RBInf->setEnabled(false) ;
365 RBL2->setEnabled(false) ;
366 RBInf->setChecked(true);
367 RBInf->setEnabled(true);
372 // -------------------------------------
373 void MonEditHypothesis::InitFieldInterp()
374 // -------------------------------------
375 // Affichage des informations pour les interpolations
377 MESSAGE ("Debut de InitFieldInterp");
378 // Choix des options generales
379 _TypeFieldInterp = aHypothesis->GetTypeFieldInterp();
380 MESSAGE ("_TypeFieldInterp = " << _TypeFieldInterp);
382 // Aucune interpolation
383 if ( _TypeFieldInterp == 0 )
385 RBFieldNo->setChecked(true);
386 TWField->setVisible(0);
388 // Interpolation de tous les champs
389 if ( _TypeFieldInterp == 1 )
391 RBFieldAll->setChecked(true);
392 TWField->setVisible(0);
394 // Interpolation de champs choisis
395 if ( _TypeFieldInterp == 2 )
397 RBFieldChosen->setChecked(true);
399 TWField->setVisible(1);
400 ADAPT::listeFieldInterpsHypo_var mesChampsAvant = aHypothesis->GetFieldInterps();
402 TWField->setRowCount(0);
403 TWField->resizeRowsToContents();
404 for (int iaux=0; iaux<mesChampsAvant->length(); iaux++)
406 TWField->insertRow(0);
407 TWField->setItem( 0, 0, new QTableWidgetItem( QString ("") ) );
408 TWField->item( 0, 0 )->setFlags( Qt::ItemIsUserCheckable|Qt::ItemIsEnabled);
409 TWField->item( 0, 0 )->setCheckState(Qt::Checked );
410 TWField->item( 0, 0 )->setFlags( 0 );
411 TWField->setItem( 0, 1, new QTableWidgetItem(QString(mesChampsAvant[iaux]).trimmed()));
412 TWField->item( 0, 1 )->setFlags( Qt::ItemIsEnabled |Qt::ItemIsSelectable );
415 TWField->resizeColumnsToContents();
416 TWField->resizeRowsToContents();
417 TWField->clearSelection();
419 RBFieldNo->setEnabled(false) ;
420 RBFieldAll->setEnabled(false) ;
421 RBFieldChosen->setEnabled(false) ;
424 // -------------------------------------
425 bool MonEditHypothesis::PushOnApply()
426 // -------------------------------------
428 // Pour du raffinement selon un champ, les seuils ont-ils change ?
429 if ( _aTypeAdap == 1 )
433 if (_TypeThR == 1) { _ThreshR = SpinBox_RAbs->value(); }
434 if (_TypeThR == 2) { _ThreshR = SpinBox_RRel->value(); }
435 if (_TypeThR == 3) { _ThreshR = SpinBox_RPE->value(); }
436 if (_TypeThR == 4) { _ThreshR = SpinBox_RMuSigma->value(); }
437 aHypothesis->SetRefinThr(_TypeThR, _ThreshR) ;
441 if (_TypeThC == 1) { _ThreshC = SpinBox_CAbs->value() ; }
442 if (_TypeThC == 2) { _ThreshC = SpinBox_CRel->value() ; }
443 if (_TypeThC == 3) { _ThreshC = SpinBox_CPE->value() ; }
444 if (_TypeThC == 4) { _ThreshC = SpinBox_CMuSigma->value() ; }
445 aHypothesis->SetUnRefThr(_TypeThC, _ThreshC) ;
448 myAdaptGen->InvalideHypo(_Name.toStdString().c_str());
449 HOMARD_UTILS::updateObjBrowser();
453 // ------------------------------------------------------------------------
454 void MonEditHypothesis::SetFiltrage()
455 // ------------------------------------------------------------------------
457 if (CBGroupe->isChecked())
459 MonEditListGroup *aDlg = new MonEditListGroup(this, NULL, true, ADAPT::ADAPT_Gen::_duplicate(myAdaptGen),_aCaseName, _aListeGroupes) ;