From 812073961e85e752c543f871b7f47c979bf1427c Mon Sep 17 00:00:00 2001 From: vsv Date: Mon, 4 Apr 2016 16:00:22 +0300 Subject: [PATCH] Issue #1389: process results on coincidences object finding --- src/PartSet/PartSet_MenuMgr.cpp | 5 +- src/PartSet/PartSet_Tools.cpp | 94 ++++++++++++++++++--------- src/PartSet/PartSet_Tools.h | 4 +- src/PartSet/PartSet_Validators.cpp | 5 +- src/PartSet/PartSet_WidgetPoint2d.cpp | 11 ++-- src/PartSet/PartSet_WidgetPoint2d.h | 2 +- 6 files changed, 80 insertions(+), 41 deletions(-) diff --git a/src/PartSet/PartSet_MenuMgr.cpp b/src/PartSet/PartSet_MenuMgr.cpp index e353cb8a4..a18ac9a53 100644 --- a/src/PartSet/PartSet_MenuMgr.cpp +++ b/src/PartSet/PartSet_MenuMgr.cpp @@ -153,10 +153,11 @@ bool PartSet_MenuMgr::addViewerMenu(QMenu* theMenu, const QMap aCoins; mySelectedFeature = aCoincident; - PartSet_Tools::findCoincidences(mySelectedFeature, myCoinsideLines, + PartSet_Tools::findCoincidences(mySelectedFeature, myCoinsideLines, aCoins, SketchPlugin_ConstraintCoincidence::ENTITY_A()); - PartSet_Tools::findCoincidences(mySelectedFeature, myCoinsideLines, + PartSet_Tools::findCoincidences(mySelectedFeature, myCoinsideLines, aCoins, SketchPlugin_ConstraintCoincidence::ENTITY_B()); if (myCoinsideLines.size() > 0) { aIsDetach = true; diff --git a/src/PartSet/PartSet_Tools.cpp b/src/PartSet/PartSet_Tools.cpp index 27921bf5e..7edba2413 100755 --- a/src/PartSet/PartSet_Tools.cpp +++ b/src/PartSet/PartSet_Tools.cpp @@ -776,8 +776,7 @@ FeaturePtr findFirstCoincidenceByData(const DataPtr& theData, std::shared_ptr thePoint, - const bool theSearchInResults) + std::shared_ptr thePoint) { FeaturePtr aCoincident; if (theFeature.get() == NULL) @@ -804,42 +803,79 @@ FeaturePtr PartSet_Tools::findFirstCoincidence(const FeaturePtr& theFeature, } } } - if (theSearchInResults) { - if (!aCoincident.get()) { - std::list aResults = theFeature->results(); - std::list::const_iterator aIt; - for (aIt = aResults.cbegin(); aIt != aResults.cend(); ++aIt) { - ResultPtr aResult = *aIt; - aCoincident = findFirstCoincidenceByData(aResult->data(), thePoint); - if (aCoincident.get()) - break; - } + /// Find by result + if (!aCoincident.get()) { + std::list aResults = theFeature->results(); + std::list::const_iterator aIt; + for (aIt = aResults.cbegin(); aIt != aResults.cend(); ++aIt) { + ResultPtr aResult = *aIt; + aCoincident = findFirstCoincidenceByData(aResult->data(), thePoint); + if (aCoincident.get()) + break; } } return aCoincident; } void PartSet_Tools::findCoincidences(FeaturePtr theStartCoin, QList& theList, + QList& theCoincidencies, std::string theAttr) { + std::shared_ptr aOrig = getCoincedencePoint(theStartCoin); + if (aOrig.get() == NULL) + return; + AttributeRefAttrPtr aPnt = theStartCoin->refattr(theAttr); - if (!aPnt) return; - FeaturePtr aObj = ModelAPI_Feature::feature(aPnt->object()); - if (!theList.contains(aObj)) { - std::shared_ptr aOrig = getCoincedencePoint(theStartCoin); - 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 = getCoincedencePoint(aConstrFeature); - if (aPnt.get() && aOrig->isEqual(aPnt)) { - findCoincidences(aConstrFeature, theList, SketchPlugin_ConstraintCoincidence::ENTITY_A()); - findCoincidences(aConstrFeature, theList, SketchPlugin_ConstraintCoincidence::ENTITY_B()); + if (!aPnt) + return; + ObjectPtr aObj = aPnt->object(); + FeaturePtr aFeature = std::dynamic_pointer_cast(aObj); + if (aFeature.get()) { + if (!theList.contains(aFeature)) { + theList.append(aFeature); + theCoincidencies.append(theStartCoin); + const std::set& aRefsList = aFeature->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()) { + if (!theCoincidencies.contains(aConstrFeature)) { + std::shared_ptr aPnt = getCoincedencePoint(aConstrFeature); + if (aPnt.get() && aOrig->isEqual(aPnt)) { + findCoincidences(aConstrFeature, theList, theCoincidencies, + SketchPlugin_ConstraintCoincidence::ENTITY_A()); + findCoincidences(aConstrFeature, theList, theCoincidencies, + SketchPlugin_ConstraintCoincidence::ENTITY_B()); + } + } + } + } + } + } else { + // Find by Results + ResultConstructionPtr aResult = std::dynamic_pointer_cast(aObj); + if (aResult.get()) { + FeaturePtr aFeature = ModelAPI_Feature::feature(aPnt->object()); + if (!theList.contains(aFeature)) + theList.append(aFeature); + theCoincidencies.append(theStartCoin); + + const std::set& aRefsList = aResult->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()) { + if (!theCoincidencies.contains(aConstrFeature)) { + std::shared_ptr aPnt = getCoincedencePoint(aConstrFeature); + if (aPnt.get() && aOrig->isEqual(aPnt)) { + findCoincidences(aConstrFeature, theList, theCoincidencies, + SketchPlugin_ConstraintCoincidence::ENTITY_A()); + findCoincidences(aConstrFeature, theList, theCoincidencies, + SketchPlugin_ConstraintCoincidence::ENTITY_B()); + } + } } } } diff --git a/src/PartSet/PartSet_Tools.h b/src/PartSet/PartSet_Tools.h index e4b034f3c..8db945e80 100755 --- a/src/PartSet/PartSet_Tools.h +++ b/src/PartSet/PartSet_Tools.h @@ -235,8 +235,7 @@ public: * \return the coincidence feature or null */ static FeaturePtr findFirstCoincidence(const FeaturePtr& theFeature, - std::shared_ptr thePoint, - const bool theSearchInResults = false); + std::shared_ptr thePoint); /** * Returns list of features connected in a councedence feature point @@ -245,6 +244,7 @@ public: * \param theAttr the attribute name */ static void findCoincidences(FeaturePtr theStartCoin, QList& theList, + QList& theCoincidencies, std::string theAttr); /** diff --git a/src/PartSet/PartSet_Validators.cpp b/src/PartSet/PartSet_Validators.cpp index 163063bd0..7cb22655f 100755 --- a/src/PartSet/PartSet_Validators.cpp +++ b/src/PartSet/PartSet_Validators.cpp @@ -638,6 +638,7 @@ bool PartSet_CoincidentAttr::isValid(const AttributePtr& theAttribute, FeaturePtr aFeature = std::dynamic_pointer_cast(theAttribute->owner()); AttributeRefAttrPtr aRefAttr = std::dynamic_pointer_cast(theAttribute); QList aCoinsideLines; + QList aCoins; bool isObject = aRefAttr->isObject(); ObjectPtr anObject = aRefAttr->object(); @@ -663,9 +664,9 @@ bool PartSet_CoincidentAttr::isValid(const AttributePtr& theAttribute, 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, + PartSet_Tools::findCoincidences(aConstrFeature, aCoinsideLines, aCoins, SketchPlugin_ConstraintCoincidence::ENTITY_A()); - PartSet_Tools::findCoincidences(aConstrFeature, aCoinsideLines, + PartSet_Tools::findCoincidences(aConstrFeature, aCoinsideLines, aCoins, SketchPlugin_ConstraintCoincidence::ENTITY_B()); } } diff --git a/src/PartSet/PartSet_WidgetPoint2d.cpp b/src/PartSet/PartSet_WidgetPoint2d.cpp index 82f7683c2..8543f3143 100644 --- a/src/PartSet/PartSet_WidgetPoint2d.cpp +++ b/src/PartSet/PartSet_WidgetPoint2d.cpp @@ -470,7 +470,7 @@ void PartSet_WidgetPoint2D::onMouseRelease(ModuleBase_IViewWindow* theWnd, QMous if (aShape.ShapeType() == TopAbs_VERTEX) { FeaturePtr aFixedFeature = ModelAPI_Feature::feature(aFixedObject); if (aFixedFeature.get() && aFixedFeature->getKind() == SketchPlugin_Point::ID()) { - anOrphanPoint = isOrphanPoint(aFixedFeature, mySketch, aX, aY, true); + anOrphanPoint = isOrphanPoint(aFixedFeature, mySketch, aX, aY); } } } @@ -650,7 +650,7 @@ bool PartSet_WidgetPoint2D::useSelectedShapes() const bool PartSet_WidgetPoint2D::isOrphanPoint(const FeaturePtr& theFeature, const CompositeFeaturePtr& theSketch, - double theX, double theY, const bool theSearchInResults) + double theX, double theY) { bool anOrphanPoint = false; if (theFeature.get()) { @@ -681,14 +681,15 @@ bool PartSet_WidgetPoint2D::isOrphanPoint(const FeaturePtr& theFeature, std::shared_ptr aPoint = aPointAttr->pnt(); // we need to find coincidence features in results also, because external object(point) // uses refs to me in another feature. - FeaturePtr aCoincidence = PartSet_Tools::findFirstCoincidence(theFeature, aPoint, theSearchInResults); + FeaturePtr aCoincidence = PartSet_Tools::findFirstCoincidence(theFeature, aPoint); anOrphanPoint = true; // if there is at least one concident line to the point, the point is not an orphant if (aCoincidence.get()) { QList aCoinsideLines; - PartSet_Tools::findCoincidences(aCoincidence, aCoinsideLines, + QList aCoins; + PartSet_Tools::findCoincidences(aCoincidence, aCoinsideLines, aCoins, SketchPlugin_ConstraintCoincidence::ENTITY_A()); - PartSet_Tools::findCoincidences(aCoincidence, aCoinsideLines, + PartSet_Tools::findCoincidences(aCoincidence, aCoinsideLines, aCoins, SketchPlugin_ConstraintCoincidence::ENTITY_B()); QList::const_iterator anIt = aCoinsideLines.begin(), aLast = aCoinsideLines.end(); diff --git a/src/PartSet/PartSet_WidgetPoint2d.h b/src/PartSet/PartSet_WidgetPoint2d.h index e179720d3..711e37c1c 100755 --- a/src/PartSet/PartSet_WidgetPoint2d.h +++ b/src/PartSet/PartSet_WidgetPoint2d.h @@ -175,7 +175,7 @@ protected: /// \param theY an Y coordinate of the point /// \return boolean result static bool isOrphanPoint(const FeaturePtr& theFeature, const CompositeFeaturePtr& theSketch, - double theX, double theY, const bool theSearchInResults = false); + double theX, double theY); protected: ModuleBase_IWorkshop* myWorkshop; ///< workshop -- 2.39.2