PyObjectBase.h File Reference

#include <Python.h>
#include <iostream>
#include <bitset>
#include <typeinfo>
#include "Exception.h"
#include <CXX/Objects.hxx>

Go to the source code of this file.

Classes

class  Base::PyObjectBase
 The PyObjectBase class, exports the class as a python type PyObjectBase is the base class for all C++ classes which need to get exported into the python namespace. More...
union  PyType_Object
 Union to convert from PyTypeObject to PyObject pointer. More...

Namespaces

namespace  Base
 

The namespace of the FreeCAD Base library.


Defines

#define _getattr_up(Parent)
 This defines the _getattr_up macro which allows attribute and method calls to be properly passed up the hierarchy.
#define PARENTSBasePyObjectBase   &Base::PyObjectBase::Type,NULL
 Root definition of the inheritance tree of the FreeCAD python objects.
#define Py_Assert(A, E, M)   {if (!(A)) {PyErr_SetString(E, M); return NULL;}}
 assert which returns with an error on failure
#define PY_CATCH
 see docu of PY_TRY
#define Py_Error(E, M)   {PyErr_SetString(E, M); return NULL;}
 returns an error
#define Py_Header
 This must be the first line of each PyC++ class.
#define Py_NEWARGS   1
 some basic python macros
#define Py_Return   Py_INCREF(Py_None); return Py_None;
 return with no retrnvalue if nothin happens
#define PY_TRY   try
 Exception handling for python callback functions Is a convenience macro to manage the exception handling of python callback functions defined in classes inheriting PyObjectBase and using PYMETHODEDEF .
#define Py_Try(F)   {if (!(F)) return NULL;}
 checks on a condition and returns an error on failure
#define PYFUNCDEF_D(CLASS, DFUNC)
 Python dynamic class macro for definition sets up a static/dynamic function entry in a class inheriting from PyObjectBase.
#define PYFUNCDEF_S(SFUNC)   static PyObject* SFUNC (PyObject *self,PyObject *args,PyObject *kwd);
 Python static class macro for definition sets up a static function entry in a class inheriting from PyObjectBase.
#define PYFUNCIMP_D(CLASS, DFUNC)   PyObject* CLASS::DFUNC (PyObject *args)
 Python dynamic class macro for implementation used to set up a impementation for PYFUNCDEF_D definition.
#define PYFUNCIMP_S(CLASS, SFUNC)   PyObject* CLASS::SFUNC (PyObject *self,PyObject *args,PyObject *kwd)
 Python static class macro for implementation used to set up a implementation for PYFUNCDEF_S definition.
#define PYMETHODEDEF(FUNC)   {"" #FUNC "",(PyCFunction) s##FUNC,Py_NEWARGS},
 Python dynamic class macro for the method list used to fill the method list of a class derived from PyObjectBase.
#define slots

Typedefs

typedef PyTypeObject * PyParentObject
 Define the PyParent Object.

Functions

void Base::Assert (int expr, char *msg)
PyObjectBase::PyAsUnicodeObject (const std::string &str)
PyObjectBase::PyAsUnicodeObject (const char *str)
 Python helper class This class encapsulate the Decoding of UTF8 to a python object.
int Base::streq (const char *A, const char *B)

Define Documentation

#define _getattr_up ( Parent   ) 
Value:
{                                                           \
    PyObject *rvalue = Py_FindMethod(Methods, this, attr);  \
    if (rvalue == NULL)                                     \
    {                                                       \
        PyErr_Clear();                                      \
        return Parent::_getattr(attr);                      \
    }                                                       \
    else                                                    \
        return rvalue;                                      \
}

This defines the _getattr_up macro which allows attribute and method calls to be properly passed up the hierarchy.

Definition at line 145 of file PyObjectBase.h.

Referenced by Gui::PyResource::_getattr(), TestGui::UnitTestPy::_getattr(), and ParameterGrpPy::_getattr().

#define PARENTSBasePyObjectBase   &Base::PyObjectBase::Type,NULL

Root definition of the inheritance tree of the FreeCAD python objects.

Definition at line 477 of file PyObjectBase.h.

#define Py_Assert ( A,
E,
 )     {if (!(A)) {PyErr_SetString(E, M); return NULL;}}

assert which returns with an error on failure

Definition at line 125 of file PyObjectBase.h.

