Salome HOME
mise a jour pour la poursuite d'iterations
[modules/homard.git] / src / HOMARDGUI / MonEditCase.cxx
1 // Copyright (C) 2011-2013  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 "MonEditCase.h"
23
24 #include "SalomeApp_Tools.h"
25 #include "HOMARDGUI_Utils.h"
26 #include "HomardQtCommun.h"
27 #include <utilities.h>
28
29
30 // -------------------------------------------------------------
31 /* Constructs a MonEditCase
32     herite de MonCreateCase
33 */
34 // -------------------------------------------------------------
35 MonEditCase::MonEditCase ( QWidget* parent, bool modal,
36                            HOMARD::HOMARD_Gen_var myHomardGen,
37                            QString CaseName ):
38    MonCreateCase(parent, modal, myHomardGen)
39 {
40     MESSAGE("Debut de MonEditCase" << CaseName.toStdString().c_str());
41     setWindowTitle(QObject::tr("HOM_CASE_EDIT_WINDOW_TITLE"));
42     _aCaseName = CaseName;
43     aCase = _myHomardGen->GetCase(_aCaseName.toStdString().c_str());
44     InitValEdit();
45 }
46 // ------------------------------
47 MonEditCase::~MonEditCase()
48 // ------------------------------
49 {
50 }
51 // ------------------------------
52 void MonEditCase::InitValEdit()
53 // ------------------------------
54 {
55   MESSAGE("InitValEdit");
56   LECaseName->setText(_aCaseName);
57   LECaseName->setReadOnly(true);
58
59   QString aDirName = aCase->GetDirName();
60   LEDirName->setText(aDirName);
61   LEDirName->setReadOnly(true);
62   PushDir->setVisible(0);
63
64   QString _aitername=aCase->GetIter0Name();
65   HOMARD::HOMARD_Iteration_var aIter = _myHomardGen->GetIteration(_aitername.toStdString().c_str());
66   QString aFileName = aIter->GetMeshFile();
67   LEFileName->setText(aFileName);
68   LEFileName->setReadOnly(true);
69   PushFichier->setVisible(0);
70
71   int ConfType=aCase->GetConfType();
72   if(ConfType==1)
73   {
74       GBTypeNoConf->setVisible(0);
75       RBConforme->setChecked(true);
76   }
77   else
78   {
79     RBNonConforme->setChecked(true);
80     GBTypeNoConf->setVisible(1);
81     RB1NpM->setEnabled(false);
82     RB1NpA->setEnabled(false);
83     RBQuelconque->setEnabled(false);
84   };
85
86   if (_ConfType==2) { RB1NpM->setChecked(true);};
87   if (_ConfType==3) { RB1NpA->setChecked(true);};
88   if (_ConfType==4) { RBQuelconque->setChecked(true);};
89
90   RBNonConforme->setEnabled(false);
91   RBConforme->setEnabled(false);
92
93 //    Non affichage du mode de suivi de frontiere
94   CBBoundaryA->setVisible(0);
95   GBBoundaryA->setVisible(0);
96   CBBoundaryD->setVisible(0);
97   GBBoundaryD->setVisible(0);
98
99 //    On passe en revue tous les couples (frontiere,groupe) du cas
100   HOMARD::ListBoundaryGroupType_var mesBoundarys = aCase->GetBoundaryGroup();
101   if (mesBoundarys->length()>0)
102   {
103     QStringList ListeFron ;
104     QString NomFron ;
105     bool BounDi = false ;
106     bool BounAn = false ;
107     for (int i=0; i<mesBoundarys->length(); i++)
108     {
109 //        Nom de la frontiere
110       NomFron = mesBoundarys[i++];
111       MESSAGE("NomFron "<<NomFron.toStdString().c_str());
112 //        L'objet associe pour en deduire le type
113       HOMARD::HOMARD_Boundary_var myBoundary = _myHomardGen->GetBoundary(NomFron.toStdString().c_str());
114       int type_obj = myBoundary->GetType() ;
115 //        C'est une frontiere discrete
116 //        Rermarque : on ne gere pas les groupes
117       if ( type_obj==0 )
118       {
119         BounDi = true ;
120         CBBoundaryDi->addItem(NomFron);
121       }
122 //        C'est une frontiere analytique
123       else
124       {
125         BounAn = true ;
126         int nbcol = TWBoundary->columnCount();
127 //          On ajoute une ligne pour le groupe
128         TWBoundary->insertRow(0);
129 //          La colonne 0 comporte le nom du groupe
130         TWBoundary->setItem( 0, 0, new QTableWidgetItem(QString(mesBoundarys[i]).trimmed()));
131 //             TWBoundary->item( 0, 0 )->setFlags(Qt::ItemIsEnabled |Qt::ItemIsSelectable );
132 //          Chacune des colonnes suivantes est associĆ© a une frontiere deja presente : on y met une
133 //          case non cochee
134         for ( int j = 1; j < nbcol; j++ )
135         {
136           TWBoundary->setItem( 0, j, new QTableWidgetItem( QString ("") ) );
137           TWBoundary->item( 0, j )->setFlags( 0 );
138           TWBoundary->item( 0, j )->setFlags( Qt::ItemIsUserCheckable  );
139           TWBoundary->item( 0, j )->setCheckState( Qt::Unchecked );
140         }
141 //          On cherche si la frontiere en cours d'examen a deja ete rencontree :
142 //          si oui, on stocke son numero de colonne
143         int ok = -1 ;
144         for ( int nufr = 0 ; nufr<ListeFron.size(); nufr++)
145         { if ( ListeFron[nufr] == NomFron ) ok = nufr+1 ; }
146 //            si non, on ajoute une colonne
147         if ( ok < 0 )
148         {
149           ListeFron.append(NomFron);
150           ok = ListeFron.size() ;
151           AddBoundaryAn(NomFron);
152         }
153 //          on coche la case correspondant au couple (frontiere,groupe) en cours d'examen
154         TWBoundary->item( 0, ok )->setCheckState( Qt::Checked );
155       }
156     }
157     MESSAGE("BounDi "<<BounDi<<", BounAn "<<BounAn);
158     if ( BounAn )
159     { GBBoundaryA->setVisible(1);
160 //    On rend les cases non modifiables.
161 //    On ne peut pas le faire pour tout le tableau sinon on perd l'ascenseur !
162       int nbcol = TWBoundary->columnCount();
163       int nbrow = TWBoundary->rowCount();
164       for ( int i = 0; i < nbrow; i++ )
165       { for ( int j = 0; j < nbcol; j++ ) TWBoundary->item( i, j )->setFlags( Qt::ItemIsSelectable ); }
166 //    on met un nom blanc au coin
167       QTableWidgetItem *__colItem = new QTableWidgetItem();
168       __colItem->setText(QApplication::translate("CreateCase", "", 0, QApplication::UnicodeUTF8));
169       TWBoundary->setHorizontalHeaderItem(0, __colItem);
170 //    on cache les boutons inutiles
171       PBBoundaryAnNew->setVisible(0);
172       PBBoundaryAnHelp->setVisible(0);
173     }
174     if ( BounDi )
175     { GBBoundaryD->setVisible(1);
176       CBBoundaryDi->setDisabled(true);
177       PBBoundaryDiNew->setVisible(0);
178       PBBoundaryDiHelp->setVisible(0); }
179   }
180 //
181 // Les options avancees (non modifiables)
182   CBAdvanced->setVisible(0) ;
183   CBAdvanced->setEnabled(false) ;
184   int Pyram = aCase->GetPyram();
185   MESSAGE("Pyram "<<Pyram);
186   if ( Pyram > 0 )
187   { GBAdvancedOptions->setVisible(1);
188     CBPyramid->setChecked(true);
189     CBPyramid->setEnabled(false);
190   }
191   else
192   { GBAdvancedOptions->setVisible(0);
193     CBPyramid->setChecked(false);
194  }
195 //
196 // L'etat
197   int etat = aCase->GetState();
198   MESSAGE("etat "<<etat);
199   if ( etat == 0 ) { Comment->setText(QApplication::translate("CreateCase", "HOM_CASE_EDIT_STATE_0", 0, QApplication::UnicodeUTF8)); }
200   else             { Comment->setText(QApplication::translate("CreateCase", "HOM_CASE_EDIT_STATE", 0, QApplication::UnicodeUTF8)); }
201
202   Comment->setVisible(1);
203 //
204   adjustSize();
205 }
206
207 // -------------------------------------
208 bool MonEditCase::PushOnApply()
209 // -------------------------------------
210 {
211   return true ;
212 };