[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [48990] branches/soc-2012-bratwurst: Added a "clear" function for bit-field boolean RNA properties, used by a " clearfield" parameter for the "prop" command.

Jorge Rodriguez bs.vino at gmail.com
Tue Jul 17 05:05:46 CEST 2012


Revision: 48990
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=48990
Author:   vino
Date:     2012-07-17 03:05:42 +0000 (Tue, 17 Jul 2012)
Log Message:
-----------
Added a "clear" function for bit-field boolean RNA properties, used by a "clearfield" parameter for the "prop" command. This allows python scripts to create buttons which clear the entire bitfield before setting a value, thus enabling mutually exclusive buttons where only one can be toggled at a time. This behavior can be overridden if shift is held down by the user. All of this is used by the TRS floating buttons so that clicking one clears the others.

Modified Paths:
--------------
    branches/soc-2012-bratwurst/release/scripts/startup/bl_ui/space_view3d.py
    branches/soc-2012-bratwurst/source/blender/editors/include/UI_interface.h
    branches/soc-2012-bratwurst/source/blender/editors/interface/interface.c
    branches/soc-2012-bratwurst/source/blender/editors/interface/interface_layout.c
    branches/soc-2012-bratwurst/source/blender/makesrna/RNA_access.h
    branches/soc-2012-bratwurst/source/blender/makesrna/RNA_define.h
    branches/soc-2012-bratwurst/source/blender/makesrna/intern/makesrna.c
    branches/soc-2012-bratwurst/source/blender/makesrna/intern/rna_ID.c
    branches/soc-2012-bratwurst/source/blender/makesrna/intern/rna_access.c
    branches/soc-2012-bratwurst/source/blender/makesrna/intern/rna_actuator.c
    branches/soc-2012-bratwurst/source/blender/makesrna/intern/rna_armature.c
    branches/soc-2012-bratwurst/source/blender/makesrna/intern/rna_brush.c
    branches/soc-2012-bratwurst/source/blender/makesrna/intern/rna_color.c
    branches/soc-2012-bratwurst/source/blender/makesrna/intern/rna_define.c
    branches/soc-2012-bratwurst/source/blender/makesrna/intern/rna_dynamicpaint.c
    branches/soc-2012-bratwurst/source/blender/makesrna/intern/rna_fcurve.c
    branches/soc-2012-bratwurst/source/blender/makesrna/intern/rna_image.c
    branches/soc-2012-bratwurst/source/blender/makesrna/intern/rna_internal_types.h
    branches/soc-2012-bratwurst/source/blender/makesrna/intern/rna_lamp.c
    branches/soc-2012-bratwurst/source/blender/makesrna/intern/rna_lattice.c
    branches/soc-2012-bratwurst/source/blender/makesrna/intern/rna_main.c
    branches/soc-2012-bratwurst/source/blender/makesrna/intern/rna_main_api.c
    branches/soc-2012-bratwurst/source/blender/makesrna/intern/rna_material.c
    branches/soc-2012-bratwurst/source/blender/makesrna/intern/rna_mesh.c
    branches/soc-2012-bratwurst/source/blender/makesrna/intern/rna_modifier.c
    branches/soc-2012-bratwurst/source/blender/makesrna/intern/rna_nla.c
    branches/soc-2012-bratwurst/source/blender/makesrna/intern/rna_object.c
    branches/soc-2012-bratwurst/source/blender/makesrna/intern/rna_object_force.c
    branches/soc-2012-bratwurst/source/blender/makesrna/intern/rna_particle.c
    branches/soc-2012-bratwurst/source/blender/makesrna/intern/rna_pose.c
    branches/soc-2012-bratwurst/source/blender/makesrna/intern/rna_rna.c
    branches/soc-2012-bratwurst/source/blender/makesrna/intern/rna_scene.c
    branches/soc-2012-bratwurst/source/blender/makesrna/intern/rna_screen.c
    branches/soc-2012-bratwurst/source/blender/makesrna/intern/rna_sculpt_paint.c
    branches/soc-2012-bratwurst/source/blender/makesrna/intern/rna_sensor.c
    branches/soc-2012-bratwurst/source/blender/makesrna/intern/rna_sequencer.c
    branches/soc-2012-bratwurst/source/blender/makesrna/intern/rna_sound.c
    branches/soc-2012-bratwurst/source/blender/makesrna/intern/rna_space.c
    branches/soc-2012-bratwurst/source/blender/makesrna/intern/rna_text.c
    branches/soc-2012-bratwurst/source/blender/makesrna/intern/rna_texture.c
    branches/soc-2012-bratwurst/source/blender/makesrna/intern/rna_tracking.c
    branches/soc-2012-bratwurst/source/blender/makesrna/intern/rna_ui.c
    branches/soc-2012-bratwurst/source/blender/makesrna/intern/rna_ui_api.c
    branches/soc-2012-bratwurst/source/blender/makesrna/intern/rna_wm.c

Modified: branches/soc-2012-bratwurst/release/scripts/startup/bl_ui/space_view3d.py
===================================================================
--- branches/soc-2012-bratwurst/release/scripts/startup/bl_ui/space_view3d.py	2012-07-16 23:29:12 UTC (rev 48989)
+++ branches/soc-2012-bratwurst/release/scripts/startup/bl_ui/space_view3d.py	2012-07-17 03:05:42 UTC (rev 48990)
@@ -2721,9 +2721,9 @@
             row.alignment = 'CENTER'
             row.scale_x = 1.5
             row.scale_y = 1.5
-            row.prop(view, "use_manipulator_translate", text="", icon='MAN_TRANS')
-            row.prop(view, "use_manipulator_rotate", text="", icon='MAN_ROT')
-            row.prop(view, "use_manipulator_scale", text="", icon='MAN_SCALE')
+            row.prop(view, "use_manipulator_translate", text="", icon='MAN_TRANS', clearfield=True)
+            row.prop(view, "use_manipulator_rotate", text="", icon='MAN_ROT', clearfield=True)
+            row.prop(view, "use_manipulator_scale", text="", icon='MAN_SCALE', clearfield=True)
 
         elif bpy.context.user_preferences.edit.floating_controls == 'LEFT' or bpy.context.user_preferences.edit.floating_controls == 'RIGHT':
             layout = self.layout
@@ -2736,9 +2736,9 @@
             column.alignment = 'CENTER'
             column.scale_x = 1.5
             column.scale_y = 1.5
-            column.prop(view, "use_manipulator_translate", text="", icon='MAN_TRANS')
-            column.prop(view, "use_manipulator_rotate", text="", icon='MAN_ROT')
-            column.prop(view, "use_manipulator_scale", text="", icon='MAN_SCALE')
+            column.prop(view, "use_manipulator_translate", text="", icon='MAN_TRANS', clearfield=True)
+            column.prop(view, "use_manipulator_rotate", text="", icon='MAN_ROT', clearfield=True)
+            column.prop(view, "use_manipulator_scale", text="", icon='MAN_SCALE', clearfield=True)
 
 
 

Modified: branches/soc-2012-bratwurst/source/blender/editors/include/UI_interface.h
===================================================================
--- branches/soc-2012-bratwurst/source/blender/editors/include/UI_interface.h	2012-07-16 23:29:12 UTC (rev 48989)
+++ branches/soc-2012-bratwurst/source/blender/editors/include/UI_interface.h	2012-07-17 03:05:42 UTC (rev 48990)
@@ -143,7 +143,7 @@
 #define UI_TEXT_RIGHT       1024
 #define UI_BUT_NODE_LINK    2048
 #define UI_BUT_NODE_ACTIVE  4096
-#define UI_FLAG_UNUSED      8192
+#define UI_CLEAR_BITFIELD   8192
 
 /* button align flag, for drawing groups together */
 #define UI_BUT_ALIGN        (UI_BUT_ALIGN_TOP | UI_BUT_ALIGN_LEFT | UI_BUT_ALIGN_RIGHT | UI_BUT_ALIGN_DOWN)
@@ -710,6 +710,7 @@
 #define UI_ITEM_R_FULL_EVENT    64
 #define UI_ITEM_R_NO_BG         128
 #define UI_ITEM_R_IMMEDIATE     256
+#define UI_ITEM_R_CLEARFIELD    512
 
 /* uiLayoutOperatorButs flags */
 #define UI_LAYOUT_OP_SHOW_TITLE 1

Modified: branches/soc-2012-bratwurst/source/blender/editors/interface/interface.c
===================================================================
--- branches/soc-2012-bratwurst/source/blender/editors/interface/interface.c	2012-07-16 23:29:12 UTC (rev 48989)
+++ branches/soc-2012-bratwurst/source/blender/editors/interface/interface.c	2012-07-17 03:05:42 UTC (rev 48990)
@@ -1478,7 +1478,18 @@
 					if (RNA_property_array_length(&but->rnapoin, prop))
 						RNA_property_boolean_set_index(&but->rnapoin, prop, but->rnaindex, value);
 					else
+					{
+						if (but->flag & UI_CLEAR_BITFIELD)
+						{
+							// I'm not thrilled with this code, but I'm not sure there's a better way to find the state of shift.
+							wmWindow *win = CTX_wm_window((const bContext*)but->block->evil_C);
+							int shift = win->eventstate->shift;
+							if (!shift)
+								RNA_property_boolean_clear(&but->rnapoin, prop);
+						}
+
 						RNA_property_boolean_set(&but->rnapoin, prop, value);
+					}
 					break;
 				case PROP_INT:
 					if (RNA_property_array_length(&but->rnapoin, prop))

Modified: branches/soc-2012-bratwurst/source/blender/editors/interface/interface_layout.c
===================================================================
--- branches/soc-2012-bratwurst/source/blender/editors/interface/interface_layout.c	2012-07-16 23:29:12 UTC (rev 48989)
+++ branches/soc-2012-bratwurst/source/blender/editors/interface/interface_layout.c	2012-07-17 03:05:42 UTC (rev 48990)
@@ -1123,7 +1123,10 @@
 
 		if (toggle && but->type == OPTION)
 			but->type = TOG;
-		
+
+		if (flag & UI_ITEM_R_CLEARFIELD)
+			but->flag |= UI_CLEAR_BITFIELD;
+
 		if (layout->redalert)
 			uiButSetFlag(but, UI_BUT_REDALERT);
 	}

