Salome HOME
Merge from V6_main 01/04/2013
[modules/homard.git] / src / HOMARDGUI / MonIterInfo.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 "MonIterInfo.h"
23
24 #include <QFile>
25 #include <QTextStream>
26 #include <QFileDialog>
27 #include <QMessageBox>
28
29 #include "SalomeApp_Tools.h"
30 #include "HOMARDGUI_Utils.h"
31 #include "HomardQtCommun.h"
32 #include <utilities.h>
33
34
35 // -----------------------------------------------------------------------------------------
36 MonIterInfo::MonIterInfo(QWidget* parent, bool modal, HOMARD::HOMARD_Gen_var myHomardGen, QString IterName)
37 // -----------------------------------------------------------------------------------------
38 /* Constructs a MonIterInfo
39  * Inherits from CasHomard
40  * Sets attributes to default values
41  */
42     :
43     Ui_IterInfo(),
44     _IterName(IterName),
45     _aCaseName(""),
46     _BlockSize(0),
47     _Connection(0),
48     _Diametre(0),
49     _Entanglement(0),
50     _Quality(0),
51     _Option(-1)
52 {
53     MESSAGE("appel de _duplicate");
54       _myHomardGen=HOMARD::HOMARD_Gen::_duplicate(myHomardGen);
55       setupUi(this);
56       setModal(modal);
57       InitConnect();
58
59       adjustSize();
60 }
61
62 // ------------------------------------------------------------------------
63 MonIterInfo::~MonIterInfo()
64 // ------------------------------------------------------------------------
65 {
66     // no need to delete child widgets, Qt does it all for us
67 }
68 // ------------------------------------------------------------------------
69 void MonIterInfo::InitConnect()
70 // ------------------------------------------------------------------------
71 {
72     MESSAGE("InitConnect");
73     connect( CBBlockSize,    SIGNAL(stateChanged(int)), this, SLOT(SetBlockSize()));
74     connect( CBConnection,   SIGNAL(stateChanged(int)), this, SLOT(SetConnection()));
75     connect( CBDiametre,     SIGNAL(stateChanged(int)), this, SLOT(SetDiametre()));
76     connect( CBEntanglement, SIGNAL(stateChanged(int)), this, SLOT(SetEntanglement()));
77     connect( CBQuality,      SIGNAL(stateChanged(int)), this, SLOT(SetQuality()));
78
79     connect( buttonOk,       SIGNAL(pressed()), this, SLOT(PushOnOK()));
80     connect( buttonApply,    SIGNAL(pressed()), this, SLOT(PushOnApply()));
81     connect( buttonCancel,   SIGNAL(pressed()), this, SLOT(close()));
82     connect( buttonHelp,     SIGNAL(pressed()), this, SLOT(PushOnHelp()));
83 }
84 // -------------------------------
85 bool MonIterInfo::PushOnApply()
86 // --------------------------------
87 {
88   MESSAGE("PushOnApply");
89
90   // Au moins une option a ete choisie
91   if ( ( _Quality == 0 ) and ( _Diametre == 0 ) and ( _Connection == 0 ) and ( _BlockSize == 0 ) and ( _Entanglement == 0 ) )
92   {
93     QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
94                               QObject::tr("HOM_MESH_INFO_1") );
95     return false;
96   }
97
98   // Recuperation de l'iteration
99   aIter = _myHomardGen->GetIteration(_IterName.toStdString().c_str()) ;
100
101   // Lancement de l'analyse
102   try
103   {
104     aIter->MeshInfoOption( _Quality, _Diametre, _Connection, _BlockSize, _Entanglement, _Option );
105   }
106   catch( SALOME::SALOME_Exception& S_ex )
107   {
108     QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
109                               QObject::tr(CORBA::string_dup(S_ex.details.text)) );
110     return false;
111   }
112
113   // Le bilan de l'analyse a afficher
114   QString aFileName = aIter->GetFileInfo() ;
115 // // Creation de l'objet fichier QT associe
116 //   QFile file( aFileName );
117 // // Ouverture
118 //   bool bOpen = file.open( QIODevice::ReadOnly | QIODevice::Text ) ;
119 // //
120 //   if ( bOpen )
121 //   {
122 //      Ui_EditFile() ;
123 // // Lecture
124 // //    Remarque : il serait plus clair de tout lire d'un coup mais cela ne marche pas !
125 // //               alors on fait ligne par ligne et on cumule en ajoutant un saut de ligne.
126 //       QTextStream stream( &file );
127 //       QString tout;
128 //       while ( !stream.atEnd() )
129 //       {
130 //         tout = tout + stream.readLine() + "\n" ;
131 //       }
132 //       QTBEditFile->setPlainText( tout );
133 //   QMessageBox::information( 0, QObject::tr("HOM_MESH_INFO_0"),
134 //                                tout );
135 //   }
136
137   // Message simple en attendant de savoir faire
138   QMessageBox::information( 0, QObject::tr("HOM_MESH_INFO_0"),
139                                QObject::tr("HOM_MESH_INFO_2")+aFileName );
140
141   HOMARD_UTILS::updateObjBrowser();
142   return true;
143 }
144 // ---------------------------
145 void MonIterInfo::PushOnOK()
146 // ---------------------------
147 {
148      bool bOK = PushOnApply();
149      if ( bOK )  this->close();
150 }
151 //------------------------------
152 void MonIterInfo::PushOnHelp()
153 //-------------------------------
154 {
155   HOMARD_UTILS::PushOnHelp(QString("gui_mesh_info.html"));
156 }
157 // ------------------------------------------------------------------------
158 void MonIterInfo::SetBlockSize()
159 // ------------------------------------------------------------------------
160 {
161   MESSAGE("Debut de SetBlockSize ");
162   if ( CBBlockSize->isChecked() ) { _BlockSize = 1 ; }
163   else                            { _BlockSize = 0 ; }
164 }
165 // ------------------------------------------------------------------------
166 void MonIterInfo::SetConnection()
167 // ------------------------------------------------------------------------
168 {
169   MESSAGE("Debut de SetConnection ");
170   if ( CBConnection->isChecked() ) { _Connection = 1 ; }
171   else                             { _Connection = 0 ; }
172 }
173 // ------------------------------------------------------------------------
174 void MonIterInfo::SetDiametre()
175 // ------------------------------------------------------------------------
176 {
177   MESSAGE("Debut de SetDiametre ");
178   if ( CBDiametre->isChecked() ) { _Diametre = 1 ; }
179   else                           { _Diametre = 0 ; }
180 }
181 // ------------------------------------------------------------------------
182 void MonIterInfo::SetEntanglement()
183 // ------------------------------------------------------------------------
184 {
185   MESSAGE("Debut de SetEntanglement ");
186   if ( CBEntanglement->isChecked() ) { _Entanglement = 1 ; }
187   else                               { _Entanglement = 0 ; }
188 }
189 // ------------------------------------------------------------------------
190 void MonIterInfo::SetQuality()
191 // ------------------------------------------------------------------------
192 {
193   MESSAGE("Debut de SetQuality ");
194   if ( CBQuality->isChecked() ) { _Quality = 1 ; }
195   else                          { _Quality = 0 ; }
196 }