chiark / gitweb /
where-vessels: No notes is default. Better treatment of lack of notes/ownership
[ypp-sc-tools.main.git] / yarrg / where-vessels
index 1506f292ad13984327e95c1cd6f4561f4aca72e1..b9264923f6b25e4fadda724fe9db250465875cfd 100755 (executable)
@@ -101,10 +101,11 @@ proc nextarg {} {
     return $v
 }
 
     return $v
 }
 
-set notes_loc vessel-notes
+set notes_loc {}
 set scraper {./yppedia-ocean-scraper --chart}
 set info_cache _vessel-info-cache
 set info_source rsync.yarrg.chiark.net::yarrg/vessel-info
 set scraper {./yppedia-ocean-scraper --chart}
 set info_cache _vessel-info-cache
 set info_source rsync.yarrg.chiark.net::yarrg/vessel-info
+set no_owners 0
 
 proc parseargs {} {
     global ai argv
 
 proc parseargs {} {
     global ai argv
@@ -131,7 +132,8 @@ proc parseargs {} {
 
 proc argdefaults {} {
     global ocean notes_loc pirate scraper
 
 proc argdefaults {} {
     global ocean notes_loc pirate scraper
-    if {![info exists ocean] || ![info exists pirate]} {
+    if {![info exists ocean] ||
+        (![info exists pirate] && [string length $notes_loc])} {
        set cmd {./yarrg --find-window-only --quiet}
        if {[info exists ocean]} { lappend cmd --ocean $ocean }
        if {[info exists pirate]} { lappend cmd --pirate $pirate }
        set cmd {./yarrg --find-window-only --quiet}
        if {[info exists ocean]} { lappend cmd --ocean $ocean }
        if {[info exists pirate]} { lappend cmd --pirate $pirate }
@@ -140,6 +142,9 @@ proc argdefaults {} {
            error "$ocean $pirate ?"
        }
     }
            error "$ocean $pirate ?"
        }
     }
+    if {![info exists pirate]} { set pirate {}; glset no_owners 1 }
+    if {![string length $notes_loc]} { glset no_owners 1 }
+
     lappend scraper $ocean
 }
 
     lappend scraper $ocean
 }
 
@@ -410,11 +415,18 @@ proc code2canvas {code canvas x yvar qty qtylen bind} {
 proc show-report-decode {code} {
     global vc_code2full
 
 proc show-report-decode {code} {
     global vc_code2full
 
+    smash-prepare
+
     manyset [split $code _] inport sizecode subclass lockown xabbrev
     manyset [split $lockown ""] lock notown
     
     report-set inport [lindex {{At Sea} {In port}} $inport]
     manyset [split $code _] inport sizecode subclass lockown xabbrev
     manyset [split $lockown ""] lock notown
     
     report-set inport [lindex {{At Sea} {In port}} $inport]
-    report-set size $vc_code2full($sizecode)
+
+    upvar #0 vc_code2full($sizecode) sizefull
+    upvar #0 smash_sizeinexact($sizecode) sizeinexact
+    set size_report $sizefull
+    if {[info exists sizeinexact]} { set size_report "($sizefull+)" }
+    report-set size $size_report
 
     global smash_subclass
     if {$smash_subclass >= 2} {
 
     global smash_subclass
     if {$smash_subclass >= 2} {
@@ -433,19 +445,32 @@ proc show-report-decode {code} {
        {(All lock states)} {(Not battle ready)}
     } $lock]
 
        {(All lock states)} {(Not battle ready)}
     } $lock]
 
-    switch -exact $notown {
-       0 { report-set own "Yours" }
-       1 { report-set own "Other pirate's" }
-       2 { report-set own "Owner unknown" }
-       3 { report-set own "(All ownerships)" }
-       4 - 5 { report-set own "(Yours/unknown)" }
-       default { report-set own "?? $notown" }
+    global no_owners notes_loc
+    if {!$no_owners} {
+       switch -exact $notown {
+           0 { report-set own "Yours" }
+           1 { report-set own "Other pirate's" }
+           2 { report-set own "Owner unknown" }
+           3 { report-set own "(All ownerships)" }
+           4 - 5 { report-set own "(Yours/unknown)" }
+           default { report-set own "?? $notown" }
+       }
     }
 
     }
 
-    if {[string length $xabbrev]} {
-       report-set xabbrev "Notes flags: $xabbrev"
+    global smash_xabbrev_map
+    if {![string length $notes_loc]} {
+    } elseif {[llength $smash_xabbrev_map]} {
+       if {[string length $xabbrev]} {
+           report-set xabbrev "(Flags: $xabbrev)"
+       } else {
+           report-set xabbrev "(No flags)"
+       }
     } else {
     } else {
-       report-set xabbrev "No flags in notes"
+       if {[string length $xabbrev]} {
+           report-set xabbrev "Notes flags: $xabbrev"
+       } else {
+           report-set xabbrev "No flags in notes"
+       }
     }
 }
 
     }
 }
 
@@ -469,13 +494,13 @@ proc begin-control-grid {cw count rows inrow} {
     return $cw
 }
 
     return $cw
 }
 
-proc make-control-grid-entry {cw kind ix ekind args} {
+proc make-control-grid-elem {cw kind ix ekind args} {
     upvar #0 control_grid_properties($cw) props
     manyset $props rows inrow
 
     set ew $cw.$ix
 
     upvar #0 control_grid_properties($cw) props
     manyset $props rows inrow
 
     set ew $cw.$ix
 
-    debug "MAKE-CONTROL-GRID-ENTRY $cw $kind $ix $ekind $rows $inrow $ew"
+    debug "MAKE-CONTROL-GRID-ELEM $cw $kind $ix $ekind $rows $inrow $ew"
 
     eval [list $ekind $ew] $args
 
 
     eval [list $ekind $ew] $args
 
@@ -519,7 +544,7 @@ proc populate-control-grid-tickboxes {cw rows inrow varsvn values flipvalues
     for {set ix 0} {$ix < $count} {incr ix} {
        set val [lindex $values $ix]
        set vars($val) [uplevel 1 $default_get]
     for {set ix 0} {$ix < $count} {incr ix} {
        set val [lindex $values $ix]
        set vars($val) [uplevel 1 $default_get]
-       set ew [make-control-grid-entry $cw ix $ix checkbutton \
+       set ew [make-control-grid-elem $cw ix $ix checkbutton \
                    -variable ${varsvn}($val) \
                    -font fixed \
                    -command [list redraw-needed c.-g.-tickbox $cw $val]]
                    -variable ${varsvn}($val) \
                    -font fixed \
                    -command [list redraw-needed c.-g.-tickbox $cw $val]]
@@ -528,7 +553,7 @@ proc populate-control-grid-tickboxes {cw rows inrow varsvn values flipvalues
            image { $ew configure -height 16 }
        }
     }
            image { $ew configure -height 16 }
        }
     }
-    [make-control-grid-entry $cw final invert button] \
+    [make-control-grid-elem $cw final invert button] \
        configure \
        -text flip -command [list control-tickbox-flip $varsvn $flipvalues] \
        -padx 0 -pady 0
        configure \
        -text flip -command [list control-tickbox-flip $varsvn $flipvalues] \
        -padx 0 -pady 0
@@ -536,9 +561,6 @@ proc populate-control-grid-tickboxes {cw rows inrow varsvn values flipvalues
 
 #---------- smashing ----------
 
 
 #---------- smashing ----------
 
-set smash_subclass 0
-set smash_owner 0
-
 proc smash-code {code} {
     manyset [split $code _] inport size subclass lockown xabbrev
 
 proc smash-code {code} {
     manyset [split $code _] inport size subclass lockown xabbrev
 
@@ -571,16 +593,32 @@ proc smash-code {code} {
        4 { set lockown 33 }
     }
 
        4 { set lockown 33 }
     }
 
+    global smash_xabbrev_map
+    set xabbrev [string map $smash_xabbrev_map $xabbrev]
+
     return [join [list $inport $smsize $subclass $lockown $xabbrev] _]
 }
 
 proc smash-prepare {} {
     return [join [list $inport $smsize $subclass $lockown $xabbrev] _]
 }
 
 proc smash-prepare {} {
-    global vc_codes smash_sizemap smash_size
+    global vc_codes smash_sizemap smash_size smash_sizeinexact
     set mapto {}
     set mapto {}
+    catch { unset smash_sizeplus }
     foreach size $vc_codes {
     foreach size $vc_codes {
-       if {!$smash_size($size)} { set mapto $size }
+       if {!$smash_size($size)} {
+           set mapto $size
+       } else {
+           set smash_sizeinexact($mapto) 1
+       }
        set smash_sizemap($size) $mapto
     }
        set smash_sizemap($size) $mapto
     }
+
+    global smash_xabbrev_a smash_xabbrev_b smash_xabbrev_map
+    set smash_xabbrev_map {}
+    foreach a [split $smash_xabbrev_a ""] b [split $smash_xabbrev_b ""] {
+       if {![string length $a]} continue
+       lappend smash_xabbrev_map $a $b
+    }
+    debug "SMASH-PREPAE xabbrev_map=[list $smash_xabbrev_map]"
 }
 
 proc make-smasher {sma label ekind} {
 }
 
 proc make-smasher {sma label ekind} {
@@ -591,7 +629,7 @@ proc make-radio-smasher {sma label variable descs rows inrow} {
     set w [make-smasher $sma $label frame]
     begin-control-grid $w [llength $descs] $rows $inrow
     for {set i 0} {$i < [llength $descs]} {incr i} {
     set w [make-smasher $sma $label frame]
     begin-control-grid $w [llength $descs] $rows $inrow
     for {set i 0} {$i < [llength $descs]} {incr i} {
-       make-control-grid-entry $w ix $i \
+       make-control-grid-elem $w ix $i \
            radiobutton \
            -variable $variable -value $i -command redraw-needed \
            -text [lindex $descs $i]
            radiobutton \
            -variable $variable -value $i -command redraw-needed \
            -text [lindex $descs $i]
@@ -606,11 +644,26 @@ proc make-smashers {} {
        image val { expr 0 } { expr {"icon/$vc_code2abbrev($val)"} }
     $cw.0 configure -state disabled
 
        image val { expr 0 } { expr {"icon/$vc_code2abbrev($val)"} }
     $cw.0 configure -state disabled
 
+    glset smash_subclass 0
     make-radio-smasher subclass Class smash_subclass \
        {Show Normal/LE Hide} 1 0
 
     make-radio-smasher subclass Class smash_subclass \
        {Show Normal/LE Hide} 1 0
 
+    global no_owners
+    glset smash_owner [expr {$no_owners ? 3 : 0}]
     make-radio-smasher owner Owner smash_owner \
        {Show Yours? {For you} Lock Hide} 2 3
     make-radio-smasher owner Owner smash_owner \
        {Show Yours? {For you} Lock Hide} 2 3
+
+    set cw [make-smasher xabbrev "Flags" frame]
+    foreach ix {1 3} ab {a b} width {14 12} {
+       set vn smash_xabbrev_$ab
+       global $vn
+       set $vn {}
+       entry $cw.$ix -textvariable $vn -width $width
+       trace add variable $vn write [list redraw-needed $vn]
+    }
+    set ix 0
+    foreach str {y/ / /d} { label $cw.$ix -text $str; incr ix 2 }
+    eval pack [lsort [winfo children $cw]] -side left
 }
 
 #---------- filtering ----------
 }
 
 #---------- filtering ----------
@@ -908,8 +961,18 @@ proc load-chart {} {
     }]]
 }
 
     }]]
 }
 
