1 // Copyright (C) 2014-2020 CEA/DEN, EDF R&D
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.
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.
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
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 #include <ExchangePlugin_ExportFeature.h>
31 #include <Config_Common.h>
32 #include <Config_PropManager.h>
34 #include <GeomAlgoAPI_BREPExport.h>
35 #include <GeomAlgoAPI_CompoundBuilder.h>
36 #include <GeomAlgoAPI_IGESExport.h>
37 #include <GeomAlgoAPI_STEPExport.h>
38 #include <GeomAlgoAPI_STLExport.h>
39 #include <GeomAlgoAPI_Tools.h>
40 #include <GeomAlgoAPI_XAOExport.h>
42 #include <GeomAPI_Shape.h>
43 #include <GeomAPI_ShapeExplorer.h>
44 #include <GeomAPI_Trsf.h>
46 #include <Locale_Convert.h>
48 #include <ModelAPI_AttributeSelectionList.h>
49 #include <ModelAPI_AttributeString.h>
50 #include <ModelAPI_AttributeStringArray.h>
51 #include <ModelAPI_AttributeIntArray.h>
52 #include <ModelAPI_AttributeTables.h>
53 #include <ModelAPI_AttributeDouble.h>
54 #include <ModelAPI_Data.h>
55 #include <ModelAPI_Document.h>
56 #include <ModelAPI_Object.h>
57 #include <ModelAPI_ResultBody.h>
58 #include <ModelAPI_ResultPart.h>
59 #include <ModelAPI_ResultGroup.h>
60 #include <ModelAPI_ResultField.h>
61 #include <ModelAPI_Session.h>
62 #include <ModelAPI_Validator.h>
63 #include <ModelAPI_Tools.h>
65 #include <Events_InfoMessage.h>
67 #include <XAO_Group.hxx>
68 #include <XAO_Field.hxx>
69 #include <XAO_Xao.hxx>
70 #include <XAO_Geometry.hxx>
72 #include <ExchangePlugin_Tools.h>
74 ExchangePlugin_ExportFeature::ExchangePlugin_ExportFeature()
78 ExchangePlugin_ExportFeature::~ExchangePlugin_ExportFeature()
80 // TODO Auto-generated destructor stub
84 * Request for initialization of data model of the feature: adding all attributes
86 void ExchangePlugin_ExportFeature::initAttributes()
88 data()->addAttribute(ExchangePlugin_ExportFeature::EXPORT_TYPE_ID(),
89 ModelAPI_AttributeString::typeId());
90 data()->addAttribute(ExchangePlugin_ExportFeature::FILE_PATH_ID(),
91 ModelAPI_AttributeString::typeId());
92 data()->addAttribute(ExchangePlugin_ExportFeature::XAO_FILE_PATH_ID(),
93 ModelAPI_AttributeString::typeId());
94 data()->addAttribute(ExchangePlugin_ExportFeature::FILE_FORMAT_ID(),
95 ModelAPI_AttributeString::typeId());
96 data()->addAttribute(ExchangePlugin_ExportFeature::SELECTION_LIST_ID(),
97 ModelAPI_AttributeSelectionList::typeId());
98 data()->addAttribute(ExchangePlugin_ExportFeature::XAO_AUTHOR_ID(),
99 ModelAPI_AttributeString::typeId());
100 data()->addAttribute(ExchangePlugin_ExportFeature::XAO_GEOMETRY_NAME_ID(),
101 ModelAPI_AttributeString::typeId());
102 data()->addAttribute(ExchangePlugin_ExportFeature::XAO_SELECTION_LIST_ID(),
103 ModelAPI_AttributeSelectionList::typeId());
104 data()->addAttribute(ExchangePlugin_ExportFeature::STL_FILE_PATH_ID(),
105 ModelAPI_AttributeString::typeId());
106 data()->addAttribute(ExchangePlugin_ExportFeature::STL_OBJECT_SELECTED(),
107 ModelAPI_AttributeSelection::typeId());
108 data()->addAttribute(ExchangePlugin_ExportFeature::STL_DEFLECTION_TYPE(),
109 ModelAPI_AttributeString::typeId());
110 data()->addAttribute(ExchangePlugin_ExportFeature::STL_RELATIVE(),
111 ModelAPI_AttributeDouble::typeId());
113 double defelection = Config_PropManager::real("Visualization", "body_deflection");
114 real(ExchangePlugin_ExportFeature::STL_RELATIVE())->setValue(defelection);
116 data()->addAttribute(ExchangePlugin_ExportFeature::STL_ABSOLUTE(),
117 ModelAPI_AttributeDouble::typeId());
118 data()->addAttribute(ExchangePlugin_ExportFeature::STL_FILE_TYPE(),
119 ModelAPI_AttributeString::typeId());
121 ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(),
122 ExchangePlugin_ExportFeature::XAO_FILE_PATH_ID());
123 ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(),
124 ExchangePlugin_ExportFeature::STL_FILE_PATH_ID());
125 ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(),
126 ExchangePlugin_ExportFeature::XAO_AUTHOR_ID());
127 ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(),
128 ExchangePlugin_ExportFeature::XAO_GEOMETRY_NAME_ID());
129 ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(),
130 ExchangePlugin_ExportFeature::XAO_SELECTION_LIST_ID());
132 // to support previous version of document, move the selection list
133 // if the type of export operation is XAO
134 AttributeStringPtr aTypeAttr = string(EXPORT_TYPE_ID());
135 if (aTypeAttr->isInitialized() && aTypeAttr->value() == "XAO") {
136 bool aWasBlocked = data()->blockSendAttributeUpdated(true, false);
137 AttributeSelectionListPtr aSelList = selectionList(SELECTION_LIST_ID());
138 AttributeSelectionListPtr aXAOSelList = selectionList(XAO_SELECTION_LIST_ID());
139 if (aSelList->size() > 0 && aXAOSelList->size() == 0)
140 aSelList->copyTo(aXAOSelList);
142 data()->blockSendAttributeUpdated(aWasBlocked, false);
146 void ExchangePlugin_ExportFeature::attributeChanged(const std::string& theID)
148 if (theID == XAO_FILE_PATH_ID()) {
149 string(ExchangePlugin_ExportFeature::FILE_PATH_ID())->setValue(
150 string(ExchangePlugin_ExportFeature::XAO_FILE_PATH_ID())->value());
152 else if (theID == STL_FILE_PATH_ID()) {
153 string(ExchangePlugin_ExportFeature::FILE_PATH_ID())->setValue(
154 string(ExchangePlugin_ExportFeature::STL_FILE_PATH_ID())->value());
160 * Computes or recomputes the results
162 void ExchangePlugin_ExportFeature::execute()
164 AttributeStringPtr aFormatAttr =
165 this->string(ExchangePlugin_ExportFeature::FILE_FORMAT_ID());
166 std::string aFormat = aFormatAttr->value();
168 AttributeStringPtr aFilePathAttr =
169 this->string(ExchangePlugin_ExportFeature::FILE_PATH_ID());
170 std::string aFilePath = aFilePathAttr->value();
171 if (aFilePath.empty())
174 exportFile(aFilePath, aFormat);
177 void ExchangePlugin_ExportFeature::exportFile(const std::string& theFileName,
178 const std::string& theFormat)
180 std::string aFormatName = theFormat;
182 if (aFormatName.empty()) { // get default format for the extension
184 std::string anExtension = GeomAlgoAPI_Tools::File_Tools::extension(theFileName);
185 if (anExtension == "BREP" || anExtension == "BRP") {
186 aFormatName = "BREP";
187 } else if (anExtension == "STEP" || anExtension == "STP") {
188 aFormatName = "STEP";
189 } else if (anExtension == "IGES" || anExtension == "IGS") {
190 aFormatName = "IGES-5.1";
192 aFormatName = anExtension;
196 if (aFormatName == "XAO") {
197 exportXAO(theFileName);
199 }else if (aFormatName == "STL") {
200 exportSTL(theFileName);
204 // make shape for export from selected shapes
205 AttributeSelectionListPtr aSelectionListAttr =
206 this->selectionList(ExchangePlugin_ExportFeature::SELECTION_LIST_ID());
207 std::list<GeomShapePtr> aShapes;
208 for (int i = 0, aSize = aSelectionListAttr->size(); i < aSize; ++i) {
209 AttributeSelectionPtr anAttrSelection = aSelectionListAttr->value(i);
210 std::shared_ptr<GeomAPI_Shape> aCurShape = anAttrSelection->value();
211 if (aCurShape.get() == NULL)
212 aCurShape = anAttrSelection->context()->shape();
213 if (aCurShape.get() != NULL)
214 aShapes.push_back(aCurShape);
217 // Store compound if we have more than one shape.
218 std::shared_ptr<GeomAPI_Shape> aShape =
219 aShapes.size() == 1 ? aShapes.front() : GeomAlgoAPI_CompoundBuilder::compound(aShapes);
221 // Perform the export
223 bool aResult = false;
224 if (aFormatName == "BREP") {
225 aResult = BREPExport(theFileName, aFormatName, aShape, anError);
226 } else if (aFormatName == "STEP") {
227 aResult = STEPExport(theFileName, aFormatName, aShape, anError);
228 } else if (aFormatName.substr(0, 4) == "IGES") {
229 aResult = IGESExport(theFileName, aFormatName, aShape, anError);
231 anError = "Unsupported format: " + aFormatName;
234 if (!aResult || !anError.empty()) {
235 setError("An error occurred while exporting " + theFileName + ": " + anError);
240 /// Returns XAO string by the value from the table
241 static std::string valToString(const ModelAPI_AttributeTables::Value& theVal,
242 const ModelAPI_AttributeTables::ValueType& theType) {
243 std::ostringstream aStr; // the resulting string value
245 case ModelAPI_AttributeTables::BOOLEAN:
246 aStr<<(theVal.myBool ? "true" : "false");
248 case ModelAPI_AttributeTables::INTEGER:
251 case ModelAPI_AttributeTables::DOUBLE:
252 aStr<<theVal.myDouble;
254 case ModelAPI_AttributeTables::STRING:
261 /// Returns true if something in selection is presented in the results list
262 static bool isInResults(AttributeSelectionListPtr theSelection,
263 const std::list<ResultPtr>& theResults,
264 std::set<ResultPtr>& theCashedResults)
266 // collect all results into a cashed set
267 if (theCashedResults.empty()) {
268 std::list<ResultPtr>::const_iterator aRes = theResults.cbegin();
269 for(; aRes != theResults.cend(); aRes++) {
270 if (theCashedResults.count(*aRes))
273 theCashedResults.insert(*aRes);
274 if ((*aRes)->groupName() == ModelAPI_ResultBody::group()) {
275 ResultBodyPtr aResBody = std::dynamic_pointer_cast<ModelAPI_ResultBody>(*aRes);
276 std::list<ResultPtr> aResults;
277 ModelAPI_Tools::allSubs(aResBody, aResults, false);
278 for(std::list<ResultPtr>::iterator aR = aResults.begin(); aR != aResults.end(); aR++) {
279 theCashedResults.insert(std::dynamic_pointer_cast<ModelAPI_ResultBody>(*aR));
281 } else if ((*aRes)->groupName() == ModelAPI_ResultPart::group()) { // all results of the part
282 ResultPartPtr aResPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(*aRes);
283 DocumentPtr aPartDoc = aResPart->partDoc();
284 if (!aPartDoc.get() || !aPartDoc->isOpened()) { // document is not accessible
287 int aBodyCount = aPartDoc->size(ModelAPI_ResultBody::group());
288 for (int aBodyIndex = 0; aBodyIndex < aBodyCount; ++aBodyIndex) {
289 ResultBodyPtr aResBody =
290 std::dynamic_pointer_cast<ModelAPI_ResultBody>(
291 aPartDoc->object(ModelAPI_ResultBody::group(), aBodyIndex));
292 if (aResBody.get()) {
293 theCashedResults.insert(aResBody);
294 std::list<ResultPtr> aResults;
295 ModelAPI_Tools::allSubs(aResBody, aResults, false);
296 for(std::list<ResultPtr>::iterator aR = aResults.begin(); aR != aResults.end(); aR++) {
297 theCashedResults.insert(std::dynamic_pointer_cast<ModelAPI_ResultBody>(*aR));
304 // if context is in results, return true
305 for(int a = 0; a < theSelection->size(); a++) {
306 AttributeSelectionPtr anAttr = theSelection->value(a);
307 ResultPtr aContext = anAttr->context();
308 // check is it group selected for groups BOP
309 if (aContext.get() && aContext->groupName() == ModelAPI_ResultGroup::group()) {
310 // it is impossible by used results check which result is used in this group result,
311 // so check the results shapes is it in results of this document or not
312 FeaturePtr aSelFeature =
313 std::dynamic_pointer_cast<ModelAPI_Feature>(theSelection->owner());
314 if (!aSelFeature.get() || aSelFeature->results().empty())
316 GeomShapePtr aGroupResShape = aSelFeature->firstResult()->shape();
318 std::set<ResultPtr>::iterator allResultsIter = theCashedResults.begin();
319 for(; allResultsIter != theCashedResults.end(); allResultsIter++) {
320 GeomShapePtr aResultShape = (*allResultsIter)->shape();
322 GeomAPI_Shape::ShapeType aType =
323 GeomAPI_Shape::shapeTypeByStr(theSelection->selectionType());
324 GeomAPI_ShapeExplorer aGroupResExp(aGroupResShape, aType);
325 for(; aGroupResExp.more(); aGroupResExp.next()) {
326 if (aResultShape->isSubShape(aGroupResExp.current(), false))
327 return true; // at least one shape of the group is in the used results
331 ResultBodyPtr aSelected = std::dynamic_pointer_cast<ModelAPI_ResultBody>(anAttr->context());
332 if (!aSelected.get()) { // try to get selected feature and all its results
333 FeaturePtr aContextFeature = anAttr->contextFeature();
334 if (aContextFeature.get() && !aContextFeature->results().empty()) {
335 const std::list<ResultPtr>& allResluts = aContextFeature->results();
336 std::list<ResultPtr>::const_iterator aResIter = allResluts.cbegin();
337 for(; aResIter != allResluts.cend(); aResIter++) {
338 if (aResIter->get() && theCashedResults.count(*aResIter))
342 } else if (aSelected.get() && theCashedResults.count(aSelected))
348 void ExchangePlugin_ExportFeature::exportSTL(const std::string& theFileName)
351 AttributeSelectionPtr aSelection = selection(STL_OBJECT_SELECTED());
352 GeomShapePtr aShape = aSelection->value();
354 aShape = aSelection->context()->shape();
357 // Get relative value and percent flag.
359 bool anIsRelative = false;
360 bool anIsASCII = false;
362 if (string(STL_DEFLECTION_TYPE())->value() == STL_DEFLECTION_TYPE_RELATIVE()) {
363 aValue = real(STL_RELATIVE())->value();
366 aValue = real(STL_ABSOLUTE())->value();
369 if (string(STL_FILE_TYPE())->value() == STL_FILE_TYPE_ASCII()) {
372 // Perform the export
374 bool aResult = false;
376 aResult = STLExport(theFileName,
383 if (!aResult || !anError.empty()) {
384 setError("An error occurred while exporting " + theFileName + ": " + anError);
390 void ExchangePlugin_ExportFeature::exportXAO(const std::string& theFileName)
399 std::string anAuthor = string(ExchangePlugin_ExportFeature::XAO_AUTHOR_ID())->value();
400 aXao.setAuthor(anAuthor);
402 // make shape for export from all results
403 std::list<GeomShapePtr> aShapes;
404 std::list<ResultPtr> aResults;
405 std::list<DocumentPtr> aDocuments; /// documents of Parts selected and used in export
406 std::map<DocumentPtr, GeomTrsfPtr> aDocTrsf; /// translation of the part
408 AttributeSelectionListPtr aSelection = selectionList(XAO_SELECTION_LIST_ID());
409 bool aIsSelection = aSelection->isInitialized() && aSelection->size() > 0;
410 if (aIsSelection) { // a mode for export to geom result by result
411 for(int a = 0; a < aSelection->size(); a++) {
412 AttributeSelectionPtr anAttr = aSelection->value(a);
413 ResultPtr aBodyContext =
414 std::dynamic_pointer_cast<ModelAPI_Result>(anAttr->context());
415 if (aBodyContext.get() && !aBodyContext->isDisabled() && aBodyContext->shape().get()) {
416 aResults.push_back(aBodyContext);
417 GeomShapePtr aShape = anAttr->value();
419 aShape = aBodyContext->shape();
420 aShapes.push_back(aShape);
421 if (aBodyContext->groupName() == ModelAPI_ResultPart::group()) {
422 ResultPartPtr aResPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aBodyContext);
423 DocumentPtr aPartDoc = aResPart->partDoc();
424 if (!aPartDoc.get() || !aPartDoc->isOpened()) { // document is not accessible
425 std::string msg = "Can not export XAO for not loaded part";
426 Events_InfoMessage("ExportFeature", msg, this).send();
429 aDocuments.push_back(aPartDoc);
430 aDocTrsf[aPartDoc] = aResPart->summaryTrsf();
436 int aBodyCount = document()->size(ModelAPI_ResultBody::group());
437 for (int aBodyIndex = 0; aBodyIndex < aBodyCount; ++aBodyIndex) {
438 ResultBodyPtr aResultBody =
439 std::dynamic_pointer_cast<ModelAPI_ResultBody>(
440 document()->object(ModelAPI_ResultBody::group(), aBodyIndex));
441 if (!aResultBody.get())
443 aShapes.push_back(aResultBody->shape());
444 aResults.push_back(aResultBody);
447 if (aShapes.empty()) {
448 setError("No shapes to export");
453 GeomShapePtr aShape = (aShapes.size() == 1)
455 : GeomAlgoAPI_CompoundBuilder::compound(aShapes);
457 SetShapeToXAO(aShape, &aXao, anError);
459 if (!anError.empty()) {
460 setError("An error occurred while exporting " + theFileName + ": " + anError);
465 std::string aGeometryName = string(ExchangePlugin_ExportFeature::XAO_GEOMETRY_NAME_ID())->value();
466 if (aGeometryName.empty() && aResults.size() == 1) {
467 // get the name from the first result
468 ResultPtr aResultBody = *aResults.begin();
469 aGeometryName = Locale::Convert::toString(aResultBody->data()->name());
472 aXao.getGeometry()->setName(aGeometryName);
474 std::set<ResultPtr> allResultsCashed; // cash to speed up searching in all results selected
476 // iterate all documents used
477 if (aDocuments.empty())
478 aDocuments.push_back(document());
479 std::list<DocumentPtr>::iterator aDoc = aDocuments.begin();
480 for(; aDoc != aDocuments.end(); aDoc++) {
482 int aGroupCount = (*aDoc)->size(ModelAPI_ResultGroup::group());
483 for (int aGroupIndex = 0; aGroupIndex < aGroupCount; ++aGroupIndex) {
484 ResultGroupPtr aResultGroup = std::dynamic_pointer_cast<ModelAPI_ResultGroup>(
485 (*aDoc)->object(ModelAPI_ResultGroup::group(), aGroupIndex));
486 if (!aResultGroup.get() || !aResultGroup->shape().get())
489 FeaturePtr aGroupFeature = (*aDoc)->feature(aResultGroup);
491 AttributeSelectionListPtr aSelectionList =
492 aGroupFeature->selectionList("group_list");
493 if (!isInResults(aSelectionList, aResults, allResultsCashed))// skip group not used in result
496 // conversion of dimension
497 std::string aSelectionType = aSelectionList->selectionType();
498 GeomAPI_Shape::ShapeType aSelType = GeomAPI_Shape::shapeTypeByStr(aSelectionType);
499 std::string aDimensionString =
500 ExchangePlugin_Tools::selectionType2xaoDimension(aSelectionType);
501 XAO::Dimension aGroupDimension = XAO::XaoUtils::stringToDimension(aDimensionString);
503 XAO::Group* aXaoGroup = aXao.addGroup(aGroupDimension,
504 Locale::Convert::toString(aResultGroup->data()->name()));
507 GeomAPI_ShapeExplorer aGroupResExplorer(aResultGroup->shape(), aSelType);
508 for(; aGroupResExplorer.more(); aGroupResExplorer.next()) {
509 GeomShapePtr aGroupShape = aGroupResExplorer.current();
510 if (aDocTrsf.find(*aDoc) != aDocTrsf.end())
511 aGroupShape->move(aDocTrsf[*aDoc]);
512 int aReferenceID = GeomAlgoAPI_CompoundBuilder::id(aShape, aGroupShape);
513 if (aReferenceID == 0) // selected value does not found in the exported shape
515 std::string aReferenceString = XAO::XaoUtils::intToString(aReferenceID);
517 aXao.getGeometry()->getElementIndexByReference(aGroupDimension, aReferenceString);
518 aXaoGroup->add(anElementID);
520 } catch (XAO::XAO_Exception& e) {
522 std::string msg = "An error occurred while exporting group " +
523 Locale::Convert::toString(aResultGroup->data()->name());
527 msg += "=> skipping this group from XAO export.";
528 Events_InfoMessage("ExportFeature", msg, this).send();
529 aXao.removeGroup(aXaoGroup);
535 int aFieldCount = (*aDoc)->size(ModelAPI_ResultField::group());
536 for (int aFieldIndex = 0; aFieldIndex < aFieldCount; ++aFieldIndex) {
537 ResultFieldPtr aResultField = std::dynamic_pointer_cast<ModelAPI_ResultField>(
538 (*aDoc)->object(ModelAPI_ResultField::group(), aFieldIndex));
540 FeaturePtr aFieldFeature = (*aDoc)->feature(aResultField);
542 AttributeSelectionListPtr aSelectionList =
543 aFieldFeature->selectionList("selected");
544 std::string aSelectionType = aSelectionList->selectionType();
545 bool isWholePart = aSelectionType == "part";
546 // skip field not used in results
547 if (!isWholePart && !isInResults(aSelectionList, aResults, allResultsCashed))
550 // conversion of dimension
551 std::string aDimensionString =
552 ExchangePlugin_Tools::selectionType2xaoDimension(aSelectionType);
553 XAO::Dimension aFieldDimension = XAO::XaoUtils::stringToDimension(aDimensionString);
554 // get tables and their type
555 std::shared_ptr<ModelAPI_AttributeTables> aTables = aFieldFeature->tables("values");
556 std::string aTypeString = ExchangePlugin_Tools::valuesType2xaoType(aTables->type());
557 XAO::Type aFieldType = XAO::XaoUtils::stringToFieldType(aTypeString);
559 XAO::Field* aXaoField = aXao.addField(aFieldType, aFieldDimension, aTables->columns(),
560 Locale::Convert::toString(aResultField->data()->name()));
564 // set components names
565 AttributeStringArrayPtr aComponents = aFieldFeature->stringArray("components_names");
566 for(int aComp = 0; aComp < aComponents->size(); aComp++) {
567 std::string aName = aComponents->value(aComp);
568 aXaoField->setComponentName(aComp, aName);
571 AttributeIntArrayPtr aStamps = aFieldFeature->intArray("stamps");
572 for (int aStepIndex = 0; aStepIndex < aTables->tables(); aStepIndex++) {
573 XAO::Step* aStep = aXaoField->addNewStep(aStepIndex + 1);
574 aStep->setStep(aStepIndex + 1);
575 int aStampIndex = aStamps->value(aStepIndex);
576 aStep->setStamp(aStampIndex);
577 int aNumElements = isWholePart ? aXaoField->countElements() : aTables->rows();
578 int aNumComps = aTables->columns();
579 std::set<int> aFilledIDs; // to fill the rest by defaults
580 // omit default values first row
581 for(int aRow = isWholePart ? 0 : 1; aRow < aNumElements; aRow++) {
582 for(int aCol = 0; aCol < aNumComps; aCol++) {
585 // element index actually is the ID of the selection
586 AttributeSelectionPtr aSel = aSelectionList->value(aRow - 1);
587 int aReferenceID = GeomAlgoAPI_CompoundBuilder::id(aShape, aSel->value());
588 if (aReferenceID == 0) // selected value does not found in the exported shape
591 std::string aReferenceString = XAO::XaoUtils::intToString(aReferenceID);
592 anElementID = aXao.getGeometry()->
593 getElementIndexByReference(aFieldDimension, aReferenceString);
596 ModelAPI_AttributeTables::Value aVal = aTables->value(
597 isWholePart ? 0 : aRow, aCol, aStepIndex);
598 std::string aStrVal = valToString(aVal, aTables->type());
599 aStep->setStringValue(isWholePart ? aRow : anElementID, aCol, aStrVal);
600 aFilledIDs.insert(anElementID);
603 if (!isWholePart) { // fill the rest values by default ones
604 XAO::GeometricElementList::iterator allElem =
605 aXao.getGeometry()->begin(aFieldDimension);
606 for(; allElem != aXao.getGeometry()->end(aFieldDimension); allElem++) {
607 if (aFilledIDs.find(allElem->first) != aFilledIDs.end())
609 for(int aCol = 0; aCol < aNumComps; aCol++) {
611 ModelAPI_AttributeTables::Value aVal = aTables->value(0, aCol, aStepIndex);
612 std::string aStrVal = valToString(aVal, aTables->type());
613 aStep->setStringValue(allElem->first, aCol, aStrVal);
618 } catch (XAO::XAO_Exception& e) {
620 std::string msg = "An error occurred while exporting field " +
621 Locale::Convert::toString(aResultField->data()->name());
625 msg += "=> skipping this field from XAO export.";
626 Events_InfoMessage("ExportFeature", msg, this).send();
627 aXao.removeField(aXaoField);
634 XAOExport(theFileName, &aXao, anError);
636 if (!anError.empty()) {
637 setError("An error occurred while exporting " + theFileName + ": " + anError);
642 } catch (XAO::XAO_Exception& e) {
643 std::string anError = e.what();
644 setError("An error occurred while exporting " + theFileName + ": " + anError);
650 bool ExchangePlugin_ExportFeature::isMacro() const
652 if (!data().get() || !data()->isValid())
654 ExchangePlugin_ExportFeature* aThis = ((ExchangePlugin_ExportFeature*)(this));
655 AttributeStringPtr aFormatAttr = aThis->string(FILE_FORMAT_ID());
656 std::string aFormat(aFormatAttr.get() ? aFormatAttr->value() : "");
658 if (aFormat.empty()) { // get default format for the extension
659 AttributeStringPtr aFilePathAttr = aThis->string(FILE_PATH_ID());
660 std::string aFilePath = aFilePathAttr->value();
661 if (!aFilePath.empty()) {
662 std::string anExtension = GeomAlgoAPI_Tools::File_Tools::extension(aFilePath);
663 aFormat = anExtension;
667 if (aFormat == "XAO") { // on export to GEOM the selection attribute is filled - this is
668 // an exceptional case where export to XAO feature must be kept
669 AttributeSelectionListPtr aList = aThis->selectionList(XAO_SELECTION_LIST_ID());
670 return !aList->isInitialized() || aList->size() == 0;