]> SALOME platform Git repositories - modules/geom.git/commitdiff
Salome HOME
IMP 0021067: Extrusion with scale factor. Fix some cases.
authorjfa <jfa@opencascade.com>
Tue, 3 May 2011 12:33:14 +0000 (12:33 +0000)
committerjfa <jfa@opencascade.com>
Tue, 3 May 2011 12:33:14 +0000 (12:33 +0000)
src/GEOMImpl/GEOMImpl_IMeasureOperations.cxx
src/GEOMImpl/GEOMImpl_IShapesOperations.cxx
src/GEOMImpl/GEOMImpl_IShapesOperations.hxx
src/GEOMImpl/GEOMImpl_MeasureDriver.cxx
src/GEOMImpl/GEOMImpl_PrismDriver.cxx
src/GEOMImpl/GEOMImpl_PrismDriver.hxx

index 46ce5f9c564d61dfbbf51c50ff108ee0ecc81420..16d58527ec6bc87a7daef92eb6c69aa6c256eb62 100644 (file)
@@ -26,6 +26,7 @@
 #include <GEOMImpl_Types.hxx>
 #include <GEOMImpl_MeasureDriver.hxx>
 #include <GEOMImpl_IMeasure.hxx>
+#include <GEOMImpl_IShapesOperations.hxx>
 
 #include <GEOMAlgo_ShapeInfo.hxx>
 #include <GEOMAlgo_ShapeInfoFiller.hxx>
@@ -778,14 +779,21 @@ gp_Ax3 GEOMImpl_IMeasureOperations::GetPosition (const TopoDS_Shape& theShape)
 
   // Origin
   gp_Pnt aPnt;
-  if (theShape.ShapeType() == TopAbs_VERTEX) {
+
+  TopAbs_ShapeEnum aShType = theShape.ShapeType();
+
+  if (aShType == TopAbs_VERTEX) {
     aPnt = BRep_Tool::Pnt(TopoDS::Vertex(theShape));
   }
   else {
+    if (aShType == TopAbs_COMPOUND) {
+      aShType = GEOMImpl_IShapesOperations::GetTypeOfSimplePart(theShape);
+    }
+
     GProp_GProps aSystem;
-    if (theShape.ShapeType() == TopAbs_EDGE || theShape.ShapeType() == TopAbs_WIRE)
+    if (aShType == TopAbs_EDGE || aShType == TopAbs_WIRE)
       BRepGProp::LinearProperties(theShape, aSystem);
-    else if (theShape.ShapeType() == TopAbs_FACE || theShape.ShapeType() == TopAbs_SHELL)
+    else if (aShType == TopAbs_FACE || aShType == TopAbs_SHELL)
       BRepGProp::SurfaceProperties(theShape, aSystem);
     else
       BRepGProp::VolumeProperties(theShape, aSystem);
index 11e0ee2fd86adea766c2e72ea3946e9787593e19..31f7006fb47b2b5f1a843925dea494565c0f8c59 100644 (file)
@@ -3726,29 +3726,28 @@ namespace {
     }
     return defaultNorm;
   }
+}
 
