From f81fd8333b11902d0794a8f83b1d880d5636c153 Mon Sep 17 00:00:00 2001 From: nds Date: Thu, 9 Jul 2015 14:23:17 +0300 Subject: [PATCH] Issue #741 fillet is wrong --- src/PartSet/PartSet_MenuMgr.cpp | 85 ++++---------------- src/PartSet/PartSet_Module.cpp | 2 + src/PartSet/PartSet_Tools.cpp | 52 ++++++++++++ src/PartSet/PartSet_Tools.h | 16 ++++ src/PartSet/PartSet_Validators.cpp | 64 +++++++++++++++ src/PartSet/PartSet_Validators.h | 15 ++++ src/SketchPlugin/SketchPlugin_Plugin.cpp | 2 - src/SketchPlugin/SketchPlugin_Validators.cpp | 61 -------------- src/SketchPlugin/SketchPlugin_Validators.h | 15 ---- src/SketchPlugin/plugin-Sketch.xml | 8 +- 10 files changed, 170 insertions(+), 150 deletions(-) diff --git a/src/PartSet/PartSet_MenuMgr.cpp b/src/PartSet/PartSet_MenuMgr.cpp index d676ce1ee..e09654f96 100644 --- a/src/PartSet/PartSet_MenuMgr.cpp +++ b/src/PartSet/PartSet_MenuMgr.cpp @@ -99,65 +99,6 @@ void PartSet_MenuMgr::onAction(bool isChecked) } } -/// Returns point of coincidence feature -/// \param theFeature the coincidence feature -/// \param theAttribute the attribute name -std::shared_ptr getPoint(std::shared_ptr& theFeature, - const std::string& theAttribute) -{ - std::shared_ptr aPointAttr; - - if (!theFeature->data()) - return std::shared_ptr(); - - FeaturePtr aFeature; - std::shared_ptr anAttr = std::dynamic_pointer_cast< - ModelAPI_AttributeRefAttr>(theFeature->data()->attribute(theAttribute)); - if (anAttr) - aFeature = ModelAPI_Feature::feature(anAttr->object()); - - if (aFeature && aFeature->getKind() == SketchPlugin_Point::ID()) - aPointAttr = std::dynamic_pointer_cast( - aFeature->data()->attribute(SketchPlugin_Point::COORD_ID())); - - else if (anAttr->attr()) { - aPointAttr = std::dynamic_pointer_cast(anAttr->attr()); - } - if (aPointAttr.get() != NULL) - return aPointAttr->pnt(); - return std::shared_ptr(); -} - -/// Returns list of features connected in a councedence feature point -/// \param theStartCoin the coincidence feature -/// \param theList a list which collects lines features -/// \param theAttr the attribute name -void findCoincidences(FeaturePtr theStartCoin, QList& theList, std::string theAttr) -{ - AttributeRefAttrPtr aPnt = theStartCoin->refattr(theAttr); - FeaturePtr aObj = ModelAPI_Feature::feature(aPnt->object()); - if (!theList.contains(aObj)) { - std::shared_ptr aOrig = getPoint(theStartCoin, theAttr); - if (aOrig.get() == NULL) - return; - theList.append(aObj); - const std::set& aRefsList = aObj->data()->refsToMe(); - std::set::const_iterator aIt; - for (aIt = aRefsList.cbegin(); aIt != aRefsList.cend(); ++aIt) { - std::shared_ptr aAttr = (*aIt); - FeaturePtr aConstrFeature = std::dynamic_pointer_cast(aAttr->owner()); - if (aConstrFeature->getKind() == SketchPlugin_ConstraintCoincidence::ID()) { - std::shared_ptr aPnt = getPoint(aConstrFeature, theAttr); - if (aPnt.get() && aOrig->isEqual(aPnt)) { - findCoincidences(aConstrFeature, theList, SketchPlugin_ConstraintCoincidence::ENTITY_A()); - findCoincidences(aConstrFeature, theList, SketchPlugin_ConstraintCoincidence::ENTITY_B()); - } - } - } - } -} - - bool PartSet_MenuMgr::addViewerMenu(QMenu* theMenu, const QMap& theStdActions) const { ModuleBase_Operation* anOperation = myModule->workshop()->currentOperation(); @@ -211,12 +152,13 @@ bool PartSet_MenuMgr::addViewerMenu(QMenu* theMenu, const QMap(aAttr->owner()); if (aConstrFeature->getKind() == SketchPlugin_ConstraintCoincidence::ID()) { std::shared_ptr a2dPnt = - getPoint(aConstrFeature, SketchPlugin_ConstraintCoincidence::ENTITY_A()); + PartSet_Tools::getPoint(aConstrFeature, SketchPlugin_ConstraintCoincidence::ENTITY_A()); if (a2dPnt.get() && aSelPnt->isEqual(a2dPnt)) { aCoincident = aConstrFeature; break; } else { - a2dPnt = getPoint(aConstrFeature, SketchPlugin_ConstraintCoincidence::ENTITY_B()); + a2dPnt = PartSet_Tools::getPoint(aConstrFeature, + SketchPlugin_ConstraintCoincidence::ENTITY_B()); if (a2dPnt.get() && aSelPnt->isEqual(a2dPnt)) { aCoincident = aConstrFeature; break; @@ -227,8 +169,10 @@ bool PartSet_MenuMgr::addViewerMenu(QMenu* theMenu, const QMap 0) { aIsDetach = true; QMenu* aSubMenu = theMenu->addMenu(tr("Detach")); @@ -294,9 +238,11 @@ void PartSet_MenuMgr::onLineDetach(QAction* theAction) { int aId = theAction->data().toInt(); FeaturePtr aLine = myCoinsideLines.at(aId); - std::shared_ptr aOrig = getPoint(mySelectedFeature, SketchPlugin_ConstraintCoincidence::ENTITY_A()); + std::shared_ptr aOrig = PartSet_Tools::getPoint(mySelectedFeature, + SketchPlugin_ConstraintCoincidence::ENTITY_A()); if (aOrig.get() == NULL) - aOrig = getPoint(mySelectedFeature, SketchPlugin_ConstraintCoincidence::ENTITY_B()); + aOrig = PartSet_Tools::getPoint(mySelectedFeature, + SketchPlugin_ConstraintCoincidence::ENTITY_B()); gp_Pnt aOr = aOrig->impl(); const std::set& aRefsList = aLine->data()->refsToMe(); @@ -308,16 +254,19 @@ void PartSet_MenuMgr::onLineDetach(QAction* theAction) std::shared_ptr aAttr = (*aIt); FeaturePtr aConstrFeature = std::dynamic_pointer_cast(aAttr->owner()); if (aConstrFeature->getKind() == SketchPlugin_ConstraintCoincidence::ID()) { - std::shared_ptr aPnt = getPoint(aConstrFeature, SketchPlugin_ConstraintCoincidence::ENTITY_A()); + std::shared_ptr aPnt = PartSet_Tools::getPoint(aConstrFeature, + SketchPlugin_ConstraintCoincidence::ENTITY_A()); if (aPnt.get() == NULL) - aPnt = getPoint(aConstrFeature, SketchPlugin_ConstraintCoincidence::ENTITY_B()); + aPnt = PartSet_Tools::getPoint(aConstrFeature, + SketchPlugin_ConstraintCoincidence::ENTITY_B()); if (aPnt.get() == NULL) return; gp_Pnt aP = aPnt->impl(); if (aOrig->isEqual(aPnt)) { aToDelFeatures.append(aConstrFeature); } else { - aPnt = getPoint(aConstrFeature, SketchPlugin_ConstraintCoincidence::ENTITY_B()); + aPnt = PartSet_Tools::getPoint(aConstrFeature, + SketchPlugin_ConstraintCoincidence::ENTITY_B()); aP = aPnt->impl(); if (aOrig->isEqual(aPnt)) { aToDelFeatures.append(aConstrFeature); diff --git a/src/PartSet/PartSet_Module.cpp b/src/PartSet/PartSet_Module.cpp index 0ea84ee28..9559e6bb5 100644 --- a/src/PartSet/PartSet_Module.cpp +++ b/src/PartSet/PartSet_Module.cpp @@ -194,6 +194,8 @@ void PartSet_Module::registerValidators() aFactory->registerValidator("PartSet_DifferentObjects", new PartSet_DifferentObjectsValidator); aFactory->registerValidator("PartSet_DifferentShapes", new ModelAPI_ShapeValidator); + aFactory->registerValidator("PartSet_CoincidentAttr", new PartSet_CoincidentAttr); + aFactory->registerValidator("GeomValidators_ShapeType", new GeomValidators_ShapeType); aFactory->registerValidator("GeomValidators_Face", new GeomValidators_Face); diff --git a/src/PartSet/PartSet_Tools.cpp b/src/PartSet/PartSet_Tools.cpp index 843bda304..33e7601a8 100644 --- a/src/PartSet/PartSet_Tools.cpp +++ b/src/PartSet/PartSet_Tools.cpp @@ -701,6 +701,58 @@ GeomShapePtr PartSet_Tools::findShapeBy2DPoint(const AttributePtr& theAttribute, return aShape; } +std::shared_ptr PartSet_Tools::getPoint(std::shared_ptr& theFeature, + const std::string& theAttribute) +{ + std::shared_ptr aPointAttr; + + if (!theFeature->data()) + return std::shared_ptr(); + + FeaturePtr aFeature; + std::shared_ptr anAttr = std::dynamic_pointer_cast< + ModelAPI_AttributeRefAttr>(theFeature->data()->attribute(theAttribute)); + if (anAttr) + aFeature = ModelAPI_Feature::feature(anAttr->object()); + + if (aFeature && aFeature->getKind() == SketchPlugin_Point::ID()) + aPointAttr = std::dynamic_pointer_cast( + aFeature->data()->attribute(SketchPlugin_Point::COORD_ID())); + + else if (anAttr->attr()) { + aPointAttr = std::dynamic_pointer_cast(anAttr->attr()); + } + if (aPointAttr.get() != NULL) + return aPointAttr->pnt(); + return std::shared_ptr(); +} + +void PartSet_Tools::findCoincidences(FeaturePtr theStartCoin, QList& theList, + std::string theAttr) +{ + AttributeRefAttrPtr aPnt = theStartCoin->refattr(theAttr); + FeaturePtr aObj = ModelAPI_Feature::feature(aPnt->object()); + if (!theList.contains(aObj)) { + std::shared_ptr aOrig = getPoint(theStartCoin, theAttr); + if (aOrig.get() == NULL) + return; + theList.append(aObj); + const std::set& aRefsList = aObj->data()->refsToMe(); + std::set::const_iterator aIt; + for (aIt = aRefsList.cbegin(); aIt != aRefsList.cend(); ++aIt) { + std::shared_ptr aAttr = (*aIt); + FeaturePtr aConstrFeature = std::dynamic_pointer_cast(aAttr->owner()); + if (aConstrFeature->getKind() == SketchPlugin_ConstraintCoincidence::ID()) { + std::shared_ptr aPnt = getPoint(aConstrFeature, theAttr); + if (aPnt.get() && aOrig->isEqual(aPnt)) { + findCoincidences(aConstrFeature, theList, SketchPlugin_ConstraintCoincidence::ENTITY_A()); + findCoincidences(aConstrFeature, theList, SketchPlugin_ConstraintCoincidence::ENTITY_B()); + } + } + } + } +} + AttributePtr PartSet_Tools::findAttributeBy2dPoint(ObjectPtr theObj, const TopoDS_Shape theShape, FeaturePtr theSketch) diff --git a/src/PartSet/PartSet_Tools.h b/src/PartSet/PartSet_Tools.h index 54c8b8978..c113b832a 100644 --- a/src/PartSet/PartSet_Tools.h +++ b/src/PartSet/PartSet_Tools.h @@ -217,6 +217,22 @@ class PARTSET_EXPORT PartSet_Tools static GeomShapePtr findShapeBy2DPoint(const AttributePtr& theAttribute, ModuleBase_IWorkshop* theWorkshop); + /* Returns point of coincidence feature + * \param theFeature the coincidence feature + * \param theAttribute the attribute name + */ + static std::shared_ptr getPoint(std::shared_ptr& theFeature, + const std::string& theAttribute); + + /** + * Returns list of features connected in a councedence feature point + * \param theStartCoin the coincidence feature + * \param theList a list which collects lines features + * \param theAttr the attribute name + */ + static void findCoincidences(FeaturePtr theStartCoin, QList& theList, + std::string theAttr); + protected: /// Returns an object that is under the mouse point. Firstly it checks the highlighting, /// if it exists, the first object is returned. Secondly, there is an iteration on diff --git a/src/PartSet/PartSet_Validators.cpp b/src/PartSet/PartSet_Validators.cpp index 1e0f79b2f..36606361e 100644 --- a/src/PartSet/PartSet_Validators.cpp +++ b/src/PartSet/PartSet_Validators.cpp @@ -6,6 +6,8 @@ #include "PartSet_Validators.h" +#include "PartSet_Tools.h" + #include #include #include @@ -23,6 +25,8 @@ #include #include +#include +#include #include #include @@ -395,3 +399,63 @@ bool PartSet_SameTypeAttrValidator::isValid( return false; } +bool PartSet_CoincidentAttr::isValid( + const AttributePtr& theAttribute, const std::list& theArguments ) const +{ + // there is a check whether the feature contains a point and a linear edge or two point values + std::string aParamA = theArguments.front(); + SessionPtr aMgr = ModelAPI_Session::get(); + ModelAPI_ValidatorsFactory* aFactory = aMgr->validators(); + + FeaturePtr aFeature = std::dynamic_pointer_cast(theAttribute->owner()); + AttributeRefAttrPtr aRefAttr = std::dynamic_pointer_cast(theAttribute); + if (!aRefAttr) + return false; + + QList aCoinsideLines; + + bool isObject = aRefAttr->isObject(); + ObjectPtr anObject = aRefAttr->object(); + if (isObject && anObject) { + FeaturePtr aRefFea = ModelAPI_Feature::feature(anObject); + AttributeRefAttrPtr aOtherAttr = aFeature->data()->refattr(aParamA); + ObjectPtr aOtherObject = aOtherAttr->object(); + // if the other attribute is not filled still, the result is true + if (!aOtherObject.get()) + return true; + FeaturePtr aOtherFea = ModelAPI_Feature::feature(aOtherObject); + + // check that both have coincidence + FeaturePtr aConstrFeature; + std::set aCoinList; + const std::set>& aRefsList = aRefFea->data()->refsToMe(); + std::set>::const_iterator aIt; + for (aIt = aRefsList.cbegin(); aIt != aRefsList.cend(); ++aIt) { + std::shared_ptr aAttr = (*aIt); + aConstrFeature = std::dynamic_pointer_cast(aAttr->owner()); + if (aConstrFeature->getKind() == SketchPlugin_ConstraintCoincidence::ID()) { + AttributeRefAttrPtr aRAttr = std::dynamic_pointer_cast(aAttr); + AttributePtr aAR = aRAttr->attr(); + if (aAR->id() != SketchPlugin_Arc::CENTER_ID()) // ignore constraint to center of arc + aCoinList.insert(aConstrFeature); + PartSet_Tools::findCoincidences(aConstrFeature, aCoinsideLines, + SketchPlugin_ConstraintCoincidence::ENTITY_A()); + PartSet_Tools::findCoincidences(aConstrFeature, aCoinsideLines, + SketchPlugin_ConstraintCoincidence::ENTITY_B()); + } + } + // if there is no coincidence then it is not valid + if (aCoinList.size() == 0) + return false; + + QList::const_iterator anIt = aCoinsideLines.begin(), aLast = aCoinsideLines.end(); + bool aValid = false; + for (; anIt != aLast && !aValid; anIt++) { + aValid = *anIt == aOtherFea; + } + if (aValid) + return true; + } + return false; +} + diff --git a/src/PartSet/PartSet_Validators.h b/src/PartSet/PartSet_Validators.h index 92eb3a71d..38d693db9 100644 --- a/src/PartSet/PartSet_Validators.h +++ b/src/PartSet/PartSet_Validators.h @@ -151,5 +151,20 @@ class PartSet_SameTypeAttrValidator : public ModelAPI_AttributeValidator const std::list& theArguments) const; }; +/**\class PartSet_CoincidentAttr + * \ingroup Validators + * \brief Validator to check whether there is a coincident constraint between + * the attribute and attribute of argument. + */ +class PartSet_CoincidentAttr : public ModelAPI_AttributeValidator +{ + public: + //! returns true if attribute is valid + //! \param theAttribute the checked attribute + //! \param theArguments arguments of the attribute + virtual bool isValid(const AttributePtr& theAttribute, + const std::list& theArguments) const; +}; + #endif diff --git a/src/SketchPlugin/SketchPlugin_Plugin.cpp b/src/SketchPlugin/SketchPlugin_Plugin.cpp index 4e29b3bfc..7742fa5c1 100644 --- a/src/SketchPlugin/SketchPlugin_Plugin.cpp +++ b/src/SketchPlugin/SketchPlugin_Plugin.cpp @@ -57,8 +57,6 @@ SketchPlugin_Plugin::SketchPlugin_Plugin() new SketchPlugin_ExternalValidator); aFactory->registerValidator("SketchPlugin_TangentAttr", new SketchPlugin_TangentAttrValidator); - aFactory->registerValidator("SketchPlugin_CoincidentAttr", - new SketchPlugin_CoincidentAttr); aFactory->registerValidator("SketchPlugin_NotFixed", new SketchPlugin_NotFixedValidator); aFactory->registerValidator("SketchPlugin_EqualAttr", diff --git a/src/SketchPlugin/SketchPlugin_Validators.cpp b/src/SketchPlugin/SketchPlugin_Validators.cpp index 40cfd995d..2af4de2e1 100644 --- a/src/SketchPlugin/SketchPlugin_Validators.cpp +++ b/src/SketchPlugin/SketchPlugin_Validators.cpp @@ -78,67 +78,6 @@ bool SketchPlugin_DistanceAttrValidator::isValid( return false; } -bool SketchPlugin_CoincidentAttr::isValid( - const AttributePtr& theAttribute, const std::list& theArguments ) const -{ - // there is a check whether the feature contains a point and a linear edge or two point values - std::string aParamA = theArguments.front(); - SessionPtr aMgr = ModelAPI_Session::get(); - ModelAPI_ValidatorsFactory* aFactory = aMgr->validators(); - - FeaturePtr aFeature = std::dynamic_pointer_cast(theAttribute->owner()); - AttributeRefAttrPtr aRefAttr = std::dynamic_pointer_cast(theAttribute); - if (!aRefAttr) - return false; - - bool isObject = aRefAttr->isObject(); - ObjectPtr anObject = aRefAttr->object(); - if (isObject && anObject) { - FeaturePtr aRefFea = ModelAPI_Feature::feature(anObject); - AttributeRefAttrPtr aOtherAttr = aFeature->data()->refattr(aParamA); - ObjectPtr aOtherObject = aOtherAttr->object(); - // if the other attribute is not filled still, the result is true - if (!aOtherObject.get()) - return true; - FeaturePtr aOtherFea = ModelAPI_Feature::feature(aOtherObject); - - // check that both have coincidence - FeaturePtr aConstrFeature; - std::set aCoinList; - const std::set>& aRefsList = aRefFea->data()->refsToMe(); - std::set>::const_iterator aIt; - for (aIt = aRefsList.cbegin(); aIt != aRefsList.cend(); ++aIt) { - std::shared_ptr aAttr = (*aIt); - aConstrFeature = std::dynamic_pointer_cast(aAttr->owner()); - if (aConstrFeature->getKind() == SketchPlugin_ConstraintCoincidence::ID()) { - AttributeRefAttrPtr aRAttr = std::dynamic_pointer_cast(aAttr); - AttributePtr aAR = aRAttr->attr(); - if (aAR->id() != SketchPlugin_Arc::CENTER_ID()) // ignore constraint to center of arc - aCoinList.insert(aConstrFeature); - } - } - // if there is no coincidence then it is not valid - if (aCoinList.size() == 0) - return false; - - // find that coincedence is the same - const std::set>& aOtherList = aOtherFea->data()->refsToMe(); - std::set::const_iterator aCoinsIt; - for (aIt = aOtherList.cbegin(); aIt != aOtherList.cend(); ++aIt) { - std::shared_ptr aAttr = (*aIt); - aConstrFeature = std::dynamic_pointer_cast(aAttr->owner()); - aCoinsIt = aCoinList.find(aConstrFeature); - if (aCoinsIt != aCoinList.end()) { - AttributeRefAttrPtr aRAttr = std::dynamic_pointer_cast(aAttr); - AttributePtr aAR = aRAttr->attr(); - if (aAR->id() != SketchPlugin_Arc::CENTER_ID()) - return true; - } - } - } - return false; -} - bool SketchPlugin_TangentAttrValidator::isValid( const AttributePtr& theAttribute, const std::list& theArguments ) const { diff --git a/src/SketchPlugin/SketchPlugin_Validators.h b/src/SketchPlugin/SketchPlugin_Validators.h index 6b1f29c0a..24d79c1b4 100644 --- a/src/SketchPlugin/SketchPlugin_Validators.h +++ b/src/SketchPlugin/SketchPlugin_Validators.h @@ -26,21 +26,6 @@ class SketchPlugin_DistanceAttrValidator : public ModelAPI_AttributeValidator const std::list& theArguments) const; }; -/**\class SketchPlugin_CoincidentAttr - * \ingroup Validators - * \brief Validator to check whether there is a coincident constraint between - * the attribute and attribute of argument. - */ -class SketchPlugin_CoincidentAttr : public ModelAPI_AttributeValidator -{ - public: - //! returns true if attribute is valid - //! \param theAttribute the checked attribute - //! \param theArguments arguments of the attribute - virtual bool isValid(const AttributePtr& theAttribute, - const std::list& theArguments) const; -}; - /**\class SketchPlugin_TangentAttrValidator * \ingroup Validators * \brief Validator for the tangent constraint input. diff --git a/src/SketchPlugin/plugin-Sketch.xml b/src/SketchPlugin/plugin-Sketch.xml index 626ec3089..ed807cd23 100644 --- a/src/SketchPlugin/plugin-Sketch.xml +++ b/src/SketchPlugin/plugin-Sketch.xml @@ -207,13 +207,13 @@ - + - + @@ -229,13 +229,13 @@ - + - + -- 2.39.2