1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
3 // File: PartSet_Filters.cpp
4 // Created: 19 Jun 2015
5 // Author: Natalia ERMOLAEVA
7 #include "PartSet_FilterInfinite.h"
9 #include <ModuleBase_IWorkshop.h>
10 #include <ModuleBase_ISelection.h>
11 #include <ModelAPI_ResultConstruction.h>
13 #include <AIS_InteractiveObject.hxx>
14 #include <AIS_Shape.hxx>
15 #include <TopoDS_Shape.hxx>
16 #include <StdSelect_BRepOwner.hxx>
18 IMPLEMENT_STANDARD_HANDLE(PartSet_FilterInfinite, SelectMgr_Filter);
19 IMPLEMENT_STANDARD_RTTIEXT(PartSet_FilterInfinite, SelectMgr_Filter);
21 PartSet_FilterInfinite::PartSet_FilterInfinite(ModuleBase_IWorkshop* theWorkshop)
22 : SelectMgr_Filter(), myWorkshop(theWorkshop)
26 Standard_Boolean PartSet_FilterInfinite::IsOk(const Handle(SelectMgr_EntityOwner)& theOwner) const
28 Standard_Boolean aValid = Standard_True;
30 ModuleBase_ViewerPrs aPrs;
31 myWorkshop->selection()->fillPresentation(aPrs, theOwner);
32 ResultPtr aResult = myWorkshop->selection()->getResult(aPrs);
33 // to filter infinite construction results
34 if (aResult.get() && aResult->groupName() == ModelAPI_ResultConstruction::group()) {
35 ResultConstructionPtr aConstruction = std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(aResult);
36 if (aConstruction.get() && aConstruction->isInfinite()) {
37 Handle(StdSelect_BRepOwner) aBRepOwner = Handle(StdSelect_BRepOwner)::DownCast(theOwner);
38 if (!aBRepOwner.IsNull() && aBRepOwner->HasShape()) {
39 const TopoDS_Shape& aShape = aBRepOwner->Shape();
40 TopAbs_ShapeEnum anOwnerShapeType = aShape.ShapeType();
42 TopAbs_ShapeEnum aResultShapeType = TopAbs_SHAPE;
43 GeomShapePtr aResultShape = aResult->shape();
44 if (aResultShape.get()) {
45 TopoDS_Shape aResultTopoShape = aResultShape->impl<TopoDS_Shape>();
46 aResultShapeType = aResultTopoShape.ShapeType();
48 // for infinite object, the selection is possible only for shapes of owners, which are coincide
49 // to the shape of corresponded AIS object. In other words, for axis, only edge can be selected
50 // (vertices are not selectable), for planes, only faces can be selected (not edges or vertices)
51 aValid = anOwnerShapeType == aResultShapeType;