def pick(self, matrix, cursor, noke=None): noke = noke and noke.through() or self.root().through() type = noke.node.type if APPL == type: nokes = noke['arg'], noke['func'] else: # VAR or ABS bubble = noke() if bubble: # Bubble inside Group matrix = matrix * bubble.transform() # create new matrix if not Ring.unit.transform(matrix).pick(cursor): return yield noke # ABS or VAR if VAR == type: return matrix = matrix * Figure.lambdaMatrix.inversion nokes = noke['expr'], # Pick Bubbles of Group or inside Lambda for noke in nokes: for n in self.pick(matrix, cursor, noke): yield n
def coordinateGroup(self, noke, dir): "dir is Matrix of Direction; noke is APPL-Noke" group = noke.group() # Co-ordinate inside Groups if are for noke in group.bubbles(): bubble = noke() bubble.ring = bubble.ring.transform(dir) # Skip Lambdas noke = noke.skipLambdas() if APPL == noke.node.type: # Inside co-ordination needed if not bubble.parent: # The same as parent group dir1 = dir else: parent = bubble.parent() dir1 = TransformMatrix() dir1.setRotate(Bubble.getDir((parent, bubble))) self.coordinateGroup(noke, dir1) # Rotate Bounding Ring group.boundingRing = group.boundingRing.transform(dir) #group.resetBoundingRing() group.resetBoundingMatrix()
def coordinateGroup( self, noke, dir ): "dir is Matrix of Direction; noke is APPL-Noke" group = noke.group() # Co-ordinate inside Groups if are for noke in group.bubbles(): bubble = noke() bubble.ring = bubble.ring.transform( dir ) # Skip Lambdas noke = noke.skipLambdas() if APPL == noke.node.type: # Inside co-ordination needed if not bubble.parent: # The same as parent group dir1 = dir else: parent = bubble.parent() dir1 = TransformMatrix() dir1.setRotate( Bubble.getDir( (parent,bubble) ) ) self.coordinateGroup( noke, dir1 ) # Rotate Bounding Ring group.boundingRing = group.boundingRing.transform( dir ) #group.resetBoundingRing() group.resetBoundingMatrix()
def pick( self, matrix, cursor, noke= None ): noke = noke and noke.through() or self.root().through() type = noke.node.type if APPL == type: nokes = noke['arg'], noke['func'] else: # VAR or ABS bubble = noke() if bubble: # Bubble inside Group matrix = matrix * bubble.transform() # create new matrix if not Ring.unit.transform( matrix ).pick( cursor ): return yield noke # ABS or VAR if VAR == type: return matrix = matrix * Figure.lambdaMatrix.inversion nokes = noke['expr'], # Pick Bubbles of Group or inside Lambda for noke in nokes: for n in self.pick( matrix, cursor, noke ): yield n
def bubbles(self, noke=None): # ?? move to Bubble """ Iterates Nokes of Bubbles of Group from root (reverse of order to draw) #in strange Order (deeply, elder Parents before) """ noke = noke or self.rootnoke yield noke for p in noke().childs: for n in self.bubbles(p): yield n
def bubbles( self, noke= None ): # ?? move to Bubble """ Iterates Nokes of Bubbles of Group from root (reverse of order to draw) #in strange Order (deeply, elder Parents before) """ noke = noke or self.rootnoke yield noke for p in noke().childs: for n in self.bubbles( p ): yield n
def ringsToDraw(self, matrix, noke=None): # ?? move to Noke class noke = noke or self.root() #debug('draw','ringsToDraw: draw',noke) yielded = False nokes = () type = noke.node.type if VAR == type: if noke.node.letbound(): # Check Fading Bubble bubble = noke() if bubble and bubble.fading: # Do not change 'matrix' matrix1 = matrix * bubble.transform() yield Drawn(noke, Ring.unit.transform(matrix1), bubble.fading.fade) yielded = True nokes = noke['ref']['be'], # Here must be ['ref'], not .ref() else: # Draw Bubble of Variable bubble = noke() if bubble: matrix *= bubble.transform() yield Drawn(noke, Ring.unit.transform(matrix)) return # Nothing to draw inside elif ABS == type: # Draw Bubble of Lambda bubble = noke() if bubble: matrix *= bubble.transform() yield Drawn(noke, Ring.unit.transform(matrix)) yielded = True matrix *= Figure.lambdaMatrix.inverse() # Go inside Abstraction nokes = noke['expr'], elif LET == type: # Check Fading Bubble bubble = noke() if bubble and bubble.fading: # Do not change 'matrix' yield Drawn( noke, bubble.ring.transform(matrix * bubble.group.transformMatrix), bubble.fading.fade) yielded = True #debug( 'draw', 'drawn LET:', noke, bubble ) nokes = noke['expr'], elif APPL == type: nokes = noke['arg'], noke['func'] # Feedback from Manipulator if yielded: if not Figure.drawing['done']: return # Skip other Bubbles inside (too small or out of view) # Draw Bubbles inside for noke in nokes: for d in self.ringsToDraw(matrix, noke): yield d
def arc(noke): return Bubble.arcs[(self, noke())]
def ringsToDraw( self, matrix, noke= None ): # ?? move to Noke class noke = noke or self.root() #debug('draw','ringsToDraw: draw',noke) yielded = False nokes = () type = noke.node.type if VAR == type: if noke.node.letbound(): # Check Fading Bubble bubble = noke() if bubble and bubble.fading: # Do not change 'matrix' matrix1 = matrix * bubble.transform() yield Drawn( noke, Ring.unit.transform( matrix1 ), bubble.fading.fade ) yielded = True nokes = noke['ref']['be'], # Here must be ['ref'], not .ref() else: # Draw Bubble of Variable bubble = noke() if bubble: matrix *= bubble.transform() yield Drawn( noke, Ring.unit.transform( matrix ) ) return # Nothing to draw inside elif ABS == type: # Draw Bubble of Lambda bubble = noke() if bubble: matrix *= bubble.transform() yield Drawn( noke, Ring.unit.transform( matrix ) ) yielded = True matrix *= Figure.lambdaMatrix.inverse() # Go inside Abstraction nokes = noke['expr'], elif LET == type: # Check Fading Bubble bubble = noke() if bubble and bubble.fading: # Do not change 'matrix' yield Drawn( noke, bubble.ring.transform( matrix * bubble.group.transformMatrix ), bubble.fading.fade ) yielded = True #debug( 'draw', 'drawn LET:', noke, bubble ) nokes = noke['expr'], elif APPL == type: nokes = noke['arg'], noke['func'] # Feedback from Manipulator if yielded: if not Figure.drawing['done']: return # Skip other Bubbles inside (too small or out of view) # Draw Bubbles inside for noke in nokes: for d in self.ringsToDraw( matrix, noke ): yield d
def arc( noke ): return Bubble.arcs[ ( self,noke() ) ]
def start(self): # Start time func-s funcs = {'pos': Enduring.I, 'r': Enduring.I} Enduring.__init__(self, Act.secRelease, funcs) figure = self.act.figure # Archive Bubbles and Groups of Figure before rebuilding for noke in figure.root().bubbleNokes(): if noke(): noke.save() # Save to archive noke.remove() # Remove original sizeRing = figure.sizeRing.copy() # Rebuild Figure figure.buildGroups() figure.buildGeometry() #debug('eat','afterbuild', figure.root().through()() ) # Det Morphs modifiedGroups = {} # dict {old group: new group} # ?? Here must be more smart Group marker # All parent groups of current must be marked (their Bounding Ring may be changed) for noke in figure.root().bubbleNokes(): debug('eat', 'noke of figure', noke, noke()) loaded = noke.load( ) # Load from archive saved current Ring of Bubble if loaded: bubble = noke() if not bubble: bubble = Bubble() noke.set(bubble) self.morphs.append(Morph(loaded.ring, bubble.ring.copy())) debug('eat', 'added morph', noke, loaded.ring, loaded.group, bubble.ring) # Restore current Bubble attributes bubble.ring = loaded.ring bubble.fading = loaded.fading # bubble.group = loaded.group ?? # Mark group as modified (for morphing of its Bounding Ring) if loaded.group and loaded.group not in modifiedGroups: if not bubble.group: # This Group disappears at this Eating bubble.group = Group( ) # Create it for a time of Release # ?? group for each bubble bubble.group.boundingRing = Ring((0, 0), 1) modifiedGroups[loaded.group] = bubble.group # Remove Archive noke.clean() # Morph Figure sizeRing self.morphs.append( Morph( sizeRing, \ figure.sizeRing.copy(), \ figure.refreshTransform ) ) figure.sizeRing = sizeRing # Restore current figure.refreshTransform() # Morph Bounding Rings of modified Groups for loaded, group in modifiedGroups.iteritems(): debug('eat', 'group for morph', loaded.rootnoke, loaded.boundingRing) self.morphs.append( Morph( loaded.boundingRing, \ group.boundingRing.copy(), \ group.resetBoundingMatrix ) ) group.boundingRing = loaded.boundingRing # Restore current group.resetBoundingMatrix() return Enduring.start(self)
def descent(noke, group, matrix): # If 'noke' has Bubble, Bubble.ring already set. debug('eat', 'descend:', noke) if APPL == noke.node.type: # Group inside some Lambda, 'matrix' must be None debug('eat', 'appl found', noke) group = noke.group() for b in noke.bubblesDraw(): # b().ring stays on its place matrix = TransformMatrix(ring=b().ring) descent( b, group, matrix ) # Pass matrix, because there inside fading vars may be bubbles of this group elif ABS == noke.node.type: noke = noke['expr'].through( ) # Noke inside Abs - no position needed descent(noke, None, None) elif VAR == noke.node.type and abs == noke.node.ref: # Mark Bubble as fading bubble = noke() if not bubble: # This Var may be inside Lambda and do not have 'bubble' bubble = Bubble() # Create Bubble without 'group' noke.set(bubble) bubble.fading = self self.faded.append(noke) debug('eat', 'it s hole. added to faded:', self.faded) if not matrix: matrix = TransformMatrix() matrix.unit() # Copy eaten branch to inside of fading Var noke = Noke(letnoke.node.be, addkey(noke.node, noke.key)) debug('eat', 'ref-be:', noke) debug('eat', 'eaten:', eating.eaten) for b, h in zip(noke.bubblesDraw(), eating.eaten): debug('eat', 'found in Hole:', b, h) # Copying Eaten Bubble bubble = Bubble() bubble.ring = h().ring.transform( matrix) # Redet position bubble.group = group b.set(bubble) # Copy remained Bubbles inside Eaten if are if ABS == b.node.type: for b,h in zip( b['expr'].bubbleNokes(), \ h['expr'].bubbleNokes() ): Noke.copyBubble(b, h)
def start( self ): # Start time func-s funcs = { 'pos': Enduring.I, 'r': Enduring.I } Enduring.__init__( self, Act.secRelease, funcs ) figure = self.act.figure # Archive Bubbles and Groups of Figure before rebuilding for noke in figure.root().bubbleNokes(): if noke(): noke.save() # Save to archive noke.remove() # Remove original sizeRing = figure.sizeRing.copy() # Rebuild Figure figure.buildGroups() figure.buildGeometry() #debug('eat','afterbuild', figure.root().through()() ) # Det Morphs modifiedGroups = {} # dict {old group: new group} # ?? Here must be more smart Group marker # All parent groups of current must be marked (their Bounding Ring may be changed) for noke in figure.root().bubbleNokes(): debug('eat','noke of figure',noke,noke()) loaded = noke.load() # Load from archive saved current Ring of Bubble if loaded: bubble = noke() if not bubble: bubble = Bubble() noke.set( bubble ) self.morphs.append( Morph( loaded.ring, bubble.ring.copy() ) ) debug('eat','added morph',noke,loaded.ring, loaded.group, bubble.ring) # Restore current Bubble attributes bubble.ring = loaded.ring bubble.fading = loaded.fading # bubble.group = loaded.group ?? # Mark group as modified (for morphing of its Bounding Ring) if loaded.group and loaded.group not in modifiedGroups: if not bubble.group: # This Group disappears at this Eating bubble.group = Group() # Create it for a time of Release # ?? group for each bubble bubble.group.boundingRing = Ring((0,0),1) modifiedGroups[ loaded.group ] = bubble.group # Remove Archive noke.clean() # Morph Figure sizeRing self.morphs.append( Morph( sizeRing, \ figure.sizeRing.copy(), \ figure.refreshTransform ) ) figure.sizeRing = sizeRing # Restore current figure.refreshTransform() # Morph Bounding Rings of modified Groups for loaded,group in modifiedGroups.iteritems(): debug('eat','group for morph', loaded.rootnoke, loaded.boundingRing ) self.morphs.append( Morph( loaded.boundingRing, \ group.boundingRing.copy(), \ group.resetBoundingMatrix ) ) group.boundingRing = loaded.boundingRing # Restore current group.resetBoundingMatrix() return Enduring.start( self )
def descent( noke, group, matrix ): # If 'noke' has Bubble, Bubble.ring already set. debug( 'eat', 'descend:', noke ) if APPL == noke.node.type: # Group inside some Lambda, 'matrix' must be None debug('eat','appl found',noke) group = noke.group() for b in noke.bubblesDraw(): # b().ring stays on its place matrix = TransformMatrix( ring= b().ring ) descent( b, group, matrix ) # Pass matrix, because there inside fading vars may be bubbles of this group elif ABS == noke.node.type: noke = noke['expr'].through() # Noke inside Abs - no position needed descent( noke, None, None ) elif VAR == noke.node.type and abs == noke.node.ref: # Mark Bubble as fading bubble = noke() if not bubble: # This Var may be inside Lambda and do not have 'bubble' bubble = Bubble() # Create Bubble without 'group' noke.set( bubble ) bubble.fading = self self.faded.append( noke ) debug('eat','it s hole. added to faded:', self.faded ) if not matrix: matrix = TransformMatrix() matrix.unit() # Copy eaten branch to inside of fading Var noke = Noke( letnoke.node.be, addkey( noke.node, noke.key ) ) debug('eat','ref-be:',noke) debug('eat','eaten:',eating.eaten) for b,h in zip( noke.bubblesDraw(), eating.eaten ): debug( 'eat', 'found in Hole:', b, h ) # Copying Eaten Bubble bubble = Bubble() bubble.ring = h().ring.transform( matrix ) # Redet position bubble.group = group b.set( bubble ) # Copy remained Bubbles inside Eaten if are if ABS == b.node.type: for b,h in zip( b['expr'].bubbleNokes(), \ h['expr'].bubbleNokes() ): Noke.copyBubble( b, h )