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_Session.h>
12 #include <ModelAPI_Validator.h>
14 #include <GeomAlgoAPI_Prism.h>
16 //=================================================================================================
17 void FeaturesPlugin_ExtrusionBoolean::initMakeSolidsAttributes()
19 data()->addAttribute(FROM_OBJECT_ID(), ModelAPI_AttributeSelection::typeId());
20 data()->addAttribute(FROM_SIZE_ID(), ModelAPI_AttributeDouble::typeId());
22 data()->addAttribute(TO_OBJECT_ID(), ModelAPI_AttributeSelection::typeId());
23 data()->addAttribute(TO_SIZE_ID(), ModelAPI_AttributeDouble::typeId());
25 ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), FROM_OBJECT_ID());
26 ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), TO_OBJECT_ID());
29 //=================================================================================================
30 ListOfShape FeaturesPlugin_ExtrusionBoolean::MakeSolids(const ListOfShape& theFaces)
32 // Getting extrusion bounding planes.
33 std::shared_ptr<GeomAPI_Shape> aFromShape;
34 std::shared_ptr<GeomAPI_Shape> aToShape;
35 std::shared_ptr<ModelAPI_AttributeSelection> anObjRef = selection(FROM_OBJECT_ID());
37 aFromShape = std::dynamic_pointer_cast<GeomAPI_Shape>(anObjRef->value());
39 anObjRef = selection(TO_OBJECT_ID());
41 aToShape = std::dynamic_pointer_cast<GeomAPI_Shape>(anObjRef->value());
44 // Getting extrusion sizes.
45 double aFromSize = real(FROM_SIZE_ID())->value();
46 double aToSize = real(TO_SIZE_ID())->value();
49 ListOfShape anExtrusionList;
50 for(ListOfShape::const_iterator aFacesIt = theFaces.begin(); aFacesIt != theFaces.end(); aFacesIt++) {
51 std::shared_ptr<GeomAPI_Shape> aBaseShape = *aFacesIt;
52 GeomAlgoAPI_Prism aPrismAlgo(aBaseShape, aFromShape, aFromSize, aToShape, aToSize);
54 // Checking that the algorithm worked properly.
55 if(!aPrismAlgo.isDone() || aPrismAlgo.shape()->isNull() || !aPrismAlgo.isValid()) {
56 setError("Extrusion algorithm failed");
59 anExtrusionList.push_back(aPrismAlgo.shape());
62 return anExtrusionList;