1 // Copyright (C) 2007-2013 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.
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");
58 GEOM_Engine::GetEngine()->RemoveObject(_impl);
61 //================================================================================
63 * \brief Returns the shape the field lies on
65 //================================================================================
67 GEOM::GEOM_Object_ptr GEOM_Field_i::GetShape()
69 GEOM::GEOM_Object_var shapeVar;
70 Handle(GEOM_Object) shape = _impl->GetShape();
71 if ( !shape.IsNull() )
73 GEOM::GEOM_BaseObject_var obj = _engine->GetObject( shape->GetDocID(),
74 shape->GetEntryString().ToCString());
75 shapeVar = GEOM::GEOM_Object::_narrow( obj );
77 return shapeVar._retn();
80 //================================================================================
82 * \brief Returns type of field data
84 //================================================================================
86 GEOM::field_data_type GEOM_Field_i::GetDataType()
88 return GEOM::field_data_type( _impl->GetDataType() );
91 //================================================================================
93 * \brief Returns dimension of the shape the field lies on
94 * 0 - VERTEX, 1 - EDGE, 2 - FACE, 3 - SOLID, -1 - whole shape
96 //================================================================================
98 CORBA::Short GEOM_Field_i::GetDimension()
100 return CORBA::Short( _impl->GetDimension() );
103 //================================================================================
105 * \brief Returns names of components
107 //================================================================================
109 GEOM::string_array* GEOM_Field_i::GetComponents()
111 GEOM::string_array_var compArr = new GEOM::string_array;
112 Handle(TColStd_HArray1OfExtendedString) comps = _impl->GetComponents();
113 if ( !comps.IsNull() )
115 compArr->length( comps->Length() );
118 for ( i = i0 = comps->Lower(), nb = comps->Upper(); i <= nb; ++i )
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() );
127 return compArr._retn();
130 //================================================================================
132 * \brief Adds a time step to the field
134 //================================================================================
136 GEOM::GEOM_FieldStep_ptr GEOM_Field_i::AddStep(::CORBA::Long stepID, ::CORBA::Long stamp)
138 GEOM::GEOM_FieldStep_var stepVar;
139 Handle(GEOM_FieldStep) step = _impl->AddStep( stepID, stamp );
140 if ( !step.IsNull() )
142 GEOM::GEOM_BaseObject_var obj = _engine->GetObject( step->GetDocID(),
143 step->GetEntryString().ToCString());
144 stepVar = GEOM::GEOM_FieldStep::_narrow( obj );
146 return stepVar._retn();
149 //================================================================================
151 * \brief Remove a time step from the field
153 //================================================================================
155 void GEOM_Field_i::RemoveStep(::CORBA::Long stepID)
157 _impl->RemoveStep( stepID );
160 //================================================================================
162 * \brief Returns number of time steps in the field
164 //================================================================================
166 CORBA::Long GEOM_Field_i::CountSteps()
168 return (CORBA::Long) _impl->GetSteps().size();
171 //================================================================================
173 * \brief Returns a list of time step IDs in the field
175 //================================================================================
177 GEOM::ListOfLong* GEOM_Field_i::GetSteps()
179 std::list< Handle(GEOM_FieldStep)> stepList = _impl->GetSteps();
180 std::list< Handle(GEOM_FieldStep)>::iterator stp = stepList.begin();
182 GEOM::ListOfLong_var stepIds = new GEOM::ListOfLong();
183 stepIds->length( stepList.size() );
185 for ( ; stp != stepList.end(); ++stp )
186 if ( !stp->IsNull() )
187 stepIds[ nbS++ ] = (*stp)->GetID();
189 stepIds->length( nbS );
190 return stepIds._retn();
193 //================================================================================
195 * \brief Returns a time step by its ID
197 //================================================================================
199 GEOM::GEOM_FieldStep_ptr GEOM_Field_i::GetStep(CORBA::Long stepID)
201 GEOM::GEOM_FieldStep_var stepVar;
202 Handle(GEOM_FieldStep) step = _impl->GetStep(stepID);
203 if ( !step.IsNull() )
205 GEOM::GEOM_BaseObject_var obj = _engine->GetObject( step->GetDocID(),
206 step->GetEntryString().ToCString());
207 stepVar = GEOM::GEOM_FieldStep::_narrow( obj );
209 return stepVar._retn();
212 //================================================================================
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
218 //================================================================================
220 CORBA::Long GEOM_Field_i::GetArraySize()
222 return (CORBA::Long) _impl->GetArrayLength();
225 //================================================================================
227 * \brief Constructor of base step class
229 //================================================================================
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 ),
240 //================================================================================
244 //================================================================================
246 GEOM_FieldStep_i::~GEOM_FieldStep_i()
250 //================================================================================
252 * \brief Changes the stamp of the field step
254 //================================================================================
256 void GEOM_FieldStep_i::SetStamp(::CORBA::Long stamp)
258 _impl->SetStamp( stamp );
261 //================================================================================
263 * \brief Returns the time of the field step
265 //================================================================================
267 ::CORBA::Long GEOM_FieldStep_i::GetStamp()
269 return (CORBA::Long) _impl->GetStamp();
272 //================================================================================
274 * \brief Returns the number of the field step
276 //================================================================================
278 ::CORBA::Long GEOM_FieldStep_i::GetID()
280 return (CORBA::Long) _impl->GetID();
283 //================================================================================
285 * \brief Returns the field the step belongs to
287 //================================================================================
289 GEOM::GEOM_Field_ptr GEOM_FieldStep_i::GetField()
291 GEOM::GEOM_Field_var fieldVar;
292 Handle(GEOM_Field) field = _impl->GetField();
293 if ( !field.IsNull() )
295 GEOM::GEOM_BaseObject_var obj = _engine->GetObject( field->GetDocID(),
296 field->GetEntryString().ToCString());
297 fieldVar = GEOM::GEOM_Field::_narrow( obj );
299 return fieldVar._retn();
302 //================================================================================
304 * \brief Constructor of GEOM_BoolFieldStep_i
306 //================================================================================
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 )
315 //================================================================================
317 * \brief Changes values of the field step. Returns false if number of values is wrong
319 //================================================================================
321 ::CORBA::Boolean GEOM_BoolFieldStep_i::SetValues(const ::GEOM::short_array& boolValues)
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] );
328 return _impl->SetValues( values );
331 //================================================================================
333 * \brief Returns values of the field step
335 //================================================================================
337 GEOM::short_array* GEOM_BoolFieldStep_i::GetValues()
339 GEOM::short_array_var resArray = new GEOM::short_array;
341 Handle(TColStd_HArray1OfInteger) values = GEOM_FieldStep_i::_impl->GetIntValues();
342 if ( !values.IsNull() )
344 resArray->length( values->Length() );
346 for ( i = i0 = values->Lower(), nb = values->Upper(); i <= nb; ++i )
347 resArray[ i-i0 ] = values->Value( i );
349 return resArray._retn();
353 //================================================================================
355 * \brief Constructor of GEOM_IntFieldStep_i
357 //================================================================================
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 )
366 //================================================================================
368 * \brief Changes values of the field step. Returns false if number of values is wrong
370 //================================================================================
372 ::CORBA::Boolean GEOM_IntFieldStep_i::SetValues(const ::GEOM::ListOfLong& intValues)
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] );
379 return _impl->SetValues( values );
382 //================================================================================
384 * \brief Returns values of the field step
386 //================================================================================
388 GEOM::ListOfLong* GEOM_IntFieldStep_i::GetValues()
390 GEOM::ListOfLong_var resArray = new GEOM::ListOfLong;
392 Handle(TColStd_HArray1OfInteger) values = GEOM_FieldStep_i::_impl->GetIntValues();
393 if ( !values.IsNull() )
395 resArray->length( values->Length() );
397 for ( i = i0 = values->Lower(), nb = values->Upper(); i <= nb; ++i )
398 resArray[ i-i0 ] = values->Value( i );
400 return resArray._retn();
404 //================================================================================
406 * \brief Constructor of GEOM_DoubleFieldStep_i
408 //================================================================================
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 )
417 //================================================================================
419 * \brief Changes values of the field step. Returns false if number of values is wrong
421 //================================================================================
423 ::CORBA::Boolean GEOM_DoubleFieldStep_i::SetValues(const ::GEOM::ListOfDouble& dblValues)
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] );
430 return _impl->SetValues( values );
433 //================================================================================
435 * \brief Returns values of the field step
437 //================================================================================
439 GEOM::ListOfDouble* GEOM_DoubleFieldStep_i::GetValues()
441 GEOM::ListOfDouble_var resArray = new GEOM::ListOfDouble;
443 Handle(TColStd_HArray1OfReal) values = GEOM_FieldStep_i::_impl->GetDoubleValues();
444 if ( !values.IsNull() )
446 resArray->length( values->Length() );
448 for ( i = i0 = values->Lower(), nb = values->Upper(); i <= nb; ++i )
449 resArray[ i-i0 ] = values->Value( i );
451 return resArray._retn();
455 //================================================================================
457 * \brief Constructor of GEOM_StringFieldStep_i
459 //================================================================================
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 )
468 //================================================================================
470 * \brief Changes values of the field step. Returns false if number of values is wrong
472 //================================================================================
474 ::CORBA::Boolean GEOM_StringFieldStep_i::SetValues(const ::GEOM::string_array& strValues)
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() );
481 return _impl->SetValues( values );
484 //================================================================================
486 * \brief Returns values of the field step
488 //================================================================================
490 GEOM::string_array* GEOM_StringFieldStep_i::GetValues()
492 GEOM::string_array_var resArray = new GEOM::string_array;
494 Handle(TColStd_HArray1OfExtendedString) values = GEOM_FieldStep_i::_impl->GetStringValues();
495 if ( !values.IsNull() )
497 resArray->length( values->Length() );
500 for ( i = i0 = values->Lower(), nb = values->Upper(); i <= nb; ++i )
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() );
509 return resArray._retn();