From 8a0955ab5eeca9a92da85f75749d4180519f2c29 Mon Sep 17 00:00:00 2001 From: Marius Date: Wed, 12 Oct 2011 20:40:14 +0300 Subject: beta 2011.10.12 19:30 --- metapost/context/base/metafun.mpii | 4 +- metapost/context/base/metafun.mpiv | 4 +- metapost/context/base/mp-char.mp | 1019 --------------- metapost/context/base/mp-flow.mpiv | 1020 --------------- metapost/context/base/mp-step.mp | 320 ----- metapost/context/base/mp-step.mpii | 320 +++++ metapost/context/base/mp-step.mpiv | 375 ++++++ tex/context/base/anch-pos.mkiv | 4 - tex/context/base/cont-new.mkii | 2 +- tex/context/base/cont-new.mkiv | 2 +- tex/context/base/context-version.pdf | Bin 4095 -> 4095 bytes tex/context/base/context-version.png | Bin 106412 -> 106290 bytes tex/context/base/context.mkii | 2 +- tex/context/base/context.mkiv | 2 +- tex/context/base/m-chart.lua | 619 +++++++++ tex/context/base/m-chart.mkii | 2 +- tex/context/base/m-chart.mkiv | 1328 -------------------- tex/context/base/m-chart.mkvi | 477 +++++++ tex/context/base/m-flow.lua | 619 --------- tex/context/base/m-flow.mkvi | 477 ------- tex/context/base/m-steps.lua | 227 ++++ tex/context/base/m-steps.mkii | 837 ++++++++++++ tex/context/base/m-steps.mkvi | 382 ++++++ tex/context/base/m-steps.tex | 837 ------------ tex/context/base/status-files.pdf | Bin 23931 -> 23918 bytes tex/context/base/status-lua.pdf | Bin 163361 -> 163358 bytes tex/context/base/x-steps.mkiv | 99 -- tex/generic/context/luatex/luatex-fonts-merged.lua | 2 +- 28 files changed, 3247 insertions(+), 5733 deletions(-) delete mode 100644 metapost/context/base/mp-char.mp delete mode 100644 metapost/context/base/mp-flow.mpiv delete mode 100644 metapost/context/base/mp-step.mp create mode 100644 metapost/context/base/mp-step.mpii create mode 100644 metapost/context/base/mp-step.mpiv create mode 100644 tex/context/base/m-chart.lua delete mode 100644 tex/context/base/m-chart.mkiv create mode 100644 tex/context/base/m-chart.mkvi delete mode 100644 tex/context/base/m-flow.lua delete mode 100644 tex/context/base/m-flow.mkvi create mode 100644 tex/context/base/m-steps.lua create mode 100644 tex/context/base/m-steps.mkii create mode 100644 tex/context/base/m-steps.mkvi delete mode 100644 tex/context/base/m-steps.tex delete mode 100644 tex/context/base/x-steps.mkiv diff --git a/metapost/context/base/metafun.mpii b/metapost/context/base/metafun.mpii index 705900a18..65d7b87f8 100644 --- a/metapost/context/base/metafun.mpii +++ b/metapost/context/base/metafun.mpii @@ -37,8 +37,8 @@ input mp-text.mp ; input mp-txts.mp ; input mp-shap.mp ; input mp-butt.mp ; -input mp-char.mp ; -input mp-step.mp ; +input mp-char.mpii ; +input mp-step.mpii ; input mp-grph.mp ; input mp-figs.mp ; input mp-grid.mp ; diff --git a/metapost/context/base/metafun.mpiv b/metapost/context/base/metafun.mpiv index 80cfcd423..b32e301a7 100644 --- a/metapost/context/base/metafun.mpiv +++ b/metapost/context/base/metafun.mpiv @@ -24,8 +24,8 @@ input mp-text.mp ; input mp-txts.mp ; input mp-butt.mp ; input mp-shap.mp ; -% mp-char.mp ; % there no need to always load this -% mp-step.mp ; % there no need to always load this +% mp-char.mpiv ; % there no need to always load this +% mp-step.mpiv ; % there no need to always load this input mp-grph.mp ; input mp-figs.mp ; input mp-mlib.mpiv ; diff --git a/metapost/context/base/mp-char.mp b/metapost/context/base/mp-char.mp deleted file mode 100644 index 3a7a1d939..000000000 --- a/metapost/context/base/mp-char.mp +++ /dev/null @@ -1,1019 +0,0 @@ -% to be cleaned up, namespace needed ! ! ! ! ! - -%D \module -%D [ file=mp-char.mp, -%D version=1998.10.10, -%D title=\CONTEXT\ \METAPOST\ graphics, -%D subtitle=charts, -%D author=Hans Hagen, -%D date=\currentdate, -%D copyright={PRAGMA / Hans Hagen \& Ton Otten}] -%C -%C This module is part of the \CONTEXT\ macro||package and is -%C therefore copyrighted by \PRAGMA. See licen-en.pdf for -%C details. - -if unknown context_tool : input mp-tool ; fi ; -if unknown context_shap : input mp-shap ; fi ; -if known context_char : endinput ; fi ; - -boolean context_char ; context_char := true ; - -% kan naar elders - -current_position := 0 ; - -def save_text_position (expr p) = % beware: clip shift needed - current_position := current_position + 1 ; - savedata - "\MPposition{" & decimal current_position & "}{" - & decimal xpart p & "}{" - & decimal ypart p & "}%" ; -enddef ; - -%D settings - -grid_width := 60pt ; grid_height := 40pt ; -shape_width := 45pt ; shape_height := 30pt ; - -chart_offset := 2pt ; -color chart_background_color ; chart_background_color := white ; - -%D test mode - -boolean show_mid_points ; show_mid_points := false ; -boolean show_con_points ; show_con_points := false ; -boolean show_all_points ; show_all_points := false ; - -%D shapes - -color shape_line_color, shape_fill_color ; - -shape_line_width := 2pt ; -shape_line_color := .5white ; -shape_fill_color := .9white ; - -shape_node := 0 ; -shape_action := 24 ; -shape_procedure := 5 ; -shape_product := 12 ; -shape_decision := 14 ; -shape_archive := 19 ; -shape_loop := 35 ; -shape_wait := 6 ; -shape_subprocedure := 20 ; shape_sub_procedure := 20 ; -shape_singledocument := 32 ; shape_single_document := 32 ; -shape_multidocument := 33 ; shape_multi_document := 33 ; -shape_right := 66 ; -shape_left := 67 ; -shape_up := 68 ; -shape_down := 69 ; - -% vardef some_shape_path (expr type) == imported from mp-shap - -def show_shapes (expr n) = - - begin_chart(n,8,10) ; - show_con_points := true ; - for i=0 upto 7 : - for j=0 upto 9 : - new_shape(i+1,j+1,i*10+j); - endfor ; - endfor ; - end_chart ; - -enddef ; - -%D connections - -def new_chart = - - color connection_line_color ; - - connection_line_width := shape_line_width ; - connection_line_color := .8white ; - connection_smooth_size := 5pt ; - connection_arrow_size := 4pt ; - connection_dash_size := 3pt ; - - max_x := 6 ; - max_y := 4 ; - - numeric xypoint ; xypoint := 0 ; - - pair xypoints [] ; - - boolean xyfree [][] ; - path xypath [][] ; - numeric xysx [][] ; - numeric xysy [][] ; - color xyfill [][] ; - color xydraw [][] ; - numeric xyline [][] ; - boolean xypeep [][] ; - picture xypicture[][] ; - - numeric cpath ; cpath := 0 ; - path cpaths [] ; - numeric cline [] ; - color ccolor [] ; - boolean carrow [] ; - boolean cdash [] ; - boolean ccross [] ; - - boolean smooth ; smooth := true ; - boolean peepshape ; peepshape := false ; - boolean arrowtip ; arrowtip := true ; - boolean dashline ; dashline := false ; - boolean forcevalid ; forcevalid := false ; - boolean touchshape ; touchshape := false ; - boolean showcrossing ; showcrossing := false ; - - picture dash_pattern ; - - boolean reverse_y ; reverse_y := true ; - -enddef ; - -new_chart ; - -def y_pos (expr y) = - if reverse_y : max_y + 1 - y else : y fi -enddef ; - -def initialize_grid (expr maxx, maxy) = - begingroup ; - save i, j ; - max_x := maxx ; - max_y := maxy ; - dsp_x := 0 ; - dsp_y := 0 ; - for x=1 upto max_x : - for y=1 upto max_y : - xyfree [x][y] := true ; - xyfill [x][y] := shape_fill_color ; - xydraw [x][y] := shape_line_color ; - xyline [x][y] := shape_line_width ; - endfor ; - endfor ; - endgroup ; -enddef ; - -def scaled_to_grid = - xscaled grid_width yscaled grid_height -enddef ; - -def xy_offset (expr x, y) = - (x+.5,y+.5) -enddef ; - -def draw_shape (expr x, yy, p, sx, sy) = - begingroup ; - save y ; - y := y_pos(yy) ; - xypath [x][y] := (p xscaled sx yscaled sy) shifted xy_offset(x,y) ; - xyfree [x][y] := false ; - xysx [x][y] := sx ; - xysy [x][y] := sy ; - xyfill [x][y] := shape_fill_color ; - xydraw [x][y] := shape_line_color ; - xyline [x][y] := shape_line_width ; - xypeep [x][y] := peepshape ; - endgroup ; -enddef ; - -vardef i_point (expr x, y, p, t) = - begingroup ; - save q, ok ; - pair q ; - boolean ok ; - q := xypath[x][y] intersection_point ((p) shifted xy_offset(x,y)) ; - ok := true ; -% if xpart q < -.5 : ok := false ; q := (-.45,ypart q) fi ; -% if xpart q > .5 : ok := false ; q := ( .45,ypart q) fi ; -% if ypart q < -.5 : ok := false ; q := (xpart q,-.45) fi ; -% if ypart q > .5 : ok := false ; q := (xpart q, .45) fi ; - if not ok : - message (t & " of shape (" & decimal x & "," & decimal y & ") limited") ; - fi ; - q - endgroup -enddef ; - -vardef trimmed (expr x, y, z, t) = - if touchshape and t : xyline[x][y]/z else : epsilon fi -enddef ; - -zfactor := 1/3 ; - -vardef xy_bottom (expr x, y, z, t) = - i_point (x, y, ((0,0)--(0,-2)) shifted (zfactor*z*xysx[x][y],0), "bottom") - shifted(0,-trimmed(x,y,grid_height,t)) -enddef ; - -vardef xy_top (expr x, y, z, t) = - i_point (x, y, ((0,0)--(0,2)) shifted (zfactor*z*xysx[x][y],0), "top") - shifted(0,trimmed(x,y,grid_height,t)) -enddef ; - -vardef xy_left (expr x, y, z, t) = - i_point (x, y, ((0,0)--(-2,0)) shifted (0,zfactor*z*xysy[x][y]), "left") - shifted(-trimmed(x,y,grid_width,t),0) -enddef ; - -vardef xy_right (expr x, y, z, t) = - i_point (x, y, ((0,0)--(2,0)) shifted (0,zfactor*z*xysy[x][y]), "right") - shifted(trimmed(x,y,grid_width,t),0) -enddef ; - -def flush_shapes = - for x=1 upto max_x : - for y=1 upto max_y : - flush_shape (x, y) ; - endfor ; - endfor ; -enddef ; - -def flush_pictures = - for x=1 upto max_x : - for y=1 upto max_y : - flush_picture (x, y) ; - endfor ; - endfor ; -enddef ; - - -def draw_connection_point (expr x, y, z) = - pickup pencircle scaled if (z=0): 2 fi xyline[x][y] ; - drawdot xy_bottom(x,y,z,false) scaled_to_grid withcolor (1,0,0) ; - drawdot xy_top (x,y,z,false) scaled_to_grid withcolor (0,1,0) ; - drawdot xy_left (x,y,z,false) scaled_to_grid withcolor (0,0,1) ; - drawdot xy_right (x,y,z,false) scaled_to_grid withcolor (1,1,0) ; -enddef ; - -def flush_shape (expr x, yy) = - begingroup ; - save y ; - y := y_pos(yy) ; - if not xyfree[x][y] : - pickup pencircle scaled xyline[x][y] ; - if xypeep[x][y] : - fill (xypath[x][y] peepholed (unitsquare shifted (x,y))) - scaled_to_grid withpen pencircle scaled 0 - withcolor chart_background_color ; - else : - fill xypath[x][y] scaled_to_grid withcolor xyfill[x][y] ; - fi ; - draw xypath[x][y] scaled_to_grid withcolor xydraw[x][y] ; - if show_con_points or show_all_points : - draw_connection_point (x, y, 0) ; - fi ; - if show_all_points : - for i=-1 upto 1 : - draw_connection_point (x, y, i) ; - endfor ; - fi ; - fi ; - endgroup ; -enddef ; - -vardef points_initialized (expr xfrom, yfrom, xto, yto, n) = - if not xyfree[xfrom][yfrom] and not xyfree[xto][yto] : - xypoint := n ; true - else : - xypoint := 0 ; false - fi -enddef ; - -def collapse_points = % this is now an mp-tool macro - % remove redundant points - n := 1 ; - for i=2 upto xypoint: - if not (xypoints[i]=xypoints[n]) : - n := n + 1 ; - xypoints[n] := xypoints[i] - fi ; - endfor ; - xypoint := n ; - % make straight lines - if xypoints[2]=xypoints[xypoint-1] : - xypoints[3] := xypoints[xypoint] ; - xypoint := 3 ; - fi ; -enddef ; - -vardef smooth_connection (expr a,b) = - sx := connection_smooth_size/grid_width ; - sy := connection_smooth_size/grid_height ; - if ypart a = ypart b : - a shifted (if xpart a >= xpart b : - fi sx,0) -% a shifted (sx*xpart unitvector(b-a),0) - else : - a shifted (0,if ypart a >= ypart b : - fi sy) -% a shifted (0,sy*ypart unitvector(b-a)) - fi -enddef ; - -vardef trim_points = - begingroup - save p, a, b, d, i ; path p ; pair d ; - p := for i=1 upto xypoint-1 : xypoints[i]-- endfor xypoints[xypoint] ; - if touchshape : - a := shape_line_width/grid_width ; - b := shape_line_width/grid_height ; - else : - a := epsilon ; - b := epsilon ; - fi ; - d := direction infinity of p ; - xypoints[xypoint] := xypoints[xypoint] shifted - if xpart d < 0 : (+a,0) ; - elseif xpart d > 0 : (-a,0) ; - elseif ypart d < 0 : (0,+b) ; - elseif ypart d > 0 : (0,-b) ; - else : origin ; - fi ; - d := direction 0 of p ; - xypoints[1] := xypoints[1] shifted - if xpart d < 0 : (-a,0) ; - elseif xpart d > 0 : (+a,0) ; - elseif ypart d < 0 : (0,-b) ; - elseif ypart d > 0 : (0,+b) ; - else : origin ; - fi ; - endgroup -enddef ; - -vardef trim_points = enddef ; - -vardef connection_path = - if reverse_connection : reverse fi (xypoints[1]-- - for i=2 upto xypoint-1 : - if smooth : - smooth_connection(xypoints[i],xypoints[i-1]) .. - controls xypoints[i] and xypoints[i] .. - smooth_connection(xypoints[i],xypoints[i+1]) -- - else : - xypoints[i]-- - fi - endfor - xypoints[xypoint]) -enddef ; - -% vardef connection_path = -% sx := connection_smooth_size/grid_width ; -% sy := connection_smooth_size/grid_height ; -% if reverse_connection : reverse fi -% (for i=1 upto xypoint-1 : xypoints[i] -- endfor xypoints[xypoint]) -% if smooth : cornered max(sx,sy) fi -% enddef ; -% -% primarydef p cornered c = -% if cycle p : -% ((point 0 of p) shifted (c*(unitvector(point 1 of p - point 0 of p))) -- -% for i=1 upto length(p) : -% (point i-1 of p) shifted (c*(unitvector(point i of p - point i-1 of p))) -- -% (point i of p) shifted (c*(unitvector(point i-1 of p - point i of p))) .. -% controls point i of p .. -% endfor cycle) -% else : -% ((point 0 of p) -- -% for i=1 upto length(p)-1 : -% (point i-1 of p) shifted (c*(unitvector(point i of p - point i-1 of p))) -- -% (point i of p) shifted (c*(unitvector(point i-1 of p - point i of p))) .. -% controls point i of p .. -% endfor -% (point length(p) of p)) -% fi -% enddef ; - -def draw_connection = - if xypoint>0 : - collapse_points ; - trim_points ; - cpath := cpath + 1 ; - cpaths[cpath] := connection_path scaled_to_grid ; - cline[cpath] := connection_line_width ; - ccolor[cpath] := connection_line_color ; - carrow[cpath] := arrowtip ; - cdash[cpath] := dashline ; - ccross[cpath] := showcrossing ; - else : - message("no connection defined") ; - fi ; - reverse_connection := false ; -enddef ; - -def flush_connections = - pair ip ; - boolean crossing ; - ahlength := connection_arrow_size ; - dash_pattern := dashpattern(on connection_dash_size off connection_dash_size ) ; - for i=1 upto cpath : - if ccross[i] : - crossing := false ; - for j=1 upto i : - %if not ((point infinity of cpaths[i] = point infinity of cpaths[j]) or - % (point 0 of cpaths[i] = point 0 of cpaths[j])) : - if not (point infinity of cpaths[i] = point infinity of cpaths[j]) : - ip := cpaths[i] intersection_point cpaths[j] ; - if intersection_found : crossing := true fi ; - fi ; - endfor ; - if crossing : - pickup pencircle scaled 2cline[i] ; - %draw cpaths[i] withcolor chart_background_color ; - path cp ; cp := cpaths[i] ; - cp := cp cutbefore point .05 length cp of cp ; - cp := cp cutafter point .95 length cp of cp ; - draw cp withcolor chart_background_color ; - fi ; - fi ; - pickup pencircle scaled cline[i] ; - if carrow[i] : - if cdash[i] : - drawarrow cpaths[i] withcolor ccolor[i] dashed dash_pattern ; - else : - drawarrow cpaths[i] withcolor ccolor[i] ; - fi ; - else : - if cdash[i] : - draw cpaths[i] withcolor ccolor[i] dashed dash_pattern ; - else : - draw cpaths[i] withcolor ccolor[i] ; - fi ; - fi ; - draw_midpoint (i) ; - endfor ; -enddef ; - -def draw_midpoint (expr n) = - begingroup - save p ; - pair p ; - p := point .5*length(cpaths[n]) of cpaths[n]; - pickup pencircle scaled 2cline[n] ; - save_text_position (p) ; - if show_mid_points : - drawdot p withcolor .7white ; - fi ; - endgroup ; -enddef ; - -def flush_picture(expr x, y) = - if known xypicture[x][y]: - draw xypicture[x][y] shifted xy_offset((x+0.5)*grid_width,(max_y-y+1.5)*grid_height) ; - fi ; -enddef ; - -def chart_draw_picture(expr x, y, p) = - xypicture[x][y] := p ; -enddef ; - -boolean reverse_connection ; reverse_connection := false ; - -vardef up_on_grid (expr n) = - (xpart xypoints[n],(ypart xypoints[n]+1) div 1) -enddef ; - -vardef down_on_grid (expr n) = - (xpart xypoints[n],(ypart xypoints[n]) div 1) -enddef ; - -vardef left_on_grid (expr n) = - ((xpart xypoints[n]) div 1, ypart xypoints[n]) -enddef ; - -vardef right_on_grid (expr n) = - ((xpart xypoints[n]+1) div 1, ypart xypoints[n]) -enddef ; - -vardef x_on_grid (expr n, xfrom, xto, zfrom) = - if (xfrom=xto) and not (zfrom=0) : - if (zfrom=1) : right_on_grid(2) else : left_on_grid(2) fi - elseif xpart xypoints[1] < xpart xypoints[6] : - right_on_grid(n) - else : - left_on_grid(n) - fi -enddef ; - -vardef y_on_grid (expr n, yfrom, yto, zfrom) = - if (yfrom=yto) and not (zfrom=0) : - if (zfrom=1) : up_on_grid(2) else : down_on_grid(2) fi - elseif ypart xypoints[1] < ypart xypoints[6] : - up_on_grid(n) - else : - down_on_grid(n) - fi -enddef ; - -vardef xy_on_grid (expr n, m) = - (xpart xypoints[n], ypart xypoints[m]) -enddef ; - -vardef down_to_grid (expr a,b) = - (xpart xypoints[a], - ypart xypoints[if ypart xypoints[a]ypart xypoints[b]:a else:b fi]) -enddef ; - -vardef left_to_grid (expr a,b) = - (xpart xypoints[if xpart xypoints[a]xpart xypoints[b]:a else:b fi], - ypart xypoints[a]) -enddef ; - -% vardef boundingboxfraction(expr p, f) = -% ((boundingbox p) enlarged (-f*bbwidth(p),-f*bbheight(p))) -% enddef ; - -vardef valid_connection (expr xfrom, yfrom, xto, yto) = - begingroup ; - save ok, vc, pp ; - boolean ok ; - % check for slanted lines - ok := true ; - for i=1 upto xypoint-1 : - if not ((xpart xypoints[i]=xpart xypoints[i+1]) or - (ypart xypoints[i]=ypart xypoints[i+1])) : ok := false ; - fi ; - endfor ; - if not ok : - %message("slanted"); - false - elseif forcevalid : - %message("force"); - true - elseif (xfrom=xto) and (yfrom=yto) : - %message("self"); - false - else : - % check for crossing shapes - pair vc ; - path pp ; - - pair xyfirst, xylast ; - xyfirst := xypoints[1] ; - xylast := xypoints[xypoint] ; - trim_points ; - pp := for i=1 upto xypoint-1 : xypoints[i]-- endfor xypoints[xypoint] ; - xypoints[1] := xyfirst ; - xypoints[xypoint] := xylast ; - - for i=1 upto max_x : - for j=1 upto max_y : % was bug: xfrom,yto - if not ( ( (i,j)=(xfrom,yfrom) ) or ( (i,j)=(xto,yto) ) ) : - if not xyfree[i][j] : - vc := pp intersection_point xypath[i][j] ; - if intersection_found : ok := false fi ; - fi ; - fi ; - endfor ; - endfor ; - %if not ok: message("crossing") ; fi ; - ok - fi - endgroup -enddef ; - -def connect_top_bottom (expr xfrom,yyfrom,zfrom) (expr xto,yyto,zto) = - yfrom := y_pos(yyfrom) ; yto := y_pos(yyto) ; - if points_initialized(xfrom,yfrom,xto,yto,6) : - xypoints[1] := xy_top(xfrom,yfrom,zfrom,true) ; - xypoints[6] := xy_bottom(xto,yto,zto,true) ; - xypoints[2] := up_on_grid(1) ; - xypoints[5] := down_on_grid(6) ; - xypoints[3] := up_to_grid(2,5) ; - xypoints[4] := up_to_grid(2,5) ; - if not valid_connection(xfrom,yfrom,xto,yto) : - xypoints[3] := x_on_grid(2,xfrom,xto,zfrom) ; - xypoints[4] := xy_on_grid(3,5) ; - fi ; - %%%% begin experiment - xypoints[3] := xypoints[3] shifted (dsp_x,0) ; - xypoints[4] := xypoints[4] shifted (dsp_x,0) ; - if dsp_y>0 : - xypoints[2] := xypoints[2] shifted (0,dsp_y) ; - xypoints[3] := xypoints[3] shifted (0,dsp_y) ; - elseif dsp_y<0 : - xypoints[4] := xypoints[4] shifted (0,dsp_y) ; - xypoints[5] := xypoints[5] shifted (0,dsp_y) ; - fi - %%%% end experiment - draw_connection ; - fi ; -enddef ; - -def connect_left_right (expr xfrom,yyfrom,zfrom) (expr xto,yyto,zto) = - yfrom := y_pos(yyfrom) ; yto := y_pos(yyto) ; - if points_initialized(xfrom,yfrom,xto,yto,6) : - xypoints[1] := xy_left(xfrom,yfrom,zfrom,true) ; - xypoints[6] := xy_right(xto,yto,zto,true) ; - xypoints[2] := left_on_grid(1) ; - xypoints[5] := right_on_grid(6) ; - xypoints[3] := left_to_grid(2,5) ; - xypoints[4] := left_to_grid(2,5) ; - if not valid_connection(xfrom,yfrom,xto,yto) : - xypoints[3] := y_on_grid(2,yfrom,yto,zfrom) ; - xypoints[4] := xy_on_grid(5,3) ; - fi ; - draw_connection ; - fi ; -enddef ; - -def connect_left_top (expr xfrom,yyfrom,zfrom) (expr xto,yyto,zto) = - yfrom := y_pos(yyfrom) ; yto := y_pos(yyto) ; - if points_initialized(xfrom,yfrom,xto,yto,5) : - xypoints[1] := xy_left(xfrom,yfrom,zfrom,true) ; - xypoints[5] := xy_top(xto,yto,zto,true) ; - xypoints[2] := left_on_grid(1) ; - xypoints[4] := up_on_grid(5) ; - xypoints[3] := left_to_grid(2,5) ; - if not valid_connection(xfrom,yfrom,xto,yto) : - xypoints[3] := xy_on_grid(2,4) ; - fi ; - draw_connection ; - fi ; -enddef ; - -def connect_left_bottom (expr xfrom,yyfrom,zfrom) (expr xto,yyto,zto) = - yfrom := y_pos(yyfrom) ; yto := y_pos(yyto) ; - if points_initialized(xfrom,yfrom,xto,yto,5) : - xypoints[1] := xy_left(xfrom,yfrom,zfrom,true) ; - xypoints[5] := xy_bottom(xto,yto,zto,true) ; - xypoints[2] := left_on_grid(1) ; - xypoints[4] := down_on_grid(5) ; - xypoints[3] := left_to_grid(2,5) ; - if not valid_connection(xfrom,yfrom,xto,yto) : - xypoints[3] := xy_on_grid(2,4) ; - fi ; - draw_connection ; - fi ; -enddef ; - -def connect_right_top (expr xfrom,yyfrom,zfrom) (expr xto,yyto,zto) = - yfrom := y_pos(yyfrom) ; yto := y_pos(yyto) ; - if points_initialized(xfrom,yfrom,xto,yto,5) : - xypoints[1] := xy_right(xfrom,yfrom,zfrom,true) ; - xypoints[5] := xy_top(xto,yto,zto,true) ; - xypoints[2] := right_on_grid(1) ; - xypoints[4] := up_on_grid(5) ; - xypoints[3] := right_to_grid(2,5) ; - if not valid_connection(xfrom,yfrom,xto,yto) : - xypoints[3] := xy_on_grid(2,4) ; - fi ; - draw_connection ; - fi ; -enddef ; - -def connect_right_bottom (expr xfrom,yyfrom,zfrom) (expr xto,yyto,zto) = - yfrom := y_pos(yyfrom) ; yto := y_pos(yyto) ; - if points_initialized(xfrom,yfrom,xto,yto,5) : - xypoints[1] := xy_right(xfrom,yfrom,zfrom,true) ; - xypoints[5] := xy_bottom(xto,yto,zto,true) ; - xypoints[2] := right_on_grid(1) ; - xypoints[4] := down_on_grid(5) ; - xypoints[3] := right_to_grid(2,5) ; - if not valid_connection(xfrom,yfrom,xto,yto) : - xypoints[3] := xy_on_grid(2,4) ; - fi ; - %%%% begin experiment - xypoints[2] := xypoints[2] shifted (dsp_x,0) ; - xypoints[3] := xypoints[3] shifted (dsp_x,0) ; - if dsp_y>0 : - xypoints[3] := xypoints[3] shifted (0,-dsp_y) ; - xypoints[4] := xypoints[4] shifted (0,-dsp_y) ; - elseif dsp_y<0 : - xypoints[3] := xypoints[3] shifted (0,dsp_y) ; - xypoints[4] := xypoints[4] shifted (0,dsp_y) ; - fi - %%%% end experiment - draw_connection ; - fi ; -enddef ; - -def connect_left_left (expr xfrom,yyfrom,zfrom) (expr xto,yyto,zto) = - yfrom := y_pos(yyfrom) ; yto := y_pos(yyto) ; - if points_initialized(xfrom,yfrom,xto,yto,6) : - xypoints[1] := xy_left(xfrom,yfrom,zfrom,true) ; - xypoints[6] := xy_left(xto,yto,zto,true) ; - xypoints[2] := left_on_grid(1) ; - xypoints[5] := left_on_grid(6) ; - xypoints[3] := left_to_grid(2,5) ; - xypoints[4] := left_to_grid(5,2) ; - if not valid_connection(xfrom,yfrom,xto,yto) : - xypoints[3] := y_on_grid(2,yfrom,yto,zfrom) ; - xypoints[4] := xy_on_grid(5,3) ; - fi ; - draw_connection ; - fi ; -enddef ; - -def connect_right_right (expr xfrom,yyfrom,zfrom) (expr xto,yyto,zto) = - yfrom := y_pos(yyfrom) ; yto := y_pos(yyto) ; - if points_initialized(xfrom,yfrom,xto,yto,6) : - xypoints[1] := xy_right(xfrom,yfrom,zfrom,true) ; - xypoints[6] := xy_right(xto,yto,zto,true) ; - xypoints[2] := right_on_grid(1) ; - xypoints[5] := right_on_grid(6) ; - xypoints[3] := right_to_grid(2,5) ; - xypoints[4] := right_to_grid(5,2) ; - if not valid_connection(xfrom,yfrom,xto,yto) : - xypoints[3] := y_on_grid(2,yfrom,yto,zfrom) ; - xypoints[4] := xy_on_grid(5,3) ; - fi ; - draw_connection ; - fi ; -enddef ; - -def connect_top_top (expr xfrom,yyfrom,zfrom) (expr xto,yyto,zto) = - yfrom := y_pos(yyfrom) ; yto := y_pos(yyto) ; - if points_initialized(xfrom,yfrom,xto,yto,6) : - xypoints[1] := xy_top(xfrom,yfrom,zfrom,true) ; - xypoints[6] := xy_top(xto,yto,zto,true) ; - xypoints[2] := up_on_grid(1) ; - xypoints[5] := up_on_grid(6) ; - xypoints[3] := up_to_grid(2,5) ; - xypoints[4] := up_to_grid(5,2) ; - if not valid_connection(xfrom,yfrom,xto,yto) : - xypoints[3] := x_on_grid(2,xfrom,xto,zfrom) ; - xypoints[4] := xy_on_grid(3,5) ; - fi ; - draw_connection ; - fi ; -enddef ; - -def connect_bottom_bottom (expr xfrom,yyfrom,zfrom) (expr xto,yyto,zto) = - yfrom := y_pos(yyfrom) ; yto := y_pos(yyto) ; - if points_initialized(xfrom,yfrom,xto,yto,6) : - xypoints[1] := xy_bottom(xfrom,yfrom,zfrom,true) ; - xypoints[6] := xy_bottom(xto,yto,zto,true) ; - xypoints[2] := down_on_grid(1) ; - xypoints[5] := down_on_grid(6) ; - xypoints[3] := down_to_grid(2,5) ; - xypoints[4] := down_to_grid(5,2) ; - if not valid_connection(xfrom,yfrom,xto,yto) : - xypoints[3] := x_on_grid(2,xfrom,xto,zfrom) ; - xypoints[4] := xy_on_grid(3,5) ; - fi ; - %%%% begin experiment - xypoints[3] := xypoints[3] shifted (dsp_x,0) ; - xypoints[4] := xypoints[4] shifted (dsp_x,0) ; - if dsp_y<0 : - xypoints[2] := xypoints[2] shifted (0,-dsp_y) ; - xypoints[3] := xypoints[3] shifted (0,-dsp_y) ; - elseif dsp_y>0 : - xypoints[4] := xypoints[4] shifted (0,dsp_y) ; - xypoints[5] := xypoints[5] shifted (0,dsp_y) ; - fi - %%%% end experiment - draw_connection ; - fi ; -enddef ; - -def connect_bottom_top (expr xfrom,yfrom,zfrom) (expr xto,yto,zto) = - reverse_connection := true ; - connect_top_bottom (xto,yto,zto) (xfrom,yfrom,zfrom) ; -enddef ; - -def connect_right_left (expr xfrom,yfrom,zfrom) (expr xto,yto,zto) = - reverse_connection := true ; - connect_left_right (xto,yto,zto) (xfrom,yfrom,zfrom) ; -enddef ; - -def connect_top_left (expr xfrom,yfrom,zfrom) (expr xto,yto,zto) = - reverse_connection := true ; - connect_left_top (xto,yto,zto) (xfrom,yfrom,zfrom) ; -enddef ; - -def connect_bottom_left (expr xfrom,yfrom,zfrom) (expr xto,yto,zto) = - reverse_connection := true ; - connect_left_bottom (xto,yto,zto) (xfrom,yfrom,zfrom) ; -enddef ; - -def connect_top_right (expr xfrom,yfrom,zfrom) (expr xto,yto,zto) = - reverse_connection := true ; - connect_right_top (xto,yto,zto) (xfrom,yfrom,zfrom) ; -enddef ; - -def connect_bottom_right (expr xfrom,yfrom,zfrom) (expr xto,yto,zto) = - reverse_connection := true ; - connect_right_bottom (xto,yto,zto) (xfrom,yfrom,zfrom) ; -enddef ; - -def draw_test_shape (expr x, y) = - draw_shape(x,y,fullcircle, .7, .7) ; -enddef ; - -def draw_test_shapes = - for i=1 upto max_x : - for j=1 upto max_y : - draw_test_shape(i,j) ; - endfor ; - endfor ; -enddef; - -def draw_test_area = - pickup pencircle scaled .5shape_line_width ; - draw (unitsquare xscaled max_x yscaled max_y shifted (1,1)) - scaled_to_grid withcolor blue ; -enddef ; - -def show_connection (expr n, m) = - - begin_chart(100+n,6,6) ; - - draw_test_area ; - - smooth := true ; - arrowtip := true ; - dashline := true ; - - draw_test_shape(2,2) ; draw_test_shape(4,5) ; - draw_test_shape(3,3) ; draw_test_shape(5,1) ; - draw_test_shape(2,5) ; draw_test_shape(1,3) ; - draw_test_shape(6,2) ; draw_test_shape(4,6) ; - - if (m=1) : - connect_top_bottom (2,2,0) (4,5,0) ; - connect_top_bottom (3,3,0) (5,1,0) ; - connect_top_bottom (2,5,0) (1,3,0) ; - connect_top_bottom (6,2,0) (4,6,0) ; - elseif (m=2) : - connect_top_top (2,2,0) (4,5,0) ; - connect_top_top (3,3,0) (5,1,0) ; - connect_top_top (2,5,0) (1,3,0) ; - connect_top_top (6,2,0) (4,6,0) ; - elseif (m=3) : - connect_bottom_bottom (2,2,0) (4,5,0) ; - connect_bottom_bottom (3,3,0) (5,1,0) ; - connect_bottom_bottom (2,5,0) (1,3,0) ; - connect_bottom_bottom (6,2,0) (4,6,0) ; - elseif (m=4) : - connect_left_right (2,2,0) (4,5,0) ; - connect_left_right (3,3,0) (5,1,0) ; - connect_left_right (2,5,0) (1,3,0) ; - connect_left_right (6,2,0) (4,6,0) ; - elseif (m=5) : - connect_left_left (2,2,0) (4,5,0) ; - connect_left_left (3,3,0) (5,1,0) ; - connect_left_left (2,5,0) (1,3,0) ; - connect_left_left (6,2,0) (4,6,0) ; - elseif (m=6) : - connect_right_right (2,2,0) (4,5,0) ; - connect_right_right (3,3,0) (5,1,0) ; - connect_right_right (2,5,0) (1,3,0) ; - connect_right_right (6,2,0) (4,6,0) ; - elseif (m=7) : - connect_left_top (2,2,0) (4,5,0) ; - connect_left_top (3,3,0) (5,1,0) ; - connect_left_top (2,5,0) (1,3,0) ; - connect_left_top (6,2,0) (4,6,0) ; - elseif (m=8) : - connect_left_bottom (2,2,0) (4,5,0) ; - connect_left_bottom (3,3,0) (5,1,0) ; - connect_left_bottom (2,5,0) (1,3,0) ; - connect_left_bottom (6,2,0) (4,6,0) ; - elseif (m=9) : - connect_right_top (2,2,0) (4,5,0) ; - connect_right_top (3,3,0) (5,1,0) ; - connect_right_top (2,5,0) (1,3,0) ; - connect_right_top (6,2,0) (4,6,0) ; - else : - connect_right_bottom (2,2,0) (4,5,0) ; - connect_right_bottom (3,3,0) (5,1,0) ; - connect_right_bottom (2,5,0) (1,3,0) ; - connect_right_bottom (6,2,0) (4,6,0) ; - fi ; - - end_chart ; - -enddef ; - -def show_connections = - for f=1 upto 10 : - show_connection(f,f) ; - endfor ; -enddef ; - -%D charts - -def clip_chart (expr minx, miny, maxx, maxy) = - cmin_x := minx ; - cmax_x := maxx ; - cmin_y := miny ; - cmax_y := maxy ; -enddef ; - -def begin_chart (expr n, maxx, maxy) = - new_chart ; - chart_figure := n ; - chart_scale := 1 ; - if chart_figure>0: beginfig(chart_figure) ; fi ; - startsavingdata ; - initialize_grid (maxx, maxy) ; - bboxmargin := 0 ; - cmin_x := 1 ; - cmax_x := maxx ; - cmin_y := 1 ; - cmax_y := maxy ; -enddef ; - -def end_chart = - flush_shapes ; - flush_connections ; - flush_pictures ; - cmin_x := cmin_x ; - cmax_x := cmin_x+cmax_x ; - cmin_y := cmin_y-1 ; - cmax_y := cmin_y+cmax_y ; - if reverse_y : - cmin_y := y_pos(cmin_y) ; - cmax_y := y_pos(cmax_y) ; - fi ; - path p ; - p := (((cmin_x,cmin_y)--(cmax_x,cmin_y)-- - (cmax_x,cmax_y)--(cmin_x,cmax_y)--cycle)) - scaled_to_grid ; - %draw p withcolor red ; - p := p enlarged chart_offset ; - clip currentpicture to p ; - setbounds currentpicture to p ; - savedata - "\MPclippath{" & - decimal xpart llcorner p & "}{" & - decimal ypart llcorner p & "}{" & - decimal xpart urcorner p & "}{" & - decimal ypart urcorner p & "}%" ; - savedata - "\MPareapath{" & - decimal (xpart llcorner p + 2chart_offset) & "}{" & - decimal (ypart llcorner p + 2chart_offset) & "}{" & - decimal (xpart urcorner p - 2chart_offset) & "}{" & - decimal (ypart urcorner p - 2chart_offset) & "}%" ; - currentpicture := currentpicture scaled chart_scale ; - stopsavingdata ; - if chart_figure>0: endfig ; fi ; -enddef ; - -def new_shape (expr x, y, n) = - if known n : - if (x>0) and (x<=max_x) and (y>0) and (y<=max_y) : - sx := shape_width/grid_width ; - sy := shape_height/grid_height ; - draw_shape(x,y,some_shape_path(n), sx, sy) ; - else : - message ("shape outside grid ignored") ; - fi ; - else - message ("shape not known" ) ; - fi ; -enddef ; - -def begin_sub_chart = - begingroup ; - save shape_line_width , connection_line_width ; - save shape_line_color, shape_fill_color, connection_line_color ; - color shape_line_color, shape_fill_color, connection_line_color ; - save smooth, arrowtip, dashline, peepshape ; - boolean smooth, arrowtip, dashline, peepshape ; -enddef ; - -def end_sub_chart = - endgroup ; -enddef ; - -%D done - -endinput ; - -%D testing - -show_shapes(100) ; - -end - -%D more testing - -show_connections ; - -begin_chart (1,4,5) ; - %clip_chart(1,1,1,2) ; - new_shape (1,1,31) ; - new_shape (1,2,3) ; - new_shape (4,4,5) ; - connect_top_left (1,1,0) (4,4,0) ; - connect_bottom_top (1,2,0) (4,4,0) ; - connect_left_right (1,2,0) (1,1,0) ; -end_chart ; - -end diff --git a/metapost/context/base/mp-flow.mpiv b/metapost/context/base/mp-flow.mpiv deleted file mode 100644 index 4cf4af0f9..000000000 --- a/metapost/context/base/mp-flow.mpiv +++ /dev/null @@ -1,1020 +0,0 @@ -%D \module -%D [ file=mp-char.mp, -%D version=2011.10.1, % 1998.10.10, -%D title=\CONTEXT\ \METAPOST\ graphics, -%D subtitle=charts, -%D author=Hans Hagen, -%D date=\currentdate, -%D copyright={PRAGMA / Hans Hagen \& Ton Otten}] -%C -%C This module is part of the \CONTEXT\ macro||package and is -%C therefore copyrighted by \PRAGMA. See licen-en.pdf for -%C details. - -%D This is ancient code .. but I see no need to rewrite it. - -if unknown context_tool : input mp-tool ; fi ; -if unknown context_shap : input mp-shap ; fi ; -if known context_flow : endinput ; fi ; - -boolean context_flow ; context_flow := true ; - -%D settings - -numeric flow_grid_width ; flow_grid_width := 60pt ; -numeric flow_shape_width ; flow_shape_width := 45pt ; -numeric flow_grid_height ; flow_grid_height := 40pt ; -numeric flow_shape_height ; flow_shape_height := 30pt ; -numeric flow_chart_offset ; flow_chart_offset := 2pt ; -color flow_chart_background_color ; flow_chart_background_color := white ; -boolean flow_show_mid_points ; flow_show_mid_points := false ; -boolean flow_show_con_points ; flow_show_con_points := false ; -boolean flow_show_all_points ; flow_show_all_points := false ; -numeric flow_shape_line_width ; flow_shape_line_width := 2pt ; -color flow_shape_line_color ; flow_shape_line_color := .5white ; -color flow_shape_fill_color ; flow_shape_fill_color := .9white ; -color flow_connection_line_color ; flow_connection_line_color := .2white ; - -numeric flow_connection_line_width ; flow_connection_line_width := flow_shape_line_width ; - -numeric flow_connection_smooth_size ; flow_connection_smooth_size := 5pt ; -numeric flow_connection_arrow_size ; flow_connection_arrow_size := 4pt ; -numeric flow_connection_dash_size ; flow_connection_dash_size := 3pt ; - -numeric flow_max_x ; flow_max_x := 6 ; -numeric flow_max_y ; flow_max_y := 4 ; - -boolean flow_smooth ; flow_smooth := true ; -boolean flow_peepshape ; flow_peepshape := false ; -boolean flow_arrowtip ; flow_arrowtip := true ; -boolean flow_dashline ; flow_dashline := false ; -boolean flow_forcevalid ; flow_forcevalid := false ; -boolean flow_touchshape ; flow_touchshape := false ; -boolean flow_showcrossing ; flow_showcrossing := false ; -boolean flow_reverse_y ; flow_reverse_y := true ; - -picture flow_dash_pattern ; flow_dash_pattern := nullpicture ; - -numeric flow_shape_node ; flow_shape_node := 0 ; -numeric flow_shape_action ; flow_shape_action := 24 ; -numeric flow_shape_procedure ; flow_shape_procedure := 5 ; -numeric flow_shape_product ; flow_shape_product := 12 ; -numeric flow_shape_decision ; flow_shape_decision := 14 ; -numeric flow_shape_archive ; flow_shape_archive := 19 ; -numeric flow_shape_loop ; flow_shape_loop := 35 ; -numeric flow_shape_wait ; flow_shape_wait := 6 ; -numeric flow_shape_subprocedure ; flow_shape_subprocedure := 20 ; -numeric flow_shape_singledocument ; flow_shape_singledocument := 32 ; -numeric flow_shape_multidocument ; flow_shape_multidocument := 33 ; -numeric flow_shape_right ; flow_shape_right := 66 ; -numeric flow_shape_left ; flow_shape_left := 67 ; -numeric flow_shape_up ; flow_shape_up := 68 ; -numeric flow_shape_down ; flow_shape_down := 69 ; - -% vardef some_shape_path (expr type) == imported from mp-shap - -def flow_show_shapes(expr n) = - flow_begin_chart(n,8,10) ; - flow_show_con_points := true ; - for i=0 upto 7 : - for j=0 upto 9 : - flow_new_shape(i+1,j+1,i*10+j); - endfor ; - endfor ; - flow_end_chart ; -enddef ; - -%D connections - -def flow_new_chart = - - flow_grid_width := 60pt ; - flow_shape_width := 45pt ; - flow_grid_height := 40pt ; - flow_shape_height := 30pt ; - flow_chart_offset := 2pt ; - flow_chart_background_color := white ; - flow_show_mid_points := false ; - flow_show_con_points := false ; - flow_show_all_points := false ; - flow_shape_line_width := 2pt ; - flow_shape_line_color := .5white ; - flow_shape_fill_color := .9white ; - flow_connection_line_color := .2white ; - flow_connection_line_width := flow_shape_line_width ; - flow_connection_smooth_size := 5pt ; - flow_connection_arrow_size := 4pt ; - flow_connection_dash_size := 3pt ; - - flow_max_x := 6 ; - flow_max_y := 4 ; - - flow_smooth := true ; - flow_peepshape := false ; - flow_arrowtip := true ; - flow_dashline := false ; - flow_forcevalid := false ; - flow_touchshape := false ; - flow_showcrossing := false ; - flow_reverse_y := true ; - - flow_dash_pattern := nullpicture ; - - numeric flow_xypoint ; flow_xypoint := 0 ; - numeric flow_cpath ; flow_cpath := 0 ; - - pair flow_xypoints [] ; - boolean flow_xyfree [][] ; - path flow_xypath [][] ; - numeric flow_xysx [][] ; - numeric flow_xysy [][] ; - color flow_xyfill [][] ; - color flow_xydraw [][] ; - numeric flow_xyline [][] ; - boolean flow_xypeep [][] ; - picture flow_xytext [][] ; - picture flow_xylabel_l[][] ; - picture flow_xylabel_r[][] ; - picture flow_xylabel_t[][] ; - picture flow_xylabel_b[][] ; - picture flow_xyexit_l [][] ; - picture flow_xyexit_r [][] ; - picture flow_xyexit_t [][] ; - picture flow_xyexit_b [][] ; - path flow_cpaths [] ; - numeric flow_cline [] ; - color flow_ccolor [] ; - boolean flow_carrow [] ; - boolean flow_cdash [] ; - boolean flow_ccross [] ; - - picture flow_tpicture[][] ; - picture flow_bpicture[][] ; - picture flow_lpicture[][] ; - picture flow_rpicture[][] ; - - predefined_shapes[61] := (fullcircle scaled (1.5*predefined_shapes_yradius) xscaled (flow_grid_height/flow_grid_width)) ; - predefined_shapes[62] := (fullcircle scaled (2.0*predefined_shapes_yradius) xscaled (flow_grid_height/flow_grid_width)) ; - -enddef ; - -flow_new_chart ; - -def flow_y_pos(expr y) = - if flow_reverse_y : - flow_max_y + 1 - y - else : - y - fi -enddef ; - -def flow_initialize_grid(expr maxx, maxy) = - flow_max_x := maxx ; - flow_max_y := maxy ; - flow_dsp_x := 0 ; - flow_dsp_y := 0 ; - for x=1 upto flow_max_x : - for y=1 upto flow_max_y : - flow_xyfree[x][y] := true ; - flow_xyfill[x][y] := flow_shape_fill_color ; - flow_xydraw[x][y] := flow_shape_line_color ; - flow_xyline[x][y] := flow_shape_line_width ; - endfor ; - endfor ; -enddef ; - -def flow_scaled_to_grid = - xscaled flow_grid_width yscaled flow_grid_height -enddef ; - -def flow_xy_offset(expr x, y) = - (x+.5,y+.5) -enddef ; - -def flow_draw_shape(expr x, yy, p, sx, sy) = - begingroup ; - save y ; numeric y ; - y := flow_y_pos(yy) ; - flow_xypath [x][y] := (p xscaled sx yscaled sy) shifted flow_xy_offset(x,y) ; - flow_xyfree [x][y] := false ; - flow_xysx [x][y] := sx ; - flow_xysy [x][y] := sy ; - flow_xyfill [x][y] := flow_shape_fill_color ; - flow_xydraw [x][y] := flow_shape_line_color ; - flow_xyline [x][y] := flow_shape_line_width ; - flow_xypeep [x][y] := flow_peepshape ; - endgroup ; -enddef ; - -vardef flow_i_point (expr x, y, p, t) = - begingroup ; - save q, ok ; pair q ; boolean ok ; - q := flow_xypath[x][y] intersection_point ((p) shifted flow_xy_offset(x,y)) ; - ok := true ; - if not ok : - message (t & " of shape (" & decimal x & "," & decimal y & ") limited") ; - fi ; - q - endgroup -enddef ; - -vardef flow_trimmed (expr x, y, z, t) = - if flow_touchshape and t : - flow_xyline[x][y]/z - else : - epsilon - fi -enddef ; - -numeric flow_zfactor ; flow_zfactor := 1/3 ; - -vardef flow_xy_bottom (expr x, y, z, t) = - flow_i_point(x, y, ((0,0)--(0,-2)) shifted (flow_zfactor*z*flow_xysx[x][y],0), "bottom") - shifted(0,-flow_trimmed(x,y,flow_grid_height,t)) -enddef ; - -vardef flow_xy_top (expr x, y, z, t) = - flow_i_point (x, y, ((0,0)--(0,2)) shifted (flow_zfactor*z*flow_xysx[x][y],0), "top") - shifted(0,flow_trimmed(x,y,flow_grid_height,t)) -enddef ; - -vardef flow_xy_left (expr x, y, z, t) = - flow_i_point (x, y, ((0,0)--(-2,0)) shifted (0,flow_zfactor*z*flow_xysy[x][y]), "left") - shifted(-flow_trimmed(x,y,flow_grid_width,t),0) -enddef ; - -vardef flow_xy_right (expr x, y, z, t) = - flow_i_point (x, y, ((0,0)--(2,0)) shifted (0,flow_zfactor*z*flow_xysy[x][y]), "right") - shifted(flow_trimmed(x,y,flow_grid_width,t),0) -enddef ; - -def flow_flush_shapes = - for x=1 upto flow_max_x : - for y=1 upto flow_max_y : - flow_flush_shape(x, y) ; - endfor ; - endfor ; -enddef ; - -def flow_flush_pictures = - for x=1 upto flow_max_x : - for y=1 upto flow_max_y : - flow_flush_picture(x, y) ; - endfor ; - endfor ; -enddef ; - -def flow_draw_connection_point(expr x, y, z) = - pickup pencircle scaled if (z=0): 2 fi flow_xyline[x][y] ; - drawdot flow_xy_bottom(x,y,z,false) flow_scaled_to_grid withcolor (1,0,0) ; - drawdot flow_xy_top (x,y,z,false) flow_scaled_to_grid withcolor (0,1,0) ; - drawdot flow_xy_left (x,y,z,false) flow_scaled_to_grid withcolor (0,0,1) ; - drawdot flow_xy_right (x,y,z,false) flow_scaled_to_grid withcolor (1,1,0) ; -enddef ; - -def flow_flush_shape(expr x, yy) = - begingroup ; - save y ; numeric y ; - y := flow_y_pos(yy) ; - if not flow_xyfree[x][y] : - pickup pencircle scaled flow_xyline[x][y] ; - if flow_xypeep[x][y] : - fill (flow_xypath[x][y] peepholed (unitsquare shifted (x,y))) - flow_scaled_to_grid withpen pencircle scaled 0 - withcolor flow_chart_background_color ; - else : - fill flow_xypath[x][y] flow_scaled_to_grid withcolor flow_xyfill[x][y] ; - fi ; - draw flow_xypath[x][y] flow_scaled_to_grid withcolor flow_xydraw[x][y] ; - if flow_show_con_points or flow_show_all_points : - flow_draw_connection_point(x, y, 0) ; - fi ; - if flow_show_all_points : - for i=-1 upto 1 : - flow_draw_connection_point(x, y, i) ; - endfor ; - fi ; - fi ; - endgroup ; -enddef ; - -vardef flow_points_initialized(expr xfrom, yfrom, xto, yto, n) = - if not flow_xyfree[xfrom][yfrom] and not flow_xyfree[xto][yto] : - flow_xypoint := n ; true - else : - flow_xypoint := 0 ; false - fi -enddef ; - -def flow_collapse_points = % this is now an mp-tool macro - begingroup ; - % remove redundant points - save n ; numeric n ; - n := 1 ; - for i=2 upto flow_xypoint : - if not (flow_xypoints[i] = flow_xypoints[n]) : - n := n + 1 ; - flow_xypoints[n] := flow_xypoints[i] - fi ; - endfor ; - flow_xypoint := n ; - % make straight lines - if flow_xypoints[2] = flow_xypoints[flow_xypoint-1] : - flow_xypoints[3] := flow_xypoints[flow_xypoint] ; - flow_xypoint := 3 ; - fi ; - endgroup ; -enddef ; - -vardef flow_smooth_connection(expr a,b) = - if ypart a = ypart b : - a shifted ( if xpart a >= xpart b : - fi (flow_connection_smooth_size/flow_grid_width ),0) - else : - a shifted (0,if ypart a >= ypart b : - fi (flow_connection_smooth_size/flow_grid_height) ) - fi -enddef ; - -vardef flow_trim_points = - begingroup - save p, a, b, d, i ; numeric a, b ; path p ; pair d ; - p := for i=1 upto flow_xypoint-1 : flow_xypoints[i]-- endfor flow_xypoints[flow_xypoint] ; - if flow_touchshape : - a := flow_shape_line_width/flow_grid_width ; - b := flow_shape_line_width/flow_grid_height ; - else : - a := epsilon ; - b := epsilon ; - fi ; - d := direction infinity of p ; - flow_xypoints[flow_xypoint] := flow_xypoints[flow_xypoint] shifted - if xpart d < 0 : (+a,0) ; - elseif xpart d > 0 : (-a,0) ; - elseif ypart d < 0 : (0,+b) ; - elseif ypart d > 0 : (0,-b) ; - else : origin ; - fi ; - d := direction 0 of p ; - flow_xypoints[1] := flow_xypoints[1] shifted - if xpart d < 0 : (-a,0) ; - elseif xpart d > 0 : (+a,0) ; - elseif ypart d < 0 : (0,-b) ; - elseif ypart d > 0 : (0,+b) ; - else : origin ; - fi ; - endgroup -enddef ; - -vardef flow_trim_points = enddef ; - -vardef flow_connection_path = - if flow_reverse_connection : reverse fi (flow_xypoints[1] -- - for i=2 upto flow_xypoint-1 : - if flow_smooth : - flow_smooth_connection(flow_xypoints[i],flow_xypoints[i-1]) .. - controls flow_xypoints[i] and flow_xypoints[i] .. - flow_smooth_connection(flow_xypoints[i],flow_xypoints[i+1]) -- - else : - flow_xypoints[i] -- - fi - endfor - flow_xypoints[flow_xypoint]) -enddef ; - -def flow_draw_connection = - if flow_xypoint > 0 : - flow_collapse_points ; - flow_trim_points ; - flow_cpath := flow_cpath + 1 ; - flow_cpaths[flow_cpath] := flow_connection_path flow_scaled_to_grid ; - flow_cline[flow_cpath] := flow_connection_line_width ; - flow_ccolor[flow_cpath] := flow_connection_line_color ; - flow_carrow[flow_cpath] := flow_arrowtip ; - flow_cdash[flow_cpath] := flow_dashline ; - flow_ccross[flow_cpath] := flow_showcrossing ; - else : - message("no connection defined") ; - fi ; - flow_reverse_connection := false ; -enddef ; - -def flow_flush_connections = % protect locals - begingroup ; - save ip, crossing, cp ; numeric ip ; boolean crossing ; path cp ; - ahlength := flow_connection_arrow_size ; - flow_dash_pattern := dashpattern(on flow_connection_dash_size off flow_connection_dash_size) ; - for i=1 upto flow_cpath : - if flow_ccross[i] : - crossing := false ; - for j=1 upto i : - if not (point infinity of flow_cpaths[i] = point infinity of flow_cpaths[j]) : - ip := flow_cpaths[i] intersection_point flow_cpaths[j] ; - if intersection_found : crossing := true fi ; - fi ; - endfor ; - if crossing : - pickup pencircle scaled 2flow_cline[i] ; - cp := flow_cpaths[i] ; - cp := cp cutbefore point .05 length cp of cp ; - cp := cp cutafter point .95 length cp of cp ; - draw cp withcolor flow_chart_background_color ; - fi ; - fi ; - pickup pencircle scaled flow_cline[i] ; - if flow_carrow[i] : - if flow_cdash[i] : - drawarrow flow_cpaths[i] withcolor flow_ccolor[i] dashed flow_dash_pattern ; - else : - drawarrow flow_cpaths[i] withcolor flow_ccolor[i] ; - fi ; - else : - if flow_cdash[i] : - draw flow_cpaths[i] withcolor flow_ccolor[i] dashed flow_dash_pattern ; - else : - draw flow_cpaths[i] withcolor flow_ccolor[i] ; - fi ; - fi ; - flow_draw_midpoint(i) ; - endfor ; - endgroup ; -enddef ; - -def flow_draw_midpoint (expr n) = - begingroup - save p ; pair p ; - p := point .5*length(flow_cpaths[n]) of flow_cpaths[n]; - pickup pencircle scaled 2flow_cline[n] ; - if flow_show_mid_points : - drawdot p withcolor .7white ; - fi ; - endgroup ; -enddef ; - -def flow_flush_picture(expr x, yy) = - begingroup ; save y ; numeric y ; - y := flow_y_pos(yy) ; - if known flow_xytext[x][y] : - begingroup ; - % flow_xypath[x][y] - save p, offset ; path p ; pair offset ; - offset := flow_xy_offset((x+0.5)*flow_grid_width,(flow_max_y-y+1.5)*flow_grid_height) ; - offset := offset shifted (-flow_xyline[x][y]/4,-flow_xyline[x][y]/4) ; % terrible hack (some compensation) - p := fullsquare - xscaled flow_grid_width - yscaled flow_grid_height - shifted offset ; - if known flow_xytext[x][y]: - draw flow_xytext[x][y] shifted offset ; - fi ; - if known flow_xylabel_t[x][y] : - label.urt(flow_xylabel_t[x][y],0.5[ulcorner p,urcorner p]) ; - fi ; - if known flow_xylabel_b[x][y] : - label.lrt(flow_xylabel_b[x][y],0.5[llcorner p,lrcorner p]) ; - fi ; - if known flow_xylabel_l[x][y] : - label.ulft(flow_xylabel_l[x][y],0.5[ulcorner p,llcorner p]) ; - fi ; - if known flow_xylabel_r[x][y] : - label.urt (flow_xylabel_r[x][y],0.5[urcorner p,lrcorner p]) ; - fi ; - if known flow_xyexit_t[x][y] : - label.top(flow_xyexit_t[x][y],0.5[ulcorner p,urcorner p] shifted (0, flow_grid_height/2)) ; - fi ; - if known flow_xyexit_b[x][y] : - label.bot(flow_xyexit_b[x][y],0.5[llcorner p,lrcorner p] shifted (0,-flow_grid_height/2)) ; - fi ; - if known flow_xyexit_l[x][y] : - label.lft(flow_xyexit_l[x][y],0.5[ulcorner p,llcorner p] shifted (-flow_grid_width/2,0)) ; - fi ; - if known flow_xyexit_r[x][y] : - label.rt (flow_xyexit_r[x][y],0.5[urcorner p,lrcorner p] shifted ( flow_grid_width/2,0)) ; - fi ; - endgroup ; - fi ; - endgroup ; -enddef ; - -def flow_chart_draw_text(expr x, y, p) = - flow_xytext[x][y] := p ; -enddef ; - -def flow_chart_draw_label_t(expr x, y, p) = flow_xylabel_t[x][y] := p ; enddef ; -def flow_chart_draw_label_b(expr x, y, p) = flow_xylabel_b[x][y] := p ; enddef ; -def flow_chart_draw_label_l(expr x, y, p) = flow_xylabel_l[x][y] := p ; enddef ; -def flow_chart_draw_label_r(expr x, y, p) = flow_xylabel_r[x][y] := p ; enddef ; - -def flow_chart_draw_exit_t (expr x, y, p) = flow_xyexit_t [x][y] := p ; enddef ; -def flow_chart_draw_exit_b (expr x, y, p) = flow_xyexit_b [x][y] := p ; enddef ; -def flow_chart_draw_exit_l (expr x, y, p) = flow_xyexit_l [x][y] := p ; enddef ; -def flow_chart_draw_exit_r (expr x, y, p) = flow_xyexit_r [x][y] := p ; enddef ; - -boolean flow_reverse_connection ; flow_reverse_connection := false ; - -vardef flow_up_on_grid (expr n) = - (xpart flow_xypoints[n],(ypart flow_xypoints[n]+1) div 1) -enddef ; - -vardef flow_down_on_grid (expr n) = - (xpart flow_xypoints[n],(ypart flow_xypoints[n]) div 1) -enddef ; - -vardef flow_left_on_grid (expr n) = - ((xpart flow_xypoints[n]) div 1, ypart flow_xypoints[n]) -enddef ; - -vardef flow_right_on_grid (expr n) = - ((xpart flow_xypoints[n]+1) div 1, ypart flow_xypoints[n]) -enddef ; - -vardef flow_x_on_grid (expr n, xfrom, xto, zfrom) = - if (xfrom = xto) and not (zfrom = 0) : - if (zfrom=1) : flow_right_on_grid(2) else : flow_left_on_grid(2) fi - elseif xpart flow_xypoints[1] < xpart flow_xypoints[6] : - flow_right_on_grid(n) - else : - flow_left_on_grid(n) - fi -enddef ; - -vardef flow_y_on_grid (expr n, yfrom, yto, zfrom) = - if (yfrom = yto) and not (zfrom = 0) : - if (zfrom = 1) : flow_up_on_grid(2) else : flow_down_on_grid(2) fi - elseif ypart flow_xypoints[1] < ypart flow_xypoints[6] : - flow_up_on_grid(n) - else : - flow_down_on_grid(n) - fi -enddef ; - -vardef flow_xy_on_grid (expr n, m) = - (xpart flow_xypoints[n], ypart flow_xypoints[m]) -enddef ; - -vardef flow_down_to_grid (expr a,b) = - (xpart flow_xypoints[a], ypart flow_xypoints[if ypart flow_xypoints[a]ypart flow_xypoints[b] : a else : b fi]) -enddef ; - -vardef flow_left_to_grid (expr a,b) = - (xpart flow_xypoints[if xpart flow_xypoints[a]xpart flow_xypoints[b] : a else : b fi], ypart flow_xypoints[a]) -enddef ; - -vardef flow_valid_connection (expr xfrom, yfrom, xto, yto) = - begingroup ; - save ok, vc, pp ; boolean ok ; pair vc ; path pp ; - save flow_xyfirst, flow_xylast ; pair flow_xyfirst, flow_xylast ; - % check for slanted lines - ok := true ; - for i=1 upto flow_xypoint-1 : - if not ((xpart flow_xypoints[i]=xpart flow_xypoints[i+1]) or (ypart flow_xypoints[i]=ypart flow_xypoints[i+1])) : - ok := false ; - fi ; - endfor ; - if not ok : - % message("slanted"); - false - elseif flow_forcevalid : - % message("force"); - true - elseif (xfrom=xto) and (yfrom=yto) : - % message("self"); - false - else : - % check for crossing shapes - flow_xyfirst := flow_xypoints[1] ; - flow_xylast := flow_xypoints[flow_xypoint] ; - flow_trim_points ; - pp := for i=1 upto flow_xypoint-1 : flow_xypoints[i]-- endfor flow_xypoints[flow_xypoint] ; - flow_xypoints[1] := flow_xyfirst ; - flow_xypoints[flow_xypoint] := flow_xylast ; - for i=1 upto flow_max_x : - for j=1 upto flow_max_y : % was bug: xfrom,yto - if not ( ( (i,j)=(xfrom,yfrom) ) or ( (i,j)=(xto,yto) ) ) : - if not flow_xyfree[i][j] : - vc := pp intersection_point flow_xypath[i][j] ; - if intersection_found : - ok := false - fi ; - fi ; - fi ; - endfor ; - endfor ; - % if not ok: message("crossing") ; fi ; - ok - fi - endgroup -enddef ; - -def flow_connect_top_bottom (expr xfrom, yyfrom, zfrom) (expr xto, yyto, zto) = - yfrom := flow_y_pos(yyfrom) ; - yto := flow_y_pos(yyto) ; - if flow_points_initialized(xfrom,yfrom,xto,yto,6) : - flow_xypoints[1] := flow_xy_top(xfrom,yfrom,zfrom,true) ; - flow_xypoints[6] := flow_xy_bottom(xto,yto,zto,true) ; - flow_xypoints[2] := flow_up_on_grid(1) ; - flow_xypoints[5] := flow_down_on_grid(6) ; - flow_xypoints[3] := flow_up_to_grid(2,5) ; - flow_xypoints[4] := flow_up_to_grid(2,5) ; - if not flow_valid_connection(xfrom,yfrom,xto,yto) : - flow_xypoints[3] := flow_x_on_grid(2,xfrom,xto,zfrom) ; - flow_xypoints[4] := flow_xy_on_grid(3,5) ; - fi ; - %%%% begin experiment - flow_xypoints[3] := flow_xypoints[3] shifted (flow_dsp_x,0) ; - flow_xypoints[4] := flow_xypoints[4] shifted (flow_dsp_x,0) ; - if flow_dsp_y>0 : - flow_xypoints[2] := flow_xypoints[2] shifted (0,flow_dsp_y) ; - flow_xypoints[3] := flow_xypoints[3] shifted (0,flow_dsp_y) ; - elseif flow_dsp_y<0 : - flow_xypoints[4] := flow_xypoints[4] shifted (0,flow_dsp_y) ; - flow_xypoints[5] := flow_xypoints[5] shifted (0,flow_dsp_y) ; - fi - %%%% end experiment - flow_draw_connection ; - fi ; -enddef ; - -def flow_connect_left_right (expr xfrom,yyfrom,zfrom) (expr xto,yyto,zto) = - yfrom := flow_y_pos(yyfrom) ; - yto := flow_y_pos(yyto) ; - if flow_points_initialized(xfrom,yfrom,xto,yto,6) : - flow_xypoints[1] := flow_xy_left(xfrom,yfrom,zfrom,true) ; - flow_xypoints[6] := flow_xy_right(xto,yto,zto,true) ; - flow_xypoints[2] := flow_left_on_grid(1) ; - flow_xypoints[5] := flow_right_on_grid(6) ; - flow_xypoints[3] := flow_left_to_grid(2,5) ; - flow_xypoints[4] := flow_left_to_grid(2,5) ; - if not flow_valid_connection(xfrom,yfrom,xto,yto) : - flow_xypoints[3] := flow_y_on_grid(2,yfrom,yto,zfrom) ; - flow_xypoints[4] := flow_xy_on_grid(5,3) ; - fi ; - flow_draw_connection ; - fi ; -enddef ; - -def flow_connect_left_top (expr xfrom,yyfrom,zfrom) (expr xto,yyto,zto) = - yfrom := flow_y_pos(yyfrom) ; - yto := flow_y_pos(yyto) ; - if flow_points_initialized(xfrom,yfrom,xto,yto,5) : - flow_xypoints[1] := flow_xy_left(xfrom,yfrom,zfrom,true) ; - flow_xypoints[5] := flow_xy_top(xto,yto,zto,true) ; - flow_xypoints[2] := flow_left_on_grid(1) ; - flow_xypoints[4] := flow_up_on_grid(5) ; - flow_xypoints[3] := flow_left_to_grid(2,5) ; - if not flow_valid_connection(xfrom,yfrom,xto,yto) : - flow_xypoints[3] := flow_xy_on_grid(2,4) ; - fi ; - flow_draw_connection ; - fi ; -enddef ; - -def flow_connect_left_bottom (expr xfrom,yyfrom,zfrom) (expr xto,yyto,zto) = - yfrom := flow_y_pos(yyfrom) ; - yto := flow_y_pos(yyto) ; - if flow_points_initialized(xfrom,yfrom,xto,yto,5) : - flow_xypoints[1] := flow_xy_left(xfrom,yfrom,zfrom,true) ; - flow_xypoints[5] := flow_xy_bottom(xto,yto,zto,true) ; - flow_xypoints[2] := flow_left_on_grid(1) ; - flow_xypoints[4] := flow_down_on_grid(5) ; - flow_xypoints[3] := flow_left_to_grid(2,5) ; - if not flow_valid_connection(xfrom,yfrom,xto,yto) : - flow_xypoints[3] := flow_xy_on_grid(2,4) ; - fi ; - flow_draw_connection ; - fi ; -enddef ; - -def flow_connect_right_top (expr xfrom,yyfrom,zfrom) (expr xto,yyto,zto) = - yfrom := flow_y_pos(yyfrom) ; - yto := flow_y_pos(yyto) ; - if flow_points_initialized(xfrom,yfrom,xto,yto,5) : - flow_xypoints[1] := flow_xy_right(xfrom,yfrom,zfrom,true) ; - flow_xypoints[5] := flow_xy_top(xto,yto,zto,true) ; - flow_xypoints[2] := flow_right_on_grid(1) ; - flow_xypoints[4] := flow_up_on_grid(5) ; - flow_xypoints[3] := flow_right_to_grid(2,5) ; - if not flow_valid_connection(xfrom,yfrom,xto,yto) : - flow_xypoints[3] := flow_xy_on_grid(2,4) ; - fi ; - flow_draw_connection ; - fi ; -enddef ; - -def flow_connect_right_bottom (expr xfrom,yyfrom,zfrom) (expr xto,yyto,zto) = - yfrom := flow_y_pos(yyfrom) ; - yto := flow_y_pos(yyto) ; - if flow_points_initialized(xfrom,yfrom,xto,yto,5) : - flow_xypoints[1] := flow_xy_right(xfrom,yfrom,zfrom,true) ; - flow_xypoints[5] := flow_xy_bottom(xto,yto,zto,true) ; - flow_xypoints[2] := flow_right_on_grid(1) ; - flow_xypoints[4] := flow_down_on_grid(5) ; - flow_xypoints[3] := flow_right_to_grid(2,5) ; - if not flow_valid_connection(xfrom,yfrom,xto,yto) : - flow_xypoints[3] := flow_xy_on_grid(2,4) ; - fi ; - %%%% begin experiment - flow_xypoints[2] := flow_xypoints[2] shifted (flow_dsp_x,0) ; - flow_xypoints[3] := flow_xypoints[3] shifted (flow_dsp_x,0) ; - if flow_dsp_y>0 : - flow_xypoints[3] := flow_xypoints[3] shifted (0,-flow_dsp_y) ; - flow_xypoints[4] := flow_xypoints[4] shifted (0,-flow_dsp_y) ; - elseif flow_dsp_y<0 : - flow_xypoints[3] := flow_xypoints[3] shifted (0,flow_dsp_y) ; - flow_xypoints[4] := flow_xypoints[4] shifted (0,flow_dsp_y) ; - fi - %%%% end experiment - flow_draw_connection ; - fi ; -enddef ; - -def flow_connect_left_left (expr xfrom,yyfrom,zfrom) (expr xto,yyto,zto) = - yfrom := flow_y_pos(yyfrom) ; - yto := flow_y_pos(yyto) ; - if flow_points_initialized(xfrom,yfrom,xto,yto,6) : - flow_xypoints[1] := flow_xy_left(xfrom,yfrom,zfrom,true) ; - flow_xypoints[6] := flow_xy_left(xto,yto,zto,true) ; - flow_xypoints[2] := flow_left_on_grid(1) ; - flow_xypoints[5] := flow_left_on_grid(6) ; - flow_xypoints[3] := flow_left_to_grid(2,5) ; - flow_xypoints[4] := flow_left_to_grid(5,2) ; - if not flow_valid_connection(xfrom,yfrom,xto,yto) : - flow_xypoints[3] := flow_y_on_grid(2,yfrom,yto,zfrom) ; - flow_xypoints[4] := flow_xy_on_grid(5,3) ; - fi ; - flow_draw_connection ; - fi ; -enddef ; - -def flow_connect_right_right (expr xfrom,yyfrom,zfrom) (expr xto,yyto,zto) = - yfrom := flow_y_pos(yyfrom) ; - yto := flow_y_pos(yyto) ; - if flow_points_initialized(xfrom,yfrom,xto,yto,6) : - flow_xypoints[1] := flow_xy_right(xfrom,yfrom,zfrom,true) ; - flow_xypoints[6] := flow_xy_right(xto,yto,zto,true) ; - flow_xypoints[2] := flow_right_on_grid(1) ; - flow_xypoints[5] := flow_right_on_grid(6) ; - flow_xypoints[3] := flow_right_to_grid(2,5) ; - flow_xypoints[4] := flow_right_to_grid(5,2) ; - if not flow_valid_connection(xfrom,yfrom,xto,yto) : - flow_xypoints[3] := flow_y_on_grid(2,yfrom,yto,zfrom) ; - flow_xypoints[4] := flow_xy_on_grid(5,3) ; - fi ; - flow_draw_connection ; - fi ; -enddef ; - -def flow_connect_top_top (expr xfrom,yyfrom,zfrom) (expr xto,yyto,zto) = - yfrom := flow_y_pos(yyfrom) ; - yto := flow_y_pos(yyto) ; - if flow_points_initialized(xfrom,yfrom,xto,yto,6) : - flow_xypoints[1] := flow_xy_top(xfrom,yfrom,zfrom,true) ; - flow_xypoints[6] := flow_xy_top(xto,yto,zto,true) ; - flow_xypoints[2] := flow_up_on_grid(1) ; - flow_xypoints[5] := flow_up_on_grid(6) ; - flow_xypoints[3] := flow_up_to_grid(2,5) ; - flow_xypoints[4] := flow_up_to_grid(5,2) ; - if not flow_valid_connection(xfrom,yfrom,xto,yto) : - flow_xypoints[3] := flow_x_on_grid(2,xfrom,xto,zfrom) ; - flow_xypoints[4] := flow_xy_on_grid(3,5) ; - fi ; - flow_draw_connection ; - fi ; -enddef ; - -def flow_connect_bottom_bottom (expr xfrom,yyfrom,zfrom) (expr xto,yyto,zto) = - yfrom := flow_y_pos(yyfrom) ; - yto := flow_y_pos(yyto) ; - if flow_points_initialized(xfrom,yfrom,xto,yto,6) : - flow_xypoints[1] := flow_xy_bottom(xfrom,yfrom,zfrom,true) ; - flow_xypoints[6] := flow_xy_bottom(xto,yto,zto,true) ; - flow_xypoints[2] := flow_down_on_grid(1) ; - flow_xypoints[5] := flow_down_on_grid(6) ; - flow_xypoints[3] := flow_down_to_grid(2,5) ; - flow_xypoints[4] := flow_down_to_grid(5,2) ; - if not flow_valid_connection(xfrom,yfrom,xto,yto) : - flow_xypoints[3] := flow_x_on_grid(2,xfrom,xto,zfrom) ; - flow_xypoints[4] := flow_xy_on_grid(3,5) ; - fi ; - %%%% begin experiment - flow_xypoints[3] := flow_xypoints[3] shifted (flow_dsp_x,0) ; - flow_xypoints[4] := flow_xypoints[4] shifted (flow_dsp_x,0) ; - if flow_dsp_y<0 : - flow_xypoints[2] := flow_xypoints[2] shifted (0,-flow_dsp_y) ; - flow_xypoints[3] := flow_xypoints[3] shifted (0,-flow_dsp_y) ; - elseif flow_dsp_y>0 : - flow_xypoints[4] := flow_xypoints[4] shifted (0,flow_dsp_y) ; - flow_xypoints[5] := flow_xypoints[5] shifted (0,flow_dsp_y) ; - fi - %%%% end experiment - flow_draw_connection ; - fi ; -enddef ; - -def flow_connect_bottom_top (expr xfrom,yfrom,zfrom) (expr xto,yto,zto) = - flow_reverse_connection := true ; - flow_connect_top_bottom (xto,yto,zto) (xfrom,yfrom,zfrom) ; -enddef ; - -def flow_connect_right_left (expr xfrom,yfrom,zfrom) (expr xto,yto,zto) = - flow_reverse_connection := true ; - flow_connect_left_right (xto,yto,zto) (xfrom,yfrom,zfrom) ; -enddef ; - -def flow_connect_top_left (expr xfrom,yfrom,zfrom) (expr xto,yto,zto) = - flow_reverse_connection := true ; - flow_connect_left_top(xto,yto,zto) (xfrom,yfrom,zfrom) ; -enddef ; - -def flow_connect_bottom_left (expr xfrom,yfrom,zfrom) (expr xto,yto,zto) = - flow_reverse_connection := true ; - flow_connect_left_bottom (xto,yto,zto) (xfrom,yfrom,zfrom) ; -enddef ; - -def flow_connect_top_right (expr xfrom,yfrom,zfrom) (expr xto,yto,zto) = - flow_reverse_connection := true ; - flow_connect_right_top (xto,yto,zto) (xfrom,yfrom,zfrom) ; -enddef ; - -def flow_connect_bottom_right (expr xfrom,yfrom,zfrom) (expr xto,yto,zto) = - flow_reverse_connection := true ; - flow_connect_right_bottom (xto,yto,zto) (xfrom,yfrom,zfrom) ; -enddef ; - -def flow_draw_test_shape(expr x, y) = - flow_draw_shape(x,y,fullcircle, .7, .7) ; -enddef ; - -def flow_draw_test_shapes = - for i=1 upto flow_max_x : - for j=1 upto flow_max_y : - flow_draw_test_shape(i,j) ; - endfor ; - endfor ; -enddef; - -def flow_draw_test_area = - pickup pencircle scaled .5flow_shape_line_width ; - draw (unitsquare xscaled flow_max_x yscaled flow_max_y shifted (1,1)) flow_scaled_to_grid withcolor blue ; -enddef ; - -def flow_show_connection(expr n, m) = - - flow_begin_chart(100+n,6,6) ; - - flow_draw_test_area ; - - flow_smooth := true ; - flow_arrowtip := true ; - flow_dashline := true ; - - flow_draw_test_shape(2,2) ; flow_draw_test_shape(4,5) ; - flow_draw_test_shape(3,3) ; flow_draw_test_shape(5,1) ; - flow_draw_test_shape(2,5) ; flow_draw_test_shape(1,3) ; - flow_draw_test_shape(6,2) ; flow_draw_test_shape(4,6) ; - - if (m=1) : - flow_connect_top_bottom (2,2,0) (4,5,0) ; - flow_connect_top_bottom (3,3,0) (5,1,0) ; - flow_connect_top_bottom (2,5,0) (1,3,0) ; - flow_connect_top_bottom (6,2,0) (4,6,0) ; - elseif (m=2) : - flow_connect_top_top (2,2,0) (4,5,0) ; - flow_connect_top_top (3,3,0) (5,1,0) ; - flow_connect_top_top (2,5,0) (1,3,0) ; - flow_connect_top_top (6,2,0) (4,6,0) ; - elseif (m=3) : - flow_connect_bottom_bottom (2,2,0) (4,5,0) ; - flow_connect_bottom_bottom (3,3,0) (5,1,0) ; - flow_connect_bottom_bottom (2,5,0) (1,3,0) ; - flow_connect_bottom_bottom (6,2,0) (4,6,0) ; - elseif (m=4) : - flow_connect_left_right (2,2,0) (4,5,0) ; - flow_connect_left_right (3,3,0) (5,1,0) ; - flow_connect_left_right (2,5,0) (1,3,0) ; - flow_connect_left_right (6,2,0) (4,6,0) ; - elseif (m=5) : - flow_connect_left_left (2,2,0) (4,5,0) ; - flow_connect_left_left (3,3,0) (5,1,0) ; - flow_connect_left_left (2,5,0) (1,3,0) ; - flow_connect_left_left (6,2,0) (4,6,0) ; - elseif (m=6) : - flow_connect_right_right (2,2,0) (4,5,0) ; - flow_connect_right_right (3,3,0) (5,1,0) ; - flow_connect_right_right (2,5,0) (1,3,0) ; - flow_connect_right_right (6,2,0) (4,6,0) ; - elseif (m=7) : - flow_connect_left_top (2,2,0) (4,5,0) ; - flow_connect_left_top (3,3,0) (5,1,0) ; - flow_connect_left_top (2,5,0) (1,3,0) ; - flow_connect_left_top (6,2,0) (4,6,0) ; - elseif (m=8) : - flow_connect_left_bottom (2,2,0) (4,5,0) ; - flow_connect_left_bottom (3,3,0) (5,1,0) ; - flow_connect_left_bottom (2,5,0) (1,3,0) ; - flow_connect_left_bottom (6,2,0) (4,6,0) ; - elseif (m=9) : - flow_connect_right_top (2,2,0) (4,5,0) ; - flow_connect_right_top (3,3,0) (5,1,0) ; - flow_connect_right_top (2,5,0) (1,3,0) ; - flow_connect_right_top (6,2,0) (4,6,0) ; - else : - flow_connect_right_bottom (2,2,0) (4,5,0) ; - flow_connect_right_bottom (3,3,0) (5,1,0) ; - flow_connect_right_bottom (2,5,0) (1,3,0) ; - flow_connect_right_bottom (6,2,0) (4,6,0) ; - fi ; - - flow_end_chart ; - -enddef ; - -def flow_show_connections = - for f=1 upto 10 : - flow_show_connection(f,f) ; - endfor ; -enddef ; - -%D charts - -def flow_clip_chart(expr minx, miny, maxx, maxy) = - flow_cmin_x := minx ; - flow_cmax_x := maxx ; - flow_cmin_y := miny ; - flow_cmax_y := maxy ; -enddef ; - -def flow_begin_chart(expr n, maxx, maxy) = - flow_new_chart ; - flow_chart_figure := n ; - flow_chart_scale := 1 ; - if flow_chart_figure>0: - beginfig(flow_chart_figure) ; - fi ; - flow_initialize_grid (maxx, maxy) ; - bboxmargin := 0 ; - flow_cmin_x := 1 ; - flow_cmax_x := maxx ; - flow_cmin_y := 1 ; - flow_cmax_y := maxy ; -enddef ; - -def flow_end_chart = - begingroup ; - save p ; path p ; - flow_flush_shapes ; - flow_flush_connections ; - flow_flush_pictures ; - flow_cmin_x := flow_cmin_x ; - flow_cmax_x := flow_cmin_x+flow_cmax_x ; - flow_cmin_y := flow_cmin_y-1 ; - flow_cmax_y := flow_cmin_y+flow_cmax_y ; - if flow_reverse_y : - flow_cmin_y := flow_y_pos(flow_cmin_y) ; - flow_cmax_y := flow_y_pos(flow_cmax_y) ; - fi ; - p := (((flow_cmin_x,flow_cmin_y)--(flow_cmax_x,flow_cmin_y)-- - (flow_cmax_x,flow_cmax_y)--(flow_cmin_x,flow_cmax_y)--cycle)) - flow_scaled_to_grid ; - %draw p withcolor red ; - p := p enlarged flow_chart_offset ; - clip currentpicture to p ; - setbounds currentpicture to p ; - endgroup ; - currentpicture := currentpicture scaled flow_chart_scale ; - if flow_chart_figure>0: - endfig ; - fi ; -enddef ; - -def flow_new_shape(expr x, y, n) = - if known n : - if (x>0) and (x<=flow_max_x) and (y>0) and (y<=flow_max_y) : - flow_draw_shape(x,y,some_shape_path(n), flow_shape_width/flow_grid_width, flow_shape_height/flow_grid_height) ; - else : - message ("shape outside grid ignored") ; - fi ; - else : - message ("shape not known" ) ; - fi ; -enddef ; - -def flow_begin_sub_chart = - begingroup ; - save flow_shape_line_width, flow_connection_line_width ; - save flow_shape_line_color, flow_shape_fill_color, flow_connection_line_color ; - color flow_shape_line_color, flow_shape_fill_color, flow_connection_line_color ; - save flow_smooth, flow_arrowtip, flow_dashline, flow_peepshape ; - boolean flow_smooth, flow_arrowtip, flow_dashline, flow_peepshape ; -enddef ; - -def flow_end_sub_chart = - endgroup ; -enddef ; - diff --git a/metapost/context/base/mp-step.mp b/metapost/context/base/mp-step.mp deleted file mode 100644 index d602f7014..000000000 --- a/metapost/context/base/mp-step.mp +++ /dev/null @@ -1,320 +0,0 @@ -%D \module -%D [ file=mp-step.mp, -%D version=2001.05.22, -%D title=\CONTEXT\ \METAPOST\ graphics, -%D subtitle=steps, -%D author=Hans Hagen, -%D date=\currentdate, -%D copyright={PRAGMA / Hans Hagen \& Ton Otten}] -%C -%C This module is part of the \CONTEXT\ macro||package and is -%C therefore copyrighted by \PRAGMA. See licen-en.pdf for -%C details. - -if unknown context_tool : input mp-tool ; fi ; -if known context_step : endinput ; fi ; - -boolean context_step ; context_step := true ; - -%D In the associated \TEX\ module \type {m-steps}, we describe -%D three methods. The first method uses a different kind of -%D code than the other two. The method we decided to use, -%D is based on positional information (paths) provided by -%D \CONTEXT. - -def initialize_step_variables = - save line_method, line_h_offset, line_v_offset ; - numeric line_method ; line_method := 1 ; - numeric line_h_offset ; line_h_offset := 3pt ; - numeric line_v_offset ; line_v_offset := 3pt ; -enddef ; - -def begin_step_chart = - initialize_step_variables ; - save steps, texts, t, b, tb, nofcells ; - picture cells[][], texts[][][], lines[][][] ; - numeric t, b ; t := 1 ; b := 2 ; - numeric nofcells ; nofcells := 0 ; -enddef ; - -def analyze_step_chart = - numeric n[], l[][], r[][] ; pair p[] ; - n[t] := n[b] := 0 ; numeric tb ; - for i=1 upto nofcells : for nn = t, b : - if bbwidth(cells[nn][i])>0 : n[nn] := n[nn] + 1 ; fi ; - l[t][i] := r[t][i] := l[b][i] := r[b][i] := 0 ; - endfor ; endfor ; - % count left and right points - for i=1 upto nofcells-1 : for j=i upto nofcells-1 : for nn = t, b : - if bbwidth(texts[nn][i][j])>0 : - l[nn][i] := l[nn][i] + 1 ; - r[nn][j+1] := r[nn][j+1] + 1 ; - fi ; - endfor ; endfor ; endfor ; - % calculate left and right points - vardef do (expr nn, mm, ii, ss) = - if (l[nn][ii] + r[nn][ii]) > 1 : ss else : .5 fi - [ ulcorner cells[mm][ii], urcorner cells[mm][ii] ] - enddef ; - % combined rows - tb := if n[t]>0 : t else : b fi ; -enddef ; - -vardef get_step_chart_top_line (expr i, j) = - if bbwidth(cells[tb][i])>0 : - if bbwidth(texts[t][i][j])>0 : - if bbwidth(cells[tb][j+1])>0 : - p[1] := top do(t, tb, i, .6) ; - p[3] := top do(t, tb, j+1, .4) ; - p[2] := .5[p[1],p[3]] ; - if line_method = 1 : - p[2] := p[2] shifted (0, ypart - (llcorner texts[t][i][j] - ulcorner cells[tb][j+1])) ; - elseif line_method = 2 : - p[2] := center texts[t][i][j] ; - else : - % nothing - fi ; - p[1] := p[1] shifted (0,+line_v_offset) ; - p[2] := p[2] shifted (0,-line_v_offset) ; - p[3] := p[3] shifted (0,+line_v_offset) ; - (p[1] {up} ... p[2] ... {down} p[3]) - else : - origin - fi - else : - origin - fi - else : - origin - fi -enddef ; - -vardef get_step_chart_bot_line (expr i, j) = - if bbwidth(cells[b][i])>0 : - if bbwidth(texts[b][i][j])>0 : - if bbwidth(cells[b][j+1])>0 : - p[1] := (bot do(b, b, i, .6)) shifted (0,-bbheight(cells[b][i])) ; - p[3] := (bot do(b, b, j+1, .4)) shifted (0,-bbheight(cells[b][j+1])) ; - p[2] := .5[p[1],p[3]] ; - if line_method = 1 : - p[2] := p[2] shifted (0, -ypart - (llcorner cells[b][j+1] - ulcorner texts[b][i][j])) ; - elseif line_method = 2 : - p[2] := center texts[b][i][j] ; - fi ; - p[1] := p[1] shifted (0,-line_v_offset) ; - p[2] := p[2] shifted (0,+line_v_offset) ; - p[3] := p[3] shifted (0,-line_v_offset) ; - (p[1] {down} ... p[2] ... {up} p[3]) - else : - origin - fi - else : - origin - fi - else : - origin - fi -enddef ; - -def end_step_chart = - for i=1 upto nofcells : for nn = t, b : - if bbwidth(cells[nn][i]) >0 : draw cells[nn][i] ; fi ; - endfor ; endfor ; - for i=1 upto nofcells : for j=i upto nofcells : for nn = t, b : - if known lines[nn][i][j] : - if bbwidth(lines[nn][i][j])>0 : draw lines[nn][i][j] ; fi ; - fi ; - endfor ; endfor ; endfor ; - for i=1 upto nofcells : for j=i upto nofcells : for nn = t, b : - if bbwidth(texts[nn][i][j])>0 : draw texts[nn][i][j] ; fi ; - endfor ; endfor ; endfor ; -enddef ; - -%D Step tables. - -def begin_step_table = - initialize_step_variables ; - picture cells[], texts[], lines[] ; - numeric nofcells ; nofcells := 0 ; -enddef ; - -def end_step_table = - for i=1 upto nofcells : if known cells[i] : if bbwidth(cells[i])>0 : - draw cells[i] ; - fi ; fi ; endfor ; - for i=1 upto nofcells : if known lines[i] : if bbwidth(lines[i])>0 : - draw lines[i] ; - fi ; fi ; endfor ; - for i=1 upto nofcells : if known texts[i] : if bbwidth(texts[i])>0 : - draw texts[i] ; - fi ; fi ; endfor ; -enddef ; - -vardef get_step_table_line (expr i) = - pair prev, self, next ; - if known texts[i] : - self := lft .5[llcorner texts[i], ulcorner texts[i] ] ; - prev := rt if known texts[i-1] : .3 else : .5 fi [lrcorner cells[i] , urcorner cells[i] ] ; - next := rt if known texts[i+1] : .7 else : .5 fi [lrcorner cells[i+1], urcorner cells[i+1]] ; - self := self shifted (-line_h_offset,0) ; - prev := prev shifted (+line_h_offset,0) ; - next := next shifted (+line_h_offset,0) ; - prev {right} ... self ... {left} next - else : - origin - fi -enddef ; - -endinput - -%D The older method let \METAPOST\ do the typesetting. The -%D macros needed for that are included here for educational -%D purposes. -%D -%D \starttypen -%D def initialize_step_variables = -%D save line_color, line_width, arrow_alternative, -%D text_fill_color, text_line_color, text_line_width, text_offset, -%D cell_fill_color, cell_line_color, cell_line_width, cell_offset, -%D line_h_offset, line_v_offset ; -%D color line_color ; line_color := .4white ; -%D numeric line_width ; line_width := 1.5pt ; -%D color text_fill_color ; text_fill_color := white ; -%D color text_line_color ; text_line_color := red ; -%D numeric text_line_width ; text_line_width := 1pt ; -%D numeric text_offset ; text_offset := 2pt ; -%D color cell_fill_color ; cell_fill_color := white ; -%D color cell_line_color ; cell_line_color := blue ; -%D numeric cell_line_width ; cell_line_width := 1pt ; -%D numeric cell_offset ; cell_offset := 2pt ; -%D numeric line_alternative ; line_alternative := 1 ; -%D numeric line_h_offset ; line_h_offset := 3pt ; -%D numeric line_v_offset ; line_v_offset := 3pt ; -%D enddef ; -%D -%D def begin_step_chart = -%D begingroup ; -%D initialize_step_variables ; -%D save steps, texts, t, b ; -%D picture cells[][] ; numeric nofcells ; nofcells := 0 ; -%D picture texts[][][] ; numeric noftexts ; noftexts := 0 ; -%D numeric t, b ; t := 1 ; b := 2 ; -%D enddef ; -%D \stoptypen -%D -%D We use a couple of macros to store the content. In the -%D second (third) alternative we will directly fill the -%D cells. -%D -%D \starttypen -%D def set_step_chart_cells (expr one, two) = -%D nofcells := nofcells + 1 ; noftexts := 0 ; -%D cells[t][nofcells] := textext.rt(one) ; -%D cells[b][nofcells] := textext.rt(two) ; -%D enddef ; -%D -%D def set_step_chart_texts (expr one, two) = -%D noftexts := noftexts + 1 ; -%D texts[t][nofcells][noftexts] := textext.rt(one) ; -%D texts[b][nofcells][noftexts] := textext.rt(two) ; -%D enddef ; -%D \stoptypen -%D -%D If you compare the building macro with the later -%D alternative, you will notice that here we explicitly -%D have to calculate the distances and positions. -%D -%D \starttypen -%D def end_step_chart = -%D numeric dx ; dx := 0 ; path p ; -%D numeric n[] ; n[t] := n[b] := 0 ; -%D numeric stepsvdistance[] ; -%D vardef bbwidth (expr p) = (xpart (lrcorner p - llcorner p)) enddef ; -%D vardef bbheight (expr p) = (ypart (urcorner p - lrcorner p)) enddef ; -%D stepsvdistance[t] := stepsvdistance[b] := 0 ; -%D for i=1 upto nofcells : -%D % find largest bbox -%D p := boundingbox steps -%D [if bbwidth(cells[t][i])>bbwidth(cells[b][i]): t else: b fi][i] ; -%D % assign largest bbox -%D for nn = t, b : -%D if bbwidth(cells[nn][i])>0 : -%D setbounds cells[nn][i] to p enlarged cell_offset ; -%D n[nn] := n[nn] + 1 ; -%D fi ; -%D endfor ; -%D % determine height -%D if n[t]>0 : -%D stepsvdistance[t] := bbheight(cells[t][1]) + intertextdistance ; -%D fi ; -%D % add to row -%D for nn = t, b : -%D cells[nn][i] := cells[nn][i] shifted (dx,stepsvdistance[nn]) ; -%D if bbwidth(cells[nn][i])>0 : -%D dowithpath (boundingbox cells[nn][i], -%D cell_line_width, cell_line_color, cell_background_color) ; -%D fi ; -%D endfor ; -%D % calculate position -%D dx := dx + interstepdistance + bbwidth(cells[b][i]) ; -%D endfor ; -%D boolean stacked ; stacked := false ; -%D numeric l[][], r[][], l[][], r[][] ; -%D pair pa, pb, pc ; path p[] ; -%D for i=1 upto nofcells : -%D l[t][i] := r[t][i] := l[b][i] := r[b][i] := 0 ; -%D endfor ; -%D % count left and right points -%D for i=1 upto nofcells : for j=1 upto nofcells : for nn = t, b : -%D if known texts[nn][i][j] : if bbwidth(texts[nn][i][j])>0 : -%D l[nn][i] := l[nn][i] + 1 ; -%D r[nn][j+i] := r[nn][j+i] + 1 ; -%D stacked := (stacked or (j>1)) ; -%D setbounds texts[nn][i][j] to boundingbox texts[nn][i][j] enlarged cell_offset ; -%D fi fi ; -%D endfor ; endfor ; endfor ; -%D % calculate left and right points -%D vardef do (expr nn, mm, ii, ss) = -%D if (l[nn][ii] > 0) and (r[nn][ii] > 0) : ss else : .5 fi -%D [ ulcorner cells[mm][ii],urcorner cells[mm][ii] ] -%D enddef ; -%D % draw arrow from left to right point -%D def dodo (expr nn, ii, jj, dd) = -%D drawarrow p[nn] -%D withpen pencircle scaled arrow_line_width -%D withcolor arrow_line_color ; -%D transform tr ; tr := identity -%D shifted point .5 along p[nn] -%D shifted -center texts[nn][ii][jj] -%D if not stacked : shifted (0,dd) fi ; -%D dowithpath ((boundingbox texts[nn][ii][jj]) transformed tr, -%D text_line_width, text_line_color, text_fill_color) ; -%D enddef ; -%D % draw top and bottom text boxes -%D for i=1 upto nofcells : for j=1 upto nofcells : -%D pickup pencircle scaled arrow_line_width ; -%D if known texts[t][i][j] : if bbwidth(texts[t][i][j]) > 0 : -%D pa := top do(t, if n[t]>0 : t else : b fi, i, .6) ; -%D pb := top do(t, if n[t]>0 : t else : b fi, j+i, .4) ; -%D pc := .5[pa,pb] shifted (0,+step_arrow_depth) ; -%D p[t] := pa {up} .. if not stacked : pc .. fi {down} pb ; -%D dodo(t, i, j, +intertextdistance) ; -%D fi fi ; -%D if known texts[b][i][j] : if bbwidth(texts[b][i][j]) > 0 : -%D pa := (bot do(b, b, i, .6)) shifted (0,-bbheight(cells[b][i])) ; -%D pb := (bot do(b, b, j+i, .4)) shifted (0,-bbheight(cells[b][j+i])) ; -%D pc := .5[pa,pb] shifted (0,-step_arrow_depth) ; -%D p[b] := pa {down} .. if not stacked : pc .. fi {up} pb ; -%D dodo(b, i, j, -intertextdistance) ; -%D fi fi ; -%D endfor ; endfor ; -%D endgroup ; -%D enddef ; -%D \stoptypen -%D -%D If you compare both methods, you will notice that the -%D first method is the cleanest, but not the most efficient -%D (since it needs \TEX\ runs within \METAPOST\ runs within -%D \TEX\ runs). diff --git a/metapost/context/base/mp-step.mpii b/metapost/context/base/mp-step.mpii new file mode 100644 index 000000000..d602f7014 --- /dev/null +++ b/metapost/context/base/mp-step.mpii @@ -0,0 +1,320 @@ +%D \module +%D [ file=mp-step.mp, +%D version=2001.05.22, +%D title=\CONTEXT\ \METAPOST\ graphics, +%D subtitle=steps, +%D author=Hans Hagen, +%D date=\currentdate, +%D copyright={PRAGMA / Hans Hagen \& Ton Otten}] +%C +%C This module is part of the \CONTEXT\ macro||package and is +%C therefore copyrighted by \PRAGMA. See licen-en.pdf for +%C details. + +if unknown context_tool : input mp-tool ; fi ; +if known context_step : endinput ; fi ; + +boolean context_step ; context_step := true ; + +%D In the associated \TEX\ module \type {m-steps}, we describe +%D three methods. The first method uses a different kind of +%D code than the other two. The method we decided to use, +%D is based on positional information (paths) provided by +%D \CONTEXT. + +def initialize_step_variables = + save line_method, line_h_offset, line_v_offset ; + numeric line_method ; line_method := 1 ; + numeric line_h_offset ; line_h_offset := 3pt ; + numeric line_v_offset ; line_v_offset := 3pt ; +enddef ; + +def begin_step_chart = + initialize_step_variables ; + save steps, texts, t, b, tb, nofcells ; + picture cells[][], texts[][][], lines[][][] ; + numeric t, b ; t := 1 ; b := 2 ; + numeric nofcells ; nofcells := 0 ; +enddef ; + +def analyze_step_chart = + numeric n[], l[][], r[][] ; pair p[] ; + n[t] := n[b] := 0 ; numeric tb ; + for i=1 upto nofcells : for nn = t, b : + if bbwidth(cells[nn][i])>0 : n[nn] := n[nn] + 1 ; fi ; + l[t][i] := r[t][i] := l[b][i] := r[b][i] := 0 ; + endfor ; endfor ; + % count left and right points + for i=1 upto nofcells-1 : for j=i upto nofcells-1 : for nn = t, b : + if bbwidth(texts[nn][i][j])>0 : + l[nn][i] := l[nn][i] + 1 ; + r[nn][j+1] := r[nn][j+1] + 1 ; + fi ; + endfor ; endfor ; endfor ; + % calculate left and right points + vardef do (expr nn, mm, ii, ss) = + if (l[nn][ii] + r[nn][ii]) > 1 : ss else : .5 fi + [ ulcorner cells[mm][ii], urcorner cells[mm][ii] ] + enddef ; + % combined rows + tb := if n[t]>0 : t else : b fi ; +enddef ; + +vardef get_step_chart_top_line (expr i, j) = + if bbwidth(cells[tb][i])>0 : + if bbwidth(texts[t][i][j])>0 : + if bbwidth(cells[tb][j+1])>0 : + p[1] := top do(t, tb, i, .6) ; + p[3] := top do(t, tb, j+1, .4) ; + p[2] := .5[p[1],p[3]] ; + if line_method = 1 : + p[2] := p[2] shifted (0, ypart + (llcorner texts[t][i][j] - ulcorner cells[tb][j+1])) ; + elseif line_method = 2 : + p[2] := center texts[t][i][j] ; + else : + % nothing + fi ; + p[1] := p[1] shifted (0,+line_v_offset) ; + p[2] := p[2] shifted (0,-line_v_offset) ; + p[3] := p[3] shifted (0,+line_v_offset) ; + (p[1] {up} ... p[2] ... {down} p[3]) + else : + origin + fi + else : + origin + fi + else : + origin + fi +enddef ; + +vardef get_step_chart_bot_line (expr i, j) = + if bbwidth(cells[b][i])>0 : + if bbwidth(texts[b][i][j])>0 : + if bbwidth(cells[b][j+1])>0 : + p[1] := (bot do(b, b, i, .6)) shifted (0,-bbheight(cells[b][i])) ; + p[3] := (bot do(b, b, j+1, .4)) shifted (0,-bbheight(cells[b][j+1])) ; + p[2] := .5[p[1],p[3]] ; + if line_method = 1 : + p[2] := p[2] shifted (0, -ypart + (llcorner cells[b][j+1] - ulcorner texts[b][i][j])) ; + elseif line_method = 2 : + p[2] := center texts[b][i][j] ; + fi ; + p[1] := p[1] shifted (0,-line_v_offset) ; + p[2] := p[2] shifted (0,+line_v_offset) ; + p[3] := p[3] shifted (0,-line_v_offset) ; + (p[1] {down} ... p[2] ... {up} p[3]) + else : + origin + fi + else : + origin + fi + else : + origin + fi +enddef ; + +def end_step_chart = + for i=1 upto nofcells : for nn = t, b : + if bbwidth(cells[nn][i]) >0 : draw cells[nn][i] ; fi ; + endfor ; endfor ; + for i=1 upto nofcells : for j=i upto nofcells : for nn = t, b : + if known lines[nn][i][j] : + if bbwidth(lines[nn][i][j])>0 : draw lines[nn][i][j] ; fi ; + fi ; + endfor ; endfor ; endfor ; + for i=1 upto nofcells : for j=i upto nofcells : for nn = t, b : + if bbwidth(texts[nn][i][j])>0 : draw texts[nn][i][j] ; fi ; + endfor ; endfor ; endfor ; +enddef ; + +%D Step tables. + +def begin_step_table = + initialize_step_variables ; + picture cells[], texts[], lines[] ; + numeric nofcells ; nofcells := 0 ; +enddef ; + +def end_step_table = + for i=1 upto nofcells : if known cells[i] : if bbwidth(cells[i])>0 : + draw cells[i] ; + fi ; fi ; endfor ; + for i=1 upto nofcells : if known lines[i] : if bbwidth(lines[i])>0 : + draw lines[i] ; + fi ; fi ; endfor ; + for i=1 upto nofcells : if known texts[i] : if bbwidth(texts[i])>0 : + draw texts[i] ; + fi ; fi ; endfor ; +enddef ; + +vardef get_step_table_line (expr i) = + pair prev, self, next ; + if known texts[i] : + self := lft .5[llcorner texts[i], ulcorner texts[i] ] ; + prev := rt if known texts[i-1] : .3 else : .5 fi [lrcorner cells[i] , urcorner cells[i] ] ; + next := rt if known texts[i+1] : .7 else : .5 fi [lrcorner cells[i+1], urcorner cells[i+1]] ; + self := self shifted (-line_h_offset,0) ; + prev := prev shifted (+line_h_offset,0) ; + next := next shifted (+line_h_offset,0) ; + prev {right} ... self ... {left} next + else : + origin + fi +enddef ; + +endinput + +%D The older method let \METAPOST\ do the typesetting. The +%D macros needed for that are included here for educational +%D purposes. +%D +%D \starttypen +%D def initialize_step_variables = +%D save line_color, line_width, arrow_alternative, +%D text_fill_color, text_line_color, text_line_width, text_offset, +%D cell_fill_color, cell_line_color, cell_line_width, cell_offset, +%D line_h_offset, line_v_offset ; +%D color line_color ; line_color := .4white ; +%D numeric line_width ; line_width := 1.5pt ; +%D color text_fill_color ; text_fill_color := white ; +%D color text_line_color ; text_line_color := red ; +%D numeric text_line_width ; text_line_width := 1pt ; +%D numeric text_offset ; text_offset := 2pt ; +%D color cell_fill_color ; cell_fill_color := white ; +%D color cell_line_color ; cell_line_color := blue ; +%D numeric cell_line_width ; cell_line_width := 1pt ; +%D numeric cell_offset ; cell_offset := 2pt ; +%D numeric line_alternative ; line_alternative := 1 ; +%D numeric line_h_offset ; line_h_offset := 3pt ; +%D numeric line_v_offset ; line_v_offset := 3pt ; +%D enddef ; +%D +%D def begin_step_chart = +%D begingroup ; +%D initialize_step_variables ; +%D save steps, texts, t, b ; +%D picture cells[][] ; numeric nofcells ; nofcells := 0 ; +%D picture texts[][][] ; numeric noftexts ; noftexts := 0 ; +%D numeric t, b ; t := 1 ; b := 2 ; +%D enddef ; +%D \stoptypen +%D +%D We use a couple of macros to store the content. In the +%D second (third) alternative we will directly fill the +%D cells. +%D +%D \starttypen +%D def set_step_chart_cells (expr one, two) = +%D nofcells := nofcells + 1 ; noftexts := 0 ; +%D cells[t][nofcells] := textext.rt(one) ; +%D cells[b][nofcells] := textext.rt(two) ; +%D enddef ; +%D +%D def set_step_chart_texts (expr one, two) = +%D noftexts := noftexts + 1 ; +%D texts[t][nofcells][noftexts] := textext.rt(one) ; +%D texts[b][nofcells][noftexts] := textext.rt(two) ; +%D enddef ; +%D \stoptypen +%D +%D If you compare the building macro with the later +%D alternative, you will notice that here we explicitly +%D have to calculate the distances and positions. +%D +%D \starttypen +%D def end_step_chart = +%D numeric dx ; dx := 0 ; path p ; +%D numeric n[] ; n[t] := n[b] := 0 ; +%D numeric stepsvdistance[] ; +%D vardef bbwidth (expr p) = (xpart (lrcorner p - llcorner p)) enddef ; +%D vardef bbheight (expr p) = (ypart (urcorner p - lrcorner p)) enddef ; +%D stepsvdistance[t] := stepsvdistance[b] := 0 ; +%D for i=1 upto nofcells : +%D % find largest bbox +%D p := boundingbox steps +%D [if bbwidth(cells[t][i])>bbwidth(cells[b][i]): t else: b fi][i] ; +%D % assign largest bbox +%D for nn = t, b : +%D if bbwidth(cells[nn][i])>0 : +%D setbounds cells[nn][i] to p enlarged cell_offset ; +%D n[nn] := n[nn] + 1 ; +%D fi ; +%D endfor ; +%D % determine height +%D if n[t]>0 : +%D stepsvdistance[t] := bbheight(cells[t][1]) + intertextdistance ; +%D fi ; +%D % add to row +%D for nn = t, b : +%D cells[nn][i] := cells[nn][i] shifted (dx,stepsvdistance[nn]) ; +%D if bbwidth(cells[nn][i])>0 : +%D dowithpath (boundingbox cells[nn][i], +%D cell_line_width, cell_line_color, cell_background_color) ; +%D fi ; +%D endfor ; +%D % calculate position +%D dx := dx + interstepdistance + bbwidth(cells[b][i]) ; +%D endfor ; +%D boolean stacked ; stacked := false ; +%D numeric l[][], r[][], l[][], r[][] ; +%D pair pa, pb, pc ; path p[] ; +%D for i=1 upto nofcells : +%D l[t][i] := r[t][i] := l[b][i] := r[b][i] := 0 ; +%D endfor ; +%D % count left and right points +%D for i=1 upto nofcells : for j=1 upto nofcells : for nn = t, b : +%D if known texts[nn][i][j] : if bbwidth(texts[nn][i][j])>0 : +%D l[nn][i] := l[nn][i] + 1 ; +%D r[nn][j+i] := r[nn][j+i] + 1 ; +%D stacked := (stacked or (j>1)) ; +%D setbounds texts[nn][i][j] to boundingbox texts[nn][i][j] enlarged cell_offset ; +%D fi fi ; +%D endfor ; endfor ; endfor ; +%D % calculate left and right points +%D vardef do (expr nn, mm, ii, ss) = +%D if (l[nn][ii] > 0) and (r[nn][ii] > 0) : ss else : .5 fi +%D [ ulcorner cells[mm][ii],urcorner cells[mm][ii] ] +%D enddef ; +%D % draw arrow from left to right point +%D def dodo (expr nn, ii, jj, dd) = +%D drawarrow p[nn] +%D withpen pencircle scaled arrow_line_width +%D withcolor arrow_line_color ; +%D transform tr ; tr := identity +%D shifted point .5 along p[nn] +%D shifted -center texts[nn][ii][jj] +%D if not stacked : shifted (0,dd) fi ; +%D dowithpath ((boundingbox texts[nn][ii][jj]) transformed tr, +%D text_line_width, text_line_color, text_fill_color) ; +%D enddef ; +%D % draw top and bottom text boxes +%D for i=1 upto nofcells : for j=1 upto nofcells : +%D pickup pencircle scaled arrow_line_width ; +%D if known texts[t][i][j] : if bbwidth(texts[t][i][j]) > 0 : +%D pa := top do(t, if n[t]>0 : t else : b fi, i, .6) ; +%D pb := top do(t, if n[t]>0 : t else : b fi, j+i, .4) ; +%D pc := .5[pa,pb] shifted (0,+step_arrow_depth) ; +%D p[t] := pa {up} .. if not stacked : pc .. fi {down} pb ; +%D dodo(t, i, j, +intertextdistance) ; +%D fi fi ; +%D if known texts[b][i][j] : if bbwidth(texts[b][i][j]) > 0 : +%D pa := (bot do(b, b, i, .6)) shifted (0,-bbheight(cells[b][i])) ; +%D pb := (bot do(b, b, j+i, .4)) shifted (0,-bbheight(cells[b][j+i])) ; +%D pc := .5[pa,pb] shifted (0,-step_arrow_depth) ; +%D p[b] := pa {down} .. if not stacked : pc .. fi {up} pb ; +%D dodo(b, i, j, -intertextdistance) ; +%D fi fi ; +%D endfor ; endfor ; +%D endgroup ; +%D enddef ; +%D \stoptypen +%D +%D If you compare both methods, you will notice that the +%D first method is the cleanest, but not the most efficient +%D (since it needs \TEX\ runs within \METAPOST\ runs within +%D \TEX\ runs). diff --git a/metapost/context/base/mp-step.mpiv b/metapost/context/base/mp-step.mpiv new file mode 100644 index 000000000..dbbc38231 --- /dev/null +++ b/metapost/context/base/mp-step.mpiv @@ -0,0 +1,375 @@ +%D \module +%D [ file=mp-cell.mpiv, % mp-step.mp, +%D version=2010.10.07, % 2001.05.22, +%D title=\CONTEXT\ \METAPOST\ graphics, +%D subtitle=steps, +%D author=Hans Hagen, +%D date=\currentdate, +%D copyright={PRAGMA / Hans Hagen \& Ton Otten}] +%C +%C This module is part of the \CONTEXT\ macro||package and is +%C therefore copyrighted by \PRAGMA. See licen-en.pdf for +%C details. + +if unknown context_tool : input mp-tool ; fi ; +if known context_cell : endinput ; fi ; + +boolean context_cell ; context_cell := true ; + +def initialize_step_variables = + save + text_fill_color, text_line_color, text_line_width, text_offset, + cell_fill_color, cell_line_color, cell_line_width, cell_offset, + line_line_color, line_line_width, line_alternative, + line_distance, cell_distance_y, cell_distance_x, + nofcells, chart_vertical ; + + color text_line_color ; text_line_color := red ; + color cell_line_color ; cell_line_color := blue ; + color line_line_color ; line_line_color := green ; + + color text_fill_color ; text_fill_color := white ; + color cell_fill_color ; cell_fill_color := white ; + + numeric text_line_width ; text_line_width := 2pt ; + numeric cell_line_width ; cell_line_width := 2pt ; + numeric line_line_width ; line_line_width := 2pt ; + + numeric text_offset ; text_offset := 4pt ; + numeric cell_offset ; cell_offset := 4pt ; + + numeric line_distance ; line_distance := 10pt ; % between line and text + numeric line_offset ; line_offset := 4pt ; % between center and start of line + numeric line_height ; line_height := 20pt ; + + numeric cell_distance_y ; cell_distance_y := 20pt ; + numeric cell_distance_x ; cell_distance_x := 20pt ; + + numeric text_distance_set ; text_distance_set := 4pt ; + + boolean chart_vertical ; chart_vertical := false ; + + numeric nofcells ; nofcells := 0 ; + +enddef ; + +def step_cells (expr t, b) = + nofcells := nofcells + 1 ; + cells_t[nofcells] := textext.d(t) ; + cells_b[nofcells] := textext.d(b) ; + texts_t[nofcells] := nullpicture ; + texts_m[nofcells] := nullpicture ; + texts_b[nofcells] := nullpicture ; +enddef ; + +def step_texts (expr t, b) = + texts_t[nofcells] := textext.d(t) ; + texts_m[nofcells] := textext.d(m) ; + texts_b[nofcells] := textext.d(b) ; +enddef ; + +def step_begin_cell = + nofcells := nofcells + 1 ; + cells_t[nofcells] := nullpicture ; + cells_b[nofcells] := nullpicture ; + texts_t[nofcells] := nullpicture ; + texts_m[nofcells] := nullpicture ; + texts_b[nofcells] := nullpicture ; +enddef ; + +def step_end_cell = +enddef ; + +def step_cell_top (expr t) = cells_t[nofcells] := textext.d(t) ; enddef ; +def step_cell_bot (expr b) = cells_b[nofcells] := textext.d(b) ; enddef ; +def step_text_top (expr t) = texts_t[nofcells] := textext.d(t) ; enddef ; +def step_text_mid (expr m) = texts_m[nofcells] := textext.d(m) ; enddef ; +def step_text_bot (expr b) = texts_b[nofcells] := textext.d(b) ; enddef ; + +def step_begin_chart = + begingroup ; + initialize_step_variables ; + save nofcells ; numeric nofcells ; nofcells := 0 ; + save cells_t, cells_m, cells_b ; picture cells_t[], cells_m[], cells_b[] ; + save texts_t, texts_m, texts_b ; picture texts_t[], texts_m[], texts_b[] ; +enddef ; + +def step_end_chart = + % we could combine some loops but this is cleaner + save dx, delta ; numeric dx, delta ; + save p ; path p ; + save one_row_only ; boolean one_row_only ; + save cell_t, next_t, text_t ; picture cell_t, next_t, text_t ; + save cell_m, next_m, text_m ; picture cell_m, next_m, text_m ; + save cell_b, next_b, text_b ; picture cell_b, next_b, text_b ; + save height_t, width_t, max_height_t, max_width_t ; numeric height_t, width_t, max_height_t, max_width_t ; + save height_m, width_m, max_height_m, max_width_m ; numeric height_m, width_m, max_height_m, max_width_m ; + save height_b, width_b, max_height_b, max_width_b ; numeric height_b, width_b, max_height_b, max_width_b ; + % check rows + one_row_only := true ; + for i=1 upto nofcells : + if bbwidth(cells_b[i]) > 0 : + one_row_only := false ; + fi ; + endfor ; + % swap and rotate + if chart_vertical : + if one_row_only : + % deal with mid_texts + max_width_t := max_width_m := max_width_b := 0 ; + for i=1 upto nofcells : + width_t := bbwidth(texts_t[i]) ; + width_m := bbwidth(texts_m[i]) ; + width_b := bbwidth(texts_b[i]) ; + if width_t > max_width_t : max_width_t := width_t fi ; + if width_m > max_width_m : max_width_m := width_m fi ; + if width_b > max_width_b : max_width_b := width_b fi ; + endfor ; + if max_width_m > 0 : + for i=1 upto nofcells : + text_t := texts_t[i] ; width_t := bbwidth(text_t) ; + text_m := texts_m[i] ; width_m := bbwidth(text_m) ; + text_b := texts_b[i] ; width_b := bbwidth(text_b) ; + if width_t < max_width_t : + setbounds text_t to boundingbox text_t leftenlarged (max_width_t - width_t) ; + fi ; + if width_m < max_width_m : + setbounds text_m to boundingbox text_m leftenlarged ((max_width_m - width_m)/2) ; + setbounds text_m to boundingbox text_m rightenlarged ((max_width_m - width_m)/2) ; + fi ; + if width_b < max_width_b : + setbounds text_b to boundingbox text_b rightenlarged (max_width_b - width_b) ; + fi ; + text_t := text_t shifted (- xpart llcorner text_t, 0) ; + text_m := text_m shifted (- xpart llcorner text_m, 0) ; + text_b := text_b shifted (- xpart llcorner text_b, 0) ; + texts_t[i] := image ( + draw text_t ; + draw text_m shifted (max_width_t + text_distance_set,0) ; + draw text_b shifted (max_width_t + max_width_m + 2*text_distance_set,0) ; + ) rotated 90 ; + texts_m[i] := texts_b[i] := nullpicture ; + cells_t[i] := cells_t[i] rotated 90 ; + endfor ; + else : + for i=1 upto nofcells : + cells_t[i] := cells_t[i] rotated 90 ; + texts_t[i] := texts_t[i] rotated 90 ; + texts_b[i] := texts_b[i] rotated 90 ; + endfor ; + fi ; + else : + for i=1 upto nofcells : + cell_t := cells_t[i] ; + cell_b := cells_b[i] ; + cells_t[i] := cell_b rotated 90 ; + cells_b[i] := cell_t rotated 90 ; + text_t := texts_t[i] ; + text_b := texts_b[i] ; + texts_t[i] := text_b rotated 90 ; + texts_b[i] := text_t rotated 90 ; + endfor ; + fi ; + fi ; + % align horizontal + for i=1 upto nofcells : + cell_t := cells_t[i] ; + cell_b := cells_b[i] ; + width_t := bbwidth(cell_t) ; + width_b := bbwidth(cell_b) ; + if (width_t = 0) and (width_b = 0) : + % skip + elseif (width_t > 0) and (width_t < width_b) : + delta := (width_b-width_t)/2 ; + setbounds cell_t to boundingbox cell_t leftenlarged delta rightenlarged delta ; + cells_t[i] := cell_t ; + elseif (width_b > 0) and (width_t > width_b) : + delta := (width_t-width_b)/2 ; + setbounds cell_b to boundingbox cell_b leftenlarged delta rightenlarged delta ; + cells_b[i] := cell_b ; + fi ; + endfor ; + % analyze vertical + max_height_t := 0 ; + max_height_b := 0 ; + for i=1 upto nofcells : + cell_t := cells_t[i] ; + cell_b := cells_b[i] ; + height_t := bbheight(cell_t) ; + height_b := bbheight(cell_b) ; + if height_t > 0 : + setbounds cell_t to boundingbox cell_t enlarged cell_offset ; + height_t := height_t + 2 * cell_offset ; + cells_t[i] := cell_t ; + fi ; + if height_b > 0 : + setbounds cell_b to boundingbox cell_b enlarged cell_offset ; + height_b := height_b + 2 * cell_offset ; + cells_b[i] := cell_b ; + fi ; + if height_t > max_height_t : + max_height_t := height_t ; + fi + if height_b > max_height_b : + max_height_b := height_b ; + fi ; + endfor ; + % align vertical + for i=1 upto nofcells : + cell_t := cells_t[i] ; + cell_b := cells_b[i] ; + height_t := bbheight(cell_t) ; + height_b := bbheight(cell_b) ; + if height_t > 0 : + delta := (max_height_t-height_t)/2 ; + setbounds cell_t to boundingbox cell_t topenlarged delta bottomenlarged delta ; + fi ; + if height_b > 0 : + delta := (max_height_b-height_b)/2 ; + setbounds cell_b to boundingbox cell_b topenlarged delta bottomenlarged delta ; + fi ; + cells_t[i] := cell_t ; + cells_b[i] := cell_b ; + endfor ; + % position + dx := 0 ; + for i=1 upto nofcells : + cell_t := cells_t[i] ; + cell_b := cells_b[i] ; + cell_t := cell_t shifted -llcorner cell_t ; + cell_b := cell_b shifted -llcorner cell_b ; + cell_t := cell_t shifted (dx, 0) ; + cell_b := cell_b shifted (dx,-cell_distance_y-max_height_b) ; + cells_t[i] := cell_t ; + cells_b[i] := cell_b ; + width_t := bbwidth(cell_t) ; + width_b := bbwidth(cell_b) ; + if width_t > 0 : + dx := dx + cell_distance_x + width_t ; + elseif width_b > 0 : + dx := dx + cell_distance_x + width_b ; + fi ; + endfor ; + % flush + for i=1 upto nofcells : + cell_t := cells_t[i] ; + cell_b := cells_b[i] ; + width_t := bbwidth(cell_t) ; + width_b := bbwidth(cell_b) ; + if width_t > 0 : + fill boundingbox cell_t withcolor cell_fill_color ; + draw boundingbox cell_t withpen pencircle scaled cell_line_width withcolor cell_line_color ; + draw cell_t ; + fi ; + if width_b > 0 : + fill boundingbox cell_b withcolor cell_fill_color ; + draw boundingbox cell_b withpen pencircle scaled cell_line_width withcolor cell_line_color ; + draw cell_b ; + fi ; + endfor ; + % + def midtopboundary expr p = 0.5[ulcorner boundingbox p, urcorner boundingbox p] enddef ; + def midbottomboundary expr p = 0.5[llcorner boundingbox p, lrcorner boundingbox p] enddef ; + % draw top and bottom text boxes + for i=1 upto nofcells-1 : + text_t := texts_t[i] ; + text_b := texts_b[i] ; + if bbwidth(text_t) > 0 : + setbounds text_t to boundingbox text_t enlarged text_offset ; + texts_t[i] := text_t ; + fi ; + if bbwidth(text_b) > 0 : + setbounds text_b to boundingbox text_b enlarged text_offset ; + texts_b[i] := text_b ; + fi ; + endfor ; + % arrows + for i=1 upto nofcells-1 : + cell_t := cells_t[i] ; + cell_b := cells_b[i] ; + next_t := cells_t[i+1] ; + next_b := cells_b[i+1] ; + pair t_a, t_b, t_c, b_a, b_b, b_c ; + t_a := midtopboundary cell_t ; + t_b := midtopboundary next_t ; + t_c := (xpart 0.5[t_a,t_b], ypart t_a+line_height+line_distance) ; + if one_row_only : + b_a := midbottomboundary cell_t ; + b_b := midbottomboundary next_t ; + else : + b_a := midbottomboundary cell_b ; + b_b := midbottomboundary next_b ; + fi ; + b_c := (xpart 0.5[b_a,b_b], ypart b_a-line_height-line_distance) ; + texts_t[i] := thelabel.top(texts_t[i],t_c) ; + texts_b[i] := thelabel.bot(texts_b[i],b_c) ; + endfor ; + % + for i=1 upto nofcells-1 : % todo arrows when empty text + cell_t := cells_t[i] ; + cell_b := cells_b[i] ; + next_t := cells_t[i+1] ; + next_b := cells_b[i+1] ; + text_t := texts_t[i] ; + text_b := texts_b[i] ; + if bbwidth(text_t) > 0 : + if bbwidth(cell_t) > 0 : + drawarrow midtopboundary cell_t + shifted (if i > 1 : line_offset else : 0 fi, cell_line_width) {up} .. + midbottomboundary text_t shifted (0,-line_distance) .. + {down} midtopboundary next_t shifted(if i < nofcells - 1 : -line_offset else : 0 fi,cell_line_width) + withpen pencircle scaled line_line_width + withcolor line_line_color ; + else : + fi ; + fi ; + if bbwidth(text_b) > 0 : + if one_row_only : + cell_b := cell_t ; + next_b := next_t ; + fi ; + if bbwidth(cell_b) > 0 : + drawarrow midbottomboundary cell_b + shifted (if i > 1 : line_offset else : 0 fi, -cell_line_width) {down} .. + midtopboundary text_b shifted (0, line_distance) .. + {up} midbottomboundary next_b shifted (if i < nofcells - 1 : -line_offset else : 0 fi,-cell_line_width) + withpen pencircle scaled line_line_width + withcolor line_line_color ; + else : + fi ; + fi ; + endfor ; + % draw top and bottom text boxes + for i=1 upto nofcells-1 : + text_t := texts_t[i] ; + text_b := texts_b[i] ; + if bbwidth(text_t) > 0 : + fill boundingbox text_t withcolor text_fill_color ; + draw boundingbox text_t withpen pencircle scaled text_line_width withcolor text_line_color ; + draw text_t ; + fi ; + if bbwidth(text_b) > 0 : + fill boundingbox text_b withcolor text_fill_color ; + draw boundingbox text_b withpen pencircle scaled text_line_width withcolor text_line_color ; + draw text_b ; + fi ; + endfor ; + if chart_vertical : + % rotate back + currentpicture := currentpicture rotated -90 ; + fi ; + endgroup ; +enddef ; + +% start_begin_step ; +% step_cells ("\strut test 0", "\strut test 0") ; +% step_cells ("\strut test 1", "\vbox{\hsize3cm \strut oeps 1\crlf oeps 1}") ; +% step_texts ("\strut 1", "\strut 1") ; +% step_cells ("\strut test 2", "\strut oeps 2 oeps 2") ; +% step_cells ("\strut test X", "\strut test X") ; +% step_texts ("\strut 2", "\strut 2") ; +% step_cells ("\strut test 3", "\strut oeps 3 oeps 3") ; +% step_texts ("\strut 3", "\strut 3") ; +% step_cells ("\strut test 4", "\strut oeps 4 oeps 4") ; +% step_texts ("\strut 4", "\strut 4") ; +% stop_end_chart ; diff --git a/tex/context/base/anch-pos.mkiv b/tex/context/base/anch-pos.mkiv index bf7575ee3..d7a4b4d07 100644 --- a/tex/context/base/anch-pos.mkiv +++ b/tex/context/base/anch-pos.mkiv @@ -149,10 +149,6 @@ \def\POSprefix{POS::} -\let\setpospx \gobblefourarguments % suppress errors with mkii tuo file -\let\setpospxywhd \gobblesevenarguments % suppress errors with mkii tuo file -\let\setpospxyplus\gobbleeightarguments % suppress errors with mkii tuo file - %D This is real tricky! The page anchor is applied to the %D page box and therefore flushed first. So, when present, it %D is applied to all positions except itself. diff --git a/tex/context/base/cont-new.mkii b/tex/context/base/cont-new.mkii index 8e57d876f..7d7f950fa 100644 --- a/tex/context/base/cont-new.mkii +++ b/tex/context/base/cont-new.mkii @@ -11,7 +11,7 @@ %C therefore copyrighted by \PRAGMA. See mreadme.pdf for %C details. -\newcontextversion{2011.10.12 16:42} +\newcontextversion{2011.10.12 19:30} %D This file is loaded at runtime, thereby providing an %D excellent place for hacks, patches, extensions and new diff --git a/tex/context/base/cont-new.mkiv b/tex/context/base/cont-new.mkiv index ad5702458..ae1b3d2bd 100644 --- a/tex/context/base/cont-new.mkiv +++ b/tex/context/base/cont-new.mkiv @@ -11,7 +11,7 @@ %C therefore copyrighted by \PRAGMA. See mreadme.pdf for %C details. -\newcontextversion{2011.10.12 16:42} +\newcontextversion{2011.10.12 19:30} %D This file is loaded at runtime, thereby providing an %D excellent place for hacks, patches, extensions and new diff --git a/tex/context/base/context-version.pdf b/tex/context/base/context-version.pdf index 0bc4592ce..ff55f5454 100644 Binary files a/tex/context/base/context-version.pdf and b/tex/context/base/context-version.pdf differ diff --git a/tex/context/base/context-version.png b/tex/context/base/context-version.png index 064aade26..44759631d 100644 Binary files a/tex/context/base/context-version.png and b/tex/context/base/context-version.png differ diff --git a/tex/context/base/context.mkii b/tex/context/base/context.mkii index ceb106492..e5991b974 100644 --- a/tex/context/base/context.mkii +++ b/tex/context/base/context.mkii @@ -20,7 +20,7 @@ %D your styles an modules. \edef\contextformat {\jobname} -\edef\contextversion{2011.10.12 16:42} +\edef\contextversion{2011.10.12 19:30} %D For those who want to use this: diff --git a/tex/context/base/context.mkiv b/tex/context/base/context.mkiv index 5a21958fe..a451b056b 100644 --- a/tex/context/base/context.mkiv +++ b/tex/context/base/context.mkiv @@ -20,7 +20,7 @@ %D your styles an modules. \edef\contextformat {\jobname} -\edef\contextversion{2011.10.12 16:42} +\edef\contextversion{2011.10.12 19:30} %D For those who want to use this: diff --git a/tex/context/base/m-chart.lua b/tex/context/base/m-chart.lua new file mode 100644 index 000000000..acb41399e --- /dev/null +++ b/tex/context/base/m-chart.lua @@ -0,0 +1,619 @@ +if not modules then modules = { } end modules ['x-flow'] = { + version = 1.001, + comment = "companion to m-flow.mkvi", + author = "Hans Hagen, PRAGMA-ADE, Hasselt NL", + copyright = "PRAGMA ADE / ConTeXt Development Team", + license = "see context related readme files" +} + +-- when we can resolve mpcolor at the lua end we will use metapost.graphic(....) directly + +moduledata.charts = moduledata.charts or { } + +local gsub, match, find, format, lower = string.gsub, string.match, string.find, string.format, string.lower +local lpegmatch = lpeg.match + +local points = number.points +local variables = interfaces.variables + +local defaults = { + chart = { + name = "", + option = "", + backgroundcolor = "", + width = 0, + height = 0, + dx = 0, + dy = 0, + offset = 0, + bodyfont = "", + dot = "", + }, + shape = { -- FLOS + rulethickness = 65436, + default = "", + framecolor = "green", + backgroundcolor = "yellow", + }, + focus = { -- FLOF + rulethickness = 65436, + framecolor = "red", + backgroundcolor = "yellow", + }, + line = { -- FLOL + rulethickness = 65436, + radius = 65436, + color = "blue", + corner = "", + dash = "", + arrow = "", + offset = "", + }, + set = { -- FLOX + }, + split = { + nx = 3, + ny = 3, + command = "", + marking = "", + before = "", + after = "", + } +} + +local validshapes = { + ["node"] = { kind = "shape", number = 0 }, + ["action"] = { kind = "shape", number = 24 }, + ["procedure"] = { kind = "shape", number = 5 }, + ["product"] = { kind = "shape", number = 12 }, + ["decision"] = { kind = "shape", number = 14 }, + ["archive"] = { kind = "shape", number = 19 }, + ["loop"] = { kind = "shape", number = 35 }, + ["wait"] = { kind = "shape", number = 6 }, + ["subprocedure"] = { kind = "shape", number = 20 }, + ["singledocument"] = { kind = "shape", number = 32 }, + ["multidocument"] = { kind = "shape", number = 33 }, + + ["right"] = { kind = "line", number = 66 }, + ["left"] = { kind = "line", number = 67 }, + ["up"] = { kind = "line", number = 68 }, + ["down"] = { kind = "line", number = 69 }, +} + +local validlabellocations = { + l = "l", left = "l", + r = "r", right = "r", + t = "t", top = "t", + b = "b", bottom = "b", +} + +table.setmetatableindex(validshapes,function(t,k) + local l = gsub(lower(k)," ","") + local v = rawget(t,l) + if not v then + local n = tonumber(k) + if n then + v = { kind = "shape", number = n } + else + v = rawget(t,"action") + end + end + t[k] = v + return v +end) + +local charts = { } + +local data, hash, temp, last_x, last_y, name + +function commands.flow_start_chart(chartname) + data = { } + hash = { } + last_x, last_y = 0, 0 + name = chartname +end + +function commands.flow_stop_chart() + charts[name] = { + data = data, + hash = hash, + last_x = last_x, + last_y = last_y, + } + data, hash, temp = nil, nil, nil +end + +function commands.flow_set_current_cell(n) + temp = data[tonumber(n)] or { } +end + +function commands.flow_start_cell(settings) + temp = { + labels = { }, + comments = { }, + exits = { }, + connections = { }, + settings = settings, + } +end + +function commands.flow_stop_cell() + data[#data+1] = temp + hash[temp.name or #data] = temp +end + +function commands.flow_set_name(str) + temp.name = str +end + +function commands.flow_set_shape(str) + temp.shape = str +end + +function commands.flow_set_destination(str) + temp.destination = str +end + +function commands.flow_set_text(align,str) + temp.align = align + temp.text = str +end + +function commands.flow_set_overlay(str) + temp.overlay = str +end + +function commands.flow_set_focus(str) + temp.focus = str +end + +function commands.flow_set_figure(str) + temp.figure = str +end + +function commands.flow_set_label(location,text) + temp.labels[#temp.labels+1] = { + location = location, + text = text, + } +end + +function commands.flow_set_comment(name,str) + temp.comments[#temp.comments+1] = { + location = location, + text = text, + } +end + +function commands.flow_set_exit(location,text) + temp.exits[#temp.exits+1] = { + location = location, + text = text, + } +end + +function commands.flow_set_include(name,x,y,settings) + data[#data+1] = { + include = name, + x = x, + y = y, + -- settings = settings, + } +end + +local function inject(includedata,data,hash) + local subchart = charts[includedata.include] + if not subchart then + return + end + local subdata = subchart.data + if not subdata then + return + end + local xoffset = (includedata.x or 1) - 1 + local yoffset = (includedata.y or 1) - 1 + local settings = includedata.settings + for i=1,#subdata do + local si = subdata[i] + local t = { + x = si.x + xoffset, + y = si.y + yoffset, + settings = settings, + } + table.setmetatableindex(t,si) + data[#data+1] = t + hash[si.name or #data] = t + end +end + +local function expanded(chart) + local expandeddata = { } + local expandedhash = { } + local expandedchart = { + data = expandeddata, + hash = expandedhash, + } + table.setmetatableindex(expandedchart,chart) + local data = chart.data + local hash = chart.hash + for i=1,#data do + local di = data[i] + if di.include then + inject(di,expandeddata,expandedhash) + else + expandeddata[#expandeddata+1] = di + expandedhash[di.name or #expandeddata] = di + end + end + for i=1,#expandeddata do + local cell = expandeddata[i] + local settings = cell.settings + if not settings then + cell.settings = chart.settings + else + table.setmetatableindex(settings,chart.settings) + end + end + return expandedchart +end + + +local splitter = lpeg.splitat(",") + +function commands.flow_set_location(str) -- handle include differently + -- wrong: delay real x,y, only store relative + local x, y = lpegmatch(splitter,str) + if not x or x == "" then + x = last_x + elseif x == "+" then + x = last_x + 1 + elseif x == "-" then + x = last_x - 1 + elseif find(x,"^[%+%-]") then + x = last_x + (tonumber(x) or 0) + else + x = tonumber(x) + end + if not y or y == "" then + y = last_y + elseif y == "+" then + y = last_y + 1 + elseif x == "-" then + y = last_y - 1 + elseif find(y,"^[%+%-]") then + y = last_y + (tonumber(y) or 0) + else + y = tonumber(y) + end + temp.x = x + temp.y = y + last_x = x + last_y = y +end + +function commands.flow_set_connection(location,displacement,name) + local dx, dy = lpegmatch(splitter,displacement) + dx = tonumber(dx) or 1 + dy = tonumber(dy) or 1 + temp.connections[#temp.connections+1] = { + location = location, + dx = dx - 1, + dy = dy - 1, + name = name, + } +end + +local where = { + l = "left", + r = "right", + t = "top", + b = "bottom", +} + +local what = { + ["p"] = 1, + ["m"] = -1, + ["+"] = 1, + ["-"] = -1, +} + +local function visible(chart,cell) + local x, y = cell.x, cell.y + return + x >= chart.from_x and x <= chart.to_x and + y >= chart.from_y and y <= chart.to_y and cell +end + +local function check_cells(chart,xoffset,yoffset,min_x,min_y,max_x,max_y) + local data = chart.data + if not data then + return + end + for i=1,#data do + local cell = data[i] + local x, y = cell.x + xoffset, cell.y + yoffset + if min_x == 0 then + min_x, max_x = x, x + min_y, max_y = y, y + else + if x < min_x then min_x = x end + if y < min_y then min_y = y end + if x > max_x then max_x = x end + if y > max_y then max_y = y end + end + end + return min_x, min_y, max_x, max_y +end + +local function process_cells(chart,xoffset,yoffset) + local data = chart.data + if not data then + return + end + for i=1,#data do + local cell = visible(chart,data[i]) + if cell then + local shape = cell.shape + if not shape or shape == "" then + shape = settings.shape.default or "none" + end + if shape ~= variables.none then + local settings = cell.settings + local shapedata = validshapes[shape] + context("flow_begin_sub_chart ;") + if shapedata.kind == "line" then + local linesettings = settings.line + context("flow_shape_line_color := \\MPcolor{%s} ;", linesettings.color) + context("flow_shape_fill_color := \\MPcolor{%s} ;", linesettings.backgroundcolor) + context("flow_shape_line_width := %s ; ", points(linesettingsrulethickness)) + elseif hasfocus then -- doifcommonelse{FLOWcell,FLOWfocus}@@FLOWfocus + local focussettings = settings.focus + context("flow_shape_line_color := \\MPcolor{%s} ;", focussettings.framecolor) + context("flow_shape_fill_color := \\MPcolor{%s} ;", focussettings.backgroundcolor) + context("flow_shape_line_width := %s ; ", points(focussettings.rulethickness)) + else + local shapesettings = settings.shape + context("flow_shape_line_color := \\MPcolor{%s} ;", shapesettings.framecolor) + context("flow_shape_fill_color := \\MPcolor{%s} ;", shapesettings.backgroundcolor) + context("flow_shape_line_width := %s ; " , points(shapesettings.rulethickness)) + end + context("bodyfontsize := 10pt ;") -- todo + context("flow_peepshape := false ;") -- todo + context("flow_new_shape(%s,%s,%s) ;",cell.x+xoffset,cell.y+yoffset,shapedata.number) + context("flow_end_sub_chart ;") + end + end + end +end + +-- todo : make lpeg for splitter + +local function process_connections(chart,xoffset,yoffset) + local data = chart.data + local hash = chart.hash + if not data then + return + end + local settings = chart.settings + for i=1,#data do + local cell = visible(chart,data[i]) + if cell then + local connections = cell.connections + for j=1,#connections do + local connection = connections[j] + local othername = connection.name + local othercell = hash[othername] + if othercell then + local cellx, celly = cell.x, cell.y + local otherx, othery, location = othercell.x, othercell.y, connection.location + if otherx > 0 and othery > 0 and cellx > 0 and celly > 0 and connection.location then + -- move to setter + local what_cell, where_cell, what_other, where_other = match(location,"([%+%-pm]-)([lrtb]),?([%+%-pm]-)([lrtb])") + local what_cell = what [what_cell] or 0 + local what_other = what [what_other] or 0 + local where_cell = where[where_cell] or "left" + local where_other = where[where_other] or "right" + local linesettings = settings.line + context("flow_smooth := %s ;", linesettings.corner == variables.round and "true" or "false") + context("flow_dashline := %s ;", linesettings.dash == variables.yes and "true" or "false") + context("flow_arrowtip := %s ;", linesettings.arrow == variables.yes and "true" or "false") + context("flow_touchshape := %s ;", linesettings.offset == variables.none and "true" or "false") + context("flow_dsp_x := %s ; flow_dsp_y := %s ;",connection.dx or 0, connection.dy or 0) + context("flow_connection_line_color := \\MPcolor{%s} ;",linesettings.color) + context("flow_connection_line_width := 2pt ;",points(linesettings.rulethickness)) + context("flow_connect_%s_%s(%s,%s,%s) (%s,%s,%s) ;",where_cell,where_other,cellx,celly,what_cell,otherx,othery,what_other) + context("flow_dsp_x := 0 ; flow_dsp_y := 0 ;") + end + end + end + end + end +end + +local texttemplate = "\\setvariables[flowcell:text][x=%s,y=%s,text={%s},align={%s},figure={%s},destination={%s}]" + +local function process_texts(chart,xoffset,yoffset) + local data = chart.data + local hash = chart.hash + if not data then + return + end + for i=1,#data do + local cell = visible(chart,data[i]) + if cell then + local x = cell.x or 1 + local y = cell.y or 1 + local text = cell.text + if text and text ~= "" then + local a = cell.align or "" + local f = cell.figure or "" + local d = cell.destination or "" + context('flow_chart_draw_text(%s,%s,textext("%s")) ;',x,y,format(texttemplate,x,y,text,a,f,d)) + end + local labels = cell.labels + for i=1,#labels do + local label = labels[i] + local text = label.text + local location = validlabellocations[label.location or ""] + if text and location then + context('flow_chart_draw_label_%s(%s,%s,textext("%s")) ;',location,x,y,text) + end + end + local exits = cell.exits + for i=1,#exits do + local exit = exits[i] + local text = exit.text + local location = validlabellocations[exit.location or ""] + if text and location then + -- maybe make autoexit an option + if location == "l" and x == chart.from_x + 1 or + location == "r" and x == chart.to_x - 1 or + location == "t" and y == chart.to_y - 1 or + location == "b" and y == chart.from_y + 1 then + context('flow_chart_draw_exit_%s(%s,%s,textext("%s")) ;',location,x,y,text) + end + end + end + local comments = cell.comments + for i=1,#comments do + -- invisible + end + end + end +end + +local function getchart(settings) + local chartname = settings.chart.name + if not chartname then + print("no name given") + return + end + local chart = charts[chartname] + if not chart then + print("no such chart",chartname) + return + end + chart.settings = settings + table.setmetatableindex(settings,defaults) + chart = expanded(chart) + local _, _, nx, ny = check_cells(chart,0,0,0,0,0,0) + chart.from_x = chart.settings.chart.x or 1 + chart.from_y = chart.settings.chart.y or 1 + chart.to_x = chart.settings.chart.nx or nx + chart.to_y = chart.settings.chart.ny or ny + chart.nx = chart.to_x - chart.from_x + 1 + chart.ny = chart.to_y - chart.from_y + 1 + return chart +end + +local function makechart(chart) + local settings = chart.settings + context.begingroup() + context.forgetall() + -- + local bodyfont = settings.chart.bodyfont + if bodyfont ~= "" then + context.switchtobodyfont { bodyfont } + end + -- + context.startMPcode() + context("if unknown context_flow : input mp-char.mpiv ; fi ;") + context("flow_begin_chart(0,%s,%s);",chart.nx,chart.ny) + -- + if settings.chart.option == variables.test or settings.chart.dot == variables.yes then + context("flow_show_con_points := true ;") + context("flow_show_mid_points := true ;") + context("flow_show_all_points := true ;") + elseif settings.chart.dot ~= "" then -- no checking done, private option + context("flow_show_%s_points := true ;",settings.chart.dot) + end + -- + local backgroundcolor = settings.chart.backgroundcolor + if backgroundcolor and backgroundcolor ~= "" then + context("flow_chart_background_color := \\MPcolor{%s} ;",backgroundcolor) + end + -- + local shapewidth = settings.chart.width + local gridwidth = shapewidth + 2*settings.chart.dx + local shapeheight = settings.chart.height + local gridheight = shapeheight + 2*settings.chart.dy + context("flow_grid_width := %s ;", points(gridwidth)) + context("flow_grid_height := %s ;", points(gridheight)) + context("flow_shape_width := %s ;", points(shapewidth)) + context("flow_shape_height := %s ;", points(shapeheight)) + -- + local radius = settings.line.radius + local rulethickness = settings.line.rulethickness + local dx = settings.chart.dx + local dy = settings.chart.dy + if radius < rulethickness then + radius = 2.5*rulethickness + if radius > dx then + radius = dx + end + if radius > dy then + radius = dy + end + end + context("flow_connection_line_width := %s ;", points(rulethickness)) + context("flow_connection_smooth_size := %s ;", points(radius)) + context("flow_connection_arrow_size := %s ;", points(radius)) + context("flow_connection_dash_size := %s ;", points(radius)) + -- + local offset = settings.chart.offset -- todo: pass string + if offset == variables.none or offset == variables.overlay or offset == "" then + offset = -2.5 * radius -- or rulethickness? + elseif offset == variables.standard then + offset = radius -- or rulethickness? + end + context("flow_chart_offset := %s ;",points(offset)) + -- + context("flow_reverse_y := true ;") + process_cells(chart,0,0) + process_connections(chart,0,0) + process_texts(chart,0,0) + -- context("clip_chart(%s,%s,%s,%s) ;",x,y,nx,ny) -- todo: draw lines but not shapes + context("flow_end_chart ;") + context.stopMPcode() + context.endgroup() +end + +function commands.flow_make_chart(settings) + local chart = getchart(settings) + if chart then + local settings = chart.settings + if settings.split.state == variables.start then + local nx = chart.settings.split.nx + local ny = chart.settings.split.ny + local x = 1 + while true do + local y = 1 + while true do + -- FLOTbefore + -- doif @@FLOTmarking on -> cuthbox + -- @@FLOTcommand + chart.from_x = x + chart.from_y = y + chart.to_x = math.min(x + nx - 1,chart.nx) + chart.to_y = math.min(x + ny - 1,chart.ny) + makechart(chart) + -- FLOTafter + y = y + ny + if y > chart.max_y then + break + else + y = y - dy + end + end + x = x + nx + if x > chart.max_x then + break + else + x = x - dx + end + end + else + makechart(chart) + end + end +end diff --git a/tex/context/base/m-chart.mkii b/tex/context/base/m-chart.mkii index 9b44a2ce1..13403966b 100644 --- a/tex/context/base/m-chart.mkii +++ b/tex/context/base/m-chart.mkii @@ -478,7 +478,7 @@ \resetMPdrawing \doglobal\newcounter\FLOWcomment \startMPdrawing - if unknown context_char : input mp-char.mp ; fi ; + if unknown context_char : input mp-char.mpii ; fi ; grid_width := \FLOWgridwidth ; grid_height := \FLOWgridheight ; shape_width := \FLOWshapewidth ; diff --git a/tex/context/base/m-chart.mkiv b/tex/context/base/m-chart.mkiv deleted file mode 100644 index 165cb1720..000000000 --- a/tex/context/base/m-chart.mkiv +++ /dev/null @@ -1,1328 +0,0 @@ -%D \module -%D [ file=m-chart, -%D version=1998.10.10, -%D title=\CONTEXT\ Modules, -%D subtitle=Flow Charts, -%D author={Hans Hagen \& Ton Otten}, -%D date=\currentdate, -%D copyright={PRAGMA ADE \& \CONTEXT\ Development Team}] -%C -%C This module is part of the \CONTEXT\ macro||package and is -%C therefore copyrighted by \PRAGMA. See mreadme.pdf for -%C details. - -%D This module will be reimplemented as it can be done much more -%D simple now in mkiv,. - -% todo: \localpushmacro/\localpopmacro (dohandleflowchart etc) -% todo: make mkiv variant -% todo: use dimexpr/numspr - -% will be redone with layers and dimexpr or even better, by just using -% textext .. a nice example of old code - -%D This is an experimental module. Pieces of code will be moved -%D to other modules. More features are possible but will be -%D interfaces later. -%D -%D When finished this module will be documented. The main macro -%D is still a rather big one and there is some redundant and -%D slow code that needs a clean up. - -% arrow, dash -% crossing -% \goto -> \normalgoto -% class -> class:name (ref prefix) -% c, automatisch geen overlap zoeken -% eind eerder chart connecties -% relateren aan korps -% check op bestaan naam, bestaan shape -% auto als extern figuur -% subchart -% pijlen -% focus -% ook nog \MPmessage -% areapath -> krappe vlak -% clippath -> gehele vlak -% -% offset : clip offset -% breedte : breedte cel -% hoogte : hoogte cel -% dx : halve afstand in breedte (grid breedte = breedte + 2dx) -% dy : halve afstand in hoogte (grid hoogte = hoogte + 2dy) -% x : x offset (clipping) -% y : y offset (clipping) -% nx : minimaal aantal cellen horizontaal -% ny : minimaal aantal cellen vertikaal -% -% shape none en geen equivalent maken -% -% kaderkleur achtergrondkleur -% lijnkleur lijndikte -% focus focuskaderkleur focusachtergrondkleur -% richting -% -% focus koppelen aan kleur - -\unprotect - -\definesorting [flowchart] [flowcharts] [\v!none] % no access -\setupsorting [flowchart] [\c!state=\v!stop] % off by default - -\def\@FLOW@{@FLOW@} -\def\@FLOC@{@FLOC@} -\def\@FLOX@{@FLOX@} - -\def\@@FLOW{@@FLOW} -\def\@@FLOL{@@FLOL} -\def\@@FLOS{@@FLOS} -\def\@@FLOF{@@FLOF} -\def\@@FLOT{@@FLOT} -\def\@@FLOX{@@FLOX} - -\def\@@MPx {@@MPx} -\def\@@MPy {@@MPy} - -\def\FLOWbufferprefix{flw-} - -\def\processFLOWbuffer#1{\getbuffer[\FLOWbufferprefix#1]} -\def\typeFLOWbuffer #1{\typebuffer[\FLOWbufferprefix#1]} - -\def\setFLOWname#1#2% funny hack that makes sure that we get - {\bgroup % names that are acceptable for METAPOST - \lccode`0=`a\lccode`1=`b\lccode`2=`c\lccode`3=`d\lccode`4=`e% - \lccode`5=`f\lccode`6=`g\lccode`7=`h\lccode`8=`i\lccode`9=`j% - \lccode` =`\_\lccode`-=`\_\lccode`_=`\_% - \lowercase{\gdef#1{#2}}% - \egroup} - -% een gobble als default is sneller, en dan alleen setten als -% nodig - -\def\resetFLOWcell - {% variables - \global\let\FLOWname \empty - \global\let\FLOWalign \empty - \global\let\FLOWshape \empty - \global\let\FLOWlocation \empty - \global\let\FLOWtext \empty - \global\let\FLOWhelp \empty - \global\let\FLOWdestination\empty - \global\let\FLOWoverlay \empty - \global\let\FLOWfocus \empty - \global\let\tFLOWlabel \empty - \global\let\bFLOWlabel \empty - \global\let\lFLOWlabel \empty - \global\let\rFLOWlabel \empty - \global\let\bcFLOWlabel \empty - \global\let\tcFLOWlabel \empty - \global\let\lcFLOWlabel \empty - \global\let\rcFLOWlabel \empty - \global\let\tFLOWexit \empty - \global\let\bFLOWexit \empty - \global\let\lFLOWexit \empty - \global\let\rFLOWexit \empty - % commands - \let\name \doFLOWname - \let\shape \doFLOWshape - \let\destination\doFLOWdestination - \let\location \doFLOWlocation - \let\focus \doFLOWfocus - \let\overlay \doFLOWoverlay - \let\figure \doFLOWfigure - \let\text \doFLOWtext - \let\comment \doFLOWcomment - \let\label \doFLOWlabel - \let\help \doFLOWhelp - \let\connection \doFLOWconnection - \let\exit \doFLOWexit - % convenience commands - \let\locate \doFLOWlocate - \let\connect \doFLOWconnect} - -\let\FLOWcell \s!unknown -\let\FLOWshape \s!unknown -\let\FLOWdestination\s!unknown -\let\FLOWfocus \s!unknown -\let\FLOWoverlay \empty -\let\FLOWtext \empty - -\def\doFLOWname#1% - {\def\FLOWcell{#1}\setFLOWname\FLOWname{name_#1}\ignorespaces} - -\def\doFLOWshape#1% - {\gdef\FLOWshape{#1}\ignorespaces} - -\def\doFLOWdestination#1% - {\gdef\FLOWdestination{#1}\ignorespaces} - -\def\doFLOWlocation#1% - {\setFLOWlocation#1\end\ignorespaces} - -\def\doFLOWfocus#1% - {\gdef\FLOWfocus{#1}\ignorespaces} - -\def\doFLOWoverlay#1% - {\gdef\FLOWoverlay{#1}\ignorespaces} - -\def\doFLOWfigure#1% - {\defineoverlay[\s!dummy][\overlayfigure{#1}]% - \overlay\s!dummy} - -\def\doFLOWtext - {\dosingleempty\dodoFLOWtext} - -\def\dodoFLOWtext[#1]% % #2% - {\gdef\FLOWalign{#1}\gdef\FLOWtext}% {#2}} - -\def\doFLOWcomment[#1]#2% - {\ignorespaces\dogobblesingleempty} - -\def\doFLOWlabel[#1]#2% wordt dit gebruikt ? - {\setgvalue{#1FLOWlabel}{#2}\ignorespaces} - -\def\doFLOWhelp#1% - {\gdef\FLOWhelp{#1}\ignorespaces} - -\def\doFLOWconnection - {\dodoubleempty\dodoFLOWconnection} - -\def\dodoFLOWconnection[#1][#2]#3% - {\ignorespaces} - -\def\doFLOWconnect - {\connection} - -\def\doFLOWlocate - {\location} - -\def\doFLOWexit[#1]#2% - {\setgvalue{#1FLOWexit}{#2}\ignorespaces} - -\def\startFLOWchart - {\bgroup - \let\stopFLOWchart\egroup - \obeylines % lelijk, buffers nog eens fatsoeneren - \dodoubleempty\dostartFLOWchart} - -\def\dostartFLOWchart[#1][#2]% - {\preparenextFLOWchart{#1}{#2}% - \dostartbuffer[\FLOWbufferprefix\nofFLOWcharts][startFLOWchart][stopFLOWchart]} - -\def\defineFLOWchart% - {\dodoubleempty\dodefineFLOWchart} - -\long\def\dodefineFLOWchart[#1][#2]#3% - {\preparenextFLOWchart{#1}{#2}% - \setbuffer[\FLOWbufferprefix\nofFLOWcharts]#3\endbuffer} - -\def\preparenextFLOWchart#1#2% - {\doglobal\increment\nofFLOWcharts - \flowchart{#1}% - \setxvalue{\@FLOW@-#1}{\noexpand\dohandleflowchart[\nofFLOWcharts][#2]}} - -\def\setupFLOWcharts{\dodoubleargument\getparameters[\@@FLOW]} -\def\setupFLOWlines {\dodoubleargument\getparameters[\@@FLOL]} -\def\setupFLOWshapes{\dodoubleargument\getparameters[\@@FLOS]} -\def\setupFLOWfocus {\dodoubleargument\getparameters[\@@FLOF]} -\def\setupFLOWsets {\dodoubleargument\getparameters[\@@FLOX]} - -\setupFLOWcharts - [\c!option=, - \c!bodyfont=, - \c!dot=, % private option - \c!width=12\bodyfontsize, - \c!height=7\bodyfontsize, - \c!maxwidth=, - \c!maxheight=, - \c!offset=\v!standard, % == auto offset - \c!dx=2\bodyfontsize, - \c!dy=2\bodyfontsize, - \c!nx=0, % 1, - \c!ny=0, % 1, - \c!x=1, - \c!y=1, - \c!autofocus=, - \c!focus=, - \c!background=, % \v!color, - \c!backgroundcolor=\s!white, - \c!rulethickness=\linewidth, - \c!frame=\v!off, - \c!framecolor=] - -\setupFLOWlines - [\c!corner=\v!round, - \c!arrow=\v!yes, - \c!dash=\v!no, - \c!radius=.375\bodyfontsize, % 2.5\c!rulethickness - \c!color=FLOWlinecolor, - \c!rulethickness=.15\bodyfontsize, % 2pt, - \c!offset=\v!none] - -\setupFLOWshapes - [\c!default=action, - \c!framecolor=FLOWframecolor, - \c!background=\v!color, - \c!backgroundcolor=FLOWbackgroundcolor, - \c!backgroundscreen=\@@rsscreen, - \c!rulethickness=.15\bodyfontsize, % 2pt, - \c!offset=.5\bodyfontsize] - -\setupFLOWfocus - [\c!framecolor=FLOWfocuscolor, - \c!background=\@@FLOSbackground, - \c!backgroundcolor=\@@FLOSbackgroundcolor, - \c!backgroundscreen=\@@FLOSbackgroundscreen, - \c!rulethickness=\@@FLOSrulethickness, - \c!offset=\@@FLOSoffset] - -\definecolor [FLOWfocuscolor] [s=.2] -\definecolor [FLOWlinecolor] [s=.5] -\definecolor [FLOWframecolor] [s=.7] -\definecolor [FLOWbackgroundcolor] [s=.9] - -\newcounter\includeFLOWx -\newcounter\includeFLOWy - -\def\includeFLOWchart - {\dodoubleempty\doincludeFLOWchart} - -\def\doincludeFLOWchart[#1][#2]% - {\pushmacro\includeFLOWx - \pushmacro\includeFLOWy - \getparameters[FLOWi][x=1,y=1,#2]% - \increment(\includeFLOWx,0\FLOWix)\decrement\includeFLOWx - \increment(\includeFLOWy,0\FLOWiy)\decrement\includeFLOWy - \def\dodoincludeFLOWchart##1% - {\doifdefined{\@FLOW@-##1} - {\globalpushmacro\dohandleflowchart % was local - \gdef\dohandleflowchart[####1][####2]% - {\globalpopmacro\dohandleflowchart % was local - \resetFLOWlocation - \processFLOWbuffer{####1}}% - \getvalue{\@FLOW@-##1}}}% - \processcommalist[#1]\dodoincludeFLOWchart - \popmacro\includeFLOWx - \popmacro\includeFLOWy} - -\def\resetFLOWlocation - {\globallet\lastFLOWx\!!zerocount - \globallet\lastFLOWy\!!zerocount} - -\def\dosetFLOWlocation[#1#2]#3#4% - {\processaction - [#1#2] - [ +=>\scratchcounter\numexpr#4+ 1+#3\relax, - -=>\scratchcounter\numexpr#4- 1+#3\relax, - +#2=>\scratchcounter\numexpr#4+#2+#3\relax, - -#2=>\scratchcounter\numexpr#4-#2+#3\relax, - \s!default=>\scratchcounter\numexpr#4 +#3\relax, - \s!unknown=>\scratchcounter\numexpr0#1#2+#3\relax]% - \xdef#4{\the\scratchcounter}} - -\def\setFLOWlocation#1,#2\end - {\dosetFLOWlocation[#1\empty]\includeFLOWx\lastFLOWx - \dosetFLOWlocation[#2\empty]\includeFLOWy\lastFLOWy - \xdef\FLOWlocation{\lastFLOWx,\lastFLOWy}} - -\def\FLOWshapes - {node, action, procedure, product, decision, archive, - loop, wait, subprocedure, singledocument, multidocument, - sub procedure, single document, multi document, up, down, - left, right} - -\def\FLOWlines - {up, down, left, right} - -\def\FLOWsetconnect#1% - {\donefalse - \let\cFLOWfrom\empty - \let\cFLOWto\empty - \let\zFLOWfrom\!!zerocount - \let\zFLOWto\!!zerocount - \handletokens#1\with\doFLOWsetconnect - \ifx\cFLOWto\empty\let\cFLOWfrom\empty\fi} - -\def\doFLOWsetconnect#1% - {\ifx #1p% - \ifdone\def\zFLOWto{+1}\else\def\zFLOWfrom{+1}\fi - \else\ifx#1+% - \ifdone\def\zFLOWto{+1}\else\def\zFLOWfrom{+1}\fi - \else\ifx#1n% - \ifdone\def\zFLOWto{-1}\else\def\zFLOWfrom{-1}\fi - \else\ifx#1-% - \ifdone\def\zFLOWto{-1}\else\def\zFLOWfrom{-1}\fi - \else\ifdone - \edef\cFLOWto{\FLOWconnector#1}% - \else - \edef\cFLOWfrom{\FLOWconnector#1}% - \donetrue - \fi\fi\fi\fi\fi} - -\def\FLOWconnector#1% - {\if#1bbottom\else\if#1ttop\else\if#1lleft\else\if#1rright\fi\fi\fi\fi} - -\newif\ifFLOWscaling \FLOWscalingtrue - -\def\@@FLOW@@offset{\@@FLOWoffset} - -\def\getFLOWchart - {\dodoubleempty\dogetFLOWchart} - -\def\dogetFLOWchart[#1][#2]% - {\doifundefinedelse{\@FLOW@-#1} - {\writestatus{FLOW}{unknown chart #1}% - \framed - [\c!width=12\bodyfontsize,\c!height=8\bodyfontsize] - {\tttf [chart #1]}} - {\dodogetFLOWchart[#1][#2]}} - -\def\dodogetFLOWchart[#1][#2]% to be split a bit more - {\vbox\bgroup - \insidefloattrue - \forgetall - \dontcomplain - % \offinterlineskip % we now explicitly use \nointerlineskip later on - \def\dohandleflowchart[##1][##2]% - {\def\currentFLOWnumber{##1}% - \getparameters[\@@FLOW][##2]}% - \getvalue{\@FLOW@-#1}% - \getparameters[\@@FLOW][#2]% dubbelop ? - \doifsomething{\@@FLOWautofocus} - {\checkFLOWautofocus}% - %\message{AUTOSHAPE 3: (\@@FLOWx,\@@FLOWy)->(\@@FLOWnx,\@@FLOWny)}\wait - \global\let\FLOWwidth \@@FLOWnx - \global\let\FLOWheight\@@FLOWny - \let\startFLOWcell\startFLOWcellA - \resetFLOWlocation - \processFLOWbuffer\currentFLOWnumber - \ifcase\@@FLOWnx\relax \let\@@FLOWnx\FLOWwidth \fi - \ifcase\@@FLOWny\relax \let\@@FLOWny\FLOWheight \fi - \doifnothing{\@@FLOWmaxwidth\@@FLOWmaxheight}{\FLOWscalingfalse}% - \ifFLOWscaling - \doifnothing{\@@FLOWmaxwidth }{\let\@@FLOWmaxwidth \maxdimen}% - \doifnothing{\@@FLOWmaxheight}{\let\@@FLOWmaxheight\maxdimen}% - \scratchcounter\bodyfontpoints - \doloop % NOG FONTSWITCH OM EX EN EM TE LATEN WERKEN - {\ifnum\scratchcounter>1 % NU DIMENSIONS IN TERMS OF BODYFONTSIZE - \bodyfontsize=\the\scratchcounter pt - \dimen0=\@@FLOWmaxwidth - \dimen2=\@@FLOWwidth - \dimen4=\@@FLOWdx - \advance\dimen2 2\dimen4 - \dimen2=\@@FLOWnx\dimen2 - \advance\dimen2 2\dimen4 - \ifdim\dimen2>\dimen0 - \advance\scratchcounter \minusone - \else - \dimen0=\@@FLOWmaxheight - \dimen2=\@@FLOWheight - \dimen4=\@@FLOWdy - \advance\dimen2 2\dimen4 - \dimen2=\@@FLOWny\dimen2 - \advance\dimen2 2\dimen4 - \ifdim\dimen2>\dimen0 - \advance\scratchcounter \minusone - \else - \exitloop - \fi - \fi - \else - \exitloop - \fi}% - \expanded{\switchtobodyfont[\the\scratchcounter pt]}% - \forgetall - % \offinterlineskip % needed ? - \else\ifx\@@FLOWbodyfont\empty\else - \expanded{\switchtobodyfont[\@@FLOWbodyfont]}% \expanded ? - \fi\fi - \global\let\FLOWcells\empty - \dimen0=\@@FLOWwidth - \edef\FLOWshapewidth{\the\dimen0}% - \dimen2=\@@FLOWdx - \advance\dimen0 2\dimen2 - \edef\FLOWgridwidth{\the\dimen0}% - \dimen0=\@@FLOWheight - \edef\FLOWshapeheight{\the\dimen0}% - \dimen2=\@@FLOWdy - \advance\dimen0 2\dimen2 - \edef\FLOWgridheight{\the\dimen0}% - \scratchdimen=\@@FLOSrulethickness - \edef\@@FLOSrulethickness{\the\scratchdimen}% - \scratchdimen=\@@FLOFrulethickness - \edef\@@FLOFrulethickness{\the\scratchdimen}% - \scratchdimen=\@@FLOLrulethickness - \edef\@@FLOLrulethickness{\the\scratchdimen}% - \ifdim\@@FLOLradius<2.5\scratchdimen - \scratchdimen=2.5\scratchdimen - \edef\@@FLOLradius{\the\scratchdimen}% - \ifdim\@@FLOLradius>\@@FLOWdx - \scratchdimen=\@@FLOWdx - \edef\@@FLOLradius{\the\scratchdimen}% - \fi - \ifdim\@@FLOLradius>\@@FLOWdy - \scratchdimen=\@@FLOWdy - \edef\@@FLOLradius{\the\scratchdimen}% - \fi - \else - \scratchdimen=\@@FLOLradius - \edef\@@FLOLradius{\the\scratchdimen}% - \fi - \processaction % magic 2.5 - [\@@FLOWoffset] - [ \v!none=>\scratchdimen=-2.5\scratchdimen, - \v!overlay=>\scratchdimen=-2.5\scratchdimen, - \v!standard=>\scratchdimen=\scratchdimen, - \s!unknown=>\scratchdimen=\@@FLOWoffset, - \s!default=>\scratchdimen=-2.5\scratchdimen]% - \edef\@@FLOW@@offset{\the\scratchdimen}% - \forgetall - \offinterlineskip - \resetMPdrawing - \doglobal\newcounter\FLOWcomment - \startMPdrawing - if unknown context_char : input mp-char.mp ; fi ; - grid_width := \FLOWgridwidth ; - grid_height := \FLOWgridheight ; - shape_width := \FLOWshapewidth ; - shape_height := \FLOWshapeheight ; - connection_line_width := \@@FLOLrulethickness ; - connection_smooth_size := \@@FLOLradius ; - connection_arrow_size := \@@FLOLradius ; - connection_dash_size := \@@FLOLradius ; - currentpicture := nullpicture ; - begin_chart(0,\FLOWwidth,\FLOWheight); - reverse_y := true ; - chart_offset := \@@FLOW@@offset ; - \stopMPdrawing - \doifelsenothing\@@FLOWbackgroundcolor - {\startMPdrawing - chart_background_color := white ; - \stopMPdrawing} - {\startMPdrawing - chart_background_color := \MPcolor{\@@FLOWbackgroundcolor} ; - \stopMPdrawing}% - \doif\@@FLOWoption\v!test - {\startMPdrawing - show_con_points := true ; - show_mid_points := true ; - show_all_points := true ; - \stopMPdrawing}% - \processaction % private - [\@@FLOWdot] - [ \v!yes=>\startMPdrawing - show_con_points := true ; - show_mid_points := true ; - show_all_points := true ; - \stopMPdrawing, - \s!unknown=>\startMPdrawing - show_\@@FLOWdot _points := true ; - \stopMPdrawing]% - \doglobal\newcounter\FLOWcomment - \let\startFLOWcell\startFLOWcellB - \resetFLOWlocation - \processFLOWbuffer\currentFLOWnumber - \doglobal\newcounter\FLOWcomment - \let\startFLOWcell\startFLOWcellC - \resetFLOWlocation - \processFLOWbuffer\currentFLOWnumber - \startMPdrawing - clip_chart(\@@FLOWx,\@@FLOWy,\@@FLOWnx,\@@FLOWny) ; - end_chart ; - \stopMPdrawing - \MPdrawingdonetrue - \setbox0\hbox - {\MPstaticgraphictrue - \MPshiftdrawingfalse - \getMPdrawing}% - \def\MPmessage##1% - {\writestatus{MP charts}{##1}}% - \def\MPposition##1##2##3% - {\setvalue{\@@MPx##1}{##2}\setvalue{\@@MPy##1}{##3}}% - \def\MPclippath##1##2##3##4% - {\def\clipMPllx{##1bp}\def\clipMPlly{##2bp}% - \def\clipMPurx{##3bp}\def\clipMPury{##4bp}}% - \def\MPareapath##1##2##3##4% - {\def\areaMPllx{##1bp}\def\areaMPlly{##2bp}% - \def\areaMPurx{##3bp}\def\areaMPury{##4bp}}% - \getMPdata - \doglobal\newcounter\FLOWcomment - \let\startFLOWcell\startFLOWcellD - \setbox2\vbox to \ht0 - {\forgetall % \offinterlineskip - \resetFLOWlocation - \processFLOWbuffer\currentFLOWnumber\vss}% - \setbox2\hbox - {\hskip\@@FLOW@@offset\lower\@@FLOW@@offset\box2}% - \wd2\wd0\ht2\ht0\dp2\dp0 - \let\startFLOWcell\startFLOWcellE - \setbox4\vbox to \ht0 - {\forgetall % \offinterlineskip - \resetFLOWlocation - \processFLOWbuffer\currentFLOWnumber\vss}% - \setbox4\hbox - {\hskip\@@FLOW@@offset\lower\@@FLOW@@offset\box4}% - \wd4\wd0\ht4\ht0\dp4\dp0 - \doifelse\@@FLOWoption\v!test - {\setbox6\vbox - {\forgetall - \vskip\@@FLOW@@offset - \hskip\@@FLOW@@offset - \basegrid - [\c!x=\@@FLOWx,\c!nx=\@@FLOWnx,\c!dx=\withoutpt\FLOWgridwidth, - \c!y=\@@FLOWy,\c!ny=\@@FLOWny,\c!dy=\withoutpt\FLOWgridheight, - \c!xstep=1,\c!ystep=1, - \c!unit=pt,\c!location=\v!middle]}% - \wd6\wd0\ht6\ht0\dp6\dp0 - \setbox8\vbox - {\forgetall - \offinterlineskip - \vskip\@@FLOW@@offset - \dostepwiserecurse\@@FLOWy\@@FLOWny\plusone - {\vbox to \FLOWgridheight - {\vfill - \hskip\@@FLOW@@offset - \hbox - {\dostepwiserecurse\@@FLOWx\@@FLOWnx\plusone - {\hbox to \FLOWgridwidth - {\hfill - \framed - [\c!framecolor=red, - \c!width=\FLOWshapewidth, - \c!height=\FLOWshapeheight] - {}% - \hfill}}} - \vfill}}}% - \wd8\wd0\ht8\ht0\dp8\dp0 - \framed - [\c!offset=\v!overlay,\c!framecolor=green] - {\hbox{\box4\hskip-\wd0\box0\hskip-\wd2\box2\hskip-\wd6\box6\hskip-\wd8\box8}}} - {\framed - [\c!offset=\v!overlay, - \c!frame=\@@FLOWframe, - \c!rulethickness=\@@FLOWrulethickness, - \c!framecolor=\@@FLOWframecolor, - \c!background=\@@FLOWbackground, - \c!backgroundcolor=\@@FLOWbackgroundcolor] - {\hbox{\box4\hskip-\wd0\box0\hskip-\wd2\box2}}}% - %\message{[\FLOWcells]}\wait - \egroup} - -% Pass A - -\long\def\startFLOWcellA#1\stopFLOWcell% - {\resetFLOWcell - \ignorespaces#1\unskip - \expandafter\getFLOWlocationA\FLOWlocation\end - \ignorespaces} - -\def\getFLOWlocationA#1,#2\end - {\ifnum0#1>\FLOWwidth \xdef\FLOWwidth {#1}\fi - \ifnum0#2>\FLOWheight\xdef\FLOWheight{#2}\fi} - -% Pass B -% -% beware: the - after \@FLOC@ is needed since name can be -% empty and we don't want to redefine \@FLOC@ itself by -% mistake - -\long\def\startFLOWcellB#1\stopFLOWcell - {\resetFLOWcell\ignorespaces#1\unskip - \setxvalue{\@FLOC@-\FLOWname}{\FLOWlocation}% kost veel cs's - \ifx\FLOWshape\empty - \global\let\FLOWshape\@@FLOSdefault - \fi - \doifnot\FLOWshape{none} % {\v!none} - {\doifinsetelse\FLOWshape\FLOWshapes - {\edef\FLOWshapetag{shape_\FLOWshape}% beter \expanded - \@EA\setFLOWname\@EA\FLOWshapetag\@EA{\FLOWshapetag}} - {\doifnumberelse\FLOWshape - {\let\FLOWshapetag\FLOWshape} - {\let\FLOWshapetag\empty}}% - \ifx\FLOWshapetag\empty \else - \doifinsetelse\FLOWshape\FLOWlines - {\chardef\FLOWstate0 } - {\doifcommonelse{\FLOWcell,\FLOWfocus}\@@FLOWfocus - {\chardef\FLOWstate1 } - {\chardef\FLOWstate2 }}% - \startMPdrawing - begin_sub_chart ; - \ifcase\FLOWstate - shape_line_color := \MPcolor{\@@FLOLcolor} ; - shape_fill_color := \MPcolor{\@@FLOLcolor} ; - shape_line_width := \@@FLOLrulethickness ; - \or - shape_line_color := \MPcolor{\@@FLOFframecolor} ; - shape_fill_color := \MPcolor{\@@FLOFbackgroundcolor} ; - shape_line_width := \@@FLOFrulethickness ; - \or - shape_line_color := \MPcolor{\@@FLOSframecolor} ; - shape_fill_color := \MPcolor{\@@FLOSbackgroundcolor} ; - shape_line_width := \@@FLOSrulethickness ; - \fi - %\ifx\FLOWoverlay\empty - % peepshape := false ; - %\else - % peepshape := true ; - %\fi - peepshape := \ifx\FLOWoverlay\empty false \else true \fi ; - new_shape(\FLOWlocation,\FLOWshapetag) ; - end_sub_chart ; - \stopMPdrawing - \fi}% - \ignorespaces} - -% Pass C - -\long\def\startFLOWcellC#1\stopFLOWcell% - {\resetFLOWcell -\pushmacro\lastFLOWx -\pushmacro\lastFLOWy - \ignorespaces#1\unskip % makes sure that vars are set -\popmacro\lastFLOWy -\popmacro\lastFLOWx - \let\connection\doFLOWconnectionC - \ignorespaces#1\unskip} - -\def\FLOWorigin{0,0} - -\def\doFLOWdisplace[#1,#2,#3]% experiment - {dsp_x := #1 ; dsp_y := #2 ;} - -\def\doFLOWconnectionC - {\dodoubleempty\dodoFLOWconnectionC} - -\def\dodoFLOWconnectionC[#1][#2]#3% - {\doglobal\increment\FLOWcomment - \setFLOWname\otherFLOWname{name_#3}% - \doifdefinedelse{\@FLOC@-\FLOWname} - {\edef\FLOWfrom{\getvalue{\@FLOC@-\FLOWname}}} - {\let \FLOWfrom \FLOWorigin}% - \ifx\FLOWfrom\FLOWorigin \else - \doifdefinedelse{\@FLOC@-\otherFLOWname} - {\edef\FLOWto {\getvalue{\@FLOC@-\otherFLOWname}}} - {\let \FLOWto \FLOWorigin}% - \ifx\FLOWto\FLOWorigin \else - \FLOWsetconnect{#1}% - \ifx\cFLOWfrom\empty \else - \doifelse\@@FLOLcorner\v!round - {\startMPdrawing smooth := true ; \stopMPdrawing} - {\startMPdrawing smooth := false ; \stopMPdrawing}% - \doifelse\@@FLOLdash\v!yes - {\startMPdrawing dashline := true ; \stopMPdrawing} - {\startMPdrawing dashline := false ; \stopMPdrawing}% - \doifelse\@@FLOLarrow\v!yes - {\startMPdrawing arrowtip := true ; \stopMPdrawing} - {\startMPdrawing arrowtip := false ; \stopMPdrawing}% - \doifelse\@@FLOLoffset\v!none - {\startMPdrawing touchshape := true ; \stopMPdrawing} - {\startMPdrawing touchshape := false ; \stopMPdrawing}% -%\doifsomething{#2} -% {\startMPdrawing -% \doFLOWdisplace[0#2,0,0]% -% \stopMPdrawing}% - \startMPdrawing -\doFLOWdisplace[0#2,0,0]% - connection_line_color := \MPcolor{\@@FLOLcolor} ; - connection_line_width := \@@FLOLrulethickness ; - connect_\cFLOWfrom _\cFLOWto (\FLOWfrom,\zFLOWfrom) (\FLOWto,\zFLOWto) ; -\doFLOWdisplace[0,0,0]% - \stopMPdrawing - \fi - \fi - \fi - \ignorespaces} - -% Pass D - -\long\def\startFLOWcellD#1\stopFLOWcell - {\resetFLOWcell - \pushmacro\lastFLOWx - \pushmacro\lastFLOWy - \ignorespaces#1\unskip % presets vars - \popmacro\lastFLOWy - \popmacro\lastFLOWx - \let\doprocessFLOWcell\doprocessFLOWcellD - \expandafter\doprocessFLOWcellD\FLOWlocation\end - \let\connection\doFLOWconnectionD - \let\comment\doFLOWcommentD - \ignorespaces#1\unskip\ignorespaces} - -\def\doFLOWconnectionD - {\dodoubleempty\dodoFLOWconnectionD} - -\def\dodoFLOWconnectionD[#1][#2]#3% - {\doglobal\increment\FLOWcomment - \ignorespaces} - -\def\doFLOWcommentD[#1]#2% - {\bgroup - \let\FLOW \middlebox - \let\FLOWb \bottombox - \let\FLOWbl\bottomleftbox - \let\FLOWbr\bottomrightbox - \let\FLOWt \topbox - \let\FLOWtl\topleftbox - \let\FLOWtr\toprightbox - \let\FLOWl \leftbox - \let\FLOWlt\lefttopbox - \let\FLOWlb\leftbottombox - \let\FLOWr \rightbox - \let\FLOWrt\righttopbox - \let\FLOWrb\rightbottombox - \let\FLOWc \middlebox -%\ifdefined{FLOW#1}% - \ifcase0\getvalue{\@@MPx\FLOWcomment}\getvalue{\@@MPy\FLOWcomment}\relax - \else - \ifdim\getvalue{\@@MPx\FLOWcomment}\s!bp<\areaMPllx\relax\else - \ifdim\getvalue{\@@MPx\FLOWcomment}\s!bp>\areaMPurx\relax\else - \ifdim\getvalue{\@@MPy\FLOWcomment}\s!bp<\areaMPlly\relax\else - \ifdim\getvalue{\@@MPy\FLOWcomment}\s!bp>\areaMPury\relax\else - \dimen0=\getvalue{\@@MPx\FLOWcomment}\s!bp - \advance\dimen0 -\@@FLOW@@offset - \advance\dimen0 -\clipMPllx - \dimen2=\clipMPury - \advance\dimen2 -\@@FLOW@@offset - \advance\dimen2 -\getvalue{\@@MPy\FLOWcomment}\s!bp - \setbox\scratchbox\hbox{\strut#2}% - \boxoffset.5\bodyfontsize - \setbox\scratchbox\hbox{\hskip\dimen0\lower\dimen2\getvalue{FLOW#1}{\box\scratchbox}}% - \smashbox\scratchbox - \box\scratchbox - \boxoffset\zeropoint - \nointerlineskip % really needed - \fi - \fi - \fi - \fi - \fi -%\fi - \egroup - \ignorespaces} - -% pass D - -\def\dophaseoneFLOWcellX#1#2% - {\!!counta#1\relax - \!!countb#2\relax - \!!countc\@@FLOWx - \!!countd\@@FLOWy - \advance\!!countc \@@FLOWnx - \advance\!!countd \@@FLOWny - \advance\!!countc \minusone - \advance\!!countd \minusone - \ifnum\!!counta<\@@FLOWx\relax \donefalse - \else\ifnum\!!counta>\!!countc \donefalse - \else\ifnum\!!countb<\@@FLOWy\relax \donefalse - \else\ifnum\!!countb>\!!countd \donefalse - \else \donetrue - \fi\fi\fi\fi} - -\def\dophasetwoFLOWcellX - {\advance\!!counta -\@@FLOWx - \advance\!!counta \plusone - \advance\!!countb -\@@FLOWy - \advance\!!countb \plusone - \dimen0=\FLOWgridwidth - \dimen0=\!!counta\dimen0 - \advance\dimen0 -\FLOWgridwidth - \dimen4=\FLOWgridwidth - \advance\dimen4 -\FLOWshapewidth - \advance\dimen0 .5\dimen4 - \dimen2=\FLOWgridheight - \dimen2=\!!countb\dimen2 - \dimen4=\FLOWgridheight - \advance\dimen4 -\FLOWshapeheight - \advance\dimen2 -.5\dimen4 - \edef\FLOWdx{\the\dimen0}% - \edef\FLOWdy{\the\dimen2}} - -\def\positionFLOWzero% assumes \FLOWdx and \FLOWdy are set - {\setbox0\hbox{\hskip\FLOWdx\lower\FLOWdy\box0}% - \smashbox0\box0 - \nointerlineskip} % new, needed since we somehow reset that - -\def\doFLOWtlabel#1#2#3% - {\scratchdimen\ifcase#2 \zeropoint\else\@@FLOWdy\fi - \setbox0\hbox{\hskip\dimen2\raise\scratchdimen - \hbox{\raise\dimen4\hbox{#1{\strut#3}}}}% - \positionFLOWzero}% - -\def\doFLOWblabel#1#2#3% - {\scratchdimen\ifcase#2 \zeropoint\else\@@FLOWdy\fi - \setbox0\hbox{\hskip\dimen2\raise-\scratchdimen - \hbox{#1{\strut#3}}}% - \positionFLOWzero}% - -\def\doFLOWllabel#1#2#3% - {\scratchdimen\ifcase#2 \zeropoint\else\@@FLOWdx\fi - \setbox0\hbox{\hskip-\scratchdimen\raise\dimen6 - \hbox{#1{\strut#3}}}% - \positionFLOWzero}% - -\def\doFLOWrlabel#1#2#3% - {\scratchdimen\ifcase#2 \zeropoint\else\@@FLOWdx\fi - \setbox0\hbox{\hskip\dimen0\hskip\scratchdimen - \hbox{\raise\dimen6\hbox{#1{\strut#3}}}}% - \positionFLOWzero} - -\def\doprocessFLOWcellD#1,#2\end - {\dophaseoneFLOWcellX{#1}{#2}% - \ifdone - \dophasetwoFLOWcellX - \doglobal\addtocommalist\FLOWcell\FLOWcells - \def\FLOWx{#1}% - \def\FLOWy{#2}% - \directsetup{flowcell}% - \setbox0\hbox - {\ifx\FLOWalign\empty\else - \setupframed - [\c!align=\v!normal,\c!bottom=\vfill,\c!top=\vfill]% - \@EA\processallactionsinset\@EA - [\FLOWalign] - [t=>{\setupframed[\c!bottom=\vfill,\c!top=]}, - b=>{\setupframed[\c!bottom=,\c!top=\vfill]}, - l=>{\setupframed[\c!align=\v!right]}, - r=>{\setupframed[\c!align=\v!left]}, - m=>{\setupframed[\c!align=\v!middle]}, - c=>{\setupframed[\c!align=\v!middle]}]% - \fi - \doifelse\FLOWshape{none} % {\v!none} - {\setupframed[\c!offset=\v!overlay]} - {\setupframed[\c!offset=\@@FLOSoffset]}% - \framed - [\c!frame=\v!off,\c!background=flowcell, - \c!width=\FLOWshapewidth,\c!height=\FLOWshapeheight] - {\FLOWtext}}% - %\showFLOWhelp0 - \ifx\FLOWdestination\empty\else - \setbox0\hbox - {\setupinteraction[\c!color=,\c!contrastcolor=]% - \gotobox{\box0}[\FLOWdestination]}% - \fi - \positionFLOWzero - \dimen0=\FLOWshapewidth \dimen2=.5\dimen0 - \dimen4=\FLOWshapeheight\dimen6=.5\dimen4 - \boxoffset.5\bodyfontsize - \doFLOWtlabel \righttopbox0\tFLOWlabel - \doFLOWblabel\rightbottombox0\bFLOWlabel - \doFLOWllabel \lefttopbox0\lFLOWlabel - \doFLOWrlabel \righttopbox0\rFLOWlabel - \doFLOWtlabel \topbox0\tcFLOWlabel % for me only - \doFLOWblabel \bottombox0\bcFLOWlabel % for me only - \doFLOWllabel \leftbox0\lcFLOWlabel % for me only - \doFLOWrlabel \rightbox0\rcFLOWlabel % for me only - \relax\ifnum#1=\@@FLOWx \relax \doFLOWllabel \leftbox1\lFLOWexit \fi - \relax\ifnum#1=\!!countc\relax \doFLOWrlabel \rightbox1\rFLOWexit \fi - \relax\ifnum#2=\@@FLOWy \relax \doFLOWtlabel \topbox1\tFLOWexit \fi - \relax\ifnum#2=\!!countd\relax \doFLOWblabel\bottombox1\bFLOWexit \fi - \boxoffset\zeropoint - \fi} - -% For Willy Egger: -% -% \startsetups flowcell -% \definelayer -% [flowcell] -% [width=\FLOWshapewidth, -% height=\FLOWshapeheight] -% \setlayerframed -% [flowcell] -% [preset=rightbottom,offset=1ex] -% [frame=off] -% {\tx(\FLOWx,\FLOWy)} -% \stopsetups - -% Pass E - -\long\def\startFLOWcellE#1\stopFLOWcell - {\resetFLOWcell - \ignorespaces#1\unskip - \let\doprocessFLOWcell\doprocessFLOWcellE - \expandafter\doprocessFLOWcell\FLOWlocation\end} - -\def\doprocessFLOWcellE#1,#2\end % redundant - {\ifx\FLOWoverlay\empty \else - \dophaseoneFLOWcellX{#1}{#2}% - \ifdone - \dophasetwoFLOWcellX - \edef\FLOWdx{\the\dimen0}% - \edef\FLOWdy{\the\dimen2}% - \setbox0\hbox - {\framed - [%\c!frame=\v!off, - \c!background={\@@FLOWbackground,\FLOWoverlay}, - \c!backgroundcolor=\@@FLOSbackgroundcolor, - \c!width=\FLOWshapewidth,\c!height=\FLOWshapeheight] - {}}% - \positionFLOWzero - \fi - \fi} - -% Pass F - -\def\checkFLOWautofocus - {\def\@@FLOWminx{100}\let\@@FLOWminy\@@FLOWminx - \def\@@FLOWmaxx {0}\let\@@FLOWmaxy\@@FLOWmaxx - \def\@@FLOWabsx {0}\let\@@FLOWabsy\@@FLOWabsx - \let\startFLOWcell\startFLOWcellF - \resetFLOWlocation - \processFLOWbuffer\currentFLOWnumber - %\message{AUTOSHAPE 1: (\@@FLOWminx,\@@FLOWminy)->(\@@FLOWmaxx,\@@FLOWmaxy)}% - \ifnum\@@FLOWabsx<\@@FLOWmaxx\let\@@FLOWmaxx\@@FLOWabsx\fi - \ifnum\@@FLOWabsy<\@@FLOWmaxy\let\@@FLOWmaxy\@@FLOWabsy\fi - %\message{AUTOSHAPE 2: (\@@FLOWminx,\@@FLOWminy)->(\@@FLOWmaxx,\@@FLOWmaxy)}% - \donetrue - \ifnum\@@FLOWminx=100 \donefalse\fi - \ifnum\@@FLOWminy=100 \donefalse\fi - \ifnum\@@FLOWmaxx=0 \donefalse\fi - \ifnum\@@FLOWmaxy=0 \donefalse\fi - \doFLOWcheckF\@@FLOWx\@@FLOWminx\@@FLOWmaxx\@@FLOWnx - \doFLOWcheckF\@@FLOWy\@@FLOWminy\@@FLOWmaxy\@@FLOWny} - -\def\startFLOWcellF#1\stopFLOWcell% - {\resetFLOWcell - \ignorespaces#1\unskip - \expandafter\doFLOWlocationF\FLOWlocation\end}% - -\def\doFLOWlocationF#1,#2\end% - {\ifnum#1>\@@FLOWabsx\def\@@FLOWabsx{#1}\fi - \ifnum#2>\@@FLOWabsy\def\@@FLOWabsy{#2}\fi - \doifinset\FLOWcell\@@FLOWautofocus - {\dodoFLOWlocationF{#1}<-\@@FLOWminx - \dodoFLOWlocationF{#1}>+\@@FLOWmaxx - \dodoFLOWlocationF{#2}<-\@@FLOWminy - \dodoFLOWlocationF{#2}>+\@@FLOWmaxy}} - -\def\dodoFLOWlocationF#1#2#3#4% - {\ifnum#1#2#4\relax - \!!counta=#1\advance\!!counta #31\relax - \edef#4{\ifnum\!!counta<1 1\else\the\!!counta\fi}% - \fi} - -\def\doFLOWcheckF#1#2#3#4% - {\ifdone - \let#1=#2% - \!!counta=#3% - \advance\!!counta \plusone\advance\!!counta -#2\relax - \ifnum\!!counta<1 \!!counta=1 \fi - \edef#4{\the\!!counta}% - \else - \let#1\!!plusone - \let#4\!!zerocount % no {1} - \fi} - -% \useFLOWchart[name][parent][setting,setting][additional settings] -% \useFLOWchart[name][parent][additional settings] - -\let\currentFLOWchart\empty - -\def\useFLOWchart - {\doquadrupleempty\douseFLOWchart} - -\def\douseFLOWchart[#1][#2][#3][#4]% name parent sets mainsettings - {\iffourthargument - \setvalue{\@FLOW@--#1}[##1]{\setgetFLOWchart[#2][#3][#4,##1]}% - \else - \checkparameters[#3]% - \ifparameters - \setvalue{\@FLOW@--#1}[##1]{\setgetFLOWchart[#2][][#3,##1]}% - \else - \setvalue{\@FLOW@--#1}[##1]{\setgetFLOWchart[#2][#3][##1]}% - \fi - \fi} - -\def\setgetFLOWchart[#1][#2][#3]% - {\def\docommand##1{}% cell line focus ? - \processcommalist[#2]\docommand - \getFLOWchart[#1][#3]} - -\def\doFLOWchart[#1][#2]% - {\hbox\bgroup\vbox\bgroup % vmode suppresses spaces -\def\currentFLOWchart{#1}% - \doifundefinedelse{\@FLOW@--#1} - {\getFLOWchart[#1][#2]} - {\getvalue{\@FLOW@--#1}[#2]}% - \egroup\egroup} - -\def\FLOWchart% - {\dodoubleempty\doFLOWchart} - -%D The next section is dedicated to splitting up charts. - -\def\getFLOWsize[#1]% - {\bgroup\let\dodogetFLOWchart\dogetFLOWsize\FLOWchart[#1]\egroup} - -\def\dogetFLOWsize[#1][#2]% - {\setbox\scratchbox=\vbox - {\globallet\FLOWmaxwidth \!!zerocount - \globallet\FLOWmaxheight\!!zerocount - \def\getFLOWlocation##1,##2\end - {\ifnum0##1>\FLOWmaxwidth \xdef\FLOWmaxwidth {##1}\fi - \ifnum0##2>\FLOWmaxheight\xdef\FLOWmaxheight{##2}\fi}% - \resetFLOWcell - \long\def\startFLOWcell##1\stopFLOWcell - {{##1\expandafter\getFLOWlocation\FLOWlocation\end}}% - \def\dohandleflowchart[##1][##2]% - {\resetFLOWlocation - \processFLOWbuffer{##1}}% - \getvalue{\@FLOW@-#1}}} - -\def\setupFLOWsplit - {\dodoubleargument\getparameters[\@@FLOT]} - -\setupFLOWsplit - [\c!nx=3,\c!ny=3, - \c!dx=1,\c!dy=1, - \c!command=, - \c!marking=\v!on, - \c!before=,\c!after=] - -\def\FLOWsplitx {1} -\def\FLOWsplity {1} -\def\FLOWsplitnx{1} -\def\FLOWsplitny{1} - -\def\FLOWcharts% - {\dodoubleempty\doFLOWcharts} - -%D While splitting, the following variables are available: -%D -%D \starttyping -%D \FLOWsplitnx \FLOWsplitny \FLOWsplitx \FLOWsplity -%D \stoptyping - -\def\doFLOWcharts[#1][#2]% - {\bgroup - \getFLOWsize[#1]% - \dodoFLOWcharts\relax - \global\let\FLOWsplitnx\FLOWsplitx - \global\let\FLOWsplitny\FLOWsplity - \dodoFLOWcharts{\dododoFLOWcharts[#1][#2]}% - \egroup} - -\def\dodoFLOWcharts#1% - {\def\@@FLOTx{1}% - \global\let\FLOWsplitx\@@FLOTx - \doloop - {\def\@@FLOTy{1}% - \global\let\FLOWsplity\@@FLOTy - \doloop - {\bgroup - \scratchcounter\FLOWmaxwidth - \advance\scratchcounter -\@@FLOTx - \advance\scratchcounter \plusone - \ifnum\scratchcounter<\@@FLOTnx\edef\@@FLOTnx{\the\scratchcounter}\fi - \scratchcounter\FLOWmaxheight - \advance\scratchcounter -\@@FLOTy - \advance\scratchcounter \plusone - \ifnum\scratchcounter<\@@FLOTny\edef\@@FLOTny{\the\scratchcounter}\fi - #1% does something with the float, or not - \egroup - \increment(\@@FLOTy,\@@FLOTny)% - \ifnum\@@FLOTy>\FLOWmaxheight - \exitloop - \else - \doglobal\increment\FLOWsplity - \decrement(\@@FLOTy,\@@FLOTdy)% - \fi}% - \increment(\@@FLOTx,\@@FLOTnx)% - \ifnum\@@FLOTx>\FLOWmaxwidth - \exitloop - \else - \doglobal\increment\FLOWsplitx - \decrement(\@@FLOTx,\@@FLOTdx)% - \fi}} - -\def\dododoFLOWcharts[#1][#2]% - {\bgroup - \@@FLOTbefore - \doifnot\@@FLOTmarking\v!on{\let\cuthbox\hbox}% - \cuthbox - {\@@FLOTcommand - {\FLOWchart[#1][#2, - \c!x=\@@FLOTx,\c!nx=\@@FLOTnx, - \c!y=\@@FLOTy,\c!ny=\@@FLOTny]}}% - \@@FLOTafter - \egroup} - -%D An example of splitting is given below: -%D -%D \starttyping -%D \setupFLOWsplit -%D [nx=5,ny=10, -%D dx=0,dy=0, -%D before=, -%D after=\page] -%D -%D \FLOWcharts[mybigflow] -%D \stoptyping -%D -%D Or, one can say: -%D -%D \starttyping -%D \splitfloat -%D {\placefigure{What a big flowchart this is!}} -%D {\FLOWcharts[mybigflow]} -%D \stoptyping - -%D \macros -%D {typeFLOWchart} -%D -%D For documentation purposes the following macro is -%D provided. Watch the use of the first and last line hooks, -%D which is needed because the start and stop commands are -%D not part of the buffer. - -\def\typeFLOWchart[#1]% - {\bgroup - \def\dohandleflowchart[##1][##2]{\typeFLOWbuffer{##1}}% - \defconvertedargument\firstverbatimfileline{\startFLOWchart[#1]}% - \defconvertedargument\lastverbatimfileline {\stopFLOWchart}% - \getvalue{\@FLOW@-#1} - \egroup} - -%D New: -%D -%D \starttyping -%D \setupFLOWcharts[command=\Whow] -%D -%D \startFLOWset[convert-en] % [tag][convert-en] -%D \subFLOWchart[a][x=1,y=1,nx=3,ny=3] -%D \subFLOWchart[b][x=1,y=2,nx=3,ny=3] -%D \subFLOWchart[c][x=2,y=1,nx=3,ny=3] -%D \stopFLOWset -%D -%D \def\Whow#1% -%D {\ifnum\currentFLOWset=1 \framed{Some Chart}\fi} -%D -%D \FLOWset[convert-en] % [tag] -%D -%D \def\Whow#1% -%D {\setuphead[state=high] -%D \startstandardmakeup -%D \centerbox{#1} -%D \stopstandardmakeup} -%D -%D \FLOWset[convert-en] % [tag] -%D \stoptyping - -\def\startFLOWset - {\dodoubleempty\dostartFLOWset} - -\def\dostartFLOWset[#1][#2]#3\stopFLOWset % tag name data - {\ifsecondargument - \long\setvalue{\@FLOX@#1}{\dohandleFLOWset{#1}{#2}{#3}}% - \else - \long\setvalue{\@FLOX@#1}{\dohandleFLOWset{#1}{#1}{#3}}% - \fi} - -\long\def\dohandleFLOWset#1#2#3% tag name data - {\bgroup - \def\subFLOWchart - {\dodoubleempty\dosubFLOWchart}% - \def\dosubFLOWchart[##1][##2]% subtag settings - {\ifsecondargument - \dodohandleFLOWset{#1}{##1}{#2}{##2}% - \else - \subFLOWchart[][##1]% - \fi}% - #3% - \egroup} - -\def\dodohandleFLOWset#1#2#3#4% tag subtag name settings - {\increment\currentFLOWset - \bgroup - \@@FLOXcommand - {\ifnum\currentFLOWset=1 \pagereference[#1]\fi - \doifsomething{#2} - {\setupreferencing[\c!prefix=]% - \pagereference[#1:#2]% -:#1:#2 - \setupreferencing[\c!prefix=#1:#2]}% - \FLOWchart[#3][#4]}% - \egroup} - -\def\FLOWset[#1]% - {\newcounter\currentFLOWset - \doifdefinedelse{\@FLOX@#1} - {\getvalue{\@FLOX@#1}} - {\dodohandleFLOWset{#1}{}{#1}{}}} - -\newcounter\currentFLOWset - -\setupFLOWsets - [\c!command=] - -%D This will be an option: - -% \def\startFLOWchart% -% {\dodoubleempty\dostartFLOWchart} -% -% \long\def\dostartFLOWchart[#1][#2]#3\stopFLOWchart -% {\preparenextFLOWchart{#1}{#2}% -% \long\setgvalue{\FLOWbufferprefix\nofFLOWcharts}{#3}} -% -% \long\def\dodefineFLOWchart[#1][#2]#3% -% {\preparenextFLOWchart{#1}{#2}% -% \long\setgvalue{\FLOWbufferprefix\nofFLOWcharts}{#3}} -% -% \def\processFLOWbuffer#1{\getvalue{\FLOWbufferprefix#1}} -% \def\typeFLOWbuffer #1{[Sorry, no verbatim chart #1 available.]} - -\writestatus\m!system{The chart mkiv xml interface is not yet defined!} - -\protect - -\continueifinputfile{m-chart.mkiv} - -\input chrt-xml.tex - -\usemodule[abr-01] - -% \setupFLOWcharts[option=test] -\setupinteraction[state=start] -% \setupFLOWcharts[dx=30pt,dy=30pt] - -\startFLOWchart[demo] - \startFLOWcell - \name {one} -% \destination{CloseDocument} - \location {2,2} -% \shape {action} -% \text {first} -% \label [b] {\bfx bottom} -% \exit [l] {exit l} -% \exit [r] {exit r} -% \exit [t] {exit t} -% \exit [b] {exit b} -\comment[t]{comment t} -\comment[b]{comment t} - \connection [rt] {two} - \stopFLOWcell - \startFLOWcell - \name {two} - \destination{CloseDocument} - \location {3,3} - \shape {action} - \text {second} - \figure {cow.pdf} -% \label [l] {\bfx left} - \stopFLOWcell -\stopFLOWchart - -\starttext - -\startTEXpage -% \FLOWchart[convert-en] -% \FLOWchart[conversion 1] -% \FLOWchart[conversion 7] -% \FLOWchart[conversion 9] -% \FLOWchart[conversion 10] - \FLOWchart[demo] -\stopTEXpage - -\startTEXpage - \FLOWchart[conversion 10] -\stopTEXpage - -\stoptext diff --git a/tex/context/base/m-chart.mkvi b/tex/context/base/m-chart.mkvi new file mode 100644 index 000000000..dc92259d2 --- /dev/null +++ b/tex/context/base/m-chart.mkvi @@ -0,0 +1,477 @@ +%D \module +%D [ file=m-chart, +%D version=2011.10.1, -- 1998.10.10, +%D title=\CONTEXT\ Modules, +%D subtitle=Flow Charts, +%D author=Hans Hagen, +%D date=\currentdate, +%D copyright={PRAGMA ADE \& \CONTEXT\ Development Team}] +%C +%C This module is part of the \CONTEXT\ macro||package and is +%C therefore copyrighted by \PRAGMA. See mreadme.pdf for +%C details. + +% todo (if used): +% autofocus={name,name,name} -> min/max +% flowsets +% autoscaling (bodyfontsteps) +% comment +% overlay +% +% todo: +% \useFLOWchart[name][parent][setting,setting][additional settings] +% \useFLOWchart[name][parent][additional settings] +% setups +% mp instance with less files + +\registerctxluafile{m-chart}{} + +\unprotect + +% todo: figure out a nice way to define the lot: share current and +% support current as name (nb: we need to set parent then) + +\def\??flch{@@flch} % chart +\def\??flln{@@flln} % line +\def\??flsh{@@flsh} % shape +\def\??flfc{@@flfc} % focus +\def\??flst{@@flst} % sets +\def\??flsp{@@flsp} % split + +\installsimplecommandhandler \??flch {FLOWchart} \??flch +\installsimplecommandhandler \??flln {FLOWline} \??flln +\installsimplecommandhandler \??flsh {FLOWshape} \??flsh +\installsimplecommandhandler \??flfc {FLOWfocus} \??flfc +\installsimplecommandhandler \??flst {FLOWsets} \??flst +\installsimplecommandhandler \??flsp {FLOWsplit} \??flsp + +\let\setupFLOWcharts\setupFLOWchart +\let\setupFLOWlines \setupFLOWline +\let\setupFLOWshapes\setupFLOWshape +\let\setupFLOWsets \setupFLOWset + +\setupFLOWcharts + [\c!width=12\bodyfontsize, + \c!height=7\bodyfontsize, + \c!offset=0pt, % \v!standard, % == auto offset + \c!dx=2\bodyfontsize, + \c!dy=2\bodyfontsize, + \c!nx=0, + \c!ny=0, + \c!x=1, + \c!y=1, + % \c!maxwidth=, + % \c!maxheight=, + % \c!option=, + % \c!bodyfont=, + % \c!dot=, % private option + % \c!autofocus=, + % \c!focus=, + % \c!background=, + % \c!framecolor= + % \c!backgroundcolor=, % \s!white + \c!rulethickness=\linewidth, + \c!frame=\v!off] + +\setupFLOWlines + [\c!corner=\v!round, + \c!arrow=\v!yes, + \c!dash=\v!no, + \c!radius=.375\bodyfontsize, + \c!color=FLOWlinecolor, + \c!rulethickness=.15\bodyfontsize, + \c!offset=\v!none] + +\setupFLOWshapes + [\c!default=action, + \c!framecolor=FLOWframecolor, + \c!background=\v!color, + \c!backgroundcolor=FLOWbackgroundcolor, + \c!rulethickness=.15\bodyfontsize, + \c!offset=.5\bodyfontsize] + +\setupFLOWfocus + [\c!framecolor=FLOWfocuscolor, + \c!background=\FLOWshapeparameter\c!background, + \c!backgroundcolor=\FLOWshapeparameter\c!backgroundcolor, + \c!backgroundscreen=\FLOWshapeparameter\c!backgroundscreen, + \c!rulethickness=\FLOWshapeparameter\c!rulethickness, + \c!offset=\FLOWshapeparameter\c!offset] + +\setupFLOWsplit + [\c!state=\v!stop, + \c!marking=\v!on, + % \c!command=, + % \c!before=, + % \c!after=, + \c!nx=3, + \c!ny=3] + +\definecolor [FLOWfocuscolor] [s=.2] +\definecolor [FLOWlinecolor] [s=.5] +\definecolor [FLOWframecolor] [s=.7] +\definecolor [FLOWbackgroundcolor] [s=.9] + +\newtoks\everyFLOWchart + +\unexpanded\def\startFLOWchart + {\startnointerference + \the\everyFLOWchart + \dosingleempty\start_FLOW_chart} + +\unexpanded\def\start_FLOW_chart[#name]% + {\ctxcommand{flow_start_chart("#name")}} + +\unexpanded\def\stopFLOWchart + {\ctxcommand{flow_stop_chart()}% + \stopnointerference} + +\unexpanded\def\defineFLOWchart % for old times sake + {\dodoubleempty\define_FLOW_chart} + +\unexpanded\def\define_FLOW_chart[#name][#settings]#cells% todo: save settings + {\startnointerference + \the\everyFLOWchart + \ctxcommand{flow_start_chart("#name")}% + #cells% + \ctxcommand{flow_stop_chart()}% + \stopnointerference} + +\unexpanded\def\startFLOWcell + {\dodoubleempty\start_FLOW_cell} + +\unexpanded\def\start_FLOW_cell[#1][#2]% + {\begingroup + \iffirstargument + \setupFLOWshape[#1]% + \fi + \ifsecondargument + \setupFLOWline[#2]% + \fi + \ctxcommand{flow_start_cell { + shape = { + rulethickness = \number\dimexpr\FLOWshapeparameter\c!rulethickness, + default = "\FLOWshapeparameter\c!default", + framecolor = "\FLOWshapeparameter\c!framecolor", + backgroundcolor = "\FLOWshapeparameter\c!backgroundcolor", + }, + focus = { + rulethickness = \number\dimexpr\FLOWfocusparameter\c!rulethickness, + framecolor = "\FLOWfocusparameter\c!framecolor", + backgroundcolor = "\FLOWfocusparameter\c!backgroundcolor", + }, + line = { + rulethickness = \number\dimexpr\FLOWlineparameter\c!rulethickness, + radius = \number\dimexpr\FLOWlineparameter\c!radius, + color = "\FLOWlineparameter\c!color", + corner = "\FLOWlineparameter\c!corner", + dash = "\FLOWlineparameter\c!dash", + arrow = "\FLOWlineparameter\c!arrow", + offset = "\FLOWlineparameter\c!offset", + }, + } }% + \endgroup} + +\unexpanded\def\stopFLOWcell + {\ctxcommand{flow_stop_cell()}} + +\unexpanded\def\FLOWchart + {\dodoubleempty\FLOW_chart} + +\def\FLOW_chart[#name][#settings]% + {\vbox\bgroup + \insidefloattrue + \dontcomplain + \setupFLOWchart[#settings]% + \ctxcommand{flow_make_chart { + chart = { + name = "#name", + option = "\FLOWchartparameter\c!option", + backgroundcolor = "\FLOWchartparameter\c!backgroundcolor", + width = \number\dimexpr\FLOWchartparameter\c!width, + height = \number\dimexpr\FLOWchartparameter\c!height, + dx = \number\dimexpr\FLOWchartparameter\c!dx, + dy = \number\dimexpr\FLOWchartparameter\c!dy, + offset = \number\dimexpr\FLOWchartparameter\c!offset, + bodyfont = "\FLOWchartparameter\c!bodyfont", + dot = "\FLOWchartparameter\c!dot", % private option + }, + shape = { + rulethickness = \number\dimexpr\FLOWshapeparameter\c!rulethickness, + default = "\FLOWshapeparameter\c!default", + framecolor = "\FLOWshapeparameter\c!framecolor", + backgroundcolor = "\FLOWshapeparameter\c!backgroundcolor", + }, + focus = { + rulethickness = \number\dimexpr\FLOWfocusparameter\c!rulethickness, + framecolor = "\FLOWfocusparameter\c!framecolor", + backgroundcolor = "\FLOWfocusparameter\c!backgroundcolor", + }, + line = { + rulethickness = \number\dimexpr\FLOWlineparameter\c!rulethickness, + radius = \number\dimexpr\FLOWlineparameter\c!radius, + color = "\FLOWlineparameter\c!color", + corner = "\FLOWlineparameter\c!corner", + dash = "\FLOWlineparameter\c!dash", + arrow = "\FLOWlineparameter\c!arrow", + offset = "\FLOWlineparameter\c!offset", + }, + set = { + }, + split = { + state = "\FLOWsplitparameter\c!state", + nx = \number\FLOWsplitparameter\c!nx, + ny = \number\FLOWsplitparameter\c!ny, + command = "", + marking = "\FLOWsplitparameter\c!marking", + before = "", + after = "", + } + } }% + \egroup} + +\unexpanded\def\FLOWcharts + {\dodoubleempty\FLOW_charts} + +\def\FLOW_charts[#name][#settings] + {\begingroup + \setupFLOWsplit[\c!state=\v!start,#settings]% + \FLOW_chart[#name][]% + \endgroup} + +\appendtoks + \let\name \FLOW_name + \let\shape \FLOW_shape + \let\destination\FLOW_destination + \let\focus \FLOW_focus + \let\overlay \FLOW_overlay + \let\location \FLOW_location + \let\text \FLOW_text + \let\label \FLOW_label + \let\comment \FLOW_comment + \let\exit \FLOW_exit + \let\connection \FLOW_connection + \let\include \FLOW_include + \let\figure \FLOW_figure + % + \let\connect \FLOW_connection + \let\locate \FLOW_location + % + \let\includeFLOWchart\include +\to \everyFLOWchart + +\unexpanded\def\FLOW_name #name{\ctxcommand{flow_set_name("#name")}\ignorespaces} +\unexpanded\def\FLOW_shape #shape{\ctxcommand{flow_set_shape("#shape")}\ignorespaces} +\unexpanded\def\FLOW_destination #destination{\ctxcommand{flow_set_destination("#destination")}\ignorespaces} +\unexpanded\def\FLOW_focus #focus{\ctxcommand{flow_set_focus("#focus")}\ignorespaces} +\unexpanded\def\FLOW_overlay #overlay{\ctxcommand{flow_set_overlay("#overlay")}\ignorespaces} +\unexpanded\def\FLOW_location #location{\ctxcommand{flow_set_location("#location")}\ignorespaces} +\unexpanded\def\FLOW_figure #figure{\ctxcommand{flow_set_figure("#figure")}\ignorespaces} + +\unexpanded\def\FLOW_text {\dosingleempty\do_FLOW_text} +\unexpanded\def\FLOW_label {\dosingleempty\do_FLOW_label} +\unexpanded\def\FLOW_comment {\dosingleempty\do_FLOW_commment} +\unexpanded\def\FLOW_exit {\dosingleempty\do_FLOW_exit} +\unexpanded\def\FLOW_connection {\dodoubleempty\do_FLOW_connection} +\unexpanded\def\FLOW_include {\dodoubleempty\do_FLOW_include} + +\unexpanded\def\do_FLOW_text [#align]#text{\ctxcommand{flow_set_text("#align",\!!bs\detokenize{#text}\!!es)}\ignorespaces} +\unexpanded\def\do_FLOW_label [#location]#text{\ctxcommand{flow_set_label("#location",\!!bs\detokenize{#text}\!!es)}\ignorespaces} +\unexpanded\def\do_FLOW_comment [#location]#text{\ctxcommand{flow_set_comment("#location",\!!bs\detokenize{#text}\!!es)}\ignorespaces} +\unexpanded\def\do_FLOW_exit [#location]#text{\ctxcommand{flow_set_exit("#location",\!!bs\detokenize{#text}\!!es)}\ignorespaces} +\unexpanded\def\do_FLOW_connection[#location][#offset]#name{\ctxcommand{flow_set_connection("#location","#offset","#name")}\ignorespaces} + +\unexpanded\def\do_FLOW_include [#name][#settings]{% + \begingroup + \getparameters[FLOWi][x=1,y=1,#settings]% + \ctxcommand{flow_set_include("#name",\number\FLOWix,\number\FLOWiy,\!!bs\detokenize{#settings}\!!es)}% + \endgroup + \ignorespaces +} + +\setvariables + [flowcell:text] + [x=1, + y=1, + text=, + align=, + set=\setups{flowcell:text:place}] + +% \c!background={\@@FLOWbackground,\FLOWoverlay}, + +\defineoverlay + [flowcell:figure] + [\overlayfigure{\getvariable{flowcell:text}{figure}}] + +\startsetups flowcell:text:place + \begingroup + \iftrialtypesetting + \directsetup{flowcell:text:place:indeed} + \else \iflocation + \doifelsenothing {\getvariable{flowcell:text}{destination}} { + \directsetup{flowcell:text:place:indeed} + } { + % tricky: scaling and moving around is not taken into account + \setupinteraction[\c!color=,\c!contrastcolor=] + \gotobox{\directsetup{flowcell:text:place:indeed}}[\getvariable{flowcell:text}{destination}] + } + \else + \directsetup{flowcell:text:place:indeed} + \fi \fi + \endgroup +\stopsetups + +\startsetups flowcell:text:place:indeed + \begingroup + \directsetup{flowcell:text:user} + \doifelsenothing {\getvariable{flowcell:text}{figure}} { + \doframed + [flowcell:\getvariable{flowcell:text}{align}] + {\getvariable{flowcell:text}{text}} + } { + \doframed + [flowcell:\getvariable{flowcell:text}{align}] + [background=flowcell:figure] + {\getvariable{flowcell:text}{text}} + } + \endgroup +\stopsetups + +\defineframed % to be discussed: shape or global + [flowcell:base] + [\c!offset=\v!overlay, % no strut ? + \c!frame=\FLOWchartparameter\c!frame, + \c!background=\FLOWchartparameter\c!background, + \c!backgroundcolor=\FLOWchartparameter\c!backgroundcolor, + %\c!foregroundcolor=\FLOWshapeparameter\c!foregroundcolor, + \c!align=\v!middle, + \c!bottom=\vfill, + \c!top=\vfill, + \c!width=\FLOWchartparameter\c!width, + \c!height=\FLOWchartparameter\c!height, + % \c!rulethickness=\FLOWchartparameter\c!rulethickness, + \c!rulethickness=\zeropoint, % comment for tracing + \c!framecolor=\FLOWchartparameter\c!framecolor] + +\defineframed[flowcell:] [flowcell:base] +\defineframed[flowcell:l] [flowcell:base][\c!align=\v!flushleft] +\defineframed[flowcell:r] [flowcell:base][\c!align=\v!flushright] +\defineframed[flowcell:m] [flowcell:base][\c!align=\v!middle] +\defineframed[flowcell:c] [flowcell:base][\c!align=\v!middle] + +\defineframed[flowcell:t] [flowcell:base][\c!top=] +\defineframed[flowcell:b] [flowcell:base][\c!bottom=] + +\defineframed[flowcell:lt][flowcell:base][\c!top=,\c!align=\v!flushleft] +\defineframed[flowcell:rt][flowcell:base][\c!top=,\c!align=\v!flushright] +\defineframed[flowcell:mt][flowcell:base][\c!top=,\c!align=\v!middle] +\defineframed[flowcell:ct][flowcell:base][\c!top=,\c!align=\v!middle] + +\defineframed[flowcell:lb][flowcell:base][\c!bottom=,\c!align=\v!flushleft] +\defineframed[flowcell:rb][flowcell:base][\c!bottom=,\c!align=\v!flushright] +\defineframed[flowcell:mb][flowcell:base][\c!bottom=,\c!align=\v!middle] +\defineframed[flowcell:cb][flowcell:base][\c!bottom=,\c!align=\v!middle] + +% todo: each cell its own setup +% +% \startsetups flowcell +% \definelayer +% [flowcell] +% [width=\FLOWshapewidth, +% height=\FLOWshapeheight] +% \setlayerframed +% [flowcell] +% [preset=rightbottom,offset=1ex] +% [frame=off] +% {\tx(\FLOWx,\FLOWy)} +% \stopsetups + +%D \starttyping +%D \setupFLOWsplit +%D [nx=5,ny=10, +%D dx=0,dy=0, +%D before=, +%D after=\page] +%D +%D \FLOWcharts[mybigflow] +%D \stoptyping +%D +%D \starttyping +%D \splitfloat +%D {\placefigure{What a big flowchart this is!}} +%D {\FLOWcharts[mybigflow]} +%D \stoptyping + +\protect + +\continueifinputfile{m-chart.mkvi} + +\input chrt-xml.tex + +\usemodule[abr-01] + +\setupFLOWcharts[option=test] +\setupFLOWcharts[frame=on] +\setupinteraction[state=start] + +% \setupFLOWcharts[dx=30pt,dy=30pt] + +\startMPinclusions + predefined_shapes[101] := fullcircle ; +\stopMPinclusions + +\startFLOWchart[demo] + \startFLOWcell[framecolor=darkgray] + \name {start} + \location {1,1} + \shape {action} + \text {start} + \connection [bl] {one} + \stopFLOWcell + \startFLOWcell + \name {one} +% \destination{CloseDocument} + \location {2,2} +% \shape {action} + \shape {101} + \text {first} +% \label [b] {\bfx bottom} + \connection [rt] {two} +% \exit [l] {exit l} +% \exit [r] {exit r} +% \exit [t] {exit t} +% \exit [b] {exit b} + \stopFLOWcell + \setupFLOWshapes[framecolor=darkgray] + \startFLOWcell % [foregroundcolor=white] + \name {two} +% \destination{CloseDocument} + \location {3,3} + \shape {action} + \text {second} + \figure {cow.pdf} +% \label [l] {\bfx left} +% \exit [l] {exit l} +% \exit [r] {exit r} +% \exit [t] {exit t} +% \exit [b] {exit b} + \stopFLOWcell +\stopFLOWchart + +\starttext + +\startTEXpage +% \FLOWchart[convert-en] +% \FLOWchart[conversion 1] +% \FLOWchart[conversion 7] +% \FLOWchart[conversion 9] +% \FLOWchart[conversion 10] + \FLOWchart[demo] + +\stopTEXpage + +\startTEXpage + \FLOWchart[conversion 10] +\stopTEXpage + +\stoptext diff --git a/tex/context/base/m-flow.lua b/tex/context/base/m-flow.lua deleted file mode 100644 index 62d31c197..000000000 --- a/tex/context/base/m-flow.lua +++ /dev/null @@ -1,619 +0,0 @@ -if not modules then modules = { } end modules ['x-flow'] = { - version = 1.001, - comment = "companion to m-flow.mkvi", - author = "Hans Hagen, PRAGMA-ADE, Hasselt NL", - copyright = "PRAGMA ADE / ConTeXt Development Team", - license = "see context related readme files" -} - --- when we can resolve mpcolor at the lua end we will use metapost.graphic(....) directly - -moduledata.charts = moduledata.charts or { } - -local gsub, match, find, format, lower = string.gsub, string.match, string.find, string.format, string.lower -local lpegmatch = lpeg.match - -local points = number.points -local variables = interfaces.variables - -local defaults = { - chart = { - name = "", - option = "", - backgroundcolor = "", - width = 0, - height = 0, - dx = 0, - dy = 0, - offset = 0, - bodyfont = "", - dot = "", - }, - shape = { -- FLOS - rulethickness = 65436, - default = "", - framecolor = "green", - backgroundcolor = "yellow", - }, - focus = { -- FLOF - rulethickness = 65436, - framecolor = "red", - backgroundcolor = "yellow", - }, - line = { -- FLOL - rulethickness = 65436, - radius = 65436, - color = "blue", - corner = "", - dash = "", - arrow = "", - offset = "", - }, - set = { -- FLOX - }, - split = { - nx = 3, - ny = 3, - command = "", - marking = "", - before = "", - after = "", - } -} - -local validshapes = { - ["node"] = { kind = "shape", number = 0 }, - ["action"] = { kind = "shape", number = 24 }, - ["procedure"] = { kind = "shape", number = 5 }, - ["product"] = { kind = "shape", number = 12 }, - ["decision"] = { kind = "shape", number = 14 }, - ["archive"] = { kind = "shape", number = 19 }, - ["loop"] = { kind = "shape", number = 35 }, - ["wait"] = { kind = "shape", number = 6 }, - ["subprocedure"] = { kind = "shape", number = 20 }, - ["singledocument"] = { kind = "shape", number = 32 }, - ["multidocument"] = { kind = "shape", number = 33 }, - - ["right"] = { kind = "line", number = 66 }, - ["left"] = { kind = "line", number = 67 }, - ["up"] = { kind = "line", number = 68 }, - ["down"] = { kind = "line", number = 69 }, -} - -local validlabellocations = { - l = "l", left = "l", - r = "r", right = "r", - t = "t", top = "t", - b = "b", bottom = "b", -} - -table.setmetatableindex(validshapes,function(t,k) - local l = gsub(lower(k)," ","") - local v = rawget(t,l) - if not v then - local n = tonumber(k) - if n then - v = { kind = "shape", number = n } - else - v = rawget(t,"action") - end - end - t[k] = v - return v -end) - -local charts = { } - -local data, hash, temp, last_x, last_y, name - -function commands.flow_start_chart(chartname) - data = { } - hash = { } - last_x, last_y = 0, 0 - name = chartname -end - -function commands.flow_stop_chart() - charts[name] = { - data = data, - hash = hash, - last_x = last_x, - last_y = last_y, - } - data, hash, temp = nil, nil, nil -end - -function commands.flow_set_current_cell(n) - temp = data[tonumber(n)] or { } -end - -function commands.flow_start_cell(settings) - temp = { - labels = { }, - comments = { }, - exits = { }, - connections = { }, - settings = settings, - } -end - -function commands.flow_stop_cell() - data[#data+1] = temp - hash[temp.name or #data] = temp -end - -function commands.flow_set_name(str) - temp.name = str -end - -function commands.flow_set_shape(str) - temp.shape = str -end - -function commands.flow_set_destination(str) - temp.destination = str -end - -function commands.flow_set_text(align,str) - temp.align = align - temp.text = str -end - -function commands.flow_set_overlay(str) - temp.overlay = str -end - -function commands.flow_set_focus(str) - temp.focus = str -end - -function commands.flow_set_figure(str) - temp.figure = str -end - -function commands.flow_set_label(location,text) - temp.labels[#temp.labels+1] = { - location = location, - text = text, - } -end - -function commands.flow_set_comment(name,str) - temp.comments[#temp.comments+1] = { - location = location, - text = text, - } -end - -function commands.flow_set_exit(location,text) - temp.exits[#temp.exits+1] = { - location = location, - text = text, - } -end - -function commands.flow_set_include(name,x,y,settings) - data[#data+1] = { - include = name, - x = x, - y = y, - -- settings = settings, - } -end - -local function inject(includedata,data,hash) - local subchart = charts[includedata.include] - if not subchart then - return - end - local subdata = subchart.data - if not subdata then - return - end - local xoffset = (includedata.x or 1) - 1 - local yoffset = (includedata.y or 1) - 1 - local settings = includedata.settings - for i=1,#subdata do - local si = subdata[i] - local t = { - x = si.x + xoffset, - y = si.y + yoffset, - settings = settings, - } - table.setmetatableindex(t,si) - data[#data+1] = t - hash[si.name or #data] = t - end -end - -local function expanded(chart) - local expandeddata = { } - local expandedhash = { } - local expandedchart = { - data = expandeddata, - hash = expandedhash, - } - table.setmetatableindex(expandedchart,chart) - local data = chart.data - local hash = chart.hash - for i=1,#data do - local di = data[i] - if di.include then - inject(di,expandeddata,expandedhash) - else - expandeddata[#expandeddata+1] = di - expandedhash[di.name or #expandeddata] = di - end - end - for i=1,#expandeddata do - local cell = expandeddata[i] - local settings = cell.settings - if not settings then - cell.settings = chart.settings - else - table.setmetatableindex(settings,chart.settings) - end - end - return expandedchart -end - - -local splitter = lpeg.splitat(",") - -function commands.flow_set_location(str) -- handle include differently - -- wrong: delay real x,y, only store relative - local x, y = lpegmatch(splitter,str) - if not x or x == "" then - x = last_x - elseif x == "+" then - x = last_x + 1 - elseif x == "-" then - x = last_x - 1 - elseif find(x,"^[%+%-]") then - x = last_x + (tonumber(x) or 0) - else - x = tonumber(x) - end - if not y or y == "" then - y = last_y - elseif y == "+" then - y = last_y + 1 - elseif x == "-" then - y = last_y - 1 - elseif find(y,"^[%+%-]") then - y = last_y + (tonumber(y) or 0) - else - y = tonumber(y) - end - temp.x = x - temp.y = y - last_x = x - last_y = y -end - -function commands.flow_set_connection(location,displacement,name) - local dx, dy = lpegmatch(splitter,displacement) - dx = tonumber(dx) or 1 - dy = tonumber(dy) or 1 - temp.connections[#temp.connections+1] = { - location = location, - dx = dx - 1, - dy = dy - 1, - name = name, - } -end - -local where = { - l = "left", - r = "right", - t = "top", - b = "bottom", -} - -local what = { - ["p"] = 1, - ["m"] = -1, - ["+"] = 1, - ["-"] = -1, -} - -local function visible(chart,cell) - local x, y = cell.x, cell.y - return - x >= chart.from_x and x <= chart.to_x and - y >= chart.from_y and y <= chart.to_y and cell -end - -local function check_cells(chart,xoffset,yoffset,min_x,min_y,max_x,max_y) - local data = chart.data - if not data then - return - end - for i=1,#data do - local cell = data[i] - local x, y = cell.x + xoffset, cell.y + yoffset - if min_x == 0 then - min_x, max_x = x, x - min_y, max_y = y, y - else - if x < min_x then min_x = x end - if y < min_y then min_y = y end - if x > max_x then max_x = x end - if y > max_y then max_y = y end - end - end - return min_x, min_y, max_x, max_y -end - -local function process_cells(chart,xoffset,yoffset) - local data = chart.data - if not data then - return - end - for i=1,#data do - local cell = visible(chart,data[i]) - if cell then - local shape = cell.shape - if not shape or shape == "" then - shape = settings.shape.default or "none" - end - if shape ~= variables.none then - local settings = cell.settings - local shapedata = validshapes[shape] - context("flow_begin_sub_chart ;") - if shapedata.kind == "line" then - local linesettings = settings.line - context("flow_shape_line_color := \\MPcolor{%s} ;", linesettings.color) - context("flow_shape_fill_color := \\MPcolor{%s} ;", linesettings.backgroundcolor) - context("flow_shape_line_width := %s ; ", points(linesettingsrulethickness)) - elseif hasfocus then -- doifcommonelse{FLOWcell,FLOWfocus}@@FLOWfocus - local focussettings = settings.focus - context("flow_shape_line_color := \\MPcolor{%s} ;", focussettings.framecolor) - context("flow_shape_fill_color := \\MPcolor{%s} ;", focussettings.backgroundcolor) - context("flow_shape_line_width := %s ; ", points(focussettings.rulethickness)) - else - local shapesettings = settings.shape - context("flow_shape_line_color := \\MPcolor{%s} ;", shapesettings.framecolor) - context("flow_shape_fill_color := \\MPcolor{%s} ;", shapesettings.backgroundcolor) - context("flow_shape_line_width := %s ; " , points(shapesettings.rulethickness)) - end - context("bodyfontsize := 10pt ;") -- todo - context("flow_peepshape := false ;") -- todo - context("flow_new_shape(%s,%s,%s) ;",cell.x+xoffset,cell.y+yoffset,shapedata.number) - context("flow_end_sub_chart ;") - end - end - end -end - --- todo : make lpeg for splitter - -local function process_connections(chart,xoffset,yoffset) - local data = chart.data - local hash = chart.hash - if not data then - return - end - local settings = chart.settings - for i=1,#data do - local cell = visible(chart,data[i]) - if cell then - local connections = cell.connections - for j=1,#connections do - local connection = connections[j] - local othername = connection.name - local othercell = hash[othername] - if othercell then - local cellx, celly = cell.x, cell.y - local otherx, othery, location = othercell.x, othercell.y, connection.location - if otherx > 0 and othery > 0 and cellx > 0 and celly > 0 and connection.location then - -- move to setter - local what_cell, where_cell, what_other, where_other = match(location,"([%+%-pm]-)([lrtb]),?([%+%-pm]-)([lrtb])") - local what_cell = what [what_cell] or 0 - local what_other = what [what_other] or 0 - local where_cell = where[where_cell] or "left" - local where_other = where[where_other] or "right" - local linesettings = settings.line - context("flow_smooth := %s ;", linesettings.corner == variables.round and "true" or "false") - context("flow_dashline := %s ;", linesettings.dash == variables.yes and "true" or "false") - context("flow_arrowtip := %s ;", linesettings.arrow == variables.yes and "true" or "false") - context("flow_touchshape := %s ;", linesettings.offset == variables.none and "true" or "false") - context("flow_dsp_x := %s ; flow_dsp_y := %s ;",connection.dx or 0, connection.dy or 0) - context("flow_connection_line_color := \\MPcolor{%s} ;",linesettings.color) - context("flow_connection_line_width := 2pt ;",points(linesettings.rulethickness)) - context("flow_connect_%s_%s(%s,%s,%s) (%s,%s,%s) ;",where_cell,where_other,cellx,celly,what_cell,otherx,othery,what_other) - context("flow_dsp_x := 0 ; flow_dsp_y := 0 ;") - end - end - end - end - end -end - -local texttemplate = "\\setvariables[flowcell:text][x=%s,y=%s,text={%s},align={%s},figure={%s},destination={%s}]" - -local function process_texts(chart,xoffset,yoffset) - local data = chart.data - local hash = chart.hash - if not data then - return - end - for i=1,#data do - local cell = visible(chart,data[i]) - if cell then - local x = cell.x or 1 - local y = cell.y or 1 - local text = cell.text - if text and text ~= "" then - local a = cell.align or "" - local f = cell.figure or "" - local d = cell.destination or "" - context('flow_chart_draw_text(%s,%s,textext("%s")) ;',x,y,format(texttemplate,x,y,text,a,f,d)) - end - local labels = cell.labels - for i=1,#labels do - local label = labels[i] - local text = label.text - local location = validlabellocations[label.location or ""] - if text and location then - context('flow_chart_draw_label_%s(%s,%s,textext("%s")) ;',location,x,y,text) - end - end - local exits = cell.exits - for i=1,#exits do - local exit = exits[i] - local text = exit.text - local location = validlabellocations[exit.location or ""] - if text and location then - -- maybe make autoexit an option - if location == "l" and x == chart.from_x + 1 or - location == "r" and x == chart.to_x - 1 or - location == "t" and y == chart.to_y - 1 or - location == "b" and y == chart.from_y + 1 then - context('flow_chart_draw_exit_%s(%s,%s,textext("%s")) ;',location,x,y,text) - end - end - end - local comments = cell.comments - for i=1,#comments do - -- invisible - end - end - end -end - -local function getchart(settings) - local chartname = settings.chart.name - if not chartname then - print("no name given") - return - end - local chart = charts[chartname] - if not chart then - print("no such chart",chartname) - return - end - chart.settings = settings - table.setmetatableindex(settings,defaults) - chart = expanded(chart) - local _, _, nx, ny = check_cells(chart,0,0,0,0,0,0) - chart.from_x = chart.settings.chart.x or 1 - chart.from_y = chart.settings.chart.y or 1 - chart.to_x = chart.settings.chart.nx or nx - chart.to_y = chart.settings.chart.ny or ny - chart.nx = chart.to_x - chart.from_x + 1 - chart.ny = chart.to_y - chart.from_y + 1 - return chart -end - -local function makechart(chart) - local settings = chart.settings - context.begingroup() - context.forgetall() - -- - local bodyfont = settings.chart.bodyfont - if bodyfont ~= "" then - context.switchtobodyfont { bodyfont } - end - -- - context.startMPcode() - context("if unknown context_flow : input mp-flow.mpiv ; fi ;") - context("flow_begin_chart(0,%s,%s);",chart.nx,chart.ny) - -- - if settings.chart.option == variables.test or settings.chart.dot == variables.yes then - context("flow_show_con_points := true ;") - context("flow_show_mid_points := true ;") - context("flow_show_all_points := true ;") - elseif settings.chart.dot ~= "" then -- no checking done, private option - context("flow_show_%s_points := true ;",settings.chart.dot) - end - -- - local backgroundcolor = settings.chart.backgroundcolor - if backgroundcolor and backgroundcolor ~= "" then - context("flow_chart_background_color := \\MPcolor{%s} ;",backgroundcolor) - end - -- - local shapewidth = settings.chart.width - local gridwidth = shapewidth + 2*settings.chart.dx - local shapeheight = settings.chart.height - local gridheight = shapeheight + 2*settings.chart.dy - context("flow_grid_width := %s ;", points(gridwidth)) - context("flow_grid_height := %s ;", points(gridheight)) - context("flow_shape_width := %s ;", points(shapewidth)) - context("flow_shape_height := %s ;", points(shapeheight)) - -- - local radius = settings.line.radius - local rulethickness = settings.line.rulethickness - local dx = settings.chart.dx - local dy = settings.chart.dy - if radius < rulethickness then - radius = 2.5*rulethickness - if radius > dx then - radius = dx - end - if radius > dy then - radius = dy - end - end - context("flow_connection_line_width := %s ;", points(rulethickness)) - context("flow_connection_smooth_size := %s ;", points(radius)) - context("flow_connection_arrow_size := %s ;", points(radius)) - context("flow_connection_dash_size := %s ;", points(radius)) - -- - local offset = settings.chart.offset -- todo: pass string - if offset == variables.none or offset == variables.overlay or offset == "" then - offset = -2.5 * radius -- or rulethickness? - elseif offset == variables.standard then - offset = radius -- or rulethickness? - end - context("flow_chart_offset := %s ;",points(offset)) - -- - context("flow_reverse_y := true ;") - process_cells(chart,0,0) - process_connections(chart,0,0) - process_texts(chart,0,0) - -- context("clip_chart(%s,%s,%s,%s) ;",x,y,nx,ny) -- todo: draw lines but not shapes - context("flow_end_chart ;") - context.stopMPcode() - context.endgroup() -end - -function commands.flow_make_chart(settings) - local chart = getchart(settings) - if chart then - local settings = chart.settings - if settings.split.state == variables.start then - local nx = chart.settings.split.nx - local ny = chart.settings.split.ny - local x = 1 - while true do - local y = 1 - while true do - -- FLOTbefore - -- doif @@FLOTmarking on -> cuthbox - -- @@FLOTcommand - chart.from_x = x - chart.from_y = y - chart.to_x = math.min(x + nx - 1,chart.nx) - chart.to_y = math.min(x + ny - 1,chart.ny) - makechart(chart) - -- FLOTafter - y = y + ny - if y > chart.max_y then - break - else - y = y - dy - end - end - x = x + nx - if x > chart.max_x then - break - else - x = x - dx - end - end - else - makechart(chart) - end - end -end diff --git a/tex/context/base/m-flow.mkvi b/tex/context/base/m-flow.mkvi deleted file mode 100644 index 425d7e490..000000000 --- a/tex/context/base/m-flow.mkvi +++ /dev/null @@ -1,477 +0,0 @@ -%D \module -%D [ file=m-flow, -- m-chart -%D version=2011.10.1, -- 1998.10.10, -%D title=\CONTEXT\ Modules, -%D subtitle=Flow Charts, -%D author=Hans Hagen, -%D date=\currentdate, -%D copyright={PRAGMA ADE \& \CONTEXT\ Development Team}] -%C -%C This module is part of the \CONTEXT\ macro||package and is -%C therefore copyrighted by \PRAGMA. See mreadme.pdf for -%C details. - -% todo (if used): -% autofocus={name,name,name} -> min/max -% flowsets -% autoscaling (bodyfontsteps) -% comment -% overlay -% -% todo: -% \useFLOWchart[name][parent][setting,setting][additional settings] -% \useFLOWchart[name][parent][additional settings] -% setups -% mp instance with less files - -\registerctxluafile{m-flow}{} - -\unprotect - -% todo: figure out a nice way to define the lot: share current and -% support current as name (nb: we need to set parent then) - -\def\??flch{@@flch} % chart -\def\??flln{@@flln} % line -\def\??flsh{@@flsh} % shape -\def\??flfc{@@flfc} % focus -\def\??flst{@@flst} % sets -\def\??flsp{@@flsp} % split - -\installsimplecommandhandler \??flch {FLOWchart} \??flch -\installsimplecommandhandler \??flln {FLOWline} \??flln -\installsimplecommandhandler \??flsh {FLOWshape} \??flsh -\installsimplecommandhandler \??flfc {FLOWfocus} \??flfc -\installsimplecommandhandler \??flst {FLOWsets} \??flst -\installsimplecommandhandler \??flsp {FLOWsplit} \??flsp - -\let\setupFLOWcharts\setupFLOWchart -\let\setupFLOWlines \setupFLOWline -\let\setupFLOWshapes\setupFLOWshape -\let\setupFLOWsets \setupFLOWset - -\setupFLOWcharts - [\c!width=12\bodyfontsize, - \c!height=7\bodyfontsize, - \c!offset=0pt, % \v!standard, % == auto offset - \c!dx=2\bodyfontsize, - \c!dy=2\bodyfontsize, - \c!nx=0, - \c!ny=0, - \c!x=1, - \c!y=1, - % \c!maxwidth=, - % \c!maxheight=, - % \c!option=, - % \c!bodyfont=, - % \c!dot=, % private option - % \c!autofocus=, - % \c!focus=, - % \c!background=, - % \c!framecolor= - % \c!backgroundcolor=, % \s!white - \c!rulethickness=\linewidth, - \c!frame=\v!off] - -\setupFLOWlines - [\c!corner=\v!round, - \c!arrow=\v!yes, - \c!dash=\v!no, - \c!radius=.375\bodyfontsize, - \c!color=FLOWlinecolor, - \c!rulethickness=.15\bodyfontsize, - \c!offset=\v!none] - -\setupFLOWshapes - [\c!default=action, - \c!framecolor=FLOWframecolor, - \c!background=\v!color, - \c!backgroundcolor=FLOWbackgroundcolor, - \c!rulethickness=.15\bodyfontsize, - \c!offset=.5\bodyfontsize] - -\setupFLOWfocus - [\c!framecolor=FLOWfocuscolor, - \c!background=\FLOWshapeparameter\c!background, - \c!backgroundcolor=\FLOWshapeparameter\c!backgroundcolor, - \c!backgroundscreen=\FLOWshapeparameter\c!backgroundscreen, - \c!rulethickness=\FLOWshapeparameter\c!rulethickness, - \c!offset=\FLOWshapeparameter\c!offset] - -\setupFLOWsplit - [\c!state=\v!stop, - \c!marking=\v!on, - % \c!command=, - % \c!before=, - % \c!after=, - \c!nx=3, - \c!ny=3] - -\definecolor [FLOWfocuscolor] [s=.2] -\definecolor [FLOWlinecolor] [s=.5] -\definecolor [FLOWframecolor] [s=.7] -\definecolor [FLOWbackgroundcolor] [s=.9] - -\newtoks\everyFLOWchart - -\unexpanded\def\startFLOWchart - {\startnointerference - \the\everyFLOWchart - \dosingleempty\start_FLOW_chart} - -\unexpanded\def\start_FLOW_chart[#name]% - {\ctxcommand{flow_start_chart("#name")}} - -\unexpanded\def\stopFLOWchart - {\ctxcommand{flow_stop_chart()}% - \stopnointerference} - -\unexpanded\def\defineFLOWchart % for old times sake - {\dodoubleempty\define_FLOW_chart} - -\unexpanded\def\define_FLOW_chart[#name][#settings]#cells% todo: save settings - {\startnointerference - \the\everyFLOWchart - \ctxcommand{flow_start_chart("#name")}% - #cells% - \ctxcommand{flow_stop_chart()}% - \stopnointerference} - -\unexpanded\def\startFLOWcell - {\dodoubleempty\start_FLOW_cell} - -\unexpanded\def\start_FLOW_cell[#1][#2]% - {\begingroup - \iffirstargument - \setupFLOWshape[#1]% - \fi - \ifsecondargument - \setupFLOWline[#2]% - \fi - \ctxcommand{flow_start_cell { - shape = { - rulethickness = \number\dimexpr\FLOWshapeparameter\c!rulethickness, - default = "\FLOWshapeparameter\c!default", - framecolor = "\FLOWshapeparameter\c!framecolor", - backgroundcolor = "\FLOWshapeparameter\c!backgroundcolor", - }, - focus = { - rulethickness = \number\dimexpr\FLOWfocusparameter\c!rulethickness, - framecolor = "\FLOWfocusparameter\c!framecolor", - backgroundcolor = "\FLOWfocusparameter\c!backgroundcolor", - }, - line = { - rulethickness = \number\dimexpr\FLOWlineparameter\c!rulethickness, - radius = \number\dimexpr\FLOWlineparameter\c!radius, - color = "\FLOWlineparameter\c!color", - corner = "\FLOWlineparameter\c!corner", - dash = "\FLOWlineparameter\c!dash", - arrow = "\FLOWlineparameter\c!arrow", - offset = "\FLOWlineparameter\c!offset", - }, - } }% - \endgroup} - -\unexpanded\def\stopFLOWcell - {\ctxcommand{flow_stop_cell()}} - -\unexpanded\def\FLOWchart - {\dodoubleempty\FLOW_chart} - -\def\FLOW_chart[#name][#settings]% - {\vbox\bgroup - \insidefloattrue - \dontcomplain - \setupFLOWchart[#settings]% - \ctxcommand{flow_make_chart { - chart = { - name = "#name", - option = "\FLOWchartparameter\c!option", - backgroundcolor = "\FLOWchartparameter\c!backgroundcolor", - width = \number\dimexpr\FLOWchartparameter\c!width, - height = \number\dimexpr\FLOWchartparameter\c!height, - dx = \number\dimexpr\FLOWchartparameter\c!dx, - dy = \number\dimexpr\FLOWchartparameter\c!dy, - offset = \number\dimexpr\FLOWchartparameter\c!offset, - bodyfont = "\FLOWchartparameter\c!bodyfont", - dot = "\FLOWchartparameter\c!dot", % private option - }, - shape = { - rulethickness = \number\dimexpr\FLOWshapeparameter\c!rulethickness, - default = "\FLOWshapeparameter\c!default", - framecolor = "\FLOWshapeparameter\c!framecolor", - backgroundcolor = "\FLOWshapeparameter\c!backgroundcolor", - }, - focus = { - rulethickness = \number\dimexpr\FLOWfocusparameter\c!rulethickness, - framecolor = "\FLOWfocusparameter\c!framecolor", - backgroundcolor = "\FLOWfocusparameter\c!backgroundcolor", - }, - line = { - rulethickness = \number\dimexpr\FLOWlineparameter\c!rulethickness, - radius = \number\dimexpr\FLOWlineparameter\c!radius, - color = "\FLOWlineparameter\c!color", - corner = "\FLOWlineparameter\c!corner", - dash = "\FLOWlineparameter\c!dash", - arrow = "\FLOWlineparameter\c!arrow", - offset = "\FLOWlineparameter\c!offset", - }, - set = { - }, - split = { - state = "\FLOWsplitparameter\c!state", - nx = \number\FLOWsplitparameter\c!nx, - ny = \number\FLOWsplitparameter\c!ny, - command = "", - marking = "\FLOWsplitparameter\c!marking", - before = "", - after = "", - } - } }% - \egroup} - -\unexpanded\def\FLOWcharts - {\dodoubleempty\FLOW_charts} - -\def\FLOW_charts[#name][#settings] - {\begingroup - \setupFLOWsplit[\c!state=\v!start,#settings]% - \FLOW_chart[#name][]% - \endgroup} - -\appendtoks - \let\name \FLOW_name - \let\shape \FLOW_shape - \let\destination\FLOW_destination - \let\focus \FLOW_focus - \let\overlay \FLOW_overlay - \let\location \FLOW_location - \let\text \FLOW_text - \let\label \FLOW_label - \let\comment \FLOW_comment - \let\exit \FLOW_exit - \let\connection \FLOW_connection - \let\include \FLOW_include - \let\figure \FLOW_figure - % - \let\connect \FLOW_connection - \let\locate \FLOW_location - % - \let\includeFLOWchart\include -\to \everyFLOWchart - -\unexpanded\def\FLOW_name #name{\ctxcommand{flow_set_name("#name")}\ignorespaces} -\unexpanded\def\FLOW_shape #shape{\ctxcommand{flow_set_shape("#shape")}\ignorespaces} -\unexpanded\def\FLOW_destination #destination{\ctxcommand{flow_set_destination("#destination")}\ignorespaces} -\unexpanded\def\FLOW_focus #focus{\ctxcommand{flow_set_focus("#focus")}\ignorespaces} -\unexpanded\def\FLOW_overlay #overlay{\ctxcommand{flow_set_overlay("#overlay")}\ignorespaces} -\unexpanded\def\FLOW_location #location{\ctxcommand{flow_set_location("#location")}\ignorespaces} -\unexpanded\def\FLOW_figure #figure{\ctxcommand{flow_set_figure("#figure")}\ignorespaces} - -\unexpanded\def\FLOW_text {\dosingleempty\do_FLOW_text} -\unexpanded\def\FLOW_label {\dosingleempty\do_FLOW_label} -\unexpanded\def\FLOW_comment {\dosingleempty\do_FLOW_commment} -\unexpanded\def\FLOW_exit {\dosingleempty\do_FLOW_exit} -\unexpanded\def\FLOW_connection {\dodoubleempty\do_FLOW_connection} -\unexpanded\def\FLOW_include {\dodoubleempty\do_FLOW_include} - -\unexpanded\def\do_FLOW_text [#align]#text{\ctxcommand{flow_set_text("#align",\!!bs\detokenize{#text}\!!es)}\ignorespaces} -\unexpanded\def\do_FLOW_label [#location]#text{\ctxcommand{flow_set_label("#location",\!!bs\detokenize{#text}\!!es)}\ignorespaces} -\unexpanded\def\do_FLOW_comment [#location]#text{\ctxcommand{flow_set_comment("#location",\!!bs\detokenize{#text}\!!es)}\ignorespaces} -\unexpanded\def\do_FLOW_exit [#location]#text{\ctxcommand{flow_set_exit("#location",\!!bs\detokenize{#text}\!!es)}\ignorespaces} -\unexpanded\def\do_FLOW_connection[#location][#offset]#name{\ctxcommand{flow_set_connection("#location","#offset","#name")}\ignorespaces} - -\unexpanded\def\do_FLOW_include [#name][#settings]{% - \begingroup - \getparameters[FLOWi][x=1,y=1,#settings]% - \ctxcommand{flow_set_include("#name",\number\FLOWix,\number\FLOWiy,\!!bs\detokenize{#settings}\!!es)}% - \endgroup - \ignorespaces -} - -\setvariables - [flowcell:text] - [x=1, - y=1, - text=, - align=, - set=\setups{flowcell:text:place}] - -% \c!background={\@@FLOWbackground,\FLOWoverlay}, - -\defineoverlay - [flowcell:figure] - [\overlayfigure{\getvariable{flowcell:text}{figure}}] - -\startsetups flowcell:text:place - \begingroup - \iftrialtypesetting - \directsetup{flowcell:text:place:indeed} - \else \iflocation - \doifelsenothing {\getvariable{flowcell:text}{destination}} { - \directsetup{flowcell:text:place:indeed} - } { - % tricky: scaling and moving around is not taken into account - \setupinteraction[\c!color=,\c!contrastcolor=] - \gotobox{\directsetup{flowcell:text:place:indeed}}[\getvariable{flowcell:text}{destination}] - } - \else - \directsetup{flowcell:text:place:indeed} - \fi \fi - \endgroup -\stopsetups - -\startsetups flowcell:text:place:indeed - \begingroup - \directsetup{flowcell:text:user} - \doifelsenothing {\getvariable{flowcell:text}{figure}} { - \doframed - [flowcell:\getvariable{flowcell:text}{align}] - {\getvariable{flowcell:text}{text}} - } { - \doframed - [flowcell:\getvariable{flowcell:text}{align}] - [background=flowcell:figure] - {\getvariable{flowcell:text}{text}} - } - \endgroup -\stopsetups - -\defineframed % to be discussed: shape or global - [flowcell:base] - [\c!offset=\v!overlay, % no strut ? - \c!frame=\FLOWchartparameter\c!frame, - \c!background=\FLOWchartparameter\c!background, - \c!backgroundcolor=\FLOWchartparameter\c!backgroundcolor, - %\c!foregroundcolor=\FLOWshapeparameter\c!foregroundcolor, - \c!align=\v!middle, - \c!bottom=\vfill, - \c!top=\vfill, - \c!width=\FLOWchartparameter\c!width, - \c!height=\FLOWchartparameter\c!height, - % \c!rulethickness=\FLOWchartparameter\c!rulethickness, - \c!rulethickness=\zeropoint, % comment for tracing - \c!framecolor=\FLOWchartparameter\c!framecolor] - -\defineframed[flowcell:] [flowcell:base] -\defineframed[flowcell:l] [flowcell:base][\c!align=\v!flushleft] -\defineframed[flowcell:r] [flowcell:base][\c!align=\v!flushright] -\defineframed[flowcell:m] [flowcell:base][\c!align=\v!middle] -\defineframed[flowcell:c] [flowcell:base][\c!align=\v!middle] - -\defineframed[flowcell:t] [flowcell:base][\c!top=] -\defineframed[flowcell:b] [flowcell:base][\c!bottom=] - -\defineframed[flowcell:lt][flowcell:base][\c!top=,\c!align=\v!flushleft] -\defineframed[flowcell:rt][flowcell:base][\c!top=,\c!align=\v!flushright] -\defineframed[flowcell:mt][flowcell:base][\c!top=,\c!align=\v!middle] -\defineframed[flowcell:ct][flowcell:base][\c!top=,\c!align=\v!middle] - -\defineframed[flowcell:lb][flowcell:base][\c!bottom=,\c!align=\v!flushleft] -\defineframed[flowcell:rb][flowcell:base][\c!bottom=,\c!align=\v!flushright] -\defineframed[flowcell:mb][flowcell:base][\c!bottom=,\c!align=\v!middle] -\defineframed[flowcell:cb][flowcell:base][\c!bottom=,\c!align=\v!middle] - -% todo: each cell its own setup -% -% \startsetups flowcell -% \definelayer -% [flowcell] -% [width=\FLOWshapewidth, -% height=\FLOWshapeheight] -% \setlayerframed -% [flowcell] -% [preset=rightbottom,offset=1ex] -% [frame=off] -% {\tx(\FLOWx,\FLOWy)} -% \stopsetups - -%D \starttyping -%D \setupFLOWsplit -%D [nx=5,ny=10, -%D dx=0,dy=0, -%D before=, -%D after=\page] -%D -%D \FLOWcharts[mybigflow] -%D \stoptyping -%D -%D \starttyping -%D \splitfloat -%D {\placefigure{What a big flowchart this is!}} -%D {\FLOWcharts[mybigflow]} -%D \stoptyping - -\protect - -\continueifinputfile{m-flow.mkvi} - -\input chrt-xml.tex - -\usemodule[abr-01] - -\setupFLOWcharts[option=test] -\setupFLOWcharts[frame=on] -\setupinteraction[state=start] - -% \setupFLOWcharts[dx=30pt,dy=30pt] - -\startMPinclusions - predefined_shapes[101] := fullcircle ; -\stopMPinclusions - -\startFLOWchart[demo] - \startFLOWcell[framecolor=darkgray] - \name {start} - \location {1,1} - \shape {action} - \text {start} - \connection [bl] {one} - \stopFLOWcell - \startFLOWcell - \name {one} -% \destination{CloseDocument} - \location {2,2} -% \shape {action} - \shape {101} - \text {first} -% \label [b] {\bfx bottom} - \connection [rt] {two} -% \exit [l] {exit l} -% \exit [r] {exit r} -% \exit [t] {exit t} -% \exit [b] {exit b} - \stopFLOWcell - \setupFLOWshapes[framecolor=darkgray] - \startFLOWcell % [foregroundcolor=white] - \name {two} -% \destination{CloseDocument} - \location {3,3} - \shape {action} - \text {second} - \figure {cow.pdf} -% \label [l] {\bfx left} -% \exit [l] {exit l} -% \exit [r] {exit r} -% \exit [t] {exit t} -% \exit [b] {exit b} - \stopFLOWcell -\stopFLOWchart - -\starttext - -\startTEXpage -% \FLOWchart[convert-en] -% \FLOWchart[conversion 1] -% \FLOWchart[conversion 7] -% \FLOWchart[conversion 9] -% \FLOWchart[conversion 10] - \FLOWchart[demo] - -\stopTEXpage - -\startTEXpage - \FLOWchart[conversion 10] -\stopTEXpage - -\stoptext diff --git a/tex/context/base/m-steps.lua b/tex/context/base/m-steps.lua new file mode 100644 index 000000000..97759b799 --- /dev/null +++ b/tex/context/base/m-steps.lua @@ -0,0 +1,227 @@ +if not modules then modules = { } end modules ['x-flow'] = { + version = 1.001, + comment = "companion to m-flow.mkvi", + author = "Hans Hagen, PRAGMA-ADE, Hasselt NL", + copyright = "PRAGMA ADE / ConTeXt Development Team", + license = "see context related readme files" +} + +-- when we can resolve mpcolor at the lua end we will use metapost.graphic(....) directly + +moduledata.steps = moduledata.steps or { } + +local points = number.points -- number.pt +local variables = interfaces.variables + +local trace_charts = false + +local defaults = { + chart = { + dx = 10*65436, + dy = 10*65436, + }, + cell = { + alternative = 1, + offset = 2*65436, + rulethickness = 65436, + framecolor = "blue", + backgroundcolor = "gray", + }, + text = { + alternative = 1, + offset = 2*65436, + distance = 4*65436, + rulethickness = 65436, + framecolor = "red", + backgroundcolor = "gray", + }, + line = { + alternative = 1, + rulethickness = 65436, + height = 30*65436, + distance = 10*65436, + offset = 5*65436, + color = "green", + }, +} + +-- todo : name (no name then direct) +-- maybe: includes +-- maybe: flush ranges + +local charts = { } +local steps = { } + +function commands.step_start_chart(name) + name = name or "" + steps = { } + charts[name] = { + steps = steps, + } +end + +function commands.step_stop_chart() +end + +function commands.step_make_chart(settings) + local chartsettings = settings.chart + if not chartsettings then + print("no chart") + return + end + local chartname = chartsettings.name + if not chartname then + print("no name given") + return + end + local chart = charts[chartname] + if not chart then + print("no such chart",chartname) + return + end + local steps = chart.steps or { } + -- + table.setmetatableindex(settings,defaults) + -- + if trace_charts then + inspect(steps) + end + -- + local textsettings = settings.text + local cellsettings = settings.cell + local linesettings = settings.line + -- + context.startMPcode() + context("if unknown context_cell : input mp-step.mpiv ; fi ;") + context("step_begin_chart ;") + -- + if chartsettings.alternative == variables.vertical then + context("chart_vertical := true ;") + end + -- + context("text_line_color := \\MPcolor{%s} ;", textsettings.framecolor) + context("text_line_width := %s ;", points(textsettings.rulethickness)) + context("text_fill_color := \\MPcolor{%s} ;", textsettings.backgroundcolor) + context("text_offset := %s ;", points(textsettings.offset)) + context("text_distance_set := %s ;", points(textsettings.distance)) + -- + context("cell_line_color := \\MPcolor{%s} ;", cellsettings.framecolor) + context("cell_line_width := %s ;", points(cellsettings.rulethickness)) + context("cell_fill_color := \\MPcolor{%s} ;", cellsettings.backgroundcolor) + context("cell_offset := %s ;", points(cellsettings.offset)) + context("cell_distance_x := %s ;", points(cellsettings.dx)) + context("cell_distance_y := %s ;", points(cellsettings.dy)) + -- + context("line_line_color := \\MPcolor{%s} ;", linesettings.color) + context("line_line_width := %s ;", points(linesettings.rulethickness)) + context("line_distance := %s ;", points(linesettings.distance)) + context("line_offset := %s ;", points(linesettings.offset)) + -- + for i=1,#steps do + local step = steps[i] + context("step_begin_cell ;") + if step.cell_top ~= "" then + context('step_cell_top("%s") ;',string.strip(step.cell_top)) + end + if step.cell_bot ~= "" then + context('step_cell_bot("%s") ;',string.strip(step.cell_bot)) + end + if step.text_top ~= "" then + context('step_text_top("%s") ;',string.strip(step.text_top)) + end + if step.text_mid ~= "" then + context('step_text_mid("%s") ;',string.strip(step.text_mid)) + end + if step.text_bot ~= "" then + context('step_text_bot("%s") ;',string.strip(step.text_bot)) + end + context("step_end_cell ;") + end + -- + context("step_end_chart ;") + context.stopMPcode() +end + +function commands.step_cells(top,bot) + steps[#steps+1] = { + cell_top = top or "", + cell_bot = bot or "", + text_top = "", + text_mid = "", + text_bot = "", + } +end + +function commands.step_texts(top,bot) + if #steps > 0 then + steps[#steps].text_top = top or "" + steps[#steps].text_bot = bot or "" + end +end + +function commands.step_cell(top) + steps[#steps+1] = { + cell_top = top or "", + cell_bot = "", + text_top = "", + text_mid = "", + text_bot = "", + } +end + +function commands.step_text(top) + if #steps > 0 then + steps[#steps].text_top = top or "" + end +end + +function commands.step_textset(left,middle,right) + if #steps > 0 then + steps[#steps].text_top = left or "" + steps[#steps].text_mid = middle or "" + steps[#steps].text_bot = right or "" + end +end + +function commands.step_start_cell() + steps[#steps+1] = { + cell_top = "", + cell_bot = "", + text_top = "", + text_mid = "", + text_bot = "", + } +end + +function commands.step_stop_cell() +end + +function commands.step_text_top(str) + if #steps > 0 then + steps[#steps].text_top = str or "" + end +end + +function commands.step_text_mid(str) + if #steps > 0 then + steps[#steps].text_mid = str or "" + end +end + +function commands.step_text_bot(str) + if #steps > 0 then + steps[#steps].text_bot = str or "" + end +end + +function commands.step_cell_top(str) + if #steps > 0 then + steps[#steps].cell_top = str or "" + end +end + +function commands.step_cell_bot(str) + if #steps > 0 then + steps[#steps].cell_bot = str or "" + end +end diff --git a/tex/context/base/m-steps.mkii b/tex/context/base/m-steps.mkii new file mode 100644 index 000000000..e6bd45548 --- /dev/null +++ b/tex/context/base/m-steps.mkii @@ -0,0 +1,837 @@ +%D \module +%D [ file=m-steps, +%D version=2001.05.28, +%D title=\CONTEXT\ Modules, +%D subtitle=Step Charts \& Tables, +%D author=Hans Hagen, +%D date=\currentdate, +%D copyright={PRAGMA ADE \& \CONTEXT\ Development Team}] +%C +%C This module is part of the \CONTEXT\ macro||package and is +%C therefore copyrighted by \PRAGMA. See mreadme.pdf for +%C details. + +%D When I need this module, I will reimplement it by using the new +%D sometxt macro. Anyhow, it reflects the state of 2001. + +\unprotect + +% temp hack : + +% \ifx\v!kleinkorps\undefined \let\v!kleinkorps\setsmallbodyfont \fi + +% end of hack + +\definecolor [STEPlinecolor] [s=.5] +\definecolor [STEPframecolor] [s=.7] +\definecolor [STEPbackgroundcolor] [s=.9] + +\def\@@STPF{@@STPF} % frames + +\def\@@STPC{@@STPC} % charts +\def\@@STPT{@@STPT} % tables + +\def\@@STEC{@@STEC} % cells +\def\@@STET{@@STET} % tables +\def\@@STEL{@@STEL} % lines + +\def\setupSTEPcharts{\dodoubleargument\getparameters[\@@STPC]} +\def\setupSTEPtables{\dodoubleargument\getparameters[\@@STPT]} +\def\setupSTEPcells {\dodoubleargument\getparameters[\@@STEC]} +\def\setupSTEPtexts {\dodoubleargument\getparameters[\@@STET]} +\def\setupSTEPlines {\dodoubleargument\getparameters[\@@STEL]} + +\setupSTEPcharts + [\c!before=\blank, + \c!after=\blank, + %\c!distance=.25em, % nvt + \c!hoffset=1em, + \c!voffset=1ex, + \c!method=1, + \c!height=2ex, + \c!offset=.15\bodyfontsize] + +\setupSTEPtables + [\c!before=\blank, + \c!after=\blank, + \c!distance=.25em, + %\c!hoffset=1em, % nvt + \c!voffset=1ex, + \c!method=1, + \c!width=4em, + \c!offset=.15\bodyfontsize] + +\setupSTEPcells + [\c!alternative=24, + \c!background=\v!color, + \c!backgroundcolor=STEPbackgroundcolor, + \c!rulethickness=.1\bodyfontsize, + \c!framecolor=STEPframecolor, + \c!offset=.25\bodyfontsize, + \c!style=, + \c!color=] + +\setupSTEPtexts + [\c!alternative=24, + \c!background=\v!color, + \c!backgroundcolor=STEPbackgroundcolor, + \c!rulethickness=.1\bodyfontsize, + \c!framecolor=STEPframecolor, + \c!offset=.25\bodyfontsize, + \c!style=\v!smallbodyfont, + \c!color=] + +\setupSTEPlines + [\c!alternative=1, + \c!rulethickness=.15\bodyfontsize, + \c!color=STEPlinecolor] + +\def\initializeSTEP + {\initializeSTET \initializeSTEC \initializeSTEL} + +\def\initializeSTPC + {\freezedimenmacro\@@STPCoffset + \startMPdrawing + line_v_offset := \@@STPCoffset ; + line_method := \@@STPCmethod ; % only charts + \stopMPdrawing} + +\def\initializeSTPT + {\freezedimenmacro\@@STPToffset + \startMPdrawing + line_h_offset := \@@STPToffset ; + line_method := \@@STPTmethod ; % only charts + \stopMPdrawing} + +\def\initializeSTET + {\freezedimenmacro\@@STETrulethickness + \freezedimenmacro\@@STEToffset} + +\def\initializeSTEC + {\freezedimenmacro\@@STECrulethickness + \freezedimenmacro\@@STECoffset} + +\def\initializeSTEL + {\freezedimenmacro\@@STELrulethickness} + +%D ... + +\presetlocalframed[\@@STPF] + +\def\@@stepcell#1% + {\doattributes\@@STEC\c!style\c!color + {\localframed + [\@@STPF][\c!offset=\@@STECoffset,\c!frame=\v!off] + {\ignorespaces#1\unskip}}} + +\def\@@stepfake#1% + {\doattributes\@@STEC\c!style\c!color + {\ignorespaces#1\unskip}} + +\def\@@steptext#1% + {\doattributes\@@STET\c!style\c!color + {\localframed + [\@@STPF][\c!offset=\@@STEToffset,\c!frame=\v!off] + {\ignorespaces#1\unskip}}} + +%D The first attempt was purely \METAPOST\ based and spawned +%D the typesetting to the \METAFUN\ handler. This method +%D collects the cells, and directly passes them on to +%D \METAPOST. This method is the cleanest, but has the +%D disadvantage that one cannot embed hyperlinks or document +%D dependent definitions in the cells. The implementation +%D roughly looks as follows: +%D +%D \starttyping +%D \def\startSTEPchart% +%D {\bgroup +%D \startMPdrawing +%D input mp-step.mpii ; begin_step_chart ; +%D \stopMPdrawing +%D \initializeSTEP +%D \let\cells\stepchartcells \def\cell{\cells{}}% +%D \let\texts\stepcharttexts \def\text{\texts{}}} +%D +%D \def\stepchartcells#1#2% +%D {\setMPtext{tdummy}{\strut\ignorespaces#1\unskip}% beter etex/btex +%D \setMPtext{bdummy}{\strut\ignorespaces#2\unskip}% beter etex/btex +%D \startMPdrawing +%D set_step_chart_cells(\MPstring{tdummy},\MPstring{bdummy}) ; +%D \stopMPdrawing} +%D +%D \def\stepcharttexts#1#2% +%D {\setMPtext{tdummy}{\strut\ignorespaces#1\unskip}% beter etex/btex +%D \setMPtext{bdummy}{\strut\ignorespaces#2\unskip}% beter etex/btex +%D \startMPdrawing +%D set_step_chart_texts(\MPstring{tdummy},\MPstring{bdummy}) ; +%D \stopMPdrawing} +%D +%D \def\stopSTEPchart +%D {\startMPdrawing +%D end_step_chart ; +%D \stopMPdrawing +%D \MPdrawingdonetrue +%D \getMPdrawing +%D \resetMPdrawing +%D \egroup} +%D \stoptyping +%D +%D This method has the advantage that it does the job in +%D (virtually) one pass, while the next methods need multiple +%D passes: one to build the table, another to synchronize the +%D positions, and a third one beause the dimensions may have +%D changed. The last pass is a result from the fact that +%D positions are related to the page. +%D +%D The second attempt was based on tabulations and used the +%D build in position tracking mechanism, which uses two +%D position nodes per cell. +%D +%D This method collects the content in token list registers +%D and build a table from them. In the collecting pass, the +%D graphics are build stepwise. We need to collect because the +%D order of definitions is not the same as the order of +%D typesetting. We show this alternative too because it +%D demonstrates how to apply backgrounds to table cells. +%D +%D \starttyping +%D \newtoks\stepsonetop \newtoks\stepstwotop +%D \newtoks\stepsonebot \newtoks\stepstwobot +%D \stoptyping +%D +%D During the collecting phase, we temporarily have to +%D increment the name space counter. +%D +%D \starttyping +%D \def\startSTEPchart% +%D {\bgroup +%D \resetMPdrawing +%D \advance\noftabpositions\plusone % begin of preroll +%D \startMPdrawing +%D input mp-step.mpii ; +%D begin_step_chart ; +%D \stopMPdrawing +%D \initializeSTEP +%D \newcounter\cellcounter +%D \stepsonetop\emptytoks \chardef\somesteponetop=1 +%D \stepsonebot\emptytoks \chardef\somesteponebot=1 +%D \stepstwotop\emptytoks \chardef\somesteptwotop=1 +%D \stepstwobot\emptytoks \chardef\somesteptwobot=1 +%D \let\cells\stepchartcells \def\cell{\cells{}}% +%D \let\texts\stepcharttexts \def\text{\texts{}}} +%D \stoptyping +%D +%D Now we collect the steps and texts, and in the process the +%D graphic is built. Then we continue with building the table. +%D +%D Watch how we anchor the graphic to the main table box. This +%D is needed since the graphic may be larger than the table +%D itself. Actually, these small point took me the most time to +%D digest, even with the right tools (anchors) already in +%D place. +%D +%D \starttyping +%D \def\stopSTEPchart +%D {\splittabulatefalse +%D \insidefloattrue +%D \startMPdrawing +%D nofcells := \cellcounter ; +%D end_step_chart ; +%D anchor_box(\MPpos{\tbPOSprefix origin}) ; +%D \stopMPdrawing +%D \MPdrawingdonetrue +%D \advance\noftabpositions\minusone % end of preroll +%D \setbox0=\vbox +%D {\getMPdrawing} +%D \resetMPdrawing +%D \increment(\cellcounter,\cellcounter)\decrement\cellcounter +%D \setbox2=\vbox +%D {\definetabulate[chart][|*{\cellcounter}{ck0|}] % k0 nills space +%D \startchart +%D \ifcase\somesteptwotop \the\stepstwotop \NC \NR \noalign{\kern2ex} \fi +%D \ifcase\somesteponetop \the\stepsonetop \NC \NR \noalign{\kern2ex} \fi +%D \ifcase\somesteponebot \the\stepsonebot \NC \NR \noalign{\kern2ex} \fi +%D \ifcase\somesteptwobot \the\stepstwobot \NC \NR \noalign{\kern2ex} \fi +%D \noalign{\kern-2ex}% +%D \stopchart} +%D \hbox +%D {\scratchdimen\wd0 +%D \advance\scratchdimen \MPllx bp +%D \raise\MPlly bp\box0 +%D \hskip-\scratchdimen +%D \hpos{\tbPOSprefix origin}{\box2}} +%D \egroup} +%D \stoptyping +%D +%D The steps and texts fill the (at most 4) lines that make up +%D the table. We also feed the (automatically registerd) cell +%D dimensions to the graphic backend. +%D +%D \starttyping +%D \newcounter\cellcounter +%D \newcounter\textcounter +%D +%D \def\stepchartcells#1#2% +%D {\doloop +%D {\ifnum\cellcounter>\textcounter +%D \stepcharttexts{}{}% +%D \else +%D \exitloop +%D \fi}% +%D \increment\cellcounter +%D \doifelsenothing{#1} +%D {\startMPdrawing +%D cells[t][\cellcounter] := origin ; +%D \stopMPdrawing +%D \appendtoks\NC\NC\to\stepsonetop} +%D {\chardef\somesteponetop=0 +%D \edef\stepidentifier{\cellcounter-t-c}% +%D \startMPdrawing +%D initialize_area(\MPpos{b:\tbPOSprefix\stepidentifier}, +%D \MPpos{e:\tbPOSprefix\stepidentifier}) ; +%D cells[t][\cellcounter] := pxy ; +%D \stopMPdrawing +%D \@EA\appendtoks\@EA\stepidentifierposition\@EA{\stepidentifier}#1\NC\to\stepsonetop}% +%D \doifelsenothing{#2} +%D {\startMPdrawing +%D cells[b][\cellcounter] := origin ; +%D \stopMPdrawing +%D \appendtoks\NC\NC\to\stepsonebot} +%D {\chardef\somesteponebot=0 +%D \edef\stepidentifier{\cellcounter-b-c}% +%D \startMPdrawing +%D initialize_area(\MPpos{b:\tbPOSprefix\stepidentifier}, +%D \MPpos{e:\tbPOSprefix\stepidentifier}) ; +%D cells[b][\cellcounter] := pxy ; +%D \stopMPdrawing +%D \@EA\appendtoks\@EA\stepidentifierposition\@EA{\stepidentifier}#2\NC\to\stepsonebot}} +%D +%D \def\stepcharttexts#1#2% \cellcounter = nofcells +%D {\increment\textcounter +%D \doifelsenothing{#1} +%D {\startMPdrawing +%D texts[t][\cellcounter][\textcounter] := origin ; +%D \stopMPdrawing +%D \appendtoks\NC\NC\to\stepstwotop} +%D {\chardef\somesteptwotop=0 +%D \edef\stepidentifier{\cellcounter-\textcounter-t-t}% +%D \startMPdrawing +%D initialize_area(\MPpos{b:\tbPOSprefix\stepidentifier}, +%D \MPpos{e:\tbPOSprefix\stepidentifier}) ; +%D texts[t][\cellcounter][\textcounter] := pxy ; +%D \stopMPdrawing +%D \@EA\appendtoks\@EA\NC\@EA\textcellposition\@EA{\stepidentifier}#1\to\stepstwotop}% +%D \doifelsenothing{#2} +%D {\startMPdrawing +%D texts[b][\cellcounter][\textcounter] := origin ; +%D \stopMPdrawing +%D \appendtoks\NC\NC\to\stepstwobot} +%D {\chardef\somesteptwobot=0 +%D \edef\stepidentifier{\cellcounter-\textcounter-b-t}% +%D \startMPdrawing +%D initialize_area(\MPpos{b:\tbPOSprefix\stepidentifier}, +%D \MPpos{e:\tbPOSprefix\stepidentifier}) ; +%D texts[b][\cellcounter][\textcounter] := pxy ; +%D \stopMPdrawing +%D \@EA\appendtoks\@EA\NC\@EA\textcellposition\@EA{\stepidentifier}#2\to\stepstwobot}} +%D \stoptyping +%D +%D Here are the hooks that take care of calculating the cell +%D dimensions. +%D +%D \starttyping +%D \def\textcellposition#1{\GSC[#1:text]} +%D \def\stepidentifierposition#1{\GSC[#1:step]} +%D \stoptyping +%D +%D We abandoned this method after some testing and went for +%D a third one. It was this third method that evolved into the +%D current mechanism. +%D +%D Since this method was not that efficient, a third one was +%D implemented, which used one position per cell. So, +%D +%D \blank {\bf Here starts the real implementation!} \blank +%D +%D Because we want to build one graphic only we need to store +%D the graphic directives. We also need to collect the cells, +%D which are not defined in the order they show up. This +%D solution uses multiple passes over the definitions. First +%D the cells and texts are processed and the associated +%D graphics are defined in the \METAPOST\ file. Next the +%D lines are flushed. We need to do that in a second pass, +%D because in order to determine the nature of the line, +%D \METAPOST\ needs to know if the start and end cells exist. +%D This need comes from the fact that we store the shapes +%D and lines kind of directly with their associated colors and +%D types, so that we can change the settings in between. So, +%D changing for instance the line color, can take place +%D locally. + +\newbox\stepboxone \newbox\stepboxtwo +\newbox\textboxone \newbox\textboxtwo + +%D We need to define a dedicated name space counter. + +\newcounter\currentstepchart + +\def\stepchartprefix{@sc@-\currentstepchart-} + +%D Next we define the initialization part of the macros. + +\newcounter\cellcounter +\newcounter\textcounter + +\def\startSTEPchart + {\dosingleempty\dostartSTEPchart} + +\long\def\dostartSTEPchart[#1]#2\stopSTEPchart + {\ifinsidefloat + \else + \whitespace + \@@STPCbefore + \startbaselinecorrection + \setlocalhsize + \noindent + \fi + \vbox\bgroup + \setupSTEPcharts[#1]% + \forgetall + \pushMPdrawing + \resetMPdrawing + \doglobal\increment\currentstepchart + \startMPdrawing + input mp-step.mpii ; + begin_step_chart ; + \stopMPdrawing + \initializeSTEP + \initializeSTPC + \global\chardef\somestepboxone\plusone + \global\chardef\sometextboxone\plusone + \global\chardef\somestepboxtwo\somestepboxone + \global\chardef\sometextboxtwo\sometextboxone + \def\startlines{\bgroup\setupSTEPlines}% + \def\stoplines {\egroup}% + \def\cells{\dosingleempty\dostepchartcells} + \def\texts{\dosingleempty\dostepcharttexts} + \def\cell {\dosingleempty\docell}% + \def\text {\dosingleempty\dotext}% + \def\docell[##1]{\dostepchartcells[##1]{}}% + \def\dotext[##1]{\dostepcharttexts[##1]{}} + \doglobal\newcounter\cellcounter + \doglobal\newcounter\textcounter + \let\dostepchartcells\doSTEPchartcellsA + \let\dostepcharttexts\doSTEPcharttextsA + {#2} % pass one: cells and texts {} keeps setting local + \startMPdrawing + nofcells := \cellcounter ; + analyze_step_chart ; + \stopMPdrawing + \doglobal\newcounter\cellcounter + \doglobal\newcounter\textcounter + \let\dostepchartcells\doSTEPchartcellsB + \let\dostepcharttexts\doSTEPcharttextsB + {#2} % pass two: lines + \startMPdrawing + end_step_chart ; + % if box_found(\MPpos{\stepchartprefix origin}) : + % initialize_box(\MPpos{\stepchartprefix origin}) ; + % draw pxy ; + % fi ; + anchor_box(\MPpos{\stepchartprefix origin}) ; + \stopMPdrawing + \MPdrawingdonetrue + \doifelse\@@STPCmethod{0} + {\setbox0\null} + {\setbox0\vbox{\MPstaticgraphictrue\getMPdrawing}}% + \resetMPdrawing + \setbox2\vbox + {\offinterlineskip + \scratchdimen\@@STPCheight + \advance\scratchdimen\@@STPCoffset + \advance\scratchdimen\@@STPCoffset + \ifcase\sometextboxone \box\textboxone \vskip\scratchdimen \fi + \ifcase\somestepboxone \box\stepboxone \vskip\@@STPCvoffset \fi + \ifcase\somestepboxtwo \box\stepboxtwo \vskip\scratchdimen \fi + \ifcase\sometextboxtwo \box\textboxtwo \vskip\@@STPCvoffset \fi + \global\setbox\stepboxone\emptybox \global\setbox\stepboxtwo\emptybox % needed indeed + \global\setbox\textboxone\emptybox \global\setbox\textboxtwo\emptybox % needed indeed + %\kern-\scratchdimen % no, instead: + \vskip-\lastskip} + \hbox + {\scratchdimen\wd0 + \advance\scratchdimen \MPllx bp + \raise\MPlly bp\box0 + \hskip-\scratchdimen + \hpos{\stepchartprefix origin}{\box2}}% + \popMPdrawing + \egroup + \ifinsidefloat \else \stopbaselinecorrection \@@STPCafter \fi} + +%D The next macro looks more complicated than it is. We collect +%D the cells in boxes. Before adding a new step cell, we padd +%D the text rows. After adding the step cells, we flush text +%D cells that are defined but not yet processed. + +\def\doSTEPchartcellsA[#1]#2#3% + {% synchronize texts + \doSTEPchartcellsAB[#1]{#2}{#3}% + % package steps + \setbox0\hbox{\doifsomething{#2}{\@@stepcell{#2}}}% + \setbox2\hbox{\doifsomething{#3}{\@@stepcell{#3}}}% + \ifdim\wd0>\zeropoint \!!doneafalse \else \!!doneatrue \fi + \ifdim\wd2>\zeropoint \!!donebfalse \else \!!donebtrue \fi + \ifdim\wd0>\wd2 + \setbox2\hbox to \wd0{\hss\box2\hss}% + \else + \setbox0\hbox to \wd2{\hss\box0\hss}% + \fi + \if!!donea + \startMPdrawing + cells[t][\cellcounter] := nullpicture ; + \stopMPdrawing + \else + \global\chardef\somestepboxone\zerocount + \edef\stepidentifier{\stepchartprefix\cellcounter-t-c}% + \setbox0\hbox{\hpos{\stepidentifier}{\box0}}% + \bgroup + \iffirstargument\setupSTEPcells[#1]\fi\initializeSTEC + \startMPdrawing + initialize_box(\MPpos{\stepidentifier}) ; + cells[t][\cellcounter] := \MPcellsgraphic ; + \stopMPdrawing + \egroup + \fi + \if!!doneb + \startMPdrawing + cells[b][\cellcounter] := nullpicture ; + \stopMPdrawing + \else + \global\chardef\somestepboxtwo\zerocount + \edef\stepidentifier{\stepchartprefix\cellcounter-b-c}% + \setbox2\hbox{\hpos{\stepidentifier}{\box2}}% + \bgroup + \iffirstargument\setupSTEPcells[#1]\fi\initializeSTEC + \startMPdrawing + initialize_box(\MPpos{\stepidentifier}) ; + cells[b][\cellcounter] := \MPcellsgraphic ; + \stopMPdrawing + \egroup + \fi + \global\setbox\stepboxone\hbox + {\ifdim\wd\stepboxone>\zeropoint + \box\stepboxone\hskip\@@STPChoffset\else + \fi\box0}% + \global\setbox\stepboxtwo\hbox + {\ifdim\wd\stepboxtwo>\zeropoint + \box\stepboxtwo\hskip\@@STPChoffset\else + \fi\box2}% + % flush saved texts + \doSTEPchartcellsBA} + +\def\doSTEPchartcellsB[#1]#2#3% + {\doSTEPchartcellsAB[#1]{#2}{#3}% + \doSTEPchartcellsBA} + +\def\doSTEPchartcellsAB[#1]#2#3% + {\doloop + {\ifnum\cellcounter>\textcounter + \texts{}{}\else\exitloop + \fi}% + \doglobal\increment\cellcounter} + +\def\doSTEPchartcellsBA + {\scratchtoks\stepchartbuffer + \stepchartbuffer\emptytoks + \the\scratchtoks} + +\def\MPcellsgraphic + {image ( drawshape ( + \@@STECalternative, pxy enlarged (-.5*\@@STECoffset), + \@@STECrulethickness, \MPcolor{\@@STECframecolor}, + \MPcolor{\@@STECbackgroundcolor} ) )} + +%D Although each step can have only one associated text, the +%D place where the text is defined determines the starting +%D point of the connecting arrow. Although several methods are +%D possible, we've chosen a funny collector that flushes one +%D step text at a time. + +\newtoks\stepchartbuffer + +\def\doSTEPcharttextsA[#1]% #2 #3 + {\dodoSTEPcharttextsA{\cellcounter}{#1}} + +\def\dodoSTEPcharttextsA#1#2#3#4% #1=number #2=setup + {\dodoSTEPcharttextsAB{#1}{#2}{#3}{#4}\dodoSTEPcharttextsA + \ifnum\textcounter>\cellcounter\relax + \doglobal\decrement\textcounter\relax + \else + \setbox0\hbox{\doifsomething{#3}{\@@steptext{#3}}}% + \setbox2\hbox{\doifsomething{#4}{\@@steptext{#4}}}% + \ifdim\wd0>\zeropoint \!!doneafalse \else \!!doneatrue \fi + \ifdim\wd2>\zeropoint \!!donebfalse \else \!!donebtrue \fi + \if!!donea + \setbox0\hbox to \@@STPChoffset{\hss}% + \startMPdrawing + texts[t][#1][\textcounter] := nullpicture ; + \stopMPdrawing + \else + \global\chardef\sometextboxone\zerocount + \edef\stepidentifier{\stepchartprefix#1-\textcounter-t-t}% + \setbox0\hbox to \@@STPChoffset + {\hss\hpos{\stepidentifier}{\box0}\hss}% + \bgroup + \setupSTEPtexts[#2]\initializeSTET + \startMPdrawing + initialize_box(\MPpos{\stepidentifier}) ; + texts[t][#1][\textcounter] := \MPtextsgraphic ; + \stopMPdrawing + \egroup + \fi + \if!!doneb + \setbox2\hbox to \@@STPChoffset{\hss}% + \startMPdrawing + texts[b][#1][\textcounter] := nullpicture ; + \stopMPdrawing + \else + \global\chardef\sometextboxtwo\zerocount + \edef\stepidentifier{\stepchartprefix#1-\textcounter-b-t}% + \setbox2\hbox to \@@STPChoffset + {\hss\hpos{\stepidentifier}{\box2}\hss}% + \bgroup + \setupSTEPtexts[#2]\initializeSTET + \startMPdrawing + initialize_box(\MPpos{\stepidentifier}) ; + texts[b][#1][\textcounter] := \MPtextsgraphic ; + \stopMPdrawing + \egroup + \fi + \global\setbox\textboxone\hbox + {\hbox to \wd\stepboxone{\box\textboxone\hss}\box0} + \global\setbox\textboxtwo\hbox + {\hbox to \wd\stepboxtwo{\box\textboxtwo\hss}\box2} + \fi} + +\def\doSTEPcharttextsB[#1]% #2 #3 + {\dodoSTEPcharttextsB{\cellcounter}{#1}} + +\def\dodoSTEPcharttextsB#1#2#3#4% #1=number #2=setup + {\dodoSTEPcharttextsAB{#1}{#2}{#3}{#4}\dodoSTEPcharttextsB + \ifnum\textcounter>\cellcounter\relax + \doglobal\decrement\textcounter\relax + \else + \bgroup + \initializeSTEL + \startMPdrawing + lines[t][#1][\textcounter] := \MPcharttoplinesgraphic{#1}\textcounter ; + lines[b][#1][\textcounter] := \MPchartbotlinesgraphic{#1}\textcounter ; + \stopMPdrawing + \egroup + \fi} + +\def\dodoSTEPcharttextsAB#1#2#3#4#5% #1=number #2=setup + {\doglobal\increment\textcounter\relax + \ifnum\textcounter>\cellcounter\relax + \@EA\appendtoks\@EA#5\@EA{#1}{#2}{#3}{#4}\to\stepchartbuffer + \fi} + +\def\MPtextsgraphic + {image(drawshape( + \@@STETalternative, pxy enlarged (-.5*\@@STEToffset), + \@@STETrulethickness, \MPcolor{\@@STETframecolor}, + \MPcolor{\@@STETbackgroundcolor} ) )} + +\def\MPcharttoplinesgraphic#1#2% + {image(drawline( + \@@STELalternative, get_step_chart_top_line(#1,#2), + \@@STELrulethickness, \MPcolor{\@@STELcolor} ) )} + +\def\MPchartbotlinesgraphic#1#2% + {image(drawline( + \@@STELalternative, get_step_chart_bot_line(#1,#2), + \@@STELrulethickness, \MPcolor{\@@STELcolor} ) )} + +%D Step tables are the vertical counterpart of stepcharts. + +\newcounter\currentsteptable + +\def\steptableprefix{@st@-\currentsteptable-} + +\def\startSTEPtable + {\dosingleempty\dostartSTEPtable} + +\def\dostartSTEPtable[#1]#2\stopSTEPtable + {\dostartSTEPaligntable[0][#1]#2\stopSTEPaligntable} + +\def\startSTEPaligntable + {\dodoubleempty\dostartSTEPaligntable[1]} + +\def\dostartSTEPaligntable[#1][#2]#3\stopSTEPaligntable % flag settings data + {\ifinsidefloat + \else + \whitespace + \@@STPTbefore + \startbaselinecorrection + \setlocalhsize + \noindent + \fi + \vbox\bgroup + \setupSTEPtables[#2]% + \forgetall + \pushMPdrawing + \doglobal\increment\currentsteptable + \startMPdrawing + input mp-step.mpii ; + begin_step_table ; + \stopMPdrawing + \initializeSTEP + \initializeSTPT + \def\startlines{\bgroup\setupSTEPlines}% + \def\stoplines {\egroup}% + \def\prep##1{\ignorespaces##1\unskip\enspace\ignorespaces}% + \def\cell {\dosingleempty\docell}% + \def\cells {\dosingleempty\docells}% + \def\text {\dosingleempty\dotext}% + % first graphic pass, also trial pass + \global\dimen1\zeropoint + \global\dimen3\zeropoint + \global\dimen5\zeropoint + \def\docell[##1]% + {\docells[##1]{}{}}% + \def\docells[##1]##2##3##4% + {\doglobal\increment\cellcounter + \bgroup + \iffirstargument\setupSTEPcells[##1]\fi + \initializeSTEC + \startMPdrawing + if box_found(\MPpos{\steptableprefix\cellcounter-c}) : + initialize_box(\MPpos{\steptableprefix\cellcounter-c}) ; + cells[\cellcounter] := \MPcellsgraphic ; + fi ; + \stopMPdrawing + \egroup + \def\do####1####2% + {\setbox\scratchbox\hbox{\@@stepfake{####2}}% + \ifdim\wd\scratchbox>\dimen####1\global\dimen####1=\wd\scratchbox\fi}% + \ifcase#1\else\do1{##2}\do3{##3}\fi\do5{##4}}% + \def\dotext[##1]##2% + {\bgroup + \iffirstargument\setupSTEPtexts[##1]\fi + \initializeSTET + \startMPdrawing + if box_found(\MPpos{\steptableprefix\cellcounter-t}) : + initialize_box(\MPpos{\steptableprefix\cellcounter-t}) ; + texts[\cellcounter] := \MPtextsgraphic ; + fi ; + \stopMPdrawing + \egroup} + \doglobal\newcounter\cellcounter#3 + % second graphic pass pass, drawing lines + \def\docells[##1]##2##3##4% + {\doglobal\increment\cellcounter} + \def\dotext[##1]##2% + {\bgroup + \initializeSTEL + \startMPdrawing + lines[\cellcounter] := \MPtablelinesgraphic ; + \stopMPdrawing + \egroup} + \doglobal\newcounter\cellcounter#3 + % finishing graphic touch + \startMPdrawing + nofcells := \cellcounter ; + end_step_table ; + anchor_box(\MPpos{\steptableprefix origin}) ; + \stopMPdrawing + \MPdrawingdonetrue + \doifelse\@@STPTmethod{0} + {\setbox0\null} + {\setbox0\vbox{\MPstaticgraphictrue\getMPdrawing}}% + \resetMPdrawing + % typesetting pass + \dimen6=\@@STPTdistance \dimen6=2\dimen6 + % cell width + \dimen8=\dimen1 + \advance\dimen8\dimen3 + \advance\dimen8\dimen5 + % offset width + \ifcase#1\else \advance\dimen8 \dimen6 \fi + % arrow width + \advance\dimen8 \@@STPTwidth + \advance\dimen8 \@@STPToffset + \advance\dimen8 \@@STPToffset + \def\docells[##1]##2##3##4% + {\doglobal\increment\cellcounter + \def\do####1####2####3####4% % strut really needed there ! + {\hbox to \dimen####1{####2\@@stepfake{####3}\strut####4}}% + \setbox8\hbox + {\ifcase#1\else + \do1\hss{##2}\relax \hskip\@@STPTdistance + \do3\hss{##3}\hss \hskip\@@STPTdistance + \fi + \do5\relax{##4}\hss}% + \hpos{\steptableprefix\cellcounter-c}{\@@stepcell{\box8}} + \endgraf + \nointerlineskip + \kern\@@STPTvoffset} + \def\dotext[##1]##2% + {\bgroup + \hskip\dimen8 + \advance\hsize-\dimen8 + \advance\hsize-\dimen6 % twice the offset + \setbox0\hbox{\@@steptext{##2}}% +% to do +% \ifdim\wd0>\hsize +% \setbox0=\vbox{\@@steptext{##2}}% +% \fi +% align + \hpos{\steptableprefix\cellcounter-t}{\box0}% + \endgraf + \egroup + \nointerlineskip + \kern\@@STPTvoffset} + \setbox2\vbox + {\doglobal\newcounter\cellcounter + #3\kern-\@@STPTvoffset} + \hbox + {\scratchdimen\wd0 + \advance\scratchdimen \MPllx bp + \raise\MPlly bp\box0 + \hskip-\scratchdimen + \hpos{\steptableprefix origin}{\box2}} + \popMPdrawing + \egroup + \ifinsidefloat \else \stopbaselinecorrection \@@STPTafter \fi} + +\def\MPtablelinesgraphic + {image ( drawline ( + \@@STELalternative, get_step_table_line(\cellcounter), + \@@STELrulethickness, \MPcolor{\@@STELcolor} ) )} + +\protect + +\continueifinputfile{m-steps.tex} + +% A simple paragraph-flow test: + +\starttext + +\startbuffer +\startSTEPchart +\cells {A} {B} +\cells {one} {five} \texts{$+2$}{$-2$} +\cells {two} {four} \texts{$+3$}{$-3$} +\cells {three} {three} \texts{$+4$}{$-4$} +\cells {four} {two} \texts{$+5$}{$-5$} +\cells {five} {one} +\stopSTEPchart +\stopbuffer + +\getbuffer + +\startnarrower \getbuffer \stopnarrower + +\placefigure[left]{}{\getbuffer} + +\stoptext diff --git a/tex/context/base/m-steps.mkvi b/tex/context/base/m-steps.mkvi new file mode 100644 index 000000000..1a4406bab --- /dev/null +++ b/tex/context/base/m-steps.mkvi @@ -0,0 +1,382 @@ +%D \module +%D [ file=m-steps, +%D version=2011.10.07, % 2001.05.28, +%D title=\CONTEXT\ Modules, +%D subtitle=Step Charts \& Tables, +%D author=Hans Hagen, +%D date=\currentdate, +%D copyright={PRAGMA ADE \& \CONTEXT\ Development Team}] +%C +%C This module is part of the \CONTEXT\ macro||package and is +%C therefore copyrighted by \PRAGMA. See mreadme.pdf for +%C details. + +% multiple texts? + +\registerctxluafile{m-steps}{} + +\unprotect + +\def\??stpc{@@stpc} % charts +\def\??stpt{@@stpt} % tables +\def\??stec{@@stec} % cells +\def\??stet{@@stet} % texts +\def\??stel{@@stel} % lines + +\installsimplecommandhandler \??stpc {STEPchart} \??stpc +\installsimplecommandhandler \??stpt {STEPtable} \??stpt +\installsimplecommandhandler \??stec {STEPcell} \??stec +\installsimplecommandhandler \??stet {STEPtext} \??stet +\installsimplecommandhandler \??stel {STEPline} \??stel + +\let\setupSTEPcharts\setupSTEPchart +\let\setupSTEPtables\setupSTEPtable +\let\setupSTEPcells \setupSTEPcell +\let\setupSTEPtexts \setupSTEPtext +\let\setupSTEPlines \setupSTEPline + +% numeric text_text_distance ; text_text_distance := 20pt ; +% numeric step_distance ; step_distance := 20pt ; + +\setupSTEPcharts + [\c!alternative=\v!horizontal, + \c!before=\blank, + \c!after=\blank] +% \c!offset=.15\bodyfontsize +% \c!height=2ex + +% \setupSTEPtables +% [\c!before=\blank, +% \c!after=\blank, +% \c!distance=.25em, +% \c!voffset=1ex, +% \c!method=1, +% \c!width=4em, +% \c!offset=.15\bodyfontsize] + +\setupSTEPcells + [\c!alternative=1, % TODO +% \c!style=, +% \c!color=, + \c!dx=\bodyfontsize, + \c!dy=\bodyfontsize, + \c!background=\v!color, + \c!backgroundcolor=STEPbackgroundcolor, + \c!rulethickness=.1\bodyfontsize, + \c!framecolor=STEPframecolor, + \c!offset=.25\bodyfontsize] + +\setupSTEPtexts + [\c!alternative=1, % TODO +% \c!style=\v!smallbodyfont, +% \c!color=, + \c!background=\v!color, + \c!backgroundcolor=STEPbackgroundcolor, + \c!rulethickness=.1\bodyfontsize, + \c!framecolor=STEPframecolor, + \c!distance=.5\bodyfontsize, + \c!offset=.25\bodyfontsize] + +\setupSTEPlines + [\c!alternative=1, % TODO + \c!rulethickness=.15\bodyfontsize, + \c!height=3\bodyfontsize, + \c!distance=.5\bodyfontsize, + \c!offset=.25\bodyfontsize, + \c!color=STEPlinecolor] + +\definecolor [STEPlinecolor] [s=.5] +\definecolor [STEPframecolor] [s=.7] +\definecolor [STEPbackgroundcolor] [s=.9] + +\newtoks\everySTEPchart + +\unexpanded\def\startSTEPchart + {\begingroup + \dodoubleempty\start_STEP_chart} + +\def\start_STEP_chart[#name][#settings]% + {\startnointerference + \iffirstargument + \doifassignmentelse{#name} + {\let\currentSTEPchart\empty + \xdef\flush_STEP_chart{\STEP_chart[][#name]}} + {\edef\currentSTEPchart{#name}% + \glet\flush_STEP_chart\relax}% settings are not stored + \else + \let\currentSTEPchart\empty + \gdef\flush_STEP_chart{\STEP_chart[][]}% + \fi + \the\everySTEPchart + \ctxcommand{step_start_chart("\currentSTEPchart")}} + +\unexpanded\def\stopSTEPchart + {\ctxcommand{step_stop_chart()}% + \stopnointerference + \flush_STEP_chart + \endgroup} + +\unexpanded\def\startSTEPtable + {\begingroup + \setupSTEPchart[\c!alternative=\v!vertical]% + \dodoubleempty\start_STEP_chart} + +\let\stopSTEPtable\stopSTEPchart + +\let\flush_STEP_chart\relax + +\unexpanded\def\STEPchart + {\dodoubleempty\STEP_chart} + +\unexpanded\def\STEP_chart[#name][#settings]% + {\begingroup + \setupSTEPchart[#settings]% + \ifinsidefloat + \makeSTEPchart[#name]% + \else + \STEPchartparameter\c!before + \startbaselinecorrection + \setlocalhsize + \makeSTEPchart[#name]% + \stopbaselinecorrection + \STEPchartparameter\c!after + \fi + \endgroup} + +\unexpanded\def\makeSTEPchart[#name]% + {\ctxcommand{step_make_chart { + chart = { + name = "#name", + alternative = "\STEPchartparameter\c!alternative", + }, + cell = { + alternative = "\STEPcellparameter\c!alternative", % TODO: shapes + offset = \number\dimexpr\STEPcellparameter\c!offset, + rulethickness = \number\dimexpr\STEPcellparameter\c!rulethickness, + framecolor = "\STEPcellparameter\c!framecolor", + backgroundcolor = "\STEPcellparameter\c!backgroundcolor", + dx = \number\dimexpr\STEPcellparameter\c!dx, + dy = \number\dimexpr\STEPcellparameter\c!dy, + }, + text = { + alternative = "\STEPtextparameter\c!alternative", % TODO: shapes + offset = \number\dimexpr\STEPtextparameter\c!offset, + distance = \number\dimexpr\STEPtextparameter\c!distance, + rulethickness = \number\dimexpr\STEPtextparameter\c!rulethickness, + framecolor = "\STEPtextparameter\c!framecolor", + backgroundcolor = "\STEPtextparameter\c!backgroundcolor", + }, + line = { + alternative = "\STEPlineparameter\c!alternative", % TODO: dash, arrow + rulethickness = \number\dimexpr\STEPlineparameter\c!rulethickness, + height = \number\dimexpr\STEPlineparameter\c!height, + distance = \number\dimexpr\STEPlineparameter\c!distance, + offset = \number\dimexpr\STEPlineparameter\c!offset, + color = "\STEPlineparameter\c!color", + }, + }}} + +\unexpanded\def\startSTEPcell + {\ctxcommand{step_start_cell()}} + +\unexpanded\def\stopSTEPcell + {\ctxcommand{step_stop_cell()}} + +\unexpanded\def\step_cells#top#bot% + {\ctxcommand{step_cells(\!!bs\detokenize{#top}\!!es,\!!bs\detokenize{#bot}\!!es)}} + +\unexpanded\def\step_texts#top#bot% + {\ctxcommand{step_texts(\!!bs\detokenize{#top}\!!es,\!!bs\detokenize{#bot}\!!es)}} + +\unexpanded\def\step_cell#str% + {\ctxcommand{step_cell(\!!bs\detokenize{#str}\!!es)}} + +\unexpanded\def\step_text#str% + {\ctxcommand{step_text(\!!bs\detokenize{#str}\!!es)}} + +\unexpanded\def\step_textset#left#middle#right% + {\ctxcommand{step_textset(\!!bs\detokenize{#left}\!!es,\!!bs\detokenize{#middle}\!!es,\!!bs\detokenize{#right}\!!es)}} + +\unexpanded\def\step_toptext#top% + {\ctxcommand{step_text_top(\!!bs\detokenize{#top}\!!es)}} + +\unexpanded\def\step_bottext#bot% + {\ctxcommand{step_text_bot(\!!bs\detokenize{#bot}\!!es)}} + +\unexpanded\def\step_topcell#top% + {\ctxcommand{step_cell_top(\!!bs\detokenize{#top}\!!es)}} + +\unexpanded\def\step_botcell#bot% + {\ctxcommand{step_cell_bot(\!!bs\detokenize{#bot}\!!es)}} + +\appendtoks + \let\cells \step_cells + \let\texts \step_texts + \let\cell \step_cell + \let\text \step_text + \let\textset\step_textset + \let\toptext\step_toptext + \let\bottext\step_bottext + \let\topcell\step_topcell + \let\botcell\step_botcell +\to \everySTEPchart + +% todo: mapping can be done in lua + +\startxmlsetups xml:step:define + \xmlsetsetup{#1} {stepchart|steptable} {xml:step:*} +\stopxmlsetups + +\xmlregistersetup{xml:step:define} + +\startxmlsetups xml:step:stepchart + \startSTEPchart + \xmlfilter{#1}{/(cells|texts|stepcell|cell|text)/command(xml:step:*)} + \stopSTEPchart +\stopxmlsetups + +\startxmlsetups xml:step:steptable + \startSTEPtable + \xmlfilter{#1}{/(cells|texts|stepcell|cell|text)/command(xml:step:*)} + \stopSTEPtable +\stopxmlsetups + +\startxmlsetups xml:step:cells + \cells {\xmltext{#1}{/top}} {\xmltext{#1}{/bot}} +\stopxmlsetups + +\startxmlsetups xml:step:texts + \texts {\xmltext{#1}{/top}} {\xmltext{#1}{/bot}} +\stopxmlsetups + +\startxmlsetups xml:step:stepcell + \cells {\xmltext{#1}{/topcell}} {\xmltext{#1}{/botcell}} + \texts {\xmltext{#1}{/toptext}} {\xmltext{#1}{/bottext}} +\stopxmlsetups + +\startxmlsetups xml:step:cell + \cell {\xmlflush{#1}} +\stopxmlsetups + +\startxmlsetups xml:step:text + \text {\xmlflush{#1}} +\stopxmlsetups + +\protect + +\continueifinputfile{m-steps.mkvi} + +\starttext + +\startbuffer + + some cell + some text + some cell + some text + some cell + +\stopbuffer + +\typebuffer \processxmlbuffer + + +\startbuffer + + some cell + some text + some cell + some text + some cell + +\stopbuffer + +\typebuffer \processxmlbuffer + +\page + +\startSTEPchart + \cells {A} {B} + \cells {one} {five} \texts{$+2$}{$-2$} + \cells {two} {four} \texts{$+3$}{$-3$} + \cells {three} {three} \texts{$+4$}{$-4$} + \cells {four} {two} \texts{$+5$}{$-5$} + \cells {five} {one} +\stopSTEPchart + +\startSTEPtable + \cell {one} \textset{$x$} {=}{$a+b+c$} + \cell {two} \textset{$c+d$}{=}{$y$} + \cell {three} +\stopSTEPtable + + +\page + +\startbuffer + + some text some text + text text + some text some text + +\stopbuffer + +\processxmlbuffer + +\startbuffer + + some text + text text + some text + +\stopbuffer + +\processxmlbuffer + +\page + +\startSTEPchart[second] + \startSTEPcell + \topcell {A} + \botcell {B} + \startSTEPcell + \topcell {one} + \botcell {five} + \toptext {$+2$} + \bottext {$-2$} + \stopSTEPcell + \startSTEPcell + \topcell {two} + \botcell {four} + \toptext {$+3$} + \bottext {$-3$} + \stopSTEPcell + \startSTEPcell + \topcell {three} + \botcell {three} + \toptext {$+4$} + \bottext {$-4$} + \stopSTEPcell + \startSTEPcell + \topcell {four} + \botcell {two} + \toptext {$+5$} + \bottext {$-5$} + \stopSTEPcell + \startSTEPcell + \topcell {five} + \botcell {one} + \stopSTEPcell +\stopSTEPchart + +\STEPchart[first][alternative=horizontal] +\STEPchart[first][alternative=vertical] + +\page + +\STEPchart[second][alternative=horizontal] +\STEPchart[second][alternative=vertical] + +\page + +\stoptext diff --git a/tex/context/base/m-steps.tex b/tex/context/base/m-steps.tex deleted file mode 100644 index 7bc92d456..000000000 --- a/tex/context/base/m-steps.tex +++ /dev/null @@ -1,837 +0,0 @@ -%D \module -%D [ file=m-steps, -%D version=2001.05.28, -%D title=\CONTEXT\ Modules, -%D subtitle=Step Charts \& Tables, -%D author=Hans Hagen, -%D date=\currentdate, -%D copyright={PRAGMA ADE \& \CONTEXT\ Development Team}] -%C -%C This module is part of the \CONTEXT\ macro||package and is -%C therefore copyrighted by \PRAGMA. See mreadme.pdf for -%C details. - -%D When I need this module, I will reimplement it by using the new -%D sometxt macro. Anyhow, it reflects the state of 2001. - -\unprotect - -% temp hack : - -% \ifx\v!kleinkorps\undefined \let\v!kleinkorps\setsmallbodyfont \fi - -% end of hack - -\definecolor [STEPlinecolor] [s=.5] -\definecolor [STEPframecolor] [s=.7] -\definecolor [STEPbackgroundcolor] [s=.9] - -\def\@@STPF{@@STPF} % frames - -\def\@@STPC{@@STPC} % charts -\def\@@STPT{@@STPT} % tables - -\def\@@STEC{@@STEC} % cells -\def\@@STET{@@STET} % tables -\def\@@STEL{@@STEL} % lines - -\def\setupSTEPcharts{\dodoubleargument\getparameters[\@@STPC]} -\def\setupSTEPtables{\dodoubleargument\getparameters[\@@STPT]} -\def\setupSTEPcells {\dodoubleargument\getparameters[\@@STEC]} -\def\setupSTEPtexts {\dodoubleargument\getparameters[\@@STET]} -\def\setupSTEPlines {\dodoubleargument\getparameters[\@@STEL]} - -\setupSTEPcharts - [\c!before=\blank, - \c!after=\blank, - %\c!distance=.25em, % nvt - \c!hoffset=1em, - \c!voffset=1ex, - \c!method=1, - \c!height=2ex, - \c!offset=.15\bodyfontsize] - -\setupSTEPtables - [\c!before=\blank, - \c!after=\blank, - \c!distance=.25em, - %\c!hoffset=1em, % nvt - \c!voffset=1ex, - \c!method=1, - \c!width=4em, - \c!offset=.15\bodyfontsize] - -\setupSTEPcells - [\c!alternative=24, - \c!background=\v!color, - \c!backgroundcolor=STEPbackgroundcolor, - \c!rulethickness=.1\bodyfontsize, - \c!framecolor=STEPframecolor, - \c!offset=.25\bodyfontsize, - \c!style=, - \c!color=] - -\setupSTEPtexts - [\c!alternative=24, - \c!background=\v!color, - \c!backgroundcolor=STEPbackgroundcolor, - \c!rulethickness=.1\bodyfontsize, - \c!framecolor=STEPframecolor, - \c!offset=.25\bodyfontsize, - \c!style=\v!smallbodyfont, - \c!color=] - -\setupSTEPlines - [\c!alternative=1, - \c!rulethickness=.15\bodyfontsize, - \c!color=STEPlinecolor] - -\def\initializeSTEP - {\initializeSTET \initializeSTEC \initializeSTEL} - -\def\initializeSTPC - {\freezedimenmacro\@@STPCoffset - \startMPdrawing - line_v_offset := \@@STPCoffset ; - line_method := \@@STPCmethod ; % only charts - \stopMPdrawing} - -\def\initializeSTPT - {\freezedimenmacro\@@STPToffset - \startMPdrawing - line_h_offset := \@@STPToffset ; - line_method := \@@STPTmethod ; % only charts - \stopMPdrawing} - -\def\initializeSTET - {\freezedimenmacro\@@STETrulethickness - \freezedimenmacro\@@STEToffset} - -\def\initializeSTEC - {\freezedimenmacro\@@STECrulethickness - \freezedimenmacro\@@STECoffset} - -\def\initializeSTEL - {\freezedimenmacro\@@STELrulethickness} - -%D ... - -\presetlocalframed[\@@STPF] - -\def\@@stepcell#1% - {\doattributes\@@STEC\c!style\c!color - {\localframed - [\@@STPF][\c!offset=\@@STECoffset,\c!frame=\v!off] - {\ignorespaces#1\unskip}}} - -\def\@@stepfake#1% - {\doattributes\@@STEC\c!style\c!color - {\ignorespaces#1\unskip}} - -\def\@@steptext#1% - {\doattributes\@@STET\c!style\c!color - {\localframed - [\@@STPF][\c!offset=\@@STEToffset,\c!frame=\v!off] - {\ignorespaces#1\unskip}}} - -%D The first attempt was purely \METAPOST\ based and spawned -%D the typesetting to the \METAFUN\ handler. This method -%D collects the cells, and directly passes them on to -%D \METAPOST. This method is the cleanest, but has the -%D disadvantage that one cannot embed hyperlinks or document -%D dependent definitions in the cells. The implementation -%D roughly looks as follows: -%D -%D \starttyping -%D \def\startSTEPchart% -%D {\bgroup -%D \startMPdrawing -%D input mp-step ; begin_step_chart ; -%D \stopMPdrawing -%D \initializeSTEP -%D \let\cells\stepchartcells \def\cell{\cells{}}% -%D \let\texts\stepcharttexts \def\text{\texts{}}} -%D -%D \def\stepchartcells#1#2% -%D {\setMPtext{tdummy}{\strut\ignorespaces#1\unskip}% beter etex/btex -%D \setMPtext{bdummy}{\strut\ignorespaces#2\unskip}% beter etex/btex -%D \startMPdrawing -%D set_step_chart_cells(\MPstring{tdummy},\MPstring{bdummy}) ; -%D \stopMPdrawing} -%D -%D \def\stepcharttexts#1#2% -%D {\setMPtext{tdummy}{\strut\ignorespaces#1\unskip}% beter etex/btex -%D \setMPtext{bdummy}{\strut\ignorespaces#2\unskip}% beter etex/btex -%D \startMPdrawing -%D set_step_chart_texts(\MPstring{tdummy},\MPstring{bdummy}) ; -%D \stopMPdrawing} -%D -%D \def\stopSTEPchart -%D {\startMPdrawing -%D end_step_chart ; -%D \stopMPdrawing -%D \MPdrawingdonetrue -%D \getMPdrawing -%D \resetMPdrawing -%D \egroup} -%D \stoptyping -%D -%D This method has the advantage that it does the job in -%D (virtually) one pass, while the next methods need multiple -%D passes: one to build the table, another to synchronize the -%D positions, and a third one beause the dimensions may have -%D changed. The last pass is a result from the fact that -%D positions are related to the page. -%D -%D The second attempt was based on tabulations and used the -%D build in position tracking mechanism, which uses two -%D position nodes per cell. -%D -%D This method collects the content in token list registers -%D and build a table from them. In the collecting pass, the -%D graphics are build stepwise. We need to collect because the -%D order of definitions is not the same as the order of -%D typesetting. We show this alternative too because it -%D demonstrates how to apply backgrounds to table cells. -%D -%D \starttyping -%D \newtoks\stepsonetop \newtoks\stepstwotop -%D \newtoks\stepsonebot \newtoks\stepstwobot -%D \stoptyping -%D -%D During the collecting phase, we temporarily have to -%D increment the name space counter. -%D -%D \starttyping -%D \def\startSTEPchart% -%D {\bgroup -%D \resetMPdrawing -%D \advance\noftabpositions\plusone % begin of preroll -%D \startMPdrawing -%D input mp-step ; -%D begin_step_chart ; -%D \stopMPdrawing -%D \initializeSTEP -%D \newcounter\cellcounter -%D \stepsonetop\emptytoks \chardef\somesteponetop=1 -%D \stepsonebot\emptytoks \chardef\somesteponebot=1 -%D \stepstwotop\emptytoks \chardef\somesteptwotop=1 -%D \stepstwobot\emptytoks \chardef\somesteptwobot=1 -%D \let\cells\stepchartcells \def\cell{\cells{}}% -%D \let\texts\stepcharttexts \def\text{\texts{}}} -%D \stoptyping -%D -%D Now we collect the steps and texts, and in the process the -%D graphic is built. Then we continue with building the table. -%D -%D Watch how we anchor the graphic to the main table box. This -%D is needed since the graphic may be larger than the table -%D itself. Actually, these small point took me the most time to -%D digest, even with the right tools (anchors) already in -%D place. -%D -%D \starttyping -%D \def\stopSTEPchart -%D {\splittabulatefalse -%D \insidefloattrue -%D \startMPdrawing -%D nofcells := \cellcounter ; -%D end_step_chart ; -%D anchor_box(\MPpos{\tbPOSprefix origin}) ; -%D \stopMPdrawing -%D \MPdrawingdonetrue -%D \advance\noftabpositions\minusone % end of preroll -%D \setbox0=\vbox -%D {\getMPdrawing} -%D \resetMPdrawing -%D \increment(\cellcounter,\cellcounter)\decrement\cellcounter -%D \setbox2=\vbox -%D {\definetabulate[chart][|*{\cellcounter}{ck0|}] % k0 nills space -%D \startchart -%D \ifcase\somesteptwotop \the\stepstwotop \NC \NR \noalign{\kern2ex} \fi -%D \ifcase\somesteponetop \the\stepsonetop \NC \NR \noalign{\kern2ex} \fi -%D \ifcase\somesteponebot \the\stepsonebot \NC \NR \noalign{\kern2ex} \fi -%D \ifcase\somesteptwobot \the\stepstwobot \NC \NR \noalign{\kern2ex} \fi -%D \noalign{\kern-2ex}% -%D \stopchart} -%D \hbox -%D {\scratchdimen\wd0 -%D \advance\scratchdimen \MPllx bp -%D \raise\MPlly bp\box0 -%D \hskip-\scratchdimen -%D \hpos{\tbPOSprefix origin}{\box2}} -%D \egroup} -%D \stoptyping -%D -%D The steps and texts fill the (at most 4) lines that make up -%D the table. We also feed the (automatically registerd) cell -%D dimensions to the graphic backend. -%D -%D \starttyping -%D \newcounter\cellcounter -%D \newcounter\textcounter -%D -%D \def\stepchartcells#1#2% -%D {\doloop -%D {\ifnum\cellcounter>\textcounter -%D \stepcharttexts{}{}% -%D \else -%D \exitloop -%D \fi}% -%D \increment\cellcounter -%D \doifelsenothing{#1} -%D {\startMPdrawing -%D cells[t][\cellcounter] := origin ; -%D \stopMPdrawing -%D \appendtoks\NC\NC\to\stepsonetop} -%D {\chardef\somesteponetop=0 -%D \edef\stepidentifier{\cellcounter-t-c}% -%D \startMPdrawing -%D initialize_area(\MPpos{b:\tbPOSprefix\stepidentifier}, -%D \MPpos{e:\tbPOSprefix\stepidentifier}) ; -%D cells[t][\cellcounter] := pxy ; -%D \stopMPdrawing -%D \@EA\appendtoks\@EA\stepidentifierposition\@EA{\stepidentifier}#1\NC\to\stepsonetop}% -%D \doifelsenothing{#2} -%D {\startMPdrawing -%D cells[b][\cellcounter] := origin ; -%D \stopMPdrawing -%D \appendtoks\NC\NC\to\stepsonebot} -%D {\chardef\somesteponebot=0 -%D \edef\stepidentifier{\cellcounter-b-c}% -%D \startMPdrawing -%D initialize_area(\MPpos{b:\tbPOSprefix\stepidentifier}, -%D \MPpos{e:\tbPOSprefix\stepidentifier}) ; -%D cells[b][\cellcounter] := pxy ; -%D \stopMPdrawing -%D \@EA\appendtoks\@EA\stepidentifierposition\@EA{\stepidentifier}#2\NC\to\stepsonebot}} -%D -%D \def\stepcharttexts#1#2% \cellcounter = nofcells -%D {\increment\textcounter -%D \doifelsenothing{#1} -%D {\startMPdrawing -%D texts[t][\cellcounter][\textcounter] := origin ; -%D \stopMPdrawing -%D \appendtoks\NC\NC\to\stepstwotop} -%D {\chardef\somesteptwotop=0 -%D \edef\stepidentifier{\cellcounter-\textcounter-t-t}% -%D \startMPdrawing -%D initialize_area(\MPpos{b:\tbPOSprefix\stepidentifier}, -%D \MPpos{e:\tbPOSprefix\stepidentifier}) ; -%D texts[t][\cellcounter][\textcounter] := pxy ; -%D \stopMPdrawing -%D \@EA\appendtoks\@EA\NC\@EA\textcellposition\@EA{\stepidentifier}#1\to\stepstwotop}% -%D \doifelsenothing{#2} -%D {\startMPdrawing -%D texts[b][\cellcounter][\textcounter] := origin ; -%D \stopMPdrawing -%D \appendtoks\NC\NC\to\stepstwobot} -%D {\chardef\somesteptwobot=0 -%D \edef\stepidentifier{\cellcounter-\textcounter-b-t}% -%D \startMPdrawing -%D initialize_area(\MPpos{b:\tbPOSprefix\stepidentifier}, -%D \MPpos{e:\tbPOSprefix\stepidentifier}) ; -%D texts[b][\cellcounter][\textcounter] := pxy ; -%D \stopMPdrawing -%D \@EA\appendtoks\@EA\NC\@EA\textcellposition\@EA{\stepidentifier}#2\to\stepstwobot}} -%D \stoptyping -%D -%D Here are the hooks that take care of calculating the cell -%D dimensions. -%D -%D \starttyping -%D \def\textcellposition#1{\GSC[#1:text]} -%D \def\stepidentifierposition#1{\GSC[#1:step]} -%D \stoptyping -%D -%D We abandoned this method after some testing and went for -%D a third one. It was this third method that evolved into the -%D current mechanism. -%D -%D Since this method was not that efficient, a third one was -%D implemented, which used one position per cell. So, -%D -%D \blank {\bf Here starts the real implementation!} \blank -%D -%D Because we want to build one graphic only we need to store -%D the graphic directives. We also need to collect the cells, -%D which are not defined in the order they show up. This -%D solution uses multiple passes over the definitions. First -%D the cells and texts are processed and the associated -%D graphics are defined in the \METAPOST\ file. Next the -%D lines are flushed. We need to do that in a second pass, -%D because in order to determine the nature of the line, -%D \METAPOST\ needs to know if the start and end cells exist. -%D This need comes from the fact that we store the shapes -%D and lines kind of directly with their associated colors and -%D types, so that we can change the settings in between. So, -%D changing for instance the line color, can take place -%D locally. - -\newbox\stepboxone \newbox\stepboxtwo -\newbox\textboxone \newbox\textboxtwo - -%D We need to define a dedicated name space counter. - -\newcounter\currentstepchart - -\def\stepchartprefix{@sc@-\currentstepchart-} - -%D Next we define the initialization part of the macros. - -\newcounter\cellcounter -\newcounter\textcounter - -\def\startSTEPchart - {\dosingleempty\dostartSTEPchart} - -\long\def\dostartSTEPchart[#1]#2\stopSTEPchart - {\ifinsidefloat - \else - \whitespace - \@@STPCbefore - \startbaselinecorrection - \setlocalhsize - \noindent - \fi - \vbox\bgroup - \setupSTEPcharts[#1]% - \forgetall - \pushMPdrawing - \resetMPdrawing - \doglobal\increment\currentstepchart - \startMPdrawing - input mp-step ; - begin_step_chart ; - \stopMPdrawing - \initializeSTEP - \initializeSTPC - \global\chardef\somestepboxone\plusone - \global\chardef\sometextboxone\plusone - \global\chardef\somestepboxtwo\somestepboxone - \global\chardef\sometextboxtwo\sometextboxone - \def\startlines{\bgroup\setupSTEPlines}% - \def\stoplines {\egroup}% - \def\cells{\dosingleempty\dostepchartcells} - \def\texts{\dosingleempty\dostepcharttexts} - \def\cell {\dosingleempty\docell}% - \def\text {\dosingleempty\dotext}% - \def\docell[##1]{\dostepchartcells[##1]{}}% - \def\dotext[##1]{\dostepcharttexts[##1]{}} - \doglobal\newcounter\cellcounter - \doglobal\newcounter\textcounter - \let\dostepchartcells\doSTEPchartcellsA - \let\dostepcharttexts\doSTEPcharttextsA - {#2} % pass one: cells and texts {} keeps setting local - \startMPdrawing - nofcells := \cellcounter ; - analyze_step_chart ; - \stopMPdrawing - \doglobal\newcounter\cellcounter - \doglobal\newcounter\textcounter - \let\dostepchartcells\doSTEPchartcellsB - \let\dostepcharttexts\doSTEPcharttextsB - {#2} % pass two: lines - \startMPdrawing - end_step_chart ; - % if box_found(\MPpos{\stepchartprefix origin}) : - % initialize_box(\MPpos{\stepchartprefix origin}) ; - % draw pxy ; - % fi ; - anchor_box(\MPpos{\stepchartprefix origin}) ; - \stopMPdrawing - \MPdrawingdonetrue - \doifelse\@@STPCmethod{0} - {\setbox0\null} - {\setbox0\vbox{\MPstaticgraphictrue\getMPdrawing}}% - \resetMPdrawing - \setbox2\vbox - {\offinterlineskip - \scratchdimen\@@STPCheight - \advance\scratchdimen\@@STPCoffset - \advance\scratchdimen\@@STPCoffset - \ifcase\sometextboxone \box\textboxone \vskip\scratchdimen \fi - \ifcase\somestepboxone \box\stepboxone \vskip\@@STPCvoffset \fi - \ifcase\somestepboxtwo \box\stepboxtwo \vskip\scratchdimen \fi - \ifcase\sometextboxtwo \box\textboxtwo \vskip\@@STPCvoffset \fi - \global\setbox\stepboxone\emptybox \global\setbox\stepboxtwo\emptybox % needed indeed - \global\setbox\textboxone\emptybox \global\setbox\textboxtwo\emptybox % needed indeed - %\kern-\scratchdimen % no, instead: - \vskip-\lastskip} - \hbox - {\scratchdimen\wd0 - \advance\scratchdimen \MPllx bp - \raise\MPlly bp\box0 - \hskip-\scratchdimen - \hpos{\stepchartprefix origin}{\box2}}% - \popMPdrawing - \egroup - \ifinsidefloat \else \stopbaselinecorrection \@@STPCafter \fi} - -%D The next macro looks more complicated than it is. We collect -%D the cells in boxes. Before adding a new step cell, we padd -%D the text rows. After adding the step cells, we flush text -%D cells that are defined but not yet processed. - -\def\doSTEPchartcellsA[#1]#2#3% - {% synchronize texts - \doSTEPchartcellsAB[#1]{#2}{#3}% - % package steps - \setbox0\hbox{\doifsomething{#2}{\@@stepcell{#2}}}% - \setbox2\hbox{\doifsomething{#3}{\@@stepcell{#3}}}% - \ifdim\wd0>\zeropoint \!!doneafalse \else \!!doneatrue \fi - \ifdim\wd2>\zeropoint \!!donebfalse \else \!!donebtrue \fi - \ifdim\wd0>\wd2 - \setbox2\hbox to \wd0{\hss\box2\hss}% - \else - \setbox0\hbox to \wd2{\hss\box0\hss}% - \fi - \if!!donea - \startMPdrawing - cells[t][\cellcounter] := nullpicture ; - \stopMPdrawing - \else - \global\chardef\somestepboxone\zerocount - \edef\stepidentifier{\stepchartprefix\cellcounter-t-c}% - \setbox0\hbox{\hpos{\stepidentifier}{\box0}}% - \bgroup - \iffirstargument\setupSTEPcells[#1]\fi\initializeSTEC - \startMPdrawing - initialize_box(\MPpos{\stepidentifier}) ; - cells[t][\cellcounter] := \MPcellsgraphic ; - \stopMPdrawing - \egroup - \fi - \if!!doneb - \startMPdrawing - cells[b][\cellcounter] := nullpicture ; - \stopMPdrawing - \else - \global\chardef\somestepboxtwo\zerocount - \edef\stepidentifier{\stepchartprefix\cellcounter-b-c}% - \setbox2\hbox{\hpos{\stepidentifier}{\box2}}% - \bgroup - \iffirstargument\setupSTEPcells[#1]\fi\initializeSTEC - \startMPdrawing - initialize_box(\MPpos{\stepidentifier}) ; - cells[b][\cellcounter] := \MPcellsgraphic ; - \stopMPdrawing - \egroup - \fi - \global\setbox\stepboxone\hbox - {\ifdim\wd\stepboxone>\zeropoint - \box\stepboxone\hskip\@@STPChoffset\else - \fi\box0}% - \global\setbox\stepboxtwo\hbox - {\ifdim\wd\stepboxtwo>\zeropoint - \box\stepboxtwo\hskip\@@STPChoffset\else - \fi\box2}% - % flush saved texts - \doSTEPchartcellsBA} - -\def\doSTEPchartcellsB[#1]#2#3% - {\doSTEPchartcellsAB[#1]{#2}{#3}% - \doSTEPchartcellsBA} - -\def\doSTEPchartcellsAB[#1]#2#3% - {\doloop - {\ifnum\cellcounter>\textcounter - \texts{}{}\else\exitloop - \fi}% - \doglobal\increment\cellcounter} - -\def\doSTEPchartcellsBA - {\scratchtoks\stepchartbuffer - \stepchartbuffer\emptytoks - \the\scratchtoks} - -\def\MPcellsgraphic - {image ( drawshape ( - \@@STECalternative, pxy enlarged (-.5*\@@STECoffset), - \@@STECrulethickness, \MPcolor{\@@STECframecolor}, - \MPcolor{\@@STECbackgroundcolor} ) )} - -%D Although each step can have only one associated text, the -%D place where the text is defined determines the starting -%D point of the connecting arrow. Although several methods are -%D possible, we've chosen a funny collector that flushes one -%D step text at a time. - -\newtoks\stepchartbuffer - -\def\doSTEPcharttextsA[#1]% #2 #3 - {\dodoSTEPcharttextsA{\cellcounter}{#1}} - -\def\dodoSTEPcharttextsA#1#2#3#4% #1=number #2=setup - {\dodoSTEPcharttextsAB{#1}{#2}{#3}{#4}\dodoSTEPcharttextsA - \ifnum\textcounter>\cellcounter\relax - \doglobal\decrement\textcounter\relax - \else - \setbox0\hbox{\doifsomething{#3}{\@@steptext{#3}}}% - \setbox2\hbox{\doifsomething{#4}{\@@steptext{#4}}}% - \ifdim\wd0>\zeropoint \!!doneafalse \else \!!doneatrue \fi - \ifdim\wd2>\zeropoint \!!donebfalse \else \!!donebtrue \fi - \if!!donea - \setbox0\hbox to \@@STPChoffset{\hss}% - \startMPdrawing - texts[t][#1][\textcounter] := nullpicture ; - \stopMPdrawing - \else - \global\chardef\sometextboxone\zerocount - \edef\stepidentifier{\stepchartprefix#1-\textcounter-t-t}% - \setbox0\hbox to \@@STPChoffset - {\hss\hpos{\stepidentifier}{\box0}\hss}% - \bgroup - \setupSTEPtexts[#2]\initializeSTET - \startMPdrawing - initialize_box(\MPpos{\stepidentifier}) ; - texts[t][#1][\textcounter] := \MPtextsgraphic ; - \stopMPdrawing - \egroup - \fi - \if!!doneb - \setbox2\hbox to \@@STPChoffset{\hss}% - \startMPdrawing - texts[b][#1][\textcounter] := nullpicture ; - \stopMPdrawing - \else - \global\chardef\sometextboxtwo\zerocount - \edef\stepidentifier{\stepchartprefix#1-\textcounter-b-t}% - \setbox2\hbox to \@@STPChoffset - {\hss\hpos{\stepidentifier}{\box2}\hss}% - \bgroup - \setupSTEPtexts[#2]\initializeSTET - \startMPdrawing - initialize_box(\MPpos{\stepidentifier}) ; - texts[b][#1][\textcounter] := \MPtextsgraphic ; - \stopMPdrawing - \egroup - \fi - \global\setbox\textboxone\hbox - {\hbox to \wd\stepboxone{\box\textboxone\hss}\box0} - \global\setbox\textboxtwo\hbox - {\hbox to \wd\stepboxtwo{\box\textboxtwo\hss}\box2} - \fi} - -\def\doSTEPcharttextsB[#1]% #2 #3 - {\dodoSTEPcharttextsB{\cellcounter}{#1}} - -\def\dodoSTEPcharttextsB#1#2#3#4% #1=number #2=setup - {\dodoSTEPcharttextsAB{#1}{#2}{#3}{#4}\dodoSTEPcharttextsB - \ifnum\textcounter>\cellcounter\relax - \doglobal\decrement\textcounter\relax - \else - \bgroup - \initializeSTEL - \startMPdrawing - lines[t][#1][\textcounter] := \MPcharttoplinesgraphic{#1}\textcounter ; - lines[b][#1][\textcounter] := \MPchartbotlinesgraphic{#1}\textcounter ; - \stopMPdrawing - \egroup - \fi} - -\def\dodoSTEPcharttextsAB#1#2#3#4#5% #1=number #2=setup - {\doglobal\increment\textcounter\relax - \ifnum\textcounter>\cellcounter\relax - \@EA\appendtoks\@EA#5\@EA{#1}{#2}{#3}{#4}\to\stepchartbuffer - \fi} - -\def\MPtextsgraphic - {image(drawshape( - \@@STETalternative, pxy enlarged (-.5*\@@STEToffset), - \@@STETrulethickness, \MPcolor{\@@STETframecolor}, - \MPcolor{\@@STETbackgroundcolor} ) )} - -\def\MPcharttoplinesgraphic#1#2% - {image(drawline( - \@@STELalternative, get_step_chart_top_line(#1,#2), - \@@STELrulethickness, \MPcolor{\@@STELcolor} ) )} - -\def\MPchartbotlinesgraphic#1#2% - {image(drawline( - \@@STELalternative, get_step_chart_bot_line(#1,#2), - \@@STELrulethickness, \MPcolor{\@@STELcolor} ) )} - -%D Step tables are the vertical counterpart of stepcharts. - -\newcounter\currentsteptable - -\def\steptableprefix{@st@-\currentsteptable-} - -\def\startSTEPtable - {\dosingleempty\dostartSTEPtable} - -\def\dostartSTEPtable[#1]#2\stopSTEPtable - {\dostartSTEPaligntable[0][#1]#2\stopSTEPaligntable} - -\def\startSTEPaligntable - {\dodoubleempty\dostartSTEPaligntable[1]} - -\def\dostartSTEPaligntable[#1][#2]#3\stopSTEPaligntable % flag settings data - {\ifinsidefloat - \else - \whitespace - \@@STPTbefore - \startbaselinecorrection - \setlocalhsize - \noindent - \fi - \vbox\bgroup - \setupSTEPtables[#2]% - \forgetall - \pushMPdrawing - \doglobal\increment\currentsteptable - \startMPdrawing - input mp-step ; - begin_step_table ; - \stopMPdrawing - \initializeSTEP - \initializeSTPT - \def\startlines{\bgroup\setupSTEPlines}% - \def\stoplines {\egroup}% - \def\prep##1{\ignorespaces##1\unskip\enspace\ignorespaces}% - \def\cell {\dosingleempty\docell}% - \def\cells {\dosingleempty\docells}% - \def\text {\dosingleempty\dotext}% - % first graphic pass, also trial pass - \global\dimen1\zeropoint - \global\dimen3\zeropoint - \global\dimen5\zeropoint - \def\docell[##1]% - {\docells[##1]{}{}}% - \def\docells[##1]##2##3##4% - {\doglobal\increment\cellcounter - \bgroup - \iffirstargument\setupSTEPcells[##1]\fi - \initializeSTEC - \startMPdrawing - if box_found(\MPpos{\steptableprefix\cellcounter-c}) : - initialize_box(\MPpos{\steptableprefix\cellcounter-c}) ; - cells[\cellcounter] := \MPcellsgraphic ; - fi ; - \stopMPdrawing - \egroup - \def\do####1####2% - {\setbox\scratchbox\hbox{\@@stepfake{####2}}% - \ifdim\wd\scratchbox>\dimen####1\global\dimen####1=\wd\scratchbox\fi}% - \ifcase#1\else\do1{##2}\do3{##3}\fi\do5{##4}}% - \def\dotext[##1]##2% - {\bgroup - \iffirstargument\setupSTEPtexts[##1]\fi - \initializeSTET - \startMPdrawing - if box_found(\MPpos{\steptableprefix\cellcounter-t}) : - initialize_box(\MPpos{\steptableprefix\cellcounter-t}) ; - texts[\cellcounter] := \MPtextsgraphic ; - fi ; - \stopMPdrawing - \egroup} - \doglobal\newcounter\cellcounter#3 - % second graphic pass pass, drawing lines - \def\docells[##1]##2##3##4% - {\doglobal\increment\cellcounter} - \def\dotext[##1]##2% - {\bgroup - \initializeSTEL - \startMPdrawing - lines[\cellcounter] := \MPtablelinesgraphic ; - \stopMPdrawing - \egroup} - \doglobal\newcounter\cellcounter#3 - % finishing graphic touch - \startMPdrawing - nofcells := \cellcounter ; - end_step_table ; - anchor_box(\MPpos{\steptableprefix origin}) ; - \stopMPdrawing - \MPdrawingdonetrue - \doifelse\@@STPTmethod{0} - {\setbox0\null} - {\setbox0\vbox{\MPstaticgraphictrue\getMPdrawing}}% - \resetMPdrawing - % typesetting pass - \dimen6=\@@STPTdistance \dimen6=2\dimen6 - % cell width - \dimen8=\dimen1 - \advance\dimen8\dimen3 - \advance\dimen8\dimen5 - % offset width - \ifcase#1\else \advance\dimen8 \dimen6 \fi - % arrow width - \advance\dimen8 \@@STPTwidth - \advance\dimen8 \@@STPToffset - \advance\dimen8 \@@STPToffset - \def\docells[##1]##2##3##4% - {\doglobal\increment\cellcounter - \def\do####1####2####3####4% % strut really needed there ! - {\hbox to \dimen####1{####2\@@stepfake{####3}\strut####4}}% - \setbox8\hbox - {\ifcase#1\else - \do1\hss{##2}\relax \hskip\@@STPTdistance - \do3\hss{##3}\hss \hskip\@@STPTdistance - \fi - \do5\relax{##4}\hss}% - \hpos{\steptableprefix\cellcounter-c}{\@@stepcell{\box8}} - \endgraf - \nointerlineskip - \kern\@@STPTvoffset} - \def\dotext[##1]##2% - {\bgroup - \hskip\dimen8 - \advance\hsize-\dimen8 - \advance\hsize-\dimen6 % twice the offset - \setbox0\hbox{\@@steptext{##2}}% -% to do -% \ifdim\wd0>\hsize -% \setbox0=\vbox{\@@steptext{##2}}% -% \fi -% align - \hpos{\steptableprefix\cellcounter-t}{\box0}% - \endgraf - \egroup - \nointerlineskip - \kern\@@STPTvoffset} - \setbox2\vbox - {\doglobal\newcounter\cellcounter - #3\kern-\@@STPTvoffset} - \hbox - {\scratchdimen\wd0 - \advance\scratchdimen \MPllx bp - \raise\MPlly bp\box0 - \hskip-\scratchdimen - \hpos{\steptableprefix origin}{\box2}} - \popMPdrawing - \egroup - \ifinsidefloat \else \stopbaselinecorrection \@@STPTafter \fi} - -\def\MPtablelinesgraphic - {image ( drawline ( - \@@STELalternative, get_step_table_line(\cellcounter), - \@@STELrulethickness, \MPcolor{\@@STELcolor} ) )} - -\protect - -\continueifinputfile{m-steps.tex} - -% A simple paragraph-flow test: - -\starttext - -\startbuffer -\startSTEPchart -\cells {A} {B} -\cells {one} {five} \texts{$+2$}{$-2$} -\cells {two} {four} \texts{$+3$}{$-3$} -\cells {three} {three} \texts{$+4$}{$-4$} -\cells {four} {two} \texts{$+5$}{$-5$} -\cells {five} {one} -\stopSTEPchart -\stopbuffer - -\getbuffer - -\startnarrower \getbuffer \stopnarrower - -\placefigure[left]{}{\getbuffer} - -\stoptext diff --git a/tex/context/base/status-files.pdf b/tex/context/base/status-files.pdf index 38f7b8132..a4c56c6f8 100644 Binary files a/tex/context/base/status-files.pdf and b/tex/context/base/status-files.pdf differ diff --git a/tex/context/base/status-lua.pdf b/tex/context/base/status-lua.pdf index 10704da13..964cabb11 100644 Binary files a/tex/context/base/status-lua.pdf and b/tex/context/base/status-lua.pdf differ diff --git a/tex/context/base/x-steps.mkiv b/tex/context/base/x-steps.mkiv deleted file mode 100644 index d60524338..000000000 --- a/tex/context/base/x-steps.mkiv +++ /dev/null @@ -1,99 +0,0 @@ -%D \module -%D [ file=m-steps, -%D version=2001.05.28, -%D title=\CONTEXT\ Modules, -%D subtitle=Step Charts \& Tables, -%D author=Hans Hagen, -%D date=\currentdate, -%D copyright={PRAGMA ADE \& \CONTEXT\ Development Team}] -%C -%C This module is part of the \CONTEXT\ macro||package and is -%C therefore copyrighted by \PRAGMA. See mreadme.pdf for -%C details. - -%D The \XML\ interface. This module can be made way more efficient -%D in \MKIV\ using textext but it makes only sense to do this when -%D I really need it in a demanding application. Probably half of the -%D code in m-steps.tex can go. - -\usemodule[m][steps] - -\unprotect - -\def\xmlstepchartdirective#1{\executeifdefined{@@stepchart@@#1}\gobbletwoarguments} % {#2}{#3} -\def\xmlsteptabledirective#1{\executeifdefined{@@steptable@@#1}\gobbletwoarguments} % {#2}{#3} - -\setvalue{@@stepchart@@charts}{\setsomevalue\@@STPC} -\setvalue{@@stepchart@@cells}{\setsomevalue\@@STEC} -\setvalue{@@stepchart@@texts}{\setsomevalue\@@STET} -\setvalue{@@stepchart@@lines}{\setsomevalue\@@STEL} - -\setvalue{@@steptable@@tables}{\setsomevalue\@@STPT} -\setvalue{@@steptable@@cells}{\setsomevalue\@@STEC} -\setvalue{@@steptable@@texts}{\setsomevalue\@@STET} -\setvalue{@@steptable@@lines}{\setsomevalue\@@STEL} - -\startxmlsetups xml:ct:define - \xmlsetsetup {#1} {ct:*} {xml:ct:*} - \xmlsetsetup {#1} {ct:stepaligntable/cells} {xml:ct:stepaligntable:cells} - \xmlsetsetup {#1} {ct:stepaligntable/lines} {xml:ct:stepaligntable:lines} -\stopxmlsetups - -\xmlregisterns{ct}{stepcharts} - -\xmlregistersetup{xml:ct:define} - -\startxmlsetups xml:ct:prep - \expanded{\prep[\xmltoparameters{#1}]}{\xmlflush{#1}} -\stopxmlsetups - -\startxmlsetups xml:ct:text - \expanded{\text[\xmltoparameters{#1}]}{\xmlflush{#1}} -\stopxmlsetups - -\startxmlsetups xml:ct:texts - \expanded{\texts[\xmltoparameters{#1}]}{\xmltext{#1}{/top}} {\xmltext{#1}{/bot}} -\stopxmlsetups - -\startxmlsetups xml:ct:cell - \expanded{\cell[\xmltoparameters{#1}]}{\xmlflush{#1}} -\stopxmlsetups - -\startxmlsetups xml:ct:cells - \expanded{\cells[\xmltoparameters{#1}]}{\xmltext{#1}{/top}} {\xmltext{#1}{/bot}} -\stopxmlsetups - -\startxmlsetups xml:ct:lines - \expanded{\startlines[\xmltoparameters{#1}]} - \xmlflush{#1} - \stoplines -\stopxmlsetups - -\startxmlsetups xml:ct:steptable - \expanded{\startSTEPtable[\xmltoparameters{#1}]} - \xmlflush{#1} - \stopSTEPtable -\stopxmlsetups - -\startxmlsetups xml:ct:stepchart - \expanded{\startSTEPchart[\xmltoparameters{#1}]} - \xmlflush{#1} - \stopSTEPchart -\stopxmlsetups - -\startxmlsetups xml:ct:stepaligntable - \expanded{\startSTEPaligntable[\xmltoparameters{#1}]} - \xmlflush{#1} - \stopSTEPaligntable -\stopxmlsetups - -\startxmlsetups xml:ct:stepaligntable:cells - \expanded{\cells[\xmltoparameters{#1}]} {\xmltext{#1}{/ct:c1}} {\xmltext{#1}{/ct:c2}} {\xmltext{#1}{/ct:c3}} -\stopxmlsetups - -\startxmlsetups xml:ct:stepaligntable:lines - \expanded{\setupSTEPlines[\xmltoparameters{#1}]} - \xmlflush{#1} -\stopxmlsetups - -\protect \endinput diff --git a/tex/generic/context/luatex/luatex-fonts-merged.lua b/tex/generic/context/luatex/luatex-fonts-merged.lua index c97bfabf2..9bb0b012a 100644 --- a/tex/generic/context/luatex/luatex-fonts-merged.lua +++ b/tex/generic/context/luatex/luatex-fonts-merged.lua @@ -1,6 +1,6 @@ -- merged file : luatex-fonts-merged.lua -- parent file : luatex-fonts.lua --- merge date : 10/12/11 16:42:20 +-- merge date : 10/12/11 19:30:11 do -- begin closure to overcome local limits and interference -- cgit v1.2.3