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>
11 #include <ModelAPI_ResultConstruction.h>
13 #include <AIS_InteractiveObject.hxx>
14 #include <AIS_Shape.hxx>
16 #include <StdSelect_BRepOwner.hxx>
18 #include <BRep_Tool.hxx>
20 #include <TopoDS_Edge.hxx>
21 #include <Geom_Curve.hxx>
23 IMPLEMENT_STANDARD_HANDLE(ModuleBase_ShapeDocumentFilter, SelectMgr_Filter);
24 IMPLEMENT_STANDARD_RTTIEXT(ModuleBase_ShapeDocumentFilter, SelectMgr_Filter);
27 //TODO (VSV): Check bug in OCCT: Filter result is ignored (bug25340)
28 Standard_Boolean ModuleBase_ShapeDocumentFilter::IsOk(const Handle(SelectMgr_EntityOwner)& theOwner) const
30 if (theOwner->HasSelectable()) {
31 Handle(AIS_InteractiveObject) aAisObj =
32 Handle(AIS_InteractiveObject)::DownCast(theOwner->Selectable());
33 if (!aAisObj.IsNull()) {
34 std::shared_ptr<GeomAPI_AISObject> aAISObj = AISObjectPtr(new GeomAPI_AISObject());
35 aAISObj->setImpl(new Handle(AIS_InteractiveObject)(aAisObj));
36 ObjectPtr aObj = myWorkshop->findPresentedObject(aAISObj);
38 DocumentPtr aDoc = aObj->document();
39 SessionPtr aMgr = ModelAPI_Session::get();
40 return (aDoc == aMgr->activeDocument() || aDoc == aMgr->moduleDocument());
43 // This is not object controlled by the filter
48 return Standard_False;
52 IMPLEMENT_STANDARD_HANDLE(ModuleBase_ShapeInPlaneFilter, SelectMgr_Filter);
53 IMPLEMENT_STANDARD_RTTIEXT(ModuleBase_ShapeInPlaneFilter, SelectMgr_Filter);
55 Standard_Boolean ModuleBase_ShapeInPlaneFilter::IsOk(const Handle(SelectMgr_EntityOwner)& theOwner) const
57 if (theOwner->HasSelectable()) {
58 Handle(StdSelect_BRepOwner) aShapeOwner = Handle(StdSelect_BRepOwner)::DownCast(theOwner);
59 if (!aShapeOwner.IsNull()) {
60 TopoDS_Shape aShape = aShapeOwner->Shape();
61 TopAbs_ShapeEnum aType = aShape.ShapeType();
65 gp_Pnt aPnt = BRep_Tool::Pnt(TopoDS::Vertex(aShape));
66 return myPlane.Distance(aPnt) < Precision::Confusion();
70 TopoDS_Edge aEdge = TopoDS::Edge(aShape);
71 Standard_Real aFirst, aLast;
72 Handle(Geom_Curve) aCurve = BRep_Tool::Curve(aEdge, aFirst, aLast);
73 gp_Pnt aFirstPnt = aCurve->Value(aFirst);
74 gp_Pnt aMidPnt = aCurve->Value((aFirst + aLast) / 2.);
75 gp_Pnt aLastPnt = aCurve->Value(aLast);
76 bool aD1 = myPlane.Distance(aFirstPnt) < Precision::Confusion();
77 bool aD2 = myPlane.Distance(aMidPnt) < Precision::Confusion();
78 bool aD3 = myPlane.Distance(aLastPnt) < Precision::Confusion();
79 return aD1 && aD2 && aD3;
82 // This is not object controlled by the filter
87 // This is not object controlled by the filter
91 return Standard_False;
95 IMPLEMENT_STANDARD_HANDLE(ModuleBase_ObjectTypesFilter, SelectMgr_Filter);
96 IMPLEMENT_STANDARD_RTTIEXT(ModuleBase_ObjectTypesFilter, SelectMgr_Filter);
99 //TODO (VSV): Check bug in OCCT: Filter result is ignored (bug25340)
100 Standard_Boolean ModuleBase_ObjectTypesFilter::IsOk(const Handle(SelectMgr_EntityOwner)& theOwner) const
102 Standard_Boolean isOk = ModuleBase_ShapeDocumentFilter::IsOk(theOwner);
103 if (isOk && theOwner->HasSelectable()) {
104 Handle(AIS_InteractiveObject) aAisObj =
105 Handle(AIS_InteractiveObject)::DownCast(theOwner->Selectable());
106 if (!aAisObj.IsNull()) {
107 std::shared_ptr<GeomAPI_AISObject> aAISObj = AISObjectPtr(new GeomAPI_AISObject());
108 aAISObj->setImpl(new Handle(AIS_InteractiveObject)(aAisObj));
109 ObjectPtr aObj = myWorkshop->findPresentedObject(aAISObj);
111 foreach (QString aType, myTypes) {
112 if (aType.toLower() == "construction") {
113 ResultConstructionPtr aConstr =
114 std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(aObj);
115 return (aConstr != NULL);
116 } // ToDo: Process other types of objects
120 return Standard_False;