From: ian Date: Thu, 29 Jan 2004 18:16:43 +0000 (+0000) Subject: new library dump feature? X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ijackson/git?a=commitdiff_plain;h=57a65ecf8e66c831116c15318984f7c8ef9de14f;p=trains.git new library dump feature? --- diff --git a/dumplib.i4 b/dumplib.i4 new file mode 100644 index 0000000..1d43018 --- /dev/null +++ b/dumplib.i4 @@ -0,0 +1,2 @@ +include(`parts.i4') +library diff --git a/layout/layout b/layout/layout index b3f3666..5f3adee 100755 --- a/layout/layout +++ b/layout/layout @@ -4,7 +4,8 @@ use POSIX; use strict; no strict 'subs'; -our $ptscale= 72/25.4 / 7.0; +our $scale= 7.0; +our $ptscale= 72/25.4 / $scale; our $psu_ulen= 4.5; our $psu_edgelw= 0.5; @@ -26,6 +27,14 @@ our $lmu_txtboxpadx= $lmu_marktpt * 0.335; our $lmu_txtboxoff= $lmu_marklw / 2; our $lmu_txtboxlw= 1; +our $olu_left= 10 * $scale; +our $olu_right= 217 * $scale - $olu_left; +our $olu_bottom= 20 * $scale; +our $olu_top= 270 * $scale - $olu_top; +our $olu_textheight= 20; +our $olu_gap_x= 5; +our $olu_gap_y= 5; + our $pi= atan2(0,-1); our $draw_t_def= '1'; @@ -302,6 +311,11 @@ sub dv { sub o ($) { $o .= $_[0]; } sub ol ($) { $ol .= $_[0]; } +sub oflushpage () { + print $o, $ol, " showpage\n" + or die $!; + $o=$ol=''; +} our $o_path_verb; @@ -645,12 +659,24 @@ sub cmd_enddefobj { $defobj_save= undef; } +sub cmd__runobj ($) { + my ($obj_id)=@_; + my ($c) + local (@al); + dv("cmd__runobj $obj_id ",'$ctx',$ctx); + foreach $c (@{ $objs{$obj_id}{CmdLog} }) { + @al= @$c; + next if $al[0] eq 'enddefobj'; + cmd__one(); + } +} + 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); + my ($ctx_inobj, $obj, $id, $newid, $newpt); $obj_id= can(\&cva_idstr); $actual= can(\&cva_idex); $formal_id= can(\&cva_idstr); @@ -670,15 +696,7 @@ sub cmd__obj ($) { $ctx->{Draw}{T}= $ctx_save->{Draw}{T}; $ctx->{Draw}{L}= $ctx_save->{Draw}{L}; $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(); - } - }; + cmd__runobj($obj_id); if (@al && $al[0] eq '=') { $pfx= ''; shift @al; } else { @@ -742,6 +760,57 @@ dv("cmd__do $ctx @al ",'$ctx',$ctx); } } +sub cmd_library { + my ($obj_id, $y, $x, $ctx_save, $width, $height); + my ($max_x, $min_x, $max_y, $min_y); + $x=$olu_left; $y=$olu_bottom; undef $nxty; + $ctx_save= $ctx; + foreach $obj_id (sort keys %objs) { + $obj= $objs{$obj_id}; + foreach $loc (values %{ $obj->{Loc} }) { + upd_min(\$min_x, $loc->{X} - abs($psu_allwidth * cos($loc->{A}))); + upd_max(\$max_x, $loc->{X} + abs($psu_allwidth * cos($loc->{A}))); + upd_min(\$min_y, $loc->{Y} - abs($psu_allwidth * sin($loc->{A}))); + upd_max(\$max_y, $loc->{Y} + abs($psu_allwidth * sin($loc->{A}))); + } + newctx(); + for (;;) { + $width= $max_x - $min_x; + $height= $max_y - $min_y; + if ($width > $height) { + $ctx->{Trans}{A}= 0; + $ctx->{Trans}{X}= $x - $min_x; + $ctx->{Trans}{Y}= $y - $min_y + $olu_textheight; + } else { + ($width,$height)=($height,$width); + $ctx->{Trans}{A}= 0.5 * $pi; + $ctx->{Trans}{X}= $x + $max_y; + $ctx->{Trans}{Y}= $y - $min_x + $olu_textheight; + } + if (defined $nxty && $x + $width > $olu_right) { + $x= $olu_left; + $y= $nxty; + } + if ($y + $height > $olu_right) { + oflushpage(); + $x=$olu_left; $y=$olu_bottom; undef $nxty; + } + $ctx->{InRunObj}= $ctx_save->{InRunObj}."${obj_id}//"; + $ctx->{Draw}= $ctx_save->{Draw}; + cmd__runobj($obj_id); + ol(" gsave\n". + " /s ($obj_id) def\n". + " lf setfont\n ". + ($x + 0.5*$width)." ".($y - $olu_textheight)." moveto\n". + " s stringwidth pop 0.5 mul 0 rmoveto\n". + " s show grestore\n"); + $x += $width + $olu_gap_x; + $yy= $y + $height + $olu_gap_y; + $nxty= $yy unless defined $nxty && $nxty >= $yy; + } + } +} + sub cmd__one { cmd__do(); } @@ -764,5 +833,4 @@ while (<>) { cmd__one(); } -print $o, $ol, " showpage\n" - or die $!; +oflushpage();