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

Class JunctionItem

SLiCAP/schematic/junction_item.py:14–57  ·  view source on GitHub ↗

Electrical junction dot — always user-managed. Junctions are auto-placed when a wire drawing operation creates a new T-intersection, but they are ordinary objects after that: selectable, movable, and deletable. There is no separate 'auto' type.

Source from the content-addressed store, hash-verified

12
13
14class JunctionItem(QGraphicsEllipseItem):
15 """
16 Electrical junction dot — always user-managed.
17
18 Junctions are auto-placed when a wire drawing operation creates a new
19 T-intersection, but they are ordinary objects after that: selectable,
20 movable, and deletable. There is no separate 'auto' type.
21 """
22
23 def __init__(self, center: QPointF):
24 r = JUNCTION_RADIUS
25 super().__init__(-r, -r, 2 * r, 2 * r)
26 self.setPos(center)
27 self.setPen(QPen(Qt.NoPen))
28 self.setBrush(QBrush(JUNCTION_COLOR))
29 self.setZValue(Z_JUNCTION)
30 self.setFlag(QGraphicsItem.ItemIsSelectable)
31 self.setFlag(QGraphicsItem.ItemIsMovable)
32 self.setFlag(QGraphicsItem.ItemSendsGeometryChanges)
33
34 def boundingRect(self) -> QRectF:
35 r = JUNCTION_RADIUS + _SEL_PAD
36 return QRectF(-r, -r, 2.0 * r, 2.0 * r)
37
38 def itemChange(self, change, value):
39 if change == QGraphicsItem.ItemPositionChange:
40 snapped = snap(value)
41 if self.scene() and not getattr(self.scene(), '_group_drag_active', False):
42 delta = snapped - self.pos()
43 if delta.x() or delta.y():
44 self._rubber_band_wires(delta)
45 return snapped
46 return super().itemChange(change, value)
47
48 def _rubber_band_wires(self, delta: QPointF) -> None:
49 """Move wire endpoints that currently touch this junction."""
50 from .wire_item import WireItem
51 pos_key = _pt_key(self.pos())
52 for item in self.scene().items():
53 if not isinstance(item, WireItem):
54 continue
55 hits = {i for i, pt in enumerate(item.points) if _pt_key(pt) == pos_key}
56 if hits:
57 item.move_points(hits, delta)

Callers 3

_sync_junctionsMethod · 0.85
from_dataMethod · 0.85
mousePressEventMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected