1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
3 // File: FeaturesPlugin_ExtrusionBoolean.h
4 // Created: 11 June 2015
5 // Author: Dmitry Bobylev
7 #include <FeaturesPlugin_ExtrusionBoolean.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 void FeaturesPlugin_ExtrusionBoolean::initMakeSolidsAttributes()
20 data()->addAttribute(CREATION_METHOD(), ModelAPI_AttributeString::typeId());
22 data()->addAttribute(TO_SIZE_ID(), ModelAPI_AttributeDouble::typeId());
23 data()->addAttribute(FROM_SIZE_ID(), ModelAPI_AttributeDouble::typeId());
25 data()->addAttribute(TO_OBJECT_ID(), ModelAPI_AttributeSelection::typeId());
26 data()->addAttribute(TO_OFFSET_ID(), ModelAPI_AttributeDouble::typeId());
28 data()->addAttribute(FROM_OBJECT_ID(), ModelAPI_AttributeSelection::typeId());
29 data()->addAttribute(FROM_OFFSET_ID(), ModelAPI_AttributeDouble::typeId());
31 ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), TO_OBJECT_ID());
32 ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), FROM_OBJECT_ID());
35 //=================================================================================================
36 ListOfShape FeaturesPlugin_ExtrusionBoolean::MakeSolids(const ListOfShape& theFaces)
38 // Getting extrusion sizes.
40 double aFromSize = 0.0;
42 if(string(CREATION_METHOD())->value() == "BySizes") {
43 aToSize = real(TO_SIZE_ID())->value();
44 aFromSize = real(FROM_SIZE_ID())->value();
46 aToSize = real(TO_OFFSET_ID())->value();
47 aFromSize = real(FROM_OFFSET_ID())->value();
50 // Getting extrusion bounding planes.
51 std::shared_ptr<GeomAPI_Shape> aToShape;
52 std::shared_ptr<GeomAPI_Shape> aFromShape;
54 if(string(CREATION_METHOD())->value() == "ByPlanesAndOffsets") {
55 std::shared_ptr<ModelAPI_AttributeSelection> anObjRef = selection(TO_OBJECT_ID());
56 if(anObjRef.get() != NULL) {
57 aToShape = std::dynamic_pointer_cast<GeomAPI_Shape>(anObjRef->value());
58 if(aToShape.get() == NULL && anObjRef->context().get() != NULL) {
59 aToShape = anObjRef->context()->shape();
62 anObjRef = selection(FROM_OBJECT_ID());
63 if(anObjRef.get() != NULL) {
64 aFromShape = std::dynamic_pointer_cast<GeomAPI_Shape>(anObjRef->value());
65 if(aFromShape.get() == NULL && anObjRef->context().get() != NULL) {
66 aFromShape = anObjRef->context()->shape();
72 ListOfShape anExtrusionList;
73 for(ListOfShape::const_iterator aFacesIt = theFaces.begin(); aFacesIt != theFaces.end(); aFacesIt++) {
74 std::shared_ptr<GeomAPI_Shape> aBaseShape = *aFacesIt;
75 GeomAlgoAPI_Prism aPrismAlgo(aBaseShape, aToShape, aToSize, aFromShape, aFromSize);
77 // Checking that the algorithm worked properly.
78 if(!aPrismAlgo.isDone() || aPrismAlgo.shape()->isNull() || !aPrismAlgo.isValid()) {
79 setError("Extrusion algorithm failed");
82 anExtrusionList.push_back(aPrismAlgo.shape());
85 return anExtrusionList;