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 #ifdef BEFORE_TRIHEDRON_PATCH
21 #include <AIS_Axis.hxx>
22 #include <AIS_Point.hxx>
23 #include <AIS_Plane.hxx>
25 #include <AIS_Trihedron.hxx>
26 #include <AIS_TrihedronOwner.hxx>
27 #include <Geom_Axis2Placement.hxx>
29 #include <Geom_Point.hxx>
30 #include <Geom_Line.hxx>
31 #include <Geom_Plane.hxx>
33 #include <StdSelect_BRepOwner.hxx>
35 #include <BRep_Tool.hxx>
37 #include <TopoDS_Edge.hxx>
38 #include <Geom_Curve.hxx>
41 IMPLEMENT_STANDARD_RTTIEXT(ModuleBase_ShapeDocumentFilter, SelectMgr_Filter);
44 //TODO (VSV): Check bug in OCCT: Filter result is ignored (bug25340)
45 Standard_Boolean ModuleBase_ShapeDocumentFilter::IsOk(
46 const Handle(SelectMgr_EntityOwner)& theOwner) const
50 ModuleBase_Operation* anOperation = myWorkshop->module()->currentOperation();
51 // the shapes from different documents should be provided if there is no started operation
52 // in order to show/hide results
54 aValid = Standard_False;
55 std::shared_ptr<GeomAPI_AISObject> aAISObj = AISObjectPtr(new GeomAPI_AISObject());
56 if (theOwner->HasSelectable()) {
57 Handle(AIS_InteractiveObject) aAisObj =
58 Handle(AIS_InteractiveObject)::DownCast(theOwner->Selectable());
59 if (!aAisObj.IsNull()) {
60 aAISObj->setImpl(new Handle(AIS_InteractiveObject)(aAisObj));
63 ObjectPtr aObj = myWorkshop->findPresentedObject(aAISObj);
65 DocumentPtr aDoc = aObj->document();
66 SessionPtr aMgr = ModelAPI_Session::get();
67 aValid = (aDoc == aMgr->activeDocument() || aDoc == aMgr->moduleDocument());
70 // This object is not controlled by the filter
71 aValid = Standard_True;
76 qDebug(QString("ModuleBase_ShapeDocumentFilter::IsOk = %1").arg(aValid).toStdString().c_str());
81 IMPLEMENT_STANDARD_RTTIEXT(ModuleBase_ShapeInPlaneFilter, SelectMgr_Filter);
83 Standard_Boolean ModuleBase_ShapeInPlaneFilter::IsOk(
84 const Handle(SelectMgr_EntityOwner)& theOwner) const
89 aValid = Standard_False;
90 if (theOwner->HasSelectable()) {
91 gp_Pln aPlane = myPlane->impl<gp_Pln>();
92 Handle(StdSelect_BRepOwner) aShapeOwner = Handle(StdSelect_BRepOwner)::DownCast(theOwner);
93 if (!aShapeOwner.IsNull() && aShapeOwner->HasShape()) {
94 TopoDS_Shape aShape = aShapeOwner->Shape();
95 TopAbs_ShapeEnum aType = aShape.ShapeType();
99 gp_Pnt aPnt = BRep_Tool::Pnt(TopoDS::Vertex(aShape));
100 return aPlane.SquareDistance(aPnt) < Precision::SquareConfusion();
104 std::shared_ptr<GeomAPI_Edge> anEdge(new GeomAPI_Edge);
105 anEdge->setImpl<TopoDS_Shape>(new TopoDS_Shape(aShape));
106 return anEdge->isInPlane(myPlane);
109 // The object can be selected in Object browser and contain, for example, compound.
110 // The compound could not belong to any plane, so the result is false
111 aValid = Standard_False;
115 // Check Trihedron sub-objects
116 Handle(SelectMgr_SelectableObject) aSelObj = theOwner->Selectable();
117 Handle(Standard_Type) aType = aSelObj->DynamicType();
118 #ifdef BEFORE_TRIHEDRON_PATCH
119 if (aType == STANDARD_TYPE(AIS_Axis)) {
120 Handle(AIS_Axis) aAxis = Handle(AIS_Axis)::DownCast(aSelObj);
121 gp_Lin aLine = aAxis->Component()->Lin();
122 return aPlane.Contains(aLine, Precision::Confusion(), Precision::Angular());
124 } else if (aType == STANDARD_TYPE(AIS_Point)) {
125 Handle(AIS_Point) aPoint = Handle(AIS_Point)::DownCast(aSelObj);
126 return aPlane.Distance(aPoint->Component()->Pnt()) < Precision::Confusion();
128 } else if (aType == STANDARD_TYPE(AIS_Plane)) {
129 Handle(AIS_Plane) aAisPlane = Handle(AIS_Plane)::DownCast(aSelObj);
130 gp_Pln aPln = aAisPlane->Component()->Pln();
131 return aPlane.Distance(aPln) < Precision::Confusion();
134 if (aType == STANDARD_TYPE(AIS_Trihedron)) {
135 Handle(AIS_Trihedron) aTrihedron = Handle(AIS_Trihedron)::DownCast(aSelObj);
136 Handle(AIS_TrihedronOwner) aTrOwner = Handle(AIS_TrihedronOwner)::DownCast(theOwner);
137 if (!aTrOwner.IsNull())
139 const Prs3d_DatumParts& aPart = aTrOwner->DatumPart();
140 if (aPart >= Prs3d_DP_XAxis && aPart <= Prs3d_DP_ZAxis)
142 Handle(Prs3d_Drawer) aDrawer = aTrihedron->Attributes();
143 Handle(Prs3d_DatumAspect) aDatumAspect = aDrawer->DatumAspect();
144 Handle(Graphic3d_ArrayOfPrimitives) aPrimitives =
145 aDatumAspect->ArrayOfPrimitives(aPart);
146 Standard_Real aX1, anY1, aZ1, aX2, anY2, aZ2;
147 aPrimitives->Vertice(1, aX1, anY1, aZ1);
148 aPrimitives->Vertice(2, aX2, anY2, aZ2);
149 gp_Pnt aPnt1(aX1, anY1, aZ1);
150 gp_Pnt aPnt2(aX2, anY2, aZ2);
151 gp_Lin aLine(aPnt1, gp_Dir(gp_Vec(aPnt1, aPnt2)));
152 return aPlane.Contains(aLine, Precision::Confusion(), Precision::Angular());
157 // This is not object controlled by the filter
158 aValid = Standard_True;
163 qDebug(QString("ModuleBase_ShapeDocumentFilter::IsOk = %1").arg(aValid).toStdString().c_str());