]> SALOME platform Git repositories - modules/homard.git/blob - src/HOMARDGUI/MonEditHypothesis.cxx
Salome HOME
version 5_1_4 HOMARD_SRC
[modules/homard.git] / src / HOMARDGUI / MonEditHypothesis.cxx
1 using namespace std;
2
3 #include "MonEditHypothesis.h"
4 #include "MonEditListGroup.h"
5
6 #include <QMessageBox>
7
8 #include "SalomeApp_Tools.h"
9 #include "HOMARDGUI_Utils.h"
10 #include "HomardQtCommun.h"
11 #include <utilities.h>
12
13
14 // -------------------------------------------------------------------------------------------------------------------------------------
15 MonEditHypothesis::MonEditHypothesis( MonCreateIteration* parent, bool modal,
16                                       HOMARD::HOMARD_Gen_var myHomardGen,
17                                       QString aHypothesisName,
18                                       QString caseName,  QString aFieldFile ):
19 // -------------------------------------------------------------------------------------------------------------------------------------
20 /* Constructs a MonEditHypothesis
21     herite de MonCreateHypothesis
22 */
23     MonCreateHypothesis(parent, modal,myHomardGen, aHypothesisName, caseName, aFieldFile)
24 {
25     MESSAGE("Hypothese " << aHypothesisName.toStdString().c_str());
26     setWindowTitle("Edit Hypothesis");
27     _aHypothesis    = _myHomardGen->GetHypothesis(_aHypothesisName.toStdString().c_str());
28     if (caseName == QString("") ){ _aCaseName = _aHypothesis->GetCaseCreation();}
29     InitValEdit();
30     InitGroupes();
31 }
32 // ------------------------------
33 MonEditHypothesis::~MonEditHypothesis()
34 // ------------------------------
35 {
36 }
37 // ------------------------------
38 void MonEditHypothesis::InitGroupes()
39 // ------------------------------
40 {
41     HOMARD::ListGroupType_var maListe = _aHypothesis->GetGroups();
42     for ( int i = 0; i < maListe->length(); i++ )
43        _aListeGroupes << QString(maListe[i]);
44
45     if (maListe->length() == 0) { CBGroupe->hide();}
46 }
47
48 // ------------------------------
49 void MonEditHypothesis::InitValEdit()
50 // ------------------------------
51 {
52       MESSAGE("Debut de InitValEdit");
53       LEHypothesisName->setText(_aHypothesisName);
54       LEHypothesisName->setReadOnly(true);
55       HOMARD::listeTypes_var ListTypes (_aHypothesis->GetAdapRefinUnRef());
56       ASSERT( ListTypes->length()==3) ;
57       _aTypeAdap = ListTypes[0];
58       _aTypeRaff = ListTypes[1];
59       _aTypeDera = ListTypes[2];
60
61       if (_aTypeAdap == -1) InitAdaptUniforme();
62       if (_aTypeAdap ==  0) InitAdaptZone();
63       if (_aTypeAdap ==  1) InitAdaptChamps();
64
65       RBUniDera->setDisabled(true);
66       RBUniRaff->setDisabled(true);
67
68       InitFieldInterp();
69
70       if (_aTypeAdap == 1 or _TypeFieldInterp >= 1 )
71       {
72         if (_aFieldFile == QString("")) { GBFieldFile->setVisible(0); }
73         else
74         {
75           GBFieldFile->setVisible(1);
76           LEFieldFile->setText(_aFieldFile);
77           LEFieldFile->setReadOnly(1);
78         }
79       }
80       else
81       {
82         GBFieldFile->setVisible(0);
83       }
84       adjustSize();
85 }
86 // ----------------------------------------
87 void MonEditHypothesis::InitAdaptUniforme()
88 // ----------------------------------------
89 // Affichage des informations pour une adaptation uniforme
90 {
91 //  Choix des options generales
92     GBFieldManagement->setVisible(0);
93     GBAreaManagement->setVisible(0);
94     GBUniform->setVisible(1);
95     adjustSize();
96     RBUniforme->setChecked(true);
97     RBUniforme->setEnabled(false);
98     RBChamp->setEnabled(false);
99     RBZone->setEnabled(false);
100 //
101 // Raffinement ou deraffinement ?
102     if (_aTypeDera == 0)
103     {
104         ASSERT(_aTypeRaff==1);
105         RBUniDera->setChecked(false);
106         RBUniRaff->setChecked(true);
107     }
108     if (_aTypeDera == 1)
109     {
110         ASSERT(_aTypeRaff==0);
111         RBUniDera->setChecked(true);
112         RBUniRaff->setChecked(false);
113     }
114 //
115 }
116 // -------------------------------------
117 void MonEditHypothesis::InitAdaptZone()
118 // -------------------------------------
119 // Affichage des informations pour une adaptation selon des zones :
120 {
121 // . Liste des zones
122
123 //  Choix des options generales
124     GBUniform->setVisible(0);
125     GBFieldManagement->setVisible(0);
126     GBAreaManagement->setVisible(1);
127     adjustSize();
128     RBZone->setChecked(true);
129     RBChamp->setEnabled(false);
130     RBUniforme->setEnabled(false);
131     RBZone->setEnabled(false);
132
133 //  Recuperation de toutes les zones decrites et notation de celles retenues
134     GetAllZones();
135     HOMARD::listeZonesHypo_var mesZonesAvant = _aHypothesis->GetZones();
136     for (int i=0; i<mesZonesAvant->length(); i++)
137     {
138         for ( int j =0 ; j < TWZone->rowCount(); j++)
139         {
140             if (TWZone->item(j,1)->text().toStdString() == string(mesZonesAvant[i]))
141             {
142                TWZone->item( j,0 )->setCheckState( Qt::Checked );
143                break;
144             }
145         }
146     }
147 //
148 //  Inactivation des choix
149     for ( int j =0 ; j < TWZone->rowCount(); j++)
150     {
151         TWZone->item( j, 0 )->setFlags(0);
152     }
153     PBZoneNew->setVisible(0);
154 //
155 }
156
157 // -------------------------------------
158 void MonEditHypothesis::InitAdaptChamps()
159 // -------------------------------------
160 // Affichage des informations pour une adaptation selon un champ :
161 // . Nom du champ
162 // . Composantes
163 // . Seuils
164 // . Absolu/relatif
165 {
166     MESSAGE ("Debut de InitAdaptChamps");
167 //  Choix des options generales
168     GBUniform->setVisible(0);
169     GBAreaManagement->setVisible(0);
170     GBFieldManagement->setVisible(1);
171     adjustSize();
172     RBChamp->setChecked(true);
173     RBUniforme->setEnabled(false);
174     RBChamp->setEnabled(false);
175     RBZone->setEnabled(false);
176
177
178
179     HOMARD::InfosHypo_var  aInfosHypo = _aHypothesis->GetField();
180     _aFieldName =  aInfosHypo->FieldName;
181     _TypeThR = aInfosHypo->TypeThR;
182     _ThreshR = aInfosHypo->ThreshR;
183     _TypeThC = aInfosHypo->TypeThC;
184     _ThreshC = aInfosHypo->ThreshC;
185     _UsCmpI  = aInfosHypo->UsCmpI;
186
187
188     CBFieldName->insertItem(0,_aFieldName);
189     CBFieldName->setCurrentIndex(0);
190     CBFieldName->setEnabled(false);
191     //SetFieldName(Qt::Unchecked);
192
193     HOMARD::listeComposantsHypo_var mesComposantsAvant = _aHypothesis->GetListComp();
194     TWCMP->clear();
195     TWCMP->setRowCount(0);
196     TWCMP->resizeRowsToContents();
197     for (int i=0; i<mesComposantsAvant->length(); i++)
198     {
199        TWCMP->insertRow(0);
200        TWCMP->setItem( 0, 0, new QTableWidgetItem( QString ("") ) );
201        TWCMP->item( 0, 0 )->setFlags( Qt::ItemIsUserCheckable|Qt::ItemIsEnabled);
202        TWCMP->item( 0, 0 )->setCheckState(Qt::Checked );
203        TWCMP->item( 0, 0 )->setFlags( 0 );
204        TWCMP->setItem( 0, 1, new QTableWidgetItem(QString(mesComposantsAvant[i])));
205        TWCMP->item( 0, 1 )->setFlags( Qt::ItemIsEnabled |Qt::ItemIsSelectable );
206     }
207     TWCMP->resizeColumnsToContents();
208     TWCMP->resizeRowsToContents();
209     TWCMP->clearSelection();
210
211   // Les seuils de raffinement
212   RBRAbs->setEnabled(false) ;
213   RBRRel->setEnabled(false) ;
214   RBRPE->setEnabled(false) ;
215   RBRNo->setEnabled(false) ;
216   if (_aTypeRaff== 0 )
217   {
218     SetRNo();
219     RBRNo->setEnabled(true) ;
220   }
221   else
222   {
223     if ( _TypeThR == 1 ) { SpinBox_RAbs->setValue(_ThreshR); SetRAbs(); RBRAbs->setEnabled(true);}
224     if ( _TypeThR == 2 ) { SpinBox_RRel->setValue(_ThreshR); SetRRel(); RBRRel->setEnabled(true);}
225     if ( _TypeThR == 3 ) { SpinBox_RPE->setValue(_ThreshR);  SetRPE();  RBRPE->setEnabled(true);}
226   }
227
228   // Les seuils de deraffinement
229   RBCAbs->setEnabled(false) ;
230   RBCRel->setEnabled(false) ;
231   RBCPE->setEnabled(false) ;
232   RBCNo->setEnabled(false) ;
233   if (_aTypeDera== 0 )
234   {
235     SetCNo();
236     RBCNo->setEnabled(true) ;
237   }
238   else
239   {
240     if ( _TypeThC == 1 ) { SpinBox_CAbs->setValue(_ThreshC); SetCAbs(); RBCAbs->setEnabled(true);}
241     if ( _TypeThC == 2 ) { SpinBox_CRel->setValue(_ThreshC); SetCRel(); RBCRel->setEnabled(true);}
242     if ( _TypeThC == 3 ) { SpinBox_CPE->setValue(_ThreshC);  SetCPE(); RBCPE->setEnabled(true);}
243   }
244   // Le choix de la prise en compte des composantes
245   if ( TWCMP->rowCount() == 1 )
246   { RBL2->setText(QString("Absolute value"));
247     RBInf->setText(QString("Relative value"));
248   }
249   else
250   { RBL2->setText(QString("L2 norm"));
251     RBInf->setText(QString("Infinite Norm"));
252   }
253   if ( _UsCmpI == 0 )
254   {
255     RBL2->setChecked(true);
256     RBL2->setEnabled(true);
257     RBInf->setEnabled(false) ;
258   }
259   else
260   {
261     RBL2->setEnabled(false) ;
262     RBInf->setChecked(true);
263     RBInf->setEnabled(true);
264   }
265 }
266 // -------------------------------------
267 void MonEditHypothesis::InitFieldInterp()
268 // -------------------------------------
269 // Affichage des informations pour les interpolations
270 {
271     MESSAGE ("Debut de InitFieldInterp");
272 //  Choix des options generales
273     _TypeFieldInterp = _aHypothesis->GetTypeFieldInterp();
274     MESSAGE ("_TypeFieldInterp = " << _TypeFieldInterp);
275 //
276 //  Aucune interpolation
277     if ( _TypeFieldInterp == 0 )
278     {
279       RBFieldNo->setChecked(true);
280       TWField->setVisible(0);
281     }
282 //  Interpolation de tous les champs
283     if ( _TypeFieldInterp == 1 )
284     {
285       RBFieldAll->setChecked(true);
286       TWField->setVisible(0);
287     }
288 //  Interpolation de champs choisis
289     if ( _TypeFieldInterp == 2 )
290     {
291       RBFieldChosen->setChecked(true);
292 //
293       TWField->setVisible(1);
294       HOMARD::listFieldInterpHypo_var mesChampsAvant = _aHypothesis->GetListFieldInterp();
295       TWField->clear();
296       TWField->setRowCount(0);
297       TWField->resizeRowsToContents();
298       for (int i=0; i<mesChampsAvant->length(); i++)
299       {
300         TWField->insertRow(0);
301         TWField->setItem( 0, 0, new QTableWidgetItem( QString ("") ) );
302         TWField->item( 0, 0 )->setFlags( Qt::ItemIsUserCheckable|Qt::ItemIsEnabled);
303         TWField->item( 0, 0 )->setCheckState(Qt::Checked );
304         TWField->item( 0, 0 )->setFlags( 0 );
305         TWField->setItem( 0, 1, new QTableWidgetItem(QString(mesChampsAvant[i])));
306         TWField->item( 0, 1 )->setFlags( Qt::ItemIsEnabled |Qt::ItemIsSelectable );
307       }
308       TWField->resizeColumnsToContents();
309       TWField->resizeRowsToContents();
310       TWField->clearSelection();
311     }
312     RBFieldNo->setEnabled(false) ;
313     RBFieldAll->setEnabled(false) ;
314     RBFieldChosen->setEnabled(false) ;
315 }
316
317 // -------------------------------------
318 bool MonEditHypothesis::PushOnApply()
319 // -------------------------------------
320 {
321 // Pour du raffinement selon un champ, les seuils ont-ils change ?
322   if ( _aTypeAdap ==  1 )
323   {
324     if (_aTypeRaff!= 0 )
325     {
326       if (_TypeThR == 1) { _ThreshR = SpinBox_RAbs->value(); }
327       if (_TypeThR == 2) { _ThreshR = SpinBox_RRel->value(); }
328       if (_TypeThR == 3) { _ThreshR = SpinBox_RPE->value();  }
329       _aHypothesis->SetRefinThr(_TypeThR, _ThreshR) ;
330     }
331     if (_aTypeDera!= 0 )
332     {
333       if (_TypeThC == 1) { _ThreshC = SpinBox_CAbs->value() ; }
334       if (_TypeThC == 2) { _ThreshC = SpinBox_CRel->value() ; }
335       if (_TypeThC == 3) { _ThreshC = SpinBox_CPE->value() ; }
336       _aHypothesis->SetUnRefThr(_TypeThC, _ThreshC) ;
337     }
338
339     _myHomardGen->InvalideHypo(_aHypothesisName.toStdString().c_str());
340     HOMARD_UTILS::updateObjBrowser();
341   }
342   return true;
343 };
344 // ------------------------------------------------------------------------
345 void MonEditHypothesis::SetFiltrage()
346 // ------------------------------------------------------------------------
347 {
348   if (CBGroupe->isChecked())
349   {
350     MonEditListGroup *aDlg = new MonEditListGroup(this, NULL, TRUE, HOMARD::HOMARD_Gen::_duplicate(_myHomardGen),_aCaseName, _aListeGroupes) ;
351     aDlg->show();
352   }
353 }
354