#define PY_CATCH
Value:
catch(Base::Exception &e)                        \
    {                                                               \
        std::string str;                                            \
        str += "FreeCAD exception thrown (";                        \
        str += e.what();                                            \
        str += ")";                                                 \
        e.ReportException();                                        \
        Py_Error(PyExc_Exception,str.c_str());                      \
    }                                                               \
    catch(std::exception &e)                                        \
    {                                                               \
        std::string str;                                            \
        str += "STL exception thrown (";                            \
        str += e.what();                                            \
        str += ")";                                                 \
        Base::Console().Error(str.c_str());                         \
        Py_Error(PyExc_Exception,str.c_str());                      \
    }                                                               \
    catch(const Py::Exception&)                                     \
    {                                                               \
        return NULL;                                                \
    }                                                               \
    catch(const char *e)                                            \
    {                                                               \
        Py_Error(PyExc_Exception,e);                                \
    }                                                               \
    catch(...)                                                      \
    {                                                               \
        Py_Error(PyExc_Exception,"Unknown C++ exception");          \
    }

see docu of PY_TRY

Definition at line 414 of file PyObjectBase.h.

Referenced by Gui::WorkbenchPy::activate(), Gui::DocumentPy::activeObject(), Gui::DocumentPy::activeView(), Gui::DocumentPy::addAnnotation(), Gui::ViewProviderPythonFeaturePy::addDisplayMode(), Mesh::MeshPy::addMesh(), Gui::PythonWorkbenchPy::appendCommandbar(), Gui::PythonWorkbenchPy::appendContextMenu(), Gui::PythonWorkbenchPy::appendMenu(), Gui::PythonWorkbenchPy::appendToolbar(), approxSurface(), best_fit_coarse(), best_fit_complete(), best_fit_test(), calcMeshVolume(), TestGui::UnitTestPy::clearErrorList(), Mesh::MeshPy::collapseEdge(), Mesh::MeshPy::collapseFacet(), createBox(), createCone(), createCylinder(), createEllipsoid(), createPlane(), createSphere(), createTestApproximate(), createTestBSPLINE(), createTorus(), Mesh::MeshPy::difference(), TestGui::UnitTestPy::errorDialog(), exporter(), fit_iter(), Mesh::MeshPy::fixDeformations(), Mesh::MeshPy::fixDegenerations(), Mesh::MeshFeaturePy::fixDegenerations(), Mesh::MeshPy::fixIndices(), Mesh::MeshFeaturePy::fixIndices(), Mesh::MeshPy::flipNormals(), getBoundary_Conditions(), Gui::ViewProviderPythonFeaturePy::getCustomAttributes(), Part::FeaturePythonPy::getCustomAttributes(), Mesh::FeaturePythonPy::getCustomAttributes(), App::FeaturePythonPy::getCustomAttributes(), Gui::DocumentPy::getObject(), TestGui::UnitTestPy::getUnitTest(), Mesh::MeshPy::harmonizeNormals(), Mesh::MeshFeaturePy::harmonizeNormals(), Gui::ViewProviderPy::hide(), Gui::DocumentPy::hide(), import_NASTRAN(), importer(), Mesh::MeshPy::inner(), insert(), TestGui::UnitTestPy::insertError(), Mesh::MeshPy::insertVertex(), Mesh::MeshPy::intersect(), Base::MatrixPy::inverse(), Base::MatrixPy::invert(), Gui::ViewProviderPy::isVisible(), Gui::PythonWorkbenchPy::listCommandbars(), Gui::ViewProviderPy::listDisplayModes(), Gui::PythonWorkbenchPy::listMenus(), Gui::PythonWorkbenchPy::listToolbars(), loftOnCurve(), makeCompound(), makeFilledFace(), makePolygon(), makeShell(), minBoundingBox(), Base::MatrixPy::move(), Gui::WorkbenchPy::name(), Mesh::MeshPy::offset(), offset(), offset_mesh(), Mesh::MeshPy::offsetSpecial(), open(), openBrowser(), openBrowserHTML(), openDYNA(), Mesh::MeshPy::optimizeEdges(), Mesh::MeshPy::optimizeTopology(), Mesh::MeshPy::outer(), povViewCamera(), project(), projectEx(), projectToDXF(), projectToSVG(), Points::PointsPy::read(), Mesh::MeshPy::read(), read(), Mesh::MeshPy::refine(), Gui::PythonWorkbenchPy::removeCommandbar(), Mesh::MeshPy::removeComponents(), Gui::PythonWorkbenchPy::removeContextMenu(), Mesh::MeshPy::removeDuplicatedFacets(), Mesh::MeshFeaturePy::removeDuplicatedFacets(), Mesh::MeshPy::removeDuplicatedPoints(), Mesh::MeshFeaturePy::removeDuplicatedPoints(), Gui::PythonWorkbenchPy::removeMenu(), Gui::PythonWorkbenchPy::removeToolbar(), Mesh::MeshPy::rotate(), Base::MatrixPy::rotateX(), Base::MatrixPy::rotateY(), Base::MatrixPy::rotateZ(), Gui::SelectionSingleton::saddSelectionGate(), Gui::SelectionSingleton::sAddSelObserver(), Base::MatrixPy::scale(), TestGui::UnitTestPy::setErrorCount(), TestGui::UnitTestPy::setFailCount(), Mesh::MeshPy::setPoint(), Gui::DocumentPy::setPos(), TestGui::UnitTestPy::setProgressFraction(), TestGui::UnitTestPy::setRemainCount(), TestGui::UnitTestPy::setRunCount(), TestGui::UnitTestPy::setStatusText(), TestGui::UnitTestPy::setUnitTest(), Gui::Application::sExport(), shape2orig(), Gui::ViewProviderPy::show(), Gui::DocumentPy::show(), show(), simulateToFile(), Gui::Application::sInsert(), SMESH_PCA(), Mesh::MeshPy::smooth(), Mesh::MeshFeaturePy::smooth(), Mesh::MeshPy::snapVertex(), Gui::Application::sOpen(), Mesh::MeshPy::splitEdge(), Mesh::MeshPy::splitEdges(), Mesh::MeshPy::splitFacet(), spring_back(), Base::ConsoleSingleton::sPyError(), Base::ConsoleSingleton::sPyGetStatus(), Base::ConsoleSingleton::sPyLog(), Base::ConsoleSingleton::sPyMessage(), Base::ConsoleSingleton::sPySetStatus(), Base::ConsoleSingleton::sPyWarning(), Gui::SelectionSingleton::sremoveSelectionGate(), Gui::SelectionSingleton::sRemSelObserver(), Mesh::MeshPy::swapEdge(), tess_shape(), tesselateShape(), Gui::ViewProviderPy::toString(), Mesh::MeshPy::transform(), Base::MatrixPy::transform(), Mesh::MeshPy::translate(), Mesh::MeshPy::unite(), Base::MatrixPy::unity(), Gui::ViewProviderDocumentObjectPy::update(), Gui::DocumentPy::update(), TestGui::UnitTestPy::updateGUI(), useMesh(), wrap_SoQtViewer_setFocalDistance(), Points::PointsPy::write(), and Mesh::MeshPy::write().

