]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Issue #442: Avoid extra menus in pop-up of sketcher objects
authorvsv <vitaly.smetannikov@opencascade.com>
Mon, 13 Apr 2015 13:00:35 +0000 (16:00 +0300)
committervsv <vitaly.smetannikov@opencascade.com>
Mon, 13 Apr 2015 13:00:35 +0000 (16:00 +0300)
src/PartSet/PartSet_MenuMgr.cpp
src/PartSet/PartSet_SketcherMgr.cpp
src/PartSet/PartSet_SketcherMgr.h

index da3bd6836d178dcea9b56c3b47c995b7254ff2c8..fa44262816150bdec9a85d277a80f584874b9d3e 100644 (file)
@@ -154,6 +154,28 @@ bool PartSet_MenuMgr::addViewerItems(QMenu* theMenu, const QMap<QString, QAction
   aSelection->selectedShapes(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<TopoDS_Shape>::Iterator aIt(aShapeList);
+    std::list<ObjectPtr>::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<ModelAPI_Result>(aObj);
+      if (aResult.get() != NULL) {
+        if (!aShape.IsEqual(aResult->shape()->impl<TopoDS_Shape>())) {
+          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<QString, QAction
       }
     }
   }
-  if ((!aIsDetach) && (aObjectsList.size() > 0)) {
+  QObjectPtrList aObjects = aSelection->selectedPresentations();
+  if ((!aIsDetach) && (aObjects.size() > 0)) {
     bool hasFeature = false;
     FeaturePtr aFeature;
-    std::list<ObjectPtr>::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<SketchPlugin_Feature> aSketchFeature =
                             std::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
         if (aSketchFeature.get() != NULL) {
index 207aee541f8eab4098baa9d5352f13d168db45f3..9c1c1be0b67ac861b6cc7f4c8ac02f061ede052e 100644 (file)
@@ -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)
index 977c666d39d9d9b911985ea84b8d0e514797c767..ef2bf9c485fcf98a204f9d2cf4e6e11ae4715e53 100644 (file)
@@ -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