Ejemplo n.º 1
0
    def drawAnno( self, a ):
        random.seed(a)
        colormap = SplitStrokeVisualizer.COLORMAP
        color = random.choice(colormap.keys())

        for s in a.getComponentStrokes():
            SketchGUI.drawStroke(s, width = 2, color = color)
Ejemplo n.º 2
0
 def drawAnno( self, a ):
     if len(a.connectMap) > 0:
         for from_node in a.connectMap.keys():
             for connect_tuple in a.connectMap[from_node]:
                 edge,to_node = connect_tuple
                 SketchGUI.drawCircle( edge.tail.X, edge.tail.Y, radius=7, width=2, color="#ccffcc")
                 SketchGUI.drawCircle( edge.tip.X, edge.tip.Y, radius=7, width=2, color="#ccffcc")
Ejemplo n.º 3
0
    def drawAnno( self, a ):
        if len(a.connectMap) > 0:
            node_map = {}
            for from_node in a.connectMap.keys():
                if from_node not in node_map:
                   node_map[from_node] = len(node_map)
                for connect_tuple in a.connectMap[from_node]:
                    edge,to_node = connect_tuple
                    if to_node not in node_map:
                       node_map[to_node] = len(node_map)

                    if from_node is not None:
                       SketchGUI.drawLine( edge.tail.X, edge.tail.Y, from_node.center.X, from_node.center.Y, width=2, color="#FA8072")
                    if to_node is not None:
                       SketchGUI.drawLine( edge.tip.X, edge.tip.Y, to_node.center.X, to_node.center.Y, width=2, color="#FA8072")

                    SketchGUI.drawCircle( edge.tail.X, edge.tail.Y, radius=2, width=2, color="#ccffcc")
                    SketchGUI.drawCircle( edge.tip.X, edge.tip.Y, radius=2, width=2, color="#ccffcc")

                    #x1,y1 = from_node.center.X, from_node.center.Y
                    #x2,y2 = edge.tail.X, edge.tail.Y
                    #SketchGUI.drawLine( x1,y1,x2,y2, width=2,color="#ccffcc")
                    #x1,y1 = to_node.center.X, to_node.center.Y
                    #x2,y2 = edge.tip.X, edge.tip.Y
                    #SketchGUI.drawLine( x1,y1,x2,y2, width=2,color="#ccffcc")

            for nodeAnno, nodeNum in node_map.items():
                if nodeAnno is not None:
                    x1,y1 = nodeAnno.center.X, nodeAnno.center.Y
                    SketchGUI.drawText(x1, y1, str(nodeNum))
Ejemplo n.º 4
0
    def drawMyself( self ):
        for a in self.annotation_list:
            center = GeomUtils.centroid(a.Strokes[0].Points) #Ugly hack to get the center of the annotation!
            templ_stroke = Stroke.Stroke(a.template)
            templ_stroke = templ_stroke.translate(center.X, center.Y)

            SketchGUI.drawText(center.X, center.Y, InText=a.name)
            SketchGUI.drawStroke(templ_stroke, color="#F050F0")
Ejemplo n.º 5
0
    def drawMyself(self, color=None):
        from SketchFramework import SketchGUI as GUI

        if color: drawColor = color
        else: drawColor = self.Color 

        if len(self.Points) > 0:
            GUI.drawStroke(self, color=drawColor, erasable = True)
Ejemplo n.º 6
0
 def drawAnno( self, a ):
     right_color = "#CF0000"
     left_color = "#0000C0"
     for wall in a.rightwalls: #Strokes
         rtv_logger.debug("Drawing right wall")
         wall = GeomUtils.strokeSmooth(wall, width = 6, preserveEnds = True)
         SketchGUI.drawStroke(wall, width = 2, color = right_color)
     for wall in a.leftwalls: #Strokes
         rtv_logger.debug("Drawing left wall")
         SketchGUI.drawStroke(wall, width = 2, color = left_color)
Ejemplo n.º 7
0
    def drawMyself(self, color=None):
        from SketchFramework import SketchGUI as GUI

        if color: drawColor = color
        else: drawColor = self.Color 

        #if len(self.Points) == 1:
        #    GUI.drawCircle( self.Points[0].X, self.Points[0].Y, radius=0,color=drawColor)
        #elif len(self.Points) > 1:
        GUI.drawStroke(self, color=drawColor, erasable = True)
Ejemplo n.º 8
0
 def drawAnno( self, a ):
     if len(a.text) >= 1:
         ul,br = GeomUtils.strokelistBoundingBox( a.Strokes )
         logger.debug(a.Strokes)
         height = ul.Y - br.Y
         left_x = ul.X# - height/3
         right_x = br.X + height/2
         midpoint = (ul.Y + br.Y) / 2
         SketchGUI.drawLine( left_x, midpoint, right_x, midpoint, color="#a0a0a0")
         y = br.Y + 5
         for idx, text in enumerate(a.alternates):
             SketchGUI.drawText( br.X, y, text, size=20, color="#a0a0a0" )
             y -= 20