#define Py_Error ( E,
 )     {PyErr_SetString(E, M); return NULL;}
#define Py_Header
Value:
public:                                                     \
    static PyTypeObject   Type;                             \
    static PyMethodDef    Methods[];                        \
    static PyParentObject Parents[];                        \
    virtual PyTypeObject *GetType(void) {return &Type;};    \
    virtual PyParentObject *GetParents(void) {return Parents;}

This must be the first line of each PyC++ class.

Definition at line 133 of file PyObjectBase.h.

#define Py_NEWARGS   1

some basic python macros

Definition at line 117 of file PyObjectBase.h.

#define Py_Return   Py_INCREF(Py_None); return Py_None;

return with no retrnvalue if nothin happens

Definition at line 119 of file PyObjectBase.h.

Referenced by App::DocumentPy::abortTransaction(), Gui::WorkbenchPy::activate(), Gui::DocumentPy::activeObject(), Gui::DocumentPy::activeView(), Part::TopoShapeShellPy::add(), Part::TopoShapeCompSolidPy::add(), Part::TopoShapeCompoundPy::add(), Base::BoundBoxPy::add(), Gui::DocumentPy::addAnnotation(), Sketcher::SketchObjectPy::addConstraint(), Gui::ViewProviderPythonFeaturePy::addDisplayMode(), Sketcher::SketchObjectPy::addExternal(), Mesh::MeshPy::addFacet(), Mesh::MeshPy::addFacets(), Sketcher::SketchPy::addGeometry(), Sketcher::SketchObjectPy::addGeometry(), Fem::FemMeshPy::addHypothesis(), Mesh::MeshPy::addMesh(), App::DocumentObjectGroupPy::addObject(), Points::PointsPy::addPoints(), Gui::PythonWorkbenchPy::appendCommandbar(), Gui::PythonWorkbenchPy::appendContextMenu(), Gui::PythonWorkbenchPy::appendMenu(), Gui::PythonWorkbenchPy::appendToolbar(), Part::BSplineCurvePy::approximate(), best_fit_coarse(), best_fit_complete(), best_fit_test(), Part::BSplineCurvePy::buildFromPoles(), calcMeshVolume(), Part::TopoShapePy::check(), checkBB(), Mesh::MeshPy::clear(), TestGui::UnitTestPy::clearErrorList(), App::DocumentPy::clearUndos(), Mesh::MeshPy::collapseEdge(), Mesh::MeshPy::collapseFacet(), Mesh::MeshPy::collapseFacets(), App::DocumentPy::commitTransaction(), Part::TopoShapePy::complement(), Fem::FemMeshPy::compute(), copyResource(), Sketcher::SketchObjectPy::delConstraint(), Sketcher::SketchObjectPy::delConstraintOnPoint(), Sketcher::SketchObjectPy::delGeometry(), Mesh::MeshPy::difference(), Base::BoundBoxPy::enlarge(), TestGui::UnitTestPy::errorDialog(), Part::BSplineSurfacePy::exchangeUV(), Part::BezierSurfacePy::exchangeUV(), Part::TopoShapePy::exportBrep(), exporter(), Part::TopoShapePy::exportIges(), Part::TopoShapePy::exportStep(), Part::TopoShapePy::exportStl(), Sketcher::SketchObjectPy::fillet(), Mesh::MeshPy::fillupHoles(), Gui::ViewProviderPy::finishEditing(), fit_iter(), Mesh::MeshPy::fixDeformations(), Mesh::MeshPy::fixDegenerations(), Mesh::MeshFeaturePy::fixDegenerations(), Mesh::MeshPy::fixIndices(), Mesh::MeshFeaturePy::fixIndices(), Mesh::MeshPy::fixSelfIntersections(), Mesh::MeshFeaturePy::fixSelfIntersections(), Mesh::MeshPy::flipNormals(), getBoundary_Conditions(), Gui::DocumentPy::getObject(), App::DocumentPy::getObject(), App::DocumentObjectGroupPy::getObject(), App::PropertyLink::getPyObject(), Base::BaseClass::getPyObject(), Mesh::MeshPy::harmonizeNormals(), Mesh::MeshFeaturePy::harmonizeNormals(), Gui::ViewProviderPy::hide(), Gui::DocumentPy::hide(), import_NASTRAN(), importer(), Part::BezierSurfacePy::increase(), Part::BezierCurvePy::increase(), Part::BSplineSurfacePy::increaseDegree(), Part::BSplineCurvePy::increaseDegree(), Part::BSplineCurvePy::increaseMultiplicity(), Part::BSplineSurfacePy::increaseUMultiplicity(), Part::BSplineSurfacePy::increaseVMultiplicity(), Part::BSplineCurvePy::incrementMultiplicity(), Part::BSplineSurfacePy::incrementUMultiplicity(), Part::BSplineSurfacePy::incrementVMultiplicity(), Mesh::MeshPy::inner(), insert(), TestGui::UnitTestPy::insertError(), Part::BSplineCurvePy::insertKnot(), Part::BSplineCurvePy::insertKnots(), Part::BezierCurvePy::insertPoleAfter(), Part::BezierCurvePy::insertPoleBefore(), Part::BezierSurfacePy::insertPoleColAfter(), Part::BezierSurfacePy::insertPoleColBefore(), Part::BezierSurfacePy::insertPoleRowAfter(), Part::BezierSurfacePy::insertPoleRowBefore(), Part::BSplineSurfacePy::insertUKnot(), Part::BSplineSurfacePy::insertUKnots(), Mesh::MeshPy::insertVertex(), Part::BSplineSurfacePy::insertVKnot(), Part::BSplineSurfacePy::insertVKnots(), Part::BSplineCurvePy::interpolate(), Mesh::MeshPy::intersect(), Base::MatrixPy::inverse(), Base::RotationPy::invert(), Base::MatrixPy::invert(), Part::BSplineCurvePy::makeC1Continuous(), Part::TopoShapePy::makeShapeFromMesh(), minBoundingBox(), Part::GeometryPy::mirror(), Base::PlacementPy::move(), Mesh::MeshPointPy::move(), Base::MatrixPy::move(), Base::BoundBoxPy::move(), Sketcher::SketchObjectPy::movePoint(), Part::TopoShapePy::nullify(), Mesh::MeshPy::offset(), offset_mesh(), Mesh::MeshPy::offsetSpecial(), open(), openBrowser(), openBrowserHTML(), openDYNA(), App::DocumentPy::openTransaction(), Mesh::MeshPy::optimizeEdges(), Mesh::MeshPy::optimizeTopology(), Mesh::MeshPy::outer(), App::DocumentObjectPy::purgeTouched(), Part::TopoShapePy::read(), Points::PointsPy::read(), Mesh::MeshPy::read(), Fem::FemMeshPy::read(), read(), App::DocumentPy::recompute(), App::DocumentPy::redo(), Mesh::MeshPy::refine(), Gui::PythonWorkbenchPy::removeCommandbar(), Mesh::MeshPy::removeComponents(), Gui::PythonWorkbenchPy::removeContextMenu(), Mesh::MeshPy::removeDuplicatedFacets(), Mesh::MeshFeaturePy::removeDuplicatedFacets(), Mesh::MeshPy::removeDuplicatedPoints(), Mesh::MeshFeaturePy::removeDuplicatedPoints(), Mesh::MeshPy::removeFacets(), Mesh::MeshPy::removeFoldsOnSurface(), Mesh::MeshFeaturePy::removeFoldsOnSurface(), Gui::PythonWorkbenchPy::removeMenu(), Mesh::MeshPy::removeNonManifolds(), Mesh::MeshFeaturePy::removeNonManifolds(), App::DocumentPy::removeObject(), App::DocumentObjectGroupPy::removeObject(), App::DocumentObjectGroupPy::removeObjectsFromDocument(), Part::BezierCurvePy::removePole(), Part::BezierSurfacePy::removePoleCol(), Part::BezierSurfacePy::removePoleRow(), Gui::PythonWorkbenchPy::removeToolbar(), Gui::DocumentPy::resetEdit(), App::DocumentPy::restore(), Part::TopoShapePy::reverse(), Part::TopoShapePy::rotate(), Mesh::MeshPy::rotate(), Part::GeometryPy::rotate(), Base::MatrixPy::rotateX(), Base::MatrixPy::rotateY(), Base::MatrixPy::rotateZ(), Gui::Application::sActiveDocument(), Gui::SelectionSingleton::sAddSelection(), Gui::SelectionSingleton::saddSelectionGate(), Gui::SelectionSingleton::sAddSelObserver(), App::DocumentPy::save(), Part::TopoShapePy::scale(), Base::MatrixPy::scale(), Part::GeometryPy::scale(), Gui::SelectionSingleton::sClearSelection(), Part::BSplineSurfacePy::segment(), Part::BSplineCurvePy::segment(), Part::BezierSurfacePy::segment(), Part::BezierCurvePy::segment(), App::MaterialPy::set(), Sketcher::SketchObjectPy::setDatum(), Gui::DocumentPy::setEdit(), TestGui::UnitTestPy::setErrorCount(), TestGui::UnitTestPy::setFailCount(), Part::BSplineCurvePy::setKnot(), Part::BSplineCurvePy::setKnots(), Part::BSplineCurvePy::setNotPeriodic(), Part::BSplineCurvePy::setOrigin(), Part::LinePy::setParameterRange(), Part::BSplineCurvePy::setPeriodic(), Mesh::MeshPy::setPoint(), Part::BSplineSurfacePy::setPole(), Part::BSplineCurvePy::setPole(), Part::BezierSurfacePy::setPole(), Part::BezierCurvePy::setPole(), Part::BSplineSurfacePy::setPoleCol(), Part::BezierSurfacePy::setPoleCol(), Part::BSplineSurfacePy::setPoleRow(), Part::BezierSurfacePy::setPoleRow(), Part::BezierCurvePy::setPoles(), Gui::DocumentPy::setPos(), TestGui::UnitTestPy::setProgressFraction(), TestGui::UnitTestPy::setRemainCount(), TestGui::UnitTestPy::setRunCount(), Fem::FemMeshPy::setShape(), Fem::FemMeshPy::setStanardHypotheses(), TestGui::UnitTestPy::setStatusText(), Part::TopoShapeVertexPy::setTolerance(), Part::TopoShapeFacePy::setTolerance(), Part::TopoShapeEdgePy::setTolerance(), Fem::FemMeshPy::setTransform(), Gui::ViewProviderPy::setTransformation(), Part::BSplineSurfacePy::setUKnot(), Part::BSplineSurfacePy::setUKnots(), TestGui::UnitTestPy::setUnitTest(), Part::BSplineSurfacePy::setUNotPeriodic(), Part::BSplineSurfacePy::setUOrigin(), Part::BSplineSurfacePy::setUPeriodic(), Part::BSplineSurfacePy::setVKnot(), Part::BSplineSurfacePy::setVKnots(), Part::BSplineSurfacePy::setVNotPeriodic(), Part::BSplineSurfacePy::setVOrigin(), Part::BSplineSurfacePy::setVPeriodic(), Part::BSplineSurfacePy::setWeight(), Part::BSplineCurvePy::setWeight(), Part::BezierSurfacePy::setWeight(), Part::BezierCurvePy::setWeight(), Part::BSplineSurfacePy::setWeightCol(), Part::BezierSurfacePy::setWeightCol(), Part::BSplineSurfacePy::setWeightRow(), Part::BezierSurfacePy::setWeightRow(), Part::TopoShapePy::sewShape(), Gui::Application::sExport(), shape2orig(), Gui::Application::sHide(), Gui::Application::sHideObject(), Gui::ViewProviderPy::show(), Gui::DocumentPy::show(), show(), Gui::Application::sInsert(), SMESH_PCA(), Mesh::MeshPy::smooth(), Mesh::MeshFeaturePy::smooth(), Mesh::MeshPy::snapVertex(), Gui::Application::sOpen(), Mesh::MeshPy::splitEdge(), Mesh::MeshPy::splitEdges(), Mesh::MeshPy::splitFacet(), spring_back(), Gui::SelectionSingleton::sRemoveSelection(), Gui::SelectionSingleton::sremoveSelectionGate(), Gui::SelectionSingleton::sRemSelObserver(), Gui::Application::sShow(), Gui::Application::sShowObject(), Mesh::MeshPy::swapEdge(), tess_shape(), tesselateShape(), Sketcher::SketchObjectPy::toggleConstruction(), App::DocumentObjectPy::touch(), Mesh::MeshPy::transform(), Base::MatrixPy::transform(), Part::GeometryPy::transform(), Part::TopoShapePy::transformShape(), Mesh::MeshPy::transformToEigen(), Part::TopoShapePy::translate(), Mesh::MeshPy::translate(), Part::GeometryPy::translate(), Sketcher::SketchObjectPy::trim(), Mesh::MeshPointPy::unbound(), Mesh::FacetPy::unbound(), App::DocumentPy::undo(), Mesh::MeshPy::unite(), Base::MatrixPy::unity(), Gui::ViewProviderDocumentObjectPy::update(), Gui::DocumentPy::update(), TestGui::UnitTestPy::updateGUI(), useMesh(), wrap_SoQtViewer_setFocalDistance(), Points::PointsPy::write(), Mesh::MeshPy::write(), Fem::FemMeshPy::write(), Fem::FemMeshPy::writeABAQUS(), writeCameraFile(), writeDataFile(), writePartFile(), writePartFileCSV(), and writeProjectFile().

