[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [17525] branches/blender2.5/blender/source /blender/makesrna: RNA

Brecht Van Lommel brecht at blender.org
Fri Nov 21 03:23:48 CET 2008


Revision: 17525
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=17525
Author:   blendix
Date:     2008-11-21 03:23:46 +0100 (Fri, 21 Nov 2008)

Log Message:
-----------
RNA

* More ID property support. What was already possible was showing
  ID properties as RNA properties. Now it is possible to define
  RNA properties and have an ID property automatically created the
  first time it is set (if not set it retuns the default).

* Added support for defining RNA structs and properties at runtime.
  This is useful for python and plugins, and could also be used
  for operators, not sure yet what is best there, they could be done
  in preprocess for speed, but not sure how to do that while keeping
  operator registration a single function.

* Added quick functions to get/set properties based on names, to be
  used for operators.

* Added some simple support for inheritance, was already doing this
  but having it as a feature simplifies things. Two things were added
  for this: when defining a struct you can give a 'from' struct whose
  properties will be copied, and structs like ID, operator, modifier,
  can define a refine callback that will return the more specific type
  of the struct like ID -> Object, Mesh, .. .

* Added simple windowmanager wrap with only the registered operators
  list, used for testing RNA for operators.

Modified Paths:
--------------
    branches/blender2.5/blender/source/blender/makesrna/RNA_access.h
    branches/blender2.5/blender/source/blender/makesrna/RNA_define.h
    branches/blender2.5/blender/source/blender/makesrna/RNA_types.h
    branches/blender2.5/blender/source/blender/makesrna/intern/makesrna.c
    branches/blender2.5/blender/source/blender/makesrna/intern/rna_ID.c
    branches/blender2.5/blender/source/blender/makesrna/intern/rna_access.c
    branches/blender2.5/blender/source/blender/makesrna/intern/rna_define.c
    branches/blender2.5/blender/source/blender/makesrna/intern/rna_internal.h
    branches/blender2.5/blender/source/blender/makesrna/intern/rna_internal_types.h
    branches/blender2.5/blender/source/blender/makesrna/intern/rna_lamp.c
    branches/blender2.5/blender/source/blender/makesrna/intern/rna_main.c
    branches/blender2.5/blender/source/blender/makesrna/intern/rna_mesh.c
    branches/blender2.5/blender/source/blender/makesrna/intern/rna_object.c
    branches/blender2.5/blender/source/blender/makesrna/intern/rna_rna.c
    branches/blender2.5/blender/source/blender/makesrna/intern/rna_scene.c

Added Paths:
-----------
    branches/blender2.5/blender/source/blender/makesrna/intern/rna_wm.c

Modified: branches/blender2.5/blender/source/blender/makesrna/RNA_access.h
===================================================================
--- branches/blender2.5/blender/source/blender/makesrna/RNA_access.h	2008-11-21 01:54:00 UTC (rev 17524)
+++ branches/blender2.5/blender/source/blender/makesrna/RNA_access.h	2008-11-21 02:23:46 UTC (rev 17525)
@@ -30,6 +30,8 @@
 struct bContext;
 struct Main;
 
+extern BlenderRNA BLENDER_RNA;
+
 /* Pointer
  *
  * Currently only an RNA pointer to Main can be obtained, this
@@ -45,6 +47,8 @@
 PropertyRNA *RNA_struct_name_property(PointerRNA *ptr);
 PropertyRNA *RNA_struct_iterator_property(PointerRNA *ptr);
 
+PropertyRNA *RNA_struct_find_property(PointerRNA *ptr, const char *identifier);
+
 /* Properties
  *
  * Access to struct properties. All this works with RNA pointers rather than
@@ -103,7 +107,6 @@
 
 void RNA_property_pointer_get(PropertyRNA *prop, PointerRNA *ptr, PointerRNA *r_ptr);
 void RNA_property_pointer_set(PropertyRNA *prop, PointerRNA *ptr, PointerRNA *ptr_value);
-StructRNA *RNA_property_pointer_type(PropertyRNA *prop, PointerRNA *ptr);
 
 void RNA_property_collection_begin(PropertyRNA *prop, CollectionPropertyIterator *iter, PointerRNA *ptr);
 void RNA_property_collection_next(PropertyRNA *prop, CollectionPropertyIterator *iter);
@@ -142,5 +145,54 @@
 void RNA_generate_dependencies(PointerRNA *mainptr, void *udata, PropDependencyCallback cb);
 #endif
 
+/* Quick name based property access
+ *
+ * These are just an easier way to access property values without having to
+ * call RNA_struct_find_property. The names have to exist as RNA properties
+ * for the type in the pointer, if they do not exist an error will be printed.
+ *
+ * The get and set functions work like the corresponding functions above, the
+ * default functions are intended to be used for runtime / id properties
+ * specifically. They will set the value only if the id property does not yet
+ * exist, and return the current value. This is useful to set inputs in an
+ * operator, avoiding to overwrite them if they were specified by the caller.
+ *
+ * There is no support for pointers and collections here yet, these can be 
+ * added when ID properties support them. */
+
+int RNA_boolean_get(PointerRNA *ptr, const char *name);
+void RNA_boolean_set(PointerRNA *ptr, const char *name, int value);
+int RNA_boolean_default(PointerRNA *ptr, const char *name, int value);
+void RNA_boolean_get_array(PointerRNA *ptr, const char *name, int *values);
+void RNA_boolean_set_array(PointerRNA *ptr, const char *name, const int *values);
+void RNA_boolean_default_array(PointerRNA *ptr, const char *name, int *values);
+
+int RNA_int_get(PointerRNA *ptr, const char *name);
+void RNA_int_set(PointerRNA *ptr, const char *name, int value);
+int RNA_int_default(PointerRNA *ptr, const char *name, int value);
+void RNA_int_get_array(PointerRNA *ptr, const char *name, int *values);
+void RNA_int_set_array(PointerRNA *ptr, const char *name, const int *values);
+void RNA_int_default_array(PointerRNA *ptr, const char *name, int *values);
+
+float RNA_float_get(PointerRNA *ptr, const char *name);
+void RNA_float_set(PointerRNA *ptr, const char *name, float value);
+float RNA_float_default(PointerRNA *ptr, const char *name, float value);
+void RNA_float_get_array(PointerRNA *ptr, const char *name, float *values);
+void RNA_float_set_array(PointerRNA *ptr, const char *name, const float *values);
+void RNA_float_default_array(PointerRNA *ptr, const char *name, float *values);
+
+int RNA_enum_get(PointerRNA *ptr, const char *name);
+void RNA_enum_set(PointerRNA *ptr, const char *name, int value);
+int RNA_enum_default(PointerRNA *ptr, const char *name, int value);
+
+void RNA_string_get(PointerRNA *ptr, const char *name, char *value);
+char *RNA_string_get_alloc(PointerRNA *ptr, const char *name, char *fixedbuf, int fixedlen);
+int RNA_string_length(PointerRNA *ptr, const char *name);
+void RNA_string_set(PointerRNA *ptr, const char *name, const char *value);
+void RNA_string_default(PointerRNA *ptr, const char *name, const char *value);
+
+/* check if the idproperty exists, for operators */
+int RNA_property_is_set(PointerRNA *ptr, const char *name);
+
 #endif /* RNA_ACCESS */
 

Modified: branches/blender2.5/blender/source/blender/makesrna/RNA_define.h
===================================================================
--- branches/blender2.5/blender/source/blender/makesrna/RNA_define.h	2008-11-21 01:54:00 UTC (rev 17524)
+++ branches/blender2.5/blender/source/blender/makesrna/RNA_define.h	2008-11-21 02:23:46 UTC (rev 17525)
@@ -25,12 +25,7 @@
 #ifndef RNA_DEFINE_H
 #define RNA_DEFINE_H
 
-/* Functions used during preprocess, for defining the RNA.
- *
- * This is currently only used internally in the module, but should eventually
- * also become available outside of that, at runtime for python and plugins.
- * Where the result of such runtime RNA is stored and how it integrates needs
- * to be figured out still. */
+/* Functions used during preprocess and runtime, for defining the RNA. */
 
 #include "DNA_listBase.h"
 #include "RNA_types.h"
@@ -40,13 +35,16 @@
 BlenderRNA *RNA_create(void);
 void RNA_define_free(BlenderRNA *brna);
 void RNA_free(BlenderRNA *brna);
+void RNA_exit(void);
 
 /* Struct */
 
-StructRNA *RNA_def_struct(BlenderRNA *brna, const char *identifier, const char *name);
+StructRNA *RNA_def_struct(BlenderRNA *brna, const char *identifier, const char *from, const char *name);
 void RNA_def_struct_sdna(StructRNA *srna, const char *structname);
 void RNA_def_struct_name_property(StructRNA *srna, PropertyRNA *prop);
 void RNA_def_struct_flag(StructRNA *srna, int flag);
+void RNA_def_struct_funcs(StructRNA *srna, const char *notify, const char *refine);
+void RNA_def_struct_identifier(StructRNA *srna, const char *identifier, const char *name);
 
 /* Property */
 
@@ -80,7 +78,7 @@
 void RNA_def_property_ui_text(PropertyRNA *prop, const char *name, const char *description);
 void RNA_def_property_ui_range(PropertyRNA *prop, double min, double max, double step, int precision);
 
-void RNA_def_property_funcs(PropertyRNA *prop, const char *notify, const char *readonly);
+void RNA_def_property_funcs(PropertyRNA *prop, const char *notify);
 void RNA_def_property_boolean_funcs(PropertyRNA *prop, const char *get, const char *set);
 void RNA_def_property_int_funcs(PropertyRNA *prop, const char *get, const char *set);
 void RNA_def_property_float_funcs(PropertyRNA *prop, const char *get, const char *set);

Modified: branches/blender2.5/blender/source/blender/makesrna/RNA_types.h
===================================================================
--- branches/blender2.5/blender/source/blender/makesrna/RNA_types.h	2008-11-21 01:54:00 UTC (rev 17524)
+++ branches/blender2.5/blender/source/blender/makesrna/RNA_types.h	2008-11-21 02:23:46 UTC (rev 17525)
@@ -96,7 +96,9 @@
 
 	/* internal flags */
 	PROP_BUILTIN = 128,
-	PROP_EXPORT = 256
+	PROP_EXPORT = 256,
+	PROP_RUNTIME = 512,
+	PROP_IDPROPERTY = 1024
 } PropertyFlag;
 
 typedef struct CollectionPropertyIterator {
@@ -120,7 +122,10 @@
 
 typedef enum StructFlag {
 	/* indicates that this struct is an ID struct */
-	STRUCT_ID = 1
+	STRUCT_ID = 1,
+
+	/* internal flags */
+	STRUCT_RUNTIME = 2
 } StructFlag;
 
 struct StructRNA;

Modified: branches/blender2.5/blender/source/blender/makesrna/intern/makesrna.c
===================================================================
--- branches/blender2.5/blender/source/blender/makesrna/intern/makesrna.c	2008-11-21 01:54:00 UTC (rev 17524)
+++ branches/blender2.5/blender/source/blender/makesrna/intern/makesrna.c	2008-11-21 02:23:46 UTC (rev 17525)
@@ -100,6 +100,9 @@
 {
 	char *func;
 
+	if(prop->flag & PROP_IDPROPERTY)
+		return NULL;
+
 	if(!dp->dnastructname || !dp->dnaname) {
 		fprintf(stderr, "rna_def_property_get_func: %s.%s has no valid dna info.\n", srna->identifier, prop->identifier);
 		DefRNA.error= 1;
@@ -195,6 +198,9 @@
 {
 	char *func;
 
+	if(prop->flag & PROP_IDPROPERTY)
+		return NULL;
+
 	if(!dp->dnastructname || !dp->dnaname) {
 		if(!(prop->flag & PROP_NOT_EDITABLE)) {
 			fprintf(stderr, "rna_def_property_set_func: %s.%s has no valid dna info.\n", srna->identifier, prop->identifier);
@@ -266,6 +272,9 @@
 {
 	char *func= NULL;
 
+	if(prop->flag & PROP_IDPROPERTY)
+		return NULL;
+
 	if(prop->type == PROP_STRING) {
 		if(!dp->dnastructname || !dp->dnaname) {
 			fprintf(stderr, "rna_def_property_length_func: %s.%s has no valid dna info.\n", srna->identifier, prop->identifier);
@@ -304,6 +313,9 @@
 {
 	char *func;
 
+	if(prop->flag & PROP_IDPROPERTY)
+		return NULL;
+
 	if(!dp->dnastructname || !dp->dnaname) {
 		fprintf(stderr, "rna_def_property_begin_func: %s.%s has no valid dna info.\n", srna->identifier, prop->identifier);
 		DefRNA.error= 1;
@@ -741,8 +753,13 @@
 	if(prop) fprintf(f, "\t(PropertyRNA*)&rna_%s_%s, ", srna->identifier, prop->identifier);
 	else fprintf(f, "\tNULL, ");
 
-	fprintf(f, "\t(PropertyRNA*)&rna_%s_rna_properties,\n", srna->identifier);
+	fprintf(f, "(PropertyRNA*)&rna_%s_rna_properties,\n", srna->identifier);
 
+	if(srna->from) fprintf(f, "\t&RNA_%s,\n", (char*)srna->from);
+	else fprintf(f, "\tNULL,\n");
+
+	fprintf(f, "\t%s, %s,\n", rna_function_string(srna->notify), rna_function_string(srna->refine));
+
 	prop= srna->properties.first;
 	if(prop) fprintf(f, "\t{(PropertyRNA*)&rna_%s_%s, ", srna->identifier, prop->identifier);
 	else fprintf(f, "\t{NULL, ");
@@ -762,13 +779,14 @@
 } RNAProcessItem;
 
 RNAProcessItem PROCESS_ITEMS[]= {
-	{"rna_ID.c", RNA_def_ID_types},
+	{"rna_ID.c", RNA_def_ID},
 	{"rna_main.c", RNA_def_main},
 	{"rna_mesh.c", RNA_def_mesh},
 	{"rna_object.c", RNA_def_object},
 	{"rna_rna.c", RNA_def_rna},
 	{"rna_scene.c", RNA_def_scene},
 	{"rna_lamp.c", RNA_def_lamp},
+	{"rna_wm.c", RNA_def_wm},
 	{NULL, NULL}};
 
 static int rna_preprocess(char *basedirectory, FILE *f)
@@ -795,6 +813,10 @@
 	fprintf(f, "#include \"RNA_types.h\"\n");
 	fprintf(f, "#include \"rna_internal.h\"\n\n");
 
+	/* this is ugly, but we cannot have c files compiled for both
+	 * makesrna and blender with some build systems at the moment */
+	fprintf(f, "#include \"rna_define.c\"\n\n");
+
 	for(i=0; PROCESS_ITEMS[i].filename; i++)
 		if(PROCESS_ITEMS[i].define)
 			PROCESS_ITEMS[i].define(brna);

Modified: branches/blender2.5/blender/source/blender/makesrna/intern/rna_ID.c
===================================================================

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list