Modified: branches/soc-2012-bratwurst/source/blender/makesrna/RNA_access.h
===================================================================
--- branches/soc-2012-bratwurst/source/blender/makesrna/RNA_access.h	2012-07-16 23:29:12 UTC (rev 48989)
+++ branches/soc-2012-bratwurst/source/blender/makesrna/RNA_access.h	2012-07-17 03:05:42 UTC (rev 48990)
@@ -758,6 +758,7 @@
 
 int RNA_property_boolean_get(PointerRNA *ptr, PropertyRNA *prop);
 void RNA_property_boolean_set(PointerRNA *ptr, PropertyRNA *prop, int value);
+void RNA_property_boolean_clear(PointerRNA *ptr, PropertyRNA *prop);
 void RNA_property_boolean_get_array(PointerRNA *ptr, PropertyRNA *prop, int *values);
 int RNA_property_boolean_get_index(PointerRNA *ptr, PropertyRNA *prop, int index);
 void RNA_property_boolean_set_array(PointerRNA *ptr, PropertyRNA *prop, const int *values);

Modified: branches/soc-2012-bratwurst/source/blender/makesrna/RNA_define.h
===================================================================
--- branches/soc-2012-bratwurst/source/blender/makesrna/RNA_define.h	2012-07-16 23:29:12 UTC (rev 48989)
+++ branches/soc-2012-bratwurst/source/blender/makesrna/RNA_define.h	2012-07-17 03:05:42 UTC (rev 48990)
@@ -167,7 +167,7 @@
 void RNA_def_property_update_runtime(PropertyRNA *prop, void *func);
 
 void RNA_def_property_dynamic_array_funcs(PropertyRNA *prop, const char *getlength);
