1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
3 // File: FeaturesPlugin_ExtrusionSketch.cpp
4 // Created: 11 September 2015
5 // Author: Dmitry Bobylev
7 #include <FeaturesPlugin_ExtrusionSketch.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_ExtrusionSketch::FeaturesPlugin_ExtrusionSketch()
22 //=================================================================================================
23 void FeaturesPlugin_ExtrusionSketch::initMakeSolidsAttributes()
25 data()->addAttribute(CREATION_METHOD(), ModelAPI_AttributeString::typeId());
27 data()->addAttribute(TO_SIZE_ID(), ModelAPI_AttributeDouble::typeId());
28 data()->addAttribute(FROM_SIZE_ID(), ModelAPI_AttributeDouble::typeId());
30 data()->addAttribute(TO_OBJECT_ID(), ModelAPI_AttributeSelection::typeId());
31 data()->addAttribute(TO_OFFSET_ID(), ModelAPI_AttributeDouble::typeId());
33 data()->addAttribute(FROM_OBJECT_ID(), ModelAPI_AttributeSelection::typeId());
34 data()->addAttribute(FROM_OFFSET_ID(), ModelAPI_AttributeDouble::typeId());
36 ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), TO_OBJECT_ID());
37 ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), FROM_OBJECT_ID());
40 //=================================================================================================
41 void FeaturesPlugin_ExtrusionSketch::makeSolid(const std::shared_ptr<GeomAPI_Shape> theFace,
42 std::shared_ptr<GeomAPI_Shape>& theResult,
43 ListOfShape& theFromFaces,
44 ListOfShape& theToFaces,
45 std::shared_ptr<GeomAlgoAPI_MakeShape>& theMakeShape,
46 std::shared_ptr<GeomAPI_DataMapOfShapeShape>& theDataMap)
48 // Getting extrusion sizes.
50 double aFromSize = 0.0;
52 if(string(CREATION_METHOD())->value() == "BySizes") {
53 aToSize = real(TO_SIZE_ID())->value();
54 aFromSize = real(FROM_SIZE_ID())->value();
56 aToSize = real(TO_OFFSET_ID())->value();
57 aFromSize = real(FROM_OFFSET_ID())->value();
60 // Getting extrusion bounding planes.
61 std::shared_ptr<GeomAPI_Shape> aToShape;
62 std::shared_ptr<GeomAPI_Shape> aFromShape;
64 if(string(CREATION_METHOD())->value() == "ByPlanesAndOffsets") {
65 std::shared_ptr<ModelAPI_AttributeSelection> anObjRef = selection(TO_OBJECT_ID());
66 if(anObjRef.get() != NULL) {
67 aToShape = std::dynamic_pointer_cast<GeomAPI_Shape>(anObjRef->value());
68 if(aToShape.get() == NULL && anObjRef->context().get() != NULL) {
69 aToShape = anObjRef->context()->shape();
72 anObjRef = selection(FROM_OBJECT_ID());
73 if(anObjRef.get() != NULL) {
74 aFromShape = std::dynamic_pointer_cast<GeomAPI_Shape>(anObjRef->value());
75 if(aFromShape.get() == NULL && anObjRef->context().get() != NULL) {
76 aFromShape = anObjRef->context()->shape();
82 GeomAlgoAPI_Prism aPrismAlgo(theFace, aToShape, aToSize, aFromShape, aFromSize);
84 // Checking that the algorithm worked properly.
85 if(!aPrismAlgo.isDone() || !aPrismAlgo.shape().get() || aPrismAlgo.shape()->isNull() ||
86 !aPrismAlgo.isValid()) {
90 theResult = aPrismAlgo.shape();
91 theFromFaces = aPrismAlgo.fromFaces();
92 theToFaces = aPrismAlgo.toFaces();
93 theMakeShape = aPrismAlgo.makeShape();
94 theDataMap = aPrismAlgo.mapOfShapes();