1 // Copyright (C) 2007-2015 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->GetDocID(),
73 shape->GetEntryString().ToCString());
74 shapeVar = GEOM::GEOM_Object::_narrow( obj );
76 return shapeVar._retn();
79 //================================================================================
81 * \brief Returns type of field data
83 //================================================================================
85 GEOM::field_data_type GEOM_Field_i::GetDataType()
87 return GEOM::field_data_type( _impl->GetDataType() );
90 //================================================================================
92 * \brief Returns dimension of the shape the field lies on
93 * 0 - VERTEX, 1 - EDGE, 2 - FACE, 3 - SOLID, -1 - whole shape
95 //================================================================================
97 CORBA::Short GEOM_Field_i::GetDimension()
99 return CORBA::Short( _impl->GetDimension() );
102 //================================================================================
104 * \brief Returns names of components
106 //================================================================================
108 GEOM::string_array* GEOM_Field_i::GetComponents()
110 GEOM::string_array_var compArr = new GEOM::string_array;
111 Handle(TColStd_HArray1OfExtendedString) comps = _impl->GetComponents();
112 if ( !comps.IsNull() )
114 compArr->length( comps->Length() );
117 for ( i = i0 = comps->Lower(), nb = comps->Upper(); i <= nb; ++i )
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() );
126 return compArr._retn();
129 //================================================================================
131 * \brief Adds a time step to the field
133 //================================================================================
135 GEOM::GEOM_FieldStep_ptr GEOM_Field_i::AddStep(::CORBA::Long stepID, ::CORBA::Long stamp)
137 GEOM::GEOM_FieldStep_var stepVar;
138 Handle(GEOM_FieldStep) step = _impl->AddStep( stepID, stamp );
139 if ( !step.IsNull() )
141 GEOM::GEOM_BaseObject_var obj = _engine->GetObject( step->GetDocID(),
142 step->GetEntryString().ToCString());
143 stepVar = GEOM::GEOM_FieldStep::_narrow( obj );
145 return stepVar._retn();
148 //================================================================================
150 * \brief Remove a time step from the field
152 //================================================================================
154 void GEOM_Field_i::RemoveStep(::CORBA::Long stepID)
156 _impl->RemoveStep( stepID );
159 //================================================================================
161 * \brief Returns number of time steps in the field
163 //================================================================================
165 CORBA::Long GEOM_Field_i::CountSteps()
167 return (CORBA::Long) _impl->GetSteps().size();
170 //================================================================================
172 * \brief Returns a list of time step IDs in the field
174 //================================================================================
176 GEOM::ListOfLong* GEOM_Field_i::GetSteps()
178 std::list< Handle(GEOM_FieldStep)> stepList = _impl->GetSteps();
179 std::list< Handle(GEOM_FieldStep)>::iterator stp = stepList.begin();
181 GEOM::ListOfLong_var stepIds = new GEOM::ListOfLong();
182 stepIds->length( stepList.size() );
184 for ( ; stp != stepList.end(); ++stp )
185 if ( !stp->IsNull() )
186 stepIds[ nbS++ ] = (*stp)->GetID();
188 stepIds->length( nbS );
189 return stepIds._retn();
192 //================================================================================
194 * \brief Returns a time step by its ID
196 //================================================================================
198 GEOM::GEOM_FieldStep_ptr GEOM_Field_i::GetStep(CORBA::Long stepID)
200 GEOM::GEOM_FieldStep_var stepVar;
201 Handle(GEOM_FieldStep) step = _impl->GetStep(stepID);
202 if ( !step.IsNull() )
204 GEOM::GEOM_BaseObject_var obj = _engine->GetObject( step->GetDocID(),
205 step->GetEntryString().ToCString());
206 stepVar = GEOM::GEOM_FieldStep::_narrow( obj );
208 return stepVar._retn();
211 //================================================================================
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
217 //================================================================================
219 CORBA::Long GEOM_Field_i::GetArraySize()
221 return (CORBA::Long) _impl->GetArrayLength();
224 //================================================================================
226 * \brief Constructor of base step class
228 //================================================================================
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 ),
239 //================================================================================
243 //================================================================================
245 GEOM_FieldStep_i::~GEOM_FieldStep_i()
249 //================================================================================
251 * \brief Changes the stamp of the field step
253 //================================================================================
255 void GEOM_FieldStep_i::SetStamp(::CORBA::Long stamp)
257 _impl->SetStamp( stamp );
260 //================================================================================
262 * \brief Returns the time of the field step
264 //================================================================================
266 ::CORBA::Long GEOM_FieldStep_i::GetStamp()
268 return (CORBA::Long) _impl->GetStamp();
271 //================================================================================
273 * \brief Returns the number of the field step
275 //================================================================================
277 ::CORBA::Long GEOM_FieldStep_i::GetID()
279 return (CORBA::Long) _impl->GetID();
282 //================================================================================
284 * \brief Returns the field the step belongs to
286 //================================================================================
288 GEOM::GEOM_Field_ptr GEOM_FieldStep_i::GetField()
290 GEOM::GEOM_Field_var fieldVar;
291 Handle(GEOM_Field) field = _impl->GetField();
292 if ( !field.IsNull() )
294 GEOM::GEOM_BaseObject_var obj = _engine->GetObject( field->GetDocID(),
295 field->GetEntryString().ToCString());
296 fieldVar = GEOM::GEOM_Field::_narrow( obj );
298 return fieldVar._retn();
301 //================================================================================
303 * \brief Constructor of GEOM_BoolFieldStep_i
305 //================================================================================
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 )
314 //================================================================================
316 * \brief Changes values of the field step. Returns false if number of values is wrong
318 //================================================================================
320 ::CORBA::Boolean GEOM_BoolFieldStep_i::SetValues(const ::GEOM::short_array& boolValues)
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] );
327 return _impl->SetValues( values );
330 //================================================================================
332 * \brief Returns values of the field step
334 //================================================================================
336 GEOM::short_array* GEOM_BoolFieldStep_i::GetValues()
338 GEOM::short_array_var resArray = new GEOM::short_array;
340 Handle(TColStd_HArray1OfInteger) values = GEOM_FieldStep_i::_impl->GetIntValues();
341 if ( !values.IsNull() )
343 resArray->length( values->Length() );
345 for ( i = i0 = values->Lower(), nb = values->Upper(); i <= nb; ++i )
346 resArray[ i-i0 ] = values->Value( i );
348 return resArray._retn();
352 //================================================================================
354 * \brief Constructor of GEOM_IntFieldStep_i
356 //================================================================================
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 )
365 //================================================================================
367 * \brief Changes values of the field step. Returns false if number of values is wrong
369 //================================================================================
371 ::CORBA::Boolean GEOM_IntFieldStep_i::SetValues(const ::GEOM::ListOfLong& intValues)
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] );
378 return _impl->SetValues( values );
381 //================================================================================
383 * \brief Returns values of the field step
385 //================================================================================
387 GEOM::ListOfLong* GEOM_IntFieldStep_i::GetValues()
389 GEOM::ListOfLong_var resArray = new GEOM::ListOfLong;
391 Handle(TColStd_HArray1OfInteger) values = GEOM_FieldStep_i::_impl->GetIntValues();
392 if ( !values.IsNull() )
394 resArray->length( values->Length() );
396 for ( i = i0 = values->Lower(), nb = values->Upper(); i <= nb; ++i )
397 resArray[ i-i0 ] = values->Value( i );
399 return resArray._retn();
403 //================================================================================
405 * \brief Constructor of GEOM_DoubleFieldStep_i
407 //================================================================================
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 )
416 //================================================================================
418 * \brief Changes values of the field step. Returns false if number of values is wrong
420 //================================================================================
422 ::CORBA::Boolean GEOM_DoubleFieldStep_i::SetValues(const ::GEOM::ListOfDouble& dblValues)
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] );
429 return _impl->SetValues( values );
432 //================================================================================
434 * \brief Returns values of the field step
436 //================================================================================
438 GEOM::ListOfDouble* GEOM_DoubleFieldStep_i::GetValues()
440 GEOM::ListOfDouble_var resArray = new GEOM::ListOfDouble;
442 Handle(TColStd_HArray1OfReal) values = GEOM_FieldStep_i::_impl->GetDoubleValues();
443 if ( !values.IsNull() )
445 resArray->length( values->Length() );
447 for ( i = i0 = values->Lower(), nb = values->Upper(); i <= nb; ++i )
448 resArray[ i-i0 ] = values->Value( i );
450 return resArray._retn();
454 //================================================================================
456 * \brief Constructor of GEOM_StringFieldStep_i
458 //================================================================================
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 )
467 //================================================================================
469 * \brief Changes values of the field step. Returns false if number of values is wrong
471 //================================================================================
473 ::CORBA::Boolean GEOM_StringFieldStep_i::SetValues(const ::GEOM::string_array& strValues)
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() );
480 return _impl->SetValues( values );
483 //================================================================================
485 * \brief Returns values of the field step
487 //================================================================================
489 GEOM::string_array* GEOM_StringFieldStep_i::GetValues()
491 GEOM::string_array_var resArray = new GEOM::string_array;
493 Handle(TColStd_HArray1OfExtendedString) values = GEOM_FieldStep_i::_impl->GetStringValues();
494 if ( !values.IsNull() )
496 resArray->length( values->Length() );
499 for ( i = i0 = values->Lower(), nb = values->Upper(); i <= nb; ++i )
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() );
508 return resArray._retn();