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