@classcad/client 0.0.0-stage → 3.0.0-beta.20261119100608

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.
Files changed (108) hide show
  1. package/README.md +20 -2
  2. package/bin/buerli-classcad.cjs +23 -0
  3. package/build/cjs/BuerliCadFacade.js +718 -0
  4. package/build/cjs/cclass/utils/assembly.js +687 -0
  5. package/build/cjs/cclass/utils/base.js +136 -0
  6. package/build/cjs/cclass/utils/index.js +99 -0
  7. package/build/cjs/cclass/utils/part.js +153 -0
  8. package/build/cjs/classcadEngine.js +33 -0
  9. package/build/cjs/createApi.js +71 -0
  10. package/build/cjs/createUnwrappedApi.js +43 -0
  11. package/build/cjs/facade.js +103 -0
  12. package/build/cjs/globals.js +157 -0
  13. package/build/cjs/index.js +102 -0
  14. package/build/cjs/io/AwvNodeClient.js +290 -0
  15. package/build/cjs/io/SocketIOClient.js +339 -0
  16. package/build/cjs/io/Transaction.js +134 -0
  17. package/build/cjs/io/WASMClient.js +433 -0
  18. package/build/cjs/io/WSClient.js +646 -0
  19. package/build/cjs/io/engineKey.js +202 -0
  20. package/build/cjs/re-export.js +35 -0
  21. package/build/cjs/session/host.js +479 -0
  22. package/build/cjs/session/identity.js +38 -0
  23. package/build/cjs/session/selection.js +283 -0
  24. package/build/cjs/session/share.js +229 -0
  25. package/build/cjs/session/types.js +23 -0
  26. package/build/cjs/test/SocketIOClient.spec.js +178 -0
  27. package/build/cjs/types/ComClient.js +10 -0
  28. package/build/cjs/utils/createRecursiveBufferGeometry.js +55 -0
  29. package/build/cjs/utils/createRecursiveScene.js +140 -0
  30. package/build/cjs/utils/getDifferentColoredMeshesFromEntity.js +24 -0
  31. package/build/cjs/utils/index.js +20 -0
  32. package/build/cjs/utils/polyline.js +65 -0
  33. package/build/cjs/utils/waitForSelect.js +29 -0
  34. package/build/esm/BuerliCadFacade.js +714 -0
  35. package/build/esm/cclass/utils/assembly.js +665 -0
  36. package/build/esm/cclass/utils/base.js +127 -0
  37. package/build/esm/cclass/utils/index.js +62 -0
  38. package/build/esm/cclass/utils/part.js +144 -0
  39. package/build/esm/classcadEngine.js +30 -0
  40. package/build/esm/createApi.js +66 -0
  41. package/build/esm/createUnwrappedApi.js +39 -0
  42. package/build/esm/facade.js +98 -0
  43. package/build/esm/globals.js +150 -0
  44. package/build/esm/index.js +80 -0
  45. package/build/esm/io/AwvNodeClient.js +286 -0
  46. package/build/esm/io/SocketIOClient.js +332 -0
  47. package/build/esm/io/Transaction.js +130 -0
  48. package/build/esm/io/WASMClient.js +429 -0
  49. package/build/esm/io/WSClient.js +642 -0
  50. package/build/esm/io/engineKey.js +196 -0
  51. package/build/esm/re-export.js +3 -0
  52. package/build/esm/session/host.js +474 -0
  53. package/build/esm/session/identity.js +34 -0
  54. package/build/esm/session/selection.js +277 -0
  55. package/build/esm/session/share.js +221 -0
  56. package/build/esm/session/types.js +20 -0
  57. package/build/esm/test/SocketIOClient.spec.js +178 -0
  58. package/build/esm/types/ComClient.js +7 -0
  59. package/build/esm/utils/createRecursiveBufferGeometry.js +51 -0
  60. package/build/esm/utils/createRecursiveScene.js +136 -0
  61. package/build/esm/utils/getDifferentColoredMeshesFromEntity.js +20 -0
  62. package/build/esm/utils/index.js +4 -0
  63. package/build/esm/utils/polyline.js +60 -0
  64. package/build/esm/utils/waitForSelect.js +23 -0
  65. package/build/types/BuerliCadFacade.d.ts +410 -0
  66. package/build/types/cclass/utils/assembly.d.ts +180 -0
  67. package/build/types/cclass/utils/base.d.ts +55 -0
  68. package/build/types/cclass/utils/index.d.ts +46 -0
  69. package/build/types/cclass/utils/part.d.ts +46 -0
  70. package/build/types/classcadEngine.d.ts +40 -0
  71. package/build/types/createApi.d.ts +65 -0
  72. package/build/types/createUnwrappedApi.d.ts +36 -0
  73. package/build/types/facade.d.ts +9 -0
  74. package/build/types/globals.d.ts +79 -0
  75. package/build/types/index.d.ts +82 -0
  76. package/build/types/io/AwvNodeClient.d.ts +182 -0
  77. package/build/types/io/SocketIOClient.d.ts +84 -0
  78. package/build/types/io/Transaction.d.ts +56 -0
  79. package/build/types/io/WASMClient.d.ts +239 -0
  80. package/build/types/io/WSClient.d.ts +242 -0
  81. package/build/types/io/engineKey.d.ts +137 -0
  82. package/build/types/re-export.d.ts +6 -0
  83. package/build/types/session/host.d.ts +108 -0
  84. package/build/types/session/identity.d.ts +46 -0
  85. package/build/types/session/selection.d.ts +164 -0
  86. package/build/types/session/share.d.ts +131 -0
  87. package/build/types/session/types.d.ts +113 -0
  88. package/build/types/test/SocketIOClient.spec.d.ts +0 -0
  89. package/build/types/types/ComClient.d.ts +307 -0
  90. package/build/types/utils/createRecursiveBufferGeometry.d.ts +8 -0
  91. package/build/types/utils/createRecursiveScene.d.ts +24 -0
  92. package/build/types/utils/getDifferentColoredMeshesFromEntity.d.ts +14 -0
  93. package/build/types/utils/index.d.ts +4 -0
  94. package/build/types/utils/polyline.d.ts +43 -0
  95. package/build/types/utils/waitForSelect.d.ts +4 -0
  96. package/doc/api/advanced/connection.md +488 -0
  97. package/doc/api/clients.md +2045 -0
  98. package/doc/api/engine-keys.md +230 -0
  99. package/doc/api/index.md +58 -0
  100. package/doc/api/modeling.md +682 -0
  101. package/doc/api/other.md +33 -0
  102. package/doc/api/session-sharing.md +706 -0
  103. package/package.json +60 -4
  104. package/test/classcadEngine.test.cjs +44 -0
  105. package/test/connect.test.cjs +81 -0
  106. package/test/engineKey.test.cjs +80 -0
  107. package/test/onClient.test.cjs +82 -0
  108. package/typedoc.json +8 -0
