b94c9e940dca76395efa6fdde9ca26682b977a11
[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_relations_tag_update(bmain);
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_relations_tag_update(bmain);
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, scene, 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         bool do_depgraph_update = 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                                 DAG_id_tag_update(&base->object->id, OB_RECALC_DATA);
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                                                 DAG_id_tag_update(&base->object->id, 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                                                 DAG_id_tag_update(&base->object->id, 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                                                 DAG_id_tag_update(&base->object->id, 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                                                         DAG_id_tag_update(&base->object->id, OB_RECALC_DATA);
952                                                 }
953                                         }
954                                 }
955                                 else if (event == 22) {
956                                         /* Copy the constraint channels over */
957                                         BKE_copy_constraints(&base->object->constraints, &ob->constraints, TRUE);
958                                         
959                                         do_depgraph_update = 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_depgraph_update)
1012                 DAG_relations_tag_update(bmain);
1013 }
1014
1015 static void UNUSED_FUNCTION(copy_attr_menu) (Main * bmain, Scene * scene, View3D * v3d)
1016 {
1017         Object *ob;
1018         short event;
1019         char str[512];
1020         
1021         if (!(ob = OBACT)) return;
1022         
1023         if (scene->obedit) { /* XXX get from context */
1024 /*              if (ob->type == OB_MESH) */
1025 /* XXX                  mesh_copy_menu(); */
1026                 return;
1027         }
1028         
1029         /* Object Mode */
1030         
1031         /* If you change this menu, don't forget to update the menu in header_view3d.c
1032          * view3d_edit_object_copyattrmenu() and in toolbox.c
1033          */
1034         
1035         strcpy(str,
1036                "Copy Attributes %t|Location %x1|Rotation %x2|Size %x3|Draw Options %x4|"
1037                "Time Offset %x5|Dupli %x6|Object Color %x31|%l|Mass %x7|Damping %x8|All Physical Attributes %x11|Properties %x9|"
1038                "Logic Bricks %x10|Protected Transform %x29|%l");
1039         
1040         strcat(str, "|Object Constraints %x22");
1041         strcat(str, "|NLA Strips %x26");
1042         
1043 /* XXX  if (OB_TYPE_SUPPORT_MATERIAL(ob->type)) { */
1044 /*              strcat(str, "|Texture Space %x17"); */
1045 /*      } */
1046         
1047         if (ob->type == OB_FONT) strcat(str, "|Font Settings %x18|Bevel Settings %x19");
1048         if (ob->type == OB_CURVE) strcat(str, "|Bevel Settings %x19|UV Orco %x28");
1049         
1050         if ((ob->type == OB_FONT) || (ob->type == OB_CURVE)) {
1051                 strcat(str, "|Curve Resolution %x25");
1052         }
1053
1054         if (ob->type == OB_MESH) {
1055                 strcat(str, "|Subsurf Settings %x21|AutoSmooth %x27");
1056         }
1057
1058         if (ob->soft) strcat(str, "|Soft Body Settings %x23");
1059         
1060         strcat(str, "|Pass Index %x30");
1061         
1062         if (ob->type == OB_MESH || ob->type == OB_CURVE || ob->type == OB_LATTICE || ob->type == OB_SURF) {
1063                 strcat(str, "|Modifiers ... %x24");
1064         }
1065
1066         event = pupmenu(str);
1067         if (event <= 0) return;
1068         
1069         copy_attr(bmain, scene, v3d, event);
1070 }
1071
1072 /* ******************* force field toggle operator ***************** */
1073
1074 static int forcefield_toggle_exec(bContext *C, wmOperator *UNUSED(op))
1075 {
1076         Object *ob = CTX_data_active_object(C);
1077
1078         if (ob->pd == NULL)
1079                 ob->pd = object_add_collision_fields(PFIELD_FORCE);
1080
1081         if (ob->pd->forcefield == 0)
1082                 ob->pd->forcefield = PFIELD_FORCE;
1083         else
1084                 ob->pd->forcefield = 0;
1085         
1086         WM_event_add_notifier(C, NC_OBJECT | ND_DRAW, NULL);
1087
1088         return OPERATOR_FINISHED;
1089 }
1090
1091 void OBJECT_OT_forcefield_toggle(wmOperatorType *ot)
1092 {
1093         
1094         /* identifiers */
1095         ot->name = "Toggle Force Field";
1096         ot->description = "Toggle object's force field";
1097         ot->idname = "OBJECT_OT_forcefield_toggle";
1098         
1099         /* api callbacks */
1100         ot->exec = forcefield_toggle_exec;
1101         ot->poll = ED_operator_object_active_editable;
1102         
1103         /* flags */
1104         ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
1105 }
1106
1107 /* ********************************************** */
1108 /* Motion Paths */
1109
1110 /* For the objects with animation: update paths for those that have got them
1111  * This should selectively update paths that exist...
1112  *
1113  * To be called from various tools that do incremental updates 
1114  */
1115 void ED_objects_recalculate_paths(bContext *C, Scene *scene)
1116 {
1117         ListBase targets = {NULL, NULL};
1118         
1119         /* loop over objects in scene */
1120         CTX_DATA_BEGIN(C, Object *, ob, selected_editable_objects)
1121         {
1122                 /* set flag to force recalc, then grab path(s) from object */
1123                 ob->avs.recalc |= ANIMVIZ_RECALC_PATHS;
1124                 animviz_get_object_motionpaths(ob, &targets);
1125         }
1126         CTX_DATA_END;
1127         
1128         /* recalculate paths, then free */
1129         animviz_calc_motionpaths(scene, &targets);
1130         BLI_freelistN(&targets);
1131 }
1132
1133
1134 /* show popup to determine settings */
1135 static int object_calculate_paths_invoke(bContext *C, wmOperator *op, wmEvent *UNUSED(event))
1136 {
1137         Object *ob = CTX_data_active_object(C);
1138         
1139         if (ob == NULL)
1140                 return OPERATOR_CANCELLED;
1141         
1142         /* set default settings from existing/stored settings */
1143         {
1144                 bAnimVizSettings *avs = &ob->avs;
1145                 
1146                 RNA_int_set(op->ptr, "start_frame", avs->path_sf);
1147                 RNA_int_set(op->ptr, "end_frame", avs->path_ef);
1148         }
1149         
1150         /* show popup dialog to allow editing of range... */
1151         /* FIXME: hardcoded dimensions here are just arbitrary */
1152         return WM_operator_props_dialog_popup(C, op, 10 * UI_UNIT_X, 10 * UI_UNIT_Y);
1153 }
1154
1155 /* Calculate/recalculate whole paths (avs.path_sf to avs.path_ef) */
1156 static int object_calculate_paths_exec(bContext *C, wmOperator *op)
1157 {
1158         Scene *scene = CTX_data_scene(C);
1159         int start = RNA_int_get(op->ptr, "start_frame");
1160         int end = RNA_int_get(op->ptr, "end_frame");
1161         
1162         /* set up path data for bones being calculated */
1163         CTX_DATA_BEGIN(C, Object *, ob, selected_editable_objects)
1164         {
1165                 bAnimVizSettings *avs = &ob->avs;
1166                 
1167                 /* grab baking settings from operator settings */
1168                 avs->path_sf = start;
1169                 avs->path_ef = end;
1170                 
1171                 /* verify that the selected object has the appropriate settings */
1172                 animviz_verify_motionpaths(op->reports, scene, ob, NULL);
1173         }
1174         CTX_DATA_END;
1175         
1176         /* calculate the paths for objects that have them (and are tagged to get refreshed) */
1177         ED_objects_recalculate_paths(C, scene);
1178         
1179         /* notifiers for updates */
1180         WM_event_add_notifier(C, NC_OBJECT | ND_TRANSFORM, NULL);
1181         
1182         return OPERATOR_FINISHED; 
1183 }
1184
1185 void OBJECT_OT_paths_calculate(wmOperatorType *ot)
1186 {
1187         /* identifiers */
1188         ot->name = "Calculate Object Paths";
1189         ot->idname = "OBJECT_OT_paths_calculate";
1190         ot->description = "Calculate motion paths for the selected objects";
1191         
1192         /* api callbacks */
1193         ot->invoke = object_calculate_paths_invoke;
1194         ot->exec = object_calculate_paths_exec;
1195         ot->poll = ED_operator_object_active_editable;
1196         
1197         /* flags */
1198         ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
1199         
1200         /* properties */
1201         RNA_def_int(ot->srna, "start_frame", 1, MINAFRAME, MAXFRAME, "Start", 
1202                     "First frame to calculate object paths on", MINFRAME, MAXFRAME / 2.0);
1203         RNA_def_int(ot->srna, "end_frame", 250, MINAFRAME, MAXFRAME, "End", 
1204                     "Last frame to calculate object paths on", MINFRAME, MAXFRAME / 2.0);
1205 }
1206
1207 /* --------- */
1208
1209 static int object_update_paths_exec(bContext *C, wmOperator *UNUSED(op))
1210 {
1211         Scene *scene = CTX_data_scene(C);
1212         
1213         if (scene == NULL)
1214                 return OPERATOR_CANCELLED;
1215                 
1216         /* calculate the paths for objects that have them (and are tagged to get refreshed) */
1217         ED_objects_recalculate_paths(C, scene);
1218         
1219         /* notifiers for updates */
1220         WM_event_add_notifier(C, NC_OBJECT | ND_TRANSFORM, NULL);
1221         
1222         return OPERATOR_FINISHED;
1223 }
1224
1225 void OBJECT_OT_paths_update(wmOperatorType *ot)
1226 {
1227         /* identifiers */
1228         ot->name = "Update Object Paths";
1229         ot->idname = "OBJECT_OT_paths_update";
1230         ot->description = "Recalculate paths for selected objects";
1231         
1232         /* api callbakcs */
1233         ot->exec = object_update_paths_exec;
1234         ot->poll = ED_operator_object_active_editable; /* TODO: this should probably check for existing paths */
1235         
1236         /* flags */
1237         ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
1238 }
1239
1240 /* --------- */
1241
1242 /* Clear motion paths for selected objects only */
1243 void ED_objects_clear_paths(bContext *C)
1244 {
1245         /* loop over objects in scene */
1246         CTX_DATA_BEGIN(C, Object *, ob, selected_editable_objects)
1247         {
1248                 if (ob->mpath) {
1249                         animviz_free_motionpath(ob->mpath);
1250                         ob->mpath = NULL;
1251                         ob->avs.path_bakeflag &= ~MOTIONPATH_BAKE_HAS_PATHS;
1252                 }
1253         }
1254         CTX_DATA_END;
1255 }
1256
1257 /* operator callback for this */
1258 static int object_clear_paths_exec(bContext *C, wmOperator *UNUSED(op))
1259 {       
1260         /* use the backend function for this */
1261         ED_objects_clear_paths(C);
1262         
1263         /* notifiers for updates */
1264         WM_event_add_notifier(C, NC_OBJECT | ND_TRANSFORM, NULL);
1265         
1266         return OPERATOR_FINISHED; 
1267 }
1268
1269 void OBJECT_OT_paths_clear(wmOperatorType *ot)
1270 {
1271         /* identifiers */
1272         ot->name = "Clear Object Paths";
1273         ot->idname = "OBJECT_OT_paths_clear";
1274         ot->description = "Clear path caches for selected objects";
1275         
1276         /* api callbacks */
1277         ot->exec = object_clear_paths_exec;
1278         ot->poll = ED_operator_object_active_editable;
1279         
1280         /* flags */
1281         ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
1282 }
1283
1284
1285 /********************** Smooth/Flat *********************/
1286
1287 static int shade_smooth_exec(bContext *C, wmOperator *op)
1288 {
1289         Curve *cu;
1290         Nurb *nu;
1291         int clear = (strcmp(op->idname, "OBJECT_OT_shade_flat") == 0);
1292         int done = FALSE;
1293
1294         CTX_DATA_BEGIN(C, Object *, ob, selected_editable_objects)
1295         {
1296
1297                 if (ob->type == OB_MESH) {
1298                         BKE_mesh_smooth_flag_set(ob, !clear);
1299
1300                         DAG_id_tag_update(&ob->id, OB_RECALC_DATA);
1301                         WM_event_add_notifier(C, NC_OBJECT | ND_DRAW, ob);
1302
1303                         done = TRUE;
1304                 }
1305                 else if (ELEM(ob->type, OB_SURF, OB_CURVE)) {
1306                         cu = ob->data;
1307
1308                         for (nu = cu->nurb.first; nu; nu = nu->next) {
1309                                 if (!clear) nu->flag |= ME_SMOOTH;
1310                                 else nu->flag &= ~ME_SMOOTH;
1311                         }
1312
1313                         DAG_id_tag_update(&ob->id, OB_RECALC_DATA);
1314                         WM_event_add_notifier(C, NC_OBJECT | ND_DRAW, ob);
1315
1316                         done = TRUE;
1317                 }
1318         }
1319         CTX_DATA_END;
1320
1321         return (done) ? OPERATOR_FINISHED : OPERATOR_CANCELLED;
1322 }
1323
1324 static int shade_poll(bContext *C)
1325 {
1326         return (ED_operator_object_active_editable(C) && !ED_operator_editmesh(C));
1327 }
1328
1329 void OBJECT_OT_shade_flat(wmOperatorType *ot)
1330 {
1331         /* identifiers */
1332         ot->name = "Shade Flat";
1333         ot->description = "Display faces 'flat'";
1334         ot->idname = "OBJECT_OT_shade_flat";
1335         
1336         /* api callbacks */
1337         ot->poll = shade_poll;
1338         ot->exec = shade_smooth_exec;
1339
1340         /* flags */
1341         ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
1342 }
1343
1344 void OBJECT_OT_shade_smooth(wmOperatorType *ot)
1345 {
1346         /* identifiers */
1347         ot->name = "Shade Smooth";
1348         ot->description = "Display faces 'smooth' (using vertex normals)";
1349         ot->idname = "OBJECT_OT_shade_smooth";
1350         
1351         /* api callbacks */
1352         ot->poll = shade_poll;
1353         ot->exec = shade_smooth_exec;
1354         
1355         /* flags */
1356         ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
1357 }
1358
1359 /* ********************** */
1360
1361 static void UNUSED_FUNCTION(image_aspect) (Scene * scene, View3D * v3d)
1362 {
1363         /* all selected objects with an image map: scale in image aspect */
1364         Base *base;
1365         Object *ob;
1366         Material *ma;
1367         Tex *tex;
1368         float x, y, space;
1369         int a, b, done;
1370         
1371         if (scene->obedit) return;  // XXX get from context
1372         if (scene->id.lib) return;
1373         
1374         for (base = FIRSTBASE; base; base = base->next) {
1375                 if (TESTBASELIB(v3d, base)) {
1376                         ob = base->object;
1377                         done = FALSE;
1378                         
1379                         for (a = 1; a <= ob->totcol; a++) {
1380                                 ma = give_current_material(ob, a);
1381                                 if (ma) {
1382                                         for (b = 0; b < MAX_MTEX; b++) {
1383                                                 if (ma->mtex[b] && ma->mtex[b]->tex) {
1384                                                         tex = ma->mtex[b]->tex;
1385                                                         if (tex->type == TEX_IMAGE && tex->ima) {
1386                                                                 ImBuf *ibuf = BKE_image_acquire_ibuf(tex->ima, NULL, NULL);
1387                                                                 
1388                                                                 /* texturespace */
1389                                                                 space = 1.0;
1390                                                                 if (ob->type == OB_MESH) {
1391                                                                         float size[3];
1392                                                                         BKE_mesh_texspace_get(ob->data, NULL, NULL, size);
1393                                                                         space = size[0] / size[1];
1394                                                                 }
1395                                                                 else if (ELEM3(ob->type, OB_CURVE, OB_FONT, OB_SURF)) {
1396                                                                         Curve *cu = ob->data;
1397                                                                         space = cu->size[0] / cu->size[1];
1398                                                                 }
1399                                                         
1400                                                                 x = ibuf->x / space;
1401                                                                 y = ibuf->y;
1402                                                                 
1403                                                                 if (x > y) ob->size[0] = ob->size[1] * x / y;
1404                                                                 else ob->size[1] = ob->size[0] * y / x;
1405                                                                 
1406                                                                 done = TRUE;
1407                                                                 DAG_id_tag_update(&ob->id, OB_RECALC_OB);
1408
1409                                                                 BKE_image_release_ibuf(tex->ima, ibuf, NULL);
1410                                                         }
1411                                                 }
1412                                                 if (done) break;
1413                                         }
1414                                 }
1415                                 if (done) break;
1416                         }
1417                 }
1418         }
1419         
1420 }
1421
1422
1423 static EnumPropertyItem *object_mode_set_itemsf(bContext *C, PointerRNA *UNUSED(ptr), PropertyRNA *UNUSED(prop), int *free)
1424 {       
1425         EnumPropertyItem *input = object_mode_items;
1426         EnumPropertyItem *item = NULL;
1427         Object *ob;
1428         int totitem = 0;
1429         
1430         if (!C) /* needed for docs */
1431                 return object_mode_items;
1432
1433
1434
1435         ob = CTX_data_active_object(C);
1436         while (ob && input->identifier) {
1437                 if ((input->value == OB_MODE_EDIT && OB_TYPE_SUPPORT_EDITMODE(ob->type)) ||
1438                     (input->value == OB_MODE_POSE && (ob->type == OB_ARMATURE)) ||
1439                     (input->value == OB_MODE_PARTICLE_EDIT && ob->particlesystem.first) ||
1440                     ((input->value == OB_MODE_SCULPT || input->value == OB_MODE_VERTEX_PAINT ||
1441                       input->value == OB_MODE_WEIGHT_PAINT || input->value == OB_MODE_TEXTURE_PAINT) && (ob->type == OB_MESH)) ||
1442                     (input->value == OB_MODE_OBJECT))
1443                 {
1444                         RNA_enum_item_add(&item, &totitem, input);
1445                 }
1446                 input++;
1447         }
1448
1449         RNA_enum_item_end(&item, &totitem);
1450
1451         *free = 1;
1452
1453         return item;
1454 }
1455
1456 static const char *object_mode_op_string(int mode)
1457 {
1458         if (mode & OB_MODE_EDIT)
1459                 return "OBJECT_OT_editmode_toggle";
1460         if (mode == OB_MODE_SCULPT)
1461                 return "SCULPT_OT_sculptmode_toggle";
1462         if (mode == OB_MODE_VERTEX_PAINT)
1463                 return "PAINT_OT_vertex_paint_toggle";
1464         if (mode == OB_MODE_WEIGHT_PAINT)
1465                 return "PAINT_OT_weight_paint_toggle";
1466         if (mode == OB_MODE_TEXTURE_PAINT)
1467                 return "PAINT_OT_texture_paint_toggle";
1468         if (mode == OB_MODE_PARTICLE_EDIT)
1469                 return "PARTICLE_OT_particle_edit_toggle";
1470         if (mode == OB_MODE_POSE)
1471                 return "OBJECT_OT_posemode_toggle";
1472         return NULL;
1473 }
1474
1475 /* checks the mode to be set is compatible with the object
1476  * should be made into a generic function */
1477 static int object_mode_set_compat(bContext *UNUSED(C), wmOperator *op, Object *ob)
1478 {
1479         ObjectMode mode = RNA_enum_get(op->ptr, "mode");
1480
1481         if (ob) {
1482                 if (mode == OB_MODE_OBJECT)
1483                         return 1;
1484
1485                 switch (ob->type) {
1486                         case OB_MESH:
1487                                 if (mode & (OB_MODE_EDIT | OB_MODE_SCULPT | OB_MODE_VERTEX_PAINT | OB_MODE_WEIGHT_PAINT | OB_MODE_TEXTURE_PAINT | OB_MODE_PARTICLE_EDIT))
1488                                         return 1;
1489                                 return 0;
1490                         case OB_CURVE:
1491                         case OB_SURF:
1492                         case OB_FONT:
1493                         case OB_MBALL:
1494                                 if (mode & (OB_MODE_EDIT))
1495                                         return 1;
1496                                 return 0;
1497                         case OB_LATTICE:
1498                                 if (mode & (OB_MODE_EDIT | OB_MODE_WEIGHT_PAINT))
1499                                         return 1;
1500                         case OB_ARMATURE:
1501                                 if (mode & (OB_MODE_EDIT | OB_MODE_POSE))
1502                                         return 1;
1503                 }
1504         }
1505
1506         return 0;
1507 }
1508
1509 static int object_mode_set_exec(bContext *C, wmOperator *op)
1510 {
1511         Object *ob = CTX_data_active_object(C);
1512         ObjectMode mode = RNA_enum_get(op->ptr, "mode");
1513         ObjectMode restore_mode = (ob) ? ob->mode : OB_MODE_OBJECT;
1514         int toggle = RNA_boolean_get(op->ptr, "toggle");
1515
1516         if (!ob || !object_mode_set_compat(C, op, ob))
1517                 return OPERATOR_PASS_THROUGH;
1518
1519         /* Exit current mode if it's not the mode we're setting */
1520         if (ob->mode != OB_MODE_OBJECT && ob->mode != mode)
1521                 WM_operator_name_call(C, object_mode_op_string(ob->mode), WM_OP_EXEC_REGION_WIN, NULL);
1522
1523         if (mode != OB_MODE_OBJECT) {
1524                 /* Enter new mode */
1525                 if (ob->mode != mode || toggle)
1526                         WM_operator_name_call(C, object_mode_op_string(mode), WM_OP_EXEC_REGION_WIN, NULL);
1527
1528                 if (toggle) {
1529                         if (ob->mode == mode)
1530                                 /* For toggling, store old mode so we know what to go back to */
1531                                 ob->restore_mode = restore_mode;
1532                         else if (ob->restore_mode != OB_MODE_OBJECT && ob->restore_mode != mode) {
1533                                 WM_operator_name_call(C, object_mode_op_string(ob->restore_mode), WM_OP_EXEC_REGION_WIN, NULL);
1534                         }
1535                 }
1536         }
1537
1538         return OPERATOR_FINISHED;
1539 }
1540
1541 void OBJECT_OT_mode_set(wmOperatorType *ot)
1542 {
1543         PropertyRNA *prop;
1544
1545         /* identifiers */
1546         ot->name = "Set Object Mode";
1547         ot->description = "Sets the object interaction mode";
1548         ot->idname = "OBJECT_OT_mode_set";
1549         
1550         /* api callbacks */
1551         ot->exec = object_mode_set_exec;
1552         
1553         ot->poll = ED_operator_object_active_editable;
1554         
1555         /* flags */
1556         ot->flag = 0; /* no register/undo here, leave it to operators being called */
1557         
1558         prop = RNA_def_enum(ot->srna, "mode", object_mode_items, OB_MODE_OBJECT, "Mode", "");
1559         RNA_def_enum_funcs(prop, object_mode_set_itemsf);
1560
1561         RNA_def_boolean(ot->srna, "toggle", 0, "Toggle", "");
1562 }
1563
1564
1565
1566 void ED_object_toggle_modes(bContext *C, int mode)
1567 {
1568         if (mode & OB_MODE_SCULPT)
1569                 WM_operator_name_call(C, "SCULPT_OT_sculptmode_toggle", WM_OP_EXEC_REGION_WIN, NULL);
1570         if (mode & OB_MODE_VERTEX_PAINT)
1571                 WM_operator_name_call(C, "PAINT_OT_vertex_paint_toggle", WM_OP_EXEC_REGION_WIN, NULL);
1572         if (mode & OB_MODE_WEIGHT_PAINT)
1573                 WM_operator_name_call(C, "PAINT_OT_weight_paint_toggle", WM_OP_EXEC_REGION_WIN, NULL);
1574         if (mode & OB_MODE_TEXTURE_PAINT)
1575                 WM_operator_name_call(C, "PAINT_OT_texture_paint_toggle", WM_OP_EXEC_REGION_WIN, NULL);
1576         if (mode & OB_MODE_PARTICLE_EDIT)
1577                 WM_operator_name_call(C, "PARTICLE_OT_particle_edit_toggle", WM_OP_EXEC_REGION_WIN, NULL);
1578         if (mode & OB_MODE_POSE)
1579                 WM_operator_name_call(C, "OBJECT_OT_posemode_toggle", WM_OP_EXEC_REGION_WIN, NULL);
1580         if (mode & OB_MODE_EDIT)
1581                 WM_operator_name_call(C, "OBJECT_OT_editmode_toggle", WM_OP_EXEC_REGION_WIN, NULL);
1582 }
1583
1584 /************************ Game Properties ***********************/
1585
1586 static int game_property_new(bContext *C, wmOperator *op)
1587 {
1588         Object *ob = CTX_data_active_object(C);
1589         bProperty *prop;
1590         char name[MAX_NAME];
1591         int type = RNA_enum_get(op->ptr, "type");
1592
1593         prop = BKE_bproperty_new(type);
1594         BLI_addtail(&ob->prop, prop);
1595
1596         RNA_string_get(op->ptr, "name", name);
1597         if (name[0] != '\0') {
1598                 BLI_strncpy(prop->name, name, sizeof(prop->name));
1599         }
1600
1601         BKE_bproperty_unique(NULL, prop, 0); // make_unique_prop_names(prop->name);
1602
1603         WM_event_add_notifier(C, NC_LOGIC, NULL);
1604         return OPERATOR_FINISHED;
1605 }
1606
1607
1608 void OBJECT_OT_game_property_new(wmOperatorType *ot)
1609 {
1610         /* identifiers */
1611         ot->name = "New Game Property";
1612         ot->description = "Create a new property available to the game engine";
1613         ot->idname = "OBJECT_OT_game_property_new";
1614
1615         /* api callbacks */
1616         ot->exec = game_property_new;
1617         ot->poll = ED_operator_object_active_editable;
1618
1619         /* flags */
1620         ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
1621
1622         RNA_def_enum(ot->srna, "type", gameproperty_type_items, GPROP_FLOAT, "Type", "Type of game property to add");
1623         RNA_def_string(ot->srna, "name", "", MAX_NAME, "Name", "Name of the game property to add");
1624 }
1625
1626 static int game_property_remove(bContext *C, wmOperator *op)
1627 {
1628         Object *ob = CTX_data_active_object(C);
1629         bProperty *prop;
1630         int index = RNA_int_get(op->ptr, "index");
1631
1632         if (!ob)
1633                 return OPERATOR_CANCELLED;
1634
1635         prop = BLI_findlink(&ob->prop, index);
1636
1637         if (prop) {
1638                 BLI_remlink(&ob->prop, prop);
1639                 BKE_bproperty_free(prop);
1640
1641                 WM_event_add_notifier(C, NC_LOGIC, NULL);
1642                 return OPERATOR_FINISHED;
1643         }
1644         else {
1645                 return OPERATOR_CANCELLED;
1646         }
1647 }
1648
1649 void OBJECT_OT_game_property_remove(wmOperatorType *ot)
1650 {
1651         /* identifiers */
1652         ot->name = "Remove Game Property";
1653         ot->description = "Remove game property";
1654         ot->idname = "OBJECT_OT_game_property_remove";
1655
1656         /* api callbacks */
1657         ot->exec = game_property_remove;
1658         ot->poll = ED_operator_object_active_editable;
1659
1660         /* flags */
1661         ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
1662
1663         RNA_def_int(ot->srna, "index", 0, 0, INT_MAX, "Index", "Property index to remove ", 0, INT_MAX);
1664 }
1665
1666 #define COPY_PROPERTIES_REPLACE 1
1667 #define COPY_PROPERTIES_MERGE   2
1668 #define COPY_PROPERTIES_COPY    3
1669
1670 static EnumPropertyItem game_properties_copy_operations[] = {
1671         {COPY_PROPERTIES_REPLACE, "REPLACE", 0, "Replace Properties", ""},
1672         {COPY_PROPERTIES_MERGE, "MERGE", 0, "Merge Properties", ""},
1673         {COPY_PROPERTIES_COPY, "COPY", 0, "Copy a Property", ""},
1674         {0, NULL, 0, NULL, NULL}
1675 };
1676
1677 static EnumPropertyItem *gameprops_itemf(bContext *C, PointerRNA *UNUSED(ptr), PropertyRNA *UNUSED(prop), int *free)
1678 {       
1679         Object *ob = ED_object_active_context(C);
1680         EnumPropertyItem tmp = {0, "", 0, "", ""};
1681         EnumPropertyItem *item = NULL;
1682         bProperty *prop;
1683         int a, totitem = 0;
1684         
1685         if (!ob)
1686                 return DummyRNA_NULL_items;
1687
1688         for (a = 1, prop = ob->prop.first; prop; prop = prop->next, a++) {
1689                 tmp.value = a;
1690                 tmp.identifier = prop->name;
1691                 tmp.name = prop->name;
1692                 RNA_enum_item_add(&item, &totitem, &tmp);
1693         }
1694
1695         RNA_enum_item_end(&item, &totitem);
1696         *free = 1;
1697
1698         return item;
1699 }
1700
1701 static int game_property_copy_exec(bContext *C, wmOperator *op)
1702 {
1703         Object *ob = ED_object_active_context(C);
1704         bProperty *prop;
1705         int type = RNA_enum_get(op->ptr, "operation");
1706         int propid = RNA_enum_get(op->ptr, "property");
1707
1708         if (propid > 0) { /* copy */
1709                 prop = BLI_findlink(&ob->prop, propid - 1);
1710                 
1711                 if (prop) {
1712                         CTX_DATA_BEGIN(C, Object *, ob_iter, selected_editable_objects)
1713                         {
1714                                 if (ob != ob_iter)
1715                                         BKE_bproperty_object_set(ob_iter, prop);
1716                         } CTX_DATA_END;
1717                 }
1718         }
1719
1720         else {
1721                 CTX_DATA_BEGIN(C, Object *, ob_iter, selected_editable_objects)
1722                 {
1723                         if (ob != ob_iter) {
1724                                 if (type == COPY_PROPERTIES_REPLACE) {
1725                                         BKE_bproperty_copy_list(&ob_iter->prop, &ob->prop);
1726                                 }
1727                                 else {
1728                                         /* merge - the default when calling with no argument */
1729                                         for (prop = ob->prop.first; prop; prop = prop->next) {
1730                                                 BKE_bproperty_object_set(ob_iter, prop);
1731                                         }
1732                                 }
1733                         }
1734                 }
1735                 CTX_DATA_END;
1736         }
1737
1738         return OPERATOR_FINISHED;
1739 }
1740
1741 void OBJECT_OT_game_property_copy(wmOperatorType *ot)
1742 {
1743         PropertyRNA *prop;
1744         /* identifiers */
1745         ot->name = "Copy Game Property";
1746         ot->idname = "OBJECT_OT_game_property_copy";
1747         ot->description = "Copy/merge/replace a game property from active object to all selected objects";
1748
1749         /* api callbacks */
1750         ot->exec = game_property_copy_exec;
1751         ot->poll = ED_operator_object_active_editable;
1752
1753         /* flags */
1754         ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
1755
1756         RNA_def_enum(ot->srna, "operation", game_properties_copy_operations, 3, "Operation", "");
1757         prop = RNA_def_enum(ot->srna, "property", DummyRNA_NULL_items, 0, "Property", "Properties to copy");
1758         RNA_def_property_flag(prop, PROP_SKIP_SAVE);
1759         RNA_def_enum_funcs(prop, gameprops_itemf);
1760         ot->prop = prop;
1761 }
1762
1763 static int game_property_clear_exec(bContext *C, wmOperator *UNUSED(op))
1764 {
1765         CTX_DATA_BEGIN(C, Object *, ob_iter, selected_editable_objects)
1766         {
1767                 BKE_bproperty_free_list(&ob_iter->prop);
1768         }
1769         CTX_DATA_END;
1770
1771         WM_event_add_notifier(C, NC_LOGIC, NULL);
1772         return OPERATOR_FINISHED;
1773 }
1774 void OBJECT_OT_game_property_clear(wmOperatorType *ot)
1775 {
1776         /* identifiers */
1777         ot->name = "Clear Game Properties";
1778         ot->idname = "OBJECT_OT_game_property_clear";
1779         ot->description = "Remove all game properties from all selected objects";
1780
1781         /* api callbacks */
1782         ot->exec = game_property_clear_exec;
1783         ot->poll = ED_operator_object_active_editable;
1784
1785         /* flags */
1786         ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
1787 }
1788
1789 /************************ Copy Logic Bricks ***********************/
1790
1791 static int logicbricks_copy_exec(bContext *C, wmOperator *UNUSED(op))
1792 {
1793         Object *ob = ED_object_active_context(C);
1794
1795         CTX_DATA_BEGIN(C, Object *, ob_iter, selected_editable_objects)
1796         {
1797                 if (ob != ob_iter) {
1798                         /* first: free all logic */
1799                         free_sensors(&ob_iter->sensors);
1800                         unlink_controllers(&ob_iter->controllers);
1801                         free_controllers(&ob_iter->controllers);
1802                         unlink_actuators(&ob_iter->actuators);
1803                         free_actuators(&ob_iter->actuators);
1804                 
1805                         /* now copy it, this also works without logicbricks! */
1806                         clear_sca_new_poins_ob(ob);
1807                         copy_sensors(&ob_iter->sensors, &ob->sensors);
1808                         copy_controllers(&ob_iter->controllers, &ob->controllers);
1809                         copy_actuators(&ob_iter->actuators, &ob->actuators);
1810                         set_sca_new_poins_ob(ob_iter);
1811                 
1812                         /* some menu settings */
1813                         ob_iter->scavisflag = ob->scavisflag;
1814                         ob_iter->scaflag = ob->scaflag;
1815                 
1816                         /* set the initial state */
1817                         ob_iter->state = ob->state;
1818                         ob_iter->init_state = ob->init_state;
1819
1820                         if (ob_iter->totcol == ob->totcol) {
1821                                 ob_iter->actcol = ob->actcol;
1822                                 WM_event_add_notifier(C, NC_OBJECT | ND_DRAW, ob_iter);
1823                         }
1824                 }
1825         }
1826         CTX_DATA_END;
1827
1828         WM_event_add_notifier(C, NC_LOGIC, NULL);
1829
1830         return OPERATOR_FINISHED;
1831 }
1832
1833 void OBJECT_OT_logic_bricks_copy(wmOperatorType *ot)
1834 {
1835         /* identifiers */
1836         ot->name = "Copy Logic Bricks to Selected";
1837         ot->description = "Copy logic bricks to other selected objects";
1838         ot->idname = "OBJECT_OT_logic_bricks_copy";
1839
1840         /* api callbacks */
1841         ot->exec = logicbricks_copy_exec;
1842         ot->poll = ED_operator_object_active_editable;
1843
1844         /* flags */
1845         ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
1846 }
1847
1848 static int game_physics_copy_exec(bContext *C, wmOperator *UNUSED(op))
1849 {
1850         Object *ob = ED_object_active_context(C);
1851         
1852         CTX_DATA_BEGIN(C, Object *, ob_iter, selected_editable_objects)
1853         {
1854                 if (ob != ob_iter) {
1855                         ob_iter->gameflag = ob->gameflag;
1856                         ob_iter->gameflag2 = ob->gameflag2;
1857                         ob_iter->inertia = ob->inertia;
1858                         ob_iter->formfactor = ob->formfactor;
1859                         ob_iter->damping = ob->damping;
1860                         ob_iter->rdamping = ob->rdamping;
1861                         ob_iter->min_vel = ob->min_vel;
1862                         ob_iter->max_vel = ob->max_vel;
1863                         ob_iter->obstacleRad = ob->obstacleRad;
1864                         ob_iter->mass = ob->mass;
1865                         copy_v3_v3(ob_iter->anisotropicFriction, ob->anisotropicFriction);
1866                         ob_iter->collision_boundtype = ob->collision_boundtype;
1867                         ob_iter->margin = ob->margin;
1868                         ob_iter->bsoft = copy_bulletsoftbody(ob->bsoft);
1869                         if (ob->restrictflag & OB_RESTRICT_RENDER) 
1870                                 ob_iter->restrictflag |= OB_RESTRICT_RENDER;
1871                         else
1872                                 ob_iter->restrictflag &= ~OB_RESTRICT_RENDER;
1873
1874                         ob_iter->col_group = ob->col_group;
1875                         ob_iter->col_mask = ob->col_mask;
1876                 }
1877         }
1878         CTX_DATA_END;
1879         
1880         return OPERATOR_FINISHED;
1881 }
1882
1883 void OBJECT_OT_game_physics_copy(struct wmOperatorType *ot)
1884 {
1885         /* identifiers */
1886         ot->name = "Copy Game Physics Properties to Selected";
1887         ot->description = "Copy game physics properties to other selected objects";
1888         ot->idname = "OBJECT_OT_game_physics_copy";
1889         
1890         /* api callbacks */
1891         ot->exec = game_physics_copy_exec;
1892         ot->poll = ED_operator_object_active_editable;
1893         
1894         /* flags */
1895         ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
1896 }