Fix #23363: Layer buttons do not update when last object deleted
[blender-staging.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         WM_event_add_notifier(C, NC_SCENE|ND_LAYER_CONTENT, scene);
1113
1114         DAG_scene_sort(bmain, scene);
1115
1116         return OPERATOR_FINISHED;
1117 }
1118
1119 void OBJECT_OT_move_to_layer(wmOperatorType *ot)
1120 {
1121         /* identifiers */
1122         ot->name= "Move to Layer";
1123         ot->description = "Move the object to different layers";
1124         ot->idname= "OBJECT_OT_move_to_layer";
1125         
1126         /* api callbacks */
1127         ot->invoke= move_to_layer_invoke;
1128         ot->exec= move_to_layer_exec;
1129         ot->poll= ED_operator_scene_editable;
1130         
1131         /* flags */
1132         ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
1133         
1134         /* properties */
1135         RNA_def_boolean_layer_member(ot->srna, "layers", 20, NULL, "Layer", "");
1136 }
1137
1138 /************************** Link to Scene Operator *****************************/
1139
1140 void link_to_scene(Main *bmain, unsigned short nr)
1141 {
1142 #if 0
1143         Scene *sce= (Scene*) BLI_findlink(&bmain->scene, G.curscreen->scenenr-1);
1144         Base *base, *nbase;
1145         
1146         if(sce==0) return;
1147         if(sce->id.lib) return;
1148         
1149         for(base= FIRSTBASE; base; base= base->next) {
1150                 if(TESTBASE(v3d, base)) {
1151                         
1152                         nbase= MEM_mallocN( sizeof(Base), "newbase");
1153                         *nbase= *base;
1154                         BLI_addhead( &(sce->base), nbase);
1155                         id_us_plus((ID *)base->object);
1156                 }
1157         }
1158 #endif
1159 }
1160
1161 static int make_links_scene_exec(bContext *C, wmOperator *op)
1162 {
1163         Main *bmain= CTX_data_main(C);
1164         Scene *scene_to= BLI_findlink(&CTX_data_main(C)->scene, RNA_enum_get(op->ptr, "scene"));
1165
1166         if(scene_to==NULL) {
1167                 BKE_report(op->reports, RPT_ERROR, "Scene not found");
1168                 return OPERATOR_CANCELLED;
1169         }
1170
1171         if(scene_to == CTX_data_scene(C)) {
1172                 BKE_report(op->reports, RPT_ERROR, "Can't link objects into the same scene");
1173                 return OPERATOR_CANCELLED;
1174         }
1175
1176         if(scene_to->id.lib) {
1177                 BKE_report(op->reports, RPT_ERROR, "Can't link objects into a linked scene");
1178                 return OPERATOR_CANCELLED;
1179         }
1180
1181         CTX_DATA_BEGIN(C, Base*, base, selected_bases)
1182         {
1183                 if(!object_in_scene(base->object, scene_to)) {
1184                         Base *nbase= MEM_mallocN( sizeof(Base), "newbase");
1185                         *nbase= *base;
1186                         BLI_addhead( &(scene_to->base), nbase);
1187                         id_us_plus((ID *)base->object);
1188                 }
1189         }
1190         CTX_DATA_END;
1191
1192         DAG_ids_flush_update(bmain, 0);
1193
1194         /* one day multiple scenes will be visible, then we should have some update function for them */
1195         return OPERATOR_FINISHED;
1196 }
1197
1198 enum {
1199         MAKE_LINKS_OBDATA = 1,
1200         MAKE_LINKS_MATERIALS,
1201         MAKE_LINKS_ANIMDATA,
1202         MAKE_LINKS_DUPLIGROUP,
1203         MAKE_LINKS_MODIFIERS
1204 };
1205
1206 /* Return 1 if make link data is allow, zero otherwise */
1207 static int allow_make_links_data(int ev, Object *ob, Object *obt)
1208 {
1209         switch(ev) {
1210                 case MAKE_LINKS_OBDATA:
1211                         if (ob->type == obt->type && ob->type != OB_EMPTY)
1212                                 return 1;
1213                         break;
1214                 case MAKE_LINKS_MATERIALS:
1215                         if (ELEM5(ob->type, OB_MESH, OB_CURVE, OB_FONT, OB_SURF, OB_MBALL) &&
1216                                 ELEM5(obt->type, OB_MESH, OB_CURVE, OB_FONT, OB_SURF, OB_MBALL))
1217                                 return 1;
1218                         break;
1219                 case MAKE_LINKS_ANIMDATA:
1220                 case MAKE_LINKS_DUPLIGROUP:
1221                         return 1;
1222                 case MAKE_LINKS_MODIFIERS:
1223                         if (ob->type != OB_EMPTY && obt->type != OB_EMPTY)
1224                                 return 1;
1225                         break;
1226         }
1227         return 0;
1228 }
1229
1230 static int make_links_data_exec(bContext *C, wmOperator *op)
1231 {
1232         Main *bmain= CTX_data_main(C);
1233         int event = RNA_int_get(op->ptr, "type");
1234         Object *ob;
1235         ID *id;
1236         int a;
1237
1238         ob= CTX_data_active_object(C);
1239
1240         CTX_DATA_BEGIN(C, Object*, obt, selected_editable_objects) {
1241                 if(ob != obt) {
1242                         if (allow_make_links_data(event, ob, obt)) {
1243                                 switch(event) {
1244                                 case MAKE_LINKS_OBDATA: /* obdata */
1245                                         id= obt->data;
1246                                         id->us--;
1247
1248                                         id= ob->data;
1249                                         id_us_plus(id);
1250                                         obt->data= id;
1251
1252                                         /* if amount of material indices changed: */
1253                                         test_object_materials(obt->data);
1254
1255                                         obt->recalc |= OB_RECALC_DATA;
1256                                         break;
1257                                 case MAKE_LINKS_MATERIALS:
1258                                         /* new approach, using functions from kernel */
1259                                         for(a=0; a<ob->totcol; a++) {
1260                                                 Material *ma= give_current_material(ob, a+1);
1261                                                 assign_material(obt, ma, a+1);  /* also works with ma==NULL */
1262                                         }
1263                                         break;
1264                                 case MAKE_LINKS_ANIMDATA:
1265                                         BKE_copy_animdata_id((ID *)obt, (ID *)ob);
1266                                         BKE_copy_animdata_id((ID *)obt->data, (ID *)ob->data);
1267                                         break;
1268                                 case MAKE_LINKS_DUPLIGROUP:
1269                                         obt->dup_group= ob->dup_group;
1270                                         if(obt->dup_group) {
1271                                                 id_lib_extern(&obt->dup_group->id);
1272                                                 obt->transflag |= OB_DUPLIGROUP;
1273                                         }
1274                                         break;
1275                                 case MAKE_LINKS_MODIFIERS:
1276                                         object_link_modifiers(obt, ob);
1277                                         obt->recalc |= OB_RECALC_ALL;
1278                                         break;
1279                                 }
1280                         }
1281                 }
1282         }
1283         CTX_DATA_END;
1284
1285         DAG_ids_flush_update(bmain, 0);
1286         WM_event_add_notifier(C, NC_SPACE|ND_SPACE_VIEW3D, CTX_wm_view3d(C));
1287         return OPERATOR_FINISHED;
1288 }
1289
1290
1291 void OBJECT_OT_make_links_scene(wmOperatorType *ot)
1292 {
1293         PropertyRNA *prop;
1294
1295         /* identifiers */
1296         ot->name= "Link Objects to Scene";
1297         ot->description = "Make linked data local to each object";
1298         ot->idname= "OBJECT_OT_make_links_scene";
1299
1300         /* api callbacks */
1301         ot->exec= make_links_scene_exec;
1302         /* better not run the poll check */
1303
1304         /* flags */
1305         ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
1306
1307         /* properties */
1308         prop= RNA_def_enum(ot->srna, "scene", DummyRNA_NULL_items, 0, "Scene", "");
1309         RNA_def_enum_funcs(prop, RNA_scene_local_itemf);
1310         ot->prop= prop;
1311 }
1312
1313 void OBJECT_OT_make_links_data(wmOperatorType *ot)
1314 {
1315         static EnumPropertyItem make_links_items[]= {
1316                 {MAKE_LINKS_OBDATA,             "OBDATA", 0, "Object Data", ""},
1317                 {MAKE_LINKS_MATERIALS,  "MATERIAL", 0, "Materials", ""},
1318                 {MAKE_LINKS_ANIMDATA,   "ANIMATION", 0, "Animation Data", ""},
1319                 {MAKE_LINKS_DUPLIGROUP, "DUPLIGROUP", 0, "DupliGroup", ""},
1320                 {MAKE_LINKS_MODIFIERS,  "MODIFIERS", 0, "Modifiers", ""},
1321                 {0, NULL, 0, NULL, NULL}};
1322
1323         PropertyRNA *prop;
1324
1325         /* identifiers */
1326         ot->name= "Link Data";
1327         ot->description = "Make links from the active object to other selected objects";
1328         ot->idname= "OBJECT_OT_make_links_data";
1329
1330         /* api callbacks */
1331         ot->exec= make_links_data_exec;
1332         ot->poll= ED_operator_scene_editable;
1333
1334         /* flags */
1335         ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
1336
1337         /* properties */
1338         prop= RNA_def_enum(ot->srna, "type", make_links_items, 0, "Type", "");
1339 }
1340
1341
1342 /**************************** Make Single User ********************************/
1343
1344 static void single_object_users__forwardModifierLinks(void *userData, Object *ob, Object **obpoin)
1345 {
1346         ID_NEW(*obpoin);
1347 }
1348
1349 void single_object_users(Scene *scene, View3D *v3d, int flag)   
1350 {
1351         Base *base;
1352         Object *ob, *obn;
1353         
1354         clear_sca_new_poins();  /* sensor/contr/act */
1355
1356         /* duplicate (must set newid) */
1357         for(base= FIRSTBASE; base; base= base->next) {
1358                 ob= base->object;
1359                 
1360                 if( (base->flag & flag)==flag ) {
1361                         if(ob->id.lib==NULL && ob->id.us>1) {
1362                                 /* base gets copy of object */
1363                                 obn= copy_object(ob);
1364                                 base->object= obn;
1365                                 ob->id.us--;
1366                         }
1367                 }
1368         }
1369         
1370         ID_NEW(scene->camera);
1371         if(v3d) ID_NEW(v3d->camera);
1372         
1373         /* object pointers */
1374         for(base= FIRSTBASE; base; base= base->next) {
1375                 ob= base->object;
1376                 if(ob->id.lib==NULL) {
1377                         relink_constraints(&base->object->constraints);
1378                         if (base->object->pose){
1379                                 bPoseChannel *chan;
1380                                 for (chan = base->object->pose->chanbase.first; chan; chan=chan->next){
1381                                         relink_constraints(&chan->constraints);
1382                                 }
1383                         }
1384                         modifiers_foreachObjectLink(base->object, single_object_users__forwardModifierLinks, NULL);
1385                         
1386                         ID_NEW(ob->parent);
1387                 }
1388         }
1389
1390         set_sca_new_poins();
1391 }
1392
1393 void new_id_matar(Material **matar, int totcol)
1394 {
1395         ID *id;
1396         int a;
1397         
1398         for(a=0; a<totcol; a++) {
1399                 id= (ID *)matar[a];
1400                 if(id && id->lib==0) {
1401                         if(id->newid) {
1402                                 matar[a]= (Material *)id->newid;
1403                                 id_us_plus(id->newid);
1404                                 id->us--;
1405                         }
1406                         else if(id->us>1) {
1407                                 matar[a]= copy_material(matar[a]);
1408                                 id->us--;
1409                                 id->newid= (ID *)matar[a];
1410                         }
1411                 }
1412         }
1413 }
1414
1415 void single_obdata_users(Main *bmain, Scene *scene, int flag)
1416 {
1417         Object *ob;
1418         Lamp *la;
1419         Curve *cu;
1420         //Camera *cam;
1421         Base *base;
1422         Mesh *me;
1423         ID *id;
1424         int a;
1425
1426         for(base= FIRSTBASE; base; base= base->next) {
1427                 ob= base->object;
1428                 if(ob->id.lib==NULL && (base->flag & flag)==flag ) {
1429                         id= ob->data;
1430                         
1431                         if(id && id->us>1 && id->lib==0) {
1432                                 ob->recalc= OB_RECALC_DATA;
1433                                 
1434                                 switch(ob->type) {
1435                                 case OB_LAMP:
1436                                         if(id && id->us>1 && id->lib==NULL) {
1437                                                 ob->data= la= copy_lamp(ob->data);
1438                                                 for(a=0; a<MAX_MTEX; a++) {
1439                                                         if(la->mtex[a]) {
1440                                                                 ID_NEW(la->mtex[a]->object);
1441                                                         }
1442                                                 }
1443                                         }
1444                                         break;
1445                                 case OB_CAMERA:
1446                                         ob->data= copy_camera(ob->data);
1447                                         break;
1448                                 case OB_MESH:
1449                                         me= ob->data= copy_mesh(ob->data);
1450                                         //if(me && me->key)
1451                                         //      ipo_idnew(me->key->ipo);        /* drivers */
1452                                         break;
1453                                 case OB_MBALL:
1454                                         ob->data= copy_mball(ob->data);
1455                                         break;
1456                                 case OB_CURVE:
1457                                 case OB_SURF:
1458                                 case OB_FONT:
1459                                         ob->data= cu= copy_curve(ob->data);
1460                                         ID_NEW(cu->bevobj);
1461                                         ID_NEW(cu->taperobj);
1462                                         break;
1463                                 case OB_LATTICE:
1464                                         ob->data= copy_lattice(ob->data);
1465                                         break;
1466                                 case OB_ARMATURE:
1467                                         ob->recalc |= OB_RECALC_DATA;
1468                                         ob->data= copy_armature(ob->data);
1469                                         armature_rebuild_pose(ob, ob->data);
1470                                         break;
1471                                 default:
1472                                         if (G.f & G_DEBUG)
1473                                                 printf("ERROR single_obdata_users: can't copy %s\n", id->name);
1474                                         return;
1475                                 }
1476                                 
1477                                 id->us--;
1478                                 id->newid= ob->data;
1479                                 
1480                         }
1481                         
1482 #if 0 // XXX old animation system
1483                         id= (ID *)ob->action;
1484                         if (id && id->us>1 && id->lib==NULL){
1485                                 if(id->newid){
1486                                         ob->action= (bAction *)id->newid;
1487                                         id_us_plus(id->newid);
1488                                 }
1489                                 else {
1490                                         ob->action= copy_action(ob->action);
1491                                         id->us--;
1492                                         id->newid=(ID *)ob->action;
1493                                 }
1494                         }
1495                         id= (ID *)ob->ipo;
1496                         if(id && id->us>1 && id->lib==NULL) {
1497                                 if(id->newid) {
1498                                         ob->ipo= (Ipo *)id->newid;
1499                                         id_us_plus(id->newid);
1500                                 }
1501                                 else {
1502                                         ob->ipo= copy_ipo(ob->ipo);
1503                                         id->us--;
1504                                         id->newid= (ID *)ob->ipo;
1505                                 }
1506                                 ipo_idnew(ob->ipo);     /* drivers */
1507                         }
1508                         /* other ipos */
1509                         switch(ob->type) {
1510                         case OB_LAMP:
1511                                 la= ob->data;
1512                                 if(la->ipo && la->ipo->id.us>1) {
1513                                         la->ipo->id.us--;
1514                                         la->ipo= copy_ipo(la->ipo);
1515                                         ipo_idnew(la->ipo);     /* drivers */
1516                                 }
1517                                 break;
1518                         case OB_CAMERA:
1519                                 cam= ob->data;
1520                                 if(cam->ipo && cam->ipo->id.us>1) {
1521                                         cam->ipo->id.us--;
1522                                         cam->ipo= copy_ipo(cam->ipo);
1523                                         ipo_idnew(cam->ipo);    /* drivers */
1524                                 }
1525                                 break;
1526                         }
1527 #endif // XXX old animation system
1528                 }
1529         }
1530         
1531         me= bmain->mesh.first;
1532         while(me) {
1533                 ID_NEW(me->texcomesh);
1534                 me= me->id.next;
1535         }
1536 }
1537
1538 void single_ipo_users(Scene *scene, int flag)
1539 {
1540 #if 0 // XXX old animation system
1541         Object *ob;
1542         Base *base;
1543         ID *id;
1544         
1545         for(base= FIRSTBASE; base; base= base->next) {
1546                 ob= base->object;
1547                 if(ob->id.lib==NULL && (flag==0 || (base->flag & SELECT)) ) {
1548                         ob->recalc= OB_RECALC_DATA;
1549                         
1550                         id= (ID *)ob->ipo;
1551                         if(id && id->us>1 && id->lib==NULL) {
1552                                 ob->ipo= copy_ipo(ob->ipo);
1553                                 id->us--;
1554                                 ipo_idnew(ob->ipo);     /* drivers */
1555                         }
1556                 }
1557         }
1558 #endif // XXX old animation system
1559 }
1560
1561 static void single_mat_users(Scene *scene, int flag, int do_textures)
1562 {
1563         Object *ob;
1564         Base *base;
1565         Material *ma, *man;
1566         Tex *tex;
1567         int a, b;
1568         
1569         for(base= FIRSTBASE; base; base= base->next) {
1570                 ob= base->object;
1571                 if(ob->id.lib==NULL && (flag==0 || (base->flag & SELECT)) ) {
1572         
1573                         for(a=1; a<=ob->totcol; a++) {
1574                                 ma= give_current_material(ob, a);
1575                                 if(ma) {
1576                                         /* do not test for LIB_NEW: this functions guaranteed delivers single_users! */
1577                                         
1578                                         if(ma->id.us>1) {
1579                                                 man= copy_material(ma);
1580                                         
1581                                                 man->id.us= 0;
1582                                                 assign_material(ob, man, a);
1583         
1584 #if 0 // XXX old animation system                                               
1585                                                 if(ma->ipo) {
1586                                                         man->ipo= copy_ipo(ma->ipo);
1587                                                         ma->ipo->id.us--;
1588                                                         ipo_idnew(ma->ipo);     /* drivers */
1589                                                 }
1590 #endif // XXX old animation system
1591                                                 if(do_textures) {
1592                                                         for(b=0; b<MAX_MTEX; b++) {
1593                                                                 if(ma->mtex[b] && ma->mtex[b]->tex) {
1594                                                                         tex= ma->mtex[b]->tex;
1595                                                                         if(tex->id.us>1) {
1596                                                                                 ma->mtex[b]->tex= copy_texture(tex);
1597                                                                                 tex->id.us--;
1598                                                                         }
1599                                                                 }
1600                                                         }
1601                                                 }
1602                                         }
1603                                 }
1604                         }
1605                 }
1606         }
1607 }
1608
1609 void do_single_tex_user(Tex **from)
1610 {
1611         Tex *tex, *texn;
1612         
1613         tex= *from;
1614         if(tex==0) return;
1615         
1616         if(tex->id.newid) {
1617                 *from= (Tex *)tex->id.newid;
1618                 id_us_plus(tex->id.newid);
1619                 tex->id.us--;
1620         }
1621         else if(tex->id.us>1) {
1622                 texn= copy_texture(tex);
1623                 tex->id.newid= (ID *)texn;
1624                 tex->id.us--;
1625                 *from= texn;
1626         }
1627 }
1628
1629 void single_tex_users_expand(Main *bmain)
1630 {
1631         /* only when 'parent' blocks are LIB_NEW */
1632         Material *ma;
1633         Lamp *la;
1634         World *wo;
1635         int b;
1636                 
1637         for(ma= bmain->mat.first; ma; ma=ma->id.next) {
1638                 if(ma->id.flag & LIB_NEW) {
1639                         for(b=0; b<MAX_MTEX; b++) {
1640                                 if(ma->mtex[b] && ma->mtex[b]->tex) {
1641                                         do_single_tex_user( &(ma->mtex[b]->tex) );
1642                                 }
1643                         }
1644                 }
1645         }
1646
1647         for(la= bmain->lamp.first; la; la=la->id.next) {
1648                 if(la->id.flag & LIB_NEW) {
1649                         for(b=0; b<MAX_MTEX; b++) {
1650                                 if(la->mtex[b] && la->mtex[b]->tex) {
1651                                         do_single_tex_user( &(la->mtex[b]->tex) );
1652                                 }
1653                         }
1654                 }
1655         }
1656
1657         for(wo= bmain->world.first; wo; wo=wo->id.next) {
1658                 if(wo->id.flag & LIB_NEW) {
1659                         for(b=0; b<MAX_MTEX; b++) {
1660                                 if(wo->mtex[b] && wo->mtex[b]->tex) {
1661                                         do_single_tex_user( &(wo->mtex[b]->tex) );
1662                                 }
1663                         }
1664                 }
1665         }
1666 }
1667
1668 static void single_mat_users_expand(Main *bmain)
1669 {
1670         /* only when 'parent' blocks are LIB_NEW */
1671         Object *ob;
1672         Mesh *me;
1673         Curve *cu;
1674         MetaBall *mb;
1675         Material *ma;
1676         int a;
1677         
1678         for(ob=bmain->object.first; ob; ob=ob->id.next)
1679                 if(ob->id.flag & LIB_NEW)
1680                         new_id_matar(ob->mat, ob->totcol);
1681
1682         for(me=bmain->mesh.first; me; me=me->id.next)
1683                 if(me->id.flag & LIB_NEW)
1684                         new_id_matar(me->mat, me->totcol);
1685
1686         for(cu=bmain->curve.first; cu; cu=cu->id.next)
1687                 if(cu->id.flag & LIB_NEW)
1688                         new_id_matar(cu->mat, cu->totcol);
1689
1690         for(mb=bmain->mball.first; mb; mb=mb->id.next)
1691                 if(mb->id.flag & LIB_NEW)
1692                         new_id_matar(mb->mat, mb->totcol);
1693
1694         /* material imats  */
1695         for(ma=bmain->mat.first; ma; ma=ma->id.next)
1696                 if(ma->id.flag & LIB_NEW)
1697                         for(a=0; a<MAX_MTEX; a++)
1698                                 if(ma->mtex[a])
1699                                         ID_NEW(ma->mtex[a]->object);
1700 }
1701
1702 /* used for copying scenes */
1703 void ED_object_single_users(Main *bmain, Scene *scene, int full)
1704 {
1705         single_object_users(scene, NULL, 0);
1706
1707         if(full) {
1708                 single_obdata_users(bmain, scene, 0);
1709                 single_mat_users_expand(bmain);
1710                 single_tex_users_expand(bmain);
1711         }
1712
1713         clear_id_newpoins();
1714 }
1715
1716 /******************************* Make Local ***********************************/
1717
1718 /* helper for below, ma was checked to be not NULL */
1719 static void make_local_makelocalmaterial(Material *ma)
1720 {
1721         AnimData *adt;
1722         int b;
1723         
1724         id_make_local(&ma->id, 0);
1725         
1726         for(b=0; b<MAX_MTEX; b++)
1727                 if(ma->mtex[b] && ma->mtex[b]->tex)
1728                         id_make_local(&ma->mtex[b]->tex->id, 0);
1729         
1730         adt= BKE_animdata_from_id(&ma->id);
1731         if(adt) BKE_animdata_make_local(adt);
1732
1733         /* nodetree? XXX */
1734 }
1735
1736 static int make_local_exec(bContext *C, wmOperator *op)
1737 {
1738         AnimData *adt;
1739         ParticleSystem *psys;
1740         Material *ma, ***matarar;
1741         Lamp *la;
1742         ID *id;
1743         int a, b, mode= RNA_enum_get(op->ptr, "type");;
1744         
1745         if(mode==3) {
1746                 all_local(NULL, 0);     /* NULL is all libs */
1747                 WM_event_add_notifier(C, NC_WINDOW, NULL);
1748                 return OPERATOR_FINISHED;
1749         }
1750
1751         clear_id_newpoins();
1752         
1753         CTX_DATA_BEGIN(C, Object*, ob, selected_objects) {
1754                 if(ob->id.lib)
1755                         id_make_local(&ob->id, 0);
1756         }
1757         CTX_DATA_END;
1758         
1759         /* maybe object pointers */
1760         CTX_DATA_BEGIN(C, Object*, ob, selected_objects) {
1761                 if(ob->id.lib==NULL) {
1762                         ID_NEW(ob->parent);
1763                 }
1764         }
1765         CTX_DATA_END;
1766
1767         CTX_DATA_BEGIN(C, Object*, ob, selected_objects) {
1768                 id= ob->data;
1769                         
1770                 if(id && mode>1) {
1771                         id_make_local(id, 0);
1772                         adt= BKE_animdata_from_id(id);
1773                         if(adt) BKE_animdata_make_local(adt);
1774                 }
1775
1776                 for(psys=ob->particlesystem.first; psys; psys=psys->next)
1777                         id_make_local(&psys->part->id, 0);
1778
1779                 adt= BKE_animdata_from_id(&ob->id);
1780                 if(adt) BKE_animdata_make_local(adt);
1781         }
1782         CTX_DATA_END;
1783
1784         if(mode>1) {
1785                 CTX_DATA_BEGIN(C, Object*, ob, selected_objects) {
1786                         if(ob->type==OB_LAMP) {
1787                                 la= ob->data;
1788
1789                                 for(b=0; b<MAX_MTEX; b++)
1790                                         if(la->mtex[b] && la->mtex[b]->tex)
1791                                                 id_make_local(&la->mtex[b]->tex->id, 0);
1792                         }
1793                         else {
1794                                 for(a=0; a<ob->totcol; a++) {
1795                                         ma= ob->mat[a];
1796                                         if(ma)
1797                                                 make_local_makelocalmaterial(ma);
1798                                 }
1799                                 
1800                                 matarar= (Material ***)give_matarar(ob);
1801                                 if(matarar) {
1802                                         for(a=0; a<ob->totcol; a++) {
1803                                                 ma= (*matarar)[a];
1804                                                 if(ma)
1805                                                         make_local_makelocalmaterial(ma);
1806                                         }
1807                                 }
1808                         }
1809                 }
1810                 CTX_DATA_END;
1811         }
1812
1813         WM_event_add_notifier(C, NC_WINDOW, NULL);
1814
1815         return OPERATOR_FINISHED;
1816 }
1817
1818 void OBJECT_OT_make_local(wmOperatorType *ot)
1819 {
1820         static EnumPropertyItem type_items[]= {
1821                 {1, "SELECTED_OBJECTS", 0, "Selected Objects", ""},
1822                 {2, "SELECTED_OBJECTS_DATA", 0, "Selected Objects and Data", ""},
1823                 {3, "ALL", 0, "All", ""},
1824                 {0, NULL, 0, NULL, NULL}};
1825
1826         /* identifiers */
1827         ot->name= "Make Local";
1828         ot->description = "Make library linked datablocks local to this file";
1829         ot->idname= "OBJECT_OT_make_local";
1830         
1831         /* api callbacks */
1832         ot->invoke= WM_menu_invoke;
1833         ot->exec= make_local_exec;
1834         ot->poll= ED_operator_scene_editable;
1835         
1836         /* flags */
1837         ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
1838         
1839         /* properties */
1840         ot->prop= RNA_def_enum(ot->srna, "type", type_items, 0, "Type", "");
1841 }
1842
1843 static int make_single_user_exec(bContext *C, wmOperator *op)
1844 {
1845         Main *bmain= CTX_data_main(C);
1846         Scene *scene= CTX_data_scene(C);
1847         View3D *v3d= CTX_wm_view3d(C); /* ok if this is NULL */
1848         int flag= RNA_enum_get(op->ptr, "type"); /* 0==ALL, SELECTED==selected objecs */
1849
1850         if(RNA_boolean_get(op->ptr, "object"))
1851                 single_object_users(scene, v3d, flag);
1852
1853         if(RNA_boolean_get(op->ptr, "obdata"))
1854                 single_obdata_users(bmain, scene, flag);
1855
1856         if(RNA_boolean_get(op->ptr, "material"))
1857                 single_mat_users(scene, flag, FALSE);
1858
1859         if(RNA_boolean_get(op->ptr, "texture"))
1860                 single_mat_users(scene, flag, TRUE);
1861
1862         if(RNA_boolean_get(op->ptr, "animation"))
1863                 single_ipo_users(scene, flag);
1864
1865         clear_id_newpoins();
1866
1867         WM_event_add_notifier(C, NC_WINDOW, NULL);
1868         return OPERATOR_FINISHED;
1869 }
1870
1871 void OBJECT_OT_make_single_user(wmOperatorType *ot)
1872 {
1873         static EnumPropertyItem type_items[]= {
1874                 {SELECT, "SELECTED_OBJECTS", 0, "Selected Objects", ""},
1875                 {0, "ALL", 0, "All", ""},
1876                 {0, NULL, 0, NULL, NULL}};
1877
1878         /* identifiers */
1879         ot->name= "Make Single User";
1880         ot->description = "Make linked data local to each object";
1881         ot->idname= "OBJECT_OT_make_single_user";
1882
1883         /* api callbacks */
1884         ot->invoke= WM_menu_invoke;
1885         ot->exec= make_single_user_exec;
1886         ot->poll= ED_operator_scene_editable;
1887
1888         /* flags */
1889         ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
1890
1891         /* properties */
1892         ot->prop= RNA_def_enum(ot->srna, "type", type_items, 0, "Type", "");
1893
1894         RNA_def_boolean(ot->srna, "object", 0, "Object", "Make single user objects");
1895         RNA_def_boolean(ot->srna, "obdata", 0, "Object Data", "Make single user object data");
1896         RNA_def_boolean(ot->srna, "material", 0, "Materials", "Make materials local to each datablock");
1897         RNA_def_boolean(ot->srna, "texture", 0, "Textures", "Make textures local to each material");
1898         RNA_def_boolean(ot->srna, "animation", 0, "Animation Data", "Make animation data local to each object");
1899 }
1900
1901 static int drop_named_material_invoke(bContext *C, wmOperator *op, wmEvent *event)
1902 {
1903         Main *bmain= CTX_data_main(C);
1904         Base *base= ED_view3d_give_base_under_cursor(C, event->mval);
1905         Material *ma;
1906         char name[32];
1907         
1908         RNA_string_get(op->ptr, "name", name);
1909         ma= (Material *)find_id("MA", name);
1910         if(base==NULL || ma==NULL) 
1911                 return OPERATOR_CANCELLED;
1912         
1913         assign_material(base->object, ma, 1);
1914         
1915         DAG_ids_flush_update(bmain, 0);
1916         WM_event_add_notifier(C, NC_SPACE|ND_SPACE_VIEW3D, CTX_wm_view3d(C));
1917         
1918         return OPERATOR_FINISHED;
1919 }
1920
1921 /* used for dropbox */
1922 /* assigns to object under cursor, only first material slot */
1923 void OBJECT_OT_drop_named_material(wmOperatorType *ot)
1924 {
1925
1926         /* identifiers */
1927         ot->name= "Drop Named Material on Object";
1928         ot->description = "";
1929         ot->idname= "OBJECT_OT_drop_named_material";
1930         
1931         /* api callbacks */
1932         ot->invoke= drop_named_material_invoke;
1933         ot->poll= ED_operator_scene_editable;
1934         
1935         /* flags */
1936         ot->flag= OPTYPE_UNDO;
1937         
1938         /* properties */
1939         RNA_def_string(ot->srna, "name", "Material", 24, "Name", "Material name to assign.");
1940 }