Esempio n. 1
0
    def __get_code_generator(self, diagram):

        if diagram.language is None:
            message = "You shall not generate the code of an empty diagram!"
            Dialog().message_dialog("Error", message, self.main_window)
            return None

        if diagram.code_template is not None:
            return CodeGenerator(diagram)

        template_list = []
        code_templates = System.get_code_templates()

        for key in code_templates:
            if code_templates[key].language == diagram.language:
                template_list.append(code_templates[key])

        if len(template_list) == 0:
            message = "Generator not available for the language " + diagram.language + "."
            Dialog().message_dialog("Error", message, self.main_window)
            return None

        if len(template_list) == 1:
            diagram.code_template = deepcopy(template_list[0])
            return CodeGenerator(diagram)

        select = SelectCodeTemplate(self.main_window, template_list)
        diagram.code_template = deepcopy(select.get_value())
        return CodeGenerator(diagram)
    def test_generate_code(self):
        diagram = self.create_diagram()
        self.code_generator = CodeGenerator(diagram)
        self.code_generator.generate_code()

        diagram.code_template = None
        self.code_generator.generate_code()

        diagram = self.create_full_diagram()
        self.code_generator = CodeGenerator(diagram)
        self.code_generator.generate_code()
    def test_constructor(self):
        self.code_generator = CodeGenerator(None)
        diagram = self.create_diagram()
        self.code_generator = CodeGenerator(diagram)

        diagram = self.create_diagram()
        diagram.code_template = None
        self.code_generator = CodeGenerator(diagram)

        diagram = self.create_diagram()
        diagram.language = None
        self.code_generator = CodeGenerator(diagram)
Esempio n. 4
0
 def get_code_template(self):
     code_template = CodeTemplate()
     for key in System.code_templates:
         if System.code_templates[key].language == self.diagram.language:
             code_template = System.code_templates[key]
             break
     generator = CodeGenerator(self.diagram, code_template)
     return generator
 def setUp(self):
     self.code_generator = CodeGenerator(self.create_diagram())
Esempio n. 6
0
    def setUp(self):
        """Do the test basic setup."""
        self.blockmodel = BlockModel()

        self.blockmodel.id = 1
        self.blockmodel.x = 2
        self.blockmodel.y = 2

        self.blockmodel.language = "c"
        self.blockmodel.framework = "opencv"
        self.blockmodel.help = "Adiciona bordas na imagem."
        self.blockmodel.label = "Add Border"
        self.blockmodel.color = "0:180:210:150"
        self.blockmodel.in_ports = [{
            "type": "mosaicode_c_opencv.extensions.ports.image",
            "name": "input_image",
            "label": "Input Image"
        }, {
            "type": "mosaicode_c_opencv.extensions.ports.int",
            "name": "border_size",
            "label": "Border Size"
        }]
        self.blockmodel.out_ports = [{
            "type": "mosaicode_c_opencv.extensions.ports.image",
            "name": "output_image",
            "label": "Output Image"
        }]
        self.blockmodel.group = "Experimental"
        self.blockmodel.properties = [{
            "label": "Color",
            "name": "color",
            "type": MOSAICODE_COLOR,
            "value": "#FF0000"
        }, {
            "name":
            "type",
            "label":
            "Type",
            "type":
            MOSAICODE_COMBO,
            "value":
            "IPL_BORDER_CONSTANT",
            "values": [
                "IPL_BORDER_CONSTANT", "IPL_BORDER_REPLICATE",
                "IPL_BORDER_REFLECT", "IPL_BORDER_WRAP"
            ]
        }, {
            "label": "Border Size",
            "name": "border_size",
            "type": MOSAICODE_INT,
            "value": "50"
        }]
        self.blockmodel.codes[0] = \
            "CvScalar get_scalar_color(const char * rgbColor){\n" + \
            "   if (strlen(rgbColor) < 13 || rgbColor[0] != '#')\n" + \
            "       return cvScalar(0,0,0,0);\n" + \
            "   char r[4], g[4], b[4];\n" + \
            "   strncpy(r, rgbColor+1, 4);\n" + \
            "   strncpy(g, rgbColor+5, 4);\n" + \
            "   strncpy(b, rgbColor+9, 4);\n" + \
            "\n" + \
            "   int ri, gi, bi = 0;\n" + \
            "   ri = (int)strtol(r, NULL, 16);\n" + \
            "   gi = (int)strtol(g, NULL, 16);\n" + \
            "   bi = (int)strtol(b, NULL, 16);\n" + \
            "\n" + \
            "   ri /= 257;\n" + \
            "   gi /= 257;\n" + \
            "   bi /= 257;\n" + \
            "   \n" + \
            "   return cvScalar(bi, gi, ri, 0);\n" + \
            "}\n"
        self.blockmodel.codes[1] = \
            "IplImage * block$id$_img_i0 = NULL;\n" + \
            "int block$id$_int_i1 = $prop[border_size]$;\n" + \
            "IplImage * block$id$_img_o0 = NULL;\n"
        self.blockmodel.codes[2] = \
            'if(block$id$_img_i0){\n' + \
            '\tCvSize size$id$ = cvSize(block$id$_img_i0->width +' + \
            ' block$id$_int_i1 * 2, block$id$_img_i0->height' + \
            ' + block$id$_int_i1 * 2);\n' + \
            '\tblock$id$_img_o0 = cvCreateImage(size$id$,' + \
            ' block$id$_img_i0->depth,block$id$_img_i0->nChannels);\n' + \
            '\tCvPoint point$id$ = cvPoint' + \
            '(block$id$_int_i1, block$id$_int_i1);\n' + \
            '\tCvScalar color = get_scalar_color("$prop[color]$");\n' + \
            '\tcvCopyMakeBorder(block$id$_img_i0, block$id$_img_o0,' + \
            ' point$id$, $prop[type]$, color);\n' + \
            '}\n'

        win = MainWindow()
        self.diagram = Diagram(win)
        self.codetemplate = CodeTemplate()
        #block = Block(diagram, blockmodel)
        #diagram.language = None
        self.code_generator = CodeGenerator(None, None)
        self.diagram.language = None
        self.code_generator = CodeGenerator(self.diagram, None)
        self.diagram.language = ""
        self.code_generator = CodeGenerator(self.diagram, None)
        self.code_generator = CodeGenerator(self.diagram, self.codetemplate)
Esempio n. 7
0
 def setUp(self):
     """Do the test basic setup."""
     win = MainWindow()
     diagram = Diagram(win)
     block = Block()
     self.code_generator = CodeGenerator(diagram)