From 08896d85652ccb0232ab499b5aae8b862983b623 Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Thu, 3 Dec 2026 15:07:25 +0100 Subject: [PATCH] brokkr_kitbash: set_params and setObjectParent ask the one-driver rule before they write; a joints row says held write_checks is the writer's own checks and the one-driver rule in one call: write_connections asks it before it writes, and set_params asks it before it rebuilds a mesh or rewrites kit_params, so its refusal leaves the scene as it stood (finding set-params-writes-before-the-guard). Brokkr's setObjectParent asks each enabled add-on that defines brokkr_parent_refusal(object, parent) before it writes a parent; brokkr_kitbash answers one_driver over the scene as the new parent would leave it (finding bridge-reparent-bypasses-the-guard). A brokkr.joints row carries held: true when its limits are of one value (finding held-pin-row-is-undistinguished). Co-Authored-By: Claude Fable 5.2 --- .../blender/brokkr_bridge/blender_target.py | 6 ++ surfaces/blender/brokkr_kitbash/__init__.py | 65 ++++++++++++++----- surfaces/blender/brokkr_kitbash/core.py | 4 +- .../blender/tests/live/kitbash_follows.py | 24 ++++++- .../tests/live/kitbash_follows.result.json | 29 ++++++++- .../tests/live/kitbash_pose.result.json | 6 ++ surfaces/blender/tests/test_kitbash.py | 21 ++++-- 7 files changed, 125 insertions(+), 30 deletions(-) diff --git a/surfaces/blender/brokkr_bridge/blender_target.py b/surfaces/blender/brokkr_bridge/blender_target.py index 6e23e8c..5d90bc4 100644 --- a/surfaces/blender/brokkr_bridge/blender_target.py +++ b/surfaces/blender/brokkr_bridge/blender_target.py @@ -47,6 +47,7 @@ HOST_SNAPSHOT_SCHEMA = "brokkr.blender.host_snapshot.v0" HOST_ACTIONS_FILE = "brokkr_actions.json" HOST_RESULT_LIMIT = 16000 # characters of a host operator's result copied into a receipt KIT_RESERVED = "kit_" # brokkr_kitbash owns every custom property so named: kit_owned is the one test, setObjectCustomProperty refuses them and importGltf drops them +PARENT_REFUSAL = "brokkr_parent_refusal" # a function(object, parent or None) -> why not, or None, that an enabled add-on may define: setObjectParent asks each before it writes (brokkr_kitbash: its one-driver rule) KIT_FROZEN = "kit_frozen" # brokkr_kitbash's frozen state (its FROZEN): read here only, to refuse an export that would apply a stack twice COMMAND_INTENT_SCHEMA = "brokkr.blender.command_intent.v0" COMMAND_RECEIPT_SCHEMA = "brokkr.blender.command_receipt.v0" @@ -934,6 +935,11 @@ class BrokkrBlenderTarget: if ancestor.name == obj.name: raise sa.ActionRefused(f"{obj.name!r} cannot be parented to itself or to one of its own children.") ancestor = getattr(ancestor, "parent", None) + for module in self.bpy.context.preferences.addons.keys(): # an enabled add-on that owns a rule over parents is asked before the write + refusal = getattr(sys.modules.get(module), PARENT_REFUSAL, None) + reason = refusal(obj, parent) if callable(refusal) else None + if reason: + raise sa.ActionRefused(reason) obj.parent = parent return self._receipt(command, "accepted", "Blender object parent updated.", obj.name) diff --git a/surfaces/blender/brokkr_kitbash/__init__.py b/surfaces/blender/brokkr_kitbash/__init__.py index b4c008f..1d04944 100644 --- a/surfaces/blender/brokkr_kitbash/__init__.py +++ b/surfaces/blender/brokkr_kitbash/__init__.py @@ -222,29 +222,33 @@ def dof(parent, parent_socket: dict): return core.load_kit(str(parent.get(KIT, "")))["socketTypes"][parent_socket["type"]].get("dof") -def connection_kind(obj, kits=None) -> tuple: +STANDS = object() # connection_kind's and joint_record's `parent` when it is the one the child has + + +def connection_kind(obj, kits=None, parent=STANDS) -> tuple: """(DOF kind, parent socket type) of the connection a child states, from the parent's kit by the socket's name alone (a socket's type is the same at every params), or (None, None) when it cannot be read: no parent, a parent that is no kit part, a socket the part does not have. `kits` is kit_part_of's: one call's read of each - kit file.""" + kit file. `parent` is the parent the child is about to be given (parent_refusal), read in place of its own.""" try: - name, kits = str(obj.parent.get(KIT, "")), {} if kits is None else kits + parent = obj.parent if parent is STANDS else parent + name, kits = str(parent.get(KIT, "")), {} if kits is None else kits if name not in kits: kits[name] = core.load_kit(name) kit = kits[name] - socket_type = next(s["type"] for s in core.part(kit, str(obj.parent[PART]))["sockets"] if s["name"] == obj.get(PARENT_SOCKET)) + socket_type = next(s["type"] for s in core.part(kit, str(parent[PART]))["sockets"] if s["name"] == obj.get(PARENT_SOCKET)) return kit["socketTypes"][socket_type].get("dof"), socket_type except (AttributeError, KeyError, StopIteration, core.KitError): return None, None -def joint_record(obj, kits=None) -> dict: +def joint_record(obj, kits=None, parent=STANDS) -> dict: """The joint record a child's connection states, {limits: (lo, hi) or None, mechanism, compliance, follows}: degrees of its roll on a revolute joint, metres of its slide on a prismatic one; follows is None or {driver (the object, None once it is gone, as closure's other part), kind 'ratio' | 'loop', k, offset}. Every report, the joints report, the poses and hose read it here. A value written by hand that write_connections would not have written reads None: one that is not of its shape, and one record_refusal refuses for this connection's DOF kind (a compliance on a - revolute joint), so no report emits it and the next write clears it.""" + revolute joint), so no report emits it and the next write clears it. `parent` is connection_kind's.""" lo, hi, label, spring, follows = obj.get(LIMIT_MIN), obj.get(LIMIT_MAX), obj.get(MECHANISM), None, None with contextlib.suppress(ValueError, TypeError): spring = json.loads(obj.get(COMPLIANCE, "null")) @@ -259,7 +263,7 @@ def joint_record(obj, kits=None) -> dict: "follows": {"driver": driver if isinstance(driver, bpy.types.Object) and driver.users_collection else None, "kind": follows["kind"], "k": float(follows["k"]) if ratio else None, "offset": float(follows["offset"]) if ratio else None} if ratio or follows == {"kind": "loop"} else None} - kind, socket_type = connection_kind(obj, kits) + kind, socket_type = connection_kind(obj, kits, parent) for field in ("limits", "mechanism", "compliance", "follows"): # limits first: a compliance is read beside the limits that stand alone = {**dict.fromkeys(record), "limits": record["limits"] if field == "compliance" else None, field: record[field]} if record[field] is not None and record_refusal(kind, socket_type, alone) is not None: @@ -390,16 +394,24 @@ def connection_checks(entries) -> list: return checked +def write_checks(entries) -> list: + """Every check a write of `entries` must pass, and what it writes (connection_checks): each entry's own, then + the one-driver rule over the scene as the entries would leave it (one_driver). write_connections asks before + it writes; set_params asks before it rebuilds a mesh, so each refusal leaves the scene as it stood.""" + checked = connection_checks(entries) + one_driver({child: (parent, kind, record) for child, parent, _, _, _, _, _, kind, record in checked}) + return checked + + def write_connections(entries) -> None: """State connections and seat them, all or none: each child's parent, its derived matrix_basis, its three properties and its joint record, kit_follows and its driver pointer with it. Every entry is checked - (connection_checks) before any is written, so one refusal leaves every part as it stood. attach, set_params, + (write_checks) before any is written, so one refusal leaves every part as it stood. attach, set_params, roll, aim, reach, slide, joint and follow write a connection here and nowhere else, so what a joint record may - be, and that a follower's value is written with its driver's, is decided here. So is the one-driver rule: the - scene as these entries would leave it is read by one_driver before any is written, whatever the action.""" - checked = connection_checks(entries) - one_driver({child: (parent, kind, record) for child, parent, _, _, _, _, _, kind, record in checked}) - for child, parent, sockets, socket, parent_socket, roll, slide, kind, record in checked: + be, and that a follower's value is written with its driver's, is decided here. So is the one-driver rule: + write_checks reads the scene as these entries would leave it (one_driver) before any is written, whatever the + action.""" + for child, parent, sockets, socket, parent_socket, roll, slide, kind, record in write_checks(entries): child.parent = parent seat(child, core.mate(*sockets, roll, slide)) child[SOCKET], child[PARENT_SOCKET], child[ROLL] = socket, parent_socket, roll @@ -441,9 +453,11 @@ def one_driver(stating: dict) -> None: follows nothing and has travel, is a second driver: a pose of it would open the loop, so the write is refused naming the loop's driver and each other one. A joint both ends hang from moves them together and is not counted. A loop whose driver is gone or states no DOF connection is derived by nothing and is not read; it is - read again by the attach that gives the driver a connection. write_connections and detach ask here before - they write, so no action (attach, detach, clearing a follower, limits widened or cleared, any pose, a new - follow) leaves a loop with two drivers, and a scene edited by hand into one is refused its next write.""" + read again by the attach that gives the driver a connection. write_checks (every write of a connection, + and set_params before it rebuilds a mesh), detach and parent_refusal (Brokkr's setObjectParent) ask here + before they write, so no action (attach, detach, clearing a follower, limits widened or cleared, any pose, a + new follow, set_params, a new parent) leaves a loop with two drivers, and a scene edited by hand into one is + refused its next write.""" known, kits = {}, {} # each part's joint and each kit file are read once def parent(o): @@ -484,6 +498,20 @@ def one_driver(stating: dict) -> None: f"limits of one value. Give it that first, or clear the loop (brokkr_kitbash.follow on {closing.name!r} with record null); nothing changed.") +def brokkr_parent_refusal(obj, parent) -> str | None: + """Why an object may not be given `parent` (None clears it), or None when it may: the one-driver rule over the + scene as it would stand, the object's stated connection read on its new parent. Brokkr's setObjectParent asks + every enabled add-on that defines this name before it writes a parent, so a new parent that would give a + stated loop a second driver is refused there and then. Nothing else is asked: a parent that only leaves a + connection not holding is drift, and reports show it.""" + kind = connection_kind(obj, None, parent)[0] if SOCKET in obj else None + try: + one_driver({obj: (parent, kind, joint_record(obj, None, parent) if kind is not None else None)}) + except (Refused, core.KitError) as error: + return str(error) + return None + + def loop_pair(obj, stating=None): """(the parent follower, the closing follower) of the loop a loop follower is one of, or None when it has no partner. The closing follower states the closure and its parent is the other: both follow one driver as a @@ -987,7 +1015,8 @@ class BROKKR_KITBASH_OT_set_params(PolishOperator): """Change params of a placed kit part and rebuild its mesh in place: its modifiers and material slots stay, each shape keeps its faces' material, the Bevel width follows, and its connection and those of the parts attached to it are seated again on the moved sockets, through write_connections (a value outside its joint's - limits or a stray slide, written by hand, is refused before anything changes); a closure is never seated and a + limits or a stray slide, written by hand, and a scene that holds a loop with a second driver, are refused + before anything changes); a closure is never seated and a follower never derived again, only reported""" bl_idname = "brokkr_kitbash.set_params" bl_label = "Set Kit Part Params" @@ -1015,7 +1044,7 @@ class BROKKR_KITBASH_OT_set_params(PolishOperator): for child in attached(obj): child_part, child_built = built_part(child) entries.append((child, obj, mated(obj, part, built, child, child_part, child_built, link(child)), link(child), None)) - connection_checks(entries) + write_checks(entries) # every refusal write_connections has, the one-driver rule with them, before the mesh is rebuilt try: old = core.build(part, stored) except core.KitError: # stored params an edited kit no longer admits: nothing to map faces by diff --git a/surfaces/blender/brokkr_kitbash/core.py b/surfaces/blender/brokkr_kitbash/core.py index b1ddab5..92ed5eb 100644 --- a/surfaces/blender/brokkr_kitbash/core.py +++ b/surfaces/blender/brokkr_kitbash/core.py @@ -1674,7 +1674,8 @@ def joint_rows(root_world, entries) -> tuple[list, int]: parent's 4x4 world, DOF kind or None for rigid, value, joint record, driven: what the report says drives it, or None). A row is a revolute or prismatic connection; its parent is the nearest one above it (a rigid connection belongs to the joint above it), its axis and origin the parent socket's z and origin in the frame of root_world, - and min and max what the limits leave of the value either way.""" + min and max what the limits leave of the value either way, and held whether the limits are of one value: a + joint with no travel, which is no degree of freedom (the one-driver rule's held pin).""" frame, nearest, rows, rigid = np.linalg.inv(np.asarray(root_world, dtype=np.float64)), {}, [], 0 for name, parent, part_name, socket, parent_world, kind, value, record, driven in entries: if kind is None: @@ -1685,6 +1686,7 @@ def joint_rows(root_world, entries) -> tuple[list, int]: rows.append({"id": name, "parent": nearest.get(parent), "part": part_name, "socket": f"{parent}:{socket['name']}", "kind": kind, "axis": [round(float(v), 6) for v in at[:3, 2]], "origin": [round(float(v), 6) for v in at[:3, 3]], "value": round(value, 6), "limits": limits, "min": limits and round(record["limits"][0] - value, 6), "max": limits and round(record["limits"][1] - value, 6), + "held": limits is not None and record["limits"][0] == record["limits"][1], "mechanism": record["mechanism"], "compliance": record["compliance"], "driven": driven}) nearest[name] = name return rows, rigid diff --git a/surfaces/blender/tests/live/kitbash_follows.py b/surfaces/blender/tests/live/kitbash_follows.py index 7b2cb9e..7d04ea1 100644 --- a/surfaces/blender/tests/live/kitbash_follows.py +++ b/surfaces/blender/tests/live/kitbash_follows.py @@ -472,13 +472,19 @@ try: refused("a pose of the driver after the lug's limits were widened by hand: the writer reads the rule before it writes", "brokkr_kitbash.slide", {"object_name": "T_Rod", "slide": 0.1}, "depend on more than one driver: 'T_Rod' and 'T_Lug' (it follows nothing and its joint has travel") refused("and a pose of the lug itself", "brokkr_kitbash.roll", {"object_name": "T_Lug", "roll": 95.0}, "depend on more than one driver: 'T_Rod' and 'T_Lug'") + shape = lambda: {name: np.array([v.co[:] for v in bpy.data.objects[name].data.vertices]).tobytes() for name in ("Idle", "Tip")} # noqa: E731 + was, tip_was = shape(), connection("Tip") + refused("set_params of an unrelated part in a scene that holds a second driver (finding set-params-writes-before-the-guard): the rule is read before the mesh is rebuilt", + "brokkr_kitbash.set_params", {"object_name": "Idle", "params": "length=0.6"}, + "the two ends of the loop 'T_Lower' closes, 'T_Barrel' (the base) and 'T_Lug' (closed on), depend on more than one driver: 'T_Rod' and 'T_Lug' (it follows nothing and its joint has travel", "nothing changed") + check("and nothing moved: the part's vertices and its child's connection read as before the refusal", shape() == was and connection("Tip") == tip_was and tip_was["holds"] is True, [tip_was, connection("Tip")]) t_lug["kit_min"], t_lug["kit_max"] = 90.0, 90.0 receipt, report = send("brokkr_kitbash.slide", object_name="T_Rod", slide=0.11) check("with the lug held again the driver is posed", receipt["status"] == "accepted" and report["closures"][0]["holds"] is True, receipt["message"]) receipt, joints = send("brokkr_kitbash.joints", object_name="T_Barrel") - check("the torque link has one degree of freedom: the rod's slide is its one row with travel that nothing drives, the lug has none, the arms are driven, and no row is unlimited", - receipt["status"] == "accepted" and [(row["id"], row["kind"], row["driven"] and row["driven"]["by"], row["min"], row["max"]) for row in joints["joints"]] == [ - ("T_Rod", "prismatic", None, -0.11, 0.19), ("T_Lug", "revolute", None, 0.0, 0.0), ("T_Upper", "revolute", "T_Rod", None, None), ("T_Lower", "revolute", "T_Rod", None, None)] + check("the torque link has one degree of freedom: the rod's slide is its one row with travel that nothing drives, the lug is its one held row, the arms are driven, and no row is unlimited", + receipt["status"] == "accepted" and [(row["id"], row["kind"], row["driven"] and row["driven"]["by"], row["min"], row["max"], row["held"]) for row in joints["joints"]] == [ + ("T_Rod", "prismatic", None, -0.11, 0.19, False), ("T_Lug", "revolute", None, 0.0, 0.0, True), ("T_Upper", "revolute", "T_Rod", None, None, False), ("T_Lower", "revolute", "T_Rod", None, None, False)] and joints["unlimited"] == [] and reading("closed", apart(t_lower, "end_b", t_lug, "end_b")) < CLOSED, [receipt["message"], joints]) place("T_Mount", "strut", W, far @ far @ far @ far @ turn) hinged = attach("T_Barrel", "base", "T_Mount", "end_a", 25.0) @@ -493,6 +499,18 @@ try: {"object_name": "T_Lug"}, "the two ends of the loop 'T_Lower' closes, 'T_Barrel' (the base) and 'T_Lug' (closed on), depend on more than one driver: 'T_Rod' and 'T_Barrel' (it follows nothing and its joint has travel") + refused("setObjectParent clearing the lug's parent (finding bridge-reparent-bypasses-the-guard): Brokkr's own row asks the same rule before it writes a parent", "setObjectParent", + {"targetObjectName": "T_Lug", "parentObjectName": ""}, + "the two ends of the loop 'T_Lower' closes, 'T_Barrel' (the base) and 'T_Lug' (closed on), depend on more than one driver: 'T_Rod' and 'T_Barrel' (it follows nothing and its joint has travel", "nothing changed") + refused("setObjectParent of a root onto a part on a free pin: with the four-bar's base under Idle, the rocker the ram closes on depends on Idle's roll", "setObjectParent", + {"targetObjectName": "Base", "parentObjectName": "Idle"}, + "the two ends of the loop 'A_Rod' closes, 'Pad' (the base) and 'Rocker' (closed on), depend on more than one driver: 'Crank' and 'Idle' (it follows nothing and its joint has travel", "nothing changed") + receipt, _ = send("setObjectParent", targetObjectName="Loose", parentObjectName="Idle") + under = bpy.data.objects["Loose"].parent + receipt2, _ = send("setObjectParent", targetObjectName="Loose", parentObjectName="") + check("setObjectParent of a part no loop depends on is written as before, and cleared again", receipt["status"] == "accepted" and under == bpy.data.objects["Idle"] + and receipt2["status"] == "accepted" and bpy.data.objects["Loose"].parent is None, [receipt["message"], receipt2["message"]]) + # --- joints, version 2 ---------------------------------------------------------------------------------------------------------- receipt, joints = send("brokkr_kitbash.joints", object_name="Ground") table = {row["id"]: row for row in (joints or {}).get("joints", [])} diff --git a/surfaces/blender/tests/live/kitbash_follows.result.json b/surfaces/blender/tests/live/kitbash_follows.result.json index a8434ac..7ffc432 100644 --- a/surfaces/blender/tests/live/kitbash_follows.result.json +++ b/surfaces/blender/tests/live/kitbash_follows.result.json @@ -321,13 +321,23 @@ "ok": true, "detail": null }, + { + "name": "refused, scene unchanged: set_params of an unrelated part in a scene that holds a second driver (finding set-params-writes-before-the-guard): the rule is read before the mesh is rebuilt", + "ok": true, + "detail": null + }, + { + "name": "and nothing moved: the part's vertices and its child's connection read as before the refusal", + "ok": true, + "detail": null + }, { "name": "with the lug held again the driver is posed", "ok": true, "detail": null }, { - "name": "the torque link has one degree of freedom: the rod's slide is its one row with travel that nothing drives, the lug has none, the arms are driven, and no row is unlimited", + "name": "the torque link has one degree of freedom: the rod's slide is its one row with travel that nothing drives, the lug is its one held row, the arms are driven, and no row is unlimited", "ok": true, "detail": null }, @@ -341,6 +351,21 @@ "ok": true, "detail": null }, + { + "name": "refused, scene unchanged: setObjectParent clearing the lug's parent (finding bridge-reparent-bypasses-the-guard): Brokkr's own row asks the same rule before it writes a parent", + "ok": true, + "detail": null + }, + { + "name": "refused, scene unchanged: setObjectParent of a root onto a part on a free pin: with the four-bar's base under Idle, the rocker the ram closes on depends on Idle's roll", + "ok": true, + "detail": null + }, + { + "name": "setObjectParent of a part no loop depends on is written as before, and cleared again", + "ok": true, + "detail": null + }, { "name": "joints is version 2: a driven row names what drives it (F6), and unlimited lists the rows that are not driven and state no limits", "ok": true, @@ -434,7 +459,7 @@ "ram solved at 45": 0.0, "ram solved at 60": 0.0, "ratio": 0.0, - "rows in the first receipt": 33.0, + "rows in the first receipt": 32.0, "slid": 1e-07, "solved": 3.3e-05 }, diff --git a/surfaces/blender/tests/live/kitbash_pose.result.json b/surfaces/blender/tests/live/kitbash_pose.result.json index 3091443..50ea94b 100644 --- a/surfaces/blender/tests/live/kitbash_pose.result.json +++ b/surfaces/blender/tests/live/kitbash_pose.result.json @@ -528,6 +528,7 @@ ], "min": -3.000003, "max": 72.999997, + "held": false, "mechanism": "knee", "compliance": null, "driven": null @@ -552,6 +553,7 @@ "limits": null, "min": null, "max": null, + "held": false, "mechanism": null, "compliance": null, "driven": null @@ -579,6 +581,7 @@ ], "min": -0.12, "max": 0.18, + "held": false, "mechanism": "shock", "compliance": { "damping_ratio": 0.7, @@ -609,6 +612,7 @@ ], "min": -75.0, "max": 35.0, + "held": false, "mechanism": "ankle", "compliance": null, "driven": null @@ -633,6 +637,7 @@ "limits": null, "min": null, "max": null, + "held": false, "mechanism": null, "compliance": null, "driven": null @@ -657,6 +662,7 @@ "limits": null, "min": null, "max": null, + "held": false, "mechanism": null, "compliance": null, "driven": null diff --git a/surfaces/blender/tests/test_kitbash.py b/surfaces/blender/tests/test_kitbash.py index fe1cfeb..02aa454 100644 --- a/surfaces/blender/tests/test_kitbash.py +++ b/surfaces/blender/tests/test_kitbash.py @@ -1617,6 +1617,9 @@ class JointRecordTests(unittest.TestCase): [("Barrel", None, "revolute", "Root:end_b"), ("Rod", "Barrel", "prismatic", "Plate:bore")]) self.assertEqual((rows[0]["value"], rows[0]["limits"], rows[0]["min"], rows[0]["max"], rows[0]["mechanism"], rows[0]["driven"]), (30.0, [-20.0, 60.0], -50.0, 30.0, "elbow", None)) self.assertEqual((rows[1]["value"], rows[1]["limits"], rows[1]["min"], rows[1]["max"], rows[1]["driven"]["by"]), (0.125, None, None, None, "Barrel")) + self.assertEqual([row["held"] for row in rows], [False, False]) + (held,), _ = core.joint_rows(root, [("Lug", "Root", "strut", socket(strut, "end_b"), root, "revolute", 90.0, {**free, "limits": (90.0, 90.0)}, None)]) + self.assertEqual((held["limits"], held["min"], held["max"], held["held"]), ([90.0, 90.0], 0.0, 0.0, True)) # limits of one value: no travel, and the row says so pin = socket(strut, "end_b")["matrix"] self.assertEqual((rows[0]["axis"], rows[0]["origin"]), ([round(float(v), 6) for v in pin[:3, 2]], [round(float(v), 6) for v in pin[:3, 3]])) # in the root's frame: the socket as the part has it bore = core.mate(socket(strut, "end_b"), socket(barrel, "base"), 30.0) @ socket(barrel, "bore")["matrix"] @@ -2530,20 +2533,26 @@ class OwnershipTests(unittest.TestCase): self.assertIsNone(re.search(r"seat\(seated|driver_add\(|constraints\.new\(", source)) self.assertEqual(source.count("seat("), 5) # its def, write_connections, and a cutter's, a ribs' and a hose's own frames body = source.split("class BROKKR_KITBASH_OT_set_params(")[1].split("class BROKKR_KITBASH_OT_")[0] - self.assertLess(body.index("connection_checks(entries)"), body.index("clear_geometry()")) + self.assertLess(body.index("write_checks(entries)"), body.index("clear_geometry()")) # the writer's own checks, the one-driver rule with them (live: 'set_params of an unrelated part in a scene that holds a second driver') + self.assertLess(body.index("write_checks(entries)"), body.index("obj[PARAMS] =")) self.assertLess(body.index("clear_geometry()"), body.index("write_connections(entries)")) self.assertEqual(source.count("core.close_loop("), 1) self.assertIn("core.close_loop(", source.split("\ndef driven(")[1].split("\n\n\n")[0]) self.assertEqual(source.count("write_connections(["), 2) # write_connection, and follow clearing a statement # every entry is checked before one is written (mutant J5, a refusal raised after the writes; F5 is its live twin): the writer's loop runs over the # checks' whole answer and raises nothing itself, and the checks write nothing - self.assertIn(" checked = connection_checks(entries)\n one_driver({child: (parent, kind, record) for child, parent, _, _, _, _, _, kind, record in checked})\n" - " for child, parent, sockets, socket, parent_socket, roll, slide, kind, record in checked:\n child.parent = parent\n", writer) + self.assertIn(" for child, parent, sockets, socket, parent_socket, roll, slide, kind, record in write_checks(entries):\n child.parent = parent\n", writer) + asked = source.split("\ndef write_checks(")[1].split("\n\n\n")[0] + self.assertIn(" checked = connection_checks(entries)\n one_driver({child: (parent, kind, record) for child, parent, _, _, _, _, _, kind, record in checked})\n return checked", asked) self.assertNotIn("raise ", writer) - # the one-driver rule has one owner, asked by the one writer and by detach before either writes, and it writes nothing: no action states its own - # copy (live: an attach, a clear, widened limits, a pose and a detach after the loop is stated are each refused) + # the one-driver rule has one owner, asked by write_checks (the one writer, and set_params before its mesh), by detach and by + # brokkr_parent_refusal (Brokkr's setObjectParent) before any writes, and it writes nothing: no action states its own copy (live: an attach, a + # clear, widened limits, a pose, a set_params, a detach and a new parent after the loop is stated are each refused) rule = source.split("\ndef one_driver(")[1].split("\n\n\n")[0] - self.assertEqual((source.count("one_driver("), source.count("depend on more than one driver")), (3, 1)) + self.assertEqual((source.count("one_driver("), source.count("depend on more than one driver")), (4, 1)) + asker = source.split("\ndef brokkr_parent_refusal(")[1].split("\n\n\n")[0] + self.assertIn("one_driver({obj: (parent, kind,", asker) + self.assertIsNone(re.search(r"\.parent\s*=(?!=)|\bseat\(|\w+\[\w+\]\s*=(?!=)|\bdel ", asker + asked)) self.assertIsNone(re.search(r"\.parent\s*=(?!=)|\bseat\(|\w+\[[A-Z_]+\]\s*=(?!=)|\bdel ", rule)) detach = source.split("class BROKKR_KITBASH_OT_detach(")[1].split("class BROKKR_KITBASH_OT_")[0] self.assertLess(detach.index("one_driver("), detach.index("obj.parent = None"))