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