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

Method start_model_placement

SLiCAP/schematic/canvas.py:765–806  ·  view source on GitHub ↗
(self, model_name: str, model_type: str,
                               simulator: str, params: list,
                               preamble_path: str = "",
                               display_width: int = 200, display_height: int = 80)

Source from the content-addressed store, hash-verified

763 self.placing_started.emit()
764
765 def start_model_placement(self, model_name: str, model_type: str,
766 simulator: str, params: list,
767 preamble_path: str = "",
768 display_width: int = 200, display_height: int = 80):
769 self._end_wire(commit=False)
770 self._cancel_placement()
771 from .latex_label import render_latex_raw
772 from .model_item import ModelItem as _MI
773 svg_bytes, _ = render_latex_raw(
774 _MI.build_latex(model_name, model_type, params), preamble_path)
775 if svg_bytes:
776 from PySide6.QtWidgets import QGraphicsPixmapItem
777 from PySide6.QtGui import QPixmap, QPainter as _QPainter
778 from PySide6.QtSvg import QSvgRenderer
779 from PySide6.QtCore import QByteArray
780 renderer = QSvgRenderer(QByteArray(svg_bytes))
781 w, h = max(1, display_width), max(1, display_height)
782 if renderer.isValid():
783 px = QPixmap(w, h)
784 px.fill(Qt.transparent)
785 p = _QPainter(px)
786 renderer.render(p)
787 p.end()
788 else:
789 px = QPixmap(w, h)
790 px.fill(QColor(200, 225, 255))
791 ghost = QGraphicsPixmapItem(px)
792 else:
793 from PySide6.QtWidgets import QGraphicsSimpleTextItem
794 from PySide6.QtGui import QBrush
795 ghost = QGraphicsSimpleTextItem(f".model {model_name} {model_type}")
796 ghost.setFont(COMMAND_FONT)
797 ghost.setBrush(QBrush(COMMAND_COLOR))
798 ghost.setOpacity(0.5)
799 ghost.setAcceptedMouseButtons(Qt.NoButton)
800 self._ghost = ghost
801 self._ghost.setPos(QPointF(-9999, -9999))
802 self.addItem(self._ghost)
803 self._model_pending = (model_name, model_type, simulator, params,
804 preamble_path, display_width, display_height)
805 self._mode = _Mode.PLACING_MODEL
806 self.placing_started.emit()
807
808 # ── shape drawing ─────────────────────────────────────────────────────────
809

Callers 1

Calls 4

_end_wireMethod · 0.95
_cancel_placementMethod · 0.95
render_latex_rawFunction · 0.85
build_latexMethod · 0.45

Tested by

no test coverage detected