Merged
https://svn.blender.org/svnroot/bf-blender/branches/soc-2008-mxcurioni (r22789) and https://svn.blender.org/svnroot/bf-blender/trunk/blender (r23338) with the "Ignore ancestry" and "Ignore line endings" options enabled (using TortoiseSVN on Windows). After the merge operation, all changes (i.e., deletion) in source/blender/freestyle/ were reverted in order to keep the primary source tree of the Freestyle renderer.
This commit is contained in:
@@ -36,8 +36,7 @@ extern char btempdir[]; /* use this to store a valid temp directory */
|
||||
struct Text; /* defined in DNA_text_types.h */
|
||||
struct ID; /* DNA_ID.h */
|
||||
struct Object; /* DNA_object_types.h */
|
||||
struct IpoDriver; /* DNA_curve_types.h */
|
||||
struct ScriptLink; /* DNA_scriptlink_types.h */
|
||||
struct ChannelDriver; /* DNA_anim_types.h */
|
||||
struct ListBase; /* DNA_listBase.h */
|
||||
struct SpaceText; /* DNA_space_types.h */
|
||||
struct SpaceScript; /* DNA_space_types.h */
|
||||
@@ -49,6 +48,9 @@ struct bConstraintOb; /* DNA_constraint_types.h */
|
||||
struct bConstraintTarget; /* DNA_constraint_types.h*/
|
||||
struct Script; /* DNA_screen_types.h */
|
||||
struct BPyMenu;
|
||||
struct bContext;
|
||||
struct ReportList;
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
@@ -94,17 +96,20 @@ extern "C" {
|
||||
int BPY_menu_do_python( short menutype, int event );
|
||||
int BPY_menu_do_shortcut( short menutype, unsigned short key, unsigned short modifiers );
|
||||
int BPY_menu_invoke( struct BPyMenu *pym, short menutype );
|
||||
void BPY_run_python_script( const char *filename );
|
||||
|
||||
/* 2.5 UI Scripts */
|
||||
int BPY_run_python_script( struct bContext *C, const char *filename, struct Text *text, struct ReportList *reports ); // 2.5 working
|
||||
int BPY_run_script_space_draw(const struct bContext *C, struct SpaceScript * sc); // 2.5 working
|
||||
void BPY_run_ui_scripts(struct bContext *C, int reload);
|
||||
// int BPY_run_script_space_listener(struct bContext *C, struct SpaceScript * sc, struct ARegion *ar, struct wmNotifier *wmn); // 2.5 working
|
||||
void BPY_update_modules( void ); // XXX - annoying, need this for pointers that get out of date
|
||||
|
||||
|
||||
|
||||
int BPY_run_script(struct Script *script);
|
||||
void BPY_free_compiled_text( struct Text *text );
|
||||
|
||||
void BPY_clear_bad_scriptlinks( struct Text *byebye );
|
||||
int BPY_has_onload_script( void );
|
||||
void BPY_do_all_scripts( short event, short anim );
|
||||
int BPY_check_all_scriptlinks( struct Text *text );
|
||||
void BPY_do_pyscript( struct ID *id, short event );
|
||||
void BPY_free_scriptlink( struct ScriptLink *slink );
|
||||
void BPY_copy_scriptlink( struct ScriptLink *scriptlink );
|
||||
|
||||
int BPY_is_spacehandler(struct Text *text, char spacetype);
|
||||
int BPY_del_spacehandler(struct Text *text, struct ScrArea *sa);
|
||||
@@ -115,10 +120,9 @@ extern "C" {
|
||||
short eventValue, unsigned short space_event);
|
||||
|
||||
void BPY_pydriver_update(void);
|
||||
float BPY_pydriver_eval(struct IpoDriver *driver);
|
||||
struct Object **BPY_pydriver_get_objects(struct IpoDriver *driver);
|
||||
float BPY_pydriver_eval(struct ChannelDriver *driver);
|
||||
|
||||
int BPY_button_eval(char *expr, double *value);
|
||||
int BPY_button_eval(struct bContext *C, char *expr, double *value);
|
||||
|
||||
/* format importer hook */
|
||||
int BPY_call_importloader( char *name );
|
||||
@@ -131,10 +135,9 @@ extern "C" {
|
||||
void BPY_scripts_clear_pyobjects( void );
|
||||
|
||||
void error_pyscript( void );
|
||||
|
||||
void BPY_DECREF(void *pyob_ptr); /* Py_DECREF() */
|
||||
|
||||
/* void BPY_Err_Handle(struct Text *text); */
|
||||
/* void BPY_clear_bad_scriptlink(struct ID *id, struct Text *byebye); */
|
||||
/* void BPY_clear_bad_scriptlist(struct ListBase *, struct Text *byebye); */
|
||||
/* int BPY_spacetext_is_pywin(struct SpaceText *st); */
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -1,127 +0,0 @@
|
||||
/*
|
||||
* $Id$
|
||||
*
|
||||
* ***** 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*
|
||||
* The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This is a new part of Blender.
|
||||
*
|
||||
* Contributor(s): Willian P. Germano, Matt Ebb
|
||||
*
|
||||
* ***** END GPL LICENSE BLOCK *****
|
||||
*/
|
||||
|
||||
#ifndef BPY_MENUS_H
|
||||
#define BPY_MENUS_H
|
||||
|
||||
/* This header exposes BPyMenu related public declarations. The implementation
|
||||
* adds 'dynamic' menus to Blender, letting scripts register themselves in any
|
||||
* of a few pre-defined (trivial to upgrade) places in menus. These places or
|
||||
* slots are called groups here (Import, Export, etc). This is how it works:
|
||||
* - scripts at dirs user pref U.pythondir and .blender/scripts/ are scanned
|
||||
* for registration info.
|
||||
* - this data is also saved to a Bpymenus file at the user's .blender/ dir and
|
||||
* only re-created when the scripts folder gets modified.
|
||||
* - on start-up Blender uses this info to fill a table, which is used to
|
||||
* create the menu entries when they are needed (see header_info.c or
|
||||
* header_script.c, under source/blender/src/, for examples).
|
||||
*/
|
||||
|
||||
/* These two structs hold py menu/submenu info.
|
||||
* BPyMenu holds a script's name (as should appear in the menu) and filename,
|
||||
* plus an optional list of submenus. Each submenu is related to a string
|
||||
* (arg) that the script can get from the __script__ pydict, to know which
|
||||
* submenu was chosen. */
|
||||
|
||||
typedef struct BPySubMenu {
|
||||
char *name;
|
||||
char *arg;
|
||||
struct BPySubMenu *next;
|
||||
} BPySubMenu;
|
||||
|
||||
typedef struct BPyMenu {
|
||||
char *name;
|
||||
char *filename;
|
||||
char *tooltip;
|
||||
unsigned short key, qual; /* Registered shortcut key */
|
||||
short version; /* Blender version */
|
||||
int dir; /* 0: default, 1: U.pythondir */
|
||||
struct BPySubMenu *submenus;
|
||||
struct BPyMenu *next;
|
||||
} BPyMenu;
|
||||
|
||||
/* Scripts can be added to only a few pre-defined places in menus, like
|
||||
* File->Import, File->Export, etc. (for speed and better control).
|
||||
* To make a new menu 'slot' available for scripts:
|
||||
* - add an entry to the enum below, before PYMENU_TOTAL, of course;
|
||||
* - update the bpymenu_group_atoi() and BPyMenu_group_itoa() functions in
|
||||
* BPY_menus.c;
|
||||
* - add the necessary code to the header_***.c file in
|
||||
* source/blender/src/, like done in header_info.c for import/export;
|
||||
*/
|
||||
typedef enum {
|
||||
PYMENU_ADD,/* creates new objects */
|
||||
PYMENU_ANIMATION,
|
||||
PYMENU_EXPORT,
|
||||
PYMENU_IMPORT,
|
||||
PYMENU_MATERIALS,
|
||||
PYMENU_MESH,
|
||||
PYMENU_MISC,
|
||||
PYMENU_OBJECT,
|
||||
PYMENU_RENDER,/* exporters to external renderers */
|
||||
PYMENU_SYSTEM,
|
||||
PYMENU_THEMES,
|
||||
PYMENU_UV,/* UV editing tools, to go in UV/Image editor space, 'UV' menu */
|
||||
PYMENU_IMAGE,/* Image editing tools, to go in UV/Image editor space, 'Image' menu */
|
||||
PYMENU_WIZARDS,/* complex 'app' scripts */
|
||||
|
||||
/* entries put after Wizards don't appear at the Scripts win->Scripts menu;
|
||||
* see define right below */
|
||||
|
||||
PYMENU_FACESELECT,
|
||||
PYMENU_WEIGHTPAINT,
|
||||
PYMENU_VERTEXPAINT,
|
||||
PYMENU_UVCALCULATION,
|
||||
PYMENU_ARMATURE,
|
||||
PYMENU_SCRIPTTEMPLATE,
|
||||
PYMENU_TEXTPLUGIN,
|
||||
PYMENU_HELP,/*Main Help menu items - prob best to leave for 'official' ones*/
|
||||
PYMENU_HELPSYSTEM,/* Resources, troubleshooting, system tools */
|
||||
PYMENU_HELPWEBSITES,/* Help -> Websites submenu */
|
||||
PYMENU_MESHFACEKEY, /* face key in mesh editmode */
|
||||
PYMENU_ADDMESH, /* adds mesh */
|
||||
PYMENU_TOTAL
|
||||
} PYMENUHOOKS;
|
||||
|
||||
#define PYMENU_SCRIPTS_MENU_TOTAL (PYMENU_WIZARDS + 1)
|
||||
|
||||
/* BPyMenuTable holds all registered pymenus, as linked lists for each menu
|
||||
* where they can appear (see PYMENUHOOKS enum above).
|
||||
*/
|
||||
extern BPyMenu *BPyMenuTable[]; /* defined in BPY_menus.c */
|
||||
|
||||
/* public functions: */
|
||||
int BPyMenu_Init( int usedir );
|
||||
void BPyMenu_RemoveAllEntries( void );
|
||||
void BPyMenu_PrintAllEntries( void );
|
||||
char *BPyMenu_CreatePupmenuStr( BPyMenu * pym, short group );
|
||||
char *BPyMenu_group_itoa( short group );
|
||||
struct BPyMenu *BPyMenu_GetEntry( short group, short pos );
|
||||
|
||||
#endif /* BPY_MENUS_H */
|
||||
@@ -1,4 +1,3 @@
|
||||
# $Id$
|
||||
# ***** BEGIN GPL LICENSE BLOCK *****
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or
|
||||
@@ -24,36 +23,31 @@
|
||||
#
|
||||
# ***** END GPL LICENSE BLOCK *****
|
||||
|
||||
FILE(GLOB SRC api2_2x/*.c)
|
||||
SET(SRC ${SRC}
|
||||
BPY_interface.c
|
||||
BPY_menus.c
|
||||
)
|
||||
FILE(GLOB SRC intern/*.c)
|
||||
FILE(GLOB GENSRC generic/*.c)
|
||||
|
||||
SET(INC
|
||||
api2_2x ../blenkernel ../blenlib ../blenloader
|
||||
../render/extern/include ../radiosity/extern/include
|
||||
../makesdna ../../../intern/guardedalloc ../../../intern/bmfont ../imbuf ../include
|
||||
${PYTHON_INC} ../../../extern/glew/include ../gpu
|
||||
../freestyle ../freestyle/intern/python
|
||||
. ../../../intern/guardedalloc ../blenlib ../makesdna ../makesrna
|
||||
../blenkernel ../editors/include ../windowmanager ${PYTHON_INC}
|
||||
../../../extern/glew/include
|
||||
)
|
||||
|
||||
IF(WITH_QUICKTIME)
|
||||
SET(INC ${INC} ${QUICKTIME_INC})
|
||||
ADD_DEFINITIONS(-DWITH_QUICKTIME)
|
||||
ENDIF(WITH_QUICKTIME)
|
||||
|
||||
IF(WITH_OPENEXR)
|
||||
ADD_DEFINITIONS(-DWITH_OPENEXR)
|
||||
ADD_DEFINITIONS(-DWITH_OPENEXR)
|
||||
ENDIF(WITH_OPENEXR)
|
||||
|
||||
IF(WITH_QUICKTIME)
|
||||
SET(INC ${INC} ${QUICKTIME_INC})
|
||||
ADD_DEFINITIONS(-DWITH_QUICKTIME)
|
||||
ENDIF(WITH_QUICKTIME)
|
||||
|
||||
IF(WITH_FFMPEG)
|
||||
ADD_DEFINITIONS(-DWITH_FFMPEG)
|
||||
SET(INC ${INC} ${FFMPEG_INC})
|
||||
ADD_DEFINITIONS(-DWITH_FFMPEG)
|
||||
ENDIF(WITH_FFMPEG)
|
||||
|
||||
IF(BF_BUILDINFO)
|
||||
ADD_DEFINITIONS(-DNAN_BUILDINFO)
|
||||
ENDIF(BF_BUILDINFO)
|
||||
ADD_DEFINITIONS(-DWITH_CCGSUBSURF)
|
||||
|
||||
BLENDERLIB(bf_python "${SRC}" "${INC}")
|
||||
BLENDERLIB(bf_gen_python "${GENSRC}" "${INC}")
|
||||
|
||||
BLENDERLIB_NOLIST(blender_python "${SRC}" "${INC}")
|
||||
#env.BlenderLib ( libname='blender_python', sources = Split(sources), includes = Split(incs), defines = defs, libtype=['core','game2'], priority = [60,115] )
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
# along with this program; if not, write to the Free Software Foundation,
|
||||
# Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
#
|
||||
# The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
|
||||
# The Original Code is Copyright (C) Blender Foundation.
|
||||
# All rights reserved.
|
||||
#
|
||||
# The Original Code is: all of this file.
|
||||
@@ -29,6 +29,6 @@
|
||||
# Bounces make to subdirectories.
|
||||
|
||||
SOURCEDIR = source/blender/python
|
||||
DIRS = api2_2x
|
||||
DIRS = intern generic
|
||||
|
||||
include nan_subdirs.mk
|
||||
|
||||
@@ -1,30 +1,21 @@
|
||||
#!/usr/bin/python
|
||||
Import ('env')
|
||||
|
||||
sources = env.Glob('*.c') + env.Glob('api2_2x/*.c')
|
||||
sources = env.Glob('intern/*.c')
|
||||
|
||||
incs = 'api2_2x ../blenkernel ../nodes ../blenlib ../blenloader'
|
||||
incs += ' ../render/extern/include ../radiosity/extern/include ../freestyle/intern/python'
|
||||
incs += ' ../makesdna #intern/guardedalloc #intern/bmfont ../imbuf ../include'
|
||||
incs += ' #extern/glew/include ../gpu'
|
||||
incs = '. ../editors/include ../makesdna ../makesrna ../blenlib ../blenkernel ../nodes'
|
||||
incs += ' ../imbuf ../blenloader ../render/extern/include ../windowmanager'
|
||||
incs += ' #intern/guardedalloc #intern/memutil #extern/glew/include'
|
||||
incs += ' ' + env['BF_PYTHON_INC']
|
||||
incs += ' ' + env['BF_OPENGL_INC']
|
||||
|
||||
defs = []
|
||||
if env['OURPLATFORM'] in ('win32-mingw') and env['BF_DEBUG']:
|
||||
defs.append('Py_TRACE_REFS')
|
||||
|
||||
if env['WITH_BF_QUICKTIME']:
|
||||
incs += ' ' + env['BF_QUICKTIME_INC']
|
||||
defs.append('WITH_QUICKTIME')
|
||||
|
||||
if env['WITH_BF_OPENEXR']:
|
||||
defs.append('WITH_OPENEXR')
|
||||
if env['OURPLATFORM'] in ('win32-mingw', 'win32-vc','win64-vc') and env['BF_DEBUG']:
|
||||
defs.append('_DEBUG')
|
||||
|
||||
if env['WITH_BF_FFMPEG']:
|
||||
defs.append('WITH_FFMPEG')
|
||||
env.BlenderLib( libname = 'bf_python', sources = Split(sources), includes = Split(incs), defines = defs, libtype = ['core','player'], priority = [361,160])
|
||||
|
||||
if env['BF_BUILDINFO']:
|
||||
defs.append('NAN_BUILDINFO')
|
||||
|
||||
env.BlenderLib ( libname='blender_python', sources = Split(sources), includes = Split(incs), defines = defs, libtype=['core','game2'], priority = [60,115] )
|
||||
# generic
|
||||
sources = env.Glob('generic/*.c')
|
||||
env.BlenderLib( libname = 'bf_gen_python', sources = Split(sources), includes = Split(incs), defines = defs, libtype = ['core','player'], priority = [362,165]) # ketsji is 360
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,67 +0,0 @@
|
||||
/*
|
||||
* $Id$
|
||||
*
|
||||
* ***** 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*
|
||||
* The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Contributor(s): Joseph gilbert
|
||||
*
|
||||
* ***** END GPL LICENSE BLOCK *****
|
||||
*/
|
||||
|
||||
#ifndef EXPP_ARMATURE_H
|
||||
#define EXPP_ARMATURE_H
|
||||
|
||||
#include <Python.h>
|
||||
#include "DNA_armature_types.h"
|
||||
|
||||
//-------------------TYPE CHECKS---------------------------------
|
||||
#define BPy_Armature_Check(v) ((v)->ob_type == &Armature_Type)
|
||||
#define BPy_BonesDict_Check(v) ((v)->ob_type == &BonesDict_Type)
|
||||
//-------------------MODULE INIT---------------------------------
|
||||
PyObject *Armature_Init( void );
|
||||
//-------------------TYPEOBJECT----------------------------------
|
||||
extern PyTypeObject Armature_Type;
|
||||
extern PyTypeObject BonesDict_Type;
|
||||
//-------------------STRUCT DEFINITION---------------------------
|
||||
typedef struct {
|
||||
PyObject_HEAD
|
||||
PyObject *bonesMap; //wrapper for bones
|
||||
PyObject *editbonesMap; //wrapper for editbones
|
||||
ListBase *bones; //pointer to armature->bonebase
|
||||
ListBase editbones; //allocated list of EditBones
|
||||
short editmode_flag; //1 = in , 0 = not in
|
||||
} BPy_BonesDict;
|
||||
|
||||
typedef struct {
|
||||
PyObject_HEAD
|
||||
struct bArmature * armature;
|
||||
BPy_BonesDict *Bones; //BPy_BonesDict
|
||||
PyObject *weaklist;
|
||||
} BPy_Armature;
|
||||
|
||||
//-------------------VISIBLE PROTOTYPES-------------------------
|
||||
PyObject *Armature_CreatePyObject(struct bArmature *armature);
|
||||
struct bArmature *PyArmature_AsArmature(BPy_Armature *py_armature);
|
||||
PyObject * Armature_RebuildEditbones(PyObject *pyarmature);
|
||||
PyObject *Armature_RebuildBones(PyObject *pyarmature);
|
||||
|
||||
struct bArmature *Armature_FromPyObject( PyObject * py_obj );
|
||||
|
||||
#endif
|
||||
@@ -1,714 +0,0 @@
|
||||
/*
|
||||
* $Id$
|
||||
*
|
||||
* ***** 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*
|
||||
* The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This is a new part of Blender.
|
||||
*
|
||||
* Contributor(s): Jacques Guignot RIP 2005,
|
||||
* Stephen Swaney, Ken Hughes
|
||||
*
|
||||
* ***** END GPL LICENSE BLOCK *****
|
||||
*/
|
||||
|
||||
#include "BezTriple.h" /*This must come first */
|
||||
#include "DNA_ipo_types.h"
|
||||
|
||||
#include "MEM_guardedalloc.h"
|
||||
#include "gen_utils.h"
|
||||
|
||||
|
||||
/***************************************************************************
|
||||
Python API function prototypes for the BezTriple module.
|
||||
***************************************************************************/
|
||||
static PyObject *M_BezTriple_New( PyObject * self, PyObject * args );
|
||||
static PyObject *M_BezTriple_Get( PyObject * self, PyObject * args );
|
||||
|
||||
/*************************************
|
||||
Doc strings for the BezTriple module
|
||||
*************************************/
|
||||
|
||||
static char M_BezTriple_doc[] = "The Blender BezTriple module\n";
|
||||
|
||||
/****************************************************************************
|
||||
Python BPy_BezTriple instance methods declarations:
|
||||
****************************************************************************/
|
||||
static PyObject *BezTriple_oldsetPoints( BPy_BezTriple * self, PyObject * args );
|
||||
static int BezTriple_setPoints( BPy_BezTriple * self, PyObject * args );
|
||||
static PyObject *BezTriple_getPoints( BPy_BezTriple * self );
|
||||
static PyObject *BezTriple_getTriple( BPy_BezTriple * self );
|
||||
|
||||
/****************************************************************************
|
||||
Python method structure definition for Blender.BezTriple module:
|
||||
****************************************************************************/
|
||||
|
||||
struct PyMethodDef M_BezTriple_methods[] = {
|
||||
{"New", ( PyCFunction ) M_BezTriple_New, METH_VARARGS | METH_KEYWORDS,
|
||||
0},
|
||||
/* {"New", ( PyCFunction ) M_BezTriple_New, METH_O, 0}, */
|
||||
{"Get", M_BezTriple_Get, METH_VARARGS, 0},
|
||||
{"get", M_BezTriple_Get, METH_VARARGS, 0},
|
||||
{NULL, NULL, 0, NULL}
|
||||
};
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Python BPy_BezTriple methods table: */
|
||||
/*****************************************************************************/
|
||||
static PyMethodDef BPy_BezTriple_methods[] = {
|
||||
/* name, method, flags, doc */
|
||||
{"setPoints", ( PyCFunction ) BezTriple_oldsetPoints, METH_VARARGS,
|
||||
"(str) - Change BezTriple point coordinates"},
|
||||
{"getPoints", ( PyCFunction ) BezTriple_getPoints, METH_NOARGS,
|
||||
"() - return BezTriple knot point x and y coordinates"},
|
||||
{"getTriple", ( PyCFunction ) BezTriple_getTriple, METH_NOARGS,
|
||||
"() - return list of 3 floating point triplets. order is H1, knot, H2"},
|
||||
{NULL, NULL, 0, NULL}
|
||||
};
|
||||
|
||||
/****************************************************************************
|
||||
Function: M_BezTriple_New
|
||||
Python equivalent: Blender.BezTriple.New
|
||||
****************************************************************************/
|
||||
|
||||
static PyObject *M_BezTriple_New( PyObject* self, PyObject * args )
|
||||
{
|
||||
float numbuf[9];
|
||||
PyObject* in_args = NULL;
|
||||
int length;
|
||||
|
||||
/* accept list, tuple, or 3 or 9 args (which better be floats) */
|
||||
|
||||
length = PyTuple_Size( args );
|
||||
if( length == 3 || length == 9 )
|
||||
in_args = args;
|
||||
else if( !PyArg_ParseTuple( args, "|O", &in_args) )
|
||||
goto TypeError;
|
||||
|
||||
if( !in_args ) {
|
||||
numbuf[0] = 0.0f; numbuf[1] = 0.0f; numbuf[2] = 0.0f;
|
||||
numbuf[3] = 0.0f; numbuf[4] = 0.0f; numbuf[5] = 0.0f;
|
||||
numbuf[6] = 0.0f; numbuf[7] = 0.0f; numbuf[8] = 0.0f;
|
||||
} else {
|
||||
int i, length;
|
||||
if( !PySequence_Check( in_args ) )
|
||||
goto TypeError;
|
||||
|
||||
length = PySequence_Length( in_args );
|
||||
if( length != 9 && length != 3 )
|
||||
goto TypeError;
|
||||
|
||||
for( i = 0; i < length; i++ ) {
|
||||
PyObject *item, *pyfloat;
|
||||
item = PySequence_ITEM( in_args, i);
|
||||
if( !item )
|
||||
goto TypeError;
|
||||
pyfloat = PyNumber_Float( item );
|
||||
Py_DECREF( item );
|
||||
if( !pyfloat )
|
||||
goto TypeError;
|
||||
numbuf[i] = ( float )PyFloat_AS_DOUBLE( pyfloat );
|
||||
Py_DECREF( pyfloat );
|
||||
}
|
||||
|
||||
if( length == 3 ) {
|
||||
numbuf[3] = numbuf[0]; numbuf[6] = numbuf[0];
|
||||
numbuf[4] = numbuf[1]; numbuf[7] = numbuf[1];
|
||||
numbuf[5] = numbuf[2]; numbuf[8] = numbuf[2];
|
||||
}
|
||||
}
|
||||
|
||||
return newBezTriple( numbuf );
|
||||
|
||||
TypeError:
|
||||
return EXPP_ReturnPyObjError( PyExc_TypeError,
|
||||
"expected sequence of 3 or 9 floats or nothing" );
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
Function: M_BezTriple_Get
|
||||
Python equivalent: Blender.BezTriple.Get
|
||||
Description: Receives a string and returns the ipo data obj
|
||||
whose name matches the string. If no argument is
|
||||
passed in, a list of all ipo data names in the
|
||||
current scene is returned.
|
||||
****************************************************************************/
|
||||
static PyObject *M_BezTriple_Get( PyObject * self, PyObject * args )
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
Function: BezTriple_dealloc
|
||||
Description: This is a callback function for the BPy_BezTriple type. It is
|
||||
the destructor function.
|
||||
****************************************************************************/
|
||||
static void BezTriple_dealloc( BPy_BezTriple * self )
|
||||
{
|
||||
if( self->own_memory)
|
||||
MEM_freeN( self->beztriple );
|
||||
|
||||
PyObject_DEL( self );
|
||||
}
|
||||
|
||||
/*
|
||||
* BezTriple_getTriple
|
||||
*
|
||||
* Get the coordinate data for a BezTriple. Returns a list of 3 points.
|
||||
* List order is handle1, knot, handle2. each point consists of a list
|
||||
* of x,y,z float values.
|
||||
*/
|
||||
|
||||
static PyObject *BezTriple_getTriple( BPy_BezTriple * self )
|
||||
{
|
||||
BezTriple *bezt = self->beztriple;
|
||||
return Py_BuildValue( "[[fff][fff][fff]]",
|
||||
bezt->vec[0][0], bezt->vec[0][1], bezt->vec[0][2],
|
||||
bezt->vec[1][0], bezt->vec[1][1], bezt->vec[1][2],
|
||||
bezt->vec[2][0], bezt->vec[2][1], bezt->vec[2][2] );
|
||||
}
|
||||
|
||||
/*
|
||||
* BezTriple_setTriple
|
||||
*
|
||||
* Set the cordinate data for a BezTriple. Takes a sequence of 3 points,
|
||||
* of the same format at BezTriple_getTriple.
|
||||
*/
|
||||
|
||||
static int BezTriple_setTriple( BPy_BezTriple * self, PyObject * args )
|
||||
{
|
||||
int i, j;
|
||||
struct BezTriple *bezt = self->beztriple;
|
||||
float vec[3][3];
|
||||
|
||||
if( !PySequence_Check( args ) || PySequence_Size( args ) != 3 )
|
||||
return EXPP_ReturnIntError( PyExc_TypeError,
|
||||
"expected three sequences of three floats" );
|
||||
|
||||
for( i = 0; i < 3; i++ ) {
|
||||
PyObject *obj1 = PySequence_ITEM( args, i );
|
||||
if( !PySequence_Check( obj1 ) || PySequence_Size( obj1 ) != 3 ) {
|
||||
Py_DECREF( obj1 );
|
||||
return EXPP_ReturnIntError( PyExc_TypeError,
|
||||
"expected three sequences of three floats" );
|
||||
}
|
||||
for( j = 0; j < 3; j++ ) {
|
||||
PyObject *obj2 = PySequence_ITEM( obj1, j );
|
||||
PyObject *num = PyNumber_Float( obj2 );
|
||||
Py_DECREF( obj2 );
|
||||
|
||||
if( !num ) {
|
||||
Py_DECREF( obj1 );
|
||||
return EXPP_ReturnIntError( PyExc_ValueError,
|
||||
"expected float parameter" );
|
||||
}
|
||||
vec[i][j] = ( float )PyFloat_AsDouble( num );
|
||||
Py_DECREF( num );
|
||||
}
|
||||
Py_DECREF( obj1 );
|
||||
}
|
||||
|
||||
for( i = 0; i < 3; i++ )
|
||||
for( j = 0; j < 3; j++ )
|
||||
bezt->vec[i][j] = vec[i][j];
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* BezTriple_getPoint
|
||||
*
|
||||
* Get the coordinate data for a BezTriple. Returns the control point,
|
||||
* as a list of x,y float values.
|
||||
*/
|
||||
|
||||
static PyObject *BezTriple_getPoints( BPy_BezTriple * self )
|
||||
{
|
||||
BezTriple *bezt = self->beztriple;
|
||||
return Py_BuildValue( "[ff]", bezt->vec[1][0], bezt->vec[1][1] );
|
||||
}
|
||||
|
||||
/*
|
||||
* BezTriple_setPoint
|
||||
*
|
||||
* Set the coordinate data for a BezTriple. Accepts the x,y for the control
|
||||
* point and builds handle values based on control point.
|
||||
*/
|
||||
|
||||
static int BezTriple_setPoints( BPy_BezTriple * self, PyObject * args )
|
||||
{
|
||||
int i;
|
||||
struct BezTriple *bezt = self->beztriple;
|
||||
float vec[2];
|
||||
|
||||
if( !PySequence_Check( args ) || PySequence_Size( args ) != 2 )
|
||||
return EXPP_ReturnIntError( PyExc_TypeError,
|
||||
"expected sequence of two floats" );
|
||||
|
||||
for( i = 0; i < 2; i++ ) {
|
||||
PyObject *obj = PySequence_ITEM( args, i );
|
||||
PyObject *num = PyNumber_Float( obj );
|
||||
Py_DECREF( obj );
|
||||
|
||||
if( !num )
|
||||
return EXPP_ReturnIntError( PyExc_ValueError,
|
||||
"expected float parameter" );
|
||||
vec[i] = ( float )PyFloat_AsDouble( num );
|
||||
Py_DECREF( num );
|
||||
}
|
||||
|
||||
for( i = 0; i < 2; i++ ) {
|
||||
bezt->vec[0][i] = vec[i] - 1;
|
||||
bezt->vec[1][i] = vec[i];
|
||||
bezt->vec[2][i] = vec[i] + 1;
|
||||
}
|
||||
|
||||
/* experimental fussing with handles - ipo.c: calchandles_ipocurve */
|
||||
if( bezt->vec[0][0] > bezt->vec[1][0] )
|
||||
bezt->vec[0][0] = bezt->vec[1][0];
|
||||
|
||||
if( bezt->vec[2][0] < bezt->vec[1][0] )
|
||||
bezt->vec[2][0] = bezt->vec[1][0];
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static PyObject *BezTriple_getTilt( BPy_BezTriple * self )
|
||||
{
|
||||
return PyFloat_FromDouble( self->beztriple->alfa );
|
||||
}
|
||||
|
||||
static int BezTriple_setTilt( BPy_BezTriple * self, PyObject *value )
|
||||
{
|
||||
PyObject *num = PyNumber_Float( value );
|
||||
|
||||
if( !num )
|
||||
return EXPP_ReturnIntError( PyExc_TypeError, "expected a float" );
|
||||
|
||||
self->beztriple->alfa = (float)PyFloat_AsDouble( num );
|
||||
Py_DECREF( num );
|
||||
return 0;
|
||||
}
|
||||
|
||||
static PyObject *BezTriple_getWeight( BPy_BezTriple * self )
|
||||
{
|
||||
return PyFloat_FromDouble( self->beztriple->weight );
|
||||
}
|
||||
|
||||
static int BezTriple_setWeight( BPy_BezTriple * self, PyObject *value )
|
||||
{
|
||||
PyObject *num = PyNumber_Float( value );
|
||||
|
||||
if( !num )
|
||||
return EXPP_ReturnIntError( PyExc_TypeError, "expected a float" );
|
||||
|
||||
self->beztriple->weight = (float)PyFloat_AsDouble( num );
|
||||
Py_DECREF( num );
|
||||
return 0;
|
||||
}
|
||||
|
||||
static PyObject *BezTriple_getRadius( BPy_BezTriple * self )
|
||||
{
|
||||
return PyFloat_FromDouble( self->beztriple->radius );
|
||||
}
|
||||
|
||||
static int BezTriple_setRadius( BPy_BezTriple * self, PyObject *value )
|
||||
{
|
||||
PyObject *num = PyNumber_Float( value );
|
||||
|
||||
if( !num )
|
||||
return EXPP_ReturnIntError( PyExc_TypeError, "expected a float" );
|
||||
|
||||
self->beztriple->radius = (float)PyFloat_AsDouble( num );
|
||||
Py_DECREF( num );
|
||||
return 0;
|
||||
}
|
||||
|
||||
static PyObject *BezTriple_getHide( BPy_BezTriple * self )
|
||||
{
|
||||
return PyInt_FromLong( self->beztriple->hide == IPO_BEZ );
|
||||
}
|
||||
|
||||
static int BezTriple_setHide( BPy_BezTriple * self, PyObject *value )
|
||||
{
|
||||
int param = PyObject_IsTrue( value );
|
||||
if( param == -1 )
|
||||
return EXPP_ReturnIntError( PyExc_TypeError,
|
||||
"expected True/False or 0/1" );
|
||||
|
||||
if( param )
|
||||
self->beztriple->hide = IPO_BEZ;
|
||||
else
|
||||
self->beztriple->hide = 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static PyObject *BezTriple_getSelects( BPy_BezTriple * self )
|
||||
{
|
||||
BezTriple *bezt = self->beztriple;
|
||||
|
||||
return Py_BuildValue( "[iii]", bezt->f1, bezt->f2, bezt->f3 );
|
||||
}
|
||||
|
||||
static int BezTriple_setSelects( BPy_BezTriple * self, PyObject *args )
|
||||
{
|
||||
struct BezTriple *bezt = self->beztriple;
|
||||
PyObject *ob1, *ob2, *ob3;
|
||||
int param1, param2, param3;
|
||||
|
||||
/* only accept a sequence of three booleans */
|
||||
|
||||
if( !PySequence_Check( args ) || PySequence_Size( args ) != 3 )
|
||||
return EXPP_ReturnIntError( PyExc_TypeError,
|
||||
"expected sequence of three integers" );
|
||||
|
||||
ob1 = PySequence_ITEM( args, 0 );
|
||||
ob2 = PySequence_ITEM( args, 1 );
|
||||
ob3 = PySequence_ITEM( args, 2 );
|
||||
|
||||
param1 = PyObject_IsTrue( ob1 );
|
||||
param2 = PyObject_IsTrue( ob2 );
|
||||
param3 = PyObject_IsTrue( ob3 );
|
||||
|
||||
if (param1==-1 || param2==-1 || param3==-1)
|
||||
return EXPP_ReturnIntError( PyExc_TypeError,
|
||||
"expected a sequence of 3 items: True/False or 0/1" );
|
||||
|
||||
/* assign the selects */
|
||||
bezt->f1 = (char)param1;
|
||||
bezt->f2 = (char)param2;
|
||||
bezt->f3 = (char)param3;
|
||||
|
||||
Py_DECREF( ob1 );
|
||||
Py_DECREF( ob2 );
|
||||
Py_DECREF( ob3 );
|
||||
return 0;
|
||||
}
|
||||
|
||||
static PyObject *BezTriple_getHandles( BPy_BezTriple * self )
|
||||
{
|
||||
BezTriple *bezt = self->beztriple;
|
||||
|
||||
return Py_BuildValue( "[ii]", bezt->h1, bezt->h2 );
|
||||
}
|
||||
|
||||
static int BezTriple_setHandles( BPy_BezTriple * self, PyObject *args )
|
||||
{
|
||||
struct BezTriple *bezt = self->beztriple;
|
||||
PyObject *ob1, *ob2;
|
||||
short h1, h2;
|
||||
|
||||
/* only accept a sequence of two ints */
|
||||
|
||||
if( !PySequence_Check( args ) || PySequence_Size( args ) != 2 )
|
||||
return EXPP_ReturnIntError( PyExc_TypeError,
|
||||
"expected sequence of two integers" );
|
||||
|
||||
ob1 = PySequence_ITEM( args, 0 );
|
||||
ob2 = PySequence_ITEM( args, 1 );
|
||||
|
||||
if( !PyInt_Check( ob1 ) || !PyInt_Check( ob2 ) ) {
|
||||
Py_DECREF( ob1 );
|
||||
Py_DECREF( ob2 );
|
||||
return EXPP_ReturnIntError( PyExc_TypeError,
|
||||
"expected sequence of two integers" );
|
||||
}
|
||||
|
||||
h1 = ( short ) PyInt_AsLong( ob1 );
|
||||
h2 = ( short ) PyInt_AsLong( ob2 );
|
||||
Py_DECREF( ob1 );
|
||||
Py_DECREF( ob2 );
|
||||
|
||||
if( h1 < HD_FREE || h2 < HD_FREE ||
|
||||
h1 > HD_AUTO_ANIM || h2 > HD_AUTO_ANIM )
|
||||
return EXPP_ReturnIntError( PyExc_ValueError,
|
||||
"expected int in range [0,4]" );
|
||||
|
||||
/* assign the handles */
|
||||
|
||||
bezt->h1 = h1;
|
||||
bezt->h2 = h2;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* Python BezTriple attributes get/set structure
|
||||
*/
|
||||
|
||||
static PyGetSetDef BPy_BezTriple_getseters[] = {
|
||||
{"pt",
|
||||
(getter)BezTriple_getPoints, (setter)BezTriple_setPoints,
|
||||
"point knot values",
|
||||
NULL},
|
||||
{"vec",
|
||||
(getter)BezTriple_getTriple, (setter)BezTriple_setTriple,
|
||||
"point handle and knot values",
|
||||
NULL},
|
||||
{"tilt",
|
||||
(getter)BezTriple_getTilt, (setter)BezTriple_setTilt,
|
||||
"point tilt",
|
||||
NULL},
|
||||
{"hide",
|
||||
(getter)BezTriple_getHide, (setter)BezTriple_setHide,
|
||||
"point hide status",
|
||||
NULL},
|
||||
{"selects",
|
||||
(getter)BezTriple_getSelects, (setter)BezTriple_setSelects,
|
||||
"point select statuses",
|
||||
NULL},
|
||||
{"handleTypes",
|
||||
(getter)BezTriple_getHandles, (setter)BezTriple_setHandles,
|
||||
"point handle types",
|
||||
NULL},
|
||||
{"weight",
|
||||
(getter)BezTriple_getWeight, (setter)BezTriple_setWeight,
|
||||
"point weight",
|
||||
NULL},
|
||||
{"radius",
|
||||
(getter)BezTriple_getRadius, (setter)BezTriple_setRadius,
|
||||
"point radius",
|
||||
NULL},
|
||||
{NULL,NULL,NULL,NULL,NULL} /* Sentinel */
|
||||
};
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Function: BezTriple_repr */
|
||||
/* Description: This is a callback function for the BPy_BezTriple type. It */
|
||||
/* builds a meaninful string to represent BezTriple objects. */
|
||||
/*****************************************************************************/
|
||||
static PyObject *BezTriple_repr( BPy_BezTriple * self )
|
||||
{
|
||||
char str[512];
|
||||
sprintf( str,
|
||||
"[BezTriple [%.6f, %.6f, %.6f] [%.6f, %.6f, %.6f] [%.6f, %.6f, %.6f]\n",
|
||||
self->beztriple->vec[0][0], self->beztriple->vec[0][1], self->beztriple->vec[0][2],
|
||||
self->beztriple->vec[1][0], self->beztriple->vec[1][1], self->beztriple->vec[1][2],
|
||||
self->beztriple->vec[2][0], self->beztriple->vec[2][1], self->beztriple->vec[2][2]);
|
||||
return PyString_FromString( str );
|
||||
}
|
||||
|
||||
/************************************************************************
|
||||
*
|
||||
* Python BezTriple_Type structure definition
|
||||
*
|
||||
************************************************************************/
|
||||
|
||||
PyTypeObject BezTriple_Type = {
|
||||
PyObject_HEAD_INIT( NULL ) /* required py macro */
|
||||
0, /* ob_size */
|
||||
/* For printing, in format "<module>.<name>" */
|
||||
"BezTriple", /* char *tp_name; */
|
||||
sizeof( BPy_BezTriple ), /* int tp_basicsize; */
|
||||
0, /* tp_itemsize; For allocation */
|
||||
|
||||
/* Methods to implement standard operations */
|
||||
|
||||
( destructor ) BezTriple_dealloc,/* destructor tp_dealloc; */
|
||||
NULL, /* printfunc tp_print; */
|
||||
NULL, /* getattrfunc tp_getattr; */
|
||||
NULL, /* setattrfunc tp_setattr; */
|
||||
NULL, /* cmpfunc tp_compare; */
|
||||
( reprfunc ) BezTriple_repr, /* reprfunc tp_repr; */
|
||||
|
||||
/* Method suites for standard classes */
|
||||
|
||||
NULL, /* PyNumberMethods *tp_as_number; */
|
||||
NULL, /* PySequenceMethods *tp_as_sequence; */
|
||||
NULL, /* PyMappingMethods *tp_as_mapping; */
|
||||
|
||||
/* More standard operations (here for binary compatibility) */
|
||||
|
||||
NULL, /* hashfunc tp_hash; */
|
||||
NULL, /* ternaryfunc tp_call; */
|
||||
NULL, /* reprfunc tp_str; */
|
||||
NULL, /* getattrofunc tp_getattro; */
|
||||
NULL, /* setattrofunc tp_setattro; */
|
||||
|
||||
/* Functions to access object as input/output buffer */
|
||||
NULL, /* PyBufferProcs *tp_as_buffer; */
|
||||
|
||||
/*** Flags to define presence of optional/expanded features ***/
|
||||
Py_TPFLAGS_DEFAULT, /* long tp_flags; */
|
||||
|
||||
NULL, /* char *tp_doc; Documentation string */
|
||||
/*** Assigned meaning in release 2.0 ***/
|
||||
/* call function for all accessible objects */
|
||||
NULL, /* traverseproc tp_traverse; */
|
||||
|
||||
/* delete references to contained objects */
|
||||
NULL, /* inquiry tp_clear; */
|
||||
|
||||
/*** Assigned meaning in release 2.1 ***/
|
||||
/*** rich comparisons ***/
|
||||
NULL, /* richcmpfunc tp_richcompare; */
|
||||
|
||||
/*** weak reference enabler ***/
|
||||
0, /* long tp_weaklistoffset; */
|
||||
|
||||
/*** Added in release 2.2 ***/
|
||||
/* Iterators */
|
||||
NULL, /* getiterfunc tp_iter; */
|
||||
NULL, /* iternextfunc tp_iternext; */
|
||||
|
||||
/*** Attribute descriptor and subclassing stuff ***/
|
||||
BPy_BezTriple_methods, /* struct PyMethodDef *tp_methods; */
|
||||
NULL, /* struct PyMemberDef *tp_members; */
|
||||
BPy_BezTriple_getseters, /* struct PyGetSetDef *tp_getset; */
|
||||
NULL, /* struct _typeobject *tp_base; */
|
||||
NULL, /* PyObject *tp_dict; */
|
||||
NULL, /* descrgetfunc tp_descr_get; */
|
||||
NULL, /* descrsetfunc tp_descr_set; */
|
||||
0, /* long tp_dictoffset; */
|
||||
NULL, /* initproc tp_init; */
|
||||
NULL, /* allocfunc tp_alloc; */
|
||||
NULL, /* newfunc tp_new; */
|
||||
/* Low-level free-memory routine */
|
||||
NULL, /* freefunc tp_free; */
|
||||
/* For PyObject_IS_GC */
|
||||
NULL, /* inquiry tp_is_gc; */
|
||||
NULL, /* PyObject *tp_bases; */
|
||||
/* method resolution order */
|
||||
NULL, /* PyObject *tp_mro; */
|
||||
NULL, /* PyObject *tp_cache; */
|
||||
NULL, /* PyObject *tp_subclasses; */
|
||||
NULL, /* PyObject *tp_weaklist; */
|
||||
NULL
|
||||
};
|
||||
|
||||
static PyObject *M_BezTriple_HandleDict( void )
|
||||
{
|
||||
PyObject *HM = PyConstant_New( );
|
||||
|
||||
if( HM ) {
|
||||
BPy_constant *d = ( BPy_constant * ) HM;
|
||||
|
||||
PyConstant_Insert( d, "FREE", PyInt_FromLong( HD_FREE ) );
|
||||
PyConstant_Insert( d, "AUTO", PyInt_FromLong( HD_AUTO ) );
|
||||
PyConstant_Insert( d, "VECT", PyInt_FromLong( HD_VECT ) );
|
||||
PyConstant_Insert( d, "ALIGN", PyInt_FromLong( HD_ALIGN ) );
|
||||
PyConstant_Insert( d, "AUTOANIM", PyInt_FromLong( HD_AUTO_ANIM ) );
|
||||
}
|
||||
return HM;
|
||||
}
|
||||
|
||||
/*
|
||||
BezTriple_Init
|
||||
*/
|
||||
|
||||
PyObject *BezTriple_Init( void )
|
||||
{
|
||||
PyObject *submodule;
|
||||
PyObject *HandleTypes = M_BezTriple_HandleDict( );
|
||||
|
||||
if( PyType_Ready( &BezTriple_Type ) < 0 )
|
||||
return NULL;
|
||||
|
||||
submodule = Py_InitModule3( "Blender.BezTriple",
|
||||
M_BezTriple_methods,
|
||||
M_BezTriple_doc );
|
||||
if( HandleTypes )
|
||||
PyModule_AddObject( submodule, "HandleTypes", HandleTypes );
|
||||
|
||||
|
||||
return submodule;
|
||||
}
|
||||
|
||||
/* Three Python BezTriple_Type helper functions needed by the Object module: */
|
||||
|
||||
/****************************************************************************
|
||||
Function: BezTriple_CreatePyObject
|
||||
Description: This function will create a new BPy_BezTriple from an existing
|
||||
Blender ipo structure.
|
||||
****************************************************************************/
|
||||
PyObject *BezTriple_CreatePyObject( BezTriple * bzt )
|
||||
{
|
||||
BPy_BezTriple *pybeztriple;
|
||||
|
||||
pybeztriple =
|
||||
( BPy_BezTriple * ) PyObject_NEW( BPy_BezTriple, &BezTriple_Type );
|
||||
|
||||
if( !pybeztriple )
|
||||
return EXPP_ReturnPyObjError( PyExc_MemoryError,
|
||||
"couldn't create BPy_BezTriple object" );
|
||||
|
||||
pybeztriple->beztriple = bzt;
|
||||
pybeztriple->own_memory = 0;
|
||||
|
||||
return ( PyObject * ) pybeztriple;
|
||||
}
|
||||
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Function: BezTriple_FromPyObject */
|
||||
/* Description: This function returns the Blender beztriple from the given */
|
||||
/* PyObject. */
|
||||
/*****************************************************************************/
|
||||
BezTriple *BezTriple_FromPyObject( PyObject * pyobj )
|
||||
{
|
||||
return ( ( BPy_BezTriple * ) pyobj )->beztriple;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
Create a new BezTriple
|
||||
input args is a sequence - either 3 or 9 floats
|
||||
*/
|
||||
|
||||
PyObject *newBezTriple( float *numbuf )
|
||||
{
|
||||
int i, j, num;
|
||||
PyObject *pyobj = NULL;
|
||||
BezTriple *bzt = NULL;
|
||||
|
||||
/* create our own beztriple data */
|
||||
bzt = MEM_callocN( sizeof( BezTriple ), "new bpytriple");
|
||||
|
||||
/* check malloc */
|
||||
if( !bzt )
|
||||
return EXPP_ReturnPyObjError( PyExc_RuntimeError,
|
||||
"MEM_callocN failed");
|
||||
|
||||
/* copy the data */
|
||||
num = 0;
|
||||
for( i = 0; i < 3; i++ ) {
|
||||
for( j = 0; j < 3; j++) {
|
||||
bzt->vec[i][j] = numbuf[num++];
|
||||
}
|
||||
}
|
||||
bzt->h1 = HD_ALIGN;
|
||||
bzt->h2 = HD_ALIGN;
|
||||
bzt->radius = 1.0;
|
||||
|
||||
/* wrap it */
|
||||
pyobj = BezTriple_CreatePyObject( bzt );
|
||||
|
||||
/* we own it. must free later */
|
||||
( ( BPy_BezTriple * )pyobj)->own_memory = 1;
|
||||
|
||||
return pyobj;
|
||||
}
|
||||
|
||||
/* #####DEPRECATED###### */
|
||||
|
||||
static PyObject *BezTriple_oldsetPoints( BPy_BezTriple * self, PyObject * args )
|
||||
{
|
||||
return EXPP_setterWrapper( (void *)self, args,
|
||||
(setter)BezTriple_setPoints );
|
||||
}
|
||||
@@ -1,61 +0,0 @@
|
||||
/*
|
||||
* $Id$
|
||||
*
|
||||
* ***** 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*
|
||||
* The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This is a new part of Blender.
|
||||
*
|
||||
* Contributor(s): Jacques Guignot, Stephen Swaney
|
||||
*
|
||||
* ***** END GPL LICENSE BLOCK *****
|
||||
*/
|
||||
|
||||
#ifndef EXPP_BEZTRIPLE_H
|
||||
#define EXPP_BEZTRIPLE_H
|
||||
|
||||
#include <Python.h>
|
||||
#include "DNA_curve_types.h"
|
||||
|
||||
extern PyTypeObject BezTriple_Type;
|
||||
|
||||
/* type check macro */
|
||||
#define BPy_BezTriple_Check(o) \
|
||||
( (o)->ob_type == &BezTriple_Type)
|
||||
|
||||
/****************************************************************************
|
||||
Python BPy_BezTriple structure definition:
|
||||
****************************************************************************/
|
||||
|
||||
typedef struct {
|
||||
PyObject_HEAD /* required python macro */
|
||||
BezTriple * beztriple;
|
||||
int own_memory; /* true == we own this memory and must delete. */
|
||||
} BPy_BezTriple;
|
||||
|
||||
/*
|
||||
* prototypes
|
||||
*/
|
||||
|
||||
PyObject *BezTriple_CreatePyObject( BezTriple * bzt );
|
||||
BezTriple *BezTriple_FromPyObject( PyObject * pyobj );
|
||||
PyObject *newBezTriple( float *args );
|
||||
PyObject *BezTriple_Init( void );
|
||||
|
||||
#endif /* EXPP_BEZTRIPLE_H */
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,38 +0,0 @@
|
||||
/*
|
||||
* $Id$
|
||||
*
|
||||
* ***** 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*
|
||||
* The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This is a new part of Blender.
|
||||
*
|
||||
* Contributor(s): Michel Selten, Willian P. Germano
|
||||
*
|
||||
* ***** END GPL LICENSE BLOCK *****
|
||||
*/
|
||||
|
||||
#ifndef EXPP_BLENDER_H
|
||||
#define EXPP_BLENDER_H
|
||||
|
||||
#include <Python.h>
|
||||
|
||||
extern PyObject *g_blenderdict;
|
||||
void M_Blender_Init( void );
|
||||
|
||||
#endif /* EXPP_BLENDER_H */
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,73 +0,0 @@
|
||||
/*
|
||||
* $Id$
|
||||
*
|
||||
* ***** 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*
|
||||
* The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Contributor(s): Joseph Gilbert
|
||||
*
|
||||
* ***** END GPL LICENSE BLOCK *****
|
||||
*/
|
||||
|
||||
#ifndef EXPP_BONE_H
|
||||
#define EXPP_BONE_H
|
||||
|
||||
#include <Python.h>
|
||||
#include "DNA_armature_types.h"
|
||||
|
||||
/*-------------------TYPE CHECKS---------------------------------*/
|
||||
#define BoneObject_Check(v) ((v)->ob_type == &Bone_Type)
|
||||
#define EditBoneObject_Check(v) ((v)->ob_type == &EditBone_Type)
|
||||
/*-------------------TYPEOBJECT----------------------------------*/
|
||||
extern PyTypeObject EditBone_Type;
|
||||
extern PyTypeObject Bone_Type;
|
||||
/*-------------------STRUCT DEFINITION----------------------------*/
|
||||
|
||||
typedef struct {
|
||||
PyObject_HEAD
|
||||
Bone * bone;
|
||||
} BPy_Bone;
|
||||
|
||||
typedef struct {
|
||||
PyObject_HEAD
|
||||
struct EditBone *editbone;
|
||||
struct EditBone *parent;
|
||||
char name[32];
|
||||
float roll;
|
||||
float head[3];
|
||||
float tail[3];
|
||||
int flag;
|
||||
float dist;
|
||||
float weight;
|
||||
float xwidth;
|
||||
float zwidth;
|
||||
float ease1;
|
||||
float ease2;
|
||||
float rad_head;
|
||||
float rad_tail;
|
||||
short segments;
|
||||
short layer;
|
||||
} BPy_EditBone;
|
||||
/*-------------------VISIBLE PROTOTYPES-------------------------*/
|
||||
PyObject *PyBone_FromBone(struct Bone *bone);
|
||||
struct Bone *PyBone_AsBone(BPy_Bone *py_Bone);
|
||||
PyObject *PyEditBone_FromBone(Bone *bone);
|
||||
PyObject *PyEditBone_FromEditBone(struct EditBone *editbone);
|
||||
|
||||
#endif
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,79 +0,0 @@
|
||||
/*
|
||||
* $Id$
|
||||
*
|
||||
* ***** 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*
|
||||
* The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This is a new part of Blender.
|
||||
*
|
||||
* Contributor(s): Willian P. Germano
|
||||
*
|
||||
* ***** END GPL LICENSE BLOCK *****
|
||||
*/
|
||||
|
||||
#ifndef EXPP_CAMERA_H
|
||||
#define EXPP_CAMERA_H
|
||||
|
||||
#include <Python.h>
|
||||
#include "DNA_camera_types.h"
|
||||
|
||||
extern PyTypeObject Camera_Type;
|
||||
|
||||
#define BPy_Camera_Check(v) \
|
||||
((v)->ob_type == &Camera_Type) /* for type checking */
|
||||
|
||||
/* Python BPy_Camera structure definition */
|
||||
typedef struct {
|
||||
PyObject_HEAD /* required py macro */
|
||||
Camera * camera;
|
||||
|
||||
} BPy_Camera;
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Python BPy_Camera defaults: */
|
||||
/*****************************************************************************/
|
||||
|
||||
/* Camera types */
|
||||
|
||||
#define EXPP_CAM_TYPE_PERSP 0
|
||||
#define EXPP_CAM_TYPE_ORTHO 1
|
||||
|
||||
/* Camera mode flags */
|
||||
|
||||
#define EXPP_CAM_MODE_SHOWLIMITS 1
|
||||
#define EXPP_CAM_MODE_SHOWMIST 2
|
||||
|
||||
/* Camera MIN, MAX values */
|
||||
|
||||
#define EXPP_CAM_LENS_MIN 1.0
|
||||
#define EXPP_CAM_LENS_MAX 250.0
|
||||
#define EXPP_CAM_SCALE_MIN 0.01f
|
||||
#define EXPP_CAM_SCALE_MAX 1000.0
|
||||
#define EXPP_CAM_CLIPSTART_MIN 0.0
|
||||
#define EXPP_CAM_CLIPSTART_MAX 100.0
|
||||
#define EXPP_CAM_CLIPEND_MIN 1.0
|
||||
#define EXPP_CAM_CLIPEND_MAX 5000.0
|
||||
#define EXPP_CAM_DRAWSIZE_MIN 0.1f
|
||||
#define EXPP_CAM_DRAWSIZE_MAX 10.0
|
||||
|
||||
PyObject *Camera_Init( void );
|
||||
PyObject *Camera_CreatePyObject( Camera * cam );
|
||||
Camera *Camera_FromPyObject( PyObject * pyobj );
|
||||
|
||||
#endif /* EXPP_CAMERA_H */
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,73 +0,0 @@
|
||||
/*
|
||||
* $Id$
|
||||
*
|
||||
* ***** 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*
|
||||
* The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This is a new part of Blender.
|
||||
*
|
||||
* Contributor(s): Joseph Gilbert, Ken Hughes
|
||||
*
|
||||
* ***** END GPL LICENSE BLOCK *****
|
||||
*/
|
||||
|
||||
#ifndef EXPP_CONSTRAINT_H
|
||||
#define EXPP_CONSTRAINT_H
|
||||
|
||||
#include <Python.h>
|
||||
#include "DNA_object_types.h"
|
||||
#include "DNA_action_types.h"
|
||||
#include "DNA_constraint_types.h"
|
||||
#include "DNA_listBase.h"
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Python BPy_Modifier structure definition: */
|
||||
/*****************************************************************************/
|
||||
typedef struct {
|
||||
PyObject_HEAD /* required macro */
|
||||
Object *obj; /* "parent" object */
|
||||
bPoseChannel *pchan;/* "parent" pose channel */
|
||||
/* if con this is null, the constraint has been removed and we need to
|
||||
* raise an error when its data is accessed */
|
||||
bConstraint *con;
|
||||
} BPy_Constraint;
|
||||
|
||||
extern PyTypeObject Constraint_Type;
|
||||
|
||||
#define BPy_Constraint_Check(v) ((v)->ob_type == &Constraint_Type) /* for type checking */
|
||||
typedef struct {
|
||||
PyObject_HEAD /* required macro */
|
||||
Object *obj; /* "parent" object */
|
||||
bPoseChannel *pchan;/* "parent" pose channel */
|
||||
bConstraint *iter;
|
||||
} BPy_ConstraintSeq;
|
||||
|
||||
/*
|
||||
* prototypes
|
||||
*/
|
||||
|
||||
PyObject *Constraint_Init( void );
|
||||
PyObject *Constraint_CreatePyObject( bPoseChannel *pchan, Object *obj,
|
||||
bConstraint *con );
|
||||
bConstraint *Constraint_FromPyObject( BPy_Constraint * obj );
|
||||
|
||||
PyObject *PoseConstraintSeq_CreatePyObject( bPoseChannel *pchan );
|
||||
PyObject *ObConstraintSeq_CreatePyObject( Object *obj );
|
||||
|
||||
#endif /* EXPP_CONSTRAINT_H */
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,67 +0,0 @@
|
||||
/*
|
||||
* $Id$
|
||||
* ***** 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*
|
||||
* The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This is a new part of Blender.
|
||||
*
|
||||
* Contributor(s): Stephen Swaney
|
||||
*
|
||||
* ***** END GPL LICENSE BLOCK *****
|
||||
*/
|
||||
|
||||
#ifndef EXPP_NURB_H
|
||||
#define EXPP_NURB_H
|
||||
|
||||
#include <Python.h>
|
||||
#include "DNA_curve_types.h"
|
||||
|
||||
extern PyTypeObject CurNurb_Type;
|
||||
|
||||
#define BPy_CurNurb_Check(v) ((v)->ob_type == &CurNurb_Type) /* for type checking */
|
||||
|
||||
/* Python BPy_CurNurb structure definition */
|
||||
typedef struct {
|
||||
PyObject_HEAD /* required py macro */
|
||||
Nurb * nurb; /* pointer to Blender data */
|
||||
|
||||
/* iterator stuff */
|
||||
/* internal ptrs to point data. do not free */
|
||||
BPoint *bp;
|
||||
BezTriple *bezt;
|
||||
int atEnd; /* iter exhausted flag */
|
||||
int nextPoint;
|
||||
|
||||
} BPy_CurNurb;
|
||||
|
||||
|
||||
/*
|
||||
* prototypes
|
||||
*/
|
||||
|
||||
PyObject *CurNurb_Init( void );
|
||||
PyObject *CurNurb_CreatePyObject( Nurb * bzt );
|
||||
Nurb *CurNurb_FromPyObject( PyObject * pyobj );
|
||||
|
||||
PyObject *CurNurb_getPoint( BPy_CurNurb * self, int index );
|
||||
PyObject *CurNurb_pointAtIndex( Nurb * nurb, int index );
|
||||
|
||||
PyObject *CurNurb_appendPointToNurb( Nurb * nurb, PyObject * args );
|
||||
|
||||
#endif /* EXPP_NURB_H */
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,75 +0,0 @@
|
||||
/*
|
||||
* $Id$
|
||||
*
|
||||
* ***** 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*
|
||||
* The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This is a new part of Blender.
|
||||
*
|
||||
* Contributor(s): Jacques Guignot, Stephen Swaney
|
||||
*
|
||||
* ***** END GPL LICENSE BLOCK *****
|
||||
*/
|
||||
|
||||
#ifndef EXPP_CURVE_H
|
||||
#define EXPP_CURVE_H
|
||||
|
||||
#include <Python.h>
|
||||
#include "DNA_curve_types.h"
|
||||
|
||||
extern PyTypeObject Curve_Type;
|
||||
|
||||
#define BPy_Curve_Check(v) ((v)->ob_type==&Curve_Type)
|
||||
|
||||
/* Python BPy_Curve structure definition */
|
||||
typedef struct {
|
||||
PyObject_HEAD /* required py macro */
|
||||
Curve * curve; /* libdata must be second */
|
||||
/* pointer for iterator: does not point to owned memory */
|
||||
Nurb *iter_pointer;
|
||||
} BPy_Curve;
|
||||
|
||||
|
||||
/*
|
||||
* protoypes
|
||||
*/
|
||||
|
||||
PyObject *Curve_Init( void );
|
||||
PyObject *Curve_CreatePyObject( struct Curve * curve );
|
||||
struct Curve *Curve_FromPyObject( PyObject * py_obj );
|
||||
PyObject *Curve_update( BPy_Curve * self );
|
||||
|
||||
PyObject *Curve_getName( BPy_Curve * self );
|
||||
PyObject *Curve_setName( BPy_Curve * self, PyObject * args );
|
||||
PyObject *Curve_getMode( BPy_Curve * self );
|
||||
PyObject *Curve_setMode( BPy_Curve * self, PyObject * args );
|
||||
PyObject *Curve_getBevresol( BPy_Curve * self );
|
||||
PyObject *Curve_setBevresol( BPy_Curve * self, PyObject * args );
|
||||
PyObject *Curve_getResolu( BPy_Curve * self );
|
||||
PyObject *Curve_setResolu( BPy_Curve * self, PyObject * args );
|
||||
PyObject *Curve_getResolv( BPy_Curve * self );
|
||||
PyObject *Curve_setResolv( BPy_Curve * self, PyObject * args );
|
||||
PyObject *Curve_getExt1( BPy_Curve * self );
|
||||
PyObject *Curve_setExt1( BPy_Curve * self, PyObject * args );
|
||||
PyObject *Curve_getExt2( BPy_Curve * self );
|
||||
PyObject *Curve_setExt2( BPy_Curve * self, PyObject * args );
|
||||
PyObject *Curve_getWidth( BPy_Curve * self );
|
||||
PyObject *Curve_setWidth( BPy_Curve * self, PyObject * args );
|
||||
|
||||
#endif /* EXPP_CURVE_H */
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,74 +0,0 @@
|
||||
/*
|
||||
* $Id$
|
||||
*
|
||||
* ***** 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*
|
||||
* The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This is a new part of Blender.
|
||||
*
|
||||
* Contributor(s): Willian P. Germano
|
||||
*
|
||||
* ***** END GPL LICENSE BLOCK *****
|
||||
*/
|
||||
|
||||
/* The code in Draw.[ch] and BGL.[ch] comes from opy_draw.c in the old
|
||||
* bpython/intern dir, with minor modifications to suit the current
|
||||
* implementation. Important original comments are marked with an @ symbol. */
|
||||
|
||||
#ifndef EXPP_DRAW_H_
|
||||
#define EXPP_DRAW_H_
|
||||
|
||||
#include <Python.h>
|
||||
#include "DNA_space_types.h"
|
||||
#include "DNA_text_types.h"
|
||||
|
||||
void initDraw( void );
|
||||
|
||||
/*
|
||||
* Button Object stuct
|
||||
*/
|
||||
|
||||
typedef struct _Button {
|
||||
PyObject_VAR_HEAD /* required Py Macro */
|
||||
int type; /*@ 1 == int, 2 == float, 3 == string */
|
||||
unsigned int slen; /*@ length of string (if type == 3) */
|
||||
union {
|
||||
int asint;
|
||||
float asfloat;
|
||||
char *asstr;
|
||||
float asvec[3];
|
||||
} val;
|
||||
char tooltip[256];
|
||||
} Button;
|
||||
|
||||
#define BPY_MAX_TOOLTIP 255
|
||||
|
||||
#define BINT_TYPE 1
|
||||
#define BFLOAT_TYPE 2
|
||||
#define BSTRING_TYPE 3
|
||||
#define BVECTOR_TYPE 4
|
||||
|
||||
/*
|
||||
* these are declared in ../BPY_extern.h
|
||||
*/
|
||||
|
||||
PyObject *M_Draw_Init( void );
|
||||
PyObject *Draw_Init( void );
|
||||
|
||||
#endif /* EXPP_DRAW_H */
|
||||
@@ -1,227 +0,0 @@
|
||||
/*
|
||||
* $Id$
|
||||
*
|
||||
* ***** 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*
|
||||
* The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This is a new part of Blender.
|
||||
*
|
||||
* Contributor(s): Michel Selten
|
||||
*
|
||||
* ***** END GPL LICENSE BLOCK *****
|
||||
*/
|
||||
|
||||
#include <Python.h>
|
||||
|
||||
#include "EXPP_interface.h"
|
||||
#include "BLI_blenlib.h"
|
||||
#include "MEM_guardedalloc.h"
|
||||
#include "BLI_linklist.h" /* linked list: LinkNode struct and functions */
|
||||
#include "DNA_object_types.h"
|
||||
#include "DNA_space_types.h" /* for FILE_MAXDIR, FILE_MAXFILE */
|
||||
#include "Blender.h"
|
||||
|
||||
extern char bprogname[]; /* argv[0] from creator.c */
|
||||
|
||||
/* this makes sure BLI_gethome() returns a path with '.blender' appended
|
||||
* Besides, this function now either returns userhome/.blender (if it exists)
|
||||
* or blenderInstallDir/.blender/ otherwise (can also be cvs dir).
|
||||
* If append_scriptsdir is non NULL, "scripts/" is appended to the dir, to
|
||||
* get the path to the scripts folder ("release/scripts/" if cvs dir).
|
||||
* Finally, if all else fails BLI_gethome() is returned
|
||||
* (or NULL if append_scriptdir != 0).
|
||||
*/
|
||||
char *bpy_gethome(int append_scriptsdir)
|
||||
{
|
||||
static char homedir[FILE_MAXDIR];
|
||||
static char scriptsdir[FILE_MAXDIR];
|
||||
char tmpdir[FILE_MAXDIR];
|
||||
char bprogdir[FILE_MAXDIR];
|
||||
char *s;
|
||||
int i;
|
||||
|
||||
if (append_scriptsdir) {
|
||||
if (scriptsdir[0] != '\0')
|
||||
return scriptsdir;
|
||||
}
|
||||
else if (homedir[0] != '\0')
|
||||
return homedir;
|
||||
|
||||
/* BLI_gethome() can return NULL if env vars are not set */
|
||||
s = BLI_gethome();
|
||||
|
||||
if( !s ) /* bail if no $HOME */
|
||||
{
|
||||
printf("$HOME is NOT set\n");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if( strstr( s, ".blender" ) )
|
||||
PyOS_snprintf( homedir, FILE_MAXDIR, s );
|
||||
else
|
||||
BLI_make_file_string( "/", homedir, s, ".blender" );
|
||||
|
||||
/* if userhome/.blender/ exists, return it */
|
||||
if( BLI_exists( homedir ) ) {
|
||||
if (append_scriptsdir) {
|
||||
BLI_make_file_string("/", scriptsdir, homedir, "scripts");
|
||||
if (BLI_exists (scriptsdir)) return scriptsdir;
|
||||
}
|
||||
else return homedir;
|
||||
}
|
||||
else homedir[0] = '\0';
|
||||
|
||||
/* if either:
|
||||
* no homedir was found or
|
||||
* append_scriptsdir = 1 but there's no scripts/ inside homedir,
|
||||
* use argv[0] (bprogname) to get .blender/ in
|
||||
* Blender's installation dir */
|
||||
s = BLI_last_slash( bprogname );
|
||||
|
||||
i = s - bprogname + 1;
|
||||
|
||||
PyOS_snprintf( bprogdir, i, "%s", bprogname );
|
||||
|
||||
/* using tmpdir to preserve homedir (if) found above:
|
||||
* the ideal is to have a home dir with scripts dir inside
|
||||
* it, but if that isn't available, it's possible to
|
||||
* have a 'broken' home dir somewhere and a scripts dir in the
|
||||
* cvs sources */
|
||||
BLI_make_file_string( "/", tmpdir, bprogdir, ".blender" );
|
||||
|
||||
if (BLI_exists(tmpdir)) {
|
||||
if (append_scriptsdir) {
|
||||
BLI_make_file_string("/", scriptsdir, tmpdir, "scripts");
|
||||
if (BLI_exists(scriptsdir)) {
|
||||
PyOS_snprintf(homedir, FILE_MAXDIR, "%s", tmpdir);
|
||||
return scriptsdir;
|
||||
}
|
||||
else {
|
||||
homedir[0] = '\0';
|
||||
scriptsdir[0] = '\0';
|
||||
}
|
||||
}
|
||||
else return homedir;
|
||||
}
|
||||
|
||||
/* last try for scripts dir: blender in cvs dir, scripts/ inside release/: */
|
||||
if (append_scriptsdir) {
|
||||
BLI_make_file_string("/", scriptsdir, bprogdir, "release/scripts");
|
||||
if (BLI_exists(scriptsdir)) return scriptsdir;
|
||||
else scriptsdir[0] = '\0';
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* PyDrivers */
|
||||
|
||||
/*
|
||||
* Pydrivers are Blender Ipo Drivers defined by Python expressions.
|
||||
* We need to tell DAG about objects used in these expressions, so we
|
||||
* eval each expression to collect the ob refs. in it.
|
||||
*/
|
||||
|
||||
/* these are checked for example in Object.c: M_Object_Get (Object.Get())
|
||||
* to collect the refs. */
|
||||
static int pydriver_running = 0;
|
||||
|
||||
int bpy_during_pydriver(void)
|
||||
{
|
||||
return pydriver_running;
|
||||
}
|
||||
|
||||
void bpy_pydriver_running(int state)
|
||||
{
|
||||
pydriver_running = state;
|
||||
}
|
||||
|
||||
/* Obj references are collected in this extern linked list: */
|
||||
LinkNode *bpy_pydriver_oblist = NULL;
|
||||
|
||||
void bpy_pydriver_freeList(void)
|
||||
{
|
||||
BLI_linklist_free(bpy_pydriver_oblist, NULL);
|
||||
bpy_pydriver_oblist = NULL;
|
||||
}
|
||||
|
||||
void bpy_pydriver_appendToList(struct Object *ob)
|
||||
{
|
||||
LinkNode *ln = bpy_pydriver_oblist;
|
||||
|
||||
/* check that the expression is not referencing its owner object */
|
||||
|
||||
/* XXX COMMENTED OUT TO TEST IF WE REALLY NEED TO IMPOSE THIS RESTRICTION
|
||||
if (ln && ln->link) {
|
||||
if (ob == (Object *)ln->link) {
|
||||
PyErr_SetString(PyExc_AttributeError,
|
||||
"Python driver expression can't reference its own object");
|
||||
return;
|
||||
}
|
||||
else
|
||||
ln = ln->next;
|
||||
}
|
||||
*/
|
||||
while (ln) { /* is ob already in list? ... */
|
||||
if (ob == (Object *)ln->link)
|
||||
break;
|
||||
ln = ln->next;
|
||||
}
|
||||
|
||||
if (!ln) /* ... not yet, append it */
|
||||
BLI_linklist_append(&bpy_pydriver_oblist, (void *)ob);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/* Get an array from our linked list of objs referenced in the
|
||||
* current pydriver. The first node in the list is discarded,
|
||||
* since it is the actual pydriver owner, which shouldn't be
|
||||
* passed to the depsgraph (no self references). */
|
||||
struct Object **bpy_pydriver_obArrayFromList(void)
|
||||
{
|
||||
Object **obarray = NULL;
|
||||
|
||||
if (bpy_pydriver_oblist) {
|
||||
int i;
|
||||
short len = BLI_linklist_length(bpy_pydriver_oblist);
|
||||
|
||||
if (len > 1) {
|
||||
|
||||
obarray = (Object **)MEM_mallocN(sizeof(Object*)*len,
|
||||
"pydriver array");
|
||||
|
||||
if (obarray) {
|
||||
LinkNode *ln = bpy_pydriver_oblist;
|
||||
ln = ln->next; /* skip first ob, which is the pydriver owner */
|
||||
|
||||
for (i = 0; i < len-1; i++) {
|
||||
obarray[i] = (Object *)ln->link;
|
||||
ln = ln->next;
|
||||
}
|
||||
|
||||
obarray[len-1] = NULL; /* NULL-terminated array */
|
||||
}
|
||||
}
|
||||
bpy_pydriver_freeList();
|
||||
}
|
||||
|
||||
return obarray;
|
||||
}
|
||||
|
||||
@@ -1,53 +0,0 @@
|
||||
/*
|
||||
* $Id$
|
||||
*
|
||||
* ***** 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*
|
||||
* The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This is a new part of Blender.
|
||||
*
|
||||
* Contributor(s): Michel Selten, Willian P. Germano
|
||||
*
|
||||
* ***** END GPL LICENSE BLOCK *****
|
||||
*/
|
||||
|
||||
#ifndef EXPP_INTERFACE_H
|
||||
#define EXPP_INTERFACE_H
|
||||
|
||||
struct Object;
|
||||
struct Script;
|
||||
struct LinkNode;
|
||||
|
||||
extern struct LinkNode *bpy_pydriver_oblist;
|
||||
|
||||
void initBlenderApi2_2x( void );
|
||||
char *bpy_gethome( int append_scriptsdir );
|
||||
void discardFromBDict( char *key );
|
||||
void EXPP_Library_Close( void ); /* in Library.c, used by BPY_end_python */
|
||||
|
||||
/* PyDrivers */
|
||||
|
||||
void bpy_pydriver_freeList(void);
|
||||
void bpy_pydriver_appendToList(struct Object *ob);
|
||||
struct Object **bpy_pydriver_obArrayFromList(void);
|
||||
|
||||
int bpy_during_pydriver(void);
|
||||
void bpy_pydriver_running(int state);
|
||||
|
||||
#endif /* EXPP_INTERFACE_H */
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,55 +0,0 @@
|
||||
/*
|
||||
* $Id$
|
||||
*
|
||||
* ***** 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*
|
||||
* The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This is a new part of Blender.
|
||||
*
|
||||
* Contributor(s): Jacques Guignot
|
||||
*
|
||||
* ***** END GPL LICENSE BLOCK *****
|
||||
*/
|
||||
|
||||
#ifndef EXPP_EFFECT_H
|
||||
#define EXPP_EFFECT_H
|
||||
|
||||
#include <Python.h>
|
||||
#include "DNA_effect_types.h"
|
||||
#include "DNA_object_types.h"
|
||||
|
||||
extern PyTypeObject Effect_Type;
|
||||
|
||||
#define BPy_Effect_Check(v) ((v)->ob_type==&Effect_Type)
|
||||
|
||||
/* Python BPy_Effect structure definition */
|
||||
typedef struct {
|
||||
PyObject_HEAD /* required py macro */
|
||||
PartEff * effect;
|
||||
Object * object;
|
||||
} BPy_Effect;
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Python Effect_Type helpder function prototypes: */
|
||||
/*****************************************************************************/
|
||||
PyObject *Effect_Init( void );
|
||||
int EffectCheckPyObject( PyObject * py_obj );
|
||||
PyObject *EffectCreatePyObject( Effect * eff, Object * ob );
|
||||
|
||||
#endif /* EXPP_EFFECT_H */
|
||||
@@ -1,400 +0,0 @@
|
||||
/*
|
||||
* ***** 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*
|
||||
* The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This is a new part of Blender.
|
||||
*
|
||||
* Contributor(s): Joilnen Leite
|
||||
*
|
||||
* ***** END GPL LICENSE BLOCK *****
|
||||
*/
|
||||
|
||||
#include "Font.h" /*This must come first*/
|
||||
|
||||
#include "DNA_packedFile_types.h"
|
||||
#include "BKE_packedFile.h"
|
||||
#include "BKE_global.h"
|
||||
#include "BKE_library.h" /* for rename_id() */
|
||||
#include "BLI_blenlib.h"
|
||||
#include "gen_utils.h"
|
||||
#include "gen_library.h"
|
||||
|
||||
#include "BKE_main.h" /* so we can access G.main->vfont.first */
|
||||
#include "DNA_space_types.h" /* for FILE_MAXDIR only */
|
||||
|
||||
extern PyObject *M_Text3d_LoadFont( PyObject * self, PyObject * args );
|
||||
|
||||
/*--------------------Python API function prototypes for the Font module----*/
|
||||
static PyObject *M_Font_Load( PyObject * self, PyObject * value );
|
||||
static PyObject *M_Font_Get( PyObject * self, PyObject * args );
|
||||
|
||||
/*------------------------Python API Doc strings for the Font module--------*/
|
||||
char M_Font_doc[] = "The Blender Font module\n\n\
|
||||
This module provides control over **Font Data** objects in Blender.\n\n\
|
||||
Example::\n\n\
|
||||
from Blender import Text3d.Font\n\
|
||||
l = Text3d.Font.Load('/usr/share/fonts/verdata.ttf')\n";
|
||||
char M_Font_Get_doc[] = "(name) - return an existing font called 'name'\
|
||||
when no argument is given it returns a list of blenders fonts.";
|
||||
char M_Font_Load_doc[] =
|
||||
"(filename) - return font from file filename as Font Object, \
|
||||
returns None if not found.\n";
|
||||
|
||||
/*----- Python method structure definition for Blender.Text3d.Font module---*/
|
||||
struct PyMethodDef M_Font_methods[] = {
|
||||
{"Get", ( PyCFunction ) M_Font_Get, METH_VARARGS, M_Font_Get_doc},
|
||||
{"Load", ( PyCFunction ) M_Font_Load, METH_O, M_Font_Load_doc},
|
||||
{NULL, NULL, 0, NULL}
|
||||
};
|
||||
|
||||
/*--------------- Python BPy_Font methods declarations:-------------------*/
|
||||
static PyObject *Font_pack( BPy_Font * self );
|
||||
static PyObject *Font_unpack( BPy_Font * self, PyObject * args );
|
||||
|
||||
/*--------------- Python BPy_Font methods table:--------------------------*/
|
||||
static PyMethodDef BPy_Font_methods[] = {
|
||||
{"pack", ( PyCFunction ) Font_pack, METH_NOARGS,
|
||||
"() - pack this Font"},
|
||||
{"unpack", ( PyCFunction ) Font_unpack, METH_O,
|
||||
"(mode) - unpack this packed font"},
|
||||
{NULL, NULL, 0, NULL}
|
||||
};
|
||||
|
||||
/*--------------- Python TypeFont callback function prototypes----------*/
|
||||
static int Font_compare( BPy_Font * a1, BPy_Font * a2 );
|
||||
static PyObject *Font_repr( BPy_Font * font );
|
||||
|
||||
|
||||
/*--------------- Python Font Module methods------------------------*/
|
||||
|
||||
/*--------------- Blender.Text3d.Font.Get()-----------------------*/
|
||||
static PyObject *M_Font_Get( PyObject * self, PyObject * args )
|
||||
{
|
||||
char *name = NULL;
|
||||
VFont *vfont_iter;
|
||||
|
||||
if( !PyArg_ParseTuple( args, "|s", &name ) )
|
||||
return ( EXPP_ReturnPyObjError( PyExc_TypeError,
|
||||
"expected string argument (or nothing)" ) );
|
||||
|
||||
vfont_iter = G.main->vfont.first;
|
||||
|
||||
if( name ) { /* (name) - Search font by name */
|
||||
|
||||
BPy_Font *wanted_vfont = NULL;
|
||||
|
||||
while(vfont_iter) {
|
||||
if( strcmp( name, vfont_iter->id.name + 2 ) == 0 ) {
|
||||
wanted_vfont =
|
||||
( BPy_Font * )
|
||||
Font_CreatePyObject( vfont_iter );
|
||||
break;
|
||||
}
|
||||
vfont_iter = vfont_iter->id.next;
|
||||
}
|
||||
|
||||
if( wanted_vfont == NULL ) { /* Requested font doesn't exist */
|
||||
char error_msg[64];
|
||||
PyOS_snprintf( error_msg, sizeof( error_msg ),
|
||||
"Font \"%s\" not found", name );
|
||||
return ( EXPP_ReturnPyObjError
|
||||
( PyExc_NameError, error_msg ) );
|
||||
}
|
||||
|
||||
return ( PyObject * ) wanted_vfont;
|
||||
}
|
||||
|
||||
else { /* () - return a list of all fonts in the scene */
|
||||
int index = 0;
|
||||
PyObject *vfontlist, *pyobj;
|
||||
|
||||
vfontlist = PyList_New( BLI_countlist( &( G.main->vfont ) ) );
|
||||
|
||||
if( vfontlist == NULL )
|
||||
return ( EXPP_ReturnPyObjError( PyExc_MemoryError,
|
||||
"couldn't create font list" ) );
|
||||
|
||||
while( vfont_iter ) {
|
||||
pyobj = Font_CreatePyObject( vfont_iter );
|
||||
|
||||
if( !pyobj ) {
|
||||
Py_DECREF(vfontlist);
|
||||
return ( EXPP_ReturnPyObjError
|
||||
( PyExc_MemoryError,
|
||||
"couldn't create Object" ) );
|
||||
}
|
||||
PyList_SET_ITEM( vfontlist, index, pyobj );
|
||||
|
||||
vfont_iter = vfont_iter->id.next;
|
||||
index++;
|
||||
}
|
||||
|
||||
return vfontlist;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*--------------- Blender.Text3d.Font.New()-----------------------*/
|
||||
PyObject *M_Font_Load( PyObject * self, PyObject * value )
|
||||
{
|
||||
char *filename_str = PyString_AsString(value);
|
||||
BPy_Font *py_font = NULL; /* for Font Data object wrapper in Python */
|
||||
|
||||
if( !value )
|
||||
return ( EXPP_ReturnPyObjError( PyExc_AttributeError,
|
||||
"expected string or empty argument" ) );
|
||||
|
||||
/*create python font*/
|
||||
if( !S_ISDIR(BLI_exist(filename_str)) ) {
|
||||
py_font= (BPy_Font *) M_Text3d_LoadFont (self, value);
|
||||
}
|
||||
else
|
||||
Py_RETURN_NONE;
|
||||
return ( PyObject * ) py_font;
|
||||
}
|
||||
|
||||
/*--------------- Python BPy_Font getsetattr funcs ---------------------*/
|
||||
|
||||
|
||||
/*--------------- BPy_Font.filename-------------------------------------*/
|
||||
static PyObject *Font_getFilename( BPy_Font * self )
|
||||
{
|
||||
return PyString_FromString( self->font->name );
|
||||
}
|
||||
|
||||
static int Font_setFilename( BPy_Font * self, PyObject * value )
|
||||
{
|
||||
char *name = NULL;
|
||||
|
||||
/* max len is FILE_MAXDIR = 160 chars like done in DNA_image_types.h */
|
||||
|
||||
name = PyString_AsString ( value );
|
||||
if( !name )
|
||||
return EXPP_ReturnIntError( PyExc_TypeError,
|
||||
"expected string argument" );
|
||||
|
||||
PyOS_snprintf( self->font->name, FILE_MAXDIR * sizeof( char ), "%s",
|
||||
name );
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*--------------- BPy_Font.pack()---------------------------------*/
|
||||
static PyObject *Font_pack( BPy_Font * self )
|
||||
{
|
||||
if( !self->font->packedfile )
|
||||
self->font->packedfile = newPackedFile(self->font->name);
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
/*--------------- BPy_Font.unpack()---------------------------------*/
|
||||
static PyObject *Font_unpack( BPy_Font * self, PyObject * value )
|
||||
{
|
||||
int mode= PyInt_AsLong(value);
|
||||
VFont *font= self->font;
|
||||
|
||||
if( mode==-1 )
|
||||
return ( EXPP_ReturnPyObjError
|
||||
( PyExc_AttributeError,
|
||||
"expected int argument from Blender.UnpackModes" ) );
|
||||
|
||||
if (font->packedfile)
|
||||
if (unpackVFont(font, mode) == RET_ERROR)
|
||||
return EXPP_ReturnPyObjError( PyExc_RuntimeError,
|
||||
"error unpacking font" );
|
||||
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
/*--------------- BPy_Font.packed---------------------------------*/
|
||||
static PyObject *Font_getPacked( BPy_Font * self )
|
||||
{
|
||||
if (G.fileflags & G_AUTOPACK)
|
||||
return EXPP_incr_ret_True();
|
||||
else
|
||||
return EXPP_incr_ret_False();
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Python attributes get/set structure: */
|
||||
/*****************************************************************************/
|
||||
static PyGetSetDef BPy_Font_getseters[] = {
|
||||
GENERIC_LIB_GETSETATTR,
|
||||
{"filename",
|
||||
(getter)Font_getFilename, (setter)Font_setFilename,
|
||||
"Font filepath",
|
||||
NULL},
|
||||
{"packed",
|
||||
(getter)Font_getPacked, (setter)NULL,
|
||||
"Packed status",
|
||||
NULL},
|
||||
{NULL,NULL,NULL,NULL,NULL} /* Sentinel */
|
||||
};
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Python TypeFont structure definition: */
|
||||
/*****************************************************************************/
|
||||
PyTypeObject Font_Type = {
|
||||
PyObject_HEAD_INIT( NULL ) /* required py macro */
|
||||
0, /* ob_size */
|
||||
/* For printing, in format "<module>.<name>" */
|
||||
"Blender Font", /* char *tp_name; */
|
||||
sizeof( BPy_Font ), /* int tp_basicsize; */
|
||||
0, /* tp_itemsize; For allocation */
|
||||
|
||||
/* Methods to implement standard operations */
|
||||
|
||||
NULL, /* destructor tp_dealloc; */
|
||||
NULL, /* printfunc tp_print; */
|
||||
NULL, /* getattrfunc tp_getattr; */
|
||||
NULL, /* setattrfunc tp_setattr; */
|
||||
( cmpfunc ) Font_compare, /* cmpfunc tp_compare; */
|
||||
( reprfunc ) Font_repr, /* reprfunc tp_repr; */
|
||||
|
||||
/* Method suites for standard classes */
|
||||
|
||||
NULL, /* PyNumberMethods *tp_as_number; */
|
||||
NULL, /* PySequenceMethods *tp_as_sequence; */
|
||||
NULL, /* PyMappingMethods *tp_as_mapping; */
|
||||
|
||||
/* More standard operations (here for binary compatibility) */
|
||||
|
||||
( hashfunc ) GenericLib_hash, /* hashfunc tp_hash; */
|
||||
NULL, /* ternaryfunc tp_call; */
|
||||
NULL, /* reprfunc tp_str; */
|
||||
NULL, /* getattrofunc tp_getattro; */
|
||||
NULL, /* setattrofunc tp_setattro; */
|
||||
|
||||
/* Functions to access object as input/output buffer */
|
||||
NULL, /* PyBufferProcs *tp_as_buffer; */
|
||||
|
||||
/*** Flags to define presence of optional/expanded features ***/
|
||||
Py_TPFLAGS_DEFAULT, /* long tp_flags; */
|
||||
|
||||
NULL, /* char *tp_doc; Documentation string */
|
||||
/*** Assigned meaning in release 2.0 ***/
|
||||
/* call function for all accessible objects */
|
||||
NULL, /* traverseproc tp_traverse; */
|
||||
|
||||
/* delete references to contained objects */
|
||||
NULL, /* inquiry tp_clear; */
|
||||
|
||||
/*** Assigned meaning in release 2.1 ***/
|
||||
/*** rich comparisons ***/
|
||||
NULL, /* richcmpfunc tp_richcompare; */
|
||||
|
||||
/*** weak reference enabler ***/
|
||||
0, /* long tp_weaklistoffset; */
|
||||
|
||||
/*** Added in release 2.2 ***/
|
||||
/* Iterators */
|
||||
NULL, /* getiterfunc tp_iter; */
|
||||
NULL, /* iternextfunc tp_iternext; */
|
||||
|
||||
/*** Attribute descriptor and subclassing stuff ***/
|
||||
BPy_Font_methods, /* struct PyMethodDef *tp_methods; */
|
||||
NULL, /* struct PyMemberDef *tp_members; */
|
||||
BPy_Font_getseters, /* struct PyGetSetDef *tp_getset; */
|
||||
NULL, /* struct _typeobject *tp_base; */
|
||||
NULL, /* PyObject *tp_dict; */
|
||||
NULL, /* descrgetfunc tp_descr_get; */
|
||||
NULL, /* descrsetfunc tp_descr_set; */
|
||||
0, /* long tp_dictoffset; */
|
||||
NULL, /* initproc tp_init; */
|
||||
NULL, /* allocfunc tp_alloc; */
|
||||
NULL, /* newfunc tp_new; */
|
||||
/* Low-level free-memory routine */
|
||||
NULL, /* freefunc tp_free; */
|
||||
/* For PyObject_IS_GC */
|
||||
NULL, /* inquiry tp_is_gc; */
|
||||
NULL, /* PyObject *tp_bases; */
|
||||
/* method resolution order */
|
||||
NULL, /* PyObject *tp_mro; */
|
||||
NULL, /* PyObject *tp_cache; */
|
||||
NULL, /* PyObject *tp_subclasses; */
|
||||
NULL, /* PyObject *tp_weaklist; */
|
||||
NULL
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/*--------------- Font Module Init-----------------------------*/
|
||||
PyObject *Font_Init( void )
|
||||
{
|
||||
PyObject *submodule;
|
||||
|
||||
if( PyType_Ready( &Font_Type ) < 0 )
|
||||
return NULL;
|
||||
|
||||
submodule = Py_InitModule3( "Blender.Text3d.Font",
|
||||
M_Font_methods, M_Font_doc );
|
||||
|
||||
return ( submodule );
|
||||
}
|
||||
|
||||
/*--------------- Font module internal callbacks-----------------*/
|
||||
/*---------------BPy_Font internal callbacks/methods-------------*/
|
||||
|
||||
/*--------------- repr---------------------------------------------*/
|
||||
static PyObject *Font_repr( BPy_Font * self )
|
||||
{
|
||||
if( self->font )
|
||||
return PyString_FromFormat( "[Font \"%s\"]",
|
||||
self->font->id.name+2 );
|
||||
else
|
||||
return PyString_FromString( "[Font - no data]" );
|
||||
}
|
||||
|
||||
/*--------------- compare------------------------------------------*/
|
||||
static int Font_compare( BPy_Font * a, BPy_Font * b )
|
||||
{
|
||||
return ( a->font == b->font ) ? 0 : -1;
|
||||
}
|
||||
|
||||
/*--------------- Font_CreatePyObject---------------------------------*/
|
||||
PyObject *Font_CreatePyObject( struct VFont * font )
|
||||
{
|
||||
BPy_Font *blen_font;
|
||||
|
||||
blen_font = ( BPy_Font * ) PyObject_NEW( BPy_Font, &Font_Type );
|
||||
|
||||
blen_font->font = font;
|
||||
|
||||
return ( ( PyObject * ) blen_font );
|
||||
}
|
||||
|
||||
/*--------------- Font_FromPyObject---------------------------------*/
|
||||
struct VFont *Font_FromPyObject( PyObject * py_obj )
|
||||
{
|
||||
BPy_Font *blen_obj;
|
||||
|
||||
blen_obj = ( BPy_Font * ) py_obj;
|
||||
if( !( ( BPy_Font * ) py_obj )->font ) { /*test to see if linked to text3d*/
|
||||
//use python vars
|
||||
return NULL;
|
||||
} else {
|
||||
return ( blen_obj->font );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,841 +0,0 @@
|
||||
/*
|
||||
* ***** 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*
|
||||
* The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This is a new part of Blender.
|
||||
*
|
||||
* Contributor(s): Campbell Barton
|
||||
*
|
||||
* ***** END GPL LICENSE BLOCK *****
|
||||
*/
|
||||
|
||||
#include "Group.h" /* This must come first */
|
||||
|
||||
#include "MEM_guardedalloc.h"
|
||||
|
||||
#include "DNA_group_types.h"
|
||||
#include "DNA_scene_types.h" /* for Base */
|
||||
|
||||
#include "BKE_mesh.h"
|
||||
#include "BKE_library.h"
|
||||
#include "BKE_global.h"
|
||||
#include "BKE_main.h"
|
||||
#include "BKE_scene.h"
|
||||
#include "BKE_group.h"
|
||||
|
||||
#include "BLI_blenlib.h"
|
||||
|
||||
#include "blendef.h"
|
||||
#include "Object.h"
|
||||
#include "gen_utils.h"
|
||||
#include "gen_library.h"
|
||||
|
||||
#include "vector.h"
|
||||
|
||||
/* checks for the group being removed */
|
||||
#define GROUP_DEL_CHECK_PY(bpy_group) if (!(bpy_group->group)) return ( EXPP_ReturnPyObjError( PyExc_RuntimeError, "Group has been removed" ) )
|
||||
#define GROUP_DEL_CHECK_INT(bpy_group) if (!(bpy_group->group)) return ( EXPP_ReturnIntError( PyExc_RuntimeError, "Group has been removed" ) )
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Python API function prototypes for the Blender module. */
|
||||
/*****************************************************************************/
|
||||
static PyObject *M_Group_New( PyObject * self, PyObject * args );
|
||||
static PyObject *M_Group_Get( PyObject * self, PyObject * args );
|
||||
static PyObject *M_Group_Unlink( PyObject * self, BPy_Group * pygrp );
|
||||
|
||||
/* internal */
|
||||
static PyObject *GroupObSeq_CreatePyObject( BPy_Group *self, GroupObject *iter );
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Python method structure definition for Blender.Object module: */
|
||||
/*****************************************************************************/
|
||||
struct PyMethodDef M_Group_methods[] = {
|
||||
{"New", ( PyCFunction ) M_Group_New, METH_VARARGS,
|
||||
"(name) Add a new empty group"},
|
||||
{"Get", ( PyCFunction ) M_Group_Get, METH_VARARGS,
|
||||
"(name) - return the group with the name 'name',\
|
||||
returns None if notfound.\nIf 'name' is not specified, it returns a list of all groups."},
|
||||
{"Unlink", ( PyCFunction ) M_Group_Unlink, METH_O,
|
||||
"(group) - Unlink (delete) this group from Blender."},
|
||||
{NULL, NULL, 0, NULL}
|
||||
};
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Python BPy_Group methods table: */
|
||||
/*****************************************************************************/
|
||||
static PyObject *BPy_Group_copy( BPy_Group * self );
|
||||
|
||||
static PyMethodDef BPy_Group_methods[] = {
|
||||
/* name, method, flags, doc */
|
||||
{"__copy__", ( PyCFunction ) BPy_Group_copy, METH_VARARGS,
|
||||
"() - Return a copy of the group containing the same objects."},
|
||||
{"copy", ( PyCFunction ) BPy_Group_copy, METH_VARARGS,
|
||||
"() - Return a copy of the group containing the same objects."},
|
||||
{NULL, NULL, 0, NULL}
|
||||
};
|
||||
|
||||
|
||||
static PyObject *BPy_Group_copy( BPy_Group * self )
|
||||
{
|
||||
BPy_Group *py_group; /* for Group Data object wrapper in Python */
|
||||
struct Group *bl_group;
|
||||
GroupObject *group_ob, *group_ob_new; /* Group object, copied and added to the groups */
|
||||
|
||||
GROUP_DEL_CHECK_PY(self);
|
||||
|
||||
bl_group= add_group( self->group->id.name + 2 );
|
||||
|
||||
if( bl_group ) /* now create the wrapper grp in Python */
|
||||
py_group = ( BPy_Group * ) Group_CreatePyObject( bl_group );
|
||||
else
|
||||
return ( EXPP_ReturnPyObjError( PyExc_RuntimeError,
|
||||
"couldn't create Group Data in Blender" ) );
|
||||
|
||||
bl_group->id.us = 1;
|
||||
|
||||
/* Now add the objects to the group */
|
||||
group_ob= self->group->gobject.first;
|
||||
while(group_ob) {
|
||||
/* save time by not using */
|
||||
group_ob_new= MEM_callocN(sizeof(GroupObject), "groupobject");
|
||||
group_ob_new->ob= group_ob->ob;
|
||||
BLI_addtail( &bl_group->gobject, group_ob_new);
|
||||
group_ob= group_ob->next;
|
||||
}
|
||||
|
||||
return ( PyObject * ) py_group;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/************************************************************************
|
||||
*
|
||||
* Python BPy_Object attributes
|
||||
*
|
||||
************************************************************************/
|
||||
static PyObject *Group_getObjects( BPy_Group * self )
|
||||
{
|
||||
return GroupObSeq_CreatePyObject(self, NULL);
|
||||
}
|
||||
|
||||
|
||||
static void add_to_group_wraper(Group *group, Object *ob) {
|
||||
Base *base;
|
||||
add_to_group(group, ob);
|
||||
|
||||
if (!(ob->flag & OB_FROMGROUP)) { /* do this to avoid a listbase lookup */
|
||||
ob->flag |= OB_FROMGROUP;
|
||||
|
||||
base= object_in_scene(ob, G.scene);
|
||||
if (base)
|
||||
base->flag |= OB_FROMGROUP;
|
||||
}
|
||||
}
|
||||
|
||||
/* only for internal use Blender.Group.Get("MyGroup").objects= []*/
|
||||
static int Group_setObjects( BPy_Group * self, PyObject * args )
|
||||
{
|
||||
int i, list_size;
|
||||
Group *group;
|
||||
Object *blen_ob;
|
||||
group= self->group;
|
||||
|
||||
GROUP_DEL_CHECK_INT(self);
|
||||
|
||||
if( PyList_Check( args ) ) {
|
||||
if( EXPP_check_sequence_consistency( args, &Object_Type ) != 1)
|
||||
return ( EXPP_ReturnIntError( PyExc_TypeError,
|
||||
"expected a list of objects" ) );
|
||||
|
||||
/* remove all from the list and add the new items */
|
||||
free_group(group); /* unlink all objects from this group, keep the group */
|
||||
list_size= PyList_Size( args );
|
||||
for( i = 0; i < list_size; i++ ) {
|
||||
blen_ob= ((BPy_Object *)PyList_GET_ITEM( args, i ))->object;
|
||||
add_to_group_wraper(group, blen_ob);
|
||||
}
|
||||
} else if (PyIter_Check(args)) {
|
||||
PyObject *iterator = PyObject_GetIter(args);
|
||||
PyObject *item;
|
||||
if (iterator == NULL) {
|
||||
Py_DECREF(iterator);
|
||||
return EXPP_ReturnIntError( PyExc_TypeError,
|
||||
"expected a list of objects, This iterator cannot be used." );
|
||||
}
|
||||
free_group(group); /* unlink all objects from this group, keep the group */
|
||||
item = PyIter_Next(iterator);
|
||||
while (item) {
|
||||
if ( PyObject_TypeCheck(item, &Object_Type) ) {
|
||||
blen_ob= ((BPy_Object *)item)->object;
|
||||
add_to_group_wraper(group, blen_ob);
|
||||
}
|
||||
Py_DECREF(item);
|
||||
item = PyIter_Next(iterator);
|
||||
}
|
||||
|
||||
Py_DECREF(iterator);
|
||||
|
||||
if (PyErr_Occurred()) {
|
||||
return EXPP_ReturnIntError( PyExc_RuntimeError,
|
||||
"An unknown error occured while adding iterator objects to the group.\nThe group has been modified." );
|
||||
}
|
||||
|
||||
} else
|
||||
return EXPP_ReturnIntError( PyExc_TypeError,
|
||||
"expected a list or sequence of objects" );
|
||||
return 0;
|
||||
}
|
||||
|
||||
static PyObject *Group_getDupliOfs( BPy_Group * self )
|
||||
{
|
||||
GROUP_DEL_CHECK_PY(self);
|
||||
return newVectorObject( self->group->dupli_ofs, 3, Py_WRAP );
|
||||
}
|
||||
|
||||
static int Group_setDupliOfs( BPy_Group * self, PyObject * value )
|
||||
{
|
||||
VectorObject *bpy_vec;
|
||||
GROUP_DEL_CHECK_INT(self);
|
||||
if (!VectorObject_Check(value))
|
||||
return ( EXPP_ReturnIntError( PyExc_TypeError,
|
||||
"expected a vector" ) );
|
||||
|
||||
bpy_vec = (VectorObject *)value;
|
||||
|
||||
if (bpy_vec->size != 3)
|
||||
return ( EXPP_ReturnIntError( PyExc_ValueError,
|
||||
"can only assign a 3D vector" ) );
|
||||
|
||||
self->group->dupli_ofs[0] = bpy_vec->vec[0];
|
||||
self->group->dupli_ofs[1] = bpy_vec->vec[1];
|
||||
self->group->dupli_ofs[2] = bpy_vec->vec[2];
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/*****************************************************************************/
|
||||
/* PythonTypeObject callback function prototypes */
|
||||
/*****************************************************************************/
|
||||
static PyObject *Group_repr( BPy_Group * obj );
|
||||
static int Group_compare( BPy_Group * a, BPy_Group * b );
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Python BPy_Group getsetattr funcs: */
|
||||
/*****************************************************************************/
|
||||
static int Group_setLayers( BPy_Group * self, PyObject * value )
|
||||
{
|
||||
unsigned int laymask = 0;
|
||||
|
||||
GROUP_DEL_CHECK_INT(self);
|
||||
|
||||
if( !PyInt_Check( value ) )
|
||||
return EXPP_ReturnIntError( PyExc_TypeError,
|
||||
"expected an integer (bitmask) as argument" );
|
||||
|
||||
laymask = ( unsigned int )PyInt_AS_LONG( value );
|
||||
|
||||
if( laymask <= 0 )
|
||||
return EXPP_ReturnIntError( PyExc_ValueError,
|
||||
"layer value cannot be zero or below" );
|
||||
|
||||
self->group->layer= laymask & ((1<<20) - 1);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static PyObject *Group_getLayers( BPy_Group * self )
|
||||
{
|
||||
return PyInt_FromLong( self->group->layer );
|
||||
}
|
||||
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Python attributes get/set structure: */
|
||||
/*****************************************************************************/
|
||||
static PyGetSetDef BPy_Group_getseters[] = {
|
||||
GENERIC_LIB_GETSETATTR,
|
||||
{"layers",
|
||||
(getter)Group_getLayers, (setter)Group_setLayers,
|
||||
"layer mask for this group",
|
||||
NULL},
|
||||
{"objects",
|
||||
(getter)Group_getObjects, (setter)Group_setObjects,
|
||||
"objects in this group",
|
||||
NULL},
|
||||
{"dupliOffset",
|
||||
(getter)Group_getDupliOfs, (setter)Group_setDupliOfs,
|
||||
"offset to use when instancing this group as a DupliGroup",
|
||||
NULL},
|
||||
{NULL,NULL,NULL,NULL,NULL} /* Sentinel */
|
||||
};
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Python TypeGroup structure definition: */
|
||||
/*****************************************************************************/
|
||||
PyTypeObject Group_Type = {
|
||||
PyObject_HEAD_INIT( NULL ) /* required py macro */
|
||||
0, /* ob_size */
|
||||
/* For printing, in format "<module>.<name>" */
|
||||
"Blender Group", /* char *tp_name; */
|
||||
sizeof( BPy_Group ), /* int tp_basicsize; */
|
||||
0, /* tp_itemsize; For allocation */
|
||||
|
||||
/* Methods to implement standard operations */
|
||||
|
||||
NULL, /* destructor tp_dealloc; */
|
||||
NULL, /* printfunc tp_print; */
|
||||
NULL, /* getattrfunc tp_getattr; */
|
||||
NULL, /* setattrfunc tp_setattr; */
|
||||
( cmpfunc ) Group_compare, /* cmpfunc tp_compare; */
|
||||
( reprfunc ) Group_repr, /* reprfunc tp_repr; */
|
||||
|
||||
/* Method suites for standard classes */
|
||||
|
||||
NULL, /* PyNumberMethods *tp_as_number; */
|
||||
NULL, /* PySequenceMethods *tp_as_sequence; */
|
||||
NULL, /* PyMappingMethods *tp_as_mapping; */
|
||||
|
||||
/* More standard operations (here for binary compatibility) */
|
||||
|
||||
( hashfunc ) GenericLib_hash, /* hashfunc tp_hash; */
|
||||
NULL, /* ternaryfunc tp_call; */
|
||||
NULL, /* reprfunc tp_str; */
|
||||
NULL, /* getattrofunc tp_getattro; */
|
||||
NULL, /* setattrofunc tp_setattro; */
|
||||
|
||||
/* Functions to access object as input/output buffer */
|
||||
NULL, /* PyBufferProcs *tp_as_buffer; */
|
||||
|
||||
/*** Flags to define presence of optional/expanded features ***/
|
||||
Py_TPFLAGS_DEFAULT, /* long tp_flags; */
|
||||
|
||||
NULL, /* char *tp_doc; Documentation string */
|
||||
/*** Assigned meaning in release 2.0 ***/
|
||||
/* call function for all accessible objects */
|
||||
NULL, /* traverseproc tp_traverse; */
|
||||
|
||||
/* delete references to contained objects */
|
||||
NULL, /* inquiry tp_clear; */
|
||||
|
||||
/*** Assigned meaning in release 2.1 ***/
|
||||
/*** rich comparisons ***/
|
||||
NULL, /* richcmpfunc tp_richcompare; */
|
||||
|
||||
/*** weak reference enabler ***/
|
||||
0, /* long tp_weaklistoffset; */
|
||||
|
||||
/*** Added in release 2.2 ***/
|
||||
/* Iterators */
|
||||
NULL, /* getiterfunc tp_iter; */
|
||||
NULL, /* iternextfunc tp_iternext; */
|
||||
|
||||
/*** Attribute descriptor and subclassing stuff ***/
|
||||
BPy_Group_methods, /* struct PyMethodDef *tp_methods; */
|
||||
NULL, /* struct PyMemberDef *tp_members; */
|
||||
BPy_Group_getseters, /* struct PyGetSetDef *tp_getset; */
|
||||
NULL, /* struct _typeobject *tp_base; */
|
||||
NULL, /* PyObject *tp_dict; */
|
||||
NULL, /* descrgetfunc tp_descr_get; */
|
||||
NULL, /* descrsetfunc tp_descr_set; */
|
||||
0, /* long tp_dictoffset; */
|
||||
NULL, /* initproc tp_init; */
|
||||
NULL, /* allocfunc tp_alloc; */
|
||||
NULL, /* newfunc tp_new; */
|
||||
/* Low-level free-memory routine */
|
||||
NULL, /* freefunc tp_free; */
|
||||
/* For PyObject_IS_GC */
|
||||
NULL, /* inquiry tp_is_gc; */
|
||||
NULL, /* PyObject *tp_bases; */
|
||||
/* method resolution order */
|
||||
NULL, /* PyObject *tp_mro; */
|
||||
NULL, /* PyObject *tp_cache; */
|
||||
NULL, /* PyObject *tp_subclasses; */
|
||||
NULL, /* PyObject *tp_weaklist; */
|
||||
NULL
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Function: M_Group_New */
|
||||
/* Python equivalent: Blender.Group.New */
|
||||
/*****************************************************************************/
|
||||
PyObject *M_Group_New( PyObject * self, PyObject * args )
|
||||
{
|
||||
char *name = "Group";
|
||||
BPy_Group *py_group; /* for Group Data object wrapper in Python */
|
||||
struct Group *bl_group;
|
||||
|
||||
if( !PyArg_ParseTuple( args, "|s", &name ) )
|
||||
return EXPP_ReturnPyObjError( PyExc_TypeError,
|
||||
"string expected as argument or nothing" );
|
||||
|
||||
bl_group= add_group( name );
|
||||
|
||||
if( bl_group ) /* now create the wrapper grp in Python */
|
||||
py_group = ( BPy_Group * ) Group_CreatePyObject( bl_group );
|
||||
else
|
||||
return ( EXPP_ReturnPyObjError( PyExc_RuntimeError,
|
||||
"couldn't create Group Data in Blender" ) );
|
||||
|
||||
bl_group->id.us = 1;
|
||||
|
||||
return ( PyObject * ) py_group;
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Function: M_Group_Get */
|
||||
/* Python equivalent: Blender.Group.Get */
|
||||
/*****************************************************************************/
|
||||
static PyObject *M_Group_Get( PyObject * self, PyObject * args )
|
||||
{
|
||||
char *name = NULL;
|
||||
Group *group_iter;
|
||||
|
||||
if( !PyArg_ParseTuple( args, "|s", &name ) )
|
||||
return ( EXPP_ReturnPyObjError( PyExc_TypeError,
|
||||
"expected string argument (or nothing)" ) );
|
||||
|
||||
group_iter = G.main->group.first;
|
||||
|
||||
if( name ) { /* (name) - Search group by name */
|
||||
|
||||
BPy_Group *wanted_group = NULL;
|
||||
|
||||
while( ( group_iter ) && ( wanted_group == NULL ) ) {
|
||||
|
||||
if( strcmp( name, group_iter->id.name + 2 ) == 0 )
|
||||
wanted_group =
|
||||
( BPy_Group * )
|
||||
Group_CreatePyObject( group_iter );
|
||||
|
||||
group_iter = group_iter->id.next;
|
||||
}
|
||||
|
||||
if( wanted_group == NULL ) { /* Requested group doesn't exist */
|
||||
char error_msg[64];
|
||||
PyOS_snprintf( error_msg, sizeof( error_msg ),
|
||||
"Group \"%s\" not found", name );
|
||||
return ( EXPP_ReturnPyObjError
|
||||
( PyExc_NameError, error_msg ) );
|
||||
}
|
||||
|
||||
return ( PyObject * ) wanted_group;
|
||||
}
|
||||
|
||||
else { /* () - return a list of all groups in the scene */
|
||||
int index = 0;
|
||||
PyObject *grouplist, *pyobj;
|
||||
|
||||
grouplist = PyList_New( BLI_countlist( &( G.main->group ) ) );
|
||||
|
||||
if( grouplist == NULL )
|
||||
return ( EXPP_ReturnPyObjError( PyExc_MemoryError,
|
||||
"couldn't create group list" ) );
|
||||
|
||||
while( group_iter ) {
|
||||
pyobj = Group_CreatePyObject( group_iter );
|
||||
|
||||
if( !pyobj ) {
|
||||
Py_DECREF(grouplist);
|
||||
return ( EXPP_ReturnPyObjError
|
||||
( PyExc_MemoryError,
|
||||
"couldn't create Object" ) );
|
||||
}
|
||||
PyList_SET_ITEM( grouplist, index, pyobj );
|
||||
|
||||
group_iter = group_iter->id.next;
|
||||
index++;
|
||||
}
|
||||
|
||||
return grouplist;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Function: M_Group_Unlink */
|
||||
/* Python equivalent: Blender.Group.Unlink */
|
||||
/*****************************************************************************/
|
||||
static PyObject *M_Group_Unlink( PyObject * self, BPy_Group * pygrp )
|
||||
{
|
||||
Group *group;
|
||||
if( !BPy_Group_Check(pygrp) )
|
||||
return ( EXPP_ReturnPyObjError( PyExc_TypeError,
|
||||
"expected a group" ) );
|
||||
|
||||
GROUP_DEL_CHECK_PY(pygrp);
|
||||
|
||||
group= pygrp->group;
|
||||
|
||||
pygrp->group= NULL;
|
||||
free_group(group);
|
||||
unlink_group(group);
|
||||
group->id.us= 0;
|
||||
free_libblock( &G.main->group, group );
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Function: initObject */
|
||||
/*****************************************************************************/
|
||||
PyObject *Group_Init( void )
|
||||
{
|
||||
PyObject *submodule;
|
||||
if( PyType_Ready( &Group_Type ) < 0 )
|
||||
return NULL;
|
||||
if( PyType_Ready( &GroupObSeq_Type ) < 0 )
|
||||
return NULL;
|
||||
|
||||
submodule = Py_InitModule3( "Blender.Group", M_Group_methods,
|
||||
"The Blender Group module\n\n\
|
||||
This module provides access to **Group Data** in Blender.\n" );
|
||||
|
||||
/*Add SUBMODULES to the module*/
|
||||
/*PyDict_SetItemString(dict, "Constraint", Constraint_Init()); //creates a *new* module*/
|
||||
return submodule;
|
||||
}
|
||||
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Function: Group_CreatePyObject */
|
||||
/* Description: This function will create a new BlenObject from an existing */
|
||||
/* Object structure. */
|
||||
/*****************************************************************************/
|
||||
PyObject *Group_CreatePyObject( struct Group * grp )
|
||||
{
|
||||
BPy_Group *pygrp;
|
||||
|
||||
if( !grp )
|
||||
Py_RETURN_NONE;
|
||||
|
||||
pygrp =
|
||||
( BPy_Group * ) PyObject_NEW( BPy_Group, &Group_Type );
|
||||
|
||||
if( pygrp == NULL ) {
|
||||
return ( NULL );
|
||||
}
|
||||
pygrp->group = grp;
|
||||
return ( ( PyObject * ) pygrp );
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Function: Group_FromPyObject */
|
||||
/* Description: This function returns the Blender group from the given */
|
||||
/* PyObject. */
|
||||
/*****************************************************************************/
|
||||
Group *Group_FromPyObject( PyObject * py_grp )
|
||||
{
|
||||
BPy_Group *blen_grp;
|
||||
|
||||
blen_grp = ( BPy_Group * ) py_grp;
|
||||
return ( blen_grp->group );
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Function: Group_compare */
|
||||
/* Description: This is a callback function for the BPy_Group type. It */
|
||||
/* compares two Group_Type objects. Only the "==" and "!=" */
|
||||
/* comparisons are meaninful. Returns 0 for equality and -1 if */
|
||||
/* they don't point to the same Blender Object struct. */
|
||||
/* In Python it becomes 1 if they are equal, 0 otherwise. */
|
||||
/*****************************************************************************/
|
||||
static int Group_compare( BPy_Group * a, BPy_Group * b )
|
||||
{
|
||||
Group *pa = a->group, *pb = b->group;
|
||||
return ( pa == pb ) ? 0 : -1;
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Function: Group_repr */
|
||||
/* Description: This is a callback function for the BPy_Group type. It */
|
||||
/* builds a meaninful string to represent object objects. */
|
||||
/*****************************************************************************/
|
||||
static PyObject *Group_repr( BPy_Group * self )
|
||||
{
|
||||
if (!self->group)
|
||||
return PyString_FromString( "[Group - Removed]" );
|
||||
|
||||
return PyString_FromFormat( "[Group \"%s\"]",
|
||||
self->group->id.name + 2 );
|
||||
}
|
||||
|
||||
|
||||
/************************************************************************
|
||||
*
|
||||
* GroupOb sequence
|
||||
*
|
||||
************************************************************************/
|
||||
/*
|
||||
* create a thin GroupOb object
|
||||
*/
|
||||
|
||||
static PyObject *GroupObSeq_CreatePyObject( BPy_Group *self, GroupObject *iter )
|
||||
{
|
||||
BPy_GroupObSeq *seq = PyObject_NEW( BPy_GroupObSeq, &GroupObSeq_Type);
|
||||
seq->bpygroup = self; Py_INCREF(self);
|
||||
seq->iter= iter;
|
||||
return (PyObject *)seq;
|
||||
}
|
||||
|
||||
|
||||
static int GroupObSeq_len( BPy_GroupObSeq * self )
|
||||
{
|
||||
GROUP_DEL_CHECK_INT(self->bpygroup);
|
||||
return BLI_countlist( &( self->bpygroup->group->gobject ) );
|
||||
}
|
||||
|
||||
/*
|
||||
* retrive a single GroupOb from somewhere in the GroupObex list
|
||||
*/
|
||||
|
||||
static PyObject *GroupObSeq_item( BPy_GroupObSeq * self, int i )
|
||||
{
|
||||
Group *group= self->bpygroup->group;
|
||||
int index=0;
|
||||
PyObject *bpy_obj;
|
||||
GroupObject *gob;
|
||||
|
||||
GROUP_DEL_CHECK_PY(self->bpygroup);
|
||||
|
||||
for (gob= group->gobject.first; gob && i!=index; gob= gob->next, index++) {}
|
||||
|
||||
if (!(gob))
|
||||
return EXPP_ReturnPyObjError( PyExc_IndexError,
|
||||
"array index out of range" );
|
||||
|
||||
bpy_obj = Object_CreatePyObject( gob->ob );
|
||||
|
||||
if( !bpy_obj )
|
||||
return EXPP_ReturnPyObjError( PyExc_RuntimeError,
|
||||
"PyObject_New() failed" );
|
||||
|
||||
return (PyObject *)bpy_obj;
|
||||
|
||||
}
|
||||
|
||||
static PySequenceMethods GroupObSeq_as_sequence = {
|
||||
( inquiry ) GroupObSeq_len, /* sq_length */
|
||||
( binaryfunc ) 0, /* sq_concat */
|
||||
( intargfunc ) 0, /* sq_repeat */
|
||||
( intargfunc ) GroupObSeq_item, /* sq_item */
|
||||
( intintargfunc ) 0, /* sq_slice */
|
||||
( intobjargproc ) 0, /* sq_ass_item */
|
||||
( intintobjargproc ) 0, /* sq_ass_slice */
|
||||
0,0,0,
|
||||
};
|
||||
|
||||
/************************************************************************
|
||||
*
|
||||
* Python GroupObSeq_Type iterator (iterates over GroupObjects)
|
||||
*
|
||||
************************************************************************/
|
||||
|
||||
/*
|
||||
* Initialize the interator index
|
||||
*/
|
||||
|
||||
static PyObject *GroupObSeq_getIter( BPy_GroupObSeq * self )
|
||||
{
|
||||
GROUP_DEL_CHECK_PY(self->bpygroup);
|
||||
|
||||
if (!self->iter) {
|
||||
self->iter = self->bpygroup->group->gobject.first;
|
||||
return EXPP_incr_ret ( (PyObject *) self );
|
||||
} else {
|
||||
return GroupObSeq_CreatePyObject(self->bpygroup, self->bpygroup->group->gobject.first);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Return next GroupOb.
|
||||
*/
|
||||
|
||||
static PyObject *GroupObSeq_nextIter( BPy_GroupObSeq * self )
|
||||
{
|
||||
PyObject *object;
|
||||
if( !(self->iter) || !(self->bpygroup->group) ) {
|
||||
self->iter = NULL; /* so we can add objects again */
|
||||
return EXPP_ReturnPyObjError( PyExc_StopIteration,
|
||||
"iterator at end" );
|
||||
}
|
||||
|
||||
object= Object_CreatePyObject( self->iter->ob );
|
||||
self->iter= self->iter->next;
|
||||
return object;
|
||||
}
|
||||
|
||||
|
||||
static PyObject *GroupObSeq_link( BPy_GroupObSeq * self, BPy_Object *value )
|
||||
{
|
||||
Object *blen_ob;
|
||||
|
||||
GROUP_DEL_CHECK_PY(self->bpygroup);
|
||||
|
||||
if( !BPy_Object_Check(value) )
|
||||
return ( EXPP_ReturnPyObjError( PyExc_TypeError,
|
||||
"expected a python object as an argument" ) );
|
||||
|
||||
/*
|
||||
if (self->iter != NULL)
|
||||
return EXPP_ReturnPyObjError( PyExc_RuntimeError,
|
||||
"Cannot modify group objects while iterating" );
|
||||
*/
|
||||
|
||||
blen_ob = value->object;
|
||||
|
||||
add_to_group_wraper(self->bpygroup->group, blen_ob); /* this checks so as not to add the object into the group twice*/
|
||||
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
static PyObject *GroupObSeq_unlink( BPy_GroupObSeq * self, BPy_Object *value )
|
||||
{
|
||||
Object *blen_ob;
|
||||
Base *base= NULL;
|
||||
|
||||
GROUP_DEL_CHECK_PY(self->bpygroup);
|
||||
|
||||
if( !BPy_Object_Check(value) )
|
||||
return ( EXPP_ReturnPyObjError( PyExc_TypeError,
|
||||
"expected a python object as an argument" ) );
|
||||
|
||||
blen_ob = value->object;
|
||||
|
||||
|
||||
|
||||
rem_from_group(self->bpygroup->group, blen_ob);
|
||||
|
||||
if(find_group(blen_ob, NULL)==NULL) {
|
||||
blen_ob->flag &= ~OB_FROMGROUP;
|
||||
|
||||
base= object_in_scene(blen_ob, G.scene);
|
||||
if (base)
|
||||
base->flag &= ~OB_FROMGROUP;
|
||||
}
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
static struct PyMethodDef BPy_GroupObSeq_methods[] = {
|
||||
{"link", (PyCFunction)GroupObSeq_link, METH_O,
|
||||
"make the object a part of this group"},
|
||||
{"unlink", (PyCFunction)GroupObSeq_unlink, METH_O,
|
||||
"unlink an object from this group"},
|
||||
{NULL, NULL, 0, NULL}
|
||||
};
|
||||
|
||||
/************************************************************************
|
||||
*
|
||||
* Python GroupObSeq_Type standard operations
|
||||
*
|
||||
************************************************************************/
|
||||
|
||||
static void GroupObSeq_dealloc( BPy_GroupObSeq * self )
|
||||
{
|
||||
Py_DECREF(self->bpygroup);
|
||||
PyObject_DEL( self );
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Python GroupObSeq_Type structure definition: */
|
||||
/*****************************************************************************/
|
||||
PyTypeObject GroupObSeq_Type = {
|
||||
PyObject_HEAD_INIT( NULL ) /* required py macro */
|
||||
0, /* ob_size */
|
||||
/* For printing, in format "<module>.<name>" */
|
||||
"Blender GroupObSeq", /* char *tp_name; */
|
||||
sizeof( BPy_GroupObSeq ), /* int tp_basicsize; */
|
||||
0, /* tp_itemsize; For allocation */
|
||||
|
||||
/* Methods to implement standard operations */
|
||||
|
||||
( destructor ) GroupObSeq_dealloc,/* destructor tp_dealloc; */
|
||||
NULL, /* printfunc tp_print; */
|
||||
NULL, /* getattrfunc tp_getattr; */
|
||||
NULL, /* setattrfunc tp_setattr; */
|
||||
NULL, /* cmpfunc tp_compare; */
|
||||
NULL, /* reprfunc tp_repr; */
|
||||
|
||||
/* Method suites for standard classes */
|
||||
|
||||
NULL, /* PyNumberMethods *tp_as_number; */
|
||||
&GroupObSeq_as_sequence, /* PySequenceMethods *tp_as_sequence; */
|
||||
NULL, /* PyMappingMethods *tp_as_mapping; */
|
||||
|
||||
/* More standard operations (here for binary compatibility) */
|
||||
|
||||
NULL, /* hashfunc tp_hash; */
|
||||
NULL, /* ternaryfunc tp_call; */
|
||||
NULL, /* reprfunc tp_str; */
|
||||
NULL, /* getattrofunc tp_getattro; */
|
||||
NULL, /* setattrofunc tp_setattro; */
|
||||
|
||||
/* Functions to access object as input/output buffer */
|
||||
NULL, /* PyBufferProcs *tp_as_buffer; */
|
||||
|
||||
/*** Flags to define presence of optional/expanded features ***/
|
||||
Py_TPFLAGS_DEFAULT, /* long tp_flags; */
|
||||
|
||||
NULL, /* char *tp_doc; Documentation string */
|
||||
/*** Assigned meaning in release 2.0 ***/
|
||||
/* call function for all accessible objects */
|
||||
NULL, /* traverseproc tp_traverse; */
|
||||
|
||||
/* delete references to contained objects */
|
||||
NULL, /* inquiry tp_clear; */
|
||||
|
||||
/*** Assigned meaning in release 2.1 ***/
|
||||
/*** rich comparisons ***/
|
||||
NULL, /* richcmpfunc tp_richcompare; */
|
||||
|
||||
/*** weak reference enabler ***/
|
||||
0, /* long tp_weaklistoffset; */
|
||||
|
||||
/*** Added in release 2.2 ***/
|
||||
/* Iterators */
|
||||
( getiterfunc) GroupObSeq_getIter, /* getiterfunc tp_iter; */
|
||||
( iternextfunc ) GroupObSeq_nextIter, /* iternextfunc tp_iternext; */
|
||||
|
||||
/*** Attribute descriptor and subclassing stuff ***/
|
||||
BPy_GroupObSeq_methods, /* struct PyMethodDef *tp_methods; */
|
||||
NULL, /* struct PyMemberDef *tp_members; */
|
||||
NULL, /* struct PyGetSetDef *tp_getset; */
|
||||
NULL, /* struct _typeobject *tp_base; */
|
||||
NULL, /* PyObject *tp_dict; */
|
||||
NULL, /* descrgetfunc tp_descr_get; */
|
||||
NULL, /* descrsetfunc tp_descr_set; */
|
||||
0, /* long tp_dictoffset; */
|
||||
NULL, /* initproc tp_init; */
|
||||
NULL, /* allocfunc tp_alloc; */
|
||||
NULL, /* newfunc tp_new; */
|
||||
/* Low-level free-memory routine */
|
||||
NULL, /* freefunc tp_free; */
|
||||
/* For PyObject_IS_GC */
|
||||
NULL, /* inquiry tp_is_gc; */
|
||||
NULL, /* PyObject *tp_bases; */
|
||||
/* method resolution order */
|
||||
NULL, /* PyObject *tp_mro; */
|
||||
NULL, /* PyObject *tp_cache; */
|
||||
NULL, /* PyObject *tp_subclasses; */
|
||||
NULL, /* PyObject *tp_weaklist; */
|
||||
NULL
|
||||
};
|
||||
@@ -1,63 +0,0 @@
|
||||
/*
|
||||
* $Id$
|
||||
*
|
||||
* ***** 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*
|
||||
* The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This is a new part of Blender.
|
||||
*
|
||||
* Contributor(s): Michel Selten
|
||||
*
|
||||
* ***** END GPL LICENSE BLOCK *****
|
||||
*/
|
||||
|
||||
#ifndef EXPP_GROUP_H
|
||||
#define EXPP_GROUP_H
|
||||
|
||||
#include <Python.h>
|
||||
#include "DNA_group_types.h"
|
||||
|
||||
/* The Group PyTypeObject defined in Group.c */
|
||||
extern PyTypeObject Group_Type;
|
||||
extern PyTypeObject GroupObSeq_Type;
|
||||
|
||||
#define BPy_Group_Check(v) ((v)->ob_type == &Group_Type)
|
||||
#define BPy_GroupObSeq_Check(v) ((v)->ob_type == &GroupObSeq_Type)
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Python BPy_Group structure definition. */
|
||||
/*****************************************************************************/
|
||||
typedef struct {
|
||||
PyObject_HEAD
|
||||
struct Group *group;
|
||||
} BPy_Group;
|
||||
|
||||
|
||||
/* Group object sequence, iterate on the groups object listbase*/
|
||||
typedef struct {
|
||||
PyObject_VAR_HEAD /* required python macro */
|
||||
BPy_Group *bpygroup; /* link to the python group so we can know if its been removed */
|
||||
GroupObject *iter; /* so we can iterate over the objects */
|
||||
} BPy_GroupObSeq;
|
||||
|
||||
PyObject *Group_Init( void );
|
||||
PyObject *Group_CreatePyObject( struct Group *group );
|
||||
Group *Group_FromPyObject( PyObject * py_obj );
|
||||
|
||||
#endif /* EXPP_GROUP_H */
|
||||
@@ -1,965 +0,0 @@
|
||||
/**
|
||||
* $Id: IDProp.c
|
||||
*
|
||||
* ***** 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*
|
||||
* The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Contributor(s): Joseph Eagar
|
||||
*
|
||||
* ***** END GPL LICENSE BLOCK *****
|
||||
*/
|
||||
|
||||
#include "DNA_ID.h"
|
||||
|
||||
#include "BKE_idprop.h"
|
||||
|
||||
#include "IDProp.h"
|
||||
#include "gen_utils.h"
|
||||
|
||||
#include "MEM_guardedalloc.h"
|
||||
|
||||
#define BSTR_EQ(a, b) (*(a) == *(b) && !strcmp(a, b))
|
||||
|
||||
/*** Function to wrap ID properties ***/
|
||||
PyObject *BPy_Wrap_IDProperty(ID *id, IDProperty *prop, IDProperty *parent);
|
||||
|
||||
extern PyTypeObject IDArray_Type;
|
||||
extern PyTypeObject IDGroup_Iter_Type;
|
||||
|
||||
/*********************** ID Property Main Wrapper Stuff ***************/
|
||||
|
||||
PyObject *IDGroup_repr( BPy_IDProperty *self )
|
||||
{
|
||||
return PyString_FromString( "(ID Property)" );
|
||||
}
|
||||
|
||||
extern PyTypeObject IDGroup_Type;
|
||||
|
||||
PyObject *BPy_IDGroup_WrapData( ID *id, IDProperty *prop )
|
||||
{
|
||||
switch ( prop->type ) {
|
||||
case IDP_STRING:
|
||||
return PyString_FromString( prop->data.pointer );
|
||||
case IDP_INT:
|
||||
return PyInt_FromLong( (long)prop->data.val );
|
||||
case IDP_FLOAT:
|
||||
return PyFloat_FromDouble( (double)(*(float*)(&prop->data.val)) );
|
||||
case IDP_DOUBLE:
|
||||
return PyFloat_FromDouble( (*(double*)(&prop->data.val)) );
|
||||
case IDP_GROUP:
|
||||
/*blegh*/
|
||||
{
|
||||
BPy_IDProperty *group = PyObject_New(BPy_IDProperty, &IDGroup_Type);
|
||||
if (!group)
|
||||
return EXPP_ReturnPyObjError( PyExc_RuntimeError,
|
||||
"PyObject_New() failed" );
|
||||
|
||||
group->id = id;
|
||||
group->prop = prop;
|
||||
return (PyObject*) group;
|
||||
}
|
||||
case IDP_ARRAY:
|
||||
{
|
||||
BPy_IDProperty *array = PyObject_New(BPy_IDProperty, &IDArray_Type);
|
||||
if (!array)
|
||||
return EXPP_ReturnPyObjError( PyExc_RuntimeError,
|
||||
"PyObject_New() failed" );
|
||||
|
||||
array->id = id;
|
||||
array->prop = prop;
|
||||
return (PyObject*) array;
|
||||
}
|
||||
}
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
int BPy_IDGroup_SetData(BPy_IDProperty *self, IDProperty *prop, PyObject *value)
|
||||
{
|
||||
switch (prop->type) {
|
||||
case IDP_STRING:
|
||||
{
|
||||
char *st;
|
||||
if (!PyString_Check(value))
|
||||
return EXPP_ReturnIntError(PyExc_TypeError, "expected a string!");
|
||||
|
||||
st = PyString_AsString(value);
|
||||
IDP_ResizeArray(prop, strlen(st)+1);
|
||||
strcpy(prop->data.pointer, st);
|
||||
return 0;
|
||||
}
|
||||
|
||||
case IDP_INT:
|
||||
{
|
||||
int ivalue;
|
||||
if (!PyNumber_Check(value))
|
||||
return EXPP_ReturnIntError(PyExc_TypeError, "expected an int!");
|
||||
value = PyNumber_Int(value);
|
||||
if (!value)
|
||||
return EXPP_ReturnIntError(PyExc_TypeError, "expected an int!");
|
||||
ivalue = (int) PyInt_AsLong(value);
|
||||
prop->data.val = ivalue;
|
||||
Py_XDECREF(value);
|
||||
break;
|
||||
}
|
||||
case IDP_FLOAT:
|
||||
{
|
||||
float fvalue;
|
||||
if (!PyNumber_Check(value))
|
||||
return EXPP_ReturnIntError(PyExc_TypeError, "expected a float!");
|
||||
value = PyNumber_Float(value);
|
||||
if (!value)
|
||||
return EXPP_ReturnIntError(PyExc_TypeError, "expected a float!");
|
||||
fvalue = (float) PyFloat_AsDouble(value);
|
||||
*(float*)&self->prop->data.val = fvalue;
|
||||
Py_XDECREF(value);
|
||||
break;
|
||||
}
|
||||
case IDP_DOUBLE:
|
||||
{
|
||||
double dvalue;
|
||||
if (!PyNumber_Check(value))
|
||||
return EXPP_ReturnIntError(PyExc_TypeError, "expected a float!");
|
||||
value = PyNumber_Float(value);
|
||||
if (!value)
|
||||
return EXPP_ReturnIntError(PyExc_TypeError, "expected a float!");
|
||||
dvalue = (float) PyFloat_AsDouble(value);
|
||||
*(double*)&self->prop->data.val = dvalue;
|
||||
Py_XDECREF(value);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
return EXPP_ReturnIntError(PyExc_AttributeError, "attempt to set read-only attribute!");
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
PyObject *BPy_IDGroup_GetName(BPy_IDProperty *self, void *bleh)
|
||||
{
|
||||
return PyString_FromString(self->prop->name);
|
||||
}
|
||||
|
||||
static int BPy_IDGroup_SetName(BPy_IDProperty *self, PyObject *value, void *bleh)
|
||||
{
|
||||
char *st;
|
||||
if (!PyString_Check(value))
|
||||
return EXPP_ReturnIntError(PyExc_TypeError, "expected a string!");
|
||||
|
||||
st = PyString_AsString(value);
|
||||
if (strlen(st) >= MAX_IDPROP_NAME)
|
||||
return EXPP_ReturnIntError(PyExc_TypeError, "string length cannot exceed 31 characters!");
|
||||
|
||||
strcpy(self->prop->name, st);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static PyObject *BPy_IDGroup_GetType(BPy_IDProperty *self)
|
||||
{
|
||||
return PyInt_FromLong((long)self->prop->type);
|
||||
}
|
||||
|
||||
static PyGetSetDef BPy_IDGroup_getseters[] = {
|
||||
{"name",
|
||||
(getter)BPy_IDGroup_GetName, (setter)BPy_IDGroup_SetName,
|
||||
"The name of this Group.",
|
||||
NULL},
|
||||
{NULL, NULL, NULL, NULL, NULL}
|
||||
};
|
||||
|
||||
static int BPy_IDGroup_Map_Len(BPy_IDProperty *self)
|
||||
{
|
||||
if (self->prop->type != IDP_GROUP)
|
||||
return EXPP_ReturnIntError( PyExc_TypeError,
|
||||
"len() of unsized object");
|
||||
|
||||
return self->prop->len;
|
||||
}
|
||||
|
||||
static PyObject *BPy_IDGroup_Map_GetItem(BPy_IDProperty *self, PyObject *item)
|
||||
{
|
||||
IDProperty *loop;
|
||||
char *st;
|
||||
|
||||
if (self->prop->type != IDP_GROUP)
|
||||
return EXPP_ReturnPyObjError( PyExc_TypeError,
|
||||
"unsubscriptable object");
|
||||
|
||||
if (!PyString_Check(item))
|
||||
return EXPP_ReturnPyObjError( PyExc_TypeError,
|
||||
"only strings are allowed as keys of ID properties");
|
||||
|
||||
st = PyString_AsString(item);
|
||||
for (loop=self->prop->data.group.first; loop; loop=loop->next) {
|
||||
if (BSTR_EQ(loop->name, st)) return BPy_IDGroup_WrapData(self->id, loop);
|
||||
}
|
||||
return EXPP_ReturnPyObjError( PyExc_KeyError,
|
||||
"key not in subgroup dict");
|
||||
}
|
||||
|
||||
/*returns NULL on success, error string on failure*/
|
||||
static char *BPy_IDProperty_Map_ValidateAndCreate(char *name, IDProperty *group, PyObject *ob)
|
||||
{
|
||||
IDProperty *prop = NULL;
|
||||
IDPropertyTemplate val = {0};
|
||||
|
||||
if (PyFloat_Check(ob)) {
|
||||
val.d = PyFloat_AsDouble(ob);
|
||||
prop = IDP_New(IDP_DOUBLE, val, name);
|
||||
} else if (PyInt_Check(ob)) {
|
||||
val.i = (int) PyInt_AsLong(ob);
|
||||
prop = IDP_New(IDP_INT, val, name);
|
||||
} else if (PyString_Check(ob)) {
|
||||
val.str = PyString_AsString(ob);
|
||||
prop = IDP_New(IDP_STRING, val, name);
|
||||
} else if (PySequence_Check(ob)) {
|
||||
PyObject *item;
|
||||
int i;
|
||||
|
||||
/*validate sequence and derive type.
|
||||
we assume IDP_INT unless we hit a float
|
||||
number; then we assume it's */
|
||||
val.array.type = IDP_INT;
|
||||
val.array.len = PySequence_Length(ob);
|
||||
for (i=0; i<val.array.len; i++) {
|
||||
item = PySequence_GetItem(ob, i);
|
||||
if (PyFloat_Check(item)) val.array.type = IDP_DOUBLE;
|
||||
else if (!PyInt_Check(item)) return "only floats and ints are allowed in ID property arrays";
|
||||
Py_XDECREF(item);
|
||||
}
|
||||
|
||||
prop = IDP_New(IDP_ARRAY, val, name);
|
||||
for (i=0; i<val.array.len; i++) {
|
||||
item = PySequence_GetItem(ob, i);
|
||||
if (val.array.type == IDP_INT) {
|
||||
item = PyNumber_Int(item);
|
||||
((int*)prop->data.pointer)[i] = (int)PyInt_AsLong(item);
|
||||
} else {
|
||||
item = PyNumber_Float(item);
|
||||
((double*)prop->data.pointer)[i] = (float)PyFloat_AsDouble(item);
|
||||
}
|
||||
Py_XDECREF(item);
|
||||
}
|
||||
} else if (PyMapping_Check(ob)) {
|
||||
PyObject *keys, *vals, *key, *pval;
|
||||
int i, len;
|
||||
/*yay! we get into recursive stuff now!*/
|
||||
keys = PyMapping_Keys(ob);
|
||||
vals = PyMapping_Values(ob);
|
||||
|
||||
/*we allocate the group first; if we hit any invalid data,
|
||||
we can delete it easily enough.*/
|
||||
prop = IDP_New(IDP_GROUP, val, name);
|
||||
len = PyMapping_Length(ob);
|
||||
for (i=0; i<len; i++) {
|
||||
key = PySequence_GetItem(keys, i);
|
||||
pval = PySequence_GetItem(vals, i);
|
||||
if (!PyString_Check(key)) {
|
||||
IDP_FreeProperty(prop);
|
||||
MEM_freeN(prop);
|
||||
Py_XDECREF(keys);
|
||||
Py_XDECREF(vals);
|
||||
Py_XDECREF(key);
|
||||
Py_XDECREF(pval);
|
||||
return "invalid element in subgroup dict template!";
|
||||
}
|
||||
if (BPy_IDProperty_Map_ValidateAndCreate(PyString_AsString(key), prop, pval)) {
|
||||
IDP_FreeProperty(prop);
|
||||
MEM_freeN(prop);
|
||||
Py_XDECREF(keys);
|
||||
Py_XDECREF(vals);
|
||||
Py_XDECREF(key);
|
||||
Py_XDECREF(pval);
|
||||
return "invalid element in subgroup dict template!";
|
||||
}
|
||||
Py_XDECREF(key);
|
||||
Py_XDECREF(pval);
|
||||
}
|
||||
Py_XDECREF(keys);
|
||||
Py_XDECREF(vals);
|
||||
} else return "invalid property value";
|
||||
|
||||
IDP_ReplaceInGroup(group, prop);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static int BPy_IDGroup_Map_SetItem(BPy_IDProperty *self, PyObject *key, PyObject *val)
|
||||
{
|
||||
char *err;
|
||||
|
||||
if (self->prop->type != IDP_GROUP)
|
||||
return EXPP_ReturnIntError( PyExc_TypeError,
|
||||
"unsubscriptable object");
|
||||
|
||||
if (!PyString_Check(key))
|
||||
return EXPP_ReturnIntError( PyExc_TypeError,
|
||||
"only strings are allowed as subgroup keys" );
|
||||
|
||||
if (val == NULL) {
|
||||
IDProperty *pkey = IDP_GetPropertyFromGroup(self->prop, PyString_AsString(key));
|
||||
if (pkey) {
|
||||
IDP_RemFromGroup(self->prop, pkey);
|
||||
IDP_FreeProperty(pkey);
|
||||
MEM_freeN(pkey);
|
||||
return 0;
|
||||
} else return EXPP_ReturnIntError( PyExc_RuntimeError, "property not found in group" );
|
||||
}
|
||||
|
||||
err = BPy_IDProperty_Map_ValidateAndCreate(PyString_AsString(key), self->prop, val);
|
||||
if (err) return EXPP_ReturnIntError( PyExc_RuntimeError, err );
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static PyObject *BPy_IDGroup_SpawnIterator(BPy_IDProperty *self)
|
||||
{
|
||||
BPy_IDGroup_Iter *iter = PyObject_New(BPy_IDGroup_Iter, &IDGroup_Iter_Type);
|
||||
|
||||
if (!iter)
|
||||
return EXPP_ReturnPyObjError( PyExc_RuntimeError,
|
||||
"PyObject_New() failed" );
|
||||
iter->group = self;
|
||||
iter->mode = IDPROP_ITER_KEYS;
|
||||
iter->cur = self->prop->data.group.first;
|
||||
Py_XINCREF(iter);
|
||||
return (PyObject*) iter;
|
||||
}
|
||||
|
||||
static PyObject *BPy_IDGroup_MapDataToPy(IDProperty *prop)
|
||||
{
|
||||
switch (prop->type) {
|
||||
case IDP_STRING:
|
||||
return PyString_FromString(prop->data.pointer);
|
||||
break;
|
||||
case IDP_FLOAT:
|
||||
return PyFloat_FromDouble(*((float*)&prop->data.val));
|
||||
break;
|
||||
case IDP_DOUBLE:
|
||||
return PyFloat_FromDouble(*((double*)&prop->data.val));
|
||||
break;
|
||||
case IDP_INT:
|
||||
return PyInt_FromLong( (long)prop->data.val );
|
||||
break;
|
||||
case IDP_ARRAY:
|
||||
{
|
||||
PyObject *seq = PyList_New(prop->len);
|
||||
int i;
|
||||
|
||||
if (!seq)
|
||||
return EXPP_ReturnPyObjError( PyExc_RuntimeError,
|
||||
"PyList_New() failed" );
|
||||
|
||||
for (i=0; i<prop->len; i++) {
|
||||
if (prop->subtype == IDP_FLOAT) {
|
||||
PyList_SetItem(seq, i,
|
||||
PyFloat_FromDouble(((float*)prop->data.pointer)[i]));
|
||||
} else if (prop->subtype == IDP_DOUBLE) {
|
||||
PyList_SetItem(seq, i,
|
||||
PyFloat_FromDouble(((double*)prop->data.pointer)[i]));
|
||||
} else { PyList_SetItem(seq, i,
|
||||
PyInt_FromLong(((int*)prop->data.pointer)[i]));
|
||||
}
|
||||
}
|
||||
return seq;
|
||||
}
|
||||
case IDP_GROUP:
|
||||
{
|
||||
PyObject *dict = PyDict_New(), *wrap;
|
||||
IDProperty *loop;
|
||||
|
||||
if (!dict)
|
||||
return EXPP_ReturnPyObjError( PyExc_RuntimeError,
|
||||
"PyDict_New() failed" );
|
||||
|
||||
for (loop=prop->data.group.first; loop; loop=loop->next) {
|
||||
wrap = BPy_IDGroup_MapDataToPy(loop);
|
||||
if (!wrap)
|
||||
return EXPP_ReturnPyObjError( PyExc_RuntimeError,
|
||||
"BPy_IDGroup_MapDataToPy() failed" );
|
||||
|
||||
PyDict_SetItemString(dict, loop->name, wrap);
|
||||
}
|
||||
return dict;
|
||||
}
|
||||
}
|
||||
|
||||
return EXPP_ReturnPyObjError( PyExc_RuntimeError,
|
||||
"eek!! a property exists with a bad type code!!!" );
|
||||
}
|
||||
|
||||
static PyObject *BPy_IDGroup_Pop(BPy_IDProperty *self, PyObject *value)
|
||||
{
|
||||
IDProperty *loop;
|
||||
PyObject *pyform;
|
||||
char *name = PyString_AsString(value);
|
||||
|
||||
if (!name) {
|
||||
return EXPP_ReturnPyObjError( PyExc_TypeError,
|
||||
"pop expected at least 1 argument, got 0" );
|
||||
}
|
||||
|
||||
for (loop=self->prop->data.group.first; loop; loop=loop->next) {
|
||||
if (BSTR_EQ(loop->name, name)) {
|
||||
pyform = BPy_IDGroup_MapDataToPy(loop);
|
||||
|
||||
if (!pyform)
|
||||
/*ok something bad happened with the pyobject,
|
||||
so don't remove the prop from the group. if pyform is
|
||||
NULL, then it already should have raised an exception.*/
|
||||
return NULL;
|
||||
|
||||
IDP_RemFromGroup(self->prop, loop);
|
||||
return pyform;
|
||||
}
|
||||
}
|
||||
|
||||
return EXPP_ReturnPyObjError( PyExc_KeyError,
|
||||
"item not in group" );
|
||||
}
|
||||
|
||||
static PyObject *BPy_IDGroup_IterItems(BPy_IDProperty *self)
|
||||
{
|
||||
BPy_IDGroup_Iter *iter = PyObject_New(BPy_IDGroup_Iter, &IDGroup_Iter_Type);
|
||||
|
||||
if (!iter)
|
||||
return EXPP_ReturnPyObjError( PyExc_RuntimeError,
|
||||
"PyObject_New() failed" );
|
||||
|
||||
iter->group = self;
|
||||
iter->mode = IDPROP_ITER_ITEMS;
|
||||
iter->cur = self->prop->data.group.first;
|
||||
Py_XINCREF(iter);
|
||||
return (PyObject*) iter;
|
||||
}
|
||||
|
||||
static PyObject *BPy_IDGroup_GetKeys(BPy_IDProperty *self)
|
||||
{
|
||||
PyObject *seq = PyList_New(self->prop->len);
|
||||
IDProperty *loop;
|
||||
int i, j;
|
||||
|
||||
if (!seq)
|
||||
return EXPP_ReturnPyObjError( PyExc_RuntimeError,
|
||||
"PyList_New() failed" );
|
||||
|
||||
for (i=0, loop=self->prop->data.group.first; loop; loop=loop->next, i++)
|
||||
PyList_SetItem(seq, i, PyString_FromString(loop->name));
|
||||
|
||||
if (i != self->prop->len) {
|
||||
printf("ID Property Error found and corrected in BPy_IDGroup_GetKeys!\n");
|
||||
|
||||
/*fill rest of list with valid references to None*/
|
||||
for (j=i; j<self->prop->len; j++) {
|
||||
Py_INCREF(Py_None);
|
||||
PyList_SetItem(seq, j, Py_None);
|
||||
}
|
||||
|
||||
/*set correct group length*/
|
||||
self->prop->len = i;
|
||||
|
||||
/*free the list*/
|
||||
Py_DECREF(seq);
|
||||
|
||||
/*call self again*/
|
||||
return BPy_IDGroup_GetKeys(self);
|
||||
}
|
||||
|
||||
return seq;
|
||||
}
|
||||
|
||||
static PyObject *BPy_IDGroup_GetValues(BPy_IDProperty *self)
|
||||
{
|
||||
PyObject *seq = PyList_New(self->prop->len);
|
||||
IDProperty *loop;
|
||||
int i, j;
|
||||
|
||||
if (!seq)
|
||||
return EXPP_ReturnPyObjError( PyExc_RuntimeError,
|
||||
"PyList_New() failed" );
|
||||
|
||||
for (i=0, loop=self->prop->data.group.first; loop; loop=loop->next, i++) {
|
||||
PyList_SetItem(seq, i, BPy_IDGroup_WrapData(self->id, loop));
|
||||
}
|
||||
|
||||
if (i != self->prop->len) {
|
||||
printf("ID Property Error found and corrected in BPy_IDGroup_GetValues!\n");
|
||||
|
||||
/*fill rest of list with valid references to None*/
|
||||
for (j=i; j<self->prop->len; j++) {
|
||||
Py_INCREF(Py_None);
|
||||
PyList_SetItem(seq, j, Py_None);
|
||||
}
|
||||
|
||||
/*set correct group length*/
|
||||
self->prop->len = i;
|
||||
|
||||
/*free the old list*/
|
||||
Py_DECREF(seq);
|
||||
|
||||
/*call self again*/
|
||||
return BPy_IDGroup_GetValues(self);
|
||||
}
|
||||
|
||||
return seq;
|
||||
}
|
||||
|
||||
static PyObject *BPy_IDGroup_HasKey(BPy_IDProperty *self, PyObject *value)
|
||||
{
|
||||
IDProperty *loop;
|
||||
char *name = PyString_AsString(value);
|
||||
|
||||
if (!name)
|
||||
return EXPP_ReturnPyObjError( PyExc_TypeError,
|
||||
"expected a string");
|
||||
|
||||
for (loop=self->prop->data.group.first; loop; loop=loop->next) {
|
||||
if (BSTR_EQ(loop->name, name)) Py_RETURN_TRUE;
|
||||
}
|
||||
|
||||
Py_RETURN_FALSE;
|
||||
}
|
||||
|
||||
static PyObject *BPy_IDGroup_Update(BPy_IDProperty *self, PyObject *vars)
|
||||
{
|
||||
PyObject *pyob, *pkey, *pval;
|
||||
Py_ssize_t i=0;
|
||||
|
||||
if (PySequence_Size(vars) != 1)
|
||||
return EXPP_ReturnPyObjError( PyExc_TypeError,
|
||||
"expected an object derived from dict.");
|
||||
|
||||
pyob = PyTuple_GET_ITEM(vars, 0);
|
||||
if (!PyDict_Check(pyob))
|
||||
return EXPP_ReturnPyObjError( PyExc_TypeError,
|
||||
"expected an object derived from dict.");
|
||||
|
||||
while (PyDict_Next(pyob, &i, &pkey, &pval)) {
|
||||
BPy_IDGroup_Map_SetItem(self, pkey, pval);
|
||||
if (PyErr_Occurred()) return NULL;
|
||||
}
|
||||
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
static PyObject *BPy_IDGroup_ConvertToPy(BPy_IDProperty *self)
|
||||
{
|
||||
return BPy_IDGroup_MapDataToPy(self->prop);
|
||||
}
|
||||
|
||||
static struct PyMethodDef BPy_IDGroup_methods[] = {
|
||||
{"pop", (PyCFunction)BPy_IDGroup_Pop, METH_O,
|
||||
"pop an item from the group; raises KeyError if the item doesn't exist."},
|
||||
{"iteritems", (PyCFunction)BPy_IDGroup_IterItems, METH_NOARGS,
|
||||
"iterate through the items in the dict; behaves like dictionary method iteritems."},
|
||||
{"keys", (PyCFunction)BPy_IDGroup_GetKeys, METH_NOARGS,
|
||||
"get the keys associated with this group as a list of strings."},
|
||||
{"values", (PyCFunction)BPy_IDGroup_GetValues, METH_NOARGS,
|
||||
"get the values associated with this group."},
|
||||
{"has_key", (PyCFunction)BPy_IDGroup_HasKey, METH_O,
|
||||
"returns true if the group contains a key, false if not."},
|
||||
{"update", (PyCFunction)BPy_IDGroup_Update, METH_VARARGS,
|
||||
"updates the values in the group with the values of another or a dict."},
|
||||
{"convert_to_pyobject", (PyCFunction)BPy_IDGroup_ConvertToPy, METH_NOARGS,
|
||||
"return a purely python version of the group."},
|
||||
{0, NULL, 0, NULL}
|
||||
};
|
||||
|
||||
PyMappingMethods BPy_IDGroup_Mapping = {
|
||||
(inquiry)BPy_IDGroup_Map_Len, /*inquiry mp_length */
|
||||
(binaryfunc)BPy_IDGroup_Map_GetItem, /*binaryfunc mp_subscript */
|
||||
(objobjargproc)BPy_IDGroup_Map_SetItem, /*objobjargproc mp_ass_subscript */
|
||||
};
|
||||
|
||||
PyTypeObject IDGroup_Type = {
|
||||
PyObject_HEAD_INIT( NULL ) /* required py macro */
|
||||
0, /* ob_size */
|
||||
/* For printing, in format "<module>.<name>" */
|
||||
"Blender IDProperty", /* char *tp_name; */
|
||||
sizeof( BPy_IDProperty ), /* int tp_basicsize; */
|
||||
0, /* tp_itemsize; For allocation */
|
||||
|
||||
/* Methods to implement standard operations */
|
||||
|
||||
NULL, /* destructor tp_dealloc; */
|
||||
NULL, /* printfunc tp_print; */
|
||||
NULL, /* getattrfunc tp_getattr; */
|
||||
NULL, /* setattrfunc tp_setattr; */
|
||||
NULL, /* cmpfunc tp_compare; */
|
||||
( reprfunc ) IDGroup_repr, /* reprfunc tp_repr; */
|
||||
|
||||
/* Method suites for standard classes */
|
||||
|
||||
NULL, /* PyNumberMethods *tp_as_number; */
|
||||
NULL, /* PySequenceMethods *tp_as_sequence; */
|
||||
&BPy_IDGroup_Mapping, /* PyMappingMethods *tp_as_mapping; */
|
||||
|
||||
/* More standard operations (here for binary compatibility) */
|
||||
|
||||
NULL, /* hashfunc tp_hash; */
|
||||
NULL, /* ternaryfunc tp_call; */
|
||||
NULL, /* reprfunc tp_str; */
|
||||
NULL, /* getattrofunc tp_getattro; */
|
||||
NULL, /* setattrofunc tp_setattro; */
|
||||
|
||||
/* Functions to access object as input/output buffer */
|
||||
NULL, /* PyBufferProcs *tp_as_buffer; */
|
||||
|
||||
/*** Flags to define presence of optional/expanded features ***/
|
||||
Py_TPFLAGS_DEFAULT, /* long tp_flags; */
|
||||
|
||||
NULL, /* char *tp_doc; Documentation string */
|
||||
/*** Assigned meaning in release 2.0 ***/
|
||||
/* call function for all accessible objects */
|
||||
NULL, /* traverseproc tp_traverse; */
|
||||
|
||||
/* delete references to contained objects */
|
||||
NULL, /* inquiry tp_clear; */
|
||||
|
||||
/*** Assigned meaning in release 2.1 ***/
|
||||
/*** rich comparisons ***/
|
||||
NULL, /* richcmpfunc tp_richcompare; */
|
||||
|
||||
/*** weak reference enabler ***/
|
||||
0, /* long tp_weaklistoffset; */
|
||||
|
||||
/*** Added in release 2.2 ***/
|
||||
/* Iterators */
|
||||
(getiterfunc)BPy_IDGroup_SpawnIterator, /* getiterfunc tp_iter; */
|
||||
NULL, /* iternextfunc tp_iternext; */
|
||||
/*** Attribute descriptor and subclassing stuff ***/
|
||||
BPy_IDGroup_methods, /* struct PyMethodDef *tp_methods; */
|
||||
NULL, /* struct PyMemberDef *tp_members; */
|
||||
BPy_IDGroup_getseters, /* struct PyGetSetDef *tp_getset; */
|
||||
};
|
||||
|
||||
/*********** Main external wrapping function *******/
|
||||
PyObject *BPy_Wrap_IDProperty(ID *id, IDProperty *prop, IDProperty *parent)
|
||||
{
|
||||
BPy_IDProperty *wrap = PyObject_New(BPy_IDProperty, &IDGroup_Type);
|
||||
|
||||
if (!wrap)
|
||||
return EXPP_ReturnPyObjError( PyExc_RuntimeError,
|
||||
"PyObject_New() failed" );
|
||||
|
||||
wrap->prop = prop;
|
||||
wrap->parent = parent;
|
||||
wrap->id = id;
|
||||
//wrap->destroy = 0;
|
||||
return (PyObject*) wrap;
|
||||
}
|
||||
|
||||
|
||||
/********Array Wrapper********/
|
||||
|
||||
static PyObject *IDArray_repr(BPy_IDArray *self)
|
||||
{
|
||||
return PyString_FromString("(ID Array)");
|
||||
}
|
||||
|
||||
|
||||
static PyObject *BPy_IDArray_GetType(BPy_IDArray *self)
|
||||
{
|
||||
return PyInt_FromLong( (long)self->prop->subtype );
|
||||
}
|
||||
|
||||
static PyObject *BPy_IDArray_GetLen(BPy_IDArray *self)
|
||||
{
|
||||
return PyInt_FromLong( (long)self->prop->len );
|
||||
}
|
||||
|
||||
static PyGetSetDef BPy_IDArray_getseters[] = {
|
||||
{"len",
|
||||
(getter)BPy_IDArray_GetLen, (setter)NULL,
|
||||
"The length of the array, can also be gotten with len(array).",
|
||||
NULL},
|
||||
{"type",
|
||||
(getter)BPy_IDArray_GetType, (setter)NULL,
|
||||
"The type of the data in the array, is an ant.",
|
||||
NULL},
|
||||
{NULL, NULL, NULL, NULL, NULL},
|
||||
};
|
||||
|
||||
static int BPy_IDArray_Len(BPy_IDArray *self)
|
||||
{
|
||||
return self->prop->len;
|
||||
}
|
||||
|
||||
static PyObject *BPy_IDArray_GetItem(BPy_IDArray *self, int index)
|
||||
{
|
||||
if (index < 0 || index >= self->prop->len)
|
||||
return EXPP_ReturnPyObjError( PyExc_IndexError,
|
||||
"index out of range!");
|
||||
|
||||
switch (self->prop->subtype) {
|
||||
case IDP_FLOAT:
|
||||
return PyFloat_FromDouble( (double)(((float*)self->prop->data.pointer)[index]));
|
||||
break;
|
||||
case IDP_DOUBLE:
|
||||
return PyFloat_FromDouble( (((double*)self->prop->data.pointer)[index]));
|
||||
break;
|
||||
case IDP_INT:
|
||||
return PyInt_FromLong( (long)((int*)self->prop->data.pointer)[index] );
|
||||
break;
|
||||
}
|
||||
return EXPP_ReturnPyObjError( PyExc_RuntimeError,
|
||||
"invalid/corrupt array type!");
|
||||
}
|
||||
|
||||
static int BPy_IDArray_SetItem(BPy_IDArray *self, int index, PyObject *val)
|
||||
{
|
||||
int i;
|
||||
float f;
|
||||
double d;
|
||||
|
||||
if (index < 0 || index >= self->prop->len)
|
||||
return EXPP_ReturnIntError( PyExc_RuntimeError,
|
||||
"index out of range!");
|
||||
|
||||
switch (self->prop->subtype) {
|
||||
case IDP_FLOAT:
|
||||
if (!PyNumber_Check(val)) return EXPP_ReturnIntError( PyExc_TypeError,
|
||||
"expected a float");
|
||||
val = PyNumber_Float(val);
|
||||
if (!val) return EXPP_ReturnIntError( PyExc_TypeError,
|
||||
"expected a float");
|
||||
|
||||
f = (float) PyFloat_AsDouble(val);
|
||||
((float*)self->prop->data.pointer)[index] = f;
|
||||
Py_XDECREF(val);
|
||||
break;
|
||||
case IDP_DOUBLE:
|
||||
if (!PyNumber_Check(val)) return EXPP_ReturnIntError( PyExc_TypeError,
|
||||
"expected a float");
|
||||
val = PyNumber_Float(val);
|
||||
if (!val) return EXPP_ReturnIntError( PyExc_TypeError,
|
||||
"expected a float");
|
||||
|
||||
d = (double) PyFloat_AsDouble(val);
|
||||
((double*)self->prop->data.pointer)[index] = d;
|
||||
Py_XDECREF(val);
|
||||
break;
|
||||
case IDP_INT:
|
||||
if (!PyNumber_Check(val)) return EXPP_ReturnIntError( PyExc_TypeError,
|
||||
"expected an int");
|
||||
val = PyNumber_Int(val);
|
||||
if (!val) return EXPP_ReturnIntError( PyExc_TypeError,
|
||||
"expected an int");
|
||||
|
||||
i = (int) PyInt_AsLong(val);
|
||||
((int*)self->prop->data.pointer)[index] = i;
|
||||
Py_XDECREF(val);
|
||||
break;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static PySequenceMethods BPy_IDArray_Seq = {
|
||||
(inquiry) BPy_IDArray_Len, /* inquiry sq_length */
|
||||
0, /* binaryfunc sq_concat */
|
||||
0, /* intargfunc sq_repeat */
|
||||
(intargfunc)BPy_IDArray_GetItem, /* intargfunc sq_item */
|
||||
0, /* intintargfunc sq_slice */
|
||||
(intobjargproc)BPy_IDArray_SetItem, /* intobjargproc sq_ass_item */
|
||||
0, /* intintobjargproc sq_ass_slice */
|
||||
0, /* objobjproc sq_contains */
|
||||
/* Added in release 2.0 */
|
||||
0, /* binaryfunc sq_inplace_concat */
|
||||
0, /* intargfunc sq_inplace_repeat */
|
||||
};
|
||||
|
||||
PyTypeObject IDArray_Type = {
|
||||
PyObject_HEAD_INIT( NULL ) /* required py macro */
|
||||
0, /* ob_size */
|
||||
/* For printing, in format "<module>.<name>" */
|
||||
"Blender IDArray", /* char *tp_name; */
|
||||
sizeof( BPy_IDArray ), /* int tp_basicsize; */
|
||||
0, /* tp_itemsize; For allocation */
|
||||
|
||||
/* Methods to implement standard operations */
|
||||
|
||||
NULL, /* destructor tp_dealloc; */
|
||||
NULL, /* printfunc tp_print; */
|
||||
NULL, /* getattrfunc tp_getattr; */
|
||||
NULL, /* setattrfunc tp_setattr; */
|
||||
NULL, /* cmpfunc tp_compare; */
|
||||
( reprfunc ) IDArray_repr, /* reprfunc tp_repr; */
|
||||
|
||||
/* Method suites for standard classes */
|
||||
|
||||
NULL, /* PyNumberMethods *tp_as_number; */
|
||||
&BPy_IDArray_Seq, /* PySequenceMethods *tp_as_sequence; */
|
||||
NULL, /* PyMappingMethods *tp_as_mapping; */
|
||||
|
||||
/* More standard operations (here for binary compatibility) */
|
||||
|
||||
NULL, /* hashfunc tp_hash; */
|
||||
NULL, /* ternaryfunc tp_call; */
|
||||
NULL, /* reprfunc tp_str; */
|
||||
NULL, /* getattrofunc tp_getattro; */
|
||||
NULL, /* setattrofunc tp_setattro; */
|
||||
|
||||
/* Functions to access object as input/output buffer */
|
||||
NULL, /* PyBufferProcs *tp_as_buffer; */
|
||||
|
||||
/*** Flags to define presence of optional/expanded features ***/
|
||||
Py_TPFLAGS_DEFAULT, /* long tp_flags; */
|
||||
|
||||
NULL, /* char *tp_doc; Documentation string */
|
||||
/*** Assigned meaning in release 2.0 ***/
|
||||
/* call function for all accessible objects */
|
||||
NULL, /* traverseproc tp_traverse; */
|
||||
|
||||
/* delete references to contained objects */
|
||||
NULL, /* inquiry tp_clear; */
|
||||
|
||||
/*** Assigned meaning in release 2.1 ***/
|
||||
/*** rich comparisons ***/
|
||||
NULL, /* richcmpfunc tp_richcompare; */
|
||||
|
||||
/*** weak reference enabler ***/
|
||||
0, /* long tp_weaklistoffset; */
|
||||
|
||||
/*** Added in release 2.2 ***/
|
||||
/* Iterators */
|
||||
NULL, /* getiterfunc tp_iter; */
|
||||
NULL, /* iternextfunc tp_iternext; */
|
||||
|
||||
/*** Attribute descriptor and subclassing stuff ***/
|
||||
NULL, /* struct PyMethodDef *tp_methods; */
|
||||
NULL, /* struct PyMemberDef *tp_members; */
|
||||
BPy_IDArray_getseters, /* struct PyGetSetDef *tp_getset; */
|
||||
NULL, /* struct _typeobject *tp_base; */
|
||||
NULL, /* PyObject *tp_dict; */
|
||||
NULL, /* descrgetfunc tp_descr_get; */
|
||||
NULL, /* descrsetfunc tp_descr_set; */
|
||||
0, /* long tp_dictoffset; */
|
||||
NULL, /* initproc tp_init; */
|
||||
NULL, /* allocfunc tp_alloc; */
|
||||
NULL, /* newfunc tp_new; */
|
||||
/* Low-level free-memory routine */
|
||||
NULL, /* freefunc tp_free; */
|
||||
/* For PyObject_IS_GC */
|
||||
NULL, /* inquiry tp_is_gc; */
|
||||
NULL, /* PyObject *tp_bases; */
|
||||
/* method resolution order */
|
||||
NULL, /* PyObject *tp_mro; */
|
||||
NULL, /* PyObject *tp_cache; */
|
||||
NULL, /* PyObject *tp_subclasses; */
|
||||
NULL, /* PyObject *tp_weaklist; */
|
||||
NULL
|
||||
};
|
||||
|
||||
/*********** ID Property Group iterator ********/
|
||||
|
||||
static PyObject *IDGroup_Iter_iterself(PyObject *self)
|
||||
{
|
||||
Py_XINCREF(self);
|
||||
return self;
|
||||
}
|
||||
|
||||
static PyObject *IDGroup_Iter_repr(BPy_IDGroup_Iter *self)
|
||||
{
|
||||
return PyString_FromString("(ID Property Group)");
|
||||
}
|
||||
|
||||
static PyObject *BPy_Group_Iter_Next(BPy_IDGroup_Iter *self)
|
||||
{
|
||||
IDProperty *cur=NULL;
|
||||
PyObject *tmpval;
|
||||
PyObject *ret;
|
||||
|
||||
if (self->cur) {
|
||||
cur = self->cur;
|
||||
self->cur = self->cur->next;
|
||||
if (self->mode == IDPROP_ITER_ITEMS) {
|
||||
tmpval = BPy_IDGroup_WrapData(self->group->id, cur);
|
||||
ret = Py_BuildValue("[s, O]", cur->name, tmpval);
|
||||
Py_DECREF(tmpval);
|
||||
return ret;
|
||||
} else {
|
||||
return PyString_FromString(cur->name);
|
||||
}
|
||||
} else {
|
||||
return EXPP_ReturnPyObjError( PyExc_StopIteration,
|
||||
"iterator at end" );
|
||||
}
|
||||
}
|
||||
|
||||
PyTypeObject IDGroup_Iter_Type = {
|
||||
PyObject_HEAD_INIT( NULL ) /* required py macro */
|
||||
0, /* ob_size */
|
||||
/* For printing, in format "<module>.<name>" */
|
||||
"Blender IDGroup_Iter", /* char *tp_name; */
|
||||
sizeof( BPy_IDGroup_Iter ), /* int tp_basicsize; */
|
||||
0, /* tp_itemsize; For allocation */
|
||||
|
||||
/* Methods to implement standard operations */
|
||||
|
||||
NULL, /* destructor tp_dealloc; */
|
||||
NULL, /* printfunc tp_print; */
|
||||
NULL, /* getattrfunc tp_getattr; */
|
||||
NULL, /* setattrfunc tp_setattr; */
|
||||
NULL, /* cmpfunc tp_compare; */
|
||||
( reprfunc ) IDGroup_Iter_repr, /* reprfunc tp_repr; */
|
||||
|
||||
/* Method suites for standard classes */
|
||||
|
||||
NULL, /* PyNumberMethods *tp_as_number; */
|
||||
NULL, /* PySequenceMethods *tp_as_sequence; */
|
||||
NULL, /* PyMappingMethods *tp_as_mapping; */
|
||||
|
||||
/* More standard operations (here for binary compatibility) */
|
||||
|
||||
NULL, /* hashfunc tp_hash; */
|
||||
NULL, /* ternaryfunc tp_call; */
|
||||
NULL, /* reprfunc tp_str; */
|
||||
NULL, /* getattrofunc tp_getattro; */
|
||||
NULL, /* setattrofunc tp_setattro; */
|
||||
|
||||
/* Functions to access object as input/output buffer */
|
||||
NULL, /* PyBufferProcs *tp_as_buffer; */
|
||||
|
||||
/*** Flags to define presence of optional/expanded features ***/
|
||||
Py_TPFLAGS_DEFAULT, /* long tp_flags; */
|
||||
|
||||
NULL, /* char *tp_doc; Documentation string */
|
||||
/*** Assigned meaning in release 2.0 ***/
|
||||
/* call function for all accessible objects */
|
||||
NULL, /* traverseproc tp_traverse; */
|
||||
|
||||
/* delete references to contained objects */
|
||||
NULL, /* inquiry tp_clear; */
|
||||
|
||||
/*** Assigned meaning in release 2.1 ***/
|
||||
/*** rich comparisons ***/
|
||||
NULL, /* richcmpfunc tp_richcompare; */
|
||||
|
||||
/*** weak reference enabler ***/
|
||||
0, /* long tp_weaklistoffset; */
|
||||
|
||||
/*** Added in release 2.2 ***/
|
||||
/* Iterators */
|
||||
IDGroup_Iter_iterself, /* getiterfunc tp_iter; */
|
||||
(iternextfunc) BPy_Group_Iter_Next, /* iternextfunc tp_iternext; */
|
||||
};
|
||||
|
||||
void IDProp_Init_Types(void)
|
||||
{
|
||||
PyType_Ready( &IDGroup_Type );
|
||||
PyType_Ready( &IDGroup_Iter_Type );
|
||||
PyType_Ready( &IDArray_Type );
|
||||
}
|
||||
@@ -1,58 +0,0 @@
|
||||
/**
|
||||
* $Id: IDProp.h
|
||||
*
|
||||
* ***** 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*
|
||||
* The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Contributor(s): Joseph Eagar
|
||||
*
|
||||
* ***** END GPL LICENSE BLOCK *****
|
||||
*/
|
||||
|
||||
#include <Python.h>
|
||||
|
||||
struct ID;
|
||||
struct IDProperty;
|
||||
struct BPy_IDGroup_Iter;
|
||||
|
||||
typedef struct BPy_IDProperty {
|
||||
PyObject_VAR_HEAD
|
||||
struct ID *id;
|
||||
struct IDProperty *prop, *parent;
|
||||
PyObject *data_wrap;
|
||||
} BPy_IDProperty;
|
||||
|
||||
typedef struct BPy_IDArray {
|
||||
PyObject_VAR_HEAD
|
||||
struct ID *id;
|
||||
struct IDProperty *prop;
|
||||
} BPy_IDArray;
|
||||
|
||||
typedef struct BPy_IDGroup_Iter {
|
||||
PyObject_VAR_HEAD
|
||||
BPy_IDProperty *group;
|
||||
struct IDProperty *cur;
|
||||
int mode;
|
||||
} BPy_IDGroup_Iter;
|
||||
|
||||
PyObject *BPy_Wrap_IDProperty(struct ID *id, struct IDProperty *prop, struct IDProperty *parent);
|
||||
void IDProp_Init_Types(void);
|
||||
|
||||
#define IDPROP_ITER_KEYS 0
|
||||
#define IDPROP_ITER_ITEMS 1
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,57 +0,0 @@
|
||||
/*
|
||||
* $Id$
|
||||
*
|
||||
* ***** 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*
|
||||
* The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This is a new part of Blender.
|
||||
*
|
||||
* Contributor(s): Willian P. Germano, Alex Mole
|
||||
*
|
||||
* ***** END GPL LICENSE BLOCK *****
|
||||
*/
|
||||
|
||||
#ifndef EXPP_IMAGE_H
|
||||
#define EXPP_IMAGE_H
|
||||
|
||||
#include <Python.h>
|
||||
#include "DNA_image_types.h"
|
||||
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Python BPy_Image structure definition */
|
||||
/*****************************************************************************/
|
||||
typedef struct {
|
||||
PyObject_HEAD
|
||||
Image * image; /* libdata must be second */
|
||||
|
||||
} BPy_Image;
|
||||
|
||||
extern PyTypeObject Image_Type; /* The Image PyType Object */
|
||||
|
||||
#define BPy_Image_Check(v) ((v)->ob_type == &Image_Type) /*for type checking */
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Module Blender.Image - public functions */
|
||||
/*****************************************************************************/
|
||||
PyObject *Image_Init( void );
|
||||
PyObject *Image_CreatePyObject( Image * image );
|
||||
Image *Image_FromPyObject( PyObject * pyobj );
|
||||
|
||||
#endif /* EXPP_IMAGE_H */
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,60 +0,0 @@
|
||||
/*
|
||||
* $Id$
|
||||
*
|
||||
* ***** 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*
|
||||
* The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This is a new part of Blender.
|
||||
*
|
||||
* Contributor(s): Jacques Guignot
|
||||
*
|
||||
* ***** END GPL LICENSE BLOCK *****
|
||||
*/
|
||||
|
||||
#ifndef EXPP_IPO_H
|
||||
#define EXPP_IPO_H
|
||||
|
||||
#include <Python.h>
|
||||
#include "DNA_ipo_types.h"
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Python BPy_Ipo structure definition: */
|
||||
/*****************************************************************************/
|
||||
typedef struct {
|
||||
PyObject_HEAD /* required macro */
|
||||
Ipo * ipo; /* libdata must be second */
|
||||
short iter;
|
||||
short mtex;
|
||||
} BPy_Ipo;
|
||||
|
||||
extern PyTypeObject Ipo_Type;
|
||||
|
||||
#define BPy_Ipo_Check(v) ((v)->ob_type == &Ipo_Type) /* for type checking */
|
||||
|
||||
|
||||
/*
|
||||
* prototypes
|
||||
*/
|
||||
|
||||
PyObject *Ipo_Init( void );
|
||||
PyObject *Ipo_CreatePyObject( struct Ipo *ipo );
|
||||
Ipo *Ipo_FromPyObject( PyObject * py_obj );
|
||||
|
||||
|
||||
#endif /* EXPP_IPO_H */
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,55 +0,0 @@
|
||||
/*
|
||||
* $Id$
|
||||
*
|
||||
* ***** 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*
|
||||
* The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This is a new part of Blender.
|
||||
*
|
||||
* Contributor(s): Jacques Guignot
|
||||
*
|
||||
* ***** END GPL LICENSE BLOCK *****
|
||||
*/
|
||||
|
||||
#ifndef EXPP_IPOCURVE_H
|
||||
#define EXPP_IPOCURVE_H
|
||||
|
||||
#include <Python.h>
|
||||
#include "DNA_ipo_types.h" /* declaration of IpoCurve */
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Python C_IpoCurve structure definition: */
|
||||
/*****************************************************************************/
|
||||
typedef struct {
|
||||
PyObject_HEAD /* required macro */
|
||||
IpoCurve * ipocurve;
|
||||
char wrapped;
|
||||
} C_IpoCurve;
|
||||
|
||||
extern PyTypeObject IpoCurve_Type;
|
||||
|
||||
#define BPy_IpoCurve_Check(v) ((v)->ob_type == &IpoCurve_Type) /* for type checking */
|
||||
|
||||
PyObject *IpoCurve_Init( void );
|
||||
PyObject *IpoCurve_CreatePyObject( IpoCurve * ipo );
|
||||
IpoCurve *IpoCurve_FromPyObject( PyObject * pyobj );
|
||||
char *getIpoCurveName( IpoCurve * icu );
|
||||
|
||||
|
||||
#endif /* EXPP_IPOCURVE_H */
|
||||
@@ -1,678 +0,0 @@
|
||||
/*
|
||||
* $Id$
|
||||
*
|
||||
* ***** 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*
|
||||
* The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This is a new part of Blender.
|
||||
*
|
||||
* Contributor(s): Pontus Lidman, Johnny Matthews, Ken Hughes,
|
||||
* Michael Reimpell
|
||||
*
|
||||
* ***** END GPL LICENSE BLOCK *****
|
||||
*/
|
||||
|
||||
#include "Key.h" /*This must come first*/
|
||||
#include "vector.h"
|
||||
|
||||
#include "DNA_scene_types.h"
|
||||
|
||||
#include <BLI_blenlib.h>
|
||||
#include <BKE_global.h>
|
||||
#include <BKE_main.h>
|
||||
#include <BKE_curve.h>
|
||||
#include <BKE_library.h>
|
||||
#include <BKE_utildefines.h>
|
||||
#include "BIF_space.h"
|
||||
|
||||
#include "Ipocurve.h"
|
||||
#include "NMesh.h" /* we create NMesh.NMVert objects */
|
||||
#include "Ipo.h"
|
||||
#include "BezTriple.h"
|
||||
|
||||
#include "BSE_editipo.h"
|
||||
#include "mydevice.h"
|
||||
#include "BKE_depsgraph.h"
|
||||
#include "blendef.h"
|
||||
#include "constant.h"
|
||||
#include "gen_utils.h"
|
||||
#include "gen_library.h"
|
||||
|
||||
#define KEY_TYPE_MESH 0
|
||||
#define KEY_TYPE_CURVE 1
|
||||
#define KEY_TYPE_LATTICE 2
|
||||
|
||||
static int Key_compare( BPy_Key * a, BPy_Key * b );
|
||||
static PyObject *Key_repr( BPy_Key * self );
|
||||
static void Key_dealloc( BPy_Key * self );
|
||||
|
||||
static PyObject *Key_getBlocks( BPy_Key * self );
|
||||
static PyObject *Key_getType( BPy_Key * self );
|
||||
static PyObject *Key_getRelative( BPy_Key * self );
|
||||
static PyObject *Key_getIpo( BPy_Key * self );
|
||||
static int Key_setIpo( BPy_Key * self, PyObject * args );
|
||||
static PyObject *Key_getValue( BPy_Key * self );
|
||||
static int Key_setRelative( BPy_Key * self, PyObject * value );
|
||||
|
||||
static struct PyMethodDef Key_methods[] = {
|
||||
{ "getBlocks", (PyCFunction) Key_getBlocks, METH_NOARGS, "Get key blocks" },
|
||||
{ "getIpo", (PyCFunction) Key_getIpo, METH_NOARGS, "Get key Ipo" },
|
||||
{ 0, 0, 0, 0 }
|
||||
};
|
||||
|
||||
static PyGetSetDef BPy_Key_getsetters[] = {
|
||||
{"type",(getter)Key_getType, (setter)NULL,
|
||||
"Key Type",NULL},
|
||||
{"value",(getter)Key_getValue, (setter)NULL,
|
||||
"Key value",NULL},
|
||||
{"ipo",(getter)Key_getIpo, (setter)Key_setIpo,
|
||||
"Ipo linked to key",NULL},
|
||||
{"blocks",(getter)Key_getBlocks, (setter)NULL,
|
||||
"Blocks linked to the key",NULL},
|
||||
{"relative",(getter)Key_getRelative, (setter)Key_setRelative,
|
||||
"Non-zero is key is relative",NULL},
|
||||
{NULL,NULL,NULL,NULL,NULL} /* Sentinel */
|
||||
};
|
||||
|
||||
static PyObject *KeyBlock_getData( PyObject * self );
|
||||
static PyObject *KeyBlock_getCurval( BPy_KeyBlock * self );
|
||||
static PyObject *KeyBlock_getName( BPy_KeyBlock * self );
|
||||
static PyObject *KeyBlock_getPos( BPy_KeyBlock * self );
|
||||
static PyObject *KeyBlock_getSlidermin( BPy_KeyBlock * self );
|
||||
static PyObject *KeyBlock_getSlidermax( BPy_KeyBlock * self );
|
||||
static PyObject *KeyBlock_getVgroup( BPy_KeyBlock * self );
|
||||
|
||||
static int KeyBlock_setName( BPy_KeyBlock *, PyObject * args );
|
||||
static int KeyBlock_setVgroup( BPy_KeyBlock *, PyObject * args );
|
||||
static int KeyBlock_setSlidermin( BPy_KeyBlock *, PyObject * args );
|
||||
static int KeyBlock_setSlidermax( BPy_KeyBlock *, PyObject * args );
|
||||
|
||||
static void KeyBlock_dealloc( BPy_KeyBlock * self );
|
||||
static int KeyBlock_compare( BPy_KeyBlock * a, BPy_KeyBlock * b );
|
||||
static PyObject *KeyBlock_repr( BPy_KeyBlock * self );
|
||||
|
||||
static struct PyMethodDef KeyBlock_methods[] = {
|
||||
{ "getData", (PyCFunction) KeyBlock_getData, METH_NOARGS,
|
||||
"Get keyblock data" },
|
||||
{ 0, 0, 0, 0 }
|
||||
};
|
||||
|
||||
static PyGetSetDef BPy_KeyBlock_getsetters[] = {
|
||||
{"curval",(getter)KeyBlock_getCurval, (setter)NULL,
|
||||
"Current value of the corresponding IpoCurve",NULL},
|
||||
{"name",(getter)KeyBlock_getName, (setter)KeyBlock_setName,
|
||||
"Keyblock Name",NULL},
|
||||
{"pos",(getter)KeyBlock_getPos, (setter)NULL,
|
||||
"Keyblock Pos",NULL},
|
||||
{"slidermin",(getter)KeyBlock_getSlidermin, (setter)KeyBlock_setSlidermin,
|
||||
"Keyblock Slider Minimum",NULL},
|
||||
{"slidermax",(getter)KeyBlock_getSlidermax, (setter)KeyBlock_setSlidermax,
|
||||
"Keyblock Slider Maximum",NULL},
|
||||
{"vgroup",(getter)KeyBlock_getVgroup, (setter)KeyBlock_setVgroup,
|
||||
"Keyblock VGroup",NULL},
|
||||
{"data",(getter)KeyBlock_getData, (setter)NULL,
|
||||
"Keyblock VGroup",NULL},
|
||||
{NULL,NULL,NULL,NULL,NULL} /* Sentinel */
|
||||
};
|
||||
|
||||
PyTypeObject Key_Type = {
|
||||
PyObject_HEAD_INIT( NULL ) 0, /*ob_size */
|
||||
"Blender Key", /*tp_name */
|
||||
sizeof( BPy_Key ), /*tp_basicsize */
|
||||
0, /*tp_itemsize */
|
||||
/* methods */
|
||||
( destructor ) Key_dealloc,/* destructor tp_dealloc; */
|
||||
( printfunc ) 0, /*tp_print */
|
||||
( getattrfunc ) 0, /*tp_getattr */
|
||||
( setattrfunc ) 0, /*tp_setattr */
|
||||
( cmpfunc) Key_compare, /*tp_compare*/
|
||||
( reprfunc ) Key_repr, /* tp_repr */
|
||||
/* Method suites for standard classes */
|
||||
|
||||
NULL, /* PyNumberMethods *tp_as_number; */
|
||||
NULL, /* PySequenceMethods *tp_as_sequence; */
|
||||
NULL, /* PyMappingMethods *tp_as_mapping; */
|
||||
|
||||
/* More standard operations (here for binary compatibility) */
|
||||
|
||||
( hashfunc ) GenericLib_hash, /* hashfunc tp_hash; */
|
||||
NULL, /* ternaryfunc tp_call; */
|
||||
NULL, /* reprfunc tp_str; */
|
||||
NULL, /* getattrofunc tp_getattro; */
|
||||
NULL, /* setattrofunc tp_setattro; */
|
||||
|
||||
/* Functions to access object as input/output buffer */
|
||||
NULL, /* PyBufferProcs *tp_as_buffer; */
|
||||
|
||||
/*** Flags to define presence of optional/expanded features ***/
|
||||
Py_TPFLAGS_DEFAULT, /* long tp_flags; */
|
||||
|
||||
NULL, /* char *tp_doc; Documentation string */
|
||||
/*** Assigned meaning in release 2.0 ***/
|
||||
/* call function for all accessible objects */
|
||||
NULL, /* traverseproc tp_traverse; */
|
||||
|
||||
/* delete references to contained objects */
|
||||
NULL, /* inquiry tp_clear; */
|
||||
|
||||
/*** Assigned meaning in release 2.1 ***/
|
||||
/*** rich comparisons ***/
|
||||
NULL, /* richcmpfunc tp_richcompare; */
|
||||
|
||||
/*** weak reference enabler ***/
|
||||
0, /* long tp_weaklistoffset; */
|
||||
|
||||
/*** Added in release 2.2 ***/
|
||||
/* Iterators */
|
||||
NULL, /* getiterfunc tp_iter; */
|
||||
NULL, /* iternextfunc tp_iternext; */
|
||||
|
||||
/*** Attribute descriptor and subclassing stuff ***/
|
||||
Key_methods, /* struct PyMethodDef *tp_methods; */
|
||||
NULL, /* struct PyMemberDef *tp_members; */
|
||||
BPy_Key_getsetters, /* struct PyGetSetDef *tp_getset; */
|
||||
NULL, /* struct _typeobject *tp_base; */
|
||||
NULL, /* PyObject *tp_dict; */
|
||||
NULL, /* descrgetfunc tp_descr_get; */
|
||||
NULL, /* descrsetfunc tp_descr_set; */
|
||||
0, /* long tp_dictoffset; */
|
||||
NULL, /* initproc tp_init; */
|
||||
NULL, /* allocfunc tp_alloc; */
|
||||
NULL, /* newfunc tp_new; */
|
||||
/* Low-level free-memory routine */
|
||||
NULL, /* freefunc tp_free; */
|
||||
/* For PyObject_IS_GC */
|
||||
NULL, /* inquiry tp_is_gc; */
|
||||
NULL, /* PyObject *tp_bases; */
|
||||
/* method resolution order */
|
||||
NULL, /* PyObject *tp_mro; */
|
||||
NULL, /* PyObject *tp_cache; */
|
||||
NULL, /* PyObject *tp_subclasses; */
|
||||
NULL, /* PyObject *tp_weaklist; */
|
||||
NULL
|
||||
};
|
||||
|
||||
PyTypeObject KeyBlock_Type = {
|
||||
PyObject_HEAD_INIT( NULL ) 0, /*ob_size */
|
||||
"Blender KeyBlock", /*tp_name */
|
||||
sizeof( BPy_KeyBlock ), /*tp_basicsize */
|
||||
0, /*tp_itemsize */
|
||||
/* methods */
|
||||
( destructor ) KeyBlock_dealloc,/* destructor tp_dealloc; */
|
||||
( printfunc ) 0, /*tp_print */
|
||||
( getattrfunc ) 0, /*tp_getattr */
|
||||
( setattrfunc ) 0, /*tp_setattr */
|
||||
( cmpfunc) KeyBlock_compare, /*tp_compare*/
|
||||
( reprfunc ) KeyBlock_repr, /* tp_repr */
|
||||
/* Method suites for standard classes */
|
||||
|
||||
NULL, /* PyNumberMethods *tp_as_number; */
|
||||
NULL, /* PySequenceMethods *tp_as_sequence; */
|
||||
NULL, /* PyMappingMethods *tp_as_mapping; */
|
||||
|
||||
/* More standard operations (here for binary compatibility) */
|
||||
|
||||
NULL, /* hashfunc tp_hash; */
|
||||
NULL, /* ternaryfunc tp_call; */
|
||||
NULL, /* reprfunc tp_str; */
|
||||
NULL, /* getattrofunc tp_getattro; */
|
||||
NULL, /* setattrofunc tp_setattro; */
|
||||
|
||||
/* Functions to access object as input/output buffer */
|
||||
NULL, /* PyBufferProcs *tp_as_buffer; */
|
||||
|
||||
/*** Flags to define presence of optional/expanded features ***/
|
||||
Py_TPFLAGS_DEFAULT, /* long tp_flags; */
|
||||
|
||||
NULL, /* char *tp_doc; Documentation string */
|
||||
/*** Assigned meaning in release 2.0 ***/
|
||||
/* call function for all accessible objects */
|
||||
NULL, /* traverseproc tp_traverse; */
|
||||
|
||||
/* delete references to contained objects */
|
||||
NULL, /* inquiry tp_clear; */
|
||||
|
||||
/*** Assigned meaning in release 2.1 ***/
|
||||
/*** rich comparisons ***/
|
||||
NULL, /* richcmpfunc tp_richcompare; */
|
||||
|
||||
/*** weak reference enabler ***/
|
||||
0, /* long tp_weaklistoffset; */
|
||||
|
||||
/*** Added in release 2.2 ***/
|
||||
/* Iterators */
|
||||
NULL, /* getiterfunc tp_iter; */
|
||||
NULL, /* iternextfunc tp_iternext; */
|
||||
|
||||
/*** Attribute descriptor and subclassing stuff ***/
|
||||
KeyBlock_methods, /* struct PyMethodDef *tp_methods; */
|
||||
NULL, /* struct PyMemberDef *tp_members; */
|
||||
BPy_KeyBlock_getsetters, /* struct PyGetSetDef *tp_getset; */
|
||||
NULL, /* struct _typeobject *tp_base; */
|
||||
NULL, /* PyObject *tp_dict; */
|
||||
NULL, /* descrgetfunc tp_descr_get; */
|
||||
NULL, /* descrsetfunc tp_descr_set; */
|
||||
0, /* long tp_dictoffset; */
|
||||
NULL, /* initproc tp_init; */
|
||||
NULL, /* allocfunc tp_alloc; */
|
||||
NULL, /* newfunc tp_new; */
|
||||
/* Low-level free-memory routine */
|
||||
NULL, /* freefunc tp_free; */
|
||||
/* For PyObject_IS_GC */
|
||||
NULL, /* inquiry tp_is_gc; */
|
||||
NULL, /* PyObject *tp_bases; */
|
||||
/* method resolution order */
|
||||
NULL, /* PyObject *tp_mro; */
|
||||
NULL, /* PyObject *tp_cache; */
|
||||
NULL, /* PyObject *tp_subclasses; */
|
||||
NULL, /* PyObject *tp_weaklist; */
|
||||
NULL
|
||||
};
|
||||
|
||||
PyObject *Key_CreatePyObject( Key * blenkey )
|
||||
{
|
||||
BPy_Key *bpykey = PyObject_NEW( BPy_Key, &Key_Type );
|
||||
/* blenkey may be NULL so be careful */
|
||||
bpykey->key = blenkey;
|
||||
return ( PyObject * ) bpykey;
|
||||
}
|
||||
|
||||
static void Key_dealloc( BPy_Key * self )
|
||||
{
|
||||
PyObject_DEL( self );
|
||||
}
|
||||
|
||||
static int Key_compare( BPy_Key * a, BPy_Key * b )
|
||||
{
|
||||
return ( a->key == b->key ) ? 0 : -1;
|
||||
}
|
||||
|
||||
static PyObject *Key_repr( BPy_Key * self )
|
||||
{
|
||||
return PyString_FromFormat( "[Key \"%s\"]", self->key->id.name + 2 );
|
||||
}
|
||||
|
||||
static PyObject *Key_getIpo( BPy_Key * self )
|
||||
{
|
||||
if (self->key->ipo)
|
||||
return Ipo_CreatePyObject( self->key->ipo );
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
static int Key_setIpo( BPy_Key * self, PyObject * value )
|
||||
{
|
||||
return GenericLib_assignData(value, (void **) &self->key->ipo, 0, 1, ID_IP, ID_KE);
|
||||
}
|
||||
|
||||
static PyObject *Key_getRelative( BPy_Key * self )
|
||||
{
|
||||
if( self->key->type == KEY_RELATIVE )
|
||||
Py_RETURN_TRUE;
|
||||
else
|
||||
Py_RETURN_FALSE;
|
||||
}
|
||||
|
||||
static int Key_setRelative( BPy_Key * self, PyObject * value )
|
||||
{
|
||||
int param = PyObject_IsTrue( value );
|
||||
if( param == -1 )
|
||||
return EXPP_ReturnIntError( PyExc_TypeError,
|
||||
"expected True/False or 0/1" );
|
||||
|
||||
if( param )
|
||||
self->key->type = KEY_RELATIVE;
|
||||
else
|
||||
self->key->type = KEY_NORMAL;
|
||||
allqueue(REDRAWIPO, 0);
|
||||
allspace(REMAKEIPO, 0);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static PyObject *Key_getType( BPy_Key * self )
|
||||
{
|
||||
int idcode;
|
||||
int type = -1;
|
||||
|
||||
idcode = GS( self->key->from->name );
|
||||
|
||||
switch( idcode ) {
|
||||
case ID_ME:
|
||||
type = KEY_TYPE_MESH;
|
||||
break;
|
||||
case ID_CU:
|
||||
type = KEY_TYPE_CURVE;
|
||||
break;
|
||||
case ID_LT:
|
||||
type = KEY_TYPE_LATTICE;
|
||||
break;
|
||||
}
|
||||
|
||||
return PyInt_FromLong( type );
|
||||
}
|
||||
|
||||
static PyObject *Key_getBlocks( BPy_Key * self )
|
||||
{
|
||||
Key *key = self->key;
|
||||
KeyBlock *kb;
|
||||
int i=0;
|
||||
PyObject *l = PyList_New( BLI_countlist( &(key->block)) );
|
||||
|
||||
for (kb = key->block.first; kb; kb = kb->next, i++)
|
||||
PyList_SET_ITEM( l, i, KeyBlock_CreatePyObject( kb, key ) );
|
||||
|
||||
return l;
|
||||
}
|
||||
|
||||
static PyObject *Key_getValue( BPy_Key * self )
|
||||
{
|
||||
BPy_Key *k = ( BPy_Key * ) self;
|
||||
|
||||
return PyFloat_FromDouble( k->key->curval );
|
||||
}
|
||||
|
||||
/* ------------ Key Block Functions -------------- */
|
||||
PyObject *KeyBlock_CreatePyObject( KeyBlock * keyblock, Key *parentKey )
|
||||
{
|
||||
BPy_KeyBlock *bpykb = PyObject_NEW( BPy_KeyBlock, &KeyBlock_Type );
|
||||
bpykb->key = parentKey;
|
||||
bpykb->keyblock = keyblock; /* keyblock maye be NULL, thats ok */
|
||||
return ( PyObject * ) bpykb;
|
||||
}
|
||||
|
||||
static PyObject *KeyBlock_getCurval( BPy_KeyBlock * self ) {
|
||||
return PyFloat_FromDouble( self->keyblock->curval );
|
||||
}
|
||||
|
||||
static PyObject *KeyBlock_getName( BPy_KeyBlock * self ) {
|
||||
return PyString_FromString(self->keyblock->name);
|
||||
}
|
||||
|
||||
static PyObject *KeyBlock_getPos( BPy_KeyBlock * self ){
|
||||
return PyFloat_FromDouble( self->keyblock->pos );
|
||||
}
|
||||
|
||||
static PyObject *KeyBlock_getSlidermin( BPy_KeyBlock * self ){
|
||||
return PyFloat_FromDouble( self->keyblock->slidermin );
|
||||
}
|
||||
|
||||
static PyObject *KeyBlock_getSlidermax( BPy_KeyBlock * self ){
|
||||
return PyFloat_FromDouble( self->keyblock->slidermax );
|
||||
}
|
||||
|
||||
static PyObject *KeyBlock_getVgroup( BPy_KeyBlock * self ){
|
||||
return PyString_FromString(self->keyblock->vgroup);
|
||||
}
|
||||
|
||||
static int KeyBlock_setName( BPy_KeyBlock * self, PyObject * args ){
|
||||
char* text = NULL;
|
||||
|
||||
text = PyString_AsString ( args );
|
||||
if( !text )
|
||||
return EXPP_ReturnIntError( PyExc_TypeError,
|
||||
"expected string argument" );
|
||||
strncpy( self->keyblock->name, text , 32);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int KeyBlock_setVgroup( BPy_KeyBlock * self, PyObject * args ){
|
||||
char* text = NULL;
|
||||
|
||||
text = PyString_AsString ( args );
|
||||
if( !text )
|
||||
return EXPP_ReturnIntError( PyExc_TypeError,
|
||||
"expected string argument" );
|
||||
strncpy( self->keyblock->vgroup, text , 32);
|
||||
|
||||
return 0;
|
||||
}
|
||||
static int KeyBlock_setSlidermin( BPy_KeyBlock * self, PyObject * args ){
|
||||
return EXPP_setFloatClamped ( args, &self->keyblock->slidermin,
|
||||
-10.0f,
|
||||
10.0f );
|
||||
}
|
||||
static int KeyBlock_setSlidermax( BPy_KeyBlock * self, PyObject * args ){
|
||||
return EXPP_setFloatClamped ( args, &self->keyblock->slidermax,
|
||||
-10.0f,
|
||||
10.0f );
|
||||
}
|
||||
|
||||
static void KeyBlock_dealloc( BPy_KeyBlock * self )
|
||||
{
|
||||
PyObject_DEL( self );
|
||||
}
|
||||
|
||||
static int KeyBlock_compare( BPy_KeyBlock * a, BPy_KeyBlock * b )
|
||||
{
|
||||
return ( a->keyblock == b->keyblock ) ? 0 : -1;
|
||||
}
|
||||
|
||||
static PyObject *KeyBlock_repr( BPy_KeyBlock * self )
|
||||
{
|
||||
return PyString_FromFormat( "[KeyBlock \"%s\"]", self->keyblock->name );
|
||||
}
|
||||
|
||||
|
||||
static Curve *find_curve( Key *key )
|
||||
{
|
||||
Curve *cu;
|
||||
|
||||
if( !key )
|
||||
return NULL;
|
||||
|
||||
for( cu = G.main->curve.first; cu; cu = cu->id.next ) {
|
||||
if( cu->key == key )
|
||||
break;
|
||||
}
|
||||
return cu;
|
||||
}
|
||||
|
||||
static PyObject *KeyBlock_getData( PyObject * self )
|
||||
{
|
||||
/* If this is a mesh key, data is an array of MVert coords.
|
||||
If lattice, data is an array of BPoint coords
|
||||
If curve, data is an array of BezTriple or BPoint */
|
||||
|
||||
char *datap;
|
||||
int datasize;
|
||||
int idcode;
|
||||
int i;
|
||||
Curve *cu;
|
||||
Nurb* nu;
|
||||
PyObject *l;
|
||||
BPy_KeyBlock *kb = ( BPy_KeyBlock * ) self;
|
||||
Key *key = kb->key;
|
||||
|
||||
if( !kb->keyblock->data ) {
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
l = PyList_New( kb->keyblock->totelem );
|
||||
if( !l )
|
||||
return EXPP_ReturnPyObjError( PyExc_MemoryError,
|
||||
"PyList_New() failed" );
|
||||
|
||||
idcode = GS( key->from->name );
|
||||
|
||||
switch(idcode) {
|
||||
case ID_ME:
|
||||
|
||||
for (i=0, datap = kb->keyblock->data; i<kb->keyblock->totelem; i++) {
|
||||
PyObject *vec = newVectorObject((float*)datap, 3, Py_WRAP);
|
||||
|
||||
if (!vec) return EXPP_ReturnPyObjError( PyExc_MemoryError,
|
||||
"could not allocate memory for Blender.Mathutils.Vector wrapper!" );
|
||||
|
||||
PyList_SetItem(l, i, vec);
|
||||
datap += kb->key->elemsize;
|
||||
}
|
||||
break;
|
||||
|
||||
case ID_CU:
|
||||
cu = find_curve ( key );
|
||||
if( !cu )
|
||||
return EXPP_ReturnPyObjError( PyExc_RuntimeError,
|
||||
"key is no linked to any curve!" );
|
||||
datasize = count_curveverts(&cu->nurb);
|
||||
nu = cu->nurb.first;
|
||||
if( nu->bezt ) {
|
||||
datasize /= 3;
|
||||
Py_DECREF (l);
|
||||
l = PyList_New( datasize );
|
||||
for( i = 0, datap = kb->keyblock->data; i < datasize;
|
||||
i++, datap += sizeof(float)*3*4) {
|
||||
PyObject *tuple = PyTuple_New(4), *vec;
|
||||
float *vecs = (float*)datap;
|
||||
|
||||
if (!tuple) return EXPP_ReturnPyObjError( PyExc_MemoryError,
|
||||
"PyTuple_New() failed!" );
|
||||
|
||||
vec = newVectorObject(vecs, 3, Py_WRAP);
|
||||
if (!vec) return EXPP_ReturnPyObjError( PyExc_MemoryError,
|
||||
"Could not allocate memory for Blender.Mathutils.Vector wrapper!" );
|
||||
|
||||
PyTuple_SET_ITEM( tuple, 0, vec);
|
||||
|
||||
vecs += 3;
|
||||
vec = newVectorObject(vecs, 3, Py_WRAP);
|
||||
if (!vec) return EXPP_ReturnPyObjError( PyExc_MemoryError,
|
||||
"Could not allocate memory for Blender.Mathutils.Vector wrapper!" );
|
||||
|
||||
PyTuple_SET_ITEM( tuple, 1, vec);
|
||||
|
||||
vecs += 3;
|
||||
vec = newVectorObject(vecs, 3, Py_WRAP);
|
||||
if (!vec) return EXPP_ReturnPyObjError( PyExc_MemoryError,
|
||||
"Could not allocate memory for Blender.Mathutils.Vector wrapper!" );
|
||||
|
||||
PyTuple_SET_ITEM( tuple, 2, vec);
|
||||
|
||||
/*tilts*/
|
||||
vecs += 3;
|
||||
vec = newVectorObject(vecs, 3, Py_WRAP);
|
||||
if (!vec) return EXPP_ReturnPyObjError( PyExc_MemoryError,
|
||||
"Could not allocate memory for Blender.Mathutils.Vector wrapper!" );
|
||||
|
||||
PyTuple_SET_ITEM( tuple, 3, vec);
|
||||
|
||||
PyList_SetItem( l, i, tuple );
|
||||
}
|
||||
} else {
|
||||
for( i = 0, datap = kb->keyblock->data; i < datasize;
|
||||
i++, datap += kb->key->elemsize ) {
|
||||
PyObject *vec = newVectorObject((float*)datap, 4, Py_WRAP);
|
||||
if (!vec) return EXPP_ReturnPyObjError( PyExc_MemoryError,
|
||||
"could not allocate memory for Blender.Mathutils.Vector wrapper!" );
|
||||
|
||||
PyList_SetItem( l, i, vec );
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case ID_LT:
|
||||
for( i = 0, datap = kb->keyblock->data; i < kb->keyblock->totelem;
|
||||
i++, datap += kb->key->elemsize ) {
|
||||
PyObject *vec = newVectorObject((float*)datap, 3, Py_WRAP);
|
||||
if (!vec) return EXPP_ReturnPyObjError( PyExc_MemoryError,
|
||||
"Could not allocate memory for Blender.Mathutils.Vector wrapper!" );
|
||||
|
||||
PyList_SetItem( l, i, vec );
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
return l;
|
||||
}
|
||||
|
||||
static PyObject *M_Key_Get( PyObject * self, PyObject * args )
|
||||
{
|
||||
char *name = NULL;
|
||||
Key *key_iter;
|
||||
char error_msg[64];
|
||||
int i;
|
||||
|
||||
if( !PyArg_ParseTuple( args, "|s", &name ) )
|
||||
return ( EXPP_ReturnPyObjError( PyExc_TypeError,
|
||||
"expected string argument (or nothing)" ) );
|
||||
|
||||
if ( name ) {
|
||||
for (key_iter = G.main->key.first; key_iter;
|
||||
key_iter=key_iter->id.next) {
|
||||
if (strcmp ( key_iter->id.name + 2, name ) == 0 ) {
|
||||
return Key_CreatePyObject( key_iter );
|
||||
}
|
||||
}
|
||||
|
||||
PyOS_snprintf( error_msg, sizeof( error_msg ),
|
||||
"Key \"%s\" not found", name );
|
||||
return EXPP_ReturnPyObjError ( PyExc_NameError, error_msg );
|
||||
|
||||
} else {
|
||||
|
||||
PyObject *keylist;
|
||||
|
||||
keylist = PyList_New( BLI_countlist( &( G.main->key ) ) );
|
||||
|
||||
for ( i=0, key_iter = G.main->key.first; key_iter;
|
||||
key_iter=key_iter->id.next, i++ ) {
|
||||
PyList_SetItem(keylist, i, Key_CreatePyObject(key_iter));
|
||||
}
|
||||
return keylist;
|
||||
}
|
||||
}
|
||||
|
||||
struct PyMethodDef M_Key_methods[] = {
|
||||
{"Get", M_Key_Get, METH_VARARGS, "Get a key or all key names"},
|
||||
{NULL, NULL, 0, NULL}
|
||||
};
|
||||
|
||||
static PyObject *M_Key_TypesDict( void )
|
||||
{
|
||||
PyObject *T = PyConstant_New( );
|
||||
|
||||
if( T ) {
|
||||
BPy_constant *d = ( BPy_constant * ) T;
|
||||
|
||||
PyConstant_Insert( d, "MESH", PyInt_FromLong( KEY_TYPE_MESH ) );
|
||||
PyConstant_Insert( d, "CURVE", PyInt_FromLong( KEY_TYPE_CURVE ) );
|
||||
PyConstant_Insert( d, "LATTICE", PyInt_FromLong( KEY_TYPE_LATTICE ) );
|
||||
}
|
||||
|
||||
return T;
|
||||
}
|
||||
|
||||
PyObject *Key_Init( void )
|
||||
{
|
||||
PyObject *submodule;
|
||||
PyObject *Types = NULL;
|
||||
|
||||
if( PyType_Ready( &Key_Type ) < 0 || PyType_Ready( &KeyBlock_Type ) < 0 )
|
||||
return NULL;
|
||||
|
||||
submodule =
|
||||
Py_InitModule3( "Blender.Key", M_Key_methods, "Key module" );
|
||||
|
||||
Types = M_Key_TypesDict( );
|
||||
if( Types )
|
||||
PyModule_AddObject( submodule, "Types", Types );
|
||||
|
||||
return submodule;
|
||||
}
|
||||
|
||||
@@ -1,65 +0,0 @@
|
||||
/*
|
||||
* $Id$
|
||||
*
|
||||
* ***** 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*
|
||||
* The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This is a new part of Blender.
|
||||
*
|
||||
* Contributor(s): Pontus Lidman
|
||||
*
|
||||
* ***** END GPL LICENSE BLOCK *****
|
||||
*/
|
||||
|
||||
#ifndef EXPP_KEY_H
|
||||
#define EXPP_KEY_H
|
||||
|
||||
#include "Python.h"
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
|
||||
#include <DNA_key_types.h>
|
||||
#include <DNA_curve_types.h>
|
||||
|
||||
extern PyTypeObject Key_Type;
|
||||
extern PyTypeObject KeyBlock_Type;
|
||||
|
||||
typedef struct {
|
||||
PyObject_HEAD /* required python macro */
|
||||
Key * key; /* libdata must be second */
|
||||
/* Object *object;*/ /* for vertex grouping info, since it's stored on the object */
|
||||
/*PyObject *keyBlock;*/
|
||||
/*PyObject *ipo;*/
|
||||
} BPy_Key;
|
||||
|
||||
typedef struct {
|
||||
PyObject_HEAD /* required python macro */
|
||||
Key *key;
|
||||
KeyBlock * keyblock;
|
||||
/* Object *object;*/ /* for vertex grouping info, since it's stored on the object */
|
||||
} BPy_KeyBlock;
|
||||
|
||||
PyObject *Key_CreatePyObject( Key * k );
|
||||
PyObject *KeyBlock_CreatePyObject( KeyBlock * k, Key *parentKey );
|
||||
|
||||
PyObject *Key_Init( void );
|
||||
|
||||
#endif /* EXPP_KEY_H */
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,58 +0,0 @@
|
||||
/*
|
||||
* $Id$
|
||||
*
|
||||
* ***** 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*
|
||||
* The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This is a new part of Blender.
|
||||
*
|
||||
* Contributor(s): Willian P. Germano, Nathan Letwory
|
||||
*
|
||||
* ***** END GPL LICENSE BLOCK *****
|
||||
*/
|
||||
|
||||
#ifndef EXPP_LAMP_H
|
||||
#define EXPP_LAMP_H
|
||||
|
||||
#include <Python.h>
|
||||
#include "DNA_lamp_types.h"
|
||||
#include "rgbTuple.h"
|
||||
|
||||
extern PyTypeObject Lamp_Type;
|
||||
|
||||
#define BPy_Lamp_Check(v) \
|
||||
((v)->ob_type == &Lamp_Type) /* for type checking */
|
||||
|
||||
/* Python BPy_Lamp structure definition */
|
||||
typedef struct {
|
||||
PyObject_HEAD /* required py macro */
|
||||
Lamp * lamp; /* libdata must be second */
|
||||
BPy_rgbTuple *color;
|
||||
} BPy_Lamp;
|
||||
|
||||
|
||||
/*
|
||||
* prototypes
|
||||
*/
|
||||
|
||||
PyObject *Lamp_Init( void );
|
||||
PyObject *Lamp_CreatePyObject( struct Lamp *lamp );
|
||||
Lamp *Lamp_FromPyObject( PyObject * pyobj );
|
||||
|
||||
#endif /* EXPP_LAMP_H */
|
||||
@@ -1,810 +0,0 @@
|
||||
/*
|
||||
* $Id$
|
||||
*
|
||||
* ***** 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*
|
||||
* The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This is a new part of Blender.
|
||||
*
|
||||
* Contributor(s): Joseph Gilbert
|
||||
*
|
||||
* ***** END GPL LICENSE BLOCK *****
|
||||
*/
|
||||
|
||||
#include "Lattice.h" /*This must come first*/
|
||||
|
||||
#include "BKE_utildefines.h"
|
||||
#include "BKE_main.h"
|
||||
#include "BKE_global.h"
|
||||
#include "BKE_library.h"
|
||||
#include "BKE_lattice.h"
|
||||
#include "BLI_blenlib.h"
|
||||
#include "DNA_object_types.h"
|
||||
#include "DNA_key_types.h"
|
||||
#include "DNA_mesh_types.h"
|
||||
#include "DNA_meshdata_types.h"
|
||||
#include "DNA_curve_types.h"
|
||||
#include "DNA_scene_types.h"
|
||||
#include "BIF_editkey.h"
|
||||
#include "BIF_editdeform.h"
|
||||
#include "BIF_space.h"
|
||||
#include "blendef.h"
|
||||
#include "gen_utils.h"
|
||||
#include "gen_library.h"
|
||||
|
||||
#include "Key.h"
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Python API function prototypes for the Lattice module. */
|
||||
/*****************************************************************************/
|
||||
static PyObject *M_Lattice_New( PyObject * self, PyObject * args );
|
||||
static PyObject *M_Lattice_Get( PyObject * self, PyObject * args );
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Lattice Module strings */
|
||||
/* The following string definitions are used for documentation strings. */
|
||||
/* In Python these will be written to the console when doing a */
|
||||
/* Blender.Lattice.__doc__ */
|
||||
/*****************************************************************************/
|
||||
static char M_Lattice_doc[] = "The Blender Lattice module\n\n";
|
||||
|
||||
static char M_Lattice_New_doc[] = "() - return a new Lattice object";
|
||||
|
||||
static char M_Lattice_Get_doc[] = "() - get a Lattice from blender";
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Python method structure definition for Blender.Lattice module: */
|
||||
/*****************************************************************************/
|
||||
struct PyMethodDef M_Lattice_methods[] = {
|
||||
{"New", ( PyCFunction ) M_Lattice_New, METH_VARARGS,
|
||||
M_Lattice_New_doc},
|
||||
{"Get", ( PyCFunction ) M_Lattice_Get, METH_VARARGS,
|
||||
M_Lattice_Get_doc},
|
||||
{NULL, NULL, 0, NULL}
|
||||
};
|
||||
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Lattice Strings */
|
||||
/* The following string definitions are used for documentation strings. */
|
||||
/* In Python these will be written to the console when doing a */
|
||||
/* Blender.Lattice.__doc__ */
|
||||
/*****************************************************************************/
|
||||
static char Lattice_getName_doc[] = "() - Return Lattice Object name";
|
||||
|
||||
static char Lattice_setName_doc[] = "(str) - Change Lattice Object name";
|
||||
|
||||
static char Lattice_setPartitions_doc[] =
|
||||
"(str) - Set the number of Partitions in x,y,z";
|
||||
|
||||
static char Lattice_getPartitions_doc[] =
|
||||
"(str) - Get the number of Partitions in x,y,z";
|
||||
|
||||
static char Lattice_getKey_doc[] =
|
||||
"() - Get the Key object attached to this Lattice";
|
||||
|
||||
static char Lattice_setKeyTypes_doc[] =
|
||||
"(str) - Set the key types for x,y,z dimensions";
|
||||
|
||||
static char Lattice_getKeyTypes_doc[] =
|
||||
"(str) - Get the key types for x,y,z dimensions";
|
||||
|
||||
static char Lattice_setMode_doc[] = "(str) - Make an outside or grid lattice";
|
||||
|
||||
static char Lattice_getMode_doc[] = "(str) - Get lattice mode type";
|
||||
|
||||
static char Lattice_setPoint_doc[] =
|
||||
"(str) - Set the coordinates of a point on the lattice";
|
||||
|
||||
static char Lattice_getPoint_doc[] =
|
||||
"(str) - Get the coordinates of a point on the lattice";
|
||||
|
||||
static char Lattice_insertKey_doc[] =
|
||||
"(str) - Set a new key for the lattice at specified frame";
|
||||
|
||||
static char Lattice_copy_doc[] =
|
||||
"() - Return a copy of the lattice.";
|
||||
|
||||
//***************************************************************************
|
||||
// Function: Lattice_CreatePyObject
|
||||
//***************************************************************************
|
||||
PyObject *Lattice_CreatePyObject( Lattice * lt )
|
||||
{
|
||||
BPy_Lattice *pyLat;
|
||||
|
||||
pyLat = ( BPy_Lattice * ) PyObject_NEW( BPy_Lattice, &Lattice_Type );
|
||||
|
||||
if( !pyLat )
|
||||
return EXPP_ReturnPyObjError( PyExc_MemoryError,
|
||||
"couldn't create BPy_Lattice PyObject" );
|
||||
|
||||
pyLat->lattice = lt;
|
||||
|
||||
return ( PyObject * ) pyLat;
|
||||
}
|
||||
|
||||
//***************************************************************************
|
||||
// Function: Lattice_FromPyObject
|
||||
//***************************************************************************
|
||||
|
||||
Lattice *Lattice_FromPyObject( PyObject * pyobj )
|
||||
{
|
||||
return ( ( BPy_Lattice * ) pyobj )->lattice;
|
||||
}
|
||||
|
||||
//***************************************************************************
|
||||
// Function: M_Lattice_New
|
||||
// Python equivalent: Blender.Lattice.New
|
||||
//***************************************************************************
|
||||
static PyObject *M_Lattice_New( PyObject * self, PyObject * args )
|
||||
{
|
||||
char *name = NULL;
|
||||
Lattice *bl_Lattice; // blender Lattice object
|
||||
PyObject *py_Lattice; // python wrapper
|
||||
|
||||
if( !PyArg_ParseTuple( args, "|s", &name ) )
|
||||
return EXPP_ReturnPyObjError( PyExc_AttributeError,
|
||||
"expected string and int arguments (or nothing)" );
|
||||
|
||||
bl_Lattice = add_lattice( "Lattice" );
|
||||
|
||||
if( bl_Lattice ) {
|
||||
bl_Lattice->id.us = 0;
|
||||
py_Lattice = Lattice_CreatePyObject( bl_Lattice );
|
||||
} else
|
||||
return EXPP_ReturnPyObjError( PyExc_RuntimeError,
|
||||
"couldn't create Lattice Object in Blender" );
|
||||
if( !py_Lattice )
|
||||
return EXPP_ReturnPyObjError( PyExc_MemoryError,
|
||||
"couldn't create Lattice Object wrapper" );
|
||||
|
||||
if( name )
|
||||
rename_id( &bl_Lattice->id, name );
|
||||
|
||||
return py_Lattice;
|
||||
}
|
||||
|
||||
//***************************************************************************
|
||||
// Function: M_Lattice_Get
|
||||
// Python equivalent: Blender.Lattice.Get
|
||||
//***************************************************************************
|
||||
static PyObject *M_Lattice_Get( PyObject * self, PyObject * args )
|
||||
{
|
||||
char *name = NULL;
|
||||
Lattice *lat_iter;
|
||||
|
||||
if( !PyArg_ParseTuple( args, "|s", &name ) )
|
||||
return ( EXPP_ReturnPyObjError( PyExc_TypeError,
|
||||
"expected string argument (or nothing)" ) );
|
||||
|
||||
lat_iter = G.main->latt.first;
|
||||
|
||||
if( name ) { /* (name) - Search Lattice by name */
|
||||
|
||||
PyObject *wanted_lat = NULL;
|
||||
|
||||
while( ( lat_iter ) && ( wanted_lat == NULL ) ) {
|
||||
if( strcmp( name, lat_iter->id.name + 2 ) == 0 ) {
|
||||
wanted_lat =
|
||||
Lattice_CreatePyObject( lat_iter );
|
||||
}
|
||||
|
||||
lat_iter = lat_iter->id.next;
|
||||
}
|
||||
|
||||
if( wanted_lat == NULL ) { /* Requested Lattice doesn't exist */
|
||||
char error_msg[64];
|
||||
PyOS_snprintf( error_msg, sizeof( error_msg ),
|
||||
"Lattice \"%s\" not found", name );
|
||||
return ( EXPP_ReturnPyObjError
|
||||
( PyExc_NameError, error_msg ) );
|
||||
}
|
||||
|
||||
return wanted_lat;
|
||||
}
|
||||
|
||||
else { /* () - return a list of all Lattices in the scene */
|
||||
int index = 0;
|
||||
PyObject *latlist, *pyobj;
|
||||
|
||||
latlist = PyList_New( BLI_countlist( &( G.main->latt ) ) );
|
||||
|
||||
if( latlist == NULL )
|
||||
return ( EXPP_ReturnPyObjError( PyExc_MemoryError,
|
||||
"couldn't create PyList" ) );
|
||||
|
||||
while( lat_iter ) {
|
||||
pyobj = Lattice_CreatePyObject( lat_iter );
|
||||
|
||||
if( !pyobj ) {
|
||||
Py_DECREF(latlist);
|
||||
return ( EXPP_ReturnPyObjError
|
||||
( PyExc_MemoryError,
|
||||
"couldn't create PyString" ) );
|
||||
}
|
||||
PyList_SET_ITEM( latlist, index, pyobj );
|
||||
|
||||
lat_iter = lat_iter->id.next;
|
||||
index++;
|
||||
}
|
||||
|
||||
return ( latlist );
|
||||
}
|
||||
}
|
||||
|
||||
//***************************************************************************
|
||||
// Function: Lattice_Init
|
||||
//***************************************************************************
|
||||
PyObject *Lattice_Init( void )
|
||||
{
|
||||
PyObject *mod;
|
||||
PyObject *dict;
|
||||
|
||||
if( PyType_Ready( &Lattice_Type ) < 0 )
|
||||
return NULL;
|
||||
|
||||
mod = Py_InitModule3( "Blender.Lattice", M_Lattice_methods,
|
||||
M_Lattice_doc );
|
||||
|
||||
dict = PyModule_GetDict( mod );
|
||||
|
||||
//Module dictionary
|
||||
#define EXPP_ADDCONST(x) EXPP_dict_set_item_str(dict, #x, PyInt_FromLong(LT_##x))
|
||||
EXPP_ADDCONST( GRID );
|
||||
EXPP_ADDCONST( OUTSIDE );
|
||||
|
||||
#undef EXPP_ADDCONST
|
||||
#define EXPP_ADDCONST(x) EXPP_dict_set_item_str(dict, #x, PyInt_FromLong(KEY_##x))
|
||||
EXPP_ADDCONST( LINEAR );
|
||||
EXPP_ADDCONST( CARDINAL );
|
||||
EXPP_ADDCONST( BSPLINE );
|
||||
|
||||
return ( mod );
|
||||
}
|
||||
|
||||
static PyObject *Lattice_setPartitions( BPy_Lattice * self, PyObject * args )
|
||||
{
|
||||
int x = 0;
|
||||
int y = 0;
|
||||
int z = 0;
|
||||
Lattice *bl_Lattice;
|
||||
|
||||
if( !PyArg_ParseTuple( args, "iii", &x, &y, &z ) )
|
||||
return ( EXPP_ReturnPyObjError( PyExc_TypeError,
|
||||
"expected int,int,int argument" ) );
|
||||
|
||||
bl_Lattice = self->lattice;
|
||||
|
||||
if( x < 2 || y < 2 || z < 2 )
|
||||
return ( EXPP_ReturnPyObjError( PyExc_RuntimeError,
|
||||
"partition values must be 2 or greater" ) );
|
||||
|
||||
resizelattice(bl_Lattice, x, y, z, NULL);
|
||||
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
static PyObject *Lattice_getPartitions( BPy_Lattice * self )
|
||||
{
|
||||
Lattice *bl_Lattice;
|
||||
bl_Lattice = self->lattice;
|
||||
|
||||
return Py_BuildValue( "[i,i,i]", ( int ) bl_Lattice->pntsu,
|
||||
( int ) bl_Lattice->pntsv,
|
||||
( int ) bl_Lattice->pntsw );
|
||||
}
|
||||
|
||||
static PyObject *Lattice_getKey( BPy_Lattice * self )
|
||||
{
|
||||
Key *key = self->lattice->key;
|
||||
|
||||
if (key)
|
||||
return Key_CreatePyObject(key);
|
||||
else
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
static PyObject *Lattice_getKeyTypes( BPy_Lattice * self )
|
||||
{
|
||||
Lattice *bl_Lattice;
|
||||
char *linear = "linear";
|
||||
char *cardinal = "cardinal";
|
||||
char *bspline = "bspline";
|
||||
char *s_x = NULL, *s_y = NULL, *s_z = NULL;
|
||||
|
||||
bl_Lattice = self->lattice;
|
||||
|
||||
if( ( bl_Lattice->typeu ) == KEY_LINEAR )
|
||||
s_x = linear;
|
||||
else if( ( bl_Lattice->typeu ) == KEY_CARDINAL )
|
||||
s_x = cardinal;
|
||||
else if( ( bl_Lattice->typeu ) == KEY_BSPLINE )
|
||||
s_x = bspline;
|
||||
else
|
||||
return EXPP_ReturnPyObjError( PyExc_RuntimeError,
|
||||
"bad key type..." );
|
||||
|
||||
if( ( bl_Lattice->typev ) == KEY_LINEAR )
|
||||
s_y = linear;
|
||||
else if( ( bl_Lattice->typev ) == KEY_CARDINAL )
|
||||
s_y = cardinal;
|
||||
else if( ( bl_Lattice->typev ) == KEY_BSPLINE )
|
||||
s_y = bspline;
|
||||
else
|
||||
return EXPP_ReturnPyObjError( PyExc_RuntimeError,
|
||||
"bad key type..." );
|
||||
|
||||
if( ( bl_Lattice->typew ) == KEY_LINEAR )
|
||||
s_z = linear;
|
||||
else if( ( bl_Lattice->typew ) == KEY_CARDINAL )
|
||||
s_z = cardinal;
|
||||
else if( ( bl_Lattice->typew ) == KEY_BSPLINE )
|
||||
s_z = bspline;
|
||||
else
|
||||
return EXPP_ReturnPyObjError( PyExc_RuntimeError,
|
||||
"bad key type..." );
|
||||
|
||||
/* we made sure no s_[xyz] is NULL */
|
||||
return Py_BuildValue( "[s,s,s]", s_x, s_y, s_z );
|
||||
}
|
||||
|
||||
static PyObject *Lattice_setKeyTypes( BPy_Lattice * self, PyObject * args )
|
||||
{
|
||||
int x;
|
||||
int y;
|
||||
int z;
|
||||
Lattice *bl_Lattice;
|
||||
|
||||
if( !PyArg_ParseTuple( args, "iii", &x, &y, &z ) )
|
||||
return ( EXPP_ReturnPyObjError( PyExc_TypeError,
|
||||
"expected int,int,int argument" ) );
|
||||
|
||||
bl_Lattice = self->lattice;
|
||||
|
||||
if( x == KEY_LINEAR )
|
||||
bl_Lattice->typeu = KEY_LINEAR;
|
||||
else if( x == KEY_CARDINAL )
|
||||
bl_Lattice->typeu = KEY_CARDINAL;
|
||||
else if( x == KEY_BSPLINE )
|
||||
bl_Lattice->typeu = KEY_BSPLINE;
|
||||
else
|
||||
return EXPP_ReturnPyObjError( PyExc_TypeError,
|
||||
"type must be LINEAR, CARDINAL OR BSPLINE" );
|
||||
|
||||
if( y == KEY_LINEAR )
|
||||
bl_Lattice->typev = KEY_LINEAR;
|
||||
else if( y == KEY_CARDINAL )
|
||||
bl_Lattice->typev = KEY_CARDINAL;
|
||||
else if( y == KEY_BSPLINE )
|
||||
bl_Lattice->typev = KEY_BSPLINE;
|
||||
else
|
||||
return EXPP_ReturnPyObjError( PyExc_TypeError,
|
||||
"type must be LINEAR, CARDINAL OR BSPLINE" );
|
||||
|
||||
if( z == KEY_LINEAR )
|
||||
bl_Lattice->typew = KEY_LINEAR;
|
||||
else if( z == KEY_CARDINAL )
|
||||
bl_Lattice->typew = KEY_CARDINAL;
|
||||
else if( z == KEY_BSPLINE )
|
||||
bl_Lattice->typew = KEY_BSPLINE;
|
||||
else
|
||||
return EXPP_ReturnPyObjError( PyExc_TypeError,
|
||||
"type must be LINEAR, CARDINAL OR BSPLINE" );
|
||||
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
static PyObject *Lattice_setMode( BPy_Lattice * self, PyObject * args )
|
||||
{
|
||||
short type;
|
||||
Lattice *bl_Lattice;
|
||||
bl_Lattice = self->lattice;
|
||||
|
||||
if( !PyArg_ParseTuple( args, "h", &type ) )
|
||||
return ( EXPP_ReturnPyObjError( PyExc_TypeError,
|
||||
"expected int argument" ) );
|
||||
|
||||
if( type == LT_GRID )
|
||||
bl_Lattice->flag = LT_GRID;
|
||||
else if( type == LT_OUTSIDE ) {
|
||||
bl_Lattice->flag = LT_OUTSIDE + LT_GRID;
|
||||
outside_lattice( bl_Lattice );
|
||||
} else
|
||||
return EXPP_ReturnPyObjError( PyExc_TypeError,
|
||||
"type must be either GRID or OUTSIDE" );
|
||||
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
static PyObject *Lattice_getMode(BPy_Lattice * self)
|
||||
{
|
||||
if( self->lattice->flag == 1 )
|
||||
return PyString_FromString( "Grid" );
|
||||
else if( self->lattice->flag == 3 )
|
||||
return PyString_FromString( "Outside" );
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
static PyObject *Lattice_setPoint( BPy_Lattice * self, PyObject * args )
|
||||
{
|
||||
BPoint *bp, *bpoint;
|
||||
short size;
|
||||
Lattice *bl_Lattice;
|
||||
int index, x;
|
||||
float tempInt;
|
||||
PyObject *listObject;
|
||||
|
||||
if( !PyArg_ParseTuple
|
||||
( args, "iO!", &index, &PyList_Type, &listObject ) )
|
||||
return ( EXPP_ReturnPyObjError
|
||||
( PyExc_TypeError, "expected int & list argument" ) );
|
||||
|
||||
if( !PyList_Check( listObject ) )
|
||||
return ( EXPP_ReturnPyObjError( PyExc_TypeError,
|
||||
"2nd parameter should be a python list" ) );
|
||||
|
||||
if( !( PyList_Size( listObject ) == 3 ) )
|
||||
return ( EXPP_ReturnPyObjError( PyExc_TypeError,
|
||||
"Please pass 3 parameters in the list [x,y,z]" ) );
|
||||
|
||||
//init
|
||||
bp = 0;
|
||||
bl_Lattice = self->lattice;
|
||||
|
||||
//get bpoints
|
||||
bp = bl_Lattice->def;
|
||||
|
||||
if( bp == 0 )
|
||||
return ( EXPP_ReturnPyObjError( PyExc_AttributeError,
|
||||
"no lattice points!" ) );
|
||||
|
||||
//calculate size of lattice
|
||||
size = bl_Lattice->pntsu * bl_Lattice->pntsv * bl_Lattice->pntsw;
|
||||
|
||||
if( index < 0 || index > size )
|
||||
return ( EXPP_ReturnPyObjError( PyExc_RuntimeError,
|
||||
"index outside of lattice size!" ) );
|
||||
|
||||
//get the bpoint
|
||||
while( index ) {
|
||||
index--;
|
||||
bp++;
|
||||
}
|
||||
bpoint = bp;
|
||||
|
||||
for( x = 0; x < PyList_Size( listObject ); x++ ) {
|
||||
if( !
|
||||
( PyArg_Parse
|
||||
( ( PyList_GetItem( listObject, x ) ), "f",
|
||||
&tempInt ) ) )
|
||||
return EXPP_ReturnPyObjError( PyExc_TypeError,
|
||||
"python list integer not parseable" );
|
||||
bpoint->vec[x] = tempInt;
|
||||
}
|
||||
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
static PyObject *Lattice_getPoint( BPy_Lattice * self, PyObject * args )
|
||||
{
|
||||
BPoint *bp, *bpoint;
|
||||
short size;
|
||||
Lattice *bl_Lattice;
|
||||
int index;
|
||||
|
||||
if( !PyArg_ParseTuple( args, "i", &index ) )
|
||||
return ( EXPP_ReturnPyObjError( PyExc_TypeError,
|
||||
"expected int argument" ) );
|
||||
|
||||
//init
|
||||
bp = 0;
|
||||
bl_Lattice = self->lattice;
|
||||
|
||||
//get bpoints
|
||||
bp = bl_Lattice->def;
|
||||
|
||||
if( bp == 0 )
|
||||
return ( EXPP_ReturnPyObjError( PyExc_AttributeError,
|
||||
"no lattice points!" ) );
|
||||
|
||||
//calculate size of lattice
|
||||
size = bl_Lattice->pntsu * bl_Lattice->pntsv * bl_Lattice->pntsw;
|
||||
|
||||
if( index < 0 || index > size )
|
||||
return ( EXPP_ReturnPyObjError( PyExc_RuntimeError,
|
||||
"index outside of lattice size!" ) );
|
||||
|
||||
//get the bpoint
|
||||
while( index ) {
|
||||
index--;
|
||||
bp++;
|
||||
}
|
||||
bpoint = bp;
|
||||
|
||||
if( bpoint == 0 )
|
||||
return ( EXPP_ReturnPyObjError( PyExc_RuntimeError,
|
||||
"bpoint does not exist" ) );
|
||||
|
||||
return Py_BuildValue( "[f,f,f]", bp->vec[0], bp->vec[1], bp->vec[2] );
|
||||
}
|
||||
|
||||
static PyObject *Lattice_insertKey( BPy_Lattice * self, PyObject * args )
|
||||
{
|
||||
Lattice *lt;
|
||||
int frame = -1, oldfra = -1;
|
||||
|
||||
if( !PyArg_ParseTuple( args, "i", &frame ) )
|
||||
return ( EXPP_ReturnPyObjError( PyExc_TypeError,
|
||||
"expected int argument" ) );
|
||||
|
||||
lt = self->lattice;
|
||||
|
||||
//set the current frame
|
||||
if( frame > 0 ) {
|
||||
frame = EXPP_ClampInt( frame, 1, MAXFRAME );
|
||||
oldfra = G.scene->r.cfra;
|
||||
G.scene->r.cfra = (int)frame;
|
||||
}
|
||||
// else just use current frame, then
|
||||
// return (EXPP_ReturnPyObjError (PyExc_RuntimeError,
|
||||
// "frame value has to be greater than 0"));
|
||||
|
||||
//insert a keybock for the lattice (1=relative)
|
||||
insert_lattkey( lt , 1);
|
||||
allspace(REMAKEIPO, 0);
|
||||
|
||||
if( frame > 0 )
|
||||
G.scene->r.cfra = (int)oldfra;
|
||||
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
static PyObject *Lattice_copy( BPy_Lattice * self )
|
||||
{
|
||||
Lattice *bl_Lattice; // blender Lattice object
|
||||
PyObject *py_Lattice; // python wrapper
|
||||
|
||||
bl_Lattice = copy_lattice( self->lattice );
|
||||
bl_Lattice->id.us = 0;
|
||||
|
||||
if( bl_Lattice )
|
||||
py_Lattice = Lattice_CreatePyObject( bl_Lattice );
|
||||
else
|
||||
return EXPP_ReturnPyObjError( PyExc_RuntimeError,
|
||||
"couldn't create Lattice Object in Blender" );
|
||||
if( !py_Lattice )
|
||||
return EXPP_ReturnPyObjError( PyExc_MemoryError,
|
||||
"couldn't create Lattice Object wrapper" );
|
||||
|
||||
return py_Lattice;
|
||||
}
|
||||
|
||||
static int Lattice_compare( BPy_Lattice * a, BPy_Lattice * b )
|
||||
{
|
||||
return ( a->lattice == b->lattice ) ? 0 : -1;
|
||||
}
|
||||
|
||||
|
||||
//***************************************************************************
|
||||
// Function: Lattice_repr
|
||||
// Description: This is a callback function for the BPy_Lattice type. It
|
||||
// builds a meaninful string to represent Lattice objects.
|
||||
//***************************************************************************
|
||||
static PyObject *Lattice_repr( BPy_Lattice * self )
|
||||
{
|
||||
if( self->lattice )
|
||||
return PyString_FromFormat( "[Lattice \"%s\"]",
|
||||
self->lattice->id.name + 2 );
|
||||
else
|
||||
return PyString_FromString( "[Lattice <deleted>]" );
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Python BPy_Lattice methods table: */
|
||||
/*****************************************************************************/
|
||||
static PyMethodDef BPy_Lattice_methods[] = {
|
||||
/* name, method, flags, doc */
|
||||
{"getName", ( PyCFunction ) GenericLib_getName, METH_NOARGS,
|
||||
Lattice_getName_doc},
|
||||
{"setName", ( PyCFunction ) GenericLib_setName_with_method, METH_VARARGS,
|
||||
Lattice_setName_doc},
|
||||
{"setPartitions", ( PyCFunction ) Lattice_setPartitions, METH_VARARGS,
|
||||
Lattice_setPartitions_doc},
|
||||
{"getPartitions", ( PyCFunction ) Lattice_getPartitions, METH_NOARGS,
|
||||
Lattice_getPartitions_doc},
|
||||
{"getKey", ( PyCFunction ) Lattice_getKey, METH_NOARGS,
|
||||
Lattice_getKey_doc},
|
||||
{"setKeyTypes", ( PyCFunction ) Lattice_setKeyTypes, METH_VARARGS,
|
||||
Lattice_setKeyTypes_doc},
|
||||
{"getKeyTypes", ( PyCFunction ) Lattice_getKeyTypes, METH_NOARGS,
|
||||
Lattice_getKeyTypes_doc},
|
||||
{"setMode", ( PyCFunction ) Lattice_setMode, METH_VARARGS,
|
||||
Lattice_setMode_doc},
|
||||
{"getMode", ( PyCFunction ) Lattice_getMode, METH_NOARGS,
|
||||
Lattice_getMode_doc},
|
||||
{"setPoint", ( PyCFunction ) Lattice_setPoint, METH_VARARGS,
|
||||
Lattice_setPoint_doc},
|
||||
{"getPoint", ( PyCFunction ) Lattice_getPoint, METH_VARARGS,
|
||||
Lattice_getPoint_doc},
|
||||
{"insertKey", ( PyCFunction ) Lattice_insertKey, METH_VARARGS,
|
||||
Lattice_insertKey_doc},
|
||||
{"__copy__", ( PyCFunction ) Lattice_copy, METH_NOARGS,
|
||||
Lattice_copy_doc},
|
||||
{"copy", ( PyCFunction ) Lattice_copy, METH_NOARGS,
|
||||
Lattice_copy_doc},
|
||||
{NULL, NULL, 0, NULL}
|
||||
};
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Python attributes get/set functions: */
|
||||
/*****************************************************************************/
|
||||
static PyObject *Lattice_getWidth(BPy_Lattice * self)
|
||||
{
|
||||
return PyInt_FromLong( self->lattice->pntsu );
|
||||
}
|
||||
static PyObject *Lattice_getHeight(BPy_Lattice * self)
|
||||
{
|
||||
return PyInt_FromLong( self->lattice->pntsv );
|
||||
}
|
||||
static PyObject *Lattice_getDepth(BPy_Lattice * self)
|
||||
{
|
||||
return PyInt_FromLong( self->lattice->pntsw );
|
||||
}
|
||||
static PyObject *Lattice_getLatSize(BPy_Lattice * self)
|
||||
{
|
||||
return PyInt_FromLong(
|
||||
self->lattice->pntsu * self->lattice->pntsv * self->lattice->pntsw );
|
||||
}
|
||||
|
||||
|
||||
static PyObject *Lattice_getAxisType(BPy_Lattice * self, void * type)
|
||||
{
|
||||
char interp_type = 0;
|
||||
switch ( GET_INT_FROM_POINTER(type) ) {
|
||||
case 0:
|
||||
interp_type = self->lattice->typeu;
|
||||
break;
|
||||
case 1:
|
||||
interp_type = self->lattice->typev;
|
||||
break;
|
||||
case 2:
|
||||
interp_type = self->lattice->typew;
|
||||
break;
|
||||
}
|
||||
|
||||
switch (interp_type) {
|
||||
case 0:
|
||||
return PyString_FromString( "Linear" );
|
||||
case 1:
|
||||
return PyString_FromString( "Cardinal" );
|
||||
case 2:
|
||||
return PyString_FromString( "Bspline" );
|
||||
}
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Python attributes get/set structure: */
|
||||
/*****************************************************************************/
|
||||
static PyGetSetDef BPy_Lattice_getseters[] = {
|
||||
GENERIC_LIB_GETSETATTR,
|
||||
{"width", (getter)Lattice_getWidth, (setter)NULL,
|
||||
"lattice U subdivision ", NULL},
|
||||
{"height", (getter)Lattice_getHeight, (setter)NULL,
|
||||
"lattice V subdivision", NULL},
|
||||
{"depth", (getter)Lattice_getDepth, (setter)NULL,
|
||||
"lattice W subdivision", NULL},
|
||||
{"latSize", (getter)Lattice_getLatSize, (setter)NULL,
|
||||
"lattice W subdivision", NULL},
|
||||
|
||||
{"widthType", (getter)Lattice_getAxisType, NULL,
|
||||
"lattice U interpolation type", (void *)0},
|
||||
{"heightType", (getter)Lattice_getAxisType, NULL,
|
||||
"lattice V interpolation type", (void *)1},
|
||||
{"depthType", (getter)Lattice_getAxisType, NULL,
|
||||
"lattice W interpolation type", (void *)2},
|
||||
|
||||
{"key", (getter)Lattice_getKey, NULL,
|
||||
"lattice key", NULL},
|
||||
{"mode", (getter)Lattice_getMode, NULL,
|
||||
"lattice key", NULL},
|
||||
{NULL,NULL,NULL,NULL,NULL} /* Sentinel */
|
||||
};
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Python Lattice_Type structure definition: */
|
||||
/*****************************************************************************/
|
||||
PyTypeObject Lattice_Type = {
|
||||
PyObject_HEAD_INIT( NULL )
|
||||
0, /* ob_size */
|
||||
"Blender Lattice", /* tp_name */
|
||||
sizeof( BPy_Lattice ), /* tp_basicsize */
|
||||
0, /* tp_itemsize */
|
||||
/* methods */
|
||||
NULL, /* tp_dealloc */
|
||||
0, /* tp_print */
|
||||
NULL, /* tp_getattr */
|
||||
NULL, /* tp_setattr */
|
||||
( cmpfunc ) Lattice_compare, /* tp_compare */
|
||||
( reprfunc ) Lattice_repr, /* tp_repr */
|
||||
|
||||
/* Method suites for standard classes */
|
||||
|
||||
NULL, /* PyNumberMethods *tp_as_number; */
|
||||
NULL, /* PySequenceMethods *tp_as_sequence; */
|
||||
NULL, /* PyMappingMethods *tp_as_mapping; */
|
||||
|
||||
/* More standard operations (here for binary compatibility) */
|
||||
|
||||
( hashfunc ) GenericLib_hash, /* hashfunc tp_hash; */
|
||||
NULL, /* ternaryfunc tp_call; */
|
||||
NULL, /* reprfunc tp_str; */
|
||||
NULL, /* getattrofunc tp_getattro; */
|
||||
NULL, /* setattrofunc tp_setattro; */
|
||||
|
||||
/* Functions to access object as input/output buffer */
|
||||
NULL, /* PyBufferProcs *tp_as_buffer; */
|
||||
|
||||
/*** Flags to define presence of optional/expanded features ***/
|
||||
Py_TPFLAGS_DEFAULT, /* long tp_flags; */
|
||||
|
||||
NULL, /* char *tp_doc; Documentation string */
|
||||
/*** Assigned meaning in release 2.0 ***/
|
||||
/* call function for all accessible objects */
|
||||
NULL, /* traverseproc tp_traverse; */
|
||||
|
||||
/* delete references to contained objects */
|
||||
NULL, /* inquiry tp_clear; */
|
||||
|
||||
/*** Assigned meaning in release 2.1 ***/
|
||||
/*** rich comparisons ***/
|
||||
NULL, /* richcmpfunc tp_richcompare; */
|
||||
|
||||
/*** weak reference enabler ***/
|
||||
0, /* long tp_weaklistoffset; */
|
||||
|
||||
/*** Added in release 2.2 ***/
|
||||
/* Iterators */
|
||||
NULL, /* getiterfunc tp_iter; */
|
||||
NULL, /* iternextfunc tp_iternext; */
|
||||
|
||||
/*** Attribute descriptor and subclassing stuff ***/
|
||||
BPy_Lattice_methods, /* struct PyMethodDef *tp_methods; */
|
||||
NULL, /* struct PyMemberDef *tp_members; */
|
||||
BPy_Lattice_getseters, /* struct PyGetSetDef *tp_getset; */
|
||||
NULL, /* struct _typeobject *tp_base; */
|
||||
NULL, /* PyObject *tp_dict; */
|
||||
NULL, /* descrgetfunc tp_descr_get; */
|
||||
NULL, /* descrsetfunc tp_descr_set; */
|
||||
0, /* long tp_dictoffset; */
|
||||
NULL, /* initproc tp_init; */
|
||||
NULL, /* allocfunc tp_alloc; */
|
||||
NULL, /* newfunc tp_new; */
|
||||
/* Low-level free-memory routine */
|
||||
NULL, /* freefunc tp_free; */
|
||||
/* For PyObject_IS_GC */
|
||||
NULL, /* inquiry tp_is_gc; */
|
||||
NULL, /* PyObject *tp_bases; */
|
||||
/* method resolution order */
|
||||
NULL, /* PyObject *tp_mro; */
|
||||
NULL, /* PyObject *tp_cache; */
|
||||
NULL, /* PyObject *tp_subclasses; */
|
||||
NULL, /* PyObject *tp_weaklist; */
|
||||
NULL
|
||||
};
|
||||
@@ -1,57 +0,0 @@
|
||||
/*
|
||||
* $Id$
|
||||
*
|
||||
* ***** 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*
|
||||
* The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This is a new part of Blender.
|
||||
*
|
||||
* Contributor(s): Joseph Gilbert
|
||||
*
|
||||
* ***** END GPL LICENSE BLOCK *****
|
||||
*/
|
||||
|
||||
#ifndef EXPP_Lattice_H
|
||||
#define EXPP_Lattice_H
|
||||
|
||||
#include <Python.h>
|
||||
#include "DNA_lattice_types.h"
|
||||
|
||||
/* The Group PyTypeObject defined in Lattice.c */
|
||||
extern PyTypeObject Lattice_Type;
|
||||
|
||||
#define BPy_Lattice_Check(v) ((v)->ob_type == &Lattice_Type)
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Python BPy_Lattice structure definition: */
|
||||
/*****************************************************************************/
|
||||
typedef struct {
|
||||
PyObject_HEAD
|
||||
Lattice * lattice; /* libdata must be second */
|
||||
} BPy_Lattice;
|
||||
|
||||
/*
|
||||
* prototypes
|
||||
*/
|
||||
|
||||
PyObject *Lattice_Init( void );
|
||||
PyObject *Lattice_CreatePyObject( Lattice * lt );
|
||||
Lattice *Lattice_FromPyObject( PyObject * pyobj );
|
||||
|
||||
#endif /* EXPP_LATTICE_H */
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,77 +0,0 @@
|
||||
/*
|
||||
* $Id$
|
||||
*
|
||||
* ***** 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*
|
||||
* The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This is a new part of Blender.
|
||||
*
|
||||
* Contributor(s): Ken Hughes
|
||||
*
|
||||
* ***** END GPL LICENSE BLOCK *****
|
||||
*/
|
||||
|
||||
#ifndef EXPP_LIBRARY_H
|
||||
#define EXPP_LIBRARY_H
|
||||
|
||||
#include <Python.h>
|
||||
#include "DNA_scene_types.h"
|
||||
#include "BLI_linklist.h"
|
||||
|
||||
#include "blendef.h"
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Python BPy_Library structure definition: */
|
||||
/*****************************************************************************/
|
||||
typedef struct {
|
||||
PyObject_HEAD
|
||||
char filename[FILE_MAXDIR + FILE_MAXFILE];
|
||||
int rel;
|
||||
} BPy_Library;
|
||||
|
||||
typedef struct {
|
||||
PyObject_HEAD
|
||||
LinkNode *iter;
|
||||
int type;
|
||||
char filename[FILE_MAXDIR + FILE_MAXFILE];
|
||||
char *name;
|
||||
int rel;
|
||||
enum {
|
||||
OBJECT_IS_LINK,
|
||||
OBJECT_IS_APPEND,
|
||||
OTHER
|
||||
} kind;
|
||||
} BPy_LibraryData;
|
||||
|
||||
extern PyTypeObject Library_Type;
|
||||
extern PyTypeObject LibraryData_Type;
|
||||
|
||||
#define BPy_LibraryData_Check(v) ((v)->ob_type == &LibraryData_Type)
|
||||
#define BPy_Library_Check(v) ((v)->ob_type == &Library_Type)
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Module Blender.Library - public functions */
|
||||
/*****************************************************************************/
|
||||
PyObject *Library_Init( void );
|
||||
PyObject *oldLibrary_Init( void );
|
||||
|
||||
PyObject *LibraryData_importLibData( BPy_LibraryData *self, char *name,
|
||||
int mode, Scene *scene );
|
||||
|
||||
#endif /* EXPP_LIBRARY_H */
|
||||
@@ -1,943 +0,0 @@
|
||||
/*
|
||||
* $Id$
|
||||
*
|
||||
* ***** 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*
|
||||
* The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This is a new part of Blender.
|
||||
*
|
||||
* Contributor(s): Alex Mole, Yehoshua Sapir, Ken Hughes
|
||||
*
|
||||
* ***** END GPL LICENSE BLOCK *****
|
||||
*/
|
||||
|
||||
#include "MTex.h" /*This must come first*/
|
||||
|
||||
#include "BKE_utildefines.h"
|
||||
#include "BLI_blenlib.h"
|
||||
#include "Texture.h"
|
||||
#include "Object.h"
|
||||
#include "gen_utils.h"
|
||||
#include "gen_library.h"
|
||||
|
||||
#include "DNA_material_types.h"
|
||||
#include "DNA_world_types.h"
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Python BPy_MTex methods declarations: */
|
||||
/*****************************************************************************/
|
||||
static PyObject *MTex_setTexMethod( BPy_MTex * self, PyObject * args );
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Python method structure definition for Blender.Texture.MTex module: */
|
||||
/*****************************************************************************/
|
||||
struct PyMethodDef M_MTex_methods[] = {
|
||||
{NULL, NULL, 0, NULL}
|
||||
};
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Python BPy_MTex methods table: */
|
||||
/*****************************************************************************/
|
||||
static PyMethodDef BPy_MTex_methods[] = {
|
||||
/* name, method, flags, doc */
|
||||
{"setTex", ( PyCFunction ) MTex_setTexMethod, METH_VARARGS,
|
||||
"(i) - Set MTex Texture"},
|
||||
{NULL, NULL, 0, NULL}
|
||||
};
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Python MTex_Type callback function prototypes: */
|
||||
/*****************************************************************************/
|
||||
static int MTex_compare( BPy_MTex * a, BPy_MTex * b );
|
||||
static PyObject *MTex_repr( BPy_MTex * self );
|
||||
|
||||
#define MTEXGET(x) \
|
||||
static PyObject *MTex_get##x( BPy_MTex *self, void *closure );
|
||||
#define MTEXSET(x) \
|
||||
static int MTex_set##x( BPy_MTex *self, PyObject *value, void *closure);
|
||||
#define MTEXGETSET(x) \
|
||||
MTEXGET(x) \
|
||||
MTEXSET(x)
|
||||
|
||||
MTEXGETSET(Tex)
|
||||
MTEXGETSET(TexCo)
|
||||
MTEXGETSET(Object)
|
||||
MTEXGETSET(UVLayer)
|
||||
MTEXGETSET(MapTo)
|
||||
MTEXGETSET(Col)
|
||||
MTEXGETSET(DVar)
|
||||
MTEXGETSET(BlendMode)
|
||||
MTEXGETSET(ColFac)
|
||||
MTEXGETSET(NorFac)
|
||||
MTEXGETSET(VarFac)
|
||||
MTEXGETSET(DispFac)
|
||||
MTEXGETSET(WarpFac)
|
||||
MTEXGETSET(Ofs)
|
||||
MTEXGETSET(Size)
|
||||
MTEXGETSET(Mapping)
|
||||
MTEXGETSET(Flag)
|
||||
MTEXGETSET(ProjX)
|
||||
MTEXGETSET(ProjY)
|
||||
MTEXGETSET(ProjZ)
|
||||
MTEXGETSET(MapToFlag)
|
||||
MTEXGETSET(WorldMapToFlag)
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Python get/set methods table */
|
||||
/*****************************************************************************/
|
||||
|
||||
static PyGetSetDef MTex_getseters[] = {
|
||||
{ "tex", (getter) MTex_getTex, (setter) MTex_setTex,
|
||||
"Texture whose mapping this MTex describes", NULL },
|
||||
{ "texco", (getter) MTex_getTexCo, (setter) MTex_setTexCo,
|
||||
"Texture coordinate space (UV, Global, etc.)", NULL },
|
||||
{ "object", (getter) MTex_getObject, (setter) MTex_setObject,
|
||||
"Object whose space to use when texco is Object", NULL },
|
||||
{ "uvlayer", (getter) MTex_getUVLayer, (setter) MTex_setUVLayer,
|
||||
"Name of the UV layer to use", NULL },
|
||||
{ "mapto", (getter) MTex_getMapTo, (setter) MTex_setMapTo,
|
||||
"What values the texture affects", NULL },
|
||||
{ "col", (getter) MTex_getCol, (setter) MTex_setCol,
|
||||
"Color that the texture blends with", NULL },
|
||||
{ "dvar", (getter) MTex_getDVar, (setter) MTex_setDVar,
|
||||
"Value that the texture blends with when not blending colors", NULL },
|
||||
{ "blendmode", (getter) MTex_getBlendMode, (setter) MTex_setBlendMode,
|
||||
"Texture blending mode", NULL },
|
||||
{ "colfac", (getter) MTex_getColFac, (setter) MTex_setColFac,
|
||||
"Factor by which texture affects color", NULL },
|
||||
{ "norfac", (getter) MTex_getNorFac, (setter) MTex_setNorFac,
|
||||
"Factor by which texture affects normal", NULL },
|
||||
{ "varfac", (getter) MTex_getVarFac, (setter) MTex_setVarFac,
|
||||
"Factor by which texture affects most variables", NULL },
|
||||
{ "dispfac", (getter) MTex_getDispFac, (setter) MTex_setDispFac,
|
||||
"Factor by which texture affects displacement", NULL },
|
||||
{ "warpfac", (getter) MTex_getWarpFac, (setter) MTex_setWarpFac,
|
||||
"Factor by which texture affects warp", NULL },
|
||||
{ "ofs", (getter) MTex_getOfs, (setter) MTex_setOfs,
|
||||
"Offset to adjust texture space", NULL },
|
||||
{ "size", (getter) MTex_getSize, (setter) MTex_setSize,
|
||||
"Size to scale texture space", NULL },
|
||||
{ "mapping", (getter) MTex_getMapping, (setter) MTex_setMapping,
|
||||
"Mapping of texture coordinates (flat, cube, etc.)", NULL },
|
||||
{ "stencil", (getter) MTex_getFlag, (setter) MTex_setFlag,
|
||||
"Stencil mode", (void*) MTEX_STENCIL },
|
||||
{ "neg", (getter) MTex_getFlag, (setter) MTex_setFlag,
|
||||
"Negate texture values mode", (void*) MTEX_NEGATIVE },
|
||||
{ "noRGB", (getter) MTex_getFlag, (setter) MTex_setFlag,
|
||||
"Convert texture RGB values to intensity values",
|
||||
(void*) MTEX_RGBTOINT },
|
||||
{ "correctNor", (getter) MTex_getFlag, (setter) MTex_setFlag,
|
||||
"Correct normal mapping for Texture space and Object space",
|
||||
(void*) MTEX_VIEWSPACE },
|
||||
{ "fromDupli", (getter) MTex_getFlag, (setter) MTex_setFlag,
|
||||
"Dupli's instanced from verts, faces or particles, inherit texture coordinate from their parent",
|
||||
(void*) MTEX_DUPLI_MAPTO },
|
||||
{ "fromOrig", (getter) MTex_getFlag, (setter) MTex_setFlag,
|
||||
"Dupli's derive their object coordinates from the original objects transformation",
|
||||
(void*) MTEX_OB_DUPLI_ORIG },
|
||||
{ "xproj", (getter) MTex_getProjX, (setter) MTex_setProjX,
|
||||
"Projection of X axis to Texture space", NULL },
|
||||
{ "yproj", (getter) MTex_getProjY, (setter) MTex_setProjY,
|
||||
"Projection of Y axis to Texture space", NULL },
|
||||
{ "zproj", (getter) MTex_getProjZ, (setter) MTex_setProjZ,
|
||||
"Projection of Z axis to Texture space", NULL },
|
||||
|
||||
/* MapTo for Material and Lamp MTex */
|
||||
|
||||
{ "mtCol", (getter) MTex_getMapToFlag, (setter) MTex_setMapToFlag,
|
||||
"How texture maps to color", (void*) MAP_COL },
|
||||
|
||||
/* MapTo for Material MTex */
|
||||
|
||||
{ "mtNor", (getter) MTex_getMapToFlag, (setter) MTex_setMapToFlag,
|
||||
"How texture maps to normals", (void*) MAP_NORM },
|
||||
{ "mtCsp", (getter) MTex_getMapToFlag, (setter) MTex_setMapToFlag,
|
||||
"How texture maps to specularity color", (void*) MAP_COLSPEC },
|
||||
{ "mtCmir", (getter) MTex_getMapToFlag, (setter) MTex_setMapToFlag,
|
||||
"How texture maps to mirror color", (void*) MAP_COLMIR },
|
||||
{ "mtRef", (getter) MTex_getMapToFlag, (setter) MTex_setMapToFlag,
|
||||
"How texture maps to reflectivity", (void*) MAP_REF },
|
||||
{ "mtSpec", (getter) MTex_getMapToFlag, (setter) MTex_setMapToFlag,
|
||||
"How texture maps to specularity", (void*) MAP_SPEC },
|
||||
{ "mtEmit", (getter) MTex_getMapToFlag, (setter) MTex_setMapToFlag,
|
||||
"How texture maps to emit value", (void*) MAP_EMIT },
|
||||
{ "mtAlpha", (getter) MTex_getMapToFlag, (setter) MTex_setMapToFlag,
|
||||
"How texture maps to alpha value", (void*) MAP_ALPHA },
|
||||
{ "mtHard", (getter) MTex_getMapToFlag, (setter) MTex_setMapToFlag,
|
||||
"How texture maps to hardness", (void*) MAP_HAR },
|
||||
{ "mtRayMir", (getter) MTex_getMapToFlag, (setter) MTex_setMapToFlag,
|
||||
"How texture maps to RayMir value", (void*) MAP_RAYMIRR },
|
||||
{ "mtTranslu", (getter) MTex_getMapToFlag, (setter) MTex_setMapToFlag,
|
||||
"How texture maps to translucency", (void*) MAP_TRANSLU },
|
||||
{ "mtAmb", (getter) MTex_getMapToFlag, (setter) MTex_setMapToFlag,
|
||||
"How texture maps to ambient value", (void*) MAP_AMB },
|
||||
{ "mtDisp", (getter) MTex_getMapToFlag, (setter) MTex_setMapToFlag,
|
||||
"How texture maps to displacement", (void*) MAP_DISPLACE },
|
||||
{ "mtWarp", (getter) MTex_getMapToFlag, (setter) MTex_setMapToFlag,
|
||||
"How texture maps to warp", (void*) MAP_WARP },
|
||||
|
||||
/* MapTo for World MTex */
|
||||
|
||||
{ "mtBlend", (getter) MTex_getWorldMapToFlag, (setter) MTex_setWorldMapToFlag,
|
||||
"Texture affects color progression of background", (void*) WOMAP_BLEND },
|
||||
{ "mtHoriz", (getter) MTex_getWorldMapToFlag, (setter) MTex_setWorldMapToFlag,
|
||||
"Texture affects color of the horizon", (void*) WOMAP_HORIZ },
|
||||
{ "mtZenUp", (getter) MTex_getWorldMapToFlag, (setter) MTex_setWorldMapToFlag,
|
||||
"Texture affects color of the zenith above", (void*) WOMAP_ZENUP },
|
||||
{ "mtZenDown", (getter) MTex_getWorldMapToFlag, (setter) MTex_setWorldMapToFlag,
|
||||
"Texture affects color of the zenith below", (void*) WOMAP_ZENDOWN },
|
||||
|
||||
{ NULL, NULL, NULL, NULL, NULL }
|
||||
};
|
||||
|
||||
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Python MTex_Type structure definition: */
|
||||
/*****************************************************************************/
|
||||
|
||||
PyTypeObject MTex_Type = {
|
||||
PyObject_HEAD_INIT( NULL )
|
||||
0, /* ob_size */
|
||||
"Blender MTex", /* tp_name */
|
||||
sizeof( BPy_MTex ), /* tp_basicsize */
|
||||
0, /* tp_itemsize */
|
||||
/* methods */
|
||||
NULL, /* tp_dealloc */
|
||||
0, /* tp_print */
|
||||
0, /* tp_getattr */
|
||||
0, /* tp_setattr */
|
||||
( cmpfunc ) MTex_compare, /* tp_compare */
|
||||
( reprfunc ) MTex_repr, /* tp_repr */
|
||||
0, /* tp_as_number */
|
||||
0, /* tp_as_sequence */
|
||||
0, /* tp_as_mapping */
|
||||
0, /* tp_as_hash */
|
||||
0, 0, 0, 0, 0,
|
||||
/*** Flags to define presence of optional/expanded features ***/
|
||||
Py_TPFLAGS_DEFAULT, /* long tp_flags; */
|
||||
0, /* tp_doc */
|
||||
0, 0, 0, 0, 0, 0,
|
||||
BPy_MTex_methods, /* tp_methods */
|
||||
0, /* tp_members */
|
||||
MTex_getseters, /* struct PyGetSetDef *tp_getset; */
|
||||
0, /* struct _typeobject *tp_base; */
|
||||
0, /* PyObject *tp_dict; */
|
||||
0, /* descrgetfunc tp_descr_get; */
|
||||
0, /* descrsetfunc tp_descr_set; */
|
||||
0, /* long tp_dictoffset; */
|
||||
0, /* initproc tp_init; */
|
||||
0, /* allocfunc tp_alloc; */
|
||||
0, /* newfunc tp_new; */
|
||||
/* Low-level free-memory routine */
|
||||
0, /* freefunc tp_free; */
|
||||
/* For PyObject_IS_GC */
|
||||
0, /* inquiry tp_is_gc; */
|
||||
0, /* PyObject *tp_bases; */
|
||||
/* method resolution order */
|
||||
0, /* PyObject *tp_mro; */
|
||||
0, /* PyObject *tp_cache; */
|
||||
0, /* PyObject *tp_subclasses; */
|
||||
0, /* PyObject *tp_weaklist; */
|
||||
0
|
||||
};
|
||||
|
||||
|
||||
PyObject *MTex_Init( void )
|
||||
{
|
||||
PyObject *submodule;
|
||||
/* PyObject *dict; */
|
||||
|
||||
/* call PyType_Ready() to init dictionaries & such */
|
||||
if( PyType_Ready( &MTex_Type) < 0)
|
||||
Py_RETURN_NONE;
|
||||
|
||||
submodule = Py_InitModule( "Blender.Texture.MTex", M_MTex_methods );
|
||||
|
||||
return submodule;
|
||||
}
|
||||
|
||||
PyObject *MTex_CreatePyObject( MTex * mtex, unsigned short type )
|
||||
{
|
||||
BPy_MTex *pymtex;
|
||||
|
||||
pymtex = ( BPy_MTex * ) PyObject_NEW( BPy_MTex, &MTex_Type );
|
||||
if( !pymtex )
|
||||
return EXPP_ReturnPyObjError( PyExc_MemoryError,
|
||||
"couldn't create BPy_MTex PyObject" );
|
||||
|
||||
pymtex->mtex = mtex;
|
||||
pymtex->type = type;
|
||||
return ( PyObject * ) pymtex;
|
||||
}
|
||||
|
||||
MTex *MTex_FromPyObject( PyObject * pyobj )
|
||||
{
|
||||
return ( ( BPy_MTex * ) pyobj )->mtex;
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Python BPy_MTex methods: */
|
||||
/*****************************************************************************/
|
||||
|
||||
static PyObject *MTex_setTexMethod( BPy_MTex * self, PyObject * args )
|
||||
{
|
||||
return EXPP_setterWrapper( (void *)self, args, (setter)MTex_setTex );
|
||||
}
|
||||
|
||||
static int MTex_compare( BPy_MTex * a, BPy_MTex * b )
|
||||
{
|
||||
return ( a->mtex == b->mtex ) ? 0 : -1;
|
||||
}
|
||||
|
||||
static PyObject *MTex_repr( BPy_MTex * self )
|
||||
{
|
||||
if( self->type == ID_MA )
|
||||
return PyString_FromFormat( "[MTex (Material)]" );
|
||||
else if( self->type == ID_LA )
|
||||
return PyString_FromFormat( "[MTex (Lamp)]" );
|
||||
else
|
||||
return PyString_FromFormat( "[MTex (World)]" );
|
||||
}
|
||||
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Python BPy_MTex get and set functions: */
|
||||
/*****************************************************************************/
|
||||
|
||||
static PyObject *MTex_getTex( BPy_MTex *self, void *closure )
|
||||
{
|
||||
if( self->mtex->tex )
|
||||
return Texture_CreatePyObject( self->mtex->tex );
|
||||
else
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
static int MTex_setTex( BPy_MTex *self, PyObject *value, void *closure)
|
||||
{
|
||||
return GenericLib_assignData(value, (void **) &self->mtex->tex, 0, 1, ID_TE, 0);
|
||||
}
|
||||
|
||||
static PyObject *MTex_getTexCo( BPy_MTex *self, void *closure )
|
||||
{
|
||||
return PyInt_FromLong( self->mtex->texco );
|
||||
}
|
||||
|
||||
static int MTex_setTexCo( BPy_MTex *self, PyObject *value, void *closure)
|
||||
{
|
||||
int texco;
|
||||
|
||||
if( !PyInt_Check( value ) )
|
||||
return EXPP_ReturnIntError( PyExc_TypeError,
|
||||
"Value must be a member of Texture.TexCo dictionary" );
|
||||
|
||||
texco = PyInt_AsLong( value ) ;
|
||||
|
||||
switch ( self->type ) {
|
||||
case ID_MA :
|
||||
if( texco != TEXCO_ORCO && texco != TEXCO_REFL &&
|
||||
texco != TEXCO_NORM && texco != TEXCO_GLOB &&
|
||||
texco != TEXCO_UV && texco != TEXCO_OBJECT &&
|
||||
texco != TEXCO_STRESS && texco != TEXCO_TANGENT &&
|
||||
texco != TEXCO_WINDOW && texco != TEXCO_VIEW &&
|
||||
texco != TEXCO_STICKY )
|
||||
return EXPP_ReturnIntError( PyExc_ValueError,
|
||||
"Value must be a member of Texture.TexCo dictionary" );
|
||||
break;
|
||||
case ID_LA :
|
||||
if( texco != TEXCO_VIEW && texco != TEXCO_GLOB &&
|
||||
texco != TEXCO_OBJECT )
|
||||
return EXPP_ReturnIntError( PyExc_ValueError,
|
||||
"Value must be a member of Texture.TexCo dictionary" );
|
||||
break;
|
||||
default: /* ID_WO */
|
||||
if( texco != TEXCO_VIEW && texco != TEXCO_GLOB &&
|
||||
texco != TEXCO_ANGMAP && texco != TEXCO_OBJECT &&
|
||||
texco != TEXCO_H_SPHEREMAP && texco != TEXCO_H_TUBEMAP )
|
||||
return EXPP_ReturnIntError( PyExc_ValueError,
|
||||
"Value must be a member of Texture.TexCo dictionary" );
|
||||
break;
|
||||
}
|
||||
|
||||
self->mtex->texco = (short)texco;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static PyObject *MTex_getObject( BPy_MTex *self, void *closure )
|
||||
{
|
||||
if( self->mtex->object )
|
||||
return Object_CreatePyObject( self->mtex->object );
|
||||
else
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
static int MTex_setObject( BPy_MTex *self, PyObject *value, void *closure)
|
||||
{
|
||||
return GenericLib_assignData(value, (void **) &self->mtex->object, 0, 1, ID_OB, 0);
|
||||
}
|
||||
|
||||
static PyObject *MTex_getUVLayer( BPy_MTex *self, void *closure )
|
||||
{
|
||||
if( self->type != ID_MA )
|
||||
return EXPP_ReturnPyObjError( PyExc_AttributeError,
|
||||
"not a Material MTex object" );
|
||||
|
||||
return PyString_FromString(self->mtex->uvname);
|
||||
}
|
||||
|
||||
static int MTex_setUVLayer( BPy_MTex *self, PyObject *value, void *closure)
|
||||
{
|
||||
if ( !PyString_Check(value) )
|
||||
return EXPP_ReturnIntError( PyExc_TypeError,
|
||||
"expected string value" );
|
||||
BLI_strncpy(self->mtex->uvname, PyString_AsString(value), 31);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static PyObject *MTex_getMapTo( BPy_MTex *self, void *closure )
|
||||
{
|
||||
if( self->type != ID_MA )
|
||||
return EXPP_ReturnPyObjError( PyExc_AttributeError,
|
||||
"not a Material MTex object" );
|
||||
|
||||
return PyInt_FromLong( self->mtex->mapto );
|
||||
}
|
||||
|
||||
static int MTex_setMapTo( BPy_MTex *self, PyObject *value, void *closure)
|
||||
{
|
||||
int mapto;
|
||||
|
||||
if( self->type != ID_MA )
|
||||
return EXPP_ReturnIntError( PyExc_AttributeError,
|
||||
"not a material MTex object" );
|
||||
|
||||
if( !PyInt_Check( value ) )
|
||||
return EXPP_ReturnIntError( PyExc_TypeError,
|
||||
"expected an int" );
|
||||
|
||||
mapto = PyInt_AsLong( value );
|
||||
|
||||
/* This method is deprecated anyway. */
|
||||
if ( mapto < 0 || mapto > 16383 )
|
||||
return EXPP_ReturnIntError( PyExc_ValueError,
|
||||
"Value must be a sum of values from Texture.MapTo dictionary" );
|
||||
|
||||
self->mtex->mapto = (short)mapto;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static PyObject *MTex_getCol( BPy_MTex *self, void *closure )
|
||||
{
|
||||
return Py_BuildValue( "(f,f,f)", self->mtex->r, self->mtex->g,
|
||||
self->mtex->b );
|
||||
}
|
||||
|
||||
static int MTex_setCol( BPy_MTex *self, PyObject *value, void *closure)
|
||||
{
|
||||
float rgb[3];
|
||||
int i;
|
||||
|
||||
if( !PyArg_ParseTuple( value, "fff", &rgb[0], &rgb[1], &rgb[2] ) )
|
||||
return EXPP_ReturnIntError( PyExc_TypeError,
|
||||
"expected tuple of 3 floats" );
|
||||
|
||||
for( i = 0; i < 3; ++i )
|
||||
if( rgb[i] < 0 || rgb[i] > 1 )
|
||||
return EXPP_ReturnIntError( PyExc_ValueError,
|
||||
"values must be in range [0,1]" );
|
||||
|
||||
self->mtex->r = rgb[0];
|
||||
self->mtex->g = rgb[1];
|
||||
self->mtex->b = rgb[2];
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static PyObject *MTex_getDVar( BPy_MTex *self, void *closure )
|
||||
{
|
||||
return PyFloat_FromDouble(self->mtex->def_var);
|
||||
}
|
||||
|
||||
static int MTex_setDVar( BPy_MTex *self, PyObject *value, void *closure)
|
||||
{
|
||||
float f;
|
||||
|
||||
if ( !PyFloat_Check( value ) )
|
||||
return EXPP_ReturnIntError( PyExc_TypeError,
|
||||
"expected a float" );
|
||||
|
||||
f = (float)PyFloat_AsDouble(value);
|
||||
|
||||
if (f < 0 || f > 1)
|
||||
return EXPP_ReturnIntError( PyExc_ValueError,
|
||||
"values must be in range [0,1]" );
|
||||
|
||||
self->mtex->def_var = f;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static PyObject *MTex_getBlendMode( BPy_MTex *self, void *closure )
|
||||
{
|
||||
return PyInt_FromLong(self->mtex->blendtype);
|
||||
}
|
||||
|
||||
static int MTex_setBlendMode( BPy_MTex *self, PyObject *value, void *closure)
|
||||
{
|
||||
int n;
|
||||
|
||||
if ( !PyInt_Check( value ) )
|
||||
return EXPP_ReturnIntError( PyExc_TypeError,
|
||||
"Value must be member of Texture.BlendModes dictionary" );
|
||||
|
||||
n = PyInt_AsLong(value);
|
||||
|
||||
if (n < 0 || n > 8)
|
||||
return EXPP_ReturnIntError( PyExc_ValueError,
|
||||
"Value must be member of Texture.BlendModes dictionary" );
|
||||
|
||||
self->mtex->blendtype = (short)n;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static PyObject *MTex_getColFac( BPy_MTex *self, void *closure )
|
||||
{
|
||||
return PyFloat_FromDouble(self->mtex->colfac);
|
||||
}
|
||||
|
||||
static int MTex_setColFac( BPy_MTex *self, PyObject *value, void *closure)
|
||||
{
|
||||
return EXPP_setFloatRange( value, &self->mtex->colfac, 0.0f, 1.0f );
|
||||
}
|
||||
|
||||
static PyObject *MTex_getNorFac( BPy_MTex *self, void *closure )
|
||||
{
|
||||
if( self->type == ID_LA )
|
||||
return EXPP_ReturnPyObjError( PyExc_AttributeError,
|
||||
"not a material or world MTex object" );
|
||||
|
||||
return PyFloat_FromDouble(self->mtex->norfac);
|
||||
}
|
||||
|
||||
static int MTex_setNorFac( BPy_MTex *self, PyObject *value, void *closure)
|
||||
{
|
||||
switch( self->type )
|
||||
{
|
||||
case ID_WO:
|
||||
return EXPP_setFloatRange( value, &self->mtex->norfac, 0.0f, 1.0f );
|
||||
case ID_MA:
|
||||
return EXPP_setFloatRange( value, &self->mtex->norfac, 0.0f, 25.0f );
|
||||
default:
|
||||
return EXPP_ReturnIntError( PyExc_AttributeError,
|
||||
"not a material or world MTex object" );
|
||||
}
|
||||
}
|
||||
|
||||
static PyObject *MTex_getVarFac( BPy_MTex *self, void *closure )
|
||||
{
|
||||
if( self->type == ID_LA )
|
||||
return EXPP_ReturnPyObjError( PyExc_AttributeError,
|
||||
"not a material or world MTex object" );
|
||||
|
||||
return PyFloat_FromDouble(self->mtex->varfac);
|
||||
}
|
||||
|
||||
static int MTex_setVarFac( BPy_MTex *self, PyObject *value, void *closure)
|
||||
{
|
||||
if( self->type == ID_LA )
|
||||
return EXPP_ReturnIntError( PyExc_AttributeError,
|
||||
"not a material or world MTex object" );
|
||||
|
||||
return EXPP_setFloatRange( value, &self->mtex->varfac, 0.0f, 1.0f );
|
||||
}
|
||||
|
||||
static PyObject *MTex_getDispFac( BPy_MTex *self, void *closure )
|
||||
{
|
||||
if( self->type != ID_MA )
|
||||
return EXPP_ReturnPyObjError( PyExc_AttributeError,
|
||||
"not a material MTex object" );
|
||||
|
||||
return PyFloat_FromDouble(self->mtex->dispfac);
|
||||
}
|
||||
|
||||
static int MTex_setDispFac( BPy_MTex *self, PyObject *value, void *closure)
|
||||
{
|
||||
if( self->type != ID_MA )
|
||||
return EXPP_ReturnIntError( PyExc_AttributeError,
|
||||
"not a material MTex object" );
|
||||
|
||||
return EXPP_setFloatRange( value, &self->mtex->dispfac, 0.0f, 1.0f );
|
||||
}
|
||||
|
||||
static PyObject *MTex_getWarpFac( BPy_MTex *self, void *closure )
|
||||
{
|
||||
if( self->type != ID_MA )
|
||||
return EXPP_ReturnPyObjError( PyExc_AttributeError,
|
||||
"not a material MTex object" );
|
||||
|
||||
return PyFloat_FromDouble(self->mtex->warpfac);
|
||||
}
|
||||
|
||||
static int MTex_setWarpFac( BPy_MTex *self, PyObject *value, void *closure)
|
||||
{
|
||||
if( self->type != ID_MA )
|
||||
return EXPP_ReturnIntError( PyExc_AttributeError,
|
||||
"not a material MTex object" );
|
||||
|
||||
return EXPP_setFloatRange( value, &self->mtex->warpfac, 0.0f, 1.0f );
|
||||
}
|
||||
|
||||
static PyObject *MTex_getOfs( BPy_MTex *self, void *closure )
|
||||
{
|
||||
return Py_BuildValue( "(f,f,f)", self->mtex->ofs[0], self->mtex->ofs[1],
|
||||
self->mtex->ofs[2] );
|
||||
}
|
||||
|
||||
static int MTex_setOfs( BPy_MTex *self, PyObject *value, void *closure)
|
||||
{
|
||||
float f[3];
|
||||
int i;
|
||||
float max;
|
||||
|
||||
if( !PyArg_ParseTuple( value, "fff", &f[0], &f[1], &f[2] ) )
|
||||
return EXPP_ReturnIntError( PyExc_TypeError,
|
||||
"expected tuple of 3 floats" );
|
||||
|
||||
if( self->type == ID_MA )
|
||||
max = 10.0f;
|
||||
else
|
||||
max = 20.0f;
|
||||
|
||||
for( i = 0; i < 3; ++i )
|
||||
if( f[i] < -max || f[i] > max ) {
|
||||
char errstr[64];
|
||||
sprintf( errstr, "values must be in range [-%6.0f,%6.0f]",
|
||||
max, max );
|
||||
return EXPP_ReturnIntError( PyExc_ValueError, errstr );
|
||||
}
|
||||
|
||||
self->mtex->ofs[0] = f[0];
|
||||
self->mtex->ofs[1] = f[1];
|
||||
self->mtex->ofs[2] = f[2];
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static PyObject *MTex_getSize( BPy_MTex *self, void *closure )
|
||||
{
|
||||
return Py_BuildValue( "(f,f,f)", self->mtex->size[0], self->mtex->size[1],
|
||||
self->mtex->size[2] );
|
||||
}
|
||||
|
||||
static int MTex_setSize( BPy_MTex *self, PyObject *value, void *closure)
|
||||
{
|
||||
float f[3];
|
||||
int i;
|
||||
|
||||
if( !PyArg_ParseTuple( value, "fff", &f[0], &f[1], &f[2] ) )
|
||||
|
||||
return EXPP_ReturnIntError( PyExc_TypeError,
|
||||
"expected tuple of 3 floats" );
|
||||
|
||||
for( i = 0; i < 3; ++i )
|
||||
if( f[i] < -100 || f[i] > 100 )
|
||||
return EXPP_ReturnIntError( PyExc_ValueError,
|
||||
"values must be in range [-100,100]" );
|
||||
|
||||
self->mtex->size[0] = f[0];
|
||||
self->mtex->size[1] = f[1];
|
||||
self->mtex->size[2] = f[2];
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static PyObject *MTex_getMapping( BPy_MTex *self, void *closure )
|
||||
{
|
||||
if( self->type != ID_MA )
|
||||
return EXPP_ReturnPyObjError( PyExc_AttributeError,
|
||||
"not a material MTex object" );
|
||||
|
||||
return PyInt_FromLong( self->mtex->mapping );
|
||||
}
|
||||
|
||||
static int MTex_setMapping( BPy_MTex *self, PyObject *value, void *closure)
|
||||
{
|
||||
int n;
|
||||
|
||||
if( self->type != ID_MA )
|
||||
return EXPP_ReturnIntError( PyExc_AttributeError,
|
||||
"not a material MTex object" );
|
||||
|
||||
|
||||
if ( !PyInt_Check( value ) )
|
||||
return EXPP_ReturnIntError( PyExc_TypeError,
|
||||
"Value must be member of Texture.Mappings dictionary" );
|
||||
|
||||
n = PyInt_AsLong(value);
|
||||
|
||||
/* if (n != MTEX_FLAT && n != MTEX_TUBE && n != MTEX_CUBE &&
|
||||
n != MTEX_SPHERE) */
|
||||
if (n < 0 || n > 3) {
|
||||
return EXPP_ReturnIntError( PyExc_ValueError,
|
||||
"Value must be member of Texture.Mappings dictionary" );
|
||||
}
|
||||
|
||||
self->mtex->mapping = (char)n;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static PyObject *MTex_getFlag( BPy_MTex *self, void *closure )
|
||||
{
|
||||
int flag = GET_INT_FROM_POINTER(closure);
|
||||
|
||||
if( self->type != ID_MA &&
|
||||
flag & ( MTEX_VIEWSPACE | MTEX_DUPLI_MAPTO | MTEX_OB_DUPLI_ORIG ) )
|
||||
return EXPP_ReturnPyObjError( PyExc_AttributeError,
|
||||
"attribute only vaild for material MTex object" );
|
||||
|
||||
return PyBool_FromLong( self->mtex->texflag & flag );
|
||||
}
|
||||
|
||||
static int MTex_setFlag( BPy_MTex *self, PyObject *value, void *closure)
|
||||
{
|
||||
int flag = GET_INT_FROM_POINTER(closure);
|
||||
|
||||
if( self->type != ID_MA &&
|
||||
flag & ( MTEX_VIEWSPACE | MTEX_DUPLI_MAPTO | MTEX_OB_DUPLI_ORIG ) )
|
||||
return EXPP_ReturnIntError( PyExc_AttributeError,
|
||||
"attribute only vaild for material MTex object" );
|
||||
|
||||
if ( !PyBool_Check( value ) )
|
||||
return EXPP_ReturnIntError( PyExc_TypeError,
|
||||
"expected a bool");
|
||||
|
||||
if ( value == Py_True )
|
||||
self->mtex->texflag |= flag;
|
||||
else
|
||||
self->mtex->texflag &= ~flag;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static PyObject *MTex_getProjX( BPy_MTex *self, void *closure )
|
||||
{
|
||||
if( self->type != ID_MA )
|
||||
return EXPP_ReturnPyObjError( PyExc_AttributeError,
|
||||
"not a material MTex object" );
|
||||
|
||||
return PyInt_FromLong( self->mtex->projx );
|
||||
}
|
||||
|
||||
static int MTex_setProjX( BPy_MTex *self, PyObject *value, void *closure)
|
||||
{
|
||||
int proj;
|
||||
|
||||
if( self->type != ID_MA )
|
||||
return EXPP_ReturnIntError( PyExc_AttributeError,
|
||||
"not a material MTex object" );
|
||||
|
||||
if( !PyInt_Check( value ) ) {
|
||||
return EXPP_ReturnIntError( PyExc_TypeError,
|
||||
"Value must be a member of Texture.Proj dictionary" );
|
||||
}
|
||||
|
||||
proj = PyInt_AsLong( value ) ;
|
||||
|
||||
/* valid values are from PROJ_N to PROJ_Z = 0 to 3 */
|
||||
if (proj < 0 || proj > 3)
|
||||
return EXPP_ReturnIntError( PyExc_ValueError,
|
||||
"Value must be a member of Texture.Proj dictionary" );
|
||||
|
||||
self->mtex->projx = (char)proj;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static PyObject *MTex_getProjY( BPy_MTex *self, void *closure )
|
||||
{
|
||||
if( self->type != ID_MA )
|
||||
return EXPP_ReturnPyObjError( PyExc_AttributeError,
|
||||
"not a material MTex object" );
|
||||
|
||||
return PyInt_FromLong( self->mtex->projy );
|
||||
}
|
||||
|
||||
static int MTex_setProjY( BPy_MTex *self, PyObject *value, void *closure )
|
||||
{
|
||||
int proj;
|
||||
|
||||
if( self->type != ID_MA )
|
||||
return EXPP_ReturnIntError( PyExc_AttributeError,
|
||||
"not a material MTex object" );
|
||||
|
||||
if( !PyInt_Check( value ) ) {
|
||||
return EXPP_ReturnIntError( PyExc_TypeError,
|
||||
"Value must be a member of Texture.Proj dictionary" );
|
||||
}
|
||||
|
||||
proj = PyInt_AsLong( value ) ;
|
||||
|
||||
/* valid values are from PROJ_N to PROJ_Z = 0 to 3 */
|
||||
if (proj < 0 || proj > 3)
|
||||
return EXPP_ReturnIntError( PyExc_ValueError,
|
||||
"Value must be a member of Texture.Proj dictionary" );
|
||||
|
||||
self->mtex->projy = (char)proj;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static PyObject *MTex_getProjZ( BPy_MTex *self, void *closure )
|
||||
{
|
||||
if( self->type != ID_MA )
|
||||
return EXPP_ReturnPyObjError( PyExc_AttributeError,
|
||||
"not a material MTex object" );
|
||||
|
||||
return PyInt_FromLong( self->mtex->projz );
|
||||
}
|
||||
|
||||
static int MTex_setProjZ( BPy_MTex *self, PyObject *value, void *closure)
|
||||
{
|
||||
int proj;
|
||||
|
||||
if( self->type != ID_MA )
|
||||
return EXPP_ReturnIntError( PyExc_AttributeError,
|
||||
"not a material MTex object" );
|
||||
|
||||
if( !PyInt_Check( value ) ) {
|
||||
return EXPP_ReturnIntError( PyExc_TypeError,
|
||||
"Value must be a member of Texture.Proj dictionary" );
|
||||
}
|
||||
|
||||
proj = PyInt_AsLong( value ) ;
|
||||
|
||||
/* valid values are from PROJ_N to PROJ_Z = 0 to 3 */
|
||||
if (proj < 0 || proj > 3)
|
||||
return EXPP_ReturnIntError( PyExc_ValueError,
|
||||
"Value must be a member of Texture.Proj dictionary" );
|
||||
|
||||
self->mtex->projz = (char)proj;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static PyObject *MTex_getMapToFlag( BPy_MTex *self, void *closure )
|
||||
{
|
||||
int flag = GET_INT_FROM_POINTER(closure);
|
||||
|
||||
if( self->type == ID_LA && flag != MAP_COL )
|
||||
return EXPP_ReturnPyObjError( PyExc_AttributeError,
|
||||
"attribute not available for a lamp MTex" );
|
||||
|
||||
if ( self->mtex->mapto & flag )
|
||||
return PyInt_FromLong( ( self->mtex->maptoneg & flag ) ? -1 : 1 );
|
||||
else
|
||||
return PyInt_FromLong( 0 );
|
||||
}
|
||||
|
||||
static PyObject *MTex_getWorldMapToFlag( BPy_MTex *self, void *closure )
|
||||
{
|
||||
int flag = GET_INT_FROM_POINTER(closure);
|
||||
|
||||
if( self->type != ID_WO )
|
||||
return EXPP_ReturnPyObjError( PyExc_AttributeError,
|
||||
"not a world MTex object" );
|
||||
|
||||
return PyInt_FromLong( (long)( (self->mtex->mapto & flag) != 0 ) );
|
||||
}
|
||||
|
||||
static int MTex_setMapToFlag( BPy_MTex *self, PyObject *value, void *closure)
|
||||
{
|
||||
int flag = GET_INT_FROM_POINTER(closure);
|
||||
int intVal;
|
||||
|
||||
if( self->type == ID_LA && flag != MAP_COL )
|
||||
return EXPP_ReturnIntError( PyExc_AttributeError,
|
||||
"attribute not available for a lamp MTex" );
|
||||
|
||||
if ( !PyInt_Check( value ) )
|
||||
return EXPP_ReturnIntError( PyExc_TypeError,
|
||||
"expected an int");
|
||||
|
||||
intVal = PyInt_AsLong( value ) ;
|
||||
|
||||
if( flag & ( MAP_COL | MAP_COLSPEC | MAP_COLMIR | MAP_WARP ) ) {
|
||||
if (intVal < 0 || intVal > 1) {
|
||||
return EXPP_ReturnIntError( PyExc_ValueError,
|
||||
"value for that mapping must be 0 or 1" );
|
||||
}
|
||||
} else {
|
||||
if (intVal < -1 || intVal > 1) {
|
||||
return EXPP_ReturnIntError( PyExc_ValueError,
|
||||
"value for that mapping must be -1, 0 or 1" );
|
||||
}
|
||||
}
|
||||
|
||||
switch (intVal)
|
||||
{
|
||||
case 0:
|
||||
self->mtex->mapto &= ~flag;
|
||||
self->mtex->maptoneg &= ~flag;
|
||||
break;
|
||||
|
||||
case 1:
|
||||
self->mtex->mapto |= flag;
|
||||
self->mtex->maptoneg &= ~flag;
|
||||
break;
|
||||
|
||||
case -1:
|
||||
self->mtex->mapto |= flag;
|
||||
self->mtex->maptoneg |= flag;
|
||||
break;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int MTex_setWorldMapToFlag( BPy_MTex *self, PyObject *value, void *closure)
|
||||
{
|
||||
int flag = GET_INT_FROM_POINTER(closure);
|
||||
|
||||
if( self->type != ID_WO )
|
||||
return EXPP_ReturnIntError( PyExc_AttributeError,
|
||||
"attribute only available for a world MTex" );
|
||||
|
||||
if ( !PyInt_Check( value ) )
|
||||
return EXPP_ReturnIntError( PyExc_TypeError,
|
||||
"expected an int");
|
||||
|
||||
switch( PyInt_AsLong( value ) ) {
|
||||
case 0:
|
||||
self->mtex->mapto &= ~flag;
|
||||
break;
|
||||
case 1:
|
||||
self->mtex->mapto |= flag;
|
||||
break;
|
||||
default:
|
||||
return EXPP_ReturnIntError( PyExc_ValueError,
|
||||
"value for mapping must be 0 or 1" );
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -1,64 +0,0 @@
|
||||
/*
|
||||
* $Id$
|
||||
*
|
||||
* ***** 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*
|
||||
* The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This is a new part of Blender.
|
||||
*
|
||||
* Contributor(s): Alex Mole
|
||||
*
|
||||
* ***** END GPL LICENSE BLOCK *****
|
||||
*/
|
||||
|
||||
#ifndef EXPP_MTEX_H
|
||||
#define EXPP_MTEX_H
|
||||
|
||||
#include <Python.h>
|
||||
#include "DNA_texture_types.h"
|
||||
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Python BPy_MTex structure definition */
|
||||
/*****************************************************************************/
|
||||
|
||||
#define MATERIAL_MTEX_TYPE 1
|
||||
#define WORLD_MTEX_TYPE 2
|
||||
#define LAMP_MTEX_TYPE 3
|
||||
|
||||
typedef struct {
|
||||
PyObject_HEAD
|
||||
MTex * mtex;
|
||||
unsigned short type;
|
||||
} BPy_MTex;
|
||||
|
||||
extern PyTypeObject MTex_Type;
|
||||
|
||||
#define BPy_MTex_Check(v) ((v)->ob_type == &MTex_Type)
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Module Blender.Texture.MTex - public functions */
|
||||
/*****************************************************************************/
|
||||
|
||||
PyObject *MTex_Init( void );
|
||||
PyObject *MTex_CreatePyObject( struct MTex *obj, unsigned short type );
|
||||
MTex *MTex_FromPyObject( PyObject * py_obj );
|
||||
|
||||
|
||||
#endif /* EXPP_MTEX_H */
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,75 +0,0 @@
|
||||
/*
|
||||
* $Id$
|
||||
*
|
||||
* ***** 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*
|
||||
* The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This is a new part of Blender.
|
||||
*
|
||||
* Contributor(s): Willian P. Germano
|
||||
*
|
||||
* ***** END GPL LICENSE BLOCK *****
|
||||
*/
|
||||
|
||||
#ifndef EXPP_MATERIAL_H
|
||||
#define EXPP_MATERIAL_H
|
||||
|
||||
#include <Python.h>
|
||||
#include "DNA_object_types.h"
|
||||
#include "DNA_material_types.h"
|
||||
#include "DNA_texture_types.h" /* colorband */
|
||||
#include "rgbTuple.h"
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Python BPy_Material structure definition: */
|
||||
/*****************************************************************************/
|
||||
typedef struct {
|
||||
PyObject_HEAD
|
||||
Material * material; /* libdata must be second */
|
||||
BPy_rgbTuple *col, *amb, *spec, *mir, *sss;
|
||||
} BPy_Material;
|
||||
|
||||
extern PyTypeObject Material_Type; /* The Material PyType Object */
|
||||
|
||||
#define BPy_Material_Check(v) \
|
||||
((v)->ob_type == &Material_Type) /* for type checking */
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Module Blender.Material - public functions */
|
||||
/*****************************************************************************/
|
||||
PyObject *M_Material_Init( void );
|
||||
|
||||
PyObject *Material_Init( void );
|
||||
PyObject *Material_CreatePyObject( Material * mat );
|
||||
Material *Material_FromPyObject( PyObject * pyobj );
|
||||
|
||||
/* colorband tp_getseters */
|
||||
PyObject *EXPP_PyList_fromColorband( ColorBand *coba );
|
||||
int EXPP_Colorband_fromPyList( ColorBand **coba, PyObject * value );
|
||||
|
||||
/* Some functions needed by NMesh, Curve and friends */
|
||||
PyObject *EXPP_PyList_fromMaterialList( Material ** matlist, int len,
|
||||
int all );
|
||||
Material **EXPP_newMaterialList_fromPyList( PyObject * list );
|
||||
Material **EXPP_newMaterialList( int len );
|
||||
void EXPP_incr_mats_us( Material ** matlist, int len );
|
||||
int EXPP_synchronizeMaterialLists( Object * object );
|
||||
int EXPP_releaseMaterialList( Material ** matlist, int len );
|
||||
|
||||
#endif /* EXPP_MATERIAL_H */
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,82 +0,0 @@
|
||||
/*
|
||||
* $Id$
|
||||
*
|
||||
* ***** 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*
|
||||
* The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This is a new part of Blender.
|
||||
*
|
||||
* Contributor(s): Joseph Gilbert
|
||||
*
|
||||
* ***** END GPL LICENSE BLOCK *****
|
||||
*/
|
||||
//Include this file for access to vector, quat, matrix, euler, etc...
|
||||
|
||||
#ifndef EXPP_Mathutils_H
|
||||
#define EXPP_Mathutils_H
|
||||
|
||||
#include <Python.h>
|
||||
#include "vector.h"
|
||||
#include "matrix.h"
|
||||
#include "quat.h"
|
||||
#include "euler.h"
|
||||
#include "point.h"
|
||||
|
||||
PyObject *Mathutils_Init( const char * from );
|
||||
PyObject *row_vector_multiplication(VectorObject* vec, MatrixObject * mat);
|
||||
PyObject *column_vector_multiplication(MatrixObject * mat, VectorObject* vec);
|
||||
PyObject *row_point_multiplication(PointObject* pt, MatrixObject * mat);
|
||||
PyObject *column_point_multiplication(MatrixObject * mat, PointObject* pt);
|
||||
PyObject *quat_rotation(PyObject *arg1, PyObject *arg2);
|
||||
|
||||
PyObject *M_Mathutils_Rand(PyObject * self, PyObject * args);
|
||||
PyObject *M_Mathutils_Vector(PyObject * self, PyObject * args);
|
||||
PyObject *M_Mathutils_CrossVecs(PyObject * self, PyObject * args);
|
||||
PyObject *M_Mathutils_DotVecs(PyObject * self, PyObject * args);
|
||||
PyObject *M_Mathutils_AngleBetweenVecs(PyObject * self, PyObject * args);
|
||||
PyObject *M_Mathutils_MidpointVecs(PyObject * self, PyObject * args);
|
||||
PyObject *M_Mathutils_ProjectVecs(PyObject * self, PyObject * args);
|
||||
PyObject *M_Mathutils_Matrix(PyObject * self, PyObject * args);
|
||||
PyObject *M_Mathutils_RotationMatrix(PyObject * self, PyObject * args);
|
||||
PyObject *M_Mathutils_TranslationMatrix(PyObject * self, VectorObject * value);
|
||||
PyObject *M_Mathutils_ScaleMatrix(PyObject * self, PyObject * args);
|
||||
PyObject *M_Mathutils_OrthoProjectionMatrix(PyObject * self, PyObject * args);
|
||||
PyObject *M_Mathutils_ShearMatrix(PyObject * self, PyObject * args);
|
||||
PyObject *M_Mathutils_Quaternion(PyObject * self, PyObject * args);
|
||||
PyObject *M_Mathutils_CrossQuats(PyObject * self, PyObject * args);
|
||||
PyObject *M_Mathutils_DotQuats(PyObject * self, PyObject * args);
|
||||
PyObject *M_Mathutils_DifferenceQuats(PyObject * self, PyObject * args);
|
||||
PyObject *M_Mathutils_Slerp(PyObject * self, PyObject * args);
|
||||
PyObject *M_Mathutils_Euler(PyObject * self, PyObject * args);
|
||||
PyObject *M_Mathutils_Intersect( PyObject * self, PyObject * args );
|
||||
PyObject *M_Mathutils_TriangleArea( PyObject * self, PyObject * args );
|
||||
PyObject *M_Mathutils_TriangleNormal( PyObject * self, PyObject * args );
|
||||
PyObject *M_Mathutils_QuadNormal( PyObject * self, PyObject * args );
|
||||
PyObject *M_Mathutils_LineIntersect( PyObject * self, PyObject * args );
|
||||
PyObject *M_Mathutils_Point(PyObject * self, PyObject * args);
|
||||
//DEPRECATED
|
||||
PyObject *M_Mathutils_CopyMat(PyObject * self, PyObject * args);
|
||||
PyObject *M_Mathutils_CopyVec(PyObject * self, PyObject * args);
|
||||
PyObject *M_Mathutils_CopyQuat(PyObject * self, PyObject * args);
|
||||
PyObject *M_Mathutils_CopyEuler(PyObject * self, PyObject * args);
|
||||
PyObject *M_Mathutils_RotateEuler(PyObject * self, PyObject * args);
|
||||
PyObject *M_Mathutils_MatMultVec(PyObject * self, PyObject * args);
|
||||
PyObject *M_Mathutils_VecMultMat(PyObject * self, PyObject * args);
|
||||
|
||||
#endif /* EXPP_Mathutils_H */
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,124 +0,0 @@
|
||||
/*
|
||||
* $Id$
|
||||
*
|
||||
* ***** 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*
|
||||
* The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This is a new part of Blender.
|
||||
*
|
||||
* Contributor(s): Ken Hughes
|
||||
*
|
||||
* ***** END GPL LICENSE BLOCK *****
|
||||
*/
|
||||
|
||||
/* Most of this file comes from opy_nmesh.[ch] in the old bpython dir */
|
||||
|
||||
#ifndef EXPP_MESH_H
|
||||
#define EXPP_MESH_H
|
||||
|
||||
#include <Python.h>
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
|
||||
#include "DNA_object_types.h"
|
||||
#include "DNA_mesh_types.h"
|
||||
#include "DNA_meshdata_types.h"
|
||||
#include "Material.h"
|
||||
#include "Image.h"
|
||||
|
||||
/* EXPP PyType Objects */
|
||||
extern PyTypeObject Mesh_Type;
|
||||
extern PyTypeObject MVert_Type;
|
||||
extern PyTypeObject PVert_Type;
|
||||
extern PyTypeObject MVertSeq_Type;
|
||||
extern PyTypeObject MEdge_Type;
|
||||
extern PyTypeObject MFace_Type;
|
||||
extern PyTypeObject MCol_Type;
|
||||
|
||||
struct BPy_Object;
|
||||
|
||||
/* Type checking for EXPP PyTypes */
|
||||
#define BPy_Mesh_Check(v) ((v)->ob_type == &Mesh_Type)
|
||||
#define BPy_MFace_Check(v) ((v)->ob_type == &MFace_Type)
|
||||
#define BPy_MEdge_Check(v) ((v)->ob_type == &MEdge_Type)
|
||||
#define BPy_MVert_Check(v) ((v)->ob_type == &MVert_Type)
|
||||
#define BPy_PVert_Check(v) ((v)->ob_type == &PVert_Type)
|
||||
#define BPy_MCol_Check(v) ((v)->ob_type == &MCol_Type)
|
||||
|
||||
/* Typedefs for the new types */
|
||||
|
||||
typedef struct {
|
||||
PyObject_HEAD /* required python macro */
|
||||
MCol *color;
|
||||
} BPy_MCol; /* a Mesh color: [r,g,b,a] */
|
||||
|
||||
typedef struct {
|
||||
PyObject_VAR_HEAD /* required python macro */
|
||||
void * data; /* points to a Mesh or an MVert */
|
||||
int index;
|
||||
} BPy_MVert; /* a Mesh vertex */
|
||||
|
||||
typedef struct {
|
||||
PyObject_VAR_HEAD /* required python macro */
|
||||
Mesh * mesh;
|
||||
int iter;
|
||||
} BPy_MVertSeq; /* a Mesh vertex sequence */
|
||||
|
||||
typedef struct {
|
||||
PyObject_VAR_HEAD /* required python macro */
|
||||
Mesh *mesh; /* points to a Mesh */
|
||||
int index;
|
||||
short iter; /* char because it can only ever be between -1 and 2 */
|
||||
} BPy_MEdge; /* a Mesh edge */
|
||||
|
||||
typedef struct {
|
||||
PyObject_VAR_HEAD /* required python macro */
|
||||
Mesh * mesh;
|
||||
int iter;
|
||||
} BPy_MEdgeSeq; /* a Mesh edge sequence */
|
||||
|
||||
typedef struct {
|
||||
PyObject_VAR_HEAD /* required python macro */
|
||||
Mesh * mesh;
|
||||
int index;
|
||||
short iter; /* char because it can only ever be between -1 and 4 */
|
||||
} BPy_MFace; /* a Mesh face */
|
||||
|
||||
typedef struct {
|
||||
PyObject_VAR_HEAD /* required python macro */
|
||||
Mesh * mesh;
|
||||
int iter;
|
||||
} BPy_MFaceSeq; /* a Mesh face sequence */
|
||||
|
||||
typedef struct {
|
||||
PyObject_HEAD /* required python macro */
|
||||
Mesh *mesh;
|
||||
Object *object;
|
||||
char new; /* was mesh created or already existed? */
|
||||
} BPy_Mesh;
|
||||
|
||||
/* PROTOS */
|
||||
|
||||
PyObject *Mesh_Init( void );
|
||||
PyObject *Mesh_CreatePyObject( Mesh * me, Object *obj );
|
||||
Mesh *Mesh_FromPyObject( PyObject * pyobj, Object *obj );
|
||||
|
||||
#endif /* EXPP_MESH_H */
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,78 +0,0 @@
|
||||
/*
|
||||
* $Id$
|
||||
*
|
||||
* ***** 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*
|
||||
* The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This is a new part of Blender.
|
||||
*
|
||||
* Contributor(s): Jacques Guignot
|
||||
*
|
||||
* ***** END GPL LICENSE BLOCK *****
|
||||
*/
|
||||
|
||||
#ifndef EXPP_METABALL_H
|
||||
#define EXPP_METABALL_H
|
||||
|
||||
#include <Python.h>
|
||||
#include "DNA_meta_types.h"
|
||||
|
||||
|
||||
extern PyTypeObject Metaball_Type;
|
||||
|
||||
#define BPy_Metaball_Check(v) ((v)->ob_type==&Metaball_Type)
|
||||
|
||||
|
||||
/* Python BPy_Metaball structure definition */
|
||||
typedef struct {
|
||||
PyObject_HEAD /* required py macro */
|
||||
MetaBall * metaball; /* libdata must be second */
|
||||
} BPy_Metaball;
|
||||
|
||||
|
||||
extern PyTypeObject Metaelem_Type;
|
||||
|
||||
#define BPy_Metaelem_Check(v) ((v)->ob_type==&Metaelem_Type)
|
||||
|
||||
/* Python BPy_Metaelem structure definition */
|
||||
typedef struct {
|
||||
PyObject_HEAD /* required py macro */
|
||||
MetaElem * metaelem;
|
||||
} BPy_Metaelem;
|
||||
|
||||
extern PyTypeObject MetaElemSeq_Type;
|
||||
|
||||
#define BPy_MetaElemSeq_Check(v) ((v)->ob_type==&MetaElemSeq_Type)
|
||||
|
||||
/* Python BPy_MetaElemSeq structure definition */
|
||||
typedef struct {
|
||||
PyObject_HEAD /* required py macro */
|
||||
BPy_Metaball *bpymetaball; /* link to the python group so we can know if its been removed */
|
||||
MetaElem * iter; /* so we can iterate over the objects */
|
||||
} BPy_MetaElemSeq;
|
||||
|
||||
/*
|
||||
* prototypes
|
||||
*/
|
||||
|
||||
PyObject *Metaball_Init( void );
|
||||
PyObject *Metaball_CreatePyObject( MetaBall * mball );
|
||||
MetaBall *Metaball_FromPyObject( PyObject * py_obj );
|
||||
|
||||
#endif /* EXPP_METABALL_H */
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,69 +0,0 @@
|
||||
/*
|
||||
* $Id$
|
||||
*
|
||||
* ***** 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*
|
||||
* The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This is a new part of Blender.
|
||||
*
|
||||
* Contributor(s): Ken Hughes
|
||||
*
|
||||
* ***** END GPL LICENSE BLOCK *****
|
||||
*/
|
||||
|
||||
#ifndef EXPP_MODIFIER_H
|
||||
#define EXPP_MODIFIER_H
|
||||
|
||||
#include <Python.h>
|
||||
#include "DNA_object_types.h"
|
||||
#include "DNA_modifier_types.h"
|
||||
#include "DNA_listBase.h"
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Python BPy_Modifier and BPy_ModSeq structure definition: */
|
||||
/*****************************************************************************/
|
||||
typedef struct {
|
||||
PyObject_HEAD /* required macro */
|
||||
Object *object;
|
||||
ModifierData *iter;
|
||||
} BPy_ModSeq;
|
||||
|
||||
typedef struct {
|
||||
PyObject_HEAD /* required macro */
|
||||
Object *object;
|
||||
/* if md this is null, the modifier has been removed and we need to raise
|
||||
an error when its data is accessed */
|
||||
ModifierData *md;
|
||||
} BPy_Modifier;
|
||||
|
||||
extern PyTypeObject ModSeq_Type;
|
||||
extern PyTypeObject Modifier_Type;
|
||||
#define BPy_ModSeq_Check(v) ((v)->ob_type == &ModSeq_Type)
|
||||
#define BPy_Modifier_Check(v) ((v)->ob_type == &Modifier_Type)
|
||||
|
||||
/*
|
||||
* prototypes
|
||||
*/
|
||||
|
||||
PyObject *Modifier_Init( void );
|
||||
PyObject *ModSeq_CreatePyObject( Object *obj, ModifierData *iter );
|
||||
PyObject *Modifier_CreatePyObject( Object *obj, ModifierData *md );
|
||||
ModifierData *Modifier_FromPyObject( PyObject * py_obj );
|
||||
|
||||
#endif /* EXPP_MODIFIER_H */
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,74 +0,0 @@
|
||||
/*
|
||||
* $Id$
|
||||
*
|
||||
* ***** 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*
|
||||
* The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This is a new part of Blender.
|
||||
*
|
||||
* Contributor(s): Joseph Gilbert, Ken Hughes
|
||||
*
|
||||
* ***** END GPL LICENSE BLOCK *****
|
||||
*/
|
||||
|
||||
#ifndef EXPP_NLA_H
|
||||
#define EXPP_NLA_H
|
||||
|
||||
#include <Python.h>
|
||||
#include "DNA_action_types.h"
|
||||
#include "DNA_nla_types.h"
|
||||
|
||||
struct Object;
|
||||
|
||||
/** NLA module initialization function. */
|
||||
PyObject *NLA_Init( void );
|
||||
|
||||
extern PyTypeObject Action_Type;
|
||||
extern PyTypeObject ActionStrip_Type;
|
||||
extern PyTypeObject ActionStrips_Type;
|
||||
|
||||
/** Python BPy_NLA structure definition. */
|
||||
typedef struct {
|
||||
PyObject_HEAD
|
||||
bAction * action; /* libdata must be second */
|
||||
} BPy_Action;
|
||||
|
||||
typedef struct {
|
||||
PyObject_HEAD
|
||||
bActionStrip * strip;
|
||||
} BPy_ActionStrip;
|
||||
|
||||
typedef struct {
|
||||
PyObject_HEAD
|
||||
struct Object * ob;
|
||||
struct bActionStrip *iter;
|
||||
} BPy_ActionStrips;
|
||||
|
||||
/* Type checking for EXPP PyTypes */
|
||||
#define BPy_Action_Check(v) ((v)->ob_type == &Action_Type)
|
||||
#define BPy_ActionStrip_Check(v) ((v)->ob_type == &ActionStrip_Type)
|
||||
#define BPy_ActionStrips_Check(v) ((v)->ob_type == &ActionStrips_Type)
|
||||
|
||||
PyObject *Action_CreatePyObject( struct bAction *action );
|
||||
bAction *Action_FromPyObject( PyObject * py_obj );
|
||||
|
||||
PyObject *ActionStrip_CreatePyObject( struct bActionStrip *strip );
|
||||
PyObject *ActionStrips_CreatePyObject( struct Object *ob );
|
||||
|
||||
#endif
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,154 +0,0 @@
|
||||
/*
|
||||
* $Id$
|
||||
*
|
||||
* ***** 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*
|
||||
* The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This is a new part of Blender.
|
||||
*
|
||||
* Contributor(s): Willian P. Germano, Jordi Rovira i Bonnet, Joseph Gilbert.
|
||||
*
|
||||
* ***** END GPL LICENSE BLOCK *****
|
||||
*/
|
||||
|
||||
/* Most of this file comes from opy_nmesh.[ch] in the old bpython dir */
|
||||
|
||||
#ifndef EXPP_NMESH_H
|
||||
#define EXPP_NMESH_H
|
||||
|
||||
#include <Python.h>
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
|
||||
#include "DNA_customdata_types.h"
|
||||
#include "DNA_object_types.h"
|
||||
#include "DNA_mesh_types.h"
|
||||
#include "DNA_meshdata_types.h"
|
||||
#include "Material.h"
|
||||
#include "Image.h"
|
||||
|
||||
/* EXPP PyType Objects */
|
||||
extern PyTypeObject NMesh_Type;
|
||||
extern PyTypeObject NMFace_Type;
|
||||
extern PyTypeObject NMVert_Type;
|
||||
extern PyTypeObject NMCol_Type;
|
||||
extern PyTypeObject NMEdge_Type;
|
||||
|
||||
|
||||
struct BPy_Object;
|
||||
|
||||
/* These are from blender/src/editdeform.c, should be declared elsewhere,
|
||||
* maybe in BIF_editdeform.h, after proper testing of vgrouping methods XXX */
|
||||
|
||||
extern void add_vert_defnr( Object * ob, int def_nr, int vertnum, float weight,
|
||||
int assignmode );
|
||||
extern void remove_vert_def_nr( Object * ob, int def_nr, int vertnum );
|
||||
|
||||
|
||||
|
||||
/* Type checking for EXPP PyTypes */
|
||||
#define BPy_NMesh_Check(v) ((v)->ob_type == &NMesh_Type)
|
||||
#define BPy_NMFace_Check(v) ((v)->ob_type == &NMFace_Type)
|
||||
#define BPy_NMVert_Check(v) ((v)->ob_type == &NMVert_Type)
|
||||
#define BPy_NMCol_Check(v) ((v)->ob_type == &NMCol_Type)
|
||||
#define BPy_NMEdge_Check(v) ((v)->ob_type == &NMEdge_Type)
|
||||
|
||||
/* Typedefs for the new types */
|
||||
|
||||
typedef struct {
|
||||
PyObject_HEAD /* required python macro */
|
||||
unsigned char r, g, b, a;
|
||||
|
||||
} BPy_NMCol; /* an NMesh color: [r,g,b,a] */
|
||||
|
||||
typedef struct {
|
||||
PyObject_VAR_HEAD /* required python macro */
|
||||
float co[3];
|
||||
float no[3];
|
||||
float uvco[3];
|
||||
int index;
|
||||
char flag; /* see MVert flag in DNA_meshdata_types */
|
||||
|
||||
} BPy_NMVert; /* an NMesh vertex */
|
||||
|
||||
typedef struct {
|
||||
PyObject_HEAD /* required python macro */
|
||||
PyObject * v;
|
||||
PyObject *uv;
|
||||
PyObject *col;
|
||||
short mode;
|
||||
short flag; /* tface->flag */
|
||||
unsigned char transp;
|
||||
Image *image;
|
||||
char mat_nr, mf_flag /* was char smooth */;
|
||||
int orig_index;
|
||||
|
||||
} BPy_NMFace; /* an NMesh face */
|
||||
|
||||
typedef struct {
|
||||
PyObject_HEAD /* required python macro */
|
||||
PyObject *v1;
|
||||
PyObject *v2;
|
||||
char crease;
|
||||
short flag;
|
||||
} BPy_NMEdge; /* an NMesh edge */
|
||||
|
||||
typedef struct {
|
||||
PyObject_HEAD /* required python macro */
|
||||
Mesh * mesh; /* libdata must be second */
|
||||
Object *object; /* for vertex grouping info, since it's stored on the object */
|
||||
PyObject *name;
|
||||
PyObject *materials;
|
||||
PyObject *verts;
|
||||
PyObject *faces;
|
||||
PyObject *edges;
|
||||
int sel_face; /*@ XXX remove */
|
||||
short smoothresh; /* max AutoSmooth angle */
|
||||
short subdiv[2]; /* SubDiv Levels: display and rendering */
|
||||
short mode; /* see the EXPP_NMESH_* defines in the beginning of this file */
|
||||
char flags;
|
||||
|
||||
#define NMESH_HASMCOL (1<<0)
|
||||
#define NMESH_HASVERTUV (1<<1)
|
||||
#define NMESH_HASFACEUV (1<<2)
|
||||
|
||||
/* stores original data that is not accesible through NMesh, but that we
|
||||
still want to preserve, indexed by orig_index in NMFace */
|
||||
CustomData fdata;
|
||||
int totfdata;
|
||||
|
||||
} BPy_NMesh;
|
||||
|
||||
/* PROTOS */
|
||||
|
||||
PyObject *NMesh_Init( void );
|
||||
PyObject *NMesh_CreatePyObject( Mesh * me, Object * ob );
|
||||
Mesh *NMesh_FromPyObject( PyObject * pyobj, Object * ob );
|
||||
|
||||
void mesh_update( Mesh * mesh , Object * ob );
|
||||
PyObject *new_NMesh( Mesh * oldmesh );
|
||||
Mesh *Mesh_fromNMesh( BPy_NMesh * nmesh );
|
||||
PyObject *NMesh_assignMaterials_toObject( BPy_NMesh * nmesh, Object * ob );
|
||||
Material **nmesh_updateMaterials( BPy_NMesh * nmesh );
|
||||
Material **newMaterialList_fromPyList( PyObject * list );
|
||||
|
||||
|
||||
#endif /* EXPP_NMESH_H */
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,103 +0,0 @@
|
||||
/*
|
||||
* $Id$
|
||||
*
|
||||
* ***** 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*
|
||||
* The Original Code is Copyright (C) 2006, Blender Foundation
|
||||
* All rights reserved.
|
||||
*
|
||||
* Original code is this file
|
||||
*
|
||||
* Contributor(s): Nathan Letwory
|
||||
*
|
||||
* ***** END GPL LICENSE BLOCK *****
|
||||
*/
|
||||
|
||||
#ifndef __NODE_H__
|
||||
#define __NODE_H__
|
||||
|
||||
#include <Python.h>
|
||||
#include "DNA_node_types.h"
|
||||
#include "BKE_node.h"
|
||||
|
||||
#include "RE_shader_ext.h" /* <- ShadeInput Shaderesult TexResult */
|
||||
|
||||
extern PyTypeObject Node_Type;
|
||||
extern PyTypeObject NodeSocket_Type;
|
||||
extern PyTypeObject NodeSocketLists_Type;
|
||||
extern PyTypeObject ShadeInput_Type;
|
||||
|
||||
#define BPy_Node_Check(v) \
|
||||
((v)->ob_type == &Node_Type)
|
||||
|
||||
#define BPy_NodeSocket_Check(v) \
|
||||
((v)->ob_type == &NodeSocket_Type)
|
||||
|
||||
#define BPy_NodeSocketLists_Check(v) \
|
||||
((v)->ob_type == &NodeSocketLists_Type)
|
||||
|
||||
#define BPy_ShadeInput_Check(v) \
|
||||
((v)->ob_type == &ShadeInput_Type)
|
||||
|
||||
typedef struct BPy_ShadeInput {
|
||||
PyObject_HEAD
|
||||
ShadeInput *shi;
|
||||
} BPy_ShadeInput;
|
||||
|
||||
typedef struct {
|
||||
PyObject_VAR_HEAD
|
||||
bNode* node;
|
||||
bNodeStack **stack;
|
||||
} BPy_SockMap;
|
||||
|
||||
typedef struct {
|
||||
PyObject_HEAD
|
||||
bNode *node;
|
||||
PyObject *input;
|
||||
PyObject *output;
|
||||
} BPy_NodeSocketLists;
|
||||
|
||||
typedef struct BPy_Node {
|
||||
PyObject_HEAD
|
||||
bNode *node;
|
||||
bNodeStack **in;
|
||||
bNodeStack **out;
|
||||
ShadeInput *shi;
|
||||
} BPy_Node;
|
||||
|
||||
typedef struct BPy_NodeSocket {
|
||||
PyObject_HEAD
|
||||
char name[NODE_MAXSTR];
|
||||
float min;
|
||||
float max;
|
||||
float val[4];
|
||||
short type; /* VALUE, VECTOR or RGBA */
|
||||
} BPy_NodeSocket;
|
||||
|
||||
extern PyObject *Node_Init(void);
|
||||
extern void InitNode(BPy_Node *self, bNode *node);
|
||||
extern BPy_Node *Node_CreatePyObject(bNode *node);
|
||||
extern BPy_NodeSocketLists *Node_CreateSocketLists(bNode *node);
|
||||
extern void Node_SetStack(BPy_Node *self, bNodeStack **stack, int type);
|
||||
extern void Node_SetShi(BPy_Node *self, ShadeInput *shi);
|
||||
extern int pytype_is_pynode(PyObject *pyob);
|
||||
|
||||
#define NODE_INPUTSTACK 0
|
||||
#define NODE_OUTPUTSTACK 1
|
||||
|
||||
#endif /* __NODE_H__*/
|
||||
|
||||
@@ -1,710 +0,0 @@
|
||||
/**
|
||||
* $Id$
|
||||
*
|
||||
* Blender.Noise BPython module implementation.
|
||||
* This submodule has functions to generate noise of various types.
|
||||
*
|
||||
* ***** 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*
|
||||
* The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This is a new part of Blender.
|
||||
*
|
||||
* Contributor(s): eeshlo
|
||||
*
|
||||
* ***** END GPL LICENSE BLOCK *****
|
||||
*/
|
||||
|
||||
/************************/
|
||||
/* Blender Noise Module */
|
||||
/************************/
|
||||
|
||||
#include <Python.h>
|
||||
|
||||
#include "BLI_blenlib.h"
|
||||
#include "DNA_texture_types.h"
|
||||
#include "constant.h"
|
||||
|
||||
/*-----------------------------------------*/
|
||||
/* 'mersenne twister' random number generator */
|
||||
|
||||
/*
|
||||
A C-program for MT19937, with initialization improved 2002/2/10.
|
||||
Coded by Takuji Nishimura and Makoto Matsumoto.
|
||||
This is a faster version by taking Shawn Cokus's optimization,
|
||||
Matthe Bellew's simplification, Isaku Wada's real version.
|
||||
|
||||
Before using, initialize the state by using init_genrand(seed)
|
||||
or init_by_array(init_key, key_length).
|
||||
|
||||
Copyright (C) 1997 - 2002, Makoto Matsumoto and Takuji Nishimura,
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions
|
||||
are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in the
|
||||
documentation and/or other materials provided with the distribution.
|
||||
|
||||
3. The names of its contributors may not be used to endorse or promote
|
||||
products derived from this software without specific prior written
|
||||
permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
|
||||
Any feedback is very welcome.
|
||||
http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/emt.html
|
||||
email: m-mat @ math.sci.hiroshima-u.ac.jp (remove space)
|
||||
*/
|
||||
|
||||
/* Period parameters */
|
||||
#define N 624
|
||||
#define M 397
|
||||
#define MATRIX_A 0x9908b0dfUL /* constant vector a */
|
||||
#define UMASK 0x80000000UL /* most significant w-r bits */
|
||||
#define LMASK 0x7fffffffUL /* least significant r bits */
|
||||
#define MIXBITS(u,v) ( ((u) & UMASK) | ((v) & LMASK) )
|
||||
#define TWIST(u,v) ((MIXBITS(u,v) >> 1) ^ ((v)&1UL ? MATRIX_A : 0UL))
|
||||
|
||||
static unsigned long state[N]; /* the array for the state vector */
|
||||
static int left = 1;
|
||||
static int initf = 0;
|
||||
static unsigned long *next;
|
||||
|
||||
PyObject *Noise_Init(void);
|
||||
|
||||
/* initializes state[N] with a seed */
|
||||
static void init_genrand( unsigned long s )
|
||||
{
|
||||
int j;
|
||||
state[0] = s & 0xffffffffUL;
|
||||
for( j = 1; j < N; j++ ) {
|
||||
state[j] =
|
||||
( 1812433253UL *
|
||||
( state[j - 1] ^ ( state[j - 1] >> 30 ) ) + j );
|
||||
/* See Knuth TAOCP Vol2. 3rd Ed. P.106 for multiplier. */
|
||||
/* In the previous versions, MSBs of the seed affect */
|
||||
/* only MSBs of the array state[]. */
|
||||
/* 2002/01/09 modified by Makoto Matsumoto */
|
||||
state[j] &= 0xffffffffUL; /* for >32 bit machines */
|
||||
}
|
||||
left = 1;
|
||||
initf = 1;
|
||||
}
|
||||
|
||||
static void next_state( void )
|
||||
{
|
||||
unsigned long *p = state;
|
||||
int j;
|
||||
|
||||
/* if init_genrand() has not been called, */
|
||||
/* a default initial seed is used */
|
||||
if( initf == 0 )
|
||||
init_genrand( 5489UL );
|
||||
|
||||
left = N;
|
||||
next = state;
|
||||
|
||||
for( j = N - M + 1; --j; p++ )
|
||||
*p = p[M] ^ TWIST( p[0], p[1] );
|
||||
|
||||
for( j = M; --j; p++ )
|
||||
*p = p[M - N] ^ TWIST( p[0], p[1] );
|
||||
|
||||
*p = p[M - N] ^ TWIST( p[0], state[0] );
|
||||
}
|
||||
|
||||
/*------------------------------------------------------------*/
|
||||
|
||||
static void setRndSeed( int seed )
|
||||
{
|
||||
if( seed == 0 )
|
||||
init_genrand( time( NULL ) );
|
||||
else
|
||||
init_genrand( seed );
|
||||
}
|
||||
|
||||
/* float number in range [0, 1) using the mersenne twister rng */
|
||||
static float frand( )
|
||||
{
|
||||
unsigned long y;
|
||||
|
||||
if( --left == 0 )
|
||||
next_state( );
|
||||
y = *next++;
|
||||
|
||||
/* Tempering */
|
||||
y ^= ( y >> 11 );
|
||||
y ^= ( y << 7 ) & 0x9d2c5680UL;
|
||||
y ^= ( y << 15 ) & 0xefc60000UL;
|
||||
y ^= ( y >> 18 );
|
||||
|
||||
return ( float ) y / 4294967296.f;
|
||||
}
|
||||
|
||||
/*------------------------------------------------------------*/
|
||||
|
||||
/* returns random unit vector */
|
||||
static void randuvec( float v[3] )
|
||||
{
|
||||
float r;
|
||||
v[2] = 2.f * frand( ) - 1.f;
|
||||
if( ( r = 1.f - v[2] * v[2] ) > 0.f ) {
|
||||
float a = (float)(6.283185307f * frand( ));
|
||||
r = (float)sqrt( r );
|
||||
v[0] = (float)(r * cos( a ));
|
||||
v[1] = (float)(r * sin( a ));
|
||||
} else
|
||||
v[2] = 1.f;
|
||||
}
|
||||
|
||||
static PyObject *Noise_random( PyObject * self )
|
||||
{
|
||||
return Py_BuildValue( "f", frand( ) );
|
||||
}
|
||||
|
||||
static PyObject *Noise_randuvec( PyObject * self )
|
||||
{
|
||||
float v[3] = {0.0f, 0.0f, 0.0f};
|
||||
randuvec( v );
|
||||
return Py_BuildValue( "[fff]", v[0], v[1], v[2] );
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------*/
|
||||
|
||||
/* Random seed init. Only used for MT random() & randuvec() */
|
||||
|
||||
static PyObject *Noise_setRandomSeed( PyObject * self, PyObject * args )
|
||||
{
|
||||
int s;
|
||||
if( !PyArg_ParseTuple( args, "i", &s ) )
|
||||
return NULL;
|
||||
setRndSeed( s );
|
||||
Py_INCREF( Py_None );
|
||||
return Py_None;
|
||||
}
|
||||
|
||||
/*-------------------------------------------------------------------------*/
|
||||
|
||||
/* General noise */
|
||||
|
||||
static PyObject *Noise_noise( PyObject * self, PyObject * args )
|
||||
{
|
||||
float x, y, z;
|
||||
int nb = 1;
|
||||
if( !PyArg_ParseTuple( args, "(fff)|i", &x, &y, &z, &nb ) )
|
||||
return NULL;
|
||||
|
||||
return PyFloat_FromDouble(
|
||||
(double)(2.0 * BLI_gNoise( 1.0, x, y, z, 0, nb ) - 1.0) );
|
||||
}
|
||||
|
||||
/*-------------------------------------------------------------------------*/
|
||||
|
||||
/* General Vector noise */
|
||||
|
||||
static void vNoise( float x, float y, float z, int nb, float v[3] )
|
||||
{
|
||||
/* Simply evaluate noise at 3 different positions */
|
||||
v[0] = (float)(2.0 * BLI_gNoise( 1.f, x + 9.321f, y - 1.531f, z - 7.951f, 0,
|
||||
nb ) - 1.0);
|
||||
v[1] = (float)(2.0 * BLI_gNoise( 1.f, x, y, z, 0, nb ) - 1.0);
|
||||
v[2] = (float)(2.0 * BLI_gNoise( 1.f, x + 6.327f, y + 0.1671f, z - 2.672f, 0,
|
||||
nb ) - 1.0);
|
||||
}
|
||||
|
||||
static PyObject *Noise_vNoise( PyObject * self, PyObject * args )
|
||||
{
|
||||
float x, y, z, v[3];
|
||||
int nb = 1;
|
||||
if( !PyArg_ParseTuple( args, "(fff)|i", &x, &y, &z, &nb ) )
|
||||
return NULL;
|
||||
vNoise( x, y, z, nb, v );
|
||||
return Py_BuildValue( "[fff]", v[0], v[1], v[2] );
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
|
||||
/* General turbulence */
|
||||
|
||||
static float turb( float x, float y, float z, int oct, int hard, int nb,
|
||||
float ampscale, float freqscale )
|
||||
{
|
||||
float amp, out, t;
|
||||
int i;
|
||||
amp = 1.f;
|
||||
out = (float)(2.0 * BLI_gNoise( 1.f, x, y, z, 0, nb ) - 1.0);
|
||||
if( hard )
|
||||
out = (float)fabs( out );
|
||||
for( i = 1; i < oct; i++ ) {
|
||||
amp *= ampscale;
|
||||
x *= freqscale;
|
||||
y *= freqscale;
|
||||
z *= freqscale;
|
||||
t = (float)(amp * ( 2.0 * BLI_gNoise( 1.f, x, y, z, 0, nb ) - 1.0 ));
|
||||
if( hard )
|
||||
t = (float)fabs( t );
|
||||
out += t;
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
static PyObject *Noise_turbulence( PyObject * self, PyObject * args )
|
||||
{
|
||||
float x, y, z;
|
||||
int oct, hd, nb = 1;
|
||||
float as = 0.5, fs = 2.0;
|
||||
if( !PyArg_ParseTuple
|
||||
( args, "(fff)ii|iff", &x, &y, &z, &oct, &hd, &nb, &as, &fs ) )
|
||||
return NULL;
|
||||
return PyFloat_FromDouble( (double)turb( x, y, z, oct, hd, nb, as, fs ) );
|
||||
}
|
||||
|
||||
/*--------------------------------------------------------------------------*/
|
||||
|
||||
/* Turbulence Vector */
|
||||
|
||||
static void vTurb( float x, float y, float z, int oct, int hard, int nb,
|
||||
float ampscale, float freqscale, float v[3] )
|
||||
{
|
||||
float amp, t[3];
|
||||
int i;
|
||||
amp = 1.f;
|
||||
vNoise( x, y, z, nb, v );
|
||||
if( hard ) {
|
||||
v[0] = (float)fabs( v[0] );
|
||||
v[1] = (float)fabs( v[1] );
|
||||
v[2] = (float)fabs( v[2] );
|
||||
}
|
||||
for( i = 1; i < oct; i++ ) {
|
||||
amp *= ampscale;
|
||||
x *= freqscale;
|
||||
y *= freqscale;
|
||||
z *= freqscale;
|
||||
vNoise( x, y, z, nb, t );
|
||||
if( hard ) {
|
||||
t[0] = (float)fabs( t[0] );
|
||||
t[1] = (float)fabs( t[1] );
|
||||
t[2] = (float)fabs( t[2] );
|
||||
}
|
||||
v[0] += amp * t[0];
|
||||
v[1] += amp * t[1];
|
||||
v[2] += amp * t[2];
|
||||
}
|
||||
}
|
||||
|
||||
static PyObject *Noise_vTurbulence( PyObject * self, PyObject * args )
|
||||
{
|
||||
float x, y, z, v[3];
|
||||
int oct, hd, nb = 1;
|
||||
float as = 0.5, fs = 2.0;
|
||||
if( !PyArg_ParseTuple
|
||||
( args, "(fff)ii|iff", &x, &y, &z, &oct, &hd, &nb, &as, &fs ) )
|
||||
return NULL;
|
||||
vTurb( x, y, z, oct, hd, nb, as, fs, v );
|
||||
return Py_BuildValue( "[fff]", v[0], v[1], v[2] );
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------*/
|
||||
|
||||
/* F. Kenton Musgrave's fractal functions */
|
||||
|
||||
static PyObject *Noise_fBm( PyObject * self, PyObject * args )
|
||||
{
|
||||
float x, y, z, H, lac, oct;
|
||||
int nb = 1;
|
||||
if( !PyArg_ParseTuple
|
||||
( args, "(fff)fff|i", &x, &y, &z, &H, &lac, &oct, &nb ) )
|
||||
return NULL;
|
||||
return PyFloat_FromDouble( (double)mg_fBm( x, y, z, H, lac, oct, nb ) );
|
||||
}
|
||||
|
||||
/*------------------------------------------------------------------------*/
|
||||
|
||||
static PyObject *Noise_multiFractal( PyObject * self, PyObject * args )
|
||||
{
|
||||
float x, y, z, H, lac, oct;
|
||||
int nb = 1;
|
||||
if( !PyArg_ParseTuple
|
||||
( args, "(fff)fff|i", &x, &y, &z, &H, &lac, &oct, &nb ) )
|
||||
return NULL;
|
||||
return PyFloat_FromDouble( (double)mg_MultiFractal( x, y, z, H, lac, oct, nb ) );
|
||||
}
|
||||
|
||||
/*------------------------------------------------------------------------*/
|
||||
|
||||
static PyObject *Noise_vlNoise( PyObject * self, PyObject * args )
|
||||
{
|
||||
float x, y, z, d;
|
||||
int nt1 = 1, nt2 = 1;
|
||||
if( !PyArg_ParseTuple
|
||||
( args, "(fff)f|ii", &x, &y, &z, &d, &nt1, &nt2 ) )
|
||||
return NULL;
|
||||
return PyFloat_FromDouble( (double)mg_VLNoise( x, y, z, d, nt1, nt2 ) );
|
||||
}
|
||||
|
||||
/*-------------------------------------------------------------------------*/
|
||||
|
||||
static PyObject *Noise_heteroTerrain( PyObject * self, PyObject * args )
|
||||
{
|
||||
float x, y, z, H, lac, oct, ofs;
|
||||
int nb = 1;
|
||||
if( !PyArg_ParseTuple
|
||||
( args, "(fff)ffff|i", &x, &y, &z, &H, &lac, &oct, &ofs, &nb ) )
|
||||
return NULL;
|
||||
|
||||
return PyFloat_FromDouble(
|
||||
(double)mg_HeteroTerrain( x, y, z, H, lac, oct, ofs, nb ) );
|
||||
}
|
||||
|
||||
/*-------------------------------------------------------------------------*/
|
||||
|
||||
static PyObject *Noise_hybridMFractal( PyObject * self, PyObject * args )
|
||||
{
|
||||
float x, y, z, H, lac, oct, ofs, gn;
|
||||
int nb = 1;
|
||||
if( !PyArg_ParseTuple
|
||||
( args, "(fff)fffff|i", &x, &y, &z, &H, &lac, &oct, &ofs, &gn,
|
||||
&nb ) )
|
||||
return NULL;
|
||||
|
||||
return PyFloat_FromDouble(
|
||||
(double)mg_HybridMultiFractal( x, y, z, H, lac, oct, ofs, gn, nb) );
|
||||
}
|
||||
|
||||
/*------------------------------------------------------------------------*/
|
||||
|
||||
static PyObject *Noise_ridgedMFractal( PyObject * self, PyObject * args )
|
||||
{
|
||||
float x, y, z, H, lac, oct, ofs, gn;
|
||||
int nb = 1;
|
||||
if( !PyArg_ParseTuple
|
||||
( args, "(fff)fffff|i", &x, &y, &z, &H, &lac, &oct, &ofs, &gn,
|
||||
&nb ) )
|
||||
return NULL;
|
||||
return PyFloat_FromDouble(
|
||||
(double)mg_RidgedMultiFractal( x, y, z, H, lac, oct, ofs, gn, nb) );
|
||||
}
|
||||
|
||||
/*-------------------------------------------------------------------------*/
|
||||
|
||||
static PyObject *Noise_voronoi( PyObject * self, PyObject * args )
|
||||
{
|
||||
float x, y, z, da[4], pa[12];
|
||||
int dtype = 0;
|
||||
float me = 2.5; /* default minkovsky exponent */
|
||||
if( !PyArg_ParseTuple( args, "(fff)|if", &x, &y, &z, &dtype, &me ) )
|
||||
return NULL;
|
||||
voronoi( x, y, z, da, pa, me, dtype );
|
||||
return Py_BuildValue( "[[ffff][[fff][fff][fff][fff]]]",
|
||||
da[0], da[1], da[2], da[3],
|
||||
pa[0], pa[1], pa[2],
|
||||
pa[3], pa[4], pa[5],
|
||||
pa[6], pa[7], pa[8], pa[9], pa[10], pa[11] );
|
||||
}
|
||||
|
||||
/*-------------------------------------------------------------------------*/
|
||||
|
||||
static PyObject *Noise_cellNoise( PyObject * self, PyObject * args )
|
||||
{
|
||||
float x, y, z;
|
||||
if( !PyArg_ParseTuple( args, "(fff)", &x, &y, &z ) )
|
||||
return NULL;
|
||||
return Py_BuildValue( "f", cellNoise( x, y, z ) );
|
||||
}
|
||||
|
||||
/*--------------------------------------------------------------------------*/
|
||||
|
||||
static PyObject *Noise_cellNoiseV( PyObject * self, PyObject * args )
|
||||
{
|
||||
float x, y, z, ca[3];
|
||||
if( !PyArg_ParseTuple( args, "(fff)", &x, &y, &z ) )
|
||||
return NULL;
|
||||
cellNoiseV( x, y, z, ca );
|
||||
return Py_BuildValue( "[fff]", ca[0], ca[1], ca[2] );
|
||||
}
|
||||
|
||||
/*--------------------------------------------------------------------------*/
|
||||
/* For all other Blender modules, this stuff seems to be put in a header file.
|
||||
This doesn't seem really appropriate to me, so I just put it here, feel free to change it.
|
||||
In the original module I actually kept the docs stings with the functions themselves,
|
||||
but I grouped them here so that it can easily be moved to a header if anyone thinks that is necessary. */
|
||||
|
||||
static char random__doc__[] = "() No arguments.\n\n\
|
||||
Returns a random floating point number in the range [0, 1)";
|
||||
|
||||
static char randuvec__doc__[] =
|
||||
"() No arguments.\n\nReturns a random unit vector (3-float list).";
|
||||
|
||||
static char setRandomSeed__doc__[] = "(seed value)\n\n\
|
||||
Initializes random number generator.\n\
|
||||
if seed is zero, the current time will be used instead.";
|
||||
|
||||
static char noise__doc__[] = "((x,y,z) tuple, [noisetype])\n\n\
|
||||
Returns general noise of the optional specified type.\n\
|
||||
Optional argument noisetype determines the type of noise, STDPERLIN by default, see NoiseTypes.";
|
||||
|
||||
static char vNoise__doc__[] = "((x,y,z) tuple, [noisetype])\n\n\
|
||||
Returns noise vector (3-float list) of the optional specified type.\
|
||||
Optional argument noisetype determines the type of noise, STDPERLIN by default, see NoiseTypes.";
|
||||
|
||||
static char turbulence__doc__[] =
|
||||
"((x,y,z) tuple, octaves, hard, [noisebasis], [ampscale], [freqscale])\n\n\
|
||||
Returns general turbulence value using the optional specified noisebasis function.\n\
|
||||
octaves (integer) is the number of noise values added.\n\
|
||||
hard (bool), when false (0) returns 'soft' noise, when true (1) returns 'hard' noise (returned value always positive).\n\
|
||||
Optional arguments:\n\
|
||||
noisebasis determines the type of noise used for the turbulence, STDPERLIN by default, see NoiseTypes.\n\
|
||||
ampscale sets the amplitude scale value of the noise frequencies added, 0.5 by default.\n\
|
||||
freqscale sets the frequency scale factor, 2.0 by default.";
|
||||
|
||||
static char vTurbulence__doc__[] =
|
||||
"((x,y,z) tuple, octaves, hard, [noisebasis], [ampscale], [freqscale])\n\n\
|
||||
Returns general turbulence vector (3-float list) using the optional specified noisebasis function.\n\
|
||||
octaves (integer) is the number of noise values added.\n\
|
||||
hard (bool), when false (0) returns 'soft' noise, when true (1) returns 'hard' noise (returned vector always positive).\n\
|
||||
Optional arguments:\n\
|
||||
noisebasis determines the type of noise used for the turbulence, STDPERLIN by default, see NoiseTypes.\n\
|
||||
ampscale sets the amplitude scale value of the noise frequencies added, 0.5 by default.\n\
|
||||
freqscale sets the frequency scale factor, 2.0 by default.";
|
||||
|
||||
static char fBm__doc__[] =
|
||||
"((x,y,z) tuple, H, lacunarity, octaves, [noisebasis])\n\n\
|
||||
Returns Fractal Brownian Motion noise value(fBm).\n\
|
||||
H is the fractal increment parameter.\n\
|
||||
lacunarity is the gap between successive frequencies.\n\
|
||||
octaves is the number of frequencies in the fBm.\n\
|
||||
Optional argument noisebasis determines the type of noise used for the turbulence, STDPERLIN by default, see NoiseTypes.";
|
||||
|
||||
static char multiFractal__doc__[] =
|
||||
"((x,y,z) tuple, H, lacunarity, octaves, [noisebasis])\n\n\
|
||||
Returns Multifractal noise value.\n\
|
||||
H determines the highest fractal dimension.\n\
|
||||
lacunarity is gap between successive frequencies.\n\
|
||||
octaves is the number of frequencies in the fBm.\n\
|
||||
Optional argument noisebasis determines the type of noise used for the turbulence, STDPERLIN by default, see NoiseTypes.";
|
||||
|
||||
static char vlNoise__doc__[] =
|
||||
"((x,y,z) tuple, distortion, [noisetype1], [noisetype2])\n\n\
|
||||
Returns Variable Lacunarity Noise value, a distorted variety of noise.\n\
|
||||
distortion sets the amount of distortion.\n\
|
||||
Optional arguments noisetype1 and noisetype2 set the noisetype to distort and the noisetype used for the distortion respectively.\n\
|
||||
See NoiseTypes, both are STDPERLIN by default.";
|
||||
|
||||
static char heteroTerrain__doc__[] =
|
||||
"((x,y,z) tuple, H, lacunarity, octaves, offset, [noisebasis])\n\n\
|
||||
returns Heterogeneous Terrain value\n\
|
||||
H determines the fractal dimension of the roughest areas.\n\
|
||||
lacunarity is the gap between successive frequencies.\n\
|
||||
octaves is the number of frequencies in the fBm.\n\
|
||||
offset raises the terrain from 'sea level'.\n\
|
||||
Optional argument noisebasis determines the type of noise used for the turbulence, STDPERLIN by default, see NoiseTypes.";
|
||||
|
||||
static char hybridMFractal__doc__[] =
|
||||
"((x,y,z) tuple, H, lacunarity, octaves, offset, gain, [noisebasis])\n\n\
|
||||
returns Hybrid Multifractal value.\n\
|
||||
H determines the fractal dimension of the roughest areas.\n\
|
||||
lacunarity is the gap between successive frequencies.\n\
|
||||
octaves is the number of frequencies in the fBm.\n\
|
||||
offset raises the terrain from 'sea level'.\n\
|
||||
gain scales the values.\n\
|
||||
Optional argument noisebasis determines the type of noise used for the turbulence, STDPERLIN by default, see NoiseTypes.";
|
||||
|
||||
static char ridgedMFractal__doc__[] =
|
||||
"((x,y,z) tuple, H, lacunarity, octaves, offset, gain [noisebasis])\n\n\
|
||||
returns Ridged Multifractal value.\n\
|
||||
H determines the fractal dimension of the roughest areas.\n\
|
||||
lacunarity is the gap between successive frequencies.\n\
|
||||
octaves is the number of frequencies in the fBm.\n\
|
||||
offset raises the terrain from 'sea level'.\n\
|
||||
gain scales the values.\n\
|
||||
Optional argument noisebasis determines the type of noise used for the turbulence, STDPERLIN by default, see NoiseTypes.";
|
||||
|
||||
static char voronoi__doc__[] =
|
||||
"((x,y,z) tuple, distance_metric, [exponent])\n\n\
|
||||
returns a list, containing a list of distances in order of closest feature,\n\
|
||||
and a list containing the positions of the four closest features\n\
|
||||
Optional arguments:\n\
|
||||
distance_metric: see DistanceMetrics, default is DISTANCE\n\
|
||||
exponent is only used with MINKOVSKY, default is 2.5.";
|
||||
|
||||
static char cellNoise__doc__[] = "((x,y,z) tuple)\n\n\
|
||||
returns cellnoise float value.";
|
||||
|
||||
static char cellNoiseV__doc__[] = "((x,y,z) tuple)\n\n\
|
||||
returns cellnoise vector/point/color (3-float list).";
|
||||
|
||||
static char Noise__doc__[] = "Blender Noise and Turbulence Module\n\n\
|
||||
This module can be used to generate noise of various types.\n\
|
||||
This can be used for terrain generation, to create textures,\n\
|
||||
make animations more 'animated', object deformation, etc.\n\
|
||||
As an example, this code segment when scriptlinked to a framechanged event,\n\
|
||||
will make the camera sway randomly about, by changing parameters this can\n\
|
||||
look like anything from an earthquake to a very nervous or maybe even drunk cameraman...\n\
|
||||
(the camera needs an ipo with at least one Loc & Rot key for this to work!):\n\
|
||||
\n\
|
||||
\tfrom Blender import Get, Scene, Noise\n\
|
||||
\n\
|
||||
\t####################################################\n\
|
||||
\t# This controls jitter speed\n\
|
||||
\tsl = 0.025\n\
|
||||
\t# This controls the amount of position jitter\n\
|
||||
\tsp = 0.1\n\
|
||||
\t# This controls the amount of rotation jitter\n\
|
||||
\tsr = 0.25\n\
|
||||
\t####################################################\n\
|
||||
\n\
|
||||
\ttime = Get('curtime')\n\
|
||||
\tob = Scene.GetCurrent().getCurrentCamera()\n\
|
||||
\tps = (sl*time, sl*time, sl*time)\n\
|
||||
\t# To add jitter only when the camera moves, use this next line instead\n\
|
||||
\t#ps = (sl*ob.LocX, sl*ob.LocY, sl*ob.LocZ)\n\
|
||||
\trv = Noise.vTurbulence(ps, 3, 0, Noise.NoiseTypes.NEWPERLIN)\n\
|
||||
\tob.dloc = (sp*rv[0], sp*rv[1], sp*rv[2])\n\
|
||||
\tob.drot = (sr*rv[0], sr*rv[1], sr*rv[2])\n\
|
||||
\n";
|
||||
|
||||
/* Just in case, declarations for a header file */
|
||||
/*
|
||||
static PyObject *Noise_random(PyObject *self);
|
||||
static PyObject *Noise_randuvec(PyObject *self);
|
||||
static PyObject *Noise_setRandomSeed(PyObject *self, PyObject *args);
|
||||
static PyObject *Noise_noise(PyObject *self, PyObject *args);
|
||||
static PyObject *Noise_vNoise(PyObject *self, PyObject *args);
|
||||
static PyObject *Noise_turbulence(PyObject *self, PyObject *args);
|
||||
static PyObject *Noise_vTurbulence(PyObject *self, PyObject *args);
|
||||
static PyObject *Noise_fBm(PyObject *self, PyObject *args);
|
||||
static PyObject *Noise_multiFractal(PyObject *self, PyObject *args);
|
||||
static PyObject *Noise_vlNoise(PyObject *self, PyObject *args);
|
||||
static PyObject *Noise_heteroTerrain(PyObject *self, PyObject *args);
|
||||
static PyObject *Noise_hybridMFractal(PyObject *self, PyObject *args);
|
||||
static PyObject *Noise_ridgedMFractal(PyObject *self, PyObject *args);
|
||||
static PyObject *Noise_voronoi(PyObject *self, PyObject *args);
|
||||
static PyObject *Noise_cellNoise(PyObject *self, PyObject *args);
|
||||
static PyObject *Noise_cellNoiseV(PyObject *self, PyObject *args);
|
||||
*/
|
||||
|
||||
static PyMethodDef NoiseMethods[] = {
|
||||
{"setRandomSeed", ( PyCFunction ) Noise_setRandomSeed, METH_VARARGS,
|
||||
setRandomSeed__doc__},
|
||||
{"random", ( PyCFunction ) Noise_random, METH_NOARGS, random__doc__},
|
||||
{"randuvec", ( PyCFunction ) Noise_randuvec, METH_NOARGS,
|
||||
randuvec__doc__},
|
||||
{"noise", ( PyCFunction ) Noise_noise, METH_VARARGS, noise__doc__},
|
||||
{"vNoise", ( PyCFunction ) Noise_vNoise, METH_VARARGS, vNoise__doc__},
|
||||
{"turbulence", ( PyCFunction ) Noise_turbulence, METH_VARARGS,
|
||||
turbulence__doc__},
|
||||
{"vTurbulence", ( PyCFunction ) Noise_vTurbulence, METH_VARARGS,
|
||||
vTurbulence__doc__},
|
||||
{"fBm", ( PyCFunction ) Noise_fBm, METH_VARARGS, fBm__doc__},
|
||||
{"multiFractal", ( PyCFunction ) Noise_multiFractal, METH_VARARGS,
|
||||
multiFractal__doc__},
|
||||
{"vlNoise", ( PyCFunction ) Noise_vlNoise, METH_VARARGS,
|
||||
vlNoise__doc__},
|
||||
{"heteroTerrain", ( PyCFunction ) Noise_heteroTerrain, METH_VARARGS,
|
||||
heteroTerrain__doc__},
|
||||
{"hybridMFractal", ( PyCFunction ) Noise_hybridMFractal, METH_VARARGS,
|
||||
hybridMFractal__doc__},
|
||||
{"ridgedMFractal", ( PyCFunction ) Noise_ridgedMFractal, METH_VARARGS,
|
||||
ridgedMFractal__doc__},
|
||||
{"voronoi", ( PyCFunction ) Noise_voronoi, METH_VARARGS,
|
||||
voronoi__doc__},
|
||||
{"cellNoise", ( PyCFunction ) Noise_cellNoise, METH_VARARGS,
|
||||
cellNoise__doc__},
|
||||
{"cellNoiseV", ( PyCFunction ) Noise_cellNoiseV, METH_VARARGS,
|
||||
cellNoiseV__doc__},
|
||||
{NULL, NULL, 0, NULL}
|
||||
};
|
||||
|
||||
/*----------------------------------------------------------------------*/
|
||||
|
||||
PyObject *Noise_Init(void)
|
||||
{
|
||||
PyObject *NoiseTypes, *DistanceMetrics,
|
||||
*md =
|
||||
Py_InitModule3( "Blender.Noise", NoiseMethods, Noise__doc__ );
|
||||
|
||||
/* use current time as seed for random number generator by default */
|
||||
setRndSeed( 0 );
|
||||
|
||||
/* Constant noisetype dictionary */
|
||||
NoiseTypes = PyConstant_New( );
|
||||
if( NoiseTypes ) {
|
||||
BPy_constant *nt = ( BPy_constant * ) NoiseTypes;
|
||||
PyConstant_Insert( nt, "BLENDER",
|
||||
PyInt_FromLong( TEX_BLENDER ) );
|
||||
PyConstant_Insert( nt, "STDPERLIN",
|
||||
PyInt_FromLong( TEX_STDPERLIN ) );
|
||||
PyConstant_Insert( nt, "NEWPERLIN",
|
||||
PyInt_FromLong( TEX_NEWPERLIN ) );
|
||||
PyConstant_Insert( nt, "VORONOI_F1",
|
||||
PyInt_FromLong( TEX_VORONOI_F1 ) );
|
||||
PyConstant_Insert( nt, "VORONOI_F2",
|
||||
PyInt_FromLong( TEX_VORONOI_F2 ) );
|
||||
PyConstant_Insert( nt, "VORONOI_F3",
|
||||
PyInt_FromLong( TEX_VORONOI_F3 ) );
|
||||
PyConstant_Insert( nt, "VORONOI_F4",
|
||||
PyInt_FromLong( TEX_VORONOI_F4 ) );
|
||||
PyConstant_Insert( nt, "VORONOI_F2F1",
|
||||
PyInt_FromLong( TEX_VORONOI_F2F1 ) );
|
||||
PyConstant_Insert( nt, "VORONOI_CRACKLE",
|
||||
PyInt_FromLong( TEX_VORONOI_CRACKLE ) );
|
||||
PyConstant_Insert( nt, "CELLNOISE",
|
||||
PyInt_FromLong( TEX_CELLNOISE ) );
|
||||
PyModule_AddObject( md, "NoiseTypes", NoiseTypes );
|
||||
}
|
||||
|
||||
/* Constant distance metric dictionary for voronoi */
|
||||
DistanceMetrics = PyConstant_New( );
|
||||
if( DistanceMetrics ) {
|
||||
BPy_constant *dm = ( BPy_constant * ) DistanceMetrics;
|
||||
PyConstant_Insert( dm, "DISTANCE",
|
||||
PyInt_FromLong( TEX_DISTANCE ) );
|
||||
PyConstant_Insert( dm, "DISTANCE_SQUARED",
|
||||
PyInt_FromLong( TEX_DISTANCE_SQUARED ) );
|
||||
PyConstant_Insert( dm, "MANHATTAN",
|
||||
PyInt_FromLong( TEX_MANHATTAN ) );
|
||||
PyConstant_Insert( dm, "CHEBYCHEV",
|
||||
PyInt_FromLong( TEX_CHEBYCHEV ) );
|
||||
PyConstant_Insert( dm, "MINKOVSKY_HALF",
|
||||
PyInt_FromLong( TEX_MINKOVSKY_HALF ) );
|
||||
PyConstant_Insert( dm, "MINKOVSKY_FOUR",
|
||||
PyInt_FromLong( TEX_MINKOVSKY_FOUR ) );
|
||||
PyConstant_Insert( dm, "MINKOVSKY",
|
||||
PyInt_FromLong( TEX_MINKOVSKY ) );
|
||||
PyModule_AddObject( md, "DistanceMetrics", DistanceMetrics );
|
||||
}
|
||||
|
||||
return md;
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,59 +0,0 @@
|
||||
/*
|
||||
* $Id$
|
||||
*
|
||||
* ***** 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*
|
||||
* The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This is a new part of Blender.
|
||||
*
|
||||
* Contributor(s): Michel Selten
|
||||
*
|
||||
* ***** END GPL LICENSE BLOCK *****
|
||||
*/
|
||||
|
||||
#ifndef EXPP_OBJECT_H
|
||||
#define EXPP_OBJECT_H
|
||||
|
||||
#include <Python.h>
|
||||
#include "DNA_object_types.h"
|
||||
|
||||
/* The Object PyType Object defined in Object.c */
|
||||
extern PyTypeObject Object_Type;
|
||||
|
||||
#define BPy_Object_Check(v) \
|
||||
((v)->ob_type == &Object_Type) /* for type checking */
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Python BPy_Object structure definition. */
|
||||
/*****************************************************************************/
|
||||
typedef struct {
|
||||
PyObject_HEAD
|
||||
struct Object *object; /* libdata must be second */
|
||||
short realtype;
|
||||
} BPy_Object;
|
||||
|
||||
PyObject *Object_Init( void );
|
||||
PyObject *Object_CreatePyObject( struct Object *obj );
|
||||
Object *Object_FromPyObject( PyObject * py_obj );
|
||||
|
||||
void Object_updateDag( void *data );
|
||||
|
||||
int EXPP_add_obdata( struct Object *object );
|
||||
|
||||
#endif /* EXPP_OBJECT_H */
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,53 +0,0 @@
|
||||
/*
|
||||
* $Id$
|
||||
*
|
||||
* ***** 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*
|
||||
* The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This is a new part of Blender.
|
||||
*
|
||||
* Contributor(s): Jacques Guignot, Cedric Paille
|
||||
*
|
||||
* ***** END GPL LICENSE BLOCK *****
|
||||
*/
|
||||
|
||||
#ifndef EXPP_PARTICLESYS_H
|
||||
#define EXPP_PARTICLESYS_H
|
||||
|
||||
#include <Python.h>
|
||||
#include "DNA_particle_types.h"
|
||||
#include "DNA_object_types.h"
|
||||
|
||||
extern PyTypeObject ParticleSys_Type;
|
||||
|
||||
#define BPy_ParticleSys_Check(v) \
|
||||
((v)->ob_type == &ParticleSys_Type) /* for type checking */
|
||||
|
||||
/* Python BPy_Effect structure definition */
|
||||
typedef struct {
|
||||
PyObject_HEAD /* required py macro */
|
||||
ParticleSystem *psys;
|
||||
Object *object; /* fixeme: if this points back to the parent object,it is wrong */
|
||||
} BPy_PartSys;
|
||||
|
||||
PyObject *ParticleSys_Init( void );
|
||||
PyObject *ParticleSys_CreatePyObject( ParticleSystem * psystem, Object *ob );
|
||||
|
||||
|
||||
#endif /* EXPP_EFFECT_H */
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,68 +0,0 @@
|
||||
/*
|
||||
* $Id:
|
||||
*
|
||||
* ***** 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*
|
||||
* The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Contributor(s): Joseph Gilbert
|
||||
*
|
||||
* ***** END GPL LICENSE BLOCK *****
|
||||
*/
|
||||
|
||||
#ifndef EXPP_POSE_H
|
||||
#define EXPP_POSE_H
|
||||
|
||||
#include <Python.h>
|
||||
#include "DNA_action_types.h"
|
||||
#include "DNA_object_types.h"
|
||||
|
||||
//-------------------TYPE CHECKS---------------------------------
|
||||
#define BPy_Pose_Check(v) ((v)->ob_type == &Pose_Type)
|
||||
#define BPy_PoseBone_Check(v) ((v)->ob_type == &PoseBone_Type)
|
||||
#define BPy_PoseBonesDict_Check(v) ((v)->ob_type == &PoseBonesDict_Type)
|
||||
//-------------------TYPEOBJECT----------------------------------
|
||||
extern PyTypeObject Pose_Type;
|
||||
extern PyTypeObject PoseBone_Type;
|
||||
extern PyTypeObject PoseBonesDict_Type;
|
||||
//-------------------STRUCT DEFINITION----------------------------
|
||||
typedef struct {
|
||||
PyObject_HEAD
|
||||
PyObject *bonesMap;
|
||||
ListBase *bones;
|
||||
} BPy_PoseBonesDict;
|
||||
|
||||
typedef struct {
|
||||
PyObject_HEAD
|
||||
bPose *pose;
|
||||
char name[24]; //because poses have not names :(
|
||||
BPy_PoseBonesDict *Bones;
|
||||
} BPy_Pose;
|
||||
|
||||
typedef struct {
|
||||
PyObject_HEAD
|
||||
bPoseChannel *posechannel;
|
||||
|
||||
} BPy_PoseBone;
|
||||
|
||||
//-------------------VISIBLE PROTOTYPES-------------------------
|
||||
PyObject *Pose_Init(void);
|
||||
PyObject *PyPose_FromPose(bPose *pose, char *name);
|
||||
PyObject *PyPoseBone_FromPosechannel(bPoseChannel *pchan);
|
||||
Object *Object_FromPoseChannel(bPoseChannel *curr_pchan);
|
||||
#endif
|
||||
@@ -1,242 +0,0 @@
|
||||
/*
|
||||
* $Id$
|
||||
*
|
||||
* ***** 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*
|
||||
* The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This is a new part of Blender.
|
||||
*
|
||||
* Contributor(s): Willian P. Germano
|
||||
*
|
||||
* ***** END GPL LICENSE BLOCK *****
|
||||
*/
|
||||
|
||||
#include "Registry.h" /*This must come first */
|
||||
|
||||
#include "BKE_global.h"
|
||||
#include "gen_utils.h"
|
||||
|
||||
|
||||
/* the Registry dictionary */
|
||||
PyObject *bpy_registryDict = NULL;
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Python API function prototypes for the Registry module. */
|
||||
/*****************************************************************************/
|
||||
static PyObject *M_Registry_Keys( PyObject * self );
|
||||
static PyObject *M_Registry_GetKey( PyObject * self, PyObject * args );
|
||||
static PyObject *M_Registry_SetKey( PyObject * self, PyObject * args );
|
||||
static PyObject *M_Registry_RemoveKey( PyObject * self, PyObject * args );
|
||||
|
||||
/*****************************************************************************/
|
||||
/* The following string definitions are used for documentation strings. */
|
||||
/* In Python these will be written to the console when doing a */
|
||||
/* Blender.Registry.__doc__ */
|
||||
/*****************************************************************************/
|
||||
char M_Registry_doc[] =
|
||||
"The Blender Registry module (persistent data cache)\n\n\
|
||||
Use this module to store configuration data that a script can reload\n\
|
||||
when it is executed again.\n";
|
||||
|
||||
char M_Registry_Keys_doc[] =
|
||||
"() - Get all keys in the Registry dictionary.\n\n\
|
||||
Each key references another dict with saved data from a specific script.\n";
|
||||
|
||||
char M_Registry_GetKey_doc[] =
|
||||
"(name, disk = False) - Get an entry (a dict) from the Registry dictionary\n\
|
||||
(name) - a string that references a specific script;\n\
|
||||
(disk = False) - search on the user (if available) or default scripts config\n\
|
||||
data dir.\n";
|
||||
|
||||
char M_Registry_SetKey_doc[] =
|
||||
"(key, dict, disk = False) - Store an entry in the Registry dictionary.\n\
|
||||
If an entry with the same 'key' already exists, it is substituted.\n\
|
||||
(key) - the string to use as a key for the dict being saved.\n\
|
||||
(dict) - a dictionary with the data to be stored.\n\
|
||||
(disk = False) - also write data as a config file inside the user (if\n\
|
||||
available) or default scripts config data dir.\n";
|
||||
|
||||
char M_Registry_RemoveKey_doc[] =
|
||||
"(key, disk = False) - Remove the dict with key 'key' from the Registry.\n\
|
||||
(key) - the name of the key to delete;\n\
|
||||
(disk = False) - if True the respective config file is also deleted.\n";
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Python method structure definition for Blender.Registry module: */
|
||||
/*****************************************************************************/
|
||||
struct PyMethodDef M_Registry_methods[] = {
|
||||
{"Keys", ( PyCFunction ) M_Registry_Keys, METH_VARARGS,
|
||||
M_Registry_Keys_doc},
|
||||
{"GetKey", M_Registry_GetKey, METH_VARARGS, M_Registry_GetKey_doc},
|
||||
{"SetKey", M_Registry_SetKey, METH_VARARGS, M_Registry_SetKey_doc},
|
||||
{"RemoveKey", M_Registry_RemoveKey, METH_VARARGS,
|
||||
M_Registry_RemoveKey_doc},
|
||||
{NULL, NULL, 0, NULL}
|
||||
};
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Function: M_Registry_Keys */
|
||||
/* Python equivalent: Blender.Registry.Keys */
|
||||
/*****************************************************************************/
|
||||
PyObject *M_Registry_Keys( PyObject * self )
|
||||
{
|
||||
PyObject *pydict = NULL;
|
||||
|
||||
if( !bpy_registryDict )
|
||||
return EXPP_ReturnPyObjError( PyExc_RuntimeError,
|
||||
"No Registry dictionary found!" );
|
||||
|
||||
pydict = PyDict_Keys( bpy_registryDict );
|
||||
|
||||
if( !pydict )
|
||||
return EXPP_ReturnPyObjError( PyExc_RuntimeError,
|
||||
"Registry_Keys: couldn't get keys" );
|
||||
|
||||
return pydict;
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Function: M_Registry_GetKey */
|
||||
/* Python equivalent: Blender.Registry.GetKey */
|
||||
/*****************************************************************************/
|
||||
static PyObject *M_Registry_GetKey( PyObject * self, PyObject * args )
|
||||
{
|
||||
PyObject *pyentry = NULL;
|
||||
PyObject *pydict = NULL;
|
||||
int disk = 0;
|
||||
|
||||
if( !bpy_registryDict )
|
||||
return EXPP_ReturnPyObjError( PyExc_RuntimeError,
|
||||
"No Registry dictionary found!" );
|
||||
|
||||
if( !PyArg_ParseTuple( args, "O!|i", &PyString_Type, &pyentry, &disk ) )
|
||||
return EXPP_ReturnPyObjError( PyExc_AttributeError,
|
||||
"expected a string and optionally a bool" );
|
||||
|
||||
pydict = PyDict_GetItem( bpy_registryDict, pyentry ); /* borrowed ... */
|
||||
|
||||
if (!pydict) {
|
||||
if (disk > 0) {
|
||||
/* try to get data from disk */
|
||||
char buf[256];
|
||||
PyOS_snprintf(buf, sizeof(buf),
|
||||
"import Blender, BPyRegistry; BPyRegistry.LoadConfigData('%s')",
|
||||
PyString_AsString(pyentry));
|
||||
if (!PyRun_SimpleString(buf))
|
||||
pydict = PyDict_GetItem(bpy_registryDict, pyentry);
|
||||
else PyErr_Clear();
|
||||
}
|
||||
|
||||
if (!pydict) /* no need to return a KeyError, since without doubt */
|
||||
pydict = Py_None; /* Py_None means no key (all valid keys are dicts) */
|
||||
}
|
||||
|
||||
return EXPP_incr_ret (pydict); /* ... so we incref it */
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Function: M_Registry_SetKey */
|
||||
/* Python equivalent: Blender.Registry.SetKey */
|
||||
/*****************************************************************************/
|
||||
static PyObject *M_Registry_SetKey( PyObject * self, PyObject * args )
|
||||
{
|
||||
PyObject *pystr = NULL;
|
||||
PyObject *pydict = NULL;
|
||||
int disk = 0;
|
||||
|
||||
if( !bpy_registryDict )
|
||||
return EXPP_ReturnPyObjError( PyExc_RuntimeError,
|
||||
"No Registry dictionary found!" );
|
||||
|
||||
if( !PyArg_ParseTuple( args, "O!O!|i",
|
||||
&PyString_Type, &pystr, &PyDict_Type,
|
||||
&pydict, &disk ) )
|
||||
return EXPP_ReturnPyObjError( PyExc_AttributeError,
|
||||
"expected a string and a dictionary" );
|
||||
|
||||
if( PyDict_SetItem( bpy_registryDict, pystr, pydict ) ) /* 0 on success */
|
||||
return EXPP_ReturnPyObjError( PyExc_RuntimeError,
|
||||
"Registry_SetKey: couldn't update the Registry dict" );
|
||||
|
||||
if (disk) {
|
||||
/* try to save data to disk */
|
||||
char buf[256];
|
||||
PyOS_snprintf(buf, sizeof(buf),
|
||||
"import Blender, BPyRegistry; BPyRegistry.SaveConfigData('%s')",
|
||||
PyString_AsString(pystr));
|
||||
if (PyRun_SimpleString(buf) != 0) {
|
||||
PyErr_Clear();
|
||||
if (G.f & G_DEBUG)
|
||||
fprintf(stderr, "\nCan't save script configuration data!\n");
|
||||
}
|
||||
}
|
||||
|
||||
Py_INCREF( Py_None );
|
||||
return Py_None;
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Function: M_Registry_RemoveKey */
|
||||
/* Python equivalent: Blender.Registry.RemoveKey */
|
||||
/*****************************************************************************/
|
||||
static PyObject *M_Registry_RemoveKey( PyObject * self, PyObject * args )
|
||||
{
|
||||
PyObject *pystr = NULL;
|
||||
int disk = 0;
|
||||
|
||||
if( !bpy_registryDict )
|
||||
return EXPP_ReturnPyObjError( PyExc_RuntimeError,
|
||||
"No Registry dictionary found!" );
|
||||
|
||||
if( !PyArg_ParseTuple( args, "O!|i", &PyString_Type, &pystr, &disk ) )
|
||||
return EXPP_ReturnPyObjError( PyExc_AttributeError,
|
||||
"expected a string and optionally a bool" );
|
||||
|
||||
if( PyDict_DelItem( bpy_registryDict, pystr ) ) /* returns 0 on success */
|
||||
return EXPP_ReturnPyObjError( PyExc_KeyError,
|
||||
"no such key in the Registry" );
|
||||
else if (disk) {
|
||||
/* try to delete from disk too */
|
||||
char buf[256];
|
||||
PyOS_snprintf(buf, sizeof(buf),
|
||||
"import Blender, BPyRegistry; BPyRegistry.RemoveConfigData('%s')",
|
||||
PyString_AsString(pystr));
|
||||
if (PyRun_SimpleString(buf) != 0) {
|
||||
PyErr_Clear();
|
||||
if (G.f & G_DEBUG)
|
||||
fprintf(stderr, "\nCan't remove script configuration data file!\n");
|
||||
}
|
||||
}
|
||||
|
||||
Py_INCREF( Py_None );
|
||||
return Py_None;
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Function: Registry_Init */
|
||||
/*****************************************************************************/
|
||||
PyObject *Registry_Init( void )
|
||||
{
|
||||
PyObject *submodule;
|
||||
|
||||
submodule = Py_InitModule3( "Blender.Registry", M_Registry_methods,
|
||||
M_Registry_doc );
|
||||
|
||||
return submodule;
|
||||
}
|
||||
@@ -1,47 +0,0 @@
|
||||
/*
|
||||
* $Id$
|
||||
*
|
||||
* ***** 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*
|
||||
* The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This is a new part of Blender.
|
||||
*
|
||||
* Contributor(s): Willian P. Germano
|
||||
*
|
||||
* ***** END GPL LICENSE BLOCK *****
|
||||
*/
|
||||
|
||||
/* This submodule was introduced as a way to preserve configured data in
|
||||
* scripts. A very simple idea: the script writer saves this data in a dict
|
||||
* and registers this dict in the "Registry" dict. This way we can discard
|
||||
* the global interpreter dictionary after a script is executed, since the
|
||||
* data meant to be kept was copied to the Registry elsewhere. The current
|
||||
* implementation is naive: scripts can deliberately mess with data saved by
|
||||
* other scripts. This is so new script versions can delete older entries, if
|
||||
* they need to. XXX Or should we block this? */
|
||||
|
||||
#ifndef EXPP_REGISTRY_H
|
||||
#define EXPP_REGISTRY_H
|
||||
|
||||
#include <Python.h>
|
||||
|
||||
extern PyObject *bpy_registryDict;
|
||||
PyObject *Registry_Init( void );
|
||||
|
||||
#endif /* EXPP_REGISTRY_H */
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,67 +0,0 @@
|
||||
/*
|
||||
* $Id$
|
||||
*
|
||||
* ***** 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*
|
||||
* The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This is a new part of Blender.
|
||||
*
|
||||
* Contributor(s): Willian P. Germano
|
||||
*
|
||||
* ***** END GPL LICENSE BLOCK *****
|
||||
*/
|
||||
|
||||
#ifndef EXPP_SCENE_H
|
||||
#define EXPP_SCENE_H
|
||||
|
||||
#include <Python.h>
|
||||
#include "DNA_scene_types.h"
|
||||
|
||||
/* The Scene PyType Object defined in Scene.c */
|
||||
extern PyTypeObject Scene_Type;
|
||||
extern PyTypeObject SceneObSeq_Type;
|
||||
|
||||
#define BPy_Scene_Check(v) \
|
||||
((v)->ob_type == &Scene_Type)
|
||||
#define BPy_SceneObSeq_Check(v) \
|
||||
((v)->ob_type == &SceneObSeq_Type)
|
||||
|
||||
/*---------------------------Python BPy_Scene structure definition----------*/
|
||||
typedef struct {
|
||||
PyObject_HEAD
|
||||
Scene * scene; /* libdata must be second */
|
||||
} BPy_Scene;
|
||||
/*---------------------------Python BPy_Scene visible prototypes-----------*/
|
||||
/* Python Scene_Type helper functions needed by Blender (the Init function) and Object modules. */
|
||||
|
||||
|
||||
/* Scene object sequence, iterate on the scene object listbase*/
|
||||
typedef struct {
|
||||
PyObject_VAR_HEAD /* required python macro */
|
||||
BPy_Scene *bpyscene; /* link to the python scene so we can know if its been removed */
|
||||
Base *iter; /* so we can iterate over the objects */
|
||||
int mode; /*0:all objects, 1:selected objects, 2:user context*/
|
||||
} BPy_SceneObSeq;
|
||||
|
||||
|
||||
PyObject *Scene_Init( void );
|
||||
PyObject *Scene_CreatePyObject( Scene * scene );
|
||||
/*Scene *Scene_FromPyObject( PyObject * pyobj );*/ /* not used yet */
|
||||
|
||||
#endif /* EXPP_SCENE_H */
|
||||
@@ -1,604 +0,0 @@
|
||||
/*
|
||||
* $Id$
|
||||
*
|
||||
* ***** 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*
|
||||
* The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This is a new part of Blender.
|
||||
*
|
||||
* Contributor(s): Chris Keith
|
||||
*
|
||||
* ***** END GPL LICENSE BLOCK *****
|
||||
*/
|
||||
|
||||
#include "Sound.h" /*This must come first*/
|
||||
|
||||
#include "BKE_global.h"
|
||||
#include "BKE_main.h"
|
||||
#include "BLI_blenlib.h"
|
||||
#include "BKE_sound.h"
|
||||
#include "BKE_library.h"
|
||||
#include "BIF_editsound.h"
|
||||
#include "BKE_packedFile.h"
|
||||
#include "mydevice.h" /* redraw defines */
|
||||
#include "gen_utils.h"
|
||||
#include "gen_library.h"
|
||||
#include "DNA_space_types.h" /* for FILE_MAXDIR only */
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Python BPy_Sound defaults: */
|
||||
/*****************************************************************************/
|
||||
|
||||
#define EXPP_SND_volume_MIN 0.0
|
||||
#define EXPP_SND_volume_MAX 1.0
|
||||
#define EXPP_SND_pitch_MIN -12.0
|
||||
#define EXPP_SND_pitch_MAX 12.0
|
||||
#define EXPP_SND_attenuation_MIN 0.0
|
||||
#define EXPP_SND_attenuation_MAX 5.0
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Python API function prototypes for the Sound module. */
|
||||
/*****************************************************************************/
|
||||
static PyObject *M_Sound_Get( PyObject * self, PyObject * args );
|
||||
static PyObject *M_Sound_Load( PyObject * self, PyObject * value );
|
||||
|
||||
/************************************************************************/
|
||||
/* The following string definitions are used for documentation strings. */
|
||||
/* In Python these will be written to the console when doing a */
|
||||
/* Blender.Sound.__doc__ */
|
||||
/************************************************************************/
|
||||
static char M_Sound_doc[] = "The Blender Sound module\n\n";
|
||||
|
||||
static char M_Sound_Get_doc[] =
|
||||
"(name) - return the sound with the name 'name', \
|
||||
returns None if not found.\n If 'name' is not specified, \
|
||||
it returns a list of all sounds in the\ncurrent scene.";
|
||||
|
||||
static char M_Sound_Load_doc[] =
|
||||
"(filename) - return sound from file filename as a Sound Object,\n\
|
||||
returns None if not found.";
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Python method structure definition for Blender.Sound module: */
|
||||
/*****************************************************************************/
|
||||
struct PyMethodDef M_Sound_methods[] = {
|
||||
{"Get", M_Sound_Get, METH_VARARGS, M_Sound_Get_doc},
|
||||
{"Load", M_Sound_Load, METH_O, M_Sound_Load_doc},
|
||||
{NULL, NULL, 0, NULL}
|
||||
};
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Python Sound_Type callback function prototypes: */
|
||||
/*****************************************************************************/
|
||||
static int Sound_compare( BPy_Sound * a, BPy_Sound * b );
|
||||
static PyObject *Sound_repr( BPy_Sound * self );
|
||||
|
||||
#define SOUND_FLOAT_METHODS(funcname, varname) \
|
||||
static PyObject *Sound_get ## funcname(BPy_Sound *self) { \
|
||||
return PyFloat_FromDouble(self->sound->varname); \
|
||||
} \
|
||||
static PyObject *Sound_set ## funcname(BPy_Sound *self, PyObject *args) { \
|
||||
float f = 0; \
|
||||
if (!PyArg_ParseTuple(args, "f", &f)) \
|
||||
return (EXPP_ReturnPyObjError (PyExc_TypeError, \
|
||||
"expected float argument")); \
|
||||
self->sound->varname = EXPP_ClampFloat(f, \
|
||||
EXPP_SND_##varname##_MIN, EXPP_SND_##varname##_MAX); \
|
||||
Py_RETURN_NONE; \
|
||||
}
|
||||
|
||||
#define SOUND_FLOAT_METHOD_FUNCS(varname) \
|
||||
{"get"#varname, (PyCFunction)Sound_get ## varname, METH_NOARGS, \
|
||||
"() - Return Sound object "#varname}, \
|
||||
{"set"#varname, (PyCFunction)Sound_set ## varname, METH_VARARGS, \
|
||||
"(float) - Change Sound object "#varname},
|
||||
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Python BPy_Sound methods declarations: */
|
||||
/*****************************************************************************/
|
||||
static PyObject *Sound_getName( BPy_Sound * self );
|
||||
static PyObject *Sound_getFilename( BPy_Sound * self );
|
||||
static PyObject *Sound_setName( BPy_Sound * self, PyObject * args );
|
||||
static int Sound_setFilename( BPy_Sound * self, PyObject * args );
|
||||
static PyObject *Sound_oldsetFilename( BPy_Sound * self, PyObject * args );
|
||||
static PyObject *Sound_setCurrent( BPy_Sound * self );
|
||||
static PyObject *Sound_play( BPy_Sound * self );
|
||||
static PyObject *Sound_unpack( BPy_Sound * self, PyObject * args);
|
||||
static PyObject *Sound_pack( BPy_Sound * self );
|
||||
/*static PyObject *Sound_reload ( BPy_Sound * self );*/
|
||||
SOUND_FLOAT_METHODS( Volume, volume )
|
||||
SOUND_FLOAT_METHODS( Attenuation, attenuation )
|
||||
SOUND_FLOAT_METHODS( Pitch, pitch )
|
||||
/* these can't be set via interface, removed for now */
|
||||
/*
|
||||
SOUND_FLOAT_METHODS( Panning, panning )
|
||||
SOUND_FLOAT_METHODS( MinGain, min_gain )
|
||||
SOUND_FLOAT_METHODS( MaxGain, max_gain )
|
||||
SOUND_FLOAT_METHODS( Distance, distance )
|
||||
*/
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Python BPy_Sound methods table: */
|
||||
/*****************************************************************************/
|
||||
static PyMethodDef BPy_Sound_methods[] = {
|
||||
/* name, method, flags, doc */
|
||||
{"getName", ( PyCFunction ) Sound_getName, METH_NOARGS,
|
||||
"() - Return Sound object name"},
|
||||
{"getFilename", ( PyCFunction ) Sound_getFilename, METH_NOARGS,
|
||||
"() - Return Sound object filename"},
|
||||
{"setName", ( PyCFunction ) Sound_setName, METH_VARARGS,
|
||||
"(name) - Set Sound object name"},
|
||||
{"setFilename", ( PyCFunction ) Sound_oldsetFilename, METH_VARARGS,
|
||||
"(filename) - Set Sound object filename"},
|
||||
{"setCurrent", ( PyCFunction ) Sound_setCurrent, METH_NOARGS,
|
||||
"() - make this the active sound in the sound buttons win (also redraws)"},
|
||||
{"play", ( PyCFunction ) Sound_play, METH_NOARGS,
|
||||
"() - play this sound"},
|
||||
{"unpack", ( PyCFunction ) Sound_unpack, METH_VARARGS,
|
||||
"(int) - Unpack sound. Uses one of the values defined in Blender.UnpackModes."},
|
||||
{"pack", ( PyCFunction ) Sound_pack, METH_NOARGS,
|
||||
"() Pack the sound"},
|
||||
/*
|
||||
{"reload", ( PyCFunction ) Sound_setCurrent, METH_NOARGS,
|
||||
"() - reload this Sound object's sample.\n\
|
||||
This is only useful if the original sound file has changed."},
|
||||
*/
|
||||
SOUND_FLOAT_METHOD_FUNCS( Volume )
|
||||
SOUND_FLOAT_METHOD_FUNCS( Attenuation )
|
||||
SOUND_FLOAT_METHOD_FUNCS( Pitch )
|
||||
/*
|
||||
SOUND_FLOAT_METHOD_FUNCS( Panning )
|
||||
SOUND_FLOAT_METHOD_FUNCS( MinGain )
|
||||
SOUND_FLOAT_METHOD_FUNCS( MaxGain )
|
||||
SOUND_FLOAT_METHOD_FUNCS( Distance )
|
||||
*/
|
||||
{NULL, NULL, 0, NULL}
|
||||
};
|
||||
|
||||
/* NOTE: these were copied and modified from image.h. To Be Done TBD:
|
||||
* macro-ize them, or C++ templates eventually?
|
||||
*/
|
||||
/****************************************************************************/
|
||||
/* Function: M_Sound_Get */
|
||||
/* Python equivalent: Blender.Sound.Get */
|
||||
/* Description: Receives a string and returns the Sound object */
|
||||
/* whose name matches the string. If no argument is */
|
||||
/* passed in, a list of all Sound names in the */
|
||||
/* current scene is returned. */
|
||||
/****************************************************************************/
|
||||
static PyObject *M_Sound_Get( PyObject * self, PyObject * args )
|
||||
{
|
||||
char *name = NULL;
|
||||
bSound *snd_iter;
|
||||
|
||||
if( !PyArg_ParseTuple( args, "|s", &name ) )
|
||||
return ( EXPP_ReturnPyObjError( PyExc_TypeError,
|
||||
"expected string argument (or nothing)" ) );
|
||||
|
||||
snd_iter = G.main->sound.first;
|
||||
|
||||
if( name ) { /* (name) - Search Sound by name */
|
||||
|
||||
BPy_Sound *wanted_Sound = NULL;
|
||||
|
||||
while( ( snd_iter ) && ( wanted_Sound == NULL ) ) {
|
||||
if( strcmp( name, snd_iter->id.name + 2 ) == 0 ) {
|
||||
wanted_Sound =
|
||||
( BPy_Sound * )
|
||||
PyObject_NEW( BPy_Sound, &Sound_Type );
|
||||
if( wanted_Sound ) {
|
||||
wanted_Sound->sound = snd_iter;
|
||||
break;
|
||||
}
|
||||
}
|
||||
snd_iter = snd_iter->id.next;
|
||||
}
|
||||
|
||||
if( wanted_Sound == NULL ) { /* Requested Sound doesn't exist */
|
||||
char error_msg[64];
|
||||
PyOS_snprintf( error_msg, sizeof( error_msg ),
|
||||
"Sound \"%s\" not found", name );
|
||||
return ( EXPP_ReturnPyObjError
|
||||
( PyExc_NameError, error_msg ) );
|
||||
}
|
||||
|
||||
return ( PyObject * ) wanted_Sound;
|
||||
}
|
||||
|
||||
else { /* () - return a list of all Sounds in the scene */
|
||||
int index = 0;
|
||||
PyObject *snd_list, *pyobj;
|
||||
|
||||
snd_list = PyList_New( BLI_countlist( &( G.main->sound ) ) );
|
||||
|
||||
if( snd_list == NULL )
|
||||
return ( EXPP_ReturnPyObjError( PyExc_MemoryError,
|
||||
"couldn't create PyList" ) );
|
||||
|
||||
while( snd_iter ) {
|
||||
pyobj = Sound_CreatePyObject( snd_iter );
|
||||
|
||||
if( !pyobj ) {
|
||||
Py_DECREF(snd_list);
|
||||
return ( EXPP_ReturnPyObjError
|
||||
( PyExc_MemoryError,
|
||||
"couldn't create PyObject" ) );
|
||||
}
|
||||
PyList_SET_ITEM( snd_list, index, pyobj );
|
||||
|
||||
snd_iter = snd_iter->id.next;
|
||||
index++;
|
||||
}
|
||||
|
||||
return ( snd_list );
|
||||
}
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Function: M_Sound_Load */
|
||||
/* Python equivalent: Blender.Sound.Load */
|
||||
/* Description: Receives a string and returns the Sound object */
|
||||
/* whose filename matches the string. */
|
||||
/*****************************************************************************/
|
||||
static PyObject *M_Sound_Load( PyObject * self, PyObject * value )
|
||||
{
|
||||
char *fname = PyString_AsString(value);
|
||||
bSound *snd_ptr;
|
||||
BPy_Sound *snd;
|
||||
|
||||
if( !fname )
|
||||
return ( EXPP_ReturnPyObjError( PyExc_TypeError,
|
||||
"expected string argument" ) );
|
||||
|
||||
snd = ( BPy_Sound * ) PyObject_NEW( BPy_Sound, &Sound_Type );
|
||||
|
||||
if( !snd )
|
||||
return ( EXPP_ReturnPyObjError( PyExc_MemoryError,
|
||||
"couldn't create PyObject Sound_Type" ) );
|
||||
|
||||
snd_ptr = sound_new_sound( fname );
|
||||
|
||||
if( snd_ptr ) {
|
||||
if( G.ssound ) {
|
||||
G.ssound->sound = snd_ptr;
|
||||
}
|
||||
}
|
||||
|
||||
if( !snd_ptr )
|
||||
return ( EXPP_ReturnPyObjError( PyExc_IOError,
|
||||
"not a valid sound sample" ) );
|
||||
|
||||
snd->sound = snd_ptr;
|
||||
|
||||
return ( PyObject * ) snd;
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Function: Sound_Init */
|
||||
/*****************************************************************************/
|
||||
PyObject *Sound_Init( void )
|
||||
{
|
||||
PyObject *submodule;
|
||||
|
||||
if( PyType_Ready( &Sound_Type ) < 0 )
|
||||
return NULL;
|
||||
|
||||
submodule =
|
||||
Py_InitModule3( "Blender.Sound", M_Sound_methods,
|
||||
M_Sound_doc );
|
||||
|
||||
return ( submodule );
|
||||
}
|
||||
|
||||
/************************/
|
||||
/*** The Sound PyType ***/
|
||||
/************************/
|
||||
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Function: Sound_CreatePyObject */
|
||||
/* Description: This function will create a new BPy_Sound from an existing */
|
||||
/* Blender Sound structure. */
|
||||
/*****************************************************************************/
|
||||
PyObject *Sound_CreatePyObject( bSound * snd )
|
||||
{
|
||||
BPy_Sound *py_snd;
|
||||
|
||||
py_snd = ( BPy_Sound * ) PyObject_NEW( BPy_Sound, &Sound_Type );
|
||||
|
||||
if( !py_snd )
|
||||
return EXPP_ReturnPyObjError( PyExc_MemoryError,
|
||||
"couldn't create BPy_Sound object" );
|
||||
|
||||
py_snd->sound = snd;
|
||||
|
||||
return ( PyObject * ) py_snd;
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Function: Sound_FromPyObject */
|
||||
/* Description: Returns the Blender Sound associated with this object */
|
||||
/*****************************************************************************/
|
||||
bSound *Sound_FromPyObject( PyObject * pyobj )
|
||||
{
|
||||
return ( ( BPy_Sound * ) pyobj )->sound;
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Python BPy_Sound methods: */
|
||||
/*****************************************************************************/
|
||||
static PyObject *Sound_getName( BPy_Sound * self )
|
||||
{
|
||||
return PyString_FromString( self->sound->id.name + 2 );
|
||||
}
|
||||
|
||||
static PyObject *Sound_getFilename( BPy_Sound * self )
|
||||
{
|
||||
return PyString_FromString( self->sound->name );
|
||||
}
|
||||
|
||||
static PyObject *Sound_getPacked( BPy_Sound * self )
|
||||
{
|
||||
if (!sound_sample_is_null(self->sound)) {
|
||||
bSample *sample = sound_find_sample(self->sound);
|
||||
if (sample->packedfile)
|
||||
Py_RETURN_TRUE;
|
||||
}
|
||||
Py_RETURN_FALSE;
|
||||
}
|
||||
|
||||
static PyObject *Sound_setName( BPy_Sound * self, PyObject * args )
|
||||
{
|
||||
char *name;
|
||||
|
||||
if( !PyArg_ParseTuple( args, "s", &name ) ) {
|
||||
return ( EXPP_ReturnPyObjError( PyExc_AttributeError,
|
||||
"expected a String as argument" ) );
|
||||
}
|
||||
|
||||
rename_id( &self->sound->id, name );
|
||||
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
static int Sound_setFilename( BPy_Sound * self, PyObject * value )
|
||||
{
|
||||
char *name;
|
||||
|
||||
/* max len is FILE_MAXDIR = 160 chars like in DNA_image_types.h */
|
||||
name = PyString_AsString(value);
|
||||
if (!name || strlen(name) > FILE_MAXDIR)
|
||||
return ( EXPP_ReturnIntError( PyExc_ValueError,
|
||||
"string argument is limited to 160 chars at most" ) );
|
||||
|
||||
strcpy( self->sound->name, name );
|
||||
return 0;
|
||||
}
|
||||
|
||||
static PyObject *Sound_oldsetFilename( BPy_Sound * self, PyObject * args )
|
||||
{
|
||||
return EXPP_setterWrapper( (void *)self, args, (setter)Sound_setFilename );
|
||||
}
|
||||
|
||||
|
||||
static PyObject *Sound_play( BPy_Sound * self )
|
||||
{
|
||||
sound_play_sound( self->sound );
|
||||
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
static PyObject *Sound_setCurrent( BPy_Sound * self )
|
||||
{
|
||||
bSound *snd_ptr = self->sound;
|
||||
|
||||
if( snd_ptr ) {
|
||||
if( G.ssound ) {
|
||||
G.ssound->sound = snd_ptr;
|
||||
}
|
||||
}
|
||||
|
||||
EXPP_allqueue( REDRAWSOUND, 0 );
|
||||
EXPP_allqueue( REDRAWBUTSLOGIC, 0 );
|
||||
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
/* unpack sound */
|
||||
|
||||
static PyObject *Sound_unpack( BPy_Sound * self, PyObject * args )
|
||||
{
|
||||
bSound *sound = self->sound;
|
||||
int mode;
|
||||
if( !PyArg_ParseTuple( args, "i", &mode ) )
|
||||
return EXPP_ReturnPyObjError( PyExc_TypeError,
|
||||
"expected an integer from Blender.UnpackModes" );
|
||||
|
||||
if (!sound_sample_is_null(sound)) {
|
||||
bSample *sample = sound_find_sample(sound);
|
||||
if (sample->packedfile) {
|
||||
if (unpackSample(sample, mode) == RET_ERROR)
|
||||
return EXPP_ReturnPyObjError( PyExc_RuntimeError,
|
||||
"error unpacking sound");
|
||||
}
|
||||
} else {
|
||||
return EXPP_ReturnPyObjError( PyExc_RuntimeError, "sound has no samples" );
|
||||
}
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
/* pack sound */
|
||||
|
||||
static PyObject *Sound_pack( BPy_Sound * self )
|
||||
{
|
||||
bSound *sound = self->sound;
|
||||
if (!sound_sample_is_null(sound))
|
||||
{
|
||||
bSample *sample = sound_find_sample(sound);
|
||||
if (sample->packedfile )
|
||||
return EXPP_ReturnPyObjError( PyExc_RuntimeError,
|
||||
"sound alredy packed" );
|
||||
sound_set_packedfile(sample, newPackedFile(sample->name));
|
||||
}
|
||||
else
|
||||
{
|
||||
return EXPP_ReturnPyObjError( PyExc_RuntimeError,
|
||||
"sound has no samples" );
|
||||
}
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
/*
|
||||
static PyObject *Sound_reload( BPy_Sound * self)
|
||||
{
|
||||
sound_free_sample();
|
||||
|
||||
if (sound->snd_sound) {
|
||||
SND_RemoveSound(ghSoundScene, sound->snd_sound);
|
||||
sound->snd_sound = NULL;
|
||||
}
|
||||
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Function: Sound_compare */
|
||||
/* Description: This is a callback function for the BPy_Sound type. It */
|
||||
/* compares two Sound_Type objects. Only the "==" and "!=" */
|
||||
/* comparisons are meaninful. Returns 0 for equality and -1 if */
|
||||
/* they don't point to the same Blender Sound struct. */
|
||||
/* In Python it becomes 1 if they are equal, 0 otherwise. */
|
||||
/*****************************************************************************/
|
||||
static int Sound_compare( BPy_Sound * a, BPy_Sound * b )
|
||||
{
|
||||
return ( a->sound == b->sound ) ? 0 : -1;
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Function: Sound_repr */
|
||||
/* Description: This is a callback function for the BPy_Sound type. It */
|
||||
/* builds a meaninful string to represent Sound objects. */
|
||||
/*****************************************************************************/
|
||||
static PyObject *Sound_repr( BPy_Sound * self )
|
||||
{
|
||||
return PyString_FromFormat( "[Sound \"%s\"]",
|
||||
self->sound->id.name + 2 );
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Python attributes get/set structure: */
|
||||
/*****************************************************************************/
|
||||
static PyGetSetDef BPy_Sound_getseters[] = {
|
||||
GENERIC_LIB_GETSETATTR,
|
||||
{"filename", (getter)Sound_getFilename, (setter)Sound_setFilename,
|
||||
"text filename", NULL},
|
||||
{"packed", (getter)Sound_getPacked, (setter)NULL,
|
||||
"text filename", NULL},
|
||||
{NULL,NULL,NULL,NULL,NULL} /* Sentinel */
|
||||
};
|
||||
|
||||
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Python Sound_Type structure definition: */
|
||||
/*****************************************************************************/
|
||||
PyTypeObject Sound_Type = {
|
||||
PyObject_HEAD_INIT( NULL )
|
||||
0, /* ob_size */
|
||||
"Blender Sound", /* tp_name */
|
||||
sizeof( BPy_Sound ), /* tp_basicsize */
|
||||
0, /* tp_itemsize */
|
||||
/* methods */
|
||||
NULL, /* tp_dealloc */
|
||||
0, /* tp_print */
|
||||
NULL, /* tp_getattr */
|
||||
NULL, /* tp_setattr */
|
||||
( cmpfunc ) Sound_compare, /* tp_compare */
|
||||
( reprfunc ) Sound_repr, /* tp_repr */
|
||||
|
||||
/* Method suites for standard classes */
|
||||
|
||||
NULL, /* PyNumberMethods *tp_as_number; */
|
||||
NULL, /* PySequenceMethods *tp_as_sequence; */
|
||||
NULL, /* PyMappingMethods *tp_as_mapping; */
|
||||
|
||||
/* More standard operations (here for binary compatibility) */
|
||||
|
||||
( hashfunc ) GenericLib_hash, /* hashfunc tp_hash; */
|
||||
NULL, /* ternaryfunc tp_call; */
|
||||
NULL, /* reprfunc tp_str; */
|
||||
NULL, /* getattrofunc tp_getattro; */
|
||||
NULL, /* setattrofunc tp_setattro; */
|
||||
|
||||
/* Functions to access object as input/output buffer */
|
||||
NULL, /* PyBufferProcs *tp_as_buffer; */
|
||||
|
||||
/*** Flags to define presence of optional/expanded features ***/
|
||||
Py_TPFLAGS_DEFAULT, /* long tp_flags; */
|
||||
|
||||
NULL, /* char *tp_doc; Documentation string */
|
||||
/*** Assigned meaning in release 2.0 ***/
|
||||
/* call function for all accessible objects */
|
||||
NULL, /* traverseproc tp_traverse; */
|
||||
|
||||
/* delete references to contained objects */
|
||||
NULL, /* inquiry tp_clear; */
|
||||
|
||||
/*** Assigned meaning in release 2.1 ***/
|
||||
/*** rich comparisons ***/
|
||||
NULL, /* richcmpfunc tp_richcompare; */
|
||||
|
||||
/*** weak reference enabler ***/
|
||||
0, /* long tp_weaklistoffset; */
|
||||
|
||||
/*** Added in release 2.2 ***/
|
||||
/* Iterators */
|
||||
NULL, /* getiterfunc tp_iter; */
|
||||
NULL, /* iternextfunc tp_iternext; */
|
||||
|
||||
/*** Attribute descriptor and subclassing stuff ***/
|
||||
BPy_Sound_methods, /* struct PyMethodDef *tp_methods; */
|
||||
NULL, /* struct PyMemberDef *tp_members; */
|
||||
BPy_Sound_getseters, /* struct PyGetSetDef *tp_getset; */
|
||||
NULL, /* struct _typeobject *tp_base; */
|
||||
NULL, /* PyObject *tp_dict; */
|
||||
NULL, /* descrgetfunc tp_descr_get; */
|
||||
NULL, /* descrsetfunc tp_descr_set; */
|
||||
0, /* long tp_dictoffset; */
|
||||
NULL, /* initproc tp_init; */
|
||||
NULL, /* allocfunc tp_alloc; */
|
||||
NULL, /* newfunc tp_new; */
|
||||
/* Low-level free-memory routine */
|
||||
NULL, /* freefunc tp_free; */
|
||||
/* For PyObject_IS_GC */
|
||||
NULL, /* inquiry tp_is_gc; */
|
||||
NULL, /* PyObject *tp_bases; */
|
||||
/* method resolution order */
|
||||
NULL, /* PyObject *tp_mro; */
|
||||
NULL, /* PyObject *tp_cache; */
|
||||
NULL, /* PyObject *tp_subclasses; */
|
||||
NULL, /* PyObject *tp_weaklist; */
|
||||
NULL
|
||||
};
|
||||
|
||||
|
||||
@@ -1,54 +0,0 @@
|
||||
/*
|
||||
* $Id$
|
||||
*
|
||||
* ***** 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*
|
||||
* The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This is a new part of Blender.
|
||||
*
|
||||
* Contributor(s): Chris Keith
|
||||
*
|
||||
* ***** END GPL LICENSE BLOCK *****
|
||||
*/
|
||||
|
||||
#ifndef EXPP_SOUND_H
|
||||
#define EXPP_SOUND_H
|
||||
|
||||
#include <Python.h>
|
||||
#include "DNA_sound_types.h"
|
||||
|
||||
#define BPy_Sound_Check(v) ((v)->ob_type == &Sound_Type)
|
||||
extern PyTypeObject Sound_Type;
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Python BPy_Sound structure definition */
|
||||
/*****************************************************************************/
|
||||
typedef struct {
|
||||
PyObject_HEAD
|
||||
bSound * sound;
|
||||
} BPy_Sound;
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Module Blender.Sound - public functions */
|
||||
/*****************************************************************************/
|
||||
PyObject *Sound_Init( void );
|
||||
PyObject *Sound_CreatePyObject( bSound * sound );
|
||||
bSound *Sound_FromPyObject( PyObject * pyobj );
|
||||
|
||||
#endif /* EXPP_SOUND_H */
|
||||
@@ -1,917 +0,0 @@
|
||||
/*
|
||||
* $Id$
|
||||
* ***** 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*
|
||||
* The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This is a new part of Blender.
|
||||
*
|
||||
* Contributor(s): Stephen Swaney
|
||||
*
|
||||
* ***** END GPL LICENSE BLOCK *****
|
||||
*/
|
||||
|
||||
#include "SurfNurb.h" /*This must come first */
|
||||
|
||||
#include "BKE_curve.h"
|
||||
#include "BDR_editcurve.h" /* for convertspline */
|
||||
#include "MEM_guardedalloc.h"
|
||||
#include "gen_utils.h"
|
||||
#include "gen_library.h"
|
||||
#include "BezTriple.h"
|
||||
|
||||
/*
|
||||
* forward declarations go here
|
||||
*/
|
||||
|
||||
static int SurfNurb_setPoint( BPy_SurfNurb * self, int index, PyObject * ob );
|
||||
static int SurfNurb_length( PyInstanceObject * inst );
|
||||
static PyObject *SurfNurb_getIter( BPy_SurfNurb * self );
|
||||
static PyObject *SurfNurb_iterNext( BPy_SurfNurb * self );
|
||||
static PyObject *SurfNurb_getKnotsU( BPy_SurfNurb * self );
|
||||
static PyObject *SurfNurb_getKnotsV( BPy_SurfNurb * self );
|
||||
PyObject *SurfNurb_append( BPy_SurfNurb * self, PyObject * args );
|
||||
|
||||
char M_SurfNurb_doc[] = "SurfNurb";
|
||||
|
||||
/*
|
||||
table of module methods
|
||||
these are the equivalent of class or static methods.
|
||||
you do not need an object instance to call one.
|
||||
*/
|
||||
|
||||
static PyMethodDef M_SurfNurb_methods[] = {
|
||||
/* name, method, flags, doc_string */
|
||||
/* {"Get", (PyCFunction) M_SurfNurb_method, METH_NOARGS, " () - doc string"}, */
|
||||
/* {"method", (PyCFunction) M_SurfNurb_method, METH_NOARGS, " () - doc string"}, */
|
||||
|
||||
{NULL, NULL, 0, NULL}
|
||||
};
|
||||
|
||||
/*
|
||||
* method table
|
||||
* table of instance methods
|
||||
* these methods are invoked on an instance of the type.
|
||||
*/
|
||||
|
||||
static PyMethodDef BPy_SurfNurb_methods[] = {
|
||||
# if 0
|
||||
{"append", ( PyCFunction ) SurfNurb_append, METH_VARARGS,
|
||||
"( point ) - add a new point. arg is BezTriple or list of x,y,z,w floats"},
|
||||
#endif
|
||||
{NULL, NULL, 0, NULL}
|
||||
};
|
||||
|
||||
/*
|
||||
* SurfNurb_appendPointToNurb
|
||||
* this is a non-bpy utility func to add a point to a given nurb.
|
||||
* notice the first arg is Nurb*.
|
||||
*/
|
||||
|
||||
#if 0
|
||||
static PyObject *SurfNurb_appendPointToNurb( Nurb * nurb, PyObject * args )
|
||||
{
|
||||
|
||||
int i;
|
||||
int size;
|
||||
PyObject *pyOb;
|
||||
int npoints = nurb->pntsu;
|
||||
|
||||
/*
|
||||
do we have a list of four floats or a BezTriple?
|
||||
*/
|
||||
if( !PyArg_ParseTuple( args, "O", &pyOb ))
|
||||
return EXPP_ReturnPyObjError
|
||||
( PyExc_RuntimeError,
|
||||
"Internal error parsing arguments" );
|
||||
|
||||
|
||||
|
||||
/* if curve is empty, adjust type depending on input type */
|
||||
if (nurb->bezt==NULL && nurb->bp==NULL) {
|
||||
if (BPy_BezTriple_Check( pyOb ))
|
||||
nurb->type |= CU_BEZIER;
|
||||
else if (PySequence_Check( pyOb ))
|
||||
nurb->type |= CU_NURBS;
|
||||
else
|
||||
return( EXPP_ReturnPyObjError( PyExc_TypeError,
|
||||
"Expected a BezTriple or a Sequence of 4 (or 5) floats" ) );
|
||||
}
|
||||
|
||||
|
||||
|
||||
if ((nurb->type & 7)==CU_BEZIER) {
|
||||
BezTriple *tmp;
|
||||
|
||||
if( !BPy_BezTriple_Check( pyOb ) )
|
||||
return( EXPP_ReturnPyObjError( PyExc_TypeError,
|
||||
"Expected a BezTriple\n" ) );
|
||||
|
||||
/* printf("\ndbg: got a BezTriple\n"); */
|
||||
tmp = nurb->bezt; /* save old points */
|
||||
nurb->bezt =
|
||||
( BezTriple * ) MEM_mallocN( sizeof( BezTriple ) *
|
||||
( npoints + 1 ),
|
||||
"SurfNurb_append2" );
|
||||
|
||||
if( !nurb->bezt )
|
||||
return ( EXPP_ReturnPyObjError
|
||||
( PyExc_MemoryError, "allocation failed" ) );
|
||||
|
||||
/* copy old points to new */
|
||||
if( tmp ) {
|
||||
memmove( nurb->bezt, tmp, sizeof( BezTriple ) * npoints );
|
||||
MEM_freeN( tmp );
|
||||
}
|
||||
|
||||
nurb->pntsu++;
|
||||
/* add new point to end of list */
|
||||
memcpy( nurb->bezt + npoints,
|
||||
BezTriple_FromPyObject( pyOb ), sizeof( BezTriple ) );
|
||||
|
||||
}
|
||||
else if( PySequence_Check( pyOb ) ) {
|
||||
size = PySequence_Size( pyOb );
|
||||
/* printf("\ndbg: got a sequence of size %d\n", size ); */
|
||||
if( size == 4 || size == 5 ) {
|
||||
BPoint *tmp;
|
||||
|
||||
tmp = nurb->bp; /* save old pts */
|
||||
|
||||
nurb->bp =
|
||||
( BPoint * ) MEM_mallocN( sizeof( BPoint ) *
|
||||
( npoints + 1 ),
|
||||
"SurfNurb_append1" );
|
||||
if( !nurb->bp )
|
||||
return ( EXPP_ReturnPyObjError
|
||||
( PyExc_MemoryError,
|
||||
"allocation failed" ) );
|
||||
|
||||
memmove( nurb->bp, tmp, sizeof( BPoint ) * npoints );
|
||||
if( tmp )
|
||||
MEM_freeN( tmp );
|
||||
|
||||
++nurb->pntsu;
|
||||
/* initialize new BPoint from old */
|
||||
memcpy( nurb->bp + npoints, nurb->bp,
|
||||
sizeof( BPoint ) );
|
||||
|
||||
for( i = 0; i < 4; ++i ) {
|
||||
PyObject *item = PySequence_GetItem( pyOb, i );
|
||||
|
||||
if (item == NULL)
|
||||
return NULL;
|
||||
|
||||
|
||||
nurb->bp[npoints].vec[i] = ( float ) PyFloat_AsDouble( item );
|
||||
Py_DECREF( item );
|
||||
}
|
||||
|
||||
if (size == 5) {
|
||||
PyObject *item = PySequence_GetItem( pyOb, i );
|
||||
|
||||
if (item == NULL)
|
||||
return NULL;
|
||||
|
||||
nurb->bp[npoints].alfa = ( float ) PyFloat_AsDouble( item );
|
||||
Py_DECREF( item );
|
||||
}
|
||||
else {
|
||||
nurb->bp[npoints].alfa = 0.0f;
|
||||
}
|
||||
|
||||
makeknots( nurb, 1, nurb->flagu >> 1 );
|
||||
|
||||
} else {
|
||||
return EXPP_ReturnPyObjError( PyExc_TypeError,
|
||||
"expected a sequence of 4 or 5 floats" );
|
||||
}
|
||||
|
||||
} else {
|
||||
/* bail with error */
|
||||
return EXPP_ReturnPyObjError( PyExc_TypeError,
|
||||
"expected a sequence of 4 or 5 floats" );
|
||||
|
||||
}
|
||||
|
||||
return ( EXPP_incr_ret( Py_None ) );
|
||||
}
|
||||
|
||||
/*
|
||||
* SurfNurb_append( point )
|
||||
* append a new point to a nurb curve.
|
||||
* arg is BezTriple or list of xyzw floats
|
||||
*/
|
||||
|
||||
PyObject *SurfNurb_append( BPy_SurfNurb * self, PyObject * args )
|
||||
{
|
||||
Nurb *nurb = self->nurb;
|
||||
|
||||
return SurfNurb_appendPointToNurb( nurb, args );
|
||||
}
|
||||
#endif
|
||||
|
||||
#if 0
|
||||
/*
|
||||
* SurfNurb_getMatIndex
|
||||
*
|
||||
* returns index into material list
|
||||
*/
|
||||
|
||||
static PyObject *SurfNurb_getMatIndex( BPy_SurfNurb * self )
|
||||
{
|
||||
return PyInt_FromLong( ( long ) self->nurb->mat_nr );
|
||||
}
|
||||
|
||||
/*
|
||||
* SurfNurb_setMatIndex
|
||||
*
|
||||
* set index into material list
|
||||
*/
|
||||
|
||||
static int SurfNurb_setMatIndex( BPy_SurfNurb * self, PyObject * args )
|
||||
{
|
||||
args = PyNumber_Int( args );
|
||||
|
||||
if( !args )
|
||||
return EXPP_ReturnIntError( PyExc_TypeError,
|
||||
"expected integer argument" );
|
||||
|
||||
/* fixme: some range checking would be nice! */
|
||||
/* can't do range checking without knowing the "parent" curve! */
|
||||
self->nurb->mat_nr = ( short )PyInt_AS_LONG( args );
|
||||
Py_DECREF( args );
|
||||
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
/*
|
||||
* SurfNurb_getPointsU
|
||||
*
|
||||
* returns number of control points in U direction
|
||||
*/
|
||||
|
||||
static PyObject *SurfNurb_getPointsU( BPy_SurfNurb * self )
|
||||
{
|
||||
return PyInt_FromLong( ( long ) self->nurb->pntsu );
|
||||
}
|
||||
|
||||
/*
|
||||
* SurfNurb_getPointsV
|
||||
*
|
||||
* returns number of control points in V direction
|
||||
*/
|
||||
|
||||
static PyObject *SurfNurb_getPointsV( BPy_SurfNurb * self )
|
||||
{
|
||||
return PyInt_FromLong( ( long ) self->nurb->pntsv );
|
||||
}
|
||||
|
||||
/*
|
||||
* SurfNurb_getFlagU
|
||||
*
|
||||
* returns curve's flagu
|
||||
*/
|
||||
|
||||
static PyObject *SurfNurb_getFlagU( BPy_SurfNurb * self )
|
||||
{
|
||||
return PyInt_FromLong( ( long ) (self->nurb->flagu >> 1) );
|
||||
}
|
||||
|
||||
/*
|
||||
* SurfNurb_setFlagU
|
||||
*
|
||||
* set curve's flagu and recalculate the knots
|
||||
*
|
||||
* Possible values: 0 - uniform, 2 - endpoints, 4 - bezier
|
||||
* bit 0 controls CU_CYCLIC
|
||||
*/
|
||||
|
||||
static int SurfNurb_setFlagU( BPy_SurfNurb * self, PyObject * args )
|
||||
{
|
||||
int flagu;
|
||||
|
||||
args = PyNumber_Int( args );
|
||||
if( !args )
|
||||
return EXPP_ReturnIntError( PyExc_TypeError,
|
||||
"expected integer argument" );
|
||||
|
||||
flagu = ( int )PyInt_AS_LONG( args );
|
||||
Py_DECREF( args );
|
||||
|
||||
if( flagu < 0 || flagu > 2 )
|
||||
return EXPP_ReturnIntError( PyExc_AttributeError,
|
||||
"expected integer argument in range [0,2]" );
|
||||
|
||||
flagu = (flagu << 1) | (self->nurb->flagu & CU_CYCLIC);
|
||||
if( self->nurb->flagu != flagu ) {
|
||||
self->nurb->flagu = (short)flagu;
|
||||
makeknots( self->nurb, 1, self->nurb->flagu >> 1 );
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* SurfNurb_getFlagV
|
||||
*
|
||||
* returns curve's flagu
|
||||
*/
|
||||
|
||||
static PyObject *SurfNurb_getFlagV( BPy_SurfNurb * self )
|
||||
{
|
||||
return PyInt_FromLong( ( long ) (self->nurb->flagv >> 1) );
|
||||
}
|
||||
|
||||
/*
|
||||
* SurfNurb_setFlagV
|
||||
*
|
||||
* set curve's flagu and recalculate the knots
|
||||
*
|
||||
* Possible values: 0 - uniform, 1 - endpoints, 2 - bezier
|
||||
*/
|
||||
|
||||
static int SurfNurb_setFlagV( BPy_SurfNurb * self, PyObject * args )
|
||||
{
|
||||
int flagv;
|
||||
|
||||
args = PyNumber_Int( args );
|
||||
if( !args )
|
||||
return EXPP_ReturnIntError( PyExc_TypeError,
|
||||
"expected integer argument" );
|
||||
|
||||
flagv = ( int )PyInt_AS_LONG( args );
|
||||
Py_DECREF( args );
|
||||
|
||||
if( flagv < 0 || flagv > 2 )
|
||||
return EXPP_ReturnIntError( PyExc_AttributeError,
|
||||
"expected integer argument in range [0,2]" );
|
||||
|
||||
flagv = (flagv << 1) | (self->nurb->flagv & CU_CYCLIC);
|
||||
if( self->nurb->flagv != flagv ) {
|
||||
self->nurb->flagv = (short)flagv;
|
||||
makeknots( self->nurb, 2, self->nurb->flagv >> 1 );
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* SurfNurb_getOrder
|
||||
*
|
||||
* returns curve's order
|
||||
*/
|
||||
|
||||
static PyObject *SurfNurb_getOrderU( BPy_SurfNurb * self )
|
||||
{
|
||||
return PyInt_FromLong( ( long ) self->nurb->orderu );
|
||||
}
|
||||
|
||||
static int SurfNurb_setOrderU( BPy_SurfNurb * self, PyObject * args )
|
||||
{
|
||||
int order;
|
||||
|
||||
args = PyNumber_Int( args );
|
||||
if( !args )
|
||||
return EXPP_ReturnIntError( PyExc_TypeError,
|
||||
"expected integer argument" );
|
||||
|
||||
order = ( int )PyInt_AS_LONG( args );
|
||||
Py_DECREF( args );
|
||||
|
||||
if( order < 2 ) order = 2;
|
||||
else if( order > 6 ) order = 6;
|
||||
|
||||
if( self->nurb->pntsu < order )
|
||||
order = self->nurb->pntsu;
|
||||
|
||||
self->nurb->orderu = (short)order;
|
||||
makeknots( self->nurb, 1, self->nurb->flagu >> 1 );
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static PyObject *SurfNurb_getOrderV( BPy_SurfNurb * self )
|
||||
{
|
||||
return PyInt_FromLong( ( long ) self->nurb->orderv );
|
||||
}
|
||||
|
||||
static int SurfNurb_setOrderV( BPy_SurfNurb * self, PyObject * args )
|
||||
{
|
||||
int order;
|
||||
|
||||
args = PyNumber_Int( args );
|
||||
if( !args )
|
||||
return EXPP_ReturnIntError( PyExc_TypeError,
|
||||
"expected integer argument" );
|
||||
|
||||
order = ( int )PyInt_AS_LONG( args );
|
||||
Py_DECREF( args );
|
||||
|
||||
if( order < 2 ) order = 2;
|
||||
else if( order > 6 ) order = 6;
|
||||
|
||||
if( self->nurb->pntsv < order )
|
||||
order = self->nurb->pntsv;
|
||||
|
||||
self->nurb->orderv = (short)order;
|
||||
makeknots( self->nurb, 2, self->nurb->flagv >> 1 );
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* SurfNurb_getCyclic()
|
||||
* test whether surface is cyclic (closed) or not (open)
|
||||
*/
|
||||
|
||||
static PyObject *SurfNurb_getCyclicU( BPy_SurfNurb * self )
|
||||
{
|
||||
if( self->nurb->flagu & CU_CYCLIC )
|
||||
Py_RETURN_TRUE;
|
||||
else
|
||||
Py_RETURN_FALSE;
|
||||
}
|
||||
|
||||
static PyObject *SurfNurb_getCyclicV( BPy_SurfNurb * self )
|
||||
{
|
||||
if( self->nurb->flagv & CU_CYCLIC )
|
||||
Py_RETURN_TRUE;
|
||||
else
|
||||
Py_RETURN_FALSE;
|
||||
}
|
||||
|
||||
static int SurfNurb_setCyclicU( BPy_SurfNurb * self, PyObject * value )
|
||||
{
|
||||
int param = PyObject_IsTrue( value );
|
||||
if( param == -1 )
|
||||
return EXPP_ReturnIntError( PyExc_TypeError,
|
||||
"expected True/False or 0/1" );
|
||||
|
||||
if( param )
|
||||
self->nurb->flagu |= CU_CYCLIC;
|
||||
else
|
||||
self->nurb->flagu &= ~CU_CYCLIC;
|
||||
makeknots( self->nurb, 1, self->nurb->flagu >> 1 );
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int SurfNurb_setCyclicV( BPy_SurfNurb * self, PyObject * value )
|
||||
{
|
||||
int param = PyObject_IsTrue( value );
|
||||
if( param == -1 )
|
||||
return EXPP_ReturnIntError( PyExc_TypeError,
|
||||
"expected True/False or 0/1" );
|
||||
|
||||
if( param )
|
||||
self->nurb->flagv |= CU_CYCLIC;
|
||||
else
|
||||
self->nurb->flagv &= ~CU_CYCLIC;
|
||||
makeknots( self->nurb, 2, self->nurb->flagu >> 1 );
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* SurfNurb_getKnotsU
|
||||
*
|
||||
* Returns surface's knotsU in a tuple. Empty tuple is returned if
|
||||
* surface isn't Nurbs or it doesn't have knots in U
|
||||
*/
|
||||
|
||||
static PyObject *SurfNurb_getKnotsU( BPy_SurfNurb * self )
|
||||
{
|
||||
if(self->nurb->knotsu) {
|
||||
int len = KNOTSU(self->nurb);
|
||||
int i;
|
||||
PyObject *knotsu = PyTuple_New(len);
|
||||
if( !knotsu )
|
||||
return EXPP_ReturnPyObjError( PyExc_RuntimeError,
|
||||
"could not get SurfNurb.knotsU attribute" );
|
||||
|
||||
for(i = 0; i < len; ++i)
|
||||
PyTuple_SetItem(knotsu, i,
|
||||
PyFloat_FromDouble(self->nurb->knotsu[i]));
|
||||
|
||||
return knotsu;
|
||||
}
|
||||
return PyTuple_New(0);
|
||||
}
|
||||
|
||||
/*
|
||||
* SurfNurb_getKnotsV
|
||||
*
|
||||
* Returns surface's knotsV in a tuple. Empty tuple is returned if
|
||||
* curve doesn't have knots in V
|
||||
*/
|
||||
|
||||
static PyObject *SurfNurb_getKnotsV( BPy_SurfNurb * self )
|
||||
{
|
||||
if(self->nurb->knotsv) {
|
||||
int len = KNOTSV(self->nurb);
|
||||
int i;
|
||||
PyObject *knotsv = PyTuple_New(len);
|
||||
if( !knotsv )
|
||||
return EXPP_ReturnPyObjError( PyExc_RuntimeError,
|
||||
"could not get SurfNurb.knotsV index" );
|
||||
|
||||
for(i = 0; i < len; ++i)
|
||||
PyTuple_SetItem(knotsv, i,
|
||||
PyFloat_FromDouble(self->nurb->knotsv[i] ));
|
||||
|
||||
return knotsv;
|
||||
}
|
||||
return PyTuple_New(0);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* SurfNurb_getIter
|
||||
*
|
||||
* create an iterator for our SurfNurb.
|
||||
* this iterator returns the points for this SurfNurb.
|
||||
*/
|
||||
|
||||
static PyObject *SurfNurb_getIter( BPy_SurfNurb * self )
|
||||
{
|
||||
self->bp = self->nurb->bp;
|
||||
self->bezt = self->nurb->bezt;
|
||||
self->nextPoint = 0;
|
||||
|
||||
Py_INCREF( self );
|
||||
return ( PyObject * ) self;
|
||||
}
|
||||
|
||||
static PyObject *SurfNurb_iterNext( BPy_SurfNurb * self )
|
||||
{
|
||||
Nurb *pnurb = self->nurb;
|
||||
int npoints = pnurb->pntsu * pnurb->pntsv;
|
||||
|
||||
if( self->bp && self->nextPoint < npoints )
|
||||
return SurfNurb_pointAtIndex( self->nurb, self->nextPoint++ );
|
||||
else
|
||||
return EXPP_ReturnPyObjError( PyExc_StopIteration,
|
||||
"iterator at end" );
|
||||
}
|
||||
|
||||
/*
|
||||
* SurfNurb_length
|
||||
* returns the number of points in a Nurb
|
||||
* this is a tp_as_sequence method, not a regular instance method.
|
||||
*/
|
||||
|
||||
static int SurfNurb_length( PyInstanceObject * inst )
|
||||
{
|
||||
Nurb *nurb;
|
||||
|
||||
if( BPy_SurfNurb_Check( ( PyObject * ) inst ) ) {
|
||||
nurb = ( ( BPy_SurfNurb * ) inst )->nurb;
|
||||
return (int)(nurb->pntsu * nurb->pntsu);
|
||||
}
|
||||
|
||||
return EXPP_ReturnIntError( PyExc_RuntimeError,
|
||||
"arg is not a BPy_SurfNurb" );
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* SurfNurb_getPoint
|
||||
* returns the Nth point in a Nurb
|
||||
* this is one of the tp_as_sequence methods, hence the int N argument.
|
||||
* it is called via the [] operator, not as a usual instance method.
|
||||
*/
|
||||
|
||||
PyObject *SurfNurb_getPoint( BPy_SurfNurb * self, int index )
|
||||
{
|
||||
Nurb *myNurb;
|
||||
|
||||
int npoints;
|
||||
|
||||
/* for convenince */
|
||||
myNurb = self->nurb;
|
||||
npoints = myNurb->pntsu * myNurb->pntsv;
|
||||
|
||||
/* bail if no Nurbs in Curve */
|
||||
if( npoints == 0 )
|
||||
return ( EXPP_ReturnPyObjError( PyExc_IndexError,
|
||||
"no points in this SurfNurb" ) );
|
||||
|
||||
/* check index limits */
|
||||
if( index >= npoints || index < 0 )
|
||||
return ( EXPP_ReturnPyObjError( PyExc_IndexError,
|
||||
"index out of range" ) );
|
||||
|
||||
return SurfNurb_pointAtIndex( myNurb, index );
|
||||
}
|
||||
|
||||
/*
|
||||
* SurfNurb_setPoint
|
||||
* modifies the Nth point in a Nurb
|
||||
* this is one of the tp_as_sequence methods, hence the int N argument.
|
||||
* it is called via the [] = operator, not as a usual instance method.
|
||||
*/
|
||||
static int SurfNurb_setPoint( BPy_SurfNurb * self, int index, PyObject * pyOb )
|
||||
{
|
||||
Nurb *nurb = self->nurb;
|
||||
int size;
|
||||
|
||||
/* check index limits */
|
||||
if( index < 0 || index >= nurb->pntsu * nurb->pntsv )
|
||||
return EXPP_ReturnIntError( PyExc_IndexError,
|
||||
"array assignment index out of range\n" );
|
||||
|
||||
/* branch by curve type */
|
||||
#if 0
|
||||
if ((nurb->type & 7)==CU_BEZIER) { /* BEZIER */
|
||||
/* check parameter type */
|
||||
if( !BPy_BezTriple_Check( pyOb ) )
|
||||
return EXPP_ReturnIntError( PyExc_TypeError,
|
||||
"expected a BezTriple\n" );
|
||||
|
||||
/* copy bezier in array */
|
||||
memcpy( nurb->bezt + index,
|
||||
BezTriple_FromPyObject( pyOb ), sizeof( BezTriple ) );
|
||||
|
||||
return 0; /* finished correctly */
|
||||
}
|
||||
else
|
||||
#endif
|
||||
{ /* NURBS or POLY */
|
||||
int i;
|
||||
|
||||
/* check parameter type */
|
||||
if (!PySequence_Check( pyOb ))
|
||||
return EXPP_ReturnIntError( PyExc_TypeError,
|
||||
"expected a list of 4 (or optionaly 5 if the curve is 3D) floats\n" );
|
||||
|
||||
size = PySequence_Size( pyOb );
|
||||
|
||||
/* check sequence size */
|
||||
if( size != 4 && size != 5 )
|
||||
return EXPP_ReturnIntError( PyExc_TypeError,
|
||||
"expected a list of 4 (or optionaly 5 if the curve is 3D) floats\n" );
|
||||
|
||||
/* copy x, y, z, w */
|
||||
for( i = 0; i < 4; ++i ) {
|
||||
PyObject *item = PySequence_GetItem( pyOb, i );
|
||||
|
||||
if (item == NULL)
|
||||
return -1;
|
||||
|
||||
nurb->bp[index].vec[i] = ( float ) PyFloat_AsDouble( item );
|
||||
Py_DECREF( item );
|
||||
}
|
||||
|
||||
if (size == 5) { /* set tilt, if present */
|
||||
PyObject *item = PySequence_GetItem( pyOb, i );
|
||||
|
||||
if (item == NULL)
|
||||
return -1;
|
||||
|
||||
nurb->bp[index].alfa = ( float ) PyFloat_AsDouble( item );
|
||||
Py_DECREF( item );
|
||||
}
|
||||
else { /* if not, set default */
|
||||
nurb->bp[index].alfa = 0.0f;
|
||||
}
|
||||
|
||||
return 0; /* finished correctly */
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* this is an internal routine. not callable directly from python
|
||||
*/
|
||||
|
||||
PyObject *SurfNurb_pointAtIndex( Nurb * nurb, int index )
|
||||
{
|
||||
PyObject *pyo;
|
||||
|
||||
if( nurb->bp ) { /* we have a nurb curve */
|
||||
int i;
|
||||
|
||||
/* add Tilt only if curve is 3D */
|
||||
if (nurb->flag & CU_3D)
|
||||
pyo = PyList_New( 5 );
|
||||
else
|
||||
pyo = PyList_New( 4 );
|
||||
|
||||
for( i = 0; i < 4; i++ ) {
|
||||
PyList_SetItem( pyo, i,
|
||||
PyFloat_FromDouble( nurb->bp[index].
|
||||
vec[i] ) );
|
||||
}
|
||||
|
||||
/* add Tilt only if curve is 3D */
|
||||
if (nurb->flag & CU_3D)
|
||||
PyList_SetItem( pyo, 4, PyFloat_FromDouble( nurb->bp[index].alfa ) );
|
||||
return pyo;
|
||||
|
||||
} else /* something is horribly wrong */
|
||||
return EXPP_ReturnPyObjError( PyExc_SystemError,
|
||||
"non-NURB surface found" );
|
||||
}
|
||||
|
||||
/*
|
||||
* methods for SurfNurb as sequence
|
||||
*/
|
||||
|
||||
static PySequenceMethods SurfNurb_as_sequence = {
|
||||
( inquiry ) SurfNurb_length, /* sq_length */
|
||||
( binaryfunc ) 0, /* sq_concat */
|
||||
( intargfunc ) 0, /* sq_repeat */
|
||||
( intargfunc ) SurfNurb_getPoint, /* sq_item */
|
||||
( intintargfunc ) 0, /* sq_slice */
|
||||
( intobjargproc ) SurfNurb_setPoint, /* sq_ass_item */
|
||||
0, /* sq_ass_slice */
|
||||
( objobjproc ) 0, /* sq_contains */
|
||||
0,
|
||||
0
|
||||
};
|
||||
|
||||
static PyGetSetDef BPy_SurfNurb_getseters[] = {
|
||||
#if 0
|
||||
{"matIndex",
|
||||
(getter)SurfNurb_getMatIndex, (setter)SurfNurb_setMatIndex,
|
||||
"material index", NULL},
|
||||
#endif
|
||||
{"pointsU",
|
||||
(getter)SurfNurb_getPointsU, (setter)NULL,
|
||||
"number of control points in U direction", NULL},
|
||||
{"pointsV",
|
||||
(getter)SurfNurb_getPointsV, (setter)NULL,
|
||||
"number of control points in V direction", NULL},
|
||||
{"flagU",
|
||||
(getter)SurfNurb_getFlagU, (setter)SurfNurb_setFlagU,
|
||||
"knot flag for U direction", NULL},
|
||||
{"flagV",
|
||||
(getter)SurfNurb_getFlagV, (setter)SurfNurb_setFlagV,
|
||||
"knot flag for V direction", NULL},
|
||||
{"cyclicU",
|
||||
(getter)SurfNurb_getCyclicU, (setter)SurfNurb_setCyclicU,
|
||||
"cyclic setting for U direction", NULL},
|
||||
{"cyclicV",
|
||||
(getter)SurfNurb_getCyclicV, (setter)SurfNurb_setCyclicV,
|
||||
"cyclic setting for V direction", NULL},
|
||||
{"orderU",
|
||||
(getter)SurfNurb_getOrderU, (setter)SurfNurb_setOrderU,
|
||||
"order setting for U direction", NULL},
|
||||
{"orderV",
|
||||
(getter)SurfNurb_getOrderV, (setter)SurfNurb_setOrderV,
|
||||
"order setting for V direction", NULL},
|
||||
{"knotsU",
|
||||
(getter)SurfNurb_getKnotsU, (setter)NULL,
|
||||
"The The knot vector in the U direction",
|
||||
NULL},
|
||||
{"knotsV",
|
||||
(getter)SurfNurb_getKnotsV, (setter)NULL,
|
||||
"The The knot vector in the V direction",
|
||||
NULL},
|
||||
|
||||
{NULL,NULL,NULL,NULL,NULL} /* Sentinel */
|
||||
};
|
||||
|
||||
/*
|
||||
* compare
|
||||
* in this case, we consider two SurfNurbs equal, if they point to the same
|
||||
* blender data.
|
||||
*/
|
||||
static int SurfNurb_compare( BPy_SurfNurb * a, BPy_SurfNurb * b )
|
||||
{
|
||||
return ( a->nurb == b->nurb ) ? 0 : -1;
|
||||
}
|
||||
|
||||
/*
|
||||
* SurfNurb_repr
|
||||
*/
|
||||
static PyObject *SurfNurb_repr( BPy_SurfNurb * self )
|
||||
{
|
||||
return PyString_FromFormat( "[SurfNurb \"%d\"]", self->nurb->type );
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Python SurfNurb_Type structure definition: */
|
||||
/*****************************************************************************/
|
||||
PyTypeObject SurfNurb_Type = {
|
||||
PyObject_HEAD_INIT( NULL ) /* required py macro */
|
||||
0, /* ob_size */
|
||||
/* For printing, in format "<module>.<name>" */
|
||||
"SurfNurb", /* char *tp_name; */
|
||||
sizeof( BPy_SurfNurb ), /* int tp_basicsize; */
|
||||
0, /* tp_itemsize; For allocation */
|
||||
|
||||
/* Methods to implement standard operations */
|
||||
|
||||
NULL, /* destructor tp_dealloc; */
|
||||
NULL, /* printfunc tp_print; */
|
||||
NULL, /* getattrfunc tp_getattr; */
|
||||
NULL, /* setattrfunc tp_setattr; */
|
||||
( cmpfunc ) SurfNurb_compare, /* cmpfunc tp_compare; */
|
||||
( reprfunc ) SurfNurb_repr, /* reprfunc tp_repr; */
|
||||
|
||||
/* Method suites for standard classes */
|
||||
|
||||
NULL, /* PyNumberMethods *tp_as_number; */
|
||||
&SurfNurb_as_sequence, /* PySequenceMethods *tp_as_sequence; */
|
||||
NULL, /* PyMappingMethods *tp_as_mapping; */
|
||||
|
||||
/* More standard operations (here for binary compatibility) */
|
||||
|
||||
NULL, /* hashfunc tp_hash; */
|
||||
NULL, /* ternaryfunc tp_call; */
|
||||
NULL, /* reprfunc tp_str; */
|
||||
NULL, /* getattrofunc tp_getattro; */
|
||||
NULL, /* setattrofunc tp_setattro; */
|
||||
|
||||
/* Functions to access object as input/output buffer */
|
||||
NULL, /* PyBufferProcs *tp_as_buffer; */
|
||||
|
||||
/*** Flags to define presence of optional/expanded features ***/
|
||||
Py_TPFLAGS_DEFAULT, /* long tp_flags; */
|
||||
|
||||
NULL, /* char *tp_doc; Documentation string */
|
||||
/*** Assigned meaning in release 2.0 ***/
|
||||
/* call function for all accessible objects */
|
||||
NULL, /* traverseproc tp_traverse; */
|
||||
|
||||
/* delete references to contained objects */
|
||||
NULL, /* inquiry tp_clear; */
|
||||
|
||||
/*** Assigned meaning in release 2.1 ***/
|
||||
/*** rich comparisons ***/
|
||||
NULL, /* richcmpfunc tp_richcompare; */
|
||||
|
||||
/*** weak reference enabler ***/
|
||||
0, /* long tp_weaklistoffset; */
|
||||
|
||||
/*** Added in release 2.2 ***/
|
||||
/* Iterators */
|
||||
( getiterfunc ) SurfNurb_getIter, /* getiterfunc tp_iter; */
|
||||
( iternextfunc ) SurfNurb_iterNext, /* iternextfunc tp_iternext; */
|
||||
|
||||
/*** Attribute descriptor and subclassing stuff ***/
|
||||
BPy_SurfNurb_methods, /* struct PyMethodDef *tp_methods; */
|
||||
NULL, /* struct PyMemberDef *tp_members; */
|
||||
BPy_SurfNurb_getseters, /* struct PyGetSetDef *tp_getset; */
|
||||
NULL, /* struct _typeobject *tp_base; */
|
||||
NULL, /* PyObject *tp_dict; */
|
||||
NULL, /* descrgetfunc tp_descr_get; */
|
||||
NULL, /* descrsetfunc tp_descr_set; */
|
||||
0, /* long tp_dictoffset; */
|
||||
NULL, /* initproc tp_init; */
|
||||
NULL, /* allocfunc tp_alloc; */
|
||||
NULL, /* newfunc tp_new; */
|
||||
/* Low-level free-memory routine */
|
||||
NULL, /* freefunc tp_free; */
|
||||
/* For PyObject_IS_GC */
|
||||
NULL, /* inquiry tp_is_gc; */
|
||||
NULL, /* PyObject *tp_bases; */
|
||||
/* method resolution order */
|
||||
NULL, /* PyObject *tp_mro; */
|
||||
NULL, /* PyObject *tp_cache; */
|
||||
NULL, /* PyObject *tp_subclasses; */
|
||||
NULL, /* PyObject *tp_weaklist; */
|
||||
NULL
|
||||
};
|
||||
|
||||
/*
|
||||
factory method to create a BPy_SurfNurb from a Blender Nurb
|
||||
*/
|
||||
|
||||
PyObject *SurfNurb_CreatePyObject( Nurb * blen_nurb )
|
||||
{
|
||||
BPy_SurfNurb *pyNurb;
|
||||
|
||||
pyNurb = ( BPy_SurfNurb * ) PyObject_NEW( BPy_SurfNurb, &SurfNurb_Type );
|
||||
|
||||
if( !pyNurb )
|
||||
return EXPP_ReturnPyObjError( PyExc_MemoryError,
|
||||
"could not create BPy_SurfNurb PyObject" );
|
||||
|
||||
pyNurb->nurb = blen_nurb;
|
||||
return ( PyObject * ) pyNurb;
|
||||
}
|
||||
|
||||
|
||||
PyObject *SurfNurb_Init( void )
|
||||
{
|
||||
PyType_Ready( &SurfNurb_Type );
|
||||
return Py_InitModule3( "Blender.SurfNurb", M_SurfNurb_methods,
|
||||
M_SurfNurb_doc );
|
||||
}
|
||||
|
||||
@@ -1,65 +0,0 @@
|
||||
/*
|
||||
* $Id$
|
||||
* ***** 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*
|
||||
* The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This is a new part of Blender.
|
||||
*
|
||||
* Contributor(s): Stephen Swaney
|
||||
*
|
||||
* ***** END GPL LICENSE BLOCK *****
|
||||
*/
|
||||
|
||||
#ifndef EXPP_SURFNURB_H
|
||||
#define EXPP_SURFNURB_H
|
||||
|
||||
#include <Python.h>
|
||||
#include "DNA_curve_types.h"
|
||||
|
||||
extern PyTypeObject SurfNurb_Type;
|
||||
|
||||
#define BPy_SurfNurb_Check(v) ((v)->ob_type == &SurfNurb_Type) /* for type checking */
|
||||
|
||||
/* Python BPy_SurfNurb structure definition */
|
||||
typedef struct {
|
||||
PyObject_HEAD
|
||||
Nurb * nurb;
|
||||
|
||||
/* iterator stuff */
|
||||
/* internal ptrs to point data. do not free */
|
||||
BPoint *bp;
|
||||
BezTriple *bezt;
|
||||
int atEnd; /* iter exhausted flag */
|
||||
int nextPoint;
|
||||
|
||||
} BPy_SurfNurb;
|
||||
|
||||
|
||||
/*
|
||||
* prototypes
|
||||
*/
|
||||
|
||||
PyObject *SurfNurb_Init( void );
|
||||
PyObject *SurfNurb_CreatePyObject( Nurb * bzt );
|
||||
Nurb *SurfNurb_FromPyObject( PyObject * pyobj );
|
||||
|
||||
PyObject *SurfNurb_getPoint( BPy_SurfNurb * self, int index );
|
||||
PyObject *SurfNurb_pointAtIndex( Nurb * nurb, int index );
|
||||
|
||||
#endif /* EXPP_SURFNURB_H */
|
||||
@@ -1,421 +0,0 @@
|
||||
/*
|
||||
* $Id$
|
||||
*
|
||||
* ***** 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*
|
||||
* The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This is a new part of Blender.
|
||||
*
|
||||
* Contributor(s): Willian P. Germano, Campbell Barton
|
||||
*
|
||||
* ***** END GPL LICENSE BLOCK *****
|
||||
*/
|
||||
|
||||
#include "Sys.h" /*This must come first*/
|
||||
|
||||
#include "BKE_utildefines.h"
|
||||
#include "BKE_global.h"
|
||||
#include "BLI_blenlib.h"
|
||||
#include "DNA_scene_types.h" /* G.scene-"r.cfra */
|
||||
#include "PIL_time.h"
|
||||
#include "gen_utils.h"
|
||||
|
||||
#ifdef WIN32
|
||||
#define DIRSEP '\\'
|
||||
#define DIRSEP_STR "\\"
|
||||
#else
|
||||
#define DIRSEP '/'
|
||||
#define DIRSEP_STR "/"
|
||||
#endif
|
||||
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Python API function prototypes for the sys module. */
|
||||
/*****************************************************************************/
|
||||
static PyObject *M_sys_basename( PyObject * self, PyObject * value );
|
||||
static PyObject *M_sys_dirname( PyObject * self, PyObject * value );
|
||||
static PyObject *M_sys_join( PyObject * self, PyObject * args );
|
||||
static PyObject *M_sys_splitext( PyObject * self, PyObject * value );
|
||||
static PyObject *M_sys_makename( PyObject * self, PyObject * args,
|
||||
PyObject * kw );
|
||||
static PyObject *M_sys_exists( PyObject * self, PyObject * value );
|
||||
static PyObject *M_sys_time( PyObject * self );
|
||||
static PyObject *M_sys_sleep( PyObject * self, PyObject * args );
|
||||
static PyObject *M_sys_expandpath( PyObject *self, PyObject *value);
|
||||
static PyObject *M_sys_cleanpath( PyObject *self, PyObject *value);
|
||||
|
||||
/*****************************************************************************/
|
||||
/* The following string definitions are used for documentation strings. */
|
||||
/* In Python these will be written to the console when doing a */
|
||||
/* Blender.sys.__doc__ */
|
||||
/*****************************************************************************/
|
||||
static char M_sys_doc[] = "The Blender.sys submodule\n\
|
||||
\n\
|
||||
This is a minimal system module to supply simple functionality available\n\
|
||||
in the default Python module os.";
|
||||
|
||||
static char M_sys_basename_doc[] =
|
||||
"(path) - Split 'path' in dir and filename.\n\
|
||||
Return the filename.";
|
||||
|
||||
static char M_sys_dirname_doc[] =
|
||||
"(path) - Split 'path' in dir and filename.\n\
|
||||
Return the dir.";
|
||||
|
||||
static char M_sys_join_doc[] =
|
||||
"(dir, file) - Join dir and file to form a full filename.\n\
|
||||
Return the filename.";
|
||||
|
||||
static char M_sys_splitext_doc[] =
|
||||
"(path) - Split 'path' in root and extension:\n\
|
||||
/this/that/file.ext -> ('/this/that/file','.ext').\n\
|
||||
Return the pair (root, extension).";
|
||||
|
||||
static char M_sys_makename_doc[] =
|
||||
"(path = Blender.Get('filename'), ext = \"\", strip = 0) -\n\
|
||||
Strip dir and extension from path, leaving only a name, then append 'ext'\n\
|
||||
to it (if given) and return the resulting string.\n\n\
|
||||
(path) - string: a pathname -- Blender.Get('filename') if 'path' isn't given;\n\
|
||||
(ext = \"\") - string: the extension to append.\n\
|
||||
(strip = 0) - int: strip dirname from 'path' if given and non-zero.\n\
|
||||
Ex: makename('/path/to/file/myfile.foo','-01.abc') returns 'myfile-01.abc'\n\
|
||||
Ex: makename(ext='.txt') returns 'untitled.txt' if Blender.Get('filename')\n\
|
||||
returns a path to the file 'untitled.blend'";
|
||||
|
||||
static char M_sys_time_doc[] =
|
||||
"() - Return a float representing time elapsed in seconds.\n\
|
||||
Each successive call is garanteed to return values greater than or\n\
|
||||
equal to the previous call.";
|
||||
|
||||
static char M_sys_sleep_doc[] =
|
||||
"(milliseconds = 10) - Sleep for the specified time.\n\
|
||||
(milliseconds = 10) - the amount of time in milliseconds to sleep.\n\
|
||||
This function can be necessary in tight 'get event' loops.";
|
||||
|
||||
static char M_sys_exists_doc[] =
|
||||
"(path) - Check if the given pathname exists.\n\
|
||||
The return value is as follows:\n\
|
||||
\t 0: path doesn't exist;\n\
|
||||
\t 1: path is an existing filename;\n\
|
||||
\t 2: path is an existing dirname;\n\
|
||||
\t-1: path exists but is neither a regular file nor a dir.";
|
||||
|
||||
static char M_sys_expandpath_doc[] =
|
||||
"(path) - Expand this Blender internal path to a proper file system path.\n\
|
||||
(path) - the string path to convert.\n\n\
|
||||
Note: internally Blender paths can contain two special character sequences:\n\
|
||||
- '//' (at start) for base path directory (the current .blend's dir path);\n\
|
||||
- '#' characters in the filename will be replaced by the frame number.\n\n\
|
||||
This function expands these to their actual content, returning a valid path.\n\
|
||||
If the special chars are not found in the given path, it is simply returned.";
|
||||
|
||||
static char M_sys_cleanpath_doc[] =
|
||||
"(path) - Removes parts of a path that are not needed paths such as '../foo/../bar/' and '//./././'";
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Python method structure definition for Blender.sys module: */
|
||||
/*****************************************************************************/
|
||||
struct PyMethodDef M_sys_methods[] = {
|
||||
{"basename", M_sys_basename, METH_O, M_sys_basename_doc},
|
||||
{"dirname", M_sys_dirname, METH_O, M_sys_dirname_doc},
|
||||
{"join", M_sys_join, METH_VARARGS, M_sys_join_doc},
|
||||
{"splitext", M_sys_splitext, METH_O, M_sys_splitext_doc},
|
||||
{"makename", ( PyCFunction ) M_sys_makename,
|
||||
METH_VARARGS | METH_KEYWORDS,
|
||||
M_sys_makename_doc},
|
||||
{"exists", M_sys_exists, METH_O, M_sys_exists_doc},
|
||||
{"sleep", M_sys_sleep, METH_VARARGS, M_sys_sleep_doc},
|
||||
{"time", ( PyCFunction ) M_sys_time, METH_NOARGS, M_sys_time_doc},
|
||||
{"expandpath", M_sys_expandpath, METH_O, M_sys_expandpath_doc},
|
||||
{"cleanpath", M_sys_cleanpath, METH_O, M_sys_cleanpath_doc},
|
||||
{NULL, NULL, 0, NULL}
|
||||
};
|
||||
|
||||
/* Module Functions */
|
||||
|
||||
PyObject *sys_Init( void )
|
||||
{
|
||||
PyObject *submodule, *dict;
|
||||
|
||||
submodule = Py_InitModule3( "Blender.sys", M_sys_methods, M_sys_doc );
|
||||
|
||||
dict = PyModule_GetDict( submodule );
|
||||
|
||||
EXPP_dict_set_item_str( dict, "dirsep", PyString_FromString(DIRSEP_STR) );
|
||||
EXPP_dict_set_item_str( dict, "sep", PyString_FromString(DIRSEP_STR) );
|
||||
|
||||
return submodule;
|
||||
}
|
||||
|
||||
static PyObject *M_sys_basename( PyObject * self, PyObject * value )
|
||||
{
|
||||
char *name = PyString_AsString(value);
|
||||
char *p, basename[FILE_MAXDIR + FILE_MAXFILE];
|
||||
int n, len;
|
||||
|
||||
if( !name )
|
||||
return EXPP_ReturnPyObjError( PyExc_TypeError,
|
||||
"expected string argument" );
|
||||
|
||||
len = strlen( name );
|
||||
|
||||
#ifdef WIN32
|
||||
p = MAX2(strrchr( name, '/' ), strrchr( name, '\\' ));
|
||||
#else
|
||||
p = strrchr( name, DIRSEP );
|
||||
#endif
|
||||
|
||||
if( p ) {
|
||||
n = name + len - p - 1; /* - 1 because we don't want the sep */
|
||||
|
||||
if( n > FILE_MAXDIR + FILE_MAXFILE )
|
||||
return EXPP_ReturnPyObjError( PyExc_RuntimeError,
|
||||
"path too long" );
|
||||
|
||||
BLI_strncpy( basename, p + 1, n + 1 );
|
||||
return PyString_FromString( basename );
|
||||
}
|
||||
|
||||
return PyString_FromString( name );
|
||||
}
|
||||
|
||||
static PyObject *M_sys_dirname( PyObject * self, PyObject * value )
|
||||
{
|
||||
char *name = PyString_AsString(value);
|
||||
char *p, dirname[FILE_MAXDIR + FILE_MAXFILE];
|
||||
int n;
|
||||
|
||||
if( !name )
|
||||
return EXPP_ReturnPyObjError( PyExc_TypeError,
|
||||
"expected string argument" );
|
||||
|
||||
#ifdef WIN32
|
||||
p = MAX2(strrchr( name, '/' ), strrchr( name, '\\' ));
|
||||
#else
|
||||
p = strrchr( name, DIRSEP );
|
||||
#endif
|
||||
|
||||
if( p ) {
|
||||
n = p - name;
|
||||
|
||||
if( n > FILE_MAXDIR + FILE_MAXFILE )
|
||||
return EXPP_ReturnPyObjError( PyExc_RuntimeError,
|
||||
"path too long" );
|
||||
|
||||
BLI_strncpy( dirname, name, n + 1 );
|
||||
return PyString_FromString( dirname );
|
||||
}
|
||||
|
||||
return PyString_FromString( "." );
|
||||
}
|
||||
|
||||
static PyObject *M_sys_join( PyObject * self, PyObject * args )
|
||||
{
|
||||
char *name = NULL, *path = NULL;
|
||||
char filename[FILE_MAXDIR + FILE_MAXFILE];
|
||||
int pathlen = 0, namelen = 0;
|
||||
|
||||
if( !PyArg_ParseTuple( args, "ss", &path, &name ) )
|
||||
return EXPP_ReturnPyObjError( PyExc_TypeError,
|
||||
"expected string argument" );
|
||||
|
||||
pathlen = strlen( path ) + 1;
|
||||
namelen = strlen( name ) + 1; /* + 1 to account for '\0' for BLI_strncpy */
|
||||
|
||||
if( pathlen + namelen > FILE_MAXDIR + FILE_MAXFILE - 1 )
|
||||
return EXPP_ReturnPyObjError( PyExc_RuntimeError,
|
||||
"filename is too long." );
|
||||
|
||||
BLI_strncpy( filename, path, pathlen );
|
||||
|
||||
if( filename[pathlen - 2] != DIRSEP ) {
|
||||
filename[pathlen - 1] = DIRSEP;
|
||||
pathlen += 1;
|
||||
}
|
||||
|
||||
BLI_strncpy( filename + pathlen - 1, name, namelen );
|
||||
|
||||
return PyString_FromString( filename );
|
||||
}
|
||||
|
||||
static PyObject *M_sys_splitext( PyObject * self, PyObject * value )
|
||||
{
|
||||
char *name = PyString_AsString(value);
|
||||
char *dot, *p, path[FILE_MAXDIR + FILE_MAXFILE], ext[FILE_MAXDIR + FILE_MAXFILE];
|
||||
int n, len;
|
||||
|
||||
if( !name )
|
||||
return EXPP_ReturnPyObjError( PyExc_TypeError,
|
||||
"expected string argument" );
|
||||
|
||||
len = strlen( name );
|
||||
dot = strrchr( name, '.' );
|
||||
|
||||
if( !dot )
|
||||
return Py_BuildValue( "ss", name, "" );
|
||||
|
||||
p = strrchr( name, DIRSEP );
|
||||
|
||||
if( p ) {
|
||||
if( p > dot )
|
||||
return Py_BuildValue( "ss", name, "" );
|
||||
}
|
||||
|
||||
n = name + len - dot;
|
||||
|
||||
/* loong extensions are supported -- foolish, but Python's os.path.splitext
|
||||
* supports them, so ... */
|
||||
|
||||
if( n >= FILE_MAXDIR + FILE_MAXFILE || ( len - n ) >= FILE_MAXDIR + FILE_MAXFILE )
|
||||
return EXPP_ReturnPyObjError( PyExc_RuntimeError, "path too long" );
|
||||
|
||||
BLI_strncpy( ext, dot, n + 1 );
|
||||
BLI_strncpy( path, name, dot - name + 1 );
|
||||
|
||||
return Py_BuildValue( "ss", path, ext );
|
||||
}
|
||||
|
||||
static PyObject *M_sys_makename( PyObject * self, PyObject * args,
|
||||
PyObject * kw )
|
||||
{
|
||||
char *path = G.sce, *ext = NULL;
|
||||
int strip = 0;
|
||||
static char *kwlist[] = { "path", "ext", "strip", NULL };
|
||||
char *dot = NULL, *p = NULL, basename[FILE_MAXDIR + FILE_MAXFILE];
|
||||
int n, len, lenext = 0;
|
||||
|
||||
if( !PyArg_ParseTupleAndKeywords( args, kw, "|ssi", kwlist,
|
||||
&path, &ext, &strip ) )
|
||||
return EXPP_ReturnPyObjError( PyExc_TypeError,
|
||||
"expected one or two strings and an int (or nothing) as arguments" );
|
||||
|
||||
len = strlen( path ) + 1; /* + 1 to consider ending '\0' */
|
||||
if( ext )
|
||||
lenext = strlen( ext ) + 1;
|
||||
|
||||
if( ( len + lenext ) > FILE_MAXDIR + FILE_MAXFILE )
|
||||
return EXPP_ReturnPyObjError( PyExc_RuntimeError,
|
||||
"path too long" );
|
||||
|
||||
p = strrchr( path, DIRSEP );
|
||||
|
||||
if( p && strip ) {
|
||||
n = path + len - p;
|
||||
BLI_strncpy( basename, p + 1, n ); /* + 1 to skip the sep */
|
||||
} else
|
||||
BLI_strncpy( basename, path, len );
|
||||
|
||||
dot = strrchr( basename, '.' );
|
||||
|
||||
/* now the extension: always remove the one in basename */
|
||||
if( dot || ext ) {
|
||||
if( !ext )
|
||||
basename[dot - basename] = '\0';
|
||||
else { /* if user gave an ext, append it */
|
||||
|
||||
if( dot )
|
||||
n = dot - basename;
|
||||
else
|
||||
n = strlen( basename );
|
||||
|
||||
BLI_strncpy( basename + n, ext, lenext );
|
||||
}
|
||||
}
|
||||
|
||||
return PyString_FromString( basename );
|
||||
}
|
||||
|
||||
static PyObject *M_sys_time( PyObject * self )
|
||||
{
|
||||
return PyFloat_FromDouble( PIL_check_seconds_timer( ) );
|
||||
}
|
||||
|
||||
static PyObject *M_sys_sleep( PyObject * self, PyObject * args )
|
||||
{
|
||||
int millisecs = 10;
|
||||
|
||||
if( !PyArg_ParseTuple( args, "|i", &millisecs ) )
|
||||
return EXPP_ReturnPyObjError( PyExc_TypeError,
|
||||
"expected int argument" );
|
||||
|
||||
PIL_sleep_ms( millisecs );
|
||||
|
||||
return EXPP_incr_ret( Py_None );
|
||||
}
|
||||
|
||||
static PyObject *M_sys_exists( PyObject * self, PyObject * value )
|
||||
{
|
||||
char *fname = PyString_AsString(value);
|
||||
|
||||
int mode = 0, i = -1;
|
||||
|
||||
if( !fname )
|
||||
return EXPP_ReturnPyObjError( PyExc_TypeError,
|
||||
"expected string (pathname) argument" );
|
||||
|
||||
mode = BLI_exist(fname);
|
||||
|
||||
if( mode == 0 )
|
||||
i = 0;
|
||||
else if( S_ISREG( mode ) )
|
||||
i = 1;
|
||||
else if( S_ISDIR( mode ) )
|
||||
i = 2;
|
||||
/* i stays as -1 if path exists but is neither a regular file nor a dir */
|
||||
|
||||
return PyInt_FromLong(i);
|
||||
}
|
||||
|
||||
static PyObject *M_sys_expandpath( PyObject * self, PyObject * value )
|
||||
{
|
||||
char *path = PyString_AsString(value);
|
||||
char expanded[FILE_MAXDIR + FILE_MAXFILE];
|
||||
|
||||
if (!path)
|
||||
return EXPP_ReturnPyObjError( PyExc_TypeError,
|
||||
"expected string argument" );
|
||||
|
||||
BLI_strncpy(expanded, path, FILE_MAXDIR + FILE_MAXFILE);
|
||||
BLI_convertstringcode(expanded, G.sce);
|
||||
BLI_convertstringframe(expanded, G.scene->r.cfra);
|
||||
|
||||
return PyString_FromString(expanded);
|
||||
}
|
||||
|
||||
static PyObject *M_sys_cleanpath( PyObject * self, PyObject * value )
|
||||
{
|
||||
char *path = PyString_AsString(value);
|
||||
char cleaned[FILE_MAXDIR + FILE_MAXFILE];
|
||||
int trailing_slash = 0, last;
|
||||
if (!path)
|
||||
return EXPP_ReturnPyObjError( PyExc_TypeError,
|
||||
"expected string argument" );
|
||||
last = strlen(path)-1;
|
||||
if ((last >= 0) && ((path[last]=='/') || (path[last]=='\\'))) {
|
||||
trailing_slash = 1;
|
||||
}
|
||||
BLI_strncpy(cleaned, path, FILE_MAXDIR + FILE_MAXFILE);
|
||||
BLI_cleanup_file(NULL, cleaned);
|
||||
|
||||
if (trailing_slash) {
|
||||
BLI_add_slash(cleaned);
|
||||
}
|
||||
|
||||
return PyString_FromString(cleaned);
|
||||
}
|
||||
@@ -1,932 +0,0 @@
|
||||
/*
|
||||
* $Id$
|
||||
*
|
||||
* ***** 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*
|
||||
* The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This is a new part of Blender.
|
||||
*
|
||||
* Contributor(s): Willian P. Germano
|
||||
*
|
||||
* ***** END GPL LICENSE BLOCK *****
|
||||
*/
|
||||
|
||||
#include "Text.h" /*This must come first*/
|
||||
|
||||
#include "BKE_library.h"
|
||||
#include "BKE_sca.h"
|
||||
#include "BKE_global.h"
|
||||
#include "BKE_main.h"
|
||||
#include "BIF_drawtext.h"
|
||||
#include "BIF_screen.h"
|
||||
#include "BKE_text.h"
|
||||
#include "BKE_suggestions.h"
|
||||
#include "BLI_blenlib.h"
|
||||
#include "DNA_screen_types.h"
|
||||
#include "DNA_space_types.h"
|
||||
#include "MEM_guardedalloc.h"
|
||||
#include "gen_utils.h"
|
||||
#include "gen_library.h"
|
||||
#include "../BPY_extern.h"
|
||||
|
||||
#define EXPP_TEXT_MODE_FOLLOW TXT_FOLLOW
|
||||
|
||||
/* checks for the group being removed */
|
||||
#define TEXT_DEL_CHECK_PY(bpy_text) if (!(bpy_text->text)) return ( EXPP_ReturnPyObjError( PyExc_RuntimeError, "Text has been removed" ) )
|
||||
#define TEXT_DEL_CHECK_INT(bpy_text) if (!(bpy_text->text)) return ( EXPP_ReturnIntError( PyExc_RuntimeError, "Text has been removed" ) )
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Python API function prototypes for the Text module. */
|
||||
/*****************************************************************************/
|
||||
static PyObject *M_Text_New( PyObject * self, PyObject * args);
|
||||
static PyObject *M_Text_Get( PyObject * self, PyObject * args );
|
||||
static PyObject *M_Text_Load( PyObject * self, PyObject * value );
|
||||
static PyObject *M_Text_unlink( PyObject * self, PyObject * args );
|
||||
|
||||
/*****************************************************************************/
|
||||
/* The following string definitions are used for documentation strings. */
|
||||
/* In Python these will be written to the console when doing a */
|
||||
/* Blender.Text.__doc__ */
|
||||
/*****************************************************************************/
|
||||
static char M_Text_doc[] = "The Blender Text module\n\n";
|
||||
|
||||
static char M_Text_New_doc[] = "() - return a new Text object";
|
||||
|
||||
static char M_Text_Get_doc[] = "(name) - return the Text with name 'name', \
|
||||
returns None if not found.\n If 'name' is not specified, \
|
||||
it returns a list of all Texts in the\ncurrent scene.";
|
||||
|
||||
static char M_Text_Load_doc[] =
|
||||
"(filename) - return text from file filename as a Text Object, \
|
||||
returns None if not found.\n";
|
||||
|
||||
static char M_Text_unlink_doc[] =
|
||||
"(text) - remove Text object 'text' from Blender";
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Python method structure definition for Blender.Text module: */
|
||||
/*****************************************************************************/
|
||||
struct PyMethodDef M_Text_methods[] = {
|
||||
{"New", M_Text_New, METH_VARARGS, M_Text_New_doc},
|
||||
{"Get", M_Text_Get, METH_VARARGS, M_Text_Get_doc},
|
||||
{"get", M_Text_Get, METH_VARARGS, M_Text_Get_doc},
|
||||
{"Load", M_Text_Load, METH_O, M_Text_Load_doc},
|
||||
{"unlink", M_Text_unlink, METH_VARARGS, M_Text_unlink_doc},
|
||||
{NULL, NULL, 0, NULL}
|
||||
};
|
||||
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Python BPy_Text methods declarations: */
|
||||
/*****************************************************************************/
|
||||
static PyObject *Text_getFilename( BPy_Text * self );
|
||||
static PyObject *Text_getNLines( BPy_Text * self );
|
||||
static PyObject *Text_clear( BPy_Text * self );
|
||||
static PyObject *Text_reset( BPy_Text * self );
|
||||
static PyObject *Text_readline( BPy_Text * self );
|
||||
static PyObject *Text_write( BPy_Text * self, PyObject * value );
|
||||
static PyObject *Text_insert( BPy_Text * self, PyObject * value );
|
||||
static PyObject *Text_delete( BPy_Text * self, PyObject * value );
|
||||
static PyObject *Text_set( BPy_Text * self, PyObject * args );
|
||||
static PyObject *Text_asLines( BPy_Text * self, PyObject * args );
|
||||
static PyObject *Text_getCursorPos( BPy_Text * self );
|
||||
static PyObject *Text_setCursorPos( BPy_Text * self, PyObject * args );
|
||||
static PyObject *Text_getSelectPos( BPy_Text * self );
|
||||
static PyObject *Text_setSelectPos( BPy_Text * self, PyObject * args );
|
||||
static PyObject *Text_markSelection( BPy_Text * self, PyObject * args );
|
||||
static PyObject *Text_suggest( BPy_Text * self, PyObject * args );
|
||||
static PyObject *Text_showDocs( BPy_Text * self, PyObject * args );
|
||||
|
||||
static void text_reset_internal( BPy_Text * self ); /* internal func */
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Python BPy_Text methods table: */
|
||||
/*****************************************************************************/
|
||||
static PyMethodDef BPy_Text_methods[] = {
|
||||
/* name, method, flags, doc */
|
||||
{"getName", ( PyCFunction ) GenericLib_getName, METH_NOARGS,
|
||||
"() - Return Text Object name"},
|
||||
{"getFilename", ( PyCFunction ) Text_getFilename, METH_VARARGS,
|
||||
"() - Return Text Object filename"},
|
||||
{"getNLines", ( PyCFunction ) Text_getNLines, METH_VARARGS,
|
||||
"() - Return number of lines in text buffer"},
|
||||
{"setName", ( PyCFunction ) GenericLib_setName_with_method, METH_VARARGS,
|
||||
"(str) - Change Text Object name"},
|
||||
{"clear", ( PyCFunction ) Text_clear, METH_NOARGS,
|
||||
"() - Clear Text buffer"},
|
||||
{"reset", ( PyCFunction ) Text_reset, METH_NOARGS,
|
||||
"() - Moves the IO pointer back to the start of the Text buffer for reading"},
|
||||
{"readline", ( PyCFunction ) Text_readline, METH_NOARGS,
|
||||
"() - Reads a line of text from the buffer and returns it incrementing the internal IO pointer."},
|
||||
{"write", ( PyCFunction ) Text_write, METH_O,
|
||||
"(line) - Append string 'str' to Text buffer"},
|
||||
{"insert", ( PyCFunction ) Text_insert, METH_O,
|
||||
"(line) - Insert string 'str' to Text buffer at cursor location"},
|
||||
{"delete", ( PyCFunction ) Text_delete, METH_O,
|
||||
"(chars) - Deletes a number of characters to the left (chars<0) or right (chars>0)"},
|
||||
{"set", ( PyCFunction ) Text_set, METH_VARARGS,
|
||||
"(name, val) - Set attribute 'name' to value 'val'"},
|
||||
{"asLines", ( PyCFunction ) Text_asLines, METH_VARARGS,
|
||||
"(start=0, end=nlines) - Return text buffer as a list of lines between start and end"},
|
||||
{"getCursorPos", ( PyCFunction ) Text_getCursorPos, METH_NOARGS,
|
||||
"() - Return cursor position as (row, col) tuple"},
|
||||
{"setCursorPos", ( PyCFunction ) Text_setCursorPos, METH_VARARGS,
|
||||
"(row, col) - Set the cursor position to (row, col)"},
|
||||
{"getSelectPos", ( PyCFunction ) Text_getSelectPos, METH_NOARGS,
|
||||
"() - Return the selection cursor position as (row, col) tuple"},
|
||||
{"setSelectPos", ( PyCFunction ) Text_setSelectPos, METH_VARARGS,
|
||||
"(row, col) - Set the selection cursor position to (row, col)"},
|
||||
{"markSelection", ( PyCFunction ) Text_markSelection, METH_VARARGS,
|
||||
"(group, (r, g, b), flags) - Places a marker over the current selection. Group: number > 0, flags: TMARK_TEMP, TMARK_EDITALL, etc."},
|
||||
{"suggest", ( PyCFunction ) Text_suggest, METH_VARARGS,
|
||||
"(list, prefix='') - Presents a list of suggestions. List is of strings, or tuples. Tuples must be of the form (name, type) where type is one of 'm', 'v', 'f', 'k' for module, variable, function and keyword respectively or '?' for other types"},
|
||||
{"showDocs", ( PyCFunction ) Text_showDocs, METH_VARARGS,
|
||||
"(docs) - Documentation string"},
|
||||
{NULL, NULL, 0, NULL}
|
||||
};
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Python Text_Type callback function prototypes: */
|
||||
/*****************************************************************************/
|
||||
static int Text_compare( BPy_Text * a, BPy_Text * b );
|
||||
static PyObject *Text_repr( BPy_Text * self );
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Function: M_Text_New */
|
||||
/* Python equivalent: Blender.Text.New */
|
||||
/*****************************************************************************/
|
||||
static PyObject *M_Text_New( PyObject * self, PyObject * args)
|
||||
{
|
||||
char *name = "Text";
|
||||
int follow = 0;
|
||||
Text *bl_text; /* blender text object */
|
||||
PyObject *py_text; /* python wrapper */
|
||||
|
||||
if( !PyArg_ParseTuple( args, "|si", &name, &follow ) )
|
||||
return EXPP_ReturnPyObjError( PyExc_AttributeError,
|
||||
"expected string and int arguments (or nothing)" );
|
||||
|
||||
bl_text = add_empty_text( name );
|
||||
|
||||
if( bl_text ) {
|
||||
/* do not set user count because Text is already linked */
|
||||
|
||||
/* create python wrapper obj */
|
||||
py_text = Text_CreatePyObject( bl_text );
|
||||
} else
|
||||
return EXPP_ReturnPyObjError( PyExc_RuntimeError,
|
||||
"couldn't create Text Object in Blender" );
|
||||
if( !py_text )
|
||||
return EXPP_ReturnPyObjError( PyExc_MemoryError,
|
||||
"couldn't create Text Object wrapper" );
|
||||
|
||||
if( follow )
|
||||
bl_text->flags |= EXPP_TEXT_MODE_FOLLOW;
|
||||
|
||||
return py_text;
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Function: M_Text_Get */
|
||||
/* Python equivalent: Blender.Text.Get */
|
||||
/* Description: Receives a string and returns the text object */
|
||||
/* whose name matches the string. If no argument is */
|
||||
/* passed in, a list of all text names in the current */
|
||||
/* scene is returned. */
|
||||
/*****************************************************************************/
|
||||
static PyObject *M_Text_Get( PyObject * self, PyObject * args )
|
||||
{
|
||||
char *name = NULL;
|
||||
Text *txt_iter;
|
||||
|
||||
if( !PyArg_ParseTuple( args, "|s", &name ) )
|
||||
return ( EXPP_ReturnPyObjError( PyExc_TypeError,
|
||||
"expected string argument (or nothing)" ) );
|
||||
|
||||
txt_iter = G.main->text.first;
|
||||
|
||||
if( name ) { /* (name) - Search text by name */
|
||||
|
||||
PyObject *wanted_txt = NULL;
|
||||
|
||||
while( ( txt_iter ) && ( wanted_txt == NULL ) ) {
|
||||
|
||||
if( strcmp( name, txt_iter->id.name + 2 ) == 0 ) {
|
||||
wanted_txt = Text_CreatePyObject( txt_iter );
|
||||
}
|
||||
|
||||
txt_iter = txt_iter->id.next;
|
||||
}
|
||||
|
||||
if( wanted_txt == NULL ) { /* Requested text doesn't exist */
|
||||
char error_msg[64];
|
||||
PyOS_snprintf( error_msg, sizeof( error_msg ),
|
||||
"Text \"%s\" not found", name );
|
||||
return ( EXPP_ReturnPyObjError
|
||||
( PyExc_NameError, error_msg ) );
|
||||
}
|
||||
|
||||
return wanted_txt;
|
||||
}
|
||||
|
||||
else { /* () - return a list of all texts in the scene */
|
||||
int index = 0;
|
||||
PyObject *txtlist, *pyobj;
|
||||
|
||||
txtlist = PyList_New( BLI_countlist( &( G.main->text ) ) );
|
||||
|
||||
if( txtlist == NULL )
|
||||
return ( EXPP_ReturnPyObjError( PyExc_MemoryError,
|
||||
"couldn't create PyList" ) );
|
||||
|
||||
while( txt_iter ) {
|
||||
pyobj = Text_CreatePyObject( txt_iter );
|
||||
|
||||
if( !pyobj ) {
|
||||
Py_DECREF(txtlist);
|
||||
return ( EXPP_ReturnPyObjError
|
||||
( PyExc_MemoryError,
|
||||
"couldn't create PyString" ) );
|
||||
}
|
||||
PyList_SET_ITEM( txtlist, index, pyobj );
|
||||
|
||||
txt_iter = txt_iter->id.next;
|
||||
index++;
|
||||
}
|
||||
|
||||
return ( txtlist );
|
||||
}
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Function: M_Text_Load */
|
||||
/* Python equivalent: Blender.Text.Load */
|
||||
/* Description: Receives a filename and returns the text object */
|
||||
/* created from the corresponding file. */
|
||||
/*****************************************************************************/
|
||||
static PyObject *M_Text_Load( PyObject * self, PyObject * value )
|
||||
{
|
||||
char *fname = PyString_AsString(value);
|
||||
char fpath[FILE_MAXDIR + FILE_MAXFILE];
|
||||
Text *txt_ptr = NULL;
|
||||
unsigned int maxlen = FILE_MAXDIR + FILE_MAXFILE;
|
||||
|
||||
if( !fname )
|
||||
return ( EXPP_ReturnPyObjError( PyExc_TypeError,
|
||||
"expected string argument" ) );
|
||||
|
||||
if (strlen(fname) > (maxlen - 1))
|
||||
return EXPP_ReturnPyObjError (PyExc_AttributeError,
|
||||
"text filename too long");
|
||||
else if (!BLI_exists(fname))
|
||||
return EXPP_ReturnPyObjError (PyExc_AttributeError,
|
||||
"text file not found");
|
||||
|
||||
BLI_strncpy(fpath, fname, maxlen);
|
||||
|
||||
txt_ptr = add_text( fpath );
|
||||
if( !txt_ptr )
|
||||
return EXPP_ReturnPyObjError( PyExc_IOError,
|
||||
"couldn't load text" );
|
||||
|
||||
return Text_CreatePyObject(txt_ptr);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Function: M_Text_unlink */
|
||||
/* Python equivalent: Blender.Text.unlink */
|
||||
/* Description: Removes the given Text object from Blender */
|
||||
/*****************************************************************************/
|
||||
static PyObject *M_Text_unlink( PyObject * self, PyObject * args )
|
||||
{
|
||||
BPy_Text *textobj;
|
||||
Text *text;
|
||||
|
||||
if( !PyArg_ParseTuple( args, "O!", &Text_Type, &textobj ) )
|
||||
return EXPP_ReturnPyObjError( PyExc_TypeError,
|
||||
"expected a Text object as argument" );
|
||||
|
||||
text = ( ( BPy_Text * ) textobj )->text;
|
||||
|
||||
if( !text )
|
||||
return EXPP_ReturnPyObjError( PyExc_RuntimeError,
|
||||
"this text was already unlinked!" );
|
||||
|
||||
BPY_clear_bad_scriptlinks( text );
|
||||
BPY_free_pyconstraint_links( text );
|
||||
free_text_controllers( text );
|
||||
unlink_text( text );
|
||||
|
||||
free_libblock( &G.main->text, text );
|
||||
|
||||
( ( BPy_Text * ) textobj )->text = NULL;
|
||||
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Function: Text_Init */
|
||||
/*****************************************************************************/
|
||||
PyObject *Text_Init( void )
|
||||
{
|
||||
PyObject *submodule, *dict;
|
||||
|
||||
if( PyType_Ready( &Text_Type ) < 0 )
|
||||
return NULL;
|
||||
|
||||
submodule =
|
||||
Py_InitModule3( "Blender.Text", M_Text_methods, M_Text_doc );
|
||||
|
||||
dict = PyModule_GetDict( submodule );
|
||||
|
||||
#define EXPP_ADDCONST(x) \
|
||||
EXPP_dict_set_item_str(dict, #x, PyInt_FromLong(x))
|
||||
|
||||
/* So, for example:
|
||||
* EXPP_ADDCONST(LEFTMOUSE) becomes
|
||||
* EXPP_dict_set_item_str(dict, "LEFTMOUSE", PyInt_FromLong(LEFTMOUSE))
|
||||
*/
|
||||
|
||||
EXPP_ADDCONST( TMARK_TEMP );
|
||||
EXPP_ADDCONST( TMARK_EDITALL );
|
||||
|
||||
return ( submodule );
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Function: Text_CreatePyObject */
|
||||
/*****************************************************************************/
|
||||
PyObject *Text_CreatePyObject( Text * txt )
|
||||
{
|
||||
BPy_Text *pytxt;
|
||||
|
||||
pytxt = ( BPy_Text * ) PyObject_NEW( BPy_Text, &Text_Type );
|
||||
|
||||
if( !pytxt )
|
||||
return EXPP_ReturnPyObjError( PyExc_MemoryError,
|
||||
"couldn't create BPy_Text PyObject" );
|
||||
|
||||
pytxt->text = txt;
|
||||
text_reset_internal(pytxt);
|
||||
|
||||
return ( PyObject * ) pytxt;
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Python BPy_Text methods: */
|
||||
/*****************************************************************************/
|
||||
static PyObject *Text_getFilename( BPy_Text * self )
|
||||
{
|
||||
TEXT_DEL_CHECK_PY(self);
|
||||
if( self->text->name )
|
||||
return PyString_FromString( self->text->name );
|
||||
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
static PyObject *Text_getNLines( BPy_Text * self )
|
||||
{ /* text->nlines isn't updated in Blender (?) */
|
||||
int nlines = 0;
|
||||
TextLine *line;
|
||||
|
||||
TEXT_DEL_CHECK_PY(self);
|
||||
|
||||
line = self->text->lines.first;
|
||||
|
||||
while( line ) { /* so we have to count them ourselves */
|
||||
line = line->next;
|
||||
nlines++;
|
||||
}
|
||||
|
||||
self->text->nlines = nlines; /* and update Blender, too (should we?) */
|
||||
|
||||
return PyInt_FromLong( nlines );
|
||||
}
|
||||
|
||||
static PyObject *Text_clear( BPy_Text * self)
|
||||
{
|
||||
int oldstate;
|
||||
|
||||
TEXT_DEL_CHECK_PY(self);
|
||||
|
||||
oldstate = txt_get_undostate( );
|
||||
txt_set_undostate( 1 );
|
||||
txt_sel_all( self->text );
|
||||
txt_cut_sel( self->text );
|
||||
txt_set_undostate( oldstate );
|
||||
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
static void text_reset_internal( BPy_Text * self )
|
||||
{
|
||||
self->iol = NULL;
|
||||
self->ioc = -1;
|
||||
}
|
||||
|
||||
static PyObject *Text_reset( BPy_Text * self )
|
||||
{
|
||||
text_reset_internal(self);
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
static PyObject *Text_readline( BPy_Text * self )
|
||||
{
|
||||
PyObject *tmpstr;
|
||||
|
||||
TEXT_DEL_CHECK_PY(self);
|
||||
|
||||
/* Reset */
|
||||
if (!self->iol && self->ioc == -1) {
|
||||
self->iol = self->text->lines.first;
|
||||
self->ioc = 0;
|
||||
}
|
||||
|
||||
if (!self->iol) {
|
||||
PyErr_SetString( PyExc_StopIteration, "End of buffer reached" );
|
||||
return PyString_FromString( "" );
|
||||
}
|
||||
|
||||
if (self->ioc > self->iol->len) {
|
||||
self->iol = NULL;
|
||||
return EXPP_ReturnPyObjError( PyExc_RuntimeError,
|
||||
"Line length exceeded, text may have changed while reading" );
|
||||
}
|
||||
|
||||
tmpstr = PyString_FromString( self->iol->line + self->ioc );
|
||||
if (self->iol->next)
|
||||
PyString_ConcatAndDel( &tmpstr, PyString_FromString("\n") );
|
||||
|
||||
self->iol = self->iol->next;
|
||||
self->ioc = 0;
|
||||
|
||||
return tmpstr;
|
||||
}
|
||||
|
||||
static PyObject *Text_write( BPy_Text * self, PyObject * value )
|
||||
{
|
||||
char *str = PyString_AsString(value);
|
||||
int oldstate;
|
||||
|
||||
if( !str )
|
||||
return EXPP_ReturnPyObjError( PyExc_TypeError,
|
||||
"expected string argument" );
|
||||
|
||||
TEXT_DEL_CHECK_PY(self);
|
||||
|
||||
oldstate = txt_get_undostate( );
|
||||
txt_insert_buf( self->text, str );
|
||||
txt_move_eof( self->text, 0 );
|
||||
txt_set_undostate( oldstate );
|
||||
|
||||
text_reset_internal( self );
|
||||
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
static PyObject *Text_insert( BPy_Text * self, PyObject * value )
|
||||
{
|
||||
char *str = PyString_AsString(value);
|
||||
int oldstate;
|
||||
|
||||
if( !str )
|
||||
return EXPP_ReturnPyObjError( PyExc_TypeError,
|
||||
"expected string argument" );
|
||||
|
||||
TEXT_DEL_CHECK_PY(self);
|
||||
|
||||
oldstate = txt_get_undostate( );
|
||||
txt_insert_buf( self->text, str );
|
||||
txt_set_undostate( oldstate );
|
||||
|
||||
text_reset_internal( self );
|
||||
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
static PyObject *Text_delete( BPy_Text * self, PyObject * value )
|
||||
{
|
||||
int num = PyInt_AsLong(value);
|
||||
int oldstate;
|
||||
|
||||
TEXT_DEL_CHECK_PY(self);
|
||||
|
||||
/* zero num is invalid and -1 is an error value */
|
||||
if( !num || (num==-1 && PyErr_Occurred()))
|
||||
return EXPP_ReturnPyObjError( PyExc_TypeError,
|
||||
"expected non-zero int argument" );
|
||||
|
||||
oldstate = txt_get_undostate( );
|
||||
while (num<0) {
|
||||
txt_backspace_char(self->text);
|
||||
num++;
|
||||
}
|
||||
while (num>0) {
|
||||
txt_delete_char(self->text);
|
||||
num--;
|
||||
}
|
||||
txt_set_undostate( oldstate );
|
||||
|
||||
text_reset_internal( self );
|
||||
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
static PyObject *Text_set( BPy_Text * self, PyObject * args )
|
||||
{
|
||||
int ival;
|
||||
char *attr;
|
||||
|
||||
TEXT_DEL_CHECK_PY(self);
|
||||
|
||||
if( !PyArg_ParseTuple( args, "si", &attr, &ival ) )
|
||||
return EXPP_ReturnPyObjError( PyExc_TypeError,
|
||||
"expected a string and an int as arguments" );
|
||||
|
||||
if( strcmp( "follow_cursor", attr ) == 0 ) {
|
||||
if( ival )
|
||||
self->text->flags |= EXPP_TEXT_MODE_FOLLOW;
|
||||
else
|
||||
self->text->flags &= EXPP_TEXT_MODE_FOLLOW;
|
||||
}
|
||||
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
static PyObject *Text_asLines( BPy_Text * self, PyObject * args )
|
||||
{
|
||||
TextLine *line;
|
||||
PyObject *list, *tmpstr;
|
||||
int start=0, end=-1, i;
|
||||
|
||||
TEXT_DEL_CHECK_PY(self);
|
||||
|
||||
if( !PyArg_ParseTuple( args, "|ii", &start, &end ) )
|
||||
return EXPP_ReturnPyObjError( PyExc_TypeError,
|
||||
"expected upto two optional ints as arguments" );
|
||||
|
||||
if (start<0)
|
||||
start=0;
|
||||
|
||||
line = self->text->lines.first;
|
||||
for (i = 0; i < start && line->next; i++)
|
||||
line= line->next;
|
||||
|
||||
list = PyList_New( 0 );
|
||||
|
||||
if( !list )
|
||||
return EXPP_ReturnPyObjError( PyExc_MemoryError,
|
||||
"couldn't create PyList" );
|
||||
|
||||
while( line && (i < end || end == -1) ) {
|
||||
tmpstr = PyString_FromString( line->line );
|
||||
PyList_Append( list, tmpstr );
|
||||
Py_DECREF(tmpstr);
|
||||
line = line->next;
|
||||
i++;
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
static PyObject *Text_getCursorPos( BPy_Text * self )
|
||||
{
|
||||
Text *text;
|
||||
TextLine *linep;
|
||||
int row, col;
|
||||
|
||||
TEXT_DEL_CHECK_PY(self);
|
||||
|
||||
text = self->text;
|
||||
|
||||
for (row=0,linep=text->lines.first; linep!=text->curl; linep=linep->next)
|
||||
row++;
|
||||
col= text->curc;
|
||||
|
||||
return Py_BuildValue( "ii", row, col );
|
||||
}
|
||||
|
||||
static PyObject *Text_setCursorPos( BPy_Text * self, PyObject * args )
|
||||
{
|
||||
int row, col;
|
||||
SpaceText *st;
|
||||
|
||||
TEXT_DEL_CHECK_PY(self);
|
||||
|
||||
if (!PyArg_ParseTuple(args, "ii", &row, &col))
|
||||
return EXPP_ReturnPyObjError(PyExc_TypeError,
|
||||
"expected two ints as arguments.");
|
||||
if (row<0) row=0;
|
||||
if (col<0) col=0;
|
||||
|
||||
txt_move_to(self->text, row, col, 0);
|
||||
|
||||
if (curarea->spacetype == SPACE_TEXT && (st=curarea->spacedata.first))
|
||||
pop_space_text(st);
|
||||
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
static PyObject *Text_getSelectPos( BPy_Text * self )
|
||||
{
|
||||
Text *text;
|
||||
TextLine *linep;
|
||||
int row, col;
|
||||
|
||||
TEXT_DEL_CHECK_PY(self);
|
||||
|
||||
text = self->text;
|
||||
|
||||
for (row=0,linep=text->lines.first; linep!=text->sell; linep=linep->next)
|
||||
row++;
|
||||
col= text->selc;
|
||||
|
||||
return Py_BuildValue( "ii", row, col );
|
||||
}
|
||||
|
||||
static PyObject *Text_setSelectPos( BPy_Text * self, PyObject * args )
|
||||
{
|
||||
int row, col;
|
||||
SpaceText *st;
|
||||
|
||||
TEXT_DEL_CHECK_PY(self);
|
||||
|
||||
if (!PyArg_ParseTuple(args, "ii", &row, &col))
|
||||
return EXPP_ReturnPyObjError(PyExc_TypeError,
|
||||
"expected two ints as arguments.");
|
||||
if (row<0) row=0;
|
||||
if (col<0) col=0;
|
||||
|
||||
txt_move_to(self->text, row, col, 1);
|
||||
|
||||
if (curarea->spacetype == SPACE_TEXT && (st=curarea->spacedata.first))
|
||||
pop_space_text(st);
|
||||
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
static PyObject *Text_markSelection( BPy_Text * self, PyObject * args )
|
||||
{
|
||||
int group = 0, flags = 0,r, g, b;
|
||||
Text *text;
|
||||
char color[4];
|
||||
|
||||
TEXT_DEL_CHECK_PY(self);
|
||||
|
||||
text = self->text;
|
||||
|
||||
if (!PyArg_ParseTuple(args, "i(iii)i", &group, &r, &g, &b, &flags))
|
||||
return EXPP_ReturnPyObjError(PyExc_TypeError,
|
||||
"expected int, 3-tuple of ints and int as arguments.");
|
||||
|
||||
if (text->curl != text->sell)
|
||||
return EXPP_ReturnPyObjError(PyExc_RuntimeError,
|
||||
"Cannot mark multi-line selection.");
|
||||
|
||||
color[0] = (char) (r&0xFF);
|
||||
color[1] = (char) (g&0xFF);
|
||||
color[2] = (char) (b&0xFF);
|
||||
color[3] = 255;
|
||||
|
||||
group &= 0xFFFF;
|
||||
|
||||
txt_add_marker(text, text->curl, text->curc, text->selc, color, group, flags);
|
||||
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
static PyObject *Text_suggest( BPy_Text * self, PyObject * args )
|
||||
{
|
||||
PyObject *item = NULL, *tup1 = NULL, *tup2 = NULL;
|
||||
PyObject *list = NULL;
|
||||
int list_len, i;
|
||||
char *prefix = NULL, *name, type;
|
||||
SpaceText *st;
|
||||
|
||||
TEXT_DEL_CHECK_PY(self);
|
||||
|
||||
/* Parse args for a list of strings/tuples */
|
||||
if (!PyArg_ParseTuple(args, "O!|s", &PyList_Type, &list, &prefix))
|
||||
return EXPP_ReturnPyObjError(PyExc_TypeError,
|
||||
"expected list of strings or tuples followed by an optional string");
|
||||
|
||||
if (curarea->spacetype != SPACE_TEXT)
|
||||
return EXPP_ReturnPyObjError(PyExc_RuntimeError,
|
||||
"Active space type is not text");
|
||||
|
||||
st = curarea->spacedata.first;
|
||||
if (!st || !st->text)
|
||||
return EXPP_ReturnPyObjError(PyExc_RuntimeError,
|
||||
"Active text area has no Text object");
|
||||
|
||||
texttool_suggest_clear();
|
||||
texttool_text_set_active(st->text);
|
||||
list_len = PyList_Size(list);
|
||||
|
||||
for (i = 0; i < list_len; i++) {
|
||||
item = PyList_GetItem(list, i);
|
||||
|
||||
if (PyString_Check(item)) {
|
||||
name = PyString_AsString(item);
|
||||
type = '?';
|
||||
} else if (PyTuple_Check(item) && PyTuple_GET_SIZE(item) == 2) {
|
||||
tup1 = PyTuple_GetItem(item, 0);
|
||||
tup2 = PyTuple_GetItem(item, 1);
|
||||
if (PyString_Check(tup1) && PyString_Check(tup2)) {
|
||||
name = PyString_AsString(tup1);
|
||||
type = PyString_AsString(tup2)[0];
|
||||
} else
|
||||
return EXPP_ReturnPyObjError(PyExc_AttributeError,
|
||||
"list must contain tuples of two strings only: (name, type)" );
|
||||
} else
|
||||
return EXPP_ReturnPyObjError(PyExc_AttributeError,
|
||||
"list must contain only individual strings or tuples of size 2" );
|
||||
|
||||
if (!strlen(name) || (type!='m' && type!='v' && type!='f' && type!='k' && type!='?'))
|
||||
return EXPP_ReturnPyObjError(PyExc_AttributeError,
|
||||
"names must be non-empty and types in ['m', 'v', 'f', 'k', '?']" );
|
||||
|
||||
texttool_suggest_add(name, type);
|
||||
}
|
||||
if (!prefix)
|
||||
prefix = "";
|
||||
texttool_suggest_prefix(prefix);
|
||||
scrarea_queue_redraw(curarea);
|
||||
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
static PyObject *Text_showDocs( BPy_Text * self, PyObject * args )
|
||||
{
|
||||
char *docs;
|
||||
SpaceText *st;
|
||||
|
||||
TEXT_DEL_CHECK_PY(self);
|
||||
|
||||
if (!PyArg_ParseTuple(args, "s", &docs))
|
||||
return EXPP_ReturnPyObjError( PyExc_TypeError,
|
||||
"expected a string as argument" );
|
||||
|
||||
if (curarea->spacetype != SPACE_TEXT)
|
||||
return EXPP_ReturnPyObjError(PyExc_RuntimeError,
|
||||
"Active space type is not text");
|
||||
|
||||
st = curarea->spacedata.first;
|
||||
if (!st || !st->text)
|
||||
return EXPP_ReturnPyObjError(PyExc_RuntimeError,
|
||||
"Active text area has no Text object");
|
||||
|
||||
texttool_text_set_active(st->text);
|
||||
texttool_docs_show(docs);
|
||||
scrarea_queue_redraw(curarea);
|
||||
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Function: Text_compare */
|
||||
/* Description: This is a callback function for the BPy_Text type. It */
|
||||
/* compares two Text_Type objects. Only the "==" and "!=" */
|
||||
/* comparisons are meaninful. Returns 0 for equality and -1 if */
|
||||
/* they don't point to the same Blender Text struct. */
|
||||
/* In Python it becomes 1 if they are equal, 0 otherwise. */
|
||||
/*****************************************************************************/
|
||||
static int Text_compare( BPy_Text * a, BPy_Text * b )
|
||||
{
|
||||
return ( a->text == b->text ) ? 0 : -1;
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Function: Text_repr */
|
||||
/* Description: This is a callback function for the BPy_Text type. It */
|
||||
/* builds a meaninful string to represent text objects. */
|
||||
/*****************************************************************************/
|
||||
static PyObject *Text_repr( BPy_Text * self )
|
||||
{
|
||||
if( self->text )
|
||||
return PyString_FromFormat( "[Text \"%s\"]",
|
||||
self->text->id.name + 2 );
|
||||
else
|
||||
return PyString_FromString( "[Text <deleted>]" );
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Python attributes get/set functions: */
|
||||
/*****************************************************************************/
|
||||
static PyObject *Text_getMode(BPy_Text * self)
|
||||
{
|
||||
TEXT_DEL_CHECK_PY(self);
|
||||
return PyInt_FromLong( self->text->flags );
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Python attributes get/set structure: */
|
||||
/*****************************************************************************/
|
||||
static PyGetSetDef BPy_Text_getseters[] = {
|
||||
GENERIC_LIB_GETSETATTR,
|
||||
{"filename", (getter)Text_getFilename, (setter)NULL,
|
||||
"text filename", NULL},
|
||||
{"mode", (getter)Text_getMode, (setter)NULL,
|
||||
"text mode flag", NULL},
|
||||
{"nlines", (getter)Text_getNLines, (setter)NULL,
|
||||
"number of lines", NULL},
|
||||
{NULL,NULL,NULL,NULL,NULL} /* Sentinel */
|
||||
};
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Python Text_Type structure definition: */
|
||||
/*****************************************************************************/
|
||||
PyTypeObject Text_Type = {
|
||||
PyObject_HEAD_INIT( NULL )
|
||||
0, /* ob_size */
|
||||
"Blender Text", /* tp_name */
|
||||
sizeof( BPy_Text ), /* tp_basicsize */
|
||||
0, /* tp_itemsize */
|
||||
/* methods */
|
||||
NULL, /* tp_dealloc */
|
||||
NULL, /* tp_print */
|
||||
NULL, /* tp_getattr */
|
||||
NULL, /* tp_setattr */
|
||||
( cmpfunc ) Text_compare, /* tp_compare */
|
||||
( reprfunc ) Text_repr, /* tp_repr */
|
||||
|
||||
/* Method suites for standard classes */
|
||||
|
||||
NULL, /* PyNumberMethods *tp_as_number; */
|
||||
NULL, /* PySequenceMethods *tp_as_sequence; */
|
||||
NULL, /* PyMappingMethods *tp_as_mapping; */
|
||||
|
||||
/* More standard operations (here for binary compatibility) */
|
||||
|
||||
( hashfunc ) GenericLib_hash, /* hashfunc tp_hash; */
|
||||
NULL, /* ternaryfunc tp_call; */
|
||||
NULL, /* reprfunc tp_str; */
|
||||
NULL, /* getattrofunc tp_getattro; */
|
||||
NULL, /* setattrofunc tp_setattro; */
|
||||
|
||||
/* Functions to access object as input/output buffer */
|
||||
NULL, /* PyBufferProcs *tp_as_buffer; */
|
||||
|
||||
/*** Flags to define presence of optional/expanded features ***/
|
||||
Py_TPFLAGS_DEFAULT, /* long tp_flags; */
|
||||
|
||||
NULL, /* char *tp_doc; Documentation string */
|
||||
/*** Assigned meaning in release 2.0 ***/
|
||||
/* call function for all accessible objects */
|
||||
NULL, /* traverseproc tp_traverse; */
|
||||
|
||||
/* delete references to contained objects */
|
||||
NULL, /* inquiry tp_clear; */
|
||||
|
||||
/*** Assigned meaning in release 2.1 ***/
|
||||
/*** rich comparisons ***/
|
||||
NULL, /* richcmpfunc tp_richcompare; */
|
||||
|
||||
/*** weak reference enabler ***/
|
||||
0, /* long tp_weaklistoffset; */
|
||||
|
||||
/*** Added in release 2.2 ***/
|
||||
/* Iterators */
|
||||
NULL, /* getiterfunc tp_iter; */
|
||||
NULL, /* iternextfunc tp_iternext; */
|
||||
|
||||
/*** Attribute descriptor and subclassing stuff ***/
|
||||
BPy_Text_methods, /* struct PyMethodDef *tp_methods; */
|
||||
NULL, /* struct PyMemberDef *tp_members; */
|
||||
BPy_Text_getseters, /* struct PyGetSetDef *tp_getset; */
|
||||
NULL, /* struct _typeobject *tp_base; */
|
||||
NULL, /* PyObject *tp_dict; */
|
||||
NULL, /* descrgetfunc tp_descr_get; */
|
||||
NULL, /* descrsetfunc tp_descr_set; */
|
||||
0, /* long tp_dictoffset; */
|
||||
NULL, /* initproc tp_init; */
|
||||
NULL, /* allocfunc tp_alloc; */
|
||||
NULL, /* newfunc tp_new; */
|
||||
/* Low-level free-memory routine */
|
||||
NULL, /* freefunc tp_free; */
|
||||
/* For PyObject_IS_GC */
|
||||
NULL, /* inquiry tp_is_gc; */
|
||||
NULL, /* PyObject *tp_bases; */
|
||||
/* method resolution order */
|
||||
NULL, /* PyObject *tp_mro; */
|
||||
NULL, /* PyObject *tp_cache; */
|
||||
NULL, /* PyObject *tp_subclasses; */
|
||||
NULL, /* PyObject *tp_weaklist; */
|
||||
NULL
|
||||
};
|
||||
@@ -1,51 +0,0 @@
|
||||
/*
|
||||
* $Id$
|
||||
*
|
||||
* ***** 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*
|
||||
* The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This is a new part of Blender.
|
||||
*
|
||||
* Contributor(s): Willian P. Germano
|
||||
*
|
||||
* ***** END GPL LICENSE BLOCK *****
|
||||
*/
|
||||
|
||||
#ifndef EXPP_TEXT_H
|
||||
#define EXPP_TEXT_H
|
||||
|
||||
#include <Python.h>
|
||||
#include "DNA_text_types.h"
|
||||
|
||||
extern PyTypeObject Text_Type;
|
||||
|
||||
/* Type checking for EXPP PyTypes */
|
||||
#define BPy_Text_Check(v) ((v)->ob_type == &Text_Type)
|
||||
|
||||
typedef struct {
|
||||
PyObject_HEAD
|
||||
Text * text; /* libdata must be second */
|
||||
TextLine * iol; /* current line being read or NULL if reset */
|
||||
int ioc; /* character offset in line being read */
|
||||
} BPy_Text;
|
||||
|
||||
PyObject *Text_Init( void );
|
||||
PyObject *Text_CreatePyObject( Text * txt );
|
||||
|
||||
#endif /* EXPP_TEXT_H */
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,53 +0,0 @@
|
||||
/*
|
||||
* $Id$
|
||||
*
|
||||
* ***** 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*
|
||||
* The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This is a new part of Blender.
|
||||
*
|
||||
* Contributor(s): Joilnen Leite
|
||||
*
|
||||
* ***** END GPL LICENSE BLOCK *****
|
||||
*/
|
||||
|
||||
#ifndef EXPP_TEXT3D_H
|
||||
#define EXPP_TEXT3D_H
|
||||
|
||||
#include <Python.h>
|
||||
#include "DNA_curve_types.h"
|
||||
|
||||
extern PyTypeObject Text3d_Type;
|
||||
|
||||
#define BPy_Text3d_Check(v) ((v)->ob_type==&Text3d_Type)
|
||||
typedef Curve Text3d;
|
||||
|
||||
/*prototypes*/
|
||||
PyObject *Text3d_Init( void );
|
||||
struct Text3d *Text3d_FromPyObject( PyObject * py_obj );
|
||||
PyObject *Text3d_CreatePyObject( Text3d* text3d );
|
||||
|
||||
/* Python BPy_Text3d structure definition */
|
||||
typedef struct {
|
||||
PyObject_HEAD /* required py macro */
|
||||
Text3d * curve;
|
||||
} BPy_Text3d;
|
||||
|
||||
#endif /* EXPP_TEXT3D_H */
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,61 +0,0 @@
|
||||
/*
|
||||
* $Id$
|
||||
*
|
||||
* ***** 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*
|
||||
* The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This is a new part of Blender.
|
||||
*
|
||||
* Contributor(s): Alex Mole
|
||||
*
|
||||
* ***** END GPL LICENSE BLOCK *****
|
||||
*/
|
||||
|
||||
/* based on Image.h */
|
||||
|
||||
#ifndef EXPP_TEXTURE_H
|
||||
#define EXPP_TEXTURE_H
|
||||
|
||||
#include <Python.h>
|
||||
#include "DNA_texture_types.h"
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Python BPy_Texture structure definition */
|
||||
/*****************************************************************************/
|
||||
|
||||
typedef struct {
|
||||
PyObject_HEAD
|
||||
Tex * texture; /* libdata must be second */
|
||||
} BPy_Texture;
|
||||
|
||||
extern PyTypeObject Texture_Type;
|
||||
|
||||
#define BPy_Texture_Check(v) ((v)->ob_type == &Texture_Type)
|
||||
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Module Blender.Texture - public functions */
|
||||
/*****************************************************************************/
|
||||
|
||||
PyObject *Texture_Init( void );
|
||||
PyObject *Texture_CreatePyObject( struct Tex *tex );
|
||||
Tex *Texture_FromPyObject( PyObject * pyobj );
|
||||
|
||||
|
||||
#endif /* EXPP_TEXTURE_H */
|
||||
@@ -1,378 +0,0 @@
|
||||
/*
|
||||
* $Id$
|
||||
* ***** 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*
|
||||
* The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This is a new part of Blender.
|
||||
*
|
||||
* Contributor(s): Willian P. Germano, Alex Mole, Joseph Gilbert
|
||||
*
|
||||
* ***** END GPL LICENSE BLOCK *****
|
||||
*/
|
||||
|
||||
#include "Types.h"
|
||||
#include "IDProp.h"
|
||||
#include "gen_utils.h"
|
||||
#include "BLI_blenlib.h"
|
||||
/*
|
||||
stuff pasted from the old Types.h
|
||||
is only need here now
|
||||
*/
|
||||
|
||||
extern PyTypeObject IDGroup_Type, IDArray_Type;
|
||||
extern PyTypeObject Action_Type, Armature_Type;
|
||||
extern PyTypeObject Pose_Type;
|
||||
extern PyTypeObject BezTriple_Type, Bone_Type, Button_Type;
|
||||
extern PyTypeObject Camera_Type;
|
||||
extern PyTypeObject CurNurb_Type, SurfNurb_Type;
|
||||
extern PyTypeObject Curve_Type;
|
||||
extern PyTypeObject Effect_Type, Font_Type;
|
||||
extern PyTypeObject Image_Type, Ipo_Type, IpoCurve_Type;
|
||||
extern PyTypeObject Lamp_Type, Lattice_Type;
|
||||
extern PyTypeObject Material_Type, Metaball_Type, MTex_Type;
|
||||
extern PyTypeObject NMFace_Type, NMEdge_Type, NMVert_Type, NMCol_Type,
|
||||
NMesh_Type;
|
||||
extern PyTypeObject MFace_Type, MVert_Type, PVert_Type, MEdge_Type, MCol_Type,
|
||||
Mesh_Type;
|
||||
|
||||
extern PyTypeObject Object_Type;
|
||||
extern PyTypeObject Group_Type;
|
||||
extern PyTypeObject Particle_Type;
|
||||
extern PyTypeObject Scene_Type, RenderData_Type;
|
||||
extern PyTypeObject Text_Type, Text3d_Type, Texture_Type;
|
||||
extern PyTypeObject World_Type;
|
||||
extern PyTypeObject property_Type;
|
||||
extern PyTypeObject buffer_Type, constant_Type, euler_Type;
|
||||
extern PyTypeObject matrix_Type, quaternion_Type, rgbTuple_Type, vector_Type;
|
||||
extern PyTypeObject point_Type;
|
||||
extern PyTypeObject Modifier_Type, ModSeq_Type;
|
||||
extern PyTypeObject EditBone_Type;
|
||||
extern PyTypeObject ThemeSpace_Type;
|
||||
extern PyTypeObject ThemeUI_Type;
|
||||
extern PyTypeObject TimeLine_Type;
|
||||
|
||||
/* includes to get structs for CSizeof */
|
||||
#include "Armature.h"
|
||||
#include "Bone.h"
|
||||
#include "BezTriple.h"
|
||||
#include "Camera.h"
|
||||
#include "Constraint.h"
|
||||
#include "Curve.h"
|
||||
#include "CurNurb.h"
|
||||
#include "Draw.h"
|
||||
#include "Effect.h"
|
||||
#include "Ipo.h"
|
||||
#include "Ipocurve.h"
|
||||
#include "Key.h"
|
||||
#include "Lamp.h"
|
||||
#include "Lattice.h"
|
||||
#include "Library.h"
|
||||
#include "Mathutils.h"
|
||||
#include "Geometry.h"
|
||||
#include "Mesh.h"
|
||||
#include "Metaball.h"
|
||||
#include "Modifier.h"
|
||||
#include "NMesh.h"
|
||||
#include "Node.h"
|
||||
#include "Object.h"
|
||||
#include "Group.h"
|
||||
#include "Registry.h"
|
||||
#include "Scene.h"
|
||||
#include "Sound.h"
|
||||
#include "SurfNurb.h"
|
||||
#include "Sys.h"
|
||||
#include "Text.h"
|
||||
#include "Texture.h"
|
||||
#include "Window.h"
|
||||
#include "World.h"
|
||||
#include "Particle.h"
|
||||
|
||||
char M_Types_doc[] = "The Blender Types module\n\n\
|
||||
This module is a dictionary of all Blender Python types";
|
||||
|
||||
static PyObject *Types_CSizeof(PyObject * self, PyObject *o)
|
||||
{
|
||||
int ret = 0;
|
||||
if(o) {
|
||||
if((void *)o == (void *)&Action_Type) {
|
||||
ret = sizeof(struct bAction);
|
||||
} else if ((void *)o==(void *)&Armature_Type) {
|
||||
ret = sizeof(struct bArmature);
|
||||
} else if ((void *)o==(void *)&BezTriple_Type) {
|
||||
ret = sizeof(struct BezTriple);
|
||||
} else if ((void *)o==(void *)&Bone_Type) {
|
||||
ret = sizeof(struct Bone);
|
||||
} else if ((void *)o==(void *)&Camera_Type) {
|
||||
ret = sizeof(struct Camera);
|
||||
} else if ((void *)o==(void *)&CurNurb_Type) {
|
||||
ret = sizeof(struct Nurb);
|
||||
} else if ((void *)o==(void *)&Curve_Type) {
|
||||
ret = sizeof(struct Curve);
|
||||
} else if ((void *)o==(void *)&Group_Type) {
|
||||
ret = sizeof(struct Group);
|
||||
} else if ((void *)o==(void *)&IDGroup_Type) {
|
||||
ret = sizeof(struct IDProperty);
|
||||
} else if ((void *)o==(void *)&Image_Type) {
|
||||
ret = sizeof(struct Image);
|
||||
} else if ((void *)o==(void *)&Ipo_Type) {
|
||||
ret = sizeof(struct Ipo);
|
||||
} else if ((void *)o==(void *)&IpoCurve_Type) {
|
||||
ret = sizeof(struct IpoCurve);
|
||||
} else if ((void *)o==(void *)&Lamp_Type) {
|
||||
ret = sizeof(struct Lamp);
|
||||
} else if ((void *)o==(void *)&Lattice_Type) {
|
||||
ret = sizeof(struct Lattice);
|
||||
} else if ((void *)o==(void *)&MCol_Type) {
|
||||
ret = sizeof(struct MCol);
|
||||
} else if ((void *)o==(void *)&MEdge_Type) {
|
||||
ret = sizeof(struct MEdge);
|
||||
} else if ((void *)o==(void *)&MFace_Type) {
|
||||
ret = sizeof(struct MFace);
|
||||
} else if ((void *)o==(void *)&MTex_Type) {
|
||||
ret = sizeof(struct MTex);
|
||||
} else if ((void *)o==(void *)&MVert_Type) {
|
||||
ret = sizeof(struct MVert);
|
||||
} else if ((void *)o==(void *)&Material_Type) {
|
||||
ret = sizeof(struct Material);
|
||||
} else if ((void *)o==(void *)&Mesh_Type) {
|
||||
ret = sizeof(struct Mesh);
|
||||
} else if ((void *)o==(void *)&Metaball_Type) {
|
||||
ret = sizeof(struct MetaBall);
|
||||
} else if ((void *)o==(void *)&ModSeq_Type) {
|
||||
ret = sizeof(struct ModifierData);
|
||||
} else if ((void *)o==(void *)&Modifier_Type) {
|
||||
ret = sizeof(struct ModifierData);
|
||||
} else if ((void *)o==(void *)&Object_Type) {
|
||||
ret = sizeof(struct Object);
|
||||
} else if ((void *)o==(void *)&Pose_Type) {
|
||||
ret = sizeof(struct bPose);
|
||||
} else if ((void *)o==(void *)&RenderData_Type) {
|
||||
ret = sizeof(struct RenderData);
|
||||
} else if ((void *)o==(void *)&Scene_Type) {
|
||||
ret = sizeof(struct Scene);
|
||||
} else if ((void *)o==(void *)&SurfNurb_Type) {
|
||||
ret = sizeof(struct Nurb);
|
||||
} else if ((void *)o==(void *)&Text3d_Type) {
|
||||
ret = sizeof(struct Curve);
|
||||
} else if ((void *)o==(void *)&Text_Type) {
|
||||
ret = sizeof(struct Text);
|
||||
} else if ((void *)o==(void *)&Texture_Type) {
|
||||
ret = sizeof(struct Tex);
|
||||
} else {
|
||||
ret = -1;
|
||||
}
|
||||
}
|
||||
|
||||
return PyInt_FromLong(ret);
|
||||
}
|
||||
|
||||
struct PyMethodDef M_Types_methods[] = {
|
||||
{"CSizeof", Types_CSizeof, METH_O,
|
||||
"(type) - Returns sizeof of the underlying C structure of the given type"},
|
||||
{NULL, NULL, 0, NULL}
|
||||
};
|
||||
|
||||
|
||||
|
||||
/* The internal types (lowercase first letter, like constant_Type) are only
|
||||
* set when some object initializes them. But unless we do it early, we get
|
||||
* some easy and unpredictable (varies with platform, even distro) ways to
|
||||
* crash Blender. Some modules also need this early up, so let's generalize
|
||||
* and init all our pytypes here.
|
||||
*/
|
||||
|
||||
void types_InitAll( void )
|
||||
{
|
||||
Action_Type.ob_type = &PyType_Type;
|
||||
Pose_Type.ob_type = &PyType_Type;
|
||||
Armature_Type.ob_type = &PyType_Type;
|
||||
BezTriple_Type.ob_type = &PyType_Type;
|
||||
Bone_Type.ob_type = &PyType_Type;
|
||||
Button_Type.ob_type = &PyType_Type;
|
||||
Camera_Type.ob_type = &PyType_Type;
|
||||
CurNurb_Type.ob_type = &PyType_Type;
|
||||
Curve_Type.ob_type = &PyType_Type;
|
||||
Effect_Type.ob_type = &PyType_Type;
|
||||
Image_Type.ob_type = &PyType_Type;
|
||||
Ipo_Type.ob_type = &PyType_Type;
|
||||
IpoCurve_Type.ob_type = &PyType_Type;
|
||||
Lamp_Type.ob_type = &PyType_Type;
|
||||
Lattice_Type.ob_type = &PyType_Type;
|
||||
Material_Type.ob_type = &PyType_Type;
|
||||
Metaball_Type.ob_type = &PyType_Type;
|
||||
MTex_Type.ob_type = &PyType_Type;
|
||||
NMCol_Type.ob_type = &PyType_Type;
|
||||
NMFace_Type.ob_type = &PyType_Type;
|
||||
NMEdge_Type.ob_type = &PyType_Type;
|
||||
NMVert_Type.ob_type = &PyType_Type;
|
||||
NMesh_Type.ob_type = &PyType_Type;
|
||||
MFace_Type.ob_type = &PyType_Type;
|
||||
MVert_Type.ob_type = &PyType_Type;
|
||||
PVert_Type.ob_type = &PyType_Type;
|
||||
MEdge_Type.ob_type = &PyType_Type;
|
||||
MCol_Type.ob_type = &PyType_Type;
|
||||
Mesh_Type.ob_type = &PyType_Type;
|
||||
Object_Type.ob_type = &PyType_Type;
|
||||
Group_Type.ob_type = &PyType_Type;
|
||||
RenderData_Type.ob_type = &PyType_Type;
|
||||
Scene_Type.ob_type = &PyType_Type;
|
||||
SurfNurb_Type.ob_type = &PyType_Type;
|
||||
Text_Type.ob_type = &PyType_Type;
|
||||
Text3d_Type.ob_type = &PyType_Type;
|
||||
Texture_Type.ob_type = &PyType_Type;
|
||||
//TimeLine_Type.ob_type = &PyType_Type;
|
||||
World_Type.ob_type = &PyType_Type;
|
||||
buffer_Type.ob_type = &PyType_Type;
|
||||
constant_Type.ob_type = &PyType_Type;
|
||||
euler_Type.ob_type = &PyType_Type;
|
||||
matrix_Type.ob_type = &PyType_Type;
|
||||
quaternion_Type.ob_type = &PyType_Type;
|
||||
PyType_Ready( &rgbTuple_Type );
|
||||
vector_Type.ob_type = &PyType_Type;
|
||||
property_Type.ob_type = &PyType_Type;
|
||||
point_Type.ob_type = &PyType_Type;
|
||||
PyType_Ready( &Modifier_Type );
|
||||
PyType_Ready( &ModSeq_Type );
|
||||
PyType_Ready( &EditBone_Type );
|
||||
PyType_Ready( &ThemeSpace_Type );
|
||||
PyType_Ready( &ThemeUI_Type );
|
||||
IDProp_Init_Types();
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Function: Types_Init */
|
||||
/*****************************************************************************/
|
||||
PyObject *Types_Init( void )
|
||||
{
|
||||
PyObject *submodule, *dict;
|
||||
|
||||
submodule =
|
||||
Py_InitModule3( "Blender.Types", M_Types_methods, M_Types_doc );
|
||||
|
||||
dict = PyModule_GetDict( submodule );
|
||||
|
||||
/* The Blender Object Type */
|
||||
|
||||
PyDict_SetItemString( dict, "ObjectType",
|
||||
( PyObject * ) &Object_Type );
|
||||
|
||||
/* Blender Object Data Types */
|
||||
|
||||
PyDict_SetItemString( dict, "GroupType",
|
||||
( PyObject * ) &Group_Type );
|
||||
|
||||
PyDict_SetItemString( dict, "SceneType", ( PyObject * ) &Scene_Type );
|
||||
PyDict_SetItemString( dict, "RenderDataType",
|
||||
( PyObject * ) &RenderData_Type );
|
||||
|
||||
PyDict_SetItemString( dict, "NMeshType", ( PyObject * ) &NMesh_Type );
|
||||
PyDict_SetItemString( dict, "NMFaceType",
|
||||
( PyObject * ) &NMFace_Type );
|
||||
PyDict_SetItemString( dict, "NMVertType",
|
||||
( PyObject * ) &NMVert_Type );
|
||||
PyDict_SetItemString( dict, "NMEdgeType",
|
||||
( PyObject * ) &NMEdge_Type );
|
||||
PyDict_SetItemString( dict, "NMColType", ( PyObject * ) &NMCol_Type );
|
||||
|
||||
PyDict_SetItemString( dict, "MeshType", ( PyObject * ) &Mesh_Type );
|
||||
PyDict_SetItemString( dict, "MFaceType",
|
||||
( PyObject * ) &MFace_Type );
|
||||
PyDict_SetItemString( dict, "MEdgeType",
|
||||
( PyObject * ) &MEdge_Type );
|
||||
PyDict_SetItemString( dict, "MVertType",
|
||||
( PyObject * ) &MVert_Type );
|
||||
PyDict_SetItemString( dict, "PVertType",
|
||||
( PyObject * ) &PVert_Type );
|
||||
PyDict_SetItemString( dict, "MColType", ( PyObject * ) &MCol_Type );
|
||||
|
||||
PyDict_SetItemString( dict, "ArmatureType",
|
||||
( PyObject * ) &Armature_Type );
|
||||
PyDict_SetItemString( dict, "BoneType", ( PyObject * ) &Bone_Type );
|
||||
|
||||
PyDict_SetItemString( dict, "CurNurbType",
|
||||
( PyObject * ) &CurNurb_Type );
|
||||
PyDict_SetItemString( dict, "SurfNurbType",
|
||||
( PyObject * ) &SurfNurb_Type );
|
||||
PyDict_SetItemString( dict, "CurveType", ( PyObject * ) &Curve_Type );
|
||||
|
||||
PyDict_SetItemString( dict, "IpoType", ( PyObject * ) &Ipo_Type );
|
||||
PyDict_SetItemString( dict, "IpoCurveType", ( PyObject * ) &IpoCurve_Type );
|
||||
PyDict_SetItemString( dict, "MetaballType",
|
||||
( PyObject * ) &Metaball_Type );
|
||||
|
||||
PyDict_SetItemString( dict, "CameraType",
|
||||
( PyObject * ) &Camera_Type );
|
||||
PyDict_SetItemString( dict, "ImageType", ( PyObject * ) &Image_Type );
|
||||
PyDict_SetItemString( dict, "LampType", ( PyObject * ) &Lamp_Type );
|
||||
PyDict_SetItemString( dict, "TextType", ( PyObject * ) &Text_Type );
|
||||
PyDict_SetItemString( dict, "Text3dType", ( PyObject * ) &Text3d_Type );
|
||||
PyDict_SetItemString( dict, "MaterialType",
|
||||
( PyObject * ) &Material_Type );
|
||||
|
||||
PyDict_SetItemString( dict, "ButtonType",
|
||||
( PyObject * ) &Button_Type );
|
||||
|
||||
PyDict_SetItemString( dict, "LatticeType",
|
||||
( PyObject * ) &Lattice_Type );
|
||||
|
||||
PyDict_SetItemString( dict, "TextureType",
|
||||
( PyObject * ) &Texture_Type );
|
||||
PyDict_SetItemString( dict, "MTexType", ( PyObject * ) &MTex_Type );
|
||||
|
||||
/* External helper Types available to the main ones above */
|
||||
|
||||
PyDict_SetItemString( dict, "vectorType",
|
||||
( PyObject * ) &vector_Type );
|
||||
PyDict_SetItemString( dict, "bufferType",
|
||||
( PyObject * ) &buffer_Type );
|
||||
PyDict_SetItemString( dict, "constantType",
|
||||
( PyObject * ) &constant_Type );
|
||||
PyDict_SetItemString( dict, "rgbTupleType",
|
||||
( PyObject * ) &rgbTuple_Type );
|
||||
PyDict_SetItemString( dict, "matrixType",
|
||||
( PyObject * ) &matrix_Type );
|
||||
PyDict_SetItemString( dict, "eulerType", ( PyObject * ) &euler_Type );
|
||||
PyDict_SetItemString( dict, "quaternionType",
|
||||
( PyObject * ) &quaternion_Type );
|
||||
PyDict_SetItemString( dict, "BezTripleType",
|
||||
( PyObject * ) &BezTriple_Type );
|
||||
PyDict_SetItemString( dict, "ActionType",
|
||||
( PyObject * ) &Action_Type );
|
||||
PyDict_SetItemString( dict, "PoseType",
|
||||
( PyObject * ) &Pose_Type );
|
||||
PyDict_SetItemString( dict, "propertyType",
|
||||
( PyObject * ) &property_Type );
|
||||
PyDict_SetItemString( dict, "pointType",
|
||||
( PyObject * ) &point_Type );
|
||||
PyDict_SetItemString( dict, "ModifierType",
|
||||
( PyObject * ) &Modifier_Type );
|
||||
PyDict_SetItemString( dict, "ModSeqType",
|
||||
( PyObject * ) &ModSeq_Type );
|
||||
PyDict_SetItemString( dict, "EditBoneType",
|
||||
( PyObject * ) &EditBone_Type);
|
||||
PyDict_SetItemString( dict, "ThemeSpaceType",
|
||||
( PyObject * ) &ThemeSpace_Type);
|
||||
PyDict_SetItemString( dict, "ThemeUIType",
|
||||
( PyObject * ) &ThemeUI_Type);
|
||||
PyDict_SetItemString( dict, "IDGroupType",
|
||||
( PyObject * ) &IDGroup_Type);
|
||||
PyDict_SetItemString( dict, "IDArrayType",
|
||||
( PyObject * ) &IDArray_Type);
|
||||
return submodule;
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -1,55 +0,0 @@
|
||||
/*
|
||||
* $Id$
|
||||
*
|
||||
* ***** 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*
|
||||
* The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This is a new part of Blender.
|
||||
*
|
||||
* Contributor(s): Jacques Guignot
|
||||
*
|
||||
* ***** END GPL LICENSE BLOCK *****
|
||||
*/
|
||||
|
||||
#ifndef EXPP_WORLD_H
|
||||
#define EXPP_WORLD_H
|
||||
|
||||
#include <Python.h>
|
||||
#include "DNA_world_types.h"
|
||||
|
||||
#define BPy_World_Check(v) ((v)->ob_type==&World_Type)
|
||||
|
||||
/* Python BPy_World structure definition */
|
||||
typedef struct {
|
||||
PyObject_HEAD /* required py macro */
|
||||
World * world; /* Libdata must be second */
|
||||
} BPy_World;
|
||||
|
||||
extern PyTypeObject World_Type;
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Python World_Type helper functions needed by Blender (the Init function) */
|
||||
/* and Object modules. */
|
||||
/*****************************************************************************/
|
||||
|
||||
PyObject *World_Init( void );
|
||||
PyObject *World_CreatePyObject( World * world );
|
||||
World *World_FromPyObject( PyObject * pyobj );
|
||||
|
||||
#endif /* EXPP_WORLD_H */
|
||||
@@ -1,83 +0,0 @@
|
||||
/*
|
||||
* $Id$
|
||||
* ***** 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*
|
||||
* The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This is a new part of Blender.
|
||||
*
|
||||
* Contributor(s): Michel Selten, Willian P. Germano, Joseph Gilbert,
|
||||
* Campbell Barton
|
||||
*
|
||||
* ***** END GPL LICENSE BLOCK *****
|
||||
*/
|
||||
|
||||
/* for open, close in Blender_Load */
|
||||
|
||||
#include "BLI_blenlib.h"
|
||||
#include "BKE_global.h"
|
||||
#include "BKE_utildefines.h"
|
||||
#include "BKE_scene.h"
|
||||
#include "BKE_main.h"
|
||||
|
||||
#include "DNA_scene_types.h"
|
||||
|
||||
#include "Types.h"
|
||||
#include "Library.h"
|
||||
|
||||
#include "bpy.h"
|
||||
#include "bpy_data.h"
|
||||
#include "bpy_config.h"
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Global variables */
|
||||
/*****************************************************************************/
|
||||
PyObject *g_bpydict;
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Function: initBlender */
|
||||
/*****************************************************************************/
|
||||
|
||||
void m_bpy_init(void)
|
||||
{
|
||||
PyObject *module;
|
||||
PyObject *dict;
|
||||
|
||||
/* G.scene should only aver be NULL if blender is executed in
|
||||
background mode, not loading a blend file and executing a python script eg.
|
||||
blender -P somescript.py -b
|
||||
The if below solves the segfaults that happen when python runs and
|
||||
G.scene is NULL */
|
||||
if(G.background && G.main->scene.first==NULL) {
|
||||
Scene *sce= add_scene("1");
|
||||
/*set_scene(sce);*/ /* causes a crash */
|
||||
G.scene= sce;
|
||||
}
|
||||
|
||||
module = Py_InitModule3("bpy", NULL, "The main bpy module");
|
||||
|
||||
types_InitAll(); /* set all our pytypes to &PyType_Type */
|
||||
|
||||
dict = PyModule_GetDict(module);
|
||||
g_bpydict = dict;
|
||||
|
||||
PyModule_AddObject( module, "config", Config_CreatePyObject() );
|
||||
PyDict_SetItemString( dict, "data", Data_Init());
|
||||
PyDict_SetItemString( dict, "libraries", Library_Init( ) );
|
||||
|
||||
}
|
||||
@@ -1,38 +0,0 @@
|
||||
/*
|
||||
* $Id$
|
||||
*
|
||||
* ***** 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*
|
||||
* The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This is a new part of Blender.
|
||||
*
|
||||
* Contributor(s): Michel Selten, Willian P. Germano
|
||||
*
|
||||
* ***** END GPL LICENSE BLOCK *****
|
||||
*/
|
||||
|
||||
#ifndef EXPP_BPYMOD_H
|
||||
#define EXPP_BPYMOD_H
|
||||
|
||||
#include <Python.h>
|
||||
|
||||
extern PyObject *g_bpydict;
|
||||
void m_bpy_init( void );
|
||||
|
||||
#endif /* EXPP_BPYMOD_H */
|
||||
@@ -1,412 +0,0 @@
|
||||
/*
|
||||
* $Id$
|
||||
*
|
||||
* ***** 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*
|
||||
* The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This is a new part of Blender.
|
||||
*
|
||||
* Contributor(s): Campbell Barton
|
||||
*
|
||||
* ***** END GPL LICENSE BLOCK *****
|
||||
*/
|
||||
|
||||
/* python types */
|
||||
#include "DNA_userdef_types.h"
|
||||
#include "../api2_2x/gen_utils.h"
|
||||
#include "bpy_config.h"
|
||||
#include "BKE_utildefines.h"
|
||||
|
||||
enum conf_consts {
|
||||
/*string*/
|
||||
EXPP_CONF_ATTR_PATH_YF_EXPORT = 0,
|
||||
EXPP_CONF_ATTR_PATH_FONT,
|
||||
EXPP_CONF_ATTR_PATH_RENDER,
|
||||
EXPP_CONF_ATTR_PATH_TEXTURE,
|
||||
EXPP_CONF_ATTR_PATH_PYTHON,
|
||||
EXPP_CONF_ATTR_PATH_TEX_PLUGIN,
|
||||
EXPP_CONF_ATTR_PATH_SOUND,
|
||||
EXPP_CONF_ATTR_PATH_SEQ_PLUGIN,
|
||||
EXPP_CONF_ATTR_PATH_TEMP,
|
||||
|
||||
/*int*/
|
||||
EXPP_CONF_ATTR_UNDOSTEPS,
|
||||
EXPP_CONF_ATTR_TEX_TIMEOUT,
|
||||
EXPP_CONF_ATTR_TEX_COLLECT_RATE,
|
||||
EXPP_CONF_ATTR_MEM_CACHE_LIMIT,
|
||||
EXPP_CONF_ATTR_FONT_SIZE
|
||||
};
|
||||
|
||||
PyObject *Config_CreatePyObject( )
|
||||
{
|
||||
BPy_Config *conf = PyObject_NEW( BPy_Config, &Config_Type);
|
||||
return (PyObject *)conf;
|
||||
}
|
||||
|
||||
/*
|
||||
* repr function
|
||||
* callback functions building meaninful string to representations
|
||||
*/
|
||||
static PyObject *Config_repr( BPy_Config * self )
|
||||
{
|
||||
return PyString_FromFormat( "[Blender Configuration Data]");
|
||||
}
|
||||
|
||||
|
||||
/*-----------------------Config module Init())-----------------------------*/
|
||||
/* see Main.c */
|
||||
/*
|
||||
static struct PyMethodDef BPy_Config_methods[] = {
|
||||
{"new", (PyCFunction)MainSeq_new, METH_VARARGS,
|
||||
"(name) - Create a new object in this scene from the obdata given and return a new object"},
|
||||
{"load", (PyCFunction)MainSeq_load, METH_VARARGS,
|
||||
"(filename) - loads the given filename for image, font and sound types"},
|
||||
{"unlink", (PyCFunction)MainSeq_unlink, METH_VARARGS,
|
||||
"unlinks the object from the scene"},
|
||||
{NULL, NULL, 0, NULL}
|
||||
};*/
|
||||
|
||||
/*
|
||||
* get integer attributes
|
||||
*/
|
||||
static PyObject *getStrAttr( BPy_Config *self, void *type )
|
||||
{
|
||||
char *param = NULL;
|
||||
|
||||
switch( GET_INT_FROM_POINTER(type) ) {
|
||||
case EXPP_CONF_ATTR_PATH_YF_EXPORT:
|
||||
param = U.yfexportdir;
|
||||
break;
|
||||
case EXPP_CONF_ATTR_PATH_FONT:
|
||||
param = U.fontdir;
|
||||
break;
|
||||
case EXPP_CONF_ATTR_PATH_RENDER:
|
||||
param = U.renderdir;
|
||||
break;
|
||||
case EXPP_CONF_ATTR_PATH_TEXTURE:
|
||||
param = U.textudir;
|
||||
break;
|
||||
case EXPP_CONF_ATTR_PATH_PYTHON:
|
||||
param = U.pythondir;
|
||||
break;
|
||||
case EXPP_CONF_ATTR_PATH_TEX_PLUGIN:
|
||||
param = U.plugtexdir;
|
||||
break;
|
||||
case EXPP_CONF_ATTR_PATH_SOUND:
|
||||
param = U.sounddir;
|
||||
break;
|
||||
case EXPP_CONF_ATTR_PATH_SEQ_PLUGIN:
|
||||
param = U.plugseqdir;
|
||||
break;
|
||||
case EXPP_CONF_ATTR_PATH_TEMP:
|
||||
param = U.tempdir;
|
||||
break;
|
||||
|
||||
default:
|
||||
return EXPP_ReturnPyObjError( PyExc_RuntimeError,
|
||||
"undefined type in getStrAttr" );
|
||||
}
|
||||
|
||||
return PyString_FromString( param );
|
||||
}
|
||||
|
||||
/*
|
||||
* set integer attributes which require clamping
|
||||
*/
|
||||
|
||||
static int setStrAttr( BPy_Config *self, PyObject *value, void *type )
|
||||
{
|
||||
char *param;
|
||||
int len=160;
|
||||
char *str = PyString_AsString(value);
|
||||
|
||||
if (!str)
|
||||
return EXPP_ReturnIntError( PyExc_TypeError,
|
||||
"error, must assign a python string for setStrAttr");
|
||||
|
||||
switch( GET_INT_FROM_POINTER(type) ) {
|
||||
case EXPP_CONF_ATTR_PATH_YF_EXPORT:
|
||||
param = U.yfexportdir;
|
||||
break;
|
||||
case EXPP_CONF_ATTR_PATH_FONT:
|
||||
param = U.fontdir;
|
||||
break;
|
||||
case EXPP_CONF_ATTR_PATH_RENDER:
|
||||
param = U.renderdir;
|
||||
break;
|
||||
case EXPP_CONF_ATTR_PATH_TEXTURE:
|
||||
param = U.textudir;
|
||||
break;
|
||||
case EXPP_CONF_ATTR_PATH_PYTHON:
|
||||
param = U.pythondir;
|
||||
break;
|
||||
case EXPP_CONF_ATTR_PATH_TEX_PLUGIN:
|
||||
param = U.plugtexdir;
|
||||
break;
|
||||
case EXPP_CONF_ATTR_PATH_SOUND:
|
||||
param = U.sounddir;
|
||||
break;
|
||||
case EXPP_CONF_ATTR_PATH_SEQ_PLUGIN:
|
||||
param = U.plugseqdir;
|
||||
break;
|
||||
case EXPP_CONF_ATTR_PATH_TEMP:
|
||||
param = U.tempdir;
|
||||
break;
|
||||
|
||||
default:
|
||||
return EXPP_ReturnIntError( PyExc_RuntimeError,
|
||||
"undefined type in setStrAttr");
|
||||
}
|
||||
|
||||
strncpy(param, str, len);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* get integer attributes
|
||||
*/
|
||||
|
||||
static PyObject *getIntAttr( BPy_Config *self, void *type )
|
||||
{
|
||||
int param;
|
||||
|
||||
switch( GET_INT_FROM_POINTER(type) ) {
|
||||
case EXPP_CONF_ATTR_UNDOSTEPS:
|
||||
param = (int)U.undosteps;
|
||||
break;
|
||||
case EXPP_CONF_ATTR_TEX_TIMEOUT:
|
||||
param = U.textimeout;
|
||||
break;
|
||||
case EXPP_CONF_ATTR_TEX_COLLECT_RATE:
|
||||
param = U.texcollectrate;
|
||||
break;
|
||||
case EXPP_CONF_ATTR_MEM_CACHE_LIMIT:
|
||||
param = U.memcachelimit;
|
||||
break;
|
||||
case EXPP_CONF_ATTR_FONT_SIZE:
|
||||
param = U.fontsize;
|
||||
break;
|
||||
|
||||
default:
|
||||
return EXPP_ReturnPyObjError( PyExc_RuntimeError,
|
||||
"undefined type in getIntAttr" );
|
||||
}
|
||||
|
||||
return PyInt_FromLong( param );
|
||||
}
|
||||
|
||||
/*
|
||||
* set integer attributes which require clamping
|
||||
*/
|
||||
|
||||
static int setIntAttrClamp( BPy_Config *self, PyObject *value, void *type )
|
||||
{
|
||||
void *param;
|
||||
int min, max, size;
|
||||
|
||||
switch( GET_INT_FROM_POINTER(type) ) {
|
||||
case EXPP_CONF_ATTR_UNDOSTEPS:
|
||||
min = 0;
|
||||
max = 64;
|
||||
size = 'h';
|
||||
param = (void *)&U.undosteps;
|
||||
break;
|
||||
case EXPP_CONF_ATTR_TEX_TIMEOUT:
|
||||
min = 1;
|
||||
max = 3600;
|
||||
size = 'i';
|
||||
param = (void *)&U.textimeout;
|
||||
break;
|
||||
case EXPP_CONF_ATTR_TEX_COLLECT_RATE:
|
||||
min = 1;
|
||||
max = 3600;
|
||||
size = 'i';
|
||||
param = (void *)&U.texcollectrate;
|
||||
break;
|
||||
case EXPP_CONF_ATTR_MEM_CACHE_LIMIT:
|
||||
min = 1;
|
||||
max = 1024;
|
||||
size = 'i';
|
||||
param = (void *)&U.memcachelimit;
|
||||
break;
|
||||
case EXPP_CONF_ATTR_FONT_SIZE:
|
||||
min = 8;
|
||||
max = 16;
|
||||
size = 'i';
|
||||
param = (void *)&U.fontsize;
|
||||
break;
|
||||
|
||||
default:
|
||||
return EXPP_ReturnIntError( PyExc_RuntimeError,
|
||||
"undefined type in setIntAttrClamp");
|
||||
}
|
||||
return EXPP_setIValueClamped( value, param, min, max, size );
|
||||
}
|
||||
|
||||
static PyGetSetDef Config_getseters[] = {
|
||||
|
||||
/* ints & shorts */
|
||||
{"undoSteps",
|
||||
(getter)getIntAttr, (setter)setIntAttrClamp,
|
||||
"undo steps",
|
||||
(void *)EXPP_CONF_ATTR_UNDOSTEPS},
|
||||
{"textureTimeout",
|
||||
(getter)getIntAttr, (setter)setIntAttrClamp,
|
||||
"time for textures to stay in openGL memory",
|
||||
(void *)EXPP_CONF_ATTR_TEX_TIMEOUT},
|
||||
{"textureCollectRate",
|
||||
(getter)getIntAttr, (setter)setIntAttrClamp,
|
||||
"intervel for textures to be tagged as used",
|
||||
(void *)EXPP_CONF_ATTR_TEX_COLLECT_RATE},
|
||||
{"sequenceMemCacheLimit",
|
||||
(getter)getIntAttr, (setter)setIntAttrClamp,
|
||||
"maximum memory for the sequencer to use as cache",
|
||||
(void *)EXPP_CONF_ATTR_MEM_CACHE_LIMIT},
|
||||
{"fontSize",
|
||||
(getter)getIntAttr, (setter)setIntAttrClamp,
|
||||
"user interface font size",
|
||||
(void *)EXPP_CONF_ATTR_FONT_SIZE},
|
||||
|
||||
/* Paths */
|
||||
{"yfExportDir",
|
||||
(getter)getStrAttr, (setter)setStrAttr,
|
||||
"yafray export path",
|
||||
(void *)EXPP_CONF_ATTR_PATH_YF_EXPORT},
|
||||
{"fontDir",
|
||||
(getter)getStrAttr, (setter)setStrAttr,
|
||||
"default font path",
|
||||
(void *)EXPP_CONF_ATTR_PATH_FONT},
|
||||
{"renderDir",
|
||||
(getter)getStrAttr, (setter)setStrAttr,
|
||||
"default render path",
|
||||
(void *)EXPP_CONF_ATTR_PATH_RENDER},
|
||||
{"textureDir",
|
||||
(getter)getStrAttr, (setter)setStrAttr,
|
||||
"default texture path",
|
||||
(void *)EXPP_CONF_ATTR_PATH_TEXTURE},
|
||||
{"userScriptsDir",
|
||||
(getter)getStrAttr, (setter)setStrAttr,
|
||||
"user scripts path",
|
||||
(void *)EXPP_CONF_ATTR_PATH_PYTHON},
|
||||
{"texturePluginsDir",
|
||||
(getter)getStrAttr, (setter)setStrAttr,
|
||||
"default texture plugins path",
|
||||
(void *)EXPP_CONF_ATTR_PATH_TEX_PLUGIN},
|
||||
{"soundDir",
|
||||
(getter)getStrAttr, (setter)setStrAttr,
|
||||
"default sound path",
|
||||
(void *)EXPP_CONF_ATTR_PATH_SOUND},
|
||||
{"sequencePluginsDir",
|
||||
(getter)getStrAttr, (setter)setStrAttr,
|
||||
"sequencer plugins path",
|
||||
(void *)EXPP_CONF_ATTR_PATH_SEQ_PLUGIN},
|
||||
{"tempDir",
|
||||
(getter)getStrAttr, (setter)setStrAttr,
|
||||
"temporary file path",
|
||||
(void *)EXPP_CONF_ATTR_PATH_TEMP},
|
||||
|
||||
{NULL,NULL,NULL,NULL,NULL} /* Sentinel */
|
||||
};
|
||||
|
||||
|
||||
/*
|
||||
* Python Config_Type structure definition
|
||||
*/
|
||||
PyTypeObject Config_Type = {
|
||||
PyObject_HEAD_INIT( NULL ) /* required py macro */
|
||||
0, /* ob_size */
|
||||
/* For printing, in format "<module>.<name>" */
|
||||
"Blender Config", /* char *tp_name; */
|
||||
sizeof( BPy_Config ), /* int tp_basicsize; */
|
||||
0, /* tp_itemsize; For allocation */
|
||||
|
||||
/* Methods to implement standard operations */
|
||||
|
||||
NULL, /* destructor tp_dealloc; */
|
||||
NULL, /* printfunc tp_print; */
|
||||
NULL, /* getattrfunc tp_getattr; */
|
||||
NULL, /* setattrfunc tp_setattr; */
|
||||
NULL, /* cmpfunc tp_compare; */
|
||||
(reprfunc)Config_repr, /* reprfunc tp_repr; */
|
||||
|
||||
/* Method suites for standard classes */
|
||||
|
||||
NULL, /* PyNumberMethods *tp_as_number; */
|
||||
NULL, /* PySequenceMethods *tp_as_sequence; */
|
||||
NULL, /* PyMappingMethods *tp_as_mapping; */
|
||||
|
||||
/* More standard operations (here for binary compatibility) */
|
||||
|
||||
NULL, /* hashfunc tp_hash; */
|
||||
NULL, /* ternaryfunc tp_call; */
|
||||
NULL, /* reprfunc tp_str; */
|
||||
NULL, /* getattrofunc tp_getattro; */
|
||||
NULL, /* setattrofunc tp_setattro; */
|
||||
|
||||
/* Functions to access object as input/output buffer */
|
||||
NULL, /* PyBufferProcs *tp_as_buffer; */
|
||||
|
||||
/*** Flags to define presence of optional/expanded features ***/
|
||||
Py_TPFLAGS_DEFAULT, /* long tp_flags; */
|
||||
|
||||
NULL, /* char *tp_doc; Documentation string */
|
||||
/*** Assigned meaning in release 2.0 ***/
|
||||
/* call function for all accessible objects */
|
||||
NULL, /* traverseproc tp_traverse; */
|
||||
|
||||
/* delete references to contained objects */
|
||||
NULL, /* inquiry tp_clear; */
|
||||
|
||||
/*** Assigned meaning in release 2.1 ***/
|
||||
/*** rich comparisons ***/
|
||||
NULL, /* richcmpfunc tp_richcompare; */
|
||||
|
||||
/*** weak reference enabler ***/
|
||||
0, /* long tp_weaklistoffset; */
|
||||
|
||||
/*** Added in release 2.2 ***/
|
||||
/* Iterators */
|
||||
NULL, /* getiterfunc tp_iter; */
|
||||
NULL, /* iternextfunc tp_iternext; */
|
||||
|
||||
/*** Attribute descriptor and subclassing stuff ***/
|
||||
NULL, /*BPy_Config_methods*/ /* struct PyMethodDef *tp_methods; */
|
||||
NULL, /* struct PyMemberDef *tp_members; */
|
||||
Config_getseters, /* struct PyGetSetDef *tp_getset; */
|
||||
NULL, /* struct _typeobject *tp_base; */
|
||||
NULL, /* PyObject *tp_dict; */
|
||||
NULL, /* descrgetfunc tp_descr_get; */
|
||||
NULL, /* descrsetfunc tp_descr_set; */
|
||||
0, /* long tp_dictoffset; */
|
||||
NULL, /* initproc tp_init; */
|
||||
NULL, /* allocfunc tp_alloc; */
|
||||
NULL, /* newfunc tp_new; */
|
||||
/* Low-level free-memory routine */
|
||||
NULL, /* freefunc tp_free; */
|
||||
/* For PyObject_IS_GC */
|
||||
NULL, /* inquiry tp_is_gc; */
|
||||
NULL, /* PyObject *tp_bases; */
|
||||
/* method resolution order */
|
||||
NULL, /* PyObject *tp_mro; */
|
||||
NULL, /* PyObject *tp_cache; */
|
||||
NULL, /* PyObject *tp_subclasses; */
|
||||
NULL, /* PyObject *tp_weaklist; */
|
||||
NULL
|
||||
};
|
||||
@@ -1,49 +0,0 @@
|
||||
/*
|
||||
* $Id$
|
||||
*
|
||||
* ***** 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*
|
||||
* The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This is a new part of Blender.
|
||||
*
|
||||
* Contributor(s): Campbell Barton
|
||||
*
|
||||
* ***** END GPL LICENSE BLOCK *****
|
||||
*/
|
||||
|
||||
#ifndef EXPP_BPY_CONFIG_H
|
||||
#define EXPP_BPY_CONFIG_H
|
||||
|
||||
#include <Python.h>
|
||||
|
||||
/* The Main PyType Object defined in Main.c */
|
||||
extern PyTypeObject Config_Type;
|
||||
|
||||
#define BPy_Config_Check(v) \
|
||||
((v)->ob_type == &Config_Type)
|
||||
|
||||
/* Main sequence, iterate on the libdatas listbase*/
|
||||
typedef struct {
|
||||
PyObject_VAR_HEAD /* required python macro */
|
||||
} BPy_Config;
|
||||
|
||||
PyObject *Config_CreatePyObject();
|
||||
|
||||
|
||||
#endif /* EXPP_BPY_CONFIG_H */
|
||||
@@ -1,820 +0,0 @@
|
||||
/*
|
||||
* $Id$
|
||||
*
|
||||
* ***** 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*
|
||||
* The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This is a new part of Blender.
|
||||
*
|
||||
* Contributor(s): Campbell Barton
|
||||
*
|
||||
* ***** END GPL LICENSE BLOCK *****
|
||||
*/
|
||||
|
||||
#include "bpy_data.h"
|
||||
|
||||
#include "MEM_guardedalloc.h" /* for MEM_callocN */
|
||||
#include "DNA_space_types.h" /* SPACE_VIEW3D, SPACE_SEQ */
|
||||
#include "DNA_scene_types.h"
|
||||
#include "DNA_object_types.h" /* LibBlockSeq_new */
|
||||
#include "DNA_texture_types.h"
|
||||
#include "DNA_curve_types.h"
|
||||
#include "DNA_ipo_types.h"
|
||||
#include "DNA_group_types.h"
|
||||
#include "DNA_world_types.h"
|
||||
#include "DNA_vfont_types.h"
|
||||
#include "DNA_armature_types.h"
|
||||
#include "DNA_sound_types.h"
|
||||
#include "DNA_text_types.h"
|
||||
#include "DNA_action_types.h"
|
||||
#include "DNA_meta_types.h"
|
||||
|
||||
/* Use the add_* from BKE_* */
|
||||
#include "BKE_global.h"
|
||||
#include "BKE_utildefines.h" /* clamp */
|
||||
#include "BKE_armature.h"
|
||||
#include "BKE_ipo.h"
|
||||
#include "BKE_image.h"
|
||||
#include "BKE_main.h"
|
||||
#include "BKE_library.h"
|
||||
#include "BKE_lattice.h"
|
||||
#include "BKE_object.h"
|
||||
#include "BKE_scene.h"
|
||||
#include "BKE_sca.h" /*free_text_controllers*/
|
||||
#include "BKE_font.h"
|
||||
#include "BKE_mball.h"
|
||||
#include "BKE_mesh.h"
|
||||
#include "BKE_curve.h"
|
||||
#include "BKE_material.h"
|
||||
#include "BKE_group.h"
|
||||
#include "BKE_text.h"
|
||||
#include "BKE_texture.h"
|
||||
#include "BKE_world.h"
|
||||
|
||||
#include "BLI_blenlib.h" /* BLI_countlist */
|
||||
#include "BIF_drawscene.h" /* for set_scene */
|
||||
#include "BIF_screen.h" /* curarea */
|
||||
#include "BIF_drawimage.h" /* what image */
|
||||
#include "BIF_drawtext.h" /* unlink_text */
|
||||
#include "BIF_editsound.h" /* sound_new_sound */
|
||||
#include "BIF_editaction.h" /* add_empty_action */
|
||||
|
||||
/* python types */
|
||||
#include "../BPY_extern.h" /* clearing scriptlinks */
|
||||
|
||||
#include "gen_utils.h"
|
||||
#include "gen_library.h" /* generic ID functions */
|
||||
|
||||
#include "Object.h"
|
||||
#include "Camera.h"
|
||||
#include "Armature.h"
|
||||
#include "Lamp.h"
|
||||
#include "Curve.h"
|
||||
#include "NMesh.h"
|
||||
#include "Mesh.h"
|
||||
#include "Lattice.h"
|
||||
#include "Metaball.h"
|
||||
#include "Text.h"
|
||||
#include "Text3d.h"
|
||||
#include "Font.h"
|
||||
#include "Group.h"
|
||||
#include "World.h"
|
||||
#include "Texture.h"
|
||||
#include "Ipo.h"
|
||||
#include "Text.h"
|
||||
#include "Sound.h"
|
||||
#include "NLA.h"
|
||||
#include "Scene.h"
|
||||
#include "Library.h"
|
||||
|
||||
#include "bpy_config.h" /* config pydata */
|
||||
|
||||
/* used only for texts.active */
|
||||
#include "BIF_screen.h"
|
||||
#include "DNA_space_types.h"
|
||||
#include "DNA_screen_types.h"
|
||||
|
||||
extern VFont *get_builtin_font(void);
|
||||
|
||||
static PyObject *LibBlockSeq_CreatePyObject( Link *iter, int type )
|
||||
{
|
||||
BPy_LibBlockSeq *seq = PyObject_NEW( BPy_LibBlockSeq, &LibBlockSeq_Type);
|
||||
seq->iter = iter;
|
||||
seq->type = type;
|
||||
return (PyObject *)seq;
|
||||
}
|
||||
|
||||
|
||||
static int LibBlockSeq_len( BPy_LibBlockSeq * self )
|
||||
{
|
||||
ListBase *lb = wich_libbase(G.main, self->type);
|
||||
return BLI_countlist( lb );
|
||||
}
|
||||
|
||||
static PyObject * LibBlockSeq_subscript(BPy_LibBlockSeq * self, PyObject *key)
|
||||
{
|
||||
char *name;
|
||||
char *lib= NULL;
|
||||
char use_lib = 0;
|
||||
ID *id;
|
||||
|
||||
id = (ID *)wich_libbase(G.main, self->type)->first;
|
||||
|
||||
if ( PyString_Check(key) ) {
|
||||
name = PyString_AsString ( key );
|
||||
} else if (PyTuple_Check(key) && (PyTuple_Size(key) == 2) ) {
|
||||
PyObject *pydata;
|
||||
use_lib = 1;
|
||||
|
||||
/* Get the first arg */
|
||||
pydata = PyTuple_GET_ITEM(key, 0);
|
||||
if (!PyString_Check(pydata)) {
|
||||
return EXPP_ReturnPyObjError( PyExc_TypeError,
|
||||
"the data name must be a string" );
|
||||
}
|
||||
|
||||
name = PyString_AsString ( pydata );
|
||||
|
||||
/* Get the second arg */
|
||||
pydata = PyTuple_GET_ITEM(key, 1);
|
||||
if (pydata == Py_None) {
|
||||
lib = NULL; /* data must be local */
|
||||
} else if (PyString_Check(pydata)) {
|
||||
lib = PyString_AsString ( pydata );
|
||||
if (!strcmp( "", lib)) {
|
||||
lib = NULL; /* and empty string also means data must be local */
|
||||
}
|
||||
} else {
|
||||
return EXPP_ReturnPyObjError( PyExc_TypeError,
|
||||
"the lib name must be a string or None" );
|
||||
}
|
||||
} else {
|
||||
return EXPP_ReturnPyObjError( PyExc_TypeError,
|
||||
"expected the a name string or a tuple (lib, name)" );
|
||||
}
|
||||
|
||||
for (; id; id = id->next) {
|
||||
if(!strcmp( name, id->name+2 )) {
|
||||
if (
|
||||
(!use_lib) || /* any data, local or external lib data */
|
||||
(use_lib && !lib && !id->lib) || /* only local */
|
||||
(lib && use_lib && id->lib && (!strcmp( id->lib->name, lib))) /* only external lib */
|
||||
)
|
||||
{
|
||||
return GetPyObjectFromID(id);
|
||||
}
|
||||
}
|
||||
}
|
||||
return ( EXPP_ReturnPyObjError
|
||||
( PyExc_KeyError, "Requested data does not exist") );
|
||||
}
|
||||
|
||||
static PyMappingMethods LibBlockSeq_as_mapping = {
|
||||
( inquiry ) LibBlockSeq_len, /* mp_length */
|
||||
( binaryfunc ) LibBlockSeq_subscript, /* mp_subscript */
|
||||
( objobjargproc ) 0, /* mp_ass_subscript */
|
||||
};
|
||||
|
||||
|
||||
/************************************************************************
|
||||
*
|
||||
* Python LibBlockSeq_Type iterator (iterates over GroupObjects)
|
||||
*
|
||||
************************************************************************/
|
||||
|
||||
/*
|
||||
* Initialize the interator index
|
||||
*/
|
||||
|
||||
static PyObject *LibBlockSeq_getIter( BPy_LibBlockSeq * self )
|
||||
{
|
||||
/* we need to get the first base, but for selected context we may need to advance
|
||||
to the first selected or first conext base */
|
||||
|
||||
ListBase *lb;
|
||||
Link *link;
|
||||
lb = wich_libbase(G.main, self->type);
|
||||
|
||||
link = lb->first;
|
||||
|
||||
/* create a new iterator if were alredy using this one */
|
||||
if (self->iter==NULL) {
|
||||
self->iter = link;
|
||||
return EXPP_incr_ret ( (PyObject *) self );
|
||||
} else {
|
||||
return LibBlockSeq_CreatePyObject(link, self->type);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Return next LibBlockSeq iter.
|
||||
*/
|
||||
|
||||
static PyObject *LibBlockSeq_nextIter( BPy_LibBlockSeq * self )
|
||||
{
|
||||
PyObject *object;
|
||||
Link *link;
|
||||
if( !(self->iter) ) {
|
||||
self->iter= NULL;
|
||||
return EXPP_ReturnPyObjError( PyExc_StopIteration,
|
||||
"iterator at end" );
|
||||
}
|
||||
|
||||
object = GetPyObjectFromID((ID *)self->iter);
|
||||
|
||||
link= self->iter->next;
|
||||
self->iter= link;
|
||||
return object;
|
||||
}
|
||||
|
||||
static PyObject *LibBlockSeq_getActive(BPy_LibBlockSeq *self)
|
||||
{
|
||||
switch (self->type) {
|
||||
case ID_SCE:
|
||||
if ( !G.scene ) {
|
||||
Py_RETURN_NONE;
|
||||
} else {
|
||||
return Scene_CreatePyObject( ( Scene * ) G.scene );
|
||||
}
|
||||
|
||||
break;
|
||||
case ID_IM:
|
||||
if (!G.sima || !G.sima->image) {
|
||||
Py_RETURN_NONE;
|
||||
} else {
|
||||
what_image( G.sima ); /* make sure image data exists */
|
||||
return Image_CreatePyObject( G.sima->image );
|
||||
}
|
||||
break;
|
||||
case ID_TXT: {
|
||||
SpaceText *st = NULL;
|
||||
|
||||
if (curarea)
|
||||
st = curarea->spacedata.first;
|
||||
|
||||
if (st==NULL || st->spacetype!=SPACE_TEXT || st->text==NULL) {
|
||||
Py_RETURN_NONE;
|
||||
} else {
|
||||
return Text_CreatePyObject( st->text );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return EXPP_ReturnPyObjError( PyExc_TypeError,
|
||||
"Only Scene and Image types have the active attribute" );
|
||||
}
|
||||
|
||||
static int LibBlockSeq_setActive(BPy_LibBlockSeq *self, PyObject *value)
|
||||
{
|
||||
switch (self->type) {
|
||||
case ID_SCE:
|
||||
if (!BPy_Scene_Check(value)) {
|
||||
return EXPP_ReturnIntError(PyExc_TypeError,
|
||||
"Must be a scene" );
|
||||
} else {
|
||||
BPy_Scene *bpydata;
|
||||
Scene *data;
|
||||
|
||||
bpydata = (BPy_Scene *)value;
|
||||
data= bpydata->scene;
|
||||
|
||||
if (!data)
|
||||
return EXPP_ReturnIntError(PyExc_RuntimeError,
|
||||
"This Scene has been removed" );
|
||||
|
||||
if (data != G.scene) {
|
||||
set_scene( data );
|
||||
scene_update_for_newframe(data, data->lay);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
|
||||
case ID_IM:
|
||||
if (!BPy_Image_Check(value)) {
|
||||
return EXPP_ReturnIntError(PyExc_TypeError,
|
||||
"Must be a scene" );
|
||||
} else {
|
||||
BPy_Image *bpydata;
|
||||
Image *data;
|
||||
|
||||
if (!G.sima)
|
||||
return 0;
|
||||
|
||||
bpydata = (BPy_Image *)value;
|
||||
data= bpydata->image;
|
||||
|
||||
if (!data)
|
||||
return EXPP_ReturnIntError(PyExc_RuntimeError,
|
||||
"This Scene has been removed" );
|
||||
|
||||
if (data != G.sima->image)
|
||||
G.sima->image= data;
|
||||
}
|
||||
return 0;
|
||||
|
||||
case ID_TXT:
|
||||
if (!BPy_Text_Check(value)) {
|
||||
return EXPP_ReturnIntError(PyExc_TypeError,
|
||||
"Must be a text" );
|
||||
} else {
|
||||
SpaceText *st= NULL;
|
||||
Text *data = ((BPy_Text *)value)->text;
|
||||
|
||||
if (curarea==NULL) {
|
||||
return 0;
|
||||
} else {
|
||||
st= curarea->spacedata.first;
|
||||
}
|
||||
|
||||
if( !data )
|
||||
return EXPP_ReturnIntError( PyExc_RuntimeError,
|
||||
"This object isn't linked to a Blender Text Object" );
|
||||
if(st->spacetype!=SPACE_TEXT)
|
||||
return 0;
|
||||
st->text = data;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
return EXPP_ReturnIntError( PyExc_TypeError,
|
||||
"Only Scene and Image types have the active attribute" );
|
||||
}
|
||||
|
||||
static int LibBlockSeq_setTag(BPy_LibBlockSeq *self, PyObject *value)
|
||||
{
|
||||
ID *id;
|
||||
int param = PyObject_IsTrue( value );
|
||||
|
||||
if( param == -1 )
|
||||
return EXPP_ReturnIntError( PyExc_TypeError,
|
||||
"expected True/False or 0/1" );
|
||||
|
||||
id = (ID *)wich_libbase(G.main, self->type)->first;
|
||||
|
||||
if (param) {
|
||||
for (; id; id = id->next) {
|
||||
id->flag |= LIB_DOIT;
|
||||
}
|
||||
} else {
|
||||
for (; id; id = id->next) {
|
||||
id->flag &= ~LIB_DOIT;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/* New Data, internal functions */
|
||||
static Mesh *add_mesh__internal(char *name)
|
||||
{
|
||||
Mesh *mesh = add_mesh(name); /* doesn't return NULL now, but might someday */
|
||||
|
||||
/* Bound box set to null needed because a new mesh is initialized
|
||||
with a bounding box of -1 -1 -1 -1 -1 -1
|
||||
if its not set to null the bounding box is not re-calculated
|
||||
when ob.getBoundBox() is called.*/
|
||||
MEM_freeN(mesh->bb);
|
||||
mesh->bb= NULL;
|
||||
return mesh;
|
||||
}
|
||||
|
||||
/* used for new and load */
|
||||
PyObject *LibBlockSeq_new(BPy_LibBlockSeq *self, PyObject * args, PyObject *kwd)
|
||||
{
|
||||
ID *id = NULL;
|
||||
char *name=NULL, *filename=NULL, *data_type=NULL;
|
||||
int img_width=256, img_height=256, img_depth=32;
|
||||
float color[] = {0, 0, 0, 1};
|
||||
short data_code = 0;
|
||||
int user_count = 0;
|
||||
|
||||
/* Load from file */
|
||||
if ( ( self->type==ID_IM || self->type==ID_VF ||
|
||||
self->type==ID_SO || self->type==ID_TXT) &&
|
||||
( PyTuple_Size( args ) < 3 ))
|
||||
{
|
||||
static char *kwlist[] = {"name", "filename", NULL};
|
||||
|
||||
if(PyArg_ParseTupleAndKeywords(args, kwd, "|ss", kwlist, &name, &filename) && filename ) {
|
||||
PyObject *ret= NULL;
|
||||
|
||||
if (strlen(filename) > FILE_MAXDIR + FILE_MAXFILE - 1)
|
||||
return ( EXPP_ReturnPyObjError( PyExc_IOError,
|
||||
"filename too long" ) );
|
||||
|
||||
if (self->type == ID_IM) {
|
||||
Image *img = BKE_add_image_file( filename );
|
||||
if (!img)
|
||||
return ( EXPP_ReturnPyObjError( PyExc_IOError,
|
||||
"couldn't load image" ) );
|
||||
ret = Image_CreatePyObject( img );
|
||||
|
||||
} else if (self->type == ID_VF) {
|
||||
VFont *vf = load_vfont (filename);
|
||||
if (!vf)
|
||||
return EXPP_ReturnPyObjError( PyExc_IOError,
|
||||
"couldn't load font" );
|
||||
ret = Font_CreatePyObject(vf);
|
||||
|
||||
} else if (self->type == ID_SO) {
|
||||
bSound *snd = sound_new_sound( filename );
|
||||
if (!snd)
|
||||
return EXPP_ReturnPyObjError( PyExc_IOError,
|
||||
"couldn't load sound" );
|
||||
ret = Sound_CreatePyObject(snd);
|
||||
|
||||
} else if (self->type == ID_TXT) {
|
||||
Text *txt = NULL;
|
||||
txt = add_text( filename );
|
||||
if( !txt )
|
||||
return EXPP_ReturnPyObjError( PyExc_IOError,
|
||||
"couldn't load text" );
|
||||
ret = Text_CreatePyObject(txt);
|
||||
}
|
||||
|
||||
if (!ret)
|
||||
return EXPP_ReturnPyObjError( PyExc_IOError,
|
||||
"couldn't create pyobject on load, unknown error" );
|
||||
if (name) {
|
||||
rename_id( ((BPy_GenericLib *)ret)->id, name );
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
||||
/* New Data */
|
||||
if (self->type == ID_IM) {
|
||||
/* Image, accepts width and height, depth */
|
||||
if( !PyArg_ParseTuple( args, "|siii", &name, &img_width, &img_height, &img_depth ) )
|
||||
return EXPP_ReturnPyObjError( PyExc_TypeError,
|
||||
"one string and two ints expected as arguments" );
|
||||
CLAMP(img_width, 4, 5000);
|
||||
CLAMP(img_height, 4, 5000);
|
||||
|
||||
} else if (self->type == ID_CU) {
|
||||
/* Curve, needs name and type strings */
|
||||
if( !PyArg_ParseTuple( args, "ss", &name, &data_type ) )
|
||||
return EXPP_ReturnPyObjError( PyExc_TypeError,
|
||||
"two strings expected as arguments" );
|
||||
|
||||
if( !strcmp( data_type, "Curve" ) ) data_code = OB_CURVE;
|
||||
else if( !strcmp( data_type, "Text3d" ) ) data_code = OB_FONT;/*
|
||||
else if( !strcmp( data_type, "Surf" ) ) data_code = OB_SURF;*/
|
||||
else return EXPP_ReturnPyObjError( PyExc_TypeError,
|
||||
"Second argument for Curve type incorrect\t\nmust be a string in (Curve or Text - Surf is not supported yet)" );
|
||||
|
||||
} else if (self->type == ID_IP) {
|
||||
/* IPO, needs name and type strings */
|
||||
if( !PyArg_ParseTuple( args, "ss", &name, &data_type ) )
|
||||
return EXPP_ReturnPyObjError( PyExc_TypeError,
|
||||
"two strings expected as arguments" );
|
||||
|
||||
if( !strcmp( data_type, "Object" ) ) data_code = ID_OB;
|
||||
else if( !strcmp( data_type, "Camera" ) ) data_code = ID_CA;
|
||||
else if( !strcmp( data_type, "World" ) ) data_code = ID_WO;
|
||||
else if( !strcmp( data_type, "Material" ) ) data_code = ID_MA;
|
||||
else if( !strcmp( data_type, "Texture" ) ) data_code = ID_TE;
|
||||
else if( !strcmp( data_type, "Lamp" ) ) data_code = ID_LA;
|
||||
else if( !strcmp( data_type, "Action" ) ) data_code = ID_PO;
|
||||
else if( !strcmp( data_type, "Constraint" ) ) data_code = ID_CO;
|
||||
else if( !strcmp( data_type, "Sequence" ) ) data_code = ID_SEQ;
|
||||
else if( !strcmp( data_type, "Curve" ) ) data_code = ID_CU;
|
||||
else if( !strcmp( data_type, "Key" ) ) data_code = ID_KE;
|
||||
else return EXPP_ReturnPyObjError( PyExc_TypeError,
|
||||
"Second argument for IPO type incorrect\t\nmust be a string in (Object, Camera, World, Material, Texture, Lamp, Action, Sequence, Curve, Key)" );
|
||||
|
||||
} else {
|
||||
/* Other types only need the name */
|
||||
if( !PyArg_ParseTuple( args, "|s", &name ) )
|
||||
return EXPP_ReturnPyObjError( PyExc_TypeError,
|
||||
"new(name) - name must be a string argument" );
|
||||
}
|
||||
|
||||
switch (self->type) {
|
||||
case ID_SCE:
|
||||
id = (ID *)add_scene( name?name:"Scene" );
|
||||
user_count = 1;
|
||||
break;
|
||||
case ID_OB:
|
||||
return EXPP_ReturnPyObjError( PyExc_RuntimeError,
|
||||
"Add objects through the scenes objects iterator" );
|
||||
case ID_ME:
|
||||
id = (ID *)add_mesh__internal( name?name:"Mesh" );
|
||||
break;
|
||||
case ID_CU:
|
||||
id = (ID *)add_curve( name?name:"Curve", data_code );
|
||||
if (data_code==OB_FONT) {
|
||||
Text3d *text3d = (Text3d *)id;
|
||||
text3d->vfont= get_builtin_font();
|
||||
text3d->vfont->id.us++;
|
||||
text3d->str= MEM_mallocN(sizeof(wchar_t), "str");
|
||||
text3d->str[0] = '\0';
|
||||
text3d->totbox= text3d->actbox= 1;
|
||||
text3d->tb= MEM_callocN(MAXTEXTBOX*sizeof(TextBox), "textbox");
|
||||
text3d->tb[0].w = text3d->tb[0].h = 0.0;
|
||||
|
||||
} /*else { CURVE - Dont need to do anything } */
|
||||
break;
|
||||
case ID_MB:
|
||||
id = (ID *)add_mball( name?name:"MBall" );
|
||||
break;
|
||||
case ID_MA:
|
||||
id = (ID *)add_material( name?name:"Material" );
|
||||
break;
|
||||
case ID_TE:
|
||||
id = (ID *)add_texture( name?name:"Texture" );
|
||||
break;
|
||||
case ID_IM:
|
||||
{
|
||||
id = (ID *)BKE_add_image_size(img_width, img_height, name?name:"Image", img_depth==128 ? 1:0, 0, color);
|
||||
if( !id )
|
||||
return ( EXPP_ReturnPyObjError( PyExc_MemoryError,
|
||||
"couldn't create PyObject Image_Type" ) );
|
||||
/* new images have zero user count */
|
||||
break;
|
||||
}
|
||||
case ID_LT:
|
||||
id = (ID *)add_lattice( name?name:"Lattice" );
|
||||
break;
|
||||
case ID_LA:
|
||||
id = (ID *)add_lamp( name?name:"Lamp" );
|
||||
break;
|
||||
case ID_CA:
|
||||
id = (ID *)add_camera( name?name:"Camera" );
|
||||
break;
|
||||
case ID_IP:
|
||||
id = (ID *)add_ipo( name?name:"Ipo", data_code );
|
||||
break;
|
||||
case ID_WO:
|
||||
id = (ID *)add_world( name?name:"World" );
|
||||
break;
|
||||
case ID_VF:
|
||||
return EXPP_ReturnPyObjError( PyExc_TypeError,
|
||||
"Cannot create new fonts, use the new(name, filename) function to load from a file" );
|
||||
case ID_TXT:
|
||||
id = (ID *)add_empty_text( name?name:"Text" );
|
||||
user_count = 1;
|
||||
break;
|
||||
case ID_SO:
|
||||
return EXPP_ReturnPyObjError( PyExc_TypeError,
|
||||
"Cannot create new sounds, use the new(name, filename) function to load from a file" );
|
||||
case ID_GR:
|
||||
id = (ID *)add_group( name?name:"Group" );
|
||||
user_count = 1;
|
||||
break;
|
||||
case ID_AR:
|
||||
id = (ID *)add_armature( name?name:"Armature" );
|
||||
break;
|
||||
case ID_AC:
|
||||
id = (ID *)add_empty_action( name?name:"Action" );
|
||||
user_count = 1;
|
||||
break;
|
||||
}
|
||||
|
||||
if (!id)
|
||||
Py_RETURN_NONE;
|
||||
|
||||
/* set some types user count to 1, otherwise zero */
|
||||
id->us = user_count;
|
||||
|
||||
return GetPyObjectFromID(id);
|
||||
}
|
||||
|
||||
|
||||
static PyObject *LibBlockSeq_unlink(BPy_LibBlockSeq *self, PyObject * value)
|
||||
{
|
||||
switch (self->type) {
|
||||
case ID_SCE:
|
||||
if( !BPy_Scene_Check(value) ) {
|
||||
return EXPP_ReturnPyObjError( PyExc_TypeError,
|
||||
"expected Scene object" );
|
||||
} else {
|
||||
Scene *data = ((BPy_Scene *)value)->scene;
|
||||
|
||||
if (!data)
|
||||
return EXPP_ReturnPyObjError( PyExc_RuntimeError,
|
||||
"This Scene has been removed" );
|
||||
|
||||
/* Run the removal code */
|
||||
free_libblock( &G.main->scene, data );
|
||||
((BPy_Scene *)value)->scene = NULL;
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
case ID_GR:
|
||||
if( !BPy_Group_Check(value) ) {
|
||||
return EXPP_ReturnPyObjError( PyExc_TypeError,
|
||||
"expected Group object" );
|
||||
} else {
|
||||
Group *data = ((BPy_Group *)value)->group;
|
||||
|
||||
if (!data)
|
||||
return EXPP_ReturnPyObjError( PyExc_RuntimeError,
|
||||
"This Group has been removed already" );
|
||||
|
||||
/* Run the removal code */
|
||||
free_group(data);
|
||||
unlink_group(data);
|
||||
data->id.us= 0;
|
||||
free_libblock( &G.main->group, data );
|
||||
((BPy_Group *)value)->group = NULL;
|
||||
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
case ID_TXT:
|
||||
if( !BPy_Text_Check(value) ) {
|
||||
return EXPP_ReturnPyObjError( PyExc_TypeError,
|
||||
"expected Text object" );
|
||||
} else {
|
||||
Text *data = ((BPy_Text *)value)->text;
|
||||
|
||||
if (!data)
|
||||
return EXPP_ReturnPyObjError( PyExc_RuntimeError,
|
||||
"This Group has been removed already" );
|
||||
|
||||
/* Run the removal code */
|
||||
BPY_clear_bad_scriptlinks( data );
|
||||
BPY_free_pyconstraint_links( data );
|
||||
free_text_controllers( data );
|
||||
unlink_text( data );
|
||||
free_libblock( &G.main->text, data );
|
||||
((BPy_Text *)value)->text = NULL;
|
||||
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
}
|
||||
return EXPP_ReturnPyObjError( PyExc_TypeError,
|
||||
"Only types Scene, Group and Text can unlink" );
|
||||
}
|
||||
|
||||
static int LibBlockSeq_compare( BPy_LibBlockSeq * a, BPy_LibBlockSeq * b )
|
||||
{
|
||||
return ( a->type == b->type) ? 0 : -1;
|
||||
}
|
||||
|
||||
/*
|
||||
* repr function
|
||||
* callback functions building meaninful string to representations
|
||||
*/
|
||||
static PyObject *LibBlockSeq_repr( BPy_LibBlockSeq * self )
|
||||
{
|
||||
return PyString_FromFormat( "[LibBlockSeq Iterator]");
|
||||
}
|
||||
|
||||
static PyGetSetDef LibBlockSeq_getseters[] = {
|
||||
{"active",
|
||||
(getter)LibBlockSeq_getActive, (setter)LibBlockSeq_setActive,
|
||||
"active object",
|
||||
NULL},
|
||||
{"tag",
|
||||
(getter)NULL, (setter)LibBlockSeq_setTag,
|
||||
"tag all data in True or False (write only)",
|
||||
NULL},
|
||||
{NULL,NULL,NULL,NULL,NULL} /* Sentinel */
|
||||
};
|
||||
|
||||
static struct PyMethodDef BPy_LibBlockSeq_methods[] = {
|
||||
{"new", (PyCFunction)LibBlockSeq_new, METH_VARARGS | METH_KEYWORDS,
|
||||
"(name) - Create a new object in this scene from the obdata given and return a new object"},
|
||||
{"unlink", (PyCFunction)LibBlockSeq_unlink, METH_O,
|
||||
"unlinks the object from the scene"},
|
||||
{NULL, NULL, 0, NULL}
|
||||
};
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Python LibBlockSeq_Type structure definition: */
|
||||
/*****************************************************************************/
|
||||
PyTypeObject LibBlockSeq_Type = {
|
||||
PyObject_HEAD_INIT( NULL ) /* required py macro */
|
||||
0, /* ob_size */
|
||||
/* For printing, in format "<module>.<name>" */
|
||||
"Blender LibBlockSeq", /* char *tp_name; */
|
||||
sizeof( BPy_LibBlockSeq ), /* int tp_basicsize; */
|
||||
0, /* tp_itemsize; For allocation */
|
||||
|
||||
/* Methods to implement standard operations */
|
||||
|
||||
NULL, /* destructor tp_dealloc; */
|
||||
NULL, /* printfunc tp_print; */
|
||||
NULL, /* getattrfunc tp_getattr; */
|
||||
NULL, /* setattrfunc tp_setattr; */
|
||||
( cmpfunc ) LibBlockSeq_compare, /* cmpfunc tp_compare; */
|
||||
( reprfunc ) LibBlockSeq_repr, /* reprfunc tp_repr; */
|
||||
|
||||
/* Method suites for standard classes */
|
||||
|
||||
NULL, /* PyNumberMethods *tp_as_number; */
|
||||
NULL, /* PySequenceMethods *tp_as_sequence; */
|
||||
&LibBlockSeq_as_mapping, /* PyMappingMethods *tp_as_mapping; */
|
||||
|
||||
/* More standard operations (here for binary compatibility) */
|
||||
|
||||
NULL, /* hashfunc tp_hash; */
|
||||
NULL, /* ternaryfunc tp_call; */
|
||||
NULL, /* reprfunc tp_str; */
|
||||
NULL, /* getattrofunc tp_getattro; */
|
||||
NULL, /* setattrofunc tp_setattro; */
|
||||
|
||||
/* Functions to access object as input/output buffer */
|
||||
NULL, /* PyBufferProcs *tp_as_buffer; */
|
||||
|
||||
/*** Flags to define presence of optional/expanded features ***/
|
||||
Py_TPFLAGS_DEFAULT, /* long tp_flags; */
|
||||
|
||||
NULL, /* char *tp_doc; Documentation string */
|
||||
/*** Assigned meaning in release 2.0 ***/
|
||||
/* call function for all accessible objects */
|
||||
NULL, /* traverseproc tp_traverse; */
|
||||
|
||||
/* delete references to contained objects */
|
||||
NULL, /* inquiry tp_clear; */
|
||||
|
||||
/*** Assigned meaning in release 2.1 ***/
|
||||
/*** rich comparisons ***/
|
||||
NULL, /* richcmpfunc tp_richcompare; */
|
||||
|
||||
/*** weak reference enabler ***/
|
||||
0, /* long tp_weaklistoffset; */
|
||||
|
||||
/*** Added in release 2.2 ***/
|
||||
/* Iterators */
|
||||
( getiterfunc) LibBlockSeq_getIter, /* getiterfunc tp_iter; */
|
||||
( iternextfunc ) LibBlockSeq_nextIter, /* iternextfunc tp_iternext; */
|
||||
|
||||
/*** Attribute descriptor and subclassing stuff ***/
|
||||
BPy_LibBlockSeq_methods, /* struct PyMethodDef *tp_methods; */
|
||||
NULL, /* struct PyMemberDef *tp_members; */
|
||||
LibBlockSeq_getseters, /* struct PyGetSetDef *tp_getset; */
|
||||
NULL, /* struct _typeobject *tp_base; */
|
||||
NULL, /* PyObject *tp_dict; */
|
||||
NULL, /* descrgetfunc tp_descr_get; */
|
||||
NULL, /* descrsetfunc tp_descr_set; */
|
||||
0, /* long tp_dictoffset; */
|
||||
NULL, /* initproc tp_init; */
|
||||
NULL, /* allocfunc tp_alloc; */
|
||||
NULL, /* newfunc tp_new; */
|
||||
/* Low-level free-memory routine */
|
||||
NULL, /* freefunc tp_free; */
|
||||
/* For PyObject_IS_GC */
|
||||
NULL, /* inquiry tp_is_gc; */
|
||||
NULL, /* PyObject *tp_bases; */
|
||||
/* method resolution order */
|
||||
NULL, /* PyObject *tp_mro; */
|
||||
NULL, /* PyObject *tp_cache; */
|
||||
NULL, /* PyObject *tp_subclasses; */
|
||||
NULL, /* PyObject *tp_weaklist; */
|
||||
NULL
|
||||
};
|
||||
|
||||
|
||||
/*-----------------------------BPy module Init())-----------------------------*/
|
||||
|
||||
PyObject * Data_Init( void )
|
||||
{
|
||||
PyObject *module;
|
||||
|
||||
PyType_Ready( &LibBlockSeq_Type );
|
||||
PyType_Ready( &Config_Type );
|
||||
|
||||
/*submodule = Py_InitModule3( "Blender.Main", NULL, M_Main_doc );*/
|
||||
module = Py_InitModule3( "bpy.data", NULL, "The bpy.data submodule" );
|
||||
|
||||
/* Python Data Types */
|
||||
PyModule_AddObject( module, "scenes", LibBlockSeq_CreatePyObject(NULL, ID_SCE) );
|
||||
PyModule_AddObject( module, "objects", LibBlockSeq_CreatePyObject(NULL, ID_OB) );
|
||||
PyModule_AddObject( module, "meshes", LibBlockSeq_CreatePyObject(NULL, ID_ME) );
|
||||
PyModule_AddObject( module, "curves", LibBlockSeq_CreatePyObject(NULL, ID_CU) );
|
||||
PyModule_AddObject( module, "metaballs",LibBlockSeq_CreatePyObject(NULL, ID_MB) );
|
||||
PyModule_AddObject( module, "materials",LibBlockSeq_CreatePyObject(NULL, ID_MA) );
|
||||
PyModule_AddObject( module, "textures", LibBlockSeq_CreatePyObject(NULL, ID_TE) );
|
||||
PyModule_AddObject( module, "images", LibBlockSeq_CreatePyObject(NULL, ID_IM) );
|
||||
PyModule_AddObject( module, "lattices", LibBlockSeq_CreatePyObject(NULL, ID_LT) );
|
||||
PyModule_AddObject( module, "lamps", LibBlockSeq_CreatePyObject(NULL, ID_LA) );
|
||||
PyModule_AddObject( module, "cameras", LibBlockSeq_CreatePyObject(NULL, ID_CA) );
|
||||
PyModule_AddObject( module, "ipos", LibBlockSeq_CreatePyObject(NULL, ID_IP) );
|
||||
PyModule_AddObject( module, "worlds", LibBlockSeq_CreatePyObject(NULL, ID_WO) );
|
||||
PyModule_AddObject( module, "fonts", LibBlockSeq_CreatePyObject(NULL, ID_VF) );
|
||||
PyModule_AddObject( module, "texts", LibBlockSeq_CreatePyObject(NULL, ID_TXT) );
|
||||
PyModule_AddObject( module, "sounds", LibBlockSeq_CreatePyObject(NULL, ID_SO) );
|
||||
PyModule_AddObject( module, "groups", LibBlockSeq_CreatePyObject(NULL, ID_GR) );
|
||||
PyModule_AddObject( module, "armatures",LibBlockSeq_CreatePyObject(NULL, ID_AR) );
|
||||
PyModule_AddObject( module, "actions", LibBlockSeq_CreatePyObject(NULL, ID_AC) );
|
||||
return module;
|
||||
}
|
||||
@@ -1,52 +0,0 @@
|
||||
/*
|
||||
*
|
||||
* ***** 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*
|
||||
* The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This is a new part of Blender.
|
||||
*
|
||||
* Contributor(s): Campbell Barton
|
||||
*
|
||||
* ***** END GPL LICENSE BLOCK *****
|
||||
*/
|
||||
|
||||
#ifndef EXPP_BPYDATA_H
|
||||
#define EXPP_BPYDATA_H
|
||||
|
||||
#include <Python.h>
|
||||
#include "DNA_listBase.h"
|
||||
|
||||
/* The Main PyType Object defined in Main.c */
|
||||
extern PyTypeObject LibBlockSeq_Type;
|
||||
|
||||
#define BPy_LibBlockSeq_Check(v) \
|
||||
((v)->ob_type == &LibBlockSeq_Type)
|
||||
|
||||
/* Main sequence, iterate on the libdatas listbase*/
|
||||
typedef struct {
|
||||
PyObject_VAR_HEAD /* required python macro */
|
||||
Link *iter; /* so we can iterate over the listbase */
|
||||
|
||||
short type; /* store the ID type such as ID_ME */
|
||||
} BPy_LibBlockSeq;
|
||||
|
||||
|
||||
PyObject * Data_Init( void );
|
||||
|
||||
#endif /* EXPP_BPYDATA_H */
|
||||
@@ -1,90 +0,0 @@
|
||||
/*
|
||||
* $Id$
|
||||
* ***** 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*
|
||||
* The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This is a new part of Blender.
|
||||
*
|
||||
* Contributor(s): Willian P. Germano
|
||||
*
|
||||
* ***** END GPL LICENSE BLOCK *****
|
||||
*/
|
||||
|
||||
#ifndef EXPP_bpy_types_h
|
||||
#define EXPP_bpy_types_h
|
||||
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Camera Data */
|
||||
/*****************************************************************************/
|
||||
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Lamp Data */
|
||||
/*****************************************************************************/
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Ipo Data */
|
||||
/*****************************************************************************/
|
||||
|
||||
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Metaball Data */
|
||||
/*****************************************************************************/
|
||||
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Metaelem Data */
|
||||
/*****************************************************************************/
|
||||
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Effect Data */
|
||||
/*****************************************************************************/
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Wave Data */
|
||||
/*****************************************************************************/
|
||||
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Build Data */
|
||||
/*****************************************************************************/
|
||||
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Particle Data */
|
||||
/*****************************************************************************/
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Curve Data */
|
||||
/*****************************************************************************/
|
||||
|
||||
/**********
|
||||
CurNurb data
|
||||
***********/
|
||||
|
||||
|
||||
/*****************************************************************************/
|
||||
/* World Data */
|
||||
/*****************************************************************************/
|
||||
|
||||
|
||||
#endif /* EXPP_bpy_types_h */
|
||||
@@ -1,472 +0,0 @@
|
||||
/*
|
||||
* $Id$
|
||||
*
|
||||
* ***** 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*
|
||||
* The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This is a new part of Blender.
|
||||
*
|
||||
* Contributor(s): Willian P. Germano
|
||||
*
|
||||
* ***** END GPL LICENSE BLOCK *****
|
||||
*/
|
||||
|
||||
#include "charRGBA.h" /*This must come first */
|
||||
#include "gen_utils.h"
|
||||
|
||||
/* This file is heavily based on the old bpython Constant object code in
|
||||
Blender */
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Python charRGBA_Type callback function prototypes: */
|
||||
/*****************************************************************************/
|
||||
static PyObject *charRGBA_repr( BPy_charRGBA * self );
|
||||
|
||||
static int charRGBALength( BPy_charRGBA * self );
|
||||
|
||||
static PyObject *charRGBASubscript( BPy_charRGBA * self, PyObject * key );
|
||||
static int charRGBAAssSubscript( BPy_charRGBA * self, PyObject * who,
|
||||
PyObject * cares );
|
||||
|
||||
static PyObject *charRGBAItem( BPy_charRGBA * self, int i );
|
||||
static int charRGBAAssItem( BPy_charRGBA * self, int i, PyObject * ob );
|
||||
static PyObject *charRGBASlice( BPy_charRGBA * self, int begin, int end );
|
||||
static int charRGBAAssSlice( BPy_charRGBA * self, int begin, int end,
|
||||
PyObject * seq );
|
||||
static PyObject *charRGBA_getColor( BPy_charRGBA * self, void * type);
|
||||
static int charRGBA_setColor( BPy_charRGBA * self, PyObject * value, void * type);
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Python charRGBA_Type Mapping Methods table: */
|
||||
/*****************************************************************************/
|
||||
static PyMappingMethods charRGBAAsMapping = {
|
||||
( inquiry ) charRGBALength, /* mp_length */
|
||||
( binaryfunc ) charRGBASubscript, /* mp_subscript */
|
||||
( objobjargproc ) charRGBAAssSubscript, /* mp_ass_subscript */
|
||||
};
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Python charRGBA_Type Sequence Methods table: */
|
||||
/*****************************************************************************/
|
||||
static PySequenceMethods charRGBAAsSequence = {
|
||||
( inquiry ) charRGBALength, /* sq_length */
|
||||
( binaryfunc ) 0, /* sq_concat */
|
||||
( intargfunc ) 0, /* sq_repeat */
|
||||
( intargfunc ) charRGBAItem, /* sq_item */
|
||||
( intintargfunc ) charRGBASlice, /* sq_slice */
|
||||
( intobjargproc ) charRGBAAssItem, /* sq_ass_item */
|
||||
( intintobjargproc ) charRGBAAssSlice, /* sq_ass_slice */
|
||||
};
|
||||
|
||||
static PyGetSetDef charRGBA_getseters[] = {
|
||||
{"R",
|
||||
(getter)charRGBA_getColor, (setter)charRGBA_setColor,
|
||||
"the red component",
|
||||
(void *) 0},
|
||||
{"r",
|
||||
(getter)charRGBA_getColor, (setter)charRGBA_setColor,
|
||||
"the red component",
|
||||
(void *) 0},
|
||||
{"G",
|
||||
(getter)charRGBA_getColor, (setter)charRGBA_setColor,
|
||||
"the green component",
|
||||
(void *) 1},
|
||||
{"g",
|
||||
(getter)charRGBA_getColor, (setter)charRGBA_setColor,
|
||||
"the green component",
|
||||
(void *) 1},
|
||||
{"B",
|
||||
(getter)charRGBA_getColor, (setter)charRGBA_setColor,
|
||||
"the blue component",
|
||||
(void *) 2},
|
||||
{"b",
|
||||
(getter)charRGBA_getColor, (setter)charRGBA_setColor,
|
||||
"the blue component",
|
||||
(void *) 2},
|
||||
{"A",
|
||||
(getter)charRGBA_getColor, (setter)charRGBA_setColor,
|
||||
"the alpha component",
|
||||
(void *) 3},
|
||||
{"a",
|
||||
(getter)charRGBA_getColor, (setter)charRGBA_setColor,
|
||||
"the alpha component",
|
||||
(void *) 3},
|
||||
{NULL,NULL,NULL,NULL,NULL} /* Sentinel */
|
||||
};
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Python charRGBA_Type structure definition: */
|
||||
/*****************************************************************************/
|
||||
PyTypeObject charRGBA_Type = {
|
||||
PyObject_HEAD_INIT( NULL ) /* required py macro */
|
||||
0, /* ob_size */
|
||||
/* For printing, in format "<module>.<name>" */
|
||||
"charRGBA", /* tp_name */
|
||||
sizeof( BPy_charRGBA ), /* tp_basicsize */
|
||||
0, /* tp_itemsize; For allocation */
|
||||
|
||||
/* Methods to implement standard operations */
|
||||
|
||||
NULL, /* destructor tp_dealloc; */
|
||||
NULL, /* printfunc tp_print; */
|
||||
NULL, /* getattrfunc tp_getattr; */
|
||||
NULL, /* setattrfunc tp_setattr; */
|
||||
NULL, /* cmpfunc tp_compare; */
|
||||
( reprfunc ) charRGBA_repr, /* reprfunc tp_repr; */
|
||||
|
||||
/* Method suites for standard classes */
|
||||
|
||||
NULL, /* PyNumberMethods *tp_as_number; */
|
||||
&charRGBAAsSequence, /* PySequenceMethods *tp_as_sequence; */
|
||||
&charRGBAAsMapping, /* PyMappingMethods *tp_as_mapping; */
|
||||
|
||||
/* More standard operations (here for binary compatibility) */
|
||||
|
||||
NULL, /* hashfunc tp_hash; */
|
||||
NULL, /* ternaryfunc tp_call; */
|
||||
NULL, /* reprfunc tp_str; */
|
||||
NULL, /* getattrofunc tp_getattro; */
|
||||
NULL, /* setattrofunc tp_setattro; */
|
||||
|
||||
/* Functions to access object as input/output buffer */
|
||||
NULL, /* PyBufferProcs *tp_as_buffer; */
|
||||
|
||||
/*** Flags to define presence of optional/expanded features ***/
|
||||
Py_TPFLAGS_DEFAULT, /* long tp_flags; */
|
||||
|
||||
NULL, /* char *tp_doc; Documentation string */
|
||||
/*** Assigned meaning in release 2.0 ***/
|
||||
/* call function for all accessible objects */
|
||||
NULL, /* traverseproc tp_traverse; */
|
||||
|
||||
/* delete references to contained objects */
|
||||
NULL, /* inquiry tp_clear; */
|
||||
|
||||
/*** Assigned meaning in release 2.1 ***/
|
||||
/*** rich comparisons ***/
|
||||
NULL, /* richcmpfunc tp_richcompare; */
|
||||
|
||||
/*** weak reference enabler ***/
|
||||
0, /* long tp_weaklistoffset; */
|
||||
|
||||
/*** Added in release 2.2 ***/
|
||||
/* Iterators */
|
||||
NULL, /* getiterfunc tp_iter; */
|
||||
NULL, /* iternextfunc tp_iternext; */
|
||||
|
||||
/*** Attribute descriptor and subclassing stuff ***/
|
||||
NULL, /* struct PyMethodDef *tp_methods; */
|
||||
NULL, /* struct PyMemberDef *tp_members; */
|
||||
charRGBA_getseters, /* struct PyGetSetDef *tp_getset; */
|
||||
NULL, /* struct _typeobject *tp_base; */
|
||||
NULL, /* PyObject *tp_dict; */
|
||||
NULL, /* descrgetfunc tp_descr_get; */
|
||||
NULL, /* descrsetfunc tp_descr_set; */
|
||||
0, /* long tp_dictoffset; */
|
||||
NULL, /* initproc tp_init; */
|
||||
NULL, /* allocfunc tp_alloc; */
|
||||
NULL, /* newfunc tp_new; */
|
||||
/* Low-level free-memory routine */
|
||||
NULL, /* freefunc tp_free; */
|
||||
/* For PyObject_IS_GC */
|
||||
NULL, /* inquiry tp_is_gc; */
|
||||
NULL, /* PyObject *tp_bases; */
|
||||
/* method resolution order */
|
||||
NULL, /* PyObject *tp_mro; */
|
||||
NULL, /* PyObject *tp_cache; */
|
||||
NULL, /* PyObject *tp_subclasses; */
|
||||
NULL, /* PyObject *tp_weaklist; */
|
||||
NULL
|
||||
};
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Function: charRGBA_New */
|
||||
/*****************************************************************************/
|
||||
PyObject *charRGBA_New( char *rgba )
|
||||
{
|
||||
BPy_charRGBA *charRGBA = NULL;
|
||||
|
||||
/*
|
||||
* When called the first time, charRGBA_Type.tp_dealloc will be NULL.
|
||||
* If that's the case, initialize the PyTypeObject. If the
|
||||
* initialization succeeds, then create a new object.
|
||||
*/
|
||||
|
||||
if( charRGBA_Type.tp_dealloc || PyType_Ready( &charRGBA_Type ) >= 0 ) {
|
||||
charRGBA = ( BPy_charRGBA * ) PyObject_NEW( BPy_charRGBA,
|
||||
&charRGBA_Type );
|
||||
}
|
||||
|
||||
if( charRGBA == NULL )
|
||||
return EXPP_ReturnPyObjError( PyExc_MemoryError,
|
||||
"couldn't create charRGBA object" );
|
||||
|
||||
/* rgba is a pointer to the first item of a char[4] array */
|
||||
charRGBA->rgba[0] = &rgba[0];
|
||||
charRGBA->rgba[1] = &rgba[1];
|
||||
charRGBA->rgba[2] = &rgba[2];
|
||||
charRGBA->rgba[3] = &rgba[3];
|
||||
|
||||
return ( PyObject * ) charRGBA;
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Functions: charRGBA_getCol and charRGBA_setCol */
|
||||
/* Description: These functions get/set rgba color triplet values. The */
|
||||
/* get function returns a tuple, the set one accepts three */
|
||||
/* chars (separated or in a tuple) as arguments. */
|
||||
/*****************************************************************************/
|
||||
PyObject *charRGBA_getCol( BPy_charRGBA * self )
|
||||
{
|
||||
PyObject *list = PyList_New( 4 );
|
||||
|
||||
if( !list )
|
||||
return EXPP_ReturnPyObjError( PyExc_MemoryError,
|
||||
"couldn't create PyList" );
|
||||
|
||||
PyList_SET_ITEM( list, 0, PyInt_FromLong( *(self->rgba[0])) );
|
||||
PyList_SET_ITEM( list, 1, PyInt_FromLong( *(self->rgba[1])) );
|
||||
PyList_SET_ITEM( list, 2, PyInt_FromLong( *(self->rgba[2])) );
|
||||
PyList_SET_ITEM( list, 3, PyInt_FromLong( *(self->rgba[3])) );
|
||||
return list;
|
||||
}
|
||||
|
||||
PyObject *charRGBA_setCol( BPy_charRGBA * self, PyObject * args )
|
||||
{
|
||||
int ok;
|
||||
char r = 0, g = 0, b = 0, a = 0;
|
||||
|
||||
if( PyObject_Length( args ) == 4 )
|
||||
ok = PyArg_ParseTuple( args, "bbbb", &r, &g, &b, &a );
|
||||
|
||||
else
|
||||
ok = PyArg_ParseTuple( args, "|(bbbb)", &r, &g, &b, &a );
|
||||
|
||||
if( !ok )
|
||||
return EXPP_ReturnPyObjError( PyExc_TypeError,
|
||||
"expected 1-byte ints [b,b,b,b] or b,b,b,b as arguments (or nothing)" );
|
||||
|
||||
*( self->rgba[0] ) = (char)EXPP_ClampInt( r, 0, 255 );
|
||||
*( self->rgba[1] ) = (char)EXPP_ClampInt( g, 0, 255 );
|
||||
*( self->rgba[2] ) = (char)EXPP_ClampInt( b, 0, 255 );
|
||||
*( self->rgba[3] ) = (char)EXPP_ClampInt( a, 0, 255 );
|
||||
|
||||
return EXPP_incr_ret( Py_None );
|
||||
}
|
||||
|
||||
/* return color value for one of the components */
|
||||
|
||||
static PyObject *charRGBA_getColor( BPy_charRGBA * self, void * type)
|
||||
{
|
||||
int index = ((long)type) & 3;
|
||||
return PyInt_FromLong ( *self->rgba[index] );
|
||||
}
|
||||
|
||||
/* sets the color value of one of the components */
|
||||
|
||||
static int charRGBA_setColor( BPy_charRGBA * self, PyObject * value,
|
||||
void * type)
|
||||
{
|
||||
int index = ((long)type) & 3;
|
||||
PyObject *num = PyNumber_Int( value );
|
||||
|
||||
/* argument must be a number */
|
||||
if( !num )
|
||||
return EXPP_ReturnIntError( PyExc_TypeError,
|
||||
"expected char argument" );
|
||||
|
||||
/* clamp valut to 0..255 then assign */
|
||||
*self->rgba[index] = (char)EXPP_ClampInt( (int)PyInt_AS_LONG(value),
|
||||
0, 255 );
|
||||
Py_DECREF( num );
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Section: charRGBA as Mapping */
|
||||
/* These functions provide code to access charRGBA objects as */
|
||||
/* mappings. */
|
||||
/*****************************************************************************/
|
||||
static int charRGBALength( BPy_charRGBA * self )
|
||||
{
|
||||
return 4;
|
||||
}
|
||||
|
||||
static PyObject *charRGBASubscript( BPy_charRGBA * self, PyObject * key )
|
||||
{
|
||||
char *name = NULL;
|
||||
int i;
|
||||
|
||||
if( PyNumber_Check( key ) )
|
||||
return charRGBAItem( self, ( int ) PyInt_AsLong( key ) );
|
||||
|
||||
if( !PyArg_ParseTuple( key, "s", &name ) )
|
||||
return EXPP_ReturnPyObjError( PyExc_TypeError,
|
||||
"expected int or string argument" );
|
||||
|
||||
if( !strcmp( name, "R" ) || !strcmp( name, "r" ) )
|
||||
i = 0;
|
||||
else if( !strcmp( name, "G" ) || !strcmp( name, "g" ) )
|
||||
i = 1;
|
||||
else if( !strcmp( name, "B" ) || !strcmp( name, "b" ) )
|
||||
i = 2;
|
||||
else if( !strcmp( name, "A" ) || !strcmp( name, "a" ) )
|
||||
i = 3;
|
||||
else
|
||||
return EXPP_ReturnPyObjError( PyExc_AttributeError, name );
|
||||
|
||||
return PyInt_FromLong( (long)(*self->rgba[i]) );
|
||||
}
|
||||
|
||||
static int charRGBAAssSubscript( BPy_charRGBA * self, PyObject * key,
|
||||
PyObject * v )
|
||||
{
|
||||
char *name = NULL;
|
||||
int i;
|
||||
|
||||
if( !PyNumber_Check( v ) )
|
||||
return EXPP_ReturnIntError( PyExc_TypeError,
|
||||
"value to assign must be a number" );
|
||||
|
||||
if( PyNumber_Check( key ) )
|
||||
return charRGBAAssItem( self, ( int ) PyInt_AsLong( key ), v );
|
||||
|
||||
if( !PyArg_Parse( key, "s", &name ) )
|
||||
return EXPP_ReturnIntError( PyExc_TypeError,
|
||||
"expected int or string argument" );
|
||||
|
||||
if( !strcmp( name, "R" ) || !strcmp( name, "r" ) )
|
||||
i = 0;
|
||||
else if( !strcmp( name, "G" ) || !strcmp( name, "g" ) )
|
||||
i = 1;
|
||||
else if( !strcmp( name, "B" ) || !strcmp( name, "b" ) )
|
||||
i = 2;
|
||||
else if( !strcmp( name, "A" ) || !strcmp( name, "a" ) )
|
||||
i = 3;
|
||||
else
|
||||
return EXPP_ReturnIntError( PyExc_AttributeError, name );
|
||||
|
||||
*( self->rgba[i] ) = (char)EXPP_ClampInt( PyInt_AsLong( v ), 0, 255 );
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Section: charRGBA as Sequence */
|
||||
/* These functions provide code to access charRGBA objects as */
|
||||
/* sequences. */
|
||||
/*****************************************************************************/
|
||||
static PyObject *charRGBAItem( BPy_charRGBA * self, int i )
|
||||
{
|
||||
if( i < 0 || i >= 4 )
|
||||
return EXPP_ReturnPyObjError( PyExc_IndexError,
|
||||
"array index out of range" );
|
||||
|
||||
return PyInt_FromLong( *(self->rgba[i]) );
|
||||
}
|
||||
|
||||
static PyObject *charRGBASlice( BPy_charRGBA * self, int begin, int end )
|
||||
{
|
||||
PyObject *list;
|
||||
int count;
|
||||
|
||||
if( begin < 0 )
|
||||
begin = 0;
|
||||
if( end > 4 )
|
||||
end = 4;
|
||||
if( begin > end )
|
||||
begin = end;
|
||||
|
||||
list = PyList_New( end - begin );
|
||||
|
||||
for( count = begin; count < end; count++ )
|
||||
PyList_SetItem( list, count - begin,
|
||||
PyInt_FromLong( *( self->rgba[count] ) ) );
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
static int charRGBAAssItem( BPy_charRGBA * self, int i, PyObject * ob )
|
||||
{
|
||||
if( i < 0 || i >= 4 )
|
||||
return EXPP_ReturnIntError( PyExc_IndexError,
|
||||
"array assignment index out of range" );
|
||||
|
||||
if( !PyNumber_Check( ob ) )
|
||||
return EXPP_ReturnIntError( PyExc_IndexError,
|
||||
"color component must be a number" );
|
||||
|
||||
*( self->rgba[i] ) = (char)EXPP_ClampInt( PyInt_AsLong( ob ), 0, 255 );
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int charRGBAAssSlice( BPy_charRGBA * self, int begin, int end,
|
||||
PyObject * seq )
|
||||
{
|
||||
int count;
|
||||
|
||||
if( begin < 0 )
|
||||
begin = 0;
|
||||
if( end > 4 )
|
||||
end = 4;
|
||||
if( begin > end )
|
||||
begin = end;
|
||||
|
||||
if( !PySequence_Check( seq ) )
|
||||
return EXPP_ReturnIntError( PyExc_TypeError,
|
||||
"illegal argument type for built-in operation" );
|
||||
|
||||
if( PySequence_Length( seq ) != ( end - begin ) )
|
||||
return EXPP_ReturnIntError( PyExc_TypeError,
|
||||
"size mismatch in slice assignment" );
|
||||
|
||||
for( count = begin; count < end; count++ ) {
|
||||
char value;
|
||||
PyObject *ob = PySequence_GetItem( seq, count );
|
||||
|
||||
if( !PyArg_Parse( ob, "b", &value ) ) {
|
||||
Py_DECREF( ob );
|
||||
return -1;
|
||||
}
|
||||
|
||||
*( self->rgba[count] ) = (char)EXPP_ClampInt( value, 0, 255 );
|
||||
|
||||
Py_DECREF( ob );
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Function: charRGBA_repr */
|
||||
/* Description: This is a callback function for the BPy_charRGBA type. It */
|
||||
/* builds a meaninful string to represent charRGBA objects. */
|
||||
/*****************************************************************************/
|
||||
static PyObject *charRGBA_repr( BPy_charRGBA * self )
|
||||
{
|
||||
char r, g, b, a;
|
||||
|
||||
r = *( self->rgba[0] );
|
||||
g = *( self->rgba[1] );
|
||||
b = *( self->rgba[2] );
|
||||
a = *( self->rgba[3] );
|
||||
|
||||
return PyString_FromFormat( "[%d, %d, %d, %d]", r, g, b, a );
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user