[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [22355] branches/blender2.5/blender/source /blender: RNA: subtypes and units

Brecht Van Lommel brecht at blender.org
Mon Aug 10 23:31:08 CEST 2009


Revision: 22355
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=22355
Author:   blendix
Date:     2009-08-10 23:31:05 +0200 (Mon, 10 Aug 2009)

Log Message:
-----------
RNA: subtypes and units

* Reviewed subtypes, making them more specific and adding new ones.
* Subtypes now have an associated type of units (length, area, volume,
  mass, rotation, time, velocity, acceleration). These are not used
  yet anywhere.
* Centralized code that decides the name of array items based on
  subtype (XYZ, RGB), was copied in 3 places.
* RNA_def_float etc functions still need to be update, will do this
  later together with another change.

Modified Paths:
--------------
    branches/blender2.5/blender/source/blender/editors/animation/anim_ipo_utils.c
    branches/blender2.5/blender/source/blender/editors/interface/interface_layout.c
    branches/blender2.5/blender/source/blender/editors/space_outliner/outliner.c
    branches/blender2.5/blender/source/blender/makesrna/RNA_access.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_access.c
    branches/blender2.5/blender/source/blender/makesrna/intern/rna_armature.c
    branches/blender2.5/blender/source/blender/makesrna/intern/rna_brush.c
    branches/blender2.5/blender/source/blender/makesrna/intern/rna_cloth.c
    branches/blender2.5/blender/source/blender/makesrna/intern/rna_color.c
    branches/blender2.5/blender/source/blender/makesrna/intern/rna_constraint.c
    branches/blender2.5/blender/source/blender/makesrna/intern/rna_curve.c
    branches/blender2.5/blender/source/blender/makesrna/intern/rna_define.c
    branches/blender2.5/blender/source/blender/makesrna/intern/rna_fcurve.c
    branches/blender2.5/blender/source/blender/makesrna/intern/rna_fluidsim.c
    branches/blender2.5/blender/source/blender/makesrna/intern/rna_group.c
    branches/blender2.5/blender/source/blender/makesrna/intern/rna_image.c
    branches/blender2.5/blender/source/blender/makesrna/intern/rna_key.c
    branches/blender2.5/blender/source/blender/makesrna/intern/rna_lamp.c
    branches/blender2.5/blender/source/blender/makesrna/intern/rna_lattice.c
    branches/blender2.5/blender/source/blender/makesrna/intern/rna_material.c
    branches/blender2.5/blender/source/blender/makesrna/intern/rna_mesh.c
    branches/blender2.5/blender/source/blender/makesrna/intern/rna_meta.c
    branches/blender2.5/blender/source/blender/makesrna/intern/rna_modifier.c
    branches/blender2.5/blender/source/blender/makesrna/intern/rna_nla.c
    branches/blender2.5/blender/source/blender/makesrna/intern/rna_nodetree.c
    branches/blender2.5/blender/source/blender/makesrna/intern/rna_object.c
    branches/blender2.5/blender/source/blender/makesrna/intern/rna_object_force.c
    branches/blender2.5/blender/source/blender/makesrna/intern/rna_particle.c
    branches/blender2.5/blender/source/blender/makesrna/intern/rna_pose.c
    branches/blender2.5/blender/source/blender/makesrna/intern/rna_rna.c
    branches/blender2.5/blender/source/blender/makesrna/intern/rna_scene.c
    branches/blender2.5/blender/source/blender/makesrna/intern/rna_sequence.c
    branches/blender2.5/blender/source/blender/makesrna/intern/rna_texture.c
    branches/blender2.5/blender/source/blender/makesrna/intern/rna_timeline.c
    branches/blender2.5/blender/source/blender/makesrna/intern/rna_userdef.c
    branches/blender2.5/blender/source/blender/makesrna/intern/rna_wm.c
    branches/blender2.5/blender/source/blender/makesrna/intern/rna_world.c
    branches/blender2.5/blender/source/blender/python/intern/bpy_rna.c

Modified: branches/blender2.5/blender/source/blender/editors/animation/anim_ipo_utils.c
===================================================================
--- branches/blender2.5/blender/source/blender/editors/animation/anim_ipo_utils.c	2009-08-10 21:10:09 UTC (rev 22354)
+++ branches/blender2.5/blender/source/blender/editors/animation/anim_ipo_utils.c	2009-08-10 21:31:05 UTC (rev 22355)
@@ -149,25 +149,13 @@
 			
 			/* Array Index - only if applicable */
 			if (RNA_property_array_length(prop)) {
-				static char *vectoritem[4]= {"X ", "Y ", "Z ", "W "};
-				static char *quatitem[4]= {"W ", "X ", "Y ", "Z "};
-				static char *coloritem[4]= {"R ", "G ", "B ", "A "};
+				char c= RNA_property_array_item_char(prop, fcu->array_index);
 				
-				int tot= RNA_property_array_length(prop);
-				int propsubtype= RNA_property_subtype(prop);
-				
-				/* get string to use for array index */
-				if ((tot == 4) && (propsubtype == PROP_ROTATION))
-					arrayname= quatitem[fcu->array_index];
-				else if ( (tot <= 4) && ((propsubtype == PROP_VECTOR) || (propsubtype == PROP_ROTATION)) )
-					arrayname= vectoritem[fcu->array_index];
-				else if ((tot <= 4) && (propsubtype == PROP_COLOR))
-					arrayname= coloritem[fcu->array_index];
-				else {
-					/* we need to write the index to a temp buffer (in py syntax), as it is a number... */
-					sprintf(arrayindbuf, "[%d]", fcu->array_index);
-					arrayname= &arrayindbuf[0];
-				}
+				/* we need to write the index to a temp buffer (in py syntax) */
+				if(c) sprintf(arrayindbuf, "%c ", c);
+				else sprintf(arrayindbuf, "[%d]", fcu->array_index);
+
+				arrayname= &arrayindbuf[0];
 			}
 			else {
 				/* no array index */

Modified: branches/blender2.5/blender/source/blender/editors/interface/interface_layout.c
===================================================================
--- branches/blender2.5/blender/source/blender/editors/interface/interface_layout.c	2009-08-10 21:10:09 UTC (rev 22354)
+++ branches/blender2.5/blender/source/blender/editors/interface/interface_layout.c	2009-08-10 21:31:05 UTC (rev 22355)
@@ -379,51 +379,38 @@
 				but->type= NUMSLI;
 		}
 	}
