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