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