Salome HOME
f38b1c60532e0bced2f5491a4bf4ea430209f903
[modules/shaper.git] / src / ExchangePlugin / ExchangePlugin_ExportFeature.cpp
1 // Copyright (C) 2014-2019  CEA/DEN, EDF R&D
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 #include <ExchangePlugin_ExportFeature.h>
21
22 #include <algorithm>
23 #include <iterator>
24 #include <string>
25 #ifdef _DEBUG
26 #include <iostream>
27 #include <ostream>
28 #endif
29
30 #include <Config_Common.h>
31 #include <Config_PropManager.h>
32
33 #include <GeomAlgoAPI_BREPExport.h>
34 #include <GeomAlgoAPI_CompoundBuilder.h>
35 #include <GeomAlgoAPI_IGESExport.h>
36 #include <GeomAlgoAPI_STEPExport.h>
37 #include <GeomAlgoAPI_Tools.h>
38 #include <GeomAlgoAPI_XAOExport.h>
39
40 #include <GeomAPI_Shape.h>
41 #include <GeomAPI_ShapeExplorer.h>
42
43 #include <ModelAPI_AttributeSelectionList.h>
44 #include <ModelAPI_AttributeString.h>
45 #include <ModelAPI_AttributeStringArray.h>
46 #include <ModelAPI_AttributeIntArray.h>
47 #include <ModelAPI_AttributeTables.h>
48 #include <ModelAPI_Data.h>
49 #include <ModelAPI_Document.h>
50 #include <ModelAPI_Object.h>
51 #include <ModelAPI_ResultBody.h>
52 #include <ModelAPI_ResultPart.h>
53 #include <ModelAPI_ResultGroup.h>
54 #include <ModelAPI_ResultField.h>
55 #include <ModelAPI_Session.h>
56 #include <ModelAPI_Validator.h>
57 #include <ModelAPI_Tools.h>
58
59 #include <Events_InfoMessage.h>
60
61 #include <XAO_Group.hxx>
62 #include <XAO_Field.hxx>
63 #include <XAO_Xao.hxx>
64 #include <XAO_Geometry.hxx>
65
66 #include <ExchangePlugin_Tools.h>
67
68 ExchangePlugin_ExportFeature::ExchangePlugin_ExportFeature()
69 {
70 }
71
72 ExchangePlugin_ExportFeature::~ExchangePlugin_ExportFeature()
73 {
74   // TODO Auto-generated destructor stub
75 }
76
77 /*
78  * Request for initialization of data model of the feature: adding all attributes
79  */
80 void ExchangePlugin_ExportFeature::initAttributes()
81 {
82   data()->addAttribute(ExchangePlugin_ExportFeature::EXPORT_TYPE_ID(),
83     ModelAPI_AttributeString::typeId());
84   data()->addAttribute(ExchangePlugin_ExportFeature::FILE_PATH_ID(),
85     ModelAPI_AttributeString::typeId());
86   data()->addAttribute(ExchangePlugin_ExportFeature::XAO_FILE_PATH_ID(),
87     ModelAPI_AttributeString::typeId());
88   data()->addAttribute(ExchangePlugin_ExportFeature::FILE_FORMAT_ID(),
89     ModelAPI_AttributeString::typeId());
90   data()->addAttribute(ExchangePlugin_ExportFeature::SELECTION_LIST_ID(),
91     ModelAPI_AttributeSelectionList::typeId());
92   data()->addAttribute(ExchangePlugin_ExportFeature::XAO_AUTHOR_ID(),
93     ModelAPI_AttributeString::typeId());
94   data()->addAttribute(ExchangePlugin_ExportFeature::XAO_GEOMETRY_NAME_ID(),
95     ModelAPI_AttributeString::typeId());
96
97   ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(),
98     ExchangePlugin_ExportFeature::XAO_FILE_PATH_ID());
99   ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(),
100     ExchangePlugin_ExportFeature::XAO_AUTHOR_ID());
101   ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(),
102     ExchangePlugin_ExportFeature::XAO_GEOMETRY_NAME_ID());
103 }
104
105 void ExchangePlugin_ExportFeature::attributeChanged(const std::string& theID)
106 {
107   if (theID == XAO_FILE_PATH_ID()) {
108     string(ExchangePlugin_ExportFeature::FILE_PATH_ID())->setValue(
109       string(ExchangePlugin_ExportFeature::XAO_FILE_PATH_ID())->value());
110   }
111 }
112
113 /*
114  * Computes or recomputes the results
115  */
116 void ExchangePlugin_ExportFeature::execute()
117 {
118   AttributeStringPtr aFormatAttr =
119       this->string(ExchangePlugin_ExportFeature::FILE_FORMAT_ID());
120   std::string aFormat = aFormatAttr->value();
121
122   AttributeStringPtr aFilePathAttr =
123       this->string(ExchangePlugin_ExportFeature::FILE_PATH_ID());
124   std::string aFilePath = aFilePathAttr->value();
125   if (aFilePath.empty())
126     return;
127
128   exportFile(aFilePath, aFormat);
129 }
130
131 void ExchangePlugin_ExportFeature::exportFile(const std::string& theFileName,
132                                               const std::string& theFormat)
133 {
134   std::string aFormatName = theFormat;
135
136   if (aFormatName.empty()) { // get default format for the extension
137     // ".brep" -> "BREP"
138     std::string anExtension = GeomAlgoAPI_Tools::File_Tools::extension(theFileName);
139     if (anExtension == "BREP" || anExtension == "BRP") {
140       aFormatName = "BREP";
141     } else if (anExtension == "STEP" || anExtension == "STP") {
142       aFormatName = "STEP";
143     } else if (anExtension == "IGES" || anExtension == "IGS") {
144       aFormatName = "IGES-5.1";
145     } else {
146       aFormatName = anExtension;
147     }
148   }
149
150   if (aFormatName == "XAO") {
151     exportXAO(theFileName);
152     return;
153   }
154
155   // make shape for export from selected shapes
156   AttributeSelectionListPtr aSelectionListAttr =
157       this->selectionList(ExchangePlugin_ExportFeature::SELECTION_LIST_ID());
158   std::list<GeomShapePtr> aShapes;
159   for (int i = 0, aSize = aSelectionListAttr->size(); i < aSize; ++i) {
160     AttributeSelectionPtr anAttrSelection = aSelectionListAttr->value(i);
161     std::shared_ptr<GeomAPI_Shape> aCurShape = anAttrSelection->value();
162     if (aCurShape.get() == NULL)
163       aCurShape = anAttrSelection->context()->shape();
164     if (aCurShape.get() != NULL)
165       aShapes.push_back(aCurShape);
166   }
167
168   // Store compound if we have more than one shape.
169   std::shared_ptr<GeomAPI_Shape> aShape =
170     aShapes.size() == 1 ? aShapes.front() : GeomAlgoAPI_CompoundBuilder::compound(aShapes);
171
172   // Perform the export
173   std::string anError;
174   bool aResult = false;
175   if (aFormatName == "BREP") {
176     aResult = BREPExport(theFileName, aFormatName, aShape, anError);
177   } else if (aFormatName == "STEP") {
178     aResult = STEPExport(theFileName, aFormatName, aShape, anError);
179   } else if (aFormatName.substr(0, 4) == "IGES") {
180     aResult = IGESExport(theFileName, aFormatName, aShape, anError);
181   } else {
182     anError = "Unsupported format: " + aFormatName;
183   }
184
185   if (!anError.empty()) {
186     setError("An error occurred while exporting " + theFileName + ": " + anError);
187     return;
188   }
189 }
190
191 /// Returns XAO string by the value from the table
192 static std::string valToString(const ModelAPI_AttributeTables::Value& theVal,
193   const ModelAPI_AttributeTables::ValueType& theType) {
194   std::ostringstream aStr; // the resulting string value
195   switch(theType) {
196   case ModelAPI_AttributeTables::BOOLEAN:
197     aStr<<(theVal.myBool ? "true" : "false");
198     break;
199   case ModelAPI_AttributeTables::INTEGER:
200     aStr<<theVal.myInt;
201     break;
202   case ModelAPI_AttributeTables::DOUBLE:
203     aStr<<theVal.myDouble;
204     break;
205   case ModelAPI_AttributeTables::STRING:
206     aStr<<theVal.myStr;
207     break;
208   }
209   return aStr.str();
210 }
211
212 /// Returns true if something in selection is presented in the results list
213 static bool isInResults(AttributeSelectionListPtr theSelection,
214                         const std::list<ResultPtr>& theResults,
215                         std::set<ResultPtr>& theCashedResults)
216 {
217   // collect all results into a cashed set
218   if (theCashedResults.empty()) {
219     std::list<ResultPtr> aResults;
220     std::list<ResultPtr>::const_iterator aRes = theResults.cbegin();
221     for(; aRes != theResults.cend(); aRes++) {
222       if (theCashedResults.count(*aRes))
223         continue;
224       else
225         theCashedResults.insert(*aRes);
226       if ((*aRes)->groupName() == ModelAPI_ResultBody::group()) {
227         ResultBodyPtr aResBody = std::dynamic_pointer_cast<ModelAPI_ResultBody>(*aRes);
228         std::list<ResultPtr> aResults;
229         ModelAPI_Tools::allSubs(aResBody, aResults, false);
230         for(std::list<ResultPtr>::iterator aR = aResults.begin(); aR != aResults.end(); aR++) {
231           theCashedResults.insert(std::dynamic_pointer_cast<ModelAPI_ResultBody>(*aR));
232         }
233       } else if ((*aRes)->groupName() == ModelAPI_ResultPart::group()) { // all results of the part
234         ResultPartPtr aResPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(*aRes);
235         DocumentPtr aPartDoc = aResPart->partDoc();
236         if (!aPartDoc.get() || !aPartDoc->isOpened()) { // document is not accessible
237           return false;
238         }
239         int aBodyCount = aPartDoc->size(ModelAPI_ResultBody::group());
240         for (int aBodyIndex = 0; aBodyIndex < aBodyCount; ++aBodyIndex) {
241           ResultBodyPtr aResBody =
242             std::dynamic_pointer_cast<ModelAPI_ResultBody>(
243               aPartDoc->object(ModelAPI_ResultBody::group(), aBodyIndex));
244           if (aResBody.get()) {
245             theCashedResults.insert(aResBody);
246             std::list<ResultPtr> aResults;
247             ModelAPI_Tools::allSubs(aResBody, aResults, false);
248             for(std::list<ResultPtr>::iterator aR = aResults.begin(); aR != aResults.end(); aR++) {
249               theCashedResults.insert(std::dynamic_pointer_cast<ModelAPI_ResultBody>(*aR));
250             }
251           }
252         }
253       }
254     }
255   }
256   // if context is in results, return true
257   for(int a = 0; a < theSelection->size(); a++) {
258     AttributeSelectionPtr anAttr = theSelection->value(a);
259     ResultPtr aContext = anAttr->context();
260     // check is it group selected for groups BOP
261     if (aContext.get() && aContext->groupName() == ModelAPI_ResultGroup::group()) {
262       // it is impossible by used results check which result is used in this group result,
263       // so check the results shapes is it in results of this document or not
264       FeaturePtr aSelFeature =
265         std::dynamic_pointer_cast<ModelAPI_Feature>(theSelection->owner());
266       if (!aSelFeature.get() || aSelFeature->results().empty())
267         continue;
268       GeomShapePtr aGroupResShape = aSelFeature->firstResult()->shape();
269
270       std::set<ResultPtr>::iterator allResultsIter = theCashedResults.begin();
271       for(; allResultsIter != theCashedResults.end(); allResultsIter++) {
272         GeomShapePtr aResultShape = (*allResultsIter)->shape();
273
274         GeomAPI_Shape::ShapeType aType =
275           GeomAPI_Shape::shapeTypeByStr(theSelection->selectionType());
276         GeomAPI_ShapeExplorer aGroupResExp(aGroupResShape, aType);
277         for(; aGroupResExp.more(); aGroupResExp.next()) {
278           if (aResultShape->isSubShape(aGroupResExp.current(), false))
279             return true; // at least one shape of the group is in the used results
280         }
281       }
282     }
283     ResultBodyPtr aSelected = std::dynamic_pointer_cast<ModelAPI_ResultBody>(anAttr->context());
284     if (!aSelected.get()) { // try to get selected feature and all its results
285       FeaturePtr aContextFeature = anAttr->contextFeature();
286       if (aContextFeature.get() && !aContextFeature->results().empty()) {
287         const std::list<ResultPtr>& allResluts = aContextFeature->results();
288         std::list<ResultPtr>::const_iterator aResIter = allResluts.cbegin();
289         for(; aResIter != allResluts.cend(); aResIter++) {
290           if (aResIter->get() && theCashedResults.count(*aResIter))
291             return true;
292         }
293       }
294     } else if (aSelected.get() && theCashedResults.count(aSelected))
295       return true;
296   }
297   return false;
298 }
299
300 /// Returns all sub-shapes of the given shape in theResult
301 static void allSubShapes(const GeomShapePtr theShape, GeomAPI_Shape::ShapeType theType,
302   std::list<GeomShapePtr>& theResult)
303 {
304   if (theShape->shapeType() == theType) {
305     theResult.push_back(theShape);
306   } else {
307     GeomAPI_DataMapOfShapeShape aUnique; // to keep only unique shapes
308     for(GeomAPI_ShapeExplorer anExp(theShape, theType); anExp.more(); anExp.next()) {
309       if (aUnique.bind(anExp.current(), anExp.current()))
310         theResult.push_back(anExp.current());
311     }
312   }
313 }
314
315 void ExchangePlugin_ExportFeature::exportXAO(const std::string& theFileName)
316 {
317   try {
318
319   std::string anError;
320   XAO::Xao aXao;
321
322   // author
323
324   std::string anAuthor = string(ExchangePlugin_ExportFeature::XAO_AUTHOR_ID())->value();
325   aXao.setAuthor(anAuthor);
326
327   // make shape for export from all results
328   std::list<GeomShapePtr> aShapes;
329   std::list<ResultPtr> aResults;
330   std::list<DocumentPtr> aDocuments; /// documents of Parts selected and used in export
331
332   AttributeSelectionListPtr aSelection = selectionList(SELECTION_LIST_ID());
333   bool aIsSelection = aSelection->isInitialized() && aSelection->size() > 0;
334   if (aIsSelection) { // a mode for export to geom result by result
335     for(int a = 0; a < aSelection->size(); a++) {
336       AttributeSelectionPtr anAttr = aSelection->value(a);
337       ResultPtr aBodyContext =
338         std::dynamic_pointer_cast<ModelAPI_Result>(anAttr->context());
339       if (aBodyContext.get() && !aBodyContext->isDisabled() && aBodyContext->shape().get()) {
340         aResults.push_back(aBodyContext);
341         GeomShapePtr aShape = anAttr->value();
342         if (!aShape.get())
343           aShape = aBodyContext->shape();
344         aShapes.push_back(aShape);
345         if (aBodyContext->groupName() == ModelAPI_ResultPart::group()) {
346           ResultPartPtr aResPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aBodyContext);
347           DocumentPtr aPartDoc = aResPart->partDoc();
348           if (!aPartDoc.get() || !aPartDoc->isOpened()) { // document is not accessible
349             std::string msg = "Can not export XAO for not loaded part";
350             Events_InfoMessage("ExportFeature", msg, this).send();
351             return;
352           } else {
353             aDocuments.push_back(aPartDoc);
354           }
355         }
356       }
357     }
358   } else {
359     int aBodyCount = document()->size(ModelAPI_ResultBody::group());
360     for (int aBodyIndex = 0; aBodyIndex < aBodyCount; ++aBodyIndex) {
361       ResultBodyPtr aResultBody =
362           std::dynamic_pointer_cast<ModelAPI_ResultBody>(
363               document()->object(ModelAPI_ResultBody::group(), aBodyIndex));
364       if (!aResultBody.get())
365         continue;
366       aShapes.push_back(aResultBody->shape());
367       aResults.push_back(aResultBody);
368     }
369   }
370   if (aShapes.empty()) {
371     setError("No shapes to export");
372     return;
373   }
374
375
376   GeomShapePtr aShape = (aShapes.size() == 1)
377       ? *aShapes.begin()
378       : GeomAlgoAPI_CompoundBuilder::compound(aShapes);
379
380   SetShapeToXAO(aShape, &aXao, anError);
381
382   if (!anError.empty()) {
383     setError("An error occurred while exporting " + theFileName + ": " + anError);
384     return;
385   }
386
387   // geometry name
388   std::string aGeometryName = string(ExchangePlugin_ExportFeature::XAO_GEOMETRY_NAME_ID())->value();
389   if (aGeometryName.empty() && aResults.size() == 1) {
390     // get the name from the first result
391     ResultPtr aResultBody = *aResults.begin();
392     aGeometryName = aResultBody->data()->name();
393   }
394
395   aXao.getGeometry()->setName(aGeometryName);
396
397   std::set<ResultPtr> allResultsCashed; // cash to speed up searching in all results selected
398
399   // iterate all documents used
400   if (aDocuments.empty())
401     aDocuments.push_back(document());
402   std::list<DocumentPtr>::iterator aDoc = aDocuments.begin();
403   for(; aDoc != aDocuments.end(); aDoc++) {
404     // groups
405     int aGroupCount = (*aDoc)->size(ModelAPI_ResultGroup::group());
406     for (int aGroupIndex = 0; aGroupIndex < aGroupCount; ++aGroupIndex) {
407       ResultGroupPtr aResultGroup = std::dynamic_pointer_cast<ModelAPI_ResultGroup>(
408           (*aDoc)->object(ModelAPI_ResultGroup::group(), aGroupIndex));
409       if (!aResultGroup.get() || !aResultGroup->shape().get())
410         continue;
411
412       FeaturePtr aGroupFeature = (*aDoc)->feature(aResultGroup);
413
414       AttributeSelectionListPtr aSelectionList =
415           aGroupFeature->selectionList("group_list");
416       if (!isInResults(aSelectionList, aResults, allResultsCashed))// skip group not used in result
417         continue;
418
419       // conversion of dimension
420       std::string aSelectionType = aSelectionList->selectionType();
421       GeomAPI_Shape::ShapeType aSelType = GeomAPI_Shape::shapeTypeByStr(aSelectionType);
422       std::string aDimensionString =
423         ExchangePlugin_Tools::selectionType2xaoDimension(aSelectionType);
424       XAO::Dimension aGroupDimension = XAO::XaoUtils::stringToDimension(aDimensionString);
425
426       XAO::Group* aXaoGroup = aXao.addGroup(aGroupDimension,
427                                             aResultGroup->data()->name());
428
429       try {
430         GeomAPI_ShapeExplorer aGroupResExplorer(aResultGroup->shape(), aSelType);
431         for(; aGroupResExplorer.more(); aGroupResExplorer.next()) {
432           int aReferenceID = GeomAlgoAPI_CompoundBuilder::id(aShape, aGroupResExplorer.current());
433           if (aReferenceID == 0) // selected value does not found in the exported shape
434             continue;
435           std::string aReferenceString = XAO::XaoUtils::intToString(aReferenceID);
436           int anElementID =
437             aXao.getGeometry()->getElementIndexByReference(aGroupDimension, aReferenceString);
438           aXaoGroup->add(anElementID);
439         }
440       } catch (XAO::XAO_Exception& e) {
441         // LCOV_EXCL_START
442         std::string msg = "An error occurred while exporting group " +
443           aResultGroup->data()->name();
444         msg += ".\n";
445         msg += e.what();
446         msg += "\n";
447         msg += "=> skipping this group from XAO export.";
448         Events_InfoMessage("ExportFeature", msg, this).send();
449         aXao.removeGroup(aXaoGroup);
450         // LCOV_EXCL_STOP
451       }
452     }
453
454     // fields
455     int aFieldCount = (*aDoc)->size(ModelAPI_ResultField::group());
456     for (int aFieldIndex = 0; aFieldIndex < aFieldCount; ++aFieldIndex) {
457       ResultFieldPtr aResultField = std::dynamic_pointer_cast<ModelAPI_ResultField>(
458         (*aDoc)->object(ModelAPI_ResultField::group(), aFieldIndex));
459
460       FeaturePtr aFieldFeature = (*aDoc)->feature(aResultField);
461
462       AttributeSelectionListPtr aSelectionList =
463           aFieldFeature->selectionList("selected");
464       std::string aSelectionType = aSelectionList->selectionType();
465       bool isWholePart = aSelectionType == "part";
466       // skip field not used in results
467       if (!isWholePart && !isInResults(aSelectionList, aResults, allResultsCashed))
468         continue;
469
470       // conversion of dimension
471       std::string aDimensionString =
472         ExchangePlugin_Tools::selectionType2xaoDimension(aSelectionType);
473       XAO::Dimension aFieldDimension = XAO::XaoUtils::stringToDimension(aDimensionString);
474       // get tables and their type
475       std::shared_ptr<ModelAPI_AttributeTables> aTables = aFieldFeature->tables("values");
476       std::string aTypeString = ExchangePlugin_Tools::valuesType2xaoType(aTables->type());
477       XAO::Type aFieldType = XAO::XaoUtils::stringToFieldType(aTypeString);
478
479       XAO::Field* aXaoField = aXao.addField(aFieldType, aFieldDimension, aTables->columns(),
480                                             aResultField->data()->name());
481
482
483       try {
484         // set components names
485         AttributeStringArrayPtr aComponents = aFieldFeature->stringArray("components_names");
486         for(int aComp = 0; aComp < aComponents->size(); aComp++) {
487           std::string aName = aComponents->value(aComp);
488           aXaoField->setComponentName(aComp, aName);
489         }
490
491         AttributeIntArrayPtr aStamps = aFieldFeature->intArray("stamps");
492         for (int aStepIndex = 0; aStepIndex < aTables->tables(); aStepIndex++) {
493           XAO::Step* aStep = aXaoField->addNewStep(aStepIndex + 1);
494           aStep->setStep(aStepIndex + 1);
495           int aStampIndex = aStamps->value(aStepIndex);
496           aStep->setStamp(aStampIndex);
497           int aNumElements = isWholePart ? aXaoField->countElements() : aTables->rows();
498           int aNumComps = aTables->columns();
499           std::set<int> aFilledIDs; // to fill the rest by defaults
500           // omit default values first row
501           for(int aRow = isWholePart ? 0 : 1; aRow < aNumElements; aRow++) {
502             for(int aCol = 0; aCol < aNumComps; aCol++) {
503               int anElementID = 0;
504               if (!isWholePart) {
505                 // element index actually is the ID of the selection
506                 AttributeSelectionPtr aSelection = aSelectionList->value(aRow - 1);
507                 int aReferenceID = GeomAlgoAPI_CompoundBuilder::id(aShape, aSelection->value());
508                 if (aReferenceID == 0) // selected value does not found in the exported shape
509                   continue;
510
511                 std::string aReferenceString = XAO::XaoUtils::intToString(aReferenceID);
512                 anElementID = aXao.getGeometry()->
513                   getElementIndexByReference(aFieldDimension, aReferenceString);
514               }
515
516               ModelAPI_AttributeTables::Value aVal = aTables->value(
517                 isWholePart ? 0 : aRow, aCol, aStepIndex);
518               std::string aStrVal = valToString(aVal, aTables->type());
519               aStep->setStringValue(isWholePart ? aRow : anElementID, aCol, aStrVal);
520               aFilledIDs.insert(anElementID);
521             }
522           }
523           if (!isWholePart) { // fill the rest values by default ones
524             XAO::GeometricElementList::iterator allElem =
525               aXao.getGeometry()->begin(aFieldDimension);
526             for(; allElem != aXao.getGeometry()->end(aFieldDimension); allElem++) {
527               if (aFilledIDs.find(allElem->first) != aFilledIDs.end())
528                 continue;
529               for(int aCol = 0; aCol < aNumComps; aCol++) {
530                 // default value
531                 ModelAPI_AttributeTables::Value aVal = aTables->value(0, aCol, aStepIndex);
532                 std::string aStrVal = valToString(aVal, aTables->type());
533                 aStep->setStringValue(allElem->first, aCol, aStrVal);
534               }
535             }
536           }
537         }
538       } catch (XAO::XAO_Exception& e) {
539         // LCOV_EXCL_START
540         std::string msg = "An error occurred while exporting field " +
541           aResultField->data()->name();
542         msg += ".\n";
543         msg += e.what();
544         msg += "\n";
545         msg += "=> skipping this field from XAO export.";
546         Events_InfoMessage("ExportFeature", msg, this).send();
547         aXao.removeField(aXaoField);
548         // LCOV_EXCL_STOP
549       }
550     }
551   }
552
553   // exporting
554   XAOExport(theFileName, &aXao, anError);
555
556   if (!anError.empty()) {
557     setError("An error occurred while exporting " + theFileName + ": " + anError);
558     return;
559   }
560
561 // LCOV_EXCL_START
562   } catch (XAO::XAO_Exception& e) {
563     std::string anError = e.what();
564     setError("An error occurred while exporting " + theFileName + ": " + anError);
565     return;
566   }
567 // LCOV_EXCL_STOP
568 }
569
570 bool ExchangePlugin_ExportFeature::isMacro() const
571 {
572   if (!data().get() || !data()->isValid())
573     return false;
574   ExchangePlugin_ExportFeature* aThis = ((ExchangePlugin_ExportFeature*)(this));
575   AttributeStringPtr aFormatAttr = aThis->string(FILE_FORMAT_ID());
576   std::string aFormat(aFormatAttr.get() ? aFormatAttr->value() : "");
577
578   if (aFormat.empty()) { // get default format for the extension
579     AttributeStringPtr aFilePathAttr = aThis->string(FILE_PATH_ID());
580     std::string aFilePath = aFilePathAttr->value();
581     if (!aFilePath.empty()) {
582       std::string anExtension = GeomAlgoAPI_Tools::File_Tools::extension(aFilePath);
583       aFormat = anExtension;
584     }
585   }
586
587   if (aFormat == "XAO") { // on export to GEOm the selection attribute is filled - this is
588                           // an exceptional case where export to XAO feature must be kept
589     AttributeSelectionListPtr aList = aThis->selectionList(SELECTION_LIST_ID());
590     return !aList->isInitialized() || aList->size() == 0;
591   }
592   return true;
593 }