MCPcopy Create free account
hub / github.com/BIT-DataLab/Edit-Banana / add_cell

Function add_cell

modules/basic_shape_processor.py:1700–1746  ·  view source on GitHub ↗
(item_list)

Source from the content-addressed store, hash-verified

1698 cell_id = 2
1699
1700 def add_cell(item_list):
1701 nonlocal cell_id
1702 for item in item_list:
1703 x1, y1, x2, y2 = map(int, item["bbox"])
1704 width, height = x2 - x1, y2 - y1
1705 elem_type = item["_type"]
1706
1707 style_data = item.get("_style")
1708 if not style_data:
1709 f_color, s_color, s_width = extract_style_colors(image, item["bbox"])
1710 style_data = {"fill_color": f_color, "stroke_color": s_color, "stroke_width": s_width}
1711
1712 fill_color = style_data["fill_color"]
1713 stroke_color = style_data["stroke_color"]
1714 stroke_width = style_data["stroke_width"]
1715
1716 if elem_type in ("rectangle", "rounded rectangle", "container"):
1717 is_rounded = item.get("is_rounded", elem_type == "rounded rectangle")
1718 rounded_val = "1" if is_rounded else "0"
1719 base_style = f"rounded={rounded_val};whiteSpace=wrap;html=1;"
1720 else:
1721 base_style = DRAWIO_STYLES.get(elem_type, "rounded=0;whiteSpace=wrap;html=1;")
1722
1723 geo_params = style_data.get("geo_params", {})
1724 if elem_type == "parallelogram" and "size" in geo_params:
1725 base_style += f"size={geo_params['size']:.2f};"
1726 elif elem_type == "cylinder" and "size" in geo_params:
1727 base_style += f"size={geo_params['size']};"
1728 elif elem_type == "triangle" and "direction" in geo_params:
1729 base_style += f"direction={geo_params['direction']};"
1730
1731 style = f"{base_style}fillColor={fill_color};strokeColor={stroke_color};strokeWidth={stroke_width};"
1732
1733 cell = ET.SubElement(root, "mxCell", {
1734 "id": str(cell_id),
1735 "parent": "1",
1736 "vertex": "1",
1737 "value": "",
1738 "style": style
1739 })
1740 ET.SubElement(cell, "mxGeometry", {
1741 "x": str(x1), "y": str(y1),
1742 "width": str(width), "height": str(height),
1743 "as": "geometry"
1744 })
1745
1746 cell_id += 1
1747
1748 add_cell(containers_list)
1749 add_cell(shapes_list)

Callers 1

process_basic_shapesFunction · 0.85

Calls 1

extract_style_colorsFunction · 0.85

Tested by

no test coverage detected