1 // Copyright (C) 2014-2023 CEA, EDF
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_OnLine.h"
22 #include <ModelAPI_AttributeSelectionList.h>
24 #include <GeomAPI_Edge.h>
25 #include <GeomAPI_Lin.h>
26 #include <GeomAPI_Pnt.h>
27 #include <GeomAPI_Vertex.h>
30 static void convertToLines(const AttributeSelectionListPtr& theSelected,
31 std::list<GeomLinePtr>& theLines)
33 for (int i = 0; i < theSelected->size(); i++) {
34 AttributeSelectionPtr aSel = theSelected->value(i);
35 GeomShapePtr aCurShape = aSel->value();
37 aCurShape = aSel->context()->shape();
38 if (aCurShape && aCurShape->isEdge()) {
39 GeomLinePtr aLine = aCurShape->edge()->line();
41 theLines.push_back(aLine);
47 bool FiltersPlugin_OnLine::isSupported(GeomAPI_Shape::ShapeType theType) const
49 return theType == GeomAPI_Shape::EDGE || theType == GeomAPI_Shape::VERTEX;
52 bool FiltersPlugin_OnLine::isOk(const GeomShapePtr& theShape, const ResultPtr&,
53 const ModelAPI_FiltersArgs& theArgs) const
55 AttributePtr aAttr = theArgs.argument("OnLine");
56 AttributeSelectionListPtr aList =
57 std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(aAttr);
60 // convert selected shapes to lines
61 std::list<GeomLinePtr> aLines;
62 convertToLines(aList, aLines);
64 if (theShape->isVertex()) {
65 GeomPointPtr aPnt = theShape->vertex()->point();
66 for (std::list<GeomLinePtr>::iterator anIt = aLines.begin(); anIt != aLines.end(); ++anIt) {
67 if ((*anIt)->contains(aPnt))
71 else if (theShape->isEdge()) {
72 GeomEdgePtr aEdge(new GeomAPI_Edge(theShape));
73 if (aEdge->isLine()) {
74 GeomPointPtr aPnt1 = aEdge->firstPoint();
75 GeomPointPtr aPnt2 = aEdge->lastPoint();
76 for (std::list<GeomLinePtr>::iterator anIt = aLines.begin(); anIt != aLines.end(); ++anIt) {
77 if ((*anIt)->contains(aPnt1) && (*anIt)->contains(aPnt2))
85 std::string FiltersPlugin_OnLine::xmlRepresentation() const
87 return xmlFromFile("filter-OnLine.xml");
90 void FiltersPlugin_OnLine::initAttributes(ModelAPI_FiltersArgs& theArguments)
92 theArguments.initAttribute("OnLine", ModelAPI_AttributeSelectionList::typeId());