1 // Copyright (C) 2007-2020 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 #include "GEOM_Field_i.hh"
25 #include <utilities.h>
27 #include <TCollection_ExtendedString.hxx>
28 #include <TColStd_HArray1OfReal.hxx>
31 #pragma warning( disable:4786 )
34 //=============================================================================
38 //=============================================================================
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 ),
49 //=============================================================================
53 //=============================================================================
55 GEOM_Field_i::~GEOM_Field_i()
57 MESSAGE("GEOM_Field_i::~GEOM_Field_i");
60 //================================================================================
62 * \brief Returns the shape the field lies on
64 //================================================================================
66 GEOM::GEOM_Object_ptr GEOM_Field_i::GetShape()
68 GEOM::GEOM_Object_var shapeVar;
69 Handle(::GEOM_Object) shape = _impl->GetShape();
70 if ( !shape.IsNull() )
72 GEOM::GEOM_BaseObject_var obj = _engine->GetObject( shape->GetEntryString().ToCString());
73 shapeVar = GEOM::GEOM_Object::_narrow( obj );
75 return shapeVar._retn();
78 //================================================================================
80 * \brief Returns type of field data
82 //================================================================================
84 GEOM::field_data_type GEOM_Field_i::GetDataType()
86 return GEOM::field_data_type( _impl->GetDataType() );
89 //================================================================================
91 * \brief Returns dimension of the shape the field lies on
92 * 0 - VERTEX, 1 - EDGE, 2 - FACE, 3 - SOLID, -1 - whole shape
94 //================================================================================
96 CORBA::Short GEOM_Field_i::GetDimension()
98 return CORBA::Short( _impl->GetDimension() );
101 //================================================================================
103 * \brief Returns names of components
105 //================================================================================
107 GEOM::string_array* GEOM_Field_i::GetComponents()
109 GEOM::string_array_var compArr = new GEOM::string_array;
110 Handle(TColStd_HArray1OfExtendedString) comps = _impl->GetComponents();
111 if ( !comps.IsNull() )
113 compArr->length( comps->Length() );
116 for ( i = i0 = comps->Lower(), nb = comps->Upper(); i <= nb; ++i )
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() );
125 return compArr._retn();
128 //================================================================================
130 * \brief Adds a time step to the field
132 //================================================================================
134 GEOM::GEOM_FieldStep_ptr GEOM_Field_i::AddStep(::CORBA::Long stepID, ::CORBA::Long stamp)
136 GEOM::GEOM_FieldStep_var stepVar;
137 Handle(::GEOM_FieldStep) step = _impl->AddStep( stepID, stamp );
138 if ( !step.IsNull() )
140 GEOM::GEOM_BaseObject_var obj = _engine->GetObject( step->GetEntryString().ToCString());
141 stepVar = GEOM::GEOM_FieldStep::_narrow( obj );
143 return stepVar._retn();
146 //================================================================================
148 * \brief Remove a time step from the field
150 //================================================================================
152 void GEOM_Field_i::RemoveStep(::CORBA::Long stepID)
154 _impl->RemoveStep( stepID );
157 //================================================================================
159 * \brief Returns number of time steps in the field
161 //================================================================================
163 CORBA::Long GEOM_Field_i::CountSteps()
165 return (CORBA::Long) _impl->GetSteps().size();
168 //================================================================================
170 * \brief Returns a list of time step IDs in the field
172 //================================================================================
174 GEOM::ListOfLong* GEOM_Field_i::GetSteps()
176 std::list< Handle(::GEOM_FieldStep)> stepList = _impl->GetSteps();
177 std::list< Handle(::GEOM_FieldStep)>::iterator stp = stepList.begin();
179 GEOM::ListOfLong_var stepIds = new GEOM::ListOfLong();
180 stepIds->length( stepList.size() );
182 for ( ; stp != stepList.end(); ++stp )
183 if ( !stp->IsNull() )
184 stepIds[ nbS++ ] = (*stp)->GetID();
186 stepIds->length( nbS );
187 return stepIds._retn();
190 //================================================================================
192 * \brief Returns a time step by its ID
194 //================================================================================
196 GEOM::GEOM_FieldStep_ptr GEOM_Field_i::GetStep(CORBA::Long stepID)
198 GEOM::GEOM_FieldStep_var stepVar;
199 Handle(::GEOM_FieldStep) step = _impl->GetStep(stepID);
200 if ( !step.IsNull() )
202 GEOM::GEOM_BaseObject_var obj = _engine->GetObject( step->GetEntryString().ToCString());
203 stepVar = GEOM::GEOM_FieldStep::_narrow( obj );
205 return stepVar._retn();
208 //================================================================================
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
214 //================================================================================
216 CORBA::Long GEOM_Field_i::GetArraySize()
218 return (CORBA::Long) _impl->GetArrayLength();
221 //================================================================================
223 * \brief Constructor of base step class
225 //================================================================================
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 ),
236 //================================================================================
240 //================================================================================
242 GEOM_FieldStep_i::~GEOM_FieldStep_i()
246 //================================================================================
248 * \brief Changes the stamp of the field step
250 //================================================================================
252 void GEOM_FieldStep_i::SetStamp(::CORBA::Long stamp)
254 _impl->SetStamp( stamp );
257 //================================================================================
259 * \brief Returns the time of the field step
261 //================================================================================
263 ::CORBA::Long GEOM_FieldStep_i::GetStamp()
265 return (CORBA::Long) _impl->GetStamp();
268 //================================================================================
270 * \brief Returns the number of the field step
272 //================================================================================
274 ::CORBA::Long GEOM_FieldStep_i::GetID()
276 return (CORBA::Long) _impl->GetID();
279 //================================================================================
281 * \brief Returns the field the step belongs to
283 //================================================================================
285 GEOM::GEOM_Field_ptr GEOM_FieldStep_i::GetField()
287 GEOM::GEOM_Field_var fieldVar;
288 Handle(::GEOM_Field) field = _impl->GetField();
289 if ( !field.IsNull() )
291 GEOM::GEOM_BaseObject_var obj = _engine->GetObject( field->GetEntryString().ToCString());
292 fieldVar = GEOM::GEOM_Field::_narrow( obj );
294 return fieldVar._retn();
297 //================================================================================
299 * \brief Constructor of GEOM_BoolFieldStep_i
301 //================================================================================
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 )
310 //================================================================================
312 * \brief Changes values of the field step. Returns false if number of values is wrong
314 //================================================================================
316 ::CORBA::Boolean GEOM_BoolFieldStep_i::SetValues(const ::GEOM::short_array& boolValues)
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] );
323 return _impl->SetValues( values );
326 //================================================================================
328 * \brief Returns values of the field step
330 //================================================================================
332 GEOM::short_array* GEOM_BoolFieldStep_i::GetValues()
334 GEOM::short_array_var resArray = new GEOM::short_array;
336 Handle(TColStd_HArray1OfInteger) values = GEOM_FieldStep_i::_impl->GetIntValues();
337 if ( !values.IsNull() )
339 resArray->length( values->Length() );
341 for ( i = i0 = values->Lower(), nb = values->Upper(); i <= nb; ++i )
342 resArray[ i-i0 ] = values->Value( i );
344 return resArray._retn();
348 //================================================================================
350 * \brief Constructor of GEOM_IntFieldStep_i
352 //================================================================================
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 )
361 //================================================================================
363 * \brief Changes values of the field step. Returns false if number of values is wrong
365 //================================================================================
367 ::CORBA::Boolean GEOM_IntFieldStep_i::SetValues(const ::GEOM::ListOfLong& intValues)
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] );
374 return _impl->SetValues( values );
377 //================================================================================
379 * \brief Returns values of the field step
381 //================================================================================
383 GEOM::ListOfLong* GEOM_IntFieldStep_i::GetValues()
385 GEOM::ListOfLong_var resArray = new GEOM::ListOfLong;
387 Handle(TColStd_HArray1OfInteger) values = GEOM_FieldStep_i::_impl->GetIntValues();
388 if ( !values.IsNull() )
390 resArray->length( values->Length() );
392 for ( i = i0 = values->Lower(), nb = values->Upper(); i <= nb; ++i )
393 resArray[ i-i0 ] = values->Value( i );
395 return resArray._retn();
399 //================================================================================
401 * \brief Constructor of GEOM_DoubleFieldStep_i
403 //================================================================================
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 )
412 //================================================================================
414 * \brief Changes values of the field step. Returns false if number of values is wrong
416 //================================================================================
418 ::CORBA::Boolean GEOM_DoubleFieldStep_i::SetValues(const ::GEOM::ListOfDouble& dblValues)
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] );
425 return _impl->SetValues( values );
428 //================================================================================
430 * \brief Returns values of the field step
432 //================================================================================
434 GEOM::ListOfDouble* GEOM_DoubleFieldStep_i::GetValues()
436 GEOM::ListOfDouble_var resArray = new GEOM::ListOfDouble;
438 Handle(TColStd_HArray1OfReal) values = GEOM_FieldStep_i::_impl->GetDoubleValues();
439 if ( !values.IsNull() )
441 resArray->length( values->Length() );
443 for ( i = i0 = values->Lower(), nb = values->Upper(); i <= nb; ++i )
444 resArray[ i-i0 ] = values->Value( i );
446 return resArray._retn();
450 //================================================================================
452 * \brief Constructor of GEOM_StringFieldStep_i
454 //================================================================================
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 )
463 //================================================================================
465 * \brief Changes values of the field step. Returns false if number of values is wrong
467 //================================================================================
469 ::CORBA::Boolean GEOM_StringFieldStep_i::SetValues(const ::GEOM::string_array& strValues)
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() );
476 return _impl->SetValues( values );
479 //================================================================================
481 * \brief Returns values of the field step
483 //================================================================================
485 GEOM::string_array* GEOM_StringFieldStep_i::GetValues()
487 GEOM::string_array_var resArray = new GEOM::string_array;
489 Handle(TColStd_HArray1OfExtendedString) values = GEOM_FieldStep_i::_impl->GetStringValues();
490 if ( !values.IsNull() )
492 resArray->length( values->Length() );
495 for ( i = i0 = values->Lower(), nb = values->Upper(); i <= nb; ++i )
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() );
504 return resArray._retn();