Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--source/blender/editors/include/UI_interface.h2
-rw-r--r--source/blender/editors/include/UI_view2d.h2
-rw-r--r--source/blender/editors/interface/interface_handlers.c3
-rw-r--r--source/blender/editors/interface/interface_ops.c219
-rw-r--r--source/blender/editors/interface/view2d_ops.c2
-rw-r--r--source/blender/editors/space_api/spacetypes.c3
-rw-r--r--source/blender/makesrna/RNA_access.h4
-rw-r--r--source/blender/makesrna/intern/rna_access.c182
8 files changed, 313 insertions, 104 deletions
diff --git a/source/blender/editors/include/UI_interface.h b/source/blender/editors/include/UI_interface.h
index f0e52a13d3f..8e44d7f386e 100644
--- a/source/blender/editors/include/UI_interface.h
+++ b/source/blender/editors/include/UI_interface.h
@@ -689,7 +689,7 @@ void uiItemMenuEnumO(uiLayout *layout, char *name, int icon, char *opname, char
void uiItemMenuEnumR(uiLayout *layout, char *name, int icon, struct PointerRNA *ptr, char *propname);
/* UI Operators */
-void ui_buttons_operatortypes(void);
+void UI_buttons_operatortypes(void);
/* Helpers for Operators */
void uiAnimContextProperty(const struct bContext *C, struct PointerRNA *ptr, struct PropertyRNA **prop, int *index);
diff --git a/source/blender/editors/include/UI_view2d.h b/source/blender/editors/include/UI_view2d.h
index 8fbff25589d..e3b00c21d04 100644
--- a/source/blender/editors/include/UI_view2d.h
+++ b/source/blender/editors/include/UI_view2d.h
@@ -195,7 +195,7 @@ void UI_view2d_text_cache_rectf(struct View2D *v2d, struct rctf *rect, char *str
void UI_view2d_text_cache_draw(struct ARegion *ar);
/* operators */
-void ui_view2d_operatortypes(void);
+void UI_view2d_operatortypes(void);
void UI_view2d_keymap(struct wmKeyConfig *keyconf);
#endif /* UI_VIEW2D_H */
diff --git a/source/blender/editors/interface/interface_handlers.c b/source/blender/editors/interface/interface_handlers.c
index 9604704dde8..88868a61592 100644
--- a/source/blender/editors/interface/interface_handlers.c
+++ b/source/blender/editors/interface/interface_handlers.c
@@ -3506,7 +3506,8 @@ static int ui_but_menu(bContext *C, uiBut *but)
else
uiItemO(layout, "Reset to Default Value", 0, "UI_OT_reset_default_button");
- uiItemO(layout, "Copy Data Path", 0, "UI_OT_copy_clipboard_button");
+ uiItemO(layout, "Copy Data Path", 0, "UI_OT_copy_data_path_button");
+ uiItemO(layout, "Copy To Selected", 0, "UI_OT_copy_to_selected_button");
uiItemS(layout);
}
diff --git a/source/blender/editors/interface/interface_ops.c b/source/blender/editors/interface/interface_ops.c
index a5caf1c930b..d1204b41a28 100644
--- a/source/blender/editors/interface/interface_ops.c
+++ b/source/blender/editors/interface/interface_ops.c
@@ -59,18 +59,17 @@
/* ********************************************************** */
-/* Copy to Clipboard Button Operator ------------------------ */
+/* Copy Data Path Operator ------------------------ */
-static int copy_clipboard_button_exec(bContext *C, wmOperator *op)
+static int copy_data_path_button_exec(bContext *C, wmOperator *op)
{
PointerRNA ptr;
- PropertyRNA *prop= NULL;
+ PropertyRNA *prop;
char *path;
- short success= 0;
+ int 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) {
@@ -86,15 +85,15 @@ static int copy_clipboard_button_exec(bContext *C, wmOperator *op)
return (success)? OPERATOR_FINISHED: OPERATOR_CANCELLED;
}
-void UI_OT_copy_clipboard_button(wmOperatorType *ot)
+void UI_OT_copy_data_path_button(wmOperatorType *ot)
{
/* identifiers */
ot->name= "Copy Data Path";
- ot->idname= "UI_OT_copy_clipboard_button";
+ ot->idname= "UI_OT_copy_data_path_button";
ot->description= "Copy the RNA data path for this property to the clipboard.";
/* callbacks */
- ot->exec= copy_clipboard_button_exec;
+ ot->exec= copy_data_path_button_exec;
//op->poll= ??? // TODO: need to have some valid property before this can be done
/* flags */
@@ -103,103 +102,34 @@ void UI_OT_copy_clipboard_button(wmOperatorType *ot)
/* Reset to Default Values Button Operator ------------------------ */
+static int reset_default_button_poll(bContext *C)
+{
+ PointerRNA ptr;
+ PropertyRNA *prop;
+ int index;
+
+ uiAnimContextProperty(C, &ptr, &prop, &index);
+
+ return (ptr.data && prop && RNA_property_editable(&ptr, prop));
+}
+
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");
+ PropertyRNA *prop;
+ int success= 0;
+ int index, 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:
- {
- int value= RNA_property_enum_get_default(&ptr, prop);
- RNA_property_enum_set(&ptr, prop, value);
- }
- break;
-
- //case PROP_POINTER:
- //case PROP_STRING:
- default:
- // FIXME: many of the other types such as strings and pointers need this implemented too!
- break;
+ if(RNA_property_reset(&ptr, prop, (all)? -1: index)) {
+ /* perform updates required for this property */
+ RNA_property_update(C, &ptr, prop);
+ success= 1;
}
-
- /* perform updates required for this property */
- RNA_property_update(C, &ptr, prop);
-
- success= 1;
}
return (success)? OPERATOR_FINISHED: OPERATOR_CANCELLED;
@@ -213,12 +143,102 @@ void UI_OT_reset_default_button(wmOperatorType *ot)
ot->description= "Copy the RNA data path for this property to the clipboard.";
/* callbacks */
+ ot->poll= reset_default_button_poll;
ot->exec= reset_default_button_exec;
- //op->poll= ??? // TODO: need to have some valid property before this can be done
/* flags */
- ot->flag= OPTYPE_REGISTER;
+ ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
+
+ /* properties */
+ RNA_def_boolean(ot->srna, "all", 1, "All", "Reset to default values all elements of the array.");
+}
+
+/* Copy To Selected Operator ------------------------ */
+
+static int copy_to_selected_list(bContext *C, PointerRNA *ptr, ListBase *lb)
+{
+ if(RNA_struct_is_a(ptr->type, &RNA_Object))
+ *lb = CTX_data_collection_get(C, "selected_editable_objects");
+ else if(RNA_struct_is_a(ptr->type, &RNA_EditBone))
+ *lb = CTX_data_collection_get(C, "selected_editable_bones");
+ else if(RNA_struct_is_a(ptr->type, &RNA_PoseBone))
+ *lb = CTX_data_collection_get(C, "selected_pose_bones");
+ else
+ return 0;
+ return 1;
+}
+
+static int copy_to_selected_button_poll(bContext *C)
+{
+ PointerRNA ptr;
+ PropertyRNA *prop;
+ int index, success= 0;
+
+ uiAnimContextProperty(C, &ptr, &prop, &index);
+
+ if (ptr.data && prop) {
+ CollectionPointerLink *link;
+ ListBase lb;
+
+ if(copy_to_selected_list(C, &ptr, &lb)) {
+ for(link= lb.first; link; link=link->next)
+ if(link->ptr.data != ptr.data && RNA_property_editable(&link->ptr, prop))
+ success= 1;
+
+ BLI_freelistN(&lb);
+ }
+ }
+
+ return success;
+}
+
+static int copy_to_selected_button_exec(bContext *C, wmOperator *op)
+{
+ PointerRNA ptr;
+ PropertyRNA *prop;
+ int success= 0;
+ int index, all = RNA_boolean_get(op->ptr, "all");
+
+ /* try to reset the nominated setting to its default value */
+ uiAnimContextProperty(C, &ptr, &prop, &index);
+
+ /* if there is a valid property that is editable... */
+ if (ptr.data && prop) {
+ CollectionPointerLink *link;
+ ListBase lb;
+
+ if(copy_to_selected_list(C, &ptr, &lb)) {
+ for(link= lb.first; link; link=link->next) {
+ if(link->ptr.data != ptr.data && RNA_property_editable(&link->ptr, prop)) {
+ if(RNA_property_copy(&link->ptr, &ptr, prop, (all)? -1: index)) {
+ RNA_property_update(C, &link->ptr, prop);
+ success= 1;
+ }
+ }
+ }
+
+ BLI_freelistN(&lb);
+ }
+ }
+
+ return (success)? OPERATOR_FINISHED: OPERATOR_CANCELLED;
+}
+
+void UI_OT_copy_to_selected_button(wmOperatorType *ot)
+{
+ /* identifiers */
+ ot->name= "Copy To Selected";
+ ot->idname= "UI_OT_copy_to_selected_button";
+ ot->description= "Copy property from this object to selected objects or bones.";
+
+ /* callbacks */
+ ot->poll= copy_to_selected_button_poll;
+ ot->exec= copy_to_selected_button_exec;
+
+ /* flags */
+ ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
+
/* properties */
RNA_def_boolean(ot->srna, "all", 1, "All", "Reset to default values all elements of the array.");
}
@@ -226,9 +246,10 @@ void UI_OT_reset_default_button(wmOperatorType *ot)
/* ********************************************************* */
/* Registration */
-void ui_buttons_operatortypes(void)
+void UI_buttons_operatortypes(void)
{
- WM_operatortype_append(UI_OT_copy_clipboard_button);
+ WM_operatortype_append(UI_OT_copy_data_path_button);
WM_operatortype_append(UI_OT_reset_default_button);
+ WM_operatortype_append(UI_OT_copy_to_selected_button);
}
diff --git a/source/blender/editors/interface/view2d_ops.c b/source/blender/editors/interface/view2d_ops.c
index 8bd840f7e84..6742df351d1 100644
--- a/source/blender/editors/interface/view2d_ops.c
+++ b/source/blender/editors/interface/view2d_ops.c
@@ -1403,7 +1403,7 @@ void VIEW2D_OT_reset(wmOperatorType *ot)
/* ********************************************************* */
/* Registration */
-void ui_view2d_operatortypes(void)
+void UI_view2d_operatortypes(void)
{
WM_operatortype_append(VIEW2D_OT_pan);
diff --git a/source/blender/editors/space_api/spacetypes.c b/source/blender/editors/space_api/spacetypes.c
index 8cf56ae3eda..90457c05fa7 100644
--- a/source/blender/editors/space_api/spacetypes.c
+++ b/source/blender/editors/space_api/spacetypes.c
@@ -101,7 +101,8 @@ void ED_spacetypes_init(void)
ED_operatortypes_sound();
ED_operatortypes_render();
- ui_view2d_operatortypes();
+ UI_view2d_operatortypes();
+ UI_buttons_operatortypes();
spacetypes = BKE_spacetypes_list();
for(type=spacetypes->first; type; type=type->next)
diff --git a/source/blender/makesrna/RNA_access.h b/source/blender/makesrna/RNA_access.h
index c2b36ddc915..c3f23e799d5 100644
--- a/source/blender/makesrna/RNA_access.h
+++ b/source/blender/makesrna/RNA_access.h
@@ -722,6 +722,10 @@ void RNA_property_collection_add(PointerRNA *ptr, PropertyRNA *prop, PointerRNA
int RNA_property_collection_remove(PointerRNA *ptr, PropertyRNA *prop, int key);
void RNA_property_collection_clear(PointerRNA *ptr, PropertyRNA *prop);
+/* copy/reset */
+int RNA_property_copy(PointerRNA *ptr, PointerRNA *fromptr, PropertyRNA *prop, int index);
+int RNA_property_reset(PointerRNA *ptr, PropertyRNA *prop, int index);
+
/* Path
*
* Experimental method to refer to structs and properties with a string,
diff --git a/source/blender/makesrna/intern/rna_access.c b/source/blender/makesrna/intern/rna_access.c
index 53f5407e521..8ae0ebacff7 100644
--- a/source/blender/makesrna/intern/rna_access.c
+++ b/source/blender/makesrna/intern/rna_access.c
@@ -4088,4 +4088,186 @@ int RNA_function_call_direct_va_lookup(bContext *C, ReportList *reports, Pointer
return 0;
}
+int RNA_property_reset(PointerRNA *ptr, PropertyRNA *prop, int index)
+{
+ int len;
+
+ /* 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 (index == -1) {
+ 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);
+ }
+ return 1;
+ case PROP_INT:
+ if (len) {
+ if (index == -1) {
+ 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);
+ }
+ return 1;
+ case PROP_FLOAT:
+ if (len) {
+ if (index == -1) {
+ 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);
+ }
+ return 1;
+ case PROP_ENUM:
+ {
+ int value= RNA_property_enum_get_default(ptr, prop);
+ RNA_property_enum_set(ptr, prop, value);
+ return 1;
+ }
+
+ //case PROP_POINTER:
+ //case PROP_STRING:
+ default:
+ // FIXME: many of the other types such as strings and pointers need this implemented too!
+ return 0;
+ }
+}
+
+int RNA_property_copy(PointerRNA *ptr, PointerRNA *fromptr, PropertyRNA *prop, int index)
+{
+ int len, fromlen;
+
+ /* get the length of the array to work with */
+ len= RNA_property_array_length(ptr, prop);
+ fromlen= RNA_property_array_length(ptr, prop);
+
+ if(len != fromlen)
+ return 0;
+
+ /* get and set the default values as appropriate for the various types */
+ switch (RNA_property_type(prop)) {
+ case PROP_BOOLEAN:
+ if (len) {
+ if (index == -1) {
+ int *tmparray= MEM_callocN(sizeof(int)*len, "copy - boolean");
+
+ RNA_property_boolean_get_array(fromptr, prop, tmparray);
+ RNA_property_boolean_set_array(ptr, prop, tmparray);
+
+ MEM_freeN(tmparray);
+ }
+ else {
+ int value= RNA_property_boolean_get_index(fromptr, prop, index);
+ RNA_property_boolean_set_index(ptr, prop, index, value);
+ }
+ }
+ else {
+ int value= RNA_property_boolean_get(fromptr, prop);
+ RNA_property_boolean_set(ptr, prop, value);
+ }
+ return 1;
+ case PROP_INT:
+ if (len) {
+ if (index == -1) {
+ int *tmparray= MEM_callocN(sizeof(int)*len, "copy - int");
+
+ RNA_property_int_get_array(fromptr, prop, tmparray);
+ RNA_property_int_set_array(ptr, prop, tmparray);
+
+ MEM_freeN(tmparray);
+ }
+ else {
+ int value= RNA_property_int_get_index(fromptr, prop, index);
+ RNA_property_int_set_index(ptr, prop, index, value);
+ }
+ }
+ else {
+ int value= RNA_property_int_get(fromptr, prop);
+ RNA_property_int_set(ptr, prop, value);
+ }
+ return 1;
+ case PROP_FLOAT:
+ if (len) {
+ if (index == -1) {
+ float *tmparray= MEM_callocN(sizeof(float)*len, "copy - float");
+
+ RNA_property_float_get_array(fromptr, prop, tmparray);
+ RNA_property_float_set_array(ptr, prop, tmparray);
+
+ MEM_freeN(tmparray);
+ }
+ else {
+ float value= RNA_property_float_get_index(fromptr, prop, index);
+ RNA_property_float_set_index(ptr, prop, index, value);
+ }
+ }
+ else {
+ float value= RNA_property_float_get(fromptr, prop);
+ RNA_property_float_set(ptr, prop, value);
+ }
+ return 1;
+ case PROP_ENUM:
+ {
+ int value= RNA_property_enum_get(fromptr, prop);
+ RNA_property_enum_set(ptr, prop, value);
+ return 1;
+ }
+ case PROP_POINTER:
+ {
+ PointerRNA value= RNA_property_pointer_get(fromptr, prop);
+ RNA_property_pointer_set(ptr, prop, value);
+ return 1;
+ }
+ case PROP_STRING:
+ {
+ char *value= RNA_property_string_get_alloc(fromptr, prop, NULL, 0);
+ RNA_property_string_set(ptr, prop, value);
+ MEM_freeN(value);
+ return 1;
+ }
+ default:
+ return 0;
+ }
+
+ return 0;
+}