[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [21921] branches/soc-2008-mxcurioni/source /blender/freestyle/intern/python: Implemented Python wrappers of context functions (such as GetTimeStampCF).

Tamito Kajiyama rd6t-kjym at asahi-net.or.jp
Sun Jul 26 13:19:39 CEST 2009


Revision: 21921
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=21921
Author:   kjym3
Date:     2009-07-26 13:19:37 +0200 (Sun, 26 Jul 2009)

Log Message:
-----------
Implemented Python wrappers of context functions (such as GetTimeStampCF).

Modified Paths:
--------------
    branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/BPy_Freestyle.cpp

Added Paths:
-----------
    branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/BPy_ContextFunctions.cpp
    branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/BPy_ContextFunctions.h

Added: branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/BPy_ContextFunctions.cpp
===================================================================
--- branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/BPy_ContextFunctions.cpp	                        (rev 0)
+++ branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/BPy_ContextFunctions.cpp	2009-07-26 11:19:37 UTC (rev 21921)
@@ -0,0 +1,156 @@
+#include "BPy_ContextFunctions.h"
+#include "BPy_Convert.h"
+
+#include "../stroke/ContextFunctions.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+  
+///////////////////////////////////////////////////////////////////////////////////////////
+
+/*-----------------------Python API function prototypes for the ContextFunctions module--*/
+
+static PyObject * ContextFunctions_GetTimeStampCF( PyObject* self );
+static PyObject * ContextFunctions_GetCanvasWidthCF( PyObject* self );
+static PyObject * ContextFunctions_GetCanvasHeightCF( PyObject* self );
+static PyObject * ContextFunctions_LoadMapCF( PyObject *self, PyObject *args );
+static PyObject * ContextFunctions_ReadMapPixelCF( PyObject *self, PyObject *args );
+static PyObject * ContextFunctions_ReadCompleteViewMapPixelCF( PyObject *self, PyObject *args );
+static PyObject * ContextFunctions_ReadDirectionalViewMapPixelCF( PyObject *self, PyObject *args );
+static PyObject * ContextFunctions_GetSelectedFEdgeCF( PyObject *self );
+
+/*-----------------------ContextFunctions module docstring-------------------------------*/
+
+static char module_docstring[] = "The Blender.Freestyle.ContextFunctions submodule";
+
+/*-----------------------ContextFunctions module functions definitions-------------------*/
+
+static PyMethodDef module_functions[] = {
+  {"GetTimeStampCF", (PyCFunction)ContextFunctions_GetTimeStampCF, METH_NOARGS, ""},
+  {"GetCanvasWidthCF", (PyCFunction)ContextFunctions_GetCanvasWidthCF, METH_NOARGS, ""},
+  {"GetCanvasHeightCF", (PyCFunction)ContextFunctions_GetCanvasHeightCF, METH_NOARGS, ""},
+  {"LoadMapCF", (PyCFunction)ContextFunctions_LoadMapCF, METH_VARARGS, ""},
+  {"ReadMapPixelCF", (PyCFunction)ContextFunctions_ReadMapPixelCF, METH_VARARGS, ""},
+  {"ReadCompleteViewMapPixelCF", (PyCFunction)ContextFunctions_ReadCompleteViewMapPixelCF, METH_VARARGS, ""},
+  {"ReadDirectionalViewMapPixelCF", (PyCFunction)ContextFunctions_ReadDirectionalViewMapPixelCF, METH_VARARGS, ""},
+  {"GetSelectedFEdgeCF", (PyCFunction)ContextFunctions_GetSelectedFEdgeCF, METH_NOARGS, ""},
+  {NULL, NULL, 0, NULL}
+};
+
+//------------------- MODULE INITIALIZATION --------------------------------
+
+void ContextFunctions_Init( PyObject *module )
+{	
+  PyObject *m, *d, *f;
+
+  if( module == NULL )
+    return;
+
+  m = Py_InitModule3("Blender.Freestyle.ContextFunctions", module_functions, module_docstring);
+  if (m == NULL)
+    return;
+  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);
+  }
+}
+
+//------------------------ MODULE FUNCTIONS ----------------------------------
+
+static PyObject *
+ContextFunctions_GetTimeStampCF( PyObject* self )
+{
+  return PyInt_FromLong( ContextFunctions::GetTimeStampCF() );
+}
+
+static PyObject *
+ContextFunctions_GetCanvasWidthCF( PyObject* self )
+{
+  return PyInt_FromLong( ContextFunctions::GetCanvasWidthCF() );
+}
+
+static PyObject *
+ContextFunctions_GetCanvasHeightCF( PyObject* self )
+{
+  return PyInt_FromLong( ContextFunctions::GetCanvasHeightCF() );
+}
+
+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 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 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 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 PyObject *
+ContextFunctions_GetSelectedFEdgeCF( PyObject *self )
+{
+  FEdge *fe = ContextFunctions::GetSelectedFEdgeCF();
+  if( fe )
+    return BPy_FEdge_from_FEdge( *fe );
+
+  Py_RETURN_NONE;
+}
+
+///////////////////////////////////////////////////////////////////////////////////////////
+
+#ifdef __cplusplus
+}
+#endif

Added: branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/BPy_ContextFunctions.h
===================================================================
--- branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/BPy_ContextFunctions.h	                        (rev 0)
+++ branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/BPy_ContextFunctions.h	2009-07-26 11:19:37 UTC (rev 21921)
@@ -0,0 +1,18 @@
+#ifndef FREESTYLE_PYTHON_CONTEXTFUNCTIONS_H
+#define FREESTYLE_PYTHON_CONTEXTFUNCTIONS_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include <Python.h>
+
+/*---------------------------Python BPy_ContextFunctions visible prototypes-----------*/
+
+PyMODINIT_FUNC ContextFunctions_Init( PyObject *module );
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* FREESTYLE_PYTHON_CONTEXTFUNCTIONS_H */

Modified: branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/BPy_Freestyle.cpp
===================================================================
--- branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/BPy_Freestyle.cpp	2009-07-26 11:01:56 UTC (rev 21920)
+++ branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/BPy_Freestyle.cpp	2009-07-26 11:19:37 UTC (rev 21921)
@@ -3,6 +3,7 @@
 #include "BPy_BBox.h"
 #include "BPy_BinaryPredicate0D.h"
 #include "BPy_BinaryPredicate1D.h"
+#include "BPy_ContextFunctions.h"
 #include "BPy_FrsMaterial.h"
 #include "BPy_FrsNoise.h"
 #include "BPy_Id.h"
@@ -147,6 +148,7 @@
 	BBox_Init( module );
 	BinaryPredicate0D_Init( module );
 	BinaryPredicate1D_Init( module );
+	ContextFunctions_Init( module );
 	FrsMaterial_Init( module );
 	FrsNoise_Init( module );
 	Id_Init( module );





More information about the Bf-blender-cvs mailing list