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