Blender  V3.3
layer_utils.c
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 
7 #include <string.h>
8 
9 #include "BLI_array.h"
10 
11 #include "BKE_collection.h"
12 #include "BKE_customdata.h"
13 #include "BKE_editmesh.h"
14 #include "BKE_layer.h"
15 
16 #include "DNA_ID.h"
17 #include "DNA_layer_types.h"
18 #include "DNA_mesh_types.h"
19 #include "DNA_object_types.h"
20 #include "DNA_scene_types.h"
21 
22 #include "MEM_guardedalloc.h"
23 
24 /* -------------------------------------------------------------------- */
29  struct ViewLayer *view_layer,
30  const struct View3D *v3d,
31  uint *r_len,
32  const struct ObjectsInViewLayerParams *params)
33 {
34  if (params->no_dup_data) {
35  FOREACH_SELECTED_OBJECT_BEGIN (view_layer, v3d, ob_iter) {
36  ID *id = ob_iter->data;
37  if (id) {
38  id->tag |= LIB_TAG_DOIT;
39  }
40  }
42  }
43 
44  Object **object_array = NULL;
45  BLI_array_declare(object_array);
46 
47  FOREACH_SELECTED_OBJECT_BEGIN (view_layer, v3d, ob_iter) {
48  if (params->filter_fn) {
49  if (!params->filter_fn(ob_iter, params->filter_userdata)) {
50  continue;
51  }
52  }
53 
54  if (params->no_dup_data) {
55  ID *id = ob_iter->data;
56  if (id) {
57  if (id->tag & LIB_TAG_DOIT) {
58  id->tag &= ~LIB_TAG_DOIT;
59  }
60  else {
61  continue;
62  }
63  }
64  }
65 
66  BLI_array_append(object_array, ob_iter);
67  }
69 
70  if (object_array != NULL) {
71  BLI_array_trim(object_array);
72  }
73  else {
74  /* We always need a valid allocation (prevent crash on free). */
75  object_array = MEM_mallocN(0, __func__);
76  }
77  *r_len = BLI_array_len(object_array);
78  return object_array;
79 }
80 
83 /* -------------------------------------------------------------------- */
88  const View3D *v3d,
89  uint *r_len,
90  const struct ObjectsInModeParams *params)
91 {
92  if (params->no_dup_data) {
93  FOREACH_BASE_IN_MODE_BEGIN (view_layer, v3d, -1, params->object_mode, base_iter) {
94  ID *id = base_iter->object->data;
95  if (id) {
96  id->tag |= LIB_TAG_DOIT;
97  }
98  }
100  }
101 
102  Base **base_array = NULL;
103  BLI_array_declare(base_array);
104 
105  FOREACH_BASE_IN_MODE_BEGIN (view_layer, v3d, -1, params->object_mode, base_iter) {
106  if (params->filter_fn) {
107  if (!params->filter_fn(base_iter->object, params->filter_userdata)) {
108  continue;
109  }
110  }
111  if (params->no_dup_data) {
112  ID *id = base_iter->object->data;
113  if (id) {
114  if (id->tag & LIB_TAG_DOIT) {
115  id->tag &= ~LIB_TAG_DOIT;
116  }
117  else {
118  continue;
119  }
120  }
121  }
122  BLI_array_append(base_array, base_iter);
123  }
125 
126  /* We always need a valid allocation (prevent crash on free). */
127  if (base_array != NULL) {
128  BLI_array_trim(base_array);
129  }
130  else {
131  base_array = MEM_mallocN(0, __func__);
132  }
133  *r_len = BLI_array_len(base_array);
134  return base_array;
135 }
136 
138  const View3D *v3d,
139  uint *r_len,
140  const struct ObjectsInModeParams *params)
141 {
143  view_layer, v3d, r_len, params);
144  if (base_array != NULL) {
145  for (uint i = 0; i < *r_len; i++) {
146  ((Object **)base_array)[i] = base_array[i]->object;
147  }
148  }
149  return (Object **)base_array;
150 }
151 
154 /* -------------------------------------------------------------------- */
159 {
160  if (ob->type == OB_MESH) {
161  const Mesh *me = ob->data;
162  const BMEditMesh *em = me->edit_mesh;
163  if (em != NULL) {
164  if (CustomData_get_offset(&em->bm->ldata, CD_MLOOPUV) != -1) {
165  return true;
166  }
167  }
168  }
169  return false;
170 }
171 
173 {
174  if (ob->type == OB_MESH) {
175  const Mesh *me = ob->data;
176  const BMEditMesh *em = me->edit_mesh;
177  if (em != NULL) {
178  if (em->bm->totedge != 0) {
179  return true;
180  }
181  }
182  }
183  return false;
184 }
185 
187  const struct View3D *v3d)
188 {
189  Object *ob_active = OBACT(view_layer);
190  Object *ob_result = NULL;
191  FOREACH_SELECTED_OBJECT_BEGIN (view_layer, v3d, ob_iter) {
192  if (ob_iter == ob_active) {
193  continue;
194  }
195 
196  if (ob_result == NULL) {
197  ob_result = ob_iter;
198  }
199  else {
200  ob_result = NULL;
201  break;
202  }
203  }
205  return ob_result;
206 }
207 
CustomData interface, see also DNA_customdata_types.h.
int CustomData_get_offset(const struct CustomData *data, int type)
#define FOREACH_BASE_IN_MODE_END
Definition: BKE_layer.h:370
#define FOREACH_SELECTED_OBJECT_BEGIN(_view_layer, _v3d, _instance)
Definition: BKE_layer.h:303
#define FOREACH_BASE_IN_MODE_BEGIN(_view_layer, _v3d, _object_type, _object_mode, _instance)
Definition: BKE_layer.h:354
#define FOREACH_SELECTED_OBJECT_END
Definition: BKE_layer.h:315
A (mainly) macro array library.
#define BLI_array_append(arr, item)
Definition: BLI_array.h:98
#define BLI_array_trim(arr)
Definition: BLI_array.h:152
#define BLI_array_declare(arr)
Definition: BLI_array.h:50
#define BLI_array_len(arr)
Definition: BLI_array.h:63
unsigned int uint
Definition: BLI_sys_types.h:67
#define UNUSED(x)
ID and Library types, which are fundamental for sdna.
@ LIB_TAG_DOIT
Definition: DNA_ID.h:707
@ CD_MLOOPUV
Object is a sort of wrapper for general info.
@ OB_MESH
#define OBACT(_view_layer)
Read Guarded memory(de)allocation.
void * user_data
uiWidgetBaseParameters params[MAX_WIDGET_BASE_BATCH]
Object ** BKE_view_layer_array_selected_objects_params(struct ViewLayer *view_layer, const struct View3D *v3d, uint *r_len, const struct ObjectsInViewLayerParams *params)
Definition: layer_utils.c:28
Object ** BKE_view_layer_array_from_objects_in_mode_params(ViewLayer *view_layer, const View3D *v3d, uint *r_len, const struct ObjectsInModeParams *params)
Definition: layer_utils.c:137
Object * BKE_view_layer_non_active_selected_object(struct ViewLayer *view_layer, const struct View3D *v3d)
Definition: layer_utils.c:186
bool BKE_view_layer_filter_edit_mesh_has_edges(const Object *ob, void *UNUSED(user_data))
Definition: layer_utils.c:172
bool BKE_view_layer_filter_edit_mesh_has_uvs(const Object *ob, void *UNUSED(user_data))
Definition: layer_utils.c:158
Base ** BKE_view_layer_array_from_bases_in_mode_params(ViewLayer *view_layer, const View3D *v3d, uint *r_len, const struct ObjectsInModeParams *params)
Definition: layer_utils.c:87
void *(* MEM_mallocN)(size_t len, const char *str)
Definition: mallocn.c:33
struct BMesh * bm
Definition: BKE_editmesh.h:40
int totedge
Definition: bmesh_class.h:297
CustomData ldata
Definition: bmesh_class.h:337
struct Object * object
Definition: DNA_ID.h:368
int tag
Definition: DNA_ID.h:387
struct BMEditMesh * edit_mesh
void * data