]> SALOME platform Git repositories - modules/homard.git/blob - src/HOMARD/HOMARD_Cas.cxx
Salome HOME
Porting HOMARD SALOME module on WIN32 platform.
[modules/homard.git] / src / HOMARD / HOMARD_Cas.cxx
1 //  HOMARD HOMARD : implementation of HOMARD idl descriptions
2 //
3 // Copyright (C) 2011-2013  CEA/DEN, EDF R&D
4 //
5 // This library is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU Lesser General Public
7 // License as published by the Free Software Foundation; either
8 // version 2.1 of the License.
9 //
10 // This library is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13 // Lesser General Public License for more details.
14 //
15 // You should have received a copy of the GNU Lesser General Public
16 // License along with this library; if not, write to the Free Software
17 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
18 //
19 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 //
21 //  File   : HOMARD_Cas.cxx
22 //  Author : Paul RASCLE, EDF
23 //  Module : HOMARD
24 //
25 // Remarques :
26 // L'ordre de description des fonctions est le meme dans tous les fichiers
27 // HOMARD_aaaa.idl, HOMARD_aaaa.hxx, HOMARD_aaaa.cxx, HOMARD_aaaa_i.hxx, HOMARD_aaaa_i.cxx :
28 // 1. Les generalites : Name, Delete, DumpPython, Dump, Restore
29 // 2. Les caracteristiques
30 // 3. Le lien avec les autres structures
31 //
32 // Quand les 2 fonctions Setxxx et Getxxx sont presentes, Setxxx est decrit en premier
33
34 #include "HOMARD_Cas.hxx"
35 #include "utilities.h"
36 #include <iostream>
37 #include <sys/stat.h>
38
39 #ifndef WIN32
40 #include <unistd.h>
41 #else
42 #include <direct.h>
43 #endif
44
45 //=============================================================================
46 /*!
47  *  default constructor:
48  *  Par defaut, l'adaptation est conforme, sans suivi de frontiere
49  */
50 //=============================================================================
51 HOMARD_Cas::HOMARD_Cas():
52   _Name(""), _NomDir("/tmp"), _ConfType(1)
53 {
54   MESSAGE("HOMARD_Cas");
55 }
56 //=============================================================================
57 HOMARD_Cas::~HOMARD_Cas()
58 //=============================================================================
59 {
60   MESSAGE("~HOMARD_Cas");
61 }
62 //=============================================================================
63 //=============================================================================
64 // Generalites
65 //=============================================================================
66 //=============================================================================
67 void HOMARD_Cas::SetName( const char* Name )
68 {
69   _Name = std::string( Name );
70 }
71 //=============================================================================
72 std::string HOMARD_Cas::GetName() const
73 {
74   return _Name;
75 }
76 //=============================================================================
77 std::string HOMARD_Cas::GetDumpPython() const
78 {
79   std::ostringstream aScript;
80   aScript << "\t" <<_Name << ".SetDirName(\"";
81   aScript << _NomDir << "\")\n";
82   aScript << "\t" <<_Name << ".SetConfType(";
83   aScript << _ConfType << ")\n";
84 // Suivi de frontieres
85   std::list<std::string>::const_iterator it = _ListBoundaryGroup.begin();
86   while(it != _ListBoundaryGroup.end())
87   {
88     aScript << "\t" <<_Name << ".AddBoundaryGroup(\"";
89     aScript << *it << "\", \"";
90     it++;
91     aScript << *it << "\")\n";
92     it++;
93   }
94   if ( _Pyram > 0 )
95   {
96     aScript << "\t" <<_Name << ".SetPyram(";
97     aScript << _Pyram << ")\n";
98   }
99
100   return aScript.str();
101 }
102 //=============================================================================
103 //=============================================================================
104 // Caracteristiques
105 //=============================================================================
106 //=============================================================================
107 int HOMARD_Cas::SetDirName( const char* NomDir )
108 {
109   MESSAGE("SetDirName,  NomDir : "<<NomDir);
110   MESSAGE("SetDirName, _NomDir : "<<_NomDir);
111   int erreur = 0 ;
112   // On vérifie qu'aucun calcul n'a eu lieu pour ce cas
113   MESSAGE("SetDirName, _ListIter.size() : "<<_ListIter.size());
114   if ( _ListIter.size() > 1 ) { erreur = 1 ; }
115   // Creation
116 #ifndef WIN32
117   if ( chdir(NomDir) == 0 ) 
118 #else
119   if ( _chdir(NomDir) == 0 ) 
120 #endif
121   { _NomDir = std::string( NomDir ); }
122   else
123   {
124
125 #ifndef WIN32
126     if ( mkdir(NomDir, S_IRWXU|S_IRGRP|S_IXGRP) == 0 )
127     {
128       if ( chdir(NomDir) == 0 ) 
129 #else
130     if ( _mkdir(NomDir) == 0 )
131     {
132       if ( _chdir(NomDir) == 0 ) 
133 #endif
134       { _NomDir = std::string( NomDir ); }
135       else                      { erreur = 2 ; }
136     }
137     else { erreur = 2 ; }
138   };
139   return erreur ;
140 }
141 //=============================================================================
142 std::string HOMARD_Cas::GetDirName() const
143 {
144   return _NomDir;
145 }
146 //=============================================================================
147 int HOMARD_Cas::GetNumberofIter()
148 {
149   return _ListIter.size();
150 }
151 //=============================================================================
152 void HOMARD_Cas::SetConfType( int Conftype )
153 {
154   _ConfType = Conftype;
155 }
156 //=============================================================================
157 const int HOMARD_Cas::GetConfType() const
158 {
159   return _ConfType;
160 }
161 //
162 // La boite englobante
163 //
164 //=============================================================================
165 void HOMARD_Cas::SetBoundingBox( const std::vector<double>& extremas )
166 {
167   _Boite.clear();
168   _Boite.resize( extremas.size() );
169   for ( int i = 0; i < extremas.size(); i++ )
170     _Boite[i] = extremas[i];
171 }
172 //=============================================================================
173 const std::vector<double>& HOMARD_Cas::GetBoundingBox() const
174 {
175   return _Boite;
176 }
177 //
178 // Les groupes
179 //
180 //=============================================================================
181 void HOMARD_Cas::AddGroup( const char* Group )
182 {
183   _ListGroup.push_back(Group);
184 }
185 //=============================================================================
186 void HOMARD_Cas::SetGroups( const std::list<std::string>& ListGroup )
187 {
188   _ListGroup.clear();
189   std::list<std::string>::const_iterator it = ListGroup.begin();
190   while(it != ListGroup.end())
191   {
192     _ListGroup.push_back((*it++));
193   }
194 }
195 //=============================================================================
196 const std::list<std::string>& HOMARD_Cas::GetGroups() const
197 {
198   return _ListGroup;
199 }
200 //=============================================================================
201 void HOMARD_Cas::SupprGroups()
202 {
203   _ListGroup.clear();
204 }
205 //
206 // Les frontieres
207 //
208 //=============================================================================
209 void HOMARD_Cas::AddBoundaryGroup( const char* Boundary, const char* Group )
210 {
211   _ListBoundaryGroup.push_back( Boundary );
212   _ListBoundaryGroup.push_back( Group    );
213 }
214 //=============================================================================
215 const std::list<std::string>& HOMARD_Cas::GetBoundaryGroup() const
216 {
217   return _ListBoundaryGroup;
218 }
219 //=============================================================================
220 void HOMARD_Cas::SupprBoundaryGroup()
221 {
222   _ListBoundaryGroup.clear();
223 }
224 //=============================================================================
225 void HOMARD_Cas::SetPyram( int Pyram )
226 {
227   _Pyram = Pyram;
228 }
229 //=============================================================================
230 const int HOMARD_Cas::GetPyram() const
231 {
232   return _Pyram;
233 }
234 //=============================================================================
235 //=============================================================================
236 // Liens avec les autres structures
237 //=============================================================================
238 //=============================================================================
239 std::string HOMARD_Cas::GetIter0Name() const
240 {
241 // Par construction de la liste, l'iteration a ete mise en tete.
242   return (*(_ListIter.begin()));
243 }
244 //=============================================================================
245 void HOMARD_Cas::AddIteration( const char* NomIteration )
246 {
247   _ListIter.push_back( std::string( NomIteration ) );
248 }
249 //=============================================================================
250 const std::list<std::string>& HOMARD_Cas::GetIterations() const
251 {
252   return _ListIter;
253 }
254 //=============================================================================
255 void HOMARD_Cas::SupprIterations()
256 {
257   _ListIter.clear();
258 }
259
260