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_OBJECT_ID(), ModelAPI_AttributeSelection::typeId());
23 data()->addAttribute(TO_SIZE_ID(), ModelAPI_AttributeDouble::typeId());
25 data()->addAttribute(FROM_OBJECT_ID(), ModelAPI_AttributeSelection::typeId());
26 data()->addAttribute(FROM_SIZE_ID(), ModelAPI_AttributeDouble::typeId());
28 ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), TO_OBJECT_ID());
29 ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), FROM_OBJECT_ID());
32 //=================================================================================================
33 ListOfShape FeaturesPlugin_ExtrusionBoolean::MakeSolids(const ListOfShape& theFaces)
35 // Getting extrusion sizes.
36 double aFromSize = real(FROM_SIZE_ID())->value();
37 double aToSize = real(TO_SIZE_ID())->value();
39 // Getting extrusion bounding planes.
40 std::shared_ptr<GeomAPI_Shape> aFromShape;
41 std::shared_ptr<GeomAPI_Shape> aToShape;
43 if(string(CREATION_METHOD())->value() == "ByPlanesAndOffsets") {
44 std::shared_ptr<ModelAPI_AttributeSelection> anObjRef = selection(FROM_OBJECT_ID());
45 if(anObjRef.get() != NULL) {
46 aFromShape = std::dynamic_pointer_cast<GeomAPI_Shape>(anObjRef->value());
47 if(aFromShape.get() == NULL && anObjRef->context().get() != NULL) {
48 aFromShape = anObjRef->context()->shape();
51 anObjRef = selection(TO_OBJECT_ID());
52 if(anObjRef.get() != NULL) {
53 aToShape = std::dynamic_pointer_cast<GeomAPI_Shape>(anObjRef->value());
54 if(aToShape.get() == NULL && anObjRef->context().get() != NULL) {
55 aToShape = anObjRef->context()->shape();
61 ListOfShape anExtrusionList;
62 for(ListOfShape::const_iterator aFacesIt = theFaces.begin(); aFacesIt != theFaces.end(); aFacesIt++) {
63 std::shared_ptr<GeomAPI_Shape> aBaseShape = *aFacesIt;
64 GeomAlgoAPI_Prism aPrismAlgo(aBaseShape, aToShape, aToSize, aFromShape, aFromSize);
66 // Checking that the algorithm worked properly.
67 if(!aPrismAlgo.isDone() || aPrismAlgo.shape()->isNull() || !aPrismAlgo.isValid()) {
68 setError("Extrusion algorithm failed");
71 anExtrusionList.push_back(aPrismAlgo.shape());
74 return anExtrusionList;