@kruschdev/pascal-plugin-plumbing 0.2.1 → 0.3.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/docs/CAD-CATALOG.md +2 -2
- package/package.json +2 -2
- package/src/agent-operations.ts +14 -2
- package/src/agent-tools.ts +1 -0
- package/src/cad/fittings.ts +26 -8
- package/src/cad/manifold-interior.ts +5 -6
- package/src/index.ts +3 -0
- package/src/ipc/audit.ts +124 -26
- package/src/ipc/autopopulate.ts +609 -93
- package/src/ipc/framing-interop.ts +3 -2
- package/src/ipc/pricing.ts +98 -0
- package/src/ipc/routing.ts +148 -18
- package/src/ipc/schedule.ts +37 -14
- package/src/ipc/sizing.ts +140 -0
- package/src/ipc/tables.ts +5 -2
- package/src/nodes/parametrics.ts +76 -0
- package/src/nodes/pipe-run.ts +83 -32
- package/src/ui/chat-card.tsx +52 -0
- package/src/ui/inspector-card.tsx +36 -4
- package/src/ui/manifold-cutaway-view.tsx +35 -8
- package/src/ui/plumbing-panel.tsx +5 -3
- package/src/ui/schedule-view.tsx +1 -1
- package/src/ui/store.ts +0 -17
package/src/nodes/parametrics.ts
CHANGED
|
@@ -3,6 +3,8 @@
|
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
5
|
import type { ParametricDescriptor } from '@pascal-app/core'
|
|
6
|
+
import { getEquipmentElectricalDemand, getFixtureElectricalDemand } from '../ipc/framing-interop'
|
|
7
|
+
import { type EquipmentKind, FIXTURE_SPECS, type FixtureKind, round2 } from '../ipc/tables'
|
|
6
8
|
import { EquipmentKindEnum, type PlumbingEquipmentNode } from './equipment'
|
|
7
9
|
import { FixtureKindEnum, PipeNominalSizeEnum, type PlumbingFixtureNode } from './fixture'
|
|
8
10
|
import { ManifoldKindEnum, type PlumbingManifoldNode } from './manifold'
|
|
@@ -29,6 +31,40 @@ export const plumbingEquipmentParametrics: ParametricDescriptor<PlumbingEquipmen
|
|
|
29
31
|
],
|
|
30
32
|
},
|
|
31
33
|
],
|
|
34
|
+
derive: (next, patch, previous) => {
|
|
35
|
+
const kind = next.equipmentKind as EquipmentKind
|
|
36
|
+
const kindChanged =
|
|
37
|
+
'equipmentKind' in patch &&
|
|
38
|
+
patch.equipmentKind !== undefined &&
|
|
39
|
+
(!previous || patch.equipmentKind !== previous.equipmentKind)
|
|
40
|
+
const wattsChanged = 'watts' in patch && typeof patch.watts === 'number'
|
|
41
|
+
|
|
42
|
+
if (kindChanged && !wattsChanged) {
|
|
43
|
+
const demand = getEquipmentElectricalDemand(kind)
|
|
44
|
+
const defaultGasBtuh =
|
|
45
|
+
kind === 'water-heater-tank-gas'
|
|
46
|
+
? 40000
|
|
47
|
+
: kind === 'water-heater-tankless-gas'
|
|
48
|
+
? 199000
|
|
49
|
+
: 0
|
|
50
|
+
return {
|
|
51
|
+
watts: demand?.loadVa ?? 0,
|
|
52
|
+
electricalDemand: demand,
|
|
53
|
+
...(!('gasBtuh' in patch) ? { gasBtuh: defaultGasBtuh } : {}),
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
if (kindChanged || wattsChanged) {
|
|
58
|
+
const customWatts = typeof next.watts === 'number' && next.watts > 0 ? next.watts : undefined
|
|
59
|
+
const demand = getEquipmentElectricalDemand(kind, customWatts)
|
|
60
|
+
return {
|
|
61
|
+
watts: demand ? (customWatts ?? demand.loadVa) : (wattsChanged ? next.watts : 0),
|
|
62
|
+
electricalDemand: demand,
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
return {}
|
|
67
|
+
},
|
|
32
68
|
}
|
|
33
69
|
|
|
34
70
|
export const plumbingManifoldParametrics: ParametricDescriptor<PlumbingManifoldNode> = {
|
|
@@ -63,6 +99,46 @@ export const plumbingFixtureParametrics: ParametricDescriptor<PlumbingFixtureNod
|
|
|
63
99
|
],
|
|
64
100
|
},
|
|
65
101
|
],
|
|
102
|
+
derive: (next, patch, previous) => {
|
|
103
|
+
const kind = next.fixtureKind as FixtureKind
|
|
104
|
+
const spec = FIXTURE_SPECS[kind]
|
|
105
|
+
const kindChanged =
|
|
106
|
+
'fixtureKind' in patch &&
|
|
107
|
+
patch.fixtureKind !== undefined &&
|
|
108
|
+
(!previous || patch.fixtureKind !== previous.fixtureKind)
|
|
109
|
+
|
|
110
|
+
if (kindChanged && spec) {
|
|
111
|
+
const wsfuCold = 'wsfuCold' in patch ? next.wsfuCold : spec.wsfuCold
|
|
112
|
+
const wsfuHot = 'wsfuHot' in patch ? next.wsfuHot : spec.wsfuHot
|
|
113
|
+
const wsfuTotal =
|
|
114
|
+
'wsfuTotal' in patch
|
|
115
|
+
? next.wsfuTotal
|
|
116
|
+
: 'wsfuCold' in patch || 'wsfuHot' in patch
|
|
117
|
+
? round2(wsfuCold + wsfuHot)
|
|
118
|
+
: spec.wsfuTotal
|
|
119
|
+
return {
|
|
120
|
+
...(!('dfu' in patch) ? { dfu: spec.dfuIpc } : {}),
|
|
121
|
+
wsfuCold,
|
|
122
|
+
wsfuHot,
|
|
123
|
+
wsfuTotal,
|
|
124
|
+
...(!('trapSize' in patch) ? { trapSize: spec.minTrapIn } : {}),
|
|
125
|
+
...(!('drainSize' in patch) ? { drainSize: spec.minDrainIn } : {}),
|
|
126
|
+
...(!('ventSize' in patch) ? { ventSize: spec.minVentIn } : {}),
|
|
127
|
+
...(!('supplySize' in patch) ? { supplySize: spec.supplySizeIn } : {}),
|
|
128
|
+
...(!('hasPTrap' in patch) ? { hasPTrap: spec.needsPTrap } : {}),
|
|
129
|
+
...(!('hasVacuumBreaker' in patch) ? { hasVacuumBreaker: kind === 'hose-bibb' } : {}),
|
|
130
|
+
electricalDemand: getFixtureElectricalDemand(kind),
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
if (('wsfuCold' in patch || 'wsfuHot' in patch) && !('wsfuTotal' in patch)) {
|
|
135
|
+
return {
|
|
136
|
+
wsfuTotal: round2(next.wsfuCold + next.wsfuHot),
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
return {}
|
|
141
|
+
},
|
|
66
142
|
}
|
|
67
143
|
|
|
68
144
|
export const plumbingPipeRunParametrics: ParametricDescriptor<PlumbingPipeRunNode> = {
|
package/src/nodes/pipe-run.ts
CHANGED
|
@@ -90,6 +90,19 @@ export const PlumbingPipeRunNode = BaseNode.extend({
|
|
|
90
90
|
|
|
91
91
|
export type PlumbingPipeRunNode = z.infer<typeof PlumbingPipeRunNode>
|
|
92
92
|
|
|
93
|
+
function isFinitePt(p: unknown): p is [number, number, number] {
|
|
94
|
+
return (
|
|
95
|
+
Array.isArray(p) &&
|
|
96
|
+
p.length >= 3 &&
|
|
97
|
+
typeof p[0] === 'number' &&
|
|
98
|
+
typeof p[1] === 'number' &&
|
|
99
|
+
typeof p[2] === 'number' &&
|
|
100
|
+
Number.isFinite(p[0]) &&
|
|
101
|
+
Number.isFinite(p[1]) &&
|
|
102
|
+
Number.isFinite(p[2])
|
|
103
|
+
)
|
|
104
|
+
}
|
|
105
|
+
|
|
93
106
|
function normalizeDir(
|
|
94
107
|
a: readonly [number, number, number],
|
|
95
108
|
b: readonly [number, number, number],
|
|
@@ -99,26 +112,29 @@ function normalizeDir(
|
|
|
99
112
|
const dy = (b[1] - a[1]) * sign
|
|
100
113
|
const dz = (b[2] - a[2]) * sign
|
|
101
114
|
const len = Math.hypot(dx, dy, dz)
|
|
102
|
-
if (len < 1e-5) return [0, 1, 0]
|
|
115
|
+
if (!Number.isFinite(len) || len < 1e-5) return [0, 1, 0]
|
|
103
116
|
return [dx / len, dy / len, dz / len]
|
|
104
117
|
}
|
|
105
118
|
|
|
106
119
|
export function getPlumbingPipeRunPorts(node: PlumbingPipeRunNode): NodePort[] {
|
|
107
|
-
const
|
|
108
|
-
const
|
|
109
|
-
|
|
120
|
+
const validPath = Array.isArray(node.path) ? node.path.filter(isFinitePt) : []
|
|
121
|
+
const start = validPath[0]
|
|
122
|
+
const end = validPath[validPath.length - 1]
|
|
123
|
+
if (!start || !end || validPath.length < 2) return []
|
|
110
124
|
let second = end
|
|
111
|
-
for (let i = 1; i <
|
|
112
|
-
const p =
|
|
113
|
-
|
|
125
|
+
for (let i = 1; i < validPath.length; i++) {
|
|
126
|
+
const p = validPath[i]!
|
|
127
|
+
const len = Math.hypot(p[0] - start[0], p[1] - start[1], p[2] - start[2])
|
|
128
|
+
if (Number.isFinite(len) && len >= 1e-5) {
|
|
114
129
|
second = p
|
|
115
130
|
break
|
|
116
131
|
}
|
|
117
132
|
}
|
|
118
133
|
let prev = start
|
|
119
|
-
for (let i =
|
|
120
|
-
const p =
|
|
121
|
-
|
|
134
|
+
for (let i = validPath.length - 2; i >= 0; i--) {
|
|
135
|
+
const p = validPath[i]!
|
|
136
|
+
const len = Math.hypot(end[0] - p[0], end[1] - p[1], end[2] - p[2])
|
|
137
|
+
if (Number.isFinite(len) && len >= 1e-5) {
|
|
122
138
|
prev = p
|
|
123
139
|
break
|
|
124
140
|
}
|
|
@@ -142,15 +158,23 @@ export function buildPlumbingPipeRunGeometry(
|
|
|
142
158
|
node: PlumbingPipeRunNode,
|
|
143
159
|
ctx: GeometryContext,
|
|
144
160
|
): Group {
|
|
161
|
+
const validPath = Array.isArray(node.path) ? node.path.filter(isFinitePt) : []
|
|
145
162
|
let penetrations: ReturnType<typeof computePipeFramingPenetrations> = []
|
|
146
|
-
if (
|
|
163
|
+
if (
|
|
164
|
+
validPath.length >= 2 &&
|
|
165
|
+
node.showFramingPenetrations &&
|
|
166
|
+
ctx &&
|
|
167
|
+
typeof ctx === 'object' &&
|
|
168
|
+
'nodes' in ctx &&
|
|
169
|
+
ctx.nodes
|
|
170
|
+
) {
|
|
147
171
|
const record = ctx.nodes as unknown as Readonly<Record<string, SceneNodeLike>>
|
|
148
172
|
const levelId = resolveNodeLevelId(record, node as unknown as SceneNodeLike) ?? node.parentId ?? null
|
|
149
173
|
const walls = extractWallSegments(record, levelId)
|
|
150
174
|
const bones = extractBonesPlumbingContext(record, levelId)
|
|
151
175
|
penetrations = computePipeFramingPenetrations({
|
|
152
176
|
pipeRunId: node.id,
|
|
153
|
-
path:
|
|
177
|
+
path: validPath,
|
|
154
178
|
pipeSize: node.nominalSize as PipeNominalSize,
|
|
155
179
|
material: node.material as PipeMaterial,
|
|
156
180
|
walls,
|
|
@@ -160,7 +184,7 @@ export function buildPlumbingPipeRunGeometry(
|
|
|
160
184
|
|
|
161
185
|
const group = buildPipeRunCad({
|
|
162
186
|
id: node.id,
|
|
163
|
-
path:
|
|
187
|
+
path: validPath,
|
|
164
188
|
system: node.system as PlumbingSystem,
|
|
165
189
|
material: node.material as PipeMaterial,
|
|
166
190
|
nominalSize: node.nominalSize as PipeNominalSize,
|
|
@@ -171,21 +195,17 @@ export function buildPlumbingPipeRunGeometry(
|
|
|
171
195
|
// Sub-Slab X-Ray Ground Visibility: render ONLY below-grade pipe segments/fittings (maxY < 0.04 m)
|
|
172
196
|
// through Pascal's opaque y=0 ground plane and floor slab so above-grade risers & bore collars stay
|
|
173
197
|
// properly depth-tested behind opaque walls and cabinets.
|
|
174
|
-
const hasBelowGradePoint =
|
|
198
|
+
const hasBelowGradePoint = validPath.some((p) => p[1] < -0.005)
|
|
175
199
|
if (node.xraySubSlab && hasBelowGradePoint && node.system !== 'dwv-vent') {
|
|
176
200
|
const isDarkDwv =
|
|
177
201
|
node.system === 'dwv-drain' && (node.material === 'abs-dwv' || node.material === 'cast-iron')
|
|
178
202
|
group.updateMatrixWorld(true)
|
|
179
203
|
const meshBox = new Box3()
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
if (!
|
|
184
|
-
|
|
185
|
-
const mats = Array.isArray(obj.material) ? obj.material : [obj.material]
|
|
186
|
-
const cloned = mats.map((m) => {
|
|
187
|
-
if (!(m instanceof MeshStandardMaterial)) return m
|
|
188
|
-
const next = m.clone()
|
|
204
|
+
const xrayCloneByBase = new Map<MeshStandardMaterial, MeshStandardMaterial>()
|
|
205
|
+
const getXrayClone = (base: MeshStandardMaterial): MeshStandardMaterial => {
|
|
206
|
+
let next = xrayCloneByBase.get(base)
|
|
207
|
+
if (!next) {
|
|
208
|
+
next = base.clone()
|
|
189
209
|
next.depthTest = false
|
|
190
210
|
next.depthWrite = false
|
|
191
211
|
next.transparent = true
|
|
@@ -195,10 +215,39 @@ export function buildPlumbingPipeRunGeometry(
|
|
|
195
215
|
next.emissiveIntensity = 0.28
|
|
196
216
|
}
|
|
197
217
|
next.needsUpdate = true
|
|
198
|
-
|
|
199
|
-
}
|
|
200
|
-
|
|
218
|
+
xrayCloneByBase.set(base, next)
|
|
219
|
+
}
|
|
220
|
+
return next
|
|
221
|
+
}
|
|
222
|
+
group.traverse((obj) => {
|
|
223
|
+
if (!(obj instanceof Mesh)) return
|
|
224
|
+
meshBox.setFromObject(obj)
|
|
225
|
+
if (!Number.isFinite(meshBox.max.y) || meshBox.max.y >= 0.04) return
|
|
226
|
+
obj.renderOrder = 30
|
|
227
|
+
if (Array.isArray(obj.material)) {
|
|
228
|
+
obj.material = obj.material.map((m) =>
|
|
229
|
+
m instanceof MeshStandardMaterial ? getXrayClone(m) : m,
|
|
230
|
+
)
|
|
231
|
+
} else if (obj.material instanceof MeshStandardMaterial) {
|
|
232
|
+
obj.material = getXrayClone(obj.material)
|
|
233
|
+
}
|
|
201
234
|
})
|
|
235
|
+
if (xrayCloneByBase.size > 0) {
|
|
236
|
+
const stillReferenced = new Set<unknown>()
|
|
237
|
+
group.traverse((obj) => {
|
|
238
|
+
if (!(obj instanceof Mesh)) return
|
|
239
|
+
if (Array.isArray(obj.material)) {
|
|
240
|
+
for (const m of obj.material) stillReferenced.add(m)
|
|
241
|
+
} else {
|
|
242
|
+
stillReferenced.add(obj.material)
|
|
243
|
+
}
|
|
244
|
+
})
|
|
245
|
+
for (const baseMat of xrayCloneByBase.keys()) {
|
|
246
|
+
if (!stillReferenced.has(baseMat)) {
|
|
247
|
+
baseMat.dispose()
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
}
|
|
202
251
|
}
|
|
203
252
|
|
|
204
253
|
return group
|
|
@@ -213,12 +262,14 @@ export function buildPlumbingPipeRunFloorplan(
|
|
|
213
262
|
const meta = systemColorMeta(node.system as PlumbingSystem)
|
|
214
263
|
const stroke = selected && view?.palette ? view.palette.selectedStroke : meta.hex
|
|
215
264
|
const children: FloorplanGeometry[] = []
|
|
265
|
+
const validPath = Array.isArray(node.path) ? node.path.filter(isFinitePt) : []
|
|
216
266
|
|
|
217
267
|
let drewHorizontal = false
|
|
218
|
-
for (let i = 0; i <
|
|
219
|
-
const a =
|
|
220
|
-
const b =
|
|
221
|
-
|
|
268
|
+
for (let i = 0; i < validPath.length - 1; i++) {
|
|
269
|
+
const a = validPath[i]!
|
|
270
|
+
const b = validPath[i + 1]!
|
|
271
|
+
const len = Math.hypot(b[0] - a[0], b[2] - a[2])
|
|
272
|
+
if (!Number.isFinite(len) || len < 1e-3) continue
|
|
222
273
|
drewHorizontal = true
|
|
223
274
|
children.push({
|
|
224
275
|
kind: 'line',
|
|
@@ -232,8 +283,8 @@ export function buildPlumbingPipeRunFloorplan(
|
|
|
232
283
|
})
|
|
233
284
|
}
|
|
234
285
|
|
|
235
|
-
const start =
|
|
236
|
-
if (!drewHorizontal && start &&
|
|
286
|
+
const start = validPath[0]
|
|
287
|
+
if (!drewHorizontal && start && validPath.length >= 2) {
|
|
237
288
|
// Pure vertical pipe stack (e.g., 3"/4" Main Vent Stack): render a visible 2D riser circle + crosshair
|
|
238
289
|
const odM = getPipeOuterDiameterM(node.nominalSize as PipeNominalSize, node.material as PipeMaterial)
|
|
239
290
|
const r = Math.max(0.085, (odM / 2) * 1.6)
|
package/src/ui/chat-card.tsx
CHANGED
|
@@ -37,6 +37,19 @@ export default function PlumbingChatCard({ toolName, output, state, actions }: C
|
|
|
37
37
|
const slopeInPerFt = typeof data?.slopeInPerFt === 'number' ? data.slopeInPerFt : null
|
|
38
38
|
const showSlope =
|
|
39
39
|
slopeInPerFt !== null && (slopeInPerFt !== 0 || data?.system === 'dwv-drain')
|
|
40
|
+
const placedName = typeof data?.name === 'string' && data.name ? data.name : null
|
|
41
|
+
const placedEquipmentKind = typeof data?.equipmentKind === 'string' ? data.equipmentKind : null
|
|
42
|
+
const placedManifoldKind = typeof data?.manifoldKind === 'string' ? data.manifoldKind : null
|
|
43
|
+
const placedFixtureKind = typeof data?.fixtureKind === 'string' ? data.fixtureKind : null
|
|
44
|
+
const placedDemand = data?.electricalDemand as
|
|
45
|
+
| { required?: boolean; voltage?: number; breakerAmps?: number }
|
|
46
|
+
| null
|
|
47
|
+
| undefined
|
|
48
|
+
const placedPortCount = typeof data?.portCount === 'number' ? data.portCount : null
|
|
49
|
+
const placedDfu = typeof data?.dfu === 'number' ? data.dfu : null
|
|
50
|
+
const placedWsfu = typeof data?.wsfu === 'number' ? data.wsfu : null
|
|
51
|
+
const connectedPipeRunCount =
|
|
52
|
+
typeof data?.connectedPipeRunCount === 'number' ? data.connectedPipeRunCount : null
|
|
40
53
|
|
|
41
54
|
return (
|
|
42
55
|
<div
|
|
@@ -94,6 +107,45 @@ export default function PlumbingChatCard({ toolName, output, state, actions }: C
|
|
|
94
107
|
</div>
|
|
95
108
|
)}
|
|
96
109
|
|
|
110
|
+
{/* Summary for plumbing_place_equipment / plumbing_place_manifold / plumbing_place_fixture */}
|
|
111
|
+
{lengthFt === null &&
|
|
112
|
+
routedNodeId &&
|
|
113
|
+
(placedEquipmentKind || placedManifoldKind || placedFixtureKind) && (
|
|
114
|
+
<div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center', fontSize: 11 }}>
|
|
115
|
+
<span>
|
|
116
|
+
{placedEquipmentKind && (
|
|
117
|
+
<>
|
|
118
|
+
<strong>Placed Equipment:</strong> {placedName ?? placedEquipmentKind}
|
|
119
|
+
{placedDemand?.required ? ` · ${placedDemand.voltage}V ${placedDemand.breakerAmps}A` : ''}
|
|
120
|
+
</>
|
|
121
|
+
)}
|
|
122
|
+
{placedManifoldKind && (
|
|
123
|
+
<>
|
|
124
|
+
<strong>Placed Manifold:</strong> {placedName ?? placedManifoldKind}
|
|
125
|
+
{placedPortCount !== null ? ` (${placedPortCount} ports)` : ''}
|
|
126
|
+
</>
|
|
127
|
+
)}
|
|
128
|
+
{placedFixtureKind && (
|
|
129
|
+
<>
|
|
130
|
+
<strong>Placed Fixture:</strong> {placedName ?? placedFixtureKind}
|
|
131
|
+
{placedDfu !== null ? ` · ${placedDfu} DFU` : ''}
|
|
132
|
+
{placedWsfu !== null ? ` · ${placedWsfu} WSFU` : ''}
|
|
133
|
+
{connectedPipeRunCount && connectedPipeRunCount > 0
|
|
134
|
+
? ` · ${connectedPipeRunCount} pipe(s) routed`
|
|
135
|
+
: ''}
|
|
136
|
+
</>
|
|
137
|
+
)}
|
|
138
|
+
</span>
|
|
139
|
+
<button
|
|
140
|
+
type="button"
|
|
141
|
+
onClick={() => actions.select([routedNodeId])}
|
|
142
|
+
style={{ background: 'transparent', border: 'none', color: '#38bdf8', cursor: 'pointer', fontSize: 11 }}
|
|
143
|
+
>
|
|
144
|
+
Select
|
|
145
|
+
</button>
|
|
146
|
+
</div>
|
|
147
|
+
)}
|
|
148
|
+
|
|
97
149
|
{/* Summary for plumbing_route_pipe */}
|
|
98
150
|
{lengthFt !== null && (
|
|
99
151
|
<div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center', fontSize: 11 }}>
|
|
@@ -19,6 +19,7 @@ import {
|
|
|
19
19
|
} from '../ipc/framing-interop'
|
|
20
20
|
import { extractWallSegments, measureDrainPathSlope, polylineLengthM } from '../ipc/routing'
|
|
21
21
|
import { resolveNodeElectricalDemand } from '../ipc/schedule'
|
|
22
|
+
import { calculateSupplyHydraulics, wsfuToGpm } from '../ipc/sizing'
|
|
22
23
|
import { METERS_TO_FEET, type PipeMaterial, type PipeNominalSize, round2 } from '../ipc/tables'
|
|
23
24
|
import { PLUMBING_SCHEDULE_VIEW_ID } from './plumbing-panel'
|
|
24
25
|
import { usePlumbingUi } from './store'
|
|
@@ -45,19 +46,43 @@ export default function PlumbingInspectorCard({ node }: { node?: AnyNode }) {
|
|
|
45
46
|
const path = raw.path as ReadonlyArray<Vec3>
|
|
46
47
|
const lengthFt = round2(polylineLengthM(path) * METERS_TO_FEET)
|
|
47
48
|
const slope = raw.system === 'dwv-drain' ? measureDrainPathSlope(path) : null
|
|
49
|
+
const material = (raw.material as PipeMaterial) || 'pex-a'
|
|
50
|
+
const pipeSize = (raw.nominalSize as PipeNominalSize) || '1/2"'
|
|
51
|
+
const wsfu = typeof raw.wsfuLoad === 'number' ? raw.wsfuLoad : 0
|
|
52
|
+
let supplyHydraulics: ReturnType<typeof calculateSupplyHydraulics> | null = null
|
|
53
|
+
if (
|
|
54
|
+
(raw.system === 'cold-water' || raw.system === 'hot-water' || raw.system === 'hot-recirc') &&
|
|
55
|
+
wsfu > 0 &&
|
|
56
|
+
(material === 'pex-a' ||
|
|
57
|
+
material === 'pex-b' ||
|
|
58
|
+
material === 'copper-l' ||
|
|
59
|
+
material === 'copper-m' ||
|
|
60
|
+
material === 'cpvc')
|
|
61
|
+
) {
|
|
62
|
+
const flushType =
|
|
63
|
+
raw.system === 'cold-water' && occupancy === 'commercial' ? 'flushometer' : 'flush-tank'
|
|
64
|
+
const gpm = wsfuToGpm(wsfu, flushType)
|
|
65
|
+
supplyHydraulics = calculateSupplyHydraulics({
|
|
66
|
+
gpm,
|
|
67
|
+
size: pipeSize,
|
|
68
|
+
material,
|
|
69
|
+
isHot: raw.system === 'hot-water' || raw.system === 'hot-recirc',
|
|
70
|
+
lengthFt: Math.max(10, lengthFt),
|
|
71
|
+
})
|
|
72
|
+
}
|
|
48
73
|
const lvlId = resolveNodeLevelId(nodes, raw)
|
|
49
74
|
const walls = extractWallSegments(nodes, lvlId)
|
|
50
75
|
const bones = extractBonesPlumbingContext(nodes, lvlId)
|
|
51
76
|
const pens = computePipeFramingPenetrations({
|
|
52
77
|
pipeRunId: raw.id,
|
|
53
78
|
path,
|
|
54
|
-
pipeSize
|
|
55
|
-
material
|
|
79
|
+
pipeSize,
|
|
80
|
+
material,
|
|
56
81
|
walls,
|
|
57
82
|
bonesContext: bones,
|
|
58
83
|
})
|
|
59
|
-
return { lengthFt, slope, pens }
|
|
60
|
-
}, [nodes, raw])
|
|
84
|
+
return { lengthFt, slope, supplyHydraulics, pens }
|
|
85
|
+
}, [nodes, raw, occupancy])
|
|
61
86
|
|
|
62
87
|
if (!raw) return null
|
|
63
88
|
|
|
@@ -120,6 +145,13 @@ export default function PlumbingInspectorCard({ node }: { node?: AnyNode }) {
|
|
|
120
145
|
warn={pipeMetrics.slope.hasUphillSegment}
|
|
121
146
|
/>
|
|
122
147
|
)}
|
|
148
|
+
{pipeMetrics.supplyHydraulics && (
|
|
149
|
+
<Row
|
|
150
|
+
label="Supply Flow / Velocity"
|
|
151
|
+
value={`${pipeMetrics.supplyHydraulics.gpm} GPM · ${pipeMetrics.supplyHydraulics.velocityFps} ft/s`}
|
|
152
|
+
warn={!pipeMetrics.supplyHydraulics.velocityOk}
|
|
153
|
+
/>
|
|
154
|
+
)}
|
|
123
155
|
<Row label="Framing Penetrations" value={`${pipeMetrics.pens.length} stud/plate bore(s)`} />
|
|
124
156
|
{pipeMetrics.pens.length > 0 && (
|
|
125
157
|
<button type="button" onClick={() => openTab('penetrations')} style={linkBtnStyle}>
|
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
import { useEffect, useMemo, useRef, useState } from 'react'
|
|
9
9
|
import {
|
|
10
10
|
AmbientLight,
|
|
11
|
+
Box3,
|
|
11
12
|
type BufferGeometry,
|
|
12
13
|
Color,
|
|
13
14
|
DirectionalLight,
|
|
@@ -16,6 +17,7 @@ import {
|
|
|
16
17
|
type Object3D,
|
|
17
18
|
PerspectiveCamera,
|
|
18
19
|
Scene,
|
|
20
|
+
Vector3,
|
|
19
21
|
WebGLRenderer,
|
|
20
22
|
} from 'three'
|
|
21
23
|
import {
|
|
@@ -66,14 +68,15 @@ export default function ManifoldCutawayView({
|
|
|
66
68
|
manifoldKind: ManifoldKind
|
|
67
69
|
portCount: number
|
|
68
70
|
viewMode: ManifoldCutawayViewMode
|
|
69
|
-
ports
|
|
71
|
+
ports?: ReadonlyArray<ManifoldPortAssignment>
|
|
70
72
|
onChangeViewMode: (m: ManifoldCutawayViewMode) => void
|
|
71
73
|
}) {
|
|
72
74
|
const containerRef = useRef<HTMLDivElement | null>(null)
|
|
73
75
|
const ctxRef = useRef<CutawayContext | null>(null)
|
|
76
|
+
const draggingRef = useRef(false)
|
|
74
77
|
const [webglError, setWebglError] = useState<string | null>(null)
|
|
75
78
|
|
|
76
|
-
const portsKey = useMemo(() => JSON.stringify(ports), [ports])
|
|
79
|
+
const portsKey = useMemo(() => (ports === undefined ? '__demo__' : JSON.stringify(ports)), [ports])
|
|
77
80
|
const stablePorts = useMemo(() => ports, [portsKey])
|
|
78
81
|
|
|
79
82
|
// Effect 1: Create & persist WebGLRenderer / Scene / Camera across prop updates
|
|
@@ -102,6 +105,8 @@ export default function ManifoldCutawayView({
|
|
|
102
105
|
|
|
103
106
|
renderer.setSize(width, height)
|
|
104
107
|
renderer.setPixelRatio(Math.min(window.devicePixelRatio || 1, 2))
|
|
108
|
+
renderer.domElement.style.touchAction = 'none'
|
|
109
|
+
renderer.domElement.style.userSelect = 'none'
|
|
105
110
|
el.innerHTML = ''
|
|
106
111
|
el.appendChild(renderer.domElement)
|
|
107
112
|
|
|
@@ -119,25 +124,25 @@ export default function ManifoldCutawayView({
|
|
|
119
124
|
}
|
|
120
125
|
ctxRef.current = ctx
|
|
121
126
|
|
|
122
|
-
let dragging = false
|
|
123
127
|
let prevX = 0
|
|
124
128
|
|
|
125
129
|
const onDown = (e: PointerEvent) => {
|
|
126
|
-
|
|
130
|
+
draggingRef.current = true
|
|
127
131
|
prevX = e.clientX
|
|
128
132
|
}
|
|
129
133
|
const onMove = (e: PointerEvent) => {
|
|
130
|
-
if (!
|
|
134
|
+
if (!draggingRef.current || !ctx.model) return
|
|
131
135
|
ctx.rotY += (e.clientX - prevX) * 0.01
|
|
132
136
|
prevX = e.clientX
|
|
133
137
|
ctx.model.rotation.y = ctx.rotY
|
|
134
138
|
renderer.render(scene, camera)
|
|
135
139
|
}
|
|
136
140
|
const onUpOrCancel = () => {
|
|
137
|
-
|
|
141
|
+
draggingRef.current = false
|
|
138
142
|
}
|
|
139
143
|
|
|
140
144
|
renderer.domElement.addEventListener('pointerdown', onDown)
|
|
145
|
+
renderer.domElement.addEventListener('pointercancel', onUpOrCancel)
|
|
141
146
|
window.addEventListener('pointermove', onMove)
|
|
142
147
|
window.addEventListener('pointerup', onUpOrCancel)
|
|
143
148
|
window.addEventListener('pointercancel', onUpOrCancel)
|
|
@@ -156,7 +161,9 @@ export default function ManifoldCutawayView({
|
|
|
156
161
|
|
|
157
162
|
return () => {
|
|
158
163
|
resizeObserver?.disconnect()
|
|
164
|
+
draggingRef.current = false
|
|
159
165
|
renderer.domElement.removeEventListener('pointerdown', onDown)
|
|
166
|
+
renderer.domElement.removeEventListener('pointercancel', onUpOrCancel)
|
|
160
167
|
window.removeEventListener('pointermove', onMove)
|
|
161
168
|
window.removeEventListener('pointerup', onUpOrCancel)
|
|
162
169
|
window.removeEventListener('pointercancel', onUpOrCancel)
|
|
@@ -173,7 +180,7 @@ export default function ManifoldCutawayView({
|
|
|
173
180
|
}
|
|
174
181
|
}, [])
|
|
175
182
|
|
|
176
|
-
// Effect 2: Rebuild & swap ONLY the 3D manifold mesh group when parameters change
|
|
183
|
+
// Effect 2: Rebuild & swap ONLY the 3D manifold mesh group when parameters change, scaling camera radius via Box3
|
|
177
184
|
useEffect(() => {
|
|
178
185
|
const ctx = ctxRef.current
|
|
179
186
|
if (!ctx) return
|
|
@@ -188,8 +195,23 @@ export default function ManifoldCutawayView({
|
|
|
188
195
|
manifoldKind,
|
|
189
196
|
portCount,
|
|
190
197
|
viewMode,
|
|
191
|
-
ports: stablePorts,
|
|
198
|
+
...(stablePorts !== undefined ? { ports: stablePorts } : {}),
|
|
192
199
|
})
|
|
200
|
+
|
|
201
|
+
const box = new Box3().setFromObject(model)
|
|
202
|
+
const size = new Vector3()
|
|
203
|
+
const center = new Vector3()
|
|
204
|
+
box.getSize(size)
|
|
205
|
+
box.getCenter(center)
|
|
206
|
+
const fovRad = (ctx.camera.fov * Math.PI) / 180
|
|
207
|
+
const halfTan = Math.tan(fovRad / 2)
|
|
208
|
+
const aspect = Math.max(0.5, ctx.camera.aspect || 1.5)
|
|
209
|
+
const fitDistV = Math.max(0.35, size.y / 2) / halfTan
|
|
210
|
+
const fitDistH = Math.max(0.25, Math.hypot(size.x, size.z) / 2) / (halfTan * aspect)
|
|
211
|
+
const camRadius = Math.max(1.55, Math.max(fitDistV, fitDistH) * 1.22)
|
|
212
|
+
ctx.camera.position.set(center.x + camRadius * 0.16, center.y + camRadius * 0.06, center.z + camRadius)
|
|
213
|
+
ctx.camera.lookAt(center.x, center.y, center.z)
|
|
214
|
+
|
|
193
215
|
model.rotation.y = ctx.rotY
|
|
194
216
|
ctx.scene.add(model)
|
|
195
217
|
ctx.model = model
|
|
@@ -253,6 +275,9 @@ export default function ManifoldCutawayView({
|
|
|
253
275
|
) : (
|
|
254
276
|
<div
|
|
255
277
|
ref={containerRef}
|
|
278
|
+
onPointerCancel={() => {
|
|
279
|
+
draggingRef.current = false
|
|
280
|
+
}}
|
|
256
281
|
style={{
|
|
257
282
|
width: '100%',
|
|
258
283
|
height: 340,
|
|
@@ -260,6 +285,8 @@ export default function ManifoldCutawayView({
|
|
|
260
285
|
overflow: 'hidden',
|
|
261
286
|
border: '1px solid var(--border, rgba(255,255,255,0.16))',
|
|
262
287
|
cursor: 'grab',
|
|
288
|
+
touchAction: 'none',
|
|
289
|
+
userSelect: 'none',
|
|
263
290
|
}}
|
|
264
291
|
/>
|
|
265
292
|
)}
|
|
@@ -30,7 +30,7 @@ import { usePlumbingUi } from './store'
|
|
|
30
30
|
export const PLUMBING_SCHEDULE_VIEW_ID = 'krusch:plumbing:schedule'
|
|
31
31
|
|
|
32
32
|
function activeLevelOf(nodes: Readonly<Record<string, AnyNode>>, selectedLevelId: string | null): string | null {
|
|
33
|
-
if (selectedLevelId && nodes[selectedLevelId]) return selectedLevelId
|
|
33
|
+
if (selectedLevelId && nodes[selectedLevelId]?.type === 'level') return selectedLevelId
|
|
34
34
|
for (const n of Object.values(nodes)) {
|
|
35
35
|
if (n.type === 'level') return n.id
|
|
36
36
|
}
|
|
@@ -283,13 +283,14 @@ export default function PlumbingHostPanel() {
|
|
|
283
283
|
)
|
|
284
284
|
const hasDeletes = (outcome.changes?.delete?.length ?? 0) > 0
|
|
285
285
|
const hasCreates = (outcome.changes?.create?.length ?? 0) > 0
|
|
286
|
+
const subSlabXray = subSlabXrayActive || xrayFamily === 'other'
|
|
286
287
|
if (hasDeletes || hasCreates) {
|
|
287
288
|
runAsSingleSceneHistoryStep(useScene, () => {
|
|
288
289
|
if (hasDeletes) {
|
|
289
290
|
deleteNodes(outcome.changes!.delete as never)
|
|
290
291
|
}
|
|
291
292
|
if (hasCreates) {
|
|
292
|
-
const toCreate =
|
|
293
|
+
const toCreate = subSlabXray
|
|
293
294
|
? outcome.changes!.create!.map((item) => {
|
|
294
295
|
const n = item.node as unknown as Record<string, unknown>
|
|
295
296
|
if (
|
|
@@ -395,9 +396,10 @@ export default function PlumbingHostPanel() {
|
|
|
395
396
|
},
|
|
396
397
|
{ activeLevelId: levelId },
|
|
397
398
|
)
|
|
399
|
+
const subSlabXray = subSlabXrayActive || xrayFamily === 'other'
|
|
398
400
|
if (outcome.changes?.create && outcome.changes.create.length > 0) {
|
|
399
401
|
runAsSingleSceneHistoryStep(useScene, () => {
|
|
400
|
-
const toCreate =
|
|
402
|
+
const toCreate = subSlabXray
|
|
401
403
|
? outcome.changes!.create!.map((item) => {
|
|
402
404
|
const n = item.node as unknown as Record<string, unknown>
|
|
403
405
|
if (
|
package/src/ui/schedule-view.tsx
CHANGED
|
@@ -497,7 +497,7 @@ export default function PlumbingScheduleView() {
|
|
|
497
497
|
manifoldKind={((activeManifold?.manifoldKind as ManifoldKind) || 'pex-homerun')}
|
|
498
498
|
portCount={typeof activeManifold?.portCount === 'number' ? activeManifold.portCount : 12}
|
|
499
499
|
viewMode={manifoldViewMode}
|
|
500
|
-
ports={activeManifoldPorts}
|
|
500
|
+
ports={activeManifold ? activeManifoldPorts : undefined}
|
|
501
501
|
onChangeViewMode={setManifoldViewMode}
|
|
502
502
|
/>
|
|
503
503
|
</div>
|
package/src/ui/store.ts
CHANGED
|
@@ -11,7 +11,6 @@ import type {
|
|
|
11
11
|
CodeEdition,
|
|
12
12
|
FoundationType,
|
|
13
13
|
OccupancyType,
|
|
14
|
-
PlumbingSystem,
|
|
15
14
|
SupplyTopology,
|
|
16
15
|
} from '../ipc/tables'
|
|
17
16
|
|
|
@@ -41,7 +40,6 @@ type PlumbingUiState = {
|
|
|
41
40
|
activeTab: PlumbingScheduleTab
|
|
42
41
|
manifoldViewMode: ManifoldCutawayViewMode
|
|
43
42
|
selectedManifoldId: string | null
|
|
44
|
-
hiddenSystems: Readonly<Record<PlumbingSystem, boolean>>
|
|
45
43
|
setOccupancy: (v: OccupancyType) => void
|
|
46
44
|
setCodeEdition: (v: CodeEdition) => void
|
|
47
45
|
setSupplyTopology: (v: SupplyTopology) => void
|
|
@@ -61,7 +59,6 @@ type PlumbingUiState = {
|
|
|
61
59
|
setActiveTab: (v: PlumbingScheduleTab) => void
|
|
62
60
|
setManifoldViewMode: (v: ManifoldCutawayViewMode) => void
|
|
63
61
|
setSelectedManifoldId: (id: string | null) => void
|
|
64
|
-
toggleSystemVisibility: (sys: PlumbingSystem) => void
|
|
65
62
|
}
|
|
66
63
|
|
|
67
64
|
export const usePlumbingUi = create<PlumbingUiState>((set) => ({
|
|
@@ -78,16 +75,6 @@ export const usePlumbingUi = create<PlumbingUiState>((set) => ({
|
|
|
78
75
|
activeTab: 'fixtures',
|
|
79
76
|
manifoldViewMode: 'wet-wall-cutaway',
|
|
80
77
|
selectedManifoldId: null,
|
|
81
|
-
hiddenSystems: {
|
|
82
|
-
'cold-water': false,
|
|
83
|
-
'hot-water': false,
|
|
84
|
-
'hot-recirc': false,
|
|
85
|
-
'dwv-drain': false,
|
|
86
|
-
'dwv-vent': false,
|
|
87
|
-
'fuel-gas': false,
|
|
88
|
-
condensate: false,
|
|
89
|
-
'dryer-vent': false,
|
|
90
|
-
},
|
|
91
78
|
setOccupancy: (occupancy) => set({ occupancy }),
|
|
92
79
|
setCodeEdition: (codeEdition) => set({ codeEdition }),
|
|
93
80
|
setSupplyTopology: (supplyTopology) => set({ supplyTopology }),
|
|
@@ -108,8 +95,4 @@ export const usePlumbingUi = create<PlumbingUiState>((set) => ({
|
|
|
108
95
|
setActiveTab: (activeTab) => set({ activeTab }),
|
|
109
96
|
setManifoldViewMode: (manifoldViewMode) => set({ manifoldViewMode }),
|
|
110
97
|
setSelectedManifoldId: (selectedManifoldId) => set({ selectedManifoldId }),
|
|
111
|
-
toggleSystemVisibility: (sys) =>
|
|
112
|
-
set((s) => ({
|
|
113
|
-
hiddenSystems: { ...s.hiddenSystems, [sys]: !s.hiddenSystems[sys] },
|
|
114
|
-
})),
|
|
115
98
|
}))
|