From: ian Date: Sat, 31 Jan 2004 20:47:43 +0000 (+0000) Subject: more flexibility: -NEWL, ^OBJ, etc., and restart layout design X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ijackson/git?a=commitdiff_plain;h=3a877a54aa49314646f6c4f207edc93a715a7834;p=trains.git more flexibility: -NEWL, ^OBJ, etc., and restart layout design --- diff --git a/layout/informat.txt b/layout/informat.txt index 7c8352f..147be43 100644 --- a/layout/informat.txt +++ b/layout/informat.txt @@ -8,8 +8,15 @@ Locations, angles, etc. Syntaxes New location + - reverse the sense (ie, 180 degrees off) Existing location - [-] (- means reverse the sense) + simply the named location + - reverse the sense (ie, 180 degrees off) + O![-] the location from the specified object + in whatever coordinate system that object + happens to have + ^O![-] the same, but the object is flipped + N-S first (see `part' and `objflip') Quantity (length/angle) [] Angle units: d (degrees,default) r (radians) @@ -61,7 +68,7 @@ Commands * showlibrary lists only parts, not objects * the -e and -E command line options distinguish parts and objects - part N [-]O [F [A]] [FR AR ...] + part N [^]O [F [A]] [FR AR ...] obj[flip] O A F [P] Places an instance of object or part O. The loc defined inside O as F (`formal parameter', F must be just ) is placed at @@ -74,7 +81,7 @@ Commands features offered by both `part' and `obj[flip]' overlap the behaviour is identical. - If `part N -O' or `objflip' is used, rather than `part N O' or + If `part N ^O' or `objflip' is used, rather than `part N O' or `obj', then the object is placed with object-space y coordinates negated (ie, it is mirrored so that the object's North exchanges with South). @@ -149,5 +156,5 @@ Special comments in PostScript: Scope S is O! when defining object or part O - N:T scope T but inside part (introduced with `part') N - O::T scope T but inside obj (introduced with `obj[flip]') O + N:T scope T but inside part (introduced with `part') N } when + O::T scope T but inside obj (introduced with `obj[flip]') O } placing diff --git a/layout/layout b/layout/layout index 950d78b..fc8f519 100755 --- a/layout/layout +++ b/layout/layout @@ -44,7 +44,8 @@ $draw_t_def= 'T'; # Data structures: # $ctx->{CmdLog}= undef } not in defobj # $ctx->{CmdLog}[]= [ command args ] } in defobj -# $ctx->{LocsMade}[]= $id +# $ctx->{LocsMade}[]{Id}= $id +# $ctx->{LocsMade}[]{Neg}= $id # $ctx->{Loc}{$id}{X} # $ctx->{Loc}{$id}{Y} # $ctx->{Loc}{$id}{A} @@ -211,15 +212,27 @@ sub cva_idstr ($) { return $&; } sub cva_idex ($) { - my ($sp,$id)=@_; - my ($r,$d,$k,$neg,$na); + my ($sp)=@_; + my ($id,$r,$d,$k,$neg,$na,$obj_id,$vflip,$locs); + if ($sp =~ s/^(\^?)(\w+)\!//) { + $vflip= length($1); + $obj_id= $2; + die "invalid obj $obj_id in loc" unless exists $objs{$obj_id}; + $locs= $objs{$obj_id}{Loc}; + } else { + $locs= $ctx->{Loc}; + $vflip= 0; + } $neg= $sp =~ s/^\-//; $id= cva_idstr($sp); - die "unknown $id" unless defined $ctx->{Loc}{$id}; - $r= $ctx->{Loc}{$id}; + die "unknown $id" unless defined $locs->{$id}; + $r= $locs->{$id}; $d= "idex $id"; foreach $k (sort keys %$r) { $d .= " $k=$r->{$k}"; } printf DEBUG "%s\n", $d; + if ($vflip) { + $r= { X => $r->{X}, Y => -$r->{Y}, A => -$r->{A} }; + } if ($neg) { $na= $r->{A} + $pi; $na -= 2*$pi if $na >= 2*$pi; @@ -229,11 +242,12 @@ sub cva_idex ($) { } sub cva_idnew ($) { my ($sp)=@_; - my ($id); + my ($id, $neg); + $neg = $sp =~ s/^\-//; $id=cva_idstr($sp); die "duplicate $id" if exists $ctx->{Loc}{$id}; exists $ctx->{Loc}{$id}{X}; - push @{ $ctx->{LocsMade} }, $id; + push @{ $ctx->{LocsMade} }, { Id => $id, Neg => $neg }; return $ctx->{Loc}{$id}; } sub cva_cmd ($) { return cva_idstr($_[0]); } @@ -707,7 +721,7 @@ sub cmd__obj ($) { my ($part_name, $ctx_inobj, $obj, $id, $newid, $newpt); if ($how eq Part) { $part_name= can(\&cva_idstr); - $how= (@al && $al[0] =~ s/^\-//) ? -1 : +1; + $how= (@al && $al[0] =~ s/^\^//) ? -1 : +1; } $obj_id= can(\&cva_idstr); if (defined $part_name) { @@ -776,11 +790,11 @@ sub cmd__obj ($) { $formalr_id= "-$formalr_id"; $formalr_id =~ s/^\-\-//; } - $formalr= cva_idex($formalr_id); { - local ($ctx) = $ctx_save; - $actualr= cva_idnew($actualr_id); - }; + local ($ctx) = $ctx_inobj; + $formalr= cva_idex($formalr_id); + } + $actualr= cva_idnew($actualr_id); %$actualr= %$formalr; } } @@ -790,7 +804,7 @@ sub cmd__do { my ($cmd); dv("cmd__do $ctx @al ",'$ctx',$ctx); $cmd= can(\&cva_cmd); - my ($id,$loc,$io,$ad); + my ($lm,$id,$loc,$io,$ad); $io= defined $ctx->{InDefObj} ? "$ctx->{InDefObj}!" : $ctx->{InRunObj}; o("%L cmd $io $cmd @al\n"); $ctx->{LocsMade}= [ ]; @@ -799,10 +813,12 @@ dv("cmd__do $ctx @al ",'$ctx',$ctx); &{ "cmd_$cmd" }; }; die "too many args" if @al; - foreach $id (@{ $ctx->{LocsMade} }) { + foreach $lm (@{ $ctx->{LocsMade} }) { + $id= $lm->{Id}; $loc= $ctx->{Loc}{$id}; + $loc->{A} += $pi if $lm->{Neg}; $ad= ang2deg($loc->{A}); - ol("%L point $io$id ".loc2dbg($loc)."\n"); + ol("%L point $io$id ".loc2dbg($loc)." ($lm->{Neg})\n"); if ($ctx->{Draw} =~ m/[LM]/) { ol(" gsave\n". " $loc->{X} $loc->{Y} translate $ad rotate\n"); diff --git a/layout/ours.m4 b/layout/ours.m4 index b0c053d..96e6863 100644 --- a/layout/ours.m4 +++ b/layout/ours.m4 @@ -3,15 +3,29 @@ include(`parts.i4') abs midx_m 830 500 90 part midx cross_peco_l m -abs dem_tljp_m 200 200 0 -obj pt_peco_mr dem_tljp_m c dem_tljp_ - -obj pt_peco_ml dem_tljp_m c dem_trjp_ - -extend midx_tl tlj0_b_ parallel dem_tljp_b -315 -obj pt_peco_mr -tlj0_b_ b tlj0_ -extend -tlj0_c lst0_ uptoang -90 -315 -rel lst0_ lst1 0 37 180 +define(`pt_main_r',`pt_peco_mr') + +defobj demos + abs right 200 200 0 + part main_up ^pt_main_r c right b right_main_up + part main_down pt_main_r c right b right_main_down + abs up 200 200 90 + part main_left ^pt_main_r c up b up_main_left + part main_right pt_main_r c up b up_main_right +enddef + +abs demos_right 200 1200 0 +part demos demos right + +extend midx_tr -l0_jtr_b parallel demos!right_main_up 315 +part l0_jtr ^pt_main_r b + +extend midx_tl -l0_jtl_b parallel demos!-right_main_down -315 +part l0_jtl pt_main_r b +extend -l0_jtl_c -l0_lst uptoang -90 -315 +rel l0_lst l2_lst 0 -37 +rel l2_lst l3_lst 0 -37 +eof rel lst1 lst2 0 -37 rel lst2 lst3 0 -37