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