Blender V2.61 - r43446
|
00001 /* 00002 * ***** BEGIN GPL LICENSE BLOCK ***** 00003 * 00004 * This program is free software; you can redistribute it and/or 00005 * modify it under the terms of the GNU General Public License 00006 * as published by the Free Software Foundation; either version 2 00007 * of the License, or (at your option) any later version. 00008 * 00009 * This program is distributed in the hope that it will be useful, 00010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 * GNU General Public License for more details. 00013 * 00014 * You should have received a copy of the GNU General Public License 00015 * along with this program; if not, write to the Free Software Foundation, 00016 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 00017 * 00018 * Contributor(s): Campbell Barton 00019 * 00020 * ***** END GPL LICENSE BLOCK ***** 00021 */ 00022 00028 #include <stdlib.h> 00029 00030 #include "RNA_define.h" 00031 00032 #include "rna_internal.h" 00033 00034 #include "DNA_group_types.h" 00035 00036 #ifdef RNA_RUNTIME 00037 00038 #include "DNA_scene_types.h" 00039 #include "DNA_object_types.h" 00040 00041 #include "BKE_group.h" 00042 00043 #include "WM_api.h" 00044 #include "WM_types.h" 00045 00046 static PointerRNA rna_Group_objects_get(CollectionPropertyIterator *iter) 00047 { 00048 ListBaseIterator *internal= iter->internal; 00049 00050 /* we are actually iterating a GroupObject list, so override get */ 00051 return rna_pointer_inherit_refine(&iter->parent, &RNA_Object, ((GroupObject*)internal->link)->ob); 00052 } 00053 00054 static void rna_Group_objects_link(Group *group, bContext *C, ReportList *reports, Object *object) 00055 { 00056 if(!add_to_group(group, object, CTX_data_scene(C), NULL)) { 00057 BKE_reportf(reports, RPT_ERROR, "Object \"%s\" already in group \"%s\"", object->id.name+2, group->id.name+2); 00058 return; 00059 } 00060 00061 WM_main_add_notifier(NC_OBJECT|ND_DRAW, &object->id); 00062 } 00063 00064 static void rna_Group_objects_unlink(Group *group, bContext *C, ReportList *reports, Object *object) 00065 { 00066 if(!rem_from_group(group, object, CTX_data_scene(C), NULL)) { 00067 BKE_reportf(reports, RPT_ERROR, "Object \"%s\" not in group \"%s\"", object->id.name+2, group->id.name+2); 00068 return; 00069 } 00070 00071 WM_main_add_notifier(NC_OBJECT|ND_DRAW, &object->id); 00072 } 00073 00074 #else 00075 00076 /* group.objects */ 00077 static void rna_def_group_objects(BlenderRNA *brna, PropertyRNA *cprop) 00078 { 00079 StructRNA *srna; 00080 // PropertyRNA *prop; 00081 00082 FunctionRNA *func; 00083 PropertyRNA *parm; 00084 00085 RNA_def_property_srna(cprop, "GroupObjects"); 00086 srna= RNA_def_struct(brna, "GroupObjects", NULL); 00087 RNA_def_struct_sdna(srna, "Group"); 00088 RNA_def_struct_ui_text(srna, "Group Objects", "Collection of group objects"); 00089 00090 /* add object */ 00091 func= RNA_def_function(srna, "link", "rna_Group_objects_link"); 00092 RNA_def_function_flag(func, FUNC_USE_CONTEXT|FUNC_USE_REPORTS); 00093 RNA_def_function_ui_description(func, "Add this object to a group"); 00094 /* object to add */ 00095 parm= RNA_def_pointer(func, "object", "Object", "", "Object to add"); 00096 RNA_def_property_flag(parm, PROP_REQUIRED|PROP_NEVER_NULL); 00097 00098 /* remove object */ 00099 func= RNA_def_function(srna, "unlink", "rna_Group_objects_unlink"); 00100 RNA_def_function_ui_description(func, "Remove this object to a group"); 00101 RNA_def_function_flag(func, FUNC_USE_CONTEXT|FUNC_USE_REPORTS); 00102 /* object to remove */ 00103 parm= RNA_def_pointer(func, "object", "Object", "", "Object to remove"); 00104 RNA_def_property_flag(parm, PROP_REQUIRED); 00105 } 00106 00107 00108 void RNA_def_group(BlenderRNA *brna) 00109 { 00110 StructRNA *srna; 00111 PropertyRNA *prop; 00112 00113 srna= RNA_def_struct(brna, "Group", "ID"); 00114 RNA_def_struct_ui_text(srna, "Group", "Group of Object datablocks"); 00115 RNA_def_struct_ui_icon(srna, ICON_GROUP); 00116 RNA_def_struct_clear_flag(srna, STRUCT_ID_REFCOUNT); /* this is done on save/load in readfile.c, removed if no objects are in the group */ 00117 00118 prop= RNA_def_property(srna, "dupli_offset", PROP_FLOAT, PROP_TRANSLATION); 00119 RNA_def_property_float_sdna(prop, NULL, "dupli_ofs"); 00120 RNA_def_property_ui_text(prop, "Dupli Offset", "Offset from the origin to use when instancing as DupliGroup"); 00121 RNA_def_property_ui_range(prop, -10000.0, 10000.0, 10, 4); 00122 00123 prop= RNA_def_property(srna, "layers", PROP_BOOLEAN, PROP_LAYER); 00124 RNA_def_property_boolean_sdna(prop, NULL, "layer", 1); 00125 RNA_def_property_array(prop, 20); 00126 RNA_def_property_ui_text(prop, "Dupli Layers", "Layers visible when this group is instanced as a dupli"); 00127 00128 00129 prop= RNA_def_property(srna, "objects", PROP_COLLECTION, PROP_NONE); 00130 RNA_def_property_collection_sdna(prop, NULL, "gobject", NULL); 00131 RNA_def_property_struct_type(prop, "Object"); 00132 RNA_def_property_ui_text(prop, "Objects", "A collection of this groups objects"); 00133 RNA_def_property_collection_funcs(prop, NULL, NULL, NULL, "rna_Group_objects_get", NULL, NULL, NULL, NULL); 00134 00135 rna_def_group_objects(brna, prop); 00136 00137 } 00138 00139 #endif 00140