~siretart/ubuntu/utopic/blender/libav10

« back to all changes in this revision

Viewing changes to source/blender/editors/mesh/editmesh_select.c

  • Committer: Reinhard Tartler
  • Date: 2014-05-31 01:50:05 UTC
  • mfrom: (14.2.27 sid)
  • Revision ID: siretart@tauware.de-20140531015005-ml6druahuj82nsav
mergeĀ fromĀ debian

Show diffs side-by-side

added added

removed removed

Lines of Context:
31
31
 
32
32
#include "MEM_guardedalloc.h"
33
33
 
 
34
#include "BLI_bitmap.h"
34
35
#include "BLI_listbase.h"
35
36
#include "BLI_linklist.h"
36
37
#include "BLI_linklist_stack.h"
184
185
unsigned int bm_solidoffs = 0, bm_wireoffs = 0, bm_vertoffs = 0;    /* set in drawobject.c ... for colorindices */
185
186
 
186
187
/* facilities for border select and circle select */
187
 
static char *selbuf = NULL;
 
188
static BLI_bitmap *selbuf = NULL;
 
189
 
 
190
static BLI_bitmap *edbm_backbuf_alloc(const int size)
 
191
{
 
192
        return BLI_BITMAP_NEW(size, "selbuf");
 
193
}
188
194
 
189
195
/* reads rect, and builds selection array for quick lookup */
190
196
/* returns if all is OK */
205
211
        dr = buf->rect;
206
212
        
207
213
        /* build selection lookup */
208
 
        selbuf = MEM_callocN(bm_vertoffs + 1, "selbuf");
 
214
        selbuf = edbm_backbuf_alloc(bm_vertoffs + 1);
209
215
        
210
216
        a = (xmax - xmin + 1) * (ymax - ymin + 1);
211
217
        while (a--) {
212
 
                if (*dr > 0 && *dr <= bm_vertoffs)
213
 
                        selbuf[*dr] = 1;
 
218
                if (*dr > 0 && *dr <= bm_vertoffs) {
 
219
                        BLI_BITMAP_SET(selbuf, *dr);
 
220
                }
214
221
                dr++;
215
222
        }
216
223
        IMB_freeImBuf(buf);
217
224
        return true;
218
225
}
219
226
 
220
 
int EDBM_backbuf_check(unsigned int index)
 
227
bool EDBM_backbuf_check(unsigned int index)
221
228
{
222
229
        /* odd logic, if selbuf is NULL we assume no zbuf-selection is enabled
223
230
         * and just ignore the depth buffer, this is error prone since its possible
224
231
         * code doesn't set the depth buffer by accident, but leave for now. - Campbell */
225
 
        if (selbuf == NULL) return 1;
 
232
        if (selbuf == NULL)
 
233
                return true;
226
234
 
227
235
        if (index > 0 && index <= bm_vertoffs)
228
 
                return selbuf[index];
229
 
        return 0;
 
236
                return BLI_BITMAP_GET_BOOL(selbuf, index);
 
237
 
 
238
        return false;
230
239
}
231
240
 
232
241
void EDBM_backbuf_free(void)
262
271
        
263
272
        /* method in use for face selecting too */
264
273
        if (vc->obedit == NULL) {
265
 
                if (!(paint_facesel_test(vc->obact) || paint_vertsel_test(vc->obact))) {
 
274
                if (!BKE_paint_select_elem_test(vc->obact)) {
266
275
                        return false;
267
276
                }
268
277
        }
286
295
               edbm_mask_lasso_px_cb, &lasso_mask_data);
287
296
 
288
297
        /* build selection lookup */
289
 
        selbuf = MEM_callocN(bm_vertoffs + 1, "selbuf");
 
298
        selbuf = edbm_backbuf_alloc(bm_vertoffs + 1);
290
299
        
291
300
        a = (xmax - xmin + 1) * (ymax - ymin + 1);
