[Bf-blender-cvs] [558119854da] id_override_static: Bring closer RNA and BKE ...override_..._find() functions, add RNA ..._get() ones.
Bastien Montagne
noreply at git.blender.org
Wed Apr 5 21:54:36 CEST 2017
Commit: 558119854dadba43b977f4e8281ea3f95bdc03f1
Author: Bastien Montagne
Date: Wed Apr 5 17:45:18 2017 +0200
Branches: id_override_static
https://developer.blender.org/rB558119854dadba43b977f4e8281ea3f95bdc03f1
Bring closer RNA and BKE ...override_..._find() functions, add RNA ..._get() ones.
===================================================================
M source/blender/blenkernel/BKE_library_override.h
M source/blender/blenkernel/intern/library_override.c
M source/blender/makesrna/RNA_access.h
M source/blender/makesrna/intern/rna_access.c
===================================================================
diff --git a/source/blender/blenkernel/BKE_library_override.h b/source/blender/blenkernel/BKE_library_override.h
index 7701088d620..cc29b0cea8f 100644
--- a/source/blender/blenkernel/BKE_library_override.h
+++ b/source/blender/blenkernel/BKE_library_override.h
@@ -51,7 +51,7 @@ struct IDOverridePropertyOperation *BKE_override_property_operation_find(
const char *subitem_refname, const char *subitem_locname,
const int subitem_refindex, const int subitem_locindex);
struct IDOverridePropertyOperation *BKE_override_property_operation_get(
- struct IDOverrideProperty *override_property, const int operation,
+ struct IDOverrideProperty *override_property, const short operation,
const char *subitem_refname, const char *subitem_locname,
const int subitem_refindex, const int subitem_locindex, bool *r_created);
void BKE_override_property_operation_delete(
diff --git a/source/blender/blenkernel/intern/library_override.c b/source/blender/blenkernel/intern/library_override.c
index e898e4687be..1fecb5908b2 100644
--- a/source/blender/blenkernel/intern/library_override.c
+++ b/source/blender/blenkernel/intern/library_override.c
@@ -152,6 +152,14 @@ IDOverridePropertyOperation *BKE_override_property_operation_find(
const int subitem_refindex, const int subitem_locindex)
{
IDOverridePropertyOperation *opop;
+ const int subitem_defindex = -1;
+
+ if (subitem_locname &&
+ (opop = BLI_findstring_ptr(&override_property->operations, subitem_locname,
+ offsetof(IDOverridePropertyOperation, subitem_local_name))))
+ {
+ return opop;
+ }
if (subitem_refname &&
(opop = BLI_findstring_ptr(&override_property->operations, subitem_refname,
@@ -160,9 +168,8 @@ IDOverridePropertyOperation *BKE_override_property_operation_find(
return opop;
}
- if (subitem_locname &&
- (opop = BLI_findstring_ptr(&override_property->operations, subitem_locname,
- offsetof(IDOverridePropertyOperation, subitem_local_name))))
+ if ((opop = BLI_listbase_bytes_find(&override_property->operations, &subitem_locindex, sizeof(subitem_locindex),
+ offsetof(IDOverridePropertyOperation, subitem_local_index))))
{
return opop;
}
@@ -173,7 +180,9 @@ IDOverridePropertyOperation *BKE_override_property_operation_find(
return opop;
}
- if ((opop = BLI_listbase_bytes_find(&override_property->operations, &subitem_locindex, sizeof(subitem_locindex),
+ /* index == -1 means all indices, that is valid fallback in case we requested specific index. */
+ if ((subitem_locindex != subitem_defindex) &&
+ (opop = BLI_listbase_bytes_find(&override_property->operations, &subitem_defindex, sizeof(subitem_defindex),
offsetof(IDOverridePropertyOperation, subitem_local_index))))
{
return opop;
@@ -186,7 +195,7 @@ IDOverridePropertyOperation *BKE_override_property_operation_find(
* Find override property operation from given sub-item(s), or create it if it does not exist.
*/
IDOverridePropertyOperation *BKE_override_property_operation_get(
- IDOverrideProperty *override_property, const int operation,
+ IDOverrideProperty *override_property, const short operation,
const char *subitem_refname, const char *subitem_locname,
const int subitem_refindex, const int subitem_locindex, bool *r_created)
{
@@ -207,6 +216,10 @@ IDOverridePropertyOperation *BKE_override_property_operation_get(
opop->subitem_reference_index = subitem_refindex;
BLI_addtail(&override_property->operations, opop);
+
+ if (r_created) {
+ *r_created = true;
+ }
}
else if (r_created) {
*r_created = false;
diff --git a/source/blender/makesrna/RNA_access.h b/source/blender/makesrna/RNA_access.h
index 22a70b1929b..70c3bcc985d 100644
--- a/source/blender/makesrna/RNA_access.h
+++ b/source/blender/makesrna/RNA_access.h
@@ -1238,8 +1238,12 @@ bool RNA_struct_auto_override(
struct PointerRNA *local, struct PointerRNA *reference, struct IDOverride *override, const char *root_path);
struct IDOverrideProperty *RNA_property_override_property_find(PointerRNA *ptr, PropertyRNA *prop);
+struct IDOverrideProperty *RNA_property_override_property_get(PointerRNA *ptr, PropertyRNA *prop, bool *r_created);
+
struct IDOverridePropertyOperation *RNA_property_override_property_operation_find(
PointerRNA *ptr, PropertyRNA *prop, const int index);
+struct IDOverridePropertyOperation *RNA_property_override_property_operation_get(
+ PointerRNA *ptr, PropertyRNA *prop, const short operation, const int index, bool *r_created);
bool RNA_property_overridable(PointerRNA *ptr, PropertyRNA *prop);
bool RNA_property_overridden(PointerRNA *ptr, PropertyRNA *prop, const int index);
diff --git a/source/blender/makesrna/intern/rna_access.c b/source/blender/makesrna/intern/rna_access.c
index b802f76d608..81091914c88 100644
--- a/source/blender/makesrna/intern/rna_access.c
+++ b/source/blender/makesrna/intern/rna_access.c
@@ -8062,13 +8062,26 @@ IDOverrideProperty *RNA_property_override_property_find(PointerRNA *ptr, Propert
char *rna_path = RNA_path_from_ID_to_property(ptr, prop);
if (rna_path) {
- for (IDOverrideProperty *op = id->override->properties.first; op; op = op->next) {
- if (STREQ(rna_path, op->rna_path)) {
- MEM_freeN(rna_path);
- return op;
- }
- }
+ IDOverrideProperty *op = BKE_override_property_find(id->override, rna_path);
+ MEM_freeN(rna_path);
+ return op;
+ }
+ return NULL;
+}
+
+IDOverrideProperty *RNA_property_override_property_get(PointerRNA *ptr, PropertyRNA *prop, bool *r_created)
+{
+ ID *id = ptr->id.data;
+
+ if (!id || !id->override) {
+ return NULL;
+ }
+
+ char *rna_path = RNA_path_from_ID_to_property(ptr, prop);
+ if (rna_path) {
+ IDOverrideProperty *op = BKE_override_property_get(id->override, rna_path, r_created);
MEM_freeN(rna_path);
+ return op;
}
return NULL;
}
@@ -8082,17 +8095,19 @@ IDOverridePropertyOperation *RNA_property_override_property_operation_find(
return NULL;
}
- IDOverridePropertyOperation *opop_generic = NULL;
- for (IDOverridePropertyOperation *opop = op->operations.first; opop; opop = opop->next) {
- if (opop->subitem_local_index == index) {
- return opop;
- }
- else if (opop->subitem_local_index == -1 && !opop_generic) {
- /* index == -1 means all indices, that is valid fallback in case we requested specific index. */
- opop_generic = opop;
- }
+ return BKE_override_property_operation_find(op, NULL, NULL, index, index);
+}
+
+IDOverridePropertyOperation *RNA_property_override_property_operation_get(
+ PointerRNA *ptr, PropertyRNA *prop, const short operation, const int index, bool *r_created)
+{
+ IDOverrideProperty *op = RNA_property_override_property_get(ptr, prop, NULL);
+
+ if (!op) {
+ return NULL;
}
- return opop_generic;
+
+ return BKE_override_property_operation_get(op, operation, NULL, NULL, index, index, r_created);
}
bool RNA_property_overridable(PointerRNA *ptr, PropertyRNA *prop)
More information about the Bf-blender-cvs
mailing list