Salome HOME
updated copyright message
[modules/geom.git] / src / GEOM_I / GEOM_Field_i.cc
1 // Copyright (C) 2007-2023  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License, or (at your option) any later version.
10 //
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 // Lesser General Public License for more details.
15 //
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 //
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22
23 #include "GEOM_Field_i.hh"
24
25 #include <utilities.h>
26
27 #include <TCollection_ExtendedString.hxx>
28 #include <TColStd_HArray1OfReal.hxx>
29
30 #ifdef WIN32
31 #pragma warning( disable:4786 )
32 #endif
33
34 //=============================================================================
35 /*!
36  *   constructor:
37  */
38 //=============================================================================
39
40 GEOM_Field_i::GEOM_Field_i (PortableServer::POA_ptr thePOA,
41                             GEOM::GEOM_Gen_ptr      theEngine,
42                             Handle(::GEOM_Field)      theImpl):
43   SALOME::GenericObj_i( thePOA ),
44   GEOM_BaseObject_i( thePOA, theEngine, theImpl ),
45   _impl( theImpl )
46 {
47 }
48
49 //=============================================================================
50 /*!
51  *  destructor
52  */
53 //=============================================================================
54
55 GEOM_Field_i::~GEOM_Field_i()
56 {
57   MESSAGE("GEOM_Field_i::~GEOM_Field_i");
58 }
59
60 //================================================================================
61 /*!
62  * \brief Returns the shape the field lies on
63  */
64 //================================================================================
65
66 GEOM::GEOM_Object_ptr GEOM_Field_i::GetShape()
67 {
68   GEOM::GEOM_Object_var shapeVar;
69   Handle(::GEOM_Object) shape = _impl->GetShape();
70   if ( !shape.IsNull() )
71   {
72     GEOM::GEOM_BaseObject_var obj = _engine->GetObject( shape->GetEntryString().ToCString());
73     shapeVar = GEOM::GEOM_Object::_narrow( obj );
74   }
75   return shapeVar._retn();
76 }
77
78 //================================================================================
79 /*!
80  * \brief Returns type of field data
81  */
82 //================================================================================
83
84 GEOM::field_data_type GEOM_Field_i::GetDataType()
85 {
86   return GEOM::field_data_type( _impl->GetDataType() );
87 }
88
89 //================================================================================
90 /*!
91  * \brief Returns dimension of the shape the field lies on
92  *  0 - VERTEX, 1 - EDGE, 2 - FACE, 3 - SOLID, -1 - whole shape
93  */
94 //================================================================================
95
96 CORBA::Short GEOM_Field_i::GetDimension()
97 {
98   return CORBA::Short( _impl->GetDimension() );
99 }
100
101 //================================================================================
102 /*!
103  * \brief Returns names of components
104  */
105 //================================================================================
106
107 GEOM::string_array* GEOM_Field_i::GetComponents()
108 {
109   GEOM::string_array_var compArr = new GEOM::string_array;
110   Handle(TColStd_HArray1OfExtendedString) comps = _impl->GetComponents();
111   if ( !comps.IsNull() )
112   {
113     compArr->length( comps->Length() );
114     std::string entry;
115     int i, i0, nb; 
116     for ( i = i0 = comps->Lower(), nb = comps->Upper(); i <= nb; ++i )
117     {
118       const TCollection_ExtendedString& anEntry = comps->Value( i );
119       entry.resize( anEntry.LengthOfCString() );
120       char* pstr = &entry[0];
121       anEntry.ToUTF8CString( pstr );
122       compArr[ i-i0 ] = CORBA::string_dup( entry.c_str() );
123     }
124   }
125   return compArr._retn();
126 }
127
128 //================================================================================
129 /*!
130  * \brief Adds a time step to the field
131  */
132 //================================================================================
133
134 GEOM::GEOM_FieldStep_ptr GEOM_Field_i::AddStep(::CORBA::Long stepID, ::CORBA::Long stamp)
135 {
136   GEOM::GEOM_FieldStep_var stepVar;
137   Handle(::GEOM_FieldStep) step = _impl->AddStep( stepID, stamp );
138   if ( !step.IsNull() )
139   {
140     GEOM::GEOM_BaseObject_var obj = _engine->GetObject( step->GetEntryString().ToCString());
141     stepVar = GEOM::GEOM_FieldStep::_narrow( obj );
142   }
143   return stepVar._retn();
144 }
145
146 //================================================================================
147 /*!
148  * \brief Remove a time step from the field
149  */
150 //================================================================================
151
152 void GEOM_Field_i::RemoveStep(::CORBA::Long stepID)
153 {
154   _impl->RemoveStep( stepID );
155 }
156
157 //================================================================================
158 /*!
159  * \brief Returns number of time steps in the field
160  */
161 //================================================================================
162
163 CORBA::Long GEOM_Field_i::CountSteps()
164 {
165   return (CORBA::Long) _impl->GetSteps().size();
166 }
167
168 //================================================================================
169 /*!
170  * \brief Returns a list of time step IDs in the field
171  */
172 //================================================================================
173
174 GEOM::ListOfLong* GEOM_Field_i::GetSteps()
175 {
176   std::list< Handle(::GEOM_FieldStep)> stepList = _impl->GetSteps();
177   std::list< Handle(::GEOM_FieldStep)>::iterator stp = stepList.begin();
178   
179   GEOM::ListOfLong_var stepIds = new GEOM::ListOfLong();
180   stepIds->length( stepList.size() );
181   int nbS = 0;
182   for ( ; stp != stepList.end(); ++stp )
183     if ( !stp->IsNull() )
184       stepIds[ nbS++ ] = (*stp)->GetID();
185
186   stepIds->length( nbS );
187   return stepIds._retn();
188 }
189
190 //================================================================================
191 /*!
192  * \brief Returns a time step by its ID
193  */
194 //================================================================================
195
196 GEOM::GEOM_FieldStep_ptr GEOM_Field_i::GetStep(CORBA::Long stepID)
197 {
198   GEOM::GEOM_FieldStep_var stepVar;
199   Handle(::GEOM_FieldStep) step = _impl->GetStep(stepID);
200   if ( !step.IsNull() )
201   {
202     GEOM::GEOM_BaseObject_var obj = _engine->GetObject( step->GetEntryString().ToCString());
203     stepVar = GEOM::GEOM_FieldStep::_narrow( obj );
204   }
205   return stepVar._retn();
206 }
207
208 //================================================================================
209 /*!
210  *  \brief Returns a size of data array that is to be passed to
211  *         GEOM_FieldStep.SetValues( dataArray ). This size depends on the
212  *         number of sub-shapes of field dimension and the number of components
213  */
214 //================================================================================
215
216 CORBA::Long GEOM_Field_i::GetArraySize()
217 {
218   return (CORBA::Long) _impl->GetArrayLength();
219 }
220
221 //================================================================================
222 /*!
223  * \brief Constructor of base step class
224  */
225 //================================================================================
226
227 GEOM_FieldStep_i::GEOM_FieldStep_i(PortableServer::POA_ptr  thePOA,
228                                    GEOM::GEOM_Gen_ptr       theEngine,
229                                    Handle(::GEOM_FieldStep)   theImpl):
230   SALOME::GenericObj_i( thePOA ),
231   GEOM_BaseObject_i( thePOA, theEngine, theImpl ),
232   _impl( theImpl )
233 {
234 }
235
236 //================================================================================
237 /*!
238  * \brief Destructor
239  */
240 //================================================================================
241
242 GEOM_FieldStep_i::~GEOM_FieldStep_i()
243 {
244 }
245
246 //================================================================================
247 /*!
248  * \brief Changes the stamp of the field step
249  */
250 //================================================================================
251
252 void GEOM_FieldStep_i::SetStamp(::CORBA::Long stamp)
253 {
254   _impl->SetStamp( stamp );
255 }
256
257 //================================================================================
258 /*!
259  * \brief Returns the time of the field step
260  */
261 //================================================================================
262
263 ::CORBA::Long GEOM_FieldStep_i::GetStamp()
264 {
265   return (CORBA::Long) _impl->GetStamp();
266 }
267
268 //================================================================================
269 /*!
270  * \brief Returns the number of the field step
271  */
272 //================================================================================
273
274 ::CORBA::Long GEOM_FieldStep_i::GetID()
275 {
276   return (CORBA::Long) _impl->GetID();
277 }
278
279 //================================================================================
280 /*!
281  * \brief Returns the field the step belongs to
282  */
283 //================================================================================
284
285 GEOM::GEOM_Field_ptr GEOM_FieldStep_i::GetField()
286 {
287   GEOM::GEOM_Field_var fieldVar;
288   Handle(::GEOM_Field) field = _impl->GetField();
289   if ( !field.IsNull() )
290   {
291     GEOM::GEOM_BaseObject_var obj = _engine->GetObject( field->GetEntryString().ToCString());
292     fieldVar = GEOM::GEOM_Field::_narrow( obj );
293   }
294   return fieldVar._retn();
295 }
296
297 //================================================================================
298 /*!
299  * \brief Constructor of GEOM_BoolFieldStep_i
300  */
301 //================================================================================
302
303 GEOM_BoolFieldStep_i::GEOM_BoolFieldStep_i(PortableServer::POA_ptr thePOA, GEOM::GEOM_Gen_ptr theEngine, Handle(::GEOM_FieldStep) theImpl):
304   SALOME::GenericObj_i( thePOA ),
305   GEOM_BaseObject_i( thePOA, theEngine, theImpl ),
306   GEOM_FieldStep_i( thePOA, theEngine, theImpl )
307 {
308 }
309
310 //================================================================================
311 /*!
312  * \brief Changes values of the field step. Returns false if number of values is wrong
313  */
314 //================================================================================
315
316 ::CORBA::Boolean GEOM_BoolFieldStep_i::SetValues(const ::GEOM::short_array& boolValues)
317 {
318   Handle(TColStd_HArray1OfInteger) values =
319     new TColStd_HArray1OfInteger( 0, boolValues.length()-1 );
320   for ( size_t i = 0; i < boolValues.length(); ++ i )
321     values->SetValue( i, boolValues[i] );
322
323   return _impl->SetValues( values );
324 }
325
326 //================================================================================
327 /*!
328  * \brief Returns values of the field step
329  */
330 //================================================================================
331
332 GEOM::short_array* GEOM_BoolFieldStep_i::GetValues()
333 {
334   GEOM::short_array_var resArray = new GEOM::short_array;
335
336   Handle(TColStd_HArray1OfInteger) values = GEOM_FieldStep_i::_impl->GetIntValues();
337   if ( !values.IsNull() )
338   {
339     resArray->length( values->Length() );
340     int i, i0, nb; 
341     for ( i = i0 = values->Lower(), nb = values->Upper(); i <= nb; ++i )
342       resArray[ i-i0 ] = values->Value( i );
343   }
344   return resArray._retn();
345 }
346
347
348 //================================================================================
349 /*!
350  * \brief Constructor of GEOM_IntFieldStep_i
351  */
352 //================================================================================
353
354 GEOM_IntFieldStep_i::GEOM_IntFieldStep_i(PortableServer::POA_ptr thePOA, GEOM::GEOM_Gen_ptr theEngine, Handle(::GEOM_FieldStep) theImpl):
355   SALOME::GenericObj_i( thePOA ),
356   GEOM_BaseObject_i( thePOA, theEngine, theImpl ),
357   GEOM_FieldStep_i( thePOA, theEngine, theImpl )
358 {
359 }
360
361 //================================================================================
362 /*!
363  * \brief Changes values of the field step. Returns false if number of values is wrong
364  */
365 //================================================================================
366
367 ::CORBA::Boolean GEOM_IntFieldStep_i::SetValues(const ::GEOM::ListOfLong& intValues)
368 {
369   Handle(TColStd_HArray1OfInteger) values =
370     new TColStd_HArray1OfInteger( 0, intValues.length()-1 );
371   for ( size_t i = 0; i < intValues.length(); ++ i )
372     values->SetValue( i, intValues[i] );
373
374   return _impl->SetValues( values );
375 }
376
377 //================================================================================
378 /*!
379  * \brief Returns values of the field step
380  */
381 //================================================================================
382
383 GEOM::ListOfLong* GEOM_IntFieldStep_i::GetValues()
384 {
385   GEOM::ListOfLong_var resArray = new GEOM::ListOfLong;
386
387   Handle(TColStd_HArray1OfInteger) values = GEOM_FieldStep_i::_impl->GetIntValues();
388   if ( !values.IsNull() )
389   {
390     resArray->length( values->Length() );
391     int i, i0, nb; 
392     for ( i = i0 = values->Lower(), nb = values->Upper(); i <= nb; ++i )
393       resArray[ i-i0 ] = values->Value( i );
394   }
395   return resArray._retn();
396 }
397
398
399 //================================================================================
400 /*!
401  * \brief Constructor of GEOM_DoubleFieldStep_i
402  */
403 //================================================================================
404
405 GEOM_DoubleFieldStep_i::GEOM_DoubleFieldStep_i(PortableServer::POA_ptr thePOA, GEOM::GEOM_Gen_ptr theEngine, Handle(::GEOM_FieldStep) theImpl):
406   SALOME::GenericObj_i( thePOA ),
407   GEOM_BaseObject_i( thePOA, theEngine, theImpl ),
408   GEOM_FieldStep_i( thePOA, theEngine, theImpl )
409 {
410 }
411
412 //================================================================================
413 /*!
414  * \brief Changes values of the field step. Returns false if number of values is wrong
415  */
416 //================================================================================
417
418 ::CORBA::Boolean GEOM_DoubleFieldStep_i::SetValues(const ::GEOM::ListOfDouble& dblValues)
419 {
420   Handle(TColStd_HArray1OfReal) values =
421     new TColStd_HArray1OfReal( 0, dblValues.length()-1 );
422   for ( size_t i = 0; i < dblValues.length(); ++ i )
423     values->SetValue( i, dblValues[i] );
424
425   return _impl->SetValues( values );
426 }
427
428 //================================================================================
429 /*!
430  * \brief Returns values of the field step
431  */
432 //================================================================================
433
434 GEOM::ListOfDouble* GEOM_DoubleFieldStep_i::GetValues()
435 {
436   GEOM::ListOfDouble_var resArray = new GEOM::ListOfDouble;
437
438   Handle(TColStd_HArray1OfReal) values = GEOM_FieldStep_i::_impl->GetDoubleValues();
439   if ( !values.IsNull() )
440   {
441     resArray->length( values->Length() );
442     int i, i0, nb; 
443     for ( i = i0 = values->Lower(), nb = values->Upper(); i <= nb; ++i )
444       resArray[ i-i0 ] = values->Value( i );
445   }
446   return resArray._retn();
447 }
448
449
450 //================================================================================
451 /*!
452  * \brief Constructor of GEOM_StringFieldStep_i
453  */
454 //================================================================================
455
456 GEOM_StringFieldStep_i::GEOM_StringFieldStep_i(PortableServer::POA_ptr thePOA, GEOM::GEOM_Gen_ptr theEngine, Handle(::GEOM_FieldStep) theImpl):
457   SALOME::GenericObj_i( thePOA ),
458   GEOM_BaseObject_i( thePOA, theEngine, theImpl ),
459   GEOM_FieldStep_i( thePOA, theEngine, theImpl )
460 {
461 }
462
463 //================================================================================
464 /*!
465  * \brief Changes values of the field step. Returns false if number of values is wrong
466  */
467 //================================================================================
468
469 ::CORBA::Boolean GEOM_StringFieldStep_i::SetValues(const ::GEOM::string_array& strValues)
470 {
471   Handle(TColStd_HArray1OfExtendedString) values =
472     new TColStd_HArray1OfExtendedString( 0, strValues.length()-1 );
473   for ( size_t i = 0; i < strValues.length(); ++ i )
474     values->SetValue( i, strValues[i].in() );
475
476   return _impl->SetValues( values );
477 }
478
479 //================================================================================
480 /*!
481  * \brief Returns values of the field step
482  */
483 //================================================================================
484
485 GEOM::string_array* GEOM_StringFieldStep_i::GetValues()
486 {
487   GEOM::string_array_var resArray = new GEOM::string_array;
488
489   Handle(TColStd_HArray1OfExtendedString) values = GEOM_FieldStep_i::_impl->GetStringValues();
490   if ( !values.IsNull() )
491   {
492     resArray->length( values->Length() );
493     std::string entry;
494     int i, i0, nb; 
495     for ( i = i0 = values->Lower(), nb = values->Upper(); i <= nb; ++i )
496     {
497       const TCollection_ExtendedString& anEntry = values->Value( i );
498       entry.resize( anEntry.LengthOfCString() );
499       char* pstr = &entry[0];
500       anEntry.ToUTF8CString( pstr );
501       resArray[ i-i0 ] = CORBA::string_dup( entry.c_str() );
502     }
503   }
504   return resArray._retn();
505 }
506