Salome HOME
Issue #2082 Sketch multiple rotation does not work as expected: debug information
[modules/shaper.git] / src / FeaturesPlugin / FeaturesPlugin_Extrusion.cpp
index 20b7c254ae2c0148e193db24eea484b9143253eb..c80171dfdeae11f66c764b41432b4e09fcc2ba03 100644 (file)
 
 #include <GeomAlgoAPI_Prism.h>
 
+#include <GeomAPI_Dir.h>
+#include <GeomAPI_Edge.h>
+#include <GeomAPI_Lin.h>
+
 //=================================================================================================
 FeaturesPlugin_Extrusion::FeaturesPlugin_Extrusion()
 {
@@ -59,7 +63,8 @@ void FeaturesPlugin_Extrusion::execute()
   int aResultIndex = 0;
   ListOfShape::const_iterator aBaseIt = aBaseShapesList.cbegin();
   ListOfMakeShape::const_iterator anAlgoIt = aMakeShapesList.cbegin();
-  for(; aBaseIt != aBaseShapesList.cend() && anAlgoIt != aMakeShapesList.cend(); ++aBaseIt, ++anAlgoIt) {
+  for(; aBaseIt != aBaseShapesList.cend() && anAlgoIt != aMakeShapesList.cend();
+        ++aBaseIt, ++anAlgoIt) {
     storeResult(*aBaseIt, *anAlgoIt, aResultIndex++);
   }
 
@@ -72,17 +77,31 @@ bool FeaturesPlugin_Extrusion::makeExtrusions(ListOfShape& theBaseShapes,
 {
   theMakeShapes.clear();
 
-  /// Sub-feature of the composite should be set in the base list.
-  setSketchObjectToList();
-
   // Getting base shapes.
   getBaseShapes(theBaseShapes);
 
+  //Getting direction.
+  std::shared_ptr<GeomAPI_Dir> aDir;
+  std::shared_ptr<GeomAPI_Edge> anEdge;
+  AttributeSelectionPtr aSelection = selection(DIRECTION_OBJECT_ID());
+  if(aSelection.get() && aSelection->value().get() && aSelection->value()->isEdge()) {
+    anEdge = std::shared_ptr<GeomAPI_Edge>(new GeomAPI_Edge(aSelection->value()));
+  } else if(aSelection->context().get() &&
+            aSelection->context()->shape().get() &&
+            aSelection->context()->shape()->isEdge()) {
+    anEdge = std::shared_ptr<GeomAPI_Edge>(new GeomAPI_Edge(aSelection->context()->shape()));
+  }
+  if(anEdge.get()) {
+    if(anEdge->isLine()) {
+      aDir = anEdge->line()->direction();
+    }
+  }
+
   // Getting sizes.
   double aToSize = 0.0;
   double aFromSize = 0.0;
 
-  if(string(CREATION_METHOD())->value() == "BySizes") {
+  if(string(CREATION_METHOD())->value() == CREATION_METHOD_BY_SIZES()) {
     aToSize = real(TO_SIZE_ID())->value();
     aFromSize = real(FROM_SIZE_ID())->value();
   } else {
@@ -94,8 +113,8 @@ bool FeaturesPlugin_Extrusion::makeExtrusions(ListOfShape& theBaseShapes,
   GeomShapePtr aToShape;
   GeomShapePtr aFromShape;
 
-  if(string(CREATION_METHOD())->value() == "ByPlanesAndOffsets") {
-    AttributeSelectionPtr aSelection = selection(TO_OBJECT_ID());
+  if(string(CREATION_METHOD())->value() == CREATION_METHOD_BY_PLANES()) {
+    aSelection = selection(TO_OBJECT_ID());
     if(aSelection.get()) {
       aToShape = std::dynamic_pointer_cast<GeomAPI_Shape>(aSelection->value());
       if(!aToShape.get() && aSelection->context().get()) {
@@ -112,10 +131,11 @@ bool FeaturesPlugin_Extrusion::makeExtrusions(ListOfShape& theBaseShapes,
   }
 
   // Generating result for each base shape.
-  for(ListOfShape::const_iterator anIter = theBaseShapes.cbegin(); anIter != theBaseShapes.cend(); anIter++) {
+  for(ListOfShape::const_iterator
+      anIter = theBaseShapes.cbegin(); anIter != theBaseShapes.cend(); anIter++) {
     std::shared_ptr<GeomAPI_Shape> aBaseShape = *anIter;
 
-    std::shared_ptr<GeomAlgoAPI_Prism> aPrismAlgo(new GeomAlgoAPI_Prism(aBaseShape,
+    std::shared_ptr<GeomAlgoAPI_Prism> aPrismAlgo(new GeomAlgoAPI_Prism(aBaseShape, aDir,
                                                                         aToShape, aToSize,
                                                                         aFromShape, aFromSize));
     if(!isMakeShapeValid(aPrismAlgo)) {