def create_block(self, diagram_control=None): if diagram_control is None: diagram_control = self.create_diagram_control() System() block_model = BlockModel() System.add_port(self.create_port()) block_model.ports = [{ "type": "Test", "label": "Click", "conn_type": "Input", "name": "0" }, { "type": "Test", "label": "Click", "conn_type": "Output", "name": "1" }, { "type": "Test", "label": "Click", "conn_type": "Input", "name": "2" }, { "type": "Test", "label": "Click", "conn_type": "Output", "name": "3" }] block_model.help = "Test" block_model.label = "Test" block_model.color = "200:200:25:150" block_model.group = "Test" block_model.codes = {"code0": "Test", "Code1": "Test", "Code2": "Test"} block_model.type = "Test" block_model.language = "Test" block_model.properties = [{ "name": "test", "label": "Test", "value": "0", "type": MOSAICODE_FLOAT }] block_model.extension = "Test" block_model.file = None result = BlockControl.load_ports(block_model, System.get_ports()) System.add_block(block_model) self.assertEquals(result[1], "Success") self.assertEquals(result[0], True) self.assertEquals(len(block_model.ports), 4) block = Block(diagram_control.diagram, block_model) self.assertEquals(len(block.ports), 4) return block
def load_xml(cls, file_name): """ This method loads the block from XML file. Returns: * **Types** (:class:`boolean<boolean>`) """ if os.path.exists(file_name) is False: return None parser = XMLParser(file_name) if parser.getTag(tag_name) is None: return None block = BlockModel() block.type = parser.getTagAttr(tag_name, "type") block.language = parser.getTagAttr(tag_name, "language") block.extension = parser.getTagAttr(tag_name, "extension") block.help = parser.getTagAttr(tag_name, "help") block.color = parser.getTagAttr(tag_name, "color") block.label = parser.getTagAttr(tag_name, "label") block.group = parser.getTagAttr(tag_name, "group") codes = parser.getTag(tag_name).getTag("codes") if codes: codes = codes.getChildTags("code") for code in codes: block.codes[code.getAttr("name_")] = code.getAttr("value") props = parser.getTag(tag_name).getTag("properties") if props: props = props.getChildTags("property") for prop in props: block.properties.append(ast.literal_eval(prop.getAttr("value"))) ports = parser.getTag(tag_name).getTag("ports") if ports: ports = ports.getChildTags("port") for port in ports: dict_port = {} dict_port["type"] = str(port.getAttr("type_")) dict_port["name"] = str(port.getAttr("name_")) dict_port["label"] = str(port.getAttr("label")) dict_port["conn_type"] = str(port.getAttr("conn_type")) block.ports.append(dict_port) block.file = file_name if block.type == "mosaicode.model.blockmodel": return None return block
def load(cls, file_name): """ This method loads the block from JSON file. Returns: * **Types** (:class:`boolean<boolean>`) """ if os.path.exists(file_name) is False: return None data = "" block = BlockModel() try: data_file = open(file_name, 'r') data = json.load(data_file) data_file.close() if data["data"] != "BLOCK": return None block.type = data["type"] block.language = data["language"] block.extension = data["extension"] block.help = data["help"] block.color = data["color"] block.label = data["label"] block.group = data["group"] codes = data["codes"] if codes: for code in codes: block.codes[code["name"]] = code["code"] props = data["properties"] for prop in props: block.properties.append(prop) ports = data["ports"] for port in ports: block.ports.append(port) block.file = file_name except: return None if block.type == "mosaicode.model.blockmodel": return None return block
def create_block(self, diagram_control=None): if diagram_control is None: diagram_control = self.create_diagram_control() block_model = BlockModel() port0 = Port() port0.label = "Test0" port0.conn_type = Port.OUTPUT port0.name = "Test0" port0.type = "Test" port1 = Port() port1.label = "Test1" port1.conn_type = Port.INPUT port1.name = "Test1" port1.type = "Test" block_model.ports = [port0, port1] block_model.help = "Test" block_model.label = "Test" block_model.color = "200:200:25:150" block_model.group = "Test" block_model.codes = {"code0":"Test", "Code1":"Test", "Code2":"Test"} block_model.type = "Test" block_model.maxIO = 2 block_model.language = "language" block_model.properties = [{"name": "test", "label": "Test", "type": MOSAICODE_FLOAT }] block_model.extension = "Test" block_model.file = None block = Block(diagram_control.diagram, block_model) return block