]> SALOME platform Git repositories - modules/shaper.git/blob - src/FeaturesPlugin/FeaturesPlugin_ExtrusionBoolean.cpp
Salome HOME
For for bounding planes selection in 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.get() != NULL) {
37     aFromShape = std::dynamic_pointer_cast<GeomAPI_Shape>(anObjRef->value());
38     if(aFromShape.get() == NULL && anObjRef->context().get() != NULL) {
39       aFromShape = anObjRef->context()->shape();
40     }
41   }
42   anObjRef = selection(TO_OBJECT_ID());
43   if(anObjRef.get() != NULL) {
44     aToShape = std::dynamic_pointer_cast<GeomAPI_Shape>(anObjRef->value());
45     if(aToShape.get() == NULL && anObjRef->context().get() != NULL) {
46       aToShape =  anObjRef->context()->shape();
47     }
48   }
49
50   // Getting extrusion sizes.
51   double aFromSize = real(FROM_SIZE_ID())->value();
52   double aToSize = real(TO_SIZE_ID())->value();
53
54   // Extrude faces.
55   ListOfShape anExtrusionList;
56   for(ListOfShape::const_iterator aFacesIt = theFaces.begin(); aFacesIt != theFaces.end(); aFacesIt++) {
57     std::shared_ptr<GeomAPI_Shape> aBaseShape = *aFacesIt;
58     GeomAlgoAPI_Prism aPrismAlgo(aBaseShape, aFromShape, aFromSize, aToShape, aToSize);
59
60     // Checking that the algorithm worked properly.
61     if(!aPrismAlgo.isDone() || aPrismAlgo.shape()->isNull() || !aPrismAlgo.isValid()) {
62       setError("Extrusion algorithm failed");
63       return ListOfShape();
64     }
65     anExtrusionList.push_back(aPrismAlgo.shape());
66   }
67
68   return anExtrusionList;
69 }