Blender  V2.93
object_constraint.c
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software Foundation,
14  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15  *
16  * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
17  * All rights reserved.
18  */
19 
24 #include <stdio.h>
25 #include <string.h>
26 
27 #include "MEM_guardedalloc.h"
28 
29 #include "BLI_blenlib.h"
30 #include "BLI_dynstr.h"
31 #include "BLI_math.h"
32 #include "BLI_utildefines.h"
33 
34 #include "BLT_translation.h"
35 
36 #include "DNA_anim_types.h"
37 #include "DNA_armature_types.h"
38 #include "DNA_constraint_types.h"
39 #include "DNA_curve_types.h"
40 #include "DNA_object_types.h"
41 #include "DNA_scene_types.h"
42 #include "DNA_text_types.h"
43 
44 #include "BIK_api.h"
45 #include "BKE_action.h"
46 #include "BKE_armature.h"
47 #include "BKE_constraint.h"
48 #include "BKE_context.h"
49 #include "BKE_fcurve.h"
50 #include "BKE_main.h"
51 #include "BKE_object.h"
52 #include "BKE_report.h"
53 #include "BKE_tracking.h"
54 
55 #include "DEG_depsgraph.h"
56 #include "DEG_depsgraph_build.h"
57 #include "DEG_depsgraph_query.h"
58 
59 #ifdef WITH_PYTHON
60 # include "BPY_extern.h"
61 #endif
62 
63 #include "WM_api.h"
64 #include "WM_types.h"
65 
66 #include "RNA_access.h"
67 #include "RNA_define.h"
68 #include "RNA_enum_types.h"
69 
70 #include "ED_keyframing.h"
71 #include "ED_object.h"
72 #include "ED_screen.h"
73 
74 #include "UI_interface.h"
75 #include "UI_resources.h"
76 
77 #include "object_intern.h"
78 
79 /* ------------------------------------------------------------------- */
88 {
89  if (ob == NULL) {
90  return NULL;
91  }
92 
93  if (ob->mode & OB_MODE_POSE) {
94  bPoseChannel *pchan;
95 
96  pchan = BKE_pose_channel_active(ob);
97  if (pchan) {
98  return &pchan->constraints;
99  }
100  }
101  else {
102  return &ob->constraints;
103  }
104 
105  return NULL;
106 }
107 
113 {
114  bPoseChannel *pose_bone = CTX_data_pointer_get(C, "pose_bone").data;
115  if (pose_bone == NULL) {
116  pose_bone = CTX_data_pointer_get(C, "active_pose_bone").data;
117  if (pose_bone == NULL) {
118  return NULL;
119  }
120  }
121 
122  return &pose_bone->constraints;
123 }
124 
125 /* Find the list that a given constraint belongs to,
126  * and/or also get the posechannel this is from (if applicable) */
128  bConstraint *con,
129  bPoseChannel **r_pchan)
130 {
131  if (r_pchan) {
132  *r_pchan = NULL;
133  }
134 
135  if (ELEM(NULL, ob, con)) {
136  return NULL;
137  }
138 
139  /* try object constraints first */
140  if ((BLI_findindex(&ob->constraints, con) != -1)) {
141  return &ob->constraints;
142  }
143 
144  /* if armature, try pose bones too */
145  if (ob->pose) {
146  bPoseChannel *pchan;
147 
148  /* try each bone in order
149  * NOTE: it's not possible to directly look up the active bone yet, so this will have to do
150  */
151  for (pchan = ob->pose->chanbase.first; pchan; pchan = pchan->next) {
152  if ((BLI_findindex(&pchan->constraints, con) != -1)) {
153 
154  if (r_pchan) {
155  *r_pchan = pchan;
156  }
157 
158  return &pchan->constraints;
159  }
160  }
161  }
162 
163  /* done */
164  return NULL;
165 }
166 
167 /* single constraint */
169 {
171 }
172 
175 /* ------------------------------------------------------------------- */
179 #ifdef WITH_PYTHON
180 
181 /* this callback sets the text-file to be used for selected menu item */
182 static void validate_pyconstraint_cb(Main *bmain, void *arg1, void *arg2)
183 {
184  bPythonConstraint *data = arg1;
185  Text *text = NULL;
186  int index = *((int *)arg2);
187  int i;
188 
189  /* exception for no script */
190  if (index) {
191  /* innovative use of a for...loop to search */
192  for (text = bmain->texts.first, i = 1; text && index != i; i++, text = text->id.next) {
193  /* pass */
194  }
195  }
196  data->text = text;
197 }
198 
199 /* this returns a string for the list of usable pyconstraint script names */
200 static char *buildmenu_pyconstraints(Main *bmain, Text *con_text, int *pyconindex)
201 {
202  DynStr *pupds = BLI_dynstr_new();
203  Text *text;
204  char *str;
205  char buf[64];
206  int i;
207 
208  /* add title first */
209  sprintf(buf, "Scripts: %%t|[None]%%x0|");
210  BLI_dynstr_append(pupds, buf);
211 
212  /* init active-index first */
213  if (con_text == NULL) {
214  *pyconindex = 0;
215  }
216 
217  /* loop through markers, adding them */
218  for (text = bmain->texts.first, i = 1; text; i++, text = text->id.next) {
219  /* this is important to ensure that right script is shown as active */
220  if (text == con_text) {
221  *pyconindex = i;
222  }
223 
224  /* only include valid pyconstraint scripts */
225  if (BPY_is_pyconstraint(text)) {
226  BLI_dynstr_append(pupds, text->id.name + 2);
227 
228  sprintf(buf, "%%x%d", i);
229  BLI_dynstr_append(pupds, buf);
230 
231  if (text->id.next) {
232  BLI_dynstr_append(pupds, "|");
233  }
234  }
235  }
236 
237  /* convert to normal MEM_malloc'd string */
238  str = BLI_dynstr_get_cstring(pupds);
239  BLI_dynstr_free(pupds);
240 
241  return str;
242 }
243 #endif /* WITH_PYTHON */
244 
245 #if 0 /* UNUSED, until pyconstraints are added back. */
246 /* this callback gets called when the 'refresh' button of a pyconstraint gets pressed */
247 static void update_pyconstraint_cb(void *arg1, void *arg2)
248 {
249 # ifndef WITH_PYTHON
250  (void)arg1; /* unused */
251  (void)arg2; /* unused */
252 # else
253  Object *owner = (Object *)arg1;
254  bConstraint *con = (bConstraint *)arg2;
255  if (owner && con) {
256  BPY_pyconstraint_update(owner, con);
257  }
258 # endif
259 }
260 #endif /* UNUSED */
261 
264 /* ------------------------------------------------------------------- */
268 /* helper function for add_constriant - sets the last target for the active constraint */
270  Object *target,
271  const char subtarget[],
272  int index)
273 {
275  ListBase targets = {NULL, NULL};
276  bConstraintTarget *ct;
277  int num_targets, i;
278 
279  if (cti && cti->get_constraint_targets) {
280  cti->get_constraint_targets(con, &targets);
281  num_targets = BLI_listbase_count(&targets);
282 
283  if (index < 0) {
284  if (abs(index) < num_targets) {
285  index = num_targets - abs(index);
286  }
287  else {
288  index = num_targets - 1;
289  }
290  }
291  else if (index >= num_targets) {
292  index = num_targets - 1;
293  }
294 
295  for (ct = targets.first, i = 0; ct; ct = ct->next, i++) {
296  if (i == index) {
297  ct->tar = target;
298  BLI_strncpy(ct->subtarget, subtarget, sizeof(ct->subtarget));
299  break;
300  }
301  }
302 
303  if (cti->flush_constraint_targets) {
304  cti->flush_constraint_targets(con, &targets, 0);
305  }
306  }
307 }
308 
311 /* ------------------------------------------------------------------- */
315 static void test_constraint(
316  Main *bmain, Object *owner, bPoseChannel *pchan, bConstraint *con, int type)
317 {
319  ListBase targets = {NULL, NULL};
320  bConstraintTarget *ct;
321  bool check_targets = true;
322 
323  /* clear disabled-flag first */
324  con->flag &= ~CONSTRAINT_DISABLE;
325 
326  if (con->type == CONSTRAINT_TYPE_KINEMATIC) {
328 
329  /* bad: we need a separate set of checks here as poletarget is
330  * optional... otherwise poletarget must exist too or else
331  * the constraint is deemed invalid
332  */
333  /* default IK check ... */
334  if (BKE_object_exists_check(bmain, data->tar) == 0) {
335  data->tar = NULL;
336  con->flag |= CONSTRAINT_DISABLE;
337  }
338  else if (data->tar == owner) {
339  if (!BKE_armature_find_bone_name(BKE_armature_from_object(owner), data->subtarget)) {
340  con->flag |= CONSTRAINT_DISABLE;
341  }
342  }
343 
344  if (data->poletar) {
345  if (BKE_object_exists_check(bmain, data->poletar) == 0) {
346  data->poletar = NULL;
347  con->flag |= CONSTRAINT_DISABLE;
348  }
349  else if (data->poletar == owner) {
350  if (!BKE_armature_find_bone_name(BKE_armature_from_object(owner), data->polesubtarget)) {
351  con->flag |= CONSTRAINT_DISABLE;
352  }
353  }
354  }
355  /* ... can be overwritten here */
356  BIK_test_constraint(owner, con);
357  /* targets have already been checked for this */
358  check_targets = false;
359  }
360  else if (con->type == CONSTRAINT_TYPE_PIVOT) {
361  bPivotConstraint *data = con->data;
362 
363  /* target doesn't have to exist, but if it is non-null, it must exist! */
364  if (data->tar && BKE_object_exists_check(bmain, data->tar) == 0) {
365  data->tar = NULL;
366  con->flag |= CONSTRAINT_DISABLE;
367  }
368  else if (data->tar == owner) {
369  if (!BKE_armature_find_bone_name(BKE_armature_from_object(owner), data->subtarget)) {
370  con->flag |= CONSTRAINT_DISABLE;
371  }
372  }
373 
374  /* targets have already been checked for this */
375  check_targets = false;
376  }
377  else if (con->type == CONSTRAINT_TYPE_ACTION) {
378  bActionConstraint *data = con->data;
379 
380  /* validate action */
381  if (data->act == NULL) {
382  /* must have action */
383  con->flag |= CONSTRAINT_DISABLE;
384  }
385  else if (data->act->idroot != ID_OB) {
386  /* only object-rooted actions can be used */
387  data->act = NULL;
388  con->flag |= CONSTRAINT_DISABLE;
389  }
390 
391  /* Skip target checking if we're not using it */
392  if (data->flag & ACTCON_USE_EVAL_TIME) {
393  check_targets = false;
394  }
395  }
396  else if (con->type == CONSTRAINT_TYPE_FOLLOWPATH) {
398 
399  /* don't allow track/up axes to be the same */
400  if (data->upflag == data->trackflag) {
401  con->flag |= CONSTRAINT_DISABLE;
402  }
403  if (data->upflag + 3 == data->trackflag) {
404  con->flag |= CONSTRAINT_DISABLE;
405  }
406  }
407  else if (con->type == CONSTRAINT_TYPE_TRACKTO) {
408  bTrackToConstraint *data = con->data;
409 
410  /* don't allow track/up axes to be the same */
411  if (data->reserved2 == data->reserved1) {
412  con->flag |= CONSTRAINT_DISABLE;
413  }
414  if (data->reserved2 + 3 == data->reserved1) {
415  con->flag |= CONSTRAINT_DISABLE;
416  }
417  }
418  else if (con->type == CONSTRAINT_TYPE_LOCKTRACK) {
420 
421  if (data->lockflag == data->trackflag) {
422  con->flag |= CONSTRAINT_DISABLE;
423  }
424  if (data->lockflag + 3 == data->trackflag) {
425  con->flag |= CONSTRAINT_DISABLE;
426  }
427  }
428  else if (con->type == CONSTRAINT_TYPE_SPLINEIK) {
429  bSplineIKConstraint *data = con->data;
430 
431  /* if the number of points does not match the amount required by the chain length,
432  * free the points array and request a rebind...
433  */
434  if ((data->points == NULL) || (data->numpoints != data->chainlen + 1)) {
435  MEM_SAFE_FREE(data->points);
436  data->numpoints = 0;
437 
438  /* clear the bound flag, forcing a rebind next time this is evaluated */
440  }
441  }
442  else if (con->type == CONSTRAINT_TYPE_FOLLOWTRACK) {
444 
445  if ((data->flag & CAMERASOLVER_ACTIVECLIP) == 0) {
446  if (data->clip != NULL && data->track[0]) {
447  MovieTracking *tracking = &data->clip->tracking;
448  MovieTrackingObject *tracking_object;
449 
450  if (data->object[0]) {
451  tracking_object = BKE_tracking_object_get_named(tracking, data->object);
452  }
453  else {
454  tracking_object = BKE_tracking_object_get_camera(tracking);
455  }
456 
457  if (!tracking_object) {
458  con->flag |= CONSTRAINT_DISABLE;
459  }
460  else {
461  if (!BKE_tracking_track_get_named(tracking, tracking_object, data->track)) {
462  con->flag |= CONSTRAINT_DISABLE;
463  }
464  }
465  }
466  else {
467  con->flag |= CONSTRAINT_DISABLE;
468  }
469  }
470  }
471  else if (con->type == CONSTRAINT_TYPE_CAMERASOLVER) {
473 
474  if ((data->flag & CAMERASOLVER_ACTIVECLIP) == 0 && (data->clip == NULL)) {
475  con->flag |= CONSTRAINT_DISABLE;
476  }
477  }
478  else if (con->type == CONSTRAINT_TYPE_OBJECTSOLVER) {
480 
481  if ((data->flag & CAMERASOLVER_ACTIVECLIP) == 0 && (data->clip == NULL)) {
482  con->flag |= CONSTRAINT_DISABLE;
483  }
484  }
485  else if (con->type == CONSTRAINT_TYPE_TRANSFORM_CACHE) {
487 
488  if ((data->cache_file == NULL) || (data->object_path[0] == '\0')) {
489  con->flag |= CONSTRAINT_DISABLE;
490  }
491  }
492 
493  /* Check targets for constraints */
494  if (check_targets && cti && cti->get_constraint_targets) {
495  cti->get_constraint_targets(con, &targets);
496 
497  /* constraints with empty target list that actually require targets */
498  if (!targets.first && ELEM(con->type, CONSTRAINT_TYPE_ARMATURE)) {
499  con->flag |= CONSTRAINT_DISABLE;
500  }
501 
502  /* disable and clear constraints targets that are incorrect */
503  for (ct = targets.first; ct; ct = ct->next) {
504  /* general validity checks (for those constraints that need this) */
505  if (BKE_object_exists_check(bmain, ct->tar) == 0) {
506  /* object doesn't exist, but constraint requires target */
507  ct->tar = NULL;
508  con->flag |= CONSTRAINT_DISABLE;
509  }
510  else if (ct->tar == owner) {
511  if (type == CONSTRAINT_OBTYPE_BONE) {
513  /* bone must exist in armature... */
514  /* TODO: clear subtarget? */
515  con->flag |= CONSTRAINT_DISABLE;
516  }
517  else if (STREQ(pchan->name, ct->subtarget)) {
518  /* cannot target self */
519  ct->subtarget[0] = '\0';
520  con->flag |= CONSTRAINT_DISABLE;
521  }
522  }
523  else {
524  /* cannot use self as target */
525  ct->tar = NULL;
526  con->flag |= CONSTRAINT_DISABLE;
527  }
528  }
529 
530  /* target checks for specific constraints */
531  if (ELEM(con->type,
535  if (ct->tar) {
536  /* The object type check is only needed here in case we have a placeholder
537  * object assigned (because the library containing the curve is missing).
538  *
539  * In other cases it should be impossible to have a type mismatch.
540  */
541  if (ct->tar->type != OB_CURVE) {
542  con->flag |= CONSTRAINT_DISABLE;
543  }
544  else {
545  Curve *cu = ct->tar->data;
546 
547  /* auto-set 'Path' setting on curve so this works */
548  cu->flag |= CU_PATH;
549  }
550  }
551  }
552  else if (con->type == CONSTRAINT_TYPE_ARMATURE) {
553  if (ct->tar) {
554  /* The object type check is only needed here in case we have a placeholder
555  * object assigned (because the library containing the armature is missing).
556  *
557  * In other cases it should be impossible to have a type mismatch.
558  */
559  if (ct->tar->type != OB_ARMATURE) {
560  con->flag |= CONSTRAINT_DISABLE;
561  }
563  ct->subtarget)) {
564  /* bone must exist in armature... */
565  con->flag |= CONSTRAINT_DISABLE;
566  }
567  }
568  }
569  }
570 
571  /* free any temporary targets */
572  if (cti->flush_constraint_targets) {
573  cti->flush_constraint_targets(con, &targets, 0);
574  }
575  }
576 }
577 
578 static int constraint_type_get(Object *owner, bPoseChannel *pchan)
579 {
580  int type;
581  /* Check parents */
582  if (pchan) {
583  switch (owner->type) {
584  case OB_ARMATURE:
586  break;
587  default:
589  break;
590  }
591  }
592  else {
594  }
595  return type;
596 }
597 
598 /* checks validity of object pointers, and NULLs,
599  * if Bone doesn't exist it sets the CONSTRAINT_DISABLE flag.
600  */
601 static void test_constraints(Main *bmain, Object *ob, bPoseChannel *pchan)
602 {
603  bConstraint *curcon;
604  ListBase *conlist = NULL;
605  int type;
606 
607  if (ob == NULL) {
608  return;
609  }
610 
611  type = constraint_type_get(ob, pchan);
612 
613  /* Get the constraint list for this object */
614  switch (type) {
616  conlist = &ob->constraints;
617  break;
619  conlist = &pchan->constraints;
620  break;
621  }
622 
623  /* Check all constraints - is constraint valid? */
624  if (conlist) {
625  for (curcon = conlist->first; curcon; curcon = curcon->next) {
626  test_constraint(bmain, ob, pchan, curcon, type);
627  }
628  }
629 }
630 
632 {
633  if (ob->constraints.first) {
634  test_constraints(bmain, ob, NULL);
635  }
636 
637  if (ob->type == OB_ARMATURE && ob->pose) {
638  bPoseChannel *pchan;
639 
640  for (pchan = ob->pose->chanbase.first; pchan; pchan = pchan->next) {
641  if (pchan->constraints.first) {
642  test_constraints(bmain, ob, pchan);
643  }
644  }
645  }
646 }
647 
648 static void object_test_constraint(Main *bmain, Object *ob, bConstraint *con)
649 {
650  if (ob->type == OB_ARMATURE && ob->pose) {
651  if (BLI_findindex(&ob->constraints, con) != -1) {
653  }
654  else {
655  bPoseChannel *pchan;
656  for (pchan = ob->pose->chanbase.first; pchan; pchan = pchan->next) {
657  if (BLI_findindex(&pchan->constraints, con) != -1) {
658  test_constraint(bmain, ob, pchan, con, CONSTRAINT_OBTYPE_BONE);
659  break;
660  }
661  }
662  }
663  }
664  else {
666  }
667 }
668 
671 /* ------------------------------------------------------------------- */
675 #define EDIT_CONSTRAINT_OWNER_OBJECT 0
676 #define EDIT_CONSTRAINT_OWNER_BONE 1
677 
680  "OBJECT",
681  0,
682  "Object",
683  "Edit a constraint on the active object"},
684  {EDIT_CONSTRAINT_OWNER_BONE, "BONE", 0, "Bone", "Edit a constraint on the active bone"},
685  {0, NULL, 0, NULL, NULL},
686 };
687 
689  StructRNA *rna_type,
690  const bool is_liboverride_allowed)
691 {
692  PointerRNA ptr = CTX_data_pointer_get_type(C, "constraint", rna_type);
694  bConstraint *con = ptr.data;
695 
696  if (!ob) {
697  CTX_wm_operator_poll_msg_set(C, "Context missing active object");
698  return false;
699  }
700 
701  if (ID_IS_LINKED(ob) || (ptr.owner_id && ID_IS_LINKED(ptr.owner_id))) {
702  CTX_wm_operator_poll_msg_set(C, "Cannot edit library data");
703  return false;
704  }
705 
706  if (!is_liboverride_allowed && BKE_constraint_is_nonlocal_in_liboverride(ob, con)) {
708  C, "Cannot edit constraints coming from linked data in a library override");
709  return false;
710  }
711 
712  return true;
713 }
714 
716 {
718 }
719 
720 /* Used by operators performing actions allowed also on constraints from the overridden linked
721  * object (not only from added 'local' ones). */
723 {
725 }
726 
728 {
729  PropertyRNA *prop;
730  prop = RNA_def_string(
731  ot->srna, "constraint", NULL, MAX_NAME, "Constraint", "Name of the constraint to edit");
733  prop = RNA_def_enum(
734  ot->srna, "owner", constraint_owner_items, 0, "Owner", "The owner of this constraint");
736 }
737 
739 {
741  ot->srna, "report", false, "Report", "Create a notification after the operation");
743 }
744 
746  wmOperator *op,
747  const wmEvent *event,
748  int *r_retval)
749 {
752  bConstraint *con;
753  ListBase *list;
754 
755  if (RNA_struct_property_is_set(op->ptr, "constraint") &&
756  RNA_struct_property_is_set(op->ptr, "owner")) {
757  return true;
758  }
759 
760  if (ptr.data) {
761  con = ptr.data;
762  RNA_string_set(op->ptr, "constraint", con->name);
763 
765 
766  if (&ob->constraints == list) {
768  }
769  else {
771  }
772 
773  return true;
774  }
775 
776  /* Check the custom data of panels under the mouse for a modifier. */
777  if (event != NULL) {
779 
780  if (!(panel_ptr == NULL || RNA_pointer_is_null(panel_ptr))) {
781  if (RNA_struct_is_a(panel_ptr->type, &RNA_Constraint)) {
782  con = panel_ptr->data;
783  RNA_string_set(op->ptr, "constraint", con->name);
785  RNA_enum_set(op->ptr,
786  "owner",
787  (&ob->constraints == list) ? EDIT_CONSTRAINT_OWNER_OBJECT :
789 
790  return true;
791  }
792 
793  BLI_assert(r_retval != NULL); /* We need the return value in this case. */
794  if (r_retval != NULL) {
796  }
797  return false;
798  }
799  }
800 
801  return false;
802 }
803 
805 {
806  char constraint_name[MAX_NAME];
807  int owner = RNA_enum_get(op->ptr, "owner");
808  bConstraint *con;
809  ListBase *list = NULL;
810 
811  RNA_string_get(op->ptr, "constraint", constraint_name);
812 
813  if (owner == EDIT_CONSTRAINT_OWNER_BONE) {
815  }
816  else {
817  list = &ob->constraints;
818  }
819 
820  con = BKE_constraints_find_name(list, constraint_name);
821 #if 0
822  if (G.debug & G_DEBUG) {
823  printf("constraint found = %p, %s\n", (void *)con, (con) ? con->name : "<Not found>");
824  }
825 #endif
826 
827  if (con && (type != 0) && (con->type != type)) {
828  con = NULL;
829  }
830 
831  return con;
832 }
833 
836 /* ------------------------------------------------------------------- */
843 {
844  Main *bmain = CTX_data_main(C);
848 
849  /* despite 3 layers of checks, we may still not be able to find a constraint */
850  if (data == NULL) {
851  return OPERATOR_CANCELLED;
852  }
853 
854  /* just set original length to 0.0, which will cause a reset on next recalc */
855  data->orglength = 0.0f;
856  ED_object_constraint_update(bmain, ob);
857 
859  return OPERATOR_FINISHED;
860 }
861 
862 static int stretchto_reset_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event))
863 {
865  return stretchto_reset_exec(C, op);
866  }
867  return OPERATOR_CANCELLED;
868 }
869 
871 {
872  /* identifiers */
873  ot->name = "Reset Original Length";
874  ot->idname = "CONSTRAINT_OT_stretchto_reset";
875  ot->description = "Reset original length of bone for Stretch To Constraint";
876 
877  /* callbacks */
881 
882  /* flags */
884 
885  /* properties */
887 }
888 
891 /* ------------------------------------------------------------------- */
898 {
899  Main *bmain = CTX_data_main(C);
903 
904  /* despite 3 layers of checks, we may still not be able to find a constraint */
905  if (data == NULL) {
906  return OPERATOR_CANCELLED;
907  }
908 
909  /* just set original length to 0.0, which will cause a reset on next recalc */
910  data->dist = 0.0f;
911  ED_object_constraint_update(bmain, ob);
912 
914  return OPERATOR_FINISHED;
915 }
916 
918 {
920  return limitdistance_reset_exec(C, op);
921  }
922  return OPERATOR_CANCELLED;
923 }
924 
926 {
927  /* identifiers */
928  ot->name = "Reset Distance";
929  ot->idname = "CONSTRAINT_OT_limitdistance_reset";
930  ot->description = "Reset limiting distance for Limit Distance Constraint";
931 
932  /* callbacks */
936 
937  /* flags */
939 
940  /* properties */
942 }
943 
946 /* ------------------------------------------------------------------- */
950 /* Force evaluation so that the 'set inverse' flag is handled.
951  * No-op when the constraint is enabled, as in such cases the evaluation will happen anyway.
952  */
954 {
955  if ((con->flag & (CONSTRAINT_DISABLE | CONSTRAINT_OFF)) == 0) {
956  return;
957  }
958 
961 
962  short flag_backup = con->flag;
965  con->flag = flag_backup;
966 }
967 
968 /* ChildOf Constraint - set inverse callback */
970 {
971  Main *bmain = CTX_data_main(C);
974  bChildOfConstraint *data = (con) ? (bChildOfConstraint *)con->data : NULL;
975 
976  /* despite 3 layers of checks, we may still not be able to find a constraint */
977  if (data == NULL) {
978  printf("DEBUG: Child-Of Set Inverse - object = '%s'\n", (ob) ? ob->id.name + 2 : "<None>");
979  BKE_report(op->reports, RPT_ERROR, "Could not find constraint data for Child-Of Set Inverse");
980  return OPERATOR_CANCELLED;
981  }
982 
983  /* Set a flag to request recalculation on next update. */
984  data->flag |= CHILDOF_SET_INVERSE;
985 
986  /* Force constraint to run, it will perform the recalculation. */
988 
989  ED_object_constraint_update(bmain, ob);
991 
992  return OPERATOR_FINISHED;
993 }
994 
996 {
998  return childof_set_inverse_exec(C, op);
999  }
1000  return OPERATOR_CANCELLED;
1001 }
1002 
1004 {
1005  /* identifiers */
1006  ot->name = "Set Inverse";
1007  ot->idname = "CONSTRAINT_OT_childof_set_inverse";
1008  ot->description = "Set inverse correction for Child Of constraint";
1009 
1010  /* callbacks */
1014 
1015  /* flags */
1017 
1018  /* properties */
1020 }
1021 
1022 /* ChildOf Constraint - clear inverse callback */
1024 {
1025  Main *bmain = CTX_data_main(C);
1028  bChildOfConstraint *data = (con) ? (bChildOfConstraint *)con->data : NULL;
1029 
1030  if (data == NULL) {
1031  BKE_report(op->reports, RPT_ERROR, "Child Of constraint not found");
1032  return OPERATOR_CANCELLED;
1033  }
1034 
1035  /* simply clear the matrix */
1036  unit_m4(data->invmat);
1037 
1038  ED_object_constraint_update(bmain, ob);
1040 
1041  return OPERATOR_FINISHED;
1042 }
1043 
1045 {
1047  return childof_clear_inverse_exec(C, op);
1048  }
1049  return OPERATOR_CANCELLED;
1050 }
1051 
1053 {
1054  /* identifiers */
1055  ot->name = "Clear Inverse";
1056  ot->idname = "CONSTRAINT_OT_childof_clear_inverse";
1057  ot->description = "Clear inverse correction for Child Of constraint";
1058 
1059  /* callbacks */
1063 
1064  /* flags */
1066 
1067  /* properties */
1069 }
1070 
1073 /* ------------------------------------------------------------------- */
1078 {
1079  Main *bmain = CTX_data_main(C);
1083 
1084  bAction *act = NULL;
1085  FCurve *fcu = NULL;
1086  int sfra = RNA_int_get(op->ptr, "frame_start");
1087  int len = RNA_int_get(op->ptr, "length");
1088  float standardRange = 1.0;
1089 
1090  /* nearly impossible sanity check */
1091  if (data == NULL) {
1092  BKE_report(op->reports, RPT_ERROR, "Follow Path constraint not found");
1093  return OPERATOR_CANCELLED;
1094  }
1095 
1096  /* add F-Curve as appropriate */
1097  if (data->tar) {
1098  Curve *cu = (Curve *)data->tar->data;
1099 
1100  if (ELEM(NULL, cu->adt, cu->adt->action) ||
1101  (BKE_fcurve_find(&cu->adt->action->curves, "eval_time", 0) == NULL)) {
1102  /* create F-Curve for path animation */
1103  act = ED_id_action_ensure(bmain, &cu->id);
1104  fcu = ED_action_fcurve_ensure(bmain, act, NULL, NULL, "eval_time", 0);
1105 
1106  /* standard vertical range - 1:1 = 100 frames */
1107  standardRange = 100.0f;
1108  }
1109  else {
1110  /* path anim exists already - abort for now as this may well be what was intended */
1111  BKE_report(op->reports, RPT_WARNING, "Path is already animated");
1112  return OPERATOR_CANCELLED;
1113  }
1114  }
1115  else {
1116  /* animate constraint's "fixed offset" */
1117  PointerRNA ptr;
1118  PropertyRNA *prop;
1119  char *path;
1120 
1121  /* get RNA pointer to constraint's "offset_factor" property - to build RNA path */
1123  prop = RNA_struct_find_property(&ptr, "offset_factor");
1124 
1125  path = RNA_path_from_ID_to_property(&ptr, prop);
1126 
1127  /* create F-Curve for constraint */
1128  act = ED_id_action_ensure(bmain, &ob->id);
1129  fcu = ED_action_fcurve_ensure(bmain, act, NULL, NULL, path, 0);
1130 
1131  /* standard vertical range - 0.0 to 1.0 */
1132  standardRange = 1.0f;
1133 
1134  /* enable "Use Fixed Position" so that animating this has effect */
1135  data->followflag |= FOLLOWPATH_STATIC;
1136 
1137  /* path needs to be freed */
1138  if (path) {
1139  MEM_freeN(path);
1140  }
1141  }
1142 
1143  /* setup dummy 'generator' modifier here to get 1-1 correspondence still working
1144  * and define basic slope of this curve based on the properties
1145  */
1146  if (!fcu->bezt && !fcu->fpt && !fcu->modifiers.first) {
1148  FMod_Generator *gen = fcm->data;
1149 
1150  /* Assume that we have the following equation:
1151  * y = Ax + B
1152  * 1 0 <-- coefficients array indices
1153  */
1154  float A = standardRange / (float)(len);
1155  float B = (float)(-sfra) * A;
1156 
1157  gen->coefficients[1] = A;
1158  gen->coefficients[0] = B;
1159  }
1160 
1161  /* updates... */
1163  return OPERATOR_FINISHED;
1164 }
1165 
1167  wmOperator *op,
1168  const wmEvent *UNUSED(event))
1169 {
1170  /* hook up invoke properties for figuring out which constraint we're dealing with */
1172  return followpath_path_animate_exec(C, op);
1173  }
1174  return OPERATOR_CANCELLED;
1175 }
1176 
1178 {
1179  /* identifiers */
1180  ot->name = "Auto Animate Path";
1181  ot->idname = "CONSTRAINT_OT_followpath_path_animate";
1182  ot->description =
1183  "Add default animation for path used by constraint if it isn't animated already";
1184 
1185  /* callbacks */
1189 
1190  /* flags */
1192 
1193  /* props */
1195  RNA_def_int(ot->srna,
1196  "frame_start",
1197  1,
1198  MINAFRAME,
1199  MAXFRAME,
1200  "Start Frame",
1201  "First frame of path animation",
1202  MINAFRAME,
1203  MAXFRAME);
1204  RNA_def_int(ot->srna,
1205  "length",
1206  100,
1207  0,
1208  MAXFRAME,
1209  "Length",
1210  "Number of frames that path animation should take",
1211  0,
1212  MAXFRAME);
1213 }
1214 
1217 /* ------------------------------------------------------------------- */
1222 {
1223  Main *bmain = CTX_data_main(C);
1227 
1228  /* despite 3 layers of checks, we may still not be able to find a constraint */
1229  if (data == NULL) {
1230  printf("DEBUG: ObjectSolver Set Inverse - object = '%s'\n", (ob) ? ob->id.name + 2 : "<None>");
1231  BKE_report(
1232  op->reports, RPT_ERROR, "Could not find constraint data for ObjectSolver Set Inverse");
1233  return OPERATOR_CANCELLED;
1234  }
1235 
1236  /* Set a flag to request recalculation on next update. */
1237  data->flag |= OBJECTSOLVER_SET_INVERSE;
1238 
1239  /* Force constraint to run, it will perform the recalculation. */
1241 
1242  ED_object_constraint_update(bmain, ob);
1244 
1245  return OPERATOR_FINISHED;
1246 }
1247 
1249  wmOperator *op,
1250  const wmEvent *UNUSED(event))
1251 {
1253  return objectsolver_set_inverse_exec(C, op);
1254  }
1255  return OPERATOR_CANCELLED;
1256 }
1257 
1259 {
1260  /* identifiers */
1261  ot->name = "Set Inverse";
1262  ot->idname = "CONSTRAINT_OT_objectsolver_set_inverse";
1263  ot->description = "Set inverse correction for Object Solver constraint";
1264 
1265  /* callbacks */
1269 
1270  /* flags */
1272 
1273  /* properties */
1275 }
1276 
1279 /* ------------------------------------------------------------------- */
1284 {
1285  Main *bmain = CTX_data_main(C);
1289 
1290  if (data == NULL) {
1291  BKE_report(op->reports, RPT_ERROR, "Child Of constraint not found");
1292  return OPERATOR_CANCELLED;
1293  }
1294 
1295  /* simply clear the matrix */
1296  unit_m4(data->invmat);
1297 
1298  ED_object_constraint_update(bmain, ob);
1300 
1301  return OPERATOR_FINISHED;
1302 }
1303 
1305  wmOperator *op,
1306  const wmEvent *UNUSED(event))
1307 {
1309  return objectsolver_clear_inverse_exec(C, op);
1310  }
1311  return OPERATOR_CANCELLED;
1312 }
1313 
1315 {
1316  /* identifiers */
1317  ot->name = "Clear Inverse";
1318  ot->idname = "CONSTRAINT_OT_objectsolver_clear_inverse";
1319  ot->description = "Clear inverse correction for Object Solver constraint";
1320 
1321  /* callbacks */
1325 
1326  /* flags */
1328 
1329  /* properties */
1331 }
1332 
1335 /* ------------------------------------------------------------------- */
1340 {
1342 
1343  /* lets be nice and escape if its active already */
1344  /* NOTE: this assumes that the stack doesn't have other active ones set... */
1345  if ((lb && con) && (con->flag & CONSTRAINT_ACTIVE)) {
1346  return;
1347  }
1348 
1349  BKE_constraints_active_set(lb, con);
1350 }
1351 
1353 {
1354  if (ob->pose) {
1356  }
1357 
1358  object_test_constraints(bmain, ob);
1359 
1360  if (ob->type == OB_ARMATURE) {
1362  }
1363  else {
1365  }
1366 }
1367 
1368 static void object_pose_tag_update(Main *bmain, Object *ob)
1369 {
1370  BKE_pose_tag_recalc(bmain, ob->pose); /* Checks & sort pose channels. */
1371  if (ob->proxy && ob->adt) {
1372  /* We need to make use of ugly #POSE_ANIMATION_WORKAROUND here too,
1373  * else anim data are not reloaded after calling `BKE_pose_rebuild()`,
1374  * which causes T43872.
1375  * Note that this is a bit wide here, since we cannot be sure whether there are some locked
1376  * proxy bones or not.
1377  * XXX Temp hack until new depsgraph hopefully solves this. */
1379  }
1380 }
1381 
1383 {
1384  ED_object_constraint_update(bmain, ob);
1385 
1386  if (ob->pose) {
1387  object_pose_tag_update(bmain, ob);
1388  }
1389  DEG_relations_tag_update(bmain);
1390 }
1391 
1393 {
1394  if (ob->pose) {
1396  }
1397 
1398  if (con) {
1399  object_test_constraint(bmain, ob, con);
1400  }
1401 
1402  if (ob->type == OB_ARMATURE) {
1404  }
1405  else {
1407  }
1408 
1409  /* Do Copy-on-Write tag here too, otherwise constraint
1410  * influence/mute buttons in UI have no effect
1411  */
1413 }
1414 
1416 {
1417  ED_object_constraint_tag_update(bmain, ob, con);
1418 
1419  if (ob->pose) {
1420  object_pose_tag_update(bmain, ob);
1421  }
1422  DEG_relations_tag_update(bmain);
1423 }
1424 
1426 {
1427  BLI_assert(con != NULL);
1428  BLI_assert(index >= 0);
1429 
1431  int current_index = BLI_findindex(conlist, con);
1432  BLI_assert(current_index >= 0);
1433 
1434  BLI_listbase_link_move(conlist, con, index - current_index);
1435 
1437 
1438  return true;
1439 }
1440 
1441 void ED_object_constraint_link(Main *bmain, Object *ob_dst, ListBase *dst, ListBase *src)
1442 {
1443  BKE_constraints_free(dst);
1444  BKE_constraints_copy(dst, src, true);
1445  LISTBASE_FOREACH (bConstraint *, con, dst) {
1446  ED_object_constraint_dependency_tag_update(bmain, ob_dst, con);
1447  }
1449 }
1450 
1452 {
1453  BKE_constraint_copy_for_object(ob_dst, con);
1454  ED_object_constraint_dependency_tag_update(bmain, ob_dst, con);
1456 }
1457 
1459  Object *ob_dst,
1460  bPoseChannel *pchan,
1461  bConstraint *con)
1462 {
1463  BKE_constraint_copy_for_pose(ob_dst, pchan, con);
1464  ED_object_constraint_dependency_tag_update(bmain, ob_dst, con);
1466 }
1467 
1470 /* ------------------------------------------------------------------- */
1475 {
1476  Main *bmain = CTX_data_main(C);
1478  bConstraint *con = edit_constraint_property_get(C, op, ob, 0);
1480 
1481  /* Store name temporarily for report. */
1482  char name[MAX_NAME];
1483  strcpy(name, con->name);
1484 
1485  /* free the constraint */
1486  if (BKE_constraint_remove_ex(lb, ob, con, true)) {
1487  /* there's no active constraint now, so make sure this is the case */
1489  /* needed to set the flags on posebones correctly */
1490  ED_object_constraint_update(bmain, ob);
1491 
1492  /* relations */
1494 
1495  /* notifiers */
1497 
1498  if (RNA_boolean_get(op->ptr, "report")) {
1499  BKE_reportf(op->reports, RPT_INFO, "Removed constraint: %s", name);
1500  }
1501 
1502  return OPERATOR_FINISHED;
1503  }
1504  /* couldn't remove due to some invalid data */
1505  return OPERATOR_CANCELLED;
1506 }
1507 
1508 static int constraint_delete_invoke(bContext *C, wmOperator *op, const wmEvent *event)
1509 {
1510  int retval;
1511  if (edit_constraint_invoke_properties(C, op, event, &retval)) {
1512  return constraint_delete_exec(C, op);
1513  }
1514  return OPERATOR_CANCELLED;
1515 }
1516 
1518 {
1519  /* identifiers */
1520  ot->name = "Delete Constraint";
1521  ot->idname = "CONSTRAINT_OT_delete";
1522  ot->description = "Remove constraint from constraint stack";
1523 
1524  /* callbacks */
1528 
1529  /* flags */
1533 }
1534 
1537 /* ------------------------------------------------------------------- */
1542 {
1544  bConstraint *con = edit_constraint_property_get(C, op, ob, 0);
1545 
1546  if (con && con->next) {
1548  bConstraint *nextCon = con->next;
1549 
1550  /* insert the nominated constraint after the one that used to be after it */
1551  BLI_remlink(conlist, con);
1552  BLI_insertlinkafter(conlist, nextCon, con);
1553 
1555 
1556  return OPERATOR_FINISHED;
1557  }
1558 
1559  return OPERATOR_CANCELLED;
1560 }
1561 
1563 {
1564  int retval;
1565  if (edit_constraint_invoke_properties(C, op, event, &retval)) {
1566  return constraint_move_down_exec(C, op);
1567  }
1568  return retval;
1569 }
1570 
1572 {
1573  /* identifiers */
1574  ot->name = "Move Constraint Down";
1575  ot->idname = "CONSTRAINT_OT_move_down";
1576  ot->description = "Move constraint down in constraint stack";
1577 
1578  /* callbacks */
1582 
1583  /* flags */
1585 
1586  /* properties */
1588 }
1589 
1592 /* ------------------------------------------------------------------- */
1597 {
1599  bConstraint *con = edit_constraint_property_get(C, op, ob, 0);
1600 
1601  if (con && con->prev) {
1603  bConstraint *prevCon = con->prev;
1604 
1605  /* insert the nominated constraint before the one that used to be before it */
1606  BLI_remlink(conlist, con);
1607  BLI_insertlinkbefore(conlist, prevCon, con);
1608 
1610 
1611  return OPERATOR_FINISHED;
1612  }
1613 
1614  return OPERATOR_CANCELLED;
1615 }
1616 
1617 static int constraint_move_up_invoke(bContext *C, wmOperator *op, const wmEvent *event)
1618 {
1619  int retval;
1620  if (edit_constraint_invoke_properties(C, op, event, &retval)) {
1621  return constraint_move_up_exec(C, op);
1622  }
1623  return retval;
1624 }
1625 
1627 {
1628  /* identifiers */
1629  ot->name = "Move Constraint Up";
1630  ot->idname = "CONSTRAINT_OT_move_up";
1631  ot->description = "Move constraint up in constraint stack";
1632 
1633  /* callbacks */
1637 
1638  /* flags */
1641 }
1642 
1645 /* ------------------------------------------------------------------- */
1650 {
1652  bConstraint *con = edit_constraint_property_get(C, op, ob, 0);
1653 
1654  int new_index = RNA_int_get(op->ptr, "index");
1655  if (new_index < 0) {
1656  new_index = 0;
1657  }
1658 
1659  if (con) {
1660  ED_object_constraint_move_to_index(ob, con, new_index);
1661 
1662  return OPERATOR_FINISHED;
1663  }
1664 
1665  return OPERATOR_CANCELLED;
1666 }
1667 
1669 {
1670  int retval;
1671  if (edit_constraint_invoke_properties(C, op, event, &retval)) {
1672  return constraint_move_to_index_exec(C, op);
1673  }
1674  return retval;
1675 }
1676 
1678 {
1679  /* identifiers */
1680  ot->name = "Move Constraint to Index";
1681  ot->idname = "CONSTRAINT_OT_move_to_index";
1682  ot->description =
1683  "Change the constraint's position in the list so it evaluates after the set number of "
1684  "others";
1685 
1686  /* callbacks */
1690 
1691  /* flags */
1694  RNA_def_int(ot->srna,
1695  "index",
1696  0,
1697  0,
1698  INT_MAX,
1699  "Index",
1700  "The index to move the constraint to",
1701  0,
1702  INT_MAX);
1703 }
1704 
1707 /* ------------------------------------------------------------------- */
1712 {
1713  Main *bmain = CTX_data_main(C);
1714  Object *prev_ob = NULL;
1715 
1716  /* free constraints for all selected bones */
1717  CTX_DATA_BEGIN_WITH_ID (C, bPoseChannel *, pchan, selected_pose_bones, Object *, ob) {
1718  BKE_constraints_free(&pchan->constraints);
1719  pchan->constflag &= ~(PCHAN_HAS_IK | PCHAN_HAS_SPLINEIK | PCHAN_HAS_CONST);
1720 
1721  if (prev_ob != ob) {
1724  prev_ob = ob;
1725  }
1726  }
1727  CTX_DATA_END;
1728 
1729  /* force depsgraph to get recalculated since relationships removed */
1730  DEG_relations_tag_update(bmain);
1731 
1732  /* note, calling BIK_clear_data() isn't needed here */
1733 
1734  return OPERATOR_FINISHED;
1735 }
1736 
1738 {
1739  /* identifiers */
1740  ot->name = "Clear Pose Constraints";
1741  ot->idname = "POSE_OT_constraints_clear";
1742  ot->description = "Clear all the constraints for the selected bones";
1743 
1744  /* callbacks */
1746  ot->poll = ED_operator_posemode_exclusive; /* XXX - do we want to ensure there are selected
1747  * bones too? */
1748 }
1749 
1751 {
1752  Main *bmain = CTX_data_main(C);
1753 
1754  /* do freeing */
1755  CTX_DATA_BEGIN (C, Object *, ob, selected_editable_objects) {
1756  BKE_constraints_free(&ob->constraints);
1758  }
1759  CTX_DATA_END;
1760 
1761  /* force depsgraph to get recalculated since relationships removed */
1762  DEG_relations_tag_update(bmain);
1763 
1764  /* do updates */
1766 
1767  return OPERATOR_FINISHED;
1768 }
1769 
1772 /* ------------------------------------------------------------------- */
1777 {
1778  /* identifiers */
1779  ot->name = "Clear Object Constraints";
1780  ot->idname = "OBJECT_OT_constraints_clear";
1781  ot->description = "Clear all the constraints for the active object only";
1782 
1783  /* callbacks */
1786 }
1787 
1790 /* ------------------------------------------------------------------- */
1795 {
1796  Main *bmain = CTX_data_main(C);
1798 
1799  /* don't do anything if bone doesn't exist or doesn't have any constraints */
1800  if (ELEM(NULL, pchan, pchan->constraints.first)) {
1801  BKE_report(op->reports, RPT_ERROR, "No active bone with constraints for copying");
1802  return OPERATOR_CANCELLED;
1803  }
1804 
1805  Object *prev_ob = NULL;
1806 
1807  /* copy all constraints from active posebone to all selected posebones */
1808  CTX_DATA_BEGIN_WITH_ID (C, bPoseChannel *, chan, selected_pose_bones, Object *, ob) {
1809  /* if we're not handling the object we're copying from, copy all constraints over */
1810  if (pchan != chan) {
1811  BKE_constraints_copy(&chan->constraints, &pchan->constraints, true);
1812  /* update flags (need to add here, not just copy) */
1813  chan->constflag |= pchan->constflag;
1814 
1815  if (prev_ob != ob) {
1816  BKE_pose_tag_recalc(bmain, ob->pose);
1818  prev_ob = ob;
1819  }
1820  }
1821  }
1822  CTX_DATA_END;
1823 
1824  /* force depsgraph to get recalculated since new relationships added */
1825  DEG_relations_tag_update(bmain);
1826 
1828 
1829  return OPERATOR_FINISHED;
1830 }
1831 
1833 {
1834  /* identifiers */
1835  ot->name = "Copy Constraints to Selected Bones";
1836  ot->idname = "POSE_OT_constraints_copy";
1837  ot->description = "Copy constraints to other selected bones";
1838 
1839  /* api callbacks */
1842 
1843  /* flags */
1845 }
1846 
1849 /* ------------------------------------------------------------------- */
1854 {
1855  Main *bmain = CTX_data_main(C);
1856  Object *obact = ED_object_active_context(C);
1857 
1858  /* copy all constraints from active object to all selected objects */
1859  CTX_DATA_BEGIN (C, Object *, ob, selected_editable_objects) {
1860  /* if we're not handling the object we're copying from, copy all constraints over */
1861  if (obact != ob) {
1862  BKE_constraints_copy(&ob->constraints, &obact->constraints, true);
1864  }
1865  }
1866  CTX_DATA_END;
1867 
1868  /* force depsgraph to get recalculated since new relationships added */
1869  DEG_relations_tag_update(bmain);
1870 
1871  /* notifiers for updates */
1873 
1874  return OPERATOR_FINISHED;
1875 }
1876 
1878 {
1879  /* identifiers */
1880  ot->name = "Copy Constraints to Selected Objects";
1881  ot->idname = "OBJECT_OT_constraints_copy";
1882  ot->description = "Copy constraints to other selected objects";
1883 
1884  /* api callbacks */
1887 
1888  /* flags */
1890 }
1891 
1894 /* ------------------------------------------------------------------- */
1898 /* get the Object and/or PoseChannel to use as target */
1900  bContext *C, int con_type, Object **tar_ob, bPoseChannel **tar_pchan, bool add)
1901 {
1902  Object *obact = ED_object_active_context(C);
1903  bPoseChannel *pchanact = BKE_pose_channel_active(obact);
1904  bool only_curve = false, only_mesh = false, only_ob = false;
1905  bool found = false;
1906 
1907  /* clear tar_ob and tar_pchan fields before use
1908  * - assume for now that both always exist...
1909  */
1910  *tar_ob = NULL;
1911  *tar_pchan = NULL;
1912 
1913  /* check if constraint type doesn't requires a target
1914  * - if so, no need to get any targets
1915  */
1916  switch (con_type) {
1917  /* no-target constraints --------------------------- */
1918  /* null constraint - shouldn't even be added! */
1919  case CONSTRAINT_TYPE_NULL:
1920  /* limit constraints - no targets needed */
1925  return false;
1926 
1927  /* restricted target-type constraints -------------- */
1928  /* NOTE: for these, we cannot try to add a target object if no valid ones are found,
1929  * since that doesn't work */
1930  /* curve-based constraints - set the only_curve and only_ob flags */
1934  only_curve = true;
1935  only_ob = true;
1936  add = false;
1937  break;
1938 
1939  /* mesh only? */
1941  only_mesh = true;
1942  only_ob = true;
1943  add = false;
1944  break;
1945  }
1946 
1947  /* if the active Object is Armature, and we can search for bones, do so... */
1948  if ((obact->type == OB_ARMATURE) && (only_ob == false)) {
1949  /* search in list of selected Pose-Channels for target */
1950  CTX_DATA_BEGIN (C, bPoseChannel *, pchan, selected_pose_bones_from_active_object) {
1951  /* just use the first one that we encounter, as long as it is not the active one */
1952  if (pchan != pchanact) {
1953  *tar_ob = obact;
1954  *tar_pchan = pchan;
1955  found = true;
1956 
1957  break;
1958  }
1959  }
1960  CTX_DATA_END;
1961  }
1962 
1963  /* if not yet found, try selected Objects... */
1964  if (found == false) {
1965  /* search in selected objects context */
1966  CTX_DATA_BEGIN (C, Object *, ob, selected_objects) {
1967  /* just use the first object we encounter (that isn't the active object)
1968  * and which fulfills the criteria for the object-target that we've got
1969  */
1970  if (ob != obact) {
1971  /* for armatures in pose mode, look inside the armature for the active bone
1972  * so that we set up cross-armature constraints with less effort
1973  */
1974  if ((ob->type == OB_ARMATURE) && (ob->mode & OB_MODE_POSE) &&
1975  (!only_curve && !only_mesh)) {
1976 
1977  /* Only use the object & bone if the bone is visible & selected
1978  * since we may have multiple objects in pose mode at once. */
1980  if (pchan != NULL) {
1981  *tar_pchan = pchan;
1982  *tar_ob = ob;
1983  found = true;
1984  }
1985 
1986  break;
1987  }
1988  if (((!only_curve) || (ob->type == OB_CURVE)) && ((!only_mesh) || (ob->type == OB_MESH))) {
1989  /* set target */
1990  *tar_ob = ob;
1991  found = true;
1992 
1993  /* perform some special operations on the target */
1994  if (only_curve) {
1995  /* Curve-Path option must be enabled for follow-path constraints to be able to work
1996  */
1997  Curve *cu = (Curve *)ob->data;
1998  cu->flag |= CU_PATH;
1999  }
2000 
2001  break;
2002  }
2003  }
2004  }
2005  CTX_DATA_END;
2006  }
2007 
2008  /* if still not found, add a new empty to act as a target (if allowed) */
2009  if ((found == false) && (add)) {
2010  Main *bmain = CTX_data_main(C);
2011  ViewLayer *view_layer = CTX_data_view_layer(C);
2012  Base *base = BASACT(view_layer);
2013  Object *obt;
2014 
2015  /* add new target object */
2016  obt = BKE_object_add(bmain, view_layer, OB_EMPTY, NULL);
2017 
2018  /* transform cent to global coords for loc */
2019  if (pchanact) {
2020  /* Since by default, IK targets the tip of the last bone,
2021  * use the tip of the active PoseChannel if adding a target for an IK Constraint. */
2022  if (con_type == CONSTRAINT_TYPE_KINEMATIC) {
2023  mul_v3_m4v3(obt->loc, obact->obmat, pchanact->pose_tail);
2024  }
2025  else {
2026  mul_v3_m4v3(obt->loc, obact->obmat, pchanact->pose_head);
2027  }
2028  }
2029  else {
2030  copy_v3_v3(obt->loc, obact->obmat[3]);
2031  }
2032 
2033  /* restore, BKE_object_add sets active */
2034  BASACT(view_layer) = base;
2036 
2037  /* make our new target the new object */
2038  *tar_ob = obt;
2039  found = true;
2040  }
2041 
2042  /* return whether there's any target */
2043  return found;
2044 }
2045 
2046 /* used by add constraint operators to add the constraint required */
2048  bContext *C, wmOperator *op, Object *ob, ListBase *list, int type, const bool setTarget)
2049 {
2050  Main *bmain = CTX_data_main(C);
2051  bPoseChannel *pchan;
2052  bConstraint *con;
2053 
2054  if (list == &ob->constraints) {
2055  pchan = NULL;
2056  }
2057  else {
2058  pchan = BKE_pose_channel_active(ob);
2059 
2060  /* ensure not to confuse object/pose adding */
2061  if (pchan == NULL) {
2062  BKE_report(op->reports, RPT_ERROR, "No active pose bone to add a constraint to");
2063  return OPERATOR_CANCELLED;
2064  }
2065  }
2066  /* check if constraint to be added is valid for the given constraints stack */
2067  if (type == CONSTRAINT_TYPE_NULL) {
2068  return OPERATOR_CANCELLED;
2069  }
2070 
2071  /* Create a new constraint of the type required,
2072  * and add it to the active/given constraints list. */
2073  if (pchan) {
2074  con = BKE_constraint_add_for_pose(ob, pchan, NULL, type);
2075  }
2076  else {
2078  }
2079 
2080  /* get the first selected object/bone, and make that the target
2081  * - apart from the buttons-window add buttons, we shouldn't add in this way
2082  */
2083  if (setTarget) {
2084  Object *tar_ob = NULL;
2085  bPoseChannel *tar_pchan = NULL;
2086 
2087  /* get the target objects, adding them as need be */
2088  if (get_new_constraint_target(C, type, &tar_ob, &tar_pchan, 1)) {
2089  /* Method of setting target depends on the type of target we've got - by default,
2090  * just set the first target (distinction here is only for multiple-targeted constraints).
2091  */
2092  if (tar_pchan) {
2093  set_constraint_nth_target(con, tar_ob, tar_pchan->name, 0);
2094  }
2095  else {
2096  set_constraint_nth_target(con, tar_ob, "", 0);
2097  }
2098  }
2099  }
2100 
2101  /* do type-specific tweaking to the constraint settings */
2102  switch (type) {
2103  case CONSTRAINT_TYPE_PYTHON: /* FIXME: this code is not really valid anymore */
2104  {
2105 #ifdef WITH_PYTHON
2106  char *menustr;
2107  int scriptint = 0;
2108  /* popup a list of usable scripts */
2109  menustr = buildmenu_pyconstraints(bmain, NULL, &scriptint);
2110  /* XXX scriptint = pupmenu(menustr); */
2111  MEM_freeN(menustr);
2112 
2113  /* only add constraint if a script was chosen */
2114  if (scriptint) {
2115  /* add constraint */
2116  validate_pyconstraint_cb(bmain, con->data, &scriptint);
2117 
2118  /* make sure target allowance is set correctly */
2119  BPY_pyconstraint_update(ob, con);
2120  }
2121 #endif
2122  break;
2123  }
2124 
2125  default:
2126  break;
2127  }
2128 
2129  /* make sure all settings are valid - similar to above checks, but sometimes can be wrong */
2130  object_test_constraints(bmain, ob);
2131 
2132  if (pchan) {
2134  }
2135 
2136  /* force depsgraph to get recalculated since new relationships added */
2137  DEG_relations_tag_update(bmain);
2138 
2139  if ((ob->type == OB_ARMATURE) && (pchan)) {
2140  BKE_pose_tag_recalc(bmain, ob->pose); /* sort pose channels */
2141  if (BKE_constraints_proxylocked_owner(ob, pchan) && ob->adt) {
2142  /* We need to make use of ugly POSE_ANIMATION_WORKAROUND here too,
2143  * else anim data are not reloaded after calling `BKE_pose_rebuild()`, which causes T43872.
2144  * XXX Temp hack until new depsgraph hopefully solves this. */
2146  }
2148  }
2149  else {
2151  }
2152 
2153  /* notifiers for updates */
2155 
2156  return OPERATOR_FINISHED;
2157 }
2158 
2159 /* ------------------ */
2160 
2161 /* dummy operator callback */
2163 {
2165  int type = RNA_enum_get(op->ptr, "type");
2166  short with_targets = 0;
2167 
2168  if (!ob) {
2169  BKE_report(op->reports, RPT_ERROR, "No active object to add constraint to");
2170  return OPERATOR_CANCELLED;
2171  }
2172 
2173  /* hack: set constraint targets from selected objects in context is allowed when
2174  * operator name included 'with_targets', since the menu doesn't allow multiple properties
2175  */
2176  if (strstr(op->idname, "with_targets")) {
2177  with_targets = 1;
2178  }
2179 
2180  return constraint_add_exec(C, op, ob, &ob->constraints, type, with_targets);
2181 }
2182 
2183 /* dummy operator callback */
2185 {
2187  int type = RNA_enum_get(op->ptr, "type");
2188  short with_targets = 0;
2189 
2190  if (!ob) {
2191  BKE_report(op->reports, RPT_ERROR, "No active object to add constraint to");
2192  return OPERATOR_CANCELLED;
2193  }
2194 
2195  /* hack: set constraint targets from selected objects in context is allowed when
2196  * operator name included 'with_targets', since the menu doesn't allow multiple properties
2197  */
2198  if (strstr(op->idname, "with_targets")) {
2199  with_targets = 1;
2200  }
2201 
2202  return constraint_add_exec(C, op, ob, ED_object_constraint_active_list(ob), type, with_targets);
2203 }
2204 
2205 /* ------------------ */
2206 
2207 /* Filters constraints that are only compatible with bones */
2209  PointerRNA *UNUSED(ptr),
2210  PropertyRNA *UNUSED(prop),
2211  bool *r_free)
2212 {
2214  EnumPropertyItem *object_constraint_items = NULL;
2215  int totitem = 0;
2216 
2217  while (item->identifier) {
2219  RNA_enum_item_add(&object_constraint_items, &totitem, item);
2220  }
2221  item++;
2222  }
2223 
2224  RNA_enum_item_end(&object_constraint_items, &totitem);
2225  *r_free = true;
2226 
2227  return object_constraint_items;
2228 }
2229 
2231 {
2232  PropertyRNA *prop;
2233 
2234  /* identifiers */
2235  ot->name = "Add Constraint";
2236  ot->description = "Add a constraint to the active object";
2237  ot->idname = "OBJECT_OT_constraint_add";
2238 
2239  /* api callbacks */
2243 
2244  /* flags */
2246 
2247  /* properties */
2248  prop = RNA_def_enum(ot->srna, "type", DummyRNA_NULL_items, 0, "Type", "");
2250  ot->prop = prop;
2251 }
2252 
2255 /* ------------------------------------------------------------------- */
2260 {
2261  PropertyRNA *prop;
2262 
2263  /* identifiers */
2264  ot->name = "Add Constraint (with Targets)";
2265  ot->description =
2266  "Add a constraint to the active object, with target (where applicable) set to the "
2267  "selected objects/bones";
2268  ot->idname = "OBJECT_OT_constraint_add_with_targets";
2269 
2270  /* api callbacks */
2274 
2275  /* flags */
2277 
2278  /* properties */
2279  prop = RNA_def_enum(ot->srna, "type", DummyRNA_NULL_items, 0, "Type", "");
2281  ot->prop = prop;
2282 }
2283 
2285 {
2286  /* identifiers */
2287  ot->name = "Add Constraint";
2288  ot->description = "Add a constraint to the active bone";
2289  ot->idname = "POSE_OT_constraint_add";
2290 
2291  /* api callbacks */
2295 
2296  /* flags */
2298 
2299  /* properties */
2300  ot->prop = RNA_def_enum(ot->srna, "type", rna_enum_constraint_type_items, 0, "Type", "");
2301 }
2302 
2304 {
2305  /* identifiers */
2306  ot->name = "Add Constraint (with Targets)";
2307  ot->description =
2308  "Add a constraint to the active bone, with target (where applicable) set to the selected "
2309  "Objects/Bones";
2310  ot->idname = "POSE_OT_constraint_add_with_targets";
2311 
2312  /* api callbacks */
2316 
2317  /* flags */
2319 
2320  /* properties */
2321  ot->prop = RNA_def_enum(ot->srna, "type", rna_enum_constraint_type_items, 0, "Type", "");
2322 }
2323 
2326 /* ------------------------------------------------------------------- */
2332 /* TODO: should these be here, or back in editors/armature/poseobject.c again? */
2333 
2334 /* present menu with options + validation for targets to use */
2335 static int pose_ik_add_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event))
2336 {
2339  bConstraint *con = NULL;
2340 
2341  uiPopupMenu *pup;
2342  uiLayout *layout;
2343  Object *tar_ob = NULL;
2344  bPoseChannel *tar_pchan = NULL;
2345 
2346  /* must have active bone */
2347  if (ELEM(NULL, ob, pchan)) {
2348  BKE_report(op->reports, RPT_ERROR, "Must have an active bone to add IK constraint to");
2349  return OPERATOR_CANCELLED;
2350  }
2351 
2352  /* bone must not have any constraints already */
2353  for (con = pchan->constraints.first; con; con = con->next) {
2354  if (con->type == CONSTRAINT_TYPE_KINEMATIC) {
2355  break;
2356  }
2357  }
2358  if (con) {
2359  BKE_report(op->reports, RPT_ERROR, "Bone already has an IK constraint");
2360  return OPERATOR_CANCELLED;
2361  }
2362 
2363  /* prepare popup menu to choose targeting options */
2364  pup = UI_popup_menu_begin(C, IFACE_("Add IK"), ICON_NONE);
2365  layout = UI_popup_menu_layout(pup);
2366 
2367  /* the type of targets we'll set determines the menu entries to show... */
2368  if (get_new_constraint_target(C, CONSTRAINT_TYPE_KINEMATIC, &tar_ob, &tar_pchan, 0)) {
2369  /* bone target, or object target?
2370  * - the only thing that matters is that we want a target...
2371  */
2372  if (tar_pchan) {
2374  layout, IFACE_("To Active Bone"), ICON_NONE, "POSE_OT_ik_add", "with_targets", 1);
2375  }
2376  else {
2378  layout, IFACE_("To Active Object"), ICON_NONE, "POSE_OT_ik_add", "with_targets", 1);
2379  }
2380  }
2381  else {
2382  /* we have a choice of adding to a new empty, or not setting any target (targetless IK) */
2384  layout, IFACE_("To New Empty Object"), ICON_NONE, "POSE_OT_ik_add", "with_targets", 1);
2386  layout, IFACE_("Without Targets"), ICON_NONE, "POSE_OT_ik_add", "with_targets", 0);
2387  }
2388 
2389  /* finish building the menu, and process it (should result in calling self again) */
2390  UI_popup_menu_end(C, pup);
2391 
2392  return OPERATOR_INTERFACE;
2393 }
2394 
2395 /* call constraint_add_exec() to add the IK constraint */
2397 {
2399  const bool with_targets = RNA_boolean_get(op->ptr, "with_targets");
2400 
2401  /* add the constraint - all necessary checks should have
2402  * been done by the invoke() callback already... */
2403  return constraint_add_exec(
2404  C, op, ob, ED_object_constraint_active_list(ob), CONSTRAINT_TYPE_KINEMATIC, with_targets);
2405 }
2406 
2408 {
2409  /* identifiers */
2410  ot->name = "Add IK to Bone";
2411  ot->description = "Add IK Constraint to the active Bone";
2412  ot->idname = "POSE_OT_ik_add";
2413 
2414  /* api callbacks */
2418 
2419  /* flags */
2421 
2422  /* properties */
2424  "with_targets",
2425  1,
2426  "With Targets",
2427  "Assign IK Constraint with targets derived from the select bones/objects");
2428 }
2429 
2432 /* ------------------------------------------------------------------- */
2439 {
2440  Object *prev_ob = NULL;
2441 
2442  /* only remove IK Constraints */
2443  CTX_DATA_BEGIN_WITH_ID (C, bPoseChannel *, pchan, selected_pose_bones, Object *, ob) {
2444  bConstraint *con, *next;
2445 
2446  /* TODO: should we be checking if these constraints were local
2447  * before we try and remove them? */
2448  for (con = pchan->constraints.first; con; con = next) {
2449  next = con->next;
2450  if (con->type == CONSTRAINT_TYPE_KINEMATIC) {
2451  BKE_constraint_remove(&pchan->constraints, con);
2452  }
2453  }
2454  pchan->constflag &= ~(PCHAN_HAS_IK | PCHAN_HAS_TARGET);
2455 
2456  if (prev_ob != ob) {
2457  prev_ob = ob;
2458 
2459  /* Refresh depsgraph. */
2461 
2462  /* Note, notifier might evolve. */
2464  }
2465  }
2466  CTX_DATA_END;
2467 
2468  return OPERATOR_FINISHED;
2469 }
2470 
2472 {
2473  /* identifiers */
2474  ot->name = "Remove IK";
2475  ot->description = "Remove all IK Constraints from selected bones";
2476  ot->idname = "POSE_OT_ik_clear";
2477 
2478  /* api callbacks */
2481 
2482  /* flags */
2484 }
2485 
typedef float(TangentPoint)[2]
void BIK_test_constraint(struct Object *ob, struct bConstraint *cons)
Definition: ikplugin_api.c:138
Blender kernel action and pose functionality.
void BKE_pose_tag_recalc(struct Main *bmain, struct bPose *pose)
Definition: action.c:1726
struct bPoseChannel * BKE_pose_channel_active_or_first_selected(struct Object *ob)
Definition: action.c:736
struct bPoseChannel * BKE_pose_channel_active(struct Object *ob)
Definition: action.c:708
void BKE_pose_tag_update_constraint_flags(struct bPose *pose)
Definition: action.c:1314
void BKE_pose_update_constraint_flags(struct bPose *pose)
Definition: action.c:1247
struct Bone * BKE_armature_find_bone_name(struct bArmature *arm, const char *name)
Definition: armature.c:609
struct bArmature * BKE_armature_from_object(struct Object *ob)
Definition: armature.c:353
bool BKE_constraint_remove(ListBase *list, struct bConstraint *con)
Definition: constraint.c:5515
struct bConstraint * BKE_constraint_copy_for_object(struct Object *ob, struct bConstraint *src)
Definition: constraint.c:5777
void BKE_constraints_free(struct ListBase *list)
Definition: constraint.c:5509
struct bConstraint * BKE_constraint_add_for_object(struct Object *ob, const char *name, short type)
Definition: constraint.c:5672
struct bConstraint * BKE_constraints_find_name(struct ListBase *list, const char *name)
Definition: constraint.c:5806
void BKE_constraints_copy(struct ListBase *dst, const struct ListBase *src, bool do_extern)
bool BKE_constraint_remove_ex(ListBase *list, struct Object *ob, struct bConstraint *con, bool clear_dep)
Definition: constraint.c:5526
bool BKE_constraint_is_nonlocal_in_liboverride(const struct Object *ob, const struct bConstraint *con)
struct bConstraint * BKE_constraints_active_get(struct ListBase *list)
Definition: constraint.c:5812
bool BKE_constraints_proxylocked_owner(struct Object *ob, struct bPoseChannel *pchan)
Definition: constraint.c:5995
const bConstraintTypeInfo * BKE_constraint_typeinfo_get(struct bConstraint *con)
Definition: constraint.c:5435
struct bConstraint * BKE_constraint_copy_for_pose(struct Object *ob, struct bPoseChannel *pchan, struct bConstraint *src)
Definition: constraint.c:5765
void BKE_constraints_active_set(ListBase *list, struct bConstraint *con)
Definition: constraint.c:5829
struct bConstraint * BKE_constraint_add_for_pose(struct Object *ob, struct bPoseChannel *pchan, const char *name, short type)
Definition: constraint.c:5659
#define CTX_DATA_BEGIN_WITH_ID(C, Type, instance, member, Type_id, instance_id)
Definition: BKE_context.h:266
PointerRNA CTX_data_pointer_get(const bContext *C, const char *member)
Definition: context.c:445
#define CTX_DATA_BEGIN(C, Type, instance, member)
Definition: BKE_context.h:252
PointerRNA CTX_data_pointer_get_type(const bContext *C, const char *member, StructRNA *type)
Definition: context.c:456
struct ViewLayer * CTX_data_view_layer(const bContext *C)
Definition: context.c:1044
struct Depsgraph * CTX_data_ensure_evaluated_depsgraph(const bContext *C)
Definition: context.c:1424
struct Object * CTX_data_active_object(const bContext *C)
Definition: context.c:1279
void CTX_wm_operator_poll_msg_set(struct bContext *C, const char *msg)
Definition: context.c:1006
struct Main * CTX_data_main(const bContext *C)
Definition: context.c:1018
#define CTX_DATA_END
Definition: BKE_context.h:260
struct bPoseChannel * CTX_data_active_pose_bone(const bContext *C)
Definition: context.c:1351
struct FCurve * BKE_fcurve_find(ListBase *list, const char rna_path[], const int array_index)
Definition: fcurve.c:274
struct FModifier * add_fmodifier(ListBase *modifiers, int type, struct FCurve *owner_fcu)
Definition: fmodifier.c:1114
@ G_DEBUG
Definition: BKE_global.h:133
General operations, lookup, etc. for blender objects.
void BKE_object_eval_constraints(struct Depsgraph *depsgraph, struct Scene *scene, struct Object *ob)
struct Object * BKE_object_pose_armature_get(struct Object *ob)
Definition: object.c:2487
struct Object * BKE_object_add(struct Main *bmain, struct ViewLayer *view_layer, int type, const char *name) ATTR_NONNULL(1
bool BKE_object_exists_check(struct Main *bmain, const struct Object *obtest)
void BKE_report(ReportList *reports, ReportType type, const char *message)
Definition: report.c:104
void BKE_reportf(ReportList *reports, ReportType type, const char *format,...) ATTR_PRINTF_FORMAT(3
struct MovieTrackingTrack * BKE_tracking_track_get_named(struct MovieTracking *tracking, struct MovieTrackingObject *object, const char *name)
Definition: tracking.c:1119
struct MovieTrackingObject * BKE_tracking_object_get_named(struct MovieTracking *tracking, const char *name)
Definition: tracking.c:2183
struct MovieTrackingObject * BKE_tracking_object_get_camera(struct MovieTracking *tracking)
Definition: tracking.c:2203
#define BLI_assert(a)
Definition: BLI_assert.h:58
A dynamically sized string ADT.
DynStr * BLI_dynstr_new(void) ATTR_MALLOC ATTR_WARN_UNUSED_RESULT
Definition: BLI_dynstr.c:71
void BLI_dynstr_free(DynStr *ds) ATTR_NONNULL()
Definition: BLI_dynstr.c:358
char * BLI_dynstr_get_cstring(DynStr *ds) ATTR_MALLOC ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
Definition: BLI_dynstr.c:323
void BLI_dynstr_append(DynStr *__restrict ds, const char *cstr) ATTR_NONNULL()
Definition: BLI_dynstr.c:107
#define LISTBASE_FOREACH(type, var, list)
Definition: BLI_listbase.h:172
void BLI_insertlinkafter(struct ListBase *listbase, void *vprevlink, void *vnewlink) ATTR_NONNULL(1)
Definition: listbase.c:352
void BLI_remlink(struct ListBase *listbase, void *vlink) ATTR_NONNULL(1)
Definition: listbase.c:133
void void void bool BLI_listbase_link_move(ListBase *listbase, void *vlink, int step) ATTR_NONNULL()
Definition: listbase.c:475
int BLI_findindex(const struct ListBase *listbase, const void *vlink) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
void BLI_insertlinkbefore(struct ListBase *listbase, void *vnextlink, void *vnewlink) ATTR_NONNULL(1)
Definition: listbase.c:395
int BLI_listbase_count(const struct ListBase *listbase) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
void unit_m4(float m[4][4])
Definition: rct.c:1140
void mul_v3_m4v3(float r[3], const float M[4][4], const float v[3])
Definition: math_matrix.c:742
MINLINE void copy_v3_v3(float r[3], const float a[3])
char * BLI_strncpy(char *__restrict dst, const char *__restrict src, const size_t maxncpy) ATTR_NONNULL()
Definition: string.c:108
#define UNUSED(x)
#define ELEM(...)
#define STREQ(a, b)
#define IFACE_(msgid)
int BPY_is_pyconstraint(struct Text *text)
void BPY_pyconstraint_update(struct Object *owner, struct bConstraint *con)
struct Depsgraph Depsgraph
Definition: DEG_depsgraph.h:51
void DEG_id_tag_update(struct ID *id, int flag)
void DEG_relations_tag_update(struct Main *bmain)
struct Scene * DEG_get_evaluated_scene(const struct Depsgraph *graph)
@ ID_RECALC_TRANSFORM
Definition: DNA_ID.h:599
@ ID_RECALC_COPY_ON_WRITE
Definition: DNA_ID.h:654
@ ID_RECALC_ANIMATION
Definition: DNA_ID.h:614
@ ID_RECALC_GEOMETRY
Definition: DNA_ID.h:611
#define ID_IS_LINKED(_id)
Definition: DNA_ID.h:426
@ ID_OB
Definition: DNA_ID_enums.h:59
@ PCHAN_HAS_CONST
@ PCHAN_HAS_IK
@ PCHAN_HAS_TARGET
@ PCHAN_HAS_SPLINEIK
@ FMODIFIER_TYPE_GENERATOR
@ CONSTRAINT_OFF
@ CONSTRAINT_ACTIVE
@ CONSTRAINT_DISABLE
@ CONSTRAINT_TYPE_TRACKTO
@ CONSTRAINT_TYPE_PIVOT
@ CONSTRAINT_TYPE_CHILDOF
@ CONSTRAINT_TYPE_FOLLOWTRACK
@ CONSTRAINT_TYPE_OBJECTSOLVER
@ CONSTRAINT_TYPE_ARMATURE
@ CONSTRAINT_TYPE_SHRINKWRAP
@ CONSTRAINT_TYPE_ROTLIMIT
@ CONSTRAINT_TYPE_CAMERASOLVER
@ CONSTRAINT_TYPE_SPLINEIK
@ CONSTRAINT_TYPE_PYTHON
@ CONSTRAINT_TYPE_KINEMATIC
@ CONSTRAINT_TYPE_NULL
@ CONSTRAINT_TYPE_DISTLIMIT
@ CONSTRAINT_TYPE_LOCLIMIT
@ CONSTRAINT_TYPE_CLAMPTO
@ CONSTRAINT_TYPE_LOCKTRACK
@ CONSTRAINT_TYPE_SIZELIMIT
@ CONSTRAINT_TYPE_ACTION
@ CONSTRAINT_TYPE_FOLLOWPATH
@ CONSTRAINT_TYPE_STRETCHTO
@ CONSTRAINT_TYPE_SAMEVOL
@ CONSTRAINT_TYPE_TRANSFORM_CACHE
@ CONSTRAINT_OBTYPE_OBJECT
@ CONSTRAINT_OBTYPE_BONE
@ CAMERASOLVER_ACTIVECLIP
@ ACTCON_USE_EVAL_TIME
@ FOLLOWPATH_STATIC
@ CONSTRAINT_SPLINEIK_BOUND
@ OBJECTSOLVER_SET_INVERSE
@ CHILDOF_SET_INVERSE
@ CU_PATH
#define MAX_NAME
Definition: DNA_defs.h:62
@ OB_MODE_POSE
Object is a sort of wrapper for general info.
@ OB_EMPTY
@ OB_ARMATURE
@ OB_MESH
@ OB_CURVE
#define MINAFRAME
#define BASACT(_view_layer)
#define MAXFRAME
@ OPERATOR_CANCELLED
@ OPERATOR_INTERFACE
@ OPERATOR_FINISHED
@ OPERATOR_PASS_THROUGH
void ED_object_base_select(struct Base *base, eObjectSelect_Mode mode)
Definition: object_select.c:98
struct Object * ED_object_active_context(const struct bContext *C)
@ BA_SELECT
Definition: ED_object.h:147
bool ED_operator_object_active_local_editable(struct bContext *C)
Definition: screen_ops.c:378
bool ED_operator_object_active_editable(struct bContext *C)
Definition: screen_ops.c:366
bool ED_operator_posemode_exclusive(struct bContext *C)
check for pose mode (no mixed modes)
Definition: screen_ops.c:453
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum type
Read Guarded memory(de)allocation.
#define MEM_SAFE_FREE(v)
StructRNA RNA_Constraint
StructRNA RNA_FollowPathConstraint
@ PROP_SKIP_SAVE
Definition: RNA_types.h:204
@ PROP_HIDDEN
Definition: RNA_types.h:202
#define C
Definition: RandGen.cpp:39
void uiItemBooleanO(uiLayout *layout, const char *name, int icon, const char *opname, const char *propname, int value)
struct uiLayout * UI_popup_menu_layout(uiPopupMenu *pup)
struct PointerRNA * UI_region_panel_custom_data_under_cursor(const struct bContext *C, const struct wmEvent *event)
void UI_popup_menu_end(struct bContext *C, struct uiPopupMenu *pup)
uiPopupMenu * UI_popup_menu_begin(struct bContext *C, const char *title, int icon) ATTR_NONNULL()
@ OPTYPE_UNDO
Definition: WM_types.h:155
@ OPTYPE_REGISTER
Definition: WM_types.h:153
#define NA_ADDED
Definition: WM_types.h:464
#define ND_CONSTRAINT
Definition: WM_types.h:365
#define NA_REMOVED
Definition: WM_types.h:465
#define NC_OBJECT
Definition: WM_types.h:280
#define A
Scene scene
const Depsgraph * depsgraph
#define str(s)
bAction * ED_id_action_ensure(Main *bmain, ID *id)
Definition: keyframing.c:136
FCurve * ED_action_fcurve_ensure(struct Main *bmain, struct bAction *act, const char group[], struct PointerRNA *ptr, const char rna_path[], const int array_index)
Definition: keyframing.c:194
void(* MEM_freeN)(void *vmemh)
Definition: mallocn.c:41
static ulong * next
#define B
static void add(GHash *messages, MemArena *memarena, const Message *msg)
Definition: msgfmt.c:268
void CONSTRAINT_OT_move_to_index(wmOperatorType *ot)
static int constraint_add_exec(bContext *C, wmOperator *op, Object *ob, ListBase *list, int type, const bool setTarget)
static int followpath_path_animate_exec(bContext *C, wmOperator *op)
static int followpath_path_animate_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event))
static const EnumPropertyItem constraint_owner_items[]
static bool edit_constraint_invoke_properties(bContext *C, wmOperator *op, const wmEvent *event, int *r_retval)
static int stretchto_reset_exec(bContext *C, wmOperator *op)
void ED_object_constraint_active_set(Object *ob, bConstraint *con)
void ED_object_constraint_update(Main *bmain, Object *ob)
static void set_constraint_nth_target(bConstraint *con, Object *target, const char subtarget[], int index)
void OBJECT_OT_constraints_copy(wmOperatorType *ot)
void ED_object_constraint_tag_update(Main *bmain, Object *ob, bConstraint *con)
void ED_object_constraint_copy_for_pose(Main *bmain, Object *ob_dst, bPoseChannel *pchan, bConstraint *con)
static int constraint_move_to_index_exec(bContext *C, wmOperator *op)
static int object_constraints_clear_exec(bContext *C, wmOperator *UNUSED(op))
void ED_object_constraint_copy_for_object(Main *bmain, Object *ob_dst, bConstraint *con)
static void force_evaluation_if_constraint_disabled(bContext *C, Object *ob, bConstraint *con)
void OBJECT_OT_constraint_add_with_targets(wmOperatorType *ot)
static int childof_clear_inverse_exec(bContext *C, wmOperator *op)
static bool edit_constraint_liboverride_allowed_poll(bContext *C)
static int object_constraint_add_exec(bContext *C, wmOperator *op)
void CONSTRAINT_OT_delete(wmOperatorType *ot)
void CONSTRAINT_OT_stretchto_reset(wmOperatorType *ot)
static int stretchto_reset_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event))
static bool edit_constraint_poll_generic(bContext *C, StructRNA *rna_type, const bool is_liboverride_allowed)
static void object_test_constraint(Main *bmain, Object *ob, bConstraint *con)
bool ED_object_constraint_move_to_index(Object *ob, bConstraint *con, const int index)
void POSE_OT_constraints_copy(wmOperatorType *ot)
#define EDIT_CONSTRAINT_OWNER_BONE
static int constraint_move_up_invoke(bContext *C, wmOperator *op, const wmEvent *event)
static int objectsolver_set_inverse_exec(bContext *C, wmOperator *op)
#define EDIT_CONSTRAINT_OWNER_OBJECT
static int constraint_move_down_exec(bContext *C, wmOperator *op)
void CONSTRAINT_OT_objectsolver_set_inverse(wmOperatorType *ot)
void OBJECT_OT_constraints_clear(wmOperatorType *ot)
void CONSTRAINT_OT_limitdistance_reset(wmOperatorType *ot)
static int objectsolver_set_inverse_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event))
void CONSTRAINT_OT_move_down(wmOperatorType *ot)
static int childof_set_inverse_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event))
static const EnumPropertyItem * object_constraint_add_itemf(bContext *UNUSED(C), PointerRNA *UNUSED(ptr), PropertyRNA *UNUSED(prop), bool *r_free)
bConstraint * ED_object_constraint_active_get(Object *ob)
static void object_pose_tag_update(Main *bmain, Object *ob)
void POSE_OT_constraints_clear(wmOperatorType *ot)
static int pose_constraint_add_exec(bContext *C, wmOperator *op)
static int objectsolver_clear_inverse_exec(bContext *C, wmOperator *op)
void OBJECT_OT_constraint_add(wmOperatorType *ot)
static int constraint_move_to_index_invoke(bContext *C, wmOperator *op, const wmEvent *event)
void ED_object_constraint_dependency_update(Main *bmain, Object *ob)
static void edit_constraint_report_property(wmOperatorType *ot)
static int pose_ik_clear_exec(bContext *C, wmOperator *UNUSED(op))
void ED_object_constraint_link(Main *bmain, Object *ob_dst, ListBase *dst, ListBase *src)
static int limitdistance_reset_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event))
static void test_constraint(Main *bmain, Object *owner, bPoseChannel *pchan, bConstraint *con, int type)
void CONSTRAINT_OT_move_up(wmOperatorType *ot)
static int object_constraint_copy_exec(bContext *C, wmOperator *UNUSED(op))
static bool edit_constraint_poll(bContext *C)
static void test_constraints(Main *bmain, Object *ob, bPoseChannel *pchan)
void POSE_OT_constraint_add_with_targets(wmOperatorType *ot)
static int pose_ik_add_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event))
void ED_object_constraint_dependency_tag_update(Main *bmain, Object *ob, bConstraint *con)
static int limitdistance_reset_exec(bContext *C, wmOperator *op)
static int pose_constraints_clear_exec(bContext *C, wmOperator *UNUSED(op))
static int objectsolver_clear_inverse_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event))
static bool get_new_constraint_target(bContext *C, int con_type, Object **tar_ob, bPoseChannel **tar_pchan, bool add)
static int constraint_delete_invoke(bContext *C, wmOperator *op, const wmEvent *event)
static int childof_clear_inverse_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event))
static int childof_set_inverse_exec(bContext *C, wmOperator *op)
static int pose_constraint_copy_exec(bContext *C, wmOperator *op)
static int pose_ik_add_exec(bContext *C, wmOperator *op)
void POSE_OT_constraint_add(wmOperatorType *ot)
void POSE_OT_ik_add(wmOperatorType *ot)
static int constraint_move_down_invoke(bContext *C, wmOperator *op, const wmEvent *event)
ListBase * ED_object_constraint_active_list(Object *ob)
ListBase * ED_object_constraint_list_from_constraint(Object *ob, bConstraint *con, bPoseChannel **r_pchan)
static void edit_constraint_properties(wmOperatorType *ot)
void POSE_OT_ik_clear(wmOperatorType *ot)
ListBase * ED_object_pose_constraint_list(const bContext *C)
static int constraint_move_up_exec(bContext *C, wmOperator *op)
void object_test_constraints(Main *bmain, Object *ob)
static int constraint_delete_exec(bContext *C, wmOperator *op)
void CONSTRAINT_OT_followpath_path_animate(wmOperatorType *ot)
void CONSTRAINT_OT_childof_set_inverse(wmOperatorType *ot)
static int constraint_type_get(Object *owner, bPoseChannel *pchan)
void CONSTRAINT_OT_objectsolver_clear_inverse(wmOperatorType *ot)
static bConstraint * edit_constraint_property_get(bContext *C, wmOperator *op, Object *ob, int type)
void CONSTRAINT_OT_childof_clear_inverse(wmOperatorType *ot)
bool RNA_struct_is_a(const StructRNA *type, const StructRNA *srna)
Definition: rna_access.c:844
void RNA_pointer_create(ID *id, StructRNA *type, void *data, PointerRNA *r_ptr)
Definition: rna_access.c:146
void RNA_string_set(PointerRNA *ptr, const char *name, const char *value)
Definition: rna_access.c:6550
PropertyRNA * RNA_struct_find_property(PointerRNA *ptr, const char *identifier)
Definition: rna_access.c:866
char * RNA_path_from_ID_to_property(PointerRNA *ptr, PropertyRNA *prop)
Definition: rna_access.c:6027
void RNA_string_get(PointerRNA *ptr, const char *name, char *value)
Definition: rna_access.c:6514
int RNA_int_get(PointerRNA *ptr, const char *name)
Definition: rna_access.c:6308
bool RNA_pointer_is_null(const PointerRNA *ptr)
Definition: rna_access.c:174
bool RNA_struct_property_is_set(PointerRNA *ptr, const char *identifier)
Definition: rna_access.c:6685
bool RNA_boolean_get(PointerRNA *ptr, const char *name)
Definition: rna_access.c:6261
void RNA_enum_set(PointerRNA *ptr, const char *name, int value)
Definition: rna_access.c:6413
int RNA_enum_get(PointerRNA *ptr, const char *name)
Definition: rna_access.c:6402
const EnumPropertyItem rna_enum_constraint_type_items[]
PropertyRNA * RNA_def_boolean(StructOrFunctionRNA *cont_, const char *identifier, bool default_value, const char *ui_name, const char *ui_description)
Definition: rna_define.c:3481
void RNA_enum_item_end(EnumPropertyItem **items, int *totitem)
Definition: rna_define.c:4470
void RNA_enum_item_add(EnumPropertyItem **items, int *totitem, const EnumPropertyItem *item)
Definition: rna_define.c:4416
PropertyRNA * RNA_def_string(StructOrFunctionRNA *cont_, const char *identifier, const char *default_value, int maxlen, const char *ui_name, const char *ui_description)
Definition: rna_define.c:3675
void RNA_def_property_flag(PropertyRNA *prop, PropertyFlag flag)
Definition: rna_define.c:1512
PropertyRNA * RNA_def_int(StructOrFunctionRNA *cont_, const char *identifier, int default_value, int hardmin, int hardmax, const char *ui_name, const char *ui_description, int softmin, int softmax)
Definition: rna_define.c:3585
void RNA_def_enum_funcs(PropertyRNA *prop, EnumPropertyItemFunc itemfunc)
Definition: rna_define.c:3819
PropertyRNA * RNA_def_enum(StructOrFunctionRNA *cont_, const char *identifier, const EnumPropertyItem *items, int default_value, const char *ui_name, const char *ui_description)
Definition: rna_define.c:3771
const EnumPropertyItem DummyRNA_NULL_items[]
Definition: rna_rna.c:40
bAction * action
struct AnimData * adt
const char * identifier
Definition: RNA_types.h:446
FPoint * fpt
BezTriple * bezt
ListBase modifiers
float * coefficients
void * data
Definition: DNA_ID.h:273
void * next
Definition: DNA_ID.h:274
char name[66]
Definition: DNA_ID.h:283
void * first
Definition: DNA_listBase.h:47
Definition: BKE_main.h:116
ListBase texts
Definition: BKE_main.h:163
ListBase constraints
struct bPose * pose
struct Object * proxy
float loc[3]
float obmat[4][4]
struct AnimData * adt
void * data
struct StructRNA * type
Definition: RNA_types.h:51
void * data
Definition: RNA_types.h:52
struct ID * owner_id
Definition: RNA_types.h:50
ListBase curves
struct bConstraintTarget * next
int(* get_constraint_targets)(struct bConstraint *con, struct ListBase *list)
void(* flush_constraint_targets)(struct bConstraint *con, struct ListBase *list, bool no_copy)
struct bConstraint * prev
struct bConstraint * next
ListBase constraints
float pose_head[3]
float pose_tail[3]
struct bPoseChannel * next
ListBase chanbase
int(* invoke)(struct bContext *, struct wmOperator *, const struct wmEvent *) ATTR_WARN_UNUSED_RESULT
Definition: WM_types.h:752
const char * name
Definition: WM_types.h:721
const char * idname
Definition: WM_types.h:723
bool(* poll)(struct bContext *) ATTR_WARN_UNUSED_RESULT
Definition: WM_types.h:776
struct StructRNA * srna
Definition: WM_types.h:802
const char * description
Definition: WM_types.h:726
int(* exec)(struct bContext *, struct wmOperator *) ATTR_WARN_UNUSED_RESULT
Definition: WM_types.h:736
PropertyRNA * prop
Definition: WM_types.h:814
struct ReportList * reports
struct PointerRNA * ptr
__forceinline const avxi abs(const avxi &a)
Definition: util_avxi.h:186
#define G(x, y, z)
uint len
void WM_main_add_notifier(unsigned int type, void *reference)
void WM_event_add_notifier(const bContext *C, uint type, void *reference)
PointerRNA * ptr
Definition: wm_files.c:3157
wmOperatorType * ot
Definition: wm_files.c:3156
int WM_menu_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event))
Definition: wm_operators.c:982