MCPcopy Create free account
hub / github.com/SLiCAP/SLiCAP_python / _save_subcircuit

Method _save_subcircuit

SLiCAP/schematic/window.py:699–758  ·  view source on GitHub ↗

Save the schematic as a SLiCAP subcircuit: write both .slicap_sch and .lib into a user-chosen directory (the 'Subcircuit' box in Document Properties is ticked).

(self)

Source from the content-addressed store, hash-verified

697 self._save_to(p)
698
699 def _save_subcircuit(self):
700 """Save the schematic as a SLiCAP subcircuit: write both <title>.slicap_sch
701 and <title>.lib into a user-chosen directory (the 'Subcircuit' box in
702 Document Properties is ticked)."""
703 title = self._doc_props.title.strip()
704 if not title:
705 QMessageBox.warning(
706 self, "No title",
707 "Set a Title in Document Properties before saving as a subcircuit.",
708 )
709 return
710
711 from .component_item import ComponentItem
712 from .wire_item import WireItem
713 from .parameter_item import ParameterItem
714 from .netlist import build_subcircuit, schematic_ports
715 from .create_subcircuit_dialog import CreateSubcircuitDialog
716
717 items = self._scene.items()
718 comps = [i for i in items if isinstance(i, ComponentItem)]
719 wires = [i for i in items if isinstance(i, WireItem)]
720 prms = [i for i in items if isinstance(i, ParameterItem)]
721
722 # Default node order: keep the previously chosen order for ports that
723 # still exist, then append any newly added ports (clockwise default).
724 present = schematic_ports(comps, wires)
725 saved = [p for p in self._doc_props.subcircuit_ports if p in present]
726 ports_default = saved + [p for p in present if p not in saved]
727
728 dlg = CreateSubcircuitDialog(
729 title, ports_default, self._doc_props.subcircuit_params, self
730 )
731 if not dlg.exec():
732 return
733
734 self._doc_props.subcircuit_ports = dlg.ports()
735 self._doc_props.subcircuit_params = dlg.params()
736
737 # Fixed project layout: editable source → sch/, compiled library → lib/.
738 sch_path = project.subdir("sch") / f"{title}.slicap_sch"
739 lib_path = project.subdir("lib") / f"{title}.lib"
740
741 # Save the editable source first (this also migrates sidecars and clears
742 # the dirty flag), then write the compiled library into lib/.
743 self._save_to(sch_path)
744 try:
745 lib_text = build_subcircuit(
746 comps, wires, title,
747 self._doc_props.subcircuit_ports,
748 self._doc_props.subcircuit_params,
749 params_items=prms,
750 )
751 lib_path.write_text(lib_text, encoding="utf-8")
752 except Exception as exc:
753 QMessageBox.critical(self, "Subcircuit save failed", str(exc))
754 return
755 QMessageBox.information(
756 self, "Subcircuit saved",

Callers 2

_on_saveMethod · 0.95
_on_save_asMethod · 0.95

Calls 6

portsMethod · 0.95
paramsMethod · 0.95
_save_toMethod · 0.95
schematic_portsFunction · 0.85
build_subcircuitFunction · 0.85

Tested by

no test coverage detected