diff --git a/src/Mod/Part/App/AppPart.cpp b/src/Mod/Part/App/AppPart.cpp index 991bbe5601..a550a71612 100644 --- a/src/Mod/Part/App/AppPart.cpp +++ b/src/Mod/Part/App/AppPart.cpp @@ -147,6 +147,7 @@ #include #include #include +#include #include "PropertyGeometryList.h" #include "DatumFeature.h" #include "Attacher.h" @@ -289,6 +290,7 @@ PyMOD_INIT_FUNC(Part) Base::Interpreter().addType(&Part::GeometryStringExtensionPy ::Type,partModule,"GeometryStringExtension"); Base::Interpreter().addType(&Part::GeometryBoolExtensionPy ::Type,partModule,"GeometryBoolExtension"); Base::Interpreter().addType(&Part::GeometryDoubleExtensionPy ::Type,partModule,"GeometryDoubleExtension"); + Base::Interpreter().addType(&Part::PrecisionPy ::Type,partModule,"Precision"); // BRepFeat package PyObject* brepfeatModule(module.getAttr("BRepFeat").ptr()); diff --git a/src/Mod/Part/App/CMakeLists.txt b/src/Mod/Part/App/CMakeLists.txt index dc88ba51c2..dfec4362bf 100644 --- a/src/Mod/Part/App/CMakeLists.txt +++ b/src/Mod/Part/App/CMakeLists.txt @@ -92,6 +92,7 @@ generate_from_xml(TopoShapeVertexPy) generate_from_xml(TopoShapeWirePy) generate_from_xml(BRepOffsetAPI_MakePipeShellPy) generate_from_xml(BRepOffsetAPI_MakeFillingPy) +generate_from_xml(PrecisionPy) # make sure to create the directory at configure time file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/BRepFeat) @@ -318,6 +319,8 @@ SET(Python_SRCS BRepOffsetAPI_MakePipeShellPyImp.cpp BRepOffsetAPI_MakeFillingPy.xml BRepOffsetAPI_MakeFillingPyImp.cpp + PrecisionPy.xml + PrecisionPyImp.cpp PartPyCXX.cpp PartPyCXX.h ) diff --git a/src/Mod/Part/App/PrecisionPy.xml b/src/Mod/Part/App/PrecisionPy.xml new file mode 100644 index 0000000000..6ba4c5a80f --- /dev/null +++ b/src/Mod/Part/App/PrecisionPy.xml @@ -0,0 +1,69 @@ + + + + + + This is the Type class + This is the Type class + + + + Returns the recommended precision value when checking the equality of two angles (given in radians) + + + + + Returns the recommended precision value when checking coincidence of two points in real space + + + + + Returns square of confusion + + + + + Returns the precision value in real space, frequently used by intersection algorithms + + + + + Returns the precision value in real space, frequently used by approximation algorithms + + + + + Convert a real space precision to a parametric space precision + + + + + Returns True if R may be considered as an infinite number + + + + + Returns True if R may be considered as a positive infinite number + + + + + Returns True if R may be considered as a negative infinite number + + + + + Returns a big number that can be considered as infinite + + + + diff --git a/src/Mod/Part/App/PrecisionPyImp.cpp b/src/Mod/Part/App/PrecisionPyImp.cpp new file mode 100644 index 0000000000..e3cab88ca0 --- /dev/null +++ b/src/Mod/Part/App/PrecisionPyImp.cpp @@ -0,0 +1,133 @@ +/*************************************************************************** + * Copyright (c) 2022 Werner Mayer * + * * + * 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_ +#endif + +#include "PrecisionPy.h" +#include "PrecisionPy.cpp" + +using namespace Part; + + +// returns a string which represents the object e.g. when printed in python +std::string PrecisionPy::representation() const +{ + return std::string(""); +} + +PyObject* PrecisionPy::angular(PyObject * /*args*/) +{ + Py::Float v(Precision::Angular()); + return Py::new_reference_to(v); +} + +PyObject* PrecisionPy::confusion(PyObject * /*args*/) +{ + Py::Float v(Precision::Confusion()); + return Py::new_reference_to(v); +} + +PyObject* PrecisionPy::squareConfusion(PyObject * /*args*/) +{ + Py::Float v(Precision::SquareConfusion()); + return Py::new_reference_to(v); +} + +PyObject* PrecisionPy::intersection(PyObject * /*args*/) +{ + Py::Float v(Precision::Intersection()); + return Py::new_reference_to(v); +} + +PyObject* PrecisionPy::approximation(PyObject * /*args*/) +{ + Py::Float v(Precision::Approximation()); + return Py::new_reference_to(v); +} + +PyObject* PrecisionPy::parametric(PyObject *args) +{ + double p; + if (PyArg_ParseTuple(args, "d", &p)) { + Py::Float v(Precision::Parametric(p)); + return Py::new_reference_to(v); + } + + PyErr_Clear(); + double t; + if (PyArg_ParseTuple(args, "dd", &p, &t)) { + Py::Float v(Precision::Parametric(p, t)); + return Py::new_reference_to(v); + } + + PyErr_SetString(PyExc_ValueError, "one or two floats expected"); + return nullptr; +} + +PyObject* PrecisionPy::isInfinite(PyObject *args) +{ + double v; + if (!PyArg_ParseTuple(args, "d", &v)) + return nullptr; + + Py::Boolean b(Precision::IsInfinite(v)); + return Py::new_reference_to(b); +} + +PyObject* PrecisionPy::isPositiveInfinite(PyObject *args) +{ + double v; + if (!PyArg_ParseTuple(args, "d", &v)) + return nullptr; + + Py::Boolean b(Precision::IsPositiveInfinite(v)); + return Py::new_reference_to(b); +} + +PyObject* PrecisionPy::isNegativeInfinite(PyObject *args) +{ + double v; + if (!PyArg_ParseTuple(args, "d", &v)) + return nullptr; + + Py::Boolean b(Precision::IsNegativeInfinite(v)); + return Py::new_reference_to(b); +} + +PyObject* PrecisionPy::infinite(PyObject * /*args*/) +{ + Py::Float v(Precision::Infinite()); + return Py::new_reference_to(v); +} + +PyObject *PrecisionPy::getCustomAttributes(const char* /*attr*/) const +{ + return nullptr; +} + +int PrecisionPy::setCustomAttributes(const char* /*attr*/, PyObject* /*obj*/) +{ + return 0; +}