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