Salome HOME
Merge branch 'hydro/imps_2017' into V8_3_BR
[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                                        const char* shapeFileName )
316 {
317   SetErrorCode(KO);
318
319   if (shape.IsNull()) return false;
320
321   // add a new shape function with parameters
322   Handle(GEOM_Function) lastFunction = shape->GetLastFunction();
323   if (lastFunction.IsNull()) return false;
324
325   // add a new result object
326   Handle(GEOM_Object) result = GetEngine()->AddObject(GetDocID(), GEOM_IMPORT);
327
328   // add an Export function
329   Handle(GEOM_Function) exportFunction = result->AddFunction(XAOPlugin_Driver::GetID(), EXPORT_SHAPE);
330   if (exportFunction.IsNull()) return false;
331   if (exportFunction->GetDriverGUID() != XAOPlugin_Driver::GetID()) return false;
332
333   // create the XAO object
334   XAO::Xao* xaoObject = new XAO::Xao();
335   xaoObject->setAuthor(author);
336
337   // add the geometry
338   XAO::BrepGeometry* geometry = (XAO::BrepGeometry*)XAO::Geometry::createGeometry(XAO::BREP);
339   TopoDS_Shape topoShape = shape->GetValue();
340   exportFunction->SetValue(topoShape);
341   XAO::BrepGeometry* brep = (XAO::BrepGeometry*)geometry;
342   brep->setTopoDS_Shape(topoShape);
343
344   geometry->setName(shape->GetName().ToCString());
345   exportSubshapes(shape, geometry);
346   xaoObject->setGeometry(geometry);
347
348   if (!exportGroups(groupList, xaoObject, geometry)) return false;
349   exportFields(fieldList, xaoObject, geometry);
350
351   // export the XAO to the file
352   xaoObject->exportXAO(fileName, shapeFileName);
353
354   // make a Python command
355   GEOM::TPythonDump pd(exportFunction);
356   pd << "exported = geompy.ExportXAO(" << shape;
357
358   // list of groups
359   pd << ", [";
360   if (groupList.size() > 0)
361   {
362     std::list<Handle(GEOM_Object)>::iterator itGroup = groupList.begin();
363     pd << (*itGroup++);
364     while (itGroup != groupList.end())
365     {
366       pd << ", " << (*itGroup++);
367     }
368   }
369
370   // list of fields
371   pd << "], [";
372   if (fieldList.size() > 0)
373   {
374     std::list<Handle(GEOM_Field)>::iterator itField = fieldList.begin();
375     pd << (*itField++);
376     while (itField != fieldList.end())
377     {
378       pd << ", " << (*itField++);
379     }
380   }
381   pd << "], ";
382   pd << "\"" << author << "\", \"" << fileName << "\", \"" << shapeFileName << "\")";
383
384   SetErrorCode(OK);
385   delete xaoObject;
386
387   return true;
388 }
389
390 void XAOPlugin_IOperations::importSubShapes( XAO::Geometry* xaoGeometry,
391                                              Handle(GEOM_Function) function, int shapeType, int dim,
392                                              Handle(TColStd_HSequenceOfTransient)& subShapeList )
393 {
394   Handle(GEOM_Object) subShape;
395   Handle(GEOM_Function) aFunction;
396   Handle(TColStd_HArray1OfInteger) anArray;
397
398   XAO::GeometricElementList::iterator elementIterator = xaoGeometry->begin((XAO::Dimension)dim);
399   for (; elementIterator != xaoGeometry->end((XAO::Dimension)dim); elementIterator++)
400   {
401     XAO::GeometricElement element = elementIterator->second;
402     if (!element.hasName())
403       continue;
404
405     std::string name = element.getName();
406     std::string ref = element.getReference();
407     int iref = XAO::XaoUtils::stringToInt(ref);
408
409     anArray = new TColStd_HArray1OfInteger(1, 1);
410     anArray->SetValue(1, iref);
411
412     subShape = GetEngine()->AddObject(GetDocID(), GEOM_SUBSHAPE);
413     Handle(GEOM_Function) aFunction = subShape->AddFunction(GEOM_Object::GetSubShapeID(), 1);
414     if (aFunction.IsNull())
415       return;
416
417     subShape->SetName(name.c_str());
418     subShape->SetType(shapeType);
419
420     GEOM_ISubShape aSSI(aFunction);
421     aSSI.SetMainShape(function);
422     aSSI.SetIndices(anArray);
423
424     //aFunction->SetValue(aValue);
425     subShapeList->Append(subShape);
426
427     // Put this subshape in the list of sub-shapes of theMainShape
428     function->AddSubShapeReference(aFunction);
429   }
430 }
431
432 //=============================================================================
433 /*!
434  *  Import a shape from XAO format
435  *  \param fileName The name of the file to import
436  *  \param shape The imported shape
437  *  \param subShapes The list of imported groups
438  *  \param groups The list of imported groups
439  *  \param fields The list of imported fields
440  *  \return boolean indicating if import was succeful.
441  */
442 //=============================================================================
443 bool XAOPlugin_IOperations::ImportXAO( const char* fileName,
444                                        Handle(GEOM_Object)& shape,
445                                        Handle(TColStd_HSequenceOfTransient)& subShapes,
446                                        Handle(TColStd_HSequenceOfTransient)& groups,
447                                        Handle(TColStd_HSequenceOfTransient)& fields )
448 {
449   SetErrorCode(KO);
450
451   if (fileName == NULL || groups.IsNull() || fields.IsNull())
452     return false;
453
454   // Read the XAO
455   XAO::Xao* xaoObject = new XAO::Xao();
456   try
457   {
458     xaoObject->importXAO(fileName);
459   }
460   catch (XAO::XAO_Exception& exc)
461   {
462     delete xaoObject;
463     SetErrorCode(exc.what());
464     return false;
465   }
466
467   XAO::Geometry* xaoGeometry = xaoObject->getGeometry();
468   if (xaoGeometry == NULL)
469   {
470     delete xaoObject;
471     SetErrorCode("Cannot import XAO: geometry format not supported.");
472     return false;
473   }
474
475   // create the shape
476   shape = GetEngine()->AddObject(GetDocID(), GEOM_IMPORT);
477   Handle(GEOM_Function) function = shape->AddFunction(XAOPlugin_Driver::GetID(), IMPORT_SHAPE);
478   if (function.IsNull()) return false;
479   if (function->GetDriverGUID() != XAOPlugin_Driver::GetID()) return false;
480
481   function->SetString( XAOPlugin_Driver::GetFileNameTag(), fileName );
482
483   // set the geometry
484   if (xaoGeometry->getFormat() == XAO::BREP)
485   {
486     XAO::BrepGeometry* brep = (XAO::BrepGeometry*)xaoGeometry;
487     TopoDS_Shape geomShape = brep->getTopoDS_Shape();
488     function->SetValue(geomShape);
489     shape->SetName(xaoGeometry->getName().c_str());
490   }
491   else
492   {
493     delete xaoObject;
494     SetErrorCode("Cannot import XAO: geometry format not supported.");
495     return false;
496   }
497
498   // create sub shapes with names
499   importSubShapes(xaoGeometry, function, GEOM_POINT, XAO::VERTEX, subShapes);
500   importSubShapes(xaoGeometry, function, GEOM_EDGE, XAO::EDGE, subShapes);
501   importSubShapes(xaoGeometry, function, GEOM_FACE, XAO::FACE, subShapes);
502   importSubShapes(xaoGeometry, function, GEOM_SOLID, XAO::SOLID, subShapes);
503
504   // create groups
505   int nbGroups = xaoObject->countGroups();
506   for (int i = 0; i < nbGroups; ++i)
507   {
508     XAO::Group* xaoGroup = xaoObject->getGroup(i);
509
510     // build an array with the indexes of the sub shapes
511     int nbElt = xaoGroup->count();
512     Handle(TColStd_HArray1OfInteger) array = new TColStd_HArray1OfInteger(1, nbElt);
513     int j = 0;
514     for (std::set<int>::iterator it = xaoGroup->begin(); it != xaoGroup->end(); ++it)
515     {
516       int index = (*it);
517       std::string ref = xaoGeometry->getElementReference(xaoGroup->getDimension(), index);
518       array->SetValue(++j, XAO::XaoUtils::stringToInt(ref));
519     }
520
521     // create the group with the array of sub shapes indexes
522     Handle(GEOM_Object) group = GetEngine()->AddSubShape(shape, array);
523     group->SetType(GEOM_GROUP);
524     group->SetName(xaoGroup->getName().c_str());
525
526     // Set a sub-shape type
527     TDF_Label freeLabel = group->GetFreeLabel();
528     TDataStd_Integer::Set(freeLabel, (Standard_Integer) getGroupDimension(xaoGroup));
529     groups->Append(group);
530
531     function = group->GetLastFunction();
532   }
533
534   // create the fields
535   int nbFields = xaoObject->countFields();
536   for (int i = 0; i < nbFields; ++i)
537   {
538     XAO::Field* xaoField = xaoObject->getField(i);
539
540     Handle(TColStd_HArray1OfExtendedString) components = new TColStd_HArray1OfExtendedString(0, xaoField->countComponents()-1);
541     for (int j = 0; j < xaoField->countComponents(); ++j)
542     {
543         components->SetValue(j, (TCollection_ExtendedString)xaoField->getComponentName(j).c_str());
544     }
545
546     Handle(GEOM_Field) field = myFieldOperations->CreateField(shape,
547                  xaoField->getName().c_str(),
548                  (int)xaoField->getType(),
549                  (int)xaoField->getDimension(),
550                  components);
551
552     switch (xaoField->getType())
553     {
554         case XAO::BOOLEAN:
555         {
556             XAO::BooleanField* bfield = (XAO::BooleanField*)xaoField;
557             for (int j = 0; j < xaoField->countSteps(); ++j)
558             {
559                 XAO::BooleanStep* bstep = bfield->getStep(j);
560                 Handle(GEOM_FieldStep) step = field->AddStep(bstep->getStep(), bstep->getStamp());
561
562                 Handle(TColStd_HArray1OfInteger) values = new TColStd_HArray1OfInteger(0, bstep->countValues()-1);
563                 std::vector<bool> bvalues = bstep->getValues();
564                 for (int k = 0; k < bstep->countValues(); ++k)
565                 {
566                     values->SetValue(k, bvalues[k] ? 1 : 0);
567                 }
568                 step->SetValues(values);
569             }
570             break;
571         }
572         case XAO::INTEGER:
573         {
574             XAO::IntegerField* ifield = (XAO::IntegerField*)xaoField;
575             for (int j = 0; j < xaoField->countSteps(); ++j)
576             {
577                 XAO::IntegerStep* istep = ifield->getStep(j);
578                 Handle(GEOM_FieldStep) step = field->AddStep(istep->getStep(), istep->getStamp());
579
580                 Handle(TColStd_HArray1OfInteger) values = new TColStd_HArray1OfInteger(0, istep->countValues()-1);
581                 std::vector<int> ivalues = istep->getValues();
582                 for (int k = 0; k < istep->countValues(); ++k)
583                 {
584                     values->SetValue(k, ivalues[k]);
585                 }
586                 step->SetValues(values);
587             }
588             break;
589         }
590         case XAO::DOUBLE:
591         {
592             XAO::DoubleField* dfield = (XAO::DoubleField*)xaoField;
593             for (int j = 0; j < xaoField->countSteps(); ++j)
594             {
595                 XAO::DoubleStep* dstep = dfield->getStep(j);
596                 Handle(GEOM_FieldStep) step = field->AddStep(dstep->getStep(), dstep->getStamp());
597
598                 Handle(TColStd_HArray1OfReal) values = new TColStd_HArray1OfReal(0, dstep->countValues()-1);
599                 std::vector<double> dvalues = dstep->getValues();
600                 for (int k = 0; k < dstep->countValues(); ++k)
601                 {
602                     values->SetValue(k, dvalues[k]);
603                 }
604                 step->SetValues(values);
605             }
606             break;
607         }
608         case XAO::STRING:
609         {
610             XAO::StringField* sfield = (XAO::StringField*)xaoField;
611             for (int j = 0; j < xaoField->countSteps(); ++j)
612             {
613                 XAO::StringStep* sstep = sfield->getStep(j);
614                 Handle(GEOM_FieldStep) step = field->AddStep(sstep->getStep(), sstep->getStamp());
615
616                 Handle(TColStd_HArray1OfExtendedString) values = new TColStd_HArray1OfExtendedString(0, sstep->countValues()-1);
617                 std::vector<std::string> svalues = sstep->getValues();
618                 for (int k = 0; k < sstep->countValues(); ++k)
619                 {
620                     values->SetValue(k, TCollection_ExtendedString(svalues[k].c_str()));
621                 }
622                 step->SetValues(values);
623             }
624             break;
625         }
626     }
627
628     fields->Append(field);
629   }
630
631   // make a Python command
632   GEOM::TPythonDump pd(function);
633   pd << "(imported, " << shape << ", ";
634
635   // list of sub shapes
636   pd << "[";
637   int nbSubshapes = subShapes->Length();
638   if (nbSubshapes > 0)
639   {
640     for (int i = 1; i <= nbSubshapes; i++)
641     {
642       Handle(GEOM_Object) obj = Handle(GEOM_Object)::DownCast(subShapes->Value(i));
643       pd << obj << ((i < nbSubshapes) ? ", " : "");
644     }
645   }
646   pd << "], [";
647
648   // list of groups
649   if (nbGroups > 0)
650   {
651     for (int i = 1; i <= nbGroups; i++)
652     {
653       Handle(GEOM_Object) obj = Handle(GEOM_Object)::DownCast(groups->Value(i));
654       pd << obj << ((i < nbGroups) ? ", " : "");
655     }
656   }
657
658   pd << "], [";
659
660   // list of fields
661   if (nbFields > 0)
662   {
663     for (int i = 1; i <= nbFields; i++)
664     {
665       Handle(GEOM_Field) obj = Handle(GEOM_Field)::DownCast(fields->Value(i));
666       pd << obj << ((i < nbFields) ? ", " : "");
667     }
668   }
669   pd << "]";
670   pd << ") = geompy.ImportXAO(\"" << fileName << "\")";
671
672   delete xaoObject;
673   SetErrorCode(OK);
674
675   return true;
676 }