-	else if(len <= 4 && ELEM3(subtype, PROP_ROTATION, PROP_VECTOR, PROP_COLOR)) {
-		if(subtype == PROP_COLOR)
+	else {
+		if(ELEM(subtype, PROP_COLOR, PROP_RGB))
 			uiDefAutoButR(block, ptr, prop, -1, "", 0, 0, 0, w, UI_UNIT_Y);
 
-		if(subtype != PROP_COLOR || expand) {
+		if(!ELEM(subtype, PROP_COLOR, PROP_RGB) || expand) {
 			/* layout for known array subtypes */
-			static char vectoritem[4]= {'X', 'Y', 'Z', 'W'};
-			static char quatitem[4]= {'W', 'X', 'Y', 'Z'};
-			static char coloritem[4]= {'R', 'G', 'B', 'A'};
 			char str[3];
 
 			for(a=0; a<len; a++) {
-				if(len == 4 && subtype == PROP_ROTATION)
-					str[0]= quatitem[a];
-				else if(subtype == PROP_VECTOR || subtype == PROP_ROTATION)
-					str[0]= vectoritem[a];
-				else
-					str[0]= coloritem[a];
+				str[0]= RNA_property_array_item_char(prop, a);
 
-				if(type == PROP_BOOLEAN) {
-					str[1]= '\0';
+				if(str[0]) {
+					if(type == PROP_BOOLEAN) {
+						str[1]= '\0';
+					}
+					else {
+						str[1]= ':';
+						str[2]= '\0';
+					}
 				}
-				else {
-					str[1]= ':';
-					str[2]= '\0';
-				}
 
 				but= uiDefAutoButR(block, ptr, prop, a, str, 0, 0, 0, w, UI_UNIT_Y);
 				if(slider && but->type==NUM)
 					but->type= NUMSLI;
 			}
 		}
-		else if(subtype == PROP_COLOR && len == 4) {
+		else if(ELEM(subtype, PROP_COLOR, PROP_RGB) && len == 4) {
 			but= uiDefAutoButR(block, ptr, prop, 3, "A:", 0, 0, 0, w, UI_UNIT_Y);
 			if(slider && but->type==NUM)
 				but->type= NUMSLI;
 		}
 	}
-	else {
-		for(a=0; a<len; a++) {
-			but= uiDefAutoButR(block, ptr, prop, a, "", 0, 0, 0, w, UI_UNIT_Y);
-			if(slider && but->type==NUM)
-				but->type= NUMSLI;
-		}
-	}
 
 	uiBlockSetCurLayout(block, layout);
 }

Modified: branches/blender2.5/blender/source/blender/editors/space_outliner/outliner.c
===================================================================
--- branches/blender2.5/blender/source/blender/editors/space_outliner/outliner.c	2009-08-10 21:10:09 UTC (rev 22354)
+++ branches/blender2.5/blender/source/blender/editors/space_outliner/outliner.c	2009-08-10 21:31:05 UTC (rev 22355)
@@ -1096,31 +1096,20 @@
 			}
 		}
 		else if(type == TSE_RNA_ARRAY_ELEM) {
-			/* array property element */
-			static char *vectoritem[4]= {"  x", "  y", "  z", "  w"};
-			static char *quatitem[4]= {"  w", "  x", "  y", "  z"};
-			static char *coloritem[4]= {"  r", "  g", "  b", "  a"};
+			char c;
 
 			prop= parent->directdata;
-			proptype= RNA_property_type(prop);
-			propsubtype= RNA_property_subtype(prop);
-			tot= RNA_property_array_length(prop);
 
 			te->directdata= prop;
 			te->rnaptr= *ptr;
 			te->index= index;
 
-			if(tot == 4 && propsubtype == PROP_ROTATION)
-				te->name= quatitem[index];
-			else if(tot <= 4 && (propsubtype == PROP_VECTOR || propsubtype == PROP_ROTATION))
-				te->name= vectoritem[index];
-			else if(tot <= 4 && propsubtype == PROP_COLOR)
-				te->name= coloritem[index];
-			else {
-				te->name= MEM_callocN(sizeof(char)*20, "OutlinerRNAArrayName");
-				sprintf(te->name, "  %d", index+1);
-				te->flag |= TE_FREE_NAME;
-			}
+			c= RNA_property_array_item_char(prop, index);
+
+			te->name= MEM_callocN(sizeof(char)*20, "OutlinerRNAArrayName");
+			if(c) sprintf(te->name, "  %c", c);
+			else sprintf(te->name, "  %d", index+1);
+			te->flag |= TE_FREE_NAME;
 		}
 	}
 	else if(type == TSE_KEYMAP) {

Modified: branches/blender2.5/blender/source/blender/makesrna/RNA_access.h
===================================================================
--- branches/blender2.5/blender/source/blender/makesrna/RNA_access.h	2009-08-10 21:10:09 UTC (rev 22354)
+++ branches/blender2.5/blender/source/blender/makesrna/RNA_access.h	2009-08-10 21:31:05 UTC (rev 22355)
@@ -559,9 +559,11 @@
 const char *RNA_property_identifier(PropertyRNA *prop);
 PropertyType RNA_property_type(PropertyRNA *prop);
 PropertySubType RNA_property_subtype(PropertyRNA *prop);
+PropertyUnit RNA_property_unit(PropertyRNA *prop);
 int RNA_property_flag(PropertyRNA *prop);
 
 int RNA_property_array_length(PropertyRNA *prop);
+char RNA_property_array_item_char(PropertyRNA *prop, int index);
 
 int RNA_property_string_maxlength(PropertyRNA *prop);
 

Modified: branches/blender2.5/blender/source/blender/makesrna/RNA_types.h
===================================================================
--- branches/blender2.5/blender/source/blender/makesrna/RNA_types.h	2009-08-10 21:10:09 UTC (rev 22354)
+++ branches/blender2.5/blender/source/blender/makesrna/RNA_types.h	2009-08-10 21:31:05 UTC (rev 22355)
@@ -66,17 +66,49 @@
 	PROP_COLLECTION = 6
 } PropertyType;
 
