All kinds of fixes for new selection modes
authorTon Roosendaal <ton@blender.org>
Fri, 24 Sep 2004 18:17:23 +0000 (18:17 +0000)
committerTon Roosendaal <ton@blender.org>
Fri, 24 Sep 2004 18:17:23 +0000 (18:17 +0000)
- circle-select now works
- delete options for edge/face select work as to be expected.
  should check on a better set of choices in menu though
- assign material / select material options work for new modes
- shift+f fill didnt leave proper select flags...
- border select on face-gones (fgons) works
- 'draw normals' and fgons works now

source/blender/include/BIF_editmesh.h
source/blender/src/buttons_editing.c
source/blender/src/buttons_object.c
source/blender/src/drawobject.c
source/blender/src/edit.c
source/blender/src/editmesh_tools.c
source/blender/src/editview.c

index 632283f9a534ec18ddc68a038a49e7e384a44229..2b9a305ff86cc035338001f20c48d2e4cafd13f3 100644 (file)
@@ -89,6 +89,9 @@ extern void flip_editnormals(void);
 extern void vertexnormals(int testflip);
 
 /* ******************* editmesh_mods.c */
+
+extern void EM_select_face_fgon(struct EditFace *efa, int sel);
+
 extern void vertexnoise(void);
 extern void vertexsmooth(void);
 extern void righthandfaces(int select);
