1 // Copyright (C) 2014-2017 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
18 // email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
21 #include "FeaturesPlugin_Revolution.h"
23 #include <ModelAPI_AttributeDouble.h>
24 #include <ModelAPI_AttributeSelection.h>
25 #include <ModelAPI_AttributeString.h>
26 #include <ModelAPI_Session.h>
27 #include <ModelAPI_Validator.h>
29 #include <GeomAlgoAPI_Revolution.h>
30 #include <GeomAlgoAPI_Tools.h>
32 #include <GeomAPI_Edge.h>
33 #include <GeomAPI_Lin.h>
34 #include <GeomAPI_ShapeIterator.h>
36 //=================================================================================================
37 FeaturesPlugin_Revolution::FeaturesPlugin_Revolution()
41 //=================================================================================================
42 void FeaturesPlugin_Revolution::initAttributes()
44 initCompositeSketchAttribtues(InitBaseObjectsList);
46 data()->addAttribute(AXIS_OBJECT_ID(), ModelAPI_AttributeSelection::typeId());
48 data()->addAttribute(CREATION_METHOD(), ModelAPI_AttributeString::typeId());
50 data()->addAttribute(TO_ANGLE_ID(), ModelAPI_AttributeDouble::typeId());
51 data()->addAttribute(FROM_ANGLE_ID(), ModelAPI_AttributeDouble::typeId());
53 data()->addAttribute(TO_OBJECT_ID(), ModelAPI_AttributeSelection::typeId());
54 data()->addAttribute(TO_OFFSET_ID(), ModelAPI_AttributeDouble::typeId());
56 data()->addAttribute(FROM_OBJECT_ID(), ModelAPI_AttributeSelection::typeId());
57 data()->addAttribute(FROM_OFFSET_ID(), ModelAPI_AttributeDouble::typeId());
59 ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), TO_OBJECT_ID());
60 ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), FROM_OBJECT_ID());
62 initCompositeSketchAttribtues(InitSketchLauncher);
65 //=================================================================================================
66 void FeaturesPlugin_Revolution::execute()
68 ListOfShape aBaseShapesList;
69 ListOfMakeShape aMakeShapesList;
72 if(!makeRevolutions(aBaseShapesList, aMakeShapesList)) {
78 ListOfShape::const_iterator aBaseIt = aBaseShapesList.cbegin();
79 ListOfMakeShape::const_iterator anAlgoIt = aMakeShapesList.cbegin();
80 for(; aBaseIt != aBaseShapesList.cend() && anAlgoIt != aMakeShapesList.cend();
81 ++aBaseIt, ++anAlgoIt) {
82 storeResult(*aBaseIt, *anAlgoIt, aResultIndex++);
85 removeResults(aResultIndex);
88 //=================================================================================================
89 bool FeaturesPlugin_Revolution::makeRevolutions(ListOfShape& theBaseShapes,
90 ListOfMakeShape& theMakeShapes)
92 theMakeShapes.clear();
94 // Getting base shapes.
95 getBaseShapes(theBaseShapes);
98 static const std::string aSelectionError = "Error: The axis shape selection is bad.";
99 AttributeSelectionPtr aSelection = selection(AXIS_OBJECT_ID());
100 GeomShapePtr aShape = aSelection->value();
102 if (aSelection->context().get()) {
103 aShape = aSelection->context()->shape();
107 setError(aSelectionError);
112 if (aShape->isEdge())
114 anEdge = aShape->edge();
116 else if (aShape->isCompound())
118 GeomAPI_ShapeIterator anIt(aShape);
119 anEdge = anIt.current()->edge();
123 setError(aSelectionError);
127 std::shared_ptr<GeomAPI_Ax1> anAxis;
129 if(anEdge->isLine()) {
130 anAxis = std::shared_ptr<GeomAPI_Ax1>(new GeomAPI_Ax1(anEdge->line()->location(),
131 anEdge->line()->direction()));
140 double aToAngle = 0.0;
141 double aFromAngle = 0.0;
143 if(string(CREATION_METHOD())->value() == CREATION_METHOD_BY_ANGLES()) {
144 aToAngle = real(TO_ANGLE_ID())->value();
145 aFromAngle = real(FROM_ANGLE_ID())->value();
147 aToAngle = real(TO_OFFSET_ID())->value();
148 aFromAngle = real(FROM_OFFSET_ID())->value();
151 // Getting bounding planes.
152 GeomShapePtr aToShape;
153 GeomShapePtr aFromShape;
155 if(string(CREATION_METHOD())->value() == CREATION_METHOD_BY_PLANES()) {
156 aSelection = selection(TO_OBJECT_ID());
157 if(aSelection.get()) {
158 aToShape = std::dynamic_pointer_cast<GeomAPI_Shape>(aSelection->value());
159 if(!aToShape.get() && aSelection->context().get()) {
160 aToShape = aSelection->context()->shape();
162 if (aToShape.get() && aToShape->isCompound()) {
163 GeomAPI_ShapeIterator anIt(aToShape);
164 aToShape = anIt.current();
167 aSelection = selection(FROM_OBJECT_ID());
168 if(aSelection.get()) {
169 aFromShape = std::dynamic_pointer_cast<GeomAPI_Shape>(aSelection->value());
170 if(!aFromShape.get() && aSelection->context().get()) {
171 aFromShape = aSelection->context()->shape();
173 if (aFromShape.get() && aFromShape->isCompound()) {
174 GeomAPI_ShapeIterator anIt(aFromShape);
175 aFromShape = anIt.current();
180 // Generating result for each base shape.
182 for(ListOfShape::const_iterator
183 anIter = theBaseShapes.cbegin(); anIter != theBaseShapes.cend(); anIter++) {
184 GeomShapePtr aBaseShape = *anIter;
186 std::shared_ptr<GeomAlgoAPI_Revolution> aRevolAlgo(new GeomAlgoAPI_Revolution(
189 aFromShape, aFromAngle));
190 if (GeomAlgoAPI_Tools::AlgoError::isAlgorithmFailed(aRevolAlgo, getKind(), anError)) {
195 theMakeShapes.push_back(aRevolAlgo);