]> SALOME platform Git repositories - modules/shaper.git/blob - src/FeaturesPlugin/FeaturesPlugin_Extrusion.cpp
Salome HOME
Issue #1343: Architecture changes. Composite features now derived from extrusion...
[modules/shaper.git] / src / FeaturesPlugin / FeaturesPlugin_Extrusion.cpp
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D -->
2
3 // File:        FeaturesPlugin_Extrusion.cpp
4 // Created:     30 May 2014
5 // Author:      Vitaly SMETANNIKOV
6
7 #include "FeaturesPlugin_Extrusion.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_Extrusion::FeaturesPlugin_Extrusion()
19 {
20 }
21
22 //=================================================================================================
23 void FeaturesPlugin_Extrusion::initAttributes()
24 {
25   initCompositeSketchAttribtues(InitBaseObjectsList);
26
27   data()->addAttribute(CREATION_METHOD(), ModelAPI_AttributeString::typeId());
28
29   data()->addAttribute(TO_SIZE_ID(), ModelAPI_AttributeDouble::typeId());
30   data()->addAttribute(FROM_SIZE_ID(), ModelAPI_AttributeDouble::typeId());
31
32   data()->addAttribute(TO_OBJECT_ID(), ModelAPI_AttributeSelection::typeId());
33   data()->addAttribute(TO_OFFSET_ID(), ModelAPI_AttributeDouble::typeId());
34
35   data()->addAttribute(FROM_OBJECT_ID(), ModelAPI_AttributeSelection::typeId());
36   data()->addAttribute(FROM_OFFSET_ID(), ModelAPI_AttributeDouble::typeId());
37
38   data()->addAttribute(DIRECTION_OBJECT_ID(), ModelAPI_AttributeSelection::typeId());
39
40   ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), TO_OBJECT_ID());
41   ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), FROM_OBJECT_ID());
42   ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), DIRECTION_OBJECT_ID());
43
44   initCompositeSketchAttribtues(InitSketchLauncher);
45 }
46
47 //=================================================================================================
48 void FeaturesPlugin_Extrusion::execute()
49 {
50   ListOfShape aBaseShapesList;
51   ListOfMakeShape aMakeShapesList;
52
53   // Make extrusions.
54   if(!makeExtrusions(aBaseShapesList, aMakeShapesList)) {
55     return;
56   }
57
58   // Store results.
59   int aResultIndex = 0;
60   ListOfShape::const_iterator aBaseIt = aBaseShapesList.cbegin();
61   ListOfMakeShape::const_iterator anAlgoIt = aMakeShapesList.cbegin();
62   for(; aBaseIt != aBaseShapesList.cend() && anAlgoIt != aMakeShapesList.cend(); ++aBaseIt, ++anAlgoIt) {
63     storeResult(*aBaseIt, *anAlgoIt, aResultIndex++);
64   }
65
66   removeResults(aResultIndex);
67 }
68
69 //=================================================================================================
70 bool FeaturesPlugin_Extrusion::makeExtrusions(ListOfShape& theBaseShapes,
71                                               ListOfMakeShape& theMakeShapes)
72 {
73   theMakeShapes.clear();
74
75   /// Sub-feature of the composite should be set in the base list.
76   setSketchObjectToList();
77
78   // Getting base shapes.
79   getBaseShapes(theBaseShapes);
80
81   // Getting sizes.
82   double aToSize = 0.0;
83   double aFromSize = 0.0;
84
85   if(string(CREATION_METHOD())->value() == "BySizes") {
86     aToSize = real(TO_SIZE_ID())->value();
87     aFromSize = real(FROM_SIZE_ID())->value();
88   } else {
89     aToSize = real(TO_OFFSET_ID())->value();
90     aFromSize = real(FROM_OFFSET_ID())->value();
91   }
92
93   // Getting bounding planes.
94   GeomShapePtr aToShape;
95   GeomShapePtr aFromShape;
96
97   if(string(CREATION_METHOD())->value() == "ByPlanesAndOffsets") {
98     AttributeSelectionPtr aSelection = selection(TO_OBJECT_ID());
99     if(aSelection.get()) {
100       aToShape = std::dynamic_pointer_cast<GeomAPI_Shape>(aSelection->value());
101       if(!aToShape.get() && aSelection->context().get()) {
102         aToShape = aSelection->context()->shape();
103       }
104     }
105     aSelection = selection(FROM_OBJECT_ID());
106     if(aSelection.get()) {
107       aFromShape = std::dynamic_pointer_cast<GeomAPI_Shape>(aSelection->value());
108       if(!aFromShape.get() && aSelection->context().get()) {
109         aFromShape = aSelection->context()->shape();
110       }
111     }
112   }
113
114   // Generating result for each base shape.
115   for(ListOfShape::const_iterator anIter = theBaseShapes.cbegin(); anIter != theBaseShapes.cend(); anIter++) {
116     std::shared_ptr<GeomAPI_Shape> aBaseShape = *anIter;
117
118     std::shared_ptr<GeomAlgoAPI_Prism> aPrismAlgo(new GeomAlgoAPI_Prism(aBaseShape,
119                                                                         aToShape, aToSize,
120                                                                         aFromShape, aFromSize));
121     if(!isMakeShapeValid(aPrismAlgo)) {
122       return false;
123     }
124
125     theMakeShapes.push_back(aPrismAlgo);
126   }
127
128   return true;
129 }