Salome HOME
Issue #1019: Provide CompSolid selection mode for composite results
authorvsv <vitaly.smetannikov@opencascade.com>
Wed, 16 Dec 2015 09:00:06 +0000 (12:00 +0300)
committervsv <vitaly.smetannikov@opencascade.com>
Wed, 16 Dec 2015 09:00:24 +0000 (12:00 +0300)
src/FeaturesPlugin/rotation_widget.xml
src/FeaturesPlugin/translation_widget.xml
src/ModuleBase/ModuleBase_ISelection.cpp
src/ModuleBase/ModuleBase_ResultPrs.cpp
src/ModuleBase/ModuleBase_ResultPrs.h
src/XGUI/XGUI_Selection.cpp

index d715df1524fc4c7c4e7a8f444cab7d48b2bee8c6..f483a7403ba34bab03ae209bf19ebda01f0f70fb 100755 (executable)
@@ -5,7 +5,7 @@
     label="Main objects"
     icon=":icons/cut_shape.png"
     tooltip="Select a solid objects"
-    type_choice=""
+    type_choice="solid"
     use_choice="false"
     concealment="true">
     <validator id="FeaturesPlugin_ValidatorTransform"/>
index c9261206bfe3fd994e81769b712449a68ceecfaf..41e53b00254a0db5f9bec353534630f9d780131c 100644 (file)
@@ -5,7 +5,7 @@
     label="Main objects"
     icon=":icons/cut_shape.png"
     tooltip="Select a solid objects"
-    type_choice=""
+    type_choice="solid"
     concealment="true">
     <validator id="FeaturesPlugin_ValidatorTransform"/>
   </multi_selector>
index 72f1e4df8337efcd78e60bbe2f48409855b611e5..d5c325558b186df333cc949b379e9a2fef344754 100644 (file)
@@ -38,13 +38,12 @@ ResultPtr ModuleBase_ISelection::getResult(const ModuleBase_ViewerPrs& thePrs)
 {
   ResultPtr aResult;
 
-  if (!thePrs.owner().IsNull()) {
+  if (thePrs.object().get())
+    aResult = std::dynamic_pointer_cast<ModelAPI_Result>(thePrs.object());
+  else if (!thePrs.owner().IsNull()) {
     ObjectPtr anObject = getSelectableObject(thePrs.owner());
     aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObject);
   }
-  else {
-    aResult = std::dynamic_pointer_cast<ModelAPI_Result>(thePrs.object());
-  }
 
   return aResult;
 }
index 73a492df92ba0e1b89e56baedbbdd7bfa1952e3f..f7f360422b244a5d9320c29295624c15bb5faee5 100755 (executable)
 
 #include <BRep_Builder.hxx>
 #include <Prs3d_Drawer.hxx>
+#include <Prs3d.hxx>
 #include <Prs3d_PointAspect.hxx>
 #include <Prs3d_IsoAspect.hxx>
 #include <TopoDS_Builder.hxx>
+#include <SelectMgr_SequenceOfOwner.hxx>
+#include <SelectMgr_EntityOwner.hxx>
+#include <SelectMgr_SelectionManager.hxx>
+#include <StdPrs_WFDeflectionShape.hxx>
+#include <StdSelect_BRepSelectionTool.hxx>
+#include <AIS_InteractiveContext.hxx>
+#include <TColStd_ListIteratorOfListOfInteger.hxx>
+
+
+
+IMPLEMENT_STANDARD_HANDLE(ModuleBase_BRepOwner, StdSelect_BRepOwner);
+IMPLEMENT_STANDARD_RTTIEXT(ModuleBase_BRepOwner, StdSelect_BRepOwner);
+
+//*******************************************************************************************
 
 IMPLEMENT_STANDARD_HANDLE(ModuleBase_ResultPrs, ViewerData_AISShape);
 IMPLEMENT_STANDARD_RTTIEXT(ModuleBase_ResultPrs, ViewerData_AISShape);
 
