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