Salome HOME
updated copyright message
[modules/shaper.git] / src / PartSet / PartSet_FilterInfinite.cpp
1 // Copyright (C) 2014-2023  CEA, EDF
2 //
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.
7 //
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.
12 //
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
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20 #include "PartSet_FilterInfinite.h"
21
22 #include <ModuleBase_IWorkshop.h>
23 #include <ModuleBase_ISelection.h>
24 #include <ModuleBase_ViewerPrs.h>
25
26 #include <ModelAPI_ResultConstruction.h>
27
28 #include <AIS_InteractiveObject.hxx>
29 #include <AIS_Shape.hxx>
30 #include <TopoDS_Shape.hxx>
31 #include <StdSelect_BRepOwner.hxx>
32
33 IMPLEMENT_STANDARD_RTTIEXT(PartSet_FilterInfinite, SelectMgr_Filter);
34
35 PartSet_FilterInfinite::PartSet_FilterInfinite(ModuleBase_IWorkshop* theWorkshop)
36 : SelectMgr_Filter(), myWorkshop(theWorkshop)
37 {
38 }
39
40 Standard_Boolean PartSet_FilterInfinite::IsOk(const Handle(SelectMgr_EntityOwner)& theOwner) const
41 {
42   Standard_Boolean aValid = Standard_True;
43
44   ModuleBase_ViewerPrsPtr aPrs(new ModuleBase_ViewerPrs());
45   myWorkshop->selection()->fillPresentation(aPrs, theOwner);
46   ResultPtr aResult = myWorkshop->selection()->getResult(aPrs);
47   // to filter infinite construction results
48   if (aResult.get() && aResult->groupName() == ModelAPI_ResultConstruction::group()) {
49     ResultConstructionPtr aConstruction =
50       std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(aResult);
51     if (aConstruction.get() && aConstruction->isInfinite()) {
52       Handle(StdSelect_BRepOwner) aBRepOwner = Handle(StdSelect_BRepOwner)::DownCast(theOwner);
53       if (!aBRepOwner.IsNull() && aBRepOwner->HasShape()) {
54         const TopoDS_Shape& aShape = aBRepOwner->Shape();
55         TopAbs_ShapeEnum anOwnerShapeType = aShape.ShapeType();
56
57         TopAbs_ShapeEnum aResultShapeType = TopAbs_SHAPE;
58         GeomShapePtr aResultShape = aResult->shape();
59         if (aResultShape.get()) {
60           TopoDS_Shape aResultTopoShape = aResultShape->impl<TopoDS_Shape>();
61           aResultShapeType = aResultTopoShape.ShapeType();
62         }
63         // for infinite object, the selection is possible only
64         // for shapes of owners, which are coincide
65         // to the shape of corresponded AIS object.
66         // In other words, for axis, only edge can be selected
67         // (vertices are not selectable), for planes,
68         // only faces can be selected (not edges or vertices)
69         aValid = anOwnerShapeType == aResultShapeType;
70       }
71     }
72   }
73 #ifdef DEBUG_FILTERS
74   qDebug(QString("PartSet_FilterInfinite::IsOk = %1").arg(aValid).toStdString().c_str());
75 #endif
76   return aValid;
77 }