-// Copyright (C) 2014-2022 CEA/DEN, EDF R&D
+// Copyright (C) 2014-2024 CEA, EDF
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
#include <ostream>
#endif
-
#include <Config_Common.h>
#include <Config_PropManager.h>
#include <GeomAlgoAPI_Tools.h>
#include <GeomAlgoAPI_XAOExport.h>
+#include <GeomAPI_IndexedMapOfShape.h>
#include <GeomAPI_Shape.h>
#include <GeomAPI_ShapeExplorer.h>
#include <GeomAPI_Trsf.h>
#include <ModelAPI_AttributeIntArray.h>
#include <ModelAPI_AttributeTables.h>
#include <ModelAPI_AttributeDouble.h>
+#include <ModelAPI_AttributeBoolean.h>
#include <ModelAPI_Data.h>
#include <ModelAPI_Document.h>
#include <ModelAPI_Object.h>
data()->addAttribute(ExchangePlugin_ExportFeature::STL_FILE_TYPE(),
ModelAPI_AttributeString::typeId());
+ // export to memory buffer (implemented for XAO format only)
+ data()->addAttribute(ExchangePlugin_ExportFeature::MEMORY_BUFFER_ID(),
+ ModelAPI_AttributeString::typeId());
+
+ data()->addAttribute(ExchangePlugin_ExportFeature::XAO_SHAPE_FILE_PATH_ID(),
+ ModelAPI_AttributeString::typeId());
+ data()->addAttribute(ExchangePlugin_ExportFeature::XAO_SHAPE_FILE_SEPARATE_ID(),
+ ModelAPI_AttributeBoolean::typeId());
+
ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(),
ExchangePlugin_ExportFeature::XAO_FILE_PATH_ID());
ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(),
ExchangePlugin_ExportFeature::XAO_GEOMETRY_NAME_ID());
ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(),
ExchangePlugin_ExportFeature::XAO_SELECTION_LIST_ID());
+ ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(),
+ ExchangePlugin_ExportFeature::MEMORY_BUFFER_ID());
+ ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(),
+ ExchangePlugin_ExportFeature::XAO_SHAPE_FILE_PATH_ID());
+ ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(),
+ ExchangePlugin_ExportFeature::XAO_SHAPE_FILE_SEPARATE_ID());
// to support previous version of document, move the selection list
// if the type of export operation is XAO
AttributeStringPtr aTypeAttr = string(EXPORT_TYPE_ID());
- if (aTypeAttr->isInitialized() && aTypeAttr->value() == "XAO") {
+ if (aTypeAttr->isInitialized() &&
+ (aTypeAttr->value() == "XAO" || aTypeAttr->value() == "XAOMem")) {
bool aWasBlocked = data()->blockSendAttributeUpdated(true, false);
AttributeSelectionListPtr aSelList = selectionList(SELECTION_LIST_ID());
AttributeSelectionListPtr aXAOSelList = selectionList(XAO_SELECTION_LIST_ID());
string(ExchangePlugin_ExportFeature::FILE_PATH_ID())->setValue(
string(ExchangePlugin_ExportFeature::STL_FILE_PATH_ID())->value());
}
-
}
/*
this->string(ExchangePlugin_ExportFeature::FILE_FORMAT_ID());
std::string aFormat = aFormatAttr->value();
+ bool isMemoryExport = false;
+ AttributeStringPtr aTypeAttr = string(EXPORT_TYPE_ID());
+ if (aTypeAttr->isInitialized() && aTypeAttr->value() == "XAOMem")
+ isMemoryExport = true;
+
AttributeStringPtr aFilePathAttr =
this->string(ExchangePlugin_ExportFeature::FILE_PATH_ID());
std::string aFilePath = aFilePathAttr->value();
- if (aFilePath.empty())
+ if (aFilePath.empty() && !isMemoryExport)
return;
- exportFile(aFilePath, aFormat);
+ exportFile(aFilePath, aFormat, isMemoryExport);
}
void ExchangePlugin_ExportFeature::exportFile(const std::string& theFileName,
- const std::string& theFormat)
+ const std::string& theFormat,
+ const bool isMemoryExport)
{
std::string aFormatName = theFormat;
if (aFormatName.empty()) { // get default format for the extension
+ if (isMemoryExport) return;
+
// ".brep" -> "BREP"
std::string anExtension = GeomAlgoAPI_Tools::File_Tools::extension(theFileName);
if (anExtension == "BREP" || anExtension == "BRP") {
}
if (aFormatName == "XAO") {
- exportXAO(theFileName);
+ exportXAO(theFileName, isMemoryExport);
return;
- }else if (aFormatName == "STL") {
+ } else if (aFormatName == "STL") {
exportSTL(theFileName);
return;
}
AttributeSelectionListPtr aSelectionListAttr =
this->selectionList(ExchangePlugin_ExportFeature::SELECTION_LIST_ID());
std::list<GeomShapePtr> aShapes;
+ std::list<ResultPtr> aContexts;
for (int i = 0, aSize = aSelectionListAttr->size(); i < aSize; ++i) {
AttributeSelectionPtr anAttrSelection = aSelectionListAttr->value(i);
if (aCurShape.get() == NULL)
aCurShape = anAttrSelection->context()->shape();
if (aCurShape.get() != NULL)
+ {
aShapes.push_back(aCurShape);
+ aContexts.push_back(anAttrSelection->context());
+ }
}
// Store compound if we have more than one shape.
if (aFormatName == "BREP") {
aResult = BREPExport(theFileName, aFormatName, aShape, anError);
} else if (aFormatName == "STEP") {
- aResult = STEPExport(theFileName, aFormatName, aShape, anError);
+ aResult = STEPExport(theFileName, aShapes, aContexts, anError);
} else if (aFormatName.substr(0, 4) == "IGES") {
aResult = IGESExport(theFileName, aFormatName, aShape, anError);
} else {
/// Returns XAO string by the value from the table
static std::string valToString(const ModelAPI_AttributeTables::Value& theVal,
- const ModelAPI_AttributeTables::ValueType& theType) {
+ const ModelAPI_AttributeTables::ValueType& theType)
+{
std::ostringstream aStr; // the resulting string value
switch(theType) {
case ModelAPI_AttributeTables::BOOLEAN:
}
-void ExchangePlugin_ExportFeature::exportXAO(const std::string& theFileName)
+void ExchangePlugin_ExportFeature::exportXAO(const std::string& theFileName,
+ const bool isMemoryExport)
{
try {
// get the name from the first result
ResultPtr aResultBody = *aResults.begin();
aGeometryName = Locale::Convert::toString(aResultBody->data()->name());
+ if (isMemoryExport) {
+ // for python dump
+ string(ExchangePlugin_ExportFeature::XAO_GEOMETRY_NAME_ID())->setValue(aGeometryName);
+ // or
+ //data()->setName(Locale::Convert::toWString(aGeometryName));
+ }
}
aXao.getGeometry()->setName(aGeometryName);
std::set<ResultPtr> allResultsCashed; // cash to speed up searching in all results selected
+ // [bos #38360] [CEA] improve performances of exportXAO and PublishToStudy
+ GeomAPI_IndexedMapOfShape aSubShapesMap;
+ bool isSubShapesMap = false; // we will init it only if required (for performance reason)
+
// iterate all documents used
if (aDocuments.empty())
aDocuments.push_back(document());
GeomShapePtr aGroupShape = aGroupResExplorer.current();
if (aDocTrsf.find(*aDoc) != aDocTrsf.end())
aGroupShape->move(aDocTrsf[*aDoc]);
- int aReferenceID = GeomAlgoAPI_CompoundBuilder::id(aShape, aGroupShape);
+
+ if (!isSubShapesMap) {
+ aSubShapesMap.MapShapes(aShape);
+ isSubShapesMap = true;
+ }
+ int aReferenceID = aSubShapesMap.FindIndexEqualLocations(aGroupShape);
if (aReferenceID == 0) // selected value does not found in the exported shape
continue;
std::string aReferenceString = XAO::XaoUtils::intToString(aReferenceID);
if (!isWholePart) {
// element index actually is the ID of the selection
AttributeSelectionPtr aSel = aSelectionList->value(aRow - 1);
- int aReferenceID = GeomAlgoAPI_CompoundBuilder::id(aShape, aSel->value());
+ if (!isSubShapesMap) {
+ aSubShapesMap.MapShapes(aShape);
+ isSubShapesMap = true;
+ }
+ int aReferenceID = aSubShapesMap.FindIndexEqualLocations(aSel->value());
if (aReferenceID == 0) // selected value does not found in the exported shape
continue;
}
// exporting
- XAOExport(theFileName, &aXao, anError);
+ if (isMemoryExport) {
+ string(ExchangePlugin_ExportFeature::MEMORY_BUFFER_ID())->setValue(XAOExportMem(&aXao, anError));
+ }
+ else {
+ std::string aShapeFile ("");
+ AttributeBooleanPtr aShapeSeparateAttr = boolean(XAO_SHAPE_FILE_SEPARATE_ID());
+ if (aShapeSeparateAttr->isInitialized() &&
+ aShapeSeparateAttr->value() == true) {
+ aShapeFile = theFileName + ".brep";
+ }
+ else {
+ AttributeStringPtr aShapeFileAttr = string(XAO_SHAPE_FILE_PATH_ID());
+ if (aShapeFileAttr->isInitialized())
+ aShapeFile = aShapeFileAttr->value();
+ }
+
+ XAOExport(theFileName, &aXao, anError, aShapeFile);
+ }
if (!anError.empty()) {
setError("An error occurred while exporting " + theFileName + ": " + anError);