From c85c8cfb33896a9c708137d683309cdf3e4e197c Mon Sep 17 00:00:00 2001 From: Matteo-Grellier Date: Mon, 18 Jul 2022 11:05:31 +0200 Subject: [PATCH] [Surface]: Implementation of BlenCurve. --- src/Mod/Surface/App/AppSurface.cpp | 53 ++--- src/Mod/Surface/App/Blending/BlendCurve.cpp | 18 +- src/Mod/Surface/App/Blending/BlendCurvePy.xml | 3 +- .../Surface/App/Blending/BlendCurvePyImp.cpp | 26 +-- src/Mod/Surface/App/Blending/BlendPoint.cpp | 2 +- src/Mod/Surface/App/Blending/BlendPointPy.xml | 2 +- .../Surface/App/Blending/BlendPointPyImp.cpp | 12 +- .../Surface/App/Blending/FeatureBlendCurve.h | 74 +++++++ src/Mod/Surface/App/CMakeLists.txt | 79 +++++--- src/Mod/Surface/Gui/AppSurfaceGui.cpp | 23 ++- .../Gui/Blending/ViewProviderBlendCurve.cpp | 42 ++++ .../Gui/Blending/ViewProviderBlendCurve.h | 42 ++++ src/Mod/Surface/Gui/CMakeLists.txt | 6 + src/Mod/Surface/Gui/Command.cpp | 120 +++++++++++ src/Mod/Surface/Gui/Resources/Surface.qrc | 2 + .../Gui/Resources/icons/BlendCurve.svg | 30 +++ .../Gui/Resources/icons/BlendSurface.svg | 191 ++++++++++++++++++ src/Mod/Surface/Gui/Workbench.cpp | 30 +-- 18 files changed, 644 insertions(+), 111 deletions(-) create mode 100644 src/Mod/Surface/App/Blending/FeatureBlendCurve.h create mode 100644 src/Mod/Surface/Gui/Blending/ViewProviderBlendCurve.cpp create mode 100644 src/Mod/Surface/Gui/Blending/ViewProviderBlendCurve.h create mode 100644 src/Mod/Surface/Gui/Resources/icons/BlendCurve.svg create mode 100644 src/Mod/Surface/Gui/Resources/icons/BlendSurface.svg diff --git a/src/Mod/Surface/App/AppSurface.cpp b/src/Mod/Surface/App/AppSurface.cpp index 773c2b3924..cf524efbdc 100644 --- a/src/Mod/Surface/App/AppSurface.cpp +++ b/src/Mod/Surface/App/AppSurface.cpp @@ -24,27 +24,30 @@ #include #include -#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 #include -namespace Surface { -class Module : public Py::ExtensionModule +namespace Surface +{ +class Module: public Py::ExtensionModule { public: Module() : Py::ExtensionModule("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); } diff --git a/src/Mod/Surface/App/Blending/BlendCurve.cpp b/src/Mod/Surface/App/Blending/BlendCurve.cpp index c3b7e12bdb..147962b5c4 100644 --- a/src/Mod/Surface/App/Blending/BlendCurve.cpp +++ b/src/Mod/Surface/App/Blending/BlendCurve.cpp @@ -33,10 +33,10 @@ #include #include #endif -#include -#include #include "Blending/BlendCurve.h" #include "Blending/BlendCurvePy.h" +#include +#include using namespace Surface; @@ -47,7 +47,7 @@ BlendCurve::BlendCurve() BlendCurve::BlendCurve(std::vector 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); diff --git a/src/Mod/Surface/App/Blending/BlendCurvePy.xml b/src/Mod/Surface/App/Blending/BlendCurvePy.xml index 12cf9293c5..aab9d90313 100644 --- a/src/Mod/Surface/App/Blending/BlendCurvePy.xml +++ b/src/Mod/Surface/App/Blending/BlendCurvePy.xml @@ -17,8 +17,7 @@ - Create a BlendCurve that interpolate a list of BlendPoints. - curve = BlendCurve([BlendPoint1, BlendPoint2]) + Create a BlendCurve that interpolate 2 BlendPoints. curve = BlendCurve(BlendPoint1, BlendPoint2) diff --git a/src/Mod/Surface/App/Blending/BlendCurvePyImp.cpp b/src/Mod/Surface/App/Blending/BlendCurvePyImp.cpp index 5d169ece5e..cf35ccc465 100644 --- a/src/Mod/Surface/App/Blending/BlendCurvePyImp.cpp +++ b/src/Mod/Surface/App/Blending/BlendCurvePyImp.cpp @@ -29,9 +29,9 @@ #include "Blending/BlendPointPy.h" // #include "Mod/Part/App/Geometry.h" // #include +#include "Blending/BlendCurvePy.cpp" #include #include -#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 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(obj.ptr())->getBlendPointPtr(); - bpList.emplace_back(*geom); - } - } - this->getBlendCurvePtr()->blendPoints = bpList; - return 0; - } - - PyErr_Clear(); 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(); @@ -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; } diff --git a/src/Mod/Surface/App/Blending/BlendPoint.cpp b/src/Mod/Surface/App/Blending/BlendPoint.cpp index 1d0ee30c16..e96179808e 100644 --- a/src/Mod/Surface/App/Blending/BlendPoint.cpp +++ b/src/Mod/Surface/App/Blending/BlendPoint.cpp @@ -45,7 +45,7 @@ BlendPoint::BlendPoint(std::vector vectorList) BlendPoint::BlendPoint() { - vectors.emplace_back(Base::Vector3d(0, 0, 0)); + vectors.emplace_back(Base::Vector3d(0, 0, 0)); } BlendPoint::~BlendPoint() diff --git a/src/Mod/Surface/App/Blending/BlendPointPy.xml b/src/Mod/Surface/App/Blending/BlendPointPy.xml index c3ec282eec..5c6f1c1798 100644 --- a/src/Mod/Surface/App/Blending/BlendPointPy.xml +++ b/src/Mod/Surface/App/Blending/BlendPointPy.xml @@ -40,7 +40,7 @@ Resizes the BlendPoint vectors, - by setting the lenght of the first derivative. + by setting the length of the first derivative. theBlendPoint.setSize(new_size) diff --git a/src/Mod/Surface/App/Blending/BlendPointPyImp.cpp b/src/Mod/Surface/App/Blending/BlendPointPyImp.cpp index b9e7d88adc..4756714146 100644 --- a/src/Mod/Surface/App/Blending/BlendPointPyImp.cpp +++ b/src/Mod/Surface/App/Blending/BlendPointPyImp.cpp @@ -27,13 +27,14 @@ #include #include #endif +#include "Blending/BlendPoint.h" +#include "Blending/BlendPointPy.h" #include #include #include -#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 vecs; @@ -89,6 +90,11 @@ int BlendPointPy::PyInit(PyObject* args, PyObject*) TopoDS_Shape shape = static_cast(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()); diff --git a/src/Mod/Surface/App/Blending/FeatureBlendCurve.h b/src/Mod/Surface/App/Blending/FeatureBlendCurve.h new file mode 100644 index 0000000000..910facf928 --- /dev/null +++ b/src/Mod/Surface/App/Blending/FeatureBlendCurve.h @@ -0,0 +1,74 @@ +/*************************************************************************** + * Copyright (c) 2014 Matteo Grellier * + * * + * 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 +#include +#include +#include +#include +#include + +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 ¶m, App::PropertyIntegerConstraint &Continuity); + double RelativeToRealParameters(double, double, double); + bool lockOnChangeMutex; + +protected: + virtual void onChanged(const App::Property *prop) override; +}; + +}//Namespace Surface + +#endif diff --git a/src/Mod/Surface/App/CMakeLists.txt b/src/Mod/Surface/App/CMakeLists.txt index 9d332f7eb9..067d4a0aea 100644 --- a/src/Mod/Surface/App/CMakeLists.txt +++ b/src/Mod/Surface/App/CMakeLists.txt @@ -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}) diff --git a/src/Mod/Surface/Gui/AppSurfaceGui.cpp b/src/Mod/Surface/Gui/AppSurfaceGui.cpp index 89d00916b1..1df76c45ec 100644 --- a/src/Mod/Surface/Gui/AppSurfaceGui.cpp +++ b/src/Mod/Surface/Gui/AppSurfaceGui.cpp @@ -24,15 +24,16 @@ #include "PreCompiled.h" #include -#include #include +#include #include -#include "Workbench.h" -#include "TaskGeomFillSurface.h" +#include "Blending/ViewProviderBlendCurve.h" #include "TaskFilling.h" +#include "TaskGeomFillSurface.h" #include "TaskSections.h" #include "ViewProviderExtend.h" +#include "Workbench.h" // use a different name to CreateCommand() @@ -45,7 +46,7 @@ class Module : public Py::ExtensionModule public: Module() : Py::ExtensionModule("SurfaceGui") { - initialize("This module is the SurfaceGui module."); // register with Python + initialize("This module is the SurfaceGui module.");// register with Python } ~Module() override {} @@ -53,12 +54,11 @@ public: private: }; -PyObject* initModule() -{ +PyObject *initModule(){ return Base::Interpreter().addModule(new Module); } -} // namespace SurfaceGui +}// namespace SurfaceGui /* Python entry */ PyMOD_INIT_FUNC(SurfaceGui) @@ -76,12 +76,13 @@ PyMOD_INIT_FUNC(SurfaceGui) SurfaceGui::Workbench::init(); SurfaceGui::ViewProviderGeomFillSurface ::init(); - SurfaceGui::ViewProviderFilling ::init(); - SurfaceGui::ViewProviderSections ::init(); - SurfaceGui::ViewProviderExtend::init(); + SurfaceGui::ViewProviderFilling ::init(); + SurfaceGui::ViewProviderSections ::init(); + SurfaceGui::ViewProviderExtend ::init(); + SurfaceGui::ViewProviderBlendCurve ::init(); // SurfaceGui::ViewProviderCut::init(); - PyObject* mod = SurfaceGui::initModule(); + PyObject *mod = SurfaceGui::initModule(); Base::Console().Log("Loading GUI of Surface module... done\n"); PyMOD_Return(mod); } diff --git a/src/Mod/Surface/Gui/Blending/ViewProviderBlendCurve.cpp b/src/Mod/Surface/Gui/Blending/ViewProviderBlendCurve.cpp new file mode 100644 index 0000000000..520215a1f8 --- /dev/null +++ b/src/Mod/Surface/Gui/Blending/ViewProviderBlendCurve.cpp @@ -0,0 +1,42 @@ +/*************************************************************************** + * Copyright (c) 2020 Eliud Cabrera Castillo * + * * + * 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" + +#include +#include + +#include "ViewProviderBlendCurve.h" + +using namespace SurfaceGui; + +PROPERTY_SOURCE(SurfaceGui::ViewProviderBlendCurve, PartGui::ViewProviderSpline) + +namespace SurfaceGui +{ + +QIcon ViewProviderBlendCurve::getIcon(void) const +{ + return Gui::BitmapFactory().pixmap("BlendCurve"); +} + +}//namespace SurfaceGui diff --git a/src/Mod/Surface/Gui/Blending/ViewProviderBlendCurve.h b/src/Mod/Surface/Gui/Blending/ViewProviderBlendCurve.h new file mode 100644 index 0000000000..143a7d1828 --- /dev/null +++ b/src/Mod/Surface/Gui/Blending/ViewProviderBlendCurve.h @@ -0,0 +1,42 @@ +/*************************************************************************** + * Copyright (c) 2020 Eliud Cabrera Castillo * + * * + * 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 SURFACEGUI_VIEWPROVIDERBLENDCURVE_H +#define SURFACEGUI_VIEWPROVIDERBLENDCURVE_H + +#include +#include + +namespace SurfaceGui +{ + +class ViewProviderBlendCurve: public PartGui::ViewProviderSpline +{ + PROPERTY_HEADER(SurfaceGui::ViewProviderBlendCurve); + +public: + QIcon getIcon(void) const; +}; + +}//namespace SurfaceGui + +#endif// SURFACEGUI_VIEWPROVIDEREXTEND_H diff --git a/src/Mod/Surface/Gui/CMakeLists.txt b/src/Mod/Surface/Gui/CMakeLists.txt index 83aec1ddb2..bcee96f93a 100644 --- a/src/Mod/Surface/Gui/CMakeLists.txt +++ b/src/Mod/Surface/Gui/CMakeLists.txt @@ -36,6 +36,11 @@ SET(SurfaceGui_UIC_SRCS TaskSections.ui ) +SET(BlendingGui_SRCS + Blending/ViewProviderBlendCurve.cpp + Blending/ViewProviderBlendCurve.h +) + if (BUILD_QT5) qt5_wrap_ui(SurfaceGui_UIC_HDRS ${SurfaceGui_UIC_SRCS}) else() @@ -45,6 +50,7 @@ endif() SET(SurfaceGui_SRCS ${SurfaceGui_QRC_SRCS} ${SurfaceGui_UIC_HDRS} + ${BlendingGui_SRCS} TaskFilling.cpp TaskFilling.h TaskFillingEdge.cpp diff --git a/src/Mod/Surface/Gui/Command.cpp b/src/Mod/Surface/Gui/Command.cpp index c5fe56ffff..2c5b3b24a1 100644 --- a/src/Mod/Surface/Gui/Command.cpp +++ b/src/Mod/Surface/Gui/Command.cpp @@ -61,6 +61,8 @@ #include #include #include "Mod/Part/App/PartFeature.h" +#include +#include //=========================================================================== @@ -189,6 +191,8 @@ void CmdSurfaceGeomFillSurface::activated(int iMsg) } + + DEF_STD_CMD_A(CmdSurfaceCurveOnMesh) CmdSurfaceCurveOnMesh::CmdSurfaceCurveOnMesh() @@ -204,6 +208,8 @@ CmdSurfaceCurveOnMesh::CmdSurfaceCurveOnMesh() sPixmap = "Surface_CurveOnMesh"; } + + void CmdSurfaceCurveOnMesh::activated(int) { doCommand(Doc,"import MeshPartGui, FreeCADGui\n" @@ -224,6 +230,118 @@ bool CmdSurfaceCurveOnMesh::isActive() return false; } +//=========================================================================== +// CmdBlendSurface THIS IS THE BLEND SURFACE COMMAND +//=========================================================================== +DEF_STD_CMD_A(CmdBlendSurface) + +CmdBlendSurface::CmdBlendSurface() + : Command("BlendSurface") +{ + sAppModule = "Surface"; + sGroup = QT_TR_NOOP("Surface"); + sMenuText = QT_TR_NOOP("Blend Surface"); + sToolTipText = QT_TR_NOOP("This is the blend Surface feature"); + sStatusTip = sToolTipText; + sWhatsThis = "BlendSurface"; + sPixmap = "BlendSurface"; +} + +void CmdBlendSurface::activated(int) +{ + +} + +bool CmdBlendSurface::isActive(void) +{ + return true; +} + + + + + +//=========================================================================== +// CmdBlendCurve THIS IS THE BLEND CURVE COMMAND +//=========================================================================== +DEF_STD_CMD_A(CmdBlendCurve) + +CmdBlendCurve::CmdBlendCurve() + : Command("BlendCurve") +{ + sAppModule = "Surface"; + sGroup = QT_TR_NOOP("Surface"); + sMenuText = QT_TR_NOOP("Blend Curve"); + sToolTipText = QT_TR_NOOP("Join two edges with high continuity"); + sStatusTip = sToolTipText; + sWhatsThis = "BlendCurve"; + sPixmap = "BlendCurve"; +} + +void CmdBlendCurve::activated(int) +{ + // To do add pickpoints to parameters + std::string docName = App::GetApplication().getActiveDocument()->getName(); + std::string objName[2]; + std::string edge[2]; + std::string featName = getUniqueObjectName("BlendCurve"); + std::vector sel = getSelection().getSelectionEx(0, Part::Feature::getClassTypeId()); + //std::vector pickedPoints = sel[0].getPickedPoints(); + //App::DocumentObject *obj1 = sel[0].getObject(); + //App::DocumentObject *obj2 = sel[1].getObject(); + //std::vector edge1SubName = sel[0].getSubNames(); + //std::vector edge2SubName = sel[1].getSubNames(); + + //TopoDS_Shape edge1 = static_cast(obj1) + // ->Shape.getShape() + // .getSubShape(edge1SubName[0].c_str()); + //if (edge1.IsNull() || edge1.ShapeType() != TopAbs_EDGE) + // return; + //TopoDS_Shape edge2 = static_cast(obj2) + // ->Shape.getShape() + // .getSubShape(edge2SubName[0].c_str()); + //if (edge2.IsNull() || edge2.ShapeType() != TopAbs_EDGE) + // return; + + //const TopoDS_Edge &e1 = TopoDS::Edge(edge1); + //BRepAdaptor_Curve adapt1(e1); + //gp_Pnt pnt1(pickedPoints[0].x, pickedPoints[0].y, pickedPoints[0].z); + + //GeomAdaptor_Curve geomCurve = adapt1.Curve(); + //GeomAPI_ProjectPointOnCurve geomAPI(pnt1, geomCurve.Curve()); + //double par = geomAPI.LowerDistanceParameter(); + + //edge2.Curve.closestParameter(vec, par) + + objName[0] = sel[0].getFeatName(); + edge[0] = sel[0].getSubNames()[0]; + + if (sel.size() == 1) { + objName[1] = sel[0].getFeatName(); + edge[1] = sel[0].getSubNames()[1]; + } + else { + objName[1] = sel[1].getFeatName(); + edge[1] = sel[1].getSubNames()[0]; + } + openCommand(QT_TRANSLATE_NOOP("Command", "Blend Curve")); + doCommand(Doc, "App.ActiveDocument.addObject(\"Surface::FeatureBlendCurve\",\"%s\")", featName.c_str()); + doCommand(Doc, "App.ActiveDocument.%s.StartEdge = (App.getDocument('%s').getObject('%s'),['%s'])", featName.c_str(), docName.c_str(), objName[0].c_str(), edge[0].c_str()); + doCommand(Doc, "App.ActiveDocument.%s.EndEdge = (App.getDocument('%s').getObject('%s'),['%s'])", featName.c_str(), docName.c_str(), objName[1].c_str(), edge[1].c_str()); + updateActive(); + commitCommand(); +} + +bool CmdBlendCurve::isActive(void) +{ + Gui::SelectionFilter edgeFilter("SELECT Part::Feature SUBELEMENT Edge COUNT 2"); + return edgeFilter.match(); +} + + + + + DEF_STD_CMD_A(CmdSurfaceExtendFace) CmdSurfaceExtendFace::CmdSurfaceExtendFace() @@ -306,4 +424,6 @@ void CreateSurfaceCommands() rcCmdMgr.addCommand(new CmdSurfaceSections()); rcCmdMgr.addCommand(new CmdSurfaceExtendFace()); rcCmdMgr.addCommand(new CmdSurfaceCurveOnMesh()); + rcCmdMgr.addCommand(new CmdBlendCurve()); + rcCmdMgr.addCommand(new CmdBlendSurface()); } diff --git a/src/Mod/Surface/Gui/Resources/Surface.qrc b/src/Mod/Surface/Gui/Resources/Surface.qrc index 7af306fa62..a0840c7967 100644 --- a/src/Mod/Surface/Gui/Resources/Surface.qrc +++ b/src/Mod/Surface/Gui/Resources/Surface.qrc @@ -4,6 +4,7 @@ icons/Surface_BSplineSurface.svg icons/Surface_CurveOnMesh.svg icons/Surface_Cut.svg + icons/BlendCurve.svg icons/Surface_ExtendFace.svg icons/Surface_Filling.svg icons/Surface_GeomFillSurface.svg @@ -11,6 +12,7 @@ icons/Surface_Sewing.svg icons/Surface_Surface.svg icons/Surface_Workbench.svg + icons/BlendSurface.svg diff --git a/src/Mod/Surface/Gui/Resources/icons/BlendCurve.svg b/src/Mod/Surface/Gui/Resources/icons/BlendCurve.svg new file mode 100644 index 0000000000..aeac6de070 --- /dev/null +++ b/src/Mod/Surface/Gui/Resources/icons/BlendCurve.svg @@ -0,0 +1,30 @@ + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/Mod/Surface/Gui/Resources/icons/BlendSurface.svg b/src/Mod/Surface/Gui/Resources/icons/BlendSurface.svg new file mode 100644 index 0000000000..7411c1dcc6 --- /dev/null +++ b/src/Mod/Surface/Gui/Resources/icons/BlendSurface.svg @@ -0,0 +1,191 @@ + + + Surface_Sewing + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + Surface_Sewing + + + [bitacovir] + + + Part_Shape_from_Mesh + 2020/10/03 + http://www.freecadweb.org/wiki/index.php?title=Artwork + + + FreeCAD + + + + + + FreeCAD LGPL2+ + + + https://www.gnu.org/copyleft/lesser.html + + + + + + + + surface + + + + + + + + + + + + + + + + + diff --git a/src/Mod/Surface/Gui/Workbench.cpp b/src/Mod/Surface/Gui/Workbench.cpp index f24b7f5ba6..0abe30b0df 100644 --- a/src/Mod/Surface/Gui/Workbench.cpp +++ b/src/Mod/Surface/Gui/Workbench.cpp @@ -44,40 +44,42 @@ Workbench::~Workbench() { } -Gui::MenuItem* Workbench::setupMenuBar() const +Gui::MenuItem *Workbench::setupMenuBar() const { - Gui::MenuItem* root = StdWorkbench::setupMenuBar(); - Gui::MenuItem* item = root->findItem( "&Windows" ); + Gui::MenuItem *root = StdWorkbench::setupMenuBar(); + Gui::MenuItem *item = root->findItem("&Windows"); - Gui::MenuItem* surface = new Gui::MenuItem; - root->insertItem( item, surface ); + Gui::MenuItem *surface = new Gui::MenuItem; + root->insertItem(item, surface); surface->setCommand("Surface"); *surface << "Surface_Filling" << "Surface_GeomFillSurface" << "Surface_Sections" << "Surface_ExtendFace" - << "Surface_CurveOnMesh"; -/* + << "Surface_CurveOnMesh" + << "BlendCurve"; + /* *surface << "Surface_Cut"; -*/ + */ return root; } -Gui::ToolBarItem* Workbench::setupToolBars() const +Gui::ToolBarItem *Workbench::setupToolBars() const { - Gui::ToolBarItem* root = StdWorkbench::setupToolBars(); + Gui::ToolBarItem *root = StdWorkbench::setupToolBars(); - Gui::ToolBarItem* surface = new Gui::ToolBarItem(root); + Gui::ToolBarItem *surface = new Gui::ToolBarItem(root); surface->setCommand("Surface"); *surface << "Surface_Filling" << "Surface_GeomFillSurface" << "Surface_Sections" << "Surface_ExtendFace" - << "Surface_CurveOnMesh"; -/* + << "Surface_CurveOnMesh" + << "BlendCurve"; + /* *surface << "Surface_Cut"; -*/ + */ return root; }