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_RTTIEXT(ModuleBase_ShapeDocumentFilter, SelectMgr_Filter);
38 //TODO (VSV): Check bug in OCCT: Filter result is ignored (bug25340)
39 Standard_Boolean ModuleBase_ShapeDocumentFilter::IsOk(
40 const Handle(SelectMgr_EntityOwner)& theOwner) const
44 ModuleBase_Operation* anOperation = myWorkshop->module()->currentOperation();
45 // the shapes from different documents should be provided if there is no started operation
46 // in order to show/hide results
48 aValid = Standard_False;
49 std::shared_ptr<GeomAPI_AISObject> aAISObj = AISObjectPtr(new GeomAPI_AISObject());
50 if (theOwner->HasSelectable()) {
51 Handle(AIS_InteractiveObject) aAisObj =
52 Handle(AIS_InteractiveObject)::DownCast(theOwner->Selectable());
53 if (!aAisObj.IsNull()) {
54 aAISObj->setImpl(new Handle(AIS_InteractiveObject)(aAisObj));
57 ObjectPtr aObj = myWorkshop->findPresentedObject(aAISObj);
59 DocumentPtr aDoc = aObj->document();
60 SessionPtr aMgr = ModelAPI_Session::get();
61 aValid = (aDoc == aMgr->activeDocument() || aDoc == aMgr->moduleDocument());
64 // This object is not controlled by the filter
65 aValid = Standard_True;
70 qDebug(QString("ModuleBase_ShapeDocumentFilter::IsOk = %1").arg(aValid).toStdString().c_str());
75 IMPLEMENT_STANDARD_RTTIEXT(ModuleBase_ShapeInPlaneFilter, SelectMgr_Filter);
77 Standard_Boolean ModuleBase_ShapeInPlaneFilter::IsOk(
78 const Handle(SelectMgr_EntityOwner)& theOwner) const
83 aValid = Standard_False;
84 if (theOwner->HasSelectable()) {
85 gp_Pln aPlane = myPlane->impl<gp_Pln>();
86 Handle(StdSelect_BRepOwner) aShapeOwner = Handle(StdSelect_BRepOwner)::DownCast(theOwner);
87 if (!aShapeOwner.IsNull() && aShapeOwner->HasShape()) {
88 TopoDS_Shape aShape = aShapeOwner->Shape();
89 TopAbs_ShapeEnum aType = aShape.ShapeType();
93 gp_Pnt aPnt = BRep_Tool::Pnt(TopoDS::Vertex(aShape));
94 return aPlane.SquareDistance(aPnt) < Precision::SquareConfusion();
98 std::shared_ptr<GeomAPI_Edge> anEdge(new GeomAPI_Edge);
99 anEdge->setImpl<TopoDS_Shape>(new TopoDS_Shape(aShape));
100 return anEdge->isInPlane(myPlane);
103 // The object can be selected in Object browser and contain, for example, compound.
104 // The compound could not belong to any plane, so the result is false
105 aValid = Standard_False;
109 // Check Trihedron sub-objects
110 Handle(SelectMgr_SelectableObject) aSelObj = theOwner->Selectable();
111 Handle(Standard_Type) aType = aSelObj->DynamicType();
112 if (aType == STANDARD_TYPE(AIS_Axis)) {
113 Handle(AIS_Axis) aAxis = Handle(AIS_Axis)::DownCast(aSelObj);
114 gp_Lin aLine = aAxis->Component()->Lin();
115 return aPlane.Contains(aLine, Precision::Confusion(), Precision::Angular());
117 } else if (aType == STANDARD_TYPE(AIS_Point)) {
118 Handle(AIS_Point) aPoint = Handle(AIS_Point)::DownCast(aSelObj);
119 return aPlane.Distance(aPoint->Component()->Pnt()) < Precision::Confusion();
121 } else if (aType == STANDARD_TYPE(AIS_Plane)) {
122 Handle(AIS_Plane) aAisPlane = Handle(AIS_Plane)::DownCast(aSelObj);
123 gp_Pln aPln = aAisPlane->Component()->Pln();
124 return aPlane.Distance(aPln) < Precision::Confusion();
126 // This is not object controlled by the filter
127 aValid = Standard_True;
132 qDebug(QString("ModuleBase_ShapeDocumentFilter::IsOk = %1").arg(aValid).toStdString().c_str());