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>
18 #include <AIS_Axis.hxx>
19 #include <AIS_Point.hxx>
20 #include <AIS_Plane.hxx>
21 #include <Geom_Point.hxx>
22 #include <Geom_Line.hxx>
23 #include <Geom_Plane.hxx>
25 #include <StdSelect_BRepOwner.hxx>
27 #include <BRep_Tool.hxx>
29 #include <TopoDS_Edge.hxx>
30 #include <Geom_Curve.hxx>
33 IMPLEMENT_STANDARD_HANDLE(ModuleBase_ShapeDocumentFilter, SelectMgr_Filter);
34 IMPLEMENT_STANDARD_RTTIEXT(ModuleBase_ShapeDocumentFilter, SelectMgr_Filter);
37 //TODO (VSV): Check bug in OCCT: Filter result is ignored (bug25340)
38 Standard_Boolean ModuleBase_ShapeDocumentFilter::IsOk(const Handle(SelectMgr_EntityOwner)& theOwner) const
42 ModuleBase_Operation* anOperation = myWorkshop->module()->currentOperation();
43 // the shapes from different documents should be provided if there is no started operation
44 // in order to show/hide results
46 aValid = Standard_False;
47 std::shared_ptr<GeomAPI_AISObject> aAISObj = AISObjectPtr(new GeomAPI_AISObject());
48 if (theOwner->HasSelectable()) {
49 Handle(AIS_InteractiveObject) aAisObj =
50 Handle(AIS_InteractiveObject)::DownCast(theOwner->Selectable());
51 if (!aAisObj.IsNull()) {
52 aAISObj->setImpl(new Handle(AIS_InteractiveObject)(aAisObj));
55 ObjectPtr aObj = myWorkshop->findPresentedObject(aAISObj);
57 DocumentPtr aDoc = aObj->document();
58 SessionPtr aMgr = ModelAPI_Session::get();
59 aValid = (aDoc == aMgr->activeDocument() || aDoc == aMgr->moduleDocument());
62 // This object is not controlled by the filter
63 aValid = Standard_True;
68 qDebug(QString("ModuleBase_ShapeDocumentFilter::IsOk = %1").arg(aValid).toStdString().c_str());
73 IMPLEMENT_STANDARD_HANDLE(ModuleBase_ShapeInPlaneFilter, SelectMgr_Filter);
74 IMPLEMENT_STANDARD_RTTIEXT(ModuleBase_ShapeInPlaneFilter, SelectMgr_Filter);
76 Standard_Boolean ModuleBase_ShapeInPlaneFilter::IsOk(const Handle(SelectMgr_EntityOwner)& theOwner) const
81 aValid = Standard_False;
82 if (theOwner->HasSelectable()) {
83 gp_Pln aPlane = myPlane->impl<gp_Pln>();
84 Handle(StdSelect_BRepOwner) aShapeOwner = Handle(StdSelect_BRepOwner)::DownCast(theOwner);
85 if (!aShapeOwner.IsNull() && aShapeOwner->HasShape()) {
86 TopoDS_Shape aShape = aShapeOwner->Shape();
87 TopAbs_ShapeEnum aType = aShape.ShapeType();
91 gp_Pnt aPnt = BRep_Tool::Pnt(TopoDS::Vertex(aShape));
92 return aPlane.Distance(aPnt) < Precision::Confusion();
96 TopoDS_Edge aEdge = TopoDS::Edge(aShape);
97 Standard_Real aFirst, aLast;
98 Handle(Geom_Curve) aCurve = BRep_Tool::Curve(aEdge, aFirst, aLast);
99 gp_Pnt aFirstPnt = aCurve->Value(aFirst);
100 gp_Pnt aMidPnt = aCurve->Value((aFirst + aLast) / 2.);
101 gp_Pnt aLastPnt = aCurve->Value(aLast);
102 bool aD1 = aPlane.Distance(aFirstPnt) < Precision::Confusion();
103 bool aD2 = aPlane.Distance(aMidPnt) < Precision::Confusion();
104 bool aD3 = aPlane.Distance(aLastPnt) < Precision::Confusion();
105 return aD1 && aD2 && aD3;
108 // The object can be selected in Object browser and contain, for example, compound.
109 // The compound could not belong to any plane, so the result is false
110 aValid = Standard_False;
114 // Check Trihedron sub-objects
115 Handle(SelectMgr_SelectableObject) aSelObj = theOwner->Selectable();
116 Handle(Standard_Type) aType = aSelObj->DynamicType();
117 if (aType == STANDARD_TYPE(AIS_Axis)) {
118 Handle(AIS_Axis) aAxis = Handle(AIS_Axis)::DownCast(aSelObj);
119 gp_Lin aLine = aAxis->Component()->Lin();
120 return aPlane.Contains(aLine, Precision::Confusion(), Precision::Angular());
122 } else if (aType == STANDARD_TYPE(AIS_Point)) {
123 Handle(AIS_Point) aPoint = Handle(AIS_Point)::DownCast(aSelObj);
124 return aPlane.Distance(aPoint->Component()->Pnt()) < Precision::Confusion();
126 } else if (aType == STANDARD_TYPE(AIS_Plane)) {
127 Handle(AIS_Plane) aAisPlane = Handle(AIS_Plane)::DownCast(aSelObj);
128 gp_Pln aPln = aAisPlane->Component()->Pln();
129 return aPlane.Distance(aPln) < Precision::Confusion();
131 // This is not object controlled by the filter
132 aValid = Standard_True;
137 qDebug(QString("ModuleBase_ShapeDocumentFilter::IsOk = %1").arg(aValid).toStdString().c_str());