diff --git a/src/Mod/Part/App/AppPart.cpp b/src/Mod/Part/App/AppPart.cpp index 1762b99663..2374b5cc93 100644 --- a/src/Mod/Part/App/AppPart.cpp +++ b/src/Mod/Part/App/AppPart.cpp @@ -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(); diff --git a/src/Mod/Part/App/CMakeLists.txt b/src/Mod/Part/App/CMakeLists.txt index d7dc2ffb9b..e385266738 100644 --- a/src/Mod/Part/App/CMakeLists.txt +++ b/src/Mod/Part/App/CMakeLists.txt @@ -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 diff --git a/src/Mod/Part/App/GeometryIntExtension.cpp b/src/Mod/Part/App/GeometryIntExtension.cpp new file mode 100644 index 0000000000..da9af3f9fc --- /dev/null +++ b/src/Mod/Part/App/GeometryIntExtension.cpp @@ -0,0 +1,84 @@ +/*************************************************************************** + * Copyright (c) 2019 Abdullah Tahiri * + * * + * 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 + +#include "GeometryIntExtension.h" + +#include + +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() << "getTypeId().getName() + << "\" value=\"" << id << "\"/>" << std::endl; +} + +void GeometryIntExtension::Restore(Base::XMLReader &reader) +{ + id = reader.getAttributeAsInteger("value"); +} + +std::unique_ptr GeometryIntExtension::copy(void) const +{ + std::unique_ptr cpy = std::make_unique(); + + cpy->id = this->id; + + return std::move(cpy); +} + +PyObject * GeometryIntExtension::getPyObject(void) +{ + return new GeometryIntExtensionPy(new GeometryIntExtension(this->id)); +} diff --git a/src/Mod/Part/App/GeometryIntExtension.h b/src/Mod/Part/App/GeometryIntExtension.h new file mode 100644 index 0000000000..22fcbb1dcd --- /dev/null +++ b/src/Mod/Part/App/GeometryIntExtension.h @@ -0,0 +1,54 @@ +/*************************************************************************** + * Copyright (c) 2019 Abdullah Tahiri * + * * + * 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 copy(void) const; + + virtual PyObject *getPyObject(void); + +public: + long int id; +}; + +} + +#endif // PART_GEOMETRYINTEXTENSION_H diff --git a/src/Mod/Part/App/GeometryIntExtensionPy.xml b/src/Mod/Part/App/GeometryIntExtensionPy.xml new file mode 100644 index 0000000000..4709502668 --- /dev/null +++ b/src/Mod/Part/App/GeometryIntExtensionPy.xml @@ -0,0 +1,27 @@ + + + + + + A GeometryExtension extending geometry objects with an int. + + + + + returns the value of the GeometryIntExtension. + + + + + + diff --git a/src/Mod/Part/App/GeometryIntExtensionPyImp.cpp b/src/Mod/Part/App/GeometryIntExtensionPyImp.cpp new file mode 100644 index 0000000000..82e4001dc5 --- /dev/null +++ b/src/Mod/Part/App/GeometryIntExtensionPyImp.cpp @@ -0,0 +1,92 @@ +/*************************************************************************** + * Copyright (c) 2019 Abdullah Tahiri * + * * + * 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 << ""; + 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; +}