]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Do not use Parts for folders
authorvsv <vsv@opencascade.com>
Tue, 28 Nov 2017 12:36:43 +0000 (15:36 +0300)
committervsv <vsv@opencascade.com>
Tue, 28 Nov 2017 12:36:43 +0000 (15:36 +0300)
src/XGUI/XGUI_ContextMenuMgr.cpp
src/XGUI/XGUI_SelectionMgr.cpp
src/XGUI/XGUI_SelectionMgr.h

index 0026ad7e1d34363437c3bbf38a0bfdfcfde32f1e..be9bf8c16fd0e706d3bde0c34798d0fc6a340911 100644 (file)
@@ -352,86 +352,89 @@ void XGUI_ContextMenuMgr::updateObjectBrowserMenu()
     // Check folder management commands state if only features are selected
     if ((!hasResult) && hasFeature && (!hasParameter) && (!hasCompositeOwner) &&
       (!hasResultInHistory) && (!hasFolder)) {
-      QModelIndexList aIndexes = aSelMgr->selection()->selectedIndexes();
-      QModelIndex aFirstIdx = aIndexes.first();
-      QModelIndex aLastIdx = aIndexes.last();
-      QModelIndex aParentIdx = aFirstIdx.parent();
-
-      // if all selected are from the same level
-      bool isSameParent = true;
-      foreach(QModelIndex aIdx, aIndexes) {
-        if (aIdx.parent() != aParentIdx) {
-          isSameParent = false;
-          break;
+      std::list<FeaturePtr> aFeatures = aSelMgr->getSelectedFeatures();
+      if (aFeatures.size() > 0) { // Check that features do not include Parts
+        QModelIndexList aIndexes = aSelMgr->selection()->selectedIndexes();
+        QModelIndex aFirstIdx = aIndexes.first();
+        QModelIndex aLastIdx = aIndexes.last();
+        QModelIndex aParentIdx = aFirstIdx.parent();
+
+        // if all selected are from the same level
+        bool isSameParent = true;
+        foreach(QModelIndex aIdx, aIndexes) {
+          if (aIdx.parent() != aParentIdx) {
+            isSameParent = false;
+            break;
+          }
         }
-      }
-      if (isSameParent) {
-        // Check is selection continuous
-        XGUI_DataModel* aModel = myWorkshop->objectBrowser()->dataModel();
-        DocumentPtr aDoc = aMgr->activeDocument();
-        std::list<FeaturePtr> aFeatures = aSelMgr->getSelectedFeatures();
-
-        bool isContinuos = true;
-        if (aSelected > 1) {
-          int aId = -1;
-          foreach(FeaturePtr aF, aFeatures) {
-            if (aId == -1)
-              aId = aDoc->index(aF);
-            else {
-              aId++;
-              if (aId != aDoc->index(aF)) {
-                isContinuos = false;
-                break;
+        if (isSameParent) {
+          // Check is selection continuous
+          XGUI_DataModel* aModel = myWorkshop->objectBrowser()->dataModel();
+          DocumentPtr aDoc = aMgr->activeDocument();
+          std::list<FeaturePtr> aFeatures = aSelMgr->getSelectedFeatures();
+
+          bool isContinuos = true;
+          if (aSelected > 1) {
+            int aId = -1;
+            foreach(FeaturePtr aF, aFeatures) {
+              if (aId == -1)
+                aId = aDoc->index(aF);
+              else {
+                aId++;
+                if (aId != aDoc->index(aF)) {
+                  isContinuos = false;
+                  break;
+                }
               }
             }
           }
-        }
-        if (isContinuos) {
-          ObjectPtr aDataObj = aModel->object(aParentIdx);
+          if (isContinuos) {
+            ObjectPtr aDataObj = aModel->object(aParentIdx);
 
-          ObjectPtr aPrevObj;
-          if (aFirstIdx.row() > 0) {
-            QModelIndex aPrevIdx = aFirstIdx.sibling(aFirstIdx.row() - 1, 0);
-            aPrevObj = aModel->object(aPrevIdx);
-          }
+            ObjectPtr aPrevObj;
+            if (aFirstIdx.row() > 0) {
+              QModelIndex aPrevIdx = aFirstIdx.sibling(aFirstIdx.row() - 1, 0);
+              aPrevObj = aModel->object(aPrevIdx);
+            }
 
-          ObjectPtr aNextObj;
-          if (aLastIdx.row() < (aModel->rowCount(aParentIdx) - 1)) {
-            QModelIndex aNextIdx = aFirstIdx.sibling(aLastIdx.row() + 1, 0);
-            aNextObj = aModel->object(aNextIdx);
-          }
+            ObjectPtr aNextObj;
+            if (aLastIdx.row() < (aModel->rowCount(aParentIdx) - 1)) {
+              QModelIndex aNextIdx = aFirstIdx.sibling(aLastIdx.row() + 1, 0);
+              aNextObj = aModel->object(aNextIdx);
+            }
 
-          bool isPrevFolder = (aPrevObj.get() &&
-            (aPrevObj->groupName() == ModelAPI_Folder::group()));
-          bool isNextFolder = (aNextObj.get() &&
-            (aNextObj->groupName() == ModelAPI_Folder::group()));
-          bool isInFolder = (aDataObj.get() &&
-            (aDataObj->groupName() == ModelAPI_Folder::group()));
-          bool isOutsideFolder = !isInFolder;
-
-          bool hasFirst = false;
-          bool hasLast = false;
-          if (isInFolder) {
-            FolderPtr aFolder = std::dynamic_pointer_cast<ModelAPI_Folder>(aDataObj);
-            FeaturePtr aFirstFeatureInFolder;
-            AttributeReferencePtr aFirstFeatAttr =
-                aFolder->data()->reference(ModelAPI_Folder::FIRST_FEATURE_ID());
-            if (aFirstFeatAttr)
-              aFirstFeatureInFolder = ModelAPI_Feature::feature(aFirstFeatAttr->value());
-            hasFirst = (aFirstFeatureInFolder == aFeatures.front());
-
-            FeaturePtr aLastFeatureInFolder;
-            AttributeReferencePtr aLastFeatAttr =
-                aFolder->data()->reference(ModelAPI_Folder::LAST_FEATURE_ID());
-            if (aLastFeatAttr)
-              aLastFeatureInFolder = ModelAPI_Feature::feature(aLastFeatAttr->value());
-            hasLast = (aLastFeatureInFolder == aFeatures.back());
+            bool isPrevFolder = (aPrevObj.get() &&
+              (aPrevObj->groupName() == ModelAPI_Folder::group()));
+            bool isNextFolder = (aNextObj.get() &&
+              (aNextObj->groupName() == ModelAPI_Folder::group()));
+            bool isInFolder = (aDataObj.get() &&
+              (aDataObj->groupName() == ModelAPI_Folder::group()));
+            bool isOutsideFolder = !isInFolder;
+
+            bool hasFirst = false;
+            bool hasLast = false;
+            if (isInFolder) {
+              FolderPtr aFolder = std::dynamic_pointer_cast<ModelAPI_Folder>(aDataObj);
+              FeaturePtr aFirstFeatureInFolder;
+              AttributeReferencePtr aFirstFeatAttr =
+                  aFolder->data()->reference(ModelAPI_Folder::FIRST_FEATURE_ID());
+              if (aFirstFeatAttr)
+                aFirstFeatureInFolder = ModelAPI_Feature::feature(aFirstFeatAttr->value());
+              hasFirst = (aFirstFeatureInFolder == aFeatures.front());
+
+              FeaturePtr aLastFeatureInFolder;
+              AttributeReferencePtr aLastFeatAttr =
+                  aFolder->data()->reference(ModelAPI_Folder::LAST_FEATURE_ID());
+              if (aLastFeatAttr)
+                aLastFeatureInFolder = ModelAPI_Feature::feature(aLastFeatAttr->value());
+              hasLast = (aLastFeatureInFolder == aFeatures.back());
+            }
+            action("INSERT_FOLDER_CMD")->setEnabled(isOutsideFolder);
+            action("ADD_TO_FOLDER_BEFORE_CMD")->setEnabled(isOutsideFolder && isPrevFolder);
+            action("ADD_TO_FOLDER_AFTER_CMD")->setEnabled(isOutsideFolder && isNextFolder);
+            action("ADD_OUT_FOLDER_BEFORE_CMD")->setEnabled(isInFolder && hasFirst);
+            action("ADD_OUT_FOLDER_AFTER_CMD")->setEnabled(isInFolder && hasLast);
           }
-          action("INSERT_FOLDER_CMD")->setEnabled(isOutsideFolder);
-          action("ADD_TO_FOLDER_BEFORE_CMD")->setEnabled(isOutsideFolder && isPrevFolder);
-          action("ADD_TO_FOLDER_AFTER_CMD")->setEnabled(isOutsideFolder && isNextFolder);
-          action("ADD_OUT_FOLDER_BEFORE_CMD")->setEnabled(isInFolder && hasFirst);
-          action("ADD_OUT_FOLDER_AFTER_CMD")->setEnabled(isInFolder && hasLast);
         }
       }
     } // end folder management commands
index 38cb1d325055cb3af5b4f1dd50d9b7b3c2fe939c..ed7e5e23330e21ab0925e668d5cb580c0f4a8e13 100755 (executable)
@@ -228,10 +228,15 @@ std::list<FeaturePtr> XGUI_SelectionMgr::getSelectedFeatures()
   if (aObjects.isEmpty())
     return aFeatures;
 
+  bool isPart = false;
   foreach(ObjectPtr aObj, aObjects) {
     FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aObj);
-    if (aFeature.get())
-      aFeatures.push_back(aFeature);
+    if (aFeature.get()) {
+      ResultPtr aRes = aFeature->firstResult();
+      isPart = (aRes.get() && (aRes->groupName() == ModelAPI_ResultPart::group()));
+      if (!isPart)
+        aFeatures.push_back(aFeature);
+    }
   }
   return aFeatures;
 }
\ No newline at end of file
index b6829da0a39143547be5df8e9b4ee7fa62d49ca7..06e6fe54e5d0f19274413f0a56504b9db9722940 100644 (file)
@@ -78,7 +78,7 @@ Q_OBJECT
   /// \param thePlace a widget where selection has happened.
   void updateSelectionBy(const ModuleBase_ISelection::SelectionPlace& thePlace);
 
-  /// Returns list of selected features (ignores other selected objects)
+  /// Returns list of selected features (ignores other selected objects and parts)
   std::list<FeaturePtr> getSelectedFeatures();
 
 signals: