Sketcher: Facade for geometry and external geometry extension

This commit is contained in:
Abdullah Tahiri
2020-11-01 07:40:46 +01:00
committed by abdullahtahiriyo
parent 36e58956c3
commit e9e8724cb1
6 changed files with 933 additions and 1 deletions

View File

@@ -33,12 +33,16 @@
#include "SketchObject.h"
#include "SketchGeometryExtension.h"
#include "ExternalGeometryExtension.h"
#include "GeometryFacade.h"
#include "ExternalGeometryFacade.h"
#include "Constraint.h"
#include "Sketch.h"
#include "ConstraintPy.h"
#include "SketchPy.h"
#include "SketchGeometryExtensionPy.h"
#include "ExternalGeometryExtensionPy.h"
#include "GeometryFacadePy.h"
#include "ExternalGeometryFacadePy.h"
#include "PropertyConstraintList.h"
@@ -65,7 +69,9 @@ PyMOD_INIT_FUNC(Sketcher)
Base::Interpreter().addType(&Sketcher::ConstraintPy ::Type,sketcherModule,"Constraint");
Base::Interpreter().addType(&Sketcher::SketchPy ::Type,sketcherModule,"Sketch");
Base::Interpreter().addType(&Sketcher::ExternalGeometryExtensionPy ::Type,sketcherModule,"ExternalGeometryExtension");
Base::Interpreter().addType(&Sketcher::SketchGeometryExtensionPy ::Type,sketcherModule,"SketchGeometryExtension");
Base::Interpreter().addType(&Sketcher::SketchGeometryExtensionPy ::Type,sketcherModule,"SketchGeometryExtension");
Base::Interpreter().addType(&Sketcher::GeometryFacadePy ::Type,sketcherModule,"GeometryFacade");
Base::Interpreter().addType(&Sketcher::ExternalGeometryFacadePy ::Type,sketcherModule,"ExternalGeometryFacade");
// NOTE: To finish the initialization of our own type objects we must
@@ -74,6 +80,8 @@ PyMOD_INIT_FUNC(Sketcher)
Sketcher::SketchGeometryExtension ::init();
Sketcher::ExternalGeometryExtension ::init();
Sketcher::GeometryFacade ::init();
Sketcher::ExternalGeometryFacade ::init();
Sketcher::SketchObjectSF ::init();
Sketcher::SketchObject ::init();
Sketcher::SketchObjectPython ::init();

View File