+typedef enum PropertyUnit {
+	PROP_UNIT_NONE = (0<<16),
+	PROP_UNIT_LENGTH = (1<<16),			/* m */
+	PROP_UNIT_AREA = (2<<16),			/* m^2 */
+	PROP_UNIT_VOLUME = (3<<16),			/* m^3 */
+	PROP_UNIT_MASS = (4<<16),			/* kg */
+	PROP_UNIT_ROTATION = (5<<16),		/* rad */
+	PROP_UNIT_TIME = (6<<16),			/* frame */
+	PROP_UNIT_VELOCITY = (7<<16),		/* m/s */
+	PROP_UNIT_ACCELERATION = (8<<16)	/* m/(s^2) */
+} PropertyUnit;
+
+#define RNA_SUBTYPE_UNIT(subtype) (subtype & 0x00FF0000)
+
+/* also update rna_property_subtypename when you change this */
 typedef enum PropertySubType {
 	PROP_NONE = 0,
-	PROP_UNSIGNED = 1,
-	PROP_FILEPATH = 2,
-	PROP_DIRPATH = 3,
-	PROP_COLOR = 4,
-	PROP_VECTOR = 5,
-	PROP_MATRIX = 6,
-	PROP_ROTATION = 7,
-	PROP_NEVER_NULL = 8,
-	PROP_PERCENTAGE = 9
+
+	/* strings */
+	PROP_FILEPATH = 1,
+	PROP_DIRPATH = 2,
+
+	/* numbers */
+	PROP_UNSIGNED = 13,
+	PROP_PERCENTAGE = 14,
+	PROP_ANGLE = 15|PROP_UNIT_ROTATION,
+	PROP_TIME = 16|PROP_UNIT_TIME,
+	PROP_DISTANCE = 17|PROP_UNIT_LENGTH,
+
+	/* number arrays */
+	PROP_COLOR = 20,
+	PROP_TRANSLATION = 21|PROP_UNIT_LENGTH,
+	PROP_DIRECTION = 22,
+	PROP_VELOCITY = 23|PROP_UNIT_VELOCITY,
+	PROP_ACCELERATION = 24|PROP_UNIT_ACCELERATION,
+	PROP_MATRIX = 25,
+	PROP_EULER = 26|PROP_UNIT_ROTATION,
+	PROP_QUATERNION = 27,
+	PROP_XYZ = 28,
+	PROP_RGB = 29,
+
+	/* pointers */
+	PROP_NEVER_NULL = 30,
 } PropertySubType;
 
 typedef enum PropertyFlag {

Modified: branches/blender2.5/blender/source/blender/makesrna/intern/makesrna.c
===================================================================
--- branches/blender2.5/blender/source/blender/makesrna/intern/makesrna.c	2009-08-10 21:10:09 UTC (rev 22354)
+++ branches/blender2.5/blender/source/blender/makesrna/intern/makesrna.c	2009-08-10 21:31:05 UTC (rev 22355)
@@ -1370,15 +1370,24 @@
 {
 	switch(type) {
 		case PROP_NONE: return "PROP_NONE";
-		case PROP_UNSIGNED: return "PROP_UNSIGNED";
 		case PROP_FILEPATH: return "PROP_FILEPATH";
 		case PROP_DIRPATH: return "PROP_DIRPATH";
+		case PROP_UNSIGNED: return "PROP_UNSIGNED";
+		case PROP_PERCENTAGE: return "PROP_PERCENTAGE";
+		case PROP_ANGLE: return "PROP_ANGLE";
+		case PROP_TIME: return "PROP_TIME";
+		case PROP_DISTANCE: return "PROP_DISTANCE";
 		case PROP_COLOR: return "PROP_COLOR";
-		case PROP_VECTOR: return "PROP_VECTOR";
+		case PROP_TRANSLATION: return "PROP_TRANSLATION";
+		case PROP_DIRECTION: return "PROP_DIRECTION";
 		case PROP_MATRIX: return "PROP_MATRIX";
-		case PROP_ROTATION: return "PROP_ROTATION";
+		case PROP_EULER: return "PROP_EULER";
+		case PROP_QUATERNION: return "PROP_QUATERNION";
+		case PROP_VELOCITY: return "PROP_VELOCITY";
+		case PROP_ACCELERATION: return "PROP_ACCELERATION";
+		case PROP_XYZ: return "PROP_XYZ";
+		case PROP_RGB: return "PROP_RGB";
 		case PROP_NEVER_NULL: return "PROP_NEVER_NULL";
-		case PROP_PERCENTAGE: return "PROP_PERCENTAGE";
 		default: return "PROP_UNKNOWN";
 	}
 }
@@ -2194,7 +2203,7 @@
 	fprintf(f, "#include \"RNA_blender.h\"\n");
 	fprintf(f, "#include \"RNA_types.h\"\n");
 
-	fprintf(f, cpp_classes);
+	fprintf(f, "%s", cpp_classes);
 
 	fprintf(f, "/**************** Declarations ****************/\n\n");
 

Modified: branches/blender2.5/blender/source/blender/makesrna/intern/rna_access.c
===================================================================
--- branches/blender2.5/blender/source/blender/makesrna/intern/rna_access.c	2009-08-10 21:10:09 UTC (rev 22354)
+++ branches/blender2.5/blender/source/blender/makesrna/intern/rna_access.c	2009-08-10 21:31:05 UTC (rev 22355)
@@ -539,6 +539,11 @@
 	return rna_ensure_property(prop)->subtype;
 }
 
+PropertyUnit RNA_property_unit(PropertyRNA *prop)
+{
+	return RNA_SUBTYPE_UNIT(rna_ensure_property(prop)->subtype);
+}
+
 int RNA_property_flag(PropertyRNA *prop)
 {

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list