[Surface]: Implementation of BlenCurve.

This commit is contained in:
Matteo-Grellier
2022-07-18 11:05:31 +02:00
committed by wwmayer
parent 6ec601dade
commit 83ee62bca4
18 changed files with 644 additions and 111 deletions

View File

@@ -24,27 +24,30 @@
#include <Base/Console.h>
#include <Base/PyObjectBase.h>
#include "FeatureFilling.h"
#include "FeatureSewing.h"
#include "FeatureCut.h"
#include "FeatureGeomFillSurface.h"
#include "FeatureExtend.h"
#include "FeatureSections.h"
#include "Blending/BlendPointPy.h"
#include "Blending/BlendCurvePy.h"
#include "Blending/BlendPoint.h"
#include "Blending/BlendPointPy.h"
#include "Blending/FeatureBlendCurve.h"
#include "FeatureCut.h"
#include "FeatureExtend.h"
#include "FeatureFilling.h"
#include "FeatureGeomFillSurface.h"
#include "FeatureSections.h"
#include "FeatureSewing.h"
#include <Base/Interpreter.h>
#include <Base/Parameter.h>
namespace Surface {
class Module : public Py::ExtensionModule<Module>
namespace Surface
{
class Module: public Py::ExtensionModule<Module>
{
public:
Module() : Py::ExtensionModule<Module>("Surface")
{
initialize("This module is the Surface module."); // register with Python
initialize("This module is the Surface module.");// register with Python
}
~Module() override {}
@@ -52,38 +55,40 @@ public:
private:
};
PyObject* initModule()
PyObject *initModule()
{
return Base::Interpreter().addModule(new Module);
}
} // namespace Surface
}// namespace Surface
/* Python entry */
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");
// Add types to module
Surface::Filling ::init();
Surface::Sewing ::init();
Surface::Cut ::init();
Surface::GeomFillSurface ::init();
Surface::Extend ::init();
Surface::Sections ::init();
Surface::BlendPoint ::init();
Surface::BlendCurve ::init();
Surface::Filling ::init();
Surface::Sewing ::init();
Surface::Cut ::init();
Surface::GeomFillSurface ::init();
Surface::Extend ::init();
Surface::FeatureBlendCurve ::init();
Surface::Sections ::init();
Surface::BlendPoint ::init();
Surface::BlendCurve ::init();
PyMOD_Return(mod);
}

View File

