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