@floless/app 0.144.0 → 0.146.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 +4010 -2888
- package/dist/skills/floless-app-steel-takeoff/SKILL.md +37 -4
- package/dist/web/app.css +35 -0
- package/dist/web/aware.js +72 -3
- package/dist/web/chat.css +17 -2
- package/dist/web/chat.js +21 -9
- package/dist/web/commands-revit.js +6 -0
- package/dist/web/commands-shell.js +11 -0
- package/dist/web/commands-tekla-parser.js +6 -0
- package/dist/web/filter-ai-context.js +8 -2
- package/dist/web/index.html +14 -3
- package/dist/web/left-pane.js +4 -1
- package/dist/web/model-chat-questions.js +178 -0
- package/dist/web/model-inspector.js +44 -19
- package/dist/web/model-measure.js +75 -18
- package/dist/web/model-pointer-dock.js +7 -2
- package/dist/web/model-snap-contract.js +14 -0
- package/dist/web/model-snapping.js +564 -139
- package/dist/web/model-viewport-revit-adapter.js +60 -0
- package/dist/web/revit-editor.css +19 -0
- package/dist/web/revit-editor.js +72 -3
- package/dist/web/steel-editor.html +16 -95
- package/dist/web/workspaces.js +37 -5
- package/package.json +1 -1
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* model-chat-questions.js - model objects in AI Chat (#1653), shared by every model viewer and the server.
|
|
3
|
+
*
|
|
4
|
+
* A question asked in the left AI Chat with objects selected is linked to them, and the chat model may link the
|
|
5
|
+
* objects its answer names. This module holds what every viewer must say the same way: how an object is named when it
|
|
6
|
+
* goes to chat, the key that tells one selection from another, and the "Questions in chat" card. The Steel Model and
|
|
7
|
+
* the snapshot viewer (Revit, Tekla Parser) all render the card from here, and the server names objects with the same
|
|
8
|
+
* function the viewer uses, so a label never differs between the pill, the card and the chat model's links. Each page
|
|
9
|
+
* styles the card with its own theme tokens; the words and the rows are only here.
|
|
10
|
+
*
|
|
11
|
+
* Pure: no page globals. DOM builders take the document they build in.
|
|
12
|
+
*/
|
|
13
|
+
import { teklaObjectFields, teklaObjectLabel } from './model-property-display.js';
|
|
14
|
+
|
|
15
|
+
/** A label exactly as the server stores it (server/chat-subjects.ts): control characters and runs of space
|
|
16
|
+
* collapsed, cut to 120 characters, trimmed. Sent this way and compared this way, so an unchanged long name never
|
|
17
|
+
* reads as renamed. */
|
|
18
|
+
export function subjectLabelText(text) {
|
|
19
|
+
return [...String(text || '').replace(/[\u0000-\u001f\u007f]+/g, ' ').replace(/\s+/g, ' ').trim()].slice(0, 120).join('').trimEnd();
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* An object of a snapshot model as AI Chat names it. Revit: what it is, then its id (`Basic Wall · element:382`) -
|
|
24
|
+
* many elements share a type and some rows carry none, so a name without the id reads as a duplicate. Tekla Parser:
|
|
25
|
+
* the name, profile and Tekla ID the viewer shows, with the entity id added when the read had no Tekla ID.
|
|
26
|
+
* `rows` are the entity's property rows (Tekla reads its name and profile from them).
|
|
27
|
+
*/
|
|
28
|
+
export function modelSubjectLabel(source, entity, rows = []) {
|
|
29
|
+
const id = String(entity?.id ?? '');
|
|
30
|
+
if (source === 'tekla-parser') {
|
|
31
|
+
const fields = teklaObjectFields(entity || {}, rows);
|
|
32
|
+
const label = teklaObjectLabel(entity || {}, rows);
|
|
33
|
+
return fields.id == null ? `${label} · ${id}` : label;
|
|
34
|
+
}
|
|
35
|
+
const what = entity?.name || entity?.typeName || entity?.categoryName || entity?.category || 'Revit element';
|
|
36
|
+
return `${what} · ${id}`;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/** 64-bit FNV-1a over the WHOLE canonical list, so a pill left out for one selection returns for another even when
|
|
40
|
+
* only objects past the 200 the pane receives changed. */
|
|
41
|
+
export function subjectsKeyOf(items) {
|
|
42
|
+
let h1 = 0x811c9dc5, h2 = 0x01000193;
|
|
43
|
+
for (const item of items) {
|
|
44
|
+
const text = `${item.kind}:${item.id}\n`;
|
|
45
|
+
for (let i = 0; i < text.length; i++) {
|
|
46
|
+
const c = text.charCodeAt(i);
|
|
47
|
+
h1 = Math.imul(h1 ^ c, 0x01000193) >>> 0; h2 = Math.imul(h2 ^ c, 0x811c9dc5) >>> 0;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
return h1.toString(16).padStart(8, '0') + h2.toString(16).padStart(8, '0');
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/* -- Questions in chat: the object card ---------------------------------------------------------------------------
|
|
54
|
+
Selecting an object shows how many questions were about it, the first line of each, and Show in chat, which opens
|
|
55
|
+
that conversation at that question. Nothing is re-attached by label: an object the model no longer has keeps its
|
|
56
|
+
questions under "Questions about objects not in the model", with the label it had when asked. A failed read says so
|
|
57
|
+
and offers Retry; it never claims there are no questions. */
|
|
58
|
+
|
|
59
|
+
/** Said when Show in chat cannot reach AI Chat for this project. */
|
|
60
|
+
export const CHAT_NOT_OPEN_COPY = 'AI Chat is not open for this project. Open the project in Workspaces, then choose Show in chat again.';
|
|
61
|
+
|
|
62
|
+
export function chatQuestionDate(iso) {
|
|
63
|
+
const date = new Date(iso);
|
|
64
|
+
return Number.isNaN(date.getTime()) ? '' : date.toLocaleDateString(undefined, { day: 'numeric', month: 'short', year: 'numeric' });
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* One row per question: the links of one message collapse into it, naming the objects it was about. A link is the
|
|
69
|
+
* person's selection, the chat model's note on it, or its answer naming the object. What a row says never depends on
|
|
70
|
+
* which link arrived first: every link of a question carries the same question line and time, the newest note wins,
|
|
71
|
+
* and "named in the answer" is a fact of the set. Newest question first.
|
|
72
|
+
*/
|
|
73
|
+
export function chatQuestionRows(links) {
|
|
74
|
+
const byMessage = new Map();
|
|
75
|
+
for (const link of links) {
|
|
76
|
+
let row = byMessage.get(link.messageEventId);
|
|
77
|
+
if (!row) { row = { link, labels: [], seen: new Set(), selected: false, named: false, aiNote: '', aiSeq: -1 }; byMessage.set(link.messageEventId, row); }
|
|
78
|
+
const key = `${link.kind}\0${link.id}`;
|
|
79
|
+
if (!row.seen.has(key)) { row.seen.add(key); row.labels.push(link.label || link.id); }
|
|
80
|
+
if (link.origin === 'ai-answer') row.named = true;
|
|
81
|
+
else if (link.origin === 'ai-note') { if (link.linkSequence > row.aiSeq) { row.aiSeq = link.linkSequence; row.aiNote = link.aiNote || ''; } }
|
|
82
|
+
else { if (!row.selected) row.link = link; row.selected = true; } // "When asked" reads the label from when the person asked
|
|
83
|
+
}
|
|
84
|
+
const askedAt = (row) => String(row.link.askedAt || row.link.createdAt);
|
|
85
|
+
return [...byMessage.values()].sort((a, b) => askedAt(b).localeCompare(askedAt(a)) || (b.link.sequence - a.link.sequence));
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/** The id is all a link knows of its object, and a reader may give a removed object's id to a new one. So a row whose
|
|
89
|
+
* object is named differently now says what it was called when asked, rather than quietly vouching for it.
|
|
90
|
+
* `currentLabel(link)` is the object's label now, '' when unknown. */
|
|
91
|
+
export function chatQuestionWas(row, currentLabel) {
|
|
92
|
+
const link = row.link; if (!link.label) return '';
|
|
93
|
+
const now = subjectLabelText(currentLabel(link));
|
|
94
|
+
return now && now !== subjectLabelText(link.label) ? link.label : '';
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
function chatQuestionRow(doc, row, opts) {
|
|
98
|
+
const { about, unresolved, commandPrefix, currentLabel, onShow, toast } = opts;
|
|
99
|
+
const link = row.link, li = doc.createElement('div'); li.className = 'chat-q';
|
|
100
|
+
const note = doc.createElement('div'); note.className = 'chat-q-note'; note.textContent = link.note; note.dataset.tip = link.note;
|
|
101
|
+
li.append(note);
|
|
102
|
+
// The chat model's own sentence, said to be its own: untrusted text, one line, textContent only.
|
|
103
|
+
if (row.aiNote) { const ai = doc.createElement('div'); ai.className = 'chat-q-ai'; ai.textContent = `AI note: ${row.aiNote}`; ai.dataset.tip = row.aiNote; li.append(ai); }
|
|
104
|
+
const meta = doc.createElement('div'); meta.className = 'chat-q-meta';
|
|
105
|
+
meta.textContent = [link.chatTitle, chatQuestionDate(link.askedAt || link.createdAt)].filter(Boolean).join(' · ') + (link.archived ? ' · archived' : '');
|
|
106
|
+
li.append(meta);
|
|
107
|
+
if (row.named) { const named = doc.createElement('div'); named.className = 'chat-q-about'; named.textContent = row.selected ? 'Also named in the answer' : 'Named in the answer'; li.append(named); }
|
|
108
|
+
if (about) {
|
|
109
|
+
const who = doc.createElement('div'); who.className = 'chat-q-about';
|
|
110
|
+
const names = row.labels.slice(0, 3);
|
|
111
|
+
who.textContent = (unresolved ? 'Was: ' : 'About ') + names.join(', ') + (row.labels.length > 3 ? ` and ${row.labels.length - 3} more` : '');
|
|
112
|
+
li.append(who);
|
|
113
|
+
} else {
|
|
114
|
+
const was = chatQuestionWas(row, currentLabel);
|
|
115
|
+
if (was) { const who = doc.createElement('div'); who.className = 'chat-q-about'; who.textContent = `When asked: ${was}`; li.append(who); }
|
|
116
|
+
}
|
|
117
|
+
const show = doc.createElement('button'); show.type = 'button'; show.className = 'ghost chat-q-show'; show.textContent = 'Show in chat';
|
|
118
|
+
show.dataset.commandId = `${commandPrefix}.chat-question-show#${link.messageEventId}`; show.dataset.commandInstanceLabel = link.note;
|
|
119
|
+
show.setAttribute('aria-label', `Show in chat: ${link.note}`);
|
|
120
|
+
show.style.gridRow = `1/span ${li.children.length}`; // spans every line this row has, and no empty ones
|
|
121
|
+
show.onclick = () => { if (!onShow(link)) toast(CHAT_NOT_OPEN_COPY); };
|
|
122
|
+
li.append(show); return li;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
function chatQuestionList(doc, host, rows, opts) {
|
|
126
|
+
const shown = rows.slice(0, 3), rest = rows.slice(3);
|
|
127
|
+
for (const row of shown) host.append(chatQuestionRow(doc, row, opts));
|
|
128
|
+
if (!rest.length) return;
|
|
129
|
+
const more = doc.createElement('details'); more.className = 'chat-q-more'; more.open = opts.ui.moreOpen === true;
|
|
130
|
+
const sum = doc.createElement('summary'); sum.dataset.commandId = `${opts.commandPrefix}.chat-questions-more`; more.append(sum);
|
|
131
|
+
const say = () => { sum.textContent = more.open ? 'Show fewer' : `Show ${rest.length} more`; }; say();
|
|
132
|
+
more.addEventListener('toggle', () => { opts.ui.moreOpen = more.open; say(); }); // stays open across repaints
|
|
133
|
+
for (const row of rest) more.append(chatQuestionRow(doc, row, opts));
|
|
134
|
+
host.append(more);
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* The "Questions in chat" card, or null when there is nothing to say.
|
|
139
|
+
* chatLinks {state: 'idle'|'ready'|'failed', links, partial}
|
|
140
|
+
* selected the selected objects as [{kind, id}]; empty when nothing is selected, and then the questions about
|
|
141
|
+
* objects not in the model are offered instead
|
|
142
|
+
* resolves(link) the link's object is in the model shown now
|
|
143
|
+
* currentLabel(link) the object's label now, '' when unknown
|
|
144
|
+
* commandPrefix the page's Instructor namespace ('steel', 'revit', 'tekla-parser')
|
|
145
|
+
* onShow(link) open AI Chat at that question; false when AI Chat cannot be reached
|
|
146
|
+
* onRetry(), toast(text)
|
|
147
|
+
* ui {moreOpen, orphansOpen}, kept by the page so an open list stays open across repaints
|
|
148
|
+
*/
|
|
149
|
+
export function renderChatQuestions({ doc, chatLinks, selected, resolves, currentLabel, commandPrefix, onShow, onRetry, toast, ui }) {
|
|
150
|
+
if (!chatLinks || chatLinks.state === 'idle') return null;
|
|
151
|
+
const box = doc.createElement('section'); box.className = 'chat-questions'; box.setAttribute('aria-label', 'Questions in chat');
|
|
152
|
+
if (chatLinks.state === 'failed') {
|
|
153
|
+
// Said with nothing selected too: that is where questions about removed objects would be listed.
|
|
154
|
+
const line = doc.createElement('div'); line.className = 'hint chat-q-failed'; line.textContent = 'Questions in chat could not be loaded.';
|
|
155
|
+
const retry = doc.createElement('button'); retry.type = 'button'; retry.className = 'ghost'; retry.textContent = 'Retry';
|
|
156
|
+
retry.dataset.commandId = `${commandPrefix}.chat-questions-retry`;
|
|
157
|
+
retry.onclick = () => onRetry(); line.append(' ', retry); box.append(line); return box;
|
|
158
|
+
}
|
|
159
|
+
const opts = { commandPrefix, currentLabel, onShow, toast, ui };
|
|
160
|
+
const atLeast = chatLinks.partial ? 'at least ' : '';
|
|
161
|
+
if (selected.length) {
|
|
162
|
+
const keys = new Set(selected.map((item) => `${item.kind}\0${item.id}`));
|
|
163
|
+
const rows = chatQuestionRows(chatLinks.links.filter((link) => keys.has(`${link.kind}\0${link.id}`) && resolves(link)));
|
|
164
|
+
if (!rows.length) return null;
|
|
165
|
+
const title = doc.createElement('div'); title.className = 'sect chat-q-title'; title.textContent = `Questions in chat (${atLeast}${rows.length})`;
|
|
166
|
+
box.append(title); chatQuestionList(doc, box, rows, { ...opts, about: selected.length > 1, unresolved: false });
|
|
167
|
+
return box;
|
|
168
|
+
}
|
|
169
|
+
const orphans = chatQuestionRows(chatLinks.links.filter((link) => !resolves(link)));
|
|
170
|
+
if (!orphans.length) return null;
|
|
171
|
+
const det = doc.createElement('details'); det.className = 'chat-q-orphans'; det.open = ui.orphansOpen === true;
|
|
172
|
+
det.addEventListener('toggle', () => { ui.orphansOpen = det.open; });
|
|
173
|
+
const sum = doc.createElement('summary'); sum.dataset.commandId = `${commandPrefix}.chat-questions-orphans`;
|
|
174
|
+
// Removed, never there, or read from another source file: an answer can name an id the model lacks.
|
|
175
|
+
sum.textContent = `Questions about objects not in the model (${atLeast}${orphans.length})`; det.append(sum);
|
|
176
|
+
chatQuestionList(doc, det, orphans, { ...opts, about: true, unresolved: true });
|
|
177
|
+
box.append(det); return box;
|
|
178
|
+
}
|
|
@@ -34,7 +34,7 @@ const PLACEMENTS = ['floating', 'docked'];
|
|
|
34
34
|
* readOnly?: boolean,
|
|
35
35
|
* emptyMessage?: string,
|
|
36
36
|
* }} options
|
|
37
|
-
* @returns {{ render(view): void, headerText(): string, destroy(): void }}
|
|
37
|
+
* @returns {{ render(view): void, refreshAfter(): void, headerText(): string, destroy(): void }}
|
|
38
38
|
*/
|
|
39
39
|
export function mountInspectorShell({
|
|
40
40
|
panel, doc, win, placement, readOnly = false,
|
|
@@ -57,6 +57,42 @@ export function mountInspectorShell({
|
|
|
57
57
|
};
|
|
58
58
|
|
|
59
59
|
let header = null;
|
|
60
|
+
// TRAILING SECTIONS (`view.after`) say something about the selection in EVERY settled state - after the body when
|
|
61
|
+
// an object is shown, after the note when nothing is selected or it went away (#1653: Questions in chat lists
|
|
62
|
+
// questions about objects no longer in the model when nothing is selected). They live in their own container so
|
|
63
|
+
// they can repaint alone (`refreshAfter`) when their own data arrives, without rebuilding the property sections
|
|
64
|
+
// above - a search typed into those survives.
|
|
65
|
+
let after = [];
|
|
66
|
+
let afterHost = null;
|
|
67
|
+
|
|
68
|
+
const paintSection = (section) => {
|
|
69
|
+
// `editable !== false` rather than `editable === true`: undeclared fails closed.
|
|
70
|
+
if (readOnly && section.editable !== false) return null;
|
|
71
|
+
const host = el('div', 'insp-section');
|
|
72
|
+
host.dataset.section = section.id || '';
|
|
73
|
+
if (section.heading) host.append(el('div', 'insp-section-heading', section.heading));
|
|
74
|
+
try {
|
|
75
|
+
section.render(host);
|
|
76
|
+
} catch (error) {
|
|
77
|
+
// Said in place rather than swallowed. A section that vanishes without explanation reads as
|
|
78
|
+
// "this object has no dimensions" - a confident wrong answer, the worst state a property panel
|
|
79
|
+
// can be in. The user gets the fact; the console keeps the cause for whoever debugs it.
|
|
80
|
+
try { win.console?.error?.('[inspector] a section could not be shown', section.id || '', error); } catch { /* reporting must not throw */ }
|
|
81
|
+
host.append(el('div', 'insp-error', 'This section could not be shown.'));
|
|
82
|
+
}
|
|
83
|
+
return host;
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
const paintAfter = () => {
|
|
87
|
+
// A trailing section that has nothing to say leaves no empty ruled box behind.
|
|
88
|
+
afterHost.replaceChildren(...after.map(paintSection).filter((host) => host && host.children.length));
|
|
89
|
+
};
|
|
90
|
+
const withAfter = (sections) => {
|
|
91
|
+
after = Array.isArray(sections) ? sections : [];
|
|
92
|
+
afterHost = el('div', 'insp-after');
|
|
93
|
+
paintAfter();
|
|
94
|
+
return afterHost;
|
|
95
|
+
};
|
|
60
96
|
|
|
61
97
|
/**
|
|
62
98
|
* Paint a view.
|
|
@@ -71,13 +107,14 @@ export function mountInspectorShell({
|
|
|
71
107
|
* also simply more accurate: this is a heading rendered as text, never a tooltip.
|
|
72
108
|
*/
|
|
73
109
|
const render = (view = {}) => {
|
|
74
|
-
const { state = 'empty', heading = '', message, sections = [] } = view;
|
|
110
|
+
const { state = 'empty', heading = '', message, sections = [], after: trailing = [] } = view;
|
|
75
111
|
|
|
76
112
|
if (state === 'loading') {
|
|
77
113
|
// The header is REUSED, not rebuilt, so the box it occupies never collapses mid-load.
|
|
78
114
|
panel.setAttribute('aria-busy', 'true');
|
|
79
115
|
const kept = header && heading === header.textContent ? header : el('div', 'insp-head', heading);
|
|
80
116
|
header = kept;
|
|
117
|
+
after = []; afterHost = null;
|
|
81
118
|
panel.replaceChildren(kept, el('div', 'insp-note', 'Loading…'));
|
|
82
119
|
return;
|
|
83
120
|
}
|
|
@@ -90,7 +127,7 @@ export function mountInspectorShell({
|
|
|
90
127
|
header = null;
|
|
91
128
|
// The two are DIFFERENT facts. "Nothing selected" and "what you had is gone" collapse into one
|
|
92
129
|
// only if you are willing to tell the user they deselected something the model removed.
|
|
93
|
-
panel.replaceChildren(el('div', `insp-note insp-${state}`, message || emptyMessage));
|
|
130
|
+
panel.replaceChildren(el('div', `insp-note insp-${state}`, message || emptyMessage), withAfter(trailing));
|
|
94
131
|
return;
|
|
95
132
|
}
|
|
96
133
|
|
|
@@ -98,30 +135,18 @@ export function mountInspectorShell({
|
|
|
98
135
|
const body = el('div', 'insp-body');
|
|
99
136
|
|
|
100
137
|
for (const section of sections) {
|
|
101
|
-
|
|
102
|
-
if (
|
|
103
|
-
|
|
104
|
-
const host = el('div', 'insp-section');
|
|
105
|
-
host.dataset.section = section.id || '';
|
|
106
|
-
if (section.heading) host.append(el('div', 'insp-section-heading', section.heading));
|
|
107
|
-
try {
|
|
108
|
-
section.render(host);
|
|
109
|
-
} catch {
|
|
110
|
-
// Said in place rather than swallowed. A section that vanishes without explanation reads as
|
|
111
|
-
// "this object has no dimensions" - a confident wrong answer, the worst state a property panel
|
|
112
|
-
// can be in. The error itself is the host's to log; the user gets the fact.
|
|
113
|
-
host.append(el('div', 'insp-error', 'This section could not be shown.'));
|
|
114
|
-
}
|
|
115
|
-
body.append(host);
|
|
138
|
+
const host = paintSection(section);
|
|
139
|
+
if (host) body.append(host);
|
|
116
140
|
}
|
|
117
141
|
|
|
118
|
-
panel.replaceChildren(header, body);
|
|
142
|
+
panel.replaceChildren(header, body, withAfter(trailing));
|
|
119
143
|
};
|
|
120
144
|
|
|
121
145
|
render({ state: 'empty' });
|
|
122
146
|
|
|
123
147
|
return {
|
|
124
148
|
render,
|
|
149
|
+
refreshAfter() { if (afterHost) paintAfter(); },
|
|
125
150
|
headerText: () => (header ? header.textContent : ''),
|
|
126
151
|
destroy() { panel.replaceChildren(); },
|
|
127
152
|
};
|
|
@@ -10,6 +10,17 @@ const SNAP_GLYPH = Object.freeze({
|
|
|
10
10
|
});
|
|
11
11
|
const SNAP_LABEL = Object.freeze({ 'mesh-vertex': 'Mesh vertex', 'mesh-edge-midpoint': 'Mesh edge midpoint',
|
|
12
12
|
'mesh-edge-nearest': 'Nearest on mesh edge', surface: 'Mesh surface' });
|
|
13
|
+
/**
|
|
14
|
+
* What the Dimension tool says when the snap index could not check the region under the pointer
|
|
15
|
+
* (#1747). `status` is appended to the step prompt in the dock and `readout` replaces the frame label
|
|
16
|
+
* next to the reticle; the dock's longer explanation is the refusal's own message, so the words live in
|
|
17
|
+
* one place (web/model-snapping.js). Only `crowded` is cured by zooming in; `pending` by waiting.
|
|
18
|
+
*/
|
|
19
|
+
const SNAP_LIMIT_COPY = Object.freeze({
|
|
20
|
+
crowded: Object.freeze({ status: 'zoom in to snap', readout: 'zoom in to snap' }),
|
|
21
|
+
pending: Object.freeze({ status: 'checking snaps…', readout: 'checking snaps…' }),
|
|
22
|
+
element: Object.freeze({ status: 'no snap on this element', readout: 'no snap on this element' }),
|
|
23
|
+
});
|
|
13
24
|
|
|
14
25
|
const point3 = (value) => Array.isArray(value) && value.length === 3 && value.every(Number.isFinite);
|
|
15
26
|
const unit = (value) => { const length = Math.hypot(...value); return length > 1e-9 ? value.map((item) => item / length) : null; };
|
|
@@ -166,7 +177,10 @@ export function mountModelMeasureTool({
|
|
|
166
177
|
const svg = document.createElementNS(SVG_NS, 'svg'); svg.classList.add('model-dim-overlay'); svg.setAttribute('aria-hidden', 'true'); host.append(svg);
|
|
167
178
|
const session = createModelMeasureSession({ initialDimensions, initialPresentation, onChange });
|
|
168
179
|
let armed, first, second, placementOffset, selectedIndex, onePickKind, visible, presentation, dimensions, lockSet;
|
|
169
|
-
let hover = null, onePickMenu = null;
|
|
180
|
+
let hover = null, onePickMenu = null, snapLimit = null, snapLimitTip = null;
|
|
181
|
+
// The pointer the tool last acquired at, so a zoom (which moves no pointer) re-checks the same spot.
|
|
182
|
+
let lastPointer = null, retryTimer = null, lastIndex = null;
|
|
183
|
+
const clearHover = () => { hover = null; snapLimit = null; snapLimitTip = null; };
|
|
170
184
|
const syncSession = () => {
|
|
171
185
|
const value = session.state(); ({ armed, first, second, placementOffset, selectedIndex, onePickKind, visible, presentation } = value);
|
|
172
186
|
dimensions = session.dimensions(); lockSet = new Set(value.locks); return value;
|
|
@@ -227,7 +241,8 @@ export function mountModelMeasureTool({
|
|
|
227
241
|
svgNode('line', { x1: x, y1: y - 13, x2: x, y2: y + 13 }));
|
|
228
242
|
const glyph = svgNode('text', { x, y: y + 4 }); glyph.textContent = SNAP_GLYPH[acquisition.kind] ?? '•'; group.append(glyph);
|
|
229
243
|
const readout = svgNode('text', { x: x + 15, y: y - 12, class: 'model-snap-readout' });
|
|
230
|
-
|
|
244
|
+
const limit = acquisition.kind === 'surface' ? SNAP_LIMIT_COPY[acquisition.snapLimit] : null;
|
|
245
|
+
readout.textContent = `${acquisition.kind} · ${limit ? limit.readout : resolveFrame(viewport).label}`; group.append(readout); svg.append(group);
|
|
231
246
|
};
|
|
232
247
|
const render = () => {
|
|
233
248
|
svg.replaceChildren();
|
|
@@ -237,17 +252,53 @@ export function mountModelMeasureTool({
|
|
|
237
252
|
if (first && second) drawDimension({ a: first.point, b: second.point, offsetPx: placementOffset }, true);
|
|
238
253
|
if (armed && hover) drawReticle(hover);
|
|
239
254
|
};
|
|
240
|
-
const surfaceAcquisition = (event, point) => point && snapModes.surface !== false ? Object.freeze({
|
|
255
|
+
const surfaceAcquisition = (event, point, limit = null) => point && snapModes.surface !== false ? Object.freeze({
|
|
241
256
|
id: 'surface-under-pointer', kind: 'surface', point: Object.freeze([...point]),
|
|
242
|
-
screen: viewport.projectPoint(point), distance: 0, entityId: null,
|
|
257
|
+
screen: viewport.projectPoint(point), distance: 0, entityId: null, snapLimit: limit,
|
|
243
258
|
}) : null;
|
|
244
259
|
const acquire = (event) => {
|
|
245
|
-
|
|
260
|
+
// Over empty space there is nothing to snap and nothing new to report, so the last notice stays:
|
|
261
|
+
// that is also the path the pointer takes to the dock, where the notice's explanation is hovered.
|
|
262
|
+
// Only "still reading" goes: the spot it was about has been left.
|
|
263
|
+
const surfacePoint = viewport.pickSurface(event.clientX, event.clientY);
|
|
264
|
+
if (!surfacePoint) {
|
|
265
|
+
// The spot a "still reading" retry would finish has been left: cancel it and forget the spot.
|
|
266
|
+
if (retryTimer !== null) { clearTimeout(retryTimer); retryTimer = null; }
|
|
267
|
+
lastPointer = null;
|
|
268
|
+
if (snapLimit === 'pending') { snapLimit = null; snapLimitTip = null; }
|
|
269
|
+
return null;
|
|
270
|
+
}
|
|
271
|
+
// Remember the last spot over the model: a zoom re-checks it, and a "still reading" retry finishes it.
|
|
272
|
+
lastPointer = { clientX: event.clientX, clientY: event.clientY, altKey: event.altKey === true };
|
|
273
|
+
snapLimit = null; snapLimitTip = null;
|
|
246
274
|
if (event.altKey) return surfaceAcquisition(event, surfacePoint);
|
|
247
275
|
const enabled = onePickKind ? Object.fromEntries(Object.keys(snapModes).map((kind) => [kind, kind === onePickKind])) : snapModes;
|
|
248
|
-
|
|
249
|
-
|
|
276
|
+
const index = snapIndex();
|
|
277
|
+
const snapped = closestModelSnap(index, { x: event.clientX, y: event.clientY }, viewport.projectPoint, enabled, 12, surfacePoint,
|
|
278
|
+
undefined, viewport.pointerRayOrigin?.(event.clientX, event.clientY) ?? null, viewport.snapVisibility?.() ?? null);
|
|
279
|
+
// A refused region is not "nothing nearby": the dock and the reticle say which, and why.
|
|
280
|
+
const looked = ['mesh-vertex', 'mesh-edge-midpoint', 'mesh-edge-nearest'].some((kind) => enabled[kind] !== false);
|
|
281
|
+
const refusal = snapped || !looked ? null : index?.pointerRefusal?.() ?? null;
|
|
282
|
+
if (refusal && SNAP_LIMIT_COPY[refusal.reason]) {
|
|
283
|
+
snapLimit = refusal.reason;
|
|
284
|
+
// The click outcome depends on this tool's own surface setting, so it is said here, not by the index.
|
|
285
|
+
const clickNow = refusal.reason === 'element' ? 'Here, a click places the point on the surface under the pointer.'
|
|
286
|
+
: 'Until then, a click places the point on the surface under the pointer.';
|
|
287
|
+
snapLimitTip = [refusal.message, enabled.surface !== false ? clickNow : null]
|
|
288
|
+
.filter(Boolean).join(' ') || null;
|
|
289
|
+
}
|
|
290
|
+
// Still being indexed: finish it without waiting for the pointer to move again.
|
|
291
|
+
if (snapLimit === 'pending') scheduleRetry();
|
|
292
|
+
return snapped ?? (enabled.surface !== false ? surfaceAcquisition(event, surfacePoint, snapLimit) : null);
|
|
293
|
+
};
|
|
294
|
+
// Re-acquire at the last pointer when the view changed or the region was still being indexed.
|
|
295
|
+
const reacquire = () => {
|
|
296
|
+
retryTimer = null; if (destroyed) return;
|
|
297
|
+
if (!armed || second || !lastPointer) { render(); return; }
|
|
298
|
+
hover = adjusted(acquire(lastPointer), lastPointer); render(); notify();
|
|
250
299
|
};
|
|
300
|
+
let destroyed = false;
|
|
301
|
+
const scheduleRetry = () => { if (retryTimer === null && !destroyed) retryTimer = setTimeout(reacquire, 0); };
|
|
251
302
|
const adjusted = (acquisition, event) => {
|
|
252
303
|
if (!first || !acquisition) return acquisition;
|
|
253
304
|
const frame = resolveFrame(viewport); const point = constrainedPoint(first.point, acquisition.point, lockSet, frame, event.altKey);
|
|
@@ -255,12 +306,15 @@ export function mountModelMeasureTool({
|
|
|
255
306
|
};
|
|
256
307
|
const notify = () => {
|
|
257
308
|
const index = snapIndex(); const step = !armed ? 0 : first === null ? 1 : second === null ? 2 : 3;
|
|
258
|
-
|
|
309
|
+
if (index !== lastIndex) { lastIndex = index; snapLimit = null; snapLimitTip = null; } // a new model generation
|
|
310
|
+
const limit = step === 1 || step === 2 ? SNAP_LIMIT_COPY[snapLimit] ?? null : null;
|
|
311
|
+
const prompt = step === 1 ? 'Pick point 1' : step === 2 ? 'Pick point 2' : step === 3 ? 'Place dimension'
|
|
312
|
+
: selectedIndex !== null ? 'Dimension selected · Enter to edit · Delete to remove' : (dimensions.length ? `${dimensions.length} placed` : 'Ready');
|
|
313
|
+
// A snap refusal is about picking points, so it is shown only while the tool is armed. Disarmed, the
|
|
259
314
|
// status returns to the session (Ready / N placed / selected) — a sentence-long refusal left behind there
|
|
260
315
|
// kept the dock's actions bar wide enough to strand it on its own upper row (#1738).
|
|
261
|
-
const status = armed && index?.available === false ? index.refusal?.message :
|
|
262
|
-
|
|
263
|
-
onState({ armed, hasDraft: !!first, step, count: dimensions.length, selectedIndex, status, visible,
|
|
316
|
+
const status = armed && index?.available === false ? index.refusal?.message : limit ? `${prompt} · ${limit.status}` : prompt;
|
|
317
|
+
onState({ armed, hasDraft: !!first, step, count: dimensions.length, selectedIndex, status, statusTip: limit ? snapLimitTip : null, visible,
|
|
264
318
|
presentation: { ...presentation }, snapModes: { ...snapModes }, locks: [...lockSet],
|
|
265
319
|
activeFrame: resolveFrame(viewport).label, acquired: hover?.kind ?? null, onePickKind });
|
|
266
320
|
};
|
|
@@ -291,7 +345,7 @@ export function mountModelMeasureTool({
|
|
|
291
345
|
}
|
|
292
346
|
event.preventDefault(); event.stopImmediatePropagation();
|
|
293
347
|
if (second) {
|
|
294
|
-
session.commitPlacement({ frameId: resolveFrame(viewport).id }); syncSession();
|
|
348
|
+
session.commitPlacement({ frameId: resolveFrame(viewport).id }); syncSession(); clearHover();
|
|
295
349
|
} else {
|
|
296
350
|
const acquisition = adjusted(acquire(event), event); if (!acquisition) { notify(); return; }
|
|
297
351
|
session.pickPoint(acquisition); syncSession(); if (second) hover = acquisition;
|
|
@@ -336,7 +390,7 @@ export function mountModelMeasureTool({
|
|
|
336
390
|
if (enabled === false) continue;
|
|
337
391
|
const button = document.createElement('button'); button.type = 'button'; button.setAttribute('role', 'menuitem');
|
|
338
392
|
button.dataset.snapOnePick = kind; button.textContent = `${SNAP_GLYPH[kind] ?? '•'} ${SNAP_LABEL[kind] ?? kind}`;
|
|
339
|
-
button.addEventListener('click', () => { session.restrictNextPick(kind); syncSession(); closeOnePickMenu(); notify(); }); menu.append(button);
|
|
393
|
+
button.addEventListener('click', () => { session.restrictNextPick(kind); syncSession(); snapLimit = null; snapLimitTip = null; closeOnePickMenu(); notify(); }); menu.append(button);
|
|
340
394
|
}
|
|
341
395
|
document.body.append(menu); onePickMenu = menu; menu.querySelector('button')?.focus();
|
|
342
396
|
};
|
|
@@ -361,20 +415,23 @@ export function mountModelMeasureTool({
|
|
|
361
415
|
if (onePickMenu) closeOnePickMenu();
|
|
362
416
|
// The rung that disarms the tool takes the button's way out: the cursor and the canvas input go with it.
|
|
363
417
|
else if (session.cancelStep() === 'tool') { api.setArmed(false); return; }
|
|
364
|
-
else { syncSession();
|
|
418
|
+
else { syncSession(); clearHover(); }
|
|
365
419
|
render(); notify();
|
|
366
420
|
};
|
|
367
421
|
let api;
|
|
368
422
|
const releaseInput = viewport.registerInputTool?.({ pointerMove: onMove, click: onClick, contextMenu: onContextMenu, keyDown: onKey,
|
|
369
423
|
cancel() { if (armed) api?.setArmed(false); } }, { id: 'model-measure', priority: 50, exclusiveGroup: 'model-command' });
|
|
370
424
|
if (typeof releaseInput !== 'function') throw new Error('Model measurement requires the shared CAD input arbiter.');
|
|
371
|
-
|
|
425
|
+
// A zoom or orbit moves the view under a still pointer: re-check that spot, so a notice such as "zoom
|
|
426
|
+
// in to snap" does not outlive the zoom that answered it.
|
|
427
|
+
// Coalesced: an orbit notifies many times per frame; the spot is re-checked once after them.
|
|
428
|
+
const unsubscribe = viewport.onCameraChange?.(() => { if (armed && !second && lastPointer) scheduleRetry(); render(); }) ?? (() => {});
|
|
372
429
|
api = {
|
|
373
|
-
setArmed(value) { if (value) releaseInput.activate?.(); else releaseInput.deactivate?.(); session.setArmed(value); syncSession(); surface.classList.toggle('measure-armed', armed); if (!armed) {
|
|
430
|
+
setArmed(value) { if (value) releaseInput.activate?.(); else releaseInput.deactivate?.(); session.setArmed(value); syncSession(); surface.classList.toggle('measure-armed', armed); if (!armed) { clearHover(); lastPointer = null; closeOnePickMenu(); } render(); notify(); },
|
|
374
431
|
toggle() { api.setArmed(!armed); },
|
|
375
432
|
setSnapMode(kind, value) { if (kind in snapModes) { snapModes = { ...snapModes, [kind]: value === true }; render(); notify(); } },
|
|
376
433
|
setAxisLock(kind) { if (['f', 'x', 'y', 'z'].includes(kind)) setLock(kind); },
|
|
377
|
-
clear() { session.clear(); syncSession();
|
|
434
|
+
clear() { session.clear(); syncSession(); clearHover(); render(); notify(); },
|
|
378
435
|
setVisible(value) { const result = session.setVisible(value); syncSession(); render(); notify(); return result; },
|
|
379
436
|
setPresentation(value) { const result = session.setPresentation(value); syncSession(); render(); notify(); return result; },
|
|
380
437
|
update(index, patch) {
|
|
@@ -388,7 +445,7 @@ export function mountModelMeasureTool({
|
|
|
388
445
|
dimensions() { return session.dimensions(); },
|
|
389
446
|
serialize() { return session.serialize(); },
|
|
390
447
|
refresh() { render(); },
|
|
391
|
-
destroy() { closeOnePickMenu(); closeEditor(); unsubscribe(); releaseInput(); session.dispose(); svg.remove(); },
|
|
448
|
+
destroy() { destroyed = true; if (retryTimer !== null) clearTimeout(retryTimer); retryTimer = null; closeOnePickMenu(); closeEditor(); unsubscribe(); releaseInput(); session.dispose(); svg.remove(); },
|
|
392
449
|
};
|
|
393
450
|
notify(); return api;
|
|
394
451
|
}
|
|
@@ -145,9 +145,14 @@ export function mountModelPointerDock({ selectionHost = null, snapHost = null, a
|
|
|
145
145
|
if (button) { button.classList.toggle('on', state.armed === true); button.setAttribute('aria-pressed', String(state.armed === true)); }
|
|
146
146
|
const status = actionsHost?.querySelector('[data-model-action-status]');
|
|
147
147
|
if (status) {
|
|
148
|
+
// This runs on every pointer move while measuring. Touch the live region only when the words
|
|
149
|
+
// change, so assistive technology is not re-told the same status on each move. The pill is
|
|
150
|
+
// width-capped with an ellipsis (model-editor.css), so it always carries a themed tooltip: the
|
|
151
|
+
// provider's longer explanation when it has one (a snap notice), else the same full sentence.
|
|
148
152
|
const text = state.status ?? (state.armed ? (state.hasDraft ? 'Pick point 2' : 'Pick point 1') : (state.count ? `${state.count} placed` : 'Ready'));
|
|
149
|
-
|
|
150
|
-
|
|
153
|
+
if (status.textContent !== text) status.textContent = text;
|
|
154
|
+
const tip = typeof state.statusTip === 'string' && state.statusTip ? state.statusTip : text;
|
|
155
|
+
if (status.getAttribute('data-tip') !== tip) status.setAttribute('data-tip', tip);
|
|
151
156
|
}
|
|
152
157
|
const locks = new Set(state.locks ?? []);
|
|
153
158
|
actionsHost?.querySelectorAll('[data-model-axis]').forEach((axisButton) => {
|
|
@@ -19,6 +19,20 @@ export const MODEL_SNAP_LIMITS_V1 = Object.freeze({
|
|
|
19
19
|
directionMinLength: 1e-9, nearParallelCrossLength: 1e-8,
|
|
20
20
|
extensionSourceLengths: 10, extensionMaximumMm: 100000,
|
|
21
21
|
});
|
|
22
|
+
/**
|
|
23
|
+
* How mesh snap acquisition decides what it has checked (#1747). Topology is indexed per element, on
|
|
24
|
+
* demand, for the pointer's sightline region only: a capsule along the pick ray, from its origin to
|
|
25
|
+
* `behindHitReach` radii past the surface under the pointer, whose radius is `neighbourhoodMargin`
|
|
26
|
+
* times the world length of the acquisition radius at that surface. Every visible element whose
|
|
27
|
+
* envelope meets that region is indexed COMPLETELY or the query is refused with `over-budget` — a
|
|
28
|
+
* partial set is never returned. `over-budget` therefore means "this pointer position's region could
|
|
29
|
+
* not be checked completely within the fixed budget" (or not yet, within one move's share of it),
|
|
30
|
+
* never "snapping is off for the model". `queryEvaluationCap` bounds the candidates one pointer event
|
|
31
|
+
* may evaluate; more than that inside the region is refused the same way, not truncated.
|
|
32
|
+
*/
|
|
33
|
+
export const MODEL_SNAP_INDEX_POLICY_V1 = Object.freeze({
|
|
34
|
+
coverage: 'pointer-sightline', neighbourhoodMargin: 2, behindHitReach: 8, queryEvaluationCap: 4096,
|
|
35
|
+
});
|
|
22
36
|
|
|
23
37
|
const MAX_COORD = 1e12, MAX_CSS = 1e7, MAX_GENERATION = 0xffffffff;
|
|
24
38
|
const own = (v, k) => Object.prototype.hasOwnProperty.call(v, k);
|