A committed wire on the schematic — an ordered polyline of grid-snapped points. Points are in scene coordinates (item pos is always (0,0)). net_name : set by the connectivity resolver or an explicit net label. display_name : when True, a draggable net-name label is shown. l
| 104 | |
| 105 | |
| 106 | class WireItem(QGraphicsPathItem): |
| 107 | """ |
| 108 | A committed wire on the schematic — an ordered polyline of grid-snapped points. |
| 109 | Points are in scene coordinates (item pos is always (0,0)). |
| 110 | |
| 111 | net_name : set by the connectivity resolver or an explicit net label. |
| 112 | display_name : when True, a draggable net-name label is shown. |
| 113 | label_offset : label position relative to points[0] (survives rubber-banding). |
| 114 | |
| 115 | When selected, filled square handles appear at every vertex. |
| 116 | Clicking a handle starts a vertex drag; clicking the wire body inserts a |
| 117 | new vertex at that point and immediately starts dragging it. |
| 118 | """ |
| 119 | |
| 120 | def __init__(self, points: list[QPointF]): |
| 121 | super().__init__() |
| 122 | self.points: list[QPointF] = list(points) |
| 123 | self.net_name: str | None = None |
| 124 | self.display_name: bool = False |
| 125 | self.label_offset: QPointF = QPointF(0.0, -_NET_LABEL_OFFSET) |
| 126 | self.net_locked: bool = False # True when name is imposed by a port |
| 127 | self._user_net_name: str | None = None # name saved before port override |
| 128 | self._net_label: _NetLabel | None = None |
| 129 | self._label_active: bool = False |
| 130 | self.setPen(QPen(WIRE_COLOR, WIRE_WIDTH)) |
| 131 | self.setZValue(Z_WIRE) |
| 132 | self.setFlag(QGraphicsItem.ItemIsSelectable) |
| 133 | self._rebuild() |
| 134 | |
| 135 | # ── net label ───────────────────────────────────────────────────────────── |
| 136 | |
| 137 | def update_label(self) -> None: |
| 138 | """Create, update, or hide the net-name label child item.""" |
| 139 | if self.display_name and self.net_name: |
| 140 | if self._net_label is None: |
| 141 | self._net_label = _NetLabel(self) |
| 142 | self._net_label.setText(self.net_name) |
| 143 | self._net_label.setVisible(True) |
| 144 | self._place_label() |
| 145 | elif self._net_label is not None: |
| 146 | self._net_label.setVisible(False) |
| 147 | |
| 148 | def _place_label(self) -> None: |
| 149 | """Position the label at points[0] + label_offset.""" |
| 150 | if self._net_label is None or not self.points: |
| 151 | return |
| 152 | ref = self.points[0] |
| 153 | self._net_label.setPos(ref.x() + self.label_offset.x(), |
| 154 | ref.y() + self.label_offset.y()) |
| 155 | |
| 156 | # ── bounding rect ───────────────────────────────────────────────────────── |
| 157 | |
| 158 | def boundingRect(self) -> QRectF: |
| 159 | br = super().boundingRect() |
| 160 | m = HANDLE_SIZE / 2.0 |
| 161 | br = br.adjusted(-m, -m, m, m) |
| 162 | if self._net_label is not None and self._net_label.isVisible() and self.points: |
| 163 | br = br.united(self._net_label.mapRectToParent(self._net_label.boundingRect())) |
no outgoing calls
no test coverage detected