Salome HOME
Issues #2027: trim on cirlce(arc will be created). Result of selected will clear...
[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_RTTIEXT(PartSet_FilterInfinite, SelectMgr_Filter);
21
22 PartSet_FilterInfinite::PartSet_FilterInfinite(ModuleBase_IWorkshop* theWorkshop)
23 : SelectMgr_Filter(), myWorkshop(theWorkshop)
24 {
25 }
26
27 Standard_Boolean PartSet_FilterInfinite::IsOk(const Handle(SelectMgr_EntityOwner)& theOwner) const
28 {
29   Standard_Boolean aValid = Standard_True;
30
31   ModuleBase_ViewerPrsPtr aPrs(new ModuleBase_ViewerPrs());
32   myWorkshop->selection()->fillPresentation(aPrs, theOwner);
33   ResultPtr aResult = myWorkshop->selection()->getResult(aPrs);
34   // to filter infinite construction results
35   if (aResult.get() && aResult->groupName() == ModelAPI_ResultConstruction::group()) {
36     ResultConstructionPtr aConstruction =
37       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
51         // for shapes of owners, which are coincide
52         // to the shape of corresponded AIS object.
53         // In other words, for axis, only edge can be selected
54         // (vertices are not selectable), for planes,
55         // only faces can be selected (not edges or vertices)
56         aValid = anOwnerShapeType == aResultShapeType;
57       }
58     }
59   }
60 #ifdef DEBUG_FILTERS
61   qDebug(QString("PartSet_FilterInfinite::IsOk = %1").arg(aValid).toStdString().c_str());
62 #endif
63   return aValid;
64 }