Salome HOME
2b500edc7d3ad6c184c2d522c99d9aeb57048cc0
[modules/geom.git] / src / GEOM_I / GEOM_Field_i.cc
1 // Copyright (C) 2007-2015  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->GetDocID(),
73                                                         shape->GetEntryString().ToCString());
74     shapeVar = GEOM::GEOM_Object::_narrow( obj );
75   }
76   return shapeVar._retn();
77 }
78
79 //================================================================================
80 /*!
81  * \brief Returns type of field data
82  */
83 //================================================================================
84
85 GEOM::field_data_type GEOM_Field_i::GetDataType()
86 {
87   return GEOM::field_data_type( _impl->GetDataType() );
88 }
89
90 //================================================================================
91 /*!
92  * \brief Returns dimension of the shape the field lies on
93  *  0 - VERTEX, 1 - EDGE, 2 - FACE, 3 - SOLID, -1 - whole shape
94  */
95 //================================================================================
96
97 CORBA::Short GEOM_Field_i::GetDimension()
98 {
99   return CORBA::Short( _impl->GetDimension() );
100 }
101
102 //================================================================================
103 /*!
104  * \brief Returns names of components
105  */
106 //================================================================================
107
108 GEOM::string_array* GEOM_Field_i::GetComponents()
109 {
110   GEOM::string_array_var compArr = new GEOM::string_array;
111   Handle(TColStd_HArray1OfExtendedString) comps = _impl->GetComponents();
112   if ( !comps.IsNull() )
113   {
114     compArr->length( comps->Length() );
115     std::string entry;
116     int i, i0, nb; 
117     for ( i = i0 = comps->Lower(), nb = comps->Upper(); i <= nb; ++i )
118     {
119       const TCollection_ExtendedString& anEntry = comps->Value( i );
120       entry.resize( anEntry.LengthOfCString() );
121       char* pstr = &entry[0];
122       anEntry.ToUTF8CString( pstr );
123       compArr[ i-i0 ] = CORBA::string_dup( entry.c_str() );
124     }
125   }
126   return compArr._retn();
127 }
128
129 //================================================================================
130 /*!
131  * \brief Adds a time step to the field
132  */
133 //================================================================================
134
135 GEOM::GEOM_FieldStep_ptr GEOM_Field_i::AddStep(::CORBA::Long stepID, ::CORBA::Long stamp)
136 {
137   GEOM::GEOM_FieldStep_var stepVar;
138   Handle(GEOM_FieldStep) step = _impl->AddStep( stepID, stamp );
139   if ( !step.IsNull() )
140   {
141     GEOM::GEOM_BaseObject_var obj = _engine->GetObject( step->GetDocID(),
142                                                         step->GetEntryString().ToCString());
143     stepVar = GEOM::GEOM_FieldStep::_narrow( obj );
144   }
145   return stepVar._retn();
146 }
147
148 //================================================================================
149 /*!
150  * \brief Remove a time step from the field
151  */
152 //================================================================================
153
154 void GEOM_Field_i::RemoveStep(::CORBA::Long stepID)
155 {
156   _impl->RemoveStep( stepID );
157 }
158
159 //================================================================================
160 /*!
161  * \brief Returns number of time steps in the field
162  */
163 //================================================================================
164
165 CORBA::Long GEOM_Field_i::CountSteps()
166 {
167   return (CORBA::Long) _impl->GetSteps().size();
168 }
169
170 //================================================================================
171 /*!
172  * \brief Returns a list of time step IDs in the field
173  */
174 //================================================================================
175
176 GEOM::ListOfLong* GEOM_Field_i::GetSteps()
177 {
178   std::list< Handle(GEOM_FieldStep)> stepList = _impl->GetSteps();
179   std::list< Handle(GEOM_FieldStep)>::iterator stp = stepList.begin();
180   
181   GEOM::ListOfLong_var stepIds = new GEOM::ListOfLong();
182   stepIds->length( stepList.size() );
183   int nbS = 0;
184   for ( ; stp != stepList.end(); ++stp )
185     if ( !stp->IsNull() )
186       stepIds[ nbS++ ] = (*stp)->GetID();
187
188   stepIds->length( nbS );
189   return stepIds._retn();
190 }
191
192 //================================================================================
193 /*!
194  * \brief Returns a time step by its ID
195  */
196 //================================================================================
197
198 GEOM::GEOM_FieldStep_ptr GEOM_Field_i::GetStep(CORBA::Long stepID)
199 {
200   GEOM::GEOM_FieldStep_var stepVar;
201   Handle(GEOM_FieldStep) step = _impl->GetStep(stepID);
202   if ( !step.IsNull() )
203   {
204     GEOM::GEOM_BaseObject_var obj = _engine->GetObject( step->GetDocID(),
205                                                         step->GetEntryString().ToCString());
206     stepVar = GEOM::GEOM_FieldStep::_narrow( obj );
207   }
208   return stepVar._retn();
209 }
210
211 //================================================================================
212 /*!
213  *  \brief Returns a size of data array that is to be passed to
214  *         GEOM_FieldStep.SetValues( dataArray ). This size depends on the
215  *         number of sub-shapes of field dimension and the number of components
216  */
217 //================================================================================
218
219 CORBA::Long GEOM_Field_i::GetArraySize()
220 {
221   return (CORBA::Long) _impl->GetArrayLength();
222 }
223
224 //================================================================================
225 /*!
226  * \brief Constructor of base step class
227  */
228 //================================================================================
229
230 GEOM_FieldStep_i::GEOM_FieldStep_i(PortableServer::POA_ptr  thePOA,
231                                    GEOM::GEOM_Gen_ptr       theEngine,
232                                    Handle(GEOM_FieldStep)   theImpl):
233   SALOME::GenericObj_i( thePOA ),
234   GEOM_BaseObject_i( thePOA, theEngine, theImpl ),
235   _impl( theImpl )
236 {
237 }
238
239 //================================================================================
240 /*!
241  * \brief Destructor
242  */
243 //================================================================================
244
245 GEOM_FieldStep_i::~GEOM_FieldStep_i()
246 {
247 }
248
249 //================================================================================
250 /*!
251  * \brief Changes the stamp of the field step
252  */
253 //================================================================================
254
255 void GEOM_FieldStep_i::SetStamp(::CORBA::Long stamp)
256 {
257   _impl->SetStamp( stamp );
258 }
259
260 //================================================================================
261 /*!
262  * \brief Returns the time of the field step
263  */
264 //================================================================================
265
266 ::CORBA::Long GEOM_FieldStep_i::GetStamp()
267 {
268   return (CORBA::Long) _impl->GetStamp();
269 }
270
271 //================================================================================
272 /*!
273  * \brief Returns the number of the field step
274  */
275 //================================================================================
276
277 ::CORBA::Long GEOM_FieldStep_i::GetID()
278 {
279   return (CORBA::Long) _impl->GetID();
280 }
281
282 //================================================================================
283 /*!
284  * \brief Returns the field the step belongs to
285  */
286 //================================================================================
287
288 GEOM::GEOM_Field_ptr GEOM_FieldStep_i::GetField()
289 {
290   GEOM::GEOM_Field_var fieldVar;
291   Handle(GEOM_Field) field = _impl->GetField();
292   if ( !field.IsNull() )
293   {
294     GEOM::GEOM_BaseObject_var obj = _engine->GetObject( field->GetDocID(),
295                                                         field->GetEntryString().ToCString());
296     fieldVar = GEOM::GEOM_Field::_narrow( obj );
297   }
298   return fieldVar._retn();
299 }
300
301 //================================================================================
302 /*!
303  * \brief Constructor of GEOM_BoolFieldStep_i
304  */
305 //================================================================================
306
307 GEOM_BoolFieldStep_i::GEOM_BoolFieldStep_i(PortableServer::POA_ptr thePOA, GEOM::GEOM_Gen_ptr theEngine, Handle(GEOM_FieldStep) theImpl):
308   SALOME::GenericObj_i( thePOA ),
309   GEOM_BaseObject_i( thePOA, theEngine, theImpl ),
310   GEOM_FieldStep_i( thePOA, theEngine, theImpl )
311 {
312 }
313
314 //================================================================================
315 /*!
316  * \brief Changes values of the field step. Returns false if number of values is wrong
317  */
318 //================================================================================
319
320 ::CORBA::Boolean GEOM_BoolFieldStep_i::SetValues(const ::GEOM::short_array& boolValues)
321 {
322   Handle(TColStd_HArray1OfInteger) values =
323     new TColStd_HArray1OfInteger( 0, boolValues.length()-1 );
324   for ( size_t i = 0; i < boolValues.length(); ++ i )
325     values->SetValue( i, boolValues[i] );
326
327   return _impl->SetValues( values );
328 }
329
330 //================================================================================
331 /*!
332  * \brief Returns values of the field step
333  */
334 //================================================================================
335
336 GEOM::short_array* GEOM_BoolFieldStep_i::GetValues()
337 {
338   GEOM::short_array_var resArray = new GEOM::short_array;
339
340   Handle(TColStd_HArray1OfInteger) values = GEOM_FieldStep_i::_impl->GetIntValues();
341   if ( !values.IsNull() )
342   {
343     resArray->length( values->Length() );
344     int i, i0, nb; 
345     for ( i = i0 = values->Lower(), nb = values->Upper(); i <= nb; ++i )
346       resArray[ i-i0 ] = values->Value( i );
347   }
348   return resArray._retn();
349 }
350
351
352 //================================================================================
353 /*!
354  * \brief Constructor of GEOM_IntFieldStep_i
355  */
356 //================================================================================
357
358 GEOM_IntFieldStep_i::GEOM_IntFieldStep_i(PortableServer::POA_ptr thePOA, GEOM::GEOM_Gen_ptr theEngine, Handle(GEOM_FieldStep) theImpl):
359   SALOME::GenericObj_i( thePOA ),
360   GEOM_BaseObject_i( thePOA, theEngine, theImpl ),
361   GEOM_FieldStep_i( thePOA, theEngine, theImpl )
362 {
363 }
364
365 //================================================================================
366 /*!
367  * \brief Changes values of the field step. Returns false if number of values is wrong
368  */
369 //================================================================================
370
371 ::CORBA::Boolean GEOM_IntFieldStep_i::SetValues(const ::GEOM::ListOfLong& intValues)
372 {
373   Handle(TColStd_HArray1OfInteger) values =
374     new TColStd_HArray1OfInteger( 0, intValues.length()-1 );
375   for ( size_t i = 0; i < intValues.length(); ++ i )
376     values->SetValue( i, intValues[i] );
377
378   return _impl->SetValues( values );
379 }
380
381 //================================================================================
382 /*!
383  * \brief Returns values of the field step
384  */
385 //================================================================================
386
387 GEOM::ListOfLong* GEOM_IntFieldStep_i::GetValues()
388 {
389   GEOM::ListOfLong_var resArray = new GEOM::ListOfLong;
390
391   Handle(TColStd_HArray1OfInteger) values = GEOM_FieldStep_i::_impl->GetIntValues();
392   if ( !values.IsNull() )
393   {
394     resArray->length( values->Length() );
395     int i, i0, nb; 
396     for ( i = i0 = values->Lower(), nb = values->Upper(); i <= nb; ++i )
397       resArray[ i-i0 ] = values->Value( i );
398   }
399   return resArray._retn();
400 }
401
402
403 //================================================================================
404 /*!
405  * \brief Constructor of GEOM_DoubleFieldStep_i
406  */
407 //================================================================================
408
409 GEOM_DoubleFieldStep_i::GEOM_DoubleFieldStep_i(PortableServer::POA_ptr thePOA, GEOM::GEOM_Gen_ptr theEngine, Handle(GEOM_FieldStep) theImpl):
410   SALOME::GenericObj_i( thePOA ),
411   GEOM_BaseObject_i( thePOA, theEngine, theImpl ),
412   GEOM_FieldStep_i( thePOA, theEngine, theImpl )
413 {
414 }
415
416 //================================================================================
417 /*!
418  * \brief Changes values of the field step. Returns false if number of values is wrong
419  */
420 //================================================================================
421
422 ::CORBA::Boolean GEOM_DoubleFieldStep_i::SetValues(const ::GEOM::ListOfDouble& dblValues)
423 {
424   Handle(TColStd_HArray1OfReal) values =
425     new TColStd_HArray1OfReal( 0, dblValues.length()-1 );
426   for ( size_t i = 0; i < dblValues.length(); ++ i )
427     values->SetValue( i, dblValues[i] );
428
429   return _impl->SetValues( values );
430 }
431
432 //================================================================================
433 /*!
434  * \brief Returns values of the field step
435  */
436 //================================================================================
437
438 GEOM::ListOfDouble* GEOM_DoubleFieldStep_i::GetValues()
439 {
440   GEOM::ListOfDouble_var resArray = new GEOM::ListOfDouble;
441
442   Handle(TColStd_HArray1OfReal) values = GEOM_FieldStep_i::_impl->GetDoubleValues();
443   if ( !values.IsNull() )
444   {
445     resArray->length( values->Length() );
446     int i, i0, nb; 
447     for ( i = i0 = values->Lower(), nb = values->Upper(); i <= nb; ++i )
448       resArray[ i-i0 ] = values->Value( i );
449   }
450   return resArray._retn();
451 }
452
453
454 //================================================================================
455 /*!
456  * \brief Constructor of GEOM_StringFieldStep_i
457  */
458 //================================================================================
459
460 GEOM_StringFieldStep_i::GEOM_StringFieldStep_i(PortableServer::POA_ptr thePOA, GEOM::GEOM_Gen_ptr theEngine, Handle(GEOM_FieldStep) theImpl):
461   SALOME::GenericObj_i( thePOA ),
462   GEOM_BaseObject_i( thePOA, theEngine, theImpl ),
463   GEOM_FieldStep_i( thePOA, theEngine, theImpl )
464 {
465 }
466
467 //================================================================================
468 /*!
469  * \brief Changes values of the field step. Returns false if number of values is wrong
470  */
471 //================================================================================
472
473 ::CORBA::Boolean GEOM_StringFieldStep_i::SetValues(const ::GEOM::string_array& strValues)
474 {
475   Handle(TColStd_HArray1OfExtendedString) values =
476     new TColStd_HArray1OfExtendedString( 0, strValues.length()-1 );
477   for ( size_t i = 0; i < strValues.length(); ++ i )
478     values->SetValue( i, strValues[i].in() );
479
480   return _impl->SetValues( values );
481 }
482
483 //================================================================================
484 /*!
485  * \brief Returns values of the field step
486  */
487 //================================================================================
488
489 GEOM::string_array* GEOM_StringFieldStep_i::GetValues()
490 {
491   GEOM::string_array_var resArray = new GEOM::string_array;
492
493   Handle(TColStd_HArray1OfExtendedString) values = GEOM_FieldStep_i::_impl->GetStringValues();
494   if ( !values.IsNull() )
495   {
496     resArray->length( values->Length() );
497     std::string entry;
498     int i, i0, nb; 
499     for ( i = i0 = values->Lower(), nb = values->Upper(); i <= nb; ++i )
500     {
501       const TCollection_ExtendedString& anEntry = values->Value( i );
502       entry.resize( anEntry.LengthOfCString() );
503       char* pstr = &entry[0];
504       anEntry.ToUTF8CString( pstr );
505       resArray[ i-i0 ] = CORBA::string_dup( entry.c_str() );
506     }
507   }
508   return resArray._retn();
509 }
510