From 7607d0803e1468dc8974a73d2fb145330901ef30 Mon Sep 17 00:00:00 2001 From: Nicolas RECHATIN Date: Thu, 26 Jan 2023 12:21:00 +0100 Subject: [PATCH] fix : Add compounds to export widget --- src/ExchangePlugin/CMakeLists.txt | 1 + .../ExchangePlugin_ExportFeature.cpp | 48 +++++-- .../ExchangePlugin_ExportRoot.cpp | 121 ++++++++++++++++-- .../ExchangePlugin_ExportRoot.h | 4 +- src/ExchangePlugin/export_widget.xml | 4 +- src/GeomAlgoAPI/GeomAlgoAPI_ROOTExport.cpp | 25 +++- src/GeomAlgoAPI/GeomAlgoAPI_ROOTExport.h | 5 +- 7 files changed, 172 insertions(+), 36 deletions(-) diff --git a/src/ExchangePlugin/CMakeLists.txt b/src/ExchangePlugin/CMakeLists.txt index ed21a8928..4ffa1aa41 100755 --- a/src/ExchangePlugin/CMakeLists.txt +++ b/src/ExchangePlugin/CMakeLists.txt @@ -34,6 +34,7 @@ INCLUDE_DIRECTORIES(${PROJECT_SOURCE_DIR}/src/Events ${PROJECT_SOURCE_DIR}/src/PartSetPlugin ${QT_INCLUDES} ${PROJECT_SOURCE_DIR}/src/PrimitivesPlugin + ${PROJECT_SOURCE_DIR}/src/FeaturesPlugin ${PROJECT_SOURCE_DIR}/src/OperaPlugin ${OpenCASCADE_INCLUDE_DIR} ) diff --git a/src/ExchangePlugin/ExchangePlugin_ExportFeature.cpp b/src/ExchangePlugin/ExchangePlugin_ExportFeature.cpp index fbfddf29d..4e202d449 100644 --- a/src/ExchangePlugin/ExchangePlugin_ExportFeature.cpp +++ b/src/ExchangePlugin/ExchangePlugin_ExportFeature.cpp @@ -678,6 +678,8 @@ void ExchangePlugin_ExportFeature::exportXAO(const std::string &theFileName) // LCOV_EXCL_STOP } +#include + void ExchangePlugin_ExportFeature::exportROOT(const std::string &theFileName) { // Get data from feature @@ -701,10 +703,13 @@ void ExchangePlugin_ExportFeature::exportROOT(const std::string &theFileName) // readFileMat(aFileMat, aMaterials, aMedias); // anAlgo->buildMaterialsMedias(aMaterials, aMedias); + // Handling data + std::list aListOfVolumes; + std::map>> aCopyData; + // Add feature in the file std::list aFeatures = document()->allFeatures(); std::list::iterator itFeature = aFeatures.begin(); - std::vector aListNamesOfFeatures; std::map aMapFeauturesObject; int aMediumIndex = 0; for (; itFeature != aFeatures.end(); ++itFeature) @@ -716,8 +721,6 @@ void ExchangePlugin_ExportFeature::exportROOT(const std::string &theFileName) aFeatureDimensions = ExchangePlugin_ExportRoot::computeBox(aFeature); std::wstring anObjectName = aFeature->firstResult()->data()->name(); anAlgo->buildBox(anObjectName, aFeatureDimensions); - aListNamesOfFeatures.push_back(anObjectName); - aListNamesOfFeatures.push_back(aFeature->data()->name()); } else if (aFeature->getKind() == "Cylinder") { @@ -725,8 +728,6 @@ void ExchangePlugin_ExportFeature::exportROOT(const std::string &theFileName) aFeatureDimensions = ExchangePlugin_ExportRoot::computeCylinder(aFeature); std::wstring anObjectName = aFeature->firstResult()->data()->name(); anAlgo->buildTube(anObjectName, aFeatureDimensions); - aListNamesOfFeatures.push_back(anObjectName); - aListNamesOfFeatures.push_back(aFeature->data()->name()); } else if (aFeature->getKind() == "Volume") { @@ -734,17 +735,42 @@ void ExchangePlugin_ExportFeature::exportROOT(const std::string &theFileName) aFeatureDimensions = ExchangePlugin_ExportRoot::computeVolume(aFeature); std::wstring anObjectName = aFeature->firstResult()->data()->name(); anAlgo->buildVolume(anObjectName, aFeatureDimensions, ++aMediumIndex); - aListNamesOfFeatures.push_back(anObjectName); - aListNamesOfFeatures.push_back(aFeature->data()->name()); + + // Add volume to known ones + aListOfVolumes.push_back(anObjectName); } else if (aFeature->getKind() == "AddNode") { - std::map aFeatureDimensions; + std::map aFeatureDimensions; aFeatureDimensions = ExchangePlugin_ExportRoot::computeAddNode(aFeature); std::wstring anObjectName = aFeature->firstResult()->data()->name(); - anAlgo->buildAddNode(anObjectName, aFeatureDimensions); - aListNamesOfFeatures.push_back(anObjectName); - aListNamesOfFeatures.push_back(aFeature->data()->name()); + + //Filter copied volumes + std::list::iterator anIter = std::find(aListOfVolumes.begin(), aListOfVolumes.end(), aFeatureDimensions["tool"]); + if (anIter != aListOfVolumes.end()) + anAlgo->buildAddNode(aFeatureDimensions, aCopyData); + } + else if (aFeature->getKind() == "Copy") + { + std::map>> aFeatureDimensions; + aFeatureDimensions = ExchangePlugin_ExportRoot::computeCopy(aFeature); + aCopyData.insert(aFeatureDimensions.begin(), aFeatureDimensions.end()); + } + else if (aFeature->getKind() == "Translation") + { + std::map aFeatureDimensions; + aFeatureDimensions = ExchangePlugin_ExportRoot::computeTranslation(aFeature); + if (aFeatureDimensions.size()) + { + std::map::iterator it; + + for (std::map::iterator it = aFeatureDimensions.begin(); it != aFeatureDimensions.end(); it++) + for (auto jt = aCopyData.begin(); jt != aCopyData.end(); jt++) + for (int k = 0; k < jt->second.size(); k++ ) + if (jt->second[k][0] == it->first) + jt->second[k][1] = it->second; + // TODO : Add TR TO ACopyData the AddNode get the TR value + } else {std::cout << "Ignoring translation" << std::endl;} } } diff --git a/src/ExchangePlugin/ExchangePlugin_ExportRoot.cpp b/src/ExchangePlugin/ExchangePlugin_ExportRoot.cpp index 86e762345..172eaa236 100644 --- a/src/ExchangePlugin/ExchangePlugin_ExportRoot.cpp +++ b/src/ExchangePlugin/ExchangePlugin_ExportRoot.cpp @@ -17,23 +17,29 @@ // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com // +#include +#include + #include #include + #include #include #include #include -#include +#include #include #include #include +#include +#include #include "math.h" - namespace ExchangePlugin_ExportRoot + namespace ExchangePlugin_ExportRoot { //=============================================================================================== std::map computeBox(FeaturePtr theFeature) @@ -133,13 +139,8 @@ FeaturePtr aSelFeature = aResult->document()->feature(aResult); std::string aKind = aSelFeature->getKind(); - // Debug data - std::wstring aWShapeName = aResult ? aResult->data()->name() : aSelFeature->firstResult()->data()->name(); - std::cout << "The volume medium is : " << aMedium << std::endl; - std::cout << "Feature kind is : " << aKind << std::endl; - std::wcout << "Feature result name is : " << aWShapeName << std::endl; - //Data out + std::wstring aWShapeName = aResult ? aResult->data()->name() : aSelFeature->firstResult()->data()->name(); std::map aFeatureDim; aFeatureDim["medium"] = aMedium; @@ -150,7 +151,7 @@ } //=============================================================================================== - std::map computeAddNode(FeaturePtr theFeature) + std::map computeAddNode(FeaturePtr theFeature) { //Get attributes std::string aMedium; @@ -170,15 +171,107 @@ std::wstring aWToolName = aToolResult ? aToolResult->data()->name() : aToolSelFeature->firstResult()->data()->name(); // Data out - std::map aFeatureDim; + std::map aFeatureDim; + aFeatureDim["main"] = aWMainName; + aFeatureDim["tool"] = aWToolName; - std::string aMainName(aWMainName.begin(), aWMainName.end()); - aFeatureDim["main"] = aMainName; + return aFeatureDim; + } - std::string aToolName(aWToolName.begin(), aWToolName.end()); - aFeatureDim["tool"] = aToolName; + //=============================================================================================== + std::map>> computeCopy(FeaturePtr theFeature) + { + // Initialisation + std::map>> aFeatureDim; + + // Get attributes + AttributeSelectionListPtr aBaseObjectList = theFeature->data()->selectionList(FeaturesPlugin_Copy::OBJECTS()); + int aNumberOfCopies = theFeature->data()->integer(FeaturesPlugin_Copy::NUMBER())->value(); + + for (int anIndex = 0; anIndex < aBaseObjectList->size(); ++anIndex) + { + AttributeSelectionPtr aSelection = aBaseObjectList->value(anIndex); + ResultPtr aMainResult = aSelection->context(); + FeaturePtr aSelectionFeature = aMainResult->document()->feature(aMainResult); + + std::cout << "Copy feature kind is : " << aSelectionFeature->getKind() << std::endl; + std::wstring aWSelName = aMainResult ? aMainResult->data()->name() : aSelectionFeature->firstResult()->data()->name(); + std::string aSelName(aWSelName.begin(), aWSelName.end()); + std::vector> aNewBaseCopies; + for (int i = 0; i < aNumberOfCopies; i++) + { + std::array aNewCopy = {aSelName + "_" + std::to_string(i+1), "0,0,0"}; //TODO : Get "copy result name" + aNewBaseCopies.push_back(aNewCopy); + } + aFeatureDim[aSelName] = aNewBaseCopies; + } return aFeatureDim; } + //=============================================================================================== + std::map computeTranslation(FeaturePtr theFeature) + { + AttributeStringPtr aMethodTypeAttr = theFeature->data()->string(FeaturesPlugin_Translation::CREATION_METHOD()); + std::string aMethodType = aMethodTypeAttr->value(); + + if (aMethodType == FeaturesPlugin_Translation::CREATION_METHOD_BY_DIMENSIONS()) + { + double DX, DY, DZ; + std::map aFeatureDim; + + DX = (theFeature->data()->real(FeaturesPlugin_Translation::DX_ID())->value()); + DY = (theFeature->data()->real(FeaturesPlugin_Translation::DY_ID())->value()); + DZ = (theFeature->data()->real(FeaturesPlugin_Translation::DZ_ID())->value()); + + AttributeSelectionListPtr aBaseObjectList = theFeature->data()->selectionList(FeaturesPlugin_Translation::OBJECTS_LIST_ID()); + for (int anIndex = 0; anIndex < aBaseObjectList->size(); ++anIndex) + { + //Get new target object name + AttributeSelectionPtr aSelection = aBaseObjectList->value(anIndex); + ResultPtr aMainResult = aSelection->context(); + FeaturePtr aSelectionFeature = aMainResult->document()->feature(aMainResult); + + std::cout << "Translation feature kind is : " << aSelectionFeature->getKind() << std::endl; + + std::wstring aWSelName = aMainResult ? aMainResult->data()->name() : aSelectionFeature->firstResult()->data()->name(); + std::string aSelName(aWSelName.begin(), aWSelName.end()); + //Add it to translated objects + std::stringstream ss; + ss << std::fixed << std::setprecision(3) << DX << "," << DY << "," << DZ; + std::string aTrStr = ss.str(); + aFeatureDim[aSelName] = aTrStr; + } + return aFeatureDim; + } + else + { + std::map aFeatureDim; + return aFeatureDim; + } + // else if (aMethodType == FeaturesPlugin_Translation::CREATION_METHOD_BY_DISTANCE()) + // { + // double anAxisOffset; + // AttributeSelectionPtr anAxis; + + // anAxis = theFeature->data()->selection(FeaturesPlugin_Translation::AXIS_OBJECT_ID()); + // anAxisOffset = (theFeature->data()->real(FeaturesPlugin_Translation::DISTANCE_ID())->value()); + + // // Get feature + // ResultPtr aResult = anAxis->context(); + // FeaturePtr anAxisFeature = aResult->document()->feature(aResult); + // std::wstring anAxisName = aResult ? aResult->data()->name() : anAxisFeature->firstResult()->data()->name(); + + // std::map aFeatureDim; + // return aFeatureDim; + // } + // else if (aMethodType == FeaturesPlugin_Translation::CREATION_METHOD_BY_TWO_POINTS()) + // { + // std::map aFeatureDim; + // return aFeatureDim; + // } + } + } // namespace ExchangePlugin_ExportRoot + +// std::map>> aCopyData; diff --git a/src/ExchangePlugin/ExchangePlugin_ExportRoot.h b/src/ExchangePlugin/ExchangePlugin_ExportRoot.h index eb77693c4..705f91a3e 100644 --- a/src/ExchangePlugin/ExchangePlugin_ExportRoot.h +++ b/src/ExchangePlugin/ExchangePlugin_ExportRoot.h @@ -29,7 +29,9 @@ namespace ExchangePlugin_ExportRoot EXCHANGEPLUGIN_EXPORT std::map computeBox(FeaturePtr theFeature); EXCHANGEPLUGIN_EXPORT std::map computeCylinder(FeaturePtr theFeature); EXCHANGEPLUGIN_EXPORT std::map computeVolume(FeaturePtr theFeature); - EXCHANGEPLUGIN_EXPORT std::map computeAddNode(FeaturePtr theFeature); + EXCHANGEPLUGIN_EXPORT std::map computeAddNode(FeaturePtr theFeature); + EXCHANGEPLUGIN_EXPORT std::map>> computeCopy(FeaturePtr theFeature); + EXCHANGEPLUGIN_EXPORT std::map computeTranslation(FeaturePtr theFeature); } #endif /* EXCHANGEPLUGIN_EXPORTROOT_H_ */ diff --git a/src/ExchangePlugin/export_widget.xml b/src/ExchangePlugin/export_widget.xml index b36da145f..097c95556 100644 --- a/src/ExchangePlugin/export_widget.xml +++ b/src/ExchangePlugin/export_widget.xml @@ -104,10 +104,10 @@ icon="" label="Main object" tooltip="Select solid object" - shape_types="solids" + shape_types="solids compounds" default="" geometrical_selection="true"> - + diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_ROOTExport.cpp b/src/GeomAlgoAPI/GeomAlgoAPI_ROOTExport.cpp index fef6e62e6..154d9dc22 100644 --- a/src/GeomAlgoAPI/GeomAlgoAPI_ROOTExport.cpp +++ b/src/GeomAlgoAPI/GeomAlgoAPI_ROOTExport.cpp @@ -144,18 +144,33 @@ void GeomAlgoAPI_ROOTExport::buildVolume(const std::wstring &theObjectName, } //================================================================================================= -void GeomAlgoAPI_ROOTExport::buildAddNode(const std::wstring &theObjectName, - const std::map theFeatureDim) +void GeomAlgoAPI_ROOTExport::buildAddNode(const std::map theFeatureDim, + const std::map>> theCopyData) { - std::string anObjectName(theObjectName.begin(), theObjectName.end()); + static int theAddNodeIndex = 0; + + std::string aMainName(theFeatureDim["main"].begin(), theFeatureDim["main"].end()); + std::string aToolName(theFeatureDim["tool"].begin(), theFeatureDim["tool"].end()); myContent << "\t" - << "//Exporting AddNode_" << anObjectName << std::endl; + << "//Exporting AddNode " << theAddNodeIndex << std::endl; myContent << "\t" - << theFeatureDim["main"] << "->AddNode(" << theFeatureDim["tool"] << ", 1);" + << aMainName << "->AddNode(" << aToolName << ", " << ++theAddNodeIndex << ");" << std::endl << std::endl; + + for (auto const &[key, val] : theCopyData){ + if (key == aToolName){ + for (auto& el: val){ + myContent << "\t" + << aMainName << "->AddNode(" << aToolName << ", " << ++theAddNodeIndex << ", " + << "new TGeoTranslation(" << el[1] <<"));" + << std::endl + << std::endl; + } + } + } } //================================================================================================= diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_ROOTExport.h b/src/GeomAlgoAPI/GeomAlgoAPI_ROOTExport.h index 403f76f5a..6851d53d7 100644 --- a/src/GeomAlgoAPI/GeomAlgoAPI_ROOTExport.h +++ b/src/GeomAlgoAPI/GeomAlgoAPI_ROOTExport.h @@ -63,9 +63,8 @@ public: const int theMediumIndex); /// Build AddNode - GEOMALGOAPI_EXPORT void buildAddNode(const std::wstring &theObjectName, - const std::map theFeatureDim); - + GEOMALGOAPI_EXPORT void buildAddNode(const std::map theFeatureDim, + const std::map>> theCopyData); /// Build Medium GEOMALGOAPI_EXPORT void addMedium(const std::string theMediumName); -- 2.39.2