Blender V5.0
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
8
9#include "DNA_object_types.h"
10#include "DNA_screen_types.h"
11#include "DNA_space_types.h"
12
13#include "BLI_listbase.h"
14#include "BLI_path_utils.hh"
15
16#include "BKE_appdir.hh"
18#include "BKE_blendfile.hh"
19#include "BKE_context.hh"
20#include "BKE_report.hh"
21
22#include "BLO_readfile.hh"
23
24#include "RNA_access.hh"
25#include "RNA_define.hh"
26
27#include "WM_api.hh"
28#include "WM_types.hh"
29
30#include "ED_outliner.hh"
31#include "ED_screen.hh"
32#include "ED_transform.hh"
33
34#include "view3d_intern.hh"
35#include "view3d_navigate.hh"
36
37#ifdef WIN32
38# include "BLI_math_base.h" /* M_PI */
39#endif
40
41/* -------------------------------------------------------------------- */
44
45static void view3d_copybuffer_filepath_get(char filepath[FILE_MAX], size_t filepath_maxncpy)
46{
47 BLI_path_join(filepath, filepath_maxncpy, BKE_tempdir_base(), "copybuffer.blend");
48}
49
51
52/* -------------------------------------------------------------------- */
55
57{
58 using namespace blender::bke::blendfile;
59
60 Main *bmain = CTX_data_main(C);
61 PartialWriteContext copybuffer{*bmain};
62
64 Object *obact_copy = nullptr;
65
66 /* context, selection, could be generalized */
67 CTX_DATA_BEGIN (C, Object *, ob, selected_objects) {
68 ID *ob_id_copy = copybuffer.id_add(
69 &ob->id,
71 (PartialWriteContext::IDAddOperations::SET_FAKE_USER |
72 PartialWriteContext::IDAddOperations::SET_CLIPBOARD_MARK |
73 PartialWriteContext::IDAddOperations::ADD_DEPENDENCIES)},
74 nullptr);
75
76 if (obact && (obact == ob)) {
77 obact_copy = reinterpret_cast<Object *>(ob_id_copy);
78 }
79 }
81
82 /* Explicitly adding an object to the copy/paste buffer _may_ add others as dependencies (e.g. a
83 * parent object). So count to total amount of objects added, to get a matching number with the
84 * one reported by the "paste" operation. */
85 int num_copied = 0;
86
87 /* Count & mark the active as done (when set). */
88 LISTBASE_FOREACH (Object *, ob, &copybuffer.bmain.objects) {
89 ob->flag &= ~OB_FLAG_ACTIVE_CLIPBOARD;
90 num_copied += 1;
91 }
92 if (obact_copy) {
93 obact_copy->flag |= OB_FLAG_ACTIVE_CLIPBOARD;
94 }
95
96 char filepath[FILE_MAX];
97 view3d_copybuffer_filepath_get(filepath, sizeof(filepath));
98 copybuffer.write(filepath, *op->reports);
99
100 BKE_reportf(op->reports, RPT_INFO, "Copied %d selected object(s)", num_copied);
101
102 return OPERATOR_FINISHED;
103}
104
106{
107 /* identifiers */
108 ot->name = "Copy Objects";
109 ot->idname = "VIEW3D_OT_copybuffer";
110 ot->description = "Copy the selected objects to the internal clipboard";
111
112 /* API callbacks. */
114 ot->poll = ED_operator_scene;
115}
116
118
119/* -------------------------------------------------------------------- */
122
124{
125 char filepath[FILE_MAX];
126 int flag = 0;
127
128 if (RNA_boolean_get(op->ptr, "autoselect")) {
130 }
131 if (RNA_boolean_get(op->ptr, "active_collection")) {
133 }
134
135 view3d_copybuffer_filepath_get(filepath, sizeof(filepath));
136
137 const int num_pasted = BKE_copybuffer_paste(C, filepath, flag, op->reports, FILTER_ID_OB);
138 if (num_pasted == 0) {
139 BKE_report(op->reports, RPT_INFO, "No objects to paste");
140 return OPERATOR_CANCELLED;
141 }
142
145
146 BKE_reportf(op->reports, RPT_INFO, "%d object(s) pasted", num_pasted);
147
148 return OPERATOR_FINISHED;
149}
150
152{
153
154 /* identifiers */
155 ot->name = "Paste Objects";
156 ot->idname = "VIEW3D_OT_pastebuffer";
157 ot->description = "Paste objects from the internal clipboard";
158
159 /* API callbacks. */
162
163 /* flags */
165
166 RNA_def_boolean(ot->srna, "autoselect", true, "Select", "Select pasted objects");
167 RNA_def_boolean(ot->srna,
168 "active_collection",
169 true,
170 "Active Collection",
171 "Put pasted objects in the active collection");
172}
173
175
176/* -------------------------------------------------------------------- */
179
181{
187#ifdef WITH_INPUT_NDOF
188 WM_operatortype_append(VIEW3D_OT_ndof_orbit_zoom);
189 WM_operatortype_append(VIEW3D_OT_ndof_orbit);
190 WM_operatortype_append(VIEW3D_OT_ndof_pan);
191 WM_operatortype_append(VIEW3D_OT_ndof_all);
192#endif /* WITH_INPUT_NDOF */
232
234
242
244
248
251
253}
254
256{
257 WM_keymap_ensure(keyconf, "3D View Generic", SPACE_VIEW3D, RGN_TYPE_WINDOW);
258
259 /* only for region 3D window */
260 WM_keymap_ensure(keyconf, "3D View", SPACE_VIEW3D, RGN_TYPE_WINDOW);
261
262 fly_modal_keymap(keyconf);
263 walk_modal_keymap(keyconf);
265 viewmove_modal_keymap(keyconf);
266 viewzoom_modal_keymap(keyconf);
267 viewdolly_modal_keymap(keyconf);
268 viewplace_modal_keymap(keyconf);
269}
270
const char * BKE_tempdir_base() ATTR_WARN_UNUSED_RESULT ATTR_RETURNS_NONNULL
Definition appdir.cc:1243
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)
Object * CTX_data_active_object(const bContext *C)
Main * CTX_data_main(const bContext *C)
#define CTX_DATA_END
void BKE_reportf(ReportList *reports, eReportType type, const char *format,...) ATTR_PRINTF_FORMAT(3
@ RPT_INFO
Definition BKE_report.hh:35
void BKE_report(ReportList *reports, eReportType type, const char *message)
Definition report.cc:153
#define LISTBASE_FOREACH(type, var, list)
#define FILE_MAX
#define BLI_path_join(...)
external readfile function prototypes.
@ BLO_LIBLINK_APPEND_SET_OB_ACTIVE_CLIPBOARD
#define FILTER_ID_OB
Definition DNA_ID.h:1214
Object is a sort of wrapper for general info.
@ OB_FLAG_ACTIVE_CLIPBOARD
@ RGN_TYPE_WINDOW
@ SPACE_VIEW3D
@ FILE_ACTIVE_COLLECTION
@ FILE_AUTOSELECT
@ OPERATOR_CANCELLED
@ OPERATOR_FINISHED
void ED_outliner_select_sync_from_object_tag(bContext *C)
bool ED_operator_scene(bContext *C)
bool ED_operator_scene_editable(bContext *C)
#define C
Definition RandGen.cpp:29
#define NC_WINDOW
Definition WM_types.hh:375
@ OPTYPE_UNDO
Definition WM_types.hh:182
@ OPTYPE_REGISTER
Definition WM_types.hh:180
ID * id_add(const ID *id, IDAddOptions options, blender::FunctionRef< IDAddOperations(LibraryIDLinkCallbackData *cb_data, IDAddOptions options)> dependencies_filter_cb=nullptr)
bool write(const char *write_filepath, int write_flags, int remap_mode, ReportList &reports)
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)
Definition DNA_ID.h:414
ListBase objects
Definition BKE_main.hh:280
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 wmOperatorStatus view3d_pastebuffer_exec(bContext *C, wmOperator *op)
static void VIEW3D_OT_pastebuffer(wmOperatorType *ot)
static void view3d_copybuffer_filepath_get(char filepath[FILE_MAX], size_t filepath_maxncpy)
Definition view3d_ops.cc:45
static void VIEW3D_OT_copybuffer(wmOperatorType *ot)
void view3d_operatortypes()
static wmOperatorStatus view3d_copybuffer_exec(bContext *C, wmOperator *op)
Definition view3d_ops.cc:56
void WM_event_add_notifier(const bContext *C, uint type, void *reference)
wmOperatorType * ot
Definition wm_files.cc:4237
wmKeyMap * WM_keymap_ensure(wmKeyConfig *keyconf, const char *idname, int spaceid, int regionid)
Definition wm_keymap.cc:895
void WM_operatortype_append(void(*opfunc)(wmOperatorType *))
uint8_t flag
Definition wm_window.cc:145