Salome HOME
"2.11 Constraint with a point from the intersection between an outer edge and plane...
[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 <ModuleBase_IWorkshop.h>
10 #include <ModuleBase_ISelection.h>
11 #include <ModelAPI_ResultConstruction.h>
12
13 #include <AIS_InteractiveObject.hxx>
14 #include <AIS_Shape.hxx>
15 #include <TopoDS_Shape.hxx>
16 #include <StdSelect_BRepOwner.hxx>
17
18 IMPLEMENT_STANDARD_HANDLE(PartSet_FilterInfinite, SelectMgr_Filter);
19 IMPLEMENT_STANDARD_RTTIEXT(PartSet_FilterInfinite, SelectMgr_Filter);
20
21 PartSet_FilterInfinite::PartSet_FilterInfinite(ModuleBase_IWorkshop* theWorkshop)
22 : SelectMgr_Filter(), myWorkshop(theWorkshop)
23 {
24 }
25
26 Standard_Boolean PartSet_FilterInfinite::IsOk(const Handle(SelectMgr_EntityOwner)& theOwner) const
27 {
28   Standard_Boolean aValid = Standard_True;
29
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();
41
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();
47         }
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;
52       }
53     }
54   }
55 #ifdef DEBUG_FILTERS
56   qDebug(QString("PartSet_FilterInfinite::IsOk = %1").arg(aValid).toStdString().c_str());
57 #endif
58   return aValid;
59 }