Salome HOME
df38f4ceb781ddcaf9b37a13f6f025fc60c897e3
[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 <ModuleBase_ViewerPrs.h>
12
13 #include <ModelAPI_ResultConstruction.h>
14
15 #include <AIS_InteractiveObject.hxx>
16 #include <AIS_Shape.hxx>
17 #include <TopoDS_Shape.hxx>
18 #include <StdSelect_BRepOwner.hxx>
19
20 IMPLEMENT_STANDARD_HANDLE(PartSet_FilterInfinite, SelectMgr_Filter);
21 IMPLEMENT_STANDARD_RTTIEXT(PartSet_FilterInfinite, SelectMgr_Filter);
22
23 PartSet_FilterInfinite::PartSet_FilterInfinite(ModuleBase_IWorkshop* theWorkshop)
24 : SelectMgr_Filter(), myWorkshop(theWorkshop)
25 {
26 }
27
28 Standard_Boolean PartSet_FilterInfinite::IsOk(const Handle(SelectMgr_EntityOwner)& theOwner) const
29 {
30   Standard_Boolean aValid = Standard_True;
31
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 = std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(aResult);
38     if (aConstruction.get() && aConstruction->isInfinite()) {
39       Handle(StdSelect_BRepOwner) aBRepOwner = Handle(StdSelect_BRepOwner)::DownCast(theOwner);
40       if (!aBRepOwner.IsNull() && aBRepOwner->HasShape()) {
41         const TopoDS_Shape& aShape = aBRepOwner->Shape();
42         TopAbs_ShapeEnum anOwnerShapeType = aShape.ShapeType();
43
44         TopAbs_ShapeEnum aResultShapeType = TopAbs_SHAPE;
45         GeomShapePtr aResultShape = aResult->shape();
46         if (aResultShape.get()) {
47           TopoDS_Shape aResultTopoShape = aResultShape->impl<TopoDS_Shape>();
48           aResultShapeType = aResultTopoShape.ShapeType();
49         }
50         // for infinite object, the selection is possible only for shapes of owners, which are coincide
51         // to the shape of corresponded AIS object. In other words, for axis, only edge can be selected
52         // (vertices are not selectable), for planes, only faces can be selected (not edges or vertices)
53         aValid = anOwnerShapeType == aResultShapeType;
54       }
55     }
56   }
57 #ifdef DEBUG_FILTERS
58   qDebug(QString("PartSet_FilterInfinite::IsOk = %1").arg(aValid).toStdString().c_str());
59 #endif
60   return aValid;
61 }