From c3181094455d7e8f52d887b54dbfb798d4c4d210 Mon Sep 17 00:00:00 2001 From: azv Date: Wed, 8 Apr 2015 16:57:25 +0300 Subject: [PATCH] Update constraint Mirror. Fix a problem with Coincidence --- src/Model/Model_AttributeRefList.cpp | 1 + src/Model/Model_AttributeSelection.cpp | 6 +++++ src/Model/Model_AttributeSelection.h | 3 +++ src/Model/Model_AttributeSelectionList.cpp | 1 + src/ModelAPI/ModelAPI_Attribute.h | 2 +- src/SketchPlugin/SketchPlugin_Plugin.cpp | 2 ++ src/SketchPlugin/SketchPlugin_Validators.cpp | 25 +++++++++++++++++++ src/SketchPlugin/SketchPlugin_Validators.h | 16 ++++++++++++ src/SketchPlugin/plugin-Sketch.xml | 1 + .../SketchSolver_ConstraintCoincidence.cpp | 2 +- src/SketchSolver/SketchSolver_Storage.cpp | 8 +++++- 11 files changed, 64 insertions(+), 3 deletions(-) diff --git a/src/Model/Model_AttributeRefList.cpp b/src/Model/Model_AttributeRefList.cpp index c09190f33..13233fb9c 100644 --- a/src/Model/Model_AttributeRefList.cpp +++ b/src/Model/Model_AttributeRefList.cpp @@ -29,6 +29,7 @@ void Model_AttributeRefList::remove(ObjectPtr theObject) if (theObject.get() != NULL) { aData = std::dynamic_pointer_cast(theObject->data()); myRef->Remove(aData->label().Father()); + REMOVE_BACK_REF(theObject); } else { // in case of empty object remove, the first empty object is removed from the list std::shared_ptr aDoc = std::dynamic_pointer_cast( diff --git a/src/Model/Model_AttributeSelection.cpp b/src/Model/Model_AttributeSelection.cpp index 3e2333345..b522b90a1 100644 --- a/src/Model/Model_AttributeSelection.cpp +++ b/src/Model/Model_AttributeSelection.cpp @@ -171,6 +171,12 @@ Model_AttributeSelection::Model_AttributeSelection(TDF_Label& theLabel) myIsInitialized = myRef.isInitialized(); } +void Model_AttributeSelection::setID(const std::string theID) +{ + myRef.setID(theID); + ModelAPI_AttributeSelection::setID(theID); +} + ResultPtr Model_AttributeSelection::context() { return std::dynamic_pointer_cast(myRef.value()); } diff --git a/src/Model/Model_AttributeSelection.h b/src/Model/Model_AttributeSelection.h index 8708c136d..22aaf8d9f 100644 --- a/src/Model/Model_AttributeSelection.h +++ b/src/Model/Model_AttributeSelection.h @@ -71,6 +71,9 @@ protected: /// Returns the prepared map of valid labels for naming selection solving (creates if not exists) TDF_LabelMap& scope(); + /// Sets the ID of the attribute in Data (called from Data): here it is used for myRef ID setting + MODELAPI_EXPORT virtual void setID(const std::string theID); + friend class Model_Data; friend class Model_AttributeSelectionList; }; diff --git a/src/Model/Model_AttributeSelectionList.cpp b/src/Model/Model_AttributeSelectionList.cpp index 24a9efca5..79eb5c714 100644 --- a/src/Model/Model_AttributeSelectionList.cpp +++ b/src/Model/Model_AttributeSelectionList.cpp @@ -39,6 +39,7 @@ void Model_AttributeSelectionList::append( if (owner()) { aNewAttr->setObject(owner()); } + aNewAttr->setID(id()); mySize->Set(aNewTag); aNewAttr->setValue(theContext, theSubShape); owner()->data()->sendAttributeUpdated(this); diff --git a/src/ModelAPI/ModelAPI_Attribute.h b/src/ModelAPI/ModelAPI_Attribute.h index 1892b77bc..e3b1b056d 100644 --- a/src/ModelAPI/ModelAPI_Attribute.h +++ b/src/ModelAPI/ModelAPI_Attribute.h @@ -77,7 +77,7 @@ class ModelAPI_Attribute MODELAPI_EXPORT ModelAPI_Attribute(); /// Sets the ID of the attribute in Data (called from Data) - MODELAPI_EXPORT void setID(const std::string theID); + MODELAPI_EXPORT virtual void setID(const std::string theID); friend class Model_Data; }; diff --git a/src/SketchPlugin/SketchPlugin_Plugin.cpp b/src/SketchPlugin/SketchPlugin_Plugin.cpp index e92cdb8c4..91a92ce7b 100644 --- a/src/SketchPlugin/SketchPlugin_Plugin.cpp +++ b/src/SketchPlugin/SketchPlugin_Plugin.cpp @@ -59,6 +59,8 @@ SketchPlugin_Plugin::SketchPlugin_Plugin() new SketchPlugin_NotFixedValidator); aFactory->registerValidator("SketchPlugin_EqualAttr", new SketchPlugin_EqualAttrValidator); + aFactory->registerValidator("SketchPlugin_MirrorAttr", + new SketchPlugin_MirrorAttrValidator); // register this plugin ModelAPI_Session::get()->registerPlugin(this); diff --git a/src/SketchPlugin/SketchPlugin_Validators.cpp b/src/SketchPlugin/SketchPlugin_Validators.cpp index 95da79b95..72f0b61d1 100644 --- a/src/SketchPlugin/SketchPlugin_Validators.cpp +++ b/src/SketchPlugin/SketchPlugin_Validators.cpp @@ -18,6 +18,8 @@ #include #include #include +#include +#include #include #include @@ -211,3 +213,26 @@ bool SketchPlugin_EqualAttrValidator::isValid( return true; } +bool SketchPlugin_MirrorAttrValidator::isValid( + const AttributePtr& theAttribute, const std::list& theArguments ) const +{ + FeaturePtr aFeature = std::dynamic_pointer_cast(theAttribute->owner()); + AttributeSelectionListPtr aSelAttr = + std::dynamic_pointer_cast(theAttribute); + if (!aSelAttr) + return false; + + AttributeRefListPtr aRefListOfMirrored = std::dynamic_pointer_cast( + aFeature->attribute(SketchPlugin_Constraint::ENTITY_C())); + std::list aMirroredObjects = aRefListOfMirrored->list(); + + for(int anInd = 0; anInd < aSelAttr->size(); anInd++) { + std::shared_ptr aSelect = aSelAttr->value(anInd); + std::list::iterator aMirIter = aMirroredObjects.begin(); + for (; aMirIter != aMirroredObjects.end(); aMirIter++) + if (aSelect->context() == *aMirIter) + return false; + } + return true; +} + diff --git a/src/SketchPlugin/SketchPlugin_Validators.h b/src/SketchPlugin/SketchPlugin_Validators.h index 47df37061..e4f6d36d6 100644 --- a/src/SketchPlugin/SketchPlugin_Validators.h +++ b/src/SketchPlugin/SketchPlugin_Validators.h @@ -76,5 +76,21 @@ class SketchPlugin_EqualAttrValidator : public ModelAPI_AttributeValidator const std::list& theArguments) const; }; +/**\class SketchPlugin_MirrorAttrValidator + * \ingroup Validators + * \brief Validator for the mirror constraint input. + * + * It checks that attributes of the Mirror constraint are correct. + */ +class SketchPlugin_MirrorAttrValidator : public ModelAPI_AttributeValidator +{ + public: + //! returns true if attribute is valid + //! \param theAttribute the checked attribute + //! \param theArguments arguments of the attribute (not used) + virtual bool isValid(const AttributePtr& theAttribute, + const std::list& theArguments) const; +}; + #endif diff --git a/src/SketchPlugin/plugin-Sketch.xml b/src/SketchPlugin/plugin-Sketch.xml index 323120ce9..208f2e689 100644 --- a/src/SketchPlugin/plugin-Sketch.xml +++ b/src/SketchPlugin/plugin-Sketch.xml @@ -217,6 +217,7 @@ label="List of objects" tooltip="Select list of mirroring objects" type_choice="Edges"> + diff --git a/src/SketchSolver/SketchSolver_ConstraintCoincidence.cpp b/src/SketchSolver/SketchSolver_ConstraintCoincidence.cpp index 1172988cb..2ae6bf381 100644 --- a/src/SketchSolver/SketchSolver_ConstraintCoincidence.cpp +++ b/src/SketchSolver/SketchSolver_ConstraintCoincidence.cpp @@ -202,6 +202,6 @@ bool SketchSolver_ConstraintCoincidence::remove(ConstraintPtr theConstraint) } anExtraIt++; } - return isFullyRemoved; + return mySlvsConstraints.empty(); } diff --git a/src/SketchSolver/SketchSolver_Storage.cpp b/src/SketchSolver/SketchSolver_Storage.cpp index d4a517132..1690d7d56 100644 --- a/src/SketchSolver/SketchSolver_Storage.cpp +++ b/src/SketchSolver/SketchSolver_Storage.cpp @@ -151,13 +151,19 @@ bool SketchSolver_Storage::removeEntity(const Slvs_hEntity& theEntityID) if (anEntIter->distance == theEntityID) return false; } + std::set anEntAndSubs; + anEntAndSubs.insert(theEntityID); + for (int i = 0; i < 4; i++) + if (myEntities[aPos].point[i] != SLVS_E_UNKNOWN) + anEntAndSubs.insert(myEntities[aPos].point[i]); + std::vector::const_iterator aConstrIter = myConstraints.begin(); for (; aConstrIter != myConstraints.end(); aConstrIter++) { Slvs_hEntity anEntIDs[6] = {aConstrIter->ptA, aConstrIter->ptB, aConstrIter->entityA, aConstrIter->entityB, aConstrIter->entityC, aConstrIter->entityD}; for (int i = 0; i < 6; i++) - if (anEntIDs[i] == theEntityID) + if (anEntAndSubs.find(anEntIDs[i]) != anEntAndSubs.end()) return false; } // The entity is not used, remove it and its parameters -- 2.30.2