[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [25432] trunk/blender/source/blender: RNA/ UI - Reset Settings to Default Values

Joshua Leung aligorith at gmail.com
Thu Dec 17 11:47:56 CET 2009


Revision: 25432
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=25432
Author:   aligorith
Date:     2009-12-17 11:47:55 +0100 (Thu, 17 Dec 2009)

Log Message:
-----------
RNA/UI - Reset Settings to Default Values

Added a new operator for properties which resets RNA-based settings to their 'default' values, as defined in RNA. This currently only works for floats, ints, enums, and booleans (strings and pointers still need to be implemented). 

The current extensions to the RNA API that I've made here seem a bit excessive, and can be toned down if necessary. In short, I've just added accessor functions for the default-values of the property definitions.

For this to be really useful, many properties in RNA will need to get defaults defined, since the current defaults for quite a few properties tested were less than ideal.

Modified Paths:
--------------
    trunk/blender/source/blender/editors/animation/anim_intern.h
    trunk/blender/source/blender/editors/animation/anim_ops.c
    trunk/blender/source/blender/editors/animation/drivers.c
    trunk/blender/source/blender/editors/include/UI_interface.h
    trunk/blender/source/blender/editors/interface/interface_handlers.c
    trunk/blender/source/blender/makesrna/RNA_access.h
    trunk/blender/source/blender/makesrna/intern/rna_access.c

Added Paths:
-----------
    trunk/blender/source/blender/editors/interface/interface_ops.c

Modified: trunk/blender/source/blender/editors/animation/anim_intern.h
===================================================================
--- trunk/blender/source/blender/editors/animation/anim_intern.h	2009-12-17 10:01:08 UTC (rev 25431)
+++ trunk/blender/source/blender/editors/animation/anim_intern.h	2009-12-17 10:47:55 UTC (rev 25432)
@@ -79,6 +79,4 @@
 void ANIM_OT_copy_driver_button(struct wmOperatorType *ot);
 void ANIM_OT_paste_driver_button(struct wmOperatorType *ot);
 
-void ANIM_OT_copy_clipboard_button(struct wmOperatorType *ot);
-
 #endif // ANIM_INTERN_H

Modified: trunk/blender/source/blender/editors/animation/anim_ops.c
===================================================================
--- trunk/blender/source/blender/editors/animation/anim_ops.c	2009-12-17 10:01:08 UTC (rev 25431)
+++ trunk/blender/source/blender/editors/animation/anim_ops.c	2009-12-17 10:47:55 UTC (rev 25432)
@@ -362,8 +362,6 @@
 	WM_operatortype_append(ANIM_OT_driver_button_remove);
 	WM_operatortype_append(ANIM_OT_copy_driver_button);
 	WM_operatortype_append(ANIM_OT_paste_driver_button);
-	
-	WM_operatortype_append(ANIM_OT_copy_clipboard_button);
 
 	
 	WM_operatortype_append(ANIM_OT_keyingset_button_add);

Modified: trunk/blender/source/blender/editors/animation/drivers.c
===================================================================
--- trunk/blender/source/blender/editors/animation/drivers.c	2009-12-17 10:01:08 UTC (rev 25431)
+++ trunk/blender/source/blender/editors/animation/drivers.c	2009-12-17 10:47:55 UTC (rev 25432)
@@ -581,47 +581,4 @@
 	ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
 }
 
-
-/* Copy to Clipboard Button Operator ------------------------ */
-
-static int copy_clipboard_button_exec(bContext *C, wmOperator *op)
-{
-	PointerRNA ptr;
-	PropertyRNA *prop= NULL;
-	char *path;
-	short success= 0;
-	int index;
-
-	/* try to create driver using property retrieved from UI */
-	memset(&ptr, 0, sizeof(PointerRNA));
-	uiAnimContextProperty(C, &ptr, &prop, &index);
-
-	if (ptr.data && prop) {
-		path= RNA_path_from_ID_to_property(&ptr, prop);
-		
-		if (path) {
-			WM_clipboard_text_set(path, FALSE);
-			MEM_freeN(path);
-		}
-	}
-
-	/* since we're just copying, we don't really need to do anything else...*/
-	return (success)? OPERATOR_FINISHED: OPERATOR_CANCELLED;
-}
-
-void ANIM_OT_copy_clipboard_button(wmOperatorType *ot)
-{
-	/* identifiers */
-	ot->name= "Copy Data Path";
-	ot->idname= "ANIM_OT_copy_clipboard_button";
-	ot->description= "Copy the RNA data path for this property to the clipboard.";
-
-	/* callbacks */
-	ot->exec= copy_clipboard_button_exec;
-	//op->poll= ??? // TODO: need to have some valid property before this can be done
-
-	/* flags */
-	ot->flag= OPTYPE_REGISTER;
-}
-
 /* ************************************************** */

