[Bf-blender-cvs] [6f9afa9] particles_refactor: Use a readonly flag for attributes and a second variant of the Data RNA access types to prevent writing over immutable attributes ("id" in particular).
Lukas Tönne
noreply at git.blender.org
Tue Apr 22 12:06:05 CEST 2014
Commit: 6f9afa9775787d5d66badf18564c055fa813bcfe
Author: Lukas Tönne
Date: Tue Dec 17 16:33:49 2013 +0100
https://developer.blender.org/rB6f9afa9775787d5d66badf18564c055fa813bcfe
Use a readonly flag for attributes and a second variant of the Data
RNA access types to prevent writing over immutable attributes ("id" in
particular).
===================================================================
M source/blender/blenkernel/intern/nparticle.c
M source/blender/makesdna/DNA_nparticle_types.h
M source/blender/makesrna/intern/rna_nparticle.c
===================================================================
diff --git a/source/blender/blenkernel/intern/nparticle.c b/source/blender/blenkernel/intern/nparticle.c
index df5fe85..990bbda 100644
--- a/source/blender/blenkernel/intern/nparticle.c
+++ b/source/blender/blenkernel/intern/nparticle.c
@@ -175,7 +175,7 @@ NParticleSystem *BKE_nparticle_system_new(void)
psys->state = nparticle_state_new(psys);
/* required attributes */
- BKE_nparticle_attribute_new(psys, "id", PAR_ATTR_DATATYPE_INT, PAR_ATTR_REQUIRED);
+ BKE_nparticle_attribute_new(psys, "id", PAR_ATTR_DATATYPE_INT, PAR_ATTR_REQUIRED | PAR_ATTR_READONLY);
return psys;
}
diff --git a/source/blender/makesdna/DNA_nparticle_types.h b/source/blender/makesdna/DNA_nparticle_types.h
index f88fa97..fd33a36 100644
--- a/source/blender/makesdna/DNA_nparticle_types.h
+++ b/source/blender/makesdna/DNA_nparticle_types.h
@@ -40,7 +40,8 @@ typedef struct NParticleAttributeDescription {
typedef enum eParticleAttributeFlag {
PAR_ATTR_REQUIRED = 1, /* always exists */
- PAR_ATTR_PROTECTED = 2 /* descriptor is immutable */
+ PAR_ATTR_PROTECTED = 2, /* descriptor is immutable */
+ PAR_ATTR_READONLY = 4 /* attribute data is read-only */
} eParticleAttributeFlag;
/* particle attribute types */
diff --git a/source/blender/makesrna/intern/rna_nparticle.c b/source/blender/makesrna/intern/rna_nparticle.c
index 843fc07..f530ab5 100644
--- a/source/blender/makesrna/intern/rna_nparticle.c
+++ b/source/blender/makesrna/intern/rna_nparticle.c
@@ -439,92 +439,117 @@ static void def_nparticle_attribute_state_type(BlenderRNA *brna,
NULL, assign_int_func);
}
-static void rna_def_nparticle_attribute_state(BlenderRNA *brna)
+/* Subtypes for data access */
+static void rna_def_nparticle_attribute_data_types(BlenderRNA *brna, bool readonly)
{
StructRNA *srna;
PropertyRNA *prop;
- srna = RNA_def_struct(brna, "NParticleAttributeState", NULL);
- RNA_def_struct_sdna(srna, "NParticleAttributeState");
- RNA_def_struct_ui_text(srna, "Particle Attribute State", "Data for a particle attribute");
- RNA_def_struct_refine_func(srna, "rna_NParticleAttributeState_refine");
-
- def_nparticle_attribute_description(srna, 0, NULL, NULL);
-
- /*** Subtypes for data access ***/
-
/* VOID */
- srna = RNA_def_struct(brna, "NParticleDataVoid", NULL);
- RNA_def_struct_ui_text(srna, "Particle Data", "Unknown particle data type");
+ if (readonly) {
+ srna = RNA_def_struct(brna, "NParticleDataVoid", NULL);
+ RNA_def_struct_ui_text(srna, "Particle Data", "Unknown particle data type");
+ }
/* FLOAT */
- srna = RNA_def_struct(brna, "NParticleDataFloat", NULL);
+ srna = RNA_def_struct(brna, readonly ? "NParticleDataFloatReadonly" : "NParticleDataFloat", NULL);
RNA_def_struct_ui_text(srna, "Particle Float Data", "");
prop = RNA_def_property(srna, "value", PROP_FLOAT, PROP_NONE);
- RNA_def_property_float_funcs(prop, "rna_NParticleDataFloat_get", "rna_NParticleDataFloat_set", NULL);
+ RNA_def_property_float_funcs(prop, "rna_NParticleDataFloat_get", readonly ? NULL : "rna_NParticleDataFloat_set", NULL);
RNA_def_property_ui_text(prop, "Value", "");
+ if (readonly)
+ RNA_def_property_clear_flag(prop, PROP_EDITABLE);
/* INT */
- srna = RNA_def_struct(brna, "NParticleDataInt", NULL);
+ srna = RNA_def_struct(brna, readonly ? "NParticleDataIntReadonly" : "NParticleDataInt", NULL);
RNA_def_struct_ui_text(srna, "Particle Int Data", "");
prop = RNA_def_property(srna, "value", PROP_INT, PROP_NONE);
- RNA_def_property_int_funcs(prop, "rna_NParticleDataInt_get", "rna_NParticleDataInt_set", NULL);
+ RNA_def_property_int_funcs(prop, "rna_NParticleDataInt_get", readonly ? NULL : "rna_NParticleDataInt_set", NULL);
RNA_def_property_ui_text(prop, "Value", "");
+ if (readonly)
+ RNA_def_property_clear_flag(prop, PROP_EDITABLE);
/* BOOL */
- srna = RNA_def_struct(brna, "NParticleDataBool", NULL);
+ srna = RNA_def_struct(brna, readonly ? "NParticleDataBoolReadonly" : "NParticleDataBool", NULL);
RNA_def_struct_ui_text(srna, "Particle Bool Data", "");
prop = RNA_def_property(srna, "value", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_funcs(prop, "rna_NParticleDataBool_get", "rna_NParticleDataBool_set");
+ RNA_def_property_boolean_funcs(prop, "rna_NParticleDataBool_get", readonly ? NULL : "rna_NParticleDataBool_set");
RNA_def_property_ui_text(prop, "Value", "");
+ if (readonly)
+ RNA_def_property_clear_flag(prop, PROP_EDITABLE);
/* VECTOR */
- srna = RNA_def_struct(brna, "NParticleDataVector", NULL);
+ srna = RNA_def_struct(brna, readonly ? "NParticleDataVectorReadonly" : "NParticleDataVector", NULL);
RNA_def_struct_ui_text(srna, "Particle Vector Data", "");
prop = RNA_def_property(srna, "value", PROP_FLOAT, PROP_XYZ);
RNA_def_property_array(prop, 3);
- RNA_def_property_float_funcs(prop, "rna_NParticleDataVector_get", "rna_NParticleDataVector_set", NULL);
+ RNA_def_property_float_funcs(prop, "rna_NParticleDataVector_get", readonly ? NULL : "rna_NParticleDataVector_set", NULL);
RNA_def_property_ui_text(prop, "Value", "");
+ if (readonly)
+ RNA_def_property_clear_flag(prop, PROP_EDITABLE);
/* POINT */
- srna = RNA_def_struct(brna, "NParticleDataPoint", NULL);
+ srna = RNA_def_struct(brna, readonly ? "NParticleDataPointReadonly" : "NParticleDataPoint", NULL);
RNA_def_struct_ui_text(srna, "Particle Point Data", "");
prop = RNA_def_property(srna, "value", PROP_FLOAT, PROP_TRANSLATION);
RNA_def_property_array(prop, 3);
- RNA_def_property_float_funcs(prop, "rna_NParticleDataVector_get", "rna_NParticleDataVector_set", NULL);
+ RNA_def_property_float_funcs(prop, "rna_NParticleDataVector_get", readonly ? NULL : "rna_NParticleDataVector_set", NULL);
RNA_def_property_ui_text(prop, "Value", "");
+ if (readonly)
+ RNA_def_property_clear_flag(prop, PROP_EDITABLE);
/* NORMAL */
- srna = RNA_def_struct(brna, "NParticleDataNormal", NULL);
+ srna = RNA_def_struct(brna, readonly ? "NParticleDataNormalReadonly" : "NParticleDataNormal", NULL);
RNA_def_struct_ui_text(srna, "Particle Normal Data", "");
prop = RNA_def_property(srna, "value", PROP_FLOAT, PROP_DIRECTION);
RNA_def_property_array(prop, 3);
- RNA_def_property_float_funcs(prop, "rna_NParticleDataVector_get", "rna_NParticleDataVector_set", NULL);
+ RNA_def_property_float_funcs(prop, "rna_NParticleDataVector_get", readonly ? NULL : "rna_NParticleDataVector_set", NULL);
RNA_def_property_ui_text(prop, "Value", "");
+ if (readonly)
+ RNA_def_property_clear_flag(prop, PROP_EDITABLE);
/* COLOR */
- srna = RNA_def_struct(brna, "NParticleDataColor", NULL);
+ srna = RNA_def_struct(brna, readonly ? "NParticleDataColorReadonly" : "NParticleDataColor", NULL);
RNA_def_struct_ui_text(srna, "Particle Color Data", "");
prop = RNA_def_property(srna, "value", PROP_FLOAT, PROP_COLOR);
RNA_def_property_array(prop, 4);
- RNA_def_property_float_funcs(prop, "rna_NParticleDataColor_get", "rna_NParticleDataColor_set", NULL);
+ RNA_def_property_float_funcs(prop, "rna_NParticleDataColor_get", readonly ? NULL : "rna_NParticleDataColor_set", NULL);
RNA_def_property_ui_text(prop, "Value", "");
+ if (readonly)
+ RNA_def_property_clear_flag(prop, PROP_EDITABLE);
/* MATRIX */
- srna = RNA_def_struct(brna, "NParticleDataMatrix", NULL);
+ srna = RNA_def_struct(brna, readonly ? "NParticleDataMatrixReadonly" : "NParticleDataMatrix", NULL);
RNA_def_struct_ui_text(srna, "Particle Matrix Data", "");
prop = RNA_def_property(srna, "value", PROP_FLOAT, PROP_MATRIX);
RNA_def_property_array(prop, 16);
- RNA_def_property_float_funcs(prop, "rna_NParticleDataMatrix_get", "rna_NParticleDataMatrix_set", NULL);
+ RNA_def_property_float_funcs(prop, "rna_NParticleDataMatrix_get", readonly ? NULL : "rna_NParticleDataMatrix_set", NULL);
RNA_def_property_ui_text(prop, "Value", "");
+ if (readonly)
+ RNA_def_property_clear_flag(prop, PROP_EDITABLE);
+}
+
+static void rna_def_nparticle_attribute_state(BlenderRNA *brna)
+{
+ StructRNA *srna;
+
+ srna = RNA_def_struct(brna, "NParticleAttributeState", NULL);
+ RNA_def_struct_sdna(srna, "NParticleAttributeState");
+ RNA_def_struct_ui_text(srna, "Particle Attribute State", "Data for a particle attribute");
+ RNA_def_struct_refine_func(srna, "rna_NParticleAttributeState_refine");
+
+ def_nparticle_attribute_description(srna, 0, NULL, NULL);
+
+ rna_def_nparticle_attribute_data_types(brna, false);
+ rna_def_nparticle_attribute_data_types(brna, true);
#define DEF_ATTR_TYPE_RNA(lcase, ucase) \
def_nparticle_attribute_state_type(brna, "NParticleAttributeState"#ucase, "NParticleData"#ucase, \
More information about the Bf-blender-cvs
mailing list