1 // Copyright (C) 2014-2021 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);
211 /// do not export pictures
212 ResultPtr aBodyContext =
213 std::dynamic_pointer_cast<ModelAPI_Result>(anAttrSelection->context());
214 if (aBodyContext->hasTexture())
217 std::shared_ptr<GeomAPI_Shape> aCurShape = anAttrSelection->value();
218 if (aCurShape.get() == NULL)
219 aCurShape = anAttrSelection->context()->shape();
220 if (aCurShape.get() != NULL)
221 aShapes.push_back(aCurShape);
224 // Store compound if we have more than one shape.
225 std::shared_ptr<GeomAPI_Shape> aShape =
226 aShapes.size() == 1 ? aShapes.front() : GeomAlgoAPI_CompoundBuilder::compound(aShapes);
228 // Perform the export
230 bool aResult = false;
231 if (aFormatName == "BREP") {
232 aResult = BREPExport(theFileName, aFormatName, aShape, anError);
233 } else if (aFormatName == "STEP") {
234 aResult = STEPExport(theFileName, aFormatName, aShape, anError);
235 } else if (aFormatName.substr(0, 4) == "IGES") {
236 aResult = IGESExport(theFileName, aFormatName, aShape, anError);
238 anError = "Unsupported format: " + aFormatName;
241 if (!aResult || !anError.empty()) {
242 setError("An error occurred while exporting " + theFileName + ": " + anError);
247 /// Returns XAO string by the value from the table
248 static std::string valToString(const ModelAPI_AttributeTables::Value& theVal,
249 const ModelAPI_AttributeTables::ValueType& theType) {
250 std::ostringstream aStr; // the resulting string value
252 case ModelAPI_AttributeTables::BOOLEAN:
253 aStr<<(theVal.myBool ? "true" : "false");
255 case ModelAPI_AttributeTables::INTEGER:
258 case ModelAPI_AttributeTables::DOUBLE:
259 aStr<<theVal.myDouble;
261 case ModelAPI_AttributeTables::STRING:
268 /// Returns true if something in selection is presented in the results list
269 static bool isInResults(AttributeSelectionListPtr theSelection,
270 const std::list<ResultPtr>& theResults,
271 std::set<ResultPtr>& theCashedResults)
273 // collect all results into a cashed set
274 if (theCashedResults.empty()) {
275 std::list<ResultPtr>::const_iterator aRes = theResults.cbegin();
276 for(; aRes != theResults.cend(); aRes++) {
277 if (theCashedResults.count(*aRes))
280 theCashedResults.insert(*aRes);
281 if ((*aRes)->groupName() == ModelAPI_ResultBody::group()) {
282 ResultBodyPtr aResBody = std::dynamic_pointer_cast<ModelAPI_ResultBody>(*aRes);
283 std::list<ResultPtr> aResults;
284 ModelAPI_Tools::allSubs(aResBody, aResults, false);
285 for(std::list<ResultPtr>::iterator aR = aResults.begin(); aR != aResults.end(); aR++) {
286 theCashedResults.insert(std::dynamic_pointer_cast<ModelAPI_ResultBody>(*aR));
288 } else if ((*aRes)->groupName() == ModelAPI_ResultPart::group()) { // all results of the part
289 ResultPartPtr aResPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(*aRes);
290 DocumentPtr aPartDoc = aResPart->partDoc();
291 if (!aPartDoc.get() || !aPartDoc->isOpened()) { // document is not accessible
294 int aBodyCount = aPartDoc->size(ModelAPI_ResultBody::group());
295 for (int aBodyIndex = 0; aBodyIndex < aBodyCount; ++aBodyIndex) {
296 ResultBodyPtr aResBody =
297 std::dynamic_pointer_cast<ModelAPI_ResultBody>(
298 aPartDoc->object(ModelAPI_ResultBody::group(), aBodyIndex));
299 if (aResBody.get()) {
300 theCashedResults.insert(aResBody);
301 std::list<ResultPtr> aResults;
302 ModelAPI_Tools::allSubs(aResBody, aResults, false);
303 for(std::list<ResultPtr>::iterator aR = aResults.begin(); aR != aResults.end(); aR++) {
304 theCashedResults.insert(std::dynamic_pointer_cast<ModelAPI_ResultBody>(*aR));
311 // if context is in results, return true
312 for(int a = 0; a < theSelection->size(); a++) {
313 AttributeSelectionPtr anAttr = theSelection->value(a);
314 ResultPtr aContext = anAttr->context();
315 // check is it group selected for groups BOP
316 if (aContext.get() && aContext->groupName() == ModelAPI_ResultGroup::group()) {
317 // it is impossible by used results check which result is used in this group result,
318 // so check the results shapes is it in results of this document or not
319 FeaturePtr aSelFeature =
320 std::dynamic_pointer_cast<ModelAPI_Feature>(theSelection->owner());
321 if (!aSelFeature.get() || aSelFeature->results().empty())
323 GeomShapePtr aGroupResShape = aSelFeature->firstResult()->shape();
325 std::set<ResultPtr>::iterator allResultsIter = theCashedResults.begin();
326 for(; allResultsIter != theCashedResults.end(); allResultsIter++) {
327 GeomShapePtr aResultShape = (*allResultsIter)->shape();
329 GeomAPI_Shape::ShapeType aType =
330 GeomAPI_Shape::shapeTypeByStr(theSelection->selectionType());
331 GeomAPI_ShapeExplorer aGroupResExp(aGroupResShape, aType);
332 for(; aGroupResExp.more(); aGroupResExp.next()) {
333 if (aResultShape->isSubShape(aGroupResExp.current(), false))
334 return true; // at least one shape of the group is in the used results
338 ResultBodyPtr aSelected = std::dynamic_pointer_cast<ModelAPI_ResultBody>(anAttr->context());
339 if (!aSelected.get()) { // try to get selected feature and all its results
340 FeaturePtr aContextFeature = anAttr->contextFeature();
341 if (aContextFeature.get() && !aContextFeature->results().empty()) {
342 const std::list<ResultPtr>& allResluts = aContextFeature->results();
343 std::list<ResultPtr>::const_iterator aResIter = allResluts.cbegin();
344 for(; aResIter != allResluts.cend(); aResIter++) {
345 if (aResIter->get() && theCashedResults.count(*aResIter))
349 } else if (aSelected.get() && theCashedResults.count(aSelected))
355 void ExchangePlugin_ExportFeature::exportSTL(const std::string& theFileName)
358 AttributeSelectionPtr aSelection = selection(STL_OBJECT_SELECTED());
359 GeomShapePtr aShape = aSelection->value();
361 aShape = aSelection->context()->shape();
364 // Get relative value and percent flag.
366 bool anIsRelative = false;
367 bool anIsASCII = false;
369 if (string(STL_DEFLECTION_TYPE())->value() == STL_DEFLECTION_TYPE_RELATIVE()) {
370 aValue = real(STL_RELATIVE())->value();
373 aValue = real(STL_ABSOLUTE())->value();
376 if (string(STL_FILE_TYPE())->value() == STL_FILE_TYPE_ASCII()) {
379 // Perform the export
381 bool aResult = false;
383 aResult = STLExport(theFileName,
390 if (!aResult || !anError.empty()) {
391 setError("An error occurred while exporting " + theFileName + ": " + anError);
397 void ExchangePlugin_ExportFeature::exportXAO(const std::string& theFileName)
406 std::string anAuthor = string(ExchangePlugin_ExportFeature::XAO_AUTHOR_ID())->value();
407 aXao.setAuthor(anAuthor);
409 // make shape for export from all results
410 std::list<GeomShapePtr> aShapes;
411 std::list<ResultPtr> aResults;
412 std::list<DocumentPtr> aDocuments; /// documents of Parts selected and used in export
413 std::map<DocumentPtr, GeomTrsfPtr> aDocTrsf; /// translation of the part
415 bool anExCludedIsImage = false;
416 AttributeSelectionListPtr aSelection = selectionList(XAO_SELECTION_LIST_ID());
417 bool aIsSelection = aSelection->isInitialized() && aSelection->size() > 0;
418 if (aIsSelection) { // a mode for export to geom result by result
419 for (int a = 0; a < aSelection->size(); a++) {
420 AttributeSelectionPtr anAttr = aSelection->value(a);
421 ResultPtr aBodyContext =
422 std::dynamic_pointer_cast<ModelAPI_Result>(anAttr->context());
423 if (aBodyContext.get() && !aBodyContext->isDisabled() && aBodyContext->shape().get()) {
424 /// do not export pictures
425 if (aBodyContext->hasTexture()){
426 anExCludedIsImage = true;
429 aResults.push_back(aBodyContext);
430 GeomShapePtr aShape = anAttr->value();
432 aShape = aBodyContext->shape();
433 aShapes.push_back(aShape);
434 if (aBodyContext->groupName() == ModelAPI_ResultPart::group()) {
435 ResultPartPtr aResPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aBodyContext);
436 DocumentPtr aPartDoc = aResPart->partDoc();
437 if (!aPartDoc.get() || !aPartDoc->isOpened()) { // document is not accessible
438 std::string msg = "Can not export XAO for not loaded part";
439 Events_InfoMessage("ExportFeature", msg, this).send();
442 aDocuments.push_back(aPartDoc);
443 aDocTrsf[aPartDoc] = aResPart->summaryTrsf();
449 int aBodyCount = document()->size(ModelAPI_ResultBody::group());
450 for (int aBodyIndex = 0; aBodyIndex < aBodyCount; ++aBodyIndex) {
451 ResultBodyPtr aResultBody =
452 std::dynamic_pointer_cast<ModelAPI_ResultBody>(
453 document()->object(ModelAPI_ResultBody::group(), aBodyIndex));
454 if (!aResultBody.get())
456 aShapes.push_back(aResultBody->shape());
457 aResults.push_back(aResultBody);
460 if (aShapes.empty()) {
461 if(!anExCludedIsImage)
462 setError("No shapes to export");
467 GeomShapePtr aShape = (aShapes.size() == 1)
469 : GeomAlgoAPI_CompoundBuilder::compound(aShapes);
471 SetShapeToXAO(aShape, &aXao, anError);
473 if (!anError.empty()) {
474 setError("An error occurred while exporting " + theFileName + ": " + anError);
479 std::string aGeometryName = string(ExchangePlugin_ExportFeature::XAO_GEOMETRY_NAME_ID())->value();
480 if (aGeometryName.empty() && aResults.size() == 1) {
481 // get the name from the first result
482 ResultPtr aResultBody = *aResults.begin();
483 aGeometryName = Locale::Convert::toString(aResultBody->data()->name());
486 aXao.getGeometry()->setName(aGeometryName);
488 std::set<ResultPtr> allResultsCashed; // cash to speed up searching in all results selected
490 // iterate all documents used
491 if (aDocuments.empty())
492 aDocuments.push_back(document());
493 std::list<DocumentPtr>::iterator aDoc = aDocuments.begin();
494 for(; aDoc != aDocuments.end(); aDoc++) {
496 int aGroupCount = (*aDoc)->size(ModelAPI_ResultGroup::group());
497 for (int aGroupIndex = 0; aGroupIndex < aGroupCount; ++aGroupIndex) {
498 ResultGroupPtr aResultGroup = std::dynamic_pointer_cast<ModelAPI_ResultGroup>(
499 (*aDoc)->object(ModelAPI_ResultGroup::group(), aGroupIndex));
500 if (!aResultGroup.get() || !aResultGroup->shape().get())
503 FeaturePtr aGroupFeature = (*aDoc)->feature(aResultGroup);
505 AttributeSelectionListPtr aSelectionList =
506 aGroupFeature->selectionList("group_list");
507 if (!isInResults(aSelectionList, aResults, allResultsCashed))// skip group not used in result
510 // conversion of dimension
511 std::string aSelectionType = aSelectionList->selectionType();
512 GeomAPI_Shape::ShapeType aSelType = GeomAPI_Shape::shapeTypeByStr(aSelectionType);
513 std::string aDimensionString =
514 ExchangePlugin_Tools::selectionType2xaoDimension(aSelectionType);
515 XAO::Dimension aGroupDimension = XAO::XaoUtils::stringToDimension(aDimensionString);
517 XAO::Group* aXaoGroup = aXao.addGroup(aGroupDimension,
518 Locale::Convert::toString(aResultGroup->data()->name()));
521 GeomAPI_ShapeExplorer aGroupResExplorer(aResultGroup->shape(), aSelType);
522 for(; aGroupResExplorer.more(); aGroupResExplorer.next()) {
523 GeomShapePtr aGroupShape = aGroupResExplorer.current();
524 if (aDocTrsf.find(*aDoc) != aDocTrsf.end())
525 aGroupShape->move(aDocTrsf[*aDoc]);
526 int aReferenceID = GeomAlgoAPI_CompoundBuilder::id(aShape, aGroupShape);
527 if (aReferenceID == 0) // selected value does not found in the exported shape
529 std::string aReferenceString = XAO::XaoUtils::intToString(aReferenceID);
531 aXao.getGeometry()->getElementIndexByReference(aGroupDimension, aReferenceString);
532 aXaoGroup->add(anElementID);
534 } catch (XAO::XAO_Exception& e) {
536 std::string msg = "An error occurred while exporting group " +
537 Locale::Convert::toString(aResultGroup->data()->name());
541 msg += "=> skipping this group from XAO export.";
542 Events_InfoMessage("ExportFeature", msg, this).send();
543 aXao.removeGroup(aXaoGroup);
549 int aFieldCount = (*aDoc)->size(ModelAPI_ResultField::group());
550 for (int aFieldIndex = 0; aFieldIndex < aFieldCount; ++aFieldIndex) {
551 ResultFieldPtr aResultField = std::dynamic_pointer_cast<ModelAPI_ResultField>(
552 (*aDoc)->object(ModelAPI_ResultField::group(), aFieldIndex));
554 FeaturePtr aFieldFeature = (*aDoc)->feature(aResultField);
556 AttributeSelectionListPtr aSelectionList =
557 aFieldFeature->selectionList("selected");
558 std::string aSelectionType = aSelectionList->selectionType();
559 bool isWholePart = aSelectionType == "part";
560 // skip field not used in results
561 if (!isWholePart && !isInResults(aSelectionList, aResults, allResultsCashed))
564 // conversion of dimension
565 std::string aDimensionString =
566 ExchangePlugin_Tools::selectionType2xaoDimension(aSelectionType);
567 XAO::Dimension aFieldDimension = XAO::XaoUtils::stringToDimension(aDimensionString);
568 // get tables and their type
569 std::shared_ptr<ModelAPI_AttributeTables> aTables = aFieldFeature->tables("values");
570 std::string aTypeString = ExchangePlugin_Tools::valuesType2xaoType(aTables->type());
571 XAO::Type aFieldType = XAO::XaoUtils::stringToFieldType(aTypeString);
573 XAO::Field* aXaoField = aXao.addField(aFieldType, aFieldDimension, aTables->columns(),
574 Locale::Convert::toString(aResultField->data()->name()));
578 // set components names
579 AttributeStringArrayPtr aComponents = aFieldFeature->stringArray("components_names");
580 for(int aComp = 0; aComp < aComponents->size(); aComp++) {
581 std::string aName = aComponents->value(aComp);
582 aXaoField->setComponentName(aComp, aName);
585 AttributeIntArrayPtr aStamps = aFieldFeature->intArray("stamps");
586 for (int aStepIndex = 0; aStepIndex < aTables->tables(); aStepIndex++) {
587 XAO::Step* aStep = aXaoField->addNewStep(aStepIndex + 1);
588 aStep->setStep(aStepIndex + 1);
589 int aStampIndex = aStamps->value(aStepIndex);
590 aStep->setStamp(aStampIndex);
591 int aNumElements = isWholePart ? aXaoField->countElements() : aTables->rows();
592 int aNumComps = aTables->columns();
593 std::set<int> aFilledIDs; // to fill the rest by defaults
594 // omit default values first row
595 for(int aRow = isWholePart ? 0 : 1; aRow < aNumElements; aRow++) {
596 for(int aCol = 0; aCol < aNumComps; aCol++) {
599 // element index actually is the ID of the selection
600 AttributeSelectionPtr aSel = aSelectionList->value(aRow - 1);
601 int aReferenceID = GeomAlgoAPI_CompoundBuilder::id(aShape, aSel->value());
602 if (aReferenceID == 0) // selected value does not found in the exported shape
605 std::string aReferenceString = XAO::XaoUtils::intToString(aReferenceID);
606 anElementID = aXao.getGeometry()->
607 getElementIndexByReference(aFieldDimension, aReferenceString);
610 ModelAPI_AttributeTables::Value aVal = aTables->value(
611 isWholePart ? 0 : aRow, aCol, aStepIndex);
612 std::string aStrVal = valToString(aVal, aTables->type());
613 aStep->setStringValue(isWholePart ? aRow : anElementID, aCol, aStrVal);
614 aFilledIDs.insert(anElementID);
617 if (!isWholePart) { // fill the rest values by default ones
618 XAO::GeometricElementList::iterator allElem =
619 aXao.getGeometry()->begin(aFieldDimension);
620 for(; allElem != aXao.getGeometry()->end(aFieldDimension); allElem++) {
621 if (aFilledIDs.find(allElem->first) != aFilledIDs.end())
623 for(int aCol = 0; aCol < aNumComps; aCol++) {
625 ModelAPI_AttributeTables::Value aVal = aTables->value(0, aCol, aStepIndex);
626 std::string aStrVal = valToString(aVal, aTables->type());
627 aStep->setStringValue(allElem->first, aCol, aStrVal);
632 } catch (XAO::XAO_Exception& e) {
634 std::string msg = "An error occurred while exporting field " +
635 Locale::Convert::toString(aResultField->data()->name());
639 msg += "=> skipping this field from XAO export.";
640 Events_InfoMessage("ExportFeature", msg, this).send();
641 aXao.removeField(aXaoField);
648 XAOExport(theFileName, &aXao, anError);
650 if (!anError.empty()) {
651 setError("An error occurred while exporting " + theFileName + ": " + anError);
656 } catch (XAO::XAO_Exception& e) {
657 std::string anError = e.what();
658 setError("An error occurred while exporting " + theFileName + ": " + anError);
664 bool ExchangePlugin_ExportFeature::isMacro() const
666 if (!data().get() || !data()->isValid())
668 ExchangePlugin_ExportFeature* aThis = ((ExchangePlugin_ExportFeature*)(this));
669 AttributeStringPtr aFormatAttr = aThis->string(FILE_FORMAT_ID());
670 std::string aFormat(aFormatAttr.get() ? aFormatAttr->value() : "");
672 if (aFormat.empty()) { // get default format for the extension
673 AttributeStringPtr aFilePathAttr = aThis->string(FILE_PATH_ID());
674 std::string aFilePath = aFilePathAttr->value();
675 if (!aFilePath.empty()) {
676 std::string anExtension = GeomAlgoAPI_Tools::File_Tools::extension(aFilePath);
677 aFormat = anExtension;
681 if (aFormat == "XAO") { // on export to GEOM the selection attribute is filled - this is
682 // an exceptional case where export to XAO feature must be kept
683 AttributeSelectionListPtr aList = aThis->selectionList(XAO_SELECTION_LIST_ID());
684 return !aList->isInitialized() || aList->size() == 0;