Merged changes to revision 25007.

The following files were according to the Math Lib reorganization
(see the commit log of revision 24464 for more information):
source/blender/freestyle/intern/blender_interface/BlenderFileLoader.cpp
source/blender/freestyle/intern/blender_interface/BlenderFileLoader.h

The file release/scripts/ui/properties_render.py was also updated
according the RNA UI API renaming in revision 24795.
This commit is contained in:
2009-11-30 00:08:30 +00:00
763 changed files with 64835 additions and 49175 deletions

View File

@@ -49,6 +49,7 @@ struct bConstraintTarget; /* DNA_constraint_types.h*/
struct Script; /* DNA_screen_types.h */
struct BPyMenu;
struct bContext;
struct bContextDataResult;
struct ReportList;
#ifdef __cplusplus
@@ -71,74 +72,73 @@ extern "C" {
This is necassary to avoid blender buttons storing invalid pointers to freed
python data.*/
void BPy_Set_DrawButtonsList(void *list);
void BPy_Free_DrawButtonsList(void);
// void BPy_Set_DrawButtonsList(void *list);
// void BPy_Free_DrawButtonsList(void);
//
void BPY_pyconstraint_eval(struct bPythonConstraint *con, struct bConstraintOb *cob, struct ListBase *targets);
void BPY_pyconstraint_settings(void *arg1, void *arg2);
// void BPY_pyconstraint_settings(void *arg1, void *arg2);
void BPY_pyconstraint_target(struct bPythonConstraint *con, struct bConstraintTarget *ct);
void BPY_pyconstraint_update(struct Object *owner, struct bConstraint *con);
int BPY_is_pyconstraint(struct Text *text);
void BPY_free_pyconstraint_links(struct Text *text);
// void BPY_free_pyconstraint_links(struct Text *text);
//
void BPY_start_python( int argc, char **argv );
void BPY_end_python( void );
void BPY_post_start_python( void );
void init_syspath( int first_time );
void syspath_append( char *dir );
void BPY_rebuild_syspath( void );
int BPY_path_update( void );
int BPY_Err_getLinenumber( void );
const char *BPY_Err_getFilename( void );
int BPY_txt_do_python_Text( struct Text *text );
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 init_syspath( int first_time );
// void syspath_append( char *dir );
// void BPY_rebuild_syspath( void );
// int BPY_path_update( void );
//
// int BPY_Err_getLinenumber( void );
// const char *BPY_Err_getFilename( void );
//
// int BPY_txt_do_python_Text( struct Text *text );
// 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 );
/* 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);
//
int BPY_context_get(struct bContext *C, const char *member, struct bContextDataResult *result);
//
// int BPY_run_script(struct Script *script);
void BPY_free_compiled_text( struct Text *text );
int BPY_has_onload_script( void );
int BPY_is_spacehandler(struct Text *text, char spacetype);
int BPY_del_spacehandler(struct Text *text, struct ScrArea *sa);
int BPY_add_spacehandler(struct Text *txt, struct ScrArea *sa,char spacetype);
int BPY_has_spacehandler(struct Text *text, struct ScrArea *sa);
void BPY_screen_free_spacehandlers(struct bScreen *sc);
int BPY_do_spacehandlers(struct ScrArea *sa, unsigned short event,
short eventValue, unsigned short space_event);
void BPY_pydriver_update(void);
//
// int BPY_has_onload_script( void );
//
// int BPY_is_spacehandler(struct Text *text, char spacetype);
// int BPY_del_spacehandler(struct Text *text, struct ScrArea *sa);
// int BPY_add_spacehandler(struct Text *txt, struct ScrArea *sa,char spacetype);
// int BPY_has_spacehandler(struct Text *text, struct ScrArea *sa);
// void BPY_screen_free_spacehandlers(struct bScreen *sc);
// int BPY_do_spacehandlers(struct ScrArea *sa, unsigned short event,
// short eventValue, unsigned short space_event);
//
// void BPY_pydriver_update(void);
float BPY_pydriver_eval(struct ChannelDriver *driver);
//
int BPY_button_eval(struct bContext *C, char *expr, double *value);
/* format importer hook */
int BPY_call_importloader( char *name );
void BPY_spacescript_do_pywin_draw( struct SpaceScript *sc );
void BPY_spacescript_do_pywin_event( struct SpaceScript *sc,
unsigned short event, short val, char ascii );
void BPY_clear_script( struct Script *script );
void BPY_free_finished_script( struct Script *script );
void BPY_scripts_clear_pyobjects( void );
void error_pyscript( void );
void BPY_DECREF(void *pyob_ptr); /* Py_DECREF() */
//
// void BPY_spacescript_do_pywin_draw( struct SpaceScript *sc );
// void BPY_spacescript_do_pywin_event( struct SpaceScript *sc,
// unsigned short event, short val, char ascii );
// void BPY_clear_script( struct Script *script );
// void BPY_free_finished_script( struct Script *script );
// void BPY_scripts_clear_pyobjects( void );
//
// void error_pyscript( void );
// void BPY_DECREF(void *pyob_ptr); /* Py_DECREF() */
void BPY_set_context(struct bContext *C);
/* void BPY_Err_Handle(struct Text *text); */
/* int BPY_spacetext_is_pywin(struct SpaceText *st); */
void BPY_load_user_modules(struct bContext *C);
#ifdef __cplusplus
} /* extern "C" */

View File

@@ -194,7 +194,15 @@ def write_func(rna, ident, out, func_type):
if rna_prop_type=='pointer':
rna_prop_type_refine = "L{%s}" % rna_prop.fixed_type.identifier
else:
rna_prop_type_refine = rna_prop_type
# Collections/Arrays can have a srna type
rna_prop_srna_type = rna_prop.srna
if rna_prop_srna_type:
print(rna_prop_srna_type.identifier)
rna_prop_type_refine = "L{%s}" % rna_prop_srna_type.identifier
else:
rna_prop_type_refine = rna_prop_type
del rna_prop_srna_type
try: length = rna_prop.array_length
@@ -373,6 +381,13 @@ def rna2epy(BASEPATH):
if rna_prop_type=='collection': collection_str = 'Collection of '
else: collection_str = ''
# some collections have a srna for their own properties
# TODO - arrays, however this isnt used yet
rna_prop_srna_type = rna_prop.srna
if rna_prop_srna_type:
collection_str = "L{%s} %s" % (rna_prop_srna_type.identifier, collection_str)
del rna_prop_srna_type
try: rna_prop_ptr = rna_prop.fixed_type
except: rna_prop_ptr = None
@@ -530,12 +545,11 @@ def rna2epy(BASEPATH):
if rna_id_ignore(rna_prop_identifier): continue
if rna_prop_identifier in rna_base_prop_keys: continue
try: rna_prop_ptr = rna_prop.fixed_type
except: rna_prop_ptr = None
# Does this property point to me?
if rna_prop_ptr:
rna_references_dict[rna_prop_ptr.identifier].append( "%s.%s" % (rna_struct_path, rna_prop_identifier) )
for rna_prop_ptr in (getattr(rna_prop, "fixed_type", None), getattr(rna_prop, "srna", None)):
# Does this property point to me?
if rna_prop_ptr:
rna_references_dict[rna_prop_ptr.identifier].append( "%s.%s" % (rna_struct_path, rna_prop_identifier) )
for rna_func in rna_struct.functions:
for rna_prop_identifier, rna_prop in rna_func.parameters.items():

View File

