Changeset 671
- Timestamp:
- 08/23/03 01:52:52 (5 years ago)
- Files:
-
- trunk/RBRapier/RBRapier/Formats/SVG/RapierRenderItems.py (modified) (8 diffs)
- trunk/RBRapier/RBRapier/Formats/SVG/SVGSkin/SVGItems/Common.py (modified) (2 diffs)
- trunk/RBRapier/RBRapier/Formats/SVG/SVGSkin/SVGItems/Groups.py (modified) (1 diff)
- trunk/RBRapier/RBRapier/Formats/SVG/SVGSkin/SVGSkinObject.py (modified) (2 diffs)
- trunk/RBRapier/RBRapier/Formats/SVG/SVGSkin/symbol.py (modified) (1 diff)
- trunk/RBRapier/demo/SVG/display.py (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/RBRapier/RBRapier/Formats/SVG/RapierRenderItems.py
r668 r671 164 164 pos = (0,0) 165 165 controlpoint = None 166 beziersteps = 32166 beziersteps = 16 167 167 ellipsesteps = 32 168 168 … … 519 519 child.Compile(style, transform, target) 520 520 521 #~ SVG Settings ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 522 521 523 def SetChildren(self, children): 522 524 self.renderChildren = [] … … 528 530 self.otherChildren.append(child) 529 531 532 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 533 534 class 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 530 546 class 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) 534 551 535 552 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 550 557 551 558 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) 555 607 556 608 return GroupRenderItem._GetStyleAndTransform(self, style, transform) … … 561 613 self.dimensions = width, height 562 614 def SetViewBox(self, viewbox): 563 self.viewbox = viewbox 615 if viewbox is not None: 616 self.viewbox = viewbox 564 617 def SetAlignment(self, xalign, yalign, alignstyle): 565 618 self.alignment = xalign, yalign, alignstyle … … 605 658 606 659 class Rect(RenderItem): 660 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 661 #~ Constants / Variables / Etc. 662 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 663 664 position = (0,0) 665 dimensions = (1,1) 666 667 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 668 #~ Public Methods 669 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 670 607 671 def Compile(self, style, transform, target): 608 672 style, transform = self._GetStyleAndTransform(style, transform) … … 642 706 643 707 class Ellipse(RenderItem): 708 ellipsesteps = 64 644 709 def Compile(self, style, transform, target): 645 710 style, transform = self._GetStyleAndTransform(style, transform) 646 711 647 ellipse = Curves.Ellipse(self.center, self.radiusx, self.radiusy )712 ellipse = Curves.Ellipse(self.center, self.radiusx, self.radiusy, steps=self.ellipsesteps) 648 713 points = transform.TransformPoints(ellipse.asCurve()) 649 714 … … 652 717 fillpoints = Numeric.concatenate((transform.TransformPoints([self.center]), points)) 653 718 fill = GLFill(fillpoints, fillcolor) 654 fill.AddTriangleFan(range(len(points)) )719 fill.AddTriangleFan(range(len(points))+[1]) 655 720 fill.Commit(target) 656 721 … … 826 891 'circle': Circle, 827 892 828 #'symbol': None, 893 'use': UseRenderItem, 894 'symbol': ContainerGroupRenderItem, 829 895 #'pattern': None, 830 896 #'marker': None, trunk/RBRapier/RBRapier/Formats/SVG/SVGSkin/SVGItems/Common.py
r658 r671 31 31 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 32 32 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*)') 34 34 35 35 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ … … 79 79 if match: 80 80 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) 82 87 else: 83 88 raise trunk/RBRapier/RBRapier/Formats/SVG/SVGSkin/SVGItems/Groups.py
r657 r671 42 42 if width is not None: 43 43 width = self._asCoord(width) 44 if width < 0 :44 if width < 0 and width is not None: 45 45 raise ValueError, '"width" attribute can not be negative"' 46 46 height = settings.get('height', None) 47 47 if height is not None: 48 48 height = self._asCoord(height) 49 if height < 0 :49 if height < 0 and height is not None: 50 50 raise ValueError, '"height" attribute can not be negative"' 51 51 self.object.SetDimensions(width, height) trunk/RBRapier/RBRapier/Formats/SVG/SVGSkin/SVGSkinObject.py
r657 r671 63 63 64 64 try: 65 if self. context.saveids:65 if self._GetSaveId(): 66 66 idname = self.settings['id'] 67 67 idmapping = self.context.idmapping … … 89 89 del self.context 90 90 91 def _GetSaveId(self): 92 return self.context.saveids 93 91 94 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 92 95 trunk/RBRapier/RBRapier/Formats/SVG/SVGSkin/symbol.py
r657 r671 32 32 33 33 class symbol(ContainerSVGItem, SVGSkinObject): 34 pass 34 def _GetSaveId(self): 35 return True 36 trunk/RBRapier/demo/SVG/display.py
r667 r671 90 90 def OnSkinFinalize(self): 91 91 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 93 100 94 101 self.viewsetup = GLViewSetup(self.glcanvas, 15) … … 102 109 self.root = SequenceMgr.RootSequence() 103 110 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)) 105 112 self.root.AddElement(self.clearcolor, -2) 106 113 … … 112 119 self.root.AddPostElement(self.projection.Deselect) 113 120 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)) 115 123 self.root.AddElement(xform.Select) 116 124 self.root.AddPostElement(xform.Deselect) … … 121 129 122 130 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 126 138 127 139 self.root.AddElement(self.svgs) … … 140 152 def PostRender(self, glviewsetup, canvas): 141 153 glviewsetup.OnRender.Remove(self.PostRender) 142 DisplayList.DisplayList.InsertAspect(self.svgs)154 #DisplayList.DisplayList.InsertAspect(self.svgs) 143 155 144 156 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
