26
26
* This is a new part of Blender.
28
* Contributor(s): Michel Selten, Willian P. Germano, Alex Mole, Ken Hughes
28
* Contributor(s): Michel Selten, Willian P. Germano, Alex Mole, Ken Hughes,
30
31
* ***** END GPL/BL DUAL LICENSE BLOCK *****
45
46
#include "constant.h"
47
//---------------------- EXPP_FloatsAreEqual -------------------------
48
//Floating point comparisons
49
//floatStep = number of representable floats allowable in between
50
// float A and float B to be considered equal.
48
/*---------------------- EXPP_FloatsAreEqual -------------------------
49
Floating point comparisons
50
floatStep = number of representable floats allowable in between
51
float A and float B to be considered equal. */
51
52
int EXPP_FloatsAreEqual(float A, float B, int floatSteps)
66
//---------------------- EXPP_VectorsAreEqual -------------------------
67
//Builds on EXPP_FloatsAreEqual to test vectors
67
/*---------------------- EXPP_VectorsAreEqual -------------------------
68
Builds on EXPP_FloatsAreEqual to test vectors */
68
69
int EXPP_VectorsAreEqual(float *vecA, float *vecB, int size, int floatSteps){
77
//---------------------- EXPP_GetModuleConstant -------------------------
78
//Helper function for returning a module constant
78
/*---------------------- EXPP_GetModuleConstant -------------------------
79
Helper function for returning a module constant */
79
80
PyObject *EXPP_GetModuleConstant(char *module, char *constant)
81
82
PyObject *py_module = NULL, *py_dict = NULL, *py_constant = NULL;
83
84
/*Careful to pass the correct Package.Module string here or
84
85
* else you add a empty module somewhere*/
85
86
py_module = PyImport_AddModule(module);
86
if(!py_module){ //null = error returning module
87
if(!py_module){ /*null = error returning module*/
87
88
return ( EXPP_ReturnPyObjError( PyExc_RuntimeError,
88
89
"error encountered with returning module constant..." ) );
90
py_dict = PyModule_GetDict(py_module); //never fails
91
py_dict = PyModule_GetDict(py_module); /*never fails*/
92
93
py_constant = PyDict_GetItemString(py_dict, constant);
93
if(!py_constant){ //null = key not found
94
if(!py_constant){ /*null = key not found*/
94
95
return ( EXPP_ReturnPyObjError( PyExc_RuntimeError,
95
96
"error encountered with returning module constant..." ) );
133
134
return ( strcmp( string1, string2 ) == 0 );
136
/*****************************************************************************/
137
/* Description: This function returns the name of the given ID struct */
138
/* without the Object type identifying characters prepended. */
139
/*****************************************************************************/
140
char *GetIdName( ID * id )
142
return ( ( id->name ) + 2 );
145
/*****************************************************************************/
146
/* Description: This function returns the ID of the object with given name */
147
/* from a given list. */
148
/*****************************************************************************/
149
ID *GetIdFromList( ListBase * list, char *name )
151
ID *id = list->first;
154
if( strcmp( name, id->name + 2 ) == 0 )
162
/*****************************************************************************/
163
/* Description: This function sets the fake user status of the ID */
164
/* returns an int error, so from getsetattrs */
165
/*****************************************************************************/
166
int SetIdFakeUser( ID * id, PyObject *value)
169
param = PyObject_IsTrue( value );
171
return EXPP_ReturnIntError( PyExc_TypeError,
172
"expected int argument in range [0,1]" );
175
if (!(id->flag & LIB_FAKEUSER)) {
176
id->flag |= LIB_FAKEUSER;
180
if (id->flag & LIB_FAKEUSER) {
181
id->flag &= ~LIB_FAKEUSER;
190
138
/*****************************************************************************/
191
139
/* Description: These functions set an internal string with the given type */
218
165
Py_DECREF(error);
221
//Like EXPP_ReturnPyObjError but takes a printf format string and multiple arguments
168
/*Like EXPP_ReturnPyObjError but takes a printf format string and multiple arguments*/
222
169
PyObject *EXPP_objError(PyObject *type, const char *format, ...)
443
390
char *eventname = NULL;
444
391
int i, event = 0;
393
list = PyList_New( 0 );
395
if( !PyArg_ParseTuple( args, "s", &eventname ) )
396
return EXPP_ReturnPyObjError( PyExc_TypeError,
397
"expected event name (string) as argument" );
446
399
/* actually !scriptlink shouldn't happen ... */
447
400
if( !slink || !slink->totscript )
448
return EXPP_incr_ret( Py_None );
450
if( !PyArg_ParseTuple( args, "s", &eventname ) )
451
return EXPP_ReturnPyObjError( PyExc_TypeError,
452
"expected event name (string) as argument" );
454
list = PyList_New( 0 );
456
404
return EXPP_ReturnPyObjError( PyExc_MemoryError,
457
405
"couldn't create PyList!" );