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