292
301
        while (a--) {
293
 
                if (*dr > 0 && *dr <= bm_vertoffs && *dr_mask == true) selbuf[*dr] = 1;
 
302
                if (*dr > 0 && *dr <= bm_vertoffs && *dr_mask == true) {
 
303
                        BLI_BITMAP_SET(selbuf, *dr);
 
304
                }
294
305
                dr++; dr_mask++;
295
306
        }
296
307
        IMB_freeImBuf(buf);
309
320
        
310
321
        /* method in use for face selecting too */
311
322
        if (vc->obedit == NULL) {
312
 
                if (!(paint_facesel_test(vc->obact) || paint_vertsel_test(vc->obact))) {
 
323
                if (!BKE_paint_select_elem_test(vc->obact)) {
313
324
                        return false;
314
325
                }
315
326
        }
326
337
        dr = buf->rect;
327
338
        
328
339
        /* build selection lookup */
329
 
        selbuf = MEM_callocN(bm_vertoffs + 1, "selbuf");
 
340
        selbuf = edbm_backbuf_alloc(bm_vertoffs + 1);
330
341
        radsq = rads * rads;
331
342
        for (yc = -rads; yc <= rads; yc++) {
332
343
                for (xc = -rads; xc <= rads; xc++, dr++) {
333
344
                        if (xc * xc + yc * yc < radsq) {
334
 
                                if (*dr > 0 && *dr <= bm_vertoffs) selbuf[*dr] = 1;
 
345
                                if (*dr > 0 && *dr <= bm_vertoffs) {
 
346
                                        BLI_BITMAP_SET(selbuf, *dr);
 
347
                                }
335
348
                        }
336
349
                }
337
350
        }
379
392
static bool findnearestvert__backbufIndextest(void *handle, unsigned int index)
380
393
{
381
394
        BMEditMesh *em = (BMEditMesh *)handle;
382
 
        BMVert *eve = BM_vert_at_index(em->bm, index - 1);
 
395
        BMVert *eve = BM_vert_at_index_find(em->bm, index - 1);
383
396
        return !(eve && BM_elem_flag_test(eve, BM_ELEM_SELECT));
384
397
}
385
398
/**
407
420
                                                           0, NULL, NULL);
408
421
                }
409
422
                
410
 
                eve = index ? BM_vert_at_index(vc->em->bm, index - 1) : NULL;
 
423
                eve = index ? BM_vert_at_index_find(vc->em->bm, index - 1) : NULL;
411
424
                
412
425
                if (eve && distance < *r_dist) {
413
426
                        *r_dist = distance;
423
436
                static int lastSelectedIndex = 0;
424
437
                static BMVert *lastSelected = NULL;
425
438
                
426
 
                if (lastSelected && BM_vert_at_index(vc->em->bm, lastSelectedIndex) != lastSelected) {
 
439
                if (lastSelected && BM_vert_at_index_find(vc->em->bm, lastSelectedIndex) != lastSelected) {
427
440
                        lastSelectedIndex = 0;
428
441
                        lastSelected = NULL;
429
442
                }
499
512
                view3d_validate_backbuf(vc);
500
513
                
501
514
                index = view3d_sample_backbuf_rect(vc, vc->mval, 50, bm_solidoffs, bm_wireoffs, &distance, 0, NULL, NULL);
502
 
                eed = index ? BM_edge_at_index(vc->em->bm, index - 1) : NULL;
 
515
                eed = index ? BM_edge_at_index_find(vc->em->bm, index - 1) : NULL;
503
516
                
504
517
                if (eed && distance < *r_dist) {
505
518
                        *r_dist = distance;
572
585
                view3d_validate_backbuf(vc);
573
586
 
574
587
                index = view3d_sample_backbuf(vc, vc->mval[0], vc->mval[1]);
575
 
                efa = index ? BM_face_at_index(vc->em->bm, index - 1) : NULL;
 
588
                efa = index ? BM_face_at_index_find(vc->em->bm, index - 1) : NULL;
576
589
                
577
590
                if (efa) {
578
591
                        struct { float mval_fl[2]; float dist; BMFace *toFace; } data;
599
612
                static int lastSelectedIndex = 0;
600
613
                static BMFace *lastSelected = NULL;
601
614
 
602
 
                if (lastSelected && BM_face_at_index(vc->em->bm, lastSelectedIndex) != lastSelected) {
 
615
                if (lastSelected && BM_face_at_index_find(vc->em->bm, lastSelectedIndex) != lastSelected) {
603
616
                        lastSelectedIndex = 0;
604
617
                        lastSelected = NULL;
605
618
                }
848
861
}
849
862
 
850
863
static EnumPropertyItem *select_similar_type_itemf(bContext *C, PointerRNA *UNUSED(ptr), PropertyRNA *UNUSED(prop),
851
 
                                                   int *free)
 
864
                                                   bool *r_free)
852
865
{
853
866
        Object *obedit;
854
867
 
884
897
                }
885
898
                RNA_enum_item_end(&item, &totitem);
886
899
 
887
 
                *free = 1;
 
900
                *r_free = true;
888
901
 
889
902
                return item;
890
903
        }
1798
1811
        BMFace *efa;
1799
1812
        BMEdge *eed;
1800
1813
        bool ok;
1801
 
        bool change = false;
 
1814
        bool changed = false;
1802
1815
 
1803
1816
        BM_ITER_MESH (efa, &iter, em->bm, BM_FACES_OF_MESH) {
1804
1817
                if (BM_elem_flag_test(efa, BM_ELEM_HIDDEN))
1815
1828
 
1816
1829
                if (ok) {
1817
1830
                        BM_face_select_set(bm, efa, true);
1818
 
                        change = true;
 
1831
                        changed = true;
1819
1832
                }
1820
1833
        }
1821
1834
 
1822
 
        return change;
 
1835
        return changed;
1823
1836
}
1824
1837
 
1825
1838
 
1843
1856
        BMEditMesh *em = BKE_editmesh_from_object(obedit);
1844
1857
        BMesh *bm = em->bm;
1845
1858
        BMIter iter;
1846
 
        BMVert *v;
1847
1859
        BMEdge *e;
1848
1860
        BMWalker walker;
1849
1861
 
1857
1869
                BMFace *efa;
1858
1870
 
1859
1871
                BM_ITER_MESH (efa, &iter, em->bm, BM_FACES_OF_MESH) {
1860
 
                        BM_elem_flag_set(efa, BM_ELEM_TAG, (BM_elem_flag_test(efa, BM_ELEM_SELECT) &&
1861
 
                                                            !BM_elem_flag_test(efa, BM_ELEM_HIDDEN)));
 
1872
                        BM_elem_flag_set(efa, BM_ELEM_TAG, BM_elem_flag_test(efa, BM_ELEM_SELECT));
1862
1873
                }
1863
1874
 
1864
1875
                if (limit) {
1878
1889
                        if (BM_elem_flag_test(efa, BM_ELEM_TAG)) {
1879
1890
                                for (efa = BMW_begin(&walker, efa); efa; efa = BMW_step(&walker)) {
1880
1891
                                        BM_face_select_set(bm, efa, true);
 
1892
                                        BM_elem_flag_disable(efa, BM_ELEM_TAG);
1881
1893
                                }
1882
1894
                        }
1883
1895
                }
1888
1900
                }
1889
1901
        }
1890
1902
        else {
 
1903
                BMVert *v;
 
1904
 
1891
1905
                BM_ITER_MESH (v, &iter, em->bm, BM_VERTS_OF_MESH) {
1892
 
                        if (BM_elem_flag_test(v, BM_ELEM_SELECT)) {
1893
 
                                BM_elem_flag_enable(v, BM_ELEM_TAG);
1894
 
                        }
1895
 
                        else {
1896
 
                                BM_elem_flag_disable(v, BM_ELEM_TAG);
1897
 
                        }
 
1906
                        BM_elem_flag_set(v, BM_ELEM_TAG, BM_elem_flag_test(v, BM_ELEM_SELECT));
1898
1907
                }
1899
1908
 
1900
1909
                BMW_init(&walker, em->bm, BMW_SHELL,
1906
1915
                        if (BM_elem_flag_test(v, BM_ELEM_TAG)) {
1907
1916
                                for (e = BMW_begin(&walker, v); e; e = BMW_step(&walker)) {
1908
1917
                                        BM_edge_select_set(em->bm, e, true);
 
1918
                                        BM_elem_flag_disable(e, BM_ELEM_TAG);
1909
1919
                                }
1910
1920
                        }
1911
1921
                }
2692
2702
{
2693
2703
        Object *obedit = CTX_data_edit_object(C);
2694
2704
        BMEditMesh *em = BKE_editmesh_from_object(obedit);
2695
 
        BMVert *eve;
2696
 
        BMEdge *eed;
2697
 
        BMFace *efa;
2698
 
        BMIter iter;
 
2705
        const bool select = (RNA_enum_get(op->ptr, "action") == SEL_SELECT);
2699
2706
        const float randfac =  RNA_float_get(op->ptr, "percent") / 100.0f;
2700
2707
 
2701
 
        if (!RNA_boolean_get(op->ptr, "extend"))
2702
 
                EDBM_flag_disable_all(em, BM_ELEM_SELECT);
 
2708
        BMIter iter;
2703
2709
 
2704
2710
        if (em->selectmode & SCE_SELECT_VERTEX) {
 
2711
                BMVert *eve;
2705
2712
                BM_ITER_MESH (eve, &iter, em->bm, BM_VERTS_OF_MESH) {
2706
2713
                        if (!BM_elem_flag_test(eve, BM_ELEM_HIDDEN) && BLI_frand() < randfac) {
2707
 
                                BM_vert_select_set(em->bm, eve, true);
 
2714
                                BM_vert_select_set(em->bm, eve, select);
2708
2715
                        }
2709
2716
                }
2710
 
                EDBM_selectmode_flush(em);
2711
2717
        }
2712
2718
        else if (em->selectmode & SCE_SELECT_EDGE) {
 
2719
                BMEdge *eed;
2713
2720
                BM_ITER_MESH (eed, &iter, em->bm, BM_EDGES_OF_MESH) {
2714
2721
                        if (!BM_elem_flag_test(eed, BM_ELEM_HIDDEN) && BLI_frand() < randfac) {
2715
 
                                BM_edge_select_set(em->bm, eed, true);
 
2722
                                BM_edge_select_set(em->bm, eed, select);
2716
2723
                        }
2717
2724
                }
2718
 
                EDBM_selectmode_flush(em);
2719
2725
        }
2720
2726
        else {
 
2727
                BMFace *efa;
2721
2728
                BM_ITER_MESH (efa, &iter, em->bm, BM_FACES_OF_MESH) {
2722
2729
                        if (!BM_elem_flag_test(efa, BM_ELEM_HIDDEN) && BLI_frand() < randfac) {
2723
 
                                BM_face_select_set(em->bm, efa, true);
 
2730
                                BM_face_select_set(em->bm, efa, select);
2724
2731
                        }
2725
2732
                }
 
2733
        }
 
2734
 
 
2735
        if (select) {
 
2736
                /* was EDBM_select_flush, but it over select in edge/face mode */
2726
2737
                EDBM_selectmode_flush(em);
2727
2738
        }
 
