From 287b0a2510b04716f9819339ae46b0bd2d0567de Mon Sep 17 00:00:00 2001 From: Jookia Date: Tue, 25 Jun 2024 04:16:51 +1000 Subject: [PATCH 1/4] Remove support for Boost.Python --- src/Mod/CAM/libarea/CMakeLists.txt | 46 +- src/Mod/CAM/libarea/PythonStuff.cpp | 578 ------------------ src/Mod/CAM/libarea/PythonStuff.h | 9 - src/Mod/MeshPart/App/CMakeLists.txt | 80 +-- .../App/MeshFlatteningBoostPython.cpp | 261 -------- 5 files changed, 20 insertions(+), 954 deletions(-) delete mode 100644 src/Mod/CAM/libarea/PythonStuff.h delete mode 100644 src/Mod/MeshPart/App/MeshFlatteningBoostPython.cpp diff --git a/src/Mod/CAM/libarea/CMakeLists.txt b/src/Mod/CAM/libarea/CMakeLists.txt index 2dd9f3e0ec..8ec30b5cff 100644 --- a/src/Mod/CAM/libarea/CMakeLists.txt +++ b/src/Mod/CAM/libarea/CMakeLists.txt @@ -23,39 +23,7 @@ include_directories( link_directories(${OCC_LIBRARY_DIR}) -if(NOT FREECAD_USE_PYBIND11) - if(NOT FREECAD_LIBPACK_USE OR FREECAD_LIBPACK_CHECKFILE_CLBUNDLER OR FREECAD_LIBPACK_CHECKFILE_VERSION) - # boost-python >= 1.67 on some platforms has suffix - if (FORCE_BOOST_PY_SUFFIX) - set(BOOST_PY_SUFFIX ${FORCE_BOOST_PY_SUFFIX}) - else () - set(BOOST_PY_SUFFIX ${Python3_VERSION_MAJOR}${Python3_VERSION_MINOR}) - endif () - - find_package( Boost COMPONENTS python${BOOST_PY_SUFFIX} ) - if (NOT Boost_PYTHON${BOOST_PY_SUFFIX}_FOUND) - # try just the major version - find_package( Boost COMPONENTS python${Python3_VERSION_MAJOR} ) - if (NOT Boost_PYTHON${Python3_VERSION_MAJOR}_FOUND) - # unversioned - find_package( Boost COMPONENTS python REQUIRED) - endif() - endif() - - if(Boost_FOUND) - include_directories(SYSTEM ${Boost_INCLUDE_DIRS}) - MESSAGE(STATUS "found Boost: " ${Boost_LIB_VERSION}) - MESSAGE(STATUS "boost-incude dirs are: " ${Boost_INCLUDE_DIRS}) - MESSAGE(STATUS "boost-python lib is: " ${Boost_PYTHON_LIBRARY}) - MESSAGE(STATUS "boost_LIBRARY_DIRS is: " ${Boost_LIBRARY_DIRS}) - MESSAGE(STATUS "Boost_LIBRARIES is: " ${Boost_LIBRARIES}) - endif() - else() - include_directories(SYSTEM ${Boost_INCLUDE_DIRS}) - endif() -else() - include_directories(SYSTEM ${pybind11_INCLUDE_DIR}) -endif(NOT FREECAD_USE_PYBIND11) +include_directories(${pybind11_INCLUDE_DIR}) # this defines the source-files for library @@ -81,15 +49,9 @@ set(AREA_SRC_CLIPPER ) # this defines the additional source-files for python module (wrapper to libarea) -if (NOT FREECAD_USE_PYBIND11) - set(PYAREA_SRC - PythonStuff.cpp - ) -else (NOT FREECAD_USE_PYBIND11) - set(PYAREA_SRC - pyarea.cpp - ) -endif (NOT FREECAD_USE_PYBIND11) +set(PYAREA_SRC + pyarea.cpp +) # this defines the headers if(DEFINED INCLUDE_INSTALL_DIR) diff --git a/src/Mod/CAM/libarea/PythonStuff.cpp b/src/Mod/CAM/libarea/PythonStuff.cpp index f98292de05..e69de29bb2 100644 --- a/src/Mod/CAM/libarea/PythonStuff.cpp +++ b/src/Mod/CAM/libarea/PythonStuff.cpp @@ -1,578 +0,0 @@ -// PythonStuff.cpp -// Copyright 2011, Dan Heeks -// This program is released under the BSD license. See the file COPYING for details. - -#include "PythonStuff.h" - -#include "Area.h" -#include "Point.h" -#include "AreaDxf.h" -#include "kurve/geometry.h" -#include "Adaptive.hpp" - -#if defined(_POSIX_C_SOURCE) -#undef _POSIX_C_SOURCE -#endif - -#if defined(_XOPEN_SOURCE) -#undef _XOPEN_SOURCE -#endif - -#if _DEBUG -#undef _DEBUG -#include -#define _DEBUG -#else -#include -#endif - -#if defined(__GNUG__) && !defined(__clang__) -#pragma implementation -#endif - -#define BOOST_BIND_GLOBAL_PLACEHOLDERS - -#include -#include -#include -#include -#include -#include - - -#include "clipper.hpp" -using namespace ClipperLib; - - -namespace bp = boost::python; - -boost::python::list getVertices(const CCurve& curve) -{ - boost::python::list vlist; - BOOST_FOREACH (const CVertex& vertex, curve.m_vertices) { - vlist.append(vertex); - } - return vlist; -} - -boost::python::list getCurves(const CArea& area) -{ - boost::python::list clist; - BOOST_FOREACH (const CCurve& curve, area.m_curves) { - clist.append(curve); - } - return clist; -} - -boost::python::tuple -transformed_point(const geoff_geometry::Matrix& matrix, double x, double y, double z) -{ - geoff_geometry::Point3d p(x, y, z); - p = p.Transform(matrix); - - return bp::make_tuple(p.x, p.y, p.z); -} - -static void print_curve(const CCurve& c) -{ - std::size_t nvertices = c.m_vertices.size(); -#if defined SIZEOF_SIZE_T && SIZEOF_SIZE_T == 4 - printf("number of vertices = %d\n", nvertices); -#elif defined(_WIN32) - printf("number of vertices = %Iu\n", nvertices); -#else - printf("number of vertices = %lu\n", nvertices); -#endif - int i = 0; - for (std::list::const_iterator It = c.m_vertices.begin(); It != c.m_vertices.end(); - It++, i++) { - const CVertex& vertex = *It; - printf("vertex %d type = %d, x = %g, y = %g", - i + 1, - vertex.m_type, - vertex.m_p.x / CArea::get_units(), - vertex.m_p.y / CArea::get_units()); - if (vertex.m_type) { - printf(", xc = %g, yc = %g", - vertex.m_c.x / CArea::get_units(), - vertex.m_c.y / CArea::get_units()); - } - printf("\n"); - } -} - -static void print_area(const CArea& a) -{ - for (std::list::const_iterator It = a.m_curves.begin(); It != a.m_curves.end(); It++) { - const CCurve& curve = *It; - print_curve(curve); - } -} - -static unsigned int num_vertices(const CCurve& curve) -{ - return static_cast(curve.m_vertices.size()); -} - -static CVertex FirstVertex(const CCurve& curve) -{ - return curve.m_vertices.front(); -} - -static CVertex LastVertex(const CCurve& curve) -{ - return curve.m_vertices.back(); -} - -static void set_units(double units) -{ - CArea::set_units(units); -} - -static double get_units() -{ - return CArea::get_units(); -} - -static bool holes_linked() -{ - return CArea::HolesLinked(); -} - -static CArea AreaFromDxf(const char* filepath) -{ - CArea area; - AreaDxfRead dxf(&area, filepath); - dxf.DoRead(); - return area; -} - -static void append_point(CCurve& c, const Point& p) -{ - c.m_vertices.emplace_back(p); -} - -static boost::python::tuple nearest_point_to_curve(CCurve& c1, const CCurve& c2) -{ - double dist; - Point p = c1.NearestPoint(c2, &dist); - - return bp::make_tuple(p, dist); -} - -boost::python::list MakePocketToolpath(const CArea& a, - double tool_radius, - double extra_offset, - double stepover, - bool from_center, - bool use_zig_zag, - double zig_angle) -{ - std::list toolpath; - - CAreaPocketParams params(tool_radius, - extra_offset, - stepover, - from_center, - use_zig_zag ? ZigZagPocketMode : SpiralPocketMode, - zig_angle); - a.SplitAndMakePocketToolpath(toolpath, params); - - boost::python::list clist; - BOOST_FOREACH (const CCurve& c, toolpath) { - clist.append(c); - } - return clist; -} - -boost::python::list SplitArea(const CArea& a) -{ - std::list areas; - a.Split(areas); - - boost::python::list alist; - BOOST_FOREACH (const CArea& a, areas) { - alist.append(a); - } - return alist; -} - -void dxfArea(CArea& area, const char* /*str*/) -{ - area = CArea(); -} - -boost::python::list getCurveSpans(const CCurve& c) -{ - boost::python::list span_list; - const Point* prev_p = NULL; - - for (std::list::const_iterator VIt = c.m_vertices.begin(); VIt != c.m_vertices.end(); - VIt++) { - const CVertex& vertex = *VIt; - - if (prev_p) { - span_list.append(Span(*prev_p, vertex)); - } - prev_p = &(vertex.m_p); - } - - return span_list; -} - -Span getFirstCurveSpan(const CCurve& c) -{ - if (c.m_vertices.size() < 2) { - return Span(); - } - - std::list::const_iterator VIt = c.m_vertices.begin(); - const Point& p = (*VIt).m_p; - VIt++; - return Span(p, *VIt, true); -} - -Span getLastCurveSpan(const CCurve& c) -{ - if (c.m_vertices.size() < 2) { - return Span(); - } - - std::list::const_reverse_iterator VIt = c.m_vertices.rbegin(); - const CVertex& v = (*VIt); - VIt++; - - return Span((*VIt).m_p, v, c.m_vertices.size() == 2); -} - -bp::tuple TangentialArc(const Point& p0, const Point& p1, const Point& v0) -{ - Point c; - int dir; - tangential_arc(p0, p1, v0, c, dir); - - return bp::make_tuple(c, dir); -} - -boost::python::list spanIntersect(const Span& span1, const Span& span2) -{ - boost::python::list plist; - std::list pts; - span1.Intersect(span2, pts); - BOOST_FOREACH (const Point& p, pts) { - plist.append(p); - } - return plist; -} - -// Matrix(boost::python::list &l){} -std::shared_ptr matrix_constructor(const boost::python::list& lst) -{ - double m[16] = {1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1}; - - boost::python::ssize_t n = boost::python::len(lst); - int j = 0; - for (boost::python::ssize_t i = 0; i < n; i++) { - boost::python::object elem = lst[i]; - m[j] = boost::python::extract(elem.attr("__float__")()); - j++; - if (j >= 16) { - break; - } - } - - return std::shared_ptr(new geoff_geometry::Matrix(m)); -} - -boost::python::list InsideCurves(const CArea& a, const CCurve& curve) -{ - boost::python::list plist; - - std::list curves_inside; - a.InsideCurves(curve, curves_inside); - BOOST_FOREACH (const CCurve& c, curves_inside) { - plist.append(c); - } - return plist; -} - -boost::python::list CurveIntersections(const CCurve& c1, const CCurve& c2) -{ - boost::python::list plist; - - std::list pts; - c1.CurveIntersections(c2, pts); - BOOST_FOREACH (const Point& p, pts) { - plist.append(p); - } - return plist; -} - -boost::python::list AreaIntersections(const CArea& a, const CCurve& c2) -{ - boost::python::list plist; - - std::list pts; - a.CurveIntersections(c2, pts); - BOOST_FOREACH (const Point& p, pts) { - plist.append(p); - } - return plist; -} - -double AreaGetArea(const CArea& a) -{ - return a.GetArea(); -} - - -// Adaptive2d.Execute wrapper -bp::list AdaptiveExecute(AdaptivePath::Adaptive2d& ada, - const boost::python::list& stock_paths, - const boost::python::list& in_paths, - boost::python::object progressCallbackFn) -{ - bp::list out_list; - - // convert stock paths - AdaptivePath::DPaths stock_dpaths; - for (bp::ssize_t i = 0; i < bp::len(stock_paths); i++) { - bp::list in_path = bp::extract(stock_paths[i]); - AdaptivePath::DPath dpath; - for (bp::ssize_t j = 0; j < bp::len(in_path); j++) { - bp::list in_point = bp::extract(in_path[j]); - dpath.push_back(pair(bp::extract(in_point[0]), - bp::extract(in_point[1]))); - } - stock_dpaths.push_back(dpath); - } - - // convert inputs - AdaptivePath::DPaths dpaths; - for (bp::ssize_t i = 0; i < bp::len(in_paths); i++) { - bp::list in_path = bp::extract(in_paths[i]); - AdaptivePath::DPath dpath; - for (bp::ssize_t j = 0; j < bp::len(in_path); j++) { - bp::list in_point = bp::extract(in_path[j]); - dpath.push_back(pair(bp::extract(in_point[0]), - bp::extract(in_point[1]))); - } - dpaths.push_back(dpath); - } - // Execute with callback - std::list result = - ada.Execute(stock_dpaths, dpaths, [progressCallbackFn](AdaptivePath::TPaths tp) -> bool { - bp::list out_paths; - for (const auto& in_pair : tp) { - bp::list path; - for (const auto& in_pt : in_pair.second) { - path.append(bp::make_tuple(in_pt.first, in_pt.second)); - } - out_paths.append(bp::make_tuple(in_pair.first, path)); - } - return bp::extract(progressCallbackFn(out_paths)); - }); - // convert outputs back - BOOST_FOREACH (const auto& res, result) { - out_list.append(res); - } - return out_list; -} - -// Converts a std::pair instance to a Python tuple. -template -struct std_pair_to_tuple -{ - static PyObject* convert(std::pair const& p) - { - return boost::python::incref(boost::python::make_tuple(p.first, p.second).ptr()); - } - static PyTypeObject const* get_pytype() - { - return &PyTuple_Type; - } -}; - -boost::python::list AdaptiveOutput_AdaptivePaths(const AdaptivePath::AdaptiveOutput& ado) -{ - bp::list olist; - for (auto& ap : ado.AdaptivePaths) { - bp::list op; - for (auto& pt : ap.second) { - op.append(bp::make_tuple(pt.first, pt.second)); - } - olist.append(bp::make_tuple(ap.first, op)); - } - return olist; -} - - -BOOST_PYTHON_MODULE(area) -{ - bp::class_("Point") - .def(bp::init()) - .def(bp::init()) - .def(bp::other() * bp::self) - .def(bp::self * bp::other()) - .def(bp::self / bp::other()) - .def(bp::self * bp::other()) - .def(bp::self - bp::other()) - .def(bp::self + bp::other()) - .def(bp::self ^ bp::other()) - .def(bp::self == bp::other()) - .def(bp::self != bp::other()) - .def(-bp::self) - .def(~bp::self) - .def("dist", &Point::dist) - .def("length", &Point::length) - .def("normalize", &Point::normalize) - .def("Rotate", static_cast(&Point::Rotate)) - .def("Rotate", static_cast(&Point::Rotate)) - .def_readwrite("x", &Point::x) - .def_readwrite("y", &Point::y) - .def("Transform", &Point::Transform); - - bp::class_("Vertex") - .def(bp::init()) - .def(bp::init()) - .def(bp::init()) - .def(bp::init()) - .def_readwrite("type", &CVertex::m_type) - .def_readwrite("p", &CVertex::m_p) - .def_readwrite("c", &CVertex::m_c) - .def_readwrite("user_data", &CVertex::m_user_data); - - bp::class_("Span") - .def(bp::init()) - .def(bp::init()) - .def("NearestPoint", - static_cast(&Span::NearestPoint)) - .def("NearestPoint", - static_cast(&Span::NearestPoint)) - .def("GetBox", &Span::GetBox) - .def("IncludedAngle", &Span::IncludedAngle) - .def("GetArea", &Span::GetArea) - .def("On", &Span::On) - .def("MidPerim", &Span::MidPerim) - .def("MidParam", &Span::MidParam) - .def("Length", &Span::Length) - .def("GetVector", &Span::GetVector) - .def("Intersect", &spanIntersect) - .def_readwrite("p", &Span::m_p) - .def_readwrite("v", &Span::m_v); - - bp::class_("Curve") - .def(bp::init()) - .def("getVertices", &getVertices) - .def("append", &CCurve::append) - .def("append", &append_point) - .def("text", &print_curve) - .def("NearestPoint", - static_cast(&CCurve::NearestPoint)) - .def("NearestPoint", &nearest_point_to_curve) - .def("Reverse", &CCurve::Reverse) - .def("getNumVertices", &num_vertices) - .def("FirstVertex", &FirstVertex) - .def("LastVertex", &LastVertex) - .def("GetArea", &CCurve::GetArea) - .def("IsClockwise", &CCurve::IsClockwise) - .def("IsClosed", &CCurve::IsClosed) - .def("ChangeStart", &CCurve::ChangeStart) - .def("ChangeEnd", &CCurve::ChangeEnd) - .def("Offset", &CCurve::Offset) - .def("OffsetForward", &CCurve::OffsetForward) - .def("GetSpans", &getCurveSpans) - .def("GetFirstSpan", &getFirstCurveSpan) - .def("GetLastSpan", &getLastCurveSpan) - .def("Break", &CCurve::Break) - .def("Perim", &CCurve::Perim) - .def("PerimToPoint", &CCurve::PerimToPoint) - .def("PointToPerim", &CCurve::PointToPerim) - .def("FitArcs", &CCurve::FitArcs) - .def("UnFitArcs", &CCurve::UnFitArcs) - .def("Intersections", &CurveIntersections); - - bp::class_("Box") - .def(bp::init()) - .def("MinX", &CBox2D::MinX) - .def("MaxX", &CBox2D::MaxX) - .def("MinY", &CBox2D::MinY) - .def("MaxY", &CBox2D::MaxY); - - bp::class_("Area") - .def(bp::init()) - .def("getCurves", &getCurves) - .def("append", &CArea::append) - .def("Subtract", &CArea::Subtract) - .def("Intersect", &CArea::Intersect) - .def("Union", &CArea::Union) - .def("Offset", &CArea::Offset) - .def("FitArcs", &CArea::FitArcs) - .def("text", &print_area) - .def("num_curves", &CArea::num_curves) - .def("NearestPoint", &CArea::NearestPoint) - .def("GetBox", &CArea::GetBox) - .def("Reorder", &CArea::Reorder) - .def("MakePocketToolpath", &MakePocketToolpath) - .def("Split", &SplitArea) - .def("InsideCurves", &InsideCurves) - .def("Thicken", &CArea::Thicken) - .def("Intersections", &AreaIntersections) - .def("GetArea", &AreaGetArea); - - bp::class_>("Matrix") - .def(bp::init()) - .def("__init__", bp::make_constructor(&matrix_constructor)) - .def("TransformedPoint", &transformed_point) - .def("Multiply", &geoff_geometry::Matrix::Multiply); - - bp::def("set_units", set_units); - bp::def("get_units", get_units); - bp::def("holes_linked", holes_linked); - bp::def("AreaFromDxf", AreaFromDxf); - bp::def("TangentialArc", TangentialArc); - - - using namespace AdaptivePath; - - boost::python:: - to_python_converter, std_pair_to_tuple, true>(); - - - bp::enum_("AdaptiveMotionType") - .value("Cutting", MotionType::mtCutting) - .value("LinkClear", MotionType::mtLinkClear) - .value("LinkNotClear", MotionType::mtLinkNotClear) - .value("LinkClearAtPrevPass", MotionType::mtLinkClearAtPrevPass); - - bp::enum_("AdaptiveOperationType") - .value("ClearingInside", OperationType::otClearingInside) - .value("ClearingOutside", OperationType::otClearingOutside) - .value("ProfilingInside", OperationType::otProfilingInside) - .value("ProfilingOutside", OperationType::otProfilingOutside); - - bp::class_("AdaptiveOutput") - .def(bp::init<>()) - .add_property("HelixCenterPoint", - bp::make_getter(&AdaptiveOutput::HelixCenterPoint, - bp::return_value_policy())) - .add_property("StartPoint", - bp::make_getter(&AdaptiveOutput::StartPoint, - bp::return_value_policy())) - .add_property("AdaptivePaths", &AdaptiveOutput_AdaptivePaths) - .def_readonly("ReturnMotionType", &AdaptiveOutput::ReturnMotionType); - - bp::class_("Adaptive2d") - .def(bp::init<>()) - .def("Execute", &AdaptiveExecute) - .def_readwrite("stepOverFactor", &Adaptive2d::stepOverFactor) - .def_readwrite("toolDiameter", &Adaptive2d::toolDiameter) - .def_readwrite("stockToLeave", &Adaptive2d::stockToLeave) - .def_readwrite("helixRampDiameter", &Adaptive2d::helixRampDiameter) - .def_readwrite("forceInsideOut", &Adaptive2d::forceInsideOut) - .def_readwrite("finishingProfile", &Adaptive2d::finishingProfile) - //.def_readwrite("polyTreeNestingLimit", &Adaptive2d::polyTreeNestingLimit) - .def_readwrite("tolerance", &Adaptive2d::tolerance) - .def_readwrite("keepToolDownDistRatio", &Adaptive2d::keepToolDownDistRatio) - .def_readwrite("opType", &Adaptive2d::opType); -} diff --git a/src/Mod/CAM/libarea/PythonStuff.h b/src/Mod/CAM/libarea/PythonStuff.h deleted file mode 100644 index 5d6e3c3cd4..0000000000 --- a/src/Mod/CAM/libarea/PythonStuff.h +++ /dev/null @@ -1,9 +0,0 @@ -// PythonStuff.h - -// Copyright 2011, Dan Heeks -// This program is released under the BSD license. See the file COPYING for details. - -extern void Message(const char*); - -void PythonInit(); -void PythonFinish(); diff --git a/src/Mod/MeshPart/App/CMakeLists.txt b/src/Mod/MeshPart/App/CMakeLists.txt index 8d52ddbafb..92179592a3 100644 --- a/src/Mod/MeshPart/App/CMakeLists.txt +++ b/src/Mod/MeshPart/App/CMakeLists.txt @@ -99,71 +99,23 @@ INSTALL(TARGETS MeshPart DESTINATION ${CMAKE_INSTALL_LIBDIR}) ################################ flat mesh ############################### -if (BUILD_FLAT_MESH) - if (FREECAD_USE_PYBIND11) - SET(FLATMESH_SRCS - MeshFlattening.cpp - MeshFlattening.h - MeshFlatteningNurbs.h - MeshFlatteningNurbs.cpp - MeshFlatteningLscmRelax.h - MeshFlatteningLscmRelax.cpp - MeshFlatteningPy.cpp - ) +if (BUILD_FLAT_MESH AND FREECAD_USE_PYBIND11) + SET(FLATMESH_SRCS + MeshFlattening.cpp + MeshFlattening.h + MeshFlatteningNurbs.h + MeshFlatteningNurbs.cpp + MeshFlatteningLscmRelax.h + MeshFlatteningLscmRelax.cpp + MeshFlatteningPy.cpp + ) - add_library(flatmesh SHARED ${FLATMESH_SRCS}) - SET_PYTHON_PREFIX_SUFFIX(flatmesh) - target_link_libraries(flatmesh ${Python3_LIBRARIES} ${MeshPart_LIBS}) + add_library(flatmesh SHARED ${FLATMESH_SRCS}) + SET_PYTHON_PREFIX_SUFFIX(flatmesh) + target_link_libraries(flatmesh ${Python3_LIBRARIES} ${MeshPart_LIBS}) - SET_BIN_DIR(flatmesh flatmesh /Mod/MeshPart) - install(TARGETS flatmesh DESTINATION ${CMAKE_INSTALL_LIBDIR}) - else() - if(NOT FREECAD_LIBPACK_USE OR FREECAD_LIBPACK_CHECKFILE_CLBUNDLER OR - (FREECAD_LIBPACK_CHECKFILE_VERSION AND FREECAD_LIBPACK_VERSION VERSION_LESS "3.1.0")) - # boost-python >= 1.67 on some platforms has suffix - if (FORCE_BOOST_PY_SUFFIX) - set(BOOST_PY_SUFFIX ${FORCE_BOOST_PY_SUFFIX}) - else () - set(BOOST_PY_SUFFIX ${Python3_VERSION_MAJOR}${Python3_VERSION_MINOR}) - endif () - - find_package( Boost COMPONENTS python${BOOST_PY_SUFFIX} ) - if (NOT Boost_PYTHON${BOOST_PY_SUFFIX}_FOUND) - # try just the major version - find_package( Boost COMPONENTS python${Python3_VERSION_MAJOR} ) - if (NOT Boost_PYTHON${Python3_VERSION_MAJOR}_FOUND) - # unversioned - find_package( Boost COMPONENTS python REQUIRED) - endif() - endif() - - if(Boost_FOUND) - include_directories(SYSTEM ${Boost_INCLUDE_DIRS}) - SET(FLATMESH_SRCS - MeshFlattening.cpp - MeshFlattening.h - MeshFlatteningNurbs.h - MeshFlatteningNurbs.cpp - MeshFlatteningLscmRelax.h - MeshFlatteningLscmRelax.cpp - MeshFlatteningBoostPython.cpp - ) - - - add_library(flatmesh SHARED ${FLATMESH_SRCS}) - SET_PYTHON_PREFIX_SUFFIX(flatmesh) - - if (BUILD_DYNAMIC_LINK_PYTHON) - target_link_libraries(flatmesh ${Python3_LIBRARIES}) - endif(BUILD_DYNAMIC_LINK_PYTHON) - - target_link_libraries(flatmesh ${MeshPart_LIBS} ${Boost_LIBRARIES}) - - SET_BIN_DIR(flatmesh flatmesh /Mod/MeshPart) - install(TARGETS flatmesh DESTINATION ${CMAKE_INSTALL_LIBDIR}) - endif() - endif() - endif() -endif(BUILD_FLAT_MESH) + SET_BIN_DIR(flatmesh flatmesh /Mod/MeshPart) + install(TARGETS flatmesh DESTINATION ${CMAKE_INSTALL_LIBDIR}) +endif(BUILD_FLAT_MESH AND FREECAD_USE_PYBIND11) ############################################################################ diff --git a/src/Mod/MeshPart/App/MeshFlatteningBoostPython.cpp b/src/Mod/MeshPart/App/MeshFlatteningBoostPython.cpp deleted file mode 100644 index 879096235b..0000000000 --- a/src/Mod/MeshPart/App/MeshFlatteningBoostPython.cpp +++ /dev/null @@ -1,261 +0,0 @@ -/*************************************************************************** - * Copyright (c) 2017 Lorenz Lechner * - * * - * 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 * - * * - ***************************************************************************/ - -#include "PreCompiled.h" -#ifndef _PreComp_ -#include -#include -#include -#include -#include -#include -#include -#endif - -// boost is purposely not in the precompiled headers, see -// https://github.com/FreeCAD/FreeCAD/pull/7979#issuecomment-1358123252 -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "MeshFlattening.h" -#include "MeshFlatteningLscmRelax.h" -#include "MeshFlatteningNurbs.h" - - -// clang-format off -namespace py = boost::python; - -const TopoDS_Face& getTopoDSFace(const py::object& face) -{ - if (PyObject_TypeCheck(face.ptr(), &(Part::TopoShapeFacePy::Type))) - { - const Part::TopoShapeFacePy* fpy = static_cast(face.ptr()); - const TopoDS_Face& myFace = TopoDS::Face(fpy->getTopoShapePtr()->getShape()); - return myFace; - } - - throw std::invalid_argument("must be a face"); -} - -const TopoDS_Edge& getTopoDSEdge(py::object* edge) -{ - if (PyObject_TypeCheck(edge->ptr(), &(Part::TopoShapeEdgePy::Type))) - { - const Part::TopoShapeEdgePy* epy = static_cast(edge->ptr()); - const TopoDS_Edge& myEdge = TopoDS::Edge(epy->getTopoShapePtr()->getShape()); - return myEdge; - } - - throw std::invalid_argument("must be an edge"); -} - -Py::Object makeEdge(const TopoDS_Edge& edge) -{ - return Py::asObject(new Part::TopoShapeEdgePy(new Part::TopoShape(edge))); -} - -std::shared_ptr FaceUnwrapper_face(const py::object& face) -{ - const TopoDS_Face& myFace = getTopoDSFace(face); - return std::make_shared(myFace); -} - -std::shared_ptr FaceUnwrapper_mesh(const py::object& points, - const py::object& facets) -{ - try { - Py::Sequence l1(points.ptr()); - ColMat coords; - coords.resize(l1.size(), 3); - int row = 0; - for (Py::Sequence::iterator it = l1.begin(); it != l1.end(); ++it, ++row) { - Py::Sequence c(*it); - int col = 0; - for (Py::Sequence::iterator jt = c.begin(); jt != c.end(); ++jt, ++col) { - double v = static_cast(Py::Float(*jt)); - coords(row, col) = v; - } - } - - Py::Sequence l2(facets.ptr()); - ColMat triangles; - triangles.resize(l2.size(), 3); - row = 0; - for (Py::Sequence::iterator it = l2.begin(); it != l2.end(); ++it, ++row) { - Py::Sequence c(*it); - int col = 0; - for (Py::Sequence::iterator jt = c.begin(); jt != c.end(); ++jt, ++col) { - long v = static_cast(Py::Long(*jt)); - triangles(row, col) = v; - } - } - - return std::shared_ptr(new FaceUnwrapper(coords, triangles)); - } - catch (const Py::Exception&) { - Base::PyException e; - throw std::invalid_argument(e.what()); - } -} - -boost::python::list interpolateFlatFacePy(FaceUnwrapper& instance, const py::object& face) -{ - const TopoDS_Face& myFace = getTopoDSFace(face); - ColMat mat = instance.interpolateFlatFace(myFace); - boost::python::list plist; - auto cols = mat.cols(); - auto rows = mat.rows(); - for (int i=0; i> mat_array = instance.getFlatBoundaryNodes(); - - boost::python::list ary; - for (auto& mat : mat_array) { - boost::python::list plist; - auto cols = mat.cols(); - auto rows = mat.rows(); - for (int i=0; i -struct eigen_matrix -{ - static PyObject* convert(const eigen_type& mat) - { - // - py::list ary; - for (int i = 0; i < mat.rows(); i++) { - py::list row; - for (int j = 0; j < mat.cols(); j++) { - row.append(mat.coeff(i ,j)); - } - ary.append(row); - } - return boost::python::incref(ary.ptr()); - } - static void to_python_converter() - { - py::to_python_converter>(); - } -}; -} // namespace fm - -BOOST_PYTHON_MODULE(flatmesh) -{ - py::class_("LscmRelax") - .def(py::init, ColMat, std::vector>()) - .def("lscm", &lscmrelax::LscmRelax::lscm) - .def("relax", &lscmrelax::LscmRelax::relax) - .def("rotate_by_min_bound_area", &lscmrelax::LscmRelax::rotate_by_min_bound_area) - .def("transform", &lscmrelax::LscmRelax::transform) - .def_readonly("rhs", &lscmrelax::LscmRelax::rhs) - .def_readonly("MATRIX", &lscmrelax::LscmRelax::MATRIX) - .def_readonly("area", &lscmrelax::LscmRelax::get_area) - .def_readonly("flat_area", &lscmrelax::LscmRelax::get_flat_area) - .def_readonly("flat_vertices_3D", &lscmrelax::LscmRelax::get_flat_vertices_3D); - - py::class_("NurbsBase2D") - .def(py::init()) - .def_readonly("u_knots", &nurbs::NurbsBase2D::u_knots) - .def_readonly("weights", &nurbs::NurbsBase2D::weights) - .def_readonly("degree_u", &nurbs::NurbsBase2D::degree_u) - .def_readonly("degree_v", &nurbs::NurbsBase2D::degree_u) - .def("getUVMesh", &nurbs::NurbsBase2D::getUVMesh) - .def("computeFirstDerivatives", &nurbs::NurbsBase2D::computeFirstDerivatives) - .def("getInfluenceVector", &nurbs::NurbsBase2D::getInfluenceVector) - .def("getInfluenceMatrix", &nurbs::NurbsBase2D::getInfluenceMatrix) - .def("getDuVector", &nurbs::NurbsBase2D::getDuVector) - .def("getDuMatrix", &nurbs::NurbsBase2D::getDuMatrix) - .def("getDvVector", &nurbs::NurbsBase2D::getDvVector) - .def("getDvMatrix", &nurbs::NurbsBase2D::getDvMatrix) - .def("interpolateUBS", &nurbs::NurbsBase2D::interpolateUBS); - - py::class_("NurbsBase1D") - .def(py::init()) - .def_readonly("u_knots", &nurbs::NurbsBase1D::u_knots) - .def_readonly("weights", &nurbs::NurbsBase1D::weights) - .def_readonly("degree_u", &nurbs::NurbsBase1D::degree_u) - .def("getUMesh", &nurbs::NurbsBase1D::getUMesh) - .def("computeFirstDerivatives", &nurbs::NurbsBase1D::computeFirstDerivatives) - .def("getInfluenceVector", &nurbs::NurbsBase1D::getInfluenceVector) - .def("getInfluenceMatrix", &nurbs::NurbsBase1D::getInfluenceMatrix) - .def("getDuVector", &nurbs::NurbsBase1D::getDuVector) - .def("getDuMatrix", &nurbs::NurbsBase1D::getDuMatrix) - .add_static_property("getKnotSequence", &nurbs::NurbsBase1D::getKnotSequence) - .add_static_property("getWeightList", &nurbs::NurbsBase1D::getWeightList); - - py::class_("FaceUnwrapper") - .def("__init__", py::make_constructor(&FaceUnwrapper_face)) - .def("__init__", py::make_constructor(&FaceUnwrapper_mesh)) - .def(py::init, ColMat>()) - .def("findFlatNodes", &FaceUnwrapper::findFlatNodes) - .def("interpolateFlatFace", &interpolateFlatFacePy) - .def("getFlatBoundaryNodes", &getFlatBoundaryNodesPy) - .add_property("tris", py::make_getter(&FaceUnwrapper::tris, py::return_value_policy())) - .add_property("nodes", py::make_getter(&FaceUnwrapper::xyz_nodes, py::return_value_policy())) - .add_property("uv_nodes", py::make_getter(&FaceUnwrapper::uv_nodes, py::return_value_policy())) - .add_property("ze_nodes", py::make_getter(&FaceUnwrapper::ze_nodes, py::return_value_policy())) - .add_property("ze_poles", py::make_getter(&FaceUnwrapper::ze_poles, py::return_value_policy())) - .add_property("A", py::make_getter(&FaceUnwrapper::A, py::return_value_policy())); - - fm::eigen_matrix::to_python_converter(); - fm::eigen_matrix>::to_python_converter(); - fm::eigen_matrix>::to_python_converter(); - fm::eigen_matrix>::to_python_converter(); - fm::eigen_matrix>::to_python_converter(); -} -// clang-format on From 1489015caf3a896b26feb082964ebc265455a896 Mon Sep 17 00:00:00 2001 From: Jookia Date: Fri, 5 Jul 2024 20:58:27 +1000 Subject: [PATCH 2/4] ci: Add python3-pybind11 to Ubuntu CI --- package/ubuntu/install-apt-packages.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package/ubuntu/install-apt-packages.sh b/package/ubuntu/install-apt-packages.sh index 9cf5f44e52..7e8a17b47a 100755 --- a/package/ubuntu/install-apt-packages.sh +++ b/package/ubuntu/install-apt-packages.sh @@ -15,7 +15,6 @@ packages=( libboost-graph-dev libboost-iostreams-dev libboost-program-options-dev - libboost-python-dev libboost-regex-dev libboost-serialization-dev libboost-thread-dev @@ -52,6 +51,7 @@ packages=( python3-packaging python3-pivy python3-ply + python3-pybind11 python3-pyside2.qtcore python3-pyside2.qtgui python3-pyside2.qtnetwork From c532683060284053439ea4cf39cd0768241c0640 Mon Sep 17 00:00:00 2001 From: wmayer Date: Fri, 15 Nov 2024 18:58:17 +0100 Subject: [PATCH 3/4] CMake: Remove FREECAD_USE_PYBIND11 as a build option --- cMake/FreeCAD_Helpers/InitializeFreeCADBuildOptions.cmake | 4 ++++ cMake/FreeCAD_Helpers/PrintFinalReport.cmake | 1 - cMake/FreeCAD_Helpers/SetupPybind11.cmake | 1 - src/Mod/MeshPart/App/CMakeLists.txt | 4 ++-- 4 files changed, 6 insertions(+), 4 deletions(-) diff --git a/cMake/FreeCAD_Helpers/InitializeFreeCADBuildOptions.cmake b/cMake/FreeCAD_Helpers/InitializeFreeCADBuildOptions.cmake index 6e8c8e42b0..bbe168eeed 100644 --- a/cMake/FreeCAD_Helpers/InitializeFreeCADBuildOptions.cmake +++ b/cMake/FreeCAD_Helpers/InitializeFreeCADBuildOptions.cmake @@ -201,6 +201,10 @@ macro(InitializeFreeCADBuildOptions) set(BUILD_SMESH OFF) endif() + if (BUILD_CAM OR BUILD_FLAT_MESH) + set(FREECAD_USE_PYBIND11 ON) + endif() + # force build directory to be different to source directory if (BUILD_FORCE_DIRECTORY) if(${CMAKE_SOURCE_DIR} STREQUAL ${CMAKE_BINARY_DIR}) diff --git a/cMake/FreeCAD_Helpers/PrintFinalReport.cmake b/cMake/FreeCAD_Helpers/PrintFinalReport.cmake index 14cf57bd89..25bb8e7b3a 100644 --- a/cMake/FreeCAD_Helpers/PrintFinalReport.cmake +++ b/cMake/FreeCAD_Helpers/PrintFinalReport.cmake @@ -87,7 +87,6 @@ macro(PrintFinalReport) value(Python3_EXECUTABLE) value(PYTHON_LIBRARY) value(FREECAD_CREATE_MAC_APP) - value(FREECAD_USE_PYBIND11) value(FREECAD_USE_EXTERNAL_KDL) value(FREECAD_USE_PYSIDE) value(FREECAD_USE_SHIBOKEN) diff --git a/cMake/FreeCAD_Helpers/SetupPybind11.cmake b/cMake/FreeCAD_Helpers/SetupPybind11.cmake index 7fc65dfe86..7c8a9880ec 100644 --- a/cMake/FreeCAD_Helpers/SetupPybind11.cmake +++ b/cMake/FreeCAD_Helpers/SetupPybind11.cmake @@ -2,7 +2,6 @@ macro(SetupPybind11) # -------------------------------- PyBind11 ----------------------------- # necessary for flat-mesh feature - option(FREECAD_USE_PYBIND11 "Use pybind11" OFF) if (FREECAD_USE_PYBIND11) find_package(pybind11 REQUIRED) endif() diff --git a/src/Mod/MeshPart/App/CMakeLists.txt b/src/Mod/MeshPart/App/CMakeLists.txt index 92179592a3..3d1d34da7f 100644 --- a/src/Mod/MeshPart/App/CMakeLists.txt +++ b/src/Mod/MeshPart/App/CMakeLists.txt @@ -99,7 +99,7 @@ INSTALL(TARGETS MeshPart DESTINATION ${CMAKE_INSTALL_LIBDIR}) ################################ flat mesh ############################### -if (BUILD_FLAT_MESH AND FREECAD_USE_PYBIND11) +if (BUILD_FLAT_MESH) SET(FLATMESH_SRCS MeshFlattening.cpp MeshFlattening.h @@ -117,5 +117,5 @@ if (BUILD_FLAT_MESH AND FREECAD_USE_PYBIND11) SET_BIN_DIR(flatmesh flatmesh /Mod/MeshPart) install(TARGETS flatmesh DESTINATION ${CMAKE_INSTALL_LIBDIR}) -endif(BUILD_FLAT_MESH AND FREECAD_USE_PYBIND11) +endif(BUILD_FLAT_MESH) ############################################################################ From 6e269b0f81aa49f2da30cecb1fb5d91b962c9213 Mon Sep 17 00:00:00 2001 From: Chris Hennes Date: Tue, 4 Mar 2025 19:26:18 -0600 Subject: [PATCH 4/4] CMake: If using Libpack, require at least v3.1 Previous versions did not include pybind11, but the error message from that failure is not terribly informative. This way the exact means of fixing the problem is provided in the message. --- cMake/UseLibPack3.cmake | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/cMake/UseLibPack3.cmake b/cMake/UseLibPack3.cmake index bce443a9ed..e1da9548dc 100644 --- a/cMake/UseLibPack3.cmake +++ b/cMake/UseLibPack3.cmake @@ -19,6 +19,9 @@ if(FREECAD_LIBPACK_VERSION VERSION_GREATER_EQUAL "3.1.0") find_package(pybind11 REQUIRED PATHS ${FREECAD_LIBPACK_DIR}/share/cmake/pybind11 NO_DEFAULT_PATH) message(STATUS "Found LibPack 3 pybind11 ${pybind11_VERSION}") set(FREECAD_USE_PYBIND11 ON) +else() + # We have completely removed support for boost-python and require pybind11, which requires LibPack 3.1 or later + message(FATAL_ERROR "FreeCAD now requires LibPack 3.1.0 or newer (you are using ${FREECAD_LIBPACK_VERSION}): please upgrade your LibPack") endif() find_package(XercesC REQUIRED PATHS ${FREECAD_LIBPACK_DIR}/cmake NO_DEFAULT_PATH) @@ -28,6 +31,7 @@ find_package(yaml-cpp REQUIRED PATHS ${FREECAD_LIBPACK_DIR}/lib/cmake NO_DEFAULT message(STATUS "Found LibPack 3 yaml-cpp ${yaml-cpp_VERSION}") find_package(Coin REQUIRED PATHS ${FREECAD_LIBPACK_DIR}/lib/cmake NO_DEFAULT_PATH) + message(STATUS "Found LibPack 3 Coin ${Coin_VERSION}") # For compatibility with the rest of the cMake scripts: set (COIN3D_FOUND TRUE)