@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
|
@@ -310,7 +310,7 @@ export type BonesPlumbingContext = {
|
|
|
310
310
|
/** Authoritative stud cavity depth in inches from Priority #1 `structural:assembly` (`5.5` for 2x6, `3.5` for 2x4). */
|
|
311
311
|
defaultStudDepthIn?: number
|
|
312
312
|
framingSystem: 'lumber' | 'lgs'
|
|
313
|
-
floorSystem?: 'dimensional' | 'tji-ijoist' | 'open-web-truss'
|
|
313
|
+
floorSystem?: 'dimensional' | 'tji-ijoist' | 'open-web-truss' | 'slab-on-grade'
|
|
314
314
|
wallRules: ReadonlyMap<string, BonesWallRule>
|
|
315
315
|
waterHeaterAnchor: BonesPlumbingServiceAnchor | null
|
|
316
316
|
waterEntryAnchor: BonesPlumbingServiceAnchor | null
|
|
@@ -416,7 +416,8 @@ export function extractBonesPlumbingContext(
|
|
|
416
416
|
const floorSystem =
|
|
417
417
|
structuralNode?.floorSystem === 'tji-ijoist' ||
|
|
418
418
|
structuralNode?.floorSystem === 'open-web-truss' ||
|
|
419
|
-
structuralNode?.floorSystem === 'dimensional'
|
|
419
|
+
structuralNode?.floorSystem === 'dimensional' ||
|
|
420
|
+
structuralNode?.floorSystem === 'slab-on-grade'
|
|
420
421
|
? structuralNode.floorSystem
|
|
421
422
|
: undefined
|
|
422
423
|
const wallRules = new Map<string, BonesWallRule>()
|
package/src/ipc/pricing.ts
CHANGED
|
@@ -3,6 +3,12 @@
|
|
|
3
3
|
* Framework-free: zero React, Three.js, or `@pascal-app/*` imports.
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
+
import {
|
|
7
|
+
type BomCostScope,
|
|
8
|
+
type PascalBomFragment,
|
|
9
|
+
createBomLine,
|
|
10
|
+
slugifyBomSku,
|
|
11
|
+
} from '@kruschdev/pascal-mep-kernel/bom'
|
|
6
12
|
import type { SceneNodeLike } from './framing-interop'
|
|
7
13
|
import { type PlumbingSchedule, buildPlumbingSchedule } from './schedule'
|
|
8
14
|
import {
|
|
@@ -471,3 +477,95 @@ export function formatPlumbingBomCsv(bom: PlumbingBomResult): string {
|
|
|
471
477
|
rows.push(['Summary', 'Grand Total', '', '', '', round2(bom.subtotalMaterialUsd + bom.markupUsd + bom.taxUsd).toFixed(2), bom.totalLaborHours.toFixed(2), bom.subtotalLaborUsd.toFixed(2), bom.grandTotalUsd.toFixed(2)].join(','))
|
|
472
478
|
return [header.join(','), ...rows].join('\n')
|
|
473
479
|
}
|
|
480
|
+
|
|
481
|
+
function classifyPlumbingBomLine(line: PlumbingBomLine): {
|
|
482
|
+
readonly costScope: BomCostScope
|
|
483
|
+
readonly csiMasterFormat?: string
|
|
484
|
+
readonly dedupeKey?: string
|
|
485
|
+
} {
|
|
486
|
+
const lower = line.item.toLowerCase()
|
|
487
|
+
if (line.category === 'Fixtures') {
|
|
488
|
+
if (/\b(?:rough-?in|carrier|flange|stub-?out)\b/.test(lower)) {
|
|
489
|
+
return { costScope: 'rough-in', csiMasterFormat: '22 41 00' }
|
|
490
|
+
}
|
|
491
|
+
if (lower.includes('water closet') || lower.includes('toilet')) {
|
|
492
|
+
return { costScope: 'allowance', csiMasterFormat: '22 41 13', dedupeKey: 'fixture:water-closet' }
|
|
493
|
+
}
|
|
494
|
+
if (lower.includes('lavatory')) {
|
|
495
|
+
return { costScope: 'allowance', csiMasterFormat: '22 41 16', dedupeKey: 'fixture:lavatory' }
|
|
496
|
+
}
|
|
497
|
+
if (lower.includes('kitchen sink')) {
|
|
498
|
+
return { costScope: 'allowance', csiMasterFormat: '22 41 16', dedupeKey: 'fixture:kitchen-sink' }
|
|
499
|
+
}
|
|
500
|
+
if (lower.includes('bathtub') || lower.includes('tub-shower') || lower.includes('tub / shower')) {
|
|
501
|
+
return { costScope: 'allowance', csiMasterFormat: '22 41 19', dedupeKey: 'fixture:bathtub' }
|
|
502
|
+
}
|
|
503
|
+
if (lower.includes('shower')) {
|
|
504
|
+
return { costScope: 'allowance', csiMasterFormat: '22 41 19', dedupeKey: 'fixture:shower' }
|
|
505
|
+
}
|
|
506
|
+
return { costScope: 'allowance', csiMasterFormat: '22 41 00' }
|
|
507
|
+
}
|
|
508
|
+
if (line.category === 'Equipment' || line.category === 'Manifolds') {
|
|
509
|
+
return { costScope: 'assembly' }
|
|
510
|
+
}
|
|
511
|
+
if (line.category === 'Fittings & Accessories') {
|
|
512
|
+
return { costScope: 'consumable' }
|
|
513
|
+
}
|
|
514
|
+
if (/\b(?:dwv|abs|pvc|drain|vent|waste|sanitary|cast\s*iron|no-hub)\b/.test(lower)) {
|
|
515
|
+
return { costScope: 'rough-in', csiMasterFormat: '22 13 16' }
|
|
516
|
+
}
|
|
517
|
+
return { costScope: 'rough-in', csiMasterFormat: '22 11 16' }
|
|
518
|
+
}
|
|
519
|
+
|
|
520
|
+
/**
|
|
521
|
+
* Convert a `PlumbingBomResult` into a canonical `@kruschdev/pascal-mep-kernel/bom` fragment (`pascal-bom/1.x`).
|
|
522
|
+
*/
|
|
523
|
+
export function toPlumbingPascalBom(
|
|
524
|
+
bom: PlumbingBomResult,
|
|
525
|
+
options: { readonly laborRateUsd?: number } = {},
|
|
526
|
+
): PascalBomFragment {
|
|
527
|
+
const effectiveLaborRate =
|
|
528
|
+
typeof options.laborRateUsd === 'number' && Number.isFinite(options.laborRateUsd)
|
|
529
|
+
? Math.max(0, options.laborRateUsd)
|
|
530
|
+
: 125
|
|
531
|
+
const lines = bom.lines.map((line) => {
|
|
532
|
+
const meta = classifyPlumbingBomLine(line)
|
|
533
|
+
return createBomLine({
|
|
534
|
+
sourcePlugin: 'pascal-plugin-plumbing',
|
|
535
|
+
trade: 'plumbing',
|
|
536
|
+
category: line.category,
|
|
537
|
+
costScope: meta.costScope,
|
|
538
|
+
...(meta.csiMasterFormat ? { csiMasterFormat: meta.csiMasterFormat } : {}),
|
|
539
|
+
...(meta.dedupeKey ? { dedupeKey: meta.dedupeKey } : {}),
|
|
540
|
+
sku: slugifyBomSku('PLB', line.item),
|
|
541
|
+
name: line.item,
|
|
542
|
+
quantity: line.quantity,
|
|
543
|
+
unit: line.unit,
|
|
544
|
+
unitMaterialUsd: line.unitMaterialUsd,
|
|
545
|
+
extendedMaterialUsd: line.materialUsd,
|
|
546
|
+
extendedLaborHours: line.laborHours,
|
|
547
|
+
laborRateUsd: effectiveLaborRate,
|
|
548
|
+
extendedLaborUsd: line.laborUsd,
|
|
549
|
+
})
|
|
550
|
+
})
|
|
551
|
+
|
|
552
|
+
return {
|
|
553
|
+
plugin: 'pascal-plugin-plumbing',
|
|
554
|
+
pluginVersion: '0.2.1',
|
|
555
|
+
laborIncluded: true,
|
|
556
|
+
lines,
|
|
557
|
+
}
|
|
558
|
+
}
|
|
559
|
+
|
|
560
|
+
export function buildPlumbingPascalBom(
|
|
561
|
+
nodes: Readonly<Record<string, SceneNodeLike>>,
|
|
562
|
+
options: PlumbingPricingOptions = {},
|
|
563
|
+
): PascalBomFragment {
|
|
564
|
+
const effectiveLaborRate =
|
|
565
|
+
typeof options.laborRateUsd === 'number' && Number.isFinite(options.laborRateUsd)
|
|
566
|
+
? Math.max(0, options.laborRateUsd)
|
|
567
|
+
: 125
|
|
568
|
+
return toPlumbingPascalBom(buildPlumbingBom(nodes, { ...options, laborRateUsd: effectiveLaborRate }), {
|
|
569
|
+
laborRateUsd: effectiveLaborRate,
|
|
570
|
+
})
|
|
571
|
+
}
|
package/src/ipc/routing.ts
CHANGED
|
@@ -34,7 +34,13 @@ import {
|
|
|
34
34
|
routeInLegalCavities,
|
|
35
35
|
segmentIntersectsAabb3,
|
|
36
36
|
} from '@kruschdev/pascal-mep-kernel'
|
|
37
|
-
import {
|
|
37
|
+
import {
|
|
38
|
+
type SceneNodeLike,
|
|
39
|
+
type Vec3,
|
|
40
|
+
belongsToLevel,
|
|
41
|
+
computePipeFramingPenetrations,
|
|
42
|
+
extractBonesPlumbingContext,
|
|
43
|
+
} from './framing-interop'
|
|
38
44
|
import { IPC_RULE_THRESHOLDS } from './rules'
|
|
39
45
|
import { getMinRequiredDrainSlopeInPerFt } from './sizing'
|
|
40
46
|
import {
|
|
@@ -319,10 +325,13 @@ export function classifyRoomName(
|
|
|
319
325
|
}
|
|
320
326
|
if (/\bwc\d*\b|\btoilettes?\b|\baseo\b/.test(s)) return 'half-bath'
|
|
321
327
|
if (/toilet/.test(s)) return 'bathroom'
|
|
322
|
-
if (/
|
|
328
|
+
if (/butler'?s?\s*pantry|wet\s*pantry|prep\s*pantry/.test(s)) return 'kitchen'
|
|
329
|
+
if (/\bkitchen\s+pantry\b/.test(s)) return 'other'
|
|
330
|
+
if (/kitchen|cuisine|cocina|cucina|\bkuche\b|\bkueche\b/.test(s)) return 'kitchen'
|
|
323
331
|
if (/laundry|mudroom|washer|buanderie|waschkuche|waschkueche|lavanderia|hauswirtschaftsraum/.test(s)) {
|
|
324
332
|
return 'laundry'
|
|
325
333
|
}
|
|
334
|
+
if (/pantry|closet|\bw\.?\s*i\.?\s*c\.?\b|walk[-\s]*in/.test(s)) return 'other'
|
|
326
335
|
if (/utility|mech|boiler|furnace|storage/.test(s)) return 'utility'
|
|
327
336
|
if (/garage|carport/.test(s)) return 'garage'
|
|
328
337
|
if (/bed|nursery|guest|\bchambre\b|schlafzimmer|dormitorio/.test(s)) return 'bedroom'
|
|
@@ -1287,11 +1296,13 @@ export function routeDwvDrainRun(params: {
|
|
|
1287
1296
|
const isLast = i === horizWaypoints.length - 1
|
|
1288
1297
|
if (!isLast && leg < 0.15) continue
|
|
1289
1298
|
curY -= leg * slopeRatio
|
|
1290
|
-
|
|
1291
|
-
|
|
1299
|
+
pts.push([wx, curY, wz])
|
|
1300
|
+
if (isLast && to[1] < curY - 0.008) {
|
|
1301
|
+
pts.push([wx, to[1], wz])
|
|
1302
|
+
curY = to[1]
|
|
1303
|
+
}
|
|
1292
1304
|
curX = wx
|
|
1293
1305
|
curZ = wz
|
|
1294
|
-
curY = y
|
|
1295
1306
|
}
|
|
1296
1307
|
return cleanPath(pts)
|
|
1297
1308
|
}
|
|
@@ -1541,6 +1552,31 @@ export function routeVentRun(params: {
|
|
|
1541
1552
|
return cleanPath(pts)
|
|
1542
1553
|
}
|
|
1543
1554
|
|
|
1555
|
+
const ventWalls =
|
|
1556
|
+
nominalSize && cavityContext?.nodes
|
|
1557
|
+
? extractWallSegments(cavityContext.nodes, cavityContext.levelId ?? null)
|
|
1558
|
+
: []
|
|
1559
|
+
const ventBones =
|
|
1560
|
+
ventWalls.length > 0 && cavityContext?.nodes
|
|
1561
|
+
? extractBonesPlumbingContext(cavityContext.nodes, cavityContext.levelId ?? null)
|
|
1562
|
+
: null
|
|
1563
|
+
const countIllegalStudBores = (cand: ReadonlyArray<Vec3>): number => {
|
|
1564
|
+
if (!nominalSize || ventWalls.length === 0) return 0
|
|
1565
|
+
const pens = computePipeFramingPenetrations({
|
|
1566
|
+
pipeRunId: 'vent_probe',
|
|
1567
|
+
path: cand,
|
|
1568
|
+
pipeSize: nominalSize,
|
|
1569
|
+
material,
|
|
1570
|
+
walls: ventWalls,
|
|
1571
|
+
bonesContext: ventBones,
|
|
1572
|
+
})
|
|
1573
|
+
let bad = 0
|
|
1574
|
+
for (const p of pens) {
|
|
1575
|
+
if (p.memberKind === 'stud' && !p.codeCompliant) bad += 1
|
|
1576
|
+
}
|
|
1577
|
+
return bad
|
|
1578
|
+
}
|
|
1579
|
+
|
|
1544
1580
|
const primary = buildVentCandidate([
|
|
1545
1581
|
[stackPoint[0], from[2]],
|
|
1546
1582
|
[stackPoint[0], stackPoint[1]],
|
|
@@ -1550,6 +1586,7 @@ export function routeVentRun(params: {
|
|
|
1550
1586
|
let bestBoundsViolation =
|
|
1551
1587
|
exceedsEnvelopeXZ(primary, env) || exceedsConcaveFootprint(primary, cavityContext, checkFootprint)
|
|
1552
1588
|
let bestRoofViolation = exceedsRoofPlane(primary, pipeRadiusM, maxRoofYAt)
|
|
1589
|
+
let bestStudBores = countIllegalStudBores(primary)
|
|
1553
1590
|
let bestTieInY = tieInHeightM
|
|
1554
1591
|
let detoured = false
|
|
1555
1592
|
|
|
@@ -1598,13 +1635,17 @@ export function routeVentRun(params: {
|
|
|
1598
1635
|
!exceedsEnvelopeXZ(cand, wallEnv) &&
|
|
1599
1636
|
!exceedsConcaveFootprint(cand, cavityContext, checkFootprint) &&
|
|
1600
1637
|
!exceedsRoofPlane(cand, pipeRadiusM, maxRoofYAt) &&
|
|
1638
|
+
countIllegalStudBores(cand) === 0 &&
|
|
1601
1639
|
detectPlumbingClashes(cand, obstacles, pipeRadiusM).length === 0
|
|
1602
1640
|
) {
|
|
1603
|
-
if (bestClashes.length > 0 || bestBoundsViolation || bestRoofViolation
|
|
1641
|
+
if (bestClashes.length > 0 || bestBoundsViolation || bestRoofViolation || bestStudBores > 0) {
|
|
1642
|
+
detoured = true
|
|
1643
|
+
}
|
|
1604
1644
|
bestPath = cand
|
|
1605
1645
|
bestClashes = []
|
|
1606
1646
|
bestBoundsViolation = false
|
|
1607
1647
|
bestRoofViolation = false
|
|
1648
|
+
bestStudBores = 0
|
|
1608
1649
|
bestTieInY = cand[cand.length - 1]![1]
|
|
1609
1650
|
adoptedWallVent = true
|
|
1610
1651
|
break
|
|
@@ -1618,7 +1659,7 @@ export function routeVentRun(params: {
|
|
|
1618
1659
|
buildingBounds && hasCavityScene(cavityContext)
|
|
1619
1660
|
? resolveAllowedEnvelope(buildingBounds, from, stackPoint, -0.05)
|
|
1620
1661
|
: env
|
|
1621
|
-
if (bestClashes.length > 0 || bestBoundsViolation || bestRoofViolation) {
|
|
1662
|
+
if (bestClashes.length > 0 || bestBoundsViolation || bestRoofViolation || bestStudBores > 0) {
|
|
1622
1663
|
const tryVent = (cand: Vec3[], tieY: number): boolean => {
|
|
1623
1664
|
const boundsViol =
|
|
1624
1665
|
exceedsEnvelopeXZ(cand, ventDetourEnv) || exceedsConcaveFootprint(cand, cavityContext, checkFootprint)
|
|
@@ -1626,19 +1667,34 @@ export function routeVentRun(params: {
|
|
|
1626
1667
|
if (boundsViol && !bestBoundsViolation) return false
|
|
1627
1668
|
if (roofViol && !bestRoofViolation && boundsViol === bestBoundsViolation) return false
|
|
1628
1669
|
const c = detectPlumbingClashes(cand, obstacles, pipeRadiusM)
|
|
1670
|
+
if (
|
|
1671
|
+
boundsViol === bestBoundsViolation &&
|
|
1672
|
+
roofViol === bestRoofViolation &&
|
|
1673
|
+
c.length > bestClashes.length
|
|
1674
|
+
) {
|
|
1675
|
+
return false
|
|
1676
|
+
}
|
|
1677
|
+
const studBores = countIllegalStudBores(cand)
|
|
1629
1678
|
const better =
|
|
1630
1679
|
(bestBoundsViolation && !boundsViol) ||
|
|
1631
1680
|
(boundsViol === bestBoundsViolation && bestRoofViolation && !roofViol) ||
|
|
1632
|
-
(boundsViol === bestBoundsViolation &&
|
|
1681
|
+
(boundsViol === bestBoundsViolation &&
|
|
1682
|
+
roofViol === bestRoofViolation &&
|
|
1683
|
+
c.length < bestClashes.length) ||
|
|
1684
|
+
(boundsViol === bestBoundsViolation &&
|
|
1685
|
+
roofViol === bestRoofViolation &&
|
|
1686
|
+
c.length === bestClashes.length &&
|
|
1687
|
+
studBores < bestStudBores)
|
|
1633
1688
|
if (better) {
|
|
1634
1689
|
bestPath = cand
|
|
1635
1690
|
bestClashes = c
|
|
1636
1691
|
bestBoundsViolation = boundsViol
|
|
1637
1692
|
bestRoofViolation = roofViol
|
|
1693
|
+
bestStudBores = studBores
|
|
1638
1694
|
bestTieInY = tieY
|
|
1639
1695
|
detoured = true
|
|
1640
1696
|
}
|
|
1641
|
-
return bestClashes.length === 0 && !bestBoundsViolation && !bestRoofViolation
|
|
1697
|
+
return bestClashes.length === 0 && !bestBoundsViolation && !bestRoofViolation && bestStudBores === 0
|
|
1642
1698
|
}
|
|
1643
1699
|
|
|
1644
1700
|
const edgePad = pipeRadiusM + 0.07
|
|
@@ -1666,6 +1722,11 @@ export function routeVentRun(params: {
|
|
|
1666
1722
|
if (!Number.isFinite(y) || y < minFloorY || y > maxAtticTieY) return
|
|
1667
1723
|
if (!tieYs.some((v) => Math.abs(v - y) < 0.02)) tieYs.push(y)
|
|
1668
1724
|
}
|
|
1725
|
+
if (bestStudBores > 0) {
|
|
1726
|
+
const minVentWallH = ventWalls.length > 0 ? Math.min(...ventWalls.map((w) => w.heightM)) : ceilingHeightM
|
|
1727
|
+
pushTieY(minVentWallH - 0.055)
|
|
1728
|
+
pushTieY(ceilingHeightM - 0.055)
|
|
1729
|
+
}
|
|
1669
1730
|
if (elevatedHits.length > 0) {
|
|
1670
1731
|
const aboveHit = Math.max(...elevatedHits.map((o) => o.box.maxY)) + pipeRadiusM + 0.05
|
|
1671
1732
|
const belowHit = Math.min(...elevatedHits.map((o) => o.box.minY)) - pipeRadiusM - 0.05
|
|
@@ -1720,6 +1781,69 @@ export function routeVentRun(params: {
|
|
|
1720
1781
|
const candidates: Array<Array<readonly [number, number]>> = [
|
|
1721
1782
|
[[stackPoint[0], sz], [stackPoint[0], stackPoint[1]]],
|
|
1722
1783
|
[[sx, stackPoint[1]], [stackPoint[0], stackPoint[1]]],
|
|
1784
|
+
[[stackPoint[0] + 0.16, sz], [stackPoint[0] + 0.16, stackPoint[1]], [stackPoint[0], stackPoint[1]]],
|
|
1785
|
+
[[stackPoint[0] - 0.16, sz], [stackPoint[0] - 0.16, stackPoint[1]], [stackPoint[0], stackPoint[1]]],
|
|
1786
|
+
[[sx, sz + 0.16], [stackPoint[0] + 0.16, sz + 0.16], [stackPoint[0] + 0.16, stackPoint[1]], [stackPoint[0], stackPoint[1]]],
|
|
1787
|
+
[[sx, sz - 0.16], [stackPoint[0] - 0.16, sz - 0.16], [stackPoint[0] - 0.16, stackPoint[1]], [stackPoint[0], stackPoint[1]]],
|
|
1788
|
+
[[sx, sz + 0.16], [stackPoint[0] - 0.16, sz + 0.16], [stackPoint[0] - 0.16, stackPoint[1]], [stackPoint[0], stackPoint[1]]],
|
|
1789
|
+
[[sx, sz - 0.16], [stackPoint[0] + 0.16, sz - 0.16], [stackPoint[0] + 0.16, stackPoint[1]], [stackPoint[0], stackPoint[1]]],
|
|
1790
|
+
// Corner-stack open-stud-bay entry: step ±0.16m off both axes so final 16cm stub stays inside a single stud bay away from corner walls
|
|
1791
|
+
...([0.16, -0.16] as const).flatMap((ox) =>
|
|
1792
|
+
([0.16, -0.16] as const).flatMap((oz): Array<Array<readonly [number, number]>> => [
|
|
1793
|
+
[
|
|
1794
|
+
[stackPoint[0] + ox, sz],
|
|
1795
|
+
[stackPoint[0] + ox, stackPoint[1] + oz],
|
|
1796
|
+
[stackPoint[0], stackPoint[1] + oz],
|
|
1797
|
+
[stackPoint[0], stackPoint[1]],
|
|
1798
|
+
],
|
|
1799
|
+
[
|
|
1800
|
+
[sx, stackPoint[1] + oz],
|
|
1801
|
+
[stackPoint[0] + ox, stackPoint[1] + oz],
|
|
1802
|
+
[stackPoint[0] + ox, stackPoint[1]],
|
|
1803
|
+
[stackPoint[0], stackPoint[1]],
|
|
1804
|
+
],
|
|
1805
|
+
[
|
|
1806
|
+
[sx, sz + oz],
|
|
1807
|
+
[stackPoint[0] + ox, sz + oz],
|
|
1808
|
+
[stackPoint[0] + ox, stackPoint[1] + oz],
|
|
1809
|
+
[stackPoint[0], stackPoint[1] + oz],
|
|
1810
|
+
[stackPoint[0], stackPoint[1]],
|
|
1811
|
+
],
|
|
1812
|
+
[
|
|
1813
|
+
[sx, sz + oz],
|
|
1814
|
+
[stackPoint[0] + ox, sz + oz],
|
|
1815
|
+
[stackPoint[0] + ox, stackPoint[1]],
|
|
1816
|
+
[stackPoint[0], stackPoint[1]],
|
|
1817
|
+
],
|
|
1818
|
+
[
|
|
1819
|
+
[sx + ox, sz],
|
|
1820
|
+
[sx + ox, stackPoint[1] + oz],
|
|
1821
|
+
[stackPoint[0] + ox, stackPoint[1] + oz],
|
|
1822
|
+
[stackPoint[0] + ox, stackPoint[1]],
|
|
1823
|
+
[stackPoint[0], stackPoint[1]],
|
|
1824
|
+
],
|
|
1825
|
+
[
|
|
1826
|
+
[sx + ox, sz],
|
|
1827
|
+
[sx + ox, stackPoint[1] + oz],
|
|
1828
|
+
[stackPoint[0], stackPoint[1] + oz],
|
|
1829
|
+
[stackPoint[0], stackPoint[1]],
|
|
1830
|
+
],
|
|
1831
|
+
[
|
|
1832
|
+
[sx + ox, sz + oz],
|
|
1833
|
+
[stackPoint[0] + ox, sz + oz],
|
|
1834
|
+
[stackPoint[0] + ox, stackPoint[1] + oz],
|
|
1835
|
+
[stackPoint[0], stackPoint[1] + oz],
|
|
1836
|
+
[stackPoint[0], stackPoint[1]],
|
|
1837
|
+
],
|
|
1838
|
+
[
|
|
1839
|
+
[sx + ox, sz + oz],
|
|
1840
|
+
[sx + ox, stackPoint[1] + oz],
|
|
1841
|
+
[stackPoint[0] + ox, stackPoint[1] + oz],
|
|
1842
|
+
[stackPoint[0] + ox, stackPoint[1]],
|
|
1843
|
+
[stackPoint[0], stackPoint[1]],
|
|
1844
|
+
],
|
|
1845
|
+
]),
|
|
1846
|
+
),
|
|
1723
1847
|
[[stackPoint[0], sz + 0.55], [stackPoint[0], stackPoint[1]]],
|
|
1724
1848
|
[[stackPoint[0], sz - 0.55], [stackPoint[0], stackPoint[1]]],
|
|
1725
1849
|
[[sx + 0.55, stackPoint[1]], [stackPoint[0], stackPoint[1]]],
|
|
@@ -1732,13 +1856,16 @@ export function routeVentRun(params: {
|
|
|
1732
1856
|
for (const wp of candidates) {
|
|
1733
1857
|
if (tryVent(buildVentCandidate(wp, tieY, jog), tieY)) break
|
|
1734
1858
|
}
|
|
1735
|
-
if (bestClashes.length === 0 && !bestBoundsViolation && !bestRoofViolation) break
|
|
1859
|
+
if (bestClashes.length === 0 && !bestBoundsViolation && !bestRoofViolation && bestStudBores === 0) break
|
|
1736
1860
|
}
|
|
1737
|
-
if (bestClashes.length === 0 && !bestBoundsViolation && !bestRoofViolation) break
|
|
1861
|
+
if (bestClashes.length === 0 && !bestBoundsViolation && !bestRoofViolation && bestStudBores === 0) break
|
|
1738
1862
|
}
|
|
1739
1863
|
|
|
1740
1864
|
// Layer 2 — Legal-Space-First Cavity Rescue (non-descending-vent, IPC 905.5 & 905.2)
|
|
1741
|
-
if (
|
|
1865
|
+
if (
|
|
1866
|
+
(bestClashes.length > 0 || bestBoundsViolation || bestRoofViolation || bestStudBores > 0) &&
|
|
1867
|
+
hasCavityScene(cavityContext)
|
|
1868
|
+
) {
|
|
1742
1869
|
const cavityTargetY =
|
|
1743
1870
|
cavityContext?.graph &&
|
|
1744
1871
|
(!maxRoofYAt ||
|
|
@@ -1868,12 +1995,15 @@ export function routePressurizedPipeRun(params: {
|
|
|
1868
1995
|
return cleanPath(pts)
|
|
1869
1996
|
}
|
|
1870
1997
|
|
|
1871
|
-
const
|
|
1872
|
-
|
|
1873
|
-
|
|
1874
|
-
|
|
1875
|
-
|
|
1876
|
-
|
|
1998
|
+
const skipMidWallLargeSnap = pipeRadiusM > 0.035 && routingPlaneY > 0.05 && routingPlaneY < 1.8
|
|
1999
|
+
const fromWallSnap =
|
|
2000
|
+
hasCavityScene(cavityContext) && !skipMidWallLargeSnap
|
|
2001
|
+
? resolveBackingWallSnap(from, cavityContext, obstacles, pipeRadiusM, buildingBounds, checkFootprint, 1.05)
|
|
2002
|
+
: null
|
|
2003
|
+
const toWallSnap =
|
|
2004
|
+
hasCavityScene(cavityContext) && !skipMidWallLargeSnap
|
|
2005
|
+
? resolveBackingWallSnap(to, cavityContext, obstacles, pipeRadiusM, buildingBounds, checkFootprint, 1.05)
|
|
2006
|
+
: null
|
|
1877
2007
|
const wallFromJog: readonly [number, number] | undefined = fromWallSnap
|
|
1878
2008
|
? [fromWallSnap[0], fromWallSnap[2]]
|
|
1879
2009
|
: undefined
|
package/src/ipc/schedule.ts
CHANGED
|
@@ -12,6 +12,8 @@ import {
|
|
|
12
12
|
} from './framing-interop'
|
|
13
13
|
import { polylineLengthM } from './routing'
|
|
14
14
|
import {
|
|
15
|
+
type FuelGasGraphSegment,
|
|
16
|
+
computeFuelGasDevelopedLengths,
|
|
15
17
|
sizeBuildingDrain,
|
|
16
18
|
sizeFuelGasPipe,
|
|
17
19
|
sizeSupplyPipe,
|
|
@@ -115,11 +117,19 @@ export function resolveNodeElectricalDemand(n: SceneNodeLike): ElectricalPowerDe
|
|
|
115
117
|
const raw = n.electricalDemand as Partial<ElectricalPowerDemand> | undefined
|
|
116
118
|
|
|
117
119
|
if (n.type === 'plumbing:equipment' && typeof n.equipmentKind === 'string') {
|
|
118
|
-
const
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
120
|
+
const kind = n.equipmentKind as EquipmentKind
|
|
121
|
+
const base = getEquipmentElectricalDemand(kind)
|
|
122
|
+
if (!base) return null
|
|
123
|
+
const rawWatts = typeof n.watts === 'number' && n.watts > 0 ? n.watts : undefined
|
|
124
|
+
const withRawWatts = rawWatts ? getEquipmentElectricalDemand(kind, rawWatts) : base
|
|
125
|
+
const labelMatchesKind =
|
|
126
|
+
typeof raw?.label === 'string' &&
|
|
127
|
+
(raw.label === base.label || raw.label === withRawWatts?.label)
|
|
128
|
+
const isStaleWatts =
|
|
129
|
+
rawWatts !== undefined &&
|
|
130
|
+
!labelMatchesKind &&
|
|
131
|
+
(rawWatts === raw?.loadVa || rawWatts === 4500)
|
|
132
|
+
const expected = isStaleWatts ? base : (withRawWatts ?? base)
|
|
123
133
|
if (
|
|
124
134
|
raw &&
|
|
125
135
|
typeof raw === 'object' &&
|
|
@@ -346,7 +356,10 @@ export function buildPlumbingSchedule(
|
|
|
346
356
|
: 'lavatory') as FixtureKind
|
|
347
357
|
const spec = FIXTURE_SPECS[kind]
|
|
348
358
|
const ratedWsfu = getFixtureWsfu(kind, occupancy)
|
|
349
|
-
const dfu =
|
|
359
|
+
const dfu =
|
|
360
|
+
typeof n.dfu === 'number' && n.dfu !== spec.dfuIpc && n.dfu !== spec.dfuUpc
|
|
361
|
+
? n.dfu
|
|
362
|
+
: getFixtureDfu(kind, codeEdition)
|
|
350
363
|
const wsfuCold =
|
|
351
364
|
occupancy === 'commercial'
|
|
352
365
|
? Math.max(ratedWsfu.cold, typeof n.wsfuCold === 'number' ? n.wsfuCold : 0)
|
|
@@ -359,12 +372,16 @@ export function buildPlumbingSchedule(
|
|
|
359
372
|
: typeof n.wsfuHot === 'number'
|
|
360
373
|
? n.wsfuHot
|
|
361
374
|
: ratedWsfu.hot
|
|
375
|
+
const hasCustomBranchWsfu = wsfuCold !== ratedWsfu.cold || wsfuHot !== ratedWsfu.hot
|
|
376
|
+
const hasDefaultTotalWsfu = n.wsfuTotal === spec.wsfuTotal || n.wsfuTotal === ratedWsfu.total
|
|
362
377
|
const wsfuTotal =
|
|
363
|
-
|
|
364
|
-
?
|
|
365
|
-
:
|
|
366
|
-
? n.wsfuTotal
|
|
367
|
-
:
|
|
378
|
+
hasCustomBranchWsfu && hasDefaultTotalWsfu
|
|
379
|
+
? round2(wsfuCold + wsfuHot)
|
|
380
|
+
: occupancy === 'commercial'
|
|
381
|
+
? Math.max(ratedWsfu.total, typeof n.wsfuTotal === 'number' ? n.wsfuTotal : 0)
|
|
382
|
+
: typeof n.wsfuTotal === 'number'
|
|
383
|
+
? n.wsfuTotal
|
|
384
|
+
: ratedWsfu.total
|
|
368
385
|
|
|
369
386
|
totalDfu += dfu
|
|
370
387
|
totalWsfuCold += wsfuCold
|
|
@@ -397,7 +414,7 @@ export function buildPlumbingSchedule(
|
|
|
397
414
|
// Group pipe runs by (system, material, nominalSize)
|
|
398
415
|
const pipeMap = new Map<string, PipeSystemSummaryRow>()
|
|
399
416
|
const supplyMatCounts = new Map<'pex-a' | 'pex-b' | 'copper-l' | 'copper-m' | 'cpvc', number>()
|
|
400
|
-
|
|
417
|
+
const gasGraphSegments: FuelGasGraphSegment[] = []
|
|
401
418
|
let applianceGasBtuh = 0
|
|
402
419
|
let maxPipeGasBtuh = 0
|
|
403
420
|
const countedGasTargetIds = new Set<string>()
|
|
@@ -473,7 +490,12 @@ export function buildPlumbingSchedule(
|
|
|
473
490
|
}
|
|
474
491
|
|
|
475
492
|
if (system === 'fuel-gas') {
|
|
476
|
-
|
|
493
|
+
gasGraphSegments.push({
|
|
494
|
+
id: n.id,
|
|
495
|
+
lengthFt,
|
|
496
|
+
...(typeof n.sourceNodeId === 'string' && n.sourceNodeId ? { sourceNodeId: n.sourceNodeId } : {}),
|
|
497
|
+
...(typeof n.targetNodeId === 'string' && n.targetNodeId ? { targetNodeId: n.targetNodeId } : {}),
|
|
498
|
+
})
|
|
477
499
|
if (material === 'csst') hasCsstGas = true
|
|
478
500
|
if (typeof n.gasBtuh === 'number' && n.gasBtuh > 0) {
|
|
479
501
|
if (n.gasBtuh > maxPipeGasBtuh) maxPipeGasBtuh = n.gasBtuh
|
|
@@ -553,7 +575,8 @@ export function buildPlumbingSchedule(
|
|
|
553
575
|
peakGpm: totalWsfuHot > 0 ? hotPeakDemandGpm : totalWsfu > 0 ? 0 : undefined,
|
|
554
576
|
})
|
|
555
577
|
|
|
556
|
-
// Conservative IFGC sizing:
|
|
578
|
+
// Conservative IFGC 402.4.1 sizing: traverse connected gas networks for root-to-most-remote-outlet developed length
|
|
579
|
+
const longestGasFt = computeFuelGasDevelopedLengths(gasGraphSegments).maxDevelopedLengthFt
|
|
557
580
|
const detectedGasMaterial: 'black-iron' | 'csst' = hasCsstGas ? 'csst' : 'black-iron'
|
|
558
581
|
const gasSizing =
|
|
559
582
|
totalGasBtuh > 0
|
package/src/ipc/sizing.ts
CHANGED
|
@@ -496,6 +496,146 @@ export function sizeFuelGasPipe(params: {
|
|
|
496
496
|
}
|
|
497
497
|
}
|
|
498
498
|
|
|
499
|
+
export type FuelGasGraphSegment = {
|
|
500
|
+
id: string
|
|
501
|
+
lengthFt: number
|
|
502
|
+
sourceNodeId?: string
|
|
503
|
+
targetNodeId?: string
|
|
504
|
+
}
|
|
505
|
+
|
|
506
|
+
/**
|
|
507
|
+
* IFGC 402.4.1 (Longest Length Method): traverse connected `fuel-gas` `sourceNodeId -> targetNodeId`
|
|
508
|
+
* graphs (with cycle guard) to compute each connected gas network's root-to-most-remote-outlet
|
|
509
|
+
* developed length in feet.
|
|
510
|
+
*/
|
|
511
|
+
export function computeFuelGasDevelopedLengths(
|
|
512
|
+
segments: ReadonlyArray<FuelGasGraphSegment>,
|
|
513
|
+
): {
|
|
514
|
+
byRunId: Map<string, number>
|
|
515
|
+
maxDevelopedLengthFt: number
|
|
516
|
+
} {
|
|
517
|
+
const byRunId = new Map<string, number>()
|
|
518
|
+
if (segments.length === 0) return { byRunId, maxDevelopedLengthFt: 0 }
|
|
519
|
+
|
|
520
|
+
const segById = new Map<string, FuelGasGraphSegment>()
|
|
521
|
+
const bySourceNode = new Map<string, string[]>()
|
|
522
|
+
const byTargetNode = new Map<string, string[]>()
|
|
523
|
+
const downstream = new Map<string, Set<string>>()
|
|
524
|
+
const undirected = new Map<string, Set<string>>()
|
|
525
|
+
|
|
526
|
+
const linkUndirected = (a: string, b: string) => {
|
|
527
|
+
if (a === b) return
|
|
528
|
+
undirected.get(a)?.add(b)
|
|
529
|
+
undirected.get(b)?.add(a)
|
|
530
|
+
}
|
|
531
|
+
|
|
532
|
+
for (const seg of segments) {
|
|
533
|
+
segById.set(seg.id, seg)
|
|
534
|
+
downstream.set(seg.id, new Set())
|
|
535
|
+
undirected.set(seg.id, new Set())
|
|
536
|
+
if (seg.sourceNodeId) {
|
|
537
|
+
const list = bySourceNode.get(seg.sourceNodeId)
|
|
538
|
+
if (list) list.push(seg.id)
|
|
539
|
+
else bySourceNode.set(seg.sourceNodeId, [seg.id])
|
|
540
|
+
}
|
|
541
|
+
if (seg.targetNodeId) {
|
|
542
|
+
const list = byTargetNode.get(seg.targetNodeId)
|
|
543
|
+
if (list) list.push(seg.id)
|
|
544
|
+
else byTargetNode.set(seg.targetNodeId, [seg.id])
|
|
545
|
+
}
|
|
546
|
+
}
|
|
547
|
+
|
|
548
|
+
// Group runs sharing a common supply root/manifold or common junction into the same connected network
|
|
549
|
+
for (const ids of bySourceNode.values()) {
|
|
550
|
+
for (let i = 1; i < ids.length; i++) linkUndirected(ids[0]!, ids[i]!)
|
|
551
|
+
}
|
|
552
|
+
for (const ids of byTargetNode.values()) {
|
|
553
|
+
for (let i = 1; i < ids.length; i++) linkUndirected(ids[0]!, ids[i]!)
|
|
554
|
+
}
|
|
555
|
+
|
|
556
|
+
// Build directed series edges (node-mediated `a.targetNodeId === b.sourceNodeId` and direct pipe-to-pipe)
|
|
557
|
+
for (const a of segments) {
|
|
558
|
+
const out = downstream.get(a.id)!
|
|
559
|
+
if (a.targetNodeId) {
|
|
560
|
+
if (segById.has(a.targetNodeId) && a.targetNodeId !== a.id) {
|
|
561
|
+
out.add(a.targetNodeId)
|
|
562
|
+
linkUndirected(a.id, a.targetNodeId)
|
|
563
|
+
}
|
|
564
|
+
for (const nextId of bySourceNode.get(a.targetNodeId) ?? []) {
|
|
565
|
+
if (nextId !== a.id) {
|
|
566
|
+
out.add(nextId)
|
|
567
|
+
linkUndirected(a.id, nextId)
|
|
568
|
+
}
|
|
569
|
+
}
|
|
570
|
+
}
|
|
571
|
+
if (a.sourceNodeId && segById.has(a.sourceNodeId) && a.sourceNodeId !== a.id) {
|
|
572
|
+
downstream.get(a.sourceNodeId)!.add(a.id)
|
|
573
|
+
linkUndirected(a.sourceNodeId, a.id)
|
|
574
|
+
}
|
|
575
|
+
}
|
|
576
|
+
|
|
577
|
+
const dagMemo = new Map<string, number>()
|
|
578
|
+
const longestFrom = (currId: string, visited: Set<string>): { len: number; hitCycle: boolean } => {
|
|
579
|
+
if (visited.size === 0 && dagMemo.has(currId)) {
|
|
580
|
+
return { len: dagMemo.get(currId)!, hitCycle: false }
|
|
581
|
+
}
|
|
582
|
+
visited.add(currId)
|
|
583
|
+
const seg = segById.get(currId)!
|
|
584
|
+
const ownLen = Number.isFinite(seg.lengthFt) && seg.lengthFt > 0 ? seg.lengthFt : 0
|
|
585
|
+
let maxChild = 0
|
|
586
|
+
let hitCycle = false
|
|
587
|
+
for (const nextId of downstream.get(currId) ?? []) {
|
|
588
|
+
if (visited.has(nextId)) {
|
|
589
|
+
hitCycle = true
|
|
590
|
+
continue
|
|
591
|
+
}
|
|
592
|
+
if (!hitCycle && dagMemo.has(nextId)) {
|
|
593
|
+
const cached = dagMemo.get(nextId)!
|
|
594
|
+
if (cached > maxChild) maxChild = cached
|
|
595
|
+
continue
|
|
596
|
+
}
|
|
597
|
+
const sub = longestFrom(nextId, visited)
|
|
598
|
+
if (sub.hitCycle) hitCycle = true
|
|
599
|
+
if (sub.len > maxChild) maxChild = sub.len
|
|
600
|
+
}
|
|
601
|
+
visited.delete(currId)
|
|
602
|
+
const total = ownLen + maxChild
|
|
603
|
+
if (!hitCycle) dagMemo.set(currId, total)
|
|
604
|
+
return { len: total, hitCycle }
|
|
605
|
+
}
|
|
606
|
+
|
|
607
|
+
const seenComp = new Set<string>()
|
|
608
|
+
let maxDevelopedLengthFt = 0
|
|
609
|
+
for (const seg of segments) {
|
|
610
|
+
if (seenComp.has(seg.id)) continue
|
|
611
|
+
const comp: string[] = []
|
|
612
|
+
const queue: string[] = [seg.id]
|
|
613
|
+
seenComp.add(seg.id)
|
|
614
|
+
while (queue.length > 0) {
|
|
615
|
+
const id = queue.pop()!
|
|
616
|
+
comp.push(id)
|
|
617
|
+
for (const nb of undirected.get(id) ?? []) {
|
|
618
|
+
if (!seenComp.has(nb)) {
|
|
619
|
+
seenComp.add(nb)
|
|
620
|
+
queue.push(nb)
|
|
621
|
+
}
|
|
622
|
+
}
|
|
623
|
+
}
|
|
624
|
+
|
|
625
|
+
let compLongest = 0
|
|
626
|
+
for (const id of comp) {
|
|
627
|
+
const { len } = longestFrom(id, new Set())
|
|
628
|
+
if (len > compLongest) compLongest = len
|
|
629
|
+
}
|
|
630
|
+
for (const id of comp) {
|
|
631
|
+
byRunId.set(id, compLongest)
|
|
632
|
+
}
|
|
633
|
+
if (compLongest > maxDevelopedLengthFt) maxDevelopedLengthFt = compLongest
|
|
634
|
+
}
|
|
635
|
+
|
|
636
|
+
return { byRunId, maxDevelopedLengthFt }
|
|
637
|
+
}
|
|
638
|
+
|
|
499
639
|
/**
|
|
500
640
|
* IRC M1502.4.5.1 — Clothes dryer exhaust duct maximum equivalent length (35 ft; -5 ft per 90° elbow, -2.5 ft per 45°).
|
|
501
641
|
*/
|
package/src/ipc/tables.ts
CHANGED
|
@@ -769,9 +769,12 @@ export function getPipeOuterDiameterM(size: PipeNominalSize, material: PipeMater
|
|
|
769
769
|
}
|
|
770
770
|
|
|
771
771
|
/**
|
|
772
|
-
* RFC 4180 CSV field escaping
|
|
772
|
+
* RFC 4180 CSV field escaping with spreadsheet formula-injection neutralization.
|
|
773
773
|
*/
|
|
774
774
|
export function csvEscape(v: string | number): string {
|
|
775
|
-
|
|
775
|
+
let s = String(v)
|
|
776
|
+
if (typeof v === 'string' && v !== '-' && /^(?:[=+\-@\t]|\s+[=+\-@])/.test(s)) {
|
|
777
|
+
s = `'${s}`
|
|
778
|
+
}
|
|
776
779
|
return /[",\r\n]/.test(s) ? `"${s.replace(/"/g, '""')}"` : s
|
|
777
780
|
}
|