Salome HOME
Remove extra files
[modules/shaper.git] / src / XGUI / XGUI_SelectionMgr.cpp
old mode 100644 (file)
new mode 100755 (executable)
index 11e2e76..f32ed50
 #include <ModelAPI_Data.h>
 #include <ModelAPI_Result.h>
 #include <ModelAPI_Object.h>
+#include <ModelAPI_ResultCompSolid.h>
+
+#include <ModuleBase_ViewerPrs.h>
+#include <ModuleBase_Tools.h>
 
 #include <SelectMgr_ListIteratorOfListOfFilter.hxx>
 
@@ -61,6 +65,8 @@ void XGUI_SelectionMgr::setSelectedOwners(const SelectMgr_IndexedMapOfOwner& the
       aContext->AddOrRemoveSelected(anOwner, isUpdateViewer);
     }
   }
+  ModuleBase_Tools::selectionInfo(aContext, 
+                                  "XGUI_SelectionMgr::setSelectedOwners -- AddOrRemoveSelected");
 }
 
 //**************************************************************
@@ -93,21 +99,33 @@ void XGUI_SelectionMgr::updateSelectedOwners(bool isUpdateViewer)
 //**************************************************************
 void XGUI_SelectionMgr::onObjectBrowserSelection()
 {
-  QList<ModuleBase_ViewerPrs> aSelectedPrs =
+  QList<ModuleBase_ViewerPrsPtr> aSelectedPrs =
              myWorkshop->selector()->selection()->getSelected(ModuleBase_ISelection::Browser);
 
-  QList<ModuleBase_ViewerPrs> aTmpList = aSelectedPrs;
+  QList<ModuleBase_ViewerPrsPtr> aTmpList = aSelectedPrs;
   ObjectPtr aObject;
   FeaturePtr aFeature;
-  foreach(ModuleBase_ViewerPrs aPrs, aTmpList) {
-    aObject = aPrs.object();
+  foreach(ModuleBase_ViewerPrsPtr aPrs, aTmpList) {
+    aObject = aPrs->object();
     if (aObject.get()) {
       aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aObject);
       if (aFeature.get()) {
         const std::list<std::shared_ptr<ModelAPI_Result>> aResList = aFeature->results();
+        ResultPtr aResult;
+        ResultCompSolidPtr aCompSolid;
         std::list<ResultPtr>::const_iterator aIt;
         for (aIt = aResList.cbegin(); aIt != aResList.cend(); ++aIt) {
-          aSelectedPrs.append(ModuleBase_ViewerPrs((*aIt), GeomShapePtr(), NULL));
+          aResult = (*aIt);
+          aSelectedPrs.append(std::shared_ptr<ModuleBase_ViewerPrs>(
+            new ModuleBase_ViewerPrs(aResult, GeomShapePtr(), NULL)));
+          aCompSolid = std::dynamic_pointer_cast<ModelAPI_ResultCompSolid>(aResult);
+          if (aCompSolid.get()) {
+            for (int i = 0; i < aCompSolid->numberOfSubs(); i++) {
+              ResultBodyPtr aResult = aCompSolid->subResult(i);
+              aSelectedPrs.append(std::shared_ptr<ModuleBase_ViewerPrs>(
+                new ModuleBase_ViewerPrs(aResult, aResult->shape(), NULL)));
+            }
+          }
         }
       }
     }
@@ -120,25 +138,28 @@ void XGUI_SelectionMgr::onObjectBrowserSelection()
 //**************************************************************
 void XGUI_SelectionMgr::onViewerSelection()
 {
+  SessionPtr aMgr = ModelAPI_Session::get();
+  DocumentPtr anActiveDocument = aMgr->activeDocument();
   QObjectPtrList aFeatures;
-  Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
-  if (!aContext.IsNull()) {
-    QList<ModuleBase_ViewerPrs> aPresentations = selection()->getSelected(ModuleBase_ISelection::Viewer);
-    foreach(ModuleBase_ViewerPrs aPrs, aPresentations) {
-      if (aPrs.object().get())
-        aFeatures.append(aPrs.object());
-    }
-  }
-  // Add features by selected results
-  QObjectPtrList aTmpList = aFeatures;
   ResultPtr aResult;
   FeaturePtr aFeature;
-  foreach(ObjectPtr aObj, aTmpList) {
-    aResult = std::dynamic_pointer_cast<ModelAPI_Result>(aObj);
-    if (aResult.get()) {
-      aFeature = ModelAPI_Feature::feature(aResult);
-      if (aFeature.get() && (!aFeatures.contains(aFeature)))
-        aFeatures.append(aFeature);
+  Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
+  if (!aContext.IsNull()) {
+    QList<ModuleBase_ViewerPrsPtr> aPresentations = 
+      selection()->getSelected(ModuleBase_ISelection::Viewer);
+    foreach(ModuleBase_ViewerPrsPtr aPrs, aPresentations) {
+      if (aPrs->object().get()) {
+        if (!aFeatures.contains(aPrs->object()))
+          aFeatures.append(aPrs->object());
+        if (aPrs->shape().get()) {
+          aResult = std::dynamic_pointer_cast<ModelAPI_Result>(aPrs->object());
+          if (aResult.get()) {
+            aFeature = anActiveDocument->producedByFeature(aResult, aPrs->shape());
+            if (aFeature.get() && (!aFeatures.contains(aFeature)))
+              aFeatures.append(aFeature);
+          }
+        }
+      }
     }
   }
   bool aBlocked = myWorkshop->objectBrowser()->blockSignals(true);
@@ -151,7 +172,7 @@ void XGUI_SelectionMgr::onViewerSelection()
 //**************************************************************
 void XGUI_SelectionMgr::updateSelectionBy(const ModuleBase_ISelection::SelectionPlace& thePlace)
 {
-  QList<ModuleBase_ViewerPrs> aSelectedPrs =
+  QList<ModuleBase_ViewerPrsPtr> aSelectedPrs =
                myWorkshop->selector()->selection()->getSelected(thePlace);
   if (thePlace == ModuleBase_ISelection::Browser) {
     XGUI_Displayer* aDisplayer = myWorkshop->displayer();
@@ -167,7 +188,7 @@ void XGUI_SelectionMgr::clearSelection()
   myWorkshop->objectBrowser()->setObjectsSelected(aFeatures);
   myWorkshop->objectBrowser()->blockSignals(aBlocked);
   
-  QList<ModuleBase_ViewerPrs> aSelectedPrs =
+  QList<ModuleBase_ViewerPrsPtr> aSelectedPrs =
              myWorkshop->selector()->selection()->getSelected(ModuleBase_ISelection::Browser);
 
   XGUI_Displayer* aDisplayer = myWorkshop->displayer();