@floless/app 0.135.1 → 0.137.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 +634 -274
- package/dist/schemas/steel.model.v2.schema.json +18 -17
- package/dist/skills/floless-app-report-issue/SKILL.md +46 -9
- package/dist/skills/floless-app-steel-model/SKILL.md +13 -12
- package/dist/skills/floless-app-steel-takeoff/SKILL.md +61 -65
- package/dist/skills/floless-app-steel-takeoff/references/elevation-registration.md +119 -0
- package/dist/templates/steel-model.flo +44 -4
- package/dist/web/commands-steel.js +6 -0
- package/dist/web/instructor.js +1 -0
- package/dist/web/steel-editor.html +609 -56
- package/dist/web/steel-model-v2-client-validation.js +36 -17
- package/dist/web/steel-model-v2-commands.js +82 -86
- package/dist/web/steel-model-v2-projection.js +179 -22
- package/dist/web/steel-plan-transform.js +82 -29
- package/dist/web/steel-plan-view-id.js +140 -0
- package/dist/web/steel-view-generation.js +2 -1
- package/dist/web/workspaces.js +7 -2
- package/package.json +2 -1
|
@@ -6,9 +6,13 @@
|
|
|
6
6
|
* It never mutates the model; importing this module is therefore inert.
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
+
import { planViewId, planViewLabels } from './steel-plan-view-id.js';
|
|
10
|
+
/* Re-exported so the editor, which loads this module dynamically as `V2Projection`, has ONE place to
|
|
11
|
+
* ask what a row's identity and display name are — rather than reading `.sheet` and hoping (#938). */
|
|
12
|
+
export { planViewId, planViewLabels };
|
|
9
13
|
import { sheetIncludesElevation,POSITION_BASIS_CAPABILITY_VERSION } from './steel-3d-core.js';
|
|
10
14
|
export const POSITION_BASIS_PROJECTION_VERSION=POSITION_BASIS_CAPABILITY_VERSION;
|
|
11
|
-
import { worldToSheetPx } from './steel-plan-transform.js';
|
|
15
|
+
import { worldToSheetPx, planTransform, PlanTransformError } from './steel-plan-transform.js';
|
|
12
16
|
|
|
13
17
|
const IN_MM = 25.4;
|
|
14
18
|
export const V2_PROJECTION_LINK = Symbol.for('floless.steelModelV2ProjectionLink');
|
|
@@ -44,12 +48,97 @@ export function memberPresence(model, plan, member) {
|
|
|
44
48
|
return { observed, explicit, crossing, visible: observed || explicit || crossing };
|
|
45
49
|
}
|
|
46
50
|
|
|
47
|
-
|
|
51
|
+
/**
|
|
52
|
+
* The drawing VIEWS that display this member (#938), in document order.
|
|
53
|
+
*
|
|
54
|
+
* It used to return `p.sheet`, which was the same list only while a page could carry one view. With
|
|
55
|
+
* five elevations on S5.1 that answer collapses five different registrations into one repeated string,
|
|
56
|
+
* and every caller that then looked a plan up by it got whichever row came first. The two questions are
|
|
57
|
+
* now separate functions, because the callers genuinely want different things: identity here, and a
|
|
58
|
+
* human-facing page list from `memberPhysicalSheets`.
|
|
59
|
+
*/
|
|
60
|
+
export function memberViewIds(model, memberId) {
|
|
48
61
|
const member = (model.members || []).find((m) => m?.id === memberId);
|
|
49
62
|
if (!member) return [];
|
|
50
|
-
return (model.plans || []).filter((p) => memberPresence(model, p, member).visible).map(
|
|
63
|
+
return (model.plans || []).filter((p) => memberPresence(model, p, member).visible).map(planViewId);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* The PAGES this member appears on — deduplicated, for display only.
|
|
68
|
+
*
|
|
69
|
+
* Never an identity: two views on one page yield one page name, which is exactly right for "also shown
|
|
70
|
+
* on S5.1" and exactly wrong for looking a row up.
|
|
71
|
+
*/
|
|
72
|
+
export function memberPhysicalSheets(model, memberId) {
|
|
73
|
+
const member = (model.members || []).find((m) => m?.id === memberId);
|
|
74
|
+
if (!member) return [];
|
|
75
|
+
return [...new Set((model.plans || [])
|
|
76
|
+
.filter((p) => memberPresence(model, p, member).visible)
|
|
77
|
+
.map((p) => (p && typeof p.sheet === 'string' ? p.sheet : ''))
|
|
78
|
+
.filter(Boolean))];
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Why this plan cannot be mapped into display pixels, or null when it can. THE one classifier: the
|
|
83
|
+
* editor imports it for its whole-model scan and its canvas banner, so what the pill counts and what the
|
|
84
|
+
* banner says can never disagree with what the projection actually did.
|
|
85
|
+
*
|
|
86
|
+
* `registered: false` separates the two states the editor must NOT conflate: a sheet still being
|
|
87
|
+
* authored (no controls yet, a view kind 2D cannot map, no grid) has nothing WRONG with it, while a
|
|
88
|
+
* sheet that states a registration which does not hold is a fault someone has to correct. Both leave
|
|
89
|
+
* the projection empty; only the second is a warning.
|
|
90
|
+
*
|
|
91
|
+
* @param {any} plan
|
|
92
|
+
* @param {string} [subject] How to NAME this view in the refusal message. Without it the message
|
|
93
|
+
says the physical page, so two views on one page produce identical text and the banner that
|
|
94
|
+
renders it cannot say which one is at fault (#938). The caller supplies it because the rule is a
|
|
95
|
+
sibling count and this function is handed one row.
|
|
96
|
+
* @returns {{code: string, message: string, registered: boolean} | null}
|
|
97
|
+
*/
|
|
98
|
+
export function registrationRefusal(plan, subject) {
|
|
99
|
+
try { planTransform(plan, subject); return null; } catch (err) {
|
|
100
|
+
/*
|
|
101
|
+
* ONLY a real refusal degrades. `planTransform` is ordinary code and can fail for ordinary reasons —
|
|
102
|
+
* a TypeError, a future regression — and catching those into `registration-invalid` would blame the
|
|
103
|
+
* user's document for a bug in ours, then hide it behind a plausible-looking notice. That is the
|
|
104
|
+
* same substitution this whole change exists to end, so anything that is not a PlanTransformError
|
|
105
|
+
* carrying a code goes back up the stack untouched.
|
|
106
|
+
*/
|
|
107
|
+
if (!(err instanceof PlanTransformError) || !err.code) throw err;
|
|
108
|
+
const code = String(err.code);
|
|
109
|
+
return { code, message: String(err.message || code), registered: !isUnstarted(plan, code) };
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* Is this refusal "nothing has been stated yet", as opposed to "something is stated and does not hold"?
|
|
115
|
+
*
|
|
116
|
+
* The CODE alone cannot answer it, and reading it as if it could was wrong in a way that mattered: two
|
|
117
|
+
* of these codes cover both states at once. `grid-unavailable` is raised both when there is no model
|
|
118
|
+
* grid (unfinished) and when a grid exists but its `origin` cannot be read (malformed); `scale-invalid`
|
|
119
|
+
* both when `pt_per_ft` was never written (unfinished) and when it is present but zero or negative
|
|
120
|
+
* (malformed). Treating the whole code as unfinished told an author that "nothing is wrong, the sheet
|
|
121
|
+
* just needs its two registration points" about a sheet whose controls were already complete and whose
|
|
122
|
+
* grid was broken — a reassuring sentence that was not true, which is the exact defect class #935 is
|
|
123
|
+
* about. So look at whether the thing the refusal names is ABSENT or merely unusable.
|
|
124
|
+
*
|
|
125
|
+
* @param {any} plan @param {string} code
|
|
126
|
+
*/
|
|
127
|
+
function isUnstarted(plan, code) {
|
|
128
|
+
if (code === 'registration-incomplete') return true;
|
|
129
|
+
const grid = plan.modelGrid || plan.grid || null;
|
|
130
|
+
if (code === 'grid-unavailable') return !grid || typeof grid !== 'object';
|
|
131
|
+
if (code === 'scale-invalid') return plan.pt_per_ft == null;
|
|
132
|
+
return false;
|
|
51
133
|
}
|
|
52
134
|
|
|
135
|
+
/**
|
|
136
|
+
* The refusal codes that CAN mean "not registered yet" — the candidates `isUnstarted` then decides
|
|
137
|
+
* between, since two of them also cover a malformed state. Imported by steel-editor.html, which
|
|
138
|
+
* classifies the same throw for the column-footprint fallback, so the two cannot drift apart.
|
|
139
|
+
*/
|
|
140
|
+
export const UNREGISTERED_CODES = ['registration-incomplete', 'view-kind-unsupported', 'scale-invalid', 'grid-unavailable'];
|
|
141
|
+
|
|
53
142
|
function projectGrid(modelGrid, plan) {
|
|
54
143
|
if (!modelGrid) return null;
|
|
55
144
|
const out = clone(modelGrid);
|
|
@@ -67,10 +156,23 @@ function projectGrid(modelGrid, plan) {
|
|
|
67
156
|
return out;
|
|
68
157
|
}
|
|
69
158
|
|
|
70
|
-
/**
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
159
|
+
/**
|
|
160
|
+
* The registration-INDEPENDENT half of a projected member row — everything a consumer can know about a
|
|
161
|
+
* member WITHOUT a sheet to draw it on: its mark, profile, material, member type, placement, elevations,
|
|
162
|
+
* end notes/details and connection references.
|
|
163
|
+
*
|
|
164
|
+
* THE CANONICAL READ PATH (#942). A refused sheet projects empty, because every projected COORDINATE
|
|
165
|
+
* derives from a registration that does not hold. But the properties above derive from the canonical
|
|
166
|
+
* member alone — `from.z`/`to.z` in world mm, and plain metadata — so a model-wide consumer that needs a
|
|
167
|
+
* member's properties and not its plan pixels has no reason to be blocked by a refusal. Such a consumer
|
|
168
|
+
* reads THIS, and never gets a `wp` it could accidentally do coordinate maths with: the key is absent, not
|
|
169
|
+
* null, so a consumer that reaches for one fails loudly instead of quietly computing NaN.
|
|
170
|
+
*
|
|
171
|
+
* `projectMember` composes it with the two mapped points, which is what keeps the two from ever drifting:
|
|
172
|
+
* there is one definition of what a member's properties are, and the projected row is that definition plus
|
|
173
|
+
* a position.
|
|
174
|
+
*/
|
|
175
|
+
export function memberProperties(member) {
|
|
74
176
|
const meta = {
|
|
75
177
|
id: member.id,
|
|
76
178
|
profile: member.profile,
|
|
@@ -86,9 +188,8 @@ export function projectMember(member, plan, session = null) {
|
|
|
86
188
|
tos: knownIn(i === 0 ? member.from.z : member.to.z),
|
|
87
189
|
tosDef: false,
|
|
88
190
|
}));
|
|
89
|
-
|
|
191
|
+
return {
|
|
90
192
|
...meta,
|
|
91
|
-
wp: [a, b],
|
|
92
193
|
ends,
|
|
93
194
|
col: {
|
|
94
195
|
bos: knownIn(member.from.z),
|
|
@@ -100,7 +201,20 @@ export function projectMember(member, plan, session = null) {
|
|
|
100
201
|
connVerified: endMeta[1]?.connVerified,
|
|
101
202
|
},
|
|
102
203
|
};
|
|
103
|
-
|
|
204
|
+
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
/** One canonical member mapped into the display-space vocabulary the 2D canvas consumes. */
|
|
208
|
+
export function projectMember(member, plan, session = null) {
|
|
209
|
+
const a = worldToSheetPx(member.from, plan);
|
|
210
|
+
const b = worldToSheetPx(member.to, plan);
|
|
211
|
+
// Destructured so the emitted key ORDER is byte-identical to what this function built inline before the
|
|
212
|
+
// properties were extracted (meta keys, then wp, then ends, then col).
|
|
213
|
+
const { ends, col, ...meta } = memberProperties(member);
|
|
214
|
+
const projected = { ...meta, wp: [a, b], ends, col };
|
|
215
|
+
// `viewId` is the identity every command resolves its row by; `sheet` rides along for display only
|
|
216
|
+
// and must never be used as a lookup key (#938).
|
|
217
|
+
const base = { session, kind: 'member', memberId: member.id, viewId: planViewId(plan), sheet: plan.sheet };
|
|
104
218
|
link(projected, base);
|
|
105
219
|
link(projected.ends[0], { ...base, kind: 'end', end: 0 });
|
|
106
220
|
link(projected.ends[1], { ...base, kind: 'end', end: 1 });
|
|
@@ -109,11 +223,14 @@ export function projectMember(member, plan, session = null) {
|
|
|
109
223
|
return projected;
|
|
110
224
|
}
|
|
111
225
|
|
|
112
|
-
/** @param {any} model @param {string}
|
|
113
|
-
export function createV2Projection(model,
|
|
226
|
+
/** @param {any} model @param {string} viewId @param {{session?: any}} options */
|
|
227
|
+
export function createV2Projection(model, viewId, options = {}) {
|
|
114
228
|
const { session = null } = options;
|
|
115
|
-
|
|
116
|
-
|
|
229
|
+
// BY VIEW ID (#938). This used to take the first row with a matching `sheet`, which silently picked
|
|
230
|
+
// one of five elevations on a shared page — and every coordinate this projection derives comes from
|
|
231
|
+
// that row's registration, so "one of five" is five different wrong pictures.
|
|
232
|
+
const plan = (model.plans || []).find((p) => planViewId(p) === viewId);
|
|
233
|
+
if (!plan) throw new Error(`steel.model/v2 has no drawing view "${viewId}"`);
|
|
117
234
|
const projection = {
|
|
118
235
|
...clone(plan),
|
|
119
236
|
modelGrid: clone(model.grid || null),
|
|
@@ -122,14 +239,52 @@ export function createV2Projection(model, sheet, options = {}) {
|
|
|
122
239
|
if (!Array.isArray(projection[key])) projection[key] = [];
|
|
123
240
|
}
|
|
124
241
|
projection.default_tos = Number.isFinite(plan.elevation_in) ? plan.elevation_in : 0;
|
|
125
|
-
|
|
126
|
-
|
|
242
|
+
/*
|
|
243
|
+
* The registration is classified ONCE, here, before anything maps a point through it — and a refusal
|
|
244
|
+
* degrades this projection rather than throwing out of it.
|
|
245
|
+
*
|
|
246
|
+
* It used to throw, from deep inside `projectGrid`/`projectMember`, straight through `setPlan` and out
|
|
247
|
+
* of the editor's `boot()`. That was survivable only while `planTransform` refused nothing a real
|
|
248
|
+
* reader produces. #935 added the span invariant, which a real reader DOES trip — so the contract that
|
|
249
|
+
* issue was filed about would have opened to a dead page instead of a wrong one. Trading a silently
|
|
250
|
+
* wrong model for a blank screen with no explanation is not a fix.
|
|
251
|
+
*
|
|
252
|
+
* So: a refused sheet projects EMPTY — no grid, no members — and says why in `registrationRefusal`.
|
|
253
|
+
* Empty is the honest answer. Every projected coordinate is derived from the registration, so a sheet
|
|
254
|
+
* whose registration does not hold has no display position for anything on it; drawing the members
|
|
255
|
+
* anyway, at some invented fallback scale, is exactly the plausible-picture-over-a-real-refusal this
|
|
256
|
+
* whole change exists to end. The editor renders the refusal instead (see #regBanner).
|
|
257
|
+
*/
|
|
258
|
+
const refusal = registrationRefusal(projection);
|
|
259
|
+
/*
|
|
260
|
+
* ONE refusal is fatal here rather than a state to render, because it is not a registration state at
|
|
261
|
+
* all: `view-kind-unsupported` says this sheet is not a plan. Every caller reaches this function having
|
|
262
|
+
* already decided it is one, so it reports a confused caller or a malformed document rather than
|
|
263
|
+
* anything a user can correct — and a native v2 document with no `viewKind` MUST keep refusing to open
|
|
264
|
+
* rather than being drawn as an empty plan, a MUST-MATCH guarantee (steel-editor-v2-must-match.test.ts)
|
|
265
|
+
* raised precisely so an unclassified sheet is never quietly reclassified. It is thrown HERE and not
|
|
266
|
+
* inside the classifier, so the editor's whole-model scan can classify every plan without exploding on
|
|
267
|
+
* one it is only counting.
|
|
268
|
+
*/
|
|
269
|
+
if (refusal && refusal.code === 'view-kind-unsupported') {
|
|
270
|
+
throw Object.assign(new Error(refusal.message), { code: refusal.code });
|
|
271
|
+
}
|
|
272
|
+
if (refusal) projection.registrationRefusal = refusal;
|
|
273
|
+
projection.grid = refusal ? null : projectGrid(model.grid || null, projection);
|
|
274
|
+
const visible = refusal ? [] : (model.members || []).filter((m) => memberPresence(model, plan, m).visible);
|
|
127
275
|
projection.members = visible.map((m) => projectMember(m, projection, session));
|
|
128
|
-
|
|
276
|
+
// Dimensions go with them. A `dim` is anchored to a member point or a grid axis (`aRef`/`bRef`), so on
|
|
277
|
+
// a refused sheet it measures between two things that are no longer there — and it draws in raw sheet
|
|
278
|
+
// pixels, so it draws ANYWAY, leaving one confident-looking annotation floating over an empty plan.
|
|
279
|
+
// The sheet's own display-space content (segments, labels, callouts) is untouched: that is the drawing
|
|
280
|
+
// itself, and it is well defined with or without a registration.
|
|
281
|
+
if (refusal) projection.dims = [];
|
|
282
|
+
// `viewId` is the identity commands resolve back to a row; `sheet` rides along for display (#938).
|
|
283
|
+
link(projection, { session, kind: 'plan', viewId, sheet: plan.sheet });
|
|
129
284
|
if (projection.grid) {
|
|
130
|
-
link(projection.grid, { session, kind: 'grid', sheet });
|
|
285
|
+
link(projection.grid, { session, kind: 'grid', viewId, sheet: plan.sheet });
|
|
131
286
|
for (const line of projection.grid.lines || []) link(line, {
|
|
132
|
-
session, kind: 'grid-line', sheet, gridLineId: line.id,
|
|
287
|
+
session, kind: 'grid-line', viewId, sheet: plan.sheet, gridLineId: line.id,
|
|
133
288
|
});
|
|
134
289
|
}
|
|
135
290
|
|
|
@@ -137,7 +292,9 @@ export function createV2Projection(model, sheet, options = {}) {
|
|
|
137
292
|
let patchCount = 0;
|
|
138
293
|
const controller = {
|
|
139
294
|
model,
|
|
140
|
-
sheet
|
|
295
|
+
/** The row this controller drives. `sheet` is retained for display and is NOT an identity (#938). */
|
|
296
|
+
viewId,
|
|
297
|
+
sheet: plan.sheet,
|
|
141
298
|
plan: projection,
|
|
142
299
|
get rebuildCount() { return rebuildCount; },
|
|
143
300
|
get patchCount() { return patchCount; },
|
|
@@ -154,10 +311,10 @@ export function createV2Projection(model, sheet, options = {}) {
|
|
|
154
311
|
return projection;
|
|
155
312
|
},
|
|
156
313
|
rebuild() {
|
|
157
|
-
const fresh = createV2Projection(model,
|
|
314
|
+
const fresh = createV2Projection(model, viewId, { session });
|
|
158
315
|
for (const key of Object.keys(projection)) delete projection[key];
|
|
159
316
|
Object.assign(projection, fresh.plan);
|
|
160
|
-
link(projection, { session, kind: 'plan', sheet });
|
|
317
|
+
link(projection, { session, kind: 'plan', viewId, sheet: plan.sheet });
|
|
161
318
|
rebuildCount += 1;
|
|
162
319
|
return projection;
|
|
163
320
|
},
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
* control to a world point. Nothing here infers a view kind or substitutes missing registration data.
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
import { parseSpacings,
|
|
9
|
+
import { parseSpacings, mmPerPx } from './grid-core.js';
|
|
10
10
|
|
|
11
11
|
const ROUND = 1e9;
|
|
12
12
|
const clean = (n) => {
|
|
@@ -14,6 +14,15 @@ const clean = (n) => {
|
|
|
14
14
|
return Object.is(q, -0) ? 0 : q;
|
|
15
15
|
};
|
|
16
16
|
const finite2 = (p) => Array.isArray(p) && p.length === 2 && p.every(Number.isFinite);
|
|
17
|
+
const round2 = (n) => Math.round(n * 100) / 100;
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* How far the drawn control span may differ from the span its grid intersections imply, in POINTS of
|
|
21
|
+
* drawn distance. The takeoff skill has always told the reader to check exactly this by hand ("verify
|
|
22
|
+
* that their display span differs by at most 2 pt from `worldSpanMm * pt_per_ft / 304.8`"); #935 is
|
|
23
|
+
* what happens when only the prose enforces it.
|
|
24
|
+
*/
|
|
25
|
+
export const REGISTRATION_SPAN_TOLERANCE_PT = 2;
|
|
17
26
|
|
|
18
27
|
export class PlanTransformError extends Error {
|
|
19
28
|
constructor(code, message, viewKind = null) {
|
|
@@ -24,6 +33,20 @@ export class PlanTransformError extends Error {
|
|
|
24
33
|
}
|
|
25
34
|
}
|
|
26
35
|
|
|
36
|
+
/**
|
|
37
|
+
* How a registration refusal NAMES the view it is about.
|
|
38
|
+
*
|
|
39
|
+
* Defaults to `sheet "S5.1"`, which is exactly what every one of these messages said before #938, so
|
|
40
|
+
* no existing refusal churns. A caller that KNOWS the page carries more than one view passes the
|
|
41
|
+
* disambiguated label instead — the module cannot work that out for itself, because the rule is a
|
|
42
|
+
* sibling count and a transform is handed one row.
|
|
43
|
+
*
|
|
44
|
+
* Without this, two elevations on one page produced character-identical refusals and an author could
|
|
45
|
+
* not tell which of them to go and fix. (Found by review — the fifth surface in this change where a
|
|
46
|
+
* view was named locally rather than by `planViewLabels`.)
|
|
47
|
+
*/
|
|
48
|
+
const subjectOf = (plan, subject) => subject || `sheet "${quote(plan && plan.sheet)}"`;
|
|
49
|
+
|
|
27
50
|
const refuse = (code, message, plan) => {
|
|
28
51
|
throw new PlanTransformError(code, message, plan && plan.viewKind);
|
|
29
52
|
};
|
|
@@ -66,12 +89,20 @@ export const clipQuoted = (value, max = MAX_QUOTED_CHARS) => {
|
|
|
66
89
|
const quote = (value) => clipQuoted(value);
|
|
67
90
|
|
|
68
91
|
/**
|
|
69
|
-
* Resolve one
|
|
70
|
-
*
|
|
92
|
+
* Resolve one model-grid intersection from a pair of AXIS IDS.
|
|
93
|
+
*
|
|
94
|
+
* It resolved LABELS until #935, and that was a silent-metres-wrong bug: `axisLabelsFor` falls back to
|
|
95
|
+
* a positional auto-name (`1,2,3…` across X, `A,B,C…` up Y) for any axis carrying no label of its own,
|
|
96
|
+
* so a contract that identified its gridlines only by `id` still resolved `1`/`C` — against the FIRST
|
|
97
|
+
* and THIRD authored axes. Both refs resolved uniquely, nothing complained, and a 250-member model
|
|
98
|
+
* landed a median of 18 m from where it belonged. An id is the field the schema already calls identity;
|
|
99
|
+
* a label is editable display text and stays out of this.
|
|
100
|
+
*
|
|
101
|
+
* A duplicate id is still ambiguous and still refuses rather than quietly taking the first match.
|
|
71
102
|
*/
|
|
72
|
-
function gridIntersection(grid, ref, plan, field) {
|
|
103
|
+
function gridIntersection(grid, ref, plan, field, subject) {
|
|
73
104
|
if (!grid || typeof grid !== 'object') {
|
|
74
|
-
return refuse('grid-unavailable',
|
|
105
|
+
return refuse('grid-unavailable', `${subjectOf(plan, subject)} has no model grid to resolve its registration controls`, plan);
|
|
75
106
|
}
|
|
76
107
|
// A grid that carries axes, spacings and labels but no `origin` used to share the message above, and
|
|
77
108
|
// it sent authors back to the half they had already filled in (#925). `$.grid.origin` is optional in
|
|
@@ -80,31 +111,35 @@ function gridIntersection(grid, ref, plan, field) {
|
|
|
80
111
|
if (!finite2(grid.origin)) {
|
|
81
112
|
return refuse(
|
|
82
113
|
'grid-unavailable',
|
|
83
|
-
|
|
114
|
+
`${subjectOf(plan, subject)} cannot resolve its registration controls: $.grid.origin is missing or unreadable — it must be two finite world-mm numbers giving where the first x and y grid axes cross`,
|
|
84
115
|
plan,
|
|
85
116
|
);
|
|
86
117
|
}
|
|
87
|
-
if (!ref || typeof ref !== 'object' || typeof ref.
|
|
88
|
-
return refuse('control-ref-invalid',
|
|
118
|
+
if (!ref || typeof ref !== 'object' || typeof ref.xAxisId !== 'string' || typeof ref.yAxisId !== 'string') {
|
|
119
|
+
return refuse('control-ref-invalid', `${subjectOf(plan, subject)} has an unreadable ${field}: a registration control needs string xAxisId and yAxisId grid axis ids`, plan);
|
|
89
120
|
}
|
|
90
121
|
|
|
91
122
|
const X = parseSpacings(grid.x), Y = parseSpacings(grid.y);
|
|
92
123
|
if (X.err || Y.err) {
|
|
93
124
|
const bad = X.err ? '$.grid.x' : '$.grid.y';
|
|
94
|
-
return refuse('grid-spacing-invalid',
|
|
125
|
+
return refuse('grid-spacing-invalid', `${subjectOf(plan, subject)} cannot use ${bad}: ${quote(X.err || Y.err)}`, plan);
|
|
95
126
|
}
|
|
96
|
-
//
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
const
|
|
100
|
-
|
|
127
|
+
// Authored order per direction, which is the order `parseSpacings` produces offsets in — the axis at
|
|
128
|
+
// slot i owns offset i. A direction whose axis rows and offsets disagree in count is not describable,
|
|
129
|
+
// so no id in it resolves; `checkModelReferences` (`grid-axis-count`) refuses such a document upstream.
|
|
130
|
+
const idsFor = (dir) => (Array.isArray(grid.axes) ? grid.axes.filter((a) => a && a.dir === dir) : [])
|
|
131
|
+
.map((a) => typeof a.id === 'string' ? a.id : null);
|
|
132
|
+
const xs = idsFor('x'), ys = idsFor('y');
|
|
133
|
+
const uniqueIndex = (ids, wanted, count) => {
|
|
134
|
+
if (ids.length !== count) return -1;
|
|
135
|
+
const hits = ids.map((id, i) => id === wanted ? i : -1).filter((i) => i >= 0);
|
|
101
136
|
return hits.length === 1 ? hits[0] : -1;
|
|
102
137
|
};
|
|
103
|
-
const xi = uniqueIndex(xs, ref.
|
|
138
|
+
const xi = uniqueIndex(xs, ref.xAxisId, X.offsets.length), yi = uniqueIndex(ys, ref.yAxisId, Y.offsets.length);
|
|
104
139
|
if (xi < 0 || yi < 0) {
|
|
105
140
|
return refuse(
|
|
106
141
|
'control-ref-unresolved',
|
|
107
|
-
|
|
142
|
+
`${subjectOf(plan, subject)} ${field} names ${quote(ref.xAxisId)}/${quote(ref.yAxisId)}, which is not exactly one x and one y axis id on the model grid`,
|
|
108
143
|
plan,
|
|
109
144
|
);
|
|
110
145
|
}
|
|
@@ -117,33 +152,33 @@ function gridIntersection(grid, ref, plan, field) {
|
|
|
117
152
|
* `plan.grid` is the model grid exposed through the projection (canonical ModelPlan intentionally has
|
|
118
153
|
* no grid property). `datum_ref` may be absent only for the explicit "datum_at is world origin" case.
|
|
119
154
|
*/
|
|
120
|
-
export function planTransform(plan) {
|
|
155
|
+
export function planTransform(plan, subject) {
|
|
121
156
|
const kind = plan && plan.viewKind;
|
|
122
157
|
if (kind !== 'plan') {
|
|
123
158
|
const named = typeof kind === 'string' && kind ? quote(kind) : 'unknown';
|
|
124
159
|
return refuse(
|
|
125
160
|
'view-kind-unsupported',
|
|
126
|
-
|
|
161
|
+
`${subjectOf(plan, subject)} is a ${named} view; ${named} views are not supported by the plan transform`,
|
|
127
162
|
plan,
|
|
128
163
|
);
|
|
129
164
|
}
|
|
130
165
|
if (!finite2(plan.datum_at) || !finite2(plan.control2_at) || !plan.control2_ref) {
|
|
131
166
|
return refuse(
|
|
132
167
|
'registration-incomplete',
|
|
133
|
-
|
|
168
|
+
`${subjectOf(plan, subject)} needs $.datum_at, $.control2_at and $.control2_ref before it can be edited`,
|
|
134
169
|
plan,
|
|
135
170
|
);
|
|
136
171
|
}
|
|
137
172
|
const ptPerFt = Number(plan.pt_per_ft);
|
|
138
173
|
if (!(ptPerFt > 0) || !Number.isFinite(ptPerFt)) {
|
|
139
|
-
return refuse('scale-invalid',
|
|
174
|
+
return refuse('scale-invalid', `${subjectOf(plan, subject)} has no positive $.pt_per_ft, so it has no drawing scale`, plan);
|
|
140
175
|
}
|
|
141
176
|
|
|
142
177
|
// Editor projections expose a display-space `grid` because grid-core draws in pixels. The canonical
|
|
143
178
|
// world grid rides beside it as `modelGrid`; standalone callers and stored-plan fixtures use `grid`.
|
|
144
179
|
const registrationGrid = plan.modelGrid || plan.grid;
|
|
145
|
-
const world0 = plan.datum_ref ? gridIntersection(registrationGrid, plan.datum_ref, plan, '$.datum_ref') : [0, 0];
|
|
146
|
-
const world1 = gridIntersection(registrationGrid, plan.control2_ref, plan, '$.control2_ref');
|
|
180
|
+
const world0 = plan.datum_ref ? gridIntersection(registrationGrid, plan.datum_ref, plan, '$.datum_ref', subject) : [0, 0];
|
|
181
|
+
const world1 = gridIntersection(registrationGrid, plan.control2_ref, plan, '$.control2_ref', subject);
|
|
147
182
|
// The shared plan scale. Its zero/negative fallback is unreachable here — the guard above already
|
|
148
183
|
// refused any sheet whose `pt_per_ft` is not a positive finite number — so this is the same value
|
|
149
184
|
// the inline `FT_MM / ptPerFt` produced, from the one implementation.
|
|
@@ -159,31 +194,49 @@ export function planTransform(plan) {
|
|
|
159
194
|
// refs are fine, or the refs can resolve to one intersection while the display points differ. Naming
|
|
160
195
|
// the wrong pair sends the author to fields that are already correct (#925's own failure mode).
|
|
161
196
|
if (!(localLen > 1e-9)) {
|
|
162
|
-
return refuse('registration-degenerate',
|
|
197
|
+
return refuse('registration-degenerate', `${subjectOf(plan, subject)} has coincident registration controls: $.datum_at and $.control2_at are the same point on the sheet`, plan);
|
|
163
198
|
}
|
|
164
199
|
if (!(worldLen > 1e-9)) {
|
|
165
200
|
// `datum_ref` is ABSENT for the "datum_at is the model origin" case, and naming a field that is
|
|
166
201
|
// not there is the same wrong-half misdirection this refusal exists to avoid.
|
|
167
202
|
const datum = plan.datum_ref ? '$.datum_ref and $.control2_ref resolve to the same grid intersection'
|
|
168
203
|
: '$.control2_ref resolves to the model origin, which is where an absent $.datum_ref already puts the datum';
|
|
169
|
-
return refuse('registration-degenerate',
|
|
204
|
+
return refuse('registration-degenerate', `${subjectOf(plan, subject)} has coincident registration controls: ${datum}`, plan);
|
|
205
|
+
}
|
|
206
|
+
// THE SPAN INVARIANT. `fitScale` corrects a sub-point pick error; it is not evidence the registration
|
|
207
|
+
// is right, and a RATIO band cannot be made into that evidence. On a 14-axis grid there are 13 bays,
|
|
208
|
+
// so resolving a control one bay out moves the run by ~7.7% — inside any band loose enough for real
|
|
209
|
+
// drawings, and #935's own defect would have passed it. Meanwhile a short but perfectly good
|
|
210
|
+
// registration can be several percent off from one pixel of pick error. So compare an ABSOLUTE
|
|
211
|
+
// distance, in the units the drawing is in: the drawn span between the two controls against the span
|
|
212
|
+
// their grid intersections imply, within 2 pt. That is the check the takeoff skill already tells the
|
|
213
|
+
// reader to do by hand — it was simply never enforced, so a whole-bay misresolution sailed through
|
|
214
|
+
// and put a 250-member model a median of 18 m out with no error at any layer.
|
|
215
|
+
const actualSpanPt = localLen / scale;
|
|
216
|
+
const expectedSpanPt = worldLen / scale;
|
|
217
|
+
if (Math.abs(actualSpanPt - expectedSpanPt) > REGISTRATION_SPAN_TOLERANCE_PT) {
|
|
218
|
+
return refuse(
|
|
219
|
+
'registration-span-mismatch',
|
|
220
|
+
`${subjectOf(plan, subject)} registration controls span ${round2(actualSpanPt)} pt on the sheet, but ${plan.datum_ref ? '$.datum_ref' : 'the model origin'} and $.control2_ref are ${round2(worldLen)} mm apart, which at ${plan.pt_per_ft} pt/ft is ${round2(expectedSpanPt)} pt — a difference of ${round2(Math.abs(actualSpanPt - expectedSpanPt))} pt, past the ${REGISTRATION_SPAN_TOLERANCE_PT} pt allowed. Either a control names the wrong grid axis or $.pt_per_ft is wrong`,
|
|
221
|
+
plan,
|
|
222
|
+
);
|
|
170
223
|
}
|
|
171
224
|
const fitScale = worldLen / localLen;
|
|
172
225
|
const rotation = Math.atan2(worldDelta[1], worldDelta[0]) - Math.atan2(local1[1], local1[0]);
|
|
173
226
|
const c = Math.cos(rotation) * fitScale;
|
|
174
227
|
const s = Math.sin(rotation) * fitScale;
|
|
175
228
|
if (![c, s, fitScale, world0[0], world0[1]].every(Number.isFinite)) {
|
|
176
|
-
return refuse('registration-invalid',
|
|
229
|
+
return refuse('registration-invalid', `${subjectOf(plan, subject)} has a non-finite registration transform`, plan);
|
|
177
230
|
}
|
|
178
231
|
return { datumPx: plan.datum_at, world0, mmPerPx: scale, fitScale, rotation, c, s };
|
|
179
232
|
}
|
|
180
233
|
|
|
181
234
|
/** Canonical world-mm work point → this plan's display px. */
|
|
182
|
-
export function worldToSheetPx(workPoint, plan) {
|
|
235
|
+
export function worldToSheetPx(workPoint, plan, subject) {
|
|
183
236
|
if (!workPoint || !Number.isFinite(workPoint.x) || !Number.isFinite(workPoint.y)) {
|
|
184
237
|
return refuse('work-point-invalid', 'a work point needs finite world x/y coordinates', plan);
|
|
185
238
|
}
|
|
186
|
-
const t = planTransform(plan);
|
|
239
|
+
const t = planTransform(plan, subject);
|
|
187
240
|
const wx = workPoint.x - t.world0[0], wy = workPoint.y - t.world0[1];
|
|
188
241
|
const det = t.c * t.c + t.s * t.s;
|
|
189
242
|
const localX = (t.c * wx + t.s * wy) / det;
|
|
@@ -195,9 +248,9 @@ export function worldToSheetPx(workPoint, plan) {
|
|
|
195
248
|
}
|
|
196
249
|
|
|
197
250
|
/** This plan's display px → canonical world-mm work point, retaining the endpoint's elevation union. */
|
|
198
|
-
export function sheetPxToWorld(point, plan, keepZ) {
|
|
251
|
+
export function sheetPxToWorld(point, plan, keepZ, subject) {
|
|
199
252
|
if (!finite2(point)) return refuse('sheet-point-invalid', 'a sheet point needs two finite pixel coordinates', plan);
|
|
200
|
-
const t = planTransform(plan);
|
|
253
|
+
const t = planTransform(plan, subject);
|
|
201
254
|
const localX = (point[0] - t.datumPx[0]) * t.mmPerPx;
|
|
202
255
|
const localY = (t.datumPx[1] - point[1]) * t.mmPerPx;
|
|
203
256
|
return {
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A `plans[]` row is ONE DRAWING VIEW. Its identity is `id`; its `sheet` is the physical page (#938).
|
|
3
|
+
*
|
|
4
|
+
* Those were the same string until #938, and the conflation had a consequence: five braced-frame
|
|
5
|
+
* elevations on one sheet — ordinary practice — had no legal representation at all. `sheet` was unique
|
|
6
|
+
* across rows, one row carries one `sourceRegistration`, one `viewKind` and one `pt_per_ft`, and an
|
|
7
|
+
* observation must live on the plan whose sheet its evidence cites. Nothing in that combination can say
|
|
8
|
+
* "five views, five frames, one page".
|
|
9
|
+
*
|
|
10
|
+
* SO THE TWO MEANINGS ARE SEPARATED, and the split is the whole change:
|
|
11
|
+
*
|
|
12
|
+
* PHYSICAL SHEET — the page. Not unique. Owns the raster, the Drawing Filter binding, the page
|
|
13
|
+
* previews, the detail bubbles, the callout targets, and `evidence.source.sheet` provenance.
|
|
14
|
+
*
|
|
15
|
+
* VIEW ID — the row. Model-global unique. Owns the registration, the drawing scale, the view kind,
|
|
16
|
+
* the endpoint analysis scope, the projection caches, the revision pairing and the editor selection.
|
|
17
|
+
*
|
|
18
|
+
* `id` IS OPTIONAL IN THE SCHEMA, and a row with no `id` means "my sheet name is my view id" — which
|
|
19
|
+
* is what every document written before #938 says. It stays optional because `checkModelReferences`
|
|
20
|
+
* is a READ gate as well as a write one (`readModelOrIssues` returns no view at all when it reports
|
|
21
|
+
* anything, and that backs approve/compile, BOM export, the 3D scene and the diff), so REQUIRING it
|
|
22
|
+
* would have stopped every stored project opening — including the very read that motivated #938.
|
|
23
|
+
*
|
|
24
|
+
* SO IT IS NORMALISED AT THE DOOR — `normalisePlanViewIds` (`server/steel-plan-view-id-normalise.ts`)
|
|
25
|
+
* materialises `id = sheet` on the way in and on the way out, exactly where `normaliseRollMarkers`
|
|
26
|
+
* runs and for exactly its reason. That is not politeness towards old files either: three places
|
|
27
|
+
* compare document BYTES rather than resolved identity — revision staging, the initial-read
|
|
28
|
+
* transaction's registration hash, and approval diffing — so leaving `{sheet:"S1"}` and
|
|
29
|
+
* `{sheet:"S1", id:"S1"}` as two encodings of one meaning would produce a spurious refusal, a
|
|
30
|
+
* `shell-changed`, or a phantom approval diff. Normalising BOTH sides removes the difference instead
|
|
31
|
+
* of teaching every comparison about it.
|
|
32
|
+
*
|
|
33
|
+
* THIS ACCESSOR IS STILL NEEDED, and is not a second mechanism. Two domains never see a normalised
|
|
34
|
+
* document: the BROWSER, which is served the stored bytes, and the deliberately-unvalidated input
|
|
35
|
+
* that `checkModelReferences` and revision staging accept. `planViewId` is what makes those total.
|
|
36
|
+
*/
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* This row's view identity. `id` when authored, else the sheet name.
|
|
40
|
+
*
|
|
41
|
+
* @param {{id?: unknown, sheet?: unknown} | null | undefined} plan
|
|
42
|
+
* @returns {string} the resolved view id, or `''` when the row states neither.
|
|
43
|
+
*/
|
|
44
|
+
export function planViewId(plan) {
|
|
45
|
+
const id = plan && typeof plan === 'object' ? plan.id : undefined;
|
|
46
|
+
if (typeof id === 'string' && id.trim() !== '') return id;
|
|
47
|
+
const sheet = plan && typeof plan === 'object' ? plan.sheet : undefined;
|
|
48
|
+
return typeof sheet === 'string' ? sheet : '';
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/** Did this row state its view id explicitly? Used where absence is the thing being judged. */
|
|
52
|
+
export function hasExplicitViewId(plan) {
|
|
53
|
+
const id = plan && typeof plan === 'object' ? plan.id : undefined;
|
|
54
|
+
return typeof id === 'string' && id.trim() !== '';
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* The RAW resolver, for the two places that read a document before anything has vouched for it:
|
|
59
|
+
* `checkModelReferences(doc: unknown)` and revision staging, both of which accept unvalidated input
|
|
60
|
+
* on purpose.
|
|
61
|
+
*
|
|
62
|
+
* It returns `null` rather than `''` when the row states neither a usable `id` nor a usable `sheet`,
|
|
63
|
+
* and that distinction is load-bearing: `''` is a value, so several malformed rows would COLLIDE
|
|
64
|
+
* with each other and report a duplicate-identity issue that describes nothing real, burying the
|
|
65
|
+
* actual fault (a missing sheet) under a fabricated one. `null` is never equal to anything, so a
|
|
66
|
+
* malformed row is diagnosed as itself.
|
|
67
|
+
*
|
|
68
|
+
* @param {unknown} plan @returns {string | null}
|
|
69
|
+
*/
|
|
70
|
+
export function rawPlanViewId(plan) {
|
|
71
|
+
if (!plan || typeof plan !== 'object' || Array.isArray(plan)) return null;
|
|
72
|
+
const row = /** @type {{id?: unknown, sheet?: unknown}} */ (plan);
|
|
73
|
+
if (row.id !== undefined) {
|
|
74
|
+
// A row that STATED an id, badly, has no identity — falling through to its sheet would invent one,
|
|
75
|
+
// and that invented identity then collides with a perfectly valid sibling and reports a duplicate
|
|
76
|
+
// against the row that is fine. `normalisePlanViewIds` leaves a present-but-invalid `id` alone for
|
|
77
|
+
// exactly this reason (so the schema can refuse it); this must agree with it. (Found by review.)
|
|
78
|
+
//
|
|
79
|
+
// `null` is one of those bad values, not an absence — it was exempted here in the first cut, which
|
|
80
|
+
// made this the one malformed id the pair disagreed about: the normaliser preserved it (so the row
|
|
81
|
+
// stayed refusable) while this resolver read straight past it to `sheet` and handed back an
|
|
82
|
+
// identity the row never stated. Only `undefined` means "states no id". (Found by review.)
|
|
83
|
+
return typeof row.id === 'string' && row.id.trim() !== '' ? row.id : null;
|
|
84
|
+
}
|
|
85
|
+
if (typeof row.sheet === 'string' && row.sheet.trim() !== '') return row.sheet;
|
|
86
|
+
return null;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* How to NAME each view to a human — never how to identify one. THE one rule: the server's refusal
|
|
91
|
+
* messages take it too (`member-end-centerline-report.ts`), so one view cannot be called two things.
|
|
92
|
+
*
|
|
93
|
+
* PLURAL, and it has to be: the label is the page name when that page carries ONE view and must
|
|
94
|
+
* disambiguate when it carries several, and no single-row function can know its siblings. (The first
|
|
95
|
+
* cut was `planViewLabel(plan)` and could not satisfy its own contract; review caught it.)
|
|
96
|
+
*
|
|
97
|
+
* A page with one view therefore reads exactly as it did before #938, which is why no existing
|
|
98
|
+
* label, toast or refusal message churns.
|
|
99
|
+
*
|
|
100
|
+
* @param {readonly unknown[] | null | undefined} plans
|
|
101
|
+
* @returns {Map<string, string>} resolved view id -> display label
|
|
102
|
+
*/
|
|
103
|
+
export function planViewLabels(plans) {
|
|
104
|
+
const rows = Array.isArray(plans) ? plans : [];
|
|
105
|
+
const perSheet = new Map();
|
|
106
|
+
for (const plan of rows) {
|
|
107
|
+
const sheet = plan && typeof plan === 'object' && typeof plan.sheet === 'string' ? plan.sheet : '';
|
|
108
|
+
perSheet.set(sheet, (perSheet.get(sheet) ?? 0) + 1);
|
|
109
|
+
}
|
|
110
|
+
const labels = new Map();
|
|
111
|
+
rows.forEach((plan, index) => {
|
|
112
|
+
const viewId = planViewId(plan);
|
|
113
|
+
const sheet = plan && typeof plan === 'object' && typeof plan.sheet === 'string' ? plan.sheet : '';
|
|
114
|
+
/*
|
|
115
|
+
* A row that names NEITHER a page nor a view resolves to `''`, and several such rows would then
|
|
116
|
+
* share one Map key — the last one written silently becoming every earlier one's label. Worse, the
|
|
117
|
+
* registration-refusal popover builds `data-command-id="steel.registration-select#<label>"` from
|
|
118
|
+
* this string, so two distinct refused views would render two buttons carrying the SAME command id.
|
|
119
|
+
* A document like that is refused by `plan-view-id-duplicate` before it can be stored, but a draft
|
|
120
|
+
* mid-edit and a harness both still render one. Keyed on its position so it stays distinct, under a
|
|
121
|
+
* sentinel no authored id can collide with; the TEXT is the positional fallback either way, so
|
|
122
|
+
* nothing about the ordinary case changes. (Found by UX review.)
|
|
123
|
+
*/
|
|
124
|
+
if (!sheet) { labels.set(viewId || `\u0000view${index}`, viewId || `view ${index + 1}`); return; }
|
|
125
|
+
/*
|
|
126
|
+
* ONE condition: does this PAGE carry more than one view. The first cut also required
|
|
127
|
+
* `viewId !== sheet`, which left a LEGAL mixed page — one row unnamed, its sibling named — showing
|
|
128
|
+
* the unnamed one as the bare page name beside a disambiguated sibling. The whole contract of this
|
|
129
|
+
* function is "disambiguate when the page carries several", so the sibling count is the only thing
|
|
130
|
+
* that may decide it. (Found by review.)
|
|
131
|
+
*
|
|
132
|
+
* A row on a shared page whose id IS the page name therefore reads `"S5.1 · S5.1"`. Redundant,
|
|
133
|
+
* and deliberately not special-cased: it is what that row is actually called, it stays
|
|
134
|
+
* distinguishable from its named sibling, and it looks as unfinished as it is — the reference
|
|
135
|
+
* guidance tells a reader to name every row on a page that carries several.
|
|
136
|
+
*/
|
|
137
|
+
labels.set(viewId, (perSheet.get(sheet) ?? 0) > 1 ? `${sheet} · ${viewId}` : sheet);
|
|
138
|
+
});
|
|
139
|
+
return labels;
|
|
140
|
+
}
|