示例#1
0
    def itterateGraffleGraphics(self,GraphicsList):
        """parent should be a list of """
        for graphics in GraphicsList:
            # Styling
            self.target.style.appendScope()
            if graphics.get("Style") is not None:
                self.target.setGraffleStyle(graphics.get("Style"))
            
            cls = graphics["Class"]
            if cls == "SolidGraphic":
                # used as background - add a 
                shallowcopy = dict({"Shape":"Rectangle"})
                shallowcopy.update(graphics)
                self.svgAddGraffleShapedGraphic(shallowcopy)
                
            elif cls == "ShapedGraphic":
                try:
                    if not self.svgAddGraffleShapedGraphic(graphics):
                        continue
                except:
                    raise
                    print "could not show shaped graphic"
                
            elif cls == "LineGraphic":
                pts = self.extractMagnetCoordinates(graphics["Points"])
                if geom.out_of_boundingbox(pts,self.bounding_box):
                    continue
                self.target.style["fill"] = "none"
                if not graphics.get("OrthogonalBarAutomatic"):
                    bar_pos = graphics.get("OrthogonalBarPosition")
                    if bar_pos is not None:
                        # Decide where to place the orthogonal position

                        bar_pos = float(bar_pos)
                        """
                        # This isn't right
                        out_pts = []
                        i = 0
                        while i < len(pts) - 1:
                            p1 = pts[i]
                            p2 = pts[i+1]
                            newpt = [p1[0] + bar_pos, p1[1]]
                            out_pts.append(p1)
                            out_pts.append(newpt)
                            out_pts.append(p2)
                            i+=2
                        pts = out_pts
                        """


                    self.target.addPath( pts,id=str(graphics["ID"]))
                
            elif cls == "TableGroup":
                # In Progress
                table_graphics = graphics.get("Graphics")
                if table_graphics is not None:
                    self.target.addLayer(self, reversed(table_graphics))
                    
            elif cls == "Group":
                subgraphics = graphics.get("Graphics")
                if subgraphics is not None:
                    self.target.addLayer(self, reversed(subgraphics))
            else:
                print "Don't know how to display Class \"%s\""%cls
                
                
            if graphics.get("Text") is not None:
                # have to write some text too ...
                self.target.setGraffleFont(graphics.get("FontInfo"))
                coords = self.extractBoundCOordinates(graphics['Bounds'])

                if geom.out_of_boundingbox(((coords[0], coords[1]),  ((coords[0]+coords[2]),  (coords[1] + coords[3]))), self.bounding_box):
                    continue
                x, y, width, height = coords
                dx = float(graphics['Text'].get('Pad',0))
                dy = float(graphics['Text'].get('VerticalPad',0))
                self.target.addText(rtftext = graphics.get("Text").get("Text",""),
                                 x = x+dx, y = y+dy, width = width-2*dx, height = height-2*dy, fontinfo = graphics.get("FontInfo"),id=graphics["ID"])


                                 
            self.target.style.popScope()
示例#2
0
    def svgAddGraffleShapedGraphic(self, graphic):
        shape = graphic['Shape']
        
        extra_opts = {}
        if graphic.get("HFlip","NO")=="YES":
            extra_opts["HFlip"] = True
        if graphic.get("VFlip","NO")=="YES":
            extra_opts["VFlip"] = True
        if graphic.get("Rotation") is not None:
            extra_opts["Rotation"] = float(graphic["Rotation"])
        extra_opts["id"] = str(graphic["ID"])

        coords = self.extractBoundCOordinates(graphic['Bounds'])

        if geom.out_of_boundingbox(((coords[0], coords[1]),  ((coords[0]+coords[2]),  (coords[1] + coords[3]))), self.bounding_box):
            return False
        if shape == 'Rectangle':
            if graphic.get("ImageID") is not None:
                # TODO: images
                image_id = graphic["ImageID"]
                if len(self.imagelist) <= image_id:
                    print "Error - image out of range"
                    return
                image = self.imagelist[image_id]
                self.target.addImage(bounds = coords, \
                                  href = image)
                print "Insert Image - " + str(image)
            else:
                # radius of corners is stored on the style in graffle
                sty = graphic.get("Style",{})
                stroke = sty.get("stroke",{})
                radius = stroke.get("CornerRadius",None)
                
                x, y   = coords[0], coords[1]
                width  = coords[2]# - coords[0]
                height = coords[3]# - coords[1]
                self.target.addRect(
                                        x = x,
                                        y = y,
                                        width = width,
                                        height = height,
                                        rx=radius,
                                        ry=radius,
                                        **extra_opts)

        elif shape == "RoundRect":
            sty = graphic.get("Style",{})
            stroke = sty.get("stroke",{})
            radius = stroke.get("CornerRadius",None)

            x, y   = coords[0], coords[1]
            width  = coords[2]# - coords[0]
            height = coords[3]# - coords[1]
            import math
            self.target.addRect(
                             x = x,
                             y = y,
                             width = width,
                             height = height,
                             rx=(width - math.sqrt(width*width-height*height))/2,
                             ry=height/2,
                             **extra_opts)            
        elif shape == "HorizontalTriangle":
            self.target.addHorizontalTriangle(
                                        bounds = coords,
                                        **extra_opts \
                                        )
        elif shape == "RightTriangle":
            self.target.addRightTriangle(
                                        bounds = coords,
                                        **extra_opts \
                                        )
        elif shape == "VerticalTriangle":
            self.target.addVerticalTriangle(
                                         bounds = coords,
                                         **extra_opts \
                                         )
        elif shape == "Circle":
            # Actually can be an ellipse
            self.target.addEllipse(
                                        bounds = coords,
                                        **extra_opts \
                                        )
        elif shape == "AdjustableArrow":
            self.target.addAdjustableArrow(
                                        bounds = coords,
                                        graphic = graphic,
                                        **extra_opts \
                                        )
        elif shape == "Diamond":
            self.target.addDiamond(bounds = coords,
                                   graphic = graphic,
                                   **extra_opts)
        elif shape == "Cloud":
            self.target.addCloud(bounds=coords,
                                 graphic = graphic,
                                 **extra_opts)
        else:
            print "Don't know how to display Shape %s"%str(graphic['Shape'])
            
        return True
示例#3
0
 def testBbMaxY(self):
     '''Test that the function returns True if one point is above bounding box'''
     pts=((-1, -1), (1., 1.))
     bb=((-2, -3), (3, 0))
     self.assertTrue(geom.out_of_boundingbox(pts, bb))
示例#4
0
 def testBbMaxX(self):
     '''Test that the function returns True if one point is on the right bounding box'''
     pts=((-1, -1), (1., 1.))
     bb=((-2, -3), (0, 4))
     self.assertTrue(geom.out_of_boundingbox(pts, bb))
示例#5
0
 def testBbInside(self):
     ''' test that the function returns False when all points are inside bounding box'''
     pts=((-1, -1), (1., 1.))
     bb=((-2, -3), (3, 4))
     self.assertFalse(geom.out_of_boundingbox(pts, bb))
示例#6
0
 def testBbNoneReturnsFalse(self):
     ''' Test that providing a None boundingbox returns False'''
     pts=((-1, -1), (1., 1.))
     self.assertFalse(geom.out_of_boundingbox(pts, None))