Fix #32667: Curve softbodies doesn't render animation (cycles)
[blender.git] / source / blender / editors / object / object_edit.c
1 /*
2  * ***** BEGIN GPL LICENSE BLOCK *****
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License
6  * as published by the Free Software Foundation; either version 2
7  * of the License, or (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software Foundation,
16  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17  *
18  * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
19  * All rights reserved.
20  *
21  * Contributor(s): Blender Foundation, 2002-2008 full recode
22  *
23  * ***** END GPL LICENSE BLOCK *****
24  */
25
26 /** \file blender/editors/object/object_edit.c
27  *  \ingroup edobj
28  */
29
30 #include <stdlib.h>
31 #include <string.h>
32 #include <math.h>
33 #include <time.h>
34 #include <float.h>
35 #include <ctype.h>
36 #include <stddef.h> //for offsetof
37
38 #include "MEM_guardedalloc.h"
39
40 #include "BLI_blenlib.h"
41 #include "BLI_math.h"
42 #include "BLI_utildefines.h"
43 #include "BLI_ghash.h"
44 #include "BLI_rand.h"
45
46 #include "DNA_armature_types.h"
47 #include "DNA_curve_types.h"
48 #include "DNA_group_types.h"
49 #include "DNA_lattice_types.h"
50 #include "DNA_material_types.h"
51 #include "DNA_meta_types.h"
52 #include "DNA_property_types.h"
53 #include "DNA_scene_types.h"
54 #include "DNA_object_types.h"
55 #include "DNA_object_force.h"
56 #include "DNA_meshdata_types.h"
57 #include "DNA_vfont_types.h"
58 #include "DNA_mesh_types.h"
59
60 #include "IMB_imbuf_types.h"
61
62 #include "BKE_anim.h"
63 #include "BKE_constraint.h"
64 #include "BKE_context.h"
65 #include "BKE_curve.h"
66 #include "BKE_effect.h"
67 #include "BKE_depsgraph.h"
68 #include "BKE_font.h"
69 #include "BKE_image.h"
70 #include "BKE_library.h"
71 #include "BKE_main.h"
72 #include "BKE_material.h"
73 #include "BKE_mball.h"
74 #include "BKE_mesh.h"
75 #include "BKE_object.h"
76 #include "BKE_paint.h"
77 #include "BKE_pointcache.h"
78 #include "BKE_property.h"
79 #include "BKE_sca.h"
80 #include "BKE_softbody.h"
81 #include "BKE_modifier.h"
82 #include "BKE_tessmesh.h"
83
84 #include "ED_armature.h"
85 #include "ED_curve.h"
86 #include "ED_mesh.h"
87 #include "ED_mball.h"
88 #include "ED_lattice.h"
89 #include "ED_object.h"
90 #include "ED_screen.h"
91 #include "ED_util.h"
92 #include "ED_image.h"
93
94 #include "RNA_access.h"
95 #include "RNA_define.h"
96 #include "RNA_enum_types.h"
97
98 /* for menu/popup icons etc etc*/
99
100 #include "UI_interface.h"
101 #include "WM_api.h"
102 #include "WM_types.h"
103
104 #include "object_intern.h"  // own include
105
106 /* ************* XXX **************** */
107 static void error(const char *UNUSED(arg)) {}
108 static void waitcursor(int UNUSED(val)) {}
109 static int pupmenu(const char *UNUSED(msg)) { return 0; }
110
111 /* port over here */
112 static void error_libdata(void) {}
113
114 Object *ED_object_context(bContext *C)
115 {
116         return CTX_data_pointer_get_type(C, "object", &RNA_Object).data;
117 }
118
119 /* find the correct active object per context
120  * note: context can be NULL when called from a enum with PROP_ENUM_NO_CONTEXT */
121 Object *ED_object_active_context(bContext *C)
122 {
123         Object *ob = NULL;
124         if (C) {
125                 ob = ED_object_context(C);
126                 if (!ob) ob = CTX_data_active_object(C);
127         }
128         return ob;
129 }
130
131
132 /* ********* clear/set restrict view *********/
133 static int object_hide_view_clear_exec(bContext *C, wmOperator *UNUSED(op))
134 {
135         Main *bmain = CTX_data_main(C);
136         ScrArea *sa = CTX_wm_area(C);
137         View3D *v3d = sa->spacedata.first;
138         Scene *scene = CTX_data_scene(C);
139         Base *base;
140         int changed = 0;
141         
142         /* XXX need a context loop to handle such cases */
143         for (base = FIRSTBASE; base; base = base->next) {
144                 if ((base->lay & v3d->lay) && base->object->restrictflag & OB_RESTRICT_VIEW) {
145                         base->flag |= SELECT;
146                         base->object->flag = base->flag;
147                         base->object->restrictflag &= ~OB_RESTRICT_VIEW; 
148                         changed = 1;
149                 }
150         }
151         if (changed) {
152                 DAG_id_type_tag(bmain, ID_OB);
153                 DAG_scene_sort(bmain, scene);
154                 WM_event_add_notifier(C, NC_SCENE | ND_OB_SELECT, scene);
155         }
156
157         return OPERATOR_FINISHED;
158 }
159
160 void OBJECT_OT_hide_view_clear(wmOperatorType *ot)
161 {
162         
163         /* identifiers */
164         ot->name = "Clear Restrict View";
165         ot->description = "Reveal the object by setting the hide flag";
166         ot->idname = "OBJECT_OT_hide_view_clear";
167         
168         /* api callbacks */
169         ot->exec = object_hide_view_clear_exec;
170         ot->poll = ED_operator_view3d_active;
171         
172         /* flags */
173         ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
174 }
175
176 static int object_hide_view_set_exec(bContext *C, wmOperator *op)
177 {
178         Main *bmain = CTX_data_main(C);
179         Scene *scene = CTX_data_scene(C);
180         short changed = 0;
181         const int unselected = RNA_boolean_get(op->ptr, "unselected");
182         
183         CTX_DATA_BEGIN(C, Base *, base, visible_bases)
184         {
185                 if (!unselected) {
186                         if (base->flag & SELECT) {
187                                 base->flag &= ~SELECT;
188                                 base->object->flag = base->flag;
189                                 base->object->restrictflag |= OB_RESTRICT_VIEW;
190                                 changed = 1;
191                                 if (base == BASACT) {
192                                         ED_base_object_activate(C, NULL);
193                                 }
194                         }
195                 }
196                 else {
197                         if (!(base->flag & SELECT)) {
198                                 base->object->restrictflag |= OB_RESTRICT_VIEW;
199                                 changed = 1;
200                                 if (base == BASACT) {
201                                         ED_base_object_activate(C, NULL);
202                                 }
203                         }
204                 }       
205         }
206         CTX_DATA_END;
207
208         if (changed) {
209                 DAG_id_type_tag(bmain, ID_OB);
210                 DAG_scene_sort(bmain, scene);
211                 
212                 WM_event_add_notifier(C, NC_SCENE | ND_OB_SELECT, CTX_data_scene(C));
213                 
214         }
215
216         return OPERATOR_FINISHED;
217 }
218
219 void OBJECT_OT_hide_view_set(wmOperatorType *ot)
220 {
221         /* identifiers */
222         ot->name = "Set Restrict View";
223         ot->description = "Hide the object by setting the hide flag";
224         ot->idname = "OBJECT_OT_hide_view_set";
225         
226         /* api callbacks */
227         ot->exec = object_hide_view_set_exec;
228         ot->poll = ED_operator_view3d_active;
229         
230         /* flags */
231         ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
232         
233         RNA_def_boolean(ot->srna, "unselected", 0, "Unselected", "Hide unselected rather than selected objects");
234         
235 }
236
237 /* 99% same as above except no need for scene refreshing (TODO, update render preview) */
238 static int object_hide_render_clear_exec(bContext *C, wmOperator *UNUSED(op))
239 {
240         short changed = 0;
241
242         /* XXX need a context loop to handle such cases */
243         CTX_DATA_BEGIN(C, Object *, ob, selected_editable_objects)
244         {
245                 if (ob->restrictflag & OB_RESTRICT_RENDER) {
246                         ob->restrictflag &= ~OB_RESTRICT_RENDER;
247                         changed = 1;
248                 }
249         }
250         CTX_DATA_END;
251
252         if (changed)
253                 WM_event_add_notifier(C, NC_SPACE | ND_SPACE_OUTLINER, NULL);
254
255         return OPERATOR_FINISHED;
256 }
257
258 void OBJECT_OT_hide_render_clear(wmOperatorType *ot)
259 {
260
261         /* identifiers */
262         ot->name = "Clear Restrict Render";
263         ot->description = "Reveal the render object by setting the hide render flag";
264         ot->idname = "OBJECT_OT_hide_render_clear";
265
266         /* api callbacks */
267         ot->exec = object_hide_render_clear_exec;
268         ot->poll = ED_operator_view3d_active;
269
270         /* flags */
271         ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
272 }
273
274 static int object_hide_render_set_exec(bContext *C, wmOperator *op)
275 {
276         const int unselected = RNA_boolean_get(op->ptr, "unselected");
277
278         CTX_DATA_BEGIN(C, Base *, base, visible_bases)
279         {
280                 if (!unselected) {
281                         if (base->flag & SELECT) {
282                                 base->object->restrictflag |= OB_RESTRICT_RENDER;
283                         }
284                 }
285                 else {
286                         if (!(base->flag & SELECT)) {
287                                 base->object->restrictflag |= OB_RESTRICT_RENDER;
288                         }
289                 }
290         }
291         CTX_DATA_END;
292         WM_event_add_notifier(C, NC_SPACE | ND_SPACE_OUTLINER, NULL);
293         return OPERATOR_FINISHED;
294 }
295
296 void OBJECT_OT_hide_render_set(wmOperatorType *ot)
297 {
298         /* identifiers */
299         ot->name = "Set Restrict Render";
300         ot->description = "Hide the render object by setting the hide render flag";
301         ot->idname = "OBJECT_OT_hide_render_set";
302
303         /* api callbacks */
304         ot->exec = object_hide_render_set_exec;
305         ot->poll = ED_operator_view3d_active;
306
307         /* flags */
308         ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
309
310         RNA_def_boolean(ot->srna, "unselected", 0, "Unselected", "Hide unselected rather than selected objects");
311 }
312
313 /* ******************* toggle editmode operator  ***************** */
314
315 void ED_object_exit_editmode(bContext *C, int flag)
316 {
317         /* Note! only in exceptional cases should 'EM_DO_UNDO' NOT be in the flag */
318
319         Scene *scene = CTX_data_scene(C);
320         Object *obedit = CTX_data_edit_object(C);
321         int freedata = flag & EM_FREEDATA;
322         
323         if (obedit == NULL) return;
324         
325         if (flag & EM_WAITCURSOR) waitcursor(1);
326         if (obedit->type == OB_MESH) {
327                 Mesh *me = obedit->data;
328                 
329 //              if (EM_texFaceCheck())
330                 
331                 if (me->edit_btmesh->bm->totvert > MESH_MAX_VERTS) {
332                         error("Too many vertices");
333                         return;
334                 }
335                 
336                 EDBM_mesh_load(obedit);
337                 
338                 if (freedata) {
339                         EDBM_mesh_free(me->edit_btmesh);
340                         MEM_freeN(me->edit_btmesh);
341                         me->edit_btmesh = NULL;
342                 }
343                 if (obedit->restore_mode & OB_MODE_WEIGHT_PAINT) {
344                         mesh_octree_table(NULL, NULL, NULL, 'e');
345                         mesh_mirrtopo_table(NULL, 'e');
346                 }
347         }
348         else if (obedit->type == OB_ARMATURE) {
349                 ED_armature_from_edit(obedit);
350                 if (freedata)
351                         ED_armature_edit_free(obedit);
352         }
353         else if (ELEM(obedit->type, OB_CURVE, OB_SURF)) {
354                 load_editNurb(obedit);
355                 if (freedata) free_editNurb(obedit);
356         }
357         else if (obedit->type == OB_FONT && freedata) {
358                 load_editText(obedit);
359                 if (freedata) free_editText(obedit);
360         }
361         else if (obedit->type == OB_LATTICE) {
362                 load_editLatt(obedit);
363                 if (freedata) free_editLatt(obedit);
364         }
365         else if (obedit->type == OB_MBALL) {
366                 load_editMball(obedit);
367                 if (freedata) free_editMball(obedit);
368         }
369
370         /* freedata only 0 now on file saves and render */
371         if (freedata) {
372                 ListBase pidlist;
373                 PTCacheID *pid;
374
375                 /* for example; displist make is different in editmode */
376                 scene->obedit = NULL; // XXX for context
377
378                 /* flag object caches as outdated */
379                 BKE_ptcache_ids_from_object(&pidlist, obedit, NULL, 0);
380                 for (pid = pidlist.first; pid; pid = pid->next) {
381                         if (pid->type != PTCACHE_TYPE_PARTICLES) /* particles don't need reset on geometry change */
382                                 pid->cache->flag |= PTCACHE_OUTDATED;
383                 }
384                 BLI_freelistN(&pidlist);
385                 
386                 BKE_ptcache_object_reset(scene, obedit, PTCACHE_RESET_OUTDATED);
387
388                 /* also flush ob recalc, doesn't take much overhead, but used for particles */
389                 DAG_id_tag_update(&obedit->id, OB_RECALC_OB | OB_RECALC_DATA);
390         
391                 if (flag & EM_DO_UNDO)
392                         ED_undo_push(C, "Editmode");
393         
394                 if (flag & EM_WAITCURSOR) waitcursor(0);
395         
396                 WM_event_add_notifier(C, NC_SCENE | ND_MODE | NS_MODE_OBJECT, scene);
397
398                 obedit->mode &= ~OB_MODE_EDIT;
399         }
400 }
401
402
403 void ED_object_enter_editmode(bContext *C, int flag)
404 {
405         Scene *scene = CTX_data_scene(C);
406         Base *base = NULL;
407         Object *ob;
408         ScrArea *sa = CTX_wm_area(C);
409         View3D *v3d = NULL;
410         int ok = 0;
411
412         if (scene->id.lib) return;
413
414         if (sa && sa->spacetype == SPACE_VIEW3D)
415                 v3d = sa->spacedata.first;
416
417         if ((flag & EM_IGNORE_LAYER) == 0) {
418                 base = CTX_data_active_base(C); /* active layer checked here for view3d */
419
420                 if (base == NULL) return;
421                 else if (v3d && (base->lay & v3d->lay) == 0) return;
422                 else if (!v3d && (base->lay & scene->lay) == 0) return;
423         }
424         else {
425                 base = scene->basact;
426         }
427
428         if (ELEM3(NULL, base, base->object, base->object->data)) return;
429
430         ob = base->object;
431
432         if (BKE_object_obdata_is_libdata(ob)) {
433                 error_libdata();
434                 return;
435         }
436
437         if (flag & EM_WAITCURSOR) waitcursor(1);
438
439         ob->restore_mode = ob->mode;
440
441         /* note, when switching scenes the object can have editmode data but
442          * not be scene->obedit: bug 22954, this avoids calling self eternally */
443         if ((ob->restore_mode & OB_MODE_EDIT) == 0)
444                 ED_object_toggle_modes(C, ob->mode);
445
446         ob->mode = OB_MODE_EDIT;
447
448         if (ob->type == OB_MESH) {
449                 BMEditMesh *em;
450                 ok = 1;
451                 scene->obedit = ob;  /* context sees this */
452
453                 EDBM_mesh_make(CTX_data_tool_settings(C), scene, ob);
454
455                 em = BMEdit_FromObject(ob);
456                 if (LIKELY(em)) {
457                         /* order doesn't matter */
458                         EDBM_mesh_normals_update(em);
459                         BMEdit_RecalcTessellation(em);
460
461                         BM_mesh_select_mode_flush(em->bm);
462                 }
463
464                 WM_event_add_notifier(C, NC_SCENE | ND_MODE | NS_EDITMODE_MESH, scene);
465         }
466         else if (ob->type == OB_ARMATURE) {
467                 bArmature *arm = base->object->data;
468                 if (!arm) return;
469                 /*
470                  * The function BKE_object_obdata_is_libdata make a problem here, the
471                  * check for ob->proxy return 0 and let blender enter to edit mode
472                  * this causes a crash when you try leave the edit mode.
473                  * The problem is that i can't remove the ob->proxy check from
474                  * BKE_object_obdata_is_libdata that prevent the bugfix #6614, so
475                  * i add this little hack here.
476                  */
477                 if (arm->id.lib) {
478                         error_libdata();
479                         return;
480                 }
481                 ok = 1;
482                 scene->obedit = ob;
483                 ED_armature_to_edit(ob);
484                 /* to ensure all goes in restposition and without striding */
485                 DAG_id_tag_update(&ob->id, OB_RECALC_OB | OB_RECALC_DATA | OB_RECALC_TIME); /* XXX: should this be OB_RECALC_DATA? */
486
487                 WM_event_add_notifier(C, NC_SCENE | ND_MODE | NS_EDITMODE_ARMATURE, scene);
488         }
489         else if (ob->type == OB_FONT) {
490                 scene->obedit = ob; /* XXX for context */
491                 ok = 1;
492                 make_editText(ob);
493
494                 WM_event_add_notifier(C, NC_SCENE | ND_MODE | NS_EDITMODE_TEXT, scene);
495         }
496         else if (ob->type == OB_MBALL) {
497                 scene->obedit = ob; /* XXX for context */
498                 ok = 1;
499                 make_editMball(ob);
500
501                 WM_event_add_notifier(C, NC_SCENE | ND_MODE | NS_EDITMODE_MBALL, scene);
502         }
503         else if (ob->type == OB_LATTICE) {
504                 scene->obedit = ob; /* XXX for context */
505                 ok = 1;
506                 make_editLatt(ob);
507
508                 WM_event_add_notifier(C, NC_SCENE | ND_MODE | NS_EDITMODE_LATTICE, scene);
509         }
510         else if (ob->type == OB_SURF || ob->type == OB_CURVE) {
511                 ok = 1;
512                 scene->obedit = ob; /* XXX for context */
513                 make_editNurb(ob);
514
515                 WM_event_add_notifier(C, NC_SCENE | ND_MODE | NS_EDITMODE_CURVE, scene);
516         }
517
518         if (ok) {
519                 DAG_id_tag_update(&ob->id, OB_RECALC_DATA);
520         }
521         else {
522                 scene->obedit = NULL; /* XXX for context */
523                 ob->mode &= ~OB_MODE_EDIT;
524                 WM_event_add_notifier(C, NC_SCENE | ND_MODE | NS_MODE_OBJECT, scene);
525         }
526
527         if (flag & EM_DO_UNDO) ED_undo_push(C, "Enter Editmode");
528         if (flag & EM_WAITCURSOR) waitcursor(0);
529 }
530
531 static int editmode_toggle_exec(bContext *C, wmOperator *UNUSED(op))
532 {
533         ToolSettings *toolsettings =  CTX_data_tool_settings(C);
534
535         if (!CTX_data_edit_object(C))
536                 ED_object_enter_editmode(C, EM_WAITCURSOR);
537         else
538                 ED_object_exit_editmode(C, EM_FREEDATA | EM_FREEUNDO | EM_WAITCURSOR);  /* had EM_DO_UNDO but op flag calls undo too [#24685] */
539         
540         ED_space_image_uv_sculpt_update(CTX_wm_manager(C), toolsettings);
541
542         return OPERATOR_FINISHED;
543 }
544
545 static int editmode_toggle_poll(bContext *C)
546 {
547         Object *ob = CTX_data_active_object(C);
548
549         /* covers proxies too */
550         if (ELEM(NULL, ob, ob->data) || ((ID *)ob->data)->lib)
551                 return 0;
552
553         if (ob->restrictflag & OB_RESTRICT_VIEW)
554                 return 0;
555
556         return (ob->type == OB_MESH || ob->type == OB_ARMATURE ||
557                 ob->type == OB_FONT || ob->type == OB_MBALL ||
558                 ob->type == OB_LATTICE || ob->type == OB_SURF ||
559                 ob->type == OB_CURVE);
560 }
561
562 void OBJECT_OT_editmode_toggle(wmOperatorType *ot)
563 {
564         
565         /* identifiers */
566         ot->name = "Toggle Editmode";
567         ot->description = "Toggle object's editmode";
568         ot->idname = "OBJECT_OT_editmode_toggle";
569         
570         /* api callbacks */
571         ot->exec = editmode_toggle_exec;
572         
573         ot->poll = editmode_toggle_poll;
574         
575         /* flags */
576         ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
577 }
578
579 /* *************************** */
580
581 static int posemode_exec(bContext *C, wmOperator *UNUSED(op))
582 {
583         Base *base = CTX_data_active_base(C);
584         
585         if (base->object->type == OB_ARMATURE) {
586                 if (base->object == CTX_data_edit_object(C)) {
587                         ED_object_exit_editmode(C, EM_FREEDATA | EM_DO_UNDO);
588                         ED_armature_enter_posemode(C, base);
589                 }
590                 else if (base->object->mode & OB_MODE_POSE)
591                         ED_armature_exit_posemode(C, base);
592                 else
593                         ED_armature_enter_posemode(C, base);
594                 
595                 return OPERATOR_FINISHED;
596         }
597         
598         return OPERATOR_PASS_THROUGH;
599 }
600
601 void OBJECT_OT_posemode_toggle(wmOperatorType *ot) 
602 {
603         /* identifiers */
604         ot->name = "Toggle Pose Mode";
605         ot->idname = "OBJECT_OT_posemode_toggle";
606         ot->description = "Enable or disable posing/selecting bones";
607         
608         /* api callbacks */
609         ot->exec = posemode_exec;
610         ot->poll = ED_operator_object_active_editable;
611         
612         /* flag */
613         ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
614 }
615
616 static void copymenu_properties(Scene *scene, View3D *v3d, Object *ob)
617 {       
618 //XXX no longer used - to be removed - replaced by game_properties_copy_exec
619         bProperty *prop;
620         Base *base;
621         int nr, tot = 0;
622         char *str;
623         
624         prop = ob->prop.first;
625         while (prop) {
626                 tot++;
627                 prop = prop->next;
628         }
629         
630         str = MEM_callocN(50 + 33 * tot, "copymenu prop");
631         
632         if (tot)
633                 strcpy(str, "Copy Property %t|Replace All|Merge All|%l");
634         else
635                 strcpy(str, "Copy Property %t|Clear All (no properties on active)");
636         
637         tot = 0;
638         prop = ob->prop.first;
639         while (prop) {
640                 tot++;
641                 strcat(str, "|");
642                 strcat(str, prop->name);
643                 prop = prop->next;
644         }
645
646         nr = pupmenu(str);
647         
648         if (nr == 1 || nr == 2) {
649                 for (base = FIRSTBASE; base; base = base->next) {
650                         if ((base != BASACT) && (TESTBASELIB(v3d, base))) {
651                                 if (nr == 1) { /* replace */
652                                         BKE_bproperty_copy_list(&base->object->prop, &ob->prop);
653                                 }
654                                 else {
655                                         for (prop = ob->prop.first; prop; prop = prop->next) {
656                                                 BKE_bproperty_object_set(base->object, prop);
657                                         }
658                                 }
659                         }
660                 }
661         }
662         else if (nr > 0) {
663                 prop = BLI_findlink(&ob->prop, nr - 4); /* account for first 3 menu items & menu index starting at 1*/
664                 
665                 if (prop) {
666                         for (base = FIRSTBASE; base; base = base->next) {
667                                 if ((base != BASACT) && (TESTBASELIB(v3d, base))) {
668                                         BKE_bproperty_object_set(base->object, prop);
669                                 }
670                         }
671                 }
672         }
673         MEM_freeN(str);
674         
675 }
676
677 static void copymenu_logicbricks(Scene *scene, View3D *v3d, Object *ob)
678 {
679 //XXX no longer used - to be removed - replaced by logicbricks_copy_exec
680         Base *base;
681         
682         for (base = FIRSTBASE; base; base = base->next) {
683                 if (base->object != ob) {
684                         if (TESTBASELIB(v3d, base)) {
685                                 
686                                 /* first: free all logic */
687                                 free_sensors(&base->object->sensors);                           
688                                 unlink_controllers(&base->object->controllers);
689                                 free_controllers(&base->object->controllers);
690                                 unlink_actuators(&base->object->actuators);
691                                 free_actuators(&base->object->actuators);
692                                 
693                                 /* now copy it, this also works without logicbricks! */
694                                 clear_sca_new_poins_ob(ob);
695                                 copy_sensors(&base->object->sensors, &ob->sensors);
696                                 copy_controllers(&base->object->controllers, &ob->controllers);
697                                 copy_actuators(&base->object->actuators, &ob->actuators);
698                                 set_sca_new_poins_ob(base->object);
699                                 
700                                 /* some menu settings */
701                                 base->object->scavisflag = ob->scavisflag;
702                                 base->object->scaflag = ob->scaflag;
703                                 
704                                 /* set the initial state */
705                                 base->object->state = ob->state;
706                                 base->object->init_state = ob->init_state;
707                         }
708                 }
709         }
710 }
711
712 /* both pointers should exist */
713 static void copy_texture_space(Object *to, Object *ob)
714 {
715         float *poin1 = NULL, *poin2 = NULL;
716         short texflag = 0;
717         
718         if (ob->type == OB_MESH) {
719                 texflag = ((Mesh *)ob->data)->texflag;
720                 poin2 = ((Mesh *)ob->data)->loc;
721         }
722         else if (ELEM3(ob->type, OB_CURVE, OB_SURF, OB_FONT)) {
723                 texflag = ((Curve *)ob->data)->texflag;
724                 poin2 = ((Curve *)ob->data)->loc;
725         }
726         else if (ob->type == OB_MBALL) {
727                 texflag = ((MetaBall *)ob->data)->texflag;
728                 poin2 = ((MetaBall *)ob->data)->loc;
729         }
730         else
731                 return;
732                 
733         if (to->type == OB_MESH) {
734                 ((Mesh *)to->data)->texflag = texflag;
735                 poin1 = ((Mesh *)to->data)->loc;
736         }
737         else if (ELEM3(to->type, OB_CURVE, OB_SURF, OB_FONT)) {
738                 ((Curve *)to->data)->texflag = texflag;
739                 poin1 = ((Curve *)to->data)->loc;
740         }
741         else if (to->type == OB_MBALL) {
742                 ((MetaBall *)to->data)->texflag = texflag;
743                 poin1 = ((MetaBall *)to->data)->loc;
744         }
745         else
746                 return;
747         
748         memcpy(poin1, poin2, 9 * sizeof(float));  /* this was noted in DNA_mesh, curve, mball */
749         
750         if (to->type == OB_MESH) {
751                 /* pass */
752         }
753         else if (to->type == OB_MBALL) {
754                 BKE_mball_texspace_calc(to);
755         }
756         else {
757                 BKE_curve_texspace_calc(to->data);
758         }
759         
760 }
761
762 /* UNUSED, keep in case we want to copy functionality for use elsewhere */
763 static void copy_attr(Main *bmain, Scene *scene, View3D *v3d, short event)
764 {
765         Object *ob;
766         Base *base;
767         Curve *cu, *cu1;
768         Nurb *nu;
769         int do_scene_sort = FALSE;
770         
771         if (scene->id.lib) return;
772
773         if (!(ob = OBACT)) return;
774         
775         if (scene->obedit) { // XXX get from context
776                 /* obedit_copymenu(); */
777                 return;
778         }
779         if (event == 9) {
780                 copymenu_properties(scene, v3d, ob);
781                 return;
782         }
783         else if (event == 10) {
784                 copymenu_logicbricks(scene, v3d, ob);
785                 return;
786         }
787         else if (event == 24) {
788                 /* moved to BKE_object_link_modifiers */
789                 /* copymenu_modifiers(bmain, scene, v3d, ob); */
790                 return;
791         }
792
793         for (base = FIRSTBASE; base; base = base->next) {
794                 if (base != BASACT) {
795                         if (TESTBASELIB(v3d, base)) {
796                                 base->object->recalc |= OB_RECALC_OB;
797                                 
798                                 if (event == 1) {  /* loc */
799                                         copy_v3_v3(base->object->loc, ob->loc);
800                                         copy_v3_v3(base->object->dloc, ob->dloc);
801                                 }
802                                 else if (event == 2) {  /* rot */
803                                         copy_v3_v3(base->object->rot, ob->rot);
804                                         copy_v3_v3(base->object->drot, ob->drot);
805
806                                         copy_qt_qt(base->object->quat, ob->quat);
807                                         copy_qt_qt(base->object->dquat, ob->dquat);
808                                 }
809                                 else if (event == 3) {  /* size */
810                                         copy_v3_v3(base->object->size, ob->size);
811                                         copy_v3_v3(base->object->dscale, ob->dscale);
812                                 }
813                                 else if (event == 4) {  /* drawtype */
814                                         base->object->dt = ob->dt;
815                                         base->object->dtx = ob->dtx;
816                                         base->object->empty_drawtype = ob->empty_drawtype;
817                                         base->object->empty_drawsize = ob->empty_drawsize;
818                                 }
819                                 else if (event == 5) {  /* time offs */
820                                         base->object->sf = ob->sf;
821                                 }
822                                 else if (event == 6) {  /* dupli */
823                                         base->object->dupon = ob->dupon;
824                                         base->object->dupoff = ob->dupoff;
825                                         base->object->dupsta = ob->dupsta;
826                                         base->object->dupend = ob->dupend;
827                                         
828                                         base->object->transflag &= ~OB_DUPLI;
829                                         base->object->transflag |= (ob->transflag & OB_DUPLI);
830
831                                         base->object->dup_group = ob->dup_group;
832                                         if (ob->dup_group)
833                                                 id_lib_extern(&ob->dup_group->id);
834                                 }
835                                 else if (event == 7) {    /* mass */
836                                         base->object->mass = ob->mass;
837                                 }
838                                 else if (event == 8) {    /* damping */
839                                         base->object->damping = ob->damping;
840                                         base->object->rdamping = ob->rdamping;
841                                 }
842                                 else if (event == 11) {   /* all physical attributes */
843                                         base->object->gameflag = ob->gameflag;
844                                         base->object->inertia = ob->inertia;
845                                         base->object->formfactor = ob->formfactor;
846                                         base->object->damping = ob->damping;
847                                         base->object->rdamping = ob->rdamping;
848                                         base->object->min_vel = ob->min_vel;
849                                         base->object->max_vel = ob->max_vel;
850                                         if (ob->gameflag & OB_BOUNDS) {
851                                                 base->object->collision_boundtype = ob->collision_boundtype;
852                                         }
853                                         base->object->margin = ob->margin;
854                                         base->object->bsoft = copy_bulletsoftbody(ob->bsoft);
855
856                                 }
857                                 else if (event == 17) {   /* tex space */
858                                         copy_texture_space(base->object, ob);
859                                 }
860                                 else if (event == 18) {   /* font settings */
861                                         
862                                         if (base->object->type == ob->type) {
863                                                 cu = ob->data;
864                                                 cu1 = base->object->data;
865
866                                                 cu1->spacemode = cu->spacemode;
867                                                 cu1->spacing = cu->spacing;
868                                                 cu1->linedist = cu->linedist;
869                                                 cu1->shear = cu->shear;
870                                                 cu1->fsize = cu->fsize;
871                                                 cu1->xof = cu->xof;
872                                                 cu1->yof = cu->yof;
873                                                 cu1->textoncurve = cu->textoncurve;
874                                                 cu1->wordspace = cu->wordspace;
875                                                 cu1->ulpos = cu->ulpos;
876                                                 cu1->ulheight = cu->ulheight;
877                                                 if (cu1->vfont) cu1->vfont->id.us--;
878                                                 cu1->vfont = cu->vfont;
879                                                 id_us_plus((ID *)cu1->vfont);
880                                                 if (cu1->vfontb) cu1->vfontb->id.us--;
881                                                 cu1->vfontb = cu->vfontb;
882                                                 id_us_plus((ID *)cu1->vfontb);
883                                                 if (cu1->vfonti) cu1->vfonti->id.us--;
884                                                 cu1->vfonti = cu->vfonti;
885                                                 id_us_plus((ID *)cu1->vfonti);
886                                                 if (cu1->vfontbi) cu1->vfontbi->id.us--;
887                                                 cu1->vfontbi = cu->vfontbi;
888                                                 id_us_plus((ID *)cu1->vfontbi);                                         
889
890                                                 BKE_vfont_to_curve(bmain, scene, base->object, 0); /* needed? */
891
892                                                 
893                                                 BLI_strncpy(cu1->family, cu->family, sizeof(cu1->family));
894                                                 
895                                                 base->object->recalc |= OB_RECALC_DATA;
896                                         }
897                                 }
898                                 else if (event == 19) {   /* bevel settings */
899                                         
900                                         if (ELEM(base->object->type, OB_CURVE, OB_FONT)) {
901                                                 cu = ob->data;
902                                                 cu1 = base->object->data;
903                                                 
904                                                 cu1->bevobj = cu->bevobj;
905                                                 cu1->taperobj = cu->taperobj;
906                                                 cu1->width = cu->width;
907                                                 cu1->bevresol = cu->bevresol;
908                                                 cu1->ext1 = cu->ext1;
909                                                 cu1->ext2 = cu->ext2;
910                                                 
911                                                 base->object->recalc |= OB_RECALC_DATA;
912                                         }
913                                 }
914                                 else if (event == 25) {   /* curve resolution */
915
916                                         if (ELEM(base->object->type, OB_CURVE, OB_FONT)) {
917                                                 cu = ob->data;
918                                                 cu1 = base->object->data;
919                                                 
920                                                 cu1->resolu = cu->resolu;
921                                                 cu1->resolu_ren = cu->resolu_ren;
922                                                 
923                                                 nu = cu1->nurb.first;
924                                                 
925                                                 while (nu) {
926                                                         nu->resolu = cu1->resolu;
927                                                         nu = nu->next;
928                                                 }
929                                                 
930                                                 base->object->recalc |= OB_RECALC_DATA;
931                                         }
932                                 }
933                                 else if (event == 21) {
934                                         if (base->object->type == OB_MESH) {
935                                                 ModifierData *md = modifiers_findByType(ob, eModifierType_Subsurf);
936
937                                                 if (md) {
938                                                         ModifierData *tmd = modifiers_findByType(base->object, eModifierType_Subsurf);
939
940                                                         if (!tmd) {
941                                                                 tmd = modifier_new(eModifierType_Subsurf);
942                                                                 BLI_addtail(&base->object->modifiers, tmd);
943                                                         }
944
945                                                         modifier_copyData(md, tmd);
946                                                         base->object->recalc |= OB_RECALC_DATA;
947                                                 }
948                                         }
949                                 }
950                                 else if (event == 22) {
951                                         /* Copy the constraint channels over */
952                                         copy_constraints(&base->object->constraints, &ob->constraints, TRUE);
953                                         
954                                         do_scene_sort = TRUE;
955                                 }
956                                 else if (event == 23) {
957                                         base->object->softflag = ob->softflag;
958                                         if (base->object->soft) sbFree(base->object->soft);
959                                         
960                                         base->object->soft = copy_softbody(ob->soft, FALSE);
961
962                                         if (!modifiers_findByType(base->object, eModifierType_Softbody)) {
963                                                 BLI_addhead(&base->object->modifiers, modifier_new(eModifierType_Softbody));
964                                         }
965                                 }
966                                 else if (event == 26) {
967 #if 0 // XXX old animation system
968                                         copy_nlastrips(&base->object->nlastrips, &ob->nlastrips);
969 #endif // XXX old animation system
970                                 }
971                                 else if (event == 27) {   /* autosmooth */
972                                         if (base->object->type == OB_MESH) {
973                                                 Mesh *me = ob->data;
974                                                 Mesh *cme = base->object->data;
975                                                 cme->smoothresh = me->smoothresh;
976                                                 if (me->flag & ME_AUTOSMOOTH)
977                                                         cme->flag |= ME_AUTOSMOOTH;
978                                                 else
979                                                         cme->flag &= ~ME_AUTOSMOOTH;
980                                         }
981                                 }
982                                 else if (event == 28) { /* UV orco */
983                                         if (ELEM(base->object->type, OB_CURVE, OB_SURF)) {
984                                                 cu = ob->data;
985                                                 cu1 = base->object->data;
986                                                 
987                                                 if (cu->flag & CU_UV_ORCO)
988                                                         cu1->flag |= CU_UV_ORCO;
989                                                 else
990                                                         cu1->flag &= ~CU_UV_ORCO;
991                                         }               
992                                 }
993                                 else if (event == 29) { /* protected bits */
994                                         base->object->protectflag = ob->protectflag;
995                                 }
996                                 else if (event == 30) { /* index object */
997                                         base->object->index = ob->index;
998                                 }
999                                 else if (event == 31) { /* object color */
1000                                         copy_v4_v4(base->object->col, ob->col);
1001                                 }
1002                         }
1003                 }
1004         }
1005         
1006         if (do_scene_sort)
1007                 DAG_scene_sort(bmain, scene);
1008
1009         DAG_ids_flush_update(bmain, 0);
1010 }
1011
1012 static void UNUSED_FUNCTION(copy_attr_menu) (Main * bmain, Scene * scene, View3D * v3d)
1013 {
1014         Object *ob;
1015         short event;
1016         char str[512];
1017         
1018         if (!(ob = OBACT)) return;
1019         
1020         if (scene->obedit) { // XXX get from context
1021 //              if (ob->type == OB_MESH)
1022 // XXX                  mesh_copy_menu();
1023                 return;
1024         }
1025         
1026         /* Object Mode */
1027         
1028         /* If you change this menu, don't forget to update the menu in header_view3d.c
1029          * view3d_edit_object_copyattrmenu() and in toolbox.c
1030          */
1031         
1032         strcpy(str,
1033                "Copy Attributes %t|Location%x1|Rotation%x2|Size%x3|Draw Options%x4|"
1034                "Time Offset%x5|Dupli%x6|Object Color%x31|%l|Mass%x7|Damping%x8|All Physical Attributes%x11|Properties%x9|"
1035                "Logic Bricks%x10|Protected Transform%x29|%l");
1036         
1037         strcat(str, "|Object Constraints%x22");
1038         strcat(str, "|NLA Strips%x26");
1039         
1040 // XXX  if (OB_TYPE_SUPPORT_MATERIAL(ob->type)) {
1041 //              strcat(str, "|Texture Space%x17");
1042 //      }       
1043         
1044         if (ob->type == OB_FONT) strcat(str, "|Font Settings%x18|Bevel Settings%x19");
1045         if (ob->type == OB_CURVE) strcat(str, "|Bevel Settings%x19|UV Orco%x28");
1046         
1047         if ((ob->type == OB_FONT) || (ob->type == OB_CURVE)) {
1048                 strcat(str, "|Curve Resolution%x25");
1049         }
1050
1051         if (ob->type == OB_MESH) {
1052                 strcat(str, "|Subsurf Settings%x21|AutoSmooth%x27");
1053         }
1054
1055         if (ob->soft) strcat(str, "|Soft Body Settings%x23");
1056         
1057         strcat(str, "|Pass Index%x30");
1058         
1059         if (ob->type == OB_MESH || ob->type == OB_CURVE || ob->type == OB_LATTICE || ob->type == OB_SURF) {
1060                 strcat(str, "|Modifiers ...%x24");
1061         }
1062
1063         event = pupmenu(str);
1064         if (event <= 0) return;
1065         
1066         copy_attr(bmain, scene, v3d, event);
1067 }
1068
1069 /* ******************* force field toggle operator ***************** */
1070
1071 static int forcefield_toggle_exec(bContext *C, wmOperator *UNUSED(op))
1072 {
1073         Object *ob = CTX_data_active_object(C);
1074
1075         if (ob->pd == NULL)
1076                 ob->pd = object_add_collision_fields(PFIELD_FORCE);
1077
1078         if (ob->pd->forcefield == 0)
1079                 ob->pd->forcefield = PFIELD_FORCE;
1080         else
1081                 ob->pd->forcefield = 0;
1082         
1083         WM_event_add_notifier(C, NC_OBJECT | ND_DRAW, NULL);
1084
1085         return OPERATOR_FINISHED;
1086 }
1087
1088 void OBJECT_OT_forcefield_toggle(wmOperatorType *ot)
1089 {
1090         
1091         /* identifiers */
1092         ot->name = "Toggle Force Field";
1093         ot->description = "Toggle object's force field";
1094         ot->idname = "OBJECT_OT_forcefield_toggle";
1095         
1096         /* api callbacks */
1097         ot->exec = forcefield_toggle_exec;
1098         ot->poll = ED_operator_object_active_editable;
1099         
1100         /* flags */
1101         ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
1102 }
1103
1104 /* ********************************************** */
1105 /* Motion Paths */
1106
1107 /* For the objects with animation: update paths for those that have got them
1108  * This should selectively update paths that exist...
1109  *
1110  * To be called from various tools that do incremental updates 
1111  */
1112 void ED_objects_recalculate_paths(bContext *C, Scene *scene)
1113 {
1114         ListBase targets = {NULL, NULL};
1115         
1116         /* loop over objects in scene */
1117         CTX_DATA_BEGIN(C, Object *, ob, selected_editable_objects)
1118         {
1119                 /* set flag to force recalc, then grab path(s) from object */
1120                 ob->avs.recalc |= ANIMVIZ_RECALC_PATHS;
1121                 animviz_get_object_motionpaths(ob, &targets);
1122         }
1123         CTX_DATA_END;
1124         
1125         /* recalculate paths, then free */
1126         animviz_calc_motionpaths(scene, &targets);
1127         BLI_freelistN(&targets);
1128 }
1129
1130
1131 /* show popup to determine settings */
1132 static int object_calculate_paths_invoke(bContext *C, wmOperator *op, wmEvent *UNUSED(event))
1133 {
1134         Object *ob = CTX_data_active_object(C);
1135         
1136         if (ob == NULL)
1137                 return OPERATOR_CANCELLED;
1138         
1139         /* set default settings from existing/stored settings */
1140         {
1141                 bAnimVizSettings *avs = &ob->avs;
1142                 
1143                 RNA_int_set(op->ptr, "start_frame", avs->path_sf);
1144                 RNA_int_set(op->ptr, "end_frame", avs->path_ef);
1145         }
1146         
1147         /* show popup dialog to allow editing of range... */
1148         /* FIXME: hardcoded dimensions here are just arbitrary */
1149         return WM_operator_props_dialog_popup(C, op, 200, 200);
1150 }
1151
1152 /* Calculate/recalculate whole paths (avs.path_sf to avs.path_ef) */
1153 static int object_calculate_paths_exec(bContext *C, wmOperator *op)
1154 {
1155         Scene *scene = CTX_data_scene(C);
1156         int start = RNA_int_get(op->ptr, "start_frame");
1157         int end = RNA_int_get(op->ptr, "end_frame");
1158         
1159         /* set up path data for bones being calculated */
1160         CTX_DATA_BEGIN(C, Object *, ob, selected_editable_objects)
1161         {
1162                 bAnimVizSettings *avs = &ob->avs;
1163                 
1164                 /* grab baking settings from operator settings */
1165                 avs->path_sf = start;
1166                 avs->path_ef = end;
1167                 
1168                 /* verify that the selected object has the appropriate settings */
1169                 animviz_verify_motionpaths(op->reports, scene, ob, NULL);
1170         }
1171         CTX_DATA_END;
1172         
1173         /* calculate the paths for objects that have them (and are tagged to get refreshed) */
1174         ED_objects_recalculate_paths(C, scene);
1175         
1176         /* notifiers for updates */
1177         WM_event_add_notifier(C, NC_OBJECT | ND_TRANSFORM, NULL);
1178         
1179         return OPERATOR_FINISHED; 
1180 }
1181
1182 void OBJECT_OT_paths_calculate(wmOperatorType *ot)
1183 {
1184         /* identifiers */
1185         ot->name = "Calculate Object Paths";
1186         ot->idname = "OBJECT_OT_paths_calculate";
1187         ot->description = "Calculate motion paths for the selected objects";
1188         
1189         /* api callbacks */
1190         ot->invoke = object_calculate_paths_invoke;
1191         ot->exec = object_calculate_paths_exec;
1192         ot->poll = ED_operator_object_active_editable;
1193         
1194         /* flags */
1195         ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
1196         
1197         /* properties */
1198         RNA_def_int(ot->srna, "start_frame", 1, MINAFRAME, MAXFRAME, "Start", 
1199                     "First frame to calculate object paths on", MINFRAME, MAXFRAME / 2.0);
1200         RNA_def_int(ot->srna, "end_frame", 250, MINAFRAME, MAXFRAME, "End", 
1201                     "Last frame to calculate object paths on", MINFRAME, MAXFRAME / 2.0);
1202 }
1203
1204 /* --------- */
1205
1206 static int object_update_paths_exec(bContext *C, wmOperator *UNUSED(op))
1207 {
1208         Scene *scene = CTX_data_scene(C);
1209         
1210         if (scene == NULL)
1211                 return OPERATOR_CANCELLED;
1212                 
1213         /* calculate the paths for objects that have them (and are tagged to get refreshed) */
1214         ED_objects_recalculate_paths(C, scene);
1215         
1216         /* notifiers for updates */
1217         WM_event_add_notifier(C, NC_OBJECT | ND_TRANSFORM, NULL);
1218         
1219         return OPERATOR_FINISHED;
1220 }
1221
1222 void OBJECT_OT_paths_update(wmOperatorType *ot)
1223 {
1224         /* identifiers */
1225         ot->name = "Update Object Paths";
1226         ot->idname = "OBJECT_OT_paths_update";
1227         ot->description = "Recalculate paths for selected objects";
1228         
1229         /* api callbakcs */
1230         ot->exec = object_update_paths_exec;
1231         ot->poll = ED_operator_object_active_editable; /* TODO: this should probably check for existing paths */
1232         
1233         /* flags */
1234         ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
1235 }
1236
1237 /* --------- */
1238
1239 /* Clear motion paths for selected objects only */
1240 void ED_objects_clear_paths(bContext *C)
1241 {
1242         /* loop over objects in scene */
1243         CTX_DATA_BEGIN(C, Object *, ob, selected_editable_objects)
1244         {
1245                 if (ob->mpath) {
1246                         animviz_free_motionpath(ob->mpath);
1247                         ob->mpath = NULL;
1248                         ob->avs.path_bakeflag &= ~MOTIONPATH_BAKE_HAS_PATHS;
1249                 }
1250         }
1251         CTX_DATA_END;
1252 }
1253
1254 /* operator callback for this */
1255 static int object_clear_paths_exec(bContext *C, wmOperator *UNUSED(op))
1256 {       
1257         /* use the backend function for this */
1258         ED_objects_clear_paths(C);
1259         
1260         /* notifiers for updates */
1261         WM_event_add_notifier(C, NC_OBJECT | ND_TRANSFORM, NULL);
1262         
1263         return OPERATOR_FINISHED; 
1264 }
1265
1266 void OBJECT_OT_paths_clear(wmOperatorType *ot)
1267 {
1268         /* identifiers */
1269         ot->name = "Clear Object Paths";
1270         ot->idname = "OBJECT_OT_paths_clear";
1271         ot->description = "Clear path caches for selected objects";
1272         
1273         /* api callbacks */
1274         ot->exec = object_clear_paths_exec;
1275         ot->poll = ED_operator_object_active_editable;
1276         
1277         /* flags */
1278         ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
1279 }
1280
1281
1282 /********************** Smooth/Flat *********************/
1283
1284 static int shade_smooth_exec(bContext *C, wmOperator *op)
1285 {
1286         Curve *cu;
1287         Nurb *nu;
1288         int clear = (strcmp(op->idname, "OBJECT_OT_shade_flat") == 0);
1289         int done = FALSE;
1290
1291         CTX_DATA_BEGIN(C, Object *, ob, selected_editable_objects)
1292         {
1293
1294                 if (ob->type == OB_MESH) {
1295                         BKE_mesh_smooth_flag_set(ob, !clear);
1296
1297                         DAG_id_tag_update(&ob->id, OB_RECALC_DATA);
1298                         WM_event_add_notifier(C, NC_OBJECT | ND_DRAW, ob);
1299
1300                         done = TRUE;
1301                 }
1302                 else if (ELEM(ob->type, OB_SURF, OB_CURVE)) {
1303                         cu = ob->data;
1304
1305                         for (nu = cu->nurb.first; nu; nu = nu->next) {
1306                                 if (!clear) nu->flag |= ME_SMOOTH;
1307                                 else nu->flag &= ~ME_SMOOTH;
1308                         }
1309
1310                         DAG_id_tag_update(&ob->id, OB_RECALC_DATA);
1311                         WM_event_add_notifier(C, NC_OBJECT | ND_DRAW, ob);
1312
1313                         done = TRUE;
1314                 }
1315         }
1316         CTX_DATA_END;
1317
1318         return (done) ? OPERATOR_FINISHED : OPERATOR_CANCELLED;
1319 }
1320
1321 static int shade_poll(bContext *C)
1322 {
1323         return (ED_operator_object_active_editable(C) && !ED_operator_editmesh(C));
1324 }
1325
1326 void OBJECT_OT_shade_flat(wmOperatorType *ot)
1327 {
1328         /* identifiers */
1329         ot->name = "Shade Flat";
1330         ot->description = "Display faces 'flat'";
1331         ot->idname = "OBJECT_OT_shade_flat";
1332         
1333         /* api callbacks */
1334         ot->poll = shade_poll;
1335         ot->exec = shade_smooth_exec;
1336
1337         /* flags */
1338         ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
1339 }
1340
1341 void OBJECT_OT_shade_smooth(wmOperatorType *ot)
1342 {
1343         /* identifiers */
1344         ot->name = "Shade Smooth";
1345         ot->description = "Display faces 'smooth' (using vertex normals)";
1346         ot->idname = "OBJECT_OT_shade_smooth";
1347         
1348         /* api callbacks */
1349         ot->poll = shade_poll;
1350         ot->exec = shade_smooth_exec;
1351         
1352         /* flags */
1353         ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
1354 }
1355
1356 /* ********************** */
1357
1358 static void UNUSED_FUNCTION(image_aspect) (Scene * scene, View3D * v3d)
1359 {
1360         /* all selected objects with an image map: scale in image aspect */
1361         Base *base;
1362         Object *ob;
1363         Material *ma;
1364         Tex *tex;
1365         float x, y, space;
1366         int a, b, done;
1367         
1368         if (scene->obedit) return;  // XXX get from context
1369         if (scene->id.lib) return;
1370         
1371         for (base = FIRSTBASE; base; base = base->next) {
1372                 if (TESTBASELIB(v3d, base)) {
1373                         ob = base->object;
1374                         done = FALSE;
1375                         
1376                         for (a = 1; a <= ob->totcol; a++) {
1377                                 ma = give_current_material(ob, a);
1378                                 if (ma) {
1379                                         for (b = 0; b < MAX_MTEX; b++) {
1380                                                 if (ma->mtex[b] && ma->mtex[b]->tex) {
1381                                                         tex = ma->mtex[b]->tex;
1382                                                         if (tex->type == TEX_IMAGE && tex->ima) {
1383                                                                 ImBuf *ibuf = BKE_image_get_ibuf(tex->ima, NULL);
1384                                                                 
1385                                                                 /* texturespace */
1386                                                                 space = 1.0;
1387                                                                 if (ob->type == OB_MESH) {
1388                                                                         float size[3];
1389                                                                         BKE_mesh_texspace_get(ob->data, NULL, NULL, size);
1390                                                                         space = size[0] / size[1];
1391                                                                 }
1392                                                                 else if (ELEM3(ob->type, OB_CURVE, OB_FONT, OB_SURF)) {
1393                                                                         Curve *cu = ob->data;
1394                                                                         space = cu->size[0] / cu->size[1];
1395                                                                 }
1396                                                         
1397                                                                 x = ibuf->x / space;
1398                                                                 y = ibuf->y;
1399                                                                 
1400                                                                 if (x > y) ob->size[0] = ob->size[1] * x / y;
1401                                                                 else ob->size[1] = ob->size[0] * y / x;
1402                                                                 
1403                                                                 done = TRUE;
1404                                                                 DAG_id_tag_update(&ob->id, OB_RECALC_OB);                                                               
1405                                                         }
1406                                                 }
1407                                                 if (done) break;
1408                                         }
1409                                 }
1410                                 if (done) break;
1411                         }
1412                 }
1413         }
1414         
1415 }
1416
1417
1418 static EnumPropertyItem *object_mode_set_itemsf(bContext *C, PointerRNA *UNUSED(ptr), PropertyRNA *UNUSED(prop), int *free)
1419 {       
1420         EnumPropertyItem *input = object_mode_items;
1421         EnumPropertyItem *item = NULL;
1422         Object *ob;
1423         int totitem = 0;
1424         
1425         if (!C) /* needed for docs */
1426                 return object_mode_items;
1427
1428
1429
1430         ob = CTX_data_active_object(C);
1431         while (ob && input->identifier) {
1432                 if ((input->value == OB_MODE_EDIT && OB_TYPE_SUPPORT_EDITMODE(ob->type)) ||
1433                     (input->value == OB_MODE_POSE && (ob->type == OB_ARMATURE)) ||
1434                     (input->value == OB_MODE_PARTICLE_EDIT && ob->particlesystem.first) ||
1435                     ((input->value == OB_MODE_SCULPT || input->value == OB_MODE_VERTEX_PAINT ||
1436                       input->value == OB_MODE_WEIGHT_PAINT || input->value == OB_MODE_TEXTURE_PAINT) && (ob->type == OB_MESH)) ||
1437                     (input->value == OB_MODE_OBJECT))
1438                 {
1439                         RNA_enum_item_add(&item, &totitem, input);
1440                 }
1441                 input++;
1442         }
1443
1444         RNA_enum_item_end(&item, &totitem);
1445
1446         *free = 1;
1447
1448         return item;
1449 }
1450
1451 static const char *object_mode_op_string(int mode)
1452 {
1453         if (mode & OB_MODE_EDIT)
1454                 return "OBJECT_OT_editmode_toggle";
1455         if (mode == OB_MODE_SCULPT)
1456                 return "SCULPT_OT_sculptmode_toggle";
1457         if (mode == OB_MODE_VERTEX_PAINT)
1458                 return "PAINT_OT_vertex_paint_toggle";
1459         if (mode == OB_MODE_WEIGHT_PAINT)
1460                 return "PAINT_OT_weight_paint_toggle";
1461         if (mode == OB_MODE_TEXTURE_PAINT)
1462                 return "PAINT_OT_texture_paint_toggle";
1463         if (mode == OB_MODE_PARTICLE_EDIT)
1464                 return "PARTICLE_OT_particle_edit_toggle";
1465         if (mode == OB_MODE_POSE)
1466                 return "OBJECT_OT_posemode_toggle";
1467         return NULL;
1468 }
1469
1470 /* checks the mode to be set is compatible with the object
1471  * should be made into a generic function */
1472 static int object_mode_set_compat(bContext *UNUSED(C), wmOperator *op, Object *ob)
1473 {
1474         ObjectMode mode = RNA_enum_get(op->ptr, "mode");
1475
1476         if (ob) {
1477                 if (mode == OB_MODE_OBJECT)
1478                         return 1;
1479
1480                 switch (ob->type) {
1481                         case OB_MESH:
1482                                 if (mode & (OB_MODE_EDIT | OB_MODE_SCULPT | OB_MODE_VERTEX_PAINT | OB_MODE_WEIGHT_PAINT | OB_MODE_TEXTURE_PAINT | OB_MODE_PARTICLE_EDIT))
1483                                         return 1;
1484                                 return 0;
1485                         case OB_CURVE:
1486                         case OB_SURF:
1487                         case OB_FONT:
1488                         case OB_MBALL:
1489                                 if (mode & (OB_MODE_EDIT))
1490                                         return 1;
1491                                 return 0;
1492                         case OB_LATTICE:
1493                                 if (mode & (OB_MODE_EDIT | OB_MODE_WEIGHT_PAINT))
1494                                         return 1;
1495                         case OB_ARMATURE:
1496                                 if (mode & (OB_MODE_EDIT | OB_MODE_POSE))
1497                                         return 1;
1498                 }
1499         }
1500
1501         return 0;
1502 }
1503
1504 static int object_mode_set_exec(bContext *C, wmOperator *op)
1505 {
1506         Object *ob = CTX_data_active_object(C);
1507         ObjectMode mode = RNA_enum_get(op->ptr, "mode");
1508         ObjectMode restore_mode = (ob) ? ob->mode : OB_MODE_OBJECT;
1509         int toggle = RNA_boolean_get(op->ptr, "toggle");
1510
1511         if (!ob || !object_mode_set_compat(C, op, ob))
1512                 return OPERATOR_PASS_THROUGH;
1513
1514         /* Exit current mode if it's not the mode we're setting */
1515         if (ob->mode != OB_MODE_OBJECT && ob->mode != mode)
1516                 WM_operator_name_call(C, object_mode_op_string(ob->mode), WM_OP_EXEC_REGION_WIN, NULL);
1517
1518         if (mode != OB_MODE_OBJECT) {
1519                 /* Enter new mode */
1520                 if (ob->mode != mode || toggle)
1521                         WM_operator_name_call(C, object_mode_op_string(mode), WM_OP_EXEC_REGION_WIN, NULL);
1522
1523                 if (toggle) {
1524                         if (ob->mode == mode)
1525                                 /* For toggling, store old mode so we know what to go back to */
1526                                 ob->restore_mode = restore_mode;
1527                         else if (ob->restore_mode != OB_MODE_OBJECT && ob->restore_mode != mode) {
1528                                 WM_operator_name_call(C, object_mode_op_string(ob->restore_mode), WM_OP_EXEC_REGION_WIN, NULL);
1529                         }
1530                 }
1531         }
1532
1533         return OPERATOR_FINISHED;
1534 }
1535
1536 void OBJECT_OT_mode_set(wmOperatorType *ot)
1537 {
1538         PropertyRNA *prop;
1539
1540         /* identifiers */
1541         ot->name = "Set Object Mode";
1542         ot->description = "Sets the object interaction mode";
1543         ot->idname = "OBJECT_OT_mode_set";
1544         
1545         /* api callbacks */
1546         ot->exec = object_mode_set_exec;
1547         
1548         ot->poll = ED_operator_object_active_editable;
1549         
1550         /* flags */
1551         ot->flag = 0; /* no register/undo here, leave it to operators being called */
1552         
1553         prop = RNA_def_enum(ot->srna, "mode", object_mode_items, OB_MODE_OBJECT, "Mode", "");
1554         RNA_def_enum_funcs(prop, object_mode_set_itemsf);
1555
1556         RNA_def_boolean(ot->srna, "toggle", 0, "Toggle", "");
1557 }
1558
1559
1560
1561 void ED_object_toggle_modes(bContext *C, int mode)
1562 {
1563         if (mode & OB_MODE_SCULPT)
1564                 WM_operator_name_call(C, "SCULPT_OT_sculptmode_toggle", WM_OP_EXEC_REGION_WIN, NULL);
1565         if (mode & OB_MODE_VERTEX_PAINT)
1566                 WM_operator_name_call(C, "PAINT_OT_vertex_paint_toggle", WM_OP_EXEC_REGION_WIN, NULL);
1567         if (mode & OB_MODE_WEIGHT_PAINT)
1568                 WM_operator_name_call(C, "PAINT_OT_weight_paint_toggle", WM_OP_EXEC_REGION_WIN, NULL);
1569         if (mode & OB_MODE_TEXTURE_PAINT)
1570                 WM_operator_name_call(C, "PAINT_OT_texture_paint_toggle", WM_OP_EXEC_REGION_WIN, NULL);
1571         if (mode & OB_MODE_PARTICLE_EDIT)
1572                 WM_operator_name_call(C, "PARTICLE_OT_particle_edit_toggle", WM_OP_EXEC_REGION_WIN, NULL);
1573         if (mode & OB_MODE_POSE)
1574                 WM_operator_name_call(C, "OBJECT_OT_posemode_toggle", WM_OP_EXEC_REGION_WIN, NULL);
1575         if (mode & OB_MODE_EDIT)
1576                 WM_operator_name_call(C, "OBJECT_OT_editmode_toggle", WM_OP_EXEC_REGION_WIN, NULL);
1577 }
1578
1579 /************************ Game Properties ***********************/
1580
1581 static int game_property_new(bContext *C, wmOperator *op)
1582 {
1583         Object *ob = CTX_data_active_object(C);
1584         bProperty *prop;
1585         char name[MAX_NAME];
1586         int type = RNA_enum_get(op->ptr, "type");
1587
1588         prop = BKE_bproperty_new(type);
1589         BLI_addtail(&ob->prop, prop);
1590
1591         RNA_string_get(op->ptr, "name", name);
1592         if (name[0] != '\0') {
1593                 BLI_strncpy(prop->name, name, sizeof(prop->name));
1594         }
1595
1596         BKE_bproperty_unique(NULL, prop, 0); // make_unique_prop_names(prop->name);
1597
1598         WM_event_add_notifier(C, NC_LOGIC, NULL);
1599         return OPERATOR_FINISHED;
1600 }
1601
1602
1603 void OBJECT_OT_game_property_new(wmOperatorType *ot)
1604 {
1605         /* identifiers */
1606         ot->name = "New Game Property";
1607         ot->description = "Create a new property available to the game engine";
1608         ot->idname = "OBJECT_OT_game_property_new";
1609
1610         /* api callbacks */
1611         ot->exec = game_property_new;
1612         ot->poll = ED_operator_object_active_editable;
1613
1614         /* flags */
1615         ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
1616
1617         RNA_def_enum(ot->srna, "type", gameproperty_type_items, GPROP_FLOAT, "Type", "Type of game property to add");
1618         RNA_def_string(ot->srna, "name", "", MAX_NAME, "Name", "Name of the game property to add");
1619 }
1620
1621 static int game_property_remove(bContext *C, wmOperator *op)
1622 {
1623         Object *ob = CTX_data_active_object(C);
1624         bProperty *prop;
1625         int index = RNA_int_get(op->ptr, "index");
1626
1627         if (!ob)
1628                 return OPERATOR_CANCELLED;
1629
1630         prop = BLI_findlink(&ob->prop, index);
1631
1632         if (prop) {
1633                 BLI_remlink(&ob->prop, prop);
1634                 BKE_bproperty_free(prop);
1635
1636                 WM_event_add_notifier(C, NC_LOGIC, NULL);
1637                 return OPERATOR_FINISHED;
1638         }
1639         else {
1640                 return OPERATOR_CANCELLED;
1641         }
1642 }
1643
1644 void OBJECT_OT_game_property_remove(wmOperatorType *ot)
1645 {
1646         /* identifiers */
1647         ot->name = "Remove Game Property";
1648         ot->description = "Remove game property";
1649         ot->idname = "OBJECT_OT_game_property_remove";
1650
1651         /* api callbacks */
1652         ot->exec = game_property_remove;
1653         ot->poll = ED_operator_object_active_editable;
1654
1655         /* flags */
1656         ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
1657
1658         RNA_def_int(ot->srna, "index", 0, 0, INT_MAX, "Index", "Property index to remove ", 0, INT_MAX);
1659 }
1660
1661 #define COPY_PROPERTIES_REPLACE 1
1662 #define COPY_PROPERTIES_MERGE   2
1663 #define COPY_PROPERTIES_COPY    3
1664
1665 static EnumPropertyItem game_properties_copy_operations[] = {
1666         {COPY_PROPERTIES_REPLACE, "REPLACE", 0, "Replace Properties", ""},
1667         {COPY_PROPERTIES_MERGE, "MERGE", 0, "Merge Properties", ""},
1668         {COPY_PROPERTIES_COPY, "COPY", 0, "Copy a Property", ""},
1669         {0, NULL, 0, NULL, NULL}
1670 };
1671
1672 static EnumPropertyItem gameprops_items[] = {
1673         {0, NULL, 0, NULL, NULL}
1674 };
1675
1676 static EnumPropertyItem *gameprops_itemf(bContext *C, PointerRNA *UNUSED(ptr), PropertyRNA *UNUSED(prop), int *free)
1677 {       
1678         Object *ob = ED_object_active_context(C);
1679         EnumPropertyItem tmp = {0, "", 0, "", ""};
1680         EnumPropertyItem *item = NULL;
1681         bProperty *prop;
1682         int a, totitem = 0;
1683         
1684         if (!ob)
1685                 return gameprops_items;
1686
1687         for (a = 1, prop = ob->prop.first; prop; prop = prop->next, a++) {
1688                 tmp.value = a;
1689                 tmp.identifier = prop->name;
1690                 tmp.name = prop->name;
1691                 RNA_enum_item_add(&item, &totitem, &tmp);
1692         }
1693
1694         RNA_enum_item_end(&item, &totitem);
1695         *free = 1;
1696
1697         return item;
1698 }
1699
1700 static int game_property_copy_exec(bContext *C, wmOperator *op)
1701 {
1702         Object *ob = ED_object_active_context(C);
1703         bProperty *prop;
1704         int type = RNA_enum_get(op->ptr, "operation");
1705         int propid = RNA_enum_get(op->ptr, "property");
1706
1707         if (propid > 0) { /* copy */
1708                 prop = BLI_findlink(&ob->prop, propid - 1);
1709                 
1710                 if (prop) {
1711                         CTX_DATA_BEGIN(C, Object *, ob_iter, selected_editable_objects)
1712                         {
1713                                 if (ob != ob_iter)
1714                                         BKE_bproperty_object_set(ob_iter, prop);
1715                         } CTX_DATA_END;
1716                 }
1717         }
1718
1719         else {
1720                 CTX_DATA_BEGIN(C, Object *, ob_iter, selected_editable_objects)
1721                 {
1722                         if (ob != ob_iter) {
1723                                 if (type == COPY_PROPERTIES_REPLACE) {
1724                                         BKE_bproperty_copy_list(&ob_iter->prop, &ob->prop);
1725                                 }
1726                                 else {
1727                                         /* merge - the default when calling with no argument */
1728                                         for (prop = ob->prop.first; prop; prop = prop->next) {
1729                                                 BKE_bproperty_object_set(ob_iter, prop);
1730                                         }
1731                                 }
1732                         }
1733                 }
1734                 CTX_DATA_END;
1735         }
1736
1737         return OPERATOR_FINISHED;
1738 }
1739
1740 void OBJECT_OT_game_property_copy(wmOperatorType *ot)
1741 {
1742         PropertyRNA *prop;
1743         /* identifiers */
1744         ot->name = "Copy Game Property";
1745         ot->idname = "OBJECT_OT_game_property_copy";
1746         ot->description = "Copy/merge/replace a game property from active object to all selected objects";
1747
1748         /* api callbacks */
1749         ot->exec = game_property_copy_exec;
1750         ot->poll = ED_operator_object_active_editable;
1751
1752         /* flags */
1753         ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
1754
1755         RNA_def_enum(ot->srna, "operation", game_properties_copy_operations, 3, "Operation", "");
1756         prop = RNA_def_enum(ot->srna, "property", gameprops_items, 0, "Property", "Properties to copy");
1757         RNA_def_property_flag(prop, PROP_SKIP_SAVE);
1758         RNA_def_enum_funcs(prop, gameprops_itemf);
1759         ot->prop = prop;
1760 }
1761
1762 static int game_property_clear_exec(bContext *C, wmOperator *UNUSED(op))
1763 {
1764         CTX_DATA_BEGIN(C, Object *, ob_iter, selected_editable_objects)
1765         {
1766                 BKE_bproperty_free_list(&ob_iter->prop);
1767         }
1768         CTX_DATA_END;
1769
1770         WM_event_add_notifier(C, NC_LOGIC, NULL);
1771         return OPERATOR_FINISHED;
1772 }
1773 void OBJECT_OT_game_property_clear(wmOperatorType *ot)
1774 {
1775         /* identifiers */
1776         ot->name = "Clear Game Properties";
1777         ot->idname = "OBJECT_OT_game_property_clear";
1778         ot->description = "Remove all game properties from all selected objects";
1779
1780         /* api callbacks */
1781         ot->exec = game_property_clear_exec;
1782         ot->poll = ED_operator_object_active_editable;
1783
1784         /* flags */
1785         ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
1786 }
1787
1788 /************************ Copy Logic Bricks ***********************/
1789
1790 static int logicbricks_copy_exec(bContext *C, wmOperator *UNUSED(op))
1791 {
1792         Object *ob = ED_object_active_context(C);
1793
1794         CTX_DATA_BEGIN(C, Object *, ob_iter, selected_editable_objects)
1795         {
1796                 if (ob != ob_iter) {
1797                         /* first: free all logic */
1798                         free_sensors(&ob_iter->sensors);                                
1799                         unlink_controllers(&ob_iter->controllers);
1800                         free_controllers(&ob_iter->controllers);
1801                         unlink_actuators(&ob_iter->actuators);
1802                         free_actuators(&ob_iter->actuators);
1803                 
1804                         /* now copy it, this also works without logicbricks! */
1805                         clear_sca_new_poins_ob(ob);
1806                         copy_sensors(&ob_iter->sensors, &ob->sensors);
1807                         copy_controllers(&ob_iter->controllers, &ob->controllers);
1808                         copy_actuators(&ob_iter->actuators, &ob->actuators);
1809                         set_sca_new_poins_ob(ob_iter);
1810                 
1811                         /* some menu settings */
1812                         ob_iter->scavisflag = ob->scavisflag;
1813                         ob_iter->scaflag = ob->scaflag;
1814                 
1815                         /* set the initial state */
1816                         ob_iter->state = ob->state;
1817                         ob_iter->init_state = ob->init_state;
1818
1819                         if (ob_iter->totcol == ob->totcol) {
1820                                 ob_iter->actcol = ob->actcol;
1821                                 WM_event_add_notifier(C, NC_OBJECT | ND_DRAW, ob_iter);
1822                         }
1823                 }
1824         }
1825         CTX_DATA_END;
1826
1827         WM_event_add_notifier(C, NC_LOGIC, NULL);
1828
1829         return OPERATOR_FINISHED;
1830 }
1831
1832 void OBJECT_OT_logic_bricks_copy(wmOperatorType *ot)
1833 {
1834         /* identifiers */
1835         ot->name = "Copy Logic Bricks to Selected";
1836         ot->description = "Copy logic bricks to other selected objects";
1837         ot->idname = "OBJECT_OT_logic_bricks_copy";
1838
1839         /* api callbacks */
1840         ot->exec = logicbricks_copy_exec;
1841         ot->poll = ED_operator_object_active_editable;
1842
1843         /* flags */
1844         ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
1845 }
1846
1847 static int game_physics_copy_exec(bContext *C, wmOperator *UNUSED(op))
1848 {
1849         Object *ob = ED_object_active_context(C);
1850         
1851         CTX_DATA_BEGIN(C, Object *, ob_iter, selected_editable_objects)
1852         {
1853                 if (ob != ob_iter) {
1854                         ob_iter->gameflag = ob->gameflag;
1855                         ob_iter->gameflag2 = ob->gameflag2;
1856                         ob_iter->inertia = ob->inertia;
1857                         ob_iter->formfactor = ob->formfactor;
1858                         ob_iter->damping = ob->damping;
1859                         ob_iter->rdamping = ob->rdamping;
1860                         ob_iter->min_vel = ob->min_vel;
1861                         ob_iter->max_vel = ob->max_vel;
1862                         ob_iter->obstacleRad = ob->obstacleRad;
1863                         ob_iter->mass = ob->mass;
1864                         ob_iter->anisotropicFriction[0] = ob->anisotropicFriction[0];
1865                         ob_iter->anisotropicFriction[1] = ob->anisotropicFriction[1];
1866                         ob_iter->anisotropicFriction[2] = ob->anisotropicFriction[2];
1867                         ob_iter->collision_boundtype = ob->collision_boundtype;                 
1868                         ob_iter->margin = ob->margin;
1869                         ob_iter->bsoft = copy_bulletsoftbody(ob->bsoft);
1870                         if (ob->restrictflag & OB_RESTRICT_RENDER) 
1871                                 ob_iter->restrictflag |= OB_RESTRICT_RENDER;
1872                         else
1873                                 ob_iter->restrictflag &= ~OB_RESTRICT_RENDER;
1874                 }
1875         }
1876         CTX_DATA_END;
1877         
1878         return OPERATOR_FINISHED;
1879 }
1880
1881 void OBJECT_OT_game_physics_copy(struct wmOperatorType *ot)
1882 {
1883         /* identifiers */
1884         ot->name = "Copy Game Physics Properties to Selected";
1885         ot->description = "Copy game physics properties to other selected objects";
1886         ot->idname = "OBJECT_OT_game_physics_copy";
1887         
1888         /* api callbacks */
1889         ot->exec = game_physics_copy_exec;
1890         ot->poll = ED_operator_object_active_editable;
1891         
1892         /* flags */
1893         ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
1894 }