@@ -39,6 +39,7 @@ generate_from_xml(SketchObjectPy)
generate_from_xml(SketchGeometryExtensionPy)
generate_from_xml(ExternalGeometryExtensionPy)
generate_from_xml(GeometryFacadePy)
generate_from_xml(ExternalGeometryFacadePy)
generate_from_xml(ConstraintPy)
generate_from_xml(SketchPy)
@@ -72,6 +73,8 @@ SET(Datatypes_SRCS
Sketch.h
GeometryFacade.cpp
GeometryFacade.h
ExternalGeometryFacade.cpp
ExternalGeometryFacade.h
)
SOURCE_GROUP("Datatypes" FILES ${Datatypes_SRCS})
@@ -86,6 +89,8 @@ SET(Python_SRCS
ExternalGeometryExtensionPyImp.cpp
GeometryFacadePy.xml
GeometryFacadePyImp.cpp
ExternalGeometryFacadePy.xml
ExternalGeometryFacadePyImp.cpp
ConstraintPyImp.cpp
ConstraintPy.xml
SketchPy.xml

View File

@@ -0,0 +1,142 @@
/***************************************************************************
* 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 "ExternalGeometryFacade.h"
#include <Base/Console.h> // Only for Debug - To be removed
#include <Base/Exception.h>
#include <boost/uuid/uuid_io.hpp>
#include "ExternalGeometryFacadePy.h"
using namespace Sketcher;
TYPESYSTEM_SOURCE(Sketcher::ExternalGeometryFacade,Part::GeometryExtension)
ExternalGeometryFacade::ExternalGeometryFacade(): Geo(nullptr), SketchGeoExtension(nullptr), ExternalGeoExtension(nullptr)
{
}
ExternalGeometryFacade::ExternalGeometryFacade(const Part::Geometry * geometry)
: Geo(geometry)
{
if(geometry != nullptr)
initExtensions();
else
THROWM(Base::ValueError, "ExternalGeometryFacade initialized with Geometry null pointer");
}
std::unique_ptr<ExternalGeometryFacade> ExternalGeometryFacade::getFacade(Part::Geometry * geometry)
{
return std::unique_ptr<ExternalGeometryFacade>(new ExternalGeometryFacade(geometry));
//return std::make_unique<ExternalGeometryFacade>(geometry); // make_unique has no access to private constructor
}
std::unique_ptr<const ExternalGeometryFacade> ExternalGeometryFacade::getFacade(const Part::Geometry * geometry)
{
return std::unique_ptr<const ExternalGeometryFacade>(new ExternalGeometryFacade(geometry));
//return std::make_unique<const ExternalGeometryFacade>(geometry); // make_unique has no access to private constructor
}
void ExternalGeometryFacade::setGeometry(Part::Geometry *geometry)
{
Geo = geometry;
if(geometry != nullptr)
initExtensions();
else
THROWM(Base::ValueError, "ExternalGeometryFacade initialized with Geometry null pointer");
}
void ExternalGeometryFacade::initExtensions()
{
if(!Geo->hasExtension(SketchGeometryExtension::getClassTypeId())) {
getGeo()->setExtension(std::make_unique<SketchGeometryExtension>()); // Create getExtension
Base::Console().Warning("%s\nSketcher External Geometry without Geometry Extension: %s \n", boost::uuids::to_string(Geo->getTag()).c_str());
}
if(!Geo->hasExtension(ExternalGeometryExtension::getClassTypeId())) {
getGeo()->setExtension(std::make_unique<ExternalGeometryExtension>()); // Create getExtension
Base::Console().Warning("%s\nSketcher External Geometry without ExternalGeometryExtension: %s \n", boost::uuids::to_string(Geo->getTag()).c_str());
}
SketchGeoExtension =
std::static_pointer_cast<const SketchGeometryExtension>(
(Geo->getExtension(SketchGeometryExtension::getClassTypeId())).lock()
);
ExternalGeoExtension =
std::static_pointer_cast<const ExternalGeometryExtension>(
(Geo->getExtension(ExternalGeometryExtension::getClassTypeId())).lock()
);
}
void ExternalGeometryFacade::initExtensions() const
{
if(!Geo->hasExtension(SketchGeometryExtension::getClassTypeId()))
THROWM(Base::ValueError, "ExternalGeometryFacade for const::Geometry without SketchGeometryExtension");
if(!Geo->hasExtension(ExternalGeometryExtension::getClassTypeId()))
THROWM(Base::ValueError, "ExternalGeometryFacade for const::Geometry without ExternalGeometryExtension");
auto ext = std::static_pointer_cast<const SketchGeometryExtension>(Geo->getExtension(SketchGeometryExtension::getClassTypeId()).lock());
const_cast<ExternalGeometryFacade *>(this)->SketchGeoExtension = ext;
auto extext = std::static_pointer_cast<const ExternalGeometryExtension>(Geo->getExtension(ExternalGeometryExtension::getClassTypeId()).lock());
const_cast<ExternalGeometryFacade *>(this)->ExternalGeoExtension = extext;
}
void ExternalGeometryFacade::ensureSketchGeometryExtensions(Part::Geometry * geometry)
{
if(!geometry->hasExtension(SketchGeometryExtension::getClassTypeId())) {
geometry->setExtension(std::make_unique<SketchGeometryExtension>()); // Create geoExtension
}
if(!geometry->hasExtension(ExternalGeometryExtension::getClassTypeId())) {
geometry->setExtension(std::make_unique<ExternalGeometryExtension>()); // Create external geoExtension
}
}
void ExternalGeometryFacade::copyId(const Part::Geometry * src, Part::Geometry * dst)
{
auto gfsrc = ExternalGeometryFacade::getFacade(src);
auto gfdst = ExternalGeometryFacade::getFacade(dst);
gfdst->setId(gfsrc->getId());
}
PyObject * ExternalGeometryFacade::getPyObject(void)
{
return new ExternalGeometryFacadePy(new ExternalGeometryFacade(this->Geo));
}

View File

@@ -0,0 +1,151 @@
/***************************************************************************
* 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_GEOMETRYEXTERNALFACADE_H
#define SKETCHER_GEOMETRYEXTERNALFACADE_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>
#include <Mod/Sketcher/App/ExternalGeometryExtension.h>
namespace Sketcher
{
// This class is a Facade to handle external geometry 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 ExternalGeometryFacade : public Base::BaseClass, public ISketchGeometryExtension, public ISketchExternalGeometryExtension
{
TYPESYSTEM_HEADER_WITH_OVERRIDE();
private:
ExternalGeometryFacade(const Part::Geometry * geometry);
public:
ExternalGeometryFacade(); // As TYPESYSTEM requirement for Python object construction
public: // Factory methods
static std::unique_ptr<ExternalGeometryFacade> getFacade(Part::Geometry * geometry);
static std::unique_ptr<const ExternalGeometryFacade> getFacade(const Part::Geometry * geometry);
public: // Utility methods
static void ensureSketchGeometryExtensions(Part::Geometry * geometry);
static void copyId(const Part::Geometry * src, Part::Geometry * dst);
public:
void setGeometry(Part::Geometry *geometry);
/** External GeometryExtension Interface **/
virtual bool testFlag(int flag) const override { return getExternalGeoExt()->testFlag(flag); }
virtual void setFlag(int flag, bool v=true) override { getExternalGeoExt()->setFlag(flag, v); }
virtual bool isClear() const override {return getExternalGeoExt()->isClear();}
virtual size_t flagSize() const override {return getExternalGeoExt()->flagSize();}
virtual const std::string& getRef() const override {return getExternalGeoExt()->getRef();}
virtual void setRef(const std::string & ref) override {getExternalGeoExt()->setRef(ref);}
/** GeometryExtension 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 &getSketchExtensionName () const {return SketchGeoExtension->getName();}
inline const std::string &getExternalExtensionName () const {return ExternalGeoExtension->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 initExtensions(void);
void initExtensions(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);}
std::shared_ptr<const ExternalGeometryExtension> getExternalGeoExt(void) const {return ExternalGeoExtension;}
std::shared_ptr<ExternalGeometryExtension> getExternalGeoExt (void) {return std::const_pointer_cast<ExternalGeometryExtension>(ExternalGeoExtension);}
private:
const Part::Geometry * Geo;
std::shared_ptr<const SketchGeometryExtension> SketchGeoExtension;
std::shared_ptr<const ExternalGeometryExtension> ExternalGeoExtension;
};
} //namespace Sketcher
#endif // SKETCHER_GEOMETRYEXTERNALFACADE_H

View File

@@ -0,0 +1,129 @@
<?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="ExternalGeometryFacadePy"
PythonName="Sketcher.ExternalGeometryFacade"
Twin="ExternalGeometryFacade"
TwinPointer="ExternalGeometryFacade"
Include="Mod/Sketcher/App/ExternalGeometryFacade.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="testFlag" Const="true">
<Documentation>
<UserDocu>returns a boolean indicating whether the given bit is set.</UserDocu>
</Documentation>
</Methode>
<Methode Name="setFlag" Const="false">
<Documentation>
<UserDocu>sets the given bit to true/false.</UserDocu>
</Documentation>
</Methode>
<Attribute Name="Ref" ReadOnly="false">
<Documentation>
<UserDocu>
returns the reference string of this external geometry.
</UserDocu>
</Documentation>
<Parameter Name="Ref" Type="String"/>
</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,497 @@
/***************************************************************************
* 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_
//# 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 "ExternalGeometryFacadePy.h"
#include "ExternalGeometryFacadePy.cpp"
using namespace Sketcher;
// returns a string which represents the object e.g. when printed in python
std::string ExternalGeometryFacadePy::representation(void) const
{
std::stringstream str;
str << "<ExternalGeometryFacadePy ( Id=";
str << getExternalGeometryFacadePtr()->getId() << " ) >";
return str.str();
}
PyObject *ExternalGeometryFacadePy::PyMake(struct _typeobject *, PyObject *, PyObject *) // Python wrapper
{
// create a new instance of PointPy and the Twin object
return new ExternalGeometryFacadePy(new ExternalGeometryFacade());
}
// constructor method
int ExternalGeometryFacadePy::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();
getExternalGeometryFacadePtr()->setGeometry(geo->clone());
return 0;
}
PyErr_SetString(PyExc_TypeError, "Sketcher::ExternalGeometryFacade constructor accepts:\n"
"-- Part.Geometry\n"
);
return -1;
}
PyObject* ExternalGeometryFacadePy::testFlag(PyObject *args)
{
char* flag;
if (PyArg_ParseTuple(args, "s",&flag)) {
auto pos = std::find_if(getExternalGeometryFacadePtr()->flag2str.begin(),
getExternalGeometryFacadePtr()->flag2str.end(),
[flag](const char * val) { return strcmp(val,flag) == 0;});
if( pos != getExternalGeometryFacadePtr()->flag2str.end()) {
int index = std::distance( getExternalGeometryFacadePtr()->flag2str.begin(), pos );
return new_reference_to(Py::Boolean(this->getExternalGeometryFacadePtr()->testFlag(index)));
}
PyErr_SetString(PyExc_TypeError, "Flag string does not exist.");
return NULL;
}
PyErr_SetString(PyExc_TypeError, "No flag string provided.");
return NULL;
}
PyObject* ExternalGeometryFacadePy::setFlag(PyObject *args)
{
char * flag;
PyObject * bflag = Py_True;
if (PyArg_ParseTuple(args, "s|O!", &flag, &PyBool_Type, &bflag)) {
auto pos = std::find_if(getExternalGeometryFacadePtr()->flag2str.begin(),
getExternalGeometryFacadePtr()->flag2str.end(),
[flag](const char * val) {
return strcmp(val,flag)==0;}
);
if( pos != getExternalGeometryFacadePtr()->flag2str.end()) {
int index = std::distance( getExternalGeometryFacadePtr()->flag2str.begin(), pos );
this->getExternalGeometryFacadePtr()->setFlag(index,PyObject_IsTrue(bflag) ? true : false);
Py_Return;
}
PyErr_SetString(PyExc_TypeError, "Flag string does not exist.");
return NULL;
}
PyErr_SetString(PyExc_TypeError, "No flag string provided.");
Py_Return;
}
Py::String ExternalGeometryFacadePy::getRef(void) const
{
return Py::String(this->getExternalGeometryFacadePtr()->getRef());
}
void ExternalGeometryFacadePy::setRef(Py::String value)
{
this->getExternalGeometryFacadePtr()->setRef(value.as_std_string());
}
Py::Long ExternalGeometryFacadePy::getId(void) const
{
return Py::Long(this->getExternalGeometryFacadePtr()->getId());
}
void ExternalGeometryFacadePy::setId(Py::Long Id)
{
this->getExternalGeometryFacadePtr()->setId(long(Id));
}
PyObject* ExternalGeometryFacadePy::mirror(PyObject *args)
{
PyObject* o;
if (PyArg_ParseTuple(args, "O!", &(Base::VectorPy::Type),&o)) {
Base::Vector3d vec = static_cast<Base::VectorPy*>(o)->value();
getExternalGeometryFacadePtr()->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();
getExternalGeometryFacadePtr()->mirror(pnt, dir);
Py_Return;
}
PyErr_SetString(Part::PartExceptionOCCError, "either a point (vector) or axis (vector, vector) must be given");
return 0;
}
PyObject* ExternalGeometryFacadePy::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();
getExternalGeometryFacadePtr()->rotate(*plm);
Py_Return;
}
PyObject* ExternalGeometryFacadePy::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();
getExternalGeometryFacadePtr()->scale(vec, scale);
Py_Return;
}
PyErr_Clear();
if (PyArg_ParseTuple(args, "O!d", &PyTuple_Type,&o, &scale)) {
vec = Base::getVectorFromTuple<double>(o);
getExternalGeometryFacadePtr()->scale(vec, scale);
Py_Return;
}
PyErr_SetString(Part::PartExceptionOCCError, "either vector or tuple and float expected");
return 0;
}
PyObject* ExternalGeometryFacadePy::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();
getExternalGeometryFacadePtr()->transform(mat);
Py_Return;
}
PyObject* ExternalGeometryFacadePy::translate(PyObject *args)
{
PyObject* o;
Base::Vector3d vec;
if (PyArg_ParseTuple(args, "O!", &(Base::VectorPy::Type),&o)) {
vec = static_cast<Base::VectorPy*>(o)->value();
getExternalGeometryFacadePtr()->translate(vec);
Py_Return;
}
PyErr_Clear();
if (PyArg_ParseTuple(args, "O!", &PyTuple_Type,&o)) {
vec = Base::getVectorFromTuple<double>(o);
getExternalGeometryFacadePtr()->translate(vec);
Py_Return;
}
PyErr_SetString(Part::PartExceptionOCCError, "either vector or tuple expected");
return 0;
}
PyObject* ExternalGeometryFacadePy::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->getExternalGeometryFacadePtr()->setExtension(std::move(cpy));
Py_Return;
}
PyErr_SetString(Part::PartExceptionOCCError, "A geometry extension object was expected");
return 0;
}
PyObject* ExternalGeometryFacadePy::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->getExternalGeometryFacadePtr()->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* ExternalGeometryFacadePy::getExtensionOfName(PyObject *args)
{
char* o;
if (PyArg_ParseTuple(args, "s", &o)) {
try {
std::shared_ptr<const Part::GeometryExtension> ext(this->getExternalGeometryFacadePtr()->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* ExternalGeometryFacadePy::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->getExternalGeometryFacadePtr()->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* ExternalGeometryFacadePy::hasExtensionOfName(PyObject *args)
{
char* o;
if (PyArg_ParseTuple(args, "s", &o)) {
try {
return Py::new_reference_to(Py::Boolean(this->getExternalGeometryFacadePtr()->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* ExternalGeometryFacadePy::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->getExternalGeometryFacadePtr()->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* ExternalGeometryFacadePy::deleteExtensionOfName(PyObject *args)
{
char* o;
if (PyArg_ParseTuple(args, "s", &o)) {
try {
this->getExternalGeometryFacadePtr()->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* ExternalGeometryFacadePy::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->getExternalGeometryFacadePtr()->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 ExternalGeometryFacadePy::getConstruction(void) const
{
return Py::Boolean(getExternalGeometryFacadePtr()->getConstruction());
}
void ExternalGeometryFacadePy::setConstruction(Py::Boolean arg)
{
if (getExternalGeometryFacadePtr()->getTypeId() != Part::GeomPoint::getClassTypeId())
getExternalGeometryFacadePtr()->setConstruction(arg);
}
Py::String ExternalGeometryFacadePy::getTag(void) const
{
std::string tmp = boost::uuids::to_string(getExternalGeometryFacadePtr()->getTag());
return Py::String(tmp);
}
Py::Object ExternalGeometryFacadePy::getGeometry(void) const
{
// We return a clone
return Py::Object(getExternalGeometryFacadePtr()->getGeometry()->clone()->getPyObject(),true);
}
void ExternalGeometryFacadePy::setGeometry(Py::Object arg)
{
if (PyObject_TypeCheck(arg.ptr(), &(Part::GeometryPy::Type))) {
Part::GeometryPy * gp = static_cast<Part::GeometryPy *>(arg.ptr());
getExternalGeometryFacadePtr()->setGeometry(gp->getGeometryPtr()->clone());
}
}
PyObject *ExternalGeometryFacadePy::getCustomAttributes(const char* /*attr*/) const
{
return 0;
}
int ExternalGeometryFacadePy::setCustomAttributes(const char* /*attr*/, PyObject* /*obj*/)
{
return 0;
}