Drag-to-toggle visible/selectable/renderable in the Group view. #39862

Open
opened 2014-04-23 18:06:06 +02:00 by Paweł Łyczkowski · 11 comments

System Information
Windows 64

Blender Version
Broken: 2.70a

Short description of error
The drag-to-toggle visible/selectable/renderable in the Outliner does not work in the Groups view.

**System Information** Windows 64 **Blender Version** Broken: 2.70a **Short description of error** The drag-to-toggle visible/selectable/renderable in the Outliner does not work in the Groups view.

Changed status to: 'Open'

Changed status to: 'Open'

Added subscriber: @PawelLyczkowski-1

Added subscriber: @PawelLyczkowski-1

#42176 was marked as duplicate of this issue

#42176 was marked as duplicate of this issue

Added subscriber: @mont29

Added subscriber: @mont29
Bastien Montagne self-assigned this 2014-04-23 18:11:42 +02:00

Added subscriber: @ideasman42

Added subscriber: @ideasman42

Groups view is a bit of a hack (or a convenient feature... call it how you like).

The groups view icons are not toggle buttons (internally), they activate a function which controls object buttons.

This could be made to work, but if doing some involves very ugly hacks, I rather not for now.


I think this is more of a TODO.

Groups view is a bit of a hack (or a convenient feature... call it how you like). The groups view icons are _not_ toggle buttons (internally), they activate a function which controls object buttons. This could be made to work, but if doing some involves very ugly hacks, I rather not for now. ---- I think this is more of a TODO.

@ideasman42: yep, that’s what I realized looking at the code… Now, my idea was to add hide properties to group RNA (could be useful elsewhere), with accessors doing mostly the same thing as what’s done in outliner currently. Then we could use RNA buttons in outliner, which would fix that glitch. What do you think?

@ideasman42: yep, that’s what I realized looking at the code… Now, my idea was to add `hide` properties to group RNA (could be useful elsewhere), with accessors doing mostly the same thing as what’s done in outliner currently. Then we could use RNA buttons in outliner, which would fix that glitch. What do you think?

@mont29, rather not, hide if added to groups, would be a function, not a property.

@mont29, rather not, hide if added to groups, would be a function, not a property.

Ack, saw that last comment too late… So probably wasted my time, but in case, here is the patch:

P49: #39862

diff --git a/source/blender/blenkernel/BKE_group.h b/source/blender/blenkernel/BKE_group.h
index f528fe8..997a47d 100644
--- a/source/blender/blenkernel/BKE_group.h
+++ b/source/blender/blenkernel/BKE_group.h
@@ -55,4 +55,7 @@ bool          BKE_group_is_animated(struct Group *group, struct Object *parent);
 void          BKE_group_tag_recalc(struct Group *group);
 void          BKE_group_handle_recalc_and_update(struct EvaluationContext *eval_ctx, struct Scene *scene, struct Object *parent, struct Group *group);
 
+bool BKE_group_restrict_flag_get(struct Group *gr, const int flag);
+void BKE_group_restrict_flag_set(struct Group *gr, const int flag, const bool val);
+
 #endif  /* __BKE_GROUP_H__ */
diff --git a/source/blender/blenkernel/intern/group.c b/source/blender/blenkernel/intern/group.c
index e84db7e..706af4e9 100644
--- a/source/blender/blenkernel/intern/group.c
+++ b/source/blender/blenkernel/intern/group.c
@@ -381,3 +381,44 @@ void BKE_group_handle_recalc_and_update(EvaluationContext *eval_ctx, Scene *scen
 		}
 	}
 }
+
+bool BKE_group_restrict_flag_get(Group *gr, const int flag)
+{
+	GroupObject *gob;
+
+#if 1
+	for (gob = gr->gobject.first; gob; gob = gob->next) {
+		if ((gob->ob->restrictflag & flag) == 0)
+			return false;
+	}
+	return true;
+#else
+	/* weak but fast */
+	if ((gob = gr->gobject.first))
+		if ((gob->ob->restrictflag & flag) == 0)
+			return false;
+	return true;
+#endif
+}
+
+void BKE_group_restrict_flag_set(Group *gr, const int flag, const bool val)
+{
+	GroupObject *gob;
+
+	if (val) {
+		for (gob = gr->gobject.first; gob; gob = gob->next) {
+			if (gob->ob->id.lib)
+				continue;
+
+			gob->ob->restrictflag |= flag;
+		}
+	}
+	else {
+		for (gob = gr->gobject.first; gob; gob = gob->next) {
+			if (gob->ob->id.lib)
+				continue;
+
+			gob->ob->restrictflag &= ~flag;
+		}
+	}
+}
diff --git a/source/blender/editors/space_outliner/outliner_draw.c b/source/blender/editors/space_outliner/outliner_draw.c
index 4db63a4..2399f21 100644
--- a/source/blender/editors/space_outliner/outliner_draw.c
+++ b/source/blender/editors/space_outliner/outliner_draw.c
@@ -188,19 +188,12 @@ static void restrictbutton_recursive_child(bContext *C, Scene *scene, Object *ob
 	}
 }
 