@@ -33,10 +33,10 @@
#include <math_Gauss.hxx>
#include <math_Matrix.hxx>
#endif
#include <Base/Vector3D.h>
#include <Mod/Part/App/Geometry.h>
#include "Blending/BlendCurve.h"
#include "Blending/BlendCurvePy.h"
#include <Base/Vector3D.h>
#include <Mod/Part/App/Geometry.h>
using namespace Surface;
@@ -47,7 +47,7 @@ BlendCurve::BlendCurve()
BlendCurve::BlendCurve(std::vector<BlendPoint> blendPointsList)
{
// Retrieve number of blendPoints and push them into blendPoints.
int nb_pts = blendPointsList.size();
size_t nb_pts = blendPointsList.size();
if (nb_pts > 2) {
throw Base::ValueError("Not implemented");
@@ -64,23 +64,23 @@ BlendCurve::~BlendCurve()
Handle(Geom_BezierCurve) BlendCurve::compute()
{
int nb_pts = blendPoints.size();
size_t nb_pts = blendPoints.size();
try {
// Uniform Parametrization
TColStd_Array1OfReal params(1, nb_pts);
for (int i = 0; i < nb_pts; ++i) {
params(i + 1) = (double)i / ((double)nb_pts - 1);
}
int num_poles = 0;
for (int i = 0; i < nb_pts; ++i) {
num_poles += blendPoints[i].nbVectors();
}
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) {
knots(i) = params(1);
@@ -127,7 +127,7 @@ Handle(Geom_BezierCurve) BlendCurve::compute()
Handle(Geom_BezierCurve) bezier = new Geom_BezierCurve(poles);
return bezier;
}
catch (Standard_Failure &e) {
PyErr_SetString(PyExc_Exception, "Failed to compute bezier curve");
}
@@ -140,7 +140,7 @@ void BlendCurve::setSize(int i, double f, bool relative)
try {
if (relative) {
double nb_poles = blendPoints.front().nbVectors() + blendPoints[1].nbVectors();
Base::Vector3d diff = blendPoints[1].vectors[0] - blendPoints[0].vectors[0];
Base::Vector3d diff = blendPoints[1].vectors[0] - blendPoints[0].vectors[0];
size = size * diff.Length() / nb_poles;
}
blendPoints[i].setSize(size);

View File

@@ -17,8 +17,7 @@
<Documentation>
<Author Licence="LGPL" Name="Mattéo Grellier" EMail="matteogrellier@gmail.com" />
<UserDocu>
Create a BlendCurve that interpolate a list of BlendPoints.
curve = BlendCurve([BlendPoint1, BlendPoint2])
Create a BlendCurve that interpolate 2 BlendPoints.
curve = BlendCurve(BlendPoint1, BlendPoint2)
</UserDocu>
</Documentation>

View File

@@ -29,9 +29,9 @@
#include "Blending/BlendPointPy.h"
// #include "Mod/Part/App/Geometry.h"
// #include <Base/GeometryPyCXX.h>
#include "Blending/BlendCurvePy.cpp"
#include <Base/VectorPy.h>
#include <Mod/Part/App/BezierCurvePy.h>
#include "Blending/BlendCurvePy.cpp"
using namespace Surface;
@@ -48,30 +48,10 @@ PyObject *BlendCurvePy::PyMake(struct _typeobject *, PyObject *, PyObject *)// P
int BlendCurvePy::PyInit(PyObject *args, PyObject * /*kwds*/)
{
PyObject *plist;
if (PyArg_ParseTuple(args, "O", &plist)) {
Py::Sequence list(plist);
if (list.size() != 2) {
PyErr_SetString(PyExc_TypeError, "Currently BlendCurve need exactly 2 BlendPoints");
return -1;
}
std::vector<BlendPoint> bpList;
for (Py::Sequence::iterator it = list.begin(); it != list.end(); ++it) {
Py::Object obj(*it);
if (PyObject_TypeCheck(obj.ptr(), &BlendPointPy::Type)) {
BlendPoint *geom = static_cast<BlendPointPy *>(obj.ptr())->getBlendPointPtr();
bpList.emplace_back(*geom);
}
}
this->getBlendCurvePtr()->blendPoints = bpList;
return 0;
}
PyErr_Clear();
PyObject *b1;
PyObject *b2;
std::vector<BlendPoint> bpList;
if (PyArg_ParseTuple(args, "O!O!", &(Surface::BlendPointPy::Type), &b1, &(Surface::BlendPointPy::Type), &b2)) {
BlendPoint *geom1 = static_cast<BlendPointPy *>(b1)->getBlendPointPtr();
BlendPoint *geom2 = static_cast<BlendPointPy *>(b2)->getBlendPointPtr();
@@ -94,7 +74,7 @@ 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;
}

View File

@@ -45,7 +45,7 @@ BlendPoint::BlendPoint(std::vector<Base::Vector3d> vectorList)
BlendPoint::BlendPoint()
{
vectors.emplace_back(Base::Vector3d(0, 0, 0));
vectors.emplace_back(Base::Vector3d(0, 0, 0));
}
BlendPoint::~BlendPoint()

View File

@@ -40,7 +40,7 @@
<Documentation>
<UserDocu>
Resizes the BlendPoint vectors,
by setting the lenght of the first derivative.
by setting the length of the first derivative.
theBlendPoint.setSize(new_size)
</UserDocu>
</Documentation>

View File

@@ -27,13 +27,14 @@
#include <TColgp_Array1OfPnt.hxx>
#include <TopoDS.hxx>
#endif
#include "Blending/BlendPoint.h"
#include "Blending/BlendPointPy.h"
#include <Base/GeometryPyCXX.h>
#include <Base/VectorPy.h>
#include <Mod/Part/App/TopoShapePy.h>
#include "Blending/BlendPoint.h"
#include "Blending/BlendPointPy.h"
#include "Blending/BlendPointPy.cpp"
using namespace Surface;
std::string BlendPointPy::representation(void) const
@@ -51,7 +52,7 @@ PyObject *BlendPointPy::PyMake(struct _typeobject *, PyObject *, PyObject *)// P
return new BlendPointPy(new BlendPoint);
}
int BlendPointPy::PyInit(PyObject* args, PyObject*)
int BlendPointPy::PyInit(PyObject *args, PyObject *)
{
PyObject *plist;
std::vector<Base::Vector3d> vecs;
@@ -89,6 +90,11 @@ int BlendPointPy::PyInit(PyObject* args, PyObject*)
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");
Base::Console().Message("fp=%f\n", adapt.FirstParameter());
Base::Console().Message("lp=%f\n", adapt.LastParameter());
}
adapt.D0(param, Pt);
Base::Vector3d bv(Pt.X(), Pt.Y(), Pt.Z());

View File

@@ -0,0 +1,74 @@
/***************************************************************************
* Copyright (c) 2014 Matteo Grellier <matteogrellier@gmail.com> *
* *
* This file is part of the FreeCAD CAx development system. *
* *
* This library is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Library General Public *
* License as published by the Free Software Foundation; either *
* version 2 of the License, or (at your option) any later version. *
* *
* This library is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU Library General Public License for more details. *
* *
* You should have received a copy of the GNU Library General Public *
* License along with this library; see the file COPYING.LIB. If not, *
* write to the Free Software Foundation, Inc., 59 Temple Place, *
* Suite 330, Boston, MA 02111-1307, USA *
* *
***************************************************************************/
#ifndef FEATURE_BLEND_CURVE_H
#define FEATURE_BLEND_CURVE_H
#include <App/PropertyLinks.h>
#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>
namespace Surface
{
class SurfaceExport FeatureBlendCurve: public Part::Spline
{
PROPERTY_HEADER_WITH_OVERRIDE(Surface::FeatureBlendCurve);
public:
FeatureBlendCurve();
App::PropertyLinkSub StartEdge;
App::PropertyFloatConstraint StartParameter;
App::PropertyIntegerConstraint StartContinuity;
App::PropertyFloat StartSize;
App::PropertyLinkSub EndEdge;
App::PropertyFloatConstraint EndParameter;
App::PropertyIntegerConstraint EndContinuity;
App::PropertyFloat EndSize;
Standard_Integer maxDegree;
App::DocumentObjectExecReturn *execute(void) override;
short mustExecute() const override;
const char *getViewProviderName(void) const override
{
return "SurfaceGui::ViewProviderBlendCurve";
}
private:
BlendPoint GetBlendPoint(App::PropertyLinkSub &link, App::PropertyFloatConstraint &param, App::PropertyIntegerConstraint &Continuity);
double RelativeToRealParameters(double, double, double);
bool lockOnChangeMutex;
protected:
virtual void onChanged(const App::Property *prop) override;
};
}//Namespace Surface
#endif

View File

@@ -1,19 +1,50 @@
if(MSVC)
add_definitions(-DHAVE_ACOSH -DHAVE_ASINH -DHAVE_ATANH)
add_definitions(-DHAVE_ACOSH -DHAVE_ASINH -DHAVE_ATANH)
else(MSVC)
add_definitions(-DHAVE_LIMITS_H -DHAVE_CONFIG_H)
add_definitions(-DHAVE_LIMITS_H -DHAVE_CONFIG_H)
endif(MSVC)
include_directories(
${Boost_INCLUDE_DIRS}
${OCC_INCLUDE_DIR}
${PYTHON_INCLUDE_DIRS}
${ZLIB_INCLUDE_DIR}
${CMAKE_BINARY_DIR}
${CMAKE_BINARY_DIR}/src
${CMAKE_SOURCE_DIR}/src
${CMAKE_CURRENT_BINARY_DIR}
${CMAKE_CURRENT_SOURCE_DIR}
${Boost_INCLUDE_DIRS}
${OCC_INCLUDE_DIR}
${PYTHON_INCLUDE_DIRS}
${ZLIB_INCLUDE_DIR}
${FREETYPE_INCLUDE_DIRS}
)
link_directories(${OCC_LIBRARY_DIR})
file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/Blending)
generate_from_xml(Blending/BlendPointPy)
generate_from_xml(Blending/BlendCurvePy)
set(Surface_LIBS
FreeCADApp
Part
FreeCADApp
Part
)
# BlendPoint Wrapper
SET(BlendingPy_SRCS
Blending/BlendPointPy.xml
Blending/BlendPointPyImp.cpp
Blending/BlendCurvePy.xml
Blending/BlendCurvePyImp.cpp
)
SOURCE_GROUP("Blending" FILES ${BlendingPy_SRCS})
SET(Blending_SRCS
Blending/FeatureBlendCurve.cpp
Blending/FeatureBlendCurve.h
Blending/BlendPoint.cpp
Blending/BlendPoint.h
Blending/BlendCurve.cpp
Blending/BlendCurve.h
)
SET(BlendingPy_SRCS
@@ -34,21 +65,23 @@ SET(Blending_SRCS
)
SET(Surface_SRCS
AppSurface.cpp
PreCompiled.cpp
PreCompiled.h
FeatureExtend.cpp
FeatureExtend.h
FeatureGeomFillSurface.cpp
FeatureGeomFillSurface.h
FeatureFilling.cpp
FeatureFilling.h
FeatureSections.cpp
FeatureSections.h
FeatureSewing.cpp
FeatureSewing.h
FeatureCut.cpp
FeatureCut.h
${Blending_SRCS}
${BlendingPy_SRCS}
AppSurface.cpp
PreCompiled.cpp
PreCompiled.h
FeatureExtend.cpp
FeatureExtend.h
FeatureGeomFillSurface.cpp
FeatureGeomFillSurface.h
FeatureFilling.cpp
FeatureFilling.h
FeatureSections.cpp
FeatureSections.h
FeatureSewing.cpp
FeatureSewing.h
FeatureCut.cpp
FeatureCut.h
)
link_directories(${OCC_LIBRARY_DIR})