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