annotate pyink/tween.py @ 1150:6586cd10c92f

Refactory frameline.py
author Thinker K.F. Li <thinker@codemud.net>
date Sun, 26 Dec 2010 19:17:12 +0800
parents e14ec6d1a661
children 71c72e8d6755
rev   line source
1140
d4dbcb93aee0 Separate the tween from the main module.
wycc
parents:
diff changeset
1 # -*- indent-tabs-mode: t; tab-width: 8; python-indent: 4; -*-
d4dbcb93aee0 Separate the tween from the main module.
wycc
parents:
diff changeset
2 # vim: sw=4:ts=8:sts=4
d4dbcb93aee0 Separate the tween from the main module.
wycc
parents:
diff changeset
3 import traceback
d4dbcb93aee0 Separate the tween from the main module.
wycc
parents:
diff changeset
4 import math
d4dbcb93aee0 Separate the tween from the main module.
wycc
parents:
diff changeset
5 class TweenObject:
d4dbcb93aee0 Separate the tween from the main module.
wycc
parents:
diff changeset
6 def __init__(self,doc,dom):
d4dbcb93aee0 Separate the tween from the main module.
wycc
parents:
diff changeset
7 self.document = doc
d4dbcb93aee0 Separate the tween from the main module.
wycc
parents:
diff changeset
8 self.dom = dom
1141
8f0ee167c5b2 Fix the issue of the new DOM implementation
wycc
parents: 1140
diff changeset
9 try:
8f0ee167c5b2 Fix the issue of the new DOM implementation
wycc
parents: 1140
diff changeset
10 self.width = float(dom.getAttribute("width"))
8f0ee167c5b2 Fix the issue of the new DOM implementation
wycc
parents: 1140
diff changeset
11 self.height = float(dom.getAttribute("height"))
8f0ee167c5b2 Fix the issue of the new DOM implementation
wycc
parents: 1140
diff changeset
12 except:
8f0ee167c5b2 Fix the issue of the new DOM implementation
wycc
parents: 1140
diff changeset
13 self.width = 640
8f0ee167c5b2 Fix the issue of the new DOM implementation
wycc
parents: 1140
diff changeset
14 self.height = 480
1140
d4dbcb93aee0 Separate the tween from the main module.
wycc
parents:
diff changeset
15
d4dbcb93aee0 Separate the tween from the main module.
wycc
parents:
diff changeset
16 def updateMapping(self):
d4dbcb93aee0 Separate the tween from the main module.
wycc
parents:
diff changeset
17 self.nodeToItem={}
d4dbcb93aee0 Separate the tween from the main module.
wycc
parents:
diff changeset
18 root = self.dom
d4dbcb93aee0 Separate the tween from the main module.
wycc
parents:
diff changeset
19 self.updateMappingNode(root)
d4dbcb93aee0 Separate the tween from the main module.
wycc
parents:
diff changeset
20 def updateMappingNode(self,node):
d4dbcb93aee0 Separate the tween from the main module.
wycc
parents:
diff changeset
21 for c in node.childList():
d4dbcb93aee0 Separate the tween from the main module.
wycc
parents:
diff changeset
22 self.updateMappingNode(c)
1141
8f0ee167c5b2 Fix the issue of the new DOM implementation
wycc
parents: 1140
diff changeset
23 try:
8f0ee167c5b2 Fix the issue of the new DOM implementation
wycc
parents: 1140
diff changeset
24 self.nodeToItem[c.getAttribute("id")] = c
8f0ee167c5b2 Fix the issue of the new DOM implementation
wycc
parents: 1140
diff changeset
25 except:
8f0ee167c5b2 Fix the issue of the new DOM implementation
wycc
parents: 1140
diff changeset
26 pass
1140
d4dbcb93aee0 Separate the tween from the main module.
wycc
parents:
diff changeset
27 def updateTweenContent(self,obj, typ, source,dest,cur):
d4dbcb93aee0 Separate the tween from the main module.
wycc
parents:
diff changeset
28 """
1150
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1146
diff changeset
29 Update the content of the duplicate scene group. We will
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1146
diff changeset
30 use the (start,end) and cur to calculate the percentage of
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1146
diff changeset
31 the tween motion effect and then use it to update the
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1146
diff changeset
32 transform matrix of the duplicated scene group.
1140
d4dbcb93aee0 Separate the tween from the main module.
wycc
parents:
diff changeset
33 """
d4dbcb93aee0 Separate the tween from the main module.
wycc
parents:
diff changeset
34
d4dbcb93aee0 Separate the tween from the main module.
wycc
parents:
diff changeset
35 start = source.idx
d4dbcb93aee0 Separate the tween from the main module.
wycc
parents:
diff changeset
36 end = dest.idx
d4dbcb93aee0 Separate the tween from the main module.
wycc
parents:
diff changeset
37 print cur,start,end
d4dbcb93aee0 Separate the tween from the main module.
wycc
parents:
diff changeset
38 percent = (cur-start)*1.0/(end-start)
d4dbcb93aee0 Separate the tween from the main module.
wycc
parents:
diff changeset
39 i = 0
d4dbcb93aee0 Separate the tween from the main module.
wycc
parents:
diff changeset
40 s = source.ref.firstChild()
d4dbcb93aee0 Separate the tween from the main module.
wycc
parents:
diff changeset
41 d = dest.ref.firstChild()
d4dbcb93aee0 Separate the tween from the main module.
wycc
parents:
diff changeset
42 sources={}
d4dbcb93aee0 Separate the tween from the main module.
wycc
parents:
diff changeset
43 dests={}
1146
e14ec6d1a661 CHange the implementation to set the transformation matrix only. This is be more friendly for the animation inside the inskcape.
wycc
parents: 1141
diff changeset
44 # Collect ref from the obj
e14ec6d1a661 CHange the implementation to set the transformation matrix only. This is be more friendly for the animation inside the inskcape.
wycc
parents: 1141
diff changeset
45 o = obj.firstChild()
e14ec6d1a661 CHange the implementation to set the transformation matrix only. This is be more friendly for the animation inside the inskcape.
wycc
parents: 1141
diff changeset
46 maps={}
e14ec6d1a661 CHange the implementation to set the transformation matrix only. This is be more friendly for the animation inside the inskcape.
wycc
parents: 1141
diff changeset
47 while o:
e14ec6d1a661 CHange the implementation to set the transformation matrix only. This is be more friendly for the animation inside the inskcape.
wycc
parents: 1141
diff changeset
48 print "--->",o
e14ec6d1a661 CHange the implementation to set the transformation matrix only. This is be more friendly for the animation inside the inskcape.
wycc
parents: 1141
diff changeset
49 try:
e14ec6d1a661 CHange the implementation to set the transformation matrix only. This is be more friendly for the animation inside the inskcape.
wycc
parents: 1141
diff changeset
50 ref = o.getAttribute("ref")
e14ec6d1a661 CHange the implementation to set the transformation matrix only. This is be more friendly for the animation inside the inskcape.
wycc
parents: 1141
diff changeset
51 except:
e14ec6d1a661 CHange the implementation to set the transformation matrix only. This is be more friendly for the animation inside the inskcape.
wycc
parents: 1141
diff changeset
52 print o
e14ec6d1a661 CHange the implementation to set the transformation matrix only. This is be more friendly for the animation inside the inskcape.
wycc
parents: 1141
diff changeset
53 ref = None
e14ec6d1a661 CHange the implementation to set the transformation matrix only. This is be more friendly for the animation inside the inskcape.
wycc
parents: 1141
diff changeset
54
e14ec6d1a661 CHange the implementation to set the transformation matrix only. This is be more friendly for the animation inside the inskcape.
wycc
parents: 1141
diff changeset
55 if ref:
e14ec6d1a661 CHange the implementation to set the transformation matrix only. This is be more friendly for the animation inside the inskcape.
wycc
parents: 1141
diff changeset
56 maps[ref] = o
e14ec6d1a661 CHange the implementation to set the transformation matrix only. This is be more friendly for the animation inside the inskcape.
wycc
parents: 1141
diff changeset
57 o = o.next()
1140
d4dbcb93aee0 Separate the tween from the main module.
wycc
parents:
diff changeset
58 # Collect all objects
d4dbcb93aee0 Separate the tween from the main module.
wycc
parents:
diff changeset
59 while d:
d4dbcb93aee0 Separate the tween from the main module.
wycc
parents:
diff changeset
60 try:
1141
8f0ee167c5b2 Fix the issue of the new DOM implementation
wycc
parents: 1140
diff changeset
61 label = d.getAttribute("inkscape:label")
1140
d4dbcb93aee0 Separate the tween from the main module.
wycc
parents:
diff changeset
62 except:
1141
8f0ee167c5b2 Fix the issue of the new DOM implementation
wycc
parents: 1140
diff changeset
63 d = d.next()
1140
d4dbcb93aee0 Separate the tween from the main module.
wycc
parents:
diff changeset
64 continue
d4dbcb93aee0 Separate the tween from the main module.
wycc
parents:
diff changeset
65 dests[label] = d
1141
8f0ee167c5b2 Fix the issue of the new DOM implementation
wycc
parents: 1140
diff changeset
66 d = d.next()
1140
d4dbcb93aee0 Separate the tween from the main module.
wycc
parents:
diff changeset
67 # Check if the object in the source exists in the destination
d4dbcb93aee0 Separate the tween from the main module.
wycc
parents:
diff changeset
68 s = source.ref.firstChild()
d4dbcb93aee0 Separate the tween from the main module.
wycc
parents:
diff changeset
69 d = dest.ref.firstChild()
d4dbcb93aee0 Separate the tween from the main module.
wycc
parents:
diff changeset
70 while s:
d4dbcb93aee0 Separate the tween from the main module.
wycc
parents:
diff changeset
71 print s,d
1146
e14ec6d1a661 CHange the implementation to set the transformation matrix only. This is be more friendly for the animation inside the inskcape.
wycc
parents: 1141
diff changeset
72 sid = s.getAttribute("id")
e14ec6d1a661 CHange the implementation to set the transformation matrix only. This is be more friendly for the animation inside the inskcape.
wycc
parents: 1141
diff changeset
73 if maps.has_key(sid):
e14ec6d1a661 CHange the implementation to set the transformation matrix only. This is be more friendly for the animation inside the inskcape.
wycc
parents: 1141
diff changeset
74 o = maps[sid]
e14ec6d1a661 CHange the implementation to set the transformation matrix only. This is be more friendly for the animation inside the inskcape.
wycc
parents: 1141
diff changeset
75 else:
e14ec6d1a661 CHange the implementation to set the transformation matrix only. This is be more friendly for the animation inside the inskcape.
wycc
parents: 1141
diff changeset
76 o = None
1140
d4dbcb93aee0 Separate the tween from the main module.
wycc
parents:
diff changeset
77 try:
1141
8f0ee167c5b2 Fix the issue of the new DOM implementation
wycc
parents: 1140
diff changeset
78 label = s.getAttribute("inkscape:label")
1140
d4dbcb93aee0 Separate the tween from the main module.
wycc
parents:
diff changeset
79 # Use i8nkscape:label to identidy the equipvalent objects
d4dbcb93aee0 Separate the tween from the main module.
wycc
parents:
diff changeset
80 if label:
1150
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1146
diff changeset
81 if dests.has_key(label):
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1146
diff changeset
82 self.updateTweenObject(obj, typ, s,
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1146
diff changeset
83 dests[label], percent, o)
1141
8f0ee167c5b2 Fix the issue of the new DOM implementation
wycc
parents: 1140
diff changeset
84 s = s.next()
1140
d4dbcb93aee0 Separate the tween from the main module.
wycc
parents:
diff changeset
85 continue
d4dbcb93aee0 Separate the tween from the main module.
wycc
parents:
diff changeset
86 except:
d4dbcb93aee0 Separate the tween from the main module.
wycc
parents:
diff changeset
87 pass
d4dbcb93aee0 Separate the tween from the main module.
wycc
parents:
diff changeset
88 # Search obejcts in the destination
d4dbcb93aee0 Separate the tween from the main module.
wycc
parents:
diff changeset
89 while d:
d4dbcb93aee0 Separate the tween from the main module.
wycc
parents:
diff changeset
90 try:
1141
8f0ee167c5b2 Fix the issue of the new DOM implementation
wycc
parents: 1140
diff changeset
91 d.getAttribute("inkscape:label")
8f0ee167c5b2 Fix the issue of the new DOM implementation
wycc
parents: 1140
diff changeset
92 d = d.next()
1140
d4dbcb93aee0 Separate the tween from the main module.
wycc
parents:
diff changeset
93 continue
d4dbcb93aee0 Separate the tween from the main module.
wycc
parents:
diff changeset
94 except:
d4dbcb93aee0 Separate the tween from the main module.
wycc
parents:
diff changeset
95 pass
d4dbcb93aee0 Separate the tween from the main module.
wycc
parents:
diff changeset
96 if s.name() == d.name():
1146
e14ec6d1a661 CHange the implementation to set the transformation matrix only. This is be more friendly for the animation inside the inskcape.
wycc
parents: 1141
diff changeset
97 self.updateTweenObject(obj,typ,s,d,percent,o)
1141
8f0ee167c5b2 Fix the issue of the new DOM implementation
wycc
parents: 1140
diff changeset
98 d = d.next()
1140
d4dbcb93aee0 Separate the tween from the main module.
wycc
parents:
diff changeset
99 break
1141
8f0ee167c5b2 Fix the issue of the new DOM implementation
wycc
parents: 1140
diff changeset
100 d = d.next()
8f0ee167c5b2 Fix the issue of the new DOM implementation
wycc
parents: 1140
diff changeset
101 s = s.next()
1140
d4dbcb93aee0 Separate the tween from the main module.
wycc
parents:
diff changeset
102
d4dbcb93aee0 Separate the tween from the main module.
wycc
parents:
diff changeset
103 def parseTransform(self,obj):
d4dbcb93aee0 Separate the tween from the main module.
wycc
parents:
diff changeset
104 """
d4dbcb93aee0 Separate the tween from the main module.
wycc
parents:
diff changeset
105 Return the transform matrix of an object
d4dbcb93aee0 Separate the tween from the main module.
wycc
parents:
diff changeset
106 """
d4dbcb93aee0 Separate the tween from the main module.
wycc
parents:
diff changeset
107 try:
1141
8f0ee167c5b2 Fix the issue of the new DOM implementation
wycc
parents: 1140
diff changeset
108 t = obj.getAttribute("transform")
1140
d4dbcb93aee0 Separate the tween from the main module.
wycc
parents:
diff changeset
109 print t
d4dbcb93aee0 Separate the tween from the main module.
wycc
parents:
diff changeset
110 if t[0:9] == 'translate':
d4dbcb93aee0 Separate the tween from the main module.
wycc
parents:
diff changeset
111 print "translate"
d4dbcb93aee0 Separate the tween from the main module.
wycc
parents:
diff changeset
112 fields = t[10:].split(',')
d4dbcb93aee0 Separate the tween from the main module.
wycc
parents:
diff changeset
113 x = float(fields[0])
d4dbcb93aee0 Separate the tween from the main module.
wycc
parents:
diff changeset
114 fields = fields[1].split(')')
d4dbcb93aee0 Separate the tween from the main module.
wycc
parents:
diff changeset
115 y = float(fields[0])
d4dbcb93aee0 Separate the tween from the main module.
wycc
parents:
diff changeset
116 return [1,0,0,1,x,y]
d4dbcb93aee0 Separate the tween from the main module.
wycc
parents:
diff changeset
117 elif t[0:6] == 'matrix':
d4dbcb93aee0 Separate the tween from the main module.
wycc
parents:
diff changeset
118 print "matrix"
d4dbcb93aee0 Separate the tween from the main module.
wycc
parents:
diff changeset
119 fields=t[7:].split(')')
d4dbcb93aee0 Separate the tween from the main module.
wycc
parents:
diff changeset
120 fields = fields[0].split(',')
d4dbcb93aee0 Separate the tween from the main module.
wycc
parents:
diff changeset
121 return [float(fields[0]),float(fields[1]),float(fields[2]),float(fields[3]),float(fields[4]),float(fields[5])]
d4dbcb93aee0 Separate the tween from the main module.
wycc
parents:
diff changeset
122 except:
d4dbcb93aee0 Separate the tween from the main module.
wycc
parents:
diff changeset
123 #traceback.print_exc()
d4dbcb93aee0 Separate the tween from the main module.
wycc
parents:
diff changeset
124 return [1,0,0,1,0,0]
d4dbcb93aee0 Separate the tween from the main module.
wycc
parents:
diff changeset
125
d4dbcb93aee0 Separate the tween from the main module.
wycc
parents:
diff changeset
126 def invA(self,m):
d4dbcb93aee0 Separate the tween from the main module.
wycc
parents:
diff changeset
127 d = m[0]*m[3]-m[2]*m[1]
d4dbcb93aee0 Separate the tween from the main module.
wycc
parents:
diff changeset
128 return [m[3]/d, -m[1]/d, -m[2]/d, m[0]/d, (m[1]*m[5]-m[4]*m[3])/d, (m[4]*m[2]-m[0]*m[5])/d]
d4dbcb93aee0 Separate the tween from the main module.
wycc
parents:
diff changeset
129
d4dbcb93aee0 Separate the tween from the main module.
wycc
parents:
diff changeset
130 def mulA(self,a,b):
d4dbcb93aee0 Separate the tween from the main module.
wycc
parents:
diff changeset
131 return [a[0]*b[0]+a[1]*b[2],
d4dbcb93aee0 Separate the tween from the main module.
wycc
parents:
diff changeset
132 a[0]*b[1]+a[1]*b[3],
d4dbcb93aee0 Separate the tween from the main module.
wycc
parents:
diff changeset
133 a[2]*b[0]+a[3]*b[2],
d4dbcb93aee0 Separate the tween from the main module.
wycc
parents:
diff changeset
134 a[2]*b[1]+a[3]*b[3],
d4dbcb93aee0 Separate the tween from the main module.
wycc
parents:
diff changeset
135 a[0]*b[4]+a[1]*b[5]+a[4],
d4dbcb93aee0 Separate the tween from the main module.
wycc
parents:
diff changeset
136 a[2]*b[4]+a[3]*b[5]+a[5]]
d4dbcb93aee0 Separate the tween from the main module.
wycc
parents:
diff changeset
137
d4dbcb93aee0 Separate the tween from the main module.
wycc
parents:
diff changeset
138 def decomposition(self,m):
d4dbcb93aee0 Separate the tween from the main module.
wycc
parents:
diff changeset
139 """
d4dbcb93aee0 Separate the tween from the main module.
wycc
parents:
diff changeset
140 Decompose the affine matrix into production of translation,rotation,shear and scale.
d4dbcb93aee0 Separate the tween from the main module.
wycc
parents:
diff changeset
141 The algorithm is documented at http://lists.w3.org/Archives/Public/www-style/2010Jun/0602.html
d4dbcb93aee0 Separate the tween from the main module.
wycc
parents:
diff changeset
142 """
d4dbcb93aee0 Separate the tween from the main module.
wycc
parents:
diff changeset
143 if m[0]*m[3] == m[1]*m[2]:
d4dbcb93aee0 Separate the tween from the main module.
wycc
parents:
diff changeset
144 print "The affine matrix is singular"
d4dbcb93aee0 Separate the tween from the main module.
wycc
parents:
diff changeset
145 return [1,0,0,1,0,0]
d4dbcb93aee0 Separate the tween from the main module.
wycc
parents:
diff changeset
146 A=m[0]
d4dbcb93aee0 Separate the tween from the main module.
wycc
parents:
diff changeset
147 B=m[2]
d4dbcb93aee0 Separate the tween from the main module.
wycc
parents:
diff changeset
148 C=m[1]
d4dbcb93aee0 Separate the tween from the main module.
wycc
parents:
diff changeset
149 D=m[3]
d4dbcb93aee0 Separate the tween from the main module.
wycc
parents:
diff changeset
150 E=m[4]
d4dbcb93aee0 Separate the tween from the main module.
wycc
parents:
diff changeset
151 F=m[5]
d4dbcb93aee0 Separate the tween from the main module.
wycc
parents:
diff changeset
152 sx = math.sqrt(A*A+B*B)
d4dbcb93aee0 Separate the tween from the main module.
wycc
parents:
diff changeset
153 A = A/sx
d4dbcb93aee0 Separate the tween from the main module.
wycc
parents:
diff changeset
154 B = B/sx
d4dbcb93aee0 Separate the tween from the main module.
wycc
parents:
diff changeset
155 shear = m[0]*m[1]+m[2]*m[3]
d4dbcb93aee0 Separate the tween from the main module.
wycc
parents:
diff changeset
156 C = C - A*shear
d4dbcb93aee0 Separate the tween from the main module.
wycc
parents:
diff changeset
157 D = D - B*shear
d4dbcb93aee0 Separate the tween from the main module.
wycc
parents:
diff changeset
158 sy = math.sqrt(C*C+D*D)
d4dbcb93aee0 Separate the tween from the main module.
wycc
parents:
diff changeset
159 C = C/sy
d4dbcb93aee0 Separate the tween from the main module.
wycc
parents:
diff changeset
160 D = D/sy
d4dbcb93aee0 Separate the tween from the main module.
wycc
parents:
diff changeset
161 r = A*D-B*C
d4dbcb93aee0 Separate the tween from the main module.
wycc
parents:
diff changeset
162 if r == -1:
d4dbcb93aee0 Separate the tween from the main module.
wycc
parents:
diff changeset
163 shear = -shear
d4dbcb93aee0 Separate the tween from the main module.
wycc
parents:
diff changeset
164 sy = -sy
d4dbcb93aee0 Separate the tween from the main module.
wycc
parents:
diff changeset
165 R = math.atan2(B,A)
d4dbcb93aee0 Separate the tween from the main module.
wycc
parents:
diff changeset
166 return [sx,sy, R, E,F]
d4dbcb93aee0 Separate the tween from the main module.
wycc
parents:
diff changeset
167
d4dbcb93aee0 Separate the tween from the main module.
wycc
parents:
diff changeset
168
1146
e14ec6d1a661 CHange the implementation to set the transformation matrix only. This is be more friendly for the animation inside the inskcape.
wycc
parents: 1141
diff changeset
169 def updateTweenObject(self,obj,typ,s,d,p,newobj):
1140
d4dbcb93aee0 Separate the tween from the main module.
wycc
parents:
diff changeset
170 """
d4dbcb93aee0 Separate the tween from the main module.
wycc
parents:
diff changeset
171 Generate tweened object in the @obj by using s and d in the @p percent
d4dbcb93aee0 Separate the tween from the main module.
wycc
parents:
diff changeset
172 http://lists.w3.org/Archives/Public/www-style/2010Jun/0602.html
d4dbcb93aee0 Separate the tween from the main module.
wycc
parents:
diff changeset
173 """
1150
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1146
diff changeset
174 if typ == 1:
1140
d4dbcb93aee0 Separate the tween from the main module.
wycc
parents:
diff changeset
175 if s.name() == 'svg:g':
1150
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1146
diff changeset
176 if not newobj:
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1146
diff changeset
177 newobj = s.duplicate(self.document)
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1146
diff changeset
178 top = self.document.createElement("svg:g")
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1146
diff changeset
179 top.setAttribute("ref", s.getAttribute("id"))
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1146
diff changeset
180 top.appendChild(newobj)
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1146
diff changeset
181 obj.appendChild(top)
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1146
diff changeset
182 else:
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1146
diff changeset
183 top = newobj
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1146
diff changeset
184 pass
1140
d4dbcb93aee0 Separate the tween from the main module.
wycc
parents:
diff changeset
185 # Parse the translate or matrix
d4dbcb93aee0 Separate the tween from the main module.
wycc
parents:
diff changeset
186 sm = self.parseTransform(s)
d4dbcb93aee0 Separate the tween from the main module.
wycc
parents:
diff changeset
187 dm = self.parseTransform(d)
d4dbcb93aee0 Separate the tween from the main module.
wycc
parents:
diff changeset
188 top.setAttribute("transform","translate(%g,%g)" % ((dm[2]-sm[2])*p,(dm[5]-sm[5])*p))
d4dbcb93aee0 Separate the tween from the main module.
wycc
parents:
diff changeset
189 else:
1150
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1146
diff changeset
190 if not newobj:
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1146
diff changeset
191 top = s.duplicate(self.document)
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1146
diff changeset
192 top.setAttribute('ref', s.getAttribute('id'))
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1146
diff changeset
193 obj.appendChild(top)
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1146
diff changeset
194 else:
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1146
diff changeset
195 top = newobj
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1146
diff changeset
196 pass
1140
d4dbcb93aee0 Separate the tween from the main module.
wycc
parents:
diff changeset
197 try:
1141
8f0ee167c5b2 Fix the issue of the new DOM implementation
wycc
parents: 1140
diff changeset
198 sx = float(s.getAttribute("x"))
8f0ee167c5b2 Fix the issue of the new DOM implementation
wycc
parents: 1140
diff changeset
199 sy = float(s.getAttribute("y"))
8f0ee167c5b2 Fix the issue of the new DOM implementation
wycc
parents: 1140
diff changeset
200 dx = float(d.getAttribute("x"))
8f0ee167c5b2 Fix the issue of the new DOM implementation
wycc
parents: 1140
diff changeset
201 dy = float(d.getAttribute("y"))
1140
d4dbcb93aee0 Separate the tween from the main module.
wycc
parents:
diff changeset
202 tx = (dx-sx)*p
d4dbcb93aee0 Separate the tween from the main module.
wycc
parents:
diff changeset
203 ty = (dy-sy)*p
d4dbcb93aee0 Separate the tween from the main module.
wycc
parents:
diff changeset
204 print tx,ty
d4dbcb93aee0 Separate the tween from the main module.
wycc
parents:
diff changeset
205 top.setAttribute("transform","translate(%g,%g)" % (tx,ty))
d4dbcb93aee0 Separate the tween from the main module.
wycc
parents:
diff changeset
206 except:
d4dbcb93aee0 Separate the tween from the main module.
wycc
parents:
diff changeset
207 traceback.print_exc()
d4dbcb93aee0 Separate the tween from the main module.
wycc
parents:
diff changeset
208 pass
d4dbcb93aee0 Separate the tween from the main module.
wycc
parents:
diff changeset
209 pass
1150
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1146
diff changeset
210 elif typ == 2:
1146
e14ec6d1a661 CHange the implementation to set the transformation matrix only. This is be more friendly for the animation inside the inskcape.
wycc
parents: 1141
diff changeset
211 self.updateTweenObjectScale(obj,s,d,p,newobj)
1140
d4dbcb93aee0 Separate the tween from the main module.
wycc
parents:
diff changeset
212 pass
1150
6586cd10c92f Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents: 1146
diff changeset
213 elif typ == 0:
1140
d4dbcb93aee0 Separate the tween from the main module.
wycc
parents:
diff changeset
214 newobj = s.duplicate(self.document)
1141
8f0ee167c5b2 Fix the issue of the new DOM implementation
wycc
parents: 1140
diff changeset
215 newobj.setAttribute("ref", s.getAttribute("id"))
1140
d4dbcb93aee0 Separate the tween from the main module.
wycc
parents:
diff changeset
216 top = self.document.createElement("svg:g")
d4dbcb93aee0 Separate the tween from the main module.
wycc
parents:
diff changeset
217 top.appendChild(newobj)
d4dbcb93aee0 Separate the tween from the main module.
wycc
parents:
diff changeset
218 obj.appendChild(top)
d4dbcb93aee0 Separate the tween from the main module.
wycc
parents:
diff changeset
219 pass
d4dbcb93aee0 Separate the tween from the main module.
wycc
parents:
diff changeset
220
1146
e14ec6d1a661 CHange the implementation to set the transformation matrix only. This is be more friendly for the animation inside the inskcape.
wycc
parents: 1141
diff changeset
221 def updateTweenObjectScale(self,obj,s,d,p,newobj):
1140
d4dbcb93aee0 Separate the tween from the main module.
wycc
parents:
diff changeset
222 """
d4dbcb93aee0 Separate the tween from the main module.
wycc
parents:
diff changeset
223 Generate a new group which contains the original group and then
d4dbcb93aee0 Separate the tween from the main module.
wycc
parents:
diff changeset
224 add the transform matrix to generate a tween frame between the
d4dbcb93aee0 Separate the tween from the main module.
wycc
parents:
diff changeset
225 origin and destination scene group.
d4dbcb93aee0 Separate the tween from the main module.
wycc
parents:
diff changeset
226
d4dbcb93aee0 Separate the tween from the main module.
wycc
parents:
diff changeset
227 We will parse the transform matrix of the @s and @d and then
d4dbcb93aee0 Separate the tween from the main module.
wycc
parents:
diff changeset
228 generate the matrix which is (1-p) of @s and p percent of @d.
d4dbcb93aee0 Separate the tween from the main module.
wycc
parents:
diff changeset
229 """
1146
e14ec6d1a661 CHange the implementation to set the transformation matrix only. This is be more friendly for the animation inside the inskcape.
wycc
parents: 1141
diff changeset
230 if newobj == None:
e14ec6d1a661 CHange the implementation to set the transformation matrix only. This is be more friendly for the animation inside the inskcape.
wycc
parents: 1141
diff changeset
231 newobj = s.duplicate(self.document)
e14ec6d1a661 CHange the implementation to set the transformation matrix only. This is be more friendly for the animation inside the inskcape.
wycc
parents: 1141
diff changeset
232 top = self.document.createElement("svg:g")
e14ec6d1a661 CHange the implementation to set the transformation matrix only. This is be more friendly for the animation inside the inskcape.
wycc
parents: 1141
diff changeset
233 top.setAttribute("ref",s.getAttribute("id"))
e14ec6d1a661 CHange the implementation to set the transformation matrix only. This is be more friendly for the animation inside the inskcape.
wycc
parents: 1141
diff changeset
234 top.appendChild(newobj)
e14ec6d1a661 CHange the implementation to set the transformation matrix only. This is be more friendly for the animation inside the inskcape.
wycc
parents: 1141
diff changeset
235 obj.appendChild(top)
e14ec6d1a661 CHange the implementation to set the transformation matrix only. This is be more friendly for the animation inside the inskcape.
wycc
parents: 1141
diff changeset
236 else:
e14ec6d1a661 CHange the implementation to set the transformation matrix only. This is be more friendly for the animation inside the inskcape.
wycc
parents: 1141
diff changeset
237 top = newobj
e14ec6d1a661 CHange the implementation to set the transformation matrix only. This is be more friendly for the animation inside the inskcape.
wycc
parents: 1141
diff changeset
238 newobj = top.firstChild()
1140
d4dbcb93aee0 Separate the tween from the main module.
wycc
parents:
diff changeset
239
d4dbcb93aee0 Separate the tween from the main module.
wycc
parents:
diff changeset
240 if s.name() == 'svg:g':
d4dbcb93aee0 Separate the tween from the main module.
wycc
parents:
diff changeset
241 # Parse the translate or matrix
d4dbcb93aee0 Separate the tween from the main module.
wycc
parents:
diff changeset
242 #
d4dbcb93aee0 Separate the tween from the main module.
wycc
parents:
diff changeset
243 # D = B inv(A)
d4dbcb93aee0 Separate the tween from the main module.
wycc
parents:
diff changeset
244 try:
1141
8f0ee167c5b2 Fix the issue of the new DOM implementation
wycc
parents: 1140
diff changeset
245 item = self.nodeToItem[s.getAttribute("id")]
1140
d4dbcb93aee0 Separate the tween from the main module.
wycc
parents:
diff changeset
246 (ox,oy) = item.getCenter()
d4dbcb93aee0 Separate the tween from the main module.
wycc
parents:
diff changeset
247 except:
d4dbcb93aee0 Separate the tween from the main module.
wycc
parents:
diff changeset
248 ox = 0
d4dbcb93aee0 Separate the tween from the main module.
wycc
parents:
diff changeset
249 oy = 0
d4dbcb93aee0 Separate the tween from the main module.
wycc
parents:
diff changeset
250 try:
1141
8f0ee167c5b2 Fix the issue of the new DOM implementation
wycc
parents: 1140
diff changeset
251 item = self.nodeToItem[d.getAttribute("id")]
1140
d4dbcb93aee0 Separate the tween from the main module.
wycc
parents:
diff changeset
252 (dx,dy) = item.getCenter()
d4dbcb93aee0 Separate the tween from the main module.
wycc
parents:
diff changeset
253 except:
d4dbcb93aee0 Separate the tween from the main module.
wycc
parents:
diff changeset
254 dx = 0
d4dbcb93aee0 Separate the tween from the main module.
wycc
parents:
diff changeset
255 dy = 0
d4dbcb93aee0 Separate the tween from the main module.
wycc
parents:
diff changeset
256
d4dbcb93aee0 Separate the tween from the main module.
wycc
parents:
diff changeset
257 sm = self.parseTransform(s)
d4dbcb93aee0 Separate the tween from the main module.
wycc
parents:
diff changeset
258 ss = self.decomposition(sm)
d4dbcb93aee0 Separate the tween from the main module.
wycc
parents:
diff changeset
259 dm = self.parseTransform(d)
d4dbcb93aee0 Separate the tween from the main module.
wycc
parents:
diff changeset
260 dd = self.decomposition(dm)
d4dbcb93aee0 Separate the tween from the main module.
wycc
parents:
diff changeset
261 sx = (ss[0]*(1-p)+dd[0]*p)/ss[0]
d4dbcb93aee0 Separate the tween from the main module.
wycc
parents:
diff changeset
262 sy = (ss[1]*(1-p)+dd[1]*p)/ss[0]
d4dbcb93aee0 Separate the tween from the main module.
wycc
parents:
diff changeset
263 a = ss[2]*(1-p)+dd[2]*p-ss[2]
1146
e14ec6d1a661 CHange the implementation to set the transformation matrix only. This is be more friendly for the animation inside the inskcape.
wycc
parents: 1141
diff changeset
264 tx = ox*(1-p)+dx*p
e14ec6d1a661 CHange the implementation to set the transformation matrix only. This is be more friendly for the animation inside the inskcape.
wycc
parents: 1141
diff changeset
265 ty = oy*(1-p)+dy*p
1140
d4dbcb93aee0 Separate the tween from the main module.
wycc
parents:
diff changeset
266 m = [math.cos(a),math.sin(a),-math.sin(a),math.cos(a),0,0]
d4dbcb93aee0 Separate the tween from the main module.
wycc
parents:
diff changeset
267 m = self.mulA([sx,0,0,sy,0,0],m)
d4dbcb93aee0 Separate the tween from the main module.
wycc
parents:
diff changeset
268 m = self.mulA(m,[1,0,0,1,-ox,oy-self.height])
d4dbcb93aee0 Separate the tween from the main module.
wycc
parents:
diff changeset
269 m = self.mulA([1,0,0,1,tx,self.height-ty],m)
d4dbcb93aee0 Separate the tween from the main module.
wycc
parents:
diff changeset
270
d4dbcb93aee0 Separate the tween from the main module.
wycc
parents:
diff changeset
271 top.setAttribute("transform","matrix(%g,%g,%g,%g,%g,%g)" % (m[0],m[2],m[1],m[3],m[4],m[5]))
d4dbcb93aee0 Separate the tween from the main module.
wycc
parents:
diff changeset
272 else:
d4dbcb93aee0 Separate the tween from the main module.
wycc
parents:
diff changeset
273 try:
1146
e14ec6d1a661 CHange the implementation to set the transformation matrix only. This is be more friendly for the animation inside the inskcape.
wycc
parents: 1141
diff changeset
274 try:
e14ec6d1a661 CHange the implementation to set the transformation matrix only. This is be more friendly for the animation inside the inskcape.
wycc
parents: 1141
diff changeset
275 sw = float(s.getAttribute("width"))
e14ec6d1a661 CHange the implementation to set the transformation matrix only. This is be more friendly for the animation inside the inskcape.
wycc
parents: 1141
diff changeset
276 except:
e14ec6d1a661 CHange the implementation to set the transformation matrix only. This is be more friendly for the animation inside the inskcape.
wycc
parents: 1141
diff changeset
277 sw = 1
e14ec6d1a661 CHange the implementation to set the transformation matrix only. This is be more friendly for the animation inside the inskcape.
wycc
parents: 1141
diff changeset
278 try:
e14ec6d1a661 CHange the implementation to set the transformation matrix only. This is be more friendly for the animation inside the inskcape.
wycc
parents: 1141
diff changeset
279 sh = float(s.getAttribute("height"))
e14ec6d1a661 CHange the implementation to set the transformation matrix only. This is be more friendly for the animation inside the inskcape.
wycc
parents: 1141
diff changeset
280 except:
e14ec6d1a661 CHange the implementation to set the transformation matrix only. This is be more friendly for the animation inside the inskcape.
wycc
parents: 1141
diff changeset
281 sh = 1
e14ec6d1a661 CHange the implementation to set the transformation matrix only. This is be more friendly for the animation inside the inskcape.
wycc
parents: 1141
diff changeset
282 try:
e14ec6d1a661 CHange the implementation to set the transformation matrix only. This is be more friendly for the animation inside the inskcape.
wycc
parents: 1141
diff changeset
283 dw = float(d.getAttribute("width"))
e14ec6d1a661 CHange the implementation to set the transformation matrix only. This is be more friendly for the animation inside the inskcape.
wycc
parents: 1141
diff changeset
284 except:
e14ec6d1a661 CHange the implementation to set the transformation matrix only. This is be more friendly for the animation inside the inskcape.
wycc
parents: 1141
diff changeset
285 dw = 1
e14ec6d1a661 CHange the implementation to set the transformation matrix only. This is be more friendly for the animation inside the inskcape.
wycc
parents: 1141
diff changeset
286 try:
e14ec6d1a661 CHange the implementation to set the transformation matrix only. This is be more friendly for the animation inside the inskcape.
wycc
parents: 1141
diff changeset
287 dh = float(d.getAttribute("height"))
e14ec6d1a661 CHange the implementation to set the transformation matrix only. This is be more friendly for the animation inside the inskcape.
wycc
parents: 1141
diff changeset
288 except:
e14ec6d1a661 CHange the implementation to set the transformation matrix only. This is be more friendly for the animation inside the inskcape.
wycc
parents: 1141
diff changeset
289 dh = 1
1140
d4dbcb93aee0 Separate the tween from the main module.
wycc
parents:
diff changeset
290 try:
1141
8f0ee167c5b2 Fix the issue of the new DOM implementation
wycc
parents: 1140
diff changeset
291 item = self.nodeToItem[s.getAttribute("id")]
1140
d4dbcb93aee0 Separate the tween from the main module.
wycc
parents:
diff changeset
292 (ox,oy) = item.getCenter()
d4dbcb93aee0 Separate the tween from the main module.
wycc
parents:
diff changeset
293 except:
d4dbcb93aee0 Separate the tween from the main module.
wycc
parents:
diff changeset
294 ox = 0
d4dbcb93aee0 Separate the tween from the main module.
wycc
parents:
diff changeset
295 oy = 0
d4dbcb93aee0 Separate the tween from the main module.
wycc
parents:
diff changeset
296 try:
1141
8f0ee167c5b2 Fix the issue of the new DOM implementation
wycc
parents: 1140
diff changeset
297 item = self.nodeToItem[d.getAttribute("id")]
1140
d4dbcb93aee0 Separate the tween from the main module.
wycc
parents:
diff changeset
298 (dx,dy) = item.getCenter()
d4dbcb93aee0 Separate the tween from the main module.
wycc
parents:
diff changeset
299 except:
d4dbcb93aee0 Separate the tween from the main module.
wycc
parents:
diff changeset
300 dx = 0
d4dbcb93aee0 Separate the tween from the main module.
wycc
parents:
diff changeset
301 dy = 0
d4dbcb93aee0 Separate the tween from the main module.
wycc
parents:
diff changeset
302 try:
d4dbcb93aee0 Separate the tween from the main module.
wycc
parents:
diff changeset
303 sm = self.parseTransform(s)
d4dbcb93aee0 Separate the tween from the main module.
wycc
parents:
diff changeset
304 ss = self.decomposition(sm)
d4dbcb93aee0 Separate the tween from the main module.
wycc
parents:
diff changeset
305 except:
d4dbcb93aee0 Separate the tween from the main module.
wycc
parents:
diff changeset
306 ss = [1,1,0,0,0]
d4dbcb93aee0 Separate the tween from the main module.
wycc
parents:
diff changeset
307 pass
d4dbcb93aee0 Separate the tween from the main module.
wycc
parents:
diff changeset
308 try:
d4dbcb93aee0 Separate the tween from the main module.
wycc
parents:
diff changeset
309 dm = self.parseTransform(d)
d4dbcb93aee0 Separate the tween from the main module.
wycc
parents:
diff changeset
310 dd = self.decomposition(dm)
1146
e14ec6d1a661 CHange the implementation to set the transformation matrix only. This is be more friendly for the animation inside the inskcape.
wycc
parents: 1141
diff changeset
311 print "dd=",dd
1140
d4dbcb93aee0 Separate the tween from the main module.
wycc
parents:
diff changeset
312 except:
d4dbcb93aee0 Separate the tween from the main module.
wycc
parents:
diff changeset
313 dd = [1,1,0,0,0]
1146
e14ec6d1a661 CHange the implementation to set the transformation matrix only. This is be more friendly for the animation inside the inskcape.
wycc
parents: 1141
diff changeset
314 dd[0] = dd[0]*dw/sw
e14ec6d1a661 CHange the implementation to set the transformation matrix only. This is be more friendly for the animation inside the inskcape.
wycc
parents: 1141
diff changeset
315 dd[1] = dd[1]*dh/sh
e14ec6d1a661 CHange the implementation to set the transformation matrix only. This is be more friendly for the animation inside the inskcape.
wycc
parents: 1141
diff changeset
316 print "ss[0]=",ss[0],"dd[0]=",dd[0]
1140
d4dbcb93aee0 Separate the tween from the main module.
wycc
parents:
diff changeset
317 sx = (ss[0]*(1-p)+dd[0]*p)/ss[0]
d4dbcb93aee0 Separate the tween from the main module.
wycc
parents:
diff changeset
318 sy = (ss[1]*(1-p)+dd[1]*p)/ss[1]
1146
e14ec6d1a661 CHange the implementation to set the transformation matrix only. This is be more friendly for the animation inside the inskcape.
wycc
parents: 1141
diff changeset
319 print "sx=",sx,"sy=",sy
1140
d4dbcb93aee0 Separate the tween from the main module.
wycc
parents:
diff changeset
320 a = ss[2]*(1-p)+dd[2]*p-ss[2]
d4dbcb93aee0 Separate the tween from the main module.
wycc
parents:
diff changeset
321 tx = ox*(1-p)+dx*p
d4dbcb93aee0 Separate the tween from the main module.
wycc
parents:
diff changeset
322 ty = oy*(1-p)+dy*p
d4dbcb93aee0 Separate the tween from the main module.
wycc
parents:
diff changeset
323 m = [math.cos(a),math.sin(a),-math.sin(a),math.cos(a),0,0]
d4dbcb93aee0 Separate the tween from the main module.
wycc
parents:
diff changeset
324 m = self.mulA([sx,0,0,sy,0,0],m)
d4dbcb93aee0 Separate the tween from the main module.
wycc
parents:
diff changeset
325 m = self.mulA(m,[1,0,0,1,-ox,oy-self.height])
d4dbcb93aee0 Separate the tween from the main module.
wycc
parents:
diff changeset
326 m = self.mulA([1,0,0,1,tx,self.height-ty],m)
d4dbcb93aee0 Separate the tween from the main module.
wycc
parents:
diff changeset
327
d4dbcb93aee0 Separate the tween from the main module.
wycc
parents:
diff changeset
328 top.setAttribute("transform","matrix(%g,%g,%g,%g,%g,%g)" % (m[0],m[2],m[1],m[3],m[4],m[5]))
d4dbcb93aee0 Separate the tween from the main module.
wycc
parents:
diff changeset
329 except:
d4dbcb93aee0 Separate the tween from the main module.
wycc
parents:
diff changeset
330 traceback.print_exc()