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