From d732760a27f3ff4607b007a4cf84901b1f5f32fc Mon Sep 17 00:00:00 2001 From: szy Date: Fri, 26 Dec 2014 18:37:35 +0300 Subject: [PATCH] Added 'selectSubShape' for sub-shape selection by name for faces. --- src/Model/Model_AttributeSelection.cpp | 112 +++++++++++++++++++++ src/Model/Model_AttributeSelection.h | 4 + src/ModelAPI/ModelAPI_AttributeSelection.h | 5 +- 3 files changed, 119 insertions(+), 2 deletions(-) diff --git a/src/Model/Model_AttributeSelection.cpp b/src/Model/Model_AttributeSelection.cpp index f610b3dbe..6e7e78cd2 100644 --- a/src/Model/Model_AttributeSelection.cpp +++ b/src/Model/Model_AttributeSelection.cpp @@ -620,3 +620,115 @@ std::string Model_AttributeSelection::namingName()//std::shared_ptr theDoc) +{ + TopoDS_Shape aFace; + const TDF_Label& aLabel = theDoc->findNamingName(theSubShapeName); + if(aLabel.IsNull()) return aFace; + Handle(TNaming_NamedShape) aNS; + if(aLabel.FindAttribute(TNaming_NamedShape::GetID(), aNS)) { + const TopoDS_Shape& aShape = aNS->Get(); + if(!aShape.IsNull()) { + if(aShape.ShapeType() == TopAbs_COMPOUND) + aFace = getShapeFromCompound(theSubShapeName, aShape); + else + aFace = aShape; + } + } + return aFace; +} +void Model_AttributeSelection::selectSubShape(const std::string& theType, const std::string& theSubShapeName) +{ + if(theSubShapeName.empty() || theType.empty()) return; + TopAbs_ShapeEnum aType = translateType(theType); + ResultPtr aCont = context(); + if(!aCont.get() || aCont->shape()->isNull()) return; + TopoDS_Shape aContext = aCont->shape()->impl(); + TopAbs_ShapeEnum aContType = aContext.ShapeType(); + if(aType <= aContType) return; // not applicable + + std::shared_ptr aDoc = std::dynamic_pointer_cast(aCont->document()); + TopoDS_Shape aSelection; + switch (aType) + { + case TopAbs_COMPOUND: + break; + case TopAbs_COMPSOLID: + break; + case TopAbs_SOLID: + break; + case TopAbs_SHELL: + break; + case TopAbs_FACE: + { + const TopoDS_Shape aSelection = findFaceByName(theSubShapeName, aDoc); + if(!aSelection.IsNull()) {// Select it + std::shared_ptr aShapeToBeSelected(new GeomAPI_Shape()); + aShapeToBeSelected->setImpl(new TopoDS_Shape(aSelection)); + setValue(aCont, aShapeToBeSelected); + } + } + break; + case TopAbs_WIRE: + break; + case TopAbs_EDGE: + { + TopTools_ListOfShape aList; + std::list aListofNames; + //ParseEdgeName(); + + } + break; + case TopAbs_VERTEX: + break; + default: //TopAbs_SHAPE + return; + } + +} \ No newline at end of file diff --git a/src/Model/Model_AttributeSelection.h b/src/Model/Model_AttributeSelection.h index 74c77344d..4ca2ef3db 100644 --- a/src/Model/Model_AttributeSelection.h +++ b/src/Model/Model_AttributeSelection.h @@ -42,6 +42,9 @@ public: /// Returns a textual string of the selection MODEL_EXPORT virtual std::string namingName(); + /// Selects (i.e. creates Naming data structure) of sub-shape specifed by textual name + MODEL_EXPORT virtual void selectSubShape(const std::string& theType, const std::string& theSubShapeName); + protected: /// Objects are created for features automatically MODEL_EXPORT Model_AttributeSelection(TDF_Label& theLabel); @@ -50,6 +53,7 @@ protected: /// Performs the selection for the body result (TNaming selection) virtual void selectBody( const ResultPtr& theContext, const std::shared_ptr& theSubShape); + /// Performs the selection for the construction result (selection by index) virtual void selectConstruction( const ResultPtr& theContext, const std::shared_ptr& theSubShape); diff --git a/src/ModelAPI/ModelAPI_AttributeSelection.h b/src/ModelAPI/ModelAPI_AttributeSelection.h index b56241025..3778ecdd4 100644 --- a/src/ModelAPI/ModelAPI_AttributeSelection.h +++ b/src/ModelAPI/ModelAPI_AttributeSelection.h @@ -48,8 +48,9 @@ class ModelAPI_AttributeSelection : public ModelAPI_Attribute virtual std::string namingName() = 0; - /// Selects sub-shape by Name - //virtual selectSubShape(const std::string& theSubShapeName, const std::string& theContextShapeName) + /// Selects sub-shape by the textual Name + virtual void selectSubShape(const std::string& theType, const std::string& theSubShapeName) = 0; + /// To virtually destroy the fields of successors virtual ~ModelAPI_AttributeSelection() { -- 2.39.2