2011-02-23 10:52:22 +00:00
|
|
|
/*
|
2008-11-07 02:58:25 +00:00
|
|
|
* ***** 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,
|
2010-02-12 13:34:04 +00:00
|
|
|
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2008-11-07 02:58:25 +00:00
|
|
|
*
|
|
|
|
|
* Contributor(s): Blender Foundation (2008).
|
|
|
|
|
*
|
|
|
|
|
* ***** END GPL LICENSE BLOCK *****
|
|
|
|
|
*/
|
|
|
|
|
|
2011-02-27 20:20:01 +00:00
|
|
|
/** \file blender/makesrna/intern/rna_ID.c
|
|
|
|
|
* \ingroup RNA
|
|
|
|
|
*/
|
|
|
|
|
|
2008-11-07 02:58:25 +00:00
|
|
|
#include <stdlib.h>
|
2008-11-17 18:44:06 +00:00
|
|
|
#include <stdio.h>
|
2008-11-07 02:58:25 +00:00
|
|
|
|
|
|
|
|
#include "DNA_ID.h"
|
2010-10-24 07:02:19 +00:00
|
|
|
#include "DNA_vfont_types.h"
|
2011-07-31 12:43:41 +00:00
|
|
|
#include "DNA_material_types.h"
|
2011-01-03 09:09:30 +00:00
|
|
|
#include "DNA_object_types.h"
|
2008-11-07 02:58:25 +00:00
|
|
|
|
2013-03-07 02:44:55 +00:00
|
|
|
#include "BLI_utildefines.h"
|
|
|
|
|
|
|
|
|
|
#include "RNA_access.h"
|
|
|
|
|
#include "RNA_define.h"
|
|
|
|
|
|
2009-11-25 23:13:47 +00:00
|
|
|
#include "WM_types.h"
|
|
|
|
|
|
2009-06-03 23:16:51 +00:00
|
|
|
#include "rna_internal.h"
|
|
|
|
|
|
2012-03-18 09:27:36 +00:00
|
|
|
/* enum of ID-block types
|
2009-10-14 09:08:53 +00:00
|
|
|
* NOTE: need to keep this in line with the other defines for these
|
|
|
|
|
*/
|
|
|
|
|
EnumPropertyItem id_type_items[] = {
|
|
|
|
|
{ID_AC, "ACTION", ICON_ACTION, "Action", ""},
|
|
|
|
|
{ID_AR, "ARMATURE", ICON_ARMATURE_DATA, "Armature", ""},
|
|
|
|
|
{ID_BR, "BRUSH", ICON_BRUSH_DATA, "Brush", ""},
|
|
|
|
|
{ID_CA, "CAMERA", ICON_CAMERA_DATA, "Camera", ""},
|
|
|
|
|
{ID_CU, "CURVE", ICON_CURVE_DATA, "Curve", ""},
|
|
|
|
|
{ID_VF, "FONT", ICON_FONT_DATA, "Font", ""},
|
|
|
|
|
{ID_GD, "GREASEPENCIL", ICON_GREASEPENCIL, "Grease Pencil", ""},
|
|
|
|
|
{ID_GR, "GROUP", ICON_GROUP, "Group", ""},
|
|
|
|
|
{ID_IM, "IMAGE", ICON_IMAGE_DATA, "Image", ""},
|
|
|
|
|
{ID_KE, "KEY", ICON_SHAPEKEY_DATA, "Key", ""},
|
|
|
|
|
{ID_LA, "LAMP", ICON_LAMP_DATA, "Lamp", ""},
|
2009-10-15 13:47:18 +00:00
|
|
|
{ID_LI, "LIBRARY", ICON_LIBRARY_DATA_DIRECT, "Library", ""},
|
2010-06-25 22:45:42 +00:00
|
|
|
{ID_LS, "LINESTYLE", ICON_PARTICLE_DATA, "FreestyleLineStyle", ""}, /* FIXME proper icon */
|
2009-10-14 09:08:53 +00:00
|
|
|
{ID_LT, "LATTICE", ICON_LATTICE_DATA, "Lattice", ""},
|
|
|
|
|
{ID_MA, "MATERIAL", ICON_MATERIAL_DATA, "Material", ""},
|
|
|
|
|
{ID_MB, "META", ICON_META_DATA, "MetaBall", ""},
|
|
|
|
|
{ID_ME, "MESH", ICON_MESH_DATA, "Mesh", ""},
|
2009-11-11 02:15:09 +00:00
|
|
|
{ID_NT, "NODETREE", ICON_NODETREE, "NodeTree", ""},
|
2009-10-14 09:08:53 +00:00
|
|
|
{ID_OB, "OBJECT", ICON_OBJECT_DATA, "Object", ""},
|
|
|
|
|
{ID_PA, "PARTICLE", ICON_PARTICLE_DATA, "Particle", ""},
|
|
|
|
|
{ID_SCE, "SCENE", ICON_SCENE_DATA, "Scene", ""},
|
2009-10-15 13:47:18 +00:00
|
|
|
{ID_SCR, "SCREEN", ICON_SPLITSCREEN, "Screen", ""},
|
2011-08-01 11:44:20 +00:00
|
|
|
{ID_SPK, "SPEAKER", ICON_SPEAKER, "Speaker", ""},
|
2009-10-15 13:47:18 +00:00
|
|
|
{ID_SO, "SOUND", ICON_PLAY_AUDIO, "Sound", ""},
|
2009-10-14 09:08:53 +00:00
|
|
|
{ID_TXT, "TEXT", ICON_TEXT, "Text", ""},
|
|
|
|
|
{ID_TE, "TEXTURE", ICON_TEXTURE_DATA, "Texture", ""},
|
|
|
|
|
{ID_WO, "WORLD", ICON_WORLD_DATA, "World", ""},
|
2009-10-15 13:47:18 +00:00
|
|
|
{ID_WM, "WINDOWMANAGER", ICON_FULLSCREEN, "Window Manager", ""},
|
2012-05-12 11:01:29 +00:00
|
|
|
{0, NULL, 0, NULL, NULL}
|
|
|
|
|
};
|
2009-10-14 09:08:53 +00:00
|
|
|
|
2008-11-07 02:58:25 +00:00
|
|
|
#ifdef RNA_RUNTIME
|
|
|
|
|
|
2012-08-03 23:44:50 +00:00
|
|
|
#include "BKE_font.h"
|
2008-11-17 18:44:06 +00:00
|
|
|
#include "BKE_idprop.h"
|
2009-03-14 23:17:55 +00:00
|
|
|
#include "BKE_library.h"
|
2009-11-05 10:50:58 +00:00
|
|
|
#include "BKE_animsys.h"
|
2010-09-03 07:25:37 +00:00
|
|
|
#include "BKE_material.h"
|
2011-01-03 09:09:30 +00:00
|
|
|
#include "BKE_depsgraph.h"
|
2008-11-17 18:44:06 +00:00
|
|
|
|
2012-05-12 22:38:15 +00:00
|
|
|
#include "WM_api.h"
|
|
|
|
|
|
2008-11-07 02:58:25 +00:00
|
|
|
/* name functions that ignore the first two ID characters */
|
2009-01-08 13:57:29 +00:00
|
|
|
void rna_ID_name_get(PointerRNA *ptr, char *value)
|
2008-11-07 02:58:25 +00:00
|
|
|
{
|
2012-05-12 11:01:29 +00:00
|
|
|
ID *id = (ID *)ptr->data;
|
|
|
|
|
BLI_strncpy(value, id->name + 2, sizeof(id->name) - 2);
|
2008-11-07 02:58:25 +00:00
|
|
|
}
|
|
|
|
|
|
2009-01-08 13:57:29 +00:00
|
|
|
int rna_ID_name_length(PointerRNA *ptr)
|
2008-11-07 02:58:25 +00:00
|
|
|
{
|
2012-05-12 11:01:29 +00:00
|
|
|
ID *id = (ID *)ptr->data;
|
|
|
|
|
return strlen(id->name + 2);
|
2008-11-07 02:58:25 +00:00
|
|
|
}
|
|
|
|
|
|
2009-01-08 13:57:29 +00:00
|
|
|
void rna_ID_name_set(PointerRNA *ptr, const char *value)
|
2008-11-07 02:58:25 +00:00
|
|
|
{
|
2012-05-12 11:01:29 +00:00
|
|
|
ID *id = (ID *)ptr->data;
|
|
|
|
|
BLI_strncpy_utf8(id->name + 2, value, sizeof(id->name) - 2);
|
2013-03-10 06:40:19 +00:00
|
|
|
test_idbutton(id->name);
|
2008-11-07 02:58:25 +00:00
|
|
|
}
|
|
|
|
|
|
2010-01-11 05:10:57 +00:00
|
|
|
static int rna_ID_name_editable(PointerRNA *ptr)
|
|
|
|
|
{
|
2012-05-12 11:01:29 +00:00
|
|
|
ID *id = (ID *)ptr->data;
|
2010-01-11 05:10:57 +00:00
|
|
|
|
|
|
|
|
if (GS(id->name) == ID_VF) {
|
2012-08-03 22:12:57 +00:00
|
|
|
VFont *vfont = (VFont *)id;
|
|
|
|
|
if (BKE_vfont_is_builtin(vfont))
|
|
|
|
|
return FALSE;
|
2010-01-11 05:10:57 +00:00
|
|
|
}
|
|
|
|
|
|
2012-08-03 22:12:57 +00:00
|
|
|
return TRUE;
|
2010-01-11 05:10:57 +00:00
|
|
|
}
|
|
|
|
|
|
2009-06-07 13:09:18 +00:00
|
|
|
short RNA_type_to_ID_code(StructRNA *type)
|
2008-11-17 18:44:06 +00:00
|
|
|
{
|
2012-03-05 23:30:41 +00:00
|
|
|
if (RNA_struct_is_a(type, &RNA_Action)) return ID_AC;
|
|
|
|
|
if (RNA_struct_is_a(type, &RNA_Armature)) return ID_AR;
|
|
|
|
|
if (RNA_struct_is_a(type, &RNA_Brush)) return ID_BR;
|
|
|
|
|
if (RNA_struct_is_a(type, &RNA_Camera)) return ID_CA;
|
|
|
|
|
if (RNA_struct_is_a(type, &RNA_Curve)) return ID_CU;
|
|
|
|
|
if (RNA_struct_is_a(type, &RNA_GreasePencil)) return ID_GD;
|
|
|
|
|
if (RNA_struct_is_a(type, &RNA_Group)) return ID_GR;
|
|
|
|
|
if (RNA_struct_is_a(type, &RNA_Image)) return ID_IM;
|
|
|
|
|
if (RNA_struct_is_a(type, &RNA_Key)) return ID_KE;
|
|
|
|
|
if (RNA_struct_is_a(type, &RNA_Lamp)) return ID_LA;
|
|
|
|
|
if (RNA_struct_is_a(type, &RNA_Library)) return ID_LI;
|
2012-03-10 21:56:23 +00:00
|
|
|
if (RNA_struct_is_a(type, &RNA_FreestyleLineStyle)) return ID_LS;
|
2012-03-05 23:30:41 +00:00
|
|
|
if (RNA_struct_is_a(type, &RNA_Lattice)) return ID_LT;
|
|
|
|
|
if (RNA_struct_is_a(type, &RNA_Material)) return ID_MA;
|
|
|
|
|
if (RNA_struct_is_a(type, &RNA_MetaBall)) return ID_MB;
|
|
|
|
|
if (RNA_struct_is_a(type, &RNA_NodeTree)) return ID_NT;
|
|
|
|
|
if (RNA_struct_is_a(type, &RNA_Mesh)) return ID_ME;
|
|
|
|
|
if (RNA_struct_is_a(type, &RNA_Object)) return ID_OB;
|
|
|
|
|
if (RNA_struct_is_a(type, &RNA_ParticleSettings)) return ID_PA;
|
|
|
|
|
if (RNA_struct_is_a(type, &RNA_Scene)) return ID_SCE;
|
|
|
|
|
if (RNA_struct_is_a(type, &RNA_Screen)) return ID_SCR;
|
|
|
|
|
if (RNA_struct_is_a(type, &RNA_Speaker)) return ID_SPK;
|
|
|
|
|
if (RNA_struct_is_a(type, &RNA_Sound)) return ID_SO;
|
|
|
|
|
if (RNA_struct_is_a(type, &RNA_Text)) return ID_TXT;
|
|
|
|
|
if (RNA_struct_is_a(type, &RNA_Texture)) return ID_TE;
|
|
|
|
|
if (RNA_struct_is_a(type, &RNA_VectorFont)) return ID_VF;
|
|
|
|
|
if (RNA_struct_is_a(type, &RNA_World)) return ID_WO;
|
|
|
|
|
if (RNA_struct_is_a(type, &RNA_WindowManager)) return ID_WM;
|
|
|
|
|
if (RNA_struct_is_a(type, &RNA_MovieClip)) return ID_MC;
|
2012-06-04 16:42:58 +00:00
|
|
|
if (RNA_struct_is_a(type, &RNA_Mask)) return ID_MSK;
|
2009-06-07 13:09:18 +00:00
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
2008-11-17 18:44:06 +00:00
|
|
|
|
2009-06-07 13:09:18 +00:00
|
|
|
StructRNA *ID_code_to_RNA_type(short idcode)
|
|
|
|
|
{
|
2012-03-05 23:30:41 +00:00
|
|
|
switch (idcode) {
|
2009-01-05 16:31:00 +00:00
|
|
|
case ID_AC: return &RNA_Action;
|
2008-12-09 11:29:40 +00:00
|
|
|
case ID_AR: return &RNA_Armature;
|
2008-12-01 06:52:18 +00:00
|
|
|
case ID_BR: return &RNA_Brush;
|
2008-11-29 19:53:49 +00:00
|
|
|
case ID_CA: return &RNA_Camera;
|
2008-12-01 19:02:27 +00:00
|
|
|
case ID_CU: return &RNA_Curve;
|
2009-08-27 06:03:41 +00:00
|
|
|
case ID_GD: return &RNA_GreasePencil;
|
2008-11-30 05:07:57 +00:00
|
|
|
case ID_GR: return &RNA_Group;
|
2008-11-30 18:39:49 +00:00
|
|
|
case ID_IM: return &RNA_Image;
|
2008-12-03 21:18:10 +00:00
|
|
|
case ID_KE: return &RNA_Key;
|
RNA
* More ID property support. What was already possible was showing
ID properties as RNA properties. Now it is possible to define
RNA properties and have an ID property automatically created the
first time it is set (if not set it retuns the default).
* Added support for defining RNA structs and properties at runtime.
This is useful for python and plugins, and could also be used
for operators, not sure yet what is best there, they could be done
in preprocess for speed, but not sure how to do that while keeping
operator registration a single function.
* Added quick functions to get/set properties based on names, to be
used for operators.
* Added some simple support for inheritance, was already doing this
but having it as a feature simplifies things. Two things were added
for this: when defining a struct you can give a 'from' struct whose
properties will be copied, and structs like ID, operator, modifier,
can define a refine callback that will return the more specific type
of the struct like ID -> Object, Mesh, .. .
* Added simple windowmanager wrap with only the registered operators
list, used for testing RNA for operators.
2008-11-21 02:23:46 +00:00
|
|
|
case ID_LA: return &RNA_Lamp;
|
2008-11-29 19:08:46 +00:00
|
|
|
case ID_LI: return &RNA_Library;
|
2010-06-25 22:45:42 +00:00
|
|
|
case ID_LS: return &RNA_FreestyleLineStyle;
|
2008-11-30 16:38:56 +00:00
|
|
|
case ID_LT: return &RNA_Lattice;
|
2008-11-27 13:36:28 +00:00
|
|
|
case ID_MA: return &RNA_Material;
|
2008-11-30 20:18:55 +00:00
|
|
|
case ID_MB: return &RNA_MetaBall;
|
2008-11-29 01:04:15 +00:00
|
|
|
case ID_NT: return &RNA_NodeTree;
|
RNA
* More ID property support. What was already possible was showing
ID properties as RNA properties. Now it is possible to define
RNA properties and have an ID property automatically created the
first time it is set (if not set it retuns the default).
* Added support for defining RNA structs and properties at runtime.
This is useful for python and plugins, and could also be used
for operators, not sure yet what is best there, they could be done
in preprocess for speed, but not sure how to do that while keeping
operator registration a single function.
* Added quick functions to get/set properties based on names, to be
used for operators.
* Added some simple support for inheritance, was already doing this
but having it as a feature simplifies things. Two things were added
for this: when defining a struct you can give a 'from' struct whose
properties will be copied, and structs like ID, operator, modifier,
can define a refine callback that will return the more specific type
of the struct like ID -> Object, Mesh, .. .
* Added simple windowmanager wrap with only the registered operators
list, used for testing RNA for operators.
2008-11-21 02:23:46 +00:00
|
|
|
case ID_ME: return &RNA_Mesh;
|
|
|
|
|
case ID_OB: return &RNA_Object;
|
2009-02-17 21:07:01 +00:00
|
|
|
case ID_PA: return &RNA_ParticleSettings;
|
RNA
* More ID property support. What was already possible was showing
ID properties as RNA properties. Now it is possible to define
RNA properties and have an ID property automatically created the
first time it is set (if not set it retuns the default).
* Added support for defining RNA structs and properties at runtime.
This is useful for python and plugins, and could also be used
for operators, not sure yet what is best there, they could be done
in preprocess for speed, but not sure how to do that while keeping
operator registration a single function.
* Added quick functions to get/set properties based on names, to be
used for operators.
* Added some simple support for inheritance, was already doing this
but having it as a feature simplifies things. Two things were added
for this: when defining a struct you can give a 'from' struct whose
properties will be copied, and structs like ID, operator, modifier,
can define a refine callback that will return the more specific type
of the struct like ID -> Object, Mesh, .. .
* Added simple windowmanager wrap with only the registered operators
list, used for testing RNA for operators.
2008-11-21 02:23:46 +00:00
|
|
|
case ID_SCE: return &RNA_Scene;
|
2008-11-29 01:04:15 +00:00
|
|
|
case ID_SCR: return &RNA_Screen;
|
2011-08-01 11:44:20 +00:00
|
|
|
case ID_SPK: return &RNA_Speaker;
|
2008-12-26 16:50:05 +00:00
|
|
|
case ID_SO: return &RNA_Sound;
|
2008-12-31 15:02:40 +00:00
|
|
|
case ID_TXT: return &RNA_Text;
|
2009-01-02 23:05:28 +00:00
|
|
|
case ID_TE: return &RNA_Texture;
|
2008-12-02 23:45:11 +00:00
|
|
|
case ID_VF: return &RNA_VectorFont;
|
2008-11-30 22:48:43 +00:00
|
|
|
case ID_WO: return &RNA_World;
|
RNA
* More ID property support. What was already possible was showing
ID properties as RNA properties. Now it is possible to define
RNA properties and have an ID property automatically created the
first time it is set (if not set it retuns the default).
* Added support for defining RNA structs and properties at runtime.
This is useful for python and plugins, and could also be used
for operators, not sure yet what is best there, they could be done
in preprocess for speed, but not sure how to do that while keeping
operator registration a single function.
* Added quick functions to get/set properties based on names, to be
used for operators.
* Added some simple support for inheritance, was already doing this
but having it as a feature simplifies things. Two things were added
for this: when defining a struct you can give a 'from' struct whose
properties will be copied, and structs like ID, operator, modifier,
can define a refine callback that will return the more specific type
of the struct like ID -> Object, Mesh, .. .
* Added simple windowmanager wrap with only the registered operators
list, used for testing RNA for operators.
2008-11-21 02:23:46 +00:00
|
|
|
case ID_WM: return &RNA_WindowManager;
|
2011-11-07 12:55:18 +00:00
|
|
|
case ID_MC: return &RNA_MovieClip;
|
2012-06-04 16:42:58 +00:00
|
|
|
case ID_MSK: return &RNA_Mask;
|
RNA
* More ID property support. What was already possible was showing
ID properties as RNA properties. Now it is possible to define
RNA properties and have an ID property automatically created the
first time it is set (if not set it retuns the default).
* Added support for defining RNA structs and properties at runtime.
This is useful for python and plugins, and could also be used
for operators, not sure yet what is best there, they could be done
in preprocess for speed, but not sure how to do that while keeping
operator registration a single function.
* Added quick functions to get/set properties based on names, to be
used for operators.
* Added some simple support for inheritance, was already doing this
but having it as a feature simplifies things. Two things were added
for this: when defining a struct you can give a 'from' struct whose
properties will be copied, and structs like ID, operator, modifier,
can define a refine callback that will return the more specific type
of the struct like ID -> Object, Mesh, .. .
* Added simple windowmanager wrap with only the registered operators
list, used for testing RNA for operators.
2008-11-21 02:23:46 +00:00
|
|
|
default: return &RNA_ID;
|
|
|
|
|
}
|
2008-11-17 18:44:06 +00:00
|
|
|
}
|
|
|
|
|
|
2009-06-07 13:09:18 +00:00
|
|
|
StructRNA *rna_ID_refine(PointerRNA *ptr)
|
|
|
|
|
{
|
2012-05-12 11:01:29 +00:00
|
|
|
ID *id = (ID *)ptr->data;
|
2009-06-07 13:09:18 +00:00
|
|
|
|
|
|
|
|
return ID_code_to_RNA_type(GS(id->name));
|
|
|
|
|
}
|
|
|
|
|
|
2013-03-07 02:44:55 +00:00
|
|
|
IDProperty *rna_ID_idprops(PointerRNA *ptr, bool create)
|
2009-05-20 09:52:02 +00:00
|
|
|
{
|
|
|
|
|
return IDP_GetProperties(ptr->data, create);
|
|
|
|
|
}
|
|
|
|
|
|
2009-01-08 13:57:29 +00:00
|
|
|
void rna_ID_fake_user_set(PointerRNA *ptr, int value)
|
2008-11-29 19:08:46 +00:00
|
|
|
{
|
2012-05-12 11:01:29 +00:00
|
|
|
ID *id = (ID *)ptr->data;
|
2008-11-29 19:08:46 +00:00
|
|
|
|
2012-03-05 23:30:41 +00:00
|
|
|
if (value && !(id->flag & LIB_FAKEUSER)) {
|
2008-11-29 19:08:46 +00:00
|
|
|
id->flag |= LIB_FAKEUSER;
|
2010-12-17 14:20:20 +00:00
|
|
|
id_us_plus(id);
|
2008-11-29 19:08:46 +00:00
|
|
|
}
|
2012-03-05 23:30:41 +00:00
|
|
|
else if (!value && (id->flag & LIB_FAKEUSER)) {
|
2008-11-29 19:08:46 +00:00
|
|
|
id->flag &= ~LIB_FAKEUSER;
|
2010-12-17 14:20:20 +00:00
|
|
|
id_us_min(id);
|
2008-11-29 19:08:46 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-03-07 02:44:55 +00:00
|
|
|
IDProperty *rna_PropertyGroup_idprops(PointerRNA *ptr, bool UNUSED(create))
|
2009-05-20 09:52:02 +00:00
|
|
|
{
|
|
|
|
|
return ptr->data;
|
|
|
|
|
}
|
|
|
|
|
|
2011-05-31 02:14:25 +00:00
|
|
|
void rna_PropertyGroup_unregister(Main *UNUSED(bmain), StructRNA *type)
|
2.5: RNA, defining enums, pointers and collections properties is now
possible from python, but it's still work in progress.
Pointers and collections are restricted to types derived from
IDPropertyGroup (same as for operators), because RNA knows how to
allocate/deallocate those.
Collections have .add() and .remove(number) functions that can be
used. The remove function should be fixed to take an other argument
than a number.
With the IDPropertyGroup restriction, pointers are more like nested
structs. They don't have add(), remove() yet, not sure where to put
them. Currently the pointer / nested struct is automatically allocated
in the get() function, this needs to be fixed, rule is that RNA get()
will not change any data for thread safety.
Also, it is only possible to add properties to structs after they have
been registered, which needs to be improved as well.
Example code:
http://www.pasteall.org/7201/python
2009-08-18 01:29:25 +00:00
|
|
|
{
|
|
|
|
|
RNA_struct_free(&BLENDER_RNA, type);
|
|
|
|
|
}
|
|
|
|
|
|
2012-03-18 09:27:36 +00:00
|
|
|
StructRNA *rna_PropertyGroup_register(Main *UNUSED(bmain), ReportList *reports, void *data, const char *identifier,
|
|
|
|
|
StructValidateFunc validate, StructCallbackFunc UNUSED(call),
|
|
|
|
|
StructFreeFunc UNUSED(free))
|
2.5: RNA, defining enums, pointers and collections properties is now
possible from python, but it's still work in progress.
Pointers and collections are restricted to types derived from
IDPropertyGroup (same as for operators), because RNA knows how to
allocate/deallocate those.
Collections have .add() and .remove(number) functions that can be
used. The remove function should be fixed to take an other argument
than a number.
With the IDPropertyGroup restriction, pointers are more like nested
structs. They don't have add(), remove() yet, not sure where to put
them. Currently the pointer / nested struct is automatically allocated
in the get() function, this needs to be fixed, rule is that RNA get()
will not change any data for thread safety.
Also, it is only possible to add properties to structs after they have
been registered, which needs to be improved as well.
Example code:
http://www.pasteall.org/7201/python
2009-08-18 01:29:25 +00:00
|
|
|
{
|
|
|
|
|
PointerRNA dummyptr;
|
|
|
|
|
|
|
|
|
|
/* create dummy pointer */
|
2011-02-16 02:51:56 +00:00
|
|
|
RNA_pointer_create(NULL, &RNA_PropertyGroup, NULL, &dummyptr);
|
2.5: RNA, defining enums, pointers and collections properties is now
possible from python, but it's still work in progress.
Pointers and collections are restricted to types derived from
IDPropertyGroup (same as for operators), because RNA knows how to
allocate/deallocate those.
Collections have .add() and .remove(number) functions that can be
used. The remove function should be fixed to take an other argument
than a number.
With the IDPropertyGroup restriction, pointers are more like nested
structs. They don't have add(), remove() yet, not sure where to put
them. Currently the pointer / nested struct is automatically allocated
in the get() function, this needs to be fixed, rule is that RNA get()
will not change any data for thread safety.
Also, it is only possible to add properties to structs after they have
been registered, which needs to be improved as well.
Example code:
http://www.pasteall.org/7201/python
2009-08-18 01:29:25 +00:00
|
|
|
|
|
|
|
|
/* validate the python class */
|
2012-03-05 23:30:41 +00:00
|
|
|
if (validate(&dummyptr, data, NULL) != 0)
|
2.5: RNA, defining enums, pointers and collections properties is now
possible from python, but it's still work in progress.
Pointers and collections are restricted to types derived from
IDPropertyGroup (same as for operators), because RNA knows how to
allocate/deallocate those.
Collections have .add() and .remove(number) functions that can be
used. The remove function should be fixed to take an other argument
than a number.
With the IDPropertyGroup restriction, pointers are more like nested
structs. They don't have add(), remove() yet, not sure where to put
them. Currently the pointer / nested struct is automatically allocated
in the get() function, this needs to be fixed, rule is that RNA get()
will not change any data for thread safety.
Also, it is only possible to add properties to structs after they have
been registered, which needs to be improved as well.
Example code:
http://www.pasteall.org/7201/python
2009-08-18 01:29:25 +00:00
|
|
|
return NULL;
|
|
|
|
|
|
2009-12-22 10:04:15 +00:00
|
|
|
/* note: it looks like there is no length limit on the srna id since its
|
|
|
|
|
* just a char pointer, but take care here, also be careful that python
|
2012-02-08 04:37:37 +00:00
|
|
|
* owns the string pointer which it could potentially free while blender
|
2009-12-22 10:04:15 +00:00
|
|
|
* is running. */
|
2012-03-05 23:30:41 +00:00
|
|
|
if (BLI_strnlen(identifier, MAX_IDPROP_NAME) == MAX_IDPROP_NAME) {
|
2012-10-21 14:02:30 +00:00
|
|
|
BKE_reportf(reports, RPT_ERROR, "Registering id property class: '%s' is too long, maximum length is %d",
|
|
|
|
|
identifier, MAX_IDPROP_NAME);
|
2009-12-22 10:04:15 +00:00
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
2013-01-09 05:32:15 +00:00
|
|
|
return RNA_def_struct_ptr(&BLENDER_RNA, identifier, &RNA_PropertyGroup); /* XXX */
|
2.5: RNA, defining enums, pointers and collections properties is now
possible from python, but it's still work in progress.
Pointers and collections are restricted to types derived from
IDPropertyGroup (same as for operators), because RNA knows how to
allocate/deallocate those.
Collections have .add() and .remove(number) functions that can be
used. The remove function should be fixed to take an other argument
than a number.
With the IDPropertyGroup restriction, pointers are more like nested
structs. They don't have add(), remove() yet, not sure where to put
them. Currently the pointer / nested struct is automatically allocated
in the get() function, this needs to be fixed, rule is that RNA get()
will not change any data for thread safety.
Also, it is only possible to add properties to structs after they have
been registered, which needs to be improved as well.
Example code:
http://www.pasteall.org/7201/python
2009-08-18 01:29:25 +00:00
|
|
|
}
|
|
|
|
|
|
2012-05-12 11:01:29 +00:00
|
|
|
StructRNA *rna_PropertyGroup_refine(PointerRNA *ptr)
|
2.5: RNA, defining enums, pointers and collections properties is now
possible from python, but it's still work in progress.
Pointers and collections are restricted to types derived from
IDPropertyGroup (same as for operators), because RNA knows how to
allocate/deallocate those.
Collections have .add() and .remove(number) functions that can be
used. The remove function should be fixed to take an other argument
than a number.
With the IDPropertyGroup restriction, pointers are more like nested
structs. They don't have add(), remove() yet, not sure where to put
them. Currently the pointer / nested struct is automatically allocated
in the get() function, this needs to be fixed, rule is that RNA get()
will not change any data for thread safety.
Also, it is only possible to add properties to structs after they have
been registered, which needs to be improved as well.
Example code:
http://www.pasteall.org/7201/python
2009-08-18 01:29:25 +00:00
|
|
|
{
|
|
|
|
|
return ptr->type;
|
|
|
|
|
}
|
|
|
|
|
|
2012-09-23 18:50:56 +00:00
|
|
|
static ID *rna_ID_copy(ID *id)
|
2009-09-28 14:28:45 +00:00
|
|
|
{
|
|
|
|
|
ID *newid;
|
|
|
|
|
|
2013-03-10 05:46:24 +00:00
|
|
|
if (id_copy(id, &newid, false)) {
|
2012-03-05 23:30:41 +00:00
|
|
|
if (newid) id_us_min(newid);
|
2009-09-28 14:28:45 +00:00
|
|
|
return newid;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
2011-02-07 08:13:28 +00:00
|
|
|
static void rna_ID_update_tag(ID *id, ReportList *reports, int flag)
|
2011-01-03 09:09:30 +00:00
|
|
|
{
|
|
|
|
|
/* XXX, new function for this! */
|
2012-03-09 18:28:30 +00:00
|
|
|
#if 0
|
|
|
|
|
if (ob->type == OB_FONT) {
|
2011-01-03 09:09:30 +00:00
|
|
|
Curve *cu = ob->data;
|
|
|
|
|
freedisplist(&cu->disp);
|
2012-05-05 14:52:04 +00:00
|
|
|
BKE_vfont_to_curve(sce, ob, CU_LEFT);
|
2012-03-09 18:28:30 +00:00
|
|
|
}
|
|
|
|
|
#endif
|
2011-01-03 09:09:30 +00:00
|
|
|
|
2012-03-05 23:30:41 +00:00
|
|
|
if (flag == 0) {
|
2011-01-03 09:09:30 +00:00
|
|
|
/* pass */
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
/* ensure flag us correct for the type */
|
2012-03-05 23:30:41 +00:00
|
|
|
switch (GS(id->name)) {
|
2012-05-12 11:01:29 +00:00
|
|
|
case ID_OB:
|
|
|
|
|
if (flag & ~(OB_RECALC_ALL)) {
|
2012-10-21 14:02:30 +00:00
|
|
|
BKE_report(reports, RPT_ERROR, "'Refresh' incompatible with Object ID type");
|
2012-05-12 11:01:29 +00:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
/* Could add particle updates later */
|
2012-03-09 18:28:30 +00:00
|
|
|
#if 0
|
2012-05-12 11:01:29 +00:00
|
|
|
case ID_PA:
|
|
|
|
|
if (flag & ~(OB_RECALC_ALL | PSYS_RECALC)) {
|
2012-10-21 14:02:30 +00:00
|
|
|
BKE_report(reports, RPT_ERROR, "'Refresh' incompatible with ParticleSettings ID type");
|
2012-05-12 11:01:29 +00:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
break;
|
2012-03-09 18:28:30 +00:00
|
|
|
#endif
|
2012-05-12 11:01:29 +00:00
|
|
|
default:
|
|
|
|
|
BKE_report(reports, RPT_ERROR, "This ID type is not compatible with any 'refresh' options");
|
|
|
|
|
return;
|
2011-01-03 09:09:30 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
DAG_id_tag_update(id, flag);
|
|
|
|
|
}
|
|
|
|
|
|
2012-09-23 18:50:56 +00:00
|
|
|
static void rna_ID_user_clear(ID *id)
|
2010-03-11 17:18:06 +00:00
|
|
|
{
|
2012-03-18 07:38:51 +00:00
|
|
|
id->us = 0; /* don't save */
|
2010-03-11 17:18:06 +00:00
|
|
|
id->flag &= ~LIB_FAKEUSER;
|
|
|
|
|
}
|
|
|
|
|
|
2010-09-24 00:39:01 +00:00
|
|
|
static void rna_IDPArray_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
|
|
|
|
|
{
|
2012-03-05 23:30:41 +00:00
|
|
|
IDProperty *prop = (IDProperty *)ptr->data;
|
2010-09-24 00:39:01 +00:00
|
|
|
rna_iterator_array_begin(iter, IDP_IDPArray(prop), sizeof(IDProperty), prop->len, 0, NULL);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int rna_IDPArray_length(PointerRNA *ptr)
|
|
|
|
|
{
|
2012-03-05 23:30:41 +00:00
|
|
|
IDProperty *prop = (IDProperty *)ptr->data;
|
2010-09-24 00:39:01 +00:00
|
|
|
return prop->len;
|
|
|
|
|
}
|
|
|
|
|
|
2011-10-01 21:09:42 +00:00
|
|
|
int rna_IDMaterials_assign_int(PointerRNA *ptr, int key, const PointerRNA *assign_ptr)
|
2011-10-01 17:54:33 +00:00
|
|
|
{
|
2012-03-05 23:30:41 +00:00
|
|
|
ID *id = ptr->id.data;
|
|
|
|
|
short *totcol = give_totcolp_id(id);
|
|
|
|
|
Material *mat_id = assign_ptr->id.data;
|
|
|
|
|
if (totcol && (key >= 0 && key < *totcol)) {
|
2011-10-11 05:45:59 +00:00
|
|
|
assign_material_id(id, mat_id, key + 1);
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
2011-10-01 17:54:33 +00:00
|
|
|
}
|
|
|
|
|
|
2012-09-23 18:50:56 +00:00
|
|
|
static void rna_IDMaterials_append_id(ID *id, Material *ma)
|
2012-05-12 22:38:15 +00:00
|
|
|
{
|
|
|
|
|
material_append_id(id, ma);
|
|
|
|
|
|
|
|
|
|
WM_main_add_notifier(NC_OBJECT | ND_DRAW, id);
|
|
|
|
|
WM_main_add_notifier(NC_OBJECT | ND_OB_SHADING, id);
|
|
|
|
|
}
|
|
|
|
|
|
2012-09-23 18:50:56 +00:00
|
|
|
static Material *rna_IDMaterials_pop_id(ID *id, int index_i, int remove_material_slot)
|
2012-05-12 22:38:15 +00:00
|
|
|
{
|
|
|
|
|
Material *ma = material_pop_id(id, index_i, remove_material_slot);
|
|
|
|
|
|
|
|
|
|
DAG_id_tag_update(id, OB_RECALC_DATA);
|
|
|
|
|
WM_main_add_notifier(NC_OBJECT | ND_DRAW, id);
|
|
|
|
|
WM_main_add_notifier(NC_OBJECT | ND_OB_SHADING, id);
|
|
|
|
|
|
|
|
|
|
return ma;
|
|
|
|
|
}
|
|
|
|
|
|
2012-09-23 18:50:56 +00:00
|
|
|
static void rna_Library_filepath_set(PointerRNA *ptr, const char *value)
|
2011-10-23 17:52:20 +00:00
|
|
|
{
|
2012-05-12 11:01:29 +00:00
|
|
|
Library *lib = (Library *)ptr->data;
|
2011-10-23 17:52:20 +00:00
|
|
|
BKE_library_filepath_set(lib, value);
|
|
|
|
|
}
|
|
|
|
|
|
2008-11-07 02:58:25 +00:00
|
|
|
#else
|
|
|
|
|
|
RNA
* More ID property support. What was already possible was showing
ID properties as RNA properties. Now it is possible to define
RNA properties and have an ID property automatically created the
first time it is set (if not set it retuns the default).
* Added support for defining RNA structs and properties at runtime.
This is useful for python and plugins, and could also be used
for operators, not sure yet what is best there, they could be done
in preprocess for speed, but not sure how to do that while keeping
operator registration a single function.
* Added quick functions to get/set properties based on names, to be
used for operators.
* Added some simple support for inheritance, was already doing this
but having it as a feature simplifies things. Two things were added
for this: when defining a struct you can give a 'from' struct whose
properties will be copied, and structs like ID, operator, modifier,
can define a refine callback that will return the more specific type
of the struct like ID -> Object, Mesh, .. .
* Added simple windowmanager wrap with only the registered operators
list, used for testing RNA for operators.
2008-11-21 02:23:46 +00:00
|
|
|
static void rna_def_ID_properties(BlenderRNA *brna)
|
2008-11-17 18:44:06 +00:00
|
|
|
{
|
|
|
|
|
StructRNA *srna;
|
|
|
|
|
PropertyRNA *prop;
|
|
|
|
|
|
|
|
|
|
/* this is struct is used for holding the virtual
|
|
|
|
|
* PropertyRNA's for ID properties */
|
2012-03-05 23:30:41 +00:00
|
|
|
srna = RNA_def_struct(brna, "PropertyGroupItem", NULL);
|
2011-02-16 02:51:56 +00:00
|
|
|
RNA_def_struct_sdna(srna, "IDProperty");
|
2010-02-10 21:15:44 +00:00
|
|
|
RNA_def_struct_ui_text(srna, "ID Property", "Property that stores arbitrary, user defined properties");
|
2008-12-19 04:06:24 +00:00
|
|
|
|
2008-11-17 18:44:06 +00:00
|
|
|
/* IDP_STRING */
|
2012-03-05 23:30:41 +00:00
|
|
|
prop = RNA_def_property(srna, "string", PROP_STRING, PROP_NONE);
|
2012-05-12 11:01:29 +00:00
|
|
|
RNA_def_property_flag(prop, PROP_EXPORT | PROP_IDPROPERTY);
|
2008-11-17 18:44:06 +00:00
|
|
|
|
|
|
|
|
/* IDP_INT */
|
2012-03-05 23:30:41 +00:00
|
|
|
prop = RNA_def_property(srna, "int", PROP_INT, PROP_NONE);
|
2012-05-12 11:01:29 +00:00
|
|
|
RNA_def_property_flag(prop, PROP_EXPORT | PROP_IDPROPERTY);
|
2008-11-17 18:44:06 +00:00
|
|
|
|
2012-03-05 23:30:41 +00:00
|
|
|
prop = RNA_def_property(srna, "int_array", PROP_INT, PROP_NONE);
|
2012-05-12 11:01:29 +00:00
|
|
|
RNA_def_property_flag(prop, PROP_EXPORT | PROP_IDPROPERTY);
|
2008-11-17 18:44:06 +00:00
|
|
|
RNA_def_property_array(prop, 1);
|
|
|
|
|
|
|
|
|
|
/* IDP_FLOAT */
|
2012-03-05 23:30:41 +00:00
|
|
|
prop = RNA_def_property(srna, "float", PROP_FLOAT, PROP_NONE);
|
2012-05-12 11:01:29 +00:00
|
|
|
RNA_def_property_flag(prop, PROP_EXPORT | PROP_IDPROPERTY);
|
2008-11-17 18:44:06 +00:00
|
|
|
|
2012-03-05 23:30:41 +00:00
|
|
|
prop = RNA_def_property(srna, "float_array", PROP_FLOAT, PROP_NONE);
|
2012-05-12 11:01:29 +00:00
|
|
|
RNA_def_property_flag(prop, PROP_EXPORT | PROP_IDPROPERTY);
|
2008-11-17 18:44:06 +00:00
|
|
|
RNA_def_property_array(prop, 1);
|
|
|
|
|
|
|
|
|
|
/* IDP_DOUBLE */
|
2012-03-05 23:30:41 +00:00
|
|
|
prop = RNA_def_property(srna, "double", PROP_FLOAT, PROP_NONE);
|
2012-05-12 11:01:29 +00:00
|
|
|
RNA_def_property_flag(prop, PROP_EXPORT | PROP_IDPROPERTY);
|
2008-11-17 18:44:06 +00:00
|
|
|
|
2012-03-05 23:30:41 +00:00
|
|
|
prop = RNA_def_property(srna, "double_array", PROP_FLOAT, PROP_NONE);
|
2012-05-12 11:01:29 +00:00
|
|
|
RNA_def_property_flag(prop, PROP_EXPORT | PROP_IDPROPERTY);
|
2008-11-17 18:44:06 +00:00
|
|
|
RNA_def_property_array(prop, 1);
|
|
|
|
|
|
|
|
|
|
/* IDP_GROUP */
|
2012-03-05 23:30:41 +00:00
|
|
|
prop = RNA_def_property(srna, "group", PROP_POINTER, PROP_NONE);
|
2012-05-12 11:01:29 +00:00
|
|
|
RNA_def_property_flag(prop, PROP_EXPORT | PROP_IDPROPERTY);
|
2009-03-23 13:24:48 +00:00
|
|
|
RNA_def_property_clear_flag(prop, PROP_EDITABLE);
|
2011-02-16 02:51:56 +00:00
|
|
|
RNA_def_property_struct_type(prop, "PropertyGroup");
|
2008-11-17 18:44:06 +00:00
|
|
|
|
2012-03-05 23:30:41 +00:00
|
|
|
prop = RNA_def_property(srna, "collection", PROP_COLLECTION, PROP_NONE);
|
2012-05-12 11:01:29 +00:00
|
|
|
RNA_def_property_flag(prop, PROP_EXPORT | PROP_IDPROPERTY);
|
2011-02-16 02:51:56 +00:00
|
|
|
RNA_def_property_struct_type(prop, "PropertyGroup");
|
RNA:
* Added support for using pointers + collections as operator properties,
but with the restriction that they must point to other type derived from
ID property groups. The "add" function for these properties will allocate
a new ID property group and point to that.
* Added support for arrays with type IDP_GROUP in ID properties.
* Fix bug getting/setting float array values.
Example code for collections, note the "OperatorMousePath" type is defined
in rna_wm.c and has a float[2] property named "loc".
Defining the operator property:
prop= RNA_def_property(ot->srna, "path", PROP_COLLECTION, PROP_NONE);
RNA_def_property_struct_runtime(prop, &RNA_OperatorMousePath);
Adding values:
PointerRNA itemptr;
float loc[2] = {1, 1},
RNA_collection_add(op->ptr, "path", &itemptr);
RNA_float_set_array(&itemptr, "loc", loc);
Iterating:
RNA_BEGIN(op->ptr, itemptr, "path") {
float loc[2];
RNA_float_get_array(&itemptr, "loc", loc);
printf("Location: %f %f\n", loc[0], loc[1]);
}
RNA_END;
2008-12-26 20:38:52 +00:00
|
|
|
|
2012-03-05 23:30:41 +00:00
|
|
|
prop = RNA_def_property(srna, "idp_array", PROP_COLLECTION, PROP_NONE);
|
2011-02-16 02:51:56 +00:00
|
|
|
RNA_def_property_struct_type(prop, "PropertyGroup");
|
2012-03-18 09:27:36 +00:00
|
|
|
RNA_def_property_collection_funcs(prop, "rna_IDPArray_begin", "rna_iterator_array_next", "rna_iterator_array_end",
|
|
|
|
|
"rna_iterator_array_get", "rna_IDPArray_length", NULL, NULL, NULL);
|
2012-05-12 11:01:29 +00:00
|
|
|
RNA_def_property_flag(prop, PROP_EXPORT | PROP_IDPROPERTY);
|
2010-09-24 00:39:01 +00:00
|
|
|
|
2012-03-05 23:30:41 +00:00
|
|
|
/* never tested, maybe its useful to have this? */
|
2009-12-09 22:37:02 +00:00
|
|
|
#if 0
|
2012-03-05 23:30:41 +00:00
|
|
|
prop = RNA_def_property(srna, "name", PROP_STRING, PROP_NONE);
|
2012-05-12 11:01:29 +00:00
|
|
|
RNA_def_property_flag(prop, PROP_EXPORT | PROP_IDPROPERTY);
|
2009-12-09 22:37:02 +00:00
|
|
|
RNA_def_property_clear_flag(prop, PROP_EDITABLE);
|
2010-02-10 21:15:44 +00:00
|
|
|
RNA_def_property_ui_text(prop, "Name", "Unique name used in the code and scripting");
|
2009-12-09 22:37:02 +00:00
|
|
|
RNA_def_struct_name_property(srna, prop);
|
|
|
|
|
#endif
|
|
|
|
|
|
2008-11-17 18:44:06 +00:00
|
|
|
/* IDP_ID -- not implemented yet in id properties */
|
|
|
|
|
|
|
|
|
|
/* ID property groups > level 0, since level 0 group is merged
|
|
|
|
|
* with native RNA properties. the builtin_properties will take
|
|
|
|
|
* care of the properties here */
|
2012-03-05 23:30:41 +00:00
|
|
|
srna = RNA_def_struct(brna, "PropertyGroup", NULL);
|
2011-02-16 02:51:56 +00:00
|
|
|
RNA_def_struct_sdna(srna, "IDPropertyGroup");
|
2010-02-10 21:15:44 +00:00
|
|
|
RNA_def_struct_ui_text(srna, "ID Property Group", "Group of ID properties");
|
2011-02-16 02:51:56 +00:00
|
|
|
RNA_def_struct_idprops_func(srna, "rna_PropertyGroup_idprops");
|
2011-05-18 11:21:10 +00:00
|
|
|
RNA_def_struct_register_funcs(srna, "rna_PropertyGroup_register", "rna_PropertyGroup_unregister", NULL);
|
2011-02-16 02:51:56 +00:00
|
|
|
RNA_def_struct_refine_func(srna, "rna_PropertyGroup_refine");
|
2009-12-09 22:37:02 +00:00
|
|
|
|
|
|
|
|
/* important so python types can have their name used in list views
|
2012-03-18 07:38:51 +00:00
|
|
|
* however this isn't prefect because it overrides how python would set the name
|
2009-12-09 22:37:02 +00:00
|
|
|
* when we only really want this so RNA_def_struct_name_property() is set to something useful */
|
2012-03-05 23:30:41 +00:00
|
|
|
prop = RNA_def_property(srna, "name", PROP_STRING, PROP_NONE);
|
2012-05-12 11:01:29 +00:00
|
|
|
RNA_def_property_flag(prop, PROP_EXPORT | PROP_IDPROPERTY);
|
2012-03-05 23:30:41 +00:00
|
|
|
/*RNA_def_property_clear_flag(prop, PROP_EDITABLE); */
|
2010-02-10 21:15:44 +00:00
|
|
|
RNA_def_property_ui_text(prop, "Name", "Unique name used in the code and scripting");
|
2009-12-09 22:37:02 +00:00
|
|
|
RNA_def_struct_name_property(srna, prop);
|
2008-11-17 18:44:06 +00:00
|
|
|
}
|
|
|
|
|
|
2010-09-03 07:25:37 +00:00
|
|
|
|
|
|
|
|
static void rna_def_ID_materials(BlenderRNA *brna)
|
|
|
|
|
{
|
|
|
|
|
StructRNA *srna;
|
|
|
|
|
FunctionRNA *func;
|
|
|
|
|
PropertyRNA *parm;
|
|
|
|
|
|
|
|
|
|
/* for mesh/mball/curve materials */
|
2012-03-05 23:30:41 +00:00
|
|
|
srna = RNA_def_struct(brna, "IDMaterials", NULL);
|
2010-09-03 07:25:37 +00:00
|
|
|
RNA_def_struct_sdna(srna, "ID");
|
|
|
|
|
RNA_def_struct_ui_text(srna, "ID Materials", "Collection of materials");
|
|
|
|
|
|
2012-05-12 22:38:15 +00:00
|
|
|
func = RNA_def_function(srna, "append", "rna_IDMaterials_append_id");
|
2011-09-19 13:23:58 +00:00
|
|
|
RNA_def_function_ui_description(func, "Add a new material to the data block");
|
2012-03-05 23:30:41 +00:00
|
|
|
parm = RNA_def_pointer(func, "material", "Material", "", "Material to add");
|
2010-09-03 07:25:37 +00:00
|
|
|
RNA_def_property_flag(parm, PROP_REQUIRED);
|
2012-05-12 22:38:15 +00:00
|
|
|
|
|
|
|
|
func = RNA_def_function(srna, "pop", "rna_IDMaterials_pop_id");
|
2011-09-19 13:23:58 +00:00
|
|
|
RNA_def_function_ui_description(func, "Remove a material from the data block");
|
2012-03-05 23:30:41 +00:00
|
|
|
parm = RNA_def_int(func, "index", 0, 0, MAXMAT, "", "Index of material to remove", 0, MAXMAT);
|
2010-09-03 07:25:37 +00:00
|
|
|
RNA_def_property_flag(parm, PROP_REQUIRED);
|
2011-09-19 13:23:58 +00:00
|
|
|
RNA_def_boolean(func, "update_data", 0, "", "Update data by re-adjusting the material slots assigned");
|
2012-03-05 23:30:41 +00:00
|
|
|
parm = RNA_def_pointer(func, "material", "Material", "", "Material to remove");
|
2010-09-03 07:25:37 +00:00
|
|
|
RNA_def_function_return(func, parm);
|
|
|
|
|
}
|
|
|
|
|
|
2008-11-29 19:08:46 +00:00
|
|
|
static void rna_def_ID(BlenderRNA *brna)
|
2008-11-07 02:58:25 +00:00
|
|
|
{
|
RNA
* More ID property support. What was already possible was showing
ID properties as RNA properties. Now it is possible to define
RNA properties and have an ID property automatically created the
first time it is set (if not set it retuns the default).
* Added support for defining RNA structs and properties at runtime.
This is useful for python and plugins, and could also be used
for operators, not sure yet what is best there, they could be done
in preprocess for speed, but not sure how to do that while keeping
operator registration a single function.
* Added quick functions to get/set properties based on names, to be
used for operators.
* Added some simple support for inheritance, was already doing this
but having it as a feature simplifies things. Two things were added
for this: when defining a struct you can give a 'from' struct whose
properties will be copied, and structs like ID, operator, modifier,
can define a refine callback that will return the more specific type
of the struct like ID -> Object, Mesh, .. .
* Added simple windowmanager wrap with only the registered operators
list, used for testing RNA for operators.
2008-11-21 02:23:46 +00:00
|
|
|
StructRNA *srna;
|
2009-09-28 14:28:45 +00:00
|
|
|
FunctionRNA *func;
|
|
|
|
|
PropertyRNA *prop, *parm;
|
2008-11-07 02:58:25 +00:00
|
|
|
|
2011-01-03 09:09:30 +00:00
|
|
|
static EnumPropertyItem update_flag_items[] = {
|
|
|
|
|
{OB_RECALC_OB, "OBJECT", 0, "Object", ""},
|
|
|
|
|
{OB_RECALC_DATA, "DATA", 0, "Data", ""},
|
|
|
|
|
{OB_RECALC_TIME, "TIME", 0, "Time", ""},
|
2012-05-12 11:01:29 +00:00
|
|
|
{0, NULL, 0, NULL, NULL}
|
|
|
|
|
};
|
2011-01-03 09:09:30 +00:00
|
|
|
|
2012-03-05 23:30:41 +00:00
|
|
|
srna = RNA_def_struct(brna, "ID", NULL);
|
2012-03-18 09:27:36 +00:00
|
|
|
RNA_def_struct_ui_text(srna, "ID",
|
|
|
|
|
"Base type for datablocks, defining a unique name, linking from other libraries "
|
|
|
|
|
"and garbage collection");
|
2012-05-12 11:01:29 +00:00
|
|
|
RNA_def_struct_flag(srna, STRUCT_ID | STRUCT_ID_REFCOUNT);
|
2009-01-01 15:52:51 +00:00
|
|
|
RNA_def_struct_refine_func(srna, "rna_ID_refine");
|
2010-08-19 10:16:30 +00:00
|
|
|
RNA_def_struct_idprops_func(srna, "rna_ID_idprops");
|
2008-11-07 02:58:25 +00:00
|
|
|
|
2012-03-05 23:30:41 +00:00
|
|
|
prop = RNA_def_property(srna, "name", PROP_STRING, PROP_NONE);
|
2010-02-10 21:15:44 +00:00
|
|
|
RNA_def_property_ui_text(prop, "Name", "Unique datablock ID name");
|
2008-11-07 02:58:25 +00:00
|
|
|
RNA_def_property_string_funcs(prop, "rna_ID_name_get", "rna_ID_name_length", "rna_ID_name_set");
|
2012-05-12 11:01:29 +00:00
|
|
|
RNA_def_property_string_maxlength(prop, MAX_ID_NAME - 2);
|
2010-01-11 05:10:57 +00:00
|
|
|
RNA_def_property_editable_func(prop, "rna_ID_name_editable");
|
2012-05-12 11:01:29 +00:00
|
|
|
RNA_def_property_update(prop, NC_ID | NA_RENAME, NULL);
|
2008-11-07 02:58:25 +00:00
|
|
|
RNA_def_struct_name_property(srna, prop);
|
2008-11-29 19:08:46 +00:00
|
|
|
|
2012-03-05 23:30:41 +00:00
|
|
|
prop = RNA_def_property(srna, "users", PROP_INT, PROP_UNSIGNED);
|
2008-11-29 19:08:46 +00:00
|
|
|
RNA_def_property_int_sdna(prop, NULL, "us");
|
2009-03-23 13:24:48 +00:00
|
|
|
RNA_def_property_clear_flag(prop, PROP_EDITABLE);
|
2010-02-10 21:15:44 +00:00
|
|
|
RNA_def_property_ui_text(prop, "Users", "Number of times this datablock is referenced");
|
2008-11-29 19:08:46 +00:00
|
|
|
|
2012-03-05 23:30:41 +00:00
|
|
|
prop = RNA_def_property(srna, "use_fake_user", PROP_BOOLEAN, PROP_NONE);
|
2008-11-29 19:08:46 +00:00
|
|
|
RNA_def_property_boolean_sdna(prop, NULL, "flag", LIB_FAKEUSER);
|
2011-09-21 08:02:26 +00:00
|
|
|
RNA_def_property_ui_text(prop, "Fake User", "Save this datablock even if it has no users");
|
2008-11-29 19:08:46 +00:00
|
|
|
RNA_def_property_boolean_funcs(prop, NULL, "rna_ID_fake_user_set");
|
|
|
|
|
|
2012-03-05 23:30:41 +00:00
|
|
|
prop = RNA_def_property(srna, "tag", PROP_BOOLEAN, PROP_NONE);
|
2009-11-03 17:00:38 +00:00
|
|
|
RNA_def_property_boolean_sdna(prop, NULL, "flag", LIB_DOIT);
|
2010-01-04 15:37:22 +00:00
|
|
|
RNA_def_property_flag(prop, PROP_LIB_EXCEPTION);
|
2011-09-21 08:02:26 +00:00
|
|
|
RNA_def_property_ui_text(prop, "Tag", "Tools can use this to tag data (initial state is undefined)");
|
2009-11-03 17:00:38 +00:00
|
|
|
|
2012-03-05 23:30:41 +00:00
|
|
|
prop = RNA_def_property(srna, "is_updated", PROP_BOOLEAN, PROP_NONE);
|
2011-11-02 20:56:52 +00:00
|
|
|
RNA_def_property_boolean_sdna(prop, NULL, "flag", LIB_ID_RECALC);
|
|
|
|
|
RNA_def_property_clear_flag(prop, PROP_EDITABLE);
|
|
|
|
|
RNA_def_property_ui_text(prop, "Is Updated", "Datablock is tagged for recalculation");
|
|
|
|
|
|
2012-03-05 23:30:41 +00:00
|
|
|
prop = RNA_def_property(srna, "is_updated_data", PROP_BOOLEAN, PROP_NONE);
|
2011-11-02 20:56:52 +00:00
|
|
|
RNA_def_property_boolean_sdna(prop, NULL, "flag", LIB_ID_RECALC_DATA);
|
|
|
|
|
RNA_def_property_clear_flag(prop, PROP_EDITABLE);
|
|
|
|
|
RNA_def_property_ui_text(prop, "Is Updated Data", "Datablock data is tagged for recalculation");
|
|
|
|
|
|
2012-05-17 09:17:39 +00:00
|
|
|
prop = RNA_def_property(srna, "is_library_indirect", PROP_BOOLEAN, PROP_NONE);
|
|
|
|
|
RNA_def_property_boolean_sdna(prop, NULL, "flag", LIB_INDIRECT);
|
|
|
|
|
RNA_def_property_clear_flag(prop, PROP_EDITABLE);
|
|
|
|
|
RNA_def_property_ui_text(prop, "Is Indirect", "Is this ID block linked indirectly");
|
|
|
|
|
|
2012-03-05 23:30:41 +00:00
|
|
|
prop = RNA_def_property(srna, "library", PROP_POINTER, PROP_NONE);
|
2008-11-29 19:08:46 +00:00
|
|
|
RNA_def_property_pointer_sdna(prop, NULL, "lib");
|
2009-03-23 13:24:48 +00:00
|
|
|
RNA_def_property_clear_flag(prop, PROP_EDITABLE);
|
2010-02-10 21:15:44 +00:00
|
|
|
RNA_def_property_ui_text(prop, "Library", "Library file the datablock is linked from");
|
2009-09-28 14:28:45 +00:00
|
|
|
|
|
|
|
|
/* functions */
|
2012-03-05 23:30:41 +00:00
|
|
|
func = RNA_def_function(srna, "copy", "rna_ID_copy");
|
2011-09-19 13:23:58 +00:00
|
|
|
RNA_def_function_ui_description(func, "Create a copy of this datablock (not supported for all datablocks)");
|
2012-03-05 23:30:41 +00:00
|
|
|
parm = RNA_def_pointer(func, "id", "ID", "", "New copy of the ID");
|
2009-09-28 14:28:45 +00:00
|
|
|
RNA_def_function_return(func, parm);
|
2009-11-05 10:50:58 +00:00
|
|
|
|
2012-03-05 23:30:41 +00:00
|
|
|
func = RNA_def_function(srna, "user_clear", "rna_ID_user_clear");
|
2011-09-21 08:02:26 +00:00
|
|
|
RNA_def_function_ui_description(func, "Clear the user count of a datablock so its not saved, "
|
2012-05-12 11:01:29 +00:00
|
|
|
"on reload the data will be removed");
|
2010-03-11 17:18:06 +00:00
|
|
|
|
2012-03-05 23:30:41 +00:00
|
|
|
func = RNA_def_function(srna, "animation_data_create", "BKE_id_add_animdata");
|
2011-09-19 13:23:58 +00:00
|
|
|
RNA_def_function_ui_description(func, "Create animation data to this ID, note that not all ID types support this");
|
2012-03-05 23:30:41 +00:00
|
|
|
parm = RNA_def_pointer(func, "anim_data", "AnimData", "", "New animation data or NULL");
|
2009-11-05 10:50:58 +00:00
|
|
|
RNA_def_function_return(func, parm);
|
|
|
|
|
|
2012-03-05 23:30:41 +00:00
|
|
|
func = RNA_def_function(srna, "animation_data_clear", "BKE_free_animdata");
|
2011-09-19 13:23:58 +00:00
|
|
|
RNA_def_function_ui_description(func, "Clear animation on this this ID");
|
2009-11-05 10:50:58 +00:00
|
|
|
|
2012-03-05 23:30:41 +00:00
|
|
|
func = RNA_def_function(srna, "update_tag", "rna_ID_update_tag");
|
2011-01-03 09:09:30 +00:00
|
|
|
RNA_def_function_flag(func, FUNC_USE_REPORTS);
|
2011-09-21 08:02:26 +00:00
|
|
|
RNA_def_function_ui_description(func, "Tag the ID to update its display data");
|
2011-09-19 13:23:58 +00:00
|
|
|
RNA_def_enum_flag(func, "refresh", update_flag_items, 0, "", "Type of updates to perform");
|
2008-11-07 02:58:25 +00:00
|
|
|
}
|
|
|
|
|
|
2008-11-29 19:08:46 +00:00
|
|
|
static void rna_def_library(BlenderRNA *brna)
|
|
|
|
|
{
|
|
|
|
|
StructRNA *srna;
|
|
|
|
|
PropertyRNA *prop;
|
|
|
|
|
|
2012-03-05 23:30:41 +00:00
|
|
|
srna = RNA_def_struct(brna, "Library", "ID");
|
2010-02-10 21:15:44 +00:00
|
|
|
RNA_def_struct_ui_text(srna, "Library", "External .blend file from which data is linked");
|
2009-06-03 23:16:51 +00:00
|
|
|
RNA_def_struct_ui_icon(srna, ICON_LIBRARY_DATA_DIRECT);
|
2008-11-29 19:08:46 +00:00
|
|
|
|
2012-03-05 23:30:41 +00:00
|
|
|
prop = RNA_def_property(srna, "filepath", PROP_STRING, PROP_FILEPATH);
|
2008-11-29 19:08:46 +00:00
|
|
|
RNA_def_property_string_sdna(prop, NULL, "name");
|
2010-06-02 17:58:28 +00:00
|
|
|
RNA_def_property_ui_text(prop, "File Path", "Path to the library .blend file");
|
2011-10-23 17:52:20 +00:00
|
|
|
RNA_def_property_string_funcs(prop, NULL, NULL, "rna_Library_filepath_set");
|
2010-04-22 08:25:05 +00:00
|
|
|
|
2012-03-05 23:30:41 +00:00
|
|
|
prop = RNA_def_property(srna, "parent", PROP_POINTER, PROP_NONE);
|
2010-06-11 10:46:47 +00:00
|
|
|
RNA_def_property_struct_type(prop, "Library");
|
2012-03-18 09:27:36 +00:00
|
|
|
RNA_def_property_ui_text(prop, "Parent", "");
|
2008-11-29 19:08:46 +00:00
|
|
|
}
|
RNA
* More ID property support. What was already possible was showing
ID properties as RNA properties. Now it is possible to define
RNA properties and have an ID property automatically created the
first time it is set (if not set it retuns the default).
* Added support for defining RNA structs and properties at runtime.
This is useful for python and plugins, and could also be used
for operators, not sure yet what is best there, they could be done
in preprocess for speed, but not sure how to do that while keeping
operator registration a single function.
* Added quick functions to get/set properties based on names, to be
used for operators.
* Added some simple support for inheritance, was already doing this
but having it as a feature simplifies things. Two things were added
for this: when defining a struct you can give a 'from' struct whose
properties will be copied, and structs like ID, operator, modifier,
can define a refine callback that will return the more specific type
of the struct like ID -> Object, Mesh, .. .
* Added simple windowmanager wrap with only the registered operators
list, used for testing RNA for operators.
2008-11-21 02:23:46 +00:00
|
|
|
void RNA_def_ID(BlenderRNA *brna)
|
2008-11-17 18:44:06 +00:00
|
|
|
{
|
2008-12-19 04:06:24 +00:00
|
|
|
StructRNA *srna;
|
2009-01-10 22:57:33 +00:00
|
|
|
|
2009-04-07 00:49:39 +00:00
|
|
|
/* built-in unknown type */
|
2012-03-05 23:30:41 +00:00
|
|
|
srna = RNA_def_struct(brna, "UnknownType", NULL);
|
2010-02-10 21:15:44 +00:00
|
|
|
RNA_def_struct_ui_text(srna, "Unknown Type", "Stub RNA type used for pointers to unknown or internal data");
|
2008-11-30 15:55:14 +00:00
|
|
|
|
2009-04-07 00:49:39 +00:00
|
|
|
/* built-in any type */
|
2012-03-05 23:30:41 +00:00
|
|
|
srna = RNA_def_struct(brna, "AnyType", NULL);
|
2010-02-10 21:15:44 +00:00
|
|
|
RNA_def_struct_ui_text(srna, "Any Type", "RNA type used for pointers to any possible data");
|
2009-04-07 00:49:39 +00:00
|
|
|
|
RNA
* More ID property support. What was already possible was showing
ID properties as RNA properties. Now it is possible to define
RNA properties and have an ID property automatically created the
first time it is set (if not set it retuns the default).
* Added support for defining RNA structs and properties at runtime.
This is useful for python and plugins, and could also be used
for operators, not sure yet what is best there, they could be done
in preprocess for speed, but not sure how to do that while keeping
operator registration a single function.
* Added quick functions to get/set properties based on names, to be
used for operators.
* Added some simple support for inheritance, was already doing this
but having it as a feature simplifies things. Two things were added
for this: when defining a struct you can give a 'from' struct whose
properties will be copied, and structs like ID, operator, modifier,
can define a refine callback that will return the more specific type
of the struct like ID -> Object, Mesh, .. .
* Added simple windowmanager wrap with only the registered operators
list, used for testing RNA for operators.
2008-11-21 02:23:46 +00:00
|
|
|
rna_def_ID(brna);
|
|
|
|
|
rna_def_ID_properties(brna);
|
2010-09-03 07:25:37 +00:00
|
|
|
rna_def_ID_materials(brna);
|
2008-11-29 19:08:46 +00:00
|
|
|
rna_def_library(brna);
|
2008-11-17 18:44:06 +00:00
|
|
|
}
|
|
|
|
|
|
2008-11-07 02:58:25 +00:00
|
|
|
#endif
|