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 boost::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());
44 return Standard_False;
48 IMPLEMENT_STANDARD_HANDLE(ModuleBase_ShapeInPlaneFilter, SelectMgr_Filter);
49 IMPLEMENT_STANDARD_RTTIEXT(ModuleBase_ShapeInPlaneFilter, SelectMgr_Filter);
51 Standard_Boolean ModuleBase_ShapeInPlaneFilter::IsOk(const Handle(SelectMgr_EntityOwner)& theOwner) const
53 if (theOwner->HasSelectable()) {
54 Handle(StdSelect_BRepOwner) aShapeOwner = Handle(StdSelect_BRepOwner)::DownCast(theOwner);
55 if (!aShapeOwner.IsNull()) {
56 TopoDS_Shape aShape = aShapeOwner->Shape();
57 TopAbs_ShapeEnum aType = aShape.ShapeType();
61 gp_Pnt aPnt = BRep_Tool::Pnt(TopoDS::Vertex(aShape));
62 return myPlane.Distance(aPnt) < Precision::Confusion();
66 TopoDS_Edge aEdge = TopoDS::Edge(aShape);
67 Standard_Real aFirst, aLast;
68 Handle(Geom_Curve) aCurve = BRep_Tool::Curve(aEdge, aFirst, aLast);
69 gp_Pnt aFirstPnt = aCurve->Value(aFirst);
70 gp_Pnt aMidPnt = aCurve->Value((aFirst + aLast) / 2.);
71 gp_Pnt aLastPnt = aCurve->Value(aLast);
72 bool aD1 = myPlane.Distance(aFirstPnt) < Precision::Confusion();
73 bool aD2 = myPlane.Distance(aMidPnt) < Precision::Confusion();
74 bool aD3 = myPlane.Distance(aLastPnt) < Precision::Confusion();
75 return aD1 && aD2 && aD3;
79 // This is not object controlled by the filter
83 return Standard_False;
87 IMPLEMENT_STANDARD_HANDLE(ModuleBase_ObjectTypesFilter, SelectMgr_Filter);
88 IMPLEMENT_STANDARD_RTTIEXT(ModuleBase_ObjectTypesFilter, SelectMgr_Filter);
91 //TODO (VSV): Check bug in OCCT: Filter result is ignored (bug25340)
92 Standard_Boolean ModuleBase_ObjectTypesFilter::IsOk(const Handle(SelectMgr_EntityOwner)& theOwner) const
94 Standard_Boolean isOk = ModuleBase_ShapeDocumentFilter::IsOk(theOwner);
95 if (isOk && theOwner->HasSelectable()) {
96 Handle(AIS_InteractiveObject) aAisObj =
97 Handle(AIS_InteractiveObject)::DownCast(theOwner->Selectable());
98 if (!aAisObj.IsNull()) {
99 boost::shared_ptr<GeomAPI_AISObject> aAISObj = AISObjectPtr(new GeomAPI_AISObject());
100 aAISObj->setImpl(new Handle(AIS_InteractiveObject)(aAisObj));
101 ObjectPtr aObj = myWorkshop->findPresentedObject(aAISObj);
103 foreach (QString aType, myTypes) {
104 if (aType.toLower() == "construction") {
105 ResultConstructionPtr aConstr =
106 boost::dynamic_pointer_cast<ModelAPI_ResultConstruction>(aObj);
107 return (aConstr != NULL);
108 } // ToDo: Process other types of objects
112 return Standard_False;