1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
3 // File: FeaturesPlugin_Revolution.cpp
4 // Created: 12 May 2015
5 // Author: Dmitry Bobylev
7 #include "FeaturesPlugin_Revolution.h"
9 #include <ModelAPI_AttributeDouble.h>
10 #include <ModelAPI_AttributeSelection.h>
11 #include <ModelAPI_AttributeString.h>
12 #include <ModelAPI_Session.h>
13 #include <ModelAPI_Validator.h>
15 #include <GeomAlgoAPI_Revolution.h>
17 #include <GeomAPI_Edge.h>
18 #include <GeomAPI_Lin.h>
20 //=================================================================================================
21 FeaturesPlugin_Revolution::FeaturesPlugin_Revolution()
25 //=================================================================================================
26 void FeaturesPlugin_Revolution::initAttributes()
28 initCompositeSketchAttribtues(InitBaseObjectsList);
30 data()->addAttribute(AXIS_OBJECT_ID(), ModelAPI_AttributeSelection::typeId());
32 data()->addAttribute(CREATION_METHOD(), ModelAPI_AttributeString::typeId());
34 data()->addAttribute(TO_ANGLE_ID(), ModelAPI_AttributeDouble::typeId());
35 data()->addAttribute(FROM_ANGLE_ID(), ModelAPI_AttributeDouble::typeId());
37 data()->addAttribute(TO_OBJECT_ID(), ModelAPI_AttributeSelection::typeId());
38 data()->addAttribute(TO_OFFSET_ID(), ModelAPI_AttributeDouble::typeId());
40 data()->addAttribute(FROM_OBJECT_ID(), ModelAPI_AttributeSelection::typeId());
41 data()->addAttribute(FROM_OFFSET_ID(), ModelAPI_AttributeDouble::typeId());
43 ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), TO_OBJECT_ID());
44 ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), FROM_OBJECT_ID());
46 initCompositeSketchAttribtues(InitSketchLauncher);
49 //=================================================================================================
50 void FeaturesPlugin_Revolution::execute()
52 ListOfShape aBaseShapesList;
53 ListOfMakeShape aMakeShapesList;
56 if(!makeRevolutions(aBaseShapesList, aMakeShapesList)) {
62 ListOfShape::const_iterator aBaseIt = aBaseShapesList.cbegin();
63 ListOfMakeShape::const_iterator anAlgoIt = aMakeShapesList.cbegin();
64 for(; aBaseIt != aBaseShapesList.cend() && anAlgoIt != aMakeShapesList.cend(); ++aBaseIt, ++anAlgoIt) {
65 storeResult(*aBaseIt, *anAlgoIt, aResultIndex++);
68 removeResults(aResultIndex);
71 //=================================================================================================
72 bool FeaturesPlugin_Revolution::makeRevolutions(ListOfShape& theBaseShapes,
73 ListOfMakeShape& theMakeShapes)
75 theMakeShapes.clear();
77 // Getting base shapes.
78 getBaseShapes(theBaseShapes);
81 std::shared_ptr<GeomAPI_Ax1> anAxis;
82 std::shared_ptr<GeomAPI_Edge> anEdge;
83 AttributeSelectionPtr aSelection = selection(AXIS_OBJECT_ID());
84 if(aSelection.get() && aSelection->value().get() && aSelection->value()->isEdge()) {
85 anEdge = std::shared_ptr<GeomAPI_Edge>(new GeomAPI_Edge(aSelection->value()));
86 } else if(aSelection->context().get() &&
87 aSelection->context()->shape().get() &&
88 aSelection->context()->shape()->isEdge()) {
89 anEdge = std::shared_ptr<GeomAPI_Edge>(new GeomAPI_Edge(aSelection->context()->shape()));
92 if(anEdge->isLine()) {
93 anAxis = std::shared_ptr<GeomAPI_Ax1>(new GeomAPI_Ax1(anEdge->line()->location(),
94 anEdge->line()->direction()));
103 double aToAngle = 0.0;
104 double aFromAngle = 0.0;
106 if(string(CREATION_METHOD())->value() == CREATION_METHOD_BY_ANGLES()) {
107 aToAngle = real(TO_ANGLE_ID())->value();
108 aFromAngle = real(FROM_ANGLE_ID())->value();
110 aToAngle = real(TO_OFFSET_ID())->value();
111 aFromAngle = real(FROM_OFFSET_ID())->value();
114 // Getting bounding planes.
115 GeomShapePtr aToShape;
116 GeomShapePtr aFromShape;
118 if(string(CREATION_METHOD())->value() == CREATION_METHOD_BY_PLANES()) {
119 aSelection = selection(TO_OBJECT_ID());
120 if(aSelection.get()) {
121 aToShape = std::dynamic_pointer_cast<GeomAPI_Shape>(aSelection->value());
122 if(!aToShape.get() && aSelection->context().get()) {
123 aToShape = aSelection->context()->shape();
126 aSelection = selection(FROM_OBJECT_ID());
127 if(aSelection.get()) {
128 aFromShape = std::dynamic_pointer_cast<GeomAPI_Shape>(aSelection->value());
129 if(!aFromShape.get() && aSelection->context().get()) {
130 aFromShape = aSelection->context()->shape();
135 // Generating result for each base shape.
136 for(ListOfShape::const_iterator anIter = theBaseShapes.cbegin(); anIter != theBaseShapes.cend(); anIter++) {
137 GeomShapePtr aBaseShape = *anIter;
139 std::shared_ptr<GeomAlgoAPI_Revolution> aRevolAlgo(new GeomAlgoAPI_Revolution(aBaseShape, anAxis,
141 aFromShape, aFromAngle));
142 if(!isMakeShapeValid(aRevolAlgo)) {
146 theMakeShapes.push_back(aRevolAlgo);