1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
3 // File: FeaturesPlugin_ExtrusionBoolean.cpp
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 void FeaturesPlugin_ExtrusionBoolean::makeSolids(const ListOfShape& theFaces,
37 ListOfShape& theResults,
38 ListOfMakeShape& theAlgos)
40 // Getting extrusion sizes.
42 double aFromSize = 0.0;
44 if(string(CREATION_METHOD())->value() == "BySizes") {
45 aToSize = real(TO_SIZE_ID())->value();
46 aFromSize = real(FROM_SIZE_ID())->value();
48 aToSize = real(TO_OFFSET_ID())->value();
49 aFromSize = real(FROM_OFFSET_ID())->value();
52 // Getting extrusion bounding planes.
53 std::shared_ptr<GeomAPI_Shape> aToShape;
54 std::shared_ptr<GeomAPI_Shape> aFromShape;
56 if(string(CREATION_METHOD())->value() == "ByPlanesAndOffsets") {
57 std::shared_ptr<ModelAPI_AttributeSelection> anObjRef = selection(TO_OBJECT_ID());
58 if(anObjRef.get() != NULL) {
59 aToShape = std::dynamic_pointer_cast<GeomAPI_Shape>(anObjRef->value());
60 if(aToShape.get() == NULL && anObjRef->context().get() != NULL) {
61 aToShape = anObjRef->context()->shape();
64 anObjRef = selection(FROM_OBJECT_ID());
65 if(anObjRef.get() != NULL) {
66 aFromShape = std::dynamic_pointer_cast<GeomAPI_Shape>(anObjRef->value());
67 if(aFromShape.get() == NULL && anObjRef->context().get() != NULL) {
68 aFromShape = anObjRef->context()->shape();
75 for(ListOfShape::const_iterator aFacesIt = theFaces.begin(); aFacesIt != theFaces.end(); aFacesIt++) {
76 std::shared_ptr<GeomAPI_Shape> aBaseShape = *aFacesIt;
77 std::shared_ptr<GeomAlgoAPI_Prism> aPrismAlgo = std::shared_ptr<GeomAlgoAPI_Prism>(new GeomAlgoAPI_Prism(aBaseShape, aToShape, aToSize, aFromShape, aFromSize));
79 // Checking that the algorithm worked properly.
80 if(!aPrismAlgo->isDone() || !aPrismAlgo->shape().get() || aPrismAlgo->shape()->isNull() ||
81 !aPrismAlgo->isValid()) {
82 setError("Error: Extrusion algorithm failed.");
86 theResults.push_back(aPrismAlgo->shape());
87 theAlgos.push_back(aPrismAlgo);