File: coverage_frames.tcl

package info (click to toggle)
savi 1.6.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,932 kB
  • sloc: ansic: 7,054; tcl: 5,755; makefile: 270; sh: 237
file content (96 lines) | stat: -rw-r--r-- 2,769 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#
######################################################
#
#  SaVi by Lloyd Wood (lloydwood@users.sourceforge.net),
#          Patrick Worfolk (worfolk@alum.mit.edu) and
#          Robert Thurman.
#
#  Copyright (c) 1997 by The Geometry Center.
#  Also Copyright (c) 2017 by Lloyd Wood.
#
#  This file is part of SaVi.  SaVi is free software;
#  you can redistribute it and/or modify it only under
#  the terms given in the file COPYRIGHT which you should
#  have received along with this file.  SaVi may be
#  obtained from:
#  http://savi.sourceforge.net/
#  http://www.geom.uiuc.edu/locate/SaVi
#
######################################################
#
# coverage_frames.tcl
#
# $Id: coverage_frames.tcl 8 2019-01-24 04:33:00Z lloydwood $

proc coverage_frames(build) {} {
    global total_frames

    if {[eval window(raise) coverage_frames]} return

    set name [build_Toplevel coverage_frames]

    wm protocol $name WM_DELETE_WINDOW coverage_frames(dismiss)

    build_Title $name "Choose no. of frames to save..."

    build_LabelEntryColumns $name total_frames \
        {ientry "" {total_frames} } \
	{text "" {frames} }

    bind $name.total_frames.c0.0 <Return> {coverage_frames(save) $total_frames}

    build_Buttonbar $name dbbar \
	{"10" "coverage_frames(save) 10"} \
	{"50" "coverage_frames(save) 50"} \
        {"100" "coverage_frames(save) 100"} \
        {"500" "coverage_frames(save) 500"} \
	{"Cancel" "coverage_frames(dismiss)"} \
        {"Save" "coverage_frames(save) $total_frames"}

    update
}

proc coverage_frames(save) v {
    global im IM_H IM_W
    global user_file_dir

    if {$v < 0} return

    coverage_frames(dismiss)

    set types {
        {"SaVi coverage animation"  {.gif} }
    }

    set filename [tk_getSaveFile -initialdir "$user_file_dir" -filetypes $types \
	          -title "SaVi: save frames to folder" ]

    if {"$filename" == ""} return

    if {$v == 1} {
        # write a single image.
        $im write "$user_file_dir$filename" -format gif -from 0 0 $IM_W $IM_H
    } else {
        set gifsicle "gifsicle"
        set files "exec $gifsicle -O3"
        set rmfiles "exec rm"
	for {set j 0} {$j < $v} {incr j} {
            set n  [format "%07d" $j]
            set files "$files $filename-$n"
            set rmfiles "$rmfiles $filename-$n"
            $im write "$filename-$n" -format gif -from 0 0 $IM_W $IM_H
            main(forw_step)
	}
        if {[catch {eval $files > $filename}]} {
           puts stderr "\nSaVi: could not run $gifsicle successfully. Is $gifsicle installed?"
        } else {
           puts stderr "\nSaVi: told $gifsicle to save animation of $v frames in $filename"
        }
        eval $rmfiles
    }
}

proc coverage_frames(dismiss) {} {

    destroy .coverage_frames
}