@floless/app 0.101.4 → 0.102.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/floless-server.cjs +192 -28
- package/dist/schemas/steel.takeoff.v1.schema.json +14 -1
- package/dist/web/app.css +11 -4
- package/dist/web/steel-editor.html +402 -21
- package/dist/web/workspaces.js +72 -17
- package/package.json +1 -1
|
@@ -392,6 +392,28 @@ text.mlentx{fill:#e2e8f0;text-anchor:middle;dominant-baseline:central;font-famil
|
|
|
392
392
|
line.dim.dimsel{stroke:#f59e0b;stroke-width:2} line.dimwit.dimsel{stroke:#f59e0b;opacity:1} rect.dimchip.dimsel{stroke:#f59e0b}
|
|
393
393
|
circle.dimend.dimsel,path.dimend.dimsel{fill:#f59e0b} line.dimend.dimsel{stroke:#f59e0b}
|
|
394
394
|
circle.dimhandle{fill:#22d3ee;stroke:#0b1220;stroke-width:2;cursor:grab}
|
|
395
|
+
body.qdpick #svg{cursor:crosshair} /* F7 grid quick-dim: the armed one-shot row-station pick */
|
|
396
|
+
/* F8 double-click value editor — a small themed popover over the canvas (dark panel, cyan dim accent). */
|
|
397
|
+
#dimEditPop{position:fixed;z-index:60;transform:translateX(-50%);background:var(--panel);border:1px solid var(--line);border-radius:8px;box-shadow:0 6px 20px rgba(0,0,0,.5);padding:8px;display:flex;flex-direction:column;gap:6px;min-width:132px}
|
|
398
|
+
#dimEditPop #dimEditVal{background:#0b1220;border:1px solid #22d3ee;color:var(--text);border-radius:5px;padding:5px 8px;font:13px/1.2 ui-monospace,SFMono-Regular,Menlo,monospace;text-align:center;outline:none;width:100%;box-sizing:border-box}
|
|
399
|
+
#dimEditPop #dimEditVal:focus{box-shadow:0 0 0 2px rgba(34,211,238,.25)}
|
|
400
|
+
#dimEditPop #dimEditVal.bad{border-color:#f87171;box-shadow:0 0 0 2px rgba(248,113,113,.25)}
|
|
401
|
+
#dimEditPop .dimEditRow{display:flex;gap:6px;justify-content:center}
|
|
402
|
+
#dimEditPop .dimEditTog{background:transparent;border:1px solid var(--line);color:var(--mut);border-radius:5px;cursor:pointer;display:inline-flex;align-items:center;justify-content:center;min-width:32px;height:24px;padding:0 9px} /* inline-SVG glyphs (crisp at any DPI) centered in a fixed hit target */
|
|
403
|
+
/* the dim inspector's "Pinned to member" slider — same .mck switch as the ⋯ Display rows, panel-scoped */
|
|
404
|
+
#panel button.pintog{display:flex;align-items:center;background:transparent;border:none;color:var(--mut);cursor:pointer;padding:2px 0;font:12px system-ui;gap:0;text-align:left}
|
|
405
|
+
#panel button.pintog.on{color:var(--text)}
|
|
406
|
+
#panel .pintog .mck{position:relative;width:26px;height:14px;margin-right:9px;border-radius:7px;border:1px solid var(--line);background:#0b1220;flex:none;transition:background-color .15s,border-color .15s}
|
|
407
|
+
#panel .pintog .mck::after{content:'';position:absolute;top:1px;left:1px;width:10px;height:10px;border-radius:50%;background:var(--mut);transition:transform .15s,background-color .15s}
|
|
408
|
+
#panel .pintog.on .mck{background:rgba(59,130,246,.28);border-color:var(--brand)}
|
|
409
|
+
#panel .pintog.on .mck::after{transform:translateX(12px);background:var(--brand)}
|
|
410
|
+
#panel .pintog svg{margin-right:4px;color:#22d3ee;flex:none} /* the pin glyph carries the dim accent, matching the on-canvas markers */
|
|
411
|
+
#panel .pintog:focus-visible{outline:2px solid var(--brand);outline-offset:2px}
|
|
412
|
+
#dimEditPop .dimEditTog:hover{border-color:var(--brand);color:var(--text)}
|
|
413
|
+
#dimEditPop .dimEditTog.on{border-color:var(--brand);background:rgba(59,130,246,.18);color:var(--text)}
|
|
414
|
+
#dimEditPop .dimEditTog.pin.on{border-color:#22d3ee;background:rgba(34,211,238,.16);color:var(--text)}
|
|
415
|
+
#dimEditPop .dimEditTog:focus-visible{outline:2px solid var(--brand);outline-offset:2px}
|
|
416
|
+
#dimEditPop .dimEditHint{font-size:10px;color:var(--mut);text-align:center}
|
|
395
417
|
/* The Dimension style pane's live preview of the CURRENT combination — the only place Ends × Label ×
|
|
396
418
|
Background interact (the on-line gap appears only with the background off). It renders through the real
|
|
397
419
|
dimSvg, so it inherits the canvas classes above, whose lines/chips are clickable. Neutralise them:
|
|
@@ -1237,6 +1259,9 @@ C.member_styles=sanitizeMemberStyles(C.member_styles); // F5: clamp the loaded
|
|
|
1237
1259
|
let P, X0,Y0,X1,Y1, FT, RB64, EXTX, EXTY, profs; // per-plan, set by setPlan()
|
|
1238
1260
|
let mode='sel', drag=null, picking=false, pickKind='profile', pickEnd=null, geoMode=null;
|
|
1239
1261
|
let dimMode=false, dimDraft=null, dimAxis='free', selDimIds=new Set(), dimsVisible=true; // Dimension tool: armed flag, in-progress {a,b,axis}, sticky axis, selected dim ids (multi-select), show/hide
|
|
1262
|
+
let qdAnchorPt=(()=>{try{const v=localStorage.getItem('steel:qdAnchor:v1');return (v==='a'||v==='b'||v==='mid')?v:'a';}catch(_){return 'a';}})(); // F7 quick-dim: which point on each beam to space between (start/mid/end), persisted
|
|
1263
|
+
let dimEdit=null; // F8: the open double-click value editor {id,l,r,pin} or null (a modal popup)
|
|
1264
|
+
let _lastDimDown=null; // F8: {id,t} of the last dim pointerdown, for manual double-click detection
|
|
1240
1265
|
let drawDraft=null; // Add-member tool: the first CLICKED start point (or null) — click-to-start / click-to-finish, mirroring the Dimension tool (no more press-drag)
|
|
1241
1266
|
let calloutsVisible=true; // Workstream B: show/hide the clickable callout bubbles (details + section/elevation/detail-ref) on the plan in select mode
|
|
1242
1267
|
let showSelLen=(()=>{try{return localStorage.getItem('steel:selLen:v1')==='1';}catch(_){return false;}})(); // ⋯ Display → Show member length: paint each selected member's length on the canvas (opt-in, default off)
|
|
@@ -1259,6 +1284,7 @@ let undo=[], redo=[];
|
|
|
1259
1284
|
const allMembers=()=>C.plans.flatMap(p=>p.members||[]);
|
|
1260
1285
|
const byId=id=>{for(const p of C.plans){const m=(p.members||[]).find(x=>x.id===id);if(m)return m;}return undefined;};
|
|
1261
1286
|
const planeOf=id=>{for(const p of C.plans)if((p.members||[]).some(m=>m.id===id))return p;return P;}; // the plane that owns a member id (for cross-sheet move/copy targeting); falls back to the active plane
|
|
1287
|
+
const planeOfMember=m=>{for(const p of C.plans)if((p.members||[]).includes(m))return p;return null;}; // F9: owning plane by OBJECT IDENTITY (member ids are only sheet-unique — id lookup could hit the wrong sheet on a collision; Codex code-review #1)
|
|
1262
1288
|
const selArr=()=>allMembers().filter(m=>selIds.has(m.id));
|
|
1263
1289
|
// The active-sheet subset of the selection — for 2D coordinate/decoration ops (handles, badges, move/copy,
|
|
1264
1290
|
// 2D drag/zoom) that draw or compute in THIS sheet's px space, where an off-sheet member's wp is meaningless.
|
|
@@ -1318,6 +1344,9 @@ function swapMemberEnds(m){
|
|
|
1318
1344
|
// symbol is drawn on. Negate the offset to keep the drawn line exactly where it was (ui-ux review).
|
|
1319
1345
|
if(m.brace.offset)m.brace.offset=-m.brace.offset;
|
|
1320
1346
|
}
|
|
1347
|
+
// F9: reversing swaps m's two physical points, so a dim ref's pt 'a'↔'b' must swap to keep pointing at the same
|
|
1348
|
+
// real end. Plan-scoped by member identity — only THIS member's owning plan's dims (never by id across plans, Codex R4 #4).
|
|
1349
|
+
{const own=planeOfMember(m);for(const d of (own&&own.dims||[]))for(const rk of ['aRef','bRef']){const r=d[rk];if(r&&r.m===m.id&&(r.pt==='a'||r.pt==='b'))r.pt=r.pt==='a'?'b':'a';}}
|
|
1321
1350
|
return m;}
|
|
1322
1351
|
// Bulk "Swap start ↔ end" (multi-select button + the P shortcut). Braces are EXCLUDED: reversing a brace is
|
|
1323
1352
|
// the inspector's "Swap lower ↔ higher end" (arrow assignment, no geometry move). (ui-ux + Codex review: the
|
|
@@ -1373,6 +1402,12 @@ function braceDisplayLine(m){const a=m.wp[0],b=m.wp[1];
|
|
|
1373
1402
|
// straight through into the geometry). (Lengths shown stay TRUE 3D via _lenFt; a parallel offset preserves
|
|
1374
1403
|
// plan length, so the PLABEL_MIN_PX thresholds agree either way.)
|
|
1375
1404
|
function memberViewLine(m){return isBrace(m)?braceDisplayLine(m):[[m.wp[0][0],m.wp[0][1]],[m.wp[1][0],m.wp[1][1]]];}
|
|
1405
|
+
// F9 magnetic dims: which members a dimension endpoint may anchor to — beams AND columns (a column anchors at
|
|
1406
|
+
// its single plan point; QA 2026-07-16 extended the original beams-only cut), but NEVER braces (a brace carries
|
|
1407
|
+
// role 'beam' and is excluded; its braceDisplayLine also reads the globally-active plan's scale, unsafe when
|
|
1408
|
+
// reanchoring a non-active sheet). One shared predicate used by F7 + sanitizeDims + resolveDimAnchor so the
|
|
1409
|
+
// checks can never drift (Codex R3 #5).
|
|
1410
|
+
const isDimAnchorableMember=m=>!!m&&!isBrace(m)&&Array.isArray(m.wp)&&m.wp.length>=2;
|
|
1376
1411
|
// SVG for a brace symbol: the (offset) display line — dashed for a below-floor vertical, solid else — with a
|
|
1377
1412
|
// DOUBLE arrowhead at the lower end + a SINGLE at the higher. Every head's tip sits AT its end point and its
|
|
1378
1413
|
// body points INWARD, so a head never overhangs the work point. Structure: an invisible line.bracehit
|
|
@@ -1760,6 +1795,70 @@ function dimGeo(a,b,axis,off,rot){rot=rot||0;
|
|
|
1760
1795
|
else{const x=off;g={p1:[x,A[1]],p2:[x,B[1]],w:[[A,[x,A[1]]],[B,[x,B[1]]]],mid:[x,(A[1]+B[1])/2],px:Math.abs(B[1]-A[1])};} // axis y
|
|
1761
1796
|
if(rot){const f=p=>rotPt(p,rot);g.p1=f(g.p1);g.p2=f(g.p2);g.mid=f(g.mid);g.w=g.w.map(s=>[f(s[0]),f(s[1])]);} // back to display space (witness `from` maps back to the original anchor)
|
|
1762
1797
|
return g;}
|
|
1798
|
+
// ── F9 magnetic (associative) dimensions ──────────────────────────────────────────────────────────────
|
|
1799
|
+
// A dim endpoint may carry an optional ref {m:<memberId>, pt:'a'|'b'|'mid'} to a beam in its OWN plan. When a
|
|
1800
|
+
// ref is present it is AUTHORITATIVE — d.a/d.b become a cache reanchored every render from the member's DRAWN
|
|
1801
|
+
// point. resolveDimAnchor is strictly PLAN-SCOPED (never byId(), which spans plans and would cross-link sheets).
|
|
1802
|
+
function resolveDimAnchor(plan,ref){
|
|
1803
|
+
if(!plan||!ref||typeof ref.m!=='string')return null;
|
|
1804
|
+
const m=(plan.members||[]).find(x=>x&&x.id===ref.m);
|
|
1805
|
+
if(!isDimAnchorableMember(m))return null;
|
|
1806
|
+
const v=memberViewLine(m);
|
|
1807
|
+
return ref.pt==='a'?v[0].slice():ref.pt==='b'?v[1].slice():ref.pt==='mid'?[(v[0][0]+v[1][0])/2,(v[0][1]+v[1][1])/2]:null;}
|
|
1808
|
+
// F9 (QA 2026-07-16): a dim endpoint may instead anchor to a GRID LINE — ref {g:'gv:i'|'gh:i'|'gl:id'}, the
|
|
1809
|
+
// same synthetic ids the grid selection uses (per-plan; index-based, so a respace/re-infer can renumber them —
|
|
1810
|
+
// the ref then resolves elsewhere or null and safe-freezes). The anchor point is the grid line ∩ the dim's own
|
|
1811
|
+
// offset line (local-Y = off in the dim's baked rot frame): the row follows the GRID when the grid moves, and
|
|
1812
|
+
// slides ALONG the grid when the dim itself is dragged. Quick-dim rows are axis:'x' — the only shape resolved.
|
|
1813
|
+
function resolveDimGridAnchor(plan,gid,d){
|
|
1814
|
+
const gc=GC();if(!gc||!plan||!plan.grid||typeof gid!=='string'||!d||d.axis!=='x')return null;
|
|
1815
|
+
let geo=null;try{geo=gc.gridGeometry(plan.grid,(plan.pt_per_ft>0)?plan.pt_per_ft:1);}catch(_){return null;}
|
|
1816
|
+
if(!geo)return null;
|
|
1817
|
+
let p1=null,p2=null;
|
|
1818
|
+
if(gid.startsWith('gv:')){const l=(geo.v||[])[+gid.slice(3)];if(l){p1=[l.x,l.lo];p2=[l.x,l.hi];}}
|
|
1819
|
+
else if(gid.startsWith('gh:')){const l=(geo.h||[])[+gid.slice(3)];if(l){p1=[l.lo,l.y];p2=[l.hi,l.y];}}
|
|
1820
|
+
else if(gid.startsWith('gl:')){const lid=gid.slice(3),l=(geo.lines||[]).find((x,i)=>String(x.id!=null?x.id:i)===lid);if(l){p1=l.a;p2=l.b;}}
|
|
1821
|
+
if(!p1)return null;
|
|
1822
|
+
const rot=d.rot||0,lyv=q=>rotPt(q,-rot)[1];
|
|
1823
|
+
const l1=lyv(p1),l2=lyv(p2);if(Math.abs(l2-l1)<1e-6)return null; // grid runs along the row → no stable anchor
|
|
1824
|
+
const t=(d.off-l1)/(l2-l1); // UNCLAMPED — a grid is conceptually infinite; the row may sit past the drawn extent
|
|
1825
|
+
return [p1[0]+t*(p2[0]-p1[0]),p1[1]+t*(p2[1]-p1[1])];}
|
|
1826
|
+
// Recompute one dim's cached a/b from its refs; drop a ref that no longer resolves (safe-freeze — the dim
|
|
1827
|
+
// survives frozen). Skips the endpoint being hand-dragged right now (dimend drag) so the live drag isn't
|
|
1828
|
+
// overwritten. Returns true if a ref was dropped.
|
|
1829
|
+
// d.pin===false = the magnetic link is DORMANT (user unpinned it): keep the refs but don't follow the
|
|
1830
|
+
// members — the dim stays where it was put until re-pinned (then it snaps back onto the member points).
|
|
1831
|
+
function reanchorDim(plan,d){let dropped=false;
|
|
1832
|
+
if(d.pin===false)return false; // unpinned → dormant, never moves and never drops its refs
|
|
1833
|
+
for(const [rk,pk,ei] of [['aRef','a',0],['bRef','b',1]]){const ref=d[rk];if(!ref)continue;
|
|
1834
|
+
if(drag&&drag.type==='dimend'&&drag.id===d.id&&drag.end===ei)continue; // don't fight an active handle drag
|
|
1835
|
+
if(ref.g&&!GC())continue; // grid-core is an ES module — the FIRST render races its load; a null resolver is "not loaded yet", NOT "grid gone", so keep the ref (the gridcore-ready re-render resolves it). Dropping here silently stripped every SAVED grid ref at load (QA 2026-07-16).
|
|
1836
|
+
const p=ref.g?resolveDimGridAnchor(plan,ref.g,d):resolveDimAnchor(plan,ref); // member ref {m,pt} vs grid ref {g}
|
|
1837
|
+
if(p)d[pk]=p;else{delete d[rk];dropped=true;}}
|
|
1838
|
+
return dropped;}
|
|
1839
|
+
// Pre-render pass over EVERY plan: keep magnetic dims glued to their members. O(dims), idempotent. One toast
|
|
1840
|
+
// when any ref is dropped this pass (its member vanished) — naturally once per deletion.
|
|
1841
|
+
function reanchorAllPlans(){let dropped=false;
|
|
1842
|
+
for(const plan of (C.plans||[]))for(const d of (plan.dims||[]))if(d&&(d.aRef||d.bRef)){if(reanchorDim(plan,d))dropped=true;}
|
|
1843
|
+
if(dropped)toast('A dimension lost its link to a removed member or grid line');}
|
|
1844
|
+
// Live path for the 2D member/endpoint drag, which updateLine()s WITHOUT a full render (:4135/:4141): reanchor
|
|
1845
|
+
// only the active plan's magnetic dims + rebuild the dim overlay group, so dims track while the pointer is down.
|
|
1846
|
+
function refreshMagneticDims2D(){for(const d of (P.dims||[]))if(d&&(d.aRef||d.bRef))reanchorDim(P,d);
|
|
1847
|
+
const dg=svg.querySelector('g.dimsg');if(dg)dg.innerHTML=renderDimsInner();}
|
|
1848
|
+
// F9 (QA 2026-07-16): the ref a hand-dragged dim anchor should carry after landing at pt — so magnetism
|
|
1849
|
+
// SURVIVES handle moves instead of silently detaching. Drop on a member end/mid → {m,pt}; on a grid line
|
|
1850
|
+
// (axis:'x' rows only — the shape resolveDimGridAnchor resolves) → {g}; free space → null (detach: the manual
|
|
1851
|
+
// position wins — Codex R1 #13). Snap delivers the target's exact coords, so the match is a tight FP epsilon,
|
|
1852
|
+
// never a search radius: an unsnapped (Alt) drop near a point stays free on purpose.
|
|
1853
|
+
function dimRefAtPoint(plan,pt,d){const EPS=0.01;
|
|
1854
|
+
for(const m of (plan.members||[])){if(!isDimAnchorableMember(m))continue;
|
|
1855
|
+
const v=memberViewLine(m),mid=[(v[0][0]+v[1][0])/2,(v[0][1]+v[1][1])/2];
|
|
1856
|
+
for(const [pk,q] of [['a',v[0]],['b',v[1]],['mid',mid]])if(Math.hypot(q[0]-pt[0],q[1]-pt[1])<=EPS)return {m:m.id,pt:pk};}
|
|
1857
|
+
if(d&&d.axis==='x'&&plan===P)for(const g of gridSelectables()){ // gridSelectables reads the ACTIVE plan's geometry — fine here (the drag is inherently active-plan); hidden grid = no attach
|
|
1858
|
+
const dx=g.p2[0]-g.p1[0],dy=g.p2[1]-g.p1[1],L2=dx*dx+dy*dy;if(L2<1e-9)continue;
|
|
1859
|
+
const t=((pt[0]-g.p1[0])*dx+(pt[1]-g.p1[1])*dy)/L2; // UNCLAMPED — a grid is conceptually infinite (same rule as resolveDimGridAnchor), so a drop snapped onto the line's EXTENSION still links (Codex final-review #1)
|
|
1860
|
+
if(Math.hypot(g.p1[0]+t*dx-pt[0],g.p1[1]+t*dy-pt[1])<=EPS)return {g:g.id};}
|
|
1861
|
+
return null;}
|
|
1763
1862
|
// measured pixels -> real length text, identical to every other length in the editor (ft-in, 16ths).
|
|
1764
1863
|
function dimValueText(px){return fmtFtIn(px/FT*12);}
|
|
1765
1864
|
// the offset a click at pointer p implies, given the two anchors + axis (+ baked frame rot). For x/y the
|
|
@@ -1844,6 +1943,15 @@ function sanitizeDims(p){if(!p)return;
|
|
|
1844
1943
|
const r=num(d.rot);
|
|
1845
1944
|
const q={id:String(d.id||('d'+Date.now()+'_'+(dimSeq++))),a:[num(d.a[0]),num(d.a[1])],b:[num(d.b[0]),num(d.b[1])],axis:d.axis,off:num(d.off),rot:r==null?0:r};
|
|
1846
1945
|
if(_dEnd(d.end))q.end=d.end;if(_dBg(d.bg))q.bg=d.bg;if(_dPlace(d.place))q.place=d.place;
|
|
1946
|
+
// F9: carry validated magnetic refs (this rebuild drops unknown fields, so aRef/bRef must be explicit).
|
|
1947
|
+
// Member ref {m,pt}: kept only if the member is anchorable (beam/column, never brace) in THIS plan and pt is
|
|
1948
|
+
// a/b/mid. Grid ref {g}: kept when it has the synthetic-id shape and THIS plan has a grid (the resolver
|
|
1949
|
+
// safe-freezes an index that no longer exists). Else dropped.
|
|
1950
|
+
const okMRef=x=>x&&typeof x==='object'&&typeof x.m==='string'&&(x.pt==='a'||x.pt==='b'||x.pt==='mid')&&(p.members||[]).some(mm=>mm&&mm.id===x.m&&isDimAnchorableMember(mm));
|
|
1951
|
+
const okGRef=x=>x&&typeof x==='object'&&typeof x.g==='string'&&/^g[vhl]:/.test(x.g)&&!!p.grid;
|
|
1952
|
+
const cpRef=x=>okGRef(x)?{g:x.g}:(okMRef(x)?{m:x.m,pt:x.pt}:null);
|
|
1953
|
+
{const ar=cpRef(d.aRef),br=cpRef(d.bRef);if(ar)q.aRef=ar;if(br)q.bRef=br;}
|
|
1954
|
+
if(d.pin===false&&(q.aRef||q.bRef))q.pin=false; // F9: a dormant (unpinned) link survives the load — but only alongside a surviving ref
|
|
1847
1955
|
out.push(q);}
|
|
1848
1956
|
if(out.length!==p.dims.length)console.warn('discarding '+(p.dims.length-out.length)+' malformed dimension(s) on '+p.sheet);
|
|
1849
1957
|
p.dims=out;}
|
|
@@ -1870,7 +1978,13 @@ function dimSvg(d,o){o=o||{};const g=dimGeo(d.a,d.b,d.axis,d.off,d.rot),dz=(o.dz
|
|
|
1870
1978
|
// text never reads upside-down; within 8° of horizontal it stays flat. A vertical dim always lands on
|
|
1871
1979
|
// −90 (reads bottom-to-top), which also puts "above" on the side away from the drawing whichever way
|
|
1872
1980
|
// its two anchors happened to be picked.
|
|
1873
|
-
let ang=Math.atan2(g.p2[1]-g.p1[1],g.p2[0]-g.p1[0])*180/Math.PI;if(ang>=90)ang-=180;else if(ang<-90)ang+=180;
|
|
1981
|
+
let ang=Math.atan2(g.p2[1]-g.p1[1],g.p2[0]-g.p1[0])*180/Math.PI;if(ang>=90)ang-=180;else if(ang<-90)ang+=180;
|
|
1982
|
+
// The ±90 boundary is FP-fragile: a rotated vertical dim's dx is the difference of two near-equal doubles,
|
|
1983
|
+
// so its SIGN is effectively random — neighbouring dims in one row could land on opposite sides and one
|
|
1984
|
+
// rendered turned 180°. Mirror the 8° flat-snap at vertical: flip the reads-top-to-bottom sliver upright,
|
|
1985
|
+
// then snap the whole near-vertical band to a clean −90 (bottom-to-top, the drafting convention).
|
|
1986
|
+
if(ang>82)ang-=180;
|
|
1987
|
+
if(Math.abs(ang)<8)ang=0;else if(Math.abs(ang+90)<8)ang=-90;
|
|
1874
1988
|
const over=st.end==='tick'?5/dz:0; // with ticks the WITNESS lines overshoot past the dim line (drafting convention); dots/arrows stop them at it
|
|
1875
1989
|
let s='';for(const w of g.w){const wx=w[1][0]-w[0][0],wy=w[1][1]-w[0][1],WL=Math.hypot(wx,wy)||1;
|
|
1876
1990
|
s+=`<line class="dimwit ${c}" x1="${w[0][0]}" y1="${w[0][1]}" x2="${w[1][0]+wx/WL*over}" y2="${w[1][1]+wy/WL*over}"/>`;}
|
|
@@ -1886,7 +2000,11 @@ function dimSvg(d,o){o=o||{};const g=dimGeo(d.a,d.b,d.axis,d.off,d.rot),dz=(o.dz
|
|
|
1886
2000
|
const lab=(st.bg?`<rect class="dimchip ${c}"${dd} x="${-cw/2}" y="${ly-ch/2}" width="${cw}" height="${ch}" rx="${4/dz}"/>`
|
|
1887
2001
|
:`<rect class="dimhit ${c}"${dd} x="${-cw/2}" y="${ly-ch/2}" width="${cw}" height="${ch}"/>`)
|
|
1888
2002
|
+`<text class="dimtx ${st.bg?'':'dimhalo '}${c}" x="0" y="${ly}" style="font-size:${13/dz}px${st.bg?'':`;stroke-width:${3/dz}px`}">${txt}</text>`; // halo rides 1/dz with the text, else it swells into a solid pill as you zoom in
|
|
1889
|
-
|
|
2003
|
+
// F9: a LINKED (magnetic) dim carries a tiny pin beside its label — filled cyan = pinned (follows its
|
|
2004
|
+
// beams), hollow + dimmed = link dormant (unpinned). Sized 1/dz like the chip; never a hit target.
|
|
2005
|
+
const _hasRef=!!(d.aRef||d.bRef),_pinOn=_hasRef&&d.pin!==false;
|
|
2006
|
+
const pinMk=_hasRef?`<g transform="translate(${cw/2+3/dz} ${ly-ch/2}) scale(${1/dz})" pointer-events="none" opacity="${_pinOn?0.95:0.4}"><circle cx="5" cy="3.4" r="2.4"${_pinOn?' fill="#22d3ee"':' fill="none" stroke="#22d3ee" stroke-width="1.1"'}/><path d="M3.7 5 1 7.7" stroke="#22d3ee" stroke-width="1.3" fill="none" stroke-linecap="round"/></g>`:'';
|
|
2007
|
+
s+=`<g transform="translate(${g.mid[0]} ${g.mid[1]}) rotate(${ang.toFixed(2)})">${lab}${pinMk}</g>`; // label group rides the dim-line midpoint
|
|
1890
2008
|
return s;}
|
|
1891
2009
|
function renderDimsInner(){if(!dimsVisible||!Array.isArray(P.dims))return '';
|
|
1892
2010
|
let s=P.dims.map(d=>dimSvg(d,{id:d.id,sel:selDimIds.has(d.id)})).join('');
|
|
@@ -2207,7 +2325,7 @@ function setGeo(){document.body.classList.toggle('geo',!!geoMode);document.body.
|
|
|
2207
2325
|
let lastCmd=null;
|
|
2208
2326
|
function setLastCmd(label,run){lastCmd={label,run};}
|
|
2209
2327
|
function anyToolActive(){
|
|
2210
|
-
if(dimMode||dimChain||dimSplitMode||geoMode||csaxisMode||gridMode||gridPick||gridLinePick||dimStyleMode||mode==='add'||picking||cmTool)return true; // 2D tools armed (cmTool = Move/Copy)
|
|
2328
|
+
if(dimMode||dimChain||dimSplitMode||geoMode||csaxisMode||gridMode||gridPick||gridLinePick||dimStyleMode||mode==='add'||picking||cmTool||qdPick)return true; // 2D tools armed (cmTool = Move/Copy; qdPick = the F7 grid station pick)
|
|
2211
2329
|
if(view3d&&window.Steel3DView){if(window.Steel3DView.clipMode&&window.Steel3DView.clipMode())return true;const dm=document.getElementById('m3dDim');if(dm&&dm.classList.contains('on'))return true;} // 3D dim/clip armed
|
|
2212
2330
|
return false;
|
|
2213
2331
|
}
|
|
@@ -2224,6 +2342,10 @@ function snapEndMulti(ms,tA,tB){const pv=snapshot();let n=0,skipped=0;
|
|
|
2224
2342
|
if(n){pushUndo(pv);render();sync3D();}return n;}
|
|
2225
2343
|
function doSplit(m,pt){if(isBrace(m)){toast('Braces can’t be split — edit them from the inspector');return;} // split/extend/trim disabled on braces (offset would create off-℄ WPs · Codex round-2)
|
|
2226
2344
|
const pv=snapshot();ensureMeta(m);const base=JSON.parse(JSON.stringify(m));
|
|
2345
|
+
// F9: split keeps m.id for the first half with CHANGED endpoints (the clone gets a fresh id), so a dim ref to m
|
|
2346
|
+
// would silently jump — detach every ref to m in its plan before geometry moves (safe-freeze; pv above still has
|
|
2347
|
+
// them so undo restores). The clone's new id carries no refs. (Codex R3 #2.)
|
|
2348
|
+
{const own=planeOfMember(m);for(const d of (own&&own.dims||[]))for(const rk of ['aRef','bRef'])if(d[rk]&&d[rk].m===m.id)delete d[rk];}
|
|
2227
2349
|
const a=m.wp[0].slice(),b=m.wp[1].slice(),q=pt.slice(),mk=()=>({tos:null,note:'',tosDef:true,detail:''});
|
|
2228
2350
|
m.wp=[a,q];if(m.ends)m.ends=[m.ends[0],mk()]; // first half keeps its start end, fresh cut end
|
|
2229
2351
|
const c=JSON.parse(JSON.stringify(base));c.id='m'+Date.now();c.wp=[q.slice(),b];
|
|
@@ -2299,9 +2421,10 @@ function mergeCollinearJS(members){
|
|
|
2299
2421
|
if(Array.isArray(members[first].ends)&&Array.isArray(members[last].ends))m.ends=[JSON.parse(JSON.stringify(members[first].ends[fo])),JSON.parse(JSON.stringify(members[last].ends[lo]))];
|
|
2300
2422
|
m.angle=_mAngle(m.wp);m.mf=ordered.some(n=>members[n].mf===true);m.verified=ordered.every(n=>members[n].verified===true);
|
|
2301
2423
|
runByAnchor.set(Math.min(...ordered),m);mergedAway+=ordered.length-1;for(const n of ordered)merged.add(n);}
|
|
2302
|
-
if(mergedAway===0)return{members,mergedAway:0,runs:0};
|
|
2424
|
+
if(mergedAway===0)return{members,mergedAway:0,runs:0,affectedIds:[]};
|
|
2303
2425
|
const out=[];for(let i=0;i<members.length;i++){if(runByAnchor.has(i))out.push(runByAnchor.get(i));else if(!merged.has(i))out.push(members[i]);}
|
|
2304
|
-
|
|
2426
|
+
const affectedIds=[...merged].map(i=>members[i]&&members[i].id).filter(Boolean); // F9: every id in a merged run (survivor keeps members[first].id with changed endpoints + the consumed ids) — the caller detaches dim refs to this set (Codex R3 #3)
|
|
2427
|
+
return{members:out,mergedAway,runs:runByAnchor.size,affectedIds};}
|
|
2305
2428
|
const svg=document.getElementById('svg');
|
|
2306
2429
|
function toSvg(e){const p=svg.createSVGPoint();p.x=e.clientX;p.y=e.clientY;return p.matrixTransform(svg.getScreenCTM().inverse());}
|
|
2307
2430
|
// --- zoom + pan ---
|
|
@@ -2334,6 +2457,7 @@ function esc(s){return String(s).replace(/[<>&"]/g,c=>({'<':'<','>':'>','&
|
|
|
2334
2457
|
function render(){
|
|
2335
2458
|
document.body.classList.remove('snapping'); // a wholesale svg rebuild drops any #snapMark → clear the cursor-hide flag too (the next pointermove re-adds it if still snapping)
|
|
2336
2459
|
buildColorRank(); // refresh the model-global colour rank before any colorFor() call below (B2 — keeps 2D hues stable across plans + matched to 3D)
|
|
2460
|
+
reanchorAllPlans(); // F9: glue magnetic dims to their members BEFORE anything reads P.dims — covers every mutation path that ends in a render()
|
|
2337
2461
|
if(geoMode&&(selIds.size<1||(geoMode==='split'&&selIds.size!==1))){geoMode=null;setGeo();} // Split needs exactly one member; Extend/Trim works on any selection. setGeo() clears BOTH geo + geoel (not a bare remove('geo')) so the grid affordance can't outlive the tool
|
|
2338
2462
|
let s=overlaySvg(); // crisp vector linework (snappable) when the sheet has vectors; raster only for scanned PDFs
|
|
2339
2463
|
s+=gridSvg(); // structural grid under the linework (members/dims stay on top)
|
|
@@ -2568,8 +2692,11 @@ function panel(){
|
|
|
2568
2692
|
const shared=k=>{const v=agg(dsel,d=>dimStyle(d)[k]);return v===VARIES?null:v;}; // null ⇒ the selection disagrees → light no button, leave the checkbox indeterminate
|
|
2569
2693
|
const endV=shared('end'),placeV=shared('place'),bgV=shared('bg');
|
|
2570
2694
|
const nOver=dsel.filter(dimHasOverride).length; // >0 ⇒ offer the way back to the model-global default
|
|
2695
|
+
const linked=dsel.filter(d=>d.aRef||d.bRef); // F9: dims carrying a magnetic link (dormant or live)
|
|
2696
|
+
const pinV=linked.length?agg(linked,d=>d.pin!==false):null; // true | false | VARIES across the linked ones
|
|
2571
2697
|
p.innerHTML=`<span class=badge>Dimension${selDimIds.size>1?'s · '+selDimIds.size:''}</span>
|
|
2572
2698
|
${one?`<div class=hint style="margin-top:8px">Length <b>${esc(dimValueText(dimGeo(one.a,one.b,one.axis,one.off,one.rot).px))}</b> · ${({free:'Free (aligned)',x:'X (horizontal)',y:'Y (vertical)'})[one.axis]}</div>`:''}
|
|
2699
|
+
${linked.length?`<button id=dimPinT class="pintog${pinV===true?' on':''}" role=switch aria-checked="${pinV===true?'true':'false'}" style="margin-top:8px" data-tip="Magnetic link: pinned, the dimension follows its member(s) and editing its value moves them. Unpinned, the link stays but goes dormant — the dimension holds still until re-pinned."><span class=mck aria-hidden=true></span>${DIMEDIT_GLY.pin}Pinned to member${dsel.length>1?` · ${linked.length} linked`:''}${pinV===VARIES?' · mixed':''}</button>`:''}
|
|
2573
2700
|
${(endV&&placeV&&bgV!==null)?dimStylePreview({end:endV,bg:bgV,place:placeV}):''}
|
|
2574
2701
|
<div class=sect style="margin-top:12px">Ends</div>
|
|
2575
2702
|
<div class="seg2 segico">${DIM_ENDS.map(k=>`<button data-dend="${k}" class="${endV===k?'on':''}" data-tip="${esc(DIM_END_TIP[k])}">${DIM_END_GLYPH[k]}<span>${DIM_END_LBL[k]}</span></button>`).join('')}</div>
|
|
@@ -2585,6 +2712,8 @@ function panel(){
|
|
|
2585
2712
|
p.querySelectorAll('button[data-dend]').forEach(b=>b.onclick=()=>setAll(d=>{d.end=b.dataset.dend;}));
|
|
2586
2713
|
p.querySelectorAll('button[data-dplace]').forEach(b=>b.onclick=()=>setAll(d=>{d.place=b.dataset.dplace;}));
|
|
2587
2714
|
const cb=document.getElementById('dimBg');cb.indeterminate=(bgV===null);cb.onchange=e=>setAll(d=>{d.bg=e.target.checked;});
|
|
2715
|
+
{const pk=document.getElementById('dimPinT');if(pk)pk.onclick=()=>{const turnOn=pinV!==true; // all-on → off; off or mixed → on (standard mixed-toggle convention)
|
|
2716
|
+
setAll(d=>{if(d.aRef||d.bRef){if(turnOn)delete d.pin;else d.pin=false;}});};} // F9: pin = per-dim magnetic switch — re-pinning reanchors onto the members' CURRENT points (the edit()'s render does it); unpinning freezes in place. Undoable.
|
|
2588
2717
|
{const ud=document.getElementById('dimUseDef');if(ud)ud.onclick=()=>setAll(d=>{delete d.end;delete d.bg;delete d.place;});}
|
|
2589
2718
|
document.getElementById('dimSplitB').onclick=()=>toggleDimSplit();
|
|
2590
2719
|
return;}
|
|
@@ -2771,9 +2900,12 @@ function panel(){
|
|
|
2771
2900
|
p.innerHTML=`<span class=badge>Grid line${n>1?'s · '+n:''}</span>
|
|
2772
2901
|
${one?`<div class=hint style="margin-top:8px">Grid <b>${esc(one.label)}</b> · ${one.type} line</div>`:`<div class=hint style="margin-top:8px">${esc(parts.join(' · '))}</div>`}
|
|
2773
2902
|
<div class=hint style="margin-top:8px">Grid lines are the plan's structural reference.${nFree?` <b>Del</b> removes the free line${nFree>1?'s':''}.`:''}${regClause}</div>
|
|
2903
|
+
${n>=2?`<div class=divrow><hr><span class=sect style="margin:0" data-tip="Place a running dimension row measuring the spacing between the selected grid lines. You'll click a point to say where the row should sit; the dims stay attached to the grid.">Quick-dim spacing <span style="opacity:.45;font-weight:400">ⓘ</span></span><hr></div>
|
|
2904
|
+
<div class=row style="margin-top:6px"><button class=ghostw id=qdPlaceG data-tip="Place spacing dimensions between the ${n} selected grid lines · Shortcut: Q">📏 Place spacing dims (${n}) <span style="opacity:.55">(Q)</span></button></div>`:''}
|
|
2774
2905
|
<div class="row f" style="gap:6px;margin-top:12px;flex-wrap:wrap"><button class=ghostw id=gridEditFromSel data-tip="Open the grid editor to rename, respace, or adjust the grid">✎ Grid lines…</button>${nFree?`<button class=danger id=gridDelFree data-tip="Delete the selected free grid line${nFree>1?'s':''} (Del)">${delLbl}</button>`:''}</div>`;
|
|
2775
2906
|
{const eb=document.getElementById('gridEditFromSel');if(eb)eb.onclick=()=>{setGridMode(true);render();};}
|
|
2776
2907
|
{const db=document.getElementById('gridDelFree');if(db)db.onclick=()=>deleteSelGrids();}
|
|
2908
|
+
{const qb=document.getElementById('qdPlaceG');if(qb)qb.onclick=()=>quickDimSpacing(qdAnchorPt);}
|
|
2777
2909
|
return;}
|
|
2778
2910
|
const arr=selArr();
|
|
2779
2911
|
if(arr.length===0){p.innerHTML='<h3 style="display:flex;justify-content:space-between;align-items:center">Legend'+(Object.keys(C.profile_colors).length?'<button class=ghost id=resetCols style="font-size:10px;padding:1px 6px">reset colours</button>':'')+'</h3><div class=legend>'+profs.filter(pr=>P.members.some(mm=>mm.profile===pr)).map(pr=>`<span><input type=color class=swc data-prof="${esc(pr)}" value="${colorFor(pr)}" data-tip="Click to recolour ${esc(pr)}">${esc(pr)}</span>`).join('')+'</div><div class=hint style="margin-top:12px">Click a member to edit; <b>Ctrl</b>/<b>Shift+click</b> to add/remove; drag an empty area to <b>box-select</b> — <b>left→right</b> grabs fully-enclosed, <b>right→left</b> grabs touched (Ctrl/Shift adds). Drag a selected line to move it (all selected move together) — it snaps onto nearby grid/endpoints; drag an end dot to adjust — also snaps (<b>Alt</b> off). Hold <b>Shift</b> to keep it straight (H/V). <b>Ctrl+D</b> duplicate, <b>Ctrl+Z/Y</b> undo/redo, <b>Del</b> delete, <b>Esc</b> deselect. <b>Scroll</b> zoom, <b>middle-drag</b> pan, <b>Home</b> fit. Short even dashes = RFI (size unresolved, e.g. MF). A line with <b>arrowheads</b> is a <b>brace</b> — solid = above the floor, long–short dashes = below; the double arrowhead marks its lower end.</div>'+
|
|
@@ -2815,6 +2947,7 @@ function panel(){
|
|
|
2815
2947
|
`<div class=sect>${dotE}End</div>${mTos('tosB','TOS',s1)}${mNote('ntB',s1)}${mDet('dtB',s1)}`;}
|
|
2816
2948
|
const posA=!allCol?agg(beams,m=>posDefault(m)):null;
|
|
2817
2949
|
const rotAgg=agg(arr,m=>((((+m.rot||0)%360)+360)%360)); // shared rotation, or VARIES
|
|
2950
|
+
const qdElig=(sel2d()||[]).filter(isDimAnchorableMember),qdN=qdElig.length+selGridIds.size,qdHasBeam=qdElig.some(m=>(m.role||'beam')!=='column'); // F7: active-plan beams + columns + co-selected grid lines; the Start/Mid/End toggle only matters when a beam is in the set
|
|
2818
2951
|
p.innerHTML=`<h3>${arr.length} members selected</h3>
|
|
2819
2952
|
${typeFilterHTML()}
|
|
2820
2953
|
<div class="row hint" style="margin-top:0">Edits apply to <b>all ${arr.length}</b> selected · a blank <b>Varies</b> field is left unchanged.</div>
|
|
@@ -2832,6 +2965,9 @@ function panel(){
|
|
|
2832
2965
|
<div class=seg2 style="margin-top:0"><button id=geoEL class="${geoMode==='el'?'on':''}">Extend / Trim all</button></div>
|
|
2833
2966
|
<div class=hint style="margin-top:6px">${geoMode==='el'?'Click a <b>target line</b> (member, segment, or grid line) — the nearest end of <b>every</b> selected member snaps to where it meets that line.':'<b>Extend/Trim</b> (E) every selected member\'s nearest end to one line. <b>Esc</b> cancels.'}</div>
|
|
2834
2967
|
<div class=row><button class=ghostw id=swapEnds data-tip="Reverse every selected member: swap each one's start and end (yellow ↔ magenta / bottom ↔ top) handles · Shortcut: P">⇄ Swap start ↔ end (all) <span style="opacity:.55">(P)</span></button></div>
|
|
2968
|
+
${qdN>=2?`<div class=divrow><hr><span class=sect style="margin:0" data-tip="Place a running dimension row measuring the spacing between the selected members, taken at the chosen point on each beam (a column uses its plan point). The dims stay attached — move a member and they follow.">Quick-dim spacing <span style="opacity:.45;font-weight:400">ⓘ</span></span><hr></div>
|
|
2969
|
+
${qdHasBeam?`<div class=seg2 style="margin-top:0"><button id=qdPtA class="${qdAnchorPt==='a'?'on':''}" data-tip="Measure between each beam's START point">Start</button><button id=qdPtMid class="${qdAnchorPt==='mid'?'on':''}" data-tip="Measure between each beam's MIDPOINT">Middle</button><button id=qdPtB class="${qdAnchorPt==='b'?'on':''}" data-tip="Measure between each beam's END point">End</button></div>`:''}
|
|
2970
|
+
<div class=row style="margin-top:6px"><button class=ghostw id=qdPlace data-tip="Place spacing dimensions between the ${qdN} selected members · Shortcut: Q">📏 Place spacing dims (${qdN}) <span style="opacity:.55">(Q)</span></button></div>`:''}
|
|
2835
2971
|
<div class="row f"><button class=danger id=del>Delete selected (${arr.length})</button></div>`;
|
|
2836
2972
|
wireTypeFilter(p);
|
|
2837
2973
|
// wiring — every commit applies to the whole selection; a blank field is a no-op (leaves each member's own value).
|
|
@@ -2840,6 +2976,11 @@ function panel(){
|
|
|
2840
2976
|
document.getElementById('verifyBtn').onclick=()=>edit(()=>{const v=!allVerified;for(const m of selArr())m.verified=v;});
|
|
2841
2977
|
{const _gel=document.getElementById('geoEL');if(_gel)_gel.onclick=()=>{geoMode=(geoMode==='el'?null:'el');setGeo();render();};}
|
|
2842
2978
|
{const _sw=document.getElementById('swapEnds');if(_sw)_sw.onclick=()=>swapSelectionEnds();} // reverse start↔end for the whole selection (2D + 3D via render+sync3D); braces excluded, and it owns its edit()/toast
|
|
2979
|
+
{const setQd=k=>{qdAnchorPt=k;try{localStorage.setItem('steel:qdAnchor:v1',k);}catch(_){}for(const [id,kk] of [['qdPtA','a'],['qdPtMid','mid'],['qdPtB','b']]){const b=document.getElementById(id);if(b)b.classList.toggle('on',qdAnchorPt===kk);}}; // F7 anchor-point toggle (persisted)
|
|
2980
|
+
const _qa=document.getElementById('qdPtA');if(_qa)_qa.onclick=()=>setQd('a');
|
|
2981
|
+
const _qm=document.getElementById('qdPtMid');if(_qm)_qm.onclick=()=>setQd('mid');
|
|
2982
|
+
const _qb=document.getElementById('qdPtB');if(_qb)_qb.onclick=()=>setQd('b');
|
|
2983
|
+
const _qp=document.getElementById('qdPlace');if(_qp)_qp.onclick=()=>quickDimSpacing(qdAnchorPt);}
|
|
2843
2984
|
document.getElementById('del').onclick=()=>edit(()=>{for(const pl of C.plans)pl.members=(pl.members||[]).filter(m=>!selIds.has(m.id));selIds.clear();if(selDimIds.size){P.dims=P.dims.filter(d=>!selDimIds.has(d.id));selDimIds.clear();}}); // selection spans sheets → remove from every plane; a mixed marquee also holds dims (active sheet) — remove them too (matches keyboard Delete)
|
|
2844
2985
|
{const sp=v=>edit(()=>{for(const m of selArr())if(m.role!=='column')m.position=v;});
|
|
2845
2986
|
const _pt=document.getElementById('posTop'),_pm=document.getElementById('posMid'),_pb=document.getElementById('posBot');
|
|
@@ -3728,17 +3869,175 @@ function dimSplitAt(m){
|
|
|
3728
3869
|
const id1='d'+Date.now()+'_'+(dimSeq++),id2='d'+Date.now()+'_'+(dimSeq++);
|
|
3729
3870
|
P.dims=P.dims.filter(x=>x.id!==d.id);
|
|
3730
3871
|
const sty=dimStyleOverrides(d); // both halves inherit the split dim's style
|
|
3731
|
-
|
|
3872
|
+
const cp=r=>r?(r.g?{g:r.g}:{m:r.m,pt:r.pt}):null; // F9: each half keeps its OUTER ref — member or grid — (+ a dormant pin state); the new interior end is raw (Codex R4 #3)
|
|
3873
|
+
const pn=d.pin===false?{pin:false}:{};
|
|
3874
|
+
P.dims.push({id:id1,a:d.a.slice(),b:mid.slice(),axis:d.axis,off:d.off,rot:d.rot,...sty,...(d.aRef?{aRef:cp(d.aRef),...pn}:{})},{id:id2,a:mid.slice(),b:d.b.slice(),axis:d.axis,off:d.off,rot:d.rot,...sty,...(d.bRef?{bRef:cp(d.bRef),...pn}:{})});
|
|
3732
3875
|
selDimIds.delete(d.id);selDimIds.add(id1);selDimIds.add(id2);
|
|
3733
3876
|
}else{ // BEYOND an end → add a continuing dimension from that end to the clicked point (same axis/off/rot)
|
|
3734
3877
|
const beyondB=t>=1-EPS,nearEnd=beyondB?d.b.slice():d.a.slice(); // discriminator must match the EPS band above (else branch runs for t≤EPS OR t≥1-EPS): t≥1-EPS → past the b end, else past a — otherwise a click just inside b extended from a, making a reversed near-full-length dim
|
|
3735
3878
|
const far=d.axis==='free'?[d.a[0]+(d.b[0]-d.a[0])*t,d.a[1]+(d.b[1]-d.a[1])*t]:m.slice(); // free: project to stay collinear; x/y: measure to the actual clicked point (graphic sits on the fixed offset line)
|
|
3736
3879
|
const id='d'+Date.now()+'_'+(dimSeq++);
|
|
3737
|
-
|
|
3880
|
+
const nr=beyondB?d.bRef:d.aRef,ncp=nr?(nr.g?{g:nr.g}:{m:nr.m,pt:nr.pt}):null,nref=ncp?{...(beyondB?{aRef:ncp}:{bRef:ncp}),...(d.pin===false?{pin:false}:{})}:{}; // F9: the continuation's NEAR end keeps that end's ref — member or grid — (+ dormant pin state); far end raw (Codex R4 #3)
|
|
3881
|
+
P.dims.push({id,a:beyondB?nearEnd:far,b:beyondB?far:nearEnd,axis:d.axis,off:d.off,rot:d.rot,...dimStyleOverrides(d),...nref}); // keep the original a→b orientation + style
|
|
3738
3882
|
selDimIds.add(id);
|
|
3739
3883
|
}
|
|
3740
3884
|
pushUndo(pv);render();sync3D();
|
|
3741
3885
|
}
|
|
3886
|
+
// ── F7 quick-dim spacing ────────────────────────────────────────────────────────────────────────────
|
|
3887
|
+
// Select 2+ members (beams/columns) and/or GRID LINES → drop a running dimension ROW measuring the spacing
|
|
3888
|
+
// between them. Beams anchor at pt (start/mid/end); a column at its plan point; a grid line where it crosses
|
|
3889
|
+
// the row. Beams + grid lines define the frame: spacing runs PERPENDICULAR to them, so the dims are rotated
|
|
3890
|
+
// axis:'x' sharing one offset → a true straight row immune to along-beam stagger (Codex R2 #6). When a grid
|
|
3891
|
+
// participates the user PICKS the row's station (a grid is infinite — QA 2026-07-16); qdPick re-enters here
|
|
3892
|
+
// with that point. Each segment is anchored (aRef/bRef, member or grid) so it follows its geometry.
|
|
3893
|
+
let qdPick=null; // armed one-shot {pt}: the next canvas click is the row station; Esc cancels
|
|
3894
|
+
function setQdPickCls(){document.body.classList.toggle('qdpick',!!qdPick);}
|
|
3895
|
+
function quickDimSpacing(pt,pick){
|
|
3896
|
+
const cand=(sel2d()||[]).filter(isDimAnchorableMember); // active-plan beams + columns (braces can't anchor — Codex R2 #5; columns added per QA 2026-07-16)
|
|
3897
|
+
const gsel=gridOn()?gridSelectables().filter(g=>selGridIds.has(g.id)):[]; // selected grid lines join the row (QA 2026-07-16)
|
|
3898
|
+
if(cand.length+gsel.length<2){toast('Select 2 or more members or grid lines to quick-dim their spacing');return;}
|
|
3899
|
+
const isCol=m=>(m.role||'beam')==='column';
|
|
3900
|
+
const dirOf=m=>{if(isCol(m))return null;const v=memberViewLine(m),dx=v[1][0]-v[0][0],dy=v[1][1]-v[0][1],L=Math.hypot(dx,dy);return L>1e-6?[dx/L,dy/L]:null;}; // a column has no direction — it donates only its point
|
|
3901
|
+
const ptOf=m=>{if(isCol(m))return m.wp[0].slice();const v=memberViewLine(m);return pt==='a'?v[0].slice():pt==='b'?v[1].slice():[(v[0][0]+v[1][0])/2,(v[0][1]+v[1][1])/2];}; // a column anchors at its single plan point (start/mid/end is meaningless for it)
|
|
3902
|
+
const items=cand.map(m=>({m,dir:dirOf(m),p:ptOf(m)})).filter(x=>x.dir||isCol(x.m)); // keep columns; drop zero-length beams
|
|
3903
|
+
if(items.length+gsel.length<2){toast('Need 2 or more members or grid lines with a usable point');return;}
|
|
3904
|
+
const gDir=g=>{const dx=g.p2[0]-g.p1[0],dy=g.p2[1]-g.p1[1],L=Math.hypot(dx,dy);return L>1e-6?[dx/L,dy/L]:null;};
|
|
3905
|
+
const donors=[...items.map(x=>x.dir).filter(Boolean),...gsel.map(gDir).filter(Boolean)]; // beams + grid lines define the frame
|
|
3906
|
+
let perp;
|
|
3907
|
+
if(donors.length){
|
|
3908
|
+
const ref=donors[0];let sx=0,sy=0; // sign-aligned mean direction (a reversed-draw line doesn't cancel its neighbour) — Codex R1 #7
|
|
3909
|
+
for(const u of donors){const s=(u[0]*ref[0]+u[1]*ref[1])>=0?1:-1;sx+=s*u[0];sy+=s*u[1];}
|
|
3910
|
+
const rl=Math.hypot(sx,sy);
|
|
3911
|
+
if(rl/donors.length<0.9){toast('Those members/grids aren’t parallel enough to space (they fan out)');return;} // mean-resultant < 0.9 (≈ >26° half-spread) → refuse rather than guess. Must stay well above 0.707, a perpendicular pair's value (Codex code-review #3)
|
|
3912
|
+
const dm=[sx/rl,sy/rl];perp=[-dm[1],dm[0]];
|
|
3913
|
+
}else{ // all columns → the spacing direction IS the spread of the points: take the farthest pair
|
|
3914
|
+
let bi=0,bj=1,bd=-1;
|
|
3915
|
+
for(let i=0;i<items.length;i++)for(let j=i+1;j<items.length;j++){const dd=Math.hypot(items[j].p[0]-items[i].p[0],items[j].p[1]-items[i].p[1]);if(dd>bd){bd=dd;bi=i;bj=j;}}
|
|
3916
|
+
if(bd<1){toast('Those columns share one point — nothing to dimension');return;}
|
|
3917
|
+
perp=[(items[bj].p[0]-items[bi].p[0])/bd,(items[bj].p[1]-items[bi].p[1])/bd];
|
|
3918
|
+
}
|
|
3919
|
+
// A near-vertical spacing dim sits right on dimSvg's ±90° text-angle boundary — a hair of beam tilt tips it
|
|
3920
|
+
// past, flipping the label 180° (top-to-bottom). Snap a near-axis-aligned spacing direction to the EXACT
|
|
3921
|
+
// cardinal so the baked rot is cleanly vertical/horizontal and the label lands stably on the upright side.
|
|
3922
|
+
{const pa=Math.atan2(perp[1],perp[0]),sn=Math.round(pa/(Math.PI/2))*(Math.PI/2);
|
|
3923
|
+
if(Math.abs(pa-sn)<0.035)perp=[Math.cos(sn),Math.sin(sn)];} // within ~2° of an axis
|
|
3924
|
+
// Canonical spacing direction: point UP (−screenY) primary, RIGHT (+screenX) secondary → the row orders the
|
|
3925
|
+
// members bottom→up / left→right and the label reads bottom-to-top / left-to-right, never turned 180°.
|
|
3926
|
+
if(perp[1]>1e-9||(Math.abs(perp[1])<=1e-9&&perp[0]<0))perp=[-perp[0],-perp[1]];
|
|
3927
|
+
const rot=Math.atan2(perp[1],perp[0]);
|
|
3928
|
+
const lx=q=>rotPt(q,-rot)[0], ly=q=>rotPt(q,-rot)[1]; // local-X = projection onto perp (the spacing coord, bottom→up / left→right); local-Y = along the lines
|
|
3929
|
+
if(gsel.length&&!pick){qdPick={pt};setQdPickCls();toast('Grid lines run the drawing’s length — click where the dimension row should sit. Esc cancels.');return;} // one-shot station pick; the click re-enters with it
|
|
3930
|
+
const off=gsel.length?ly(pick):(Math.min(...items.map(it=>ly(it.p)))-40/zoom); // grids → the row sits AT the picked station; members-only → auto, clear of every point
|
|
3931
|
+
const tmpD={axis:'x',off,rot};
|
|
3932
|
+
const gItems=gsel.map(g=>{const gp=resolveDimGridAnchor(P,g.id,tmpD);return gp?{g:g.id,p:gp}:null;}).filter(Boolean); // grid anchor = the line ∩ the row (a grid running along the row can't anchor)
|
|
3933
|
+
const all=[...items.map(it=>({m:it.m,p:it.p})),...gItems];
|
|
3934
|
+
if(all.length<2){toast('Those grid lines run along the row — nothing to measure between');return;}
|
|
3935
|
+
all.sort((a,b)=>lx(a.p)-lx(b.p)); // order across the row, bottom→up / left→right
|
|
3936
|
+
const pv=snapshot();const made=[];
|
|
3937
|
+
for(let i=0;i<all.length-1;i++){const A=all[i],B=all[i+1];
|
|
3938
|
+
if(Math.abs(lx(B.p)-lx(A.p))<1)continue; // coincident projection → no spacing to show
|
|
3939
|
+
const rf=E=>E.m?{m:E.m.id,pt:isCol(E.m)?'a':pt}:{g:E.g}; // a column stores a canonical pt 'a' (its two wp are one plan point)
|
|
3940
|
+
const id='d'+Date.now()+'_'+(dimSeq++);made.push(id);
|
|
3941
|
+
P.dims.push({id,a:A.p.slice(),b:B.p.slice(),axis:'x',off,rot,aRef:rf(A),bRef:rf(B)});}
|
|
3942
|
+
if(!made.length){toast('Those members share a spacing point — nothing to dimension');return;}
|
|
3943
|
+
pushUndo(pv);selIds.clear();selGridIds.clear();selDimIds=new Set(made);dimsVisible=true;updDimToggle();render();sync3D();
|
|
3944
|
+
toast('Placed '+made.length+' spacing dimension'+(made.length===1?'':'s')+' — they follow their members and grids');
|
|
3945
|
+
}
|
|
3946
|
+
// ── F8 double-click a dimension to edit its value ─────────────────────────────────────────────────────
|
|
3947
|
+
// The popup drives the typed length into the geometry. ◄/► pick which end(s) move (both on → symmetric, ½
|
|
3948
|
+
// each; last choice persists). The pin is the DIM'S OWN magnetic switch: pinned = the dim follows its beams
|
|
3949
|
+
// and editing the value moves them; unpinned = the link goes dormant (kept, not detached) and the dim is a
|
|
3950
|
+
// plain annotation until re-pinned. The pin applies IMMEDIATELY on toggle (its own undo step — QA 2026-07-16);
|
|
3951
|
+
// the typed value commits on Enter; Esc discards the value only.
|
|
3952
|
+
// Crisp inline-SVG toggle glyphs (text ◄/► rasterize fuzzy at this size).
|
|
3953
|
+
const DIMEDIT_GLY={
|
|
3954
|
+
left:'<svg viewBox="0 0 12 12" width="12" height="12" aria-hidden="true"><path d="M8.7 1.6v8.8L2.9 6z" fill="currentColor"/></svg>',
|
|
3955
|
+
right:'<svg viewBox="0 0 12 12" width="12" height="12" aria-hidden="true"><path d="M3.3 1.6v8.8L9.1 6z" fill="currentColor"/></svg>',
|
|
3956
|
+
pin:'<svg viewBox="0 0 12 12" width="12" height="12" aria-hidden="true"><g fill="currentColor"><circle cx="7.6" cy="4.4" r="2.6"/><path d="M6.2 6.6 2.2 10.6l-.8-.8 4-4z"/></g></svg>'};
|
|
3957
|
+
let _dimEditAway=null;
|
|
3958
|
+
function openDimEdit(did){
|
|
3959
|
+
const d=P.dims.find(x=>x.id===did);if(!d)return;
|
|
3960
|
+
let ends=null;try{ends=JSON.parse(localStorage.getItem('steel:dimEdit:ends:v1'));}catch(_){}
|
|
3961
|
+
if(!ends||typeof ends!=='object'||(!ends.l&&!ends.r))ends={l:false,r:true}; // default: the right (second) end drives
|
|
3962
|
+
dimEdit={id:did,l:!!ends.l,r:!!ends.r,pin:d.pin!==false}; // pin = THIS dim's state (default pinned)
|
|
3963
|
+
render();buildDimEditPop();
|
|
3964
|
+
_dimEditAway=ev=>{const p=document.getElementById('dimEditPop');if(p&&!p.contains(ev.target))closeDimEdit();}; // click outside cancels
|
|
3965
|
+
setTimeout(()=>{if(dimEdit)document.addEventListener('pointerdown',_dimEditAway,true);},0); // deferred so the opening dblclick doesn't close it
|
|
3966
|
+
}
|
|
3967
|
+
function closeDimEdit(){dimEdit=null;const p=document.getElementById('dimEditPop');if(p)p.remove();
|
|
3968
|
+
if(_dimEditAway){document.removeEventListener('pointerdown',_dimEditAway,true);_dimEditAway=null;}}
|
|
3969
|
+
function buildDimEditPop(){
|
|
3970
|
+
if(!dimEdit)return;const d=P.dims.find(x=>x.id===dimEdit.id);if(!d){closeDimEdit();return;}
|
|
3971
|
+
let pop=document.getElementById('dimEditPop');
|
|
3972
|
+
if(!pop){pop=document.createElement('div');pop.id='dimEditPop';document.body.appendChild(pop);
|
|
3973
|
+
pop.addEventListener('keydown',e=>{e.stopPropagation();if(e.key==='Escape'){e.preventDefault();closeDimEdit();}});} // the popup owns its keys — the global editor/tool shortcuts never see them (Codex R2 #8)
|
|
3974
|
+
const cur=dimValueText(dimGeo(d.a,d.b,d.axis,d.off,d.rot).px);
|
|
3975
|
+
if(dimEdit.cur0==null)dimEdit.cur0=cur; // the value the popup OPENED with — commit compares against it so Enter-without-change is a clean no-op (no phantom undo — Codex final-review #5)
|
|
3976
|
+
const prevVal=document.getElementById('dimEditVal'),keep=prevVal?prevVal.value:null; // a toggle click rebuilds the popup — the user's typed value must survive it (pr-review-toolkit #2)
|
|
3977
|
+
const nM=(d.aRef&&d.aRef.m?1:0)+(d.bRef&&d.bRef.m?1:0),nG=(d.aRef&&d.aRef.g?1:0)+(d.bRef&&d.bRef.g?1:0),nLinked=nM+nG;
|
|
3978
|
+
const linkedTxt=[nM?nM+' member end'+(nM>1?'s':''):null,nG?nG+' grid line'+(nG>1?'s':''):null].filter(Boolean).join(' + ');
|
|
3979
|
+
pop.innerHTML=`<input id=dimEditVal value="${esc(keep!=null?keep:cur)}" autocomplete=off spellcheck=false aria-label="Dimension value">`
|
|
3980
|
+
+`<div class=dimEditRow>`
|
|
3981
|
+
+`<button id=dimEditL class="dimEditTog${dimEdit.l?' on':''}" data-tip="Move the LEFT end to reach the value" aria-label="Drive the left end">${DIMEDIT_GLY.left}</button>`
|
|
3982
|
+
+(nLinked?`<button id=dimEditPin class="dimEditTog pin${dimEdit.pin?' on':''}" data-tip="${dimEdit.pin?'Pinned — the dimension follows its beams, and the value moves them':'Unpinned — the link is dormant; the dimension stays put and the value only moves the dimension'}" aria-label="Pin to steel">${DIMEDIT_GLY.pin}</button>`:'')
|
|
3983
|
+
+`<button id=dimEditR class="dimEditTog${dimEdit.r?' on':''}" data-tip="Move the RIGHT end to reach the value" aria-label="Drive the right end">${DIMEDIT_GLY.right}</button>`
|
|
3984
|
+
+`</div>`
|
|
3985
|
+
+`<div class=dimEditHint>${nLinked?('🔗 linked to '+linkedTxt+(dimEdit.pin?'':' · unpinned')):'not linked to steel'}</div>`;
|
|
3986
|
+
const g=dimGeo(d.a,d.b,d.axis,d.off,d.rot),ctm=svg.getScreenCTM(),spt=svg.createSVGPoint();spt.x=g.mid[0];spt.y=g.mid[1];
|
|
3987
|
+
const sp=spt.matrixTransform(ctm);pop.style.left=Math.round(sp.x)+'px';pop.style.top=Math.round(sp.y+14)+'px';pop.style.display='block';
|
|
3988
|
+
const val=document.getElementById('dimEditVal');
|
|
3989
|
+
val.onkeydown=e=>{e.stopPropagation();if(e.key==='Enter'){e.preventDefault();dimEditCommit();}else if(e.key==='Escape'){e.preventDefault();closeDimEdit();}};
|
|
3990
|
+
val.oninput=()=>val.classList.remove('bad');
|
|
3991
|
+
const setTog=k=>{if(k==='pin'){dimEdit.pin=!dimEdit.pin; // applies IMMEDIATELY (QA 2026-07-16: a toggle that waits for Enter reads as broken) — undoable; re-pinning reanchors live, unpinning freezes now
|
|
3992
|
+
edit(()=>{const dd=P.dims.find(x=>x.id===dimEdit.id);if(dd&&(dd.aRef||dd.bRef)){if(dimEdit.pin)delete dd.pin;else dd.pin=false;}});}
|
|
3993
|
+
else{const other=k==='l'?'r':'l';if(dimEdit[k]&&!dimEdit[other])return; // keep at least one end driven
|
|
3994
|
+
dimEdit[k]=!dimEdit[k];try{localStorage.setItem('steel:dimEdit:ends:v1',JSON.stringify({l:dimEdit.l,r:dimEdit.r}));}catch(_){}}
|
|
3995
|
+
buildDimEditPop();const v2=document.getElementById('dimEditVal');if(v2)v2.focus();};
|
|
3996
|
+
document.getElementById('dimEditL').onclick=()=>setTog('l');
|
|
3997
|
+
document.getElementById('dimEditR').onclick=()=>setTog('r');
|
|
3998
|
+
{const pb=document.getElementById('dimEditPin');if(pb)pb.onclick=()=>setTog('pin');}
|
|
3999
|
+
val.focus();val.select();
|
|
4000
|
+
}
|
|
4001
|
+
function dimEditCommit(){
|
|
4002
|
+
if(!dimEdit)return;const d=P.dims.find(x=>x.id===dimEdit.id);if(!d){closeDimEdit();return;}
|
|
4003
|
+
const val=document.getElementById('dimEditVal');if(!val)return;const inches=parseLen(val.value);
|
|
4004
|
+
if(inches==null){val.classList.add('bad');return;}
|
|
4005
|
+
if(val.value.trim()===dimEdit.cur0){closeDimEdit();return;} // Enter without changing the value = a clean close, not a phantom undo step (Codex final-review #5)
|
|
4006
|
+
const targetPx=inches*FT/12; // parseLen returns INCHES; dimGeo/wp are display units (Codex R2 #8)
|
|
4007
|
+
if(!isFinite(targetPx)||!(targetPx>=1)){val.classList.add('bad');return;} // reject 0 / negative / sub-pixel / Infinity — a degenerate target would collapse the member onto the datum or fling it to infinity (Codex code-review #2 + final-review #4)
|
|
4008
|
+
const g=dimGeo(d.a,d.b,d.axis,d.off,d.rot);
|
|
4009
|
+
let ux,uy;const vx=g.p2[0]-g.p1[0],vy=g.p2[1]-g.p1[1],vl=Math.hypot(vx,vy);
|
|
4010
|
+
if(vl>1e-6){ux=vx/vl;uy=vy/vl;}
|
|
4011
|
+
else if(d.axis!=='free'){const a=d.rot||0;if(d.axis==='x'){ux=Math.cos(a);uy=Math.sin(a);}else{ux=-Math.sin(a);uy=Math.cos(a);}} // zero-span x/y → direction from rot+axis (Codex R2 #6)
|
|
4012
|
+
else{toast('This dimension is zero-length — an aligned (free) dim has no direction to set');closeDimEdit();return;}
|
|
4013
|
+
if(ux<-1e-9||(Math.abs(ux)<1e-9&&uy<0)){ux=-ux;uy=-uy;} // canonicalize to +screen-X, +screen-Y tiebreak (Codex R2 #9)
|
|
4014
|
+
const deltaPx=targetPx-g.px,pa=d.a[0]*ux+d.a[1]*uy,pb=d.b[0]*ux+d.b[1]*uy,leftIsA=pa<=pb;
|
|
4015
|
+
const nd=(dimEdit.l?1:0)+(dimEdit.r?1:0);if(!nd){toast('Turn on at least one end (◄ / ►)');return;}
|
|
4016
|
+
const share=deltaPx/nd,aDriven=leftIsA?dimEdit.l:dimEdit.r,bDriven=leftIsA?dimEdit.r:dimEdit.l;
|
|
4017
|
+
const aRef=d.aRef,bRef=d.bRef,gPin=r=>dimEdit.pin&&r&&r.g; // a pin-ON grid anchor is a passive datum: the dim follows the grid, never the reverse…
|
|
4018
|
+
let effA=aDriven?1:0,effB=bDriven?1:0; // …so a grid end's share REDIRECTS to the opposite end — the typed value still lands, the STEEL moves (QA 2026-07-16: "beams still should move")
|
|
4019
|
+
if(effA&&gPin(aRef)){effA=0;if(!gPin(bRef))effB+=1;}
|
|
4020
|
+
if(effB&&gPin(bRef)){effB=0;if(!gPin(aRef))effA+=1;}
|
|
4021
|
+
if(!(effA||effB)){toast('Both ends sit on grid lines — a grid can’t be moved from a dimension; unpin 📌 to edit the dimension only');return;}
|
|
4022
|
+
const dA=leftIsA?[-ux,-uy]:[ux,uy],dB=leftIsA?[ux,uy]:[-ux,-uy];
|
|
4023
|
+
const mvA=[dA[0]*share*effA,dA[1]*share*effA],mvB=[dB[0]*share*effB,dB[1]*share*effB];
|
|
4024
|
+
const redirected=(aDriven&&gPin(aRef))||(bDriven&&gPin(bRef));
|
|
4025
|
+
if(dimEdit.pin&&aRef&&bRef&&aRef.m&&bRef.m&&aRef.m===bRef.m){ // pin ON validates the FULL ref pair for same-member conflicts, driven or not (Codex R3 #1 / R4 #1); .m guards keep a grid pair out (undefined===undefined)
|
|
4026
|
+
if(aRef.pt===bRef.pt){toast('Both ends point at the same member point — nothing to resize');return;}
|
|
4027
|
+
if(aRef.pt==='mid'||bRef.pt==='mid'){toast('One end is this member’s midpoint — unpin 📌 to edit the dimension only');return;}}
|
|
4028
|
+
const mem=id=>(P.members||[]).find(x=>x&&x.id===id),addv=(p,v)=>[p[0]+v[0],p[1]+v[1]];
|
|
4029
|
+
edit(()=>{
|
|
4030
|
+
if(aRef||bRef){if(dimEdit.pin)delete d.pin;else d.pin=false;} // the popup's pin state commits onto the dim. Unpinned keeps the refs DORMANT (reanchor skips d.pin===false), so the typed value sticks AND the link can be re-pinned later — supersedes the old detach-both (Codex R1 #12) now that magnetism itself is pin-gated.
|
|
4031
|
+
const doEnd=(driven,ref,mv,rawKey)=>{if(!driven)return;
|
|
4032
|
+
if(dimEdit.pin&&ref){const m=mem(ref.m);if(m&&Array.isArray(m.wp)&&m.wp.length>=2){
|
|
4033
|
+
if(ref.pt==='mid'||m.role==='column'){m.wp[0]=addv(m.wp[0],mv);m.wp[1]=addv(m.wp[1],mv);} // mid = rigid; a COLUMN always moves rigidly (one plumb plan point — both wp stay coincident)
|
|
4034
|
+
else if(ref.pt==='a')m.wp[0]=addv(m.wp[0],mv);else m.wp[1]=addv(m.wp[1],mv);}}
|
|
4035
|
+
else{d[rawKey]=addv(d[rawKey],mv);}}; // pin OFF, or an unref'd end → move the dim's own coord
|
|
4036
|
+
doEnd(effA>0,aRef,mvA,'a');doEnd(effB>0,bRef,mvB,'b');
|
|
4037
|
+
});
|
|
4038
|
+
if(redirected)toast('The grid-linked end stays put — the value moved the other end instead');
|
|
4039
|
+
closeDimEdit();
|
|
4040
|
+
}
|
|
3742
4041
|
let dimLastPtr=null; // last canvas pointer during placement, for axis-key live refresh
|
|
3743
4042
|
function dimRefreshPrev(){if(!dimMode||!dimDraft||!dimLastPtr)return;
|
|
3744
4043
|
const g=document.getElementById('dimPrevG');if(!g)return;
|
|
@@ -4050,6 +4349,8 @@ svg.addEventListener('pointerdown',e=>{if(e.button!==0)return;const t=e.target;
|
|
|
4050
4349
|
e.preventDefault();return;}
|
|
4051
4350
|
if(gridPick){let q=toSvg(e),x=q.x,y=q.y;if(!e.altKey){buildSnap(null);const sn=snap(x,y);x=sn.x;y=sn.y;}snapClear(); // armed pick-origin → one snapped click sets the grid's 1-A corner (undoable)
|
|
4052
4351
|
gridPick=false;gridSetPickClass();if(P.grid)edit(()=>{P.grid.origin=[x,y];});else panel();e.preventDefault();return;}
|
|
4352
|
+
if(qdPick&&(view3d||mode!=='sel'||dimMode||csaxisMode||geoMode||cmTool||picking||dimSplitMode)){qdPick=null;setQdPickCls();} // a stale F7 station pick must never fire while/after ANOTHER tool runs — the first click under that tool disarms it instead (Codex final-review #3)
|
|
4353
|
+
if(qdPick){let q=toSvg(e),x=q.x,y=q.y;if(!e.altKey){buildSnap(null);const sn=snap(x,y);x=sn.x;y=sn.y;}snapClear();const pp=qdPick;qdPick=null;setQdPickCls();quickDimSpacing(pp.pt,[x,y]);e.preventDefault();return;} // F7 grid quick-dim: the armed one-shot station pick consumes this click BEFORE the grid-line hit test — the picked station often lies ON a grid line, which must not start a grid drag instead (Codex final-review #6)
|
|
4053
4354
|
{const gb=t.closest&&t.closest('g.gridbubg'),ghit=(t.classList&&t.classList.contains('gridhit'))?t:null; // grid line body OR label bubble → drag slides the line; a no-move click selects it (bubble double-click still renames)
|
|
4054
4355
|
const gel=gb||ghit;
|
|
4055
4356
|
if(gel&&mode==='sel'&&!geoMode&&!dimSplitMode&&!picking&&P.grid){
|
|
@@ -4063,11 +4364,18 @@ svg.addEventListener('pointerdown',e=>{if(e.button!==0)return;const t=e.target;
|
|
|
4063
4364
|
if(gridMode)setGridMode(false); // any other canvas click leaves the grid panel — selection takes the panel back (fields commit on blur first)
|
|
4064
4365
|
if(dimStyleMode)setDimStyleMode(false); // …and the Dimension style pane, so clicking a dim hands the panel to its inspector
|
|
4065
4366
|
if(dimSplitMode&&selDimIds.size&&dimsVisible&&mode==='sel'){let q=toSvg(e),x=q.x,y=q.y;if(!e.altKey){buildSnap(null);const sn=snap(x,y);x=sn.x;y=sn.y;}snapClear();dimSplitAt([x,y]);e.preventDefault();return;} // split mode → each click inserts a point into the selected dim under it
|
|
4066
|
-
if(t.dataset.dimend!=null&&mode==='sel'){const id=t.dataset.dim,end=+t.dataset.dimend;
|
|
4067
|
-
|
|
4367
|
+
if(t.dataset.dimend!=null&&mode==='sel'){const id=t.dataset.dim,end=+t.dataset.dimend; // drag a selected dim's anchor handle. PINNED + member-linked = GRIP EDIT: the handle drives the member's work point (rigid for mid/column), the dim follows — the drag mirror of the F8 pin (QA 2026-07-16). Unpinned / grid-linked / free = re-measure (snaps; exclude this dim so the end can't snap to its own line/midpoint — and in grip mode the member too, so it can't snap to itself).
|
|
4368
|
+
const d0=P.dims.find(x=>x.id===id),ref0=d0&&d0[end===0?'aRef':'bRef'];let gm=null;
|
|
4369
|
+
if(d0&&d0.pin!==false&&ref0&&ref0.m){const m=(P.members||[]).find(x=>x&&x.id===ref0.m);
|
|
4370
|
+
if(isDimAnchorableMember(m))gm={mid:m.id,pt:ref0.pt,rigid:ref0.pt==='mid'||(m.role||'beam')==='column',ow:[m.wp[0].slice(),m.wp[1].slice()],oa:(end===0?d0.a:d0.b).slice()};}
|
|
4371
|
+
buildSnap(gm?new Set([id,gm.mid]):id);drag={type:'dimend',id,end,grip:gm,pre:snapshot()};svg.setPointerCapture(e.pointerId);e.preventDefault();return;}
|
|
4372
|
+
if(t.dataset.dim&&mode==='sel'&&selDimOK()){const did=t.dataset.dim,add=e.ctrlKey||e.metaKey;
|
|
4373
|
+
if(!add&&_lastDimDown&&_lastDimDown.id===did&&(e.timeStamp-_lastDimDown.t)<400){_lastDimDown=null;selDimIds=new Set([did]);openDimEdit(did);e.preventDefault();return;} // F8: double-click a dim → value editor. Detected HERE (in pointerdown), NOT via the native dblclick event, so the select-render between the two clicks can't swallow it (Codex R4 #2).
|
|
4374
|
+
_lastDimDown={id:did,t:e.timeStamp};
|
|
4375
|
+
selIds.clear();if(!add)selGridIds.clear(); // a plain dim click is exclusive (clears member + grid selection); Ctrl keeps an intentional mixed grid/dim selection. Dimensions select-switch off → click falls through (inert)
|
|
4068
4376
|
if(e.ctrlKey||e.metaKey){selDimIds.has(did)?selDimIds.delete(did):selDimIds.add(did);render();return;} // Ctrl+click toggles this dim within the dim selection
|
|
4069
4377
|
selDimIds=new Set([did]);const d=P.dims.find(x=>x.id===did); // plain click → exactly this dim (collapses any multi-selection, so Delete removes only it)
|
|
4070
|
-
if(d){drag={type:'dim',id:d.id,pre:snapshot()};svg.setPointerCapture(e.pointerId);e.preventDefault();}render();return;} // drag the dim line to slide its offset
|
|
4378
|
+
if(d){drag={type:'dim',id:d.id,pre:snapshot(),cx0:e.clientX,cy0:e.clientY,moved:false};svg.setPointerCapture(e.pointerId);e.preventDefault();}render();return;} // drag the dim line to slide its offset (cx0/cy0 + moved arm a movement threshold so a click/double-click doesn't nudge off — Codex code-review #4)
|
|
4071
4379
|
if(selDimIds.size){selDimIds.clear();render();} // ANY other click (member / handle / empty / marquee-start, incl. Ctrl) is dim-exclusive → drop the dim selection so Delete never hits a stale dim
|
|
4072
4380
|
if(selGridIds.size&&!(e.ctrlKey||e.metaKey||e.shiftKey)){selGridIds.clear();render();} // a plain (non-additive) click elsewhere drops the grid selection too; Ctrl/Shift preserves it so grid marquees stay additive
|
|
4073
4381
|
if(geoMode==='split'&&selIds.size===1){const id=[...selIds][0],m=byId(id);
|
|
@@ -4151,7 +4459,7 @@ svg.addEventListener('pointermove',e=>{
|
|
|
4151
4459
|
else{a=[drag.origA[0]+dxc,drag.origA[1]+dyc];b=[drag.origB[0]+dxc,drag.origB[1]+dyc];snapClear();}
|
|
4152
4460
|
gridReadout(e,gridDelta(Math.hypot(a[0]-drag.origA[0],a[1]-drag.origA[1])),'');
|
|
4153
4461
|
}
|
|
4154
|
-
line.a=a;line.b=b;refreshGridLayer();const dl=svg.querySelector(`line.gridln[data-gl="${drag.gi}"]`);if(dl)dl.classList.add('gdrag');return;}
|
|
4462
|
+
line.a=a;line.b=b;refreshGridLayer();refreshMagneticDims2D();const dl=svg.querySelector(`line.gridln[data-gl="${drag.gi}"]`);if(dl)dl.classList.add('gdrag');return;} // free-line drag mutates P.grid.lines LIVE → gl:-anchored dims track it (Codex final-review #2)
|
|
4155
4463
|
if(drag.type==='gridline'){const dxc=p.x-drag.startPt[0],dyc=p.y-drag.startPt[1];
|
|
4156
4464
|
if(!drag.moved){if(Math.hypot(dxc,dyc)<=4/zoom)return;drag.moved=true; // past the tolerance = a drag, not a click
|
|
4157
4465
|
const along=drag.axis==='v'?Math.abs(dyc):Math.abs(dxc),perp=drag.axis==='v'?Math.abs(dxc):Math.abs(dyc);
|
|
@@ -4177,11 +4485,17 @@ svg.addEventListener('pointermove',e=>{
|
|
|
4177
4485
|
const applied=gc.moveGridLineEnd(P.grid,ppf,drag.axis,drag.gi,drag.end,np); // 12" min length; near the full span → back to auto
|
|
4178
4486
|
gridReadout(e,gridDelta((applied!=null?applied:np)-drag.origEnd),'');
|
|
4179
4487
|
}
|
|
4180
|
-
refreshGridLayer();
|
|
4488
|
+
refreshGridLayer();refreshMagneticDims2D(); // moveGridLine mutates P.grid LIVE — grid-anchored dims must track the drag, not jump at pointer-up (Codex final-review #2)
|
|
4181
4489
|
const dl=svg.querySelector(`line.gridln[data-g${drag.axis}="${drag.gi}"]`);if(dl)dl.classList.add('gdrag'); // highlight the line in flight
|
|
4182
4490
|
return;}
|
|
4183
|
-
if(drag.type==='dimend'){const d=P.dims.find(x=>x.id===drag.id);if(d){let x=p.x,y=p.y;if(!e.altKey){const sn=snap(x,y);x=sn.x;y=sn.y;sn.hit?snapMark(x,y):snapClear();}else snapClear();
|
|
4184
|
-
|
|
4491
|
+
if(drag.type==='dimend'){const d=P.dims.find(x=>x.id===drag.id);if(d){let x=p.x,y=p.y;if(!e.altKey){const sn=snap(x,y);x=sn.x;y=sn.y;sn.hit?snapMark(x,y):snapClear();}else snapClear();
|
|
4492
|
+
if(drag.grip){const gp=drag.grip,m=(P.members||[]).find(mm=>mm&&mm.id===gp.mid); // pinned grip: the handle DRIVES the member — end wp follows the pointer; mid/column translate rigidly (delta from the grabbed anchor), so the anchor still lands exactly at [x,y]
|
|
4493
|
+
if(m&&Array.isArray(m.wp)&&m.wp.length>=2){
|
|
4494
|
+
if(gp.rigid){const dx=x-gp.oa[0],dy=y-gp.oa[1];m.wp[0]=[gp.ow[0][0]+dx,gp.ow[0][1]+dy];m.wp[1]=[gp.ow[1][0]+dx,gp.ow[1][1]+dy];}
|
|
4495
|
+
else if(gp.pt==='a')m.wp[0]=[x,y];else m.wp[1]=[x,y];}}
|
|
4496
|
+
if(drag.end===0)d.a=[x,y];else d.b=[x,y];render();}return;} // dragging a dim anchor → snap + re-measure live (render() reanchors every OTHER magnetic dim off the grip-moved member too)
|
|
4497
|
+
if(drag.type==='dim'){if(!drag.moved){if(Math.hypot(e.clientX-drag.cx0,e.clientY-drag.cy0)<4)return;drag.moved=true;} // below the threshold it's a click/double-click, not an offset slide — don't touch off or write an undo entry (Codex code-review #4)
|
|
4498
|
+
const d=P.dims.find(x=>x.id===drag.id);if(d){d.off=dimOffFromPointer(d.a,d.b,d.axis,[p.x,p.y],d.rot);render();}return;}
|
|
4185
4499
|
if(drag.type==='marquee'){const x=Math.min(drag.x0,p.x),y=Math.min(drag.y0,p.y),w=Math.abs(p.x-drag.x0),h=Math.abs(p.y-drag.y0);
|
|
4186
4500
|
drag.window=(e.clientX>=drag.sx0); // Tekla: drag L→R = window (enclose); R→L = crossing (touch)
|
|
4187
4501
|
drag.rect.classList.toggle('window',drag.window); // solid rect = window, dashed = crossing (visual affordance)
|
|
@@ -4210,12 +4524,12 @@ svg.addEventListener('pointermove',e=>{
|
|
|
4210
4524
|
else snapClear();
|
|
4211
4525
|
for(const it of drag.items){const m=byId(it.id);if(!m)continue;
|
|
4212
4526
|
m.wp[0]=[it.o0[0]+dx,it.o0[1]+dy];m.wp[1]=[it.o1[0]+dx,it.o1[1]+dy];updateLine(m);}
|
|
4213
|
-
if(selIds.size<=2)for(const m of sel2d())updateHandles(m);return;}
|
|
4527
|
+
if(selIds.size<=2)for(const m of sel2d())updateHandles(m);refreshMagneticDims2D();return;} // F9: magnetic dims track the moving members live
|
|
4214
4528
|
// endpoint
|
|
4215
4529
|
const m=byId(drag.id);if(!m)return;let x=p.x,y=p.y;
|
|
4216
4530
|
if(e.shiftKey){[x,y]=orthoLock(drag.anchor[0],drag.anchor[1],x,y);snapClear();} // ortho endpoint — local frame when set, else screen H/V
|
|
4217
4531
|
else if(!e.altKey){const sn=snap(x,y,drag.anchor);x=sn.x;y=sn.y;sn.hit?snapMark(x,y):snapClear();}else snapClear(); // anchor = the member's fixed end → ⟂/∥ to a target line
|
|
4218
|
-
m.wp[drag.h]=[x,y];updateLine(m);updateHandles(m);
|
|
4532
|
+
m.wp[drag.h]=[x,y];updateLine(m);updateHandles(m);refreshMagneticDims2D(); // F9: magnetic dims track the moving endpoint live
|
|
4219
4533
|
{let g=document.getElementById('epPrevG');if(!g){g=document.createElementNS(SVGNS,'g');g.id='epPrevG';g.setAttribute('pointer-events','none');svg.appendChild(g);}epPrevDraw(g,drag.orig,drag.anchor,[x,y],m);}}); // live moved + length readout
|
|
4220
4534
|
svg.addEventListener('pointerup',()=>{if(!drag)return;snapClear();epPrevClear();
|
|
4221
4535
|
if(drag.type==='gridfree'){const moved=drag.moved,pre=drag.pre,add=drag.add,geo=gridGeo(),line=geo&&(geo.lines||[])[drag.gi],gid='gl:'+(line&&line.id!=null?line.id:drag.gi);drag=null;gridReadoutHide();snapOnlyClear2d();
|
|
@@ -4247,10 +4561,22 @@ svg.addEventListener('pointerup',()=>{if(!drag)return;snapClear();epPrevClear();
|
|
|
4247
4561
|
return;}
|
|
4248
4562
|
if(drag.pre&&snapshot()!==drag.pre)pushUndo(drag.pre); // armed move/copy committed (copy always changed geometry via its clones)
|
|
4249
4563
|
const wasCopy=drag.copy;if(!anyToolActive())snapOnlyClear2d();drag=null;render();if(wasCopy)toast('Copied '+selIds.size+' member'+(selIds.size===1?'':'s'));return;} // a grab move/copy was the operation → single-shot override clears
|
|
4564
|
+
if(drag.type==='dimend'&&drag.grip){/* pinned grip drag moved the MEMBER — the ref stays exactly as it was */}
|
|
4565
|
+
else if(drag.type==='dimend'){const d=P.dims.find(x=>x.id===drag.id); // F9: a hand-dragged anchor RE-LINKS to whatever it landed on (member point / grid line) so magnetism survives handle moves (QA 2026-07-16); a free-space drop detaches so the manual position wins (Codex R1 #13). Only when it actually moved.
|
|
4566
|
+
if(d&&drag.pre&&snapshot()!==drag.pre){const rk=drag.end===0?'aRef':'bRef',had=!!d[rk];
|
|
4567
|
+
const nr=dimRefAtPoint(P,drag.end===0?d.a:d.b,d);
|
|
4568
|
+
if(nr){d[rk]=nr;toast((nr.g?'Dimension end linked to grid line':'Dimension end linked to member')+(d.pin===false?' — unpinned':''));}
|
|
4569
|
+
else{delete d[rk];if(had)toast('Dimension end unlinked');}}}
|
|
4570
|
+
if((drag.type==='dim'||drag.type==='dimend')&&drag.pre&&snapshot()!==drag.pre)_lastDimDown=null; // a dim that was actually dragged (off slid / anchor moved) must not pair with the next click as a double-click (Codex code-review #5)
|
|
4250
4571
|
if(drag.pre&&snapshot()!==drag.pre)pushUndo(drag.pre);
|
|
4251
4572
|
if(!anyToolActive())snapOnlyClear2d(); // a select-mode drag WAS the operation → the override was single-shot
|
|
4252
4573
|
drag=null;render();});
|
|
4253
|
-
svg.addEventListener('pointercancel',()=>{epPrevClear();if(drag
|
|
4574
|
+
svg.addEventListener('pointercancel',()=>{epPrevClear();if(!drag)return; // a cancelled pointer must not strand a half-applied drag — revert to the pre-drag snapshot (member/dim/dimend/grab/grid), mirroring the Esc-mid-drag path (Codex R1 #3)
|
|
4575
|
+
const pre=drag.pre,wasGrid=drag.type==='gridline'||drag.type==='gridfree';
|
|
4576
|
+
if(drag.type==='marquee'&&drag.rect)drag.rect.remove();
|
|
4577
|
+
_lastDimDown=null; // a cancelled gesture must not pair with the next click as a double-click (Codex code-review #5)
|
|
4578
|
+
drag=null;snapClear();gridReadoutHide();if(wasGrid||!anyToolActive())snapOnlyClear2d();
|
|
4579
|
+
if(pre)apply(pre);else render();});
|
|
4254
4580
|
svg.addEventListener('dblclick',e=>{ // dbl-click a grid bubble → rename that label in place
|
|
4255
4581
|
const at=document.elementFromPoint(e.clientX,e.clientY); // the pointer capture the drag takes retargets dblclick to the svg root — resolve the bubble by position, not e.target
|
|
4256
4582
|
const gb=at&&at.closest&&at.closest('g.gridbubg');
|
|
@@ -4260,10 +4586,10 @@ svg.addEventListener('dblclick',e=>{ // dbl-click a grid bubble → rename tha
|
|
|
4260
4586
|
function setMode(){document.body.classList.toggle('add',mode==='add');document.getElementById('mAdd').classList.toggle('on',mode==='add');
|
|
4261
4587
|
picking=false;pickKind='profile';pickEnd=null; // a pick armed in one mode must never bleed into the other (an inspector ⌖ pick would otherwise show the Add panel's button pre-armed)
|
|
4262
4588
|
if(mode!=='add'){drawDraft=null;drawPrevClear();cmHudClose();if(view3d&&window.Steel3DView&&window.Steel3DView.drClear3d)window.Steel3DView.drClear3d();}} // leaving Add-member drops the in-progress start + preview, closes any open typed-entry HUD, and clears the 3D draw start (else a stale Add token could revalidate on re-arm — Codex)
|
|
4263
|
-
document.getElementById('mAdd').onclick=()=>{if(dimMode){dimMode=false;setDimMode();}if(csaxisMode){csaxisMode=false;setCsMode();}if(cmTool)disarmCm();
|
|
4589
|
+
document.getElementById('mAdd').onclick=()=>{if(dimMode){dimMode=false;setDimMode();}if(csaxisMode){csaxisMode=false;setCsMode();}if(cmTool)disarmCm();if(qdPick){qdPick=null;setQdPickCls();}
|
|
4264
4590
|
if(view3d&&window.Steel3DView){const dm=document.getElementById('m3dDim');if(dm&&dm.classList.contains('on'))window.Steel3DView.toggleDimTool();if(window.Steel3DView.disarmFrame3d)window.Steel3DView.disarmFrame3d();} // the 3D dim tool + the local frame share the left-click — disarm both when entering add mode
|
|
4265
4591
|
selDimIds.clear();dimStyleMode=false;mode=(mode==='add'?'sel':'add');if(mode==='add')selIds.clear();else if(window.Steel3DView&&window.Steel3DView.drClear3d)window.Steel3DView.drClear3d();snapOnlyClear2d();setMode();render();setLastCmd('Add member',()=>{if(mode!=='add'){if(dimMode){dimMode=false;setDimMode();}mode='add';selIds.clear();setMode();render();}});}; // entering add/sel disarms the Dimension + set-axes tools + the Dimension style pane + drops any dim selection + reverts a snap override; leaving add clears the 3D draw draft
|
|
4266
|
-
document.getElementById('dimB').onclick=()=>{if(csaxisMode){csaxisMode=false;setCsMode();}dimMode=!dimMode;setDimMode();render();setLastCmd('Dimension',()=>{if(!dimMode){dimMode=true;setDimMode();render();}});};
|
|
4592
|
+
document.getElementById('dimB').onclick=()=>{if(csaxisMode){csaxisMode=false;setCsMode();}if(qdPick){qdPick=null;setQdPickCls();}dimMode=!dimMode;setDimMode();render();setLastCmd('Dimension',()=>{if(!dimMode){dimMode=true;setDimMode();render();}});};
|
|
4267
4593
|
document.getElementById('csSetB').onclick=()=>{csaxisMode=!csaxisMode;setCsMode();render();};
|
|
4268
4594
|
document.getElementById('csResetB').onclick=()=>{ if(view3d&&window.Steel3DView&&window.Steel3DView.clearFrame3d){window.Steel3DView.clearFrame3d();csSyncF3d();updCS();} else {resetFrame();render();} };
|
|
4269
4595
|
document.getElementById('csStat').onclick=()=>{ // click the Axes chip → reset to global (easy exit; mirrors ⋯ "Reset to global axes", and clears a set ◇ Plane)
|
|
@@ -4317,7 +4643,8 @@ document.getElementById('revB').onclick=()=>{const ids=reversedBeams(); // bea
|
|
|
4317
4643
|
toast(ids.length+' reversed beam'+(ids.length>1?'s':'')+' selected — press P to swap direction');}; // select reversed → review → P swaps them
|
|
4318
4644
|
document.getElementById('mrgB').onclick=()=>{const r=mergeCollinearJS(P.members); // conservative; result is undoable (Ctrl+Z)
|
|
4319
4645
|
if(!r.mergedAway){toast('Nothing to merge');return;}
|
|
4320
|
-
edit(()=>{
|
|
4646
|
+
edit(()=>{const aff=new Set(r.affectedIds);for(const d of (P.dims||[]))for(const rk of ['aRef','bRef'])if(d[rk]&&aff.has(d[rk].m))delete d[rk]; // F9: detach dim refs to every merged member before replacing P.members (safe-freeze; Codex R3 #3)
|
|
4647
|
+
P.members=r.members;selIds=new Set();selDimIds.clear();});
|
|
4321
4648
|
toast('Merged '+r.mergedAway+' segment'+(r.mergedAway===1?'':'s')+' into '+r.runs+' member'+(r.runs===1?'':'s'));};
|
|
4322
4649
|
document.getElementById('undoB').onclick=doUndo;
|
|
4323
4650
|
document.getElementById('redoB').onclick=doRedo;
|
|
@@ -4325,6 +4652,7 @@ document.getElementById('dragMoveB').onclick=()=>{setDragMove(!dragMoveOn);toast
|
|
|
4325
4652
|
setDragMove(dragMoveOn); // reflect the persisted state on load (body class + pill)
|
|
4326
4653
|
addEventListener('keydown',e=>{
|
|
4327
4654
|
const inForm=/^(INPUT|SELECT|TEXTAREA)$/.test((document.activeElement||{}).tagName);
|
|
4655
|
+
if(dimEdit){if(e.key==='Escape'){e.preventDefault();closeDimEdit();}return;} // F8 popup is modal — suppress every editor/tool shortcut (incl. Ctrl+Z under the popup). Its own input/buttons handle their keys and stopPropagation, so they never reach here (Codex R2 #8).
|
|
4328
4656
|
if(e.key==='Escape'&&moreOpen()){closeMore();moreBtn.focus();return;}
|
|
4329
4657
|
if(e.key==='Escape'&&xfMenuC.isOpen()){xfMenuC.close();return;}
|
|
4330
4658
|
if(lvOpen()){if(e.key==='Escape')closeLevelModal();return;} // the level modal is modal: no Delete/undo/tool keys mutate state underneath it
|
|
@@ -4356,6 +4684,7 @@ addEventListener('keydown',e=>{
|
|
|
4356
4684
|
else if(cmDraft&&cmDraft.vA){cmDraft.vA=null;cmRefreshPrev();panel();}else if(cmDraft){cmDraft=null;cmPrevClear();panel();}else{disarmCm();render();}return;} // Move/Copy Esc ladder: HUD → array dir A → base pick → exit tool
|
|
4357
4685
|
if(e.key==='Escape'&&csaxisMode){if(csDraft){csDraft=null;csPrevClear();}else{csaxisMode=false;setCsMode();}render();return;} // 1st Esc drops the in-progress origin, 2nd exits set-axes
|
|
4358
4686
|
if(e.key==='Enter'&&dimMode&&dimChainPrev){e.preventDefault();dimChainPrev=null;dimPrevClear();render();return;} // Enter ends a running chain
|
|
4687
|
+
if(e.key==='Escape'&&qdPick){qdPick=null;setQdPickCls();toast('Quick-dim cancelled');return;} // Esc disarms the F7 grid station pick (selection stays)
|
|
4359
4688
|
if(e.key==='Escape'&&dimMode){if(dimChainPrev){dimChainPrev=null;dimPrevClear();}else if(dimDraft){dimDraft=null;dimPrevClear();}else{dimMode=false;setDimMode();}render();return;} // Esc: end the chain → drop the in-progress dim → exit the tool
|
|
4360
4689
|
if(e.key==='Escape'&&selDimIds.size){if(dimSplitMode){dimSplitMode=false;snapClear();render();}else{selDimIds.clear();render();}return;} // Esc on a selected dim: end split mode → else deselect
|
|
4361
4690
|
if(e.key==='Escape'&&view3d&&mode==='add'){if(cmHudIsOpen()){cmHudClose();return;}if(window.Steel3DView&&window.Steel3DView.drEscape&&window.Steel3DView.drEscape())return;} // 3D draw: Esc closes an open typed-entry HUD first, then drops the in-progress start pick, then exits add mode (falls through below)
|
|
@@ -4381,6 +4710,7 @@ addEventListener('keydown',e=>{
|
|
|
4381
4710
|
return;}
|
|
4382
4711
|
if(!inForm&&!e.ctrlKey&&!e.metaKey&&!e.altKey&&e.key.toLowerCase()==='d'&&!view3d){e.preventDefault();dimMode=!dimMode;setDimMode();render();setLastCmd('Dimension',()=>{if(!dimMode){dimMode=true;setDimMode();render();}});return;} // D — toggle the Dimension tool
|
|
4383
4712
|
if(!inForm&&!e.ctrlKey&&!e.metaKey&&!e.altKey&&e.key.toLowerCase()==='a'){e.preventDefault();document.getElementById('mAdd').click();return;} // A — toggle the Add-member tool in 2D AND 3D (mirrors D=Dimension; plain 'a', Ctrl+A is still select-all). The mAdd click owns the arm/disarm-conflicts + setLastCmd logic.
|
|
4713
|
+
if(!inForm&&!e.ctrlKey&&!e.metaKey&&!e.altKey&&e.key.toLowerCase()==='q'&&!view3d&&mode==='sel'&&!dimMode&&!cmTool&&!geoMode&&!picking&&!csaxisMode&&!gridMode&&((sel2d()||[]).length>=1||selGridIds.size>=1)){e.preventDefault();quickDimSpacing(qdAnchorPt);return;} // Q — F7 quick-dim spacing. Fires on any active-plane member OR grid selection; quickDimSpacing itself toasts what it rejects (design: "toast what it rejected")
|
|
4384
4714
|
if(dimMode&&!inForm&&!e.ctrlKey&&!e.metaKey&&!e.altKey){const dk=e.key.toLowerCase();
|
|
4385
4715
|
if(dk==='x'||dk==='y'||dk==='f'){e.preventDefault();dimSetAxis(dk==='f'?'free':dk);dimDraft&&svg.querySelector('#dimPrevG')&&dimRefreshPrev();return;}
|
|
4386
4716
|
if(dk==='c'){e.preventDefault();toggleDimChain();return;}} // C — toggle chained (continuous) dimensioning
|
|
@@ -5969,6 +6299,7 @@ async function setView(on){
|
|
|
5969
6299
|
if(on){
|
|
5970
6300
|
if(dimMode||dimChain||dimSplitMode){disarmed2d=true;dimMode=dimChain=dimSplitMode=false;selDimIds.clear();setDimMode();document.body.classList.remove('dimsplit');} // entering 3D disarms the 2D dim/chain/split tools so their X/Y/F/S/Esc keys don't double-fire with the 3D tool
|
|
5971
6301
|
if(dimStyleMode){disarmed2d=true;dimStyleMode=false;} // …and closes the 2D Dimension style pane (it styles the 2D overlay only)
|
|
6302
|
+
if(qdPick){disarmed2d=true;qdPick=null;setQdPickCls();} // …and the F7 grid station pick (2D-only; a leaked pick would eat the first 3D-return click)
|
|
5972
6303
|
if(disarmed2d)render(); // repaint the 2D SVG + inspector ONCE, now that EVERY 2D-only tool is disarmed and view3d is still false (2D render path): they suppress callouts / draw pick hotspots (:2061,:2069) and take over #panel, and the return-to-2D path never render()s — so a render here (like the Esc paths) un-stales the canvas + panel. Deferred past the dim/dim-style disarm so it can't paint a still-armed Dimension panel (dimMode can coexist with grid/pick) that then goes stale.
|
|
5973
6304
|
if(cmTool){cmDraft=null;cmPrevClear();cmHudClose();} // Move/Copy stays armed across the view switch — only the in-progress 2D pick is dropped (it's in plan px)
|
|
5974
6305
|
if(selIds.size)sel3dDimIds.clear(); // a member selected in 2D wins over a stale 3D-dim selection
|
|
@@ -6536,7 +6867,7 @@ function setPlan(i){C.active=i;P=C.plans[i];
|
|
|
6536
6867
|
profs=[...new Set([...P.members.map(m=>m.profile), ...Object.keys(WT)])].sort();
|
|
6537
6868
|
// undo/redo is one GLOBAL stack (module-level, declared once) — NOT swapped per plane. A plane switch
|
|
6538
6869
|
// must not reset or re-scope undo, since snapshots are whole-model and selection/edits span sheets.
|
|
6539
|
-
selIds=new Set();findHits=new Set();selGridIds=new Set();picking=false;pickKind='profile';pickEnd=null;mode='sel';geoMode=null;setGeo(); // findHits + selGridIds reset per plan like selIds — a stale highlight (or, for grids, an index-based id) must not bleed onto another sheet (grids are per-plan). setGeo() clears body.geo/geoel so an armed Extend/Trim tool doesn't leave the grid crosshair on the next sheet
|
|
6870
|
+
selIds=new Set();findHits=new Set();selGridIds=new Set();picking=false;pickKind='profile';pickEnd=null;mode='sel';geoMode=null;setGeo();qdPick=null;setQdPickCls(); // findHits + selGridIds reset per plan like selIds — a stale highlight (or, for grids, an index-based id) must not bleed onto another sheet (grids are per-plan). setGeo() clears body.geo/geoel so an armed Extend/Trim tool doesn't leave the grid crosshair on the next sheet; the F7 station pick is plan-local too
|
|
6540
6871
|
dimMode=false;dimChain=false;dimSplitMode=false;selDimIds=new Set();setDimMode(); // Dimension tool resets per plan (incl. chain + split); setDimMode syncs the button/body.dimon classes + clears any draft/preview/chain (dimsVisible persists across plans)
|
|
6541
6872
|
setMode(); // Add-member likewise resets per plan: syncs body.add (crosshair) + the button off, and drops any in-progress start point (a plan-pixel draft is stale on another sheet)
|
|
6542
6873
|
if(gridMode||gridPick||gridLinePick){if(gridLinePick&&gridLinePick.line)gridLinePick.line.remove();gridMode=false;gridPick=false;gridLinePick=null;gridSetPickClass();} // grid panel/pick disarms per plan like the other takeover tools (a leaked pick would set geometry in the WRONG sheet's display space)
|
|
@@ -6559,6 +6890,7 @@ const _restored=restoreSaved(); // bring back this brows
|
|
|
6559
6890
|
// non-brace, clamp bad values. Covers reader-emitted, partial and localStorage-restored payloads, so it runs
|
|
6560
6891
|
// AFTER restoreSaved() and BEFORE the first paint. (normBrace lives inside main(); boot() can't see it.)
|
|
6561
6892
|
for(const _p of (C.plans||[]))for(const _m of (_p.members||[]))normBrace(_m);
|
|
6893
|
+
for(const _p of (C.plans||[]))sanitizeDims(_p); // F9: validate magnetic dim refs on EVERY sheet (not just the active one setPlan sanitizes) — an unvisited plan could otherwise keep a stale/cross-plan ref (Codex R1 #17). Runs after normBrace so isBrace is reliable.
|
|
6562
6894
|
// Migrate every plan before the first whole-contract validation/save/3D build. Visiting sheets one-by-one must
|
|
6563
6895
|
// not be required to turn legacy scalar/overlong labels_z into the canonical bounded array.
|
|
6564
6896
|
for(const _p of (C.plans||[]))sanitizePlanGrid(_p);
|
|
@@ -6703,6 +7035,55 @@ if(new URLSearchParams(location.search).get('selftest')==='1'){(function(){
|
|
|
6703
7035
|
ok(bad.dims[0].end==='arrow'&&bad.dims[0].bg===true&&bad.dims[0].place==='on','sanitizeDims keeps valid style fields');
|
|
6704
7036
|
ok(!('end' in bad.dims[1])&&!('place' in bad.dims[1])&&!('bg' in bad.dims[1]),'sanitizeDims strips junk style fields');
|
|
6705
7037
|
{const nd={sheet:'T',dims:'not an array'};sanitizeDims(nd);ok(Array.isArray(nd.dims)&&!nd.dims.length,'sanitizeDims replaces a non-array dims with []');}}
|
|
7038
|
+
// 5f) F9 magnetic dimensions — pure model layer (anchor resolution, reanchor, ref sanitize). The interactive
|
|
7039
|
+
// quick-dim (F7) + value-edit (F8) paths call render()/edit() and are covered by the real E2E pass, not
|
|
7040
|
+
// here (rendering a synthetic member would need the full ensureMeta shape).
|
|
7041
|
+
{const beam=(id,wp)=>({id,role:'beam',profile:'W12X26',wp});
|
|
7042
|
+
{const b=beam('b1',[[10,20],[110,20]]);const pl={members:[b]};
|
|
7043
|
+
ok(pnear(resolveDimAnchor(pl,{m:'b1',pt:'a'}),[10,20])&&pnear(resolveDimAnchor(pl,{m:'b1',pt:'b'}),[110,20])&&pnear(resolveDimAnchor(pl,{m:'b1',pt:'mid'}),[60,20]),'resolveDimAnchor → a/b/mid on a beam');
|
|
7044
|
+
ok(resolveDimAnchor(pl,{m:'nope',pt:'a'})===null,'resolveDimAnchor → null for a missing member');
|
|
7045
|
+
ok(pnear(resolveDimAnchor({members:[{id:'c1',role:'column',wp:[[7,8],[7,8]]}]},{m:'c1',pt:'b'}),[7,8]),'resolveDimAnchor → a column anchors at its plan point (pt irrelevant)');
|
|
7046
|
+
ok(resolveDimAnchor({members:[{id:'br1',role:'beam',memberType:'brace',wp:[[0,0],[10,10]]}]},{m:'br1',pt:'a'})===null,'resolveDimAnchor → null for a brace (never anchorable)');}
|
|
7047
|
+
{const b=beam('b2',[[0,0],[100,0]]);const pl={members:[b]};
|
|
7048
|
+
const d={id:'d1',a:[0,0],b:[100,0],axis:'free',off:10,rot:0,bRef:{m:'b2',pt:'b'}};
|
|
7049
|
+
b.wp=[[0,0],[140,0]];reanchorDim(pl,d);ok(pnear(d.b,[140,0]),'reanchorDim follows a member move');
|
|
7050
|
+
const d2={id:'d2',a:[0,0],b:[100,0],axis:'free',off:10,rot:0,aRef:{m:'gone',pt:'a'}};
|
|
7051
|
+
ok(reanchorDim(pl,d2)===true&&!('aRef' in d2),'reanchorDim drops a stale ref (safe-freeze)');
|
|
7052
|
+
const d3={id:'d3',a:[0,0],b:[100,0],axis:'free',off:10,rot:0,bRef:{m:'b2',pt:'b'},pin:false};
|
|
7053
|
+
reanchorDim(pl,d3);ok(pnear(d3.b,[100,0])&&d3.bRef&&d3.bRef.m==='b2','reanchorDim skips an UNPINNED dim (dormant link: no follow, refs kept)');}
|
|
7054
|
+
{const save=window.GridCore;window.GridCore=null; // boot race: grid-core (ES module) not loaded yet must NOT read as "grid gone"
|
|
7055
|
+
const d={id:'gr',a:[0,0],b:[100,0],axis:'x',off:5,rot:0,aRef:{g:'gv:0'}};
|
|
7056
|
+
reanchorDim({grid:{origin:[0,0],x:'0 100',y:'0 100'},members:[]},d);
|
|
7057
|
+
ok(!!(d.aRef&&d.aRef.g==='gv:0'),'reanchorDim keeps a grid ref while grid-core is still loading (no false drop at boot)');
|
|
7058
|
+
window.GridCore=save;}
|
|
7059
|
+
{const pl={members:[beam('b5',[[0,0],[100,0]]),{id:'br5',role:'beam',memberType:'brace',wp:[[200,0],[300,100]]}]}; // dimRefAtPoint: what a dropped anchor handle re-links to
|
|
7060
|
+
const r1=dimRefAtPoint(pl,[100,0],null),r2=dimRefAtPoint(pl,[50,0],null);
|
|
7061
|
+
ok(r1&&r1.m==='b5'&&r1.pt==='b'&&r2&&r2.m==='b5'&&r2.pt==='mid','dimRefAtPoint → member end + midpoint re-link a dropped handle');
|
|
7062
|
+
ok(dimRefAtPoint(pl,[50,7],null)===null,'dimRefAtPoint → a free-space drop (even near a member) stays unlinked');
|
|
7063
|
+
ok(dimRefAtPoint(pl,[200,0],null)===null,'dimRefAtPoint → a brace end never re-links');}
|
|
7064
|
+
{const pl={sheet:'T',members:[beam('b3',[[0,0],[100,0]]),{id:'c3',role:'column',wp:[[5,5],[5,5]]},{id:'br3',role:'beam',memberType:'brace',wp:[[0,0],[10,10]]}],dims:[
|
|
7065
|
+
{id:'k',a:[0,0],b:[100,0],axis:'x',off:5,rot:0,aRef:{m:'b3',pt:'a'},bRef:{m:'b3',pt:'b'}},
|
|
7066
|
+
{id:'col',a:[0,0],b:[100,0],axis:'x',off:5,rot:0,aRef:{m:'c3',pt:'a'}},
|
|
7067
|
+
{id:'brc',a:[0,0],b:[100,0],axis:'x',off:5,rot:0,aRef:{m:'br3',pt:'a'}},
|
|
7068
|
+
{id:'miss',a:[0,0],b:[100,0],axis:'x',off:5,rot:0,bRef:{m:'nope',pt:'b'}}]};
|
|
7069
|
+
sanitizeDims(pl);const kk=pl.dims.find(x=>x.id==='k'),cc=pl.dims.find(x=>x.id==='col'),bb=pl.dims.find(x=>x.id==='brc'),mm=pl.dims.find(x=>x.id==='miss');
|
|
7070
|
+
ok(kk&&kk.aRef&&kk.aRef.m==='b3'&&kk.bRef&&kk.bRef.pt==='b','sanitizeDims keeps a valid beam ref (both ends)');
|
|
7071
|
+
ok(cc&&cc.aRef&&cc.aRef.m==='c3','sanitizeDims keeps a COLUMN ref (anchorable since QA 2026-07-16)');
|
|
7072
|
+
ok(bb&&!('aRef' in bb)&&mm&&!('bRef' in mm),'sanitizeDims drops a brace ref and a missing-member ref');}
|
|
7073
|
+
{const pl={sheet:'T',members:[beam('b4',[[0,0],[100,0]])],dims:[
|
|
7074
|
+
{id:'pf',a:[0,0],b:[100,0],axis:'x',off:5,rot:0,aRef:{m:'b4',pt:'a'},pin:false},
|
|
7075
|
+
{id:'po',a:[0,0],b:[100,0],axis:'x',off:5,rot:0,pin:false}]}; // pin without any ref = meaningless → dropped
|
|
7076
|
+
sanitizeDims(pl);const pf=pl.dims.find(x=>x.id==='pf'),po=pl.dims.find(x=>x.id==='po');
|
|
7077
|
+
ok(pf&&pf.pin===false&&pf.aRef,'sanitizeDims keeps a dormant pin alongside its surviving ref');
|
|
7078
|
+
ok(po&&!('pin' in po),'sanitizeDims drops a pin with no ref');}
|
|
7079
|
+
{const pl={sheet:'T',grid:{origin:[0,0],x:'0 100',y:'0 100'},members:[],dims:[
|
|
7080
|
+
{id:'g1',a:[0,0],b:[100,0],axis:'x',off:5,rot:0,aRef:{g:'gv:0'},bRef:{g:'gl:7'}},
|
|
7081
|
+
{id:'g2',a:[0,0],b:[100,0],axis:'x',off:5,rot:0,aRef:{g:'zz:0'}}]};
|
|
7082
|
+
sanitizeDims(pl);
|
|
7083
|
+
ok(pl.dims[0].aRef&&pl.dims[0].aRef.g==='gv:0'&&pl.dims[0].bRef&&pl.dims[0].bRef.g==='gl:7','sanitizeDims keeps well-shaped grid refs when the plan has a grid');
|
|
7084
|
+
ok(!('aRef' in pl.dims[1]),'sanitizeDims drops a malformed grid ref');
|
|
7085
|
+
const pl2={sheet:'T',members:[],dims:[{id:'g3',a:[0,0],b:[100,0],axis:'x',off:5,rot:0,aRef:{g:'gv:0'}}]};
|
|
7086
|
+
sanitizeDims(pl2);ok(!('aRef' in pl2.dims[0]),'sanitizeDims drops a grid ref when the plan has no grid');}}
|
|
6706
7087
|
// 6) snap — midpoint tier (△) + dimension lines as snap targets + self-snap exclusion
|
|
6707
7088
|
{const sm=P.members,ss=P.segments,sd=P.dims,sdv=dimsVisible,sz=zoom;
|
|
6708
7089
|
zoom=1;P.members=[{id:'tm',wp:[[0,0],[100,0]]}];P.segments=[];P.dims=[];dimsVisible=true;
|