-static void restrictbutton_view_cb(bContext *C, void *poin, void *poin2)
+static void restrictbutton_ob_view_cb(bContext *C, void *poin, void *poin2)
 {
 	Scene *scene = (Scene *)poin;
 	Object *ob = (Object *)poin2;
-	
-	if (!common_restrict_check(C, ob)) return;
-	
-	/* deselect objects that are invisible */
-	if (ob->restrictflag & OB_RESTRICT_VIEW) {
-		/* Ouch! There is no backwards pointer from Object to Base, 
-		 * so have to do loop to find it. */
-		ED_base_object_select(BKE_scene_base_find(scene, ob), BA_DESELECT);
-	}
+
+	if (!common_restrict_check(scene, ob, NULL)) return;
 
 	if (CTX_wm_window(C)->eventstate->ctrl) {
 		restrictbutton_recursive_child(C, scene, ob, OB_RESTRICT_VIEW,
@@ -208,22 +201,14 @@ static void restrictbutton_view_cb(bContext *C, void *poin, void *poin2)
 	}
 
 	WM_event_add_notifier(C, NC_SCENE | ND_OB_SELECT, scene);
-
 }
 
-static void restrictbutton_sel_cb(bContext *C, void *poin, void *poin2)
+static void restrictbutton_ob_sel_cb(bContext *C, void *poin, void *poin2)
 {
 	Scene *scene = (Scene *)poin;
 	Object *ob = (Object *)poin2;
-	
-	if (!common_restrict_check(C, ob)) return;
-	
-	/* if select restriction has just been turned on */
-	if (ob->restrictflag & OB_RESTRICT_SELECT) {
-		/* Ouch! There is no backwards pointer from Object to Base, 
-		 * so have to do loop to find it. */
-		ED_base_object_select(BKE_scene_base_find(scene, ob), BA_DESELECT);
-	}
+
+	if (!common_restrict_check(scene, ob, NULL)) return;
 
 	if (CTX_wm_window(C)->eventstate->ctrl) {
 		restrictbutton_recursive_child(C, scene, ob, OB_RESTRICT_SELECT,
@@ -231,19 +216,19 @@ static void restrictbutton_sel_cb(bContext *C, void *poin, void *poin2)
 	}
 
 	WM_event_add_notifier(C, NC_SCENE | ND_OB_SELECT, scene);
-
 }
 
-static void restrictbutton_rend_cb(bContext *C, void *poin, void *poin2)
+static void restrictbutton_ob_rend_cb(bContext *C, void *poin, void *poin2)
 {
+	Scene *scene = (Scene *)poin;
 	Object *ob = (Object *)poin2;
 
 	if (CTX_wm_window(C)->eventstate->ctrl) {
-		restrictbutton_recursive_child(C, (Scene *)poin, ob, OB_RESTRICT_RENDER,
+		restrictbutton_recursive_child(C, scene, ob, OB_RESTRICT_RENDER,
 		                               (ob->restrictflag & OB_RESTRICT_RENDER) != 0, false);
 	}
 
-	WM_event_add_notifier(C, NC_SCENE | ND_OB_RENDER, poin);
+	WM_event_add_notifier(C, NC_SCENE | ND_OB_RENDER, scene);
 }
 
 static void restrictbutton_r_lay_cb(bContext *C, void *poin, void *UNUSED(poin2))
@@ -317,25 +302,6 @@ static void restrictbutton_ebone_visibility_cb(bContext *C, void *UNUSED(poin),
 	WM_event_add_notifier(C, NC_OBJECT | ND_POSE, NULL);
 }
 
-static int group_restrict_flag(Group *gr, int flag)
-{
-	GroupObject *gob;
-
-#ifdef USE_GROUP_SELECT
-	for (gob = gr->gobject.first; gob; gob = gob->next) {
-		if ((gob->ob->restrictflag & flag) == 0)
-			return 0;
-	}
-	return 1;
-#else
-	/* weak but fast */
-	if ((gob = gr->gobject.first))
-		if ((gob->ob->restrictflag & flag) == 0)
-			return 0;
-	return 1;
-#endif
-}
-
 static int group_select_flag(Group *gr)
 {
 	GroupObject *gob;
@@ -355,56 +321,45 @@ static int group_select_flag(Group *gr)
 #endif
 }
 
-void restrictbutton_gr_restrict_flag(void *poin, void *poin2, int flag)
+static void restrictbutton_gr_view_cb(bContext *C, void *poin, void *poin2)
 {
 	Scene *scene = (Scene *)poin;
-	GroupObject *gob;
 	Group *gr = (Group *)poin2;
+	GroupObject *gob;
 
-	if (group_restrict_flag(gr, flag)) {
-		for (gob = gr->gobject.first; gob; gob = gob->next) {
-			if (gob->ob->id.lib)
-				continue;
-
-			gob->ob->restrictflag &= ~flag;
-			
-			if (flag == OB_RESTRICT_VIEW)
-				if (gob->ob->flag & SELECT)
-					ED_base_object_select(BKE_scene_base_find(scene, gob->ob), BA_DESELECT);
-		}
-	}
-	else {
-		for (gob = gr->gobject.first; gob; gob = gob->next) {
-			if (gob->ob->id.lib)
-				continue;
-
-			/* not in editmode */
-			if (scene->obedit != gob->ob) {
-				gob->ob->restrictflag |= flag;
+	for (gob = gr->gobject.first; gob; gob = gob->next) {
+		if (gob->ob->id.lib)
+			continue;
 
-				if (ELEM(flag, OB_RESTRICT_SELECT, OB_RESTRICT_VIEW)) {
-					if ((gob->ob->flag & SELECT)) {
-						ED_base_object_select(BKE_scene_base_find(scene, gob->ob), BA_DESELECT);
-					}
-				}
-			}
-		}
+		common_restrict_check(scene, gob->ob, NULL);
 	}
-} 
 
-static void restrictbutton_gr_restrict_view(bContext *C, void *poin, void *poin2)
-{
-	restrictbutton_gr_restrict_flag(poin, poin2, OB_RESTRICT_VIEW);
+	WM_event_add_notifier(C, NC_SCENE | ND_OB_SELECT, scene);
 	WM_event_add_notifier(C, NC_GROUP, NULL);
 }
-static void restrictbutton_gr_restrict_select(bContext *C, void *poin, void *poin2)
+
+static void restrictbutton_gr_sel_cb(bContext *C, void *poin, void *poin2)
 {
-	restrictbutton_gr_restrict_flag(poin, poin2, OB_RESTRICT_SELECT);
+	Scene *scene = (Scene *)poin;
+	Group *gr = (Group *)poin2;
+	GroupObject *gob;
+
+	for (gob = gr->gobject.first; gob; gob = gob->next) {
+		if (gob->ob->id.lib)
+			continue;
+
+		common_restrict_check(scene, gob->ob, NULL);
+	}
+
+	WM_event_add_notifier(C, NC_SCENE | ND_OB_SELECT, scene);
 	WM_event_add_notifier(C, NC_GROUP, NULL);
 }
-static void restrictbutton_gr_restrict_render(bContext *C, void *poin, void *poin2)
+
+static void restrictbutton_gr_rend_cb(bContext *C, void *poin, void *UNUSED(poin2))
 {
-	restrictbutton_gr_restrict_flag(poin, poin2, OB_RESTRICT_RENDER);
+	Scene *scene = (Scene *)poin;
+
+	WM_event_add_notifier(C, NC_SCENE | ND_OB_SELECT, scene);
 	WM_event_add_notifier(C, NC_GROUP, NULL);
 }
 
@@ -537,6 +492,7 @@ static void outliner_draw_restrictbuts(uiBlock *block, Scene *scene, ARegion *ar
 	Group  *gr = NULL;
 
 	PropertyRNA *object_prop_hide, *object_prop_hide_select, *object_prop_hide_render;
+	PropertyRNA *grp_prop_hide, *grp_prop_hide_select, *grp_prop_hide_render;
 
 	/* get RNA properties (once) */
 	object_prop_hide = RNA_struct_type_find_property(&RNA_Object, "hide");
@@ -544,6 +500,10 @@ static void outliner_draw_restrictbuts(uiBlock *block, Scene *scene, ARegion *ar
 	object_prop_hide_render = RNA_struct_type_find_property(&RNA_Object, "hide_render");
 	BLI_assert(object_prop_hide && object_prop_hide_select  && object_prop_hide_render);
 
+	grp_prop_hide = RNA_struct_type_find_property(&RNA_Group, "hide");
+	grp_prop_hide_select = RNA_struct_type_find_property(&RNA_Group, "hide_select");
+	grp_prop_hide_render = RNA_struct_type_find_property(&RNA_Group, "hide_render");
+	BLI_assert(grp_prop_hide && grp_prop_hide_select && grp_prop_hide_render);
 
 	for (te = lb->first; te; te = te->next) {
 		tselem = TREESTORE(te);
@@ -560,56 +520,53 @@ static void outliner_draw_restrictbuts(uiBlock *block, Scene *scene, ARegion *ar
 				                        (int)(ar->v2d.cur.xmax - OL_TOG_RESTRICT_VIEWX), te->ys, UI_UNIT_X, UI_UNIT_Y,
 				                        &ptr, object_prop_hide, -1, 0, 0, -1, -1,
 				                        TIP_("Restrict viewport visibility (Ctrl - Recursive)"));
-				uiButSetFunc(bt, restrictbutton_view_cb, scene, ob);
+				uiButSetFunc(bt, restrictbutton_ob_view_cb, scene, ob);
 				uiButSetFlag(bt, UI_BUT_DRAG_LOCK);
 				
 				bt = uiDefIconButR_prop(block, ICONTOG, 0, ICON_RESTRICT_SELECT_OFF,
 				                        (int)(ar->v2d.cur.xmax - OL_TOG_RESTRICT_SELECTX), te->ys, UI_UNIT_X, UI_UNIT_Y,
 				                        &ptr, object_prop_hide_select, -1, 0, 0, -1, -1,
 				                        TIP_("Restrict viewport selection (Ctrl - Recursive)"));
-				uiButSetFunc(bt, restrictbutton_sel_cb, scene, ob);
+				uiButSetFunc(bt, restrictbutton_ob_sel_cb, scene, ob);
 				uiButSetFlag(bt, UI_BUT_DRAG_LOCK);
 				
 				bt = uiDefIconButR_prop(block, ICONTOG, 0, ICON_RESTRICT_RENDER_OFF,
 				                        (int)(ar->v2d.cur.xmax - OL_TOG_RESTRICT_RENDERX), te->ys, UI_UNIT_X, UI_UNIT_Y,
 				                        &ptr, object_prop_hide_render, -1, 0, 0, -1, -1,
 				                        TIP_("Restrict rendering (Ctrl - Recursive)"));
-				uiButSetFunc(bt, restrictbutton_rend_cb, scene, ob);
+				uiButSetFunc(bt, restrictbutton_ob_rend_cb, scene, ob);
 				uiButSetFlag(bt, UI_BUT_DRAG_LOCK);
 				
 				uiBlockSetEmboss(block, UI_EMBOSS);
 				
 			}
 			if (tselem->type == 0 && te->idcode == ID_GR) {
-				int restrict_bool;
-				int but_flag = UI_BUT_DRAG_LOCK;
+				PointerRNA ptr;
+
 				gr = (Group *)tselem->id;
+				RNA_pointer_create((ID *)gr, &RNA_Group, gr, &ptr);
 
-				if (gr->id.lib)
-					but_flag |= UI_BUT_DISABLED;
-				
 				uiBlockSetEmboss(block, UI_EMBOSSN);
+				bt = uiDefIconButR_prop(block, ICONTOG, 0, ICON_RESTRICT_VIEW_OFF,
+				                        (int)(ar->v2d.cur.xmax - OL_TOG_RESTRICT_VIEWX), te->ys, UI_UNIT_X, UI_UNIT_Y,
+				                        &ptr, grp_prop_hide, -1, 0, 0, -1, -1,
+				                        TIP_("Restrict viewport visibility"));
+				uiButSetFunc(bt, restrictbutton_gr_view_cb, scene, gr);
+				uiButSetFlag(bt, UI_BUT_DRAG_LOCK);
+
+				bt = uiDefIconButR_prop(block, ICONTOG, 0, ICON_RESTRICT_SELECT_OFF,
+				                        (int)(ar->v2d.cur.xmax - OL_TOG_RESTRICT_SELECTX), te->ys, UI_UNIT_X, UI_UNIT_Y,
+				                        &ptr, grp_prop_hide_select, -1, 0, 0, -1, -1,
+				                        TIP_("Restrict viewport selection"));
+				uiButSetFunc(bt, restrictbutton_gr_sel_cb, scene, gr);
+				uiButSetFlag(bt, UI_BUT_DRAG_LOCK);
 
-				restrict_bool = group_restrict_flag(gr, OB_RESTRICT_VIEW);
-				bt = uiDefIconBut(block, ICONTOG, 0, restrict_bool ? ICON_RESTRICT_VIEW_ON : ICON_RESTRICT_VIEW_OFF,
-				                  (int)(ar->v2d.cur.xmax - OL_TOG_RESTRICT_VIEWX), te->ys, UI_UNIT_X, UI_UNIT_Y,
-				                  NULL, 0, 0, 0, 0, TIP_("Restrict/Allow visibility in the 3D View"));
-				uiButSetFunc(bt, restrictbutton_gr_restrict_view, scene, gr);
-				uiButSetFlag(bt, but_flag);
-
-				restrict_bool = group_restrict_flag(gr, OB_RESTRICT_SELECT);
-				bt = uiDefIconBut(block, ICONTOG, 0, restrict_bool ? ICON_RESTRICT_SELECT_ON : ICON_RESTRICT_SELECT_OFF,
-				                  (int)(ar->v2d.cur.xmax - OL_TOG_RESTRICT_SELECTX), te->ys, UI_UNIT_X, UI_UNIT_Y,
-				                  NULL, 0, 0, 0, 0, TIP_("Restrict/Allow selection in the 3D View"));
-				uiButSetFunc(bt, restrictbutton_gr_restrict_select, scene, gr);
-				uiButSetFlag(bt, but_flag);
-
-				restrict_bool = group_restrict_flag(gr, OB_RESTRICT_RENDER);
-				bt = uiDefIconBut(block, ICONTOG, 0, restrict_bool ? ICON_RESTRICT_RENDER_ON : ICON_RESTRICT_RENDER_OFF,
-				                  (int)(ar->v2d.cur.xmax - OL_TOG_RESTRICT_RENDERX), te->ys, UI_UNIT_X, UI_UNIT_Y,
-				                  NULL, 0, 0, 0, 0, TIP_("Restrict/Allow renderability"));
-				uiButSetFunc(bt, restrictbutton_gr_restrict_render, scene, gr);
-				uiButSetFlag(bt, but_flag);
+				bt = uiDefIconButR_prop(block, ICONTOG, 0, ICON_RESTRICT_RENDER_OFF,
+				                        (int)(ar->v2d.cur.xmax - OL_TOG_RESTRICT_RENDERX), te->ys, UI_UNIT_X, UI_UNIT_Y,
+				                        &ptr, grp_prop_hide_render, -1, 0, 0, -1, -1,
+				                        TIP_("Restrict rendering"));
+				uiButSetFunc(bt, restrictbutton_gr_rend_cb, scene, gr);
+				uiButSetFlag(bt, UI_BUT_DRAG_LOCK);
 
 				uiBlockSetEmboss(block, UI_EMBOSS);
 			}
diff --git a/source/blender/editors/space_outliner/outliner_edit.c b/source/blender/editors/space_outliner/outliner_edit.c
index 17e1e03..39e932c 100644
--- a/source/blender/editors/space_outliner/outliner_edit.c
+++ b/source/blender/editors/space_outliner/outliner_edit.c
@@ -45,6 +45,7 @@
 #include "BKE_animsys.h"
 #include "BKE_context.h"
 #include "BKE_depsgraph.h"
+#include "BKE_group.h"
 #include "BKE_library.h"
 #include "BKE_main.h"
 #include "BKE_report.h"
@@ -354,12 +355,12 @@ void outliner_set_flag(SpaceOops *soops, ListBase *lb, short flag, short set)
 /* same check needed for both object operation and restrict column button func
  * return 0 when in edit mode (cannot restrict view or select)
  * otherwise return 1 */
-int common_restrict_check(bContext *C, Object *ob)
+bool common_restrict_check(Scene *scene, Object *ob, Base *base)
 {
 	/* Don't allow hide an object in edit mode,
 	 * check the bug #22153 and #21609, #23977
 	 */
-	Object *obedit = CTX_data_edit_object(C);
+	Object *obedit = scene->obedit;
 	if (obedit && obedit == ob) {
 		/* found object is hidden, reset */
 		if (ob->restrictflag & OB_RESTRICT_VIEW)
@@ -370,35 +371,61 @@ int common_restrict_check(bContext *C, Object *ob)
 		return 0;
 	}
 	
+	if (ob->restrictflag & (OB_RESTRICT_VIEW | OB_RESTRICT_SELECT)) {
+		if (!base) {
+			/* Ouch! There is no backwards pointer from Object to Base, so have to do loop to find it. */
+			base = BKE_scene_base_find(scene, ob);
+		}
+		ED_base_object_select(base, BA_DESELECT);
+	}
+	
 	return 1;
 }
 
 /* =============================================== */
 /* Restriction toggles */
 
+static void group_toggle_restrict_flag(Scene *scene, Group *gr, const int flag)
+{
+	GroupObject *gob;
+	const bool set = !BKE_group_restrict_flag_get(gr, flag);
+
+	for (gob = gr->gobject.first; gob; gob = gob->next) {
+		if (gob->ob->id.lib)
+			continue;
+
+		if (set) {
+			gob->ob->restrictflag |= flag;
+		}
+		else {
+			gob->ob->restrictflag &= ~flag;
+		}
+
+		if (flag & (OB_RESTRICT_VIEW | OB_RESTRICT_SELECT)) {
+			common_restrict_check(scene, gob->ob, NULL);
+		}
+	}
+}
+
 /* Toggle Visibility ---------------------------------------- */
 
-void object_toggle_visibility_cb(bContext *C, Scene *scene, TreeElement *te,
+void object_toggle_visibility_cb(bContext *UNUSED(C), Scene *scene, TreeElement *te,
                                  TreeStoreElem *UNUSED(tsep), TreeStoreElem *tselem)
 {
 	Base *base = (Base *)te->directdata;
 	Object *ob = (Object *)tselem->id;
-	
-	/* add check for edit mode */
-	if (!common_restrict_check(C, ob)) return;
-	
-	if (base || (base = BKE_scene_base_find(scene, ob))) {
-		if ((base->object->restrictflag ^= OB_RESTRICT_VIEW)) {
-			ED_base_object_select(base, BA_DESELECT);
-		}
-	}
+
+	ob->restrictflag ^= OB_RESTRICT_VIEW;
+
+	/* add check for edit mode, and deselect if hidden/unselectable */
+	if (!common_restrict_check(scene, ob, base)) return;
 }
 
 void group_toggle_visibility_cb(bContext *UNUSED(C), Scene *scene, TreeElement *UNUSED(te),
                                 TreeStoreElem *UNUSED(tsep), TreeStoreElem *tselem)
 {
 	Group *group = (Group *)tselem->id;
-	restrictbutton_gr_restrict_flag(scene, group, OB_RESTRICT_VIEW);
+	group_toggle_restrict_flag(scene, group, OB_RESTRICT_VIEW);
 }
 
 static int outliner_toggle_visibility_exec(bContext *C, wmOperator *UNUSED(op))
@@ -437,18 +464,19 @@ void object_toggle_selectability_cb(bContext *UNUSED(C), Scene *scene, TreeEleme
                                     TreeStoreElem *UNUSED(tsep), TreeStoreElem *tselem)
 {
 	Base *base = (Base *)te->directdata;
-	
-	if (base == NULL) base = BKE_scene_base_find(scene, (Object *)tselem->id);
-	if (base) {
-		base->object->restrictflag ^= OB_RESTRICT_SELECT;
-	}
+	Object *ob = (Object *)tselem->id;
+
+	ob->restrictflag ^= OB_RESTRICT_SELECT;
+
+	/* add check for edit mode, and deselect if hidden/unselectable */
+	if (!common_restrict_check(scene, ob, base)) return;
 }
 
 void group_toggle_selectability_cb(bContext *UNUSED(C), Scene *scene, TreeElement *UNUSED(te),
                                    TreeStoreElem *UNUSED(tsep), TreeStoreElem *tselem)
 {
 	Group *group = (Group *)tselem->id;
-	restrictbutton_gr_restrict_flag(scene, group, OB_RESTRICT_SELECT);
+	group_toggle_restrict_flag(scene, group, OB_RESTRICT_SELECT);
 }
 
 static int outliner_toggle_selectability_exec(bContext *C, wmOperator *UNUSED(op))
@@ -481,22 +509,19 @@ void OUTLINER_OT_selectability_toggle(wmOperatorType *ot)
 
 /* Toggle Renderability ---------------------------------------- */
 
-void object_toggle_renderability_cb(bContext *UNUSED(C), Scene *scene, TreeElement *te,
+void object_toggle_renderability_cb(bContext *UNUSED(C), Scene *UNUSED(scene), TreeElement *UNUSED(te),
                                     TreeStoreElem *UNUSED(tsep), TreeStoreElem *tselem)
 {
-	Base *base = (Base *)te->directdata;
-	
-	if (base == NULL) base = BKE_scene_base_find(scene, (Object *)tselem->id);
-	if (base) {
-		base->object->restrictflag ^= OB_RESTRICT_RENDER;
-	}
+	Object *ob = (Object *)tselem->id;
+
+	ob->restrictflag ^= OB_RESTRICT_RENDER;
 }
 
 void group_toggle_renderability_cb(bContext *UNUSED(C), Scene *scene, TreeElement *UNUSED(te),
                                    TreeStoreElem *UNUSED(tsep), TreeStoreElem *tselem)
 {
 	Group *group = (Group *)tselem->id;
-	restrictbutton_gr_restrict_flag(scene, group, OB_RESTRICT_RENDER);
+	group_toggle_restrict_flag(scene, group, OB_RESTRICT_RENDER);
 }
 
 static int outliner_toggle_renderability_exec(bContext *C, wmOperator *UNUSED(op))
diff --git a/source/blender/editors/space_outliner/outliner_intern.h b/source/blender/editors/space_outliner/outliner_intern.h
index 317d33d..18d8940 100644
--- a/source/blender/editors/space_outliner/outliner_intern.h
+++ b/source/blender/editors/space_outliner/outliner_intern.h
@@ -174,7 +174,6 @@ void outliner_build_tree(struct Main *mainvar, struct Scene *scene, struct Space
 /* outliner_draw.c ---------------------------------------------- */
 
 void draw_outliner(const struct bContext *C);
-void restrictbutton_gr_restrict_flag(void *poin, void *poin2, int flag);
 
 /* outliner_select.c -------------------------------------------- */
 eOLDrawState tree_element_type_active(
@@ -189,7 +188,7 @@ int outliner_item_do_activate(struct bContext *C, int x, int y, bool extend, boo
 void outliner_do_object_operation(struct bContext *C, struct Scene *scene, struct SpaceOops *soops, struct ListBase *lb, 
                                   void (*operation_cb)(struct bContext *C, struct Scene *scene, struct TreeElement *, struct TreeStoreElem *, TreeStoreElem *));
 
-int common_restrict_check(struct bContext *C, struct Object *ob);
+bool common_restrict_check(struct Scene *scene, struct Object *ob, struct Base *base);
 
 int outliner_has_one_flag(struct SpaceOops *soops, ListBase *lb, short flag, const int curlevel);
 void outliner_set_flag(struct SpaceOops *soops, ListBase *lb, short flag, short set);
diff --git a/source/blender/makesrna/intern/rna_group.c b/source/blender/makesrna/intern/rna_group.c
index 2f9c12c..001ea88 100644
--- a/source/blender/makesrna/intern/rna_group.c
+++ b/source/blender/makesrna/intern/rna_group.c
@@ -42,6 +42,7 @@
 #include "DNA_object_types.h"
 
 #include "BKE_group.h"
+#include "BKE_depsgraph.h"
 
 #include "WM_api.h"
 
@@ -73,6 +74,47 @@ static void rna_Group_objects_unlink(Group *group, bContext *C, ReportList *repo
 	WM_main_add_notifier(NC_OBJECT | ND_DRAW, &object->id);
 }
 
+static void rna_Group_hide_update(Main *bmain, Scene *UNUSED(scene), PointerRNA *UNUSED(ptr))
+{
+	DAG_id_type_tag(bmain, ID_OB);
+}
+
+static int rna_Group_hide_get(PointerRNA *ptr)
+{
+	Group *gr = (Group *)ptr->data;
+	return BKE_group_restrict_flag_get(gr, OB_RESTRICT_VIEW);
+}
+
+static void rna_Group_hide_set(PointerRNA *ptr, const int value)
+{
+	Group *gr = (Group *)ptr->data;
+	BKE_group_restrict_flag_set(gr, OB_RESTRICT_VIEW, (bool)value);
+}
+
+static int rna_Group_hide_select_get(PointerRNA *ptr)
+{
+	Group *gr = (Group *)ptr->data;
+	return BKE_group_restrict_flag_get(gr, OB_RESTRICT_SELECT);
+}
+
+static void rna_Group_hide_select_set(PointerRNA *ptr, const int value)
+{
+	Group *gr = (Group *)ptr->data;
+	BKE_group_restrict_flag_set(gr, OB_RESTRICT_SELECT, (bool)value);
+}
+
+static int rna_Group_hide_render_get(PointerRNA *ptr)
+{
+	Group *gr = (Group *)ptr->data;
+	return BKE_group_restrict_flag_get(gr, OB_RESTRICT_RENDER);
+}
+
+static void rna_Group_hide_render_set(PointerRNA *ptr, const int value)
+{
+	Group *gr = (Group *)ptr->data;
+	BKE_group_restrict_flag_set(gr, OB_RESTRICT_RENDER, (bool)value);
+}
+
 #else
 
 /* group.objects */
@@ -118,6 +160,32 @@ void RNA_def_group(BlenderRNA *brna)
 	/* this is done on save/load in readfile.c, removed if no objects are in the group */
 	RNA_def_struct_clear_flag(srna, STRUCT_ID_REFCOUNT);
 
+	/* restrict */
+	RNA_define_verify_sdna(false);
+
+	prop = RNA_def_property(srna, "hide", PROP_BOOLEAN, PROP_NONE);
+	//RNA_def_property_boolean_sdna(prop, NULL, "restrictflag", OB_RESTRICT_VIEW);
+	RNA_def_property_ui_text(prop, "Restrict View", "Restrict visibility in the viewport");
+	RNA_def_property_ui_icon(prop, ICON_RESTRICT_VIEW_OFF, true);
+	RNA_def_property_update(prop, NC_OBJECT | ND_DRAW, "rna_Group_hide_update");
+	RNA_def_property_boolean_funcs(prop, "rna_Group_hide_get", "rna_Group_hide_set");
+
+	prop = RNA_def_property(srna, "hide_select", PROP_BOOLEAN, PROP_NONE);
+	//RNA_def_property_boolean_sdna(prop, NULL, "restrictflag", OB_RESTRICT_SELECT);
+	RNA_def_property_ui_text(prop, "Restrict Select", "Restrict selection in the viewport");
+	RNA_def_property_ui_icon(prop, ICON_RESTRICT_SELECT_OFF, true);
+	RNA_def_property_update(prop, NC_OBJECT | ND_DRAW, NULL);
+	RNA_def_property_boolean_funcs(prop, "rna_Group_hide_select_get", "rna_Group_hide_select_set");
+
+	prop = RNA_def_property(srna, "hide_render", PROP_BOOLEAN, PROP_NONE);
+	//RNA_def_property_boolean_sdna(prop, NULL, "restrictflag", OB_RESTRICT_RENDER);
+	RNA_def_property_ui_text(prop, "Restrict Render", "Restrict renderability");
+	RNA_def_property_ui_icon(prop, ICON_RESTRICT_RENDER_OFF, true);
+	RNA_def_property_update(prop, NC_OBJECT | ND_DRAW, "rna_Group_hide_update");
+	RNA_def_property_boolean_funcs(prop, "rna_Group_hide_render_get", "rna_Group_hide_render_set");
+
+	RNA_define_verify_sdna(true);
+
 	prop = RNA_def_property(srna, "dupli_offset", PROP_FLOAT, PROP_TRANSLATION);
 	RNA_def_property_float_sdna(prop, NULL, "dupli_ofs");
 	RNA_def_property_ui_text(prop, "Dupli Offset", "Offset from the origin to use when instancing as DupliGroup");

Else we’ll just close this as known limitation I guess… :/

Ack, saw that last comment too late… So probably wasted my time, but in case, here is the patch: [P49: #39862](https://archive.blender.org/developer/P49.txt) ```diff diff --git a/source/blender/blenkernel/BKE_group.h b/source/blender/blenkernel/BKE_group.h index f528fe8..997a47d 100644 --- a/source/blender/blenkernel/BKE_group.h +++ b/source/blender/blenkernel/BKE_group.h @@ -55,4 +55,7 @@ bool BKE_group_is_animated(struct Group *group, struct Object *parent); void BKE_group_tag_recalc(struct Group *group); void BKE_group_handle_recalc_and_update(struct EvaluationContext *eval_ctx, struct Scene *scene, struct Object *parent, struct Group *group); +bool BKE_group_restrict_flag_get(struct Group *gr, const int flag); +void BKE_group_restrict_flag_set(struct Group *gr, const int flag, const bool val); + #endif /* __BKE_GROUP_H__ */ diff --git a/source/blender/blenkernel/intern/group.c b/source/blender/blenkernel/intern/group.c index e84db7e..706af4e9 100644 --- a/source/blender/blenkernel/intern/group.c +++ b/source/blender/blenkernel/intern/group.c @@ -381,3 +381,44 @@ void BKE_group_handle_recalc_and_update(EvaluationContext *eval_ctx, Scene *scen } } } + +bool BKE_group_restrict_flag_get(Group *gr, const int flag) +{ + GroupObject *gob; + +#if 1 + for (gob = gr->gobject.first; gob; gob = gob->next) { + if ((gob->ob->restrictflag & flag) == 0) + return false; + } + return true; +#else + /* weak but fast */ + if ((gob = gr->gobject.first)) + if ((gob->ob->restrictflag & flag) == 0) + return false; + return true; +#endif +} + +void BKE_group_restrict_flag_set(Group *gr, const int flag, const bool val) +{ + GroupObject *gob; + + if (val) { + for (gob = gr->gobject.first; gob; gob = gob->next) { + if (gob->ob->id.lib) + continue; + + gob->ob->restrictflag |= flag; + } + } + else { + for (gob = gr->gobject.first; gob; gob = gob->next) { + if (gob->ob->id.lib) + continue; + + gob->ob->restrictflag &= ~flag; + } + } +} diff --git a/source/blender/editors/space_outliner/outliner_draw.c b/source/blender/editors/space_outliner/outliner_draw.c index 4db63a4..2399f21 100644 --- a/source/blender/editors/space_outliner/outliner_draw.c +++ b/source/blender/editors/space_outliner/outliner_draw.c @@ -188,19 +188,12 @@ static void restrictbutton_recursive_child(bContext *C, Scene *scene, Object *ob } } -static void restrictbutton_view_cb(bContext *C, void *poin, void *poin2) +static void restrictbutton_ob_view_cb(bContext *C, void *poin, void *poin2) { Scene *scene = (Scene *)poin; Object *ob = (Object *)poin2; - - if (!common_restrict_check(C, ob)) return; - - /* deselect objects that are invisible */ - if (ob->restrictflag & OB_RESTRICT_VIEW) { - /* Ouch! There is no backwards pointer from Object to Base, - * so have to do loop to find it. */ - ED_base_object_select(BKE_scene_base_find(scene, ob), BA_DESELECT); - } + + if (!common_restrict_check(scene, ob, NULL)) return; if (CTX_wm_window(C)->eventstate->ctrl) { restrictbutton_recursive_child(C, scene, ob, OB_RESTRICT_VIEW, @@ -208,22 +201,14 @@ static void restrictbutton_view_cb(bContext *C, void *poin, void *poin2) } WM_event_add_notifier(C, NC_SCENE | ND_OB_SELECT, scene); - } -static void restrictbutton_sel_cb(bContext *C, void *poin, void *poin2) +static void restrictbutton_ob_sel_cb(bContext *C, void *poin, void *poin2) { Scene *scene = (Scene *)poin; Object *ob = (Object *)poin2; - - if (!common_restrict_check(C, ob)) return; - - /* if select restriction has just been turned on */ - if (ob->restrictflag & OB_RESTRICT_SELECT) { - /* Ouch! There is no backwards pointer from Object to Base, - * so have to do loop to find it. */ - ED_base_object_select(BKE_scene_base_find(scene, ob), BA_DESELECT); - } + + if (!common_restrict_check(scene, ob, NULL)) return; if (CTX_wm_window(C)->eventstate->ctrl) { restrictbutton_recursive_child(C, scene, ob, OB_RESTRICT_SELECT, @@ -231,19 +216,19 @@ static void restrictbutton_sel_cb(bContext *C, void *poin, void *poin2) } WM_event_add_notifier(C, NC_SCENE | ND_OB_SELECT, scene); - } -static void restrictbutton_rend_cb(bContext *C, void *poin, void *poin2) +static void restrictbutton_ob_rend_cb(bContext *C, void *poin, void *poin2) { + Scene *scene = (Scene *)poin; Object *ob = (Object *)poin2; if (CTX_wm_window(C)->eventstate->ctrl) { - restrictbutton_recursive_child(C, (Scene *)poin, ob, OB_RESTRICT_RENDER, + restrictbutton_recursive_child(C, scene, ob, OB_RESTRICT_RENDER, (ob->restrictflag & OB_RESTRICT_RENDER) != 0, false); } - WM_event_add_notifier(C, NC_SCENE | ND_OB_RENDER, poin); + WM_event_add_notifier(C, NC_SCENE | ND_OB_RENDER, scene); } static void restrictbutton_r_lay_cb(bContext *C, void *poin, void *UNUSED(poin2)) @@ -317,25 +302,6 @@ static void restrictbutton_ebone_visibility_cb(bContext *C, void *UNUSED(poin), WM_event_add_notifier(C, NC_OBJECT | ND_POSE, NULL); } -static int group_restrict_flag(Group *gr, int flag) -{ - GroupObject *gob; - -#ifdef USE_GROUP_SELECT - for (gob = gr->gobject.first; gob; gob = gob->next) { - if ((gob->ob->restrictflag & flag) == 0) - return 0; - } - return 1; -#else - /* weak but fast */ - if ((gob = gr->gobject.first)) - if ((gob->ob->restrictflag & flag) == 0) - return 0; - return 1; -#endif -} - static int group_select_flag(Group *gr) { GroupObject *gob; @@ -355,56 +321,45 @@ static int group_select_flag(Group *gr) #endif } -void restrictbutton_gr_restrict_flag(void *poin, void *poin2, int flag) +static void restrictbutton_gr_view_cb(bContext *C, void *poin, void *poin2) { Scene *scene = (Scene *)poin; - GroupObject *gob; Group *gr = (Group *)poin2; + GroupObject *gob; - if (group_restrict_flag(gr, flag)) { - for (gob = gr->gobject.first; gob; gob = gob->next) { - if (gob->ob->id.lib) - continue; - - gob->ob->restrictflag &= ~flag; - - if (flag == OB_RESTRICT_VIEW) - if (gob->ob->flag & SELECT) - ED_base_object_select(BKE_scene_base_find(scene, gob->ob), BA_DESELECT); - } - } - else { - for (gob = gr->gobject.first; gob; gob = gob->next) { - if (gob->ob->id.lib) - continue; - - /* not in editmode */ - if (scene->obedit != gob->ob) { - gob->ob->restrictflag |= flag; + for (gob = gr->gobject.first; gob; gob = gob->next) { + if (gob->ob->id.lib) + continue; - if (ELEM(flag, OB_RESTRICT_SELECT, OB_RESTRICT_VIEW)) { - if ((gob->ob->flag & SELECT)) { - ED_base_object_select(BKE_scene_base_find(scene, gob->ob), BA_DESELECT); - } - } - } - } + common_restrict_check(scene, gob->ob, NULL); } -} -static void restrictbutton_gr_restrict_view(bContext *C, void *poin, void *poin2) -{ - restrictbutton_gr_restrict_flag(poin, poin2, OB_RESTRICT_VIEW); + WM_event_add_notifier(C, NC_SCENE | ND_OB_SELECT, scene); WM_event_add_notifier(C, NC_GROUP, NULL); } -static void restrictbutton_gr_restrict_select(bContext *C, void *poin, void *poin2) + +static void restrictbutton_gr_sel_cb(bContext *C, void *poin, void *poin2) { - restrictbutton_gr_restrict_flag(poin, poin2, OB_RESTRICT_SELECT); + Scene *scene = (Scene *)poin; + Group *gr = (Group *)poin2; + GroupObject *gob; + + for (gob = gr->gobject.first; gob; gob = gob->next) { + if (gob->ob->id.lib) + continue; + + common_restrict_check(scene, gob->ob, NULL); + } + + WM_event_add_notifier(C, NC_SCENE | ND_OB_SELECT, scene); WM_event_add_notifier(C, NC_GROUP, NULL); } -static void restrictbutton_gr_restrict_render(bContext *C, void *poin, void *poin2) + +static void restrictbutton_gr_rend_cb(bContext *C, void *poin, void *UNUSED(poin2)) { - restrictbutton_gr_restrict_flag(poin, poin2, OB_RESTRICT_RENDER); + Scene *scene = (Scene *)poin; + + WM_event_add_notifier(C, NC_SCENE | ND_OB_SELECT, scene); WM_event_add_notifier(C, NC_GROUP, NULL); } @@ -537,6 +492,7 @@ static void outliner_draw_restrictbuts(uiBlock *block, Scene *scene, ARegion *ar Group *gr = NULL; PropertyRNA *object_prop_hide, *object_prop_hide_select, *object_prop_hide_render; + PropertyRNA *grp_prop_hide, *grp_prop_hide_select, *grp_prop_hide_render; /* get RNA properties (once) */ object_prop_hide = RNA_struct_type_find_property(&RNA_Object, "hide"); @@ -544,6 +500,10 @@ static void outliner_draw_restrictbuts(uiBlock *block, Scene *scene, ARegion *ar object_prop_hide_render = RNA_struct_type_find_property(&RNA_Object, "hide_render"); BLI_assert(object_prop_hide && object_prop_hide_select && object_prop_hide_render); + grp_prop_hide = RNA_struct_type_find_property(&RNA_Group, "hide"); + grp_prop_hide_select = RNA_struct_type_find_property(&RNA_Group, "hide_select"); + grp_prop_hide_render = RNA_struct_type_find_property(&RNA_Group, "hide_render"); + BLI_assert(grp_prop_hide && grp_prop_hide_select && grp_prop_hide_render); for (te = lb->first; te; te = te->next) { tselem = TREESTORE(te); @@ -560,56 +520,53 @@ static void outliner_draw_restrictbuts(uiBlock *block, Scene *scene, ARegion *ar (int)(ar->v2d.cur.xmax - OL_TOG_RESTRICT_VIEWX), te->ys, UI_UNIT_X, UI_UNIT_Y, &ptr, object_prop_hide, -1, 0, 0, -1, -1, TIP_("Restrict viewport visibility (Ctrl - Recursive)")); - uiButSetFunc(bt, restrictbutton_view_cb, scene, ob); + uiButSetFunc(bt, restrictbutton_ob_view_cb, scene, ob); uiButSetFlag(bt, UI_BUT_DRAG_LOCK); bt = uiDefIconButR_prop(block, ICONTOG, 0, ICON_RESTRICT_SELECT_OFF, (int)(ar->v2d.cur.xmax - OL_TOG_RESTRICT_SELECTX), te->ys, UI_UNIT_X, UI_UNIT_Y, &ptr, object_prop_hide_select, -1, 0, 0, -1, -1, TIP_("Restrict viewport selection (Ctrl - Recursive)")); - uiButSetFunc(bt, restrictbutton_sel_cb, scene, ob); + uiButSetFunc(bt, restrictbutton_ob_sel_cb, scene, ob); uiButSetFlag(bt, UI_BUT_DRAG_LOCK); bt = uiDefIconButR_prop(block, ICONTOG, 0, ICON_RESTRICT_RENDER_OFF, (int)(ar->v2d.cur.xmax - OL_TOG_RESTRICT_RENDERX), te->ys, UI_UNIT_X, UI_UNIT_Y, &ptr, object_prop_hide_render, -1, 0, 0, -1, -1, TIP_("Restrict rendering (Ctrl - Recursive)")); - uiButSetFunc(bt, restrictbutton_rend_cb, scene, ob); + uiButSetFunc(bt, restrictbutton_ob_rend_cb, scene, ob); uiButSetFlag(bt, UI_BUT_DRAG_LOCK); uiBlockSetEmboss(block, UI_EMBOSS); } if (tselem->type == 0 && te->idcode == ID_GR) { - int restrict_bool; - int but_flag = UI_BUT_DRAG_LOCK; + PointerRNA ptr; + gr = (Group *)tselem->id; + RNA_pointer_create((ID *)gr, &RNA_Group, gr, &ptr); - if (gr->id.lib) - but_flag |= UI_BUT_DISABLED; - uiBlockSetEmboss(block, UI_EMBOSSN); + bt = uiDefIconButR_prop(block, ICONTOG, 0, ICON_RESTRICT_VIEW_OFF, + (int)(ar->v2d.cur.xmax - OL_TOG_RESTRICT_VIEWX), te->ys, UI_UNIT_X, UI_UNIT_Y, + &ptr, grp_prop_hide, -1, 0, 0, -1, -1, + TIP_("Restrict viewport visibility")); + uiButSetFunc(bt, restrictbutton_gr_view_cb, scene, gr); + uiButSetFlag(bt, UI_BUT_DRAG_LOCK); + + bt = uiDefIconButR_prop(block, ICONTOG, 0, ICON_RESTRICT_SELECT_OFF, + (int)(ar->v2d.cur.xmax - OL_TOG_RESTRICT_SELECTX), te->ys, UI_UNIT_X, UI_UNIT_Y, + &ptr, grp_prop_hide_select, -1, 0, 0, -1, -1, + TIP_("Restrict viewport selection")); + uiButSetFunc(bt, restrictbutton_gr_sel_cb, scene, gr); + uiButSetFlag(bt, UI_BUT_DRAG_LOCK); - restrict_bool = group_restrict_flag(gr, OB_RESTRICT_VIEW); - bt = uiDefIconBut(block, ICONTOG, 0, restrict_bool ? ICON_RESTRICT_VIEW_ON : ICON_RESTRICT_VIEW_OFF, - (int)(ar->v2d.cur.xmax - OL_TOG_RESTRICT_VIEWX), te->ys, UI_UNIT_X, UI_UNIT_Y, - NULL, 0, 0, 0, 0, TIP_("Restrict/Allow visibility in the 3D View")); - uiButSetFunc(bt, restrictbutton_gr_restrict_view, scene, gr); - uiButSetFlag(bt, but_flag); - - restrict_bool = group_restrict_flag(gr, OB_RESTRICT_SELECT); - bt = uiDefIconBut(block, ICONTOG, 0, restrict_bool ? ICON_RESTRICT_SELECT_ON : ICON_RESTRICT_SELECT_OFF, - (int)(ar->v2d.cur.xmax - OL_TOG_RESTRICT_SELECTX), te->ys, UI_UNIT_X, UI_UNIT_Y, - NULL, 0, 0, 0, 0, TIP_("Restrict/Allow selection in the 3D View")); - uiButSetFunc(bt, restrictbutton_gr_restrict_select, scene, gr); - uiButSetFlag(bt, but_flag); - - restrict_bool = group_restrict_flag(gr, OB_RESTRICT_RENDER); - bt = uiDefIconBut(block, ICONTOG, 0, restrict_bool ? ICON_RESTRICT_RENDER_ON : ICON_RESTRICT_RENDER_OFF, - (int)(ar->v2d.cur.xmax - OL_TOG_RESTRICT_RENDERX), te->ys, UI_UNIT_X, UI_UNIT_Y, - NULL, 0, 0, 0, 0, TIP_("Restrict/Allow renderability")); - uiButSetFunc(bt, restrictbutton_gr_restrict_render, scene, gr); - uiButSetFlag(bt, but_flag); + bt = uiDefIconButR_prop(block, ICONTOG, 0, ICON_RESTRICT_RENDER_OFF, + (int)(ar->v2d.cur.xmax - OL_TOG_RESTRICT_RENDERX), te->ys, UI_UNIT_X, UI_UNIT_Y, + &ptr, grp_prop_hide_render, -1, 0, 0, -1, -1, + TIP_("Restrict rendering")); + uiButSetFunc(bt, restrictbutton_gr_rend_cb, scene, gr); + uiButSetFlag(bt, UI_BUT_DRAG_LOCK); uiBlockSetEmboss(block, UI_EMBOSS); } diff --git a/source/blender/editors/space_outliner/outliner_edit.c b/source/blender/editors/space_outliner/outliner_edit.c index 17e1e03..39e932c 100644 --- a/source/blender/editors/space_outliner/outliner_edit.c +++ b/source/blender/editors/space_outliner/outliner_edit.c @@ -45,6 +45,7 @@ #include "BKE_animsys.h" #include "BKE_context.h" #include "BKE_depsgraph.h" +#include "BKE_group.h" #include "BKE_library.h" #include "BKE_main.h" #include "BKE_report.h" @@ -354,12 +355,12 @@ void outliner_set_flag(SpaceOops *soops, ListBase *lb, short flag, short set) /* same check needed for both object operation and restrict column button func * return 0 when in edit mode (cannot restrict view or select) * otherwise return 1 */ -int common_restrict_check(bContext *C, Object *ob) +bool common_restrict_check(Scene *scene, Object *ob, Base *base) { /* Don't allow hide an object in edit mode, * check the bug #22153 and #21609, #23977 */ - Object *obedit = CTX_data_edit_object(C); + Object *obedit = scene->obedit; if (obedit && obedit == ob) { /* found object is hidden, reset */ if (ob->restrictflag & OB_RESTRICT_VIEW) @@ -370,35 +371,61 @@ int common_restrict_check(bContext *C, Object *ob) return 0; } + if (ob->restrictflag & (OB_RESTRICT_VIEW | OB_RESTRICT_SELECT)) { + if (!base) { + /* Ouch! There is no backwards pointer from Object to Base, so have to do loop to find it. */ + base = BKE_scene_base_find(scene, ob); + } + ED_base_object_select(base, BA_DESELECT); + } + return 1; } /* =============================================== */ /* Restriction toggles */ +static void group_toggle_restrict_flag(Scene *scene, Group *gr, const int flag) +{ + GroupObject *gob; + const bool set = !BKE_group_restrict_flag_get(gr, flag); + + for (gob = gr->gobject.first; gob; gob = gob->next) { + if (gob->ob->id.lib) + continue; + + if (set) { + gob->ob->restrictflag |= flag; + } + else { + gob->ob->restrictflag &= ~flag; + } + + if (flag & (OB_RESTRICT_VIEW | OB_RESTRICT_SELECT)) { + common_restrict_check(scene, gob->ob, NULL); + } + } +} + /* Toggle Visibility ---------------------------------------- */ -void object_toggle_visibility_cb(bContext *C, Scene *scene, TreeElement *te, +void object_toggle_visibility_cb(bContext *UNUSED(C), Scene *scene, TreeElement *te, TreeStoreElem *UNUSED(tsep), TreeStoreElem *tselem) { Base *base = (Base *)te->directdata; Object *ob = (Object *)tselem->id; - - /* add check for edit mode */ - if (!common_restrict_check(C, ob)) return; - - if (base || (base = BKE_scene_base_find(scene, ob))) { - if ((base->object->restrictflag ^= OB_RESTRICT_VIEW)) { - ED_base_object_select(base, BA_DESELECT); - } - } + + ob->restrictflag ^= OB_RESTRICT_VIEW; + + /* add check for edit mode, and deselect if hidden/unselectable */ + if (!common_restrict_check(scene, ob, base)) return; } void group_toggle_visibility_cb(bContext *UNUSED(C), Scene *scene, TreeElement *UNUSED(te), TreeStoreElem *UNUSED(tsep), TreeStoreElem *tselem) { Group *group = (Group *)tselem->id; - restrictbutton_gr_restrict_flag(scene, group, OB_RESTRICT_VIEW); + group_toggle_restrict_flag(scene, group, OB_RESTRICT_VIEW); } static int outliner_toggle_visibility_exec(bContext *C, wmOperator *UNUSED(op)) @@ -437,18 +464,19 @@ void object_toggle_selectability_cb(bContext *UNUSED(C), Scene *scene, TreeEleme TreeStoreElem *UNUSED(tsep), TreeStoreElem *tselem) { Base *base = (Base *)te->directdata; - - if (base == NULL) base = BKE_scene_base_find(scene, (Object *)tselem->id); - if (base) { - base->object->restrictflag ^= OB_RESTRICT_SELECT; - } + Object *ob = (Object *)tselem->id; + + ob->restrictflag ^= OB_RESTRICT_SELECT; + + /* add check for edit mode, and deselect if hidden/unselectable */ + if (!common_restrict_check(scene, ob, base)) return; } void group_toggle_selectability_cb(bContext *UNUSED(C), Scene *scene, TreeElement *UNUSED(te), TreeStoreElem *UNUSED(tsep), TreeStoreElem *tselem) { Group *group = (Group *)tselem->id; - restrictbutton_gr_restrict_flag(scene, group, OB_RESTRICT_SELECT); + group_toggle_restrict_flag(scene, group, OB_RESTRICT_SELECT); } static int outliner_toggle_selectability_exec(bContext *C, wmOperator *UNUSED(op)) @@ -481,22 +509,19 @@ void OUTLINER_OT_selectability_toggle(wmOperatorType *ot) /* Toggle Renderability ---------------------------------------- */ -void object_toggle_renderability_cb(bContext *UNUSED(C), Scene *scene, TreeElement *te, +void object_toggle_renderability_cb(bContext *UNUSED(C), Scene *UNUSED(scene), TreeElement *UNUSED(te), TreeStoreElem *UNUSED(tsep), TreeStoreElem *tselem) { - Base *base = (Base *)te->directdata; - - if (base == NULL) base = BKE_scene_base_find(scene, (Object *)tselem->id); - if (base) { - base->object->restrictflag ^= OB_RESTRICT_RENDER; - } + Object *ob = (Object *)tselem->id; + + ob->restrictflag ^= OB_RESTRICT_RENDER; } void group_toggle_renderability_cb(bContext *UNUSED(C), Scene *scene, TreeElement *UNUSED(te), TreeStoreElem *UNUSED(tsep), TreeStoreElem *tselem) { Group *group = (Group *)tselem->id; - restrictbutton_gr_restrict_flag(scene, group, OB_RESTRICT_RENDER); + group_toggle_restrict_flag(scene, group, OB_RESTRICT_RENDER); } static int outliner_toggle_renderability_exec(bContext *C, wmOperator *UNUSED(op)) diff --git a/source/blender/editors/space_outliner/outliner_intern.h b/source/blender/editors/space_outliner/outliner_intern.h index 317d33d..18d8940 100644 --- a/source/blender/editors/space_outliner/outliner_intern.h +++ b/source/blender/editors/space_outliner/outliner_intern.h @@ -174,7 +174,6 @@ void outliner_build_tree(struct Main *mainvar, struct Scene *scene, struct Space /* outliner_draw.c ---------------------------------------------- */ void draw_outliner(const struct bContext *C); -void restrictbutton_gr_restrict_flag(void *poin, void *poin2, int flag); /* outliner_select.c -------------------------------------------- */ eOLDrawState tree_element_type_active( @@ -189,7 +188,7 @@ int outliner_item_do_activate(struct bContext *C, int x, int y, bool extend, boo void outliner_do_object_operation(struct bContext *C, struct Scene *scene, struct SpaceOops *soops, struct ListBase *lb, void (*operation_cb)(struct bContext *C, struct Scene *scene, struct TreeElement *, struct TreeStoreElem *, TreeStoreElem *)); -int common_restrict_check(struct bContext *C, struct Object *ob); +bool common_restrict_check(struct Scene *scene, struct Object *ob, struct Base *base); int outliner_has_one_flag(struct SpaceOops *soops, ListBase *lb, short flag, const int curlevel); void outliner_set_flag(struct SpaceOops *soops, ListBase *lb, short flag, short set); diff --git a/source/blender/makesrna/intern/rna_group.c b/source/blender/makesrna/intern/rna_group.c index 2f9c12c..001ea88 100644 --- a/source/blender/makesrna/intern/rna_group.c +++ b/source/blender/makesrna/intern/rna_group.c @@ -42,6 +42,7 @@ #include "DNA_object_types.h" #include "BKE_group.h" +#include "BKE_depsgraph.h" #include "WM_api.h" @@ -73,6 +74,47 @@ static void rna_Group_objects_unlink(Group *group, bContext *C, ReportList *repo WM_main_add_notifier(NC_OBJECT | ND_DRAW, &object->id); } +static void rna_Group_hide_update(Main *bmain, Scene *UNUSED(scene), PointerRNA *UNUSED(ptr)) +{ + DAG_id_type_tag(bmain, ID_OB); +} + +static int rna_Group_hide_get(PointerRNA *ptr) +{ + Group *gr = (Group *)ptr->data; + return BKE_group_restrict_flag_get(gr, OB_RESTRICT_VIEW); +} + +static void rna_Group_hide_set(PointerRNA *ptr, const int value) +{ + Group *gr = (Group *)ptr->data; + BKE_group_restrict_flag_set(gr, OB_RESTRICT_VIEW, (bool)value); +} + +static int rna_Group_hide_select_get(PointerRNA *ptr) +{ + Group *gr = (Group *)ptr->data; + return BKE_group_restrict_flag_get(gr, OB_RESTRICT_SELECT); +} + +static void rna_Group_hide_select_set(PointerRNA *ptr, const int value) +{ + Group *gr = (Group *)ptr->data; + BKE_group_restrict_flag_set(gr, OB_RESTRICT_SELECT, (bool)value); +} + +static int rna_Group_hide_render_get(PointerRNA *ptr) +{ + Group *gr = (Group *)ptr->data; + return BKE_group_restrict_flag_get(gr, OB_RESTRICT_RENDER); +} + +static void rna_Group_hide_render_set(PointerRNA *ptr, const int value) +{ + Group *gr = (Group *)ptr->data; + BKE_group_restrict_flag_set(gr, OB_RESTRICT_RENDER, (bool)value); +} + #else /* group.objects */ @@ -118,6 +160,32 @@ void RNA_def_group(BlenderRNA *brna) /* this is done on save/load in readfile.c, removed if no objects are in the group */ RNA_def_struct_clear_flag(srna, STRUCT_ID_REFCOUNT); + /* restrict */ + RNA_define_verify_sdna(false); + + prop = RNA_def_property(srna, "hide", PROP_BOOLEAN, PROP_NONE); + //RNA_def_property_boolean_sdna(prop, NULL, "restrictflag", OB_RESTRICT_VIEW); + RNA_def_property_ui_text(prop, "Restrict View", "Restrict visibility in the viewport"); + RNA_def_property_ui_icon(prop, ICON_RESTRICT_VIEW_OFF, true); + RNA_def_property_update(prop, NC_OBJECT | ND_DRAW, "rna_Group_hide_update"); + RNA_def_property_boolean_funcs(prop, "rna_Group_hide_get", "rna_Group_hide_set"); + + prop = RNA_def_property(srna, "hide_select", PROP_BOOLEAN, PROP_NONE); + //RNA_def_property_boolean_sdna(prop, NULL, "restrictflag", OB_RESTRICT_SELECT); + RNA_def_property_ui_text(prop, "Restrict Select", "Restrict selection in the viewport"); + RNA_def_property_ui_icon(prop, ICON_RESTRICT_SELECT_OFF, true); + RNA_def_property_update(prop, NC_OBJECT | ND_DRAW, NULL); + RNA_def_property_boolean_funcs(prop, "rna_Group_hide_select_get", "rna_Group_hide_select_set"); + + prop = RNA_def_property(srna, "hide_render", PROP_BOOLEAN, PROP_NONE); + //RNA_def_property_boolean_sdna(prop, NULL, "restrictflag", OB_RESTRICT_RENDER); + RNA_def_property_ui_text(prop, "Restrict Render", "Restrict renderability"); + RNA_def_property_ui_icon(prop, ICON_RESTRICT_RENDER_OFF, true); + RNA_def_property_update(prop, NC_OBJECT | ND_DRAW, "rna_Group_hide_update"); + RNA_def_property_boolean_funcs(prop, "rna_Group_hide_render_get", "rna_Group_hide_render_set"); + + RNA_define_verify_sdna(true); + prop = RNA_def_property(srna, "dupli_offset", PROP_FLOAT, PROP_TRANSLATION); RNA_def_property_float_sdna(prop, NULL, "dupli_ofs"); RNA_def_property_ui_text(prop, "Dupli Offset", "Offset from the origin to use when instancing as DupliGroup"); ``` Else we’ll just close this as known limitation I guess… :/

: (

: (
Bastien Montagne removed their assignment 2014-05-18 10:22:00 +02:00

Added subscriber: @DuarteRamos

Added subscriber: @DuarteRamos
Paweł Łyczkowski changed title from Drag-to-toggle visible/selectable/renderable to Drag-to-toggle visible/selectable/renderable in the Group view. 2015-10-18 17:22:57 +02:00
Sign in to join this conversation.
No Label
Interest
Alembic
Interest
Animation & Rigging
Interest
Asset Browser
Interest
Asset Browser Project Overview
Interest
Audio
Interest
Automated Testing
Interest
Blender Asset Bundle
Interest
BlendFile
Interest
Collada
Interest
Compatibility
Interest
Compositing
Interest
Core
Interest
Cycles
Interest
Dependency Graph
Interest
Development Management
Interest
EEVEE
Interest
EEVEE & Viewport
Interest
Freestyle
Interest
Geometry Nodes
Interest
Grease Pencil
Interest
ID Management
Interest
Images & Movies
Interest
Import Export
Interest
Line Art
Interest
Masking
Interest
Metal
Interest
Modeling
Interest
Modifiers
Interest
Motion Tracking
Interest
Nodes & Physics
Interest
OpenGL
Interest
Overlay
Interest
Overrides
Interest
Performance
Interest
Physics
Interest
Pipeline, Assets & IO
Interest
Platforms, Builds & Tests
Interest
Python API
Interest
Render & Cycles
Interest
Render Pipeline
Interest
Sculpt, Paint & Texture
Interest
Text Editor
Interest
Translations
Interest
Triaging
Interest
Undo
Interest
USD
Interest
User Interface
Interest
UV Editing
Interest
VFX & Video
Interest
Video Sequencer
Interest
Virtual Reality
Interest
Vulkan
Interest
Wayland
Interest
Workbench
Interest: X11
Legacy
Blender 2.8 Project
Legacy
Milestone 1: Basic, Local Asset Browser
Legacy
OpenGL Error
Meta
Good First Issue
Meta
Papercut
Meta
Retrospective
Meta
Security
Module
Animation & Rigging
Module
Core
Module
Development Management
Module
EEVEE & Viewport
Module
Grease Pencil
Module
Modeling
Module
Nodes & Physics
Module
Pipeline, Assets & IO
Module
Platforms, Builds & Tests
Module
Python API
Module
Render & Cycles
Module
Sculpt, Paint & Texture
Module
Triaging
Module
User Interface
Module
VFX & Video
Platform
FreeBSD
Platform
Linux
Platform
macOS
Platform
Windows
Priority
High
Priority
Low
Priority
Normal
Priority
Unbreak Now!
Status
Archived
Status
Confirmed
Status
Duplicate
Status
Needs Info from Developers
Status
Needs Information from User
Status
Needs Triage
Status
Resolved
Type
Bug
Type
Design
Type
Known Issue
Type
Patch
Type
Report
Type
To Do
No Milestone
No project
No Assignees
4 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: blender/blender#39862
No description provided.