[Bf-blender-cvs] [23a5726ec28] blender2.8: Refactor: Move rna_scene.c layer/collection to rna_layer.c

Dalai Felinto noreply at git.blender.org
Mon Oct 23 22:28:16 CEST 2017


Commit: 23a5726ec286f66648195776592eeaf4f19a1d45
Author: Dalai Felinto
Date:   Mon Oct 23 17:46:35 2017 -0200
Branches: blender2.8
https://developer.blender.org/rB23a5726ec286f66648195776592eeaf4f19a1d45

Refactor: Move rna_scene.c layer/collection to rna_layer.c

rna_scene.c was getting way too big with data that was related to
DNA_layer_types.h.

I tried doing it earlier, but failed. But now with the new changes I think it's
better to do this sooner than later.

===================================================================

M	source/blender/makesrna/intern/CMakeLists.txt
M	source/blender/makesrna/intern/makesrna.c
M	source/blender/makesrna/intern/rna_internal.h
A	source/blender/makesrna/intern/rna_layer.c
M	source/blender/makesrna/intern/rna_scene.c

===================================================================

diff --git a/source/blender/makesrna/intern/CMakeLists.txt b/source/blender/makesrna/intern/CMakeLists.txt
index bf537ea67c6..74c36c456b0 100644
--- a/source/blender/makesrna/intern/CMakeLists.txt
+++ b/source/blender/makesrna/intern/CMakeLists.txt
@@ -56,6 +56,7 @@ set(DEFSRC
 	rna_key.c
 	rna_lamp.c
 	rna_lattice.c
+	rna_layer.c
 	rna_linestyle.c
 	rna_main.c
 	rna_mask.c
diff --git a/source/blender/makesrna/intern/makesrna.c b/source/blender/makesrna/intern/makesrna.c
index 3e67eeb3951..720f7324bdb 100644
--- a/source/blender/makesrna/intern/makesrna.c
+++ b/source/blender/makesrna/intern/makesrna.c
@@ -3336,6 +3336,7 @@ static RNAProcessItem PROCESS_ITEMS[] = {
 	{"rna_key.c", NULL, RNA_def_key},
 	{"rna_lamp.c", NULL, RNA_def_lamp},
 	{"rna_lattice.c", "rna_lattice_api.c", RNA_def_lattice},
+	{"rna_layer.c", NULL, RNA_def_scene_layer},
 	{"rna_linestyle.c", NULL, RNA_def_linestyle},
 	{"rna_main.c", "rna_main_api.c", RNA_def_main},
 	{"rna_material.c", "rna_material_api.c", RNA_def_material},
diff --git a/source/blender/makesrna/intern/rna_internal.h b/source/blender/makesrna/intern/rna_internal.h
index 00b1b53ad71..ec9b8cc24b2 100644
--- a/source/blender/makesrna/intern/rna_internal.h
+++ b/source/blender/makesrna/intern/rna_internal.h
@@ -172,6 +172,7 @@ void RNA_def_render(struct BlenderRNA *brna);
 void RNA_def_rigidbody(struct BlenderRNA *brna);
 void RNA_def_rna(struct BlenderRNA *brna);
 void RNA_def_scene(struct BlenderRNA *brna);
+void RNA_def_scene_layer(struct BlenderRNA *brna);
 void RNA_def_screen(struct BlenderRNA *brna);
 void RNA_def_sculpt_paint(struct BlenderRNA *brna);
 void RNA_def_sensor(struct BlenderRNA *brna);
diff --git a/source/blender/makesrna/intern/rna_layer.c b/source/blender/makesrna/intern/rna_layer.c
new file mode 100644
index 00000000000..acec7330922
--- /dev/null
+++ b/source/blender/makesrna/intern/rna_layer.c
@@ -0,0 +1,2196 @@
+/*
+ * ***** 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,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Contributor(s): Blender Foundation.
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+/** \file blender/makesrna/intern/rna_layer.c
+ *  \ingroup RNA
+ */
+
+#include "DNA_scene_types.h"
+#include "DNA_layer_types.h"
+
+#include "BLI_math.h"
+#include "BLI_string_utils.h"
+
+#include "BLT_translation.h"
+
+#include "ED_object.h"
+#include "ED_render.h"
+
+#include "RE_engine.h"
+
+#include "DRW_engine.h"
+
+#include "WM_api.h"
+#include "WM_types.h"
+
+#include "RNA_define.h"
+
+#include "rna_internal.h"
+
+const EnumPropertyItem rna_enum_layer_collection_mode_settings_type_items[] = {
+	{COLLECTION_MODE_OBJECT, "OBJECT", 0, "Object", ""},
+	{COLLECTION_MODE_EDIT, "EDIT", 0, "Edit", ""},
+	{COLLECTION_MODE_PAINT_WEIGHT, "PAINT_WEIGHT", 0, "Weight Paint", ""},
+	{COLLECTION_MODE_PAINT_WEIGHT, "PAINT_VERTEX", 0, "Vertex Paint", ""},
+	{0, NULL, 0, NULL, NULL}
+};
+
+#ifdef RNA_RUNTIME
+
+#include "DNA_anim_types.h"
+#include "DNA_color_types.h"
+#include "DNA_node_types.h"
+#include "DNA_object_types.h"
+#include "DNA_mesh_types.h"
+#include "DNA_text_types.h"
+#include "DNA_workspace_types.h"
+
+#include "RNA_access.h"
+
+#include "MEM_guardedalloc.h"
+
+#include "BKE_brush.h"
+#include "BKE_collection.h"
+#include "BKE_colortools.h"
+#include "BKE_context.h"
+#include "BKE_global.h"
+#include "BKE_idprop.h"
+#include "BKE_image.h"
+#include "BKE_layer.h"
+#include "BKE_main.h"
+#include "BKE_node.h"
+#include "BKE_pointcache.h"
+#include "BKE_scene.h"
+#include "BKE_mesh.h"
+#include "BKE_sound.h"
+#include "BKE_screen.h"
+#include "BKE_sequencer.h"
+#include "BKE_animsys.h"
+#include "BKE_freestyle.h"
+#include "BKE_gpencil.h"
+
+#include "ED_info.h"
+#include "ED_node.h"
+#include "ED_view3d.h"
+#include "ED_mesh.h"
+#include "ED_keyframing.h"
+#include "ED_image.h"
+#include "ED_scene.h"
+
+#include "DEG_depsgraph.h"
+#include "DEG_depsgraph_build.h"
+#include "DEG_depsgraph_query.h"
+
+#ifdef WITH_FREESTYLE
+#include "FRS_freestyle.h"
+#endif
+
+static void rna_SceneCollection_name_set(PointerRNA *ptr, const char *value)
+{
+	Scene *scene = (Scene *)ptr->id.data;
+	SceneCollection *sc = (SceneCollection *)ptr->data;
+	BKE_collection_rename(scene, sc, value);
+}
+
+static void rna_SceneCollection_filter_set(PointerRNA *ptr, const char *value)
+{
+	Scene *scene = (Scene *)ptr->id.data;
+	SceneCollection *sc = (SceneCollection *)ptr->data;
+	BLI_strncpy_utf8(sc->filter, value, sizeof(sc->filter));
+
+	TODO_LAYER_SYNC_FILTER;
+	(void)scene;
+}
+
+static PointerRNA rna_SceneCollection_objects_get(CollectionPropertyIterator *iter)
+{
+	ListBaseIterator *internal = &iter->internal.listbase;
+
+	/* we are actually iterating a LinkData list, so override get */
+	return rna_pointer_inherit_refine(&iter->parent, &RNA_Object, ((LinkData *)internal->link)->data);
+}
+
+static int rna_SceneCollection_move_above(ID *id, SceneCollection *sc_src, Main *bmain, SceneCollection *sc_dst)
+{
+	Scene *scene = (Scene *)id;
+
+	if (!BKE_collection_move_above(scene, sc_dst, sc_src)) {
+		return 0;
+	}
+
+	DEG_relations_tag_update(bmain);
+	WM_main_add_notifier(NC_SCENE | ND_LAYER, NULL);
+
+	return 1;
+}
+
+static int rna_SceneCollection_move_below(ID *id, SceneCollection *sc_src, Main *bmain, SceneCollection *sc_dst)
+{
+	Scene *scene = (Scene *)id;
+
+	if (!BKE_collection_move_below(scene, sc_dst, sc_src)) {
+		return 0;
+	}
+
+	DEG_relations_tag_update(bmain);
+	WM_main_add_notifier(NC_SCENE | ND_LAYER, NULL);
+
+	return 1;
+}
+
+static int rna_SceneCollection_move_into(ID *id, SceneCollection *sc_src, Main *bmain, SceneCollection *sc_dst)
+{
+	Scene *scene = (Scene *)id;
+
+	if (!BKE_collection_move_into(scene, sc_dst, sc_src)) {
+		return 0;
+	}
+
+	DEG_relations_tag_update(bmain);
+	WM_main_add_notifier(NC_SCENE | ND_LAYER, NULL);
+
+	return 1;
+}
+
+static SceneCollection *rna_SceneCollection_new(
+        ID *id, SceneCollection *sc_parent, Main *bmain, const char *name)
+{
+	Scene *scene = (Scene *)id;
+	SceneCollection *sc = BKE_collection_add(scene, sc_parent, name);
+
+	DEG_relations_tag_update(bmain);
+	WM_main_add_notifier(NC_SCENE | ND_LAYER, NULL);
+
+	return sc;
+}
+
+static void rna_SceneCollection_remove(
+        ID *id, SceneCollection *sc_parent, Main *bmain, ReportList *reports, PointerRNA *sc_ptr)
+{
+	Scene *scene = (Scene *)id;
+	SceneCollection *sc = sc_ptr->data;
+
+	const int index = BLI_findindex(&sc_parent->scene_collections, sc);
+	if (index == -1) {
+		BKE_reportf(reports, RPT_ERROR, "Collection '%s' is not a sub-collection of '%s'",
+		            sc->name, sc_parent->name);
+		return;
+	}
+
+	if (!BKE_collection_remove(scene, sc)) {
+		BKE_reportf(reports, RPT_ERROR, "Collection '%s' could not be removed from collection '%s'",
+		            sc->name, sc_parent->name);
+		return;
+	}
+
+	RNA_POINTER_INVALIDATE(sc_ptr);
+
+	DEG_relations_tag_update(bmain);
+	WM_main_add_notifier(NC_SCENE | ND_LAYER, NULL);
+}
+
+static int rna_SceneCollection_objects_active_index_get(PointerRNA *ptr)
+{
+	SceneCollection *sc = (SceneCollection *)ptr->data;
+	return sc->active_object_index;
+}
+
+static void rna_SceneCollection_objects_active_index_set(PointerRNA *ptr, int value)
+{
+	SceneCollection *sc = (SceneCollection *)ptr->data;
+	sc->active_object_index = value;
+}
+
+static void rna_SceneCollection_objects_active_index_range(
+        PointerRNA *ptr, int *min, int *max, int *UNUSED(softmin), int *UNUSED(softmax))
+{
+	SceneCollection *sc = (SceneCollection *)ptr->data;
+	*min = 0;
+	*max = max_ii(0, BLI_listbase_count(&sc->objects) - 1);
+}
+
+void rna_SceneCollection_object_link(
+        ID *id, SceneCollection *sc, Main *bmain, ReportList *reports, Object *ob)
+{
+	Scene *scene = (Scene *)id;
+
+	if (BLI_findptr(&sc->objects, ob, offsetof(LinkData, data))) {
+		BKE_reportf(reports, RPT_ERROR, "Object '%s' is already in collection '%s'", ob->id.name + 2, sc->name);
+		return;
+	}
+
+	BKE_collection_object_add(scene, sc, ob);
+
+	/* TODO(sergey): Only update relations for the current scene. */
+	DEG_relations_tag_update(bmain);
+
+	/* TODO(sergey): Use proper flag for tagging here. */
+	DEG_id_tag_update(&scene->id, 0);
+
+	DEG_id_tag_update(&ob->id, OB_RECALC_OB | OB_RECALC_DATA | OB_RECALC_TIME);
+
+	WM_main_add_notifier(NC_SCENE | ND_LAYER | ND_OB_ACTIVE, scene);
+}
+
+static void rna_SceneCollection_object_unlink(
+        ID *id, SceneCollection *sc, Main *bmain, ReportList *reports, Object *ob)
+{
+	Scene *scene = (Scene *)id;
+
+	if (!BLI_findptr(&sc->objects, ob, offsetof(LinkData, data))) {
+		BKE_reportf(reports, RPT_ERROR, "Object '%s' is not in collection '%s'", ob->id.name + 2, sc->name);
+		return;
+	}
+
+	BKE_collection_object_remove(bmain, scene, sc, ob, false);
+
+	/* needed otherwise the depgraph will contain freed objects which can crash, see [#20958] */
+	DEG_relations_tag_update(bmain);
+
+	WM_main_add_notifier(NC_SCENE | ND_LAYER | ND_OB_ACTIVE, scene);
+}
+
+/****** layer collection engine settings *******/
+
+#define RNA_LAYER_ENGINE_GET_SET(_TYPE_, _ENGINE_, _MODE_, _NAME_)                 \
+static _TYPE_ rna_LayerEngineSettings_##_ENGINE_##_##_NAME_##_get(PointerRNA *ptr) \
+{                                                                                  \
+	IDProperty *props = (IDProperty *)ptr->data;                                   \
+	return BKE_collection_engine_property_value_get_##_TYPE_(props, #_NAME_);      \
+}                                                                                  \
+	                                                                      

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list