1 // Copyright (C) 2020 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 <FeaturesPlugin_Fillet1D.h>
21 #include <FeaturesPlugin_Tools.h>
23 #include <GeomAlgoAPI_Fillet1D.h>
24 #include <GeomAlgoAPI_MapShapesAndAncestors.h>
25 #include <GeomAlgoAPI_ShapeTools.h>
26 #include <GeomAlgoAPI_Tools.h>
28 #include <GeomAPI_Edge.h>
29 #include <GeomAPI_Pln.h>
30 #include <GeomAPI_WireExplorer.h>
32 #include <ModelAPI_AttributeDouble.h>
33 #include <ModelAPI_AttributeSelectionList.h>
34 #include <ModelAPI_AttributeString.h>
36 FeaturesPlugin_Fillet1D::FeaturesPlugin_Fillet1D()
40 void FeaturesPlugin_Fillet1D::initAttributes()
42 data()->addAttribute(CREATION_METHOD(), ModelAPI_AttributeString::typeId());
43 data()->addAttribute(WIRE_LIST_ID(), ModelAPI_AttributeSelectionList::typeId());
44 data()->addAttribute(VERTEX_LIST_ID(), ModelAPI_AttributeSelectionList::typeId());
45 data()->addAttribute(RADIUS_ID(), ModelAPI_AttributeDouble::typeId());
48 void FeaturesPlugin_Fillet1D::execute()
51 MapShapeSubs aVertices;
52 if (!baseShapes(aWires, aVertices))
56 for (ListOfShape::iterator anIt = aWires.begin(); anIt != aWires.end(); ++anIt)
57 if (!performFillet(*anIt, aVertices[*anIt], aResultIndex++))
59 removeResults(aResultIndex);
62 bool FeaturesPlugin_Fillet1D::baseShapes(ListOfShape& theWires, MapShapeSubs& theWireVertices)
64 std::set<GeomShapePtr, GeomAPI_Shape::Comparator> aProcessedWires;
65 std::string aMethod = string(CREATION_METHOD())->value();
66 if (aMethod == CREATION_BY_WIRES()) {
67 AttributeSelectionListPtr aSelList = selectionList(WIRE_LIST_ID());
69 int aNbSel = aSelList->size();
70 for (int ind = 0; ind < aNbSel; ++ind) {
71 AttributeSelectionPtr aCurSel = aSelList->value(ind);
72 GeomShapePtr aWire = aCurSel->context()->shape();
73 if (aProcessedWires.find(aWire) != aProcessedWires.end())
76 aProcessedWires.insert(aWire);
77 // get vertices applicable for fillet
78 GeomAlgoAPI_MapShapesAndAncestors aMapVE(aWire, GeomAPI_Shape::VERTEX, GeomAPI_Shape::EDGE);
79 const MapShapeToShapes& aSubshapes = aMapVE.map();
80 std::set<GeomShapePtr, GeomAPI_Shape::Comparator> aFilletVertices;
81 for (MapShapeToShapes::const_iterator anIt = aSubshapes.begin();
82 anIt != aSubshapes.end(); ++anIt) {
83 // vertex should have 2 adjacent edges
84 if (anIt->second.size() != 2)
87 // skip vertices, which adjacent edges are not on the same plane
89 anEdges.insert(anEdges.end(), anIt->second.begin(), anIt->second.end());
90 GeomPlanePtr aPlane = GeomAlgoAPI_ShapeTools::findPlane(anEdges);
94 // skip vertices, which smoothly connect adjacent edges
95 GeomEdgePtr anEdge1(new GeomAPI_Edge(anEdges.front()));
96 GeomEdgePtr anEdge2(new GeomAPI_Edge(anEdges.back()));
97 GeomVertexPtr aSharedVertex(new GeomAPI_Vertex(anIt->first));
98 if (GeomAlgoAPI_ShapeTools::isTangent(anEdge1, anEdge2, aSharedVertex))
101 aFilletVertices.insert(anIt->first);
104 if (aFilletVertices.empty()) {
105 setError("Wire has no vertices for fillet.");
110 // keep the sequence of wires and fillet vertices stable
111 theWires.push_back(aWire);
112 for (GeomAPI_WireExplorer anExp(aWire->wire()); anExp.more(); anExp.next()) {
113 GeomShapePtr aVertex = anExp.currentVertex();
114 if (aFilletVertices.find(aVertex) != aFilletVertices.end())
115 theWireVertices[aWire].push_back(aVertex);
119 else if (aMethod == CREATION_BY_VERTICES()) {
120 AttributeSelectionListPtr aSelList = selectionList(VERTEX_LIST_ID());
121 int aNbSel = aSelList->size();
122 for (int ind = 0; ind < aNbSel; ++ind) {
123 AttributeSelectionPtr aCurSel = aSelList->value(ind);
124 GeomShapePtr aWire = aCurSel->context()->shape();
125 GeomShapePtr aVertex = aCurSel->value();
127 // keep the sequence of wires stable
128 if (aProcessedWires.find(aWire) == aProcessedWires.end()) {
129 theWires.push_back(aWire);
130 aProcessedWires.insert(aWire);
133 theWireVertices[aWire].push_back(aVertex);
139 bool FeaturesPlugin_Fillet1D::performFillet(const GeomShapePtr& theWire,
140 const ListOfShape& theVertices,
141 const int theResultIndex)
143 double aRadius = real(RADIUS_ID())->value();
145 // perform fillet operation
146 std::shared_ptr<GeomAlgoAPI_Fillet1D> aFilletBuilder(
147 new GeomAlgoAPI_Fillet1D(theWire, theVertices, aRadius));
150 if (GeomAlgoAPI_Tools::AlgoError::isAlgorithmFailed(aFilletBuilder, getKind(), anError)) {
155 static const std::string THE_PREFIX = "Fillet1D";
158 ResultBodyPtr aResult = document()->createBody(data(), theResultIndex);
159 ListOfShape anOriginal;
160 anOriginal.push_back(theWire);
161 FeaturesPlugin_Tools::loadModifiedShapes(aResult, anOriginal, ListOfShape(),
162 aFilletBuilder, aFilletBuilder->shape(), THE_PREFIX);
163 setResult(aResult, theResultIndex);
164 // store new edges generated from vertices
165 for (ListOfShape::const_iterator anIt = theVertices.begin(); anIt != theVertices.end(); ++anIt)
166 aResult->loadGeneratedShapes(aFilletBuilder, *anIt, GeomAPI_Shape::VERTEX, THE_PREFIX, true);