[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [13237] branches/blender2.5/blender/source /blender: New API to access Operator properties.

Diego Borghetti (Plumiferos) bdiego at gmail.com
Mon Jan 14 20:44:20 CET 2008


Revision: 13237
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=13237
Author:   bdiego
Date:     2008-01-14 20:44:20 +0100 (Mon, 14 Jan 2008)

Log Message:
-----------
New API to access Operator properties.

This is a simple API around IDProperty to store properties
in the Operator, it is really simple and this first commit
just add support for IDP_INT data type.

Take care that this "properties" are not save yet and you get
some "Error totblock" more with this.

I add some notes to the WM_api.h file, please check this,
comment and ideas are welcome.

Modified Paths:
--------------
    branches/blender2.5/blender/source/blender/editors/screen/screen_edit.c
    branches/blender2.5/blender/source/blender/makesdna/DNA_windowmanager_types.h
    branches/blender2.5/blender/source/blender/windowmanager/WM_api.h
    branches/blender2.5/blender/source/blender/windowmanager/intern/wm.c
    branches/blender2.5/blender/source/blender/windowmanager/intern/wm_operators.c

Modified: branches/blender2.5/blender/source/blender/editors/screen/screen_edit.c
===================================================================
--- branches/blender2.5/blender/source/blender/editors/screen/screen_edit.c	2008-01-14 19:03:27 UTC (rev 13236)
+++ branches/blender2.5/blender/source/blender/editors/screen/screen_edit.c	2008-01-14 19:44:20 UTC (rev 13237)
@@ -646,16 +646,13 @@
 
 */
 
-/* "global" variables for all functions inside this operator */
-/*  we could do it with properties? */
-static int	bigger, smaller, dir, origval;
-	
 /* validate selection inside screen, set variables OK */
 /* return 0: init failed */
 static int move_areas_init (bContext *C, wmOperator *op)
 {
 	ScrEdge *actedge= screen_find_active_scredge(C->screen, op->veci.x, op->veci.y);
 	ScrArea *sa;
+	int bigger, smaller, dir, origval;
 	
 	if(actedge==NULL) return 0;
 	
@@ -691,7 +688,12 @@
 			}
 		}
 	}
-	
+
+	OP_set_int(op, "bigger", bigger);
+	OP_set_int(op, "smaller", smaller);
+	OP_set_int(op, "dir", dir);
+	OP_set_int(op, "origval", origval);
+
 	return 1;
 }
 
