From c2aa623aa6235c865252d894c8ba5d13b02341c3 Mon Sep 17 00:00:00 2001 From: mpv Date: Wed, 12 Dec 2018 14:59:29 +0300 Subject: [PATCH] Correction of tests execution: ModelAPI_TestSaveOpen2 and ExchangePlugin_TestImport --- .../ExchangePlugin_ImportFeature.cpp | 7 ++++ src/Model/Model_AttributeSelection.cpp | 37 +++++++++++++++++++ src/Model/Model_AttributeSelection.h | 3 ++ src/ModelAPI/ModelAPI_AttributeSelection.h | 3 ++ src/ModelAPI/Test/TestSaveOpen2.py | 4 +- 5 files changed, 51 insertions(+), 3 deletions(-) diff --git a/src/ExchangePlugin/ExchangePlugin_ImportFeature.cpp b/src/ExchangePlugin/ExchangePlugin_ImportFeature.cpp index c40bffec0..b6464f07f 100644 --- a/src/ExchangePlugin/ExchangePlugin_ImportFeature.cpp +++ b/src/ExchangePlugin/ExchangePlugin_ImportFeature.cpp @@ -201,6 +201,13 @@ void ExchangePlugin_ImportFeature::importXAO(const std::string& theFileName) aSelectionList->setSelectionType(aSelectionType); for (int anElementIndex = 0; anElementIndex < aXaoGroup->count(); ++anElementIndex) { aSelectionList->append(aResultBody, GeomShapePtr()); + // complex conversion of element index to reference id + int anElementID = aXaoGroup->get(anElementIndex); + std::string aReferenceString = + aXaoGeometry->getElementReference(aXaoGroup->getDimension(), anElementID); + int aReferenceID = XAO::XaoUtils::stringToInt(aReferenceString); + + aSelectionList->value(anElementIndex)->setId(aReferenceID); } } // Create new fields diff --git a/src/Model/Model_AttributeSelection.cpp b/src/Model/Model_AttributeSelection.cpp index e088c9a44..d8d4df6fe 100644 --- a/src/Model/Model_AttributeSelection.cpp +++ b/src/Model/Model_AttributeSelection.cpp @@ -1020,6 +1020,43 @@ void Model_AttributeSelection::selectSubShape(const std::string& theType, } } +void Model_AttributeSelection::setId(int theID) +{ + std::shared_ptr aSelection; + + ResultPtr aContextRes = context(); + // support for compsolids: + while(ModelAPI_Tools::bodyOwner(aContextRes).get()) { + aContextRes = ModelAPI_Tools::bodyOwner(aContextRes); + } + std::shared_ptr aContext = aContextRes->shape(); + + TopoDS_Shape aMainShape = aContext->impl(); + // searching for the latest main shape + if (theID > 0 && aContext && !aContext->isNull()) + { + std::shared_ptr aDoc = + std::dynamic_pointer_cast(aContextRes->document()); + if (aDoc.get()) { + Handle(TNaming_NamedShape) aNS = TNaming_Tool::NamedShape(aMainShape, aDoc->generalLabel()); + if (!aNS.IsNull()) { + aMainShape = TNaming_Tool::CurrentShape(aNS); + } + } + + TopTools_IndexedMapOfShape aSubShapesMap; + TopExp::MapShapes(aMainShape, aSubShapesMap); + const TopoDS_Shape& aSelShape = aSubShapesMap.FindKey(theID); + + std::shared_ptr aResult(new GeomAPI_Shape); + aResult->setImpl(new TopoDS_Shape(aSelShape)); + + aSelection = aResult; + } + + setValue(aContextRes, aSelection); +} + std::string Model_AttributeSelection::contextName(const ResultPtr& theContext) const { std::string aResult; diff --git a/src/Model/Model_AttributeSelection.h b/src/Model/Model_AttributeSelection.h index 6c8d66d73..66bbc59ff 100644 --- a/src/Model/Model_AttributeSelection.h +++ b/src/Model/Model_AttributeSelection.h @@ -100,6 +100,9 @@ public: /// \param theDefaultValue a name, which is returned if the naming name can not be obtained MODEL_EXPORT virtual std::string namingName(const std::string& theDefaultValue = ""); + /// Defines the sub-shape by Id + MODEL_EXPORT virtual void setId(int theID); + /// Selects (i.e. creates Naming data structure) of sub-shape specified by textual name MODEL_EXPORT virtual void selectSubShape(const std::string& theType, const std::string& theSubShapeName); diff --git a/src/ModelAPI/ModelAPI_AttributeSelection.h b/src/ModelAPI/ModelAPI_AttributeSelection.h index a1df51888..5f7711197 100644 --- a/src/ModelAPI/ModelAPI_AttributeSelection.h +++ b/src/ModelAPI/ModelAPI_AttributeSelection.h @@ -95,6 +95,9 @@ class ModelAPI_AttributeSelection : public ModelAPI_Attribute /// \param theDefaultValue a value, which is used if the naming name can not be obtained virtual std::string namingName(const std::string& theDefaultValue = "") = 0; + /// Defines an id of the selection + virtual void setId(int theID) = 0; + /// Selects sub-shape by the textual Name virtual void selectSubShape(const std::string& theType, const std::string& theSubShapeName) = 0; diff --git a/src/ModelAPI/Test/TestSaveOpen2.py b/src/ModelAPI/Test/TestSaveOpen2.py index 133ba146c..b2e6cc928 100644 --- a/src/ModelAPI/Test/TestSaveOpen2.py +++ b/src/ModelAPI/Test/TestSaveOpen2.py @@ -65,9 +65,7 @@ aFieldFeature = aPartDoc.objectByName("Features", "Field_1") aFieldResult = modelAPI_ResultField(objectToFeature(aFieldFeature).results()[0]) assert(aFieldResult.textLine(0) == "5") aSession.setActiveDocument(partSet, True) +model.do() aTranslation = objectToFeature(partSet.objectByName("Features", "Translation_1")) partSet.setCurrentFeature(aTranslation, True) model.end() - -# check the translation feature has a correct result -assert(not aTranslation.firstResult().shape().isNull()) \ No newline at end of file -- 2.39.2