diff options
author | Brecht Van Lommel <brechtvanlommel@pandora.be> | 2008-11-21 22:14:38 +0300 |
---|---|---|
committer | Brecht Van Lommel <brechtvanlommel@pandora.be> | 2008-11-21 22:14:38 +0300 |
commit | c6da2a59d88a75d00890de5ae1d79408e7f9f906 (patch) | |
tree | 13491555b978c1ec3e6b99caeceaebb7bbbe28ed /source/blender/windowmanager | |
parent | 129585285c47a016cf93fb183117eb86ce544461 (diff) |
RNA
* Added RNA for operators. This still uses ID properties internally,
but through the RNA API now. The OP_get/set_* API that was used is
replaced by the RNA API. Currently RNA properties for operators are
defined at runtime since it means operator registration can be done
in a single function.
* Changed the existing operators to use this system, I haven't defined
user interface names yet though. I also think there need to be some
conventions on which properties to expose to make these operators
usable in macros, for example if mouse coordinates should be stored
or not.
* When using ID properties through defined RNA properties, it now
checks that the ID property actually matches the RNA property and
removes/overwrites it otherwise. This ensures that you can safely
get/set arrays for example without having to worry that some
external thing may have changed the length.
* Documentation now has some information on RNA + ID properties.
http://wiki.blender.org/index.php/BlenderDev/Blender2.5/RNA
Diffstat (limited to 'source/blender/windowmanager')
-rw-r--r-- | source/blender/windowmanager/SConscript | 1 | ||||
-rw-r--r-- | source/blender/windowmanager/WM_api.h | 60 | ||||
-rw-r--r-- | source/blender/windowmanager/intern/Makefile | 1 | ||||
-rw-r--r-- | source/blender/windowmanager/intern/wm.c | 18 | ||||
-rw-r--r-- | source/blender/windowmanager/intern/wm_event_system.c | 6 | ||||
-rw-r--r-- | source/blender/windowmanager/intern/wm_init_exit.c | 4 | ||||
-rw-r--r-- | source/blender/windowmanager/intern/wm_operators.c | 13 |
7 files changed, 38 insertions, 65 deletions
diff --git a/source/blender/windowmanager/SConscript b/source/blender/windowmanager/SConscript index cdc5edfeaa6..7e591ad34f6 100644 --- a/source/blender/windowmanager/SConscript +++ b/source/blender/windowmanager/SConscript @@ -9,6 +9,7 @@ sources = env.Glob('intern/*.c') incs = '. ../editors/include ../python ../makesdna ../blenlib ../blenkernel' incs += ' ../nodes ../imbuf ../blenloader ../render/extern/include' incs += ' ../ftfont ../radiosity/extern/include ../../kernel/gen_system' +incs += ' ../makesrna' incs += ' #/intern/guardedalloc #/intern/memutil #/intern/ghost #/intern/bmfont' incs += ' #/intern/elbeem #/extern/glew/include' diff --git a/source/blender/windowmanager/WM_api.h b/source/blender/windowmanager/WM_api.h index b81184df049..cb2bc80dfd2 100644 --- a/source/blender/windowmanager/WM_api.h +++ b/source/blender/windowmanager/WM_api.h @@ -103,66 +103,6 @@ void WM_operator_cancel (struct bContext *C, ListBase *modalops, wmOperatorTyp int WM_border_select_invoke (struct bContext *C, wmOperator *op, struct wmEvent *event); int WM_border_select_modal (struct bContext *C, wmOperator *op, struct wmEvent *event); -/* - * Operator property api - * - * Some notes to take care: - * - * All the OP_set_* functions append a new property to the operator, - * if the property already exist, just replace it with the new - * value in other case make a new property and append it. - * - * The OP_get_string function is a "special case", this function - * return a pointer to property data, so don't change/resize/free - * the string, because probably we get a segfault. - * I really think that is better duplicate the string, so we are - * really sure that the property data don't change. - * - * OP_get_int/float/array return 1 on success (found the property) - * or 0 if can't find the property in the operator. - * The property value are store in the "value" pointer. - * - * OP_verify_* sets the value only if it wasn't set already, and - * returns the existing or new value. - * - * Both array function copy the property data into the "array" - * pointer, but you need init the len pointer to the "array" size. - * - * For example: - * int vec[] = { 1, 2, 3, 4 }; - * OP_set_int_array (op, "vector", vec, 4); - * - * ... - * - * short len; - * int vec[4]; - * len= 4; <---- set the size!! - * OP_get_int_array (op, "vector", vec, &len); - */ -void OP_set_int (wmOperator *op, char *name, int value); -void OP_set_float (wmOperator *op, char *name, float value); -void OP_set_string (wmOperator *op, char *name, char *str); -void OP_set_int_array(wmOperator *op, char *name, int *array, short len); -void OP_set_float_array(wmOperator *op, char *name, float *array, short len); - -int OP_get_int (wmOperator *op, char *name, int *value); -int OP_get_float (wmOperator *op, char *name, float *value); -char *OP_get_string (wmOperator *op, char *name); -int OP_get_int_array(wmOperator *op, char *name, int *array, short *len); -int OP_get_float_array(wmOperator *op, char *name, float *array, short *len); - -void OP_verify_int (wmOperator *op, char *name, int value, int *result); -void OP_verify_float (wmOperator *op, char *name, float value, int *result); -char *OP_verify_string(wmOperator *op, char *name, char *str); -void OP_verify_int_array(wmOperator *op, char *name, int *array, short len, int *resultarray, short *resultlen); -void OP_verify_float_array(wmOperator *op, char *name, float *array, short len, float *resultarray, short *resultlen); - -/* - * Need call this function in the "exit callback" - * of the operator, but only if you use the property system. - **/ -void OP_free_property(wmOperator *op); - /* Gesture manager API */ struct wmGesture *WM_gesture_new(struct bContext *C, struct wmEvent *event, int type); void WM_gesture_end(struct bContext *C, struct wmGesture *gesture); diff --git a/source/blender/windowmanager/intern/Makefile b/source/blender/windowmanager/intern/Makefile index cbd0b3afa87..00412f00445 100644 --- a/source/blender/windowmanager/intern/Makefile +++ b/source/blender/windowmanager/intern/Makefile @@ -51,6 +51,7 @@ CPPFLAGS += -I$(NAN_SOUNDSYSTEM)/include $(NAN_SDLCFLAGS) CPPFLAGS += -I../../editors/include CPPFLAGS += -I../../python CPPFLAGS += -I../../makesdna +CPPFLAGS += -I../../makesrna CPPFLAGS += -I../../blenlib CPPFLAGS += -I../../blenkernel CPPFLAGS += -I../../nodes diff --git a/source/blender/windowmanager/intern/wm.c b/source/blender/windowmanager/intern/wm.c index 165ca88ab71..8a18cb71893 100644 --- a/source/blender/windowmanager/intern/wm.c +++ b/source/blender/windowmanager/intern/wm.c @@ -53,7 +53,18 @@ void wm_operator_free(wmOperator *op) { - OP_free_property(op); + if(op->properties) { + IDP_FreeProperty(op->properties); + + /* This need change, when the idprop code only + * need call IDP_FreeProperty. (check BKE_idprop.h) */ + MEM_freeN(op->properties); + op->properties= NULL; + } + + if(op->rna) + MEM_freeN(op->rna); + MEM_freeN(op); } @@ -62,6 +73,11 @@ void wm_operator_free(wmOperator *op) void wm_operator_register(wmWindowManager *wm, wmOperator *op) { int tot; + + if(op->rna) { + MEM_freeN(op->rna); + op->rna= NULL; + } BLI_addtail(&wm->operators, op); tot= BLI_countlist(&wm->operators); diff --git a/source/blender/windowmanager/intern/wm_event_system.c b/source/blender/windowmanager/intern/wm_event_system.c index d2143fe5028..d0f812e31e6 100644 --- a/source/blender/windowmanager/intern/wm_event_system.c +++ b/source/blender/windowmanager/intern/wm_event_system.c @@ -46,6 +46,8 @@ #include "ED_screen.h" #include "ED_area.h" +#include "RNA_access.h" + #include "WM_api.h" #include "WM_types.h" #include "wm.h" @@ -290,6 +292,10 @@ int WM_operator_invoke(bContext *C, wmOperatorType *ot, wmEvent *event) op->type= ot; + op->rna= MEM_callocN(sizeof(PointerRNA), "wmOperatorPtrRNA"); + op->rna->type= op->type->rna; + op->rna->data= op; + if(op->type->invoke) retval= (*op->type->invoke)(C, op, event); else if(op->type->exec) diff --git a/source/blender/windowmanager/intern/wm_init_exit.c b/source/blender/windowmanager/intern/wm_init_exit.c index 422a655f53a..c196f7a4fff 100644 --- a/source/blender/windowmanager/intern/wm_init_exit.c +++ b/source/blender/windowmanager/intern/wm_init_exit.c @@ -70,6 +70,8 @@ #include "UI_interface.h" +#include "RNA_define.h" + #include "WM_api.h" #include "WM_types.h" #include "wm.h" @@ -237,6 +239,8 @@ void WM_exit(bContext *C) UI_exit(); BLI_freelistN(&U.themes); // XXX BIF_preview_free_dbase(); + + RNA_exit(); MEM_freeN(C); diff --git a/source/blender/windowmanager/intern/wm_operators.c b/source/blender/windowmanager/intern/wm_operators.c index 5374592180e..b8c822592df 100644 --- a/source/blender/windowmanager/intern/wm_operators.c +++ b/source/blender/windowmanager/intern/wm_operators.c @@ -42,6 +42,9 @@ #include "BKE_main.h" #include "BKE_idprop.h" +#include "RNA_access.h" +#include "RNA_define.h" + #include "WM_api.h" #include "WM_types.h" @@ -70,7 +73,9 @@ void WM_operatortype_append(void (*opfunc)(wmOperatorType*)) wmOperatorType *ot; ot= MEM_callocN(sizeof(wmOperatorType), "operatortype"); + ot->rna= RNA_def_struct(&BLENDER_RNA, "", "Operator", ""); opfunc(ot); + RNA_def_struct_identifier(ot->rna, ot->idname, ot->name); BLI_addtail(&global_ops, ot); } @@ -144,10 +149,10 @@ static void border_select_apply(bContext *C, wmOperator *op) rcti *rect= gesture->customdata; /* operator arguments and storage. */ - OP_verify_int(op, "xmin", rect->xmin, NULL); - OP_verify_int(op, "ymin", rect->ymin, NULL); - OP_verify_int(op, "xmax", rect->xmax, NULL); - OP_verify_int(op, "ymax", rect->ymax, NULL); + RNA_int_default(op->rna, "xmin", rect->xmin); + RNA_int_default(op->rna, "ymin", rect->ymin); + RNA_int_default(op->rna, "xmax", rect->xmax); + RNA_int_default(op->rna, "ymax", rect->ymax); op->type->exec(C, op); } |