Surface: apply clang format

This commit is contained in:
wmayer
2023-09-04 01:11:59 +02:00
committed by Chris Hennes
parent ecc21af1f1
commit 4919fa18ff
45 changed files with 1398 additions and 1088 deletions

View File

@@ -43,7 +43,8 @@ namespace Surface
class Module: public Py::ExtensionModule<Module>
{
public:
Module() : Py::ExtensionModule<Module>("Surface")
Module()
: Py::ExtensionModule<Module>("Surface")
{
initialize("This module is the Surface module.");// register with Python
}
@@ -51,7 +52,7 @@ public:
private:
};
PyObject *initModule()
PyObject* initModule()
{
return Base::Interpreter().addModule(new Module);
}
@@ -64,16 +65,17 @@ PyMOD_INIT_FUNC(Surface)
try {
Base::Interpreter().runString("import Part");
}
catch (const Base::Exception &e) {
catch (const Base::Exception& e) {
PyErr_SetString(PyExc_ImportError, e.what());
PyMOD_Return(nullptr);
}
PyObject *mod = Surface::initModule();
PyObject* mod = Surface::initModule();
Base::Console().Log("Loading Surface module... done\n");
Base::Interpreter().addType(&Surface::BlendPointPy::Type, mod, "BlendPoint");
Base::Interpreter().addType(&Surface::BlendCurvePy::Type, mod, "BlendCurve");
// clang-format off
// Add types to module
Surface::Filling ::init();
Surface::Sewing ::init();
@@ -82,6 +84,7 @@ PyMOD_INIT_FUNC(Surface)
Surface::Extend ::init();
Surface::FeatureBlendCurve ::init();
Surface::Sections ::init();
// clang-format on
PyMOD_Return(mod);
}

View File

@@ -71,8 +71,9 @@ Handle(Geom_BezierCurve) BlendCurve::compute()
}
Handle(Geom_BezierCurve) curve;
if (num_poles > (curve->MaxDegree() + 1))// use Geom_BezierCurve max degree
if (num_poles > (curve->MaxDegree() + 1)) {// use Geom_BezierCurve max degree
Standard_Failure::Raise("number of constraints exceeds bezier curve capacity");
}
TColStd_Array1OfReal knots(1, 2 * num_poles);
for (int i = 1; i <= num_poles; ++i) {
@@ -89,7 +90,13 @@ Handle(Geom_BezierCurve) BlendCurve::compute()
for (size_t i = 0; i < nb_pts; ++i) {
math_Matrix bezier_eval(1, blendPoints[i].nbVectors(), 1, num_poles, 0.0);
Standard_Integer first_non_zero;
BSplCLib::EvalBsplineBasis(blendPoints[i].nbVectors() - 1, num_poles, knots, params(cons_idx), first_non_zero, bezier_eval, Standard_False);
BSplCLib::EvalBsplineBasis(blendPoints[i].nbVectors() - 1,
num_poles,
knots,
params(cons_idx),
first_non_zero,
bezier_eval,
Standard_False);
int idx2 = 1;
for (int it2 = 0; it2 < blendPoints[i].nbVectors(); ++it2) {
OCCmatrix.SetRow(row_idx, bezier_eval.Row(idx2));
@@ -104,14 +111,17 @@ Handle(Geom_BezierCurve) BlendCurve::compute()
}
math_Gauss gauss(OCCmatrix);
gauss.Solve(res_x);
if (!gauss.IsDone())
if (!gauss.IsDone()) {
Standard_Failure::Raise("Failed to solve equations");
}
gauss.Solve(res_y);
if (!gauss.IsDone())
if (!gauss.IsDone()) {
Standard_Failure::Raise("Failed to solve equations");
}
gauss.Solve(res_z);
if (!gauss.IsDone())
if (!gauss.IsDone()) {
Standard_Failure::Raise("Failed to solve equations");
}
TColgp_Array1OfPnt poles(1, num_poles);
for (int idx = 1; idx <= num_poles; ++idx) {
@@ -120,7 +130,7 @@ Handle(Geom_BezierCurve) BlendCurve::compute()
Handle(Geom_BezierCurve) bezier = new Geom_BezierCurve(poles);
return bezier;
}
catch (Standard_Failure &) {
catch (Standard_Failure&) {
PyErr_SetString(Base::PyExc_FC_CADKernelError, "Failed to compute bezier curve");
}
return nullptr;
@@ -136,7 +146,7 @@ void BlendCurve::setSize(int i, double f, bool relative)
}
blendPoints[i].setSize(size);
}
catch (Standard_Failure &e) {
catch (Standard_Failure& e) {
PyErr_SetString(Base::PyExc_FC_CADKernelError, e.GetMessageString());
}
}

View File

@@ -24,14 +24,14 @@
#define SURFACE_BLEND_CURVE_H
#include <Geom_BezierCurve.hxx>
#include <Mod/Surface/SurfaceGlobal.h>
#include <Mod/Surface/App/Blending/BlendPoint.h>
#include <Mod/Surface/SurfaceGlobal.h>
namespace Surface
{
/*!
* Create a BezierCurve interpolating a list of BlendPoints
*/
* Create a BezierCurve interpolating a list of BlendPoints
*/
class SurfaceExport BlendCurve
{
public:
@@ -39,25 +39,24 @@ public:
BlendCurve() = default;
/*!
* Constructor
*\param std::vector<BlendPoint>
*/
* Constructor
*\param std::vector<BlendPoint>
*/
explicit BlendCurve(const std::vector<BlendPoint>& blendPointsList);
~BlendCurve() = default;
/*!
* Perform the interpolate algorithm
*\return the BezierCurve
*/
* Perform the interpolate algorithm
*\return the BezierCurve
*/
Handle(Geom_BezierCurve) compute();
/*!
* Set the size of the first derivative of a BlendPoint
*\param int index of the BlendPoint to modify
*\param double new size
*\param bool interpret new size relative to chordlength
*/
* Set the size of the first derivative of a BlendPoint
*\param int index of the BlendPoint to modify
*\param double new size
*\param bool interpret new size relative to chordlength
*/
void setSize(int, double, bool);
};
}// namespace Surface
#endif

View File

@@ -22,9 +22,11 @@
#include "PreCompiled.h"
// clang-format off
#include "Blending/BlendCurvePy.h"
#include "Blending/BlendCurvePy.cpp"
#include "Blending/BlendPointPy.h"
// clang-format on
#include <Base/VectorPy.h>
#include <Mod/Part/App/BezierCurvePy.h>
@@ -35,44 +37,51 @@ std::string BlendCurvePy::representation() const
return "BlendCurve";
}
PyObject *BlendCurvePy::PyMake(struct _typeobject *, PyObject *, PyObject *)// Python wrapper
PyObject* BlendCurvePy::PyMake(struct _typeobject*, PyObject*, PyObject*)// Python wrapper
{
// create a new instance of BlendCurvePy
return new BlendCurvePy(new BlendCurve);
}
int BlendCurvePy::PyInit(PyObject *args, PyObject * /*kwds*/)
int BlendCurvePy::PyInit(PyObject* args, PyObject* /*kwds*/)
{
PyObject *b1;
PyObject *b2;
PyObject* b1;
PyObject* b2;
if (!PyArg_ParseTuple(args, "O!O!", &(Surface::BlendPointPy::Type), &b1, &(Surface::BlendPointPy::Type), &b2))
if (!PyArg_ParseTuple(args,
"O!O!",
&(Surface::BlendPointPy::Type),
&b1,
&(Surface::BlendPointPy::Type),
&b2)) {
return -1;
}
std::vector<BlendPoint> bpList;
BlendPoint *geom1 = static_cast<BlendPointPy *>(b1)->getBlendPointPtr();
BlendPoint *geom2 = static_cast<BlendPointPy *>(b2)->getBlendPointPtr();
BlendPoint* geom1 = static_cast<BlendPointPy*>(b1)->getBlendPointPtr();
BlendPoint* geom2 = static_cast<BlendPointPy*>(b2)->getBlendPointPtr();
bpList.emplace_back(*geom1);
bpList.emplace_back(*geom2);
this->getBlendCurvePtr()->blendPoints = bpList;
return 0;
}
PyObject *BlendCurvePy::compute(PyObject * args)
PyObject* BlendCurvePy::compute(PyObject* args)
{
if (!PyArg_ParseTuple(args, ""))
if (!PyArg_ParseTuple(args, "")) {
return nullptr;
}
BlendCurve *bc = getBlendCurvePtr();
BlendCurve* bc = getBlendCurvePtr();
Handle(Geom_BezierCurve) gc = bc->compute();
return new Part::BezierCurvePy(new Part::GeomBezierCurve(gc));
}
PyObject *BlendCurvePy::setSize(PyObject *args)
PyObject* BlendCurvePy::setSize(PyObject* args)
{
int i;
double size;
PyObject *relative = Py_True;
PyObject* relative = Py_True;
if (!PyArg_ParseTuple(args, "idO!", &i, &size, &PyBool_Type, &relative)) {
return nullptr;
}
@@ -80,18 +89,18 @@ PyObject *BlendCurvePy::setSize(PyObject *args)
getBlendCurvePtr()->setSize(i, size, Base::asBoolean(relative));
Py_Return;
}
catch (Standard_Failure &e) {
catch (Standard_Failure& e) {
PyErr_SetString(Base::PyExc_FC_CADKernelError, e.GetMessageString());
return nullptr;
}
}
PyObject *BlendCurvePy::getCustomAttributes(const char * /*attr*/) const
PyObject* BlendCurvePy::getCustomAttributes(const char* /*attr*/) const
{
return nullptr;
}
int BlendCurvePy::setCustomAttributes(const char * /*attr*/, PyObject * /*obj*/)
int BlendCurvePy::setCustomAttributes(const char* /*attr*/, PyObject* /*obj*/)
{
return 0;
}

View File

