]> SALOME platform Git repositories - modules/shaper.git/blob - src/FeaturesPlugin/FeaturesPlugin_ExtrusionBoolean.cpp
Salome HOME
Class structure modification for composite features.
[modules/shaper.git] / src / FeaturesPlugin / FeaturesPlugin_ExtrusionBoolean.cpp
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
2
3 // File:        FeaturesPlugin_ExtrusionBoolean.h
4 // Created:     11 June 2015
5 // Author:      Dmitry Bobylev
6
7 #include <FeaturesPlugin_ExtrusionBoolean.h>
8
9 #include <ModelAPI_AttributeDouble.h>
10 #include <ModelAPI_AttributeSelection.h>
11 #include <ModelAPI_Session.h>
12 #include <ModelAPI_Validator.h>
13
14 #include <GeomAlgoAPI_Prism.h>
15
16 //=================================================================================================
17 void FeaturesPlugin_ExtrusionBoolean::initMakeSolidsAttributes()
18 {
19   data()->addAttribute(FROM_OBJECT_ID(), ModelAPI_AttributeSelection::typeId());
20   data()->addAttribute(FROM_SIZE_ID(), ModelAPI_AttributeDouble::typeId());
21
22   data()->addAttribute(TO_OBJECT_ID(), ModelAPI_AttributeSelection::typeId());
23   data()->addAttribute(TO_SIZE_ID(), ModelAPI_AttributeDouble::typeId());
24
25   ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), FROM_OBJECT_ID());
26   ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), TO_OBJECT_ID());
27 }
28
29 //=================================================================================================
30 ListOfShape FeaturesPlugin_ExtrusionBoolean::MakeSolids(const ListOfShape& theFaces)
31 {
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());
36   if (anObjRef) {
37     aFromShape = std::dynamic_pointer_cast<GeomAPI_Shape>(anObjRef->value());
38   }
39   anObjRef = selection(TO_OBJECT_ID());
40   if (anObjRef) {
41     aToShape = std::dynamic_pointer_cast<GeomAPI_Shape>(anObjRef->value());
42   }
43
44   // Getting extrusion sizes.
45   double aFromSize = real(FROM_SIZE_ID())->value();
46   double aToSize = real(TO_SIZE_ID())->value();
47
48   // Extrude faces.
49   ListOfShape anExtrusionList;
50   for(ListOfShape::const_iterator aFacesIt = theFaces.begin(); aFacesIt != theFaces.end(); aFacesIt++) {
51     std::shared_ptr<GeomAPI_Shape> aBaseFace = *aFacesIt;
52     GeomAlgoAPI_Prism aPrismAlgo(aBaseFace, aFromShape, aFromSize, aToShape, aToSize);
53
54     // Checking that the algorithm worked properly.
55     if(!aPrismAlgo.isDone() || aPrismAlgo.shape()->isNull() || !aPrismAlgo.isValid()) {
56       setError("Extrusion algorithm failed");
57       return ListOfShape();
58     }
59     anExtrusionList.push_back(aPrismAlgo.shape());
60   }
61
62   return anExtrusionList;
63 }