[Bf-blender-cvs] [65bad61cee7] soc-2019-outliner: Outliner: Add set parent menu for multiple objects
Nathan Craddock
noreply at git.blender.org
Tue Jul 30 06:15:22 CEST 2019
Commit: 65bad61cee7cc549acc816ed0eba49b1dfdff41f
Author: Nathan Craddock
Date: Mon Jul 29 22:12:17 2019 -0600
Branches: soc-2019-outliner
https://developer.blender.org/rB65bad61cee7cc549acc816ed0eba49b1dfdff41f
Outliner: Add set parent menu for multiple objects
Allow setting the parent for multiple objects to curves, lattices
and armatures from the outliner. This has a few issues still.
===================================================================
M source/blender/editors/space_outliner/outliner_dragdrop.c
===================================================================
diff --git a/source/blender/editors/space_outliner/outliner_dragdrop.c b/source/blender/editors/space_outliner/outliner_dragdrop.c
index b7a38c0b82f..6bd47da7be2 100644
--- a/source/blender/editors/space_outliner/outliner_dragdrop.c
+++ b/source/blender/editors/space_outliner/outliner_dragdrop.c
@@ -326,38 +326,256 @@ static bool parent_drop_poll(bContext *C,
return false;
}
-static int parent_drop_exec(bContext *C, wmOperator *op)
+static void parent_drop_set_parents(
+ bContext *C, wmOperator *op, wmDragID *drag, Object *parent, short parent_type)
{
- Object *par = NULL, *ob = NULL;
Main *bmain = CTX_data_main(C);
- Scene *scene = CTX_data_scene(C);
- int partype = -1;
- char parname[MAX_NAME], childname[MAX_NAME];
+ SpaceOutliner *soops = CTX_wm_space_outliner(C);
- partype = RNA_enum_get(op->ptr, "type");
- RNA_string_get(op->ptr, "parent", parname);
- par = (Object *)BKE_libblock_find_name(bmain, ID_OB, parname);
- RNA_string_get(op->ptr, "child", childname);
- ob = (Object *)BKE_libblock_find_name(bmain, ID_OB, childname);
+ TreeElement *te = outliner_find_id(soops, &soops->tree, &parent->id);
+ Scene *scene = (Scene *)outliner_search_back(soops, te, ID_SCE);
- if (ID_IS_LINKED(ob)) {
- BKE_report(op->reports, RPT_INFO, "Can't edit library linked object");
- return OPERATOR_CANCELLED;
+ if (scene == NULL) {
+ /* currently outlier organized in a way, that if there's no parent scene
+ * element for object it means that all displayed objects belong to
+ * active scene and parenting them is allowed (sergey)
+ */
+
+ scene = CTX_data_scene(C);
}
- ED_object_parent_set(op->reports, C, scene, ob, par, partype, false, false, NULL);
+ bool parent_set = false;
+ for (wmDragID *drag_id = drag; drag_id; drag_id = drag_id->next) {
+ if (GS(drag_id->id->name) == ID_OB) {
+ Object *object = (Object *)drag_id->id;
- DEG_relations_tag_update(bmain);
- WM_event_add_notifier(C, NC_OBJECT | ND_TRANSFORM, NULL);
- WM_event_add_notifier(C, NC_OBJECT | ND_PARENT, NULL);
+ /* Do nothing to linked data */
+ if (ID_IS_LINKED(object)) {
+ puts("Can't edit library linked object");
+ // BKE_report(op->reports, RPT_INFO, "Can't edit library linked object");
+ continue;
+ }
- return OPERATOR_FINISHED;
+ if (ED_object_parent_set(NULL, C, scene, object, parent, parent_type, false, false, NULL)) {
+ parent_set = true;
+ }
+ }
+ }
+
+ if (parent_set) {
+ DEG_relations_tag_update(bmain);
+ WM_event_add_notifier(C, NC_OBJECT | ND_TRANSFORM, NULL);
+ WM_event_add_notifier(C, NC_OBJECT | ND_PARENT, NULL);
+ }
+}
+
+typedef struct ParentDropData {
+ wmOperator *op;
+ Object *parent;
+ ListBase *drag_items;
+ short type;
+} ParentDropData;
+
+static void parent_drop_menu_callback(bContext *C, void *data, int event)
+{
+ ParentDropData *drag_data = (ParentDropData *)data;
+
+ wmDragID *drag = drag_data->drag_items->first;
+ parent_drop_set_parents(C, drag_data->op, drag, drag_data->parent, event);
+
+ BLI_freelistN(drag_data->drag_items);
+ MEM_freeN(drag_data->drag_items);
+ MEM_freeN(drag_data);
+}
+
+static uiBlock *parent_drop_menu(bContext *C, ARegion *ar, void *data)
+{
+ uiBlock *block;
+ ParentDropData *drag_data = (ParentDropData *)data;
+
+ block = UI_block_begin(C, ar, __func__, UI_EMBOSS);
+ UI_block_flag_enable(block, UI_BLOCK_MOVEMOUSE_QUIT);
+ UI_block_func_butmenu_set(block, parent_drop_menu_callback, drag_data);
+
+ short menu_width = 10 * UI_UNIT_X;
+ short y_position = 0;
+
+ uiDefBut(block,
+ UI_BTYPE_LABEL,
+ 0,
+ IFACE_("Set Parent To"),
+ 0,
+ y_position,
+ menu_width,
+ UI_UNIT_Y,
+ NULL,
+ 0.0,
+ 0.0,
+ 0,
+ 0,
+ "");
+
+ uiDefBut(block,
+ UI_BTYPE_BUT_MENU,
+ 0,
+ IFACE_("Object"),
+ 0,
+ y_position -= UI_UNIT_Y,
+ menu_width,
+ UI_UNIT_Y,
+ NULL,
+ 0.0,
+ 0.0,
+ 0,
+ PAR_OBJECT,
+ "");
+
+ if (drag_data->type == OB_ARMATURE) {
+ uiDefBut(block,
+ UI_BTYPE_BUT_MENU,
+ 0,
+ IFACE_("Armature Deform"),
+ 0,
+ y_position -= UI_UNIT_Y,
+ menu_width,
+ UI_UNIT_Y,
+ NULL,
+ 0.0,
+ 0.0,
+ 0,
+ PAR_ARMATURE,
+ "");
+
+ uiDefBut(block,
+ UI_BTYPE_BUT_MENU,
+ 0,
+ IFACE_(" With Empty Groups"),
+ 0,
+ y_position -= UI_UNIT_Y,
+ menu_width,
+ UI_UNIT_Y,
+ NULL,
+ 0.0,
+ 0.0,
+ 0,
+ PAR_ARMATURE_NAME,
+ "");
+
+ uiDefBut(block,
+ UI_BTYPE_BUT_MENU,
+ 0,
+ IFACE_(" With Envelope Weights"),
+ 0,
+ y_position -= UI_UNIT_Y,
+ menu_width,
+ UI_UNIT_Y,
+ NULL,
+ 0.0,
+ 0.0,
+ 0,
+ PAR_ARMATURE_ENVELOPE,
+ "");
+
+ uiDefBut(block,
+ UI_BTYPE_BUT_MENU,
+ 0,
+ IFACE_(" With Automatic Weights"),
+ 0,
+ y_position -= UI_UNIT_Y,
+ menu_width,
+ UI_UNIT_Y,
+ NULL,
+ 0.0,
+ 0.0,
+ 0,
+ PAR_ARMATURE_AUTO,
+ "");
+
+ uiDefBut(block,
+ UI_BTYPE_BUT_MENU,
+ 0,
+ IFACE_("Bone"),
+ 0,
+ y_position -= UI_UNIT_Y,
+ menu_width,
+ UI_UNIT_Y,
+ NULL,
+ 0.0,
+ 0.0,
+ 0,
+ PAR_BONE,
+ "");
+ }
+ else if (drag_data->type == OB_CURVE) {
+ uiDefBut(block,
+ UI_BTYPE_BUT_MENU,
+ 0,
+ IFACE_("Curve Deform"),
+ 0,
+ y_position -= UI_UNIT_Y,
+ menu_width,
+ UI_UNIT_Y,
+ NULL,
+ 0.0,
+ 0.0,
+ 0,
+ PAR_CURVE,
+ "");
+
+ uiDefBut(block,
+ UI_BTYPE_BUT_MENU,
+ 0,
+ IFACE_("Follow Path"),
+ 0,
+ y_position -= UI_UNIT_Y,
+ menu_width,
+ UI_UNIT_Y,
+ NULL,
+ 0.0,
+ 0.0,
+ 0,
+ PAR_FOLLOW,
+ "");
+
+ uiDefBut(block,
+ UI_BTYPE_BUT_MENU,
+ 0,
+ IFACE_("Path Constraint"),
+ 0,
+ y_position -= UI_UNIT_Y,
+ menu_width,
+ UI_UNIT_Y,
+ NULL,
+ 0.0,
+ 0.0,
+ 0,
+ PAR_PATH_CONST,
+ "");
+ }
+ else if (drag_data->type == OB_LATTICE) {
+ uiDefBut(block,
+ UI_BTYPE_BUT_MENU,
+ 0,
+ IFACE_("Lattice Deform"),
+ 0,
+ y_position -= UI_UNIT_Y,
+ menu_width,
+ UI_UNIT_Y,
+ NULL,
+ 0.0,
+ 0.0,
+ 0,
+ PAR_LATTICE,
+ "");
+ }
+
+ UI_block_bounds_set_popup(block, 6, (const int[2]){0, 0});
+
+ return block;
}
static int parent_drop_invoke(bContext *C, wmOperator *op, const wmEvent *event)
{
- Main *bmain = CTX_data_main(C);
- SpaceOutliner *soops = CTX_wm_space_outliner(C);
TreeElement *te = outliner_drop_find(C, event);
TreeStoreElem *tselem = te ? TREESTORE(te) : NULL;
@@ -379,119 +597,26 @@ static int parent_drop_invoke(bContext *C, wmOperator *op, const wmEvent *event)
return OPERATOR_CANCELLED;
}
- char childname[MAX_NAME];
- char parname[MAX_NAME];
- STRNCPY(childname, ob->id.name + 2);
- STRNCPY(parname, par->id.name + 2);
- RNA_string_set(op->ptr, "child", childname);
- RNA_string_set(op->ptr, "parent", parname);
-
- Scene *scene = (Scene *)outliner_search_back(soops, te, ID_SCE);
-
- if (scene == NULL) {
- /* currently outlier organized in a way, that if there's no parent scene
- * element for object it means that all displayed objects belong to
- * active scene and parenting them is allowed (sergey)
- */
-
- scene = CTX_data_scene(C);
+ if (event->custom != EVT_DATA_DRAGDROP) {
+ return OPERATOR_CANCELLED;
}
- /* Temporary: Only do object parenting */
- if (true) {
- if (event->custom != EVT_DATA_DRAGDROP) {
- return OPERATOR_CANCELLED;
- }
-
- bool parent_set = false;
- int partype = 0;
- ListBase *lb = event->customdata;
- wmDrag *drag = lb->first;
-
- for (wmDragID *drag_id = drag->ids.first; drag_id; drag_id = drag_id->next) {
- if (GS(drag_id->id->name) == ID_OB) {
- Object *object = (Object *)drag_id->id;
-
- if (ED_object_parent_set(
- op->reports, C, scene, object, par, partype, false, false, NULL)) {
- parent_set = true;
- }
- }
- }
+ ListBase *lb = event->customdata;
+ wmDrag *drag = lb->first;
- if (parent_set) {
- DEG_relations_tag_update(bmain);
- WM_event_add_notifier(C, NC_OBJECT | ND_TRANSFORM, NULL);
- WM_event_add_notifier(C, NC_OBJECT | ND_PARENT, NULL);
- }
+ if (par->type != OB_ARMATURE && par->type != OB_CURVE && par->type != OB_LATTICE) {
+ parent_drop_set_parents(C, op, drag->ids.first, par, PAR_OBJECT);
}
else {
- /* Menu creation */
- wmOperatorType *ot = WM_operatortype_find("OUTLINER_OT_parent_drop", false);
- uiPopupMenu *pup = UI_popup_menu_begin(C, IFACE_("Set Parent To"), ICON_NONE);
- uiLayout *layout = UI_popup_menu_layout(pup);
- PointerRNA ptr;
-
- /* Cannot use uiItemEnumO()... have multiple properties to set. */
- uiItemFullO_ptr(layout, ot, IFACE_("Object"), 0, NULL, WM_OP_EXEC_DEFAULT, 0, &ptr);
- RNA_string_set(&ptr, "parent", parname);
- RNA_string_set(&ptr, "child", childname);
- RNA_enum_set(&ptr, "type", PAR_OBJECT);
-
- /* par beco
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list