Merge branch 'master' into blender2.8
[blender.git] / source / blender / makesrna / intern / rna_ID.c
index cdea0502d12451c88b57d479c2a35c0a06b8f718..27c3cee422cd3527f6e67091942df1a147ab9349 100644 (file)
@@ -75,6 +75,7 @@ const EnumPropertyItem rna_enum_id_type_items[] = {
        {ID_PC, "PAINTCURVE", ICON_CURVE_BEZCURVE, "Paint Curve", ""},
        {ID_PAL, "PALETTE", ICON_COLOR, "Palette", ""},
        {ID_PA, "PARTICLE", ICON_PARTICLE_DATA, "Particle", ""},
+       {ID_LT, "LIGHT_PROBE", ICON_RADIO, "Light Probe", ""},
        {ID_SCE, "SCENE", ICON_SCENE_DATA, "Scene", ""},
        {ID_SCR, "SCREEN", ICON_SPLITSCREEN, "Screen", ""},
        {ID_SO, "SOUND", ICON_PLAY_AUDIO, "Sound", ""},
@@ -83,6 +84,7 @@ const EnumPropertyItem rna_enum_id_type_items[] = {
        {ID_TE, "TEXTURE", ICON_TEXTURE_DATA, "Texture", ""},
        {ID_WM, "WINDOWMANAGER", ICON_FULLSCREEN, "Window Manager", ""},
        {ID_WO, "WORLD", ICON_WORLD_DATA, "World", ""},
+       {ID_WS, "WORKSPACE", ICON_NONE, "Workspace", ""},
        {0, NULL, 0, NULL, NULL}
 };
 
@@ -96,14 +98,42 @@ const EnumPropertyItem rna_enum_id_type_items[] = {
 #include "BKE_idprop.h"
 #include "BKE_library.h"
 #include "BKE_library_query.h"
+#include "BKE_library_override.h"
 #include "BKE_library_remap.h"
 #include "BKE_animsys.h"
 #include "BKE_material.h"
-#include "BKE_depsgraph.h"
 #include "BKE_global.h"  /* XXX, remove me */
 
+#include "DEG_depsgraph.h"
+#include "DEG_depsgraph_build.h"
+
 #include "WM_api.h"
 
+void rna_ID_override_static_property_operation_refname_get(PointerRNA *ptr, char *value)
+{
+       IDOverrideStaticPropertyOperation *opop = ptr->data;
+       strcpy(value, (opop->subitem_reference_name == NULL) ? "" : opop->subitem_reference_name);
+}
+
+int rna_ID_override_static_property_operation_refname_length(PointerRNA *ptr)
+{
+       IDOverrideStaticPropertyOperation *opop = ptr->data;
+       return (opop->subitem_reference_name == NULL) ? 0 : strlen(opop->subitem_reference_name);
+}
+
+void rna_ID_override_static_property_operation_locname_get(PointerRNA *ptr, char *value)
+{
+       IDOverrideStaticPropertyOperation *opop = ptr->data;
+       strcpy(value, (opop->subitem_local_name == NULL) ? "" : opop->subitem_local_name);
+}
+
+int rna_ID_override_static_property_operation_locname_length(PointerRNA *ptr)
+{
+       IDOverrideStaticPropertyOperation *opop = ptr->data;
+       return (opop->subitem_local_name == NULL) ? 0 : strlen(opop->subitem_local_name);
+}
+
+
 /* name functions that ignore the first two ID characters */
 void rna_ID_name_get(PointerRNA *ptr, char *value)
 {
@@ -167,6 +197,7 @@ short RNA_type_to_ID_code(const StructRNA *type)
        if (base_type == &RNA_ParticleSettings) return ID_PA;
        if (base_type == &RNA_Palette) return ID_PAL;
        if (base_type == &RNA_PaintCurve) return ID_PC;
+       if (base_type == &RNA_LightProbe) return ID_LP;
        if (base_type == &RNA_Scene) return ID_SCE;
        if (base_type == &RNA_Screen) return ID_SCR;
        if (base_type == &RNA_Sound) return ID_SO;
@@ -174,6 +205,7 @@ short RNA_type_to_ID_code(const StructRNA *type)
        if (base_type == &RNA_Texture) return ID_TE;
        if (base_type == &RNA_Text) return ID_TXT;
        if (base_type == &RNA_VectorFont) return ID_VF;
+       if (base_type == &RNA_WorkSpace) return ID_WS;
        if (base_type == &RNA_World) return ID_WO;
        if (base_type == &RNA_WindowManager) return ID_WM;
 
@@ -209,6 +241,7 @@ StructRNA *ID_code_to_RNA_type(short idcode)
                case ID_PA: return &RNA_ParticleSettings;
                case ID_PAL: return &RNA_Palette;
                case ID_PC: return &RNA_PaintCurve;
+               case ID_LP: return &RNA_LightProbe;
                case ID_SCE: return &RNA_Scene;
                case ID_SCR: return &RNA_Screen;
                case ID_SO: return &RNA_Sound;
@@ -218,6 +251,7 @@ StructRNA *ID_code_to_RNA_type(short idcode)
                case ID_VF: return &RNA_VectorFont;
                case ID_WM: return &RNA_WindowManager;
                case ID_WO: return &RNA_World;
+               case ID_WS: return &RNA_WorkSpace;
 
                /* deprecated */
                case ID_IP: break;
@@ -304,6 +338,15 @@ static ID *rna_ID_copy(ID *id, Main *bmain)
        return NULL;
 }
 
+static ID *rna_ID_override_create(ID *id, Main *bmain)
+{
+       if (id->lib == NULL) {
+               return NULL;
+       }
+
+       return BKE_override_static_create_from_id(bmain, id);
+}
+
 static void rna_ID_update_tag(ID *id, ReportList *reports, int flag)
 {
        /* XXX, new function for this! */
@@ -342,7 +385,7 @@ static void rna_ID_update_tag(ID *id, ReportList *reports, int flag)
                }
        }
 
-       DAG_id_tag_update(id, flag);
+       DEG_id_tag_update(id, flag);
 }
 
 static void rna_ID_user_clear(ID *id)
