Compare commits
2
Commits
0d5e5115d9
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6dd01b13b9 | ||
|
|
0dddea53f8 |
+1
-1
@@ -8,7 +8,7 @@ so later rebinding would only ever be seen by the module that did it.
|
||||
import configparser
|
||||
import os
|
||||
|
||||
VERSION = "0.0.0.180"
|
||||
VERSION = "0.0.0.182"
|
||||
PROPERTIES_FILE = os.path.join(os.path.dirname(os.path.abspath(__file__)), "editor.properties")
|
||||
DEFAULT_GRID_SIZE = 10
|
||||
DEFAULT_ADD_TIMESTAMP = True
|
||||
|
||||
@@ -92,17 +92,55 @@ def _trace(direction, msg, datagram=None):
|
||||
import datetime
|
||||
ts = datetime.datetime.now().strftime("%H:%M:%S.%f")[:-3]
|
||||
name = _MSG_TYPE_NAMES.get(msg.msg_type, f"?{msg.msg_type}")
|
||||
seq = f" seq={msg.seq_num}" if msg.seq_num >= 0 else ""
|
||||
ack = f" ack={msg.ack}" if msg.ack >= 0 else ""
|
||||
plen = len(msg.payload) if msg.payload else 0
|
||||
hexdump = ""
|
||||
arrow = {"S": ">> SEND", "R": "<< RECV"}.get(direction, direction)
|
||||
payload = msg.payload or b""
|
||||
size = f" ({len(datagram)} bytes)" if datagram else ""
|
||||
lines = [f"[DASP] {ts} {arrow} {name:<12} {_trace_fields(msg)}{size}"]
|
||||
if datagram:
|
||||
hexdump = " [" + datagram.hex(" ") + "]"
|
||||
line = f"[DASP] {ts} {direction} {name}{seq}{ack} payload={plen}{hexdump}"
|
||||
hdr_len = len(datagram) - len(payload)
|
||||
lines.extend(_hexdump(datagram[:hdr_len], f"header {hdr_len}"))
|
||||
if payload:
|
||||
lines.extend(_hexdump(payload, f"payload {len(payload)}"))
|
||||
color = _TRACE_COLORS.get(direction)
|
||||
if color and _console_colors():
|
||||
line = f"{color}{line}\033[0m"
|
||||
_trace_out(line)
|
||||
lines = [f"{color}{ln}\033[0m" for ln in lines]
|
||||
_trace_out("\n".join(lines))
|
||||
|
||||
|
||||
def _trace_fields(msg):
|
||||
"""The message's header fields as name=value pairs, only those it carries."""
|
||||
f = []
|
||||
if msg.session_id >= 0: f.append(f"session=0x{msg.session_id:04x}")
|
||||
if msg.seq_num >= 0: f.append(f"seq={msg.seq_num}")
|
||||
if msg.ack >= 0: f.append(f"ack={msg.ack}")
|
||||
if msg.ack_more: f.append(f"ackMore={msg.ack_more.hex()}")
|
||||
if msg.version >= 0: f.append(f"version=0x{msg.version:04x}")
|
||||
if msg.remote_id >= 0: f.append(f"remoteId=0x{msg.remote_id:04x}")
|
||||
if msg.username: f.append(f"user={msg.username}")
|
||||
if msg.digest_algorithm: f.append(f"digestAlg={msg.digest_algorithm}")
|
||||
if msg.nonce: f.append(f"nonce=<{len(msg.nonce)} bytes>")
|
||||
if msg.digest: f.append(f"digest=<{len(msg.digest)} bytes>")
|
||||
if msg.ideal_max >= 0: f.append(f"idealMax={msg.ideal_max}")
|
||||
if msg.abs_max >= 0: f.append(f"absMax={msg.abs_max}")
|
||||
if msg.receive_max >= 0: f.append(f"receiveMax={msg.receive_max}")
|
||||
if msg.receive_timeout >= 0: f.append(f"receiveTimeout={msg.receive_timeout // 1000}s")
|
||||
if msg.platform_id: f.append(f"platform={msg.platform_id}")
|
||||
if msg.error_code >= 0:
|
||||
hint = _ERROR_HINTS.get(msg.error_code, "")
|
||||
f.append(f"error=0x{msg.error_code:02x}{hint}")
|
||||
return " ".join(f)
|
||||
|
||||
|
||||
def _hexdump(data, label):
|
||||
"""Hex and ASCII, 16 bytes a row, the first row headed by label."""
|
||||
out = []
|
||||
for off in range(0, len(data), 16):
|
||||
chunk = data[off:off + 16]
|
||||
hexs = chunk.hex(" ").ljust(47)
|
||||
text = "".join(chr(b) if 32 <= b < 127 else "." for b in chunk)
|
||||
head = label if off == 0 else ""
|
||||
out.append(f" {head:<11} {off:04x} {hexs} |{text}|")
|
||||
return out
|
||||
|
||||
|
||||
# Sent lines yellow, received lines green, so the two directions read apart at a glance.
|
||||
|
||||
+3
-2
@@ -5,10 +5,11 @@ add_timestamp = True
|
||||
box_width = 250
|
||||
left_pane_width = 230
|
||||
trace_dasp = True
|
||||
lazy_loading = False
|
||||
lazy_loading = True
|
||||
show_slot_numbers = False
|
||||
|
||||
[Device]
|
||||
host = localhost
|
||||
host = 192.168.0.26
|
||||
port = 1876
|
||||
user = admin
|
||||
|
||||
|
||||
@@ -2135,14 +2135,17 @@ def on_canvas_drag(event):
|
||||
dy = cy - app_state.drag_data["y"]
|
||||
xs = [entry["origin"][0] for entry in group]
|
||||
ys = [entry["origin"][1] for entry in group]
|
||||
dx = min(limit - max(xs), max(margin - min(xs), dx))
|
||||
# A box with an off-sheet input stops a step further in, keeping its knob on the sheet.
|
||||
left = wiresheet.box_left_limits([entry["tag"] for entry in group], margin, step)
|
||||
dx = min(limit - max(xs),
|
||||
max(max(left[e["tag"]] - e["origin"][0] for e in group), dx))
|
||||
dy = min(limit - max(ys), max(margin - min(ys), dy))
|
||||
|
||||
shifted = False
|
||||
for entry in group:
|
||||
# Land each box on a step every step of the way.
|
||||
start_x, start_y = entry["origin"]
|
||||
target_x = min(limit, max(margin, round((start_x + dx) / step) * step))
|
||||
target_x = min(limit, max(left[entry["tag"]], round((start_x + dx) / step) * step))
|
||||
target_y = min(limit, max(margin, round((start_y + dy) / step) * step))
|
||||
origin = wiresheet.get_box_origin(entry["tag"])
|
||||
if origin is None:
|
||||
@@ -2178,6 +2181,7 @@ def on_canvas_release(event):
|
||||
|
||||
changes = []
|
||||
failed = []
|
||||
left = wiresheet.box_left_limits([entry["tag"] for entry in group], margin, step)
|
||||
for entry in group:
|
||||
group_tag = entry["tag"]
|
||||
origin = wiresheet.get_box_origin(group_tag)
|
||||
@@ -2185,7 +2189,7 @@ def on_canvas_release(event):
|
||||
continue
|
||||
current_x, current_y = origin
|
||||
|
||||
snapped_x = min(limit, max(margin, round(current_x / step) * step))
|
||||
snapped_x = min(limit, max(left[group_tag], round(current_x / step) * step))
|
||||
snapped_y = min(limit, max(margin, round(current_y / step) * step))
|
||||
|
||||
shift_x = snapped_x - current_x
|
||||
@@ -2255,9 +2259,11 @@ def nudge_selected_boxes(dx, dy):
|
||||
origins = {t: wiresheet.get_box_origin(t) for t in tags}
|
||||
if any(o is None for o in origins.values()):
|
||||
return "break"
|
||||
# The group stops as one at the margin strip and the sheet's far edge.
|
||||
# The group stops as one at the margin strip and the sheet's far edge; a box with an
|
||||
# off-sheet input stops a step further in, keeping its knob on the sheet.
|
||||
left = wiresheet.box_left_limits(tags, margin, step)
|
||||
shift_x = min(limit - max(o[0] for o in origins.values()),
|
||||
max(margin - min(o[0] for o in origins.values()), dx * step))
|
||||
max(max(left[t] - o[0] for t, o in origins.items()), dx * step))
|
||||
shift_y = min(limit - max(o[1] for o in origins.values()),
|
||||
max(margin - min(o[1] for o in origins.values()), dy * step))
|
||||
if not shift_x and not shift_y:
|
||||
|
||||
@@ -154,6 +154,36 @@ def suggest_box_width_for_grid(width, grid_size):
|
||||
return proposed
|
||||
|
||||
|
||||
def offsheet_input_comps(components):
|
||||
"""The components with a link arriving from off this sheet, drawn as a knob on
|
||||
their left edge."""
|
||||
root = app_state.xml_root_element
|
||||
links_elem = root.find("links") if root is not None else None
|
||||
if links_elem is None:
|
||||
return set()
|
||||
comp_by_path = {get_component_path(comp, root): comp for comp in components}
|
||||
found = set()
|
||||
for link in links_elem.findall("link"):
|
||||
from_ref, to_ref = link.get("from", ""), link.get("to", "")
|
||||
if "." not in from_ref or "." not in to_ref:
|
||||
continue
|
||||
dst = comp_by_path.get(to_ref.rsplit(".", 1)[0])
|
||||
if dst is not None and from_ref.rsplit(".", 1)[0] not in comp_by_path:
|
||||
found.add(dst)
|
||||
return found
|
||||
|
||||
|
||||
def box_left_limits(tags, margin, step):
|
||||
"""Left-most x each box on the open sheet may be moved to, keyed by canvas tag.
|
||||
|
||||
The margin, or one step further in for a box with an off-sheet input, so its knob
|
||||
stays on the sheet rather than out in the grey margin.
|
||||
"""
|
||||
knobbed = offsheet_input_comps(list(app_state.canvas_comp_map.values()))
|
||||
return {tag: margin + step if app_state.canvas_comp_map.get(tag) in knobbed
|
||||
else margin for tag in tags}
|
||||
|
||||
|
||||
def layout_margin(grid_size=None):
|
||||
"""The top/left edge offset a box may not encroach on, snapped onto the grid."""
|
||||
if grid_size is None:
|
||||
@@ -1575,6 +1605,10 @@ def plan_columns(columns, column_keys, demand, scale, wires=()):
|
||||
# Column x positions depend only on widths and wire lanes, so they come first.
|
||||
column_x = []
|
||||
cursor_x = margin # the left-most column clears the canvas edge by the margin
|
||||
if count and any(item.get("knob_in") for item in columns[column_keys[0]]):
|
||||
# One step further in, so a knob on a first-column box's left edge stays on
|
||||
# the sheet instead of out in the margin.
|
||||
cursor_x = snap_up(margin + app_state.GRID_SIZE, scale)
|
||||
for index, grid_x in enumerate(column_keys):
|
||||
column_x.append(cursor_x)
|
||||
gap = column_gap_for(demand.get(index, 0))
|
||||
@@ -1868,6 +1902,7 @@ def build_layout_items(components):
|
||||
linked_slot_index = build_linked_slot_index()
|
||||
pairs = sheet_link_pairs(components)
|
||||
on_sheet = {comp for src, _, dst, _ in pairs for comp in (src, dst)}
|
||||
knobbed = offsheet_input_comps(components)
|
||||
|
||||
linked = []
|
||||
loose = []
|
||||
@@ -1880,6 +1915,7 @@ def build_layout_items(components):
|
||||
"comp": comp, "meta": meta_val,
|
||||
"grid_x": grid_x, "grid_y": grid_y,
|
||||
"width": width, "height": height,
|
||||
"knob_in": comp in knobbed,
|
||||
# Where each slot's wire meets the box, as painted by draw_component_box.
|
||||
"slot_offsets": {
|
||||
raw_name: HEADER_HEIGHT + row * SLOT_ROW_HEIGHT + SLOT_ROW_HEIGHT // 2
|
||||
|
||||
Reference in New Issue
Block a user