-void RNA_def_property_boolean_funcs(PropertyRNA *prop, const char *get, const char *set);
+void RNA_def_property_boolean_funcs(PropertyRNA *prop, const char *get, const char *set, const char *clear);
 void RNA_def_property_int_funcs(PropertyRNA *prop, const char *get, const char *set, const char *range);
 void RNA_def_property_float_funcs(PropertyRNA *prop, const char *get, const char *set, const char *range);
 void RNA_def_property_enum_funcs(PropertyRNA *prop, const char *get, const char *set, const char *item);

Modified: branches/soc-2012-bratwurst/source/blender/makesrna/intern/makesrna.c
===================================================================
--- branches/soc-2012-bratwurst/source/blender/makesrna/intern/makesrna.c	2012-07-16 23:29:12 UTC (rev 48989)
+++ branches/soc-2012-bratwurst/source/blender/makesrna/intern/makesrna.c	2012-07-17 03:05:42 UTC (rev 48990)
@@ -31,6 +31,7 @@
 #include <stdlib.h>
 #include <string.h>
 #include <errno.h>
+#include <assert.h>
 
 #include "MEM_guardedalloc.h"
 
@@ -956,6 +957,54 @@
 	return func;
 }
 
+static char *rna_def_property_clear_func(FILE *f, StructRNA *srna, PropertyRNA *prop, PropertyDefRNA *dp,
+                                       const char *manualfunc)
+{
+	char *func;
+
+	if (!(prop->flag & PROP_EDITABLE))
+		return NULL;
+	if (prop->flag & PROP_IDPROPERTY && manualfunc == NULL)
+		return NULL;
+
+	if (!manualfunc) {
+		if (!dp->dnastructname || !dp->dnaname) {
+			/*if (prop->flag & PROP_EDITABLE) {
+				fprintf(stderr, "%s: %s.%s has no valid dna info.\n",
+				        __func__, srna->identifier, prop->identifier);
+				DefRNA.error = 1;
+			}*/
+			return NULL;
+		}
+	}
+
+	// This function is only for clearing boolean bit fields
+	if (prop->type != PROP_BOOLEAN)
+		return NULL;
+
+	if (prop->arraydimension)
+		return NULL;
+
+	if (!dp->booleanbit)
+		return NULL;
+
+	func = rna_alloc_function_name(srna->identifier, rna_safe_id(prop->identifier), "clear");
+
+	fprintf(f, "void %s(PointerRNA *ptr)\n", func);
+	fprintf(f, "{\n");
+
+	if (manualfunc) {
+		fprintf(f, "	%s(ptr);\n", manualfunc);
+	}
+	else {
+		rna_print_data_get(f, dp);
+		fprintf(f, "	data->%s = 0;\n", dp->dnaname);
+	}
+	fprintf(f, "}\n\n");
+
+	return func;
+}
+
 static char *rna_def_property_length_func(FILE *f, StructRNA *srna, PropertyRNA *prop, PropertyDefRNA *dp,
                                           const char *manualfunc)
 {
@@ -1284,6 +1333,7 @@
 
 				bprop->get = (void *)rna_def_property_get_func(f, srna, prop, dp, (const char *)bprop->get);
 				bprop->set = (void *)rna_def_property_set_func(f, srna, prop, dp, (const char *)bprop->set);
+				bprop->clear = (void *)rna_def_property_clear_func(f, srna, prop, dp, (const char *)bprop->clear);
 			}
 			else {
 				bprop->getarray = (void *)rna_def_property_get_func(f, srna, prop, dp, (const char *)bprop->getarray);
@@ -2382,9 +2432,10 @@
 	switch (prop->type) {
 		case PROP_BOOLEAN: {
 			BoolPropertyRNA *bprop = (BoolPropertyRNA *)prop;
-			fprintf(f, "\t%s, %s, %s, %s, %d, ",
+			fprintf(f, "\t%s, %s, %s, %s, %s, %d, ",
 			        rna_function_string(bprop->get),
 			        rna_function_string(bprop->set),
+			        rna_function_string(bprop->clear),
 			        rna_function_string(bprop->getarray),
 			        rna_function_string(bprop->setarray),
 			        bprop->defaultvalue);
@@ -2741,11 +2792,15 @@
 		}
 	}
 
+	fprintf(f, "/* Property Functions */\n\n");
+
 	for (ds = DefRNA.structs.first; ds; ds = ds->cont.next)
 		if (!filename || ds->filename == filename)
 			for (dp = ds->cont.properties.first; dp; dp = dp->next)
 				rna_def_property_funcs(f, ds->srna, dp);
 
+	fprintf(f, "/* Function Functions */\n\n");
+
 	for (ds = DefRNA.structs.first; ds; ds = ds->cont.next) {
 		if (!filename || ds->filename == filename) {
 			for (dfunc = ds->functions.first; dfunc; dfunc = dfunc->cont.next)
@@ -2755,6 +2810,8 @@
 		}
 	}
 
+	fprintf(f, "/* Structs */\n\n");
+
 	for (ds = DefRNA.structs.first; ds; ds = ds->cont.next)
 		if (!filename || ds->filename == filename)
 			rna_generate_struct(brna, ds->srna, f);

Modified: branches/soc-2012-bratwurst/source/blender/makesrna/intern/rna_ID.c
===================================================================
--- branches/soc-2012-bratwurst/source/blender/makesrna/intern/rna_ID.c	2012-07-16 23:29:12 UTC (rev 48989)
+++ branches/soc-2012-bratwurst/source/blender/makesrna/intern/rna_ID.c	2012-07-17 03:05:42 UTC (rev 48990)
@@ -516,7 +516,7 @@

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list