]> SALOME platform Git repositories - modules/homard.git/blob - src/HOMARDGUI/MonCreateYACS.cxx
Salome HOME
Nouvelles icones
[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 /* Constructs a MonCreateYACS
35  * Sets attributes to default values
36  */
37 // -----------------------------------------------------------------------------------------
38 MonCreateYACS::MonCreateYACS (QWidget* parent, bool modal, HOMARD::HOMARD_Gen_var myHomardGen, QString CaseName )
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(myHomardGen);
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()
66 // ------------------------------------------------------------------------
67 {
68     // no need to delete child widgets, Qt does it all for us
69 }
70 // ------------------------------------------------------------------------
71 void MonCreateYACS::InitConnect()
72 // ------------------------------------------------------------------------
73 {
74     connect( PBCaseName,     SIGNAL(pressed()), this, SLOT(SetCaseName()));
75     connect( PushDir,        SIGNAL(pressed()), this, SLOT(SetDirName()));
76     connect( PushFile,       SIGNAL(pressed()), this, SLOT(SetScriptFile()));
77     connect( PushFile_2,     SIGNAL(pressed()), this, SLOT(SetMeshFile()));
78
79     connect( RBStatic,       SIGNAL(clicked()), this, SLOT(SetType(1)));
80     connect( RBTransient,    SIGNAL(clicked()), this, SLOT(SetType(2)));
81
82     connect( buttonOk,       SIGNAL(pressed()), this, SLOT(PushOnOK()));
83     connect( buttonApply,    SIGNAL(pressed()), this, SLOT(PushOnApply()));
84     connect( buttonCancel,   SIGNAL(pressed()), this, SLOT(close()));
85     connect( buttonHelp,     SIGNAL(pressed()), this, SLOT(PushOnHelp()));
86 }
87 // -------------------------------
88 bool MonCreateYACS::PushOnApply()
89 // --------------------------------
90 {
91   MESSAGE("PushOnApply");
92
93   if ( _aCaseName == QString (""))
94   {
95     QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
96                               QObject::tr("HOM_CASE_NAME") );
97     return false;
98   }
99 // Le fichier du script
100   QString aFileName=LEScriptFile->text().trimmed();
101   if (aFileName ==QString(""))
102   {
103     QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
104                               QObject::tr("HOM_SCRIPT_FILE") );
105     return false;
106   }
107
108 // Le repertoire de calcul
109   QString aDirName=LEDirName->text().trimmed();
110   if (aDirName == QString(""))
111   {
112     QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
113                               QObject::tr("HOM_CASE_DIRECTORY_4") );
114     return false;
115   }
116   if ((aDirName != _aDirName) and (myHomardGen->VerifieDir( aDirName.toStdString().c_str()) == false))
117   {
118     QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
119                               QObject::tr("HOM_CASE_DIRECTORY_2") );
120     return false;
121   }
122   if (chdir(aDirName.toStdString().c_str()) != 0)
123   {
124     QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
125                               QObject::tr("HOM_CASE_DIRECTORY_3") );
126     return false;
127   }
128
129 // Le fichier du tout premier maillage
130   aFileName=LEMeshFile->text().trimmed();
131   if (aFileName ==QString(""))
132   {
133     QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
134                               QObject::tr("HOM_CASE_MESH") );
135     return false;
136   }
137   QString aMeshName = HOMARD_QT_COMMUN::LireNomMaillage(aFileName);
138   if (aMeshName == "" )
139   {
140     QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
141                               QObject::tr("HOM_MED_FILE_2") );
142     return false;
143   }
144
145   HOMARD_UTILS::updateObjBrowser();
146   MESSAGE ("_aCaseName.toStdString " << _aCaseName.toStdString() );
147
148 // Creation de l'objet CORBA
149   try
150   {
151     _Name=LEName->text().trimmed();
152     aYACS=myHomardGen->CreateYACSSchema(CORBA::string_dup(_Name.toStdString().c_str()), _aCaseName.toStdString().c_str(), _aScriptFile.toStdString().c_str(), _aDirName.toStdString().c_str(), _aMeshFile.toStdString().c_str());
153 //     _parent->AddYACS(_Name);
154   }
155   catch( SALOME::SALOME_Exception& S_ex )
156   {
157     QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
158                               QObject::tr(CORBA::string_dup(S_ex.details.text)) );
159     return false;
160   }
161
162 return true;
163 }
164 // ---------------------------
165 void MonCreateYACS::PushOnOK()
166 // ---------------------------
167 {
168   bool bOK = PushOnApply();
169   if ( bOK )  this->close();
170 }
171 //------------------------------
172 void MonCreateYACS::PushOnHelp()
173 //-------------------------------
174 {
175   HOMARD_UTILS::PushOnHelp(QString("gui_create_case.html"), QString(""));
176 }
177 // -------------------------------------------------
178 void MonCreateYACS::SetNewName()
179 // --------------------------------------------------
180 {
181
182   HOMARD::listeYACSs_var MyObjects = myHomardGen->GetAllYACSsName();
183   int num = 0; QString aName="";
184   while (aName == QString("") )
185   {
186     aName.setNum(num+1) ;
187     aName.insert(0, QString("YACS_")) ;
188     for ( int i=0; i<MyObjects->length(); i++)
189     {
190       if ( aName ==  QString(MyObjects[i]))
191       {
192           num=num+1;
193           aName="";
194           break;
195       }
196    }
197   }
198   LEName->setText(aName);
199 }
200 // ------------------------------------------------------------------------
201 void MonCreateYACS::SetCaseName()
202 // ------------------------------------------------------------------------
203 {
204   MESSAGE ("SetCaseName avec _aCaseName = " << _aCaseName.toStdString() );
205   if (_aCaseName == QString(""))
206   {
207     _aCaseName=HOMARD_QT_COMMUN::SelectionArbreEtude(QString("CasHomard"), 1);
208     if (_aCaseName == QString("")) { raise();return;};
209   }
210 /*  MESSAGE ("appel de GetCase avec _aCaseName = " << _aCaseName.toStdString() );*/
211   aCase = myHomardGen->GetCase(_aCaseName.toStdString().c_str());
212   LECaseName->setText(_aCaseName);
213 }
214 // ------------------------------------------------------------------------
215 void MonCreateYACS::SetDirName()
216 // ------------------------------------------------------------------------
217 {
218   QString aDirName=QFileDialog::getExistingDirectory ();
219   if (!(aDirName.isEmpty()))LEDirName->setText(aDirName);
220 }
221 // ------------------------------------------------------------------------
222 void MonCreateYACS::SetScriptFile()
223 // ------------------------------------------------------------------------
224 {
225   QString fileName0 = LEScriptFile->text().trimmed();
226   QString fileName = HOMARD_QT_COMMUN::PushNomFichier(false);
227   if (fileName.isEmpty()) fileName = fileName0 ;
228   LEScriptFile->setText(fileName);
229 }
230 // ------------------------------------------------------------------------
231 void MonCreateYACS::SetMeshFile()
232 // ------------------------------------------------------------------------
233 {
234   QString fileName0 = LEMeshFile->text().trimmed();
235   QString fileName = HOMARD_QT_COMMUN::PushNomFichier(false);
236   if (fileName.isEmpty()) fileName = fileName0 ;
237   LEMeshFile->setText(fileName);
238 }
239 // ------------------------------------------------------------------------
240 void MonCreateYACS::SetType(int Type)
241 // ------------------------------------------------------------------------
242 {
243   _Type=Type;
244 }