Salome HOME
SketchShapePlugin package is removed as not used.
[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<GeomAlgoAPI_MakeShape>& theMakeShape)
43 {
44   // Getting extrusion sizes.
45   double aToSize = 0.0;
46   double aFromSize = 0.0;
47
48   if(string(CREATION_METHOD())->value() == "BySizes") {
49     aToSize = real(TO_SIZE_ID())->value();
50     aFromSize =  real(FROM_SIZE_ID())->value();
51   } else {
52     aToSize = real(TO_OFFSET_ID())->value();
53     aFromSize =  real(FROM_OFFSET_ID())->value();
54   }
55
56   // Getting extrusion bounding planes.
57   std::shared_ptr<GeomAPI_Shape> aToShape;
58   std::shared_ptr<GeomAPI_Shape> aFromShape;
59
60   if(string(CREATION_METHOD())->value() == "ByPlanesAndOffsets") {
61     std::shared_ptr<ModelAPI_AttributeSelection> anObjRef = selection(TO_OBJECT_ID());
62     if(anObjRef.get() != NULL) {
63       aToShape = std::dynamic_pointer_cast<GeomAPI_Shape>(anObjRef->value());
64       if(aToShape.get() == NULL && anObjRef->context().get() != NULL) {
65         aToShape =  anObjRef->context()->shape();
66       }
67     }
68     anObjRef = selection(FROM_OBJECT_ID());
69     if(anObjRef.get() != NULL) {
70       aFromShape = std::dynamic_pointer_cast<GeomAPI_Shape>(anObjRef->value());
71       if(aFromShape.get() == NULL && anObjRef->context().get() != NULL) {
72         aFromShape = anObjRef->context()->shape();
73       }
74     }
75   }
76
77   // Extrude face
78   std::shared_ptr<GeomAlgoAPI_Prism> aPrismAlgo(new GeomAlgoAPI_Prism(theFace, aToShape, aToSize, aFromShape, aFromSize));
79
80   // Checking that the algorithm worked properly.
81   if(!aPrismAlgo->isDone() || !aPrismAlgo->shape().get() || aPrismAlgo->shape()->isNull() ||
82      !aPrismAlgo->isValid()) {
83     return;
84   }
85
86   theMakeShape = aPrismAlgo;
87 }