[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [28492] branches/branch-farsthary/source/ blender: Applied Group restrictions patch (Group as layers) that add layer manager functionality to the groups in the outliner.

Raul Fernandez Hernandez farsthary at gmail.com
Wed Apr 28 17:09:43 CEST 2010


Revision: 28492
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=28492
Author:   farsthary
Date:     2010-04-28 17:09:43 +0200 (Wed, 28 Apr 2010)

Log Message:
-----------
Applied Group restrictions patch (Group as layers) that add layer manager functionality to the groups in the outliner.
 It allows groups to be restricted their visibility, selectability and renderability as  whole, very useful for huge scene management.
 

Modified Paths:
--------------
    branches/branch-farsthary/source/blender/editors/space_outliner/outliner.c
    branches/branch-farsthary/source/blender/makesdna/DNA_group_types.h
    branches/branch-farsthary/source/blender/makesrna/intern/rna_group.c

Modified: branches/branch-farsthary/source/blender/editors/space_outliner/outliner.c
===================================================================
--- branches/branch-farsthary/source/blender/editors/space_outliner/outliner.c	2010-04-28 14:36:36 UTC (rev 28491)
+++ branches/branch-farsthary/source/blender/editors/space_outliner/outliner.c	2010-04-28 15:09:43 UTC (rev 28492)
@@ -124,6 +124,8 @@
 static void outliner_draw_tree_element(bContext *C, uiBlock *block, Scene *scene, ARegion *ar, SpaceOops *soops, TreeElement *te, int startx, int *starty);
 static void outliner_do_object_operation(bContext *C, Scene *scene, SpaceOops *soops, ListBase *lb, 
 										 void (*operation_cb)(bContext *C, Scene *scene, TreeElement *, TreeStoreElem *, TreeStoreElem *));
+static void outliner_do_group_operation(bContext *C, Scene *scene, SpaceOops *soops, ListBase *lb, 
+ 										 void (*operation_cb)(bContext *C, Scene *scene, TreeElement *, TreeStoreElem *, TreeStoreElem *));
 
 
 /* ******************** PERSISTANT DATA ***************** */
@@ -1580,6 +1582,36 @@
 }
 
 /* --- */
+static void group_toggle_visibility_cb(bContext *C, Scene *scene, TreeElement *te, TreeStoreElem *tsep, TreeStoreElem *tselem) {
+ 	Group *group= (Group *)tselem->id;
+ 	GroupObject *gob;
+ 	
+	group->restrictflag ^= GR_RESTRICT_VIEW;	
+	for(gob=group->gobject.first; gob; gob=gob->next) { 		
+		gob->ob->restrictflag  = group->restrictflag; 	
+ 	}	
+}
+ 
+static void group_toggle_selectability_cb(bContext *C, Scene *scene, TreeElement *te, TreeStoreElem *tsep, TreeStoreElem *tselem) {
+ 	Group *group= (Group *)tselem->id;
+ 	GroupObject *gob;
+ 		
+	group->restrictflag ^= GR_RESTRICT_SELECT;	
+	for(gob=group->gobject.first; gob; gob=gob->next) { 		
+		gob->ob->restrictflag  = group->restrictflag; 	
+ 	}
+}
+ 
+static void group_toggle_renderability_cb(bContext *C, Scene *scene, TreeElement *te, TreeStoreElem *tsep, TreeStoreElem *tselem) {
+	Group *group= (Group *)tselem->id;
+	GroupObject *gob;
+ 		
+	group->restrictflag ^= GR_RESTRICT_RENDER;	
+	for(gob=group->gobject.first; gob; gob=gob->next) { 		
+		gob->ob->restrictflag  = group->restrictflag; 	
+ 	}
+}
+/* --- */
 
 static int outliner_toggle_expanded_exec(bContext *C, wmOperator *op)
 {
@@ -3215,6 +3247,31 @@
 	}
 }
 