@@ -0,0 +1,410 @@
1
+ import type * as THREE from 'three';
2
+ import { BufferGeometry, Material, Object3D, Scene } from 'three';
3
+ import { DrawingID, ObjectID, InteractionInfo } from '@classcad/sdkjs';
4
+ import { ScgGraphicContainer, ScgGraphicType, ScgTree } from '@classcad/api-js';
5
+ import { UnwrappedApiType } from './createUnwrappedApi';
6
+ import { EmissionConfig } from './types/ComClient';
7
+ /**
8
+ * The kinds of geometry {@link BuerliCadFacade.selectGeometry} picks.
9
+ *
10
+ * @inline
11
+ */
12
+ type GrT = ScgGraphicType.POINT | ScgGraphicType.LINE | ScgGraphicType.ARC | ScgGraphicType.CIRCLE | ScgGraphicType.PLANE | ScgGraphicType.CYLINDER | ScgGraphicType.CONE | ScgGraphicType.SPHERE | ScgGraphicType.NURBSCURVE | ScgGraphicType.NURBSSURFACE;
13
+ /**
14
+ * The ClassCAD API of a {@link BuerliCadFacade}, unwrapped: calls resolve to their result and reject on an error.
15
+ *
16
+ * `api.v1` holds the namespaces (`part`, `sketch`, `assembly`, `solid`, `curve`, `common`, `drawing2d`), which are
17
+ * also on the object itself. See {@link createUnwrappedApi}.
18
+ *
19
+ * @example
20
+ * ```ts
21
+ * import { BuerliCadFacade } from '@classcad/client'
22
+ * import type { ClassCADApi } from '@classcad/client'
23
+ *
24
+ * // A model function that works with any facade's API
25
+ * async function plateWithHole(api: ClassCADApi, size: number) {
26
+ * const part = (await api.v1.part.create({ name: 'Plate' }))!
27
+ * const plate = (await api.v1.part.box({ id: part, length: size, width: size, height: 10 }))!
28
+ * const hole = (await api.v1.part.cylinder({ id: part, diameter: size / 2, height: 10 }))!
29
+ * await api.v1.part.boolean({ id: part, type: 'SUBTRACTION', target: plate, tools: [hole] })
30
+ * return part
31
+ * }
32
+ *
33
+ * const facade = new BuerliCadFacade()
34
+ * await facade.connect()
35
+ * const part = await plateWithHole(facade.api, 100)
36
+ * ```
37
+ * @category Modeling
38
+ */
39
+ export type ClassCADApi = UnwrappedApiType;
40
+ /**
41
+ * A drawing connected to ClassCAD: its API, and helpers that turn the model into three.js objects.
42
+ *
43
+ * `connect()` creates a drawing in the SDK's store and connects it with a client from the factory given to
44
+ * {@link init}. Then `api` is the drawing's ClassCAD API, unwrapped: `await api.v1.part.create(…)` resolves to the
45
+ * new part's id and rejects when the engine reports an error; warnings are logged. `createBufferGeometry` and
46
+ * `createScene` make three.js geometry of what was built, `tree` and `graphic` read the drawing as the store holds
47
+ * it. The static `utils` do the facade's work for any drawing, by its id.
48
+ *
49
+ * @example
50
+ * ```ts
51
+ * import * as THREE from 'three'
52
+ * import { init, BuerliCadFacade, WASMClient } from '@classcad/client'
53
+ *
54
+ * init(drawingId => new WASMClient(drawingId, { token: 'ccpk_…' }))
55
+ *
56
+ * // A parametric flange: one facade per drawing
57
+ * export async function flange(diameter: number, thickness: number) {
58
+ * const facade = new BuerliCadFacade()
59
+ * await facade.connect('Flange')
60
+ * const { part } = facade.api.v1
61
+ * const flange = (await part.create({ name: 'Flange' }))!
62
+ * await part.cylinder({ id: flange, diameter, height: thickness })
63
+ * const geometries = (await facade.createBufferGeometry(flange)) ?? []
64
+ * const meshes = geometries.map(geometry => new THREE.Mesh(geometry, new THREE.MeshStandardMaterial()))
65
+ * // Done with it: the drawing leaves the store
66
+ * await facade.destroy()
67
+ * return meshes
68
+ * }
69
+ * ```
70
+ * @category Modeling
71
+ */
72
+ export declare class BuerliCadFacade {
73
+ private _drawingId;
74
+ private _api;
75
+ /**
76
+ * The facade's work for any drawing, by its id: connect, disconnect, undo, emission config, middleware commands.
77
+ *
78
+ * For drawings an app connects without a facade, and for the drawings of react-cad and Buerligons.
79
+ */
80
+ static utils: {
81
+ /**
82
+ * Creates a drawing and connects it: makes its client with the factory given to {@link init}, calls the
83
+ * {@link onClient} callbacks, connects the client.
84
+ *
85
+ * Rejects when `init` has not been called. When connecting fails, the error is logged and shown as a message,
86
+ * and it resolves to null.
87
+ *
88
+ * @param drawingName - The drawing's name in the store; by default `Drawing #<n>`.
89
+ * @returns The new drawing's id, or null when it could not connect.
90
+ */
91
+ connect: (drawingName?: string) => Promise<DrawingID | null>;
92
+ /**
93
+ * Disconnects the drawing's client and resets the drawing: it stays in the store, without its model.
94
+ *
95
+ * Rejects when the drawing has no client.
96
+ *
97
+ * @param drawingId - The drawing.
98
+ */
99
+ disconnect: (drawingId: DrawingID) => Promise<void>;
100
+ /**
101
+ * Disconnects the drawing, connects its client again and recalculates the model (`v1.common.recalc`).
102
+ *
103
+ * @param drawingId - The drawing.
104
+ */
105
+ reconnect: (drawingId: DrawingID) => Promise<void>;
106
+ /**
107
+ * Loads the drawing's structure tree from the engine into the store.
108
+ *
109
+ * @param drawingId - The drawing.
110
+ */
111
+ fetchTree: (drawingId: DrawingID) => Promise<void>;
112
+ /**
113
+ * Effective per-connection emission config of the drawing's client (see {@link IComClient.getEmissionConfig}).
114
+ *
115
+ * @param drawingId - The drawing.
116
+ */
117
+ getEmissionConfig: (drawingId: DrawingID) => Promise<EmissionConfig>;
118
+ /**
119
+ * Merges `partial` into the per-connection emission config and returns the effective flags.
120
+ *
121
+ * @param drawingId - The drawing.
122
+ * @param partial - The flags to change; the others stay as they are.
123
+ */
124
+ setEmissionConfig: (drawingId: DrawingID, partial: Partial<EmissionConfig>) => Promise<EmissionConfig>;
125
+ /**
126
+ * Runs `fn` with a temporary emission config and restores the previous one
127
+ * afterwards (also when `fn` throws). This is the "own config for a
128
+ * script" pattern: e.g. switch every graphic category off while a script
129
+ * issues hundreds of commands, then restore the app's config and fetch
130
+ * tree + graphic once. On engines without GetEmissionConfig/SetEmissionConfig
131
+ * ({@link EMISSION_CONFIG_UNSUPPORTED}) `fn` simply runs with the fixed config.
132
+ *
133
+ * Only the flags in `partial` are restored. Resolves to what `fn` resolves to. {@link EmissionConfig} has an
134
+ * example.
135
+ *
136
+ * @param drawingId - The drawing.
137
+ * @param partial - The flags to change while `fn` runs, e.g. `{ sendGraphic_Kernel: false }`.
138
+ * @param fn - The work to do with them.
139
+ */
140
+ withEmissionConfig: <T>(drawingId: DrawingID, partial: Partial<EmissionConfig>, fn: () => Promise<T>) => Promise<T>;
141
+ /**
142
+ * Steps back in the drawing's undo history, to `state` when given ({@link AwvNodeClient.undo}).
143
+ *
144
+ * Messages of the engine are logged as warnings; an error is logged, not thrown.
145
+ *
146
+ * @param drawingId - The drawing.
147
+ * @param state - The state to go back to, a name from the drawing's `cad.states.stack`.
148
+ */
149
+ undo: (drawingId: DrawingID, state?: string) => Promise<void>;
150
+ /**
151
+ * Steps forward in the drawing's undo history, to `state` when given ({@link AwvNodeClient.redo}).
152
+ *
153
+ * Messages of the engine are logged as warnings; an error is logged, not thrown.
154
+ *
155
+ * @param drawingId - The drawing.
156
+ * @param state - The state to go forward to, a name from the drawing's `cad.states.stack`.
157
+ */
158
+ redo: (drawingId: DrawingID, state?: string) => Promise<void>;
159
+ /**
160
+ * Sends a command of the server's own ({@link AwvNodeClient.executeMiddleware}) and resolves to the reply.
161
+ *
162
+ * Messages of the reply are logged as warnings; on an error it is logged and the call resolves to undefined.
163
+ *
164
+ * @param drawingId - The drawing.
165
+ * @param middlewareCommand - The command's name.
166
+ * @param data - Fields sent along with the command.
167
+ */
168
+ callMiddleware: (drawingId: DrawingID, middlewareCommand: string, data: any) => Promise<import(".").ServerResponse | undefined>;
169
+ };
170
+ /** The id of the drawing the facade connected. Throws before `connect()`. */
171
+ get drawingId(): DrawingID;
172
+ /**
173
+ * The drawing's ClassCAD API ({@link ClassCADApi}): calls resolve to their result and reject on an error.
174
+ * Throws before `connect()` and after `disconnect()`.
175
+ */
176
+ get api(): ClassCADApi;
177
+ /**
178
+ * Disconnects from ClassCAD and removes the drawing from the SDK's store. The facade can `connect()` again.
179
+ *
180
+ * A failing disconnect does not keep the drawing from being removed.
181
+ */
182
+ destroy(): Promise<void>;
183
+ /**
184
+ * Creates a drawing, connects it to ClassCAD with a client from the factory given to {@link init}, and makes its
185
+ * `api` available.
186
+ *
187
+ * Rejects when the facade is connected already, when `init` has not been called, and when connecting fails: then
188
+ * with the error that kept the client from connecting (a token the key service refuses, an engine that cannot be
189
+ * reached), and the drawing it made is removed again.
190
+ *
191
+ * @param drawingName - The drawing's name in the store; by default `Drawing #<n>`.
192
+ * @returns The id of the new drawing.
193
+ */
194
+ connect(drawingName?: string): Promise<DrawingID>;
195
+ /**
196
+ * Disconnects from ClassCAD. The drawing stays in the SDK's store, reset (without its model), and keeps its
197
+ * client; `api` is not available until {@link BuerliCadFacade.reconnect}.
198
+ */
199
+ disconnect(): Promise<void>;
200
+ /**
201
+ * Disconnects, connects the drawing's client again and recalculates the model (`v1.common.recalc`); then `api` is
202
+ * available again.
203
+ */
204
+ reconnect(): Promise<void>;
205
+ /**
206
+ * The structure tree (id -> node) of the drawing, as held by the SDK's store.
207
+ * The tree is kept up to date by the regular structure broadcast; pass
208
+ * `refresh: true` to explicitly request it from ClassCAD first.
209
+ *
210
+ * @param opts - Options.
211
+ * @param opts.refresh - Loads the tree from ClassCAD before reading it.
212
+ * @returns The structure tree, keyed by object id.
213
+ * @example
214
+ * ```ts
215
+ * import { ccUtils, ScgClassType } from '@classcad/client'
216
+ *
217
+ * // The parts of a loaded model, by name
218
+ * const tree = await facade.tree({ refresh: true })
219
+ * const parts = Object.values(tree).filter(node => ccUtils.base.isA(node.class, ScgClassType.CCPart))
220
+ * const wheel = parts.find(node => node.name === 'Wheel')
221
+ * console.log(parts.map(node => node.name), wheel?.id)
222
+ * ```
223
+ */
224
+ tree(opts?: {
225
+ refresh?: boolean;
226
+ }): Promise<ScgTree>;
227
+ /**
228
+ * The current graphic (tessellation) of the drawing as `{ containers }`, as
229
+ * held by the SDK's store. Pass `recalc: true` to recalculate first.
230
+ *
231
+ * Note that graphic element ids are payload-local - they rotate on every
232
+ * re-tessellation. The stable join between graphic and structure tree is
233
+ * `container.owner === <CC_Solid id>`.
234
+ *
235
+ * @param opts - Options.
236
+ * @param opts.recalc - Recalculates the model before reading the graphic.
237
+ * @returns The graphic containers, or `null` if the drawing is not available.
238
+ * @example
239
+ * ```ts
240
+ * import * as THREE from 'three'
241
+ *
242
+ * // Frames the camera on the model: the bounds of every body
243
+ * const graphic = await facade.graphic()
244
+ * const bounds = new THREE.Box3()
245
+ * for (const container of graphic?.containers ?? []) {
246
+ * if (!container.meshes?.length) continue
247
+ * bounds.expandByPoint(new THREE.Vector3().fromArray(container.properties.min))
248
+ * bounds.expandByPoint(new THREE.Vector3().fromArray(container.properties.max))
249
+ * }
250
+ * const center = bounds.getCenter(new THREE.Vector3())
251
+ * const size = bounds.getSize(new THREE.Vector3()).length()
252
+ * camera.position.copy(center).add(new THREE.Vector3(0, -size, size))
253
+ * camera.lookAt(center)
254
+ * ```
255
+ */
256
+ graphic(opts?: {
257
+ recalc?: boolean;
258
+ }): Promise<{
259
+ /** One per body or curve: its meshes, edges and vertices; `owner` is the model object it belongs to. */
260
+ containers: ScgGraphicContainer[];
261
+ } | null>;
262
+ /**
263
+ * Creates the buffer geometry of any product (part or assembly).
264
+ *
265
+ * Each part, and each instance of a part in an assembly, becomes one geometry: its bodies merged, placed where it
266
+ * is in the model. Bodies the store has no graphic for yet are requested from ClassCAD first. Rejects when an id is
267
+ * not in the drawing's tree.
268
+ *
269
+ * @param objectId - The product, its instance or a solid; or several of them.
270
+ * @returns The geometries, or undefined when there is no id or nothing to show.
271
+ * @example
272
+ * ```ts
273
+ * import * as THREE from 'three'
274
+ *
275
+ * // A cylinder with diameter 20 and height 30, as a mesh of one's own
276
+ * const part = (await facade.api.v1.part.create({ name: 'Pin' }))!
277
+ * await facade.api.v1.part.cylinder({ id: part, diameter: 20, height: 30 })
278
+ * const [geometry] = (await facade.createBufferGeometry(part)) ?? []
279
+ * if (geometry) scene.add(new THREE.Mesh(geometry, new THREE.MeshStandardMaterial({ color: 'orange' })))
280
+ * ```
281
+ */
282
+ createBufferGeometry(objectId?: ObjectID | ObjectID[]): Promise<BufferGeometry[] | undefined>;
283
+ /**
284
+ * Creates the threeJS scene of any product (part or assembly).
285
+ *
286
+ * Assemblies and instances become groups placed as in the model, parts become groups of their bodies. A body is
287
+ * one mesh per color (`meshPerGeometry: false`, default) or one mesh per face. Bodies the store has no graphic
288
+ * for yet are requested from ClassCAD first. Rejects when an id is not in the drawing's tree.
289
+ *
290
+ * @param objectId - The product, its instance or a solid, or several of them; by default the drawing's root.
291
+ * @param options - Options.
292
+ * @param options.meshPerGeometry - Makes a mesh for each face (its `userData.id` is the face's graphic id) instead
293
+ * of merging a body's faces of one color into one mesh.
294
+ * @param options.structureOnly - Makes the nodes without geometry and materials.
295
+ * @returns The scene, its nodes and their materials.
296
+ * @example
297
+ * ```ts
298
+ * import * as THREE from 'three'
299
+ *
300
+ * // The whole assembly in a three.js scene, a node per instance
301
+ * const { scene: model, nodes } = await facade.createScene(assembly)
302
+ * scene.add(model)
303
+ * // The nodes by the id of the object they show, and by name
304
+ * nodes[`${wheel}`].rotation.z = Math.PI / 4
305
+ * ```
306
+ */
307
+ createScene(objectId?: ObjectID | ObjectID[], options?: {
308
+ meshPerGeometry?: boolean;
309
+ structureOnly?: boolean;
310
+ }): Promise<{
311
+ /** The scene, with a node for each product. */
312
+ scene: Scene;
313
+ /** The groups and meshes, by name and by the id of the object they show (`userData.id`). */
314
+ nodes: {
315
+ [key: string]: Object3D;
316
+ };
317
+ /** The meshes' materials, by name (`<mesh name>_material`). */
318
+ materials: {
319
+ [key: string]: Material;
320
+ };
321
+ }>;
322
+ /**
323
+ * Adds the curves of a three.js `Shape` to a shape curve of the model, in one batch of API calls.
324
+ *
325
+ * Lines, arcs and ellipses, quadratic and cubic Bézier curves and splines (as interpolation curves) are added, in
326
+ * the XY plane; other curves and the shape's holes are not.
327
+ *
328
+ * @param owner - The shape curve, from `v1.curve.shape`.
329
+ * @param shape - The outline.
330
+ * @example
331
+ * ```ts
332
+ * import * as THREE from 'three'
333
+ *
334
+ * // A disc, extruded from a three.js outline
335
+ * const part = (await facade.api.v1.part.create({ name: 'Disc' }))!
336
+ * const ei = (await facade.api.v1.part.entityInjection({ id: part }))!
337
+ * const outline = new THREE.Shape()
338
+ * outline.absarc(0, 0, 40, 0, Math.PI * 2, false)
339
+ * const curve = (await facade.api.v1.curve.shape({ id: ei }))!
340
+ * await facade.createThreeShape(curve, outline)
341
+ * await facade.api.v1.solid.extrusion({ id: ei, curves: [curve], direction: [0, 0, 5] })
342
+ * ```
343
+ */
344
+ createThreeShape(owner: ObjectID, shape: THREE.Shape): Promise<void>;
345
+ /**
346
+ * Adds a polyline through the given points to a shape curve of the model, its corners rounded where a radius is
347
+ * given (`v1.curve.polyline2d`).
348
+ *
349
+ * A corner with a radius above 0 becomes an arc of that radius. A corner whose arc does not fit between its
350
+ * neighbours is left out.
351
+ *
352
+ * @param owner - The shape curve, from `v1.curve.shape`.
353
+ * @param fPts - The corners, each with the radius to round it with (0 for a sharp corner).
354
+ * @param close - Closes the polyline. Default `true`.
355
+ * @example
356
+ * ```ts
357
+ * import * as THREE from 'three'
358
+ *
359
+ * // A plate with two rounded corners, extruded from a polyline
360
+ * const part = (await facade.api.v1.part.create({ name: 'Plate' }))!
361
+ * const ei = (await facade.api.v1.part.entityInjection({ id: part }))!
362
+ * const curve = (await facade.api.v1.curve.shape({ id: ei }))!
363
+ * await facade.createPolyline(curve, [
364
+ * { point: new THREE.Vector3(0, 0, 0), radius: 0 },
365
+ * { point: new THREE.Vector3(100, 0, 0), radius: 10 },
366
+ * { point: new THREE.Vector3(100, 50, 0), radius: 10 },
367
+ * { point: new THREE.Vector3(0, 50, 0), radius: 0 },
368
+ * ])
369
+ * await facade.api.v1.solid.extrusion({ id: ei, curves: [curve], direction: [0, 0, 8] })
370
+ * ```
371
+ */
372
+ createPolyline(owner: ObjectID, fPts: {
373
+ point: THREE.Vector3;
374
+ radius: number;
375
+ }[], close?: boolean): Promise<void>;
376
+ /**
377
+ * Lets the user pick geometry of the given types in the 3D view, and resolves with what was picked.
378
+ *
379
+ * The drawing's geometry must be shown for selection, for example by `BuerliGeometry` of `@classcad/react` with
380
+ * `selection`. With a count it resolves once that many items are picked; with a function, that function is
381
+ * called at the first pick with one that ends the selection. Each item carries the picked element's ids, and in
382
+ * `userData` its geometry in world coordinates and its positions (`matchingPoints`).
383
+ *
384
+ * @param types - The kinds of geometry that can be picked.
385
+ * @param countOrResolver - How many items to pick (default 1), or a function that gets the function that ends the
386
+ * selection.
387
+ * @returns The picked items.
388
+ * @example
389
+ * ```ts
390
+ * import { ScgGraphicType } from '@classcad/client'
391
+ *
392
+ * // A box whose edges the user picks to round them; the drawing is shown with <BuerliGeometry selection />
393
+ * const part = (await facade.api.v1.part.create({ name: 'Block' }))!
394
+ * await facade.api.v1.part.box({ id: part, length: 60, width: 40, height: 20 })
395
+ * const edges = await facade.selectGeometry([ScgGraphicType.LINE, ScgGraphicType.ARC], 2)
396
+ * await facade.api.v1.part.fillet({ id: part, references: edges.map(edge => edge.graphicId!), radius: 4 })
397
+ * ```
398
+ * @example
399
+ * ```ts
400
+ * import { ScgGraphicType } from '@classcad/client'
401
+ *
402
+ * // As many faces as the user likes, until "Done"
403
+ * const faces = await facade.selectGeometry([ScgGraphicType.PLANE, ScgGraphicType.CYLINDER], finish => {
404
+ * doneButton.onclick = () => finish()
405
+ * })
406
+ * ```
407
+ */
408
+ selectGeometry(types: GrT[], countOrResolver?: number | ((resolve: () => void) => void)): Promise<InteractionInfo[]>;
409
+ }
410
+ export {};
@@ -0,0 +1,180 @@
1
+ import { DrawingID, ObjectID, ObjectIdent, WorkGeomType } from '@classcad/sdkjs';
2
+ import { CircularPatternConstraint, CylindricalConstraint, FastenedConstraint, FastenedOriginConstraint, GroupConstraint, IStructureTree, LinearPatternConstraint, ParallelConstraint, PlanarConstraint, RevoluteConstraint, SliderConstraint } from '../../re-export';
3
+ /**
4
+ * Finds the product of given reference in the structure tree
5
+ *
6
+ * @param refOrRefEtId The reference id or referenceET id.
7
+ * @param tree The structure tree.
8
+ * @returns The resolved product for the provided reference _refOrRefEtId_. If no product was found, _undefined_ is returned.
9
+ */
10
+ export declare const findProduct: (refOrRefEtId: ObjectID, tree: IStructureTree) => ObjectID | undefined;
11
+ /**
12
+ * @deprecated use specific methods e.g. getFastenedConstraint() instead, getConstraint() will be removed in a future release.
13
+ *
14
+ * Returns the fastened or fastened origin constraint of given reference with specified name.
15
+ *
16
+ * @param drawingId The drawing id.
17
+ * @param refId The product reference to look for constraint.
18
+ * @param constrName The name of constraint to look for.
19
+ * @returns The constraint information as array. The array is empty if no constraint was found.
20
+ */
21
+ export declare const getConstraint: (drawingId: DrawingID, refId: ObjectID, constrName?: string) => any[];
22
+ /**
23
+ * Returns the fastened constraint of given reference with specified name.
24
+ *
25
+ * @param drawingId The drawing id.
26
+ * @param refId The product reference to look for constraint.
27
+ * @param constrName The name of constraint to look for.
28
+ * @returns The found fastened constraint as object or undefined if nothing has been found
29
+ */
30
+ export declare const getFastenedConstraint: (drawingId: DrawingID, refId: ObjectID, constrName: string) => Omit<Required<FastenedConstraint>, "useCurrentTransform"> | undefined;
31
+ /**
32
+ * Returns the fastened origin constraint of given reference with specified name.
33
+ *
34
+ * @param drawingId The drawing id.
35
+ * @param refId The product reference to look for constraint.
36
+ * @param constrName The name of constraint to look for.
37
+ * @returns The found fastened origin constraint as object or undefined if nothing has been found
38
+ */
39
+ export declare const getFastenedOriginConstraint: (drawingId: DrawingID, refId: ObjectID, constrName: string) => Omit<Required<FastenedOriginConstraint>, "useCurrentTransform"> | undefined;
40
+ /**
41
+ * Returns the revolute constraint of given reference with specified name.
42
+ *
43
+ * @param drawingId The drawing id.
44
+ * @param refId The product reference to look for constraint.
45
+ * @param constrName The name of constraint to look for.
46
+ * @returns The found revolute constraint as object or undefined if nothing has been found
47
+ */
48
+ export declare const getRevoluteConstraint: (drawingId: DrawingID, refId: ObjectID, constrName: string) => RevoluteConstraint | undefined;
49
+ /**
50
+ * Returns the slider constraint of given reference with specified name.
51
+ *
52
+ * @param drawingId The drawing id.
53
+ * @param refId The product reference to look for constraint.
54
+ * @param constrName The name of constraint to look for.
55
+ * @returns The found slider constraint as object or undefined if nothing has been found
56
+ */
57
+ export declare const getSliderConstraint: (drawingId: DrawingID, refId: ObjectID, constrName: string) => SliderConstraint | undefined;
58
+ /**
59
+ * Returns the planar constraint of given reference with specified name.
60
+ *
61
+ * @param drawingId The drawing id.
62
+ * @param refId The product reference to look for constraint.
63
+ * @param constrName The name of constraint to look for.
64
+ * @returns The found planar constraint as object or undefined if nothing has been found
65
+ */
66
+ export declare const getPlanarConstraint: (drawingId: DrawingID, refId: ObjectID, constrName: string) => PlanarConstraint | undefined;
67
+ /**
68
+ * Returns the parallel constraint of given reference with specified name.
69
+ *
70
+ * @param drawingId The drawing id.
71
+ * @param refId The product reference to look for constraint.
72
+ * @param constrName The name of constraint to look for.
73
+ * @returns The found parallel constraint as object or undefined if nothing has been found
74
+ */
75
+ export declare const getParallelConstraint: (drawingId: DrawingID, refId: ObjectID, constrName: string) => ParallelConstraint | undefined;
76
+ /**
77
+ * Returns the cylindrical constraint of given reference with specified name.
78
+ *
79
+ * @param drawingId The drawing id.
80
+ * @param refId The product reference to look for constraint.
81
+ * @param constrName The name of constraint to look for.
82
+ * @returns The found cylindrical constraint as object or undefined if nothing has been found
83
+ */
84
+ export declare const getCylindricalConstraint: (drawingId: DrawingID, refId: ObjectID, constrName: string) => CylindricalConstraint | undefined;
85
+ /**
86
+ * Returns the group constraint of given reference with specified name.
87
+ *
88
+ * @param drawingId The drawing id.
89
+ * @param refId The product reference to look for constraint.
90
+ * @param constrName The name of constraint to look for.
91
+ * @returns The found group constraint as object or undefined if nothing has been found
92
+ */
93
+ export declare const getGroupConstraint: (drawingId: DrawingID, refId: ObjectID, constrName: string) => GroupConstraint | undefined;
94
+ /**
95
+ * Returns the linear pattern constraint of given reference with specified name.
96
+ *
97
+ * @param drawingId The drawing id.
98
+ * @param refId The product reference to look for constraint.
99
+ * @param constrName The name of constraint to look for.
100
+ * @returns The found linear pattern constraint as object or undefined if nothing has been found
101
+ */
102
+ export declare const getLinearPatternConstraint: (drawingId: DrawingID, refId: ObjectID, constrName: string) => LinearPatternConstraint | undefined;
103
+ /**
104
+ * Returns the circular pattern constraint of given reference with specified name.
105
+ *
106
+ * @param drawingId The drawing id.
107
+ * @param refId The product reference to look for constraint.
108
+ * @param constrName The name of constraint to look for.
109
+ * @returns The found circular pattern constraint as object or undefined if nothing has been found
110
+ */
111
+ export declare const getCircularPatternConstraint: (drawingId: DrawingID, refId: ObjectID, constrName: string) => CircularPatternConstraint | undefined;
112
+ /**
113
+ * @deprecated use getWorkGeometry() instead, getWorkCoordSystem() will be removed in a future release.
114
+ *
115
+ * Returns all workcoordsystems of given reference with specified name.
116
+ * If _wcsName_ is undefined, all workcoordsystems of given reference will be returned.
117
+ *
118
+ * @param drawingId The drawing id.
119
+ * @param refId The product reference to look for wcs.
120
+ * @param wcsName The name of wcs to look for.
121
+ * @returns An array of ids of all workcoordsystems found. The array is empty if nothing was found.
122
+ */
123
+ export declare const getWorkCoordSystem: (drawingId: DrawingID, refId: ObjectID, wcsName?: string) => ObjectID[];
124
+ /**
125
+ * Returns all work geometry of given type and given reference with specified name.
126
+ * If wgName is undefined, all work geometry of given reference will be returned.
127
+ *
128
+ * @param drawingId The drawing id.
129
+ * @param refId The product reference to look for work geometry.
130
+ * @param type The type of work geometry to look for
131
+ * @param wgName The name of work geometry to look for.
132
+ * @returns An array of ids of all found work geometry. The array is empty if nothing was found.
133
+ */
134
+ export declare const getWorkGeometry: (drawingId: DrawingID, refId: ObjectID, type: WorkGeomType, wgName?: string) => ObjectID[];
135
+ /**
136
+ * Returns the part template with given identifier or name from part container.
137
+ * If _partName_ is undefined, all parts from part container will be returned.
138
+ *
139
+ * @param drawingId The drawing id.
140
+ * @param partName The identifier or name of the part to look for.
141
+ * @returns An array of ids of all parts found. The array is empty if nothing was found.
142
+ */
143
+ export declare const getPartTemplate: (drawingId: DrawingID, partName?: string) => ObjectID[];
144
+ /**
145
+ * Returns the assembly template with given identifier or name from assembly container.
146
+ * If _asmName_ is undefined, all assemblies from assembly container will be returned.
147
+ *
148
+ * @param drawingId The drawing id.
149
+ * @param asmName The identifier or name of the assembly to look for.
150
+ * @returns An array of ids of all assemblies found. The array is empty if nothing was found.
151
+ */
152
+ export declare const getAssemblyTemplate: (drawingId: DrawingID, asmName?: string) => ObjectID[];
153
+ /**
154
+ * Returns an instance or all instances of a node, depending on whether a name is given or not.
155
+ * The node is the parent of the instance/instances we're looking for and can be a root assembly,
156
+ * another instance or an assembly template.
157
+ *
158
+ * @param drawingId The drawing id.
159
+ * @param id id of the node from which we are searching the children for instances that have the name we are looking for.
160
+ * @param instanceName name of the instance we are looking for
161
+ * @returns array containing the ids of the found instances
162
+ */
163
+ export declare const getInstance: (drawingId: DrawingID, id: ObjectID, instanceName?: string) => ObjectID[];
164
+ /**
165
+ * Returns the coordinate system (global transformation) of the given instance id.
166
+ *
167
+ * @param drawingId The drawing id
168
+ * @param instanceId id of the instance to get the coordinate system (global transformation) from
169
+ * @returns The coordinate system as an two-dimensional array
170
+ */
171
+ export declare const getTransformation: (drawingId: DrawingID, instanceId: ObjectID) => number[][] | undefined;
172
+ /**
173
+ * Creates and returns the mate path as array from the given instance id up to the current instance.
174
+ * This helps to get the right path to set constraints between instances which are located in
175
+ * nested assemblies.
176
+ * @param drawingId The drawing id
177
+ * @param instanceId id of the instance to get the mate path from. Id can be a number or string.
178
+ * @returns The mate path as array from the given instance id up to the current instance
179
+ */
180
+ export declare const getMatePath: (drawingId: DrawingID, instanceId: ObjectID | ObjectIdent) => ObjectID[];
@@ -0,0 +1,55 @@
1
+ import { DrawingID, ObjectID, ObjectIdent } from '@classcad/sdkjs';
2
+ import { CCClasses, IStructureTree } from '../../re-export';
3
+ /**
4
+ * Checks if the given class is equal to the provided type or derives from it.
5
+ *
6
+ * @param objClass The class to check.
7
+ * @param type The type to be checked for.
8
+ * @returns true if objClass is of type or derived from type, false else.
9
+ */
10
+ export declare const isA: (objClass?: string, type?: CCClasses) => boolean;
11
+ /**
12
+ * Gets all children of the given object with the provided type.
13
+ *
14
+ * @param objId The id of the object to get children from.
15
+ * @param type The type of children to search for.
16
+ * @param tree The structure tree.
17
+ * @returns An array of object ids of the found children.
18
+ */
19
+ export declare const getChildren: (objId: ObjectID, type: CCClasses, tree: IStructureTree) => ObjectID[];
20
+ /**
21
+ * Searches for an object's ancestor of specified class.
22
+ * @param drawingId The drawing id.
23
+ * @param objectId The id of the object to search for its ancestor.
24
+ * @param parentClass The CCClass of the ancestor to search for.
25
+ * @returns first found object of specified class.
26
+ */
27
+ export declare const getAncestorIdByClass: (drawingId: DrawingID, objectId: ObjectID, parentClass: CCClasses) => number | null;
28
+ /**
29
+ * Gets all ancestors of the given object.
30
+ * @param drawingId The drawing id.
31
+ * @param objectId The id of the object to get ancestors from.
32
+ * @returns an array of object's ancestors.
33
+ */
34
+ export declare const getAncestors: (drawingId: DrawingID, objectId: ObjectID) => number[];
35
+ /**
36
+ * Gets all descendants of the given object.
37
+ * @param drawingId The drawing id.
38
+ * @param objectId The id of the object to get descendants from.
39
+ * @returns an array of object's descendants.
40
+ */
41
+ export declare const getDescendants: (drawingId: DrawingID, objectId: ObjectID) => number[];
42
+ /**
43
+ * Find first object which can be identified by given identifier or name.
44
+ * If both optional parameters has been set, the identifier is treated with priority.
45
+ * If no object with given identifier will be found, the name is used to find an object, if available.
46
+ * @param drawingId The drawing id.
47
+ * @param options Optional parameters to identify to find object.
48
+ * @param options.ident Identifier to find the object by an identifier
49
+ * @param options.name Name to find the object by its name
50
+ * @returns first found object which meets the searching conditions
51
+ */
52
+ export declare const findObject: (drawingId: DrawingID, options: {
53
+ ident?: ObjectIdent;
54
+ name?: string;
55
+ }) => ObjectID | undefined;