gump-general mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aj...@apache.org
Subject cvs commit: gump/python/gump/svg __init__.py depdiag.py svg.py drawing.py .cvsignore
Date Fri, 09 Apr 2004 22:38:26 GMT
ajack       2004/04/09 15:38:26

  Modified:    python/gump/document forrest.py
               python/gump/utils __init__.py
               python/gump/test pyunit.py
               python/gump/output statsdb.py
  Added:       python/gump/shared .cvsignore __init__.py comparator.py
               python/gump/test depdiag.py svg.py drawing.py
               python/gump/svg __init__.py depdiag.py svg.py drawing.py
                        .cvsignore
  Log:
  ******* Work in progress *******
  
  Tinkering with a dependency diagram, written as SVG, to show
  relationships (using graphics/colors/patterns).
  
  Revision  Changes    Path
  1.1                  gump/python/gump/shared/.cvsignore
  
  Index: .cvsignore
  ===================================================================
  *.pyc
  
  
  
  1.1                  gump/python/gump/shared/__init__.py
  
  Index: __init__.py
  ===================================================================
  #!/usr/bin/env python
  
  # Copyright 2003-2004 The Apache Software Foundation
  #
  # Licensed under the Apache License, Version 2.0 (the "License");
  # you may not use this file except in compliance with the License.
  # You may obtain a copy of the License at
  # 
  #     http://www.apache.org/licenses/LICENSE-2.0
  # 
  # Unless required by applicable law or agreed to in writing, software
  # distributed under the License is distributed on an "AS IS" BASIS,
  # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  # See the License for the specific language governing permissions and
  # limitations under the License.
  
  # tell Python what modules make up the gump.output package
  __all__ = ["comparator"]
  
  
  
  1.1                  gump/python/gump/shared/comparator.py
  
  Index: comparator.py
  ===================================================================
  #!/usr/bin/python
  
  # Copyright 2003-2004 The Apache Software Foundation
  #
  # Licensed under the Apache License, Version 2.0 (the "License");
  # you may not use this file except in compliance with the License.
  # You may obtain a copy of the License at
  # 
  #     http://www.apache.org/licenses/LICENSE-2.0
  # 
  # Unless required by applicable law or agreed to in writing, software
  # distributed under the License is distributed on an "AS IS" BASIS,
  # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  # See the License for the specific language governing permissions and
  # limitations under the License.
  
  #
  # $Header: /home/cvs/gump/python/gump/shared/comparator.py,v 1.1 2004/04/09 22:38:25 ajack
