Part: Default geometry extensions for boolean and double

This commit is contained in:
Abdullah Tahiri
2019-02-11 20:15:48 +01:00
committed by wmayer
parent 331817d1b7
commit 21e1ccbe9b
8 changed files with 317 additions and 0 deletions

View File

@@ -62,6 +62,8 @@
#include "Geometry2d.h"
#include "Mod/Part/App/GeometryIntExtensionPy.h"
#include "Mod/Part/App/GeometryStringExtensionPy.h"
#include "Mod/Part/App/GeometryBoolExtensionPy.h"
#include "Mod/Part/App/GeometryDoubleExtensionPy.h"
#include "Mod/Part/App/TopoShapePy.h"
#include "Mod/Part/App/TopoShapeVertexPy.h"
#include "Mod/Part/App/TopoShapeFacePy.h"
@@ -359,6 +361,8 @@ PyMOD_INIT_FUNC(Part)
Base::Interpreter().addType(&Part::GeometryIntExtensionPy ::Type,partModule,"GeometryIntExtension");
Base::Interpreter().addType(&Part::GeometryStringExtensionPy ::Type,partModule,"GeometryStringExtension");
Base::Interpreter().addType(&Part::GeometryBoolExtensionPy ::Type,partModule,"GeometryBoolExtension");
Base::Interpreter().addType(&Part::GeometryDoubleExtensionPy ::Type,partModule,"GeometryDoubleExtension");
#if PY_MAJOR_VERSION >= 3
static struct PyModuleDef BRepOffsetAPIDef = {
@@ -487,6 +491,8 @@ PyMOD_INIT_FUNC(Part)
Part::GeometryExtension ::init();
Part::GeometryIntExtension ::init();
Part::GeometryStringExtension ::init();
Part::GeometryBoolExtension ::init();
Part::GeometryDoubleExtension ::init();
Part::Geometry ::init();
Part::GeomPoint ::init();
Part::GeomCurve ::init();

View File

@@ -54,6 +54,8 @@ generate_from_xml(GeometryPy)
generate_from_xml(GeometryExtensionPy)
generate_from_xml(GeometryIntExtensionPy)
generate_from_xml(GeometryStringExtensionPy)
generate_from_xml(GeometryBoolExtensionPy)
generate_from_xml(GeometryDoubleExtensionPy)
generate_from_xml(GeometryCurvePy)
generate_from_xml(BoundedCurvePy)
generate_from_xml(TrimmedCurvePy)
@@ -220,6 +222,10 @@ SET(Python_SRCS
GeometryIntExtensionPyImp.cpp
GeometryStringExtensionPy.xml
GeometryStringExtensionPyImp.cpp
GeometryBoolExtensionPy.xml
GeometryBoolExtensionPyImp.cpp
GeometryDoubleExtensionPy.xml
GeometryDoubleExtensionPyImp.cpp
GeometryCurvePy.xml
GeometryCurvePyImp.cpp
BoundedCurvePy.xml

View File

@@ -0,0 +1,27 @@
<?xml version="1.0" encoding="UTF-8"?>
<GenerateModel xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="generateMetaModel_Module.xsd">
<PythonExport
Father="GeometryExtensionPy"
Name="GeometryBoolExtensionPy"
PythonName="Part.GeometryBoolExtension"
Twin="GeometryBoolExtension"
TwinPointer="GeometryBoolExtension"
Include="Mod/Part/App/GeometryDefaultExtension.h"
Namespace="Part"
FatherInclude="Mod/Part/App/GeometryExtensionPy.h"
FatherNamespace="Part"
Constructor="true">
<Documentation>
<Author Licence="LGPL" Name="Abdullah Tahiri" EMail="abdullah.tahiri.yo@gmail.com" />
<UserDocu>A GeometryExtension extending geometry objects with a boolean.</UserDocu>
</Documentation>
<Attribute Name="Value" ReadOnly="false">
<Documentation>
<UserDocu>
returns the value of the GeometryBoolExtension.
</UserDocu>
</Documentation>
<Parameter Name="Value" Type="Boolean"/>
</Attribute>
</PythonExport>
</GenerateModel>

View File

@@ -0,0 +1,104 @@
/***************************************************************************
* Copyright (c) 2019 Abdullah Tahiri <abdullah.tahiri.yo@gmail.com> *
* *
* 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 "GeometryDefaultExtension.h"
#include "GeometryBoolExtensionPy.h"
#include "GeometryBoolExtensionPy.cpp"
using namespace Part;
// returns a string which represents the object e.g. when printed in python
std::string GeometryBoolExtensionPy::representation(void) const
{
std::stringstream str;
long id = getGeometryBoolExtensionPtr()->getValue();
str << "<GeometryBoolExtension (" ;
if(getGeometryBoolExtensionPtr()->getName().size()>0)
str << "\'" << getGeometryBoolExtensionPtr()->getName() << "\', ";
str << (id==0?"False":"True") << ") >";
return str.str();
}
PyObject *GeometryBoolExtensionPy::PyMake(struct _typeobject *, PyObject *, PyObject *) // Python wrapper
{
// create a new instance of the python object and the Twin object
return new GeometryBoolExtensionPy(new GeometryBoolExtension);
}
// constructor method
int GeometryBoolExtensionPy::PyInit(PyObject* args, PyObject* /*kwd*/)
{
if (PyArg_ParseTuple(args, "")) {
// default extension
return 0;
}
PyErr_Clear();
PyObject* Id;
if (PyArg_ParseTuple(args, "O!", &PyBool_Type, &Id)) {
this->getGeometryBoolExtensionPtr()->setValue(PyObject_IsTrue(Id) ? true : false);
return 0;
}
PyErr_Clear();
char * pystr;
if (PyArg_ParseTuple(args, "O!s", &PyBool_Type, &Id, &pystr)) {
this->getGeometryBoolExtensionPtr()->setValue(PyObject_IsTrue(Id) ? true : false);
this->getGeometryBoolExtensionPtr()->setName(pystr);
return 0;
}
PyErr_SetString(PyExc_TypeError, "GeometryBoolExtension constructor accepts:\n"
"-- empty parameter list\n"
"-- Boolean\n"
"-- Boolean, string\n");
return -1;
}
Py::Boolean GeometryBoolExtensionPy::getValue(void) const
{
return Py::Boolean(this->getGeometryBoolExtensionPtr()->getValue());
}
void GeometryBoolExtensionPy::setValue(Py::Boolean value)
{
this->getGeometryBoolExtensionPtr()->setValue(value);
}
PyObject *GeometryBoolExtensionPy::getCustomAttributes(const char* /*attr*/) const
{
return 0;
}
int GeometryBoolExtensionPy::setCustomAttributes(const char* /*attr*/, PyObject* /*obj*/)
{
return 0;
}

View File

@@ -32,6 +32,8 @@
#include "GeometryStringExtensionPy.h"
#include "GeometryIntExtensionPy.h"
#include "GeometryBoolExtensionPy.h"
#include "GeometryDoubleExtensionPy.h"
using namespace Part;
@@ -121,4 +123,36 @@ PyObject * GeometryDefaultExtension<std::string>::getPyObject(void)
return new GeometryStringExtensionPy(new GeometryStringExtension(*this));
}
// ---------- GeometryBoolExtension ----------
TYPESYSTEM_SOURCE_TEMPLATE_T(Part::GeometryBoolExtension,Part::GeometryExtension)
template <>
PyObject * GeometryDefaultExtension<bool>::getPyObject(void)
{
return new GeometryBoolExtensionPy(new GeometryBoolExtension(*this));
}
template <>
void GeometryDefaultExtension<bool>::Restore(Base::XMLReader &reader)
{
restoreNameAttribute(reader);
value = (bool)reader.getAttributeAsInteger("value");
}
// ---------- GeometryDoubleExtension ----------
TYPESYSTEM_SOURCE_TEMPLATE_T(Part::GeometryDoubleExtension,Part::GeometryExtension)
template <>
PyObject * GeometryDefaultExtension<double>::getPyObject(void)
{
return new GeometryDoubleExtensionPy(new GeometryDoubleExtension(*this));
}
template <>
void GeometryDefaultExtension<double>::Restore(Base::XMLReader &reader)
{
restoreNameAttribute(reader);
value = reader.getAttributeAsFloat("value");
}

