Blender V4.5
object_constraint.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2001-2002 NaN Holding BV. All rights reserved.
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
9#include <algorithm>
10#include <cstdio>
11#include <cstring>
12
13#include "MEM_guardedalloc.h"
14
15#include "BLI_dynstr.h"
16#include "BLI_listbase.h"
17#include "BLI_math_matrix.h"
18#include "BLI_math_vector.h"
19#include "BLI_string.h"
20#include "BLI_utildefines.h"
21
22#include "BLT_translation.hh"
23
24#include "DNA_anim_types.h"
25#include "DNA_armature_types.h"
27#include "DNA_curve_types.h"
28#include "DNA_object_types.h"
29#include "DNA_scene_types.h"
30#include "DNA_text_types.h"
31
32#include "BIK_api.h"
33#include "BKE_action.hh"
34#include "BKE_armature.hh"
35#include "BKE_constraint.h"
36#include "BKE_context.hh"
37#include "BKE_fcurve.hh"
38#include "BKE_layer.hh"
39#include "BKE_library.hh"
40#include "BKE_main.hh"
41#include "BKE_object.hh"
42#include "BKE_report.hh"
43#include "BKE_tracking.h"
44
45#include "DEG_depsgraph.hh"
48
49#ifdef WITH_PYTHON
50# include "BPY_extern.hh"
51#endif
52
53#include "WM_api.hh"
54#include "WM_types.hh"
55
56#include "RNA_access.hh"
57#include "RNA_define.hh"
58#include "RNA_enum_types.hh"
59#include "RNA_path.hh"
60#include "RNA_prototypes.hh"
61
62#include "ED_object.hh"
63#include "ED_screen.hh"
64
65#include "ANIM_action.hh"
66#include "ANIM_action_legacy.hh"
67#include "ANIM_animdata.hh"
68
69#include "UI_interface.hh"
70#include "UI_resources.hh"
71
72#include "object_intern.hh"
73
74namespace blender::ed::object {
75
76/* ------------------------------------------------------------------- */
79
81{
82 if (ob == nullptr) {
83 return nullptr;
84 }
85
86 if (ob->mode & OB_MODE_POSE) {
87 bPoseChannel *pchan;
88
90 if (pchan) {
91 return &pchan->constraints;
92 }
93 }
94 else {
95 return &ob->constraints;
96 }
97
98 return nullptr;
99}
100
102{
103 bPoseChannel *pose_bone = static_cast<bPoseChannel *>(CTX_data_pointer_get(C, "pose_bone").data);
104 if (pose_bone == nullptr) {
105 pose_bone = static_cast<bPoseChannel *>(CTX_data_pointer_get(C, "active_pose_bone").data);
106 if (pose_bone == nullptr) {
107 return nullptr;
108 }
109 }
110
111 return &pose_bone->constraints;
112}
113
115{
116 if (r_pchan) {
117 *r_pchan = nullptr;
118 }
119
120 if (ELEM(nullptr, ob, con)) {
121 return nullptr;
122 }
123
124 /* try object constraints first */
125 if (BLI_findindex(&ob->constraints, con) != -1) {
126 return &ob->constraints;
127 }
128
129 /* if armature, try pose bones too */
130 if (ob->pose) {
131 /* try each bone in order
132 * NOTE: it's not possible to directly look up the active bone yet, so this will have to do
133 */
134 LISTBASE_FOREACH (bPoseChannel *, pchan, &ob->pose->chanbase) {
135 if (BLI_findindex(&pchan->constraints, con) != -1) {
136
137 if (r_pchan) {
138 *r_pchan = pchan;
139 }
140
141 return &pchan->constraints;
142 }
143 }
144 }
145
146 /* done */
147 return nullptr;
148}
149
154
156
157/* ------------------------------------------------------------------- */
160
161/* helper function for add_constriant - sets the last target for the active constraint */
163 Object *target,
164 const char subtarget[],
165 int index)
166{
167 ListBase targets = {nullptr, nullptr};
169 int targets_num, i;
170
171 if (BKE_constraint_targets_get(con, &targets)) {
172 targets_num = BLI_listbase_count(&targets);
173
174 if (index < 0) {
175 if (abs(index) < targets_num) {
176 index = targets_num - abs(index);
177 }
178 else {
179 index = targets_num - 1;
180 }
181 }
182 else if (index >= targets_num) {
183 index = targets_num - 1;
184 }
185
186 for (ct = static_cast<bConstraintTarget *>(targets.first), i = 0; ct; ct = ct->next, i++) {
187 if (i == index) {
188 ct->tar = target;
189 STRNCPY(ct->subtarget, subtarget);
190 break;
191 }
192 }
193
194 BKE_constraint_targets_flush(con, &targets, false);
195 }
196}
197
199
200/* ------------------------------------------------------------------- */
203
204static void test_constraint(
205 Main *bmain, Object *owner, bPoseChannel *pchan, bConstraint *con, int type)
206{
207 ListBase targets = {nullptr, nullptr};
208 bool check_targets = true;
209
210 /* clear disabled-flag first */
212
213 if (con->type == CONSTRAINT_TYPE_KINEMATIC) {
214 bKinematicConstraint *data = static_cast<bKinematicConstraint *>(con->data);
215
216 /* Bad: we need a separate set of checks here as pole-target is optional...
217 * otherwise pole-target must exist too or else the constraint is deemed invalid. */
218
219 /* default IK check ... */
220 if (BKE_object_exists_check(bmain, data->tar) == 0) {
221 data->tar = nullptr;
222 con->flag |= CONSTRAINT_DISABLE;
223 }
224 else if (data->tar == owner) {
226 con->flag |= CONSTRAINT_DISABLE;
227 }
228 }
229
230 if (data->poletar) {
231 if (BKE_object_exists_check(bmain, data->poletar) == 0) {
232 data->poletar = nullptr;
233 con->flag |= CONSTRAINT_DISABLE;
234 }
235 else if (data->poletar == owner) {
236 if (!BKE_armature_find_bone_name(BKE_armature_from_object(owner), data->polesubtarget)) {
237 con->flag |= CONSTRAINT_DISABLE;
238 }
239 }
240 }
241 /* ... can be overwritten here */
242 BIK_test_constraint(owner, con);
243 /* targets have already been checked for this */
244 check_targets = false;
245 }
246 else if (con->type == CONSTRAINT_TYPE_PIVOT) {
247 bPivotConstraint *data = static_cast<bPivotConstraint *>(con->data);
248
249 /* target doesn't have to exist, but if it is non-null, it must exist! */
250 if (data->tar && BKE_object_exists_check(bmain, data->tar) == 0) {
251 data->tar = nullptr;
252 con->flag |= CONSTRAINT_DISABLE;
253 }
254 else if (data->tar == owner) {
256 con->flag |= CONSTRAINT_DISABLE;
257 }
258 }
259
260 /* targets have already been checked for this */
261 check_targets = false;
262 }
263 else if (con->type == CONSTRAINT_TYPE_ACTION) {
264 bActionConstraint *data = static_cast<bActionConstraint *>(con->data);
265
266 /* validate action */
267 if (data->act == nullptr) {
268 /* must have action */
269 con->flag |= CONSTRAINT_DISABLE;
270 }
271 else {
273 if (!ELEM(data->act->idroot, ID_OB, 0)) {
274 /* Only object-rooted actions can be used. */
275 data->act = nullptr;
276 con->flag |= CONSTRAINT_DISABLE;
277 }
278 }
279 else {
280 /* The slot was assigned, so assume that it is suitable to animate the
281 * owner (only suitable slots appear in the drop-down). */
282 animrig::Action &action = data->act->wrap();
283 animrig::Slot *slot = action.slot_for_handle(data->action_slot_handle);
284 if (!slot) {
285 con->flag |= CONSTRAINT_DISABLE;
286 }
287 }
288 }
289
290 /* Skip target checking if we're not using it */
291 if (data->flag & ACTCON_USE_EVAL_TIME) {
292 check_targets = false;
293 }
294 }
295 else if (con->type == CONSTRAINT_TYPE_FOLLOWPATH) {
297
298 /* don't allow track/up axes to be the same */
299 if (data->upflag == data->trackflag) {
300 con->flag |= CONSTRAINT_DISABLE;
301 }
302 if (data->upflag + 3 == data->trackflag) {
303 con->flag |= CONSTRAINT_DISABLE;
304 }
305 }
306 else if (con->type == CONSTRAINT_TYPE_TRACKTO) {
307 bTrackToConstraint *data = static_cast<bTrackToConstraint *>(con->data);
308
309 /* don't allow track/up axes to be the same */
310 if (data->reserved2 == data->reserved1) {
311 con->flag |= CONSTRAINT_DISABLE;
312 }
313 if (data->reserved2 + 3 == data->reserved1) {
314 con->flag |= CONSTRAINT_DISABLE;
315 }
316 }
317 else if (con->type == CONSTRAINT_TYPE_LOCKTRACK) {
318 bLockTrackConstraint *data = static_cast<bLockTrackConstraint *>(con->data);
319
320 if (data->lockflag == data->trackflag) {
321 con->flag |= CONSTRAINT_DISABLE;
322 }
323 if (data->lockflag + 3 == data->trackflag) {
324 con->flag |= CONSTRAINT_DISABLE;
325 }
326 }
327 else if (con->type == CONSTRAINT_TYPE_SPLINEIK) {
328 bSplineIKConstraint *data = static_cast<bSplineIKConstraint *>(con->data);
329
330 /* if the number of points does not match the amount required by the chain length,
331 * free the points array and request a rebind...
332 */
333 if ((data->points == nullptr) || (data->numpoints != data->chainlen + 1)) {
334 MEM_SAFE_FREE(data->points);
335 data->numpoints = 0;
336
337 /* clear the bound flag, forcing a rebind next time this is evaluated */
339 }
340 }
341 else if (con->type == CONSTRAINT_TYPE_FOLLOWTRACK) {
343
344 if ((data->flag & CAMERASOLVER_ACTIVECLIP) == 0) {
345 if (data->clip != nullptr && data->track[0]) {
346 MovieTracking *tracking = &data->clip->tracking;
347 MovieTrackingObject *tracking_object;
348
349 if (data->object[0]) {
350 tracking_object = BKE_tracking_object_get_named(tracking, data->object);
351 }
352 else {
353 tracking_object = BKE_tracking_object_get_camera(tracking);
354 }
355
356 if (!tracking_object) {
357 con->flag |= CONSTRAINT_DISABLE;
358 }
359 else {
360 if (!BKE_tracking_object_find_track_with_name(tracking_object, data->track)) {
361 con->flag |= CONSTRAINT_DISABLE;
362 }
363 }
364 }
365 else {
366 con->flag |= CONSTRAINT_DISABLE;
367 }
368 }
369 }
370 else if (con->type == CONSTRAINT_TYPE_CAMERASOLVER) {
372
373 if ((data->flag & CAMERASOLVER_ACTIVECLIP) == 0 && (data->clip == nullptr)) {
374 con->flag |= CONSTRAINT_DISABLE;
375 }
376 }
377 else if (con->type == CONSTRAINT_TYPE_OBJECTSOLVER) {
379
380 if ((data->flag & CAMERASOLVER_ACTIVECLIP) == 0 && (data->clip == nullptr)) {
381 con->flag |= CONSTRAINT_DISABLE;
382 }
383 }
384 else if (con->type == CONSTRAINT_TYPE_TRANSFORM_CACHE) {
386
387 if ((data->cache_file == nullptr) || (data->object_path[0] == '\0')) {
388 con->flag |= CONSTRAINT_DISABLE;
389 }
390 }
391
392 /* Check targets for constraints */
393 if (check_targets && BKE_constraint_targets_get(con, &targets)) {
394 /* disable and clear constraints targets that are incorrect */
395 LISTBASE_FOREACH (bConstraintTarget *, ct, &targets) {
396 /* general validity checks (for those constraints that need this) */
397 if (BKE_object_exists_check(bmain, ct->tar) == 0) {
398 /* object doesn't exist, but constraint requires target */
399 ct->tar = nullptr;
400 con->flag |= CONSTRAINT_DISABLE;
401 }
402 else if (ct->tar == owner) {
403 if (type == CONSTRAINT_OBTYPE_BONE) {
404 if (!BKE_armature_find_bone_name(BKE_armature_from_object(owner), ct->subtarget)) {
405 /* bone must exist in armature... */
406 /* TODO: clear subtarget? */
407 con->flag |= CONSTRAINT_DISABLE;
408 }
409 else if (STREQ(pchan->name, ct->subtarget)) {
410 /* cannot target self */
411 ct->subtarget[0] = '\0';
412 con->flag |= CONSTRAINT_DISABLE;
413 }
414 }
415 else {
416 /* cannot use self as target */
417 ct->tar = nullptr;
418 con->flag |= CONSTRAINT_DISABLE;
419 }
420 }
421
422 /* target checks for specific constraints */
423 if (ELEM(con->type,
427 {
428 if (ct->tar) {
429 /* The object type check is only needed here in case we have a placeholder
430 * object assigned (because the library containing the curve is missing).
431 *
432 * In other cases it should be impossible to have a type mismatch.
433 */
434 if (ct->tar->type != OB_CURVES_LEGACY) {
435 con->flag |= CONSTRAINT_DISABLE;
436 }
437 else {
438 Curve *cu = static_cast<Curve *>(ct->tar->data);
439
440 /* auto-set 'Path' setting on curve so this works. */
441 cu->flag |= CU_PATH;
442 }
443 }
444 }
445 else if (con->type == CONSTRAINT_TYPE_ARMATURE) {
446 if (ct->tar) {
447 /* The object type check is only needed here in case we have a placeholder
448 * object assigned (because the library containing the armature is missing).
449 *
450 * In other cases it should be impossible to have a type mismatch.
451 */
452 if (ct->tar->type != OB_ARMATURE) {
453 con->flag |= CONSTRAINT_DISABLE;
454 }
455 else if (!BKE_armature_find_bone_name(BKE_armature_from_object(ct->tar), ct->subtarget))
456 {
457 /* bone must exist in armature... */
458 con->flag |= CONSTRAINT_DISABLE;
459 }
460 }
461 }
462 }
463
464 /* free any temporary targets */
465 BKE_constraint_targets_flush(con, &targets, false);
466 }
467 else if (check_targets) {
468 /* constraints with empty target list that actually require targets */
470 con->flag |= CONSTRAINT_DISABLE;
471 }
472 }
473}
474
475static int constraint_type_get(Object *owner, bPoseChannel *pchan)
476{
477 int type;
478 /* Check parents */
479 if (pchan) {
480 switch (owner->type) {
481 case OB_ARMATURE:
483 break;
484 default:
486 break;
487 }
488 }
489 else {
491 }
492 return type;
493}
494
495/* checks validity of object pointers, and NULLs,
496 * if Bone doesn't exist it sets the CONSTRAINT_DISABLE flag.
497 */
498static void test_constraints(Main *bmain, Object *ob, bPoseChannel *pchan)
499{
500 ListBase *conlist = nullptr;
501 int type;
502
503 if (ob == nullptr) {
504 return;
505 }
506
507 type = constraint_type_get(ob, pchan);
508
509 /* Get the constraint list for this object */
510 switch (type) {
512 conlist = &ob->constraints;
513 break;
515 conlist = &pchan->constraints;
516 break;
517 }
518
519 /* Check all constraints - is constraint valid? */
520 if (conlist) {
521 LISTBASE_FOREACH (bConstraint *, curcon, conlist) {
522 test_constraint(bmain, ob, pchan, curcon, type);
523 }
524 }
525}
526
528{
529 if (ob->constraints.first) {
530 test_constraints(bmain, ob, nullptr);
531 }
532
533 if (ob->type == OB_ARMATURE && ob->pose) {
534 LISTBASE_FOREACH (bPoseChannel *, pchan, &ob->pose->chanbase) {
535 if (pchan->constraints.first) {
536 test_constraints(bmain, ob, pchan);
537 }
538 }
539 }
540}
541
542static void object_test_constraint(Main *bmain, Object *ob, bConstraint *con)
543{
544 if (ob->type == OB_ARMATURE && ob->pose) {
545 if (BLI_findindex(&ob->constraints, con) != -1) {
546 test_constraint(bmain, ob, nullptr, con, CONSTRAINT_OBTYPE_OBJECT);
547 }
548 else {
549 LISTBASE_FOREACH (bPoseChannel *, pchan, &ob->pose->chanbase) {
550 if (BLI_findindex(&pchan->constraints, con) != -1) {
551 test_constraint(bmain, ob, pchan, con, CONSTRAINT_OBTYPE_BONE);
552 break;
553 }
554 }
555 }
556 }
557 else {
558 test_constraint(bmain, ob, nullptr, con, CONSTRAINT_OBTYPE_OBJECT);
559 }
560}
561
563
564/* ------------------------------------------------------------------- */
567
568#define EDIT_CONSTRAINT_OWNER_OBJECT 0
569#define EDIT_CONSTRAINT_OWNER_BONE 1
570
573 "OBJECT",
574 0,
575 "Object",
576 "Edit a constraint on the active object"},
577 {EDIT_CONSTRAINT_OWNER_BONE, "BONE", 0, "Bone", "Edit a constraint on the active bone"},
578 {0, nullptr, 0, nullptr, nullptr},
579};
580
582 StructRNA *rna_type,
583 const bool is_liboverride_allowed)
584{
585 PointerRNA ptr = CTX_data_pointer_get_type(C, "constraint", rna_type);
586 Object *ob = (ptr.owner_id) ? (Object *)ptr.owner_id : context_active_object(C);
587 bConstraint *con = static_cast<bConstraint *>(ptr.data);
588
590 return false;
591 }
592
593 if (ptr.owner_id != nullptr && !ID_IS_EDITABLE(ptr.owner_id)) {
594 CTX_wm_operator_poll_msg_set(C, "Cannot edit library data");
595 return false;
596 }
597
598 if (!is_liboverride_allowed && BKE_constraint_is_nonlocal_in_liboverride(ob, con)) {
600 C, "Cannot edit constraints coming from linked data in a library override");
601 return false;
602 }
603
604 return true;
605}
606
608{
609 return edit_constraint_poll_generic(C, &RNA_Constraint, false);
610}
611
612/* Used by operators performing actions allowed also on constraints from the overridden linked
613 * object (not only from added 'local' ones). */
615{
616 return edit_constraint_poll_generic(C, &RNA_Constraint, true);
617}
618
620{
621 PropertyRNA *prop;
622 prop = RNA_def_string(
623 ot->srna, "constraint", nullptr, MAX_NAME, "Constraint", "Name of the constraint to edit");
625 prop = RNA_def_enum(
626 ot->srna, "owner", constraint_owner_items, 0, "Owner", "The owner of this constraint");
628}
629
631{
633 ot->srna, "report", false, "Report", "Create a notification after the operation");
635}
636
638 wmOperator *op,
639 const wmEvent *event,
640 wmOperatorStatus *r_retval)
641{
642 PointerRNA ptr = CTX_data_pointer_get_type(C, "constraint", &RNA_Constraint);
643 Object *ob = (ptr.owner_id) ? (Object *)ptr.owner_id : context_active_object(C);
644 bConstraint *con;
645 ListBase *list;
646
647 if (RNA_struct_property_is_set(op->ptr, "constraint") &&
648 RNA_struct_property_is_set(op->ptr, "owner"))
649 {
650 return true;
651 }
652
653 if (ptr.data) {
654 con = static_cast<bConstraint *>(ptr.data);
655 RNA_string_set(op->ptr, "constraint", con->name);
656
657 list = constraint_list_from_constraint(ob, con, nullptr);
658
659 if (&ob->constraints == list) {
661 }
662 else {
664 }
665
666 return true;
667 }
668
669 /* Check the custom data of panels under the mouse for a modifier. */
670 if (event != nullptr) {
672
673 if (!(panel_ptr == nullptr || RNA_pointer_is_null(panel_ptr))) {
674 if (RNA_struct_is_a(panel_ptr->type, &RNA_Constraint)) {
675 con = static_cast<bConstraint *>(panel_ptr->data);
676 RNA_string_set(op->ptr, "constraint", con->name);
677 list = constraint_list_from_constraint(ob, con, nullptr);
678 RNA_enum_set(op->ptr,
679 "owner",
682
683 return true;
684 }
685
686 BLI_assert(r_retval != nullptr); /* We need the return value in this case. */
687 if (r_retval != nullptr) {
689 }
690 return false;
691 }
692 }
693
694 if (r_retval != nullptr) {
695 *r_retval = OPERATOR_CANCELLED;
696 }
697 return false;
698}
699
701{
702 char constraint_name[MAX_NAME];
703 int owner = RNA_enum_get(op->ptr, "owner");
704 bConstraint *con;
705 ListBase *list = nullptr;
706
707 RNA_string_get(op->ptr, "constraint", constraint_name);
708
709 if (owner == EDIT_CONSTRAINT_OWNER_BONE) {
710 list = pose_constraint_list(C);
711 if (!list) {
712 return nullptr;
713 }
714 }
715 else {
716 list = &ob->constraints;
717 }
718
719 con = BKE_constraints_find_name(list, constraint_name);
720#if 0
721 if (G.debug & G_DEBUG) {
722 printf("constraint found = %p, %s\n", (void *)con, (con) ? con->name : "<Not found>");
723 }
724#endif
725
726 if (con && (type != 0) && (con->type != type)) {
727 con = nullptr;
728 }
729
730 return con;
731}
732
734
735/* ------------------------------------------------------------------- */
740
742{
743 Main *bmain = CTX_data_main(C);
746 bStretchToConstraint *data = (con) ? (bStretchToConstraint *)con->data : nullptr;
747
748 /* despite 3 layers of checks, we may still not be able to find a constraint */
749 if (data == nullptr) {
750 return OPERATOR_CANCELLED;
751 }
752
753 /* just set original length to 0.0, which will cause a reset on next recalc */
754 data->orglength = 0.0f;
755 constraint_update(bmain, ob);
756
758 return OPERATOR_FINISHED;
759}
760
762 wmOperator *op,
763 const wmEvent * /*event*/)
764{
765 if (edit_constraint_invoke_properties(C, op, nullptr, nullptr)) {
766 return stretchto_reset_exec(C, op);
767 }
768 return OPERATOR_CANCELLED;
769}
770
772{
773 /* identifiers */
774 ot->name = "Reset Original Length";
775 ot->idname = "CONSTRAINT_OT_stretchto_reset";
776 ot->description = "Reset original length of bone for Stretch To Constraint";
777
778 /* callbacks */
779 ot->invoke = stretchto_reset_invoke;
780 ot->exec = stretchto_reset_exec;
782
783 /* flags */
785
786 /* properties */
788}
789
791
792/* ------------------------------------------------------------------- */
797
799{
800 Main *bmain = CTX_data_main(C);
803 bDistLimitConstraint *data = (con) ? (bDistLimitConstraint *)con->data : nullptr;
804
805 /* despite 3 layers of checks, we may still not be able to find a constraint */
806 if (data == nullptr) {
807 return OPERATOR_CANCELLED;
808 }
809
810 /* just set original length to 0.0, which will cause a reset on next recalc */
811 data->dist = 0.0f;
812 constraint_update(bmain, ob);
813
815 return OPERATOR_FINISHED;
816}
817
819 wmOperator *op,
820 const wmEvent * /*event*/)
821{
822 if (edit_constraint_invoke_properties(C, op, nullptr, nullptr)) {
823 return limitdistance_reset_exec(C, op);
824 }
825 return OPERATOR_CANCELLED;
826}
827
829{
830 /* identifiers */
831 ot->name = "Reset Distance";
832 ot->idname = "CONSTRAINT_OT_limitdistance_reset";
833 ot->description = "Reset limiting distance for Limit Distance Constraint";
834
835 /* callbacks */
839
840 /* flags */
842
843 /* properties */
845}
846
848
849/* ------------------------------------------------------------------- */
852
853/* Force evaluation so that the 'set inverse' flag is handled.
854 * No-op when the constraint is enabled, as in such cases the evaluation will happen anyway.
855 */
857{
858 if ((con->flag & (CONSTRAINT_DISABLE | CONSTRAINT_OFF)) == 0) {
859 return;
860 }
861
864
865 short flag_backup = con->flag;
868 con->flag = flag_backup;
869}
870
871/* ChildOf Constraint - set inverse callback */
873{
874 Main *bmain = CTX_data_main(C);
877 bChildOfConstraint *data = (con) ? (bChildOfConstraint *)con->data : nullptr;
878
879 /* despite 3 layers of checks, we may still not be able to find a constraint */
880 if (data == nullptr) {
881 printf("DEBUG: Child-Of Set Inverse - object = '%s'\n", (ob) ? ob->id.name + 2 : "<None>");
882 BKE_report(op->reports, RPT_ERROR, "Could not find constraint data for Child-Of Set Inverse");
883 return OPERATOR_CANCELLED;
884 }
885
886 /* Set a flag to request recalculation on next update. */
887 data->flag |= CHILDOF_SET_INVERSE;
888
889 /* Force constraint to run, it will perform the recalculation. */
891
892 constraint_update(bmain, ob);
894
895 return OPERATOR_FINISHED;
896}
897
899 wmOperator *op,
900 const wmEvent * /*event*/)
901{
902 if (edit_constraint_invoke_properties(C, op, nullptr, nullptr)) {
903 return childof_set_inverse_exec(C, op);
904 }
905 return OPERATOR_CANCELLED;
906}
907
909{
910 /* identifiers */
911 ot->name = "Set Inverse";
912 ot->idname = "CONSTRAINT_OT_childof_set_inverse";
913 ot->description = "Set inverse correction for Child Of constraint";
914
915 /* callbacks */
919
920 /* flags */
922
923 /* properties */
925}
926
927/* ChildOf Constraint - clear inverse callback */
929{
930 Main *bmain = CTX_data_main(C);
933 bChildOfConstraint *data = (con) ? (bChildOfConstraint *)con->data : nullptr;
934
935 if (data == nullptr) {
936 BKE_report(op->reports, RPT_ERROR, "Child Of constraint not found");
937 return OPERATOR_CANCELLED;
938 }
939
940 /* simply clear the matrix */
941 unit_m4(data->invmat);
942
943 constraint_update(bmain, ob);
945
946 return OPERATOR_FINISHED;
947}
948
950 wmOperator *op,
951 const wmEvent * /*event*/)
952{
953 if (edit_constraint_invoke_properties(C, op, nullptr, nullptr)) {
954 return childof_clear_inverse_exec(C, op);
955 }
956 return OPERATOR_CANCELLED;
957}
958
960{
961 /* identifiers */
962 ot->name = "Clear Inverse";
963 ot->idname = "CONSTRAINT_OT_childof_clear_inverse";
964 ot->description = "Clear inverse correction for Child Of constraint";
965
966 /* callbacks */
970
971 /* flags */
973
974 /* properties */
976}
977
979
980/* ------------------------------------------------------------------- */
983
985{
986 Main *bmain = CTX_data_main(C);
989 bFollowPathConstraint *data = (con) ? (bFollowPathConstraint *)con->data : nullptr;
990
991 bAction *act = nullptr;
992 FCurve *fcu = nullptr;
993 int sfra = RNA_int_get(op->ptr, "frame_start");
994 int len = RNA_int_get(op->ptr, "length");
995 float standardRange = 1.0;
996
997 /* nearly impossible sanity check */
998 if (data == nullptr) {
999 BKE_report(op->reports, RPT_ERROR, "Follow Path constraint not found");
1000 return OPERATOR_CANCELLED;
1001 }
1002
1003 /* add F-Curve as appropriate */
1004 if (data->tar) {
1005 Curve *cu = (Curve *)data->tar->data;
1006
1007 if (ELEM(nullptr, cu->adt, cu->adt->action) ||
1008 (animrig::fcurve_find_in_assigned_slot(*cu->adt, {"eval_time", 0}) == nullptr))
1009 {
1010 /* create F-Curve for path animation */
1011 act = animrig::id_action_ensure(bmain, &cu->id);
1012 PointerRNA id_ptr = RNA_id_pointer_create(&cu->id);
1013 fcu = animrig::action_fcurve_ensure_ex(bmain, act, nullptr, &id_ptr, {"eval_time", 0});
1014
1015 /* standard vertical range - 1:1 = 100 frames */
1016 standardRange = 100.0f;
1017 }
1018 else {
1019 /* path anim exists already - abort for now as this may well be what was intended */
1020 BKE_report(op->reports, RPT_WARNING, "Path is already animated");
1021 return OPERATOR_CANCELLED;
1022 }
1023 }
1024 else {
1025 /* animate constraint's "fixed offset" */
1026 PropertyRNA *prop;
1027
1028 /* get RNA pointer to constraint's "offset_factor" property - to build RNA path */
1029 PointerRNA ptr = RNA_pointer_create_discrete(&ob->id, &RNA_FollowPathConstraint, con);
1030 prop = RNA_struct_find_property(&ptr, "offset_factor");
1031
1032 const std::optional<std::string> path = RNA_path_from_ID_to_property(&ptr, prop);
1033 BLI_assert(path.has_value());
1034
1035 /* create F-Curve for constraint */
1036 act = animrig::id_action_ensure(bmain, &ob->id);
1037 PointerRNA id_ptr = RNA_id_pointer_create(&ob->id);
1038 fcu = animrig::action_fcurve_ensure_ex(bmain, act, nullptr, &id_ptr, {path->c_str(), 0});
1039
1040 /* standard vertical range - 0.0 to 1.0 */
1041 standardRange = 1.0f;
1042
1043 /* enable "Use Fixed Position" so that animating this has effect */
1044 data->followflag |= FOLLOWPATH_STATIC;
1045 }
1046
1047 /* setup dummy 'generator' modifier here to get 1-1 correspondence still working
1048 * and define basic slope of this curve based on the properties
1049 */
1050 if (!fcu->bezt && !fcu->fpt && !fcu->modifiers.first) {
1052 FMod_Generator *gen = static_cast<FMod_Generator *>(fcm->data);
1053
1054 /* Assume that we have the following equation:
1055 * y = Ax + B
1056 * 1 0 <-- coefficients array indices
1057 */
1058 float A = standardRange / float(len);
1059 float B = float(-sfra) * A;
1060
1061 gen->coefficients[1] = A;
1062 gen->coefficients[0] = B;
1063 }
1064
1065 /* updates... */
1067 return OPERATOR_FINISHED;
1068}
1069
1071 wmOperator *op,
1072 const wmEvent * /*event*/)
1073{
1074 /* hook up invoke properties for figuring out which constraint we're dealing with */
1075 if (edit_constraint_invoke_properties(C, op, nullptr, nullptr)) {
1076 return followpath_path_animate_exec(C, op);
1077 }
1078 return OPERATOR_CANCELLED;
1079}
1080
1082{
1083 /* identifiers */
1084 ot->name = "Auto Animate Path";
1085 ot->idname = "CONSTRAINT_OT_followpath_path_animate";
1086 ot->description =
1087 "Add default animation for path used by constraint if it isn't animated already";
1088
1089 /* callbacks */
1092 ot->poll = edit_constraint_poll;
1093
1094 /* flags */
1095 ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
1096
1097 /* props */
1099 RNA_def_int(ot->srna,
1100 "frame_start",
1101 1,
1102 MINAFRAME,
1103 MAXFRAME,
1104 "Start Frame",
1105 "First frame of path animation",
1106 MINAFRAME,
1107 MAXFRAME);
1108 RNA_def_int(ot->srna,
1109 "length",
1110 100,
1111 0,
1112 MAXFRAME,
1113 "Length",
1114 "Number of frames that path animation should take",
1115 0,
1116 MAXFRAME);
1117}
1118
1120
1121/* ------------------------------------------------------------------- */
1124
1126{
1127 Main *bmain = CTX_data_main(C);
1130 bObjectSolverConstraint *data = (con) ? (bObjectSolverConstraint *)con->data : nullptr;
1131
1132 /* despite 3 layers of checks, we may still not be able to find a constraint */
1133 if (data == nullptr) {
1134 printf("DEBUG: ObjectSolver Set Inverse - object = '%s'\n", (ob) ? ob->id.name + 2 : "<None>");
1135 BKE_report(
1136 op->reports, RPT_ERROR, "Could not find constraint data for ObjectSolver Set Inverse");
1137 return OPERATOR_CANCELLED;
1138 }
1139
1140 /* Set a flag to request recalculation on next update. */
1142
1143 /* Force constraint to run, it will perform the recalculation. */
1145
1146 constraint_update(bmain, ob);
1148
1149 return OPERATOR_FINISHED;
1150}
1151
1153 wmOperator *op,
1154 const wmEvent * /*event*/)
1155{
1156 if (edit_constraint_invoke_properties(C, op, nullptr, nullptr)) {
1157 return objectsolver_set_inverse_exec(C, op);
1158 }
1159 return OPERATOR_CANCELLED;
1160}
1161
1163{
1164 /* identifiers */
1165 ot->name = "Set Inverse";
1166 ot->idname = "CONSTRAINT_OT_objectsolver_set_inverse";
1167 ot->description = "Set inverse correction for Object Solver constraint";
1168
1169 /* callbacks */
1172 ot->poll = edit_constraint_poll;
1173
1174 /* flags */
1175 ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
1176
1177 /* properties */
1179}
1180
1182
1183/* ------------------------------------------------------------------- */
1186
1188{
1189 Main *bmain = CTX_data_main(C);
1192 bObjectSolverConstraint *data = (con) ? (bObjectSolverConstraint *)con->data : nullptr;
1193
1194 if (data == nullptr) {
1195 BKE_report(op->reports, RPT_ERROR, "Child Of constraint not found");
1196 return OPERATOR_CANCELLED;
1197 }
1198
1199 /* simply clear the matrix */
1200 unit_m4(data->invmat);
1201
1202 constraint_update(bmain, ob);
1204
1205 return OPERATOR_FINISHED;
1206}
1207
1209 wmOperator *op,
1210 const wmEvent * /*event*/)
1211{
1212 if (edit_constraint_invoke_properties(C, op, nullptr, nullptr)) {
1214 }
1215 return OPERATOR_CANCELLED;
1216}
1217
1219{
1220 /* identifiers */
1221 ot->name = "Clear Inverse";
1222 ot->idname = "CONSTRAINT_OT_objectsolver_clear_inverse";
1223 ot->description = "Clear inverse correction for Object Solver constraint";
1224
1225 /* callbacks */
1228 ot->poll = edit_constraint_poll;
1229
1230 /* flags */
1231 ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
1232
1233 /* properties */
1235}
1236
1238
1239/* ------------------------------------------------------------------- */
1242
1244{
1245 ListBase *lb = constraint_list_from_constraint(ob, con, nullptr);
1246
1247 /* lets be nice and escape if its active already */
1248 /* NOTE: this assumes that the stack doesn't have other active ones set... */
1249 if ((lb && con) && (con->flag & CONSTRAINT_ACTIVE)) {
1250 return;
1251 }
1252
1254}
1255
1257{
1258 if (ob->pose) {
1260 }
1261
1262 object_test_constraints(bmain, ob);
1263
1264 if (ob->type == OB_ARMATURE) {
1266 }
1267 else {
1269 }
1270}
1271
1272static void object_pose_tag_update(Main *bmain, Object *ob)
1273{
1274 BKE_pose_tag_recalc(bmain, ob->pose); /* Checks & sort pose channels. */
1275}
1276
1278{
1279 constraint_update(bmain, ob);
1280
1281 if (ob->pose) {
1282 object_pose_tag_update(bmain, ob);
1283 }
1285}
1286
1288{
1289 if (ob->pose) {
1291 }
1292
1293 if (con) {
1294 object_test_constraint(bmain, ob, con);
1295 }
1296
1297 if (ob->type == OB_ARMATURE) {
1299 }
1300 else {
1302 }
1303
1304 /* Do Copy-on-Write tag here too, otherwise constraint
1305 * influence/mute buttons in UI have no effect
1306 */
1308}
1309
1311{
1312 constraint_tag_update(bmain, ob, con);
1313
1314 if (ob->pose) {
1315 object_pose_tag_update(bmain, ob);
1316 }
1318}
1319
1320bool constraint_move_to_index(Object *ob, bConstraint *con, const int index)
1321{
1322 BLI_assert(con != nullptr);
1323 BLI_assert(index >= 0);
1324
1325 ListBase *conlist = constraint_list_from_constraint(ob, con, nullptr);
1326 int current_index = BLI_findindex(conlist, con);
1327 BLI_assert(current_index >= 0);
1328
1329 BLI_listbase_link_move(conlist, con, index - current_index);
1330
1332
1333 return true;
1334}
1335
1336void constraint_link(Main *bmain, Object *ob_dst, ListBase *dst, ListBase *src)
1337{
1339 BKE_constraints_copy(dst, src, true);
1340 LISTBASE_FOREACH (bConstraint *, con, dst) {
1341 constraint_dependency_tag_update(bmain, ob_dst, con);
1342 }
1344}
1345
1347{
1348 bConstraint *copy_con = BKE_constraint_copy_for_object(ob_dst, con);
1350
1351 constraint_dependency_tag_update(bmain, ob_dst, con);
1353}
1354
1356{
1357 bConstraint *copy_con = BKE_constraint_copy_for_pose(ob_dst, pchan, con);
1359
1360 constraint_dependency_tag_update(bmain, ob_dst, con);
1362}
1363
1365
1366/* ------------------------------------------------------------------- */
1369
1371{
1372 Main *bmain = CTX_data_main(C);
1374 bConstraint *con = edit_constraint_property_get(C, op, ob, 0);
1375
1376 if (con == nullptr) {
1377 return OPERATOR_CANCELLED;
1378 }
1379
1380 ListBase *lb = constraint_list_from_constraint(ob, con, nullptr);
1381
1382 /* Store name temporarily for report. */
1383 char name[MAX_NAME];
1384 STRNCPY(name, con->name);
1385
1386 /* free the constraint */
1387 if (BKE_constraint_remove_ex(lb, ob, con)) {
1388 /* Needed to set the flags on pose-bones correctly. */
1389 constraint_update(bmain, ob);
1390
1391 /* relations */
1393
1394 /* notifiers */
1396
1397 if (RNA_boolean_get(op->ptr, "report")) {
1398 BKE_reportf(op->reports, RPT_INFO, "Removed constraint: %s", name);
1399 }
1400
1401 return OPERATOR_FINISHED;
1402 }
1403 /* couldn't remove due to some invalid data */
1404 return OPERATOR_CANCELLED;
1405}
1406
1408{
1409 wmOperatorStatus retval;
1410 if (!edit_constraint_invoke_properties(C, op, event, &retval)) {
1411 return OPERATOR_CANCELLED;
1412 }
1413 return constraint_delete_exec(C, op);
1414}
1415
1417{
1418 /* identifiers */
1419 ot->name = "Delete Constraint";
1420 ot->idname = "CONSTRAINT_OT_delete";
1421 ot->description = "Remove constraint from constraint stack";
1422
1423 /* callbacks */
1424 ot->invoke = constraint_delete_invoke;
1425 ot->exec = constraint_delete_exec;
1426 ot->poll = edit_constraint_poll;
1427
1428 /* flags */
1429 ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
1432}
1433
1435
1436/* ------------------------------------------------------------------- */
1439
1441{
1442 Scene *scene = CTX_data_scene(C);
1444 Main *bmain = CTX_data_main(C);
1446 bConstraint *con = edit_constraint_property_get(C, op, ob, 0);
1447
1448 if (con == nullptr) {
1449 return OPERATOR_CANCELLED;
1450 }
1451
1452 bPoseChannel *pchan;
1454
1455 /* Store name temporarily for report. */
1456 char name[MAX_NAME];
1457 STRNCPY(name, con->name);
1458 const bool is_first_constraint = con != constraints->first;
1459
1460 /* Copy the constraint. */
1461 bool success;
1462 if (pchan) {
1464 depsgraph, scene, constraints, ob, con, pchan);
1465 }
1466 else {
1468 }
1469
1470 if (!success) {
1471 /* Couldn't remove due to some invalid data. */
1472 return OPERATOR_CANCELLED;
1473 }
1474
1475 /* Update for any children that may get moved. */
1477
1478 /* Needed to set the flags on pose-bones correctly. */
1479 constraint_update(bmain, ob);
1480
1483 if (pchan) {
1485 }
1486 else {
1488 }
1489
1490 if (RNA_boolean_get(op->ptr, "report")) {
1491 if (is_first_constraint) {
1492 BKE_report(op->reports,
1493 RPT_INFO,
1494 "Applied constraint was not first, result may not be as expected");
1495 }
1496 else {
1497 /* Only add this report if the operator didn't cause another one. The purpose here is
1498 * to alert that something happened, and the previous report will do that anyway. */
1499 BKE_reportf(op->reports, RPT_INFO, "Applied constraint: %s", name);
1500 }
1501 }
1502
1503 return OPERATOR_FINISHED;
1504}
1505
1507{
1508 wmOperatorStatus retval;
1509 if (!edit_constraint_invoke_properties(C, op, event, &retval)) {
1510 return OPERATOR_CANCELLED;
1511 }
1512 return constraint_apply_exec(C, op);
1513}
1514
1516{
1517 /* identifiers */
1518 ot->name = "Apply Constraint";
1519 ot->idname = "CONSTRAINT_OT_apply";
1520 ot->description = "Apply constraint and remove from the stack";
1521
1522 /* callbacks */
1523 ot->invoke = constraint_apply_invoke;
1524 ot->exec = constraint_apply_exec;
1525 ot->poll = edit_constraint_poll;
1526
1527 /* flags */
1528 ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
1531}
1532
1534
1535/* ------------------------------------------------------------------- */
1538
1540{
1541 Main *bmain = CTX_data_main(C);
1543 bConstraint *con = edit_constraint_property_get(C, op, ob, 0);
1544
1545 if (con == nullptr) {
1546 return OPERATOR_CANCELLED;
1547 }
1548
1549 bPoseChannel *pchan;
1551
1552 /* Store name temporarily for report. */
1553 char name[MAX_NAME];
1554 STRNCPY(name, con->name);
1555
1556 /* Copy the constraint. */
1557 bConstraint *copy_con;
1558 if (pchan) {
1559 copy_con = BKE_constraint_copy_for_pose(ob, pchan, con);
1560 }
1561 else {
1562 copy_con = BKE_constraint_copy_for_object(ob, con);
1563 }
1564
1565 if (!copy_con) {
1566 /* Couldn't remove due to some invalid data. */
1567 return OPERATOR_CANCELLED;
1568 }
1570
1571 /* Move constraint to correct position. */
1572 const int new_index = BLI_findindex(constraints, con) + 1;
1573 const int current_index = BLI_findindex(constraints, copy_con);
1574 BLI_assert(new_index >= 0);
1575 BLI_assert(current_index >= 0);
1576 BLI_listbase_link_move(constraints, copy_con, new_index - current_index);
1577
1578 /* Needed to set the flags on pose-bones correctly. */
1579 constraint_update(bmain, ob);
1580
1583
1584 if (RNA_boolean_get(op->ptr, "report")) {
1585 BKE_reportf(op->reports, RPT_INFO, "Copied constraint: %s", name);
1586 }
1587
1588 return OPERATOR_FINISHED;
1589}
1590
1592{
1593 wmOperatorStatus retval;
1594 if (!edit_constraint_invoke_properties(C, op, event, &retval)) {
1595 return OPERATOR_CANCELLED;
1596 }
1597 return constraint_copy_exec(C, op);
1598}
1599
1601{
1602 /* identifiers */
1603 ot->name = "Duplicate Constraint";
1604 ot->idname = "CONSTRAINT_OT_copy";
1605 ot->description = "Duplicate constraint at the same position in the stack";
1606
1607 /* callbacks */
1608 ot->invoke = constraint_copy_invoke;
1609 ot->exec = constraint_copy_exec;
1610 ot->poll = edit_constraint_poll;
1611
1612 /* flags */
1613 ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
1616}
1617
1619
1620/* ------------------------------------------------------------------- */
1623
1625{
1626 Main *bmain = CTX_data_main(C);
1627 Object *obact = context_active_object(C);
1628 bConstraint *con = edit_constraint_property_get(C, op, obact, 0);
1629
1630 if (con == nullptr) {
1631 return OPERATOR_CANCELLED;
1632 }
1633
1634 bPoseChannel *pchan;
1635 constraint_list_from_constraint(obact, con, &pchan);
1636
1637 if (pchan) {
1638 /* Don't do anything if bone doesn't exist or doesn't have any constraints. */
1639 if (pchan->constraints.first == nullptr) {
1640 BKE_report(op->reports, RPT_ERROR, "No constraints for copying");
1641 return OPERATOR_CANCELLED;
1642 }
1643
1644 Object *prev_ob = nullptr;
1645
1646 /* Copy all constraints from active pose-bone to all selected pose-bones. */
1647 CTX_DATA_BEGIN_WITH_ID (C, bPoseChannel *, chan, selected_pose_bones, Object *, ob) {
1648 /* If we're not handling the object we're copying from, copy all constraints over. */
1649 if (pchan == chan) {
1650 continue;
1651 }
1652
1653 bConstraint *copy_con = BKE_constraint_copy_for_pose(ob, chan, con);
1655
1656 /* Update flags (need to add here, not just copy). */
1657 chan->constflag |= pchan->constflag;
1658
1659 if (prev_ob == ob) {
1660 continue;
1661 }
1662
1663 BKE_pose_tag_recalc(bmain, ob->pose);
1665 prev_ob = ob;
1666 }
1668 }
1669 else {
1670 /* Copy all constraints from active object to all selected objects. */
1671 CTX_DATA_BEGIN (C, Object *, ob, selected_editable_objects) {
1672 /* If we're not handling the object we're copying from, copy all constraints over. */
1673 if (obact == ob) {
1674 continue;
1675 }
1676
1677 bConstraint *copy_con = BKE_constraint_copy_for_object(ob, con);
1679
1681 }
1683 }
1684
1685 /* Force depsgraph to get recalculated since new relationships added. */
1687
1689
1690 return OPERATOR_FINISHED;
1691}
1692
1694 wmOperator *op,
1695 const wmEvent *event)
1696{
1697 wmOperatorStatus retval;
1698 if (!edit_constraint_invoke_properties(C, op, event, &retval)) {
1699 return retval;
1700 }
1702}
1703
1705{
1706 PointerRNA ptr = CTX_data_pointer_get_type(C, "constraint", &RNA_Constraint);
1707 Object *obact = (ptr.owner_id) ? (Object *)ptr.owner_id : context_active_object(C);
1708 bConstraint *con = static_cast<bConstraint *>(ptr.data);
1709 bPoseChannel *pchan;
1710 constraint_list_from_constraint(obact, con, &pchan);
1711
1712 if (pchan) {
1713 bool found = false;
1714 CTX_DATA_BEGIN_WITH_ID (C, bPoseChannel *, chan, selected_pose_bones, Object *, ob) {
1715 UNUSED_VARS(ob);
1716 if (pchan != chan) {
1719 found = true;
1720 break;
1721 }
1722 }
1724 if (found) {
1725 return true;
1726 }
1727
1728 CTX_wm_operator_poll_msg_set(C, "No other bones are selected");
1729 return false;
1730 }
1731
1732 if (!obact) {
1733 CTX_wm_operator_poll_msg_set(C, "No selected object to copy from");
1734 return false;
1735 }
1736
1737 bool found = false;
1738 CTX_DATA_BEGIN (C, Object *, ob, selected_objects) {
1739 if (ob != obact) {
1742 found = true;
1743 break;
1744 }
1745 }
1747 if (found) {
1748 return true;
1749 }
1750
1751 CTX_wm_operator_poll_msg_set(C, "No other objects are selected");
1752 return false;
1753}
1754
1756{
1757 /* identifiers */
1758 ot->name = "Copy Constraint To Selected";
1759 ot->idname = "CONSTRAINT_OT_copy_to_selected";
1760 ot->description = "Copy constraint to other selected objects/bones";
1761
1762 /* API callbacks. */
1766
1767 /* flags */
1768 ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
1770}
1771
1773
1774/* ------------------------------------------------------------------- */
1777
1779{
1781 bConstraint *con = edit_constraint_property_get(C, op, ob, 0);
1782
1783 if (con && con->next) {
1784 ListBase *conlist = constraint_list_from_constraint(ob, con, nullptr);
1785 bConstraint *nextCon = con->next;
1786
1787 /* insert the nominated constraint after the one that used to be after it */
1788 BLI_remlink(conlist, con);
1789 BLI_insertlinkafter(conlist, nextCon, con);
1790
1793
1794 return OPERATOR_FINISHED;
1795 }
1796
1797 return OPERATOR_CANCELLED;
1798}
1799
1801 wmOperator *op,
1802 const wmEvent *event)
1803{
1804 wmOperatorStatus retval;
1805 if (edit_constraint_invoke_properties(C, op, event, &retval)) {
1806 return constraint_move_down_exec(C, op);
1807 }
1808 return retval;
1809}
1810
1812{
1813 /* identifiers */
1814 ot->name = "Move Constraint Down";
1815 ot->idname = "CONSTRAINT_OT_move_down";
1816 ot->description = "Move constraint down in constraint stack";
1817
1818 /* callbacks */
1821 ot->poll = edit_constraint_poll;
1822
1823 /* flags */
1824 ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
1825
1826 /* properties */
1828}
1829
1831
1832/* ------------------------------------------------------------------- */
1835
1837{
1839 bConstraint *con = edit_constraint_property_get(C, op, ob, 0);
1840
1841 if (con && con->prev) {
1842 ListBase *conlist = constraint_list_from_constraint(ob, con, nullptr);
1843 bConstraint *prevCon = con->prev;
1844
1845 /* insert the nominated constraint before the one that used to be before it */
1846 BLI_remlink(conlist, con);
1847 BLI_insertlinkbefore(conlist, prevCon, con);
1848
1851
1852 return OPERATOR_FINISHED;
1853 }
1854
1855 return OPERATOR_CANCELLED;
1856}
1857
1859 wmOperator *op,
1860 const wmEvent *event)
1861{
1862 wmOperatorStatus retval;
1863 if (edit_constraint_invoke_properties(C, op, event, &retval)) {
1864 return constraint_move_up_exec(C, op);
1865 }
1866 return retval;
1867}
1868
1870{
1871 /* identifiers */
1872 ot->name = "Move Constraint Up";
1873 ot->idname = "CONSTRAINT_OT_move_up";
1874 ot->description = "Move constraint up in constraint stack";
1875
1876 /* callbacks */
1878 ot->invoke = constraint_move_up_invoke;
1879 ot->poll = edit_constraint_poll;
1880
1881 /* flags */
1882 ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
1884}
1885
1887
1888/* ------------------------------------------------------------------- */
1891
1893{
1895 bConstraint *con = edit_constraint_property_get(C, op, ob, 0);
1896
1897 int new_index = RNA_int_get(op->ptr, "index");
1898 new_index = std::max(new_index, 0);
1899
1900 if (con) {
1901 constraint_move_to_index(ob, con, new_index);
1902
1904
1905 return OPERATOR_FINISHED;
1906 }
1907
1908 return OPERATOR_CANCELLED;
1909}
1910
1912 wmOperator *op,
1913 const wmEvent *event)
1914{
1915 wmOperatorStatus retval;
1916 if (edit_constraint_invoke_properties(C, op, event, &retval)) {
1917 return constraint_move_to_index_exec(C, op);
1918 }
1919 return retval;
1920}
1921
1923{
1924 /* identifiers */
1925 ot->name = "Move Constraint to Index";
1926 ot->idname = "CONSTRAINT_OT_move_to_index";
1927 ot->description =
1928 "Change the constraint's position in the list so it evaluates after the set number of "
1929 "others";
1930
1931 /* callbacks */
1934 ot->poll = edit_constraint_poll;
1935
1936 /* flags */
1937 ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
1939 RNA_def_int(ot->srna,
1940 "index",
1941 0,
1942 0,
1943 INT_MAX,
1944 "Index",
1945 "The index to move the constraint to",
1946 0,
1947 INT_MAX);
1948}
1949
1951
1952/* ------------------------------------------------------------------- */
1955
1957{
1958 Main *bmain = CTX_data_main(C);
1959 Object *prev_ob = nullptr;
1960
1961 /* free constraints for all selected bones */
1962 CTX_DATA_BEGIN_WITH_ID (C, bPoseChannel *, pchan, selected_pose_bones, Object *, ob) {
1963 BKE_constraints_free(&pchan->constraints);
1964 pchan->constflag = 0;
1965
1966 if (prev_ob != ob) {
1969 prev_ob = ob;
1970 }
1971 }
1973
1974 /* force depsgraph to get recalculated since relationships removed */
1976
1977 /* NOTE: calling BIK_clear_data() isn't needed here. */
1978
1979 return OPERATOR_FINISHED;
1980}
1981
1983{
1984 /* identifiers */
1985 ot->name = "Clear Pose Constraints";
1986 ot->idname = "POSE_OT_constraints_clear";
1987 ot->description = "Clear all constraints from the selected bones";
1988
1989 /* callbacks */
1991 /* XXX: do we want to ensure there are selected bones too? */
1993}
1994
1996{
1997 Main *bmain = CTX_data_main(C);
1998
1999 /* do freeing */
2000 CTX_DATA_BEGIN (C, Object *, ob, selected_editable_objects) {
2001 BKE_constraints_free(&ob->constraints);
2003 }
2005
2006 /* force depsgraph to get recalculated since relationships removed */
2008
2009 /* do updates */
2011
2012 return OPERATOR_FINISHED;
2013}
2014
2016
2017/* ------------------------------------------------------------------- */
2020
2022{
2023 /* identifiers */
2024 ot->name = "Clear Object Constraints";
2025 ot->idname = "OBJECT_OT_constraints_clear";
2026 ot->description = "Clear all constraints from the selected objects";
2027
2028 /* callbacks */
2031}
2032
2034
2035/* ------------------------------------------------------------------- */
2038
2040{
2041 Main *bmain = CTX_data_main(C);
2043
2044 /* don't do anything if bone doesn't exist or doesn't have any constraints */
2045 if (ELEM(nullptr, pchan, pchan->constraints.first)) {
2046 BKE_report(op->reports, RPT_ERROR, "No active bone with constraints for copying");
2047 return OPERATOR_CANCELLED;
2048 }
2049
2050 Object *prev_ob = nullptr;
2051
2052 /* Copy all constraints from active pose-bone to all selected pose-bones. */
2053 CTX_DATA_BEGIN_WITH_ID (C, bPoseChannel *, chan, selected_pose_bones, Object *, ob) {
2054 /* if we're not handling the object we're copying from, copy all constraints over */
2055 if (pchan != chan) {
2056 BKE_constraints_copy(&chan->constraints, &pchan->constraints, true);
2057 /* update flags (need to add here, not just copy) */
2058 chan->constflag |= pchan->constflag;
2059
2060 if (prev_ob != ob) {
2061 BKE_pose_tag_recalc(bmain, ob->pose);
2063 prev_ob = ob;
2064 }
2065 }
2066 }
2068
2069 /* force depsgraph to get recalculated since new relationships added */
2071
2073
2074 return OPERATOR_FINISHED;
2075}
2076
2078{
2079 /* identifiers */
2080 ot->name = "Copy Constraints to Selected Bones";
2081 ot->idname = "POSE_OT_constraints_copy";
2082 ot->description = "Copy constraints to other selected bones";
2083
2084 /* API callbacks. */
2087
2088 /* flags */
2089 ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
2090}
2091
2093
2094/* ------------------------------------------------------------------- */
2097
2099{
2100 Main *bmain = CTX_data_main(C);
2101 Object *obact = context_active_object(C);
2102
2103 /* copy all constraints from active object to all selected objects */
2104 CTX_DATA_BEGIN (C, Object *, ob, selected_editable_objects) {
2105 /* if we're not handling the object we're copying from, copy all constraints over */
2106 if (obact != ob) {
2107 BKE_constraints_copy(&ob->constraints, &obact->constraints, true);
2109 }
2110 }
2112
2113 /* force depsgraph to get recalculated since new relationships added */
2115
2116 /* notifiers for updates */
2118
2119 return OPERATOR_FINISHED;
2120}
2121
2123{
2124 /* identifiers */
2125 ot->name = "Copy Constraints to Selected Objects";
2126 ot->idname = "OBJECT_OT_constraints_copy";
2127 ot->description = "Copy constraints to other selected objects";
2128
2129 /* API callbacks. */
2132
2133 /* flags */
2134 ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
2135}
2136
2138
2139/* ------------------------------------------------------------------- */
2142
2143/* get the Object and/or PoseChannel to use as target */
2145 bContext *C, int con_type, Object **tar_ob, bPoseChannel **tar_pchan, bool add)
2146{
2147 Object *obact = context_active_object(C);
2149 bool only_curve = false, only_mesh = false, only_ob = false;
2150 bool found = false;
2151
2152 /* clear tar_ob and tar_pchan fields before use
2153 * - assume for now that both always exist...
2154 */
2155 *tar_ob = nullptr;
2156 *tar_pchan = nullptr;
2157
2158 /* check if constraint type doesn't requires a target
2159 * - if so, no need to get any targets
2160 */
2161 switch (con_type) {
2162 /* no-target constraints --------------------------- */
2163 /* null constraint - shouldn't even be added! */
2165 /* limit constraints - no targets needed */
2170 return false;
2171
2172 /* restricted target-type constraints -------------- */
2173 /* NOTE: for these, we cannot try to add a target object if no valid ones are found,
2174 * since that doesn't work */
2175 /* curve-based constraints - set the only_curve and only_ob flags */
2179 only_curve = true;
2180 only_ob = true;
2181 add = false;
2182 break;
2183
2184 /* mesh only? */
2186 only_mesh = true;
2187 only_ob = true;
2188 add = false;
2189 break;
2190
2191 /* Armature only. */
2193 add = false;
2194 break;
2195 }
2196
2197 /* if the active Object is Armature, and we can search for bones, do so... */
2198 if ((obact->type == OB_ARMATURE) && (only_ob == false)) {
2199 /* search in list of selected Pose-Channels for target */
2200 CTX_DATA_BEGIN (C, bPoseChannel *, pchan, selected_pose_bones_from_active_object) {
2201 /* just use the first one that we encounter, as long as it is not the active one */
2202 if (pchan != pchanact) {
2203 *tar_ob = obact;
2204 *tar_pchan = pchan;
2205 found = true;
2206
2207 break;
2208 }
2209 }
2211 }
2212
2213 /* if not yet found, try selected Objects... */
2214 if (found == false) {
2215 /* search in selected objects context */
2216 CTX_DATA_BEGIN (C, Object *, ob, selected_objects) {
2217 /* just use the first object we encounter (that isn't the active object)
2218 * and which fulfills the criteria for the object-target that we've got
2219 */
2220 if (ob != obact) {
2221 /* for armatures in pose mode, look inside the armature for the active bone
2222 * so that we set up cross-armature constraints with less effort
2223 */
2224 if ((ob->type == OB_ARMATURE) && (ob->mode & OB_MODE_POSE) && (!only_curve && !only_mesh))
2225 {
2226
2227 /* Only use the object & bone if the bone is visible & selected
2228 * since we may have multiple objects in pose mode at once. */
2230 if (pchan != nullptr) {
2231 *tar_pchan = pchan;
2232 *tar_ob = ob;
2233 found = true;
2234 }
2235
2236 break;
2237 }
2238 if (((!only_curve) || (ob->type == OB_CURVES_LEGACY)) &&
2239 ((!only_mesh) || (ob->type == OB_MESH)))
2240 {
2241 /* set target */
2242 *tar_ob = ob;
2243 found = true;
2244
2245 /* perform some special operations on the target */
2246 if (only_curve) {
2247 /* Curve-Path option must be enabled for follow-path constraints to be able to work
2248 */
2249 Curve *cu = (Curve *)ob->data;
2250 cu->flag |= CU_PATH;
2251 }
2252
2253 break;
2254 }
2255 }
2256 }
2258 }
2259
2260 /* if still not found, add a new empty to act as a target (if allowed) */
2261 if ((found == false) && (add)) {
2262 Main *bmain = CTX_data_main(C);
2263 Scene *scene = CTX_data_scene(C);
2264 ViewLayer *view_layer = CTX_data_view_layer(C);
2265 BKE_view_layer_synced_ensure(scene, view_layer);
2266 Base *base = BKE_view_layer_active_base_get(view_layer);
2267 Object *obt;
2268
2269 /* add new target object */
2270 obt = BKE_object_add(bmain, scene, view_layer, OB_EMPTY, nullptr);
2271
2272 /* transform cent to global coords for loc */
2273 if (pchanact) {
2274 /* Since by default, IK targets the tip of the last bone,
2275 * use the tip of the active PoseChannel if adding a target for an IK Constraint. */
2276 if (con_type == CONSTRAINT_TYPE_KINEMATIC) {
2277 mul_v3_m4v3(obt->loc, obact->object_to_world().ptr(), pchanact->pose_tail);
2278 }
2279 else {
2280 mul_v3_m4v3(obt->loc, obact->object_to_world().ptr(), pchanact->pose_head);
2281 }
2282 }
2283 else {
2284 copy_v3_v3(obt->loc, obact->object_to_world().location());
2285 }
2286
2287 /* restore, BKE_object_add sets active */
2288 view_layer->basact = base;
2289 base_select(base, BA_SELECT);
2290
2291 /* make our new target the new object */
2292 *tar_ob = obt;
2293 found = true;
2294 }
2295
2296 /* return whether there's any target */
2297 return found;
2298}
2299
2300/* used by add constraint operators to add the constraint required */
2302 bContext *C, wmOperator *op, Object *ob, ListBase *list, int type, const bool setTarget)
2303{
2304 Main *bmain = CTX_data_main(C);
2305 bPoseChannel *pchan;
2306 bConstraint *con;
2307
2308 if (list == &ob->constraints) {
2309 pchan = nullptr;
2310 }
2311 else {
2313
2314 /* ensure not to confuse object/pose adding */
2315 if (pchan == nullptr) {
2316 BKE_report(op->reports, RPT_ERROR, "No active pose bone to add a constraint to");
2317 return OPERATOR_CANCELLED;
2318 }
2319 }
2320 /* check if constraint to be added is valid for the given constraints stack */
2321 if (type == CONSTRAINT_TYPE_NULL) {
2322 return OPERATOR_CANCELLED;
2323 }
2324
2325 /* Create a new constraint of the type required,
2326 * and add it to the active/given constraints list. */
2327 if (pchan) {
2328 con = BKE_constraint_add_for_pose(ob, pchan, nullptr, type);
2329 }
2330 else {
2331 con = BKE_constraint_add_for_object(ob, nullptr, type);
2332 }
2333
2334 /* get the first selected object/bone, and make that the target
2335 * - apart from the buttons-window add buttons, we shouldn't add in this way
2336 */
2337 if (setTarget) {
2338 Object *tar_ob = nullptr;
2339 bPoseChannel *tar_pchan = nullptr;
2340
2341 /* get the target objects, adding them as need be */
2342 if (get_new_constraint_target(C, type, &tar_ob, &tar_pchan, true)) {
2343
2344 /* Armature constraints don't have a target by default, add one. */
2345 if (type == CONSTRAINT_TYPE_ARMATURE) {
2346 bArmatureConstraint *acon = static_cast<bArmatureConstraint *>(con->data);
2347 bConstraintTarget *ct = MEM_callocN<bConstraintTarget>("Constraint Target");
2348
2349 ct->weight = 1.0f;
2350 BLI_addtail(&acon->targets, ct);
2351
2352 constraint_dependency_tag_update(bmain, ob, con);
2353 }
2354
2355 /* Method of setting target depends on the type of target we've got - by default,
2356 * just set the first target (distinction here is only for multiple-targeted constraints).
2357 */
2358 if (tar_pchan) {
2359 set_constraint_nth_target(con, tar_ob, tar_pchan->name, 0);
2360 }
2361 else {
2362 set_constraint_nth_target(con, tar_ob, "", 0);
2363 }
2364 }
2365 }
2366
2367 /* make sure all settings are valid - similar to above checks, but sometimes can be wrong */
2368 object_test_constraints(bmain, ob);
2369
2370 if (pchan) {
2372 }
2373
2374 /* force depsgraph to get recalculated since new relationships added */
2376
2377 if ((ob->type == OB_ARMATURE) && (pchan)) {
2378 BKE_pose_tag_recalc(bmain, ob->pose); /* sort pose channels */
2380 }
2381 else {
2383 }
2384
2385 /* notifiers for updates */
2387
2388 return OPERATOR_FINISHED;
2389}
2390
2391/* ------------------ */
2392
2393/* dummy operator callback */
2395{
2397 int type = RNA_enum_get(op->ptr, "type");
2398 short with_targets = 0;
2399
2400 if (!ob) {
2401 BKE_report(op->reports, RPT_ERROR, "No active object to add constraint to");
2402 return OPERATOR_CANCELLED;
2403 }
2404
2405 /* hack: set constraint targets from selected objects in context is allowed when
2406 * operator name included 'with_targets', since the menu doesn't allow multiple properties
2407 */
2408 if (strstr(op->idname, "with_targets")) {
2409 with_targets = 1;
2410 }
2411
2412 return constraint_add_exec(C, op, ob, &ob->constraints, type, with_targets);
2413}
2414
2415/* dummy operator callback */
2417{
2419 int type = RNA_enum_get(op->ptr, "type");
2420 short with_targets = 0;
2421
2422 if (!ob) {
2423 BKE_report(op->reports, RPT_ERROR, "No active object to add constraint to");
2424 return OPERATOR_CANCELLED;
2425 }
2426
2427 /* hack: set constraint targets from selected objects in context is allowed when
2428 * operator name included 'with_targets', since the menu doesn't allow multiple properties
2429 */
2430 if (strstr(op->idname, "with_targets")) {
2431 with_targets = 1;
2432 }
2433
2434 return constraint_add_exec(C, op, ob, constraint_active_list(ob), type, with_targets);
2435}
2436
2437/* ------------------ */
2438
2439/* Filters constraints that are only compatible with bones */
2441 PointerRNA * /*ptr*/,
2442 PropertyRNA * /*prop*/,
2443 bool *r_free)
2444{
2446 EnumPropertyItem *object_constraint_items = nullptr;
2447 int totitem = 0;
2448
2449 while (item->identifier) {
2451 RNA_enum_item_add(&object_constraint_items, &totitem, item);
2452 }
2453 item++;
2454 }
2455
2456 RNA_enum_item_end(&object_constraint_items, &totitem);
2457 *r_free = true;
2458
2459 return object_constraint_items;
2460}
2461
2463{
2464 PropertyRNA *prop;
2465
2466 /* identifiers */
2467 ot->name = "Add Constraint";
2468 ot->description = "Add a constraint to the active object";
2469 ot->idname = "OBJECT_OT_constraint_add";
2470
2471 /* API callbacks. */
2472 ot->invoke = WM_menu_invoke;
2475
2476 /* flags */
2477 ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
2478
2479 /* properties */
2480 prop = RNA_def_enum(ot->srna, "type", rna_enum_dummy_NULL_items, 0, "Type", "");
2482 ot->prop = prop;
2483}
2484
2486
2487/* ------------------------------------------------------------------- */
2490
2492{
2493 PropertyRNA *prop;
2494
2495 /* identifiers */
2496 ot->name = "Add Constraint (with Targets)";
2497 ot->description =
2498 "Add a constraint to the active object, with target (where applicable) set to the "
2499 "selected objects/bones";
2500 ot->idname = "OBJECT_OT_constraint_add_with_targets";
2501
2502 /* API callbacks. */
2503 ot->invoke = WM_menu_invoke;
2506
2507 /* flags */
2508 ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
2509
2510 /* properties */
2511 prop = RNA_def_enum(ot->srna, "type", rna_enum_dummy_NULL_items, 0, "Type", "");
2513 ot->prop = prop;
2514}
2515
2517{
2518 /* identifiers */
2519 ot->name = "Add Constraint";
2520 ot->description = "Add a constraint to the active bone";
2521 ot->idname = "POSE_OT_constraint_add";
2522
2523 /* API callbacks. */
2524 ot->invoke = WM_menu_invoke;
2527
2528 /* flags */
2529 ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
2530
2531 /* properties */
2532 ot->prop = RNA_def_enum(ot->srna, "type", rna_enum_constraint_type_items, 0, "Type", "");
2533}
2534
2536{
2537 /* identifiers */
2538 ot->name = "Add Constraint (with Targets)";
2539 ot->description =
2540 "Add a constraint to the active bone, with target (where applicable) set to the selected "
2541 "Objects/Bones";
2542 ot->idname = "POSE_OT_constraint_add_with_targets";
2543
2544 /* API callbacks. */
2545 ot->invoke = WM_menu_invoke;
2548
2549 /* flags */
2550 ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
2551
2552 /* properties */
2553 ot->prop = RNA_def_enum(ot->srna, "type", rna_enum_constraint_type_items, 0, "Type", "");
2554}
2555
2557
2558/* ------------------------------------------------------------------- */
2563
2564/* TODO: should these be here, or back in `editors/armature/poseobject.c` again? */
2565
2566/* present menu with options + validation for targets to use */
2568{
2571 bConstraint *con = nullptr;
2572
2573 uiPopupMenu *pup;
2574 uiLayout *layout;
2575 Object *tar_ob = nullptr;
2576 bPoseChannel *tar_pchan = nullptr;
2577
2578 /* must have active bone */
2579 if (ELEM(nullptr, ob, pchan)) {
2580 BKE_report(op->reports, RPT_ERROR, "Must have an active bone to add IK constraint to");
2581 return OPERATOR_CANCELLED;
2582 }
2583
2584 /* bone must not have any constraints already */
2585 for (con = static_cast<bConstraint *>(pchan->constraints.first); con; con = con->next) {
2586 if (con->type == CONSTRAINT_TYPE_KINEMATIC) {
2587 break;
2588 }
2589 }
2590 if (con) {
2591 BKE_report(op->reports, RPT_ERROR, "Bone already has an IK constraint");
2592 return OPERATOR_CANCELLED;
2593 }
2594
2595 /* prepare popup menu to choose targeting options */
2596 pup = UI_popup_menu_begin(C, IFACE_("Add IK"), ICON_NONE);
2597 layout = UI_popup_menu_layout(pup);
2598
2599 /* the type of targets we'll set determines the menu entries to show... */
2600 if (get_new_constraint_target(C, CONSTRAINT_TYPE_KINEMATIC, &tar_ob, &tar_pchan, false)) {
2601 /* bone target, or object target?
2602 * - the only thing that matters is that we want a target...
2603 */
2604 if (tar_pchan) {
2605 PointerRNA op_ptr = layout->op("POSE_OT_ik_add", IFACE_("To Active Bone"), ICON_NONE);
2606 RNA_boolean_set(&op_ptr, "with_targets", true);
2607 }
2608 else {
2609 PointerRNA op_ptr = layout->op("POSE_OT_ik_add", IFACE_("To Active Object"), ICON_NONE);
2610 RNA_boolean_set(&op_ptr, "with_targets", true);
2611 }
2612 }
2613 else {
2614 /* we have a choice of adding to a new empty, or not setting any target (targetless IK) */
2615 PointerRNA op_ptr = layout->op("POSE_OT_ik_add", IFACE_("To New Empty Object"), ICON_NONE);
2616 RNA_boolean_set(&op_ptr, "with_targets", true);
2617 op_ptr = layout->op("POSE_OT_ik_add", IFACE_("Without Targets"), ICON_NONE);
2618 RNA_boolean_set(&op_ptr, "with_targets", false);
2619 }
2620
2621 /* finish building the menu, and process it (should result in calling self again) */
2622 UI_popup_menu_end(C, pup);
2623
2624 return OPERATOR_INTERFACE;
2625}
2626
2627/* call constraint_add_exec() to add the IK constraint */
2629{
2631 const bool with_targets = RNA_boolean_get(op->ptr, "with_targets");
2632
2633 /* add the constraint - all necessary checks should have
2634 * been done by the invoke() callback already... */
2635 return constraint_add_exec(
2636 C, op, ob, constraint_active_list(ob), CONSTRAINT_TYPE_KINEMATIC, with_targets);
2637}
2638
2640{
2641 /* identifiers */
2642 ot->name = "Add IK to Bone";
2643 ot->description = "Add IK Constraint to the active Bone";
2644 ot->idname = "POSE_OT_ik_add";
2645
2646 /* API callbacks. */
2647 ot->invoke = pose_ik_add_invoke;
2648 ot->exec = pose_ik_add_exec;
2650
2651 /* flags */
2652 ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
2653
2654 /* properties */
2655 RNA_def_boolean(ot->srna,
2656 "with_targets",
2657 true,
2658 "With Targets",
2659 "Assign IK Constraint with targets derived from the select bones/objects");
2660}
2661
2663
2664/* ------------------------------------------------------------------- */
2669
2671{
2672 Object *prev_ob = nullptr;
2673
2674 /* only remove IK Constraints */
2675 CTX_DATA_BEGIN_WITH_ID (C, bPoseChannel *, pchan, selected_pose_bones, Object *, ob) {
2676 bConstraint *con, *next;
2677
2678 /* TODO: should we be checking if these constraints were local
2679 * before we try and remove them? */
2680 for (con = static_cast<bConstraint *>(pchan->constraints.first); con; con = next) {
2681 next = con->next;
2682 if (con->type == CONSTRAINT_TYPE_KINEMATIC) {
2683 BKE_constraint_remove_ex(&pchan->constraints, ob, con);
2684 }
2685 }
2686 pchan->constflag &= ~(PCHAN_HAS_IK | PCHAN_HAS_NO_TARGET);
2687
2688 if (prev_ob != ob) {
2689 prev_ob = ob;
2690
2691 /* Refresh depsgraph. */
2693
2694 /* NOTE: notifier might evolve. */
2696 }
2697 }
2699
2700 return OPERATOR_FINISHED;
2701}
2702
2704{
2705 /* identifiers */
2706 ot->name = "Remove IK";
2707 ot->description = "Remove all IK Constraints from selected bones";
2708 ot->idname = "POSE_OT_ik_clear";
2709
2710 /* API callbacks. */
2711 ot->exec = pose_ik_clear_exec;
2713
2714 /* flags */
2715 ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
2716}
2717
2719
2720} // namespace blender::ed::object
Functions and classes to work with Actions.
Functions for backward compatibility with the legacy Action API.
Functions to work with AnimData.
void BIK_test_constraint(struct Object *ob, struct bConstraint *cons)
Blender kernel action and pose functionality.
void BKE_pose_tag_recalc(Main *bmain, bPose *pose) ATTR_NONNULL(1
void BKE_pose_update_constraint_flags(bPose *pose) ATTR_NONNULL(1)
bPoseChannel * BKE_pose_channel_active_or_first_selected(Object *ob) ATTR_WARN_UNUSED_RESULT
bPoseChannel * BKE_pose_channel_active_if_bonecoll_visible(Object *ob) ATTR_WARN_UNUSED_RESULT
void BKE_pose_tag_update_constraint_flags(bPose *pose) ATTR_NONNULL(1)
bArmature * BKE_armature_from_object(Object *ob)
Definition armature.cc:546
Bone * BKE_armature_find_bone_name(bArmature *arm, const char *name)
Definition armature.cc:812
struct bConstraint * BKE_constraints_find_name(struct ListBase *list, const char *name)
void BKE_constraints_free(struct ListBase *list)
void BKE_constraint_targets_flush(struct bConstraint *con, struct ListBase *targets, bool no_copy)
int BKE_constraint_targets_get(struct bConstraint *con, struct ListBase *r_targets)
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)
struct bConstraint * BKE_constraint_copy_for_pose(struct Object *ob, struct bPoseChannel *pchan, struct bConstraint *src)
struct bConstraint * BKE_constraint_add_for_object(struct Object *ob, const char *name, short type)
bool BKE_constraint_apply_and_remove_for_pose(struct Depsgraph *depsgraph, struct Scene *scene, ListBase *constraints, struct Object *ob, struct bConstraint *con, struct bPoseChannel *pchan)
bool BKE_constraint_is_nonlocal_in_liboverride(const struct Object *ob, const struct bConstraint *con)
struct bConstraint * BKE_constraint_add_for_pose(struct Object *ob, struct bPoseChannel *pchan, const char *name, short type)
bool BKE_constraint_apply_and_remove_for_object(struct Depsgraph *depsgraph, struct Scene *scene, ListBase *constraints, struct Object *ob, struct bConstraint *con)
struct bConstraint * BKE_constraint_copy_for_object(struct Object *ob, struct bConstraint *src)
struct bConstraint * BKE_constraints_active_get(struct ListBase *list)
void BKE_constraints_active_set(ListBase *list, struct bConstraint *con)
#define CTX_DATA_BEGIN_WITH_ID(C, Type, instance, member, Type_id, instance_id)
PointerRNA CTX_data_pointer_get(const bContext *C, const char *member)
bPoseChannel * CTX_data_active_pose_bone(const bContext *C)
#define CTX_DATA_BEGIN(C, Type, instance, member)
PointerRNA CTX_data_pointer_get_type(const bContext *C, const char *member, StructRNA *type)
void CTX_wm_operator_poll_msg_set(bContext *C, const char *msg)
Depsgraph * CTX_data_ensure_evaluated_depsgraph(const bContext *C)
Object * CTX_data_active_object(const bContext *C)
Scene * CTX_data_scene(const bContext *C)
Main * CTX_data_main(const bContext *C)
#define CTX_DATA_END
ViewLayer * CTX_data_view_layer(const bContext *C)
FModifier * add_fmodifier(ListBase *modifiers, int type, FCurve *owner_fcu)
@ G_DEBUG
void BKE_view_layer_synced_ensure(const Scene *scene, ViewLayer *view_layer)
Base * BKE_view_layer_active_base_get(ViewLayer *view_layer)
General operations, lookup, etc. for blender objects.
bool BKE_object_exists_check(Main *bmain, const Object *obtest)
Object * BKE_object_add(Main *bmain, Scene *scene, ViewLayer *view_layer, int type, const char *name) ATTR_NONNULL(1
void BKE_object_eval_constraints(Depsgraph *depsgraph, Scene *scene, Object *ob)
Object * BKE_object_pose_armature_get(Object *ob)
void BKE_reportf(ReportList *reports, eReportType type, const char *format,...) ATTR_PRINTF_FORMAT(3
void BKE_report(ReportList *reports, eReportType type, const char *message)
Definition report.cc:126
struct MovieTrackingObject * BKE_tracking_object_get_camera(const struct MovieTracking *tracking)
struct MovieTrackingObject * BKE_tracking_object_get_named(struct MovieTracking *tracking, const char *name)
Definition tracking.cc:1965
struct MovieTrackingTrack * BKE_tracking_object_find_track_with_name(struct MovieTrackingObject *tracking_object, const char *name)
Definition tracking.cc:1992
#define BLI_assert(a)
Definition BLI_assert.h:46
A dynamically sized string ADT.
int BLI_findindex(const ListBase *listbase, const void *vlink) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
Definition listbase.cc:586
#define LISTBASE_FOREACH(type, var, list)
void BLI_addtail(ListBase *listbase, void *vlink) ATTR_NONNULL(1)
Definition listbase.cc:111
void BLI_insertlinkafter(ListBase *listbase, void *vprevlink, void *vnewlink) ATTR_NONNULL(1)
Definition listbase.cc:332
void BLI_remlink(ListBase *listbase, void *vlink) ATTR_NONNULL(1)
Definition listbase.cc:131
void void void bool BLI_listbase_link_move(ListBase *listbase, void *vlink, int step) ATTR_NONNULL()
Definition listbase.cc:436
int BLI_listbase_count(const ListBase *listbase) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
Definition listbase.cc:524
void BLI_insertlinkbefore(ListBase *listbase, void *vnextlink, void *vnewlink) ATTR_NONNULL(1)
Definition listbase.cc:371
void mul_v3_m4v3(float r[3], const float mat[4][4], const float vec[3])
void unit_m4(float m[4][4])
MINLINE void copy_v3_v3(float r[3], const float a[3])
char * STRNCPY(char(&dst)[N], const char *src)
Definition BLI_string.h:688
#define UNUSED_VARS(...)
#define ELEM(...)
#define STREQ(a, b)
#define IFACE_(msgid)
void DEG_id_tag_update(ID *id, unsigned int flags)
void DEG_relations_tag_update(Main *bmain)
Scene * DEG_get_evaluated_scene(const Depsgraph *graph)
@ ID_RECALC_TRANSFORM
Definition DNA_ID.h:962
@ ID_RECALC_SYNC_TO_EVAL
Definition DNA_ID.h:1026
@ ID_RECALC_GEOMETRY
Definition DNA_ID.h:982
@ ID_OB
@ PCHAN_HAS_NO_TARGET
@ PCHAN_HAS_IK
@ FMODIFIER_TYPE_GENERATOR
@ CONSTRAINT_OFF
@ CONSTRAINT_OVERRIDE_LIBRARY_LOCAL
@ 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_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
@ OB_MODE_POSE
Object is a sort of wrapper for general info.
@ OB_EMPTY
@ OB_ARMATURE
@ OB_MESH
@ OB_CURVES_LEGACY
#define MINAFRAME
#define MAXFRAME
@ OPERATOR_CANCELLED
@ OPERATOR_INTERFACE
@ OPERATOR_FINISHED
@ OPERATOR_PASS_THROUGH
bool ED_operator_object_active_local_editable(bContext *C)
bool ED_operator_object_active_editable(bContext *C)
bool ED_operator_posemode_exclusive(bContext *C)
bool ED_operator_object_active_local_editable_posemode_exclusive(bContext *C)
bool ED_operator_object_active_editable_ex(bContext *C, const Object *ob)
Read Guarded memory(de)allocation.
@ PROP_SKIP_SAVE
Definition RNA_types.hh:330
@ PROP_HIDDEN
Definition RNA_types.hh:324
#define C
Definition RandGen.cpp:29
void UI_popup_menu_end(bContext *C, uiPopupMenu *pup)
uiPopupMenu * UI_popup_menu_begin(bContext *C, const char *title, int icon) ATTR_NONNULL()
uiLayout * UI_popup_menu_layout(uiPopupMenu *pup)
PointerRNA * UI_region_panel_custom_data_under_cursor(const bContext *C, const wmEvent *event)
@ OPTYPE_UNDO
Definition WM_types.hh:182
@ OPTYPE_REGISTER
Definition WM_types.hh:180
#define NA_ADDED
Definition WM_types.hh:583
#define ND_POSE
Definition WM_types.hh:455
#define ND_CONSTRAINT
Definition WM_types.hh:461
#define NA_REMOVED
Definition WM_types.hh:584
#define ND_TRANSFORM
Definition WM_types.hh:453
#define NC_OBJECT
Definition WM_types.hh:376
BMesh const char void * data
#define A
BPy_StructRNA * depsgraph
btSequentialImpulseConstraintSolverMt int btPersistentManifold int btTypedConstraint ** constraints
Slot * slot_for_handle(slot_handle_t handle)
#define abs
#define printf(...)
#define MEM_SAFE_FREE(v)
#define ID_IS_EDITABLE(_id)
#define MAX_NAME
void * MEM_callocN(size_t len, const char *str)
Definition mallocn.cc:118
static ulong * next
#define B
#define G(x, y, z)
static void add(blender::Map< std::string, std::string > &messages, Message &msg)
Definition msgfmt.cc:222
bool action_treat_as_legacy(const bAction &action)
bAction * id_action_ensure(Main *bmain, ID *id)
Definition animdata.cc:195
FCurve * action_fcurve_ensure_ex(Main *bmain, bAction *act, const char group[], PointerRNA *ptr, const FCurveDescriptor &fcurve_descriptor)
FCurve * fcurve_find_in_assigned_slot(AnimData &adt, const FCurveDescriptor &fcurve_descriptor)
static int constraint_type_get(Object *owner, bPoseChannel *pchan)
void object_test_constraints(Main *bmain, Object *ob)
static wmOperatorStatus objectsolver_set_inverse_exec(bContext *C, wmOperator *op)
static bool edit_constraint_poll(bContext *C)
bConstraint * constraint_active_get(Object *ob)
void constraint_link(Main *bmain, Object *ob_dst, ListBase *dst, ListBase *src)
static wmOperatorStatus constraint_move_up_invoke(bContext *C, wmOperator *op, const wmEvent *event)
static wmOperatorStatus followpath_path_animate_exec(bContext *C, wmOperator *op)
static wmOperatorStatus constraint_move_down_invoke(bContext *C, wmOperator *op, const wmEvent *event)
static bool edit_constraint_poll_generic(bContext *C, StructRNA *rna_type, const bool is_liboverride_allowed)
void constraint_copy_for_object(Main *bmain, Object *ob_dst, bConstraint *con)
static void object_pose_tag_update(Main *bmain, Object *ob)
static wmOperatorStatus constraint_copy_invoke(bContext *C, wmOperator *op, const wmEvent *event)
void CONSTRAINT_OT_move_down(wmOperatorType *ot)
static void edit_constraint_report_property(wmOperatorType *ot)
static void object_test_constraint(Main *bmain, Object *ob, bConstraint *con)
void constraint_active_set(Object *ob, bConstraint *con)
static wmOperatorStatus constraint_delete_exec(bContext *C, wmOperator *op)
static wmOperatorStatus childof_set_inverse_invoke(bContext *C, wmOperator *op, const wmEvent *)
void constraint_copy_for_pose(Main *bmain, Object *ob_dst, bPoseChannel *pchan, bConstraint *con)
static wmOperatorStatus constraint_apply_exec(bContext *C, wmOperator *op)
static void test_constraints(Main *bmain, Object *ob, bPoseChannel *pchan)
static wmOperatorStatus constraint_copy_to_selected_invoke(bContext *C, wmOperator *op, const wmEvent *event)
void constraint_dependency_tag_update(Main *bmain, Object *ob, bConstraint *con)
static bool edit_constraint_liboverride_allowed_poll(bContext *C)
static wmOperatorStatus constraint_add_exec(bContext *C, wmOperator *op, Object *ob, ListBase *list, int type, const bool setTarget)
void constraint_update(Main *bmain, Object *ob)
static bConstraint * edit_constraint_property_get(bContext *C, wmOperator *op, Object *ob, int type)
static wmOperatorStatus childof_clear_inverse_invoke(bContext *C, wmOperator *op, const wmEvent *)
static const EnumPropertyItem * object_constraint_add_itemf(bContext *, PointerRNA *, PropertyRNA *, bool *r_free)
static wmOperatorStatus object_constraint_add_exec(bContext *C, wmOperator *op)
static wmOperatorStatus constraint_copy_exec(bContext *C, wmOperator *op)
void OBJECT_OT_constraint_add_with_targets(wmOperatorType *ot)
void CONSTRAINT_OT_objectsolver_set_inverse(wmOperatorType *ot)
static bool constraint_copy_to_selected_poll(bContext *C)
static void force_evaluation_if_constraint_disabled(bContext *C, Object *ob, bConstraint *con)
static wmOperatorStatus stretchto_reset_exec(bContext *C, wmOperator *op)
void base_select(Base *base, eObjectSelect_Mode mode)
ListBase * pose_constraint_list(const bContext *C)
static wmOperatorStatus constraint_copy_to_selected_exec(bContext *C, wmOperator *op)
void CONSTRAINT_OT_limitdistance_reset(wmOperatorType *ot)
static wmOperatorStatus pose_ik_clear_exec(bContext *C, wmOperator *)
static wmOperatorStatus objectsolver_clear_inverse_invoke(bContext *C, wmOperator *op, const wmEvent *)
static bool get_new_constraint_target(bContext *C, int con_type, Object **tar_ob, bPoseChannel **tar_pchan, bool add)
static wmOperatorStatus constraint_move_up_exec(bContext *C, wmOperator *op)
static wmOperatorStatus pose_ik_add_invoke(bContext *C, wmOperator *op, const wmEvent *)
static wmOperatorStatus limitdistance_reset_exec(bContext *C, wmOperator *op)
static wmOperatorStatus constraint_move_down_exec(bContext *C, wmOperator *op)
void CONSTRAINT_OT_copy(wmOperatorType *ot)
void CONSTRAINT_OT_apply(wmOperatorType *ot)
void constraint_tag_update(Main *bmain, Object *ob, bConstraint *con)
static wmOperatorStatus objectsolver_set_inverse_invoke(bContext *C, wmOperator *op, const wmEvent *)
void CONSTRAINT_OT_move_up(wmOperatorType *ot)
ListBase * constraint_active_list(Object *ob)
void POSE_OT_constraints_copy(wmOperatorType *ot)
static wmOperatorStatus childof_clear_inverse_exec(bContext *C, wmOperator *op)
static wmOperatorStatus object_constraint_copy_exec(bContext *C, wmOperator *)
static wmOperatorStatus objectsolver_clear_inverse_exec(bContext *C, wmOperator *op)
static wmOperatorStatus childof_set_inverse_exec(bContext *C, wmOperator *op)
static wmOperatorStatus limitdistance_reset_invoke(bContext *C, wmOperator *op, const wmEvent *)
static wmOperatorStatus constraint_apply_invoke(bContext *C, wmOperator *op, const wmEvent *event)
Object * context_active_object(const bContext *C)
static wmOperatorStatus constraint_delete_invoke(bContext *C, wmOperator *op, const wmEvent *event)
static wmOperatorStatus constraint_move_to_index_invoke(bContext *C, wmOperator *op, const wmEvent *event)
static wmOperatorStatus followpath_path_animate_invoke(bContext *C, wmOperator *op, const wmEvent *)
void POSE_OT_ik_add(wmOperatorType *ot)
void POSE_OT_ik_clear(wmOperatorType *ot)
void POSE_OT_constraint_add(wmOperatorType *ot)
void constraint_dependency_update(Main *bmain, Object *ob)
static wmOperatorStatus constraint_move_to_index_exec(bContext *C, wmOperator *op)
void CONSTRAINT_OT_delete(wmOperatorType *ot)
bool constraint_move_to_index(Object *ob, bConstraint *con, int index)
static wmOperatorStatus stretchto_reset_invoke(bContext *C, wmOperator *op, const wmEvent *)
void CONSTRAINT_OT_stretchto_reset(wmOperatorType *ot)
void OBJECT_OT_constraint_add(wmOperatorType *ot)
static wmOperatorStatus pose_constraints_clear_exec(bContext *C, wmOperator *)
void CONSTRAINT_OT_move_to_index(wmOperatorType *ot)
void OBJECT_OT_constraints_copy(wmOperatorType *ot)
static void test_constraint(Main *bmain, Object *owner, bPoseChannel *pchan, bConstraint *con, int type)
static wmOperatorStatus pose_constraint_add_exec(bContext *C, wmOperator *op)
void OBJECT_OT_constraints_clear(wmOperatorType *ot)
static void edit_constraint_properties(wmOperatorType *ot)
static wmOperatorStatus pose_constraint_copy_exec(bContext *C, wmOperator *op)
static void set_constraint_nth_target(bConstraint *con, Object *target, const char subtarget[], int index)
static wmOperatorStatus pose_ik_add_exec(bContext *C, wmOperator *op)
void CONSTRAINT_OT_objectsolver_clear_inverse(wmOperatorType *ot)
void CONSTRAINT_OT_childof_clear_inverse(wmOperatorType *ot)
void CONSTRAINT_OT_followpath_path_animate(wmOperatorType *ot)
static const EnumPropertyItem constraint_owner_items[]
void CONSTRAINT_OT_childof_set_inverse(wmOperatorType *ot)
void POSE_OT_constraint_add_with_targets(wmOperatorType *ot)
static wmOperatorStatus object_constraints_clear_exec(bContext *C, wmOperator *)
void CONSTRAINT_OT_copy_to_selected(wmOperatorType *ot)
void POSE_OT_constraints_clear(wmOperatorType *ot)
static bool edit_constraint_invoke_properties(bContext *C, wmOperator *op, const wmEvent *event, wmOperatorStatus *r_retval)
ListBase * constraint_list_from_constraint(Object *ob, bConstraint *con, bPoseChannel **r_pchan)
#define EDIT_CONSTRAINT_OWNER_BONE
#define EDIT_CONSTRAINT_OWNER_OBJECT
bool RNA_struct_is_a(const StructRNA *type, const StructRNA *srna)
void RNA_string_set(PointerRNA *ptr, const char *name, const char *value)
PropertyRNA * RNA_struct_find_property(PointerRNA *ptr, const char *identifier)
void RNA_boolean_set(PointerRNA *ptr, const char *name, bool value)
void RNA_string_get(PointerRNA *ptr, const char *name, char *value)
int RNA_int_get(PointerRNA *ptr, const char *name)
bool RNA_pointer_is_null(const PointerRNA *ptr)
bool RNA_struct_property_is_set(PointerRNA *ptr, const char *identifier)
bool RNA_boolean_get(PointerRNA *ptr, const char *name)
void RNA_enum_set(PointerRNA *ptr, const char *name, int value)
PointerRNA RNA_pointer_create_discrete(ID *id, StructRNA *type, void *data)
int RNA_enum_get(PointerRNA *ptr, const char *name)
PointerRNA RNA_id_pointer_create(ID *id)
const EnumPropertyItem rna_enum_constraint_type_items[]
PropertyRNA * RNA_def_string(StructOrFunctionRNA *cont_, const char *identifier, const char *default_value, const int maxlen, const char *ui_name, const char *ui_description)
PropertyRNA * RNA_def_enum(StructOrFunctionRNA *cont_, const char *identifier, const EnumPropertyItem *items, const int default_value, const char *ui_name, const char *ui_description)
void RNA_enum_item_end(EnumPropertyItem **items, int *totitem)
void RNA_enum_item_add(EnumPropertyItem **items, int *totitem, const EnumPropertyItem *item)
PropertyRNA * RNA_def_boolean(StructOrFunctionRNA *cont_, const char *identifier, const bool default_value, const char *ui_name, const char *ui_description)
void RNA_def_property_flag(PropertyRNA *prop, PropertyFlag flag)
void RNA_def_enum_funcs(PropertyRNA *prop, EnumPropertyItemFunc itemfunc)
PropertyRNA * RNA_def_int(StructOrFunctionRNA *cont_, const char *identifier, const int default_value, const int hardmin, const int hardmax, const char *ui_name, const char *ui_description, const int softmin, const int softmax)
std::optional< std::string > RNA_path_from_ID_to_property(const PointerRNA *ptr, PropertyRNA *prop)
Definition rna_path.cc:1173
const EnumPropertyItem rna_enum_dummy_NULL_items[]
Definition rna_rna.cc:26
bAction * action
struct AnimData * adt
const char * identifier
Definition RNA_types.hh:623
FPoint * fpt
BezTriple * bezt
ListBase modifiers
Definition DNA_ID.h:404
char name[66]
Definition DNA_ID.h:415
void * first
ListBase constraints
struct bPose * pose
float loc[3]
StructRNA * type
Definition RNA_types.hh:52
void * data
Definition RNA_types.hh:53
struct Base * basact
struct bConstraintTarget * next
struct bConstraint * prev
struct bConstraint * next
ListBase chanbase
PointerRNA op(wmOperatorType *ot, std::optional< blender::StringRef > name, int icon, wmOperatorCallContext context, eUI_Item_Flag flag)
struct ReportList * reports
struct PointerRNA * ptr
i
Definition text_draw.cc:230
uint len
void WM_main_add_notifier(uint type, void *reference)
void WM_event_add_notifier(const bContext *C, uint type, void *reference)
PointerRNA * ptr
Definition wm_files.cc:4226
wmOperatorType * ot
Definition wm_files.cc:4225
wmOperatorStatus WM_menu_invoke(bContext *C, wmOperator *op, const wmEvent *)