Salome HOME
1493c8ff16dc7d6312da3ef5f888906b96299cbe
[modules/homard.git] / src / HOMARD / HOMARD_Cas.cxx
1 //  HOMARD HOMARD : implementation of HOMARD idl descriptions
2 //
3 // Copyright (C) 2011-2020  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, or (at your option) any later version.
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 : Gerald NICOLAS, 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 "HOMARD.hxx"
37 #include <iostream>
38 #include <sys/stat.h>
39
40 #ifndef WIN32
41 #include <unistd.h>
42 #else
43 #include <direct.h>
44 #endif
45
46 //=============================================================================
47 /*!
48  *  default constructor:
49  *  Par defaut, l'adaptation est conforme, sans suivi de frontiere
50  */
51 //=============================================================================
52 HOMARD_Cas::HOMARD_Cas():
53   _Name(""), _NomDir("/tmp"), _ConfType(0), _ExtType(0)
54 {
55   MESSAGE("HOMARD_Cas");
56 }
57 //=============================================================================
58 HOMARD_Cas::~HOMARD_Cas()
59 //=============================================================================
60 {
61   MESSAGE("~HOMARD_Cas");
62 }
63 //=============================================================================
64 //=============================================================================
65 // Generalites
66 //=============================================================================
67 //=============================================================================
68 void HOMARD_Cas::SetName( const char* Name )
69 {
70   _Name = std::string( Name );
71 }
72 //=============================================================================
73 std::string HOMARD_Cas::GetName() const
74 {
75   return _Name;
76 }
77 //=============================================================================
78 std::string HOMARD_Cas::GetDumpPython() const
79 {
80   std::ostringstream aScript;
81   aScript << "\t" <<_Name << ".SetDirName(\"";
82   aScript << _NomDir << "\")\n";
83   aScript << "\t" <<_Name << ".SetConfType(";
84   aScript << _ConfType << ")\n";
85   aScript << "\t" <<_Name << ".SetExtType(";
86   aScript << _ExtType << ")\n";
87 // Suivi de frontieres
88   std::list<std::string>::const_iterator it = _ListBoundaryGroup.begin();
89   while(it != _ListBoundaryGroup.end())
90   {
91     aScript << "\t" <<_Name << ".AddBoundaryGroup(\"";
92     aScript << *it << "\", \"";
93     it++;
94     aScript << *it << "\")\n";
95     it++;
96   }
97   if ( _Pyram > 0 )
98   {
99     aScript << "\t" <<_Name << ".SetPyram(";
100     aScript << _Pyram << ")\n";
101   }
102
103   return aScript.str();
104 }
105 //=============================================================================
106 //=============================================================================
107 // Caracteristiques
108 //=============================================================================
109 //=============================================================================
110 int HOMARD_Cas::SetDirName( const char* NomDir )
111 {
112 //   MESSAGE("SetDirName,  NomDir : "<<NomDir);
113 //   MESSAGE("SetDirName, _NomDir : "<<_NomDir);
114   int erreur = 0 ;
115   // On vĂ©rifie qu'aucun calcul n'a eu lieu pour ce cas
116 //   MESSAGE("SetDirName, _ListIter.size() : "<<_ListIter.size());
117   if ( _ListIter.size() > 1 ) { erreur = 1 ; }
118   // Creation
119   if ( CHDIR(NomDir) == 0 )
120   { _NomDir = std::string( NomDir ); }
121   else
122   {
123
124 #ifndef WIN32
125     if ( mkdir(NomDir, S_IRWXU|S_IRGRP|S_IXGRP) == 0 )
126 #else
127     if ( _mkdir(NomDir) == 0 )
128 #endif
129     {
130       if ( CHDIR(NomDir) == 0 ) { _NomDir = std::string( NomDir ); }
131       else                      { erreur = 2 ; }
132     }
133     else { erreur = 2 ; }
134   };
135   return erreur ;
136 }
137 //=============================================================================
138 std::string HOMARD_Cas::GetDirName() const
139 {
140   return _NomDir;
141 }
142 //=============================================================================
143 int HOMARD_Cas::GetNumberofIter()
144 {
145   return _ListIter.size();
146 }
147 //
148 // Le type de conformite ou non conformite
149 //
150 //=============================================================================
151 void HOMARD_Cas::SetConfType( int Conftype )
152 {
153 //   VERIFICATION( (Conftype>=-2) && (Conftype<=3) );
154   _ConfType = Conftype;
155 }
156 //=============================================================================
157 const int HOMARD_Cas::GetConfType() const
158 {
159   return _ConfType;
160 }
161 //
162 // Le type exterieur
163 //
164 //=============================================================================
165 void HOMARD_Cas::SetExtType( int ExtType )
166 {
167 //   VERIFICATION( (ExtType>=0) && (ExtType<=2) );
168   _ExtType = ExtType;
169 }
170 //=============================================================================
171 const int HOMARD_Cas::GetExtType() const
172 {
173   return _ExtType;
174 }
175 //
176 // La boite englobante
177 //
178 //=============================================================================
179 void HOMARD_Cas::SetBoundingBox( const std::vector<double>& extremas )
180 {
181   _Boite.clear();
182   _Boite.resize( extremas.size() );
183   for ( int i = 0; i < extremas.size(); i++ )
184     _Boite[i] = extremas[i];
185 }
186 //=============================================================================
187 const std::vector<double>& HOMARD_Cas::GetBoundingBox() const
188 {
189   return _Boite;
190 }
191 //
192 // Les groupes
193 //
194 //=============================================================================
195 void HOMARD_Cas::AddGroup( const char* Group )
196 {
197   _ListGroup.push_back(Group);
198 }
199 //=============================================================================
200 void HOMARD_Cas::SetGroups( const std::list<std::string>& ListGroup )
201 {
202   _ListGroup.clear();
203   std::list<std::string>::const_iterator it = ListGroup.begin();
204   while(it != ListGroup.end())
205   {
206     _ListGroup.push_back((*it++));
207   }
208 }
209 //=============================================================================
210 const std::list<std::string>& HOMARD_Cas::GetGroups() const
211 {
212   return _ListGroup;
213 }
214 //=============================================================================
215 void HOMARD_Cas::SupprGroups()
216 {
217   _ListGroup.clear();
218 }
219 //
220 // Les frontieres
221 //
222 //=============================================================================
223 void HOMARD_Cas::AddBoundary( const char* Boundary )
224 {
225 //   MESSAGE ( ". HOMARD_Cas::AddBoundary : Boundary = " << Boundary );
226   const char* Group = "";
227   AddBoundaryGroup( Boundary, Group );
228 }
229 //=============================================================================
230 void HOMARD_Cas::AddBoundaryGroup( const char* Boundary, const char* Group )
231 {
232 //   MESSAGE ( ". HOMARD_Cas::AddBoundaryGroup : Boundary = " << Boundary );
233 //   MESSAGE ( ". HOMARD_Cas::AddBoundaryGroup : Group = " << Group );
234   _ListBoundaryGroup.push_back( Boundary );
235   _ListBoundaryGroup.push_back( Group    );
236 }
237 //=============================================================================
238 const std::list<std::string>& HOMARD_Cas::GetBoundaryGroup() const
239 {
240   return _ListBoundaryGroup;
241 }
242 //=============================================================================
243 void HOMARD_Cas::SupprBoundaryGroup()
244 {
245   _ListBoundaryGroup.clear();
246 }
247 //=============================================================================
248 void HOMARD_Cas::SetPyram( int Pyram )
249 {
250   _Pyram = Pyram;
251 }
252 //=============================================================================
253 const int HOMARD_Cas::GetPyram() const
254 {
255   return _Pyram;
256 }
257 //=============================================================================
258 //=============================================================================
259 // Liens avec les autres structures
260 //=============================================================================
261 //=============================================================================
262 std::string HOMARD_Cas::GetIter0Name() const
263 {
264 // Par construction de la liste, l'iteration a ete mise en tete.
265   return (*(_ListIter.begin()));
266 }
267 //=============================================================================
268 void HOMARD_Cas::AddIteration( const char* NomIteration )
269 {
270   _ListIter.push_back( std::string( NomIteration ) );
271 }
272 //=============================================================================
273 const std::list<std::string>& HOMARD_Cas::GetIterations() const
274 {
275   return _ListIter;
276 }
277 //=============================================================================
278 void HOMARD_Cas::SupprIterations()
279 {
280   _ListIter.clear();
281 }
282
283