Salome HOME
Shape plane filter should process shapes of objects selected in object browser.
authornds <natalia.donis@opencascade.com>
Fri, 3 Jul 2015 08:13:29 +0000 (11:13 +0300)
committernds <natalia.donis@opencascade.com>
Fri, 3 Jul 2015 08:13:52 +0000 (11:13 +0300)
Using geom algo plane in the plane filter for futher modifications.
Scenario: [crash] create sketch, create closed contour, create 2nd sketch, start translate operation, select with rectangle the prev sketch lines. Abort[sketch is selected in the OB]. Start translate again, crash[the sketch selected in OB is applyed to the multi selector control]

src/ModuleBase/ModuleBase_ViewerFilters.cpp
src/ModuleBase/ModuleBase_ViewerFilters.h
src/PartSet/PartSet_SketcherMgr.cpp

index 74304a35c790c4f03bafe2d3b814cff102d091a9..957b970e9e9aeaebf4a42cdc0bdaba1559717817 100644 (file)
@@ -22,6 +22,7 @@
 #include <TopoDS.hxx>
 #include <TopoDS_Edge.hxx>
 #include <Geom_Curve.hxx>
+#include <gp_Pln.hxx>
 
 IMPLEMENT_STANDARD_HANDLE(ModuleBase_ShapeDocumentFilter, SelectMgr_Filter);
 IMPLEMENT_STANDARD_RTTIEXT(ModuleBase_ShapeDocumentFilter, SelectMgr_Filter);
@@ -57,22 +58,25 @@ Standard_Boolean ModuleBase_ShapeDocumentFilter::IsOk(const Handle(SelectMgr_Ent
   return Standard_False;
 }
 
-
 IMPLEMENT_STANDARD_HANDLE(ModuleBase_ShapeInPlaneFilter, SelectMgr_Filter);
 IMPLEMENT_STANDARD_RTTIEXT(ModuleBase_ShapeInPlaneFilter, SelectMgr_Filter);
 
 Standard_Boolean ModuleBase_ShapeInPlaneFilter::IsOk(const Handle(SelectMgr_EntityOwner)& theOwner) const
 {
+  if (!myPlane.get())
+    return Standard_True;
+
   if (theOwner->HasSelectable()) {
     Handle(StdSelect_BRepOwner) aShapeOwner = Handle(StdSelect_BRepOwner)::DownCast(theOwner);
     if (!aShapeOwner.IsNull()) {
       TopoDS_Shape aShape = aShapeOwner->Shape();
       TopAbs_ShapeEnum aType = aShape.ShapeType();
+      gp_Pln aPlane = myPlane->impl<gp_Pln>();
       switch (aType) {
       case TopAbs_VERTEX:
         {
           gp_Pnt aPnt = BRep_Tool::Pnt(TopoDS::Vertex(aShape));
-          return myPlane.Distance(aPnt) < Precision::Confusion();
+          return aPlane.Distance(aPnt) < Precision::Confusion();
         }
       case TopAbs_EDGE:
         {
@@ -82,14 +86,17 @@ Standard_Boolean ModuleBase_ShapeInPlaneFilter::IsOk(const Handle(SelectMgr_Enti
           gp_Pnt aFirstPnt = aCurve->Value(aFirst);
           gp_Pnt aMidPnt = aCurve->Value((aFirst + aLast) / 2.);
           gp_Pnt aLastPnt = aCurve->Value(aLast);
-          bool aD1 = myPlane.Distance(aFirstPnt) < Precision::Confusion();
-          bool aD2 = myPlane.Distance(aMidPnt) < Precision::Confusion();
-          bool aD3 = myPlane.Distance(aLastPnt) < Precision::Confusion();
+          bool aD1 = aPlane.Distance(aFirstPnt) < Precision::Confusion();
+          bool aD2 = aPlane.Distance(aMidPnt) < Precision::Confusion();
+          bool aD3 = aPlane.Distance(aLastPnt) < Precision::Confusion();
           return aD1 && aD2 && aD3;
         }
       default:
         // This is not object controlled by the filter
         return Standard_True;
+        // The object can be selected in Object browser and contain, for example, compound.
+        // The compound could not belong to any plane, so the result is false
+        return Standard_False;
       break;
       }
     } else {
index a5d404ee81a84d850261c5a506c4244e8cd2b57e..9c1ad9b464973e32288ea31f7136740b338a1642 100644 (file)
@@ -12,7 +12,8 @@
 
 #include <SelectMgr_Filter.hxx>
 #include <SelectMgr_EntityOwner.hxx>
-#include <gp_Pln.hxx>
+
+#include <GeomAPI_Pln.h>
 
 
 class ModuleBase_IWorkshop;
@@ -60,10 +61,10 @@ public:
 
   /// Set working plane
   /// \param thePane plane object
-  void setPlane(const gp_Pln& thePane) { myPlane = thePane; }
+  void setPlane(const std::shared_ptr<GeomAPI_Pln>& thePlane) { myPlane = thePlane; }
 
   /// Returns current working plane
-  gp_Pln plane() const { return myPlane; }
+  std::shared_ptr<GeomAPI_Pln> plane() const { return myPlane; }
 
   /// Returns True if the given owner is acceptable for selection
   /// \param theOwner the selected owner
@@ -72,7 +73,7 @@ public:
   DEFINE_STANDARD_RTTI(ModuleBase_ShapeInPlaneFilter)
 private:
   /// Working plane
-  gp_Pln myPlane;
+  std::shared_ptr<GeomAPI_Pln> myPlane;
 };
 
 #endif
index 1385c097030fa9f7895880d1167e75811f4ce912..7bc472b75af7f53bd393582965de105d785fca5b 100644 (file)
@@ -743,14 +743,15 @@ void PartSet_SketcherMgr::startSketch(ModuleBase_Operation* theOperation)
   myModule->workshop()->viewer()->addSelectionFilter(myPlaneFilter);
 
   bool aHasPlane = false;
+  std::shared_ptr<GeomAPI_Pln> aPln;
   if (theOperation->isEditOperation()) {
     // If it is editing of sketch then it means that plane is already defined
-    std::shared_ptr<GeomAPI_Pln> aPln = PartSet_Tools::sketchPlane(myCurrentSketch);
-    if (aPln.get()) {
-      myPlaneFilter->setPlane(aPln->impl<gp_Pln>());
+    aPln = PartSet_Tools::sketchPlane(myCurrentSketch);
+    if (aPln.get())
       aHasPlane = true;
-    }
   }
+  myPlaneFilter->setPlane(aPln);
+
   Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
   // all sketch objects should be activated in the sketch selection modes by edit operation start
   // in case of creation operation, there is an active widget, which activates own selection mode
@@ -956,7 +957,7 @@ bool PartSet_SketcherMgr::isObjectOfSketch(const ObjectPtr& theObject) const
 
 void PartSet_SketcherMgr::onPlaneSelected(const std::shared_ptr<GeomAPI_Pln>& thePln)
 {
-  myPlaneFilter->setPlane(thePln->impl<gp_Pln>());
+  myPlaneFilter->setPlane(thePln);
 }
 
 void PartSet_SketcherMgr::getCurrentSelection(const FeaturePtr& theFeature,