Salome HOME
Issue #2344: Fix cleared selection on Cancel of Undo/Redo command
[modules/shaper.git] / src / XGUI / XGUI_Displayer.cpp
index b68f63dd656d6f8f2eafa9726c4e3be10a43fe18..2652ae0ed1753caa9e7f863862942f59b2ba4247 100644 (file)
 // email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
 //
 
+#include "XGUI_CustomPrs.h"
 #include "XGUI_Displayer.h"
-#include "XGUI_Workshop.h"
-#include "XGUI_ViewerProxy.h"
-#include "XGUI_SelectionMgr.h"
+#include "XGUI_FacesPanel.h"
 #include "XGUI_Selection.h"
-#include "XGUI_CustomPrs.h"
+#include "XGUI_SelectionMgr.h"
+#include "XGUI_ViewerProxy.h"
+#include "XGUI_Workshop.h"
 
 #ifndef HAVE_SALOME
 #include <AppElements_Viewer.h>
 #include <ModelAPI_AttributeIntArray.h>
 #include <ModelAPI_ResultCompSolid.h>
 
+#include <ModuleBase_BRepOwner.h>
+#include <ModuleBase_IModule.h>
+#include <ModuleBase_Preferences.h>
 #include <ModuleBase_ResultPrs.h>
 #include <ModuleBase_Tools.h>
-#include <ModuleBase_IModule.h>
 #include <ModuleBase_ViewerPrs.h>
-#include <ModuleBase_Preferences.h>
 
 #include <GeomAPI_Shape.h>
 #include <GeomAPI_IPresentable.h>
@@ -74,7 +76,7 @@
 #include <TColStd_MapIteratorOfMapOfTransient.hxx>
 
 #ifdef TINSPECTOR
-#include <VInspectorAPI_CallBack.hxx>
+#include <inspector/VInspectorAPI_CallBack.hxx>
 #endif
 
 #include <Events_Loop.h>