Modified: trunk/blender/source/blender/editors/include/UI_interface.h
===================================================================
--- trunk/blender/source/blender/editors/include/UI_interface.h	2009-12-17 10:01:08 UTC (rev 25431)
+++ trunk/blender/source/blender/editors/include/UI_interface.h	2009-12-17 10:47:55 UTC (rev 25432)
@@ -688,6 +688,9 @@
 void uiItemMenuEnumO(uiLayout *layout, char *name, int icon, char *opname, char *propname);
 void uiItemMenuEnumR(uiLayout *layout, char *name, int icon, struct PointerRNA *ptr, char *propname);
 
+/* UI Operators */
+void ui_buttons_operatortypes(void);
+
 /* Helpers for Operators */
 void uiAnimContextProperty(const struct bContext *C, struct PointerRNA *ptr, struct PropertyRNA **prop, int *index);
 void uiFileBrowseContextProperty(const struct bContext *C, struct PointerRNA *ptr, struct PropertyRNA **prop);

Modified: trunk/blender/source/blender/editors/interface/interface_handlers.c
===================================================================
--- trunk/blender/source/blender/editors/interface/interface_handlers.c	2009-12-17 10:01:08 UTC (rev 25431)
+++ trunk/blender/source/blender/editors/interface/interface_handlers.c	2009-12-17 10:47:55 UTC (rev 25432)
@@ -3499,9 +3499,14 @@
 		//Copy Property Value
 		//Paste Property Value
 		
-		//uiItemO(layout, "Reset to Default Value", 0, "WM_OT_property_value_reset_button");
+		if(length) {
+			uiItemBooleanO(layout, "Reset All to Default Values", 0, "UI_OT_reset_default_button", "all", 1);
+			uiItemBooleanO(layout, "Reset Single to Default Value", 0, "UI_OT_reset_default_button", "all", 0);
+		}
+		else
+			uiItemO(layout, "Reset to Default Value", 0, "UI_OT_reset_default_button");
 		
-		uiItemO(layout, "Copy Data Path", 0, "ANIM_OT_copy_clipboard_button");
+		uiItemO(layout, "Copy Data Path", 0, "UI_OT_copy_clipboard_button");
 
 		uiItemS(layout);
 	}

