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