1 // File: ModuleBase_ViewerFilters.cpp
2 // Created: 07 Okt 2014
3 // Author: Vitaly SMETANNIKOV
6 #include "ModuleBase_ViewerFilters.h"
7 #include "ModuleBase_IWorkshop.h"
9 #include <ModelAPI_Session.h>
10 #include <ModelAPI_Document.h>
12 #include <AIS_InteractiveObject.hxx>
13 #include <AIS_Shape.hxx>
15 #include <StdSelect_BRepOwner.hxx>
17 #include <BRep_Tool.hxx>
19 #include <TopoDS_Edge.hxx>
20 #include <Geom_Curve.hxx>
22 IMPLEMENT_STANDARD_HANDLE(ModuleBase_ShapeDocumentFilter, SelectMgr_Filter);
23 IMPLEMENT_STANDARD_RTTIEXT(ModuleBase_ShapeDocumentFilter, SelectMgr_Filter);
26 //TODO (VSV): Check bug in OCCT: Filter result is ignored (bug25340)
27 Standard_Boolean ModuleBase_ShapeDocumentFilter::IsOk(const Handle(SelectMgr_EntityOwner)& theOwner) const
29 if (theOwner->HasSelectable()) {
30 Handle(AIS_InteractiveObject) aAisObj =
31 Handle(AIS_InteractiveObject)::DownCast(theOwner->Selectable());
32 if (!aAisObj.IsNull()) {
33 boost::shared_ptr<GeomAPI_AISObject> aAISObj = AISObjectPtr(new GeomAPI_AISObject());
34 aAISObj->setImpl(new Handle(AIS_InteractiveObject)(aAisObj));
35 ObjectPtr aObj = myWorkshop->findPresentedObject(aAISObj);
37 DocumentPtr aDoc = aObj->document();
38 SessionPtr aMgr = ModelAPI_Session::get();
39 return (aDoc == aMgr->activeDocument()) || (aDoc == aMgr->moduleDocument());
43 return Standard_False;
47 IMPLEMENT_STANDARD_HANDLE(ModuleBase_ShapeInPlaneFilter, SelectMgr_Filter);
48 IMPLEMENT_STANDARD_RTTIEXT(ModuleBase_ShapeInPlaneFilter, SelectMgr_Filter);
50 Standard_Boolean ModuleBase_ShapeInPlaneFilter::IsOk(const Handle(SelectMgr_EntityOwner)& theOwner) const
52 if (theOwner->HasSelectable()) {
53 Handle(StdSelect_BRepOwner) aShapeOwner = Handle(StdSelect_BRepOwner)::DownCast(theOwner);
54 if (!aShapeOwner.IsNull()) {
55 TopoDS_Shape aShape = aShapeOwner->Shape();
56 TopAbs_ShapeEnum aType = aShape.ShapeType();
60 gp_Pnt aPnt = BRep_Tool::Pnt(TopoDS::Vertex(aShape));
61 return myPlane.Distance(aPnt) < Precision::Confusion();
65 TopoDS_Edge aEdge = TopoDS::Edge(aShape);
66 Standard_Real aFirst, aLast;
67 Handle(Geom_Curve) aCurve = BRep_Tool::Curve(aEdge, aFirst, aLast);
68 gp_Pnt aFirstPnt = aCurve->Value(aFirst);
69 gp_Pnt aMidPnt = aCurve->Value((aFirst + aLast) / 2.);
70 gp_Pnt aLastPnt = aCurve->Value(aLast);
71 bool aD1 = myPlane.Distance(aFirstPnt) < Precision::Confusion();
72 bool aD2 = myPlane.Distance(aMidPnt) < Precision::Confusion();
73 bool aD3 = myPlane.Distance(aLastPnt) < Precision::Confusion();
74 return aD1 && aD2 && aD3;
78 // This is not object controlled by the filter
82 return Standard_False;