Salome HOME
Correction de l'affichage du cas en mode non conforme
[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 ( bool modal,
36                            HOMARD::HOMARD_Gen_var myHomardGen,
37                            QString CaseName ):
38    MonCreateCase(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   LEName->setText(_aCaseName);
57   LEName->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     RBConforme->setChecked(true);
75     GBTypeNoConf->setVisible(0);
76   }
77   else
78   {
79     RBNonConforme->setChecked(true);
80     GBTypeNoConf->setVisible(1);
81     if (ConfType==2) { RB1NpM->setChecked(true);};
82     if (ConfType==3) { RB1NpA->setChecked(true);};
83     if (ConfType==4) { RBQuelconque->setChecked(true);};
84     RB1NpM->setEnabled(false);
85     RB1NpA->setEnabled(false);
86     RBQuelconque->setEnabled(false);
87   };
88
89   RBConforme->setEnabled(false);
90   RBNonConforme->setEnabled(false);
91
92 //    Non affichage du mode de suivi de frontiere
93   CBBoundaryA->setVisible(0);
94   GBBoundaryA->setVisible(0);
95   CBBoundaryD->setVisible(0);
96   GBBoundaryD->setVisible(0);
97
98 //    On passe en revue tous les couples (frontiere,groupe) du cas
99   HOMARD::ListBoundaryGroupType_var mesBoundarys = aCase->GetBoundaryGroup();
100   if (mesBoundarys->length()>0)
101   {
102     QStringList ListeFron ;
103     QString NomFron ;
104     bool BounDi = false ;
105     bool BounAn = false ;
106     for (int i=0; i<mesBoundarys->length(); i++)
107     {
108 //        Nom de la frontiere
109       NomFron = mesBoundarys[i++];
110       MESSAGE("NomFron "<<NomFron.toStdString().c_str());
111 //        L'objet associe pour en deduire le type
112       HOMARD::HOMARD_Boundary_var myBoundary = myHomardGen->GetBoundary(NomFron.toStdString().c_str());
113       int type_obj = myBoundary->GetType() ;
114 //        C'est une frontiere discrete
115 //        Rermarque : on ne gere pas les groupes
116       if ( type_obj==0 )
117       {
118         BounDi = true ;
119         CBBoundaryDi->addItem(NomFron);
120       }
121 //        C'est une frontiere analytique
122       else
123       {
124         BounAn = true ;
125         int nbcol = TWBoundary->columnCount();
126 //          On ajoute une ligne pour le groupe
127         TWBoundary->insertRow(0);
128 //          La colonne 0 comporte le nom du groupe
129         TWBoundary->setItem( 0, 0, new QTableWidgetItem(QString(mesBoundarys[i]).trimmed()));
130 //             TWBoundary->item( 0, 0 )->setFlags(Qt::ItemIsEnabled |Qt::ItemIsSelectable );
131 //          Chacune des colonnes suivantes est associĆ© a une frontiere deja presente : on y met une
132 //          case non cochee
133         for ( int j = 1; j < nbcol; j++ )
134         {
135           TWBoundary->setItem( 0, j, new QTableWidgetItem( QString ("") ) );
136           TWBoundary->item( 0, j )->setFlags( 0 );
137           TWBoundary->item( 0, j )->setFlags( Qt::ItemIsUserCheckable  );
138           TWBoundary->item( 0, j )->setCheckState( Qt::Unchecked );
139         }
140 //          On cherche si la frontiere en cours d'examen a deja ete rencontree :
141 //          si oui, on stocke son numero de colonne
142         int ok = -1 ;
143         for ( int nufr = 0 ; nufr<ListeFron.size(); nufr++)
144         { if ( ListeFron[nufr] == NomFron ) ok = nufr+1 ; }
145 //            si non, on ajoute une colonne
146         if ( ok < 0 )
147         {
148           ListeFron.append(NomFron);
149           ok = ListeFron.size() ;
150           AddBoundaryAn(NomFron);
151         }
152 //          on coche la case correspondant au couple (frontiere,groupe) en cours d'examen
153         TWBoundary->item( 0, ok )->setCheckState( Qt::Checked );
154       }
155     }
156     MESSAGE("BounDi "<<BounDi<<", BounAn "<<BounAn);
157     if ( BounAn )
158     { GBBoundaryA->setVisible(1);
159 //    On rend les cases non modifiables.
160 //    On ne peut pas le faire pour tout le tableau sinon on perd l'ascenseur !
161       int nbcol = TWBoundary->columnCount();
162       int nbrow = TWBoundary->rowCount();
163       for ( int i = 0; i < nbrow; i++ )
164       { for ( int j = 0; j < nbcol; j++ ) TWBoundary->item( i, j )->setFlags( Qt::ItemIsSelectable ); }
165 //    on met un nom blanc au coin
166       QTableWidgetItem *__colItem = new QTableWidgetItem();
167       __colItem->setText(QApplication::translate("CreateCase", "", 0, QApplication::UnicodeUTF8));
168       TWBoundary->setHorizontalHeaderItem(0, __colItem);
169 //    on cache les boutons inutiles
170       PBBoundaryAnNew->setVisible(0);
171       PBBoundaryAnHelp->setVisible(0);
172     }
173     if ( BounDi )
174     { GBBoundaryD->setVisible(1);
175       CBBoundaryDi->setDisabled(true);
176       PBBoundaryDiNew->setVisible(0);
177       PBBoundaryDiHelp->setVisible(0); }
178   }
179 //
180 // Les options avancees (non modifiables)
181   CBAdvanced->setVisible(0) ;
182   CBAdvanced->setEnabled(false) ;
183   int Pyram = aCase->GetPyram();
184   MESSAGE("Pyram "<<Pyram);
185   if ( Pyram > 0 )
186   { GBAdvancedOptions->setVisible(1);
187     CBPyramid->setChecked(true);
188     CBPyramid->setEnabled(false);
189   }
190   else
191   { GBAdvancedOptions->setVisible(0);
192     CBPyramid->setChecked(false);
193  }
194 //
195 // L'etat
196   int etat = aCase->GetState();
197   MESSAGE("etat "<<etat);
198   if ( etat == 0 ) { Comment->setText(QApplication::translate("CreateCase", "HOM_CASE_EDIT_STATE_0", 0, QApplication::UnicodeUTF8)); }
199   else             { Comment->setText(QApplication::translate("CreateCase", "HOM_CASE_EDIT_STATE", 0, QApplication::UnicodeUTF8)); }
200
201   Comment->setVisible(1);
202 //
203   adjustSize();
204 }
205
206 // -------------------------------------
207 bool MonEditCase::PushOnApply()
208 // -------------------------------------
209 {
210   return true ;
211 };