Cleanup: Remove seq->tmp_flag DNA member
[blender.git] / source / blender / editors / space_view3d / view3d_ops.c
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
20 /** \file
21  * \ingroup spview3d
22  */
23
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
60 static int view3d_copybuffer_exec(bContext *C, wmOperator *op)
61 {
62   Main *bmain = CTX_data_main(C);
63   char str[FILE_MAX];
64   int num_copied = 0;
65
66   BKE_copybuffer_copy_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_copy_tag_ID(&ob->id);
72       num_copied++;
73     }
74   }
75   CTX_DATA_END;
76
77   BLI_join_dirfile(str, sizeof(str), BKE_tempdir_base(), "copybuffer.blend");
78   BKE_copybuffer_copy_end(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
85 static void VIEW3D_OT_copybuffer(wmOperatorType *ot)
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 */
93   ot->exec = view3d_copybuffer_exec;
94   ot->poll = ED_operator_scene;
95 }
96
97 static int view3d_pastebuffer_exec(bContext *C, wmOperator *op)
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
117   WM_event_add_notifier(C, NC_WINDOW, NULL);
118   ED_outliner_select_sync_from_object_tag(C);
119
120   BKE_reportf(op->reports, RPT_INFO, "%d object(s) pasted", num_pasted);
121
122   return OPERATOR_FINISHED;
123 }
124
125 static void VIEW3D_OT_pastebuffer(wmOperatorType *ot)
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 */
134   ot->exec = view3d_pastebuffer_exec;
135   ot->poll = ED_operator_scene_editable;
136
137   /* flags */
138   ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
139
140   RNA_def_boolean(ot->srna, "autoselect", true, "Select", "Select pasted objects");
141   RNA_def_boolean(ot->srna,
142                   "active_collection",
143                   true,
144                   "Active Collection",
145                   "Put pasted objects in the active collection");
146 }
147
148 /* ************************** registration **********************************/
149
150 void view3d_operatortypes(void)
151 {
152   WM_operatortype_append(VIEW3D_OT_rotate);
153   WM_operatortype_append(VIEW3D_OT_move);
154   WM_operatortype_append(VIEW3D_OT_zoom);
155   WM_operatortype_append(VIEW3D_OT_zoom_camera_1_to_1);
156   WM_operatortype_append(VIEW3D_OT_dolly);
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 */
163   WM_operatortype_append(VIEW3D_OT_view_all);
164   WM_operatortype_append(VIEW3D_OT_view_axis);
165   WM_operatortype_append(VIEW3D_OT_view_camera);
166   WM_operatortype_append(VIEW3D_OT_view_orbit);
167   WM_operatortype_append(VIEW3D_OT_view_roll);
168   WM_operatortype_append(VIEW3D_OT_view_pan);
169   WM_operatortype_append(VIEW3D_OT_view_persportho);
170   WM_operatortype_append(VIEW3D_OT_background_image_add);
171   WM_operatortype_append(VIEW3D_OT_background_image_remove);
172   WM_operatortype_append(VIEW3D_OT_drop_world);
173   WM_operatortype_append(VIEW3D_OT_view_selected);
174   WM_operatortype_append(VIEW3D_OT_view_lock_clear);
175   WM_operatortype_append(VIEW3D_OT_view_lock_to_active);
176   WM_operatortype_append(VIEW3D_OT_view_center_cursor);
177   WM_operatortype_append(VIEW3D_OT_view_center_pick);
178   WM_operatortype_append(VIEW3D_OT_view_center_camera);
179   WM_operatortype_append(VIEW3D_OT_view_center_lock);
180   WM_operatortype_append(VIEW3D_OT_select);
181   WM_operatortype_append(VIEW3D_OT_select_box);
182   WM_operatortype_append(VIEW3D_OT_clip_border);
183   WM_operatortype_append(VIEW3D_OT_select_circle);
184   WM_operatortype_append(VIEW3D_OT_smoothview);
185   WM_operatortype_append(VIEW3D_OT_render_border);
186   WM_operatortype_append(VIEW3D_OT_clear_render_border);
187   WM_operatortype_append(VIEW3D_OT_zoom_border);
188   WM_operatortype_append(VIEW3D_OT_cursor3d);
189   WM_operatortype_append(VIEW3D_OT_select_lasso);
190   WM_operatortype_append(VIEW3D_OT_select_menu);
191   WM_operatortype_append(VIEW3D_OT_bone_select_menu);
192   WM_operatortype_append(VIEW3D_OT_camera_to_view);
193   WM_operatortype_append(VIEW3D_OT_camera_to_view_selected);
194   WM_operatortype_append(VIEW3D_OT_object_as_camera);
195   WM_operatortype_append(VIEW3D_OT_localview);
196   WM_operatortype_append(VIEW3D_OT_localview_remove_from);
197   WM_operatortype_append(VIEW3D_OT_fly);
198   WM_operatortype_append(VIEW3D_OT_walk);
199   WM_operatortype_append(VIEW3D_OT_navigate);
200   WM_operatortype_append(VIEW3D_OT_copybuffer);
201   WM_operatortype_append(VIEW3D_OT_pastebuffer);
202
203   WM_operatortype_append(VIEW3D_OT_object_mode_pie_or_toggle);
204
205   WM_operatortype_append(VIEW3D_OT_snap_selected_to_grid);
206   WM_operatortype_append(VIEW3D_OT_snap_selected_to_cursor);
207   WM_operatortype_append(VIEW3D_OT_snap_selected_to_active);
208   WM_operatortype_append(VIEW3D_OT_snap_cursor_to_grid);
209   WM_operatortype_append(VIEW3D_OT_snap_cursor_to_center);
210   WM_operatortype_append(VIEW3D_OT_snap_cursor_to_selected);
211   WM_operatortype_append(VIEW3D_OT_snap_cursor_to_active);
212
213   WM_operatortype_append(VIEW3D_OT_interactive_add);
214
215   WM_operatortype_append(VIEW3D_OT_toggle_shading);
216   WM_operatortype_append(VIEW3D_OT_toggle_xray);
217   WM_operatortype_append(VIEW3D_OT_toggle_matcap_flip);
218
219   WM_operatortype_append(VIEW3D_OT_ruler_add);
220   WM_operatortype_append(VIEW3D_OT_ruler_remove);
221
222   transform_operatortypes();
223 }
224
225 void view3d_keymap(wmKeyConfig *keyconf)
226 {
227   WM_keymap_ensure(keyconf, "3D View Generic", SPACE_VIEW3D, 0);
228
229   /* only for region 3D window */
230   WM_keymap_ensure(keyconf, "3D View", SPACE_VIEW3D, 0);
231
232   fly_modal_keymap(keyconf);
233   walk_modal_keymap(keyconf);
234   viewrotate_modal_keymap(keyconf);
235   viewmove_modal_keymap(keyconf);
236   viewzoom_modal_keymap(keyconf);
237   viewdolly_modal_keymap(keyconf);
238   viewplace_modal_keymap(keyconf);
239 }