index 198512044664293ed28fdcc714b27738d70da69b..e726bd1247010e493e06bfe7bfe52b092a01b895 100644 (file)
@@ -407,7 +407,7 @@ void do_common_editbuts(unsigned short event) // old name, is a mix of object an
                        if(G.obedit->type == OB_MESH) {
                                efa= em->faces.first;
                                while(efa) {
-                                       if( faceselectedAND(efa, 1) ) {
+                                       if(efa->f & SELECT) {
                                                if(index== -1) index= efa->mat_nr;
                                                else if(index!=efa->mat_nr) {
                                                        error("Mixed colors");
@@ -451,7 +451,7 @@ void do_common_editbuts(unsigned short event) // old name, is a mix of object an
                        if(G.obedit->type == OB_MESH) {
                                efa= em->faces.first;
                                while(efa) {
-                                       if( faceselectedAND(efa, 1) )
+                                       if(efa->f & SELECT)
                                                efa->mat_nr= G.obedit->actcol-1;
                                        efa= efa->next;
                                }
@@ -564,7 +564,7 @@ void do_common_editbuts(unsigned short event) // old name, is a mix of object an
                        if(G.obedit->type == OB_MESH) {
                                efa= em->faces.first;
                                while(efa) {
-                                       if( faceselectedAND(efa, 1) ) {
+                                       if(efa->f & SELECT) {
                                                if(event==B_SETSMOOTH) efa->flag |= ME_SMOOTH;
                                                else efa->flag &= ~ME_SMOOTH;
                                        }
index 8b39da847894fe66ddd87ac07c2172662b5356c6..e57f8ee911a10adcf40f0db2fcdc5e8f181114c1 100644 (file)
@@ -68,9 +68,7 @@
 #include "BIF_glutil.h"
 #include "BIF_interface.h"
 #include "BIF_toolbox.h"
-#include "BIF_editmesh.h"
 #include "BDR_editcurve.h"
-#include "BDR_editface.h"
 #include "BDR_drawobject.h"
 
 #include "BIF_butspace.h"
index ddfef9c6cb0719e837f44ad812143d48d8f832e4..51a8ed3b81d2456166a2f166ff5dc9a2f16c03a6 100644 (file)
@@ -2661,10 +2661,8 @@ static void drawmeshwire(Object *ob)
                        
                        efa= em->faces.first;
                        while(efa) {
-                               if(efa->h==0) {
-                                       if(efa->v4) CalcCent4f(fvec, efa->v1->co, efa->v2->co, efa->v3->co, efa->v4->co);
-                                       else CalcCent3f(fvec, efa->v1->co, efa->v2->co, efa->v3->co);
-
+                               if(efa->h==0 && efa->fgonf!=EM_FGON) {
+                                       VECCOPY(fvec, efa->cent);
                                        glVertex3fv(fvec);
                                        fvec[0]+= editbutsize*efa->n[0];
                                        fvec[1]+= editbutsize*efa->n[1];
index d80d195988e01be972ec77a15e896d8106fab379..8843d6475a59732cbbbbd2d4353c218a9529bc56 100644 (file)
@@ -437,7 +437,7 @@ void circle_selectCB(select_CBfunc callback)
        
        /* clear circle */
        draw_sel_circle(0, mvalo, 0, rad, 1);
-
+       BIF_undo_push("Circle Select");
        countall();
        allqueue(REDRAWINFO, 0);
 }
index 3cbf29599b3edf54ac3a64463df0a221d7904060..6cba1758597e4b5ae79254d78c96a87251715fcf 100644 (file)
@@ -844,13 +844,13 @@ void delete_mesh(void)
                efa= em->faces.first;
                while(efa) {
                        nextvl= efa->next;
-                       /* delete only faces with 2 or more vertices selected */
+                       /* delete only faces with 1 or more edges selected */
                        count= 0;
-                       if(efa->v1->f & SELECT) count++;
-                       if(efa->v2->f & SELECT) count++;
-                       if(efa->v3->f & SELECT) count++;
-                       if(efa->v4 && (efa->v4->f & SELECT)) count++;
-                       if(count>1) {
+                       if(efa->e1->f & SELECT) count++;
+                       if(efa->e2->f & SELECT) count++;
+                       if(efa->e3->f & SELECT) count++;
+                       if(efa->e4 && (efa->e4->f & SELECT)) count++;
+                       if(count) {
                                BLI_remlink(&em->faces, efa);
                                free_editface(efa);
                        }
@@ -859,7 +859,7 @@ void delete_mesh(void)
                eed= em->edges.first;
                while(eed) {
                        nexted= eed->next;
-                       if( (eed->v1->f & SELECT) && (eed->v2->f & SELECT) ) {
+                       if(eed->f & SELECT) {
                                remedge(eed);
                                free_editedge(eed);
                        }
@@ -883,30 +883,31 @@ void delete_mesh(void)
        } 
        else if(event==1) {
                str= "Erase Edges";
-               eed= em->edges.first;
-               while(eed) {
-                       nexted= eed->next;
-                       if( (eed->v1->f & SELECT) && (eed->v2->f & SELECT) ) {
-                               remedge(eed);
-                               free_editedge(eed);
-                       }
-                       eed= nexted;
-               }
+               // faces first
                efa= em->faces.first;
                while(efa) {
                        nextvl= efa->next;
                        event=0;
-                       if( efa->v1->f & SELECT) event++;
-                       if( efa->v2->f & SELECT) event++;
-                       if( efa->v3->f & SELECT) event++;
-                       if(efa->v4 && (efa->v4->f & SELECT)) event++;
+                       if( efa->e1->f & SELECT) event++;
+                       if( efa->e2->f & SELECT) event++;
+                       if( efa->e3->f & SELECT) event++;
+                       if(efa->e4 && (efa->e4->f & SELECT)) event++;
                        
-                       if(event>1) {
+                       if(event) {
                                BLI_remlink(&em->faces, efa);
                                free_editface(efa);
                        }
                        efa= nextvl;
                }
+               eed= em->edges.first;
+               while(eed) {
+                       nexted= eed->next;
+                       if(eed->f & SELECT) {
+                               remedge(eed);
+                               free_editedge(eed);
+                       }
+                       eed= nexted;
+               }
                /* to remove loose vertices: */
                eed= em->edges.first;
                while(eed) {
@@ -917,7 +918,7 @@ void delete_mesh(void)
                eve= em->verts.first;
                while(eve) {
                        nextve= eve->next;
-                       if(eve->f & 1) {
+                       if(eve->f & SELECT) {
                                BLI_remlink(&em->verts,eve);
                                free_editvert(eve);
                        }
@@ -940,7 +941,7 @@ void delete_mesh(void)
                efa= em->faces.first;
                while(efa) {
                        nextvl= efa->next;
-                       if(faceselectedAND(efa, 1)) {
+                       if(efa->f & SELECT) {
                                BLI_remlink(&em->faces, efa);
                                free_editface(efa);
                        }
@@ -1040,7 +1041,7 @@ void fill_mesh(void)
        BLI_end_edgefill();
 
        waitcursor(0);
-
+       EM_select_flush();
        countall();
        allqueue(REDRAWVIEW3D, 0);
        makeDispList(G.obedit);
index 727989908ed2d0444d35af184f233f9757945fd8..499f4fc018b93b194913b25c57c0f763d58a03ba 100644 (file)
@@ -683,7 +683,6 @@ static int edge_fully_inside_rect(rcti rect, short x1, short y1, short x2, short
        
 }
 
-
 static int edge_inside_rect(rcti rect, short x1, short y1, short x2, short y2)
 {
        int d1, d2, d3, d4;
@@ -710,6 +709,29 @@ static int edge_inside_rect(rcti rect, short x1, short y1, short x2, short y2)
        return 1;
 }
 
+static int edge_inside_circle(short centx, short centy, short rad, short x1, short y1, short x2, short y2)
+{
+       int radsq= rad*rad;
+       float v1[2], v2[2], v3[2];
+       
+       // check points in circle itself
+       if( (x1-centx)*(x1-centx) + (y1-centy)*(y1-centy) <= radsq ) return 1;
+       if( (x2-centx)*(x2-centx) + (y2-centy)*(y2-centy) <= radsq ) return 1;
+       
+       // pointdistline
+       v3[0]= centx;
+       v3[1]= centy;
+       v1[0]= x1;
+       v1[1]= y1;
+       v2[0]= x2;
+       v2[1]= y2;
+       
+       if( PdistVL2Dfl(v3, v1, v2) < (float)rad ) return 1;
+       
+       return 0;
+}
+
+
 /**
  * Does the 'borderselect' command. (Select verts based on selecting with a 
  * border: key 'b'). All selecting seems to be done in the get_border part.
@@ -811,7 +833,7 @@ void borderselect(void)
                                        for(efa= em->faces.first; efa; efa= efa->next) {
                                                if(efa->h==0 && efa->xs>rect.xmin && efa->xs<rect.xmax) {
                                                        if(efa->ys>rect.ymin && efa->ys<rect.ymax) {
-                                                               EM_select_face(efa, val==LEFTMOUSE);
+                                                               EM_select_face_fgon(efa, val==LEFTMOUSE);
                                                        }
                                                }
                                        }
@@ -995,7 +1017,7 @@ void borderselect(void)
                allqueue(REDRAWINFO, 0);
        }
 
-       BIF_undo_push("Border select");
+       if(val) BIF_undo_push("Border select");
        
 } /* end of borderselect() */
 
@@ -1014,23 +1036,56 @@ void mesh_selectionCB(int selecting, Object *editobj, short *mval, float rad)
 {
        EditMesh *em = G.editMesh;
        EditVert *eve;
+       EditEdge *eed;
+       EditFace *efa;
        float x, y, r;
 
-       calc_meshverts_ext();   /* drawobject.c */
-       eve= em->verts.first;
-       while(eve) {
-               if(eve->h==0) {
-                       x= eve->xs-mval[0];
-                       y= eve->ys-mval[1];
-                       r= sqrt(x*x+y*y);
-                       if(r<=rad) {
-                               if(selecting==LEFTMOUSE) eve->f|= 1;
-                               else eve->f&= 254;
+       if(G.scene->selectmode & SCE_SELECT_VERTEX) {
+               calc_meshverts_ext();   /* drawobject.c */
+               eve= em->verts.first;
+               while(eve) {
+                       if(eve->h==0) {
+                               x= eve->xs-mval[0];
+                               y= eve->ys-mval[1];
+                               r= sqrt(x*x+y*y);
+                               if(r<=rad) {
+                                       if(selecting==LEFTMOUSE) eve->f|= 1;
+                                       else eve->f&= 254;
+                               }
                        }
+                       eve= eve->next;
                }
-               eve= eve->next;
        }
 
+       if(G.scene->selectmode & SCE_SELECT_EDGE) {
+               calc_meshverts_ext_f2();        /* doesnt clip, drawobject.c */
+               
+               /* two stages, for nice edge select first do 'both points in rect' */
+               for(eed= em->edges.first; eed; eed= eed->next) {
+                       if(eed->h==0) {
+                               if( edge_inside_circle(mval[0], mval[1], (short)rad, eed->v1->xs, eed->v1->ys,  eed->v2->xs, eed->v2->ys)) {
+                                       EM_select_edge(eed, selecting==LEFTMOUSE);
+                               }
+                       }
+               }
+       }
+       
+       if(G.scene->selectmode & SCE_SELECT_FACE) {
+               calc_mesh_facedots_ext();
+               for(efa= em->faces.first; efa; efa= efa->next) {
+                       if(efa->h==0) {
+                               x= efa->xs-mval[0];
+                               y= efa->ys-mval[1];
+                               r= sqrt(x*x+y*y);
+                               if(r<=rad) {
+                                       EM_select_face_fgon(efa, selecting==LEFTMOUSE);
+                               }
+                       }
+               }
+       }
+                               
+       EM_selectmode_flush();
+
        draw_sel_circle(0, 0, 0, 0, 0); /* signal */
        force_draw();