-
-set scale 16
+proc init-scales {} {
+    global scales scaleix scale
+    set defscale 16
+    set scales {1 2 3 4 5 6 8}
+    set e12 {10 12 15 18 22 27 33 39 47 56 68 82}
+    foreach t $e12 {
+       if {$t < $defscale} { set scaleix [llength $scales] }
+       lappend scales $t
+    }
+    foreach t [lrange $e12 0 6] { lappend scales [expr {$t * 10}] }
+    set scale [lindex $scales $scaleix]
+}
 
 proc coord {c} {
        global scale
 
 proc coord {c} {
        global scale
@@ -1192,10 +1255,14 @@ proc islandnames-handler {offset maxchars} {
 #---------- main user interface ----------
 
 proc widgets-setup {} {
 #---------- main user interface ----------
 
 proc widgets-setup {} {
-    global canvas debug pirate ocean filterstyle
+    global canvas debug pirate ocean filterstyle notes_loc
 
     wm geometry . 1200x800
 
     wm geometry . 1200x800
-    wm title . "where-vessels - $pirate on the $ocean ocean"
+    if {[string length $pirate]} {
+       wm title . "where-vessels - $pirate on the $ocean ocean"
+    } else {
+       wm title . "where-vessels - $ocean ocean"
+    }
 
     #----- map -----
 
 
     #----- map -----
 
@@ -1245,9 +1312,11 @@ proc widgets-setup {} {
     frame .cp.ctrl.zoom
     pack .cp.ctrl.zoom -side top
 
     frame .cp.ctrl.zoom
     pack .cp.ctrl.zoom -side top
 
-    button .cp.ctrl.zoom.out -text - -font {Courier 16} -command {zoom /2} -pady 0
-    button .cp.ctrl.zoom.in  -text + -font {Courier 16} -command {zoom *2} -pady 0
-    pack .cp.ctrl.zoom.out .cp.ctrl.zoom.in -side left
+    foreach inout {out in} minplus {- +} {
+       button .cp.ctrl.zoom.$inout -text $minplus -font {Courier 16} \
+           -command "zoom ${minplus}1" -pady 0
+       pack .cp.ctrl.zoom.$inout -side left
+    }
 
     parser-control-create .cp.ctrl.acquire \
        acquire Acquire \
 
     parser-control-create .cp.ctrl.acquire \
        acquire Acquire \
@@ -1258,9 +1327,13 @@ proc widgets-setup {} {
     parser-control-create .cp.ctrl.notes \
        notes "Reload notes" \
        "Vessel notes loading report" \
     parser-control-create .cp.ctrl.notes \
        notes "Reload notes" \
        "Vessel notes loading report" \
-       
+
     pack .cp.ctrl.notes -side top -pady 2
 
     pack .cp.ctrl.notes -side top -pady 2
 
+    if {![string length $notes_loc]} {
+       .cp.ctrl.notes.do configure -state disabled
+    }  
+       
     #----- island name count and copy -----
 
     label .islands.count
     #----- island name count and copy -----
 
     label .islands.count
@@ -1302,6 +1375,8 @@ proc widgets-setup {} {
 proc report-set {sw val} { .cp.report.details.$sw configure -text $val }
 
 proc show-report {islandname code} {
 proc report-set {sw val} { .cp.report.details.$sw configure -text $val }
 
 proc show-report {islandname code} {
+    global no_owners
+    
     .cp.report.island configure -text $islandname
 
     .cp.report.abbrev delete all
     .cp.report.island configure -text $islandname
 
     .cp.report.abbrev delete all
@@ -1318,8 +1393,8 @@ proc show-report {islandname code} {
 
     .cp.report.list delete 0 end
 
 
     .cp.report.list delete 0 end
 
-    foreach entry $k {
-       manyset $entry vid name owner
+    foreach elem $k {
+       manyset $elem vid name owner
        lappend owned($owner) $name
     }
 
        lappend owned($owner) $name
     }
 
@@ -1329,19 +1404,23 @@ proc show-report {islandname code} {
        } else {
            set owndesc "Owner unknown"
        }
        } else {
            set owndesc "Owner unknown"
        }
-       .cp.report.list insert end "$owndesc:"
+       if {!$no_owners} {
+           .cp.report.list insert end "$owndesc:"
+       }
        foreach name $owned($owner) {
            .cp.report.list insert end " $name"
        }
     }
 }
 
        foreach name $owned($owner) {
            .cp.report.list insert end " $name"
        }
     }
 }
 
-proc zoom {extail} {
-    global scale canvas
-    set nscale [expr "\$scale $extail"]
-    debug "ZOOM $scale $nscale"
-    if {$nscale < 1 || $nscale > 200} return
-    set scale $nscale
+proc zoom {amt} {
+    global scaleix scales scale canvas
+    incr scaleix $amt
+    if {$scaleix < 0} { set scaleix 0 }
+    set nscales [llength $scales]
+    if {$scaleix >= $nscales} { set scaleix [expr {$nscales-1}] }
+    set scale [lindex $scales $scaleix]
+    debug "ZOOM $amt $scaleix $scale"
     draw
 }
 
     draw
 }
 
@@ -1390,6 +1469,7 @@ proc invoke_notes {} {
 
 #---------- main program ----------
 
 
 #---------- main program ----------
 
+init-scales
 parseargs
 argdefaults
 httpclientsetup where-vessels
 parseargs
 argdefaults
 httpclientsetup where-vessels
@@ -1405,7 +1485,9 @@ if {[catch { parse-clipboard } emsg]} {
     puts stderr "$emsg\n$errorInfo"
     exit 1
 }
     puts stderr "$emsg\n$errorInfo"
     exit 1
 }
-after idle invoke_notes
+if {[string length $notes_loc]} {
+    after idle invoke_notes
+}
 
 draw
 
 
 draw
 
@@ -1416,4 +1498,10 @@ if {$debug} {
        -prompt2 { return "> " }
 }
 
        -prompt2 { return "> " }
 }
 
-# rsync -r --exclude=\*~ yarrg/icons/. ijackson@chiark.greenend.org.uk:/home/ftp/users/ijackson/yarrg/vessel-info/.
+# some runes I use:
+#
+# offline development
+#   ./where-vessels --notes ~/vessel-notes --vessel-info-source '' --pirate Aristarchus --ocean Midnight --debug --local-html-dir . --clipboard-file ~/clipboard-aristarchus
+#
+# updating published vessel info
+#   rsync -r --exclude=\*~ yarrg/icons/. ijackson@chiark.greenend.org.uk:/home/ftp/users/ijackson/yarrg/vessel-info/.