2 * $Id: rna_object_api.c 21115 2009-06-23 19:17:59Z kazanbas $
4 * ***** BEGIN GPL LICENSE BLOCK *****
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software Foundation,
18 * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 * The Original Code is Copyright (C) 2009 Blender Foundation.
21 * All rights reserved.
24 * Contributor(s): Blender Foundation
26 * ***** END GPL LICENSE BLOCK *****
32 #include "RNA_define.h"
33 #include "RNA_types.h"
35 #include "DNA_object_types.h"
36 #include "DNA_scene_types.h"
40 #include "BKE_scene.h"
41 #include "ED_object.h"
43 static void rna_Scene_add_object(Scene *sce, ReportList *reports, Object *ob)
45 Base *base= object_in_scene(ob, sce);
47 BKE_report(reports, RPT_ERROR, "Object is already in this scene.");
50 base= scene_add_base(sce, ob);
53 /* this is similar to what object_add_type and add_object do */
54 ob->lay= base->lay= sce->lay;
55 ob->recalc |= OB_RECALC;
60 static void rna_Scene_remove_object(Scene *sce, ReportList *reports, Object *ob)
62 Base *base= object_in_scene(ob, sce);
64 BKE_report(reports, RPT_ERROR, "Object is not in this scene.");
67 /* as long as ED_base_object_free_and_unlink calls free_libblock_us, we don't have to decrement ob->id.us */
68 ED_base_object_free_and_unlink(sce, base);
71 static void rna_Scene_set_frame(Scene *sce, bContext *C, int frame)
74 CLAMP(sce->r.cfra, MINAFRAME, MAXFRAME);
75 scene_update_for_newframe(sce, (1<<20) - 1);
77 WM_event_add_notifier(C, NC_SCENE|ND_FRAME, sce);
82 void RNA_api_scene(StructRNA *srna)
87 func= RNA_def_function(srna, "add_object", "rna_Scene_add_object");
88 RNA_def_function_ui_description(func, "Add object to scene.");
89 RNA_def_function_flag(func, FUNC_USE_REPORTS);
90 parm= RNA_def_pointer(func, "object", "Object", "", "Object to add to scene.");
91 RNA_def_property_flag(parm, PROP_REQUIRED);
93 func= RNA_def_function(srna, "remove_object", "rna_Scene_remove_object");
94 RNA_def_function_ui_description(func, "Remove object from scene.");
95 RNA_def_function_flag(func, FUNC_USE_REPORTS);
96 parm= RNA_def_pointer(func, "object", "Object", "", "Object to remove from scene.");
97 RNA_def_property_flag(parm, PROP_REQUIRED);
99 func= RNA_def_function(srna, "set_frame", "rna_Scene_set_frame");
100 RNA_def_function_flag(func, FUNC_USE_CONTEXT);
101 RNA_def_function_ui_description(func, "Set scene frame updating all objects immediately.");
102 parm= RNA_def_int(func, "frame", 0, MINAFRAME, MAXFRAME, "", "Frame number to set.", MINAFRAME, MAXFRAME);
103 RNA_def_property_flag(parm, PROP_REQUIRED);