+
+
+
+
 ModuleBase_ResultPrs::ModuleBase_ResultPrs(ResultPtr theResult)
   : ViewerData_AISShape(TopoDS_Shape()), myResult(theResult), myIsSketchMode(false)
 {
@@ -40,6 +59,10 @@ ModuleBase_ResultPrs::ModuleBase_ResultPrs(ResultPtr theResult)
     aDrawer->PointAspect()->SetTypeOfMarker(Aspect_TOM_PLUS);
   else
     aDrawer->SetPointAspect(new Prs3d_PointAspect(Aspect_TOM_PLUS, Quantity_NOC_YELLOW, 1.));
+
+  // Activate individual repaintng if this is a part of compsolid
+  ResultCompSolidPtr aCompSolid = ModelAPI_Tools::compSolidOwner(myResult);
+  SetAutoHilight(aCompSolid.get() == NULL);
 }
 
 
@@ -50,6 +73,7 @@ void ModuleBase_ResultPrs::Compute(const Handle(PrsMgr_PresentationManager3d)& t
   std::shared_ptr<GeomAPI_Shape> aShapePtr = ModelAPI_Tools::shape(myResult);
   if (!aShapePtr)
     return;
+
   if (myIsSketchMode) {
     myFacesList.clear();
     ResultConstructionPtr aConstruction = 
@@ -75,12 +99,13 @@ void ModuleBase_ResultPrs::Compute(const Handle(PrsMgr_PresentationManager3d)& t
 void ModuleBase_ResultPrs::ComputeSelection(const Handle(SelectMgr_Selection)& aSelection,
                                             const Standard_Integer aMode)
 {
-  if (aMode > TopAbs_SHAPE)
+  if (aMode > 8)
     // In order to avoid using custom selection modes
     return;
 
+  
   if (myIsSketchMode) {
-    if (aMode == TopAbs_FACE) {
+    if (aMode == AIS_Shape::SelectionMode(TopAbs_FACE)) {
       BRep_Builder aBuilder;
       TopoDS_Compound aComp;
       aBuilder.MakeCompound(aComp);
@@ -91,9 +116,102 @@ void ModuleBase_ResultPrs::ComputeSelection(const Handle(SelectMgr_Selection)& a
         aBuilder.Add(aComp, aFace);
       }
       Set(aComp);
-    } else {
+    } else
       Set(myOriginalShape);
+  } 
+  if (aMode == AIS_Shape::SelectionMode(TopAbs_COMPSOLID)) {
+    // Limit selection area only by actual object (Shape)
+    ResultCompSolidPtr aCompSolid = ModelAPI_Tools::compSolidOwner(myResult);
+    if (aCompSolid.get()) {
+      std::shared_ptr<GeomAPI_Shape> aShapePtr = ModelAPI_Tools::shape(aCompSolid);
+      if (aShapePtr.get()) {
+        TopoDS_Shape aShape = aShapePtr->impl<TopoDS_Shape>();
+        int aPriority = StdSelect_BRepSelectionTool::GetStandardPriority(aShape, TopAbs_SHAPE);
+        double aDeflection = Prs3d::GetDeflection(aShape, myDrawer);
+
+        Handle(ModuleBase_BRepOwner) aOwner = new ModuleBase_BRepOwner(aShape, aPriority);
+        StdSelect_BRepSelectionTool::ComputeSensitive(aShape, aOwner, aSelection, 
+          aDeflection, myDrawer->HLRAngle(), 9, 500);
+
+        for (aSelection->Init(); aSelection->More(); aSelection->Next()) {
+          Handle(SelectMgr_EntityOwner) anOwner
+            = Handle(SelectMgr_EntityOwner)::DownCast (aSelection->Sensitive()->BaseSensitive()->OwnerId());
+          anOwner->Set(this);
+        }
+        return;
+      }
     }
-  }
+    //AIS_Shape::ComputeSelection(aSelection, 0);
+  } 
   AIS_Shape::ComputeSelection(aSelection, aMode);
-}
\ No newline at end of file
+}
+
+
+bool ModuleBase_ResultPrs::hasCompSolidSelectionMode() const
+{
+  if (!HasInteractiveContext()) 
+    return false;
+
+  Handle(AIS_InteractiveContext) aContext = GetContext();
+  TColStd_ListOfInteger aModes;
+  aContext->ActivatedModes(this, aModes);
+
+  TColStd_ListIteratorOfListOfInteger aIt(aModes);
+  for (; aIt.More(); aIt.Next()) {
+    if (aIt.Value() == AIS_Shape::SelectionMode(TopAbs_COMPSOLID)) 
+      return true;
+  }
+  return false;
+}
+
+
+TopoDS_Shape ModuleBase_ResultPrs::getSelectionShape() const
+{
+  if (hasCompSolidSelectionMode()) {
+    // In case of CompSolid mode use shape from Parent for highlighting
+    ResultCompSolidPtr aCompSolid = ModelAPI_Tools::compSolidOwner(myResult);
+    if (aCompSolid.get()) {
+      std::shared_ptr<GeomAPI_Shape> aShapePtr = ModelAPI_Tools::shape(aCompSolid);
+      if (aShapePtr.get()) 
+        return aShapePtr->impl<TopoDS_Shape>();
+    }
+  } 
+  return myOriginalShape;
+}
+
+
+void ModuleBase_ResultPrs::HilightSelected(const Handle(PrsMgr_PresentationManager3d)& thePM, 
+                                           const SelectMgr_SequenceOfOwner& theOwners)
+{
+  TopoDS_Shape aShape = getSelectionShape();
+  if (!aShape.IsNull()) {
+    Handle( Prs3d_Presentation ) aSelectionPrs = GetSelectPresentation( thePM );
+    aSelectionPrs->Clear();
+
+    StdPrs_WFDeflectionShape::Add(aSelectionPrs, aShape, myDrawer);
+
+    aSelectionPrs->SetDisplayPriority(9);
+    aSelectionPrs->Highlight(Aspect_TOHM_COLOR, aSelectionPrs->HighlightColor());
+    aSelectionPrs->Display();
+    thePM->Highlight(this);
+  }
+}
+  
+void ModuleBase_ResultPrs::HilightOwnerWithColor(const Handle(PrsMgr_PresentationManager3d)& thePM, 
+                                                 const Quantity_NameOfColor theColor, 
+                                                 const Handle(SelectMgr_EntityOwner)& theOwner)
+{
+  TopoDS_Shape aShape = getSelectionShape();
+  if (!aShape.IsNull()) {
+    thePM->Color(this, theColor);
+
+    Handle( Prs3d_Presentation ) aHilightPrs = GetHilightPresentation( thePM );
+    aHilightPrs->Clear();
+
+    StdPrs_WFDeflectionShape::Add(aHilightPrs, aShape, myDrawer);
+    aHilightPrs->Highlight(Aspect_TOHM_COLOR, theColor);
+
+    if (thePM->IsImmediateModeOn())
+      thePM->AddToImmediateList(aHilightPrs);
+  }
+}
index 0389241a033826f128d5a6dc099c803c5176b2e7..056d757e18b619639cee7317391eedeafd3d317a 100644 (file)
 
 #include <ViewerData_AISShape.hxx>
 #include <Standard_DefineHandle.hxx>
+#include <StdSelect_BRepOwner.hxx>
+
+DEFINE_STANDARD_HANDLE(ModuleBase_BRepOwner, StdSelect_BRepOwner)
+
+/**
+* \ingroup GUI
+* A redefinition of standard BRep Owner in order to provide specific selection
+* of CompSolid objects. This owner is created only for selection mode TopAbs_COMPSOLID
+*/
+class ModuleBase_BRepOwner: public StdSelect_BRepOwner
+{
+public:
+  ModuleBase_BRepOwner(const TopoDS_Shape& aShape, 
+    const Standard_Integer aPriority = 0, 
+    const Standard_Boolean ComesFromDecomposition = Standard_False)
+    : StdSelect_BRepOwner(aShape, aPriority, ComesFromDecomposition) {}
+
+  virtual void HilightWithColor (const Handle(PrsMgr_PresentationManager3d)& aPM, 
+    const Quantity_NameOfColor aCol, const Standard_Integer aMode = 0)
+  {  Selectable()->HilightOwnerWithColor(aPM, aCol, this); }
+
+  DEFINE_STANDARD_RTTI(ModuleBase_BRepOwner)
+};
+
+
 
 DEFINE_STANDARD_HANDLE(ModuleBase_ResultPrs, ViewerData_AISShape)
 
@@ -28,6 +53,16 @@ public:
   /// \param theResult a result object
   Standard_EXPORT ModuleBase_ResultPrs(ResultPtr theResult);
 
+
+  //! Method which draws selected owners ( for fast presentation draw )
+  Standard_EXPORT virtual void HilightSelected(const Handle(PrsMgr_PresentationManager3d)& thePM, 
+                                               const SelectMgr_SequenceOfOwner& theOwners);
+  
+  //! Method which hilight an owner belonging to
+  //! this selectable object  ( for fast presentation draw )
+  Standard_EXPORT virtual void HilightOwnerWithColor(const Handle(PrsMgr_PresentationManager3d)& thePM, 
+                                                     const Quantity_NameOfColor theColor, const Handle(SelectMgr_EntityOwner)& theOwner);
+
   /// Returns result object
   Standard_EXPORT ResultPtr getResult() const { return myResult; }
 
@@ -37,6 +72,9 @@ public:
   /// Returns a list of faces
   Standard_EXPORT const std::list<std::shared_ptr<GeomAPI_Shape> >& facesList() { return myFacesList; }
 
+  /// Returns true if the object is used in CompSolid selection mode
+  Standard_EXPORT bool hasCompSolidSelectionMode() const;
+
   DEFINE_STANDARD_RTTI(ModuleBase_ResultPrs)
 protected:
   /// Redefinition of virtual function
@@ -48,6 +86,10 @@ protected:
     const Standard_Integer aMode) ;
 
 private:
+  /// Returns shape dependent on CompSolid selection mode
+  /// In case CompSolid selection mode it returns parent's compsolid shape
+  TopoDS_Shape getSelectionShape() const;
+
   /// Reference to result object
   ResultPtr myResult;
 
index 1b6f86542f9b2dfa79f6576a6741846e1a61b0df..079c30cba599938890356ce430a0cb9d2c1727d2 100644 (file)
 #include "XGUI_ViewerProxy.h"
 #include "XGUI_ObjectsBrowser.h"
 
+#include "ModuleBase_ResultPrs.h"
+
 #include <ModelAPI_Feature.h>
+#include <ModelAPI_Tools.h>
 
 #include <AIS_InteractiveContext.hxx>
 #include <AIS_Axis.hxx>
@@ -166,6 +169,26 @@ void XGUI_Selection::fillPresentation(ModuleBase_ViewerPrs& thePrs,
      
   XGUI_Displayer* aDisplayer = myWorkshop->displayer();
   ObjectPtr aFeature = aDisplayer->getObject(anIO);
+
+  Handle(ModuleBase_BRepOwner) aCompSolidBRO = Handle(ModuleBase_BRepOwner)::DownCast(theOwner);
+  if (!aCompSolidBRO.IsNull()) {
+    // If ModuleBase_BRepOwner object is created then it means that TopAbs_COMPSOLID selection mode
+    // is On and we have to use parent result which corresponds to the CompSolid shape
+    ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(aFeature);
+    if (aResult.get()) {
+      ResultCompSolidPtr aCompSolid = ModelAPI_Tools::compSolidOwner(aResult);
+      if (aCompSolid.get()) {
+        GeomShapePtr aShapePtr = aCompSolid->shape();
+        if (aShapePtr.get()) {
+          TopoDS_Shape aShape = aShapePtr->impl<TopoDS_Shape>();
+          if (aShape.IsEqual(thePrs.shape())) {
+            thePrs.setObject(aCompSolid);
+            return;
+          }
+        }
+      }
+    }
+  }
   thePrs.setObject(aFeature);
 }