@@ -30,7 +30,7 @@
#include "Geometry.h"
/* - Not needed for now though other geometry functions will probably need them
#include "BLI_arithb.h"
#include "BLI_math.h"
#include "BKE_utildefines.h"
*/
@@ -42,10 +42,10 @@
#include "BKE_utildefines.h"
#include "BKE_curve.h"
#include "BLI_boxpack2d.h"
#include "BLI_arithb.h"
#include "BLI_math.h"
#define SWAP_FLOAT(a,b,tmp) tmp=a; a=b; b=tmp
#define eul 0.000001
#define eps 0.000001
/*-- forward declarations -- */
static PyObject *M_Geometry_PolyFill( PyObject * self, PyObject * polyLineSeq );
@@ -252,18 +252,18 @@ static PyObject *M_Geometry_LineIntersect2D( PyObject * self, PyObject * args )
Py_RETURN_NONE;
}
/* Make sure the hoz/vert line comes first. */
if (fabs(b1x - b2x) < eul || fabs(b1y - b2y) < eul) {
if (fabs(b1x - b2x) < eps || fabs(b1y - b2y) < eps) {
SWAP_FLOAT(a1x, b1x, xi); /*abuse xi*/
SWAP_FLOAT(a1y, b1y, xi);
SWAP_FLOAT(a2x, b2x, xi);
SWAP_FLOAT(a2y, b2y, xi);
}
if (fabs(a1x-a2x) < eul) { /* verticle line */
if (fabs(b1x-b2x) < eul){ /*verticle second line */
if (fabs(a1x-a2x) < eps) { /* verticle line */
if (fabs(b1x-b2x) < eps){ /*verticle second line */
Py_RETURN_NONE; /* 2 verticle lines dont intersect. */
}
else if (fabs(b1y-b2y) < eul) {
else if (fabs(b1y-b2y) < eps) {
/*X of vert, Y of hoz. no calculation needed */
newvec[0]= a1x;
newvec[1]= b1y;
@@ -280,8 +280,8 @@ static PyObject *M_Geometry_LineIntersect2D( PyObject * self, PyObject * args )
newvec[0]= a1x;
newvec[1]= yi;
return newVectorObject(newvec, 2, Py_NEW, NULL);
} else if (fabs(a2y-a1y) < eul) { /* hoz line1 */
if (fabs(b2y-b1y) < eul) { /*hoz line2*/
} else if (fabs(a2y-a1y) < eps) { /* hoz line1 */
if (fabs(b2y-b1y) < eps) { /*hoz line2*/
Py_RETURN_NONE; /*2 hoz lines dont intersect*/
}
@@ -346,7 +346,7 @@ static PyObject *M_Geometry_ClosestPointOnLine( PyObject * self, PyObject * args
else { l2[2]=0.0; VECCOPY2D(l2, line_2->vec) }
/* do the calculation */
lambda = lambda_cp_line_ex(pt_in, l1, l2, pt_out);
lambda = closest_to_line_v3( pt_out,pt_in, l1, l2);
ret = PyTuple_New(2);
PyTuple_SET_ITEM( ret, 0, newVectorObject(pt_out, 3, Py_NEW, NULL) );
@@ -371,7 +371,7 @@ static PyObject *M_Geometry_PointInTriangle2D( PyObject * self, PyObject * args
if(!BaseMath_ReadCallback(pt_vec) || !BaseMath_ReadCallback(tri_p1) || !BaseMath_ReadCallback(tri_p2) || !BaseMath_ReadCallback(tri_p3))
return NULL;
return PyLong_FromLong(IsectPT2Df(pt_vec->vec, tri_p1->vec, tri_p2->vec, tri_p3->vec));
return PyLong_FromLong(isect_point_tri_v2(pt_vec->vec, tri_p1->vec, tri_p2->vec, tri_p3->vec));
}
static PyObject *M_Geometry_PointInQuad2D( PyObject * self, PyObject * args )
@@ -392,7 +392,7 @@ static PyObject *M_Geometry_PointInQuad2D( PyObject * self, PyObject * args )
if(!BaseMath_ReadCallback(pt_vec) || !BaseMath_ReadCallback(quad_p1) || !BaseMath_ReadCallback(quad_p2) || !BaseMath_ReadCallback(quad_p3) || !BaseMath_ReadCallback(quad_p4))
return NULL;
return PyLong_FromLong(IsectPQ2Df(pt_vec->vec, quad_p1->vec, quad_p2->vec, quad_p3->vec, quad_p4->vec));
return PyLong_FromLong(isect_point_quad_v2(pt_vec->vec, quad_p1->vec, quad_p2->vec, quad_p3->vec, quad_p4->vec));
}
static int boxPack_FromPyObject(PyObject * value, boxPack **boxarray )

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,64 @@
/**
* $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.
*
* Contributor(s): Joseph Eagar, Campbell Barton
*
* ***** 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);
PyObject *BPy_Wrap_GetKeys(IDProperty *prop);
PyObject *BPy_Wrap_GetValues(ID *id, IDProperty *prop);
PyObject *BPy_Wrap_GetItems(ID *id, IDProperty *prop);
int BPy_Wrap_SetMapItem(IDProperty *prop, PyObject *key, PyObject *val);
PyObject *BPy_IDGroup_WrapData( ID *id, IDProperty *prop );
char *BPy_IDProperty_Map_ValidateAndCreate(char *name, IDProperty *group, PyObject *ob);
void IDProp_Init_Types(void);
#define IDPROP_ITER_KEYS 0
#define IDPROP_ITER_ITEMS 1

View File

@@ -29,7 +29,7 @@
#include "Mathutils.h"
#include "BLI_arithb.h"
#include "BLI_math.h"
#include "PIL_time.h"
#include "BLI_rand.h"
#include "BKE_utildefines.h"
@@ -437,7 +437,7 @@ static PyObject *M_Mathutils_RotationMatrix(PyObject * self, PyObject * args)
mat[8] = 1.0f;
} else if((strcmp(axis, "r") == 0) || (strcmp(axis, "R") == 0)) {
//arbitrary rotation
AxisAngleToMat3(vec->vec, angle, (float (*)[3])mat);
axis_angle_to_mat3( (float (*)[3])mat,vec->vec, angle);
} else {
PyErr_SetString(PyExc_AttributeError, "Mathutils.RotationMatrix(): unrecognizable axis of rotation type - expected x,y,z or r\n");
@@ -477,7 +477,7 @@ static PyObject *M_Mathutils_TranslationMatrix(PyObject * self, VectorObject * v
return NULL;
//create a identity matrix and add translation
Mat4One((float(*)[4]) mat);
unit_m4((float(*)[4]) mat);
mat[12] = vec->vec[0];
mat[13] = vec->vec[1];
mat[14] = vec->vec[2];
@@ -762,7 +762,7 @@ static PyObject *M_Mathutils_DifferenceQuats(PyObject * self, PyObject * args)
for(x = 0; x < 4; x++) {
tempQuat[x] /= (float)(dot * dot);
}
QuatMul(quat, tempQuat, quatV->quat);
mul_qt_qtqt(quat, tempQuat, quatV->quat);
return newQuaternionObject(quat, Py_NEW, NULL);
}
//----------------------------------Mathutils.Slerp() ------------------
@@ -853,19 +853,19 @@ static PyObject *M_Mathutils_Intersect( PyObject * self, PyObject * args )
VECCOPY(v3, vec3->vec);
VECCOPY(dir, ray->vec);
Normalize(dir);
normalize_v3(dir);
VECCOPY(orig, ray_off->vec);
/* find vectors for two edges sharing v1 */
VecSubf(e1, v2, v1);
VecSubf(e2, v3, v1);
sub_v3_v3v3(e1, v2, v1);
sub_v3_v3v3(e2, v3, v1);
/* begin calculating determinant - also used to calculated U parameter */
Crossf(pvec, dir, e2);
cross_v3_v3v3(pvec, dir, e2);
/* if determinant is near zero, ray lies in plane of triangle */
det = Inpf(e1, pvec);
det = dot_v3v3(e1, pvec);
if (det > -0.000001 && det < 0.000001) {
Py_RETURN_NONE;
@@ -874,29 +874,29 @@ static PyObject *M_Mathutils_Intersect( PyObject * self, PyObject * args )
inv_det = 1.0f / det;
/* calculate distance from v1 to ray origin */
VecSubf(tvec, orig, v1);
sub_v3_v3v3(tvec, orig, v1);
/* calculate U parameter and test bounds */
u = Inpf(tvec, pvec) * inv_det;
u = dot_v3v3(tvec, pvec) * inv_det;
if (clip && (u < 0.0f || u > 1.0f)) {
Py_RETURN_NONE;
}
/* prepare to test the V parameter */
Crossf(qvec, tvec, e1);
cross_v3_v3v3(qvec, tvec, e1);
/* calculate V parameter and test bounds */
v = Inpf(dir, qvec) * inv_det;
v = dot_v3v3(dir, qvec) * inv_det;
if (clip && (v < 0.0f || u + v > 1.0f)) {
Py_RETURN_NONE;
}
/* calculate t, ray intersects triangle */
t = Inpf(e2, qvec) * inv_det;
t = dot_v3v3(e2, qvec) * inv_det;
VecMulf(dir, t);
VecAddf(pvec, orig, dir);
mul_v3_fl(dir, t);
add_v3_v3v3(pvec, orig, dir);
return newVectorObject(pvec, 3, Py_NEW, NULL);
}
@@ -947,7 +947,7 @@ static PyObject *M_Mathutils_LineIntersect( PyObject * self, PyObject * args )
v4[2] = 0.0f;
}
result = LineIntersectLine(v1, v2, v3, v4, i1, i2);
result = isect_line_line_v3(v1, v2, v3, v4, i1, i2);
if (result == 0) {
/* colinear */
@@ -1000,22 +1000,22 @@ static PyObject *M_Mathutils_QuadNormal( PyObject * self, PyObject * args )
VECCOPY(v4, vec4->vec);
/* find vectors for two edges sharing v2 */
VecSubf(e1, v1, v2);
VecSubf(e2, v3, v2);
sub_v3_v3v3(e1, v1, v2);
sub_v3_v3v3(e2, v3, v2);
Crossf(n1, e2, e1);
Normalize(n1);
cross_v3_v3v3(n1, e2, e1);
normalize_v3(n1);
/* find vectors for two edges sharing v4 */
VecSubf(e1, v3, v4);
VecSubf(e2, v1, v4);
sub_v3_v3v3(e1, v3, v4);
sub_v3_v3v3(e2, v1, v4);
Crossf(n2, e2, e1);
Normalize(n2);
cross_v3_v3v3(n2, e2, e1);
normalize_v3(n2);
/* adding and averaging the normals of both triangles */
VecAddf(n1, n2, n1);
Normalize(n1);
add_v3_v3v3(n1, n2, n1);
normalize_v3(n1);
return newVectorObject(n1, 3, Py_NEW, NULL);
}
@@ -1047,11 +1047,11 @@ static PyObject *M_Mathutils_TriangleNormal( PyObject * self, PyObject * args )
VECCOPY(v3, vec3->vec);
/* find vectors for two edges sharing v2 */
VecSubf(e1, v1, v2);
VecSubf(e2, v3, v2);
sub_v3_v3v3(e1, v1, v2);
sub_v3_v3v3(e2, v3, v2);
Crossf(n, e2, e1);
Normalize(n);
cross_v3_v3v3(n, e2, e1);
normalize_v3(n);
return newVectorObject(n, 3, Py_NEW, NULL);
}
@@ -1082,7 +1082,7 @@ static PyObject *M_Mathutils_TriangleArea( PyObject * self, PyObject * args )
VECCOPY(v2, vec2->vec);
VECCOPY(v3, vec3->vec);
return PyFloat_FromDouble( AreaT3Dfl(v1, v2, v3) );
return PyFloat_FromDouble( area_tri_v3(v1, v2, v3) );
}
else if (vec1->size == 2) {
v1[0] = vec1->vec[0];
@@ -1094,7 +1094,7 @@ static PyObject *M_Mathutils_TriangleArea( PyObject * self, PyObject * args )
v3[0] = vec3->vec[0];
v3[1] = vec3->vec[1];
return PyFloat_FromDouble( AreaF2Dfl(v1, v2, v3) );
return PyFloat_FromDouble( area_tri_v2(v1, v2, v3) );
}
else {
PyErr_SetString( PyExc_TypeError, "only 2D,3D vectors are supported\n" );

View File

@@ -54,12 +54,35 @@ void bpy_import_main_set(struct Main *maggie)
bpy_import_main= maggie;
}
PyObject *bpy_text_import( Text *text )
{
char *buf = NULL;
char modulename[24];
int len;
PyObject *bpy_text_import( char *name, int *found )
if( !text->compiled ) {
buf = txt_to_buf( text );
text->compiled = Py_CompileString( buf, text->id.name+2, Py_file_input );
MEM_freeN( buf );
if( PyErr_Occurred( ) ) {
PyErr_Print( );
PyErr_Clear( );
PySys_SetObject("last_traceback", NULL);
free_compiled_text( text );
return NULL;
}
}
len= strlen(text->id.name+2) - 3;
strncpy(modulename, text->id.name+2, len);
return PyImport_ExecCodeModule(modulename, text->compiled);
}
PyObject *bpy_text_import_name( char *name, int *found )
{
Text *text;
char txtname[22]; /* 21+NULL */
char *buf = NULL;
int namelen = strlen( name );
//XXX Main *maggie= bpy_import_main ? bpy_import_main:G.main;
Main *maggie= bpy_import_main;
@@ -86,21 +109,7 @@ PyObject *bpy_text_import( char *name, int *found )
else
*found = 1;
if( !text->compiled ) {
buf = txt_to_buf( text );
text->compiled = Py_CompileString( buf, text->id.name+2, Py_file_input );
MEM_freeN( buf );
if( PyErr_Occurred( ) ) {
PyErr_Print( );
PyErr_Clear( );
PySys_SetObject("last_traceback", NULL);
free_compiled_text( text );
return NULL;
}
}
return PyImport_ExecCodeModule( name, text->compiled );
return bpy_text_import(text);
}
@@ -195,7 +204,7 @@ static PyObject *blender_import( PyObject * self, PyObject * args, PyObject * k
PyErr_Fetch( &exception, &err, &tb ); /* get the python error incase we cant import as blender text either */
/* importing from existing modules failed, see if we have this module as blender text */
newmodule = bpy_text_import( name, &found );
newmodule = bpy_text_import_name( name, &found );
if( newmodule ) {/* found module as blender text, ignore above exception */
PyErr_Clear( );

View File

@@ -44,7 +44,10 @@
#include "compile.h" /* for the PyCodeObject */
#include "eval.h" /* for PyEval_EvalCode */
PyObject* bpy_text_import( char *name, int *found );
struct Text;
PyObject* bpy_text_import( struct Text *text );
PyObject* bpy_text_import_name( char *name, int *found );
PyObject* bpy_text_reimport( PyObject *module, int *found );
/* void bpy_text_clear_modules( int clear_all );*/ /* Clear user modules */
extern PyMethodDef bpy_import_meth[];

View File

@@ -28,7 +28,7 @@
#include "Mathutils.h"
#include "BLI_arithb.h"
#include "BLI_math.h"
#include "BKE_utildefines.h"
#include "BLI_blenlib.h"
@@ -123,9 +123,9 @@ static PyObject *Euler_ToQuat(EulerObject * self)
for(x = 0; x < 3; x++) {
eul[x] = self->eul[x] * ((float)Py_PI / 180);
}
EulToQuat(eul, quat);
eul_to_quat( quat,eul);
#else
EulToQuat(self->eul, quat);
eul_to_quat( quat,self->eul);
#endif
return newQuaternionObject(quat, Py_NEW, NULL);
@@ -147,10 +147,10 @@ static PyObject *Euler_ToMatrix(EulerObject * self)
for(x = 0; x < 3; x++) {
eul[x] = self->eul[x] * ((float)Py_PI / 180);
}
EulToMat3(eul, (float (*)[3]) mat);
eul_to_mat3( (float (*)[3]) mat,eul);
}
#else
EulToMat3(self->eul, (float (*)[3]) mat);
eul_to_mat3( (float (*)[3]) mat,self->eul);
#endif
return newMatrixObject(mat, 3, 3 , Py_NEW, NULL);
}
@@ -261,7 +261,7 @@ static PyObject *Euler_Rotate(EulerObject * self, PyObject *args)
}
}
#endif
euler_rot(self->eul, angle, *axis);
rotate_eul(self->eul, *axis, angle);
#ifdef USE_MATHUTILS_DEG
{

View File

@@ -28,7 +28,7 @@
#include "Mathutils.h"
#include "BKE_utildefines.h"
#include "BLI_arithb.h"
#include "BLI_math.h"
#include "BLI_blenlib.h"
static PyObject *column_vector_multiplication(MatrixObject * mat, VectorObject* vec); /* utility func */
@@ -229,9 +229,9 @@ static PyObject *Matrix_toQuat(MatrixObject * self)
return NULL;
}
if(self->colSize == 3){
Mat3ToQuat((float (*)[3])*self->matrix, quat);
mat3_to_quat( quat,(float (*)[3])*self->matrix);
}else{
Mat4ToQuat((float (*)[4])*self->matrix, quat);
mat4_to_quat( quat,(float (*)[4])*self->matrix);
}
return newQuaternionObject(quat, Py_NEW, NULL);
@@ -266,14 +266,14 @@ PyObject *Matrix_toEuler(MatrixObject * self, PyObject *args)
/*must be 3-4 cols, 3-4 rows, square matrix*/
if(self->colSize ==3 && self->rowSize ==3) {
if(eul_compat) Mat3ToCompatibleEul((float (*)[3])*self->matrix, eul, eul_compatf);
else Mat3ToEul((float (*)[3])*self->matrix, eul);
if(eul_compat) mat3_to_compatible_eul( eul, eul_compatf,(float (*)[3])*self->matrix);
else mat3_to_eul( eul,(float (*)[3])*self->matrix);
}else if (self->colSize ==4 && self->rowSize ==4) {
float tempmat3[3][3];
Mat3CpyMat4(tempmat3, (float (*)[4])*self->matrix);
Mat3ToEul(tempmat3, eul);
if(eul_compat) Mat3ToCompatibleEul(tempmat3, eul, eul_compatf);
else Mat3ToEul(tempmat3, eul);
copy_m3_m4(tempmat3, (float (*)[4])*self->matrix);
mat3_to_eul( eul,tempmat3);
if(eul_compat) mat3_to_compatible_eul( eul, eul_compatf,tempmat3);
else mat3_to_eul( eul,tempmat3);
}else {
PyErr_SetString(PyExc_AttributeError, "Matrix.toEuler(): inappropriate matrix size - expects 3x3 or 4x4 matrix\n");
@@ -400,18 +400,18 @@ PyObject *Matrix_scalePart(MatrixObject * self)
/*must be 3-4 cols, 3-4 rows, square matrix*/
if(self->colSize == 4 && self->rowSize == 4)
Mat3CpyMat4(mat, (float (*)[4])*self->matrix);
copy_m3_m4(mat, (float (*)[4])*self->matrix);
else if(self->colSize == 3 && self->rowSize == 3)
Mat3CpyMat3(mat, (float (*)[3])*self->matrix);
copy_m3_m3(mat, (float (*)[3])*self->matrix);
else {
PyErr_SetString(PyExc_AttributeError, "Matrix.scalePart(): inappropriate matrix size - expects 3x3 or 4x4 matrix\n");
return NULL;
}
/* functionality copied from editobject.c apply_obmat */
Mat3ToEul(mat, rot);
EulToMat3(rot, tmat);
Mat3Inv(imat, tmat);
Mat3MulMat3(tmat, imat, mat);
mat3_to_eul( rot,mat);
eul_to_mat3( tmat,rot);
invert_m3_m3(imat, tmat);
mul_m3_m3m3(tmat, imat, mat);
scale[0]= tmat[0][0];
scale[1]= tmat[1][1];
@@ -449,9 +449,9 @@ PyObject *Matrix_Invert(MatrixObject * self)
mat[2] = -self->matrix[1][0];
mat[3] = self->matrix[0][0];
} else if(self->rowSize == 3) {
Mat3Adj((float (*)[3]) mat,(float (*)[3]) *self->matrix);
adjoint_m3_m3((float (*)[3]) mat,(float (*)[3]) *self->matrix);
} else if(self->rowSize == 4) {
Mat4Adj((float (*)[4]) mat, (float (*)[4]) *self->matrix);
adjoint_m4_m4((float (*)[4]) mat, (float (*)[4]) *self->matrix);
}
/*divide by determinate*/
for(x = 0; x < (self->rowSize * self->colSize); x++) {
@@ -491,16 +491,16 @@ PyObject *Matrix_Determinant(MatrixObject * self)
}
if(self->rowSize == 2) {
det = Det2x2(self->matrix[0][0], self->matrix[0][1],
det = determinant_m2(self->matrix[0][0], self->matrix[0][1],
self->matrix[1][0], self->matrix[1][1]);
} else if(self->rowSize == 3) {
det = Det3x3(self->matrix[0][0], self->matrix[0][1],
det = determinant_m3(self->matrix[0][0], self->matrix[0][1],
self->matrix[0][2], self->matrix[1][0],
self->matrix[1][1], self->matrix[1][2],
self->matrix[2][0], self->matrix[2][1],
self->matrix[2][2]);
} else {
det = Det4x4((float (*)[4]) *self->matrix);
det = determinant_m4((float (*)[4]) *self->matrix);
}
return PyFloat_FromDouble( (double) det );
@@ -523,9 +523,9 @@ PyObject *Matrix_Transpose(MatrixObject * self)
self->matrix[1][0] = self->matrix[0][1];
self->matrix[0][1] = t;
} else if(self->rowSize == 3) {
Mat3Transp((float (*)[3])*self->matrix);
transpose_m3((float (*)[3])*self->matrix);
} else {
Mat4Transp((float (*)[4])*self->matrix);
transpose_m4((float (*)[4])*self->matrix);
}
BaseMath_WriteCallback(self);
@@ -568,9 +568,9 @@ PyObject *Matrix_Identity(MatrixObject * self)
self->matrix[1][0] = 0.0f;
self->matrix[1][1] = 1.0f;
} else if(self->rowSize == 3) {
Mat3One((float (*)[3]) *self->matrix);
unit_m3((float (*)[3]) *self->matrix);
} else {
Mat4One((float (*)[4]) *self->matrix);
unit_m4((float (*)[4]) *self->matrix);
}
if(!BaseMath_WriteCallback(self))

View File

@@ -28,7 +28,7 @@
#include "Mathutils.h"
#include "BLI_arithb.h"
#include "BLI_math.h"
#include "BKE_utildefines.h"
#include "BLI_blenlib.h"
@@ -152,9 +152,9 @@ static PyObject *Quaternion_new(PyTypeObject *type, PyObject *args, PyObject *kw
if(size == 3) //calculate the quat based on axis/angle
#ifdef USE_MATHUTILS_DEG
AxisAngleToQuat(quat, quat, angle * (Py_PI / 180));
axis_angle_to_quat(quat, quat, angle * (Py_PI / 180));
#else
AxisAngleToQuat(quat, quat, angle);
axis_angle_to_quat(quat, quat, angle);
#endif
return newQuaternionObject(quat, Py_NEW, NULL);
@@ -180,7 +180,7 @@ static PyObject *Quaternion_ToEuler(QuaternionObject * self, PyObject *args)
if(!BaseMath_ReadCallback(eul_compat))
return NULL;
QuatToMat3(self->quat, mat);
quat_to_mat3( mat,self->quat);
#ifdef USE_MATHUTILS_DEG
{
@@ -190,14 +190,14 @@ static PyObject *Quaternion_ToEuler(QuaternionObject * self, PyObject *args)
for(x = 0; x < 3; x++) {
eul_compatf[x] = eul_compat->eul[x] * ((float)Py_PI / 180);
}
Mat3ToCompatibleEul(mat, eul, eul_compatf);
mat3_to_compatible_eul( eul, eul_compatf,mat);
}
#else
Mat3ToCompatibleEul(mat, eul, eul_compat->eul);
mat3_to_compatible_eul( eul, eul_compat->eul,mat);
#endif
}
else {
QuatToEul(self->quat, eul);
quat_to_eul( eul,self->quat);
}
#ifdef USE_MATHUTILS_DEG
@@ -220,7 +220,7 @@ static PyObject *Quaternion_ToMatrix(QuaternionObject * self)
if(!BaseMath_ReadCallback(self))
return NULL;
QuatToMat3(self->quat, (float (*)[3]) mat);
quat_to_mat3( (float (*)[3]) mat,self->quat);
return newMatrixObject(mat, 3, 3, Py_NEW, NULL);
}
@@ -238,7 +238,7 @@ static PyObject *Quaternion_Cross(QuaternionObject * self, QuaternionObject * va
if(!BaseMath_ReadCallback(self) || !BaseMath_ReadCallback(value))
return NULL;
QuatMul(quat, self->quat, value->quat);
mul_qt_qtqt(quat, self->quat, value->quat);
return newQuaternionObject(quat, Py_NEW, NULL);
}
@@ -254,7 +254,7 @@ static PyObject *Quaternion_Dot(QuaternionObject * self, QuaternionObject * valu
if(!BaseMath_ReadCallback(self) || !BaseMath_ReadCallback(value))
return NULL;
return PyFloat_FromDouble(QuatDot(self->quat, value->quat));
return PyFloat_FromDouble(dot_qtqt(self->quat, value->quat));
}
//----------------------------Quaternion.normalize()----------------
@@ -264,7 +264,7 @@ static PyObject *Quaternion_Normalize(QuaternionObject * self)
if(!BaseMath_ReadCallback(self))
return NULL;
NormalQuat(self->quat);
normalize_qt(self->quat);
BaseMath_WriteCallback(self);
Py_INCREF(self);
@@ -277,7 +277,7 @@ static PyObject *Quaternion_Inverse(QuaternionObject * self)
if(!BaseMath_ReadCallback(self))
return NULL;
QuatInv(self->quat);
invert_qt(self->quat);
BaseMath_WriteCallback(self);
Py_INCREF(self);
@@ -290,7 +290,7 @@ static PyObject *Quaternion_Identity(QuaternionObject * self)
if(!BaseMath_ReadCallback(self))
return NULL;
QuatOne(self->quat);
unit_qt(self->quat);
BaseMath_WriteCallback(self);
Py_INCREF(self);
@@ -303,7 +303,7 @@ static PyObject *Quaternion_Negate(QuaternionObject * self)
if(!BaseMath_ReadCallback(self))
return NULL;
QuatMulf(self->quat, -1.0f);
mul_qt_fl(self->quat, -1.0f);
BaseMath_WriteCallback(self);
Py_INCREF(self);
@@ -316,7 +316,7 @@ static PyObject *Quaternion_Conjugate(QuaternionObject * self)
if(!BaseMath_ReadCallback(self))
return NULL;
QuatConj(self->quat);
conjugate_qt(self->quat);
BaseMath_WriteCallback(self);
Py_INCREF(self);
@@ -525,7 +525,7 @@ static PyObject *Quaternion_add(PyObject * q1, PyObject * q2)
if(!BaseMath_ReadCallback(quat1) || !BaseMath_ReadCallback(quat2))
return NULL;
QuatAdd(quat, quat1->quat, quat2->quat, 1.0f);
add_qt_qtqt(quat, quat1->quat, quat2->quat, 1.0f);
return newQuaternionObject(quat, Py_NEW, NULL);
}
//------------------------obj - obj------------------------------
@@ -573,7 +573,7 @@ static PyObject *Quaternion_mul(PyObject * q1, PyObject * q2)
}
if(quat1 && quat2) { /* QUAT*QUAT (dot product) */
return PyFloat_FromDouble(QuatDot(quat1->quat, quat2->quat));
return PyFloat_FromDouble(dot_qtqt(quat1->quat, quat2->quat));
}
/* the only case this can happen (for a supported type is "FLOAT*QUAT" ) */
@@ -581,7 +581,7 @@ static PyObject *Quaternion_mul(PyObject * q1, PyObject * q2)
scalar= PyFloat_AsDouble(q1);
if ((scalar == -1.0 && PyErr_Occurred())==0) { /* FLOAT*QUAT */
QUATCOPY(quat, quat2->quat);
QuatMulf(quat, scalar);
mul_qt_fl(quat, scalar);
return newQuaternionObject(quat, Py_NEW, NULL);
}
PyErr_SetString(PyExc_TypeError, "Quaternion multiplication: val * quat, val is not an acceptable type");
@@ -600,7 +600,7 @@ static PyObject *Quaternion_mul(PyObject * q1, PyObject * q2)
scalar= PyFloat_AsDouble(q2);
if ((scalar == -1.0 && PyErr_Occurred())==0) { /* QUAT*FLOAT */
QUATCOPY(quat, quat1->quat);
QuatMulf(quat, scalar);
mul_qt_fl(quat, scalar);
return newQuaternionObject(quat, Py_NEW, NULL);
}
}
@@ -669,7 +669,7 @@ static int Quaternion_setAxis( QuaternionObject * self, PyObject * value, void *
static PyObject *Quaternion_getMagnitude( QuaternionObject * self, void *type )
{
return PyFloat_FromDouble(sqrt(QuatDot(self->quat, self->quat)));
return PyFloat_FromDouble(sqrt(dot_qtqt(self->quat, self->quat)));
}
static PyObject *Quaternion_getAngle( QuaternionObject * self, void *type )
@@ -692,7 +692,7 @@ static PyObject *Quaternion_getAxisVec( QuaternionObject * self, void *type )
for(i = 0; i < 3; i++)
vec[i] = (float)(self->quat[i + 1] / mag);
Normalize(vec);
normalize_v3(vec);
//If the axis of rotation is 0,0,0 set it to 1,0,0 - for zero-degree rotations
if( EXPP_FloatsAreEqual(vec[0], 0.0f, 10) &&
EXPP_FloatsAreEqual(vec[1], 0.0f, 10) &&
@@ -820,7 +820,7 @@ PyObject *newQuaternionObject(float *quat, int type, PyTypeObject *base_type)
}else if (type == Py_NEW){
self->quat = PyMem_Malloc(4 * sizeof(float));
if(!quat) { //new empty
QuatOne(self->quat);
unit_qt(self->quat);
}else{
QUATCOPY(self->quat, quat);
}

View File

@@ -29,7 +29,7 @@
#include "BLI_blenlib.h"
#include "BKE_utildefines.h"
#include "BLI_arithb.h"
#include "BLI_math.h"
#define MAX_DIMENSIONS 4
/* Swizzle axes get packed into a single value that is used as a closure. Each
@@ -347,7 +347,7 @@ static PyObject *Vector_ToTrackQuat( VectorObject * self, PyObject * args )
vec[1] = -self->vec[1];
vec[2] = -self->vec[2];
vectoquat(vec, track, up, quat);
vec_to_quat( quat,vec, track, up);
return newQuaternionObject(quat, Py_NEW, NULL);
}
@@ -379,7 +379,7 @@ static PyObject *Vector_Reflect( VectorObject * self, VectorObject * value )
if (self->size > 2) vec[2] = self->vec[2];
else vec[2] = 0.0;
VecReflect(reflect, vec, mirror);
reflect_v3_v3v3(reflect, vec, mirror);
return newVectorObject(reflect, self->size, Py_NEW, NULL);
}
@@ -402,7 +402,7 @@ static PyObject *Vector_Cross( VectorObject * self, VectorObject * value )
return NULL;
vecCross = (VectorObject *)newVectorObject(NULL, 3, Py_NEW, NULL);
Crossf(vecCross->vec, self->vec, value->vec);
cross_v3_v3v3(vecCross->vec, self->vec, value->vec);
return (PyObject *)vecCross;
}
@@ -626,36 +626,30 @@ static PyObject *Vector_add(PyObject * v1, PyObject * v2)
static PyObject *Vector_iadd(PyObject * v1, PyObject * v2)
{
int i;
VectorObject *vec1 = NULL, *vec2 = NULL;
if (!VectorObject_Check(v1) || !VectorObject_Check(v2)) {
PyErr_SetString(PyExc_AttributeError, "Vector addition: arguments not valid for this operation....\n");
return NULL;
}
vec1 = (VectorObject*)v1;
vec2 = (VectorObject*)v2;
if VectorObject_Check(v1)
vec1= (VectorObject *)v1;
if VectorObject_Check(v2)
vec2= (VectorObject *)v2;
/* make sure v1 is always the vector */
if (vec1 && vec2 ) {
if(!BaseMath_ReadCallback(vec1) || !BaseMath_ReadCallback(vec2))
return NULL;
/*VECTOR + VECTOR*/
if(vec1->size != vec2->size) {
PyErr_SetString(PyExc_AttributeError, "Vector addition: vectors must have the same dimensions for this operation\n");
return NULL;
}
for(i = 0; i < vec1->size; i++) {
vec1->vec[i] += vec2->vec[i];
}
Py_INCREF( v1 );
return v1;
if(vec1->size != vec2->size) {
PyErr_SetString(PyExc_AttributeError, "Vector addition: vectors must have the same dimensions for this operation\n");
return NULL;
}
if(!BaseMath_ReadCallback(vec1) || !BaseMath_ReadCallback(vec2))
return NULL;
for(i = 0; i < vec1->size; i++) {
vec1->vec[i] = vec1->vec[i] + vec2->vec[i];
}
BaseMath_WriteCallback(vec1);
PyErr_SetString(PyExc_AttributeError, "Vector addition: arguments not valid for this operation....\n");
return NULL;
Py_INCREF( v1 );
return v1;
}
/*------------------------obj - obj------------------------------

View File

@@ -64,6 +64,8 @@
#include "BKE_fcurve.h"
#include "BKE_text.h"
#include "BKE_context.h"
#include "BKE_global.h"
#include "BKE_main.h"
#include "BPY_extern.h"
@@ -75,6 +77,7 @@
#include "../generic/Mathutils.h"
#include "../generic/Geometry.h"
#include "../generic/BGL.h"
#include "../generic/IDProp.h"
/* for internal use, when starting and ending python scripts */
@@ -177,7 +180,7 @@ static BPy_StructRNA *bpy_context_module= NULL; /* for fast access */
static void bpy_init_modules( void )
{
PyObject *mod;
/* Needs to be first since this dir is needed for future modules */
char *modpath= BLI_gethome_folder("scripts/modules", BLI_GETHOME_ALL);
if(modpath) {
@@ -187,10 +190,18 @@ static void bpy_init_modules( void )
Py_DECREF(py_modpath);
}
mod = PyModule_New("bpy");
/* stand alone utility modules not related to blender directly */
Geometry_Init();
Mathutils_Init();
BGL_Init();
IDProp_Init_Types();
Freestyle_Init();
mod = PyModule_New("_bpy");
/* add the module so we can import it */
PyDict_SetItemString(PySys_GetObject("modules"), "bpy", mod);
PyDict_SetItemString(PySys_GetObject("modules"), "_bpy", mod);
Py_DECREF(mod);
/* run first, initializes rna types */
@@ -202,7 +213,7 @@ static void bpy_init_modules( void )
bpy_import_test("bpy_types");
/* PyModule_AddObject( mod, "doc", BPY_rna_doc() ); */
PyModule_AddObject( mod, "props", BPY_rna_props() );
PyModule_AddObject( mod, "__ops__", BPY_operator_module() ); /* ops is now a python module that does the conversion from SOME_OT_foo -> some.foo */
PyModule_AddObject( mod, "ops", BPY_operator_module() ); /* ops is now a python module that does the conversion from SOME_OT_foo -> some.foo */
PyModule_AddObject( mod, "ui", BPY_ui_module() ); // XXX very experimental, consider this a test, especially PyCObject is not meant to be permanent
@@ -215,17 +226,8 @@ static void bpy_init_modules( void )
PyModule_AddObject(mod, "context", (PyObject *)bpy_context_module);
}
/* stand alone utility modules not related to blender directly */
Geometry_Init();
Mathutils_Init();
BGL_Init();
Freestyle_Init();
/* add our own modules dir */
{
bpy_import_test("bpy_ops"); /* adds its self to bpy.ops */
bpy_import_test("bpy_utils"); /* adds its self to bpy.sys */
}
/* add our own modules dir, this is a python package */
bpy_import_test("bpy");
}
void BPY_update_modules( void )
@@ -244,34 +246,24 @@ void BPY_update_modules( void )
/*****************************************************************************
* Description: This function creates a new Python dictionary object.
*****************************************************************************/
static PyObject *CreateGlobalDictionary( bContext *C )
static PyObject *CreateGlobalDictionary( bContext *C, const char *filename )
{
PyObject *mod;
PyObject *item;
PyObject *dict = PyDict_New( );
PyObject *item = PyUnicode_FromString( "__main__" );
PyDict_SetItemString( dict, "__builtins__", PyEval_GetBuiltins( ) );
item = PyUnicode_FromString( "__main__" );
PyDict_SetItemString( dict, "__name__", item );
Py_DECREF(item);
// XXX - put somewhere more logical
{
PyMethodDef *ml;
static PyMethodDef bpy_prop_meths[] = {
{"FloatProperty", (PyCFunction)BPy_FloatProperty, METH_VARARGS|METH_KEYWORDS, ""},
{"IntProperty", (PyCFunction)BPy_IntProperty, METH_VARARGS|METH_KEYWORDS, ""},
{"BoolProperty", (PyCFunction)BPy_BoolProperty, METH_VARARGS|METH_KEYWORDS, ""},
{"StringProperty", (PyCFunction)BPy_StringProperty, METH_VARARGS|METH_KEYWORDS, ""},
{"EnumProperty", (PyCFunction)BPy_EnumProperty, METH_VARARGS|METH_KEYWORDS, ""},
{"PointerProperty", (PyCFunction)BPy_PointerProperty, METH_VARARGS|METH_KEYWORDS, ""},
{"CollectionProperty", (PyCFunction)BPy_CollectionProperty, METH_VARARGS|METH_KEYWORDS, ""},
{NULL, NULL, 0, NULL}
};
for(ml = bpy_prop_meths; ml->ml_name; ml++) {
PyDict_SetItemString( dict, ml->ml_name, PyCFunction_New(ml, NULL));
}
/* __file__ only for nice UI'ness */
if(filename) {
PyObject *item = PyUnicode_FromString( filename );
PyDict_SetItemString( dict, "__file__", item );
Py_DECREF(item);
}
/* add bpy to global namespace */
mod= PyImport_ImportModuleLevel("bpy", NULL, NULL, NULL, 0);
PyDict_SetItemString( dict, "bpy", mod );
@@ -305,6 +297,13 @@ void BPY_start_python_path(void)
}
void BPY_set_context(bContext *C)
{
BPy_SetContext(C);
}
/* call BPY_set_context first */
void BPY_start_python( int argc, char **argv )
{
PyThreadState *py_tstate = NULL;
@@ -340,11 +339,6 @@ void BPY_start_python( int argc, char **argv )
PyObject *d = PyEval_GetBuiltins( );
PyDict_SetItemString(d, "reload", item=PyCFunction_New(bpy_reload_meth, NULL)); Py_DECREF(item);
PyDict_SetItemString(d, "__import__", item=PyCFunction_New(bpy_import_meth, NULL)); Py_DECREF(item);
/* a bit nasty but this prevents help() and input() from locking blender
* Ideally we could have some way for the console to replace sys.stdin but
* python would lock blender while waiting for a return value, not easy :| */
PySys_SetObject("stdin", Py_None);
}
pyrna_alloc_types();
@@ -399,7 +393,7 @@ int BPY_run_python_script( bContext *C, const char *fn, struct Text *text, struc
bpy_context_set(C, &gilstate);
py_dict = CreateGlobalDictionary(C);
py_dict = CreateGlobalDictionary(C, text?text->id.name+2:fn);
if (text) {
@@ -419,24 +413,32 @@ int BPY_run_python_script( bContext *C, const char *fn, struct Text *text, struc
py_result = PyEval_EvalCode( text->compiled, py_dict, py_dict );
} else {
#if 0
char *pystring;
pystring= malloc(strlen(fn) + 32);
pystring[0]= '\0';
sprintf(pystring, "exec(open(r'%s').read())", fn);
py_result = PyRun_String( pystring, Py_file_input, py_dict, py_dict );
free(pystring);
#else
FILE *fp= fopen(fn, "r");
if(fp) {
#ifdef _WIN32
/* Previously we used PyRun_File to run directly the code on a FILE
* object, but as written in the Python/C API Ref Manual, chapter 2,
* 'FILE structs for different C libraries can be different and
* incompatible'.
* So now we load the script file data to a buffer */
char *pystring;
fclose(fp);
pystring= malloc(strlen(fn) + 32);
pystring[0]= '\0';
sprintf(pystring, "exec(open(r'%s').read())", fn);
py_result = PyRun_String( pystring, Py_file_input, py_dict, py_dict );
free(pystring);
#else
py_result = PyRun_File(fp, fn, Py_file_input, py_dict, py_dict);
fclose(fp);
#endif
}
else {
PyErr_Format(PyExc_SystemError, "Python file \"%s\" could not be opened: %s", fn, strerror(errno));
py_result= NULL;
}
#endif
}
if (!py_result) {
@@ -594,117 +596,6 @@ int BPY_run_python_script_space(const char *modulename, const char *func)
#include "PIL_time.h"
#endif
/* for use by BPY_run_ui_scripts only */
static int bpy_import_module(char *modname, int reload)
{
PyObject *mod= PyImport_ImportModuleLevel(modname, NULL, NULL, NULL, 0);
if (mod) {
if (reload) {
PyObject *mod_orig= mod;
mod= PyImport_ReloadModule(mod);
Py_DECREF(mod_orig);
}
}
if(mod) {
Py_DECREF(mod); /* could be NULL from reloading */
return 0;
} else {
return -1;
}
}
/* XXX this is temporary, need a proper script registration system for 2.5 */
void BPY_run_ui_scripts(bContext *C, int reload)
{
#ifdef TIME_REGISTRATION
double time = PIL_check_seconds_timer();
#endif
DIR *dir;
struct dirent *de;
char *file_extension;
char *dirname;
char path[FILE_MAX];
char *dirs[] = {"scripts/ui", "scripts/op", "scripts/io", NULL};
int path_flags[] = {BLI_GETHOME_LOCAL|BLI_GETHOME_SYSTEM, BLI_GETHOME_USER}; /* SYSTEM / NON-SYSTEM */
int a, err, flag_iter;
PyGILState_STATE gilstate;
PyObject *sys_path;
bpy_context_set(C, &gilstate);
sys_path= PySys_GetObject("path"); /* borrow */
PyList_Insert(sys_path, 0, Py_None); /* place holder, resizes the list */
/* Scan system scripts first, then local/user */
for(flag_iter=0; flag_iter < sizeof(path_flags)/sizeof(int); flag_iter++) {
for(a=0; dirs[a]; a++) {
dirname= BLI_gethome_folder(dirs[a], path_flags[flag_iter]);
if(!dirname)
continue;
dir = opendir(dirname);
if(!dir)
continue;
/* set the first dir in the sys.path for fast importing of modules */
PyList_SetItem(sys_path, 0, PyUnicode_FromString(dirname)); /* steals the ref */
while((de = readdir(dir)) != NULL) {
/* We could stat the file but easier just to let python
* import it and complain if theres a problem */
err = 0;
if (de->d_name[0] == '.') {
/* do nothing, probably .svn */
}
else if ((file_extension = strstr(de->d_name, ".py"))) {
/* normal py files? */
if(file_extension && file_extension[3] == '\0') {
de->d_name[(file_extension - de->d_name)] = '\0';
err= bpy_import_module(de->d_name, reload);
}
}
#ifndef __linux__
else if( BLI_join_dirfile(path, dirname, de->d_name), S_ISDIR(BLI_exist(path))) {
#else
else if(de->d_type==DT_DIR) {
BLI_join_dirfile(path, dirname, de->d_name);
#endif
/* support packages */
BLI_join_dirfile(path, path, "__init__.py");
if(BLI_exists(path)) {
err= bpy_import_module(de->d_name, reload);
}
}
if(err==-1) {
BPy_errors_to_report(NULL);
fprintf(stderr, "unable to import %s/%s\n", dirname, de->d_name);
}
}
closedir(dir);
}
}
PyList_SetSlice(sys_path, 0, 1, NULL); /* remove the first item */
bpy_context_clear(C, &gilstate);
#ifdef TIME_REGISTRATION
printf("script time %f\n", (PIL_check_seconds_timer()-time));
#endif
/* reset the timer so as not to take loading into the stats */
bpy_timer_count = 0;
}
/* ****************************************** */
/* Drivers - PyExpression Evaluation */
@@ -911,7 +802,7 @@ int BPY_button_eval(bContext *C, char *expr, double *value)
bpy_context_set(C, &gilstate);
dict= CreateGlobalDictionary(C);
dict= CreateGlobalDictionary(C, NULL);
/* import some modules: builtins,math*/
PyDict_SetItemString(dict, "__builtins__", PyEval_GetBuiltins());
@@ -967,9 +858,30 @@ int BPY_button_eval(bContext *C, char *expr, double *value)
return error_ret;
}
void BPY_load_user_modules(bContext *C)
{
PyGILState_STATE gilstate;
Text *text;
bpy_context_set(C, &gilstate);
int bpy_context_get(bContext *C, const char *member, bContextDataResult *result)
for(text=CTX_data_main(C)->text.first; text; text= text->id.next) {
if(text->flags & TXT_ISSCRIPT && BLI_testextensie(text->id.name+2, ".py")) {
PyObject *module= bpy_text_import(text);
if (module==NULL) {
PyErr_Print();
PyErr_Clear();
}
else {
Py_DECREF(module);
}
}
}
bpy_context_clear(C, &gilstate);
}
int BPY_context_get(bContext *C, const char *member, bContextDataResult *result)
{
PyObject *pyctx= (PyObject *)CTX_py_dict_get(C);
PyObject *item= PyDict_GetItemString(pyctx, member);
@@ -1022,8 +934,11 @@ int bpy_context_get(bContext *C, const char *member, bContextDataResult *result)
}
if(done==0) {
if (item) printf("Context '%s' not found\n", member);
else printf("Context '%s' not a valid type\n", member);
if (item) printf("Context '%s' not a valid type\n", member);
else printf("Context '%s' not found\n", member);
}
else if (G.f & G_DEBUG) {
printf("Context '%s' found\n", member);
}
return done;

View File

@@ -57,13 +57,13 @@ static PyObject *pyop_call( PyObject * self, PyObject * args)
// XXX Todo, work out a better solution for passing on context, could make a tuple from self and pack the name and Context into it...
bContext *C = BPy_GetContext();
if (!PyArg_ParseTuple(args, "sO|O!i:bpy.__ops__.call", &opname, &context_dict, &PyDict_Type, &kw, &context))
if (!PyArg_ParseTuple(args, "sO|O!i:_bpy.ops.call", &opname, &context_dict, &PyDict_Type, &kw, &context))
return NULL;
ot= WM_operatortype_find(opname, TRUE);
if (ot == NULL) {
PyErr_Format( PyExc_SystemError, "bpy.__ops__.call: operator \"%s\"could not be found", opname);
PyErr_Format( PyExc_SystemError, "_bpy.ops.call: operator \"%s\"could not be found", opname);
return NULL;
}
@@ -76,7 +76,7 @@ static PyObject *pyop_call( PyObject * self, PyObject * args)
Py_XINCREF(context_dict); /* so we done loose it */
if(WM_operator_poll((bContext*)C, ot) == FALSE) {
PyErr_SetString( PyExc_SystemError, "bpy.__ops__.call: operator poll() function failed, context is incorrect");
PyErr_Format( PyExc_SystemError, "_bpy.ops.call: operator %.200s.poll() function failed, context is incorrect", opname);
error_val= -1;
}
else {
@@ -153,18 +153,18 @@ static PyObject *pyop_as_string( PyObject * self, PyObject * args)
int all_args = 1;
int error_val= 0;
char *buf;
char *buf = NULL;
PyObject *pybuf;
bContext *C = BPy_GetContext();
if (!PyArg_ParseTuple(args, "s|O!i:bpy.__ops__.as_string", &opname, &PyDict_Type, &kw, &all_args))
if (!PyArg_ParseTuple(args, "s|O!i:_bpy.ops.as_string", &opname, &PyDict_Type, &kw, &all_args))
return NULL;
ot= WM_operatortype_find(opname, TRUE);
if (ot == NULL) {
PyErr_Format( PyExc_SystemError, "bpy.__ops__.as_string: operator \"%s\"could not be found", opname);
PyErr_Format( PyExc_SystemError, "_bpy.ops.as_string: operator \"%s\"could not be found", opname);
return NULL;
}
@@ -217,12 +217,12 @@ static PyObject *pyop_getrna(PyObject *self, PyObject *value)
BPy_StructRNA *pyrna= NULL;
if(opname==NULL) {
PyErr_SetString(PyExc_TypeError, "bpy.__ops__.get_rna() expects a string argument");
PyErr_SetString(PyExc_TypeError, "_bpy.ops.get_rna() expects a string argument");
return NULL;
}
ot= WM_operatortype_find(opname, TRUE);
if(ot==NULL) {
PyErr_Format(PyExc_KeyError, "bpy.__ops__.get_rna(\"%s\") not found", opname);
PyErr_Format(PyExc_KeyError, "_bpy.ops.get_rna(\"%s\") not found", opname);
return NULL;
}
@@ -230,7 +230,9 @@ static PyObject *pyop_getrna(PyObject *self, PyObject *value)
//RNA_pointer_create(NULL, &RNA_Struct, ot->srna, &ptr);
/* XXX - should call WM_operator_properties_free */
WM_operator_properties_create(&ptr, ot->idname);
WM_operator_properties_create_ptr(&ptr, ot);
pyrna= (BPy_StructRNA *)pyrna_struct_CreatePyObject(&ptr);
pyrna->freeptr= TRUE;
return (PyObject *)pyrna;
@@ -245,8 +247,8 @@ PyObject *BPY_operator_module( void )
static PyMethodDef pyop_add_meth = {"add", (PyCFunction) PYOP_wrap_add, METH_O, NULL};
static PyMethodDef pyop_remove_meth = {"remove", (PyCFunction) PYOP_wrap_remove, METH_O, NULL};
PyObject *submodule = PyModule_New("bpy.__ops__");
PyDict_SetItemString(PySys_GetObject("modules"), "bpy.__ops__", submodule);
PyObject *submodule = PyModule_New("_bpy.ops");
PyDict_SetItemString(PySys_GetObject("modules"), "_bpy.ops", submodule);
PyModule_AddObject( submodule, "call", PyCFunction_New(&pyop_call_meth, NULL) );
PyModule_AddObject( submodule, "as_string",PyCFunction_New(&pyop_as_string_meth,NULL) );

View File

@@ -32,6 +32,7 @@
#include "MEM_guardedalloc.h"
#include "WM_api.h"
#include "WM_types.h"
#include "UI_interface.h"
#include "ED_screen.h"
#include "RNA_define.h"
@@ -78,10 +79,11 @@ static struct BPY_flag_def pyop_ret_flags[] = {
#define PYOP_EXEC 1
#define PYOP_INVOKE 2
#define PYOP_POLL 3
#define PYOP_DRAW 4
extern void BPY_update_modules( void ); //XXX temp solution
static int PYTHON_OT_generic(int mode, bContext *C, wmOperatorType *ot, wmOperator *op, wmEvent *event)
static int PYTHON_OT_generic(int mode, bContext *C, wmOperatorType *ot, wmOperator *op, wmEvent *event, uiLayout *layout)
{
PyObject *py_class = ot->pyop_data;
PyObject *args;
@@ -89,7 +91,6 @@ static int PYTHON_OT_generic(int mode, bContext *C, wmOperatorType *ot, wmOperat
int ret_flag= (mode==PYOP_POLL ? 0:OPERATOR_CANCELLED);
PointerRNA ptr_context;
PointerRNA ptr_operator;
PointerRNA ptr_event;
PyGILState_STATE gilstate;
@@ -105,31 +106,18 @@ static int PYTHON_OT_generic(int mode, bContext *C, wmOperatorType *ot, wmOperat
py_class_instance = PyObject_Call(py_class, args, NULL);
Py_DECREF(args);
if (py_class_instance) { /* Initializing the class worked, now run its invoke function */
PyObject *class_dict= PyObject_GetAttrString(py_class_instance, "__dict__");
/* Assign instance attributes from operator properties */
if(op) {
const char *arg_name;
RNA_STRUCT_BEGIN(op->ptr, prop) {
arg_name= RNA_property_identifier(prop);
if (strcmp(arg_name, "rna_type")==0) continue;
item = pyrna_prop_to_py(op->ptr, prop);
PyDict_SetItemString(class_dict, arg_name, item);
Py_DECREF(item);
}
RNA_STRUCT_END;
}
if (py_class_instance==NULL) { /* Initializing the class worked, now run its invoke function */
PyErr_Print();
PyErr_Clear();
}
else {
RNA_pointer_create(NULL, &RNA_Context, C, &ptr_context);
if (mode==PYOP_INVOKE) {
PointerRNA ptr_event;
item= PyObject_GetAttrString(py_class, "invoke");
args = PyTuple_New(3);
RNA_pointer_create(NULL, &RNA_Event, event, &ptr_event);
// PyTuple_SET_ITEM "steals" object reference, it is
@@ -148,17 +136,42 @@ static int PYTHON_OT_generic(int mode, bContext *C, wmOperatorType *ot, wmOperat
args = PyTuple_New(2);
PyTuple_SET_ITEM(args, 1, pyrna_struct_CreatePyObject(&ptr_context));
}
else if (mode==PYOP_DRAW) {
PointerRNA ptr_layout;
item= PyObject_GetAttrString(py_class, "draw");
args = PyTuple_New(2);
RNA_pointer_create(NULL, &RNA_UILayout, layout, &ptr_layout);
// PyTuple_SET_ITEM "steals" object reference, it is
// an object passed shouldn't be DECREF'ed
PyTuple_SET_ITEM(args, 1, pyrna_struct_CreatePyObject(&ptr_context));
#if 0
PyTuple_SET_ITEM(args, 2, pyrna_struct_CreatePyObject(&ptr_layout));
#else
{
/* mimic panels */
PyObject *py_layout= pyrna_struct_CreatePyObject(&ptr_layout);
PyObject *pyname= PyUnicode_FromString("layout");
if(PyObject_GenericSetAttr(py_class_instance, pyname, py_layout)) {
PyErr_Print();
PyErr_Clear();
}
else {
Py_DECREF(py_layout);
}
Py_DECREF(pyname);
}
#endif
}
PyTuple_SET_ITEM(args, 0, py_class_instance);
ret = PyObject_Call(item, args, NULL);
Py_DECREF(args);
Py_DECREF(item);
Py_DECREF(class_dict);
}
else {
PyErr_Print();
PyErr_Clear();
}
if (ret == NULL) { /* covers py_class_instance failing too */
@@ -168,21 +181,18 @@ static int PYTHON_OT_generic(int mode, bContext *C, wmOperatorType *ot, wmOperat
else {
if (mode==PYOP_POLL) {
if (PyBool_Check(ret) == 0) {
PyErr_SetString(PyExc_ValueError, "Python poll function return value ");
if(op)
BPy_errors_to_report(op->reports);
PyErr_Format(PyExc_ValueError, "Python operator '%s.poll', did not return a bool value", ot->idname);
BPy_errors_to_report(op ? op->reports:NULL); /* prints and clears if NULL given */
}
else {
ret_flag= ret==Py_True ? 1:0;
}
} else if(mode==PYOP_DRAW) {
/* pass */
} else if (BPY_flag_from_seq(pyop_ret_flags, ret, &ret_flag) == -1) {
/* the returned value could not be converted into a flag */
if(op) {
fprintf(stderr, "error using return value from \"%s\"\n", op->idname); // for some reason the error raised doesnt include file:line... this helps
BPy_errors_to_report(op->reports);
}
PyErr_Format(PyExc_ValueError, "Python operator, error using return value from \"%s\"\n", ot->idname);
BPy_errors_to_report(op ? op->reports:NULL);
ret_flag = OPERATOR_CANCELLED;
}
/* there is no need to copy the py keyword dict modified by
@@ -232,17 +242,22 @@ static int PYTHON_OT_generic(int mode, bContext *C, wmOperatorType *ot, wmOperat
static int PYTHON_OT_invoke(bContext *C, wmOperator *op, wmEvent *event)
{
return PYTHON_OT_generic(PYOP_INVOKE, C, op->type, op, event);
return PYTHON_OT_generic(PYOP_INVOKE, C, op->type, op, event, NULL);
}
static int PYTHON_OT_execute(bContext *C, wmOperator *op)
{
return PYTHON_OT_generic(PYOP_EXEC, C, op->type, op, NULL);
return PYTHON_OT_generic(PYOP_EXEC, C, op->type, op, NULL, NULL);
}
static int PYTHON_OT_poll(bContext *C, wmOperatorType *ot)
{
return PYTHON_OT_generic(PYOP_POLL, C, ot, NULL, NULL);
return PYTHON_OT_generic(PYOP_POLL, C, ot, NULL, NULL, NULL);
}
static void PYTHON_OT_draw(bContext *C, wmOperator *op, uiLayout *layout)
{
PYTHON_OT_generic(PYOP_DRAW, C, op->type, op, NULL, layout);
}
void PYTHON_OT_wrapper(wmOperatorType *ot, void *userdata)
@@ -279,6 +294,8 @@ void PYTHON_OT_wrapper(wmOperatorType *ot, void *userdata)
ot->exec= PYTHON_OT_execute;
if (PyObject_HasAttrString(py_class, "poll"))
ot->pyop_poll= PYTHON_OT_poll;
if (PyObject_HasAttrString(py_class, "draw"))
ot->ui= PYTHON_OT_draw;
ot->pyop_data= userdata;
@@ -308,9 +325,16 @@ void PYTHON_OT_wrapper(wmOperatorType *ot, void *userdata)
*/
item= ((PyTypeObject*)py_class)->tp_dict;
if(item) {
/* only call this so pyrna_deferred_register_props gives a useful error
* WM_operatortype_append_ptr will call RNA_def_struct_identifier
* later */
RNA_def_struct_identifier(ot->srna, ot->idname);
if(pyrna_deferred_register_props(ot->srna, item)!=0) {
/* failed to register operator props */
PyErr_Print();
PyErr_Clear();
}
}
else {
@@ -336,12 +360,17 @@ PyObject *PYOP_wrap_add(PyObject *self, PyObject *py_class)
{"execute", 'f', 2, -1, BPY_CLASS_ATTR_OPTIONAL},
{"invoke", 'f', 3, -1, BPY_CLASS_ATTR_OPTIONAL},
{"poll", 'f', 2, -1, BPY_CLASS_ATTR_OPTIONAL},
{"draw", 'f', 2, -1, BPY_CLASS_ATTR_OPTIONAL},
{NULL, 0, 0, 0}
};
// in python would be...
//PyObject *optype = PyObject_GetAttrString(PyObject_GetAttrString(PyDict_GetItemString(PyEval_GetGlobals(), "bpy"), "types"), "Operator");
base_class = PyObject_GetAttrStringArgs(PyDict_GetItemString(PyEval_GetGlobals(), "bpy"), 2, "types", "Operator");
//PyObject bpy_mod= PyDict_GetItemString(PyEval_GetGlobals(), "bpy");
PyObject *bpy_mod= PyImport_ImportModuleLevel("bpy", NULL, NULL, NULL, 0);
base_class = PyObject_GetAttrStringArgs(bpy_mod, 2, "types", "Operator");
Py_DECREF(bpy_mod);
if(BPY_class_validate("Operator", py_class, base_class, pyop_class_attr_values, NULL) < 0) {
return NULL; /* BPY_class_validate sets the error */
@@ -414,6 +443,3 @@ PyObject *PYOP_wrap_remove(PyObject *self, PyObject *value)
Py_RETURN_NONE;
}

File diff suppressed because it is too large Load Diff

View File

@@ -39,11 +39,9 @@ extern PyTypeObject pyrna_prop_Type;
#define BPy_PropertyRNA_CheckExact(v) (Py_TYPE(v) == &pyrna_prop_Type)
typedef struct {
void * _a;
void * _b;
PyTypeObject *py_type;
} BPy_StructFakeType;
PyObject_HEAD /* required python macro */
PointerRNA ptr;
} BPy_DummyPointerRNA;
typedef struct {
PyObject_HEAD /* required python macro */

View File

@@ -48,7 +48,7 @@ static struct PyMethodDef ui_methods[] = {
static struct PyModuleDef ui_module = {
PyModuleDef_HEAD_INIT,
"bpy.ui",
"_bpy.ui",
"",
-1,/* multiple "initialization" just copies the module dict. */
ui_methods,

View File

@@ -162,12 +162,15 @@ void BPY_getFileAndNum(char **filename, int *lineno)
getframe = PySys_GetObject("_getframe"); // borrowed
if (getframe==NULL) {
PyErr_Clear();
return;
}
frame = PyObject_CallObject(getframe, NULL);
if (frame==NULL)
if (frame==NULL) {
PyErr_Clear();
return;
}
if (filename) {
co_filename= PyObject_GetAttrStringArgs(frame, 1, "f_code", "co_filename");
@@ -413,6 +416,7 @@ int BPy_reports_to_error(ReportList *reports)
int BPy_errors_to_report(ReportList *reports)
{
PyObject *pystring;
PyObject *pystring_format= NULL; // workaround, see below
char *cstring;
char *filename;
@@ -436,14 +440,23 @@ int BPy_errors_to_report(ReportList *reports)
}
BPY_getFileAndNum(&filename, &lineno);
if(filename==NULL)
filename= "<unknown location>";
cstring= _PyUnicode_AsString(pystring);
#if 0 // ARG!. workaround for a bug in blenders use of vsnprintf
BKE_reportf(reports, RPT_ERROR, "%s\nlocation:%s:%d\n", cstring, filename, lineno);
#else
pystring_format= PyUnicode_FromFormat("%s\nlocation:%s:%d\n", cstring, filename, lineno);
cstring= _PyUnicode_AsString(pystring_format);
BKE_report(reports, RPT_ERROR, cstring);
#endif
fprintf(stderr, "%s\nlocation:%s:%d\n", cstring, filename, lineno); // not exactly needed. just for testing
Py_DECREF(pystring);
Py_DECREF(pystring_format); // workaround
return 1;
}

View File

@@ -27,7 +27,6 @@
*/
/* python, will come back */
void BPY_post_start_python() {}
//void BPY_run_python_script() {}
//void BPY_start_python() {}
void BPY_call_importloader() {}