@@ -700,6 +702,12 @@
 static int move_areas_exec(bContext *C, wmOperator *op)
 {
 	ScrVert *v1;
+	int bigger, smaller, dir, origval;
+
+	OP_get_int(op, "bigger", &bigger);
+	OP_get_int(op, "smaller", &smaller);
+	OP_get_int(op, "dir", &dir);
+	OP_get_int(op, "origval", &origval);
 	
 	op->delta= CLAMPIS(op->delta, -smaller, bigger);
 	
@@ -760,6 +768,10 @@
 /* return 0 = stop evaluating for next handlers */
 static int move_areas_modal (bContext *C, wmOperator *op, wmEvent *event)
 {
+	int dir;
+
+	OP_get_int(op, "dir", &dir);
+
 	/* execute the events */
 	switch(event->type) {
 		case MOUSEMOVE:

Modified: branches/blender2.5/blender/source/blender/makesdna/DNA_windowmanager_types.h
===================================================================
--- branches/blender2.5/blender/source/blender/makesdna/DNA_windowmanager_types.h	2008-01-14 19:03:27 UTC (rev 13236)
+++ branches/blender2.5/blender/source/blender/makesdna/DNA_windowmanager_types.h	2008-01-14 19:44:20 UTC (rev 13237)
@@ -163,7 +163,7 @@
 	/* custom storage, dna pointer */
 	void *customdata; 
 	/* or IDproperty list */
-	void *properties;
+	IDProperty *properties;
 
 	
 } wmOperator;

Modified: branches/blender2.5/blender/source/blender/windowmanager/WM_api.h
===================================================================
--- branches/blender2.5/blender/source/blender/windowmanager/WM_api.h	2008-01-14 19:03:27 UTC (rev 13236)
+++ branches/blender2.5/blender/source/blender/windowmanager/WM_api.h	2008-01-14 19:44:20 UTC (rev 13237)
@@ -81,6 +81,22 @@
 wmOperatorType *WM_operatortype_find(const char *idname);
 void		WM_operatortypelist_append(ListBase *lb);
 
+/* 
+ * Operator property api
+ *
+ * Some notes to take care:
+ *
+ * OP_set_int try to append a new property to the operator,
+ * if the property already exist, just replace it with the
+ * value in other case make a new property and append it.
+ *
+ * OP_get_int return 0 on success (found the property) or
+ * != 0 if can't found the property in the operator.
+ * The property value are store in the "value" pointer.
+ */
+void OP_set_int(wmOperator *op, char *name, int value);
+int OP_get_int(wmOperator *op, char *name, int *value);
+
 			/* OpenGL wrappers, mimicing opengl syntax */
 void		wmLoadMatrix		(wmWindow *win, float mat[][4]);
 void		wmGetMatrix			(wmWindow *win, float mat[][4]);

Modified: branches/blender2.5/blender/source/blender/windowmanager/intern/wm.c
===================================================================
--- branches/blender2.5/blender/source/blender/windowmanager/intern/wm.c	2008-01-14 19:03:27 UTC (rev 13236)
+++ branches/blender2.5/blender/source/blender/windowmanager/intern/wm.c	2008-01-14 19:44:20 UTC (rev 13237)
@@ -36,6 +36,7 @@
 #include "BKE_global.h"
 #include "BKE_library.h"
 #include "BKE_main.h"
+#include "BKE_idprop.h"
 
 #include "WM_api.h"
 #include "WM_types.h"
@@ -124,6 +125,7 @@
 /* context is allowed to be NULL, do net free wm itself (library.c) */
 void wm_close_and_free(bContext *C, wmWindowManager *wm)
 {
+	wmOperator *op;
 	wmWindow *win;
 	
 	while((win= wm->windows.first)) {
@@ -131,6 +133,19 @@
 		wm_window_free(C, win);
 	}
 	
+	op= wm->operators.first;
+	while(op) {
+		/*
+		 * Need this, because if the operator don't have
+		 * properties also don't have group.
+		 */
+		if(op->properties) {
+			IDP_FreeGroup(op->properties);
+			op->properties= NULL;
+		}
+		op= op->next;
+	}
+
 	BLI_freelistN(&wm->operators);
 	
 	BLI_freelistN(&wm->windowkeymap);

Modified: branches/blender2.5/blender/source/blender/windowmanager/intern/wm_operators.c
===================================================================
--- branches/blender2.5/blender/source/blender/windowmanager/intern/wm_operators.c	2008-01-14 19:03:27 UTC (rev 13236)
+++ branches/blender2.5/blender/source/blender/windowmanager/intern/wm_operators.c	2008-01-14 19:44:20 UTC (rev 13237)
@@ -28,6 +28,7 @@
 
 #include <string.h>
 
+#include "DNA_ID.h"
 #include "DNA_windowmanager_types.h"
 
 #include "MEM_guardedalloc.h"
@@ -38,6 +39,7 @@
 #include "BKE_global.h"
 #include "BKE_library.h"
 #include "BKE_main.h"
+#include "BKE_idprop.h"
 
 #include "WM_api.h"
 #include "WM_types.h"
@@ -136,7 +138,47 @@
     ADD_OPTYPE(WM_OT_window_fullscreen_toggle);
 }
 
+/* wrapped to get property from a operator. */
+IDProperty *op_get_property(wmOperator *op, char *name)
+{
+	IDProperty *prop= IDP_GetPropertyFromGroup(op->properties, name);
+	return(prop);
+}
 
+/*
+ * We need create a "group" to store the operator properties.
+ * We don't have a WM_operator_new or some thing like that,
+ * so this function is called by all the OP_set_* function
+ * in case that op->properties is equal to NULL.
+ */
+void op_init_property(wmOperator *op)
+{
+	IDPropertyTemplate val;
+	op->properties= IDP_New(IDP_GROUP, val, "property");
+}
 
+/* ***** Property API, exported ***** */
+void OP_set_int(wmOperator *op, char *name, int value)
+{
+	IDPropertyTemplate val;
+	IDProperty *prop;
 
+	if(!op->properties)
+		op_init_property(op);
 
+	val.i= value;
+	prop= IDP_New(IDP_INT, val, name);
+	IDP_ReplaceInGroup(op->properties, prop);
+}
+
+int OP_get_int(wmOperator *op, char *name, int *value)
+{
+	IDProperty *prop= op_get_property(op, name);
+	int status= 1;
+
+	if ((prop) && (prop->type == IDP_INT)) {
+		(*value)= prop->data.val;
+		status= 0;
+	}
+	return (status);
+}





More information about the Bf-blender-cvs mailing list