Salome HOME
015701265747e0b6bd397b2a482c2bda04737861
[modules/shaper.git] / src / PartSet / PartSet_FilterInfinite.cpp
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
2
3 // File:        PartSet_Filters.cpp
4 // Created:     19 Jun 2015
5 // Author:      Natalia ERMOLAEVA
6
7 #include "PartSet_FilterInfinite.h"
8
9 #include <AIS_InteractiveObject.hxx>
10 #include <AIS_Shape.hxx>
11 #include <TopoDS_Shape.hxx>
12 #include <StdSelect_BRepOwner.hxx>
13
14 IMPLEMENT_STANDARD_HANDLE(PartSet_FilterInfinite, SelectMgr_Filter);
15 IMPLEMENT_STANDARD_RTTIEXT(PartSet_FilterInfinite, SelectMgr_Filter);
16
17 Standard_Boolean PartSet_FilterInfinite::IsOk(const Handle(SelectMgr_EntityOwner)& theOwner) const
18 {
19   Standard_Boolean aValid = Standard_True;
20   Handle(AIS_InteractiveObject) anAISObj =
21     Handle(AIS_InteractiveObject)::DownCast(theOwner->Selectable());
22   if (!anAISObj.IsNull()) {
23     Handle(AIS_InteractiveObject) anObj = 
24         Handle(AIS_InteractiveObject)::DownCast(theOwner->Selectable());
25     Handle(AIS_Shape) aAISShape = Handle(AIS_Shape)::DownCast(anObj);
26     if (!aAISShape.IsNull()) {
27       TopoDS_Shape anAISShape = aAISShape->Shape();
28       if (!anAISShape.IsNull() && anAISShape.Infinite()) {
29         aValid = Standard_False;
30         // for infinite object, the selection is possible only for shapes of owners, which are coincide
31         // to the shape of corresponded AIS object. In other words, for axis, only edge can be selected
32         // (vertices are not selectable), for planes, only faces can be selected (not edges or vertices)
33         TopoDS_Shape anOwnerShape;
34         Handle(StdSelect_BRepOwner) aBRO = Handle(StdSelect_BRepOwner)::DownCast(theOwner);
35         if( !aBRO.IsNull() ) {
36           anOwnerShape = aBRO->Shape();
37           if (!anOwnerShape.IsNull()) {
38             aValid = anAISShape.ShapeType() == anOwnerShape.ShapeType();
39           }
40         }
41       }
42     }
43   }
44   return aValid;
45 }