Populate the scene from a SchematicData object.
(self, data, library)
| 1618 | model_defs=model_defs) |
| 1619 | |
| 1620 | def from_data(self, data, library) -> None: |
| 1621 | """Populate the scene from a SchematicData object.""" |
| 1622 | self._library = library |
| 1623 | self.reset() |
| 1624 | for cd in data.components: |
| 1625 | svg = library.svg_bytes(cd.symbol_name) |
| 1626 | if svg is None: |
| 1627 | continue |
| 1628 | item = ComponentItem(cd.symbol_name, cd.instance_id, svg) |
| 1629 | # __init__ creates a "refdes" label at the default position. |
| 1630 | # Clear it now so _save_label_offsets() inside update_labels() |
| 1631 | # below does not overwrite the prop_offsets we are about to restore. |
| 1632 | for _lbl in list(item._labels.values()): |
| 1633 | _lbl.setParentItem(None) |
| 1634 | item._labels.clear() |
| 1635 | item.setPos(QPointF(cd.x, cd.y)) |
| 1636 | item.setRotation(cd.rotation) |
| 1637 | item.h_flip = cd.h_flip |
| 1638 | item.v_flip = cd.v_flip |
| 1639 | item.apply_transform() |
| 1640 | item.params = dict(cd.params) |
| 1641 | item.model = cd.model |
| 1642 | item.refs = list(cd.refs) |
| 1643 | item.prop_display = {k: tuple(v) for k, v in cd.prop_display.items()} |
| 1644 | item.prop_offsets = {k: tuple(v) for k, v in cd.prop_offsets.items()} |
| 1645 | # Backfill defaults for power symbols saved without net name (old files) |
| 1646 | if cd.symbol_name in ("0", "port"): |
| 1647 | item.params.setdefault("name", "0" if cd.symbol_name == "0" else "") |
| 1648 | item.prop_display.setdefault("name", (True, False)) |
| 1649 | item.update_labels() |
| 1650 | self.addItem(item) |
| 1651 | # Keep counters above highest loaded number — keyed by PREFIX, to |
| 1652 | # match _next_id (otherwise X / M counters reset and refdes collide). |
| 1653 | prefix = SYMBOL_PREFIX.get(cd.symbol_name, "X") |
| 1654 | m = re.match(rf"^{re.escape(prefix)}(\d+)$", cd.instance_id) |
| 1655 | if m: |
| 1656 | n = int(m.group(1)) |
| 1657 | self._counters[prefix] = max(self._counters.get(prefix, 1), n + 1) |
| 1658 | |
| 1659 | for wd in data.wires: |
| 1660 | wire = WireItem([QPointF(x, y) for x, y in wd.points]) |
| 1661 | wire.net_name = wd.net_name |
| 1662 | wire.display_name = wd.display_name |
| 1663 | wire.label_offset = QPointF(*wd.label_offset) |
| 1664 | wire.net_locked = wd.net_locked |
| 1665 | wire._user_net_name = wd.user_net_name |
| 1666 | self.addItem(wire) |
| 1667 | wire.update_label() |
| 1668 | |
| 1669 | for jd in data.junctions: |
| 1670 | self.addItem(JunctionItem(QPointF(jd.x, jd.y))) |
| 1671 | |
| 1672 | for td in data.free_texts: |
| 1673 | self.addItem(FreeTextItem(td.text, QPointF(td.x, td.y))) |
| 1674 | |
| 1675 | for cd in data.commands: |
| 1676 | self.addItem(CommandItem(cd.text, QPointF(cd.x, cd.y))) |
| 1677 |
no test coverage detected