Esempio n. 1
0
def generate_arrowtype_images():

    for at in AttrsDef.E_ARROWTYPE:
        
        DEUtils.gen_arrow_image(at, 'resource/edge_arrowtype/%s.png'%at)
                
    return
Esempio n. 2
0
def generate_arrowtype_images():

    for at in AttrsDef.E_ARROWTYPE:

        DEUtils.gen_arrow_image(at, 'resource/edge_arrowtype/%s.png' % at)

    return
Esempio n. 3
0
def generateFortranModules(cmd, srcPath, OutputDir):
    # Fortran 90 code often fails to compile because it needs modules defined by
    # other files in the same directory.  If this seems to be happening then try
    # to generate all of the required modules by compiling every Fortran file in
    # the same directory.
    srcDir, srcBase = os.path.split(srcPath)
    cmd = cmd + ['-I', srcDir, '-fsyntax-only']

    # If the file compiles OK or isn't failing because of lacking modules then
    # there is no point in trying to generate modules.
    out, err, exitCode = DEUtils.executeCommand(cmd + [srcPath], OutputDir)
    if exitCode == 0 or err is None or "Can't open module file" not in err:
        return

    # Drat, it fails to compile.  Generate modules for every Fortran file in the
    # source directory.
    fortranSuffixes = DEUtils.getSuffixesForLanguage('fortran')
    filesToCompile = []
    for filename in os.listdir(srcDir):
        filepath = os.path.join(srcDir, filename)
        if not os.path.isdir(filepath):
            base, ext = os.path.splitext(filename)
            if ext in fortranSuffixes:
                filesToCompile.append(filepath)

    # Compile every file, returning triumphantly once the original file manages
    # to compile, or giving up miserably if no progress is being made.
    newFilesToCompile = []
    while filesToCompile != newFilesToCompile:
        newFilesToCompile = []
        # Compile each file in turn.
        for path in filesToCompile:
            out, err, exitCode = DEUtils.executeCommand(
                cmd + [path], OutputDir)
            if exitCode != 0 and err is not None and "Can't open module file" in err:
                # It failed to compile due to a missing module.  Remember it for
                # the next round.
                newFilesToCompile.append(path)
            elif path == srcPath:
                # The original file compiled, or at least didn't fail to compile
                # due to a lacking module.  Return triumphantly!
                return
        # Arrange for the next iteration to compile the files that were missing
        # modules this time round.
        filesToCompile, newFilesToCompile = newFilesToCompile, filesToCompile

    # The set of files missing modules didn't change, give up miserably.
    return
Esempio n. 4
0
def generateFortranModules(cmd, srcPath, OutputDir):
    # Fortran 90 code often fails to compile because it needs modules defined by
    # other files in the same directory.  If this seems to be happening then try
    # to generate all of the required modules by compiling every Fortran file in
    # the same directory.
    srcDir,srcBase = os.path.split(srcPath)
    cmd = cmd + ['-I', srcDir, '-fsyntax-only']

    # If the file compiles OK or isn't failing because of lacking modules then
    # there is no point in trying to generate modules.
    out,err,exitCode = DEUtils.executeCommand(cmd + [srcPath], OutputDir)
    if exitCode == 0 or err is None or "Can't open module file" not in err:
        return

    # Drat, it fails to compile.  Generate modules for every Fortran file in the
    # source directory.
    fortranSuffixes = DEUtils.getSuffixesForLanguage('fortran')
    filesToCompile = []
    for filename in os.listdir(srcDir):
        filepath = os.path.join(srcDir, filename)
        if not os.path.isdir(filepath):
            base,ext = os.path.splitext(filename)
            if ext in fortranSuffixes:
                filesToCompile.append(filepath)

    # Compile every file, returning triumphantly once the original file manages
    # to compile, or giving up miserably if no progress is being made.
    newFilesToCompile = []
    while filesToCompile != newFilesToCompile:
        newFilesToCompile = []
        # Compile each file in turn.
        for path in filesToCompile:
            out,err,exitCode = DEUtils.executeCommand(cmd + [path], OutputDir)
            if exitCode != 0 and err is not None and "Can't open module file" in err:
                # It failed to compile due to a missing module.  Remember it for
                # the next round.
                newFilesToCompile.append(path);
            elif path == srcPath:
                # The original file compiled, or at least didn't fail to compile
                # due to a lacking module.  Return triumphantly!
                return
        # Arrange for the next iteration to compile the files that were missing
        # modules this time round.
        filesToCompile, newFilesToCompile = newFilesToCompile, filesToCompile

    # The set of files missing modules didn't change, give up miserably.
    return
