1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D -->
3 // File: FeaturesPlugin_Extrusion.cpp
4 // Created: 30 May 2014
5 // Author: Vitaly SMETANNIKOV
7 #include "FeaturesPlugin_Extrusion.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_Prism.h>
17 #include <GeomAPI_Dir.h>
18 #include <GeomAPI_Edge.h>
19 #include <GeomAPI_Lin.h>
21 //=================================================================================================
22 FeaturesPlugin_Extrusion::FeaturesPlugin_Extrusion()
26 //=================================================================================================
27 void FeaturesPlugin_Extrusion::initAttributes()
29 initCompositeSketchAttribtues(InitBaseObjectsList);
31 data()->addAttribute(CREATION_METHOD(), ModelAPI_AttributeString::typeId());
33 data()->addAttribute(TO_SIZE_ID(), ModelAPI_AttributeDouble::typeId());
34 data()->addAttribute(FROM_SIZE_ID(), ModelAPI_AttributeDouble::typeId());
36 data()->addAttribute(TO_OBJECT_ID(), ModelAPI_AttributeSelection::typeId());
37 data()->addAttribute(TO_OFFSET_ID(), ModelAPI_AttributeDouble::typeId());
39 data()->addAttribute(FROM_OBJECT_ID(), ModelAPI_AttributeSelection::typeId());
40 data()->addAttribute(FROM_OFFSET_ID(), ModelAPI_AttributeDouble::typeId());
42 data()->addAttribute(DIRECTION_OBJECT_ID(), ModelAPI_AttributeSelection::typeId());
44 ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), TO_OBJECT_ID());
45 ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), FROM_OBJECT_ID());
46 ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), DIRECTION_OBJECT_ID());
48 initCompositeSketchAttribtues(InitSketchLauncher);
51 //=================================================================================================
52 void FeaturesPlugin_Extrusion::execute()
54 ListOfShape aBaseShapesList;
55 ListOfMakeShape aMakeShapesList;
58 if(!makeExtrusions(aBaseShapesList, aMakeShapesList)) {
64 ListOfShape::const_iterator aBaseIt = aBaseShapesList.cbegin();
65 ListOfMakeShape::const_iterator anAlgoIt = aMakeShapesList.cbegin();
66 for(; aBaseIt != aBaseShapesList.cend() && anAlgoIt != aMakeShapesList.cend();
67 ++aBaseIt, ++anAlgoIt) {
68 storeResult(*aBaseIt, *anAlgoIt, aResultIndex++);
71 removeResults(aResultIndex);
74 //=================================================================================================
75 bool FeaturesPlugin_Extrusion::makeExtrusions(ListOfShape& theBaseShapes,
76 ListOfMakeShape& theMakeShapes)
78 theMakeShapes.clear();
80 // Getting base shapes.
81 getBaseShapes(theBaseShapes);
84 std::shared_ptr<GeomAPI_Dir> aDir;
85 std::shared_ptr<GeomAPI_Edge> anEdge;
86 AttributeSelectionPtr aSelection = selection(DIRECTION_OBJECT_ID());
87 if(aSelection.get() && aSelection->value().get() && aSelection->value()->isEdge()) {
88 anEdge = std::shared_ptr<GeomAPI_Edge>(new GeomAPI_Edge(aSelection->value()));
89 } else if(aSelection->context().get() &&
90 aSelection->context()->shape().get() &&
91 aSelection->context()->shape()->isEdge()) {
92 anEdge = std::shared_ptr<GeomAPI_Edge>(new GeomAPI_Edge(aSelection->context()->shape()));
95 if(anEdge->isLine()) {
96 aDir = anEdge->line()->direction();
101 double aToSize = 0.0;
102 double aFromSize = 0.0;
104 if(string(CREATION_METHOD())->value() == CREATION_METHOD_BY_SIZES()) {
105 aToSize = real(TO_SIZE_ID())->value();
106 aFromSize = real(FROM_SIZE_ID())->value();
108 aToSize = real(TO_OFFSET_ID())->value();
109 aFromSize = real(FROM_OFFSET_ID())->value();
112 // Getting bounding planes.
113 GeomShapePtr aToShape;
114 GeomShapePtr aFromShape;
116 if(string(CREATION_METHOD())->value() == CREATION_METHOD_BY_PLANES()) {
117 aSelection = selection(TO_OBJECT_ID());
118 if(aSelection.get()) {
119 aToShape = std::dynamic_pointer_cast<GeomAPI_Shape>(aSelection->value());
120 if(!aToShape.get() && aSelection->context().get()) {
121 aToShape = aSelection->context()->shape();
124 aSelection = selection(FROM_OBJECT_ID());
125 if(aSelection.get()) {
126 aFromShape = std::dynamic_pointer_cast<GeomAPI_Shape>(aSelection->value());
127 if(!aFromShape.get() && aSelection->context().get()) {
128 aFromShape = aSelection->context()->shape();
133 // Generating result for each base shape.
134 for(ListOfShape::const_iterator
135 anIter = theBaseShapes.cbegin(); anIter != theBaseShapes.cend(); anIter++) {
136 std::shared_ptr<GeomAPI_Shape> aBaseShape = *anIter;
138 std::shared_ptr<GeomAlgoAPI_Prism> aPrismAlgo(new GeomAlgoAPI_Prism(aBaseShape, aDir,
140 aFromShape, aFromSize));
141 if(!isMakeShapeValid(aPrismAlgo)) {
145 theMakeShapes.push_back(aPrismAlgo);