@floless/app 0.119.0 → 0.120.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 +1334 -707
- package/dist/schemas/steel.model.v2.schema.json +43 -0
- package/dist/web/app.css +38 -4
- package/dist/web/aware.js +5 -0
- package/dist/web/steel-3d-core.js +21 -0
- package/dist/web/steel-3d-view.js +361 -1
- package/dist/web/steel-editor.html +782 -5
- package/package.json +2 -1
|
@@ -722,7 +722,70 @@ text.mlentx{fill:#e2e8f0;text-anchor:middle;dominant-baseline:central;font-famil
|
|
|
722
722
|
#m3dLegend .m3dbody{display:none;flex-direction:column;gap:1px;overflow:auto;min-height:0}
|
|
723
723
|
#m3dLegend .m3dbody.on{display:flex;flex:1 1 auto} /* the active body fills the capped panel and scrolls (min-height:0 lets it shrink below content) */
|
|
724
724
|
#m3dLegendBody{padding:8px 10px}
|
|
725
|
-
#m3dViewsBody,#m3dFavBody{padding:8px 10px}
|
|
725
|
+
#m3dViewsBody,#m3dFavBody,#m3dRefsBody{padding:8px 10px}
|
|
726
|
+
/* ── References tab (#m3dRefsBody) — borrowed geometry we never own (#278). The Views-tab row recipe,
|
|
727
|
+
with two departures the feature earns:
|
|
728
|
+
· zoom-to is a PERMANENT icon on every row, not a hover-reveal like .vwrow .vx. A reference can
|
|
729
|
+
sit at real site coordinates, entirely off-screen; if "where is it?" is hidden behind hover the
|
|
730
|
+
import reads as having silently failed, which is the first thing a user concludes anyway.
|
|
731
|
+
· the snap dot does NOT dim with a hidden row. Hiding a reference does not stop it snapping —
|
|
732
|
+
deliberate, and the single most surprising thing here — so the one control that is still live
|
|
733
|
+
stays at full strength while the rest of the row greys out. Same idea as .lrow.off .lsw:hover,
|
|
734
|
+
which already carves one element out of a dimmed row.
|
|
735
|
+
Cyan is this app's reserved snap colour (#snapStat, .snapmk, #snapMenu .sg); it is spent here rather
|
|
736
|
+
than a new hue being invented. ── */
|
|
737
|
+
#refHeadRow{display:flex;align-items:stretch;gap:6px;margin-bottom:6px;flex:none}
|
|
738
|
+
#refAddBtn{flex:1;min-width:0;height:28px;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
|
|
739
|
+
#m3dRefsBody .refempty,#m3dRefsBody .refhint{color:var(--mut);font-size:11px;line-height:1.5;padding:6px 4px}
|
|
740
|
+
#m3dRefsBody .refrow{display:flex;align-items:center;gap:6px;padding:3px 4px;border-radius:5px;cursor:pointer;user-select:none;white-space:nowrap}
|
|
741
|
+
#m3dRefsBody .refrow:hover{background:#33415580}
|
|
742
|
+
#m3dRefsBody .refrow.sel{box-shadow:inset 2px 0 0 var(--brand);background:rgba(59,130,246,.16);padding-left:2px}
|
|
743
|
+
#m3dRefsBody .refrow.hidden{opacity:.4}
|
|
744
|
+
#m3dRefsBody .refrow.hidden .refsnap{opacity:1} /* the exception that makes "hidden but still snapping" readable at a glance */
|
|
745
|
+
#m3dRefsBody .refsw{width:11px;height:11px;border-radius:2px;flex:none;background:#94a3b8;cursor:pointer}
|
|
746
|
+
#m3dRefsBody .refrow.hidden .refsw{background:transparent;box-shadow:inset 0 0 0 1.6px #94a3b8}
|
|
747
|
+
#m3dRefsBody .refsw:hover{box-shadow:0 0 0 2px rgba(255,255,255,.25)}
|
|
748
|
+
#m3dRefsBody .refrow.hidden .refsw:hover{box-shadow:inset 0 0 0 1.6px #94a3b8,0 0 0 2px rgba(255,255,255,.25)}
|
|
749
|
+
#m3dRefsBody .refsnap{width:8px;height:8px;border-radius:50%;flex:none;background:#22d3ee;cursor:pointer}
|
|
750
|
+
#m3dRefsBody .refsnap.off{background:transparent;box-shadow:inset 0 0 0 1.5px #475569}
|
|
751
|
+
#m3dRefsBody .refname{flex:1;min-width:0;overflow:hidden;text-overflow:ellipsis;color:var(--text)}
|
|
752
|
+
#m3dRefsBody .refrow.unresolved .refname{color:#fbbf24;text-decoration:underline dotted}
|
|
753
|
+
#m3dRefsBody .refzoom,#m3dRefsBody .refdots{flex:none;color:var(--mut);font-size:12px;line-height:1;padding:0 3px;border-radius:4px;cursor:pointer}
|
|
754
|
+
#m3dRefsBody .refzoom:hover,#m3dRefsBody .refdots:hover{color:var(--text);background:#334155}
|
|
755
|
+
#m3dRefsBody .refdet{padding:6px 6px 8px;margin:2px 0 6px;border-left:1px solid var(--line);display:flex;flex-direction:column;gap:6px}
|
|
756
|
+
#m3dRefsBody .refdet .drow{display:flex;align-items:center;gap:6px}
|
|
757
|
+
#m3dRefsBody .refdet .dlab{flex:none;color:var(--mut);font-size:11px;min-width:52px}
|
|
758
|
+
#m3dRefsBody .refdet input[type=range]{accent-color:var(--brand);flex:1;min-width:0}
|
|
759
|
+
#m3dRefsBody .refdet .dval{flex:none;min-width:34px;text-align:right;font-variant-numeric:tabular-nums;color:var(--mut);font-size:11px}
|
|
760
|
+
#m3dRefsBody .refdet input[type=text]{height:24px;font-size:11px}
|
|
761
|
+
#m3dRefsBody .refdet .dnote{color:var(--mut);font-size:11px;line-height:1.45}
|
|
762
|
+
#m3dRefsBody .refdet .dwarn{color:#fbbf24;font-size:11px;line-height:1.45}
|
|
763
|
+
#m3dRefsBody .refdet .lockrow{display:flex;align-items:center;gap:0;color:var(--text);font-size:11px;background:transparent;border:0;padding:2px 0;cursor:pointer;box-shadow:none}
|
|
764
|
+
#m3dRefsBody .refdet .lockrow .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}
|
|
765
|
+
#m3dRefsBody .refdet .lockrow .mck::after{content:'';position:absolute;top:1px;left:1px;width:10px;height:10px;border-radius:50%;background:#64748b;transition:transform .15s,background-color .15s}
|
|
766
|
+
#m3dRefsBody .refdet .lockrow.on .mck{background:rgba(59,130,246,.28);border-color:var(--brand)}
|
|
767
|
+
#m3dRefsBody .refdet .lockrow.on .mck::after{transform:translateX(12px);background:var(--brand)}
|
|
768
|
+
/* ── Reference-model import modal (#refImportModal) — the #connImportModal recipe, under its own ids.
|
|
769
|
+
A sibling rather than a third stage inside it: that modal's last stage is "pick one of several
|
|
770
|
+
candidates found inside the file", and this one's is "confirm the one thing you are about to add",
|
|
771
|
+
which is a different screen wearing the same clothes. ── */
|
|
772
|
+
#refImportModal{display:none;position:fixed;inset:0;z-index:60;align-items:center;justify-content:center}
|
|
773
|
+
#refImportModal .mbackdrop{position:absolute;inset:0;background:rgba(2,6,23,.66)}
|
|
774
|
+
#refImportModal .ripanel{position:relative;width:min(460px,92vw);max-height:86vh;display:flex;flex-direction:column;background:var(--panel);border:1px solid var(--line);border-radius:10px;box-shadow:0 18px 48px rgba(0,0,0,.55)}
|
|
775
|
+
#refImportModal .mhead{display:flex;align-items:center;justify-content:space-between;gap:10px;padding:12px 14px;border-bottom:1px solid var(--line)}
|
|
776
|
+
#refImportModal .ribody{padding:14px;overflow:auto;min-height:0}
|
|
777
|
+
#refImportModal .rifoot{display:flex;justify-content:flex-end;gap:8px;padding:10px 14px;border-top:1px solid var(--line)}
|
|
778
|
+
#riDrop{border:1px dashed #475569;border-radius:8px;padding:26px 14px;text-align:center;color:var(--mut);font-size:12px;line-height:1.6;cursor:pointer}
|
|
779
|
+
#riDrop:hover,#riDrop.drag{border-color:var(--brand);color:var(--text);background:rgba(59,130,246,.07)}
|
|
780
|
+
#riDropErr{display:none;margin-top:8px;color:#fca5a5;font-size:11.5px;line-height:1.5}
|
|
781
|
+
#riProgTxt{color:var(--mut);font-size:12px;line-height:1.6;text-align:center;padding:22px 6px}
|
|
782
|
+
#refImportModal .rirow{display:flex;align-items:baseline;justify-content:space-between;gap:12px;padding:3px 0;font-size:12px}
|
|
783
|
+
#refImportModal .rirow .pn{color:var(--mut)}
|
|
784
|
+
#refImportModal .rirow .pv{color:var(--text);font-variant-numeric:tabular-nums}
|
|
785
|
+
#riSays{margin:2px 0 10px;font-size:12.5px;color:var(--text);line-height:1.6}
|
|
786
|
+
#riSays b{color:var(--mut);font-weight:600}
|
|
787
|
+
#riVerdict{display:none;margin-top:10px;padding:8px 10px;border:1px solid #713f12;border-radius:7px;color:#fbbf24;font-size:11.5px;line-height:1.55}
|
|
788
|
+
#riVerdict button{margin-top:7px}
|
|
726
789
|
/* ── Favourites tab (#m3dFavBody) — the Views-tab row/search recipe. No create button (★ lives in the
|
|
727
790
|
Inspector); a kind-filter + search header, per-row kind swatch + portability badge + row-click-to-arm. ── */
|
|
728
791
|
#favHeadRow{display:flex;align-items:stretch;gap:6px;margin-bottom:6px;flex:none}
|
|
@@ -1127,12 +1190,16 @@ text.mlentx{fill:#e2e8f0;text-anchor:middle;dominant-baseline:central;font-famil
|
|
|
1127
1190
|
<button class=m3dtab role=tab data-tab=objects aria-selected=true data-tip="Objects — show / hide, isolate, and search the model's parts">Objects</button>
|
|
1128
1191
|
<button class=m3dtab role=tab data-tab=views aria-selected=false data-tip="Saved views — save, switch, and manage named viewpoints">Views</button>
|
|
1129
1192
|
<button class=m3dtab role=tab data-tab=fav aria-selected=false data-tip="Favourite connections — save and re-apply detailed connections">Favourites</button>
|
|
1193
|
+
<!-- Reference models (#278). HIDDEN, not disabled, until the project holds the model-level contract:
|
|
1194
|
+
a tab that can never hold anything is the same dead chrome the header stat spans are hidden for. -->
|
|
1195
|
+
<button class=m3dtab role=tab data-tab=refs aria-selected=false style="display:none" data-tip="Reference models — an architect's or engineer's model overlaid to build against. Never part of your steel.">References</button>
|
|
1130
1196
|
</div>
|
|
1131
1197
|
<button type=button id=m3dLegendCollapse aria-label="Collapse 3D panel" aria-controls=m3dLegend aria-expanded=true data-tip="Collapse Objects, Views, and Favourites to the bottom-left corner">‹</button>
|
|
1132
1198
|
</div>
|
|
1133
1199
|
<div id=m3dLegendBody class="m3dbody on" role=tabpanel aria-label=Objects></div>
|
|
1134
1200
|
<div id=m3dViewsBody class=m3dbody role=tabpanel aria-label=Views></div>
|
|
1135
1201
|
<div id=m3dFavBody class=m3dbody role=tabpanel aria-label=Favourites></div>
|
|
1202
|
+
<div id=m3dRefsBody class=m3dbody role=tabpanel aria-label="Reference models"></div>
|
|
1136
1203
|
</div>
|
|
1137
1204
|
<button type=button id=m3dLegendLauncher aria-label="Expand 3D panel" aria-controls=m3dLegend aria-expanded=false data-tip="Expand Objects, Views, and Favourites">›</button>
|
|
1138
1205
|
<div id=m3dCube data-tip="Click a face for that view · right-drag to orbit"></div>
|
|
@@ -1222,6 +1289,37 @@ text.mlentx{fill:#e2e8f0;text-anchor:middle;dominant-baseline:central;font-famil
|
|
|
1222
1289
|
<div id=rfiModal><div class=mbackdrop id=rfiBackdrop></div>
|
|
1223
1290
|
<div class=mpanel><div class=mhead><b>Unresolved members — RFI</b><button id=rfiClose>✕</button></div>
|
|
1224
1291
|
<div id=rfiGrid style="padding:14px;overflow:auto"></div></div></div>
|
|
1292
|
+
<!-- Reference-model import (#278): drop → probe → confirm. Three stages in one modal, the whole body
|
|
1293
|
+
swapping per stage, so Insert is never a disabled button waiting for a condition to be met. -->
|
|
1294
|
+
<div id=refImportModal><div class=mbackdrop id=riBackdrop></div>
|
|
1295
|
+
<div class=ripanel><div class=mhead><b id=riTitle>Add a reference model</b><button id=riClose data-tip="Close">✕</button></div>
|
|
1296
|
+
<div class=ribody>
|
|
1297
|
+
<div id=riDropStage>
|
|
1298
|
+
<div id=riDrop tabindex=0 role=button aria-label="Choose an IFC file">Drop an IFC here, or click to choose<br><span style="font-size:11px">.ifc or .ifczip · up to 150 MB</span></div>
|
|
1299
|
+
<div id=riDropErr role=alert></div>
|
|
1300
|
+
<input id=riFile type=file accept=".ifc,.ifczip" style="display:none">
|
|
1301
|
+
</div>
|
|
1302
|
+
<div id=riProgStage style="display:none"><div id=riProgTxt>Reading the file…</div></div>
|
|
1303
|
+
<div id=riConfirmStage style="display:none">
|
|
1304
|
+
<div id=riSays></div>
|
|
1305
|
+
<div class=rirow><span class=pn>Schema</span><span class=pv id=riSchema>—</span></div>
|
|
1306
|
+
<div class=rirow><span class=pn>Objects</span><span class=pv id=riElements>—</span></div>
|
|
1307
|
+
<div class=rirow><span class=pn>File size</span><span class=pv id=riBytes>—</span></div>
|
|
1308
|
+
<!-- NO SIZE ROW HERE, and that is a decision rather than an omission. The only pre-tessellation
|
|
1309
|
+
measurement available is `probe.bbox`, which its own manifest calls APPROXIMATE — measured, it
|
|
1310
|
+
spans every cartesian point the file places, not the geometry: for the Motebello lift shaft it
|
|
1311
|
+
reports 42.64 x 43.93 x 74.07 m for a model that renders 3.62 x 3.66 x 0.74 m. Printing that
|
|
1312
|
+
beside a real "File size" would read as fact. The panel states the true size once the geometry
|
|
1313
|
+
is in, from the rendered bounds; the bbox is used ONLY for the position hint below, which is
|
|
1314
|
+
labelled a probability and phrased as one. -->
|
|
1315
|
+
<div id=riVerdict role=status></div>
|
|
1316
|
+
</div>
|
|
1317
|
+
</div>
|
|
1318
|
+
<div class=rifoot>
|
|
1319
|
+
<button id=riCancel>Cancel</button>
|
|
1320
|
+
<button id=riInsert class=primary style="display:none" data-tip="Add this model as a reference. It is never part of your steel.">Add reference</button>
|
|
1321
|
+
</div>
|
|
1322
|
+
</div></div>
|
|
1225
1323
|
<div id=connImportModal><div class=mbackdrop id=ciBackdrop></div>
|
|
1226
1324
|
<div class=mpanel><div class=mhead><b id=ciTitle>Import a connection</b><button id=ciClose data-tip="Close">✕</button></div>
|
|
1227
1325
|
<div id=ciBody>
|
|
@@ -1806,6 +1904,10 @@ async function boot() {
|
|
|
1806
1904
|
if(!C.dim_overlays||typeof C.dim_overlays!=='object'||Array.isArray(C.dim_overlays))C.dim_overlays={bolt_pitch:true,edge_clearance:true,cope_size:true,base_plate:true,anchor_depth:true}; // model-global legend DIMENSIONS toggles — all on by default
|
|
1807
1905
|
if(!C.dim_style||typeof C.dim_style!=='object'||Array.isArray(C.dim_style))C.dim_style={}; // model-global dimension-style defaults; the full sanitizeDimStyle() runs inside main() where DIM_ENDS/DIM_DEF live (mirrors prop_labels/views)
|
|
1808
1906
|
if(!Array.isArray(C.views))C.views=[]; // model-global saved views (Views Organizer): ensure an array in boot()'s OUTER scope (like dims3d/detail_placements above); the full sanitizeViews() runs inside main() where that helper lives (mirrors prop_labels)
|
|
1907
|
+
// Reference models (#278) — same treatment as `views`, and ONLY on v2: the key is not in the v1
|
|
1908
|
+
// schema, so materialising an empty array on a v1 document would add a property its own validator
|
|
1909
|
+
// refuses and turn the next save into a 400 for an edit the user never made.
|
|
1910
|
+
if(MODEL_V2&&!Array.isArray(C.reference_models))C.reference_models=[];
|
|
1809
1911
|
main(); // (C.prop_labels is normalised inside main(), right after the PROP_DEFS/sanitizePropLabels registry is defined — see ~"normalise the contract's incoming value" — since that helper isn't in scope out here in boot())
|
|
1810
1912
|
// SSE: listen for external contract writebacks (e.g. the terminal AI PUT a revision).
|
|
1811
1913
|
// We open our own EventSource to the same /api/events endpoint as the main app.
|
|
@@ -2587,7 +2689,7 @@ function sanitizeViews(arr){return ViewGen.sanitizeViews(arr);}
|
|
|
2587
2689
|
function persist(){try{localStorage.setItem(LSKEY,JSON.stringify({sig:dataSig(),baseEtag:serverEtag,ts:Date.now(),active:C.active,
|
|
2588
2690
|
members:MODEL_V2?C.members:undefined,
|
|
2589
2691
|
grid:C.grid,
|
|
2590
|
-
custom_details:C.custom_details, profile_colors:C.profile_colors, member_styles:C.member_styles, member_types:C.member_types, target_confidence:C.target_confidence, dims3d:C.dims3d, dim_overlays:C.dim_overlays, dim_style:C.dim_style, prop_labels:C.prop_labels, joints:C.joints, connections:C.connections, detail_placements:C.detail_placements, views:C.views,
|
|
2692
|
+
custom_details:C.custom_details, profile_colors:C.profile_colors, member_styles:C.member_styles, member_types:C.member_types, target_confidence:C.target_confidence, dims3d:C.dims3d, dim_overlays:C.dim_overlays, dim_style:C.dim_style, prop_labels:C.prop_labels, joints:C.joints, connections:C.connections, detail_placements:C.detail_placements, views:C.views, reference_models:C.reference_models,
|
|
2591
2693
|
plans:C.plans.map(p=>MODEL_V2?p:{sheet:p.sheet,members:p.members,default_tos:p.default_tos,details:p.details,callouts:p.callouts,dims:p.dims,frame:p.frame||null,grid:p.grid||null})}));return true;}catch(e){setSaved('err');console.error('local autosave failed',e);return false;}}
|
|
2592
2694
|
// --- server-side draft save: PUT the FULL contract C — this is the copy Approve bakes.
|
|
2593
2695
|
// localStorage (persist) stays the instant per-browser draft cache; this is the durable one.
|
|
@@ -2821,6 +2923,49 @@ window.flushContract = async () => {
|
|
|
2821
2923
|
if (!res.ok) throw new Error('save failed (' + res.status + ')');
|
|
2822
2924
|
});
|
|
2823
2925
|
};
|
|
2926
|
+
/**
|
|
2927
|
+
* The server's reference list, wearing the draft's display and placement wherever the ids still match.
|
|
2928
|
+
*
|
|
2929
|
+
* Membership from the server, presentation from the draft — the one split that makes a local draft safe
|
|
2930
|
+
* to restore over a list only server-side verbs can add to or remove from. Order follows the server too,
|
|
2931
|
+
* so a restore never reshuffles the panel.
|
|
2932
|
+
*/
|
|
2933
|
+
/** A plain object, and nothing else. `"hidden"` spreads into numeric keys; an array spreads into "0","1". */
|
|
2934
|
+
const refPlainObject=(v)=>!!v&&typeof v==='object'&&!Array.isArray(v);
|
|
2935
|
+
function reconcileReferences(server,draft){
|
|
2936
|
+
// ONE MALFORMED ROW MUST NOT COST THE WHOLE DRAFT. localStorage is user-writable and survives version
|
|
2937
|
+
// changes, so a `display` that is a string spreads into {0:'h',1:'i',…} — keys the v2 schema refuses
|
|
2938
|
+
// (`additionalProperties:false`). `V2_SESSION.replaceDocument` then rightly declines the document, and
|
|
2939
|
+
// the user loses every UNRELATED edit in that draft with it. Malformed fields are dropped, loudly.
|
|
2940
|
+
const byId=new Map();
|
|
2941
|
+
for(const r of draft||[]){
|
|
2942
|
+
if(!r||!r.id){console.warn('steel-editor: a drafted reference row had no id — dropped');continue;}
|
|
2943
|
+
if(byId.has(r.id))console.warn('steel-editor: duplicate drafted reference id — the later row wins',r.id);
|
|
2944
|
+
byId.set(r.id,r);
|
|
2945
|
+
}
|
|
2946
|
+
const seen=new Set();
|
|
2947
|
+
const out=(server||[]).map(r=>{
|
|
2948
|
+
const mine=byId.get(r&&r.id);if(!mine)return r;
|
|
2949
|
+
seen.add(r.id);
|
|
2950
|
+
// PER FIELD, NOT PER OBJECT, and the first cut got this wrong in the one direction that loses data.
|
|
2951
|
+
// It replaced `placement` outright and DELETED it when the draft had none — but `placement` only
|
|
2952
|
+
// exists once somebody moves or scales a reference, so "the draft cleared it" and "the draft predates
|
|
2953
|
+
// it" are the same shape, and resolving that toward deletion threw away a move made in another tab.
|
|
2954
|
+
// Merging matches how the edit was applied in the first place: `refEdit` spreads a patch over the
|
|
2955
|
+
// existing object, so a draft carrying only `{scale:2}` must not wipe an `origin` it never saw.
|
|
2956
|
+
const merged=structuredClone(r);
|
|
2957
|
+
for(const key of ['display','placement']){
|
|
2958
|
+
if(mine[key]===undefined)continue;
|
|
2959
|
+
if(!refPlainObject(mine[key])){console.warn('steel-editor: a drafted reference '+key+' was not an object — dropped',r.id);continue;}
|
|
2960
|
+
merged[key]={...(r[key]||{}),...structuredClone(mine[key])};
|
|
2961
|
+
}
|
|
2962
|
+
return merged;});
|
|
2963
|
+
// SAY WHEN SOMETHING IS DROPPED. Every other draft-refusal path in this file names its reason in the
|
|
2964
|
+
// console; this one silently discarded a drafted edit whose reference is gone, which is exactly the
|
|
2965
|
+
// kind of quiet that made the bug above take a browser pass to find.
|
|
2966
|
+
for(const id of byId.keys())if(!seen.has(id))console.warn('steel-editor: a drafted reference edit was dropped — that reference is no longer in this model',id);
|
|
2967
|
+
return out;
|
|
2968
|
+
}
|
|
2824
2969
|
/**
|
|
2825
2970
|
* Overlay a stored draft's fields onto C.
|
|
2826
2971
|
*
|
|
@@ -2840,6 +2985,17 @@ function applyDraftFields(d){
|
|
|
2840
2985
|
const candidate=structuredClone(C);
|
|
2841
2986
|
const rootKeys=['members','grid','custom_details','profile_colors','member_styles','member_types','target_confidence','dims3d','dim_overlays','dim_style','prop_labels','joints','connections','detail_placements','views'];
|
|
2842
2987
|
for(const key of rootKeys)if(key in d)candidate[key]=structuredClone(d[key]);
|
|
2988
|
+
// REFERENCES ARE RECONCILED, NEVER REPLACED — and this is not tidiness, it is a reference that
|
|
2989
|
+
// vanished in front of me. Which references EXIST is the server's answer: insert and remove are
|
|
2990
|
+
// routes that write the contract themselves, and `adoptReferenceWrite` then re-points this draft at
|
|
2991
|
+
// the tag they produced so the next ordinary save does not 412. That restamp makes a draft written
|
|
2992
|
+
// BEFORE the insert look perfectly current — so restoring it wholesale deleted the reference the
|
|
2993
|
+
// user had just added, silently, with no banner, while the file sat safely on the server and on
|
|
2994
|
+
// disk. What the draft legitimately owns is the per-reference display and placement (the toggle
|
|
2995
|
+
// that must survive a closed tab, which is why this key was added here at all), so that is all it
|
|
2996
|
+
// is allowed to carry back. The symmetric case falls out for free: a draft cannot resurrect a
|
|
2997
|
+
// reference somebody else removed.
|
|
2998
|
+
if(Array.isArray(d.reference_models))candidate.reference_models=reconcileReferences(candidate.reference_models,d.reference_models);
|
|
2843
2999
|
if(Array.isArray(d.plans)){
|
|
2844
3000
|
const bySheet=new Map(d.plans.filter(p=>p&&typeof p.sheet==='string').map(p=>[p.sheet,p]));
|
|
2845
3001
|
candidate.plans=candidate.plans.map(p=>bySheet.has(p.sheet)?structuredClone(bySheet.get(p.sheet)):p);
|
|
@@ -2937,6 +3093,20 @@ function v2DraftFits(d){
|
|
|
2937
3093
|
if(MODEL_V2_LIVE){
|
|
2938
3094
|
const rootKeys=['members','grid','custom_details','profile_colors','member_styles','member_types','target_confidence','dims3d','dim_overlays','dim_style','prop_labels','joints','connections','detail_placements','views'];
|
|
2939
3095
|
if(rootKeys.some(k=>k in d&&JSON.stringify(d[k])!==JSON.stringify(C&&C[k])))return true;
|
|
3096
|
+
// Asked through the SAME reconciliation the restore performs, or the two disagree: a draft that is
|
|
3097
|
+
// merely one insert behind would read as "differs", offer the user their earlier edits, and then put
|
|
3098
|
+
// nothing back — the offer that cannot be satisfied, which this feature has already produced once on
|
|
3099
|
+
// the position advisory. Only a real display/placement delta counts.
|
|
3100
|
+
//
|
|
3101
|
+
// SAID PLAINLY: this whole function is UNREACHABLE today, so this arm has never executed. Its two
|
|
3102
|
+
// callers are `draftFits` — which short-circuits on `canWriteModel()` — and `applyDraftReadOnlyFields`,
|
|
3103
|
+
// which is itself behind `if(!canWriteModel())`. `canWriteModel()` is `!MODEL_RO`,
|
|
3104
|
+
// `MODEL_RO = MODEL_V2 && !MODEL_V2_LIVE`, and `MODEL_V2_LIVE` is the constant `true`. It is kept
|
|
3105
|
+
// aligned rather than left behind because the read-only mode is the thing that would resurrect it,
|
|
3106
|
+
// and a half-updated pair is how the original defect got in — but nothing exercises it, and a comment
|
|
3107
|
+
// claiming otherwise would be the same kind of lie this pass has been removing.
|
|
3108
|
+
if(Array.isArray(d.reference_models)
|
|
3109
|
+
&&JSON.stringify(reconcileReferences(C&&C.reference_models,d.reference_models))!==JSON.stringify((C&&C.reference_models)||[]))return true;
|
|
2940
3110
|
if(Array.isArray(d.plans)){
|
|
2941
3111
|
const bySheet=new Map((C.plans||[]).map(p=>[p.sheet,p]));
|
|
2942
3112
|
if(d.plans.some(p=>!bySheet.has(p.sheet)||JSON.stringify(p)!==JSON.stringify(bySheet.get(p.sheet))))return true;
|
|
@@ -7656,6 +7826,11 @@ const view3dApi={
|
|
|
7656
7826
|
beginClipEdit:()=>pushUndo(snapshot()), // a clip / work-area manipulation → push a pre-edit snapshot so Ctrl+Z/Y restores it
|
|
7657
7827
|
onClipModeChange:(m)=>{const b=document.getElementById('m3dClip');if(b){b.classList.toggle('on',!!m);b.textContent=m?'Clip ✕':'Clip ▾';}}, // armed → button fills brand-blue + becomes a cancel target (✕ = cancel)
|
|
7658
7828
|
onInsertModeChange:(on)=>{const b=document.getElementById('m3dInsert');if(b){b.classList.toggle('on',!!on);b.textContent=on?'✕ Cancel insert':'Insert…';} if(!on)favDisarmed();}, // armed → cancel target; disarm also clears any armed favourite (the pinned bar + the .armed row)
|
|
7829
|
+
// A canvas click selected (or deselected) a whole reference model. Without this the binding is
|
|
7830
|
+
// one-way — the panel drives the 3D view but a pick in the 3D view leaves the panel showing the
|
|
7831
|
+
// previous row, which is worse than no highlight because it is confidently wrong. Found by clicking
|
|
7832
|
+
// the canvas for real; every panel-driven path had looked fine.
|
|
7833
|
+
onReferenceSelect:(id)=>{if(refSelectedId===id)return;refSelectedId=id||null;if(legendTab==='refs')renderRefsTab();},
|
|
7659
7834
|
onBasePickModeChange:()=>{}, // Mode B armed state shows via the 3D crosshair + elevation readout; nothing else to reflect
|
|
7660
7835
|
onBasePick:(p)=>{ // Mode B: retarget the armed column's base to the picked elevation (world mm → inches), ONE undo entry
|
|
7661
7836
|
const m=byId(basePickColId); if(!m||m.role!=='column'||!m.col){toast('No column to trim');return;}
|
|
@@ -8036,12 +8211,17 @@ function setLegendPanelCollapsed(on,moveFocus){
|
|
|
8036
8211
|
if(moveFocus)(legendCollapsed?document.getElementById('m3dLegendLauncher'):document.getElementById('m3dLegendCollapse'))?.focus();
|
|
8037
8212
|
}
|
|
8038
8213
|
// Switch the active tab: light the strip button, show that body, render it on demand, persist the choice.
|
|
8039
|
-
function setLegendTab(tab){if(tab!=='objects'&&tab!=='views'&&tab!=='fav')tab='objects';
|
|
8214
|
+
function setLegendTab(tab){if(tab!=='objects'&&tab!=='views'&&tab!=='fav'&&tab!=='refs')tab='objects';
|
|
8215
|
+
// A persisted 'refs' choice must not strand a v1 project on a tab it cannot show (the button is hidden
|
|
8216
|
+
// there). Falling back to Objects is what makes hiding the tab safe across a migration in either direction.
|
|
8217
|
+
if(tab==='refs'&&!MODEL_V2)tab='objects';
|
|
8218
|
+
legendTab=tab;saveLegendTab();
|
|
8040
8219
|
document.querySelectorAll('#m3dTabs .m3dtab').forEach(b=>{const on=b.dataset.tab===tab;b.classList.toggle('on',on);b.setAttribute('aria-selected',String(on));});
|
|
8041
|
-
const bodies={objects:'m3dLegendBody',views:'m3dViewsBody',fav:'m3dFavBody'};
|
|
8220
|
+
const bodies={objects:'m3dLegendBody',views:'m3dViewsBody',fav:'m3dFavBody',refs:'m3dRefsBody'};
|
|
8042
8221
|
for(const [k,id] of Object.entries(bodies)){const el=document.getElementById(id);if(el)el.classList.toggle('on',k===tab);}
|
|
8043
8222
|
if(tab==='views')renderViewsTab(); // (re)render the Views list when it becomes visible
|
|
8044
8223
|
if(tab==='fav')renderFavTab(); // (re)render the Favourites list when it becomes visible
|
|
8224
|
+
if(tab==='refs')renderRefsTab(); // (re)render the Reference models list when it becomes visible
|
|
8045
8225
|
updateViewsBtn();
|
|
8046
8226
|
}
|
|
8047
8227
|
// The 3D-toolbar Views button lights (.on) while the panel is open on the Views tab.
|
|
@@ -8521,6 +8701,590 @@ async function deleteFav(f){const idx=steelFavourites.findIndex(x=>x.id===f.id);
|
|
|
8521
8701
|
}catch(_){toast('Could not restore the favourite');}});
|
|
8522
8702
|
}
|
|
8523
8703
|
|
|
8704
|
+
// ══ Reference models (#278): borrowed geometry we never own ═══════════════════════════════════════
|
|
8705
|
+
// An IFC somebody else authored, overlaid so you can see it, snap to it and build against it. It never
|
|
8706
|
+
// reaches a BOM, an export of our steel, a connection or the lock — and that is STRUCTURAL, not a
|
|
8707
|
+
// filter: the geometry lives on its own editor-only 3D layer and never passes through the projector
|
|
8708
|
+
// the exporters share. `C.reference_models` holds only pointers + how each is placed and displayed,
|
|
8709
|
+
// exactly the way `C.views` holds saved views, and rides the ordinary scheduleSave() like they do.
|
|
8710
|
+
//
|
|
8711
|
+
// v2-ONLY. `reference_models` is a model-level-contract key, so on v1 the tab is hidden and the Insert
|
|
8712
|
+
// item is replaced by a sentence saying what unlocks it — the server refuses the verbs there too, with
|
|
8713
|
+
// the same words, so a direct API hit and a click get the same answer.
|
|
8714
|
+
const refGeom=new Map(); // id -> { objects, dropped } once the geometry route has answered
|
|
8715
|
+
const refLoading=new Set(); // ids with a geometry fetch in flight — the row shows it, and it dedupes
|
|
8716
|
+
const refFailed=new Map(); // id -> why its geometry could not be fetched (see loadReferenceGeometry)
|
|
8717
|
+
const refEmpty=new Set(); // ids the reader answered for, with nothing drawable in the answer
|
|
8718
|
+
let refSelectedId=null; // the reference the panel has expanded (and the 3D layer has selected)
|
|
8719
|
+
const refUnresolved=new Set(); // ids whose original file is missing from the project (relink case)
|
|
8720
|
+
|
|
8721
|
+
function refList(){return Array.isArray(C.reference_models)?C.reference_models:[];}
|
|
8722
|
+
function refById(id){return refList().find(r=>r&&r.id===id)||null;}
|
|
8723
|
+
function refDisp(r){return (r&&r.display)||{};}
|
|
8724
|
+
const refApi=(suffix)=>'/api/steel/'+encodeURIComponent(APP_ID)+'/reference'+suffix+(PROJECT?(suffix.includes('?')?'&':'?')+'project='+encodeURIComponent(PROJECT):'');
|
|
8725
|
+
|
|
8726
|
+
/** Hand the 3D layer everything it draws. Called after any geometry arrival or display/placement edit. */
|
|
8727
|
+
function pushReferences(){
|
|
8728
|
+
if(!window.Steel3DView||!window.Steel3DView.setReferences||!view3d)return;
|
|
8729
|
+
window.Steel3DView.setReferences(refList().map(r=>({
|
|
8730
|
+
id:r.id,name:r.name,placement:r.placement||null,display:refDisp(r),
|
|
8731
|
+
objects:(refGeom.get(r.id)||{}).objects||[],
|
|
8732
|
+
})));
|
|
8733
|
+
if(refSelectedId&&window.Steel3DView.selectReference)window.Steel3DView.selectReference(refSelectedId);
|
|
8734
|
+
}
|
|
8735
|
+
|
|
8736
|
+
/**
|
|
8737
|
+
* Fetch one reference's geometry.
|
|
8738
|
+
*
|
|
8739
|
+
* A MISS IS ORDINARY, NOT AN ERROR. The geometry cache is reserved-internal, so it is stripped from
|
|
8740
|
+
* every export and duplicate: a project that arrived from somewhere else has none, and this call is
|
|
8741
|
+
* what rebuilds it. That is also why nothing here blocks — the native steel is already on screen and
|
|
8742
|
+
* the reference streams in behind it.
|
|
8743
|
+
*/
|
|
8744
|
+
async function loadReferenceGeometry(id){
|
|
8745
|
+
if(refGeom.has(id)||refLoading.has(id))return;
|
|
8746
|
+
refLoading.add(id);if(legendTab==='refs')renderRefsTab();
|
|
8747
|
+
try{
|
|
8748
|
+
const res=await fetch(refApi('/'+encodeURIComponent(id)+'/geometry'));
|
|
8749
|
+
const d=await res.json().catch(()=>({}));
|
|
8750
|
+
// A LATE RESPONSE FOR A REMOVED REFERENCE IS DROPPED. These bodies can be hundreds of megabytes, and
|
|
8751
|
+
// repopulating `refGeom` under an id the contract no longer holds leaks all of it while making the
|
|
8752
|
+
// 3D layer and the model disagree.
|
|
8753
|
+
if(!refById(id)){refLoading.delete(id);return;}
|
|
8754
|
+
// The three states are MUTUALLY EXCLUSIVE — each arm clears the other two. Clearing only one is how
|
|
8755
|
+
// a row ends up claiming both "file missing" and "nothing to draw", or keeps a stale reason after a
|
|
8756
|
+
// successful retry.
|
|
8757
|
+
const only=(set)=>{for(const s of [refUnresolved,refFailed,refEmpty])if(s!==set)s.delete(id);};
|
|
8758
|
+
if(res.ok&&d.ok){refGeom.set(id,{objects:d.objects||[],dropped:d.dropped||0,spanMm:d.spanMm||0});only(null);}
|
|
8759
|
+
else if(d.code==='reference-unresolved'){only(refUnresolved);refUnresolved.add(id);}
|
|
8760
|
+
else if(d.code==='reference-empty'){only(refEmpty);refEmpty.add(id);}
|
|
8761
|
+
// An `else` is mandatory here: a 500 whose body is not JSON parses to `{}`, so without one a failed
|
|
8762
|
+
// fetch produced no toast, no state and no log — the row simply looked fine.
|
|
8763
|
+
else {only(refFailed);refFailed.set(id,d.error||('the server answered '+res.status));}
|
|
8764
|
+
}catch(e){
|
|
8765
|
+
// FAILURE IS ROW STATE, not a swallow. The first cut had an empty catch whose comment claimed the row
|
|
8766
|
+
// would stay "loading…" — and the `finally` below falsified it on the very next line: it clears
|
|
8767
|
+
// refLoading and pushes an EMPTY objects array into the scene regardless. The result was a reference
|
|
8768
|
+
// that looked completely healthy — eye on, snap dot on, no suffix — drawing nothing, with no retry.
|
|
8769
|
+
// Indistinguishable from an IFC that genuinely contains no geometry, which is the one confusion this
|
|
8770
|
+
// whole feature must avoid.
|
|
8771
|
+
if(refById(id)){
|
|
8772
|
+
for(const st of [refUnresolved,refEmpty])st.delete(id);
|
|
8773
|
+
refFailed.set(id,(e&&e.message)||'could not reach the server');
|
|
8774
|
+
}
|
|
8775
|
+
console.error('[reference] geometry fetch failed',id,e);
|
|
8776
|
+
}
|
|
8777
|
+
finally{refLoading.delete(id);pushReferences();if(legendTab==='refs')renderRefsTab();}
|
|
8778
|
+
}
|
|
8779
|
+
/** Pull every reference's geometry once the 3D view is up. Sequential: one AWARE run at a time anyway. */
|
|
8780
|
+
async function loadAllReferences(){for(const r of refList())await loadReferenceGeometry(r.id);}
|
|
8781
|
+
|
|
8782
|
+
// ── MIRRORED FROM server/reference-import.ts — pinned by reference-constants-parity.test.ts ──
|
|
8783
|
+
// The judgement has to happen where the rendered bounds are, and they only exist in the browser. So the
|
|
8784
|
+
// three constants are mirrored rather than the measurement being shipped to the server and back, and the
|
|
8785
|
+
// parity test reads THIS FILE as text and fails if either side moves. Keep the names and the literals on
|
|
8786
|
+
// one line each; that is what the test matches on.
|
|
8787
|
+
const REF_UNIT_RATIOS=[1000,304.8,100,25.4,12,10];
|
|
8788
|
+
const REF_RATIO_TOLERANCE=0.03;
|
|
8789
|
+
const REF_OFFSCREEN_SPANS=1.5;
|
|
8790
|
+
|
|
8791
|
+
/**
|
|
8792
|
+
* Does this reference look like a unit mistake — and which way round?
|
|
8793
|
+
*
|
|
8794
|
+
* Runs on `spanMm`, which the server measures off the vertices the reader returned, NOT on the reader's
|
|
8795
|
+
* bbox (that spans everything the file mentions and reads 74 m for a 3.6 m lift shaft). Returns the
|
|
8796
|
+
* factor to APPLY plus the phrase to say, because "0×" is what `Math.round(1/factor)` prints when the
|
|
8797
|
+
* reference is the SMALLER of the two — the direction the first cut got wrong in every message.
|
|
8798
|
+
*/
|
|
8799
|
+
function refScaleAdvice(id){
|
|
8800
|
+
const g=refGeom.get(id),native=nativeModelSpan(),r=refById(id);
|
|
8801
|
+
if(!g||!(g.spanMm>0)||!(native>0))return null;
|
|
8802
|
+
// AGAINST THE SCALE ALREADY APPLIED. `spanMm` is the file's own size; the thing on screen is that
|
|
8803
|
+
// times `placement.scale`. Comparing the raw span meant the advice survived being taken — click
|
|
8804
|
+
// "Scale x0.001" and it kept offering the same fix, so a second click gave 0.000001.
|
|
8805
|
+
const applied=((r&&r.placement&&r.placement.scale)||1);
|
|
8806
|
+
const ratio=(g.spanMm*applied)/native;
|
|
8807
|
+
for(const r of REF_UNIT_RATIOS){
|
|
8808
|
+
if(Math.abs(ratio/r-1)<=REF_RATIO_TOLERANCE)return {factor:1/r,words:Math.round(r)+'× larger than'};
|
|
8809
|
+
if(Math.abs(ratio*r-1)<=REF_RATIO_TOLERANCE)return {factor:r,words:Math.round(r)+'× smaller than'};
|
|
8810
|
+
}
|
|
8811
|
+
return null;
|
|
8812
|
+
}
|
|
8813
|
+
|
|
8814
|
+
/**
|
|
8815
|
+
* The native model's own bounds, or null. Both the size and the distance checks start here.
|
|
8816
|
+
*
|
|
8817
|
+
* THE CATCH LOGS NOW, because this stopped being read-only. It used to gate advice — a throw meant a
|
|
8818
|
+
* hint quietly did not appear. It now also gates a WRITE ("move it next to your model"), where an
|
|
8819
|
+
* erased exception would degrade into "move it to [0,0,0] and save that". Callers that write must
|
|
8820
|
+
* refuse on null rather than fall back, and `refMoveToOrigin` does.
|
|
8821
|
+
*/
|
|
8822
|
+
function nativeModelBounds(){
|
|
8823
|
+
try{const b=window.Steel3DView&&window.Steel3DView.sceneBounds?window.Steel3DView.sceneBounds():null;
|
|
8824
|
+
return b&&b.min&&b.max?b:null;}
|
|
8825
|
+
catch(e){console.error('[reference] scene bounds unavailable',e);return null;}
|
|
8826
|
+
}
|
|
8827
|
+
/** The native model's centre in mm, or [0,0,0] when there is no model to centre on. */
|
|
8828
|
+
function nativeModelCentre(){
|
|
8829
|
+
const b=nativeModelBounds();
|
|
8830
|
+
return b?[0,1,2].map(i=>(b.min[i]+b.max[i])/2):[0,0,0];
|
|
8831
|
+
}
|
|
8832
|
+
/** The model's own largest dimension in mm — what a reference's size and distance are judged against. */
|
|
8833
|
+
function nativeModelSpan(){
|
|
8834
|
+
const b=nativeModelBounds();
|
|
8835
|
+
return b?Math.max(b.max[0]-b.min[0],b.max[1]-b.min[1],b.max[2]-b.min[2]):0;
|
|
8836
|
+
}
|
|
8837
|
+
/** Is this reference sitting so far from the model that it is off-screen? (Distance only — never scale.) */
|
|
8838
|
+
function refOffscreen(id){
|
|
8839
|
+
const n=nativeModelBounds();if(!n)return false;
|
|
8840
|
+
const span=Math.max(n.max[0]-n.min[0],n.max[1]-n.min[1],n.max[2]-n.min[2]);
|
|
8841
|
+
if(!(span>0))return false;
|
|
8842
|
+
const b=window.Steel3DView&&window.Steel3DView.referenceBounds?window.Steel3DView.referenceBounds(id):null;
|
|
8843
|
+
if(!b)return false;
|
|
8844
|
+
// FROM THE MODEL'S CENTRE, not from the world origin. A project genuinely surveyed at site
|
|
8845
|
+
// coordinates has its steel out there too; measuring from [0,0,0] called such a reference off-screen
|
|
8846
|
+
// when the camera frames both together perfectly — and the fix on offer would have moved it AWAY
|
|
8847
|
+
// from the steel it was correctly aligned with.
|
|
8848
|
+
const mid=(x)=>[0,1,2].map(i=>(x.min[i]+x.max[i])/2);
|
|
8849
|
+
const c=mid(b),m=mid(n);
|
|
8850
|
+
return Math.hypot(c[0]-m[0],c[1]-m[1],c[2]-m[2])>span*REF_OFFSCREEN_SPANS;
|
|
8851
|
+
}
|
|
8852
|
+
|
|
8853
|
+
/**
|
|
8854
|
+
* Patch one reference's display/placement and persist it the ordinary way — this is draft state.
|
|
8855
|
+
*
|
|
8856
|
+
* IT NEVER GOES THROUGH `pushReferences`, deliberately. That call re-uploads every vertex buffer, and a
|
|
8857
|
+
* whole tessellated building is tens of megabytes of GPU traffic; paying it to change an opacity is the
|
|
8858
|
+
* difference between a slider that follows the cursor and one that stutters. The 3D layer exposes two
|
|
8859
|
+
* cheap paths — a material update and a 4×4 transform — and this uses them. A full rebuild is for
|
|
8860
|
+
* geometry ARRIVING, which is the only time the vertices actually change.
|
|
8861
|
+
*/
|
|
8862
|
+
function refEdit(id,patch){
|
|
8863
|
+
const r=refById(id);if(!r)return;
|
|
8864
|
+
if(refDisp(r).locked&&patch.placement){toast('“'+r.name+'” is locked — unlock it to move or scale it');return;}
|
|
8865
|
+
edit(()=>{if(patch.display)r.display={...refDisp(r),...patch.display};
|
|
8866
|
+
if(patch.placement)r.placement={...(r.placement||{}),...patch.placement};});
|
|
8867
|
+
const v=window.Steel3DView;
|
|
8868
|
+
if(v){if(patch.display&&v.setReferenceDisplay)v.setReferenceDisplay(id,refDisp(r));
|
|
8869
|
+
if(patch.placement&&v.setReferencePlacement)v.setReferencePlacement(id,r.placement||null);}
|
|
8870
|
+
scheduleSave();renderRefsTab();
|
|
8871
|
+
}
|
|
8872
|
+
|
|
8873
|
+
// ── The References tab ────────────────────────────────────────────────────────────────────────────
|
|
8874
|
+
function renderRefsTab(){const host=document.getElementById('m3dRefsBody');if(!host)return;host.replaceChildren();
|
|
8875
|
+
const head=document.createElement('div');head.id='refHeadRow';
|
|
8876
|
+
const add=document.createElement('button');add.type='button';add.id='refAddBtn';add.textContent='+ Add a reference model';
|
|
8877
|
+
add.dataset.tip='Overlay an architect’s or engineer’s IFC to build against. It is never part of your steel.';
|
|
8878
|
+
add.addEventListener('click',()=>window.openRefImport());
|
|
8879
|
+
head.appendChild(add);host.appendChild(head);
|
|
8880
|
+
|
|
8881
|
+
const all=refList();
|
|
8882
|
+
if(!all.length){const e=Object.assign(document.createElement('div'),{className:'refempty'});
|
|
8883
|
+
e.textContent='No reference models yet — add somebody else’s IFC to see it beside your steel and snap to it. It never enters your BOM, an export, or the lock.';
|
|
8884
|
+
host.appendChild(e);return;}
|
|
8885
|
+
for(const r of all){host.appendChild(buildRefRow(r));if(r.id===refSelectedId)host.appendChild(buildRefDetail(r));}
|
|
8886
|
+
}
|
|
8887
|
+
|
|
8888
|
+
function buildRefRow(r){
|
|
8889
|
+
const d=refDisp(r),visible=d.visible!==false,snap=d.snap!==false,unresolved=refUnresolved.has(r.id);
|
|
8890
|
+
const row=document.createElement('div');
|
|
8891
|
+
row.className='refrow'+(visible?'':' hidden')+(r.id===refSelectedId?' sel':'')+(unresolved?' unresolved':'');
|
|
8892
|
+
row.dataset.id=r.id;
|
|
8893
|
+
|
|
8894
|
+
const sw=Object.assign(document.createElement('span'),{className:'refsw'});
|
|
8895
|
+
sw.dataset.tip=visible?'Hide this reference. It will still snap — turn snapping off separately.':'Show this reference';
|
|
8896
|
+
sw.addEventListener('click',e=>{e.stopPropagation();refEdit(r.id,{display:{visible:!visible}});});
|
|
8897
|
+
row.appendChild(sw);
|
|
8898
|
+
|
|
8899
|
+
// The cyan snap dot. It deliberately does NOT dim with a hidden row (see the CSS) — hiding a reference
|
|
8900
|
+
// does not stop it snapping, and that is the one thing here a user will misread.
|
|
8901
|
+
const dot=Object.assign(document.createElement('span'),{className:'refsnap'+(snap?'':' off')});
|
|
8902
|
+
dot.dataset.tip=snap
|
|
8903
|
+
?(visible?'Snapping to this reference is ON':'Hidden, but your model can still snap to it — click to stop that')
|
|
8904
|
+
:'Snapping to this reference is OFF';
|
|
8905
|
+
dot.addEventListener('click',e=>{e.stopPropagation();refEdit(r.id,{display:{snap:!snap}});});
|
|
8906
|
+
row.appendChild(dot);
|
|
8907
|
+
|
|
8908
|
+
const name=Object.assign(document.createElement('span'),{className:'refname'});
|
|
8909
|
+
// The suffix is the whole honesty budget of this row. `dropped` in particular is carried permanently
|
|
8910
|
+
// rather than announced once in a toast: the reader counts it precisely so a partial load cannot pass
|
|
8911
|
+
// for a whole one, and a count that only the importer ever saw does nothing for the colleague who
|
|
8912
|
+
// opens the project next.
|
|
8913
|
+
const geom=refGeom.get(r.id),failed=refFailed.get(r.id),empty=refEmpty.has(r.id);
|
|
8914
|
+
const suffix=refLoading.has(r.id)?' · loading…'
|
|
8915
|
+
:unresolved?' · file missing'
|
|
8916
|
+
:failed?' · could not load'
|
|
8917
|
+
:empty?' · nothing to draw'
|
|
8918
|
+
:(geom&&geom.dropped)?' · '+geom.dropped+' not drawn':'';
|
|
8919
|
+
name.textContent=r.name+suffix;
|
|
8920
|
+
name.dataset.tip=unresolved?'The original file is missing from this project — remove it and add the file again'
|
|
8921
|
+
:failed?failed+' — use ⋯ ▸ Reload its geometry to try again'
|
|
8922
|
+
:empty?'The reader read this file but found nothing it could draw'
|
|
8923
|
+
:(geom&&geom.dropped)?geom.dropped+' object'+(geom.dropped===1?'':'s')+' in this file carried no usable mesh, so they are not shown'
|
|
8924
|
+
:'Click to select the whole model';
|
|
8925
|
+
row.appendChild(name);
|
|
8926
|
+
|
|
8927
|
+
// PERMANENT, not hover-revealed. A reference can arrive correctly sized and 74 m up, entirely
|
|
8928
|
+
// off-screen; if "where is it?" hides until hover, the import reads as having silently failed.
|
|
8929
|
+
const zoom=Object.assign(document.createElement('span'),{className:'refzoom',textContent:'⤢'});
|
|
8930
|
+
zoom.setAttribute('role','button');zoom.dataset.tip='Zoom to this reference — it may sit far from your model';
|
|
8931
|
+
zoom.addEventListener('click',e=>{e.stopPropagation();
|
|
8932
|
+
if(window.Steel3DView&&window.Steel3DView.frameReference&&window.Steel3DView.frameReference(r.id))return;
|
|
8933
|
+
// "Still loading" was asserted for a state that, after a failed or empty read, never changes — so the
|
|
8934
|
+
// user was told to wait, waited, and was told to wait again. Name the real reason.
|
|
8935
|
+
toast(refLoading.has(r.id)?'Still reading its geometry — try again in a moment'
|
|
8936
|
+
:refFailed.has(r.id)?'Its geometry could not be loaded — use ⋯ ▸ Reload its geometry'
|
|
8937
|
+
:refEmpty.has(r.id)?'“'+r.name+'” contains nothing we can draw'
|
|
8938
|
+
:refUnresolved.has(r.id)?'Its file is missing from this project'
|
|
8939
|
+
:'Nothing to zoom to yet');});
|
|
8940
|
+
row.appendChild(zoom);
|
|
8941
|
+
|
|
8942
|
+
const dots=Object.assign(document.createElement('span'),{className:'refdots',textContent:'⋯'});
|
|
8943
|
+
dots.setAttribute('role','button');dots.dataset.tip='More — move it next to your model, reload, remove';
|
|
8944
|
+
dots.addEventListener('click',e=>{e.stopPropagation();openRefRowMenu(r,dots);});
|
|
8945
|
+
row.appendChild(dots);
|
|
8946
|
+
|
|
8947
|
+
row.addEventListener('click',()=>{
|
|
8948
|
+
refSelectedId=refSelectedId===r.id?null:r.id;
|
|
8949
|
+
if(window.Steel3DView&&window.Steel3DView.selectReference)window.Steel3DView.selectReference(refSelectedId);
|
|
8950
|
+
renderRefsTab();});
|
|
8951
|
+
return row;
|
|
8952
|
+
}
|
|
8953
|
+
|
|
8954
|
+
/** The expanded block for the selected reference — the five controls a row has no room for. */
|
|
8955
|
+
function buildRefDetail(r){
|
|
8956
|
+
const d=refDisp(r),wrap=document.createElement('div');wrap.className='refdet';
|
|
8957
|
+
const opPct=Math.round((Number.isFinite(d.opacity)?d.opacity:0.5)*100);
|
|
8958
|
+
|
|
8959
|
+
const opRow=document.createElement('div');opRow.className='drow';
|
|
8960
|
+
opRow.appendChild(Object.assign(document.createElement('span'),{className:'dlab',textContent:'Opacity'}));
|
|
8961
|
+
const op=document.createElement('input');op.type='range';op.min='10';op.max='100';op.value=String(opPct);
|
|
8962
|
+
op.dataset.tip='How solid this reference looks. Lower is easier to see your own steel through.';
|
|
8963
|
+
const opV=Object.assign(document.createElement('span'),{className:'dval',textContent:opPct+'%'});
|
|
8964
|
+
op.addEventListener('input',()=>{opV.textContent=op.value+'%';
|
|
8965
|
+
if(window.Steel3DView&&window.Steel3DView.setReferenceDisplay)window.Steel3DView.setReferenceDisplay(r.id,{...refDisp(r),opacity:op.value/100});});
|
|
8966
|
+
op.addEventListener('change',()=>refEdit(r.id,{display:{opacity:op.value/100}})); // live while dragging, persisted on release
|
|
8967
|
+
opRow.append(op,opV);wrap.appendChild(opRow);
|
|
8968
|
+
|
|
8969
|
+
const lock=document.createElement('button');lock.type='button';lock.className='lockrow'+(d.locked?' on':'');
|
|
8970
|
+
lock.setAttribute('role','menuitemcheckbox');lock.setAttribute('aria-checked',String(!!d.locked));
|
|
8971
|
+
lock.dataset.tip='Locked freezes moving, scaling and removing this reference. It stays visible and still snaps.';
|
|
8972
|
+
lock.append(Object.assign(document.createElement('span'),{className:'mck'}),document.createTextNode('Locked'));
|
|
8973
|
+
lock.addEventListener('click',()=>refEdit(r.id,{display:{locked:!d.locked}}));
|
|
8974
|
+
wrap.appendChild(lock);
|
|
8975
|
+
|
|
8976
|
+
// Always-visible, not a tooltip: the cross-wired hidden/snap state is exactly the kind of surprise that
|
|
8977
|
+
// has to reach someone who never hovers, and a keyboard or screen-reader user never sees a data-tip.
|
|
8978
|
+
const note=Object.assign(document.createElement('div'),{className:'dnote'});
|
|
8979
|
+
note.textContent=d.visible===false
|
|
8980
|
+
?'Hidden — but your model can still snap to it. The cyan dot on the row is the snap switch.'
|
|
8981
|
+
:'Hiding this reference does not stop snapping to it — the cyan dot on the row does.';
|
|
8982
|
+
wrap.appendChild(note);
|
|
8983
|
+
|
|
8984
|
+
// The TRUE size — measured off the geometry that is actually on screen, which is the only place this
|
|
8985
|
+
// number can be honest. The import modal deliberately shows none: before tessellation the sole
|
|
8986
|
+
// measurement available is the reader's own APPROXIMATE bbox, and that spans every point the file
|
|
8987
|
+
// places rather than the model (74 m for a 3.6 m lift shaft, measured).
|
|
8988
|
+
const sb=window.Steel3DView&&window.Steel3DView.referenceBounds?window.Steel3DView.referenceBounds(r.id):null;
|
|
8989
|
+
if(sb){const sz=Object.assign(document.createElement('div'),{className:'dnote'});
|
|
8990
|
+
sz.textContent='Size '+[0,1,2].map(i=>Math.round((sb.max[i]-sb.min[i])/10)/100).join(' × ')+' m';
|
|
8991
|
+
wrap.appendChild(sz);}
|
|
8992
|
+
|
|
8993
|
+
// The declared unit is shown as PROVENANCE and nothing more. There is deliberately no override
|
|
8994
|
+
// control in S1: review found the one that was here wrote `units.override` into the contract and
|
|
8995
|
+
// nothing read it back, so a user with the single file it exists for — one that lies about its units
|
|
8996
|
+
// — would set it, watch it persist, and see the geometry not move. The schema keeps the field (the
|
|
8997
|
+
// reader fills `declared`); the correction it enables is the Scale box below, which does work.
|
|
8998
|
+
const said=(r.units&&r.units.declared)||null;
|
|
8999
|
+
const uNote=Object.assign(document.createElement('div'),{className:'dnote'});
|
|
9000
|
+
uNote.textContent=said?('This file says: '+unitWords(said)+' — already applied'):'This file does not say what units it uses';
|
|
9001
|
+
uNote.dataset.tip='What the IFC declared. FloLess has already applied it, so a correctly-made file needs no rescaling.';
|
|
9002
|
+
wrap.appendChild(uNote);
|
|
9003
|
+
|
|
9004
|
+
const sRow=document.createElement('div');sRow.className='drow';
|
|
9005
|
+
sRow.appendChild(Object.assign(document.createElement('span'),{className:'dlab',textContent:'Scale'}));
|
|
9006
|
+
const sc=document.createElement('input');sc.type='text';sc.style.cssText='flex:1;min-width:0';
|
|
9007
|
+
sc.value=String((r.placement&&r.placement.scale)||1);sc.dataset.tip='Uniform scale, applied about the insertion point. 1 is the file’s own size.';
|
|
9008
|
+
sc.addEventListener('change',()=>{const v=parseFloat(sc.value);
|
|
9009
|
+
if(!(v>0)){sc.value=String((r.placement&&r.placement.scale)||1);toast('Scale must be a positive number');return;}
|
|
9010
|
+
refEdit(r.id,{placement:{scale:v}});});
|
|
9011
|
+
sRow.appendChild(sc);wrap.appendChild(sRow);
|
|
9012
|
+
|
|
9013
|
+
// The scale advisory, on a measurement that can bear it: `spanMm` is computed server-side from the
|
|
9014
|
+
// vertices the reader actually returned. The pre-insert modal deliberately offers none, because
|
|
9015
|
+
// before tessellation the only number available is the reader's bbox, which spans everything the file
|
|
9016
|
+
// MENTIONS (74 m for a 3.6 m shaft) and would offer to permanently mis-scale a correct reference.
|
|
9017
|
+
const scale=refScaleAdvice(r.id);
|
|
9018
|
+
if(scale){
|
|
9019
|
+
const w=Object.assign(document.createElement('div'),{className:'dwarn'});
|
|
9020
|
+
w.textContent='This looks about '+scale.words+' your model. If the file states the wrong units, this is the usual fix.';
|
|
9021
|
+
const fix=document.createElement('button');fix.type='button';fix.className='ghost';fix.style.marginTop='6px';
|
|
9022
|
+
fix.textContent='Scale ×'+scale.factor;fix.dataset.tip='Apply this scale. You can always type another value in the Scale box.';
|
|
9023
|
+
fix.addEventListener('click',()=>refEdit(r.id,{placement:{scale:(((r.placement||{}).scale)||1)*scale.factor}}));
|
|
9024
|
+
w.appendChild(document.createElement('br'));w.appendChild(fix);wrap.appendChild(w);
|
|
9025
|
+
}
|
|
9026
|
+
if(refOffscreen(r.id)){
|
|
9027
|
+
const w=Object.assign(document.createElement('div'),{className:'dwarn'});
|
|
9028
|
+
w.textContent='This sits a long way from your model — it is probably at real site coordinates.';
|
|
9029
|
+
const fix=document.createElement('button');fix.type='button';fix.className='ghost';fix.style.marginTop='6px';
|
|
9030
|
+
fix.textContent=REF_MOVE_LABEL;fix.dataset.tip='Shift this reference so its centre lands on your model’s centre';
|
|
9031
|
+
fix.addEventListener('click',()=>refMoveToOrigin(r.id));
|
|
9032
|
+
w.appendChild(document.createElement('br'));w.appendChild(fix);wrap.appendChild(w);
|
|
9033
|
+
}
|
|
9034
|
+
return wrap;
|
|
9035
|
+
}
|
|
9036
|
+
|
|
9037
|
+
/** A file size a human recognises from their file manager. KB under a megabyte, MB above it. */
|
|
9038
|
+
function fileSizeWords(bytes){
|
|
9039
|
+
const n=Number(bytes)||0;
|
|
9040
|
+
return n<1024*1024?Math.max(1,Math.round(n/1024))+' KB':(Math.round(n/(1024*1024)*10)/10)+' MB';
|
|
9041
|
+
}
|
|
9042
|
+
/** "MILLI.METRE" → "millimetres". Plain words, because the panel is read by people who do not write IFC. */
|
|
9043
|
+
function unitWords(declared){
|
|
9044
|
+
const map={'MILLI.METRE':'millimetres','CENTI.METRE':'centimetres','METRE':'metres','INCH':'inches','FOOT':'feet'};
|
|
9045
|
+
return map[String(declared||'').toUpperCase()]||String(declared||'').toLowerCase().replace(/\./g,' ');
|
|
9046
|
+
}
|
|
9047
|
+
/**
|
|
9048
|
+
* The label for the move, in ONE place because there are two buttons for it — the advisory's offer in
|
|
9049
|
+
* the row detail and the unconditional ⋯ item — and design review's point was that the same action
|
|
9050
|
+
* wearing two independently-edited labels is a drift waiting to happen. (They are deliberately both
|
|
9051
|
+
* kept: the advisory's copy only exists while the reference IS far away, while the ⋯ item is the
|
|
9052
|
+
* general-purpose nudge after a manual drag.)
|
|
9053
|
+
*/
|
|
9054
|
+
const REF_MOVE_LABEL='Move it next to your model';
|
|
9055
|
+
/**
|
|
9056
|
+
* Shift a reference so its centre lands ON THE MODEL — the fix the Motebello measurement earned.
|
|
9057
|
+
*
|
|
9058
|
+
* ONTO THE MODEL'S CENTRE, NOT THE WORLD ORIGIN, and that distinction is the whole point. The
|
|
9059
|
+
* off-screen advisory that offers this measures the distance from the model's centre (`refOffscreen`),
|
|
9060
|
+
* so a remedy that moved to [0,0,0] could not resolve the condition it was offered for: driving a
|
|
9061
|
+
* project whose own steel sits at real survey coordinates, taking the offer moved the reference 99 m
|
|
9062
|
+
* AWAY from the steel it was meant to join, and the advisory then persisted through every further
|
|
9063
|
+
* click. Same shape as the scale advice that survived being taken, on the other axis of the same
|
|
9064
|
+
* panel. `nativeModelCentre()` returns [0,0,0] when there is no model to centre on, so a project at
|
|
9065
|
+
* the origin — every project the first two passes drove — behaves exactly as it did.
|
|
9066
|
+
*/
|
|
9067
|
+
function refMoveToOrigin(id){
|
|
9068
|
+
const b=window.Steel3DView&&window.Steel3DView.referenceBounds?window.Steel3DView.referenceBounds(id):null;
|
|
9069
|
+
if(!b){toast(refLoading.has(id)?'Still reading its geometry — try again in a moment':'There is no geometry to move yet');return;}
|
|
9070
|
+
const r=refById(id);if(!r)return;
|
|
9071
|
+
// REFUSE WHEN THERE IS NOTHING TO BE NEXT TO. Overlaying somebody's IFC before you have modelled any
|
|
9072
|
+
// steel is a normal first move, and `sceneBounds()` is null then — so the centre would fall back to
|
|
9073
|
+
// [0,0,0] and this would teleport a site-coordinate reference 99 km, silently, to sit beside nothing.
|
|
9074
|
+
// Worse, it is not undoable: `snapshot()` does not capture `reference_models`, so Ctrl+Z restores
|
|
9075
|
+
// unrelated state and leaves the reference where it landed. The sibling refusal above already toasts
|
|
9076
|
+
// for the other unsatisfiable precondition; this is the same courtesy for this one.
|
|
9077
|
+
const n=nativeModelBounds();
|
|
9078
|
+
if(!n){toast('There is no steel in this model yet to move it next to');return;}
|
|
9079
|
+
const o=(r.placement&&r.placement.origin)||[0,0,0];
|
|
9080
|
+
const c=[(b.min[0]+b.max[0])/2,(b.min[1]+b.max[1])/2,(b.min[2]+b.max[2])/2];
|
|
9081
|
+
const m=[0,1,2].map(i=>(n.min[i]+n.max[i])/2);
|
|
9082
|
+
refEdit(id,{placement:{origin:[o[0]-c[0]+m[0],o[1]-c[1]+m[1],o[2]-c[2]+m[2]]}});
|
|
9083
|
+
if(window.Steel3DView&&window.Steel3DView.frameReference)window.Steel3DView.frameReference(id);
|
|
9084
|
+
}
|
|
9085
|
+
|
|
9086
|
+
function openRefRowMenu(r,anchorEl){closeRefRowMenu();
|
|
9087
|
+
const m=document.createElement('div');m.id='refRowMenu';m.className='m3dmenu open';m.setAttribute('role','menu');
|
|
9088
|
+
const mk=(label,fn,danger)=>{const b=document.createElement('button');b.type='button';b.textContent=label;if(danger)b.className='mdanger';b.setAttribute('role','menuitem');b.addEventListener('click',()=>{closeRefRowMenu();fn();});return b;};
|
|
9089
|
+
m.append(mk('Zoom to it',()=>{if(window.Steel3DView)window.Steel3DView.frameReference(r.id);}));
|
|
9090
|
+
// OFFERED ONLY WHEN THERE IS SOMETHING TO BE NEXT TO. Loading a reference before modelling any steel is
|
|
9091
|
+
// a normal first move, and in that state this command can do nothing but toast a refusal — an enabled
|
|
9092
|
+
// item that always fails is a worse answer than no item. Omitted rather than disabled, which is how
|
|
9093
|
+
// this feature already hides the References tab itself on a project that cannot have references.
|
|
9094
|
+
// (`refMoveToOrigin` keeps its own refusal: it is reachable from the panel's advisory offer, and a
|
|
9095
|
+
// guard that only exists in the caller is one refactor from being gone.)
|
|
9096
|
+
if(nativeModelBounds())m.append(mk(REF_MOVE_LABEL,()=>refMoveToOrigin(r.id)));
|
|
9097
|
+
m.append(mk('Reload its geometry',()=>{
|
|
9098
|
+
if(refDisp(r).locked){toast('“'+r.name+'” is locked — unlock it to reload it');return;} // the lock freezes reload, as the schema says
|
|
9099
|
+
refGeom.delete(r.id);refFailed.delete(r.id);refEmpty.delete(r.id);refUnresolved.delete(r.id);loadReferenceGeometry(r.id);}));
|
|
9100
|
+
m.appendChild(document.createElement('hr'));
|
|
9101
|
+
m.appendChild(mk('Remove',()=>refRemove(r),true));
|
|
9102
|
+
document.body.appendChild(m);
|
|
9103
|
+
const rc=anchorEl.getBoundingClientRect();const mw=m.offsetWidth||184,mh=m.offsetHeight||120;
|
|
9104
|
+
let x=rc.right-mw,y=rc.bottom+4;if(x<6)x=6;if(y+mh>innerHeight-6)y=rc.top-mh-4;if(y<6)y=6;
|
|
9105
|
+
m.style.left=x+'px';m.style.top=y+'px';
|
|
9106
|
+
setTimeout(()=>document.addEventListener('mousedown',refRowMenuOutside,true),0);
|
|
9107
|
+
}
|
|
9108
|
+
function refRowMenuOutside(e){const m=document.getElementById('refRowMenu');if(m&&!m.contains(e.target))closeRefRowMenu();}
|
|
9109
|
+
function closeRefRowMenu(){const m=document.getElementById('refRowMenu');if(m)m.remove();document.removeEventListener('mousedown',refRowMenuOutside,true);}
|
|
9110
|
+
|
|
9111
|
+
/**
|
|
9112
|
+
* Remove a reference — the contract entry, its copied original and its cached geometry.
|
|
9113
|
+
*
|
|
9114
|
+
* NO UNDO TOAST, unlike a favourite. Undo there re-POSTs a recipe; here the original file has been
|
|
9115
|
+
* deleted from the project, so an "undo" would have to re-upload bytes the browser no longer holds.
|
|
9116
|
+
* Promising a restore we cannot perform is worse than not offering one.
|
|
9117
|
+
*/
|
|
9118
|
+
async function refRemove(r){
|
|
9119
|
+
if(refDisp(r).locked){toast('“'+r.name+'” is locked — unlock it first');return;}
|
|
9120
|
+
if(!await confirmDanger({title:'Remove “'+r.name+'”?',body:'Its copy inside this project is deleted too. Your own steel is untouched.',confirmLabel:'Remove'}))return;
|
|
9121
|
+
try{
|
|
9122
|
+
const mid=newMutationId();claimMutation(mid);
|
|
9123
|
+
const res=await fetch(refApi('/'+encodeURIComponent(r.id)),{method:'DELETE',headers:{'x-floless-mutation-id':mid}});
|
|
9124
|
+
const d=await res.json().catch(()=>({}));
|
|
9125
|
+
if(!res.ok||!d.ok){toast(d.error||'Could not remove that reference');return;}
|
|
9126
|
+
adoptReferenceWrite(d.etag);
|
|
9127
|
+
const i=refList().findIndex(x=>x&&x.id===r.id);if(i>=0)C.reference_models.splice(i,1);
|
|
9128
|
+
refGeom.delete(r.id);refUnresolved.delete(r.id);refFailed.delete(r.id);refEmpty.delete(r.id);
|
|
9129
|
+
if(refSelectedId===r.id)refSelectedId=null;
|
|
9130
|
+
pushReferences();renderRefsTab();
|
|
9131
|
+
}catch(_){toast('Could not remove that reference');}
|
|
9132
|
+
}
|
|
9133
|
+
|
|
9134
|
+
/**
|
|
9135
|
+
* Adopt the tag a reference verb produced.
|
|
9136
|
+
*
|
|
9137
|
+
* The routes write the contract themselves, so the tag this tab holds is stale the moment they return —
|
|
9138
|
+
* and the next ordinary save would 412 against a change this very tab asked for. Same two moves the
|
|
9139
|
+
* contract PUT makes on success: take the new tag, and re-point the stored draft at it.
|
|
9140
|
+
*/
|
|
9141
|
+
function adoptReferenceWrite(etag){if(!etag)return;const prev=serverEtag;serverEtag=etag;restampDraftBase(prev,etag);conflicted=false;}
|
|
9142
|
+
|
|
9143
|
+
// ── The import modal: drop → probe → confirm ──────────────────────────────────────────────────────
|
|
9144
|
+
{ const ri$=id=>document.getElementById(id);
|
|
9145
|
+
// `riProbeCentre` is reset alongside the rest on every open — it used to survive from the PREVIOUS
|
|
9146
|
+
// file, which only failed to matter because `riInsert` bails on a missing `riSha`.
|
|
9147
|
+
let riSha=null,riName='',riVerdict=null,riProbeCentre=null,riSoftT=null,riBusy=false;
|
|
9148
|
+
const riClearSoft=()=>{if(riSoftT){clearTimeout(riSoftT);riSoftT=null;}};
|
|
9149
|
+
const riStage=s=>{ // 'drop' | 'prog' | 'confirm'
|
|
9150
|
+
ri$('riDropStage').style.display=s==='drop'?'':'none';
|
|
9151
|
+
ri$('riProgStage').style.display=s==='prog'?'':'none';
|
|
9152
|
+
ri$('riConfirmStage').style.display=s==='confirm'?'':'none';
|
|
9153
|
+
ri$('riInsert').style.display=s==='confirm'?'':'none';
|
|
9154
|
+
ri$('riClose').style.display=s==='prog'?'none':''; // no ✕ mid-run — Cancel owns the exit
|
|
9155
|
+
ri$('riTitle').textContent=s==='prog'?'Reading the file':s==='confirm'?'Add this reference?':'Add a reference model';};
|
|
9156
|
+
const riProg=(label,soft)=>{riClearSoft();ri$('riProgTxt').textContent=label;
|
|
9157
|
+
if(soft)riSoftT=setTimeout(()=>{ri$('riProgTxt').textContent=soft;},6000);}; // an honest "still working", never a fake %
|
|
9158
|
+
const riErr=msg=>{const e=ri$('riDropErr');if(msg){e.textContent=msg;e.style.display='block';}else{e.style.display='none';e.textContent='';}};
|
|
9159
|
+
|
|
9160
|
+
function openRefImport(){
|
|
9161
|
+
if(!MODEL_V2){toast('Reference models need this project on the model-level contract');return;}
|
|
9162
|
+
if(!view3d){toast('Switch to the 3D view to add a reference model');return;}
|
|
9163
|
+
riSha=null;riName='';riVerdict=null;riProbeCentre=null;riErr('');ri$('riDrop').classList.remove('drag');
|
|
9164
|
+
riStage('drop');ri$('refImportModal').style.display='flex';}
|
|
9165
|
+
window.openRefImport=openRefImport;
|
|
9166
|
+
function riClose(){riClearSoft();ri$('refImportModal').style.display='none';}
|
|
9167
|
+
|
|
9168
|
+
const RI_MAX_BYTES=150*1024*1024; // mirrors MAX_BYTES in server/reference-import.ts (pinned by the parity test)
|
|
9169
|
+
function riReadFile(f){ if(!f||riBusy)return;riErr('');
|
|
9170
|
+
if(!/\.(ifc|ifczip)$/i.test(f.name||'')){riErr('Not an IFC file — expected .ifc or .ifczip.');return;}
|
|
9171
|
+
if(f.size>RI_MAX_BYTES){riErr('“'+f.name+'” is '+fileSizeWords(f.size)+'; the limit for a reference model is 150 MB. Try exporting just the part of the model you need to see.');return;}
|
|
9172
|
+
riName=f.name;
|
|
9173
|
+
const fr=new FileReader();
|
|
9174
|
+
fr.onerror=()=>{riStage('drop');riErr('Could not read that file.');};
|
|
9175
|
+
fr.onload=()=>riProbe(String(fr.result||''),f);
|
|
9176
|
+
riStage('prog');riProg('Reading “'+f.name+'”…');
|
|
9177
|
+
fr.readAsDataURL(f);}
|
|
9178
|
+
|
|
9179
|
+
async function riProbe(dataUrl,f){
|
|
9180
|
+
riProg('Checking what “'+f.name+'” says about itself…','Still checking — a large model takes a moment.');
|
|
9181
|
+
try{
|
|
9182
|
+
const res=await fetch(refApi('/probe'),{method:'POST',headers:{'content-type':'application/json'},
|
|
9183
|
+
// The model's CENTRE rides along with its span: "off-screen" is a question about the distance
|
|
9184
|
+
// between the reference and the steel, and the server has no other way to know where the steel is.
|
|
9185
|
+
body:JSON.stringify({dataUrl,name:f.name,nativeSpan:nativeModelSpan(),nativeCenter:nativeModelCentre()})});
|
|
9186
|
+
const d=await res.json().catch(()=>({}));
|
|
9187
|
+
riClearSoft();
|
|
9188
|
+
if(!res.ok||!d.ok){riStage('drop');riErr(d.error||'Could not read that file.');return;}
|
|
9189
|
+
riSha=d.sha;riVerdict=d.verdict||null;
|
|
9190
|
+
{const bb=d.probe&&d.probe.bbox;riProbeCentre=bb?[0,1,2].map(i=>(bb.min[i]+bb.max[i])/2):null;}
|
|
9191
|
+
const said=d.probe&&d.probe.units&&d.probe.units.declared;
|
|
9192
|
+
const says=ri$('riSays');says.replaceChildren();
|
|
9193
|
+
const b=document.createElement('b');b.textContent='This file says: ';
|
|
9194
|
+
says.append(b,document.createTextNode(said?unitWords(said):'nothing about its units'),
|
|
9195
|
+
document.createTextNode('. FloLess has already applied that — you should not need to rescale it.'));
|
|
9196
|
+
ri$('riSchema').textContent=(d.probe&&d.probe.schema)||'—';
|
|
9197
|
+
ri$('riElements').textContent=String((d.probe&&d.probe.elements)||0);
|
|
9198
|
+
// KB below a megabyte. `Math.max(1, …)` reported a 7.6 KB file as "1 MB" — a small lie, but the
|
|
9199
|
+
// number sits directly above a limit stated in MB, so it made the two unreadable together.
|
|
9200
|
+
ri$('riBytes').textContent=fileSizeWords(d.bytes||0);
|
|
9201
|
+
riShowVerdict(d.warn,d.bytes);
|
|
9202
|
+
riStage('confirm');
|
|
9203
|
+
}catch(_){riClearSoft();riStage('drop');riErr('Could not reach the reader — check the app is running.');}}
|
|
9204
|
+
|
|
9205
|
+
/** The advisory. AMBER, never red: a scale or position guess is an offer, not something being broken. */
|
|
9206
|
+
function riShowVerdict(warn,bytes){
|
|
9207
|
+
const v=ri$('riVerdict');v.replaceChildren();v.style.display='none';
|
|
9208
|
+
const lines=[];
|
|
9209
|
+
if(warn)lines.push('At '+Math.round((bytes||0)/(1024*1024))+' MB this will take a while to read.');
|
|
9210
|
+
// POSITION ONLY before the file is read. A size judgement needs the geometry, and the only
|
|
9211
|
+
// pre-tessellation measurement available describes everything the file mentions rather than what it
|
|
9212
|
+
// draws — so the scale advice waits for the panel, where the rendered span is real. Position does
|
|
9213
|
+
// not have that problem: "these points are a long way from the origin" needs no such distinction.
|
|
9214
|
+
if(riVerdict&&riVerdict.offscreen)lines.push('This sits a long way from your model — probably at real site coordinates, so it will land off-screen.');
|
|
9215
|
+
if(!lines.length)return;
|
|
9216
|
+
v.appendChild(document.createTextNode(lines.join(' ')));
|
|
9217
|
+
// The fix PRE-FILLS; Add is never gated on taking it. Declining just inserts as probed.
|
|
9218
|
+
if(riVerdict&&riVerdict.offscreen){
|
|
9219
|
+
const fix=document.createElement('button');fix.type='button';fix.className='ghost';
|
|
9220
|
+
fix.textContent='Move it next to my model';fix.dataset.tip='Apply this when the reference is added';
|
|
9221
|
+
fix.addEventListener('click',()=>{fix.classList.add('on');fix.textContent='Will move it next to your model';});
|
|
9222
|
+
v.appendChild(document.createElement('br'));v.appendChild(fix);
|
|
9223
|
+
}
|
|
9224
|
+
v.style.display='block';}
|
|
9225
|
+
|
|
9226
|
+
async function riInsert(){
|
|
9227
|
+
if(!riSha||riBusy)return;riBusy=true;
|
|
9228
|
+
let inserted=null,d=null;
|
|
9229
|
+
const takeOrigin=!!ri$('riVerdict').querySelector('button.on')&&riVerdict&&riVerdict.offscreen;
|
|
9230
|
+
// Computed from the PROBE's own centre, which is what the offer was based on, and TOWARDS THE
|
|
9231
|
+
// MODEL'S CENTRE rather than the world origin — the same correction `refMoveToOrigin` carries, for
|
|
9232
|
+
// the same reason: the offer is made because the reference is far from the STEEL, so landing it on
|
|
9233
|
+
// [0,0,0] in a site-coordinate project would answer a question nobody asked. It is approximate for
|
|
9234
|
+
// the same reason the offer is (the bbox spans everything the file places) — the panel's own offer
|
|
9235
|
+
// re-does it exactly once the real bounds exist.
|
|
9236
|
+
const riNative=nativeModelCentre();
|
|
9237
|
+
const riOriginShift=takeOrigin&&riProbeCentre?riProbeCentre.map((v,i)=>riNative[i]-v):null;
|
|
9238
|
+
riStage('prog');riProg('Reading the geometry…','Still reading — a whole building takes a moment.');
|
|
9239
|
+
try{
|
|
9240
|
+
const mid=newMutationId();claimMutation(mid);
|
|
9241
|
+
const res=await fetch(refApi(''),{method:'POST',headers:{'content-type':'application/json','x-floless-mutation-id':mid},
|
|
9242
|
+
// The placement rides the INSERT, so the choice the user made in the modal is committed with
|
|
9243
|
+
// the reference rather than by a debounced PUT afterwards. Applying it in the presentation
|
|
9244
|
+
// block left it outside the point of no return: a closed tab or a save conflict would leave
|
|
9245
|
+
// the server holding the site coordinates the user had just asked to move away from.
|
|
9246
|
+
body:JSON.stringify({sha:riSha,name:riName,...(takeOrigin&&riOriginShift?{placement:{origin:riOriginShift}}:{})})});
|
|
9247
|
+
d=await res.json().catch(()=>({}));
|
|
9248
|
+
riClearSoft();
|
|
9249
|
+
if(!res.ok||!d.ok){riStage('drop');riErr(d.error||'Could not add that reference.');return;}
|
|
9250
|
+
adoptReferenceWrite(d.etag);
|
|
9251
|
+
if(!Array.isArray(C.reference_models))C.reference_models=[];
|
|
9252
|
+
C.reference_models.push(d.reference);
|
|
9253
|
+
refGeom.set(d.reference.id,{objects:d.objects||[],dropped:d.dropped||0,spanMm:d.spanMm||0});
|
|
9254
|
+
refSelectedId=d.reference.id;
|
|
9255
|
+
inserted=d.reference;
|
|
9256
|
+
}catch(e){riClearSoft();riStage('drop');riErr('Could not add that reference.');console.error('[reference] insert failed',e);return;}
|
|
9257
|
+
finally{riBusy=false;}
|
|
9258
|
+
// ── PAST THE POINT OF NO RETURN. Everything above is the transaction; everything below is showing
|
|
9259
|
+
// it. They were one try, and a throw in the presentation half ran riErr() on a modal riClose() had
|
|
9260
|
+
// already hidden — so the user saw NOTHING while the reference was committed and on disk, and the
|
|
9261
|
+
// natural response (drop the file again) made a second copy. Uploading tens of megabytes of vertex
|
|
9262
|
+
// buffers is exactly where a RangeError is plausible, so this is not a theoretical split.
|
|
9263
|
+
riClose();
|
|
9264
|
+
try{
|
|
9265
|
+
pushReferences();
|
|
9266
|
+
setLegendTab('refs');showLegendPanel('refs',true);
|
|
9267
|
+
// Frame it immediately. A reference at real site coordinates is off-screen the moment it lands,
|
|
9268
|
+
// and "nothing happened" is what the user concludes otherwise. (The move itself was committed
|
|
9269
|
+
// WITH the insert — see the request body — so there is nothing to apply here.)
|
|
9270
|
+
if(window.Steel3DView&&window.Steel3DView.frameReference)window.Steel3DView.frameReference(inserted.id);
|
|
9271
|
+
renderRefsTab();
|
|
9272
|
+
toast('Added “'+inserted.name+'” as a reference'+(d.dropped?' ('+d.dropped+' object'+(d.dropped===1?'':'s')+' had nothing to draw)':''));
|
|
9273
|
+
}catch(e){
|
|
9274
|
+
console.error('[reference] added, but the view could not be updated',e);
|
|
9275
|
+
toast('Added “'+inserted.name+'” — reload the view to see it');
|
|
9276
|
+
}}
|
|
9277
|
+
|
|
9278
|
+
ri$('riClose').onclick=riClose;ri$('riCancel').onclick=riClose;ri$('riBackdrop').onclick=riClose;
|
|
9279
|
+
ri$('riInsert').onclick=riInsert;
|
|
9280
|
+
ri$('riDrop').onclick=()=>ri$('riFile').click();
|
|
9281
|
+
ri$('riDrop').onkeydown=e=>{if(e.key==='Enter'||e.key===' '){e.preventDefault();ri$('riFile').click();}};
|
|
9282
|
+
ri$('riFile').onchange=e=>{const f=e.target.files&&e.target.files[0];e.target.value='';riReadFile(f);};
|
|
9283
|
+
for(const ev of ['dragenter','dragover'])ri$('riDrop').addEventListener(ev,e=>{e.preventDefault();ri$('riDrop').classList.add('drag');});
|
|
9284
|
+
for(const ev of ['dragleave','drop'])ri$('riDrop').addEventListener(ev,e=>{e.preventDefault();ri$('riDrop').classList.remove('drag');});
|
|
9285
|
+
ri$('riDrop').addEventListener('drop',e=>{const f=e.dataTransfer&&e.dataTransfer.files&&e.dataTransfer.files[0];riReadFile(f);});
|
|
9286
|
+
}
|
|
9287
|
+
|
|
8524
9288
|
// ── Apply a favourite in-editor: arm the placement crosshair (sticky → repeat), then click a target ──────────
|
|
8525
9289
|
function armFavouriteInsert(f){if(!f)return;
|
|
8526
9290
|
if(!view3d){toast('Switch to the 3D view to place a connection');return;}
|
|
@@ -8869,6 +9633,12 @@ function wire3DBar(){if(bar3dWired||!window.Steel3DView)return;bar3dWired=true;
|
|
|
8869
9633
|
frag.appendChild(document.createElement('hr'));
|
|
8870
9634
|
const add=document.createElement('button');add.textContent='+ Add an image…';add.onclick=()=>{insMenuClose();closeMore();document.getElementById('insFile').click();};frag.appendChild(add);
|
|
8871
9635
|
const conn=document.createElement('button');conn.textContent='Connection…';conn.dataset.tip='Import a steel connection from an IFC file';conn.onclick=()=>{insMenuClose();closeMore();window.openConnImport();};frag.appendChild(conn);
|
|
9636
|
+
// Reference models (#278). On a v1 project the ITEM is replaced by a muted, non-interactive line in
|
|
9637
|
+
// the exact place the feature will appear once unlocked — hiding it outright would be honest but
|
|
9638
|
+
// undiscoverable, and a DISABLED button is the anti-pattern this modal family already avoids. One
|
|
9639
|
+
// location, one sentence: no separate explanation to drift out of step with this one.
|
|
9640
|
+
if(MODEL_V2){const rm=document.createElement('button');rm.textContent='Reference model…';rm.dataset.tip='Overlay an architect’s or engineer’s IFC to build against. It is never part of your steel — no BOM, no export, no lock.';rm.onclick=()=>{insMenuClose();closeMore();window.openRefImport();};frag.appendChild(rm);}
|
|
9641
|
+
else{const note=document.createElement('div');note.className='mhint';note.style.cssText='padding:4px 10px;color:var(--mut);font-size:11px;line-height:1.45;max-width:220px;white-space:normal';note.textContent='Reference models need this project on the model-level contract — ask your terminal AI to migrate it.';frag.appendChild(note);}
|
|
8872
9642
|
insMenu.replaceChildren(frag);}
|
|
8873
9643
|
insBtn.onclick=e=>{e.stopPropagation();
|
|
8874
9644
|
if(d3.insertMode()){d3.setInsertMode(false);return;} // armed → cancel the pick
|
|
@@ -9060,7 +9830,14 @@ async function setView(on){
|
|
|
9060
9830
|
if(seq!==viewSeq)return;
|
|
9061
9831
|
window.Steel3DView.setSelection(selIds);
|
|
9062
9832
|
if(window.Steel3DView.setGridSelection)window.Steel3DView.setGridSelection(selGridIds); // carry the shared 2D grid selection across the rebuild; rebuild replaces the line objects/materials
|
|
9063
|
-
wire3DBar();wireLegendTabs();loadSteelFavourites();build3DLegend();
|
|
9833
|
+
wire3DBar();wireLegendTabs();loadSteelFavourites();build3DLegend();
|
|
9834
|
+
// Reference models (#278). The tab exists only on the model-level contract — hidden, not disabled,
|
|
9835
|
+
// because a tab that can never hold anything is the same dead chrome the header stats are hidden for.
|
|
9836
|
+
{const t=document.querySelector('#m3dTabs .m3dtab[data-tab=refs]');if(t)t.style.display=MODEL_V2?'':'none';}
|
|
9837
|
+
showLegendPanel(); // open the panel on the last-used tab (setLegendTab falls back off 'refs' on v1)
|
|
9838
|
+
// Push what we already hold, THEN stream the rest in behind the native steel. Deliberately not
|
|
9839
|
+
// awaited: a project must never wait on somebody else's coordination model to finish opening.
|
|
9840
|
+
pushReferences();loadAllReferences();
|
|
9064
9841
|
reflectProj();reflectMode(); // reflect persisted projection + display mode into the Camera/Display dropdown triggers
|
|
9065
9842
|
}catch(e){ // a failed open must not strand the UI in 3D with a blank canvas
|
|
9066
9843
|
// …but only if this switch is still the current one. rebuild() awaits a POST to /scene, so it can
|