Blender  V3.3
object_edit.c
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later
2  * Copyright 2001-2002 NaN Holding BV. All rights reserved. */
3 
8 #include <ctype.h>
9 #include <float.h>
10 #include <math.h>
11 #include <stddef.h> /* for offsetof */
12 #include <stdlib.h>
13 #include <string.h>
14 #include <time.h>
15 
16 #include "MEM_guardedalloc.h"
17 
18 #include "BLI_blenlib.h"
19 #include "BLI_ghash.h"
20 #include "BLI_math_rotation.h"
21 #include "BLI_utildefines.h"
22 
23 #include "BLT_translation.h"
24 
25 #include "DNA_armature_types.h"
26 #include "DNA_collection_types.h"
27 #include "DNA_curve_types.h"
28 #include "DNA_gpencil_types.h"
29 #include "DNA_lattice_types.h"
30 #include "DNA_material_types.h"
31 #include "DNA_mesh_types.h"
32 #include "DNA_meshdata_types.h"
33 #include "DNA_meta_types.h"
34 #include "DNA_object_force_types.h"
35 #include "DNA_object_types.h"
36 #include "DNA_scene_types.h"
37 #include "DNA_vfont_types.h"
38 #include "DNA_workspace_types.h"
39 
40 #include "IMB_imbuf_types.h"
41 
42 #include "BKE_anim_visualization.h"
43 #include "BKE_armature.h"
44 #include "BKE_collection.h"
45 #include "BKE_constraint.h"
46 #include "BKE_context.h"
47 #include "BKE_curve.h"
48 #include "BKE_editlattice.h"
49 #include "BKE_editmesh.h"
50 #include "BKE_effect.h"
51 #include "BKE_global.h"
52 #include "BKE_image.h"
53 #include "BKE_lattice.h"
54 #include "BKE_layer.h"
55 #include "BKE_lib_id.h"
56 #include "BKE_main.h"
57 #include "BKE_material.h"
58 #include "BKE_mball.h"
59 #include "BKE_mesh.h"
60 #include "BKE_modifier.h"
61 #include "BKE_object.h"
62 #include "BKE_paint.h"
63 #include "BKE_particle.h"
64 #include "BKE_pointcache.h"
65 #include "BKE_report.h"
66 #include "BKE_scene.h"
67 #include "BKE_softbody.h"
68 #include "BKE_workspace.h"
69 
70 #include "DEG_depsgraph.h"
71 #include "DEG_depsgraph_build.h"
72 
73 #include "ED_anim_api.h"
74 #include "ED_armature.h"
75 #include "ED_curve.h"
76 #include "ED_gpencil.h"
77 #include "ED_image.h"
78 #include "ED_keyframes_keylist.h"
79 #include "ED_lattice.h"
80 #include "ED_mball.h"
81 #include "ED_mesh.h"
82 #include "ED_object.h"
83 #include "ED_outliner.h"
84 #include "ED_screen.h"
85 #include "ED_undo.h"
86 
87 #include "RNA_access.h"
88 #include "RNA_define.h"
89 #include "RNA_enum_types.h"
90 #include "RNA_types.h"
91 
92 #include "UI_interface_icons.h"
93 
94 #include "CLG_log.h"
95 
96 /* For menu/popup icons etc. */
97 
98 #include "UI_interface.h"
99 #include "UI_resources.h"
100 
101 #include "WM_api.h"
102 #include "WM_message.h"
103 #include "WM_toolsystem.h"
104 #include "WM_types.h"
105 
106 #include "object_intern.h" /* own include */
107 
108 static CLG_LogRef LOG = {"ed.object.edit"};
109 
110 /* prototypes */
112 static void move_to_collection_menus_items(struct uiLayout *layout,
113  struct MoveToCollectionData *menu);
115 
116 /* -------------------------------------------------------------------- */
121 {
122  return CTX_data_pointer_get_type(C, "object", &RNA_Object).data;
123 }
124 
126 {
127  Object *ob = NULL;
128  if (C) {
129  ob = ED_object_context(C);
130  if (!ob) {
132  }
133  }
134  return ob;
135 }
136 
138  bool (*filter_fn)(const Object *ob, void *user_data),
139  void *filter_user_data,
140  uint *r_objects_len)
141 {
143  ViewLayer *view_layer = CTX_data_view_layer(C);
144  Object *ob_active = OBACT(view_layer);
145  ID *id_pin = NULL;
146  const bool use_objects_in_mode = (ob_active != NULL) &&
147  (ob_active->mode & (OB_MODE_EDIT | OB_MODE_POSE));
148  const char space_type = area ? area->spacetype : SPACE_EMPTY;
149  Object **objects;
150 
151  Object *ob = NULL;
152  bool use_ob = true;
153 
154  if (space_type == SPACE_PROPERTIES) {
155  SpaceProperties *sbuts = area->spacedata.first;
156  id_pin = sbuts->pinid;
157  }
158 
159  if (id_pin && (GS(id_pin->name) == ID_OB)) {
160  /* Pinned data takes priority, in this case ignore selection & other objects in the mode. */
161  ob = (Object *)id_pin;
162  }
163  else if ((space_type == SPACE_PROPERTIES) && (use_objects_in_mode == false)) {
164  /* When using the space-properties, we don't want to use the entire selection
165  * as the current active object may not be selected.
166  *
167  * This is not the case when we're in a mode that supports multi-mode editing,
168  * since the active object and all other objects in the mode will be included
169  * irrespective of selection. */
170  ob = ob_active;
171  }
172  else if (ob_active && (ob_active->mode &
174  /* When painting, limit to active. */
175  ob = ob_active;
176  }
177  else {
178  /* Otherwise use full selection. */
179  use_ob = false;
180  }
181 
182  if (use_ob) {
183  if ((ob != NULL) && !filter_fn(ob, filter_user_data)) {
184  ob = NULL;
185  }
186  *r_objects_len = (ob != NULL) ? 1 : 0;
187  objects = MEM_mallocN(sizeof(*objects) * *r_objects_len, __func__);
188  if (ob != NULL) {
189  objects[0] = ob;
190  }
191  }
192  else {
193  const View3D *v3d = (space_type == SPACE_VIEW3D) ? area->spacedata.first : NULL;
194  /* When in a mode that supports multiple active objects, use "objects in mode"
195  * instead of the object's selection. */
196  if (use_objects_in_mode) {
197  objects = BKE_view_layer_array_from_objects_in_mode(view_layer,
198  v3d,
199  r_objects_len,
200  {.object_mode = ob_active->mode,
201  .no_dup_data = true,
202  .filter_fn = filter_fn,
203  .filter_userdata = filter_user_data});
204  }
205  else {
207  view_layer,
208  v3d,
209  r_objects_len,
210  {.no_dup_data = true, .filter_fn = filter_fn, .filter_userdata = filter_user_data});
211  }
212  }
213  return objects;
214 }
215 
218 /* -------------------------------------------------------------------- */
223 {
224  if (CTX_wm_space_outliner(C) != NULL) {
226  }
228 }
229 
231 {
233  ViewLayer *view_layer = CTX_data_view_layer(C);
234  const bool select = RNA_boolean_get(op->ptr, "select");
235  bool changed = false;
236 
237  LISTBASE_FOREACH (Base *, base, &view_layer->object_bases) {
238  if (base->flag & BASE_HIDDEN) {
239  base->flag &= ~BASE_HIDDEN;
240  changed = true;
241 
242  if (select) {
243  /* We cannot call `ED_object_base_select` because
244  * base is not selectable while it is hidden. */
245  base->flag |= BASE_SELECTED;
247  }
248  }
249  }
250 
251  if (!changed) {
252  return OPERATOR_CANCELLED;
253  }
254 
255  BKE_layer_collection_sync(scene, view_layer);
259 
260  return OPERATOR_FINISHED;
261 }
262 
264 {
265  /* identifiers */
266  ot->name = "Show Hidden Objects";
267  ot->description = "Reveal temporarily hidden objects";
268  ot->idname = "OBJECT_OT_hide_view_clear";
269 
270  /* api callbacks */
273 
274  /* flags */
276 
277  PropertyRNA *prop = RNA_def_boolean(ot->srna, "select", true, "Select", "");
279 }
280 
282 {
284  ViewLayer *view_layer = CTX_data_view_layer(C);
285  const bool unselected = RNA_boolean_get(op->ptr, "unselected");
286  bool changed = false;
287 
288  /* Hide selected or unselected objects. */
289  LISTBASE_FOREACH (Base *, base, &view_layer->object_bases) {
290  if (!(base->flag & BASE_VISIBLE_VIEWLAYER)) {
291  continue;
292  }
293 
294  if (!unselected) {
295  if (base->flag & BASE_SELECTED) {
297  base->flag |= BASE_HIDDEN;
298  changed = true;
299  }
300  }
301  else {
302  if (!(base->flag & BASE_SELECTED)) {
304  base->flag |= BASE_HIDDEN;
305  changed = true;
306  }
307  }
308  }
309  if (!changed) {
310  return OPERATOR_CANCELLED;
311  }
312 
313  BKE_layer_collection_sync(scene, view_layer);
317 
318  return OPERATOR_FINISHED;
319 }
320 
322 {
323  /* identifiers */
324  ot->name = "Hide Objects";
325  ot->description = "Temporarily hide objects from the viewport";
326  ot->idname = "OBJECT_OT_hide_view_set";
327 
328  /* api callbacks */
331 
332  /* flags */
334 
335  PropertyRNA *prop;
336  prop = RNA_def_boolean(
337  ot->srna, "unselected", 0, "Unselected", "Hide unselected rather than selected objects");
339 }
340 
342 {
343  View3D *v3d = CTX_wm_view3d(C);
344 
345  int index = RNA_int_get(op->ptr, "collection_index");
346  const bool extend = RNA_boolean_get(op->ptr, "extend");
347  const bool toggle = RNA_boolean_get(op->ptr, "toggle");
348 
350  ViewLayer *view_layer = CTX_data_view_layer(C);
352 
353  if (!lc) {
354  return OPERATOR_CANCELLED;
355  }
356 
358 
359  if (v3d->flag & V3D_LOCAL_COLLECTIONS) {
361  return OPERATOR_CANCELLED;
362  }
363  if (toggle) {
365  BKE_layer_collection_local_sync(view_layer, v3d);
366  }
367  else {
368  BKE_layer_collection_isolate_local(view_layer, v3d, lc, extend);
369  }
370  }
371  else {
372  BKE_layer_collection_isolate_global(scene, view_layer, lc, extend);
373  }
374 
376 
377  return OPERATOR_FINISHED;
378 }
379 
380 #define COLLECTION_INVALID_INDEX -1
381 
383 {
384  ViewLayer *view_layer = CTX_data_view_layer(C);
385  LayerCollection *lc_scene = view_layer->layer_collections.first;
386 
388 
390  int index = BKE_layer_collection_findindex(view_layer, lc);
391  uiLayout *row = uiLayoutRow(layout, false);
392 
393  if (lc->flag & LAYER_COLLECTION_EXCLUDE) {
394  continue;
395  }
396 
397  if (lc->collection->flag & COLLECTION_HIDE_VIEWPORT) {
398  continue;
399  }
400 
401  int icon = ICON_NONE;
402  if (BKE_layer_collection_has_selected_objects(view_layer, lc)) {
403  icon = ICON_LAYER_ACTIVE;
404  }
405  else if (lc->runtime_flag & LAYER_COLLECTION_HAS_OBJECTS) {
406  icon = ICON_LAYER_USED;
407  }
408 
409  uiItemIntO(row,
410  lc->collection->id.name + 2,
411  icon,
412  "OBJECT_OT_hide_collection",
413  "collection_index",
414  index);
415  }
416 }
417 
419 {
420  /* Immediately execute if collection index was specified. */
421  int index = RNA_int_get(op->ptr, "collection_index");
423  /* Only initialize extend from the shift key if the property isn't set
424  * (typically initialized from the key-map). */
425  PropertyRNA *prop = RNA_struct_find_property(op->ptr, "extend");
426  if (!RNA_property_is_set(op->ptr, prop)) {
427  RNA_property_boolean_set(op->ptr, prop, (event->modifier & KM_SHIFT) != 0);
428  }
429  return object_hide_collection_exec(C, op);
430  }
431 
432  /* Open popup menu. */
433  const char *title = CTX_IFACE_(op->type->translation_context, op->type->name);
434  uiPopupMenu *pup = UI_popup_menu_begin(C, title, ICON_OUTLINER_COLLECTION);
435  uiLayout *layout = UI_popup_menu_layout(pup);
436 
438 
439  UI_popup_menu_end(C, pup);
440 
441  return OPERATOR_INTERFACE;
442 }
443 
445 {
446  /* identifiers */
447  ot->name = "Hide Collection";
448  ot->description = "Show only objects in collection (Shift to extend)";
449  ot->idname = "OBJECT_OT_hide_collection";
450 
451  /* api callbacks */
455 
456  /* flags */
458 
459  /* Properties. */
460  PropertyRNA *prop;
461  prop = RNA_def_int(ot->srna,
462  "collection_index",
465  INT_MAX,
466  "Collection Index",
467  "Index of the collection to change visibility",
468  0,
469  INT_MAX);
471  prop = RNA_def_boolean(ot->srna, "toggle", 0, "Toggle", "Toggle visibility");
473  prop = RNA_def_boolean(ot->srna, "extend", 0, "Extend", "Extend visibility");
475 }
476 
479 /* -------------------------------------------------------------------- */
483 static bool mesh_needs_keyindex(Main *bmain, const Mesh *me)
484 {
485  if (me->key) {
486  return false; /* will be added */
487  }
488 
489  LISTBASE_FOREACH (const Object *, ob, &bmain->objects) {
490  if ((ob->parent) && (ob->parent->data == me) && ELEM(ob->partype, PARVERT1, PARVERT3)) {
491  return true;
492  }
493  if (ob->data == me) {
494  LISTBASE_FOREACH (const ModifierData *, md, &ob->modifiers) {
495  if (md->type == eModifierType_Hook) {
496  return true;
497  }
498  }
499  }
500  }
501  return false;
502 }
503 
511  Object *obedit,
512  const bool load_data,
513  const bool free_data)
514 {
515  BLI_assert(load_data || free_data);
516 
517  if (obedit == NULL) {
518  return false;
519  }
520 
521  if (obedit->type == OB_MESH) {
522  Mesh *me = obedit->data;
523  if (me->edit_mesh == NULL) {
524  return false;
525  }
526 
527  if (me->edit_mesh->bm->totvert > MESH_MAX_VERTS) {
528  /* This used to be warned int the UI, we could warn again although it's quite rare. */
529  CLOG_WARN(&LOG,
530  "Too many vertices for mesh '%s' (%d)",
531  me->id.name + 2,
532  me->edit_mesh->bm->totvert);
533  return false;
534  }
535 
536  if (load_data) {
537  EDBM_mesh_load_ex(bmain, obedit, free_data);
538  }
539 
540  if (free_data) {
542  MEM_freeN(me->edit_mesh);
543  me->edit_mesh = NULL;
544  }
545  /* will be recalculated as needed. */
546  {
549  }
550  }
551  else if (obedit->type == OB_ARMATURE) {
552  const bArmature *arm = obedit->data;
553  if (arm->edbo == NULL) {
554  return false;
555  }
556 
557  if (load_data) {
558  ED_armature_from_edit(bmain, obedit->data);
559  }
560 
561  if (free_data) {
562  ED_armature_edit_free(obedit->data);
563 
564  if (load_data == false) {
565  /* Don't keep unused pose channels created by duplicating bones
566  * which may have been deleted/undone, see: T87631. */
567  if (obedit->pose != NULL) {
569  }
570  }
571  }
572  /* TODO(sergey): Pose channels might have been changed, so need
573  * to inform dependency graph about this. But is it really the
574  * best place to do this?
575  */
577  }
578  else if (ELEM(obedit->type, OB_CURVES_LEGACY, OB_SURF)) {
579  const Curve *cu = obedit->data;
580  if (cu->editnurb == NULL) {
581  return false;
582  }
583 
584  if (load_data) {
585  ED_curve_editnurb_load(bmain, obedit);
586  }
587 
588  if (free_data) {
589  ED_curve_editnurb_free(obedit);
590  }
591  }
592  else if (obedit->type == OB_FONT) {
593  const Curve *cu = obedit->data;
594  if (cu->editfont == NULL) {
595  return false;
596  }
597 
598  if (load_data) {
599  ED_curve_editfont_load(obedit);
600  }
601 
602  if (free_data) {
603  ED_curve_editfont_free(obedit);
604  }
605  }
606  else if (obedit->type == OB_LATTICE) {
607  const Lattice *lt = obedit->data;
608  if (lt->editlatt == NULL) {
609  return false;
610  }
611 
612  if (load_data) {
613  BKE_editlattice_load(obedit);
614  }
615 
616  if (free_data) {
617  BKE_editlattice_free(obedit);
618  }
619  }
620  else if (obedit->type == OB_MBALL) {
621  const MetaBall *mb = obedit->data;
622  if (mb->editelems == NULL) {
623  return false;
624  }
625 
626  if (load_data) {
627  ED_mball_editmball_load(obedit);
628  }
629 
630  if (free_data) {
631  ED_mball_editmball_free(obedit);
632  }
633  }
634  else {
635  return false;
636  }
637 
638  if (load_data) {
639  char *needs_flush_ptr = BKE_object_data_editmode_flush_ptr_get(obedit->data);
640  if (needs_flush_ptr) {
641  *needs_flush_ptr = false;
642  }
643  }
644 
645  return true;
646 }
647 
648 bool ED_object_editmode_load(Main *bmain, Object *obedit)
649 {
650  return ED_object_editmode_load_free_ex(bmain, obedit, true, false);
651 }
652 
653 bool ED_object_editmode_exit_ex(Main *bmain, Scene *scene, Object *obedit, int flag)
654 {
655  const bool free_data = (flag & EM_FREEDATA) != 0;
656 
657  if (ED_object_editmode_load_free_ex(bmain, obedit, true, free_data) == false) {
658  /* in rare cases (background mode) its possible active object
659  * is flagged for editmode, without 'obedit' being set T35489. */
660  if (UNLIKELY(obedit && obedit->mode & OB_MODE_EDIT)) {
661  obedit->mode &= ~OB_MODE_EDIT;
662  /* Also happens when mesh is shared across multiple objects. [#T69834] */
664  }
665  return true;
666  }
667 
668  /* `free_data` only false now on file saves and render. */
669  if (free_data) {
670  /* flag object caches as outdated */
671  ListBase pidlist;
672  BKE_ptcache_ids_from_object(&pidlist, obedit, scene, 0);
673  LISTBASE_FOREACH (PTCacheID *, pid, &pidlist) {
674  /* particles don't need reset on geometry change */
675  if (pid->type != PTCACHE_TYPE_PARTICLES) {
676  pid->cache->flag |= PTCACHE_OUTDATED;
677  }
678  }
679  BLI_freelistN(&pidlist);
680 
683 
684  /* also flush ob recalc, doesn't take much overhead, but used for particles */
686 
688 
689  obedit->mode &= ~OB_MODE_EDIT;
690  }
691 
692  return (obedit->mode & OB_MODE_EDIT) == 0;
693 }
694 
696 {
697  Main *bmain = CTX_data_main(C);
699  Object *obedit = CTX_data_edit_object(C);
700  return ED_object_editmode_exit_ex(bmain, scene, obedit, flag);
701 }
702 
704 {
705  return ED_object_editmode_load_free_ex(bmain, obedit, false, true);
706 }
707 
708 bool ED_object_editmode_exit_multi_ex(Main *bmain, Scene *scene, ViewLayer *view_layer, int flag)
709 {
710  Object *obedit = OBEDIT_FROM_VIEW_LAYER(view_layer);
711  if (obedit == NULL) {
712  return false;
713  }
714  bool changed = false;
715  const short obedit_type = obedit->type;
716 
717  LISTBASE_FOREACH (Base *, base, &view_layer->object_bases) {
718  Object *ob = base->object;
719  if ((ob->type == obedit_type) && (ob->mode & OB_MODE_EDIT)) {
720  changed |= ED_object_editmode_exit_ex(bmain, scene, base->object, flag);
721  }
722  }
723  return changed;
724 }
725 
727 {
728  Main *bmain = CTX_data_main(C);
730  ViewLayer *view_layer = CTX_data_view_layer(C);
731  return ED_object_editmode_exit_multi_ex(bmain, scene, view_layer, flag);
732 }
733 
734 bool ED_object_editmode_enter_ex(Main *bmain, Scene *scene, Object *ob, int flag)
735 {
736  bool ok = false;
737 
738  if (ELEM(NULL, ob, ob->data) || ID_IS_LINKED(ob) || ID_IS_OVERRIDE_LIBRARY(ob) ||
740  return false;
741  }
742 
743  /* This checks actual `ob->data`, for cases when other scenes have it in edit-mode context.
744  * Currently multiple objects sharing a mesh being in edit-mode at once isn't supported,
745  * see: T86767. */
746  if (BKE_object_is_in_editmode(ob)) {
747  return true;
748  }
749 
751  /* Ideally the caller should check this. */
752  CLOG_WARN(&LOG, "Unable to enter edit-mode on library data for object '%s'", ob->id.name + 2);
753  return false;
754  }
755 
756  ob->restore_mode = ob->mode;
757 
758  ob->mode = OB_MODE_EDIT;
759 
760  if (ob->type == OB_MESH) {
761  ok = true;
762 
763  const bool use_key_index = mesh_needs_keyindex(bmain, ob->data);
764 
765  EDBM_mesh_make(ob, scene->toolsettings->selectmode, use_key_index);
766 
768  if (LIKELY(em)) {
770  }
771 
773  }
774  else if (ob->type == OB_ARMATURE) {
775  bArmature *arm = ob->data;
776  ok = true;
777  ED_armature_to_edit(arm);
778  /* To ensure all goes in rest-position and without striding. */
779 
780  arm->needs_flush_to_id = 0;
781 
782  /* XXX: should this be ID_RECALC_GEOMETRY? */
784 
786  }
787  else if (ob->type == OB_FONT) {
788  ok = true;
790 
792  }
793  else if (ob->type == OB_MBALL) {
794  MetaBall *mb = ob->data;
795 
796  ok = true;
798 
799  mb->needs_flush_to_id = 0;
800 
802  }
803  else if (ob->type == OB_LATTICE) {
804  ok = true;
806 
808  }
809  else if (ELEM(ob->type, OB_SURF, OB_CURVES_LEGACY)) {
810  ok = true;
812 
814  }
815  else if (ob->type == OB_CURVES) {
816  ok = true;
818  }
819 
820  if (ok) {
822  }
823  else {
824  if ((flag & EM_NO_CONTEXT) == 0) {
825  ob->mode &= ~OB_MODE_EDIT;
826  }
828  }
829 
830  return (ob->mode & OB_MODE_EDIT) != 0;
831 }
832 
834 {
835  Main *bmain = CTX_data_main(C);
837 
838  /* Active layer checked here for view3d,
839  * callers that don't want view context can call the extended version. */
841  return ED_object_editmode_enter_ex(bmain, scene, ob, flag);
842 }
843 
845 {
846  Main *bmain = CTX_data_main(C);
848  View3D *v3d = CTX_wm_view3d(C);
849  ViewLayer *view_layer = CTX_data_view_layer(C);
850  Object *obact = OBACT(view_layer);
851  const int mode_flag = OB_MODE_EDIT;
852  const bool is_mode_set = (obact->mode & mode_flag) != 0;
853  struct wmMsgBus *mbus = CTX_wm_message_bus(C);
854 
855  if (!is_mode_set) {
856  if (!ED_object_mode_compat_set(C, obact, mode_flag, op->reports)) {
857  return OPERATOR_CANCELLED;
858  }
859  }
860 
861  if (!is_mode_set) {
862  ED_object_editmode_enter_ex(bmain, scene, obact, 0);
863  if (obact->mode & mode_flag) {
864  FOREACH_SELECTED_OBJECT_BEGIN (view_layer, v3d, ob) {
865  if ((ob != obact) && (ob->type == obact->type)) {
867  }
868  }
870  }
871  }
872  else {
874 
875  if ((obact->mode & mode_flag) == 0) {
876  FOREACH_OBJECT_BEGIN (view_layer, ob) {
877  if ((ob != obact) && (ob->type == obact->type)) {
879  }
880  }
882  }
883  }
884 
885  WM_msg_publish_rna_prop(mbus, &obact->id, obact, Object, mode);
886 
887  if (G.background == false) {
889  }
890 
891  return OPERATOR_FINISHED;
892 }
893 
895 {
897 
898  /* covers proxies too */
899  if (ELEM(NULL, ob, ob->data) || ID_IS_LINKED(ob->data) || ID_IS_OVERRIDE_LIBRARY(ob) ||
901  return false;
902  }
903 
904  /* if hidden but in edit mode, we still display */
905  if ((ob->visibility_flag & OB_HIDE_VIEWPORT) && !(ob->mode & OB_MODE_EDIT)) {
906  return false;
907  }
908 
909  return OB_TYPE_SUPPORT_EDITMODE(ob->type);
910 }
911 
913 {
914 
915  /* identifiers */
916  ot->name = "Toggle Edit Mode";
917  ot->description = "Toggle object's edit mode";
918  ot->idname = "OBJECT_OT_editmode_toggle";
919 
920  /* api callbacks */
923 
924  /* flags */
926 }
927 
930 /* -------------------------------------------------------------------- */
935 {
936  struct wmMsgBus *mbus = CTX_wm_message_bus(C);
937  struct Main *bmain = CTX_data_main(C);
939  ViewLayer *view_layer = CTX_data_view_layer(C);
940  Base *base = CTX_data_active_base(C);
941 
942  /* If the base is NULL it means we have an active object, but the object itself is hidden. */
943  if (base == NULL) {
944  return OPERATOR_CANCELLED;
945  }
946 
947  Object *obact = base->object;
948  const int mode_flag = OB_MODE_POSE;
949  bool is_mode_set = (obact->mode & mode_flag) != 0;
950 
951  if (!is_mode_set) {
952  if (!ED_object_mode_compat_set(C, obact, mode_flag, op->reports)) {
953  return OPERATOR_CANCELLED;
954  }
955  }
956 
957  if (obact->type != OB_ARMATURE) {
958  return OPERATOR_PASS_THROUGH;
959  }
960 
961  {
962  Object *obedit = OBEDIT_FROM_VIEW_LAYER(view_layer);
963  if (obact == obedit) {
965  is_mode_set = false;
966  }
967  }
968 
969  if (is_mode_set) {
970  bool ok = ED_object_posemode_exit(C, obact);
971  if (ok) {
972  FOREACH_OBJECT_BEGIN (view_layer, ob) {
973  if ((ob != obact) && (ob->type == OB_ARMATURE) && (ob->mode & mode_flag)) {
974  ED_object_posemode_exit_ex(bmain, ob);
975  }
976  }
978  }
979  }
980  else {
981  bool ok = ED_object_posemode_enter(C, obact);
982  if (ok) {
983  const View3D *v3d = CTX_wm_view3d(C);
984  FOREACH_SELECTED_OBJECT_BEGIN (view_layer, v3d, ob) {
985  if ((ob != obact) && (ob->type == OB_ARMATURE) && (ob->mode == OB_MODE_OBJECT) &&
986  BKE_id_is_editable(bmain, &ob->id)) {
987  ED_object_posemode_enter_ex(bmain, ob);
988  }
989  }
991  }
992  }
993 
994  WM_msg_publish_rna_prop(mbus, &obact->id, obact, Object, mode);
995 
996  if (G.background == false) {
998  }
999 
1000  return OPERATOR_FINISHED;
1001 }
1002 
1004 {
1005  /* identifiers */
1006  ot->name = "Toggle Pose Mode";
1007  ot->idname = "OBJECT_OT_posemode_toggle";
1008  ot->description = "Enable or disable posing/selecting bones";
1009 
1010  /* api callbacks */
1011  ot->exec = posemode_exec;
1013 
1014  /* flag */
1016 }
1017 
1020 /* -------------------------------------------------------------------- */
1025 {
1026  PartDeflect *pd = object->pd;
1028 
1029  /* add/remove modifier as needed */
1030  if (!md) {
1031  if (pd && (pd->shape == PFIELD_SHAPE_SURFACE) &&
1033  if (ELEM(object->type, OB_MESH, OB_SURF, OB_FONT, OB_CURVES_LEGACY)) {
1035  }
1036  }
1037  }
1038  else {
1039  if (!pd || (pd->shape != PFIELD_SHAPE_SURFACE) ||
1041  ED_object_modifier_remove(NULL, bmain, scene, object, md);
1042  }
1043  }
1044 }
1045 
1047 {
1049 
1050  if (ob->pd == NULL) {
1052  }
1053  else if (ob->pd->forcefield == 0) {
1054  ob->pd->forcefield = PFIELD_FORCE;
1055  }
1056  else {
1057  ob->pd->forcefield = 0;
1058  }
1059 
1063 
1065 
1066  return OPERATOR_FINISHED;
1067 }
1068 
1070 {
1071 
1072  /* identifiers */
1073  ot->name = "Toggle Force Field";
1074  ot->description = "Toggle object's force field";
1075  ot->idname = "OBJECT_OT_forcefield_toggle";
1076 
1077  /* api callbacks */
1080 
1081  /* flags */
1083 }
1084 
1087 /* -------------------------------------------------------------------- */
1092 {
1093  switch (range) {
1099  return ANIMVIZ_CALC_RANGE_FULL;
1100  }
1101  return ANIMVIZ_CALC_RANGE_FULL;
1102 }
1103 
1105 {
1106  ListBase selected_objects = {NULL, NULL};
1107  CTX_DATA_BEGIN (C, Object *, ob, selected_editable_objects) {
1108  BLI_addtail(&selected_objects, BLI_genericNodeN(ob));
1109  }
1110  CTX_DATA_END;
1111 
1112  ED_objects_recalculate_paths(C, scene, range, &selected_objects);
1113 
1114  BLI_freelistN(&selected_objects);
1115 }
1116 
1118 {
1119  ListBase visible_objects = {NULL, NULL};
1120  CTX_DATA_BEGIN (C, Object *, ob, visible_objects) {
1121  BLI_addtail(&visible_objects, BLI_genericNodeN(ob));
1122  }
1123  CTX_DATA_END;
1124 
1125  ED_objects_recalculate_paths(C, scene, range, &visible_objects);
1126 
1127  BLI_freelistN(&visible_objects);
1128 }
1129 
1131 {
1132  return (ob->avs.path_bakeflag & MOTIONPATH_BAKE_HAS_PATHS) != 0;
1133 }
1134 
1136 {
1137  return ob->pose && (ob->pose->avs.path_bakeflag & MOTIONPATH_BAKE_HAS_PATHS) != 0;
1138 }
1139 
1141  Scene *scene,
1142  eObjectPathCalcRange range,
1143  ListBase *ld_objects)
1144 {
1145  /* Transform doesn't always have context available to do update. */
1146  if (C == NULL) {
1147  return;
1148  }
1149 
1150  Main *bmain = CTX_data_main(C);
1151  ViewLayer *view_layer = CTX_data_view_layer(C);
1152 
1153  ListBase targets = {NULL, NULL};
1154  LISTBASE_FOREACH (LinkData *, link, ld_objects) {
1155  Object *ob = link->data;
1156 
1157  /* set flag to force recalc, then grab path(s) from object */
1158  if (has_object_motion_paths(ob)) {
1160  }
1161 
1162  if (has_pose_motion_paths(ob)) {
1164  }
1165 
1166  animviz_get_object_motionpaths(ob, &targets);
1167  }
1168 
1170  bool free_depsgraph = false;
1171  /* For a single frame update it's faster to re-use existing dependency graph and avoid overhead
1172  * of building all the relations and so on for a temporary one. */
1173  if (range == OBJECT_PATH_CALC_RANGE_CURRENT_FRAME) {
1174  /* NOTE: Dependency graph will be evaluated at all the frames, but we first need to access some
1175  * nested pointers, like animation data. */
1177  free_depsgraph = false;
1178  }
1179  else {
1180  depsgraph = animviz_depsgraph_build(bmain, scene, view_layer, &targets);
1181  free_depsgraph = true;
1182  }
1183 
1184  /* recalculate paths, then free */
1186  depsgraph, bmain, scene, &targets, object_path_convert_range(range), true);
1187  BLI_freelistN(&targets);
1188 
1189  if (range != OBJECT_PATH_CALC_RANGE_CURRENT_FRAME) {
1190  /* Tag objects for copy on write - so paths will draw/redraw
1191  * For currently frame only we update evaluated object directly. */
1192  LISTBASE_FOREACH (LinkData *, link, ld_objects) {
1193  Object *ob = link->data;
1194 
1197  }
1198  }
1199  }
1200 
1201  /* Free temporary depsgraph. */
1202  if (free_depsgraph) {
1204  }
1205 }
1206 
1207 /* show popup to determine settings */
1209 {
1211 
1212  if (ob == NULL) {
1213  return OPERATOR_CANCELLED;
1214  }
1215 
1216  /* set default settings from existing/stored settings */
1217  {
1218  bAnimVizSettings *avs = &ob->avs;
1219  RNA_enum_set(op->ptr, "display_type", avs->path_type);
1220  RNA_enum_set(op->ptr, "range", avs->path_range);
1221  }
1222 
1223  /* show popup dialog to allow editing of range... */
1224  /* FIXME: hard-coded dimensions here are just arbitrary. */
1225  return WM_operator_props_dialog_popup(C, op, 270);
1226 }
1227 
1228 /* Calculate/recalculate whole paths (avs.path_sf to avs.path_ef) */
1230 {
1232  short path_type = RNA_enum_get(op->ptr, "display_type");
1233  short path_range = RNA_enum_get(op->ptr, "range");
1234 
1235  /* set up path data for objects being calculated */
1236  CTX_DATA_BEGIN (C, Object *, ob, selected_editable_objects) {
1237  bAnimVizSettings *avs = &ob->avs;
1238  /* grab baking settings from operator settings */
1239  avs->path_type = path_type;
1240  avs->path_range = path_range;
1242 
1243  /* verify that the selected object has the appropriate settings */
1245  }
1246  CTX_DATA_END;
1247 
1248  /* calculate the paths for objects that have them (and are tagged to get refreshed) */
1250 
1251  /* notifiers for updates */
1253  /* NOTE: the notifier below isn't actually correct, but kept around just to be on the safe side.
1254  * If further testing shows it's not necessary (for both bones and objects) removal is fine. */
1256 
1257  return OPERATOR_FINISHED;
1258 }
1259 
1261 {
1262  /* identifiers */
1263  ot->name = "Calculate Object Motion Paths";
1264  ot->idname = "OBJECT_OT_paths_calculate";
1265  ot->description = "Generate motion paths for the selected objects";
1266 
1267  /* api callbacks */
1271 
1272  /* flags */
1274 
1275  /* properties */
1276  RNA_def_enum(ot->srna,
1277  "display_type",
1280  "Display type",
1281  "");
1282  RNA_def_enum(ot->srna,
1283  "range",
1286  "Computation Range",
1287  "");
1288 }
1289 
1292 /* -------------------------------------------------------------------- */
1297 {
1300  return (ob->avs.path_bakeflag & MOTIONPATH_BAKE_HAS_PATHS) != 0;
1301  }
1302 
1303  return false;
1304 }
1305 
1307 {
1309 
1310  if (scene == NULL) {
1311  return OPERATOR_CANCELLED;
1312  }
1313  CTX_DATA_BEGIN (C, Object *, ob, selected_editable_objects) {
1315  /* verify that the selected object has the appropriate settings */
1317  }
1318  CTX_DATA_END;
1319 
1320  /* calculate the paths for objects that have them (and are tagged to get refreshed) */
1322 
1323  /* notifiers for updates */
1325  /* NOTE: the notifier below isn't actually correct, but kept around just to be on the safe side.
1326  * If further testing shows it's not necessary (for both bones and objects) removal is fine. */
1328 
1329  return OPERATOR_FINISHED;
1330 }
1331 
1333 {
1334  /* identifiers */
1335  ot->name = "Update Object Paths";
1336  ot->idname = "OBJECT_OT_paths_update";
1337  ot->description = "Recalculate motion paths for selected objects";
1338 
1339  /* api callbacks */
1342 
1343  /* flags */
1345 }
1346 
1349 /* -------------------------------------------------------------------- */
1354 {
1355  return true;
1356 }
1357 
1359 {
1361 
1362  if (scene == NULL) {
1363  return OPERATOR_CANCELLED;
1364  }
1365 
1367 
1369 
1370  return OPERATOR_FINISHED;
1371 }
1372 
1374 {
1375  /* identifiers */
1376  ot->name = "Update All Object Paths";
1377  ot->idname = "OBJECT_OT_paths_update_visible";
1378  ot->description = "Recalculate all visible motion paths for objects and poses";
1379 
1380  /* api callbacks */
1383 
1384  /* flags */
1386 }
1387 
1390 /* -------------------------------------------------------------------- */
1394 /* Helper for ED_objects_clear_paths() */
1395 static void object_clear_mpath(Object *ob)
1396 {
1397  if (ob->mpath) {
1399  ob->mpath = NULL;
1401 
1402  /* tag object for copy on write - so removed paths don't still show */
1404  }
1405 }
1406 
1407 void ED_objects_clear_paths(bContext *C, bool only_selected)
1408 {
1409  if (only_selected) {
1410  /* Loop over all selected + editable objects in scene. */
1411  CTX_DATA_BEGIN (C, Object *, ob, selected_editable_objects) {
1412  object_clear_mpath(ob);
1413  }
1414  CTX_DATA_END;
1415  }
1416  else {
1417  /* Loop over all editable objects in scene. */
1418  CTX_DATA_BEGIN (C, Object *, ob, editable_objects) {
1419  object_clear_mpath(ob);
1420  }
1421  CTX_DATA_END;
1422  }
1423 }
1424 
1425 /* operator callback for this */
1427 {
1428  bool only_selected = RNA_boolean_get(op->ptr, "only_selected");
1429 
1430  /* use the backend function for this */
1431  ED_objects_clear_paths(C, only_selected);
1432 
1433  /* notifiers for updates */
1435 
1436  return OPERATOR_FINISHED;
1437 }
1438 
1439 /* operator callback/wrapper */
1440 static int object_clear_paths_invoke(bContext *C, wmOperator *op, const wmEvent *event)
1441 {
1442  if ((event->modifier & KM_SHIFT) && !RNA_struct_property_is_set(op->ptr, "only_selected")) {
1443  RNA_boolean_set(op->ptr, "only_selected", true);
1444  }
1445  return object_clear_paths_exec(C, op);
1446 }
1447 
1449 {
1450  /* identifiers */
1451  ot->name = "Clear Object Paths";
1452  ot->idname = "OBJECT_OT_paths_clear";
1453  ot->description = "Clear path caches for all objects, hold Shift key for selected objects only";
1454 
1455  /* api callbacks */
1459 
1460  /* flags */
1462 
1463  /* properties */
1464  ot->prop = RNA_def_boolean(
1465  ot->srna, "only_selected", false, "Only Selected", "Only clear paths from selected objects");
1467 }
1468 
1471 /* -------------------------------------------------------------------- */
1476 {
1477  const bool use_smooth = STREQ(op->idname, "OBJECT_OT_shade_smooth");
1478  bool changed_multi = false;
1479  bool has_linked_data = false;
1480 
1481  ListBase ctx_objects = {NULL, NULL};
1482  CollectionPointerLink ctx_ob_single_active = {NULL};
1483 
1484  /* For modes that only use an active object, don't handle the whole selection. */
1485  {
1486  ViewLayer *view_layer = CTX_data_view_layer(C);
1487  Object *obact = OBACT(view_layer);
1488  if (obact && ((obact->mode & OB_MODE_ALL_PAINT))) {
1489  ctx_ob_single_active.ptr.data = obact;
1490  BLI_addtail(&ctx_objects, &ctx_ob_single_active);
1491  }
1492  }
1493 
1494  if (ctx_objects.first != &ctx_ob_single_active) {
1495  CTX_data_selected_editable_objects(C, &ctx_objects);
1496  }
1497 
1498  LISTBASE_FOREACH (CollectionPointerLink *, ctx_ob, &ctx_objects) {
1499  Object *ob = ctx_ob->ptr.data;
1500  ID *data = ob->data;
1501  if (data != NULL) {
1502  data->tag |= LIB_TAG_DOIT;
1503  }
1504  }
1505 
1506  Main *bmain = CTX_data_main(C);
1507  LISTBASE_FOREACH (CollectionPointerLink *, ctx_ob, &ctx_objects) {
1508  /* Always un-tag all object data-blocks irrespective of our ability to operate on them. */
1509  Object *ob = ctx_ob->ptr.data;
1510  ID *data = ob->data;
1511  if ((data == NULL) || ((data->tag & LIB_TAG_DOIT) == 0)) {
1512  continue;
1513  }
1514  data->tag &= ~LIB_TAG_DOIT;
1515  /* Finished un-tagging, continue with regular logic. */
1516 
1517  if (data && !BKE_id_is_editable(bmain, data)) {
1518  has_linked_data = true;
1519  continue;
1520  }
1521 
1522  bool changed = false;
1523  if (ob->type == OB_MESH) {
1524  BKE_mesh_smooth_flag_set(ob->data, use_smooth);
1525  if (use_smooth) {
1526  const bool use_auto_smooth = RNA_boolean_get(op->ptr, "use_auto_smooth");
1527  const float auto_smooth_angle = RNA_float_get(op->ptr, "auto_smooth_angle");
1528  BKE_mesh_auto_smooth_flag_set(ob->data, use_auto_smooth, auto_smooth_angle);
1529  }
1531  changed = true;
1532  }
1533  else if (ELEM(ob->type, OB_SURF, OB_CURVES_LEGACY)) {
1534  BKE_curve_smooth_flag_set(ob->data, use_smooth);
1535  changed = true;
1536  }
1537 
1538  if (changed) {
1539  changed_multi = true;
1540 
1543  }
1544  }
1545 
1546  if (ctx_objects.first != &ctx_ob_single_active) {
1547  BLI_freelistN(&ctx_objects);
1548  }
1549 
1550  if (has_linked_data) {
1551  BKE_report(op->reports, RPT_WARNING, "Can't edit linked mesh or curve data");
1552  }
1553 
1554  return (changed_multi) ? OPERATOR_FINISHED : OPERATOR_CANCELLED;
1555 }
1556 
1557 static bool shade_poll(bContext *C)
1558 {
1559  ViewLayer *view_layer = CTX_data_view_layer(C);
1560  Object *obact = OBACT(view_layer);
1561  if (obact != NULL) {
1562  /* Doesn't handle edit-data, sculpt dynamic-topology, or their undo systems. */
1563  if (obact->mode & (OB_MODE_EDIT | OB_MODE_SCULPT) || obact->data == NULL ||
1565  return false;
1566  }
1567  }
1568  return true;
1569 }
1570 
1572 {
1573  /* identifiers */
1574  ot->name = "Shade Flat";
1575  ot->description = "Render and display faces uniform, using Face Normals";
1576  ot->idname = "OBJECT_OT_shade_flat";
1577 
1578  /* api callbacks */
1579  ot->poll = shade_poll;
1581 
1582  /* flags */
1584 }
1585 
1587 {
1588  /* identifiers */
1589  ot->name = "Shade Smooth";
1590  ot->description = "Render and display faces smooth, using interpolated Vertex Normals";
1591  ot->idname = "OBJECT_OT_shade_smooth";
1592 
1593  /* api callbacks */
1594  ot->poll = shade_poll;
1596 
1597  /* flags */
1599 
1600  /* properties */
1601  PropertyRNA *prop;
1602 
1603  prop = RNA_def_boolean(
1604  ot->srna,
1605  "use_auto_smooth",
1606  false,
1607  "Auto Smooth",
1608  "Enable automatic smooth based on smooth/sharp faces/edges and angle between faces");
1610 
1611  prop = RNA_def_property(ot->srna, "auto_smooth_angle", PROP_FLOAT, PROP_ANGLE);
1612  RNA_def_property_range(prop, 0.0f, DEG2RADF(180.0f));
1615  "Angle",
1616  "Maximum angle between face normals that will be considered as smooth"
1617  "(unused if custom split normals data are available)");
1618 }
1619 
1622 /* -------------------------------------------------------------------- */
1627  PointerRNA *UNUSED(ptr),
1628  PropertyRNA *UNUSED(prop),
1629  bool *r_free)
1630 {
1632  EnumPropertyItem *item = NULL;
1633  int totitem = 0;
1634 
1635  if (!C) { /* needed for docs */
1637  }
1638 
1639  const Object *ob = CTX_data_active_object(C);
1640  if (ob) {
1641  while (input->identifier) {
1642  if (ED_object_mode_compat_test(ob, input->value)) {
1643  RNA_enum_item_add(&item, &totitem, input);
1644  }
1645  input++;
1646  }
1647  }
1648  else {
1649  /* We need at least this one! */
1650  RNA_enum_items_add_value(&item, &totitem, input, OB_MODE_OBJECT);
1651  }
1652 
1653  RNA_enum_item_end(&item, &totitem);
1654 
1655  *r_free = true;
1656 
1657  return item;
1658 }
1659 
1661 {
1662  /* Needed as #ED_operator_object_active_editable doesn't call use 'active_object'. */
1665 }
1666 
1668 {
1669  const bool use_submode = STREQ(op->idname, "OBJECT_OT_mode_set_with_submode");
1671  eObjectMode mode = RNA_enum_get(op->ptr, "mode");
1672  const bool toggle = RNA_boolean_get(op->ptr, "toggle");
1673 
1674  /* by default the operator assume is a mesh, but if gp object change mode */
1675  if ((ob->type == OB_GPENCIL) && (mode == OB_MODE_EDIT)) {
1676  mode = OB_MODE_EDIT_GPENCIL;
1677  }
1678 
1679  if (!ED_object_mode_compat_test(ob, mode)) {
1680  return OPERATOR_PASS_THROUGH;
1681  }
1682 
1701  if (toggle == false) {
1702  if (ob->mode != mode) {
1703  ED_object_mode_set_ex(C, mode, true, op->reports);
1704  }
1705  }
1706  else {
1707  const eObjectMode mode_prev = ob->mode;
1708  /* When toggling object mode, we always use the restore mode,
1709  * otherwise there is nothing to do. */
1710  if (mode == OB_MODE_OBJECT) {
1711  if (ob->mode != OB_MODE_OBJECT) {
1712  if (ED_object_mode_set_ex(C, OB_MODE_OBJECT, true, op->reports)) {
1713  /* Store old mode so we know what to go back to. */
1714  ob->restore_mode = mode_prev;
1715  }
1716  }
1717  else {
1718  if (ob->restore_mode != OB_MODE_OBJECT) {
1719  ED_object_mode_set_ex(C, ob->restore_mode, true, op->reports);
1720  }
1721  }
1722  }
1723  else {
1724  /* Non-object modes, enter the 'mode' unless it's already set,
1725  * in that case use restore mode. */
1726  if (ob->mode != mode) {
1727  if (ED_object_mode_set_ex(C, mode, true, op->reports)) {
1728  /* Store old mode so we know what to go back to. */
1729  ob->restore_mode = mode_prev;
1730  }
1731  }
1732  else {
1733  if (ob->restore_mode != OB_MODE_OBJECT) {
1734  ED_object_mode_set_ex(C, ob->restore_mode, true, op->reports);
1735  }
1736  else {
1738  }
1739  }
1740  }
1741  }
1742 
1743  if (use_submode) {
1744  if (ob->type == OB_MESH) {
1745  if (ob->mode & OB_MODE_EDIT) {
1746  PropertyRNA *prop = RNA_struct_find_property(op->ptr, "mesh_select_mode");
1747  if (RNA_property_is_set(op->ptr, prop)) {
1748  int mesh_select_mode = RNA_property_enum_get(op->ptr, prop);
1749  if (mesh_select_mode != 0) {
1750  EDBM_selectmode_set_multi(C, mesh_select_mode);
1751  }
1752  }
1753  }
1754  }
1755  }
1756 
1757  return OPERATOR_FINISHED;
1758 }
1759 
1761 {
1762  PropertyRNA *prop;
1763 
1764  /* identifiers */
1765  ot->name = "Set Object Mode";
1766  ot->description = "Sets the object interaction mode";
1767  ot->idname = "OBJECT_OT_mode_set";
1768 
1769  /* api callbacks */
1772 
1773  /* flags */
1774  ot->flag = 0; /* no register/undo here, leave it to operators being called */
1775 
1776  ot->prop = RNA_def_enum(
1777  ot->srna, "mode", rna_enum_object_mode_items, OB_MODE_OBJECT, "Mode", "");
1780 
1781  prop = RNA_def_boolean(ot->srna, "toggle", 0, "Toggle", "");
1783 }
1784 
1786 {
1788 
1789  /* identifiers */
1790  ot->name = "Set Object Mode with Sub-mode";
1791  ot->idname = "OBJECT_OT_mode_set_with_submode";
1792 
1793  /* properties */
1794  /* we could add other types - particle for eg. */
1795  PropertyRNA *prop;
1796  prop = RNA_def_enum_flag(
1797  ot->srna, "mesh_select_mode", rna_enum_mesh_select_mode_items, 0, "Mesh Mode", "");
1799 }
1800 
1803 /* -------------------------------------------------------------------- */
1808 {
1809  ListBase objects = {NULL};
1810 
1811  if (CTX_wm_space_outliner(C) != NULL) {
1813  }
1814  else {
1815  CTX_DATA_BEGIN (C, Object *, ob, selected_objects) {
1817  }
1818  CTX_DATA_END;
1819  }
1820 
1821  return objects;
1822 }
1823 
1825 {
1826  if (CTX_wm_space_outliner(C) != NULL) {
1828  }
1829  return ED_operator_objectmode(C);
1830 }
1831 
1833 {
1834  Main *bmain = CTX_data_main(C);
1836  PropertyRNA *prop = RNA_struct_find_property(op->ptr, "collection_index");
1837  const bool is_link = STREQ(op->idname, "OBJECT_OT_link_to_collection");
1838  const bool is_new = RNA_boolean_get(op->ptr, "is_new");
1839 
1840  if (!RNA_property_is_set(op->ptr, prop)) {
1841  BKE_report(op->reports, RPT_ERROR, "No collection selected");
1842  return OPERATOR_CANCELLED;
1843  }
1844 
1845  int collection_index = RNA_property_int_get(op->ptr, prop);
1846  Collection *collection = BKE_collection_from_index(scene, collection_index);
1847  if (collection == NULL) {
1848  BKE_report(op->reports, RPT_ERROR, "Unexpected error, collection not found");
1849  return OPERATOR_CANCELLED;
1850  }
1851 
1852  if (ID_IS_LINKED(collection) || ID_IS_OVERRIDE_LIBRARY(collection)) {
1853  BKE_report(
1854  op->reports, RPT_ERROR, "Cannot add objects to a library override or linked collection");
1855  return OPERATOR_CANCELLED;
1856  }
1857 
1859 
1860  if (is_new) {
1861  char new_collection_name[MAX_NAME];
1862  RNA_string_get(op->ptr, "new_collection_name", new_collection_name);
1863  collection = BKE_collection_add(bmain, collection, new_collection_name);
1864  }
1865 
1866  Object *single_object = BLI_listbase_is_single(&objects) ? ((LinkData *)objects.first)->data :
1867  NULL;
1868 
1869  if ((single_object != NULL) && is_link &&
1870  BLI_findptr(&collection->gobject, single_object, offsetof(CollectionObject, ob))) {
1871  BKE_reportf(op->reports,
1872  RPT_ERROR,
1873  "%s already in %s",
1874  single_object->id.name + 2,
1875  collection->id.name + 2);
1877  return OPERATOR_CANCELLED;
1878  }
1879 
1880  LISTBASE_FOREACH (LinkData *, link, &objects) {
1881  Object *ob = link->data;
1882 
1883  if (!is_link) {
1884  BKE_collection_object_move(bmain, scene, collection, NULL, ob);
1885  }
1886  else {
1887  BKE_collection_object_add(bmain, collection, ob);
1888  }
1889  }
1891 
1892  BKE_reportf(op->reports,
1893  RPT_INFO,
1894  "%s %s to %s",
1895  (single_object != NULL) ? single_object->id.name + 2 : "Objects",
1896  is_link ? "linked" : "moved",
1897  collection->id.name + 2);
1898 
1899  DEG_relations_tag_update(bmain);
1901 
1905 
1906  return OPERATOR_FINISHED;
1907 }
1908 
1911  int index;
1913  struct ListBase submenus;
1916 };
1917 
1919 {
1920  int index = menu->index;
1921  LISTBASE_FOREACH (CollectionChild *, child, &menu->collection->children) {
1922  Collection *collection = child->collection;
1923  MoveToCollectionData *submenu = MEM_callocN(sizeof(MoveToCollectionData), __func__);
1924  BLI_addtail(&menu->submenus, submenu);
1925  submenu->collection = collection;
1926  submenu->index = ++index;
1927  index = move_to_collection_menus_create(op, submenu);
1928  submenu->ot = op->type;
1929  }
1930  return index;
1931 }
1932 
1934 {
1935  LISTBASE_FOREACH (MoveToCollectionData *, submenu, &menu->submenus) {
1937  }
1938  BLI_freelistN(&menu->submenus);
1939 }
1940 
1942 {
1943  if (*menu == NULL) {
1944  return;
1945  }
1946 
1948  MEM_freeN(*menu);
1949  *menu = NULL;
1950 }
1951 
1952 static void move_to_collection_menu_create(bContext *C, uiLayout *layout, void *menu_v)
1953 {
1954  MoveToCollectionData *menu = menu_v;
1955  const char *name = BKE_collection_ui_name_get(menu->collection);
1956 
1958 
1959  WM_operator_properties_create_ptr(&menu->ptr, menu->ot);
1960  RNA_int_set(&menu->ptr, "collection_index", menu->index);
1961  RNA_boolean_set(&menu->ptr, "is_new", true);
1962 
1963  uiItemFullO_ptr(layout,
1964  menu->ot,
1965  CTX_IFACE_(BLT_I18NCONTEXT_OPERATOR_DEFAULT, "New Collection"),
1966  ICON_ADD,
1967  menu->ptr.data,
1969  0,
1970  NULL);
1971 
1972  uiItemS(layout);
1973 
1975  const int icon = (menu->collection == scene->master_collection) ?
1976  ICON_SCENE_DATA :
1978  uiItemIntO(layout, name, icon, menu->ot->idname, "collection_index", menu->index);
1979 
1980  LISTBASE_FOREACH (MoveToCollectionData *, submenu, &menu->submenus) {
1981  move_to_collection_menus_items(layout, submenu);
1982  }
1983 }
1984 
1986 {
1987  const int icon = UI_icon_color_from_collection(menu->collection);
1988 
1989  if (BLI_listbase_is_empty(&menu->submenus)) {
1990  uiItemIntO(layout,
1991  menu->collection->id.name + 2,
1992  icon,
1993  menu->ot->idname,
1994  "collection_index",
1995  menu->index);
1996  }
1997  else {
1998  uiItemMenuF(layout, menu->collection->id.name + 2, icon, move_to_collection_menu_create, menu);
1999  }
2000 }
2001 
2002 /* This is allocated statically because we need this available for the menus creation callback. */
2004 
2006 {
2008 
2009  ListBase objects = selected_objects_get(C);
2010  if (BLI_listbase_is_empty(&objects)) {
2011  BKE_report(op->reports, RPT_ERROR, "No objects selected");
2012  return OPERATOR_CANCELLED;
2013  }
2014  BLI_freelistN(&objects);
2015 
2016  /* Reset the menus data for the current master collection, and free previously allocated data. */
2018 
2019  PropertyRNA *prop;
2020  prop = RNA_struct_find_property(op->ptr, "collection_index");
2021  if (RNA_property_is_set(op->ptr, prop)) {
2022  int collection_index = RNA_property_int_get(op->ptr, prop);
2023 
2024  if (RNA_boolean_get(op->ptr, "is_new")) {
2025  prop = RNA_struct_find_property(op->ptr, "new_collection_name");
2026  if (!RNA_property_is_set(op->ptr, prop)) {
2027  char name[MAX_NAME];
2028  Collection *collection;
2029 
2030  collection = BKE_collection_from_index(scene, collection_index);
2031  BKE_collection_new_name_get(collection, name);
2032 
2034  return WM_operator_props_dialog_popup(C, op, 200);
2035  }
2036  }
2037  return move_to_collection_exec(C, op);
2038  }
2039 
2040  Collection *master_collection = scene->master_collection;
2041 
2042  /* We need the data to be allocated so it's available during menu drawing.
2043  * Technically we could use #wmOperator.customdata. However there is no free callback
2044  * called to an operator that exit with OPERATOR_INTERFACE to launch a menu.
2045  *
2046  * So we are left with a memory that will necessarily leak. It's a small leak though. */
2047  if (master_collection_menu == NULL) {
2049  "MoveToCollectionData menu - expected eventual memleak");
2050  }
2051 
2052  master_collection_menu->collection = master_collection;
2055 
2056  uiPopupMenu *pup;
2057  uiLayout *layout;
2058 
2059  /* Build the menus. */
2060  const char *title = CTX_IFACE_(op->type->translation_context, op->type->name);
2061  pup = UI_popup_menu_begin(C, title, ICON_NONE);
2062  layout = UI_popup_menu_layout(pup);
2063 
2065 
2067 
2068  UI_popup_menu_end(C, pup);
2069 
2070  return OPERATOR_INTERFACE;
2071 }
2072 
2074 {
2075  PropertyRNA *prop;
2076 
2077  /* identifiers */
2078  ot->name = "Move to Collection";
2079  ot->description = "Move objects to a collection";
2080  ot->idname = "OBJECT_OT_move_to_collection";
2081 
2082  /* api callbacks */
2086 
2087  /* flags */
2089 
2090  prop = RNA_def_int(ot->srna,
2091  "collection_index",
2094  INT_MAX,
2095  "Collection Index",
2096  "Index of the collection to move to",
2097  0,
2098  INT_MAX);
2100  prop = RNA_def_boolean(ot->srna, "is_new", false, "New", "Move objects to a new collection");
2103  "new_collection_name",
2104  NULL,
2105  MAX_NAME,
2106  "Name",
2107  "Name of the newly added collection");
2109  ot->prop = prop;
2110 }
2111 
2113 {
2114  PropertyRNA *prop;
2115 
2116  /* identifiers */
2117  ot->name = "Link to Collection";
2118  ot->description = "Link objects to a collection";
2119  ot->idname = "OBJECT_OT_link_to_collection";
2120 
2121  /* api callbacks */
2125 
2126  /* flags */
2128 
2129  prop = RNA_def_int(ot->srna,
2130  "collection_index",
2133  INT_MAX,
2134  "Collection Index",
2135  "Index of the collection to move to",
2136  0,
2137  INT_MAX);
2139  prop = RNA_def_boolean(ot->srna, "is_new", false, "New", "Move objects to a new collection");
2142  "new_collection_name",
2143  NULL,
2144  MAX_NAME,
2145  "Name",
2146  "Name of the newly added collection");
2148  ot->prop = prop;
2149 }
2150 
void animviz_free_motionpath(struct bMotionPath *mpath)
struct bMotionPath * animviz_verify_motionpaths(struct ReportList *reports, struct Scene *scene, struct Object *ob, struct bPoseChannel *pchan)
void BKE_pose_channels_clear_with_null_bone(struct bPose *pose, bool do_id_user)
Definition: armature.c:2351
struct Collection * BKE_collection_add(struct Main *bmain, struct Collection *parent, const char *name)
Definition: collection.c:425
const char * BKE_collection_ui_name_get(struct Collection *collection)
Definition: collection.c:736
bool BKE_collection_object_add(struct Main *bmain, struct Collection *collection, struct Object *ob)
Definition: collection.c:1125
void BKE_collection_new_name_get(struct Collection *collection_parent, char *rname)
Definition: collection.c:713
void BKE_collection_object_move(struct Main *bmain, struct Scene *scene, struct Collection *collection_dst, struct Collection *collection_src, struct Object *ob)
Definition: collection.c:1361
struct Collection * BKE_collection_from_index(struct Scene *scene, int index)
Definition: collection.c:1716
struct ScrArea * CTX_wm_area(const bContext *C)
Definition: context.c:738
struct Scene * CTX_data_scene(const bContext *C)
Definition: context.c:1090
struct Object * CTX_data_edit_object(const bContext *C)
Definition: context.c:1370
struct Base * CTX_data_active_base(const bContext *C)
Definition: context.c:1358
struct SpaceOutliner * CTX_wm_space_outliner(const bContext *C)
Definition: context.c:860
#define CTX_DATA_BEGIN(C, Type, instance, member)
Definition: BKE_context.h:269
PointerRNA CTX_data_pointer_get_type(const bContext *C, const char *member, StructRNA *type)
Definition: context.c:473
struct ViewLayer * CTX_data_view_layer(const bContext *C)
Definition: context.c:1100
struct Depsgraph * CTX_data_ensure_evaluated_depsgraph(const bContext *C)
Definition: context.c:1528
struct Object * CTX_data_active_object(const bContext *C)
Definition: context.c:1353
struct View3D * CTX_wm_view3d(const bContext *C)
Definition: context.c:784
struct wmMsgBus * CTX_wm_message_bus(const bContext *C)
Definition: context.c:770
int CTX_data_selected_editable_objects(const bContext *C, ListBase *list)
Definition: context.c:1303
struct Main * CTX_data_main(const bContext *C)
Definition: context.c:1074
#define CTX_DATA_END
Definition: BKE_context.h:278
void BKE_curve_smooth_flag_set(struct Curve *cu, bool use_smooth)
Definition: curve.cc:5440
void BKE_editlattice_load(struct Object *obedit)
Definition: editlattice.c:70
void BKE_editlattice_make(struct Object *obedit)
Definition: editlattice.c:44
void BKE_editlattice_free(struct Object *ob)
Definition: editlattice.c:24
void BKE_editmesh_looptri_and_normals_calc(BMEditMesh *em)
Definition: editmesh.c:135
BMEditMesh * BKE_editmesh_from_object(struct Object *ob)
Return the BMEditMesh for a given object.
Definition: editmesh.c:58
struct PartDeflect * BKE_partdeflect_new(int type)
Definition: effect.c:71
#define FOREACH_SELECTED_OBJECT_BEGIN(_view_layer, _v3d, _instance)
Definition: BKE_layer.h:303
#define BKE_view_layer_array_selected_objects(view_layer, v3d, r_len,...)
Definition: BKE_layer.h:499
void BKE_layer_collection_local_sync(struct ViewLayer *view_layer, const struct View3D *v3d)
#define FOREACH_OBJECT_END
Definition: BKE_layer.h:430
bool BKE_layer_collection_has_selected_objects(struct ViewLayer *view_layer, struct LayerCollection *lc)
Definition: layer.c:1445
void BKE_layer_collection_isolate_global(struct Scene *scene, struct ViewLayer *view_layer, struct LayerCollection *lc, bool extend)
Definition: layer.c:1585
struct LayerCollection * BKE_layer_collection_from_index(struct ViewLayer *view_layer, int index)
Definition: layer.c:630
#define FOREACH_OBJECT_BEGIN(view_layer, _instance)
Definition: BKE_layer.h:423
int BKE_layer_collection_findindex(struct ViewLayer *view_layer, const struct LayerCollection *lc)
void BKE_layer_collection_sync(const struct Scene *scene, struct ViewLayer *view_layer)
#define FOREACH_SELECTED_OBJECT_END
Definition: BKE_layer.h:315
#define BKE_view_layer_array_from_objects_in_mode(view_layer, v3d, r_len,...)
Definition: BKE_layer.h:523
void BKE_layer_collection_isolate_local(struct ViewLayer *view_layer, const struct View3D *v3d, struct LayerCollection *lc, bool extend)
bool BKE_id_is_editable(const struct Main *bmain, const struct ID *id)
General operations, lookup, etc. for materials.
void BKE_mesh_smooth_flag_set(struct Mesh *me, bool use_smooth)
Definition: mesh.cc:1486
void BKE_mesh_batch_cache_dirty_tag(struct Mesh *me, eMeshBatchDirtyMode mode)
void BKE_mesh_auto_smooth_flag_set(struct Mesh *me, bool use_auto_smooth, float auto_smooth_angle)
Definition: mesh.cc:1500
@ BKE_MESH_BATCH_DIRTY_ALL
struct ModifierData * BKE_modifiers_findby_type(const struct Object *ob, ModifierType type)
General operations, lookup, etc. for blender objects.
bool BKE_object_obdata_is_libdata(const struct Object *ob)
char * BKE_object_data_editmode_flush_ptr_get(struct ID *id)
Definition: object.cc:1941
bool BKE_object_is_in_editmode(const struct Object *ob)
void BKE_particlesystem_reset_all(struct Object *object)
void BKE_ptcache_ids_from_object(struct ListBase *lb, struct Object *ob, struct Scene *scene, int duplis)
Definition: pointcache.c:1250
#define PTCACHE_TYPE_PARTICLES
#define PTCACHE_RESET_OUTDATED
int BKE_ptcache_object_reset(struct Scene *scene, struct Object *ob, int mode)
Definition: pointcache.c:2930
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.c:83
void BKE_scene_object_base_flag_sync_from_base(struct Base *base)
Definition: scene.cc:2896
#define BLI_assert(a)
Definition: BLI_assert.h:46
BLI_INLINE bool BLI_listbase_is_empty(const struct ListBase *lb)
Definition: BLI_listbase.h:269
#define LISTBASE_FOREACH(type, var, list)
Definition: BLI_listbase.h:336
struct LinkData * BLI_genericNodeN(void *data)
Definition: listbase.c:842
void void BLI_freelistN(struct ListBase *listbase) ATTR_NONNULL(1)
Definition: listbase.c:466
void void BLI_INLINE bool BLI_listbase_is_single(const struct ListBase *lb)
Definition: BLI_listbase.h:265
void BLI_addtail(struct ListBase *listbase, void *vlink) ATTR_NONNULL(1)
Definition: listbase.c:80
void * BLI_findptr(const struct ListBase *listbase, const void *ptr, int offset) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
#define DEG2RADF(_deg)
unsigned int uint
Definition: BLI_sys_types.h:67
#define UNUSED(x)
#define UNLIKELY(x)
#define ELEM(...)
#define STREQ(a, b)
#define LIKELY(x)
#define CTX_IFACE_(context, msgid)
#define BLT_I18NCONTEXT_OPERATOR_DEFAULT
#define CLOG_WARN(clg_ref,...)
Definition: CLG_log.h:189
struct Depsgraph Depsgraph
Definition: DEG_depsgraph.h:35
void DEG_graph_free(Depsgraph *graph)
Definition: depsgraph.cc:295
void DEG_id_tag_update(struct ID *id, int flag)
void DEG_relations_tag_update(struct Main *bmain)
@ ID_RECALC_TRANSFORM
Definition: DNA_ID.h:771
@ ID_RECALC_COPY_ON_WRITE
Definition: DNA_ID.h:834
@ ID_RECALC_SELECT
Definition: DNA_ID.h:818
@ ID_RECALC_ANIMATION
Definition: DNA_ID.h:794
@ ID_RECALC_GEOMETRY
Definition: DNA_ID.h:791
@ ID_RECALC_BASE_FLAGS
Definition: DNA_ID.h:821
#define ID_IS_LINKED(_id)
Definition: DNA_ID.h:566
@ LIB_TAG_DOIT
Definition: DNA_ID.h:707
#define ID_IS_OVERRIDE_LIBRARY(_id)
Definition: DNA_ID.h:588
@ ID_OB
Definition: DNA_ID_enums.h:47
@ MOTIONPATH_BAKE_HAS_PATHS
@ MOTIONPATH_TYPE_RANGE
@ MOTIONPATH_RANGE_SCENE
@ ANIMVIZ_RECALC_PATHS
Object groups, one object can be in many groups at once.
@ COLLECTION_HIDE_VIEWPORT
#define MAX_NAME
Definition: DNA_defs.h:48
@ LAYER_COLLECTION_EXCLUDE
@ BASE_HIDDEN
@ BASE_VISIBLE_VIEWLAYER
@ BASE_SELECTED
@ LAYER_COLLECTION_HIDE_VIEWPORT
@ LAYER_COLLECTION_HAS_OBJECTS
#define MESH_MAX_VERTS
@ eModifierType_Surface
@ eModifierType_Hook
#define OB_MODE_ALL_PAINT
#define OB_MODE_ALL_PAINT_GPENCIL
eObjectMode
@ OB_MODE_EDIT_GPENCIL
@ OB_MODE_EDIT
@ OB_MODE_SCULPT
@ OB_MODE_POSE
@ OB_MODE_OBJECT
#define OB_MODE_ALL_SCULPT
#define PFIELD_SHAPE_SURFACE
@ PFIELD_FORCE
@ PFIELD_GUIDE
@ PFIELD_TEXTURE
Object is a sort of wrapper for general info.
@ OB_HIDE_VIEWPORT
@ OB_LATTICE
@ OB_MBALL
@ OB_SURF
@ OB_FONT
@ OB_ARMATURE
@ OB_MESH
@ OB_CURVES_LEGACY
@ OB_CURVES
@ OB_GPENCIL
@ PARVERT1
@ PARVERT3
#define OB_TYPE_SUPPORT_EDITMODE(_type)
@ PTCACHE_OUTDATED
#define OBEDIT_FROM_VIEW_LAYER(view_layer)
#define OBACT(_view_layer)
@ SPACE_PROPERTIES
@ SPACE_EMPTY
@ SPACE_VIEW3D
#define V3D_LOCAL_COLLECTIONS
@ OPERATOR_CANCELLED
@ OPERATOR_INTERFACE
@ OPERATOR_FINISHED
@ OPERATOR_PASS_THROUGH
eAnimvizCalcRange
Definition: ED_anim_api.h:1088
@ ANIMVIZ_CALC_RANGE_FULL
Definition: ED_anim_api.h:1096
@ ANIMVIZ_CALC_RANGE_CURRENT_FRAME
Definition: ED_anim_api.h:1090
@ ANIMVIZ_CALC_RANGE_CHANGED
Definition: ED_anim_api.h:1093
void ED_mball_editmball_free(struct Object *obedit)
Definition: mball_edit.c:51
void ED_mball_editmball_make(struct Object *obedit)
Definition: mball_edit.c:59
void ED_mball_editmball_load(struct Object *obedit)
void ED_mesh_mirror_topo_table_end(struct Object *ob)
void EDBM_mesh_load_ex(struct Main *bmain, struct Object *ob, bool free_data)
void EDBM_mesh_free_data(struct BMEditMesh *em)
void ED_mesh_mirror_spatial_table_end(struct Object *ob)
bool EDBM_selectmode_set_multi(struct bContext *C, short selectmode)
void EDBM_mesh_make(struct Object *ob, int select_mode, bool add_key_index)
struct ModifierData * ED_object_modifier_add(struct ReportList *reports, struct Main *bmain, struct Scene *scene, struct Object *ob, const char *name, int type)
@ EM_NO_CONTEXT
Definition: ED_object.h:243
@ EM_FREEDATA
Definition: ED_object.h:242
bool ED_object_mode_set_ex(struct bContext *C, eObjectMode mode, bool use_undo, struct ReportList *reports)
Definition: object_modes.c:191
bool ED_object_mode_compat_test(const struct Object *ob, eObjectMode mode)
void ED_object_base_select(struct Base *base, eObjectSelect_Mode mode)
Definition: object_select.c:76
bool ED_object_modifier_remove(struct ReportList *reports, struct Main *bmain, struct Scene *scene, struct Object *ob, struct ModifierData *md)
eObjectPathCalcRange
Definition: ED_object.h:396
@ OBJECT_PATH_CALC_RANGE_CHANGED
Definition: ED_object.h:398
@ OBJECT_PATH_CALC_RANGE_CURRENT_FRAME
Definition: ED_object.h:397
@ OBJECT_PATH_CALC_RANGE_FULL
Definition: ED_object.h:399
@ BA_DESELECT
Definition: ED_object.h:154
bool ED_object_mode_compat_set(struct bContext *C, struct Object *ob, eObjectMode mode, struct ReportList *reports)
Definition: object_modes.c:161
bool ED_outliner_collections_editor_poll(struct bContext *C)
void ED_outliner_selected_objects_get(const struct bContext *C, struct ListBase *objects)
bool ED_operator_object_active_editable_ex(struct bContext *C, const Object *ob)
Definition: screen_ops.c:376
bool ED_operator_object_active_editable(struct bContext *C)
Definition: screen_ops.c:396
bool ED_operator_view3d_active(struct bContext *C)
Definition: screen_ops.c:225
bool ED_operator_objectmode(struct bContext *C)
Definition: screen_ops.c:186
Contains defines and structs used throughout the imbuf module.
Read Guarded memory(de)allocation.
@ PROP_FLOAT
Definition: RNA_types.h:61
@ PROP_SKIP_SAVE
Definition: RNA_types.h:218
@ PROP_HIDDEN
Definition: RNA_types.h:216
@ PROP_ANGLE
Definition: RNA_types.h:145
#define C
Definition: RandGen.cpp:25
uiBlock * uiLayoutGetBlock(uiLayout *layout)
void uiItemIntO(uiLayout *layout, const char *name, int icon, const char *opname, const char *propname, int value)
struct uiLayout * UI_popup_menu_layout(uiPopupMenu *pup)
void uiItemS(uiLayout *layout)
uiLayout * uiLayoutRow(uiLayout *layout, bool align)
void uiItemFullO_ptr(uiLayout *layout, struct wmOperatorType *ot, const char *name, int icon, struct IDProperty *properties, wmOperatorCallContext context, int flag, struct PointerRNA *r_opptr)
void UI_popup_menu_end(struct bContext *C, struct uiPopupMenu *pup)
void uiItemMenuF(uiLayout *layout, const char *name, int icon, uiMenuCreateFunc func, void *arg)
void UI_block_flag_enable(uiBlock *block, int flag)
Definition: interface.cc:5848
void uiLayoutSetOperatorContext(uiLayout *layout, wmOperatorCallContext opcontext)
uiPopupMenu * UI_popup_menu_begin(struct bContext *C, const char *title, int icon) ATTR_NONNULL()
@ UI_BLOCK_IS_FLIP
Definition: UI_interface.h:136
int UI_icon_color_from_collection(const struct Collection *collection)
#define NS_EDITMODE_MESH
Definition: WM_types.h:503
@ OPTYPE_UNDO
Definition: WM_types.h:148
@ OPTYPE_REGISTER
Definition: WM_types.h:146
#define NS_EDITMODE_TEXT
Definition: WM_types.h:506
#define ND_DRAW
Definition: WM_types.h:410
#define ND_OB_ACTIVE
Definition: WM_types.h:388
#define NS_EDITMODE_CURVES
Definition: WM_types.h:512
#define ND_MODE
Definition: WM_types.h:393
#define ND_OB_SELECT
Definition: WM_types.h:390
#define NC_SCENE
Definition: WM_types.h:328
#define NS_EDITMODE_ARMATURE
Definition: WM_types.h:509
#define ND_OB_VISIBLE
Definition: WM_types.h:391
#define ND_LAYER_CONTENT
Definition: WM_types.h:402
#define ND_MODIFIER
Definition: WM_types.h:411
#define ND_POSE
Definition: WM_types.h:407
#define NS_MODE_OBJECT
Definition: WM_types.h:501
#define NS_EDITMODE_MBALL
Definition: WM_types.h:507
#define ND_TRANSFORM
Definition: WM_types.h:405
#define NS_EDITMODE_LATTICE
Definition: WM_types.h:508
#define ND_LAYER
Definition: WM_types.h:398
@ WM_OP_EXEC_REGION_WIN
Definition: WM_types.h:209
@ WM_OP_INVOKE_DEFAULT
Definition: WM_types.h:201
@ KM_SHIFT
Definition: WM_types.h:238
#define ND_DRAW_ANIMVIZ
Definition: WM_types.h:422
#define NC_OBJECT
Definition: WM_types.h:329
#define NS_EDITMODE_CURVE
Definition: WM_types.h:504
void animviz_calc_motionpaths(Depsgraph *depsgraph, Main *bmain, Scene *scene, ListBase *targets, eAnimvizCalcRange range, bool restore)
void animviz_get_object_motionpaths(Object *ob, ListBase *targets)
Depsgraph * animviz_depsgraph_build(Main *bmain, Scene *scene, ViewLayer *view_layer, ListBase *targets)
void animviz_motionpath_compute_range(Object *ob, Scene *scene)
void ED_armature_edit_free(struct bArmature *arm)
void ED_armature_from_edit(Main *bmain, bArmature *arm)
void ED_armature_to_edit(bArmature *arm)
__forceinline const avxb select(const avxb &m, const avxb &t, const avxb &f)
Definition: avxb.h:154
Scene scene
const Depsgraph * depsgraph
void * user_data
void ED_curve_editnurb_make(Object *obedit)
Definition: editcurve.c:1271
void ED_curve_editnurb_free(Object *obedit)
Definition: editcurve.c:1316
void ED_curve_editnurb_load(Main *bmain, Object *obedit)
Definition: editcurve.c:1234
void ED_curve_editfont_make(Object *obedit)
Definition: editfont.c:1837
void ED_curve_editfont_load(Object *obedit)
Definition: editfont.c:1873
void ED_curve_editfont_free(Object *obedit)
Definition: editfont.c:1903
#define GS(x)
Definition: iris.c:225
ccl_global KernelShaderEvalInput * input
void(* MEM_freeN)(void *vmemh)
Definition: mallocn.c:27
void *(* MEM_callocN)(size_t len, const char *str)
Definition: mallocn.c:31
void *(* MEM_mallocN)(size_t len, const char *str)
Definition: mallocn.c:33
#define G(x, y, z)
static void area(int d1, int d2, int e1, int e2, float weights[2])
void ED_object_check_force_modifiers(Main *bmain, Scene *scene, Object *object)
Definition: object_edit.c:1024
bool ED_object_editmode_exit_ex(Main *bmain, Scene *scene, Object *obedit, int flag)
Definition: object_edit.c:653
static int posemode_exec(bContext *C, wmOperator *op)
Definition: object_edit.c:934
static int object_hide_collection_invoke(bContext *C, wmOperator *op, const wmEvent *event)
Definition: object_edit.c:418
void OBJECT_OT_move_to_collection(wmOperatorType *ot)
Definition: object_edit.c:2073
void OBJECT_OT_mode_set_with_submode(wmOperatorType *ot)
Definition: object_edit.c:1785
void ED_objects_clear_paths(bContext *C, bool only_selected)
Definition: object_edit.c:1407
static int shade_smooth_exec(bContext *C, wmOperator *op)
Definition: object_edit.c:1475
void OBJECT_OT_hide_view_clear(wmOperatorType *ot)
Definition: object_edit.c:263
Object * ED_object_active_context(const bContext *C)
Definition: object_edit.c:125
bool ED_object_editmode_free_ex(Main *bmain, Object *obedit)
Definition: object_edit.c:703
static int move_to_collection_menus_create(wmOperator *op, MoveToCollectionData *menu)
Definition: object_edit.c:1918
void ED_objects_recalculate_paths(bContext *C, Scene *scene, eObjectPathCalcRange range, ListBase *ld_objects)
Definition: object_edit.c:1140
static bool shade_poll(bContext *C)
Definition: object_edit.c:1557
static bool has_pose_motion_paths(Object *ob)
Definition: object_edit.c:1135
void OBJECT_OT_hide_collection(wmOperatorType *ot)
Definition: object_edit.c:444
static void move_to_collection_menus_free(MoveToCollectionData **menu)
Definition: object_edit.c:1941
static int object_clear_paths_exec(bContext *C, wmOperator *op)
Definition: object_edit.c:1426
bool ED_object_editmode_exit_multi_ex(Main *bmain, Scene *scene, ViewLayer *view_layer, int flag)
Definition: object_edit.c:708
static eAnimvizCalcRange object_path_convert_range(eObjectPathCalcRange range)
Definition: object_edit.c:1091
void OBJECT_OT_paths_update(wmOperatorType *ot)
Definition: object_edit.c:1332
bool ED_object_editmode_enter_ex(Main *bmain, Scene *scene, Object *ob, int flag)
Definition: object_edit.c:734
static bool object_update_paths_poll(bContext *C)
Definition: object_edit.c:1296
static bool has_object_motion_paths(Object *ob)
Definition: object_edit.c:1130
void OBJECT_OT_posemode_toggle(wmOperatorType *ot)
Definition: object_edit.c:1003
static ListBase selected_objects_get(bContext *C)
Definition: object_edit.c:1807
static int object_hide_view_clear_exec(bContext *C, wmOperator *op)
Definition: object_edit.c:230
static int move_to_collection_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event))
Definition: object_edit.c:2005
void OBJECT_OT_link_to_collection(wmOperatorType *ot)
Definition: object_edit.c:2112
void ED_objects_recalculate_paths_visible(bContext *C, Scene *scene, eObjectPathCalcRange range)
Definition: object_edit.c:1117
static bool object_update_all_paths_poll(bContext *UNUSED(C))
Definition: object_edit.c:1353
static int object_update_all_paths_exec(bContext *C, wmOperator *UNUSED(op))
Definition: object_edit.c:1358
static int object_mode_set_exec(bContext *C, wmOperator *op)
Definition: object_edit.c:1667
static int move_to_collection_exec(bContext *C, wmOperator *op)
Definition: object_edit.c:1832
static bool object_hide_poll(bContext *C)
Definition: object_edit.c:222
static int forcefield_toggle_exec(bContext *C, wmOperator *UNUSED(op))
Definition: object_edit.c:1046
void OBJECT_OT_hide_view_set(wmOperatorType *ot)
Definition: object_edit.c:321
void OBJECT_OT_paths_clear(wmOperatorType *ot)
Definition: object_edit.c:1448
void OBJECT_OT_forcefield_toggle(wmOperatorType *ot)
Definition: object_edit.c:1069
Object ** ED_object_array_in_mode_or_selected(bContext *C, bool(*filter_fn)(const Object *ob, void *user_data), void *filter_user_data, uint *r_objects_len)
Definition: object_edit.c:137
static int object_hide_view_set_exec(bContext *C, wmOperator *op)
Definition: object_edit.c:281
static int object_clear_paths_invoke(bContext *C, wmOperator *op, const wmEvent *event)
Definition: object_edit.c:1440
bool ED_object_editmode_enter(bContext *C, int flag)
Definition: object_edit.c:833
static int editmode_toggle_exec(bContext *C, wmOperator *op)
Definition: object_edit.c:844
static bool object_mode_set_poll(bContext *C)
Definition: object_edit.c:1660
static MoveToCollectionData * master_collection_menu
Definition: object_edit.c:2003
void ED_collection_hide_menu_draw(const bContext *C, uiLayout *layout)
Definition: object_edit.c:382
void OBJECT_OT_editmode_toggle(wmOperatorType *ot)
Definition: object_edit.c:912
static int object_calculate_paths_exec(bContext *C, wmOperator *op)
Definition: object_edit.c:1229
bool ED_object_editmode_load(Main *bmain, Object *obedit)
Definition: object_edit.c:648
void OBJECT_OT_shade_flat(wmOperatorType *ot)
Definition: object_edit.c:1571
static const EnumPropertyItem * object_mode_set_itemf(bContext *C, PointerRNA *UNUSED(ptr), PropertyRNA *UNUSED(prop), bool *r_free)
Definition: object_edit.c:1626
static bool mesh_needs_keyindex(Main *bmain, const Mesh *me)
Definition: object_edit.c:483
static bool ED_object_editmode_load_free_ex(Main *bmain, Object *obedit, const bool load_data, const bool free_data)
Definition: object_edit.c:510
void OBJECT_OT_paths_update_visible(wmOperatorType *ot)
Definition: object_edit.c:1373
#define COLLECTION_INVALID_INDEX
Definition: object_edit.c:380
void OBJECT_OT_shade_smooth(wmOperatorType *ot)
Definition: object_edit.c:1586
bool ED_object_editmode_exit(bContext *C, int flag)
Definition: object_edit.c:695
static int object_update_paths_exec(bContext *C, wmOperator *op)
Definition: object_edit.c:1306
static CLG_LogRef LOG
Definition: object_edit.c:108
Object * ED_object_context(const bContext *C)
Definition: object_edit.c:120
static void move_to_collection_menus_items(struct uiLayout *layout, struct MoveToCollectionData *menu)
Definition: object_edit.c:1985
static bool editmode_toggle_poll(bContext *C)
Definition: object_edit.c:894
static bool move_to_collection_poll(bContext *C)
Definition: object_edit.c:1824
static void move_to_collection_menu_create(bContext *C, uiLayout *layout, void *menu_v)
Definition: object_edit.c:1952
void OBJECT_OT_paths_calculate(wmOperatorType *ot)
Definition: object_edit.c:1260
static void move_to_collection_menus_free_recursive(MoveToCollectionData *menu)
Definition: object_edit.c:1933
void OBJECT_OT_mode_set(wmOperatorType *ot)
Definition: object_edit.c:1760
void ED_objects_recalculate_paths_selected(bContext *C, Scene *scene, eObjectPathCalcRange range)
Definition: object_edit.c:1104
static int object_calculate_paths_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event))
Definition: object_edit.c:1208
bool ED_object_editmode_exit_multi(bContext *C, int flag)
Definition: object_edit.c:726
static void object_clear_mpath(Object *ob)
Definition: object_edit.c:1395
static int object_hide_collection_exec(bContext *C, wmOperator *op)
Definition: object_edit.c:341
bool ED_object_posemode_enter(bContext *C, Object *ob)
Definition: pose_edit.c:100
bool ED_object_posemode_enter_ex(struct Main *bmain, Object *ob)
Definition: pose_edit.c:80
bool ED_object_posemode_exit_ex(struct Main *bmain, Object *ob)
Definition: pose_edit.c:115
bool ED_object_posemode_exit(bContext *C, Object *ob)
Definition: pose_edit.c:128
void RNA_boolean_set(PointerRNA *ptr, const char *name, bool value)
Definition: rna_access.c:4874
bool RNA_property_is_set(PointerRNA *ptr, PropertyRNA *prop)
Definition: rna_access.c:5271
void RNA_int_set(PointerRNA *ptr, const char *name, int value)
Definition: rna_access.c:4921
PropertyRNA * RNA_struct_find_property(PointerRNA *ptr, const char *identifier)
Definition: rna_access.c:717
int RNA_property_int_get(PointerRNA *ptr, PropertyRNA *prop)
Definition: rna_access.c:2429
void RNA_string_get(PointerRNA *ptr, const char *name, char *value)
Definition: rna_access.c:5116
int RNA_int_get(PointerRNA *ptr, const char *name)
Definition: rna_access.c:4910
void RNA_property_boolean_set(PointerRNA *ptr, PropertyRNA *prop, bool value)
Definition: rna_access.c:2180
float RNA_float_get(PointerRNA *ptr, const char *name)
Definition: rna_access.c:4957
int RNA_property_enum_get(PointerRNA *ptr, PropertyRNA *prop)
Definition: rna_access.c:3402
bool RNA_struct_property_is_set(PointerRNA *ptr, const char *identifier)
Definition: rna_access.c:5301
bool RNA_boolean_get(PointerRNA *ptr, const char *name)
Definition: rna_access.c:4863
void RNA_enum_set(PointerRNA *ptr, const char *name, int value)
Definition: rna_access.c:5015
int RNA_enum_get(PointerRNA *ptr, const char *name)
Definition: rna_access.c:5004
void RNA_property_string_set(PointerRNA *ptr, PropertyRNA *prop, const char *value)
Definition: rna_access.c:3239
const EnumPropertyItem rna_enum_motionpath_display_type_items[]
Definition: rna_animviz.c:39
const EnumPropertyItem rna_enum_motionpath_range_items[]
Definition: rna_animviz.c:53
PropertyRNA * RNA_def_boolean(StructOrFunctionRNA *cont_, const char *identifier, bool default_value, const char *ui_name, const char *ui_description)
Definition: rna_define.c:3493
PropertyRNA * RNA_def_enum_flag(StructOrFunctionRNA *cont_, const char *identifier, const EnumPropertyItem *items, int default_value, const char *ui_name, const char *ui_description)
Definition: rna_define.c:3806
void RNA_def_property_float_default(PropertyRNA *prop, float value)
Definition: rna_define.c:2022
void RNA_def_property_ui_text(PropertyRNA *prop, const char *name, const char *description)
Definition: rna_define.c:1645
void RNA_def_property_range(PropertyRNA *prop, double min, double max)
Definition: rna_define.c:1737
PropertyRNA * RNA_def_property(StructOrFunctionRNA *cont_, const char *identifier, int type, int subtype)
Definition: rna_define.c:1257
void RNA_enum_item_end(EnumPropertyItem **items, int *totitem)
Definition: rna_define.c:4487
void RNA_enum_item_add(EnumPropertyItem **items, int *totitem, const EnumPropertyItem *item)
Definition: rna_define.c:4436
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:3687
void RNA_def_property_flag(PropertyRNA *prop, PropertyFlag flag)
Definition: rna_define.c:1490
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:3597
void RNA_def_enum_funcs(PropertyRNA *prop, EnumPropertyItemFunc itemfunc)
Definition: rna_define.c:3830
void RNA_enum_items_add_value(EnumPropertyItem **items, int *totitem, const EnumPropertyItem *item, int value)
Definition: rna_define.c:4472
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:3783
const EnumPropertyItem rna_enum_object_mode_items[]
Definition: rna_object.c:53
const EnumPropertyItem rna_enum_mesh_select_mode_items[]
Definition: rna_scene.c:131
struct BMesh * bm
Definition: BKE_editmesh.h:40
int totvert
Definition: bmesh_class.h:297
struct Object * object
struct EditFont * editfont
EditNurb * editnurb
Definition: DNA_ID.h:368
char name[66]
Definition: DNA_ID.h:378
struct EditLatt * editlatt
ListBase layer_collections
unsigned short local_collections_bits
void * first
Definition: DNA_listBase.h:31
Definition: BKE_main.h:121
ListBase objects
Definition: BKE_main.h:170
struct BMEditMesh * edit_mesh
struct Key * key
ListBase * editelems
char needs_flush_to_id
struct wmOperatorType * ot
Definition: object_edit.c:1915
struct MoveToCollectionData * prev
Definition: object_edit.c:1910
struct ListBase submenus
Definition: object_edit.c:1913
struct MoveToCollectionData * next
Definition: object_edit.c:1910
struct Collection * collection
Definition: object_edit.c:1912
int restore_mode
struct bPose * pose
struct PartDeflect * pd
short visibility_flag
bMotionPath * mpath
void * data
bAnimVizSettings avs
void * data
Definition: RNA_types.h:38
struct Collection * master_collection
struct ToolSettings * toolsettings
unsigned short local_collections_uuid
ListBase layer_collections
ListBase object_bases
ListBase * edbo
bAnimVizSettings avs
uint8_t modifier
Definition: WM_types.h:693
int(* invoke)(struct bContext *, struct wmOperator *, const struct wmEvent *) ATTR_WARN_UNUSED_RESULT
Definition: WM_types.h:919
const char * name
Definition: WM_types.h:888
const char * idname
Definition: WM_types.h:890
bool(* poll)(struct bContext *) ATTR_WARN_UNUSED_RESULT
Definition: WM_types.h:943
struct StructRNA * srna
Definition: WM_types.h:969
const char * translation_context
Definition: WM_types.h:891
const char * description
Definition: WM_types.h:893
int(* exec)(struct bContext *, struct wmOperator *) ATTR_WARN_UNUSED_RESULT
Definition: WM_types.h:903
PropertyRNA * prop
Definition: WM_types.h:981
struct ReportList * reports
struct wmOperatorType * type
struct PointerRNA * ptr
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:3480
wmOperatorType * ot
Definition: wm_files.c:3479
#define WM_msg_publish_rna_prop(mbus, id_, data_, type_, prop_)
void WM_operator_properties_create_ptr(PointerRNA *ptr, wmOperatorType *ot)
Definition: wm_operators.c:661
int WM_operator_props_dialog_popup(bContext *C, wmOperator *op, int width)
void WM_toolsystem_update_from_context_view3d(bContext *C)