diff --git a/CHANGELOG.md b/CHANGELOG.md index 73b097f..b52193e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,26 @@ Newest first. Versions follow `pyproject.toml`; a tag `vX.Y.Z` publishes the add-on zip. +## 0.1.2 - 2026-11-05 + +### Fixed + +- **The 4D back buttons step back.** After "next event", the -1 day and + -7 day buttons jumped forward to the next event: Blender gave each + button the step operator's last-used `event`. The step's properties are + no longer remembered, and each button sets both. + +Ported from BIMForge (its fix for this project's PR #1 review): + +- **Ground still to dig draws its edges beyond the cut.** Before the dig + date, the visible edges beyond a section or elevation now show the ground + as it stands, not the ground with its hole already dug. When every void + of a host is still to dig, the host is drawn uncut beyond the plane. A + ground solid that its cut removes entirely, lying behind the plane, no + longer vanishes from the pre-dig view. A host with some voids already + dug is drawn as before, with all of its voids. Ground that is not + standing at the date (placed later, or already removed) restores nothing. + ## 0.1.1 - 2026-11-05 ### Fixed diff --git a/pyproject.toml b/pyproject.toml index de29735..162dafb 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta" [project] name = "ifcsection" -version = "0.1.1" +version = "0.1.2" description = "Cross sections and developed elevations along an IFC alignment: a Blender (Bonsai) add-on and the Python it carries" readme = "README.md" license = "Apache-2.0" diff --git a/src/ifcsection/__init__.py b/src/ifcsection/__init__.py index 11bf5d2..396ca96 100644 --- a/src/ifcsection/__init__.py +++ b/src/ifcsection/__init__.py @@ -9,4 +9,4 @@ Importing the package does not import Blender. """ -__version__ = "0.1.1" +__version__ = "0.1.2" diff --git a/src/ifcsection/addon.py b/src/ifcsection/addon.py index 40d4cdf..c5ae2e5 100644 --- a/src/ifcsection/addon.py +++ b/src/ifcsection/addon.py @@ -42,7 +42,7 @@ bl_info = { "name": "IfcSection", "author": "Brandon Lewis", - "version": (0, 1, 1), + "version": (0, 1, 2), "blender": (4, 2, 0), "location": "View3D > Sidebar > Section", "description": "Sections and developed elevations along an IFC alignment", @@ -1518,8 +1518,12 @@ class IFCSECTION_OT_section_date_step(bpy.types.Operator): bl_label = "Step Date" bl_description = ("Move the 4D date by days, or to the previous / " "next day something appears or is removed") - days: bpy.props.IntProperty(default=1) - event: bpy.props.IntProperty(default=0) # -1 / +1: jump to event + # SKIP_SAVE: a panel button sets only one of the two, and Blender + # otherwise gives the other its LAST value - after "next event", a + # "-1 day" button would jump to the next event again + days: bpy.props.IntProperty(default=1, options={"SKIP_SAVE"}) + event: bpy.props.IntProperty(default=0, # -1 / +1: jump to event + options={"SKIP_SAVE"}) def execute(self, context): props = context.scene.ifcsection @@ -1645,16 +1649,15 @@ def draw(self, context): row.prop(props, "date_filter", text="") row.prop(props, "date", text="") row = dbox.row(align=True) - for icon, kw in (("PREV_KEYFRAME", {"event": -1}), - ("TRIA_LEFT", {"days": -7}), - ("REW", {"days": -1}), - ("FF", {"days": 1}), - ("TRIA_RIGHT", {"days": 7}), - ("NEXT_KEYFRAME", {"event": 1})): + for icon, event, days in (("PREV_KEYFRAME", -1, 0), + ("TRIA_LEFT", 0, -7), + ("REW", 0, -1), + ("FF", 0, 1), + ("TRIA_RIGHT", 0, 7), + ("NEXT_KEYFRAME", 1, 0)): op = row.operator("ifcsection.section_date_step", text="", icon=icon) - for k, v in kw.items(): - setattr(op, k, v) + op.event, op.days = event, days ev = _STATE["events"] dbox.label(text=f"schedule {ev[0]} to {ev[-1]}") c = _STATE["counts"] diff --git a/src/ifcsection/developed.py b/src/ifcsection/developed.py index 717edd5..be0d272 100644 --- a/src/ifcsection/developed.py +++ b/src/ifcsection/developed.py @@ -181,7 +181,7 @@ def _all_bodies(f, date): hosts = [r.RelatingBuildingElement for r in getattr(el, "VoidsElements", None) or ()] undug.append((el.Name or el.is_a(), - hosts[0] if hosts else None, v, t)) + hosts[0] if hosts else None, v, t, el.id())) elif (el.is_a("IfcElement") and len(t) and not (spans is not None and not standing(spans.get(el.GlobalId), date))): @@ -208,20 +208,25 @@ def _all_bodies(f, date): pt = t if sel is None else t[sel] ptr = tri_rgb if sel is None else [prgb[0]] * len(pt) layer, ptr = _cut_layer(el, pmat, pm, prgb, ptr) - out.append((el.Name or el.is_a(), layer, - (not solid) and _is_surface(v, pt), v, pt, ptr)) + surf = bool((not solid) and _is_surface(v, pt)) + if getattr(el, "HasOpenings", None): + surf = Voided(surf, el.id()) + out.append((el.Name or el.is_a(), layer, surf, v, pt, ptr)) if not it.next(): break host_style = {name: (layer, trgb[0]) for name, layer, surf, _v, _t, trgb in out if surf is not LIMIT and trgb} gross = {} - for name, host, v, t in undug: + undug_ids = {i for *_x, i in undug} + for name, host, v, t, _id in undug: layer, rgb = host_style.get(host.Name if host is not None else None, (_layer_name("Earthwork"), (0.56, 0.44, 0.30))) if host is None: # a pay-item body is the soil itself: restore it whole out.append((f"{name} (not yet dug)", layer, False, v, t, [rgb] * len(t))) continue + if spans is not None and not standing(spans.get(host.GlobalId), date): + continue # no ground there yet, or none left # a cut can reach past its host (over grade, as an opening runs past # its wall): restore only what lies in the host's UNCUT body if host.id() not in gross: @@ -229,7 +234,12 @@ def _all_bodies(f, date): if hv is None: continue gross[host.id()] = True - out.append((host.Name, None, Clip(host.id()), hv, ht, [rgb] * len(ht))) + # every void still to dig: the uncut host IS the ground before + # the dig, and draws beyond the cut in the voided host's place + whole = all(r.RelatedOpeningElement.id() in undug_ids + for r in host.HasOpenings or ()) + out.append((host.Name, None, Clip(host.id(), whole), hv, ht, + [rgb] * len(ht))) out.append((f"{name} (not yet dug)", layer, Restore(host.id()), v, t, [rgb] * len(t))) _BODY_CACHE[key] = out @@ -256,8 +266,25 @@ def _named(f, m): class Clip(int): - """A body that is not drawn: a host's UNCUT shape, clipping the ground - restored in its voids (Restore) before they are dug.""" + """A host's UNCUT shape, clipping the ground restored in its voids + (Restore) before they are dug. Not cut; `whole` when every void of the + host is still to dig, and then drawn beyond the cut in place of the + voided host (Voided of the same host).""" + + def __new__(cls, host_id, whole=False): + c = super().__new__(cls, host_id) + c.whole = whole + return c + + +class Voided(int): + """The surface flag (0 or 1) of a body with voids, carrying its `host` + id: beyond the cut, a whole Clip of the same host draws in its place.""" + + def __new__(cls, surface, host): + v = super().__new__(cls, bool(surface)) + v.host = host + return v class Restore(int): @@ -340,9 +367,24 @@ def _extent(drawing) -> list: return zs -def _drawn(w) -> bool: - """A warped body whose edges beyond the cut are drawn.""" - return not (w[2] is LIMIT or isinstance(w[2], (Clip, Restore))) +def _beyond(warped) -> list: + """The warped bodies whose edges beyond the cut are drawn: not limits + or restored ground; before the dig, a host whose every void is still to + dig is drawn uncut (its whole Clip) in place of its voided body.""" + whole = {int(w[2]) for w in warped if isinstance(w[2], Clip) and w[2].whole} + + out = [] + for w in warped: + s = w[2] + if s is LIMIT or isinstance(s, Restore): + continue + if isinstance(s, Clip): + if s.whole: # a solid: its flag is a host id, not + out.append((*w[:2], False, *w[3:])) # a surface flag + continue + if not (isinstance(s, Voided) and s.host in whole): + out.append(w) + return out def is_excavation(el) -> bool: @@ -543,7 +585,7 @@ def to2d(u, z): # ---------------------------------------------------------------- cut _cut_into(drawing, warped, to2d) # ----------------------------------------------------- visible beyond - drawing.beyond = _visible_edges([w for w in warped if _drawn(w)], to2d, + drawing.beyond = _visible_edges(_beyond(warped), to2d, drawing, view, depth * k, k) # ---------------------------------------------------------- ticks drawing.ticks = _ticks(st, un, view, d0, d1, to2d, unit, k) @@ -599,7 +641,7 @@ def to2d(u, z): za + zb * v[:, 2], t[idx], [trgb[i] for i in idx], None)) drawing.elements = len(warped) _cut_into(drawing, warped, to2d) - drawing.beyond = _visible_edges([w for w in warped if _drawn(w)], to2d, + drawing.beyond = _visible_edges(_beyond(warped), to2d, drawing, view, depth * k, k) # an offset tick every whole unit: (x, offset left); looking ahead the # left is on the viewer's left diff --git a/tests/blender/test_alignment_section.py b/tests/blender/test_alignment_section.py index fcf06e5..e467a36 100644 --- a/tests/blender/test_alignment_section.py +++ b/tests/blender/test_alignment_section.py @@ -365,6 +365,11 @@ def test_the_date_filter_hides_what_is_not_built_and_skips_its_cut(addon): assert len(bpy.data.objects[mod.CUT].data.polygons) > 0 bpy.ops.ifcsection.section_date_step(days=-1) assert props.date == "2027-09-14" and not deck.visible_get() + # a panel button sets one of `event` / `days`; Blender gives an unset, + # saved property its LAST value, so after "next event" every back + # button jumped forward. Neither may be remembered. + rna = bpy.ops.ifcsection.section_date_step.get_rna_type().properties + assert rna["event"].is_skip_save and rna["days"].is_skip_save props.date_filter = False # everything back assert deck.visible_get() and not mod._STATE["hidden"] diff --git a/tests/test_developed.py b/tests/test_developed.py index 5bc75f0..bbc31b5 100644 --- a/tests/test_developed.py +++ b/tests/test_developed.py @@ -501,8 +501,9 @@ def _section_model(tmp_path, name, bodies): ctx = _ctx() al = Alignment(POB, RUN, name="ML") m = StructureModel(name, ctx) - for nm, ring, ifc, voids in bodies: - sw = SweptSection(nm, ring, al, 1010.0, 1100.0, origin=ctx, ifc=ifc) + for nm, ring, ifc, voids, *span in bodies: + s0, s1 = span[0] if span else (1010.0, 1100.0) + sw = SweptSection(nm, ring, al, s0, s1, origin=ctx, ifc=ifc) el = Element.from_geometry(nm, sw, ifc_class=ifc, quantities={"volume_cf": sw.volume_cf}) if voids: @@ -538,6 +539,41 @@ def test_restored_ground_stays_inside_its_host(tmp_path, monkeypatch): D._BODY_CACHE.clear() +@pytest.mark.skipif(not HAS_VOIDS, reason="needs BIMForge with Element.voids") +def test_ground_still_to_dig_draws_beyond_the_cut(tmp_path, monkeypatch): + """A ground solid wholly beyond the plane, all of it to be dug: before + the dig its edges are drawn beyond the cut (the host drawn uncut), after + it nothing is (PR #1 review).""" + from ifcsection import developed as D + from ifcsection import schedule_state as SS + box = lambda x0, x1, z0, z1: [(x0, z0), (x1, z0), (x1, z1), (x0, z1)] # noqa: E731 + f = _section_model(tmp_path, "behind", [ + ("existing ground", box(-20, 20, -12, 0), "IfcGeographicElement", None, + (1060.0, 1090.0)), + ("structure excavation", box(-21, 21, -13, 1), "IfcEarthworksCut", + "existing ground", (1055.0, 1095.0))]) + cut = f.by_type("IfcEarthworksCut")[0] + monkeypatch.setattr(SS, "element_spans", + lambda f: {cut.GlobalId: SS.Span("2027-01-10", None, ("dig",))}) + + def beyond(date): + D._BODY_CACHE.clear() + dr = cross_section(f, SectionView("S", 1050.0, width=50.0, depth=60.0, + date=date)) + assert not dr.cut # the plane misses the ground + return sum(math.dist(a, b) for ln in dr.beyond for a, b in zip(ln, ln[1:])) + # the near face of the ground, 40 x 12 ft, outlined + assert beyond("2027-01-05") == pytest.approx(2 * (40 + 12), rel=1e-2) + assert beyond("2027-01-12") == pytest.approx(0.0, abs=1e-6) + # ground not there at the date (placed later): nothing is restored + host = f.by_type("IfcGeographicElement")[0] + monkeypatch.setattr(SS, "element_spans", lambda f: { + cut.GlobalId: SS.Span("2027-01-10", None, ("dig",)), + host.GlobalId: SS.Span("2027-01-07", None, ("place",))}) + assert beyond("2027-01-05") == pytest.approx(0.0, abs=1e-6) + D._BODY_CACHE.clear() + + def test_the_extent_takes_in_the_limits_of_excavation(tmp_path): """A section of an excavation alone still frames its limit lines (PR #8 review), not a default band around grade."""