Ejemplo n.º 9
0
 def drawAnno(self, anno):
     #pdb.set_trace()
     if self.trackedAnno == None:
         self.trackedAnno = anno
     for stk in anno.Strokes:
         prevPt = None
         for i, point in enumerate(GeomUtils.strokeNormalizeSpacing(stk, numpoints = len(stk.Points)).Points):
             if prevPt != None:
                 color = self.colors[anno.pattern[ (i + anno.idx) % len(anno.pattern) ] ]
                 SketchGUI.drawLine(prevPt.X, prevPt.Y, point.X, point.Y, color=color, width = 3)
             prevPt = point
     if anno == self.trackedAnno:
         dt = time.time() - self.lastDraw
         self.lastDraw = time.time()
         logger.debug("Effective FPS = %s" % (1 / float(dt)))
Ejemplo n.º 10
0
 def drawAnno( self, a ):
     if len(a.text) > 1:
         ul,br = GeomUtils.strokelistBoundingBox( a.Strokes )
         logger.debug(a.Strokes)
         height = ul.Y - br.Y
         midpointY = (ul.Y + br.Y) / 2
         midpointX = (ul.X + br.X) / 2
         left_x = midpointX - a.scale / 2.0
         right_x = midpointX + a.scale / 2.0
         #SketchGUI.drawLine( left_x, midpointY, right_x, midpointY, color="#a0a0a0")
         y = br.Y
         SketchGUI.drawText( br.X, y, a.text, size=15, color="#a0a0a0" )
         y -= 15
         for idx, text in enumerate(a.alternates):
             SketchGUI.drawText( br.X, y, text, size=10, color="#a0a0a0" )
             y -= 10
Ejemplo n.º 11
0
    def drawMyself( self ):
	for a in self.annotation_list:
            SketchGUI.drawLine( a.start_point.X, a.start_point.Y, a.end_point.X, a.end_point.Y,  color="#ddaaff", width=2.0)
Ejemplo n.º 12
0
def standAloneMain():
    "Sets up the SketchGUI interface on the local machine"
    from SketchFramework import SketchGUI as GUI
    #GUI.LoadApp()
    GUI.run()
Ejemplo n.º 13
0
    def drawMyself( self ):
	for a in self.annotation_list:
            SketchGUI.drawCircle( a.center.X,a.center.Y, radius=a.radius, color="#bbbbff", width=2.0)
Ejemplo n.º 14
0
 def drawMyself( self ):
     for a in self.annotation_list:
         SketchGUI.drawCircle( a.tail.X, a.tail.Y, color="#93bfdd", width=2.0, radius=4)
         SketchGUI.drawCircle( a.tip.X, a.tip.Y, color="#93bfdd", width=2.0, radius=4)
 def drawAnno(self, a):
     prev = None
     for cPt in a.corners + [a.corners[0]]:
         if prev != None:
             SketchGUI.drawLine( prev.X, prev.Y, cPt.X, cPt.Y, width=4,color="#ccffcc")
         prev = cPt
    def drawAnno( self, a ):
        tm_logger.debug(ET.tostring(a.xml()))

        edge_label_size = 15
        tape_label_size = 20
        active_color = "#BF5252"
        active_width = 7.0
        state_graph = a.state_graph_anno
        for from_node, connection_list in state_graph.connectMap.items():
            if from_node is not None:
                nodeColor = "#000000"
                if from_node == a.active_state:
                    nodeColor = active_color
                x, y = ( from_node.center.X, from_node.center.Y )
                SketchGUI.drawCircle (x, y, radius=from_node.radius, color=nodeColor, width=3.0)

            #GeomUtils.strokeSmooth(edge.tailstroke, width = len(edge.tailstroke.Points) / 3).drawMyself()
            for edge, to_node in connection_list:
                if edge == a.leading_edge['edge']:
                    edgeColor = active_color
                else:
                    edgeColor = "#000000"
                if to_node is not None:
                    nodeColor = "#000000"
                    nodeWidth = 3.0
                    if to_node == a.active_state:
                        nodeColor = active_color
                        nodeWidth = active_width
                    x, y = ( to_node.center.X, to_node.center.Y )
                    SketchGUI.drawCircle (x, y, radius=to_node.radius, color=nodeColor, fill="", width=nodeWidth)
                #Draw the smoothed tail
                if from_node is not None:
                    if edge.direction == "tail2head": #Connect the tail more closely to the edge
                        smooth_tail = Stroke([from_node.center] + edge.tailstroke.Points + [edge.tip])
                    else:
                        smooth_tail = Stroke([edge.tip] + edge.tailstroke.Points + [from_node.center])
                else:
                    smooth_tail = edge.tailstroke
                smooth_tail = GeomUtils.strokeSmooth(smooth_tail, width = len(edge.tailstroke.Points) / 3, preserveEnds = True)
                smooth_tail.drawMyself(color=edgeColor)

                #Draw the smoothed head
                ep1, ep2 = ( edge.headstroke.Points[0], edge.headstroke.Points[-1] )
                smooth_head = Stroke([ep1, edge.tip, ep2])
                smooth_head.drawMyself(color = edgeColor)

                if edge in a.edge2labels_map:
                    #Determine label offset
                     
                    for label in a.edge2labels_map[edge]:
                        textColor = "#000000"
                        if label == a.leading_edge['label']:
                            tm_logger.debug("Drawing leading label: %s" % (label.text))
                            textColor = active_color
                        tl, br = GeomUtils.strokelistBoundingBox(label.Strokes)

                        label_point = Point ((tl.X + br.X) / 2.0, (tl.Y + br.Y) / 2.0)
                        label_point.X -= edge_label_size
                        label_point.Y += edge_label_size
                        #label_point = smooth_tail.Points[len(smooth_tail.Points)/2]
                        SketchGUI.drawText (label_point.X, label_point.Y, InText=label.text, size=edge_label_size, color=textColor)
                    #endfor
                #endif
            #end for edge
        #end for from_node

        #Draw the tape string
        tl, br = GeomUtils.strokelistBoundingBox(a.Strokes)
        tape_label_pt = Point( \
            ((tl.X + br.X) / 2.0) - (len(a.tape_string) + 2) * tape_label_size / 2.0 , \
            br.Y - tape_label_size)

        for curIdx, tapeChar in enumerate(['-'] + a.tape_string + ['-']):
            curPt = Point(tape_label_pt.X + curIdx * tape_label_size, tape_label_pt.Y)
            charColor = "#000000"
            if curIdx - 1== a.tape_idx:
                charColor = active_color
            SketchGUI.drawText (curPt.X, curPt.Y, InText=tapeChar, size=tape_label_size, color=charColor)
