# $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;
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
#
# 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);
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();
$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;
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");
}
}
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 {
foreach $bit (qw(CmdLog Loc)) {
$objs{$id}{$bit}= $ctx->{$bit};
}
+ $objs{$id}{Part}= $defobj_ispart;
$ctx= $defobj_save;
$defobj_save= undef;
}
$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;
$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".
upd_max(\$nxty, $y + $height + $olu_gap_y + $olu_textheight);
}
@al= ();
+ $ctx= $ctx_save;
}
sub cmd__one {
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+$//;