1 // Copyright (C) 2014-2017 CEA/DEN, EDF R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or
18 // email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
21 #include "PartSet_FilterInfinite.h"
23 #include <ModuleBase_IWorkshop.h>
24 #include <ModuleBase_ISelection.h>
25 #include <ModuleBase_ViewerPrs.h>
27 #include <ModelAPI_ResultConstruction.h>
29 #include <AIS_InteractiveObject.hxx>
30 #include <AIS_Shape.hxx>
31 #include <TopoDS_Shape.hxx>
32 #include <StdSelect_BRepOwner.hxx>
34 IMPLEMENT_STANDARD_RTTIEXT(PartSet_FilterInfinite, SelectMgr_Filter);
36 PartSet_FilterInfinite::PartSet_FilterInfinite(ModuleBase_IWorkshop* theWorkshop)
37 : SelectMgr_Filter(), myWorkshop(theWorkshop)
41 Standard_Boolean PartSet_FilterInfinite::IsOk(const Handle(SelectMgr_EntityOwner)& theOwner) const
43 Standard_Boolean aValid = Standard_True;
45 ModuleBase_ViewerPrsPtr aPrs(new ModuleBase_ViewerPrs());
46 myWorkshop->selection()->fillPresentation(aPrs, theOwner);
47 ResultPtr aResult = myWorkshop->selection()->getResult(aPrs);
48 // to filter infinite construction results
49 if (aResult.get() && aResult->groupName() == ModelAPI_ResultConstruction::group()) {
50 ResultConstructionPtr aConstruction =
51 std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(aResult);
52 if (aConstruction.get() && aConstruction->isInfinite()) {
53 Handle(StdSelect_BRepOwner) aBRepOwner = Handle(StdSelect_BRepOwner)::DownCast(theOwner);
54 if (!aBRepOwner.IsNull() && aBRepOwner->HasShape()) {
55 const TopoDS_Shape& aShape = aBRepOwner->Shape();
56 TopAbs_ShapeEnum anOwnerShapeType = aShape.ShapeType();
58 TopAbs_ShapeEnum aResultShapeType = TopAbs_SHAPE;
59 GeomShapePtr aResultShape = aResult->shape();
60 if (aResultShape.get()) {
61 TopoDS_Shape aResultTopoShape = aResultShape->impl<TopoDS_Shape>();
62 aResultShapeType = aResultTopoShape.ShapeType();
64 // for infinite object, the selection is possible only
65 // for shapes of owners, which are coincide
66 // to the shape of corresponded AIS object.
67 // In other words, for axis, only edge can be selected
68 // (vertices are not selectable), for planes,
69 // only faces can be selected (not edges or vertices)
70 aValid = anOwnerShapeType == aResultShapeType;
75 qDebug(QString("PartSet_FilterInfinite::IsOk = %1").arg(aValid).toStdString().c_str());