X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FPartSet%2FPartSet_MenuMgr.cpp;h=f39331b6270ec89594ad50fb38349e03c71d8cbc;hb=3205d0f18200948632155bbe7b640bc1e482243d;hp=65a2f98d7ed2ad4052e5a98e137559fe2221a204;hpb=e11ae05578690f15d9da81d97cf979b9c8f536f4;p=modules%2Fshaper.git diff --git a/src/PartSet/PartSet_MenuMgr.cpp b/src/PartSet/PartSet_MenuMgr.cpp index 65a2f98d7..f39331b62 100644 --- a/src/PartSet/PartSet_MenuMgr.cpp +++ b/src/PartSet/PartSet_MenuMgr.cpp @@ -29,7 +29,6 @@ #include #include #include -#include #include #include @@ -40,6 +39,7 @@ #include #include +#include #include #include @@ -150,28 +150,7 @@ bool PartSet_MenuMgr::addViewerMenu(QMenu* theMenu, const QMap& aRefsList = aFeature->data()->refsToMe(); - std::set::const_iterator aIt; - FeaturePtr aCoincident; - 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 a2dPnt = - PartSet_Tools::getPoint(aConstrFeature, SketchPlugin_ConstraintCoincidence::ENTITY_A()); - if (a2dPnt.get() && aSelPnt->isEqual(a2dPnt)) { - aCoincident = aConstrFeature; - break; - } else { - a2dPnt = PartSet_Tools::getPoint(aConstrFeature, - SketchPlugin_ConstraintCoincidence::ENTITY_B()); - if (a2dPnt.get() && aSelPnt->isEqual(a2dPnt)) { - aCoincident = aConstrFeature; - break; - } - } - } - } + FeaturePtr aCoincident = PartSet_Tools::findFirstCoincidence(aFeature, aSelPnt); // If we have coincidence then add Detach menu if (aCoincident.get() != NULL) { mySelectedFeature = aCoincident; @@ -257,49 +236,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(); @@ -470,6 +447,7 @@ void PartSet_MenuMgr::onActivatePart(bool) } if (aPart.get()) aPart->activate(); + myModule->workshop()->updateCommandStatus(); } } @@ -488,6 +466,8 @@ void PartSet_MenuMgr::activatePartSet() const if (isNewTransaction) aMgr->startOperation("Activation"); aMgr->setActiveDocument(aMgr->moduleDocument()); if (isNewTransaction) aMgr->finishOperation(); + + myModule->workshop()->updateCommandStatus(); } void PartSet_MenuMgr::grantedOperationIds(ModuleBase_Operation* theOperation, @@ -530,3 +510,13 @@ void PartSet_MenuMgr::onSelectParentFeature() aSelection.append( aParentFeature ); myModule->workshop()->selection()->setSelectedObjects( aSelection ); } + +bool PartSet_MenuMgr::eventFilter(QObject* theObj, QEvent* theEvent) +{ + if (theEvent->type() == QEvent::MouseButtonDblClick) { + SessionPtr aMgr = ModelAPI_Session::get(); + if (aMgr->activeDocument() != aMgr->moduleDocument()) + activatePartSet(); + } + return QObject::eventFilter(theObj, theEvent); +} \ No newline at end of file