#define PY_TRY   try

Exception handling for python callback functions Is a convenience macro to manage the exception handling of python callback functions defined in classes inheriting PyObjectBase and using PYMETHODEDEF .

You can automate this:

 PYFUNCIMP_D(DocTypeStdPy,AddFeature)
 {
   char *pstr;
   if (!PyArg_ParseTuple(args, "s", &pstr))     // convert args: Python->C 
      return NULL;                             // NULL triggers exception 
 
   try {
     Feature *pcFtr = _pcDocTypeStd->AddFeature(pstr);
   }catch(...)                                                        \
   {                                                                 \
                Py_Error(PyExc_Exception,"Unknown C++ exception");          \
   }catch(FCException e) ..... // and so on....                                                               \
 }

with that:

 PYFUNCIMP_D(DocTypeStdPy,AddFeature)
 {
   char *pstr;
   if (!PyArg_ParseTuple(args, "s", &pstr))     // convert args: Python->C 
      return NULL;                             // NULL triggers exception 
 
  PY_TRY {
    Feature *pcFtr = _pcDocTypeStd->AddFeature(pstr);
  }PY_CATCH;
 }

this catch maps all of the FreeCAD standard exception to a clear output for the Python exception.

See also:
PYMETHODEDEF
PyObjectBase

Definition at line 410 of file PyObjectBase.h.

