Changeset 671

Show
Ignore:
Timestamp:
08/23/03 01:52:52 (5 years ago)
Author:
sholloway
Message:

*** empty log message ***

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/RBRapier/RBRapier/Formats/SVG/RapierRenderItems.py

    r668 r671  
    164164    pos = (0,0) 
    165165    controlpoint = None 
    166     beziersteps = 32 
     166    beziersteps = 16 
    167167    ellipsesteps = 32 
    168168 
     
    519519            child.Compile(style, transform, target) 
    520520 
     521    #~ SVG Settings ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
     522 
    521523    def SetChildren(self, children): 
    522524        self.renderChildren = [] 
     
    528530                self.otherChildren.append(child) 
    529531 
     532#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
     533 
     534class UseRenderItem(RenderItem): 
     535    def Compile(self, style=None, transform=None, target=None): 
     536        style, transform = self._GetStyleAndTransform(style, transform) 
     537        self.useitem.Compile(style, transform, target) 
     538 
     539    #~ SVG Settings ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
     540 
     541    def SetUseItem(self, useitem): 
     542        self.useitem = useitem 
     543 
     544#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
     545 
    530546class ContainerGroupRenderItem(GroupRenderItem): 
    531     viewbox = None 
    532     dimensions = None 
    533     alignment = None 
     547    viewbox = (None, None, None, None) 
     548    dimensions = (None, None) 
     549    alignment = ('xmid', 'ymid', 'meet') 
     550    position = (0, 0) 
    534551 
    535552    def _GetStyleAndTransform(self, style=None, transform=None): 
    536         if self.viewbox is not None: 
    537             x, y, w, h = self.viewbox 
    538         elif self.dimensions is not None: 
    539             x, y = 0, 0 
    540             w, h = self.dimensions 
    541         else: 
    542             x, y, w, h = 0,0,100,100 
    543  
    544         projection = Transform() 
    545         projection.matrix( 
    546             2./w, 0., -1-2.*x/w,  
    547             0., 2./h, -1-2.*y/h) 
    548  
    549         # TODO: implement alignment 
     553        vx, vy, vw, vh = self.viewbox 
     554        uw, uh = self.dimensions 
     555        uw = uw or 2. # 1 - -1 
     556        uh = uh or 2. # 1 - -1 
    550557 
    551558        if transform is None: 
    552             transform = projection 
    553         else:  
    554             transform = transform * projection 
     559            # This implies that the default OpenGL portal is setup and the 
     560            # display is [-1,1] wide and [-1,1] tall.  Since I'm trying to 
     561            # implement this coordinate independent, then the svg dimensions 
     562            # should be mapped to this [-1,1] range in both directions.  At 
     563            # this point, we can also flip the coordinate system for OpenGL. 
     564 
     565            transform = Transform() 
     566            transform.matrix(2./uw, 0., -1., 0., -2./uh, 1.) 
     567 
     568        if vw > 0. and vh > 0.: 
     569            vx = vx or 0. 
     570            vy = vy or 0. 
     571 
     572            transform = transform.copy() 
     573            xalign, yalign, aligntype = [s and s.lower() or s for s in self.alignment] 
     574            nw = float(vw)/uw 
     575            nh = float(vh)/uh 
     576 
     577            if aligntype == 'meet': 
     578                # scale by larger dimension 
     579                if nh > nw: 
     580                    # height is greater -- scale by height 
     581                    sx = sy = uh/vh 
     582                else: 
     583                    # width is greater -- scale by width 
     584                    sx = sy = uw/vw 
     585            elif aligntype == 'slice': 
     586                # scale by smaller dimension 
     587                if nh < nw: 
     588                    # width is greater -- scale by height 
     589                    sx = sy = uh/vh 
     590                else: 
     591                    # height is greater -- scale by width 
     592                    sx = sy = uw/vw 
     593            else: 
     594                sx, sy = uw/vw, uh/vh 
     595 
     596            if xalign == 'xmin': tx = vx 
     597            elif xalign == 'xmid': tx = vx - 0.5*(uw/sx-vw) 
     598            elif xalign == 'xmax': tx = vx - (uw/sx-vw) 
     599            else: tx = vx - 0.5*(uw/sx-vw) 
     600 
     601            if yalign == 'ymin': ty = vy 
     602            elif yalign == 'ymid': ty = vy - 0.5*(uh/sy-vh) 
     603            elif yalign == 'ymax': ty = vy - (uh/sy-vh) 
     604            else: ty = vy - 0.5*(uh/sy-vh) 
     605 
     606            transform.matrix(sx, 0., sx*-tx, 0., sy, sy*-ty) 
    555607 
    556608        return GroupRenderItem._GetStyleAndTransform(self, style, transform) 
     
    561613        self.dimensions = width, height 
    562614    def SetViewBox(self, viewbox): 
    563         self.viewbox = viewbox 
     615        if viewbox is not None: 
     616            self.viewbox = viewbox 
    564617    def SetAlignment(self, xalign, yalign, alignstyle): 
    565618        self.alignment = xalign, yalign, alignstyle 
     
    605658 
    606659class Rect(RenderItem): 
     660    #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
     661    #~ Constants / Variables / Etc.  
     662    #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
     663 
     664    position = (0,0) 
     665    dimensions = (1,1) 
     666 
     667    #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
     668    #~ Public Methods  
     669    #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
     670 
    607671    def Compile(self, style, transform, target): 
    608672        style, transform = self._GetStyleAndTransform(style, transform) 
     
    642706 
    643707class Ellipse(RenderItem): 
     708    ellipsesteps = 64 
    644709    def Compile(self, style, transform, target): 
    645710        style, transform = self._GetStyleAndTransform(style, transform) 
    646711 
    647         ellipse = Curves.Ellipse(self.center, self.radiusx, self.radiusy
     712        ellipse = Curves.Ellipse(self.center, self.radiusx, self.radiusy, steps=self.ellipsesteps
    648713        points = transform.TransformPoints(ellipse.asCurve()) 
    649714 
     
    652717            fillpoints = Numeric.concatenate((transform.TransformPoints([self.center]), points)) 
    653718            fill = GLFill(fillpoints, fillcolor) 
    654             fill.AddTriangleFan(range(len(points))
     719            fill.AddTriangleFan(range(len(points))+[1]
    655720            fill.Commit(target) 
    656721 
     
    826891        'circle': Circle, 
    827892         
    828         #'symbol': None, 
     893        'use': UseRenderItem, 
     894        'symbol': ContainerGroupRenderItem, 
    829895        #'pattern': None, 
    830896        #'marker': None, 
  • trunk/RBRapier/RBRapier/Formats/SVG/SVGSkin/SVGItems/Common.py

    r658 r671  
    3131#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
    3232 
    33 _re_coordwithunits = re.compile(r'([-+]?(?:\d+(?:\.\d*)?|\d*\.\d+)(?:[eE][-+]?\d+)?)(\w*)') 
     33_re_coordwithunits = re.compile(r'([-+]?(?:\d+(?:\.\d*)?|\d*\.\d+)(?:[eE][-+]?\d+)?)(\D*)') 
    3434 
    3535#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
     
    7979            if match: 
    8080                value, units = match.groups() 
    81                 return float(value) 
     81                # FIXME 
     82                print "Warning: unit %r found in coordinate %r" % (units, coord) 
     83                if units == '%': 
     84                    return None  
     85                else: 
     86                    return float(value) 
    8287            else: 
    8388                raise 
  • trunk/RBRapier/RBRapier/Formats/SVG/SVGSkin/SVGItems/Groups.py

    r657 r671  
    4242        if width is not None: 
    4343            width = self._asCoord(width) 
    44             if width < 0
     44            if width < 0 and width is not None
    4545                raise ValueError, '"width" attribute can not be negative"' 
    4646        height = settings.get('height', None) 
    4747        if height is not None: 
    4848            height = self._asCoord(height) 
    49             if height < 0
     49            if height < 0 and height is not None
    5050                raise ValueError, '"height" attribute can not be negative"' 
    5151        self.object.SetDimensions(width, height) 
  • trunk/RBRapier/RBRapier/Formats/SVG/SVGSkin/SVGSkinObject.py

    r657 r671  
    6363 
    6464        try:  
    65             if self.context.saveids
     65            if self._GetSaveId()
    6666                idname = self.settings['id'] 
    6767                idmapping = self.context.idmapping 
     
    8989        del self.context 
    9090 
     91    def _GetSaveId(self): 
     92        return self.context.saveids 
     93 
    9194#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
    9295 
  • trunk/RBRapier/RBRapier/Formats/SVG/SVGSkin/symbol.py

    r657 r671  
    3232 
    3333class symbol(ContainerSVGItem, SVGSkinObject): 
    34     pass 
     34    def _GetSaveId(self): 
     35        return True 
     36 
  • trunk/RBRapier/demo/SVG/display.py

    r667 r671  
    9090    def OnSkinFinalize(self): 
    9191        SVGRenderItemFactory=RapierRenderItems.RapierSVGRenderItemFactory() 
    92         self.svgitems = [SVGSkinner.SkinFile(svgfile, SVGRenderItemFactory=SVGRenderItemFactory).object for svgfile in sys.argv[1:]] 
     92 
     93        svgfile = ' '.join(sys.argv[1:]) 
     94        print "Parsing \"%s\" as SVG... (%s)" % (svgfile, time.strftime('%X'),) 
     95        s = time.time() 
     96        self.svgitem = SVGSkinner.SkinFile(svgfile, SVGRenderItemFactory=SVGRenderItemFactory).object 
     97        d = time.time() - s 
     98        print "done. (%s -- %1.3fs)" % (time.strftime('%X'), d) 
     99        print 
    93100 
    94101        self.viewsetup = GLViewSetup(self.glcanvas, 15) 
     
    102109        self.root = SequenceMgr.RootSequence() 
    103110 
    104         self.clearcolor = Buffers.ClearColor((1.0,1.0,1.0,0.0)) 
     111        self.clearcolor = Buffers.ClearColor((0.0,0.0,0.0,0.0)) 
    105112        self.root.AddElement(self.clearcolor, -2) 
    106113 
     
    112119        self.root.AddPostElement(self.projection.Deselect) 
    113120 
    114         xform = Transformations.ScaleMgd(GL.GL_PROJECTION, True, (1, -1, 1)) 
     121        # Note: replace 3./4. by the screen aspect ratio h/w 
     122        xform = Transformations.ScaleMgd(GL.GL_PROJECTION, True, (1., 3./4., 1))  
    115123        self.root.AddElement(xform.Select) 
    116124        self.root.AddPostElement(xform.Deselect) 
     
    121129 
    122130        self.svgs = SequenceMgr.Sequence() 
    123         while self.svgitems: 
    124             svg = self.svgitems.pop() 
    125             self.svgs.AddElements(svg.Compile()) 
     131         
     132        print "Compling svg... (%s)" % (time.strftime('%X'),) 
     133        s = time.time() 
     134        self.svgs.AddElements(self.svgitem.Compile()) 
     135        d = time.time() - s 
     136        print "done. (%s -- %1.3fs)" % (time.strftime('%X'), d) 
     137        print 
    126138 
    127139        self.root.AddElement(self.svgs) 
     
    140152    def PostRender(self, glviewsetup, canvas): 
    141153        glviewsetup.OnRender.Remove(self.PostRender) 
    142         DisplayList.DisplayList.InsertAspect(self.svgs) 
     154        #DisplayList.DisplayList.InsertAspect(self.svgs) 
    143155 
    144156#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~