diff options
author | Geoffrey Bantle <hairbat@yahoo.com> | 2006-03-27 09:19:14 +0400 |
---|---|---|
committer | Geoffrey Bantle <hairbat@yahoo.com> | 2006-03-27 09:19:14 +0400 |
commit | 7b1d69a35c80cffef4965616731deb68760b6fb2 (patch) | |
tree | 17a98ca3c76eeb3f3c790507bcff305520704db7 /source/blender/src/editmesh_lib.c | |
parent | 07b88496e0a1bc1662eb8059c14e1fdf5d7d2584 (diff) |
-> Stored Selections
Previously Blender did not store the order in which vertices, edges
or faces were selected in edit mode. In many cases it is useful to
have this data, however it is not desirable to store every selection
made. Now blender stores selections in the order in which they were
made in a linked list called 'selected' in EditMesh. EditSelection structs
are created whenever 'EM_store_selection' from editmesh_lib.c is called
(currently only on user selection with mouse). There are several cases
in which they might be deallocated by calling the 'EM_remove_selection'
function however:
-When the user deselects something with the mouse ('mouse_mesh' in
editmesh_mods.c)
-When switching selection modes stored selections that are not relevant
to the new mode are removed by the 'EM_strip_selections' function
(multi-select mode is supported)
-When the vertex, edge or face pointed to by a certain stored selection is
deallocated
-When EM_clear_flag_all is called and where the flag passed to the function
contains the 'SELECT' bitmask.
-When leaving edit mode (making stored selection data persistent across
editing sessions will require modifications to mesh DNA later)
Todo:
There are a few cases still where you can temporarily end up with a stored
selection that points to an element that is no longer selected
(edge loop de-select can cause this for instance). The solution to this is to
add a call to EM_remove_selection from 'EM_select_edge' and 'EM_select_face' when
these functions are being used to deselect elements. For the sake of completeness
however this will also require that an 'EM_select_vert' function be coded and
called at all appropriate parts of the editmesh code. I will look into this
later in the week.
For now there are two tools that already take advantage of the stored selections.
The first one is 'merge at first or last vertex' in the merge menu (the 'firstvert' and
'lastvert' pointers are gone from EditMesh). The second tool is path select, which builds
a path between the last vert selected and the second to last vert selected. This allows you
to build complex path selections in a short amount of time like this
'select A, select B, path select. select C, path select. select D...'
Diffstat (limited to 'source/blender/src/editmesh_lib.c')
-rw-r--r-- | source/blender/src/editmesh_lib.c | 72 |
1 files changed, 70 insertions, 2 deletions
diff --git a/source/blender/src/editmesh_lib.c b/source/blender/src/editmesh_lib.c index c3cd12f1ebf..bf64fdc34cc 100644 --- a/source/blender/src/editmesh_lib.c +++ b/source/blender/src/editmesh_lib.c @@ -67,7 +67,74 @@ editmesh_lib: generic (no UI, no menus) operations/evaluators for editmesh data #include "editmesh.h" +//TODO +//fix undo code. Biggest one. +//fix issues with EM_selectmode_set() +//get rid of 'lastvert' and 'firstvert' hacks in EditMesh struct and clean from undo code and 'load_editmesh' code and elsewhere +//find out if storing EditSelection(s) in Mesh DNA is 'ok', even if only for runtime(?) + /* ********* Selection ************ */ +static int EM_check_selection(void *data) +{ + EditSelection *ese; + + for(ese = G.editMesh->selected.first; ese; ese = ese->next){ + if(ese->data == data) return 1; + } + + return 0; +} + +void EM_remove_selection(void *data, int type) +{ + EditSelection *ese; + for(ese=G.editMesh->selected.first; ese; ese = ese->next){ + if(ese->data == data){ + BLI_freelinkN(&(G.editMesh->selected),ese); + break; + } + } +} + +void EM_store_selection(void *data, int type) +{ + EditSelection *ese; + if(!EM_check_selection(data)){ + ese = (EditSelection*) MEM_callocN( sizeof(EditSelection), "Edit Selection"); + ese->type = type; + ese->data = data; + BLI_addtail(&(G.editMesh->selected),ese); + } +} + +static void EM_strip_selections(void) +{ + EditSelection *ese, *nextese; + if(!(G.scene->selectmode & SCE_SELECT_VERTEX)){ + ese = G.editMesh->selected.first; + while(ese){ + nextese = ese->next; + if(ese->type == EDITVERT) BLI_freelinkN(&(G.editMesh->selected),ese); + ese = nextese; + } + } + if(!(G.scene->selectmode & SCE_SELECT_EDGE)){ + ese=G.editMesh->selected.first; + while(ese){ + nextese = ese->next; + if(ese->type == EDITEDGE) BLI_freelinkN(&(G.editMesh->selected), ese); + ese = nextese; + } + } + if(!(G.scene->selectmode & SCE_SELECT_FACE)){ + ese=G.editMesh->selected.first; + while(ese){ + nextese = ese->next; + if(ese->type == EDITFACE) BLI_freelinkN(&(G.editMesh->selected), ese); + ese = nextese; + } + } +} void EM_select_face(EditFace *efa, int sel) { @@ -205,6 +272,7 @@ void EM_clear_flag_all(int flag) for (eed= em->edges.first; eed; eed= eed->next) eed->f &= ~flag; for (efa= em->faces.first; efa; efa= efa->next) efa->f &= ~flag; + if(flag & SELECT) BLI_freelistN(&(G.editMesh->selected)); } void EM_set_flag_all(int flag) @@ -463,7 +531,8 @@ void EM_selectmode_set(void) EditVert *eve; EditEdge *eed; EditFace *efa; - + + EM_strip_selections(); /*strip EditSelections from em->selected that are not relevant to new mode*/ if(G.scene->selectmode == SCE_SELECT_VERTEX) { /* vertices -> edges -> faces */ for (eed= em->edges.first; eed; eed= eed->next) eed->f &= ~SELECT; @@ -478,7 +547,6 @@ void EM_selectmode_set(void) if(eed->f & SELECT) EM_select_edge(eed, 1); /* selects faces based on edge status */ EM_selectmode_flush(); - } else if(G.scene->selectmode == SCE_SELECT_FACE) { /* deselect eges, and select again based on face select */ |