changeset 1294:082fff7e9604

merge
author Thinker K.F. Li <thinker@codemud.net>
date Sat, 15 Jan 2011 23:07:29 +0800
parents 10bffaffef82 (diff) 99de83340782 (current diff)
children 71118bff7d61
files pyink/MBScene.py pyink/domview.py pyink/domview_ui.py
diffstat 3 files changed, 92 insertions(+), 61 deletions(-) [+]
line wrap: on
line diff
--- a/pyink/MBScene.py	Sat Jan 15 21:19:50 2011 +0800
+++ b/pyink/MBScene.py	Sat Jan 15 23:07:29 2011 +0800
@@ -128,7 +128,7 @@
 	# Create a key frame which link to the previous key frame
 	scene_group = self._domviewui.get_key_group(layer_idx, start)
 	self._domviewui.mark_key(layer_idx, frame_idx)
-	self._domviewui.link_key_group(layer_idx, start, frame_idx)
+	self._domviewui.clone_key_group(layer_idx, start, frame_idx)
 	self._director.show_scene(frame_idx)
 	self.selectSceneObject(layer_idx, frame_idx)
 	pass
--- a/pyink/domview.py	Sat Jan 15 21:19:50 2011 +0800
+++ b/pyink/domview.py	Sat Jan 15 23:07:29 2011 +0800
@@ -235,12 +235,11 @@
 		continue
 
 	    try:
-	    	ref = scene_node.getAttribute('ref')
 		start, end, scene_type = self.parse_one_scene(scene_node)
-	    except:
+                group_id = scene_node.getAttribute("ref")
+	    except:             # the scene node is incompleted.
 		continue
 	    
-	    group_id = scene_node.getAttribute("ref")
 	    self._group2scene[group_id] = scene_node
 	    pass
 	pass
@@ -706,18 +705,13 @@
 	    
 	    if end < frame_idx:
 		continue
-
+            
 	    if start > last_rm:	# this scene is at right side
 		self.chg_scene_node(scene_node,
 				    start=(start - num),
 				    end=(end - num))
-	    elif start >= frame_idx:
-	        self.rm_scene_node_n_group(scene_node)
-	        pass
 	    else:	 # this scene is covered by removing range
-		self.chg_scene_node(scene_node,
-				    start=start,
-				    end=(end - num))
+                self.rm_scene_node_n_group(scene_node)
 		pass
 	    pass
 	pass
@@ -732,15 +726,15 @@
     def copy_group_children(self, src_group, dst_group):
 	# Search for the duplicated group
 	doc = self._doc
-	
-	dup_group = src_group.duplicate(doc)
+        
+        dup_group = src_group.duplicate(doc)
         
 	old_nodes = _DOM_iterator(src_group)
-	new_nodes = _DOM_iterator(dup_group)
+        new_nodes = _DOM_iterator(dup_group)
         new_gids = set()
 	for old_node in old_nodes:
 	    old_node_id = old_node.getAttribute('id')
-	    new_node = new_nodes.next()
+            new_node = new_nodes.next()
 	    new_node.setAttribute('ns0:duplicate-src', old_node_id)
             
             #
@@ -758,42 +752,30 @@
             new_node.setAttribute('id', gid)
 	    pass
 
-	for child in dup_group.childList():
-	    dup_group.removeChild(child) # prvent from crash
-	    dst_group.appendChild(child)
-	    pass
+        for child in dup_group.childList():
+            dup_group.removeChild(child) # prevent from crash
+            dst_group.append(child)
+            pass
 	pass
+
+    ## \brief Clone children of a source group to a destinate group.
+    #
+    # It create a 'svg:use' node for every child of the source group,
+    # and append nodes to the desitnate group.
+    #
+    def clone_group_children(self, src_group, dst_group):
+        doc = self._doc
+
+        for src_child in src_group.childList():
+            src_child_id = src_child.getAttribute('id')
+            dst_child_id = self.new_id()
+            
+            dst_child = doc.createElement('svg:use')
+            dst_child.setAttribute('id', dst_child_id)
+            dst_child.setAttribute('xlink:href', '#' + src_child_id)
+            dst_child.setAttribute('ns0:duplicate-src', src_child_id)
+            dst_group.append(child)
+            pass
+        pass
     pass
 
