chiark / gitweb /
cmd line parsing and control of output style
authorian <ian>
Fri, 30 Jan 2004 17:53:50 +0000 (17:53 +0000)
committerian <ian>
Fri, 30 Jan 2004 17:53:50 +0000 (17:53 +0000)
TODO
layout/informat.txt
layout/layout

diff --git a/TODO b/TODO
index 967967573cc4bbcbb8697a0c10c3de852532e6f1..23ec3e21edc7c31b7e34e46f18556eafb512aa93 100644 (file)
--- a/TODO
+++ b/TODO
@@ -1,5 +1,3 @@
-cmd line lines vs track
-cmd line labels
 other joins
 quiet bits
 objflip broken ? only when on objs ?
index 77db5ed25f8a94cdb9d484aadf7bbfc3190aca65..9b09559ee72ed261fe122ae0402dbdcfeb64c68e 100644 (file)
@@ -68,3 +68,38 @@ Commands
   then the object is placed with object-space y coordinates negated
   (ie, it is mirrored so that the object's North exchanges with
   South).
+
+Command-line options
+
+ -D       turn on debug (level 1)  } currently only debug levels are
+ -Dnnn    set debug level to nnn   }  0 (none) and 1 (some)
+
+ -e[ARSCcLlMNOm]...
+          Turn on and off drawing of elements in groups.
+          These are abbreviations for various -E... options.
+           track                                                 -E....
+             A  full track                                         ARSc
+             R  rails only                                         aRsc
+             S  rails and sleepers only                            aRSc
+             C  centrelines only                                   arsC
+             c  swept area and ticks only                          Arsc
+           labels at locs
+             L  label top-level locs (turns on bars for them too)  LM
+             l  do not label any locs                              l
+           bars at locs (thick lines perp to track dir'n)
+             M  bars for top-level locs only                       Mno
+             N  bars for top-level locs and those in obj's         MNo
+             O  bars for everything, including those inside parts  MNO
+             m  no bars (turns off labelling too)                  mnol
+            
+ -E[ARSCLMNOarsclmno]...
+          enable (capitals) or disable (lowercase) drawing of
+         individual elements
+             A  draw track swept area, with ticks
+             R  draw track rails
+             S  draw track sleepers
+             C  draw track centrelines
+             L  label locs
+             M  mark locs with a bar
+             N  mark locs with a bar in objs
+             O  mark locs with a bar in parts
index c32c00d860ae1834852fb66e6d0e9454838b3858..16065a4ffcd1e307e56aa5ff2d386cf1c82ac68d 100755 (executable)
@@ -52,11 +52,14 @@ $draw_t_def= 'T';
 #  $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
+#  $ctx->{Draw}           # sequence of 0 or more of:
+#                         # restrictions:  T => !C,  L => M
+#  $ctx->{Draw}{T}        # 1 or T for drawing track or thin lines, or ''
+#  $ctx->{Draw}{L}        # L1 or 1 for labelling or drawing locs, or ''
 #
 #  $objs{$id}{CmdLog}
 #  $objs{$id}{Loc}
+#  $objs{$id}{Part}       # 1 iff object is a part
 
 our $ctx;
 our %objs;
@@ -66,15 +69,7 @@ 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
 #
@@ -379,8 +374,8 @@ sub parametric_segment ($$$$) {
     # 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,$thinline);
-    return unless $ctx->{Draw}{T} =~ m/./;
+    my ($pa,$pb,@ends,$side,$ppu,$e,$v,$tick,$draw);
+    return unless $ctx->{Draw} =~ m/[ARSC]/;
     $ppu= $psu_ulen/$lenperp;
     my ($railctr)=($psu_gauge + $psu_raillw)*0.5;
     my ($tickend)=($psu_allwidth - $psu_ticklen);
@@ -388,8 +383,8 @@ sub parametric_segment ($$$$) {
     my ($sleeperctr)=($psu_ulen*0.5);
     my ($sleeperend)=($psu_sleeperlen*0.5);
 print DEBUG "ps $p0 $p1 $lenperp ($ppu)\n";
-    $thinline= $ctx->{Draw}{T} !~ m/1/;
-    if ($thinline) {
+    $draw= $ctx->{Draw};
+    if ($draw =~ m/C/) {
        my ($pt);
        o("    $psu_thinlw setlinewidth\n");
        o_path_begin();
@@ -399,8 +394,8 @@ print DEBUG "ps $p0 $p1 $lenperp ($ppu)\n";
        $param=$p1;
        parametric__o_pt(&$calcfn);
        o("      stroke\n");
-       return;
     }
+    return unless $draw =~ m/[ARS]/;
     for ($pa= $p0; $pa<$p1; $pa=$pb) {
        $pb= $pa + $ppu;
        $param= $pa; $ends[0]= @ends ? $ends[1] : &$calcfn;
@@ -416,21 +411,27 @@ print DEBUG "ps $p0 $p1 $lenperp ($ppu)\n";
        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);
+           if ($draw =~ m/R/) {
+               o_line(psu_coords(\@ends,0,$side*$railctr),
+                      psu_coords(\@ends,1.5,$side*$railctr),
+                      $psu_raillw);
+           }
+           if ($draw =~ m/A/) {
+               o_line(psu_coords(\@ends,0,$side*$psu_allwidth),
+                      psu_coords(\@ends,1.5,$side*$psu_allwidth),
+                      $psu_edgelw);
+               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);
+       if ($draw =~ m/S/) {
+           o_line(psu_coords(\@ends,$sleeperctr,-$sleeperend),
+                  psu_coords(\@ends,$sleeperctr,+$sleeperend),
+                  $psu_sleeperlw);
+       }
        o("      grestore\n");
     }
 }
@@ -639,23 +640,27 @@ sub input_abscoords ($$) {
 sub newctx () {
     $ctx= {
        Trans => { X => 0.0, Y => 0.0, A => 0.0, R => 1.0 },
-       InRunObj => "",
-       Draw => { T => $draw_t_def, L => L1 }
+       InRunObj => ""
        };
 }
 
 our $defobj_save;
+our $defobj_ispart;
 
-sub cmd_defobj {
+sub cmd_defobj { cmd__defobj(0); }
+sub cmd_defpart { cmd__defobj(1); }
+sub cmd__defobj ($) {
+    my ($ispart) = @_;
     my ($id);
     $id= can(\&cva_idstr);
     die "nested defobj" if $defobj_save;
     die "repeated defobj" if exists $objs{$id};
     $defobj_save= $ctx;
+    $defobj_ispart= $ispart;
     newctx();
     $ctx->{CmdLog}= [ ];
     $ctx->{InDefObj}= $id;
-    $ctx->{Draw}= { T => '', L => '' }
+    $ctx->{Draw}= '';
 }
 
 sub cmd_enddefobj {
@@ -665,6 +670,7 @@ sub cmd_enddefobj {
     foreach $bit (qw(CmdLog Loc)) {
        $objs{$id}{$bit}= $ctx->{$bit};
     }
+    $objs{$id}{Part}= $defobj_ispart;
     $ctx= $defobj_save;
     $defobj_save= undef;
 }
@@ -703,9 +709,14 @@ sub cmd__obj ($) {
     $ctx->{Trans}{X}= $actual->{X} - $formcv->{X};
     $ctx->{Trans}{Y}= $actual->{Y} - $formcv->{Y};
     $ctx->{InRunObj}= $ctx_save->{InRunObj}."${obj_id}::";
-    $ctx->{Draw}{T}= $ctx_save->{Draw}{T};
-    $ctx->{Draw}{L}= $ctx_save->{Draw}{L};
-    $ctx->{Draw}{L} =~ s/L//;
+    $ctx->{Draw}= $ctx_save->{Draw};
+    if ($obj->{Part}) {
+       $ctx->{Draw} =~ s/[LMN]//g;
+       $ctx->{Draw} =~ s/O/MNO/;
+    } else {
+       $ctx->{Draw} =~ s/[LM]//g;
+       $ctx->{Draw} =~ s/N/MN/;
+    }
     cmd__runobj($obj_id);
     if (@al && $al[0] eq '=') {
        $pfx= ''; shift @al;
@@ -742,15 +753,15 @@ dv("cmd__do $ctx @al ",'$ctx',$ctx);
        $loc= $ctx->{Loc}{$id};
        $ad= ang2deg($loc->{A});
        ol("%L point $io$id ".loc2dbg($loc)."\n");
-       if (length $ctx->{Draw}{L}) {
+       if ($ctx->{Draw} =~ m/[LM]/) {
            ol("    gsave\n".
               "      $loc->{X} $loc->{Y} translate $ad rotate\n");
-           if ($ctx->{Draw}{L} =~ m/1/) {
+           if ($ctx->{Draw} =~ m/M/) {
                ol("      0 $psu_allwidth newpath moveto\n".
                   "      0 -$psu_allwidth lineto\n".
                   "      $lmu_marklw setlinewidth stroke\n");
            }
-           if ($ctx->{Draw}{L} =~ m/L/) {
+           if ($ctx->{Draw} =~ m/L/) {
                ol("      /s ($id) def\n".
                   "      lf setfont\n".
                   "      /sx5  s stringwidth pop\n".
@@ -840,6 +851,7 @@ sub cmd_showlibrary {
        upd_max(\$nxty, $y + $height + $olu_gap_y + $olu_textheight);
     }
     @al= ();
+    $ctx= $ctx_save;
 }
 
 sub cmd__one {
@@ -853,7 +865,56 @@ print
     or die $!;
 
 newctx();
-    
+
+our $drawers= 'arsclmno';
+our %chdraw_emap= qw(A ARSc
+                    R aRsc
+                    S aRSc
+                    C arsC
+                    c Arsc
+                    L LM
+                    l l
+                    M Mno
+                    N MNo
+                    O MNO
+                    m mnol);
+                    
+$ctx->{Draw}= uc $drawers;
+
+while (@ARGV && $ARGV[0] =~ m/^\-/) {
+    last if $ARGV[0] eq '-';
+    $_= shift @ARGV;
+    last if $_ eq '--';
+    s/^\-//;
+    while (length) {
+       if (s/^D(\d+)//) { $debug= $1; }
+       elsif (s/^D//) { $debug++; }
+       elsif (s/^([Ee])([a-zA-Z]+)//) {
+           my ($ee,$c);
+           $ee= $1;
+           foreach $c (split //, $2) {
+               if ($ee eq 'e') {
+                   die "bad -e option $c" unless defined $chdraw_emap{$c};
+                   $c= $chdraw_emap{$c};
+               } else {
+                   die "bad -E option $c" unless $c =~ m/[$drawers]/i;
+               }
+               $ctx->{Draw} =~ s/$c//ig;
+               $ctx->{Draw} .= $c if $c =~ m/[A-Z]/;
+           }
+       } else {
+           die "unknown option -$_";
+       }
+    }
+}
+
+open DEBUG, ($debug ? ">&2" : ">/dev/null") or die $!;
+
+if ($debug) {
+    select(DEBUG); $|=1;
+    select(STDOUT); $|=1;
+}
+
 while (<>) {
     next if m/^\s*\#/;
     chomp; s/^\s+//; s/\s+$//;