View File

@@ -94,14 +94,21 @@ namespace Part {
template <>
inline GeometryDefaultExtension<long>::GeometryDefaultExtension():value(0){}
template <>
inline GeometryDefaultExtension<double>::GeometryDefaultExtension():value(0.0f){}
// instantiate the types so that other translation units (python wrappers) can access template
//constructors other than the default.
template class GeometryDefaultExtension<long>;
template class GeometryDefaultExtension<std::string>;
template class GeometryDefaultExtension<bool>;
template class GeometryDefaultExtension<double>;
// Prefer alias to typedef item 9
using GeometryIntExtension = GeometryDefaultExtension<long>;
using GeometryStringExtension = GeometryDefaultExtension<std::string>;
using GeometryBoolExtension = GeometryDefaultExtension<bool>;
using GeometryDoubleExtension = GeometryDefaultExtension<double>;
}
#endif // PART_GEOMETRYDEFAULTEXTENSION_H

View File

@@ -0,0 +1,27 @@
<?xml version="1.0" encoding="UTF-8"?>
<GenerateModel xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="generateMetaModel_Module.xsd">
<PythonExport
Father="GeometryExtensionPy"
Name="GeometryDoubleExtensionPy"
PythonName="Part.GeometryDoubleExtension"
Twin="GeometryDoubleExtension"
TwinPointer="GeometryDoubleExtension"
Include="Mod/Part/App/GeometryDefaultExtension.h"
Namespace="Part"
FatherInclude="Mod/Part/App/GeometryExtensionPy.h"
FatherNamespace="Part"
Constructor="true">
<Documentation>
<Author Licence="LGPL" Name="Abdullah Tahiri" EMail="abdullah.tahiri.yo@gmail.com" />
<UserDocu>A GeometryExtension extending geometry objects with a double.</UserDocu>
</Documentation>
<Attribute Name="Value" ReadOnly="false">
<Documentation>
<UserDocu>
returns the value of the GeometryDoubleExtension.
</UserDocu>
</Documentation>
<Parameter Name="Value" Type="Float"/>
</Attribute>
</PythonExport>
</GenerateModel>

