* Fixed a bug in Object.getSelected(). All the objects were returned in stead
of just the selected object(s). This bug was pointed out by Jacek Poplawski. * If there's already a PyObject of a certain object available, then don't create a new one, just return the specified object. * Updated the Object_getData function to return correct objects. So far it can return objects of type Camera, Curve, Lamp and Object.
This commit is contained in:
@@ -172,6 +172,7 @@ PyObject *M_Object_New(PyObject *self, PyObject *args)
|
|||||||
/* Create a Python object from it. */
|
/* Create a Python object from it. */
|
||||||
blen_object = (C_Object*)PyObject_NEW (C_Object, &object_type);
|
blen_object = (C_Object*)PyObject_NEW (C_Object, &object_type);
|
||||||
blen_object->object = object;
|
blen_object->object = object;
|
||||||
|
blen_object->data = NULL;
|
||||||
|
|
||||||
return ((PyObject*)blen_object);
|
return ((PyObject*)blen_object);
|
||||||
}
|
}
|
||||||
@@ -203,6 +204,7 @@ PyObject *M_Object_Get(PyObject *self, PyObject *args)
|
|||||||
}
|
}
|
||||||
blen_object = (C_Object*)PyObject_NEW (C_Object, &object_type);
|
blen_object = (C_Object*)PyObject_NEW (C_Object, &object_type);
|
||||||
blen_object->object = object;
|
blen_object->object = object;
|
||||||
|
blen_object->data = NULL;
|
||||||
|
|
||||||
return ((PyObject*)blen_object);
|
return ((PyObject*)blen_object);
|
||||||
}
|
}
|
||||||
@@ -267,14 +269,15 @@ PyObject *M_Object_GetSelected (PyObject *self, PyObject *args)
|
|||||||
return (Py_None);
|
return (Py_None);
|
||||||
}
|
}
|
||||||
blen_object->object = G.scene->basact->object;
|
blen_object->object = G.scene->basact->object;
|
||||||
|
blen_object->data = NULL;
|
||||||
PyList_Append (list, (PyObject*)blen_object);
|
PyList_Append (list, (PyObject*)blen_object);
|
||||||
}
|
}
|
||||||
|
|
||||||
base_iter = G.scene->base.first;
|
base_iter = G.scene->base.first;
|
||||||
while (base_iter)
|
while (base_iter)
|
||||||
{
|
{
|
||||||
if (((G.scene->basact->flag & SELECT) &&
|
if (((base_iter->flag & SELECT) &&
|
||||||
(G.scene->basact->lay & G.vd->lay)) &&
|
(base_iter->lay & G.vd->lay)) &&
|
||||||
(base_iter != G.scene->basact))
|
(base_iter != G.scene->basact))
|
||||||
{
|
{
|
||||||
blen_object = (C_Object*)PyObject_NEW (C_Object, &object_type);
|
blen_object = (C_Object*)PyObject_NEW (C_Object, &object_type);
|
||||||
@@ -285,6 +288,7 @@ PyObject *M_Object_GetSelected (PyObject *self, PyObject *args)
|
|||||||
return (Py_None);
|
return (Py_None);
|
||||||
}
|
}
|
||||||
blen_object->object = base_iter->object;
|
blen_object->object = base_iter->object;
|
||||||
|
blen_object->data = NULL;
|
||||||
PyList_Append (list, (PyObject*)blen_object);
|
PyList_Append (list, (PyObject*)blen_object);
|
||||||
}
|
}
|
||||||
base_iter = base_iter->next;
|
base_iter = base_iter->next;
|
||||||
@@ -344,6 +348,13 @@ static PyObject *Object_getData (C_Object *self)
|
|||||||
int obj_id;
|
int obj_id;
|
||||||
ID * id;
|
ID * id;
|
||||||
|
|
||||||
|
/* If there's a valid PyObject already, then just return that one. */
|
||||||
|
if (self->data != NULL)
|
||||||
|
{
|
||||||
|
Py_INCREF (self->data);
|
||||||
|
return (self->data);
|
||||||
|
}
|
||||||
|
|
||||||
/* If there's no data associated to the Object, then there's nothing to */
|
/* If there's no data associated to the Object, then there's nothing to */
|
||||||
/* return. */
|
/* return. */
|
||||||
if (self->object->data == NULL)
|
if (self->object->data == NULL)
|
||||||
@@ -352,29 +363,52 @@ static PyObject *Object_getData (C_Object *self)
|
|||||||
return (Py_None);
|
return (Py_None);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
data_object = NULL;
|
||||||
|
|
||||||
id = (ID*)self->object;
|
id = (ID*)self->object;
|
||||||
obj_id = MAKE_ID2 (id->name[0], id->name[1]);
|
obj_id = MAKE_ID2 (id->name[0], id->name[1]);
|
||||||
switch (obj_id)
|
switch (obj_id)
|
||||||
{
|
{
|
||||||
case ID_CA:
|
case ID_CA:
|
||||||
|
data_object = Camera_createPyObject (self->object->data);
|
||||||
|
break;
|
||||||
case ID_CU:
|
case ID_CU:
|
||||||
|
data_object = CurveCreatePyObject (self->object->data);
|
||||||
|
break;
|
||||||
case ID_IM:
|
case ID_IM:
|
||||||
|
break;
|
||||||
case ID_IP:
|
case ID_IP:
|
||||||
|
break;
|
||||||
case ID_LA:
|
case ID_LA:
|
||||||
|
data_object = Lamp_createPyObject (self->object->data);
|
||||||
|
break;
|
||||||
case ID_MA:
|
case ID_MA:
|
||||||
|
break;
|
||||||
case ID_ME:
|
case ID_ME:
|
||||||
|
break;
|
||||||
case ID_OB:
|
case ID_OB:
|
||||||
data_object = M_ObjectCreatePyObject (self->object->data);
|
data_object = M_ObjectCreatePyObject (self->object->data);
|
||||||
Py_INCREF (data_object);
|
break;
|
||||||
return (data_object);
|
|
||||||
case ID_SCE:
|
case ID_SCE:
|
||||||
|
break;
|
||||||
case ID_TXT:
|
case ID_TXT:
|
||||||
|
break;
|
||||||
case ID_WO:
|
case ID_WO:
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
Py_INCREF (Py_None);
|
break;
|
||||||
return (Py_None);
|
}
|
||||||
|
if (data_object == NULL)
|
||||||
|
{
|
||||||
|
Py_INCREF (Py_None);
|
||||||
|
return (Py_None);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
self->data = data_object;
|
||||||
|
Py_INCREF (data_object);
|
||||||
|
return (data_object);
|
||||||
}
|
}
|
||||||
return (Py_None);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static PyObject *Object_getDeformData (C_Object *self)
|
static PyObject *Object_getDeformData (C_Object *self)
|
||||||
@@ -450,10 +484,11 @@ static PyObject *Object_link (C_Object *self, PyObject *args)
|
|||||||
return (PythonReturnErrorObject (PyExc_AttributeError,
|
return (PythonReturnErrorObject (PyExc_AttributeError,
|
||||||
"expected an object as argument"));
|
"expected an object as argument"));
|
||||||
}
|
}
|
||||||
/* TODO: remove the Object type here, add the correct functions when */
|
if (Camera_checkPyObject (py_data))
|
||||||
/* ready. */
|
data = (void*) Camera_fromPyObject (py_data);
|
||||||
if (M_ObjectCheckPyObject (py_data))
|
if (Lamp_checkPyObject (py_data))
|
||||||
data = (void*) M_ObjectFromPyObject (py_data);
|
data = (void*) Lamp_fromPyObject (py_data);
|
||||||
|
/* TODO: add the (N)Mesh check and from functions here when finished. */
|
||||||
|
|
||||||
oldid = (ID*) self->object->data;
|
oldid = (ID*) self->object->data;
|
||||||
id = (ID*) data;
|
id = (ID*) data;
|
||||||
@@ -487,6 +522,7 @@ static PyObject *Object_link (C_Object *self, PyObject *args)
|
|||||||
"Linking this object type is not supported"));
|
"Linking this object type is not supported"));
|
||||||
}
|
}
|
||||||
self->object->data = data;
|
self->object->data = data;
|
||||||
|
self->data = py_data;
|
||||||
id_us_plus (id);
|
id_us_plus (id);
|
||||||
if (oldid)
|
if (oldid)
|
||||||
{
|
{
|
||||||
|
@@ -89,7 +89,11 @@ The active object is the first in the list, if visible";
|
|||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
typedef struct {
|
typedef struct {
|
||||||
PyObject_HEAD
|
PyObject_HEAD
|
||||||
struct Object *object;
|
struct Object * object;
|
||||||
|
|
||||||
|
/* points to the data. This only is set when there's a valid PyObject */
|
||||||
|
/* that points to the linked data. */
|
||||||
|
PyObject * data;
|
||||||
} C_Object;
|
} C_Object;
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
|
Reference in New Issue
Block a user