Blender  V3.3
view3d_ops.c
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later
2  * Copyright 2008 Blender Foundation. All rights reserved. */
3 
8 #include <math.h>
9 #include <stdlib.h>
10 
11 #include "DNA_object_types.h"
12 #include "DNA_scene_types.h"
13 #include "DNA_screen_types.h"
14 #include "DNA_space_types.h"
15 #include "DNA_view3d_types.h"
16 
17 #include "BLI_blenlib.h"
18 #include "BLI_utildefines.h"
19 
20 #include "BKE_appdir.h"
21 #include "BKE_blender_copybuffer.h"
22 #include "BKE_context.h"
23 #include "BKE_main.h"
24 #include "BKE_report.h"
25 
26 #include "RNA_access.h"
27 #include "RNA_define.h"
28 
29 #include "WM_api.h"
30 #include "WM_types.h"
31 
32 #include "ED_outliner.h"
33 #include "ED_screen.h"
34 #include "ED_transform.h"
35 
36 #include "view3d_intern.h"
37 #include "view3d_navigate.h"
38 
39 #ifdef WIN32
40 # include "BLI_math_base.h" /* M_PI */
41 #endif
42 
43 /* ************************** copy paste ***************************** */
44 
46 {
47  Main *bmain = CTX_data_main(C);
48  char str[FILE_MAX];
49  int num_copied = 0;
50 
52 
53  /* context, selection, could be generalized */
54  CTX_DATA_BEGIN (C, Object *, ob, selected_objects) {
55  if ((ob->id.tag & LIB_TAG_DOIT) == 0) {
57  num_copied++;
58  }
59  }
61 
62  BLI_join_dirfile(str, sizeof(str), BKE_tempdir_base(), "copybuffer.blend");
63  BKE_copybuffer_copy_end(bmain, str, op->reports);
64 
65  BKE_reportf(op->reports, RPT_INFO, "Copied %d selected object(s)", num_copied);
66 
67  return OPERATOR_FINISHED;
68 }
69 
71 {
72  /* identifiers */
73  ot->name = "Copy Objects";
74  ot->idname = "VIEW3D_OT_copybuffer";
75  ot->description = "Selected objects are copied to the clipboard";
76 
77  /* api callbacks */
80 }
81 
83 {
84  char str[FILE_MAX];
85  short flag = 0;
86 
87  if (RNA_boolean_get(op->ptr, "autoselect")) {
88  flag |= FILE_AUTOSELECT;
89  }
90  if (RNA_boolean_get(op->ptr, "active_collection")) {
91  flag |= FILE_ACTIVE_COLLECTION;
92  }
93 
94  BLI_join_dirfile(str, sizeof(str), BKE_tempdir_base(), "copybuffer.blend");
95 
96  const int num_pasted = BKE_copybuffer_paste(C, str, flag, op->reports, FILTER_ID_OB);
97  if (num_pasted == 0) {
98  BKE_report(op->reports, RPT_INFO, "No objects to paste");
99  return OPERATOR_CANCELLED;
100  }
101 
104 
105  BKE_reportf(op->reports, RPT_INFO, "%d object(s) pasted", num_pasted);
106 
107  return OPERATOR_FINISHED;
108 }
109 
111 {
112 
113  /* identifiers */
114  ot->name = "Paste Objects";
115  ot->idname = "VIEW3D_OT_pastebuffer";
116  ot->description = "Objects from the clipboard are pasted";
117 
118  /* api callbacks */
121 
122  /* flags */
124 
125  RNA_def_boolean(ot->srna, "autoselect", true, "Select", "Select pasted objects");
127  "active_collection",
128  true,
129  "Active Collection",
130  "Put pasted objects in the active collection");
131 }
132 
133 /* ************************** registration **********************************/
134 
136 {
142 #ifdef WITH_INPUT_NDOF
143  WM_operatortype_append(VIEW3D_OT_ndof_orbit_zoom);
144  WM_operatortype_append(VIEW3D_OT_ndof_orbit);
145  WM_operatortype_append(VIEW3D_OT_ndof_pan);
146  WM_operatortype_append(VIEW3D_OT_ndof_all);
147 #endif /* WITH_INPUT_NDOF */
187 
189 
197 
199 
203 
206 
208 }
209 
211 {
212  WM_keymap_ensure(keyconf, "3D View Generic", SPACE_VIEW3D, 0);
213 
214  /* only for region 3D window */
215  WM_keymap_ensure(keyconf, "3D View", SPACE_VIEW3D, 0);
216 
217  fly_modal_keymap(keyconf);
218  walk_modal_keymap(keyconf);
219  viewrotate_modal_keymap(keyconf);
220  viewmove_modal_keymap(keyconf);
221  viewzoom_modal_keymap(keyconf);
222  viewdolly_modal_keymap(keyconf);
223  viewplace_modal_keymap(keyconf);
224 }
const char * BKE_tempdir_base(void)
Definition: appdir.c:1154
bool BKE_copybuffer_copy_end(struct Main *bmain_src, const char *filename, struct ReportList *reports)
void BKE_copybuffer_copy_begin(struct Main *bmain_src)
void BKE_copybuffer_copy_tag_ID(struct ID *id)
int BKE_copybuffer_paste(struct bContext *C, const char *libname, int flag, struct ReportList *reports, uint64_t id_types_mask)
#define CTX_DATA_BEGIN(C, Type, instance, member)
Definition: BKE_context.h:269
struct Main * CTX_data_main(const bContext *C)
Definition: context.c:1074
#define CTX_DATA_END
Definition: BKE_context.h:278
void BKE_reportf(ReportList *reports, eReportType type, const char *format,...) ATTR_PRINTF_FORMAT(3
void BKE_report(ReportList *reports, eReportType type, const char *message)
Definition: report.c:83
#define FILE_MAX
void BLI_join_dirfile(char *__restrict dst, size_t maxlen, const char *__restrict dir, const char *__restrict file) ATTR_NONNULL()
Definition: path_util.c:1531
#define FILTER_ID_OB
Definition: DNA_ID.h:916
@ LIB_TAG_DOIT
Definition: DNA_ID.h:707
Object is a sort of wrapper for general info.
@ SPACE_VIEW3D
@ FILE_ACTIVE_COLLECTION
@ FILE_AUTOSELECT
@ OPERATOR_CANCELLED
@ OPERATOR_FINISHED
void ED_outliner_select_sync_from_object_tag(struct bContext *C)
bool ED_operator_scene(struct bContext *C)
Definition: screen_ops.c:168
bool ED_operator_scene_editable(struct bContext *C)
Definition: screen_ops.c:177
void transform_operatortypes(void)
#define C
Definition: RandGen.cpp:25
@ OPTYPE_UNDO
Definition: WM_types.h:148
@ OPTYPE_REGISTER
Definition: WM_types.h:146
#define NC_WINDOW
Definition: WM_types.h:325
#define str(s)
bool RNA_boolean_get(PointerRNA *ptr, const char *name)
Definition: rna_access.c:4863
PropertyRNA * RNA_def_boolean(StructOrFunctionRNA *cont_, const char *identifier, bool default_value, const char *ui_name, const char *ui_description)
Definition: rna_define.c:3493
Definition: BKE_main.h:121
const char * name
Definition: WM_types.h:888
const char * idname
Definition: WM_types.h:890
bool(* poll)(struct bContext *) ATTR_WARN_UNUSED_RESULT
Definition: WM_types.h:943
struct StructRNA * srna
Definition: WM_types.h:969
const char * description
Definition: WM_types.h:893
int(* exec)(struct bContext *, struct wmOperator *) ATTR_WARN_UNUSED_RESULT
Definition: WM_types.h:903
struct ReportList * reports
struct PointerRNA * ptr
void VIEW3D_OT_object_mode_pie_or_toggle(wmOperatorType *ot)
void VIEW3D_OT_view_persportho(wmOperatorType *ot)
Definition: view3d_edit.c:489
void VIEW3D_OT_toggle_xray(wmOperatorType *ot)
Definition: view3d_edit.c:1225
void VIEW3D_OT_view_center_camera(wmOperatorType *ot)
Definition: view3d_edit.c:200
void VIEW3D_OT_view_center_lock(wmOperatorType *ot)
Definition: view3d_edit.c:232
void VIEW3D_OT_zoom_camera_1_to_1(wmOperatorType *ot)
Definition: view3d_edit.c:444
void VIEW3D_OT_clip_border(wmOperatorType *ot)
Definition: view3d_edit.c:793
void VIEW3D_OT_view_lock_to_active(wmOperatorType *ot)
Definition: view3d_edit.c:147
void VIEW3D_OT_cursor3d(wmOperatorType *ot)
Definition: view3d_edit.c:1076
void VIEW3D_OT_clear_render_border(wmOperatorType *ot)
Definition: view3d_edit.c:386
void VIEW3D_OT_background_image_add(wmOperatorType *ot)
Definition: view3d_edit.c:595
void VIEW3D_OT_view_lock_clear(wmOperatorType *ot)
Definition: view3d_edit.c:90
void VIEW3D_OT_navigate(wmOperatorType *ot)
Definition: view3d_edit.c:529
void VIEW3D_OT_render_border(wmOperatorType *ot)
Definition: view3d_edit.c:326
void VIEW3D_OT_background_image_remove(wmOperatorType *ot)
Definition: view3d_edit.c:660
void VIEW3D_OT_toggle_shading(wmOperatorType *ot)
Definition: view3d_edit.c:1170
void VIEW3D_OT_drop_world(wmOperatorType *ot)
Definition: view3d_edit.c:713
void VIEW3D_OT_ruler_remove(wmOperatorType *ot)
void VIEW3D_OT_ruler_add(wmOperatorType *ot)
void VIEW3D_OT_toggle_matcap_flip(wmOperatorType *ot)
Definition: view3d_header.c:67
void VIEW3D_OT_snap_selected_to_grid(struct wmOperatorType *ot)
Definition: view3d_snap.c:267
void VIEW3D_OT_camera_to_view(struct wmOperatorType *ot)
Definition: view3d_view.c:100
void VIEW3D_OT_select_box(struct wmOperatorType *ot)
void VIEW3D_OT_snap_selected_to_active(struct wmOperatorType *ot)
Definition: view3d_snap.c:652
void VIEW3D_OT_snap_selected_to_cursor(struct wmOperatorType *ot)
Definition: view3d_snap.c:608
void VIEW3D_OT_snap_cursor_to_selected(struct wmOperatorType *ot)
Definition: view3d_snap.c:893
void VIEW3D_OT_select(struct wmOperatorType *ot)
void VIEW3D_OT_bone_select_menu(struct wmOperatorType *ot)
void VIEW3D_OT_camera_to_view_selected(struct wmOperatorType *ot)
Definition: view3d_view.c:143
void VIEW3D_OT_select_menu(struct wmOperatorType *ot)
void VIEW3D_OT_select_circle(struct wmOperatorType *ot)
void VIEW3D_OT_select_lasso(struct wmOperatorType *ot)
void VIEW3D_OT_snap_cursor_to_grid(struct wmOperatorType *ot)
Definition: view3d_snap.c:694
void VIEW3D_OT_localview(struct wmOperatorType *ot)
Definition: view3d_view.c:1070
void VIEW3D_OT_snap_cursor_to_center(struct wmOperatorType *ot)
Definition: view3d_snap.c:979
void VIEW3D_OT_interactive_add(struct wmOperatorType *ot)
void VIEW3D_OT_object_as_camera(struct wmOperatorType *ot)
Definition: view3d_view.c:285
void VIEW3D_OT_localview_remove_from(struct wmOperatorType *ot)
Definition: view3d_view.c:1132
void viewplace_modal_keymap(struct wmKeyConfig *keyconf)
void VIEW3D_OT_snap_cursor_to_active(struct wmOperatorType *ot)
Definition: view3d_snap.c:942
void VIEW3D_OT_view_axis(wmOperatorType *ot)
void VIEW3D_OT_view_orbit(wmOperatorType *ot)
void VIEW3D_OT_view_pan(wmOperatorType *ot)
void VIEW3D_OT_view_all(wmOperatorType *ot)
void VIEW3D_OT_view_selected(wmOperatorType *ot)
void VIEW3D_OT_view_camera(wmOperatorType *ot)
void VIEW3D_OT_view_center_pick(wmOperatorType *ot)
void VIEW3D_OT_view_center_cursor(wmOperatorType *ot)
void viewdolly_modal_keymap(struct wmKeyConfig *keyconf)
void VIEW3D_OT_walk(struct wmOperatorType *ot)
void viewmove_modal_keymap(struct wmKeyConfig *keyconf)
void VIEW3D_OT_smoothview(struct wmOperatorType *ot)
void VIEW3D_OT_zoom(struct wmOperatorType *ot)
void walk_modal_keymap(struct wmKeyConfig *keyconf)
void VIEW3D_OT_fly(struct wmOperatorType *ot)
void VIEW3D_OT_dolly(struct wmOperatorType *ot)
void fly_modal_keymap(struct wmKeyConfig *keyconf)
void viewrotate_modal_keymap(struct wmKeyConfig *keyconf)
void VIEW3D_OT_zoom_border(struct wmOperatorType *ot)
void VIEW3D_OT_view_roll(struct wmOperatorType *ot)
void viewzoom_modal_keymap(struct wmKeyConfig *keyconf)
void VIEW3D_OT_rotate(struct wmOperatorType *ot)
void VIEW3D_OT_move(struct wmOperatorType *ot)
void view3d_keymap(wmKeyConfig *keyconf)
Definition: view3d_ops.c:210
void view3d_operatortypes(void)
Definition: view3d_ops.c:135
static void VIEW3D_OT_pastebuffer(wmOperatorType *ot)
Definition: view3d_ops.c:110
static int view3d_copybuffer_exec(bContext *C, wmOperator *op)
Definition: view3d_ops.c:45
static void VIEW3D_OT_copybuffer(wmOperatorType *ot)
Definition: view3d_ops.c:70
static int view3d_pastebuffer_exec(bContext *C, wmOperator *op)
Definition: view3d_ops.c:82
void WM_event_add_notifier(const bContext *C, uint type, void *reference)
wmOperatorType * ot
Definition: wm_files.c:3479
wmKeyMap * WM_keymap_ensure(wmKeyConfig *keyconf, const char *idname, int spaceid, int regionid)
Definition: wm_keymap.c:852
void WM_operatortype_append(void(*opfunc)(wmOperatorType *))