${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}
)
// LCOV_EXCL_STOP
}
+#include <iostream>
+
void ExchangePlugin_ExportFeature::exportROOT(const std::string &theFileName)
{
// Get data from feature
// readFileMat(aFileMat, aMaterials, aMedias);
// anAlgo->buildMaterialsMedias(aMaterials, aMedias);
+ // Handling data
+ std::list<std::wstring> aListOfVolumes;
+ std::map<std::string, std::vector <std::array<std::string, 2>>> aCopyData;
+
// Add feature in the file
std::list<FeaturePtr> aFeatures = document()->allFeatures();
std::list<FeaturePtr>::iterator itFeature = aFeatures.begin();
- std::vector<std::wstring> aListNamesOfFeatures;
std::map<std::wstring, std::string> aMapFeauturesObject;
int aMediumIndex = 0;
for (; itFeature != aFeatures.end(); ++itFeature)
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")
{
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")
{
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<std::string, std::string> aFeatureDimensions;
+ std::map<std::string, std::wstring> 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<std::wstring>::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<std::string, std::vector<std::array<std::string, 2>>> aFeatureDimensions;
+ aFeatureDimensions = ExchangePlugin_ExportRoot::computeCopy(aFeature);
+ aCopyData.insert(aFeatureDimensions.begin(), aFeatureDimensions.end());
+ }
+ else if (aFeature->getKind() == "Translation")
+ {
+ std::map<std::string, std::string> aFeatureDimensions;
+ aFeatureDimensions = ExchangePlugin_ExportRoot::computeTranslation(aFeature);
+ if (aFeatureDimensions.size())
+ {
+ std::map<std::string, std::string>::iterator it;
+
+ for (std::map<std::string, std::string>::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;}
}
}
// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
//
+#include <FeaturesPlugin_Copy.h>
+#include <FeaturesPlugin_Translation.h>
+
#include <PrimitivesPlugin_Box.h>
#include <PrimitivesPlugin_Cylinder.h>
+
#include <OperaPlugin_Volume.h>
#include <OperaPlugin_AddNode.h>
#include <GeomAlgoAPI_PointBuilder.h>
#include <ModelAPI_AttributeDouble.h>
-#include <ModelAPI_AttributeString.h>
+#include <ModelAPI_AttributeInteger.h>
#include <ModelAPI_AttributeSelectionList.h>
#include <string>
#include <iostream>
+#include <iomanip>
+#include <sstream>
#include "math.h"
- namespace ExchangePlugin_ExportRoot
+ namespace ExchangePlugin_ExportRoot
{
//===============================================================================================
std::map<std::string, double> computeBox(FeaturePtr theFeature)
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<std::string, std::string> aFeatureDim;
aFeatureDim["medium"] = aMedium;
}
//===============================================================================================
- std::map<std::string, std::string> computeAddNode(FeaturePtr theFeature)
+ std::map<std::string, std::wstring> computeAddNode(FeaturePtr theFeature)
{
//Get attributes
std::string aMedium;
std::wstring aWToolName = aToolResult ? aToolResult->data()->name() : aToolSelFeature->firstResult()->data()->name();
// Data out
- std::map<std::string, std::string> aFeatureDim;
+ std::map<std::string, std::wstring> 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<std::string, std::vector<std::array<std ::string, 2>>> computeCopy(FeaturePtr theFeature)
+ {
+ // Initialisation
+ std::map<std::string, std::vector<std::array<std :: string, 2>>> 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<std::array<std::string, 2>> aNewBaseCopies;
+ for (int i = 0; i < aNumberOfCopies; i++)
+ {
+ std::array <std::string, 2> 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<std::string, std::string> 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<std::string, std::string> 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<std::string, std::string> 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<std::string, std::string> aFeatureDim;
+ // return aFeatureDim;
+ // }
+ // else if (aMethodType == FeaturesPlugin_Translation::CREATION_METHOD_BY_TWO_POINTS())
+ // {
+ // std::map<std::string, std::string> aFeatureDim;
+ // return aFeatureDim;
+ // }
+ }
+
} // namespace ExchangePlugin_ExportRoot
+
+// std::map<std::string, std::vector<std::array<std : string, 2>>> aCopyData;
EXCHANGEPLUGIN_EXPORT std::map<std::string, double> computeBox(FeaturePtr theFeature);
EXCHANGEPLUGIN_EXPORT std::map<std::string, double> computeCylinder(FeaturePtr theFeature);
EXCHANGEPLUGIN_EXPORT std::map<std::string, std::string> computeVolume(FeaturePtr theFeature);
- EXCHANGEPLUGIN_EXPORT std::map<std::string, std::string> computeAddNode(FeaturePtr theFeature);
+ EXCHANGEPLUGIN_EXPORT std::map<std::string, std::wstring> computeAddNode(FeaturePtr theFeature);
+ EXCHANGEPLUGIN_EXPORT std::map<std::string, std::vector<std::array<std ::string, 2>>> computeCopy(FeaturePtr theFeature);
+ EXCHANGEPLUGIN_EXPORT std::map<std::string, std::string> computeTranslation(FeaturePtr theFeature);
}
#endif /* EXCHANGEPLUGIN_EXPORTROOT_H_ */
icon=""
label="Main object"
tooltip="Select solid object"
- shape_types="solids"
+ shape_types="solids compounds"
default=""
geometrical_selection="true">
- <validator id="GeomValidators_ShapeType" parameters="solid"/>
+ <validator id="GeomValidators_ShapeType" parameters="solid compound" />
</shape_selector>
<file_selector id="mat_file" title="Materials file" path="">
</file_selector>
}
//=================================================================================================
-void GeomAlgoAPI_ROOTExport::buildAddNode(const std::wstring &theObjectName,
- const std::map<std::string, std::string> theFeatureDim)
+void GeomAlgoAPI_ROOTExport::buildAddNode(const std::map<std::string, std::wstring> theFeatureDim,
+ const std::map<std::string, std::vector<std::array<std::string, 2>>> 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;
+ }
+ }
+ }
}
//=================================================================================================
const int theMediumIndex);
/// Build AddNode
- GEOMALGOAPI_EXPORT void buildAddNode(const std::wstring &theObjectName,
- const std::map<std::string, std::string> theFeatureDim);
-
+ GEOMALGOAPI_EXPORT void buildAddNode(const std::map<std::string, std::wstring> theFeatureDim,
+ const std::map<std::string, std::vector<std::array<std::string, 2>>> theCopyData);
/// Build Medium
GEOMALGOAPI_EXPORT void addMedium(const std::string theMediumName);