[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [49015] trunk/blender/source/blender/ editors/object/object_group.c: adding objects active groups now gives menu of which group to add to.

Campbell Barton ideasman42 at gmail.com
Wed Jul 18 10:13:31 CEST 2012


Revision: 49015
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=49015
Author:   campbellbarton
Date:     2012-07-18 08:13:30 +0000 (Wed, 18 Jul 2012)
Log Message:
-----------
adding objects active groups now gives menu of which group to add to.

Modified Paths:
--------------
    trunk/blender/source/blender/editors/object/object_group.c

Modified: trunk/blender/source/blender/editors/object/object_group.c
===================================================================
--- trunk/blender/source/blender/editors/object/object_group.c	2012-07-18 05:51:44 UTC (rev 49014)
+++ trunk/blender/source/blender/editors/object/object_group.c	2012-07-18 08:13:30 UTC (rev 49015)
@@ -59,57 +59,113 @@
 
 /********************* 3d view operators ***********************/
 
+/* can be called with C == NULL */
+static EnumPropertyItem *group_object_active_itemf(bContext *C, PointerRNA *UNUSED(ptr), PropertyRNA *UNUSED(prop), int *free)
+{
+	Object *ob;
+	EnumPropertyItem *item = NULL, item_tmp = {0};
+	int totitem = 0;
+
+	if (C == NULL) {
+		return DummyRNA_NULL_items;
+	}
+
+	ob = ED_object_context(C);
+
+	/* check that the action exists */
+	if (ob) {
+		Group *group = NULL;
+		int i = 0;
+
+		while ((group = find_group(ob, group))) {
+			item_tmp.identifier = item_tmp.name = group->id.name + 2;
+			/* item_tmp.icon = ICON_ARMATURE_DATA; */
+			item_tmp.value = i;
+			RNA_enum_item_add(&item, &totitem, &item_tmp);
+			i++;
+		}
+	}
+
+	RNA_enum_item_end(&item, &totitem);
+	*free = 1;
+
+	return item;
+}
+
+/* get the group back from the enum index, quite awkward and UI specific */
+static Group *group_object_active_find_index(Object *ob, const int group_object_index)
+{
+	Group *group = NULL;
+	int i = 0;
+	while ((group = find_group(ob, group))) {
+		if (i == group_object_index) {
+			break;
+		}
+		i++;
+	}
+
+	return group;
+}
+
 static int objects_add_active_exec(bContext *C, wmOperator *op)
 {
+	Object *ob = ED_object_context(C);
 	Main *bmain = CTX_data_main(C);
 	Scene *scene = CTX_data_scene(C);
-	Object *ob = OBACT;
-	Group *group;
-	int ok = 0, cycle = 0;
-	
-	if (!ob) return OPERATOR_CANCELLED;
-	
-	/* linking to same group requires its own loop so we can avoid
-	 * looking up the active objects groups each time */
+	int group_object_index = RNA_enum_get(op->ptr, "group");
+	int cycle = FALSE;
 
-	for (group = bmain->group.first; group; group = group->id.next) {
-		if (object_in_group(ob, group)) {
-			/* Assign groups to selected objects */
+	if (ob) {
+		Group *group = group_object_active_find_index(ob, group_object_index);
+
+		/* now add all selected objects from the group */
+		if (group) {
+
 			CTX_DATA_BEGIN (C, Base *, base, selected_editable_bases)
 			{
-				if (base->object->dup_group != group)
+				if (base->object->dup_group != group) {
 					add_to_group(group, base->object, scene, base);
-				else
-					cycle = 1;
-				ok = 1;
+				}
+				else {
+					cycle = TRUE;
+				}
 			}
 			CTX_DATA_END;
+
+			DAG_scene_sort(bmain, scene);
+			WM_event_add_notifier(C, NC_GROUP | NA_EDITED, NULL);
+
+			return OPERATOR_FINISHED;
 		}
 	}
-	
-	if (!ok) BKE_report(op->reports, RPT_ERROR, "Active Object contains no groups");
+
 	if (cycle)
 		BKE_report(op->reports, RPT_WARNING, "Skipped some groups because of cycle detected");
-	
-	DAG_scene_sort(bmain, scene);
-	WM_event_add_notifier(C, NC_GROUP | NA_EDITED, NULL);
-	
-	return OPERATOR_FINISHED;
+
+	return OPERATOR_CANCELLED;
 }
 
 void GROUP_OT_objects_add_active(wmOperatorType *ot)
 {
+	PropertyRNA *prop;
+
 	/* identifiers */
 	ot->name = "Add Selected To Active Group";
 	ot->description = "Add the object to an object group that contains the active object";
 	ot->idname = "GROUP_OT_objects_add_active";
 	
 	/* api callbacks */
-	ot->exec = objects_add_active_exec;	
+	ot->exec = objects_add_active_exec;
+	ot->invoke = WM_menu_invoke;
 	ot->poll = ED_operator_objectmode;
 
 	/* flags */
 	ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
+
+	/* properties */
+	prop = RNA_def_enum(ot->srna, "group", DummyRNA_NULL_items, 0, "Group", "The group to add other selected objects to");
+	RNA_def_enum_funcs(prop, group_object_active_itemf);
+	ot->prop = prop;
 }
 
 static int objects_remove_active_exec(bContext *C, wmOperator *op)
@@ -202,18 +258,9 @@
 	Scene *scene = CTX_data_scene(C);
 	int group_object_index = RNA_enum_get(op->ptr, "group");
 
-	/* first get the group back from the enum index, quite awkward and UI specific */
 	if (ob) {
-		Group *group = NULL;
-		int i = 0;
+		Group *group = group_object_active_find_index(ob, group_object_index);
 
-		while ((group = find_group(ob, group))) {
-			if (i == group_object_index) {
-				break;
-			}
-			i++;
-		}
-
 		/* now remove all selected objects from the group */
 		if (group) {
 
@@ -233,40 +280,6 @@
 	return OPERATOR_CANCELLED;
 }
 
-
-/* can be called with C == NULL */
-static EnumPropertyItem *group_objects_remove_itemf(bContext *C, PointerRNA *UNUSED(ptr), PropertyRNA *UNUSED(prop), int *free)
-{
-	Object *ob;
-	EnumPropertyItem *item = NULL, item_tmp = {0};
-	int totitem = 0;
-
-	if (C == NULL) {
-		return DummyRNA_NULL_items;
-	}
-
-	ob = ED_object_context(C);
-
-	/* check that the action exists */
-	if (ob) {
-		Group *group = NULL;
-		int i = 0;
-
-		while ((group = find_group(ob, group))) {
-			item_tmp.identifier = item_tmp.name = group->id.name + 2;
-			/* item_tmp.icon = ICON_ARMATURE_DATA; */
-			item_tmp.value = i;
-			RNA_enum_item_add(&item, &totitem, &item_tmp);
-			i++;
-		}
-	}
-
-	RNA_enum_item_end(&item, &totitem);
-	*free = 1;
-
-	return item;
-}
-
 void GROUP_OT_objects_remove(wmOperatorType *ot)
 {
 	PropertyRNA *prop;
@@ -286,7 +299,7 @@
 
 	/* properties */
 	prop = RNA_def_enum(ot->srna, "group", DummyRNA_NULL_items, 0, "Group", "The group to remove this object from");
-	RNA_def_enum_funcs(prop, group_objects_remove_itemf);
+	RNA_def_enum_funcs(prop, group_object_active_itemf);
 	ot->prop = prop;
 }
 




More information about the Bf-blender-cvs mailing list