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 <ModuleBase_ViewerPrs.h>
13 #include <ModelAPI_ResultConstruction.h>
15 #include <AIS_InteractiveObject.hxx>
16 #include <AIS_Shape.hxx>
17 #include <TopoDS_Shape.hxx>
18 #include <StdSelect_BRepOwner.hxx>
20 IMPLEMENT_STANDARD_HANDLE(PartSet_FilterInfinite, SelectMgr_Filter);
21 IMPLEMENT_STANDARD_RTTIEXT(PartSet_FilterInfinite, SelectMgr_Filter);
23 PartSet_FilterInfinite::PartSet_FilterInfinite(ModuleBase_IWorkshop* theWorkshop)
24 : SelectMgr_Filter(), myWorkshop(theWorkshop)
28 Standard_Boolean PartSet_FilterInfinite::IsOk(const Handle(SelectMgr_EntityOwner)& theOwner) const
30 Standard_Boolean aValid = Standard_True;
32 ModuleBase_ViewerPrsPtr aPrs(new ModuleBase_ViewerPrs());
33 myWorkshop->selection()->fillPresentation(aPrs, theOwner);
34 ResultPtr aResult = myWorkshop->selection()->getResult(aPrs);
35 // to filter infinite construction results
36 if (aResult.get() && aResult->groupName() == ModelAPI_ResultConstruction::group()) {
37 ResultConstructionPtr aConstruction =
38 std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(aResult);
39 if (aConstruction.get() && aConstruction->isInfinite()) {
40 Handle(StdSelect_BRepOwner) aBRepOwner = Handle(StdSelect_BRepOwner)::DownCast(theOwner);
41 if (!aBRepOwner.IsNull() && aBRepOwner->HasShape()) {
42 const TopoDS_Shape& aShape = aBRepOwner->Shape();
43 TopAbs_ShapeEnum anOwnerShapeType = aShape.ShapeType();
45 TopAbs_ShapeEnum aResultShapeType = TopAbs_SHAPE;
46 GeomShapePtr aResultShape = aResult->shape();
47 if (aResultShape.get()) {
48 TopoDS_Shape aResultTopoShape = aResultShape->impl<TopoDS_Shape>();
49 aResultShapeType = aResultTopoShape.ShapeType();
51 // for infinite object, the selection is possible only
52 // for shapes of owners, which are coincide
53 // to the shape of corresponded AIS object.
54 // In other words, for axis, only edge can be selected
55 // (vertices are not selectable), for planes,
56 // only faces can be selected (not edges or vertices)
57 aValid = anOwnerShapeType == aResultShapeType;
62 qDebug(QString("PartSet_FilterInfinite::IsOk = %1").arg(aValid).toStdString().c_str());