Salome HOME
Prism algo interface changes for more convenient use in nested features.
authordbv <dbv@opencascade.com>
Wed, 10 Jun 2015 13:06:22 +0000 (16:06 +0300)
committerdbv <dbv@opencascade.com>
Wed, 10 Jun 2015 15:05:53 +0000 (18:05 +0300)
src/FeaturesPlugin/FeaturesPlugin_Extrusion.cpp
src/GeomAPI/GeomAPI_Interface.h
src/GeomAlgoAPI/GeomAlgoAPI_Prism.cpp
src/GeomAlgoAPI/GeomAlgoAPI_Prism.h

index 7fd7c13017cb9eed0c3d886f2081a3712240f43e..fa7484b657f0350a272577f2fd859f4df364c759 100644 (file)
@@ -17,8 +17,6 @@
 #include <ModelAPI_AttributeBoolean.h>
 #include <ModelAPI_AttributeString.h>
 #include <ModelAPI_AttributeReference.h>
-#include <GeomAPI_Pln.h>
-#include <GeomAPI_XYZ.h>
 #include <GeomAlgoAPI_Extrusion.h>
 #include <GeomAlgoAPI_FaceBuilder.h>
 #include <GeomAlgoAPI_Prism.h>
@@ -107,37 +105,7 @@ void FeaturesPlugin_Extrusion::execute()
         aBaseShape = std::dynamic_pointer_cast<GeomAPI_Shape>(aConstruction->face(aFaceIndex));
       }
 
