This repository has been archived on 2023-10-09. You can view files and clone it, but cannot push or open issues or pull requests.
Files
blender-archive/source/blender/freestyle/intern/python/BPy_ContextFunctions.cpp

294 lines
9.1 KiB
C++
Raw Normal View History

2013-02-23 18:32:28 +00:00
/*
* ***** BEGIN GPL LICENSE BLOCK *****
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* The Original Code is Copyright (C) 2010 Blender Foundation.
* All rights reserved.
*
* The Original Code is: all of this file.
*
* Contributor(s): none yet.
*
* ***** END GPL LICENSE BLOCK *****
*/
/** \file source/blender/freestyle/intern/python/BPy_ContextFunctions.cpp
* \ingroup freestyle
*/
#include "BPy_ContextFunctions.h"
#include "BPy_Convert.h"
#include "../stroke/ContextFunctions.h"
#ifdef __cplusplus
extern "C" {
#endif
///////////////////////////////////////////////////////////////////////////////////////////
//------------------------ MODULE FUNCTIONS ----------------------------------
static char ContextFunctions_GetTimeStampCF___doc__[] =
".. function:: GetTimeStampCF()\n"
"\n"
" Returns the system time stamp.\n"
"\n"
" :return: The system time stamp.\n"
" :rtype: int\n";
static PyObject *
ContextFunctions_GetTimeStampCF( PyObject* self )
{
return PyLong_FromLong( ContextFunctions::GetTimeStampCF() );
}
static char ContextFunctions_GetCanvasWidthCF___doc__[] =
".. method:: GetCanvasWidthCF()\n"
"\n"
" Returns the canvas width.\n"
"\n"
" :return: The canvas width.\n"
" :rtype: int\n";
static PyObject *
ContextFunctions_GetCanvasWidthCF( PyObject* self )
{
return PyLong_FromLong( ContextFunctions::GetCanvasWidthCF() );
}
static char ContextFunctions_GetCanvasHeightCF___doc__[] =
".. method:: GetCanvasHeightCF()\n"
"\n"
" Returns the canvas height.\n"
"\n"
" :return: The canvas height.\n"
" :rtype: int\n";
static PyObject *
ContextFunctions_GetCanvasHeightCF( PyObject* self )
{
return PyLong_FromLong( ContextFunctions::GetCanvasHeightCF() );
}
static char ContextFunctions_LoadMapCF___doc__[] =
".. function:: LoadMapCF(iFileName, iMapName, iNbLevels=4, iSigma=1.0)\n"
"\n"
" Loads an image map for further reading.\n"
"\n"
" :arg iFileName: The name of the image file.\n"
" :type iFileName: str\n"
" :arg iMapName: The name that will be used to access this image.\n"
" :type iMapName: str\n"
" :arg iNbLevels: The number of levels in the map pyramid\n"
" (default = 4). If iNbLevels == 0, the complete pyramid is\n"
" built.\n"
" :type iNbLevels: int\n"
" :arg iSigma: The sigma value of the gaussian function.\n"
" :type iSigma: float\n";
static PyObject *
ContextFunctions_LoadMapCF( PyObject *self, PyObject *args )
{
char *fileName, *mapName;
unsigned nbLevels;
float sigma;
if( !PyArg_ParseTuple(args, "ssIf", &fileName, &mapName, &nbLevels, &sigma) )
return NULL;
ContextFunctions::LoadMapCF(fileName, mapName, nbLevels, sigma);
Py_RETURN_NONE;
}
static char ContextFunctions_ReadMapPixelCF___doc__[] =
".. function:: ReadMapPixelCF(iMapName, level, x, y)\n"
"\n"
" Reads a pixel in a user-defined map.\n"
"\n"
" :arg iMapName: The name of the map.\n"
" :type iMapName: str\n"
" :arg level: The level of the pyramid in which we wish to read the\n"
" pixel.\n"
" :type level: int\n"
" :arg x: The x coordinate of the pixel we wish to read. The origin\n"
" is in the lower-left corner.\n"
" :type x: int\n"
" :arg y: The y coordinate of the pixel we wish to read. The origin\n"
" is in the lower-left corner.\n"
" :type y: int\n"
" :return: The floating-point value stored for that pixel.\n"
" :rtype: float\n";
static PyObject *
ContextFunctions_ReadMapPixelCF( PyObject *self, PyObject *args )
{
char *mapName;
int level;
unsigned x, y;
if( !PyArg_ParseTuple(args, "siII", &mapName, &level, &x, &y) )
return NULL;
float f = ContextFunctions::ReadMapPixelCF(mapName, level, x, y);
return PyFloat_FromDouble( f );
}
static char ContextFunctions_ReadCompleteViewMapPixelCF___doc__[] =
".. function:: ReadCompleteViewMapPixelCF(level, x, y)\n"
"\n"
" Reads a pixel in the complete view map.\n"
"\n"
" :arg level: The level of the pyramid in which we wish to read the\n"
" pixel.\n"
" :type level: int\n"
" :arg x: The x coordinate of the pixel we wish to read. The origin\n"
" is in the lower-left corner.\n"
" :type x: int\n"
" :arg y: The y coordinate of the pixel we wish to read. The origin\n"
" is in the lower-left corner.\n"
" :type y: int\n"
" :return: The floating-point value stored for that pixel.\n"
" :rtype: float\n";
static PyObject *
ContextFunctions_ReadCompleteViewMapPixelCF( PyObject *self, PyObject *args )
{
int level;
unsigned x, y;
if( !PyArg_ParseTuple(args, "iII", &level, &x, &y) )
return NULL;
float f = ContextFunctions::ReadCompleteViewMapPixelCF(level, x, y);
return PyFloat_FromDouble( f );
}
static char ContextFunctions_ReadDirectionalViewMapPixelCF___doc__[] =
".. function:: ReadDirectionalViewMapPixelCF(iOrientation, level, x, y)\n"
"\n"
" Reads a pixel in one of the oriented view map images.\n"
"\n"
" :arg iOrientation: The number telling which orientation we want to\n"
" check.\n"
" :type iOrientation: int\n"
" :arg level: The level of the pyramid in which we wish to read the\n"
" pixel.\n"
" :type level: int\n"
" :arg x: The x coordinate of the pixel we wish to read. The origin\n"
" is in the lower-left corner.\n"
" :type x: int\n"
" :arg y: The y coordinate of the pixel we wish to read. The origin\n"
" is in the lower-left corner.\n"
" :type y: int\n"
" :return: The floating-point value stored for that pixel.\n"
" :rtype: float\n";
static PyObject *
ContextFunctions_ReadDirectionalViewMapPixelCF( PyObject *self, PyObject *args )
{
int orientation, level;
unsigned x, y;
if( !PyArg_ParseTuple(args, "iiII", &orientation, &level, &x, &y) )
return NULL;
float f = ContextFunctions::ReadDirectionalViewMapPixelCF(orientation, level, x, y);
return PyFloat_FromDouble( f );
}
static char ContextFunctions_GetSelectedFEdgeCF___doc__[] =
".. function:: GetSelectedFEdgeCF()\n"
"\n"
" Returns the selected FEdge.\n"
"\n"
" :return: The selected FEdge.\n"
" :rtype: :class:`FEdge`\n";
static PyObject *
ContextFunctions_GetSelectedFEdgeCF( PyObject *self )
{
FEdge *fe = ContextFunctions::GetSelectedFEdgeCF();
if( fe )
SWIG/directors dependency removal (cont'd) * Added to python/BPy_Convert.{cpp,h} 4 utility converters below for better introspection-based automatic type conversion. PyObject * Any_BPy_Interface0D_from_Interface0D( Interface0D& if0D ); PyObject * Any_BPy_Interface1D_from_Interface1D( Interface1D& if1D ); PyObject * Any_BPy_FEdge_from_FEdge( FEdge& fe ); PyObject * Any_BPy_ViewVertex_from_ViewVertex( ViewVertex& vv ); There are 4 corresponding converters without the "Any_" prefix. All calls of them in the code base were replaced with these new converters so that the introspection-based automatic conversion would take place universally. * python/BPy_Convert.{cpp,h}: Those C++ to Python converters having had a "_ptr" suffix were renamed to a name without the suffix, and their arguments were changed so as to take a reference (e.g., ViewVertex&) instead of a pointer (e.g., ViewVertex *). The changed converters and their new function prototypes are listed below. These converters now return a Python wrapper object that retains the passed reference, instead of retaining a newly created C++ object by the converters. // Interface0D converters PyObject * BPy_Interface0D_from_Interface0D( Interface0D& if0D ); PyObject * BPy_CurvePoint_from_CurvePoint( CurvePoint& cp ); PyObject * BPy_StrokeVertex_from_StrokeVertex( StrokeVertex& sv ); PyObject * BPy_SVertex_from_SVertex( SVertex& sv ); PyObject * BPy_ViewVertex_from_ViewVertex( ViewVertex& vv ); PyObject * BPy_TVertex_from_TVertex( TVertex& tv ); PyObject * BPy_NonTVertex_from_NonTVertex( NonTVertex& ntv ); // Interface1D converters PyObject * BPy_Interface1D_from_Interface1D( Interface1D& if1D ); PyObject * BPy_Chain_from_Chain( Chain& c ); PyObject * BPy_FEdge_from_FEdge( FEdge& fe ); PyObject * BPy_FEdgeSharp_from_FEdgeSharp( FEdgeSharp& fes ); PyObject * BPy_FEdgeSmooth_from_FEdgeSmooth( FEdgeSmooth& fes ); PyObject * BPy_Stroke_from_Stroke( Stroke& s ); PyObject * BPy_ViewEdge_from_ViewEdge( ViewEdge& ve ); PyObject * BPy_directedViewEdge_from_directedViewEdge( ViewVertex::directedViewEdge& dve ); // some other converters PyObject * BPy_ViewShape_from_ViewShape( ViewShape& vs ); PyObject * BPy_SShape_from_SShape( SShape& ss ); PyObject * BPy_FrsMaterial_from_FrsMaterial( FrsMaterial& m ); PyObject * BPy_StrokeAttribute_from_StrokeAttribute( StrokeAttribute& sa ); * Added a "borrowed" flag to the definitions of Python types being used to wrap C++ components of Freestyle's internal data structures. The flag indicates whether or not a Python wrapper object has a reference to a C++ object that comprises the internal data structures. The deallocation routines of the Python types check this flag and release a wrapped C++ object only when it is not part of the internal data structures. The following files were modified: python/BPy_FrsMaterial.{cpp,h} python/BPy_Interface0D.{cpp,h} python/BPy_Interface1D.{cpp,h} python/BPy_SShape.{cpp,h} python/BPy_StrokeAttribute.{cpp,h} python/BPy_ViewShape.{cpp,h} python/Interface0D/BPy_CurvePoint.cpp python/Interface0D/BPy_SVertex.cpp python/Interface0D/BPy_ViewVertex.cpp python/Interface0D/CurvePoint/BPy_StrokeVertex.cpp python/Interface0D/ViewVertex/BPy_NonTVertex.cpp python/Interface0D/ViewVertex/BPy_TVertex.cpp python/Interface1D/BPy_FEdge.cpp python/Interface1D/BPy_FrsCurve.cpp python/Interface1D/BPy_Stroke.cpp python/Interface1D/BPy_ViewEdge.cpp python/Interface1D/Curve/BPy_Chain.cpp python/Interface1D/FEdge/BPy_FEdgeSharp.cpp python/Interface1D/FEdge/BPy_FEdgeSmooth.cpp * view_map/Interface[01]D.h, python/BPy_Interface[01]D.cpp: Removed from the Interface0D and Interface1D C++ classes a back pointer to a Python wrapper object and all "director" calls. These classes (and their subclasses) are used to build Freestyle's main data structures (such as a view map and strokes) and their class hierarchy is static. Python wrappers of these C++ classes are only used to access the data structures from the Python layer, and not intended to extend the data structures by subclassing the Python wrappers. Without the necessity of subclassing in the Python layer, the back pointer to a wrapping Python object and "director" calls would be useless (actually they were not used at all), so they were all removed. * python/Director.{cpp,h}: Removed the definitions of directors that were no longer used. * stroke/Stroke.{cpp,h}: Removed an (unused) back pointer to a Python wrapper object. * python/BPy_ViewMap.cpp: Fixed a possible null pointer reference. * python/Interface1D/BPy_FEdge.cpp: Fixed parameter checking in FEdge___init__().
2009-08-02 16:23:18 +00:00
return Any_BPy_FEdge_from_FEdge( *fe );
Py_RETURN_NONE;
}
/*-----------------------ContextFunctions module docstring-------------------------------*/
static char module_docstring[] = "The Blender Freestyle.ContextFunctions submodule\n\n";
/*-----------------------ContextFunctions module functions definitions-------------------*/
static PyMethodDef module_functions[] = {
{"GetTimeStampCF", (PyCFunction)ContextFunctions_GetTimeStampCF, METH_NOARGS, ContextFunctions_GetTimeStampCF___doc__},
{"GetCanvasWidthCF", (PyCFunction)ContextFunctions_GetCanvasWidthCF, METH_NOARGS, ContextFunctions_GetCanvasWidthCF___doc__},
{"GetCanvasHeightCF", (PyCFunction)ContextFunctions_GetCanvasHeightCF, METH_NOARGS, ContextFunctions_GetCanvasHeightCF___doc__},
{"LoadMapCF", (PyCFunction)ContextFunctions_LoadMapCF, METH_VARARGS, ContextFunctions_LoadMapCF___doc__},
{"ReadMapPixelCF", (PyCFunction)ContextFunctions_ReadMapPixelCF, METH_VARARGS, ContextFunctions_ReadMapPixelCF___doc__},
{"ReadCompleteViewMapPixelCF", (PyCFunction)ContextFunctions_ReadCompleteViewMapPixelCF, METH_VARARGS, ContextFunctions_ReadCompleteViewMapPixelCF___doc__},
{"ReadDirectionalViewMapPixelCF", (PyCFunction)ContextFunctions_ReadDirectionalViewMapPixelCF, METH_VARARGS, ContextFunctions_ReadDirectionalViewMapPixelCF___doc__},
{"GetSelectedFEdgeCF", (PyCFunction)ContextFunctions_GetSelectedFEdgeCF, METH_NOARGS, ContextFunctions_GetSelectedFEdgeCF___doc__},
{NULL, NULL, 0, NULL}
};
/*-----------------------ContextFunctions module definition--------------------------------*/
static PyModuleDef module_definition = {
PyModuleDef_HEAD_INIT,
"Freestyle.ContextFunctions",
module_docstring,
-1,
module_functions
};
//------------------- MODULE INITIALIZATION --------------------------------
int ContextFunctions_Init( PyObject *module )
{
PyObject *m, *d, *f;
if( module == NULL )
return -1;
m = PyModule_Create(&module_definition);
if (m == NULL)
return -1;
Py_INCREF(m);
PyModule_AddObject(module, "ContextFunctions", m);
// from ContextFunctions import *
d = PyModule_GetDict(m);
for (PyMethodDef *p = module_functions; p->ml_name; p++) {
f = PyDict_GetItemString(d, p->ml_name);
Py_INCREF(f);
PyModule_AddObject(module, p->ml_name, f);
}
return 0;
}
///////////////////////////////////////////////////////////////////////////////////////////
#ifdef __cplusplus
}
#endif