Blender  V2.93
view3d_ops.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) 2008 Blender Foundation.
17  * All rights reserved.
18  */
19 
24 #include <math.h>
25 #include <stdlib.h>
26 
27 #include "DNA_object_types.h"
28 #include "DNA_scene_types.h"
29 #include "DNA_screen_types.h"
30 #include "DNA_space_types.h"
31 #include "DNA_view3d_types.h"
32 
33 #include "BLI_blenlib.h"
34 #include "BLI_utildefines.h"
35 
36 #include "BKE_appdir.h"
37 #include "BKE_blender_copybuffer.h"
38 #include "BKE_context.h"
39 #include "BKE_main.h"
40 #include "BKE_report.h"
41 
42 #include "RNA_access.h"
43 #include "RNA_define.h"
44 
45 #include "WM_api.h"
46 #include "WM_types.h"
47 
48 #include "ED_outliner.h"
49 #include "ED_screen.h"
50 #include "ED_transform.h"
51 
52 #include "view3d_intern.h"
53 
54 #ifdef WIN32
55 # include "BLI_math_base.h" /* M_PI */
56 #endif
57 
58 /* ************************** copy paste ***************************** */
59 
61 {
62  Main *bmain = CTX_data_main(C);
63  char str[FILE_MAX];
64  int num_copied = 0;
65 
66  BKE_copybuffer_begin(bmain);
67 
68  /* context, selection, could be generalized */
69  CTX_DATA_BEGIN (C, Object *, ob, selected_objects) {
70  if ((ob->id.tag & LIB_TAG_DOIT) == 0) {
71  BKE_copybuffer_tag_ID(&ob->id);
72  num_copied++;
73  }
74  }
76 
77  BLI_join_dirfile(str, sizeof(str), BKE_tempdir_base(), "copybuffer.blend");
78  BKE_copybuffer_save(bmain, str, op->reports);
79 
80  BKE_reportf(op->reports, RPT_INFO, "Copied %d selected object(s)", num_copied);
81 
82  return OPERATOR_FINISHED;
83 }
84 
86 {
87  /* identifiers */
88  ot->name = "Copy Objects";
89  ot->idname = "VIEW3D_OT_copybuffer";
90  ot->description = "Selected objects are copied to the clipboard";
91 
92  /* api callbacks */
95 }
96 
98 {
99  char str[FILE_MAX];
100  short flag = 0;
101 
102  if (RNA_boolean_get(op->ptr, "autoselect")) {
103  flag |= FILE_AUTOSELECT;
104  }
105  if (RNA_boolean_get(op->ptr, "active_collection")) {
106  flag |= FILE_ACTIVE_COLLECTION;
107  }
108 
109  BLI_join_dirfile(str, sizeof(str), BKE_tempdir_base(), "copybuffer.blend");
110 
111  const int num_pasted = BKE_copybuffer_paste(C, str, flag, op->reports, FILTER_ID_OB);
112  if (num_pasted == 0) {
113  BKE_report(op->reports, RPT_INFO, "No objects to paste");
114  return OPERATOR_CANCELLED;
115  }
116 
119 
120  BKE_reportf(op->reports, RPT_INFO, "%d object(s) pasted", num_pasted);
121 
122  return OPERATOR_FINISHED;
123 }
124 
126 {
127 
128  /* identifiers */
129  ot->name = "Paste Objects";
130  ot->idname = "VIEW3D_OT_pastebuffer";
131  ot->description = "Objects from the clipboard are pasted";
132 
133  /* api callbacks */
136 
137  /* flags */
139 
140  RNA_def_boolean(ot->srna, "autoselect", true, "Select", "Select pasted objects");
142  "active_collection",
143  true,
144  "Active Collection",
145  "Put pasted objects in the active collection");
146 }
147 
148 /* ************************** registration **********************************/
149 
151 {
157 #ifdef WITH_INPUT_NDOF
158  WM_operatortype_append(VIEW3D_OT_ndof_orbit_zoom);
159  WM_operatortype_append(VIEW3D_OT_ndof_orbit);
160  WM_operatortype_append(VIEW3D_OT_ndof_pan);
161  WM_operatortype_append(VIEW3D_OT_ndof_all);
162 #endif /* WITH_INPUT_NDOF */
201 
203 
211 
213 
217 
220 
222 }
223 
225 {
226  WM_keymap_ensure(keyconf, "3D View Generic", SPACE_VIEW3D, 0);
227 
228  /* only for region 3D window */
229  WM_keymap_ensure(keyconf, "3D View", SPACE_VIEW3D, 0);
230 
231  fly_modal_keymap(keyconf);
232  walk_modal_keymap(keyconf);
233  viewrotate_modal_keymap(keyconf);
234  viewmove_modal_keymap(keyconf);
235  viewzoom_modal_keymap(keyconf);
236  viewdolly_modal_keymap(keyconf);
237  viewplace_modal_keymap(keyconf);
238 }
const char * BKE_tempdir_base(void)
Definition: appdir.c:1182
bool BKE_copybuffer_save(struct Main *bmain_src, const char *filename, struct ReportList *reports)
int BKE_copybuffer_paste(struct bContext *C, const char *libname, const short flag, struct ReportList *reports, const uint64_t id_types_mask)
void BKE_copybuffer_begin(struct Main *bmain_src)
void BKE_copybuffer_tag_ID(struct ID *id)
#define CTX_DATA_BEGIN(C, Type, instance, member)
Definition: BKE_context.h:252
struct Main * CTX_data_main(const bContext *C)
Definition: context.c:1018
#define CTX_DATA_END
Definition: BKE_context.h:260
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
#define FILE_MAX
void BLI_join_dirfile(char *__restrict dst, const size_t maxlen, const char *__restrict dir, const char *__restrict file) ATTR_NONNULL()
Definition: path_util.c:1737
#define FILTER_ID_OB
Definition: DNA_ID.h:722
@ LIB_TAG_DOIT
Definition: DNA_ID.h:554
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)
Definition: outliner_sync.c:56
bool ED_operator_scene(struct bContext *C)
Definition: screen_ops.c:183
bool ED_operator_scene_editable(struct bContext *C)
Definition: screen_ops.c:192
void transform_operatortypes(void)
#define C
Definition: RandGen.cpp:39
#define NC_WINDOW
Definition: WM_types.h:277
@ OPTYPE_UNDO
Definition: WM_types.h:155
@ OPTYPE_REGISTER
Definition: WM_types.h:153
#define str(s)
bool RNA_boolean_get(PointerRNA *ptr, const char *name)
Definition: rna_access.c:6261
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
Definition: BKE_main.h:116
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 * description
Definition: WM_types.h:726
int(* exec)(struct bContext *, struct wmOperator *) ATTR_WARN_UNUSED_RESULT
Definition: WM_types.h:736
struct ReportList * reports
struct PointerRNA * ptr
void VIEW3D_OT_object_mode_pie_or_toggle(wmOperatorType *ot)
void viewmove_modal_keymap(wmKeyConfig *keyconf)
Definition: view3d_edit.c:1692
void VIEW3D_OT_view_roll(wmOperatorType *ot)
Definition: view3d_edit.c:4578
void VIEW3D_OT_view_axis(wmOperatorType *ot)
Definition: view3d_edit.c:4078
void VIEW3D_OT_view_orbit(wmOperatorType *ot)
Definition: view3d_edit.c:4337
void VIEW3D_OT_view_persportho(wmOperatorType *ot)
Definition: view3d_edit.c:4712
void VIEW3D_OT_toggle_xray(wmOperatorType *ot)
Definition: view3d_edit.c:5390
void VIEW3D_OT_zoom_border(wmOperatorType *ot)
Definition: view3d_edit.c:3771
void VIEW3D_OT_rotate(wmOperatorType *ot)
Definition: view3d_edit.c:1035
void VIEW3D_OT_view_center_camera(wmOperatorType *ot)
Definition: view3d_edit.c:3410
void VIEW3D_OT_view_center_lock(wmOperatorType *ot)
Definition: view3d_edit.c:3442
void VIEW3D_OT_zoom_camera_1_to_1(wmOperatorType *ot)
Definition: view3d_edit.c:3834
void VIEW3D_OT_clip_border(wmOperatorType *ot)
Definition: view3d_edit.c:4962
void VIEW3D_OT_view_lock_to_active(wmOperatorType *ot)
Definition: view3d_edit.c:3260
void VIEW3D_OT_view_pan(wmOperatorType *ot)
Definition: view3d_edit.c:4663
void VIEW3D_OT_cursor3d(wmOperatorType *ot)
Definition: view3d_edit.c:5242
void VIEW3D_OT_clear_render_border(wmOperatorType *ot)
Definition: view3d_edit.c:3596
void VIEW3D_OT_background_image_add(wmOperatorType *ot)
Definition: view3d_edit.c:4820
void VIEW3D_OT_view_lock_clear(wmOperatorType *ot)
Definition: view3d_edit.c:3203
void VIEW3D_OT_view_all(wmOperatorType *ot)
Definition: view3d_edit.c:2996
void viewzoom_modal_keymap(wmKeyConfig *keyconf)
Definition: view3d_edit.c:1890
void VIEW3D_OT_navigate(wmOperatorType *ot)
Definition: view3d_edit.c:4754
void VIEW3D_OT_view_selected(wmOperatorType *ot)
Definition: view3d_edit.c:3164
void viewrotate_modal_keymap(wmKeyConfig *keyconf)
Definition: view3d_edit.c:615
void VIEW3D_OT_zoom(wmOperatorType *ot)
Definition: view3d_edit.c:2426
void VIEW3D_OT_view_camera(wmOperatorType *ot)
Definition: view3d_edit.c:4201
void viewdolly_modal_keymap(wmKeyConfig *keyconf)
Definition: view3d_edit.c:2459
void VIEW3D_OT_view_center_pick(wmOperatorType *ot)
Definition: view3d_edit.c:3358
void VIEW3D_OT_view_center_cursor(wmOperatorType *ot)
Definition: view3d_edit.c:3306
void VIEW3D_OT_render_border(wmOperatorType *ot)
Definition: view3d_edit.c:3536
void VIEW3D_OT_background_image_remove(wmOperatorType *ot)
Definition: view3d_edit.c:4878
void VIEW3D_OT_toggle_shading(wmOperatorType *ot)
Definition: view3d_edit.c:5336
void VIEW3D_OT_move(wmOperatorType *ot)
Definition: view3d_edit.c:1861
void VIEW3D_OT_dolly(wmOperatorType *ot)
Definition: view3d_edit.c:2739
void fly_modal_keymap(wmKeyConfig *keyconf)
Definition: view3d_fly.c:105
void VIEW3D_OT_fly(wmOperatorType *ot)
Definition: view3d_fly.c:1134
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:84
void VIEW3D_OT_snap_selected_to_grid(struct wmOperatorType *ot)
Definition: view3d_snap.c:283
void VIEW3D_OT_camera_to_view(struct wmOperatorType *ot)
Definition: view3d_view.c:512
void VIEW3D_OT_walk(struct wmOperatorType *ot)
Definition: view3d_walk.c:1459
void VIEW3D_OT_select_box(struct wmOperatorType *ot)
void VIEW3D_OT_smoothview(struct wmOperatorType *ot)
Definition: view3d_view.c:444
void VIEW3D_OT_snap_selected_to_active(struct wmOperatorType *ot)
Definition: view3d_snap.c:634
void walk_modal_keymap(struct wmKeyConfig *keyconf)
Definition: view3d_walk.c:133
void VIEW3D_OT_snap_selected_to_cursor(struct wmOperatorType *ot)
Definition: view3d_snap.c:593
void VIEW3D_OT_snap_cursor_to_selected(struct wmOperatorType *ot)
Definition: view3d_snap.c:874
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:555
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:676
void VIEW3D_OT_localview(struct wmOperatorType *ot)
Definition: view3d_view.c:1486
void VIEW3D_OT_snap_cursor_to_center(struct wmOperatorType *ot)
Definition: view3d_snap.c:960
void VIEW3D_OT_interactive_add(struct wmOperatorType *ot)
void VIEW3D_OT_object_as_camera(struct wmOperatorType *ot)
Definition: view3d_view.c:692
void VIEW3D_OT_localview_remove_from(struct wmOperatorType *ot)
Definition: view3d_view.c:1548
void viewplace_modal_keymap(struct wmKeyConfig *keyconf)
void VIEW3D_OT_snap_cursor_to_active(struct wmOperatorType *ot)
Definition: view3d_snap.c:923
void view3d_keymap(wmKeyConfig *keyconf)
Definition: view3d_ops.c:224
void view3d_operatortypes(void)
Definition: view3d_ops.c:150
static void VIEW3D_OT_pastebuffer(wmOperatorType *ot)
Definition: view3d_ops.c:125
static int view3d_copybuffer_exec(bContext *C, wmOperator *op)
Definition: view3d_ops.c:60
static void VIEW3D_OT_copybuffer(wmOperatorType *ot)
Definition: view3d_ops.c:85
static int view3d_pastebuffer_exec(bContext *C, wmOperator *op)
Definition: view3d_ops.c:97
void WM_event_add_notifier(const bContext *C, uint type, void *reference)
wmOperatorType * ot
Definition: wm_files.c:3156
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 *))