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