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