From dc90df3ac278c727aca81131746a9806e4f27499 Mon Sep 17 00:00:00 2001 From: mpv Date: Wed, 16 Sep 2015 10:27:52 +0300 Subject: [PATCH] Fix for the issue #769: fillet now does not destroy the naming of the modified edge of the sketch. --- src/Model/Model_AttributeRefList.cpp | 31 +++++++++++++++++++ src/Model/Model_AttributeRefList.h | 3 ++ src/ModelAPI/ModelAPI_AttributeRefList.h | 5 ++- src/ModelAPI/ModelAPI_CompositeFeature.cpp | 6 ++++ src/ModelAPI/ModelAPI_CompositeFeature.h | 4 +++ src/PartSet/PartSet_WidgetSketchLabel.cpp | 1 + .../SketchPlugin_ConstraintFillet.cpp | 3 ++ src/SketchPlugin/SketchPlugin_Sketch.cpp | 6 ++++ src/SketchPlugin/SketchPlugin_Sketch.h | 5 +++ 9 files changed, 63 insertions(+), 1 deletion(-) diff --git a/src/Model/Model_AttributeRefList.cpp b/src/Model/Model_AttributeRefList.cpp index bb9fa83e2..ee9b20d74 100644 --- a/src/Model/Model_AttributeRefList.cpp +++ b/src/Model/Model_AttributeRefList.cpp @@ -164,6 +164,37 @@ void Model_AttributeRefList::substitute(const ObjectPtr& theCurrent, const Objec } } +void Model_AttributeRefList::exchange(const ObjectPtr& theObject1, const ObjectPtr& theObject2) +{ + std::shared_ptr aDoc = std::dynamic_pointer_cast( + owner()->document()); + if (aDoc) { + std::shared_ptr aData1 = std::dynamic_pointer_cast(theObject1->data()); + if (aData1.get() && aData1->isValid()) { + TDF_Label aLab1 = aData1->label().Father(); + if (theObject2.get() && theObject2->data()->isValid()) { // the new may be null + std::shared_ptr aData2 = + std::dynamic_pointer_cast(theObject2->data()); + if (aData2.get() && aData2->isValid()) { + TDF_Label aLab2 = aData2->label().Father(); + // do the substitution: use the temporary label, as usually in exchange + TDF_Label aTmpLab = aLab1.Root(); + if (myRef->InsertAfter(aTmpLab, aLab1)) { + myRef->Remove(aLab1); + } + if (myRef->InsertAfter(aLab1, aLab2)) { + myRef->Remove(aLab2); + } + if (myRef->InsertAfter(aLab2, aTmpLab)) { + myRef->Remove(aTmpLab); + } + owner()->data()->sendAttributeUpdated(this); + } + } + } + } +} + void Model_AttributeRefList::removeLast() { std::shared_ptr aDoc = std::dynamic_pointer_cast( diff --git a/src/Model/Model_AttributeRefList.h b/src/Model/Model_AttributeRefList.h index 52de359b1..c329662d0 100644 --- a/src/Model/Model_AttributeRefList.h +++ b/src/Model/Model_AttributeRefList.h @@ -50,6 +50,9 @@ class Model_AttributeRefList : public ModelAPI_AttributeRefList /// Substitutes the feature by another one. Does nothing if such object is not found. MODEL_EXPORT virtual void substitute(const ObjectPtr& theCurrent, const ObjectPtr& theNew); + /// Substitutes the object by another one and back. So, features wil become exchanged in the list + MODEL_EXPORT virtual void exchange(const ObjectPtr& theObject1, const ObjectPtr& theObject2); + /// Removes the last element in the list. MODEL_EXPORT virtual void removeLast(); diff --git a/src/ModelAPI/ModelAPI_AttributeRefList.h b/src/ModelAPI/ModelAPI_AttributeRefList.h index 2a282108f..d51900022 100644 --- a/src/ModelAPI/ModelAPI_AttributeRefList.h +++ b/src/ModelAPI/ModelAPI_AttributeRefList.h @@ -52,9 +52,12 @@ class ModelAPI_AttributeRefList : public ModelAPI_Attribute ///\param theWithEmpty if it is false, counts the not-empty referenced objects only virtual ObjectPtr object(const int theIndex, const bool theWithEmpty = true) const = 0; - /// Substitutes the feature by another one. Does nothing if such object is not found. + /// Substitutes the object by another one. Does nothing if such object is not found. virtual void substitute(const ObjectPtr& theCurrent, const ObjectPtr& theNew) = 0; + /// Substitutes the object by another one and back. So, features wil become exchanged in the list + virtual void exchange(const ObjectPtr& theObject1, const ObjectPtr& theObject2) = 0; + /// Removes the last element in the list. virtual void removeLast() = 0; diff --git a/src/ModelAPI/ModelAPI_CompositeFeature.cpp b/src/ModelAPI/ModelAPI_CompositeFeature.cpp index 71b6fc280..7913a8bde 100644 --- a/src/ModelAPI/ModelAPI_CompositeFeature.cpp +++ b/src/ModelAPI/ModelAPI_CompositeFeature.cpp @@ -10,3 +10,9 @@ ModelAPI_CompositeFeature::~ModelAPI_CompositeFeature() { } + +void ModelAPI_CompositeFeature::exchangeIDs( + std::shared_ptr theFeature1, std::shared_ptr theFeature2) +{ + // by default nothing is in the implementation +} diff --git a/src/ModelAPI/ModelAPI_CompositeFeature.h b/src/ModelAPI/ModelAPI_CompositeFeature.h index 4a86409e2..bc31a21eb 100644 --- a/src/ModelAPI/ModelAPI_CompositeFeature.h +++ b/src/ModelAPI/ModelAPI_CompositeFeature.h @@ -39,6 +39,10 @@ public: /// This method to inform that sub-feature is removed and must be removed from the internal data /// structures of the owner (the remove from the document will be done outside just after) virtual void removeFeature(std::shared_ptr theFeature) = 0; + + /// Exchanges IDs of two given features: needed for more correct naming in some cases (issue 769) + MODELAPI_EXPORT virtual void exchangeIDs(std::shared_ptr theFeature1, + std::shared_ptr theFeature2); }; //! Pointer on the composite feature object diff --git a/src/PartSet/PartSet_WidgetSketchLabel.cpp b/src/PartSet/PartSet_WidgetSketchLabel.cpp index 5b63142db..e4df553d7 100644 --- a/src/PartSet/PartSet_WidgetSketchLabel.cpp +++ b/src/PartSet/PartSet_WidgetSketchLabel.cpp @@ -337,6 +337,7 @@ void PartSet_WidgetSketchLabel::showPreviewPlanes() // Create Preview std::shared_ptr anOrigin(new GeomAPI_Pnt(0, 0, 0)); std::shared_ptr aYZDir(new GeomAPI_Dir(1, 0, 0)); + // -1, not 1 for correct internal sketch coords (issue 898) std::shared_ptr aXZDir(new GeomAPI_Dir(0, -1, 0)); std::shared_ptr aXYDir(new GeomAPI_Dir(0, 0, 1)); diff --git a/src/SketchPlugin/SketchPlugin_ConstraintFillet.cpp b/src/SketchPlugin/SketchPlugin_ConstraintFillet.cpp index 6cf6da8f6..a9f00c9f4 100644 --- a/src/SketchPlugin/SketchPlugin_ConstraintFillet.cpp +++ b/src/SketchPlugin/SketchPlugin_ConstraintFillet.cpp @@ -316,6 +316,9 @@ void SketchPlugin_ConstraintFillet::execute() myBaseObjects.clear(); myBaseObjects.push_back(aFeatureA); myBaseObjects.push_back(aFeatureB); + // exchange the naming IDs of newly created and old line that become auxiliary + sketch()->exchangeIDs(aFeatureA, aNewFeatureA); + sketch()->exchangeIDs(aFeatureB, aNewFeatureB); } else { // Update radius value int aNbSubs = sketch()->numberOfSubs(); diff --git a/src/SketchPlugin/SketchPlugin_Sketch.cpp b/src/SketchPlugin/SketchPlugin_Sketch.cpp index 972c95693..21247d13a 100644 --- a/src/SketchPlugin/SketchPlugin_Sketch.cpp +++ b/src/SketchPlugin/SketchPlugin_Sketch.cpp @@ -319,3 +319,9 @@ std::shared_ptr SketchPlugin_Sketch::plane(SketchPlugin_Sketch* the return std::shared_ptr(new GeomAPI_Ax3(anOrigin->pnt(), aDirX->dir(), aNorm->dir())); } + +void SketchPlugin_Sketch::exchangeIDs( + std::shared_ptr theFeature1, std::shared_ptr theFeature2) +{ + reflist(SketchPlugin_Sketch::FEATURES_ID())->exchange(theFeature1, theFeature2); +} diff --git a/src/SketchPlugin/SketchPlugin_Sketch.h b/src/SketchPlugin/SketchPlugin_Sketch.h index 3246a2ad7..cef6307e6 100644 --- a/src/SketchPlugin/SketchPlugin_Sketch.h +++ b/src/SketchPlugin/SketchPlugin_Sketch.h @@ -196,6 +196,11 @@ class SketchPlugin_Sketch : public ModelAPI_CompositeFeature, public GeomAPI_ICu SKETCHPLUGIN_EXPORT virtual void attributeChanged(const std::string& theID); + /// Exchanges IDs of two given features: needed for fillet feature better naming (issue 769) + SKETCHPLUGIN_EXPORT virtual void exchangeIDs(std::shared_ptr theFeature1, + std::shared_ptr theFeature2); + + /// \brief Create a result for the point in the attribute if the attribute is initialized /// \param theAttributeID an attribute string /// \param theIndex an index of the result -- 2.39.2