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