Salome HOME
#2027 Sketcher Trim Feature: correction of compilation on Linux
[modules/shaper.git] / src / ModuleBase / ModuleBase_ViewerFilters.cpp
index 8ee95af0c03c8527e8b0081bc25bb9111ec29659..03d24a4693071b58352a3828cabaca3ca25f6a16 100644 (file)
 #include <ModelAPI_Document.h>
 #include <ModelAPI_ResultConstruction.h>
 
+#include <GeomAPI_Edge.h>
+
 #include <AIS_InteractiveObject.hxx>
 #include <AIS_Shape.hxx>
+#ifdef BEFORE_TRIHEDRON_PATCH
 #include <AIS_Axis.hxx>
 #include <AIS_Point.hxx>
 #include <AIS_Plane.hxx>
+#else
+#include <AIS_Trihedron.hxx>
+#include <AIS_TrihedronOwner.hxx>
+#include <Geom_Axis2Placement.hxx>
+#endif
 #include <Geom_Point.hxx>
 #include <Geom_Line.hxx>
 #include <Geom_Plane.hxx>
 #include <Geom_Curve.hxx>
 #include <gp_Pln.hxx>
 
-IMPLEMENT_STANDARD_HANDLE(ModuleBase_ShapeDocumentFilter, SelectMgr_Filter);
 IMPLEMENT_STANDARD_RTTIEXT(ModuleBase_ShapeDocumentFilter, SelectMgr_Filter);
 
 
 //TODO (VSV): Check bug in OCCT: Filter result is ignored (bug25340)
-Standard_Boolean ModuleBase_ShapeDocumentFilter::IsOk(const Handle(SelectMgr_EntityOwner)& theOwner) const
+Standard_Boolean ModuleBase_ShapeDocumentFilter::IsOk(
+                                            const Handle(SelectMgr_EntityOwner)& theOwner) const
 {
   bool aValid = true;
 
@@ -70,10 +78,10 @@ Standard_Boolean ModuleBase_ShapeDocumentFilter::IsOk(const Handle(SelectMgr_Ent
   return aValid;
 }
 
-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
+Standard_Boolean ModuleBase_ShapeInPlaneFilter::IsOk(
+                                        const Handle(SelectMgr_EntityOwner)& theOwner) const
 {
   bool aValid = true;
 
@@ -89,20 +97,13 @@ Standard_Boolean ModuleBase_ShapeInPlaneFilter::IsOk(const Handle(SelectMgr_Enti
         case TopAbs_VERTEX:
           {
             gp_Pnt aPnt = BRep_Tool::Pnt(TopoDS::Vertex(aShape));
-            return aPlane.Distance(aPnt) < Precision::Confusion();
+            return aPlane.SquareDistance(aPnt) < Precision::SquareConfusion();
           }
         case TopAbs_EDGE:
           {
-            TopoDS_Edge aEdge = TopoDS::Edge(aShape);
-            Standard_Real aFirst, aLast;
-            Handle(Geom_Curve) aCurve = BRep_Tool::Curve(aEdge, aFirst, aLast);
-            gp_Pnt aFirstPnt = aCurve->Value(aFirst);
-            gp_Pnt aMidPnt = aCurve->Value((aFirst + aLast) / 2.);
-            gp_Pnt aLastPnt = aCurve->Value(aLast);
-            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;
+            std::shared_ptr<GeomAPI_Edge> anEdge(new GeomAPI_Edge);
+            anEdge->setImpl<TopoDS_Shape>(new TopoDS_Shape(aShape));
+            return anEdge->isInPlane(myPlane);
           }
         default:
           // The object can be selected in Object browser and contain, for example, compound.
@@ -114,6 +115,7 @@ Standard_Boolean ModuleBase_ShapeInPlaneFilter::IsOk(const Handle(SelectMgr_Enti
         // Check Trihedron sub-objects
         Handle(SelectMgr_SelectableObject) aSelObj = theOwner->Selectable();
         Handle(Standard_Type) aType = aSelObj->DynamicType();
+#ifdef BEFORE_TRIHEDRON_PATCH
         if (aType == STANDARD_TYPE(AIS_Axis)) {
           Handle(AIS_Axis) aAxis = Handle(AIS_Axis)::DownCast(aSelObj);
           gp_Lin aLine = aAxis->Component()->Lin();
@@ -128,6 +130,30 @@ Standard_Boolean ModuleBase_ShapeInPlaneFilter::IsOk(const Handle(SelectMgr_Enti
           gp_Pln aPln = aAisPlane->Component()->Pln();
           return aPlane.Distance(aPln) < Precision::Confusion();
         }
+#else
+        if (aType == STANDARD_TYPE(AIS_Trihedron)) {
+          Handle(AIS_Trihedron) aTrihedron = Handle(AIS_Trihedron)::DownCast(aSelObj);
+          Handle(AIS_TrihedronOwner) aTrOwner = Handle(AIS_TrihedronOwner)::DownCast(theOwner);
+          if (!aTrOwner.IsNull())
+          {
+            const Prs3d_DatumParts& aPart = aTrOwner->DatumPart();
+            if (aPart >= Prs3d_DP_XAxis && aPart <= Prs3d_DP_ZAxis)
+            {
+              Handle(Prs3d_Drawer) aDrawer = aTrihedron->Attributes();
+              Handle(Prs3d_DatumAspect) aDatumAspect = aDrawer->DatumAspect();
+              Handle(Graphic3d_ArrayOfPrimitives) aPrimitives =
+                                                        aDatumAspect->ArrayOfPrimitives(aPart);
+              Standard_Real aX1, anY1, aZ1, aX2, anY2, aZ2;
+              aPrimitives->Vertice(1, aX1, anY1, aZ1);
+              aPrimitives->Vertice(2, aX2, anY2, aZ2);
+              gp_Pnt aPnt1(aX1, anY1, aZ1);
+              gp_Pnt aPnt2(aX2, anY2, aZ2);
+              gp_Lin aLine(aPnt1, gp_Dir(gp_Vec(aPnt1, aPnt2)));
+              return aPlane.Contains(aLine, Precision::Confusion(), Precision::Angular());
+            }
+          }
+        }
+#endif
         // This is not object controlled by the filter
         aValid = Standard_True;
       }