Blender V4.3
view3d_ops.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2008 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
9#include <cmath>
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.hh"
22#include "BKE_blendfile.hh"
23#include "BKE_context.hh"
24#include "BKE_report.hh"
25
26#include "RNA_access.hh"
27#include "RNA_define.hh"
28
29#include "WM_api.hh"
30#include "WM_types.hh"
31
32#include "ED_outliner.hh"
33#include "ED_screen.hh"
34#include "ED_transform.hh"
35
36#include "view3d_intern.hh"
37#include "view3d_navigate.hh"
38
39#ifdef WIN32
40# include "BLI_math_base.h" /* M_PI */
41#endif
42
43/* -------------------------------------------------------------------- */
47static void view3d_copybuffer_filepath_get(char filepath[FILE_MAX], size_t filepath_maxncpy)
48{
49 BLI_path_join(filepath, filepath_maxncpy, BKE_tempdir_base(), "copybuffer.blend");
50}
51
54/* -------------------------------------------------------------------- */
59{
60 using namespace blender::bke::blendfile;
61
62 Main *bmain = CTX_data_main(C);
64 int num_copied = 0;
65
66 /* context, selection, could be generalized */
67 CTX_DATA_BEGIN (C, Object *, ob, selected_objects) {
68 copybuffer.id_add(&ob->id,
69 PartialWriteContext::IDAddOptions{PartialWriteContext::IDAddOperations(
70 PartialWriteContext::IDAddOperations::SET_FAKE_USER |
71 PartialWriteContext::IDAddOperations::SET_CLIPBOARD_MARK |
72 PartialWriteContext::IDAddOperations::ADD_DEPENDENCIES)},
73 nullptr);
74
75 num_copied++;
76 }
78
79 char filepath[FILE_MAX];
80 view3d_copybuffer_filepath_get(filepath, sizeof(filepath));
81 copybuffer.write(filepath, *op->reports);
82
83 BKE_reportf(op->reports, RPT_INFO, "Copied %d selected object(s)", num_copied);
84
85 return OPERATOR_FINISHED;
86}
87
89{
90 /* identifiers */
91 ot->name = "Copy Objects";
92 ot->idname = "VIEW3D_OT_copybuffer";
93 ot->description = "Copy the selected objects to the internal clipboard";
94
95 /* api callbacks */
98}
99
102/* -------------------------------------------------------------------- */
107{
108 char filepath[FILE_MAX];
109 short flag = 0;
110
111 if (RNA_boolean_get(op->ptr, "autoselect")) {
113 }
114 if (RNA_boolean_get(op->ptr, "active_collection")) {
116 }
117
118 view3d_copybuffer_filepath_get(filepath, sizeof(filepath));
119
120 const int num_pasted = BKE_copybuffer_paste(C, filepath, flag, op->reports, FILTER_ID_OB);
121 if (num_pasted == 0) {
122 BKE_report(op->reports, RPT_INFO, "No objects to paste");
123 return OPERATOR_CANCELLED;
124 }
125
126 WM_event_add_notifier(C, NC_WINDOW, nullptr);
128
129 BKE_reportf(op->reports, RPT_INFO, "%d object(s) pasted", num_pasted);
130
131 return OPERATOR_FINISHED;
132}
133
135{
136
137 /* identifiers */
138 ot->name = "Paste Objects";
139 ot->idname = "VIEW3D_OT_pastebuffer";
140 ot->description = "Paste objects from the internal clipboard";
141
142 /* api callbacks */
145
146 /* flags */
148
149 RNA_def_boolean(ot->srna, "autoselect", true, "Select", "Select pasted objects");
151 "active_collection",
152 true,
153 "Active Collection",
154 "Put pasted objects in the active collection");
155}
156
159/* -------------------------------------------------------------------- */
164{
170#ifdef WITH_INPUT_NDOF
171 WM_operatortype_append(VIEW3D_OT_ndof_orbit_zoom);
172 WM_operatortype_append(VIEW3D_OT_ndof_orbit);
173 WM_operatortype_append(VIEW3D_OT_ndof_pan);
174 WM_operatortype_append(VIEW3D_OT_ndof_all);
175#endif /* WITH_INPUT_NDOF */
215
217
225
227
231
234
236}
237
239{
240 WM_keymap_ensure(keyconf, "3D View Generic", SPACE_VIEW3D, RGN_TYPE_WINDOW);
241
242 /* only for region 3D window */
243 WM_keymap_ensure(keyconf, "3D View", SPACE_VIEW3D, RGN_TYPE_WINDOW);
244
245 fly_modal_keymap(keyconf);
246 walk_modal_keymap(keyconf);
248 viewmove_modal_keymap(keyconf);
249 viewzoom_modal_keymap(keyconf);
250 viewdolly_modal_keymap(keyconf);
251 viewplace_modal_keymap(keyconf);
252}
253
const char * BKE_tempdir_base() ATTR_WARN_UNUSED_RESULT ATTR_RETURNS_NONNULL
Definition appdir.cc:1211
int BKE_copybuffer_paste(bContext *C, const char *libname, int flag, ReportList *reports, uint64_t id_types_mask)
#define CTX_DATA_BEGIN(C, Type, instance, member)
Main * CTX_data_main(const bContext *C)
#define CTX_DATA_END
const char * BKE_main_blendfile_path(const Main *bmain) ATTR_NONNULL()
Definition main.cc:832
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.cc:125
#define FILE_MAX
#define BLI_path_join(...)
#define FILTER_ID_OB
Definition DNA_ID.h:1181
Object is a sort of wrapper for general info.
@ RGN_TYPE_WINDOW
@ SPACE_VIEW3D
@ FILE_ACTIVE_COLLECTION
@ FILE_AUTOSELECT
void ED_outliner_select_sync_from_object_tag(bContext *C)
bool ED_operator_scene(bContext *C)
bool ED_operator_scene_editable(bContext *C)
void transform_operatortypes()
@ OPTYPE_UNDO
Definition WM_types.hh:162
@ OPTYPE_REGISTER
Definition WM_types.hh:160
#define NC_WINDOW
Definition WM_types.hh:342
ID * id_add(const ID *id, IDAddOptions options, blender::FunctionRef< IDAddOperations(LibraryIDLinkCallbackData *cb_data, IDAddOptions options)> dependencies_filter_cb=nullptr)
bool RNA_boolean_get(PointerRNA *ptr, const char *name)
PropertyRNA * RNA_def_boolean(StructOrFunctionRNA *cont_, const char *identifier, const bool default_value, const char *ui_name, const char *ui_description)
const char * name
Definition WM_types.hh:990
bool(* poll)(bContext *C) ATTR_WARN_UNUSED_RESULT
Definition WM_types.hh:1042
const char * idname
Definition WM_types.hh:992
int(* exec)(bContext *C, wmOperator *op) ATTR_WARN_UNUSED_RESULT
Definition WM_types.hh:1006
const char * description
Definition WM_types.hh:996
StructRNA * srna
Definition WM_types.hh:1080
struct ReportList * reports
struct PointerRNA * ptr
void VIEW3D_OT_object_mode_pie_or_toggle(wmOperatorType *ot)
void VIEW3D_OT_view_persportho(wmOperatorType *ot)
void VIEW3D_OT_toggle_xray(wmOperatorType *ot)
void VIEW3D_OT_view_center_camera(wmOperatorType *ot)
void VIEW3D_OT_view_center_lock(wmOperatorType *ot)
void VIEW3D_OT_zoom_camera_1_to_1(wmOperatorType *ot)
void VIEW3D_OT_clip_border(wmOperatorType *ot)
void VIEW3D_OT_view_lock_to_active(wmOperatorType *ot)
void VIEW3D_OT_cursor3d(wmOperatorType *ot)
void VIEW3D_OT_clear_render_border(wmOperatorType *ot)
void VIEW3D_OT_view_lock_clear(wmOperatorType *ot)
void VIEW3D_OT_navigate(wmOperatorType *ot)
void VIEW3D_OT_camera_background_image_remove(wmOperatorType *ot)
void VIEW3D_OT_render_border(wmOperatorType *ot)
void VIEW3D_OT_toggle_shading(wmOperatorType *ot)
void VIEW3D_OT_drop_world(wmOperatorType *ot)
void VIEW3D_OT_camera_background_image_add(wmOperatorType *ot)
void VIEW3D_OT_ruler_remove(wmOperatorType *ot)
void VIEW3D_OT_ruler_add(wmOperatorType *ot)
void VIEW3D_OT_toggle_matcap_flip(wmOperatorType *ot)
void VIEW3D_OT_select(wmOperatorType *ot)
void VIEW3D_OT_localview(wmOperatorType *ot)
void VIEW3D_OT_snap_cursor_to_grid(wmOperatorType *ot)
void VIEW3D_OT_bone_select_menu(wmOperatorType *ot)
void VIEW3D_OT_select_box(wmOperatorType *ot)
void VIEW3D_OT_localview_remove_from(wmOperatorType *ot)
void VIEW3D_OT_camera_to_view_selected(wmOperatorType *ot)
void VIEW3D_OT_snap_selected_to_grid(wmOperatorType *ot)
void VIEW3D_OT_interactive_add(wmOperatorType *ot)
void VIEW3D_OT_snap_cursor_to_selected(wmOperatorType *ot)
void VIEW3D_OT_select_menu(wmOperatorType *ot)
void VIEW3D_OT_snap_cursor_to_center(wmOperatorType *ot)
void VIEW3D_OT_snap_selected_to_active(wmOperatorType *ot)
void VIEW3D_OT_select_circle(wmOperatorType *ot)
void VIEW3D_OT_select_lasso(wmOperatorType *ot)
void VIEW3D_OT_snap_cursor_to_active(wmOperatorType *ot)
void VIEW3D_OT_camera_to_view(wmOperatorType *ot)
void viewplace_modal_keymap(wmKeyConfig *keyconf)
void VIEW3D_OT_snap_selected_to_cursor(wmOperatorType *ot)
void VIEW3D_OT_object_as_camera(wmOperatorType *ot)
void viewmove_modal_keymap(wmKeyConfig *keyconf)
void VIEW3D_OT_view_roll(wmOperatorType *ot)
void VIEW3D_OT_view_axis(wmOperatorType *ot)
void VIEW3D_OT_view_orbit(wmOperatorType *ot)
void fly_modal_keymap(wmKeyConfig *keyconf)
void VIEW3D_OT_walk(wmOperatorType *ot)
void VIEW3D_OT_zoom_border(wmOperatorType *ot)
void VIEW3D_OT_rotate(wmOperatorType *ot)
void VIEW3D_OT_view_pan(wmOperatorType *ot)
void VIEW3D_OT_view_all(wmOperatorType *ot)
void viewzoom_modal_keymap(wmKeyConfig *keyconf)
void VIEW3D_OT_view_selected(wmOperatorType *ot)
void viewrotate_modal_keymap(wmKeyConfig *keyconf)
void VIEW3D_OT_zoom(wmOperatorType *ot)
void VIEW3D_OT_view_camera(wmOperatorType *ot)
void viewdolly_modal_keymap(wmKeyConfig *keyconf)
void VIEW3D_OT_view_center_pick(wmOperatorType *ot)
void VIEW3D_OT_view_center_cursor(wmOperatorType *ot)
void walk_modal_keymap(wmKeyConfig *keyconf)
void VIEW3D_OT_fly(wmOperatorType *ot)
void VIEW3D_OT_move(wmOperatorType *ot)
void VIEW3D_OT_smoothview(wmOperatorType *ot)
void VIEW3D_OT_dolly(wmOperatorType *ot)
void view3d_keymap(wmKeyConfig *keyconf)
static void VIEW3D_OT_pastebuffer(wmOperatorType *ot)
static int view3d_copybuffer_exec(bContext *C, wmOperator *op)
Definition view3d_ops.cc:58
static void view3d_copybuffer_filepath_get(char filepath[FILE_MAX], size_t filepath_maxncpy)
Definition view3d_ops.cc:47
static void VIEW3D_OT_copybuffer(wmOperatorType *ot)
Definition view3d_ops.cc:88
void view3d_operatortypes()
static int view3d_pastebuffer_exec(bContext *C, wmOperator *op)
void WM_event_add_notifier(const bContext *C, uint type, void *reference)
wmOperatorType * ot
Definition wm_files.cc:4125
wmKeyMap * WM_keymap_ensure(wmKeyConfig *keyconf, const char *idname, int spaceid, int regionid)
Definition wm_keymap.cc:897
void WM_operatortype_append(void(*opfunc)(wmOperatorType *))
uint8_t flag
Definition wm_window.cc:138