MCPcopy Index your code
hub / github.com/SLiCAP/SLiCAP_python / _rb_keep_item

Function _rb_keep_item

SLiCAP/schematic/canvas.py:2677–2710  ·  view source on GitHub ↗

Return True if item should stay selected given scene_rect and mode. contains=True → right-to-left drag: item must be fully inside scene_rect. contains=False → left-to-right drag: item must intersect scene_rect. Uses tight per-type rects so that label bounding boxes on components

(item, scene_rect: QRectF, contains: bool)

Source from the content-addressed store, hash-verified

2675
2676
2677def _rb_keep_item(item, scene_rect: QRectF, contains: bool) -> bool:
2678 """
2679 Return True if item should stay selected given scene_rect and mode.
2680
2681 contains=True → right-to-left drag: item must be fully inside scene_rect.
2682 contains=False → left-to-right drag: item must intersect scene_rect.
2683
2684 Uses tight per-type rects so that label bounding boxes on components and
2685 wires don't trigger selection when the rubber-band is far from the body.
2686 """
2687 from .component_item import ComponentItem, SYMBOL_TIGHT_RECT
2688 from .wire_item import WireItem
2689 if isinstance(item, WireItem):
2690 if contains:
2691 return all(scene_rect.contains(pt) for pt in item.points)
2692 # intersects: build a tight rect from the wire points, ignoring the label
2693 pts = item.points
2694 if not pts:
2695 return False
2696 xs = [p.x() for p in pts]
2697 ys = [p.y() for p in pts]
2698 tol = 3.0
2699 path_rect = QRectF(min(xs) - tol, min(ys) - tol,
2700 max(xs) - min(xs) + 2 * tol,
2701 max(ys) - min(ys) + 2 * tol)
2702 return scene_rect.intersects(path_rect)
2703 if isinstance(item, ComponentItem):
2704 tight = SYMBOL_TIGHT_RECT.get(item.symbol_name)
2705 local_rect = QRectF(*tight) if tight else QRectF(-30, -30, 60, 60)
2706 item_rect = item.mapRectToScene(local_rect)
2707 return scene_rect.contains(item_rect) if contains else scene_rect.intersects(item_rect)
2708 # JunctionItem, FreeTextItem, CommandItem, etc. — use actual bounding rect (no labels)
2709 item_rect = item.mapRectToScene(item.boundingRect())
2710 return scene_rect.contains(item_rect) if contains else scene_rect.intersects(item_rect)
2711
2712
2713# ── view ─────────────────────────────────────────────────────────────────────

Callers 2

mouseMoveEventMethod · 0.85
mouseReleaseEventMethod · 0.85

Calls 1

boundingRectMethod · 0.45

Tested by

no test coverage detected