Referenced by Gui::WorkbenchPy::activate(), Gui::DocumentPy::activeObject(), Gui::DocumentPy::activeView(), Gui::DocumentPy::addAnnotation(), Gui::ViewProviderPythonFeaturePy::addDisplayMode(), Mesh::MeshPy::addMesh(), Gui::PythonWorkbenchPy::appendCommandbar(), Gui::PythonWorkbenchPy::appendContextMenu(), Gui::PythonWorkbenchPy::appendMenu(), Gui::PythonWorkbenchPy::appendToolbar(), approxSurface(), best_fit_coarse(), best_fit_complete(), best_fit_test(), calcMeshVolume(), TestGui::UnitTestPy::clearErrorList(), Mesh::MeshPy::collapseEdge(), Mesh::MeshPy::collapseFacet(), createBox(), createCone(), createCylinder(), createEllipsoid(), createPlane(), createSphere(), createTestApproximate(), createTestBSPLINE(), createTorus(), Mesh::MeshPy::difference(), TestGui::UnitTestPy::errorDialog(), exporter(), fit_iter(), Mesh::MeshPy::fixDeformations(), Mesh::MeshPy::fixDegenerations(), Mesh::MeshFeaturePy::fixDegenerations(), Mesh::MeshPy::fixIndices(), Mesh::MeshFeaturePy::fixIndices(), Mesh::MeshPy::flipNormals(), getBoundary_Conditions(), Gui::ViewProviderPythonFeaturePy::getCustomAttributes(), Part::FeaturePythonPy::getCustomAttributes(), Mesh::FeaturePythonPy::getCustomAttributes(), App::FeaturePythonPy::getCustomAttributes(), Gui::DocumentPy::getObject(), TestGui::UnitTestPy::getUnitTest(), Mesh::MeshPy::harmonizeNormals(), Mesh::MeshFeaturePy::harmonizeNormals(), Gui::ViewProviderPy::hide(), Gui::DocumentPy::hide(), import_NASTRAN(), importer(), Mesh::MeshPy::inner(), insert(), TestGui::UnitTestPy::insertError(), Mesh::MeshPy::insertVertex(), Mesh::MeshPy::intersect(), Base::MatrixPy::inverse(), Base::MatrixPy::invert(), Gui::ViewProviderPy::isVisible(), Gui::PythonWorkbenchPy::listCommandbars(), Gui::ViewProviderPy::listDisplayModes(), Gui::PythonWorkbenchPy::listMenus(), Gui::PythonWorkbenchPy::listToolbars(), loftOnCurve(), makeCompound(), makeFilledFace(), makePolygon(), makeShell(), minBoundingBox(), Base::MatrixPy::move(), Gui::WorkbenchPy::name(), Mesh::MeshPy::offset(), offset(), offset_mesh(), Mesh::MeshPy::offsetSpecial(), open(), openBrowser(), openBrowserHTML(), openDYNA(), Mesh::MeshPy::optimizeEdges(), Mesh::MeshPy::optimizeTopology(), Mesh::MeshPy::outer(), povViewCamera(), project(), projectEx(), projectToDXF(), projectToSVG(), Points::PointsPy::read(), Mesh::MeshPy::read(), read(), Mesh::MeshPy::refine(), Gui::PythonWorkbenchPy::removeCommandbar(), Mesh::MeshPy::removeComponents(), Gui::PythonWorkbenchPy::removeContextMenu(), Mesh::MeshPy::removeDuplicatedFacets(), Mesh::MeshFeaturePy::removeDuplicatedFacets(), Mesh::MeshPy::removeDuplicatedPoints(), Mesh::MeshFeaturePy::removeDuplicatedPoints(), Gui::PythonWorkbenchPy::removeMenu(), Gui::PythonWorkbenchPy::removeToolbar(), Mesh::MeshPy::rotate(), Base::MatrixPy::rotateX(), Base::MatrixPy::rotateY(), Base::MatrixPy::rotateZ(), Gui::SelectionSingleton::saddSelectionGate(), Gui::SelectionSingleton::sAddSelObserver(), Base::MatrixPy::scale(), TestGui::UnitTestPy::setErrorCount(), TestGui::UnitTestPy::setFailCount(), Mesh::MeshPy::setPoint(), Gui::DocumentPy::setPos(), TestGui::UnitTestPy::setProgressFraction(), TestGui::UnitTestPy::setRemainCount(), TestGui::UnitTestPy::setRunCount(), TestGui::UnitTestPy::setStatusText(), TestGui::UnitTestPy::setUnitTest(), Gui::Application::sExport(), shape2orig(), Gui::ViewProviderPy::show(), Gui::DocumentPy::show(), show(), simulateToFile(), Gui::Application::sInsert(), SMESH_PCA(), Mesh::MeshPy::smooth(), Mesh::MeshFeaturePy::smooth(), Mesh::MeshPy::snapVertex(), Gui::Application::sOpen(), Mesh::MeshPy::splitEdge(), Mesh::MeshPy::splitEdges(), Mesh::MeshPy::splitFacet(), spring_back(), Base::ConsoleSingleton::sPyError(), Base::ConsoleSingleton::sPyGetStatus(), Base::ConsoleSingleton::sPyLog(), Base::ConsoleSingleton::sPyMessage(), Base::ConsoleSingleton::sPySetStatus(), Base::ConsoleSingleton::sPyWarning(), Gui::SelectionSingleton::sremoveSelectionGate(), Gui::SelectionSingleton::sRemSelObserver(), Mesh::MeshPy::swapEdge(), tess_shape(), tesselateShape(), Gui::ViewProviderPy::toString(), Mesh::MeshPy::transform(), Base::MatrixPy::transform(), Mesh::MeshPy::translate(), Mesh::MeshPy::unite(), Base::MatrixPy::unity(), Gui::ViewProviderDocumentObjectPy::update(), Gui::DocumentPy::update(), TestGui::UnitTestPy::updateGUI(), useMesh(), wrap_SoQtViewer_setFocalDistance(), Points::PointsPy::write(), and Mesh::MeshPy::write().

