2 * ***** BEGIN GPL LICENSE BLOCK *****
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version 2
7 * of the License, or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software Foundation,
16 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * The Original Code is Copyright (C) 2008 Blender Foundation.
19 * All rights reserved.
22 * Contributor(s): Blender Foundation
24 * ***** END GPL LICENSE BLOCK *****
27 /** \file blender/editors/space_view3d/view3d_ops.c
36 #include "DNA_collection_types.h"
37 #include "DNA_object_types.h"
38 #include "DNA_scene_types.h"
39 #include "DNA_screen_types.h"
40 #include "DNA_space_types.h"
41 #include "DNA_view3d_types.h"
43 #include "BLI_blenlib.h"
44 #include "BLI_utildefines.h"
46 #include "BKE_appdir.h"
47 #include "BKE_blender_copybuffer.h"
48 #include "BKE_collection.h"
49 #include "BKE_context.h"
51 #include "BKE_report.h"
53 #include "RNA_access.h"
54 #include "RNA_define.h"
59 #include "ED_screen.h"
60 #include "ED_select_utils.h"
61 #include "ED_transform.h"
63 #include "view3d_intern.h"
66 # include "BLI_math_base.h" /* M_PI */
69 /* ************************** copy paste ***************************** */
71 static int view3d_copybuffer_exec(bContext *C, wmOperator *op)
73 Main *bmain = CTX_data_main(C);
76 BKE_copybuffer_begin(bmain);
78 /* context, selection, could be generalized */
79 CTX_DATA_BEGIN (C, Object *, ob, selected_objects)
81 BKE_copybuffer_tag_ID(&ob->id);
85 for (Collection *collection = bmain->collection.first; collection; collection = collection->id.next) {
86 for (CollectionObject *cob = collection->gobject.first; cob; cob = cob->next) {
87 Object *object = cob->ob;
89 if (object && (object->id.tag & LIB_TAG_DOIT)) {
90 BKE_copybuffer_tag_ID(&collection->id);
91 /* don't expand out to all other objects */
92 collection->id.tag &= ~LIB_TAG_NEED_EXPAND;
98 BLI_make_file_string("/", str, BKE_tempdir_base(), "copybuffer.blend");
99 BKE_copybuffer_save(bmain, str, op->reports);
101 BKE_report(op->reports, RPT_INFO, "Copied selected objects to buffer");
103 return OPERATOR_FINISHED;
106 static void VIEW3D_OT_copybuffer(wmOperatorType *ot)
110 ot->name = "Copy Selection to Buffer";
111 ot->idname = "VIEW3D_OT_copybuffer";
112 ot->description = "Selected objects are saved in a temp file";
115 ot->exec = view3d_copybuffer_exec;
116 ot->poll = ED_operator_scene;
119 static int view3d_pastebuffer_exec(bContext *C, wmOperator *op)
124 if (RNA_boolean_get(op->ptr, "autoselect"))
125 flag |= FILE_AUTOSELECT;
126 if (RNA_boolean_get(op->ptr, "active_collection"))
127 flag |= FILE_ACTIVE_COLLECTION;
129 BLI_make_file_string("/", str, BKE_tempdir_base(), "copybuffer.blend");
130 if (BKE_copybuffer_paste(C, str, flag, op->reports)) {
131 WM_event_add_notifier(C, NC_WINDOW, NULL);
133 BKE_report(op->reports, RPT_INFO, "Objects pasted from buffer");
135 return OPERATOR_FINISHED;
138 BKE_report(op->reports, RPT_INFO, "No buffer to paste from");
140 return OPERATOR_CANCELLED;
143 static void VIEW3D_OT_pastebuffer(wmOperatorType *ot)
147 ot->name = "Paste Selection from Buffer";
148 ot->idname = "VIEW3D_OT_pastebuffer";
149 ot->description = "Contents of copy buffer gets pasted";
152 ot->exec = view3d_pastebuffer_exec;
153 ot->poll = ED_operator_scene_editable;
156 ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
158 RNA_def_boolean(ot->srna, "autoselect", true, "Select", "Select pasted objects");
159 RNA_def_boolean(ot->srna, "active_collection", true, "Active Collection", "Put pasted objects on the active collection");
162 /* ************************** registration **********************************/
164 void view3d_operatortypes(void)
166 WM_operatortype_append(VIEW3D_OT_rotate);
167 WM_operatortype_append(VIEW3D_OT_move);
168 WM_operatortype_append(VIEW3D_OT_zoom);
169 WM_operatortype_append(VIEW3D_OT_zoom_camera_1_to_1);
170 WM_operatortype_append(VIEW3D_OT_dolly);
171 #ifdef WITH_INPUT_NDOF
172 WM_operatortype_append(VIEW3D_OT_ndof_orbit_zoom);
173 WM_operatortype_append(VIEW3D_OT_ndof_orbit);
174 WM_operatortype_append(VIEW3D_OT_ndof_pan);
175 WM_operatortype_append(VIEW3D_OT_ndof_all);
176 #endif /* WITH_INPUT_NDOF */
177 WM_operatortype_append(VIEW3D_OT_view_all);
178 WM_operatortype_append(VIEW3D_OT_view_axis);
179 WM_operatortype_append(VIEW3D_OT_view_camera);
180 WM_operatortype_append(VIEW3D_OT_view_orbit);
181 WM_operatortype_append(VIEW3D_OT_view_roll);
182 WM_operatortype_append(VIEW3D_OT_view_pan);
183 WM_operatortype_append(VIEW3D_OT_view_persportho);
184 WM_operatortype_append(VIEW3D_OT_background_image_add);
185 WM_operatortype_append(VIEW3D_OT_background_image_remove);
186 WM_operatortype_append(VIEW3D_OT_view_selected);
187 WM_operatortype_append(VIEW3D_OT_view_lock_clear);
188 WM_operatortype_append(VIEW3D_OT_view_lock_to_active);
189 WM_operatortype_append(VIEW3D_OT_view_center_cursor);
190 WM_operatortype_append(VIEW3D_OT_view_center_pick);
191 WM_operatortype_append(VIEW3D_OT_view_center_camera);
192 WM_operatortype_append(VIEW3D_OT_view_center_lock);
193 WM_operatortype_append(VIEW3D_OT_select);
194 WM_operatortype_append(VIEW3D_OT_select_box);
195 WM_operatortype_append(VIEW3D_OT_clip_border);
196 WM_operatortype_append(VIEW3D_OT_select_circle);
197 WM_operatortype_append(VIEW3D_OT_smoothview);
198 WM_operatortype_append(VIEW3D_OT_render_border);
199 WM_operatortype_append(VIEW3D_OT_clear_render_border);
200 WM_operatortype_append(VIEW3D_OT_zoom_border);
201 WM_operatortype_append(VIEW3D_OT_cursor3d);
202 WM_operatortype_append(VIEW3D_OT_select_lasso);
203 WM_operatortype_append(VIEW3D_OT_select_menu);
204 WM_operatortype_append(VIEW3D_OT_camera_to_view);
205 WM_operatortype_append(VIEW3D_OT_camera_to_view_selected);
206 WM_operatortype_append(VIEW3D_OT_object_as_camera);
207 WM_operatortype_append(VIEW3D_OT_localview);
208 WM_operatortype_append(VIEW3D_OT_localview_remove_from);
209 WM_operatortype_append(VIEW3D_OT_fly);
210 WM_operatortype_append(VIEW3D_OT_walk);
211 WM_operatortype_append(VIEW3D_OT_navigate);
212 WM_operatortype_append(VIEW3D_OT_copybuffer);
213 WM_operatortype_append(VIEW3D_OT_pastebuffer);
215 WM_operatortype_append(VIEW3D_OT_properties);
216 WM_operatortype_append(VIEW3D_OT_object_mode_pie_or_toggle);
217 WM_operatortype_append(VIEW3D_OT_toolshelf);
219 WM_operatortype_append(VIEW3D_OT_snap_selected_to_grid);
220 WM_operatortype_append(VIEW3D_OT_snap_selected_to_cursor);
221 WM_operatortype_append(VIEW3D_OT_snap_selected_to_active);
222 WM_operatortype_append(VIEW3D_OT_snap_cursor_to_grid);
223 WM_operatortype_append(VIEW3D_OT_snap_cursor_to_center);
224 WM_operatortype_append(VIEW3D_OT_snap_cursor_to_selected);
225 WM_operatortype_append(VIEW3D_OT_snap_cursor_to_active);
227 WM_operatortype_append(VIEW3D_OT_toggle_shading);
228 WM_operatortype_append(VIEW3D_OT_toggle_xray);
229 WM_operatortype_append(VIEW3D_OT_toggle_matcap_flip);
231 WM_operatortype_append(VIEW3D_OT_ruler_add);
233 transform_operatortypes();
236 void view3d_keymap(wmKeyConfig *keyconf)
238 WM_keymap_ensure(keyconf, "3D View Generic", SPACE_VIEW3D, 0);
240 /* only for region 3D window */
241 WM_keymap_ensure(keyconf, "3D View", SPACE_VIEW3D, 0);
243 fly_modal_keymap(keyconf);
244 walk_modal_keymap(keyconf);
245 viewrotate_modal_keymap(keyconf);
246 viewmove_modal_keymap(keyconf);
247 viewzoom_modal_keymap(keyconf);
248 viewdolly_modal_keymap(keyconf);