IMP 0021067: Extrusion with scale factor. Fix some cases.

This commit is contained in:
jfa 2011-05-03 12:33:14 +00:00
parent b8e5dd32fc
commit f397db69cd
6 changed files with 130 additions and 45 deletions

View 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);

View File

@ -3726,14 +3726,14 @@ 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 GEOMImpl_IShapesOperations::GetTypeOfSimplePart (const TopoDS_Shape& theShape)
{
TopAbs_ShapeEnum aType = theShape.ShapeType();
if (aType == TopAbs_VERTEX) return TopAbs_VERTEX;
@ -3749,7 +3749,6 @@ namespace {
}
return TopAbs_SHAPE;
}
}
//=============================================================================
/*!

View 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,

View 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)

View File

@ -24,22 +24,32 @@
#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_Pnt aCDG = theCDG;
if (!isCDG) {
gp_Ax3 aPos = GEOMImpl_IMeasureOperations::GetPosition(theShapeBase);
gp_Pnt aCDG = aPos.Location();
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;
}

View 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