Serialize the current scene to a SchematicData object.
(self)
| 1492 | wire.update_label() |
| 1493 | |
| 1494 | def to_data(self): |
| 1495 | """Serialize the current scene to a SchematicData object.""" |
| 1496 | from .schematic_data import SchematicData, ComponentData, WireData, JunctionData, FreeTextData, CommandData, BorderData, LibraryData, ImageData, LatexFragmentData, ParameterData, AnalysisData, HyperlinkData, ModelData |
| 1497 | comps, wires, junctions, free_texts, commands, libs, images, latex_frags, param_items, analysis_items, hyperlinks, shapes, model_defs = [], [], [], [], [], [], [], [], [], [], [], [], [] |
| 1498 | border_data = None |
| 1499 | for item in self.items(): |
| 1500 | if isinstance(item, ComponentItem): |
| 1501 | item._save_label_offsets() |
| 1502 | comps.append(ComponentData( |
| 1503 | symbol_name=item.symbol_name, |
| 1504 | instance_id=item.instance_id, |
| 1505 | x=item.pos().x(), |
| 1506 | y=item.pos().y(), |
| 1507 | rotation=item.rotation(), |
| 1508 | h_flip=item.h_flip, |
| 1509 | v_flip=item.v_flip, |
| 1510 | params=dict(item.params), |
| 1511 | model=item.model, |
| 1512 | refs=list(item.refs), |
| 1513 | prop_display={k: list(v) for k, v in item.prop_display.items()}, |
| 1514 | prop_offsets={k: list(v) for k, v in item.prop_offsets.items()}, |
| 1515 | )) |
| 1516 | elif isinstance(item, WireItem): |
| 1517 | wires.append(WireData( |
| 1518 | points=[(p.x(), p.y()) for p in item.points], |
| 1519 | net_name=item.net_name, |
| 1520 | display_name=item.display_name, |
| 1521 | label_offset=(item.label_offset.x(), item.label_offset.y()), |
| 1522 | net_locked=item.net_locked, |
| 1523 | user_net_name=item._user_net_name, |
| 1524 | )) |
| 1525 | elif isinstance(item, JunctionItem): |
| 1526 | junctions.append(JunctionData(x=item.pos().x(), y=item.pos().y())) |
| 1527 | elif isinstance(item, FreeTextItem): |
| 1528 | free_texts.append(FreeTextData( |
| 1529 | x=item.pos().x(), y=item.pos().y(), |
| 1530 | text=item.toPlainText(), |
| 1531 | )) |
| 1532 | elif isinstance(item, CommandItem): |
| 1533 | commands.append(CommandData( |
| 1534 | x=item.pos().x(), y=item.pos().y(), |
| 1535 | text=item.toPlainText(), |
| 1536 | )) |
| 1537 | elif isinstance(item, BorderItem): |
| 1538 | r = item.rect() |
| 1539 | border_data = BorderData( |
| 1540 | x=item.pos().x(), y=item.pos().y(), |
| 1541 | width=r.width(), height=r.height(), |
| 1542 | show_in_export=item.show_in_export, |
| 1543 | ) |
| 1544 | elif isinstance(item, LibraryItem): |
| 1545 | libs.append(LibraryData( |
| 1546 | x=item.pos().x(), y=item.pos().y(), |
| 1547 | file_path=item.file_path, |
| 1548 | directive=item.directive, |
| 1549 | simulator=item.simulator, |
| 1550 | corner=item.corner, |
| 1551 | )) |
no test coverage detected