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