def pipe_connector_symbol_handler(node: xml._Element, ctx: Context) -> svgwrite.container.Group: """ Handler to process Proteus PipeConnectorSymbol node. This is a complex node which contains other nodes :param node: :param ctx: :return: """ ensure_type(node, 'PipeConnectorSymbol') pipe_conn_group = create_group(ctx, node) cross_page_conn = node.find('CrossPageConnection') if cross_page_conn is not None: pipe_conn_group.attribs[ 'data-drawing-name'] = cross_page_conn.attrib.get('DrawingName') pipe_conn_group.attribs[ 'data-drawing-link-label'] = cross_page_conn.attrib.get( 'LinkLabel') # todo we could also need support for CrossPageConnection with linkedPersistentId if node.attrib.get(ATTR_COMP_NAME) is not None: shape_reference = ctx.get_from_shape_catalog( 'PipeConnectorSymbol', node.attrib[ATTR_COMP_NAME]) process_shape_reference(node, shape_reference, ctx) return pipe_conn_group
def component_handler(node: xml._Element, ctx: Context) -> svgwrite.container.Group: """ Handler to process Proteus Component node. This is a complex node which contains other nodes :param node: :param ctx: :return: """ ensure_type(node, 'Component') pn_sys_group = create_group(ctx, node) shape_reference = ctx.get_from_shape_catalog( 'Component', node.attrib.get(ATTR_COMP_NAME)) process_shape_reference(node, shape_reference, ctx) return pn_sys_group
def instrument_component_handler(node: xml._Element, ctx: Context): """ Handler to process Proteus InstrumentComponent node. This is a complex node which contains other nodes and can be referenced in ShapeCatalogue :param node: :param ctx: :return: """ ensure_type(node, 'InstrumentComponent') pipe_comp_group = create_group(ctx, node) shape_reference = ctx.get_from_shape_catalog( 'InstrumentComponent', node.attrib.get(ATTR_COMP_NAME)) process_shape_reference(node, shape_reference, ctx) return pipe_comp_group
def process_instrumentation_function_handler(node: xml._Element, ctx: Context): """ Handler to process Proteus ProcessInstrumentationFunction node. This is a complex node which contains other nodes and can be referenced in ShapeCatalogue :param node: :param ctx: :return: """ ensure_type(node, 'ProcessInstrumentationFunction') shape_reference = ctx.get_from_shape_catalog( 'ProcessInstrumentationFunction', node.attrib.get(ATTR_COMP_NAME)) process_shape_reference(node, shape_reference, ctx) return create_group(ctx, node)
def piping_component_handler(node: xml._Element, ctx: Context) -> svgwrite.container.Group: """ Handler to process Proteus PipingComponent node. This is a complex node which contains other nodes and can be referenced in ShapeCatalogue :param node: node to process :param ctx: drawing context :return: svgwrite.container.Group object """ ensure_type(node, 'PipingComponent') pipe_comp_group = create_group(ctx, node) shape_reference = ctx.get_from_shape_catalog( 'PipingComponent', node.attrib.get(ATTR_COMP_NAME)) process_shape_reference(node, shape_reference, ctx) return pipe_comp_group
def equipment_handler(node: xml._Element, ctx: Context) -> svgwrite.container.Group: """ Handler to process Equipment object :param node: node to process :param ctx: model context :return: SVG group object where Equipment parts will be added later """ ensure_type(node, 'Equipment') eq_group = create_group(ctx, node) # fixme this one will work with Comos but what if we get drawing from any other systems? # eq_group.attribs[DATA_LABEL] = get_gen_attr_val(node, 'ComosProperties', 'Label') # eq_group.attribs[DATA_FULL_LABEL] = get_gen_attr_val(node, 'ComosProperties', 'FullLabel') # this it temporary fix for that # attributes_to_add_from_origin method should be updated if we get new Proteus data sources # probably we could move it into external config file instead of code # probably we also need common data-* name's which do not depend on originating system for attr in ctx.attributes_to_add_from_origin(): for attr_value in attr.get('values'): key = f'data-{ctx.origin.lower()}-{attr_value.lower()}' value = get_gen_attr_val(node, attr['set'], attr_value) if value is not None: eq_group.attribs[key] = value descr_obj = node.find('Description') if descr_obj is not None: eq_group.attribs['data-description'] = descr_obj.text if eq_group.attribs.get(DATA_COMPONENT_NAME) is not None: shape_reference = ctx.get_from_shape_catalog( 'Equipment', eq_group.attribs[DATA_COMPONENT_NAME]) process_shape_reference(node, shape_reference, ctx) return eq_group
def process_file(project_id): debug = bool(request.args.get('debug')) grid = request.args.get('grid') for file in request.files: input_file = xml.parse(request.files[file], PARSER) plant_model = input_file.getroot() if plant_model.tag != ROOT_ELEMENT: abort( 400, f'malformed file {file}, {ROOT_ELEMENT} expected at root level' ) pl_info = plant_model.find('PlantInformation') m_unit = Unit[pl_info.attrib['Units']] # proteus coordinates x_min, y_min, x_max, y_max = map( lambda x: x * m_unit.value, get_model_dimensions_from_plant_model(plant_model)) drawing = get_default(f'{file}.svg', size=(x_max, y_max), view_box=(0, 0, x_max, y_max)) model_context = Context( drawing=drawing, x_min=x_min, x_max=x_max, y_min=y_min, y_max=y_max, debug=debug, origin=pl_info.attrib['OriginatingSystem'], units=m_unit, shape_catalog=plant_model.find('ShapeCatalogue')) drawing.attribs['data-origin'] = model_context.origin drawing.attribs['data-drawing'] = plant_model.find( 'Drawing').attrib.get('Name') drawing.attribs['data-project'] = str(project_id) set_bg_color(drawing, plant_model) if grid is not None: add_grid(drawing, int(grid) if grid.isnumeric() else 10) process_node(plant_model, drawing, model_context) return Response(drawing.tostring(), mimetype='image/svg+xml')
def label_handler(node: xml._Element, ctx: Context) -> svgwrite.container.Group: """ Handler to process Proteus Label node. This is a complex node which contains other nodes and can be referenced in ShapeCatalogue :param node: :param ctx: :return: """ ensure_type(node, 'Label') shape_reference = ctx.get_from_shape_catalog( 'Label', node.attrib.get(ATTR_COMP_NAME)) process_shape_reference(node, shape_reference, ctx) return create_group(ctx, node)
def nozzle_handler(node: xml._Element, ctx: Context) -> svgwrite.container.Group: """ Handler to process Nozzle object :param node: object to process :param ctx: drawing context :return: SVG group object """ ensure_type(node, 'Nozzle') nozzle_group = create_group(ctx, node) shape_reference = ctx.get_from_shape_catalog( 'Nozzle', nozzle_group.attribs[DATA_COMPONENT_NAME]) process_shape_reference(node, shape_reference, ctx) return nozzle_group