Esempio n. 5
0
 def refresh_preview(self):
     
     # Gen image.
     at = self.getArrowType()
     fn = tempfile.gettempdir()+'/.atpreview'
     DEUtils.gen_arrow_image(at, fn)
     img = wx.Image(fn)
     
     # Cut the center part for preview. 
     w,h=img.GetSize()
     img = img.GetSubImage(wx.Rect((w-h)/2, 0, h, h))
     
     self.m_bitmap_preview.SetSize((h,h))
     self.m_bitmap_preview.SetBitmap(img.ConvertToBitmap())
     self.m_bitmap_preview.UpdateWindowUI()
     
     return
Esempio n. 6
0
 def ValidateValue(self, value, validationInfo):
     """ Let's limit the value NOT inclue double-quote.
     """
     
     if type(DEUtils.escape_dot_string(value)) == str:
         return True
     else:
         return False
Esempio n. 7
0
 def refresh_preview(self):
     
     # Gen image.
     at = self.getArrowType()
     fn = tempfile.gettempdir()+'/atpreview.png'
     DEUtils.gen_arrow_image(at, fn)
     img = wx.Image(fn)
     
     # Cut the center part for preview. 
     w,h=img.GetSize()
     # img = img.GetSubImage(wx.Rect((w-h)/2, 0, w, h))
     
     self.m_bitmap_preview.SetSize((w,h))
     self.m_bitmap_preview.SetBitmap(img.ConvertToBitmap())
     self.m_bitmap_preview.UpdateWindowUI()
     
     return
Esempio n. 8
0
def executeCompilatorTest(test, litConfig, compilers, flags, language_flags,
                          skip, xfails):
    test_path = '/'.join(test.path_in_suite)

    # Skip this test if requested to do so.
    if test_path in skip:
        return (Test.UNSUPPORTED, None)

    # Create the output directory if it does not already exist.
    execPath = test.getExecPath()
    execDir,execBase = os.path.split(execPath)
    tmpDir = os.path.join(execDir, 'Output')
    tmpDir = os.path.join(tmpDir, execBase)
    Util.mkdir_p(tmpDir)

    # Is this test expected to fail?
    isXFail = test_path in xfails

    # The file should be compiled to assembler.
    srcPath = test.getSourcePath();
    common_args = ['-S', srcPath]

    # Look for headers and such-like in the directory containing the source.
    srcDir,srcBase = os.path.split(srcPath)
    common_args += ['-I', srcDir]

    # Add any file specific flags.
    srcBase,srcExt = os.path.splitext(srcPath)
    language = DEUtils.getLanguageForSuffix(srcExt)
    if language in language_flags:
      common_args += language_flags[language]

    # Fortran files may not compile because they need modules provided by other
    # Fortran files.  Workaround this by generating missing modules if possible.
    if language == 'fortran':
      generateFortranModules(compilers[0], srcPath, tmpDir)

    # Compile the test.
    for args in flags:
        result,output = compareCommands(compilers, common_args + args, tmpDir)
        if result != Test.PASS:
            return (Test.XFAIL if isXFail else result,output)
    return (Test.XPASS if isXFail else Test.PASS, None)
Esempio n. 9
0
def executeCompilatorTest(test, litConfig, compilers, flags, language_flags,
                          skip, xfails):
    test_path = '/'.join(test.path_in_suite)

    # Skip this test if requested to do so.
    if test_path in skip:
        return (Test.UNSUPPORTED, None)

    # Create the output directory if it does not already exist.
    execPath = test.getExecPath()
    execDir, execBase = os.path.split(execPath)
    tmpDir = os.path.join(execDir, 'Output')
    tmpDir = os.path.join(tmpDir, execBase)
    lit.util.mkdir_p(tmpDir)

    # Is this test expected to fail?
    isXFail = test_path in xfails

    # The file should be compiled to assembler.
    srcPath = test.getSourcePath()
    common_args = ['-S', srcPath]

    # Look for headers and such-like in the directory containing the source.
    srcDir, srcBase = os.path.split(srcPath)
    common_args += ['-I', srcDir]

    # Add any file specific flags.
    srcBase, srcExt = os.path.splitext(srcPath)
    language = DEUtils.getLanguageForSuffix(srcExt)
    if language in language_flags:
        common_args += language_flags[language]

    # Fortran files may not compile because they need modules provided by other
    # Fortran files.  Workaround this by generating missing modules if possible.
    if language == 'fortran':
        generateFortranModules(compilers[0], srcPath, tmpDir)

    # Compile the test.
    for args in flags:
        result, output = compareCommands(compilers, common_args + args, tmpDir)
        if result != Test.PASS:
            return (Test.XFAIL if isXFail else result, output)
    return (Test.XPASS if isXFail else Test.PASS, None)
