Welcome to mirror list, hosted at ThFree Co, Russian Federation.

collections_ops.c « space_collections « editors « blender « source - git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 7e1bf8091b033b60f9b3dcc342adc01de39c2ff6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
/*
 * ***** BEGIN GPL LICENSE BLOCK *****
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 *
 * ***** END GPL LICENSE BLOCK *****
 */

/** \file blender/editors/space_collections/collections_ops.c
 *  \ingroup spcollections
 */

#include "BKE_context.h"
#include "BKE_layer.h"
#include "BKE_report.h"

#include "ED_screen.h"

#include "WM_api.h"
#include "WM_types.h"

#include "RNA_access.h"
#include "RNA_define.h"

#include "collections_intern.h" /* own include */

/* -------------------------------------------------------------------- */
/* polls */

static SceneCollection *collection_manager_collection_active(bContext *C)
{
	TODO_LAYER_OPERATORS;
	/* consider that we may have overrides active
	 * leading to no active collections */
	return CTX_data_scene_collection(C);
}

static int operator_not_master_collection_active(bContext *C)
{
	SceneCollection *sc = collection_manager_collection_active(C);
	if (sc == NULL) {
		return 1;
	}

	return  (sc == BKE_collection_master(CTX_data_scene(C))) ? 0 : 1;
}

static int operator_top_collection_active(bContext *C)
{
	SceneCollection *sc = collection_manager_collection_active(C);
	if (sc == NULL) {
		return 0;
	}

	TODO_LAYER_OPERATORS;
	/* see if it's a top collection */
	return 1;
}

static int operator_collection_active(bContext *C)
{
	return collection_manager_collection_active(C) ? 1 : 0;
}

/* -------------------------------------------------------------------- */
/* collection manager operators */

static int collection_link_invoke(bContext *UNUSED(C), wmOperator *op, const wmEvent *UNUSED(event))
{
	TODO_LAYER_OPERATORS;
	BKE_report(op->reports, RPT_ERROR, "COLLECTIONS_OT_collection_link not implemented yet");
	return OPERATOR_CANCELLED;
}

static void COLLECTIONS_OT_collection_link(wmOperatorType *ot)
{
	/* identifiers */
	ot->name = "Add Collection";
	ot->idname = "COLLECTIONS_OT_collection_link";
	ot->description = "Link a new collection to the active layer";

	/* api callbacks */
	ot->invoke = collection_link_invoke;

	/* flags */
	ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
}

static int collection_unlink_invoke(bContext *UNUSED(C), wmOperator *op, const wmEvent *UNUSED(event))
{
	TODO_LAYER_OPERATORS;
	BKE_report(op->reports, RPT_ERROR, "COLLECTIONS_OT_collection_unlink not implemented yet");
	return OPERATOR_CANCELLED;
}

static void COLLECTIONS_OT_collection_unlink(wmOperatorType *ot)
{
	/* identifiers */
	ot->name = "Add Collection";
	ot->idname = "COLLECTIONS_OT_collection_unlink";
	ot->description = "Link a new collection to the active layer";

	/* api callbacks */
	ot->invoke = collection_unlink_invoke;
	ot->poll = operator_top_collection_active;

	/* flags */
	ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
}

static int collection_new_exec(bContext *C, wmOperator *UNUSED(op))
{
	Scene *scene = CTX_data_scene(C);
	SceneLayer *sl = CTX_data_scene_layer(C);

	SceneCollection *sc = BKE_collection_add(scene, NULL, NULL);
	BKE_collection_link(sl, sc);

	WM_main_add_notifier(NC_SCENE | ND_LAYER, NULL);
	return OPERATOR_FINISHED;
}

static void COLLECTIONS_OT_collection_new(wmOperatorType *ot)
{
	/* identifiers */
	ot->name = "New Collection";
	ot->idname = "COLLECTIONS_OT_collection_new";
	ot->description = "Add a new collection to the scene, and link it to the active layer";

	/* api callbacks */
	ot->exec = collection_new_exec;

	/* flags */
	ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
}

static int override_new_invoke(bContext *UNUSED(C), wmOperator *op, const wmEvent *UNUSED(event))
{
	TODO_LAYER_OPERATORS;
	TODO_LAYER_OVERRIDE;
	BKE_report(op->reports, RPT_ERROR, "COLLECTIONS_OT_override_new not implemented yet");
	return OPERATOR_CANCELLED;
}

static void COLLECTIONS_OT_override_new(wmOperatorType *ot)
{
	/* identifiers */
	ot->name = "New Override";
	ot->idname = "COLLECTIONS_OT_override_new";
	ot->description = "Add a new override to the active collection";

	/* api callbacks */
	ot->invoke = override_new_invoke;
	ot->poll = operator_collection_active;

	/* flags */
	ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
}

static int delete_invoke(bContext *UNUSED(C), wmOperator *op, const wmEvent *UNUSED(event))
{
	TODO_LAYER_OPERATORS;
	BKE_report(op->reports, RPT_ERROR, "COLLECTIONS_OT_delete not implemented yet");
	return OPERATOR_CANCELLED;
}

static void COLLECTIONS_OT_delete(wmOperatorType *ot)
{
	/* identifiers */
	ot->name = "Delete";
	ot->idname = "COLLECTIONS_OT_delete";
	ot->description = "Delete active  override or collection";

	/* api callbacks */
	ot->invoke = delete_invoke;
	ot->poll = operator_not_master_collection_active;

	/* flags */
	ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
}

