Salome HOME
Composite features update due to changes in Extrusion and Revolution algos
[modules/shaper.git] / src / FeaturesPlugin / FeaturesPlugin_ExtrusionBoolean.cpp
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
2
3 // File:        FeaturesPlugin_ExtrusionBoolean.cpp
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_AttributeString.h>
12 #include <ModelAPI_Session.h>
13 #include <ModelAPI_Validator.h>
14
15 #include <GeomAlgoAPI_Prism.h>
16
17 //=================================================================================================
18 void FeaturesPlugin_ExtrusionBoolean::initMakeSolidsAttributes()
19 {
20   data()->addAttribute(CREATION_METHOD(), ModelAPI_AttributeString::typeId());
21
22   data()->addAttribute(TO_SIZE_ID(), ModelAPI_AttributeDouble::typeId());
23   data()->addAttribute(FROM_SIZE_ID(), ModelAPI_AttributeDouble::typeId());
24
25   data()->addAttribute(TO_OBJECT_ID(), ModelAPI_AttributeSelection::typeId());
26   data()->addAttribute(TO_OFFSET_ID(), ModelAPI_AttributeDouble::typeId());
27
28   data()->addAttribute(FROM_OBJECT_ID(), ModelAPI_AttributeSelection::typeId());
29   data()->addAttribute(FROM_OFFSET_ID(), ModelAPI_AttributeDouble::typeId());
30
31   ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), TO_OBJECT_ID());
32   ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), FROM_OBJECT_ID());
33 }
34
35 //=================================================================================================
36 void FeaturesPlugin_ExtrusionBoolean::makeSolids(const ListOfShape& theFaces,
37                                                  ListOfShape& theResults,
38                                                  ListOfMakeShape& theAlgos)
39 {
40   // Getting extrusion sizes.
41   double aToSize = 0.0;
42   double aFromSize = 0.0;
43
44   if(string(CREATION_METHOD())->value() == "BySizes") {
45     aToSize = real(TO_SIZE_ID())->value();
46     aFromSize =  real(FROM_SIZE_ID())->value();
47   } else {
48     aToSize = real(TO_OFFSET_ID())->value();
49     aFromSize =  real(FROM_OFFSET_ID())->value();
50   }
51
52   // Getting extrusion bounding planes.
53   std::shared_ptr<GeomAPI_Shape> aToShape;
54   std::shared_ptr<GeomAPI_Shape> aFromShape;
55
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();
62       }
63     }
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();
69       }
70     }
71   }
72
73   // Extrude faces.
74   theResults.clear();
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));
78
79     // Checking that the algorithm worked properly.
80     if(!aPrismAlgo->isDone() || !aPrismAlgo->shape().get() || aPrismAlgo->shape()->isNull() ||
81        !aPrismAlgo->isValid()) {
82       setError("Extrusion algorithm failed");
83       theResults.clear();
84       return;
85     }
86     theResults.push_back(aPrismAlgo->shape());
87     theAlgos.push_back(aPrismAlgo);
88   }
89 }