@@ -1071,13 +1073,13 @@ Handle(SelectMgr_AndFilter) XGUI_Displayer::GetFilter()
 }
 
 bool XGUI_Displayer::displayAIS(AISObjectPtr theAIS, const bool toActivateInSelectionModes,
-                                bool theUpdateViewer)
+                                const Standard_Integer theDisplayMode, bool theUpdateViewer)
 {
   bool aDisplayed = false;
   Handle(AIS_InteractiveContext) aContext = AISContext();
   Handle(AIS_InteractiveObject) anAISIO = theAIS->impl<Handle(AIS_InteractiveObject)>();
   if (!aContext.IsNull() && !anAISIO.IsNull()) {
-    aContext->Display(anAISIO, 0/*wireframe*/, 0, false/*update viewer*/, true, AIS_DS_Displayed);
+    aContext->Display(anAISIO, theDisplayMode, 0, false/*update viewer*/, true, AIS_DS_Displayed);
     #ifdef TINSPECTOR
     if (getCallBack()) getCallBack()->Display(anAISIO);
     #endif
@@ -1389,6 +1391,11 @@ bool XGUI_Displayer::customizeObject(ObjectPtr theObject)
                       aCustomPrs->customisePresentation(aResult, anAISObj, myCustomPrs);
   isCustomized = myWorkshop->module()->afterCustomisePresentation(aResult, anAISObj, myCustomPrs)
                  || isCustomized;
+
+  // update presentation state if faces panel is active
+  if (anAISObj.get() && myWorkshop->facesPanel())
+    isCustomized = myWorkshop->facesPanel()->customizeObject(theObject, anAISObj) || isCustomized;
+
   return isCustomized;
 }
 
@@ -1518,7 +1525,7 @@ void XGUI_Displayer::displayTrihedron(bool theToDisplay) const
   } else {
     deactivateTrihedron(false);
 
-    aContext->Erase(aTrihedron);
+    aContext->Erase(aTrihedron, Standard_True);
     #ifdef TINSPECTOR
     if (getCallBack()) getCallBack()->Remove(aTrihedron);
     #endif
@@ -1541,6 +1548,9 @@ void XGUI_Displayer::AddOrRemoveSelectedShapes(Handle(AIS_InteractiveContext) th
                            const NCollection_DataMap<TopoDS_Shape,
                            NCollection_Map<Handle(AIS_InteractiveObject)>>& theShapesToBeSelected)
 {
+  NCollection_Map<Handle(AIS_InteractiveObject)> aCompsolidPresentations;
+  NCollection_Map<Handle(AIS_InteractiveObject)> aSelectedPresentations;
+
   NCollection_List<Handle(SelectBasics_EntityOwner)> anActiveOwners;
   theContext->MainSelector()->ActiveOwners(anActiveOwners);
   NCollection_List<Handle(SelectBasics_EntityOwner)>::Iterator anOwnersIt (anActiveOwners);
@@ -1564,26 +1574,46 @@ void XGUI_Displayer::AddOrRemoveSelectedShapes(Handle(AIS_InteractiveContext) th
       if (aShape.IsNull())
         continue;
 
+      Handle(ModuleBase_BRepOwner) aCustomOwner = Handle(ModuleBase_BRepOwner)::DownCast(anOwner);
+
       NCollection_DataMap<TopoDS_Shape, NCollection_Map<Handle(AIS_InteractiveObject)> >
                                              ::Iterator aShapeIt(theShapesToBeSelected);
       for (; aShapeIt.More(); aShapeIt.Next()) {
-        if (aShapeIt.Key().IsSame(aShape)) {
-          const TopoDS_Shape& aParameterShape = aShapeIt.Key();
-          // isSame should be used here as it does not check orientation of shapes
-          // despite on isEqual of shapes or IsBound for shape in QMap. Orientation is
-          // different for Edges shapes in model shape and owner even if this is the same shape
-          if (aParameterShape.IsSame(aShape)) {
-            Handle(AIS_InteractiveObject) anOwnerPresentation =
-                              Handle(AIS_InteractiveObject)::DownCast(anOwner->Selectable());
-            NCollection_Map<Handle(AIS_InteractiveObject)> aPresentations =
-                                        theShapesToBeSelected.Find(aParameterShape);
-            if (aPresentations.Contains(anOwnerPresentation)) {
-              theContext->AddOrRemoveSelected(anOwner);
-              anOwner->SetSelected (Standard_True);
-            }
+        const TopoDS_Shape& aParameterShape = aShapeIt.Key();
+        // isSame should be used here as it does not check orientation of shapes
+        // despite on isEqual of shapes or IsBound for shape in QMap. Orientation is
+        // different for Edges shapes in model shape and owner even if this is the same shape
+        if (aParameterShape.IsSame(aShape)) {
+          Handle(AIS_InteractiveObject) anOwnerPresentation =
+                            Handle(AIS_InteractiveObject)::DownCast(anOwner->Selectable());
+          NCollection_Map<Handle(AIS_InteractiveObject)> aPresentations =
+                                      theShapesToBeSelected.Find(aParameterShape);
+          if (aPresentations.Contains(anOwnerPresentation)) {
+            theContext->AddOrRemoveSelected(anOwner, Standard_False);
+            anOwner->SetSelected (Standard_True);
+            // collect selected presentations to do not select them if compsolid is selected
+            if (!aSelectedPresentations.Contains(anOwnerPresentation))
+              aSelectedPresentations.Add(anOwnerPresentation);
           }
         }
+        else if (!aCustomOwner.IsNull()) { // CompSolid processing #2219
+          // shape of owner is compound, but shape to be selected is compsolid, so
+          // we need to compare shape to AIS presentation of owner(rule of the owner creation)
+          Handle(AIS_Shape) anOwnerPresentation =
+                            Handle(AIS_Shape)::DownCast(anOwner->Selectable());
+          const TopoDS_Shape& aPresentationShape = anOwnerPresentation->Shape();
+          if (aParameterShape.IsSame(anOwnerPresentation->Shape()) &&
+              !aCompsolidPresentations.Contains(anOwnerPresentation))
+            aCompsolidPresentations.Add(anOwnerPresentation);
+        }
       }
     }
   }
+  // select CompSolid presentations if their owners was not selected yet
+  NCollection_Map<Handle(AIS_InteractiveObject)>::Iterator anIt (aCompsolidPresentations);
+  for (; anIt.More(); anIt.Next()) {
+    if (aSelectedPresentations.Contains(anIt.Value()))
+      continue;
+    theContext->AddOrRemoveSelected(anIt.Value(), Standard_False);
+  }
 }