Esempio n. 10
0
 def ValidateValue(self, value, validationInfo):
     """ Let's limit the value NOT inclue double-quote.
     """
     return True, DEUtils.escape_dot_string(value)
Esempio n. 11
0
def generate_platte():
    max_w, max_h = 90, 120

    all_files = []

    for scheme in AttrsDef.E_COLORSCHEME:
        fn = 'resource/palette/%s.png' % scheme
        all_files.append(fn)
        color_dict = DEUtils.get_colors_in_schcme(scheme)
        c_num = len(color_dict)
        if c_num > 20:  ### Too many color, use small rectangle to arrange.
            # Calc color rect.
            x = int(math.sqrt(c_num))
            h = x - x % 10
            w = c_num / h
            r = c_num % h
            if r > 0:
                w += 1
            blank_num = w * h - c_num
            # Arrange color.
            colors = color_dict.keys()
            colors.sort()
            pixels = []
            for c in colors:
                r, g, b = color_dict[c]
                pixels.append([b, g, r])

            [pixels.append([255, 255, 255]) for b in range(blank_num)]
            pixels = numpy.array(pixels)
            pixels = pixels.reshape(h, w, 3)
        else:
            colors = color_dict.keys()
            colors.sort()
            pixels = []
            for c in colors:
                r, g, b = color_dict[c]
                pixels.append([b, g, r])

            pixels = numpy.array(pixels)
            pixels = pixels.reshape(1, c_num, 3)

        ### Now enlarge the pixels.
        w, h, _ = pixels.shape

        bx = max_w / w
        by = max_h / h
        bz = min(bx, by)

        if w == 1:
            h_k = max_w / bz
        else:
            h_k = 1

        large_p = []
        for x in range(w):
            for _ in range(bz * h_k):  ### Repeat bz times in line.
                for y in range(h):
                    ### Repeat bz times in pixel.
                    [large_p.append(pixels[x, y]) for _ in range(bz)]
        large_p = numpy.array(large_p)
        large_p = large_p.reshape(w * bz * h_k, h * bz, 3)

        cv2.imwrite(fn, large_p)

    ### Normalize all image.
    image_list = [(fn, wx.Image(fn)) for fn in all_files]

    max_w, max_h = (0, 0)
    for img in image_list:
        w, h = img[1].GetSize()
        if w > max_w: max_w = w
        if h > max_h: max_h = h

    for img in image_list:
        w, h = img[1].GetSize()
        if w == max_w and h == max_h:
            img[1].SaveFile(img[0], wx.BITMAP_TYPE_PNG)
        else:
            pos_x = int((max_w - w) / 2)
            pos_y = int((max_h - h) / 2)

            new_img = wx.Image(max_w, max_h)
            new_img.Clear(0xff)
            new_img.Paste(img[1], pos_x, pos_y)
            new_img.SaveFile(img[0], wx.BITMAP_TYPE_PNG)

    return
Esempio n. 12
0
def generate_platte():
    max_w, max_h = 90, 120
    
    all_files = []
    
    for scheme in AttrsDef.E_COLORSCHEME:
        fn = 'resource/palette/%s.png'%scheme
        all_files.append(fn)
        color_dict = DEUtils.get_colors_in_schcme(scheme)
        c_num = len(color_dict) 
        if c_num > 20: ### Too many color, use small rectangle to arrange.
            # Calc color rect.
            x = int(math.sqrt(c_num))
            h = x - x%10
            w = c_num / h
            r = c_num % h
            if r > 0:
                w += 1
            blank_num = w*h - c_num
            # Arrange color.
            colors = color_dict.keys()
            colors.sort()
            pixels = []
            for c in colors:
                r,g,b = color_dict[c]
                pixels.append([b,g,r])
                
            [ pixels.append([255,255,255]) for b in range(blank_num) ]
            pixels = numpy.array(pixels)
            pixels = pixels.reshape(h,w,3)
        else:
            colors = color_dict.keys()
            colors.sort()
            pixels = []
            for c in colors:
                r,g,b = color_dict[c]
                pixels.append([b,g,r])
            
            pixels = numpy.array(pixels)
            pixels = pixels.reshape(1,c_num,3)
            
        ### Now enlarge the pixels.
        w, h, _ = pixels.shape
        
        bx = max_w/w ; by = max_h/h
        bz = min(bx, by)

        if w == 1:
            h_k = max_w / bz
        else:
            h_k = 1
        
        large_p = []
        for x in range(w):
            for _ in range(bz*h_k): ### Repeat bz times in line.
                for y in range(h):
                    ### Repeat bz times in pixel.
                    [ large_p.append(pixels[x,y]) for _ in range(bz) ] 
        large_p = numpy.array(large_p)
        large_p = large_p.reshape(w*bz*h_k, h*bz, 3)
         
        cv2.imwrite(fn, large_p)
    
    ### Normalize all image. 
    image_list = [ (fn, wx.Image(fn)) for fn in all_files ]
    
    max_w, max_h = (0,0)
    for img in image_list:
        w,h = img[1].GetSize()
        if w > max_w: max_w = w
        if h > max_h: max_h = h
    
    for img in image_list:
        w,h = img[1].GetSize()
        if w==max_w and h==max_h:
            img[1].SaveFile(img[0], wx.BITMAP_TYPE_PNG)
        else:
            pos_x = int((max_w-w)/2)
            pos_y = int((max_h-h)/2)
    
            new_img = wx.EmptyImage(max_w, max_h)
            new_img.Clear(0xff)
            new_img.Paste(img[1], pos_x, pos_y)
            new_img.SaveFile(img[0], wx.BITMAP_TYPE_PNG)

    return
