From 5ad51988c7e9357d6f65415b3555be8f7a38e508 Mon Sep 17 00:00:00 2001 From: mpv Date: Wed, 31 Oct 2018 17:44:44 +0300 Subject: [PATCH] Fix the problem with renamed sketch edges vertices selection (the stator_ermes case) --- src/Model/Model_AttributeSelection.cpp | 43 ++++++++++++++++++++++++-- src/Model/Model_AttributeSelection.h | 22 +++++++------ 2 files changed, 53 insertions(+), 12 deletions(-) diff --git a/src/Model/Model_AttributeSelection.cpp b/src/Model/Model_AttributeSelection.cpp index 61b85dd89..0c07f092e 100644 --- a/src/Model/Model_AttributeSelection.cpp +++ b/src/Model/Model_AttributeSelection.cpp @@ -705,6 +705,44 @@ bool Model_AttributeSelection::update() return setInvalidIfFalse(aSelLab, false); // unknown case } +/// integer that contains the tag number of external construction shape naming +static Standard_GUID kEXTERNAL_CONSTRUCTION_TAG("f7d0726f-e848-4d22-9101-def16d0eff2c"); + +void Model_AttributeSelection::storeExternalConstruction( + const ResultConstructionPtr& theConstruction, const GeomShapePtr& theSubShape) +{ + std::string aName = namingName(); + if (aName.empty()) // unknown error + return; + std::shared_ptr aMyDoc = + std::dynamic_pointer_cast(owner()->document()); + TDF_Label anExternalLab = aMyDoc->extConstructionsLabel(); + Handle(TDataStd_Integer) anExtTag; + if (selectionLabel().FindAttribute(kEXTERNAL_CONSTRUCTION_TAG, anExtTag)) { + anExternalLab = anExternalLab.FindChild(anExtTag->Get()); // use existing label + } else { + // search label with the same name + TDF_ChildIDIterator aNamesIter(anExternalLab, TDataStd_Name::GetID()); + for(; aNamesIter.More(); aNamesIter.Next()) { + if (aName == TCollection_AsciiString(Handle(TDataStd_Name)::DownCast( + aNamesIter.Value())->Get()).ToCString()) { + anExternalLab = aNamesIter.Value()->Label(); + break; + } + } + if (aNamesIter.More()) { + } else { + anExternalLab = anExternalLab.NewChild(); // create new label + TDataStd_Integer::Set(selectionLabel(), kEXTERNAL_CONSTRUCTION_TAG, + anExternalLab.Tag()); // store this tag in the data model + } + } + anExternalLab.ForgetAllAttributes(); + TopoDS_Shape aSubShape = theSubShape->impl(); + TNaming_Builder aBuilder(anExternalLab); + aBuilder.Generated(aSubShape); +} + void Model_AttributeSelection::selectBody( const ResultPtr& theContext, const std::shared_ptr& theSubShape) { @@ -755,10 +793,9 @@ void Model_AttributeSelection::selectBody( if (aFaceIndex >= 0) { TDataStd_Integer::Set(aSelLab, theSubShape->shapeType() == GeomAPI_Shape::FACE ? kEXT_SKETCH_FACE : kEXT_SKETCH_WIRE, aFaceIndex); // store index of the face + //storeExternalConstruction(aConstr, theSubShape); return; } - } else if (theSubShape->shapeType() == GeomAPI_Shape::WIRE) { - } else if (theSubShape->shapeType() == GeomAPI_Shape::EDGE ||// sketch result edge (full one) theSubShape->shapeType() == GeomAPI_Shape::VERTEX) { // or start/end vertex bool isVertex = theSubShape->shapeType() == GeomAPI_Shape::VERTEX; @@ -1684,7 +1721,7 @@ bool Model_AttributeSelection::restoreContext(std::string theName, if ((*aRes)->data()->name() == aCompName) { theValue = std::dynamic_pointer_cast((*aRes)->data())->shapeLab(); break; - } else if (aCompName.find((*aRes)->data()->name()) != std::string::npos) {// sub-vertex + } else { // any sub-label because the sketch line may be renamed, but not sub-vertices TDF_Label aLab = std::dynamic_pointer_cast((*aRes)->data())->shapeLab(); TDF_ChildIDIterator aSubNames(aLab, TDataStd_Name::GetID()); for(; aSubNames.More(); aSubNames.Next()) { diff --git a/src/Model/Model_AttributeSelection.h b/src/Model/Model_AttributeSelection.h index 45b8ba7c2..8759f8d58 100644 --- a/src/Model/Model_AttributeSelection.h +++ b/src/Model/Model_AttributeSelection.h @@ -31,6 +31,7 @@ class Model_AttributeSelectionList; class Model_Document; +class ModelAPI_ResultConstruction; /**\class Model_AttributeSelection * \ingroup DataModel @@ -39,14 +40,14 @@ class Model_Document; class Model_AttributeSelection : public ModelAPI_AttributeSelection, public Selector_NameGenerator { - Model_AttributeReference myRef; ///< The reference functionality reusage + Model_AttributeReference myRef; ///< The reference functionality re-usage /// temporarily storages to avoid keeping in the data structure if not needed ResultPtr myTmpContext; /// temporarily storages to avoid keeping in the data structure if not needed std::shared_ptr myTmpSubShape; /// temporarily storages to avoid keeping in the data structure if not needed CenterType myTmpCenterType; - /// Reference to the partent attribute, if any (to split selection compounds in issue 1799) + /// Reference to the parent attribute, if any (to split selection compounds in issue 1799) Model_AttributeSelectionList* myParent; std::shared_ptr myRestoreDocument; // current document to restore by name @@ -55,7 +56,7 @@ public: /// \param theContext object where the sub-shape was selected /// \param theSubShape selected sub-shape (if null, the whole context is selected) /// \param theTemporarily if it is true, do not store and name the added in the data framework - /// (used to remove immideately, without the following updates) + /// (used to remove immediately, without the following updates) /// \returns true if attribute was updated MODEL_EXPORT virtual bool setValue( const ObjectPtr& theContext, const std::shared_ptr& theSubShape, @@ -89,7 +90,7 @@ public: /// Sets the feature object MODEL_EXPORT virtual void setObject(const std::shared_ptr& theObject); - /// Updates the underlied selection due to the changes in the referenced objects + /// Updates the selection due to the changes in the referenced objects /// \returns false if update is failed MODEL_EXPORT virtual bool update(); @@ -107,7 +108,7 @@ public: /// NOTE: This method is opposite to Id() method. MODEL_EXPORT virtual void setId(int theID); - /// Selects (i.e. creates Naming data structure) of sub-shape specifed by textual name + /// 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); @@ -121,7 +122,7 @@ public: /// Returns true if attribute was initialized by some value MODEL_EXPORT virtual bool isInitialized(); - /// Returns true if recomute of selection become impossible + /// Returns true if recompute of selection become impossible MODEL_EXPORT virtual bool isInvalid(); /// Updates the arguments of selection if something was affected by creation @@ -157,8 +158,11 @@ protected: /// Returns theType type of the center, or NOT_CENTER if it is not. std::shared_ptr internalValue(CenterType& theType); - - /// Performs the selection for the body result (TNaming Selection) + /// stores the naming structure of external construction (sketch element) in the data + /// tree of this document with name equal to selection-name in external document + void storeExternalConstruction( + const std::shared_ptr& theConstruction, + const std::shared_ptr& theSubShape); /// Performs the selection for the body result (TNaming selection) virtual void selectBody( @@ -168,7 +172,7 @@ protected: /// \param theContext the result - owner of the selection /// \param theSubShape selected shape /// \param theUpdate flag that shows that it must be just update, theShape is null - /// \returns true if eveything is selected correctly + /// \returns true if everything is selected correctly virtual bool selectPart( const ResultPtr& theContext, const std::shared_ptr& theSubShape, const bool theUpdate = false); -- 2.39.2