Changeset 631
- Timestamp:
- 07/15/03 21:10:02 (5 years ago)
- Files:
-
- trunk/RBRapier/RBRapier/Formats/Attic/SVG.old/Renderers/Abstract.py (modified) (1 diff)
- trunk/RBRapier/RBRapier/Formats/Attic/SVG.old/Renderers/Logging.py (modified) (1 diff)
- trunk/RBRapier/RBRapier/Formats/Attic/SVG.old/Renderers/Null.py (modified) (1 diff)
- trunk/RBRapier/RBRapier/Formats/Attic/SVG.old/Renderers/Rapier.py (modified) (6 diffs)
- trunk/RBRapier/RBRapier/Formats/Attic/SVG.old/Renderers/RapierObjects.py (added)
- trunk/RBRapier/RBRapier/Formats/Attic/SVG.old/SVGSkin/RenderItems/Common.py (modified) (1 diff)
- trunk/RBRapier/RBRapier/Formats/Attic/SVG.old/SVGSkin/RenderItems/Groups.py (modified) (4 diffs)
- trunk/RBRapier/RBRapier/Formats/Attic/SVG.old/SVGSkin/RenderItems/PathBuilder.py (modified) (7 diffs)
- trunk/RBRapier/RBRapier/Formats/Attic/SVG.old/SVGSkin/RenderItems/Styled.py (modified) (2 diffs)
- trunk/RBRapier/RBRapier/Formats/Attic/SVG.old/SVGSkin/RenderItems/TransformBuilder.py (modified) (1 diff)
- trunk/RBRapier/RBRapier/Formats/Attic/SVG.old/SVGSkin/SVGSkinObject.py (modified) (3 diffs)
- trunk/RBRapier/RBRapier/Formats/Attic/SVG.old/SVGSkin/use.py (modified) (2 diffs)
- trunk/RBRapier/demo/Attic/SVG.old/display.py (modified) (8 diffs)
- trunk/RBRapier/demo/Attic/SVG.old/logdisplay.py (modified) (1 diff)
- trunk/RBRapier/demo/Attic/SVG.old/nulldisplay.py (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/RBRapier/RBRapier/Formats/Attic/SVG.old/Renderers/Abstract.py
r630 r631 35 35 36 36 def Display(self, ri): 37 r eturn ri.DisplayOn(self)37 raise NotImplementedError 38 38 39 39 #~ Meta Information ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ trunk/RBRapier/RBRapier/Formats/Attic/SVG.old/Renderers/Logging.py
r630 r631 43 43 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 44 44 45 def __init__(self):45 def Display(self, ri): 46 46 self.resolver = [] 47 ri.DisplayOn(self) 48 del self.resolver 47 49 48 50 #~ Meta Information ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ trunk/RBRapier/RBRapier/Formats/Attic/SVG.old/Renderers/Null.py
r630 r631 32 32 33 33 class NullRenderer(Abstract.AbstractRenderer): 34 def __init__(self):34 def Display(self, ri): 35 35 self.resolver = [] 36 ri.DisplayOn(self) 37 del self.resolver 36 38 37 39 #~ Meta Information ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ trunk/RBRapier/RBRapier/Formats/Attic/SVG.old/Renderers/Rapier.py
r630 r631 24 24 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 25 25 26 import logging 26 import warnings 27 from OpenGL import GL 28 29 from RBRapier.Renderer.View import Transformations 30 from RBRapier.Renderer.Geometry import VertexArrays 31 from RBRapier.Renderer.Geometry import ArrayTraversal 32 from RBRapier.Renderer import SequenceMgr 33 27 34 import Abstract 35 import RapierObjects 28 36 29 37 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ … … 31 39 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 32 40 41 class RapierPathFactory(Abstract.AbstractPathFactory): 42 __slots__ = 'pos', 'pathlist' 43 44 def BeginPath(self, pathstr): 45 self.pathlist = [] 46 self.pos = 0., 0. 47 48 def AddPathElement(self, name, *args): 49 name, relative = self.command_table[name] 50 getattr(self, name.lower())(relative, *args) 51 52 def EndPath(self, pathstr): 53 pass 54 55 def move(self, relative, x, y): 56 if relative: 57 dx, dy = self.pos 58 x += dx 59 y += dy 60 self.pathlist.append([(x,y)]) 61 self.pos = x,y 62 63 def closepath(self, relative): 64 lastpath = self.pathlist[-1] 65 self.pos = lastpath[0] 66 lastpath.append(self.pos) 67 68 def line(self, relative, x, y): 69 if relative: 70 dx, dy = self.pos 71 x += dx 72 y += dy 73 self.pathlist[-1].append((x,y)) 74 self.pos = x,y 75 76 def hline(self, relative, x): 77 dx, y = self.pos 78 if relative: 79 x += dx 80 self.pathlist[-1].append((x,y)) 81 self.pos = x,y 82 83 def vline(self, relative, y): 84 x, dy = self.pos 85 if relative: 86 y += dy 87 self.pathlist[-1].append((x,y)) 88 self.pos = x,y 89 90 def cubicbezier(self, relative, x1, y1, x2, y2, x, y): 91 if relative: 92 dx, dy = self.x, self.y 93 x1 += dx 94 y1 += dy 95 x2 += dx 96 y2 += dy 97 x += dx 98 y += dy 99 warnings.warn( "TODO: path.cubicbezier") 100 self.pathlist[-1].append((x,y)) 101 self.pos = x,y 102 103 def smoothcurve(self, relative, x2, y2, x, y): 104 if relative: 105 dx, dy = self.pos 106 x2 += dx 107 y2 += dy 108 x += dx 109 y += dy 110 warnings.warn( "TODO: path.smoothcurve") 111 self.pathlist[-1].append((x,y)) 112 self.pos = x,y 113 114 def quadraticbezier(self, relative, x1, y1, x, y): 115 if relative: 116 dx, dy = self.pos 117 x1 += dx 118 y1 += dy 119 x += dx 120 y += dy 121 warnings.warn( "TODO: path.quadraticbezier") 122 self.pathlist[-1].append((x,y)) 123 self.pos = x,y 124 125 def smoothquadraticbezier(self, relative, x, y): 126 if relative: 127 dx, dy = self.pos 128 x += dx 129 y += dy 130 warnings.warn( "TODO: path.smoothquadraticbezier") 131 self.pathlist[-1].append((x,y)) 132 self.pos = x,y 133 134 def ellipticarc(self, relative, rx, ry, xrotation, largeArcFlag, sweepFlag, x, y): 135 if relative: 136 dx, dy = self.pos 137 x += dx 138 y += dy 139 warnings.warn( "TODO: path.ellipticarc") 140 self.pathlist[-1].append((x,y)) 141 self.pos = x,y 142 143 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 144 145 class RapierTransformFactory(object): 146 def __init__(self, xform): 147 pass 148 149 def BeginTransform(self, transformstr): 150 pass 151 def AddTransformElement(self, name, *args): 152 pass 153 def EndTransform(self, transformstr): 154 pass 155 156 def translate(self, x=0.0, y=0.0): 157 warnings.warn( "TODO: transform.translate") 158 def scale(self, x=1., y=None): 159 warnings.warn( "TODO: transform.scale") 160 def rotate(self, angle=0.0, x=0, y=0): 161 warnings.warn( "TODO: transform.rotate") 162 def skewx(self, angle=0.0): 163 warnings.warn( "TODO: transform.skewx") 164 def skewy(self, angle=0.0): 165 warnings.warn( "TODO: transform.skewy") 166 def matrix(self, xx=1.0, xy=0.0, xh=0.0, yx=0.0, yy=1.0, yh=0.0, hx=0.0, hy=0.0, hh=1.0): 167 warnings.warn( "TODO: transform.matrix") 168 169 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 170 33 171 class RapierRenderer(Abstract.AbstractRenderer): 34 def __init__(self): 172 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 173 #~ Constants / Variables / Etc. 174 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 175 176 PathFactory = RapierPathFactory 177 TransformFactory = RapierTransformFactory 178 SequenceFactory = SequenceMgr.Sequence 179 180 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 181 #~ Public Methods 182 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 183 184 def Display(self, ri): 185 rootsequence = self.SequenceFactory() 186 self.sequence = rootsequence 187 self.style = {} 188 189 # SVG coordinate system is upside down from OpenGL's 190 xform = Transformations.ScaleMgd(GL.GL_PROJECTION, True, (1, -1, 1)) 191 self.sequence.AddElement(xform.Select) 192 self.sequence.AddPostElement(xform.Deselect) 193 194 xform = Transformations.IdentityMgd(GL.GL_MODELVIEW, True) 195 self.sequence.AddElement(xform.Select) 196 self.sequence.AddPostElement(xform.Deselect) 197 35 198 self.context = [] 36 199 self.resolver = [] 37 200 201 try: 202 ri.DisplayOn(self) 203 finally: 204 del self.resolver 205 del self.context 206 del self.sequence 207 return rootsequence 208 38 209 #~ Meta Information ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 39 210 … … 47 218 48 219 def DisplaySVG(self, ri_svg): 49 self.PushContext(ri_svg )220 self.PushContext(ri_svg, True) 50 221 self.resolver.append(ri_svg.idmapping) 51 222 try: … … 63 234 64 235 def DisplaySymbol(self, ri_symbol): 65 self.PushContext(ri_symbol )236 self.PushContext(ri_symbol, True) 66 237 try: 67 238 ri_symbol.DisplayChildrenOn(self) … … 81 252 82 253 def DisplayLine(self, ri_line): 83 print "TODO: DisplayLine" 254 self.PushContext(ri_line) 255 try: 256 self.sequence.AddElement(RapierObjects.Line((ri_line.x1, ri_line.y1), (ri_line.x2, ri_line.y2))) 257 finally: 258 self.PopContext(ri_line) 84 259 85 260 def DisplayRect(self, ri_rect): 86 print "TODO: DisplayRect" 261 self.PushContext(ri_rect) 262 try: 263 self.sequence.AddElement(RapierObjects.Rect(ri_rect.width, ri_rect.height)) 264 finally: 265 self.PopContext(ri_rect) 87 266 88 267 def DisplayCircle(self, ri_circle): 89 print "TODO: DisplayCircle" 268 self.PushContext(ri_circle) 269 try: 270 warnings.warn( "TODO: DisplayCircle") 271 finally: 272 self.PopContext(ri_circle) 90 273 91 274 def DisplayEllipse(self, ri_ellipse): 92 print "TODO: DisplayEllipse" 275 self.PushContext(ri_ellipse) 276 try: 277 warnings.warn( "TODO: DisplayEllipse") 278 finally: 279 self.PopContext(ri_ellipse) 93 280 94 281 def DisplayPolygon(self, ri_polygon): 95 print "TODO: DisplayPolygon" 282 self.PushContext(ri_polygon) 283 try: 284 self.sequence.AddElement(RapierObjects.Polygon(ri_polygon.points)) 285 finally: 286 self.PopContext(ri_polygon) 96 287 97 288 def DisplayPolyline(self, ri_polyline): 98 print "TODO: DisplayPolyline" 289 self.PushContext(ri_polyline) 290 try: 291 self.sequence.AddElement(RapierObjects.Polyline(ri_polyline.points)) 292 finally: 293 self.PopContext(ri_polyline) 99 294 100 295 def DisplayPath(self, ri_path): 101 print "TODO: DisplayPath" 296 self.PushContext(ri_path) 297 try: 298 pathlist = ri_path.path.RestoreTo(self.PathFactory()).pathlist 299 self.sequence.AddElement(RapierObjects.Path(pathlist)) 300 finally: 301 self.PopContext(ri_path) 102 302 103 303 def DisplayText(self, ri_text): 104 print "TODO: DisplayText" 304 self.PushContext(ri_text) 305 try: 306 warnings.warn( "TODO: DisplayText") 307 finally: 308 self.PopContext(ri_text) 105 309 106 310 #~ Order management ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ … … 110 314 return self.resolver[-1].get(tag, None) 111 315 112 def PushContext(self, ri): 113 print "TODO: PushContext" 316 def PushContext(self, ri, extendTransform=False): 317 self.context.append([self.sequence, self.style]) 318 319 if extendTransform: 320 self._DoExtendedTransform(ri) 321 else: 322 self._DoTransform(ri) 323 self._DoStyle(ri) 114 324 115 325 def PopContext(self, ri): 116 print "TODO: PopContext" 117 118 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 119 120 class RapierPathFactory(object): 121 def BeginPath(self, pathstr): 122 pass 123 def AddPathElement(self, name, relative, *args): 124 getattr(self, name.lower())(relative, *args) 125 def EndPath(self, pathstr): 126 pass 127 128 def move(self, relative, x, y): 129 pass 130 def closepath(self, relative): 131 pass 132 def line(self, relative, x, y): 133 pass 134 def hline(self, relative, x): 135 pass 136 def vline(self, relative, y): 137 pass 138 def cubicbezier(self, relative, x1, y1, x2, y2, x, y): 139 pass 140 def smoothcurve(self, relative, x2, y2, x, y): 141 pass 142 def quadraticbezier(self, relative, x1, y1, x, y): 143 pass 144 def smoothquadraticbezier(self, relative, x, y): 145 pass 146 def ellipticarc(self, relative, rx, ry, xrotation, largeArcFlag, sweepFlag, x, y): 147 pass 148 149 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 150 151 class RapierTransform(object): 152 def BeginTransform(self, transformstr): 153 pass 154 def AddTransformElement(self, name, *args): 155 pass 156 def EndTransform(self, transformstr): 157 pass 158 159 def translate(self, x=0.0, y=0.0): 160 pass 161 def scale(self, x=1., y=None): 162 pass 163 def rotate(self, angle=0.0, x=0, y=0): 164 pass 165 def skewx(self, angle=0.0): 166 pass 167 def skewy(self, angle=0.0): 168 pass 169 def matrix(self, xx=1.0, xy=0.0, xh=0.0, yx=0.0, yy=1.0, yh=0.0, hx=0.0, hy=0.0, hh=1.0): 170 pass 171 326 self.sequence, self.style = self.context.pop() 327 328 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 329 330 def PushSequence(self): 331 newsequence = self.SequenceFactory() 332 self.sequence.AddElement(newsequence.Execute) 333 self.sequence = newsequence 334 return self.sequence 335 336 def _DoStyle(self, ri): 337 try: newstyle = ri.style 338 except AttributeError: pass 339 340 if newstyle: 341 self.style = self.style.copy() 342 self.style.update(newstyle) 343 344 if self.style: 345 color = self.style.get('fill') or self.style.get('stroke') 346 if color: 347 self.sequence.AddElement(RapierObjects.Color(color)) 348 349 def _DoTransform(self, ri): 350 x, y, transform = ri.x, ri.y, ri.transform 351 if not (x or y or transform): 352 return False 353 354 if transform: 355 xform = Transformations.CompositeMgd(None, True) 356 if x or y: 357 xform.Add(Transformations.Translate((x or 0., y or 0.))) 358 transform.RestoreTo(self.TransformFactory(xform)) 359 elif x or y: 360 xform = Transformations.TranslateMgd(None, True, (x or 0., y or 0.)) 361 362 sequence = self.PushSequence() 363 sequence.AddElement(xform.Select) 364 sequence.AddPostElement(xform.Deselect) 365 366 return True 367 368 def _DoExtendedTransform(self, ri): 369 l, b, w, h = ri.viewBox 370 xform = Transformations.OrthographicMgd(None, True, l, l+w, b, b+h) 371 372 sequence = self.PushSequence() 373 sequence.AddElement(xform.Select) 374 sequence.AddPostElement(xform.Deselect) 375 376 return True 377 trunk/RBRapier/RBRapier/Formats/Attic/SVG.old/SVGSkin/RenderItems/Common.py
r630 r631 40 40 #~ Public Methods 41 41 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 42 43 def __init__(self): 44 RenderItemBase.count += 1 45 count = 0 46 def __del__(self): 47 RenderItemBase.count -= 1 48 if not RenderItemBase.count: 49 print "Zero point for svg render items" 42 50 43 51 def __repr__(self): trunk/RBRapier/RBRapier/Formats/Attic/SVG.old/SVGSkin/RenderItems/Groups.py
r630 r631 24 24 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 25 25 26 from Common import TransformableRenderItem26 from Styled import StyledRenderItem 27 27 28 28 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ … … 30 30 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 31 31 32 class GroupRenderItem( TransformableRenderItem):32 class GroupRenderItem(StyledRenderItem): 33 33 def __init__(self): 34 TransformableRenderItem.__init__(self)34 StyledRenderItem.__init__(self) 35 35 self.children = [] 36 36 … … 49 49 GroupRenderItem.InterpretSettings(self, settings) 50 50 51 try: width = settings['width ']51 try: width = settings['width'] 52 52 except LookupError: pass 53 53 else: self.width = width … … 93 93 def GetViewBox(self): 94 94 try: 95 return self. viewbox95 return self._viewBox 96 96 except AttributeError: 97 97 self._viewbox = [self.x, self.y, self.width, self.height] 98 98 return self._viewbox 99 99 def SetViewBox(self, value): 100 self._view box = self._asViewBox(value)101 view box = property(GetViewBox, SetViewBox)100 self._viewBox = self._asViewBox(value) 101 viewBox = property(GetViewBox, SetViewBox) 102 102 103 103 def GetPreserveAspectRatio(self): trunk/RBRapier/RBRapier/Formats/Attic/SVG.old/SVGSkin/RenderItems/PathBuilder.py
r629 r631 61 61 62 62 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 63 #~ Definitions64 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~65 66 def _pathcommand(name, relative, nextcommand, argtypes):67 return {'name':name, 'relative':relative, 'nextcommand':nextcommand, 'argtypes':argtypes}68 69 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~70 63 #~ Path Factories 71 64 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ … … 73 66 class AbstractPathFactory(object): 74 67 __slots__ = () 68 69 command_table = { 70 'M': ('move', False), 71 'm': ('move', True), 72 73 'Z': ('closepath', False), 74 'z': ('closepath', True), 75 76 'L': ('line', False), 77 'l': ('line', True), 78 79 'H': ('hline', False), 80 'h': ('hline', True), 81 82 'V': ('vline', False), 83 'v': ('vline', True), 84 85 'C': ('cubicbezier', False), 86 'c': ('cubicbezier', True), 87 88 'S': ('smoothcurve', False), 89 's': ('smoothcurve', True), 90 91 'Q': ('quadraticbezier', False), 92 'q': ('quadraticbezier', True), 93 94 'T': ('smoothquadraticbezier', False), 95 't': ('smoothquadraticbezier', True), 96 97 'A': ('ellipticarc', False), 98 'a': ('ellipticarc', True), 99 } 75 100 76 101 def BeginPath(self, pathstr): … … 122 147 pathfactory.AddPathElement(*args) 123 148 pathfactory.EndPath(self.pathstr) 149 return pathfactory 124 150 125 151 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ … … 141 167 _flag = (_re_flag, int) 142 168 143 pathCommandTable = { 144 'M': _pathcommand('move', False, 'L', (_coord, _coord)), 145 'm': _pathcommand('move', True, 'l', (_coord, _coord)), 146 147 'Z': _pathcommand('closepath', False, 'M', ()), 148 'z': _pathcommand('closepath', True, 'm', ()), 149 150 'L': _pathcommand('line', False, None, (_coord, _coord)), 151 'l': _pathcommand('line', True, None, (_coord, _coord)), 152 153 'H': _pathcommand('hline', False, None, (_coord, )), 154 'h': _pathcommand('hline', True, None, (_coord, )), 155 156 'V': _pathcommand('vline', False, None, (_coord, )), 157 'v': _pathcommand('vline', True, None, (_coord, )), 158 159 'C': _pathcommand('cubicbezier', False, None, (_coord, _coord, _coord, _coord, _coord, _coord)), 160 'c': _pathcommand('cubicbezier', True, None, (_coord, _coord, _coord, _coord, _coord, _coord)), 161 162 'S': _pathcommand('smoothcurve', False, None, (_coord, _coord, _coord, _coord)), 163 's': _pathcommand('smoothcurve', True, None, (_coord, _coord, _coord, _coord)), 164 165 'Q': _pathcommand('quadraticbezier', False, None, (_coord, _coord, _coord, _coord)), 166 'q': _pathcommand('quadraticbezier', True, None, (_coord, _coord, _coord, _coord)), 167 168 'T': _pathcommand('smoothquadraticbezier', False, None, (_coord, _coord)), 169 't': _pathcommand('smoothquadraticbezier', True, None, (_coord, _coord)), 170 171 'A': _pathcommand('ellipticarc', False, None, (_coord, _coord, _rotation, _flag, _flag, _coord, _coord)), 172 'a': _pathcommand('ellipticarc', True, None, (_coord, _coord, _rotation, _flag, _flag, _coord, _coord)), 169 path_transitions = { 'M': 'L', 'm': 'l', 'Z': 'M', 'z': 'm', } 170 path_args = { 171 'M': (_coord, _coord), 172 'm': (_coord, _coord), 173 174 'Z': (), 175 'z': (), 176 177 'L': (_coord, _coord), 178 'l': (_coord, _coord), 179 180 'H': (_coord, ), 181 'h': (_coord, ), 182 183 'V': (_coord, ), 184 'v': (_coord, ), 185 186 'C': (_coord, _coord, _coord, _coord, _coord, _coord), 187 'c': (_coord, _coord, _coord, _coord, _coord, _coord), 188 189 'S': (_coord, _coord, _coord, _coord), 190 's': (_coord, _coord, _coord, _coord), 191 192 'Q': (_coord, _coord, _coord, _coord), 193 'q': (_coord, _coord, _coord, _coord), 194 195 'T': (_coord, _coord), 196 't': (_coord, _coord), 197 198 'A': (_coord, _coord, _rotation, _flag, _flag, _coord, _coord), 199 'a': (_coord, _coord, _rotation, _flag, _flag, _coord, _coord), 173 200 } 174 201 … … 185 212 186 213 matchidx = 0 187 # MoveTo is the default command188 command = self.pathCommandTable['M']214 # MoveTo absolute is the default command 215 commandidx = 'M' 189 216 while matchidx < len(pathstr): 190 217 # Find out what command we're dealing with 191 218 commandmatch = self._re_command.match(pathstr, matchidx) 192 219 if commandmatch is not None: 193 commandidx = commandmatch.groups()[0] 220 commandidx = commandmatch.groups()[0] or commandidx 194 221 matchidx = commandmatch.end() 195 196 if commandidx:197 # Lookup our new command198 command = self.pathCommandTable[commandidx]199 222 200 223 # parse out the arguments for the path element 201 224 arguments = [] 202 for argre, argvalue in command['argtypes']:225 for argre, argvalue in self.path_args[commandidx]: # CommandArguments 203 226 argmatch = argre.match(pathstr, matchidx) 204 227 if argmatch is None: … … 209 232 210 233 # go get the path factory method for our command 211 pathfactory.AddPathElement(command ['name'], command['relative'], *arguments)234 pathfactory.AddPathElement(commandidx, *arguments) 212 235 213 236 # see if we have a command transfer 214 commandidx = command['nextcommand'] 215 if commandidx is not None: 216 # Lookup our new command 217 command = self.pathCommandTable[commandidx] 237 commandidx = self.path_transitions.get(commandidx, commandidx) 218 238 219 239 pathfactory.EndPath(pathstr) … … 231 251 self.results = ["begin()"] 232 252 def AddPathElement(self, name, *args): 233 self.results.append('%s%r' % (name, args)) 253 name, relative = self.command_table[name] 254 self.results.append('%s%r' % (name, (relative,) + args)) 234 255 def EndPath(self, pathstr): 235 256 self.results.append("end()") trunk/RBRapier/RBRapier/Formats/Attic/SVG.old/SVGSkin/RenderItems/Styled.py
r628 r631 24 24 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 25 25 26 import warnings 26 27 from RBFoundation.XMLUtilityFunctions import ColorStringToRGB 27 28 from Common import TransformableRenderItem … … 76 77 """ 77 78 if isinstance(color, (type(None), int, long, tuple)): 78 re turncolor79 result = color 79 80 elif color == 'currentColor': 80 return 'currentColor' 81 result = 'currentColor' 82 elif color.startswith('url'): 83 warnings.warn('TODO: implement color url') 84 result = None 81 85 elif not color: 82 re turnNone86 result = None 83 87 else: 84 return ColorStringToRGB(color) 88 result = ColorStringToRGB(color) 89 return result 85 90 86 91 def _asOpacity(self, opacity): trunk/RBRapier/RBRapier/Formats/Attic/SVG.old/SVGSkin/RenderItems/TransformBuilder.py
r629 r631 91 91 transformfactory.AddTransformElement(*args) 92 92 transformfactory.EndTransform(self.transformstr) 93 return transformfactory 93 94 94 95 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ trunk/RBRapier/RBRapier/Formats/Attic/SVG.old/SVGSkin/SVGSkinObject.py
r630 r631 53 53 self.context = None 54 54 55 SVGSkinObject.count += 1 56 count = 0 57 def __del__(self): 58 SVGSkinObject.count -= 1 59 if not SVGSkinObject.count: 60 print "Zero point for svg skin elements" 61 55 62 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 56 63 … … 70 77 self.children = [] 71 78 self.object = self.RenderItemFactory() 79 80 try: 81 idname = self.settings['id'] 82 idmapping = self.context.idmapping 83 except (KeyError, AttributeError): pass 84 else: idmapping[idname] = self.object 85 72 86 if self.object is not None: 73 87 self.object.InterpretSettings(self.settings) … … 81 95 def _xmlInitFinalized(self): 82 96 if self.object is not None: 83 try:84 idname = self.settings['id']85 except KeyError:86 pass87 else:88 self.context.idmapping[idname] = self.object89 90 97 children = filter(None, [getattr(child, 'object', None) for child in self.children]) 91 98 self.object.AddChildRenderItems(children) trunk/RBRapier/RBRapier/Formats/Attic/SVG.old/SVGSkin/use.py
r630 r631 26 26 import warnings 27 27 from SVGSkinObject import SVGSkinObject 28 from RenderItems. Common import TransformableRenderItem28 from RenderItems.Styled import StyledRenderItem 29 29 30 30 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ … … 32 32 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 33 33 34 class UseRenderItem( TransformableRenderItem):34 class UseRenderItem(StyledRenderItem): 35 35 def DisplayOn(self, renderer): 36 36 renderer.DisplayUse(self) 37 37 38 38 def InterpretSettings(self, settings): 39 TransformableRenderItem.InterpretSettings(self, settings)39 StyledRenderItem.InterpretSettings(self, settings) 40 40 41 41 xlink = settings[('http://www.w3.org/1999/xlink', 'href')] trunk/RBRapier/demo/Attic/SVG.old/display.py
r626 r631 39 39 from RBRapier.Formats import SVG 40 40 import RBRapier.Formats.SVG.SVGSkinner 41 import RBRapier.Formats.SVG.Renderers. Null41 import RBRapier.Formats.SVG.Renderers.Rapier 42 42 43 43 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ … … 47 47 skinxml = """<?xml version='1.0'?> 48 48 <skin:skin xmlns:skin='http://namespaces.runeblade.com/skin' xmlns:py='http://namespaces.runeblade.com/xmlPython' xmlns='http://namespaces.runeblade.com/wxPythonSkin'> 49 <frame title='S imple Cube Demo' show='1' pos='0,0' size='800,600'>49 <frame title='SVG Displayer' show='1' pos='0,0' size='800,600'> 50 50 <layout fit='0'> 51 51 <panel> … … 57 57 </frame> 58 58 59 <!-- 59 60 <frame title='Demo PyCrust' show='1' pos='850,0' size='400,800'> 60 61 <layout fit='0'> … … 62 63 </layout> 63 64 </frame> 65 --> 64 66 </skin:skin> 65 67 """ … … 74 76 75 77 def OnSkinFinalize(self): 76 self.svgrenderer = SVG.Renderers.Null.NullRenderer() 77 78 self.svgskins = [SVG.SVGSkinner.SkinFile(svgfile).object for svgfile in sys.argv[1:]] 78 self.svgitems = [SVG.SVGSkinner.SkinFile(svgfile).object for svgfile in sys.argv[1:]] 79 79 80 80 self.viewsetup = GLViewSetup(self.glcanvas) … … 87 87 self.root = SequenceMgr.RootSequence() 88 88 89 self.clearcolor = Buffers.ClearColor(( 0.5,0.5,0.7,1.0))89 self.clearcolor = Buffers.ClearColor((1.0,1.0,1.0,0.0)) 90 90 self.root.AddElement(self.clearcolor, -2) 91 91 … … 93 93 self.root.AddElement(self.viewport, -2) 94 94 95 self.root.AddElement(self.DisplaySVGSkins) 95 svgrenderer = SVG.Renderers.Rapier.RapierRenderer() 96 while self.svgitems: 97 svg = self.svgitems.pop() 98 self.root.AddElement(svgrenderer.Display(svg)) 96 99 97 100 def Render(self, subject, canvas): … … 99 102 self.root.Execute(None) 100 103 101 def DisplaySVGSkins(self, glcontext): 102 for svgskin in self.svgskins: 103 self.svgrenderer.Display(svgskin) 104 maxfps = 40 105 realfps = self.root.Statistics['persecond'] 106 targetfps = self.viewsetup.GetTargetFPS() 107 if realfps < 2*targetfps: 108 newtarget = min(maxfps, realfps*0.45) 109 self.viewsetup.SetTargetFPS(newtarget) 110 print "Lowering fps to:", newtarget, "old target:", targetfps, "real:", realfps 104 111 105 112 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ trunk/RBRapier/demo/Attic/SVG.old/logdisplay.py
r626 r631 41 41 42 42 for svgfile in sys.argv[1:]: 43 print "Started \"%s\" on %s" % (svgfile, time.asctime()) 44 print 43 print "Started \"" + svgfile + "\" on", time.asctime() 45 44 46 45 start = time.clock() 47 46 skin = SkinFile(svgfile) 48 parse end = time.clock()47 parsed = time.clock() 49 48 skin.DisplayOn(renderer) 50 displaye nd = time.clock()49 displayed = time.clock() 51 50 52 print 53 print "Completed on %s (parse %1.1fs, display %1.1fs, total %1.1fs)" % (time.asctime(), parseend-start, displayend-parseend, displayend-start) 51 print "Completed on", time.asctime() 52 print "Timing info: %1.1f display, %1.1f parse, %1.1f total" % ( displayed-parsed, parsed-start, displayed-start) 53 trunk/RBRapier/demo/Attic/SVG.old/nulldisplay.py
r626 r631 39 39 40 40 for svgfile in sys.argv[1:]: 41 print "Started \"%s\" on %s" % (svgfile, time.asctime()) 42 print 41 print "Started \"" + svgfile + "\" on", time.asctime() 43 42 44 43 times = [time.clock()] … … 50 49 51 50 times = [b-a for a, b in zip(times[:-1], times[1:])] 52 print 53 print "Completed on %s times: %r" % (time.asctime(), times) 51 print "Completed on", time.asctime() 52 print "Timing info:", ', '.join(['%1.5fs' % t for t in times]) 53
