2a0d6e6c046a56f2100ed1a654e32e19fb1f1aff
[blender.git] / source / blender / editors / object / object_add.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 <stdlib.h>
29 #include <string.h>
30
31 #include "MEM_guardedalloc.h"
32
33 #include "DNA_action_types.h"
34 #include "DNA_curve_types.h"
35 #include "DNA_group_types.h"
36 #include "DNA_lamp_types.h"
37 #include "DNA_material_types.h"
38 #include "DNA_mesh_types.h"
39 #include "DNA_meta_types.h"
40 #include "DNA_object_fluidsim.h"
41 #include "DNA_object_types.h"
42 #include "DNA_object_force.h"
43 #include "DNA_scene_types.h"
44 #include "DNA_screen_types.h"
45 #include "DNA_userdef_types.h"
46 #include "DNA_view3d_types.h"
47 #include "DNA_vfont_types.h"
48
49 #include "BLI_math.h"
50 #include "BLI_listbase.h"
51
52 #include "BKE_anim.h"
53 #include "BKE_armature.h"
54 #include "BKE_constraint.h"
55 #include "BKE_context.h"
56 #include "BKE_curve.h"
57 #include "BKE_customdata.h"
58 #include "BKE_depsgraph.h"
59 #include "BKE_DerivedMesh.h"
60 #include "BKE_displist.h"
61 #include "BKE_effect.h"
62 #include "BKE_global.h"
63 #include "BKE_group.h"
64 #include "BKE_lattice.h"
65 #include "BKE_library.h"
66 #include "BKE_main.h"
67 #include "BKE_material.h"
68 #include "BKE_mball.h"
69 #include "BKE_mesh.h"
70 #include "BKE_modifier.h"
71 #include "BKE_object.h"
72 #include "BKE_particle.h"
73 #include "BKE_report.h"
74 #include "BKE_sca.h"
75 #include "BKE_scene.h"
76 #include "BKE_texture.h"
77 #include "BKE_utildefines.h"
78
79 #include "RNA_access.h"
80 #include "RNA_define.h"
81 #include "RNA_enum_types.h"
82
83 #include "WM_api.h"
84 #include "WM_types.h"
85
86 #include "ED_anim_api.h"
87 #include "ED_armature.h"
88 #include "ED_curve.h"
89 #include "ED_mball.h"
90 #include "ED_mesh.h"
91 #include "ED_object.h"
92 #include "ED_render.h"
93 #include "ED_screen.h"
94 #include "ED_transform.h"
95
96 #include "UI_interface.h"
97 #include "UI_resources.h"
98
99 #include "object_intern.h"
100
101 /************************** Exported *****************************/
102
103 void ED_object_location_from_view(bContext *C, float *loc)
104 {
105         View3D *v3d= CTX_wm_view3d(C);
106         Scene *scene= CTX_data_scene(C);
107         
108         if (v3d) {
109                 if (v3d->localvd)
110                         copy_v3_v3(loc, v3d->cursor);
111                 else
112                         copy_v3_v3(loc, scene->cursor);
113         } else {
114                 copy_v3_v3(loc, scene->cursor);
115         }
116 }
117
118 void ED_object_rotation_from_view(bContext *C, float *rot)
119 {
120         RegionView3D *rv3d = CTX_wm_region_view3d(C);
121         
122         if(rv3d) {
123                 rv3d->viewquat[0]= -rv3d->viewquat[0];
124                 quat_to_eul( rot, rv3d->viewquat);
125                 rv3d->viewquat[0]= -rv3d->viewquat[0];
126         }
127         else
128                 rot[0] = rot[1] = rot[2] = 0.f;
129 }
130
131 void ED_object_base_init_transform(bContext *C, Base *base, float *loc, float *rot)
132 {
133         Object *ob= base->object;
134         Scene *scene= CTX_data_scene(C);
135         
136         if (!scene) return;
137         
138         if (loc)
139                 copy_v3_v3(ob->loc, loc);
140         
141         if (rot)
142                 copy_v3_v3(ob->rot, rot);
143         
144         where_is_object(scene, ob);
145 }
146
147 /* uses context to figure out transform for primitive */
148 /* returns standard diameter */
149 float ED_object_new_primitive_matrix(bContext *C, float *loc, float *rot, float primmat[][4])
150 {
151         Object *obedit= CTX_data_edit_object(C);
152         View3D *v3d =CTX_wm_view3d(C);
153         float mat[3][3], rmat[3][3], cmat[3][3], imat[3][3];
154         
155         unit_m4(primmat);
156         
157         eul_to_mat3(rmat, rot);
158         invert_m3(rmat);
159         
160         /* inverse transform for initial rotation and object */
161         copy_m3_m4(mat, obedit->obmat);
162         mul_m3_m3m3(cmat, rmat, mat);
163         invert_m3_m3(imat, cmat);
164         copy_m4_m3(primmat, imat);
165         
166         /* center */
167         VECCOPY(primmat[3], loc);
168         VECSUB(primmat[3], primmat[3], obedit->obmat[3]);
169         invert_m3_m3(imat, mat);
170         mul_m3_v3(imat, primmat[3]);
171         
172         if(v3d) return v3d->grid;
173         return 1.0f;
174 }
175
176 /********************* Add Object Operator ********************/
177
178 void add_object_draw(Scene *scene, View3D *v3d, int type)       /* for toolbox or menus, only non-editmode stuff */
179 {
180         /* keep here to get things compile, remove later */
181 }
182
183 void ED_object_add_generic_props(wmOperatorType *ot, int do_editmode)
184 {
185         PropertyRNA *prop;
186         RNA_def_boolean(ot->srna, "view_align", 0, "Align to View", "Align the new object to the view.");
187
188         if(do_editmode)
189                 RNA_def_boolean(ot->srna, "enter_editmode", 0, "Enter Editmode", "Enter editmode when adding this object.");
190         
191         RNA_def_float_vector(ot->srna, "location", 3, NULL, -FLT_MAX, FLT_MAX, "Location", "Location for the newly added object.", -FLT_MAX, FLT_MAX);
192         RNA_def_float_rotation(ot->srna, "rotation", 3, NULL, -FLT_MAX, FLT_MAX, "Rotation", "Rotation for the newly added object", -FLT_MAX, FLT_MAX);
193         
194         prop = RNA_def_boolean_layer_member(ot->srna, "layer", 32, NULL, "Layer", "");
195         RNA_def_property_flag(prop, PROP_HIDDEN);
196 }
197
198 static void object_add_generic_invoke_options(bContext *C, wmOperator *op)
199 {
200         if(RNA_struct_find_property(op->ptr, "enter_editmode")) /* optional */
201                 if (!RNA_property_is_set(op->ptr, "enter_editmode"))
202                         RNA_boolean_set(op->ptr, "enter_editmode", U.flag & USER_ADD_EDITMODE);
203         
204         if (!RNA_property_is_set(op->ptr, "location")) {
205                 float loc[3];
206                 
207                 ED_object_location_from_view(C, loc);
208                 RNA_float_set_array(op->ptr, "location", loc);
209         }
210         
211         if (!RNA_property_is_set(op->ptr, "rotation")) {
212                 int view_align;
213                 float rot[3] = {0.f, 0.f, 0.f};
214         
215                 /* view align property is just used to set rotation property */
216                 if (!RNA_property_is_set(op->ptr, "view_align"))
217                         view_align = U.flag & USER_ADD_VIEWALIGNED;
218                 else
219                         view_align = RNA_boolean_get(op->ptr, "view_align");
220                 
221                 if (view_align)
222                         ED_object_rotation_from_view(C, rot);
223
224                 RNA_float_set_array(op->ptr, "rotation", rot);
225         }
226
227         if (!RNA_property_is_set(op->ptr, "layer")) {
228                 View3D *v3d = CTX_wm_view3d(C);
229                 Scene *scene = CTX_data_scene(C);
230                 int a, values[32], layer;
231                 
232                 if (v3d) {
233                         if (v3d->localvd) {
234                                 layer = v3d->layact + v3d->lay;
235                                 for(a=0; a<32; a++)
236                                         values[a]= (layer & (1<<a));
237                         } else {
238                                 layer = v3d->layact;
239                                 for(a=0; a<32; a++)
240                                         values[a]= (layer & (1<<a));
241                         }
242                 } else {
243                         layer = scene->lay;
244                         for(a=0; a<32; a++)
245                                 values[a]= (layer & (1<<a));
246                 }
247                 
248                 RNA_boolean_set_array(op->ptr, "layer", values);
249         }
250 }
251
252 int ED_object_add_generic_invoke(bContext *C, wmOperator *op, wmEvent *event)
253 {
254         object_add_generic_invoke_options(C, op);
255         return op->type->exec(C, op);
256 }
257
258 void ED_object_add_generic_get_opts(wmOperator *op, float *loc, float *rot, int *enter_editmode, unsigned int *layer)
259 {
260         int a, layer_values[32];
261         
262         *enter_editmode = FALSE;
263         if(RNA_struct_find_property(op->ptr, "enter_editmode") && RNA_boolean_get(op->ptr, "enter_editmode")) {
264                 *enter_editmode = TRUE;
265         }
266         
267         RNA_float_get_array(op->ptr, "location", loc);
268         RNA_float_get_array(op->ptr, "rotation", rot);
269         RNA_boolean_get_array(op->ptr, "layer", layer_values);
270         
271         for(a=0; a<32; a++)
272                 if(layer_values[a])
273                         *layer |= (1 << a);
274                 else
275                         *layer &= ~(1 << a);
276 }
277
278 /* for object add primitive operators */
279 Object *ED_object_add_type(bContext *C, int type, float *loc, float *rot, int enter_editmode, unsigned int layer)
280 {
281         Scene *scene= CTX_data_scene(C);
282         Object *ob;
283         
284         /* for as long scene has editmode... */
285         if (CTX_data_edit_object(C)) 
286                 ED_object_exit_editmode(C, EM_FREEDATA|EM_FREEUNDO|EM_WAITCURSOR|EM_DO_UNDO); /* freedata, and undo */
287         
288         /* deselects all, sets scene->basact */
289         ob= add_object(scene, type);
290         BASACT->lay = ob->lay = layer;
291         /* editor level activate, notifiers */
292         ED_base_object_activate(C, BASACT);
293
294         /* more editor stuff */
295         ED_object_base_init_transform(C, BASACT, loc, rot);
296
297         DAG_scene_sort(scene);
298         ED_render_id_flush_update(G.main, ob->data);
299
300         if(enter_editmode)
301                 ED_object_enter_editmode(C, EM_IGNORE_LAYER);
302
303         return ob;
304 }
305
306 /* for object add operator */
307 static int object_add_exec(bContext *C, wmOperator *op)
308 {
309         int enter_editmode;
310         unsigned int layer;
311         float loc[3], rot[3];
312         
313         ED_object_add_generic_get_opts(op, loc, rot, &enter_editmode, &layer);
314         ED_object_add_type(C, RNA_enum_get(op->ptr, "type"), loc, rot, enter_editmode, layer);
315         
316         return OPERATOR_FINISHED;
317 }
318
319 void OBJECT_OT_add(wmOperatorType *ot)
320 {
321         /* identifiers */
322         ot->name= "Add Object";
323         ot->description = "Add an object to the scene";
324         ot->idname= "OBJECT_OT_add";
325         
326         /* api callbacks */
327         ot->invoke= ED_object_add_generic_invoke;
328         ot->exec= object_add_exec;
329         
330         ot->poll= ED_operator_scene_editable;
331         
332         /* flags */
333         ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
334         
335         RNA_def_enum(ot->srna, "type", object_type_items, 0, "Type", "");
336
337         ED_object_add_generic_props(ot, TRUE);
338 }
339
340 /********************* Add Effector Operator ********************/
341 /* copy from rna_object_force.c*/
342 static EnumPropertyItem field_type_items[] = {
343         {PFIELD_FORCE, "FORCE", ICON_FORCE_FORCE, "Force", ""},
344         {PFIELD_WIND, "WIND", ICON_FORCE_WIND, "Wind", ""},
345         {PFIELD_VORTEX, "VORTEX", ICON_FORCE_VORTEX, "Vortex", ""},
346         {PFIELD_MAGNET, "MAGNET", ICON_FORCE_MAGNETIC, "Magnetic", ""},
347         {PFIELD_HARMONIC, "HARMONIC", ICON_FORCE_HARMONIC, "Harmonic", ""},
348         {PFIELD_CHARGE, "CHARGE", ICON_FORCE_CHARGE, "Charge", ""},
349         {PFIELD_LENNARDJ, "LENNARDJ", ICON_FORCE_LENNARDJONES, "Lennard-Jones", ""},
350         {PFIELD_TEXTURE, "TEXTURE", ICON_FORCE_TEXTURE, "Texture", ""},
351         {PFIELD_GUIDE, "GUIDE", ICON_FORCE_CURVE, "Curve Guide", ""},
352         {PFIELD_BOID, "BOID", ICON_FORCE_BOID, "Boid", ""},
353         {PFIELD_TURBULENCE, "TURBULENCE", ICON_FORCE_TURBULENCE, "Turbulence", ""},
354         {PFIELD_DRAG, "DRAG", ICON_FORCE_DRAG, "Drag", ""},
355         {0, NULL, 0, NULL, NULL}};
356
357 void add_effector_draw(Scene *scene, View3D *v3d, int type)     /* for toolbox or menus, only non-editmode stuff */
358 {
359         /* keep here to get things compile, remove later */
360 }
361
362 /* for effector add primitive operators */
363 static Object *effector_add_type(bContext *C, wmOperator *op, int type)
364 {
365         Object *ob;
366         int enter_editmode;
367         unsigned int layer;
368         float loc[3], rot[3];
369         float mat[4][4];
370         
371         object_add_generic_invoke_options(C, op);
372         ED_object_add_generic_get_opts(op, loc, rot, &enter_editmode, &layer);
373
374         if(type==PFIELD_GUIDE) {
375                 ob= ED_object_add_type(C, OB_CURVE, loc, rot, FALSE, layer);
376                 rename_id(&ob->id, "CurveGuide");
377
378                 ((Curve*)ob->data)->flag |= CU_PATH|CU_3D;
379                 ED_object_enter_editmode(C, 0);
380                 ED_object_new_primitive_matrix(C, loc, rot, mat);
381                 BLI_addtail(curve_get_editcurve(ob), add_nurbs_primitive(C, mat, CU_NURBS|CU_PRIM_PATH, 1));
382
383                 if(!enter_editmode)
384                         ED_object_exit_editmode(C, EM_FREEDATA);
385         }
386         else {
387                 ob= ED_object_add_type(C, OB_EMPTY, loc, rot, FALSE, layer);
388                 rename_id(&ob->id, "Field");
389
390                 switch(type) {
391                         case PFIELD_WIND:
392                         case PFIELD_VORTEX:
393                                 ob->empty_drawtype = OB_SINGLE_ARROW;
394                                 break;
395                 }
396         }
397
398         ob->pd= object_add_collision_fields(type);
399
400         return ob;
401 }
402
403 /* for object add operator */
404 static int effector_add_exec(bContext *C, wmOperator *op)
405 {
406         effector_add_type(C, op, RNA_int_get(op->ptr, "type"));
407         
408         return OPERATOR_FINISHED;
409 }
410
411 void OBJECT_OT_effector_add(wmOperatorType *ot)
412 {
413         /* identifiers */
414         ot->name= "Add Effector";
415         ot->description = "Add an empty object with a physics effector to the scene";
416         ot->idname= "OBJECT_OT_effector_add";
417         
418         /* api callbacks */
419         ot->invoke= WM_menu_invoke;
420         ot->exec= effector_add_exec;
421         
422         ot->poll= ED_operator_scene_editable;
423         
424         /* flags */
425         ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
426         
427         ot->prop= RNA_def_enum(ot->srna, "type", field_type_items, 0, "Type", "");
428
429         ED_object_add_generic_props(ot, TRUE);
430 }
431
432 /* ***************** Add Camera *************** */
433
434 static int object_camera_add_exec(bContext *C, wmOperator *op)
435 {
436         View3D *v3d = CTX_wm_view3d(C);
437         Scene *scene= CTX_data_scene(C);
438         Object *ob;
439         int enter_editmode;
440         unsigned int layer;
441         float loc[3], rot[3];
442         
443         /* force view align for cameras */
444         RNA_boolean_set(op->ptr, "view_align", 1);
445         
446         object_add_generic_invoke_options(C, op);
447         ED_object_add_generic_get_opts(op, loc, rot, &enter_editmode, &layer);
448
449         ob= ED_object_add_type(C, OB_CAMERA, loc, rot, FALSE, layer);
450         
451         if (v3d) {
452                 if (v3d->camera == NULL)
453                         v3d->camera = ob;
454                 if (v3d->scenelock && scene->camera==NULL) {
455                         scene->camera = ob;
456                 }
457         }
458
459         return OPERATOR_FINISHED;
460 }
461
462 void OBJECT_OT_camera_add(wmOperatorType *ot)
463 {
464         /* identifiers */
465         ot->name= "Add Camera";
466         ot->description = "Add a camera object to the scene";
467         ot->idname= "OBJECT_OT_camera_add";
468         
469         /* api callbacks */
470         ot->exec= object_camera_add_exec;
471         ot->poll= ED_operator_scene_editable;
472         
473         /* flags */
474         ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
475                 
476         ED_object_add_generic_props(ot, TRUE);
477 }
478
479
480 /* ***************** add primitives *************** */
481
482 static EnumPropertyItem prop_curve_types[] = {
483         {CU_BEZIER|CU_PRIM_CURVE, "BEZIER_CURVE", ICON_CURVE_BEZCURVE, "Bezier Curve", ""},
484         {CU_BEZIER|CU_PRIM_CIRCLE, "BEZIER_CIRCLE", ICON_CURVE_BEZCIRCLE, "Bezier Circle", ""},
485         {CU_NURBS|CU_PRIM_CURVE, "NURBS_CURVE", ICON_CURVE_NCURVE, "NURBS Curve", ""},
486         {CU_NURBS|CU_PRIM_CIRCLE, "NURBS_CIRCLE", ICON_CURVE_NCIRCLE, "NURBS Circle", ""},
487         {CU_NURBS|CU_PRIM_PATH, "PATH", ICON_CURVE_PATH, "Path", ""},
488         {0, NULL, 0, NULL, NULL}
489 };
490
491 static int object_add_curve_exec(bContext *C, wmOperator *op)
492 {
493         Object *obedit= CTX_data_edit_object(C);
494         ListBase *editnurb;
495         Nurb *nu;
496         int newob= 0, type= RNA_enum_get(op->ptr, "type");
497         int enter_editmode;
498         unsigned int layer;
499         float loc[3], rot[3];
500         float mat[4][4];
501         
502         object_add_generic_invoke_options(C, op); // XXX these props don't get set right when only exec() is called
503         ED_object_add_generic_get_opts(op, loc, rot, &enter_editmode, &layer);
504         
505         if(obedit==NULL || obedit->type!=OB_CURVE) {
506                 obedit= ED_object_add_type(C, OB_CURVE, loc, rot, TRUE, layer);
507                 newob = 1;
508
509                 if(type & CU_PRIM_PATH)
510                         ((Curve*)obedit->data)->flag |= CU_PATH|CU_3D;
511         }
512         else DAG_id_flush_update(&obedit->id, OB_RECALC_DATA);
513         
514         ED_object_new_primitive_matrix(C, loc, rot, mat);
515         
516         nu= add_nurbs_primitive(C, mat, type, newob);
517         editnurb= curve_get_editcurve(obedit);
518         BLI_addtail(editnurb, nu);
519         
520         /* userdef */
521         if (newob && !enter_editmode) {
522                 ED_object_exit_editmode(C, EM_FREEDATA);
523         }
524         
525         WM_event_add_notifier(C, NC_OBJECT|ND_DRAW, obedit);
526         
527         return OPERATOR_FINISHED;
528 }
529
530 static int object_add_curve_invoke(bContext *C, wmOperator *op, wmEvent *event)
531 {
532         Object *obedit= CTX_data_edit_object(C);
533         uiPopupMenu *pup;
534         uiLayout *layout;
535
536         object_add_generic_invoke_options(C, op);
537
538         pup= uiPupMenuBegin(C, op->type->name, 0);
539         layout= uiPupMenuLayout(pup);
540         if(!obedit || obedit->type == OB_CURVE)
541                 uiItemsEnumO(layout, op->type->idname, "type");
542         else
543                 uiItemsEnumO(layout, "OBJECT_OT_surface_add", "type");
544         uiPupMenuEnd(C, pup);
545
546         return OPERATOR_CANCELLED;
547 }
548
549 void OBJECT_OT_curve_add(wmOperatorType *ot)
550 {
551         /* identifiers */
552         ot->name= "Add Curve";
553         ot->description = "Add a curve object to the scene";
554         ot->idname= "OBJECT_OT_curve_add";
555         
556         /* api callbacks */
557         ot->invoke= object_add_curve_invoke;
558         ot->exec= object_add_curve_exec;
559         
560         ot->poll= ED_operator_scene_editable;
561         
562         /* flags */
563         ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
564         
565         RNA_def_enum(ot->srna, "type", prop_curve_types, 0, "Primitive", "");
566
567         ED_object_add_generic_props(ot, TRUE);
568 }
569
570 static EnumPropertyItem prop_surface_types[]= {
571         {CU_PRIM_CURVE|CU_NURBS, "NURBS_CURVE", ICON_SURFACE_NCURVE, "NURBS Curve", ""},
572         {CU_PRIM_CIRCLE|CU_NURBS, "NURBS_CIRCLE", ICON_SURFACE_NCIRCLE, "NURBS Circle", ""},
573         {CU_PRIM_PATCH|CU_NURBS, "NURBS_SURFACE", ICON_SURFACE_NSURFACE, "NURBS Surface", ""},
574         {CU_PRIM_TUBE|CU_NURBS, "NURBS_TUBE", ICON_SURFACE_NTUBE, "NURBS Tube", ""},
575         {CU_PRIM_SPHERE|CU_NURBS, "NURBS_SPHERE", ICON_SURFACE_NSPHERE, "NURBS Sphere", ""},
576         {CU_PRIM_DONUT|CU_NURBS, "NURBS_DONUT", ICON_SURFACE_NDONUT, "NURBS Donut", ""},
577         {0, NULL, 0, NULL, NULL}
578 };
579
580 static int object_add_surface_exec(bContext *C, wmOperator *op)
581 {
582         Object *obedit= CTX_data_edit_object(C);
583         ListBase *editnurb;
584         Nurb *nu;
585         int newob= 0;
586         int enter_editmode;
587         unsigned int layer;
588         float loc[3], rot[3];
589         float mat[4][4];
590         
591         object_add_generic_invoke_options(C, op); // XXX these props don't get set right when only exec() is called
592         ED_object_add_generic_get_opts(op, loc, rot, &enter_editmode, &layer);
593         
594         if(obedit==NULL || obedit->type!=OB_SURF) {
595                 obedit= ED_object_add_type(C, OB_SURF, loc, rot, TRUE, layer);
596                 newob = 1;
597         }
598         else DAG_id_flush_update(&obedit->id, OB_RECALC_DATA);
599         
600         ED_object_new_primitive_matrix(C, loc, rot, mat);
601         
602         nu= add_nurbs_primitive(C, mat, RNA_enum_get(op->ptr, "type"), newob);
603         editnurb= curve_get_editcurve(obedit);
604         BLI_addtail(editnurb, nu);
605         
606         /* userdef */
607         if (newob && !enter_editmode) {
608                 ED_object_exit_editmode(C, EM_FREEDATA);
609         }
610         
611         WM_event_add_notifier(C, NC_OBJECT|ND_DRAW, obedit);
612         
613         return OPERATOR_FINISHED;
614 }
615
616 void OBJECT_OT_surface_add(wmOperatorType *ot)
617 {
618         /* identifiers */
619         ot->name= "Add Surface";
620         ot->description = "Add a surface object to the scene";
621         ot->idname= "OBJECT_OT_surface_add";
622         
623         /* api callbacks */
624         ot->invoke= WM_menu_invoke;
625         ot->exec= object_add_surface_exec;
626         
627         ot->poll= ED_operator_scene_editable;
628         
629         /* flags */
630         ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
631         
632         ot->prop= RNA_def_enum(ot->srna, "type", prop_surface_types, 0, "Primitive", "");
633         ED_object_add_generic_props(ot, TRUE);
634 }
635
636 static EnumPropertyItem prop_metaball_types[]= {
637         {MB_BALL, "MBALL_BALL", ICON_META_BALL, "Meta Ball", ""},
638         {MB_TUBE, "MBALL_TUBE", ICON_META_TUBE, "Meta Tube", ""},
639         {MB_PLANE, "MBALL_PLANE", ICON_META_PLANE, "Meta Plane", ""},
640         {MB_CUBE, "MBALL_CUBE", ICON_META_CUBE, "Meta Cube", ""},
641         {MB_ELIPSOID, "MBALL_ELLIPSOID", ICON_META_ELLIPSOID, "Meta Ellipsoid", ""},
642         {0, NULL, 0, NULL, NULL}
643 };
644
645 static int object_metaball_add_exec(bContext *C, wmOperator *op)
646 {
647         Object *obedit= CTX_data_edit_object(C);
648         MetaBall *mball;
649         MetaElem *elem;
650         int newob= 0;
651         int enter_editmode;
652         unsigned int layer;
653         float loc[3], rot[3];
654         float mat[4][4];
655         
656         object_add_generic_invoke_options(C, op); // XXX these props don't get set right when only exec() is called
657         ED_object_add_generic_get_opts(op, loc, rot, &enter_editmode, &layer);
658         
659         if(obedit==NULL || obedit->type!=OB_MBALL) {
660                 obedit= ED_object_add_type(C, OB_MBALL, loc, rot, TRUE, layer);
661                 newob = 1;
662         }
663         else DAG_id_flush_update(&obedit->id, OB_RECALC_DATA);
664         
665         ED_object_new_primitive_matrix(C, loc, rot, mat);
666         
667         elem= (MetaElem*)add_metaball_primitive(C, mat, RNA_enum_get(op->ptr, "type"), newob);
668         mball= (MetaBall*)obedit->data;
669         BLI_addtail(mball->editelems, elem);
670         
671         /* userdef */
672         if (newob && !enter_editmode) {
673                 ED_object_exit_editmode(C, EM_FREEDATA);
674         }
675         
676         WM_event_add_notifier(C, NC_OBJECT|ND_DRAW, obedit);
677         
678         return OPERATOR_FINISHED;
679 }
680
681 static int object_metaball_add_invoke(bContext *C, wmOperator *op, wmEvent *event)
682 {
683         Object *obedit= CTX_data_edit_object(C);
684         uiPopupMenu *pup;
685         uiLayout *layout;
686
687         object_add_generic_invoke_options(C, op);
688
689         pup= uiPupMenuBegin(C, op->type->name, 0);
690         layout= uiPupMenuLayout(pup);
691         if(!obedit || obedit->type == OB_MBALL)
692                 uiItemsEnumO(layout, op->type->idname, "type");
693         else
694                 uiItemsEnumO(layout, "OBJECT_OT_metaball_add", "type");
695         uiPupMenuEnd(C, pup);
696
697         return OPERATOR_CANCELLED;
698 }
699
700 void OBJECT_OT_metaball_add(wmOperatorType *ot)
701 {
702         /* identifiers */
703         ot->name= "Add Metaball";
704         ot->description= "Add an metaball object to the scene";
705         ot->idname= "OBJECT_OT_metaball_add";
706
707         /* api callbacks */
708         ot->invoke= object_metaball_add_invoke;
709         ot->exec= object_metaball_add_exec;
710         ot->poll= ED_operator_scene_editable;
711
712         /* flags */
713         ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
714         
715         RNA_def_enum(ot->srna, "type", prop_metaball_types, 0, "Primitive", "");
716         ED_object_add_generic_props(ot, TRUE);
717 }
718
719 static int object_add_text_exec(bContext *C, wmOperator *op)
720 {
721         Object *obedit= CTX_data_edit_object(C);
722         int enter_editmode;
723         unsigned int layer;
724         float loc[3], rot[3];
725         
726         object_add_generic_invoke_options(C, op); // XXX these props don't get set right when only exec() is called
727         ED_object_add_generic_get_opts(op, loc, rot, &enter_editmode, &layer);
728         
729         if(obedit && obedit->type==OB_FONT)
730                 return OPERATOR_CANCELLED;
731
732         obedit= ED_object_add_type(C, OB_FONT, loc, rot, enter_editmode, layer);
733         
734         WM_event_add_notifier(C, NC_OBJECT|ND_DRAW, obedit);
735         
736         return OPERATOR_FINISHED;
737 }
738
739 void OBJECT_OT_text_add(wmOperatorType *ot)
740 {
741         /* identifiers */
742         ot->name= "Add Text";
743         ot->description = "Add a text object to the scene";
744         ot->idname= "OBJECT_OT_text_add";
745         
746         /* api callbacks */
747         ot->invoke= ED_object_add_generic_invoke;
748         ot->exec= object_add_text_exec;
749         ot->poll= ED_operator_scene_editable;
750         
751         /* flags */
752         ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
753         ED_object_add_generic_props(ot, TRUE);
754 }
755
756 static int object_armature_add_exec(bContext *C, wmOperator *op)
757 {
758         Object *obedit= CTX_data_edit_object(C);
759         View3D *v3d= CTX_wm_view3d(C);
760         RegionView3D *rv3d= NULL;
761         int newob= 0;
762         int enter_editmode;
763         unsigned int layer;
764         float loc[3], rot[3];
765         
766         object_add_generic_invoke_options(C, op); // XXX these props don't get set right when only exec() is called
767         ED_object_add_generic_get_opts(op, loc, rot, &enter_editmode, &layer);
768         
769         if ((obedit==NULL) || (obedit->type != OB_ARMATURE)) {
770                 obedit= ED_object_add_type(C, OB_ARMATURE, loc, rot, TRUE, layer);
771                 ED_object_enter_editmode(C, 0);
772                 newob = 1;
773         }
774         else DAG_id_flush_update(&obedit->id, OB_RECALC_DATA);
775         
776         if(obedit==NULL) {
777                 BKE_report(op->reports, RPT_ERROR, "Cannot create editmode armature.");
778                 return OPERATOR_CANCELLED;
779         }
780         
781         if(v3d) 
782                 rv3d= CTX_wm_region(C)->regiondata;
783         
784         /* v3d and rv3d are allowed to be NULL */
785         add_primitive_bone(CTX_data_scene(C), v3d, rv3d);
786
787         /* userdef */
788         if (newob && !enter_editmode)
789                 ED_object_exit_editmode(C, EM_FREEDATA);
790         
791         WM_event_add_notifier(C, NC_OBJECT|ND_DRAW, obedit);
792         
793         return OPERATOR_FINISHED;
794 }
795
796 void OBJECT_OT_armature_add(wmOperatorType *ot)
797 {       
798         /* identifiers */
799         ot->name= "Add Armature";
800         ot->description = "Add an armature object to the scene";
801         ot->idname= "OBJECT_OT_armature_add";
802         
803         /* api callbacks */
804         ot->invoke= ED_object_add_generic_invoke;
805         ot->exec= object_armature_add_exec;
806         ot->poll= ED_operator_scene_editable;
807         
808         /* flags */
809         ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
810         ED_object_add_generic_props(ot, TRUE);
811 }
812
813 static int object_lamp_add_exec(bContext *C, wmOperator *op)
814 {
815         Object *ob;
816         int type= RNA_enum_get(op->ptr, "type");
817         int enter_editmode;
818         unsigned int layer;
819         float loc[3], rot[3];
820         
821         object_add_generic_invoke_options(C, op);
822         ED_object_add_generic_get_opts(op, loc, rot, &enter_editmode, &layer);
823
824         ob= ED_object_add_type(C, OB_LAMP, loc, rot, FALSE, layer);
825         if(ob && ob->data)
826                 ((Lamp*)ob->data)->type= type;
827         
828         return OPERATOR_FINISHED;
829 }
830
831 void OBJECT_OT_lamp_add(wmOperatorType *ot)
832 {       
833         static EnumPropertyItem lamp_type_items[] = {
834                 {LA_LOCAL, "POINT", ICON_LAMP_POINT, "Point", "Omnidirectional point light source"},
835                 {LA_SUN, "SUN", ICON_LAMP_SUN, "Sun", "Constant direction parallel ray light source"},
836                 {LA_SPOT, "SPOT", ICON_LAMP_SPOT, "Spot", "Directional cone light source"},
837                 {LA_HEMI, "HEMI", ICON_LAMP_HEMI, "Hemi", "180 degree constant light source"},
838                 {LA_AREA, "AREA", ICON_LAMP_AREA, "Area", "Directional area light source"},
839                 {0, NULL, 0, NULL, NULL}};
840
841         /* identifiers */
842         ot->name= "Add Lamp";
843         ot->description = "Add a lamp object to the scene";
844         ot->idname= "OBJECT_OT_lamp_add";
845         
846         /* api callbacks */
847         ot->invoke= WM_menu_invoke;
848         ot->exec= object_lamp_add_exec;
849         ot->poll= ED_operator_scene_editable;
850         
851         /* flags */
852         ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
853
854         /* properties */
855         ot->prop= RNA_def_enum(ot->srna, "type", lamp_type_items, 0, "Type", "");
856
857         ED_object_add_generic_props(ot, FALSE);
858 }
859
860 static int group_instance_add_exec(bContext *C, wmOperator *op)
861 {
862         Group *group= BLI_findlink(&CTX_data_main(C)->group, RNA_enum_get(op->ptr, "type"));
863
864         int enter_editmode;
865         unsigned int layer;
866         float loc[3], rot[3];
867         
868         object_add_generic_invoke_options(C, op);
869         ED_object_add_generic_get_opts(op, loc, rot, &enter_editmode, &layer);
870
871         if(group) {
872                 Object *ob= ED_object_add_type(C, OB_EMPTY, loc, rot, FALSE, layer);
873                 rename_id(&ob->id, group->id.name+2);
874                 ob->dup_group= group;
875                 ob->transflag |= OB_DUPLIGROUP;
876                 id_us_plus(&group->id);
877
878
879                 WM_event_add_notifier(C, NC_OBJECT|ND_DRAW, ob);
880
881                 return OPERATOR_FINISHED;
882         }
883
884         return OPERATOR_CANCELLED;
885 }
886
887 /* only used as menu */
888 void OBJECT_OT_group_instance_add(wmOperatorType *ot)
889 {
890         PropertyRNA *prop;
891
892         /* identifiers */
893         ot->name= "Add Group Instance";
894         ot->description = "Add a dupligroup instance";
895         ot->idname= "OBJECT_OT_group_instance_add";
896
897         /* api callbacks */
898         ot->invoke= WM_enum_search_invoke;
899         ot->exec= group_instance_add_exec;
900
901         ot->poll= ED_operator_scene_editable;
902
903         /* flags */
904         ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
905
906         /* properties */
907         prop= RNA_def_enum(ot->srna, "type", DummyRNA_NULL_items, 0, "Type", "");
908         RNA_def_enum_funcs(prop, RNA_group_itemf);
909         ot->prop= prop;
910         ED_object_add_generic_props(ot, FALSE);
911 }
912
913 /**************************** Delete Object *************************/
914
915 /* remove base from a specific scene */
916 /* note: now unlinks constraints as well */
917 void ED_base_object_free_and_unlink(Scene *scene, Base *base)
918 {
919         BLI_remlink(&scene->base, base);
920         free_libblock_us(&G.main->object, base->object);
921         if(scene->basact==base) scene->basact= NULL;
922         MEM_freeN(base);
923 }
924
925 static int object_delete_exec(bContext *C, wmOperator *op)
926 {
927         Scene *scene= CTX_data_scene(C);
928         int islamp= 0;
929         
930         if(CTX_data_edit_object(C)) 
931                 return OPERATOR_CANCELLED;
932         
933         CTX_DATA_BEGIN(C, Base*, base, selected_bases) {
934
935                 if(base->object->type==OB_LAMP) islamp= 1;
936                 
937                 /* remove from current scene only */
938                 ED_base_object_free_and_unlink(scene, base);
939         }
940         CTX_DATA_END;
941
942         if(islamp) reshadeall_displist(scene);  /* only frees displist */
943         
944         DAG_scene_sort(scene);
945         DAG_ids_flush_update(0);
946         
947         WM_event_add_notifier(C, NC_SCENE|ND_OB_ACTIVE, CTX_data_scene(C));
948         
949         return OPERATOR_FINISHED;
950 }
951
952 void OBJECT_OT_delete(wmOperatorType *ot)
953 {
954         /* identifiers */
955         ot->name= "Delete";
956         ot->description = "Delete selected objects";
957         ot->idname= "OBJECT_OT_delete";
958         
959         /* api callbacks */
960         ot->invoke= WM_operator_confirm;
961         ot->exec= object_delete_exec;
962         ot->poll= ED_operator_scene_editable;
963         
964         /* flags */
965         ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
966 }
967
968 /**************************** Copy Utilities ******************************/
969
970 static void copy_object__forwardModifierLinks(void *userData, Object *ob,
971                                               ID **idpoin)
972 {
973         /* this is copied from ID_NEW; it might be better to have a macro */
974         if(*idpoin && (*idpoin)->newid) *idpoin = (*idpoin)->newid;
975 }
976
977 /* after copying objects, copied data should get new pointers */
978 static void copy_object_set_idnew(bContext *C, int dupflag)
979 {
980         Material *ma, *mao;
981         ID *id;
982 #if 0 // XXX old animation system
983         Ipo *ipo;
984         bActionStrip *strip;
985 #endif // XXX old animation system
986         int a;
987         
988         /* XXX check object pointers */
989         CTX_DATA_BEGIN(C, Object*, ob, selected_editable_objects) {
990                 relink_constraints(&ob->constraints);
991                 if (ob->pose){
992                         bPoseChannel *chan;
993                         for (chan = ob->pose->chanbase.first; chan; chan=chan->next){
994                                 relink_constraints(&chan->constraints);
995                         }
996                 }
997                 modifiers_foreachIDLink(ob, copy_object__forwardModifierLinks, NULL);
998                 ID_NEW(ob->parent);
999                 ID_NEW(ob->track);
1000                 ID_NEW(ob->proxy);
1001                 ID_NEW(ob->proxy_group);
1002                 
1003 #if 0 // XXX old animation system
1004                 for(strip= ob->nlastrips.first; strip; strip= strip->next) {
1005                         bActionModifier *amod;
1006                         for(amod= strip->modifiers.first; amod; amod= amod->next)
1007                                 ID_NEW(amod->ob);
1008                 }
1009 #endif // XXX old animation system
1010         }
1011         CTX_DATA_END;
1012         
1013         /* materials */
1014         if( dupflag & USER_DUP_MAT) {
1015                 mao= G.main->mat.first;
1016                 while(mao) {
1017                         if(mao->id.newid) {
1018                                 
1019                                 ma= (Material *)mao->id.newid;
1020                                 
1021                                 if(dupflag & USER_DUP_TEX) {
1022                                         for(a=0; a<MAX_MTEX; a++) {
1023                                                 if(ma->mtex[a]) {
1024                                                         id= (ID *)ma->mtex[a]->tex;
1025                                                         if(id) {
1026                                                                 ID_NEW_US(ma->mtex[a]->tex)
1027                                                                 else ma->mtex[a]->tex= copy_texture(ma->mtex[a]->tex);
1028                                                                 id->us--;
1029                                                         }
1030                                                 }
1031                                         }
1032                                 }
1033 #if 0 // XXX old animation system
1034                                 id= (ID *)ma->ipo;
1035                                 if(id) {
1036                                         ID_NEW_US(ma->ipo)
1037                                         else ma->ipo= copy_ipo(ma->ipo);
1038                                         id->us--;
1039                                 }
1040 #endif // XXX old animation system
1041                         }
1042                         mao= mao->id.next;
1043                 }
1044         }
1045         
1046 #if 0 // XXX old animation system
1047         /* lamps */
1048         if( dupflag & USER_DUP_IPO) {
1049                 Lamp *la= G.main->lamp.first;
1050                 while(la) {
1051                         if(la->id.newid) {
1052                                 Lamp *lan= (Lamp *)la->id.newid;
1053                                 id= (ID *)lan->ipo;
1054                                 if(id) {
1055                                         ID_NEW_US(lan->ipo)
1056                                         else lan->ipo= copy_ipo(lan->ipo);
1057                                         id->us--;
1058                                 }
1059                         }
1060                         la= la->id.next;
1061                 }
1062         }
1063         
1064         /* ipos */
1065         ipo= G.main->ipo.first;
1066         while(ipo) {
1067                 if(ipo->id.lib==NULL && ipo->id.newid) {
1068                         Ipo *ipon= (Ipo *)ipo->id.newid;
1069                         IpoCurve *icu;
1070                         for(icu= ipon->curve.first; icu; icu= icu->next) {
1071                                 if(icu->driver) {
1072                                         ID_NEW(icu->driver->ob);
1073                                 }
1074                         }
1075                 }
1076                 ipo= ipo->id.next;
1077         }
1078 #endif // XXX old animation system
1079         
1080         set_sca_new_poins();
1081         
1082         clear_id_newpoins();
1083 }
1084
1085 /********************* Make Duplicates Real ************************/
1086
1087 static void make_object_duplilist_real(bContext *C, Scene *scene, Base *base)
1088 {
1089         Base *basen;
1090         Object *ob;
1091         ListBase *lb;
1092         DupliObject *dob;
1093         
1094         if(!base && !(base = BASACT))
1095                 return;
1096         
1097         if(!(base->object->transflag & OB_DUPLI))
1098                 return;
1099         
1100         lb= object_duplilist(scene, base->object);
1101         
1102         for(dob= lb->first; dob; dob= dob->next) {
1103                 ob= copy_object(dob->ob);
1104                 /* font duplis can have a totcol without material, we get them from parent
1105                 * should be implemented better...
1106                 */
1107                 if(ob->mat==NULL) ob->totcol= 0;
1108                 
1109                 basen= MEM_dupallocN(base);
1110                 basen->flag &= ~OB_FROMDUPLI;
1111                 basen->lay= base->lay;
1112                 BLI_addhead(&scene->base, basen);       /* addhead: othwise eternal loop */
1113                 basen->object= ob;
1114                 ob->ipo= NULL;          /* make sure apply works */
1115                 ob->parent= ob->track= NULL;
1116                 ob->disp.first= ob->disp.last= NULL;
1117                 ob->transflag &= ~OB_DUPLI;     
1118                 ob->lay= base->lay;
1119                 
1120                 copy_m4_m4(ob->obmat, dob->mat);
1121                 ED_object_apply_obmat(ob);
1122         }
1123         
1124         copy_object_set_idnew(C, 0);
1125         
1126         free_object_duplilist(lb);
1127         
1128         base->object->transflag &= ~OB_DUPLI;   
1129 }
1130
1131 static int object_duplicates_make_real_exec(bContext *C, wmOperator *op)
1132 {
1133         Scene *scene= CTX_data_scene(C);
1134         
1135         clear_id_newpoins();
1136                 
1137         CTX_DATA_BEGIN(C, Base*, base, selected_editable_bases) {
1138                 make_object_duplilist_real(C, scene, base);
1139         }
1140         CTX_DATA_END;
1141
1142         DAG_scene_sort(scene);
1143         DAG_ids_flush_update(0);
1144         WM_event_add_notifier(C, NC_SCENE, scene);
1145         
1146         return OPERATOR_FINISHED;
1147 }
1148
1149 void OBJECT_OT_duplicates_make_real(wmOperatorType *ot)
1150 {
1151         
1152         /* identifiers */
1153         ot->name= "Make Duplicates Real";
1154         ot->description = "Make dupli objects attached to this object real";
1155         ot->idname= "OBJECT_OT_duplicates_make_real";
1156         
1157         /* api callbacks */
1158         ot->exec= object_duplicates_make_real_exec;
1159         
1160         ot->poll= ED_operator_scene_editable;
1161         
1162         /* flags */
1163         ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
1164 }
1165
1166 /**************************** Convert **************************/
1167
1168 static EnumPropertyItem convert_target_items[]= {
1169         {OB_CURVE, "CURVE", ICON_OUTLINER_OB_CURVE, "Curve from Mesh/Text", ""},
1170         {OB_MESH, "MESH", ICON_OUTLINER_OB_MESH, "Mesh from Curve/Meta/Surf/Mesh", ""},
1171         {0, NULL, 0, NULL, NULL}};
1172
1173 static void curvetomesh(Scene *scene, Object *ob) 
1174 {
1175         Curve *cu= ob->data;
1176         
1177         if(cu->disp.first==0)
1178                 makeDispListCurveTypes(scene, ob, 0); /* force creation */
1179
1180         nurbs_to_mesh(ob); /* also does users */
1181
1182         if(ob->type == OB_MESH)
1183                 object_free_modifiers(ob);
1184 }
1185
1186 static int convert_poll(bContext *C)
1187 {
1188         Object *obact= CTX_data_active_object(C);
1189         Scene *scene= CTX_data_scene(C);
1190
1191         return (!scene->id.lib && obact && scene->obedit != obact && (obact->flag & SELECT) && !(obact->id.lib));
1192 }
1193
1194 /* Helper for convert_exec */
1195 static Base *duplibase_for_convert(Scene *scene, Base *base, Object *ob)
1196 {
1197         Object *obn;
1198         Base *basen;
1199
1200         if (ob == NULL) {
1201                 ob= base->object;
1202         }
1203
1204         obn= copy_object(ob);
1205         obn->recalc |= OB_RECALC;
1206
1207         basen= MEM_mallocN(sizeof(Base), "duplibase");
1208         *basen= *base;
1209         BLI_addhead(&scene->base, basen);       /* addhead: otherwise eternal loop */
1210         basen->object= obn;
1211         basen->flag |= SELECT;
1212         obn->flag |= SELECT;
1213         base->flag &= ~SELECT;
1214         ob->flag &= ~SELECT;
1215
1216         return basen;
1217 }
1218
1219 static int convert_exec(bContext *C, wmOperator *op)
1220 {
1221         Scene *scene= CTX_data_scene(C);
1222         Base *basen=NULL, *basact=NULL, *basedel=NULL;
1223         Object *ob, *ob1, *newob, *obact= CTX_data_active_object(C);
1224         DerivedMesh *dm;
1225         Curve *cu;
1226         Nurb *nu;
1227         MetaBall *mb;
1228         Mesh *me;
1229         int target= RNA_enum_get(op->ptr, "target");
1230         int keep_original= RNA_boolean_get(op->ptr, "keep_original");
1231         int a, mballConverted= 0;
1232
1233         /* don't forget multiple users! */
1234
1235         /* reset flags */
1236         CTX_DATA_BEGIN(C, Base*, base, selected_editable_bases) {
1237                 ob= base->object;
1238                 ob->flag &= ~OB_DONE;
1239         }
1240         CTX_DATA_END;
1241
1242         CTX_DATA_BEGIN(C, Base*, base, selected_editable_bases) {
1243                 ob= base->object;
1244
1245                 if(ob->flag & OB_DONE) {
1246                         if (ob->type != target) {
1247                                 base->flag &= ~SELECT;
1248                                 ob->flag &= ~SELECT;
1249                         }
1250                 }
1251                 else if (ob->type==OB_MESH && target == OB_CURVE) {
1252                         ob->flag |= OB_DONE;
1253
1254                         if (keep_original) {
1255                                 basen= duplibase_for_convert(scene, base, NULL);
1256                                 newob= basen->object;
1257
1258                                 /* decrement original mesh's usage count  */
1259                                 me= newob->data;
1260                                 me->id.us--;
1261
1262                                 /* make a new copy of the mesh */
1263                                 newob->data= copy_mesh(me);
1264                         } else {
1265                                 newob = ob;
1266                         }
1267
1268                         mesh_to_curve(scene, newob);
1269
1270                         if(newob->type==OB_CURVE)
1271                                 object_free_modifiers(newob);   /* after derivedmesh calls! */
1272                 }
1273                 else if(ob->type==OB_MESH && ob->modifiers.first) { /* converting a mesh with no modifiers causes a segfault */
1274                         ob->flag |= OB_DONE;
1275
1276                         if (keep_original) {
1277                                 basen= duplibase_for_convert(scene, base, NULL);
1278                                 newob= basen->object;
1279
1280                                 /* decrement original mesh's usage count  */
1281                                 me= newob->data;
1282                                 me->id.us--;
1283
1284                                 /* make a new copy of the mesh */
1285                                 newob->data= copy_mesh(me);
1286                         } else {
1287                                 newob = ob;
1288                                 ob->recalc |= OB_RECALC;
1289                         }
1290
1291                         /* make new mesh data from the original copy */
1292                         /* note: get the mesh from the original, not from the copy in some
1293                          * cases this doesnt give correct results (when MDEF is used for eg)
1294                          */
1295                         dm= mesh_get_derived_final(scene, newob, CD_MASK_MESH);
1296                         /* dm= mesh_create_derived_no_deform(ob1, NULL);        this was called original (instead of get_derived). man o man why! (ton) */
1297
1298                         DM_to_mesh(dm, newob->data);
1299
1300                         dm->release(dm);
1301                         object_free_modifiers(newob);   /* after derivedmesh calls! */
1302                 }
1303                 else if(ob->type==OB_FONT) {
1304                         ob->flag |= OB_DONE;
1305
1306                         if (keep_original) {
1307                                 basen= duplibase_for_convert(scene, base, NULL);
1308                                 newob= basen->object;
1309
1310                                 /* decrement original curve's usage count  */
1311                                 ((Curve *)newob->data)->id.us--;
1312
1313                                 /* make a new copy of the curve */
1314                                 newob->data= copy_curve(ob->data);
1315                         } else {
1316                                 newob= ob;
1317                         }
1318
1319                         cu= newob->data;
1320
1321                         if (!cu->disp.first)
1322                                 makeDispListCurveTypes(scene, newob, 0);
1323
1324                         newob->type= OB_CURVE;
1325
1326                         if(cu->vfont) {
1327                                 cu->vfont->id.us--;
1328                                 cu->vfont= 0;
1329                         }
1330                         if(cu->vfontb) {
1331                                 cu->vfontb->id.us--;
1332                                 cu->vfontb= 0;
1333                         }
1334                         if(cu->vfonti) {
1335                                 cu->vfonti->id.us--;
1336                                 cu->vfonti= 0;
1337                         }
1338                         if(cu->vfontbi) {
1339                                 cu->vfontbi->id.us--;
1340                                 cu->vfontbi= 0;
1341                         }
1342
1343                         if (!keep_original) {
1344                                 /* other users */
1345                                 if(cu->id.us>1) {
1346                                         for(ob1= G.main->object.first; ob1; ob1=ob1->id.next) {
1347                                                 if(ob1->data==ob->data) {
1348                                                         ob1->type= OB_CURVE;
1349                                                         ob1->recalc |= OB_RECALC;
1350                                                 }
1351                                         }
1352                                 }
1353                         }
1354
1355                         for(nu=cu->nurb.first; nu; nu=nu->next)
1356                                 nu->charidx= 0;
1357
1358                         if(target == OB_MESH)
1359                                 curvetomesh(scene, newob);
1360                 }
1361                 else if(ELEM(ob->type, OB_CURVE, OB_SURF)) {
1362                         ob->flag |= OB_DONE;
1363
1364                         if(target == OB_MESH) {
1365                                 if (keep_original) {
1366                                         basen= duplibase_for_convert(scene, base, NULL);
1367                                         newob= basen->object;
1368
1369                                         /* decrement original curve's usage count  */
1370                                         ((Curve *)newob->data)->id.us--;
1371
1372                                         /* make a new copy of the curve */
1373                                         newob->data= copy_curve(ob->data);
1374                                 } else {
1375                                         newob= ob;
1376                                 }
1377
1378                                 curvetomesh(scene, newob);
1379                         }
1380                 }
1381                 else if(ob->type==OB_MBALL) {
1382                         Object *baseob;
1383
1384                         if (target != OB_MESH) {
1385                                 ob->flag |= OB_DONE;
1386                                 continue;
1387                         }
1388
1389                         base->flag &= ~SELECT;
1390                         ob->flag &= ~SELECT;
1391
1392                         baseob= find_basis_mball(scene, ob);
1393
1394                         if (ob != baseob) {
1395                                 /* if motherball is converting it would be marked as done later */
1396                                 ob->flag |= OB_DONE;
1397                         }
1398
1399                         if (!baseob->disp.first) {
1400                                 makeDispListMBall(scene, baseob);
1401                         }
1402
1403                         if(!(baseob->flag & OB_DONE)) {
1404                                 baseob->flag |= OB_DONE;
1405
1406                                 basen= duplibase_for_convert(scene, base, baseob);
1407                                 newob= basen->object;
1408
1409                                 mb= newob->data;
1410                                 mb->id.us--;
1411
1412                                 newob->data= add_mesh("Mesh");
1413                                 newob->type= OB_MESH;
1414
1415                                 me= newob->data;
1416                                 me->totcol= mb->totcol;
1417                                 if(newob->totcol) {
1418                                         me->mat= MEM_dupallocN(mb->mat);
1419                                         for(a=0; a<newob->totcol; a++) id_us_plus((ID *)me->mat[a]);
1420                                 }
1421
1422                                 mball_to_mesh(&baseob->disp, newob->data);
1423
1424                                 if (obact->type == OB_MBALL) {
1425                                         basact= basen;
1426                                 }
1427
1428                                 mballConverted= 1;
1429                         }
1430                         else
1431                                 continue;
1432                 }
1433                 else
1434                         continue;
1435
1436                 /* If the original object is active then make this object active */
1437                 if(basen) {
1438                         if(ob == obact) {
1439                                 /* store new active base to update BASACT */
1440                                 basact= basen;
1441                         }
1442
1443                         basen= NULL;
1444                 }
1445
1446                 /* delete original if needed */
1447                 if(basedel) {
1448                         if(!keep_original)
1449                                 ED_base_object_free_and_unlink(scene, basedel); 
1450
1451                         basedel = NULL;
1452                 }
1453         }
1454         CTX_DATA_END;
1455
1456         if(!keep_original) {
1457                 if (mballConverted) {
1458                         Base *base= scene->base.first, *tmpbase;
1459                         while (base) {
1460                                 ob= base->object;
1461                                 tmpbase= base;
1462                                 base= base->next;
1463
1464                                 if (ob->type == OB_MBALL) {
1465                                         ED_base_object_free_and_unlink(scene, tmpbase);
1466                                 }
1467                         }
1468                 }
1469
1470                 /* delete object should renew depsgraph */
1471                 DAG_scene_sort(scene);
1472         }
1473
1474 // XXX  ED_object_enter_editmode(C, 0);
1475 // XXX  exit_editmode(C, EM_FREEDATA|EM_WAITCURSOR); /* freedata, but no undo */
1476
1477         if (basact) {
1478                 /* active base was changed */
1479                 ED_base_object_activate(C, basact);
1480                 BASACT= basact;
1481         } else if (BASACT->object->flag & OB_DONE) {
1482                 WM_event_add_notifier(C, NC_OBJECT|ND_MODIFIER|ND_DATA, BASACT->object);
1483         }
1484
1485         DAG_scene_sort(scene);
1486         WM_event_add_notifier(C, NC_SCENE|NC_OBJECT|ND_DRAW, scene); /* is NC_SCENE needed ? */
1487
1488         return OPERATOR_FINISHED;
1489 }
1490
1491
1492 void OBJECT_OT_convert(wmOperatorType *ot)
1493 {
1494         /* identifiers */
1495         ot->name= "Convert";
1496         ot->description = "Convert selected objects to another type";
1497         ot->idname= "OBJECT_OT_convert";
1498         
1499         /* api callbacks */
1500         ot->invoke= WM_menu_invoke;
1501         ot->exec= convert_exec;
1502         ot->poll= convert_poll;
1503         
1504         /* flags */
1505         ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
1506
1507         /* properties */
1508         ot->prop= RNA_def_enum(ot->srna, "target", convert_target_items, OB_MESH, "Target", "Type of object to convert to.");
1509         RNA_def_boolean(ot->srna, "keep_original", 0, "Keep Original", "Keep original objects instead of replacing them.");
1510 }
1511
1512 /**************************** Duplicate ************************/
1513
1514 /* 
1515         dupflag: a flag made from constants declared in DNA_userdef_types.h
1516         The flag tells adduplicate() weather to copy data linked to the object, or to reference the existing data.
1517         U.dupflag for default operations or you can construct a flag as python does
1518         if the dupflag is 0 then no data will be copied (linked duplicate) */
1519
1520 /* used below, assumes id.new is correct */
1521 /* leaves selection of base/object unaltered */
1522 static Base *object_add_duplicate_internal(Scene *scene, Base *base, int dupflag)
1523 {
1524         Base *basen= NULL;
1525         Material ***matarar;
1526         Object *ob, *obn;
1527         ID *id;
1528         int a, didit;
1529
1530         ob= base->object;
1531         if(ob->mode & OB_MODE_POSE) {
1532                 ; /* nothing? */
1533         }
1534         else {
1535                 obn= copy_object(ob);
1536                 obn->recalc |= OB_RECALC;
1537                 
1538                 basen= MEM_mallocN(sizeof(Base), "duplibase");
1539                 *basen= *base;
1540                 BLI_addhead(&scene->base, basen);       /* addhead: prevent eternal loop */
1541                 basen->object= obn;
1542                 
1543                 if(basen->flag & OB_FROMGROUP) {
1544                         Group *group;
1545                         for(group= G.main->group.first; group; group= group->id.next) {
1546                                 if(object_in_group(ob, group))
1547                                         add_to_group(group, obn, scene, basen);
1548                         }
1549                 }
1550                 
1551                 /* duplicates using userflags */
1552 #if 0 // XXX old animation system                               
1553                 if(dupflag & USER_DUP_IPO) {
1554                         bConstraintChannel *chan;
1555                         id= (ID *)obn->ipo;
1556                         
1557                         if(id) {
1558                                 ID_NEW_US( obn->ipo)
1559                                 else obn->ipo= copy_ipo(obn->ipo);
1560                                 id->us--;
1561                         }
1562                         /* Handle constraint ipos */
1563                         for (chan=obn->constraintChannels.first; chan; chan=chan->next){
1564                                 id= (ID *)chan->ipo;
1565                                 if(id) {
1566                                         ID_NEW_US( chan->ipo)
1567                                         else chan->ipo= copy_ipo(chan->ipo);
1568                                         id->us--;
1569                                 }
1570                         }
1571                 }
1572                 if(dupflag & USER_DUP_ACT){ /* Not buttons in the UI to modify this, add later? */
1573                         id= (ID *)obn->action;
1574                         if (id){
1575                                 ID_NEW_US(obn->action)
1576                                 else{
1577                                         obn->action= copy_action(obn->action);
1578                                 }
1579                                 id->us--;
1580                         }
1581                 }
1582 #endif // XXX old animation system
1583                 if(dupflag & USER_DUP_MAT) {
1584                         for(a=0; a<obn->totcol; a++) {
1585                                 id= (ID *)obn->mat[a];
1586                                 if(id) {
1587                                         ID_NEW_US(obn->mat[a])
1588                                         else obn->mat[a]= copy_material(obn->mat[a]);
1589                                         id->us--;
1590                                 }
1591                         }
1592                 }
1593                 if(dupflag & USER_DUP_PSYS) {
1594                         ParticleSystem *psys;
1595                         for(psys=obn->particlesystem.first; psys; psys=psys->next) {
1596                                 id= (ID*) psys->part;
1597                                 if(id) {
1598                                         ID_NEW_US(psys->part)
1599                                         else psys->part= psys_copy_settings(psys->part);
1600                                         id->us--;
1601                                 }
1602                         }
1603                 }
1604                 
1605                 id= obn->data;
1606                 didit= 0;
1607                 
1608                 switch(obn->type) {
1609                         case OB_MESH:
1610                                 if(dupflag & USER_DUP_MESH) {
1611                                         ID_NEW_US2( obn->data )
1612                                         else {
1613                                                 obn->data= copy_mesh(obn->data);
1614                                                 
1615                                                 if(obn->fluidsimSettings) {
1616                                                         obn->fluidsimSettings->orgMesh = (Mesh *)obn->data;
1617                                                 }
1618                                                 
1619                                                 didit= 1;
1620                                         }
1621                                         id->us--;
1622                                 }
1623                                 break;
1624                         case OB_CURVE:
1625                                 if(dupflag & USER_DUP_CURVE) {
1626                                         ID_NEW_US2(obn->data )
1627                                         else {
1628                                                 obn->data= copy_curve(obn->data);
1629                                                 didit= 1;
1630                                         }
1631                                         id->us--;
1632                                 }
1633                                 break;
1634                         case OB_SURF:
1635                                 if(dupflag & USER_DUP_SURF) {
1636                                         ID_NEW_US2( obn->data )
1637                                         else {
1638                                                 obn->data= copy_curve(obn->data);
1639                                                 didit= 1;
1640                                         }
1641                                         id->us--;
1642                                 }
1643                                 break;
1644                         case OB_FONT:
1645                                 if(dupflag & USER_DUP_FONT) {
1646                                         ID_NEW_US2( obn->data )
1647                                         else {
1648                                                 obn->data= copy_curve(obn->data);
1649                                                 didit= 1;
1650                                         }
1651                                         id->us--;
1652                                 }
1653                                 break;
1654                         case OB_MBALL:
1655                                 if(dupflag & USER_DUP_MBALL) {
1656                                         ID_NEW_US2(obn->data )
1657                                         else {
1658                                                 obn->data= copy_mball(obn->data);
1659                                                 didit= 1;
1660                                         }
1661                                         id->us--;
1662                                 }
1663                                 break;
1664                         case OB_LAMP:
1665                                 if(dupflag & USER_DUP_LAMP) {
1666                                         ID_NEW_US2(obn->data )
1667                                         else obn->data= copy_lamp(obn->data);
1668                                         id->us--;
1669                                 }
1670                                 break;
1671                                 
1672                         case OB_ARMATURE:
1673                                 obn->recalc |= OB_RECALC_DATA;
1674                                 if(obn->pose) obn->pose->flag |= POSE_RECALC;
1675                                         
1676                                         if(dupflag & USER_DUP_ARM) {
1677                                                 ID_NEW_US2(obn->data )
1678                                                 else {
1679                                                         obn->data= copy_armature(obn->data);
1680                                                         armature_rebuild_pose(obn, obn->data);
1681                                                         didit= 1;
1682                                                 }
1683                                                 id->us--;
1684                                         }
1685                                                 
1686                                                 break;
1687                                 
1688                         case OB_LATTICE:
1689                                 if(dupflag!=0) {
1690                                         ID_NEW_US2(obn->data )
1691                                         else obn->data= copy_lattice(obn->data);
1692                                         id->us--;
1693                                 }
1694                                 break;
1695                         case OB_CAMERA:
1696                                 if(dupflag!=0) {
1697                                         ID_NEW_US2(obn->data )
1698                                         else obn->data= copy_camera(obn->data);
1699                                         id->us--;
1700                                 }
1701                                 break;
1702                 }
1703                 
1704                 if(dupflag & USER_DUP_MAT) {
1705                         matarar= give_matarar(obn);
1706                         if(didit && matarar) {
1707                                 for(a=0; a<obn->totcol; a++) {
1708                                         id= (ID *)(*matarar)[a];
1709                                         if(id) {
1710                                                 ID_NEW_US( (*matarar)[a] )
1711                                                 else (*matarar)[a]= copy_material((*matarar)[a]);
1712                                                 
1713                                                 id->us--;
1714                                         }
1715                                 }
1716                         }
1717                 }
1718         }
1719         return basen;
1720 }
1721
1722 /* single object duplicate, if dupflag==0, fully linked, else it uses the flags given */
1723 /* leaves selection of base/object unaltered */
1724 Base *ED_object_add_duplicate(Scene *scene, Base *base, int dupflag)
1725 {
1726         Base *basen;
1727         Object *ob;
1728
1729         clear_id_newpoins();
1730         clear_sca_new_poins();  /* sensor/contr/act */
1731         
1732         basen= object_add_duplicate_internal(scene, base, dupflag);
1733         ob= basen->object;
1734         
1735         DAG_scene_sort(scene);
1736         ED_render_id_flush_update(G.main, ob->data);
1737         
1738         return basen;
1739 }
1740
1741 /* contextual operator dupli */
1742 static int duplicate_exec(bContext *C, wmOperator *op)
1743 {
1744         Scene *scene= CTX_data_scene(C);
1745         int linked= RNA_boolean_get(op->ptr, "linked");
1746         int dupflag= (linked)? 0: U.dupflag;
1747         
1748         clear_id_newpoins();
1749         clear_sca_new_poins();  /* sensor/contr/act */
1750         
1751         CTX_DATA_BEGIN(C, Base*, base, selected_editable_bases) {
1752                 Base *basen= object_add_duplicate_internal(scene, base, dupflag);
1753                 
1754                 /* note that this is safe to do with this context iterator,
1755                    the list is made in advance */
1756                 ED_base_object_select(base, BA_DESELECT);
1757
1758                 /* new object becomes active */
1759                 if(BASACT==base)
1760                         ED_base_object_activate(C, basen);
1761                 
1762                 ED_render_id_flush_update(G.main, basen->object->data);
1763         }
1764         CTX_DATA_END;
1765
1766         copy_object_set_idnew(C, dupflag);
1767
1768         DAG_scene_sort(scene);
1769         DAG_ids_flush_update(0);
1770
1771         WM_event_add_notifier(C, NC_SCENE|ND_OB_SELECT, scene);
1772
1773         return OPERATOR_FINISHED;
1774 }
1775
1776 void OBJECT_OT_duplicate(wmOperatorType *ot)
1777 {
1778         /* identifiers */
1779         ot->name= "Duplicate";
1780         ot->description = "Duplicate selected objects";
1781         ot->idname= "OBJECT_OT_duplicate";
1782         
1783         /* api callbacks */
1784         ot->exec= duplicate_exec;
1785         ot->poll= ED_operator_scene_editable;
1786         
1787         /* flags */
1788         ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
1789         
1790         /* to give to transform */
1791         RNA_def_boolean(ot->srna, "linked", 0, "Linked", "Duplicate object but not object data, linking to the original data.");
1792         RNA_def_int(ot->srna, "mode", TFM_TRANSLATION, 0, INT_MAX, "Mode", "", 0, INT_MAX);
1793 }
1794
1795 /* **************** add named object, for dragdrop ************* */
1796
1797 /* contextual operator dupli */
1798
1799 static int add_named_poll(bContext *C)
1800 {
1801         if(!ED_operator_scene_editable(C)) {
1802                 return 0;
1803         } else {
1804                 Object *ob= CTX_data_active_object(C);
1805                 if(ob && ob->mode != OB_MODE_OBJECT)
1806                         return 0;
1807                 else
1808                         return 1;
1809         }
1810 }
1811
1812 static int add_named_exec(bContext *C, wmOperator *op)
1813 {
1814         Scene *scene= CTX_data_scene(C);
1815         Base *basen, *base;
1816         Object *ob;
1817         int linked= RNA_boolean_get(op->ptr, "linked");
1818         int dupflag= (linked)? 0: U.dupflag;
1819         char name[32];
1820         
1821         /* find object, create fake base */
1822         RNA_string_get(op->ptr, "name", name);
1823         ob= (Object *)find_id("OB", name);
1824         if(ob==NULL) 
1825                 return OPERATOR_CANCELLED;
1826         
1827         base= MEM_callocN(sizeof(Base), "duplibase");
1828         base->object= ob;
1829         base->flag= ob->flag;
1830         
1831         /* prepare dupli */
1832         clear_id_newpoins();
1833         clear_sca_new_poins();  /* sensor/contr/act */
1834         
1835         basen= object_add_duplicate_internal(scene, base, dupflag);
1836         basen->lay= basen->object->lay= scene->lay;
1837         
1838         ED_object_location_from_view(C, basen->object->loc);
1839         ED_base_object_activate(C, basen);
1840         
1841         copy_object_set_idnew(C, dupflag);
1842         
1843         DAG_scene_sort(scene);
1844         DAG_ids_flush_update(0);
1845         
1846         MEM_freeN(base);
1847         
1848         WM_event_add_notifier(C, NC_SCENE|ND_OB_SELECT, scene);
1849         
1850         return OPERATOR_FINISHED;
1851 }
1852
1853 void OBJECT_OT_add_named(wmOperatorType *ot)
1854 {
1855         /* identifiers */
1856         ot->name= "Add Named Object";
1857         ot->description = "Add named object";
1858         ot->idname= "OBJECT_OT_add_named";
1859         
1860         /* api callbacks */
1861         ot->exec= add_named_exec;
1862         ot->poll= add_named_poll;
1863         
1864         /* flags */
1865         ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
1866         
1867         RNA_def_boolean(ot->srna, "linked", 0, "Linked", "Duplicate object but not object data, linking to the original data.");
1868         RNA_def_string(ot->srna, "name", "Cube", 24, "Name", "Object name to add.");
1869 }
1870
1871
1872
1873 /**************************** Join *************************/
1874 static int join_poll(bContext *C)
1875 {
1876         Object *ob= CTX_data_active_object(C);
1877         
1878         if (!ob || ob->id.lib) return 0;
1879         
1880         if (ELEM4(ob->type, OB_MESH, OB_CURVE, OB_SURF, OB_ARMATURE))
1881                 return ED_operator_screenactive(C);
1882         else
1883                 return 0;
1884 }
1885
1886
1887 static int join_exec(bContext *C, wmOperator *op)
1888 {
1889         Scene *scene= CTX_data_scene(C);
1890         Object *ob= CTX_data_active_object(C);
1891
1892         if(scene->obedit) {
1893                 BKE_report(op->reports, RPT_ERROR, "This data does not support joining in editmode.");
1894                 return OPERATOR_CANCELLED;
1895         }
1896         else if(object_data_is_libdata(ob)) {
1897                 BKE_report(op->reports, RPT_ERROR, "Can't edit external libdata.");
1898                 return OPERATOR_CANCELLED;
1899         }
1900
1901         if(ob->type == OB_MESH)
1902                 return join_mesh_exec(C, op);
1903         else if(ELEM(ob->type, OB_CURVE, OB_SURF))
1904                 return join_curve_exec(C, op);
1905         else if(ob->type == OB_ARMATURE)
1906                 return join_armature_exec(C, op);
1907         
1908         return OPERATOR_CANCELLED;
1909 }
1910
1911 void OBJECT_OT_join(wmOperatorType *ot)
1912 {
1913         /* identifiers */
1914         ot->name= "Join";
1915         ot->description = "Join selected objects into active object";
1916         ot->idname= "OBJECT_OT_join";
1917         
1918         /* api callbacks */
1919         ot->exec= join_exec;
1920         ot->poll= join_poll;
1921         
1922         /* flags */
1923         ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
1924 }
1925
1926 /**************************** Join as Shape Key*************************/
1927 static int join_shapes_poll(bContext *C)
1928 {
1929         Object *ob= CTX_data_active_object(C);
1930         
1931         if (!ob || ob->id.lib) return 0;
1932         
1933         /* only meshes supported at the moment */
1934         if (ob->type == OB_MESH)
1935                 return ED_operator_screenactive(C);
1936         else
1937                 return 0;
1938 }
1939
1940 static int join_shapes_exec(bContext *C, wmOperator *op)
1941 {
1942         Scene *scene= CTX_data_scene(C);
1943         Object *ob= CTX_data_active_object(C);
1944         
1945         if(scene->obedit) {
1946                 BKE_report(op->reports, RPT_ERROR, "This data does not support joining in editmode.");
1947                 return OPERATOR_CANCELLED;
1948         }
1949         else if(object_data_is_libdata(ob)) {
1950                 BKE_report(op->reports, RPT_ERROR, "Can't edit external libdata.");
1951                 return OPERATOR_CANCELLED;
1952         }
1953         
1954         if(ob->type == OB_MESH)
1955                 return join_mesh_shapes_exec(C, op);
1956         
1957         return OPERATOR_CANCELLED;
1958 }
1959
1960 void OBJECT_OT_join_shapes(wmOperatorType *ot)
1961 {
1962         /* identifiers */
1963         ot->name= "Join as Shapes";
1964         ot->description = "Merge selected objects to shapes of active object";
1965         ot->idname= "OBJECT_OT_join_shapes";
1966         
1967         /* api callbacks */
1968         ot->exec= join_shapes_exec;
1969         ot->poll= join_shapes_poll;
1970         
1971         /* flags */
1972         ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
1973 }