Esempio n. 13
0
    def EG_to_string(self, indent=0, root_graph=None):
        """Returns a string representation of the graph in dot language.
        This version try to make string looking better than to_string().
        """
        idt = ' ' * (4 + indent)
        graph = list()

        if root_graph is None:
            root_graph = self

        if root_graph != root_graph.get_parent_graph():
            graph.append(' ' * indent)

        if root_graph.obj_dict.get('strict', None) is not None:
            if root_graph == root_graph.get_parent_graph(
            ) and root_graph.obj_dict['strict']:
                graph.append('strict ')

        if root_graph.obj_dict['name'] == '':
            graph.append('{\n')
        else:
            graph.append(
                '%s %s {\n' %
                (root_graph.obj_dict['type'], root_graph.obj_dict['name']))

        for attr in root_graph.obj_dict['attributes'].keys():
            if root_graph.obj_dict['attributes'].get(attr, None) is not None:
                graph.append(idt + '%s=' % attr)
                val = root_graph.obj_dict['attributes'].get(attr)
                graph.append(pydot.quote_if_necessary(val))
                graph.append(';\n')

        edges_done = set()

        edge_obj_dicts = list()
        for e in root_graph.obj_dict['edges'].values():
            edge_obj_dicts.extend(e)

        if edge_obj_dicts:
            edge_src_set, edge_dst_set = zip(
                *[obj['points'] for obj in edge_obj_dicts])
            edge_src_set, edge_dst_set = set(edge_src_set), set(edge_dst_set)
        else:
            edge_src_set, edge_dst_set = set(), set()

        node_obj_dicts = list()
        for e in root_graph.obj_dict['nodes'].values():
            node_obj_dicts.extend(e)

        sgraph_obj_dicts = list()
        for sg in root_graph.obj_dict['subgraphs'].values():
            sgraph_obj_dicts.extend(sg)

        obj_list = [
            (obj['sequence'], obj)
            for obj in (edge_obj_dicts + node_obj_dicts + sgraph_obj_dicts)
        ]
        obj_list.sort()

        for _, obj in obj_list:
            if obj['type'] == 'node':
                node = pydot.Node(obj_dict=obj)
                if root_graph.obj_dict.get('suppress_disconnected', False):
                    if (node.get_name() not in edge_src_set
                            and node.get_name() not in edge_dst_set):
                        continue

                graph.append(
                    DEUtils.smart_indent(node.to_string(), idt) + '\n')

            elif obj['type'] == 'edge':
                edge = pydot.Edge(obj_dict=obj)
                if root_graph.obj_dict.get('simplify',
                                           False) and edge in edges_done:
                    continue

                graph.append(
                    DEUtils.smart_indent(edge.to_string(), idt) + '\n')

                edges_done.add(edge)

            else:
                sgraph = pydot.Subgraph(obj_dict=obj)
                sg_str = self.EG_to_string(indent + 4, sgraph)
                graph.append(sg_str + '\n')

        if root_graph != root_graph.get_parent_graph():
            graph.append(' ' * indent)

        graph.append('}\n')

        return ''.join(graph)
Esempio n. 14
0
This module define the extended functions of graph data. 

