diff --git a/src/Mod/Part/App/GeometryDefaultExtension.h b/src/Mod/Part/App/GeometryDefaultExtension.h index d8640eab30..5f983610e7 100644 --- a/src/Mod/Part/App/GeometryDefaultExtension.h +++ b/src/Mod/Part/App/GeometryDefaultExtension.h @@ -34,7 +34,7 @@ namespace Part { { TYPESYSTEM_HEADER(); public: - GeometryDefaultExtension() = default; + inline GeometryDefaultExtension(); GeometryDefaultExtension(const T& val, std::string name = std::string()); virtual ~GeometryDefaultExtension() = default; @@ -63,7 +63,8 @@ namespace Part { // // Warnings: // - The default constructor relies on the default constructor of T for initialisation. Built-in types - // so constructed will be uninitialised. Use the specific constructor from a T to initiliase it. + // so constructed will be uninitialised. Use the specific constructor from a T to initiliase it. Note + // that the default constructor is required by the type system (see TYPESYSTEM_SOURCE_TEMPLATE_T). // // Default assumptions: // - T can be constructed from T @@ -85,6 +86,19 @@ namespace Part { // 5. Provide specialisations if your type does not meet the assumptions above (e.g. for serialisation) (cpp file) // 6. Register your type and corresponding python type in AppPart.cpp + template + inline GeometryDefaultExtension::GeometryDefaultExtension(){ } + + // Specialised constructors go here so that specialisation is before the template instantiation + // Specialised default constructors are inline, because a full specialisation otherwise shall go in the cpp file, but there it would be after the template instantiation. + template <> + inline GeometryDefaultExtension::GeometryDefaultExtension():value(0){} + + // instantiate the types so that other translation units (python wrappers) can access template + //constructors other than the default. + template class GeometryDefaultExtension; + template class GeometryDefaultExtension; + // Prefer alias to typedef item 9 using GeometryIntExtension = GeometryDefaultExtension; using GeometryStringExtension = GeometryDefaultExtension; diff --git a/src/Mod/Part/App/GeometryIntExtensionPyImp.cpp b/src/Mod/Part/App/GeometryIntExtensionPyImp.cpp index 872335ce3e..f05930ea1c 100644 --- a/src/Mod/Part/App/GeometryIntExtensionPyImp.cpp +++ b/src/Mod/Part/App/GeometryIntExtensionPyImp.cpp @@ -48,7 +48,7 @@ std::string GeometryIntExtensionPy::representation(void) const PyObject *GeometryIntExtensionPy::PyMake(struct _typeobject *, PyObject *, PyObject *) // Python wrapper { - // create a new instance of PointPy and the Twin object + // create a new instance of the python object and the Twin object return new GeometryIntExtensionPy(new GeometryIntExtension); } @@ -68,11 +68,18 @@ int GeometryIntExtensionPy::PyInit(PyObject* args, PyObject* /*kwd*/) return 0; } - + PyErr_Clear(); + char * pystr; + if (PyArg_ParseTuple(args, "ls", &Id,&pystr)) { + this->getGeometryIntExtensionPtr()->setValue(Id); + this->getGeometryIntExtensionPtr()->setName(pystr); + return 0; + } PyErr_SetString(PyExc_TypeError, "GeometryIntExtension constructor accepts:\n" "-- empty parameter list\n" - "-- long int\n"); + "-- long int\n" + "-- long int, string\n"); return -1; } diff --git a/src/Mod/Part/App/GeometryStringExtensionPyImp.cpp b/src/Mod/Part/App/GeometryStringExtensionPyImp.cpp index 3b4eb41d89..9cbd54df29 100644 --- a/src/Mod/Part/App/GeometryStringExtensionPyImp.cpp +++ b/src/Mod/Part/App/GeometryStringExtensionPyImp.cpp @@ -50,7 +50,7 @@ std::string GeometryStringExtensionPy::representation(void) const PyObject *GeometryStringExtensionPy::PyMake(struct _typeobject *, PyObject *, PyObject *) // Python wrapper { - // create a new instance of PointPy and the Twin object + // create a new instance of the python object and the Twin object return new GeometryStringExtensionPy(new GeometryStringExtension); } @@ -70,11 +70,19 @@ int GeometryStringExtensionPy::PyInit(PyObject* args, PyObject* /*kwd*/) return 0; } + PyErr_Clear(); + char * pystr; + if (PyArg_ParseTuple(args, "ss", &pstr, &pystr)) { + this->getGeometryStringExtensionPtr()->setValue(pstr); + this->getGeometryStringExtensionPtr()->setName(pystr); + return 0; + } PyErr_SetString(PyExc_TypeError, "GeometryStringExtension constructor accepts:\n" "-- empty parameter list\n" - "-- string\n"); + "-- string\n" + "-- string, string\n"); return -1; }