"Fill deformed" option for 2D curves
[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                 Curve *cu;
507                 obedit= ED_object_add_type(C, OB_CURVE, loc, rot, TRUE, layer);
508                 newob = 1;
509
510                 cu= (Curve*)obedit->data;
511                 cu->flag |= CU_DEFORM_FILL;
512                 if(type & CU_PRIM_PATH)
513                         cu->flag |= CU_PATH|CU_3D;
514         }
515         else DAG_id_flush_update(&obedit->id, OB_RECALC_DATA);
516         
517         ED_object_new_primitive_matrix(C, loc, rot, mat);
518         
519         nu= add_nurbs_primitive(C, mat, type, newob);
520         editnurb= curve_get_editcurve(obedit);
521         BLI_addtail(editnurb, nu);
522         
523         /* userdef */
524         if (newob && !enter_editmode) {
525                 ED_object_exit_editmode(C, EM_FREEDATA);
526         }
527         
528         WM_event_add_notifier(C, NC_OBJECT|ND_DRAW, obedit);
529         
530         return OPERATOR_FINISHED;
531 }
532
533 static int object_add_curve_invoke(bContext *C, wmOperator *op, wmEvent *event)
534 {
535         Object *obedit= CTX_data_edit_object(C);
536         uiPopupMenu *pup;
537         uiLayout *layout;
538
539         object_add_generic_invoke_options(C, op);
540
541         pup= uiPupMenuBegin(C, op->type->name, 0);
542         layout= uiPupMenuLayout(pup);
543         if(!obedit || obedit->type == OB_CURVE)
544                 uiItemsEnumO(layout, op->type->idname, "type");
545         else
546                 uiItemsEnumO(layout, "OBJECT_OT_surface_add", "type");
547         uiPupMenuEnd(C, pup);
548
549         return OPERATOR_CANCELLED;
550 }
551
552 void OBJECT_OT_curve_add(wmOperatorType *ot)
553 {
554         /* identifiers */
555         ot->name= "Add Curve";
556         ot->description = "Add a curve object to the scene";
557         ot->idname= "OBJECT_OT_curve_add";
558         
559         /* api callbacks */
560         ot->invoke= object_add_curve_invoke;
561         ot->exec= object_add_curve_exec;
562         
563         ot->poll= ED_operator_scene_editable;
564         
565         /* flags */
566         ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
567         
568         RNA_def_enum(ot->srna, "type", prop_curve_types, 0, "Primitive", "");
569
570         ED_object_add_generic_props(ot, TRUE);
571 }
572
573 static EnumPropertyItem prop_surface_types[]= {
574         {CU_PRIM_CURVE|CU_NURBS, "NURBS_CURVE", ICON_SURFACE_NCURVE, "NURBS Curve", ""},
575         {CU_PRIM_CIRCLE|CU_NURBS, "NURBS_CIRCLE", ICON_SURFACE_NCIRCLE, "NURBS Circle", ""},
576         {CU_PRIM_PATCH|CU_NURBS, "NURBS_SURFACE", ICON_SURFACE_NSURFACE, "NURBS Surface", ""},
577         {CU_PRIM_TUBE|CU_NURBS, "NURBS_TUBE", ICON_SURFACE_NTUBE, "NURBS Tube", ""},
578         {CU_PRIM_SPHERE|CU_NURBS, "NURBS_SPHERE", ICON_SURFACE_NSPHERE, "NURBS Sphere", ""},
579         {CU_PRIM_DONUT|CU_NURBS, "NURBS_DONUT", ICON_SURFACE_NDONUT, "NURBS Donut", ""},
580         {0, NULL, 0, NULL, NULL}
581 };
582
583 static int object_add_surface_exec(bContext *C, wmOperator *op)
584 {
585         Object *obedit= CTX_data_edit_object(C);
586         ListBase *editnurb;
587         Nurb *nu;
588         int newob= 0;
589         int enter_editmode;
590         unsigned int layer;
591         float loc[3], rot[3];
592         float mat[4][4];
593         
594         object_add_generic_invoke_options(C, op); // XXX these props don't get set right when only exec() is called
595         ED_object_add_generic_get_opts(op, loc, rot, &enter_editmode, &layer);
596         
597         if(obedit==NULL || obedit->type!=OB_SURF) {
598                 obedit= ED_object_add_type(C, OB_SURF, loc, rot, TRUE, layer);
599                 newob = 1;
600         }
601         else DAG_id_flush_update(&obedit->id, OB_RECALC_DATA);
602         
603         ED_object_new_primitive_matrix(C, loc, rot, mat);
604         
605         nu= add_nurbs_primitive(C, mat, RNA_enum_get(op->ptr, "type"), newob);
606         editnurb= curve_get_editcurve(obedit);
607         BLI_addtail(editnurb, nu);
608         
609         /* userdef */
610         if (newob && !enter_editmode) {
611                 ED_object_exit_editmode(C, EM_FREEDATA);
612         }
613         
614         WM_event_add_notifier(C, NC_OBJECT|ND_DRAW, obedit);
615         
616         return OPERATOR_FINISHED;
617 }
618
619 void OBJECT_OT_surface_add(wmOperatorType *ot)
620 {
621         /* identifiers */
622         ot->name= "Add Surface";
623         ot->description = "Add a surface object to the scene";
624         ot->idname= "OBJECT_OT_surface_add";
625         
626         /* api callbacks */
627         ot->invoke= WM_menu_invoke;
628         ot->exec= object_add_surface_exec;
629         
630         ot->poll= ED_operator_scene_editable;
631         
632         /* flags */
633         ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
634         
635         ot->prop= RNA_def_enum(ot->srna, "type", prop_surface_types, 0, "Primitive", "");
636         ED_object_add_generic_props(ot, TRUE);
637 }
638
639 static EnumPropertyItem prop_metaball_types[]= {
640         {MB_BALL, "MBALL_BALL", ICON_META_BALL, "Meta Ball", ""},
641         {MB_TUBE, "MBALL_TUBE", ICON_META_TUBE, "Meta Tube", ""},
642         {MB_PLANE, "MBALL_PLANE", ICON_META_PLANE, "Meta Plane", ""},
643         {MB_CUBE, "MBALL_CUBE", ICON_META_CUBE, "Meta Cube", ""},
644         {MB_ELIPSOID, "MBALL_ELLIPSOID", ICON_META_ELLIPSOID, "Meta Ellipsoid", ""},
645         {0, NULL, 0, NULL, NULL}
646 };
647
648 static int object_metaball_add_exec(bContext *C, wmOperator *op)
649 {
650         Object *obedit= CTX_data_edit_object(C);
651         MetaBall *mball;
652         MetaElem *elem;
653         int newob= 0;
654         int enter_editmode;
655         unsigned int layer;
656         float loc[3], rot[3];
657         float mat[4][4];
658         
659         object_add_generic_invoke_options(C, op); // XXX these props don't get set right when only exec() is called
660         ED_object_add_generic_get_opts(op, loc, rot, &enter_editmode, &layer);
661         
662         if(obedit==NULL || obedit->type!=OB_MBALL) {
663                 obedit= ED_object_add_type(C, OB_MBALL, loc, rot, TRUE, layer);
664                 newob = 1;
665         }
666         else DAG_id_flush_update(&obedit->id, OB_RECALC_DATA);
667         
668         ED_object_new_primitive_matrix(C, loc, rot, mat);
669         
670         elem= (MetaElem*)add_metaball_primitive(C, mat, RNA_enum_get(op->ptr, "type"), newob);
671         mball= (MetaBall*)obedit->data;
672         BLI_addtail(mball->editelems, elem);
673         
674         /* userdef */
675         if (newob && !enter_editmode) {
676                 ED_object_exit_editmode(C, EM_FREEDATA);
677         }
678         
679         WM_event_add_notifier(C, NC_OBJECT|ND_DRAW, obedit);
680         
681         return OPERATOR_FINISHED;
682 }
683
684 static int object_metaball_add_invoke(bContext *C, wmOperator *op, wmEvent *event)
685 {
686         Object *obedit= CTX_data_edit_object(C);
687         uiPopupMenu *pup;
688         uiLayout *layout;
689
690         object_add_generic_invoke_options(C, op);
691
692         pup= uiPupMenuBegin(C, op->type->name, 0);
693         layout= uiPupMenuLayout(pup);
694         if(!obedit || obedit->type == OB_MBALL)
695                 uiItemsEnumO(layout, op->type->idname, "type");
696         else
697                 uiItemsEnumO(layout, "OBJECT_OT_metaball_add", "type");
698         uiPupMenuEnd(C, pup);
699
700         return OPERATOR_CANCELLED;
701 }
702
703 void OBJECT_OT_metaball_add(wmOperatorType *ot)
704 {
705         /* identifiers */
706         ot->name= "Add Metaball";
707         ot->description= "Add an metaball object to the scene";
708         ot->idname= "OBJECT_OT_metaball_add";
709
710         /* api callbacks */
711         ot->invoke= object_metaball_add_invoke;
712         ot->exec= object_metaball_add_exec;
713         ot->poll= ED_operator_scene_editable;
714
715         /* flags */
716         ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
717         
718         RNA_def_enum(ot->srna, "type", prop_metaball_types, 0, "Primitive", "");
719         ED_object_add_generic_props(ot, TRUE);
720 }
721
722 static int object_add_text_exec(bContext *C, wmOperator *op)
723 {
724         Object *obedit= CTX_data_edit_object(C);
725         int enter_editmode;
726         unsigned int layer;
727         float loc[3], rot[3];
728         
729         object_add_generic_invoke_options(C, op); // XXX these props don't get set right when only exec() is called
730         ED_object_add_generic_get_opts(op, loc, rot, &enter_editmode, &layer);
731         
732         if(obedit && obedit->type==OB_FONT)
733                 return OPERATOR_CANCELLED;
734
735         obedit= ED_object_add_type(C, OB_FONT, loc, rot, enter_editmode, layer);
736         
737         WM_event_add_notifier(C, NC_OBJECT|ND_DRAW, obedit);
738         
739         return OPERATOR_FINISHED;
740 }
741
742 void OBJECT_OT_text_add(wmOperatorType *ot)
743 {
744         /* identifiers */
745         ot->name= "Add Text";
746         ot->description = "Add a text object to the scene";
747         ot->idname= "OBJECT_OT_text_add";
748         
749         /* api callbacks */
750         ot->invoke= ED_object_add_generic_invoke;
751         ot->exec= object_add_text_exec;
752         ot->poll= ED_operator_scene_editable;
753         
754         /* flags */
755         ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
756         ED_object_add_generic_props(ot, TRUE);
757 }
758
759 static int object_armature_add_exec(bContext *C, wmOperator *op)
760 {
761         Object *obedit= CTX_data_edit_object(C);
762         View3D *v3d= CTX_wm_view3d(C);
763         RegionView3D *rv3d= NULL;
764         int newob= 0;
765         int enter_editmode;
766         unsigned int layer;
767         float loc[3], rot[3];
768         
769         object_add_generic_invoke_options(C, op); // XXX these props don't get set right when only exec() is called
770         ED_object_add_generic_get_opts(op, loc, rot, &enter_editmode, &layer);
771         
772         if ((obedit==NULL) || (obedit->type != OB_ARMATURE)) {
773                 obedit= ED_object_add_type(C, OB_ARMATURE, loc, rot, TRUE, layer);
774                 ED_object_enter_editmode(C, 0);
775                 newob = 1;
776         }
777         else DAG_id_flush_update(&obedit->id, OB_RECALC_DATA);
778         
779         if(obedit==NULL) {
780                 BKE_report(op->reports, RPT_ERROR, "Cannot create editmode armature.");
781                 return OPERATOR_CANCELLED;
782         }
783         
784         if(v3d) 
785                 rv3d= CTX_wm_region(C)->regiondata;
786         
787         /* v3d and rv3d are allowed to be NULL */
788         add_primitive_bone(CTX_data_scene(C), v3d, rv3d);
789
790         /* userdef */
791         if (newob && !enter_editmode)
792                 ED_object_exit_editmode(C, EM_FREEDATA);
793         
794         WM_event_add_notifier(C, NC_OBJECT|ND_DRAW, obedit);
795         
796         return OPERATOR_FINISHED;
797 }
798
799 void OBJECT_OT_armature_add(wmOperatorType *ot)
800 {       
801         /* identifiers */
802         ot->name= "Add Armature";
803         ot->description = "Add an armature object to the scene";
804         ot->idname= "OBJECT_OT_armature_add";
805         
806         /* api callbacks */
807         ot->invoke= ED_object_add_generic_invoke;
808         ot->exec= object_armature_add_exec;
809         ot->poll= ED_operator_scene_editable;
810         
811         /* flags */
812         ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
813         ED_object_add_generic_props(ot, TRUE);
814 }
815
816 static int object_lamp_add_exec(bContext *C, wmOperator *op)
817 {
818         Object *ob;
819         int type= RNA_enum_get(op->ptr, "type");
820         int enter_editmode;
821         unsigned int layer;
822         float loc[3], rot[3];
823         
824         object_add_generic_invoke_options(C, op);
825         ED_object_add_generic_get_opts(op, loc, rot, &enter_editmode, &layer);
826
827         ob= ED_object_add_type(C, OB_LAMP, loc, rot, FALSE, layer);
828         if(ob && ob->data)
829                 ((Lamp*)ob->data)->type= type;
830         
831         return OPERATOR_FINISHED;
832 }
833
834 void OBJECT_OT_lamp_add(wmOperatorType *ot)
835 {       
836         static EnumPropertyItem lamp_type_items[] = {
837                 {LA_LOCAL, "POINT", ICON_LAMP_POINT, "Point", "Omnidirectional point light source"},
838                 {LA_SUN, "SUN", ICON_LAMP_SUN, "Sun", "Constant direction parallel ray light source"},
839                 {LA_SPOT, "SPOT", ICON_LAMP_SPOT, "Spot", "Directional cone light source"},
840                 {LA_HEMI, "HEMI", ICON_LAMP_HEMI, "Hemi", "180 degree constant light source"},
841                 {LA_AREA, "AREA", ICON_LAMP_AREA, "Area", "Directional area light source"},
842                 {0, NULL, 0, NULL, NULL}};
843
844         /* identifiers */
845         ot->name= "Add Lamp";
846         ot->description = "Add a lamp object to the scene";
847         ot->idname= "OBJECT_OT_lamp_add";
848         
849         /* api callbacks */
850         ot->invoke= WM_menu_invoke;
851         ot->exec= object_lamp_add_exec;
852         ot->poll= ED_operator_scene_editable;
853         
854         /* flags */
855         ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
856
857         /* properties */
858         ot->prop= RNA_def_enum(ot->srna, "type", lamp_type_items, 0, "Type", "");
859
860         ED_object_add_generic_props(ot, FALSE);
861 }
862
863 static int group_instance_add_exec(bContext *C, wmOperator *op)
864 {
865         Group *group= BLI_findlink(&CTX_data_main(C)->group, RNA_enum_get(op->ptr, "type"));
866
867         int enter_editmode;
868         unsigned int layer;
869         float loc[3], rot[3];
870         
871         object_add_generic_invoke_options(C, op);
872         ED_object_add_generic_get_opts(op, loc, rot, &enter_editmode, &layer);
873
874         if(group) {
875                 Object *ob= ED_object_add_type(C, OB_EMPTY, loc, rot, FALSE, layer);
876                 rename_id(&ob->id, group->id.name+2);
877                 ob->dup_group= group;
878                 ob->transflag |= OB_DUPLIGROUP;
879                 id_us_plus(&group->id);
880
881
882                 WM_event_add_notifier(C, NC_OBJECT|ND_DRAW, ob);
883
884                 return OPERATOR_FINISHED;
885         }
886
887         return OPERATOR_CANCELLED;
888 }
889
890 /* only used as menu */
891 void OBJECT_OT_group_instance_add(wmOperatorType *ot)
892 {
893         PropertyRNA *prop;
894
895         /* identifiers */
896         ot->name= "Add Group Instance";
897         ot->description = "Add a dupligroup instance";
898         ot->idname= "OBJECT_OT_group_instance_add";
899
900         /* api callbacks */
901         ot->invoke= WM_enum_search_invoke;
902         ot->exec= group_instance_add_exec;
903
904         ot->poll= ED_operator_scene_editable;
905
906         /* flags */
907         ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
908
909         /* properties */
910         prop= RNA_def_enum(ot->srna, "type", DummyRNA_NULL_items, 0, "Type", "");
911         RNA_def_enum_funcs(prop, RNA_group_itemf);
912         ot->prop= prop;
913         ED_object_add_generic_props(ot, FALSE);
914 }
915
916 /**************************** Delete Object *************************/
917
918 /* remove base from a specific scene */
919 /* note: now unlinks constraints as well */
920 void ED_base_object_free_and_unlink(Scene *scene, Base *base)
921 {
922         BLI_remlink(&scene->base, base);
923         free_libblock_us(&G.main->object, base->object);
924         if(scene->basact==base) scene->basact= NULL;
925         MEM_freeN(base);
926 }
927
928 static int object_delete_exec(bContext *C, wmOperator *op)
929 {
930         Scene *scene= CTX_data_scene(C);
931         int islamp= 0;
932         
933         if(CTX_data_edit_object(C)) 
934                 return OPERATOR_CANCELLED;
935         
936         CTX_DATA_BEGIN(C, Base*, base, selected_bases) {
937
938                 if(base->object->type==OB_LAMP) islamp= 1;
939                 
940                 /* remove from current scene only */
941                 ED_base_object_free_and_unlink(scene, base);
942         }
943         CTX_DATA_END;
944
945         if(islamp) reshadeall_displist(scene);  /* only frees displist */
946         
947         DAG_scene_sort(scene);
948         DAG_ids_flush_update(0);
949         
950         WM_event_add_notifier(C, NC_SCENE|ND_OB_ACTIVE, CTX_data_scene(C));
951         
952         return OPERATOR_FINISHED;
953 }
954
955 void OBJECT_OT_delete(wmOperatorType *ot)
956 {
957         /* identifiers */
958         ot->name= "Delete";
959         ot->description = "Delete selected objects";
960         ot->idname= "OBJECT_OT_delete";
961         
962         /* api callbacks */
963         ot->invoke= WM_operator_confirm;
964         ot->exec= object_delete_exec;
965         ot->poll= ED_operator_scene_editable;
966         
967         /* flags */
968         ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
969 }
970
971 /**************************** Copy Utilities ******************************/
972
973 static void copy_object__forwardModifierLinks(void *userData, Object *ob,
974                                               ID **idpoin)
975 {
976         /* this is copied from ID_NEW; it might be better to have a macro */
977         if(*idpoin && (*idpoin)->newid) *idpoin = (*idpoin)->newid;
978 }
979
980 /* after copying objects, copied data should get new pointers */
981 static void copy_object_set_idnew(bContext *C, int dupflag)
982 {
983         Material *ma, *mao;
984         ID *id;
985 #if 0 // XXX old animation system
986         Ipo *ipo;
987         bActionStrip *strip;
988 #endif // XXX old animation system
989         int a;
990         
991         /* XXX check object pointers */
992         CTX_DATA_BEGIN(C, Object*, ob, selected_editable_objects) {
993                 relink_constraints(&ob->constraints);
994                 if (ob->pose){
995                         bPoseChannel *chan;
996                         for (chan = ob->pose->chanbase.first; chan; chan=chan->next){
997                                 relink_constraints(&chan->constraints);
998                         }
999                 }
1000                 modifiers_foreachIDLink(ob, copy_object__forwardModifierLinks, NULL);
1001                 ID_NEW(ob->parent);
1002                 ID_NEW(ob->track);
1003                 ID_NEW(ob->proxy);
1004                 ID_NEW(ob->proxy_group);
1005                 
1006 #if 0 // XXX old animation system
1007                 for(strip= ob->nlastrips.first; strip; strip= strip->next) {
1008                         bActionModifier *amod;
1009                         for(amod= strip->modifiers.first; amod; amod= amod->next)
1010                                 ID_NEW(amod->ob);
1011                 }
1012 #endif // XXX old animation system
1013         }
1014         CTX_DATA_END;
1015         
1016         /* materials */
1017         if( dupflag & USER_DUP_MAT) {
1018                 mao= G.main->mat.first;
1019                 while(mao) {
1020                         if(mao->id.newid) {
1021                                 
1022                                 ma= (Material *)mao->id.newid;
1023                                 
1024                                 if(dupflag & USER_DUP_TEX) {
1025                                         for(a=0; a<MAX_MTEX; a++) {
1026                                                 if(ma->mtex[a]) {
1027                                                         id= (ID *)ma->mtex[a]->tex;
1028                                                         if(id) {
1029                                                                 ID_NEW_US(ma->mtex[a]->tex)
1030                                                                 else ma->mtex[a]->tex= copy_texture(ma->mtex[a]->tex);
1031                                                                 id->us--;
1032                                                         }
1033                                                 }
1034                                         }
1035                                 }
1036 #if 0 // XXX old animation system
1037                                 id= (ID *)ma->ipo;
1038                                 if(id) {
1039                                         ID_NEW_US(ma->ipo)
1040                                         else ma->ipo= copy_ipo(ma->ipo);
1041                                         id->us--;
1042                                 }
1043 #endif // XXX old animation system
1044                         }
1045                         mao= mao->id.next;
1046                 }
1047         }
1048         
1049 #if 0 // XXX old animation system
1050         /* lamps */
1051         if( dupflag & USER_DUP_IPO) {
1052                 Lamp *la= G.main->lamp.first;
1053                 while(la) {
1054                         if(la->id.newid) {
1055                                 Lamp *lan= (Lamp *)la->id.newid;
1056                                 id= (ID *)lan->ipo;
1057                                 if(id) {
1058                                         ID_NEW_US(lan->ipo)
1059                                         else lan->ipo= copy_ipo(lan->ipo);
1060                                         id->us--;
1061                                 }
1062                         }
1063                         la= la->id.next;
1064                 }
1065         }
1066         
1067         /* ipos */
1068         ipo= G.main->ipo.first;
1069         while(ipo) {
1070                 if(ipo->id.lib==NULL && ipo->id.newid) {
1071                         Ipo *ipon= (Ipo *)ipo->id.newid;
1072                         IpoCurve *icu;
1073                         for(icu= ipon->curve.first; icu; icu= icu->next) {
1074                                 if(icu->driver) {
1075                                         ID_NEW(icu->driver->ob);
1076                                 }
1077                         }
1078                 }
1079                 ipo= ipo->id.next;
1080         }
1081 #endif // XXX old animation system
1082         
1083         set_sca_new_poins();
1084         
1085         clear_id_newpoins();
1086 }
1087
1088 /********************* Make Duplicates Real ************************/
1089
1090 static void make_object_duplilist_real(bContext *C, Scene *scene, Base *base)
1091 {
1092         Base *basen;
1093         Object *ob;
1094         ListBase *lb;
1095         DupliObject *dob;
1096         
1097         if(!base && !(base = BASACT))
1098                 return;
1099         
1100         if(!(base->object->transflag & OB_DUPLI))
1101                 return;
1102         
1103         lb= object_duplilist(scene, base->object);
1104         
1105         for(dob= lb->first; dob; dob= dob->next) {
1106                 ob= copy_object(dob->ob);
1107                 /* font duplis can have a totcol without material, we get them from parent
1108                 * should be implemented better...
1109                 */
1110                 if(ob->mat==NULL) ob->totcol= 0;
1111                 
1112                 basen= MEM_dupallocN(base);
1113                 basen->flag &= ~OB_FROMDUPLI;
1114                 basen->lay= base->lay;
1115                 BLI_addhead(&scene->base, basen);       /* addhead: othwise eternal loop */
1116                 basen->object= ob;
1117                 ob->ipo= NULL;          /* make sure apply works */
1118                 ob->parent= ob->track= NULL;
1119                 ob->disp.first= ob->disp.last= NULL;
1120                 ob->transflag &= ~OB_DUPLI;     
1121                 ob->lay= base->lay;
1122                 
1123                 copy_m4_m4(ob->obmat, dob->mat);
1124                 ED_object_apply_obmat(ob);
1125         }
1126         
1127         copy_object_set_idnew(C, 0);
1128         
1129         free_object_duplilist(lb);
1130         
1131         base->object->transflag &= ~OB_DUPLI;   
1132 }
1133
1134 static int object_duplicates_make_real_exec(bContext *C, wmOperator *op)
1135 {
1136         Scene *scene= CTX_data_scene(C);
1137         
1138         clear_id_newpoins();
1139                 
1140         CTX_DATA_BEGIN(C, Base*, base, selected_editable_bases) {
1141                 make_object_duplilist_real(C, scene, base);
1142         }
1143         CTX_DATA_END;
1144
1145         DAG_scene_sort(scene);
1146         DAG_ids_flush_update(0);
1147         WM_event_add_notifier(C, NC_SCENE, scene);
1148         
1149         return OPERATOR_FINISHED;
1150 }
1151
1152 void OBJECT_OT_duplicates_make_real(wmOperatorType *ot)
1153 {
1154         
1155         /* identifiers */
1156         ot->name= "Make Duplicates Real";
1157         ot->description = "Make dupli objects attached to this object real";
1158         ot->idname= "OBJECT_OT_duplicates_make_real";
1159         
1160         /* api callbacks */
1161         ot->exec= object_duplicates_make_real_exec;
1162         
1163         ot->poll= ED_operator_scene_editable;
1164         
1165         /* flags */
1166         ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
1167 }
1168
1169 /**************************** Convert **************************/
1170
1171 static EnumPropertyItem convert_target_items[]= {
1172         {OB_CURVE, "CURVE", ICON_OUTLINER_OB_CURVE, "Curve from Mesh/Text", ""},
1173         {OB_MESH, "MESH", ICON_OUTLINER_OB_MESH, "Mesh from Curve/Meta/Surf/Mesh", ""},
1174         {0, NULL, 0, NULL, NULL}};
1175
1176 static void curvetomesh(Scene *scene, Object *ob) 
1177 {
1178         Curve *cu= ob->data;
1179         
1180         if(cu->disp.first==0)
1181                 makeDispListCurveTypes(scene, ob, 0); /* force creation */
1182
1183         nurbs_to_mesh(ob); /* also does users */
1184
1185         if(ob->type == OB_MESH)
1186                 object_free_modifiers(ob);
1187 }
1188
1189 static int convert_poll(bContext *C)
1190 {
1191         Object *obact= CTX_data_active_object(C);
1192         Scene *scene= CTX_data_scene(C);
1193
1194         return (!scene->id.lib && obact && scene->obedit != obact && (obact->flag & SELECT) && !(obact->id.lib));
1195 }
1196
1197 /* Helper for convert_exec */
1198 static Base *duplibase_for_convert(Scene *scene, Base *base, Object *ob)
1199 {
1200         Object *obn;
1201         Base *basen;
1202
1203         if (ob == NULL) {
1204                 ob= base->object;
1205         }
1206
1207         obn= copy_object(ob);
1208         obn->recalc |= OB_RECALC;
1209
1210         basen= MEM_mallocN(sizeof(Base), "duplibase");
1211         *basen= *base;
1212         BLI_addhead(&scene->base, basen);       /* addhead: otherwise eternal loop */
1213         basen->object= obn;
1214         basen->flag |= SELECT;
1215         obn->flag |= SELECT;
1216         base->flag &= ~SELECT;
1217         ob->flag &= ~SELECT;
1218
1219         return basen;
1220 }
1221
1222 static int convert_exec(bContext *C, wmOperator *op)
1223 {
1224         Scene *scene= CTX_data_scene(C);
1225         Base *basen=NULL, *basact=NULL, *basedel=NULL;
1226         Object *ob, *ob1, *newob, *obact= CTX_data_active_object(C);
1227         DerivedMesh *dm;
1228         Curve *cu;
1229         Nurb *nu;
1230         MetaBall *mb;
1231         Mesh *me;
1232         int target= RNA_enum_get(op->ptr, "target");
1233         int keep_original= RNA_boolean_get(op->ptr, "keep_original");
1234         int a, mballConverted= 0;
1235
1236         /* don't forget multiple users! */
1237
1238         /* reset flags */
1239         CTX_DATA_BEGIN(C, Base*, base, selected_editable_bases) {
1240                 ob= base->object;
1241                 ob->flag &= ~OB_DONE;
1242         }
1243         CTX_DATA_END;
1244
1245         CTX_DATA_BEGIN(C, Base*, base, selected_editable_bases) {
1246                 ob= base->object;
1247
1248                 if(ob->flag & OB_DONE) {
1249                         if (ob->type != target) {
1250                                 base->flag &= ~SELECT;
1251                                 ob->flag &= ~SELECT;
1252                         }
1253                 }
1254                 else if (ob->type==OB_MESH && target == OB_CURVE) {
1255                         ob->flag |= OB_DONE;
1256
1257                         if (keep_original) {
1258                                 basen= duplibase_for_convert(scene, base, NULL);
1259                                 newob= basen->object;
1260
1261                                 /* decrement original mesh's usage count  */
1262                                 me= newob->data;
1263                                 me->id.us--;
1264
1265                                 /* make a new copy of the mesh */
1266                                 newob->data= copy_mesh(me);
1267                         } else {
1268                                 newob = ob;
1269                         }
1270
1271                         mesh_to_curve(scene, newob);
1272
1273                         if(newob->type==OB_CURVE)
1274                                 object_free_modifiers(newob);   /* after derivedmesh calls! */
1275                 }
1276                 else if(ob->type==OB_MESH && ob->modifiers.first) { /* converting a mesh with no modifiers causes a segfault */
1277                         ob->flag |= OB_DONE;
1278
1279                         if (keep_original) {
1280                                 basen= duplibase_for_convert(scene, base, NULL);
1281                                 newob= basen->object;
1282
1283                                 /* decrement original mesh's usage count  */
1284                                 me= newob->data;
1285                                 me->id.us--;
1286
1287                                 /* make a new copy of the mesh */
1288                                 newob->data= copy_mesh(me);
1289                         } else {
1290                                 newob = ob;
1291                                 ob->recalc |= OB_RECALC;
1292                         }
1293
1294                         /* make new mesh data from the original copy */
1295                         /* note: get the mesh from the original, not from the copy in some
1296                          * cases this doesnt give correct results (when MDEF is used for eg)
1297                          */
1298                         dm= mesh_get_derived_final(scene, newob, CD_MASK_MESH);
1299                         /* dm= mesh_create_derived_no_deform(ob1, NULL);        this was called original (instead of get_derived). man o man why! (ton) */
1300
1301                         DM_to_mesh(dm, newob->data);
1302
1303                         dm->release(dm);
1304                         object_free_modifiers(newob);   /* after derivedmesh calls! */
1305                 }
1306                 else if(ob->type==OB_FONT) {
1307                         ob->flag |= OB_DONE;
1308
1309                         if (keep_original) {
1310                                 basen= duplibase_for_convert(scene, base, NULL);
1311                                 newob= basen->object;
1312
1313                                 /* decrement original curve's usage count  */
1314                                 ((Curve *)newob->data)->id.us--;
1315
1316                                 /* make a new copy of the curve */
1317                                 newob->data= copy_curve(ob->data);
1318                         } else {
1319                                 newob= ob;
1320                         }
1321
1322                         cu= newob->data;
1323
1324                         if (!cu->disp.first)
1325                                 makeDispListCurveTypes(scene, newob, 0);
1326
1327                         newob->type= OB_CURVE;
1328
1329                         if(cu->vfont) {
1330                                 cu->vfont->id.us--;
1331                                 cu->vfont= 0;
1332                         }
1333                         if(cu->vfontb) {
1334                                 cu->vfontb->id.us--;
1335                                 cu->vfontb= 0;
1336                         }
1337                         if(cu->vfonti) {
1338                                 cu->vfonti->id.us--;
1339                                 cu->vfonti= 0;
1340                         }
1341                         if(cu->vfontbi) {
1342                                 cu->vfontbi->id.us--;
1343                                 cu->vfontbi= 0;
1344                         }
1345
1346                         if (!keep_original) {
1347                                 /* other users */
1348                                 if(cu->id.us>1) {
1349                                         for(ob1= G.main->object.first; ob1; ob1=ob1->id.next) {
1350                                                 if(ob1->data==ob->data) {
1351                                                         ob1->type= OB_CURVE;
1352                                                         ob1->recalc |= OB_RECALC;
1353                                                 }
1354                                         }
1355                                 }
1356                         }
1357
1358                         for(nu=cu->nurb.first; nu; nu=nu->next)
1359                                 nu->charidx= 0;
1360
1361                         if(target == OB_MESH)
1362                                 curvetomesh(scene, newob);
1363                 }
1364                 else if(ELEM(ob->type, OB_CURVE, OB_SURF)) {
1365                         ob->flag |= OB_DONE;
1366
1367                         if(target == OB_MESH) {
1368                                 if (keep_original) {
1369                                         basen= duplibase_for_convert(scene, base, NULL);
1370                                         newob= basen->object;
1371
1372                                         /* decrement original curve's usage count  */
1373                                         ((Curve *)newob->data)->id.us--;
1374
1375                                         /* make a new copy of the curve */
1376                                         newob->data= copy_curve(ob->data);
1377                                 } else {
1378                                         newob= ob;
1379                                 }
1380
1381                                 curvetomesh(scene, newob);
1382                         }
1383                 }
1384                 else if(ob->type==OB_MBALL) {
1385                         Object *baseob;
1386
1387                         if (target != OB_MESH) {
1388                                 ob->flag |= OB_DONE;
1389                                 continue;
1390                         }
1391
1392                         base->flag &= ~SELECT;
1393                         ob->flag &= ~SELECT;
1394
1395                         baseob= find_basis_mball(scene, ob);
1396
1397                         if (ob != baseob) {
1398                                 /* if motherball is converting it would be marked as done later */
1399                                 ob->flag |= OB_DONE;
1400                         }
1401
1402                         if (!baseob->disp.first) {
1403                                 makeDispListMBall(scene, baseob);
1404                         }
1405
1406                         if(!(baseob->flag & OB_DONE)) {
1407                                 baseob->flag |= OB_DONE;
1408
1409                                 basen= duplibase_for_convert(scene, base, baseob);
1410                                 newob= basen->object;
1411
1412                                 mb= newob->data;
1413                                 mb->id.us--;
1414
1415                                 newob->data= add_mesh("Mesh");
1416                                 newob->type= OB_MESH;
1417
1418                                 me= newob->data;
1419                                 me->totcol= mb->totcol;
1420                                 if(newob->totcol) {
1421                                         me->mat= MEM_dupallocN(mb->mat);
1422                                         for(a=0; a<newob->totcol; a++) id_us_plus((ID *)me->mat[a]);
1423                                 }
1424
1425                                 mball_to_mesh(&baseob->disp, newob->data);
1426
1427                                 if (obact->type == OB_MBALL) {
1428                                         basact= basen;
1429                                 }
1430
1431                                 mballConverted= 1;
1432                         }
1433                         else
1434                                 continue;
1435                 }
1436                 else
1437                         continue;
1438
1439                 /* If the original object is active then make this object active */
1440                 if(basen) {
1441                         if(ob == obact) {
1442                                 /* store new active base to update BASACT */
1443                                 basact= basen;
1444                         }
1445
1446                         basen= NULL;
1447                 }
1448
1449                 /* delete original if needed */
1450                 if(basedel) {
1451                         if(!keep_original)
1452                                 ED_base_object_free_and_unlink(scene, basedel); 
1453
1454                         basedel = NULL;
1455                 }
1456         }
1457         CTX_DATA_END;
1458
1459         if(!keep_original) {
1460                 if (mballConverted) {
1461                         Base *base= scene->base.first, *tmpbase;
1462                         while (base) {
1463                                 ob= base->object;
1464                                 tmpbase= base;
1465                                 base= base->next;
1466
1467                                 if (ob->type == OB_MBALL) {
1468                                         ED_base_object_free_and_unlink(scene, tmpbase);
1469                                 }
1470                         }
1471                 }
1472
1473                 /* delete object should renew depsgraph */
1474                 DAG_scene_sort(scene);
1475         }
1476
1477 // XXX  ED_object_enter_editmode(C, 0);
1478 // XXX  exit_editmode(C, EM_FREEDATA|EM_WAITCURSOR); /* freedata, but no undo */
1479
1480         if (basact) {
1481                 /* active base was changed */
1482                 ED_base_object_activate(C, basact);
1483                 BASACT= basact;
1484         } else if (BASACT->object->flag & OB_DONE) {
1485                 WM_event_add_notifier(C, NC_OBJECT|ND_MODIFIER|ND_DATA, BASACT->object);
1486         }
1487
1488         DAG_scene_sort(scene);
1489         WM_event_add_notifier(C, NC_SCENE|NC_OBJECT|ND_DRAW, scene); /* is NC_SCENE needed ? */
1490
1491         return OPERATOR_FINISHED;
1492 }
1493
1494
1495 void OBJECT_OT_convert(wmOperatorType *ot)
1496 {
1497         /* identifiers */
1498         ot->name= "Convert";
1499         ot->description = "Convert selected objects to another type";
1500         ot->idname= "OBJECT_OT_convert";
1501         
1502         /* api callbacks */
1503         ot->invoke= WM_menu_invoke;
1504         ot->exec= convert_exec;
1505         ot->poll= convert_poll;
1506         
1507         /* flags */
1508         ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
1509
1510         /* properties */
1511         ot->prop= RNA_def_enum(ot->srna, "target", convert_target_items, OB_MESH, "Target", "Type of object to convert to.");
1512         RNA_def_boolean(ot->srna, "keep_original", 0, "Keep Original", "Keep original objects instead of replacing them.");
1513 }
1514
1515 /**************************** Duplicate ************************/
1516
1517 /* 
1518         dupflag: a flag made from constants declared in DNA_userdef_types.h
1519         The flag tells adduplicate() weather to copy data linked to the object, or to reference the existing data.
1520         U.dupflag for default operations or you can construct a flag as python does
1521         if the dupflag is 0 then no data will be copied (linked duplicate) */
1522
1523 /* used below, assumes id.new is correct */
1524 /* leaves selection of base/object unaltered */
1525 static Base *object_add_duplicate_internal(Scene *scene, Base *base, int dupflag)
1526 {
1527         Base *basen= NULL;
1528         Material ***matarar;
1529         Object *ob, *obn;
1530         ID *id;
1531         int a, didit;
1532
1533         ob= base->object;
1534         if(ob->mode & OB_MODE_POSE) {
1535                 ; /* nothing? */
1536         }
1537         else {
1538                 obn= copy_object(ob);
1539                 obn->recalc |= OB_RECALC;
1540                 
1541                 basen= MEM_mallocN(sizeof(Base), "duplibase");
1542                 *basen= *base;
1543                 BLI_addhead(&scene->base, basen);       /* addhead: prevent eternal loop */
1544                 basen->object= obn;
1545                 
1546                 if(basen->flag & OB_FROMGROUP) {
1547                         Group *group;
1548                         for(group= G.main->group.first; group; group= group->id.next) {
1549                                 if(object_in_group(ob, group))
1550                                         add_to_group(group, obn, scene, basen);
1551                         }
1552                 }
1553                 
1554                 /* duplicates using userflags */
1555 #if 0 // XXX old animation system                               
1556                 if(dupflag & USER_DUP_IPO) {
1557                         bConstraintChannel *chan;
1558                         id= (ID *)obn->ipo;
1559                         
1560                         if(id) {
1561                                 ID_NEW_US( obn->ipo)
1562                                 else obn->ipo= copy_ipo(obn->ipo);
1563                                 id->us--;
1564                         }
1565                         /* Handle constraint ipos */
1566                         for (chan=obn->constraintChannels.first; chan; chan=chan->next){
1567                                 id= (ID *)chan->ipo;
1568                                 if(id) {
1569                                         ID_NEW_US( chan->ipo)
1570                                         else chan->ipo= copy_ipo(chan->ipo);
1571                                         id->us--;
1572                                 }
1573                         }
1574                 }
1575                 if(dupflag & USER_DUP_ACT){ /* Not buttons in the UI to modify this, add later? */
1576                         id= (ID *)obn->action;
1577                         if (id){
1578                                 ID_NEW_US(obn->action)
1579                                 else{
1580                                         obn->action= copy_action(obn->action);
1581                                 }
1582                                 id->us--;
1583                         }
1584                 }
1585 #endif // XXX old animation system
1586                 if(dupflag & USER_DUP_MAT) {
1587                         for(a=0; a<obn->totcol; a++) {
1588                                 id= (ID *)obn->mat[a];
1589                                 if(id) {
1590                                         ID_NEW_US(obn->mat[a])
1591                                         else obn->mat[a]= copy_material(obn->mat[a]);
1592                                         id->us--;
1593                                 }
1594                         }
1595                 }
1596                 if(dupflag & USER_DUP_PSYS) {
1597                         ParticleSystem *psys;
1598                         for(psys=obn->particlesystem.first; psys; psys=psys->next) {
1599                                 id= (ID*) psys->part;
1600                                 if(id) {
1601                                         ID_NEW_US(psys->part)
1602                                         else psys->part= psys_copy_settings(psys->part);
1603                                         id->us--;
1604                                 }
1605                         }
1606                 }
1607                 
1608                 id= obn->data;
1609                 didit= 0;
1610                 
1611                 switch(obn->type) {
1612                         case OB_MESH:
1613                                 if(dupflag & USER_DUP_MESH) {
1614                                         ID_NEW_US2( obn->data )
1615                                         else {
1616                                                 obn->data= copy_mesh(obn->data);
1617                                                 
1618                                                 if(obn->fluidsimSettings) {
1619                                                         obn->fluidsimSettings->orgMesh = (Mesh *)obn->data;
1620                                                 }
1621                                                 
1622                                                 didit= 1;
1623                                         }
1624                                         id->us--;
1625                                 }
1626                                 break;
1627                         case OB_CURVE:
1628                                 if(dupflag & USER_DUP_CURVE) {
1629                                         ID_NEW_US2(obn->data )
1630                                         else {
1631                                                 obn->data= copy_curve(obn->data);
1632                                                 didit= 1;
1633                                         }
1634                                         id->us--;
1635                                 }
1636                                 break;
1637                         case OB_SURF:
1638                                 if(dupflag & USER_DUP_SURF) {
1639                                         ID_NEW_US2( obn->data )
1640                                         else {
1641                                                 obn->data= copy_curve(obn->data);
1642                                                 didit= 1;
1643                                         }
1644                                         id->us--;
1645                                 }
1646                                 break;
1647                         case OB_FONT:
1648                                 if(dupflag & USER_DUP_FONT) {
1649                                         ID_NEW_US2( obn->data )
1650                                         else {
1651                                                 obn->data= copy_curve(obn->data);
1652                                                 didit= 1;
1653                                         }
1654                                         id->us--;
1655                                 }
1656                                 break;
1657                         case OB_MBALL:
1658                                 if(dupflag & USER_DUP_MBALL) {
1659                                         ID_NEW_US2(obn->data )
1660                                         else {
1661                                                 obn->data= copy_mball(obn->data);
1662                                                 didit= 1;
1663                                         }
1664                                         id->us--;
1665                                 }
1666                                 break;
1667                         case OB_LAMP:
1668                                 if(dupflag & USER_DUP_LAMP) {
1669                                         ID_NEW_US2(obn->data )
1670                                         else obn->data= copy_lamp(obn->data);
1671                                         id->us--;
1672                                 }
1673                                 break;
1674                                 
1675                         case OB_ARMATURE:
1676                                 obn->recalc |= OB_RECALC_DATA;
1677                                 if(obn->pose) obn->pose->flag |= POSE_RECALC;
1678                                         
1679                                         if(dupflag & USER_DUP_ARM) {
1680                                                 ID_NEW_US2(obn->data )
1681                                                 else {
1682                                                         obn->data= copy_armature(obn->data);
1683                                                         armature_rebuild_pose(obn, obn->data);
1684                                                         didit= 1;
1685                                                 }
1686                                                 id->us--;
1687                                         }
1688                                                 
1689                                                 break;
1690                                 
1691                         case OB_LATTICE:
1692                                 if(dupflag!=0) {
1693                                         ID_NEW_US2(obn->data )
1694                                         else obn->data= copy_lattice(obn->data);
1695                                         id->us--;
1696                                 }
1697                                 break;
1698                         case OB_CAMERA:
1699                                 if(dupflag!=0) {
1700                                         ID_NEW_US2(obn->data )
1701                                         else obn->data= copy_camera(obn->data);
1702                                         id->us--;
1703                                 }
1704                                 break;
1705                 }
1706                 
1707                 if(dupflag & USER_DUP_MAT) {
1708                         matarar= give_matarar(obn);
1709                         if(didit && matarar) {
1710                                 for(a=0; a<obn->totcol; a++) {
1711                                         id= (ID *)(*matarar)[a];
1712                                         if(id) {
1713                                                 ID_NEW_US( (*matarar)[a] )
1714                                                 else (*matarar)[a]= copy_material((*matarar)[a]);
1715                                                 
1716                                                 id->us--;
1717                                         }
1718                                 }
1719                         }
1720                 }
1721         }
1722         return basen;
1723 }
1724
1725 /* single object duplicate, if dupflag==0, fully linked, else it uses the flags given */
1726 /* leaves selection of base/object unaltered */
1727 Base *ED_object_add_duplicate(Scene *scene, Base *base, int dupflag)
1728 {
1729         Base *basen;
1730         Object *ob;
1731
1732         clear_id_newpoins();
1733         clear_sca_new_poins();  /* sensor/contr/act */
1734         
1735         basen= object_add_duplicate_internal(scene, base, dupflag);
1736         ob= basen->object;
1737         
1738         DAG_scene_sort(scene);
1739         ED_render_id_flush_update(G.main, ob->data);
1740         
1741         return basen;
1742 }
1743
1744 /* contextual operator dupli */
1745 static int duplicate_exec(bContext *C, wmOperator *op)
1746 {
1747         Scene *scene= CTX_data_scene(C);
1748         int linked= RNA_boolean_get(op->ptr, "linked");
1749         int dupflag= (linked)? 0: U.dupflag;
1750         
1751         clear_id_newpoins();
1752         clear_sca_new_poins();  /* sensor/contr/act */
1753         
1754         CTX_DATA_BEGIN(C, Base*, base, selected_editable_bases) {
1755                 Base *basen= object_add_duplicate_internal(scene, base, dupflag);
1756                 
1757                 /* note that this is safe to do with this context iterator,
1758                    the list is made in advance */
1759                 ED_base_object_select(base, BA_DESELECT);
1760
1761                 /* new object becomes active */
1762                 if(BASACT==base)
1763                         ED_base_object_activate(C, basen);
1764                 
1765                 ED_render_id_flush_update(G.main, basen->object->data);
1766         }
1767         CTX_DATA_END;
1768
1769         copy_object_set_idnew(C, dupflag);
1770
1771         DAG_scene_sort(scene);
1772         DAG_ids_flush_update(0);
1773
1774         WM_event_add_notifier(C, NC_SCENE|ND_OB_SELECT, scene);
1775
1776         return OPERATOR_FINISHED;
1777 }
1778
1779 void OBJECT_OT_duplicate(wmOperatorType *ot)
1780 {
1781         /* identifiers */
1782         ot->name= "Duplicate";
1783         ot->description = "Duplicate selected objects";
1784         ot->idname= "OBJECT_OT_duplicate";
1785         
1786         /* api callbacks */
1787         ot->exec= duplicate_exec;
1788         ot->poll= ED_operator_scene_editable;
1789         
1790         /* flags */
1791         ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
1792         
1793         /* to give to transform */
1794         RNA_def_boolean(ot->srna, "linked", 0, "Linked", "Duplicate object but not object data, linking to the original data.");
1795         RNA_def_int(ot->srna, "mode", TFM_TRANSLATION, 0, INT_MAX, "Mode", "", 0, INT_MAX);
1796 }
1797
1798 /* **************** add named object, for dragdrop ************* */
1799
1800 /* contextual operator dupli */
1801
1802 static int add_named_poll(bContext *C)
1803 {
1804         if(!ED_operator_scene_editable(C)) {
1805                 return 0;
1806         } else {
1807                 Object *ob= CTX_data_active_object(C);
1808                 if(ob && ob->mode != OB_MODE_OBJECT)
1809                         return 0;
1810                 else
1811                         return 1;
1812         }
1813 }
1814
1815 static int add_named_exec(bContext *C, wmOperator *op)
1816 {
1817         Scene *scene= CTX_data_scene(C);
1818         Base *basen, *base;
1819         Object *ob;
1820         int linked= RNA_boolean_get(op->ptr, "linked");
1821         int dupflag= (linked)? 0: U.dupflag;
1822         char name[32];
1823         
1824         /* find object, create fake base */
1825         RNA_string_get(op->ptr, "name", name);
1826         ob= (Object *)find_id("OB", name);
1827         if(ob==NULL) 
1828                 return OPERATOR_CANCELLED;
1829         
1830         base= MEM_callocN(sizeof(Base), "duplibase");
1831         base->object= ob;
1832         base->flag= ob->flag;
1833         
1834         /* prepare dupli */
1835         clear_id_newpoins();
1836         clear_sca_new_poins();  /* sensor/contr/act */
1837         
1838         basen= object_add_duplicate_internal(scene, base, dupflag);
1839         basen->lay= basen->object->lay= scene->lay;
1840         
1841         ED_object_location_from_view(C, basen->object->loc);
1842         ED_base_object_activate(C, basen);
1843         
1844         copy_object_set_idnew(C, dupflag);
1845         
1846         DAG_scene_sort(scene);
1847         DAG_ids_flush_update(0);
1848         
1849         MEM_freeN(base);
1850         
1851         WM_event_add_notifier(C, NC_SCENE|ND_OB_SELECT, scene);
1852         
1853         return OPERATOR_FINISHED;
1854 }
1855
1856 void OBJECT_OT_add_named(wmOperatorType *ot)
1857 {
1858         /* identifiers */
1859         ot->name= "Add Named Object";
1860         ot->description = "Add named object";
1861         ot->idname= "OBJECT_OT_add_named";
1862         
1863         /* api callbacks */
1864         ot->exec= add_named_exec;
1865         ot->poll= add_named_poll;
1866         
1867         /* flags */
1868         ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
1869         
1870         RNA_def_boolean(ot->srna, "linked", 0, "Linked", "Duplicate object but not object data, linking to the original data.");
1871         RNA_def_string(ot->srna, "name", "Cube", 24, "Name", "Object name to add.");
1872 }
1873
1874
1875
1876 /**************************** Join *************************/
1877 static int join_poll(bContext *C)
1878 {
1879         Object *ob= CTX_data_active_object(C);
1880         
1881         if (!ob || ob->id.lib) return 0;
1882         
1883         if (ELEM4(ob->type, OB_MESH, OB_CURVE, OB_SURF, OB_ARMATURE))
1884                 return ED_operator_screenactive(C);
1885         else
1886                 return 0;
1887 }
1888
1889
1890 static int join_exec(bContext *C, wmOperator *op)
1891 {
1892         Scene *scene= CTX_data_scene(C);
1893         Object *ob= CTX_data_active_object(C);
1894
1895         if(scene->obedit) {
1896                 BKE_report(op->reports, RPT_ERROR, "This data does not support joining in editmode.");
1897                 return OPERATOR_CANCELLED;
1898         }
1899         else if(object_data_is_libdata(ob)) {
1900                 BKE_report(op->reports, RPT_ERROR, "Can't edit external libdata.");
1901                 return OPERATOR_CANCELLED;
1902         }
1903
1904         if(ob->type == OB_MESH)
1905                 return join_mesh_exec(C, op);
1906         else if(ELEM(ob->type, OB_CURVE, OB_SURF))
1907                 return join_curve_exec(C, op);
1908         else if(ob->type == OB_ARMATURE)
1909                 return join_armature_exec(C, op);
1910         
1911         return OPERATOR_CANCELLED;
1912 }
1913
1914 void OBJECT_OT_join(wmOperatorType *ot)
1915 {
1916         /* identifiers */
1917         ot->name= "Join";
1918         ot->description = "Join selected objects into active object";
1919         ot->idname= "OBJECT_OT_join";
1920         
1921         /* api callbacks */
1922         ot->exec= join_exec;
1923         ot->poll= join_poll;
1924         
1925         /* flags */
1926         ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
1927 }
1928
1929 /**************************** Join as Shape Key*************************/
1930 static int join_shapes_poll(bContext *C)
1931 {
1932         Object *ob= CTX_data_active_object(C);
1933         
1934         if (!ob || ob->id.lib) return 0;
1935         
1936         /* only meshes supported at the moment */
1937         if (ob->type == OB_MESH)
1938                 return ED_operator_screenactive(C);
1939         else
1940                 return 0;
1941 }
1942
1943 static int join_shapes_exec(bContext *C, wmOperator *op)
1944 {
1945         Scene *scene= CTX_data_scene(C);
1946         Object *ob= CTX_data_active_object(C);
1947         
1948         if(scene->obedit) {
1949                 BKE_report(op->reports, RPT_ERROR, "This data does not support joining in editmode.");
1950                 return OPERATOR_CANCELLED;
1951         }
1952         else if(object_data_is_libdata(ob)) {
1953                 BKE_report(op->reports, RPT_ERROR, "Can't edit external libdata.");
1954                 return OPERATOR_CANCELLED;
1955         }
1956         
1957         if(ob->type == OB_MESH)
1958                 return join_mesh_shapes_exec(C, op);
1959         
1960         return OPERATOR_CANCELLED;
1961 }
1962
1963 void OBJECT_OT_join_shapes(wmOperatorType *ot)
1964 {
1965         /* identifiers */
1966         ot->name= "Join as Shapes";
1967         ot->description = "Merge selected objects to shapes of active object";
1968         ot->idname= "OBJECT_OT_join_shapes";
1969         
1970         /* api callbacks */
1971         ot->exec= join_shapes_exec;
1972         ot->poll= join_shapes_poll;
1973         
1974         /* flags */
1975         ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
1976 }