# HG changeset patch # User wycc # Date 1230133419 -28800 # Node ID 889cdc5f23c5773c59101176364eec530b28c0bd # Parent ec62453bbb2b389f11d7047ea6721fe35adffae2 When a scene is selected to0 edit, we copy all of its elements out of the scene so that inkscape can edit it directly. All elements add or delete by the inkspcae will be put back when we switch the scene. The svg2code.py must recognize this structure. diff -r ec62453bbb2b -r 889cdc5f23c5 inkscape/MB_Frame.py --- a/inkscape/MB_Frame.py Mon Dec 22 00:21:46 2008 +0800 +++ b/inkscape/MB_Frame.py Wed Dec 24 23:43:39 2008 +0800 @@ -10,15 +10,17 @@ # Like the layer, the frames are represented by special groups. All groups directly under a layer will be treated as frames. However, a group may be spanned for more than one # frame. For example # +# +# # # -# -# -# +# # +# # -# This will stand for 7 scenes. Scene 1 and scene 2 are key scenes. 3,4,5,6,7 are filled scenes.In the above example, g1234 and g1236 are in the scene 1. g1235 and g1236 are in -# scene 2-7 +# This will stand for 7 scenes. Scene 1 and scene 2 are key scenes. 3,4,5,6,7 are filled scenes. The current scene is defined by the 'current' attribute. In the above example, it is 3. +# All elements without scene attributes are items in the current scene. +# Therefore, when we switch scene, we will move all items into the current scene and then move items out from the new scene. # # In the inkscape extention, we will provide an grid for users to select the current scene or change the scene structure. Users are allowed to # Insert a new key scene @@ -48,6 +50,7 @@ def __init__(self,node): self.scene = [] self.node = node + self.nodes=[] class Scene: def __init__(self, node, start,end): self.node = node @@ -76,21 +79,53 @@ print " " * l * 2,"/>" def parseScene(self): + """ + In this function, we will collect all items for the current scene and then relocate them back to the appropriate scene object. + """ self.layer = [] - for layer in self.document.getroot(): - if layer.tag == '{http://www.w3.org/2000/svg}g': + current_scene = [] + oldscene = None + for node in self.document.getroot(): + if node.tag == '{http://www.w3.org/2000/svg}g': #print layer.attrib.get("id") - lyobj = Layer(layer) + lyobj = Layer(node) self.layer.append(lyobj) - for scene in layer: + for scene in node: if scene.tag == '{http://www.w3.org/2000/svg}g': - range = scene.attrib.get("scene").split('-') + s = scene.get("scene") + if s == None: + # group without scene is part of the current scene + current_scene.append(scene) + continue + range = s.split('-') + + cur = scene.get("current") + try: + self.current_scene = int(cur) + del scene.attrib["current"] + oldscene = scene + except: + pass if len(range) == 1: #print " scene %d" % int(range[0]) lyobj.scene.append(Scene(scene,range[0],range[0])) elif len(range) == 2: #print " scene%d-%d" % (int(range[0]),int(range[1])) lyobj.scene.append(Scene(scene,range[0],range[1])) + else: + current_scene.append(scene) + pass + pass + pass + pass + + if oldscene != None: + # Put the objects back to the current scene + #print "Add elements back" + for o in current_scene: + #print o.tag + oldscene.append(o) + self.collectID() #self.dumpID() def collectID(self): @@ -201,6 +236,15 @@ for s in layer.scene: if nth >= s.start and nth <= s.end: s.node.set("style","") + s.node.set("current","%d"%nth) + #print "Put the elemenets out" + layer.nodes = [] + + for o in s.node: + #print " ",o.tag + layer.nodes.append(o) + for o in s.node: + s.node.remove(o) else: s.node.set("style","display:none") def generate(self): @@ -215,6 +259,8 @@ lnode = etree.Element("{http://www.w3.org/2000/svg}g") for a,v in l.node.attrib.items(): lnode.set(a,v) + for n in l.nodes: + lnode.append(n) root.append(lnode) for s in l.scene: snode = etree.Element("{http://www.w3.org/2000/svg}g")