From be55e12a76d294827fe32eb22d008b561d982bb5 Mon Sep 17 00:00:00 2001 From: vsv Date: Mon, 13 Apr 2015 16:00:35 +0300 Subject: [PATCH] Issue #442: Avoid extra menus in pop-up of sketcher objects --- src/PartSet/PartSet_MenuMgr.cpp | 42 ++++++++++++++++++++++------- src/PartSet/PartSet_SketcherMgr.cpp | 12 ++++----- src/PartSet/PartSet_SketcherMgr.h | 2 +- 3 files changed, 38 insertions(+), 18 deletions(-) diff --git a/src/PartSet/PartSet_MenuMgr.cpp b/src/PartSet/PartSet_MenuMgr.cpp index da3bd6836..fa4426281 100644 --- a/src/PartSet/PartSet_MenuMgr.cpp +++ b/src/PartSet/PartSet_MenuMgr.cpp @@ -154,6 +154,28 @@ bool PartSet_MenuMgr::addViewerItems(QMenu* theMenu, const QMapselectedShapes(aShapeList, aObjectsList); bool aIsDetach = false; + // Check that selected shape is not attribute + // if at least a one shape is attribute then we can not add auxiliary item + bool hasAttribute = false; + if (aShapeList.Extent() > 0) { + NCollection_List::Iterator aIt(aShapeList); + std::list::const_iterator aItObj; + TopoDS_Shape aShape; + ObjectPtr aObj; + ResultPtr aResult; + for (aItObj = aObjectsList.cbegin(); aIt.More(); aIt.Next(), aItObj++) { + aShape = aIt.Value(); + aObj = (*aItObj); + aResult = std::dynamic_pointer_cast(aObj); + if (aResult.get() != NULL) { + if (!aShape.IsEqual(aResult->shape()->impl())) { + hasAttribute = true; + break; + } + } + } + } + if (aShapeList.Extent() == 1) { TopoDS_Shape aShape = aShapeList.First(); if (aShape.ShapeType() == TopAbs_VERTEX) { @@ -204,21 +226,21 @@ bool PartSet_MenuMgr::addViewerItems(QMenu* theMenu, const QMap 0)) { + QObjectPtrList aObjects = aSelection->selectedPresentations(); + if ((!aIsDetach) && (aObjects.size() > 0)) { bool hasFeature = false; FeaturePtr aFeature; - std::list::const_iterator aIt; - ObjectPtr aObject; - for (aIt = aObjectsList.cbegin(); aIt != aObjectsList.cend(); ++aIt) { - aObject = (*aIt); + foreach (ObjectPtr aObject, aObjects) { aFeature = ModelAPI_Feature::feature(aObject); if (aFeature.get() != NULL) { hasFeature = true; } } - if (hasFeature) + if (hasFeature && (!hasAttribute)) theMenu->addAction(theStdActions["DELETE_CMD"]); } + if (hasAttribute) + return true; bool isAuxiliary; if (canSetAuxiliary(isAuxiliary)) { QAction* anAction = action("AUXILIARY_CMD"); @@ -330,7 +352,7 @@ void PartSet_MenuMgr::setAuxiliary(const bool isChecked) bool isUseTransaction = false; // 1. change auxiliary type of a created feature if (PartSet_SketcherMgr::isNestedCreateOperation(anOperation) && - PartSet_SketcherMgr::isEntityOperation(anOperation) ) { + PartSet_SketcherMgr::isEntity(anOperation->id().toStdString()) ) { anObjects.append(anOperation->feature()); } else { @@ -387,7 +409,7 @@ bool PartSet_MenuMgr::canSetAuxiliary(bool& theValue) const QObjectPtrList anObjects; // 1. change auxiliary type of a created feature if (PartSet_SketcherMgr::isNestedCreateOperation(anOperation) && - PartSet_SketcherMgr::isEntityOperation(anOperation) ) { + PartSet_SketcherMgr::isEntity(anOperation->id().toStdString()) ) { anObjects.append(anOperation->feature()); } else { @@ -399,14 +421,14 @@ bool PartSet_MenuMgr::canSetAuxiliary(bool& theValue) const ModuleBase_ISelection* aSelection = myModule->workshop()->selection(); anObjects = aSelection->selectedPresentations(); } - anEnabled = anObjects.size() > 0; bool isNotAuxiliaryFound = false; if (anObjects.size() > 0) { QObjectPtrList::const_iterator anIt = anObjects.begin(), aLast = anObjects.end(); for (; anIt != aLast && !isNotAuxiliaryFound; anIt++) { FeaturePtr aFeature = ModelAPI_Feature::feature(*anIt); - if (aFeature.get() != NULL) { + if ((aFeature.get() != NULL) && PartSet_SketcherMgr::isEntity(aFeature->getKind())) { + anEnabled = true; std::shared_ptr aSketchFeature = std::dynamic_pointer_cast(aFeature); if (aSketchFeature.get() != NULL) { diff --git a/src/PartSet/PartSet_SketcherMgr.cpp b/src/PartSet/PartSet_SketcherMgr.cpp index 207aee541..9c1c1be0b 100644 --- a/src/PartSet/PartSet_SketcherMgr.cpp +++ b/src/PartSet/PartSet_SketcherMgr.cpp @@ -640,14 +640,12 @@ bool PartSet_SketcherMgr::isNestedCreateOperation(ModuleBase_Operation* theOpera return theOperation && !theOperation->isEditOperation() && isNestedSketchOperation(theOperation); } -bool PartSet_SketcherMgr::isEntityOperation(ModuleBase_Operation* theOperation) +bool PartSet_SketcherMgr::isEntity(const std::string& theId) { - std::string aId = theOperation ? theOperation->id().toStdString() : ""; - - return (aId == SketchPlugin_Line::ID()) || - (aId == SketchPlugin_Point::ID()) || - (aId == SketchPlugin_Arc::ID()) || - (aId == SketchPlugin_Circle::ID()); + return (theId == SketchPlugin_Line::ID()) || + (theId == SketchPlugin_Point::ID()) || + (theId == SketchPlugin_Arc::ID()) || + (theId == SketchPlugin_Circle::ID()); } bool PartSet_SketcherMgr::isDistanceOperation(ModuleBase_Operation* theOperation) diff --git a/src/PartSet/PartSet_SketcherMgr.h b/src/PartSet/PartSet_SketcherMgr.h index 977c666d3..ef2bf9c48 100644 --- a/src/PartSet/PartSet_SketcherMgr.h +++ b/src/PartSet/PartSet_SketcherMgr.h @@ -95,7 +95,7 @@ public: /// Returns whether the current operation is a sketch entity - line, point, arc or circle /// \param the operation /// \return a boolean value - static bool isEntityOperation(ModuleBase_Operation* theOperation); + static bool isEntity(const std::string& theId); /// Returns whether the current operation is a sketch distance - lenght, distance or radius /// \param the operation -- 2.39.2