#!/usr/bin/perl -w use POSIX; use strict; no strict 'subs'; our $ptscale= 72/25.4 / 7.0; our $psu_ulen= 4.5; our $psu_edgelw= 0.5; our $psu_ticklw= 0.1; our $psu_ticksperu= 1; our $psu_ticklen= 5.0; our $psu_allwidth= 37.0/2; our $psu_gauge= 9; our $psu_sleeperlen= 17; our $psu_sleeperlw= 15; our $psu_raillw= 1.0; our $lmu_marklw= 4; our $lmu_marktpt= 11; our $lmu_txtboxtxty= $lmu_marktpt * 0.300; our $lmu_txtboxh= $lmu_marktpt * 1.100; our $lmu_txtboxpadx= $lmu_marktpt * 0.335; our $lmu_txtboxoff= $lmu_marklw / 2; our $lmu_txtboxlw= 1; our $pi= atan2(0,-1); # Data structures: # $ctx->{CmdLog}= undef } not in defobj # $ctx->{CmdLog}[]= [ command args ] } in defobj # $ctx->{LocsMade}[]= $id # $ctx->{Loc}{$id}{X} # $ctx->{Loc}{$id}{Y} # $ctx->{Loc}{$id}{A} # $ctx->{Trans}{X} # transformation. is ev representing # $ctx->{Trans}{Y} # new origin. (is applied at _input_ # $ctx->{Trans}{A} # not at plot-time) # $ctx->{Trans}{R} # but multiply all y coords by this! # $ctx->{Draw}{T} # 1 or '' for drawing track # $ctx->{Draw}{L} # L1 or 1 or '' for labelling or drawing locs # # $objs{$id}{CmdLog} # $objs{$id}{Loc} our $ctx; our %objs; our @al; # current cmd our $o=''; our $ol=''; our $param; # for parametric_curve our $debug=0; #$debug=1; open DEBUG, ($debug ? ">&2" : ">/dev/null") or die $!; if ($debug) { select(DEBUG); $|=1; select(STDOUT); $|=1; } # ev_... functions # # Operate on Enhanced Vectors which are a location (coordinates) and a # direction at that location. Representation is a hash with members X # Y and A (angle of the direction in radians, anticlockwise from # East). May be absolute, or interpreted as relative, according to # context. # # Each function's first argument is a hashref whose X Y A members will # be created or overwritten; this hashref will be returned (so you can # use it `functionally' by passing {}). The other arguments may be ev # hashrefs, or other info. The results are in general undefined if # one of the arguments is the same hash as the result. sub ev_byang ($$;$) { # ev_byang(R, ANG,[LEN]) # result is evec of specified angle and length (default=1.0) my ($res,$ang,$len)=@_; $len=1.0 unless defined $len; $res->{X}= $len * cos($ang); $res->{Y}= $len * sin($ang); $res->{A}= $ang; $res; } sub ev_compose ($$$) { # ev_compose(SUM_R, A,B); # appends B to A, result is end of new B # (B's X is forwards from end of A, Y is translating left from end of A) # A may have a member R, which if provided then it should be 1.0 or -1.0, # and B's Y and A will be multiplied by R first (ie, we can reflect); my ($sum,$a,$b) = @_; my ($r); $r= defined $a->{R} ? $a->{R} : 1.0; $sum->{X}= $a->{X} + $b->{X} * cos($a->{A}) - $r * $b->{Y} * sin($a->{A}); $sum->{Y}= $a->{Y} + $r * $b->{Y} * cos($a->{A}) + $b->{X} * sin($a->{A}); $sum->{A}= $a->{A} + $r * $b->{A}; $sum; } sub ev_decompose ($$$) { # ev_decompose(B_R, A,SUM) # computes B_R s.t. ev_compose({}, A, B_R) gives SUM my ($b,$a,$sum)=@_; my ($r,$brx,$bry); $r= defined $a->{R} ? $a->{R} : 1.0; $brx= $sum->{X} - $a->{X}; $bry= $r * ($sum->{Y} - $a->{Y}); $b->{X}= $brx * cos($a->{A}) + $bry * sin($a->{A}); $b->{Y}= $bry * cos($a->{A}) - $brx * sin($a->{A}); $b->{A}= $r * ($sum->{A} - $a->{A}); $b; } sub ev_lincomb ($$$$) { # ev_linkcomb(RES,A,B,P) # gives P*A + (1-P)*B my ($r,$a,$b,$p) = @_; my ($q) = 1.0-$p; map { $r->{$_} = $q * $a->{$_} + $p * $b->{$_} } qw(X Y A); $r; } sub ev_bearing ($$) { # ev_bearing(A,B) # returns bearing of B from A # value returned is in [ A->{A}, A->{A} + 2*$pi > # A->{A} and B->{A} are otherwise ignored my ($a,$b)= @_; my ($r); $r= atan2($b->{Y} - $a->{Y}, $b->{X} - $a->{X}); $r -= 4.0 * $pi; while ($r < $a->{A}) { $r += 2.0 * $pi; } $r; } sub v_dist ($$) { # v_dist(A,B) # returns distance from A to B # A->{A} and B->{A} are ignored my ($a,$b)= @_; my ($xd,$yd); $xd= $b->{X} - $a->{X}; $yd= $b->{Y} - $a->{Y}; return sqrt($xd*$xd + $yd*$yd); } sub canf ($$) { my ($converter,$defaulter)=@_; my ($spec,$v); return &$defaulter unless @al; $spec= shift @al; $v= &$converter($spec); dv('canf ','$spec',$spec, '$v',$v); return $v; } sub can ($) { my ($c)=@_; canf($c, sub { die "too few args"; }); } sub cano ($$) { my ($c,$def)=@_; canf($c, sub { return $def }); } sub signum ($) { return ($_[0] > 0) - ($_[0] < 0); } our %units_len= qw(- mm mm 1 cm 10 m 1000); our %units_ang= qw(- d r 1); $units_ang{'d'}= 2*$pi / 360; sub cva_len ($) { my ($sp)=@_; cva_units($sp,\%units_len); } sub cva_ang ($) { my ($sp)=@_; cva_units($sp,\%units_ang); } sub cva_absang ($) { input_absang(cva_ang($_[0])) } sub cva_units ($$) { my ($sp,$ua)=@_; my ($n,$u,$r); $sp =~ m/^([-0-9eE.]*[0-9.])([A-Za-z]*)$/ or die "lexically invalid quantity"; ($n,$u)= ($1,$2); $u=$ua->{'-'} unless length $u; defined $ua->{$u} or die "unknown unit $u"; $r= $n * $ua->{$u}; print DEBUG "cva_units($sp,)=$r ($n $u $ua->{$u})\n"; return $r; } sub cva_idstr ($) { my ($sp)=@_; die "invalid id" unless $sp =~ m/^[a-z][_0-9A-Za-z]*$/; return $&; } sub cva_idex ($) { my ($sp,$id)=@_; my ($r,$d,$k,$neg,$na); $neg= $sp =~ s/^\-//; $id= cva_idstr($sp); die "unknown $id" unless defined $ctx->{Loc}{$id}; $r= $ctx->{Loc}{$id}; $d= "idex $id"; foreach $k (sort keys %$r) { $d .= " $k=$r->{$k}"; } printf DEBUG "%s\n", $d; if ($neg) { $na= $r->{A} + $pi; $na -= 2*$pi if $na >= 2*$pi; $r= { X => $r->{X}, Y => $r->{Y}, A => $na }; } return $r; } sub cva_idnew ($) { my ($sp)=@_; my ($id); $id=cva_idstr($sp); die "duplicate $id" if exists $ctx->{Loc}{$id}; exists $ctx->{Loc}{$id}{X}; push @{ $ctx->{LocsMade} }, $id; return $ctx->{Loc}{$id}; } sub cva_cmd ($) { return cva_idstr($_[0]); } sub cva__enum ($$) { my ($sp,$el)=@_; return $sp if grep { $_ eq $sp } @$el; die "invalid option (permitted: @$el)"; } sub cvam_enum { my (@e) = @_; return sub { cva__enum($_[0],\@e); }; } sub cmd_abs { my ($i,$nl); $nl= can(\&cva_idnew); $i->{X}= can(\&cva_len); $i->{Y}= can(\&cva_len); $i->{A}= can(\&cva_ang); ev_compose($nl, $ctx->{Trans}, $i); } sub cmd_rel { my ($from,$to,$len,$right,$turn); $from= can(\&cva_idex); $to= can(\&cva_idnew); $len= can(\&cva_len); $right= can(\&cva_len); $turn= cano(\&cva_absang, 0); my ($u)= ev_compose({}, $from, { X => $len, Y => -$right, A => 0 }); ev_compose($to, $u, { X => 0, Y => 0, A => $turn }); } sub dv__evreff ($) { my ($pfx) = @_; $pfx . ($pfx =~ m/\}$|\]$/ ? '' : '->'); } sub dv__evr ($) { my ($v) = @_; return 'undef' if !defined $v; return $v if $v !~ m/\W/ && $v =~ m/[A-Z]/ && $v =~ m/^[a-z_]/i; return $v if $v =~ m/^[0-9.]+/; $v =~ s/[\\\']/\\$&/g; return "'$v'"; } sub dv1 ($$$); sub dv1_kind ($$$$$$$) { my ($pfx,$expr,$ref,$ref_exp,$ixfmt,$ixesfn,$ixmapfn) = @_; my ($ix,$any); return 0 if $ref ne $ref_exp; $any=0; foreach $ix (&$ixesfn) { $any=1; my ($v)= &$ixmapfn($ix); #print STDERR "dv1_kind($pfx,$expr,$ref,$ref_exp,$ixmapfn) ix=$ix v=$v\n"; dv1($pfx,$expr.sprintf($ixfmt,dv__evr($ix)),$v); } if (!$any) { printf DEBUG "%s%s= $ixfmt\n", $pfx, $expr, ' '; } 1; } sub dv1 ($$$) { return 0 unless $debug; my ($pfx,$expr,$v) = @_; my ($ref); $ref= ref $v; #print STDERR "dv1 >$pfx|$ref<\n"; if (!$ref) { printf DEBUG "%s%s= %s\n", $pfx,$expr, dv__evr($v); return; } elsif ($ref eq 'SCALAR') { dv1($pfx, ($expr =~ m/^\$/ ? "\$$expr" : '${'.$expr.'}'), $$v); return; } $expr.='->' unless $expr =~ m/\]$|\}$/; return if dv1_kind($pfx,$expr,$ref,'ARRAY','[%s]', sub { ($[ .. $#$v) }, sub { $v->[$_[0]] }); return if dv1_kind($pfx,$expr,$ref,'HASH','{%s}', sub { sort keys %$v }, sub { $v->{$_[0]} }); printf DEBUG "%s%s is %s\n", $pfx, $expr, $ref; } sub dv { my ($pfx,@l) = @_; my ($expr,$v,$ref); while (@l) { ($expr,$v,@l)=@l; dv1($pfx,$expr,$v); } } sub o ($) { $o .= $_[0]; } sub ol ($) { $ol .= $_[0]; } our $o_path_verb; sub o_path_begin () { o(" newpath\n"); $o_path_verb= 'moveto'; } sub o_path_point ($) { my ($pt)=@_; o(" $pt $o_path_verb\n"); $o_path_verb= 'lineto'; } sub o_path_stroke ($) { my ($width)=@_; o(" $width setlinewidth stroke\n"); } sub o_line ($$$) { my ($a,$b,$width)=@_; o_path_begin(); o_path_point($a); o_path_point($b); o_path_stroke($width); } sub psu_coords ($$$) { my ($ends,$inunit,$across)=@_; # $ends->[0]{X} etc.; $inunit 0 to 1 (but go to 1.5); # $across in mm, +ve to right. my (%ea_zo, $zo, $prop); $ea_zo{X}=$ea_zo{Y}=0; foreach $zo (qw(0 1)) { $prop= $zo ? $inunit : (1.0 - $inunit); $ea_zo{X} += $prop * ($ends->[$zo]{X} - $across * sin($ends->[0]{A})); $ea_zo{Y} += $prop * ($ends->[$zo]{Y} + $across * cos($ends->[0]{A})); } # dv("psu_coords ", '$ends',$ends, '$inunit',$inunit, '$across',$across, # '\\%ea_zo', \%ea_zo); return $ea_zo{X}." ".$ea_zo{Y}; } sub parametric_segment ($$$$) { my ($p0,$p1,$lenperp,$calcfn) = @_; # makes $p (global) go from $p0 to $p1 ($p1>$p0) # $lenperp is the length of one unit p, ie the curve # must have a uniform `density' in parameter space # $calcfn is invoked with $p set and should return a loc # (ie, ref to X =>, Y =>, A =>). my ($pa,$pb,@ends,$side,$ppu,$e,$v,$tick); return unless $ctx->{Draw}{T} =~ m/1/; $ppu= $psu_ulen/$lenperp; my ($railctr)=($psu_gauge + $psu_raillw)*0.5; my ($tickend)=($psu_allwidth - $psu_ticklen); my ($tickpitch)=($psu_ulen / $psu_ticksperu); my ($sleeperctr)=($psu_ulen*0.5); my ($sleeperend)=($psu_sleeperlen*0.5); print DEBUG "ps $p0 $p1 $lenperp ($ppu)\n"; for ($pa= $p0; $pa<$p1; $pa=$pb) { $pb= $pa + $ppu; $param= $pa; $ends[0]= @ends ? $ends[1] : &$calcfn; $param= $pb; $ends[1]= &$calcfn; #print DEBUG "pa $pa $ends[0]{X} $ends[0]{Y} $ends[0]{A}\n"; #print DEBUG "pb $pb $ends[1]{X} $ends[1]{Y} $ends[1]{A}\n"; $e= $pb<=$p1 ? 1.0 : ($p1-$pa)/$ppu; o(" gsave\n"); o_path_begin(); o_path_point(psu_coords(\@ends,0,-$psu_allwidth)); o_path_point(psu_coords(\@ends,0,$psu_allwidth)); o_path_point(psu_coords(\@ends,$e,$psu_allwidth)); o_path_point(psu_coords(\@ends,$e,-$psu_allwidth)); o(" closepath clip\n"); foreach $side qw(-1 1) { o_line(psu_coords(\@ends,0,$side*$psu_allwidth), psu_coords(\@ends,1.5,$side*$psu_allwidth), $psu_edgelw); o_line(psu_coords(\@ends,0,$side*$railctr), psu_coords(\@ends,1.5,$side*$railctr), $psu_raillw); for ($tick=0; $tick<1.5; $tick+=$tickpitch/$psu_ulen) { o_line(psu_coords(\@ends,$tick,$side*$psu_allwidth), psu_coords(\@ends,$tick,$side*$tickend), $psu_ticklw); } } o_line(psu_coords(\@ends,$sleeperctr,-$sleeperend), psu_coords(\@ends,$sleeperctr,+$sleeperend), $psu_sleeperlw); o(" grestore\n"); } } sub arc ($$$$$) { my ($to, $ctr,$from, $radius,$delta) = @_; # does parametric_segment to draw an arc centred on $ctr # ($ctr->{A} ignored) # from $from with radius $radius (this must be consistent!) # and directionally-subtending an angle $delta. # sets $to->... to be the other end, and returns $to my ($beta); $to->{A}= $beta= $from->{A} + $delta; $to->{X}= $ctr->{X} - $radius * sin($beta); $to->{Y}= $ctr->{Y} + $radius * cos($beta); return if abs($delta*$radius) < 1E-9; parametric_segment(0.0,1.0, abs($radius*$delta), sub { my ($beta) = $from->{A} + $delta * $param; return { X => $ctr->{X} - $radius * sin($beta), Y => $ctr->{Y} + $radius * cos($beta), A => $beta } }); } sub cmd_join { my ($from,$to,$how,$radius); $from= can(\&cva_idex); $to= can(\&cva_idex); $how= can(cvam_enum(qw(arcs arcsline arcline))); if ($how eq 'arcsline') { $radius= can(\&cva_len); } my (@paths); if ($how eq 'arcs') { my ($sigma,$distfact, $theta,$phi, $a,$b,$c,$d, $m,$r); my ($cvec,$cfrom,$cto,$midpt, $delta1,$delta2, $path,$reverse); $sigma= ev_bearing($from,$to); $distfact= v_dist($from,$to); $theta= 0.5 * $pi - ($from->{A} - $sigma); $phi= 0.5 * $pi - ($to->{A} + $pi - $sigma); $a= 2 * (1 + cos($theta - $phi)); $b= 2 * (cos($theta) - cos($phi)); $c= -1; $d= sqrt($b*$b - 4*$a*$c); foreach $m (qw(-1 1)) { $r= -0.5 * (-$b + $m*$d) / $a; $radius= -$r * $distfact; $cfrom= ev_compose({}, $from, { X=>0, Y=>-$radius, A=>-0.5*$pi }); $cto= ev_compose({}, $to, { X=>0, Y=> $radius, A=> 0.5*$pi }); $midpt= ev_lincomb({}, $cfrom, $cto, 0.5); $reverse= signum($r); if ($reverse<0) { $cfrom->{A} += $pi; $cto->{A} += $pi; } $delta1= ev_bearing($cfrom, $midpt) - $cfrom->{A}; $delta2= ev_bearing($cto, $midpt) - $cto->{A}; if ($reverse<0) { $delta1 -= 2*$pi; $delta2 -= 2*$pi; } my ($fs); $path= [{ T=>Arc, F=>$from, C=>$cfrom, R=> $radius, D=>$delta1 }, { T=>Arc, F=>$to, C=>$cto, R=>-$radius, D=>$delta2 }]; push @paths, $path; } } my ($path,$segment,$bestpath,$len,$bestlen); foreach $path (@paths) { o("% possible path $path\n"); $len= 0; foreach $segment (@$path) { if ($segment->{T} eq Arc) { o("% Arc C ".loc2dbg($segment->{C}). " R $segment->{R} D ".ang2deg($segment->{D})."\n"); $len += abs($radius * $segment->{D}); } else { die "unknown segment $segment->{T}"; } } o("% length $len\n"); if (!defined($bestpath) || $len < $bestlen) { $bestpath= $path; $bestlen= $len; } } die unless defined $bestpath; o("% chose path $bestpath\n"); foreach $segment (@$bestpath) { if ($segment->{T} eq 'Arc') { arc({}, $segment->{C},$segment->{F},$segment->{R},$segment->{D}); } else { die "unknown segment"; } } } sub cmd_extend { my ($from,$to,$radius,$len,$upto,$ctr,$beta,$ang,$how,$sign_r); $from= can(\&cva_idex); $to= can(\&cva_idnew); printf DEBUG "from $from->{X} $from->{Y} $from->{A}\n"; $how= can(cvam_enum(qw(len upto ang uptoang parallel))); if ($how eq 'len') { $len= can(\&cva_len); } elsif ($how =~ m/ang$/) { $ang= can(\&cva_ang); } elsif ($how eq 'parallel' || $how eq 'upto') { $upto= can(\&cva_idex); } $radius= cano(\&cva_len, 'Inf'); # +ve is right hand bend if ($radius eq 'Inf') { # print DEBUG "extend inf $len\n"; if ($how eq 'upto') { $len= ($upto->{X} - $from->{X}) * cos($from->{A}) + ($upto->{Y} - $from->{Y}) * sin($from->{A}); } elsif ($how eq 'len') { } else { die "len of straight spec by angle"; } printf DEBUG "len $len\n"; $to->{X}= $from->{X} + $len * cos($from->{A}); $to->{Y}= $from->{Y} + $len * sin($from->{A}); $to->{A}= $from->{A}; parametric_segment(0.0, 1.0, abs($len), sub { ev_lincomb({}, $from, $to, $param); }); } else { my ($sign_r, $sign_ang, $ctr, $beta_interval, $beta, $delta); print DEBUG "radius >$radius<\n"; $radius *= $ctx->{Trans}{R}; $sign_r= signum($radius); $sign_ang= 1; $ctr->{X}= $from->{X} + $radius * sin($from->{A}); $ctr->{Y}= $from->{Y} - $radius * cos($from->{A}); if ($how eq 'upto') { $beta= atan2(-$sign_r * ($upto->{X} - $ctr->{X}), $sign_r * ($upto->{Y} - $ctr->{Y})); $beta_interval= 1.0; } elsif ($how eq 'parallel') { $beta= $upto->{A}; $beta_interval= 1.0; } elsif ($how eq 'uptoang') { $beta= input_absang($ang); $beta_interval= 2.0; } elsif ($how eq 'len') { $sign_ang= signum($len); $beta= $from->{A} - $sign_r * $len / abs($radius); $beta_interval= 2.0; } else { $sign_ang= signum($ang); $beta= $from->{A} - $sign_r * $ang; $beta_interval= 2.0; } printf DEBUG "ctr->{Y}=$ctr->{Y} radius=$radius beta=$beta\n"; $beta += $sign_ang * $sign_r * 4.0 * $pi; for (;;) { $delta= $beta - $from->{A}; last if $sign_ang * $sign_r * $delta <= 0; $beta -= $sign_ang * $sign_r * $beta_interval * $pi; } printf DEBUG "ctr->{Y}=$ctr->{Y} radius=$radius beta=$beta\n"; arc($to, ,$ctr,$from, $radius,$delta); } printf DEBUG "to $to->{X} $to->{Y} $to->{A}\n"; } sub loc2dbg ($) { my ($loc) = @_; return "$loc->{X} $loc->{Y} ".ang2deg($loc->{A}); } sub ang2deg ($) { return $_[0] * 180 / $pi; } sub input_absang ($) { return $_[0] * $ctx->{Trans}{R} + $ctx->{Trans}{A}; } sub input_abscoords ($$) { my ($in,$out); ($in->{X}, $in->{Y}) = @_; $in->{A}= 0.0; $out= ev_compose({}, $ctx->{Trans}, $in); return ($out->{X}, $out->{Y}); } sub newctx () { $ctx= { Trans => { X => 0.0, Y => 0.0, A => 0.0, R => 1.0 }, InRunObj => "", Draw => { T => 1, L => L1 } }; } our $defobj_save; sub cmd_defobj { my ($id); $id= can(\&cva_idstr); die "nested defobj" if $defobj_save; die "repeated defobj" if exists $objs{$id}; $defobj_save= $ctx; newctx(); $ctx->{CmdLog}= [ ]; $ctx->{InDefObj}= $id; $ctx->{Draw}= { T => '', L => '' } } sub cmd_enddefobj { my ($bit,$id); $id= $ctx->{InDefObj}; die "unmatched enddefobj" unless defined $id; foreach $bit (qw(CmdLog Loc)) { $objs{$id}{$bit}= $ctx->{$bit}; } $ctx= $defobj_save; $defobj_save= undef; } sub cmd_obj { cmd__obj(1); } sub cmd_objflip { cmd__obj(-1); } sub cmd__obj ($) { my ($flipsignum)=@_; my ($obj_id, $ctx_save, $pfx, $actual, $formal_id, $formal, $formcv); my ($c, $ctx_inobj, $obj, $id, $newid, $newpt); $obj_id= can(\&cva_idstr); $actual= can(\&cva_idex); $formal_id= can(\&cva_idstr); $obj= $objs{$obj_id}; dv("cmd__obj ",'$obj',$obj); die "unknown obj $obj_id" unless $obj; $formal= $obj->{Loc}{$formal_id}; die "unknown formal $formal_id" unless $formal; $ctx_save= $ctx; newctx(); $ctx->{Trans}{R}= $flipsignum; $ctx->{Trans}{A}= $actual->{A} - $formal->{A}/$flipsignum; $formcv= ev_compose({}, $ctx->{Trans},$formal); $ctx->{Trans}{X}= $actual->{X} - $formcv->{X}; $ctx->{Trans}{Y}= $actual->{Y} - $formcv->{Y}; $ctx->{InRunObj}= $ctx_save->{InRunObj}."${obj_id}::"; $ctx->{Draw}{L} =~ s/L//; dv("cmd__obj $obj_id ",'$ctx',$ctx); { local (@al); foreach $c (@{ $obj->{CmdLog} }) { @al= @$c; next if $al[0] eq 'enddefobj'; cmd__one(); } }; $pfx= cano(\&cva_idstr,''); $ctx_inobj= $ctx; $ctx= $ctx_save; if (length $pfx) { foreach $id (keys %{ $ctx_inobj->{Loc} }) { next if $id eq $formal_id; $newid= $pfx.$id; next if exists $ctx_save->{Loc}{$newid}; $newpt= cva_idnew($newid); %$newpt= %{ $ctx_inobj->{Loc}{$id} }; } } } sub cmd__do { my ($cmd); dv("cmd__do $ctx @al ",'$ctx',$ctx); $cmd= can(\&cva_cmd); my ($id,$loc,$io,$ad); $io= defined $ctx->{InDefObj} ? "$ctx->{InDefObj}!" : $ctx->{InRunObj}; o("%L cmd $io $cmd @al\n"); $ctx->{LocsMade}= [ ]; { no strict 'refs'; &{ "cmd_$cmd" }; }; die "too many args" if @al; foreach $id (@{ $ctx->{LocsMade} }) { $loc= $ctx->{Loc}{$id}; $ad= ang2deg($loc->{A}); ol("%L point $io$id ".loc2dbg($loc)."\n"); if (length $ctx->{Draw}{L}) { ol(" gsave\n". " $loc->{X} $loc->{Y} translate $ad rotate\n"); if ($ctx->{Draw}{L} =~ m/1/) { ol(" 0 $psu_allwidth newpath moveto\n". " 0 -$psu_allwidth lineto\n". " $lmu_marklw setlinewidth stroke\n"); } if ($ctx->{Draw}{L} =~ m/L/) { ol(" /s ($id) def\n". " lf setfont\n". " /sx5 s stringwidth pop\n". " 0.5 mul $lmu_txtboxpadx add def\n". " -90 rotate 0 $lmu_txtboxoff translate newpath\n". " sx5 neg 0 moveto\n". " sx5 neg $lmu_txtboxh lineto\n". " sx5 $lmu_txtboxh lineto\n". " sx5 0 lineto closepath\n". " gsave 1 setgray fill grestore\n". " $lmu_txtboxlw setlinewidth stroke\n". " sx5 neg $lmu_txtboxpadx add $lmu_txtboxtxty\n". " moveto s show\n"); } ol(" grestore\n"); } } } sub cmd__one { cmd__do(); } print "%!\n". " /lf /Courier-New findfont $lmu_marktpt scalefont def\n". " $ptscale $ptscale scale\n" or die $!; newctx(); while (<>) { next if m/^\s*\#/; chomp; s/^\s+//; s/\s+$//; @al= split /\s+/, $_; next unless @al; print DEBUG "=== @al\n"; push @{ $ctx->{CmdLog} }, [ @al ] if exists $ctx->{CmdLog}; cmd__one(); } print $o, $ol, " showpage\n" or die $!;