The core class base on the PyDot project. (https://github.com/erocarrera/pydot)
'''

import pydot
import wx, sys
import ExtParser
from DEUtils import to_unicode, add_double_quote,\
    remove_double_quote
import tempfile
import DEUtils

TEMP_IMG_FILE = tempfile.gettempdir() + '/de_tempimg'

TEMPLATE_DOT = DEUtils.resource_path('GraphTemplate.dot')
INIT_SCRIPT = '''
digraph G {
    rankdir=LR;
    node [fontname="serif"];
    edge [fontname="serif"];
}
'''

INIT_SCRIPT_SUBGRAPH = '''
graph G {
    node [comment="subgraph node wildcard"];
    edge [comment="subgraph edge wildcard"];
}
'''
Esempio n. 15
0
    def EG_to_string(self, indent=0, root_graph=None):
        """Returns a string representation of the graph in dot language.
        This version try to make string looking better than to_string().
        """
        idt = " " * (4 + indent)
        graph = list()

        if root_graph is None:
            root_graph = self

        if root_graph != root_graph.get_parent_graph():
            graph.append(" " * indent)

        if root_graph.obj_dict.get("strict", None) is not None:
            if root_graph == root_graph.get_parent_graph() and root_graph.obj_dict["strict"]:
                graph.append("strict ")

        if root_graph.obj_dict["name"] == "":
            graph.append("{\n")
        else:
            graph.append("%s %s {\n" % (root_graph.obj_dict["type"], root_graph.obj_dict["name"]))

        for attr in root_graph.obj_dict["attributes"].keys():
            if root_graph.obj_dict["attributes"].get(attr, None) is not None:
                graph.append(idt + "%s=" % attr)
                val = root_graph.obj_dict["attributes"].get(attr)
                graph.append(pydot.quote_if_necessary(val))
                graph.append(";\n")

        edges_done = set()

        edge_obj_dicts = list()
        for e in root_graph.obj_dict["edges"].values():
            edge_obj_dicts.extend(e)

        if edge_obj_dicts:
            edge_src_set, edge_dst_set = zip(*[obj["points"] for obj in edge_obj_dicts])
            edge_src_set, edge_dst_set = set(edge_src_set), set(edge_dst_set)
        else:
            edge_src_set, edge_dst_set = set(), set()

        node_obj_dicts = list()
        for e in root_graph.obj_dict["nodes"].values():
            node_obj_dicts.extend(e)

        sgraph_obj_dicts = list()
        for sg in root_graph.obj_dict["subgraphs"].values():
            sgraph_obj_dicts.extend(sg)

        obj_list = [(obj["sequence"], obj) for obj in (edge_obj_dicts + node_obj_dicts + sgraph_obj_dicts)]
        obj_list.sort()

        for _, obj in obj_list:
            if obj["type"] == "node":
                node = pydot.Node(obj_dict=obj)
                if root_graph.obj_dict.get("suppress_disconnected", False):
                    if node.get_name() not in edge_src_set and node.get_name() not in edge_dst_set:
                        continue

                graph.append(DEUtils.smart_indent(node.to_string(), idt) + "\n")

            elif obj["type"] == "edge":
                edge = pydot.Edge(obj_dict=obj)
                if root_graph.obj_dict.get("simplify", False) and edge in edges_done:
                    continue

                graph.append(DEUtils.smart_indent(edge.to_string(), idt) + "\n")

                edges_done.add(edge)

            else:
                sgraph = pydot.Subgraph(obj_dict=obj)
                sg_str = self.EG_to_string(indent + 4, sgraph)
                graph.append(sg_str + "\n")

        if root_graph != root_graph.get_parent_graph():
            graph.append(" " * indent)

        graph.append("}\n")

        return "".join(graph)
Esempio n. 16
0
 def executeOne(cmd):
     return DEUtils.executeCommand(cmd + args, cwd)
Esempio n. 17
0
 def executeOne(cmd):
     return DEUtils.executeCommand(cmd + args, cwd)
Esempio n. 18
0
This module define the extended functions of graph data. 

The core class base on the PyDot project. (https://github.com/erocarrera/pydot)
"""

import pydot
import wx, sys
import ExtParser
from DEUtils import to_unicode, add_double_quote, remove_double_quote
import tempfile
import DEUtils


TEMP_IMG_FILE = tempfile.gettempdir() + "/de_tempimg"

TEMPLATE_DOT = DEUtils.resource_path("GraphTemplate.dot")
INIT_SCRIPT = """
digraph G {
    rankdir=LR;
    node [fontname="serif"];
    edge [fontname="serif"];
}
"""

INIT_SCRIPT_SUBGRAPH = """
graph G {
    node [comment="subgraph node wildcard"];
    edge [comment="subgraph edge wildcard"];
}
"""
Esempio n. 19
0
 def ValidateValue(self, value, validationInfo):
     """ Let's limit the value NOT inclue double-quote.
     """
     return True, DEUtils.escape_dot_string(value)