View File

@@ -0,0 +1,106 @@
/***************************************************************************
* Copyright (c) 2019 Abdullah Tahiri <abdullah.tahiri.yo@gmail.com> *
* *
* 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 "GeometryDefaultExtension.h"
#include "GeometryDoubleExtensionPy.h"
#include "GeometryDoubleExtensionPy.cpp"
using namespace Part;
// returns a string which represents the object e.g. when printed in python
std::string GeometryDoubleExtensionPy::representation(void) const
{
std::stringstream str;
double id = getGeometryDoubleExtensionPtr()->getValue();
str << "<GeometryDoubleExtension (" ;
if(getGeometryDoubleExtensionPtr()->getName().size()>0)
str << "\'" << getGeometryDoubleExtensionPtr()->getName() << "\', ";
str << id << ") >";
return str.str();
}
PyObject *GeometryDoubleExtensionPy::PyMake(struct _typeobject *, PyObject *, PyObject *) // Python wrapper
{
// create a new instance of the python object and the Twin object
return new GeometryDoubleExtensionPy(new GeometryDoubleExtension);
}
// constructor method
int GeometryDoubleExtensionPy::PyInit(PyObject* args, PyObject* /*kwd*/)
{
if (PyArg_ParseTuple(args, "")) {
// default extension
return 0;
}
PyErr_Clear();
double Id;
if (PyArg_ParseTuple(args, "d", &Id)) {
this->getGeometryDoubleExtensionPtr()->setValue(Id);
return 0;
}
PyErr_Clear();
char * pystr;
if (PyArg_ParseTuple(args, "ds", &Id,&pystr)) {
this->getGeometryDoubleExtensionPtr()->setValue(Id);
this->getGeometryDoubleExtensionPtr()->setName(pystr);
return 0;
}
PyErr_SetString(PyExc_TypeError, "GeometryDoubleExtension constructor accepts:\n"
"-- empty parameter list\n"
"-- double\n"
"-- double, string\n");
return -1;
}
Py::Float GeometryDoubleExtensionPy::getValue(void) const
{
return Py::Float(this->getGeometryDoubleExtensionPtr()->getValue());
}
void GeometryDoubleExtensionPy::setValue(Py::Float value)
{
this->getGeometryDoubleExtensionPtr()->setValue(float(value));
}
PyObject *GeometryDoubleExtensionPy::getCustomAttributes(const char* /*attr*/) const
{
return 0;
}
int GeometryDoubleExtensionPy::setCustomAttributes(const char* /*attr*/, PyObject* /*obj*/)
{
return 0;
}