Salome HOME
Merge branch 'V7_dev'
[modules/geom.git] / src / XAOPlugin / XAOPlugin_IOperations.cxx
1 // Copyright (C) 2014-2016  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20 // internal includes
21 #include "XAOPlugin_IOperations.hxx"
22 #include "XAOPlugin_Driver.hxx"
23 #include "XAOPlugin_IImportExport.hxx"
24
25 // KERNEL includes
26 #include <utilities.h>
27 #include <Utils_SALOME_Exception.hxx>
28
29 // GEOM includes
30 #include "GEOM_PythonDump.hxx"
31 #include "GEOMImpl_Types.hxx"
32 #include "GEOMImpl_IGroupOperations.hxx"
33 #include "GEOMImpl_IShapesOperations.hxx"
34 #include "GEOMImpl_IFieldOperations.hxx"
35 #include "GEOM_ISubShape.hxx"
36
37 #include <XAO_Geometry.hxx>
38 #include <XAO_BrepGeometry.hxx>
39 #include <XAO_Xao.hxx>
40 #include <XAO_Group.hxx>
41 #include <XAO_Field.hxx>
42 #include <XAO_BooleanField.hxx>
43 #include <XAO_IntegerField.hxx>
44 #include <XAO_DoubleField.hxx>
45 #include <XAO_StringField.hxx>
46 #include <XAO_DoubleStep.hxx>
47 #include <XAO_StringStep.hxx>
48
49 #include <Standard_ErrorHandler.hxx> // CAREFUL ! position of this file is critic : see Lucien PIGNOLONI / OCC
50
51 // OCC includes
52 #include <TColStd_HArray1OfByte.hxx>
53 #include <TColStd_HArray1OfReal.hxx>
54 #include <TDataStd_Integer.hxx>
55
56
57 XAO::Dimension shapeEnumToDimension(const TopAbs_ShapeEnum& shape)
58 {
59   XAO::Dimension dim;
60   switch( shape ) {
61   case TopAbs_VERTEX:
62     dim = XAO::VERTEX; break;
63   case TopAbs_EDGE:
64     dim = XAO::EDGE; break;
65   case TopAbs_FACE:
66     dim = XAO::FACE; break;
67   case TopAbs_SOLID:
68     dim = XAO::SOLID; break;
69   default:
70     throw SALOME_Exception("Bad type"); // TODO
71   }
72   return dim;
73 }
74
75 TopAbs_ShapeEnum getGroupDimension(XAO::Group* group)
76 {
77   XAO::Dimension dim = group->getDimension();
78   TopAbs_ShapeEnum rdim;
79   switch ( dim )
80   {
81   case XAO::VERTEX:
82     rdim = TopAbs_VERTEX; break;
83   case XAO::EDGE:
84     rdim = TopAbs_EDGE; break;
85   case XAO::FACE:
86     rdim = TopAbs_FACE; break;
87   case XAO::SOLID:
88     rdim = TopAbs_SOLID; break;
89   default:
90     rdim = TopAbs_COMPOUND; break;
91   }
92   return rdim;
93 }
94
95 //=============================================================================
96 /*!
97  *  Constructor
98  */
99 //=============================================================================
100 XAOPlugin_IOperations::XAOPlugin_IOperations( GEOM_Engine* theEngine, int theDocID )
101 : GEOMImpl_IBaseIEOperations( theEngine, theDocID )
102 {
103   MESSAGE( "XAOPlugin_IOperations::XAOPlugin_IOperations" );
104 }
105
106 //=============================================================================
107 /*!
108  *  Destructor
109  */
110 //=============================================================================
111 XAOPlugin_IOperations::~XAOPlugin_IOperations()
112 {
113   MESSAGE( "XAOPlugin_IOperations::~XAOPlugin_IOperations" );
114 }
115
116 bool XAOPlugin_IOperations::exportGroups( std::list<Handle(GEOM_Object)> groupList,
117                                           XAO::Xao* xaoObject,
118                                           XAO::BrepGeometry* geometry )
119 {
120   // add the groups
121   std::list<Handle(GEOM_Object)>::iterator groupIterator = groupList.begin();
122   while (groupIterator != groupList.end())
123   {
124     Handle(GEOM_Object) currGroup = (*groupIterator++);
125     if (currGroup->GetType() != GEOM_GROUP) {
126       SetErrorCode("Error when export groups: you could perform this operation only with group.");
127       return false;
128     }
129     Handle(TColStd_HArray1OfInteger) groupIds = myGroupOperations->GetObjects(currGroup);
130
131     TopAbs_ShapeEnum shapeGroup = myGroupOperations->GetType(currGroup);
132     XAO::Dimension dim = shapeEnumToDimension(shapeGroup);
133     XAO::Group* group = xaoObject->addGroup(dim, currGroup->GetName().ToCString());
134
135     switch (shapeGroup)
136     {
137     case TopAbs_VERTEX:
138       for (int i = 1; i <= groupIds->Length(); i++)
139       {
140         std::string ref = XAO::XaoUtils::intToString(groupIds->Value(i));
141         int index = geometry->getVertexIndexByReference(ref);
142         group->add(index);
143       }
144       break;
145     case TopAbs_EDGE:
146       for (int i = 1; i <= groupIds->Length(); i++)
147       {
148         std::string ref = XAO::XaoUtils::intToString(groupIds->Value(i));
149         int index = geometry->getEdgeIndexByReference(ref);
150         group->add(index);
151       }
152       break;
153     case TopAbs_FACE:
154       for (int i = 1; i <= groupIds->Length(); i++)
155       {
156         std::string ref = XAO::XaoUtils::intToString(groupIds->Value(i));
157         int index = geometry->getFaceIndexByReference(ref);
158         group->add(index);
159       }
160       break;
161     case TopAbs_SOLID:
162       for (int i = 1; i <= groupIds->Length(); i++)
163       {
164         std::string ref = XAO::XaoUtils::intToString(groupIds->Value(i));
165         int index = geometry->getSolidIndexByReference(ref);
166         group->add(index);
167       }
168       break;
169     }
170   }
171   return true;
172 }
173
174 void XAOPlugin_IOperations::exportFields( std::list<Handle(GEOM_Field)> fieldList,
175                                           XAO::Xao* xaoObject,
176                                           XAO::BrepGeometry* geometry )
177 {
178   std::list<Handle(GEOM_Field)>::iterator fieldIterator = fieldList.begin();
179   while (fieldIterator != fieldList.end())
180   {
181     Handle(GEOM_Field) currField = (*fieldIterator++);
182
183     int fdim = currField->GetDimension();
184     int ftype = currField->GetDataType();
185     int nbComponents = currField->GetNbComponents();
186     std::string name = currField->GetName().ToCString();
187
188     XAO::Field* field = xaoObject->addField((XAO::Type)ftype, (XAO::Dimension)fdim, nbComponents, name);
189
190     Handle(TColStd_HArray1OfExtendedString) components = currField->GetComponents();
191     for (int i = components->Lower(), j = 0; i <= components->Upper(); ++i, ++j)
192     {
193       field->setComponentName(j, TCollection_AsciiString(components->Value(i)).ToCString());
194     }
195
196     std::list< Handle(GEOM_FieldStep)> steps = currField->GetSteps();
197     std::list<Handle(GEOM_FieldStep)>::iterator stepIterator = steps.begin();
198     while (stepIterator != steps.end())
199     {
200       Handle(GEOM_FieldStep) currStep = (*stepIterator++);
201
202       XAO::Step* step = field->addNewStep(currStep->GetID());
203       step->setStamp(currStep->GetStamp());
204
205       switch (ftype)
206       {
207         case 0: // bool
208         {
209           XAO::BooleanStep* bs = (XAO::BooleanStep*)step;
210           Handle(TColStd_HArray1OfInteger) bvalues = currStep->GetIntValues();
211           std::vector<bool> bv;
212           bv.reserve(bvalues->Upper());
213           for ( int i = bvalues->Lower(), nb = bvalues->Upper(); i <= nb; ++i )
214           {
215             bv.push_back(bvalues->Value(i) != 0);
216           }
217           bs->setValues(bv);
218           break;
219         }
220         case 1: // integer
221         {
222           XAO::IntegerStep* is = (XAO::IntegerStep*)step;
223           Handle(TColStd_HArray1OfInteger) ivalues = currStep->GetIntValues();
224           std::vector<int> iv;
225           iv.reserve(ivalues->Upper());
226           for ( int i = ivalues->Lower(), nb = ivalues->Upper(); i <= nb; ++i )
227           {
228             iv.push_back(ivalues->Value(i));
229           }
230           is->setValues(iv);
231           break;
232         }
233         case 2: // double
234         {
235           XAO::DoubleStep* ds = (XAO::DoubleStep*)step;
236           Handle(TColStd_HArray1OfReal) dvalues = currStep->GetDoubleValues();
237           std::vector<double> dv;
238           dv.reserve(dvalues->Upper());
239           for ( int i = dvalues->Lower(), nb = dvalues->Upper(); i <= nb; ++i )
240           {
241             dv.push_back(dvalues->Value(i));
242           }
243           ds->setValues(dv);
244             break;
245         }
246         case 3: // string
247         {
248           XAO::StringStep* ss = (XAO::StringStep*)step;
249           Handle(TColStd_HArray1OfExtendedString) svalues = currStep->GetStringValues();
250           std::vector<std::string> sv;
251           sv.reserve(svalues->Upper());
252           for ( int i = svalues->Lower(), nb = svalues->Upper(); i <= nb; ++i )
253           {
254             sv.push_back(TCollection_AsciiString(svalues->Value(i)).ToCString());
255           }
256           ss->setValues(sv);
257           break;
258         }
259       }
260     }
261   }
262 }
263
264 void XAOPlugin_IOperations::exportSubshapes( const Handle(GEOM_Object)& shape, XAO::BrepGeometry* geometry )
265 {
266   Handle(TColStd_HSequenceOfTransient) subObjects = myShapesOperations->GetExistingSubObjects( shape, GEOMImpl_IShapesOperations::SubShapes );
267   int nbSubObjects = subObjects->Length();
268   // set the names of the sub shapes
269   for (int i = 1; i <= nbSubObjects; i++)
270   {
271     Handle(Standard_Transient) transientSubObject = subObjects->Value(i);
272     if (transientSubObject.IsNull())
273       continue;
274
275     Handle(GEOM_Object) subObject = Handle(GEOM_Object)::DownCast( transientSubObject );
276     if (subObject->GetType() != GEOM_GROUP)
277     {
278       int subIndex = myShapesOperations->GetSubShapeIndex( shape, subObject );
279       switch (subObject->GetValue().ShapeType())
280       {
281       case TopAbs_VERTEX:
282         geometry->changeVertexName(subIndex, subObject->GetName().ToCString());
283         break;
284       case TopAbs_EDGE:
285         geometry->changeEdgeName(subIndex, subObject->GetName().ToCString());
286         break;
287       case TopAbs_FACE:
288         geometry->changeFaceName(subIndex, subObject->GetName().ToCString());
289         break;
290       case TopAbs_SOLID:
291         geometry->changeSolidName(subIndex, subObject->GetName().ToCString());
292         break;
293       }
294     }
295   }
296 }
297
298 //=============================================================================
299 /*!
300  *  Export a shape to XAO format
301  *  \param shape The shape to export
302  *  \param groups The list of groups to export
303  *  \param fields The list of fields to export
304  *  \param fileName The name of the file to exported
305  *  \return boolean indicating if export was succeful.
306  */
307 //=============================================================================
308 bool XAOPlugin_IOperations::ExportXAO( Handle(GEOM_Object) shape,
309                                        std::list<Handle(GEOM_Object)> groupList,
310                                        std::list<Handle(GEOM_Field)> fieldList,
311                                        const char* author,
312                                        const char* fileName )
313 {
314   SetErrorCode(KO);
315
316   if (shape.IsNull()) return false;
317
318   // add a new shape function with parameters
319   Handle(GEOM_Function) lastFunction = shape->GetLastFunction();
320   if (lastFunction.IsNull()) return false;
321
322   // add a new result object
323   Handle(GEOM_Object) result = GetEngine()->AddObject(GetDocID(), GEOM_IMPORT);
324
325   // add an Export function
326   Handle(GEOM_Function) exportFunction = result->AddFunction(XAOPlugin_Driver::GetID(), EXPORT_SHAPE);
327   if (exportFunction.IsNull()) return false;
328   if (exportFunction->GetDriverGUID() != XAOPlugin_Driver::GetID()) return false;
329
330   // create the XAO object
331   XAO::Xao* xaoObject = new XAO::Xao();
332   xaoObject->setAuthor(author);
333
334   // add the geometry
335   XAO::BrepGeometry* geometry = (XAO::BrepGeometry*)XAO::Geometry::createGeometry(XAO::BREP);
336   TopoDS_Shape topoShape = shape->GetValue();
337   exportFunction->SetValue(topoShape);
338   XAO::BrepGeometry* brep = (XAO::BrepGeometry*)geometry;
339   brep->setTopoDS_Shape(topoShape);
340
341   geometry->setName(shape->GetName().ToCString());
342   exportSubshapes(shape, geometry);
343   xaoObject->setGeometry(geometry);
344
345   if (!exportGroups(groupList, xaoObject, geometry)) return false;
346   exportFields(fieldList, xaoObject, geometry);
347
348   // export the XAO to the file
349   xaoObject->exportXAO(fileName);
350
351   // make a Python command
352   GEOM::TPythonDump pd(exportFunction);
353   pd << "exported = geompy.ExportXAO(" << shape;
354
355   // list of groups
356   pd << ", [";
357   if (groupList.size() > 0)
358   {
359     std::list<Handle(GEOM_Object)>::iterator itGroup = groupList.begin();
360     pd << (*itGroup++);
361     while (itGroup != groupList.end())
362     {
363       pd << ", " << (*itGroup++);
364     }
365   }
366
367   // list of fields
368   pd << "], [";
369   if (fieldList.size() > 0)
370   {
371     std::list<Handle(GEOM_Field)>::iterator itField = fieldList.begin();
372     pd << (*itField++);
373     while (itField != fieldList.end())
374     {
375       pd << ", " << (*itField++);
376     }
377   }
378   pd << "], ";
379   pd << "\"" << author << "\", \"" << fileName << "\")";
380
381   SetErrorCode(OK);
382   delete xaoObject;
383
384   return true;
385 }
386
387 void XAOPlugin_IOperations::importSubShapes( XAO::Geometry* xaoGeometry,
388                                              Handle(GEOM_Function) function, int shapeType, int dim,
389                                              Handle(TColStd_HSequenceOfTransient)& subShapeList )
390 {
391   Handle(GEOM_Object) subShape;
392   Handle(GEOM_Function) aFunction;
393   Handle(TColStd_HArray1OfInteger) anArray;
394
395   XAO::GeometricElementList::iterator elementIterator = xaoGeometry->begin((XAO::Dimension)dim);
396   for (; elementIterator != xaoGeometry->end((XAO::Dimension)dim); elementIterator++)
397   {
398     XAO::GeometricElement element = elementIterator->second;
399     if (!element.hasName())
400       continue;
401
402     std::string name = element.getName();
403     std::string ref = element.getReference();
404     int iref = XAO::XaoUtils::stringToInt(ref);
405
406     anArray = new TColStd_HArray1OfInteger(1, 1);
407     anArray->SetValue(1, iref);
408
409     subShape = GetEngine()->AddObject(GetDocID(), GEOM_SUBSHAPE);
410     Handle(GEOM_Function) aFunction = subShape->AddFunction(GEOM_Object::GetSubShapeID(), 1);
411     if (aFunction.IsNull())
412       return;
413
414     subShape->SetName(name.c_str());
415     subShape->SetType(shapeType);
416
417     GEOM_ISubShape aSSI(aFunction);
418     aSSI.SetMainShape(function);
419     aSSI.SetIndices(anArray);
420
421     //aFunction->SetValue(aValue);
422     subShapeList->Append(subShape);
423
424     // Put this subshape in the list of sub-shapes of theMainShape
425     function->AddSubShapeReference(aFunction);
426   }
427 }
428
429 //=============================================================================
430 /*!
431  *  Import a shape from XAO format
432  *  \param fileName The name of the file to import
433  *  \param shape The imported shape
434  *  \param subShapes The list of imported groups
435  *  \param groups The list of imported groups
436  *  \param fields The list of imported fields
437  *  \return boolean indicating if import was succeful.
438  */
439 //=============================================================================
440 bool XAOPlugin_IOperations::ImportXAO( const char* fileName,
441                                        Handle(GEOM_Object)& shape,
442                                        Handle(TColStd_HSequenceOfTransient)& subShapes,
443                                        Handle(TColStd_HSequenceOfTransient)& groups,
444                                        Handle(TColStd_HSequenceOfTransient)& fields )
445 {
446   SetErrorCode(KO);
447
448   if (fileName == NULL || groups.IsNull() || fields.IsNull())
449     return false;
450
451   // Read the XAO
452   XAO::Xao* xaoObject = new XAO::Xao();
453   try
454   {
455     xaoObject->importXAO(fileName);
456   }
457   catch (XAO::XAO_Exception& exc)
458   {
459     delete xaoObject;
460     SetErrorCode(exc.what());
461     return false;
462   }
463
464   XAO::Geometry* xaoGeometry = xaoObject->getGeometry();
465   if (xaoGeometry == NULL)
466   {
467     delete xaoObject;
468     SetErrorCode("Cannot import XAO: geometry format not supported.");
469     return false;
470   }
471
472   // create the shape
473   shape = GetEngine()->AddObject(GetDocID(), GEOM_IMPORT);
474   Handle(GEOM_Function) function = shape->AddFunction(XAOPlugin_Driver::GetID(), IMPORT_SHAPE);
475   if (function.IsNull()) return false;
476   if (function->GetDriverGUID() != XAOPlugin_Driver::GetID()) return false;
477
478   function->SetString( XAOPlugin_Driver::GetFileNameTag(), fileName );
479
480   // set the geometry
481   if (xaoGeometry->getFormat() == XAO::BREP)
482   {
483     XAO::BrepGeometry* brep = (XAO::BrepGeometry*)xaoGeometry;
484     TopoDS_Shape geomShape = brep->getTopoDS_Shape();
485     function->SetValue(geomShape);
486     shape->SetName(xaoGeometry->getName().c_str());
487   }
488   else
489   {
490     delete xaoObject;
491     SetErrorCode("Cannot import XAO: geometry format not supported.");
492     return false;
493   }
494
495   // create sub shapes with names
496   importSubShapes(xaoGeometry, function, GEOM_POINT, XAO::VERTEX, subShapes);
497   importSubShapes(xaoGeometry, function, GEOM_EDGE, XAO::EDGE, subShapes);
498   importSubShapes(xaoGeometry, function, GEOM_FACE, XAO::FACE, subShapes);
499   importSubShapes(xaoGeometry, function, GEOM_SOLID, XAO::SOLID, subShapes);
500
501   // create groups
502   int nbGroups = xaoObject->countGroups();
503   for (int i = 0; i < nbGroups; ++i)
504   {
505     XAO::Group* xaoGroup = xaoObject->getGroup(i);
506
507     // build an array with the indexes of the sub shapes
508     int nbElt = xaoGroup->count();
509     Handle(TColStd_HArray1OfInteger) array = new TColStd_HArray1OfInteger(1, nbElt);
510     int j = 0;
511     for (std::set<int>::iterator it = xaoGroup->begin(); it != xaoGroup->end(); ++it)
512     {
513       int index = (*it);
514       std::string ref = xaoGeometry->getElementReference(xaoGroup->getDimension(), index);
515       array->SetValue(++j, XAO::XaoUtils::stringToInt(ref));
516     }
517
518     // create the group with the array of sub shapes indexes
519     Handle(GEOM_Object) group = GetEngine()->AddSubShape(shape, array);
520     group->SetType(GEOM_GROUP);
521     group->SetName(xaoGroup->getName().c_str());
522
523     // Set a sub-shape type
524     TDF_Label freeLabel = group->GetFreeLabel();
525     TDataStd_Integer::Set(freeLabel, (Standard_Integer) getGroupDimension(xaoGroup));
526     groups->Append(group);
527
528     function = group->GetLastFunction();
529   }
530
531   // create the fields
532   int nbFields = xaoObject->countFields();
533   for (int i = 0; i < nbFields; ++i)
534   {
535     XAO::Field* xaoField = xaoObject->getField(i);
536
537     Handle(TColStd_HArray1OfExtendedString) components = new TColStd_HArray1OfExtendedString(0, xaoField->countComponents()-1);
538     for (int j = 0; j < xaoField->countComponents(); ++j)
539     {
540         components->SetValue(j, (TCollection_ExtendedString)xaoField->getComponentName(j).c_str());
541     }
542
543     Handle(GEOM_Field) field = myFieldOperations->CreateField(shape,
544                  xaoField->getName().c_str(),
545                  (int)xaoField->getType(),
546                  (int)xaoField->getDimension(),
547                  components);
548
549     switch (xaoField->getType())
550     {
551         case XAO::BOOLEAN:
552         {
553             XAO::BooleanField* bfield = (XAO::BooleanField*)xaoField;
554             for (int j = 0; j < xaoField->countSteps(); ++j)
555             {
556                 XAO::BooleanStep* bstep = bfield->getStep(j);
557                 Handle(GEOM_FieldStep) step = field->AddStep(bstep->getStep(), bstep->getStamp());
558
559                 Handle(TColStd_HArray1OfInteger) values = new TColStd_HArray1OfInteger(0, bstep->countValues()-1);
560                 std::vector<bool> bvalues = bstep->getValues();
561                 for (int k = 0; k < bstep->countValues(); ++k)
562                 {
563                     values->SetValue(k, bvalues[k] ? 1 : 0);
564                 }
565                 step->SetValues(values);
566             }
567             break;
568         }
569         case XAO::INTEGER:
570         {
571             XAO::IntegerField* ifield = (XAO::IntegerField*)xaoField;
572             for (int j = 0; j < xaoField->countSteps(); ++j)
573             {
574                 XAO::IntegerStep* istep = ifield->getStep(j);
575                 Handle(GEOM_FieldStep) step = field->AddStep(istep->getStep(), istep->getStamp());
576
577                 Handle(TColStd_HArray1OfInteger) values = new TColStd_HArray1OfInteger(0, istep->countValues()-1);
578                 std::vector<int> ivalues = istep->getValues();
579                 for (int k = 0; k < istep->countValues(); ++k)
580                 {
581                     values->SetValue(k, ivalues[k]);
582                 }
583                 step->SetValues(values);
584             }
585             break;
586         }
587         case XAO::DOUBLE:
588         {
589             XAO::DoubleField* dfield = (XAO::DoubleField*)xaoField;
590             for (int j = 0; j < xaoField->countSteps(); ++j)
591             {
592                 XAO::DoubleStep* dstep = dfield->getStep(j);
593                 Handle(GEOM_FieldStep) step = field->AddStep(dstep->getStep(), dstep->getStamp());
594
595                 Handle(TColStd_HArray1OfReal) values = new TColStd_HArray1OfReal(0, dstep->countValues()-1);
596                 std::vector<double> dvalues = dstep->getValues();
597                 for (int k = 0; k < dstep->countValues(); ++k)
598                 {
599                     values->SetValue(k, dvalues[k]);
600                 }
601                 step->SetValues(values);
602             }
603             break;
604         }
605         case XAO::STRING:
606         {
607             XAO::StringField* sfield = (XAO::StringField*)xaoField;
608             for (int j = 0; j < xaoField->countSteps(); ++j)
609             {
610                 XAO::StringStep* sstep = sfield->getStep(j);
611                 Handle(GEOM_FieldStep) step = field->AddStep(sstep->getStep(), sstep->getStamp());
612
613                 Handle(TColStd_HArray1OfExtendedString) values = new TColStd_HArray1OfExtendedString(0, sstep->countValues()-1);
614                 std::vector<std::string> svalues = sstep->getValues();
615                 for (int k = 0; k < sstep->countValues(); ++k)
616                 {
617                     values->SetValue(k, TCollection_ExtendedString(svalues[k].c_str()));
618                 }
619                 step->SetValues(values);
620             }
621             break;
622         }
623     }
624
625     fields->Append(field);
626   }
627
628   // make a Python command
629   GEOM::TPythonDump pd(function);
630   pd << "(imported, " << shape << ", ";
631
632   // list of sub shapes
633   pd << "[";
634   int nbSubshapes = subShapes->Length();
635   if (nbSubshapes > 0)
636   {
637     for (int i = 1; i <= nbSubshapes; i++)
638     {
639       Handle(GEOM_Object) obj = Handle(GEOM_Object)::DownCast(subShapes->Value(i));
640       pd << obj << ((i < nbSubshapes) ? ", " : "");
641     }
642   }
643   pd << "], [";
644
645   // list of groups
646   if (nbGroups > 0)
647   {
648     for (int i = 1; i <= nbGroups; i++)
649     {
650       Handle(GEOM_Object) obj = Handle(GEOM_Object)::DownCast(groups->Value(i));
651       pd << obj << ((i < nbGroups) ? ", " : "");
652     }
653   }
654
655   pd << "], [";
656
657   // list of fields
658   if (nbFields > 0)
659   {
660     for (int i = 1; i <= nbFields; i++)
661     {
662       Handle(GEOM_Field) obj = Handle(GEOM_Field)::DownCast(fields->Value(i));
663       pd << obj << ((i < nbFields) ? ", " : "");
664     }
665   }
666   pd << "]";
667   pd << ") = geompy.ImportXAO(\"" << fileName << "\")";
668
669   delete xaoObject;
670   SetErrorCode(OK);
671
672   return true;
673 }