Bug fix, IRC report.
[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         /* this checks actual object->data, for cases when other scenes have it in editmode context */
433         if ( BKE_object_is_in_editmode(ob) )
434                 return;
435         
436         if (BKE_object_obdata_is_libdata(ob)) {
437                 error_libdata();
438                 return;
439         }
440
441         if (flag & EM_WAITCURSOR) waitcursor(1);
442
443         ob->restore_mode = ob->mode;
444
445         /* note, when switching scenes the object can have editmode data but
446          * not be scene->obedit: bug 22954, this avoids calling self eternally */
447         if ((ob->restore_mode & OB_MODE_EDIT) == 0)
448                 ED_object_toggle_modes(C, ob->mode);
449
450         ob->mode = OB_MODE_EDIT;
451
452         if (ob->type == OB_MESH) {
453                 BMEditMesh *em;
454                 ok = 1;
455                 scene->obedit = ob;  /* context sees this */
456
457                 EDBM_mesh_make(CTX_data_tool_settings(C), scene, ob);
458
459                 em = BMEdit_FromObject(ob);
460                 if (LIKELY(em)) {
461                         /* order doesn't matter */
462                         EDBM_mesh_normals_update(em);
463                         BMEdit_RecalcTessellation(em);
464
465                         BM_mesh_select_mode_flush(em->bm);
466                 }
467
468                 WM_event_add_notifier(C, NC_SCENE | ND_MODE | NS_EDITMODE_MESH, scene);
469         }
470         else if (ob->type == OB_ARMATURE) {
471                 bArmature *arm = base->object->data;
472                 if (!arm) return;
473                 /*
474                  * The function BKE_object_obdata_is_libdata make a problem here, the
475                  * check for ob->proxy return 0 and let blender enter to edit mode
476                  * this causes a crash when you try leave the edit mode.
477                  * The problem is that i can't remove the ob->proxy check from
478                  * BKE_object_obdata_is_libdata that prevent the bugfix #6614, so
479                  * i add this little hack here.
480                  */
481                 if (arm->id.lib) {
482                         error_libdata();
483                         return;
484                 }
485                 ok = 1;
486                 scene->obedit = ob;
487                 ED_armature_to_edit(ob);
488                 /* to ensure all goes in restposition and without striding */
489                 DAG_id_tag_update(&ob->id, OB_RECALC_OB | OB_RECALC_DATA | OB_RECALC_TIME); /* XXX: should this be OB_RECALC_DATA? */
490
491                 WM_event_add_notifier(C, NC_SCENE | ND_MODE | NS_EDITMODE_ARMATURE, scene);
492         }
493         else if (ob->type == OB_FONT) {
494                 scene->obedit = ob; /* XXX for context */
495                 ok = 1;
496                 make_editText(ob);
497
498                 WM_event_add_notifier(C, NC_SCENE | ND_MODE | NS_EDITMODE_TEXT, scene);
499         }
500         else if (ob->type == OB_MBALL) {
501                 scene->obedit = ob; /* XXX for context */
502                 ok = 1;
503                 make_editMball(ob);
504
505                 WM_event_add_notifier(C, NC_SCENE | ND_MODE | NS_EDITMODE_MBALL, scene);
506         }
507         else if (ob->type == OB_LATTICE) {
508                 scene->obedit = ob; /* XXX for context */
509                 ok = 1;
510                 make_editLatt(ob);
511
512                 WM_event_add_notifier(C, NC_SCENE | ND_MODE | NS_EDITMODE_LATTICE, scene);
513         }
514         else if (ob->type == OB_SURF || ob->type == OB_CURVE) {
515                 ok = 1;
516                 scene->obedit = ob; /* XXX for context */
517                 make_editNurb(ob);
518
519                 WM_event_add_notifier(C, NC_SCENE | ND_MODE | NS_EDITMODE_CURVE, scene);
520         }
521
522         if (ok) {
523                 DAG_id_tag_update(&ob->id, OB_RECALC_DATA);
524         }
525         else {
526                 scene->obedit = NULL; /* XXX for context */
527                 ob->mode &= ~OB_MODE_EDIT;
528                 WM_event_add_notifier(C, NC_SCENE | ND_MODE | NS_MODE_OBJECT, scene);
529         }
530
531         if (flag & EM_DO_UNDO) ED_undo_push(C, "Enter Editmode");
532         if (flag & EM_WAITCURSOR) waitcursor(0);
533 }
534
535 static int editmode_toggle_exec(bContext *C, wmOperator *UNUSED(op))
536 {
537         ToolSettings *toolsettings =  CTX_data_tool_settings(C);
538
539         if (!CTX_data_edit_object(C))
540                 ED_object_enter_editmode(C, EM_WAITCURSOR);
541         else
542                 ED_object_exit_editmode(C, EM_FREEDATA | EM_FREEUNDO | EM_WAITCURSOR);  /* had EM_DO_UNDO but op flag calls undo too [#24685] */
543         
544         ED_space_image_uv_sculpt_update(CTX_wm_manager(C), toolsettings);
545
546         return OPERATOR_FINISHED;
547 }
548
549 static int editmode_toggle_poll(bContext *C)
550 {
551         Object *ob = CTX_data_active_object(C);
552
553         /* covers proxies too */
554         if (ELEM(NULL, ob, ob->data) || ((ID *)ob->data)->lib)
555                 return 0;
556
557         /* if hidden but in edit mode, we still display */
558         if ((ob->restrictflag & OB_RESTRICT_VIEW) && !(ob->mode & OB_MODE_EDIT))
559                 return 0;
560
561         return (ob->type == OB_MESH || ob->type == OB_ARMATURE ||
562                 ob->type == OB_FONT || ob->type == OB_MBALL ||
563                 ob->type == OB_LATTICE || ob->type == OB_SURF ||
564                 ob->type == OB_CURVE);
565 }
566
567 void OBJECT_OT_editmode_toggle(wmOperatorType *ot)
568 {
569         
570         /* identifiers */
571         ot->name = "Toggle Editmode";
572         ot->description = "Toggle object's editmode";
573         ot->idname = "OBJECT_OT_editmode_toggle";
574         
575         /* api callbacks */
576         ot->exec = editmode_toggle_exec;
577         
578         ot->poll = editmode_toggle_poll;
579         
580         /* flags */
581         ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
582 }
583
584 /* *************************** */
585
586 static int posemode_exec(bContext *C, wmOperator *UNUSED(op))
587 {
588         Base *base = CTX_data_active_base(C);
589         
590         if (base->object->type == OB_ARMATURE) {
591                 if (base->object == CTX_data_edit_object(C)) {
592                         ED_object_exit_editmode(C, EM_FREEDATA | EM_DO_UNDO);
593                         ED_armature_enter_posemode(C, base);
594                 }
595                 else if (base->object->mode & OB_MODE_POSE)
596                         ED_armature_exit_posemode(C, base);
597                 else
598                         ED_armature_enter_posemode(C, base);
599                 
600                 return OPERATOR_FINISHED;
601         }
602         
603         return OPERATOR_PASS_THROUGH;
604 }
605
606 void OBJECT_OT_posemode_toggle(wmOperatorType *ot) 
607 {
608         /* identifiers */
609         ot->name = "Toggle Pose Mode";
610         ot->idname = "OBJECT_OT_posemode_toggle";
611         ot->description = "Enable or disable posing/selecting bones";
612         
613         /* api callbacks */
614         ot->exec = posemode_exec;
615         ot->poll = ED_operator_object_active_editable;
616         
617         /* flag */
618         ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
619 }
620
621 static void copymenu_properties(Scene *scene, View3D *v3d, Object *ob)
622 {       
623 //XXX no longer used - to be removed - replaced by game_properties_copy_exec
624         bProperty *prop;
625         Base *base;
626         int nr, tot = 0;
627         char *str;
628         
629         prop = ob->prop.first;
630         while (prop) {
631                 tot++;
632                 prop = prop->next;
633         }
634         
635         str = MEM_callocN(50 + 33 * tot, "copymenu prop");
636         
637         if (tot)
638                 strcpy(str, "Copy Property %t|Replace All|Merge All|%l");
639         else
640                 strcpy(str, "Copy Property %t|Clear All (no properties on active)");
641         
642         tot = 0;
643         prop = ob->prop.first;
644         while (prop) {
645                 tot++;
646                 strcat(str, "|");
647                 strcat(str, prop->name);
648                 prop = prop->next;
649         }
650
651         nr = pupmenu(str);
652         
653         if (nr == 1 || nr == 2) {
654                 for (base = FIRSTBASE; base; base = base->next) {
655                         if ((base != BASACT) && (TESTBASELIB(v3d, base))) {
656                                 if (nr == 1) { /* replace */
657                                         BKE_bproperty_copy_list(&base->object->prop, &ob->prop);
658                                 }
659                                 else {
660                                         for (prop = ob->prop.first; prop; prop = prop->next) {
661                                                 BKE_bproperty_object_set(base->object, prop);
662                                         }
663                                 }
664                         }
665                 }
666         }
667         else if (nr > 0) {
668                 prop = BLI_findlink(&ob->prop, nr - 4); /* account for first 3 menu items & menu index starting at 1*/
669                 
670                 if (prop) {
671                         for (base = FIRSTBASE; base; base = base->next) {
672                                 if ((base != BASACT) && (TESTBASELIB(v3d, base))) {
673                                         BKE_bproperty_object_set(base->object, prop);
674                                 }
675                         }
676                 }
677         }
678         MEM_freeN(str);
679         
680 }
681
682 static void copymenu_logicbricks(Scene *scene, View3D *v3d, Object *ob)
683 {
684 //XXX no longer used - to be removed - replaced by logicbricks_copy_exec
685         Base *base;
686         
687         for (base = FIRSTBASE; base; base = base->next) {
688                 if (base->object != ob) {
689                         if (TESTBASELIB(v3d, base)) {
690                                 
691                                 /* first: free all logic */
692                                 free_sensors(&base->object->sensors);
693                                 unlink_controllers(&base->object->controllers);
694                                 free_controllers(&base->object->controllers);
695                                 unlink_actuators(&base->object->actuators);
696                                 free_actuators(&base->object->actuators);
697                                 
698                                 /* now copy it, this also works without logicbricks! */
699                                 clear_sca_new_poins_ob(ob);
700                                 copy_sensors(&base->object->sensors, &ob->sensors);
701                                 copy_controllers(&base->object->controllers, &ob->controllers);
702                                 copy_actuators(&base->object->actuators, &ob->actuators);
703                                 set_sca_new_poins_ob(base->object);
704                                 
705                                 /* some menu settings */
706                                 base->object->scavisflag = ob->scavisflag;
707                                 base->object->scaflag = ob->scaflag;
708                                 
709                                 /* set the initial state */
710                                 base->object->state = ob->state;
711                                 base->object->init_state = ob->init_state;
712                         }
713                 }
714         }
715 }
716
717 /* both pointers should exist */
718 static void copy_texture_space(Object *to, Object *ob)
719 {
720         float *poin1 = NULL, *poin2 = NULL;
721         short texflag = 0;
722         
723         if (ob->type == OB_MESH) {
724                 texflag = ((Mesh *)ob->data)->texflag;
725                 poin2 = ((Mesh *)ob->data)->loc;
726         }
727         else if (ELEM3(ob->type, OB_CURVE, OB_SURF, OB_FONT)) {
728                 texflag = ((Curve *)ob->data)->texflag;
729                 poin2 = ((Curve *)ob->data)->loc;
730         }
731         else if (ob->type == OB_MBALL) {
732                 texflag = ((MetaBall *)ob->data)->texflag;
733                 poin2 = ((MetaBall *)ob->data)->loc;
734         }
735         else
736                 return;
737                 
738         if (to->type == OB_MESH) {
739                 ((Mesh *)to->data)->texflag = texflag;
740                 poin1 = ((Mesh *)to->data)->loc;
741         }
742         else if (ELEM3(to->type, OB_CURVE, OB_SURF, OB_FONT)) {
743                 ((Curve *)to->data)->texflag = texflag;
744                 poin1 = ((Curve *)to->data)->loc;
745         }
746         else if (to->type == OB_MBALL) {
747                 ((MetaBall *)to->data)->texflag = texflag;
748                 poin1 = ((MetaBall *)to->data)->loc;
749         }
750         else
751                 return;
752         
753         memcpy(poin1, poin2, 9 * sizeof(float));  /* this was noted in DNA_mesh, curve, mball */
754         
755         if (to->type == OB_MESH) {
756                 /* pass */
757         }
758         else if (to->type == OB_MBALL) {
759                 BKE_mball_texspace_calc(to);
760         }
761         else {
762                 BKE_curve_texspace_calc(to->data);
763         }
764         
765 }
766
767 /* UNUSED, keep in case we want to copy functionality for use elsewhere */
768 static void copy_attr(Main *bmain, Scene *scene, View3D *v3d, short event)
769 {
770         Object *ob;
771         Base *base;
772         Curve *cu, *cu1;
773         Nurb *nu;
774         int do_scene_sort = FALSE;
775         
776         if (scene->id.lib) return;
777
778         if (!(ob = OBACT)) return;
779         
780         if (scene->obedit) { // XXX get from context
781                 /* obedit_copymenu(); */
782                 return;
783         }
784         if (event == 9) {
785                 copymenu_properties(scene, v3d, ob);
786                 return;
787         }
788         else if (event == 10) {
789                 copymenu_logicbricks(scene, v3d, ob);
790                 return;
791         }
792         else if (event == 24) {
793                 /* moved to BKE_object_link_modifiers */
794                 /* copymenu_modifiers(bmain, scene, v3d, ob); */
795                 return;
796         }
797
798         for (base = FIRSTBASE; base; base = base->next) {
799                 if (base != BASACT) {
800                         if (TESTBASELIB(v3d, base)) {
801                                 base->object->recalc |= OB_RECALC_OB;
802                                 
803                                 if (event == 1) {  /* loc */
804                                         copy_v3_v3(base->object->loc, ob->loc);
805                                         copy_v3_v3(base->object->dloc, ob->dloc);
806                                 }
807                                 else if (event == 2) {  /* rot */
808                                         copy_v3_v3(base->object->rot, ob->rot);
809                                         copy_v3_v3(base->object->drot, ob->drot);
810
811                                         copy_qt_qt(base->object->quat, ob->quat);
812                                         copy_qt_qt(base->object->dquat, ob->dquat);
813                                 }
814                                 else if (event == 3) {  /* size */
815                                         copy_v3_v3(base->object->size, ob->size);
816                                         copy_v3_v3(base->object->dscale, ob->dscale);
817                                 }
818                                 else if (event == 4) {  /* drawtype */
819                                         base->object->dt = ob->dt;
820                                         base->object->dtx = ob->dtx;
821                                         base->object->empty_drawtype = ob->empty_drawtype;
822                                         base->object->empty_drawsize = ob->empty_drawsize;
823                                 }
824                                 else if (event == 5) {  /* time offs */
825                                         base->object->sf = ob->sf;
826                                 }
827                                 else if (event == 6) {  /* dupli */
828                                         base->object->dupon = ob->dupon;
829                                         base->object->dupoff = ob->dupoff;
830                                         base->object->dupsta = ob->dupsta;
831                                         base->object->dupend = ob->dupend;
832                                         
833                                         base->object->transflag &= ~OB_DUPLI;
834                                         base->object->transflag |= (ob->transflag & OB_DUPLI);
835
836                                         base->object->dup_group = ob->dup_group;
837                                         if (ob->dup_group)
838                                                 id_lib_extern(&ob->dup_group->id);
839                                 }
840                                 else if (event == 7) {    /* mass */
841                                         base->object->mass = ob->mass;
842                                 }
843                                 else if (event == 8) {    /* damping */
844                                         base->object->damping = ob->damping;
845                                         base->object->rdamping = ob->rdamping;
846                                 }
847                                 else if (event == 11) {   /* all physical attributes */
848                                         base->object->gameflag = ob->gameflag;
849                                         base->object->inertia = ob->inertia;
850                                         base->object->formfactor = ob->formfactor;
851                                         base->object->damping = ob->damping;
852                                         base->object->rdamping = ob->rdamping;
853                                         base->object->min_vel = ob->min_vel;
854                                         base->object->max_vel = ob->max_vel;
855                                         if (ob->gameflag & OB_BOUNDS) {
856                                                 base->object->collision_boundtype = ob->collision_boundtype;
857                                         }
858                                         base->object->margin = ob->margin;
859                                         base->object->bsoft = copy_bulletsoftbody(ob->bsoft);
860
861                                 }
862                                 else if (event == 17) {   /* tex space */
863                                         copy_texture_space(base->object, ob);
864                                 }
865                                 else if (event == 18) {   /* font settings */
866                                         
867                                         if (base->object->type == ob->type) {
868                                                 cu = ob->data;
869                                                 cu1 = base->object->data;
870
871                                                 cu1->spacemode = cu->spacemode;
872                                                 cu1->spacing = cu->spacing;
873                                                 cu1->linedist = cu->linedist;
874                                                 cu1->shear = cu->shear;
875                                                 cu1->fsize = cu->fsize;
876                                                 cu1->xof = cu->xof;
877                                                 cu1->yof = cu->yof;
878                                                 cu1->textoncurve = cu->textoncurve;
879                                                 cu1->wordspace = cu->wordspace;
880                                                 cu1->ulpos = cu->ulpos;
881                                                 cu1->ulheight = cu->ulheight;
882                                                 if (cu1->vfont) cu1->vfont->id.us--;
883                                                 cu1->vfont = cu->vfont;
884                                                 id_us_plus((ID *)cu1->vfont);
885                                                 if (cu1->vfontb) cu1->vfontb->id.us--;
886                                                 cu1->vfontb = cu->vfontb;
887                                                 id_us_plus((ID *)cu1->vfontb);
888                                                 if (cu1->vfonti) cu1->vfonti->id.us--;
889                                                 cu1->vfonti = cu->vfonti;
890                                                 id_us_plus((ID *)cu1->vfonti);
891                                                 if (cu1->vfontbi) cu1->vfontbi->id.us--;
892                                                 cu1->vfontbi = cu->vfontbi;
893                                                 id_us_plus((ID *)cu1->vfontbi);
894
895                                                 BKE_vfont_to_curve(bmain, scene, base->object, 0); /* needed? */
896
897                                                 
898                                                 BLI_strncpy(cu1->family, cu->family, sizeof(cu1->family));
899                                                 
900                                                 base->object->recalc |= OB_RECALC_DATA;
901                                         }
902                                 }
903                                 else if (event == 19) {   /* bevel settings */
904                                         
905                                         if (ELEM(base->object->type, OB_CURVE, OB_FONT)) {
906                                                 cu = ob->data;
907                                                 cu1 = base->object->data;
908                                                 
909                                                 cu1->bevobj = cu->bevobj;
910                                                 cu1->taperobj = cu->taperobj;
911                                                 cu1->width = cu->width;
912                                                 cu1->bevresol = cu->bevresol;
913                                                 cu1->ext1 = cu->ext1;
914                                                 cu1->ext2 = cu->ext2;
915                                                 
916                                                 base->object->recalc |= OB_RECALC_DATA;
917                                         }
918                                 }
919                                 else if (event == 25) {   /* curve resolution */
920
921                                         if (ELEM(base->object->type, OB_CURVE, OB_FONT)) {
922                                                 cu = ob->data;
923                                                 cu1 = base->object->data;
924                                                 
925                                                 cu1->resolu = cu->resolu;
926                                                 cu1->resolu_ren = cu->resolu_ren;
927                                                 
928                                                 nu = cu1->nurb.first;
929                                                 
930                                                 while (nu) {
931                                                         nu->resolu = cu1->resolu;
932                                                         nu = nu->next;
933                                                 }
934                                                 
935                                                 base->object->recalc |= OB_RECALC_DATA;
936                                         }
937                                 }
938                                 else if (event == 21) {
939                                         if (base->object->type == OB_MESH) {
940                                                 ModifierData *md = modifiers_findByType(ob, eModifierType_Subsurf);
941
942                                                 if (md) {
943                                                         ModifierData *tmd = modifiers_findByType(base->object, eModifierType_Subsurf);
944
945                                                         if (!tmd) {
946                                                                 tmd = modifier_new(eModifierType_Subsurf);
947                                                                 BLI_addtail(&base->object->modifiers, tmd);
948                                                         }
949
950                                                         modifier_copyData(md, tmd);
951                                                         base->object->recalc |= OB_RECALC_DATA;
952                                                 }
953                                         }
954                                 }
955                                 else if (event == 22) {
956                                         /* Copy the constraint channels over */
957                                         copy_constraints(&base->object->constraints, &ob->constraints, TRUE);
958                                         
959                                         do_scene_sort = TRUE;
960                                 }
961                                 else if (event == 23) {
962                                         base->object->softflag = ob->softflag;
963                                         if (base->object->soft) sbFree(base->object->soft);
964                                         
965                                         base->object->soft = copy_softbody(ob->soft, FALSE);
966
967                                         if (!modifiers_findByType(base->object, eModifierType_Softbody)) {
968                                                 BLI_addhead(&base->object->modifiers, modifier_new(eModifierType_Softbody));
969                                         }
970                                 }
971                                 else if (event == 26) {
972 #if 0 // XXX old animation system
973                                         copy_nlastrips(&base->object->nlastrips, &ob->nlastrips);
974 #endif // XXX old animation system
975                                 }
976                                 else if (event == 27) {   /* autosmooth */
977                                         if (base->object->type == OB_MESH) {
978                                                 Mesh *me = ob->data;
979                                                 Mesh *cme = base->object->data;
980                                                 cme->smoothresh = me->smoothresh;
981                                                 if (me->flag & ME_AUTOSMOOTH)
982                                                         cme->flag |= ME_AUTOSMOOTH;
983                                                 else
984                                                         cme->flag &= ~ME_AUTOSMOOTH;
985                                         }
986                                 }
987                                 else if (event == 28) { /* UV orco */
988                                         if (ELEM(base->object->type, OB_CURVE, OB_SURF)) {
989                                                 cu = ob->data;
990                                                 cu1 = base->object->data;
991                                                 
992                                                 if (cu->flag & CU_UV_ORCO)
993                                                         cu1->flag |= CU_UV_ORCO;
994                                                 else
995                                                         cu1->flag &= ~CU_UV_ORCO;
996                                         }
997                                 }
998                                 else if (event == 29) { /* protected bits */
999                                         base->object->protectflag = ob->protectflag;
1000                                 }
1001                                 else if (event == 30) { /* index object */
1002                                         base->object->index = ob->index;
1003                                 }
1004                                 else if (event == 31) { /* object color */
1005                                         copy_v4_v4(base->object->col, ob->col);
1006                                 }
1007                         }
1008                 }
1009         }
1010         
1011         if (do_scene_sort)
1012                 DAG_scene_sort(bmain, scene);
1013
1014         DAG_ids_flush_update(bmain, 0);
1015 }
1016
1017 static void UNUSED_FUNCTION(copy_attr_menu) (Main * bmain, Scene * scene, View3D * v3d)
1018 {
1019         Object *ob;
1020         short event;
1021         char str[512];
1022         
1023         if (!(ob = OBACT)) return;
1024         
1025         if (scene->obedit) { /* XXX get from context */
1026 /*              if (ob->type == OB_MESH) */
1027 /* XXX                  mesh_copy_menu(); */
1028                 return;
1029         }
1030         
1031         /* Object Mode */
1032         
1033         /* If you change this menu, don't forget to update the menu in header_view3d.c
1034          * view3d_edit_object_copyattrmenu() and in toolbox.c
1035          */
1036         
1037         strcpy(str,
1038                "Copy Attributes %t|Location %x1|Rotation %x2|Size %x3|Draw Options %x4|"
1039                "Time Offset %x5|Dupli %x6|Object Color %x31|%l|Mass %x7|Damping %x8|All Physical Attributes %x11|Properties %x9|"
1040                "Logic Bricks %x10|Protected Transform %x29|%l");
1041         
1042         strcat(str, "|Object Constraints %x22");
1043         strcat(str, "|NLA Strips %x26");
1044         
1045 /* XXX  if (OB_TYPE_SUPPORT_MATERIAL(ob->type)) { */
1046 /*              strcat(str, "|Texture Space %x17"); */
1047 /*      } */
1048         
1049         if (ob->type == OB_FONT) strcat(str, "|Font Settings %x18|Bevel Settings %x19");
1050         if (ob->type == OB_CURVE) strcat(str, "|Bevel Settings %x19|UV Orco %x28");
1051         
1052         if ((ob->type == OB_FONT) || (ob->type == OB_CURVE)) {
1053                 strcat(str, "|Curve Resolution %x25");
1054         }
1055
1056         if (ob->type == OB_MESH) {
1057                 strcat(str, "|Subsurf Settings %x21|AutoSmooth %x27");
1058         }
1059
1060         if (ob->soft) strcat(str, "|Soft Body Settings %x23");
1061         
1062         strcat(str, "|Pass Index %x30");
1063         
1064         if (ob->type == OB_MESH || ob->type == OB_CURVE || ob->type == OB_LATTICE || ob->type == OB_SURF) {
1065                 strcat(str, "|Modifiers ... %x24");
1066         }
1067
1068         event = pupmenu(str);
1069         if (event <= 0) return;
1070         
1071         copy_attr(bmain, scene, v3d, event);
1072 }
1073
1074 /* ******************* force field toggle operator ***************** */
1075
1076 static int forcefield_toggle_exec(bContext *C, wmOperator *UNUSED(op))
1077 {
1078         Object *ob = CTX_data_active_object(C);
1079
1080         if (ob->pd == NULL)
1081                 ob->pd = object_add_collision_fields(PFIELD_FORCE);
1082
1083         if (ob->pd->forcefield == 0)
1084                 ob->pd->forcefield = PFIELD_FORCE;
1085         else
1086                 ob->pd->forcefield = 0;
1087         
1088         WM_event_add_notifier(C, NC_OBJECT | ND_DRAW, NULL);
1089
1090         return OPERATOR_FINISHED;
1091 }
1092
1093 void OBJECT_OT_forcefield_toggle(wmOperatorType *ot)
1094 {
1095         
1096         /* identifiers */
1097         ot->name = "Toggle Force Field";
1098         ot->description = "Toggle object's force field";
1099         ot->idname = "OBJECT_OT_forcefield_toggle";
1100         
1101         /* api callbacks */
1102         ot->exec = forcefield_toggle_exec;
1103         ot->poll = ED_operator_object_active_editable;
1104         
1105         /* flags */
1106         ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
1107 }
1108
1109 /* ********************************************** */
1110 /* Motion Paths */
1111
1112 /* For the objects with animation: update paths for those that have got them
1113  * This should selectively update paths that exist...
1114  *
1115  * To be called from various tools that do incremental updates 
1116  */
1117 void ED_objects_recalculate_paths(bContext *C, Scene *scene)
1118 {
1119         ListBase targets = {NULL, NULL};
1120         
1121         /* loop over objects in scene */
1122         CTX_DATA_BEGIN(C, Object *, ob, selected_editable_objects)
1123         {
1124                 /* set flag to force recalc, then grab path(s) from object */
1125                 ob->avs.recalc |= ANIMVIZ_RECALC_PATHS;
1126                 animviz_get_object_motionpaths(ob, &targets);
1127         }
1128         CTX_DATA_END;
1129         
1130         /* recalculate paths, then free */
1131         animviz_calc_motionpaths(scene, &targets);
1132         BLI_freelistN(&targets);
1133 }
1134
1135
1136 /* show popup to determine settings */
1137 static int object_calculate_paths_invoke(bContext *C, wmOperator *op, wmEvent *UNUSED(event))
1138 {
1139         Object *ob = CTX_data_active_object(C);
1140         
1141         if (ob == NULL)
1142                 return OPERATOR_CANCELLED;
1143         
1144         /* set default settings from existing/stored settings */
1145         {
1146                 bAnimVizSettings *avs = &ob->avs;
1147                 
1148                 RNA_int_set(op->ptr, "start_frame", avs->path_sf);
1149                 RNA_int_set(op->ptr, "end_frame", avs->path_ef);
1150         }
1151         
1152         /* show popup dialog to allow editing of range... */
1153         /* FIXME: hardcoded dimensions here are just arbitrary */
1154         return WM_operator_props_dialog_popup(C, op, 200, 200);
1155 }
1156
1157 /* Calculate/recalculate whole paths (avs.path_sf to avs.path_ef) */
1158 static int object_calculate_paths_exec(bContext *C, wmOperator *op)
1159 {
1160         Scene *scene = CTX_data_scene(C);
1161         int start = RNA_int_get(op->ptr, "start_frame");
1162         int end = RNA_int_get(op->ptr, "end_frame");
1163         
1164         /* set up path data for bones being calculated */
1165         CTX_DATA_BEGIN(C, Object *, ob, selected_editable_objects)
1166         {
1167                 bAnimVizSettings *avs = &ob->avs;
1168                 
1169                 /* grab baking settings from operator settings */
1170                 avs->path_sf = start;
1171                 avs->path_ef = end;
1172                 
1173                 /* verify that the selected object has the appropriate settings */
1174                 animviz_verify_motionpaths(op->reports, scene, ob, NULL);
1175         }
1176         CTX_DATA_END;
1177         
1178         /* calculate the paths for objects that have them (and are tagged to get refreshed) */
1179         ED_objects_recalculate_paths(C, scene);
1180         
1181         /* notifiers for updates */
1182         WM_event_add_notifier(C, NC_OBJECT | ND_TRANSFORM, NULL);
1183         
1184         return OPERATOR_FINISHED; 
1185 }
1186
1187 void OBJECT_OT_paths_calculate(wmOperatorType *ot)
1188 {
1189         /* identifiers */
1190         ot->name = "Calculate Object Paths";
1191         ot->idname = "OBJECT_OT_paths_calculate";
1192         ot->description = "Calculate motion paths for the selected objects";
1193         
1194         /* api callbacks */
1195         ot->invoke = object_calculate_paths_invoke;
1196         ot->exec = object_calculate_paths_exec;
1197         ot->poll = ED_operator_object_active_editable;
1198         
1199         /* flags */
1200         ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
1201         
1202         /* properties */
1203         RNA_def_int(ot->srna, "start_frame", 1, MINAFRAME, MAXFRAME, "Start", 
1204                     "First frame to calculate object paths on", MINFRAME, MAXFRAME / 2.0);
1205         RNA_def_int(ot->srna, "end_frame", 250, MINAFRAME, MAXFRAME, "End", 
1206                     "Last frame to calculate object paths on", MINFRAME, MAXFRAME / 2.0);
1207 }
1208
1209 /* --------- */
1210
1211 static int object_update_paths_exec(bContext *C, wmOperator *UNUSED(op))
1212 {
1213         Scene *scene = CTX_data_scene(C);
1214         
1215         if (scene == NULL)
1216                 return OPERATOR_CANCELLED;
1217                 
1218         /* calculate the paths for objects that have them (and are tagged to get refreshed) */
1219         ED_objects_recalculate_paths(C, scene);
1220         
1221         /* notifiers for updates */
1222         WM_event_add_notifier(C, NC_OBJECT | ND_TRANSFORM, NULL);
1223         
1224         return OPERATOR_FINISHED;
1225 }
1226
1227 void OBJECT_OT_paths_update(wmOperatorType *ot)
1228 {
1229         /* identifiers */
1230         ot->name = "Update Object Paths";
1231         ot->idname = "OBJECT_OT_paths_update";
1232         ot->description = "Recalculate paths for selected objects";
1233         
1234         /* api callbakcs */
1235         ot->exec = object_update_paths_exec;
1236         ot->poll = ED_operator_object_active_editable; /* TODO: this should probably check for existing paths */
1237         
1238         /* flags */
1239         ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
1240 }
1241
1242 /* --------- */
1243
1244 /* Clear motion paths for selected objects only */
1245 void ED_objects_clear_paths(bContext *C)
1246 {
1247         /* loop over objects in scene */
1248         CTX_DATA_BEGIN(C, Object *, ob, selected_editable_objects)
1249         {
1250                 if (ob->mpath) {
1251                         animviz_free_motionpath(ob->mpath);
1252                         ob->mpath = NULL;
1253                         ob->avs.path_bakeflag &= ~MOTIONPATH_BAKE_HAS_PATHS;
1254                 }
1255         }
1256         CTX_DATA_END;
1257 }
1258
1259 /* operator callback for this */
1260 static int object_clear_paths_exec(bContext *C, wmOperator *UNUSED(op))
1261 {       
1262         /* use the backend function for this */
1263         ED_objects_clear_paths(C);
1264         
1265         /* notifiers for updates */
1266         WM_event_add_notifier(C, NC_OBJECT | ND_TRANSFORM, NULL);
1267         
1268         return OPERATOR_FINISHED; 
1269 }
1270
1271 void OBJECT_OT_paths_clear(wmOperatorType *ot)
1272 {
1273         /* identifiers */
1274         ot->name = "Clear Object Paths";
1275         ot->idname = "OBJECT_OT_paths_clear";
1276         ot->description = "Clear path caches for selected objects";
1277         
1278         /* api callbacks */
1279         ot->exec = object_clear_paths_exec;
1280         ot->poll = ED_operator_object_active_editable;
1281         
1282         /* flags */
1283         ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
1284 }
1285
1286
1287 /********************** Smooth/Flat *********************/
1288
1289 static int shade_smooth_exec(bContext *C, wmOperator *op)
1290 {
1291         Curve *cu;
1292         Nurb *nu;
1293         int clear = (strcmp(op->idname, "OBJECT_OT_shade_flat") == 0);
1294         int done = FALSE;
1295
1296         CTX_DATA_BEGIN(C, Object *, ob, selected_editable_objects)
1297         {
1298
1299                 if (ob->type == OB_MESH) {
1300                         BKE_mesh_smooth_flag_set(ob, !clear);
1301
1302                         DAG_id_tag_update(&ob->id, OB_RECALC_DATA);
1303                         WM_event_add_notifier(C, NC_OBJECT | ND_DRAW, ob);
1304
1305                         done = TRUE;
1306                 }
1307                 else if (ELEM(ob->type, OB_SURF, OB_CURVE)) {
1308                         cu = ob->data;
1309
1310                         for (nu = cu->nurb.first; nu; nu = nu->next) {
1311                                 if (!clear) nu->flag |= ME_SMOOTH;
1312                                 else nu->flag &= ~ME_SMOOTH;
1313                         }
1314
1315                         DAG_id_tag_update(&ob->id, OB_RECALC_DATA);
1316                         WM_event_add_notifier(C, NC_OBJECT | ND_DRAW, ob);
1317
1318                         done = TRUE;
1319                 }
1320         }
1321         CTX_DATA_END;
1322
1323         return (done) ? OPERATOR_FINISHED : OPERATOR_CANCELLED;
1324 }
1325
1326 static int shade_poll(bContext *C)
1327 {
1328         return (ED_operator_object_active_editable(C) && !ED_operator_editmesh(C));
1329 }
1330
1331 void OBJECT_OT_shade_flat(wmOperatorType *ot)
1332 {
1333         /* identifiers */
1334         ot->name = "Shade Flat";
1335         ot->description = "Display faces 'flat'";
1336         ot->idname = "OBJECT_OT_shade_flat";
1337         
1338         /* api callbacks */
1339         ot->poll = shade_poll;
1340         ot->exec = shade_smooth_exec;
1341
1342         /* flags */
1343         ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
1344 }
1345
1346 void OBJECT_OT_shade_smooth(wmOperatorType *ot)
1347 {
1348         /* identifiers */
1349         ot->name = "Shade Smooth";
1350         ot->description = "Display faces 'smooth' (using vertex normals)";
1351         ot->idname = "OBJECT_OT_shade_smooth";
1352         
1353         /* api callbacks */
1354         ot->poll = shade_poll;
1355         ot->exec = shade_smooth_exec;
1356         
1357         /* flags */
1358         ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
1359 }
1360
1361 /* ********************** */
1362
1363 static void UNUSED_FUNCTION(image_aspect) (Scene * scene, View3D * v3d)
1364 {
1365         /* all selected objects with an image map: scale in image aspect */
1366         Base *base;
1367         Object *ob;
1368         Material *ma;
1369         Tex *tex;
1370         float x, y, space;
1371         int a, b, done;
1372         
1373         if (scene->obedit) return;  // XXX get from context
1374         if (scene->id.lib) return;
1375         
1376         for (base = FIRSTBASE; base; base = base->next) {
1377                 if (TESTBASELIB(v3d, base)) {
1378                         ob = base->object;
1379                         done = FALSE;
1380                         
1381                         for (a = 1; a <= ob->totcol; a++) {
1382                                 ma = give_current_material(ob, a);
1383                                 if (ma) {
1384                                         for (b = 0; b < MAX_MTEX; b++) {
1385                                                 if (ma->mtex[b] && ma->mtex[b]->tex) {
1386                                                         tex = ma->mtex[b]->tex;
1387                                                         if (tex->type == TEX_IMAGE && tex->ima) {
1388                                                                 ImBuf *ibuf = BKE_image_acquire_ibuf(tex->ima, NULL, NULL);
1389                                                                 
1390                                                                 /* texturespace */
1391                                                                 space = 1.0;
1392                                                                 if (ob->type == OB_MESH) {
1393                                                                         float size[3];
1394                                                                         BKE_mesh_texspace_get(ob->data, NULL, NULL, size);
1395                                                                         space = size[0] / size[1];
1396                                                                 }
1397                                                                 else if (ELEM3(ob->type, OB_CURVE, OB_FONT, OB_SURF)) {
1398                                                                         Curve *cu = ob->data;
1399                                                                         space = cu->size[0] / cu->size[1];
1400                                                                 }
1401                                                         
1402                                                                 x = ibuf->x / space;
1403                                                                 y = ibuf->y;
1404                                                                 
1405                                                                 if (x > y) ob->size[0] = ob->size[1] * x / y;
1406                                                                 else ob->size[1] = ob->size[0] * y / x;
1407                                                                 
1408                                                                 done = TRUE;
1409                                                                 DAG_id_tag_update(&ob->id, OB_RECALC_OB);
1410
1411                                                                 BKE_image_release_ibuf(tex->ima, ibuf, NULL);
1412                                                         }
1413                                                 }
1414                                                 if (done) break;
1415                                         }
1416                                 }
1417                                 if (done) break;
1418                         }
1419                 }
1420         }
1421         
1422 }
1423
1424
1425 static EnumPropertyItem *object_mode_set_itemsf(bContext *C, PointerRNA *UNUSED(ptr), PropertyRNA *UNUSED(prop), int *free)
1426 {       
1427         EnumPropertyItem *input = object_mode_items;
1428         EnumPropertyItem *item = NULL;
1429         Object *ob;
1430         int totitem = 0;
1431         
1432         if (!C) /* needed for docs */
1433                 return object_mode_items;
1434
1435
1436
1437         ob = CTX_data_active_object(C);
1438         while (ob && input->identifier) {
1439                 if ((input->value == OB_MODE_EDIT && OB_TYPE_SUPPORT_EDITMODE(ob->type)) ||
1440                     (input->value == OB_MODE_POSE && (ob->type == OB_ARMATURE)) ||
1441                     (input->value == OB_MODE_PARTICLE_EDIT && ob->particlesystem.first) ||
1442                     ((input->value == OB_MODE_SCULPT || input->value == OB_MODE_VERTEX_PAINT ||
1443                       input->value == OB_MODE_WEIGHT_PAINT || input->value == OB_MODE_TEXTURE_PAINT) && (ob->type == OB_MESH)) ||
1444                     (input->value == OB_MODE_OBJECT))
1445                 {
1446                         RNA_enum_item_add(&item, &totitem, input);
1447                 }
1448                 input++;
1449         }
1450
1451         RNA_enum_item_end(&item, &totitem);
1452
1453         *free = 1;
1454
1455         return item;
1456 }
1457
1458 static const char *object_mode_op_string(int mode)
1459 {
1460         if (mode & OB_MODE_EDIT)
1461                 return "OBJECT_OT_editmode_toggle";
1462         if (mode == OB_MODE_SCULPT)
1463                 return "SCULPT_OT_sculptmode_toggle";
1464         if (mode == OB_MODE_VERTEX_PAINT)
1465                 return "PAINT_OT_vertex_paint_toggle";
1466         if (mode == OB_MODE_WEIGHT_PAINT)
1467                 return "PAINT_OT_weight_paint_toggle";
1468         if (mode == OB_MODE_TEXTURE_PAINT)
1469                 return "PAINT_OT_texture_paint_toggle";
1470         if (mode == OB_MODE_PARTICLE_EDIT)
1471                 return "PARTICLE_OT_particle_edit_toggle";
1472         if (mode == OB_MODE_POSE)
1473                 return "OBJECT_OT_posemode_toggle";
1474         return NULL;
1475 }
1476
1477 /* checks the mode to be set is compatible with the object
1478  * should be made into a generic function */
1479 static int object_mode_set_compat(bContext *UNUSED(C), wmOperator *op, Object *ob)
1480 {
1481         ObjectMode mode = RNA_enum_get(op->ptr, "mode");
1482
1483         if (ob) {
1484                 if (mode == OB_MODE_OBJECT)
1485                         return 1;
1486
1487                 switch (ob->type) {
1488                         case OB_MESH:
1489                                 if (mode & (OB_MODE_EDIT | OB_MODE_SCULPT | OB_MODE_VERTEX_PAINT | OB_MODE_WEIGHT_PAINT | OB_MODE_TEXTURE_PAINT | OB_MODE_PARTICLE_EDIT))
1490                                         return 1;
1491                                 return 0;
1492                         case OB_CURVE:
1493                         case OB_SURF:
1494                         case OB_FONT:
1495                         case OB_MBALL:
1496                                 if (mode & (OB_MODE_EDIT))
1497                                         return 1;
1498                                 return 0;
1499                         case OB_LATTICE:
1500                                 if (mode & (OB_MODE_EDIT | OB_MODE_WEIGHT_PAINT))
1501                                         return 1;
1502                         case OB_ARMATURE:
1503                                 if (mode & (OB_MODE_EDIT | OB_MODE_POSE))
1504                                         return 1;
1505                 }
1506         }
1507
1508         return 0;
1509 }
1510
1511 static int object_mode_set_exec(bContext *C, wmOperator *op)
1512 {
1513         Object *ob = CTX_data_active_object(C);
1514         ObjectMode mode = RNA_enum_get(op->ptr, "mode");
1515         ObjectMode restore_mode = (ob) ? ob->mode : OB_MODE_OBJECT;
1516         int toggle = RNA_boolean_get(op->ptr, "toggle");
1517
1518         if (!ob || !object_mode_set_compat(C, op, ob))
1519                 return OPERATOR_PASS_THROUGH;
1520
1521         /* Exit current mode if it's not the mode we're setting */
1522         if (ob->mode != OB_MODE_OBJECT && ob->mode != mode)
1523                 WM_operator_name_call(C, object_mode_op_string(ob->mode), WM_OP_EXEC_REGION_WIN, NULL);
1524
1525         if (mode != OB_MODE_OBJECT) {
1526                 /* Enter new mode */
1527                 if (ob->mode != mode || toggle)
1528                         WM_operator_name_call(C, object_mode_op_string(mode), WM_OP_EXEC_REGION_WIN, NULL);
1529
1530                 if (toggle) {
1531                         if (ob->mode == mode)
1532                                 /* For toggling, store old mode so we know what to go back to */
1533                                 ob->restore_mode = restore_mode;
1534                         else if (ob->restore_mode != OB_MODE_OBJECT && ob->restore_mode != mode) {
1535                                 WM_operator_name_call(C, object_mode_op_string(ob->restore_mode), WM_OP_EXEC_REGION_WIN, NULL);
1536                         }
1537                 }
1538         }
1539
1540         return OPERATOR_FINISHED;
1541 }
1542
1543 void OBJECT_OT_mode_set(wmOperatorType *ot)
1544 {
1545         PropertyRNA *prop;
1546
1547         /* identifiers */
1548         ot->name = "Set Object Mode";
1549         ot->description = "Sets the object interaction mode";
1550         ot->idname = "OBJECT_OT_mode_set";
1551         
1552         /* api callbacks */
1553         ot->exec = object_mode_set_exec;
1554         
1555         ot->poll = ED_operator_object_active_editable;
1556         
1557         /* flags */
1558         ot->flag = 0; /* no register/undo here, leave it to operators being called */
1559         
1560         prop = RNA_def_enum(ot->srna, "mode", object_mode_items, OB_MODE_OBJECT, "Mode", "");
1561         RNA_def_enum_funcs(prop, object_mode_set_itemsf);
1562
1563         RNA_def_boolean(ot->srna, "toggle", 0, "Toggle", "");
1564 }
1565
1566
1567
1568 void ED_object_toggle_modes(bContext *C, int mode)
1569 {
1570         if (mode & OB_MODE_SCULPT)
1571                 WM_operator_name_call(C, "SCULPT_OT_sculptmode_toggle", WM_OP_EXEC_REGION_WIN, NULL);
1572         if (mode & OB_MODE_VERTEX_PAINT)
1573                 WM_operator_name_call(C, "PAINT_OT_vertex_paint_toggle", WM_OP_EXEC_REGION_WIN, NULL);
1574         if (mode & OB_MODE_WEIGHT_PAINT)
1575                 WM_operator_name_call(C, "PAINT_OT_weight_paint_toggle", WM_OP_EXEC_REGION_WIN, NULL);
1576         if (mode & OB_MODE_TEXTURE_PAINT)
1577                 WM_operator_name_call(C, "PAINT_OT_texture_paint_toggle", WM_OP_EXEC_REGION_WIN, NULL);
1578         if (mode & OB_MODE_PARTICLE_EDIT)
1579                 WM_operator_name_call(C, "PARTICLE_OT_particle_edit_toggle", WM_OP_EXEC_REGION_WIN, NULL);
1580         if (mode & OB_MODE_POSE)
1581                 WM_operator_name_call(C, "OBJECT_OT_posemode_toggle", WM_OP_EXEC_REGION_WIN, NULL);
1582         if (mode & OB_MODE_EDIT)
1583                 WM_operator_name_call(C, "OBJECT_OT_editmode_toggle", WM_OP_EXEC_REGION_WIN, NULL);
1584 }
1585
1586 /************************ Game Properties ***********************/
1587
1588 static int game_property_new(bContext *C, wmOperator *op)
1589 {
1590         Object *ob = CTX_data_active_object(C);
1591         bProperty *prop;
1592         char name[MAX_NAME];
1593         int type = RNA_enum_get(op->ptr, "type");
1594
1595         prop = BKE_bproperty_new(type);
1596         BLI_addtail(&ob->prop, prop);
1597
1598         RNA_string_get(op->ptr, "name", name);
1599         if (name[0] != '\0') {
1600                 BLI_strncpy(prop->name, name, sizeof(prop->name));
1601         }
1602
1603         BKE_bproperty_unique(NULL, prop, 0); // make_unique_prop_names(prop->name);
1604
1605         WM_event_add_notifier(C, NC_LOGIC, NULL);
1606         return OPERATOR_FINISHED;
1607 }
1608
1609
1610 void OBJECT_OT_game_property_new(wmOperatorType *ot)
1611 {
1612         /* identifiers */
1613         ot->name = "New Game Property";
1614         ot->description = "Create a new property available to the game engine";
1615         ot->idname = "OBJECT_OT_game_property_new";
1616
1617         /* api callbacks */
1618         ot->exec = game_property_new;
1619         ot->poll = ED_operator_object_active_editable;
1620
1621         /* flags */
1622         ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
1623
1624         RNA_def_enum(ot->srna, "type", gameproperty_type_items, GPROP_FLOAT, "Type", "Type of game property to add");
1625         RNA_def_string(ot->srna, "name", "", MAX_NAME, "Name", "Name of the game property to add");
1626 }
1627
1628 static int game_property_remove(bContext *C, wmOperator *op)
1629 {
1630         Object *ob = CTX_data_active_object(C);
1631         bProperty *prop;
1632         int index = RNA_int_get(op->ptr, "index");
1633
1634         if (!ob)
1635                 return OPERATOR_CANCELLED;
1636
1637         prop = BLI_findlink(&ob->prop, index);
1638
1639         if (prop) {
1640                 BLI_remlink(&ob->prop, prop);
1641                 BKE_bproperty_free(prop);
1642
1643                 WM_event_add_notifier(C, NC_LOGIC, NULL);
1644                 return OPERATOR_FINISHED;
1645         }
1646         else {
1647                 return OPERATOR_CANCELLED;
1648         }
1649 }
1650
1651 void OBJECT_OT_game_property_remove(wmOperatorType *ot)
1652 {
1653         /* identifiers */
1654         ot->name = "Remove Game Property";
1655         ot->description = "Remove game property";
1656         ot->idname = "OBJECT_OT_game_property_remove";
1657
1658         /* api callbacks */
1659         ot->exec = game_property_remove;
1660         ot->poll = ED_operator_object_active_editable;
1661
1662         /* flags */
1663         ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
1664
1665         RNA_def_int(ot->srna, "index", 0, 0, INT_MAX, "Index", "Property index to remove ", 0, INT_MAX);
1666 }
1667
1668 #define COPY_PROPERTIES_REPLACE 1
1669 #define COPY_PROPERTIES_MERGE   2
1670 #define COPY_PROPERTIES_COPY    3
1671
1672 static EnumPropertyItem game_properties_copy_operations[] = {
1673         {COPY_PROPERTIES_REPLACE, "REPLACE", 0, "Replace Properties", ""},
1674         {COPY_PROPERTIES_MERGE, "MERGE", 0, "Merge Properties", ""},
1675         {COPY_PROPERTIES_COPY, "COPY", 0, "Copy a Property", ""},
1676         {0, NULL, 0, NULL, NULL}
1677 };
1678
1679 static EnumPropertyItem gameprops_items[] = {
1680         {0, NULL, 0, NULL, NULL}
1681 };
1682
1683 static EnumPropertyItem *gameprops_itemf(bContext *C, PointerRNA *UNUSED(ptr), PropertyRNA *UNUSED(prop), int *free)
1684 {       
1685         Object *ob = ED_object_active_context(C);
1686         EnumPropertyItem tmp = {0, "", 0, "", ""};
1687         EnumPropertyItem *item = NULL;
1688         bProperty *prop;
1689         int a, totitem = 0;
1690         
1691         if (!ob)
1692                 return gameprops_items;
1693
1694         for (a = 1, prop = ob->prop.first; prop; prop = prop->next, a++) {
1695                 tmp.value = a;
1696                 tmp.identifier = prop->name;
1697                 tmp.name = prop->name;
1698                 RNA_enum_item_add(&item, &totitem, &tmp);
1699         }
1700
1701         RNA_enum_item_end(&item, &totitem);
1702         *free = 1;
1703
1704         return item;
1705 }
1706
1707 static int game_property_copy_exec(bContext *C, wmOperator *op)
1708 {
1709         Object *ob = ED_object_active_context(C);
1710         bProperty *prop;
1711         int type = RNA_enum_get(op->ptr, "operation");
1712         int propid = RNA_enum_get(op->ptr, "property");
1713
1714         if (propid > 0) { /* copy */
1715                 prop = BLI_findlink(&ob->prop, propid - 1);
1716                 
1717                 if (prop) {
1718                         CTX_DATA_BEGIN(C, Object *, ob_iter, selected_editable_objects)
1719                         {
1720                                 if (ob != ob_iter)
1721                                         BKE_bproperty_object_set(ob_iter, prop);
1722                         } CTX_DATA_END;
1723                 }
1724         }
1725
1726         else {
1727                 CTX_DATA_BEGIN(C, Object *, ob_iter, selected_editable_objects)
1728                 {
1729                         if (ob != ob_iter) {
1730                                 if (type == COPY_PROPERTIES_REPLACE) {
1731                                         BKE_bproperty_copy_list(&ob_iter->prop, &ob->prop);
1732                                 }
1733                                 else {
1734                                         /* merge - the default when calling with no argument */
1735                                         for (prop = ob->prop.first; prop; prop = prop->next) {
1736                                                 BKE_bproperty_object_set(ob_iter, prop);
1737                                         }
1738                                 }
1739                         }
1740                 }
1741                 CTX_DATA_END;
1742         }
1743
1744         return OPERATOR_FINISHED;
1745 }
1746
1747 void OBJECT_OT_game_property_copy(wmOperatorType *ot)
1748 {
1749         PropertyRNA *prop;
1750         /* identifiers */
1751         ot->name = "Copy Game Property";
1752         ot->idname = "OBJECT_OT_game_property_copy";
1753         ot->description = "Copy/merge/replace a game property from active object to all selected objects";
1754
1755         /* api callbacks */
1756         ot->exec = game_property_copy_exec;
1757         ot->poll = ED_operator_object_active_editable;
1758
1759         /* flags */
1760         ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
1761
1762         RNA_def_enum(ot->srna, "operation", game_properties_copy_operations, 3, "Operation", "");
1763         prop = RNA_def_enum(ot->srna, "property", gameprops_items, 0, "Property", "Properties to copy");
1764         RNA_def_property_flag(prop, PROP_SKIP_SAVE);
1765         RNA_def_enum_funcs(prop, gameprops_itemf);
1766         ot->prop = prop;
1767 }
1768
1769 static int game_property_clear_exec(bContext *C, wmOperator *UNUSED(op))
1770 {
1771         CTX_DATA_BEGIN(C, Object *, ob_iter, selected_editable_objects)
1772         {
1773                 BKE_bproperty_free_list(&ob_iter->prop);
1774         }
1775         CTX_DATA_END;
1776
1777         WM_event_add_notifier(C, NC_LOGIC, NULL);
1778         return OPERATOR_FINISHED;
1779 }
1780 void OBJECT_OT_game_property_clear(wmOperatorType *ot)
1781 {
1782         /* identifiers */
1783         ot->name = "Clear Game Properties";
1784         ot->idname = "OBJECT_OT_game_property_clear";
1785         ot->description = "Remove all game properties from all selected objects";
1786
1787         /* api callbacks */
1788         ot->exec = game_property_clear_exec;
1789         ot->poll = ED_operator_object_active_editable;
1790
1791         /* flags */
1792         ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
1793 }
1794
1795 /************************ Copy Logic Bricks ***********************/
1796
1797 static int logicbricks_copy_exec(bContext *C, wmOperator *UNUSED(op))
1798 {
1799         Object *ob = ED_object_active_context(C);
1800
1801         CTX_DATA_BEGIN(C, Object *, ob_iter, selected_editable_objects)
1802         {
1803                 if (ob != ob_iter) {
1804                         /* first: free all logic */
1805                         free_sensors(&ob_iter->sensors);
1806                         unlink_controllers(&ob_iter->controllers);
1807                         free_controllers(&ob_iter->controllers);
1808                         unlink_actuators(&ob_iter->actuators);
1809                         free_actuators(&ob_iter->actuators);
1810                 
1811                         /* now copy it, this also works without logicbricks! */
1812                         clear_sca_new_poins_ob(ob);
1813                         copy_sensors(&ob_iter->sensors, &ob->sensors);
1814                         copy_controllers(&ob_iter->controllers, &ob->controllers);
1815                         copy_actuators(&ob_iter->actuators, &ob->actuators);
1816                         set_sca_new_poins_ob(ob_iter);
1817                 
1818                         /* some menu settings */
1819                         ob_iter->scavisflag = ob->scavisflag;
1820                         ob_iter->scaflag = ob->scaflag;
1821                 
1822                         /* set the initial state */
1823                         ob_iter->state = ob->state;
1824                         ob_iter->init_state = ob->init_state;
1825
1826                         if (ob_iter->totcol == ob->totcol) {
1827                                 ob_iter->actcol = ob->actcol;
1828                                 WM_event_add_notifier(C, NC_OBJECT | ND_DRAW, ob_iter);
1829                         }
1830                 }
1831         }
1832         CTX_DATA_END;
1833
1834         WM_event_add_notifier(C, NC_LOGIC, NULL);
1835
1836         return OPERATOR_FINISHED;
1837 }
1838
1839 void OBJECT_OT_logic_bricks_copy(wmOperatorType *ot)
1840 {
1841         /* identifiers */
1842         ot->name = "Copy Logic Bricks to Selected";
1843         ot->description = "Copy logic bricks to other selected objects";
1844         ot->idname = "OBJECT_OT_logic_bricks_copy";
1845
1846         /* api callbacks */
1847         ot->exec = logicbricks_copy_exec;
1848         ot->poll = ED_operator_object_active_editable;
1849
1850         /* flags */
1851         ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
1852 }
1853
1854 static int game_physics_copy_exec(bContext *C, wmOperator *UNUSED(op))
1855 {
1856         Object *ob = ED_object_active_context(C);
1857         
1858         CTX_DATA_BEGIN(C, Object *, ob_iter, selected_editable_objects)
1859         {
1860                 if (ob != ob_iter) {
1861                         ob_iter->gameflag = ob->gameflag;
1862                         ob_iter->gameflag2 = ob->gameflag2;
1863                         ob_iter->inertia = ob->inertia;
1864                         ob_iter->formfactor = ob->formfactor;
1865                         ob_iter->damping = ob->damping;
1866                         ob_iter->rdamping = ob->rdamping;
1867                         ob_iter->min_vel = ob->min_vel;
1868                         ob_iter->max_vel = ob->max_vel;
1869                         ob_iter->obstacleRad = ob->obstacleRad;
1870                         ob_iter->mass = ob->mass;
1871                         ob_iter->anisotropicFriction[0] = ob->anisotropicFriction[0];
1872                         ob_iter->anisotropicFriction[1] = ob->anisotropicFriction[1];
1873                         ob_iter->anisotropicFriction[2] = ob->anisotropicFriction[2];
1874                         ob_iter->collision_boundtype = ob->collision_boundtype;
1875                         ob_iter->margin = ob->margin;
1876                         ob_iter->bsoft = copy_bulletsoftbody(ob->bsoft);
1877                         if (ob->restrictflag & OB_RESTRICT_RENDER) 
1878                                 ob_iter->restrictflag |= OB_RESTRICT_RENDER;
1879                         else
1880                                 ob_iter->restrictflag &= ~OB_RESTRICT_RENDER;
1881                 }
1882         }
1883         CTX_DATA_END;
1884         
1885         return OPERATOR_FINISHED;
1886 }
1887
1888 void OBJECT_OT_game_physics_copy(struct wmOperatorType *ot)
1889 {
1890         /* identifiers */
1891         ot->name = "Copy Game Physics Properties to Selected";
1892         ot->description = "Copy game physics properties to other selected objects";
1893         ot->idname = "OBJECT_OT_game_physics_copy";
1894         
1895         /* api callbacks */
1896         ot->exec = game_physics_copy_exec;
1897         ot->poll = ED_operator_object_active_editable;
1898         
1899         /* flags */
1900         ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
1901 }