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