chiark / gitweb /
improved distance label placement when centrelines drawn
[trains.git] / layout / layout
index 2a52ac5fa737f3eb57dfa535a61bd8cc1c272d71..31d1daf83046261aadb66e548b9abe00225e4fe0 100755 (executable)
@@ -25,12 +25,12 @@ our @eopts;
 our @segments= ('/');
 our %subsegcmap;
 
-our $drawers= 'arsclmnog';
-our %chdraw_emap= qw(A ARScg
-                    R aRscg
-                    S aRScg
-                    C arsCg
-                    c Arscg
+our $drawers= 'arscldmnog';
+our %chdraw_emap= qw(A ARScgd
+                    R aRscgD
+                    S aRScgd
+                    C arsCgd
+                    c Arscgd
                     r arcs
                     L LMg
                     l l
@@ -158,7 +158,7 @@ our $psu_sleeperlw= 15;
 our $psu_raillw= 1.0;
 our $psu_thinlw= 1.0;
 our %psu_subseglw;
-$psu_subseglw{'e'}= 25.0;
+$psu_subseglw{'e'}= 20.0;
 $psu_subseglw{'m'}= 15.0;
 
 our $lmu_marklw= 4;
@@ -168,6 +168,8 @@ our $lmu_txtboxh= $lmu_marktpt * 1.100;
 our $lmu_txtboxpadx= $lmu_marktpt * 0.335;
 our $lmu_txtboxoff= $lmu_marklw / 2;
 our $lmu_txtboxlw= 1;
+our $lmu_lenlabeloffctr= -$lmu_marklw * 1.0;
+our $lmu_lenlabeloff=     $lmu_marklw * 0.5;
 
 our $olu_left= 10 * $scale;
 our $olu_right= 217 * $scale - $olu_left;
@@ -628,10 +630,11 @@ sub parametric__o_pt ($) {
 our $segused_incurrent;
 our $segused_currentpt;
 our $segmentpart_counter=0;
+our $segused_restorecounter;
 
 sub segment_used__print ($) {
     my ($pt) = @_;
-    if ($segused_incurrent > 0) {
+    if ($segused_incurrent > 0 && $segused_restorecounter==1) {
        o("%L segmentpart ".
          $segmentpart_counter++." ".
          $ctx->{Layer}{Level}.$ctx->{Layer}{Kind}." ".
@@ -660,13 +663,14 @@ sub segment_used__len ($$) {
 }
     
 sub segment_state_save () {
-    return [ $segused_incurrent, $segused_currentpt,
+    return [ 0, $segused_incurrent, $segused_currentpt,
             $segmentpart_counter, @segments ];
 }
 sub segment_state_restore ($) {
     my ($r) = @_;
-    ($segused_incurrent, $segused_currentpt,
+    ($segused_restorecounter, $segused_incurrent, $segused_currentpt,
      $segmentpart_counter, @segments) = @$r;
+    $r->[0]++;
 }
 
 sub segment_used_begin ($) {
@@ -684,10 +688,10 @@ sub segment_used_end ($$) {
 }
 sub parametric_segment ($$$$$) {
     my ($p0,$p1,$lenperp,$minradius,$calcfn) = @_;
-    # makes $p (global) go from $p0 to $p1  ($p1>$p0)
+    # makes $param (global) go from $p0 to $p1  ($p1>$p0)
     # $lenperp is the length of one unit p, ie the curve
     # must have a uniform `density' in parameter space
-    # $calcfn is invoked with $p set and should return a loc
+    # $calcfn is invoked with $param set and should return a loc
     # (ie, ref to X =>, Y =>, A =>).
     my ($pa,$pb,@ends,$side,$ppu,$e,$v,$tick,$draw,$allwidth);
     return unless $ctx->{Draw} =~ m/[ARSCG]/;
@@ -768,6 +772,21 @@ print DEBUG "ps $p0 $p1 $lenperp ($ppu)\n";
        parametric__o_pt(&$calcfn);
        o("      stroke\n");
     }
+    if ($draw =~ m/D/) {
+       my ($pt,$ad,$len,$off);
+       $param= ($p0+$p1)*0.5;
+       $pt= &$calcfn;
+       $ad= ang2deg($pt->{A});
+       $len= sprintf "%.0f", $lenperp * abs($p1-$p0);
+       $off= $draw =~ m/C/ ? $lmu_lenlabeloff : $lmu_lenlabeloffctr;
+       ol("      gsave\n".
+          "        $pt->{X} $pt->{Y} translate\n".
+          "        $ad rotate\n".
+          "        lf setfont\n".
+          "        0 $off moveto\n".
+          "        ($len) show\n".
+          "      grestore\n");
+    }
     return unless $draw =~ m/[ARS]/;
     for ($pa= $p0; $pa<$p1; $pa=$pb) {
        $pb= $pa + $ppu;