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"
10 #include "ModuleBase_IModule.h"
12 #include <ModelAPI_Session.h>
13 #include <ModelAPI_Document.h>
14 #include <ModelAPI_ResultConstruction.h>
16 #include <AIS_InteractiveObject.hxx>
17 #include <AIS_Shape.hxx>
19 #include <StdSelect_BRepOwner.hxx>
21 #include <BRep_Tool.hxx>
23 #include <TopoDS_Edge.hxx>
24 #include <Geom_Curve.hxx>
26 IMPLEMENT_STANDARD_HANDLE(ModuleBase_ShapeDocumentFilter, SelectMgr_Filter);
27 IMPLEMENT_STANDARD_RTTIEXT(ModuleBase_ShapeDocumentFilter, SelectMgr_Filter);
30 //TODO (VSV): Check bug in OCCT: Filter result is ignored (bug25340)
31 Standard_Boolean ModuleBase_ShapeDocumentFilter::IsOk(const Handle(SelectMgr_EntityOwner)& theOwner) const
33 ModuleBase_Operation* anOperation = myWorkshop->module()->currentOperation();
34 // the shapes from different documents should be provided if there is no started operation
35 // in order to show/hide results
39 if (theOwner->HasSelectable()) {
40 Handle(AIS_InteractiveObject) aAisObj =
41 Handle(AIS_InteractiveObject)::DownCast(theOwner->Selectable());
42 if (!aAisObj.IsNull()) {
43 std::shared_ptr<GeomAPI_AISObject> aAISObj = AISObjectPtr(new GeomAPI_AISObject());
44 aAISObj->setImpl(new Handle(AIS_InteractiveObject)(aAisObj));
45 ObjectPtr aObj = myWorkshop->findPresentedObject(aAISObj);
47 DocumentPtr aDoc = aObj->document();
48 SessionPtr aMgr = ModelAPI_Session::get();
49 return (aDoc == aMgr->activeDocument() || aDoc == aMgr->moduleDocument());
52 // This is not object controlled by the filter
57 return Standard_False;
61 IMPLEMENT_STANDARD_HANDLE(ModuleBase_ShapeInPlaneFilter, SelectMgr_Filter);
62 IMPLEMENT_STANDARD_RTTIEXT(ModuleBase_ShapeInPlaneFilter, SelectMgr_Filter);
64 Standard_Boolean ModuleBase_ShapeInPlaneFilter::IsOk(const Handle(SelectMgr_EntityOwner)& theOwner) const
66 if (theOwner->HasSelectable()) {
67 Handle(StdSelect_BRepOwner) aShapeOwner = Handle(StdSelect_BRepOwner)::DownCast(theOwner);
68 if (!aShapeOwner.IsNull()) {
69 TopoDS_Shape aShape = aShapeOwner->Shape();
70 TopAbs_ShapeEnum aType = aShape.ShapeType();
74 gp_Pnt aPnt = BRep_Tool::Pnt(TopoDS::Vertex(aShape));
75 return myPlane.Distance(aPnt) < Precision::Confusion();
79 TopoDS_Edge aEdge = TopoDS::Edge(aShape);
80 Standard_Real aFirst, aLast;
81 Handle(Geom_Curve) aCurve = BRep_Tool::Curve(aEdge, aFirst, aLast);
82 gp_Pnt aFirstPnt = aCurve->Value(aFirst);
83 gp_Pnt aMidPnt = aCurve->Value((aFirst + aLast) / 2.);
84 gp_Pnt aLastPnt = aCurve->Value(aLast);
85 bool aD1 = myPlane.Distance(aFirstPnt) < Precision::Confusion();
86 bool aD2 = myPlane.Distance(aMidPnt) < Precision::Confusion();
87 bool aD3 = myPlane.Distance(aLastPnt) < Precision::Confusion();
88 return aD1 && aD2 && aD3;
91 // This is not object controlled by the filter
96 // This is not object controlled by the filter
100 return Standard_False;