[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [30864] branches/soc-2010-aligorith-2: Bullet SoC - Manipulator API (WIP Basics)

Joshua Leung aligorith at gmail.com
Thu Jul 29 07:08:16 CEST 2010


Revision: 30864
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=30864
Author:   aligorith
Date:     2010-07-29 07:08:15 +0200 (Thu, 29 Jul 2010)

Log Message:
-----------
Bullet SoC - Manipulator API (WIP Basics)

This commit is still very much WIP stuff. Just committing this first part now before I mess things up getting the remaining parts working. Not usable for any real/user testing yet.
* No File I/O stuff yet (that'll come later when I get it some visible/functioning results)
* No proper freeing of manipulators instances yet. This will come along with File I/O

What works/is done:
* A very primitive (read ugly-looking) and likely to be replaced by a fancier alternative at some point widget/template for quick access to manipulators for an editor. 
- Is only barebones enough to access stuff we need, and nothing more
- Currently only seen on 3D-View header, and in a temporary place

* Exposed icons enum (RNA) via RNA_enum_types.h instead of having it for rna_ui_api.c only

* Manipulators registry (like for operators), defining the manipulator types (callbacks storage). By and large, this should be working ok. 
* Manipulator instances are stored per editor. Each spacelink also stores (unused) manipulator instances, to be restored when they are restored.

* Added a test manipulator which should just draw a semi-transparent box on screen.
- Proves that registration currently works ok
- But also is waiting on the remaining steps to be testable

Next Steps:
* Figure out where to add code to register drawing callbacks. I'm thinking about to go back to using one of my earlier plans which would've allowed this to be quite easily managed...

* Figure out a "safe" way to link up the required operator to manipulators. Currently (or before I disabled it temporarily) RNA complains about wrong types when trying to set this up in the most natural way.

Modified Paths:
--------------
    branches/soc-2010-aligorith-2/release/scripts/modules/bpy/utils.py
    branches/soc-2010-aligorith-2/release/scripts/ui/space_view3d.py
    branches/soc-2010-aligorith-2/source/blender/editors/include/UI_interface.h
    branches/soc-2010-aligorith-2/source/blender/editors/interface/interface_templates.c
    branches/soc-2010-aligorith-2/source/blender/editors/screen/area.c
    branches/soc-2010-aligorith-2/source/blender/makesdna/DNA_action_types.h
    branches/soc-2010-aligorith-2/source/blender/makesdna/DNA_screen_types.h
    branches/soc-2010-aligorith-2/source/blender/makesdna/DNA_sound_types.h
    branches/soc-2010-aligorith-2/source/blender/makesdna/DNA_space_types.h
    branches/soc-2010-aligorith-2/source/blender/makesdna/DNA_view3d_types.h
    branches/soc-2010-aligorith-2/source/blender/makesdna/DNA_windowmanager_types.h
    branches/soc-2010-aligorith-2/source/blender/makesrna/RNA_access.h
    branches/soc-2010-aligorith-2/source/blender/makesrna/RNA_enum_types.h
    branches/soc-2010-aligorith-2/source/blender/makesrna/intern/rna_internal.h
    branches/soc-2010-aligorith-2/source/blender/makesrna/intern/rna_screen.c
    branches/soc-2010-aligorith-2/source/blender/makesrna/intern/rna_ui_api.c
    branches/soc-2010-aligorith-2/source/blender/makesrna/intern/rna_wm.c
    branches/soc-2010-aligorith-2/source/blender/makesrna/intern/rna_wm_api.c
    branches/soc-2010-aligorith-2/source/blender/windowmanager/WM_api.h
    branches/soc-2010-aligorith-2/source/blender/windowmanager/WM_types.h
    branches/soc-2010-aligorith-2/source/blender/windowmanager/intern/wm_init_exit.c
    branches/soc-2010-aligorith-2/source/blender/windowmanager/wm.h

Added Paths:
-----------
    branches/soc-2010-aligorith-2/release/scripts/manipulators/
    branches/soc-2010-aligorith-2/release/scripts/manipulators/manips_transform.py
    branches/soc-2010-aligorith-2/source/blender/python/intern/bpy_manipulator_wrap.c
    branches/soc-2010-aligorith-2/source/blender/python/intern/bpy_manipulator_wrap.h
    branches/soc-2010-aligorith-2/source/blender/windowmanager/intern/wm_manipulator.c

Added: branches/soc-2010-aligorith-2/release/scripts/manipulators/manips_transform.py
===================================================================
--- branches/soc-2010-aligorith-2/release/scripts/manipulators/manips_transform.py	                        (rev 0)
+++ branches/soc-2010-aligorith-2/release/scripts/manipulators/manips_transform.py	2010-07-29 05:08:15 UTC (rev 30864)
@@ -0,0 +1,101 @@
+# Transform Manipulators
+# XXX: maybe these will eventually end up back in C again...
+
+import bpy
+import blf
+from bgl import *
+
+###############################
+# Dummy Test Manipulator
+# XXX - this manipulator should be removed once we get a few more done
+
+class MANIPULATOR_OT_activeop_test(bpy.types.Operator):
+	bl_name = "Test Manipulator Interact"
+	bl_label = "Interactive operator for active 'Test' Manipulator"
+	
+	def poll(self, context):
+		# XXX: must verify that manipulator is ok...
+		return True;
+	
+	def modal(self, context, event):
+		# get data
+		# FIXME: need way to get the manipulator
+		manip = None # XXX
+		
+		# handle events
+		if event in ('ESC', 'RET'):
+			# done
+			return {'FINISHED'}
+		else:
+			# TODO: handle other events... 
+			pass;
+		
+		return {'RUNNING_MODAL'}
+
+class MANIPULATOR_MANIP_test(bpy.types.Manipulator):
+	bl_label = "Test Manipulator"
+	bl_description = "A manipulator to run us through our paces"
+	#bl_operator = MANIPULATOR_OT_activeop_test
+	bl_icon = 'RADIO'
+	bl_draw_space = 'POST_PIXEL'
+	
+	def poll_possible(self, editor_type):
+		# TODO: do others later too, but only 3d view can support this for now
+		return editor_type in ('VIEW_3D')
+		
+	def poll_applicable(self, context):
+		# just always show for now (to avoid complications)
+		return True
+	
+	def draw_idle(self, context):
+		# just draw simple blue rect on screen
+		glColor4f(0.2, 0.45, 1.0, 0.8)
+		
+		glBegin(GL_QUADS)
+		glVertex2f(10.0, 10.0)
+		glVertex2f(10.0, 80.0)
+		glVertex2f(80.0, 80.0)
+		glVertex2f(80.0, 10.0)
+		glEnd() # GL_QUADS
+		
+	def draw_active(self, context, op):
+		# draw simple red rect on screen
+		glColor4f(1.0, 0.3, 0.0, 0.8)
+		
+		glBegin(GL_QUADS)
+		glVertex2f(10.0, 10.0)
+		glVertex2f(10.0, 80.0)
+		glVertex2f(80.0, 80.0)
+		glVertex2f(80.0, 10.0)
+		glEnd() # GL_QUADS
+		
+		# write special info
+		blf.position(20, 40, 0)
+		glColor3f(1.0, 1.0, 1.0)
+		blf.draw("Sample text - Active")
+
+
+############################### 
+
+classes = [
+		# XXX: testing manipulator...
+	MANIPULATOR_OT_activeop_test,
+	MANIPULATOR_MANIP_test
+]
+
+
+def register():
+	register = bpy.types.register
+	for cls in classes:
+		register(cls)
+
+
+def unregister():
+	unregister = bpy.types.unregister
+	for cls in classes:
+		unregister(cls)
+
+if __name__ == "__main__":
+	register()
+
+############################### 

Modified: branches/soc-2010-aligorith-2/release/scripts/modules/bpy/utils.py
===================================================================
--- branches/soc-2010-aligorith-2/release/scripts/modules/bpy/utils.py	2010-07-29 04:33:26 UTC (rev 30863)
+++ branches/soc-2010-aligorith-2/release/scripts/modules/bpy/utils.py	2010-07-29 05:08:15 UTC (rev 30864)
@@ -179,7 +179,7 @@
     user_path = user_script_path()
 
     for base_path in script_paths():
-        for path_subdir in ("", "ui", "op", "io", "cfg", "keyingsets", "modules"):
+        for path_subdir in ("", "ui", "op", "io", "cfg", "keyingsets", "manipulators", "modules"):
             path = _os.path.join(base_path, path_subdir)
             if _os.path.isdir(path):
                 sys_path_ensure(path)

Modified: branches/soc-2010-aligorith-2/release/scripts/ui/space_view3d.py
===================================================================
--- branches/soc-2010-aligorith-2/release/scripts/ui/space_view3d.py	2010-07-29 04:33:26 UTC (rev 30863)
+++ branches/soc-2010-aligorith-2/release/scripts/ui/space_view3d.py	2010-07-29 05:08:15 UTC (rev 30864)
@@ -107,6 +107,8 @@
             row.operator("pose.paste", text="", icon='PASTEDOWN')
             props = row.operator("pose.paste", text="", icon='PASTEFLIPDOWN')
             props.flipped = 1
+            
+        layout.template_manipulator_controls()
 
 
 # ********** Menu **********

Modified: branches/soc-2010-aligorith-2/source/blender/editors/include/UI_interface.h
===================================================================
--- branches/soc-2010-aligorith-2/source/blender/editors/include/UI_interface.h	2010-07-29 04:33:26 UTC (rev 30863)
+++ branches/soc-2010-aligorith-2/source/blender/editors/include/UI_interface.h	2010-07-29 05:08:15 UTC (rev 30864)
@@ -694,6 +694,7 @@
 void uiTemplateHeader3D(uiLayout *layout, struct bContext *C);
 void uiTemplateTextureImage(uiLayout *layout, struct bContext *C, struct Tex *tex);
 void uiTemplateReportsBanner(uiLayout *layout, struct bContext *C);
+void uiTemplateManipulators(uiLayout *layout, struct bContext *C);
 
 void uiTemplateList(uiLayout *layout, struct bContext *C, struct PointerRNA *ptr, char *propname, struct PointerRNA *activeptr, char *activeprop, int rows, int maxrows, int type);
 

Modified: branches/soc-2010-aligorith-2/source/blender/editors/interface/interface_templates.c
===================================================================
--- branches/soc-2010-aligorith-2/source/blender/editors/interface/interface_templates.c	2010-07-29 04:33:26 UTC (rev 30863)
+++ branches/soc-2010-aligorith-2/source/blender/editors/interface/interface_templates.c	2010-07-29 05:08:15 UTC (rev 30864)
@@ -2519,3 +2519,54 @@
 
 }
 
+/************************* Manipulators for Area Template **************************/
+
+// TODO:
+//	- extend this to allow column layouts too...
+//	- perhaps consider another form of UI instead?
+
+void uiTemplateManipulators(uiLayout *layout, bContext *C)
+{
+	ScrArea *sa = CTX_wm_area(C);
+	wmManipulator *man;
+	uiLayout *row;
+	
+	/* santiy checks */
+	if ELEM(NULL, sa, sa->manipulators.first)
+		return;
+		
+	/* set up widget */
+	row = uiLayoutRow(layout, 1);
+	uiItemL(row, "Manips:", ICON_MANIPUL);
+	
+	/* manipulators */
+	for (man = sa->manipulators.first; man; man = man->next) {
+		wmManipulatorType *mti = man->type;
+		PointerRNA ptr;
+		
+		/* setup work */
+		if (mti == NULL)
+			man->type = mti = WM_manipulatortype_find(man->idname, 1); // XXX?
+		RNA_pointer_create(NULL, &RNA_Manipulator, man, &ptr);
+		
+		/* simply display a toggle for each manipulator for the visibility
+		 * state of the manipulator
+		 *	- if there's a valid icon, use that
+		 *	- otherwise, use the first two letters in the name
+		 */
+		if (mti->icon == 0) {
+			char name[3];
+			
+			/* manually construct 3-char name string */
+			// xxx: review later whether this is really usable or not...
+			name[0] = mti->name[0];
+			name[1] = (mti->name[1])? mti->name[1] : ' ';
+			name[2] = '\0';
+			
+			/* use name instead of icon... */
+			uiItemR(row, &ptr, "visible", UI_ITEM_R_TOGGLE, name, 0);
+		}
+		else
+			uiItemR(row, &ptr, "visible", 0, "", man->type->icon);
+	} 
+}

Modified: branches/soc-2010-aligorith-2/source/blender/editors/screen/area.c
===================================================================
--- branches/soc-2010-aligorith-2/source/blender/editors/screen/area.c	2010-07-29 04:33:26 UTC (rev 30863)
+++ branches/soc-2010-aligorith-2/source/blender/editors/screen/area.c	2010-07-29 05:08:15 UTC (rev 30864)
@@ -861,6 +861,56 @@
 	}
 }
 