Ejemplo n.º 17
0
    def drawMyself( self ):
        vizlogger.debug("Drawing self: %s" % (self.annotation_list))
	for a in self.annotation_list:
            vizlogger.debug("Drawing Circle")
            SketchGUI.drawCircle( a.center.X, a.center.Y, radius=a.radius, color="#bbbbff", width=2.0)
Ejemplo n.º 18
0
    def drawMyself( self ):
        # FIXME: does this tie us to the tk front-end?  If so, what should
        # we put into the GUI API to enable this sort of animation? is it mostly 
        # "update" that is needed?
        from SketchFramework import SketchGUI as gui
        canvas = gui.SketchGUISingleton()
        color_levels = { 0: "#FF6633", 1: "#FF00FF", 2: "#3366FF", 3: "#00CC00",}
        scale = 18  # pixels for text size

        # start with a list of all the annotations
        allAnnoSet = set([])
        logger.debug("Watch set %s" % (self.watchSet))
        for stroke in BoardSingleton().Strokes:
            logger.debug("Stroke annotations %s" % (stroke.findAnnotations(None)))

            for anno in stroke.findAnnotations(None):
                logger.debug ("%s in %s?" % (type(anno), list(self.watchSet)))
                if type(anno) in list(self.watchSet):
                    logger.debug("Adding %s to annoset" % (anno))
                    allAnnoSet.add( anno )

        # now make a map from the sets of strokes to the annotations on them
        annoMap = {} # dictionary of {frozenset(strokes):[annotations]}
        for anno in allAnnoSet:
            strokeset = frozenset(anno.Strokes)
            if strokeset not in annoMap:
                annoMap[strokeset] = []
            annoMap[strokeset].append( anno )

        # now assign a unique size for each anno on a given set of strokes
        sizeDict = {}
        for strokeset in annoMap.keys():
            depth = 0
            for anno in annoMap[strokeset]:
                sizeDict[anno] = depth
                depth += 1

        # sort the annotations based on the time at which they were added
        annoList = list(allAnnoSet)
        annoList.sort(key= (lambda x: x.Time))
        for anno in annoList:
            nestlevel = sizeDict[anno] # get the nesting level for this annotation
            # for the set of stroke this anno is annotating, find the bounding box
            
            tl = anno.Strokes[0].BoundTopLeft
            br = anno.Strokes[0].BoundBottomRight
            tlx = tl.X
            tly = tl.Y
            brx = br.X
            bry = br.Y
            
            bottomright_list = [s.BoundBottomRight for s in anno.Strokes]
            topleft_list = [s.BoundTopLeft for s in anno.Strokes]
            br, tl = _nestingBox(bottomright_list, topleft_list, scale = nestlevel*3)
            br.Y -= nestlevel * scale # save some space for text on bottom of box

            # if this is a "new" anno, wait a little before drawing
            if anno not in self.seenBefore:
                #time.sleep(0.5)
                self.seenBefore[anno] = True

            # now draw the actual boxes
            labeltext = anno.classname()
            tlx = tl.X
            tly = tl.Y
            brx = br.X
            bry = br.Y
            
            gui.drawBox(tl,br,color=color_levels[nestlevel % len(color_levels)])
            gui.drawText(tl.X, br.Y+scale, size = 12, InText=labeltext)