Skip to content

Commit

Permalink
Part: expose Precision to Python
Browse files Browse the repository at this point in the history
  • Loading branch information
wwmayer committed Jan 17, 2022
1 parent a3b3134 commit 20b86e5
Show file tree
Hide file tree
Showing 4 changed files with 207 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/Mod/Part/App/AppPart.cpp
Expand Up @@ -147,6 +147,7 @@
#include <Mod/Part/App/HLRBRep/HLRBRep_PolyAlgoPy.h>
#include <Mod/Part/App/HLRBRep/PolyHLRToShapePy.h>
#include <Mod/Part/App/ShapeUpgrade/UnifySameDomainPy.h>
#include <Mod/Part/App/PrecisionPy.h>
#include "PropertyGeometryList.h"
#include "DatumFeature.h"
#include "Attacher.h"
Expand Down Expand Up @@ -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());
Expand Down
3 changes: 3 additions & 0 deletions src/Mod/Part/App/CMakeLists.txt
Expand Up @@ -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)
Expand Down Expand Up @@ -318,6 +319,8 @@ SET(Python_SRCS
BRepOffsetAPI_MakePipeShellPyImp.cpp
BRepOffsetAPI_MakeFillingPy.xml
BRepOffsetAPI_MakeFillingPyImp.cpp
PrecisionPy.xml
PrecisionPyImp.cpp
PartPyCXX.cpp
PartPyCXX.h
)
Expand Down
69 changes: 69 additions & 0 deletions src/Mod/Part/App/PrecisionPy.xml
@@ -0,0 +1,69 @@
<?xml version="1.0" encoding="UTF-8"?>
<GenerateModel xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="generateMetaModel_Module.xsd">
<PythonExport
Father="PyObjectBase"
Name="PrecisionPy"
PythonName="Part.Precision"
Twin="Precision"
TwinPointer="Precision"
Include="Precision.hxx"
Namespace="Part"
FatherInclude="Base/PyObjectBase.h"
FatherNamespace="Base">
<Documentation>
<Author Licence="LGPL" Name="Werner Mayer" EMail="wmayer@users.sourceforge.net" />
<DeveloperDocu>This is the Type class</DeveloperDocu>
<UserDocu>This is the Type class</UserDocu>
</Documentation>
<Methode Name="angular" Static="true">
<Documentation>
<UserDocu>Returns the recommended precision value when checking the equality of two angles (given in radians)</UserDocu>
</Documentation>
</Methode>
<Methode Name="confusion" Static="true">
<Documentation>
<UserDocu>Returns the recommended precision value when checking coincidence of two points in real space</UserDocu>
</Documentation>
</Methode>
<Methode Name="squareConfusion" Static="true">
<Documentation>
<UserDocu>Returns square of confusion</UserDocu>
</Documentation>
</Methode>
<Methode Name="intersection" Static="true">
<Documentation>
<UserDocu>Returns the precision value in real space, frequently used by intersection algorithms</UserDocu>
</Documentation>
</Methode>
<Methode Name="approximation" Static="true">
<Documentation>
<UserDocu>Returns the precision value in real space, frequently used by approximation algorithms</UserDocu>
</Documentation>
</Methode>
<Methode Name="parametric" Static="true">
<Documentation>
<UserDocu>Convert a real space precision to a parametric space precision</UserDocu>
</Documentation>
</Methode>
<Methode Name="isInfinite" Static="true">
<Documentation>
<UserDocu>Returns True if R may be considered as an infinite number</UserDocu>
</Documentation>
</Methode>
<Methode Name="isPositiveInfinite" Static="true">
<Documentation>
<UserDocu>Returns True if R may be considered as a positive infinite number</UserDocu>
</Documentation>
</Methode>
<Methode Name="isNegativeInfinite" Static="true">
<Documentation>
<UserDocu>Returns True if R may be considered as a negative infinite number</UserDocu>
</Documentation>
</Methode>
<Methode Name="infinite" Static="true">
<Documentation>
<UserDocu>Returns a big number that can be considered as infinite</UserDocu>
</Documentation>
</Methode>
</PythonExport>
</GenerateModel>
133 changes: 133 additions & 0 deletions src/Mod/Part/App/PrecisionPyImp.cpp
@@ -0,0 +1,133 @@
/***************************************************************************
* Copyright (c) 2022 Werner Mayer <wmayer[at]users.sourceforge.net> *
* *
* 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("<Precision object>");
}

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;
}

0 comments on commit 20b86e5

Please sign in to comment.