1 // Copyright (C) 2014-2019 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 email : webmaster.salome@opencascade.com
20 #include "FiltersPlugin_OnPlaneSide.h"
22 #include <ModelAPI_AttributeSelection.h>
24 #include <GeomAPI_Face.h>
25 #include <GeomAPI_Pln.h>
26 #include <GeomAPI_Pnt.h>
27 #include <GeomAPI_XYZ.h>
30 bool FiltersPlugin_OnPlaneSide::isSupported(GeomAPI_Shape::ShapeType theType) const
35 bool FiltersPlugin_OnPlaneSide::isOk(const GeomShapePtr& theShape, const ResultPtr&,
36 const ModelAPI_FiltersArgs& theArgs) const
38 static const double THE_TOLERANCE = 1.e-7;
40 AttributePtr aAttr = theArgs.argument("OnPlaneSide");
41 AttributeSelectionPtr aList = std::dynamic_pointer_cast<ModelAPI_AttributeSelection>(aAttr);
44 GeomShapePtr aPlanarShape = aList->value();
46 aPlanarShape = aList->context()->shape();
48 GeomPlanePtr aPlane = aPlanarShape->face()->getPlane();
49 GeomPointPtr aPlaneLoc = aPlane->location();
50 GeomDirPtr aPlaneNorm = aPlane->direction();
52 GeomPointPtr aShapeCenter = theShape->middlePoint();
53 GeomXYZPtr aVec = aShapeCenter->xyz()->decreased(aPlaneLoc->xyz());
55 return aVec->dot(aPlaneNorm->xyz()) > THE_TOLERANCE;
58 std::string FiltersPlugin_OnPlaneSide::xmlRepresentation() const
60 return xmlFromFile("filter-OnPlaneSide.xml");
63 void FiltersPlugin_OnPlaneSide::initAttributes(ModelAPI_FiltersArgs& theArguments)
65 theArguments.initAttribute("OnPlaneSide", ModelAPI_AttributeSelection::typeId());