static int select_exec(bContext *C, wmOperator *op)
{
	SceneLayer *sl = CTX_data_scene_layer(C);
	const int collection_index = RNA_int_get(op->ptr, "collection_index");
	sl->active_collection = collection_index;
	WM_main_add_notifier(NC_SCENE | ND_LAYER, NULL);
	return OPERATOR_FINISHED;
}

static void COLLECTIONS_OT_select(wmOperatorType *ot)
{
	/* identifiers */
	ot->name = "Select";
	ot->idname = "COLLECTIONS_OT_select";
	ot->description = "Change active collection or override";

	/* api callbacks */
	ot->exec = select_exec;

	/* flags */
	ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;

	RNA_def_int(ot->srna, "collection_index", 0, 0, INT_MAX, "Index",
	            "Index of collection to select", 0, INT_MAX);
}

static int rename_invoke(bContext *UNUSED(C), wmOperator *op, const wmEvent *UNUSED(event))
{
	TODO_LAYER_OPERATORS;
	BKE_report(op->reports, RPT_ERROR, "COLLECTIONS_rename not implemented yet");
	return OPERATOR_CANCELLED;
}

static void COLLECTIONS_OT_rename(wmOperatorType *ot)
{
	/* identifiers */
	ot->name = "Rename";
	ot->idname = "COLLECTIONS_OT_rename";
	ot->description = "Rename active collection or override";

	/* api callbacks */
	ot->invoke = rename_invoke;
	ot->poll = operator_not_master_collection_active;

	/* flags */
	ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
}

/* -------------------------------------------------------------------- */
/* property editor operators */

static int stubs_invoke(bContext *UNUSED(C), wmOperator *op, const wmEvent *UNUSED(event))
{
	TODO_LAYER_OPERATORS;
	BKE_report(op->reports, RPT_ERROR, "Operator not implemented yet");
	return OPERATOR_CANCELLED;
}

static void COLLECTIONS_OT_objects_add(wmOperatorType *ot)
{
	/* identifiers */
	ot->name = "Add Objects";
	ot->idname = "COLLECTIONS_OT_objects_add";
	ot->description = "Add selected objects to collection";

	/* api callbacks */
	ot->invoke = stubs_invoke;

	/* flags */
	ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
}

static void COLLECTIONS_OT_objects_remove(wmOperatorType *ot)
{
	/* identifiers */
	ot->name = "Remove Object";
	ot->idname = "COLLECTIONS_OT_objects_remove";
	ot->description = "Remove object from collection";

	/* api callbacks */
	ot->invoke = stubs_invoke;

	/* flags */
	ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
}

static void COLLECTIONS_OT_objects_select(wmOperatorType *ot)
{
	/* identifiers */
	ot->name = "Select Objects";
	ot->idname = "COLLECTIONS_OT_objects_select";
	ot->description = "Selected collection objects";

	/* api callbacks */
	ot->invoke = stubs_invoke;

	/* flags */
	ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
}

static void COLLECTIONS_OT_objects_deselect(wmOperatorType *ot)
{
	/* identifiers */
	ot->name = "Deselect Objects";
	ot->idname = "COLLECTIONS_OT_objects_deselect";
	ot->description = "Deselected collection objects";

	/* api callbacks */
	ot->invoke = stubs_invoke;

	/* flags */
	ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
}

/* ************************** registration - operator types **********************************/

void collections_operatortypes(void)
{
	WM_operatortype_append(COLLECTIONS_OT_delete);
	WM_operatortype_append(COLLECTIONS_OT_select);
	WM_operatortype_append(COLLECTIONS_OT_rename);
	WM_operatortype_append(COLLECTIONS_OT_collection_link);
	WM_operatortype_append(COLLECTIONS_OT_collection_unlink);
	WM_operatortype_append(COLLECTIONS_OT_collection_new);
	WM_operatortype_append(COLLECTIONS_OT_override_new);

	WM_operatortype_append(COLLECTIONS_OT_objects_add);
	WM_operatortype_append(COLLECTIONS_OT_objects_remove);
	WM_operatortype_append(COLLECTIONS_OT_objects_select);
	WM_operatortype_append(COLLECTIONS_OT_objects_deselect);
}

void collections_keymap(wmKeyConfig *keyconf)
{
	wmKeyMap *keymap = WM_keymap_find(keyconf, "Collections Manager", SPACE_COLLECTIONS, 0);

	/* selection */
	WM_keymap_add_item(keymap, "COLLECTIONS_OT_select", LEFTMOUSE, KM_CLICK, 0, 0);

	WM_keymap_add_item(keymap, "COLLECTIONS_OT_rename", LEFTMOUSE, KM_DBL_CLICK, 0, 0);
	WM_keymap_add_item(keymap, "COLLECTIONS_OT_rename", LEFTMOUSE, KM_PRESS, KM_CTRL, 0);

	WM_keymap_add_item(keymap, "COLLECTIONS_OT_collection_new", NKEY, KM_PRESS, KM_CTRL, 0);

	WM_keymap_add_item(keymap, "COLLECTIONS_OT_delete", XKEY, KM_PRESS, 0, 0);
	WM_keymap_add_item(keymap, "COLLECTIONS_OT_delete", DELKEY, KM_PRESS, 0, 0);
}