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