From: szy Date: Tue, 23 Dec 2014 15:06:03 +0000 (+0300) Subject: Topological names management: add "buildSubShapeName". X-Git-Tag: V_0.7.0_rc1~54 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=c16dc95c6e368bbd3fd4b62aa2dbcd138b44e631;p=modules%2Fshaper.git Topological names management: add "buildSubShapeName". --- diff --git a/src/Model/Model_AttributeSelection.cpp b/src/Model/Model_AttributeSelection.cpp index f76344f55..aa3d7c976 100644 --- a/src/Model/Model_AttributeSelection.cpp +++ b/src/Model/Model_AttributeSelection.cpp @@ -35,7 +35,9 @@ #include #include #include - +#include +#include +#include using namespace std; /// adeed to the index in the packed map to signalize that the vertex of edge is seleted /// (multiplied by the index of the edge) @@ -65,6 +67,10 @@ void Model_AttributeSelection::setValue(const ResultPtr& theContext, else if (theContext->groupName() == ModelAPI_ResultConstruction::group()) selectConstruction(theContext, theSubShape); + std::string aSelName = buildSubShapeName(theSubShape, theContext); + if(!aSelName.empty()) + TDataStd_Name::Set(selectionLabel(), aSelName.c_str()); //set name + myIsInitialized = true; owner()->data()->sendAttributeUpdated(this); } @@ -426,3 +432,56 @@ TDF_Label Model_AttributeSelection::selectionLabel() { return myRef.myRef->Label().FindChild(1); } + +std::string Model_AttributeSelection::buildSubShapeName(std::shared_ptr theSubShape, + const ResultPtr& theContext) +{ + std::string aName; + if(theSubShape->isNull() || theContext->shape()->isNull()) return aName; + TopoDS_Shape aSubShape = theSubShape->impl(); + TopoDS_Shape aContext = theContext->shape()->impl(); + + // check if the subShape is already in DF + Handle(TNaming_NamedShape) aNS = TNaming_Tool::NamedShape(aSubShape, selectionLabel()); + Handle(TDataStd_Name) anAttr; + if(!aNS.IsNull()) { // in the document + if(aNS->Label().FindAttribute(TDataStd_Name::GetID(), anAttr)) { + aName = TCollection_AsciiString(anAttr->Get()).ToCString(); + if(!aName.empty()) { + std::shared_ptr aDoc = std::dynamic_pointer_cast(theContext->document()); + const TDF_Label& aLabel = aDoc->findNamingName(aName); + if(!aLabel.IsEqual(aNS->Label())) { + aName.erase(); //something is wrong, to be checked! + } + const TopoDS_Shape& aShape = aNS->Get(); + if(aShape.ShapeType() == TopAbs_COMPOUND) { + std::string aFullName = aName + "_"; + TopoDS_Iterator it(aShape); + int i(1); + for (;it.More();it.Next(), i++) { + if(it.Value() != aSubShape) continue; + else { + aName = aFullName + TCollection_AsciiString (i).ToCString(); + break; + } + } + } + } + } + } + if(aName.empty() ) { // not in the document! + TopAbs_ShapeEnum aType = aSubShape.ShapeType(); + switch (aType) { + case TopAbs_FACE: + // the Face should be in DF. If it is not a case it is an error ==> to be dbugged + + break; + case TopAbs_EDGE: + break; + case TopAbs_VERTEX: + break; + + } + } + return aName; +} diff --git a/src/Model/Model_AttributeSelection.h b/src/Model/Model_AttributeSelection.h index bc6933d39..8cfd02f30 100644 --- a/src/Model/Model_AttributeSelection.h +++ b/src/Model/Model_AttributeSelection.h @@ -39,6 +39,10 @@ public: /// \returns false if update is failed MODEL_EXPORT virtual bool update(); + /// builds name of the SubShape + MODEL_EXPORT virtual std::string buildSubShapeName(std::shared_ptr theSubShape, + const ResultPtr& theContext); + protected: /// Objects are created for features automatically MODEL_EXPORT Model_AttributeSelection(TDF_Label& theLabel); diff --git a/src/ModelAPI/ModelAPI_AttributeSelection.h b/src/ModelAPI/ModelAPI_AttributeSelection.h index 600a98204..4e8f2a51e 100644 --- a/src/ModelAPI/ModelAPI_AttributeSelection.h +++ b/src/ModelAPI/ModelAPI_AttributeSelection.h @@ -44,6 +44,9 @@ class ModelAPI_AttributeSelection : public ModelAPI_Attribute return type(); } + /// builds name of the SubShape + virtual std::string buildSubShapeName(std::shared_ptr theSubShape, + const ResultPtr& theContext) = 0; /// To virtually destroy the fields of successors virtual ~ModelAPI_AttributeSelection() {