Blender  V2.93
object_edit.c
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software Foundation,
14  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15  *
16  * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
17  * All rights reserved.
18  */
19 
24 #include <ctype.h>
25 #include <float.h>
26 #include <math.h>
27 #include <stddef.h> /* for offsetof */
28 #include <stdlib.h>
29 #include <string.h>
30 #include <time.h>
31 
32 #include "MEM_guardedalloc.h"
33 
34 #include "BLI_blenlib.h"
35 #include "BLI_ghash.h"
36 #include "BLI_utildefines.h"
37 
38 #include "BLT_translation.h"
39 
40 #include "DNA_armature_types.h"
41 #include "DNA_collection_types.h"
42 #include "DNA_curve_types.h"
43 #include "DNA_gpencil_types.h"
44 #include "DNA_lattice_types.h"
45 #include "DNA_material_types.h"
46 #include "DNA_mesh_types.h"
47 #include "DNA_meshdata_types.h"
48 #include "DNA_meta_types.h"
49 #include "DNA_object_force_types.h"
50 #include "DNA_object_types.h"
51 #include "DNA_scene_types.h"
52 #include "DNA_vfont_types.h"
53 #include "DNA_workspace_types.h"
54 
55 #include "IMB_imbuf_types.h"
56 
57 #include "BKE_anim_visualization.h"
58 #include "BKE_armature.h"
59 #include "BKE_collection.h"
60 #include "BKE_constraint.h"
61 #include "BKE_context.h"
62 #include "BKE_curve.h"
63 #include "BKE_editlattice.h"
64 #include "BKE_editmesh.h"
65 #include "BKE_effect.h"
66 #include "BKE_global.h"
67 #include "BKE_image.h"
68 #include "BKE_lattice.h"
69 #include "BKE_layer.h"
70 #include "BKE_main.h"
71 #include "BKE_material.h"
72 #include "BKE_mball.h"
73 #include "BKE_mesh.h"
74 #include "BKE_modifier.h"
75 #include "BKE_object.h"
76 #include "BKE_paint.h"
77 #include "BKE_particle.h"
78 #include "BKE_pointcache.h"
79 #include "BKE_report.h"
80 #include "BKE_scene.h"
81 #include "BKE_softbody.h"
82 #include "BKE_workspace.h"
83 
84 #include "DEG_depsgraph.h"
85 #include "DEG_depsgraph_build.h"
86 
87 #include "ED_anim_api.h"
88 #include "ED_armature.h"
89 #include "ED_curve.h"
90 #include "ED_gpencil.h"
91 #include "ED_image.h"
92 #include "ED_lattice.h"
93 #include "ED_mball.h"
94 #include "ED_mesh.h"
95 #include "ED_object.h"
96 #include "ED_outliner.h"
97 #include "ED_screen.h"
98 #include "ED_undo.h"
99 
100 #include "RNA_access.h"
101 #include "RNA_define.h"
102 #include "RNA_enum_types.h"
103 
104 #include "UI_interface_icons.h"
105 
106 #include "CLG_log.h"
107 
108 /* for menu/popup icons etc etc*/
109 
110 #include "UI_interface.h"
111 #include "UI_resources.h"
112 
113 #include "WM_api.h"
114 #include "WM_message.h"
115 #include "WM_toolsystem.h"
116 #include "WM_types.h"
117 
118 #include "object_intern.h" /* own include */
119 
120 static CLG_LogRef LOG = {"ed.object.edit"};
121 
122 /* prototypes */
124 static void move_to_collection_menus_items(struct uiLayout *layout,
125  struct MoveToCollectionData *menu);
127 
128 /* -------------------------------------------------------------------- */
133 {
134  return CTX_data_pointer_get_type(C, "object", &RNA_Object).data;
135 }
136 
137 /* find the correct active object per context
138  * note: context can be NULL when called from a enum with PROP_ENUM_NO_CONTEXT */
140 {
141  Object *ob = NULL;
142  if (C) {
143  ob = ED_object_context(C);
144  if (!ob) {
146  }
147  }
148  return ob;
149 }
150 
160  bool (*filter_fn)(Object *ob, void *user_data),
161  void *filter_user_data,
162  uint *r_objects_len)
163 {
165  ViewLayer *view_layer = CTX_data_view_layer(C);
166  Object *ob_active = OBACT(view_layer);
167  ID *id_pin = NULL;
168  const bool use_objects_in_mode = (ob_active != NULL) &&
169  (ob_active->mode & (OB_MODE_EDIT | OB_MODE_POSE));
170  const char space_type = area ? area->spacetype : SPACE_EMPTY;
171  Object **objects;
172 
173  Object *ob = NULL;
174  bool use_ob = true;
175 
176  if (space_type == SPACE_PROPERTIES) {
177  SpaceProperties *sbuts = area->spacedata.first;
178  id_pin = sbuts->pinid;
179  }
180 
181  if (id_pin && (GS(id_pin->name) == ID_OB)) {
182  /* Pinned data takes priority, in this case ignore selection & other objects in the mode. */
183  ob = (Object *)id_pin;
184  }
185  else if ((space_type == SPACE_PROPERTIES) && (use_objects_in_mode == false)) {
186  /* When using the space-properties, we don't want to use the entire selection
187  * as the current active object may not be selected.
188  *
189  * This is not the case when we're in a mode that supports multi-mode editing,
190  * since the active object and all other objects in the mode will be included
191  * irrespective of selection. */
192  ob = ob_active;
193  }
194  else if (ob_active && (ob_active->mode &
196  /* When painting, limit to active. */
197  ob = ob_active;
198  }
199  else {
200  /* Otherwise use full selection. */
201  use_ob = false;
202  }
203 
204  if (use_ob) {
205  if ((ob != NULL) && !filter_fn(ob, filter_user_data)) {
206  ob = NULL;
207  }
208  *r_objects_len = (ob != NULL) ? 1 : 0;
209  objects = MEM_mallocN(sizeof(*objects) * *r_objects_len, __func__);
210  if (ob != NULL) {
211  objects[0] = ob;
212  }
213  }
214  else {
215  const View3D *v3d = (space_type == SPACE_VIEW3D) ? area->spacedata.first : NULL;
216  /* When in a mode that supports multiple active objects, use "objects in mode"
217  * instead of the object's selection. */
218  if (use_objects_in_mode) {
219  objects = BKE_view_layer_array_from_objects_in_mode(view_layer,
220  v3d,
221  r_objects_len,
222  {.object_mode = ob_active->mode,
223  .no_dup_data = true,
224  .filter_fn = filter_fn,
225  .filter_userdata = filter_user_data});
226  }
227  else {
229  view_layer,
230  v3d,
231  r_objects_len,
232  {.no_dup_data = true, .filter_fn = filter_fn, .filter_userdata = filter_user_data});
233  }
234  }
235  return objects;
236 }
237 
240 /* -------------------------------------------------------------------- */
245 {
246  if (CTX_wm_space_outliner(C) != NULL) {
248  }
250 }
251 
253 {
255  ViewLayer *view_layer = CTX_data_view_layer(C);
256  const bool select = RNA_boolean_get(op->ptr, "select");
257  bool changed = false;
258 
259  LISTBASE_FOREACH (Base *, base, &view_layer->object_bases) {
260  if (base->flag & BASE_HIDDEN) {
261  base->flag &= ~BASE_HIDDEN;
262  changed = true;
263 
264  if (select) {
265  /* We cannot call `ED_object_base_select` because
266  * base is not selectable while it is hidden. */
267  base->flag |= BASE_SELECTED;
269  }
270  }
271  }
272 
273  if (!changed) {
274  return OPERATOR_CANCELLED;
275  }
276 
277  BKE_layer_collection_sync(scene, view_layer);
281 
282  return OPERATOR_FINISHED;
283 }
284 
286 {
287  /* identifiers */
288  ot->name = "Show Hidden Objects";
289  ot->description = "Reveal temporarily hidden objects";
290  ot->idname = "OBJECT_OT_hide_view_clear";
291 
292  /* api callbacks */
295 
296  /* flags */
298 
299  PropertyRNA *prop = RNA_def_boolean(ot->srna, "select", true, "Select", "");
301 }
302 
304 {
306  ViewLayer *view_layer = CTX_data_view_layer(C);
307  const bool unselected = RNA_boolean_get(op->ptr, "unselected");
308  bool changed = false;
309 
310  /* Hide selected or unselected objects. */
311  LISTBASE_FOREACH (Base *, base, &view_layer->object_bases) {
312  if (!(base->flag & BASE_VISIBLE_VIEWLAYER)) {
313  continue;
314  }
315 
316  if (!unselected) {
317  if (base->flag & BASE_SELECTED) {
319  base->flag |= BASE_HIDDEN;
320  changed = true;
321  }
322  }
323  else {
324  if (!(base->flag & BASE_SELECTED)) {
326  base->flag |= BASE_HIDDEN;
327  changed = true;
328  }
329  }
330  }
331  if (!changed) {
332  return OPERATOR_CANCELLED;
333  }
334 
335  BKE_layer_collection_sync(scene, view_layer);
339 
340  return OPERATOR_FINISHED;
341 }
342 
344 {
345  /* identifiers */
346  ot->name = "Hide Objects";
347  ot->description = "Temporarily hide objects from the viewport";
348  ot->idname = "OBJECT_OT_hide_view_set";
349 
350  /* api callbacks */
353 
354  /* flags */
356 
357  PropertyRNA *prop;
358  prop = RNA_def_boolean(
359  ot->srna, "unselected", 0, "Unselected", "Hide unselected rather than selected objects");
361 }
362 
364 {
365  wmWindow *win = CTX_wm_window(C);
366  View3D *v3d = CTX_wm_view3d(C);
367 
368  int index = RNA_int_get(op->ptr, "collection_index");
369  const bool extend = (win->eventstate->shift != 0);
370  const bool toggle = RNA_boolean_get(op->ptr, "toggle");
371 
372  if (win->eventstate->alt != 0) {
373  index += 10;
374  }
375 
377  ViewLayer *view_layer = CTX_data_view_layer(C);
379 
380  if (!lc) {
381  return OPERATOR_CANCELLED;
382  }
383 
385 
386  if (v3d->flag & V3D_LOCAL_COLLECTIONS) {
388  return OPERATOR_CANCELLED;
389  }
390  if (toggle) {
392  BKE_layer_collection_local_sync(view_layer, v3d);
393  }
394  else {
395  BKE_layer_collection_isolate_local(view_layer, v3d, lc, extend);
396  }
397  }
398  else {
399  BKE_layer_collection_isolate_global(scene, view_layer, lc, extend);
400  }
401 
403 
404  return OPERATOR_FINISHED;
405 }
406 
407 #define COLLECTION_INVALID_INDEX -1
408 
410 {
411  ViewLayer *view_layer = CTX_data_view_layer(C);
412  LayerCollection *lc_scene = view_layer->layer_collections.first;
413 
415 
417  int index = BKE_layer_collection_findindex(view_layer, lc);
418  uiLayout *row = uiLayoutRow(layout, false);
419 
420  if (lc->flag & LAYER_COLLECTION_EXCLUDE) {
421  continue;
422  }
423 
424  if (lc->collection->flag & COLLECTION_RESTRICT_VIEWPORT) {
425  continue;
426  }
427 
428  int icon = ICON_NONE;
429  if (BKE_layer_collection_has_selected_objects(view_layer, lc)) {
430  icon = ICON_LAYER_ACTIVE;
431  }
432  else if (lc->runtime_flag & LAYER_COLLECTION_HAS_OBJECTS) {
433  icon = ICON_LAYER_USED;
434  }
435 
436  uiItemIntO(row,
437  lc->collection->id.name + 2,
438  icon,
439  "OBJECT_OT_hide_collection",
440  "collection_index",
441  index);
442  }
443 }
444 
446 {
447  /* Immediately execute if collection index was specified. */
448  int index = RNA_int_get(op->ptr, "collection_index");
450  return object_hide_collection_exec(C, op);
451  }
452 
453  /* Open popup menu. */
454  const char *title = CTX_IFACE_(op->type->translation_context, op->type->name);
455  uiPopupMenu *pup = UI_popup_menu_begin(C, title, ICON_OUTLINER_COLLECTION);
456  uiLayout *layout = UI_popup_menu_layout(pup);
457 
459 
460  UI_popup_menu_end(C, pup);
461 
462  return OPERATOR_INTERFACE;
463 }
464 
466 {
467  /* identifiers */
468  ot->name = "Hide Collection";
469  ot->description = "Show only objects in collection (Shift to extend)";
470  ot->idname = "OBJECT_OT_hide_collection";
471 
472  /* api callbacks */
476 
477  /* flags */
479 
480  /* Properties. */
481  PropertyRNA *prop;
482  prop = RNA_def_int(ot->srna,
483  "collection_index",
486  INT_MAX,
487  "Collection Index",
488  "Index of the collection to change visibility",
489  0,
490  INT_MAX);
492  prop = RNA_def_boolean(ot->srna, "toggle", 0, "Toggle", "Toggle visibility");
494 }
495 
498 /* -------------------------------------------------------------------- */
502 static bool mesh_needs_keyindex(Main *bmain, const Mesh *me)
503 {
504  if (me->key) {
505  return false; /* will be added */
506  }
507 
508  LISTBASE_FOREACH (const Object *, ob, &bmain->objects) {
509  if ((ob->parent) && (ob->parent->data == me) && ELEM(ob->partype, PARVERT1, PARVERT3)) {
510  return true;
511  }
512  if (ob->data == me) {
513  LISTBASE_FOREACH (const ModifierData *, md, &ob->modifiers) {
514  if (md->type == eModifierType_Hook) {
515  return true;
516  }
517  }
518  }
519  }
520  return false;
521 }
522 
530  Object *obedit,
531  const bool load_data,
532  const bool free_data)
533 {
534  BLI_assert(load_data || free_data);
535 
536  if (obedit == NULL) {
537  return false;
538  }
539 
540  if (obedit->type == OB_MESH) {
541  Mesh *me = obedit->data;
542  if (me->edit_mesh == NULL) {
543  return false;
544  }
545 
546  if (me->edit_mesh->bm->totvert > MESH_MAX_VERTS) {
547  /* This used to be warned int the UI, we could warn again although it's quite rare. */
548  CLOG_WARN(&LOG,
549  "Too many vertices for mesh '%s' (%d)",
550  me->id.name + 2,
551  me->edit_mesh->bm->totvert);
552  return false;
553  }
554 
555  if (load_data) {
556  EDBM_mesh_load_ex(bmain, obedit, free_data);
557  }
558 
559  if (free_data) {
561  MEM_freeN(me->edit_mesh);
562  me->edit_mesh = NULL;
563  }
564  /* will be recalculated as needed. */
565  {
568  }
569  }
570  else if (obedit->type == OB_ARMATURE) {
571  const bArmature *arm = obedit->data;
572  if (arm->edbo == NULL) {
573  return false;
574  }
575 
576  if (load_data) {
577  ED_armature_from_edit(bmain, obedit->data);
578  }
579 
580  if (free_data) {
581  ED_armature_edit_free(obedit->data);
582 
583  if (load_data == false) {
584  /* Don't keep unused pose channels created by duplicating bones
585  * which may have been deleted/undone, see: T87631. */
586  if (obedit->pose != NULL) {
588  }
589  }
590  }
591  /* TODO(sergey): Pose channels might have been changed, so need
592  * to inform dependency graph about this. But is it really the
593  * best place to do this?
594  */
596  }
597  else if (ELEM(obedit->type, OB_CURVE, OB_SURF)) {
598  const Curve *cu = obedit->data;
599  if (cu->editnurb == NULL) {
600  return false;
601  }
602 
603  if (load_data) {
604  ED_curve_editnurb_load(bmain, obedit);
605  }
606 
607  if (free_data) {
608  ED_curve_editnurb_free(obedit);
609  }
610  }
611  else if (obedit->type == OB_FONT) {
612  const Curve *cu = obedit->data;
613  if (cu->editfont == NULL) {
614  return false;
615  }
616 
617  if (load_data) {
618  ED_curve_editfont_load(obedit);
619  }
620 
621  if (free_data) {
622  ED_curve_editfont_free(obedit);
623  }
624  }
625  else if (obedit->type == OB_LATTICE) {
626  const Lattice *lt = obedit->data;
627  if (lt->editlatt == NULL) {
628  return false;
629  }
630 
631  if (load_data) {
632  BKE_editlattice_load(obedit);
633  }
634 
635  if (free_data) {
636  BKE_editlattice_free(obedit);
637  }
638  }
639  else if (obedit->type == OB_MBALL) {
640  const MetaBall *mb = obedit->data;
641  if (mb->editelems == NULL) {
642  return false;
643  }
644 
645  if (load_data) {
646  ED_mball_editmball_load(obedit);
647  }
648 
649  if (free_data) {
650  ED_mball_editmball_free(obedit);
651  }
652  }
653  else {
654  return false;
655  }
656 
657  if (load_data) {
658  char *needs_flush_ptr = BKE_object_data_editmode_flush_ptr_get(obedit->data);
659  if (needs_flush_ptr) {
660  *needs_flush_ptr = false;
661  }
662  }
663 
664  return true;
665 }
666 
667 bool ED_object_editmode_load(Main *bmain, Object *obedit)
668 {
669  return ED_object_editmode_load_free_ex(bmain, obedit, true, false);
670 }
671 
676 bool ED_object_editmode_exit_ex(Main *bmain, Scene *scene, Object *obedit, int flag)
677 {
678  const bool free_data = (flag & EM_FREEDATA) != 0;
679 
680  if (ED_object_editmode_load_free_ex(bmain, obedit, true, free_data) == false) {
681  /* in rare cases (background mode) its possible active object
682  * is flagged for editmode, without 'obedit' being set T35489. */
683  if (UNLIKELY(obedit && obedit->mode & OB_MODE_EDIT)) {
684  obedit->mode &= ~OB_MODE_EDIT;
685  /* Also happens when mesh is shared across multiple objects. [#T69834] */
687  }
688  return true;
689  }
690 
691  /* `free_data` only false now on file saves and render. */
692  if (free_data) {
693  /* flag object caches as outdated */
694  ListBase pidlist;
695  BKE_ptcache_ids_from_object(&pidlist, obedit, scene, 0);
696  LISTBASE_FOREACH (PTCacheID *, pid, &pidlist) {
697  /* particles don't need reset on geometry change */
698  if (pid->type != PTCACHE_TYPE_PARTICLES) {
699  pid->cache->flag |= PTCACHE_OUTDATED;
700  }
701  }
702  BLI_freelistN(&pidlist);
703 
706 
707  /* also flush ob recalc, doesn't take much overhead, but used for particles */
709 
711 
712  obedit->mode &= ~OB_MODE_EDIT;
713  }
714 
715  return (obedit->mode & OB_MODE_EDIT) == 0;
716 }
717 
719 {
720  Main *bmain = CTX_data_main(C);
722  Object *obedit = CTX_data_edit_object(C);
723  return ED_object_editmode_exit_ex(bmain, scene, obedit, flag);
724 }
725 
732 {
733  return ED_object_editmode_load_free_ex(bmain, obedit, false, true);
734 }
735 
736 bool ED_object_editmode_exit_multi_ex(Main *bmain, Scene *scene, ViewLayer *view_layer, int flag)
737 {
738  Object *obedit = OBEDIT_FROM_VIEW_LAYER(view_layer);
739  if (obedit == NULL) {
740  return false;
741  }
742  bool changed = false;
743  const short obedit_type = obedit->type;
744 
745  LISTBASE_FOREACH (Base *, base, &view_layer->object_bases) {
746  Object *ob = base->object;
747  if ((ob->type == obedit_type) && (ob->mode & OB_MODE_EDIT)) {
748  changed |= ED_object_editmode_exit_ex(bmain, scene, base->object, flag);
749  }
750  }
751  return changed;
752 }
753 
755 {
756  Main *bmain = CTX_data_main(C);
758  ViewLayer *view_layer = CTX_data_view_layer(C);
759  return ED_object_editmode_exit_multi_ex(bmain, scene, view_layer, flag);
760 }
761 
762 bool ED_object_editmode_enter_ex(Main *bmain, Scene *scene, Object *ob, int flag)
763 {
764  bool ok = false;
765 
766  if (ELEM(NULL, ob, ob->data) || ID_IS_LINKED(ob) || ID_IS_OVERRIDE_LIBRARY(ob) ||
768  return false;
769  }
770 
771  /* This checks actual `ob->data`, for cases when other scenes have it in edit-mode context.
772  * Currently multiple objects sharing a mesh being in edit-mode at once isn't supported,
773  * see: T86767. */
774  if (BKE_object_is_in_editmode(ob)) {
775  return true;
776  }
777 
779  /* Ideally the caller should check this. */
780  CLOG_WARN(&LOG, "Unable to enter edit-mode on library data for object '%s'", ob->id.name + 2);
781  return false;
782  }
783 
784  ob->restore_mode = ob->mode;
785 
786  ob->mode = OB_MODE_EDIT;
787 
788  if (ob->type == OB_MESH) {
789  ok = true;
790 
791  const bool use_key_index = mesh_needs_keyindex(bmain, ob->data);
792 
793  EDBM_mesh_make(ob, scene->toolsettings->selectmode, use_key_index);
794 
796  if (LIKELY(em)) {
797  /* order doesn't matter */
800  }
801 
803  }
804  else if (ob->type == OB_ARMATURE) {
805  bArmature *arm = ob->data;
806  ok = true;
807  ED_armature_to_edit(arm);
808  /* To ensure all goes in rest-position and without striding. */
809 
810  arm->needs_flush_to_id = 0;
811 
812  /* XXX: should this be ID_RECALC_GEOMETRY? */
814 
816  }
817  else if (ob->type == OB_FONT) {
818  ok = true;
820 
822  }
823  else if (ob->type == OB_MBALL) {
824  MetaBall *mb = ob->data;
825 
826  ok = true;
828 
829  mb->needs_flush_to_id = 0;
830 
832  }
833  else if (ob->type == OB_LATTICE) {
834  ok = true;
836 
838  }
839  else if (ELEM(ob->type, OB_SURF, OB_CURVE)) {
840  ok = true;
842 
844  }
845 
846  if (ok) {
848  }
849  else {
850  if ((flag & EM_NO_CONTEXT) == 0) {
851  ob->mode &= ~OB_MODE_EDIT;
852  }
854  }
855 
856  return (ob->mode & OB_MODE_EDIT) != 0;
857 }
858 
860 {
861  Main *bmain = CTX_data_main(C);
863 
864  /* Active layer checked here for view3d,
865  * callers that don't want view context can call the extended version. */
867  return ED_object_editmode_enter_ex(bmain, scene, ob, flag);
868 }
869 
871 {
872  Main *bmain = CTX_data_main(C);
874  View3D *v3d = CTX_wm_view3d(C);
875  ViewLayer *view_layer = CTX_data_view_layer(C);
876  Object *obact = OBACT(view_layer);
877  const int mode_flag = OB_MODE_EDIT;
878  const bool is_mode_set = (obact->mode & mode_flag) != 0;
879  struct wmMsgBus *mbus = CTX_wm_message_bus(C);
880 
881  if (!is_mode_set) {
882  if (!ED_object_mode_compat_set(C, obact, mode_flag, op->reports)) {
883  return OPERATOR_CANCELLED;
884  }
885  }
886 
887  if (!is_mode_set) {
888  ED_object_editmode_enter_ex(bmain, scene, obact, 0);
889  if (obact->mode & mode_flag) {
890  FOREACH_SELECTED_OBJECT_BEGIN (view_layer, v3d, ob) {
891  if ((ob != obact) && (ob->type == obact->type)) {
893  }
894  }
896  }
897  }
898  else {
900 
901  if ((obact->mode & mode_flag) == 0) {
902  FOREACH_OBJECT_BEGIN (view_layer, ob) {
903  if ((ob != obact) && (ob->type == obact->type)) {
905  }
906  }
908  }
909  }
910 
911  WM_msg_publish_rna_prop(mbus, &obact->id, obact, Object, mode);
912 
913  if (G.background == false) {
915  }
916 
917  return OPERATOR_FINISHED;
918 }
919 
921 {
923 
924  /* covers proxies too */
925  if (ELEM(NULL, ob, ob->data) || ID_IS_LINKED(ob->data) || ID_IS_OVERRIDE_LIBRARY(ob) ||
927  return false;
928  }
929 
930  /* if hidden but in edit mode, we still display */
931  if ((ob->restrictflag & OB_RESTRICT_VIEWPORT) && !(ob->mode & OB_MODE_EDIT)) {
932  return false;
933  }
934 
935  return OB_TYPE_SUPPORT_EDITMODE(ob->type);
936 }
937 
939 {
940 
941  /* identifiers */
942  ot->name = "Toggle Edit Mode";
943  ot->description = "Toggle object's edit mode";
944  ot->idname = "OBJECT_OT_editmode_toggle";
945 
946  /* api callbacks */
949 
950  /* flags */
952 }
953 
956 /* -------------------------------------------------------------------- */
961 {
962  struct wmMsgBus *mbus = CTX_wm_message_bus(C);
963  struct Main *bmain = CTX_data_main(C);
965  ViewLayer *view_layer = CTX_data_view_layer(C);
966  Base *base = CTX_data_active_base(C);
967 
968  /* If the base is NULL it means we have an active object, but the object itself is hidden. */
969  if (base == NULL) {
970  return OPERATOR_CANCELLED;
971  }
972 
973  Object *obact = base->object;
974  const int mode_flag = OB_MODE_POSE;
975  bool is_mode_set = (obact->mode & mode_flag) != 0;
976 
977  if (!is_mode_set) {
978  if (!ED_object_mode_compat_set(C, obact, mode_flag, op->reports)) {
979  return OPERATOR_CANCELLED;
980  }
981  }
982 
983  if (obact->type != OB_ARMATURE) {
984  return OPERATOR_PASS_THROUGH;
985  }
986 
987  {
988  Object *obedit = OBEDIT_FROM_VIEW_LAYER(view_layer);
989  if (obact == obedit) {
991  is_mode_set = false;
992  }
993  }
994 
995  if (is_mode_set) {
996  bool ok = ED_object_posemode_exit(C, obact);
997  if (ok) {
998  FOREACH_OBJECT_BEGIN (view_layer, ob) {
999  if ((ob != obact) && (ob->type == OB_ARMATURE) && (ob->mode & mode_flag)) {
1000  ED_object_posemode_exit_ex(bmain, ob);
1001  }
1002  }
1004  }
1005  }
1006  else {
1007  bool ok = ED_object_posemode_enter(C, obact);
1008  if (ok) {
1009  const View3D *v3d = CTX_wm_view3d(C);
1010  FOREACH_SELECTED_OBJECT_BEGIN (view_layer, v3d, ob) {
1011  if ((ob != obact) && (ob->type == OB_ARMATURE) && (ob->mode == OB_MODE_OBJECT) &&
1012  (!ID_IS_LINKED(ob))) {
1013  ED_object_posemode_enter_ex(bmain, ob);
1014  }
1015  }
1017  }
1018  }
1019 
1020  WM_msg_publish_rna_prop(mbus, &obact->id, obact, Object, mode);
1021 
1022  if (G.background == false) {
1024  }
1025 
1026  return OPERATOR_FINISHED;
1027 }
1028 
1030 {
1031  /* identifiers */
1032  ot->name = "Toggle Pose Mode";
1033  ot->idname = "OBJECT_OT_posemode_toggle";
1034  ot->description = "Enable or disable posing/selecting bones";
1035 
1036  /* api callbacks */
1037  ot->exec = posemode_exec;
1039 
1040  /* flag */
1042 }
1043 
1046 /* -------------------------------------------------------------------- */
1051 {
1052  PartDeflect *pd = object->pd;
1054 
1055  /* add/remove modifier as needed */
1056  if (!md) {
1057  if (pd && (pd->shape == PFIELD_SHAPE_SURFACE) &&
1059  if (ELEM(object->type, OB_MESH, OB_SURF, OB_FONT, OB_CURVE)) {
1061  }
1062  }
1063  }
1064  else {
1065  if (!pd || (pd->shape != PFIELD_SHAPE_SURFACE) ||
1067  ED_object_modifier_remove(NULL, bmain, scene, object, md);
1068  }
1069  }
1070 }
1071 
1073 {
1075 
1076  if (ob->pd == NULL) {
1078  }
1079  else if (ob->pd->forcefield == 0) {
1080  ob->pd->forcefield = PFIELD_FORCE;
1081  }
1082  else {
1083  ob->pd->forcefield = 0;
1084  }
1085 
1089 
1091 
1092  return OPERATOR_FINISHED;
1093 }
1094 
1096 {
1097 
1098  /* identifiers */
1099  ot->name = "Toggle Force Field";
1100  ot->description = "Toggle object's force field";
1101  ot->idname = "OBJECT_OT_forcefield_toggle";
1102 
1103  /* api callbacks */
1106 
1107  /* flags */
1109 }
1110 
1113 /* -------------------------------------------------------------------- */
1118 {
1119  switch (range) {
1125  return ANIMVIZ_CALC_RANGE_FULL;
1126  }
1127  return ANIMVIZ_CALC_RANGE_FULL;
1128 }
1129 
1130 /* For the objects with animation: update paths for those that have got them
1131  * This should selectively update paths that exist...
1132  *
1133  * To be called from various tools that do incremental updates
1134  */
1136 {
1137  /* Transform doesn't always have context available to do update. */
1138  if (C == NULL) {
1139  return;
1140  }
1141 
1142  Main *bmain = CTX_data_main(C);
1143  ViewLayer *view_layer = CTX_data_view_layer(C);
1144 
1145  ListBase targets = {NULL, NULL};
1146  /* loop over objects in scene */
1147  CTX_DATA_BEGIN (C, Object *, ob, selected_editable_objects) {
1148  /* set flag to force recalc, then grab path(s) from object */
1149  ob->avs.recalc |= ANIMVIZ_RECALC_PATHS;
1150  animviz_get_object_motionpaths(ob, &targets);
1151  }
1152  CTX_DATA_END;
1153 
1155  bool free_depsgraph = false;
1156  /* For a single frame update it's faster to re-use existing dependency graph and avoid overhead
1157  * of building all the relations and so on for a temporary one. */
1158  if (range == OBJECT_PATH_CALC_RANGE_CURRENT_FRAME) {
1159  /* NOTE: Dependency graph will be evaluated at all the frames, but we first need to access some
1160  * nested pointers, like animation data. */
1162  free_depsgraph = false;
1163  }
1164  else {
1165  depsgraph = animviz_depsgraph_build(bmain, scene, view_layer, &targets);
1166  free_depsgraph = true;
1167  }
1168 
1169  /* recalculate paths, then free */
1171  depsgraph, bmain, scene, &targets, object_path_convert_range(range), true);
1172  BLI_freelistN(&targets);
1173 
1174  if (range != OBJECT_PATH_CALC_RANGE_CURRENT_FRAME) {
1175  /* Tag objects for copy on write - so paths will draw/redraw
1176  * For currently frame only we update evaluated object directly. */
1177  CTX_DATA_BEGIN (C, Object *, ob, selected_editable_objects) {
1178  if (ob->mpath) {
1180  }
1181  }
1182  CTX_DATA_END;
1183  }
1184 
1185  /* Free temporary depsgraph. */
1186  if (free_depsgraph) {
1188  }
1189 }
1190 
1191 /* show popup to determine settings */
1193 {
1195 
1196  if (ob == NULL) {
1197  return OPERATOR_CANCELLED;
1198  }
1199 
1200  /* set default settings from existing/stored settings */
1201  {
1202  bAnimVizSettings *avs = &ob->avs;
1203 
1204  RNA_int_set(op->ptr, "start_frame", avs->path_sf);
1205  RNA_int_set(op->ptr, "end_frame", avs->path_ef);
1206  }
1207 
1208  /* show popup dialog to allow editing of range... */
1209  /* FIXME: hard-coded dimensions here are just arbitrary. */
1210  return WM_operator_props_dialog_popup(C, op, 200);
1211 }
1212 
1213 /* Calculate/recalculate whole paths (avs.path_sf to avs.path_ef) */
1215 {
1217  int start = RNA_int_get(op->ptr, "start_frame");
1218  int end = RNA_int_get(op->ptr, "end_frame");
1219 
1220  /* set up path data for bones being calculated */
1221  CTX_DATA_BEGIN (C, Object *, ob, selected_editable_objects) {
1222  bAnimVizSettings *avs = &ob->avs;
1223 
1224  /* grab baking settings from operator settings */
1225  avs->path_sf = start;
1226  avs->path_ef = end;
1227 
1228  /* verify that the selected object has the appropriate settings */
1230  }
1231  CTX_DATA_END;
1232 
1233  /* calculate the paths for objects that have them (and are tagged to get refreshed) */
1235 
1236  /* notifiers for updates */
1238 
1239  return OPERATOR_FINISHED;
1240 }
1241 
1243 {
1244  /* identifiers */
1245  ot->name = "Calculate Object Paths";
1246  ot->idname = "OBJECT_OT_paths_calculate";
1247  ot->description = "Calculate motion paths for the selected objects";
1248 
1249  /* api callbacks */
1253 
1254  /* flags */
1256 
1257  /* properties */
1258  RNA_def_int(ot->srna,
1259  "start_frame",
1260  1,
1261  MINAFRAME,
1262  MAXFRAME,
1263  "Start",
1264  "First frame to calculate object paths on",
1265  MINFRAME,
1266  MAXFRAME / 2.0);
1267  RNA_def_int(ot->srna,
1268  "end_frame",
1269  250,
1270  MINAFRAME,
1271  MAXFRAME,
1272  "End",
1273  "Last frame to calculate object paths on",
1274  MINFRAME,
1275  MAXFRAME / 2.0);
1276 }
1277 
1280 /* -------------------------------------------------------------------- */
1285 {
1288  return (ob->avs.path_bakeflag & MOTIONPATH_BAKE_HAS_PATHS) != 0;
1289  }
1290 
1291  return false;
1292 }
1293 
1295 {
1297 
1298  if (scene == NULL) {
1299  return OPERATOR_CANCELLED;
1300  }
1301 
1302  /* calculate the paths for objects that have them (and are tagged to get refreshed) */
1304 
1305  /* notifiers for updates */
1307 
1308  return OPERATOR_FINISHED;
1309 }
1310 
1312 {
1313  /* identifiers */
1314  ot->name = "Update Object Paths";
1315  ot->idname = "OBJECT_OT_paths_update";
1316  ot->description = "Recalculate paths for selected objects";
1317 
1318  /* api callbacks */
1321 
1322  /* flags */
1324 }
1325 
1328 /* -------------------------------------------------------------------- */
1332 /* Helper for ED_objects_clear_paths() */
1333 static void object_clear_mpath(Object *ob)
1334 {
1335  if (ob->mpath) {
1337  ob->mpath = NULL;
1339 
1340  /* tag object for copy on write - so removed paths don't still show */
1342  }
1343 }
1344 
1345 /* Clear motion paths for all objects */
1346 void ED_objects_clear_paths(bContext *C, bool only_selected)
1347 {
1348  if (only_selected) {
1349  /* Loop over all selected + editable objects in scene. */
1350  CTX_DATA_BEGIN (C, Object *, ob, selected_editable_objects) {
1351  object_clear_mpath(ob);
1352  }
1353  CTX_DATA_END;
1354  }
1355  else {
1356  /* Loop over all editable objects in scene. */
1357  CTX_DATA_BEGIN (C, Object *, ob, editable_objects) {
1358  object_clear_mpath(ob);
1359  }
1360  CTX_DATA_END;
1361  }
1362 }
1363 
1364 /* operator callback for this */
1366 {
1367  bool only_selected = RNA_boolean_get(op->ptr, "only_selected");
1368 
1369  /* use the backend function for this */
1370  ED_objects_clear_paths(C, only_selected);
1371 
1372  /* notifiers for updates */
1374 
1375  return OPERATOR_FINISHED;
1376 }
1377 
1378 /* operator callback/wrapper */
1379 static int object_clear_paths_invoke(bContext *C, wmOperator *op, const wmEvent *event)
1380 {
1381  if ((event->shift) && !RNA_struct_property_is_set(op->ptr, "only_selected")) {
1382  RNA_boolean_set(op->ptr, "only_selected", true);
1383  }
1384  return object_clear_paths_exec(C, op);
1385 }
1386 
1388 {
1389  /* identifiers */
1390  ot->name = "Clear Object Paths";
1391  ot->idname = "OBJECT_OT_paths_clear";
1392  ot->description = "Clear path caches for all objects, hold Shift key for selected objects only";
1393 
1394  /* api callbacks */
1398 
1399  /* flags */
1401 
1402  /* properties */
1403  ot->prop = RNA_def_boolean(
1404  ot->srna, "only_selected", false, "Only Selected", "Only clear paths from selected objects");
1406 }
1407 
1410 /* -------------------------------------------------------------------- */
1415 {
1417 
1418  /* Loop over all editable objects in scene. */
1419  CTX_DATA_BEGIN (C, Object *, ob, editable_objects) {
1420  /* use Preview Range or Full Frame Range - whichever is in use */
1421  ob->avs.path_sf = PSFRA;
1422  ob->avs.path_ef = PEFRA;
1423 
1424  /* tag for updates */
1427  }
1428  CTX_DATA_END;
1429 
1430  return OPERATOR_FINISHED;
1431 }
1432 
1434 {
1435  /* identifiers */
1436  ot->name = "Update Range from Scene";
1437  ot->idname = "OBJECT_OT_paths_range_update";
1438  ot->description = "Update frame range for motion paths from the Scene's current frame range";
1439 
1440  /* callbacks */
1443 
1444  /* flags */
1446 }
1447 
1450 /* -------------------------------------------------------------------- */
1455 {
1456  const bool use_smooth = STREQ(op->idname, "OBJECT_OT_shade_smooth");
1457  bool changed_multi = false;
1458  bool has_linked_data = false;
1459 
1460  ListBase ctx_objects = {NULL, NULL};
1461  CollectionPointerLink ctx_ob_single_active = {NULL};
1462 
1463  /* For modes that only use an active object, don't handle the whole selection. */
1464  {
1465  ViewLayer *view_layer = CTX_data_view_layer(C);
1466  Object *obact = OBACT(view_layer);
1467  if (obact && ((obact->mode & OB_MODE_ALL_PAINT))) {
1468  ctx_ob_single_active.ptr.data = obact;
1469  BLI_addtail(&ctx_objects, &ctx_ob_single_active);
1470  }
1471  }
1472 
1473  if (ctx_objects.first != &ctx_ob_single_active) {
1474  CTX_data_selected_editable_objects(C, &ctx_objects);
1475  }
1476 
1477  LISTBASE_FOREACH (CollectionPointerLink *, ctx_ob, &ctx_objects) {
1478  Object *ob = ctx_ob->ptr.data;
1479  ID *data = ob->data;
1480  if (data != NULL) {
1481  data->tag |= LIB_TAG_DOIT;
1482  }
1483  }
1484 
1485  LISTBASE_FOREACH (CollectionPointerLink *, ctx_ob, &ctx_objects) {
1486  /* Always un-tag all object data-blocks irrespective of our ability to operate on them. */
1487  Object *ob = ctx_ob->ptr.data;
1488  ID *data = ob->data;
1489  if ((data == NULL) || ((data->tag & LIB_TAG_DOIT) == 0)) {
1490  continue;
1491  }
1492  data->tag &= ~LIB_TAG_DOIT;
1493  /* Finished un-tagging, continue with regular logic. */
1494 
1495  if (data && ID_IS_LINKED(data)) {
1496  has_linked_data = true;
1497  continue;
1498  }
1499 
1500  bool changed = false;
1501  if (ob->type == OB_MESH) {
1502  BKE_mesh_smooth_flag_set(ob->data, use_smooth);
1504  changed = true;
1505  }
1506  else if (ELEM(ob->type, OB_SURF, OB_CURVE)) {
1507  BKE_curve_smooth_flag_set(ob->data, use_smooth);
1508  changed = true;
1509  }
1510 
1511  if (changed) {
1512  changed_multi = true;
1513 
1516  }
1517  }
1518 
1519  if (ctx_objects.first != &ctx_ob_single_active) {
1520  BLI_freelistN(&ctx_objects);
1521  }
1522 
1523  if (has_linked_data) {
1524  BKE_report(op->reports, RPT_WARNING, "Can't edit linked mesh or curve data");
1525  }
1526 
1527  return (changed_multi) ? OPERATOR_FINISHED : OPERATOR_CANCELLED;
1528 }
1529 
1530 static bool shade_poll(bContext *C)
1531 {
1532  ViewLayer *view_layer = CTX_data_view_layer(C);
1533  Object *obact = OBACT(view_layer);
1534  if (obact != NULL) {
1535  /* Doesn't handle edit-data, sculpt dynamic-topology, or their undo systems. */
1536  if (obact->mode & (OB_MODE_EDIT | OB_MODE_SCULPT) || obact->data == NULL ||
1538  return false;
1539  }
1540  }
1541  return true;
1542 }
1543 
1545 {
1546  /* identifiers */
1547  ot->name = "Shade Flat";
1548  ot->description = "Render and display faces uniform, using Face Normals";
1549  ot->idname = "OBJECT_OT_shade_flat";
1550 
1551  /* api callbacks */
1552  ot->poll = shade_poll;
1554 
1555  /* flags */
1557 }
1558 
1560 {
1561  /* identifiers */
1562  ot->name = "Shade Smooth";
1563  ot->description = "Render and display faces smooth, using interpolated Vertex Normals";
1564  ot->idname = "OBJECT_OT_shade_smooth";
1565 
1566  /* api callbacks */
1567  ot->poll = shade_poll;
1569 
1570  /* flags */
1572 }
1573 
1576 /* -------------------------------------------------------------------- */
1581  PointerRNA *UNUSED(ptr),
1582  PropertyRNA *UNUSED(prop),
1583  bool *r_free)
1584 {
1586  EnumPropertyItem *item = NULL;
1587  int totitem = 0;
1588 
1589  if (!C) { /* needed for docs */
1591  }
1592 
1593  const Object *ob = CTX_data_active_object(C);
1594  if (ob) {
1595  const bool use_mode_particle_edit = ED_object_particle_edit_mode_supported(ob);
1596  while (input->identifier) {
1597  if ((input->value == OB_MODE_EDIT && OB_TYPE_SUPPORT_EDITMODE(ob->type)) ||
1598  (input->value == OB_MODE_POSE && (ob->type == OB_ARMATURE)) ||
1599  (input->value == OB_MODE_PARTICLE_EDIT && use_mode_particle_edit) ||
1600  (ELEM(input->value,
1605  (ob->type == OB_MESH)) ||
1606  (ELEM(input->value,
1612  (ob->type == OB_GPENCIL)) ||
1613  (input->value == OB_MODE_OBJECT)) {
1614  RNA_enum_item_add(&item, &totitem, input);
1615  }
1616  input++;
1617  }
1618  }
1619  else {
1620  /* We need at least this one! */
1621  RNA_enum_items_add_value(&item, &totitem, input, OB_MODE_OBJECT);
1622  }
1623 
1624  RNA_enum_item_end(&item, &totitem);
1625 
1626  *r_free = true;
1627 
1628  return item;
1629 }
1630 
1632 {
1633  /* Needed as #ED_operator_object_active_editable doesn't call use 'active_object'. */
1636 }
1637 
1639 {
1640  const bool use_submode = STREQ(op->idname, "OBJECT_OT_mode_set_with_submode");
1642  eObjectMode mode = RNA_enum_get(op->ptr, "mode");
1643  const bool toggle = RNA_boolean_get(op->ptr, "toggle");
1644 
1645  /* by default the operator assume is a mesh, but if gp object change mode */
1646  if ((ob->type == OB_GPENCIL) && (mode == OB_MODE_EDIT)) {
1647  mode = OB_MODE_EDIT_GPENCIL;
1648  }
1649 
1650  if (!ED_object_mode_compat_test(ob, mode)) {
1651  return OPERATOR_PASS_THROUGH;
1652  }
1653 
1672  if (toggle == false) {
1673  if (ob->mode != mode) {
1674  ED_object_mode_set_ex(C, mode, true, op->reports);
1675  }
1676  }
1677  else {
1678  const eObjectMode mode_prev = ob->mode;
1679  /* When toggling object mode, we always use the restore mode,
1680  * otherwise there is nothing to do. */
1681  if (mode == OB_MODE_OBJECT) {
1682  if (ob->mode != OB_MODE_OBJECT) {
1683  if (ED_object_mode_set_ex(C, OB_MODE_OBJECT, true, op->reports)) {
1684  /* Store old mode so we know what to go back to. */
1685  ob->restore_mode = mode_prev;
1686  }
1687  }
1688  else {
1689  if (ob->restore_mode != OB_MODE_OBJECT) {
1690  ED_object_mode_set_ex(C, ob->restore_mode, true, op->reports);
1691  }
1692  }
1693  }
1694  else {
1695  /* Non-object modes, enter the 'mode' unless it's already set,
1696  * in that case use restore mode. */
1697  if (ob->mode != mode) {
1698  if (ED_object_mode_set_ex(C, mode, true, op->reports)) {
1699  /* Store old mode so we know what to go back to. */
1700  ob->restore_mode = mode_prev;
1701  }
1702  }
1703  else {
1704  if (ob->restore_mode != OB_MODE_OBJECT) {
1705  ED_object_mode_set_ex(C, ob->restore_mode, true, op->reports);
1706  }
1707  else {
1709  }
1710  }
1711  }
1712  }
1713 
1714  if (use_submode) {
1715  if (ob->type == OB_MESH) {
1716  if (ob->mode & OB_MODE_EDIT) {
1717  PropertyRNA *prop = RNA_struct_find_property(op->ptr, "mesh_select_mode");
1718  if (RNA_property_is_set(op->ptr, prop)) {
1719  int mesh_select_mode = RNA_property_enum_get(op->ptr, prop);
1720  if (mesh_select_mode != 0) {
1721  EDBM_selectmode_set_multi(C, mesh_select_mode);
1722  }
1723  }
1724  }
1725  }
1726  }
1727 
1728  return OPERATOR_FINISHED;
1729 }
1730 
1732 {
1733  PropertyRNA *prop;
1734 
1735  /* identifiers */
1736  ot->name = "Set Object Mode";
1737  ot->description = "Sets the object interaction mode";
1738  ot->idname = "OBJECT_OT_mode_set";
1739 
1740  /* api callbacks */
1743 
1744  /* flags */
1745  ot->flag = 0; /* no register/undo here, leave it to operators being called */
1746 
1747  ot->prop = RNA_def_enum(
1748  ot->srna, "mode", rna_enum_object_mode_items, OB_MODE_OBJECT, "Mode", "");
1751 
1752  prop = RNA_def_boolean(ot->srna, "toggle", 0, "Toggle", "");
1754 }
1755 
1757 {
1759 
1760  /* identifiers */
1761  ot->name = "Set Object Mode with Submode";
1762  ot->idname = "OBJECT_OT_mode_set_with_submode";
1763 
1764  /* properties */
1765  /* we could add other types - particle for eg. */
1766  PropertyRNA *prop;
1767  prop = RNA_def_enum_flag(
1768  ot->srna, "mesh_select_mode", rna_enum_mesh_select_mode_items, 0, "Mesh Mode", "");
1770 }
1771 
1774 /* -------------------------------------------------------------------- */
1779 {
1780  ListBase objects = {NULL};
1781 
1782  if (CTX_wm_space_outliner(C) != NULL) {
1784  }
1785  else {
1786  CTX_DATA_BEGIN (C, Object *, ob, selected_objects) {
1788  }
1789  CTX_DATA_END;
1790  }
1791 
1792  return objects;
1793 }
1794 
1796 {
1797  if (CTX_wm_space_outliner(C) != NULL) {
1799  }
1800 
1801  View3D *v3d = CTX_wm_view3d(C);
1802 
1803  if (v3d && v3d->localvd) {
1804  return false;
1805  }
1806 
1807  return ED_operator_objectmode(C);
1808 }
1809 
1811 {
1812  Main *bmain = CTX_data_main(C);
1814  PropertyRNA *prop = RNA_struct_find_property(op->ptr, "collection_index");
1815  const bool is_link = STREQ(op->idname, "OBJECT_OT_link_to_collection");
1816  const bool is_new = RNA_boolean_get(op->ptr, "is_new");
1817 
1818  if (!RNA_property_is_set(op->ptr, prop)) {
1819  BKE_report(op->reports, RPT_ERROR, "No collection selected");
1820  return OPERATOR_CANCELLED;
1821  }
1822 
1823  int collection_index = RNA_property_int_get(op->ptr, prop);
1824  Collection *collection = BKE_collection_from_index(scene, collection_index);
1825  if (collection == NULL) {
1826  BKE_report(op->reports, RPT_ERROR, "Unexpected error, collection not found");
1827  return OPERATOR_CANCELLED;
1828  }
1829 
1831 
1832  if (is_new) {
1833  char new_collection_name[MAX_NAME];
1834  RNA_string_get(op->ptr, "new_collection_name", new_collection_name);
1835  collection = BKE_collection_add(bmain, collection, new_collection_name);
1836  }
1837 
1838  Object *single_object = BLI_listbase_is_single(&objects) ? ((LinkData *)objects.first)->data :
1839  NULL;
1840 
1841  if ((single_object != NULL) && is_link &&
1842  BLI_findptr(&collection->gobject, single_object, offsetof(CollectionObject, ob))) {
1843  BKE_reportf(op->reports,
1844  RPT_ERROR,
1845  "%s already in %s",
1846  single_object->id.name + 2,
1847  collection->id.name + 2);
1849  return OPERATOR_CANCELLED;
1850  }
1851 
1852  LISTBASE_FOREACH (LinkData *, link, &objects) {
1853  Object *ob = link->data;
1854 
1855  if (!is_link) {
1856  BKE_collection_object_move(bmain, scene, collection, NULL, ob);
1857  }
1858  else {
1859  BKE_collection_object_add(bmain, collection, ob);
1860  }
1861  }
1863 
1864  BKE_reportf(op->reports,
1865  RPT_INFO,
1866  "%s %s to %s",
1867  (single_object != NULL) ? single_object->id.name + 2 : "Objects",
1868  is_link ? "linked" : "moved",
1869  collection->id.name + 2);
1870 
1871  DEG_relations_tag_update(bmain);
1873 
1877 
1878  return OPERATOR_FINISHED;
1879 }
1880 
1883  int index;
1885  struct ListBase submenus;
1888 };
1889 
1891 {
1892  int index = menu->index;
1893  LISTBASE_FOREACH (CollectionChild *, child, &menu->collection->children) {
1894  Collection *collection = child->collection;
1895  MoveToCollectionData *submenu = MEM_callocN(sizeof(MoveToCollectionData), __func__);
1896  BLI_addtail(&menu->submenus, submenu);
1897  submenu->collection = collection;
1898  submenu->index = ++index;
1899  index = move_to_collection_menus_create(op, submenu);
1900  submenu->ot = op->type;
1901  }
1902  return index;
1903 }
1904 
1906 {
1907  LISTBASE_FOREACH (MoveToCollectionData *, submenu, &menu->submenus) {
1909  }
1910  BLI_freelistN(&menu->submenus);
1911 }
1912 
1914 {
1915  if (*menu == NULL) {
1916  return;
1917  }
1918 
1920  MEM_freeN(*menu);
1921  *menu = NULL;
1922 }
1923 
1924 static void move_to_collection_menu_create(bContext *C, uiLayout *layout, void *menu_v)
1925 {
1926  MoveToCollectionData *menu = menu_v;
1927  const char *name = BKE_collection_ui_name_get(menu->collection);
1928 
1930 
1931  WM_operator_properties_create_ptr(&menu->ptr, menu->ot);
1932  RNA_int_set(&menu->ptr, "collection_index", menu->index);
1933  RNA_boolean_set(&menu->ptr, "is_new", true);
1934 
1936  layout, menu->ot, "New Collection", ICON_ADD, menu->ptr.data, WM_OP_INVOKE_DEFAULT, 0, NULL);
1937 
1938  uiItemS(layout);
1939 
1941  const int icon = (menu->collection == scene->master_collection) ?
1942  ICON_SCENE_DATA :
1944  uiItemIntO(layout, name, icon, menu->ot->idname, "collection_index", menu->index);
1945 
1946  LISTBASE_FOREACH (MoveToCollectionData *, submenu, &menu->submenus) {
1947  move_to_collection_menus_items(layout, submenu);
1948  }
1949 }
1950 
1952 {
1953  const int icon = UI_icon_color_from_collection(menu->collection);
1954 
1955  if (BLI_listbase_is_empty(&menu->submenus)) {
1956  uiItemIntO(layout,
1957  menu->collection->id.name + 2,
1958  icon,
1959  menu->ot->idname,
1960  "collection_index",
1961  menu->index);
1962  }
1963  else {
1964  uiItemMenuF(layout, menu->collection->id.name + 2, icon, move_to_collection_menu_create, menu);
1965  }
1966 }
1967 
1968 /* This is allocated statically because we need this available for the menus creation callback. */
1970 
1972 {
1974 
1975  ListBase objects = selected_objects_get(C);
1976  if (BLI_listbase_is_empty(&objects)) {
1977  BKE_report(op->reports, RPT_ERROR, "No objects selected");
1978  return OPERATOR_CANCELLED;
1979  }
1980  BLI_freelistN(&objects);
1981 
1982  /* Reset the menus data for the current master collection, and free previously allocated data. */
1984 
1985  PropertyRNA *prop;
1986  prop = RNA_struct_find_property(op->ptr, "collection_index");
1987  if (RNA_property_is_set(op->ptr, prop)) {
1988  int collection_index = RNA_property_int_get(op->ptr, prop);
1989 
1990  if (RNA_boolean_get(op->ptr, "is_new")) {
1991  prop = RNA_struct_find_property(op->ptr, "new_collection_name");
1992  if (!RNA_property_is_set(op->ptr, prop)) {
1993  char name[MAX_NAME];
1994  Collection *collection;
1995 
1996  collection = BKE_collection_from_index(scene, collection_index);
1997  BKE_collection_new_name_get(collection, name);
1998 
2000  return WM_operator_props_dialog_popup(C, op, 200);
2001  }
2002  }
2003  return move_to_collection_exec(C, op);
2004  }
2005 
2006  Collection *master_collection = scene->master_collection;
2007 
2008  /* We need the data to be allocated so it's available during menu drawing.
2009  * Technically we could use #wmOperator.customdata. However there is no free callback
2010  * called to an operator that exit with OPERATOR_INTERFACE to launch a menu.
2011  *
2012  * So we are left with a memory that will necessarily leak. It's a small leak though.*/
2013  if (master_collection_menu == NULL) {
2015  "MoveToCollectionData menu - expected eventual memleak");
2016  }
2017 
2018  master_collection_menu->collection = master_collection;
2021 
2022  uiPopupMenu *pup;
2023  uiLayout *layout;
2024 
2025  /* Build the menus. */
2026  const char *title = CTX_IFACE_(op->type->translation_context, op->type->name);
2027  pup = UI_popup_menu_begin(C, title, ICON_NONE);
2028  layout = UI_popup_menu_layout(pup);
2029 
2031 
2033 
2034  UI_popup_menu_end(C, pup);
2035 
2036  return OPERATOR_INTERFACE;
2037 }
2038 
2040 {
2041  PropertyRNA *prop;
2042 
2043  /* identifiers */
2044  ot->name = "Move to Collection";
2045  ot->description = "Move objects to a collection";
2046  ot->idname = "OBJECT_OT_move_to_collection";
2047 
2048  /* api callbacks */
2052 
2053  /* flags */
2055 
2056  prop = RNA_def_int(ot->srna,
2057  "collection_index",
2060  INT_MAX,
2061  "Collection Index",
2062  "Index of the collection to move to",
2063  0,
2064  INT_MAX);
2066  prop = RNA_def_boolean(ot->srna, "is_new", false, "New", "Move objects to a new collection");
2069  "new_collection_name",
2070  NULL,
2071  MAX_NAME,
2072  "Name",
2073  "Name of the newly added collection");
2075  ot->prop = prop;
2076 }
2077 
2079 {
2080  PropertyRNA *prop;
2081 
2082  /* identifiers */
2083  ot->name = "Link to Collection";
2084  ot->description = "Link objects to a collection";
2085  ot->idname = "OBJECT_OT_link_to_collection";
2086 
2087  /* api callbacks */
2091 
2092  /* flags */
2094 
2095  prop = RNA_def_int(ot->srna,
2096  "collection_index",
2099  INT_MAX,
2100  "Collection Index",
2101  "Index of the collection to move to",
2102  0,
2103  INT_MAX);
2105  prop = RNA_def_boolean(ot->srna, "is_new", false, "New", "Move objects to a new collection");
2108  "new_collection_name",
2109  NULL,
2110  MAX_NAME,
2111  "Name",
2112  "Name of the newly added collection");
2114  ot->prop = prop;
2115 }
2116 
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, const bool do_id_user)
Definition: armature.c:2518
struct Collection * BKE_collection_add(struct Main *bmain, struct Collection *parent, const char *name)
Definition: collection.c:435
const char * BKE_collection_ui_name_get(struct Collection *collection)
Definition: collection.c:776
bool BKE_collection_object_add(struct Main *bmain, struct Collection *collection, struct Object *ob)
Definition: collection.c:1134
void BKE_collection_new_name_get(struct Collection *collection_parent, char *rname)
Definition: collection.c:751
struct Collection * BKE_collection_from_index(struct Scene *scene, const int index)
Definition: collection.c:1734
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:1367
struct ScrArea * CTX_wm_area(const bContext *C)
Definition: context.c:714
struct Scene * CTX_data_scene(const bContext *C)
Definition: context.c:1034
struct Object * CTX_data_edit_object(const bContext *C)
Definition: context.c:1296
struct Base * CTX_data_active_base(const bContext *C)
Definition: context.c:1284
struct SpaceOutliner * CTX_wm_space_outliner(const bContext *C)
Definition: context.c:836
#define CTX_DATA_BEGIN(C, Type, instance, member)
Definition: BKE_context.h:252
PointerRNA CTX_data_pointer_get_type(const bContext *C, const char *member, StructRNA *type)
Definition: context.c:456
struct ViewLayer * CTX_data_view_layer(const bContext *C)
Definition: context.c:1044
struct Depsgraph * CTX_data_ensure_evaluated_depsgraph(const bContext *C)
Definition: context.c:1424
struct Object * CTX_data_active_object(const bContext *C)
Definition: context.c:1279
struct View3D * CTX_wm_view3d(const bContext *C)
Definition: context.c:760
struct wmMsgBus * CTX_wm_message_bus(const bContext *C)
Definition: context.c:746
int CTX_data_selected_editable_objects(const bContext *C, ListBase *list)
Definition: context.c:1229
struct Main * CTX_data_main(const bContext *C)
Definition: context.c:1018
#define CTX_DATA_END
Definition: BKE_context.h:260
struct wmWindow * CTX_wm_window(const bContext *C)
Definition: context.c:699
void BKE_curve_smooth_flag_set(struct Curve *cu, const bool use_smooth)
Definition: curve.c:5532
void BKE_editlattice_load(struct Object *obedit)
Definition: editlattice.c:84
void BKE_editlattice_make(struct Object *obedit)
Definition: editlattice.c:58
void BKE_editlattice_free(struct Object *ob)
Definition: editlattice.c:38
void BKE_editmesh_looptri_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:85
struct PartDeflect * BKE_partdeflect_new(int type)
Definition: effect.c:86
#define FOREACH_SELECTED_OBJECT_BEGIN(_view_layer, _v3d, _instance)
Definition: BKE_layer.h:200
#define BKE_view_layer_array_selected_objects(view_layer, v3d, r_len,...)
Definition: BKE_layer.h:383
void BKE_layer_collection_local_sync(struct ViewLayer *view_layer, const struct View3D *v3d)
#define FOREACH_OBJECT_END
Definition: BKE_layer.h:331
struct LayerCollection * BKE_layer_collection_from_index(struct ViewLayer *view_layer, const int index)
Definition: layer.c:621
bool BKE_layer_collection_has_selected_objects(struct ViewLayer *view_layer, struct LayerCollection *lc)
Definition: layer.c:1067
void BKE_layer_collection_isolate_global(struct Scene *scene, struct ViewLayer *view_layer, struct LayerCollection *lc, bool extend)
Definition: layer.c:1206
#define FOREACH_OBJECT_BEGIN(view_layer, _instance)
Definition: BKE_layer.h:324
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:213
#define BKE_view_layer_array_from_objects_in_mode(view_layer, v3d, r_len,...)
Definition: BKE_layer.h:407
void BKE_layer_collection_isolate_local(struct ViewLayer *view_layer, const struct View3D *v3d, struct LayerCollection *lc, bool extend)
General operations, lookup, etc. for materials.
void BKE_mesh_batch_cache_dirty_tag(struct Mesh *me, eMeshBatchDirtyMode mode)
Definition: mesh_runtime.c:251
void BKE_mesh_smooth_flag_set(struct Mesh *me, const bool use_smooth)
Definition: mesh.c:1392
@ 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.c:1893
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:1278
#define PTCACHE_TYPE_PARTICLES
#define PTCACHE_RESET_OUTDATED
int BKE_ptcache_object_reset(struct Scene *scene, struct Object *ob, int mode)
Definition: pointcache.c:2953
void BKE_report(ReportList *reports, ReportType type, const char *message)
Definition: report.c:104
void BKE_reportf(ReportList *reports, ReportType type, const char *format,...) ATTR_PRINTF_FORMAT(3
void BKE_scene_object_base_flag_sync_from_base(struct Base *base)
Definition: scene.c:2966
#define BLI_assert(a)
Definition: BLI_assert.h:58
BLI_INLINE bool BLI_listbase_is_empty(const struct ListBase *lb)
Definition: BLI_listbase.h:124
#define LISTBASE_FOREACH(type, var, list)
Definition: BLI_listbase.h:172
struct LinkData * BLI_genericNodeN(void *data)
Definition: listbase.c:923
void void BLI_freelistN(struct ListBase *listbase) ATTR_NONNULL(1)
Definition: listbase.c:547
void void BLI_INLINE bool BLI_listbase_is_single(const struct ListBase *lb)
Definition: BLI_listbase.h:120
void BLI_addtail(struct ListBase *listbase, void *vlink) ATTR_NONNULL(1)
Definition: listbase.c:110
void * BLI_findptr(const struct ListBase *listbase, const void *ptr, const int offset) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
unsigned int uint
Definition: BLI_sys_types.h:83
#define UNUSED(x)
#define UNLIKELY(x)
#define ELEM(...)
#define STREQ(a, b)
#define LIKELY(x)
#define CTX_IFACE_(context, msgid)
#define CLOG_WARN(clg_ref,...)
Definition: CLG_log.h:203
struct Depsgraph Depsgraph
Definition: DEG_depsgraph.h:51
void DEG_graph_free(Depsgraph *graph)
Definition: depsgraph.cc:314
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:599
@ ID_RECALC_COPY_ON_WRITE
Definition: DNA_ID.h:654
@ ID_RECALC_SELECT
Definition: DNA_ID.h:638
@ ID_RECALC_ANIMATION
Definition: DNA_ID.h:614
@ ID_RECALC_GEOMETRY
Definition: DNA_ID.h:611
@ ID_RECALC_BASE_FLAGS
Definition: DNA_ID.h:641
@ LIB_TAG_DOIT
Definition: DNA_ID.h:554
#define ID_IS_LINKED(_id)
Definition: DNA_ID.h:426
#define ID_IS_OVERRIDE_LIBRARY(_id)
Definition: DNA_ID.h:445
@ ID_OB
Definition: DNA_ID_enums.h:59
@ MOTIONPATH_BAKE_HAS_PATHS
@ ANIMVIZ_RECALC_PATHS
Object groups, one object can be in many groups at once.
@ COLLECTION_RESTRICT_VIEWPORT
#define MAX_NAME
Definition: DNA_defs.h:62
@ LAYER_COLLECTION_EXCLUDE
@ BASE_HIDDEN
@ BASE_VISIBLE_VIEWLAYER
@ BASE_SELECTED
@ LAYER_COLLECTION_RESTRICT_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_VERTEX_GPENCIL
@ OB_MODE_EDIT_GPENCIL
@ OB_MODE_PARTICLE_EDIT
@ OB_MODE_EDIT
@ OB_MODE_WEIGHT_PAINT
@ OB_MODE_WEIGHT_GPENCIL
@ OB_MODE_SCULPT
@ OB_MODE_SCULPT_GPENCIL
@ OB_MODE_POSE
@ OB_MODE_TEXTURE_PAINT
@ OB_MODE_OBJECT
@ OB_MODE_VERTEX_PAINT
@ OB_MODE_PAINT_GPENCIL
#define OB_MODE_ALL_SCULPT
#define PFIELD_SHAPE_SURFACE
@ PFIELD_FORCE
@ PFIELD_GUIDE
@ PFIELD_TEXTURE
Object is a sort of wrapper for general info.
@ PARVERT1
@ PARVERT3
@ OB_LATTICE
@ OB_MBALL
@ OB_SURF
@ OB_FONT
@ OB_ARMATURE
@ OB_MESH
@ OB_CURVE
@ OB_GPENCIL
@ OB_RESTRICT_VIEWPORT
#define OB_TYPE_SUPPORT_EDITMODE(_type)
#define PTCACHE_OUTDATED
#define OBEDIT_FROM_VIEW_LAYER(view_layer)
#define MINFRAME
#define MINAFRAME
#define PSFRA
#define OBACT(_view_layer)
#define PEFRA
#define MAXFRAME
@ 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:873
@ ANIMVIZ_CALC_RANGE_FULL
Definition: ED_anim_api.h:881
@ ANIMVIZ_CALC_RANGE_CURRENT_FRAME
Definition: ED_anim_api.h:875
@ ANIMVIZ_CALC_RANGE_CHANGED
Definition: ED_anim_api.h:878
void ED_mball_editmball_free(struct Object *obedit)
Definition: mball_edit.c:66
void ED_mball_editmball_make(struct Object *obedit)
Definition: mball_edit.c:76
void ED_mball_editmball_load(struct Object *obedit)
void ED_mesh_mirror_topo_table_end(struct Object *ob)
void EDBM_mesh_make(struct Object *ob, const int select_mode, const bool add_key_index)
bool EDBM_selectmode_set_multi(struct bContext *C, const short selectmode)
void EDBM_mesh_load_ex(struct Main *bmain, struct Object *ob, bool free_data)
void EDBM_mesh_free(struct BMEditMesh *em)
void ED_mesh_mirror_spatial_table_end(struct Object *ob)
void EDBM_mesh_normals_update(struct BMEditMesh *em)
bool ED_object_particle_edit_mode_supported(const Object *ob)
struct ModifierData * ED_object_modifier_add(struct ReportList *reports, struct Main *bmain, struct Scene *scene, struct Object *ob, const char *name, int type)
bool ED_object_mode_set_ex(struct bContext *C, eObjectMode mode, bool use_undo, struct ReportList *reports)
Definition: object_modes.c:195
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:98
@ EM_NO_CONTEXT
Definition: ED_object.h:205
@ EM_FREEDATA
Definition: ED_object.h:204
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:328
@ OBJECT_PATH_CALC_RANGE_CHANGED
Definition: ED_object.h:330
@ OBJECT_PATH_CALC_RANGE_CURRENT_FRAME
Definition: ED_object.h:329
@ OBJECT_PATH_CALC_RANGE_FULL
Definition: ED_object.h:331
@ BA_DESELECT
Definition: ED_object.h:146
bool ED_object_mode_compat_set(struct bContext *C, struct Object *ob, eObjectMode mode, struct ReportList *reports)
Definition: object_modes.c:165
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)
bool ED_operator_object_active_editable(struct bContext *C)
Definition: screen_ops.c:366
bool ED_operator_view3d_active(struct bContext *C)
Definition: screen_ops.c:230
bool ED_operator_objectmode(struct bContext *C)
Definition: screen_ops.c:201
Contains defines and structs used throughout the imbuf module.
Read Guarded memory(de)allocation.
StructRNA RNA_Object
@ PROP_SKIP_SAVE
Definition: RNA_types.h:204
@ PROP_HIDDEN
Definition: RNA_types.h:202
#define C
Definition: RandGen.cpp:39
uiBlock * uiLayoutGetBlock(uiLayout *layout)
void uiLayoutSetOperatorContext(uiLayout *layout, int opcontext)
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)
void uiItemFullO_ptr(uiLayout *layout, struct wmOperatorType *ot, const char *name, int icon, struct IDProperty *properties, int context, int flag, struct PointerRNA *r_opptr)
uiLayout * uiLayoutRow(uiLayout *layout, bool align)
@ UI_BLOCK_IS_FLIP
Definition: UI_interface.h:141
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.c:6067
uiPopupMenu * UI_popup_menu_begin(struct bContext *C, const char *title, int icon) ATTR_NONNULL()
int UI_icon_color_from_collection(const struct Collection *collection)
#define NS_EDITMODE_MESH
Definition: WM_types.h:443
#define NS_EDITMODE_TEXT
Definition: WM_types.h:446
#define ND_DRAW
Definition: WM_types.h:362
#define ND_OB_ACTIVE
Definition: WM_types.h:340
@ OPTYPE_UNDO
Definition: WM_types.h:155
@ OPTYPE_REGISTER
Definition: WM_types.h:153
@ WM_OP_EXEC_REGION_WIN
Definition: WM_types.h:205
@ WM_OP_INVOKE_DEFAULT
Definition: WM_types.h:197
#define ND_MODE
Definition: WM_types.h:345
#define ND_OB_SELECT
Definition: WM_types.h:342
#define NC_SCENE
Definition: WM_types.h:279
#define NS_EDITMODE_ARMATURE
Definition: WM_types.h:449
#define ND_OB_VISIBLE
Definition: WM_types.h:343
#define ND_LAYER_CONTENT
Definition: WM_types.h:354
#define ND_MODIFIER
Definition: WM_types.h:363
#define NS_MODE_OBJECT
Definition: WM_types.h:441
#define NS_EDITMODE_MBALL
Definition: WM_types.h:447
#define ND_TRANSFORM
Definition: WM_types.h:357
#define NS_EDITMODE_LATTICE
Definition: WM_types.h:448
#define ND_LAYER
Definition: WM_types.h:350
#define NC_OBJECT
Definition: WM_types.h:280
#define NS_EDITMODE_CURVE
Definition: WM_types.h:444
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 ED_armature_edit_free(struct bArmature *arm)
void ED_armature_from_edit(Main *bmain, bArmature *arm)
void ED_armature_to_edit(bArmature *arm)
Scene scene
const Depsgraph * depsgraph
void * user_data
void ED_curve_editnurb_make(Object *obedit)
Definition: editcurve.c:1289
void ED_curve_editnurb_free(Object *obedit)
Definition: editcurve.c:1334
void ED_curve_editnurb_load(Main *bmain, Object *obedit)
Definition: editcurve.c:1251
void ED_curve_editfont_make(Object *obedit)
Definition: editfont.c:1874
void ED_curve_editfont_load(Object *obedit)
Definition: editfont.c:1910
void ED_curve_editfont_free(Object *obedit)
Definition: editfont.c:1940
#define GS(x)
Definition: iris.c:241
void(* MEM_freeN)(void *vmemh)
Definition: mallocn.c:41
void *(* MEM_callocN)(size_t len, const char *str)
Definition: mallocn.c:45
void *(* MEM_mallocN)(size_t len, const char *str)
Definition: mallocn.c:47
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:1050
bool ED_object_editmode_exit_ex(Main *bmain, Scene *scene, Object *obedit, int flag)
Definition: object_edit.c:676
static int posemode_exec(bContext *C, wmOperator *op)
Definition: object_edit.c:960
void OBJECT_OT_move_to_collection(wmOperatorType *ot)
Definition: object_edit.c:2039
void OBJECT_OT_mode_set_with_submode(wmOperatorType *ot)
Definition: object_edit.c:1756
void ED_objects_clear_paths(bContext *C, bool only_selected)
Definition: object_edit.c:1346
static int shade_smooth_exec(bContext *C, wmOperator *op)
Definition: object_edit.c:1454
void OBJECT_OT_hide_view_clear(wmOperatorType *ot)
Definition: object_edit.c:285
Object * ED_object_active_context(const bContext *C)
Definition: object_edit.c:139
bool ED_object_editmode_free_ex(Main *bmain, Object *obedit)
Definition: object_edit.c:731
static int move_to_collection_menus_create(wmOperator *op, MoveToCollectionData *menu)
Definition: object_edit.c:1890
static bool shade_poll(bContext *C)
Definition: object_edit.c:1530
void OBJECT_OT_hide_collection(wmOperatorType *ot)
Definition: object_edit.c:465
static void move_to_collection_menus_free(MoveToCollectionData **menu)
Definition: object_edit.c:1913
static int object_clear_paths_exec(bContext *C, wmOperator *op)
Definition: object_edit.c:1365
bool ED_object_editmode_exit_multi_ex(Main *bmain, Scene *scene, ViewLayer *view_layer, int flag)
Definition: object_edit.c:736
static eAnimvizCalcRange object_path_convert_range(eObjectPathCalcRange range)
Definition: object_edit.c:1117
void OBJECT_OT_paths_update(wmOperatorType *ot)
Definition: object_edit.c:1311
bool ED_object_editmode_enter_ex(Main *bmain, Scene *scene, Object *ob, int flag)
Definition: object_edit.c:762
void OBJECT_OT_paths_range_update(wmOperatorType *ot)
Definition: object_edit.c:1433
static bool object_update_paths_poll(bContext *C)
Definition: object_edit.c:1284
void OBJECT_OT_posemode_toggle(wmOperatorType *ot)
Definition: object_edit.c:1029
static ListBase selected_objects_get(bContext *C)
Definition: object_edit.c:1778
static int object_hide_view_clear_exec(bContext *C, wmOperator *op)
Definition: object_edit.c:252
static int move_to_collection_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event))
Definition: object_edit.c:1971
void OBJECT_OT_link_to_collection(wmOperatorType *ot)
Definition: object_edit.c:2078
static const EnumPropertyItem * object_mode_set_itemsf(bContext *C, PointerRNA *UNUSED(ptr), PropertyRNA *UNUSED(prop), bool *r_free)
Definition: object_edit.c:1580
static int object_mode_set_exec(bContext *C, wmOperator *op)
Definition: object_edit.c:1638
static int move_to_collection_exec(bContext *C, wmOperator *op)
Definition: object_edit.c:1810
static bool object_hide_poll(bContext *C)
Definition: object_edit.c:244
static int forcefield_toggle_exec(bContext *C, wmOperator *UNUSED(op))
Definition: object_edit.c:1072
void OBJECT_OT_hide_view_set(wmOperatorType *ot)
Definition: object_edit.c:343
Object ** ED_object_array_in_mode_or_selected(bContext *C, bool(*filter_fn)(Object *ob, void *user_data), void *filter_user_data, uint *r_objects_len)
Definition: object_edit.c:159
void OBJECT_OT_paths_clear(wmOperatorType *ot)
Definition: object_edit.c:1387
void OBJECT_OT_forcefield_toggle(wmOperatorType *ot)
Definition: object_edit.c:1095
static int object_hide_view_set_exec(bContext *C, wmOperator *op)
Definition: object_edit.c:303
static int object_clear_paths_invoke(bContext *C, wmOperator *op, const wmEvent *event)
Definition: object_edit.c:1379
bool ED_object_editmode_enter(bContext *C, int flag)
Definition: object_edit.c:859
static int editmode_toggle_exec(bContext *C, wmOperator *op)
Definition: object_edit.c:870
static bool object_mode_set_poll(bContext *C)
Definition: object_edit.c:1631
static MoveToCollectionData * master_collection_menu
Definition: object_edit.c:1969
void ED_collection_hide_menu_draw(const bContext *C, uiLayout *layout)
Definition: object_edit.c:409
void OBJECT_OT_editmode_toggle(wmOperatorType *ot)
Definition: object_edit.c:938
static int object_calculate_paths_exec(bContext *C, wmOperator *op)
Definition: object_edit.c:1214
bool ED_object_editmode_load(Main *bmain, Object *obedit)
Definition: object_edit.c:667
void OBJECT_OT_shade_flat(wmOperatorType *ot)
Definition: object_edit.c:1544
static bool mesh_needs_keyindex(Main *bmain, const Mesh *me)
Definition: object_edit.c:502
static bool ED_object_editmode_load_free_ex(Main *bmain, Object *obedit, const bool load_data, const bool free_data)
Definition: object_edit.c:529
static int object_update_paths_exec(bContext *C, wmOperator *UNUSED(op))
Definition: object_edit.c:1294
static int object_update_paths_range_exec(bContext *C, wmOperator *UNUSED(op))
Definition: object_edit.c:1414
#define COLLECTION_INVALID_INDEX
Definition: object_edit.c:407
void OBJECT_OT_shade_smooth(wmOperatorType *ot)
Definition: object_edit.c:1559
bool ED_object_editmode_exit(bContext *C, int flag)
Definition: object_edit.c:718
static CLG_LogRef LOG
Definition: object_edit.c:120
static int object_hide_collection_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event))
Definition: object_edit.c:445
Object * ED_object_context(const bContext *C)
Definition: object_edit.c:132
static void move_to_collection_menus_items(struct uiLayout *layout, struct MoveToCollectionData *menu)
Definition: object_edit.c:1951
static bool editmode_toggle_poll(bContext *C)
Definition: object_edit.c:920
static bool move_to_collection_poll(bContext *C)
Definition: object_edit.c:1795
void ED_objects_recalculate_paths(bContext *C, Scene *scene, eObjectPathCalcRange range)
Definition: object_edit.c:1135
static void move_to_collection_menu_create(bContext *C, uiLayout *layout, void *menu_v)
Definition: object_edit.c:1924
void OBJECT_OT_paths_calculate(wmOperatorType *ot)
Definition: object_edit.c:1242
static void move_to_collection_menus_free_recursive(MoveToCollectionData *menu)
Definition: object_edit.c:1905
void OBJECT_OT_mode_set(wmOperatorType *ot)
Definition: object_edit.c:1731
static int object_calculate_paths_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event))
Definition: object_edit.c:1192
bool ED_object_editmode_exit_multi(bContext *C, int flag)
Definition: object_edit.c:754
static void object_clear_mpath(Object *ob)
Definition: object_edit.c:1333
static int object_hide_collection_exec(bContext *C, wmOperator *op)
Definition: object_edit.c:363
bool ED_object_posemode_enter(bContext *C, Object *ob)
Definition: pose_edit.c:114
bool ED_object_posemode_enter_ex(struct Main *bmain, Object *ob)
Definition: pose_edit.c:94
bool ED_object_posemode_exit_ex(struct Main *bmain, Object *ob)
Definition: pose_edit.c:129
bool ED_object_posemode_exit(bContext *C, Object *ob)
Definition: pose_edit.c:142
void RNA_boolean_set(PointerRNA *ptr, const char *name, bool value)
Definition: rna_access.c:6272
bool RNA_property_is_set(PointerRNA *ptr, PropertyRNA *prop)
Definition: rna_access.c:6655
void RNA_int_set(PointerRNA *ptr, const char *name, int value)
Definition: rna_access.c:6319
PropertyRNA * RNA_struct_find_property(PointerRNA *ptr, const char *identifier)
Definition: rna_access.c:866
int RNA_property_int_get(PointerRNA *ptr, PropertyRNA *prop)
Definition: rna_access.c:2607
void RNA_string_get(PointerRNA *ptr, const char *name, char *value)
Definition: rna_access.c:6514
int RNA_int_get(PointerRNA *ptr, const char *name)
Definition: rna_access.c:6308
int RNA_property_enum_get(PointerRNA *ptr, PropertyRNA *prop)
Definition: rna_access.c:3543
bool RNA_struct_property_is_set(PointerRNA *ptr, const char *identifier)
Definition: rna_access.c:6685
bool RNA_boolean_get(PointerRNA *ptr, const char *name)
Definition: rna_access.c:6261
int RNA_enum_get(PointerRNA *ptr, const char *name)
Definition: rna_access.c:6402
void RNA_property_string_set(PointerRNA *ptr, PropertyRNA *prop, const char *value)
Definition: rna_access.c:3401
PropertyRNA * RNA_def_boolean(StructOrFunctionRNA *cont_, const char *identifier, bool default_value, const char *ui_name, const char *ui_description)
Definition: rna_define.c:3481
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:3795
void RNA_enum_item_end(EnumPropertyItem **items, int *totitem)
Definition: rna_define.c:4470
void RNA_enum_item_add(EnumPropertyItem **items, int *totitem, const EnumPropertyItem *item)
Definition: rna_define.c:4416
PropertyRNA * RNA_def_string(StructOrFunctionRNA *cont_, const char *identifier, const char *default_value, int maxlen, const char *ui_name, const char *ui_description)
Definition: rna_define.c:3675
void RNA_def_property_flag(PropertyRNA *prop, PropertyFlag flag)
Definition: rna_define.c:1512
PropertyRNA * RNA_def_int(StructOrFunctionRNA *cont_, const char *identifier, int default_value, int hardmin, int hardmax, const char *ui_name, const char *ui_description, int softmin, int softmax)
Definition: rna_define.c:3585
void RNA_def_enum_funcs(PropertyRNA *prop, EnumPropertyItemFunc itemfunc)
Definition: rna_define.c:3819
void RNA_enum_items_add_value(EnumPropertyItem **items, int *totitem, const EnumPropertyItem *item, int value)
Definition: rna_define.c:4455
PropertyRNA * RNA_def_enum(StructOrFunctionRNA *cont_, const char *identifier, const EnumPropertyItem *items, int default_value, const char *ui_name, const char *ui_description)
Definition: rna_define.c:3771
const EnumPropertyItem rna_enum_object_mode_items[]
Definition: rna_object.c:65
const EnumPropertyItem rna_enum_mesh_select_mode_items[]
Definition: rna_scene.c:143
struct BMesh * bm
Definition: BKE_editmesh.h:52
int totvert
Definition: bmesh_class.h:297
struct Object * object
struct EditFont * editfont
EditNurb * editnurb
const char * identifier
Definition: RNA_types.h:446
Definition: DNA_ID.h:273
char name[66]
Definition: DNA_ID.h:283
struct EditLatt * editlatt
ListBase layer_collections
unsigned short local_collections_bits
void * first
Definition: DNA_listBase.h:47
Definition: BKE_main.h:116
ListBase objects
Definition: BKE_main.h:148
struct BMEditMesh * edit_mesh
struct Key * key
ListBase * editelems
char needs_flush_to_id
struct wmOperatorType * ot
Definition: object_edit.c:1887
struct MoveToCollectionData * prev
Definition: object_edit.c:1882
struct ListBase submenus
Definition: object_edit.c:1885
struct MoveToCollectionData * next
Definition: object_edit.c:1882
struct Collection * collection
Definition: object_edit.c:1884
int restore_mode
struct bPose * pose
struct PartDeflect * pd
bMotionPath * mpath
void * data
char restrictflag
bAnimVizSettings avs
void * data
Definition: RNA_types.h:52
struct Collection * master_collection
struct ToolSettings * toolsettings
struct View3D * localvd
unsigned short local_collections_uuid
ListBase layer_collections
ListBase object_bases
ListBase * edbo
short shift
Definition: WM_types.h:618
short alt
Definition: WM_types.h:618
int(* invoke)(struct bContext *, struct wmOperator *, const struct wmEvent *) ATTR_WARN_UNUSED_RESULT
Definition: WM_types.h:752
const char * name
Definition: WM_types.h:721
const char * idname
Definition: WM_types.h:723
bool(* poll)(struct bContext *) ATTR_WARN_UNUSED_RESULT
Definition: WM_types.h:776
struct StructRNA * srna
Definition: WM_types.h:802
const char * translation_context
Definition: WM_types.h:724
const char * description
Definition: WM_types.h:726
int(* exec)(struct bContext *, struct wmOperator *) ATTR_WARN_UNUSED_RESULT
Definition: WM_types.h:736
PropertyRNA * prop
Definition: WM_types.h:814
struct ReportList * reports
struct wmOperatorType * type
struct PointerRNA * ptr
struct wmEvent * eventstate
__forceinline const avxb select(const avxb &m, const avxb &t, const avxb &f)
Definition: util_avxb.h:167
#define G(x, y, z)
void WM_main_add_notifier(unsigned int type, void *reference)
void WM_event_add_notifier(const bContext *C, uint type, void *reference)
PointerRNA * ptr
Definition: wm_files.c:3157
wmOperatorType * ot
Definition: wm_files.c:3156
#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:584
int WM_operator_props_dialog_popup(bContext *C, wmOperator *op, int width)
void WM_toolsystem_update_from_context_view3d(bContext *C)