Part: Standard geometry extension adding an integer value

This commit is contained in:
Abdullah Tahiri
2019-01-24 17:38:59 +01:00
committed by wmayer
parent 1e2c627f26
commit 7828c34ffe
6 changed files with 268 additions and 3 deletions

View File

@@ -57,6 +57,8 @@
#include "Part2DObject.h"
#include "CustomFeature.h"
#include "Geometry.h"
#include "GeometryExtension.h"
#include "GeometryIntExtension.h"
#include "Geometry2d.h"
#include "Mod/Part/App/TopoShapePy.h"
#include "Mod/Part/App/TopoShapeVertexPy.h"
@@ -330,8 +332,8 @@ PyMOD_INIT_FUNC(Part)
Base::Interpreter().addType(&Part::ArcPy ::Type,partModule,"Arc");
Base::Interpreter().addType(&Part::ArcOfCirclePy ::Type,partModule,"ArcOfCircle");
Base::Interpreter().addType(&Part::ArcOfEllipsePy ::Type,partModule,"ArcOfEllipse");
Base::Interpreter().addType(&Part::ArcOfParabolaPy ::Type,partModule,"ArcOfParabola");
Base::Interpreter().addType(&Part::ArcOfHyperbolaPy ::Type,partModule,"ArcOfHyperbola");
Base::Interpreter().addType(&Part::ArcOfParabolaPy ::Type,partModule,"ArcOfParabola");
Base::Interpreter().addType(&Part::ArcOfHyperbolaPy ::Type,partModule,"ArcOfHyperbola");
Base::Interpreter().addType(&Part::BezierCurvePy ::Type,partModule,"BezierCurve");
Base::Interpreter().addType(&Part::BSplineCurvePy ::Type,partModule,"BSplineCurve");
Base::Interpreter().addType(&Part::OffsetCurvePy ::Type,partModule,"OffsetCurve");
@@ -416,7 +418,7 @@ PyMOD_INIT_FUNC(Part)
Attacher::AttachEnginePlane ::init();
Attacher::AttachEngineLine ::init();
Attacher::AttachEnginePoint ::init();
Part::AttachExtension ::init();
Part::AttachExtensionPython ::init();
@@ -478,6 +480,7 @@ PyMOD_INIT_FUNC(Part)
// Geometry types
Part::GeometryExtension ::init();
Part::GeometryIntExtension ::init();
Part::Geometry ::init();
Part::GeomPoint ::init();
Part::GeomCurve ::init();

View File