#define Py_Try (  )     {if (!(F)) return NULL;}

checks on a condition and returns an error on failure

Definition at line 123 of file PyObjectBase.h.

#define PYFUNCDEF_D ( CLASS,
DFUNC   ) 
Value:
PyObject * DFUNC (PyObject *args);  \
static PyObject * s##DFUNC (PyObject *self, PyObject *args, PyObject * /*kwd*/){return (( CLASS *)self)-> DFUNC (args);};

Python dynamic class macro for definition sets up a static/dynamic function entry in a class inheriting from PyObjectBase.

Its a pure convenience macro. You can also do it by hand if you want. It looks like that:

 PyObject *PyGetGrp(PyObject *args);
 static PyObject *sPyGetGrp(PyObject *self, PyObject *args, PyObject *kwd)
        {return ((FCPyParametrGrp*)self)->PyGetGrp(args);};

first the method is defined which have the functionality then the static wrapper is used to provide a callback for python. The call is simply mapped to the method.

Parameters:
CLASS is the class in which the macro take place.
DFUNC is the object method get defined and called sDFUNC is the static method name (use what you want)
See also:
PYFUNCIMP_D
PyObjectBase

Definition at line 326 of file PyObjectBase.h.

#define PYFUNCDEF_S ( SFUNC   )     static PyObject* SFUNC (PyObject *self,PyObject *args,PyObject *kwd);

