Skip to content

Commit 69a1a0c

Browse files
authored
Added the MMB option to the Connect command (#613)
* - Added the MMB option to the Connect command, allowing us to dynamically increase the amount of cut; * - Added changes to wings_drag in order to force the changed object to be updated on screen. That happens when an operation add more elements dynamically, like in this code which we add multiple connections that bacome selected for better feedback. * - Changed the wings_drag code to better handler couter parameters that are integer values which was not handled before. * - Worked on Copilot suggestions
1 parent 11112e6 commit 69a1a0c

File tree

2 files changed

+89
-18
lines changed

2 files changed

+89
-18
lines changed

src/wings_drag.erl

Lines changed: 45 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,9 @@
8282
-type fold_tv() :: basic_tv() | {'we',[we_transform_fun()],basic_tv()}.
8383

8484
-type inf_or_float() :: 'infinity' | float().
85+
-type inf_or_int() :: 'infinity' | integer().
8586
-type limit2() :: {inf_or_float(),inf_or_float()}.
87+
-type limit2i() :: {inf_or_int(),inf_or_int()}.
8688

8789
-type unit() :: 'angle' | {'angle',limit2()}
8890
| 'distance'| {'distance',limit2()}
@@ -94,6 +96,7 @@
9496
| 'percent' | {'percent',limit2()}
9597
| 'rx' | {'rx',limit2()}
9698
| 'skip'
99+
| 'count' | {'count',limit2i()}
97100
| plugin_unit_kludge().
98101

99102
%% FIXME: Should wrap in a tuple, e.e. {custom,CustomType}.
@@ -533,6 +536,9 @@ drag_help(Units) ->
533536
percent ->
534537
Msg = zmove_help(?__(2,"Scale")),
535538
{4,S,[Msg|MsgAcc]};
539+
count ->
540+
Msg = zmove_help(?__(7,"Count")),
541+
{4,S,[Msg|MsgAcc]};
536542
_ when S ->
537543
Msg = zmove_help(wings_util:stringify(P)),
538544
{4,S,[Msg|MsgAcc]};
@@ -548,6 +554,9 @@ drag_help(Units) ->
548554
percent ->
549555
Msg = p4_help(?__(2,"Scale")),
550556
{5,S,[Msg|MsgAcc]};
557+
count ->
558+
Msg = zmove_help(?__(7,"Count")),
559+
{5,S,[Msg|MsgAcc]};
551560
_ when S ->
552561
Msg = p4_help(wings_util:stringify(P)),
553562
{5,S,[Msg|MsgAcc]};
@@ -563,6 +572,9 @@ drag_help(Units) ->
563572
percent ->
564573
Msg = p5_help(?__(2,"Scale")),
565574
{6,S,[Msg|MsgAcc]};
575+
count ->
576+
Msg = zmove_help(?__(7,"Count")),
577+
{6,S,[Msg|MsgAcc]};
566578
_ when S ->
567579
Msg = p5_help(wings_util:stringify(P)),
568580
{6,S,[Msg|MsgAcc]};
@@ -893,6 +905,8 @@ make_move_1([{percent,_}=Unit|Units], [V|Vals]) ->
893905
[clamp(Unit, V/100)|make_move_1(Units, Vals)];
894906
make_move_1([percent|Units], [V|Vals]) ->
895907
[V/100|make_move_1(Units, Vals)];
908+
make_move_1([count|Units], [V|Vals]) ->
909+
[trunc(V)|make_move_1(Units, Vals)];
896910
make_move_1([{U,{_Min,_Max}}=Unit|Units], [V|Vals]) ->
897911
make_move_1([U|Units], [clamp(Unit, V)|Vals]);
898912
make_move_1([_U|Units], [V|Vals]) ->
@@ -1096,7 +1110,11 @@ round_to_constraint([], [], _, Acc) -> reverse(Acc).
10961110

10971111
constrain_1([falloff], _, #drag{falloff=Falloff}) ->
10981112
[Falloff];
1099-
constrain_1([_|Us], [D|Ds], Drag) ->
1113+
constrain_1([{count,_}=U|Us], [D|Ds], Drag) ->
1114+
[clamp(U, trunc(D))|constrain_1(Us, Ds, Drag)];
1115+
constrain_1([count|Us], [D|Ds], Drag) ->
1116+
[trunc(D)|constrain_1(Us, Ds, Drag)];
1117+
constrain_1([_U|Us], [D|Ds], Drag) ->
11001118
[D|constrain_1(Us, Ds, Drag)];
11011119
constrain_1([], _, _) -> [].
11021120

@@ -1364,6 +1382,8 @@ unit(percent, P) ->
13641382
trim(io_lib:format("~.2f% ", [P*100.0]));
13651383
unit(falloff, R) ->
13661384
["R: "|trim(io_lib:format("~10.2f", [R]))];
1385+
unit(count, R) ->
1386+
["C: "|trim(io_lib:format("~10w", [trunc(R)]))];
13671387
unit(skip,_) ->
13681388
%% the atom 'skip' can be used as a place holder. See wpc_arc.erl
13691389
[];
@@ -1379,39 +1399,48 @@ trim([[_|_]=H|T]) ->
13791399
trim(S) -> S.
13801400

13811401
normalize(Move, #drag{mode_fun=ModeFun,mode_data=ModeData,
1382-
st=#st{shapes=Shs0}=St}) ->
1402+
st=#st{shapes=Shs0,sel=Sel0}=St}) ->
13831403
ModeFun(done, ModeData),
13841404
gl:disable(gl_rescale_normal()),
1385-
Shs = wings_dl:map(fun(D, Sh) ->
1405+
{Shs,Sel} = wings_dl:map(fun(D, Sh) ->
13861406
normalize_fun(D, Move, Sh)
1387-
end, Shs0),
1388-
St#st{shapes=Shs}.
1407+
end, {Shs0,Sel0}),
1408+
if Sel=/=Sel0 -> wings_draw:refresh_dlists(St);
1409+
true -> ignore
1410+
end,
1411+
St#st{shapes=Shs,sel=Sel}.
13891412

1390-
normalize_fun(#dlo{drag=none}=D, _Move, Shs) -> {D,Shs};
1413+
normalize_fun(#dlo{drag=none}=D, _Move, ShsSel) -> {D,ShsSel};
13911414
normalize_fun(#dlo{drag={matrix,_,_,_},transparent=#we{id=Id}=We,
1392-
proxy_data=PD}=D0, _Move, Shs0) when ?IS_LIGHT(We) ->
1415+
proxy_data=PD}=D0, _Move, {Shs0,Sel}) when ?IS_LIGHT(We) ->
13931416
Shs = gb_trees:update(Id, We, Shs0),
13941417
D = D0#dlo{work=none,smooth=none,drag=none,src_we=We,transparent=false,
13951418
proxy_data=wings_proxy:invalidate(PD, dl)},
1396-
{wings_draw:changed_we(D, D),Shs};
1397-
normalize_fun(#dlo{drag={matrix,_,_,Matrix},src_we=#we{id=Id}=We0,
1398-
proxy_data=PD}=D0,
1399-
_Move, Shs0) ->
1419+
{wings_draw:changed_we(D, D),{Shs,Sel}};
1420+
normalize_fun(#dlo{drag={matrix,_,_,Matrix},src_sel={_,DSel},src_we=#we{id=Id}=We0,
1421+
proxy_data=PD}=D0, _Move, {Shs0,Sel}) ->
14001422
We1 = We0#we{temp=[]},
14011423
We = wings_we:transform_vs(Matrix, We1),
14021424
Shs = gb_trees:update(Id, We, Shs0),
14031425
D = D0#dlo{work=none,smooth=none,edges=none,sel=none,drag=none,src_we=We,
14041426
mirror=none,proxy_data=wings_proxy:invalidate(PD, dl)},
1405-
{wings_draw:changed_we(D, D),Shs};
1406-
normalize_fun(#dlo{drag={general,Fun},src_we=#we{id=Id}=We0}=D0, Move, Shs) ->
1427+
{wings_draw:changed_we(D, D),{Shs,update_sel(Id,DSel,Sel)}};
1428+
normalize_fun(#dlo{drag={general,Fun}, src_sel={_,DSel}, src_we=#we{id=Id}=We0}=D0,
1429+
Move, {Shs,Sel}) ->
14071430
D1 = Fun({finish,Move}, D0),
14081431
We = We0#we{temp=[]},
14091432
D = D1#dlo{drag=none,sel=none,src_we=We},
1410-
{wings_draw:changed_we(D, D),gb_trees:update(Id, We, Shs)};
1411-
normalize_fun(#dlo{src_we=#we{id=Id}}=D0, _Move, Shs) ->
1433+
{wings_draw:changed_we(D, D),{gb_trees:update(Id, We, Shs),update_sel(Id,DSel,Sel)}};
1434+
normalize_fun(#dlo{src_sel={_,DSel}, src_we=#we{id=Id}}=D0, _Move, {Shs,Sel}) ->
14121435
#dlo{src_we=We0} = D = wings_draw:join(D0),
14131436
We = We0#we{temp=[]},
1414-
{D,gb_trees:update(Id, We, Shs)}.
1437+
{D,{gb_trees:update(Id, We, Shs),update_sel(Id,DSel,Sel)}}.
1438+
1439+
update_sel(Id, DSel, Sel) ->
1440+
case orddict:is_key(Id,Sel) of
1441+
true -> orddict:store(Id,DSel,Sel);
1442+
false -> Sel
1443+
end.
14151444

14161445
%%%
14171446
%%% Redrawing while dragging.

src/wings_edge_cmd.erl

Lines changed: 44 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,9 @@ menu(X, Y, St) ->
4141
separator,
4242
cut_line(St),
4343
{?__(6,"Connect"),connect(),
44-
{?__(7,"Create a new edge by connecting midpoints of selected edges"), [],
45-
?__(25,"Create a new edge and slides it along neighbor edges")},[]},
44+
{?__(7,"Create a new edge by connecting midpoints of selected edges"),
45+
?__(26,"Create multiple parallel edges by connecting selected edges"),
46+
?__(25,"Create a new edge and slides it along neighbor edges")},[]},
4647
{?__(8,"Bevel"),bevel,
4748
?__(9,"Round off selected edges")},
4849
separator,
@@ -69,6 +70,7 @@ menu(X, Y, St) ->
6970
connect() ->
7071
fun
7172
(1, _Ns) -> {edge,connect};
73+
(2, _Ns) -> {edge,connect_multiple};
7274
(3, _Ns) -> {edge,connect_slide};
7375
(_, _) -> ignore
7476
end.
@@ -144,6 +146,8 @@ command({cut,Num}, St) ->
144146
{save_state,cut(Num, St)};
145147
command(connect, St) ->
146148
{save_state,connect(St)};
149+
command(connect_multiple, St) ->
150+
connect_multiple(St);
147151
command(connect_slide, St) ->
148152
connect_slide(St);
149153
command(clean_dissolve, St) ->
@@ -189,6 +193,44 @@ connect(Es0, We0) ->
189193
We = wings_edge:dissolve_isolated_vs(Vs, We2),
190194
{We,Sel}.
191195

196+
connect_multiple(St0) ->
197+
St = wings_sel:map_update_sel(fun connect_multiple_1/2, St0),
198+
ConFun0 = fun([N|_], _)-> N end,
199+
DF = fun(_) -> adjust_fun(ConFun0) end,
200+
Units = [{count,{1,infinity}}],
201+
Flags = [{initial,[1]}],
202+
wings_drag:general(DF, Units, Flags, St).
203+
204+
adjust_fun(AdjFun) ->
205+
fun({finish,Ds}, D) ->
206+
adjust_fun_1(AdjFun, Ds, D);
207+
(Ds, D) -> adjust_fun_1(AdjFun, Ds, D)
208+
end.
209+
210+
adjust_fun_1(AdjFun, Ds, #dlo{src_sel=Sel0,src_we=#we{temp={N0,Es,WeSrc}}=We0}=D) ->
211+
N = AdjFun(Ds, N0),
212+
{We,Sel} =
213+
case N == N0 of
214+
false ->
215+
{_Vs,We1} =
216+
mapfoldl(fun(Edge, W0) ->
217+
{W,V} = wings_edge:cut(Edge, N+1, W0),
218+
{V,W}
219+
end, WeSrc, gb_sets:to_list(Es)),
220+
S = wings_we:new_items_as_gbset(vertex, WeSrc, We1),
221+
We2 = wings_vertex_cmd:connect(gb_sets:to_list(S), We1),
222+
Sel1 = wings_we:new_items_as_gbset(edge, We1, We2),
223+
{We2,{edge,Sel1}};
224+
true -> {We0,Sel0}
225+
end,
226+
D#dlo{src_sel=Sel,src_we=We#we{temp={N,Es,WeSrc}}}.
227+
228+
connect_multiple_1(Es0, We) ->
229+
Es1 = gb_sets:to_list(Es0),
230+
Es2 = remove_nonconnectable(Es1, Es0, We, []),
231+
Es = gb_sets:from_list(Es2),
232+
{We#we{temp={0,Es,We}},Es}.
233+
192234
connect_slide(St0) ->
193235
St = wings_sel:map_update_sel(fun connect/2, St0),
194236
slide(St).

0 commit comments

Comments
 (0)