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:
authorMartin Poirier <theeth@yahoo.com>2009-12-31 01:14:32 +0300
committerMartin Poirier <theeth@yahoo.com>2009-12-31 01:14:32 +0300
commitb00cddeb66f2b9f51cad15ed597a6ca975bd31dd (patch)
treebd686691ecde5cd24abd2330dea086e275d07635 /source/blender/makesrna
parent3702998fec6d237eb567bb8353ac93c8d4a68d4c (diff)
Macro registration using the normal rna registration methods (like operators).
bpy.types.register(MacroClass) instead of bpy.ops.add_macro(MacroClass) The rest is unchanged. Also remove some now unused code for the old registration methods (there's still some remaining).
Diffstat (limited to 'source/blender/makesrna')
-rw-r--r--source/blender/makesrna/RNA_access.h1
-rw-r--r--source/blender/makesrna/intern/rna_internal.h1
-rw-r--r--source/blender/makesrna/intern/rna_wm.c96
-rw-r--r--source/blender/makesrna/intern/rna_wm_api.c29
4 files changed, 127 insertions, 0 deletions
diff --git a/source/blender/makesrna/RNA_access.h b/source/blender/makesrna/RNA_access.h
index 2528af6b57a..908d832daf1 100644
--- a/source/blender/makesrna/RNA_access.h
+++ b/source/blender/makesrna/RNA_access.h
@@ -319,6 +319,7 @@ extern StructRNA RNA_Object;
extern StructRNA RNA_ObjectBase;
extern StructRNA RNA_ObstacleFluidSettings;
extern StructRNA RNA_Operator;
+extern StructRNA RNA_Macro;
extern StructRNA RNA_OperatorFileListElement;
extern StructRNA RNA_OperatorMousePath;
extern StructRNA RNA_OperatorProperties;
diff --git a/source/blender/makesrna/intern/rna_internal.h b/source/blender/makesrna/intern/rna_internal.h
index 5bb3c82395d..22b8388f693 100644
--- a/source/blender/makesrna/intern/rna_internal.h
+++ b/source/blender/makesrna/intern/rna_internal.h
@@ -211,6 +211,7 @@ void RNA_api_armature_edit_bone(StructRNA *srna);
void RNA_api_drivers(StructRNA *srna);
void RNA_api_image(struct StructRNA *srna);
void RNA_api_operator(struct StructRNA *srna);
+void RNA_api_macro(struct StructRNA *srna);
void RNA_api_keyconfig(struct StructRNA *srna);
void RNA_api_keyingset(struct StructRNA *srna);
void RNA_api_keymap(struct StructRNA *srna);
diff --git a/source/blender/makesrna/intern/rna_wm.c b/source/blender/makesrna/intern/rna_wm.c
index 7abba3c004a..e68681919eb 100644
--- a/source/blender/makesrna/intern/rna_wm.c
+++ b/source/blender/makesrna/intern/rna_wm.c
@@ -692,6 +692,7 @@ static void operator_draw(bContext *C, wmOperator *op)
}
void operator_wrapper(wmOperatorType *ot, void *userdata);
+void macro_wrapper(wmOperatorType *ot, void *userdata);
static char _operator_idname[OP_MAX_TYPENAME];
static char _operator_name[OP_MAX_TYPENAME];
@@ -763,12 +764,84 @@ static StructRNA *rna_Operator_register(const bContext *C, ReportList *reports,
return dummyot.ext.srna;
}
+
+static StructRNA *rna_MacroOperator_register(const bContext *C, ReportList *reports, void *data, const char *identifier, StructValidateFunc validate, StructCallbackFunc call, StructFreeFunc free)
+{
+ wmOperatorType dummyot = {0};
+ wmOperator dummyop= {0};
+ PointerRNA dummyotr;
+ int have_function[4];
+
+ /* setup dummy operator & operator type to store static properties in */
+ dummyop.type= &dummyot;
+ dummyot.idname= _operator_idname; /* only assigne the pointer, string is NULL'd */
+ dummyot.name= _operator_name; /* only assigne the pointer, string is NULL'd */
+ dummyot.description= _operator_descr; /* only assigne the pointer, string is NULL'd */
+ RNA_pointer_create(NULL, &RNA_Macro, &dummyop, &dummyotr);
+
+ /* validate the python class */
+ if(validate(&dummyotr, data, have_function) != 0)
+ return NULL;
+
+ { /* convert foo.bar to FOO_OT_bar
+ * allocate the description and the idname in 1 go */
+ int idlen = strlen(_operator_idname) + 4;
+ int namelen = strlen(_operator_name) + 1;
+ int desclen = strlen(_operator_descr) + 1;
+ char *ch, *ch_arr;
+ ch_arr= ch= MEM_callocN(sizeof(char) * (idlen + namelen + desclen), "_operator_idname"); /* 2 terminators and 3 to convert a.b -> A_OT_b */
+ WM_operator_bl_idname(ch, _operator_idname); /* convert the idname from python */
+ dummyot.idname= ch;
+ ch += idlen;
+ strcpy(ch, _operator_name);
+ dummyot.name = ch;
+ ch += namelen;
+ strcpy(ch, _operator_descr);
+ dummyot.description = ch;
+ }
+
+ if(strlen(identifier) >= sizeof(dummyop.idname)) {
+ BKE_reportf(reports, RPT_ERROR, "registering operator class: '%s' is too long, maximum length is %d.", identifier, sizeof(dummyop.idname));
+ return NULL;
+ }
+
+ /* check if we have registered this operator type before, and remove it */
+ {
+ wmOperatorType *ot= WM_operatortype_exists(dummyot.idname);
+ if(ot && ot->ext.srna)
+ rna_Operator_unregister(C, ot->ext.srna);
+ }
+
+ /* create a new menu type */
+ dummyot.ext.srna= RNA_def_struct(&BLENDER_RNA, dummyot.idname, "Operator");
+ dummyot.ext.data= data;
+ dummyot.ext.call= call;
+ dummyot.ext.free= free;
+
+ dummyot.pyop_poll= (have_function[0])? operator_poll: NULL;
+ dummyot.ui= (have_function[3])? operator_draw: NULL;
+
+ WM_operatortype_append_macro_ptr(macro_wrapper, (void *)&dummyot);
+
+ /* update while blender is running */
+ if(C)
+ WM_main_add_notifier(NC_SCREEN|NA_EDITED, NULL);
+
+ return dummyot.ext.srna;
+}
+
static StructRNA* rna_Operator_refine(PointerRNA *opr)
{
wmOperator *op= (wmOperator*)opr->data;
return (op->type && op->type->ext.srna)? op->type->ext.srna: &RNA_Operator;
}
+static StructRNA* rna_MacroOperator_refine(PointerRNA *opr)
+{
+ wmOperator *op= (wmOperator*)opr->data;
+ return (op->type && op->type->ext.srna)? op->type->ext.srna: &RNA_Macro;
+}
+
#else
static void rna_def_operator(BlenderRNA *brna)
@@ -832,6 +905,8 @@ static void rna_def_macro_operator(BlenderRNA *brna)
srna= RNA_def_struct(brna, "Macro", NULL);
RNA_def_struct_ui_text(srna, "Macro Operator", "Storage of a macro operator being executed, or registered after execution.");
RNA_def_struct_sdna(srna, "wmOperator");
+ RNA_def_struct_refine_func(srna, "rna_MacroOperator_refine");
+ RNA_def_struct_register_funcs(srna, "rna_MacroOperator_register", "rna_Operator_unregister");
prop= RNA_def_property(srna, "name", PROP_STRING, PROP_NONE);
RNA_def_property_clear_flag(prop, PROP_EDITABLE);
@@ -844,6 +919,27 @@ static void rna_def_macro_operator(BlenderRNA *brna)
RNA_def_property_struct_type(prop, "OperatorProperties");
RNA_def_property_ui_text(prop, "Properties", "");
RNA_def_property_pointer_funcs(prop, "rna_Operator_properties_get", NULL, NULL);
+
+ /* Registration */
+ prop= RNA_def_property(srna, "bl_idname", PROP_STRING, PROP_NONE);
+ RNA_def_property_string_sdna(prop, NULL, "type->idname");
+ RNA_def_property_string_maxlength(prop, OP_MAX_TYPENAME); /* else it uses the pointer size! */
+ RNA_def_property_flag(prop, PROP_REGISTER);
+
+ prop= RNA_def_property(srna, "bl_label", PROP_STRING, PROP_NONE);
+ RNA_def_property_string_sdna(prop, NULL, "type->name");
+ RNA_def_property_string_maxlength(prop, 1024); /* else it uses the pointer size! */
+ RNA_def_property_flag(prop, PROP_REGISTER);
+
+ prop= RNA_def_property(srna, "bl_register", PROP_BOOLEAN, PROP_NONE);
+ RNA_def_property_boolean_sdna(prop, NULL, "type->flag", OPTYPE_REGISTER);
+ RNA_def_property_flag(prop, PROP_REGISTER_OPTIONAL);
+
+ prop= RNA_def_property(srna, "bl_undo", PROP_BOOLEAN, PROP_NONE);
+ RNA_def_property_boolean_sdna(prop, NULL, "type->flag", OPTYPE_UNDO);
+ RNA_def_property_flag(prop, PROP_REGISTER_OPTIONAL);
+
+ RNA_api_macro(srna);
}
static void rna_def_operator_type_macro(BlenderRNA *brna)
diff --git a/source/blender/makesrna/intern/rna_wm_api.c b/source/blender/makesrna/intern/rna_wm_api.c
index 1afedf1c6a6..9ed6046ecd0 100644
--- a/source/blender/makesrna/intern/rna_wm_api.c
+++ b/source/blender/makesrna/intern/rna_wm_api.c
@@ -237,6 +237,35 @@ void RNA_api_operator(StructRNA *srna)
RNA_def_pointer(func, "context", "Context", "", "");
}
+void RNA_api_macro(StructRNA *srna)
+{
+ FunctionRNA *func;
+ PropertyRNA *parm;
+
+ /* utility, not for registering */
+ func= RNA_def_function(srna, "report", "rna_Operator_report");
+ parm= RNA_def_enum(func, "type", wm_report_items, 0, "Type", "");
+ RNA_def_property_flag(parm, PROP_REQUIRED|PROP_ENUM_FLAG);
+ parm= RNA_def_string(func, "message", "", 0, "Report Message", "");
+ RNA_def_property_flag(parm, PROP_REQUIRED);
+
+
+ /* Registration */
+
+ /* poll */
+ func= RNA_def_function(srna, "poll", NULL);
+ RNA_def_function_ui_description(func, "Test if the operator can be called or not.");
+ RNA_def_function_flag(func, FUNC_REGISTER_OPTIONAL);
+ RNA_def_function_return(func, RNA_def_boolean(func, "visible", 1, "", ""));
+ RNA_def_pointer(func, "context", "Context", "", "");
+
+ /* draw */
+ func= RNA_def_function(srna, "draw", NULL);
+ RNA_def_function_ui_description(func, "Draw function for the operator.");
+ RNA_def_function_flag(func, FUNC_REGISTER_OPTIONAL);
+ RNA_def_pointer(func, "context", "Context", "", "");
+}
+
void RNA_api_keyconfig(StructRNA *srna)
{
FunctionRNA *func;