Python static class macro for definition sets up a static function entry in a class inheriting from PyObjectBase.

Its a pure convenience macro. You can also do it by hand if you want. It looks like that:

 static PyObject* X (PyObject *self,PyObject *args,PyObject *kwd);
Parameters:
SFUNC is the static method name (use what you want)
See also:
PYFUNCIMP_S
FCPythonExport

Definition at line 60 of file PyObjectBase.h.

#define PYFUNCIMP_D ( CLASS,
DFUNC   )     PyObject* CLASS::DFUNC (PyObject *args)

Python dynamic class macro for implementation used to set up a impementation for PYFUNCDEF_D definition.

Its a pure confiniance macro. You can also do it by hand if you want. It looks like that:

 PyObject *FCPyParametrGrp::PyGetGrp(PyObject *args)

see PYFUNCDEF_D for details *

Parameters:
CLASS is the class in which the macro take place.
DFUNC is the object method get defined and called
See also:
PYFUNCDEF_D
PyObjectBase

Definition at line 341 of file PyObjectBase.h.

#define PYFUNCIMP_S ( CLASS,
SFUNC   )     PyObject* CLASS::SFUNC (PyObject *self,PyObject *args,PyObject *kwd)

Python static class macro for implementation used to set up a implementation for PYFUNCDEF_S definition.

