Salome HOME
Issue #273: Add copyright string
[modules/shaper.git] / src / GeomAlgoAPI / GeomAlgoAPI_Extrusion.cpp
index b81b0f5fe2b1fa09b9a9150b70ac6ba4dac3f7d7..29c4aec277baa4167af118b36f05d4f343f9e261 100644 (file)
@@ -1,3 +1,5 @@
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
 // File:        GeomAlgoAPI_Extrusion.cpp
 // Created:     06 Jun 2014
 // Author:      Artem ZHIDKOV
@@ -5,7 +7,7 @@
 #include <GeomAlgoAPI_Extrusion.h>
 #include <GeomAlgoAPI_MakeShape.h>
 #include <GeomAlgoAPI_DFLoader.h>
-#include <GeomAlgoAPI_DFLoader.h>
+#include <GeomAlgoAPI_MakeShape.h>
 #include <gp_Pln.hxx>
 #include <BRepPrimAPI_MakePrism.hxx>
 #include <BRepBuilderAPI_MakeShape.hxx>
 #include <TopTools_ListIteratorOfListOfShape.hxx>
 #include <Precision.hxx>
 #include <TDF_TagSource.hxx>
-#include <boost/shared_ptr.hpp>
+#include <memory>
 #include <BRepPrimAPI_MakePrism.hxx>
 #include <TopoDS_Shape.hxx>
 
 const double tolerance = Precision::Angular();
 // Constructor
 GeomAlgoAPI_Extrusion::GeomAlgoAPI_Extrusion(
-  boost::shared_ptr<GeomAPI_Shape> theBasis, double theSize)
-: mySize(theSize), myDone(false),
-  myShape(new GeomAPI_Shape()), myFirst(new GeomAPI_Shape()), myLast(new GeomAPI_Shape())
+  std::shared_ptr<GeomAPI_Shape> theBasis, double theSize)
+: mySize(theSize), myDone(false), myShape(new GeomAPI_Shape()),
+  myFirst(new GeomAPI_Shape()), myLast(new GeomAPI_Shape())
 {
   build(theBasis);
 }
 
 //============================================================================
-void GeomAlgoAPI_Extrusion::build(const boost::shared_ptr<GeomAPI_Shape>& theBasis)
+void GeomAlgoAPI_Extrusion::build(const std::shared_ptr<GeomAPI_Shape>& theBasis)
 {
   bool isFirstNorm = true;
   gp_Dir aShapeNormal;
-
-  //const TopoDS_Shape& aShape = theShape->impl<TopoDS_Shape>(); 
   TopoDS_Face aBasis = TopoDS::Face(theBasis->impl<TopoDS_Shape>());
   Handle(Geom_Plane) aPlane = Handle(Geom_Plane)::DownCast(
     BRep_Tool::Surface(aBasis));
@@ -54,21 +54,24 @@ void GeomAlgoAPI_Extrusion::build(const boost::shared_ptr<GeomAPI_Shape>& theBas
   if(aBuilder) {
     setImpl(aBuilder);
     myDone = aBuilder->IsDone() == Standard_True;
-    if (myDone) {
-      BRepCheck_Analyzer aChecker(aBuilder->Shape());
-      myDone = aChecker.IsValid() == Standard_True;
-    }
-    if(myDone) {
+    if (myDone) {       
       TopoDS_Shape aResult;
       if(aBuilder->Shape().ShapeType() == TopAbs_COMPOUND) 
         aResult = GeomAlgoAPI_DFLoader::refineResult(aBuilder->Shape());
       else
         aResult = aBuilder->Shape();
+         // fill data map to keep correct orientation of sub-shapes 
+         for (TopExp_Explorer Exp(aResult,TopAbs_FACE); Exp.More(); Exp.Next()) {
+           std::shared_ptr<GeomAPI_Shape> aCurrentShape(new GeomAPI_Shape());
+        aCurrentShape->setImpl(new TopoDS_Shape(Exp.Current()));
+           myMap.bind(aCurrentShape, aCurrentShape);
+         }   
       myShape->setImpl(new TopoDS_Shape(aResult));
       myFirst->setImpl(new TopoDS_Shape(aBuilder->FirstShape()));
       myLast->setImpl(new TopoDS_Shape(aBuilder-> LastShape()));
-    }
-  }    
+         myMkShape = new GeomAlgoAPI_MakeShape (aBuilder);
+       }  
+  }
 }
 
 //============================================================================
@@ -78,7 +81,8 @@ const bool GeomAlgoAPI_Extrusion::isDone() const
 //============================================================================
 const bool GeomAlgoAPI_Extrusion::isValid() const
 {
-  return myDone;
+       BRepCheck_Analyzer aChecker(myShape->impl<TopoDS_Shape>());
+    return (aChecker.IsValid() == Standard_True);
 }
 
 //============================================================================
@@ -96,104 +100,39 @@ const bool GeomAlgoAPI_Extrusion::hasVolume() const
 }
 
 //============================================================================
