1 // Copyright (C) 2017-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 "FeaturesPlugin_Chamfer.h"
21 ////#include "FeaturesPlugin_Tools.h"
23 ////#include <ModelAPI_Data.h>
24 #include <ModelAPI_AttributeDouble.h>
25 #include <ModelAPI_AttributeSelectionList.h>
26 #include <ModelAPI_AttributeString.h>
27 ////#include <ModelAPI_ResultBody.h>
28 ////#include <ModelAPI_Session.h>
29 ////#include <ModelAPI_Tools.h>
30 ////#include <ModelAPI_Validator.h>
32 ////#include <GeomAlgoAPI_CompoundBuilder.h>
33 #include <GeomAlgoAPI_Chamfer.h>
34 #include <GeomAlgoAPI_MakeShape.h>
35 #include <GeomAlgoAPI_Tools.h>
37 ////#include <GeomAPI_DataMapOfShapeMapOfShapes.h>
38 #include <GeomAPI_ShapeExplorer.h>
39 ////#include <GeomAPI_ShapeIterator.h>
41 ////// Obtain all sub-shapes from the shape and append them to the list
42 ////static void collectSubs(const GeomShapePtr& theShape,
43 //// ListOfShape& theSubs,
44 //// const GeomAPI_Shape::ShapeType theShapeType)
46 //// GeomAPI_ShapeExplorer anExp(theShape, theShapeType);
47 //// for (; anExp.more(); anExp.next()) {
48 //// GeomShapePtr aShape = anExp.current();
49 //// // Store all shapes with FORWARD orientation to avoid duplication of shared edges/vertices
50 //// aShape->setOrientation(GeomAPI_Shape::FORWARD);
51 //// theSubs.push_back(aShape);
55 // Extract edges from the list
56 static void extractEdgesAndFaces(const ListOfShape& theShapes,
57 ListOfShape& theEdges,
58 std::map<GeomShapePtr, GeomShapePtr>& theMapEdgeFace)
60 for (ListOfShape::const_iterator anIt = theShapes.begin(); anIt != theShapes.end(); ++anIt)
61 if ((*anIt)->isEdge())
62 theEdges.push_back(*anIt);
64 for (GeomAPI_ShapeExplorer anExp(*anIt, GeomAPI_Shape::EDGE); anExp.more(); anExp.next()) {
65 GeomShapePtr aCurrent = anExp.current();
66 theEdges.push_back(aCurrent);
67 theMapEdgeFace[aCurrent] = *anIt;
73 FeaturesPlugin_Chamfer::FeaturesPlugin_Chamfer()
77 void FeaturesPlugin_Chamfer::initAttributes()
79 data()->addAttribute(FeaturesPlugin_Chamfer::CREATION_METHOD(),
80 ModelAPI_AttributeString::typeId());
81 AttributePtr aSelectionList = data()->addAttribute(FeaturesPlugin_Chamfer::OBJECT_LIST_ID(),
82 ModelAPI_AttributeSelectionList::typeId());
83 data()->addAttribute(FeaturesPlugin_Chamfer::D1_ID(), ModelAPI_AttributeDouble::typeId());
84 data()->addAttribute(FeaturesPlugin_Chamfer::D2_ID(), ModelAPI_AttributeDouble::typeId());
85 data()->addAttribute(FeaturesPlugin_Chamfer::D_ID(), ModelAPI_AttributeDouble::typeId());
86 data()->addAttribute(FeaturesPlugin_Chamfer::ANGLE_ID(), ModelAPI_AttributeDouble::typeId());
88 initVersion(aSelectionList);
91 AttributePtr FeaturesPlugin_Chamfer::objectsAttribute()
93 return attribute(OBJECT_LIST_ID());
96 const std::string& FeaturesPlugin_Chamfer::modifiedShapePrefix() const
98 static const std::string& THE_PREFIX("Chamfer");
102 GeomMakeShapePtr FeaturesPlugin_Chamfer::performOperation(const GeomShapePtr& theSolid,
103 const ListOfShape& theEdges)
105 AttributeStringPtr aCreationMethod = string(CREATION_METHOD());
106 if (!aCreationMethod)
107 return GeomMakeShapePtr();
109 bool isDistDist = aCreationMethod->value() == CREATION_METHOD_DISTANCE_DISTANCE();
110 double aD1 = 0.0, aD2 = 0.0, aD = 0.0, anAngle = 0.0;
112 aD1 = real(FeaturesPlugin_Chamfer::D1_ID())->value();
113 aD2 = real(FeaturesPlugin_Chamfer::D2_ID())->value();
116 aD = real(FeaturesPlugin_Chamfer::D_ID())->value();
117 anAngle = real(FeaturesPlugin_Chamfer::ANGLE_ID())->value();
120 // Perform chamfer operation
121 std::shared_ptr<GeomAlgoAPI_Chamfer> aChamferBuilder;
124 ListOfShape aChamferEdges;
125 std::map<GeomShapePtr, GeomShapePtr> aMapEdgeFace;
126 extractEdgesAndFaces(theEdges, aChamferEdges, aMapEdgeFace);
129 aChamferBuilder.reset(new GeomAlgoAPI_Chamfer(
130 theSolid, aChamferEdges, aMapEdgeFace, true, aD1, aD2));
133 aChamferBuilder.reset(new GeomAlgoAPI_Chamfer(
134 theSolid, aChamferEdges, aMapEdgeFace, false, aD, anAngle));
137 if (GeomAlgoAPI_Tools::AlgoError::isAlgorithmFailed(aChamferBuilder, getKind(), anError)) {
139 return GeomMakeShapePtr();
141 return aChamferBuilder;