Sketcher: Geometry Facade interface for Geometry and SketchGeometryExtension

This commit is contained in:
Abdullah Tahiri
2020-10-28 17:44:59 +01:00
committed by abdullahtahiriyo
parent 7bfec92bdf
commit 0fd808dfc1
7 changed files with 847 additions and 0 deletions

View File

@@ -38,6 +38,7 @@ generate_from_xml(SketchObjectSFPy)
generate_from_xml(SketchObjectPy)
generate_from_xml(SketchGeometryExtensionPy)
generate_from_xml(ExternalGeometryExtensionPy)
generate_from_xml(GeometryFacadePy)
generate_from_xml(ConstraintPy)
generate_from_xml(SketchPy)
@@ -69,6 +70,8 @@ SET(Datatypes_SRCS
Constraint.h
Sketch.cpp
Sketch.h
GeometryFacade.cpp
GeometryFacade.h
)
SOURCE_GROUP("Datatypes" FILES ${Datatypes_SRCS})
@@ -81,6 +84,8 @@ SET(Python_SRCS
SketchGeometryExtensionPyImp.cpp
ExternalGeometryExtensionPy.xml
ExternalGeometryExtensionPyImp.cpp
GeometryFacadePy.xml
GeometryFacadePyImp.cpp
ConstraintPyImp.cpp
ConstraintPy.xml
SketchPy.xml

View File

@@ -0,0 +1,107 @@
/***************************************************************************
* Copyright (c) 2020 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"
#ifndef _PreComp_
#endif
#include "GeometryFacade.h"
#include <Base/Console.h> // Only for Debug - To be removed
#include <Base/Exception.h>
#include <boost/uuid/uuid_io.hpp>
#include "GeometryFacadePy.h"
using namespace Sketcher;
TYPESYSTEM_SOURCE(Sketcher::GeometryFacade,Part::GeometryExtension)
GeometryFacade::GeometryFacade(): Geo(nullptr), SketchGeoExtension(nullptr)
{
}
GeometryFacade::GeometryFacade(const Part::Geometry * geometry)
: Geo(geometry)
{
if(geometry != nullptr)
initExtension();
else
THROWM(Base::ValueError, "GeometryFacade initialized with Geometry null pointer");
}
std::unique_ptr<GeometryFacade> GeometryFacade::getFacade(Part::Geometry * geometry)
{
return std::unique_ptr<GeometryFacade>(new GeometryFacade(geometry));
//return std::make_unique<GeometryFacade>(geometry); // make_unique has no access to private constructor
}
std::unique_ptr<const GeometryFacade> GeometryFacade::getFacade(const Part::Geometry * geometry)
{
return std::unique_ptr<const GeometryFacade>(new GeometryFacade(geometry));
//return std::make_unique<const GeometryFacade>(geometry); // make_unique has no access to private constructor
}
void GeometryFacade::setGeometry(Part::Geometry *geometry)
{
Geo = geometry;
if(geometry != nullptr)
initExtension();
else
THROWM(Base::ValueError, "GeometryFacade initialized with Geometry null pointer");
}
void GeometryFacade::initExtension()
{
if(!Geo->hasExtension(SketchGeometryExtension::getClassTypeId())) {
getGeo()->setExtension(std::make_unique<SketchGeometryExtension>()); // Create getExtension
Base::Console().Warning("%s\nSketcher Geometry without Extension: %s \n", boost::uuids::to_string(Geo->getTag()).c_str());
}
SketchGeoExtension =
std::static_pointer_cast<const SketchGeometryExtension>(
(Geo->getExtension(SketchGeometryExtension::getClassTypeId())).lock()
);
}
void GeometryFacade::initExtension() const
{
if(!Geo->hasExtension(SketchGeometryExtension::getClassTypeId()))
THROWM(Base::ValueError, "GeometryConstFacade for const::Geometry without SketchGeometryExtension");
auto ext = std::static_pointer_cast<const SketchGeometryExtension>(Geo->getExtension(SketchGeometryExtension::getClassTypeId()).lock());
const_cast<GeometryFacade *>(this)->SketchGeoExtension = ext;
}
PyObject * GeometryFacade::getPyObject(void)
{
return new GeometryFacadePy(new GeometryFacade(this->Geo));
}

View File

@@ -0,0 +1,133 @@
/***************************************************************************
* Copyright (c) 2020 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 SKETCHER_GEOMETRYFACADE_H
#define SKETCHER_GEOMETRYFACADE_H
#include <Base/BaseClass.h>
#include <Base/Console.h> // Only for Debug - To be removed
#include <boost/uuid/uuid_io.hpp>
#include <Mod/Part/App/Geometry.h>
#include <Mod/Sketcher/App/SketchGeometryExtension.h>
namespace Sketcher
{
// This class is a Facade to handle geometry and sketcher geometry extensions with a single sketcher specific interface
//
//
//
// It is intended to have a separate type (not being a Geometry type).
// it is intended to have the relevant interface for the sketcher only
// It is intended to work on borrowed memory allocation.
class SketcherExport GeometryFacade : public Base::BaseClass, ISketchGeometryExtension
{
TYPESYSTEM_HEADER_WITH_OVERRIDE();
private:
GeometryFacade(const Part::Geometry * geometry);
public:
GeometryFacade(); // As TYPESYSTEM requirement for Python object construction
public: // Factory methods
static std::unique_ptr<GeometryFacade> getFacade(Part::Geometry * geometry);
static std::unique_ptr<const GeometryFacade> getFacade(const Part::Geometry * geometry);
public:
void setGeometry(Part::Geometry *geometry);
// Geometry Extension Interface
inline virtual long getId() const override {return getGeoExt()->getId();}
virtual void setId(long id) override {getGeoExt()->setId(id);}
// Geometry Extension Information
inline const std::string &getExtensionName () const {return SketchGeoExtension->getName();}
// Geometry Element
template < typename GeometryT = Part::Geometry,
typename = typename std::enable_if<
std::is_base_of<Part::Geometry, typename std::decay<GeometryT>::type>::value
>::type
>
GeometryT * getGeometry() {return dynamic_cast<GeometryT *>(const_cast<GeometryT *>(Geo));}
// Geometry Element
template < typename GeometryT = Part::Geometry,
typename = typename std::enable_if<
std::is_base_of<Part::Geometry, typename std::decay<GeometryT>::type>::value
>::type
>
GeometryT * getGeometry() const {return dynamic_cast<GeometryT *>(Geo);}
virtual PyObject *getPyObject(void) override;
// Geometry Interface
TopoDS_Shape toShape() const {return getGeo()->toShape();};
const Handle(Geom_Geometry)& handle() const {return getGeo()->handle();};
Part::Geometry *copy(void) const {return getGeo()->copy();};
Part::Geometry *clone(void) const {return getGeo()->clone();};
inline bool getConstruction(void) const {return getGeo()->getConstruction();};
inline void setConstruction(bool construction) {getGeo()->setConstruction(construction);};
boost::uuids::uuid getTag() const {return getGeo()->getTag();};
std::vector<std::weak_ptr<const Part::GeometryExtension>> getExtensions() const {return getGeo()->getExtensions();};
bool hasExtension(Base::Type type) const {return getGeo()->hasExtension(type);};
bool hasExtension(std::string name) const {return getGeo()->hasExtension(name);};
std::weak_ptr<const Part::GeometryExtension> getExtension(Base::Type type) const {return getGeo()->getExtension(type);};
std::weak_ptr<const Part::GeometryExtension> getExtension(std::string name) const {return getGeo()->getExtension(name);};
void setExtension(std::unique_ptr<Part::GeometryExtension> &&geo) {return getGeo()->setExtension(std::move(geo));};
void deleteExtension(Base::Type type) {return getGeo()->deleteExtension(type);};
void deleteExtension(std::string name) {return getGeo()->deleteExtension(name);};
void mirror(Base::Vector3d point) {return getGeo()->mirror(point);};
void mirror(Base::Vector3d point, Base::Vector3d dir) {return getGeo()->mirror(point, dir);};
void rotate(Base::Placement plm) {return getGeo()->rotate(plm);};
void scale(Base::Vector3d vec, double scale) {return getGeo()->scale(vec, scale);};
void transform(Base::Matrix4D mat) {return getGeo()->transform(mat);};
void translate(Base::Vector3d vec) {return getGeo()->translate(vec);};
private:
void initExtension(void);
void initExtension(void) const;
const Part::Geometry * getGeo(void) const {return Geo;}
Part::Geometry * getGeo(void) {return const_cast<Part::Geometry *>(Geo);}
std::shared_ptr<const SketchGeometryExtension> getGeoExt(void) const {return SketchGeoExtension;}
std::shared_ptr<SketchGeometryExtension> getGeoExt (void) {return std::const_pointer_cast<SketchGeometryExtension>(SketchGeoExtension);}
private:
const Part::Geometry * Geo;
std::shared_ptr<const SketchGeometryExtension> SketchGeoExtension;
};
} //namespace Sketcher
#endif // SKETCHER_GEOMETRYFACADE_H

View File

@@ -0,0 +1,111 @@
<?xml version="1.0" encoding="UTF-8"?>
<GenerateModel xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="generateMetaModel_Module.xsd">
<PythonExport
Father="BaseClassPy"
Name="GeometryFacadePy"
PythonName="Sketcher.GeometryFacade"
Twin="GeometryFacade"
TwinPointer="GeometryFacade"
Include="Mod/Sketcher/App/GeometryFacade.h"
Namespace="Sketcher"
FatherInclude="Base/BaseClassPy.h"
FatherNamespace="Base"
Constructor="true">
<Documentation>
<Author Licence="LGPL" Name="Abdullah Tahiri" EMail="abdullah.tahiri.yo@gmail.com" />
<UserDocu>Describes a GeometryFacade</UserDocu>
</Documentation>
<Attribute Name="Id" ReadOnly="false">
<Documentation>
<UserDocu>
returns the Id of the SketchGeometryExtension.
</UserDocu>
</Documentation>
<Parameter Name="Id" Type="Long"/>
</Attribute>
<Methode Name="mirror">
<Documentation>
<UserDocu>Performs the symmetrical transformation of this geometric object</UserDocu>
</Documentation>
</Methode>
<Methode Name="rotate">
<Documentation>
<UserDocu>Rotates this geometric object at angle Ang (in radians) about axis</UserDocu>
</Documentation>
</Methode>
<Methode Name="scale">
<Documentation>
<UserDocu>Applies a scaling transformation on this geometric object with a center and scaling factor</UserDocu>
</Documentation>
</Methode>
<Methode Name="transform">
<Documentation>
<UserDocu>Applies a transformation to this geometric object</UserDocu>
</Documentation>
</Methode>
<Methode Name="translate">
<Documentation>
<UserDocu>Translates this geometric object</UserDocu>
</Documentation>
</Methode>
<Methode Name="hasExtensionOfType" Const="true">
<Documentation>
<UserDocu>Returns a boolean indicating whether a geometry extension of the type indicated as a string exists.</UserDocu>
</Documentation>
</Methode>
<Methode Name="hasExtensionOfName" Const="true">
<Documentation>
<UserDocu>Returns a boolean indicating whether a geometry extension with the name indicated as a string exists.</UserDocu>
</Documentation>
</Methode>
<Methode Name="getExtensionOfType" Const="true">
<Documentation>
<UserDocu>Gets the first geometry extension of the type indicated by the string.</UserDocu>
</Documentation>
</Methode>
<Methode Name="getExtensionOfName" Const="true">
<Documentation>
<UserDocu>Gets the first geometry extension of the name indicated by the string.</UserDocu>
</Documentation>
</Methode>
<Methode Name="setExtension" Const="false">
<Documentation>
<UserDocu>Sets a geometry extension of the indicated type.</UserDocu>
</Documentation>
</Methode>
<Methode Name="deleteExtensionOfType" Const="false">
<Documentation>
<UserDocu>Deletes all extensions of the indicated type.</UserDocu>
</Documentation>
</Methode>
<Methode Name="deleteExtensionOfName" Const="false">
<Documentation>
<UserDocu>Deletes all extensions of the indicated name.</UserDocu>
</Documentation>
</Methode>
<Methode Name="getExtensions" Const="true">
<Documentation>
<UserDocu>Returns a list with information about the geometry extensions.</UserDocu>
</Documentation>
</Methode>
<Attribute Name="Construction" ReadOnly="false">
<Documentation>
<UserDocu>Defines this geometry as a construction one which
means that it is not part of a later built shape.</UserDocu>
</Documentation>
<Parameter Name="Construction" Type="Boolean"/>
</Attribute>
<Attribute Name="Tag" ReadOnly="true">
<Documentation>
<UserDocu>Gives the tag of the geometry as string.</UserDocu>
</Documentation>
<Parameter Name="Tag" Type="String"/>
</Attribute>
<Attribute Name="Geometry" ReadOnly="false">
<Documentation>
<UserDocu>Gives the tag of the geometry as string.</UserDocu>
</Documentation>
<Parameter Name="Geometry" Type="Object"/>
</Attribute>
</PythonExport>
</GenerateModel>

View File

@@ -0,0 +1,441 @@
/***************************************************************************
* 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"
//#ifndef _PreComp_
//# include <gp.hxx>
//#endif
#include <Base/GeometryPyCXX.h>
#include <Base/Matrix.h>
#include <Base/MatrixPy.h>
#include <Base/Vector3D.h>
#include <Base/VectorPy.h>
#include <Base/Rotation.h>
#include <Base/Placement.h>
#include <Base/PlacementPy.h>
#include <Mod/Part/App/OCCError.h>
#include <Mod/Part/App/Geometry.h>
#include <Mod/Part/App/GeometryPy.h>
#include <Mod/Part/App/GeometryExtensionPy.h>
#include "SketchObject.h"
#include "GeometryFacadePy.h"
#include "GeometryFacadePy.cpp"
using namespace Sketcher;
// returns a string which represents the object e.g. when printed in python
std::string GeometryFacadePy::representation(void) const
{
std::stringstream str;
str << "<GeometryFacade ( Extension(";
if(getGeometryFacadePtr()->getExtensionName().size()>0)
str << "\'" << getGeometryFacadePtr()->getExtensionName() << "\', ";
str << "Id=";
str << getGeometryFacadePtr()->getId() << ") >";
return str.str();
}
PyObject *GeometryFacadePy::PyMake(struct _typeobject *, PyObject *, PyObject *) // Python wrapper
{
// create a new instance of PointPy and the Twin object
return new GeometryFacadePy(new GeometryFacade());
}
// constructor method
int GeometryFacadePy::PyInit(PyObject* args, PyObject* /*kwd*/)
{
PyObject *object;
if (PyArg_ParseTuple(args,"O!",&(Part::GeometryPy::Type), &object)) {
Part::Geometry * geo = static_cast<Part::GeometryPy *>(object)->getGeometryPtr();
getGeometryFacadePtr()->setGeometry(geo->clone());
return 0;
}
PyErr_SetString(PyExc_TypeError, "Sketcher::GeometryFacade constructor accepts:\n"
"-- Part.Geometry\n"
);
return -1;
}
Py::Long GeometryFacadePy::getId(void) const
{
return Py::Long(this->getGeometryFacadePtr()->getId());
}
void GeometryFacadePy::setId(Py::Long Id)
{
this->getGeometryFacadePtr()->setId(long(Id));
}
PyObject* GeometryFacadePy::mirror(PyObject *args)
{
PyObject* o;
if (PyArg_ParseTuple(args, "O!", &(Base::VectorPy::Type),&o)) {
Base::Vector3d vec = static_cast<Base::VectorPy*>(o)->value();
getGeometryFacadePtr()->mirror(vec);
Py_Return;
}
PyErr_Clear();
PyObject* axis;
if (PyArg_ParseTuple(args, "O!O!", &(Base::VectorPy::Type),&o,
&(Base::VectorPy::Type),&axis)) {
Base::Vector3d pnt = static_cast<Base::VectorPy*>(o)->value();
Base::Vector3d dir = static_cast<Base::VectorPy*>(axis)->value();
getGeometryFacadePtr()->mirror(pnt, dir);
Py_Return;
}
PyErr_SetString(Part::PartExceptionOCCError, "either a point (vector) or axis (vector, vector) must be given");
return 0;
}
PyObject* GeometryFacadePy::rotate(PyObject *args)
{
PyObject* o;
if (!PyArg_ParseTuple(args, "O!", &(Base::PlacementPy::Type),&o))
return 0;
Base::Placement* plm = static_cast<Base::PlacementPy*>(o)->getPlacementPtr();
getGeometryFacadePtr()->rotate(*plm);
Py_Return;
}
PyObject* GeometryFacadePy::scale(PyObject *args)
{
PyObject* o;
double scale;
Base::Vector3d vec;
if (PyArg_ParseTuple(args, "O!d", &(Base::VectorPy::Type),&o, &scale)) {
vec = static_cast<Base::VectorPy*>(o)->value();
getGeometryFacadePtr()->scale(vec, scale);
Py_Return;
}
PyErr_Clear();
if (PyArg_ParseTuple(args, "O!d", &PyTuple_Type,&o, &scale)) {
vec = Base::getVectorFromTuple<double>(o);
getGeometryFacadePtr()->scale(vec, scale);
Py_Return;
}
PyErr_SetString(Part::PartExceptionOCCError, "either vector or tuple and float expected");
return 0;
}
PyObject* GeometryFacadePy::transform(PyObject *args)
{
PyObject* o;
if (!PyArg_ParseTuple(args, "O!", &(Base::MatrixPy::Type),&o))
return 0;
Base::Matrix4D mat = static_cast<Base::MatrixPy*>(o)->value();
getGeometryFacadePtr()->transform(mat);
Py_Return;
}
PyObject* GeometryFacadePy::translate(PyObject *args)
{
PyObject* o;
Base::Vector3d vec;
if (PyArg_ParseTuple(args, "O!", &(Base::VectorPy::Type),&o)) {
vec = static_cast<Base::VectorPy*>(o)->value();
getGeometryFacadePtr()->translate(vec);
Py_Return;
}
PyErr_Clear();
if (PyArg_ParseTuple(args, "O!", &PyTuple_Type,&o)) {
vec = Base::getVectorFromTuple<double>(o);
getGeometryFacadePtr()->translate(vec);
Py_Return;
}
PyErr_SetString(Part::PartExceptionOCCError, "either vector or tuple expected");
return 0;
}
PyObject* GeometryFacadePy::setExtension(PyObject *args)
{
PyObject* o;
if (PyArg_ParseTuple(args, "O!", &(Part::GeometryExtensionPy::Type),&o)) {
Part::GeometryExtension * ext;
ext = static_cast<Part::GeometryExtensionPy *>(o)->getGeometryExtensionPtr();
// make copy of Python managed memory and wrap it in smart pointer
auto cpy = ext->copy();
this->getGeometryFacadePtr()->setExtension(std::move(cpy));
Py_Return;
}
PyErr_SetString(Part::PartExceptionOCCError, "A geometry extension object was expected");
return 0;
}
PyObject* GeometryFacadePy::getExtensionOfType(PyObject *args)
{
char* o;
if (PyArg_ParseTuple(args, "s", &o)) {
Base::Type type = Base::Type::fromName(o);
if(type != Base::Type::badType()) {
try {
std::shared_ptr<const Part::GeometryExtension> ext(this->getGeometryFacadePtr()->getExtension(type));
// we create a copy and transfer this copy's memory management responsibility to Python
PyObject* cpy = static_cast<Part::GeometryExtensionPy *>(std::const_pointer_cast<Part::GeometryExtension>(ext)->getPyObject())->copy(Py::new_reference_to(Py::Tuple(size_t(0))));
return cpy;
}
catch(const Base::ValueError& e) {
PyErr_SetString(Part::PartExceptionOCCError, e.what());
return 0;
}
catch(const std::bad_weak_ptr&) {
PyErr_SetString(Part::PartExceptionOCCError, "Geometry extension does not exist anymore.");
return 0;
}
}
else
{
PyErr_SetString(Part::PartExceptionOCCError, "Exception type does not exist");
return 0;
}
}
PyErr_SetString(Part::PartExceptionOCCError, "A string with the name of the geometry extension type was expected");
return 0;
}
PyObject* GeometryFacadePy::getExtensionOfName(PyObject *args)
{
char* o;
if (PyArg_ParseTuple(args, "s", &o)) {
try {
std::shared_ptr<const Part::GeometryExtension> ext(this->getGeometryFacadePtr()->getExtension(std::string(o)));
// we create a copy and transfer this copy's memory management responsibility to Python
PyObject* cpy = static_cast<Part::GeometryExtensionPy *>(std::const_pointer_cast<Part::GeometryExtension>(ext)->getPyObject())->copy(Py::new_reference_to(Py::Tuple(size_t(0))));
return cpy;
}
catch(const Base::ValueError& e) {
PyErr_SetString(Part::PartExceptionOCCError, e.what());
return 0;
}
catch(const std::bad_weak_ptr&) {
PyErr_SetString(Part::PartExceptionOCCError, "Geometry extension does not exist anymore.");
return 0;
}
}
PyErr_SetString(Part::PartExceptionOCCError, "A string with the name of the geometry extension was expected");
return 0;
}
PyObject* GeometryFacadePy::hasExtensionOfType(PyObject *args)
{
char* o;
if (PyArg_ParseTuple(args, "s", &o)) {
Base::Type type = Base::Type::fromName(o);
if(type != Base::Type::badType()) {
try {
return Py::new_reference_to(Py::Boolean(this->getGeometryFacadePtr()->hasExtension(type)));
}
catch(const Base::ValueError& e) {
PyErr_SetString(Part::PartExceptionOCCError, e.what());
return 0;
}
}
else
{
PyErr_SetString(Part::PartExceptionOCCError, "Exception type does not exist");
return 0;
}
}
PyErr_SetString(Part::PartExceptionOCCError, "A string with the type of the geometry extension was expected");
return 0;
}
PyObject* GeometryFacadePy::hasExtensionOfName(PyObject *args)
{
char* o;
if (PyArg_ParseTuple(args, "s", &o)) {
try {
return Py::new_reference_to(Py::Boolean(this->getGeometryFacadePtr()->hasExtension(std::string(o))));
}
catch(const Base::ValueError& e) {
PyErr_SetString(Part::PartExceptionOCCError, e.what());
return 0;
}
}
PyErr_SetString(Part::PartExceptionOCCError, "A string with the type of the geometry extension was expected");
return 0;
}
PyObject* GeometryFacadePy::deleteExtensionOfType(PyObject *args)
{
char* o;
if (PyArg_ParseTuple(args, "s", &o)) {
Base::Type type = Base::Type::fromName(o);
if(type != Base::Type::badType()) {
try {
this->getGeometryFacadePtr()->deleteExtension(type);
Py_Return;
}
catch(const Base::ValueError& e) {
PyErr_SetString(Part::PartExceptionOCCError, e.what());
return 0;
}
}
else
{
PyErr_SetString(Part::PartExceptionOCCError, "Type does not exist");
return 0;
}
}
PyErr_SetString(Part::PartExceptionOCCError, "A string with a type object was expected");
return 0;
}
PyObject* GeometryFacadePy::deleteExtensionOfName(PyObject *args)
{
char* o;
if (PyArg_ParseTuple(args, "s", &o)) {
try {
this->getGeometryFacadePtr()->deleteExtension(std::string(o));
Py_Return;
}
catch(const Base::ValueError& e) {
PyErr_SetString(Part::PartExceptionOCCError, e.what());
return 0;
}
}
PyErr_SetString(Part::PartExceptionOCCError, "A string with the name of the extension was expected");
return 0;
}
PyObject* GeometryFacadePy::getExtensions(PyObject *args)
{
if (!PyArg_ParseTuple(args, "")){
PyErr_SetString(Part::PartExceptionOCCError, "No arguments were expected");
return NULL;
}
try {
const std::vector<std::weak_ptr<const Part::GeometryExtension>> ext = this->getGeometryFacadePtr()->getExtensions();
PyObject* list = PyList_New(ext.size());
Py::Tuple tuple(ext.size());
for (std::size_t i=0; i<ext.size(); ++i) {
std::shared_ptr<const Part::GeometryExtension> p = ext[i].lock();
if(p) {
// we create a python copy and add it to the list
PyObject* cpy = static_cast<Part::GeometryExtensionPy *>(std::const_pointer_cast<Part::GeometryExtension>(p)->getPyObject())->copy(Py::new_reference_to(Py::Tuple(size_t(0))));
PyList_SetItem( list, i, cpy);
}
}
return list;
}
catch(const Base::ValueError& e) {
PyErr_SetString(Part::PartExceptionOCCError, e.what());
return 0;
}
}
Py::Boolean GeometryFacadePy::getConstruction(void) const
{
return Py::Boolean(getGeometryFacadePtr()->getConstruction());
}
void GeometryFacadePy::setConstruction(Py::Boolean arg)
{
if (getGeometryFacadePtr()->getTypeId() != Part::GeomPoint::getClassTypeId())
getGeometryFacadePtr()->setConstruction(arg);
}
Py::String GeometryFacadePy::getTag(void) const
{
std::string tmp = boost::uuids::to_string(getGeometryFacadePtr()->getTag());
return Py::String(tmp);
}
Py::Object GeometryFacadePy::getGeometry(void) const
{
// We return a clone
return Py::Object(getGeometryFacadePtr()->getGeometry()->clone()->getPyObject(),true);
}
void GeometryFacadePy::setGeometry(Py::Object arg)
{
if (PyObject_TypeCheck(arg.ptr(), &(Part::GeometryPy::Type))) {
Part::GeometryPy * gp = static_cast<Part::GeometryPy *>(arg.ptr());
getGeometryFacadePtr()->setGeometry(gp->getGeometryPtr()->clone());
}
}
PyObject *GeometryFacadePy::getCustomAttributes(const char* /*attr*/) const
{
return 0;
}
int GeometryFacadePy::setCustomAttributes(const char* /*attr*/, PyObject* /*obj*/)
{
return 0;
}

