~ubuntu-branches/ubuntu/trusty/blender/trusty

« back to all changes in this revision

Viewing changes to source/blender/editors/object/object_edit.c

  • Committer: Package Import Robot
  • Author(s): Jeremy Bicha
  • Date: 2013-03-06 12:08:47 UTC
  • mfrom: (1.5.1) (14.1.8 experimental)
  • Revision ID: package-import@ubuntu.com-20130306120847-frjfaryb2zrotwcg
Tags: 2.66a-1ubuntu1
* Resynchronize with Debian (LP: #1076930, #1089256, #1052743, #999024,
  #1122888, #1147084)
* debian/control:
  - Lower build-depends on libavcodec-dev since we're not
    doing the libav9 transition in Ubuntu yet

Show diffs side-by-side

added added

removed removed

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