@@ -378,14 +421,14 @@ static struct ID *rna_ID_make_local(struct ID *self, Main *bmain, int clear_prox
 static AnimData * rna_ID_animation_data_create(ID *id, Main *bmain)
 {
        AnimData *adt = BKE_animdata_add_id(id);
-       DAG_relations_tag_update(bmain);
+       DEG_relations_tag_update(bmain);
        return adt;
 }
 
 static void rna_ID_animation_data_free(ID *id, Main *bmain)
 {
        BKE_animdata_free(id, true);
-       DAG_relations_tag_update(bmain);
+       DEG_relations_tag_update(bmain);
 }
 
 #ifdef WITH_PYTHON
@@ -451,7 +494,7 @@ static Material *rna_IDMaterials_pop_id(ID *id, Main *bmain, ReportList *reports
                return NULL;
        }
 
-       DAG_id_tag_update(id, OB_RECALC_DATA);
+       DEG_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);
 
@@ -462,7 +505,7 @@ static void rna_IDMaterials_clear_id(ID *id, int remove_material_slot)
 {
        BKE_material_clear_id(G.main, id, remove_material_slot);
 
-       DAG_id_tag_update(id, OB_RECALC_DATA);
+       DEG_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);
 }
@@ -755,6 +798,27 @@ static PointerRNA rna_IDPreview_get(PointerRNA *ptr)
        return rna_pointer_inherit_refine(ptr, &RNA_ImagePreview, prv_img);
 }
 