+static void ed_manipulator_instances_init(ScrArea *sa)
+{
+	ListBase typelinks = {NULL, NULL}; 	/* list of manipulators that should appear */
+	ListBase newManips = {NULL, NULL};	/* list of manipulators editor should have */
+	LinkData *ld;
+	
+	/* get list of manipulator types that can possibly appear in editortype */
+	// XXX: ideally we'd have this stored in spacetypes once, but it's easier for now to query on the fly...
+	WM_manipulatortypes_for_editor(sa->spacetype, &typelinks);
+	
+	/* for each type, make sure we have an instance of it */
+	// FIXME: this is actually quite slow to be done everytime a view is resized, but we've got no other choice
+	// for when we need things set when new areas are set up...
+	for (ld = typelinks.first; ld; ld = ld->next) {
+		wmManipulatorType *mti = ld->data;
+		wmManipulator *man;
+		
+		/* try to find match from editor's existing manipulators 
+		 * NOTE: we can only do a name match, since the typeinfo is probably not hooked up...
+		 */
+		for (man = sa->manipulators.first; man; man = man->next) {
+			if (strcmp(man->idname, mti->idname) == 0) {
+				/* prepare to move this instance across */
+				BLI_remlink(&sa->manipulators, man);
+				break;
+			}
+		}
+		
+		/* if no instance found, so make a new one */
+		if (man == NULL) {
+			// TODO: make a "create manipulator" call?
+			man = MEM_callocN(sizeof(wmManipulator), "wmManipulator Instance");
+			
+			man->type = mti;
+			BLI_snprintf(man->idname, sizeof(man->idname), mti->idname);
+		}
+		
+		/* add instance to list of new manips */
+		BLI_addtail(&newManips, man);
+	}
+	
+	/* replace old list with new list
+	 *	- all manipulators still in old list are now invalid
+	 */
+	WM_manipulator_free_list(&sa->manipulators);
+	sa->manipulators = newManips;
+	
+	/* cleanup */
+	BLI_freelistN(&typelinks);
+}
 
 /* called in screen_refresh, or screens_init, also area size changes */
 void ED_area_initialize(wmWindowManager *wm, wmWindow *win, ScrArea *sa)
