5f9534a1f1c4ce42966e77522edf641e4225d30a
[blender.git] / source / blender / editors / include / ED_object.h
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) 2008 Blender Foundation.
17  * All rights reserved.
18  */
19
20 /** \file
21  * \ingroup editors
22  */
23
24 #ifndef __ED_OBJECT_H__
25 #define __ED_OBJECT_H__
26
27 #ifdef __cplusplus
28 extern "C" {
29 #endif
30
31 struct Base;
32 struct Depsgraph;
33 struct EnumPropertyItem;
34 struct EnumPropertyItem;
35 struct ID;
36 struct Main;
37 struct Menu;
38 struct ModifierData;
39 struct Object;
40 struct PointerRNA;
41 struct PropertyRNA;
42 struct ReportList;
43 struct Scene;
44 struct ShaderFxData;
45 struct View3D;
46 struct ViewLayer;
47 struct bConstraint;
48 struct bContext;
49 struct bFaceMap;
50 struct bPoseChannel;
51 struct uiLayout;
52 struct wmKeyConfig;
53 struct wmKeyMap;
54 struct wmOperator;
55 struct wmOperatorType;
56 struct wmWindow;
57 struct wmWindowManager;
58
59 #include "DNA_object_enums.h"
60 #include "BLI_compiler_attrs.h"
61
62 /* object_edit.c */
63 /* context.object */
64 struct Object *ED_object_context(struct bContext *C);
65 /* context.object or context.active_object */
66 struct Object *ED_object_active_context(struct bContext *C);
67 void ED_collection_hide_menu_draw(const struct bContext *C, struct uiLayout *layout);
68
69 /* object_utils.c */
70 bool ED_object_calc_active_center_for_editmode(struct Object *obedit,
71                                                const bool select_only,
72                                                float r_center[3]);
73 bool ED_object_calc_active_center_for_posemode(struct Object *ob,
74                                                const bool select_only,
75                                                float r_center[3]);
76 bool ED_object_calc_active_center(struct Object *ob, const bool select_only, float r_center[3]);
77
78 /* object_ops.c */
79 void ED_operatortypes_object(void);
80 void ED_operatormacros_object(void);
81 void ED_keymap_object(struct wmKeyConfig *keyconf);
82
83 /* object_relations.c */
84 typedef enum eParentType {
85   PAR_OBJECT,
86   PAR_ARMATURE,
87   PAR_ARMATURE_NAME,
88   PAR_ARMATURE_ENVELOPE,
89   PAR_ARMATURE_AUTO,
90   PAR_BONE,
91   PAR_BONE_RELATIVE,
92   PAR_CURVE,
93   PAR_FOLLOW,
94   PAR_PATH_CONST,
95   PAR_LATTICE,
96   PAR_VERTEX,
97   PAR_VERTEX_TRI,
98 } eParentType;
99
100 typedef enum eObjectSelect_Mode {
101   BA_DESELECT = 0,
102   BA_SELECT = 1,
103   BA_INVERT = 2,
104 } eObjectSelect_Mode;
105
106 #ifdef __RNA_TYPES_H__
107 extern struct EnumPropertyItem prop_clear_parent_types[];
108 extern struct EnumPropertyItem prop_make_parent_types[];
109 #endif
110
111 bool ED_object_parent_set(struct ReportList *reports,
112                           const struct bContext *C,
113                           struct Scene *scene,
114                           struct Object *ob,
115                           struct Object *par,
116                           int partype,
117                           const bool xmirror,
118                           const bool keep_transform,
119                           const int vert_par[3]);
120 void ED_object_parent_clear(struct Object *ob, const int type);
121
122 void ED_object_base_select(struct Base *base, eObjectSelect_Mode mode);
123 void ED_object_base_activate(struct bContext *C, struct Base *base);
124 void ED_object_base_active_refresh(struct Main *bmain,
125                                    struct Scene *scene,
126                                    struct ViewLayer *view_layer);
127 void ED_object_base_free_and_unlink(struct Main *bmain, struct Scene *scene, struct Object *ob);
128 bool ED_object_base_deselect_all_ex(struct ViewLayer *view_layer,
129                                     struct View3D *v3d,
130                                     int action,
131                                     bool *r_any_visible);
132 bool ED_object_base_deselect_all(struct ViewLayer *view_layer, struct View3D *v3d, int action);
133
134 /* single object duplicate, if (dupflag == 0), fully linked, else it uses the flags given */
135 struct Base *ED_object_add_duplicate(struct Main *bmain,
136                                      struct Scene *scene,
137                                      struct ViewLayer *view_layer,
138                                      struct Base *base,
139                                      int dupflag);
140
141 void ED_object_parent(struct Object *ob,
142                       struct Object *parent,
143                       const int type,
144                       const char *substr);
145
146 /* bitflags for enter/exit editmode */
147 enum {
148   EM_FREEDATA = (1 << 0),
149   EM_NO_CONTEXT = (1 << 1),
150 };
151 bool ED_object_editmode_exit_ex(struct Main *bmain,
152                                 struct Scene *scene,
153                                 struct Object *obedit,
154                                 int flag);
155 bool ED_object_editmode_exit(struct bContext *C, int flag);
156
157 bool ED_object_editmode_enter_ex(struct Main *bmain,
158                                  struct Scene *scene,
159                                  struct Object *ob,
160                                  int flag);
161 bool ED_object_editmode_enter(struct bContext *C, int flag);
162 bool ED_object_editmode_load(struct Main *bmain, struct Object *obedit);
163
164 void ED_object_vpaintmode_enter_ex(struct Main *bmain,
165                                    struct Depsgraph *depsgraph,
166                                    struct wmWindowManager *wm,
167                                    struct Scene *scene,
168                                    struct Object *ob);
169 void ED_object_wpaintmode_enter_ex(struct Main *bmain,
170                                    struct Depsgraph *depsgraph,
171                                    struct wmWindowManager *wm,
172                                    struct Scene *scene,
173                                    struct Object *ob);
174
175 void ED_object_vpaintmode_exit_ex(struct Object *ob);
176 void ED_object_vpaintmode_exit(struct bContext *C);
177 void ED_object_wpaintmode_exit_ex(struct Object *ob);
178 void ED_object_wpaintmode_exit(struct bContext *C);
179
180 void ED_object_sculptmode_enter_ex(struct Main *bmain,
181                                    struct Depsgraph *depsgraph,
182                                    struct Scene *scene,
183                                    struct Object *ob,
184                                    const bool force_dyntopo,
185                                    struct ReportList *reports);
186 void ED_object_sculptmode_exit_ex(struct Main *bmain,
187                                   struct Depsgraph *depsgraph,
188                                   struct Scene *scene,
189                                   struct Object *ob);
190
191 void ED_object_location_from_view(struct bContext *C, float loc[3]);
192 void ED_object_rotation_from_quat(float rot[3], const float quat[4], const char align_axis);
193 void ED_object_rotation_from_view(struct bContext *C, float rot[3], const char align_axis);
194 void ED_object_base_init_transform(struct bContext *C,
195                                    struct Base *base,
196                                    const float loc[3],
197                                    const float rot[3]);
198 float ED_object_new_primitive_matrix(struct bContext *C,
199                                      struct Object *editob,
200                                      const float loc[3],
201                                      const float rot[3],
202                                      float primmat[4][4]);
203
204 /* Avoid allowing too much insane values even by typing
205  * (typos can hang/crash Blender otherwise). */
206 #define OBJECT_ADD_SIZE_MAXF 1.0e12f
207
208 void ED_object_add_unit_props_size(struct wmOperatorType *ot);
209 void ED_object_add_unit_props_radius(struct wmOperatorType *ot);
210 void ED_object_add_generic_props(struct wmOperatorType *ot, bool do_editmode);
211 void ED_object_add_mesh_props(struct wmOperatorType *ot);
212 bool ED_object_add_generic_get_opts(struct bContext *C,
213                                     struct wmOperator *op,
214                                     const char view_align_axis,
215                                     float loc[3],
216                                     float rot[3],
217                                     bool *enter_editmode,
218                                     unsigned short *local_view_bits,
219                                     bool *is_view_aligned);
220
221 struct Object *ED_object_add_type(struct bContext *C,
222                                   int type,
223                                   const char *name,
224                                   const float loc[3],
225                                   const float rot[3],
226                                   bool enter_editmode,
227                                   unsigned short local_view_bits)
228     ATTR_NONNULL(1) ATTR_RETURNS_NONNULL;
229
230 void ED_object_single_users(struct Main *bmain,
231                             struct Scene *scene,
232                             const bool full,
233                             const bool copy_groups);
234 void ED_object_single_user(struct Main *bmain, struct Scene *scene, struct Object *ob);
235
236 /* object motion paths */
237 void ED_objects_clear_paths(struct bContext *C, bool only_selected);
238 void ED_objects_recalculate_paths(struct bContext *C,
239                                   struct Scene *scene,
240                                   bool current_frame_only);
241
242 /* constraints */
243 struct ListBase *get_active_constraints(struct Object *ob);
244 struct ListBase *get_constraint_lb(struct Object *ob,
245                                    struct bConstraint *con,
246                                    struct bPoseChannel **r_pchan);
247 struct bConstraint *get_active_constraint(struct Object *ob);
248
249 void object_test_constraints(struct Main *bmain, struct Object *ob);
250
251 void ED_object_constraint_set_active(struct Object *ob, struct bConstraint *con);
252 void ED_object_constraint_update(struct Main *bmain, struct Object *ob);
253 void ED_object_constraint_dependency_update(struct Main *bmain, struct Object *ob);
254
255 void ED_object_constraint_tag_update(struct Main *bmain,
256                                      struct Object *ob,
257                                      struct bConstraint *con);
258 void ED_object_constraint_dependency_tag_update(struct Main *bmain,
259                                                 struct Object *ob,
260                                                 struct bConstraint *con);
261
262 /* object_modes.c */
263 bool ED_object_mode_compat_test(const struct Object *ob, eObjectMode mode);
264 bool ED_object_mode_compat_set(struct bContext *C,
265                                struct Object *ob,
266                                eObjectMode mode,
267                                struct ReportList *reports);
268 void ED_object_mode_toggle(struct bContext *C, eObjectMode mode);
269 void ED_object_mode_set(struct bContext *C, eObjectMode mode);
270
271 bool ED_object_mode_generic_enter(struct bContext *C, eObjectMode object_mode);
272 void ED_object_mode_generic_exit(struct Main *bmain,
273                                  struct Depsgraph *depsgraph,
274                                  struct Scene *scene,
275                                  struct Object *ob);
276 bool ED_object_mode_generic_has_data(struct Depsgraph *depsgraph, struct Object *ob);
277
278 /* object_modifier.c */
279 enum {
280   MODIFIER_APPLY_DATA = 1,
281   MODIFIER_APPLY_SHAPE,
282 };
283
284 struct ModifierData *ED_object_modifier_add(struct ReportList *reports,
285                                             struct Main *bmain,
286                                             struct Scene *scene,
287                                             struct Object *ob,
288                                             const char *name,
289                                             int type);
290 bool ED_object_modifier_remove(struct ReportList *reports,
291                                struct Main *bmain,
292                                struct Object *ob,
293                                struct ModifierData *md);
294 void ED_object_modifier_clear(struct Main *bmain, struct Object *ob);
295 int ED_object_modifier_move_down(struct ReportList *reports,
296                                  struct Object *ob,
297                                  struct ModifierData *md);
298 int ED_object_modifier_move_up(struct ReportList *reports,
299                                struct Object *ob,
300                                struct ModifierData *md);
301 int ED_object_modifier_convert(struct ReportList *reports,
302                                struct Main *bmain,
303                                struct Depsgraph *depsgraph,
304                                struct Scene *scene,
305                                struct ViewLayer *view_layer,
306                                struct Object *ob,
307                                struct ModifierData *md);
308 int ED_object_modifier_apply(struct Main *bmain,
309                              struct ReportList *reports,
310                              struct Depsgraph *depsgraph,
311                              struct Scene *scene,
312                              struct Object *ob,
313                              struct ModifierData *md,
314                              int mode);
315 int ED_object_modifier_copy(struct ReportList *reports,
316                             struct Object *ob,
317                             struct ModifierData *md);
318
319 bool ED_object_iter_other(struct Main *bmain,
320                           struct Object *orig_ob,
321                           const bool include_orig,
322                           bool (*callback)(struct Object *ob, void *callback_data),
323                           void *callback_data);
324
325 bool ED_object_multires_update_totlevels_cb(struct Object *ob, void *totlevel_v);
326
327 /* object_greasepencil_modifier.c */
328 struct GpencilModifierData *ED_object_gpencil_modifier_add(struct ReportList *reports,
329                                                            struct Main *bmain,
330                                                            struct Scene *scene,
331                                                            struct Object *ob,
332                                                            const char *name,
333                                                            int type);
334 bool ED_object_gpencil_modifier_remove(struct ReportList *reports,
335                                        struct Main *bmain,
336                                        struct Object *ob,
337                                        struct GpencilModifierData *md);
338 void ED_object_gpencil_modifier_clear(struct Main *bmain, struct Object *ob);
339 int ED_object_gpencil_modifier_move_down(struct ReportList *reports,
340                                          struct Object *ob,
341                                          struct GpencilModifierData *md);
342 int ED_object_gpencil_modifier_move_up(struct ReportList *reports,
343                                        struct Object *ob,
344                                        struct GpencilModifierData *md);
345 int ED_object_gpencil_modifier_apply(struct Main *bmain,
346                                      struct ReportList *reports,
347                                      struct Depsgraph *depsgraph,
348                                      struct Object *ob,
349                                      struct GpencilModifierData *md,
350                                      int mode);
351 int ED_object_gpencil_modifier_copy(struct ReportList *reports,
352                                     struct Object *ob,
353                                     struct GpencilModifierData *md);
354
355 /* object_shader_fx.c */
356 struct ShaderFxData *ED_object_shaderfx_add(struct ReportList *reports,
357                                             struct Main *bmain,
358                                             struct Scene *scene,
359                                             struct Object *ob,
360                                             const char *name,
361                                             int type);
362 bool ED_object_shaderfx_remove(struct ReportList *reports,
363                                struct Main *bmain,
364                                struct Object *ob,
365                                struct ShaderFxData *fx);
366 void ED_object_shaderfx_clear(struct Main *bmain, struct Object *ob);
367 int ED_object_shaderfx_move_down(struct ReportList *reports,
368                                  struct Object *ob,
369                                  struct ShaderFxData *fx);
370 int ED_object_shaderfx_move_up(struct ReportList *reports,
371                                struct Object *ob,
372                                struct ShaderFxData *fx);
373
374 /* object_select.c */
375 void ED_object_select_linked_by_id(struct bContext *C, struct ID *id);
376
377 const struct EnumPropertyItem *ED_object_vgroup_selection_itemf_helper(
378     const struct bContext *C,
379     struct PointerRNA *ptr,
380     struct PropertyRNA *prop,
381     bool *r_free,
382     const unsigned int selection_mask);
383
384 void ED_object_check_force_modifiers(struct Main *bmain,
385                                      struct Scene *scene,
386                                      struct Object *object);
387
388 struct Base *ED_object_find_first_by_data_id(struct ViewLayer *view_layer, struct ID *id);
389
390 bool ED_object_jump_to_object(struct bContext *C, struct Object *ob, const bool reveal_hidden);
391 bool ED_object_jump_to_bone(struct bContext *C,
392                             struct Object *ob,
393                             const char *bone_name,
394                             const bool reveal_hidden);
395
396 /* object_facemap_ops.c */
397 void ED_object_facemap_face_add(struct Object *ob, struct bFaceMap *fmap, int facenum);
398 void ED_object_facemap_face_remove(struct Object *ob, struct bFaceMap *fmap, int facenum);
399
400 #ifdef __cplusplus
401 }
402 #endif
403
404 #endif /* __ED_OBJECT_H__ */