@snaptrude/plugin-core 0.0.0-dev-20260908074328 → 0.0.0-dev-20260921132444
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/AGENTS.md +4 -0
- package/CHANGELOG.md +52 -16
- package/dist/api/core/io/import/index.d.ts +3 -1
- package/dist/api/core/io/import/index.d.ts.map +1 -1
- package/dist/api/core/mode/index.d.ts +19 -7
- package/dist/api/core/mode/index.d.ts.map +1 -1
- package/dist/api/core/tags.d.ts +81 -0
- package/dist/api/core/tags.d.ts.map +1 -1
- package/dist/api/design/create/bulk-items.d.ts +185 -0
- package/dist/api/design/create/bulk-items.d.ts.map +1 -0
- package/dist/api/design/create/grids.d.ts +132 -0
- package/dist/api/design/create/grids.d.ts.map +1 -0
- package/dist/api/design/create/index.d.ts +424 -51
- package/dist/api/design/create/index.d.ts.map +1 -1
- package/dist/api/design/create/opening-fields.d.ts +37 -0
- package/dist/api/design/create/opening-fields.d.ts.map +1 -0
- package/dist/api/design/delete/index.d.ts +6 -20
- package/dist/api/design/delete/index.d.ts.map +1 -1
- package/dist/api/design/dimensions.d.ts +427 -0
- package/dist/api/design/dimensions.d.ts.map +1 -0
- package/dist/api/design/doors/index.d.ts +20 -13
- package/dist/api/design/doors/index.d.ts.map +1 -1
- package/dist/api/design/family.d.ts +73 -5
- package/dist/api/design/family.d.ts.map +1 -1
- package/dist/api/design/grids.d.ts +237 -0
- package/dist/api/design/grids.d.ts.map +1 -0
- package/dist/api/design/index.d.ts +9 -0
- package/dist/api/design/index.d.ts.map +1 -1
- package/dist/api/design/query/grids.d.ts +287 -0
- package/dist/api/design/query/grids.d.ts.map +1 -0
- package/dist/api/design/query/index.d.ts +29 -2
- package/dist/api/design/query/index.d.ts.map +1 -1
- package/dist/api/design/query/spaces.d.ts +0 -61
- package/dist/api/design/query/spaces.d.ts.map +1 -1
- package/dist/api/design/update/index.d.ts +74 -0
- package/dist/api/design/update/index.d.ts.map +1 -1
- package/dist/api/entity/space.d.ts +0 -3
- package/dist/api/entity/space.d.ts.map +1 -1
- package/dist/api/presentation/annotate.d.ts +2 -2
- package/dist/api/presentation/placedViews.d.ts +1 -35
- package/dist/api/presentation/placedViews.d.ts.map +1 -1
- package/dist/api/presentation/shapes.d.ts +2 -2
- package/dist/api/presentation/sheets.d.ts +2 -20
- package/dist/api/presentation/sheets.d.ts.map +1 -1
- package/dist/api/program/departments.d.ts +58 -2
- package/dist/api/program/departments.d.ts.map +1 -1
- package/dist/api/program/index.d.ts +16 -6
- package/dist/api/program/index.d.ts.map +1 -1
- package/dist/api/program/labels.d.ts +355 -0
- package/dist/api/program/labels.d.ts.map +1 -0
- package/dist/api/program/metadata.d.ts +328 -0
- package/dist/api/program/metadata.d.ts.map +1 -0
- package/dist/api/program/spreadsheet.d.ts +263 -0
- package/dist/api/program/spreadsheet.d.ts.map +1 -1
- package/dist/api/workspace/index.d.ts +49 -2
- package/dist/api/workspace/index.d.ts.map +1 -1
- package/dist/errors/codes.d.ts +3 -8
- package/dist/errors/codes.d.ts.map +1 -1
- package/dist/handles.d.ts +19 -0
- package/dist/handles.d.ts.map +1 -1
- package/dist/index.cjs +2489 -1941
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +2395 -1936
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/api/core/io/import/index.ts +11 -3
- package/src/api/core/mode/index.ts +19 -7
- package/src/api/core/tags.ts +76 -0
- package/src/api/design/create/bulk-items.ts +186 -0
- package/src/api/design/create/grids.ts +137 -0
- package/src/api/design/create/index.ts +472 -70
- package/src/api/design/create/opening-fields.ts +37 -0
- package/src/api/design/delete/index.ts +5 -20
- package/src/api/design/dimensions.ts +453 -0
- package/src/api/design/doors/index.ts +20 -13
- package/src/api/design/family.ts +51 -4
- package/src/api/design/grids.ts +237 -0
- package/src/api/design/index.ts +10 -0
- package/src/api/design/query/grids.ts +197 -0
- package/src/api/design/query/index.ts +27 -2
- package/src/api/design/query/spaces.ts +0 -68
- package/src/api/design/update/index.ts +53 -0
- package/src/api/entity/space.ts +0 -2
- package/src/api/presentation/placedViews.ts +1 -29
- package/src/api/presentation/sheets.ts +3 -19
- package/src/api/program/departments.ts +54 -2
- package/src/api/program/index.ts +16 -6
- package/src/api/program/labels.ts +332 -0
- package/src/api/program/metadata.ts +364 -0
- package/src/api/program/spreadsheet.ts +282 -0
- package/src/api/workspace/index.ts +51 -2
- package/src/errors/codes.ts +2 -30
- package/src/handles.ts +24 -0
- package/test/errors.test.mjs +0 -4
- package/snaptrude-plugin-core-0.11.0.tgz +0 -0
package/src/api/design/family.ts
CHANGED
|
@@ -25,7 +25,8 @@ import { ComponentHandle, Vec3Components } from "../../handles"
|
|
|
25
25
|
* ## Read getReference() first
|
|
26
26
|
*
|
|
27
27
|
* The spec DSL is a closed expression language with its own op set, coordinate
|
|
28
|
-
* convention (**+Y up,
|
|
28
|
+
* convention (**+Y up, Snaptrude units** — the scene's own unit, 1 SU = 254 mm;
|
|
29
|
+
* literals may carry a unit suffix such as `600mm` or `2ft`)
|
|
29
30
|
* and part-naming law. It is deliberately NOT duplicated in these types:
|
|
30
31
|
* {@linkcode PluginDesignFamilyApi.getReference} returns the whole reference,
|
|
31
32
|
* generated from a family that is actually registered in the host, so the
|
|
@@ -278,11 +279,11 @@ export interface PluginFamilyBundle {
|
|
|
278
279
|
deps?: Record<string, Record<string, unknown>>
|
|
279
280
|
}
|
|
280
281
|
|
|
281
|
-
/** Axis-aligned extents of a built family.
|
|
282
|
+
/** Axis-aligned extents of a built family. Snaptrude units (1 SU = 254 mm), +Y up. */
|
|
282
283
|
export interface PluginFamilyBBox {
|
|
283
284
|
min: [number, number, number]
|
|
284
285
|
max: [number, number, number]
|
|
285
|
-
/** `[width, height, depth]` in
|
|
286
|
+
/** `[width, height, depth]` in Snaptrude units — convert with `core.units.convert` for display. */
|
|
286
287
|
size: [number, number, number]
|
|
287
288
|
}
|
|
288
289
|
|
|
@@ -322,6 +323,7 @@ export interface PluginFamilyDiagnostic {
|
|
|
322
323
|
| "unbounded-repeat"
|
|
323
324
|
| "depth"
|
|
324
325
|
| "bad-dimension"
|
|
326
|
+
| "proportion"
|
|
325
327
|
message: string
|
|
326
328
|
hint?: string
|
|
327
329
|
}
|
|
@@ -335,7 +337,7 @@ export interface PluginFamilyPrepareResult {
|
|
|
335
337
|
label?: string
|
|
336
338
|
/** How many parts the family built. Sanity-check against intent. */
|
|
337
339
|
partCount?: number
|
|
338
|
-
/** Extents in
|
|
340
|
+
/** Extents in Snaptrude units. Sanity-check against intent. */
|
|
339
341
|
bbox?: PluginFamilyBBox
|
|
340
342
|
evalMs?: number
|
|
341
343
|
parameters?: PluginFamilyParameter[]
|
|
@@ -343,6 +345,8 @@ export interface PluginFamilyPrepareResult {
|
|
|
343
345
|
takeoff?: Record<string, number | string>
|
|
344
346
|
/** The first few part names — enough to check the naming came out right. */
|
|
345
347
|
sampleParts?: string[]
|
|
348
|
+
/** Present when `snapshot` was asked for. */
|
|
349
|
+
snapshot?: PluginFamilySnapshot
|
|
346
350
|
errors: PluginFamilyDiagnostic[]
|
|
347
351
|
warnings: PluginFamilyDiagnostic[]
|
|
348
352
|
/** Set when the bundle validated but threw while building. */
|
|
@@ -372,6 +376,10 @@ export interface PluginFamilyFlexResult {
|
|
|
372
376
|
evalMs?: number
|
|
373
377
|
changed?: PluginFamilyChangeBuckets
|
|
374
378
|
takeoff?: Record<string, number | string>
|
|
379
|
+
/** Proportion warnings at the flexed values (code `proportion`): a part thinner than 0.5 mm, a part or family over 50 m, a family under 10 mm — the signature of a unit slip. */
|
|
380
|
+
warnings?: PluginFamilyDiagnostic[]
|
|
381
|
+
/** Present when `snapshot` was asked for. */
|
|
382
|
+
snapshot?: PluginFamilySnapshot
|
|
375
383
|
error?: string
|
|
376
384
|
}
|
|
377
385
|
|
|
@@ -421,6 +429,8 @@ export interface PluginFamilyInstanceParameters {
|
|
|
421
429
|
values: Record<string, number | string>
|
|
422
430
|
/** The sheet: what each key means, its bounds, and whether it moves geometry. */
|
|
423
431
|
parameters: PluginFamilyParameter[]
|
|
432
|
+
/** Present when `getParameters` was asked for a `snapshot`. */
|
|
433
|
+
snapshot?: PluginFamilySnapshot
|
|
424
434
|
}
|
|
425
435
|
|
|
426
436
|
/** What `create` reports. */
|
|
@@ -455,13 +465,46 @@ export const PluginFamilyBundleSchema = z.object({
|
|
|
455
465
|
* |---|---|---|
|
|
456
466
|
* | `bundle` | {@linkcode PluginFamilyBundle} | The family spec bundle |
|
|
457
467
|
* | `spec` | {@linkcode PluginFamilyBundle} | Alias for `bundle` |
|
|
468
|
+
* | `snapshot` | {@linkcode PluginFamilySnapshotOption} | Also return a picture of the built family |
|
|
458
469
|
*
|
|
459
470
|
* Exactly one of `bundle` / `spec` is required. A bare `FamilySpec` (no `root`
|
|
460
471
|
* wrapper) is also accepted by the host and wrapped for the caller.
|
|
461
472
|
*/
|
|
473
|
+
/**
|
|
474
|
+
* Ask for a picture with the result: `true` for the default sheet (iso, front,
|
|
475
|
+
* right and top tiles with a dimension line), or an object to choose views and
|
|
476
|
+
* tile size. The picture is an isolated offscreen render of the family alone —
|
|
477
|
+
* the viewport is not moved — and comes back as a PNG data URL in the result's
|
|
478
|
+
* `snapshot.image`. Through the agent's `run_worker`, return the result and the
|
|
479
|
+
* image reaches the model as an image.
|
|
480
|
+
*/
|
|
481
|
+
export const PluginFamilySnapshotOption = z.union([
|
|
482
|
+
z.boolean(),
|
|
483
|
+
z.object({
|
|
484
|
+
views: z.array(z.enum(["iso", "front", "right", "top"])).optional(),
|
|
485
|
+
/** Pixels per tile (square), 64–2048; default 512. */
|
|
486
|
+
tileSize: z.number().optional(),
|
|
487
|
+
}),
|
|
488
|
+
])
|
|
489
|
+
export type PluginFamilySnapshotOption = z.infer<typeof PluginFamilySnapshotOption>
|
|
490
|
+
|
|
491
|
+
/** The picture block on prepare / flex / getParameters results when `snapshot` was asked for. */
|
|
492
|
+
export interface PluginFamilySnapshot {
|
|
493
|
+
ok: boolean
|
|
494
|
+
/** PNG data URL of the composed sheet. */
|
|
495
|
+
image?: string
|
|
496
|
+
views?: ("iso" | "front" | "right" | "top")[]
|
|
497
|
+
/** [width, height, depth] in Snaptrude units. */
|
|
498
|
+
size?: [number, number, number]
|
|
499
|
+
ms?: number
|
|
500
|
+
/** Set when the picture could not be taken (e.g. the legacy renderer); the call itself still succeeded. */
|
|
501
|
+
error?: string
|
|
502
|
+
}
|
|
503
|
+
|
|
462
504
|
export const PluginDesignFamilyPrepareArgs = z.object({
|
|
463
505
|
bundle: PluginFamilyBundleSchema.optional(),
|
|
464
506
|
spec: PluginFamilyBundleSchema.optional(),
|
|
507
|
+
snapshot: PluginFamilySnapshotOption.optional(),
|
|
465
508
|
})
|
|
466
509
|
export type PluginDesignFamilyPrepareArgs = z.infer<typeof PluginDesignFamilyPrepareArgs>
|
|
467
510
|
|
|
@@ -471,9 +514,11 @@ export type PluginDesignFamilyPrepareArgs = z.infer<typeof PluginDesignFamilyPre
|
|
|
471
514
|
* | Property | Type | Description |
|
|
472
515
|
* |---|---|---|
|
|
473
516
|
* | `values` | `Record<string, number \| string>` | Parameter values to change (partial) |
|
|
517
|
+
* | `snapshot` | {@linkcode PluginFamilySnapshotOption} | Also return a picture of the flexed family |
|
|
474
518
|
*/
|
|
475
519
|
export const PluginDesignFamilyFlexArgs = z.object({
|
|
476
520
|
values: z.record(z.string(), z.union([z.number(), z.string()])),
|
|
521
|
+
snapshot: PluginFamilySnapshotOption.optional(),
|
|
477
522
|
})
|
|
478
523
|
export type PluginDesignFamilyFlexArgs = z.infer<typeof PluginDesignFamilyFlexArgs>
|
|
479
524
|
|
|
@@ -522,6 +567,8 @@ export type PluginDesignFamilyPlaceArgs = z.infer<typeof PluginDesignFamilyPlace
|
|
|
522
567
|
*/
|
|
523
568
|
export const PluginDesignFamilyGetParametersArgs = z.object({
|
|
524
569
|
component: ComponentHandle,
|
|
570
|
+
/** Also return a picture of this instance (its recipe re-run at its values, with its paint). */
|
|
571
|
+
snapshot: PluginFamilySnapshotOption.optional(),
|
|
525
572
|
})
|
|
526
573
|
export type PluginDesignFamilyGetParametersArgs = z.infer<
|
|
527
574
|
typeof PluginDesignFamilyGetParametersArgs
|
|
@@ -0,0 +1,237 @@
|
|
|
1
|
+
import * as z from "zod"
|
|
2
|
+
import { PluginApiReturn } from "../../types"
|
|
3
|
+
import { ComponentHandle } from "../../handles"
|
|
4
|
+
import { PluginGridStyleOptions } from "./create/grids"
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Tag policy for structural line removal (mirrors the engine
|
|
8
|
+
* `GridLineTagPolicy` values verbatim): `"rewrite"` renumbers each affected
|
|
9
|
+
* wing's tag sequence after removal; `"preserve"` keeps the surviving lines'
|
|
10
|
+
* tags unchanged.
|
|
11
|
+
*/
|
|
12
|
+
export const PluginGridLineTagPolicy = z.enum(["rewrite", "preserve"])
|
|
13
|
+
export type PluginGridLineTagPolicy = z.infer<typeof PluginGridLineTagPolicy>
|
|
14
|
+
|
|
15
|
+
/** A positional grid-line address — indices into `design.query.grids.get`'s `wings` arrays. */
|
|
16
|
+
export const PluginGridLineAddress = z.object({
|
|
17
|
+
wing: z.number().int().nonnegative(),
|
|
18
|
+
line: z.number().int().nonnegative(),
|
|
19
|
+
})
|
|
20
|
+
export type PluginGridLineAddress = z.infer<typeof PluginGridLineAddress>
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* One per-wing entry of {@linkcode PluginDesignGridsApi.updateWings} —
|
|
24
|
+
* addressed by wing index. `spanMin`/`spanMax` move the family's length
|
|
25
|
+
* handles (Snaptrude units).
|
|
26
|
+
*/
|
|
27
|
+
export const PluginGridWingEntry = z.object({
|
|
28
|
+
wing: z.number().int().nonnegative(),
|
|
29
|
+
spacing: z.number().positive().finite().optional(),
|
|
30
|
+
count: z.number().int().min(1).optional(),
|
|
31
|
+
spanMin: z.number().finite().optional(),
|
|
32
|
+
spanMax: z.number().finite().optional(),
|
|
33
|
+
})
|
|
34
|
+
export type PluginGridWingEntry = z.infer<typeof PluginGridWingEntry>
|
|
35
|
+
|
|
36
|
+
/** Arguments for {@linkcode PluginDesignGridsApi.updateWings}. */
|
|
37
|
+
export const PluginDesignGridsUpdateWingsArgs = z.object({
|
|
38
|
+
grid: ComponentHandle,
|
|
39
|
+
wings: z.array(PluginGridWingEntry).min(1),
|
|
40
|
+
})
|
|
41
|
+
export type PluginDesignGridsUpdateWingsArgs = z.infer<
|
|
42
|
+
typeof PluginDesignGridsUpdateWingsArgs
|
|
43
|
+
>
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* One per-line entry of {@linkcode PluginDesignGridsApi.updateLines} —
|
|
47
|
+
* addressed positionally by `{ wing, line }` indices (invalidated by
|
|
48
|
+
* structural edits; re-query after mutating). `distanceToPrevious` /
|
|
49
|
+
* `distanceToNext` set the typed distance to the adjacent line on that side
|
|
50
|
+
* and are mutually exclusive.
|
|
51
|
+
*
|
|
52
|
+
* `visible` is **hide-only** (`false`), mirroring the product: per-line show
|
|
53
|
+
* does not exist — showing the GROUP (`design.visibility.show`) restores all
|
|
54
|
+
* of its lines, exactly like the native Show All.
|
|
55
|
+
*/
|
|
56
|
+
export const PluginGridLineEntry = z
|
|
57
|
+
.object({
|
|
58
|
+
wing: z.number().int().nonnegative(),
|
|
59
|
+
line: z.number().int().nonnegative(),
|
|
60
|
+
tag: z.string().min(1).optional(),
|
|
61
|
+
distanceToPrevious: z.number().positive().finite().optional(),
|
|
62
|
+
distanceToNext: z.number().positive().finite().optional(),
|
|
63
|
+
props: PluginGridStyleOptions.optional(),
|
|
64
|
+
visible: z.literal(false).optional(),
|
|
65
|
+
})
|
|
66
|
+
.superRefine((entry, ctx) => {
|
|
67
|
+
if (entry.distanceToPrevious !== undefined && entry.distanceToNext !== undefined) {
|
|
68
|
+
ctx.addIssue({
|
|
69
|
+
code: z.ZodIssueCode.custom,
|
|
70
|
+
message:
|
|
71
|
+
"distanceToPrevious and distanceToNext are mutually exclusive on one line entry",
|
|
72
|
+
})
|
|
73
|
+
}
|
|
74
|
+
})
|
|
75
|
+
export type PluginGridLineEntry = z.infer<typeof PluginGridLineEntry>
|
|
76
|
+
|
|
77
|
+
/** Arguments for {@linkcode PluginDesignGridsApi.updateLines}. */
|
|
78
|
+
export const PluginDesignGridsUpdateLinesArgs = z.object({
|
|
79
|
+
grid: ComponentHandle,
|
|
80
|
+
lines: z.array(PluginGridLineEntry).min(1),
|
|
81
|
+
})
|
|
82
|
+
export type PluginDesignGridsUpdateLinesArgs = z.infer<
|
|
83
|
+
typeof PluginDesignGridsUpdateLinesArgs
|
|
84
|
+
>
|
|
85
|
+
|
|
86
|
+
/** Arguments for {@linkcode PluginDesignGridsApi.addLine}. */
|
|
87
|
+
export const PluginDesignGridsAddLineArgs = z.object({
|
|
88
|
+
grid: ComponentHandle,
|
|
89
|
+
wing: z.number().int().nonnegative(),
|
|
90
|
+
position: z.number().finite(),
|
|
91
|
+
})
|
|
92
|
+
export type PluginDesignGridsAddLineArgs = z.infer<typeof PluginDesignGridsAddLineArgs>
|
|
93
|
+
|
|
94
|
+
/** Arguments for {@linkcode PluginDesignGridsApi.removeLines}. */
|
|
95
|
+
export const PluginDesignGridsRemoveLinesArgs = z.object({
|
|
96
|
+
grid: ComponentHandle,
|
|
97
|
+
lines: z.array(PluginGridLineAddress).min(1),
|
|
98
|
+
tagPolicy: PluginGridLineTagPolicy.optional(),
|
|
99
|
+
})
|
|
100
|
+
export type PluginDesignGridsRemoveLinesArgs = z.infer<
|
|
101
|
+
typeof PluginDesignGridsRemoveLinesArgs
|
|
102
|
+
>
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* `design.grids.*` — structural edits on a grid's line structure (the
|
|
106
|
+
* entity-family home for grid-specific operations, like `design.doors`).
|
|
107
|
+
*
|
|
108
|
+
* Lines are addressed positionally as `{ wing, line }` index pairs into the
|
|
109
|
+
* `wings` arrays returned by `design.query.grids.get`. Adding, removing, or
|
|
110
|
+
* re-counting lines re-indexes the wing — re-query after every structural edit.
|
|
111
|
+
*
|
|
112
|
+
* Group-level edits (default styling, angle, storey visibility) live on
|
|
113
|
+
* `design.update.grid`; creation lives on `design.create.grid*`.
|
|
114
|
+
*
|
|
115
|
+
* Accessed via `snaptrude.design.grids`.
|
|
116
|
+
*/
|
|
117
|
+
export abstract class PluginDesignGridsApi {
|
|
118
|
+
constructor() {}
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* Update one or more **wings** of a grid with sparse per-wing entries —
|
|
122
|
+
* `spacing` (uniform re-space), `count` (grow/truncate + tag renumber),
|
|
123
|
+
* `spanMin`/`spanMax` (family length handles). Every change routes through
|
|
124
|
+
* the exact setters the native panel uses — each changed field commits its
|
|
125
|
+
* own undoable command, identical to editing that field in the panel.
|
|
126
|
+
*
|
|
127
|
+
* A `count` change re-indexes the wing's lines — positional `{ wing, line }`
|
|
128
|
+
* addresses held from before the call are stale afterwards; re-query.
|
|
129
|
+
*
|
|
130
|
+
* @param grid - The grid group
|
|
131
|
+
* @param wings - Sparse {@linkcode PluginGridWingEntry} entries (≥ 1)
|
|
132
|
+
* @returns `true` once applied
|
|
133
|
+
*
|
|
134
|
+
* @examplePrompt Change this grid's spacing to 8 metres
|
|
135
|
+
* @examplePrompt Make this grid 10 by 12 lines
|
|
136
|
+
*
|
|
137
|
+
* # Example
|
|
138
|
+
* ```ts
|
|
139
|
+
* await snaptrude.design.grids.updateWings(grid, [{ wing: 0, spacing: 8, count: 10 }])
|
|
140
|
+
* ```
|
|
141
|
+
*/
|
|
142
|
+
public abstract updateWings(
|
|
143
|
+
grid: ComponentHandle,
|
|
144
|
+
wings: PluginGridWingEntry[],
|
|
145
|
+
): PluginApiReturn<boolean>
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* Update one or more **lines** of a grid with sparse per-line entries —
|
|
149
|
+
* `tag`, `distanceToPrevious`/`distanceToNext` (typed distance to the
|
|
150
|
+
* neighbour on that side; mutually exclusive), `props` (per-line style
|
|
151
|
+
* overrides), and `visible: false` (hide). Every change routes through the
|
|
152
|
+
* exact setters the native panel uses — each changed field commits its own
|
|
153
|
+
* undoable command, identical to editing that field in the panel.
|
|
154
|
+
*
|
|
155
|
+
* Visibility mirrors the product exactly: `visible` accepts only `false` —
|
|
156
|
+
* per-line show does not exist. Hiding lines that would leave NO visible
|
|
157
|
+
* line hides the whole GROUP instead (the native last-line rule; those line
|
|
158
|
+
* flags stay untouched). To bring hidden lines back, show the group
|
|
159
|
+
* (`design.visibility.show([grid])`) — it restores ALL of its lines, like
|
|
160
|
+
* the native Show All.
|
|
161
|
+
*
|
|
162
|
+
* @param grid - The grid group
|
|
163
|
+
* @param lines - Sparse {@linkcode PluginGridLineEntry} entries (≥ 1)
|
|
164
|
+
* @returns `true` once applied
|
|
165
|
+
*
|
|
166
|
+
* @examplePrompt Rename grid line 2 to "B"
|
|
167
|
+
* @examplePrompt Move this grid line 4 metres from its neighbour
|
|
168
|
+
* @examplePrompt Hide grid line 3 on this grid
|
|
169
|
+
*
|
|
170
|
+
* # Example
|
|
171
|
+
* ```ts
|
|
172
|
+
* await snaptrude.design.grids.updateLines(grid, [
|
|
173
|
+
* { wing: 0, line: 1, tag: "B", distanceToPrevious: 4 },
|
|
174
|
+
* ])
|
|
175
|
+
* ```
|
|
176
|
+
*/
|
|
177
|
+
public abstract updateLines(
|
|
178
|
+
grid: ComponentHandle,
|
|
179
|
+
lines: PluginGridLineEntry[],
|
|
180
|
+
): PluginApiReturn<boolean>
|
|
181
|
+
|
|
182
|
+
/**
|
|
183
|
+
* Insert a parallel grid line into a wing at an explicit position along the
|
|
184
|
+
* wing's spacing axis (Snaptrude units, wing-local — line 0's position can
|
|
185
|
+
* be read from its curve). Sibling lines do not shift; the wing's tag
|
|
186
|
+
* sequence is renumbered. Undoable.
|
|
187
|
+
*
|
|
188
|
+
* @param grid - The grid group
|
|
189
|
+
* @param wing - Wing index
|
|
190
|
+
* @param position - Position along the wing's spacing axis (Snaptrude units)
|
|
191
|
+
* @returns `true` once inserted
|
|
192
|
+
* @throws `VALIDATION` on a bad wing index or non-finite position
|
|
193
|
+
*
|
|
194
|
+
* @examplePrompt Add a grid line between lines 2 and 3
|
|
195
|
+
* @examplePrompt Insert an extra grid line 4 metres from line A
|
|
196
|
+
*
|
|
197
|
+
* # Example
|
|
198
|
+
* ```ts
|
|
199
|
+
* await snaptrude.design.grids.addLine(grid, 0, 12.5)
|
|
200
|
+
* ```
|
|
201
|
+
*/
|
|
202
|
+
public abstract addLine(
|
|
203
|
+
grid: ComponentHandle,
|
|
204
|
+
wing: number,
|
|
205
|
+
position: number,
|
|
206
|
+
): PluginApiReturn<boolean>
|
|
207
|
+
|
|
208
|
+
/**
|
|
209
|
+
* Remove grid lines by positional address, as ONE undoable step. With
|
|
210
|
+
* `tagPolicy: "rewrite"` (default) each affected wing renumbers its tag
|
|
211
|
+
* sequence; `"preserve"` keeps surviving tags unchanged. A wing emptied of
|
|
212
|
+
* lines is dropped from the group.
|
|
213
|
+
*
|
|
214
|
+
* Removing EVERY line of the group is rejected — delete the group instead
|
|
215
|
+
* (`design.delete.entities`).
|
|
216
|
+
*
|
|
217
|
+
* @param grid - The grid group
|
|
218
|
+
* @param lines - Positional addresses to remove (see `design.query.grids.get`)
|
|
219
|
+
* @param tagPolicy - `"rewrite"` (default) or `"preserve"`
|
|
220
|
+
* @returns `true` once removed
|
|
221
|
+
* @throws `VALIDATION` on out-of-range addresses; `OPERATION_FAILED` when the
|
|
222
|
+
* removal would delete the group's last line
|
|
223
|
+
*
|
|
224
|
+
* @examplePrompt Delete grid line B
|
|
225
|
+
* @examplePrompt Remove the last two lines of this grid without renumbering
|
|
226
|
+
*
|
|
227
|
+
* # Example
|
|
228
|
+
* ```ts
|
|
229
|
+
* await snaptrude.design.grids.removeLines(grid, [{ wing: 0, line: 2 }], "preserve")
|
|
230
|
+
* ```
|
|
231
|
+
*/
|
|
232
|
+
public abstract removeLines(
|
|
233
|
+
grid: ComponentHandle,
|
|
234
|
+
lines: PluginGridLineAddress[],
|
|
235
|
+
tagPolicy?: PluginGridLineTagPolicy,
|
|
236
|
+
): PluginApiReturn<boolean>
|
|
237
|
+
}
|
package/src/api/design/index.ts
CHANGED
|
@@ -14,8 +14,10 @@ import { PluginDesignTransformApi } from "./transform"
|
|
|
14
14
|
import { PluginDesignEditApi } from "./edit"
|
|
15
15
|
import { PluginDesignUpdateApi } from "./update"
|
|
16
16
|
import { PluginDesignVisibilityApi } from "./visibility"
|
|
17
|
+
import { PluginDesignDimensionsApi } from "./dimensions"
|
|
17
18
|
import { PluginDesignTypesApi } from "./types"
|
|
18
19
|
import { PluginDesignFamilyApi } from "./family"
|
|
20
|
+
import { PluginDesignGridsApi } from "./grids"
|
|
19
21
|
import { PluginDesignChangeResult } from "./lock"
|
|
20
22
|
|
|
21
23
|
/**
|
|
@@ -31,6 +33,7 @@ import { PluginDesignChangeResult } from "./lock"
|
|
|
31
33
|
* - {@linkcode PluginDesignApi.erase} — plan-level adjacency-edge erase (NOT hard delete)
|
|
32
34
|
* - {@linkcode PluginDesignApi.delete} — hard entity removal
|
|
33
35
|
* - {@linkcode PluginDesignApi.visibility} — hide / isolate / reveal entities
|
|
36
|
+
* - {@linkcode PluginDesignApi.dimensions} — dimension lines (Measuring Tape): create / list / delete / hide
|
|
34
37
|
* - {@linkcode PluginDesignApi.types} — read-only building type / assembly reference
|
|
35
38
|
* - {@linkcode PluginDesignApi.family} — author parametric families from a JSON spec
|
|
36
39
|
* - {@linkcode PluginDesignApi.lock} / {@linkcode PluginDesignApi.unlock} / {@linkcode PluginDesignApi.isLocked} / {@linkcode PluginDesignApi.listLocked} — lock state (top-level design verbs, §2A.1)
|
|
@@ -67,11 +70,16 @@ export abstract class PluginDesignApi {
|
|
|
67
70
|
public abstract update: PluginDesignUpdateApi
|
|
68
71
|
/** Hide / isolate / reveal entities. See {@linkcode PluginDesignVisibilityApi}. */
|
|
69
72
|
public abstract visibility: PluginDesignVisibilityApi
|
|
73
|
+
/** Dimension lines (Measuring Tape). See {@linkcode PluginDesignDimensionsApi}. */
|
|
74
|
+
public abstract dimensions: PluginDesignDimensionsApi
|
|
70
75
|
/** Read-only building type / assembly reference. See {@linkcode PluginDesignTypesApi}. */
|
|
71
76
|
public abstract types: PluginDesignTypesApi
|
|
72
77
|
/** Author parametric families from a JSON spec. See {@linkcode PluginDesignFamilyApi}. */
|
|
73
78
|
public abstract family: PluginDesignFamilyApi
|
|
74
79
|
|
|
80
|
+
/** Structural edits on a grid's line structure. See {@linkcode PluginDesignGridsApi}. */
|
|
81
|
+
public abstract grids: PluginDesignGridsApi
|
|
82
|
+
|
|
75
83
|
/**
|
|
76
84
|
* Lock entities so they cannot be edited. Undoable. Cascades to void/door/window
|
|
77
85
|
* children, stacked-wall companions, and terrain neighborhood; skips
|
|
@@ -260,5 +268,7 @@ export * from "./transform"
|
|
|
260
268
|
export * from "./edit"
|
|
261
269
|
export * from "./update"
|
|
262
270
|
export * from "./visibility"
|
|
271
|
+
export * from "./dimensions"
|
|
263
272
|
export * from "./types"
|
|
264
273
|
export * from "./family"
|
|
274
|
+
export * from "./grids"
|
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
import * as z from "zod"
|
|
2
|
+
import { PluginApiReturn } from "../../../types"
|
|
3
|
+
import { CurveHandle, BBoxComponents } from "../../../handles"
|
|
4
|
+
import { PluginReferenceLineStyle } from "../create"
|
|
5
|
+
|
|
6
|
+
// ---------------------------------------------------------------------------
|
|
7
|
+
// Records
|
|
8
|
+
// ---------------------------------------------------------------------------
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Visual properties of grid lines — the group's defaults and any per-line
|
|
12
|
+
* overrides share this shape (values mirror the engine's `GridLineProps`).
|
|
13
|
+
*
|
|
14
|
+
* | Property | Type | Description |
|
|
15
|
+
* |---|---|---|
|
|
16
|
+
* | `style` | {@linkcode PluginReferenceLineStyle} | Line style (`"SOLID"` \| `"DASHED"` \| `"DOT_DASH"`) |
|
|
17
|
+
* | `weight` | `number` | Line weight |
|
|
18
|
+
* | `color` | `string` | Line color as a `#rrggbb` hex string |
|
|
19
|
+
* | `showStart` | `boolean` | Whether the start-end tag bubble is shown |
|
|
20
|
+
* | `showEnd` | `boolean` | Whether the end-end tag bubble is shown |
|
|
21
|
+
*/
|
|
22
|
+
export const PluginGridLineProps = z.object({
|
|
23
|
+
style: PluginReferenceLineStyle,
|
|
24
|
+
weight: z.number(),
|
|
25
|
+
color: z.string(),
|
|
26
|
+
showStart: z.boolean(),
|
|
27
|
+
showEnd: z.boolean(),
|
|
28
|
+
})
|
|
29
|
+
export type PluginGridLineProps = z.infer<typeof PluginGridLineProps>
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* One grid line within a wing.
|
|
33
|
+
*
|
|
34
|
+
* | Property | Type | Description |
|
|
35
|
+
* |---|---|---|
|
|
36
|
+
* | `curve` | {@linkcode CurveHandle} | The line's geometry in **world space** (a line or arc; read coordinates via `core.geom.curve`) |
|
|
37
|
+
* | `tag` | `string` | The line's grid tag (e.g. `"A"`, `"3"`) |
|
|
38
|
+
* | `visible` | `boolean` | Persisted per-line visibility |
|
|
39
|
+
* | `props` | {@linkcode PluginGridLineProps} | **Effective** visual properties (group defaults merged with this line's overrides) |
|
|
40
|
+
* | `overrides` | `Partial<`{@linkcode PluginGridLineProps}`>`? | This line's raw overrides, when any exist |
|
|
41
|
+
*/
|
|
42
|
+
export const PluginGridLineRecord = z.object({
|
|
43
|
+
curve: CurveHandle,
|
|
44
|
+
tag: z.string(),
|
|
45
|
+
visible: z.boolean(),
|
|
46
|
+
props: PluginGridLineProps,
|
|
47
|
+
overrides: PluginGridLineProps.partial().optional(),
|
|
48
|
+
})
|
|
49
|
+
export type PluginGridLineRecord = z.infer<typeof PluginGridLineRecord>
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* One wing of a grid — a family of parallel lines sharing a local frame.
|
|
53
|
+
* `spacing` and `span` are measured along the wing's local axes in
|
|
54
|
+
* Snaptrude units; line addresses used by mutating APIs are
|
|
55
|
+
* `{ wing, line }` index pairs into these arrays.
|
|
56
|
+
*
|
|
57
|
+
* | Property | Type | Description |
|
|
58
|
+
* |---|---|---|
|
|
59
|
+
* | `spacing` | `number` | Nominal spacing between adjacent lines (Snaptrude units) |
|
|
60
|
+
* | `tagStart` | `string` | First tag of the wing's deterministic tag sequence |
|
|
61
|
+
* | `span` | `{ min: number; max: number }`? | Explicit family length along the wing's line axis, when baked |
|
|
62
|
+
* | `lines` | {@linkcode PluginGridLineRecord}`[]` | The wing's lines, in wing order (index = the `line` address) |
|
|
63
|
+
*/
|
|
64
|
+
export const PluginGridWingRecord = z.object({
|
|
65
|
+
spacing: z.number(),
|
|
66
|
+
tagStart: z.string(),
|
|
67
|
+
span: z.object({ min: z.number(), max: z.number() }).optional(),
|
|
68
|
+
lines: z.array(PluginGridLineRecord),
|
|
69
|
+
})
|
|
70
|
+
export type PluginGridWingRecord = z.infer<typeof PluginGridWingRecord>
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Per-storey 2D-plan visibility of a grid.
|
|
74
|
+
*
|
|
75
|
+
* | Property | Type | Description |
|
|
76
|
+
* |---|---|---|
|
|
77
|
+
* | `activeStorey` | `number` | The storey the grid belongs to |
|
|
78
|
+
* | `disabledOnStoreys` | `number[]` | Storeys on whose 2D plan the grid is hidden |
|
|
79
|
+
*/
|
|
80
|
+
export const PluginGridStoreyVisibility = z.object({
|
|
81
|
+
activeStorey: z.number(),
|
|
82
|
+
disabledOnStoreys: z.array(z.number()),
|
|
83
|
+
})
|
|
84
|
+
export type PluginGridStoreyVisibility = z.infer<typeof PluginGridStoreyVisibility>
|
|
85
|
+
|
|
86
|
+
// ---------------------------------------------------------------------------
|
|
87
|
+
// get — args & result
|
|
88
|
+
// ---------------------------------------------------------------------------
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Property names readable via {@linkcode PluginDesignQueryGridsApi.get}.
|
|
92
|
+
*
|
|
93
|
+
* | Value | Description |
|
|
94
|
+
* |---|---|
|
|
95
|
+
* | `"angle"` | World rotation about +Y, in **degrees** |
|
|
96
|
+
* | `"props"` | Group-level default line properties |
|
|
97
|
+
* | `"storeyVisibility"` | Active storey + storeys where the grid is hidden in 2D |
|
|
98
|
+
* | `"wings"` | Full wing/line structure with world-space curve handles |
|
|
99
|
+
* | `"bounds"` | World-space axis-aligned bounding box of the grid geometry |
|
|
100
|
+
*/
|
|
101
|
+
export const PluginGridGetProperty = z.enum([
|
|
102
|
+
"angle",
|
|
103
|
+
"props",
|
|
104
|
+
"storeyVisibility",
|
|
105
|
+
"wings",
|
|
106
|
+
"bounds",
|
|
107
|
+
])
|
|
108
|
+
export type PluginGridGetProperty = z.infer<typeof PluginGridGetProperty>
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* Arguments for {@linkcode PluginDesignQueryGridsApi.get}.
|
|
112
|
+
*
|
|
113
|
+
* | Property | Type | Description |
|
|
114
|
+
* |---|---|---|
|
|
115
|
+
* | `gridId` | `string` | The grid group ID to query |
|
|
116
|
+
* | `properties` | {@linkcode PluginGridGetProperty}`[]` | Properties to retrieve |
|
|
117
|
+
*/
|
|
118
|
+
export const PluginGridGetArgs = z.object({
|
|
119
|
+
gridId: z.string(),
|
|
120
|
+
properties: z.array(PluginGridGetProperty),
|
|
121
|
+
})
|
|
122
|
+
export type PluginGridGetArgs = z.infer<typeof PluginGridGetArgs>
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* Result of {@linkcode PluginDesignQueryGridsApi.get} — only the requested
|
|
126
|
+
* properties are present.
|
|
127
|
+
*/
|
|
128
|
+
export const PluginGridGetResult = z
|
|
129
|
+
.object({
|
|
130
|
+
angle: z.number(),
|
|
131
|
+
props: PluginGridLineProps,
|
|
132
|
+
storeyVisibility: PluginGridStoreyVisibility,
|
|
133
|
+
wings: z.array(PluginGridWingRecord),
|
|
134
|
+
bounds: BBoxComponents,
|
|
135
|
+
})
|
|
136
|
+
.partial()
|
|
137
|
+
export type PluginGridGetResult = z.infer<typeof PluginGridGetResult>
|
|
138
|
+
|
|
139
|
+
// ---------------------------------------------------------------------------
|
|
140
|
+
// Abstract API
|
|
141
|
+
// ---------------------------------------------------------------------------
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* `design.query.grids.*` — structural-grid-specific reads.
|
|
145
|
+
*
|
|
146
|
+
* A **grid** (grid group) is a structural/documentation grid: one or more
|
|
147
|
+
* *wings* (families of parallel lines with a shared local frame), each holding
|
|
148
|
+
* tagged grid *lines* (straight lines, or a lone arc). Enumerate grids with
|
|
149
|
+
* `design.query.listGrids`; read an individual grid's structure here.
|
|
150
|
+
*
|
|
151
|
+
* Lines have no stable identity of their own — mutating APIs address them
|
|
152
|
+
* positionally as `{ wing, line }` index pairs into the `wings` arrays
|
|
153
|
+
* returned by {@linkcode get}. Structural edits (adding/removing lines,
|
|
154
|
+
* count changes) re-index lines; re-query after mutating.
|
|
155
|
+
*
|
|
156
|
+
* Accessed via `snaptrude.design.query.grids`.
|
|
157
|
+
*/
|
|
158
|
+
export abstract class PluginDesignQueryGridsApi {
|
|
159
|
+
constructor() {}
|
|
160
|
+
|
|
161
|
+
/**
|
|
162
|
+
* Get properties of a grid by its ID.
|
|
163
|
+
*
|
|
164
|
+
* Only the properties listed in `properties` are returned — unlisted
|
|
165
|
+
* properties will be `undefined` in the result. `wings` is the heavy
|
|
166
|
+
* read (it registers a world-space {@linkcode CurveHandle} per line);
|
|
167
|
+
* request it only when the geometry is needed.
|
|
168
|
+
*
|
|
169
|
+
* Units: `angle` is in **degrees** (positive = CCW about +Y); `spacing`,
|
|
170
|
+
* `span`, `bounds`, and curve coordinates are in **Snaptrude units**,
|
|
171
|
+
* world space.
|
|
172
|
+
*
|
|
173
|
+
* @param gridId - The unique grid group ID
|
|
174
|
+
* @param properties - Array of property names to retrieve. See
|
|
175
|
+
* {@linkcode PluginGridGetProperty}.
|
|
176
|
+
* @returns A partial {@linkcode PluginGridGetResult} containing only the
|
|
177
|
+
* requested properties
|
|
178
|
+
* @throws If the grid does not exist
|
|
179
|
+
*
|
|
180
|
+
* @examplePrompt What is the spacing of this grid?
|
|
181
|
+
* @examplePrompt Read the grid line tags on this structural grid
|
|
182
|
+
* @examplePrompt Get the geometry of every line in this grid
|
|
183
|
+
* @examplePrompt Which storeys is this grid hidden on?
|
|
184
|
+
*
|
|
185
|
+
* # Example
|
|
186
|
+
* ```ts
|
|
187
|
+
* const [grid] = await snaptrude.design.query.listGrids()
|
|
188
|
+
* const { wings } = await snaptrude.design.query.grids.get(grid, ["wings"])
|
|
189
|
+
* // wings[0].lines[0].curve is an opaque CurveHandle in world space;
|
|
190
|
+
* // read its coordinates via `snaptrude.core.geom.curve`.
|
|
191
|
+
* ```
|
|
192
|
+
*/
|
|
193
|
+
public abstract get(
|
|
194
|
+
gridId: string,
|
|
195
|
+
properties: z.infer<typeof PluginGridGetProperty>[],
|
|
196
|
+
): PluginApiReturn<PluginGridGetResult>
|
|
197
|
+
}
|