[Bf-blender-cvs] [f12a66817d0] modifier-panels-ui: Implement expansion saving, drag drop for constraints

Hans Goudey noreply at git.blender.org
Sun Apr 19 19:44:43 CEST 2020


Commit: f12a66817d08b45cb7c29ee03459e2e0754b48e6
Author: Hans Goudey
Date:   Sun Apr 19 12:44:35 2020 -0500
Branches: modifier-panels-ui
https://developer.blender.org/rBf12a66817d08b45cb7c29ee03459e2e0754b48e6

Implement expansion saving, drag drop for constraints

The move constraint to index operator still needs a proper poll function.

===================================================================

M	source/blender/blenkernel/intern/constraint.c
M	source/blender/editors/interface/interface_templates.c
M	source/blender/editors/object/object_constraint.c
M	source/blender/editors/object/object_intern.h
M	source/blender/editors/object/object_ops.c
M	source/blender/makesdna/DNA_constraint_types.h
M	source/blender/makesrna/intern/rna_constraint.c

===================================================================

diff --git a/source/blender/blenkernel/intern/constraint.c b/source/blender/blenkernel/intern/constraint.c
index 099fdacf401..132b72b3e60 100644
--- a/source/blender/blenkernel/intern/constraint.c
+++ b/source/blender/blenkernel/intern/constraint.c
@@ -5251,6 +5251,10 @@ static bConstraint *add_new_constraint_internal(const char *name, short type)
   con->flag |= CONSTRAINT_EXPAND | CONSTRAINT_OVERRIDE_LIBRARY_LOCAL;
   con->enforce = 1.0f;
 
