Salome HOME
Merge branch 'Dev_1.5.0' into BR_REENTRANCE_OPERATION
[modules/shaper.git] / src / FeaturesPlugin / FeaturesPlugin_ExtrusionSketch.cpp
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
2
3 // File:        FeaturesPlugin_ExtrusionSketch.cpp
4 // Created:     11 September 2015
5 // Author:      Dmitry Bobylev
6
7 #include <FeaturesPlugin_ExtrusionSketch.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 FeaturesPlugin_ExtrusionSketch::FeaturesPlugin_ExtrusionSketch()
19 {
20 }
21
22 //=================================================================================================
23 void FeaturesPlugin_ExtrusionSketch::initMakeSolidsAttributes()
24 {
25   data()->addAttribute(CREATION_METHOD(), ModelAPI_AttributeString::typeId());
26
27   data()->addAttribute(TO_SIZE_ID(), ModelAPI_AttributeDouble::typeId());
28   data()->addAttribute(FROM_SIZE_ID(), ModelAPI_AttributeDouble::typeId());
29
30   data()->addAttribute(TO_OBJECT_ID(), ModelAPI_AttributeSelection::typeId());
31   data()->addAttribute(TO_OFFSET_ID(), ModelAPI_AttributeDouble::typeId());
32
33   data()->addAttribute(FROM_OBJECT_ID(), ModelAPI_AttributeSelection::typeId());
34   data()->addAttribute(FROM_OFFSET_ID(), ModelAPI_AttributeDouble::typeId());
35
36   ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), TO_OBJECT_ID());
37   ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), FROM_OBJECT_ID());
38 }
39
40 //=================================================================================================
41 void FeaturesPlugin_ExtrusionSketch::makeSolid(const std::shared_ptr<GeomAPI_Shape> theFace,
42                                                std::shared_ptr<GeomAPI_Shape>& theResult,
43                                                ListOfShape& theFromFaces,
44                                                ListOfShape& theToFaces,
45                                                std::shared_ptr<GeomAlgoAPI_MakeShape>& theMakeShape,
46                                                std::shared_ptr<GeomAPI_DataMapOfShapeShape>& theDataMap)
47 {
48   // Getting extrusion sizes.
49   double aToSize = 0.0;
50   double aFromSize = 0.0;
51
52   if(string(CREATION_METHOD())->value() == "BySizes") {
53     aToSize = real(TO_SIZE_ID())->value();
54     aFromSize =  real(FROM_SIZE_ID())->value();
55   } else {
56     aToSize = real(TO_OFFSET_ID())->value();
57     aFromSize =  real(FROM_OFFSET_ID())->value();
58   }
59
60   // Getting extrusion bounding planes.
61   std::shared_ptr<GeomAPI_Shape> aToShape;
62   std::shared_ptr<GeomAPI_Shape> aFromShape;
63
64   if(string(CREATION_METHOD())->value() == "ByPlanesAndOffsets") {
65     std::shared_ptr<ModelAPI_AttributeSelection> anObjRef = selection(TO_OBJECT_ID());
66     if(anObjRef.get() != NULL) {
67       aToShape = std::dynamic_pointer_cast<GeomAPI_Shape>(anObjRef->value());
68       if(aToShape.get() == NULL && anObjRef->context().get() != NULL) {
69         aToShape =  anObjRef->context()->shape();
70       }
71     }
72     anObjRef = selection(FROM_OBJECT_ID());
73     if(anObjRef.get() != NULL) {
74       aFromShape = std::dynamic_pointer_cast<GeomAPI_Shape>(anObjRef->value());
75       if(aFromShape.get() == NULL && anObjRef->context().get() != NULL) {
76         aFromShape = anObjRef->context()->shape();
77       }
78     }
79   }
80
81   // Extrude face
82   GeomAlgoAPI_Prism aPrismAlgo(theFace, aToShape, aToSize, aFromShape, aFromSize);
83
84   // Checking that the algorithm worked properly.
85   if(!aPrismAlgo.isDone() || !aPrismAlgo.shape().get() || aPrismAlgo.shape()->isNull() ||
86      !aPrismAlgo.isValid()) {
87     return;
88   }
89
90   theResult = aPrismAlgo.shape();
91   theFromFaces = aPrismAlgo.fromFaces();
92   theToFaces = aPrismAlgo.toFaces();
93   theMakeShape = aPrismAlgo.makeShape();
94   theDataMap = aPrismAlgo.mapOfShapes();
95 }