-  //================================================================================
-  /*!
-   * \brief Return type of shape for explode. In case of compound it will be a type of sub shape.
-   */
-  //================================================================================
-
-  TopAbs_ShapeEnum GetTypeOfSimplePart (const TopoDS_Shape& theShape)
-  {
-    TopAbs_ShapeEnum aType = theShape.ShapeType();
-    if      (aType == TopAbs_VERTEX)                             return TopAbs_VERTEX;
-    else if (aType == TopAbs_EDGE  || aType == TopAbs_WIRE)      return TopAbs_EDGE;
-    else if (aType == TopAbs_FACE  || aType == TopAbs_SHELL)     return TopAbs_FACE;
-    else if (aType == TopAbs_SOLID || aType == TopAbs_COMPSOLID) return TopAbs_SOLID;
-    else if (aType == TopAbs_COMPOUND) {
-      // Only the iType of the first shape in the compound is taken into account
-      TopoDS_Iterator It (theShape, Standard_False, Standard_False);
-      if (It.More()) {
-        return GetTypeOfSimplePart(It.Value());
-      }
+//================================================================================
+/*!
+ * \brief Return type of shape for explode. In case of compound it will be a type of sub shape.
+ */
+//================================================================================
+TopAbs_ShapeEnum GEOMImpl_IShapesOperations::GetTypeOfSimplePart (const TopoDS_Shape& theShape)
+{
+  TopAbs_ShapeEnum aType = theShape.ShapeType();
+  if      (aType == TopAbs_VERTEX)                             return TopAbs_VERTEX;
+  else if (aType == TopAbs_EDGE  || aType == TopAbs_WIRE)      return TopAbs_EDGE;
+  else if (aType == TopAbs_FACE  || aType == TopAbs_SHELL)     return TopAbs_FACE;
+  else if (aType == TopAbs_SOLID || aType == TopAbs_COMPSOLID) return TopAbs_SOLID;
+  else if (aType == TopAbs_COMPOUND) {
+    // Only the iType of the first shape in the compound is taken into account
+    TopoDS_Iterator It (theShape, Standard_False, Standard_False);
+    if (It.More()) {
+      return GetTypeOfSimplePart(It.Value());
     }
-    return TopAbs_SHAPE;
   }
+  return TopAbs_SHAPE;
 }
 
 //=============================================================================
index 25666f82a1973b1caa71d06bead449ce3e24ed17..2076bdbce6a120c7251b615c34ebbec1b2a5f8eb 100644 (file)
@@ -399,6 +399,13 @@ class GEOMImpl_IShapesOperations : public GEOM_IOperations
    */
   Standard_EXPORT static bool CheckTriangulation (const TopoDS_Shape& theShape);
 
+  /*!
+   * \brief Return type of shape for explode. In case of compound it will be a type of its first sub shape.
+   * \param theShape The shape to get type of.
+   * \retval TopAbs_ShapeEnum Return type of shape for explode.
+   */
+  Standard_EXPORT static TopAbs_ShapeEnum GetTypeOfSimplePart (const TopoDS_Shape& theShape);
+
  private:
   Handle(GEOM_Object) MakeShape (std::list<Handle(GEOM_Object)>      theShapes,
                                  const Standard_Integer         theObjectType,
index 6d8698259ab39d1f5ceba9867268e84ed529e599..f454de9264fe83558bbf86a09c5d4f8c5ce4ee10 100644 (file)
@@ -18,7 +18,6 @@
 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
 //
 //  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
-//
 
 #include <Standard_Stream.hxx>
 
@@ -96,22 +95,8 @@ Standard_Integer GEOMImpl_MeasureDriver::Execute(TFunction_Logbook& log) const
       Standard_NullObject::Raise("Shape for centre of mass calculation is null");
     }
 
-    GProp_GProps aSystem;
-    gp_Pnt aCenterMass;
-
-    if (aShapeBase.ShapeType() == TopAbs_VERTEX) {
-      aCenterMass = BRep_Tool::Pnt(TopoDS::Vertex(aShapeBase));
-    } else if (aShapeBase.ShapeType() == TopAbs_EDGE || aShapeBase.ShapeType() == TopAbs_WIRE) {
-      BRepGProp::LinearProperties(aShapeBase, aSystem);
-      aCenterMass = aSystem.CentreOfMass();
-    } else if (aShapeBase.ShapeType() == TopAbs_FACE || aShapeBase.ShapeType() == TopAbs_SHELL) {
-      BRepGProp::SurfaceProperties(aShapeBase, aSystem);
-      aCenterMass = aSystem.CentreOfMass();
-    } else {
-      BRepGProp::VolumeProperties(aShapeBase, aSystem);
-      aCenterMass = aSystem.CentreOfMass();
-    }
-
+    gp_Ax3 aPos = GEOMImpl_IMeasureOperations::GetPosition(aShapeBase);
+    gp_Pnt aCenterMass = aPos.Location();
     aShape = BRepBuilderAPI_MakeVertex(aCenterMass).Shape();
   }
   else if (aType == VERTEX_BY_INDEX)
index ad87f7ad749022643c66de02cf3f1799cc81a1ed..e5e82de53e5d2b9a71e676362d9d8f39bb9b4d85 100644 (file)
 #include <GEOMImpl_IPrism.hxx>
 #include <GEOMImpl_IShapesOperations.hxx>
 #include <GEOMImpl_IMeasureOperations.hxx>
+#include <GEOMImpl_GlueDriver.hxx>
 #include <GEOMImpl_PipeDriver.hxx>
 #include <GEOMImpl_Types.hxx>
 #include <GEOM_Function.hxx>
 
 #include <BRepPrimAPI_MakePrism.hxx>
+
+#include <BRep_Builder.hxx>
 #include <BRepBuilderAPI_MakeEdge.hxx>
 #include <BRepBuilderAPI_MakeWire.hxx>
 #include <BRepBuilderAPI_MakeVertex.hxx>
+#include <BRepBuilderAPI_Sewing.hxx>
 #include <BRepBuilderAPI_Transform.hxx>
+#include <BRepCheck_Shell.hxx>
+#include <BRepClass3d_SolidClassifier.hxx>
 #include <BRep_Tool.hxx>
 
 #include <TopAbs.hxx>
 #include <TopExp.hxx>
+#include <TopExp_Explorer.hxx>
 #include <TopoDS.hxx>
-#include <TopoDS_Shape.hxx>
+#include <TopoDS_Compound.hxx>
 #include <TopoDS_Edge.hxx>
+#include <TopoDS_Shape.hxx>
+#include <TopoDS_Shell.hxx>
+#include <TopoDS_Solid.hxx>
 #include <TopoDS_Vertex.hxx>
 #include <TopTools_HSequenceOfShape.hxx>
 #include <TopTools_IndexedDataMapOfShapeListOfShape.hxx>
@@ -186,15 +196,41 @@ Standard_Integer GEOMImpl_PrismDriver::Execute(TFunction_Logbook& log) const
 //=======================================================================
 TopoDS_Shape GEOMImpl_PrismDriver::MakeScaledPrism (const TopoDS_Shape& theShapeBase,
                                                     const gp_Vec&       theVector,
-                                                    const Standard_Real theScaleFactor)
+                                                    const Standard_Real theScaleFactor,
+                                                    const gp_Pnt&       theCDG,
+                                                    bool                isCDG)
 {
   TopoDS_Shape aShape;
+  BRep_Builder B;
 
   // 1. aCDG = geompy.MakeCDG(theBase)
-  gp_Ax3 aPos = GEOMImpl_IMeasureOperations::GetPosition(theShapeBase);
-  gp_Pnt aCDG = aPos.Location();
+  gp_Pnt aCDG = theCDG;
+  if (!isCDG) {
+    gp_Ax3 aPos = GEOMImpl_IMeasureOperations::GetPosition(theShapeBase);
+    aCDG = aPos.Location();
+  }
   TopoDS_Shape aShapeCDG_1 = BRepBuilderAPI_MakeVertex(aCDG).Shape();
 
+  // Process case of several given shapes
+  if (theShapeBase.ShapeType() == TopAbs_COMPOUND ||
+      theShapeBase.ShapeType() == TopAbs_SHELL) {
+    int nbSub = 0;
+    TopoDS_Shape aShapeI;
+    TopoDS_Compound aCompound;
+    B.MakeCompound(aCompound);
+    TopoDS_Iterator It (theShapeBase, Standard_True, Standard_True);
+    for (; It.More(); It.Next()) {
+      nbSub++;
+      aShapeI = MakeScaledPrism(It.Value(), theVector, theScaleFactor, aCDG, true);
+      B.Add(aCompound, aShapeI);
+    }
+    if (nbSub == 1)
+      aShape = aShapeI;
+    else if (nbSub > 1)
+      aShape = GEOMImpl_GlueDriver::GlueFaces(aCompound, Precision::Confusion(), Standard_True);
+    return aShape;
+  }
+
   // 2. Scale = geompy.MakeScaleTransform(theBase, aCDG, theScaleFactor)
 
   // Bug 6839: Check for standalone (not included in faces) degenerated edges
@@ -244,6 +280,54 @@ TopoDS_Shape GEOMImpl_PrismDriver::MakeScaledPrism (const TopoDS_Shape& theShape
   aLocs->Append(aShapeCDG_2);
 
   aShape = GEOMImpl_PipeDriver::CreatePipeWithDifferentSections(aWirePath, aBases, aLocs, false, false);
+
+  // 7. Make a solid, if possible
+  if (theShapeBase.ShapeType() == TopAbs_FACE) {
+    BRepBuilderAPI_Sewing aSewing (Precision::Confusion()*10.0);
+    TopExp_Explorer expF (aShape, TopAbs_FACE);
+    Standard_Integer ifa = 0;
+    for (; expF.More(); expF.Next()) {
+      aSewing.Add(expF.Current());
+      ifa++;
+    }
+    if (ifa > 0) {
+      aSewing.Perform();
+      TopoDS_Shape aShell;
+
+      TopoDS_Shape sh = aSewing.SewedShape();
+      if (sh.ShapeType() == TopAbs_FACE && ifa == 1) {
+        // case for creation of shell from one face
+        TopoDS_Shell ss;
+        B.MakeShell(ss);
+        B.Add(ss,sh);
+        aShell = ss;
+      }
+      else {
+        TopExp_Explorer exp (sh, TopAbs_SHELL);
+        Standard_Integer ish = 0;
+        for (; exp.More(); exp.Next()) {
+          aShell = exp.Current();
+          ish++;
+        }
+        if (ish != 1)
+          aShell = sh;
+      }
+      BRepCheck_Shell chkShell (TopoDS::Shell(aShell));
+      if (chkShell.Closed() == BRepCheck_NoError) {
+        TopoDS_Solid Sol;
+        B.MakeSolid(Sol);
+        B.Add(Sol, aShell);
+        BRepClass3d_SolidClassifier SC (Sol);
+        SC.PerformInfinitePoint(Precision::Confusion());
+        if (SC.State() == TopAbs_IN) {
+          B.MakeSolid(Sol);
+          B.Add(Sol, aShell.Reversed());
+        }
+        aShape = Sol;
+      }
+    }
+  }
+
   return aShape;
 }
 
index 80028095cdc44c980d19645e24136299d23f5a54..566ea94effc335332e9dee644a3b2ade01053a8c 100644 (file)
@@ -154,7 +154,9 @@ public:
 
   Standard_EXPORT static TopoDS_Shape MakeScaledPrism (const TopoDS_Shape& theShapeBase,
                                                        const gp_Vec&       theVector,
-                                                       const Standard_Real theScaleFactor); 
+                                                       const Standard_Real theScaleFactor,
+                                                       const gp_Pnt&       theCDG = gp::Origin(),
+                                                       bool                isCDG = false); 
 
 
   // Type management