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

Method _on_place_subcircuit

SLiCAP/schematic/window.py:314–346  ·  view source on GitHub ↗

Place a subcircuit (.lib) as an X block: generate a default symbol, add the de-duplicated .lib include, and start placing the block.

(self)

Source from the content-addressed store, hash-verified

312 )
313
314 def _on_place_subcircuit(self):
315 """Place a subcircuit (.lib) as an X block: generate a default symbol,
316 add the de-duplicated .lib include, and start placing the block."""
317 from .place_subcircuit_dialog import PlaceSubcircuitDialog
318 from .subcircuit import box_symbol_svg
319
320 dlg = PlaceSubcircuitDialog(self)
321 if not dlg.exec():
322 return
323 defn = dlg.subckt_def()
324 lib_path = Path(dlg.lib_path())
325
326 # Generate (or refresh) the block symbol next to its .lib and load just
327 # that symbol — so it never leaks into other (new) schematics, which stay
328 # system-symbols-only until they place the block themselves. The chosen
329 # pin placement is visual only; data-nodes keeps the .subckt order.
330 svg_path = lib_path.with_name(f"{defn.name}.svg")
331 svg_path.write_text(
332 box_symbol_svg(defn, dlg.placement(), *dlg.extra_size()),
333 encoding="utf-8",
334 )
335 self._library.add_bundle(svg_path)
336 self._library.inject_into_component_item()
337 svg = self._library.svg_bytes(defn.name)
338 if svg is None:
339 QMessageBox.critical(
340 self, "Place subcircuit",
341 f"Could not load the generated symbol for {defn.name}.",
342 )
343 return
344
345 self._ensure_library_include(lib_path)
346 self._scene.start_placement(defn.name, svg)
347
348 def _ensure_library_include(self, lib_path: str):
349 """Add a .lib include for lib_path unless one is already on the canvas."""

Callers

nothing calls this directly

Calls 11

subckt_defMethod · 0.95
lib_pathMethod · 0.95
placementMethod · 0.95
extra_sizeMethod · 0.95
box_symbol_svgFunction · 0.85
add_bundleMethod · 0.80
start_placementMethod · 0.80
svg_bytesMethod · 0.45

Tested by

no test coverage detected