Merge remote-tracking branch 'svn/trunk'

This commit is contained in:
jriegel 2012-01-24 20:06:48 +01:00
commit cf3b67cca2
9 changed files with 163 additions and 49 deletions

View File

@ -23,7 +23,7 @@
</Methode> </Methode>
<Methode Name="discretize"> <Methode Name="discretize">
<Documentation> <Documentation>
<UserDocu>Discretizes the curve using a given deflection and returns a list of points</UserDocu> <UserDocu>Discretizes the curve using a given deflection or number of points and returns a list of points</UserDocu>
</Documentation> </Documentation>
</Methode> </Methode>
<Methode Name="value"> <Methode Name="value">

View File

@ -108,22 +108,33 @@ PyObject* GeometryCurvePy::toShape(PyObject *args)
PyObject* GeometryCurvePy::discretize(PyObject *args) PyObject* GeometryCurvePy::discretize(PyObject *args)
{ {
double d; PyObject* defl_or_num;
if (!PyArg_ParseTuple(args, "d", &d)) if (!PyArg_ParseTuple(args, "O", &defl_or_num))
return 0; return 0;
Handle_Geom_Geometry g = getGeometryPtr()->handle();
Handle_Geom_Curve c = Handle_Geom_Curve::DownCast(g);
try { try {
Handle_Geom_Geometry g = getGeometryPtr()->handle();
Handle_Geom_Curve c = Handle_Geom_Curve::DownCast(g);
if (!c.IsNull()) { if (!c.IsNull()) {
GeomAdaptor_Curve curve_adaptator(c); GeomAdaptor_Curve adapt(c);
GCPnts_UniformAbscissa discretizer; GCPnts_UniformAbscissa discretizer;
discretizer.Initialize (curve_adaptator, d); if (PyInt_Check(defl_or_num)) {
int num = PyInt_AsLong(defl_or_num);
discretizer.Initialize (adapt, num);
}
else if (PyFloat_Check(defl_or_num)) {
double defl = PyFloat_AsDouble(defl_or_num);
discretizer.Initialize (adapt, defl);
}
else {
PyErr_SetString(PyExc_TypeError, "Either int or float expected");
return 0;
}
if (discretizer.IsDone () && discretizer.NbPoints () > 0) { if (discretizer.IsDone () && discretizer.NbPoints () > 0) {
Py::List points; Py::List points;
int nbPoints = discretizer.NbPoints (); int nbPoints = discretizer.NbPoints ();
for (int i=1; i<=nbPoints; i++) { for (int i=1; i<=nbPoints; i++) {
gp_Pnt p = curve_adaptator.Value (discretizer.Parameter (i)); gp_Pnt p = adapt.Value (discretizer.Parameter (i));
points.append(Py::Vector(Base::Vector3d(p.X(),p.Y(),p.Z()))); points.append(Py::Vector(Base::Vector3d(p.X(),p.Y(),p.Z())));
} }

View File

@ -1771,17 +1771,24 @@ TopoDS_Shape TopoShape::removeSplitter() const
Standard_Failure::Raise("Cannot remove splitter from empty shape"); Standard_Failure::Raise("Cannot remove splitter from empty shape");
if (_Shape.ShapeType() == TopAbs_SOLID) { if (_Shape.ShapeType() == TopAbs_SOLID) {
const TopoDS_Solid& solid = TopoDS::Solid(_Shape); const TopoDS_Solid &solid = TopoDS::Solid(_Shape);
ModelRefine::FaceUniter uniter(solid); BRepTools_ReShape reshape;
if (uniter.process()) { TopExp_Explorer it;
TopoDS_Solid solidMod; for (it.Init(solid, TopAbs_SHELL); it.More(); it.Next()) {
if (!uniter.getSolid(solidMod)) const TopoDS_Shell &currentShell = TopoDS::Shell(it.Current());
Standard_Failure::Raise("Getting solid failed"); ModelRefine::FaceUniter uniter(currentShell);
return solidMod; if (uniter.process()) {
} if (uniter.isModified()) {
else { const TopoDS_Shell &newShell = uniter.getShell();
Standard_Failure::Raise("Removing splitter failed"); reshape.Replace(currentShell, newShell);
}
}
else {
Standard_Failure::Raise("Removing splitter failed");
return _Shape;
}
} }
return reshape.Apply(solid);
} }
else if (_Shape.ShapeType() == TopAbs_SHELL) { else if (_Shape.ShapeType() == TopAbs_SHELL) {
const TopoDS_Shell& shell = TopoDS::Shell(_Shape); const TopoDS_Shell& shell = TopoDS::Shell(_Shape);
@ -1801,13 +1808,20 @@ TopoDS_Shape TopoShape::removeSplitter() const
TopExp_Explorer xp; TopExp_Explorer xp;
// solids // solids
for (xp.Init(_Shape, TopAbs_SOLID); xp.More(); xp.Next()) { for (xp.Init(_Shape, TopAbs_SOLID); xp.More(); xp.Next()) {
const TopoDS_Solid& solid = TopoDS::Solid(xp.Current()); const TopoDS_Solid &solid = TopoDS::Solid(xp.Current());
ModelRefine::FaceUniter uniter(solid); BRepTools_ReShape reshape;
if (uniter.process()) { TopExp_Explorer it;
TopoDS_Solid solidMod; for (it.Init(solid, TopAbs_SHELL); it.More(); it.Next()) {
if (uniter.getSolid(solidMod)) const TopoDS_Shell &currentShell = TopoDS::Shell(it.Current());
builder.Add(comp, solidMod); ModelRefine::FaceUniter uniter(currentShell);
if (uniter.process()) {
if (uniter.isModified()) {
const TopoDS_Shell &newShell = uniter.getShell();
reshape.Replace(currentShell, newShell);
}
}
} }
builder.Add(comp, reshape.Apply(solid));
} }
// free shells // free shells
for (xp.Init(_Shape, TopAbs_SHELL, TopAbs_SOLID); xp.More(); xp.Next()) { for (xp.Init(_Shape, TopAbs_SHELL, TopAbs_SOLID); xp.More(); xp.Next()) {

View File

@ -59,6 +59,11 @@
<UserDocu>Set the tolerance for the edge.</UserDocu> <UserDocu>Set the tolerance for the edge.</UserDocu>
</Documentation> </Documentation>
</Methode> </Methode>
<Methode Name="discretize">
<Documentation>
<UserDocu>Discretizes the edge using a given deflection or number of points and returns a list of points</UserDocu>
</Documentation>
</Methode>
<Attribute Name="Tolerance"> <Attribute Name="Tolerance">
<Documentation> <Documentation>
<UserDocu>Set or get the tolerance of the vertex</UserDocu> <UserDocu>Set or get the tolerance of the vertex</UserDocu>

View File

@ -53,6 +53,7 @@
#include <BRepGProp.hxx> #include <BRepGProp.hxx>
#include <GProp_GProps.hxx> #include <GProp_GProps.hxx>
#include <GCPnts_AbscissaPoint.hxx> #include <GCPnts_AbscissaPoint.hxx>
#include <GCPnts_UniformAbscissa.hxx>
#include <Base/VectorPy.h> #include <Base/VectorPy.h>
#include <Base/GeometryPyCXX.h> #include <Base/GeometryPyCXX.h>
@ -396,6 +397,52 @@ PyObject* TopoShapeEdgePy::derivative3At(PyObject *args)
} }
} }
PyObject* TopoShapeEdgePy::discretize(PyObject *args)
{
PyObject* defl_or_num;
if (!PyArg_ParseTuple(args, "O", &defl_or_num))
return 0;
try {
BRepAdaptor_Curve adapt(TopoDS::Edge(getTopoShapePtr()->_Shape));
GCPnts_UniformAbscissa discretizer;
if (PyInt_Check(defl_or_num)) {
int num = PyInt_AsLong(defl_or_num);
discretizer.Initialize (adapt, num);
}
else if (PyFloat_Check(defl_or_num)) {
double defl = PyFloat_AsDouble(defl_or_num);
discretizer.Initialize (adapt, defl);
}
else {
PyErr_SetString(PyExc_TypeError, "Either int or float expected");
return 0;
}
if (discretizer.IsDone () && discretizer.NbPoints () > 0) {
Py::List points;
int nbPoints = discretizer.NbPoints ();
for (int i=1; i<=nbPoints; i++) {
gp_Pnt p = adapt.Value (discretizer.Parameter (i));
points.append(Py::Vector(Base::Vector3d(p.X(),p.Y(),p.Z())));
}
return Py::new_reference_to(points);
}
else {
PyErr_SetString(PyExc_Exception, "Descretization of curve failed");
return 0;
}
}
catch (Standard_Failure) {
Handle_Standard_Failure e = Standard_Failure::Caught();
PyErr_SetString(PyExc_Exception, e->GetMessageString());
return 0;
}
PyErr_SetString(PyExc_Exception, "Geometry is not a curve");
return 0;
}
PyObject* TopoShapeEdgePy::setTolerance(PyObject *args) PyObject* TopoShapeEdgePy::setTolerance(PyObject *args)
{ {
double tol; double tol;

View File

@ -45,13 +45,18 @@
</Documentation> </Documentation>
</Methode> </Methode>
<Methode Name="approximate"> <Methode Name="approximate">
<Documentation>
<UserDocu>Approximate B-Spline-curve from this wire</UserDocu>
</Documentation>
</Methode>
<Attribute Name="CenterOfMass" ReadOnly="true">
<Documentation> <Documentation>
<UserDocu>Returns the center of mass of the current system. <UserDocu>Approximate B-Spline-curve from this wire</UserDocu>
</Documentation>
</Methode>
<Methode Name="discretize">
<Documentation>
<UserDocu>Discretizes the wire using a given deflection or number of points and returns a list of points</UserDocu>
</Documentation>
</Methode>
<Attribute Name="CenterOfMass" ReadOnly="true">
<Documentation>
<UserDocu>Returns the center of mass of the current system.
If the gravitational field is uniform, it is the center of gravity. If the gravitational field is uniform, it is the center of gravity.
The coordinates returned for the center of mass are expressed in the The coordinates returned for the center of mass are expressed in the
absolute Cartesian coordinate system.</UserDocu> absolute Cartesian coordinate system.</UserDocu>

View File

@ -37,6 +37,7 @@
#include <BRepGProp.hxx> #include <BRepGProp.hxx>
#include <GProp_GProps.hxx> #include <GProp_GProps.hxx>
#include <GCPnts_UniformAbscissa.hxx>
#include <Base/VectorPy.h> #include <Base/VectorPy.h>
#include <Base/GeometryPyCXX.h> #include <Base/GeometryPyCXX.h>
@ -320,6 +321,52 @@ PyObject* TopoShapeWirePy::approximate(PyObject *args)
} }
} }
PyObject* TopoShapeWirePy::discretize(PyObject *args)
{
PyObject* defl_or_num;
if (!PyArg_ParseTuple(args, "O", &defl_or_num))
return 0;
try {
BRepAdaptor_CompCurve adapt(TopoDS::Wire(getTopoShapePtr()->_Shape));
GCPnts_UniformAbscissa discretizer;
if (PyInt_Check(defl_or_num)) {
int num = PyInt_AsLong(defl_or_num);
discretizer.Initialize (adapt, num);
}
else if (PyFloat_Check(defl_or_num)) {
double defl = PyFloat_AsDouble(defl_or_num);
discretizer.Initialize (adapt, defl);
}
else {
PyErr_SetString(PyExc_TypeError, "Either int or float expected");
return 0;
}
if (discretizer.IsDone () && discretizer.NbPoints () > 0) {
Py::List points;
int nbPoints = discretizer.NbPoints ();
for (int i=1; i<=nbPoints; i++) {
gp_Pnt p = adapt.Value (discretizer.Parameter (i));
points.append(Py::Vector(Base::Vector3d(p.X(),p.Y(),p.Z())));
}
return Py::new_reference_to(points);
}
else {
PyErr_SetString(PyExc_Exception, "Descretization of wire failed");
return 0;
}
}
catch (Standard_Failure) {
Handle_Standard_Failure e = Standard_Failure::Caught();
PyErr_SetString(PyExc_Exception, e->GetMessageString());
return 0;
}
PyErr_SetString(PyExc_Exception, "Geometry is not a curve");
return 0;
}
Py::Object TopoShapeWirePy::getCenterOfMass(void) const Py::Object TopoShapeWirePy::getCenterOfMass(void) const
{ {
GProp_GProps props; GProp_GProps props;

View File

@ -436,19 +436,11 @@ FaceTypedCylinder& ModelRefine::getCylinderObject()
///////////////////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////////////////
FaceUniter::FaceUniter(const TopoDS_Shell &shellIn) FaceUniter::FaceUniter(const TopoDS_Shell &shellIn) : modifiedSignal(false)
{ {
workShell = shellIn; workShell = shellIn;
} }
FaceUniter::FaceUniter(const TopoDS_Solid &solidIn)
{
//get first shell
TopExp_Explorer it;
it.Init(solidIn, TopAbs_SHELL);
workShell = TopoDS::Shell(it.Current());
}
bool FaceUniter::process() bool FaceUniter::process()
{ {
if (workShell.IsNull()) if (workShell.IsNull())
@ -495,6 +487,7 @@ bool FaceUniter::process()
} }
if (facesToSew.size() > 0) if (facesToSew.size() > 0)
{ {
modifiedSignal = true;
workShell = ModelRefine::removeFaces(workShell, facesToRemove); workShell = ModelRefine::removeFaces(workShell, facesToRemove);
TopExp_Explorer xp; TopExp_Explorer xp;
bool emptyShell = true; bool emptyShell = true;
@ -537,11 +530,3 @@ bool FaceUniter::process()
} }
return true; return true;
} }
bool FaceUniter::getSolid(TopoDS_Solid &outSolid) const
{
BRepBuilderAPI_MakeSolid solidMaker;
solidMaker.Add(workShell);
outSolid = solidMaker.Solid();
return solidMaker.IsDone() ? true : false;
}

View File

@ -151,14 +151,14 @@ namespace ModelRefine
FaceUniter(){} FaceUniter(){}
public: public:
FaceUniter(const TopoDS_Shell &shellIn); FaceUniter(const TopoDS_Shell &shellIn);
FaceUniter(const TopoDS_Solid &solidIn);//get first shell
bool process(); bool process();
const TopoDS_Shell& getShell() const {return workShell;} const TopoDS_Shell& getShell() const {return workShell;}
bool getSolid(TopoDS_Solid &outSolid) const;//tries to make solid from shell. bool isModified(){return modifiedSignal;}
private: private:
TopoDS_Shell workShell; TopoDS_Shell workShell;
std::vector<FaceTypedBase *> typeObjects; std::vector<FaceTypedBase *> typeObjects;
bool modifiedSignal;
}; };
} }