]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Insert feature to a folder command call
authorvsv <vsv@opencascade.com>
Fri, 24 Nov 2017 15:08:54 +0000 (18:08 +0300)
committervsv <vsv@opencascade.com>
Fri, 24 Nov 2017 15:08:54 +0000 (18:08 +0300)
src/XGUI/XGUI_Workshop.cpp
src/XGUI/XGUI_Workshop.h

index 387df6660ffa45cf86693cde39dc8e637b63b35d..7556e1042546333ae6e20912225efabe22d1607e 100755 (executable)
@@ -1416,9 +1416,9 @@ void XGUI_Workshop::onContextMenuCommand(const QString& theId, bool isChecked)
   } else if (theId == "INSERT_FOLDER_CMD") {
     insertFeatureFolder();
   } else if (theId == "ADD_TO_FOLDER_BEFORE_CMD") {
-    insertToFolderBefore();
+    insertToFolder(true);
   } else if (theId == "ADD_TO_FOLDER_AFTER_CMD") {
-    insertToFolderAfter();
+    insertToFolder(false);
   } else if (theId == "SELECT_RESULT_CMD") {
     //setViewerSelectionMode(-1);
     //IMP: an attempt to use result selection with other selection modes
@@ -2448,16 +2448,31 @@ void XGUI_Workshop::insertFeatureFolder()
   aMgr->finishOperation();
 }
 
-void XGUI_Workshop::insertToFolderBefore()
+
+void XGUI_Workshop::insertToFolder(bool isBefore)
 {
   QObjectPtrList aObjects = mySelector->selection()->selectedObjects();
   if (aObjects.isEmpty())
     return;
-}
 
-void XGUI_Workshop::insertToFolderAfter()
-{
-  QObjectPtrList aObjects = mySelector->selection()->selectedObjects();
-  if (aObjects.isEmpty())
+  std::list<FeaturePtr> aFeatures;
+  foreach(ObjectPtr aObj, aObjects) {
+    FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aObj);
+    if (aFeature.get())
+      aFeatures.push_back(aFeature);
+  }
+  if (aFeatures.empty())
+    return;
+
+  SessionPtr aMgr = ModelAPI_Session::get();
+  DocumentPtr aDoc = aMgr->activeDocument();
+
+  FolderPtr aFolder = isBefore? aDoc->findFolderAbove(aFeatures):
+                                aDoc->findFolderBelow(aFeatures);
+  if (!aFolder.get())
     return;
+
+  aMgr->startOperation();
+  aDoc->moveToFolder(aFeatures, aFolder);
+  aMgr->finishOperation();
 }
index 5b6f3bb5ae3790442e44602f84863a702f42a0a4..b5d181f2e68ee413f6e86eb40064b1effca4fdbe 100755 (executable)
@@ -451,11 +451,8 @@ private:
   /// Insert folder object before currently selected feature
   void insertFeatureFolder();
 
-  /// Insert an object to a folder above
-  void insertToFolderBefore();
-
-  /// Insert an object to a folder below
-  void insertToFolderAfter();
+  /// Insert an object to a folder above or below
+  void insertToFolder(bool isBefore);
 
  private slots:
   /// SLOT, that is called after the operation is started. Update workshop state according to