Salome HOME
Issue #2344: Fix cleared selection on Cancel of Undo/Redo command
[modules/shaper.git] / src / XGUI / XGUI_Displayer.cpp
index 26672b4726b4cf94ac9210dfb0d184d1c9f02d34..2652ae0ed1753caa9e7f863862942f59b2ba4247 100644 (file)
@@ -1,15 +1,30 @@
-// Copyright (C) 2014-20xx CEA/DEN, EDF R&D -->
-
-// File:        XGUI_Displayer.cpp
-// Created:     20 Apr 2014
-// Author:      Natalia ERMOLAEVA
+// Copyright (C) 2014-2017  CEA/DEN, EDF R&D
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// See http://www.salome-platform.org/ or
+// 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>
@@ -60,7 +76,7 @@
 #include <TColStd_MapIteratorOfMapOfTransient.hxx>
 
 #ifdef TINSPECTOR
-#include <VInspectorAPI_CallBack.hxx>
+#include <inspector/VInspectorAPI_CallBack.hxx>
 #endif
 
 #include <Events_Loop.h>
@@ -1057,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
@@ -1351,7 +1367,6 @@ bool XGUI_Displayer::activate(const Handle(AIS_InteractiveObject)& theIO,
   return isActivationChanged;
 }
 
-//#define DEBUG_FULLY_CONSTRAINED
 bool XGUI_Displayer::customizeObject(ObjectPtr theObject)
 {
   AISObjectPtr anAISObj = getAISObject(theObject);
@@ -1374,10 +1389,13 @@ bool XGUI_Displayer::customizeObject(ObjectPtr theObject)
   }
   bool isCustomized = aCustomPrs.get() &&
                       aCustomPrs->customisePresentation(aResult, anAISObj, myCustomPrs);
-#ifdef DEBUG_FULLY_CONSTRAINED
   isCustomized = myWorkshop->module()->afterCustomisePresentation(aResult, anAISObj, myCustomPrs)
                  || isCustomized;
-#endif
+
+  // update presentation state if faces panel is active
+  if (anAISObj.get() && myWorkshop->facesPanel())
+    isCustomized = myWorkshop->facesPanel()->customizeObject(theObject, anAISObj) || isCustomized;
+
   return isCustomized;
 }
 
@@ -1434,6 +1452,14 @@ void XGUI_Displayer::getPresentations(const ObjectPtr& theObject,
   ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
   if (aResult.get()) {
     AISObjectPtr aAISObj = getAISObject(aResult);
+    if (aAISObj.get() == NULL) {
+      // if result is a result of a composite feature, it is visualized by visualization of
+      // composite children, so we should get one of this presentations
+      ResultCompSolidPtr aCompSolid = std::dynamic_pointer_cast<ModelAPI_ResultCompSolid>(aResult);
+      if (aCompSolid.get() && aCompSolid->numberOfSubs() > 0) {
+        aAISObj = getAISObject(aCompSolid->subResult(0));
+      }
+    }
     if (aAISObj.get() != NULL) {
       Handle(AIS_InteractiveObject) anAIS = aAISObj->impl<Handle(AIS_InteractiveObject)>();
       if (!anAIS.IsNull() && !thePresentations.Contains(anAIS))
@@ -1499,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
@@ -1522,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);
@@ -1545,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);
+  }
 }