1 // Copyright (C) 2014-2021 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:
44 default: // [to avoid compilation warning]
50 GeomPlanePtr getPlane(AttributeSelectionPtr theAttr)
52 GeomShapePtr aGeom = theAttr->value();
53 if (!aGeom.get()) { // construction plane, #2942
54 aGeom = theAttr->context()->shape();
56 GeomFacePtr aFace(new GeomAPI_Face(aGeom));
57 return aFace->getPlane();
60 bool FiltersPlugin_OnPlane::isOk(const GeomShapePtr& theShape, const ResultPtr&,
61 const ModelAPI_FiltersArgs& theArgs) const
63 AttributePtr aAttr = theArgs.argument("OnPlane");
64 AttributeSelectionListPtr aList =
65 std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(aAttr);
68 if (theShape->isVertex()) {
69 GeomVertexPtr aVertex(new GeomAPI_Vertex(theShape));
70 GeomPointPtr aPnt = aVertex->point();
71 for (int i = 0; i < aList->size(); i++) {
72 GeomPlanePtr aPlane = getPlane(aList->value(i));
73 if (aPlane->distance(aPnt) < LIN_TOLERANCE)
77 else if (theShape->isEdge()) {
78 GeomEdgePtr aEdge(new GeomAPI_Edge(theShape));
79 if (aEdge->isLine()) {
80 GeomPointPtr aPnt1 = aEdge->firstPoint();
81 GeomPointPtr aPnt2 = aEdge->lastPoint();
82 for (int i = 0; i < aList->size(); i++) {
83 GeomPlanePtr aPlane = getPlane(aList->value(i));
84 if ((aPlane->distance(aPnt1) < LIN_TOLERANCE) && (aPlane->distance(aPnt2) < LIN_TOLERANCE))
88 else if (aEdge->isPlanar()) {
89 for (int i = 0; i < aList->size(); i++) {
90 GeomPlanePtr aPlane = getPlane(aList->value(i));
91 if (aEdge->isInPlane(aPlane))
96 else if (theShape->isFace()) {
97 GeomFacePtr aFace(new GeomAPI_Face(theShape));
98 if (aFace->isPlanar()) {
99 GeomPlanePtr aPln = aFace->getPlane();
100 for (int i = 0; i < aList->size(); i++) {
101 AttributeSelectionPtr aCurAttr = aList->value(i);
102 GeomPlanePtr aPlane = getPlane(aCurAttr);
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());