Salome HOME
Revert "Synchronize adm files"
[modules/homard.git] / src / HOMARD / HOMARD_Cas.cxx
1 //  HOMARD HOMARD : implementation of HOMARD idl descriptions
2 //
3 // Copyright (C) 2011-2014  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 : 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 "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(1)
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 // Suivi de frontieres
86   std::list<std::string>::const_iterator it = _ListBoundaryGroup.begin();
87   while(it != _ListBoundaryGroup.end())
88   {
89     aScript << "\t" <<_Name << ".AddBoundaryGroup(\"";
90     aScript << *it << "\", \"";
91     it++;
92     aScript << *it << "\")\n";
93     it++;
94   }
95   if ( _Pyram > 0 )
96   {
97     aScript << "\t" <<_Name << ".SetPyram(";
98     aScript << _Pyram << ")\n";
99   }
100
101   return aScript.str();
102 }
103 //=============================================================================
104 //=============================================================================
105 // Caracteristiques
106 //=============================================================================
107 //=============================================================================
108 int HOMARD_Cas::SetDirName( const char* NomDir )
109 {
110   MESSAGE("SetDirName,  NomDir : "<<NomDir);
111   MESSAGE("SetDirName, _NomDir : "<<_NomDir);
112   int erreur = 0 ;
113   // On vĂ©rifie qu'aucun calcul n'a eu lieu pour ce cas
114   MESSAGE("SetDirName, _ListIter.size() : "<<_ListIter.size());
115   if ( _ListIter.size() > 1 ) { erreur = 1 ; }
116   // Creation
117   if ( CHDIR(NomDir) == 0 )
118   { _NomDir = std::string( NomDir ); }
119   else
120   {
121
122 #ifndef WIN32
123     if ( mkdir(NomDir, S_IRWXU|S_IRGRP|S_IXGRP) == 0 )
124 #else
125     if ( _mkdir(NomDir) == 0 )
126 #endif
127     {
128       if ( CHDIR(NomDir) == 0 ) { _NomDir = std::string( NomDir ); }
129       else                      { erreur = 2 ; }
130     }
131     else { erreur = 2 ; }
132   };
133   return erreur ;
134 }
135 //=============================================================================
136 std::string HOMARD_Cas::GetDirName() const
137 {
138   return _NomDir;
139 }
140 //=============================================================================
141 int HOMARD_Cas::GetNumberofIter()
142 {
143   return _ListIter.size();
144 }
145 //=============================================================================
146 void HOMARD_Cas::SetConfType( int Conftype )
147 {
148 //   VERIFICATION( (Conftype>=1) && (Conftype<=4) );
149   _ConfType = Conftype;
150 }
151 //=============================================================================
152 const int HOMARD_Cas::GetConfType() const
153 {
154   return _ConfType;
155 }
156 //
157 // La boite englobante
158 //
159 //=============================================================================
160 void HOMARD_Cas::SetBoundingBox( const std::vector<double>& extremas )
161 {
162   _Boite.clear();
163   _Boite.resize( extremas.size() );
164   for ( int i = 0; i < extremas.size(); i++ )
165     _Boite[i] = extremas[i];
166 }
167 //=============================================================================
168 const std::vector<double>& HOMARD_Cas::GetBoundingBox() const
169 {
170   return _Boite;
171 }
172 //
173 // Les groupes
174 //
175 //=============================================================================
176 void HOMARD_Cas::AddGroup( const char* Group )
177 {
178   _ListGroup.push_back(Group);
179 }
180 //=============================================================================
181 void HOMARD_Cas::SetGroups( const std::list<std::string>& ListGroup )
182 {
183   _ListGroup.clear();
184   std::list<std::string>::const_iterator it = ListGroup.begin();
185   while(it != ListGroup.end())
186   {
187     _ListGroup.push_back((*it++));
188   }
189 }
190 //=============================================================================
191 const std::list<std::string>& HOMARD_Cas::GetGroups() const
192 {
193   return _ListGroup;
194 }
195 //=============================================================================
196 void HOMARD_Cas::SupprGroups()
197 {
198   _ListGroup.clear();
199 }
200 //
201 // Les frontieres
202 //
203 //=============================================================================
204 void HOMARD_Cas::AddBoundaryGroup( const char* Boundary, const char* Group )
205 {
206 //  MESSAGE ( ". AddBoundaryGroup : Boundary = " << Boundary );
207 //   MESSAGE ( ". AddBoundaryGroup : Group = " << Group );
208   _ListBoundaryGroup.push_back( Boundary );
209   _ListBoundaryGroup.push_back( Group    );
210 }
211 //=============================================================================
212 const std::list<std::string>& HOMARD_Cas::GetBoundaryGroup() const
213 {
214   return _ListBoundaryGroup;
215 }
216 //=============================================================================
217 void HOMARD_Cas::SupprBoundaryGroup()
218 {
219   _ListBoundaryGroup.clear();
220 }
221 //=============================================================================
222 void HOMARD_Cas::SetPyram( int Pyram )
223 {
224   _Pyram = Pyram;
225 }
226 //=============================================================================
227 const int HOMARD_Cas::GetPyram() const
228 {
229   return _Pyram;
230 }
231 //=============================================================================
232 //=============================================================================
233 // Liens avec les autres structures
234 //=============================================================================
235 //=============================================================================
236 std::string HOMARD_Cas::GetIter0Name() const
237 {
238 // Par construction de la liste, l'iteration a ete mise en tete.
239   return (*(_ListIter.begin()));
240 }
241 //=============================================================================
242 void HOMARD_Cas::AddIteration( const char* NomIteration )
243 {
244   _ListIter.push_back( std::string( NomIteration ) );
245 }
246 //=============================================================================
247 const std::list<std::string>& HOMARD_Cas::GetIterations() const
248 {
249   return _ListIter;
250 }
251 //=============================================================================
252 void HOMARD_Cas::SupprIterations()
253 {
254   _ListIter.clear();
255 }
256
257