1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
3 // File: ModuleBase_ViewerFilters.cpp
4 // Created: 07 Okt 2014
5 // Author: Vitaly SMETANNIKOV
8 #include "ModuleBase_ViewerFilters.h"
9 #include "ModuleBase_IWorkshop.h"
11 #include <ModelAPI_Session.h>
12 #include <ModelAPI_Document.h>
13 #include <ModelAPI_ResultConstruction.h>
15 #include <AIS_InteractiveObject.hxx>
16 #include <AIS_Shape.hxx>
18 #include <StdSelect_BRepOwner.hxx>
20 #include <BRep_Tool.hxx>
22 #include <TopoDS_Edge.hxx>
23 #include <Geom_Curve.hxx>
25 IMPLEMENT_STANDARD_HANDLE(ModuleBase_ShapeDocumentFilter, SelectMgr_Filter);
26 IMPLEMENT_STANDARD_RTTIEXT(ModuleBase_ShapeDocumentFilter, SelectMgr_Filter);
29 //TODO (VSV): Check bug in OCCT: Filter result is ignored (bug25340)
30 Standard_Boolean ModuleBase_ShapeDocumentFilter::IsOk(const Handle(SelectMgr_EntityOwner)& theOwner) const
32 if (theOwner->HasSelectable()) {
33 Handle(AIS_InteractiveObject) aAisObj =
34 Handle(AIS_InteractiveObject)::DownCast(theOwner->Selectable());
35 if (!aAisObj.IsNull()) {
36 std::shared_ptr<GeomAPI_AISObject> aAISObj = AISObjectPtr(new GeomAPI_AISObject());
37 aAISObj->setImpl(new Handle(AIS_InteractiveObject)(aAisObj));
38 ObjectPtr aObj = myWorkshop->findPresentedObject(aAISObj);
40 DocumentPtr aDoc = aObj->document();
41 SessionPtr aMgr = ModelAPI_Session::get();
42 return (aDoc == aMgr->activeDocument() || aDoc == aMgr->moduleDocument());
45 // This is not object controlled by the filter
50 return Standard_False;
54 IMPLEMENT_STANDARD_HANDLE(ModuleBase_ShapeInPlaneFilter, SelectMgr_Filter);
55 IMPLEMENT_STANDARD_RTTIEXT(ModuleBase_ShapeInPlaneFilter, SelectMgr_Filter);
57 Standard_Boolean ModuleBase_ShapeInPlaneFilter::IsOk(const Handle(SelectMgr_EntityOwner)& theOwner) const
59 if (theOwner->HasSelectable()) {
60 Handle(StdSelect_BRepOwner) aShapeOwner = Handle(StdSelect_BRepOwner)::DownCast(theOwner);
61 if (!aShapeOwner.IsNull()) {
62 TopoDS_Shape aShape = aShapeOwner->Shape();
63 TopAbs_ShapeEnum aType = aShape.ShapeType();
67 gp_Pnt aPnt = BRep_Tool::Pnt(TopoDS::Vertex(aShape));
68 return myPlane.Distance(aPnt) < Precision::Confusion();
72 TopoDS_Edge aEdge = TopoDS::Edge(aShape);
73 Standard_Real aFirst, aLast;
74 Handle(Geom_Curve) aCurve = BRep_Tool::Curve(aEdge, aFirst, aLast);
75 gp_Pnt aFirstPnt = aCurve->Value(aFirst);
76 gp_Pnt aMidPnt = aCurve->Value((aFirst + aLast) / 2.);
77 gp_Pnt aLastPnt = aCurve->Value(aLast);
78 bool aD1 = myPlane.Distance(aFirstPnt) < Precision::Confusion();
79 bool aD2 = myPlane.Distance(aMidPnt) < Precision::Confusion();
80 bool aD3 = myPlane.Distance(aLastPnt) < Precision::Confusion();
81 return aD1 && aD2 && aD3;
84 // This is not object controlled by the filter
89 // This is not object controlled by the filter
93 return Standard_False;
97 IMPLEMENT_STANDARD_HANDLE(ModuleBase_ObjectTypesFilter, SelectMgr_Filter);
98 IMPLEMENT_STANDARD_RTTIEXT(ModuleBase_ObjectTypesFilter, SelectMgr_Filter);
101 //TODO (VSV): Check bug in OCCT: Filter result is ignored (bug25340)
102 Standard_Boolean ModuleBase_ObjectTypesFilter::IsOk(const Handle(SelectMgr_EntityOwner)& theOwner) const
104 Standard_Boolean isOk = ModuleBase_ShapeDocumentFilter::IsOk(theOwner);
105 if (isOk && theOwner->HasSelectable()) {
106 Handle(AIS_InteractiveObject) aAisObj =
107 Handle(AIS_InteractiveObject)::DownCast(theOwner->Selectable());
108 if (!aAisObj.IsNull()) {
109 std::shared_ptr<GeomAPI_AISObject> aAISObj = AISObjectPtr(new GeomAPI_AISObject());
110 aAISObj->setImpl(new Handle(AIS_InteractiveObject)(aAisObj));
111 ObjectPtr aObj = myWorkshop->findPresentedObject(aAISObj);
113 foreach (QString aType, myTypes) {
114 if (aType.toLower() == "construction") {
115 ResultConstructionPtr aConstr =
116 std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(aObj);
117 return (aConstr != NULL);
118 } // ToDo: Process other types of objects
122 return Standard_False;