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>
31 #include <GeomAPI_Edge.h>
32 #include <GeomAPI_Lin.h>
34 //=================================================================================================
35 FeaturesPlugin_Revolution::FeaturesPlugin_Revolution()
39 //=================================================================================================
40 void FeaturesPlugin_Revolution::initAttributes()
42 initCompositeSketchAttribtues(InitBaseObjectsList);
44 data()->addAttribute(AXIS_OBJECT_ID(), ModelAPI_AttributeSelection::typeId());
46 data()->addAttribute(CREATION_METHOD(), ModelAPI_AttributeString::typeId());
48 data()->addAttribute(TO_ANGLE_ID(), ModelAPI_AttributeDouble::typeId());
49 data()->addAttribute(FROM_ANGLE_ID(), ModelAPI_AttributeDouble::typeId());
51 data()->addAttribute(TO_OBJECT_ID(), ModelAPI_AttributeSelection::typeId());
52 data()->addAttribute(TO_OFFSET_ID(), ModelAPI_AttributeDouble::typeId());
54 data()->addAttribute(FROM_OBJECT_ID(), ModelAPI_AttributeSelection::typeId());
55 data()->addAttribute(FROM_OFFSET_ID(), ModelAPI_AttributeDouble::typeId());
57 ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), TO_OBJECT_ID());
58 ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), FROM_OBJECT_ID());
60 initCompositeSketchAttribtues(InitSketchLauncher);
63 //=================================================================================================
64 void FeaturesPlugin_Revolution::execute()
66 ListOfShape aBaseShapesList;
67 ListOfMakeShape aMakeShapesList;
70 if(!makeRevolutions(aBaseShapesList, aMakeShapesList)) {
76 ListOfShape::const_iterator aBaseIt = aBaseShapesList.cbegin();
77 ListOfMakeShape::const_iterator anAlgoIt = aMakeShapesList.cbegin();
78 for(; aBaseIt != aBaseShapesList.cend() && anAlgoIt != aMakeShapesList.cend();
79 ++aBaseIt, ++anAlgoIt) {
80 storeResult(*aBaseIt, *anAlgoIt, aResultIndex++);
83 removeResults(aResultIndex);
86 //=================================================================================================
87 bool FeaturesPlugin_Revolution::makeRevolutions(ListOfShape& theBaseShapes,
88 ListOfMakeShape& theMakeShapes)
90 theMakeShapes.clear();
92 // Getting base shapes.
93 getBaseShapes(theBaseShapes);
96 std::shared_ptr<GeomAPI_Ax1> anAxis;
97 std::shared_ptr<GeomAPI_Edge> anEdge;
98 AttributeSelectionPtr aSelection = selection(AXIS_OBJECT_ID());
99 if(aSelection.get() && aSelection->value().get() && aSelection->value()->isEdge()) {
100 anEdge = std::shared_ptr<GeomAPI_Edge>(new GeomAPI_Edge(aSelection->value()));
101 } else if(aSelection->context().get() &&
102 aSelection->context()->shape().get() &&
103 aSelection->context()->shape()->isEdge()) {
104 anEdge = std::shared_ptr<GeomAPI_Edge>(new GeomAPI_Edge(aSelection->context()->shape()));
107 if(anEdge->isLine()) {
108 anAxis = std::shared_ptr<GeomAPI_Ax1>(new GeomAPI_Ax1(anEdge->line()->location(),
109 anEdge->line()->direction()));
118 double aToAngle = 0.0;
119 double aFromAngle = 0.0;
121 if(string(CREATION_METHOD())->value() == CREATION_METHOD_BY_ANGLES()) {
122 aToAngle = real(TO_ANGLE_ID())->value();
123 aFromAngle = real(FROM_ANGLE_ID())->value();
125 aToAngle = real(TO_OFFSET_ID())->value();
126 aFromAngle = real(FROM_OFFSET_ID())->value();
129 // Getting bounding planes.
130 GeomShapePtr aToShape;
131 GeomShapePtr aFromShape;
133 if(string(CREATION_METHOD())->value() == CREATION_METHOD_BY_PLANES()) {
134 aSelection = selection(TO_OBJECT_ID());
135 if(aSelection.get()) {
136 aToShape = std::dynamic_pointer_cast<GeomAPI_Shape>(aSelection->value());
137 if(!aToShape.get() && aSelection->context().get()) {
138 aToShape = aSelection->context()->shape();
141 aSelection = selection(FROM_OBJECT_ID());
142 if(aSelection.get()) {
143 aFromShape = std::dynamic_pointer_cast<GeomAPI_Shape>(aSelection->value());
144 if(!aFromShape.get() && aSelection->context().get()) {
145 aFromShape = aSelection->context()->shape();
150 // Generating result for each base shape.
151 for(ListOfShape::const_iterator
152 anIter = theBaseShapes.cbegin(); anIter != theBaseShapes.cend(); anIter++) {
153 GeomShapePtr aBaseShape = *anIter;
155 std::shared_ptr<GeomAlgoAPI_Revolution> aRevolAlgo(new GeomAlgoAPI_Revolution(
158 aFromShape, aFromAngle));
159 if(!isMakeShapeValid(aRevolAlgo)) {
163 theMakeShapes.push_back(aRevolAlgo);