-    ## \brief Link children of a group.
-    #
-    # Clone children of a group, and append them to another group.
-    #
-    def link_group_children(self, src_group, dst_group):
-	# Search for the duplicated group
-	doc = self._doc
-	old_nodes = _DOM_iterator(src_group)
-        new_gids = set()
-	for old_node in old_nodes:
-	    old_node_id = old_node.getAttribute('id')
-	    new_node = doc.createElement("svg:use")
-	    new_node.setAttribute("xlink:href",'#'+old_node_id)
-	    new_node.setAttribute('ns0:duplicate-src', old_node_id)
-            
-            #
-            # Change ID here, or inkscape would insert the node with
-            # the same ID, and change it later to avoid duplication.
-            # But, our event handler would be called before changing
-            # ID.  It would confuse our code.  We change ID of nodes
-            # before inserting them into the DOM-tree.
-            #
-            gid = self.new_id()
-            while gid in new_gids:
-                gid = self.new_id()
-                pass
-            new_gids.add(gid)
-            new_node.setAttribute('id', gid)
-	    dst_group.appendChild(new_node)
-	    pass
-	pass
-    pass
--- a/pyink/domview_ui.py	Sat Jan 15 21:19:50 2011 +0800
+++ b/pyink/domview_ui.py	Sat Jan 15 23:07:29 2011 +0800
@@ -227,7 +227,7 @@
     # The tween can be changed by tweening it again.
     def tween(self, layer_idx, key_frame_idx, tween_len,
 	      tween_type=TweenObject.TWEEN_TYPE_NORMAL):
-	assert tween_len > 0
+	assert tween_len > 1
 	frameline = self._framelines[layer_idx]
 	right_frame_idx = key_frame_idx + tween_len - 1
 	fl_tween_type = self._frameline_tween_types[tween_type]
@@ -243,6 +243,16 @@
 	frameline.tween(start, fl_tween_type)
 	pass
 
+    def untween(self, layer_idx, key_frame_idx):
+	frameline = self._framelines[layer_idx]
+        start, end, tween_type = \
+            frameline.get_frame_block(key_frame_idx)
+        if start < end:
+            frameline.untween(start)
+            frameline.unmark_keyframe(end)
+            pass
+        pass
+
     ## \brief Unmark a key frame.
     #
     # Once a key frame was unmark, the associated tween was also removed
@@ -319,13 +329,14 @@
 	except ValueError:	# last removed frame is not in any tween
 	    pass
 	else:
-	    if start >= frame_idx and start > last_rm:
+	    if start >= frame_idx and end > last_rm:
 		# Left key frame of the tween was removed, but not right one.
 		frameline.untween(start)
 		frameline.unmark_keyframe(end)
 		pass
 	    pass
 
+        #
 	# Remove left key of the tween that right key frame is in removing
 	# range.
 	#
@@ -509,10 +520,53 @@
 
     ## \brief Insert frames at specified position.
     #
-    # All frame at and after given position will shift left, except nearest
+    # All frames at and after given position will shift left, except nearest
     # \ref num frames are removed.
     #
+    #  - For a tween that only right part is covered by removing
+    #    range, its tween length would be shrinked just before
+    #    removing range.
+    #  - For a tween that only left part is covered by removing range,
+    #    key and tween are fully removed.
+    #  - For a tween that only middle part is covered, tween length is
+    #    also shrinked according length of covered part.
+    #
     def rm_frames(self, layer_idx, frame_idx, num):
+        #
+        # Check the key that is partially covered key tween, but not
+        # include key frame.
+        #
+        last_rm_idx = frame_idx + num - 1
+        try:
+            start, end, tween_type = \
+                self._fl_stack.get_left_key_tween(layer_idx, frame_idx)
+        except ValueError:
+            pass                # no key at left
+        else:
+            if start < frame_idx and end >= frame_idx:
+                #
+                # Key frame is not covered, only part of a key tween
+                # is covered.  Shrink its tween length, size of the
+                # covered part, or the key will be unmarked.
+                #
+                shrink_sz = min(end - frame_idx + 1, num)
+                
+                tween_len = end - start + 1 - shrink_sz
+                if tween_len == 1:
+                    self._fl_stack.untween(layer_idx, start)
+                else:
+                    self._fl_stack.tween(layer_idx, start, tween_len,
+                                         tween_type)
+                    pass
+
+                scene_end = end - shrink_sz
+                scene_node = self._fl_stack.get_keyframe_data(layer_idx, start)
+                self._dom.chg_scene_node(scene_node, end=scene_end)
+
+                frame_idx = scene_end + 1 # to shift/remove keys at right side
+                pass
+            pass
+
 	self._fl_stack.rm_frames(layer_idx, frame_idx, num)
 	self._dom.rm_frames(layer_idx, frame_idx, num)
 	pass
@@ -604,15 +658,10 @@
         self._dom.copy_group_children(src_group, dst_group)
         pass
 
-    ## \brief Link content of a source key frame to a destinate.
-    #
-    # Link content of the scene group of a source key frame to the
-    # scene group of a destinate key frame.
-    #
-    def link_key_group(self, layer_idx, src_frame_idx, dst_frame_idx):
+    def clone_key_group(self, layer_idx, src_frame_idx, dst_frame_idx):
         src_group = self.get_key_group(layer_idx, src_frame_idx)
         dst_group = self.get_key_group(layer_idx, dst_frame_idx)
-        self._dom.link_group_children(src_group, dst_group)
+        self._dom.clone_group_children(src_group, dst_group)
         pass
 
     ## \brief Return widget showing frames and layers.