@@ -33,9 +33,8 @@
using namespace Surface;
BlendPoint::BlendPoint(const std::vector<Base::Vector3d>& vectorList)
: vectors{vectorList}
{
}
: vectors {vectorList}
{}
BlendPoint::BlendPoint()
{

View File

@@ -24,8 +24,8 @@
#define SURFACE_BLEND_POINT_H
#include <Mod/Surface/SurfaceGlobal.h>
#include <Base/Vector3D.h>
#include <Mod/Surface/SurfaceGlobal.h>
#include <vector>
@@ -33,9 +33,9 @@ namespace Surface
{
/*!
* Create a list of vectors formed by a point and some derivatives
* obtained from a curve or surface
*/
* Create a list of vectors formed by a point and some derivatives
* obtained from a curve or surface
*/
class SurfaceExport BlendPoint
{
public:
@@ -43,29 +43,29 @@ public:
BlendPoint();
/*!
* Constructor
*\param std::vector<Base::Vector3d>
*/
* Constructor
*\param std::vector<Base::Vector3d>
*/
explicit BlendPoint(const std::vector<Base::Vector3d>& vectorList);
~BlendPoint() = default;
/*!
* Scale the blendpoint vectors
*\param double scaling factor
*/
* Scale the blendpoint vectors
*\param double scaling factor
*/
void multiply(double f);
/*!
* Resize the blendpoint vectors
* by setting the size of the first derivative
*\param double new size
*/
* Resize the blendpoint vectors
* by setting the size of the first derivative
*\param double new size
*/
void setSize(double f);
/*!
*\return continuity of this BlendPoint
*/
*\return continuity of this BlendPoint
*/
int getContinuity();
/*!
*\return Number of vectors of this BlendPoint
*/
*\return Number of vectors of this BlendPoint
*/
int nbVectors();
private:
@@ -73,4 +73,3 @@ private:
}// namespace Surface
#endif

View File

@@ -25,9 +25,13 @@
#include <BRepAdaptor_Curve.hxx>
#include <TopoDS.hxx>
#endif
// clang-format off
#include "Blending/BlendPoint.h"
#include "Blending/BlendPointPy.h"
#include "Blending/BlendPointPy.cpp"
// clang-format on
#include <Base/GeometryPyCXX.h>
#include <Base/VectorPy.h>
#include <Mod/Part/App/TopoShapePy.h>
@@ -47,15 +51,15 @@ std::string BlendPointPy::representation() const
return str.str();
}
PyObject *BlendPointPy::PyMake(struct _typeobject *, PyObject *, PyObject *)// Python wrapper
PyObject* BlendPointPy::PyMake(struct _typeobject*, PyObject*, PyObject*)// Python wrapper
{
// create a new instance of BlendPointPy
return new BlendPointPy(new BlendPoint);
}
int BlendPointPy::PyInit(PyObject *args, PyObject *)
int BlendPointPy::PyInit(PyObject* args, PyObject*)
{
PyObject *plist;
PyObject* plist;
std::vector<Base::Vector3d> vecs;
if (PyArg_ParseTuple(args, "O", &plist)) {
Py::Sequence list(plist);
@@ -82,14 +86,15 @@ int BlendPointPy::PyInit(PyObject *args, PyObject *)
double param;
int cont;
PyObject *pcObj;
PyObject* pcObj;
PyErr_Clear();
// Create a curve with an edge, parameter and continiuity.
if (PyArg_ParseTuple(args, "O!di", &(Part::TopoShapePy::Type), &pcObj, &param, &cont)) {
try {
gp_Pnt Pt;
TopoDS_Shape shape = static_cast<Part::TopoShapePy *>(pcObj)->getTopoShapePtr()->getShape();
const TopoDS_Edge &e = TopoDS::Edge(shape);
TopoDS_Shape shape =
static_cast<Part::TopoShapePy*>(pcObj)->getTopoShapePtr()->getShape();
const TopoDS_Edge& e = TopoDS::Edge(shape);
BRepAdaptor_Curve adapt(e);
if (param < adapt.FirstParameter() || param > adapt.LastParameter()) {
PyErr_Warn(PyExc_UserWarning, "BlendPoint: edge is not a closed curve");
@@ -109,39 +114,42 @@ int BlendPointPy::PyInit(PyObject *args, PyObject *)
this->getBlendPointPtr()->vectors = vecs;
return 0;
}
catch (const std::exception &e) {
catch (const std::exception& e) {
PyErr_SetString(PyExc_RuntimeError, e.what());
return -1;
}
}
PyErr_SetString(PyExc_TypeError, "supported signatures:\n"
PyErr_SetString(PyExc_TypeError,
"supported signatures:\n"
"BlendPoint()\n"
"BlendPoint(list of Vector)\n"
"BlendPoint(edge, parameter and continiuity)\n");
return -1;
}
PyObject *BlendPointPy::setSize(PyObject *args)
PyObject* BlendPointPy::setSize(PyObject* args)
{
double size = 1.0;
if (!PyArg_ParseTuple(args, "d", &size))
if (!PyArg_ParseTuple(args, "d", &size)) {
return nullptr;
}
try {
getBlendPointPtr()->setSize(size);
Py_Return;
}
catch (Standard_Failure &) {
catch (Standard_Failure&) {
PyErr_SetString(Base::PyExc_FC_CADKernelError, "Failed to set size");
return nullptr;
}
}
PyObject *BlendPointPy::getSize(PyObject *args)
PyObject* BlendPointPy::getSize(PyObject* args)
{
if (!PyArg_ParseTuple(args, ""))
if (!PyArg_ParseTuple(args, "")) {
return nullptr;
}
int nb = getBlendPointPtr()->nbVectors();
if (nb >= 2) {
double bpTangentLength = getBlendPointPtr()->vectors[1].Length();
@@ -154,18 +162,18 @@ PyObject *BlendPointPy::getSize(PyObject *args)
Py::List BlendPointPy::getVectors() const
{
BlendPoint *bp = getBlendPointPtr();
BlendPoint* bp = getBlendPointPtr();
Py::List vecs;
for (const auto& p : bp->vectors) {
Base::VectorPy *vec = new Base::VectorPy(p);
Base::VectorPy* vec = new Base::VectorPy(p);
vecs.append(Py::asObject(vec));
}
return vecs;
}
PyObject *BlendPointPy::setvectors(PyObject *args)
PyObject* BlendPointPy::setvectors(PyObject* args)
{
PyObject *plist;
PyObject* plist;
if (!PyArg_ParseTuple(args, "O", &plist)) {
PyErr_SetString(PyExc_TypeError, "List of vectors required.");
return nullptr;
@@ -179,17 +187,17 @@ PyObject *BlendPointPy::setvectors(PyObject *args)
vecs.emplace_back(pole);
}
BlendPoint *bp = getBlendPointPtr();
BlendPoint* bp = getBlendPointPtr();
bp->vectors = vecs;
Py_Return;
}
PyObject *BlendPointPy::getCustomAttributes(const char * /*attr*/) const
PyObject* BlendPointPy::getCustomAttributes(const char* /*attr*/) const
{
return nullptr;
}
int BlendPointPy::setCustomAttributes(const char * /*attr*/, PyObject * /*obj*/)
int BlendPointPy::setCustomAttributes(const char* /*attr*/, PyObject* /*obj*/)
{
return 0;
}

View File

@@ -30,9 +30,9 @@
#include <gp_Pnt.hxx>
#endif
#include <Base/Tools.h>
#include "Mod/Surface/App/Blending/BlendCurve.h"
#include "Mod/Surface/App/Blending/BlendPoint.h"
#include <Base/Tools.h>
#include "FeatureBlendCurve.h"
@@ -47,20 +47,52 @@ PROPERTY_SOURCE(Surface::FeatureBlendCurve, Part::Spline)
FeatureBlendCurve::FeatureBlendCurve()
{
ADD_PROPERTY_TYPE(StartEdge, (nullptr), "FirstEdge", App::Prop_None, "Edge support of the start point");
ADD_PROPERTY_TYPE(StartContinuity, (2), "FirstEdge", App::Prop_None, "Geometric continuity at start point");
ADD_PROPERTY_TYPE(StartEdge,
(nullptr),
"FirstEdge",
App::Prop_None,
"Edge support of the start point");
ADD_PROPERTY_TYPE(StartContinuity,
(2),
"FirstEdge",
App::Prop_None,
"Geometric continuity at start point");
StartContinuity.setConstraints(&ContinuityConstraint);
ADD_PROPERTY_TYPE(StartParameter, (0.0f), "FirstEdge", App::Prop_None, "Parameter of start point along edge");
ADD_PROPERTY_TYPE(StartParameter,
(0.0f),
"FirstEdge",
App::Prop_None,
"Parameter of start point along edge");
StartParameter.setConstraints(&ParameterConstraint);
ADD_PROPERTY_TYPE(StartSize, (1.0f), "FirstEdge", App::Prop_None, "Size of derivatives at start point");
ADD_PROPERTY_TYPE(StartSize,
(1.0f),
"FirstEdge",
App::Prop_None,
"Size of derivatives at start point");
StartSize.setConstraints(&SizeConstraint);
ADD_PROPERTY_TYPE(EndEdge, (nullptr), "SecondEdge", App::Prop_None, "Edge support of the end point");
ADD_PROPERTY_TYPE(EndContinuity, (2), "SecondEdge", App::Prop_None, "Geometric continuity at end point");
ADD_PROPERTY_TYPE(EndEdge,
(nullptr),
"SecondEdge",
App::Prop_None,
"Edge support of the end point");
ADD_PROPERTY_TYPE(EndContinuity,
(2),
"SecondEdge",
App::Prop_None,
"Geometric continuity at end point");
EndContinuity.setConstraints(&ContinuityConstraint);
ADD_PROPERTY_TYPE(EndParameter, (0.0f), "SecondEdge", App::Prop_None, "Parameter of end point along edge");
ADD_PROPERTY_TYPE(EndParameter,
(0.0f),
"SecondEdge",
App::Prop_None,
"Parameter of end point along edge");
EndParameter.setConstraints(&ParameterConstraint);
ADD_PROPERTY_TYPE(EndSize, (1.0f), "SecondEdge", App::Prop_None, "Size of derivatives at end point");
ADD_PROPERTY_TYPE(EndSize,
(1.0f),
"SecondEdge",
App::Prop_None,
"Size of derivatives at end point");
EndSize.setConstraints(&SizeConstraint);
Handle(Geom_BezierCurve) maxDegreeCurve;
@@ -69,42 +101,56 @@ FeatureBlendCurve::FeatureBlendCurve()
short FeatureBlendCurve::mustExecute() const
{
if (StartEdge.isTouched())
if (StartEdge.isTouched()) {
return 1;
if (StartParameter.isTouched())
}
if (StartParameter.isTouched()) {
return 1;
if (StartContinuity.isTouched())
}
if (StartContinuity.isTouched()) {
return 1;
if (StartSize.isTouched())
}
if (StartSize.isTouched()) {
return 1;
if (EndEdge.isTouched())
}
if (EndEdge.isTouched()) {
return 1;
if (EndParameter.isTouched())
}
if (EndParameter.isTouched()) {
return 1;
if (EndContinuity.isTouched())
}
if (EndContinuity.isTouched()) {
return 1;
if (EndSize.isTouched())
}
if (EndSize.isTouched()) {
return 1;
}
return 0;
}
BlendPoint FeatureBlendCurve::GetBlendPoint(App::PropertyLinkSub &link, App::PropertyFloatConstraint &param, App::PropertyIntegerConstraint &continuity)
BlendPoint FeatureBlendCurve::GetBlendPoint(App::PropertyLinkSub& link,
App::PropertyFloatConstraint& param,
App::PropertyIntegerConstraint& continuity)
{
auto linked = link.getValue();
TopoDS_Shape axEdge;
if (link.getSubValues().size() > 0 && link.getSubValues()[0].length() > 0) {
axEdge = Feature::getTopoShape(linked, link.getSubValues()[0].c_str(), true /*need element*/).getShape();
axEdge =
Feature::getTopoShape(linked, link.getSubValues()[0].c_str(), true /*need element*/)
.getShape();
}
else {
axEdge = Feature::getShape(linked);
}
if (axEdge.IsNull())
if (axEdge.IsNull()) {
throw Base::ValueError("DirLink shape is null");
if (axEdge.ShapeType() != TopAbs_EDGE)
}
if (axEdge.ShapeType() != TopAbs_EDGE) {
throw Base::TypeError("DirLink shape is not an edge");
const TopoDS_Edge &e = TopoDS::Edge(axEdge);
}
const TopoDS_Edge& e = TopoDS::Edge(axEdge);
BRepAdaptor_Curve adapt(e);
double fp = adapt.FirstParameter();
double lp = adapt.LastParameter();
@@ -129,7 +175,7 @@ BlendPoint FeatureBlendCurve::GetBlendPoint(App::PropertyLinkSub &link, App::Pro
return bp;
}
App::DocumentObjectExecReturn *FeatureBlendCurve::execute()
App::DocumentObjectExecReturn* FeatureBlendCurve::execute()
{
BlendPoint bp1 = GetBlendPoint(StartEdge, StartParameter, StartContinuity);
BlendPoint bp2 = GetBlendPoint(EndEdge, EndParameter, EndContinuity);
@@ -157,7 +203,7 @@ double FeatureBlendCurve::RelativeToRealParameters(double relativeValue, double
}
void FeatureBlendCurve::onChanged(const App::Property *prop)
void FeatureBlendCurve::onChanged(const App::Property* prop)
{
if (prop == &StartContinuity) {
long maxValue = maxDegree - 2 - EndContinuity.getValue();
@@ -171,9 +217,10 @@ void FeatureBlendCurve::onChanged(const App::Property *prop)
EndContinuity.setValue(maxValue);
}
}
if (prop == &StartContinuity || prop == &StartParameter || prop == &StartSize || prop == &EndContinuity || prop == &EndParameter || prop == &EndSize) {
if (prop == &StartContinuity || prop == &StartParameter || prop == &StartSize
|| prop == &EndContinuity || prop == &EndParameter || prop == &EndSize) {
if (!isRestoring()) {
App::DocumentObjectExecReturn *ret = recompute();
App::DocumentObjectExecReturn* ret = recompute();
delete ret;
}
}

View File

@@ -27,8 +27,8 @@
#include <App/PropertyStandard.h>
#include <App/PropertyUnits.h>
#include <Mod/Part/App/FeaturePartSpline.h>
#include <Mod/Surface/SurfaceGlobal.h>
#include <Mod/Surface/App/Blending/BlendPoint.h>
#include <Mod/Surface/SurfaceGlobal.h>
namespace Surface
{
@@ -38,7 +38,6 @@ class SurfaceExport FeatureBlendCurve: public Part::Spline
PROPERTY_HEADER_WITH_OVERRIDE(Surface::FeatureBlendCurve);
public:
FeatureBlendCurve();
App::PropertyLinkSub StartEdge;
@@ -53,21 +52,23 @@ public:
Standard_Integer maxDegree;
App::DocumentObjectExecReturn *execute() override;
App::DocumentObjectExecReturn* execute() override;
short mustExecute() const override;
const char *getViewProviderName() const override
const char* getViewProviderName() const override
{
return "SurfaceGui::ViewProviderBlendCurve";
}
private:
BlendPoint GetBlendPoint(App::PropertyLinkSub &link, App::PropertyFloatConstraint &param, App::PropertyIntegerConstraint &Continuity);
BlendPoint GetBlendPoint(App::PropertyLinkSub& link,
App::PropertyFloatConstraint& param,
App::PropertyIntegerConstraint& Continuity);
double RelativeToRealParameters(double, double, double);
protected:
void onChanged(const App::Property *prop) override;
void onChanged(const App::Property* prop) override;
};
}//Namespace Surface
}// Namespace Surface
#endif

View File

@@ -22,7 +22,7 @@
#include "PreCompiled.h"
#ifndef _PreComp_
# include <TopoDS.hxx>
#include <TopoDS.hxx>
#endif
#include "FeatureCut.h"
@@ -34,41 +34,43 @@ PROPERTY_SOURCE(Surface::Cut, Part::Feature)
Cut::Cut()
{
ADD_PROPERTY(ShapeList,(nullptr,"TopoDS_Shape"));
ADD_PROPERTY(ShapeList, (nullptr, "TopoDS_Shape"));
ShapeList.setScope(App::LinkScope::Global);
}
//Check if any components of the surface have been modified
// Check if any components of the surface have been modified
short Cut::mustExecute() const
{
if (ShapeList.isTouched())
if (ShapeList.isTouched()) {
return 1;
}
return 0;
}
App::DocumentObjectExecReturn *Cut::execute()
App::DocumentObjectExecReturn* Cut::execute()
{
//Perform error checking
// Perform error checking
try {
std::vector<App::DocumentObject*> shapes = ShapeList.getValues();
if (shapes.size() != 2){
return new App::DocumentObjectExecReturn("Two shapes must be entered at a time for a cut operation");
if (shapes.size() != 2) {
return new App::DocumentObjectExecReturn(
"Two shapes must be entered at a time for a cut operation");
}
Part::TopoShape ts1;
Part::TopoShape ts2;
//Get first toposhape
// Get first toposhape
if (shapes[0]->getTypeId().isDerivedFrom(Part::Feature::getClassTypeId())) {
ts1 = static_cast<Part::Feature*>(shapes[0])->Shape.getShape(); //Part::TopoShape 1
ts1 = static_cast<Part::Feature*>(shapes[0])->Shape.getShape();// Part::TopoShape 1
}
else {
return new App::DocumentObjectExecReturn("Shape1 not from Part::Feature");
}
//Get second toposhape
// Get second toposhape
if (shapes[1]->getTypeId().isDerivedFrom(Part::Feature::getClassTypeId())) {
ts2 = static_cast<Part::Feature*>(shapes[1])->Shape.getShape();
}
@@ -76,12 +78,12 @@ App::DocumentObjectExecReturn *Cut::execute()
return new App::DocumentObjectExecReturn("Shape2 not from Part::Feature");
}
//Cut Shape1 by Shape2
// Cut Shape1 by Shape2
TopoDS_Shape aCutShape;
aCutShape = ts1.cut(ts2.getShape());
//Check if resulting shell is null
if (aCutShape.IsNull()){
// Check if resulting shell is null
if (aCutShape.IsNull()) {
return new App::DocumentObjectExecReturn("Resulting shape is null");
}

View File

@@ -31,25 +31,24 @@
namespace Surface
{
class SurfaceExport Cut : public Part::Feature
class SurfaceExport Cut: public Part::Feature
{
PROPERTY_HEADER_WITH_OVERRIDE(Surface::Cut);
public:
Cut();
App::PropertyLinkSubList ShapeList; //Shapes to be cut.
App::PropertyLinkSubList ShapeList;// Shapes to be cut.
// recalculate the feature
App::DocumentObjectExecReturn *execute() override;
App::DocumentObjectExecReturn* execute() override;
short mustExecute() const override;
/// returns the type name of the view provider
// const char* getViewProviderName(void) const {
// return "SurfaceGui::ViewProviderCut";
// }
// const char* getViewProviderName(void) const {
// return "SurfaceGui::ViewProviderCut";
// }
};
}//Namespace Surface
}// Namespace Surface
#endif

View File

@@ -22,17 +22,17 @@
#include "PreCompiled.h"
#ifndef _PreComp_
# include <BRepAdaptor_Surface.hxx>
# include <BRepBuilderAPI_MakeFace.hxx>
# include <BRepLProp_SLProps.hxx>
# include <Geom_BSplineSurface.hxx>
# include <GeomAPI_PointsToBSplineSurface.hxx>
# include <gp_Pnt.hxx>
# include <Precision.hxx>
# include <Standard_Version.hxx>
# include <TColgp_Array2OfPnt.hxx>
# include <TopoDS.hxx>
# include <TopoDS_Face.hxx>
#include <BRepAdaptor_Surface.hxx>
#include <BRepBuilderAPI_MakeFace.hxx>
#include <BRepLProp_SLProps.hxx>
#include <GeomAPI_PointsToBSplineSurface.hxx>
#include <Geom_BSplineSurface.hxx>
#include <Precision.hxx>
#include <Standard_Version.hxx>
#include <TColgp_Array2OfPnt.hxx>
#include <TopoDS.hxx>
#include <TopoDS_Face.hxx>
#include <gp_Pnt.hxx>
#endif
#include <Base/Tools.h>
@@ -49,7 +49,7 @@ PROPERTY_SOURCE(Surface::Extend, Part::Spline)
Extend::Extend()
{
ADD_PROPERTY(Face,(nullptr));
ADD_PROPERTY(Face, (nullptr));
Face.setScope(App::LinkScope::Global);
ADD_PROPERTY(Tolerance, (0.1));
Tolerance.setConstraints(&ToleranceRange);
@@ -74,32 +74,40 @@ Extend::Extend()
short Extend::mustExecute() const
{
if (Face.isTouched())
if (Face.isTouched()) {
return 1;
if (ExtendUNeg.isTouched())
}
if (ExtendUNeg.isTouched()) {
return 1;
if (ExtendUPos.isTouched())
return 1;
if (ExtendVNeg.isTouched())
}
if (ExtendUPos.isTouched()) {
return 1;
if (ExtendVPos.isTouched())
return 1;
}
if (ExtendVNeg.isTouched()) {
return 1;
}
if (ExtendVPos.isTouched()) {
return 1;
}
return 0;
}
App::DocumentObjectExecReturn *Extend::execute()
App::DocumentObjectExecReturn* Extend::execute()
{
App::DocumentObject* part = Face.getValue();
if (!part || !part->getTypeId().isDerivedFrom(Part::Feature::getClassTypeId()))
if (!part || !part->getTypeId().isDerivedFrom(Part::Feature::getClassTypeId())) {
return new App::DocumentObjectExecReturn("No shape linked.");
}
const auto& faces = Face.getSubValues();
if (faces.size() != 1)
if (faces.size() != 1) {
return new App::DocumentObjectExecReturn("Not exactly one sub-shape linked.");
}
TopoDS_Shape shape = static_cast<Part::Feature*>(part)
->Shape.getShape().getSubShape(faces[0].c_str());
if (shape.IsNull() || shape.ShapeType() != TopAbs_FACE)
TopoDS_Shape shape =
static_cast<Part::Feature*>(part)->Shape.getShape().getSubShape(faces[0].c_str());
if (shape.IsNull() || shape.ShapeType() != TopAbs_FACE) {
return new App::DocumentObjectExecReturn("Sub-shape is not a face.");
}
const TopoDS_Face& face = TopoDS::Face(shape);
BRepAdaptor_Surface adapt(face);
@@ -110,23 +118,23 @@ App::DocumentObjectExecReturn *Extend::execute()
double ur = u2 - u1;
double vr = v2 - v1;
double eu1 = u1 - ur*ExtendUNeg.getValue();
double eu2 = u2 + ur*ExtendUPos.getValue();
double ev1 = v1 - vr*ExtendVNeg.getValue();
double ev2 = v2 + vr*ExtendVPos.getValue();
double eu1 = u1 - ur * ExtendUNeg.getValue();
double eu2 = u2 + ur * ExtendUPos.getValue();
double ev1 = v1 - vr * ExtendVNeg.getValue();
double ev2 = v2 + vr * ExtendVPos.getValue();
double eur = eu2 - eu1;
double evr = ev2 - ev1;
long numU = SampleU.getValue();
long numV = SampleV.getValue();
TColgp_Array2OfPnt approxPoints(1, numU, 1, numV);
for (long u=0; u<numU; u++) {
double uu = eu1 + u * eur / (numU-1);
for (long v=0; v<numV; v++) {
double vv = ev1 + v * evr / (numV-1);
BRepLProp_SLProps prop(adapt,uu,vv,0,Precision::Confusion());
for (long u = 0; u < numU; u++) {
double uu = eu1 + u * eur / (numU - 1);
for (long v = 0; v < numV; v++) {
double vv = ev1 + v * evr / (numV - 1);
BRepLProp_SLProps prop(adapt, uu, vv, 0, Precision::Confusion());
const gp_Pnt& pnt = prop.Value();
approxPoints(u+1, v+1) = pnt;
approxPoints(u + 1, v + 1) = pnt;
}
}
@@ -150,30 +158,25 @@ App::DocumentObjectExecReturn *Extend::execute()
void Extend::onChanged(const App::Property* prop)
{
// using a mutex and lock to protect a recursive calling when setting the new values
if (lockOnChangeMutex)
if (lockOnChangeMutex) {
return;
}
Base::StateLocker lock(lockOnChangeMutex);
if (ExtendUSymetric.getValue())
{
if (prop == &ExtendUNeg || prop == &ExtendUPos)
{
if (ExtendUSymetric.getValue()) {
if (prop == &ExtendUNeg || prop == &ExtendUPos) {
auto changedValue = dynamic_cast<const App::PropertyFloat*>(prop);
if (changedValue)
{
if (changedValue) {
ExtendUNeg.setValue(changedValue->getValue());
ExtendUPos.setValue(changedValue->getValue());
}
}
}
if (ExtendVSymetric.getValue())
{
if (prop == &ExtendVNeg || prop == &ExtendVPos)
{
if (ExtendVSymetric.getValue()) {
if (prop == &ExtendVNeg || prop == &ExtendVPos) {
auto changedValue = dynamic_cast<const App::PropertyFloat*>(prop);
if (changedValue)
{
if (changedValue) {
ExtendVNeg.setValue(changedValue->getValue());
ExtendVPos.setValue(changedValue->getValue());
}
@@ -182,18 +185,20 @@ void Extend::onChanged(const App::Property* prop)
Part::Spline::onChanged(prop);
}
void Extend::handleChangedPropertyName(Base::XMLReader &reader,
const char * TypeName,
const char *PropName)
void Extend::handleChangedPropertyName(Base::XMLReader& reader,
const char* TypeName,
const char* PropName)
{
Base::Type type = Base::Type::fromName(TypeName);
if (App::PropertyFloatConstraint::getClassTypeId() == type && strcmp(PropName, "ExtendU") == 0) {
if (App::PropertyFloatConstraint::getClassTypeId() == type
&& strcmp(PropName, "ExtendU") == 0) {
App::PropertyFloatConstraint v;
v.Restore(reader);
ExtendUNeg.setValue(v.getValue());
ExtendUPos.setValue(v.getValue());
}
else if (App::PropertyFloatConstraint::getClassTypeId() == type && strcmp(PropName, "ExtendV") == 0) {
else if (App::PropertyFloatConstraint::getClassTypeId() == type
&& strcmp(PropName, "ExtendV") == 0) {
App::PropertyFloatConstraint v;
v.Restore(reader);
ExtendVNeg.setValue(v.getValue());

View File

@@ -31,7 +31,7 @@
namespace Surface
{
class SurfaceExport Extend : public Part::Spline
class SurfaceExport Extend: public Part::Spline
{
PROPERTY_HEADER_WITH_OVERRIDE(Surface::Extend);
@@ -42,31 +42,32 @@ public:
App::PropertyFloatConstraint Tolerance;
App::PropertyFloatConstraint ExtendUNeg;
App::PropertyFloatConstraint ExtendUPos;
App::PropertyBool ExtendUSymetric;
App::PropertyBool ExtendUSymetric;
App::PropertyFloatConstraint ExtendVNeg;
App::PropertyFloatConstraint ExtendVPos;
App::PropertyBool ExtendVSymetric;
App::PropertyBool ExtendVSymetric;
App::PropertyIntegerConstraint SampleU;
App::PropertyIntegerConstraint SampleV;
// recalculate the feature
App::DocumentObjectExecReturn *execute() override;
App::DocumentObjectExecReturn* execute() override;
short mustExecute() const override;
/// returns the type name of the view provider
const char* getViewProviderName() const override {
const char* getViewProviderName() const override
{
return "SurfaceGui::ViewProviderExtend";
}
protected:
void onChanged(const App::Property* prop) override;
void handleChangedPropertyName(Base::XMLReader &reader,
const char * TypeName,
const char *PropName) override;
void handleChangedPropertyName(Base::XMLReader& reader,
const char* TypeName,
const char* PropName) override;
private:
bool lockOnChangeMutex{false};
bool lockOnChangeMutex {false};
};
}//Namespace Surface
}// Namespace Surface
#endif

View File

@@ -22,14 +22,14 @@
#include "PreCompiled.h"
#ifndef _PreComp_
# include <string>
#include <string>
# include <BRepBuilderAPI_MakeWire.hxx>
# include <BRepFill_Filling.hxx>
# include <BRep_Tool.hxx>
# include <gp_Pnt.hxx>
# include <TopoDS.hxx>
# include <TopoDS_Face.hxx>
#include <BRepBuilderAPI_MakeWire.hxx>
#include <BRepFill_Filling.hxx>
#include <BRep_Tool.hxx>
#include <TopoDS.hxx>
#include <TopoDS_Face.hxx>
#include <gp_Pnt.hxx>
#endif
#include "FeatureFilling.h"
@@ -39,17 +39,23 @@ using namespace Surface;
PROPERTY_SOURCE(Surface::Filling, Part::Spline)
//Initial values
// Initial values
Filling::Filling()
{
ADD_PROPERTY_TYPE(BoundaryEdges,(nullptr,""), "Filling", App::Prop_None, "Boundary Edges (C0 is required for edges without a corresponding face)");
// clang-format off
ADD_PROPERTY_TYPE(BoundaryEdges,(nullptr,""), "Filling", App::Prop_None,
"Boundary Edges (C0 is required for edges without a corresponding face)");
ADD_PROPERTY_TYPE(BoundaryFaces,(""), "Filling", App::Prop_None, "Boundary Faces");
ADD_PROPERTY_TYPE(BoundaryOrder,(-1), "Filling", App::Prop_None, "Order of constraint on boundary faces (C0, G1 and G2 are possible)");
ADD_PROPERTY_TYPE(BoundaryOrder,(-1), "Filling", App::Prop_None,
"Order of constraint on boundary faces (C0, G1 and G2 are possible)");
ADD_PROPERTY_TYPE(UnboundEdges,(nullptr,""), "Filling", App::Prop_None, "Unbound constraint edges (C0 is required for edges without a corresponding face)");
ADD_PROPERTY_TYPE(UnboundFaces,(""), "Filling", App::Prop_None, "Unbound constraint faces");
ADD_PROPERTY_TYPE(UnboundOrder,(-1), "Filling", App::Prop_None, "Order of constraint on curve faces (C0, G1 and G2 are possible)");
ADD_PROPERTY_TYPE(UnboundEdges,(nullptr,""), "Filling", App::Prop_None,
"Unbound constraint edges (C0 is required for edges without a corresponding face)");
ADD_PROPERTY_TYPE(UnboundFaces,(""), "Filling", App::Prop_None,
"Unbound constraint faces");
ADD_PROPERTY_TYPE(UnboundOrder,(-1), "Filling", App::Prop_None,
"Order of constraint on curve faces (C0, G1 and G2 are possible)");
ADD_PROPERTY_TYPE(FreeFaces,(nullptr,""), "Filling", App::Prop_None, "Free constraint on a face");
ADD_PROPERTY_TYPE(FreeOrder,(0), "Filling", App::Prop_None, "Order of constraint on free faces");
@@ -58,7 +64,8 @@ Filling::Filling()
ADD_PROPERTY_TYPE(InitialFace,(nullptr), "Filling", App::Prop_None, "Initial surface to use");
ADD_PROPERTY_TYPE(Degree,(3), "Filling", App::Prop_None, "Starting degree");
ADD_PROPERTY_TYPE(PointsOnCurve,(15), "Filling", App::Prop_None, "Number of points on an edge for constraint");
ADD_PROPERTY_TYPE(PointsOnCurve,(15), "Filling", App::Prop_None,
"Number of points on an edge for constraint");
ADD_PROPERTY_TYPE(Iterations,(2), "Filling", App::Prop_None, "Number of iterations");
ADD_PROPERTY_TYPE(Anisotropy,(false), "Filling", App::Prop_None, "Anisotropy");
ADD_PROPERTY_TYPE(Tolerance2d,(0.00001), "Filling", App::Prop_None, "2D Tolerance");
@@ -67,6 +74,7 @@ Filling::Filling()
ADD_PROPERTY_TYPE(TolCurvature,(0.1), "Filling", App::Prop_None, "G2 tolerance");
ADD_PROPERTY_TYPE(MaximumDegree,(8), "Filling", App::Prop_None, "Maximum curve degree");
ADD_PROPERTY_TYPE(MaximumSegments,(9), "Filling", App::Prop_None, "Maximum number of segments");
// clang-format on
BoundaryEdges.setScope(App::LinkScope::Global);
UnboundEdges.setScope(App::LinkScope::Global);
@@ -87,27 +95,15 @@ Filling::Filling()
short Filling::mustExecute() const
{
if (BoundaryEdges.isTouched() ||
BoundaryFaces.isTouched() ||
BoundaryOrder.isTouched() ||
UnboundEdges.isTouched() ||
UnboundFaces.isTouched() ||
UnboundOrder.isTouched() ||
FreeFaces.isTouched() ||
FreeOrder.isTouched() ||
Points.isTouched() ||
InitialFace.isTouched() ||
Degree.isTouched() ||
PointsOnCurve.isTouched() ||
Iterations.isTouched() ||
Anisotropy.isTouched() ||
Tolerance2d.isTouched() ||
Tolerance3d.isTouched() ||
TolAngular.isTouched() ||
TolCurvature.isTouched() ||
MaximumDegree.isTouched() ||
MaximumSegments.isTouched())
if (BoundaryEdges.isTouched() || BoundaryFaces.isTouched() || BoundaryOrder.isTouched()
|| UnboundEdges.isTouched() || UnboundFaces.isTouched() || UnboundOrder.isTouched()
|| FreeFaces.isTouched() || FreeOrder.isTouched() || Points.isTouched()
|| InitialFace.isTouched() || Degree.isTouched() || PointsOnCurve.isTouched()
|| Iterations.isTouched() || Anisotropy.isTouched() || Tolerance2d.isTouched()
|| Tolerance3d.isTouched() || TolAngular.isTouched() || TolCurvature.isTouched()
|| MaximumDegree.isTouched() || MaximumSegments.isTouched()) {
return 1;
}
return 0;
}
@@ -137,7 +133,8 @@ void Filling::addConstraints(BRepFill_Filling& builder,
if (edge_obj.size() == edge_sub.size()) {
// BRepFill_Filling crashes if the boundary edges are not added in a consecutive order.
// these edges are first added to a test wire to check that they can be securely added to the Filling algo
// these edges are first added to a test wire to check that they can be securely added to
// the Filling algo
BRepBuilderAPI_MakeWire testWire;
for (std::size_t index = 0; index < edge_obj.size(); index++) {
// get the part object
@@ -167,7 +164,8 @@ void Filling::addConstraints(BRepFill_Filling& builder,
builder.Add(TopoDS::Edge(edge), cont, bnd);
}
else {
Standard_Failure::Raise("Boundary edges must be added in a consecutive order");
Standard_Failure::Raise(
"Boundary edges must be added in a consecutive order");
}
}
}
@@ -185,7 +183,8 @@ void Filling::addConstraints(BRepFill_Filling& builder,
builder.Add(TopoDS::Edge(edge), TopoDS::Face(face), cont, bnd);
}
else {
Standard_Failure::Raise("Boundary edges must be added in a consecutive order");
Standard_Failure::Raise(
"Boundary edges must be added in a consecutive order");
}
}
}
@@ -214,8 +213,7 @@ void Filling::addConstraints(BRepFill_Filling& builder,
auto face_sub = faces.getSubValues();
auto contvals = orders.getValues();
if (face_obj.size() == face_sub.size() &&
face_obj.size() == contvals.size()) {
if (face_obj.size() == face_sub.size() && face_obj.size() == contvals.size()) {
for (std::size_t index = 0; index < face_obj.size(); index++) {
App::DocumentObject* obj = face_obj[index];
const std::string& sub = face_sub[index];
@@ -237,8 +235,7 @@ void Filling::addConstraints(BRepFill_Filling& builder,
}
}
void Filling::addConstraints(BRepFill_Filling& builder,
const App::PropertyLinkSubList& pointsList)
void Filling::addConstraints(BRepFill_Filling& builder, const App::PropertyLinkSubList& pointsList)
{
auto points = pointsList.getSubListValues();
for (const auto& it : points) {
@@ -257,12 +254,12 @@ void Filling::addConstraints(BRepFill_Filling& builder,
}
}
App::DocumentObjectExecReturn *Filling::execute()
App::DocumentObjectExecReturn* Filling::execute()
{
//Assign Variables
unsigned int degree = Degree.getValue();
// Assign Variables
unsigned int degree = Degree.getValue();
unsigned int ptsoncurve = PointsOnCurve.getValue();
unsigned int numIter = Iterations.getValue();
unsigned int numIter = Iterations.getValue();
bool anisotropy = Anisotropy.getValue();
double tol2d = Tolerance2d.getValue();
double tol3d = Tolerance3d.getValue();
@@ -272,11 +269,20 @@ App::DocumentObjectExecReturn *Filling::execute()
unsigned int maxseg = MaximumSegments.getValue();
try {
BRepFill_Filling builder(degree, ptsoncurve, numIter, anisotropy, tol2d,
tol3d, tolG1, tolG2, maxdeg, maxseg);
BRepFill_Filling builder(degree,
ptsoncurve,
numIter,
anisotropy,
tol2d,
tol3d,
tolG1,
tolG2,
maxdeg,
maxseg);
if ((BoundaryEdges.getSize()) < 1) {
return new App::DocumentObjectExecReturn("Border must have at least one curve defined.");
return new App::DocumentObjectExecReturn(
"Border must have at least one curve defined.");
}
// Load the initial surface if set
@@ -312,14 +318,15 @@ App::DocumentObjectExecReturn *Filling::execute()
addConstraints(builder, Points);
}
//Build the face
if (numBoundaries > 1)
// Build the face
if (numBoundaries > 1) {
builder.Build();
}
if (!builder.IsDone()) {
Standard_Failure::Raise("Failed to create a face from constraints");
}
//Return the face
// Return the face
TopoDS_Face aFace = builder.Face();
this->Shape.setValue(aFace);
return App::DocumentObject::StdReturn;

View File

@@ -33,42 +33,45 @@ class BRepFill_Filling;
namespace Surface
{
class SurfaceExport Filling : public Part::Spline
class SurfaceExport Filling: public Part::Spline
{
PROPERTY_HEADER_WITH_OVERRIDE(Surface::Filling);
public:
Filling();
//Properties of Curves
App::PropertyLinkSubList BoundaryEdges; // Boundary Edges (C0 is required for edges without a corresponding face)
App::PropertyStringList BoundaryFaces; // Boundary Faces (C0, G1 and G2 are possible)
App::PropertyIntegerList BoundaryOrder; // Order of constraint on border faces
App::PropertyLinkSubList UnboundEdges; // Unbound constraint edges (C0 is required for edges without a corresponding face)
App::PropertyStringList UnboundFaces; // Unbound constraint faces (C0, G1 and G2 are possible)
App::PropertyIntegerList UnboundOrder; // Order of constraint on curve faces
App::PropertyLinkSubList FreeFaces; // Free constraint faces
App::PropertyIntegerList FreeOrder; // Order of constraint on free faces
App::PropertyLinkSubList Points; // Constraint Points (on Surface)
App::PropertyLinkSub InitialFace; // Initial Face to use
// Properties of Curves
App::PropertyLinkSubList
BoundaryEdges;// Boundary Edges (C0 is required for edges without a corresponding face)
App::PropertyStringList BoundaryFaces; // Boundary Faces (C0, G1 and G2 are possible)
App::PropertyIntegerList BoundaryOrder;// Order of constraint on border faces
App::PropertyLinkSubList UnboundEdges; // Unbound constraint edges (C0 is required for edges
// without a corresponding face)
App::PropertyStringList UnboundFaces; // Unbound constraint faces (C0, G1 and G2 are possible)
App::PropertyIntegerList UnboundOrder; // Order of constraint on curve faces
App::PropertyLinkSubList FreeFaces; // Free constraint faces
App::PropertyIntegerList FreeOrder; // Order of constraint on free faces
App::PropertyLinkSubList Points; // Constraint Points (on Surface)
App::PropertyLinkSub InitialFace; // Initial Face to use
//Algorithm Variables
App::PropertyInteger Degree; //Starting degree
App::PropertyInteger PointsOnCurve; //Number of points on an edge for constraint
App::PropertyInteger Iterations; //Number of iterations
App::PropertyBool Anisotropy; //Anisotropy
App::PropertyFloat Tolerance2d; //2D Tolerance
App::PropertyFloat Tolerance3d; //3D Tolerance
App::PropertyFloat TolAngular; //G1 tolerance
App::PropertyFloat TolCurvature; //G2 tolerance
App::PropertyInteger MaximumDegree; //Maximum curve degree
App::PropertyInteger MaximumSegments; //Maximum number of segments
// Algorithm Variables
App::PropertyInteger Degree; // Starting degree
App::PropertyInteger PointsOnCurve; // Number of points on an edge for constraint
App::PropertyInteger Iterations; // Number of iterations
App::PropertyBool Anisotropy; // Anisotropy
App::PropertyFloat Tolerance2d; // 2D Tolerance
App::PropertyFloat Tolerance3d; // 3D Tolerance
App::PropertyFloat TolAngular; // G1 tolerance
App::PropertyFloat TolCurvature; // G2 tolerance
App::PropertyInteger MaximumDegree; // Maximum curve degree
App::PropertyInteger MaximumSegments;// Maximum number of segments
// recalculate the feature
App::DocumentObjectExecReturn *execute() override;
App::DocumentObjectExecReturn* execute() override;
short mustExecute() const override;
/// returns the type name of the view provider
const char* getViewProviderName() const override {
const char* getViewProviderName() const override
{
return "SurfaceGui::ViewProviderFilling";
}
@@ -81,10 +84,9 @@ private:
void addConstraints(BRepFill_Filling& builder,
const App::PropertyLinkSubList& faces,
const App::PropertyIntegerList& orders);
void addConstraints(BRepFill_Filling& builder,
const App::PropertyLinkSubList& points);
void addConstraints(BRepFill_Filling& builder, const App::PropertyLinkSubList& points);
};
} //Namespace Surface
}// Namespace Surface
#endif

View File

@@ -24,22 +24,21 @@
#include "PreCompiled.h"
#ifndef _PreComp_
#include <BRep_Tool.hxx>
#include <BRepBuilderAPI_Copy.hxx>
#include <BRepBuilderAPI_MakeFace.hxx>
#include <Geom_BezierCurve.hxx>
#include <Geom_BezierSurface.hxx>
#include <Geom_BSplineCurve.hxx>
#include <Geom_BSplineSurface.hxx>
#include <Geom_TrimmedCurve.hxx>
#include <BRep_Tool.hxx>
#include <GeomConvert.hxx>
#include <GeomFill.hxx>
#include <GeomFill_BezierCurves.hxx>
#include <GeomFill_BSplineCurves.hxx>
#include <gp_Trsf.hxx>
#include <GeomFill_BezierCurves.hxx>
#include <Geom_BSplineCurve.hxx>
#include <Geom_BSplineSurface.hxx>
#include <Geom_BezierCurve.hxx>
#include <Geom_BezierSurface.hxx>
#include <Geom_TrimmedCurve.hxx>
#include <ShapeConstruct_Curve.hxx>
#include <ShapeFix_Wire.hxx>
#include <ShapeExtend_WireData.hxx>
#include <ShapeFix_Wire.hxx>
#include <Standard_ConstructionError.hxx>
#include <StdFail_NotDone.hxx>
#include <TopExp_Explorer.hxx>
@@ -47,6 +46,7 @@
#include <TopoDS_Edge.hxx>
#include <TopoDS_Face.hxx>
#include <TopoDS_Wire.hxx>
#include <gp_Trsf.hxx>
#endif
#include "FeatureGeomFillSurface.h"
@@ -56,7 +56,7 @@ using namespace Surface;
ShapeValidator::ShapeValidator()
{
initValidator();
initValidator();
}
void ShapeValidator::initValidator()
@@ -72,12 +72,13 @@ void ShapeValidator::checkEdge(const TopoDS_Shape& shape)
Standard_Failure::Raise("Shape is not an edge.\n");
}
TopoDS_Edge etmp = TopoDS::Edge(shape); //Curve TopoDS_Edge
TopLoc_Location heloc; // this will be output
Standard_Real u0;// contains output
Standard_Real u1;// contains output
Handle(Geom_Curve) c_geom = BRep_Tool::Curve(etmp,heloc,u0,u1); //The geometric curve
Handle(Geom_BezierCurve) bez_geom = Handle(Geom_BezierCurve)::DownCast(c_geom); //Try to get Bezier curve
TopoDS_Edge etmp = TopoDS::Edge(shape); // Curve TopoDS_Edge
TopLoc_Location heloc; // this will be output
Standard_Real u0; // contains output
Standard_Real u1; // contains output
Handle(Geom_Curve) c_geom = BRep_Tool::Curve(etmp, heloc, u0, u1);// The geometric curve
Handle(Geom_BezierCurve) bez_geom =
Handle(Geom_BezierCurve)::DownCast(c_geom);// Try to get Bezier curve
// if not a Bezier then try to create a B-spline surface from the edges
if (bez_geom.IsNull()) {
@@ -87,7 +88,7 @@ void ShapeValidator::checkEdge(const TopoDS_Shape& shape)
edgeCount++;
}
void ShapeValidator::checkAndAdd(const TopoDS_Shape &shape, Handle(ShapeExtend_WireData) *aWD)
void ShapeValidator::checkAndAdd(const TopoDS_Shape& shape, Handle(ShapeExtend_WireData) * aWD)
{
checkEdge(shape);
if (aWD) {
@@ -97,11 +98,13 @@ void ShapeValidator::checkAndAdd(const TopoDS_Shape &shape, Handle(ShapeExtend_W
}
}
void ShapeValidator::checkAndAdd(const Part::TopoShape &ts, const char *subName, Handle(ShapeExtend_WireData) *aWD)
void ShapeValidator::checkAndAdd(const Part::TopoShape& ts,
const char* subName,
Handle(ShapeExtend_WireData) * aWD)
{
try {
if (subName && *subName != '\0') {
//we want only the subshape which is linked
// we want only the subshape which is linked
checkAndAdd(ts.getSubShape(subName), aWD);
}
else if (!ts.getShape().IsNull() && ts.getShape().ShapeType() == TopAbs_WIRE) {
@@ -114,7 +117,7 @@ void ShapeValidator::checkAndAdd(const Part::TopoShape &ts, const char *subName,
checkAndAdd(ts.getShape(), aWD);
}
}
catch (Standard_Failure&) { // any OCC exception means an inappropriate shape in the selection
catch (Standard_Failure&) {// any OCC exception means an inappropriate shape in the selection
Standard_Failure::Raise("Wrong shape type.\n");
}
}
@@ -122,9 +125,10 @@ void ShapeValidator::checkAndAdd(const Part::TopoShape &ts, const char *subName,
PROPERTY_SOURCE(Surface::GeomFillSurface, Part::Spline)
const char* GeomFillSurface::FillTypeEnums[] = {"Stretched", "Coons", "Curved", nullptr};
const char* GeomFillSurface::FillTypeEnums[] = {"Stretched", "Coons", "Curved", nullptr};
GeomFillSurface::GeomFillSurface(): Spline()
GeomFillSurface::GeomFillSurface()
: Spline()
{
ADD_PROPERTY(FillType, ((long)0));
ADD_PROPERTY(BoundaryList, (nullptr, "Dummy"));
@@ -134,12 +138,10 @@ GeomFillSurface::GeomFillSurface(): Spline()
}
//Check if any components of the surface have been modified
// Check if any components of the surface have been modified
short GeomFillSurface::mustExecute() const
{
if (BoundaryList.isTouched() ||
ReversedList.isTouched() ||
FillType.isTouched()) {
if (BoundaryList.isTouched() || ReversedList.isTouched() || FillType.isTouched()) {
return 1;
}
return Spline::mustExecute();
@@ -158,12 +160,12 @@ void GeomFillSurface::onChanged(const App::Property* prop)
Part::Spline::onChanged(prop);
}
App::DocumentObjectExecReturn *GeomFillSurface::execute()
App::DocumentObjectExecReturn* GeomFillSurface::execute()
{
try {
TopoDS_Wire aWire;
//Gets the healed wire
// Gets the healed wire
if (getWire(aWire)) {
createBezierSurface(aWire);
}
@@ -178,7 +180,8 @@ App::DocumentObjectExecReturn *GeomFillSurface::execute()
return new App::DocumentObjectExecReturn("Curves are disjoint.");
}
catch (StdFail_NotDone&) {
return new App::DocumentObjectExecReturn("A curve was not a B-spline and could not be converted into one.");
return new App::DocumentObjectExecReturn(
"A curve was not a B-spline and could not be converted into one.");
}
catch (Standard_Failure& e) {
return new App::DocumentObjectExecReturn(e.GetMessageString());
@@ -187,15 +190,16 @@ App::DocumentObjectExecReturn *GeomFillSurface::execute()
GeomFill_FillingStyle GeomFillSurface::getFillingStyle()
{
//Identify filling style
// Identify filling style
switch (FillType.getValue()) {
case GeomFill_StretchStyle:
case GeomFill_CoonsStyle:
case GeomFill_CurvedStyle:
return static_cast<GeomFill_FillingStyle>(FillType.getValue());
default:
Standard_Failure::Raise("Filling style must be 0 (Stretch), 1 (Coons), or 2 (Curved).\n");
return GeomFill_StretchStyle; // this is to shut up the compiler
case GeomFill_StretchStyle:
case GeomFill_CoonsStyle:
case GeomFill_CurvedStyle:
return static_cast<GeomFill_FillingStyle>(FillType.getValue());
default:
Standard_Failure::Raise(
"Filling style must be 0 (Stretch), 1 (Coons), or 2 (Curved).\n");
return GeomFill_StretchStyle;// this is to shut up the compiler
}
}
@@ -210,10 +214,11 @@ bool GeomFillSurface::getWire(TopoDS_Wire& aWire)
}
ShapeValidator validator;
for(const auto& set : boundary) {
for (const auto& set : boundary) {
if (set.first->getTypeId().isDerivedFrom(Part::Feature::getClassTypeId())) {
for (const auto& jt : set.second) {
const Part::TopoShape &ts = static_cast<Part::Feature*>(set.first)->Shape.getShape();
const Part::TopoShape& ts =
static_cast<Part::Feature*>(set.first)->Shape.getShape();
validator.checkAndAdd(ts, jt.c_str(), &aWD);
}
}
@@ -226,16 +231,16 @@ bool GeomFillSurface::getWire(TopoDS_Wire& aWire)
Standard_Failure::Raise("Only 2-4 curves are allowed\n");
}
//Reorder the curves and fix the wire if required
// Reorder the curves and fix the wire if required
aShFW->Load(aWD); //Load in the wire
aShFW->FixReorder(); //Fix the order of the edges if required
aShFW->ClosedWireMode() = Standard_True; //Enables closed wire mode
aShFW->FixConnected(); //Fix connection between wires
aShFW->FixSelfIntersection(); //Fix Self Intersection
aShFW->Perform(); //Perform the fixes
aShFW->Load(aWD); // Load in the wire
aShFW->FixReorder(); // Fix the order of the edges if required
aShFW->ClosedWireMode() = Standard_True;// Enables closed wire mode
aShFW->FixConnected(); // Fix connection between wires
aShFW->FixSelfIntersection(); // Fix Self Intersection
aShFW->Perform(); // Perform the fixes
aWire = aShFW->Wire(); //Healed Wire
aWire = aShFW->Wire();// Healed Wire
if (aWire.IsNull()) {
Standard_Failure::Raise("Wire unable to be constructed\n");
@@ -244,7 +249,7 @@ bool GeomFillSurface::getWire(TopoDS_Wire& aWire)
return validator.isBezier();
}
void GeomFillSurface::createFace(const Handle(Geom_BoundedSurface) &aSurface)
void GeomFillSurface::createFace(const Handle(Geom_BoundedSurface) & aSurface)
{
BRepBuilderAPI_MakeFace aFaceBuilder;
Standard_Real u1, u2, v1, v2;
@@ -268,18 +273,19 @@ void GeomFillSurface::createBezierSurface(TopoDS_Wire& aWire)
std::vector<Handle(Geom_BezierCurve)> curves;
curves.reserve(4);
Standard_Real u1, u2; // contains output
TopExp_Explorer anExp (aWire, TopAbs_EDGE);
Standard_Real u1, u2;// contains output
TopExp_Explorer anExp(aWire, TopAbs_EDGE);
for (; anExp.More(); anExp.Next()) {
const TopoDS_Edge hedge = TopoDS::Edge (anExp.Current());
TopLoc_Location heloc; // this will be output
Handle(Geom_Curve) c_geom = BRep_Tool::Curve(hedge, heloc, u1, u2); //The geometric curve
Handle(Geom_BezierCurve) bezier = Handle(Geom_BezierCurve)::DownCast(c_geom); //Try to get Bezier curve
const TopoDS_Edge hedge = TopoDS::Edge(anExp.Current());
TopLoc_Location heloc; // this will be output
Handle(Geom_Curve) c_geom = BRep_Tool::Curve(hedge, heloc, u1, u2);// The geometric curve
Handle(Geom_BezierCurve) bezier =
Handle(Geom_BezierCurve)::DownCast(c_geom);// Try to get Bezier curve
if (!bezier.IsNull()) {
gp_Trsf transf = heloc.Transformation();
bezier->Transform(transf); // apply original transformation to control points
//Store Underlying Geometry
bezier->Transform(transf);// apply original transformation to control points
// Store Underlying Geometry
curves.push_back(bezier);
}
else {
@@ -288,14 +294,15 @@ void GeomFillSurface::createBezierSurface(TopoDS_Wire& aWire)
}
GeomFill_FillingStyle fstyle = getFillingStyle();
GeomFill_BezierCurves aSurfBuilder; //Create Surface Builder
GeomFill_BezierCurves aSurfBuilder;// Create Surface Builder
std::size_t edgeCount = curves.size();
const boost::dynamic_bitset<>& booleans = ReversedList.getValues();
if (edgeCount == booleans.size()) {
for (std::size_t i=0; i<edgeCount; i++) {
if (booleans[i])
for (std::size_t i = 0; i < edgeCount; i++) {
if (booleans[i]) {
curves[i]->Reverse();
}
}
}
@@ -316,17 +323,18 @@ void GeomFillSurface::createBSplineSurface(TopoDS_Wire& aWire)
{
std::vector<Handle(Geom_BSplineCurve)> curves;
curves.reserve(4);
Standard_Real u1, u2; // contains output
TopExp_Explorer anExp (aWire, TopAbs_EDGE);
Standard_Real u1, u2;// contains output
TopExp_Explorer anExp(aWire, TopAbs_EDGE);
for (; anExp.More(); anExp.Next()) {
const TopoDS_Edge& edge = TopoDS::Edge (anExp.Current());
TopLoc_Location heloc; // this will be output
Handle(Geom_Curve) c_geom = BRep_Tool::Curve(edge, heloc, u1, u2); //The geometric curve
Handle(Geom_BSplineCurve) bspline = Handle(Geom_BSplineCurve)::DownCast(c_geom); //Try to get BSpline curve
const TopoDS_Edge& edge = TopoDS::Edge(anExp.Current());
TopLoc_Location heloc; // this will be output
Handle(Geom_Curve) c_geom = BRep_Tool::Curve(edge, heloc, u1, u2);// The geometric curve
Handle(Geom_BSplineCurve) bspline =
Handle(Geom_BSplineCurve)::DownCast(c_geom);// Try to get BSpline curve
gp_Trsf transf = heloc.Transformation();
if (!bspline.IsNull()) {
bspline->Transform(transf); // apply original transformation to control points
//Store Underlying Geometry
bspline->Transform(transf);// apply original transformation to control points
// Store Underlying Geometry
curves.push_back(bspline);
}
else {
@@ -338,30 +346,34 @@ void GeomFillSurface::createBSplineSurface(TopoDS_Wire& aWire)
Convert_ParameterisationType paratype = Convert_Polynomial;
Handle(Geom_BSplineCurve) bspline2 = conv.CurveToBSplineCurve(trim, paratype);
if (!bspline2.IsNull()) {
bspline2->Transform(transf); // apply original transformation to control points
bspline2->Transform(transf);// apply original transformation to control points
curves.push_back(bspline2);
}
else {
// GeomConvert failed, try ShapeConstruct_Curve now
ShapeConstruct_Curve scc;
Handle(Geom_BSplineCurve) spline = scc.ConvertToBSpline(c_geom, u1, u2, Precision::Confusion());
if (spline.IsNull())
Standard_Failure::Raise("A curve was not a B-spline and could not be converted into one.");
spline->Transform(transf); // apply original transformation to control points
Handle(Geom_BSplineCurve) spline =
scc.ConvertToBSpline(c_geom, u1, u2, Precision::Confusion());
if (spline.IsNull()) {
Standard_Failure::Raise(
"A curve was not a B-spline and could not be converted into one.");
}
spline->Transform(transf);// apply original transformation to control points
curves.push_back(spline);
}
}
}
GeomFill_FillingStyle fstyle = getFillingStyle();
GeomFill_BSplineCurves aSurfBuilder; //Create Surface Builder
GeomFill_BSplineCurves aSurfBuilder;// Create Surface Builder
std::size_t edgeCount = curves.size();
const boost::dynamic_bitset<>& booleans = ReversedList.getValues();
if (edgeCount == booleans.size()) {
for (std::size_t i=0; i<edgeCount; i++) {
if (booleans[i])
for (std::size_t i = 0; i < edgeCount; i++) {
if (booleans[i]) {
curves[i]->Reverse();
}
}
}
if (edgeCount == 2) {

View File

@@ -28,8 +28,8 @@
#include <Mod/Part/App/FeaturePartSpline.h>
#include <Mod/Surface/SurfaceGlobal.h>
#include <Geom_BoundedSurface.hxx>
#include <GeomFill_FillingStyle.hxx>
#include <Geom_BoundedSurface.hxx>
#include <ShapeExtend_WireData.hxx>
@@ -46,33 +46,38 @@ public:
ShapeValidator();
void initValidator();
void checkEdge(const TopoDS_Shape& shape);
void checkAndAdd(const TopoDS_Shape &shape, Handle(ShapeExtend_WireData) *aWD = nullptr);
void checkAndAdd(const Part::TopoShape &ts, const char *subName, Handle(ShapeExtend_WireData) *aWire = nullptr);
void checkAndAdd(const TopoDS_Shape& shape, Handle(ShapeExtend_WireData) * aWD = nullptr);
void checkAndAdd(const Part::TopoShape& ts,
const char* subName,
Handle(ShapeExtend_WireData) * aWire = nullptr);
bool isBezier() const {
bool isBezier() const
{
return willBezier;
}
int numEdges() const {
int numEdges() const
{
return edgeCount;
}
};
class GeomFillSurface : public Part::Spline
class GeomFillSurface: public Part::Spline
{
PROPERTY_HEADER_WITH_OVERRIDE(Surface::GeomFillSurface);
PROPERTY_HEADER_WITH_OVERRIDE(Surface::GeomFillSurface);
public:
GeomFillSurface();
App::PropertyLinkSubList BoundaryList; // Curves to be turned into a face (2-4 curves allowed).
App::PropertyBoolList ReversedList; // Booleans to handle orientation of the curves
App::PropertyEnumeration FillType; // Fill method (1, 2, or 3 for Stretch, Coons, and Curved)
App::PropertyLinkSubList BoundaryList;// Curves to be turned into a face (2-4 curves allowed).
App::PropertyBoolList ReversedList; // Booleans to handle orientation of the curves
App::PropertyEnumeration FillType; // Fill method (1, 2, or 3 for Stretch, Coons, and Curved)
short mustExecute() const override;
void onChanged(const App::Property*) override;
App::DocumentObjectExecReturn *execute() override;
App::DocumentObjectExecReturn* execute() override;
/// returns the type name of the view provider
const char* getViewProviderName() const override {
const char* getViewProviderName() const override
{
return "SurfaceGui::ViewProviderGeomFillSurface";
}
@@ -80,7 +85,7 @@ protected:
GeomFill_FillingStyle getFillingStyle();
/// True means that all edges have Bezier curves
bool getWire(TopoDS_Wire& aWire);
void createFace(const Handle(Geom_BoundedSurface) &aSurface);
void createFace(const Handle(Geom_BoundedSurface) & aSurface);
void createBezierSurface(TopoDS_Wire& aWire);
void createBSplineSurface(TopoDS_Wire& aWire);
@@ -88,6 +93,6 @@ private:
static const char* FillTypeEnums[];
};
}
}// namespace Surface
#endif // FEATUREGEOMFILLSURFACE_H
#endif// FEATUREGEOMFILLSURFACE_H

View File

@@ -22,15 +22,15 @@
#include "PreCompiled.h"
#ifndef _PreComp_
# include <BRepAdaptor_Curve.hxx>
# include <BRepBuilderAPI_MakeFace.hxx>
# include <Geom_BSplineSurface.hxx>
# include <Geom_TrimmedCurve.hxx>
# include <GeomFill_NSections.hxx>
# include <Precision.hxx>
# include <Standard_Version.hxx>
# include <TopLoc_Location.hxx>
# include <TopoDS.hxx>
#include <BRepAdaptor_Curve.hxx>
#include <BRepBuilderAPI_MakeFace.hxx>
#include <GeomFill_NSections.hxx>
#include <Geom_BSplineSurface.hxx>
#include <Geom_TrimmedCurve.hxx>
#include <Precision.hxx>
#include <Standard_Version.hxx>
#include <TopLoc_Location.hxx>
#include <TopoDS.hxx>
#endif
#include "FeatureSections.h"
@@ -42,11 +42,11 @@ PROPERTY_SOURCE(Surface::Sections, Part::Spline)
Sections::Sections()
{
ADD_PROPERTY_TYPE(NSections,(nullptr), "Sections", App::Prop_None, "Section curves");
ADD_PROPERTY_TYPE(NSections, (nullptr), "Sections", App::Prop_None, "Section curves");
NSections.setScope(App::LinkScope::Global);
}
App::DocumentObjectExecReturn *Sections::execute()
App::DocumentObjectExecReturn* Sections::execute()
{
TColGeom_SequenceOfCurve curveSeq;
auto edge_obj = NSections.getValues();
@@ -63,9 +63,10 @@ App::DocumentObjectExecReturn *Sections::execute()
if (!edge.IsNull() && edge.ShapeType() == TopAbs_EDGE) {
BRepAdaptor_Curve curve_adapt(TopoDS::Edge(edge));
const TopLoc_Location& loc = edge.Location();
Handle(Geom_TrimmedCurve) hCurve = new Geom_TrimmedCurve(curve_adapt.Curve().Curve(),
curve_adapt.FirstParameter(),
curve_adapt.LastParameter());
Handle(Geom_TrimmedCurve) hCurve =
new Geom_TrimmedCurve(curve_adapt.Curve().Curve(),
curve_adapt.FirstParameter(),
curve_adapt.LastParameter());
if (!loc.IsIdentity()) {
hCurve->Transform(loc.Transformation());
}
@@ -75,17 +76,19 @@ App::DocumentObjectExecReturn *Sections::execute()
}
}
if (curveSeq.Length() < 2)
if (curveSeq.Length() < 2) {
return new App::DocumentObjectExecReturn("At least two sections are required.");
}
GeomFill_NSections fillOp(curveSeq);
fillOp.ComputeSurface();
Handle(Geom_BSplineSurface) aSurf = fillOp.BSplineSurface();
if (aSurf.IsNull())
if (aSurf.IsNull()) {
return new App::DocumentObjectExecReturn("Failed to create surface from sections.");
}
BRepBuilderAPI_MakeFace mkFace(aSurf, Precision::Confusion() );
BRepBuilderAPI_MakeFace mkFace(aSurf, Precision::Confusion());
Shape.setValue(mkFace.Face());
return StdReturn;

View File

@@ -31,7 +31,7 @@
namespace Surface
{
class SurfaceExport Sections : public Part::Spline
class SurfaceExport Sections: public Part::Spline
{
PROPERTY_HEADER_WITH_OVERRIDE(Surface::Sections);
@@ -41,13 +41,14 @@ public:
App::PropertyLinkSubList NSections;
// recalculate the feature
App::DocumentObjectExecReturn *execute() override;
App::DocumentObjectExecReturn* execute() override;
/// returns the type name of the view provider
const char* getViewProviderName() const override {
const char* getViewProviderName() const override
{
return "SurfaceGui::ViewProviderSections";
}
};
}//Namespace Surface
}// Namespace Surface
#endif

View File

@@ -22,9 +22,9 @@
#include "PreCompiled.h"
#ifndef _PreComp_
# include <BRepBuilderAPI_Sewing.hxx>
# include <Precision.hxx>
# include <TopoDS.hxx>
#include <BRepBuilderAPI_Sewing.hxx>
#include <Precision.hxx>
#include <TopoDS.hxx>
#endif
#include "FeatureSewing.h"
@@ -34,35 +34,40 @@ using namespace Surface;
PROPERTY_SOURCE(Surface::Sewing, Part::Feature)
//Initial values
// Initial values
Sewing::Sewing()
{
ADD_PROPERTY_TYPE(ShapeList,(nullptr,""), "Sewing", App::Prop_None, "Input shapes");
ADD_PROPERTY_TYPE(Tolerance,(Precision::Confusion()), "Sewing", App::Prop_None, "Sewing tolerance");
ADD_PROPERTY_TYPE(SewingOption,(true), "Sewing", App::Prop_None, "Sewing option");
ADD_PROPERTY_TYPE(DegenerateShape,(true), "Sewing", App::Prop_None, "Analysis of degenerated shapes");
ADD_PROPERTY_TYPE(CutFreeEdges,(true), "Sewing", App::Prop_None, "Cutting of free edges");
ADD_PROPERTY_TYPE(Nonmanifold,(false), "Sewing", App::Prop_None, "Non-manifold processing");
ADD_PROPERTY_TYPE(ShapeList, (nullptr, ""), "Sewing", App::Prop_None, "Input shapes");
ADD_PROPERTY_TYPE(Tolerance,
(Precision::Confusion()),
"Sewing",
App::Prop_None,
"Sewing tolerance");
ADD_PROPERTY_TYPE(SewingOption, (true), "Sewing", App::Prop_None, "Sewing option");
ADD_PROPERTY_TYPE(DegenerateShape,
(true),
"Sewing",
App::Prop_None,
"Analysis of degenerated shapes");
ADD_PROPERTY_TYPE(CutFreeEdges, (true), "Sewing", App::Prop_None, "Cutting of free edges");
ADD_PROPERTY_TYPE(Nonmanifold, (false), "Sewing", App::Prop_None, "Non-manifold processing");
ShapeList.setScope(App::LinkScope::Global);
}
short Sewing::mustExecute() const
{
if (ShapeList.isTouched() ||
Tolerance.isTouched() ||
SewingOption.isTouched() ||
DegenerateShape.isTouched() ||
CutFreeEdges.isTouched() ||
Nonmanifold.isTouched())
if (ShapeList.isTouched() || Tolerance.isTouched() || SewingOption.isTouched()
|| DegenerateShape.isTouched() || CutFreeEdges.isTouched() || Nonmanifold.isTouched()) {
return 1;
}
return 0;
}
App::DocumentObjectExecReturn *Sewing::execute()
App::DocumentObjectExecReturn* Sewing::execute()
{
//Assign Variables
// Assign Variables
double atol = Tolerance.getValue();
bool opt1 = SewingOption.getValue();
bool opt2 = DegenerateShape.getValue();
@@ -70,17 +75,17 @@ App::DocumentObjectExecReturn *Sewing::execute()
bool opt4 = Nonmanifold.getValue();
try {
BRepBuilderAPI_Sewing builder(atol,opt1,opt2,opt3,opt4);
BRepBuilderAPI_Sewing builder(atol, opt1, opt2, opt3, opt4);
std::vector<App::PropertyLinkSubList::SubSet> subset = ShapeList.getSubListValues();
for(const auto& it : subset) {
for (const auto& it : subset) {
// the subset has the documentobject and the element name which belongs to it,
// in our case for example the cube object and the "Edge1" string
if (it.first->getTypeId().isDerivedFrom(Part::Feature::getClassTypeId())) {
//we get the shape of the document object which resemble the whole box
// we get the shape of the document object which resemble the whole box
Part::TopoShape ts = static_cast<Part::Feature*>(it.first)->Shape.getShape();
//we want only the subshape which is linked
// we want only the subshape which is linked
for (const auto& jt : it.second) {
TopoDS_Shape sub = ts.getSubShape(jt.c_str());
builder.Add(sub);
@@ -91,11 +96,12 @@ App::DocumentObjectExecReturn *Sewing::execute()
}
}
builder.Perform(); //Perform Sewing
builder.Perform();// Perform Sewing
TopoDS_Shape aShape = builder.SewedShape(); //Get Shape
if (aShape.IsNull())
TopoDS_Shape aShape = builder.SewedShape();// Get Shape
if (aShape.IsNull()) {
return new App::DocumentObjectExecReturn("Resulting shape is null");
}
this->Shape.setValue(aShape);
return StdReturn;
}

View File

@@ -31,26 +31,26 @@
namespace Surface
{
class SurfaceExport Sewing : public Part::Feature
class SurfaceExport Sewing: public Part::Feature
{
PROPERTY_HEADER_WITH_OVERRIDE(Surface::Sewing);
public:
Sewing();
App::PropertyLinkSubList ShapeList; //Shapes to be sewn.
App::PropertyLinkSubList ShapeList;// Shapes to be sewn.
App::PropertyFloat Tolerance;
App::PropertyBool SewingOption; //Option for sewing (if false only control)
App::PropertyBool DegenerateShape; //Option for analysis of degenerated shapes
App::PropertyBool CutFreeEdges; //Option for cutting of free edges
App::PropertyBool Nonmanifold; //Option for non-manifold processing
App::PropertyBool SewingOption; // Option for sewing (if false only control)
App::PropertyBool DegenerateShape;// Option for analysis of degenerated shapes
App::PropertyBool CutFreeEdges; // Option for cutting of free edges
App::PropertyBool Nonmanifold; // Option for non-manifold processing
// recalculate the feature
App::DocumentObjectExecReturn *execute() override;
App::DocumentObjectExecReturn* execute() override;
short mustExecute() const override;
};
}//Namespace Surface
}// Namespace Surface
#endif // SURFACE_FEATURESEWING_H
#endif// SURFACE_FEATURESEWING_H

View File

@@ -30,10 +30,9 @@
// STL
#include <string>
//opencascade
// opencascade
#include <Mod/Part/App/OpenCascadeAll.h>
#endif //_PreComp_
#endif//_PreComp_
#endif