changeset 1290:99de83340782

Merge
author wycc
date Sat, 15 Jan 2011 21:19:50 +0800
parents e816b0c2deec (diff) 922d1caf6632 (current diff)
children 082fff7e9604
files pyink/domview.py
diffstat 3 files changed, 70 insertions(+), 15 deletions(-) [+]
line wrap: on
line diff
--- a/pyink/MBScene.py	Sat Jan 15 20:48:03 2011 +0800
+++ b/pyink/MBScene.py	Sat Jan 15 21:19:50 2011 +0800
@@ -118,14 +118,19 @@
 	pass
     
     def extendScene(self):
+        # Create a tween
 	layer_idx, frame_idx = self._domviewui.get_active_layer_frame()
 	start, end, tween_type = \
 	    self._domviewui.get_left_key(layer_idx, frame_idx)
-	tween_len = frame_idx - start + 1
+	tween_len = frame_idx - start 
 	self._domviewui.tween(layer_idx, start, tween_len, tween_type)
-	
+
+	# Create a key frame which link to the previous key frame
 	scene_group = self._domviewui.get_key_group(layer_idx, start)
-	self._enterGroup(scene_group)
+	self._domviewui.mark_key(layer_idx, frame_idx)
+	self._domviewui.link_key_group(layer_idx, start, frame_idx)
+	self._director.show_scene(frame_idx)
+	self.selectSceneObject(layer_idx, frame_idx)
 	pass
     
     def _enterGroup(self, scene_group):
@@ -153,6 +158,7 @@
     def duplicateKeyScene(self):
         # Search for the current scene
 	layer_idx, frame_idx = self._domviewui.get_active_layer_frame()
+	self.removeKeyScene(layer_idx, frame_idx)
 
 	try:
 	    left_start, left_end, left_tween_type = \
--- a/pyink/domview.py	Sat Jan 15 20:48:03 2011 +0800
+++ b/pyink/domview.py	Sat Jan 15 21:19:50 2011 +0800
@@ -235,11 +235,12 @@
 		continue
 
 	    try:
+	    	ref = scene_node.getAttribute('ref')
 		start, end, scene_type = self.parse_one_scene(scene_node)
-                group_id = scene_node.getAttribute("ref")
-	    except:             # the scene node is incompleted.
+	    except:
 		continue
 	    
+	    group_id = scene_node.getAttribute("ref")
 	    self._group2scene[group_id] = scene_node
 	    pass
 	pass
@@ -705,13 +706,18 @@
 	    
 	    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.rm_scene_node_n_group(scene_node)
+		self.chg_scene_node(scene_node,
+				    start=start,
+				    end=(end - num))
 		pass
 	    pass
 	pass
@@ -726,15 +732,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)
             
             #
@@ -752,10 +758,42 @@
             new_node.setAttribute('id', gid)
 	    pass
 
-        for child in dup_group.childList():
-            dup_group.removeChild(child) # prevent from crash
-            dst_group.append(child)
-            pass
+	for child in dup_group.childList():
+	    dup_group.removeChild(child) # prvent from crash
+	    dst_group.appendChild(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 20:48:03 2011 +0800
+++ b/pyink/domview_ui.py	Sat Jan 15 21:19:50 2011 +0800
@@ -604,6 +604,17 @@
         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):
+        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)
+        pass
+
     ## \brief Return widget showing frames and layers.
     #
     def get_frame_ui_widget(self):