Exp $
  # 
              
  #
  # Module Comparisons
  #            
          
  def compareModulesByElapsed(module1,module2):
      elapsed1=module1.getElapsedSecs()
      elapsed2=module2.getElapsedSecs()
      c = 0
      if elapsed1 > elapsed2: c = -1
      if elapsed1 < elapsed2: c = 1       
      if not c: c=cmp(module1,module2)
      return c
  
  def compareModulesByProjectCount(module1,module2):
      count1=len(module1.getProjects())
      count2=len(module2.getProjects())
      c = count2 - count1                  
      if not c: c=cmp(module1,module2)
      return c
  
  def compareModulesByDependencyCount(module1,module2):
      count1=module1.getFullDependencyCount()
      count2=module2.getFullDependencyCount()
      c= count2 - count1                 
      if not c: c=cmp(module1,module2)
      return c        
          
  def compareModulesByDependeeCount(module1,module2):
      count1=module1.getFullDependeeCount()
      count2=module2.getFullDependeeCount()
      c= count2 - count1                  
      if not c: c=cmp(module1,module2)
      return c       
      
  def compareModulesByFOGFactor(module1,module2):
      fog1=module1.getFOGFactor()
      fog2=module2.getFOGFactor()
      # Allow comparison to 2 decimal places, by *100
      c= int(round((fog2 - fog1)*100,0))                  
      if not c: c=cmp(module1,module2)
      return c             
              
  def compareModulesByLastUpdated(module1,module2):
      lu1=module1.getLastUpdated()
      lu2=module2.getLastUpdated()
      c= int(round(lu2 - lu1,0))                  
      if not c: c=cmp(module1,module2)
      return c             
              
  #
  # Project Comparisons
  #            
      
  def compareProjectsByElapsed(project1,project2):
      elapsed1=project1.getElapsedSecs()
      elapsed2=project2.getElapsedSecs()
      c = 0
      if elapsed1 > elapsed2: c = -1
      if elapsed1 < elapsed2: c = 1       
      if not c: c=cmp(project1,project2)
      return c
  
  def compareProjectsByDependencyCount(project1,project2):
      count1=project1.getDependencyCount()
      count2=project2.getDependencyCount()
      c= count2 - count1                 
      if not c: c=cmp(project1,project2)
      return c        
          
  def compareProjectsByDependeeCount(project1,project2):
      count1=project1.getDependeeCount()
      count2=project2.getDependeeCount()
      c= count2 - count1                  
      if not c: c=cmp(project1,project2)
      return c       
      
  def compareProjectsByFOGFactor(project1,project2):
      fog1=project1.getFOGFactor()
      fog2=project2.getFOGFactor()
      # Allow comparison to 2 decimal places, by *100
      c= int(round((fog2 - fog1)*100,0))                  
      if not c: c=cmp(project1,project2)
      return c             
              
  def compareProjectsByLastUpdated(project1,project2):
      lu1=project1.getLastUpdated()
      lu2=project2.getLastUpdated()
      c= int(round(lu2 - lu1,0))                  
      if not c: c=cmp(project1,project2)
      return c              
              
  def compareProjectsBySequenceInState(project1,project2):
      seq1=project1.getStats().sequenceInState
      seq2=project2.getStats().sequenceInState
      c= int(round(seq2 - seq1,0))                  
      if not c: c=cmp(project1,project2)
      return c                         
              
  
  
  1.137     +1 -1      gump/python/gump/document/forrest.py
  
  Index: forrest.py
  ===================================================================
  RCS file: /home/cvs/gump/python/gump/document/forrest.py,v
  retrieving revision 1.136
  retrieving revision 1.137
  diff -u -r1.136 -r1.137
  --- forrest.py	8 Apr 2004 18:11:43 -0000	1.136
  +++ forrest.py	9 Apr 2004 22:38:25 -0000	1.137
  @@ -1620,7 +1620,7 @@
                   self.insertStateIcon(project,referencingObject,dependencyRow.createData())
                   
                   # FOG Factor
  -                dependencyRow.createData(project.getFOGFactor())
  +                dependencyRow.createData('%02.2f' % project.getFOGFactor())
                   
                   if full:
                       # Contributor
  
  
  
  1.28      +1 -1      gump/python/gump/utils/__init__.py
  
  Index: __init__.py
  ===================================================================
  RCS file: /home/cvs/gump/python/gump/utils/__init__.py,v
  retrieving revision 1.27
  retrieving revision 1.28
  diff -u -r1.27 -r1.28
  --- __init__.py	8 Apr 2004 18:11:43 -0000	1.27
  +++ __init__.py	9 Apr 2004 22:38:25 -0000	1.28
  @@ -146,7 +146,7 @@
       printSeparatorToFile(None,indent)
       
   def printSeparatorToFile(f=None,indent=''):    
  -    if not f: f = sys.stdout
  +    if not f: f=sys.stdout
       f.write( '%s\n' % (indent + ' ----------------------------------------------------
Gump'))
   
   def secsToElapsedTimeTriple(secs):   
  
  
  
  1.26      +9 -0      gump/python/gump/test/pyunit.py
  
  Index: pyunit.py
  ===================================================================
  RCS file: /home/cvs/gump/python/gump/test/pyunit.py,v
  retrieving revision 1.25
  retrieving revision 1.26
  diff -u -r1.25 -r1.26
  --- pyunit.py	2 Apr 2004 16:48:06 -0000	1.25
  +++ pyunit.py	9 Apr 2004 22:38:25 -0000	1.26
  @@ -337,6 +337,15 @@
       from gump.test.thomas import EngineTestSuite  
       runner.addSuite(EngineTestSuite())
       
  +    from gump.test.depdiag import DependencyDiagramTestSuite  
  +    runner.addSuite(DependencyDiagramTestSuite())
  +    
  +    from gump.test.svg import SvgTestSuite  
  +    runner.addSuite(SvgTestSuite())
  +    
  +    from gump.test.drawing import DrawingTestSuite  
  +    runner.addSuite(DrawingTestSuite())
  +    
       # Any args are pattern matches
       patterns=list(sys.argv)
       del patterns[0:1]
  
  
  
  1.1                  gump/python/gump/test/depdiag.py
  
  Index: depdiag.py
  ===================================================================
  #!/usr/bin/env python
  
  # Copyright 2003-2004 The Apache Software Foundation
  #
  # Licensed under the Apache License, Version 2.0 (the "License");
  # you may not use this file except in compliance with the License.
  # You may obtain a copy of the License at
  # 
  #     http://www.apache.org/licenses/LICENSE-2.0
  # 
  # Unless required by applicable law or agreed to in writing, software
  # distributed under the License is distributed on an "AS IS" BASIS,
  # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  # See the License for the specific language governing permissions and
  # limitations under the License.
  
  """
      Drawing Testing
  """
  
  from gump import log
  from gump.svg.drawing import *
  from gump.svg.depdiag import DependencyDiagram
  from gump.test import getWorkedTestWorkspace
  from gump.test.pyunit import UnitTestSuite
  
  class DependencyDiagramTestSuite(UnitTestSuite):
      def __init__(self):
          UnitTestSuite.__init__(self)
          
      def suiteSetUp(self):
          #
          # Load a decent Workspace
          #
          self.workspace=getWorkedTestWorkspace() 
          self.assertNotNone('Needed a workspace', self.workspace)
          self.project5=self.workspace.getProject('project5')
          
      def testDependencyDiagramGeneration(self):
          diagram=DependencyDiagram(self.project5)
          
          diagram.compute()
          
          svg=diagram.generateDiagram()
          
          
  
  
  1.1                  gump/python/gump/test/svg.py
  
  Index: svg.py
  ===================================================================
  #!/usr/bin/env python
  
  # Copyright 2003-2004 The Apache Software Foundation
  #
  # Licensed under the Apache License, Version 2.0 (the "License");
  # you may not use this file except in compliance with the License.
  # You may obtain a copy of the License at
  # 
  #     http://www.apache.org/licenses/LICENSE-2.0
  # 
  # Unless required by applicable law or agreed to in writing, software
  # distributed under the License is distributed on an "AS IS" BASIS,
  # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  # See the License for the specific language governing permissions and
  # limitations under the License.
  
  """
      SVG Testing
  """
  
  from gump import log
  from gump.svg.drawing import *
  from gump.svg.svg import *
  from gump.test.pyunit import UnitTestSuite
  
  class SvgTestSuite(UnitTestSuite):
      def __init__(self):
          UnitTestSuite.__init__(self)
          
      def testSvgConstruction(self):
          svg=SimpleSvg()
          svg.serialize()
  
  
  1.1                  gump/python/gump/test/drawing.py
  
  Index: drawing.py
  ===================================================================
  #!/usr/bin/env python
  
  # Copyright 2003-2004 The Apache Software Foundation
  #
  # Licensed under the Apache License, Version 2.0 (the "License");
  # you may not use this file except in compliance with the License.
  # You may obtain a copy of the License at
  # 
  #     http://www.apache.org/licenses/LICENSE-2.0
  # 
  # Unless required by applicable law or agreed to in writing, software
  # distributed under the License is distributed on an "AS IS" BASIS,
  # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  # See the License for the specific language governing permissions and
  # limitations under the License.
  
  """
      Drawing Testing
  """
  
  from gump import log
  from gump.svg.drawing import *
  from gump.test.pyunit import UnitTestSuite
  
  class DrawingTestSuite(UnitTestSuite):
      def __init__(self):
          UnitTestSuite.__init__(self)
          
      def testDrawingContext(self):
          context=StandardDrawingContext(rect=Rect(0,0,100,100))
                  
      def testScaledDrawingContext(self):
          context=ScaledDrawingContext('TestScale',None,Rect(0,0,100,100),200,200)
          (x,y)=context.realPoint(50,50)
          self.assertEqual('Half the size', 50/2, x)
          self.assertEqual('Half the size', 50/2, y)
                  
      def testShiftedDrawingContext(self):
          context=ShiftedDrawingContext('TestShift',None,200,200)
          (x,y)=context.realPoint(50,50)
          self.assertEqual('Shifted up by 200', 250, x)
          self.assertEqual('Shifted up by 200', 250, y)
          
      def testShiftedScaledDrawingContext(self):
          context=ShiftedDrawingContext('TestShift',	\
                      ScaledDrawingContext('TestScale',None,	\
                          Rect(0,0,100,100),200,200),200,200)
          (x,y)=context.realPoint(50,50)
          self.assertEqual('Shifted & Scaled', 125, x)
          self.assertEqual('Shifted & Scaled', 125, y)
          
      def testGridDrawingContext(self):
          baseContext=StandardDrawingContext(rect=Rect(0,0,100,100))
          context=GridDrawingContext('TestGrid',baseContext,10,10)
          context.dump()
          for row in [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9]:
              for col in [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9]:    
                  (x,y)=context.realPoint(row,col)
                  
                  expectedX=(row+1)*5
                  expectedY=(col+1)*5
                  
                  # :TODO: self.assertEqual('Grid', expectedX, x)
                  # :TODO: self.assertEqual('Grid', expectedY, y)
  
  
  
  1.21      +2 -98     gump/python/gump/output/statsdb.py
  
  Index: statsdb.py
  ===================================================================
  RCS file: /home/cvs/gump/python/gump/output/statsdb.py,v
  retrieving revision 1.20
  retrieving revision 1.21
  diff -u -r1.20 -r1.21
  --- statsdb.py	1 Apr 2004 23:48:10 -0000	1.20
  +++ statsdb.py	9 Apr 2004 22:38:25 -0000	1.21
  @@ -29,6 +29,8 @@
   from gump.model.repository import Repository, RepositoryStatistics
   from gump.model.workspace import Workspace, WorkspaceStatistics
   from gump.model.state import *
  +
  +from gump.shared.comparator import *
     
   class StatisticsDB:
       """Statistics Interface"""
  @@ -336,105 +338,7 @@
           #
           self.averageProjectsPerModule=	\
               float(self.projectsInWorkspace)/self.modulesInWorkspace
  -            
  -#
  -# Module Comparisons
  -#            
  -        
  -def compareModulesByElapsed(module1,module2):
  -    elapsed1=module1.getElapsedSecs()
  -    elapsed2=module2.getElapsedSecs()
  -    c = 0
  -    if elapsed1 > elapsed2: c = -1
  -    if elapsed1 < elapsed2: c = 1       
  -    if not c: c=cmp(module1,module2)
  -    return c
  -
  -def compareModulesByProjectCount(module1,module2):
  -    count1=len(module1.getProjects())
  -    count2=len(module2.getProjects())
  -    c = count2 - count1                  
  -    if not c: c=cmp(module1,module2)
  -    return c
  -
  -def compareModulesByDependencyCount(module1,module2):
  -    count1=module1.getFullDependencyCount()
  -    count2=module2.getFullDependencyCount()
  -    c= count2 - count1                 
  -    if not c: c=cmp(module1,module2)
  -    return c        
  -        
  -def compareModulesByDependeeCount(module1,module2):
  -    count1=module1.getFullDependeeCount()
  -    count2=module2.getFullDependeeCount()
  -    c= count2 - count1                  
  -    if not c: c=cmp(module1,module2)
  -    return c       
  -    
  -def compareModulesByFOGFactor(module1,module2):
  -    fog1=module1.getFOGFactor()
  -    fog2=module2.getFOGFactor()
  -    # Allow comparison to 2 decimal places, by *100
  -    c= int(round((fog2 - fog1)*100,0))                  
  -    if not c: c=cmp(module1,module2)
  -    return c             
  -            
  -def compareModulesByLastUpdated(module1,module2):
  -    lu1=module1.getLastUpdated()
  -    lu2=module2.getLastUpdated()
  -    c= int(round(lu2 - lu1,0))                  
  -    if not c: c=cmp(module1,module2)
  -    return c             
  -            
  -#
  -# Project Comparisons
  -#            
  -    
  -def compareProjectsByElapsed(project1,project2):
  -    elapsed1=project1.getElapsedSecs()
  -    elapsed2=project2.getElapsedSecs()
  -    c = 0
  -    if elapsed1 > elapsed2: c = -1
  -    if elapsed1 < elapsed2: c = 1       
  -    if not c: c=cmp(project1,project2)
  -    return c
   
  -def compareProjectsByDependencyCount(project1,project2):
  -    count1=project1.getDependencyCount()
  -    count2=project2.getDependencyCount()
  -    c= count2 - count1                 
  -    if not c: c=cmp(project1,project2)
  -    return c        
  -        
  -def compareProjectsByDependeeCount(project1,project2):
  -    count1=project1.getDependeeCount()
  -    count2=project2.getDependeeCount()
  -    c= count2 - count1                  
  -    if not c: c=cmp(project1,project2)
  -    return c       
  -    
  -def compareProjectsByFOGFactor(project1,project2):
  -    fog1=project1.getFOGFactor()
  -    fog2=project2.getFOGFactor()
  -    # Allow comparison to 2 decimal places, by *100
  -    c= int(round((fog2 - fog1)*100,0))                  
  -    if not c: c=cmp(project1,project2)
  -    return c             
  -            
  -def compareProjectsByLastUpdated(project1,project2):
  -    lu1=project1.getLastUpdated()
  -    lu2=project2.getLastUpdated()
  -    c= int(round(lu2 - lu1,0))                  
  -    if not c: c=cmp(project1,project2)
  -    return c              
  -            
  -def compareProjectsBySequenceInState(project1,project2):
  -    seq1=project1.getStats().sequenceInState
  -    seq2=project2.getStats().sequenceInState
  -    c= int(round(seq2 - seq1,0))                  
  -    if not c: c=cmp(project1,project2)
  -    return c                         
  -            
   class StatisticsGuru:
       """ Know it all ... """
       
  
  
  
  1.1                  gump/python/gump/svg/__init__.py
  
  Index: __init__.py
  ===================================================================
  #!/usr/bin/env python
  
  #!/usr/bin/env python
  # Copyright 2003-2004 The Apache Software Foundation
  #
  # Licensed under the Apache License, Version 2.0 (the "License");
  # you may not use this file except in compliance with the License.
  # You may obtain a copy of the License at
  # 
  #     http://www.apache.org/licenses/LICENSE-2.0
  # 
  # Unless required by applicable law or agreed to in writing, software
  # distributed under the License is distributed on an "AS IS" BASIS,
  # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  # See the License for the specific language governing permissions and
  # limitations under the License.
  
  # tell Python what modules make up the gump.test package
  __all__ = ["drawing","svg","depdiag"]
  
  
  
  1.1                  gump/python/gump/svg/depdiag.py
  
  Index: depdiag.py
  ===================================================================
  #!/usr/bin/env python
  
  # Copyright 2003-2004 The Apache Software Foundation
  #
  # Licensed under the Apache License, Version 2.0 (the "License");
  # you may not use this file except in compliance with the License.
  # You may obtain a copy of the License at
  # 
  #     http://www.apache.org/licenses/LICENSE-2.0
  # 
  # Unless required by applicable law or agreed to in writing, software
  # distributed under the License is distributed on an "AS IS" BASIS,
  # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  # See the License for the specific language governing permissions and
  # limitations under the License.
  
  
  """
  
      Dependency Diagram
      
  """
  
  import logging
  import sys
  
  from gump import log
  from gump.shared.comparator import compareProjectsByFOGFactor
  from gump.utils import getIndent,createOrderedList
  
  class DependencyNode:
      def __init__(self,project):
          self.project=project
          self.point=None
  
  class DependencyMatrix:
      """
          This matrix
      """
      def __init__(self,project):
          
          self.project=project
          
          # Create a sparse matrix
          self.depths={}
          self.maxNumAtDepth=0
          
          # Create a lookup
          self.nodes={}
      
      def compute(self):
          """
              Build the matrix
          """
          
          # Start with the focus
          self.insertProject(self.project)
          
          # Go onto all dependencies
          for project in self.project.getFullDependencyProjectList():
              self.insertProject(project)
              
          # Now re-order the rows, sorting by FOG
          for rowNo in self.depths.keys():
              row=self.depths[rowNo] 
              newRow=createOrderedList(row,compareProjectsByFOGFactor)
              self.depths[rowNo]=newRow
          
      # Insert into lists 
      def insertProject(self,project):
          depth=project.getDependencyDepth()
          if not self.depths.has_key(depth):
              self.depths[depth]=[]    
          
          # Context
          node=DependencyNode(project)
          
          # Insert into sparce matrix
          depthList=self.depths[depth]          
          depthList.append(node)
          
          # Keep track of 
          numAtDepth=len(depthList)        
          if (numAtDepth > self.maxNumAtDepth):
              self.maxNumAtDepth=numAtDepth        
              
          # Lookups
          self.nodes[project]=node
          
      def getExtent(self):        
          # Max by max
          return (self.maxNumAtDepth, len(self.depths.keys()))
          
      def getNodeForProject(self,project):
          return self.nodes[project]
          
          self.projectsByFOGFactor=createOrderedList(workspace.getProjects(),compareProjectsByFOGFactor)
          
          
      def dump(self, indent=0, output=sys.stdout):
          """ Display the contents of this object """
          
          output.write(getIndent(indent)+'Extent : ' + `self.getExtent()` +  '\n')
          
          # Now re-order the rows, sorting by FOG
          for rowNo in self.depths.keys():
              row=self.depths[rowNo]             
              output.write(getIndent(indent)+'Row [Depth]: ' + `rowNo` +  '\n')
              for value in row:
                  output.write(getIndent(indent+1)+'Row : ' + `value` +  '\n')
  
  class DependencyDiagram:
      """ The interface to a chainable context """
      def __init__(self, project) : 
          self.project=project
          self.matrix=None
          
      def compute(self):
          self.matrix=DependencyMatrix(self.project)
          self.matrix.compute()
          
          
      def generateDiagram(self):
          self.matrix.dump()
          
          
      
          
  
  
  1.1                  gump/python/gump/svg/svg.py
  
  Index: svg.py
  ===================================================================
  #!/usr/bin/env python
  
  # Copyright 2003-2004 The Apache Software Foundation
  #
  # Licensed under the Apache License, Version 2.0 (the "License");
  # you may not use this file except in compliance with the License.
  # You may obtain a copy of the License at
  # 
  #     http://www.apache.org/licenses/LICENSE-2.0
  # 
  # Unless required by applicable law or agreed to in writing, software
  # distributed under the License is distributed on an "AS IS" BASIS,
  # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  # See the License for the specific language governing permissions and
  # limitations under the License.
  
  
  """
      SVG Generation
  """
  
  import sys
  import logging
  
  from gump import log
  
  # Write a document Header
  def writeHeader(stream):
      stream.write("""<?xml version='1.0' encoding='UTF-8'?>
  <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.0//EN" "http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd
">""")
  
  
  # Write a document Footer
  def writeFooter(stream):
      pass
          
  # Write an SVG Header
  def writeSvg(width='8cm',height='12cm',x=80,y=120):
      stream.write("""<svg width="%s" 
      height="%s"
      viewBox="%s %s %s %s"
      xmlns="http://www.w3.org/2000/svg">
      """
          % width,height,0,0,x,y)
      
  # Write a description
  def writeDescription(stream,desc=None):
      if desc:
          writeElement(stream,'desc',desc)
             
  # Write a generic element 
  def writeElement(stream,tag,value):
      stream.write("""\t<%s>%s</%s>\n""" % tag,value,tag)
   
  #            
  def startDefinitions(self):
      writeStart('defs')
      
  def endDefinitions(self):
      writeEnd('defs')
      
  def writeStart(stream,tag,attrs=None):
      stream.write('\t<')
      stream.write(tag)
      if attrs: stream.write(attrs)
      stream.write('>\n')
      
  def writeEnd(stream,tag):
      stream.write('\t</')
      stream.write(tag)
      stream.write('>\n')
  
  class Location:
      def __init__(self,x=0,y=0):
          self.x=x
          self.y=y
          
  class SvgDefaults:
      def __init__(): pass
                  
  class Entity:
      def __init__(self,locn,attrs=None):
          self.location=locn
          self.attrs={}
          if attrs:
              self.attrs=attrs
              
      def getLocation(self):
          return location
          
      def getAttributes(self):
          return attributes
          
  class SimpleSvg:
      def __init__(self,width='8cm',height='12cm',x=80,y=120):
          self.width=width
          self.height=height
          self.x=x
          self.y=y
          
          self.definitions=[]
          self.actions=[]
          
      def addAction(self,type,x,y,context=None):
          pass
          
      def serialize(self,stream=None):
          
          if not stream:
              stream=sys.stdout
              doNotClose=1
          
          try:
              try:
                  writeHeader(stream)
                  writeSvg(stream,self.width,self.height,self.x,self.y)
                  if self.description:
                      writeDesc(stream,self.description)
                  if self.definitions:
                      startDefinitions(stream)
                      
                      for definition in self.definitions:
                          #:TODO: write...
                          pass
                          
                      endDefinitions(stream)
                  writeFooter(stream)
              except:
                  pass
          finally:        
              if not doNotClose: stream.close()
  
  
  1.1                  gump/python/gump/svg/drawing.py
  
  Index: drawing.py
  ===================================================================
  #!/usr/bin/env python
  
  # Copyright 2003-2004 The Apache Software Foundation
  #
  # Licensed under the Apache License, Version 2.0 (the "License");
  # you may not use this file except in compliance with the License.
  # You may obtain a copy of the License at
  # 
  #     http://www.apache.org/licenses/LICENSE-2.0
  # 
  # Unless required by applicable law or agreed to in writing, software
  # distributed under the License is distributed on an "AS IS" BASIS,
  # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  # See the License for the specific language governing permissions and
  # limitations under the License.
  
  
  """
  
      Drawing Shapes
      
  """
  
  import sys
  import logging
  
  from gump import log
  from gump.utils import *
  
  class Rect:
      """ A rectangle """
      def __init__(self,x,y,w,h):
          self.x=x
          self.y=y
          self.w=w
          self.h=h
          
      def getX(self): return self.x
      def getY(self): return self.y
      def getWidth(self): return self.w
      def getHeight(self): return self.h
      
      def inRect(self,x,y):
          if not x < self.w: return 0
          if not y < self.h: return 0
          if not x >= self.x: return 0
          if not y >= self.y: return 0
          return 1
          
      def dump(self, indent=0, output=sys.stdout):
          """ Display the contents of this object """
          output.write(getIndent(indent)+'Rect : ' \
                      + `self.x` + ',' 	\
                      + `self.y` + ' '	\
  	                + `self.w` + ','	\
  	                + `self.h` + '\n')
          
  class DrawingContext:
      """ The interface to a chainable context """
      def __init__(self,name=None,next=None) : 
          self.name=name
          self.next=next
      
      def realRect(self):
          """ Return the extent of this area. """
          
          # Return rectangle
          if hasattr(self,'getRealRect') and callable(self.getRealRect): 
              rect=self.getRealRect()
              if rect: return rect
          
          # We don't have one, so assume next does...
          self.enforceHasNextContext('DrawingContext.realRect')                    
          return self.getNextContext().realRect()
              
      def realPoint(self,x,y):        
      
          # Calculate (or pass though)
          if hasattr(self,'getRealPoint')and callable(self.getRealPoint): 
              (x1,y1)=self.getRealPoint(x,y)
          else:
              (x1,y1)=(x,y)
          
          # Chain (or pass through)...
          if self.hasNextContext():
              (x2,y2)=self.getNextContext().realPoint(x1,y1)
          else:
              (x2,y2)=(x1,y1)
          
          return (x2,y2)
  
      def setNextContext(self,next):
          self.next=next
          
      def hasNextContext(self):
          return self.next
          
      def getNextContext(self):
          return self.next
          
      def getRootContext(self):
          if self.next: return self.next.getRootContext()
          return self
          
      def enforceHasNextContext(self,operation):
          if not self.hasNextContext():
              raise RuntimeError, "Missing 'next' context in " + str(operation)
  
      def dump(self, indent=0, output=sys.stdout):
          """ Display the contents of this object """
          output.write(getIndent(indent)+'Class: ' + self.__class__.__name__ + '\n')
          output.write(getIndent(indent)+'Name : ' + self.name + '\n')
                   
  class StandardDrawingContext(DrawingContext):
      """ A drawing context, is an area width*height """
      def __init__(self,name=None,context=None,rect=None):
          DrawingContext.__init__(self,name,context)
          if rect: self.rect=rect
          
      def getPoint(x,y):
          if not self.rect.inRect(x,y): 
              raise RuntimeError, "Point not in context rectangle."
          return (x,y)
      
      def hasRect(self):    return hasattr(self,'rect') and self.rect
      def getRealRect(self): 
          if self.hasRect(): return self.rect
      
      def getWidth(self): return self.realRect().getWidth()
      def getHeight(self): return self.realRect().getHeight()
                  
      def dump(self, indent=0, output=sys.stdout):
          """ Display the contents of this object """
          DrawingContext.dump(self)
          if self.hasRect(): self.rect.dump(indent,output)
          output.write(getIndent(indent)+'Width : ' + `self.getWidth()` + '\n')
          output.write(getIndent(indent)+'Height : ' + `self.getHeight()` + '\n')
                   
  class ScaledDrawingContext(StandardDrawingContext):
      def __init__(self,name=None,context=None,rect=None,scaledWidth=1,scaledHeight=1):
          StandardDrawingContext.__init__(self,name,context,rect)
          
          self.scaledWidth=scaledWidth
          self.scaledHeight=scaledHeight
          
          self.wRatio=float(self.getWidth())/self.scaledWidth
          self.hRatio=float(self.getHeight())/self.scaledHeight
      
      def getRealPoint(self,x,y):
          return (x * self.wRatio, y * self.hRatio)
          
      #:TODO: Not working
      def getWidthUnit(self): return self.wRatio
      def getHeightUnit(self): return self.hRatio
                  
      def dump(self, indent=0, output=sys.stdout):
          """ Display the contents of this object """
          StandardDrawingContext.dump(self)
          output.write(getIndent(indent)+'wScaled : ' + `self.scaledWidth` + '\n')
          output.write(getIndent(indent)+'hScaled : ' + `self.scaledHeight` + '\n')
          output.write(getIndent(indent)+'wRatio : ' + `self.wRatio` + '\n')
          output.write(getIndent(indent)+'hRatio : ' + `self.hRatio` + '\n')
          
  class ShiftedDrawingContext(StandardDrawingContext):
      def __init__(self,name=None,context=None,shiftedX=0,shiftedY=0):
          StandardDrawingContext.__init__(self,name,context)    
          
          if not (shiftedX or shiftedY):
              raise RuntimeError, 'A ShiftedDrawingContext with no shift'
              
          self.shiftedX=shiftedX
          self.shiftedY=shiftedY
      
      def getRealPoint(self,x,y):
          return (x + self.shiftedX, y + self.shiftedY)
          
  class GridDrawingContext(DrawingContext):
      """ 
          
          An x/y (10/10) grid over a context (e.g. a standard 100/100)
          is a standard scaling (e.g. 1 -> 10), but followed by a 1/2
          unit shift. This is so that point fit halfway through the
          middle of their blocks. E.g. 0,0 -> 5,5 (with units of 10 points)
          
      """
      def __init__(self,name=None,context=None,rows=10,cols=10):
          
          # Initiaze w/o sub-context
          DrawingContext.__init__(self,name)    
          
          # Create the scale
          self.scale=ScaledDrawingContext('GridScale:'+name,context,None,rows,cols)      
 
          self.scale.dump()
          
          # Calculatethe 1/2 unit shift
          self.widthUnit=self.scale.getWidthUnit()
          self.heightUnit=self.scale.getHeightUnit()
          
          # Create the shift
          self.shift=ShiftedDrawingContext('GridShift:'+name,	\
                              self.scale,	\
                              self.widthUnit/2,	\
                              self.heightUnit/2)
          self.shift.dump()
                  
          # Instal lthis context...
          self.setNextContext(self.shift)
                          
  class VirtualPoint:
      def __init__(self,x,y,context):
          self.x=x
          self.y=y
          self.context=context
          
      #:TODO: Check in root context = drawing root context? [in right tree]
      #:TODO: Check in root context? [in scope]
  
  
  1.1                  gump/python/gump/svg/.cvsignore
  
  Index: .cvsignore
  ===================================================================
  *.pyc
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: general-unsubscribe@gump.apache.org
For additional commands, e-mail: general-help@gump.apache.org


Mime
View raw message