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_OnPlane.h"
22 #include <ModelAPI_AttributeSelectionList.h>
23 #include <GeomAPI_Vertex.h>
24 #include <GeomAPI_Pnt.h>
25 #include <GeomAPI_Face.h>
26 #include <GeomAPI_Pln.h>
27 #include <GeomAPI_Edge.h>
28 #include <GeomAPI_Curve.h>
29 #include <GeomAPI_Circ.h>
30 #include <GeomAPI_Dir.h>
33 #define LIN_TOLERANCE 1.e-7
35 bool FiltersPlugin_OnPlane::isSupported(GeomAPI_Shape::ShapeType theType) const
38 case GeomAPI_Shape::SHELL:
39 case GeomAPI_Shape::FACE:
40 case GeomAPI_Shape::WIRE:
41 case GeomAPI_Shape::EDGE:
42 case GeomAPI_Shape::VERTEX:
48 GeomPlanePtr getPlane(AttributeSelectionPtr theAttr)
50 GeomShapePtr aGeom = theAttr->value();
51 GeomFacePtr aFace(new GeomAPI_Face(aGeom));
52 return aFace->getPlane();
55 bool FiltersPlugin_OnPlane::isOk(const GeomShapePtr& theShape, const ResultPtr&,
56 const ModelAPI_FiltersArgs& theArgs) const
58 AttributePtr aAttr = theArgs.argument("OnPlane");
59 AttributeSelectionListPtr aList =
60 std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(aAttr);
63 if (theShape->isVertex()) {
64 GeomVertexPtr aVertex(new GeomAPI_Vertex(theShape));
65 GeomPointPtr aPnt = aVertex->point();
66 for (int i = 0; i < aList->size(); i++) {
67 GeomPlanePtr aPlane = getPlane(aList->value(i));
68 if (aPlane->distance(aPnt) < LIN_TOLERANCE)
72 else if (theShape->isEdge()) {
73 GeomEdgePtr aEdge(new GeomAPI_Edge(theShape));
74 if (aEdge->isLine()) {
75 GeomPointPtr aPnt1 = aEdge->firstPoint();
76 GeomPointPtr aPnt2 = aEdge->lastPoint();
77 for (int i = 0; i < aList->size(); i++) {
78 GeomPlanePtr aPlane = getPlane(aList->value(i));
79 if ((aPlane->distance(aPnt1) < LIN_TOLERANCE) && (aPlane->distance(aPnt2) < LIN_TOLERANCE))
83 else if (aEdge->isCircle()) {
84 GeomCurvePtr aCurve(new GeomAPI_Curve(aEdge));
85 GeomCirclePtr aCircle(new GeomAPI_Circ(aCurve));
86 GeomDirPtr aDir = aCircle->normal();
87 GeomPointPtr aPnt = aCircle->center();
88 for (int i = 0; i < aList->size(); i++) {
89 GeomPlanePtr aPlane = getPlane(aList->value(i));
90 if ((aPlane->direction()->isParallel(aDir)) && (aPlane->distance(aPnt) < LIN_TOLERANCE))
95 else if (theShape->isFace()) {
96 GeomFacePtr aFace(new GeomAPI_Face(theShape));
97 if (aFace->isPlanar()) {
98 GeomPlanePtr aPln = aFace->getPlane();
99 for (int i = 0; i < aList->size(); i++) {
100 AttributeSelectionPtr aAttr = aList->value(i);
101 GeomShapePtr aGeom = aAttr->value();
102 GeomPlanePtr aPlane = getPlane(aAttr);
103 if (aPlane->isCoincident(aPln))
111 std::string FiltersPlugin_OnPlane::xmlRepresentation() const
113 return xmlFromFile("filter-OnPlane.xml");
116 void FiltersPlugin_OnPlane::initAttributes(ModelAPI_FiltersArgs& theArguments)
118 theArguments.initAttribute("OnPlane", ModelAPI_AttributeSelectionList::typeId());