Permalink
Browse files

Merge branch 'rj/deselect_previous'

  • Loading branch information...
2 parents cdd7b23 + deddfc1 commit 372e741069b1dae6c28bc5f143e4f84048f4c1c1 Richard Jones committed Nov 18, 2010
Showing with 59 additions and 2 deletions.
  1. +1 −0 plugins_src/commands/Makefile
  2. +56 −0 plugins_src/commands/wpc_deselect_previous.erl
  3. +2 −2 src/wings_sel_cmd.erl
View
1 plugins_src/commands/Makefile
@@ -41,6 +41,7 @@ MODULES= \
wpc_constraints \
wpc_cylindrilize \
wpc_corner \
+ wpc_deselect_previous \
wpc_doosabin \
wpc_explode \
wpc_intersect_edge \
View
56 plugins_src/commands/wpc_deselect_previous.erl
@@ -0,0 +1,56 @@
+
+-module(wpc_deselect_previous).
+-export([init/0,menu/2,command/2]).
+-include("wings.hrl").
+
+init() ->
+ true.
+
+%%% Menu
+menu({select},Menu) ->
+ lists:reverse(parse(Menu, [], false));
+menu(_,Menu) ->
+ Menu.
+
+parse([], NewMenu, true) ->
+ NewMenu;
+parse([], NewMenu, false) ->
+ [deselect_previous(), separator|NewMenu];
+parse([A = {_,inverse,_}|Rest], NewMenu, false) ->
+ parse(Rest, [deselect_previous(),A|NewMenu], true);
+parse([Elem|Rest], NewMenu, Found) ->
+ parse(Rest, [Elem|NewMenu], Found).
+
+deselect_previous() ->
+ {?__(1,"Deselect Previous"),deselect_previous,
+ ?__(2,"Subtract the previous selection state from the current selection")}.
+
+%%% Commands
+command({select,deselect_previous}, St) ->
+ {save_state,deselect_previous(St)};
+command(_, _) ->
+ next.
+
+deselect_previous(St) ->
+ PrevSt = wings_undo:undo(St),
+ deselect_previous(PrevSt, St).
+
+deselect_previous(#st{sel=PrevSel,selmode=Mode}, #st{sel=Sel,selmode=Mode}=St) ->
+ NewSel = subtract(Sel, PrevSel),
+ St#st{sel=NewSel};
+deselect_previous(PrevSt0, #st{selmode=Mode}=St) ->
+ PrevSt = wings_sel_conv:mode(Mode, PrevSt0),
+ deselect_previous(PrevSt, St).
+
+subtract([{Id1,_}=E1|Es1], [{Id2,_}|_]=Set2) when Id1 < Id2 ->
+ [E1|subtract(Es1, Set2)];
+subtract([{Id1,_}|_]=Set1, [{Id2,_}|Es2]) when Id1 > Id2 ->
+ subtract(Set1, Es2);
+subtract([{Id,E1}|Es1], [{Id,E2}|Es2]) ->
+ E = gb_sets:subtract(E1, E2),
+ case gb_sets:is_empty(E) of
+ true -> subtract(Es1, Es2);
+ false -> [{Id,E}|subtract(Es1, Es2)]
+ end;
+subtract([], _Es2) -> [];
+subtract(Es1, []) -> Es1.
View
4 src/wings_sel_cmd.erl
@@ -291,9 +291,9 @@ command({edge_loop,complete_loops}, St) ->
command(deselect, St) ->
{save_state,deselect(St)};
command(more, St) ->
- wings_sel_conv:more(St);
+ {save_state,wings_sel_conv:more(St)};
command(less, St) ->
- wings_sel_conv:less(St);
+ {save_state,wings_sel_conv:less(St)};
command(all, St) ->
{save_state,select_all(St)};
command(lights, St) ->

0 comments on commit 372e741

Please sign in to comment.