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 <GeomAPI_Edge.h>
18 #include <AIS_InteractiveObject.hxx>
19 #include <AIS_Shape.hxx>
20 #include <AIS_Axis.hxx>
21 #include <AIS_Point.hxx>
22 #include <AIS_Plane.hxx>
23 #include <Geom_Point.hxx>
24 #include <Geom_Line.hxx>
25 #include <Geom_Plane.hxx>
27 #include <StdSelect_BRepOwner.hxx>
29 #include <BRep_Tool.hxx>
31 #include <TopoDS_Edge.hxx>
32 #include <Geom_Curve.hxx>
35 IMPLEMENT_STANDARD_HANDLE(ModuleBase_ShapeDocumentFilter, SelectMgr_Filter);
36 IMPLEMENT_STANDARD_RTTIEXT(ModuleBase_ShapeDocumentFilter, SelectMgr_Filter);
39 //TODO (VSV): Check bug in OCCT: Filter result is ignored (bug25340)
40 Standard_Boolean ModuleBase_ShapeDocumentFilter::IsOk(
41 const Handle(SelectMgr_EntityOwner)& theOwner) const
45 ModuleBase_Operation* anOperation = myWorkshop->module()->currentOperation();
46 // the shapes from different documents should be provided if there is no started operation
47 // in order to show/hide results
49 aValid = Standard_False;
50 std::shared_ptr<GeomAPI_AISObject> aAISObj = AISObjectPtr(new GeomAPI_AISObject());
51 if (theOwner->HasSelectable()) {
52 Handle(AIS_InteractiveObject) aAisObj =
53 Handle(AIS_InteractiveObject)::DownCast(theOwner->Selectable());
54 if (!aAisObj.IsNull()) {
55 aAISObj->setImpl(new Handle(AIS_InteractiveObject)(aAisObj));
58 ObjectPtr aObj = myWorkshop->findPresentedObject(aAISObj);
60 DocumentPtr aDoc = aObj->document();
61 SessionPtr aMgr = ModelAPI_Session::get();
62 aValid = (aDoc == aMgr->activeDocument() || aDoc == aMgr->moduleDocument());
65 // This object is not controlled by the filter
66 aValid = Standard_True;
71 qDebug(QString("ModuleBase_ShapeDocumentFilter::IsOk = %1").arg(aValid).toStdString().c_str());
76 IMPLEMENT_STANDARD_HANDLE(ModuleBase_ShapeInPlaneFilter, SelectMgr_Filter);
77 IMPLEMENT_STANDARD_RTTIEXT(ModuleBase_ShapeInPlaneFilter, SelectMgr_Filter);
79 Standard_Boolean ModuleBase_ShapeInPlaneFilter::IsOk(
80 const Handle(SelectMgr_EntityOwner)& theOwner) const
85 aValid = Standard_False;
86 if (theOwner->HasSelectable()) {
87 gp_Pln aPlane = myPlane->impl<gp_Pln>();
88 Handle(StdSelect_BRepOwner) aShapeOwner = Handle(StdSelect_BRepOwner)::DownCast(theOwner);
89 if (!aShapeOwner.IsNull() && aShapeOwner->HasShape()) {
90 TopoDS_Shape aShape = aShapeOwner->Shape();
91 TopAbs_ShapeEnum aType = aShape.ShapeType();
95 gp_Pnt aPnt = BRep_Tool::Pnt(TopoDS::Vertex(aShape));
96 return aPlane.SquareDistance(aPnt) < Precision::SquareConfusion();
100 std::shared_ptr<GeomAPI_Edge> anEdge(new GeomAPI_Edge);
101 anEdge->setImpl<TopoDS_Shape>(new TopoDS_Shape(aShape));
102 return anEdge->isInPlane(myPlane);
105 // The object can be selected in Object browser and contain, for example, compound.
106 // The compound could not belong to any plane, so the result is false
107 aValid = Standard_False;
111 // Check Trihedron sub-objects
112 Handle(SelectMgr_SelectableObject) aSelObj = theOwner->Selectable();
113 Handle(Standard_Type) aType = aSelObj->DynamicType();
114 if (aType == STANDARD_TYPE(AIS_Axis)) {
115 Handle(AIS_Axis) aAxis = Handle(AIS_Axis)::DownCast(aSelObj);
116 gp_Lin aLine = aAxis->Component()->Lin();
117 return aPlane.Contains(aLine, Precision::Confusion(), Precision::Angular());
119 } else if (aType == STANDARD_TYPE(AIS_Point)) {
120 Handle(AIS_Point) aPoint = Handle(AIS_Point)::DownCast(aSelObj);
121 return aPlane.Distance(aPoint->Component()->Pnt()) < Precision::Confusion();
123 } else if (aType == STANDARD_TYPE(AIS_Plane)) {
124 Handle(AIS_Plane) aAisPlane = Handle(AIS_Plane)::DownCast(aSelObj);
125 gp_Pln aPln = aAisPlane->Component()->Pln();
126 return aPlane.Distance(aPln) < Precision::Confusion();
128 // This is not object controlled by the filter
129 aValid = Standard_True;
134 qDebug(QString("ModuleBase_ShapeDocumentFilter::IsOk = %1").arg(aValid).toStdString().c_str());