00001 __copyright__ = """
00002 Copyright 2008 Sean Ross-Ross
00003 """
00004 __license__ = """
00005 This file is part of SLIMpy .
00006
00007 SLIMpy is free software: you can redistribute it and/or modify
00008 it under the terms of the GNU Lesser General Public License as published by
00009 the Free Software Foundation, either version 3 of the License, or
00010 (at your option) any later version.
00011
00012 SLIMpy is distributed in the hope that it will be useful,
00013 but WITHOUT ANY WARRANTY; without even the implied warranty of
00014 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00015 GNU Lesser General Public License for more details.
00016
00017 You should have received a copy of the GNU Lesser General Public License
00018 along with SLIMpy . If not, see <http://www.gnu.org/licenses/>.
00019 """
00020
00021 """
00022 Deprecated
00023 """
00024
00025
00026 from slimpy_base.Core.Graph.Builders.SLIMBuilder import SLIMBuilder
00027
00028
00029 class DotBuilder( SLIMBuilder ):
00030 node = 0
00031
00032 def __init__( self, graph, name='SLIMpy', abr=True ):
00033 self.counterC = 0
00034 self.counterD = 0
00035
00036 self.abr = abr
00037 self.dot = self.toDot( graph, name=name, abr=abr )
00038
00039 def printDot( self ):
00040 return self.dot
00041
00042 def toDot( self, graph, name='SLIMpy', abr=True ):
00043 start = 'digraph %s {\n' %name
00044 end = '\n}'
00045 datastr = 'node [shape = "ellipse"];\n\n'
00046 commstr = 'node [shape = "box"];\n\n'
00047 middle = "\n\n"
00048
00049
00050 dataDict = {}
00051 commandDict = {}
00052
00053 for u in graph:
00054 for v in graph.adj( u ):
00055
00056 nodestru = self.nodeToString( u, dataDict, commandDict )
00057 nodestrv = self.nodeToString( v, dataDict, commandDict )
00058 middle += '''%(nodestru)s -> %(nodestrv)s; \n''' %vars()
00059
00060 datastr += "\n".join( ['%(val)s [ label = "%(key)s" ]' %vars() for key, val in dataDict.items()] ) +"\n\n\n"
00061 commstr += "\n".join( ['%(val)s [ label = "%(key)s" ]' %vars() for key, val in commandDict.items()] ) + '\n\n\n'
00062
00063
00064 return self.abbrige( start + datastr + commstr + middle + end, abr )
00065
00066 def abbrige( self, s, abr ):
00067 if abr:
00068 for item in self.slimvars['abridgeMap'].items():
00069 s = s.replace( *item )
00070
00071 return s
00072
00073 def nodeToString( self, node, dataDict, commandDict ):
00074 """
00075 function to work with data in the hashtable
00076 """
00077 if isinstance( node, tuple ):
00078
00079 nodes = [self.table[n] for n in node ]
00080
00081 s = str( nodes ).replace( '"', "'" )
00082
00083 val = "d%d" %self.counterC
00084 if commandDict.has_key( s ):
00085 return commandDict[s]
00086 else:
00087 self.counterC+=1
00088 commandDict[s] = val
00089
00090 return val
00091
00092
00093 else:
00094 nodes = self.table[node]
00095
00096 s = str( nodes ).replace( '"', "'" )
00097
00098 val = "c%d" %self.counterD
00099
00100 if dataDict.has_key( s ):
00101 return dataDict[s]
00102 else:
00103 self.counterD+=1
00104 dataDict[s] = val
00105 return val
00106