+static void outliner_do_group_operation(bContext *C, Scene *scene, SpaceOops *soops, ListBase *lb, 
+ 										 void (*operation_cb)(bContext *C, Scene *scene, TreeElement *, TreeStoreElem *, TreeStoreElem *))
+ {
+ 	TreeElement *te;
+ 	TreeStoreElem *tselem;
+ 	
+ 	for(te=lb->first; te; te= te->next) {
+ 		tselem= TREESTORE(te);
+ 		if(tselem->flag & TSE_SELECTED) {
+ 			if(tselem->type==0 && te->idcode==ID_GR) {
+ 				/* when objects selected in other scenes... dunno if that should be allowed */
+ 				Scene *sce= (Scene *)outliner_search_back(soops, te, ID_SCE);
+ 				if(sce && scene != sce) {
+ 					ED_screen_set_scene(C, sce);
+ 				}
+ 				
+ 				operation_cb(C, scene, te, NULL, tselem);
+ 			}
+ 		}
+		if((tselem->flag & TSE_CLOSED)==0) {
+ 			outliner_do_group_operation(C, scene, soops, &te->subtree, operation_cb);
+		}
+	}
+}
+
 void outliner_del(bContext *C, Scene *scene, ARegion *ar, SpaceOops *soops)
 {
 	
@@ -3318,6 +3375,9 @@
 	{1, "UNLINK", 0, "Unlink", ""},
 	{2, "LOCAL", 0, "Make Local", ""},
 	{3, "LINK", 0, "Link Group Objects to Scene", ""},
+	{4, "TOGVIS", 0, "Toggle Visible", ""},
+ 	{5, "TOGSEL", 0, "Toggle Selectable", ""},
+ 	{6, "TOGREN", 0, "Toggle Renderable", ""},
 	{0, NULL, 0, NULL, NULL}
 };
 
@@ -3345,8 +3405,18 @@
 		outliner_do_libdata_operation(C, scene, soops, &soops->tree, group_linkobs2scene_cb);
 		ED_undo_push(C, "Link Group Objects to Scene");
 	}
-	
-	
+	else if(event==4) {
+ 	        outliner_do_libdata_operation(C, scene, soops, &soops->tree, group_toggle_visibility_cb);
+ 		ED_undo_push(C, "Toggle group visibility");
+ 	}
+ 	else if(event==5) {
+ 	        outliner_do_libdata_operation(C, scene, soops, &soops->tree, group_toggle_selectability_cb);
+ 		ED_undo_push(C, "Toggle group selectability");
+ 	}
+ 	else if(event==6) {
+ 	        outliner_do_libdata_operation(C, scene, soops, &soops->tree, group_toggle_renderability_cb);
+ 		ED_undo_push(C, "Toggle group renderrability");
+ 	}
 	WM_event_add_notifier(C, NC_GROUP, NULL);
 	
 	return OPERATOR_FINISHED;
@@ -4776,6 +4846,19 @@
 	WM_event_add_notifier(C, NC_OBJECT|ND_POSE, NULL);
 }
 
