~siretart/ubuntu/utopic/blender/libav10

« back to all changes in this revision

Viewing changes to source/blender/editors/object/object_relations.c

  • Committer: Package Import Robot
  • Author(s): Matteo F. Vescovi
  • Date: 2012-07-23 08:54:18 UTC
  • mfrom: (14.2.16 sid)
  • mto: (14.2.19 sid)
  • mto: This revision was merged to the branch mainline in revision 42.
  • Revision ID: package-import@ubuntu.com-20120723085418-9foz30v6afaf5ffs
Tags: 2.63a-2
* debian/: Cycles support added (Closes: #658075)
  For now, this top feature has been enabled only
  on [any-amd64 any-i386] architectures because
  of OpenImageIO failing on all others
* debian/: scripts installation path changed
  from /usr/lib to /usr/share:
  + debian/patches/: patchset re-worked for path changing
  + debian/control: "Breaks" field added on yafaray-exporter

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/**
2
 
 * $Id: object_relations.c 30277 2010-07-13 16:53:17Z campbellbarton $
3
 
 *
 
1
/*
4
2
 * ***** BEGIN GPL LICENSE BLOCK *****
5
3
 *
6
4
 * This program is free software; you can redistribute it and/or
25
23
 * ***** END GPL LICENSE BLOCK *****
26
24
 */
27
25
 
 
26
/** \file blender/editors/object/object_relations.c
 
27
 *  \ingroup edobj
 
28
 */
 
29
 
 
30
 
28
31
#include <stdio.h>
29
32
#include <stdlib.h>
30
33
#include <string.h>
32
35
#include "MEM_guardedalloc.h"
33
36
 
34
37
#include "DNA_anim_types.h"
 
38
#include "DNA_mesh_types.h"
35
39
#include "DNA_constraint_types.h"
36
40
#include "DNA_group_types.h"
37
41
#include "DNA_lamp_types.h"
40
44
#include "DNA_meta_types.h"
41
45
#include "DNA_particle_types.h"
42
46
#include "DNA_scene_types.h"
 
47
#include "DNA_speaker_types.h"
43
48
#include "DNA_world_types.h"
 
49
#include "DNA_object_types.h"
44
50
 
45
51
#include "BLI_math.h"
46
 
#include "BLI_editVert.h"
47
52
#include "BLI_listbase.h"
48
53
#include "BLI_string.h"
 
54
#include "BLI_utildefines.h"
49
55
 
50
56
#include "BKE_action.h"
51
57
#include "BKE_animsys.h"
52
58
#include "BKE_armature.h"
 
59
#include "BKE_camera.h"
53
60
#include "BKE_context.h"
54
61
#include "BKE_constraint.h"
55
62
#include "BKE_curve.h"
56
63
#include "BKE_depsgraph.h"
 
64
#include "BKE_DerivedMesh.h"
57
65
#include "BKE_displist.h"
58
66
#include "BKE_global.h"
 
67
#include "BKE_fcurve.h"
 
68
#include "BKE_lamp.h"
59
69
#include "BKE_lattice.h"
60
70
#include "BKE_library.h"
61
71
#include "BKE_main.h"
67
77
#include "BKE_report.h"
68
78
#include "BKE_sca.h"
69
79
#include "BKE_scene.h"
 
80
#include "BKE_speaker.h"
70
81
#include "BKE_texture.h"
71
 
#include "BKE_utildefines.h"
 
82
#include "BKE_tessmesh.h"
72
83
 
73
84
#include "WM_api.h"
74
85
#include "WM_types.h"
82
93
 
83
94
#include "ED_armature.h"
84
95
#include "ED_curve.h"
 
96
#include "ED_keyframing.h"
85
97
#include "ED_object.h"
 
98
#include "ED_mesh.h"
86
99
#include "ED_screen.h"
87
100
#include "ED_view3d.h"
88
101
 
97
110
 
98
111
static int vertex_parent_set_exec(bContext *C, wmOperator *op)
99
112
{
 
113
        Main *bmain= CTX_data_main(C);
100
114
        Scene *scene= CTX_data_scene(C);
101
115
        Object *obedit= CTX_data_edit_object(C);
102
 
        EditVert *eve;
 
116
        BMVert *eve;
 
117
        BMIter iter;
103
118
        Curve *cu;
104
119
        Nurb *nu;
105
120
        BezTriple *bezt;
109
124
        
110
125
        /* we need 1 to 3 selected vertices */
111
126
        
112
 
        if(obedit->type==OB_MESH) {
 
127
        if (obedit->type==OB_MESH) {
113
128
                Mesh *me= obedit->data;
114
 
                EditMesh *em = BKE_mesh_get_editmesh(me);
115
 
 
116
 
                eve= em->verts.first;
117
 
                while(eve) {
118
 
                        if(eve->f & 1) {
119
 
                                if(v1==0) v1= nr;
120
 
                                else if(v2==0) v2= nr;
121
 
                                else if(v3==0) v3= nr;
122
 
                                else if(v4==0) v4= nr;
 
129
                BMEditMesh *em;
 
130
 
 
131
                EDBM_mesh_load(obedit);
 
132
                EDBM_mesh_make(scene->toolsettings, scene, obedit);
 
133
 
 
134
                em= me->edit_btmesh;
 
135
 
 
136
                /* derivedMesh might be needed for solving parenting,
 
137
                 * so re-create it here */
 
138
                makeDerivedMesh(scene, obedit, em, CD_MASK_BAREMESH, 0);
 
139
 
 
140
                BM_ITER_MESH (eve, &iter, em->bm, BM_VERTS_OF_MESH) {
 
141
                        if (BM_elem_flag_test(eve, BM_ELEM_SELECT)) {
 
142
                                if (v1==0) v1= nr;
 
143
                                else if (v2==0) v2= nr;
 
144
                                else if (v3==0) v3= nr;
 
145
                                else if (v4==0) v4= nr;
123
146
                                else break;
124
147
                        }
125
148
                        nr++;
126
 
                        eve= eve->next;
127
149
                }
128
 
 
129
 
                BKE_mesh_end_editmesh(me, em);
130
150
        }
131
 
        else if(ELEM(obedit->type, OB_SURF, OB_CURVE)) {
132
 
                ListBase *editnurb= curve_get_editcurve(obedit);
 
151
        else if (ELEM(obedit->type, OB_SURF, OB_CURVE)) {
 
152
                ListBase *editnurb= object_editcurve_get(obedit);
133
153
                
134
154
                cu= obedit->data;
135
155
 
136
156
                nu= editnurb->first;
137
 
                while(nu) {
138
 
                        if(nu->type == CU_BEZIER) {
 
157
                while (nu) {
 
158
                        if (nu->type == CU_BEZIER) {
139
159
                                bezt= nu->bezt;
140
160
                                a= nu->pntsu;
141
 
                                while(a--) {
142
 
                                        if(BEZSELECTED_HIDDENHANDLES(cu, bezt)) {
143
 
                                                if(v1==0) v1= nr;
144
 
                                                else if(v2==0) v2= nr;
145
 
                                                else if(v3==0) v3= nr;
146
 
                                                else if(v4==0) v4= nr;
 
161
                                while (a--) {
 
162
                                        if (BEZSELECTED_HIDDENHANDLES(cu, bezt)) {
 
163
                                                if (v1==0) v1= nr;
 
164
                                                else if (v2==0) v2= nr;
 
165
                                                else if (v3==0) v3= nr;
 
166
                                                else if (v4==0) v4= nr;
147
167
                                                else break;
148
168
                                        }
149
169
                                        nr++;
153
173
                        else {
154
174
                                bp= nu->bp;
155
175
                                a= nu->pntsu*nu->pntsv;
156
 
                                while(a--) {
157
 
                                        if(bp->f1 & SELECT) {
158
 
                                                if(v1==0) v1= nr;
159
 
                                                else if(v2==0) v2= nr;
160
 
                                                else if(v3==0) v3= nr;
161
 
                                                else if(v4==0) v4= nr;
 
176
                                while (a--) {
 
177
                                        if (bp->f1 & SELECT) {
 
178
                                                if (v1==0) v1= nr;
 
179
                                                else if (v2==0) v2= nr;
 
180
                                                else if (v3==0) v3= nr;
 
181
                                                else if (v4==0) v4= nr;
162
182
                                                else break;
163
183
                                        }
164
184
                                        nr++;
168
188
                        nu= nu->next;
169
189
                }
170
190
        }
171
 
        else if(obedit->type==OB_LATTICE) {
 
191
        else if (obedit->type==OB_LATTICE) {
172
192
                Lattice *lt= obedit->data;
173
193
                
174
 
                a= lt->editlatt->pntsu*lt->editlatt->pntsv*lt->editlatt->pntsw;
175
 
                bp= lt->editlatt->def;
176
 
                while(a--) {
177
 
                        if(bp->f1 & SELECT) {
178
 
                                if(v1==0) v1= nr;
179
 
                                else if(v2==0) v2= nr;
180
 
                                else if(v3==0) v3= nr;
181
 
                                else if(v4==0) v4= nr;
 
194
                a= lt->editlatt->latt->pntsu*lt->editlatt->latt->pntsv*lt->editlatt->latt->pntsw;
 
195
                bp= lt->editlatt->latt->def;
 
196
                while (a--) {
 
197
                        if (bp->f1 & SELECT) {
 
198
                                if (v1==0) v1= nr;
 
199
                                else if (v2==0) v2= nr;
 
200
                                else if (v3==0) v3= nr;
 
201
                                else if (v4==0) v4= nr;
182
202
                                else break;
183
203
                        }
184
204
                        nr++;
186
206
                }
187
207
        }
188
208
        
189
 
        if(v4 || !((v1 && v2==0 && v3==0) || (v1 && v2 && v3)) ) {
 
209
        if (v4 || !((v1 && v2==0 && v3==0) || (v1 && v2 && v3)) ) {
190
210
                BKE_report(op->reports, RPT_ERROR, "Select either 1 or 3 vertices to parent to");
191
211
                return OPERATOR_CANCELLED;
192
212
        }
193
213
        
194
214
        CTX_DATA_BEGIN(C, Object*, ob, selected_editable_objects) {
195
 
                if(ob != obedit) {
196
 
                        ob->recalc |= OB_RECALC_ALL;
 
215
                if (ob != obedit) {
 
216
                        ob->recalc |= OB_RECALC_OB|OB_RECALC_DATA|OB_RECALC_TIME;
197
217
                        par= obedit->parent;
198
218
                        
199
 
                        while(par) {
200
 
                                if(par==ob) break;
 
219
                        while (par) {
 
220
                                if (par==ob) break;
201
221
                                par= par->parent;
202
222
                        }
203
 
                        if(par) {
 
223
                        if (par) {
204
224
                                BKE_report(op->reports, RPT_ERROR, "Loop in parents");
205
225
                        }
206
226
                        else {
207
227
                                Object workob;
208
228
                                
209
229
                                ob->parent= BASACT->object;
210
 
                                if(v3) {
 
230
                                if (v3) {
211
231
                                        ob->partype= PARVERT3;
212
232
                                        ob->par1= v1-1;
213
233
                                        ob->par2= v2-1;
230
250
        }
231
251
        CTX_DATA_END;
232
252
        
233
 
        DAG_scene_sort(scene);
 
253
        DAG_scene_sort(bmain, scene);
234
254
 
235
255
        WM_event_add_notifier(C, NC_OBJECT, NULL);
236
256
 
240
260
void OBJECT_OT_vertex_parent_set(wmOperatorType *ot)
241
261
{
242
262
        /* identifiers */
243
 
        ot->name= "Make Vertex Parent";
 
263
        ot->name = "Make Vertex Parent";
244
264
        ot->description = "Parent selected objects to the selected vertices";
245
 
        ot->idname= "OBJECT_OT_vertex_parent_set";
 
265
        ot->idname = "OBJECT_OT_vertex_parent_set";
246
266
        
247
267
        /* api callbacks */
248
 
        ot->invoke= WM_operator_confirm;
249
 
        ot->poll= vertex_parent_set_poll;
250
 
        ot->exec= vertex_parent_set_exec;
 
268
        ot->invoke = WM_operator_confirm;
 
269
        ot->poll = vertex_parent_set_poll;
 
270
        ot->exec = vertex_parent_set_exec;
251
271
        
252
272
        /* flags */
253
 
        ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
 
273
        ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO;
254
274
}
255
275
 
256
276
/********************** Make Proxy Operator *************************/
259
279
static int make_proxy_invoke (bContext *C, wmOperator *op, wmEvent *evt)
260
280
{
261
281
        Scene *scene= CTX_data_scene(C);
262
 
        Object *ob= CTX_data_active_object(C);
 
282
        Object *ob= ED_object_active_context(C);
263
283
        
264
284
        /* sanity checks */
265
285
        if (!scene || scene->id.lib || !ob)
276
296
        else if (ob->id.lib) {
277
297
                uiPopupMenu *pup= uiPupMenuBegin(C, "OK?", ICON_QUESTION);
278
298
                uiLayout *layout= uiPupMenuLayout(pup);
279
 
                PointerRNA props_ptr;
280
299
                
281
300
                /* create operator menu item with relevant properties filled in */
282
 
                props_ptr= uiItemFullO(layout, op->idname, op->type->name, 0, NULL, WM_OP_EXEC_REGION_WIN, UI_ITEM_O_RETURN_PROPS);
 
301
                uiItemFullO_ptr(layout, op->type, op->type->name, ICON_NONE, NULL, WM_OP_EXEC_REGION_WIN, UI_ITEM_O_RETURN_PROPS);
283
302
                
284
303
                /* present the menu and be done... */
285
304
                uiPupMenuEnd(C, pup);
295
314
 
296
315
static int make_proxy_exec (bContext *C, wmOperator *op)
297
316
{
298
 
        Object *ob, *gob= CTX_data_active_object(C);
 
317
        Main *bmain= CTX_data_main(C);
 
318
        Object *ob, *gob= ED_object_active_context(C);
299
319
        GroupObject *go;
300
320
        Scene *scene= CTX_data_scene(C);
301
321
 
302
 
        if (gob->dup_group != NULL)
303
 
        {
304
 
                go= BLI_findlink(&gob->dup_group->gobject, RNA_enum_get(op->ptr, "type"));
 
322
        if (gob->dup_group != NULL) {
 
323
                go= BLI_findlink(&gob->dup_group->gobject, RNA_enum_get(op->ptr, "object"));
305
324
                ob= go->ob;
306
325
        }
307
 
        else
308
 
        {
 
326
        else {
309
327
                ob= gob;
310
328
                gob = NULL;
311
329
        }
313
331
        if (ob) {
314
332
                Object *newob;
315
333
                Base *newbase, *oldbase= BASACT;
316
 
                char name[32];
 
334
                char name[MAX_ID_NAME+4];
317
335
                
318
336
                /* Add new object for the proxy */
319
337
                newob= add_object(scene, OB_EMPTY);
320
 
                if (gob)
321
 
                        strcpy(name, gob->id.name+2);
322
 
                else
323
 
                        strcpy(name, ob->id.name+2);
324
 
                strcat(name, "_proxy");
 
338
 
 
339
                BLI_snprintf(name, sizeof(name), "%s_proxy", ((ID *)(gob ? gob : ob))->name+2);
 
340
 
325
341
                rename_id(&newob->id, name);
326
342
                
327
343
                /* set layers OK */
338
354
                object_make_proxy(newob, ob, gob);
339
355
                
340
356
                /* depsgraph flushes are needed for the new data */
341
 
                DAG_scene_sort(scene);
342
 
                DAG_id_flush_update(&newob->id, OB_RECALC_ALL);
 
357
                DAG_scene_sort(bmain, scene);
 
358
                DAG_id_tag_update(&newob->id, OB_RECALC_OB|OB_RECALC_DATA|OB_RECALC_TIME);
343
359
                WM_event_add_notifier(C, NC_OBJECT|ND_DRAW, newob);
344
360
        }
345
361
        else {
351
367
}
352
368
 
353
369
/* Generic itemf's for operators that take library args */
354
 
static EnumPropertyItem *proxy_group_object_itemf(bContext *C, PointerRNA *ptr, int *free)
 
370
static EnumPropertyItem *proxy_group_object_itemf(bContext *C, PointerRNA *UNUSED(ptr), PropertyRNA *UNUSED(prop), int *free)
355
371
{
356
 
        EnumPropertyItem *item= NULL, item_tmp;
 
372
        EnumPropertyItem item_tmp= {0}, *item= NULL;
357
373
        int totitem= 0;
358
374
        int i= 0;
359
 
        Object *ob= CTX_data_active_object(C);
 
375
        Object *ob= ED_object_active_context(C);
360
376
        GroupObject *go;
361
377
 
362
 
        if(!ob || !ob->dup_group)
 
378
        if (!ob || !ob->dup_group)
363
379
                return DummyRNA_DEFAULT_items;
364
380
 
365
 
        memset(&item_tmp, 0, sizeof(item_tmp));
366
 
 
367
381
        /* find the object to affect */
368
382
        for (go= ob->dup_group->gobject.first; go; go= go->next) {
369
383
                item_tmp.identifier= item_tmp.name= go->ob->id.name+2;
382
396
        PropertyRNA *prop;
383
397
 
384
398
        /* identifiers */
385
 
        ot->name= "Make Proxy";
386
 
        ot->idname= "OBJECT_OT_proxy_make";
387
 
        ot->description= "Add empty object to become local replacement data of a library-linked object";
 
399
        ot->name = "Make Proxy";
 
400
        ot->idname = "OBJECT_OT_proxy_make";
 
401
        ot->description = "Add empty object to become local replacement data of a library-linked object";
388
402
        
389
403
        /* callbacks */
390
 
        ot->invoke= make_proxy_invoke;
391
 
        ot->exec= make_proxy_exec;
392
 
        ot->poll= ED_operator_object_active;
 
404
        ot->invoke = make_proxy_invoke;
 
405
        ot->exec = make_proxy_exec;
 
406
        ot->poll = ED_operator_object_active;
393
407
        
394
408
        /* flags */
395
 
        ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
 
409
        ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO;
396
410
        
397
411
        /* properties */
398
 
        RNA_def_string(ot->srna, "object", "", 19, "Proxy Object", "Name of lib-linked/grouped object to make a proxy for.");
399
 
        prop= RNA_def_enum(ot->srna, "type", DummyRNA_DEFAULT_items, 0, "Type", "Group object"); /* XXX, relies on hard coded ID at the moment */
 
412
        prop= RNA_def_enum(ot->srna, "object", DummyRNA_DEFAULT_items, 0, "Proxy Object", "Name of lib-linked/grouped object to make a proxy for"); /* XXX, relies on hard coded ID at the moment */
400
413
        RNA_def_enum_funcs(prop, proxy_group_object_itemf);
401
 
        ot->prop= prop;
 
414
        ot->prop = prop;
402
415
}
403
416
 
404
417
/********************** Clear Parent Operator ******************* */
405
418
 
406
 
static EnumPropertyItem prop_clear_parent_types[] = {
 
419
EnumPropertyItem prop_clear_parent_types[] = {
407
420
        {0, "CLEAR", 0, "Clear Parent", ""},
408
421
        {1, "CLEAR_KEEP_TRANSFORM", 0, "Clear and Keep Transformation", ""},
409
422
        {2, "CLEAR_INVERSE", 0, "Clear Parent Inverse", ""},
410
423
        {0, NULL, 0, NULL, NULL}
411
424
};
412
425
 
 
426
void ED_object_parent_clear(bContext *C, int type)
 
427
{
 
428
        Main *bmain= CTX_data_main(C);
 
429
        Scene *scene= CTX_data_scene(C);
 
430
 
 
431
        CTX_DATA_BEGIN(C, Object*, ob, selected_editable_objects) 
 
432
        {
 
433
                if (ob->parent == NULL)
 
434
                        continue;
 
435
                
 
436
                if (type == 0) {
 
437
                        ob->parent= NULL;
 
438
                }
 
439
                else if (type == 1) {
 
440
                        ob->parent= NULL;
 
441
                        object_apply_mat4(ob, ob->obmat, TRUE, FALSE);
 
442
                }
 
443
                else if (type == 2)
 
444
                        unit_m4(ob->parentinv);
 
445
                
 
446
                ob->recalc |= OB_RECALC_OB|OB_RECALC_DATA|OB_RECALC_TIME;
 
447
        }
 
448
        CTX_DATA_END;
 
449
 
 
450
        DAG_scene_sort(bmain, scene);
 
451
        DAG_ids_flush_update(bmain, 0);
 
452
        WM_event_add_notifier(C, NC_OBJECT|ND_TRANSFORM, NULL);
 
453
        WM_event_add_notifier(C, NC_OBJECT|ND_PARENT, NULL);
 
454
}
 
455
 
413
456
/* note, poll should check for editable scene */
414
457
static int parent_clear_exec(bContext *C, wmOperator *op)
415
458
{
416
 
        int type= RNA_enum_get(op->ptr, "type");
417
 
        
418
 
        CTX_DATA_BEGIN(C, Object*, ob, selected_editable_objects) {
419
 
 
420
 
                if(type == 0) {
421
 
                        ob->parent= NULL;
422
 
                }                       
423
 
                else if(type == 1) {
424
 
                        ob->parent= NULL;
425
 
                        object_apply_mat4(ob, ob->obmat);
426
 
                }
427
 
                else if(type == 2)
428
 
                        unit_m4(ob->parentinv);
429
 
 
430
 
                ob->recalc |= OB_RECALC_ALL;
431
 
        }
432
 
        CTX_DATA_END;
433
 
        
434
 
        DAG_scene_sort(CTX_data_scene(C));
435
 
        DAG_ids_flush_update(0);
436
 
        WM_event_add_notifier(C, NC_OBJECT|ND_TRANSFORM, NULL);
 
459
        ED_object_parent_clear(C, RNA_enum_get(op->ptr, "type"));
437
460
 
438
461
        return OPERATOR_FINISHED;
439
462
}
441
464
void OBJECT_OT_parent_clear(wmOperatorType *ot)
442
465
{
443
466
        /* identifiers */
444
 
        ot->name= "Clear Parent";
 
467
        ot->name = "Clear Parent";
445
468
        ot->description = "Clear the object's parenting";
446
 
        ot->idname= "OBJECT_OT_parent_clear";
 
469
        ot->idname = "OBJECT_OT_parent_clear";
447
470
        
448
471
        /* api callbacks */
449
 
        ot->invoke= WM_menu_invoke;
450
 
        ot->exec= parent_clear_exec;
 
472
        ot->invoke = WM_menu_invoke;
 
473
        ot->exec = parent_clear_exec;
451
474
        
452
 
        ot->poll= ED_operator_object_active_editable;
 
475
        ot->poll = ED_operator_object_active_editable;
453
476
        
454
477
        /* flags */
455
 
        ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
 
478
        ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO;
456
479
        
457
 
        ot->prop= RNA_def_enum(ot->srna, "type", prop_clear_parent_types, 0, "Type", "");
 
480
        ot->prop = RNA_def_enum(ot->srna, "type", prop_clear_parent_types, 0, "Type", "");
458
481
}
459
482
 
460
483
/* ******************** Make Parent Operator *********************** */
461
484
 
462
 
#define PAR_OBJECT                              0
463
 
#define PAR_ARMATURE                    1
464
 
#define PAR_ARMATURE_NAME               2
465
 
#define PAR_ARMATURE_ENVELOPE   3
466
 
#define PAR_ARMATURE_AUTO               4
467
 
#define PAR_BONE                                5
468
 
#define PAR_CURVE                               6
469
 
#define PAR_FOLLOW                              7
470
 
#define PAR_PATH_CONST                  8
471
 
#define PAR_LATTICE                             9
472
 
#define PAR_VERTEX                              10
473
 
#define PAR_TRIA                                11
474
 
 
475
 
static EnumPropertyItem prop_make_parent_types[] = {
 
485
void ED_object_parent(Object *ob, Object *par, int type, const char *substr)
 
486
{
 
487
        if (!par || BKE_object_parent_loop_check(par, ob)) {
 
488
                ob->parent= NULL;
 
489
                ob->partype= PAROBJECT;
 
490
                ob->parsubstr[0]= 0;
 
491
                return;
 
492
        }
 
493
 
 
494
        /* this could use some more checks */
 
495
 
 
496
        ob->parent= par;
 
497
        ob->partype &= ~PARTYPE;
 
498
        ob->partype |= type;
 
499
        BLI_strncpy(ob->parsubstr, substr, sizeof(ob->parsubstr));
 
500
}
 
501
 
 
502
/* Operator Property */
 
503
EnumPropertyItem prop_make_parent_types[] = {
476
504
        {PAR_OBJECT, "OBJECT", 0, "Object", ""},
477
505
        {PAR_ARMATURE, "ARMATURE", 0, "Armature Deform", ""},
478
506
        {PAR_ARMATURE_NAME, "ARMATURE_NAME", 0, "   With Empty Groups", ""},
488
516
        {0, NULL, 0, NULL, NULL}
489
517
};
490
518
 
491
 
static int test_parent_loop(Object *par, Object *ob)
492
 
{
493
 
        /* test if 'ob' is a parent somewhere in par's parents */
494
 
        
495
 
        if(par == NULL) return 0;
496
 
        if(ob == par) return 1;
497
 
        
498
 
        return test_parent_loop(par->parent, ob);
499
 
}
500
 
 
501
 
void ED_object_parent(Object *ob, Object *par, int type, const char *substr)
502
 
{
503
 
        if(!par || test_parent_loop(par, ob)) {
504
 
                ob->parent= NULL;
505
 
                ob->partype= PAROBJECT;
506
 
                ob->parsubstr[0]= 0;
507
 
                return;
508
 
        }
509
 
 
510
 
        /* this could use some more checks */
511
 
 
512
 
        ob->parent= par;
513
 
        ob->partype &= ~PARTYPE;
514
 
        ob->partype |= type;
515
 
        BLI_strncpy(ob->parsubstr, substr, sizeof(ob->parsubstr));
516
 
}
517
 
 
518
 
static int parent_set_exec(bContext *C, wmOperator *op)
519
 
{
520
 
        Scene *scene= CTX_data_scene(C);
521
 
        Object *par= CTX_data_active_object(C);
 
519
int ED_object_parent_set(ReportList *reports, Main *bmain, Scene *scene, Object *ob, Object *par, int partype)
 
520
{
522
521
        bPoseChannel *pchan= NULL;
523
 
        int partype= RNA_enum_get(op->ptr, "type");
524
522
        int pararm= ELEM4(partype, PAR_ARMATURE, PAR_ARMATURE_NAME, PAR_ARMATURE_ENVELOPE, PAR_ARMATURE_AUTO);
525
523
        
526
524
        par->recalc |= OB_RECALC_OB;
527
525
        
528
526
        /* preconditions */
529
 
        if(partype==PAR_FOLLOW || partype==PAR_PATH_CONST) {
530
 
                if(par->type!=OB_CURVE)
531
 
                        return OPERATOR_CANCELLED;
 
527
        if (partype==PAR_FOLLOW || partype==PAR_PATH_CONST) {
 
528
                if (par->type!=OB_CURVE)
 
529
                        return 0;
532
530
                else {
533
531
                        Curve *cu= par->data;
534
532
                        
535
 
                        if((cu->flag & CU_PATH)==0) {
 
533
                        if ((cu->flag & CU_PATH)==0) {
536
534
                                cu->flag |= CU_PATH|CU_FOLLOW;
537
535
                                makeDispListCurveTypes(scene, par, 0);  /* force creation of path data */
538
536
                        }
539
537
                        else cu->flag |= CU_FOLLOW;
540
538
                        
 
539
                        /* if follow, add F-Curve for ctime (i.e. "eval_time") so that path-follow works */
 
540
                        if (partype == PAR_FOLLOW) {
 
541
                                /* get or create F-Curve */
 
542
                                bAction *act = verify_adt_action(&cu->id, 1);
 
543
                                FCurve *fcu = verify_fcurve(act, NULL, "eval_time", 0, 1);
 
544
                                
 
545
                                /* setup dummy 'generator' modifier here to get 1-1 correspondence still working */
 
546
                                if (!fcu->bezt && !fcu->fpt && !fcu->modifiers.first)
 
547
                                        add_fmodifier(&fcu->modifiers, FMODIFIER_TYPE_GENERATOR);
 
548
                        }
 
549
                        
541
550
                        /* fall back on regular parenting now (for follow only) */
542
 
                        if(partype == PAR_FOLLOW)
 
551
                        if (partype == PAR_FOLLOW)
543
552
                                partype= PAR_OBJECT;
544
553
                }               
545
554
        }
546
 
        else if(partype==PAR_BONE) {
 
555
        else if (partype==PAR_BONE) {
547
556
                pchan= get_active_posechannel(par);
548
557
                
549
 
                if(pchan==NULL) {
550
 
                        BKE_report(op->reports, RPT_ERROR, "No active Bone");
551
 
                        return OPERATOR_CANCELLED;
 
558
                if (pchan==NULL) {
 
559
                        BKE_report(reports, RPT_ERROR, "No active Bone");
 
560
                        return 0;
552
561
                }
553
562
        }
554
563
        
555
 
        /* context itterator */
556
 
        CTX_DATA_BEGIN(C, Object*, ob, selected_editable_objects) {
557
 
                
558
 
                if(ob!=par) {
559
 
                        
560
 
                        if( test_parent_loop(par, ob) ) {
561
 
                                BKE_report(op->reports, RPT_ERROR, "Loop in parents");
 
564
        if (ob!=par) {
 
565
                if (BKE_object_parent_loop_check(par, ob)) {
 
566
                        BKE_report(reports, RPT_ERROR, "Loop in parents");
 
567
                        return 0;
 
568
                }
 
569
                else {
 
570
                        Object workob;
 
571
                        
 
572
                        /* apply transformation of previous parenting */
 
573
                        /* object_apply_mat4(ob, ob->obmat); */ /* removed because of bug [#23577] */
 
574
                        
 
575
                        /* set the parent (except for follow-path constraint option) */
 
576
                        if (partype != PAR_PATH_CONST) {
 
577
                                ob->parent= par;
 
578
                        }
 
579
                        
 
580
                        /* handle types */
 
581
                        if (pchan)
 
582
                                BLI_strncpy(ob->parsubstr, pchan->name, sizeof(ob->parsubstr));
 
583
                        else
 
584
                                ob->parsubstr[0]= 0;
 
585
                                
 
586
                        if (partype == PAR_PATH_CONST) {
 
587
                                /* don't do anything here, since this is not technically "parenting" */
 
588
                        }
 
589
                        else if (ELEM(partype, PAR_CURVE, PAR_LATTICE) || (pararm)) {
 
590
                                /* partype is now set to PAROBJECT so that invisible 'virtual' modifiers don't need to be created
 
591
                                 * NOTE: the old (2.4x) method was to set ob->partype = PARSKEL, creating the virtual modifiers
 
592
                                 */
 
593
                                ob->partype= PAROBJECT; /* note, dna define, not operator property */
 
594
                                //ob->partype= PARSKEL; /* note, dna define, not operator property */
 
595
                                
 
596
                                /* BUT, to keep the deforms, we need a modifier, and then we need to set the object that it uses */
 
597
                                // XXX currently this should only happen for meshes, curves, surfaces, and lattices - this stuff isn't available for metas yet
 
598
                                if (ELEM5(ob->type, OB_MESH, OB_CURVE, OB_SURF, OB_FONT, OB_LATTICE)) {
 
599
                                        ModifierData *md;
 
600
                                        
 
601
                                        switch (partype) {
 
602
                                        case PAR_CURVE: /* curve deform */
 
603
                                                md= ED_object_modifier_add(reports, bmain, scene, ob, NULL, eModifierType_Curve);
 
604
                                                ((CurveModifierData *)md)->object= par;
 
605
                                                break;
 
606
                                        case PAR_LATTICE: /* lattice deform */
 
607
                                                md= ED_object_modifier_add(reports, bmain, scene, ob, NULL, eModifierType_Lattice);
 
608
                                                ((LatticeModifierData *)md)->object= par;
 
609
                                                break;
 
610
                                        default: /* armature deform */
 
611
                                                md= ED_object_modifier_add(reports, bmain, scene, ob, NULL, eModifierType_Armature);
 
612
                                                ((ArmatureModifierData *)md)->object= par;
 
613
                                                break;
 
614
                                        }
 
615
                                }
 
616
                        }
 
617
                        else if (partype == PAR_BONE)
 
618
                                ob->partype= PARBONE; /* note, dna define, not operator property */
 
619
                        else
 
620
                                ob->partype= PAROBJECT; /* note, dna define, not operator property */
 
621
                        
 
622
                        /* constraint */
 
623
                        if (partype == PAR_PATH_CONST) {
 
624
                                bConstraint *con;
 
625
                                bFollowPathConstraint *data;
 
626
                                float cmat[4][4], vec[3];
 
627
                                
 
628
                                con = add_ob_constraint(ob, "AutoPath", CONSTRAINT_TYPE_FOLLOWPATH);
 
629
                                
 
630
                                data = con->data;
 
631
                                data->tar = par;
 
632
                                
 
633
                                get_constraint_target_matrix(scene, con, 0, CONSTRAINT_OBTYPE_OBJECT, NULL, cmat, scene->r.cfra);
 
634
                                sub_v3_v3v3(vec, ob->obmat[3], cmat[3]);
 
635
                                
 
636
                                ob->loc[0] = vec[0];
 
637
                                ob->loc[1] = vec[1];
 
638
                                ob->loc[2] = vec[2];
 
639
                        }
 
640
                        else if (pararm && ob->type==OB_MESH && par->type == OB_ARMATURE) {
 
641
                                if (partype == PAR_ARMATURE_NAME)
 
642
                                        create_vgroups_from_armature(reports, scene, ob, par, ARM_GROUPS_NAME, 0);
 
643
                                else if (partype == PAR_ARMATURE_ENVELOPE)
 
644
                                        create_vgroups_from_armature(reports, scene, ob, par, ARM_GROUPS_ENVELOPE, 0);
 
645
                                else if (partype == PAR_ARMATURE_AUTO) {
 
646
                                        WM_cursor_wait(1);
 
647
                                        create_vgroups_from_armature(reports, scene, ob, par, ARM_GROUPS_AUTO, 0);
 
648
                                        WM_cursor_wait(0);
 
649
                                }
 
650
                                /* get corrected inverse */
 
651
                                ob->partype= PAROBJECT;
 
652
                                what_does_parent(scene, ob, &workob);
 
653
                                
 
654
                                invert_m4_m4(ob->parentinv, workob.obmat);
562
655
                        }
563
656
                        else {
564
 
                                Object workob;
565
 
                                
566
 
                                /* apply transformation of previous parenting */
567
 
                                object_apply_mat4(ob, ob->obmat);
568
 
                                
569
 
                                /* set the parent (except for follow-path constraint option) */
570
 
                                if(partype != PAR_PATH_CONST)
571
 
                                        ob->parent= par;
572
 
                                
573
 
                                /* handle types */
574
 
                                if (pchan)
575
 
                                        strcpy(ob->parsubstr, pchan->name);
576
 
                                else
577
 
                                        ob->parsubstr[0]= 0;
578
 
                                        
579
 
                                if(partype == PAR_PATH_CONST)
580
 
                                        ; /* don't do anything here, since this is not technically "parenting" */
581
 
                                else if( ELEM(partype, PAR_CURVE, PAR_LATTICE) || pararm )
582
 
                                {
583
 
                                        /* partype is now set to PAROBJECT so that invisible 'virtual' modifiers don't need to be created
584
 
                                         * NOTE: the old (2.4x) method was to set ob->partype = PARSKEL, creating the virtual modifiers
585
 
                                         */
586
 
                                        ob->partype= PAROBJECT; /* note, dna define, not operator property */
587
 
                                        //ob->partype= PARSKEL; /* note, dna define, not operator property */
588
 
                                        
589
 
                                        /* BUT, to keep the deforms, we need a modifier, and then we need to set the object that it uses */
590
 
                                        // XXX currently this should only happen for meshes, curves, surfaces, and lattices - this stuff isn't available for metas yet
591
 
                                        if (ELEM5(ob->type, OB_MESH, OB_CURVE, OB_SURF, OB_FONT, OB_LATTICE)) 
592
 
                                        {
593
 
                                                ModifierData *md;
594
 
 
595
 
                                                switch (partype) {
596
 
                                                case PAR_CURVE: /* curve deform */
597
 
                                                        md= ED_object_modifier_add(op->reports, scene, ob, NULL, eModifierType_Curve);
598
 
                                                        ((CurveModifierData *)md)->object= par;
599
 
                                                        break;
600
 
                                                case PAR_LATTICE: /* lattice deform */
601
 
                                                        md= ED_object_modifier_add(op->reports, scene, ob, NULL, eModifierType_Lattice);
602
 
                                                        ((LatticeModifierData *)md)->object= par;
603
 
                                                        break;
604
 
                                                default: /* armature deform */
605
 
                                                        md= ED_object_modifier_add(op->reports, scene, ob, NULL, eModifierType_Armature);
606
 
                                                        ((ArmatureModifierData *)md)->object= par;
607
 
                                                        break;
608
 
                                                }
609
 
                                        }
610
 
                                }
611
 
                                else if (partype == PAR_BONE)
612
 
                                        ob->partype= PARBONE; /* note, dna define, not operator property */
613
 
                                else
614
 
                                        ob->partype= PAROBJECT; /* note, dna define, not operator property */
615
 
                                
616
 
                                /* constraint */
617
 
                                if(partype == PAR_PATH_CONST) {
618
 
                                        bConstraint *con;
619
 
                                        bFollowPathConstraint *data;
620
 
                                        float cmat[4][4], vec[3];
621
 
                                        
622
 
                                        con = add_ob_constraint(ob, "AutoPath", CONSTRAINT_TYPE_FOLLOWPATH);
623
 
                                        
624
 
                                        data = con->data;
625
 
                                        data->tar = par;
626
 
                                        
627
 
                                        get_constraint_target_matrix(scene, con, 0, CONSTRAINT_OBTYPE_OBJECT, NULL, cmat, scene->r.cfra - give_timeoffset(ob));
628
 
                                        sub_v3_v3v3(vec, ob->obmat[3], cmat[3]);
629
 
                                        
630
 
                                        ob->loc[0] = vec[0];
631
 
                                        ob->loc[1] = vec[1];
632
 
                                        ob->loc[2] = vec[2];
633
 
                                }
634
 
                                else if(pararm && ob->type==OB_MESH && par->type == OB_ARMATURE) {
635
 
                                        if(partype == PAR_ARMATURE_NAME)
636
 
                                                create_vgroups_from_armature(scene, ob, par, ARM_GROUPS_NAME, 0);
637
 
                                        else if(partype == PAR_ARMATURE_ENVELOPE)
638
 
                                                create_vgroups_from_armature(scene, ob, par, ARM_GROUPS_ENVELOPE, 0);
639
 
                                        else if(partype == PAR_ARMATURE_AUTO)
640
 
                                                create_vgroups_from_armature(scene, ob, par, ARM_GROUPS_AUTO, 0);
641
 
                                        
642
 
                                        /* get corrected inverse */
643
 
                                        ob->partype= PAROBJECT;
644
 
                                        what_does_parent(scene, ob, &workob);
645
 
                                        
646
 
                                        invert_m4_m4(ob->parentinv, workob.obmat);
647
 
                                }
648
 
                                else {
649
 
                                        /* calculate inverse parent matrix */
650
 
                                        what_does_parent(scene, ob, &workob);
651
 
                                        invert_m4_m4(ob->parentinv, workob.obmat);
652
 
                                }
653
 
                                
654
 
                                ob->recalc |= OB_RECALC_OB|OB_RECALC_DATA;
 
657
                                /* calculate inverse parent matrix */
 
658
                                what_does_parent(scene, ob, &workob);
 
659
                                invert_m4_m4(ob->parentinv, workob.obmat);
655
660
                        }
 
661
                        
 
662
                        ob->recalc |= OB_RECALC_OB|OB_RECALC_DATA;
 
663
                }
 
664
        }
 
665
 
 
666
        return 1;
 
667
}
 
668
 
 
669
static int parent_set_exec(bContext *C, wmOperator *op)
 
670
{
 
671
        Main *bmain= CTX_data_main(C);
 
672
        Scene *scene= CTX_data_scene(C);
 
673
        Object *par= ED_object_active_context(C);
 
674
        int partype= RNA_enum_get(op->ptr, "type");
 
675
        int ok = 1;
 
676
 
 
677
        CTX_DATA_BEGIN(C, Object*, ob, selected_editable_objects)
 
678
        {
 
679
                if (!ED_object_parent_set(op->reports, bmain, scene, ob, par, partype)) {
 
680
                        ok = 0;
 
681
                        break;
656
682
                }
657
683
        }
658
684
        CTX_DATA_END;
659
 
        
660
 
        DAG_scene_sort(scene);
661
 
        DAG_ids_flush_update(0);
 
685
 
 
686
        if (!ok)
 
687
                return OPERATOR_CANCELLED;
 
688
 
 
689
        DAG_scene_sort(bmain, scene);
 
690
        DAG_ids_flush_update(bmain, 0);
662
691
        WM_event_add_notifier(C, NC_OBJECT|ND_TRANSFORM, NULL);
663
 
        
 
692
        WM_event_add_notifier(C, NC_OBJECT|ND_PARENT, NULL);
 
693
 
664
694
        return OPERATOR_FINISHED;
665
695
}
666
696
 
667
 
static int parent_set_invoke(bContext *C, wmOperator *op, wmEvent *event)
 
697
 
 
698
static int parent_set_invoke(bContext *C, wmOperator *UNUSED(op), wmEvent *UNUSED(event))
668
699
{
669
 
        Object *ob= CTX_data_active_object(C);
670
 
        uiPopupMenu *pup= uiPupMenuBegin(C, "Set Parent To", 0);
 
700
        Object *ob= ED_object_active_context(C);
 
701
        uiPopupMenu *pup= uiPupMenuBegin(C, "Set Parent To", ICON_NONE);
671
702
        uiLayout *layout= uiPupMenuLayout(pup);
672
703
        
673
704
        uiLayoutSetOperatorContext(layout, WM_OP_EXEC_DEFAULT);
674
705
        uiItemEnumO(layout, "OBJECT_OT_parent_set", NULL, 0, "type", PAR_OBJECT);
675
706
        
676
707
        /* ob becomes parent, make the associated menus */
677
 
        if(ob->type==OB_ARMATURE) {
 
708
        if (ob->type==OB_ARMATURE) {
678
709
                uiItemEnumO(layout, "OBJECT_OT_parent_set", NULL, 0, "type", PAR_ARMATURE);
679
710
                uiItemEnumO(layout, "OBJECT_OT_parent_set", NULL, 0, "type", PAR_ARMATURE_NAME);
680
711
                uiItemEnumO(layout, "OBJECT_OT_parent_set", NULL, 0, "type", PAR_ARMATURE_ENVELOPE);
681
712
                uiItemEnumO(layout, "OBJECT_OT_parent_set", NULL, 0, "type", PAR_ARMATURE_AUTO);
682
713
                uiItemEnumO(layout, "OBJECT_OT_parent_set", NULL, 0, "type", PAR_BONE);
683
714
        }
684
 
        else if(ob->type==OB_CURVE) {
 
715
        else if (ob->type==OB_CURVE) {
685
716
                uiItemEnumO(layout, "OBJECT_OT_parent_set", NULL, 0, "type", PAR_CURVE);
686
717
                uiItemEnumO(layout, "OBJECT_OT_parent_set", NULL, 0, "type", PAR_FOLLOW);
687
718
                uiItemEnumO(layout, "OBJECT_OT_parent_set", NULL, 0, "type", PAR_PATH_CONST);
688
719
        }
689
 
        else if(ob->type == OB_LATTICE) {
 
720
        else if (ob->type == OB_LATTICE) {
690
721
                uiItemEnumO(layout, "OBJECT_OT_parent_set", NULL, 0, "type", PAR_LATTICE);
691
722
        }
692
723
        
699
730
void OBJECT_OT_parent_set(wmOperatorType *ot)
700
731
{
701
732
        /* identifiers */
702
 
        ot->name= "Make Parent";
 
733
        ot->name = "Make Parent";
703
734
        ot->description = "Set the object's parenting";
704
 
        ot->idname= "OBJECT_OT_parent_set";
 
735
        ot->idname = "OBJECT_OT_parent_set";
705
736
        
706
737
        /* api callbacks */
707
 
        ot->invoke= parent_set_invoke;
708
 
        ot->exec= parent_set_exec;
 
738
        ot->invoke = parent_set_invoke;
 
739
        ot->exec = parent_set_exec;
709
740
        
710
 
        ot->poll= ED_operator_object_active_editable;
 
741
        ot->poll = ED_operator_object_active;
711
742
        
712
743
        /* flags */
713
 
        ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
 
744
        ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO;
714
745
        
715
746
        RNA_def_enum(ot->srna, "type", prop_make_parent_types, 0, "Type", "");
716
747
}
719
750
 
720
751
static int parent_noinv_set_exec(bContext *C, wmOperator *op)
721
752
{
722
 
        Object *par= CTX_data_active_object(C);
 
753
        Main *bmain= CTX_data_main(C);
 
754
        Object *par= ED_object_active_context(C);
723
755
        
724
756
        par->recalc |= OB_RECALC_OB;
725
757
        
726
 
        /* context itterator */
 
758
        /* context iterator */
727
759
        CTX_DATA_BEGIN(C, Object*, ob, selected_editable_objects) {
728
760
                if (ob != par) {
729
 
                        if (test_parent_loop(par, ob)) {
 
761
                        if (BKE_object_parent_loop_check(par, ob)) {
730
762
                                BKE_report(op->reports, RPT_ERROR, "Loop in parents");
731
763
                        }
732
764
                        else {
745
777
        }
746
778
        CTX_DATA_END;
747
779
        
748
 
        DAG_scene_sort(CTX_data_scene(C));
749
 
        DAG_ids_flush_update(0);
 
780
        DAG_scene_sort(bmain, CTX_data_scene(C));
 
781
        DAG_ids_flush_update(bmain, 0);
750
782
        WM_event_add_notifier(C, NC_OBJECT|ND_TRANSFORM, NULL);
751
783
        
752
784
        return OPERATOR_FINISHED;
755
787
void OBJECT_OT_parent_no_inverse_set(wmOperatorType *ot)
756
788
{
757
789
        /* identifiers */
758
 
        ot->name= "Make Parent without Inverse";
 
790
        ot->name = "Make Parent without Inverse";
759
791
        ot->description = "Set the object's parenting without setting the inverse parent correction";
760
 
        ot->idname= "OBJECT_OT_parent_no_inverse_set";
 
792
        ot->idname = "OBJECT_OT_parent_no_inverse_set";
761
793
        
762
794
        /* api callbacks */
763
 
        ot->invoke= WM_operator_confirm;
764
 
        ot->exec= parent_noinv_set_exec;
765
 
        ot->poll= ED_operator_object_active_editable;
 
795
        ot->invoke = WM_operator_confirm;
 
796
        ot->exec = parent_noinv_set_exec;
 
797
        ot->poll = ED_operator_object_active_editable;
766
798
        
767
799
        /* flags */
768
 
        ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
 
800
        ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO;
769
801
}
770
802
 
771
803
/************************ Clear Slow Parent Operator *********************/
772
804
 
773
 
static int object_slow_parent_clear_exec(bContext *C, wmOperator *op)
 
805
static int object_slow_parent_clear_exec(bContext *C, wmOperator *UNUSED(op))
774
806
{
 
807
        Main *bmain= CTX_data_main(C);
775
808
        Scene *scene= CTX_data_scene(C);
776
809
 
777
810
        CTX_DATA_BEGIN(C, Object*, ob, selected_editable_objects) {
778
 
                if(ob->parent) {
779
 
                        if(ob->partype & PARSLOW) {
 
811
                if (ob->parent) {
 
812
                        if (ob->partype & PARSLOW) {
780
813
                                ob->partype -= PARSLOW;
781
814
                                where_is_object(scene, ob);
782
815
                                ob->partype |= PARSLOW;
786
819
        }
787
820
        CTX_DATA_END;
788
821
 
789
 
        DAG_ids_flush_update(0);
 
822
        DAG_ids_flush_update(bmain, 0);
790
823
        WM_event_add_notifier(C, NC_SCENE, scene);
791
824
        
792
825
        return OPERATOR_FINISHED;
796
829
{
797
830
        
798
831
        /* identifiers */
799
 
        ot->name= "Clear Slow Parent";
 
832
        ot->name = "Clear Slow Parent";
800
833
        ot->description = "Clear the object's slow parent";
801
 
        ot->idname= "OBJECT_OT_slow_parent_clear";
 
834
        ot->idname = "OBJECT_OT_slow_parent_clear";
802
835
        
803
836
        /* api callbacks */
804
 
        ot->invoke= WM_operator_confirm;
805
 
        ot->exec= object_slow_parent_clear_exec;
806
 
        ot->poll= ED_operator_view3d_active;
 
837
        ot->invoke = WM_operator_confirm;
 
838
        ot->exec = object_slow_parent_clear_exec;
 
839
        ot->poll = ED_operator_view3d_active;
807
840
        
808
841
        /* flags */
809
 
        ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
 
842
        ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO;
810
843
}
811
844
 
812
845
/********************** Make Slow Parent Operator *********************/
813
846
 
814
 
static int object_slow_parent_set_exec(bContext *C, wmOperator *op)
 
847
static int object_slow_parent_set_exec(bContext *C, wmOperator *UNUSED(op))
815
848
{
 
849
        Main *bmain= CTX_data_main(C);
816
850
        Scene *scene= CTX_data_scene(C);
817
851
 
818
852
        CTX_DATA_BEGIN(C, Object*, ob, selected_editable_objects) {
819
 
                if(ob->parent)
 
853
                if (ob->parent)
820
854
                        ob->partype |= PARSLOW;
821
855
 
822
856
                ob->recalc |= OB_RECALC_OB;
824
858
        }
825
859
        CTX_DATA_END;
826
860
 
827
 
        DAG_ids_flush_update(0);
 
861
        DAG_ids_flush_update(bmain, 0);
828
862
        WM_event_add_notifier(C, NC_SCENE, scene);
829
863
        
830
864
        return OPERATOR_FINISHED;
834
868
{
835
869
        
836
870
        /* identifiers */
837
 
        ot->name= "Set Slow Parent";
 
871
        ot->name = "Set Slow Parent";
838
872
        ot->description = "Set the object's slow parent";
839
 
        ot->idname= "OBJECT_OT_slow_parent_set";
 
873
        ot->idname = "OBJECT_OT_slow_parent_set";
840
874
        
841
875
        /* api callbacks */
842
 
        ot->invoke= WM_operator_confirm;
843
 
        ot->exec= object_slow_parent_set_exec;
844
 
        ot->poll= ED_operator_view3d_active;
 
876
        ot->invoke = WM_operator_confirm;
 
877
        ot->exec = object_slow_parent_set_exec;
 
878
        ot->poll = ED_operator_view3d_active;
845
879
        
846
880
        /* flags */
847
 
        ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
 
881
        ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO;
848
882
}
849
883
 
850
884
/* ******************** Clear Track Operator ******************* */
858
892
/* note, poll should check for editable scene */
859
893
static int object_track_clear_exec(bContext *C, wmOperator *op)
860
894
{
 
895
        Main *bmain= CTX_data_main(C);
 
896
        Scene *scene= CTX_data_scene(C);
861
897
        int type= RNA_enum_get(op->ptr, "type");
862
898
 
863
 
        if(CTX_data_edit_object(C)) {
 
899
        if (CTX_data_edit_object(C)) {
864
900
                BKE_report(op->reports, RPT_ERROR, "Operation cannot be performed in EditMode");
865
901
                return OPERATOR_CANCELLED;
866
902
        }
869
905
                
870
906
                /* remove track-object for old track */
871
907
                ob->track= NULL;
872
 
                ob->recalc |= OB_RECALC_ALL;
 
908
                ob->recalc |= OB_RECALC_OB|OB_RECALC_DATA|OB_RECALC_TIME;
873
909
                
874
910
                /* also remove all tracking constraints */
875
911
                for (con= ob->constraints.last; con; con= pcon) {
878
914
                                remove_constraint(&ob->constraints, con);
879
915
                }
880
916
                
881
 
                if(type == 1)
882
 
                        object_apply_mat4(ob, ob->obmat);
 
917
                if (type == 1)
 
918
                        object_apply_mat4(ob, ob->obmat, TRUE, TRUE);
883
919
        }
884
920
        CTX_DATA_END;
885
921
 
886
 
        DAG_ids_flush_update(0);
887
 
        DAG_scene_sort(CTX_data_scene(C));
 
922
        DAG_ids_flush_update(bmain, 0);
 
923
        DAG_scene_sort(bmain, scene);
888
924
        WM_event_add_notifier(C, NC_OBJECT|ND_TRANSFORM, NULL);
889
925
 
890
926
        return OPERATOR_FINISHED;
893
929
void OBJECT_OT_track_clear(wmOperatorType *ot)
894
930
{
895
931
        /* identifiers */
896
 
        ot->name= "Clear track";
 
932
        ot->name = "Clear track";
897
933
        ot->description = "Clear tracking constraint or flag from object";
898
 
        ot->idname= "OBJECT_OT_track_clear";
 
934
        ot->idname = "OBJECT_OT_track_clear";
899
935
        
900
936
        /* api callbacks */
901
 
        ot->invoke= WM_menu_invoke;
902
 
        ot->exec= object_track_clear_exec;
 
937
        ot->invoke = WM_menu_invoke;
 
938
        ot->exec = object_track_clear_exec;
903
939
        
904
 
        ot->poll= ED_operator_scene_editable;
 
940
        ot->poll = ED_operator_objectmode;
905
941
        
906
942
        /* flags */
907
 
        ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
 
943
        ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO;
908
944
        
909
 
        ot->prop= RNA_def_enum(ot->srna, "type", prop_clear_track_types, 0, "Type", "");
 
945
        ot->prop = RNA_def_enum(ot->srna, "type", prop_clear_track_types, 0, "Type", "");
910
946
}
911
947
 
912
948
/************************** Make Track Operator *****************************/
920
956
 
921
957
static int track_set_exec(bContext *C, wmOperator *op)
922
958
{
 
959
        Main *bmain= CTX_data_main(C);
923
960
        Scene *scene= CTX_data_scene(C);
924
 
        Object *obact= CTX_data_active_object(C); 
 
961
        Object *obact= ED_object_active_context(C); 
925
962
        
926
963
        int type= RNA_enum_get(op->ptr, "type");
927
964
        
928
 
        if(type == 1) {
 
965
        if (type == 1) {
929
966
                bConstraint *con;
930
967
                bDampTrackConstraint *data;
931
968
 
932
969
                CTX_DATA_BEGIN(C, Object*, ob, selected_editable_objects) {
933
 
                        if(ob!=obact) {
 
970
                        if (ob!=obact) {
934
971
                                con = add_ob_constraint(ob, "AutoTrack", CONSTRAINT_TYPE_DAMPTRACK);
935
972
 
936
973
                                data = con->data;
937
974
                                data->tar = obact;
938
 
                                ob->recalc |= OB_RECALC_ALL;
 
975
                                ob->recalc |= OB_RECALC_OB|OB_RECALC_DATA|OB_RECALC_TIME;
939
976
                                
940
 
                                /* Lamp and Camera track differently by default */
941
 
                                if (ob->type == OB_LAMP || ob->type == OB_CAMERA)
 
977
                                /* Lamp, Camera and Speaker track differently by default */
 
978
                                if (ob->type == OB_LAMP || ob->type == OB_CAMERA || ob->type == OB_SPEAKER)
942
979
                                        data->trackflag = TRACK_nZ;
943
980
                        }
944
981
                }
945
982
                CTX_DATA_END;
946
983
        }
947
 
        else if(type == 2) {
 
984
        else if (type == 2) {
948
985
                bConstraint *con;
949
986
                bTrackToConstraint *data;
950
987
 
951
988
                CTX_DATA_BEGIN(C, Object*, ob, selected_editable_objects) {
952
 
                        if(ob!=obact) {
 
989
                        if (ob!=obact) {
953
990
                                con = add_ob_constraint(ob, "AutoTrack", CONSTRAINT_TYPE_TRACKTO);
954
991
 
955
992
                                data = con->data;
956
993
                                data->tar = obact;
957
 
                                ob->recalc |= OB_RECALC_ALL;
 
994
                                ob->recalc |= OB_RECALC_OB|OB_RECALC_DATA|OB_RECALC_TIME;
958
995
                                
959
 
                                /* Lamp and Camera track differently by default */
960
 
                                if (ob->type == OB_LAMP || ob->type == OB_CAMERA) {
 
996
                                /* Lamp, Camera and Speaker track differently by default */
 
997
                                if (ob->type == OB_LAMP || ob->type == OB_CAMERA || ob->type == OB_SPEAKER) {
961
998
                                        data->reserved1 = TRACK_nZ;
962
999
                                        data->reserved2 = UP_Y;
963
1000
                                }
965
1002
                }
966
1003
                CTX_DATA_END;
967
1004
        }
968
 
        else if(type == 3) {
 
1005
        else if (type == 3) {
969
1006
                bConstraint *con;
970
1007
                bLockTrackConstraint *data;
971
1008
 
972
1009
                CTX_DATA_BEGIN(C, Object*, ob, selected_editable_objects) {
973
 
                        if(ob!=obact) {
 
1010
                        if (ob!=obact) {
974
1011
                                con = add_ob_constraint(ob, "AutoTrack", CONSTRAINT_TYPE_LOCKTRACK);
975
1012
 
976
1013
                                data = con->data;
977
1014
                                data->tar = obact;
978
 
                                ob->recalc |= OB_RECALC_ALL;
 
1015
                                ob->recalc |= OB_RECALC_OB|OB_RECALC_DATA|OB_RECALC_TIME;
979
1016
                                
980
 
                                /* Lamp and Camera track differently by default */
981
 
                                if (ob->type == OB_LAMP || ob->type == OB_CAMERA) {
 
1017
                                /* Lamp, Camera and Speaker track differently by default */
 
1018
                                if (ob->type == OB_LAMP || ob->type == OB_CAMERA || ob->type == OB_SPEAKER) {
982
1019
                                        data->trackflag = TRACK_nZ;
983
1020
                                        data->lockflag = LOCK_Y;
984
1021
                                }
987
1024
                CTX_DATA_END;
988
1025
        }
989
1026
        
990
 
        DAG_scene_sort(scene);
991
 
        DAG_ids_flush_update(0);
 
1027
        DAG_scene_sort(bmain, scene);
 
1028
        DAG_ids_flush_update(bmain, 0);
992
1029
        WM_event_add_notifier(C, NC_OBJECT|ND_TRANSFORM, NULL);
993
1030
        
994
1031
        return OPERATOR_FINISHED;
997
1034
void OBJECT_OT_track_set(wmOperatorType *ot)
998
1035
{
999
1036
        /* identifiers */
1000
 
        ot->name= "Make Track";
 
1037
        ot->name = "Make Track";
1001
1038
        ot->description = "Make the object track another object, either by constraint or old way or locked track";
1002
 
        ot->idname= "OBJECT_OT_track_set";
 
1039
        ot->idname = "OBJECT_OT_track_set";
1003
1040
        
1004
1041
        /* api callbacks */
1005
 
        ot->invoke= WM_menu_invoke;
1006
 
        ot->exec= track_set_exec;
 
1042
        ot->invoke = WM_menu_invoke;
 
1043
        ot->exec = track_set_exec;
1007
1044
        
1008
 
        ot->poll= ED_operator_scene_editable;
 
1045
        ot->poll = ED_operator_objectmode;
1009
1046
        
1010
1047
        /* flags */
1011
 
        ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
 
1048
        ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO;
1012
1049
        
1013
1050
        /* properties */
1014
 
        ot->prop= RNA_def_enum(ot->srna, "type", prop_make_track_types, 0, "Type", "");
 
1051
        ot->prop = RNA_def_enum(ot->srna, "type", prop_make_track_types, 0, "Type", "");
1015
1052
}
1016
1053
 
1017
1054
/************************** Move to Layer Operator *****************************/
1021
1058
        int values[20], a;
1022
1059
        unsigned int lay= 0;
1023
1060
 
1024
 
        if(!RNA_property_is_set(op->ptr, "layer")) {
1025
 
                CTX_DATA_BEGIN(C, Base*, base, selected_editable_bases) {
 
1061
        if (!RNA_struct_property_is_set(op->ptr, "layers")) {
 
1062
                /* note: layers are set in bases, library objects work for this */
 
1063
                CTX_DATA_BEGIN(C, Base*, base, selected_bases) {
1026
1064
                        lay |= base->lay;
1027
1065
                }
1028
1066
                CTX_DATA_END;
1029
1067
 
1030
 
                for(a=0; a<20; a++)
 
1068
                for (a=0; a<20; a++)
1031
1069
                        values[a]= (lay & (1<<a));
1032
1070
                
1033
 
                RNA_boolean_set_array(op->ptr, "layer", values);
 
1071
                RNA_boolean_set_array(op->ptr, "layers", values);
1034
1072
        }
1035
1073
        else {
1036
 
                RNA_boolean_get_array(op->ptr, "layer", values);
 
1074
                RNA_boolean_get_array(op->ptr, "layers", values);
1037
1075
 
1038
 
                for(a=0; a<20; a++)
1039
 
                        if(values[a])
 
1076
                for (a=0; a<20; a++)
 
1077
                        if (values[a])
1040
1078
                                lay |= (1 << a);
1041
1079
        }
1042
1080
 
1046
1084
static int move_to_layer_invoke(bContext *C, wmOperator *op, wmEvent *event)
1047
1085
{
1048
1086
        View3D *v3d= CTX_wm_view3d(C);
1049
 
        if(v3d && v3d->localvd) {
 
1087
        if (v3d && v3d->localvd) {
1050
1088
                return WM_operator_confirm_message(C, op, "Move from localview");
1051
1089
        }
1052
1090
        else {
1057
1095
 
1058
1096
static int move_to_layer_exec(bContext *C, wmOperator *op)
1059
1097
{
 
1098
        Main *bmain= CTX_data_main(C);
1060
1099
        Scene *scene= CTX_data_scene(C);
1061
1100
        View3D *v3d= CTX_wm_view3d(C);
1062
1101
        unsigned int lay, local;
1063
 
        int islamp= 0;
 
1102
        /* int islamp= 0; */ /* UNUSED */
1064
1103
        
1065
1104
        lay= move_to_layer_init(C, op);
1066
1105
        lay &= 0xFFFFFF;
1067
1106
 
1068
 
        if(lay==0) return OPERATOR_CANCELLED;
 
1107
        if (lay==0) return OPERATOR_CANCELLED;
1069
1108
        
1070
 
        if(v3d && v3d->localvd) {
 
1109
        if (v3d && v3d->localvd) {
1071
1110
                /* now we can move out of localview. */
1072
 
                // XXX if (!okee("Move from localview")) return;
1073
 
                CTX_DATA_BEGIN(C, Base*, base, selected_editable_bases) {
 
1111
                /* note: layers are set in bases, library objects work for this */
 
1112
                CTX_DATA_BEGIN(C, Base*, base, selected_bases) {
1074
1113
                        lay= base->lay & ~v3d->lay;
1075
1114
                        base->lay= lay;
1076
1115
                        base->object->lay= lay;
1077
1116
                        base->object->flag &= ~SELECT;
1078
1117
                        base->flag &= ~SELECT;
1079
 
                        if(base->object->type==OB_LAMP) islamp= 1;
 
1118
                        /* if (base->object->type==OB_LAMP) islamp= 1; */
1080
1119
                }
1081
1120
                CTX_DATA_END;
1082
1121
        }
1083
1122
        else {
1084
1123
                /* normal non localview operation */
1085
 
                CTX_DATA_BEGIN(C, Base*, base, selected_editable_bases) {
 
1124
                /* note: layers are set in bases, library objects work for this */
 
1125
                CTX_DATA_BEGIN(C, Base*, base, selected_bases) {
1086
1126
                        /* upper byte is used for local view */
1087
1127
                        local= base->lay & 0xFF000000;  
1088
1128
                        base->lay= lay + local;
1089
1129
                        base->object->lay= lay;
1090
 
                        if(base->object->type==OB_LAMP) islamp= 1;
 
1130
                        /* if (base->object->type==OB_LAMP) islamp= 1; */
1091
1131
                }
1092
1132
                CTX_DATA_END;
1093
1133
        }
1094
 
 
1095
 
        if(islamp) reshadeall_displist(scene);  /* only frees */
1096
1134
        
1097
1135
        /* warning, active object may be hidden now */
1098
1136
        
1099
 
        WM_event_add_notifier(C, NC_SCENE|NC_OBJECT|ND_DRAW, scene); /* is NC_SCENE needed ? */
1100
 
        DAG_scene_sort(scene);
 
1137
        WM_event_add_notifier(C, NC_OBJECT|ND_DRAW, scene);
 
1138
        WM_event_add_notifier(C, NC_SCENE|ND_LAYER_CONTENT, scene);
 
1139
 
 
1140
        DAG_scene_sort(bmain, scene);
1101
1141
 
1102
1142
        return OPERATOR_FINISHED;
1103
1143
}
1105
1145
void OBJECT_OT_move_to_layer(wmOperatorType *ot)
1106
1146
{
1107
1147
        /* identifiers */
1108
 
        ot->name= "Move to Layer";
 
1148
        ot->name = "Move to Layer";
1109
1149
        ot->description = "Move the object to different layers";
1110
 
        ot->idname= "OBJECT_OT_move_to_layer";
 
1150
        ot->idname = "OBJECT_OT_move_to_layer";
1111
1151
        
1112
1152
        /* api callbacks */
1113
 
        ot->invoke= move_to_layer_invoke;
1114
 
        ot->exec= move_to_layer_exec;
1115
 
        ot->poll= ED_operator_scene_editable;
 
1153
        ot->invoke = move_to_layer_invoke;
 
1154
        ot->exec = move_to_layer_exec;
 
1155
        ot->poll = ED_operator_objectmode;
1116
1156
        
1117
1157
        /* flags */
1118
 
        ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
 
1158
        ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO;
1119
1159
        
1120
1160
        /* properties */
1121
 
        RNA_def_boolean_layer_member(ot->srna, "layer", 20, NULL, "Layer", "");
 
1161
        RNA_def_boolean_layer_member(ot->srna, "layers", 20, NULL, "Layer", "");
1122
1162
}
1123
1163
 
1124
1164
/************************** Link to Scene Operator *****************************/
1125
1165
 
1126
 
void link_to_scene(unsigned short nr)
1127
 
{
1128
1166
#if 0
1129
 
        Scene *sce= (Scene*) BLI_findlink(&G.main->scene, G.curscreen->scenenr-1);
 
1167
static void link_to_scene(Main *UNUSED(bmain), unsigned short UNUSED(nr))
 
1168
{
 
1169
        Scene *sce= (Scene*) BLI_findlink(&bmain->scene, G.curscreen->scenenr-1);
1130
1170
        Base *base, *nbase;
1131
1171
        
1132
 
        if(sce==0) return;
1133
 
        if(sce->id.lib) return;
 
1172
        if (sce==0) return;
 
1173
        if (sce->id.lib) return;
1134
1174
        
1135
 
        for(base= FIRSTBASE; base; base= base->next) {
1136
 
                if(TESTBASE(v3d, base)) {
 
1175
        for (base= FIRSTBASE; base; base= base->next) {
 
1176
                if (TESTBASE(v3d, base)) {
1137
1177
                        
1138
1178
                        nbase= MEM_mallocN( sizeof(Base), "newbase");
1139
1179
                        *nbase= *base;
1141
1181
                        id_us_plus((ID *)base->object);
1142
1182
                }
1143
1183
        }
 
1184
}
1144
1185
#endif
1145
 
}
1146
1186
 
1147
1187
static int make_links_scene_exec(bContext *C, wmOperator *op)
1148
1188
{
 
1189
        Main *bmain= CTX_data_main(C);
1149
1190
        Scene *scene_to= BLI_findlink(&CTX_data_main(C)->scene, RNA_enum_get(op->ptr, "scene"));
1150
1191
 
1151
 
        if(scene_to==NULL) {
 
1192
        if (scene_to==NULL) {
1152
1193
                BKE_report(op->reports, RPT_ERROR, "Scene not found");
1153
1194
                return OPERATOR_CANCELLED;
1154
1195
        }
1155
1196
 
1156
 
        if(scene_to == CTX_data_scene(C)) {
 
1197
        if (scene_to == CTX_data_scene(C)) {
1157
1198
                BKE_report(op->reports, RPT_ERROR, "Can't link objects into the same scene");
1158
1199
                return OPERATOR_CANCELLED;
1159
1200
        }
1160
1201
 
1161
 
        if(scene_to->id.lib) {
 
1202
        if (scene_to->id.lib) {
1162
1203
                BKE_report(op->reports, RPT_ERROR, "Can't link objects into a linked scene");
1163
1204
                return OPERATOR_CANCELLED;
1164
1205
        }
1165
1206
 
1166
1207
        CTX_DATA_BEGIN(C, Base*, base, selected_bases)
1167
1208
        {
1168
 
                if(!object_in_scene(base->object, scene_to)) {
 
1209
                if (!object_in_scene(base->object, scene_to)) {
1169
1210
                        Base *nbase= MEM_mallocN( sizeof(Base), "newbase");
1170
1211
                        *nbase= *base;
1171
1212
                        BLI_addhead( &(scene_to->base), nbase);
1174
1215
        }
1175
1216
        CTX_DATA_END;
1176
1217
 
1177
 
        DAG_ids_flush_update(0);
 
1218
        DAG_ids_flush_update(bmain, 0);
1178
1219
 
1179
1220
        /* one day multiple scenes will be visible, then we should have some update function for them */
1180
1221
        return OPERATOR_FINISHED;
1197
1238
                                return 1;
1198
1239
                        break;
1199
1240
                case MAKE_LINKS_MATERIALS:
1200
 
                        if (ELEM5(ob->type, OB_MESH, OB_CURVE, OB_FONT, OB_SURF, OB_MBALL) &&
1201
 
                                ELEM5(obt->type, OB_MESH, OB_CURVE, OB_FONT, OB_SURF, OB_MBALL))
 
1241
                        if (OB_TYPE_SUPPORT_MATERIAL(ob->type) &&
 
1242
                                OB_TYPE_SUPPORT_MATERIAL(obt->type))
 
1243
                        {
1202
1244
                                return 1;
 
1245
                        }
1203
1246
                        break;
1204
1247
                case MAKE_LINKS_ANIMDATA:
1205
1248
                case MAKE_LINKS_DUPLIGROUP:
1214
1257
 
1215
1258
static int make_links_data_exec(bContext *C, wmOperator *op)
1216
1259
{
1217
 
        int event = RNA_int_get(op->ptr, "type");
 
1260
        Main *bmain= CTX_data_main(C);
 
1261
        int event = RNA_enum_get(op->ptr, "type");
1218
1262
        Object *ob;
1219
1263
        ID *id;
1220
1264
        int a;
1221
1265
 
1222
 
        ob= CTX_data_active_object(C);
 
1266
        ob= ED_object_active_context(C);
1223
1267
 
1224
1268
        CTX_DATA_BEGIN(C, Object*, obt, selected_editable_objects) {
1225
 
                if(ob != obt) {
 
1269
                if (ob != obt) {
1226
1270
                        if (allow_make_links_data(event, ob, obt)) {
1227
1271
                                switch(event) {
1228
1272
                                case MAKE_LINKS_OBDATA: /* obdata */
1240
1284
                                        break;
1241
1285
                                case MAKE_LINKS_MATERIALS:
1242
1286
                                        /* new approach, using functions from kernel */
1243
 
                                        for(a=0; a<ob->totcol; a++) {
 
1287
                                        for (a=0; a<ob->totcol; a++) {
1244
1288
                                                Material *ma= give_current_material(ob, a+1);
1245
1289
                                                assign_material(obt, ma, a+1);  /* also works with ma==NULL */
1246
1290
                                        }
1247
1291
                                        break;
1248
1292
                                case MAKE_LINKS_ANIMDATA:
1249
 
                                        BKE_copy_animdata_id((ID *)obt, (ID *)ob);
1250
 
                                        BKE_copy_animdata_id((ID *)obt->data, (ID *)ob->data);
 
1293
                                        BKE_copy_animdata_id((ID *)obt, (ID *)ob, FALSE);
 
1294
                                        BKE_copy_animdata_id((ID *)obt->data, (ID *)ob->data, FALSE);
1251
1295
                                        break;
1252
1296
                                case MAKE_LINKS_DUPLIGROUP:
1253
1297
                                        obt->dup_group= ob->dup_group;
1254
 
                                        if(obt->dup_group) {
 
1298
                                        if (obt->dup_group) {
1255
1299
                                                id_lib_extern(&obt->dup_group->id);
1256
1300
                                                obt->transflag |= OB_DUPLIGROUP;
1257
1301
                                        }
1258
1302
                                        break;
1259
1303
                                case MAKE_LINKS_MODIFIERS:
1260
1304
                                        object_link_modifiers(obt, ob);
1261
 
                                        obt->recalc |= OB_RECALC_ALL;
 
1305
                                        obt->recalc |= OB_RECALC_OB|OB_RECALC_DATA|OB_RECALC_TIME;
1262
1306
                                        break;
1263
1307
                                }
1264
1308
                        }
1266
1310
        }
1267
1311
        CTX_DATA_END;
1268
1312
 
1269
 
        DAG_ids_flush_update(0);
 
1313
        DAG_scene_sort(bmain, CTX_data_scene(C));
 
1314
        
 
1315
        DAG_ids_flush_update(bmain, 0);
1270
1316
        WM_event_add_notifier(C, NC_SPACE|ND_SPACE_VIEW3D, CTX_wm_view3d(C));
1271
1317
        return OPERATOR_FINISHED;
1272
1318
}
1277
1323
        PropertyRNA *prop;
1278
1324
 
1279
1325
        /* identifiers */
1280
 
        ot->name= "Link Objects to Scene";
1281
 
        ot->description = "Make linked data local to each object";
1282
 
        ot->idname= "OBJECT_OT_make_links_scene";
 
1326
        ot->name = "Link Objects to Scene";
 
1327
        ot->description = "Link selection to another scene";
 
1328
        ot->idname = "OBJECT_OT_make_links_scene";
1283
1329
 
1284
1330
        /* api callbacks */
1285
 
        ot->exec= make_links_scene_exec;
 
1331
        ot->invoke = WM_enum_search_invoke;
 
1332
        ot->exec = make_links_scene_exec;
1286
1333
        /* better not run the poll check */
1287
1334
 
1288
1335
        /* flags */
1289
 
        ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
 
1336
        ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO;
1290
1337
 
1291
1338
        /* properties */
1292
1339
        prop= RNA_def_enum(ot->srna, "scene", DummyRNA_NULL_items, 0, "Scene", "");
1293
1340
        RNA_def_enum_funcs(prop, RNA_scene_local_itemf);
1294
 
        ot->prop= prop;
 
1341
        ot->prop = prop;
1295
1342
}
1296
1343
 
1297
1344
void OBJECT_OT_make_links_data(wmOperatorType *ot)
1304
1351
                {MAKE_LINKS_MODIFIERS,  "MODIFIERS", 0, "Modifiers", ""},
1305
1352
                {0, NULL, 0, NULL, NULL}};
1306
1353
 
1307
 
        PropertyRNA *prop;
1308
 
 
1309
1354
        /* identifiers */
1310
 
        ot->name= "Link Data";
 
1355
        ot->name = "Link Data";
1311
1356
        ot->description = "Make links from the active object to other selected objects";
1312
 
        ot->idname= "OBJECT_OT_make_links_data";
 
1357
        ot->idname = "OBJECT_OT_make_links_data";
1313
1358
 
1314
1359
        /* api callbacks */
1315
 
        ot->exec= make_links_data_exec;
1316
 
        ot->poll= ED_operator_scene_editable;
 
1360
        ot->exec = make_links_data_exec;
 
1361
        ot->poll = ED_operator_object_active;
1317
1362
 
1318
1363
        /* flags */
1319
 
        ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
 
1364
        ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO;
1320
1365
 
1321
1366
        /* properties */
1322
 
        prop= RNA_def_enum(ot->srna, "type", make_links_items, 0, "Type", "");
 
1367
        ot->prop = RNA_def_enum(ot->srna, "type", make_links_items, 0, "Type", "");
1323
1368
}
1324
1369
 
1325
1370
 
1326
1371
/**************************** Make Single User ********************************/
1327
1372
 
1328
 
static void single_object_users__forwardModifierLinks(void *userData, Object *ob, Object **obpoin)
1329
 
{
1330
 
        ID_NEW(*obpoin);
1331
 
}
1332
 
 
1333
 
void single_object_users(Scene *scene, View3D *v3d, int flag)   
 
1373
static void single_object_users(Scene *scene, View3D *v3d, int flag)    
1334
1374
{
1335
1375
        Base *base;
1336
1376
        Object *ob, *obn;
1338
1378
        clear_sca_new_poins();  /* sensor/contr/act */
1339
1379
 
1340
1380
        /* duplicate (must set newid) */
1341
 
        for(base= FIRSTBASE; base; base= base->next) {
 
1381
        for (base= FIRSTBASE; base; base= base->next) {
1342
1382
                ob= base->object;
1343
1383
                
1344
 
                if( (base->flag & flag)==flag ) {
1345
 
                        if(ob->id.lib==NULL && ob->id.us>1) {
 
1384
                /* newid may still have some trash from Outliner tree building,
 
1385
                 * so clear that first to avoid errors [#26002]
 
1386
                 */
 
1387
                ob->id.newid = NULL;
 
1388
                
 
1389
                if ( (base->flag & flag)==flag ) {
 
1390
                        if (ob->id.lib==NULL && ob->id.us>1) {
1346
1391
                                /* base gets copy of object */
1347
1392
                                obn= copy_object(ob);
1348
1393
                                base->object= obn;
1352
1397
        }
1353
1398
        
1354
1399
        ID_NEW(scene->camera);
1355
 
        if(v3d) ID_NEW(v3d->camera);
 
1400
        if (v3d) ID_NEW(v3d->camera);
1356
1401
        
1357
1402
        /* object pointers */
1358
 
        for(base= FIRSTBASE; base; base= base->next) {
1359
 
                ob= base->object;
1360
 
                if(ob->id.lib==NULL) {
1361
 
                        relink_constraints(&base->object->constraints);
1362
 
                        if (base->object->pose){
1363
 
                                bPoseChannel *chan;
1364
 
                                for (chan = base->object->pose->chanbase.first; chan; chan=chan->next){
1365
 
                                        relink_constraints(&chan->constraints);
1366
 
                                }
1367
 
                        }
1368
 
                        modifiers_foreachObjectLink(base->object, single_object_users__forwardModifierLinks, NULL);
1369
 
                        
1370
 
                        ID_NEW(ob->parent);
1371
 
                }
 
1403
        for (base= FIRSTBASE; base; base= base->next) {
 
1404
                object_relink(base->object);
1372
1405
        }
1373
1406
 
1374
1407
        set_sca_new_poins();
1375
1408
}
1376
1409
 
1377
 
void new_id_matar(Material **matar, int totcol)
 
1410
/* not an especially efficient function, only added so the single user
 
1411
 * button can be functional.*/
 
1412
void ED_object_single_user(Scene *scene, Object *ob)
 
1413
{
 
1414
        Base *base;
 
1415
 
 
1416
        for (base= FIRSTBASE; base; base= base->next) {
 
1417
                if (base->object == ob)  base->flag |=  OB_DONE;
 
1418
                else                                    base->flag &= ~OB_DONE;
 
1419
        }
 
1420
 
 
1421
        single_object_users(scene, NULL, OB_DONE);
 
1422
}
 
1423
 
 
1424
static void new_id_matar(Material **matar, int totcol)
1378
1425
{
1379
1426
        ID *id;
1380
1427
        int a;
1381
1428
        
1382
 
        for(a=0; a<totcol; a++) {
 
1429
        for (a=0; a<totcol; a++) {
1383
1430
                id= (ID *)matar[a];
1384
 
                if(id && id->lib==0) {
1385
 
                        if(id->newid) {
 
1431
                if (id && id->lib == NULL) {
 
1432
                        if (id->newid) {
1386
1433
                                matar[a]= (Material *)id->newid;
1387
1434
                                id_us_plus(id->newid);
1388
1435
                                id->us--;
1389
1436
                        }
1390
 
                        else if(id->us>1) {
 
1437
                        else if (id->us>1) {
1391
1438
                                matar[a]= copy_material(matar[a]);
1392
1439
                                id->us--;
1393
1440
                                id->newid= (ID *)matar[a];
1396
1443
        }
1397
1444
}
1398
1445
 
1399
 
void single_obdata_users(Scene *scene, int flag)
 
1446
static void single_obdata_users(Main *bmain, Scene *scene, int flag)
1400
1447
{
1401
1448
        Object *ob;
1402
1449
        Lamp *la;
1407
1454
        ID *id;
1408
1455
        int a;
1409
1456
 
1410
 
        for(base= FIRSTBASE; base; base= base->next) {
 
1457
        for (base= FIRSTBASE; base; base= base->next) {
1411
1458
                ob= base->object;
1412
 
                if(ob->id.lib==NULL && (base->flag & flag)==flag ) {
 
1459
                if (ob->id.lib==NULL && (base->flag & flag)==flag ) {
1413
1460
                        id= ob->data;
1414
1461
                        
1415
 
                        if(id && id->us>1 && id->lib==0) {
 
1462
                        if (id && id->us>1 && id->lib==NULL) {
1416
1463
                                ob->recalc= OB_RECALC_DATA;
1417
1464
                                
 
1465
                                BKE_copy_animdata_id_action(id);
 
1466
                                
1418
1467
                                switch(ob->type) {
1419
1468
                                case OB_LAMP:
1420
 
                                        if(id && id->us>1 && id->lib==NULL) {
1421
 
                                                ob->data= la= copy_lamp(ob->data);
1422
 
                                                for(a=0; a<MAX_MTEX; a++) {
1423
 
                                                        if(la->mtex[a]) {
1424
 
                                                                ID_NEW(la->mtex[a]->object);
1425
 
                                                        }
 
1469
                                        ob->data= la= copy_lamp(ob->data);
 
1470
                                        for (a=0; a<MAX_MTEX; a++) {
 
1471
                                                if (la->mtex[a]) {
 
1472
                                                        ID_NEW(la->mtex[a]->object);
1426
1473
                                                }
1427
1474
                                        }
1428
1475
                                        break;
1430
1477
                                        ob->data= copy_camera(ob->data);
1431
1478
                                        break;
1432
1479
                                case OB_MESH:
1433
 
                                        me= ob->data= copy_mesh(ob->data);
1434
 
                                        //if(me && me->key)
 
1480
                                        ob->data= copy_mesh(ob->data);
 
1481
                                        //me= ob->data;
 
1482
                                        //if (me && me->key)
1435
1483
                                        //      ipo_idnew(me->key->ipo);        /* drivers */
1436
1484
                                        break;
1437
1485
                                case OB_MBALL:
1452
1500
                                        ob->data= copy_armature(ob->data);
1453
1501
                                        armature_rebuild_pose(ob, ob->data);
1454
1502
                                        break;
 
1503
                                case OB_SPEAKER:
 
1504
                                        ob->data= copy_speaker(ob->data);
 
1505
                                        break;
1455
1506
                                default:
1456
 
                                        if (G.f & G_DEBUG)
1457
 
                                                printf("ERROR single_obdata_users: can't copy %s\n", id->name);
 
1507
                                        if (G.debug & G_DEBUG)
 
1508
                                                printf("ERROR %s: can't copy %s\n", __func__, id->name);
1458
1509
                                        return;
1459
1510
                                }
1460
1511
                                
1463
1514
                                
1464
1515
                        }
1465
1516
                        
1466
 
#if 0 // XXX old animation system
1467
 
                        id= (ID *)ob->action;
1468
 
                        if (id && id->us>1 && id->lib==NULL){
1469
 
                                if(id->newid){
1470
 
                                        ob->action= (bAction *)id->newid;
1471
 
                                        id_us_plus(id->newid);
1472
 
                                }
1473
 
                                else {
1474
 
                                        ob->action= copy_action(ob->action);
1475
 
                                        id->us--;
1476
 
                                        id->newid=(ID *)ob->action;
1477
 
                                }
1478
 
                        }
1479
 
                        id= (ID *)ob->ipo;
1480
 
                        if(id && id->us>1 && id->lib==NULL) {
1481
 
                                if(id->newid) {
1482
 
                                        ob->ipo= (Ipo *)id->newid;
1483
 
                                        id_us_plus(id->newid);
1484
 
                                }
1485
 
                                else {
1486
 
                                        ob->ipo= copy_ipo(ob->ipo);
1487
 
                                        id->us--;
1488
 
                                        id->newid= (ID *)ob->ipo;
1489
 
                                }
1490
 
                                ipo_idnew(ob->ipo);     /* drivers */
1491
 
                        }
1492
 
                        /* other ipos */
1493
 
                        switch(ob->type) {
1494
 
                        case OB_LAMP:
1495
 
                                la= ob->data;
1496
 
                                if(la->ipo && la->ipo->id.us>1) {
1497
 
                                        la->ipo->id.us--;
1498
 
                                        la->ipo= copy_ipo(la->ipo);
1499
 
                                        ipo_idnew(la->ipo);     /* drivers */
1500
 
                                }
1501
 
                                break;
1502
 
                        case OB_CAMERA:
1503
 
                                cam= ob->data;
1504
 
                                if(cam->ipo && cam->ipo->id.us>1) {
1505
 
                                        cam->ipo->id.us--;
1506
 
                                        cam->ipo= copy_ipo(cam->ipo);
1507
 
                                        ipo_idnew(cam->ipo);    /* drivers */
1508
 
                                }
1509
 
                                break;
1510
 
                        }
1511
 
#endif // XXX old animation system
1512
1517
                }
1513
1518
        }
1514
1519
        
1515
 
        me= G.main->mesh.first;
1516
 
        while(me) {
 
1520
        me= bmain->mesh.first;
 
1521
        while (me) {
1517
1522
                ID_NEW(me->texcomesh);
1518
1523
                me= me->id.next;
1519
1524
        }
1520
1525
}
1521
1526
 
1522
 
void single_ipo_users(Scene *scene, int flag)
 
1527
static void single_object_action_users(Scene *scene, int flag)
1523
1528
{
1524
 
#if 0 // XXX old animation system
1525
1529
        Object *ob;
1526
1530
        Base *base;
1527
 
        ID *id;
1528
1531
        
1529
 
        for(base= FIRSTBASE; base; base= base->next) {
 
1532
        for (base= FIRSTBASE; base; base= base->next) {
1530
1533
                ob= base->object;
1531
 
                if(ob->id.lib==NULL && (flag==0 || (base->flag & SELECT)) ) {
 
1534
                if (ob->id.lib==NULL && (flag==0 || (base->flag & SELECT)) ) {
1532
1535
                        ob->recalc= OB_RECALC_DATA;
1533
 
                        
1534
 
                        id= (ID *)ob->ipo;
1535
 
                        if(id && id->us>1 && id->lib==NULL) {
1536
 
                                ob->ipo= copy_ipo(ob->ipo);
1537
 
                                id->us--;
1538
 
                                ipo_idnew(ob->ipo);     /* drivers */
1539
 
                        }
 
1536
                        BKE_copy_animdata_id_action(&ob->id);
1540
1537
                }
1541
1538
        }
1542
 
#endif // XXX old animation system
1543
1539
}
1544
1540
 
1545
1541
static void single_mat_users(Scene *scene, int flag, int do_textures)
1550
1546
        Tex *tex;
1551
1547
        int a, b;
1552
1548
        
1553
 
        for(base= FIRSTBASE; base; base= base->next) {
 
1549
        for (base= FIRSTBASE; base; base= base->next) {
1554
1550
                ob= base->object;
1555
 
                if(ob->id.lib==NULL && (flag==0 || (base->flag & SELECT)) ) {
 
1551
                if (ob->id.lib==NULL && (flag==0 || (base->flag & SELECT)) ) {
1556
1552
        
1557
 
                        for(a=1; a<=ob->totcol; a++) {
 
1553
                        for (a=1; a<=ob->totcol; a++) {
1558
1554
                                ma= give_current_material(ob, a);
1559
 
                                if(ma) {
 
1555
                                if (ma) {
1560
1556
                                        /* do not test for LIB_NEW: this functions guaranteed delivers single_users! */
1561
1557
                                        
1562
 
                                        if(ma->id.us>1) {
 
1558
                                        if (ma->id.us>1) {
1563
1559
                                                man= copy_material(ma);
1564
 
                                        
 
1560
                                                BKE_copy_animdata_id_action(&man->id);
 
1561
                                                
1565
1562
                                                man->id.us= 0;
1566
1563
                                                assign_material(ob, man, a);
1567
 
        
1568
 
#if 0 // XXX old animation system                                               
1569
 
                                                if(ma->ipo) {
1570
 
                                                        man->ipo= copy_ipo(ma->ipo);
1571
 
                                                        ma->ipo->id.us--;
1572
 
                                                        ipo_idnew(ma->ipo);     /* drivers */
1573
 
                                                }
1574
 
#endif // XXX old animation system
1575
 
                                                if(do_textures) {
1576
 
                                                        for(b=0; b<MAX_MTEX; b++) {
1577
 
                                                                if(ma->mtex[b] && ma->mtex[b]->tex) {
1578
 
                                                                        tex= ma->mtex[b]->tex;
1579
 
                                                                        if(tex->id.us>1) {
1580
 
                                                                                ma->mtex[b]->tex= copy_texture(tex);
 
1564
 
 
1565
                                                if (do_textures) {
 
1566
                                                        for (b=0; b<MAX_MTEX; b++) {
 
1567
                                                                if (ma->mtex[b] && (tex= ma->mtex[b]->tex)) {
 
1568
                                                                        if (tex->id.us>1) {
1581
1569
                                                                                tex->id.us--;
 
1570
                                                                                tex= copy_texture(tex);
 
1571
                                                                                BKE_copy_animdata_id_action(&tex->id);
 
1572
                                                                                man->mtex[b]->tex= tex;
1582
1573
                                                                        }
1583
1574
                                                                }
1584
1575
                                                        }
1590
1581
        }
1591
1582
}
1592
1583
 
1593
 
void do_single_tex_user(Tex **from)
 
1584
static void do_single_tex_user(Tex **from)
1594
1585
{
1595
1586
        Tex *tex, *texn;
1596
1587
        
1597
1588
        tex= *from;
1598
 
        if(tex==0) return;
 
1589
        if (tex==NULL) return;
1599
1590
        
1600
 
        if(tex->id.newid) {
 
1591
        if (tex->id.newid) {
1601
1592
                *from= (Tex *)tex->id.newid;
1602
1593
                id_us_plus(tex->id.newid);
1603
1594
                tex->id.us--;
1604
1595
        }
1605
 
        else if(tex->id.us>1) {
 
1596
        else if (tex->id.us>1) {
1606
1597
                texn= copy_texture(tex);
 
1598
                BKE_copy_animdata_id_action(&texn->id);
1607
1599
                tex->id.newid= (ID *)texn;
1608
1600
                tex->id.us--;
1609
1601
                *from= texn;
1610
1602
        }
1611
1603
}
1612
1604
 
1613
 
void single_tex_users_expand()
 
1605
static void single_tex_users_expand(Main *bmain)
1614
1606
{
1615
1607
        /* only when 'parent' blocks are LIB_NEW */
1616
 
        Main *bmain= G.main;
1617
1608
        Material *ma;
1618
1609
        Lamp *la;
1619
1610
        World *wo;
1620
1611
        int b;
1621
1612
                
1622
 
        for(ma= bmain->mat.first; ma; ma=ma->id.next) {
1623
 
                if(ma->id.flag & LIB_NEW) {
1624
 
                        for(b=0; b<MAX_MTEX; b++) {
1625
 
                                if(ma->mtex[b] && ma->mtex[b]->tex) {
 
1613
        for (ma= bmain->mat.first; ma; ma=ma->id.next) {
 
1614
                if (ma->id.flag & LIB_NEW) {
 
1615
                        for (b=0; b<MAX_MTEX; b++) {
 
1616
                                if (ma->mtex[b] && ma->mtex[b]->tex) {
1626
1617
                                        do_single_tex_user( &(ma->mtex[b]->tex) );
1627
1618
                                }
1628
1619
                        }
1629
1620
                }
1630
1621
        }
1631
1622
 
1632
 
        for(la= bmain->lamp.first; la; la=la->id.next) {
1633
 
                if(la->id.flag & LIB_NEW) {
1634
 
                        for(b=0; b<MAX_MTEX; b++) {
1635
 
                                if(la->mtex[b] && la->mtex[b]->tex) {
 
1623
        for (la= bmain->lamp.first; la; la=la->id.next) {
 
1624
                if (la->id.flag & LIB_NEW) {
 
1625
                        for (b=0; b<MAX_MTEX; b++) {
 
1626
                                if (la->mtex[b] && la->mtex[b]->tex) {
1636
1627
                                        do_single_tex_user( &(la->mtex[b]->tex) );
1637
1628
                                }
1638
1629
                        }
1639
1630
                }
1640
1631
        }
1641
1632
 
1642
 
        for(wo= bmain->world.first; wo; wo=wo->id.next) {
1643
 
                if(wo->id.flag & LIB_NEW) {
1644
 
                        for(b=0; b<MAX_MTEX; b++) {
1645
 
                                if(wo->mtex[b] && wo->mtex[b]->tex) {
 
1633
        for (wo= bmain->world.first; wo; wo=wo->id.next) {
 
1634
                if (wo->id.flag & LIB_NEW) {
 
1635
                        for (b=0; b<MAX_MTEX; b++) {
 
1636
                                if (wo->mtex[b] && wo->mtex[b]->tex) {
1646
1637
                                        do_single_tex_user( &(wo->mtex[b]->tex) );
1647
1638
                                }
1648
1639
                        }
1650
1641
        }
1651
1642
}
1652
1643
 
1653
 
static void single_mat_users_expand(void)
 
1644
static void single_mat_users_expand(Main *bmain)
1654
1645
{
1655
1646
        /* only when 'parent' blocks are LIB_NEW */
1656
 
        Main *bmain= G.main;
1657
1647
        Object *ob;
1658
1648
        Mesh *me;
1659
1649
        Curve *cu;
1661
1651
        Material *ma;
1662
1652
        int a;
1663
1653
        
1664
 
        for(ob=bmain->object.first; ob; ob=ob->id.next)
1665
 
                if(ob->id.flag & LIB_NEW)
 
1654
        for (ob=bmain->object.first; ob; ob=ob->id.next)
 
1655
                if (ob->id.flag & LIB_NEW)
1666
1656
                        new_id_matar(ob->mat, ob->totcol);
1667
1657
 
1668
 
        for(me=bmain->mesh.first; me; me=me->id.next)
1669
 
                if(me->id.flag & LIB_NEW)
 
1658
        for (me=bmain->mesh.first; me; me=me->id.next)
 
1659
                if (me->id.flag & LIB_NEW)
1670
1660
                        new_id_matar(me->mat, me->totcol);
1671
1661
 
1672
 
        for(cu=bmain->curve.first; cu; cu=cu->id.next)
1673
 
                if(cu->id.flag & LIB_NEW)
 
1662
        for (cu=bmain->curve.first; cu; cu=cu->id.next)
 
1663
                if (cu->id.flag & LIB_NEW)
1674
1664
                        new_id_matar(cu->mat, cu->totcol);
1675
1665
 
1676
 
        for(mb=bmain->mball.first; mb; mb=mb->id.next)
1677
 
                if(mb->id.flag & LIB_NEW)
 
1666
        for (mb=bmain->mball.first; mb; mb=mb->id.next)
 
1667
                if (mb->id.flag & LIB_NEW)
1678
1668
                        new_id_matar(mb->mat, mb->totcol);
1679
1669
 
1680
1670
        /* material imats  */
1681
 
        for(ma=bmain->mat.first; ma; ma=ma->id.next)
1682
 
                if(ma->id.flag & LIB_NEW)
1683
 
                        for(a=0; a<MAX_MTEX; a++)
1684
 
                                if(ma->mtex[a])
 
1671
        for (ma=bmain->mat.first; ma; ma=ma->id.next)
 
1672
                if (ma->id.flag & LIB_NEW)
 
1673
                        for (a=0; a<MAX_MTEX; a++)
 
1674
                                if (ma->mtex[a])
1685
1675
                                        ID_NEW(ma->mtex[a]->object);
1686
1676
}
1687
1677
 
1688
1678
/* used for copying scenes */
1689
 
void ED_object_single_users(Scene *scene, int full)
 
1679
void ED_object_single_users(Main *bmain, Scene *scene, int full)
1690
1680
{
1691
1681
        single_object_users(scene, NULL, 0);
1692
1682
 
1693
 
        if(full) {
1694
 
                single_obdata_users(scene, 0);
1695
 
                single_mat_users_expand();
1696
 
                single_tex_users_expand();
 
1683
        if (full) {
 
1684
                single_obdata_users(bmain, scene, 0);
 
1685
                single_object_action_users(scene, 0);
 
1686
                single_mat_users_expand(bmain);
 
1687
                single_tex_users_expand(bmain);
1697
1688
        }
1698
1689
 
1699
1690
        clear_id_newpoins();
1709
1700
        
1710
1701
        id_make_local(&ma->id, 0);
1711
1702
        
1712
 
        for(b=0; b<MAX_MTEX; b++)
1713
 
                if(ma->mtex[b] && ma->mtex[b]->tex)
 
1703
        for (b=0; b<MAX_MTEX; b++)
 
1704
                if (ma->mtex[b] && ma->mtex[b]->tex)
1714
1705
                        id_make_local(&ma->mtex[b]->tex->id, 0);
1715
1706
        
1716
1707
        adt= BKE_animdata_from_id(&ma->id);
1717
 
        if(adt) BKE_animdata_make_local(adt);
 
1708
        if (adt) BKE_animdata_make_local(adt);
1718
1709
 
1719
1710
        /* nodetree? XXX */
1720
1711
}
1721
1712
 
1722
1713
static int make_local_exec(bContext *C, wmOperator *op)
1723
1714
{
 
1715
        Main *bmain= CTX_data_main(C);
1724
1716
        AnimData *adt;
1725
1717
        ParticleSystem *psys;
1726
1718
        Material *ma, ***matarar;
1727
1719
        Lamp *la;
1728
1720
        ID *id;
1729
 
        int a, b, mode= RNA_enum_get(op->ptr, "type");;
 
1721
        int a, b, mode= RNA_enum_get(op->ptr, "type");
1730
1722
        
1731
 
        if(mode==3) {
1732
 
                all_local(NULL, 0);     /* NULL is all libs */
 
1723
        if (mode==3) {
 
1724
                BKE_library_make_local(bmain, NULL, 0); /* NULL is all libs */
1733
1725
                WM_event_add_notifier(C, NC_WINDOW, NULL);
1734
1726
                return OPERATOR_FINISHED;
1735
1727
        }
1737
1729
        clear_id_newpoins();
1738
1730
        
1739
1731
        CTX_DATA_BEGIN(C, Object*, ob, selected_objects) {
1740
 
                if(ob->id.lib)
 
1732
                if (ob->id.lib)
1741
1733
                        id_make_local(&ob->id, 0);
1742
1734
        }
1743
1735
        CTX_DATA_END;
1744
1736
        
1745
1737
        /* maybe object pointers */
1746
1738
        CTX_DATA_BEGIN(C, Object*, ob, selected_objects) {
1747
 
                if(ob->id.lib==NULL) {
 
1739
                if (ob->id.lib==NULL) {
1748
1740
                        ID_NEW(ob->parent);
1749
1741
                }
1750
1742
        }
1753
1745
        CTX_DATA_BEGIN(C, Object*, ob, selected_objects) {
1754
1746
                id= ob->data;
1755
1747
                        
1756
 
                if(id && mode>1) {
 
1748
                if (id && mode>1) {
1757
1749
                        id_make_local(id, 0);
1758
1750
                        adt= BKE_animdata_from_id(id);
1759
 
                        if(adt) BKE_animdata_make_local(adt);
 
1751
                        if (adt) BKE_animdata_make_local(adt);
 
1752
                        
 
1753
                        /* tag indirect data direct */
 
1754
                        matarar= (Material ***)give_matarar(ob);
 
1755
                        if (matarar) {
 
1756
                                for (a=0; a<ob->totcol; a++) {
 
1757
                                        ma= (*matarar)[a];
 
1758
                                        if (ma)
 
1759
                                                id_lib_extern(&ma->id);
 
1760
                                }
 
1761
                        }
1760
1762
                }
1761
1763
 
1762
 
                for(psys=ob->particlesystem.first; psys; psys=psys->next)
 
1764
                for (psys=ob->particlesystem.first; psys; psys=psys->next)
1763
1765
                        id_make_local(&psys->part->id, 0);
1764
1766
 
1765
1767
                adt= BKE_animdata_from_id(&ob->id);
1766
 
                if(adt) BKE_animdata_make_local(adt);
 
1768
                if (adt) BKE_animdata_make_local(adt);
1767
1769
        }
1768
1770
        CTX_DATA_END;
1769
1771
 
1770
 
        if(mode>1) {
 
1772
        if (mode>1) {
1771
1773
                CTX_DATA_BEGIN(C, Object*, ob, selected_objects) {
1772
 
                        if(ob->type==OB_LAMP) {
 
1774
                        if (ob->type==OB_LAMP) {
1773
1775
                                la= ob->data;
1774
1776
 
1775
 
                                for(b=0; b<MAX_MTEX; b++)
1776
 
                                        if(la->mtex[b] && la->mtex[b]->tex)
 
1777
                                for (b=0; b<MAX_MTEX; b++)
 
1778
                                        if (la->mtex[b] && la->mtex[b]->tex)
1777
1779
                                                id_make_local(&la->mtex[b]->tex->id, 0);
1778
1780
                        }
1779
1781
                        else {
1780
 
                                for(a=0; a<ob->totcol; a++) {
 
1782
                                for (a=0; a<ob->totcol; a++) {
1781
1783
                                        ma= ob->mat[a];
1782
 
                                        if(ma)
 
1784
                                        if (ma)
1783
1785
                                                make_local_makelocalmaterial(ma);
1784
1786
                                }
1785
1787
                                
1786
1788
                                matarar= (Material ***)give_matarar(ob);
1787
 
                                if(matarar) {
1788
 
                                        for(a=0; a<ob->totcol; a++) {
 
1789
                                if (matarar) {
 
1790
                                        for (a=0; a<ob->totcol; a++) {
1789
1791
                                                ma= (*matarar)[a];
1790
 
                                                if(ma)
 
1792
                                                if (ma)
1791
1793
                                                        make_local_makelocalmaterial(ma);
1792
1794
                                        }
1793
1795
                                }
1810
1812
                {0, NULL, 0, NULL, NULL}};
1811
1813
 
1812
1814
        /* identifiers */
1813
 
        ot->name= "Make Local";
 
1815
        ot->name = "Make Local";
1814
1816
        ot->description = "Make library linked datablocks local to this file";
1815
 
        ot->idname= "OBJECT_OT_make_local";
 
1817
        ot->idname = "OBJECT_OT_make_local";
1816
1818
        
1817
1819
        /* api callbacks */
1818
 
        ot->invoke= WM_menu_invoke;
1819
 
        ot->exec= make_local_exec;
1820
 
        ot->poll= ED_operator_scene_editable;
 
1820
        ot->invoke = WM_menu_invoke;
 
1821
        ot->exec = make_local_exec;
 
1822
        ot->poll = ED_operator_objectmode;
1821
1823
        
1822
1824
        /* flags */
1823
 
        ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
 
1825
        ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO;
1824
1826
        
1825
1827
        /* properties */
1826
 
        ot->prop= RNA_def_enum(ot->srna, "type", type_items, 0, "Type", "");
 
1828
        ot->prop = RNA_def_enum(ot->srna, "type", type_items, 0, "Type", "");
1827
1829
}
1828
1830
 
1829
1831
static int make_single_user_exec(bContext *C, wmOperator *op)
1830
1832
{
 
1833
        Main *bmain= CTX_data_main(C);
1831
1834
        Scene *scene= CTX_data_scene(C);
1832
1835
        View3D *v3d= CTX_wm_view3d(C); /* ok if this is NULL */
1833
1836
        int flag= RNA_enum_get(op->ptr, "type"); /* 0==ALL, SELECTED==selected objecs */
1834
1837
 
1835
 
        if(RNA_boolean_get(op->ptr, "object"))
 
1838
        if (RNA_boolean_get(op->ptr, "object"))
1836
1839
                single_object_users(scene, v3d, flag);
1837
1840
 
1838
 
        if(RNA_boolean_get(op->ptr, "obdata"))
1839
 
                single_obdata_users(scene, flag);
1840
 
 
1841
 
        if(RNA_boolean_get(op->ptr, "material"))
1842
 
                single_mat_users(scene, flag, FALSE);
1843
 
 
1844
 
        if(RNA_boolean_get(op->ptr, "texture"))
 
1841
        if (RNA_boolean_get(op->ptr, "obdata"))
 
1842
                single_obdata_users(bmain, scene, flag);
 
1843
 
 
1844
        if (RNA_boolean_get(op->ptr, "material"))
 
1845
                single_mat_users(scene, flag, RNA_boolean_get(op->ptr, "texture"));
 
1846
 
 
1847
#if 0 /* can't do this separate from materials */
 
1848
        if (RNA_boolean_get(op->ptr, "texture"))
1845
1849
                single_mat_users(scene, flag, TRUE);
1846
 
 
1847
 
        if(RNA_boolean_get(op->ptr, "animation"))
1848
 
                single_ipo_users(scene, flag);
 
1850
#endif
 
1851
        if (RNA_boolean_get(op->ptr, "animation"))
 
1852
                single_object_action_users(scene, flag);
1849
1853
 
1850
1854
        clear_id_newpoins();
1851
1855
 
1861
1865
                {0, NULL, 0, NULL, NULL}};
1862
1866
 
1863
1867
        /* identifiers */
1864
 
        ot->name= "Make Single User";
 
1868
        ot->name = "Make Single User";
1865
1869
        ot->description = "Make linked data local to each object";
1866
 
        ot->idname= "OBJECT_OT_make_single_user";
 
1870
        ot->idname = "OBJECT_OT_make_single_user";
1867
1871
 
1868
1872
        /* api callbacks */
1869
 
        ot->invoke= WM_menu_invoke;
1870
 
        ot->exec= make_single_user_exec;
1871
 
        ot->poll= ED_operator_scene_editable;
 
1873
        ot->invoke = WM_menu_invoke;
 
1874
        ot->exec = make_single_user_exec;
 
1875
        ot->poll = ED_operator_objectmode;
1872
1876
 
1873
1877
        /* flags */
1874
 
        ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
 
1878
        ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO;
1875
1879
 
1876
1880
        /* properties */
1877
 
        ot->prop= RNA_def_enum(ot->srna, "type", type_items, 0, "Type", "");
 
1881
        ot->prop = RNA_def_enum(ot->srna, "type", type_items, SELECT, "Type", "");
1878
1882
 
1879
1883
        RNA_def_boolean(ot->srna, "object", 0, "Object", "Make single user objects");
1880
1884
        RNA_def_boolean(ot->srna, "obdata", 0, "Object Data", "Make single user object data");
1881
1885
        RNA_def_boolean(ot->srna, "material", 0, "Materials", "Make materials local to each datablock");
1882
1886
        RNA_def_boolean(ot->srna, "texture", 0, "Textures", "Make textures local to each material");
1883
 
        RNA_def_boolean(ot->srna, "animation", 0, "Animation Data", "Make animation data local to each object");
 
1887
        RNA_def_boolean(ot->srna, "animation", 0, "Object Animation", "Make animation data local to each object");
1884
1888
}
1885
1889
 
1886
1890
static int drop_named_material_invoke(bContext *C, wmOperator *op, wmEvent *event)
1887
1891
{
 
1892
        Main *bmain= CTX_data_main(C);
1888
1893
        Base *base= ED_view3d_give_base_under_cursor(C, event->mval);
1889
1894
        Material *ma;
1890
 
        char name[32];
 
1895
        char name[MAX_ID_NAME-2];
1891
1896
        
1892
1897
        RNA_string_get(op->ptr, "name", name);
1893
1898
        ma= (Material *)find_id("MA", name);
1894
 
        if(base==NULL || ma==NULL) 
 
1899
        if (base==NULL || ma==NULL) 
1895
1900
                return OPERATOR_CANCELLED;
1896
1901
        
1897
1902
        assign_material(base->object, ma, 1);
1898
1903
        
1899
 
        DAG_ids_flush_update(0);
 
1904
        DAG_ids_flush_update(bmain, 0);
1900
1905
        WM_event_add_notifier(C, NC_SPACE|ND_SPACE_VIEW3D, CTX_wm_view3d(C));
1901
1906
        
1902
1907
        return OPERATOR_FINISHED;
1908
1913
{
1909
1914
 
1910
1915
        /* identifiers */
1911
 
        ot->name= "Drop Named Material on Object";
 
1916
        ot->name = "Drop Named Material on Object";
1912
1917
        ot->description = "";
1913
 
        ot->idname= "OBJECT_OT_drop_named_material";
 
1918
        ot->idname = "OBJECT_OT_drop_named_material";
1914
1919
        
1915
1920
        /* api callbacks */
1916
 
        ot->invoke= drop_named_material_invoke;
1917
 
        ot->poll= ED_operator_scene_editable;
 
1921
        ot->invoke = drop_named_material_invoke;
 
1922
        ot->poll = ED_operator_objectmode;
1918
1923
        
1919
1924
        /* flags */
1920
 
        ot->flag= OPTYPE_UNDO;
 
1925
        ot->flag = OPTYPE_UNDO;
1921
1926
        
1922
1927
        /* properties */
1923
 
        RNA_def_string(ot->srna, "name", "Material", 24, "Name", "Material name to assign.");
 
1928
        RNA_def_string(ot->srna, "name", "Material", MAX_ID_NAME-2, "Name", "Material name to assign");
1924
1929
}