1 # anm-view.tcl --
2 #
3 # FIXME: This file needs a description here.
4 #
5 # Copyright (c) 1993-2002 The Regents of the University of California.
6 # All rights reserved.
7 #
8 # Redistribution and use in source and binary forms, with or without
9 # modification, are permitted provided that the following conditions are met:
10 #
11 # A. Redistributions of source code must retain the above copyright notice,
12 # this list of conditions and the following disclaimer.
13 # B. Redistributions in binary form must reproduce the above copyright notice,
14 # this list of conditions and the following disclaimer in the documentation
15 # and/or other materials provided with the distribution.
16 # C. Neither the names of the copyright holders nor the names of its
17 # contributors may be used to endorse or promote products derived from this
18 # software without specific prior written permission.
19 #
20 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS''
21 # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 # ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR
24 # ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
26 # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
27 # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
28 # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30
31
32 # The AnmView class in charge of displaying animation objects.
33 #
34 Class AnmView
35
36 AnmView instproc init {{pathname {}}} {
37 $self instvar aseq_ wgt_ tools_ pathname_ objectIds_
38 $self instvar staticIds_ wpath_ fpath_
39
40 # null pathname means we generate one on the fly
41 if {$pathname==""} {
42 set pathname .ato_$self
43 }
44 set pathname_ $pathname
45 # DbgOut "creating $pathname_"
46
47 toplevel $pathname_
48 set fpath_ [frame $pathname.af -relief ridge]
49 pack $fpath_ -fill both -side top -expand 1
50
51 set wpath_ $fpath_.dwgt
52 set wgt_ [new DrawBoardWidget $wpath_]
53 pack $wpath_ -fill both -side top -expand 1
54 $wgt_ attach_painter $self
55
56 # tkwait visibility $wgtpath
57 # update idletasks
58 wm withdraw $pathname
59 wm deiconify $pathname
60 wm geometry $pathname 500x400
61
62 set objectIds_ ""
63 set staticIds_ ""
64 # DbgOut end init [winfo exists $wgtpath]
65 }
66
67 AnmView instproc destroy {} {
68 $self instvar datasrc_ pathname_
69 delete $datasrc_
70 destroy $pathname_
71 }
72
73 AnmView instproc path {} {
74 return [$self set pathname_]
75 }
76
77 AnmView instproc wpath {} {
78 return [$self set wpath_]
79 }
80
81 AnmView instproc fpath {} {
82 return [$self set fpath_]
83 }
84
85 AnmView instproc attach_session {session} {
86 set session_ $session
87 }
88
89 # Note: AnmView takes responsibilities to destroy datasrc
90 AnmView instproc attach_datasrc {datasrc} {
91 $self instvar datasrc_ mintime_ maxtime_
92 set datasrc_ $datasrc
93 }
94
95 # tells all the non-static animation objects that the current time is t
96 # they should remove themselves if they are no longer active
97 AnmView instproc update {t} {
98 $self instvar objects_
99 if [array exists objects_] {
100 foreach elt [array names objects_] {
101 $objects_($elt) update $t
102 }
103 }
104 }
105
106 AnmView instproc refresh {t} {
107 [$self set wgt_] refresh
108 # DbgOut refresh $t
109 # update idletasks
110 }
111
112 AnmView instproc draw {} {
113 $self instvar objects_ damage_ objectIds_ staticIds_ datasrc_
114 $self next
115 set now [$datasrc_ now]
116 # DbgOut draw $now $staticIds_ $objectIds_
117
118 if ![array exists objects_] { return }
119 # DbgVar objectIds_ staticIds_
120 foreach elt $staticIds_ {
121 $objects_($elt) draw $now
122 }
123 foreach elt $objectIds_ {
124 $objects_($elt) draw $now
125 }
126
127 return
128 }
129
130 AnmView instproc setFontByIdx {index font color} {
131 $self instvar fonts_ nextFontId_ wgt_
132
133 if ![info exists nextFontId_] {
134 set nextFontId_ 0
135 }
136 $wgt_ set_font $nextFontId_ $font $color
137 set fonts_($font,$color) $nextFontId_
138 incr nextFontId_
139 }
140
141 # computes the bounding bbox of all the objects
142 AnmView instproc bbox {} {
143 $self instvar objects_ bbox_
144 if [info exists bbox_] {
145 return $bbox_
146 }
147 set bbox {0 0 0 0}
148 foreach elt [array names objects_] {
149 eval $objects_($elt) merge bbox
150 }
151 DbgOut "bbox:$bbox"
152 return $bbox
153 }
154
155 AnmView instproc setBBox {bbox} {
156 $self set bbox_ $bbox
157 }
158
159 AnmView instproc resize {} {
160 [$self set wgt_] resize
161 }
162
163 # returns the lowest id of objects that are currently active
164 AnmView instproc oldestEId {} {
165 $self instvar objectIds_ objects_
166 if {"$objectIds_"==""} return ""
167 return [lindex $objectIds_ 0]
168 }
169
170 # returns the lowest id of objects that are currently active
171 AnmView instproc newestEId {} {
172 $self instvar objectIds_ objects_ maxId_
173 if {"$objectIds_"==""} return ""
174 return [lindex $objectIds_ end]
175 }
176
177 # this procedure is optimized for inserting mostly from the back
178 proc insertSorted {vl item} {
179 upvar $vl l
180 for {set i [expr [llength $l] - 1]} {$i>=0} {incr i -1} {
181 if {[lindex $l $i] < $item} {
182 break
183 }
184 }
185 incr i
186 set l [linsert $l $i $item]
187 }
188
189 # REVIEW: make sure we don't put 2 elements into 1 slot!
190 AnmView instproc insert_AnmObj {obj} {
191 $self instvar objects_ wgt_ objectIds_ staticIds_
192 # DbgOut "insertANM $obj [$obj info class]"
193
194 set id [$obj eId]
195 if [info exists objects_($id)] {
196 DbgOut skipping duplicate object id $id
197 return
198 }
199 set objects_($id) $obj
200 $obj set_drawboard $self $wgt_
201
202 if {![$obj isStatic]} {
203 insertSorted objectIds_ $id
204 } else {
205 insertSorted staticIds_ $id
206 }
207 }
208
209 AnmView instproc remove {id} {
210 $self instvar objects_ objectIds_
211 $self next
212
213 # DbgOut remove_AnmObj $id now [[$self set datasrc_] now] \
214 # s-e [$objects_($id) set sT_] [$objects_($id) set eT_]
215
216 if ![info exists objects_($id)] {
217 DbgOut "[$self info class] remove: non-existent object"
218 return
219 }
220 # DbgOut "Deleting pkt: $objects_($id)"
221
222 # could be a static object or non-static
223 set ix [lsearch -exact $objectIds_ $id]
224 set ix1 -1
225 if {$ix >= 0} {
226 set objectIds_ [lreplace $objectIds_ $ix $ix]
227 } else {
228 DbgOut "removing static object"
229 set ix1 [lsearch -exact $staticIds_ $id]
230 DbgAssert [expr $ix1 >= 0]
231 set staticIds_ [lreplace $staticIds_ $ix1 $ix1]
232 }
233 DbgAssert [expr $ix >= 0 || $ix1 >= 0]
234 # DbgOut "objectIds_: $objectIds_"
235
236 # NOTE: we have to remove it AFTER, otherwise there would be
237 # an instant we there is an objectIds_ without an objects_!
238 # REVIEW: the above condition might no longer be neccessary
239 delete $objects_($id)
240 unset objects_($id)
241 }
242
This page was automatically generated by the
LXR engine.
Visit the LXR main site for more
information.