View File

@@ -450,5 +450,13 @@ If there is no such constraint an exception is raised.
</Documentation>
<Parameter Name="AxisCount" Type="Long"/>
</Attribute>
<Attribute Name="GeometryFacadeList" ReadOnly="false">
<Documentation>
<UserDocu>
Return a list of GeometryFacade objects corresponding to the PropertyGeometryList
</UserDocu>
</Documentation>
<Parameter Name="GeometryFacadeList" Type="List"/>
</Attribute>
</PythonExport>
</GenerateModel>

View File

@@ -27,6 +27,8 @@
# include <boost/shared_ptr.hpp>
#endif
#include <Base/StdStlTools.h>
#include <Mod/Sketcher/App/SketchObject.h>
#include <Mod/Part/App/LinePy.h>
#include <Mod/Part/App/Geometry.h>
@@ -45,6 +47,8 @@
#include "SketchObjectPy.cpp"
// other python types
#include "ConstraintPy.h"
#include "GeometryFacade.h"
#include "GeometryFacadePy.h"
using namespace Sketcher;
@@ -1750,6 +1754,44 @@ Py::Long SketchObjectPy::getAxisCount(void) const
return Py::Long(this->getSketchObjectPtr()->getAxisCount());
}
Py::List SketchObjectPy::getGeometryFacadeList(void) const
{
Py::List list;
for (int i = 0; i < getSketchObjectPtr()->Geometry.getSize(); i++) {
// we create a python copy and add it to the list
std::unique_ptr<GeometryFacade> geofacade = GeometryFacade::getFacade(getSketchObjectPtr()->Geometry[i]->clone());
Py::Object gfp = Py::Object(new GeometryFacadePy(geofacade.release()),true);
list.append(gfp);
}
return list;
}
void SketchObjectPy::setGeometryFacadeList(Py::List value)
{
std::vector<Part::Geometry *> list;
list.reserve(value.size());
for (const auto & ti : value) {
if (PyObject_TypeCheck(ti.ptr(), &(GeometryFacadePy::Type))) {
GeometryFacadePy * gfp = static_cast<GeometryFacadePy *>(ti.ptr());
GeometryFacade * gf = gfp->getGeometryFacadePtr();
Part::Geometry * geo = gf->getGeometry()->clone();
list.push_back(geo);
}
}
getSketchObjectPtr()->Geometry.setValues(std::move(list));
}
PyObject *SketchObjectPy::getCustomAttributes(const char* /*attr*/) const
{
return 0;