@@ -52,6 +52,7 @@ generate_from_xml(ParabolaPy)
generate_from_xml(OffsetCurvePy)
generate_from_xml(GeometryPy)
generate_from_xml(GeometryExtensionPy)
generate_from_xml(GeometryIntExtensionPy)
generate_from_xml(GeometryCurvePy)
generate_from_xml(BoundedCurvePy)
generate_from_xml(TrimmedCurvePy)
@@ -214,6 +215,8 @@ SET(Python_SRCS
GeometryPyImp.cpp
GeometryExtensionPy.xml
GeometryExtensionPyImp.cpp
GeometryIntExtensionPy.xml
GeometryIntExtensionPyImp.cpp
GeometryCurvePy.xml
GeometryCurvePyImp.cpp
BoundedCurvePy.xml
@@ -345,6 +348,8 @@ SET(Part_SRCS
CrossSection.h
GeometryExtension.cpp
GeometryExtension.h
GeometryIntExtension.cpp
GeometryIntExtension.h
Geometry.cpp
Geometry.h
Geometry2d.cpp

View File

@@ -0,0 +1,84 @@
/***************************************************************************
* 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 <Base/Writer.h>
#include <Base/Reader.h>
#include <Base/Tools.h>
#include "GeometryIntExtension.h"
#include <Mod/Part/App/GeometryIntExtensionPy.h>
using namespace Part;
//---------- Geometry Extension
TYPESYSTEM_SOURCE(Part::GeometryIntExtension,Part::GeometryExtension)
GeometryIntExtension::GeometryIntExtension():id(0)
{
}
GeometryIntExtension::GeometryIntExtension(long cid):id(cid)
{
}
GeometryIntExtension::~GeometryIntExtension()
{
}
// Persistence implementer
unsigned int GeometryIntExtension::getMemSize (void) const
{
return sizeof(long int);
}
void GeometryIntExtension::Save(Base::Writer &writer) const
{
writer.Stream() << writer.ind() << "<GeoExtension type=\"" << this->getTypeId().getName()
<< "\" value=\"" << id << "\"/>" << std::endl;
}
void GeometryIntExtension::Restore(Base::XMLReader &reader)
{
id = reader.getAttributeAsInteger("value");
}
std::unique_ptr<Part::GeometryExtension> GeometryIntExtension::copy(void) const
{
std::unique_ptr<GeometryIntExtension> cpy = std::make_unique<GeometryIntExtension>();
cpy->id = this->id;
return std::move(cpy);
}
PyObject * GeometryIntExtension::getPyObject(void)
{
return new GeometryIntExtensionPy(new GeometryIntExtension(this->id));
}

View File

@@ -0,0 +1,54 @@
/***************************************************************************
* 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 *
* *
***************************************************************************/
#ifndef PART_GEOMETRYINTEXTENSION_H
#define PART_GEOMETRYINTEXTENSION_H
#include "GeometryExtension.h"
namespace Part {
class PartExport GeometryIntExtension: public Part::GeometryExtension
{
TYPESYSTEM_HEADER();
public:
GeometryIntExtension();
GeometryIntExtension(long cid);
virtual ~GeometryIntExtension();
// Persistence implementer ---------------------
virtual unsigned int getMemSize(void) const;
virtual void Save(Base::Writer &/*writer*/) const;
virtual void Restore(Base::XMLReader &/*reader*/);
virtual std::unique_ptr<Part::GeometryExtension> copy(void) const;
virtual PyObject *getPyObject(void);
public:
long int id;
};
}
#endif // PART_GEOMETRYINTEXTENSION_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="GeometryIntExtensionPy"
PythonName="Part.GeometryIntExtension"
Twin="GeometryIntExtension"
TwinPointer="GeometryIntExtension"
Include="Mod/Part/App/GeometryIntExtension.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 an int.</UserDocu>
</Documentation>
<Attribute Name="Value" ReadOnly="false">
<Documentation>
<UserDocu>
returns the value of the GeometryIntExtension.
</UserDocu>
</Documentation>
<Parameter Name="Value" Type="Long"/>
</Attribute>
</PythonExport>
</GenerateModel>

View File

@@ -0,0 +1,92 @@
/***************************************************************************
* 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 "GeometryIntExtension.h"
#include "GeometryIntExtensionPy.h"
#include "GeometryIntExtensionPy.cpp"
using namespace Part;
// returns a string which represents the object e.g. when printed in python
std::string GeometryIntExtensionPy::representation(void) const
{
std::stringstream str;
long id = getGeometryIntExtensionPtr()->id;
str << "<GeometryIntExtension (" << id << ") >";
return str.str();
}
PyObject *GeometryIntExtensionPy::PyMake(struct _typeobject *, PyObject *, PyObject *) // Python wrapper
{
// create a new instance of PointPy and the Twin object
return new GeometryIntExtensionPy(new GeometryIntExtension);
}
// constructor method
int GeometryIntExtensionPy::PyInit(PyObject* args, PyObject* /*kwd*/)
{
if (PyArg_ParseTuple(args, "")) {
// default extension
return 0;
}
PyErr_Clear();
int Id;
if (PyArg_ParseTuple(args, "i", &Id)) {
this->getGeometryIntExtensionPtr()->id=Id;
return 0;
}
PyErr_SetString(PyExc_TypeError, "GeometryIntExtension constructor accepts:\n"
"-- empty parameter list\n"
"-- int\n");
return -1;
}
Py::Long GeometryIntExtensionPy::getValue(void) const
{
return Py::Long(this->getGeometryIntExtensionPtr()->id);
}
void GeometryIntExtensionPy::setValue(Py::Long value)
{
this->getGeometryIntExtensionPtr()->id=long(value);
}
PyObject *GeometryIntExtensionPy::getCustomAttributes(const char* /*attr*/) const
{
return 0;
}
int GeometryIntExtensionPy::setCustomAttributes(const char* /*attr*/, PyObject* /*obj*/)
{
return 0;
}