+static int rna_ID_is_updated_get(PointerRNA *ptr)
+{
+       ID *id = (ID *)ptr->data;
+       /* TODO(sergey): Do we need to limit some of flags here? */
+       return ((id->recalc & ID_RECALC_ALL) != 0);
+}
+
+static int rna_ID_is_updated_data_get(PointerRNA *ptr)
+{
+       ID *id = (ID *)ptr->data;
+       if (GS(id->name) != ID_OB) {
+               return 0;
+       }
+       Object *object = (Object *)id;
+       ID *data = object->data;
+       if (data == NULL) {
+               return 0;
+       }
+       return ((data->recalc & ID_RECALC_ALL) != 0);
+}
+
 static IDProperty *rna_IDPropertyWrapPtr_idprops(PointerRNA *ptr, bool UNUSED(create))
 {
        if (ptr == NULL) {
@@ -959,6 +1023,107 @@ static void rna_def_image_preview(BlenderRNA *brna)
        RNA_def_function_ui_description(func, "Reload the preview from its source path");
 }
 
+static void rna_def_ID_override_static_property_operation(BlenderRNA *brna)
+{
+       StructRNA *srna;
+       PropertyRNA *prop;
+
+       static const EnumPropertyItem static_override_property_operation_items[] = {
+               {IDOVERRIDESTATIC_OP_NOOP, "NOOP", 0, "No-Op", "Does nothing, prevents adding actual overrides (NOT USED)"},
+               {IDOVERRIDESTATIC_OP_REPLACE, "REPLACE", 0, "Replace", "Replace value of reference by overriding one"},
+               {IDOVERRIDESTATIC_OP_ADD, "DIFF_ADD", 0, "Differential",
+                "Stores and apply difference between reference and local value (NOT USED)"},
+               {IDOVERRIDESTATIC_OP_SUBTRACT, "DIFF_SUB", 0, "Differential",
+                "Stores and apply difference between reference and local value (NOT USED)"},
+               {IDOVERRIDESTATIC_OP_MULTIPLY, "FACT_MULTIPLY", 0, "Factor",
+                "Stores and apply multiplication factor between reference and local value (NOT USED)"},
+               {IDOVERRIDESTATIC_OP_INSERT_AFTER, "INSERT_AFTER", 0, "Insert After",
+                "Insert a new item into collection after the one referenced in subitem_reference_name or _index"},
+               {IDOVERRIDESTATIC_OP_INSERT_BEFORE, "INSERT_BEFORE", 0, "Insert Before",
+                "Insert a new item into collection after the one referenced in subitem_reference_name or _index (NOT USED)"},
+               {0, NULL, 0, NULL, NULL}
+       };
+
+       static const EnumPropertyItem static_override_property_flag_items[] = {
+               {IDOVERRIDESTATIC_FLAG_MANDATORY, "MANDATORY", 0, "Mandatory",
+                "For templates, prevents the user from removing pre-defined operation (NOT USED)"},
+               {IDOVERRIDESTATIC_FLAG_LOCKED, "LOCKED", 0, "Locked",
+                "Prevents the user from modifying that override operation (NOT USED)"},
+               {0, NULL, 0, NULL, NULL}
+       };
+
+       srna = RNA_def_struct(brna, "IDOverrideStaticPropertyOperation", NULL);
+       RNA_def_struct_ui_text(srna, "ID Static Override Property Operation",
+                              "Description of an override operation over an overridden property");
+
+       prop = RNA_def_enum(srna, "operation", static_override_property_operation_items, IDOVERRIDESTATIC_OP_REPLACE,
+                           "Operation", "What override operation is performed");
+       RNA_def_property_clear_flag(prop, PROP_EDITABLE);  /* For now. */
+
+       prop = RNA_def_enum(srna, "flag", static_override_property_flag_items, 0,
+                           "Flags", "Optional flags (NOT USED)");
+       RNA_def_property_clear_flag(prop, PROP_EDITABLE);  /* For now. */
+
+       prop = RNA_def_string(srna, "subitem_reference_name", NULL, INT_MAX, "Subitem Reference Name",
+                             "Used to handle insertions into collection");
+       RNA_def_property_clear_flag(prop, PROP_EDITABLE);  /* For now. */
+       RNA_def_property_string_funcs(prop, "rna_ID_override_static_property_operation_refname_get",
+                                     "rna_ID_override_static_property_operation_refname_length", NULL);
+
+       prop = RNA_def_string(srna, "subitem_local_name", NULL, INT_MAX, "Subitem Local Name",
+                             "Used to handle insertions into collection");
+       RNA_def_property_clear_flag(prop, PROP_EDITABLE);  /* For now. */
+       RNA_def_property_string_funcs(prop, "rna_ID_override_static_property_operation_locname_get",
+                                     "rna_ID_override_static_property_operation_locname_length", NULL);
+
+       prop = RNA_def_int(srna, "subitem_reference_index", -1, -1, INT_MAX, "Subitem Reference Index",
+                          "Used to handle insertions into collection", -1, INT_MAX);
+       RNA_def_property_clear_flag(prop, PROP_EDITABLE);  /* For now. */
+
+       prop = RNA_def_int(srna, "subitem_local_index", -1, -1, INT_MAX, "Subitem Local Index",
+                          "Used to handle insertions into collection", -1, INT_MAX);
+       RNA_def_property_clear_flag(prop, PROP_EDITABLE);  /* For now. */
+}
+
+static void rna_def_ID_override_static_property(BlenderRNA *brna)
+{
+       StructRNA *srna;
+       PropertyRNA *prop;
+
+       srna = RNA_def_struct(brna, "IDOverrideStaticProperty", NULL);
+       RNA_def_struct_ui_text(srna, "ID Static Override Property", "Description of an overridden property");
+
+       /* String pointer, we *should* add get/set/etc. But NULL rna_path would be a nasty bug anyway... */
+       prop = RNA_def_string(srna, "rna_path", NULL, INT_MAX, "RNA Path",
+                             "RNA path leading to that property, from owning ID");
+       RNA_def_property_clear_flag(prop, PROP_EDITABLE);  /* For now. */
+
+       RNA_def_collection(srna, "operations", "IDOverrideStaticPropertyOperation", "Operations",
+                          "List of overriding operations for a property");
+
+       rna_def_ID_override_static_property_operation(brna);
+}
+
+static void rna_def_ID_override_static(BlenderRNA *brna)
+{
+       StructRNA *srna;
+       PropertyRNA *prop;
+
+       srna = RNA_def_struct(brna, "IDOverrideStatic", NULL);
+       RNA_def_struct_ui_text(srna, "ID Static Override", "Struct gathering all data needed by statically overridden IDs");
+
+       RNA_def_pointer(srna, "reference", "ID", "Reference ID", "Linked ID used as reference by this override");
+
+       prop = RNA_def_boolean(srna, "auto_generate", true, "Auto Generate Override",
+                              "Automatically generate overriding operations by detecting changes in properties");
+       RNA_def_property_boolean_sdna(prop, NULL, "flag", STATICOVERRIDE_AUTO);
+
+       RNA_def_collection(srna, "properties", "IDOverrideStaticProperty", "Properties",
+                          "List of overridden properties");
+
+       rna_def_ID_override_static_property(brna);
+}
+
 static void rna_def_ID(BlenderRNA *brna)
 {
        StructRNA *srna;
@@ -1006,13 +1171,13 @@ static void rna_def_ID(BlenderRNA *brna)
                                 "(initial state is undefined)");
 
        prop = RNA_def_property(srna, "is_updated", PROP_BOOLEAN, PROP_NONE);
-       RNA_def_property_boolean_sdna(prop, NULL, "recalc", ID_RECALC);
        RNA_def_property_clear_flag(prop, PROP_EDITABLE);
+       RNA_def_property_boolean_funcs(prop, "rna_ID_is_updated_get", NULL);
        RNA_def_property_ui_text(prop, "Is Updated", "Data-block is tagged for recalculation");
 
        prop = RNA_def_property(srna, "is_updated_data", PROP_BOOLEAN, PROP_NONE);
-       RNA_def_property_boolean_sdna(prop, NULL, "recalc", ID_RECALC_DATA);
        RNA_def_property_clear_flag(prop, PROP_EDITABLE);
+       RNA_def_property_boolean_funcs(prop, "rna_ID_is_updated_data_get", NULL);
        RNA_def_property_ui_text(prop, "Is Updated Data", "Data-block data is tagged for recalculation");
 
        prop = RNA_def_property(srna, "is_library_indirect", PROP_BOOLEAN, PROP_NONE);
@@ -1025,6 +1190,9 @@ static void rna_def_ID(BlenderRNA *brna)
        RNA_def_property_clear_flag(prop, PROP_EDITABLE);
        RNA_def_property_ui_text(prop, "Library", "Library file the data-block is linked from");
 
+       prop = RNA_def_pointer(srna, "override_static", "IDOverrideStatic", "Static Override", "Static override data");
+       RNA_def_property_clear_flag(prop, PROP_EDITABLE);
+
        prop = RNA_def_pointer(srna, "preview", "ImagePreview", "Preview",
                               "Preview image and icon of this data-block (None if not supported for this type of data)");
        RNA_def_property_clear_flag(prop, PROP_EDITABLE);
@@ -1037,6 +1205,12 @@ static void rna_def_ID(BlenderRNA *brna)
        parm = RNA_def_pointer(func, "id", "ID", "", "New copy of the ID");
        RNA_def_function_return(func, parm);
 
+       func = RNA_def_function(srna, "override_create", "rna_ID_override_create");
+       RNA_def_function_ui_description(func, "Create an overridden local copy of this linked data-block (not supported for all data-blocks)");
+       RNA_def_function_flag(func, FUNC_USE_MAIN);
+       parm = RNA_def_pointer(func, "id", "ID", "", "New overridden local copy of the ID");
+       RNA_def_function_return(func, parm);
+
        func = RNA_def_function(srna, "user_clear", "rna_ID_user_clear");
        RNA_def_function_ui_description(func, "Clear the user count of a data-block so its not saved, "
                                        "on reload the data will be removed");
@@ -1141,6 +1315,7 @@ void RNA_def_ID(BlenderRNA *brna)
        RNA_def_struct_ui_text(srna, "Any Type", "RNA type used for pointers to any possible data");
 
        rna_def_ID(brna);
+       rna_def_ID_override_static(brna);
        rna_def_image_preview(brna);
        rna_def_ID_properties(brna);
        rna_def_ID_materials(brna);