2.5
authorTon Roosendaal <ton@blender.org>
Sun, 28 Dec 2008 18:10:24 +0000 (18:10 +0000)
committerTon Roosendaal <ton@blender.org>
Sun, 28 Dec 2008 18:10:24 +0000 (18:10 +0000)
Recode of 'select all objects by type' to show
how to use itterators.

source/blender/blenkernel/BKE_context.h
source/blender/blenkernel/intern/context.c
source/blender/editors/space_view3d/space_view3d.c
source/blender/editors/space_view3d/view3d_select.c

index e8bd72ac3f3a0ef399cba2d69ed25596b2049991..791d7251ef53a553649c7816d96e414993456f6a 100644 (file)
@@ -137,6 +137,9 @@ void CTX_data_scene_set(bContext *C, struct Scene *bmain);
 int CTX_data_selected_objects(const bContext *C, ListBase *list);
 int CTX_data_selected_bases(const bContext *C, ListBase *list);
 
+int CTX_data_visible_objects(const bContext *C, ListBase *list);
+int CTX_data_visible_bases(const bContext *C, ListBase *list);
+
 struct Object *CTX_data_active_object(const bContext *C);
 struct Base *CTX_data_active_base(const bContext *C);
 
index 703bb4c2b0000413cb3ffe634adf568080920832..fa5740f74e9d8a714fd68871a8085f498e1abd1c 100644 (file)
@@ -365,6 +365,16 @@ int CTX_data_selected_bases(const bContext *C, ListBase *list)
        return ctx_data_collection_get(C, CTX_data_selected_bases, list);
 }
 
+int CTX_data_visible_objects(const bContext *C, ListBase *list)
+{
+       return ctx_data_collection_get(C, CTX_data_visible_objects, list);
+}
+
+int CTX_data_visible_bases(const bContext *C, ListBase *list)
+{
+       return ctx_data_collection_get(C, CTX_data_visible_bases, list);
+}
+
 struct Object *CTX_data_active_object(const bContext *C)
 {
        return ctx_data_pointer_get(C, CTX_data_active_object);
index b523810fbd8b9924afaaa3276b8ffc4b0df613fa..1503dd878d3bd85520856b752f22e3ea05b108ff 100644 (file)
@@ -266,6 +266,20 @@ static int view3d_context(const bContext *C, const bContextDataMember *member, b
 
                return 1;
        }
+       else if(ELEM(member, CTX_data_visible_objects, CTX_data_visible_bases)) {
+               for(base=scene->base.first; base; base=base->next) {
+                       if(base->lay & v3d->lay) {
+                               if((base->object->restrictflag & OB_RESTRICT_VIEW)==0) {
+                                       if(member == CTX_data_selected_objects)
+                                               CTX_data_list_add(result, base->object);
+                                       else
+                                               CTX_data_list_add(result, base);
+                               }
+                       }
+               }
+               
+               return 1;
+       }
        else if(member == CTX_data_active_base) {
                if(scene->basact && (scene->basact->lay & v3d->lay))
                        if((scene->basact->object->restrictflag & OB_RESTRICT_VIEW)==0)
index 89f2650affcd540ed52aa5a7613d41e9239c0119..7bb2c9d1162f28268b539d3b1a3033d7b7db9e79 100644 (file)
@@ -194,6 +194,7 @@ void select_base_v3d(Base *base, short mode)
                else if (mode==BA_DESELECT) {
                        base->flag &= ~SELECT;
                }
+               base->object->flag= base->flag;
        }
 }
 
@@ -762,25 +763,6 @@ void selectrandom(Scene *scene, View3D *v3d, short randfac)
        BIF_undo_push("Select Random");
 }
 
-/* selects all objects of a particular type, on currently visible layers */
-void selectall_type(Scene *scene, View3D *v3d, short obtype) 
-{
-       Base *base;
-       
-       base= FIRSTBASE;
-       while(base) {
-               if((base->lay & v3d->lay) &&
-                 (base->object->type == obtype) &&
-                 (base->object->restrictflag & OB_RESTRICT_VIEW)==0
-               ) {
-                       select_base_v3d(base, BA_SELECT);
-                       base->object->flag= base->flag;
-               }
-               base= base->next;
-       }
-
-       BIF_undo_push("Select all per type");
-}
 /* selects all objects on a particular layer */
 void selectall_layer(Scene *scene, unsigned int layernum) 
 {
@@ -792,7 +774,6 @@ void selectall_layer(Scene *scene, unsigned int layernum)
                  (base->object->restrictflag & OB_RESTRICT_VIEW)==0
                ) {
                        select_base_v3d(base, BA_SELECT);
-                       base->object->flag= base->flag;
                }
                base= base->next;
        }
@@ -903,7 +884,6 @@ static void deselectall_except(Scene *scene, Base *b)   /* deselect all except b
                if (base->flag & SELECT) {
                        if(b!=base) {
                                select_base_v3d(base, BA_DESELECT);
-                               base->object->flag= base->flag;
                        }
                }
        }
@@ -1207,9 +1187,6 @@ static void mouse_select(Scene *scene, ARegion *ar, View3D *v3d, short *mval)
                                else select_base_v3d(basact, BA_SELECT);
                        }
 
-                       /* copy */
-                       basact->object->flag= basact->flag;
-                       
                        if(oldbasact != basact) {
                                set_active_base(scene, basact);
                        }
@@ -1565,8 +1542,6 @@ static int view3d_borderselect_exec(bContext *C, wmOperator *op)
                                                                select_base_v3d(base, BA_SELECT);
                                                        else
                                                                select_base_v3d(base, BA_DESELECT);
-
-                                                       base->object->flag= base->flag;
                                                }
 
                                                col+=4; /* next color */
@@ -1660,16 +1635,19 @@ static EnumPropertyItem prop_select_object_types[] = {
 
 static int view3d_select_by_type_exec(bContext *C, wmOperator *op)
 {
-       ScrArea *sa= CTX_wm_area(C);
        ARegion *ar= CTX_wm_region(C);
-       View3D *v3d= sa->spacedata.first;
-       Scene *scene= CTX_data_scene(C);
        short obtype;
        
        obtype = RNA_enum_get(op->ptr, "type");
                
-       selectall_type(scene, v3d, obtype);
+       CTX_DATA_BEGIN(C, Base*, base, visible_bases) {
+               if(base->object->type==obtype) {
+                       select_base_v3d(base, BA_SELECT);
+               }
+       }
+       CTX_DATA_END;
        
+       /* undo? */
        ED_region_tag_redraw(ar);
        
        return OPERATOR_FINISHED;
@@ -1980,9 +1958,7 @@ static int view3d_circle_select(bContext *C, wmOperator *op)
                                int dx= base->sx-x;
                                int dy= base->sy-y;
                                if( dx*dx + dy*dy < radius*radius)
-                               
                                        select_base_v3d(base, BA_SELECT);
-                               base->object->flag= base->flag;
                        }
                }
        }