-      // If bounding faces was not set creating them.
-      std::shared_ptr<GeomAPI_Face>  aBaseFace(new GeomAPI_Face(aBaseShape));
-      std::shared_ptr<GeomAPI_Pln>   aBasePln = aBaseFace->getPlane();
-      std::shared_ptr<GeomAPI_Dir>   aBaseDir = aBasePln->direction();
-      std::shared_ptr<GeomAPI_Pnt>   aBaseLoc = aBasePln->location();
-      std::shared_ptr<GeomAPI_Shape> aBasePlane = GeomAlgoAPI_FaceBuilder::planarFace(aBaseLoc, aBaseDir);
-
-      std::shared_ptr<GeomAPI_Shape> aBoundingFromShape = aFromShape ? aFromShape : aBasePlane;
-      std::shared_ptr<GeomAPI_Shape> aBoundingToShape   = aToShape   ? aToShape   : aBasePlane;
-
-      // Moving bounding faces according to "from" and "to" sizes.
-      std::shared_ptr<GeomAPI_Face> aFromFace(new GeomAPI_Face(aBoundingFromShape));
-      std::shared_ptr<GeomAPI_Pln>  aFromPln = aFromFace->getPlane();
-      std::shared_ptr<GeomAPI_Pnt>  aFromLoc = aFromPln->location();
-      std::shared_ptr<GeomAPI_Dir>  aFromDir = aFromPln->direction();
-
-      std::shared_ptr<GeomAPI_Face> aToFace(new GeomAPI_Face(aBoundingToShape));
-      std::shared_ptr<GeomAPI_Pln>  aToPln = aToFace->getPlane();
-      std::shared_ptr<GeomAPI_Pnt>  aToLoc = aToPln->location();
-      std::shared_ptr<GeomAPI_Dir>  aToDir = aToPln->direction();
-
-      bool aSign = aFromLoc->xyz()->dot(aBaseDir->xyz()) > aToLoc->xyz()->dot(aBaseDir->xyz());
-
-      std::shared_ptr<GeomAPI_Pnt> aFromPnt(new GeomAPI_Pnt(aFromLoc->xyz()->added(aBaseDir->xyz()->multiplied(aSign ? aFromSize : -aFromSize))));
-      aBoundingFromShape = GeomAlgoAPI_FaceBuilder::planarFace(aFromPnt, aFromDir);
-
-      std::shared_ptr<GeomAPI_Pnt> aToPnt(new GeomAPI_Pnt(aToLoc->xyz()->added(aBaseDir->xyz()->multiplied(aSign ? -aToSize : aToSize))));
-      aBoundingToShape = GeomAlgoAPI_FaceBuilder::planarFace(aToPnt, aToDir);
-
-      //GeomAlgoAPI_Extrusion aFeature(aFace, aFromSize);
-      GeomAlgoAPI_Prism aFeature(aBaseShape, aBoundingFromShape, aBoundingToShape);
+      GeomAlgoAPI_Prism aFeature(aBaseShape, aFromShape, aFromSize, aToShape, aToSize);
       if(!aFeature.isDone()) {
         static const std::string aFeatureError = "Extrusion algorithm failed";
         setError(aFeatureError);
@@ -181,12 +149,11 @@ void FeaturesPlugin_Extrusion::LoadNamingDS(GeomAlgoAPI_Prism& theFeature,
   else
     theResultBody->storeGenerated(theBasis, theFeature.shape());
 
-  GeomAPI_DataMapOfShapeShape* aSubShapes = new GeomAPI_DataMapOfShapeShape();
-  theFeature.mapOfShapes(*aSubShapes);
+  std::shared_ptr<GeomAPI_DataMapOfShapeShape> aSubShapes = theFeature.mapOfShapes();
 
   //Insert lateral face : Face from Edge
   std::string aLatName = "LateralFace";
-  theResultBody->loadAndOrientGeneratedShapes(theFeature.makeShape(), theBasis, EDGE,_LATERAL_TAG, aLatName, *aSubShapes);
+  theResultBody->loadAndOrientGeneratedShapes(theFeature.makeShape().get(), theBasis, EDGE,_LATERAL_TAG, aLatName, *aSubShapes.get());
 
   //Insert bottom face
   std::string aBotName = "BottomFace";
index 0e79a10f6c124f27db5cac305f21e49a3b8f6dbb..49db964fc715e995c1495ec72bfaf704fbaa05bd 100644 (file)
@@ -35,7 +35,7 @@ class GEOMAPI_EXPORT GeomAPI_Interface
     return static_cast<T*>(myImpl);
   }
   /// Returns the reference object of the impl
-  template<class T> inline const T& impl()
+  template<class T> inline const T& impl() const
   {
     return *(static_cast<T*>(myImpl));
   }
index 7d2cf323385f9b7a013cb337bb35815e330b874d..41bb42be31e2a4a7f2aa3fee4fbf8c1ee4751ee1 100644 (file)
@@ -6,7 +6,12 @@
 
 #include <GeomAlgoAPI_Prism.h>
 
+#include <GeomAPI_Face.h>
+#include <GeomAPI_Pln.h>
+#include <GeomAPI_Pnt.h>
+#include <GeomAPI_XYZ.h>
 #include <GeomAlgoAPI_DFLoader.h>
+#include <GeomAlgoAPI_FaceBuilder.h>
 
 #include <BRep_Tool.hxx>
 #include <BRepCheck_Analyzer.hxx>
 #include <TopoDS.hxx>
 
 //=================================================================================================
-GeomAlgoAPI_Prism::GeomAlgoAPI_Prism(std::shared_ptr<GeomAPI_Shape> theBasis,
-                                     std::shared_ptr<GeomAPI_Shape> theFromShape,
-                                     std::shared_ptr<GeomAPI_Shape> theToShape)
-: myFromShape(theFromShape),
-  myToShape(theToShape),
-  myDone(false),
-  myShape(new GeomAPI_Shape()),
-  myFirst(new GeomAPI_Shape()),myLast(new GeomAPI_Shape())
+GeomAlgoAPI_Prism::GeomAlgoAPI_Prism(const std::shared_ptr<GeomAPI_Shape>& theBasis,
+                                     const std::shared_ptr<GeomAPI_Shape>& theFromShape,
+                                     double               theFromDistance,
+                                     const std::shared_ptr<GeomAPI_Shape>& theToShape,
+                                     double               theToDistance)
+: myDone(false)
 {
-  build(theBasis);
+  build(theBasis, theFromShape, theFromDistance, theToShape, theToDistance);
 }
 
 //=================================================================================================
-void GeomAlgoAPI_Prism::build(const std::shared_ptr<GeomAPI_Shape>& theBasis)
+void GeomAlgoAPI_Prism::build(const std::shared_ptr<GeomAPI_Shape>& theBasis,
+                              const std::shared_ptr<GeomAPI_Shape>& theFromShape,
+                              double                                theFromDistance,
+                              const std::shared_ptr<GeomAPI_Shape>& theToShape,
+                              double                                theToDistance)
 {
-  if(!theBasis || !myFromShape || !myToShape ||
-    (myFromShape && myToShape && myFromShape->isEqual(myToShape))) {
+  if(!theBasis ||
+    (((!theFromShape && !theToShape) || (theFromShape && theToShape && theFromShape->isEqual(theToShape)))
+    && (theFromDistance == 0.0 && theToDistance == 0.0))) {
     return;
   }
 
+  // If bounding faces was not set creating them.
+  std::shared_ptr<GeomAPI_Face>  aBaseFace(new GeomAPI_Face(theBasis));
+  std::shared_ptr<GeomAPI_Pln>   aBasePln = aBaseFace->getPlane();
+  std::shared_ptr<GeomAPI_Dir>   aBaseDir = aBasePln->direction();
+  std::shared_ptr<GeomAPI_Pnt>   aBaseLoc = aBasePln->location();
+  std::shared_ptr<GeomAPI_Shape> aBasePlane = GeomAlgoAPI_FaceBuilder::planarFace(aBaseLoc, aBaseDir);
+
+  std::shared_ptr<GeomAPI_Shape> aBoundingFromShape = theFromShape ? theFromShape : aBasePlane;
+  std::shared_ptr<GeomAPI_Shape> aBoundingToShape   = theToShape   ? theToShape   : aBasePlane;
+
+  // Moving bounding faces according to "from" and "to" sizes.
+  std::shared_ptr<GeomAPI_Face> aFromFace(new GeomAPI_Face(aBoundingFromShape));
+  std::shared_ptr<GeomAPI_Pln>  aFromPln = aFromFace->getPlane();
+  std::shared_ptr<GeomAPI_Pnt>  aFromLoc = aFromPln->location();
+  std::shared_ptr<GeomAPI_Dir>  aFromDir = aFromPln->direction();
+
+  std::shared_ptr<GeomAPI_Face> aToFace(new GeomAPI_Face(aBoundingToShape));
+  std::shared_ptr<GeomAPI_Pln>  aToPln = aToFace->getPlane();
+  std::shared_ptr<GeomAPI_Pnt>  aToLoc = aToPln->location();
+  std::shared_ptr<GeomAPI_Dir>  aToDir = aToPln->direction();
+
+  bool aSign = aFromLoc->xyz()->dot(aBaseDir->xyz()) > aToLoc->xyz()->dot(aBaseDir->xyz());
+
+  std::shared_ptr<GeomAPI_Pnt> aFromPnt(new GeomAPI_Pnt(aFromLoc->xyz()->added(aBaseDir->xyz()->multiplied(
+                                                        aSign ? theFromDistance : -theFromDistance))));
+  aBoundingFromShape = GeomAlgoAPI_FaceBuilder::planarFace(aFromPnt, aFromDir);
+
+  std::shared_ptr<GeomAPI_Pnt> aToPnt(new GeomAPI_Pnt(aToLoc->xyz()->added(aBaseDir->xyz()->multiplied(
+                                                      aSign ? -theToDistance : theToDistance))));
+  aBoundingToShape = GeomAlgoAPI_FaceBuilder::planarFace(aToPnt, aToDir);
+
   TopoDS_Face aBasis = TopoDS::Face(theBasis->impl<TopoDS_Shape>());
   Handle(Geom_Plane) aPlane = Handle(Geom_Plane)::DownCast(BRep_Tool::Surface(aBasis));
   if(aPlane.IsNull()) { // non-planar shapes is not supported for extrusion yet
@@ -49,9 +88,8 @@ void GeomAlgoAPI_Prism::build(const std::shared_ptr<GeomAPI_Shape>& theBasis)
   BRepFeat_MakePrism* aBuilder = new BRepFeat_MakePrism(aBasis, aBasis, aBasis, aNormal, 2, Standard_True);
 
   if(aBuilder) {
-    setImpl(aBuilder);
-    TopoDS_Shape aFromShape = myFromShape->impl<TopoDS_Shape>();
-    TopoDS_Shape aToShape   = myToShape->impl<TopoDS_Shape>();
+    const TopoDS_Shape& aFromShape = aBoundingFromShape->impl<TopoDS_Shape>();
+    const TopoDS_Shape& aToShape   = aBoundingToShape->impl<TopoDS_Shape>();
     aBuilder->Perform(aFromShape, aToShape);
     myDone = aBuilder->IsDone() == Standard_True;
     if(myDone){
@@ -64,34 +102,39 @@ void GeomAlgoAPI_Prism::build(const std::shared_ptr<GeomAPI_Shape>& theBasis)
         aResult = GeomAlgoAPI_DFLoader::refineResult(aResult);
       }
       // fill data map to keep correct orientation of sub-shapes
+      myMap = std::make_shared<GeomAPI_DataMapOfShapeShape>();
       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);
+        myMap->bind(aCurrentShape, aCurrentShape);
       }
+      myShape = std::make_shared<GeomAPI_Shape>();
       myShape->setImpl(new TopoDS_Shape(aResult));
+      myFirst = std::make_shared<GeomAPI_Shape>();
       myFirst->setImpl(new TopoDS_Shape(aBuilder->Modified(aFromShape).First()));
+      myLast = std::make_shared<GeomAPI_Shape>();
       myLast->setImpl(new TopoDS_Shape(aBuilder->Modified(aToShape).First()));
-      myMkShape = new GeomAlgoAPI_MakeShape (aBuilder);
+      myMkShape = std::shared_ptr<GeomAlgoAPI_MakeShape>(new GeomAlgoAPI_MakeShape());
+      myMkShape->setImpl(aBuilder);
     }
   }
 }
 
 //=================================================================================================
