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