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 "FeaturesPlugin_Revolution.h"
22 #include <ModelAPI_AttributeDouble.h>
23 #include <ModelAPI_AttributeSelection.h>
24 #include <ModelAPI_AttributeString.h>
25 #include <ModelAPI_Session.h>
26 #include <ModelAPI_Validator.h>
28 #include <GeomAlgoAPI_Revolution.h>
29 #include <GeomAlgoAPI_Tools.h>
31 #include <GeomAPI_Edge.h>
32 #include <GeomAPI_Lin.h>
33 #include <GeomAPI_ShapeIterator.h>
35 //=================================================================================================
36 FeaturesPlugin_Revolution::FeaturesPlugin_Revolution()
40 //=================================================================================================
41 void FeaturesPlugin_Revolution::initAttributes()
43 initCompositeSketchAttribtues(InitBaseObjectsList);
45 data()->addAttribute(AXIS_OBJECT_ID(), ModelAPI_AttributeSelection::typeId());
47 data()->addAttribute(CREATION_METHOD(), ModelAPI_AttributeString::typeId());
49 data()->addAttribute(TO_ANGLE_ID(), ModelAPI_AttributeDouble::typeId());
50 data()->addAttribute(FROM_ANGLE_ID(), ModelAPI_AttributeDouble::typeId());
52 data()->addAttribute(TO_OBJECT_ID(), ModelAPI_AttributeSelection::typeId());
53 data()->addAttribute(TO_OFFSET_ID(), ModelAPI_AttributeDouble::typeId());
55 data()->addAttribute(FROM_OBJECT_ID(), ModelAPI_AttributeSelection::typeId());
56 data()->addAttribute(FROM_OFFSET_ID(), ModelAPI_AttributeDouble::typeId());
58 ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), TO_OBJECT_ID());
59 ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), FROM_OBJECT_ID());
61 initCompositeSketchAttribtues(InitSketchLauncher);
64 //=================================================================================================
65 void FeaturesPlugin_Revolution::execute()
67 ListOfShape aBaseShapesList;
68 ListOfMakeShape aMakeShapesList;
71 if(!makeRevolutions(aBaseShapesList, aMakeShapesList)) {
77 ListOfShape::const_iterator aBaseIt = aBaseShapesList.cbegin();
78 ListOfMakeShape::const_iterator anAlgoIt = aMakeShapesList.cbegin();
79 for(; aBaseIt != aBaseShapesList.cend() && anAlgoIt != aMakeShapesList.cend();
80 ++aBaseIt, ++anAlgoIt) {
81 storeResult(*aBaseIt, *anAlgoIt, aResultIndex++);
84 removeResults(aResultIndex);
87 //=================================================================================================
88 bool FeaturesPlugin_Revolution::makeRevolutions(ListOfShape& theBaseShapes,
89 ListOfMakeShape& theMakeShapes)
91 theMakeShapes.clear();
93 // Getting base shapes.
94 getBaseShapes(theBaseShapes);
97 static const std::string aSelectionError = "Error: The axis shape selection is bad.";
98 AttributeSelectionPtr aSelection = selection(AXIS_OBJECT_ID());
99 GeomShapePtr aShape = aSelection->value();
101 if (aSelection->context().get()) {
102 aShape = aSelection->context()->shape();
106 setError(aSelectionError);
111 if (aShape->isEdge())
113 anEdge = aShape->edge();
115 else if (aShape->isCompound())
117 GeomAPI_ShapeIterator anIt(aShape);
118 anEdge = anIt.current()->edge();
122 setError(aSelectionError);
126 std::shared_ptr<GeomAPI_Ax1> anAxis;
128 if(anEdge->isLine()) {
129 anAxis = std::shared_ptr<GeomAPI_Ax1>(new GeomAPI_Ax1(anEdge->line()->location(),
130 anEdge->line()->direction()));
139 double aToAngle = 0.0;
140 double aFromAngle = 0.0;
142 if (string(CREATION_METHOD())->value() == CREATION_METHOD_BY_ANGLES()) {
143 aToAngle = real(TO_ANGLE_ID())->value();
144 aFromAngle = real(FROM_ANGLE_ID())->value();
145 } else if (string(CREATION_METHOD())->value() == CREATION_METHOD_BY_PLANES()) {
146 aToAngle = real(TO_OFFSET_ID())->value();
147 aFromAngle = real(FROM_OFFSET_ID())->value();
148 } else if (string(CREATION_METHOD())->value() == CREATION_METHOD_THROUGH_ALL()) {
154 // Getting bounding planes.
155 GeomShapePtr aToShape;
156 GeomShapePtr aFromShape;
158 if(string(CREATION_METHOD())->value() == CREATION_METHOD_BY_PLANES()) {
159 aSelection = selection(TO_OBJECT_ID());
160 if(aSelection.get()) {
161 aToShape = std::dynamic_pointer_cast<GeomAPI_Shape>(aSelection->value());
162 if(!aToShape.get() && aSelection->context().get()) {
163 aToShape = aSelection->context()->shape();
165 if (aToShape.get() && aToShape->isCompound()) {
166 GeomAPI_ShapeIterator anIt(aToShape);
167 aToShape = anIt.current();
170 aSelection = selection(FROM_OBJECT_ID());
171 if(aSelection.get()) {
172 aFromShape = std::dynamic_pointer_cast<GeomAPI_Shape>(aSelection->value());
173 if(!aFromShape.get() && aSelection->context().get()) {
174 aFromShape = aSelection->context()->shape();
176 if (aFromShape.get() && aFromShape->isCompound()) {
177 GeomAPI_ShapeIterator anIt(aFromShape);
178 aFromShape = anIt.current();
183 // Generating result for each base shape.
185 for(ListOfShape::const_iterator
186 anIter = theBaseShapes.cbegin(); anIter != theBaseShapes.cend(); anIter++) {
187 GeomShapePtr aBaseShape = *anIter;
189 std::shared_ptr<GeomAlgoAPI_Revolution> aRevolAlgo(new GeomAlgoAPI_Revolution(
192 aFromShape, aFromAngle));
193 if (GeomAlgoAPI_Tools::AlgoError::isAlgorithmFailed(aRevolAlgo, getKind(), anError)) {
198 theMakeShapes.push_back(aRevolAlgo);