Its a pure confiniance macro. You can also do it by hand if you want. It looks like that:

 PyObject* CLASS::SFUNC (PyObject *self,PyObject *args,PyObject *kwd)

see PYFUNCDEF_S for details

Parameters:
CLASS is the class in which the macro take place.
SFUNC is the object method get implemented
See also:
PYFUNCDEF_S
FCPythonExport

Definition at line 76 of file PyObjectBase.h.

#define PYMETHODEDEF ( FUNC   )     {"" #FUNC "",(PyCFunction) s##FUNC,Py_NEWARGS},

Python dynamic class macro for the method list used to fill the method list of a class derived from PyObjectBase.

Its a pure confiniance macro. You can also do it by hand if you want. It looks like that:

 PyMethodDef DocTypeStdPy::Methods[] = {
        {"AddFeature",    (PyCFunction) sAddFeature,    Py_NEWARGS},
        {"RemoveFeature", (PyCFunction) sRemoveFeature, Py_NEWARGS},
        {NULL, NULL}            
 };

instead of:

 PyMethodDef DocTypeStdPy::Methods[] = {
        PYMETHODEDEF(AddFeature)
        PYMETHODEDEF(RemoveFeature)
        {NULL, NULL}            
 };

see PYFUNCDEF_D for details

Parameters:
FUNC is the object method get defined
See also:
PYFUNCDEF_D
PyObjectBase

Definition at line 369 of file PyObjectBase.h.

#define slots

Definition at line 39 of file PyObjectBase.h.


Typedef Documentation

typedef PyTypeObject* PyParentObject

Define the PyParent Object.

Definition at line 129 of file PyObjectBase.h.


Generated on Wed Nov 23 19:01:20 2011 for FreeCAD by  doxygen 1.6.1