chiark / gitweb /
default layer *
authorian <ian>
Mon, 2 Feb 2004 02:12:01 +0000 (02:12 +0000)
committerian <ian>
Mon, 2 Feb 2004 02:12:01 +0000 (02:12 +0000)
layout/informat.txt
layout/layout

index c70f3fae0e515795d0a90fced69e43790687c712..e434b0db8946d71311cd543da40d120f8079f9b0 100644 (file)
@@ -33,11 +33,12 @@ Commands
   Defines loc T: start at loc F, go forward L, translate right R,
   turn left A (defaults are all 0).
 
- layer KL
+ layer K[L]
   K is layer kind (letters and `_', may be empty), L is a layer depth
-  (digits).  Controls drawing style, by selecting appropriate parts of
-  the track and locs to draw, according to element selection rules.
-  Default outcomes:
+  (digits, or `=' meaning current layer; default for L is `='; default
+  KL at start of file is `layer 5').  Controls drawing style, by
+  selecting appropriate parts of the track and locs to draw, according
+  to element selection rules.  Default outcomes:
     K       L        result (description)     result (element letters)
     any     other    nothing                  -
     empty   current  default track            RLMNasco
@@ -163,9 +164,11 @@ Command-line options
  D+ matches L iff L>=D; D++ iff L>D; D+++ iff L>D+1 and so on; D-
  matches L iff L<=D; D-- iff L<D; etc.; D= matches L iff L==D; D== iff
  D-1<=L<=D+1; D=== iff D-2<=L<=D+2; etc.  If D is omitted the current
- layer (from the most recent -l option) is used.  N may be empty or
- `~'; the latter simply inverts the sense of the match.  If C is
- omitted then `=' is assumed.
+ layer (from the most recent -l option) is used (or `5' if current
+ layer is `*').  N may be empty or `~'; the latter simply inverts the
+ sense of the match.  If C is omitted then `=' is assumed.  If the
+ final output layer is `*' then we pretend, for the moment, that L was
+ D.
 
  If V is present then C must be exactly one character and it is as if
  V (must be an integer) copies of C were specified.
index 36670791f723f829c7306dc741aca28b69f5d1ef..88c24fd7070cf0d93b2aa90fd44aba820038d324 100755 (executable)
@@ -65,6 +65,8 @@ our $allwidthmin= allwidth(undef);
 #  $ctx->{Trans}{R}       # but multiply all y coords by this!
 #  $ctx->{Draw}           # sequence of one or more chrs from uc $drawers
 #                         #  or X meaning never draw anything (eg in defobj)
+#  $ctx->{Layer}{Level}
+#  $ctx->{Layer}{Kind}
 #
 #  $objs{$id}{CmdLog}
 #  $objs{$id}{Loc}
@@ -682,11 +684,14 @@ sub input_abscoords ($$) {
     return ($out->{X}, $out->{Y});
 }
 
-sub newctx () {
+sub newctx (;$) {
+    my ($ctx_save) = @_;
     $ctx= {
        Trans => { X => 0.0, Y => 0.0, A => 0.0, R => 1.0 },
        InRunObj => ""
        };
+    %{ $ctx->{Layer} }= %{ $ctx_save->{Layer} }
+        if defined $ctx_save;
 }
 
 our $defobj_save;
@@ -702,10 +707,11 @@ sub cmd__defobj ($) {
     die "repeated defobj" if exists $objs{$id};
     $defobj_save= $ctx;
     $defobj_ispart= $ispart;
-    newctx();
+    newctx($defobj_save);
     $ctx->{CmdLog}= [ ];
     $ctx->{InDefObj}= $id;
     $ctx->{Draw}= 'X';
+    $ctx->{Layer}= { Level => 5, Kind => '' };
 }
 
 sub cmd_enddef {
@@ -718,6 +724,7 @@ sub cmd_enddef {
     $objs{$id}{Part}= $defobj_ispart;
     $ctx= $defobj_save;
     $defobj_save= undef;
+    $defobj_ispart= undef;
 }
 
 sub cmd__runobj ($) {
@@ -735,9 +742,12 @@ sub cmd__runobj ($) {
 sub cmd_layer {
     my ($kl, $k,$l, $eo,$cc);
     $kl= can(\&cva_identity);
-    return if $ctx->{Draw} =~ m/X/;
-    $kl =~ m/^([A-Za-z_]*)(\d+)$/ or die "invalid layer spec";
+    $kl =~ m/^([A-Za-z_]*)(\d*|\=)$/ or die "invalid layer spec";
     ($k,$l)=($1,$2);
+    $l= $ctx->{Layer}{Level} if $l =~ m/^\=?$/;
+    $ctx->{Layer}{Kind}= $l;
+    $ctx->{Layer}{Level}= $l;
+    return if $ctx->{Draw} =~ m/X/;
     if ($output_layer ne '*' && $l != $output_layer) {
        $ctx->{Draw} = '';
     } elsif ($k eq '') {
@@ -751,7 +761,7 @@ sub cmd_layer {
     }
     foreach $eo (@eopts) {
        next unless $k =~ m/^$eo->{GlobRe}$/;
-       next unless $output_layer eq '*' || &{ $eo->{LayerCheck} }($l);
+       next unless &{ $eo->{LayerCheck} }($l);
        foreach $cc (split //, $eo->{DrawMods}) {
            $ctx->{Draw} =~ s/$cc//ig;
            $ctx->{Draw} .= $cc if $cc =~ m/[A-Z]/;
@@ -788,7 +798,7 @@ sub cmd__obj ($) {
     $formal= $obj->{Loc}{$formal_id};
     die "unknown formal $formal_id" unless $formal;
     $ctx_save= $ctx;
-    newctx();
+    newctx($ctx_save);
     $how *= $ctx_save->{Trans}{R};
     $ctx->{Trans}{R}= $how;
     $ctx->{Trans}{A}= $actual->{A} - $formal->{A}/$how;
@@ -915,7 +925,7 @@ sub cmd_showlibrary {
        $obj= $objs{$obj_id};
        next unless $obj->{Part};
        ($min_x, $max_x, $min_y, $max_y) = bbox($obj->{Loc});
-       newctx();
+       newctx($ctx_save);
 
        for (;;) {
            $width= $max_x - $min_x;
@@ -1008,6 +1018,7 @@ while (@ARGV && $ARGV[0] =~ m/^\-/) {
            my ($eo, $invert, $lfn, $ccc, $sense,$limit);
            $g =~ s/[?*]/\\$&/g;
            $d= $output_layer if !length $d;
+           $d= 5 if $d eq '*';
            $invert= length $n;
            $c= '=' if !length $c;
            if (length $v) {
@@ -1017,10 +1028,18 @@ while (@ARGV && $ARGV[0] =~ m/^\-/) {
            if ($c =~ m/^[-+]/) {
                $sense= ($c.'1') + 0;
                $limit= ($sense * $d) + length($c) - 1;
-               $lfn= sub { $_[0] * $sense >= $limit xor $invert };
+               $lfn= sub {
+                   ($output_layer eq '*' ? $d
+                    : $_[0]) * $sense >= $limit
+                        xor $invert;
+               };
            } else {
                $limit= length($c) - 1;
-               $lfn= sub { abs($_[0] - $d) <= $limit xor $invert };
+               $lfn= sub {
+                   ($output_layer eq '*' ? 1
+                    : abs($_[0] - $d) <= $limit)
+                       xor $invert;
+               };
            }
            $ccc= '';
            foreach $c (split //, $cc) {