-const boost::shared_ptr<GeomAPI_Shape>& GeomAlgoAPI_Extrusion::shape () const 
-{return myShape;}
-
-//============================================================================
-void GeomAlgoAPI_Extrusion::generated(
-  const boost::shared_ptr<GeomAPI_Shape> theShape, ListOfShape& theHistory)
+const std::shared_ptr<GeomAPI_Shape>& GeomAlgoAPI_Extrusion::shape () const 
 {
-  theHistory.clear();
-  if(myDone) {
-    const TopTools_ListOfShape& aList = implPtr<BRepPrimAPI_MakePrism>()
-      ->Generated(theShape->impl<TopoDS_Shape>());
-    TopTools_ListIteratorOfListOfShape it(aList);
-    for(;it.More();it.Next()) {
-      boost::shared_ptr<GeomAPI_Shape> aShape(new GeomAPI_Shape());
-      aShape->setImpl(&(it.Value()));
-      theHistory.push_back(aShape);
-    }
-  }
+  return myShape;
 }
 
 //============================================================================
-const boost::shared_ptr<GeomAPI_Shape>& GeomAlgoAPI_Extrusion::firstShape()
+const std::shared_ptr<GeomAPI_Shape>& GeomAlgoAPI_Extrusion::firstShape()
 {
   return myFirst;
 }
 
 //============================================================================
-const boost::shared_ptr<GeomAPI_Shape>& GeomAlgoAPI_Extrusion::lastShape()
+const std::shared_ptr<GeomAPI_Shape>& GeomAlgoAPI_Extrusion::lastShape()
 {
   return myLast;
 }
 
 //============================================================================
-/*
-void GeomAlgoAPI_Extrusion::LoadNamingDS(boost::shared_ptr<ModelAPI_ResultBody> theResultBody, 
-boost::shared_ptr<GeomAPI_Shape> theContext)
+void GeomAlgoAPI_Extrusion::mapOfShapes (GeomAPI_DataMapOfShapeShape& theMap) const
 {
-if(isValid()) {
-const TopoDS_Shape& aShape = myBuilder->Shape();
-TopoDS_Shape aResult = GeomAlgoAPI_DFLoader::refineResult(aShape);
-boost::shared_ptr<Model_Data> aData = boost::dynamic_pointer_cast<Model_Data>(theResultBody->data());
-if (aData) {
-const TDF_Label& aShapeLab = aData->shapeLab();
-const Handle(TDF_TagSource)& Tagger = TDF_TagSource::Set(aShapeLab);
-if (Tagger.IsNull()) return;
-Tagger->Set(0);
-
-TNaming_Builder aBuilder (aShapeLab);
-if(myBasis.IsEqual(theContext->impl<TopoDS_Shape>()))
-aBuilder.Generated(aResult);
-else
-aBuilder.Generated(theContext->impl<TopoDS_Shape>(), aResult);
-
-TopTools_DataMapOfShapeShape aSubShapes;
-for (TopExp_Explorer Exp(aResult,TopAbs_FACE); Exp.More(); Exp.Next()) {
-aSubShapes.Bind(Exp.Current(),Exp.Current());
-}
-
-//Insert lateral face : Face from Edge
-TNaming_Builder  aLateralFaceBuilder(aShapeLab.NewChild());
-GeomAlgoAPI_DFLoader::loadAndOrientGeneratedShapes(*myBuilder, myBasis, TopAbs_EDGE, aLateralFaceBuilder, aSubShapes);
-
-//Insert bottom face
-TopoDS_Shape aBottomFace = myBuilder->FirstShape();
-if (!aBottomFace.IsNull()) {
-if (aBottomFace.ShapeType() != TopAbs_COMPOUND) {
-TNaming_Builder aBottomBuilder(aShapeLab.NewChild());  //2
-if (aSubShapes.IsBound(aBottomFace)) {
-aBottomFace = aSubShapes(aBottomFace);
-}
-aBottomBuilder.Generated(aBottomFace);
-} else {
-TopoDS_Iterator itr(aBottomFace);
-for (; itr.More(); itr.Next()) {
-TNaming_Builder aBottomBuilder(aShapeLab.NewChild());
-aBottomBuilder.Generated(itr.Value());
-}
+  theMap = myMap;
 }
 
+//============================================================================
+GeomAlgoAPI_MakeShape * GeomAlgoAPI_Extrusion::makeShape() const
+{
+  return myMkShape;
 }
 
-//Insert top face
-TopoDS_Shape aTopFace = myBuilder->LastShape();
-if (!aTopFace.IsNull()) {
-if (aTopFace.ShapeType() != TopAbs_COMPOUND) {
-TNaming_Builder aTopBuilder(aShapeLab.NewChild()); //3
-if (aSubShapes.IsBound(aTopFace)) {
-aTopFace = aSubShapes(aTopFace);
-}
-aTopBuilder.Generated(aTopFace);
-} else {
-TopoDS_Iterator itr(aTopFace);
-for (; itr.More(); itr.Next()) {
-TNaming_Builder aTopBuilder(aShapeLab.NewChild());
-aTopBuilder.Generated(itr.Value());
-}
-}
-}
-}
-}
-*/
\ No newline at end of file
+//============================================================================
+GeomAlgoAPI_Extrusion::~GeomAlgoAPI_Extrusion()
+{
+  if (myImpl) {    
+       myMap.clear();
+  }
+}
\ No newline at end of file