+  /* Only open the main panel when constraints are created, not the subpanels.
+   * Note: This can be overriden for individual constraint types. */
+  con->ui_expand_flag = 1;
+
   /* Determine a basic name, and info */
   if (cti) {
     /* initialize constraint data */
diff --git a/source/blender/editors/interface/interface_templates.c b/source/blender/editors/interface/interface_templates.c
index 771fc21f97f..27ef2265599 100644
--- a/source/blender/editors/interface/interface_templates.c
+++ b/source/blender/editors/interface/interface_templates.c
@@ -1905,6 +1905,49 @@ void uiTemplateModifiers(uiLayout *UNUSED(layout), bContext *C)
  *  Template for building the panel layout for the active object or bone's constraints.
  * \{ */
 
+/**
+ * Move a constraint to the index it's moved to after a drag and drop.
+ */
+static void constraint_reorder(bContext *C, Panel *panel, int new_index)
+{
+  Object *ob = CTX_data_active_object(C);
+  ListBase *lb = get_active_constraints(ob);
+  bool constraint_from_bone = false;
+  if (ob->mode & OB_MODE_POSE) {
+    bPoseChannel *pchan;
+    pchan = BKE_pose_channel_active(ob);
+    if (pchan) {
+      constraint_from_bone = true;
+    }
+  }
+
+  bConstraint *con = BLI_findlink(lb, panel->runtime.list_index);
+  PointerRNA props_ptr;
+  wmOperatorType *ot = WM_operatortype_find("CONSTRAINT_OT_move_to_index", false);
+  WM_operator_properties_create_ptr(&props_ptr, ot);
+  RNA_string_set(&props_ptr, "constraint", con->name);
+  RNA_int_set(&props_ptr, "index", new_index);
+  RNA_enum_set(&props_ptr, "owner", constraint_from_bone ? 1 : 0);
+  WM_operator_name_call_ptr(C, ot, WM_OP_INVOKE_DEFAULT, &props_ptr);
+  WM_operator_properties_free(&props_ptr);
+}
+
+static short get_constraint_expand_flag(const bContext *C, Panel *panel)
+{
+  Object *ob = CTX_data_active_object(C);
+  ListBase *lb = get_active_constraints(ob);
+  bConstraint *con = BLI_findlink(lb, panel->runtime.list_index);
+  return con->ui_expand_flag;
+}
+
+static void set_constraint_expand_flag(const bContext *C, Panel *panel, short expand_flag)
+{
+  Object *ob = CTX_data_active_object(C);
+  ListBase *lb = get_active_constraints(ob);
+  bConstraint *con = BLI_findlink(lb, panel->runtime.list_index);
+  con->ui_expand_flag = expand_flag;
+}
+
 #define CONSTRAINT_TYPE_PANEL_PREFIX "OBJECT_PT_"
 static PanelType *panel_type_from_constraint_type(ARegion *region, eBConstraint_Types type)
 {
@@ -1974,6 +2017,12 @@ void uiTemplateConstraints(uiLayout *UNUSED(layout), bContext *C)
       BLI_assert(panel_type != NULL);
 
       Panel *new_panel = UI_panel_add_recreate(sa, region, &region->panels, panel_type, i);
+
+      /* Set the list panel functionality function pointers since we don't do it with python. */
+      new_panel->type->set_list_data_expand_flag = set_constraint_expand_flag;
+      new_panel->type->get_list_data_expand_flag = get_constraint_expand_flag;
+      new_panel->type->reorder = constraint_reorder;
+
       UI_panel_set_expand_from_list_data(C, new_panel);
     }
   }
@@ -2679,19 +2728,6 @@ static void draw_constraint_header(uiLayout *layout, Object *ob, bConstraint *co
 
     uiLayoutSetOperatorContext(layout, WM_OP_INVOKE_DEFAULT);
 
-    /* up/down */
-    if (show_upbut || show_downbut) {
-      UI_block_align_begin(block);
-      if (show_upbut) {
-        uiItemO(layout, "", ICON_TRIA_UP, "CONSTRAINT_OT_move_up");
-      }
-
-      if (show_downbut) {
-        uiItemO(layout, "", ICON_TRIA_DOWN, "CONSTRAINT_OT_move_down");
-      }
-      UI_block_align_end(block);
-    }
-
     /* Close 'button' - emboss calls here disable drawing of 'button' behind X */
     UI_block_emboss_set(block, UI_EMBOSS_NONE);
     uiItemO(layout, "", ICON_X, "CONSTRAINT_OT_delete");
diff --git a/source/blender/editors/object/object_constraint.c b/source/blender/editors/object/object_constraint.c
index ba641fb2a39..fcf8a8dc2fe 100644
--- a/source/blender/editors/object/object_constraint.c
+++ b/source/blender/editors/object/object_constraint.c
@@ -1559,6 +1559,79 @@ void CONSTRAINT_OT_move_up(wmOperatorType *ot)
 
 /** \} */
 
+/* ------------------------------------------------------------------- */
+/** \name Move Constraint To Index Operator
+ * \{ */
+
+/* HANS-TODO: Implement poll function for constraint moving. The standard constraint function
+ * #edit_constraint_poll checks with #CTX_data_pointer_get_type, so I need to set that properly.
+ *
+ * Needed for modifiers as well. */
+static bool constraint_move_to_index_poll(bContext *C)
+{
+  return true;
+}
+
+static int constraint_move_to_index_exec(bContext *C, wmOperator *op)
+{
+  Object *ob = ED_object_active_context(C);
+  bConstraint *con = edit_constraint_property_get(op, ob, 0);
+  int index = RNA_int_get(op->ptr, "index");
+
+  if (con) {
+    ListBase *conlist = get_constraint_lb(ob, con, NULL);
+    int current_index = BLI_findindex(conlist, con);
+
+    BLI_listbase_link_move(conlist, con, index - current_index);
+
+    WM_event_add_notifier(C, NC_OBJECT | ND_CONSTRAINT, ob);
+
+    return OPERATOR_FINISHED;
+  }
+
+  return OPERATOR_CANCELLED;
+}
+
+static int constraint_move_to_index_invoke(bContext *C,
+                                           wmOperator *op,
+                                           const wmEvent *UNUSED(event))
+{
+  if (edit_constraint_invoke_properties(C, op)) {
+    return constraint_move_to_index_exec(C, op);
+  }
+  else {
+    return OPERATOR_CANCELLED;
+  }
+}
+
+void CONSTRAINT_OT_move_to_index(wmOperatorType *ot)
+{
+  /* identifiers */
+  ot->name = "Move Constraint To Index";
+  ot->idname = "CONSTRAINT_OT_move_to_index";
+  ot->description = "Move constraint to an index in the stack";
+
+  /* callbacks */
+  ot->exec = constraint_move_to_index_exec;
+  ot->invoke = constraint_move_to_index_invoke;
+  ot->poll = constraint_move_to_index_poll;
+
+  /* flags */
+  ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
+  edit_constraint_properties(ot);
+  RNA_def_int(ot->srna,
+              "index",
+              0,
+              0,
+              INT_MAX,
+              "Index",
+              "The index to move the constraint to",
+              0,
+              INT_MAX);
+}
+
+/** \} */
+
 /* ------------------------------------------------------------------- */
 /** \name Clear Pose Constraints Operator
  * \{ */
diff --git a/source/blender/editors/object/object_intern.h b/source/blender/editors/object/object_intern.h
index 41cd4fb010e..f04291939e8 100644
--- a/source/blender/editors/object/object_intern.h
+++ b/source/blender/editors/object/object_intern.h
@@ -219,6 +219,7 @@ void CONSTRAINT_OT_delete(struct wmOperatorType *ot);
 
 void CONSTRAINT_OT_move_up(struct wmOperatorType *ot);
 void CONSTRAINT_OT_move_down(struct wmOperatorType *ot);
+void CONSTRAINT_OT_move_to_index(struct wmOperatorType *ot);
 
 void CONSTRAINT_OT_stretchto_reset(struct wmOperatorType *ot);
 void CONSTRAINT_OT_limitdistance_reset(struct wmOperatorType *ot);
diff --git a/source/blender/editors/object/object_ops.c b/source/blender/editors/object/object_ops.c
index 5b168e69d90..0ba60d6f960 100644
--- a/source/blender/editors/object/object_ops.c
+++ b/source/blender/editors/object/object_ops.c
@@ -178,6 +178,7 @@ void ED_operatortypes_object(void)
   WM_operatortype_append(POSE_OT_ik_clear);
   WM_operatortype_append(CONSTRAINT_OT_delete);
   WM_operatortype_append(CONSTRAINT_OT_move_up);
+  WM_operatortype_append(CONSTRAINT_OT_move_to_index);
   WM_operatortype_append(CONSTRAINT_OT_move_down);
   WM_operatortype_append(CONSTRAINT_OT_stretchto_reset);
   WM_operatortype_append(CONSTRAINT_OT_limitdistance_reset);
diff --git a/source/blender/makesdna/DNA_constraint_types.h b/source/blender/makesdna/DNA_constraint_types.h
index 9efd2116601..9209dd698a5 100644
--- a/source/blender/makesdna/DNA_constraint_types.h
+++ b/source/blender/makesdna/DNA_constraint_types.h
@@ -61,7 +61,8 @@ typedef struct bConstraint {
   /** Constraint name, MAX_NAME. */
   char name[64];
 
-  char _pad[2];
+  /* Flag for panel and subpanel closed / open state in the UI. */
+  short ui_expand_flag;
 
   /** Amount of influence exherted by constraint (0.0-1.0). */
   float enforce;
@@ -689,7 +690,7 @@ typedef enum eBConstraint_Types {
 /* flag 0x20 (1 << 5) was used to indicate that a constraint was evaluated
  *                  using a 'local' hack for posebones only. */
 typedef enum eBConstraint_Flags {
-  /* expand for UI */
+  /* expand for UI. Deprecated */
   CONSTRAINT_EXPAND = (1 << 0),
   /* pre-check for illegal object name or bone name */
   CONSTRAINT_DISABLE = (1 << 2),
diff --git a/source/blender/makesrna/intern/rna_constraint.c b/source/blender/makesrna/intern/rna_constraint.c
index dc0cde953f4..04a859e6543 100644
--- a/source/blender/makesrna/intern/rna_constraint.c
+++ b/source/blender/makesrna/intern/rna_constraint.c
@@ -3263,12 +3263,12 @@ void RNA_def_constraint(BlenderRNA *brna)
   RNA_def_property_update(prop, NC_OBJECT | ND_CONSTRAINT, "rna_Constraint_update");
   RNA_def_property_ui_icon(prop, ICON_HIDE_OFF, -1);
 
-  prop = RNA_def_property(srna, "show_expanded", PROP_BOOLEAN, PROP_NONE);
-  RNA_def_property_flag(prop, PROP_NO_DEG_UPDATE);
-  RNA_def_property_boolean_sdna(prop, NULL, "flag", CONSTRAINT_EXPAND);
-  RNA_def_property_override_flag(prop, PROPOVERRIDE_OVERRIDABLE_LIBRARY);
-  RNA_def_property_ui_text(prop, "Expanded", "Constraint's panel is expanded in UI");
-  RNA_def_property_ui_icon(prop, ICON_DISCLOSURE_TRI_RIGHT, 1);
+  // prop = RNA_def_property(srna, "show_expanded", PROP_BOOLEAN, PROP_NONE);
+  // RNA_def_property_flag(prop, PROP_NO_DEG_UPDATE);
+  // RNA_def_property_boolean_sdna(prop, NULL, "flag", CONSTRAINT_EXPAND);
+  // RNA_def_property_override_flag(prop, PROPOVERRIDE_OVERRIDABLE_LIBRARY);
+  // RNA_def_prope

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list