@pooder/kit 4.3.0 → 5.0.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/.test-dist/src/CanvasService.js +249 -0
- package/.test-dist/src/ViewportSystem.js +75 -0
- package/.test-dist/src/background.js +203 -0
- package/.test-dist/src/bridgeSelection.js +20 -0
- package/.test-dist/src/constraints.js +237 -0
- package/.test-dist/src/coordinate.js +74 -0
- package/.test-dist/src/dieline.js +723 -0
- package/.test-dist/src/edgeScale.js +12 -0
- package/.test-dist/src/feature.js +752 -0
- package/.test-dist/src/featureComplete.js +32 -0
- package/.test-dist/src/film.js +167 -0
- package/.test-dist/src/geometry.js +506 -0
- package/.test-dist/src/image.js +1234 -0
- package/.test-dist/src/index.js +35 -0
- package/.test-dist/src/maskOps.js +270 -0
- package/.test-dist/src/mirror.js +104 -0
- package/.test-dist/src/renderSpec.js +2 -0
- package/.test-dist/src/ruler.js +343 -0
- package/.test-dist/src/sceneLayout.js +99 -0
- package/.test-dist/src/sceneLayoutModel.js +196 -0
- package/.test-dist/src/sceneView.js +40 -0
- package/.test-dist/src/sceneVisibility.js +42 -0
- package/.test-dist/src/size.js +332 -0
- package/.test-dist/src/tracer.js +544 -0
- package/.test-dist/src/units.js +30 -0
- package/.test-dist/src/white-ink.js +829 -0
- package/.test-dist/src/wrappedOffsets.js +33 -0
- package/.test-dist/tests/run.js +94 -0
- package/CHANGELOG.md +17 -0
- package/dist/index.d.mts +339 -36
- package/dist/index.d.ts +339 -36
- package/dist/index.js +3587 -854
- package/dist/index.mjs +3580 -856
- package/package.json +2 -2
- package/src/CanvasService.ts +300 -96
- package/src/ViewportSystem.ts +92 -92
- package/src/background.ts +230 -230
- package/src/bridgeSelection.ts +17 -0
- package/src/coordinate.ts +106 -106
- package/src/dieline.ts +897 -955
- package/src/edgeScale.ts +19 -0
- package/src/feature.ts +83 -30
- package/src/film.ts +194 -194
- package/src/geometry.ts +234 -80
- package/src/image.ts +1582 -512
- package/src/index.ts +14 -10
- package/src/maskOps.ts +326 -0
- package/src/mirror.ts +128 -128
- package/src/renderSpec.ts +18 -0
- package/src/ruler.ts +449 -508
- package/src/sceneLayout.ts +121 -0
- package/src/sceneLayoutModel.ts +335 -0
- package/src/sceneVisibility.ts +49 -0
- package/src/size.ts +379 -0
- package/src/tracer.ts +719 -570
- package/src/units.ts +27 -27
- package/src/white-ink.ts +1018 -373
- package/src/wrappedOffsets.ts +33 -0
- package/tests/run.ts +118 -0
- package/tsconfig.test.json +15 -15
package/src/ruler.ts
CHANGED
|
@@ -1,508 +1,449 @@
|
|
|
1
|
-
import {
|
|
2
|
-
Extension,
|
|
3
|
-
ExtensionContext,
|
|
4
|
-
ContributionPointIds,
|
|
5
|
-
CommandContribution,
|
|
6
|
-
ConfigurationContribution,
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
import
|
|
10
|
-
import
|
|
11
|
-
import { formatMm } from "./units";
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
private
|
|
22
|
-
private
|
|
23
|
-
private
|
|
24
|
-
private
|
|
25
|
-
private
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
private
|
|
29
|
-
private
|
|
30
|
-
private
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
this.canvasService
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
this.
|
|
62
|
-
this.
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
this.
|
|
68
|
-
this.
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
);
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
private
|
|
207
|
-
if (!this.canvasService) return;
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
const
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
{ x:
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
);
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
const
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
const
|
|
322
|
-
const
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
const
|
|
366
|
-
const
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
//
|
|
384
|
-
const
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
lineColor,
|
|
390
|
-
);
|
|
391
|
-
layer.add(
|
|
392
|
-
|
|
393
|
-
//
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
layer.add(leftDimLine);
|
|
451
|
-
|
|
452
|
-
// Left Extension Lines
|
|
453
|
-
layer.add(
|
|
454
|
-
new Line(
|
|
455
|
-
[
|
|
456
|
-
leftRulerX - extLen,
|
|
457
|
-
leftRulerYStart,
|
|
458
|
-
leftRulerX + extLen,
|
|
459
|
-
leftRulerYStart,
|
|
460
|
-
],
|
|
461
|
-
{
|
|
462
|
-
stroke: lineColor,
|
|
463
|
-
strokeWidth: 1,
|
|
464
|
-
selectable: false,
|
|
465
|
-
evented: false,
|
|
466
|
-
},
|
|
467
|
-
),
|
|
468
|
-
);
|
|
469
|
-
layer.add(
|
|
470
|
-
new Line(
|
|
471
|
-
[
|
|
472
|
-
leftRulerX - extLen,
|
|
473
|
-
leftRulerYEnd,
|
|
474
|
-
leftRulerX + extLen,
|
|
475
|
-
leftRulerYEnd,
|
|
476
|
-
],
|
|
477
|
-
{
|
|
478
|
-
stroke: lineColor,
|
|
479
|
-
strokeWidth: 1,
|
|
480
|
-
selectable: false,
|
|
481
|
-
evented: false,
|
|
482
|
-
},
|
|
483
|
-
),
|
|
484
|
-
);
|
|
485
|
-
|
|
486
|
-
// Left Text (Centered, Rotated)
|
|
487
|
-
const heightStr = formatMm(displayHeightMm, this.dielineDisplayUnit);
|
|
488
|
-
const leftTextContent = `${heightStr} ${this.dielineDisplayUnit}`;
|
|
489
|
-
const leftText = new Text(leftTextContent, {
|
|
490
|
-
left: leftRulerX,
|
|
491
|
-
top: leftRulerYStart + (rulerBottom - rulerTop) / 2,
|
|
492
|
-
angle: -90,
|
|
493
|
-
fontSize: fontSize,
|
|
494
|
-
fill: textColor,
|
|
495
|
-
fontFamily: "Arial",
|
|
496
|
-
originX: "center",
|
|
497
|
-
originY: "center",
|
|
498
|
-
backgroundColor: backgroundColor,
|
|
499
|
-
selectable: false,
|
|
500
|
-
evented: false,
|
|
501
|
-
});
|
|
502
|
-
layer.add(leftText);
|
|
503
|
-
|
|
504
|
-
// Always bring ruler to front
|
|
505
|
-
this.canvasService.canvas.bringObjectToFront(layer);
|
|
506
|
-
this.canvasService.canvas.requestRenderAll();
|
|
507
|
-
}
|
|
508
|
-
}
|
|
1
|
+
import {
|
|
2
|
+
Extension,
|
|
3
|
+
ExtensionContext,
|
|
4
|
+
ContributionPointIds,
|
|
5
|
+
CommandContribution,
|
|
6
|
+
ConfigurationContribution,
|
|
7
|
+
ConfigurationService,
|
|
8
|
+
} from "@pooder/core";
|
|
9
|
+
import { Rect, Line, Text, Group, Polygon } from "fabric";
|
|
10
|
+
import CanvasService from "./CanvasService";
|
|
11
|
+
import { formatMm } from "./units";
|
|
12
|
+
import { computeSceneLayout, readSizeState } from "./sceneLayoutModel";
|
|
13
|
+
|
|
14
|
+
export class RulerTool implements Extension {
|
|
15
|
+
id = "pooder.kit.ruler";
|
|
16
|
+
|
|
17
|
+
public metadata = {
|
|
18
|
+
name: "RulerTool",
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
private thickness: number = 20;
|
|
22
|
+
private gap: number = 15;
|
|
23
|
+
private backgroundColor: string = "#f0f0f0";
|
|
24
|
+
private textColor: string = "#333333";
|
|
25
|
+
private lineColor: string = "#999999";
|
|
26
|
+
private fontSize: number = 10;
|
|
27
|
+
|
|
28
|
+
private canvasService?: CanvasService;
|
|
29
|
+
private context?: ExtensionContext;
|
|
30
|
+
private onCanvasResized = () => {
|
|
31
|
+
this.updateRuler();
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
constructor(
|
|
35
|
+
options?: Partial<{
|
|
36
|
+
thickness: number;
|
|
37
|
+
backgroundColor: string;
|
|
38
|
+
textColor: string;
|
|
39
|
+
lineColor: string;
|
|
40
|
+
fontSize: number;
|
|
41
|
+
}>,
|
|
42
|
+
) {
|
|
43
|
+
if (options) {
|
|
44
|
+
Object.assign(this, options);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
activate(context: ExtensionContext) {
|
|
49
|
+
this.context = context;
|
|
50
|
+
this.canvasService = context.services.get<CanvasService>("CanvasService");
|
|
51
|
+
if (!this.canvasService) {
|
|
52
|
+
console.warn("CanvasService not found for RulerTool");
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
const configService = context.services.get<ConfigurationService>(
|
|
57
|
+
"ConfigurationService",
|
|
58
|
+
);
|
|
59
|
+
if (configService) {
|
|
60
|
+
// Load initial config
|
|
61
|
+
this.thickness = configService.get("ruler.thickness", this.thickness);
|
|
62
|
+
this.gap = configService.get("ruler.gap", this.gap);
|
|
63
|
+
this.backgroundColor = configService.get(
|
|
64
|
+
"ruler.backgroundColor",
|
|
65
|
+
this.backgroundColor,
|
|
66
|
+
);
|
|
67
|
+
this.textColor = configService.get("ruler.textColor", this.textColor);
|
|
68
|
+
this.lineColor = configService.get("ruler.lineColor", this.lineColor);
|
|
69
|
+
this.fontSize = configService.get("ruler.fontSize", this.fontSize);
|
|
70
|
+
|
|
71
|
+
// Listen for changes
|
|
72
|
+
configService.onAnyChange((e: { key: string; value: any }) => {
|
|
73
|
+
let shouldUpdate = false;
|
|
74
|
+
if (e.key.startsWith("ruler.")) {
|
|
75
|
+
const prop = e.key.split(".")[1];
|
|
76
|
+
if (prop && prop in this) {
|
|
77
|
+
(this as any)[prop] = e.value;
|
|
78
|
+
shouldUpdate = true;
|
|
79
|
+
}
|
|
80
|
+
} else if (e.key.startsWith("size.")) {
|
|
81
|
+
shouldUpdate = true;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
if (shouldUpdate) {
|
|
85
|
+
this.updateRuler();
|
|
86
|
+
}
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
this.createLayer();
|
|
91
|
+
context.eventBus.on("canvas:resized", this.onCanvasResized);
|
|
92
|
+
this.updateRuler();
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
deactivate(context: ExtensionContext) {
|
|
96
|
+
context.eventBus.off("canvas:resized", this.onCanvasResized);
|
|
97
|
+
this.destroyLayer();
|
|
98
|
+
this.canvasService = undefined;
|
|
99
|
+
this.context = undefined;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
contribute() {
|
|
103
|
+
return {
|
|
104
|
+
[ContributionPointIds.CONFIGURATIONS]: [
|
|
105
|
+
{
|
|
106
|
+
id: "ruler.thickness",
|
|
107
|
+
type: "number",
|
|
108
|
+
label: "Thickness",
|
|
109
|
+
min: 10,
|
|
110
|
+
max: 100,
|
|
111
|
+
default: 20,
|
|
112
|
+
},
|
|
113
|
+
{
|
|
114
|
+
id: "ruler.gap",
|
|
115
|
+
type: "number",
|
|
116
|
+
label: "Gap",
|
|
117
|
+
min: 0,
|
|
118
|
+
max: 100,
|
|
119
|
+
default: 15,
|
|
120
|
+
},
|
|
121
|
+
{
|
|
122
|
+
id: "ruler.backgroundColor",
|
|
123
|
+
type: "color",
|
|
124
|
+
label: "Background Color",
|
|
125
|
+
default: "#f0f0f0",
|
|
126
|
+
},
|
|
127
|
+
{
|
|
128
|
+
id: "ruler.textColor",
|
|
129
|
+
type: "color",
|
|
130
|
+
label: "Text Color",
|
|
131
|
+
default: "#333333",
|
|
132
|
+
},
|
|
133
|
+
{
|
|
134
|
+
id: "ruler.lineColor",
|
|
135
|
+
type: "color",
|
|
136
|
+
label: "Line Color",
|
|
137
|
+
default: "#999999",
|
|
138
|
+
},
|
|
139
|
+
{
|
|
140
|
+
id: "ruler.fontSize",
|
|
141
|
+
type: "number",
|
|
142
|
+
label: "Font Size",
|
|
143
|
+
min: 8,
|
|
144
|
+
max: 24,
|
|
145
|
+
default: 10,
|
|
146
|
+
},
|
|
147
|
+
] as ConfigurationContribution[],
|
|
148
|
+
[ContributionPointIds.COMMANDS]: [
|
|
149
|
+
{
|
|
150
|
+
command: "setTheme",
|
|
151
|
+
title: "Set Ruler Theme",
|
|
152
|
+
handler: (
|
|
153
|
+
theme: Partial<{
|
|
154
|
+
backgroundColor: string;
|
|
155
|
+
textColor: string;
|
|
156
|
+
lineColor: string;
|
|
157
|
+
fontSize: number;
|
|
158
|
+
thickness: number;
|
|
159
|
+
}>,
|
|
160
|
+
) => {
|
|
161
|
+
const oldState = {
|
|
162
|
+
backgroundColor: this.backgroundColor,
|
|
163
|
+
textColor: this.textColor,
|
|
164
|
+
lineColor: this.lineColor,
|
|
165
|
+
fontSize: this.fontSize,
|
|
166
|
+
thickness: this.thickness,
|
|
167
|
+
};
|
|
168
|
+
const newState = { ...oldState, ...theme };
|
|
169
|
+
if (JSON.stringify(newState) === JSON.stringify(oldState))
|
|
170
|
+
return true;
|
|
171
|
+
|
|
172
|
+
Object.assign(this, newState);
|
|
173
|
+
this.updateRuler();
|
|
174
|
+
return true;
|
|
175
|
+
},
|
|
176
|
+
},
|
|
177
|
+
] as CommandContribution[],
|
|
178
|
+
};
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
private getLayer() {
|
|
182
|
+
return this.canvasService?.getLayer("ruler-overlay");
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
private createLayer() {
|
|
186
|
+
if (!this.canvasService) return;
|
|
187
|
+
|
|
188
|
+
const canvas = this.canvasService.canvas;
|
|
189
|
+
const width = canvas.width || 800;
|
|
190
|
+
const height = canvas.height || 600;
|
|
191
|
+
|
|
192
|
+
const layer = this.canvasService.createLayer("ruler-overlay", {
|
|
193
|
+
width,
|
|
194
|
+
height,
|
|
195
|
+
selectable: false,
|
|
196
|
+
evented: false,
|
|
197
|
+
left: 0,
|
|
198
|
+
top: 0,
|
|
199
|
+
originX: "left",
|
|
200
|
+
originY: "top",
|
|
201
|
+
});
|
|
202
|
+
|
|
203
|
+
canvas.bringObjectToFront(layer);
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
private destroyLayer() {
|
|
207
|
+
if (!this.canvasService) return;
|
|
208
|
+
const layer = this.getLayer();
|
|
209
|
+
if (layer) {
|
|
210
|
+
this.canvasService.canvas.remove(layer);
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
private createArrowLine(
|
|
215
|
+
x1: number,
|
|
216
|
+
y1: number,
|
|
217
|
+
x2: number,
|
|
218
|
+
y2: number,
|
|
219
|
+
color: string,
|
|
220
|
+
): Group {
|
|
221
|
+
const line = new Line([x1, y1, x2, y2], {
|
|
222
|
+
stroke: color,
|
|
223
|
+
strokeWidth: this.thickness / 20, // Scale stroke width relative to thickness (default 1)
|
|
224
|
+
selectable: false,
|
|
225
|
+
evented: false,
|
|
226
|
+
});
|
|
227
|
+
|
|
228
|
+
// Arrow size proportional to thickness
|
|
229
|
+
const arrowSize = Math.max(4, this.thickness * 0.3);
|
|
230
|
+
const angle = Math.atan2(y2 - y1, x2 - x1);
|
|
231
|
+
|
|
232
|
+
// End Arrow (at x2, y2)
|
|
233
|
+
const endArrow = new Polygon(
|
|
234
|
+
[
|
|
235
|
+
{ x: 0, y: 0 },
|
|
236
|
+
{ x: -arrowSize, y: -arrowSize / 2 },
|
|
237
|
+
{ x: -arrowSize, y: arrowSize / 2 },
|
|
238
|
+
],
|
|
239
|
+
{
|
|
240
|
+
fill: color,
|
|
241
|
+
left: x2,
|
|
242
|
+
top: y2,
|
|
243
|
+
originX: "right",
|
|
244
|
+
originY: "center",
|
|
245
|
+
angle: (angle * 180) / Math.PI,
|
|
246
|
+
selectable: false,
|
|
247
|
+
evented: false,
|
|
248
|
+
},
|
|
249
|
+
);
|
|
250
|
+
|
|
251
|
+
// Start Arrow (at x1, y1)
|
|
252
|
+
const startArrow = new Polygon(
|
|
253
|
+
[
|
|
254
|
+
{ x: 0, y: 0 },
|
|
255
|
+
{ x: arrowSize, y: -arrowSize / 2 },
|
|
256
|
+
{ x: arrowSize, y: arrowSize / 2 },
|
|
257
|
+
],
|
|
258
|
+
{
|
|
259
|
+
fill: color,
|
|
260
|
+
left: x1,
|
|
261
|
+
top: y1,
|
|
262
|
+
originX: "left",
|
|
263
|
+
originY: "center",
|
|
264
|
+
angle: (angle * 180) / Math.PI,
|
|
265
|
+
selectable: false,
|
|
266
|
+
evented: false,
|
|
267
|
+
},
|
|
268
|
+
);
|
|
269
|
+
|
|
270
|
+
return new Group([line, startArrow, endArrow], {
|
|
271
|
+
selectable: false,
|
|
272
|
+
evented: false,
|
|
273
|
+
});
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
private updateRuler() {
|
|
277
|
+
if (!this.canvasService) return;
|
|
278
|
+
const layer = this.getLayer();
|
|
279
|
+
if (!layer) return;
|
|
280
|
+
|
|
281
|
+
layer.remove(...layer.getObjects());
|
|
282
|
+
|
|
283
|
+
const { backgroundColor, lineColor, textColor, fontSize } = this;
|
|
284
|
+
|
|
285
|
+
const configService = this.context?.services.get<ConfigurationService>(
|
|
286
|
+
"ConfigurationService",
|
|
287
|
+
);
|
|
288
|
+
if (!configService) return;
|
|
289
|
+
const sizeState = readSizeState(configService);
|
|
290
|
+
const layout = computeSceneLayout(this.canvasService, sizeState);
|
|
291
|
+
if (!layout) return;
|
|
292
|
+
|
|
293
|
+
const trimRect = layout.trimRect;
|
|
294
|
+
const cutRect = layout.cutRect;
|
|
295
|
+
const useCutAsRuler = layout.cutMode === "outset";
|
|
296
|
+
const rulerRect = useCutAsRuler ? cutRect : trimRect;
|
|
297
|
+
// Use gap configuration
|
|
298
|
+
const gap = this.gap || 15;
|
|
299
|
+
|
|
300
|
+
// New Bounding Box for Ruler
|
|
301
|
+
const rulerLeft = rulerRect.left;
|
|
302
|
+
const rulerTop = rulerRect.top;
|
|
303
|
+
const rulerRight = rulerRect.left + rulerRect.width;
|
|
304
|
+
const rulerBottom = rulerRect.top + rulerRect.height;
|
|
305
|
+
|
|
306
|
+
// Display Dimensions (Physical)
|
|
307
|
+
const displayWidthMm = useCutAsRuler ? layout.cutWidthMm : layout.trimWidthMm;
|
|
308
|
+
const displayHeightMm = useCutAsRuler
|
|
309
|
+
? layout.cutHeightMm
|
|
310
|
+
: layout.trimHeightMm;
|
|
311
|
+
const displayUnit = sizeState.unit;
|
|
312
|
+
|
|
313
|
+
// Ruler Placement Coordinates
|
|
314
|
+
// Top Ruler: Above the top boundary
|
|
315
|
+
const topRulerY = rulerTop - gap;
|
|
316
|
+
const topRulerXStart = rulerLeft;
|
|
317
|
+
const topRulerXEnd = rulerRight;
|
|
318
|
+
|
|
319
|
+
// Left Ruler: Left of the left boundary
|
|
320
|
+
const leftRulerX = rulerLeft - gap;
|
|
321
|
+
const leftRulerYStart = rulerTop;
|
|
322
|
+
const leftRulerYEnd = rulerBottom;
|
|
323
|
+
|
|
324
|
+
// 1. Top Dimension Line (X-Axis)
|
|
325
|
+
const topDimLine = this.createArrowLine(
|
|
326
|
+
topRulerXStart,
|
|
327
|
+
topRulerY,
|
|
328
|
+
topRulerXEnd,
|
|
329
|
+
topRulerY,
|
|
330
|
+
lineColor,
|
|
331
|
+
);
|
|
332
|
+
layer.add(topDimLine);
|
|
333
|
+
|
|
334
|
+
// Top Extension Lines
|
|
335
|
+
const extLen = 5;
|
|
336
|
+
layer.add(
|
|
337
|
+
new Line(
|
|
338
|
+
[
|
|
339
|
+
topRulerXStart,
|
|
340
|
+
topRulerY - extLen,
|
|
341
|
+
topRulerXStart,
|
|
342
|
+
topRulerY + extLen,
|
|
343
|
+
],
|
|
344
|
+
{
|
|
345
|
+
stroke: lineColor,
|
|
346
|
+
strokeWidth: 1,
|
|
347
|
+
selectable: false,
|
|
348
|
+
evented: false,
|
|
349
|
+
},
|
|
350
|
+
),
|
|
351
|
+
);
|
|
352
|
+
layer.add(
|
|
353
|
+
new Line(
|
|
354
|
+
[topRulerXEnd, topRulerY - extLen, topRulerXEnd, topRulerY + extLen],
|
|
355
|
+
{
|
|
356
|
+
stroke: lineColor,
|
|
357
|
+
strokeWidth: 1,
|
|
358
|
+
selectable: false,
|
|
359
|
+
evented: false,
|
|
360
|
+
},
|
|
361
|
+
),
|
|
362
|
+
);
|
|
363
|
+
|
|
364
|
+
// Top Text (Centered)
|
|
365
|
+
const widthStr = formatMm(displayWidthMm, displayUnit);
|
|
366
|
+
const topTextContent = `${widthStr} ${displayUnit}`;
|
|
367
|
+
const topText = new Text(topTextContent, {
|
|
368
|
+
left: topRulerXStart + (rulerRight - rulerLeft) / 2,
|
|
369
|
+
top: topRulerY,
|
|
370
|
+
fontSize: fontSize,
|
|
371
|
+
fill: textColor,
|
|
372
|
+
fontFamily: "Arial",
|
|
373
|
+
originX: "center",
|
|
374
|
+
originY: "center",
|
|
375
|
+
backgroundColor: backgroundColor, // Background mask for readability
|
|
376
|
+
selectable: false,
|
|
377
|
+
evented: false,
|
|
378
|
+
});
|
|
379
|
+
// Add small padding to text background if Fabric supports it directly or via separate rect
|
|
380
|
+
// Fabric Text backgroundColor is tight.
|
|
381
|
+
layer.add(topText);
|
|
382
|
+
|
|
383
|
+
// 2. Left Dimension Line (Y-Axis)
|
|
384
|
+
const leftDimLine = this.createArrowLine(
|
|
385
|
+
leftRulerX,
|
|
386
|
+
leftRulerYStart,
|
|
387
|
+
leftRulerX,
|
|
388
|
+
leftRulerYEnd,
|
|
389
|
+
lineColor,
|
|
390
|
+
);
|
|
391
|
+
layer.add(leftDimLine);
|
|
392
|
+
|
|
393
|
+
// Left Extension Lines
|
|
394
|
+
layer.add(
|
|
395
|
+
new Line(
|
|
396
|
+
[
|
|
397
|
+
leftRulerX - extLen,
|
|
398
|
+
leftRulerYStart,
|
|
399
|
+
leftRulerX + extLen,
|
|
400
|
+
leftRulerYStart,
|
|
401
|
+
],
|
|
402
|
+
{
|
|
403
|
+
stroke: lineColor,
|
|
404
|
+
strokeWidth: 1,
|
|
405
|
+
selectable: false,
|
|
406
|
+
evented: false,
|
|
407
|
+
},
|
|
408
|
+
),
|
|
409
|
+
);
|
|
410
|
+
layer.add(
|
|
411
|
+
new Line(
|
|
412
|
+
[
|
|
413
|
+
leftRulerX - extLen,
|
|
414
|
+
leftRulerYEnd,
|
|
415
|
+
leftRulerX + extLen,
|
|
416
|
+
leftRulerYEnd,
|
|
417
|
+
],
|
|
418
|
+
{
|
|
419
|
+
stroke: lineColor,
|
|
420
|
+
strokeWidth: 1,
|
|
421
|
+
selectable: false,
|
|
422
|
+
evented: false,
|
|
423
|
+
},
|
|
424
|
+
),
|
|
425
|
+
);
|
|
426
|
+
|
|
427
|
+
// Left Text (Centered, Rotated)
|
|
428
|
+
const heightStr = formatMm(displayHeightMm, displayUnit);
|
|
429
|
+
const leftTextContent = `${heightStr} ${displayUnit}`;
|
|
430
|
+
const leftText = new Text(leftTextContent, {
|
|
431
|
+
left: leftRulerX,
|
|
432
|
+
top: leftRulerYStart + (rulerBottom - rulerTop) / 2,
|
|
433
|
+
angle: -90,
|
|
434
|
+
fontSize: fontSize,
|
|
435
|
+
fill: textColor,
|
|
436
|
+
fontFamily: "Arial",
|
|
437
|
+
originX: "center",
|
|
438
|
+
originY: "center",
|
|
439
|
+
backgroundColor: backgroundColor,
|
|
440
|
+
selectable: false,
|
|
441
|
+
evented: false,
|
|
442
|
+
});
|
|
443
|
+
layer.add(leftText);
|
|
444
|
+
|
|
445
|
+
// Always bring ruler to front
|
|
446
|
+
this.canvasService.canvas.bringObjectToFront(layer);
|
|
447
|
+
this.canvasService.canvas.requestRenderAll();
|
|
448
|
+
}
|
|
449
|
+
}
|