@@ -910,8 +960,10 @@
 			/* prevent uiblocks to run */
 			uiFreeBlocks(NULL, &ar->uiblocks);	
 		}
-		
 	}
+	
+	/* manipulator instaces */
+	ed_manipulator_instances_init(sa);
 }
 
 /* externally called for floating regions like menus */
@@ -1048,12 +1100,16 @@
 		}
 		
 		if (sl) {
-			
 			/* swap regions */
 			slold->regionbase= sa->regionbase;
 			sa->regionbase= sl->regionbase;
 			sl->regionbase.first= sl->regionbase.last= NULL;
 			
+			/* swap manipulator instances too */
+			slold->manipulators= sa->manipulators;
+			sa->manipulators= sl->manipulators;
+			sl->manipulators.first= sl->manipulators.last= NULL;
+			
 			/* put in front of list */
 			BLI_remlink(&sa->spacedata, sl);
 			BLI_addhead(&sa->spacedata, sl);
@@ -1069,6 +1125,12 @@
 					slold->regionbase= sa->regionbase;
 				sa->regionbase= sl->regionbase;
 				sl->regionbase.first= sl->regionbase.last= NULL;
+				
+				/* swap manipulator instances too */
+				if(slold)
+					slold->manipulators= sa->manipulators;
+				sa->manipulators= sl->manipulators;
+				sl->manipulators.first= sl->manipulators.last= NULL;
 			}
 		}
 		


@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list