-const bool GeomAlgoAPI_Prism::isDone() const
+bool GeomAlgoAPI_Prism::isDone() const
 {
   return myDone;
 }
 
 //=================================================================================================
-const bool GeomAlgoAPI_Prism::isValid() const
+bool GeomAlgoAPI_Prism::isValid() const
 {
   BRepCheck_Analyzer aChecker(myShape->impl<TopoDS_Shape>());
   return (aChecker.IsValid() == Standard_True);
 }
 
 //=================================================================================================
-const bool GeomAlgoAPI_Prism::hasVolume() const
+bool GeomAlgoAPI_Prism::hasVolume() const
 {
   bool hasVolume(false);
   if(isValid()) {
@@ -105,39 +148,31 @@ const bool GeomAlgoAPI_Prism::hasVolume() const
 }
 
 //=================================================================================================
-const std::shared_ptr<GeomAPI_Shape>& GeomAlgoAPI_Prism::shape () const
+std::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_Prism::shape() const
 {
   return myShape;
 }
 
 //=================================================================================================
-const std::shared_ptr<GeomAPI_Shape>& GeomAlgoAPI_Prism::firstShape()
+std::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_Prism::firstShape() const
 {
   return myFirst;
 }
 
 //=================================================================================================
-const std::shared_ptr<GeomAPI_Shape>& GeomAlgoAPI_Prism::lastShape()
+std::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_Prism::lastShape() const
 {
   return myLast;
 }
 
 //=================================================================================================
-void GeomAlgoAPI_Prism::mapOfShapes (GeomAPI_DataMapOfShapeShape& theMap) const
+std::shared_ptr<GeomAPI_DataMapOfShapeShape> GeomAlgoAPI_Prism::mapOfShapes() const
 {
-  theMap = myMap;
+  return myMap;
 }
 
 //=================================================================================================
-GeomAlgoAPI_MakeShape* GeomAlgoAPI_Prism::makeShape() const
+std::shared_ptr<GeomAlgoAPI_MakeShape> GeomAlgoAPI_Prism::makeShape() const
 {
   return myMkShape;
 }
-
-//=================================================================================================
-GeomAlgoAPI_Prism::~GeomAlgoAPI_Prism()
-{
-  if (myImpl) {
-    myMap.clear();
-  }
-}
\ No newline at end of file
index fde00d55d965ad3c0a5cbfacb611d7becb08cfba..2631e4bc276b385d614ac6c94fe3dce8474d4a3c 100644 (file)
@@ -23,55 +23,58 @@ class GeomAlgoAPI_Prism : public GeomAPI_Interface
 {
 public:
   /** \brief Creates extrusion for the given shape along the normal for this shape.
-   *  \param[in] theBasis face or wire to be extruded;
-   *  \param[in] theFromShape bottom bounding shape;
-   *  \param[in] theToShape top bounding shape;
+   *  \param[in] theBasis face or wire to be extruded.
+   *  \param[in] theFromShape bottom bounding shape.
+   *  \param[in] theFromDistance offset for "from" plane.
+   *  \param[in] theToShape top bounding shape.
+   *  \param[in] theToDistance offset for "to" plane.
    */
-  GEOMALGOAPI_EXPORT GeomAlgoAPI_Prism(std::shared_ptr<GeomAPI_Shape> theBasis,
-                                       std::shared_ptr<GeomAPI_Shape> theFromShape,
-                                       std::shared_ptr<GeomAPI_Shape> theToShape);
+  GEOMALGOAPI_EXPORT GeomAlgoAPI_Prism(const std::shared_ptr<GeomAPI_Shape>& theBasis,
+                                       const std::shared_ptr<GeomAPI_Shape>& theFromShape,
+                                       double               theFromDistance,
+                                       const std::shared_ptr<GeomAPI_Shape>& theToShape,
+                                       double               theToDistance);
 
   /// \return true if algorithm succeed.
-  GEOMALGOAPI_EXPORT const bool isDone() const;
+  GEOMALGOAPI_EXPORT bool isDone() const;
 
   /// \return true if resulting shape is valid.
-  GEOMALGOAPI_EXPORT const bool isValid() const;
+  GEOMALGOAPI_EXPORT bool isValid() const;
 
   /// \return true if resulting shape has volume.
-  GEOMALGOAPI_EXPORT const bool hasVolume() const;
+  GEOMALGOAPI_EXPORT bool hasVolume() const;
 
   /// \return result of the Prism algorithm.
-  GEOMALGOAPI_EXPORT const std::shared_ptr<GeomAPI_Shape>& shape() const;
+  GEOMALGOAPI_EXPORT std::shared_ptr<GeomAPI_Shape> shape() const;
 
   /// \returns the first shape.
-  GEOMALGOAPI_EXPORT const std::shared_ptr<GeomAPI_Shape>& firstShape();
+  GEOMALGOAPI_EXPORT std::shared_ptr<GeomAPI_Shape> firstShape() const;
 
   /// \return the last shape.
-  GEOMALGOAPI_EXPORT const std::shared_ptr<GeomAPI_Shape>& lastShape();
+  GEOMALGOAPI_EXPORT std::shared_ptr<GeomAPI_Shape> lastShape() const;
 
   /// \return map of sub-shapes of the result. To be used for History keeping.
-  GEOMALGOAPI_EXPORT void  mapOfShapes(GeomAPI_DataMapOfShapeShape& theMap) const;
+  GEOMALGOAPI_EXPORT std::shared_ptr<GeomAPI_DataMapOfShapeShape> mapOfShapes() const;
 
   /// \return interface for History processing.
-  GEOMALGOAPI_EXPORT GeomAlgoAPI_MakeShape* makeShape() const;
-
-  /// Destructor.
-  GEOMALGOAPI_EXPORT  ~GeomAlgoAPI_Prism();
+  GEOMALGOAPI_EXPORT std::shared_ptr<GeomAlgoAPI_MakeShape> makeShape() const;
 
 private:
   /// Builds resulting shape.
-  void build(const std::shared_ptr<GeomAPI_Shape>& theBasis);
+  void build(const std::shared_ptr<GeomAPI_Shape>& theBasis,
+             const std::shared_ptr<GeomAPI_Shape>& theFromShape,
+             double               theFromDistance,
+             const std::shared_ptr<GeomAPI_Shape>& theToShape,
+             double               theToDistance);
 
 private:
   /// Fields.
-  std::shared_ptr<GeomAPI_Shape> myFromShape;
-  std::shared_ptr<GeomAPI_Shape> myToShape;
   bool myDone;
   std::shared_ptr<GeomAPI_Shape> myShape;
   std::shared_ptr<GeomAPI_Shape> myFirst;
   std::shared_ptr<GeomAPI_Shape> myLast;
-  GeomAPI_DataMapOfShapeShape myMap;
-  GeomAlgoAPI_MakeShape* myMkShape;
+  std::shared_ptr<GeomAPI_DataMapOfShapeShape> myMap;
+  std::shared_ptr<GeomAlgoAPI_MakeShape> myMkShape;
 };
 
 #endif