Added: trunk/blender/source/blender/editors/interface/interface_ops.c
===================================================================
--- trunk/blender/source/blender/editors/interface/interface_ops.c	                        (rev 0)
+++ trunk/blender/source/blender/editors/interface/interface_ops.c	2009-12-17 10:47:55 UTC (rev 25432)
@@ -0,0 +1,234 @@
+/**
+ * $Id: interface_ops.c 24699 2009-11-20 10:21:31Z aligorith $
+ *
+ * ***** BEGIN GPL LICENSE BLOCK *****
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version. 
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+ *
+ * The Original Code is Copyright (C) 2009 Blender Foundation.
+ * All rights reserved.
+ * 
+ * Contributor(s): Blender Foundation, Joshua Leung
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+#include <stdio.h>
+#include <math.h>
+#include <string.h>
+
+
+#include "MEM_guardedalloc.h"
+
+#include "DNA_scene_types.h"
+#include "DNA_screen_types.h"
+#include "DNA_space_types.h"
+#include "DNA_userdef_types.h"
+#include "DNA_vec_types.h"
+#include "DNA_view2d_types.h"
+
+#include "BLI_blenlib.h"
+
+#include "BKE_context.h"
+#include "BKE_utildefines.h"
+
+#include "RNA_access.h"
+#include "RNA_define.h"
+
+#include "WM_api.h"
+#include "WM_types.h"
+
+#include "BIF_gl.h"
+
+#include "ED_screen.h"
+
+#include "UI_interface.h"
+#include "UI_resources.h"
+
+/* ********************************************************** */
+
+/* Copy to Clipboard Button Operator ------------------------ */
+
+static int copy_clipboard_button_exec(bContext *C, wmOperator *op)
+{
+	PointerRNA ptr;
+	PropertyRNA *prop= NULL;
+	char *path;
+	short success= 0;
+	int index;
+
+	/* try to create driver using property retrieved from UI */
+	memset(&ptr, 0, sizeof(PointerRNA));
+	uiAnimContextProperty(C, &ptr, &prop, &index);
+
+	if (ptr.data && prop) {
+		path= RNA_path_from_ID_to_property(&ptr, prop);
+		
+		if (path) {
+			WM_clipboard_text_set(path, FALSE);
+			MEM_freeN(path);
+		}
+	}
+
+	/* since we're just copying, we don't really need to do anything else...*/
+	return (success)? OPERATOR_FINISHED: OPERATOR_CANCELLED;
+}
+
+void UI_OT_copy_clipboard_button(wmOperatorType *ot)
+{
+	/* identifiers */
+	ot->name= "Copy Data Path";
+	ot->idname= "UI_OT_copy_clipboard_button";
+	ot->description= "Copy the RNA data path for this property to the clipboard.";
+
+	/* callbacks */
+	ot->exec= copy_clipboard_button_exec;
+	//op->poll= ??? // TODO: need to have some valid property before this can be done
+
+	/* flags */
+	ot->flag= OPTYPE_REGISTER;
+}
+
+/* Reset to Default Values Button Operator ------------------------ */
+
+static int reset_default_button_exec(bContext *C, wmOperator *op)
+{
+	PointerRNA ptr;
+	PropertyRNA *prop= NULL;
+	short success= 0;
+	int index, len;
+	int all = RNA_boolean_get(op->ptr, "all");
+
+	/* try to reset the nominated setting to its default value */
+	memset(&ptr, 0, sizeof(PointerRNA));
+	uiAnimContextProperty(C, &ptr, &prop, &index);
+	
+	/* if there is a valid property that is editable... */
+	if (ptr.data && prop && RNA_property_editable(&ptr, prop)) {
+		/* get the length of the array to work with */
+		len= RNA_property_array_length(&ptr, prop);
+		
+		/* get and set the default values as appropriate for the various types */
+		switch (RNA_property_type(prop)) {
+			case PROP_BOOLEAN:
+				if (len) {
+					if (all) {
+						int *tmparray= MEM_callocN(sizeof(int)*len, "reset_defaults - boolean");
+						
+						RNA_property_boolean_get_default_array(&ptr, prop, tmparray);
+						RNA_property_boolean_set_array(&ptr, prop, tmparray);
+						
+						MEM_freeN(tmparray);
+					}
+					else {
+						int value= RNA_property_boolean_get_default_index(&ptr, prop, index);
+						RNA_property_boolean_set_index(&ptr, prop, index, value);
+					}
+				}
+				else {
+					int value= RNA_property_boolean_get_default(&ptr, prop);
+					RNA_property_boolean_set(&ptr, prop, value);
+				}
+				break;
+			case PROP_INT:
+				if (len) {
+					if (all) {
+						int *tmparray= MEM_callocN(sizeof(int)*len, "reset_defaults - int");
+						
+						RNA_property_int_get_default_array(&ptr, prop, tmparray);
+						RNA_property_int_set_array(&ptr, prop, tmparray);
+						
+						MEM_freeN(tmparray);
+					}
+					else {
+						int value= RNA_property_int_get_default_index(&ptr, prop, index);
+						RNA_property_int_set_index(&ptr, prop, index, value);
+					}
+				}
+				else {
+					int value= RNA_property_int_get_default(&ptr, prop);
+					RNA_property_int_set(&ptr, prop, value);
+				}
+				break;
+			case PROP_FLOAT:
+				if (len) {
+					if (all) {
+						float *tmparray= MEM_callocN(sizeof(float)*len, "reset_defaults - float");
+						
+						RNA_property_float_get_default_array(&ptr, prop, tmparray);
+						RNA_property_float_set_array(&ptr, prop, tmparray);
+						
+						MEM_freeN(tmparray);
+					}
+					else {
+						float value= RNA_property_float_get_default_index(&ptr, prop, index);
+						RNA_property_float_set_index(&ptr, prop, index, value);
+					}
+				}
+				else {
+					float value= RNA_property_float_get_default(&ptr, prop);
+					RNA_property_float_set(&ptr, prop, value);
+				}
+				break;
+			case PROP_ENUM:
+			{

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list