From 639498d118ab5d59d65a7759ff37ce90f7223297 Mon Sep 17 00:00:00 2001 From: vsv Date: Wed, 14 Oct 2015 15:43:04 +0300 Subject: [PATCH] Issue #789: Detach a coincidence from a line object --- src/PartSet/PartSet_MenuMgr.cpp | 64 ++++++++++++++++---------------- src/PartSet/PartSet_Tools.cpp | 15 +++++++- src/PartSet/PartSet_Tools.h | 6 +++ src/XGUI/XGUI_ObjectsBrowser.cpp | 2 + 4 files changed, 52 insertions(+), 35 deletions(-) diff --git a/src/PartSet/PartSet_MenuMgr.cpp b/src/PartSet/PartSet_MenuMgr.cpp index 65a2f98d7..b4f56d4a8 100644 --- a/src/PartSet/PartSet_MenuMgr.cpp +++ b/src/PartSet/PartSet_MenuMgr.cpp @@ -257,49 +257,47 @@ QColor PartSet_MenuMgr::setLineColor(int theId, const QColor theColor, bool theU } -void PartSet_MenuMgr::onLineDetach(QAction* theAction) +void addRefCoincidentFeatures(const std::set& theRefList, + std::shared_ptr& theRefPnt, + QObjectPtrList& theOutList) { - int aId = theAction->data().toInt(); - FeaturePtr aLine = myCoinsideLines.at(aId); - std::shared_ptr aOrig = PartSet_Tools::getPoint(mySelectedFeature, - SketchPlugin_ConstraintCoincidence::ENTITY_A()); - if (aOrig.get() == NULL) - aOrig = PartSet_Tools::getPoint(mySelectedFeature, - SketchPlugin_ConstraintCoincidence::ENTITY_B()); - - gp_Pnt aOr = aOrig->impl(); - const std::set& aRefsList = aLine->data()->refsToMe(); - - QObjectPtrList aToDelFeatures; std::set::const_iterator aIt; - // Find all coincedences corresponded to the selected line in the selected point - for (aIt = aRefsList.cbegin(); aIt != aRefsList.cend(); ++aIt) { + for (aIt = theRefList.cbegin(); aIt != theRefList.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 = PartSet_Tools::getPoint(aConstrFeature, - SketchPlugin_ConstraintCoincidence::ENTITY_A()); - if (aPnt.get() == NULL) - aPnt = PartSet_Tools::getPoint(aConstrFeature, - SketchPlugin_ConstraintCoincidence::ENTITY_B()); + std::shared_ptr aPnt = PartSet_Tools::getCoincedencePoint(aConstrFeature); if (aPnt.get() == NULL) return; gp_Pnt aP = aPnt->impl(); - if (aOrig->isEqual(aPnt)) { - aToDelFeatures.append(aConstrFeature); - } else { - aPnt = PartSet_Tools::getPoint(aConstrFeature, - SketchPlugin_ConstraintCoincidence::ENTITY_B()); - if (aPnt.get() == NULL) - return; - aP = aPnt->impl(); - if (aOrig->isEqual(aPnt)) { - aToDelFeatures.append(aConstrFeature); - break; - } - } + if (theRefPnt->isEqual(aPnt) && (!theOutList.contains(aConstrFeature))) { + theOutList.append(aConstrFeature); + } } } +} + +void PartSet_MenuMgr::onLineDetach(QAction* theAction) +{ + int aId = theAction->data().toInt(); + FeaturePtr aLine = myCoinsideLines.at(aId); + std::shared_ptr aOrig = PartSet_Tools::getCoincedencePoint(mySelectedFeature); + if (!aOrig.get()) + return; + + const std::set& aRefsList = aLine->data()->refsToMe(); + + QObjectPtrList aToDelFeatures; + + addRefCoincidentFeatures(aRefsList, aOrig, aToDelFeatures); + + const std::list& aResults = aLine->results(); + std::list::const_iterator aResIt; + for (aResIt = aResults.cbegin(); aResIt != aResults.cend(); aResIt++) { + ResultPtr aResult = (*aResIt); + const std::set& aRefList = aResult->data()->refsToMe(); + addRefCoincidentFeatures(aRefList, aOrig, aToDelFeatures); + } if (aToDelFeatures.size() > 0) { XGUI_ModuleConnector* aConnector = dynamic_cast(myModule->workshop()); XGUI_Workshop* aWorkshop = aConnector->workshop(); diff --git a/src/PartSet/PartSet_Tools.cpp b/src/PartSet/PartSet_Tools.cpp index 8a4c158f3..57df4e003 100755 --- a/src/PartSet/PartSet_Tools.cpp +++ b/src/PartSet/PartSet_Tools.cpp @@ -15,6 +15,8 @@ #include #include +#include + #include #include #include @@ -676,7 +678,7 @@ void PartSet_Tools::findCoincidences(FeaturePtr theStartCoin, QList& if (!aPnt) return; FeaturePtr aObj = ModelAPI_Feature::feature(aPnt->object()); if (!theList.contains(aObj)) { - std::shared_ptr aOrig = getPoint(theStartCoin, theAttr); + std::shared_ptr aOrig = getCoincedencePoint(theStartCoin); if (aOrig.get() == NULL) return; theList.append(aObj); @@ -686,7 +688,7 @@ void PartSet_Tools::findCoincidences(FeaturePtr theStartCoin, QList& 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); + 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()); @@ -696,6 +698,15 @@ void PartSet_Tools::findCoincidences(FeaturePtr theStartCoin, QList& } } +std::shared_ptr PartSet_Tools::getCoincedencePoint(FeaturePtr theStartCoin) +{ + std::shared_ptr aPnt = SketcherPrs_Tools::getPoint(theStartCoin.get(), + SketchPlugin_Constraint::ENTITY_A()); + if (aPnt.get() == NULL) + aPnt = SketcherPrs_Tools::getPoint(theStartCoin.get(), SketchPlugin_Constraint::ENTITY_B()); + return aPnt; +} + 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 f204d3df4..438135840 100755 --- a/src/PartSet/PartSet_Tools.h +++ b/src/PartSet/PartSet_Tools.h @@ -207,6 +207,12 @@ class PARTSET_EXPORT PartSet_Tools */ static void findCoincidences(FeaturePtr theStartCoin, QList& theList, std::string theAttr); + + /** + * Returns point of a coincedence + * \param theStartCoin the coincedence feature + */ + static std::shared_ptr getCoincedencePoint(FeaturePtr theStartCoin); }; #endif diff --git a/src/XGUI/XGUI_ObjectsBrowser.cpp b/src/XGUI/XGUI_ObjectsBrowser.cpp index 9eee72dce..74d04d931 100644 --- a/src/XGUI/XGUI_ObjectsBrowser.cpp +++ b/src/XGUI/XGUI_ObjectsBrowser.cpp @@ -176,6 +176,7 @@ XGUI_ObjectsBrowser::XGUI_ObjectsBrowser(QWidget* theParent) aLayout->setSpacing(0); QFrame* aLabelWgt = new QFrame(this); + //QWidget* aLabelWgt = new QWidget(this); aLabelWgt->setAutoFillBackground(true); QPalette aPalet = aLabelWgt->palette(); aPalet.setColor(QPalette::Window, Qt::white); @@ -210,6 +211,7 @@ XGUI_ObjectsBrowser::XGUI_ObjectsBrowser(QWidget* theParent) aLabelLay->setStretch(1, 1); myTreeView = new XGUI_DataTree(this); + //myTreeView->setFrameShape(QFrame::NoFrame); aLayout->addWidget(myTreeView); aLabelWgt->setFrameShape(myTreeView->frameShape()); -- 2.39.2