+static void restrictbutton_gr(bContext *C, void *poin, void *poin2)
+{	
+	Scene *scene = (Scene *)poin;		
+	GroupObject *gob;
+	Group *gr = (Group *)poin2; 	
+			
+	for(gob= gr->gobject.first; gob; gob= gob->next) {			
+		gob->ob->flag &= ~SELECT;
+		gob->ob->restrictflag  = gr->restrictflag; 	
+	}	
+	WM_event_add_notifier(C, NC_GROUP, NULL);
+}
+
 static void namebutton_cb(bContext *C, void *tsep, char *oldname)
 {
 	SpaceOops *soops= CTX_wm_space_outliner(C);
@@ -4893,6 +4976,7 @@
 	TreeElement *te;
 	TreeStoreElem *tselem;
 	Object *ob = NULL;
+	Group  *gr = NULL;
 
 	for(te= lb->first; te; te= te->next) {
 		tselem= TREESTORE(te);
@@ -4916,6 +5000,24 @@
 				
 				uiBlockSetEmboss(block, UI_EMBOSS);
 			}
+			if(tselem->type==0 && te->idcode==ID_GR){ 
+ 			        gr = (Group *)tselem->id;
+ 				
+ 				uiBlockSetEmboss(block, UI_EMBOSSN);
+ 				bt= uiDefIconButBitS(block, ICONTOG, GR_RESTRICT_VIEW, 0, ICON_RESTRICT_VIEW_OFF, 
+ 						(int)ar->v2d.cur.xmax-OL_TOG_RESTRICT_VIEWX, (short)te->ys, 17, OL_H-1, &(gr->restrictflag), 0, 0, 0, 0, "Restrict/Allow visibility in the 3D View");
+ 				uiButSetFunc(bt, restrictbutton_gr, scene, gr);
+ 				
+ 				bt= uiDefIconButBitS(block, ICONTOG, GR_RESTRICT_SELECT, 0, ICON_RESTRICT_SELECT_OFF, 
+ 						(int)ar->v2d.cur.xmax-OL_TOG_RESTRICT_SELECTX, (short)te->ys, 17, OL_H-1, &(gr->restrictflag), 0, 0, 0, 0, "Restrict/Allow selection in the 3D View");
+ 				uiButSetFunc(bt, restrictbutton_gr, scene, gr);
+ 				
+ 				bt= uiDefIconButBitS(block, ICONTOG, GR_RESTRICT_RENDER, 0, ICON_RESTRICT_RENDER_OFF, 
+ 						(int)ar->v2d.cur.xmax-OL_TOG_RESTRICT_RENDERX, (short)te->ys, 17, OL_H-1, &(gr->restrictflag), 0, 0, 0, 0, "Restrict/Allow renderability");
+ 				uiButSetFunc(bt, restrictbutton_gr, scene, gr);
+ 				
+ 				uiBlockSetEmboss(block, UI_EMBOSS); 
+ 			}
 			/* scene render layers and passes have toggle-able flags too! */
 			else if(tselem->type==TSE_R_LAYER) {
 				uiBlockSetEmboss(block, UI_EMBOSSN);

Modified: branches/branch-farsthary/source/blender/makesdna/DNA_group_types.h
===================================================================
--- branches/branch-farsthary/source/blender/makesdna/DNA_group_types.h	2010-04-28 14:36:36 UTC (rev 28491)
+++ branches/branch-farsthary/source/blender/makesdna/DNA_group_types.h	2010-04-28 15:09:43 UTC (rev 28492)
@@ -55,8 +55,13 @@
 	 * on the last used scene */
 	unsigned int layer;
 	float dupli_ofs[3];
+	int restrictflag, pad;
 } Group;
 
+#define GR_RESTRICT_VIEW    1
+#define GR_RESTRICT_SELECT  2
+#define GR_RESTRICT_RENDER  4
 
 #endif
 
+

Modified: branches/branch-farsthary/source/blender/makesrna/intern/rna_group.c
===================================================================
--- branches/branch-farsthary/source/blender/makesrna/intern/rna_group.c	2010-04-28 14:36:36 UTC (rev 28491)
+++ branches/branch-farsthary/source/blender/makesrna/intern/rna_group.c	2010-04-28 15:09:43 UTC (rev 28492)
@@ -30,6 +30,8 @@
 
 #include "DNA_group_types.h"
 
+#include "WM_types.h"
+
 #ifdef RNA_RUNTIME
 
 #include "DNA_scene_types.h"
@@ -38,8 +40,8 @@
 #include "BKE_group.h"
 
 #include "WM_api.h"
-#include "WM_types.h"
 
+
 static PointerRNA rna_Group_objects_get(CollectionPropertyIterator *iter)
 {
 	ListBaseIterator *internal= iter->internal;
@@ -120,9 +122,24 @@
 	RNA_def_property_boolean_sdna(prop, NULL, "layer", 1);
 	RNA_def_property_array(prop, 20);
 	RNA_def_property_ui_text(prop, "Dupli Layers", "Layers visible when this groups is instanced as a dupli");
+	
+        /* restrict */
+ 	prop= RNA_def_property(srna, "restrict_view", PROP_BOOLEAN, PROP_NONE);
+ 	RNA_def_property_boolean_sdna(prop, NULL, "restrictflag", GR_RESTRICT_VIEW);
+ 	RNA_def_property_ui_text(prop, "Restrict View", "Restrict visibility in the viewport.");
+ 	RNA_def_property_update(prop, NC_GROUP, NULL);
+ 
+ 	prop= RNA_def_property(srna, "restrict_select", PROP_BOOLEAN, PROP_NONE);
+ 	RNA_def_property_boolean_sdna(prop, NULL, "restrictflag", GR_RESTRICT_SELECT);
+ 	RNA_def_property_ui_text(prop, "Restrict Select", "Restrict selection.");
+ 	RNA_def_property_update(prop, NC_GROUP, NULL);
+ 
+ 	prop= RNA_def_property(srna, "restrict_render", PROP_BOOLEAN, PROP_NONE);
+ 	RNA_def_property_boolean_sdna(prop, NULL, "restrictflag", GR_RESTRICT_RENDER);
+ 	RNA_def_property_ui_text(prop, "Restrict Render", "Restrict renderability.");
+ 	RNA_def_property_update(prop, NC_GROUP, NULL);
 
-
-	prop= RNA_def_property(srna, "objects", PROP_COLLECTION, PROP_NONE);
+	prop= RNA_def_property(srna, "objects", PROP_COLLECTION, PROP_NONE);   
 	RNA_def_property_collection_sdna(prop, NULL, "gobject", NULL);
 	RNA_def_property_struct_type(prop, "Object");
 	RNA_def_property_ui_text(prop, "Objects", "A collection of this groups objects");
@@ -134,3 +151,4 @@
 
 #endif
 
+





More information about the Bf-blender-cvs mailing list