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