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<GeomAlgoAPI_MakeShape>& theMakeShape)
44 // Getting extrusion sizes.
46 double aFromSize = 0.0;
48 if(string(CREATION_METHOD())->value() == "BySizes") {
49 aToSize = real(TO_SIZE_ID())->value();
50 aFromSize = real(FROM_SIZE_ID())->value();
52 aToSize = real(TO_OFFSET_ID())->value();
53 aFromSize = real(FROM_OFFSET_ID())->value();
56 // Getting extrusion bounding planes.
57 std::shared_ptr<GeomAPI_Shape> aToShape;
58 std::shared_ptr<GeomAPI_Shape> aFromShape;
60 if(string(CREATION_METHOD())->value() == "ByPlanesAndOffsets") {
61 std::shared_ptr<ModelAPI_AttributeSelection> anObjRef = selection(TO_OBJECT_ID());
62 if(anObjRef.get() != NULL) {
63 aToShape = std::dynamic_pointer_cast<GeomAPI_Shape>(anObjRef->value());
64 if(aToShape.get() == NULL && anObjRef->context().get() != NULL) {
65 aToShape = anObjRef->context()->shape();
68 anObjRef = selection(FROM_OBJECT_ID());
69 if(anObjRef.get() != NULL) {
70 aFromShape = std::dynamic_pointer_cast<GeomAPI_Shape>(anObjRef->value());
71 if(aFromShape.get() == NULL && anObjRef->context().get() != NULL) {
72 aFromShape = anObjRef->context()->shape();
78 std::shared_ptr<GeomAlgoAPI_Prism> aPrismAlgo(new GeomAlgoAPI_Prism(theFace, aToShape, aToSize, aFromShape, aFromSize));
80 // Checking that the algorithm worked properly.
81 if(!aPrismAlgo->isDone() || !aPrismAlgo->shape().get() || aPrismAlgo->shape()->isNull() ||
82 !aPrismAlgo->isValid()) {
86 theMakeShape = aPrismAlgo;