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