[Bf-blender-cvs] [b292dcb2ecb] temp-soc-2019-outliner-sync: Outliner: Use entire selection for parenting
Nathan Craddock
noreply at git.blender.org
Sat Aug 10 05:04:15 CEST 2019
Commit: b292dcb2ecb0962e49e75f684cf877a28cfd04d8
Author: Nathan Craddock
Date: Fri Aug 9 13:55:58 2019 -0600
Branches: temp-soc-2019-outliner-sync
https://developer.blender.org/rBb292dcb2ecb0962e49e75f684cf877a28cfd04d8
Outliner: Use entire selection for parenting
Set and clear parents for all elements in the selection in the outliner.
This also rewrites the popup menu for setting parents to armatures,
curves, and lattices to support multiple objects, though it removes
the operator reports for failures in those cases.
===================================================================
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 d8276aa2bbc..60af13802b7 100644
--- a/source/blender/editors/space_outliner/outliner_dragdrop.c
+++ b/source/blender/editors/space_outliner/outliner_dragdrop.c
@@ -326,38 +326,255 @@ 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, ReportList *reports, 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)) {
+ BKE_report(reports, RPT_INFO, "Can't edit library linked object");
+ continue;
+ }
- return OPERATOR_FINISHED;
+ if (ED_object_parent_set(
+ reports, 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 {
+ 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, NULL, 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;
@@ -374,104 +591,26 @@ static int parent_drop_invoke(bContext *C, wmOperator *op, const wmEvent *event)
if (ob == par) {
return OPERATOR_CANCELLED;
}
- if (ID_IS_LINKED(ob)) {
- BKE_report(op->reports, RPT_INFO, "Can't edit library linked object");
+
+ if (event->custom != EVT_DATA_DRAGDROP) {
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);
- }
+ ListBase *lb = event->customdata;
+ wmDrag *drag = lb->first;
- if ((par->type != OB_ARMATURE) && (par->type != OB_CURVE) && (par->type != OB_LATTICE)) {
- int partype = 0;
- if (ED_object_parent_set(op->reports, C, scene, ob, par, partype, false, false, NULL)) {
- 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->reports, 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 becomes parent, make the associated menus */
- if (par->type == OB_ARMATURE) {
- uiItemFullO_ptr(layout, ot, IFACE_("Armature Deform"), 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_ARMATURE);
-
- uiItemFullO_ptr(
- layout,
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list