Salome HOME
integration of modifications from Gérald Nicolas
[modules/homard.git] / src / HOMARD_I / HOMARD_Cas_i.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 #include "HOMARD_Cas_i.hxx"
21 #include "HOMARD_Gen_i.hxx"
22 #include "HOMARD_Cas.hxx"
23 #include "HOMARD_DriverTools.hxx"
24
25 #include "utilities.h"
26 #include <vector>
27
28 //=============================================================================
29 /*!
30  *  standard constructor
31  */
32 //=============================================================================
33 HOMARD_Cas_i::HOMARD_Cas_i()
34 {
35   MESSAGE( "Default constructor, not for use" );
36   ASSERT( 0 );
37 }
38
39 //=============================================================================
40 /*!
41  *  standard constructor
42  */
43 //=============================================================================
44 HOMARD_Cas_i::HOMARD_Cas_i( CORBA::ORB_ptr orb,
45                             HOMARD::HOMARD_Gen_var engine )
46 {
47   MESSAGE( "HOMARD_Cas_i" );
48   _gen_i = engine;
49   _orb = orb;
50   myHomardCas = new ::HOMARD_Cas();
51   ASSERT( myHomardCas );
52 }
53
54 //=============================================================================
55 /*!
56  *  standard destructor
57  */
58 //=============================================================================
59 HOMARD_Cas_i::~HOMARD_Cas_i()
60 {
61 }
62
63 //=============================================================================
64 /*!
65  */
66 //=============================================================================
67 void HOMARD_Cas_i::SetDirName( const char* NomDir )
68 {
69   ASSERT( myHomardCas );
70   myHomardCas->SetDirName( NomDir );
71 }
72
73 //=============================================================================
74 /*!
75  */
76 //=============================================================================
77 void HOMARD_Cas_i::SetName( const char* Name )
78 {
79   ASSERT( myHomardCas );
80   myHomardCas->SetName( Name );
81 }
82
83 //=============================================================================
84 /*!
85  */
86 //=============================================================================
87 char* HOMARD_Cas_i::GetName()
88 {
89   ASSERT( myHomardCas );
90   return CORBA::string_dup( myHomardCas->GetName().c_str() );
91 }
92
93 //=============================================================================
94 /*!
95  */
96 //=============================================================================
97 char* HOMARD_Cas_i::GetDumpPython()
98 {
99   ASSERT( myHomardCas );
100   return CORBA::string_dup( myHomardCas->GetDumpPython().c_str() );
101 }
102
103 //=============================================================================
104 char* HOMARD_Cas_i::GetDirName()
105 {
106   ASSERT( myHomardCas );
107   return CORBA::string_dup( myHomardCas->GetDirName().c_str() );
108 }
109
110 //=============================================================================
111 void HOMARD_Cas_i::SetConfType( CORBA::Long ConfType )
112 {
113   ASSERT( myHomardCas );
114   myHomardCas->SetConfType( ConfType );
115 }
116 //=============================================================================
117 CORBA::Long HOMARD_Cas_i::GetNumber()
118 {
119   ASSERT( myHomardCas );
120   return myHomardCas->GetNumber();
121 }
122
123 //=============================================================================
124 CORBA::Long HOMARD_Cas_i::GetConfType()
125 {
126   ASSERT( myHomardCas );
127   return myHomardCas->GetConfType();
128 }
129
130 //=============================================================================
131 char* HOMARD_Cas_i::GetIter0Name()
132 {
133   ASSERT( myHomardCas );
134   return CORBA::string_dup( myHomardCas->GetIter0Name().c_str() );
135 }
136 //=============================================================================
137 HOMARD::HOMARD_Iteration_ptr HOMARD_Cas_i::GetIter0()
138 {
139 // Nom de l'iteration parent
140   char* Iter0Name = GetIter0Name() ;
141   MESSAGE ( "GetIter0 : Iter0Name      = " << Iter0Name );
142 // On passe par la methode sur l'objet HOMARD
143 // Il serait plus elegant de tout faire ici, mais il est complexe de passer tout le contexte
144   return _gen_i->GetIteration(Iter0Name) ;
145 }
146
147 //=============================================================================
148 HOMARD::HOMARD_Iteration_ptr HOMARD_Cas_i::NextIteration( const char* IterName )
149 {
150 // Nom de l'iteration parent
151   char* NomIterParent = GetIter0Name() ;
152   MESSAGE ( "NextIteration : IterName      = " << IterName );
153   MESSAGE ( "NextIteration : NomIterParent = " << NomIterParent );
154 // On passe par la methode sur l'objet HOMARD
155 // Il serait plus elegant de tout faire ici, mais il est complexe de passer tout le contexte
156   return _gen_i->CreateIteration(IterName, NomIterParent) ;
157 }
158
159 //=============================================================================
160 void HOMARD_Cas_i::AddIteration( const char* NomIteration )
161 {
162   ASSERT( myHomardCas );
163   myHomardCas->AddIteration( NomIteration );
164 }
165 //=============================================================================
166 HOMARD::extrema* HOMARD_Cas_i::GetBoundingBox()
167 {
168   ASSERT(myHomardCas );
169   HOMARD::extrema_var aResult = new HOMARD::extrema();
170   std::vector<double> LesExtremes = myHomardCas->GetBoundingBox();
171   ASSERT( LesExtremes.size() == 10 );
172   aResult->length( 10 );
173   for ( int i = 0; i < LesExtremes.size(); i++ )
174   {
175     aResult[i] = LesExtremes[i];
176   }
177   return aResult._retn();
178 }
179 //=============================================================================
180 void HOMARD_Cas_i::SetBoundingBox( const HOMARD::extrema& LesExtrema )
181 {
182   ASSERT( myHomardCas );
183   std::vector<double> VExtrema;
184   ASSERT( LesExtrema.length() == 10 );
185   VExtrema.resize( LesExtrema.length() );
186   for ( int i = 0; i < LesExtrema.length(); i++ )
187   {
188     VExtrema[i] = LesExtrema[i];
189   }
190
191   myHomardCas->SetBoundingBox( VExtrema );
192 }
193 //=============================================================================
194 void HOMARD_Cas_i::AddGroup( const char* Group)
195 {
196   ASSERT( myHomardCas );
197   myHomardCas->AddGroup( Group );
198 }
199 //=============================================================================
200 void HOMARD_Cas_i::SetGroups( const HOMARD::ListGroupType& ListGroup )
201 {
202   ASSERT( myHomardCas );
203   std::list<std::string> ListString ;
204   for ( int i = 0; i < ListGroup.length(); i++ )
205   {
206     ListString.push_back(std::string(ListGroup[i]));
207   }
208
209   myHomardCas->SetGroups( ListString );
210 }
211 //=============================================================================
212 HOMARD::ListGroupType* HOMARD_Cas_i::GetGroups()
213 {
214   ASSERT(myHomardCas );
215   const std::list<std::string>& ListString = myHomardCas->GetGroups();
216   HOMARD::ListGroupType_var aResult = new HOMARD::ListGroupType();
217   aResult->length( ListString.size() );
218   std::list<std::string>::const_iterator it;
219   int i = 0;
220   for ( it = ListString.begin(); it != ListString.end(); it++ )
221   {
222     aResult[i++] = CORBA::string_dup( (*it).c_str() );
223   }
224   return aResult._retn();
225 }
226
227 //=============================================================================
228 void HOMARD_Cas_i::AddBoundaryGroup( const char* Boundary, const char* Group)
229 {
230   MESSAGE ("AddBoundaryGroup");
231   ASSERT( myHomardCas );
232   myHomardCas->AddBoundaryGroup( Boundary, Group );
233 }
234 //=============================================================================
235 HOMARD::ListBoundaryGroupType* HOMARD_Cas_i::GetBoundaryGroup()
236 {
237   MESSAGE ("GetBoundaryGroup");
238   ASSERT(myHomardCas );
239   const std::list<std::string>& ListString = myHomardCas->GetBoundaryGroup();
240   HOMARD::ListBoundaryGroupType_var aResult = new HOMARD::ListBoundaryGroupType();
241   aResult->length( ListString.size() );
242   std::list<std::string>::const_iterator it;
243   int i = 0;
244   for ( it = ListString.begin(); it != ListString.end(); it++ )
245   {
246     aResult[i++] = CORBA::string_dup( (*it).c_str() );
247   }
248   return aResult._retn();
249 }
250
251 //=============================================================================
252 void HOMARD_Cas_i::SetPyram( CORBA::Long Pyram )
253 {
254   MESSAGE ("SetPyram, Pyram = " << Pyram );
255   ASSERT( myHomardCas );
256   myHomardCas->SetPyram( Pyram );
257 }
258 //=============================================================================
259 CORBA::Long HOMARD_Cas_i::GetPyram()
260 {
261   MESSAGE ("GetPyram");
262   ASSERT( myHomardCas );
263   return myHomardCas->GetPyram();
264 }
265 //=============================================================================
266 std::string HOMARD_Cas_i::Dump() const
267 {
268   return HOMARD::Dump( *myHomardCas );
269 }
270
271 //=============================================================================
272 bool HOMARD_Cas_i::Restore( const std::string& stream )
273 {
274   return HOMARD::Restore( *myHomardCas, stream );
275 }