diff --git a/src/Mod/Surface/App/AppSurface.cpp b/src/Mod/Surface/App/AppSurface.cpp index cf524efbdc..02349b5af6 100644 --- a/src/Mod/Surface/App/AppSurface.cpp +++ b/src/Mod/Surface/App/AppSurface.cpp @@ -26,7 +26,6 @@ #include #include "Blending/BlendCurvePy.h" -#include "Blending/BlendPoint.h" #include "Blending/BlendPointPy.h" #include "Blending/FeatureBlendCurve.h" #include "FeatureCut.h" @@ -65,8 +64,6 @@ PyObject *initModule() /* Python entry */ PyMOD_INIT_FUNC(Surface) { - - try { Base::Interpreter().runString("import Part"); } @@ -79,6 +76,7 @@ PyMOD_INIT_FUNC(Surface) 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(); @@ -87,8 +85,6 @@ PyMOD_INIT_FUNC(Surface) Surface::Extend ::init(); Surface::FeatureBlendCurve ::init(); Surface::Sections ::init(); - Surface::BlendPoint ::init(); - Surface::BlendCurve ::init(); PyMOD_Return(mod); } diff --git a/src/Mod/Surface/App/Blending/BlendCurve.cpp b/src/Mod/Surface/App/Blending/BlendCurve.cpp index 541cf7d545..b03a2a3061 100644 --- a/src/Mod/Surface/App/Blending/BlendCurve.cpp +++ b/src/Mod/Surface/App/Blending/BlendCurve.cpp @@ -26,7 +26,6 @@ #include #include #include -#include #include #include #include @@ -40,17 +39,13 @@ using namespace Surface; -BlendCurve::BlendCurve() -{ -} - -BlendCurve::BlendCurve(std::vector blendPointsList) +BlendCurve::BlendCurve(const std::vector& blendPointsList) { // Retrieve number of blendPoints and push them into blendPoints. size_t nb_pts = blendPointsList.size(); if (nb_pts > 2) { - throw Base::ValueError("Not implemented"); + throw Base::NotImplementedError("Not implemented"); } else if (nb_pts < 2) { throw Base::ValueError("Need two points for working"); @@ -58,10 +53,6 @@ BlendCurve::BlendCurve(std::vector blendPointsList) blendPoints = blendPointsList; } -BlendCurve::~BlendCurve() -{ -} - Handle(Geom_BezierCurve) BlendCurve::compute() { size_t nb_pts = blendPoints.size(); @@ -127,9 +118,8 @@ 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"); + catch (Standard_Failure &) { + PyErr_SetString(Base::PyExc_FC_CADKernelError, "Failed to compute bezier curve"); } return nullptr; } @@ -146,6 +136,6 @@ void BlendCurve::setSize(int i, double f, bool relative) blendPoints[i].setSize(size); } catch (Standard_Failure &e) { - PyErr_SetString(PyExc_Exception, e.GetMessageString()); + PyErr_SetString(Base::PyExc_FC_CADKernelError, e.GetMessageString()); } } diff --git a/src/Mod/Surface/App/Blending/BlendCurve.h b/src/Mod/Surface/App/Blending/BlendCurve.h index 4520d80dd1..b73c871e6e 100644 --- a/src/Mod/Surface/App/Blending/BlendCurve.h +++ b/src/Mod/Surface/App/Blending/BlendCurve.h @@ -20,12 +20,11 @@ * * ***************************************************************************/ -#ifndef BLEND_CURVE_H -#define BLEND_CURVE_H +#ifndef SURFACE_BLEND_CURVE_H +#define SURFACE_BLEND_CURVE_H #include #include -#include #include namespace Surface @@ -33,18 +32,18 @@ namespace Surface /*! * Create a BezierCurve interpolating a list of BlendPoints */ -class SurfaceExport BlendCurve: public Base::BaseClass +class SurfaceExport BlendCurve { public: std::vector blendPoints; - BlendCurve(); + BlendCurve() = default; /*! * Constructor *\param std::vector */ - BlendCurve(std::vector blendPointsList); - virtual ~BlendCurve(); + BlendCurve(const std::vector& blendPointsList); + ~BlendCurve() = default; /*! * Perform the interpolate algorithm *\return the BezierCurve @@ -57,8 +56,6 @@ public: *\param bool interpret new size relative to chordlength */ void setSize(int, double, bool); - - virtual PyObject *getPyObject(void); }; }// namespace Surface diff --git a/src/Mod/Surface/App/Blending/BlendCurvePy.xml b/src/Mod/Surface/App/Blending/BlendCurvePy.xml index 977eef9fef..a1938d25e6 100644 --- a/src/Mod/Surface/App/Blending/BlendCurvePy.xml +++ b/src/Mod/Surface/App/Blending/BlendCurvePy.xml @@ -1,7 +1,7 @@ -#include -#endif + #include "Blending/BlendCurvePy.h" -#include "Blending/BlendPointPy.h" #include "Blending/BlendCurvePy.cpp" +#include "Blending/BlendPointPy.h" #include #include using namespace Surface; -std::string BlendCurvePy::representation(void) const +std::string BlendCurvePy::representation() const { return "BlendCurve"; } @@ -48,26 +45,29 @@ int BlendCurvePy::PyInit(PyObject *args, PyObject * /*kwds*/) { PyObject *b1; PyObject *b2; - std::vector bpList; - if (PyArg_ParseTuple(args, "O!O!", &(Surface::BlendPointPy::Type), &b1, &(Surface::BlendPointPy::Type), &b2)) { - BlendPoint *geom1 = static_cast(b1)->getBlendPointPtr(); - BlendPoint *geom2 = static_cast(b2)->getBlendPointPtr(); - bpList.emplace_back(*geom1); - bpList.emplace_back(*geom2); - this->getBlendCurvePtr()->blendPoints = bpList; - return 0; - } - return -1; + if (!PyArg_ParseTuple(args, "O!O!", &(Surface::BlendPointPy::Type), &b1, &(Surface::BlendPointPy::Type), &b2)) + return -1; + + std::vector bpList; + BlendPoint *geom1 = static_cast(b1)->getBlendPointPtr(); + BlendPoint *geom2 = static_cast(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, "")) + return nullptr; + BlendCurve *bc = getBlendCurvePtr(); Handle(Geom_BezierCurve) gc = bc->compute(); return new Part::BezierCurvePy(new Part::GeomBezierCurve(gc)); } - PyObject *BlendCurvePy::setSize(PyObject *args) { int i; @@ -78,12 +78,12 @@ PyObject *BlendCurvePy::setSize(PyObject *args) } try { getBlendCurvePtr()->setSize(i, size, Base::asBoolean(relative)); + Py_Return; } catch (Standard_Failure &e) { - PyErr_SetString(PyExc_Exception, e.GetMessageString()); + PyErr_SetString(Base::PyExc_FC_CADKernelError, e.GetMessageString()); return nullptr; } - Py_Return; } PyObject *BlendCurvePy::getCustomAttributes(const char * /*attr*/) const diff --git a/src/Mod/Surface/App/Blending/BlendPoint.cpp b/src/Mod/Surface/App/Blending/BlendPoint.cpp index 1adebe02fe..62a4d7b128 100644 --- a/src/Mod/Surface/App/Blending/BlendPoint.cpp +++ b/src/Mod/Surface/App/Blending/BlendPoint.cpp @@ -23,12 +23,8 @@ #include "PreCompiled.h" #ifndef _PreComp_ -#include -#include #include -#include -#include -#include +#include #endif #include "Blending/BlendPoint.h" #include "Blending/BlendPointPy.h" @@ -36,11 +32,9 @@ using namespace Surface; -BlendPoint::BlendPoint(std::vector vectorList) +BlendPoint::BlendPoint(const std::vector& vectorList) + : vectors{vectorList} { - for (size_t i = 0; i < vectorList.size(); i++) { - vectors.emplace_back(vectorList[i]); - } } BlendPoint::BlendPoint() @@ -48,10 +42,6 @@ BlendPoint::BlendPoint() vectors.emplace_back(Base::Vector3d(0, 0, 0)); } -BlendPoint::~BlendPoint() -{ -} - void BlendPoint::multiply(double f) { for (int i = 0; i < nbVectors(); i++) { @@ -78,8 +68,3 @@ int BlendPoint::nbVectors() { return vectors.size(); } - -PyObject *BlendPoint::getPyObject(void) -{ - return new BlendPointPy(new BlendPoint(vectors)); -} \ No newline at end of file diff --git a/src/Mod/Surface/App/Blending/BlendPoint.h b/src/Mod/Surface/App/Blending/BlendPoint.h index 5b24575359..d775897b01 100644 --- a/src/Mod/Surface/App/Blending/BlendPoint.h +++ b/src/Mod/Surface/App/Blending/BlendPoint.h @@ -20,13 +20,13 @@ * * ***************************************************************************/ -#ifndef BLEND_POINT_H -#define BLEND_POINT_H +#ifndef SURFACE_BLEND_POINT_H +#define SURFACE_BLEND_POINT_H #include -#include #include +#include namespace Surface @@ -36,7 +36,7 @@ namespace Surface * Create a list of vectors formed by a point and some derivatives * obtained from a curve or surface */ -class SurfaceExport BlendPoint: public Base::BaseClass +class SurfaceExport BlendPoint { public: std::vector vectors; @@ -46,8 +46,8 @@ public: * Constructor *\param std::vector */ - BlendPoint(std::vector vectorList); - virtual ~BlendPoint(); + BlendPoint(const std::vector& vectorList); + ~BlendPoint() = default; /*! * Scale the blendpoint vectors *\param double scaling factor @@ -67,7 +67,7 @@ public: *\return Number of vectors of this BlendPoint */ int nbVectors(); - virtual PyObject *getPyObject(void); + private: }; }// namespace Surface diff --git a/src/Mod/Surface/App/Blending/BlendPointPy.xml b/src/Mod/Surface/App/Blending/BlendPointPy.xml index 1305d115e3..8024dc3c99 100644 --- a/src/Mod/Surface/App/Blending/BlendPointPy.xml +++ b/src/Mod/Surface/App/Blending/BlendPointPy.xml @@ -1,7 +1,7 @@ -#include -#include #include #endif #include "Blending/BlendPoint.h" #include "Blending/BlendPointPy.h" +#include "Blending/BlendPointPy.cpp" #include #include #include -#include "Blending/BlendPointPy.cpp" using namespace Surface; -std::string BlendPointPy::representation(void) const +std::string BlendPointPy::representation() const { - Base::Vector3d bp = getBlendPointPtr()->vectors[0]; std::stringstream str; - str << "G" << getBlendPointPtr()->getContinuity() - << " BlendPoint at (" << bp.x << ", " << bp.y << ", " << bp.z << "), "; + str << "G" << getBlendPointPtr()->getContinuity() << " BlendPoint"; + + if (getBlendPointPtr()->vectors.empty()) { + Base::Vector3d bp = getBlendPointPtr()->vectors[0]; + str << " at (" << bp.x << ", " << bp.y << ", " << bp.z << "), "; + } return str.str(); } @@ -109,10 +110,15 @@ int BlendPointPy::PyInit(PyObject *args, PyObject *) return 0; } catch (const std::exception &e) { - std::cerr << e.what() << '\n'; + PyErr_SetString(PyExc_RuntimeError, e.what()); return -1; } } + + PyErr_SetString(PyExc_TypeError, "supported signatures:\n" + "BlendPoint()\n" + "BlendPoint(list of Vector)\n" + "BlendPoint(edge, parameter and continiuity)\n"); return -1; } @@ -127,7 +133,7 @@ PyObject *BlendPointPy::setSize(PyObject *args) Py_Return; } catch (Standard_Failure &e) { - PyErr_SetString(PyExc_Exception, "Failed to set size"); + PyErr_SetString(Base::PyExc_FC_CADKernelError, "Failed to set size"); return nullptr; } } @@ -141,52 +147,41 @@ PyObject *BlendPointPy::getSize(PyObject *args) double bpTangentLength = getBlendPointPtr()->vectors[1].Length(); return Py_BuildValue("d", bpTangentLength); } + + PyErr_SetString(PyExc_RuntimeError, "Cannot determine size"); return nullptr; } Py::List BlendPointPy::getVectors() const { - try { - BlendPoint *bp = getBlendPointPtr(); - std::vector p = bp->vectors; - Py::List vecs; - for (size_t i = 0; i < p.size(); i++) { - Base::VectorPy *vec = new Base::VectorPy(Base::Vector3d( - p[i].x, p[i].y, p[i].z)); - vecs.append(Py::asObject(vec)); - } - return vecs; - } - catch (Standard_Failure &e) { - PyErr_SetString(PyExc_RuntimeError, - e.GetMessageString()); - return Py::List(); + BlendPoint *bp = getBlendPointPtr(); + Py::List vecs; + for (const auto& p : bp->vectors) { + Base::VectorPy *vec = new Base::VectorPy(p); + vecs.append(Py::asObject(vec)); } + return vecs; } PyObject *BlendPointPy::setvectors(PyObject *args) { - BlendPoint *bp = getBlendPointPtr(); PyObject *plist; if (!PyArg_ParseTuple(args, "O", &plist)) { PyErr_SetString(PyExc_TypeError, "List of vectors required."); return nullptr; } - try { - Py::Sequence list(plist); - std::vector vecs; - for (Py::Sequence::iterator it = list.begin(); it != list.end(); ++it) { - Py::Vector v(*it); - Base::Vector3d pole = v.toVector(); - vecs.emplace_back(pole); - } - bp->vectors = vecs; - Py_Return; + + Py::Sequence list(plist); + std::vector vecs; + for (Py::Sequence::iterator it = list.begin(); it != list.end(); ++it) { + Py::Vector v(*it); + Base::Vector3d pole = v.toVector(); + vecs.emplace_back(pole); } - catch (Standard_Failure &e) { - PyErr_SetString(PyExc_RuntimeError, e.GetMessageString()); - } - return nullptr; + + BlendPoint *bp = getBlendPointPtr(); + bp->vectors = vecs; + Py_Return; } PyObject *BlendPointPy::getCustomAttributes(const char * /*attr*/) const diff --git a/src/Mod/Surface/App/Blending/FeatureBlendCurve.cpp b/src/Mod/Surface/App/Blending/FeatureBlendCurve.cpp index 77748ebec4..b3c63c53a5 100644 --- a/src/Mod/Surface/App/Blending/FeatureBlendCurve.cpp +++ b/src/Mod/Surface/App/Blending/FeatureBlendCurve.cpp @@ -128,7 +128,6 @@ BlendPoint FeatureBlendCurve::GetBlendPoint(App::PropertyLinkSub &link, App::Pro App::DocumentObjectExecReturn *FeatureBlendCurve::execute(void) { - BlendPoint bp1 = GetBlendPoint(StartEdge, StartParameter, StartContinuity); BlendPoint bp2 = GetBlendPoint(EndEdge, EndParameter, EndContinuity); @@ -149,10 +148,6 @@ App::DocumentObjectExecReturn *FeatureBlendCurve::execute(void) return StdReturn; } -PyObject* Surface::BlendCurve::getPyObject(){ - return nullptr; -} - double FeatureBlendCurve::RelativeToRealParameters(double relativeValue, double fp, double lp) { return fp + relativeValue * (lp - fp); diff --git a/src/Mod/Surface/App/Blending/FeatureBlendCurve.h b/src/Mod/Surface/App/Blending/FeatureBlendCurve.h index 910facf928..6ff4329a32 100644 --- a/src/Mod/Surface/App/Blending/FeatureBlendCurve.h +++ b/src/Mod/Surface/App/Blending/FeatureBlendCurve.h @@ -53,9 +53,9 @@ public: Standard_Integer maxDegree; - App::DocumentObjectExecReturn *execute(void) override; + App::DocumentObjectExecReturn *execute() override; short mustExecute() const override; - const char *getViewProviderName(void) const override + const char *getViewProviderName() const override { return "SurfaceGui::ViewProviderBlendCurve"; } @@ -66,7 +66,7 @@ private: bool lockOnChangeMutex; protected: - virtual void onChanged(const App::Property *prop) override; + void onChanged(const App::Property *prop) override; }; }//Namespace Surface diff --git a/src/Mod/Surface/Gui/AppSurfaceGui.cpp b/src/Mod/Surface/Gui/AppSurfaceGui.cpp index 1df76c45ec..5bc15816f9 100644 --- a/src/Mod/Surface/Gui/AppSurfaceGui.cpp +++ b/src/Mod/Surface/Gui/AppSurfaceGui.cpp @@ -54,7 +54,7 @@ public: private: }; -PyObject *initModule(){ +PyObject *initModule() { return Base::Interpreter().addModule(new Module); } @@ -76,10 +76,10 @@ PyMOD_INIT_FUNC(SurfaceGui) SurfaceGui::Workbench::init(); SurfaceGui::ViewProviderGeomFillSurface ::init(); - SurfaceGui::ViewProviderFilling ::init(); - SurfaceGui::ViewProviderSections ::init(); - SurfaceGui::ViewProviderExtend ::init(); - SurfaceGui::ViewProviderBlendCurve ::init(); + SurfaceGui::ViewProviderFilling ::init(); + SurfaceGui::ViewProviderSections ::init(); + SurfaceGui::ViewProviderExtend ::init(); + SurfaceGui::ViewProviderBlendCurve ::init(); // SurfaceGui::ViewProviderCut::init(); PyObject *mod = SurfaceGui::initModule(); diff --git a/src/Mod/Surface/Gui/Blending/ViewProviderBlendCurve.cpp b/src/Mod/Surface/Gui/Blending/ViewProviderBlendCurve.cpp index 520215a1f8..333c4c6051 100644 --- a/src/Mod/Surface/Gui/Blending/ViewProviderBlendCurve.cpp +++ b/src/Mod/Surface/Gui/Blending/ViewProviderBlendCurve.cpp @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (c) 2020 Eliud Cabrera Castillo * + * Copyright (c) 2022 Matteo Grellier * * * * This file is part of the FreeCAD CAx development system. * * * @@ -20,21 +20,17 @@ * * ***************************************************************************/ -#include "../PreCompiled.h" +#include "PreCompiled.h" #include -#include - #include "ViewProviderBlendCurve.h" -using namespace SurfaceGui; - PROPERTY_SOURCE(SurfaceGui::ViewProviderBlendCurve, PartGui::ViewProviderSpline) namespace SurfaceGui { -QIcon ViewProviderBlendCurve::getIcon(void) const +QIcon ViewProviderBlendCurve::getIcon() const { return Gui::BitmapFactory().pixmap("BlendCurve"); } diff --git a/src/Mod/Surface/Gui/Blending/ViewProviderBlendCurve.h b/src/Mod/Surface/Gui/Blending/ViewProviderBlendCurve.h index 143a7d1828..09e4b70c89 100644 --- a/src/Mod/Surface/Gui/Blending/ViewProviderBlendCurve.h +++ b/src/Mod/Surface/Gui/Blending/ViewProviderBlendCurve.h @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (c) 2020 Eliud Cabrera Castillo * + * Copyright (c) 2022 Matteo Grellier * * * * This file is part of the FreeCAD CAx development system. * * * @@ -24,7 +24,6 @@ #define SURFACEGUI_VIEWPROVIDERBLENDCURVE_H #include -#include namespace SurfaceGui { @@ -34,7 +33,7 @@ class ViewProviderBlendCurve: public PartGui::ViewProviderSpline PROPERTY_HEADER(SurfaceGui::ViewProviderBlendCurve); public: - QIcon getIcon(void) const; + QIcon getIcon() const; }; }//namespace SurfaceGui diff --git a/src/Mod/Surface/Gui/CMakeLists.txt b/src/Mod/Surface/Gui/CMakeLists.txt index bcee96f93a..5d4d9e77b5 100644 --- a/src/Mod/Surface/Gui/CMakeLists.txt +++ b/src/Mod/Surface/Gui/CMakeLists.txt @@ -9,6 +9,7 @@ include_directories( ${CMAKE_SOURCE_DIR}/src ${CMAKE_BINARY_DIR}/src ${CMAKE_CURRENT_BINARY_DIR} + ${CMAKE_CURRENT_SOURCE_DIR} ${Boost_INCLUDE_DIRS} ${COIN3D_INCLUDE_DIRS} ${OCC_INCLUDE_DIR} diff --git a/src/Mod/Surface/Gui/Command.cpp b/src/Mod/Surface/Gui/Command.cpp index 2c5b3b24a1..9a89a24811 100644 --- a/src/Mod/Surface/Gui/Command.cpp +++ b/src/Mod/Surface/Gui/Command.cpp @@ -236,7 +236,7 @@ bool CmdSurfaceCurveOnMesh::isActive() DEF_STD_CMD_A(CmdBlendSurface) CmdBlendSurface::CmdBlendSurface() - : Command("BlendSurface") + : Command("Surface_BlendSurface") { sAppModule = "Surface"; sGroup = QT_TR_NOOP("Surface"); @@ -249,10 +249,10 @@ CmdBlendSurface::CmdBlendSurface() void CmdBlendSurface::activated(int) { - + } -bool CmdBlendSurface::isActive(void) +bool CmdBlendSurface::isActive() { return true; } @@ -267,7 +267,7 @@ bool CmdBlendSurface::isActive(void) DEF_STD_CMD_A(CmdBlendCurve) CmdBlendCurve::CmdBlendCurve() - : Command("BlendCurve") + : Command("Surface_BlendCurve") { sAppModule = "Surface"; sGroup = QT_TR_NOOP("Surface"); @@ -332,7 +332,7 @@ void CmdBlendCurve::activated(int) commitCommand(); } -bool CmdBlendCurve::isActive(void) +bool CmdBlendCurve::isActive() { Gui::SelectionFilter edgeFilter("SELECT Part::Feature SUBELEMENT Edge COUNT 2"); return edgeFilter.match(); diff --git a/src/Mod/Surface/Gui/Workbench.cpp b/src/Mod/Surface/Gui/Workbench.cpp index 0abe30b0df..a16839b6f4 100644 --- a/src/Mod/Surface/Gui/Workbench.cpp +++ b/src/Mod/Surface/Gui/Workbench.cpp @@ -57,7 +57,7 @@ Gui::MenuItem *Workbench::setupMenuBar() const << "Surface_Sections" << "Surface_ExtendFace" << "Surface_CurveOnMesh" - << "BlendCurve"; + << "Surface_BlendCurve"; /* *surface << "Surface_Cut"; */ @@ -76,7 +76,7 @@ Gui::ToolBarItem *Workbench::setupToolBars() const << "Surface_Sections" << "Surface_ExtendFace" << "Surface_CurveOnMesh" - << "BlendCurve"; + << "Surface_BlendCurve"; /* *surface << "Surface_Cut"; */