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 //=================================================================================================
18 FeaturesPlugin_Extrusion::FeaturesPlugin_Extrusion()
22 //=================================================================================================
23 void FeaturesPlugin_Extrusion::initAttributes()
25 initCompositeSketchAttribtues(InitBaseObjectsList);
27 data()->addAttribute(CREATION_METHOD(), ModelAPI_AttributeString::typeId());
29 data()->addAttribute(TO_SIZE_ID(), ModelAPI_AttributeDouble::typeId());
30 data()->addAttribute(FROM_SIZE_ID(), ModelAPI_AttributeDouble::typeId());
32 data()->addAttribute(TO_OBJECT_ID(), ModelAPI_AttributeSelection::typeId());
33 data()->addAttribute(TO_OFFSET_ID(), ModelAPI_AttributeDouble::typeId());
35 data()->addAttribute(FROM_OBJECT_ID(), ModelAPI_AttributeSelection::typeId());
36 data()->addAttribute(FROM_OFFSET_ID(), ModelAPI_AttributeDouble::typeId());
38 data()->addAttribute(DIRECTION_OBJECT_ID(), ModelAPI_AttributeSelection::typeId());
40 ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), TO_OBJECT_ID());
41 ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), FROM_OBJECT_ID());
42 ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), DIRECTION_OBJECT_ID());
44 initCompositeSketchAttribtues(InitSketchLauncher);
47 //=================================================================================================
48 void FeaturesPlugin_Extrusion::execute()
50 ListOfShape aBaseShapesList;
51 ListOfMakeShape aMakeShapesList;
54 if(!makeExtrusions(aBaseShapesList, aMakeShapesList)) {
60 ListOfShape::const_iterator aBaseIt = aBaseShapesList.cbegin();
61 ListOfMakeShape::const_iterator anAlgoIt = aMakeShapesList.cbegin();
62 for(; aBaseIt != aBaseShapesList.cend() && anAlgoIt != aMakeShapesList.cend(); ++aBaseIt, ++anAlgoIt) {
63 storeResult(*aBaseIt, *anAlgoIt, aResultIndex++);
66 removeResults(aResultIndex);
69 //=================================================================================================
70 bool FeaturesPlugin_Extrusion::makeExtrusions(ListOfShape& theBaseShapes,
71 ListOfMakeShape& theMakeShapes)
73 theMakeShapes.clear();
75 /// Sub-feature of the composite should be set in the base list.
76 setSketchObjectToList();
78 // Getting base shapes.
79 getBaseShapes(theBaseShapes);
83 double aFromSize = 0.0;
85 if(string(CREATION_METHOD())->value() == "BySizes") {
86 aToSize = real(TO_SIZE_ID())->value();
87 aFromSize = real(FROM_SIZE_ID())->value();
89 aToSize = real(TO_OFFSET_ID())->value();
90 aFromSize = real(FROM_OFFSET_ID())->value();
93 // Getting bounding planes.
94 GeomShapePtr aToShape;
95 GeomShapePtr aFromShape;
97 if(string(CREATION_METHOD())->value() == "ByPlanesAndOffsets") {
98 AttributeSelectionPtr aSelection = selection(TO_OBJECT_ID());
99 if(aSelection.get()) {
100 aToShape = std::dynamic_pointer_cast<GeomAPI_Shape>(aSelection->value());
101 if(!aToShape.get() && aSelection->context().get()) {
102 aToShape = aSelection->context()->shape();
105 aSelection = selection(FROM_OBJECT_ID());
106 if(aSelection.get()) {
107 aFromShape = std::dynamic_pointer_cast<GeomAPI_Shape>(aSelection->value());
108 if(!aFromShape.get() && aSelection->context().get()) {
109 aFromShape = aSelection->context()->shape();
114 // Generating result for each base shape.
115 for(ListOfShape::const_iterator anIter = theBaseShapes.cbegin(); anIter != theBaseShapes.cend(); anIter++) {
116 std::shared_ptr<GeomAPI_Shape> aBaseShape = *anIter;
118 std::shared_ptr<GeomAlgoAPI_Prism> aPrismAlgo(new GeomAlgoAPI_Prism(aBaseShape,
120 aFromShape, aFromSize));
121 if(!isMakeShapeValid(aPrismAlgo)) {
125 theMakeShapes.push_back(aPrismAlgo);