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