]> SALOME platform Git repositories - modules/homard.git/blob - src/HOMARDGUI/MonCreateYACS.cxx
Salome HOME
Documentation sur les schémas YACS
[modules/homard.git] / src / HOMARDGUI / MonCreateYACS.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 "MonCreateYACS.h"
23
24 #include <QFileDialog>
25 #include <QMessageBox>
26
27 #include "SalomeApp_Tools.h"
28 #include "HOMARDGUI_Utils.h"
29 #include "HomardQtCommun.h"
30 #include <utilities.h>
31
32
33 // ----------------------------------------------------------------------
34 MonCreateYACS::MonCreateYACS (bool modal, HOMARD::HOMARD_Gen_var myHomardGen0, QString CaseName ):
35 // ----------------------------------------------------------------------
36 /* Constructs a MonCreateYACS
37  * Sets attributes to default values
38  */
39 // ----------------------------------------------------------------------
40   Ui_CreateYACS(),
41   _aCaseName(CaseName),
42   _aScriptFile(""),
43   _aDirName(""),
44   _aMeshFile("")
45   {
46 //     MESSAGE("Debut du constructeur de MonCreateYACS");
47     myHomardGen=HOMARD::HOMARD_Gen::_duplicate(myHomardGen0);
48     setupUi(this);
49     setModal(modal);
50
51     InitConnect();
52
53     SetNewName() ;
54
55     if (_aCaseName != QString(""))
56       { SetCaseName(); }
57     else
58       {setModal(false); /* permet selection du cas dans l arbre d etude */}
59
60     adjustSize();
61 //     MESSAGE("Fin du constructeur de MonCreateYACS");
62   }
63
64 // ----------------------------------------------------------------------
65 MonCreateYACS::MonCreateYACS(HOMARD::HOMARD_Gen_var myHomardGen0,
66                              QString caseName):
67 // ----------------------------------------------------------------------
68 // Constructeur appele par MonEditYACS
69 //
70     myHomardGen(myHomardGen0),
71     _Name (""),
72     Chgt (false)
73     {
74 //       MESSAGE("Debut du constructeur de MonCreateYACS appele par MonEditYACS");
75       setupUi(this) ;
76
77       setModal(true) ;
78       InitConnect() ;
79     }
80
81 // ------------------------------------------------------------------------
82 MonCreateYACS::~MonCreateYACS()
83 // ------------------------------------------------------------------------
84 {
85     // no need to delete child widgets, Qt does it all for us
86 }
87 // ------------------------------------------------------------------------
88 void MonCreateYACS::InitConnect()
89 // ------------------------------------------------------------------------
90 {
91     connect( PBCaseName,     SIGNAL(pressed()), this, SLOT(SetCaseName()));
92     connect( PBScriptFile,   SIGNAL(pressed()), this, SLOT(SetScriptFile()));
93     connect( PBDir,          SIGNAL(pressed()), this, SLOT(SetDirName()));
94     connect( PBMeshFile,     SIGNAL(pressed()), this, SLOT(SetMeshFile()));
95
96     connect( RBConstant,     SIGNAL(clicked()), this, SLOT(SetType(1)));
97     connect( RBVariable,     SIGNAL(clicked()), this, SLOT(SetType(2)));
98
99     connect( buttonOk,       SIGNAL(pressed()), this, SLOT(PushOnOK()));
100     connect( buttonApply,    SIGNAL(pressed()), this, SLOT(PushOnApply()));
101     connect( buttonCancel,   SIGNAL(pressed()), this, SLOT(close()));
102     connect( buttonHelp,     SIGNAL(pressed()), this, SLOT(PushOnHelp()));
103 }
104 // -------------------------------
105 bool MonCreateYACS::PushOnApply()
106 // --------------------------------
107 {
108   MESSAGE("PushOnApply");
109
110 // Le fichier du script
111   QString aFileName=LEScriptFile->text().trimmed();
112   if (aFileName ==QString(""))
113   {
114     QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
115                               QObject::tr("HOM_SCRIPT_FILE") );
116     return false;
117   }
118
119 // Le repertoire de calcul
120   QString aDirName=LEDirName->text().trimmed();
121   if (aDirName == QString(""))
122   {
123     QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
124                               QObject::tr("HOM_CASE_DIRECTORY_4") );
125     return false;
126   }
127   if ((aDirName != _aDirName) and (myHomardGen->VerifieDir( aDirName.toStdString().c_str()) == false))
128   {
129     QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
130                               QObject::tr("HOM_CASE_DIRECTORY_2") );
131     return false;
132   }
133   if (chdir(aDirName.toStdString().c_str()) != 0)
134   {
135     QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
136                               QObject::tr("HOM_CASE_DIRECTORY_3") );
137     return false;
138   }
139
140 // Le fichier du tout premier maillage
141   aFileName=LEMeshFile->text().trimmed();
142   if (aFileName ==QString(""))
143   {
144     QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
145                               QObject::tr("HOM_CASE_MESH") );
146     return false;
147   }
148   QString aMeshName = HOMARD_QT_COMMUN::LireNomMaillage(aFileName);
149   if (aMeshName == "" )
150   {
151     QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
152                               QObject::tr("HOM_MED_FILE_2") );
153     return false;
154   }
155
156   bool bOK = CreateOrUpdate() ;
157
158   if ( bOK ) { HOMARD_UTILS::updateObjBrowser() ; }
159
160   return bOK;
161 }
162 // ---------------------------------------------------
163 bool MonCreateYACS:: CreateOrUpdate()
164 //----------------------------------------------------
165 //  Creation ou modification du schema
166 {
167   MESSAGE("CreateOrUpdate");
168   bool bOK = true ;
169
170   // Le cas
171   if ( _aCaseName == QString (""))
172   {
173     QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
174                               QObject::tr("HOM_CASE_NAME") );
175     return false;
176   }
177   // Les donnees
178   QString aScriptFile=LEScriptFile->text().trimmed();
179   if ( aScriptFile != _aScriptFile )
180   {
181     _aScriptFile = aScriptFile ;
182     Chgt = true ;
183   }
184   QString aDirName=LEDirName->text().trimmed();
185   if ( aDirName != _aDirName )
186   {
187     _aDirName = aDirName ;
188     Chgt = true ;
189   }
190   QString aMeshFile=LEMeshFile->text().trimmed();
191   if ( aMeshFile != _aMeshFile )
192   {
193     _aMeshFile = aMeshFile ;
194     Chgt = true ;
195   }
196
197   // Creation de l'objet CORBA
198   try
199   {
200     _Name=LEName->text().trimmed();
201     aYACS=myHomardGen->CreateYACSSchema(CORBA::string_dup(_Name.toStdString().c_str()), CORBA::string_dup(_aCaseName.toStdString().c_str()), CORBA::string_dup(_aScriptFile.toStdString().c_str()), CORBA::string_dup(_aDirName.toStdString().c_str()), CORBA::string_dup(_aMeshFile.toStdString().c_str()));
202   }
203   catch( SALOME::SALOME_Exception& S_ex )
204   {
205     QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
206                               QObject::tr(CORBA::string_dup(S_ex.details.text)) );
207     bOK = false;
208   }
209
210   // Options
211   if ( bOK )
212   { aYACS->SetType(_Type) ; }
213
214   // Ecriture du fichier
215   if ( bOK )
216   { aYACS->Write() ; }
217
218   return bOK;
219 }
220 // ---------------------------
221 void MonCreateYACS::PushOnOK()
222 // ---------------------------
223 {
224   bool bOK = PushOnApply();
225   if ( bOK ) this->close();
226 }
227 //------------------------------
228 void MonCreateYACS::PushOnHelp()
229 //-------------------------------
230 {
231   char* LanguageShort = myHomardGen->GetLanguageShort();
232   HOMARD_UTILS::PushOnHelp(QString("yacs.html"), QString(""), QString(LanguageShort));
233 }
234 // -------------------------------------------------
235 void MonCreateYACS::SetNewName()
236 // --------------------------------------------------
237 {
238
239   HOMARD::listeYACSs_var MyObjects = myHomardGen->GetAllYACSsName();
240   int num = 0; QString aName="";
241   while (aName == QString("") )
242   {
243     aName.setNum(num+1) ;
244     aName.insert(0, QString("YACS_")) ;
245     for ( int i=0; i<MyObjects->length(); i++)
246     {
247       if ( aName ==  QString(MyObjects[i]))
248       {
249           num=num+1;
250           aName="";
251           break;
252       }
253    }
254   }
255   LEName->setText(aName);
256 }
257 // ------------------------------------------------------------------------
258 void MonCreateYACS::SetCaseName()
259 // ------------------------------------------------------------------------
260 {
261   MESSAGE ("SetCaseName avec _aCaseName = " << _aCaseName.toStdString() );
262   if (_aCaseName == QString(""))
263   {
264     _aCaseName=HOMARD_QT_COMMUN::SelectionArbreEtude(QString("CasHomard"), 1);
265     if (_aCaseName == QString("")) { raise();return;};
266   }
267   LECaseName->setText(_aCaseName);
268 }
269 // ------------------------------------------------------------------------
270 void MonCreateYACS::SetDirName()
271 // ------------------------------------------------------------------------
272 {
273   QString aDirName=QFileDialog::getExistingDirectory ();
274   if (!(aDirName.isEmpty()))LEDirName->setText(aDirName);
275 }
276 // ------------------------------------------------------------------------
277 void MonCreateYACS::SetScriptFile()
278 // ------------------------------------------------------------------------
279 {
280   QString fileName0 = LEScriptFile->text().trimmed();
281   QString fileName = HOMARD_QT_COMMUN::PushNomFichier(false);
282   if (fileName.isEmpty()) fileName = fileName0 ;
283   LEScriptFile->setText(fileName);
284 }
285 // ------------------------------------------------------------------------
286 void MonCreateYACS::SetMeshFile()
287 // ------------------------------------------------------------------------
288 {
289   QString fileName0 = LEMeshFile->text().trimmed();
290   QString fileName = HOMARD_QT_COMMUN::PushNomFichier(false);
291   if (fileName.isEmpty()) fileName = fileName0 ;
292   LEMeshFile->setText(fileName);
293 }
294 // ------------------------------------------------------------------------
295 void MonCreateYACS::SetType(int Type)
296 // ------------------------------------------------------------------------
297 {
298   _Type=Type;
299 }