Part: Geometry Python interface to get/set an extension
This commit is contained in:
@@ -51,6 +51,7 @@ generate_from_xml(ArcOfHyperbolaPy)
|
||||
generate_from_xml(ParabolaPy)
|
||||
generate_from_xml(OffsetCurvePy)
|
||||
generate_from_xml(GeometryPy)
|
||||
generate_from_xml(GeometryExtensionPy)
|
||||
generate_from_xml(GeometryCurvePy)
|
||||
generate_from_xml(BoundedCurvePy)
|
||||
generate_from_xml(TrimmedCurvePy)
|
||||
@@ -211,6 +212,8 @@ SET(Python_SRCS
|
||||
OffsetCurvePyImp.cpp
|
||||
GeometryPy.xml
|
||||
GeometryPyImp.cpp
|
||||
GeometryExtensionPy.xml
|
||||
GeometryExtensionPyImp.cpp
|
||||
GeometryCurvePy.xml
|
||||
GeometryCurvePyImp.cpp
|
||||
BoundedCurvePy.xml
|
||||
|
||||
@@ -53,6 +53,16 @@ It describes the common behavior of these objects when:
|
||||
<UserDocu>Create a clone of this geometry with the same Tag</UserDocu>
|
||||
</Documentation>
|
||||
</Methode>
|
||||
<Methode Name="getExtension" Const="true">
|
||||
<Documentation>
|
||||
<UserDocu>Gets a geometry extension of the indicated type.</UserDocu>
|
||||
</Documentation>
|
||||
</Methode>
|
||||
<Methode Name="setExtension" Const="false">
|
||||
<Documentation>
|
||||
<UserDocu>Sets a geometry extension of the indicated type.</UserDocu>
|
||||
</Documentation>
|
||||
</Methode>
|
||||
<Attribute Name="Construction" ReadOnly="false">
|
||||
<Documentation>
|
||||
<UserDocu>Defines this geometry as a construction one which
|
||||
|
||||
@@ -51,6 +51,7 @@
|
||||
#include "GeometryPy.h"
|
||||
#include "GeometryPy.cpp"
|
||||
|
||||
#include "GeometryExtensionPy.h"
|
||||
#include "TopoShape.h"
|
||||
#include "TopoShapePy.h"
|
||||
|
||||
@@ -239,6 +240,57 @@ PyObject* GeometryPy::clone(PyObject *args)
|
||||
return cpy;
|
||||
}
|
||||
|
||||
PyObject* GeometryPy::setExtension(PyObject *args)
|
||||
{
|
||||
PyObject* o;
|
||||
if (PyArg_ParseTuple(args, "O!", &(GeometryExtensionPy::Type),&o)) {
|
||||
Part::GeometryExtension * ext;
|
||||
ext = static_cast<GeometryExtensionPy *>(o)->getGeometryExtensionPtr();
|
||||
|
||||
std::unique_ptr<GeometryExtension> cpy = ext->copy(); // allocate new extension in memory
|
||||
|
||||
this->getGeometryPtr()->setExtension(std::move(cpy));
|
||||
Py_Return;
|
||||
}
|
||||
|
||||
PyErr_SetString(PartExceptionOCCError, "A geometry extension object was expected");
|
||||
return 0;
|
||||
}
|
||||
|
||||
PyObject* GeometryPy::getExtension(PyObject *args)
|
||||
{
|
||||
char* o;
|
||||
if (PyArg_ParseTuple(args, "s", &o)) {
|
||||
|
||||
Base::Type type = Base::Type::fromName(o);
|
||||
|
||||
if(type != Base::Type::badType()) {
|
||||
try {
|
||||
const std::weak_ptr<GeometryExtension> ext = this->getGeometryPtr()->getExtension(type);
|
||||
|
||||
std::unique_ptr<GeometryExtension> cext = ext.lock()->copy();
|
||||
|
||||
GeometryExtension * pcext = cext.release();
|
||||
|
||||
return pcext->getPyObject();
|
||||
}
|
||||
catch(Base::ValueError e) {
|
||||
PyErr_SetString(PartExceptionOCCError, e.what());
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
PyErr_SetString(PartExceptionOCCError, "Exception type does not exist");
|
||||
return 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
PyErr_SetString(PartExceptionOCCError, "A string with the name of the geometry extension type was expected");
|
||||
return 0;
|
||||
}
|
||||
|
||||
Py::Boolean GeometryPy::getConstruction(void) const
|
||||
{
|
||||
return Py::Boolean(getGeometryPtr()->Construction);
|
||||
|
||||
@@ -36,6 +36,7 @@ set(Sketcher_LIBS
|
||||
|
||||
generate_from_xml(SketchObjectSFPy)
|
||||
generate_from_xml(SketchObjectPy)
|
||||
generate_from_xml(SketchGeometryExtensionPy)
|
||||
generate_from_xml(ConstraintPy)
|
||||
generate_from_xml(SketchPy)
|
||||
|
||||
@@ -71,6 +72,8 @@ SET(Python_SRCS
|
||||
SketchObjectSFPyImp.cpp
|
||||
SketchObjectPy.xml
|
||||
SketchObjectPyImp.cpp
|
||||
SketchGeometryExtensionPy.xml
|
||||
SketchGeometryExtensionPyImp.cpp
|
||||
ConstraintPyImp.cpp
|
||||
ConstraintPy.xml
|
||||
SketchPy.xml
|
||||
|
||||
@@ -80,6 +80,7 @@
|
||||
#include "SketchObject.h"
|
||||
#include "Sketch.h"
|
||||
#include <Mod/Sketcher/App/SketchObjectPy.h>
|
||||
#include <Mod/Sketcher/App/SketchGeometryExtensionPy.h>
|
||||
|
||||
|
||||
#undef DEBUG
|
||||
@@ -92,6 +93,16 @@ using namespace Base;
|
||||
|
||||
TYPESYSTEM_SOURCE(Sketcher::SketchGeometryExtension,Part::GeometryExtension)
|
||||
|
||||
SketchGeometryExtension::SketchGeometryExtension():id(0)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
SketchGeometryExtension::SketchGeometryExtension(long cid):id(cid)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
SketchGeometryExtension::~SketchGeometryExtension()
|
||||
{
|
||||
}
|
||||
@@ -125,7 +136,7 @@ std::unique_ptr<Part::GeometryExtension> SketchGeometryExtension::copy(void) con
|
||||
|
||||
PyObject * SketchGeometryExtension::getPyObject(void)
|
||||
{
|
||||
return 0;
|
||||
return new SketchGeometryExtensionPy(new SketchGeometryExtension(this->id));
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -45,6 +45,8 @@ class SketcherExport SketchGeometryExtension : public Part::GeometryExtension
|
||||
{
|
||||
TYPESYSTEM_HEADER();
|
||||
public:
|
||||
SketchGeometryExtension();
|
||||
SketchGeometryExtension(long cid);
|
||||
virtual ~SketchGeometryExtension();
|
||||
|
||||
// Persistence implementer ---------------------
|
||||
|
||||
Reference in New Issue
Block a user