2739
        else {
 
2740
                EDBM_deselect_flush(em);
 
2741
        }
2728
2742
        
2729
2743
        WM_event_add_notifier(C, NC_GEOM | ND_SELECT, obedit->data);
2730
2744
        
2748
2762
        /* props */
2749
2763
        RNA_def_float_percentage(ot->srna, "percent", 50.f, 0.0f, 100.0f,
2750
2764
                                 "Percent", "Percentage of elements to select randomly", 0.f, 100.0f);
2751
 
        RNA_def_boolean(ot->srna, "extend", false, "Extend", "Extend the selection");
 
2765
        WM_operator_properties_select_action_simple(ot, SEL_SELECT);
2752
2766
}
2753
2767
 
2754
2768
static int edbm_select_ungrouped_poll(bContext *C)
2761
2775
                if ((em->selectmode & SCE_SELECT_VERTEX) == 0) {
2762
2776
                        CTX_wm_operator_poll_msg_set(C, "Must be in vertex selection mode");
2763
2777
                }
2764
 
                else if (obedit->defbase.first == NULL || cd_dvert_offset == -1) {
 
2778
                else if (BLI_listbase_is_empty(&obedit->defbase) || cd_dvert_offset == -1) {
2765
2779
                        CTX_wm_operator_poll_msg_set(C, "No weights/vertex groups on object");
2766
2780
                }
2767
2781
                else {
3057
3071
 
3058
3072
static int verg_radial(const void *va, const void *vb)
3059
3073
{
3060
 
        BMEdge *e1 = *((void **)va);
3061
 
        BMEdge *e2 = *((void **)vb);
 
3074
        BMEdge *e_a = *((BMEdge **)va);
 
3075
        BMEdge *e_b = *((BMEdge **)vb);
 
3076
 
3062
3077
        int a, b;
3063
 
        
3064
 
        a = BM_edge_face_count(e1);
3065
 
        b = BM_edge_face_count(e2);
3066
 
        
3067
 
        if (a > b)  return -1;
3068
 
        if (a == b) return  0;
3069
 
        if (a < b)  return  1;
3070
 
        
3071
 
        return -1;
 
3078
        a = BM_edge_face_count(e_a);
 
3079
        b = BM_edge_face_count(e_b);
 
3080
        
 
3081
        if (a > b) return -1;
 
3082
        if (a < b) return  1;
 
3083
        return  0;
3072
3084
}
3073
3085
 
3074
 
static int loop_find_regions(BMEditMesh *em, int selbigger)
 
3086
static int loop_find_regions(BMEditMesh *em, const bool selbigger)
3075
3087
{
3076
3088
        SmallHash visithash;
3077
3089
        BMIter iter;
3078
 
        BMEdge *e, **edges = NULL;
3079
 
        BLI_array_declare(edges);
 
3090
        const int edges_len = em->bm->totedgesel;
 
3091
        BMEdge *e, **edges;
3080
3092
        BMFace *f;
3081
3093
        int count = 0, i;
3082
3094
        
3083
 
        BLI_smallhash_init(&visithash);
 
3095
        BLI_smallhash_init_ex(&visithash, edges_len);
 
3096
        edges = MEM_mallocN(sizeof(*edges) * edges_len, __func__);
3084
3097
        
3085
3098
        BM_ITER_MESH (f, &iter, em->bm, BM_FACES_OF_MESH) {
3086
3099
                BM_elem_flag_disable(f, BM_ELEM_TAG);
3087
3100
        }
3088
3101
 
 
3102
        i = 0;
3089
3103
        BM_ITER_MESH (e, &iter, em->bm, BM_EDGES_OF_MESH) {
3090
3104
                if (BM_elem_flag_test(e, BM_ELEM_SELECT)) {
3091
 
                        BLI_array_append(edges, e);
 
3105
                        edges[i++] = e;
3092
3106
                        BM_elem_flag_enable(e, BM_ELEM_TAG);
3093
3107
                }
3094
3108
                else {
3097
3111
        }
3098
3112
        
3099
3113
        /* sort edges by radial cycle length */
3100
 
        qsort(edges,  BLI_array_count(edges), sizeof(void *), verg_radial);
 
3114
        qsort(edges, edges_len, sizeof(*edges), verg_radial);
3101
3115
        
3102
 
        for (i = 0; i < BLI_array_count(edges); i++) {
 
3116
        for (i = 0; i < edges_len; i++) {
3103
3117
                BMIter liter;
3104
3118
                BMLoop *l;
3105
3119
                BMFace **region = NULL, **region_out;
3148
3162
                }
3149
3163
        }
3150
3164
        
3151
 
        BLI_array_free(edges);
 
3165
        MEM_freeN(edges);
3152
3166
        BLI_smallhash_release(&visithash);
3153
3167
        
3154
3168
        return count;