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 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);
251 HOMARD::InfosHypo_var aInfosHypo = _aHypothesis->GetField();
252 _aFieldName = aInfosHypo->FieldName;
253 _TypeThR = aInfosHypo->TypeThR;
254 _ThreshR = aInfosHypo->ThreshR;
255 _TypeThC = aInfosHypo->TypeThC;
256 _ThreshC = aInfosHypo->ThreshC;
257 _UsField = aInfosHypo->UsField;
258 _UsCmpI = aInfosHypo->UsCmpI;
261 CBFieldName->insertItem(0,_aFieldName);
262 CBFieldName->setCurrentIndex(0);
263 CBFieldName->setEnabled(false);
264 //SetFieldName(Qt::Unchecked);
266 HOMARD::listeComposantsHypo_var mesComposantsAvant = _aHypothesis->GetListComp();
268 TWCMP->setRowCount(0);
269 TWCMP->resizeRowsToContents();
270 for (int i=0; i<mesComposantsAvant->length(); i++)
273 TWCMP->setItem( 0, 0, new QTableWidgetItem( QString ("") ) );
274 TWCMP->item( 0, 0 )->setFlags( Qt::ItemIsUserCheckable|Qt::ItemIsEnabled);
275 TWCMP->item( 0, 0 )->setCheckState(Qt::Checked );
276 TWCMP->item( 0, 0 )->setFlags( 0 );
277 TWCMP->setItem( 0, 1, new QTableWidgetItem(QString(mesComposantsAvant[i]).trimmed()));
278 TWCMP->item( 0, 1 )->setFlags( Qt::ItemIsEnabled |Qt::ItemIsSelectable );
280 TWCMP->resizeColumnsToContents();
281 TWCMP->resizeRowsToContents();
282 TWCMP->clearSelection();
284 // Les seuils de raffinement
285 RBRAbs->setEnabled(false) ;
286 RBRRel->setEnabled(false) ;
287 RBRPE->setEnabled(false) ;
288 RBRNo->setEnabled(false) ;
292 RBRNo->setEnabled(true) ;
296 if ( _TypeThR == 1 ) { SpinBox_RAbs->setValue(_ThreshR); SetRAbs(); RBRAbs->setEnabled(true);}
297 if ( _TypeThR == 2 ) { SpinBox_RRel->setValue(_ThreshR); SetRRel(); RBRRel->setEnabled(true);}
298 if ( _TypeThR == 3 ) { SpinBox_RPE->setValue(_ThreshR); SetRPE(); RBRPE->setEnabled(true);}
301 // Les seuils de deraffinement
302 RBCAbs->setEnabled(false) ;
303 RBCRel->setEnabled(false) ;
304 RBCPE->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);}
317 // Le choix de la prise en compte des composantes
318 if ( TWCMP->rowCount() == 1 )
319 { RBL2->setText(QObject::tr("HOM_HYPO_NORM_ABS"));
320 RBInf->setText(QObject::tr("HOM_HYPO_NORM_REL"));
323 { RBL2->setText(QObject::tr("HOM_HYPO_NORM_L2"));
324 RBInf->setText(QObject::tr("HOM_HYPO_NORM_INF"));
326 if ( _UsField == 0 ) { CBJump->hide(); }
329 CBJump->setChecked(true);
330 CBJump->setEnabled(false);
334 RBL2->setChecked(true);
335 RBL2->setEnabled(true);
336 RBInf->setEnabled(false) ;
340 RBL2->setEnabled(false) ;
341 RBInf->setChecked(true);
342 RBInf->setEnabled(true);
345 // -------------------------------------
346 void MonEditHypothesis::InitFieldInterp()
347 // -------------------------------------
348 // Affichage des informations pour les interpolations
350 MESSAGE ("Debut de InitFieldInterp");
351 // Choix des options generales
352 _TypeFieldInterp = _aHypothesis->GetTypeFieldInterp();
353 MESSAGE ("_TypeFieldInterp = " << _TypeFieldInterp);
355 // Aucune interpolation
356 if ( _TypeFieldInterp == 0 )
358 RBFieldNo->setChecked(true);
359 TWField->setVisible(0);
361 // Interpolation de tous les champs
362 if ( _TypeFieldInterp == 1 )
364 RBFieldAll->setChecked(true);
365 TWField->setVisible(0);
367 // Interpolation de champs choisis
368 if ( _TypeFieldInterp == 2 )
370 RBFieldChosen->setChecked(true);
372 TWField->setVisible(1);
373 HOMARD::listFieldInterpHypo_var mesChampsAvant = _aHypothesis->GetListFieldInterp();
375 TWField->setRowCount(0);
376 TWField->resizeRowsToContents();
377 for (int i=0; i<mesChampsAvant->length(); i++)
379 TWField->insertRow(0);
380 TWField->setItem( 0, 0, new QTableWidgetItem( QString ("") ) );
381 TWField->item( 0, 0 )->setFlags( Qt::ItemIsUserCheckable|Qt::ItemIsEnabled);
382 TWField->item( 0, 0 )->setCheckState(Qt::Checked );
383 TWField->item( 0, 0 )->setFlags( 0 );
384 TWField->setItem( 0, 1, new QTableWidgetItem(QString(mesChampsAvant[i]).trimmed()));
385 TWField->item( 0, 1 )->setFlags( Qt::ItemIsEnabled |Qt::ItemIsSelectable );
387 TWField->resizeColumnsToContents();
388 TWField->resizeRowsToContents();
389 TWField->clearSelection();
391 RBFieldNo->setEnabled(false) ;
392 RBFieldAll->setEnabled(false) ;
393 RBFieldChosen->setEnabled(false) ;
396 // -------------------------------------
397 bool MonEditHypothesis::PushOnApply()
398 // -------------------------------------
400 // Pour du raffinement selon un champ, les seuils ont-ils change ?
401 if ( _aTypeAdap == 1 )
405 if (_TypeThR == 1) { _ThreshR = SpinBox_RAbs->value(); }
406 if (_TypeThR == 2) { _ThreshR = SpinBox_RRel->value(); }
407 if (_TypeThR == 3) { _ThreshR = SpinBox_RPE->value(); }
408 _aHypothesis->SetRefinThr(_TypeThR, _ThreshR) ;
412 if (_TypeThC == 1) { _ThreshC = SpinBox_CAbs->value() ; }
413 if (_TypeThC == 2) { _ThreshC = SpinBox_CRel->value() ; }
414 if (_TypeThC == 3) { _ThreshC = SpinBox_CPE->value() ; }
415 _aHypothesis->SetUnRefThr(_TypeThC, _ThreshC) ;
418 _myHomardGen->InvalideHypo(_aHypothesisName.toStdString().c_str());
419 HOMARD_UTILS::updateObjBrowser();
423 // ------------------------------------------------------------------------
424 void MonEditHypothesis::SetFiltrage()
425 // ------------------------------------------------------------------------
427 if (CBGroupe->isChecked())
429 MonEditListGroup *aDlg = new MonEditListGroup(this, NULL, TRUE, HOMARD::HOMARD_Gen::_duplicate(_myHomardGen),_aCaseName, _aListeGroupes) ;