@design-core/core 0.0.6 → 50.1.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/.eslintrc.json +4 -0
- package/.github/workflows/DesignCoreQA.yml +3 -0
- package/TODO.md +49 -6
- package/core/core/core.js +0 -3
- package/core/designCore.js +1 -1
- package/core/dimensions/alignedDimension.js +12 -11
- package/core/dimensions/angularDimension.js +38 -37
- package/core/dimensions/{baseCircularDimension.js → circularDimensionBase.js} +22 -21
- package/core/dimensions/diametricDimension.js +14 -13
- package/core/dimensions/dimension.js +62 -55
- package/core/dimensions/{baseDimension.js → dimensionBase.js} +73 -107
- package/core/dimensions/{baseLinearDimension.js → linearDimensionBase.js} +15 -14
- package/core/dimensions/radialDimension.js +12 -11
- package/core/dimensions/rotatedDimension.js +20 -19
- package/core/entities/arc.js +123 -156
- package/core/entities/arctext.js +222 -184
- package/core/entities/circle.js +77 -99
- package/core/entities/entity.js +114 -93
- package/core/entities/hatch.js +346 -273
- package/core/entities/insert.js +68 -83
- package/core/entities/line.js +21 -142
- package/core/entities/lwpolyline.js +16 -11
- package/core/entities/point.js +19 -19
- package/core/entities/polyline.js +7 -7
- package/core/entities/{basePolyline.js → polylineBase.js} +47 -299
- package/core/entities/rectangle.js +3 -1
- package/core/entities/solid.js +6 -15
- package/core/entities/text.js +190 -201
- package/core/lib/auxiliary/rubberBand.js +32 -0
- package/core/lib/auxiliary/selectionWindow.js +63 -0
- package/core/lib/auxiliary/snapPoint.js +113 -0
- package/core/lib/auxiliary/trackingLine.js +76 -0
- package/core/lib/boundingBox.js +11 -11
- package/core/lib/canvas.js +232 -168
- package/core/lib/clipboard.js +9 -3
- package/core/lib/colour.js +16 -0
- package/core/lib/commandLine.js +1 -6
- package/core/lib/commandManager.js +18 -8
- package/core/lib/constants.js +28 -0
- package/core/lib/dxf/dxf.js +15 -14
- package/core/lib/dxf/dxfIterator.js +2 -2
- package/core/lib/entityManager.js +33 -26
- package/core/lib/inputManager.js +36 -12
- package/core/lib/intersect.js +25 -0
- package/core/lib/matrix.js +1 -1
- package/core/lib/patterns.js +9 -2
- package/core/lib/plotOptions.js +67 -0
- package/core/lib/polylineUtils.js +75 -0
- package/core/lib/renderers/cairoRenderer.js +371 -0
- package/core/lib/renderers/canvasRenderer.js +315 -0
- package/core/lib/renderers/pdfRenderer.js +366 -0
- package/core/lib/renderers/rendererBase.js +284 -0
- package/core/lib/renderers/svgRenderer.js +343 -0
- package/core/lib/scene.js +28 -6
- package/core/lib/selectionManager.js +20 -20
- package/core/lib/settings.js +4 -2
- package/core/lib/snapping.js +4 -191
- package/core/lib/stateManager.js +30 -1
- package/core/lib/utils.js +26 -7
- package/core/properties/entityProperties.js +104 -0
- package/core/properties/property.js +106 -2
- package/core/properties/propertyManager.js +60 -44
- package/core/tables/block.js +50 -81
- package/core/tables/dimStyle.js +5 -5
- package/core/tables/endblk.js +1 -1
- package/core/tables/layer.js +8 -0
- package/core/tables/ltypeManager.js +1 -1
- package/core/tables/styleManagerBase.js +3 -2
- package/core/tables/tableManagerBase.js +8 -3
- package/core/tables/vport.js +2 -2
- package/core/tools/chamfer.js +117 -143
- package/core/tools/chamferFilletBase.js +138 -37
- package/core/tools/copy.js +11 -11
- package/core/tools/copybase.js +3 -3
- package/core/tools/copyclip.js +3 -3
- package/core/tools/cornerEntity.js +2 -2
- package/core/tools/cutclip.js +3 -3
- package/core/tools/explode.js +7 -7
- package/core/tools/extend.js +138 -25
- package/core/tools/fillet.js +92 -189
- package/core/tools/matchProp.js +3 -12
- package/core/tools/mirror.js +15 -14
- package/core/tools/move.js +8 -8
- package/core/tools/offset.js +31 -33
- package/core/tools/pasteclip.js +1 -1
- package/core/tools/purge.js +10 -10
- package/core/tools/rotate.js +19 -16
- package/core/tools/scale.js +7 -7
- package/core/tools/trim.js +271 -29
- package/core/tools/zoom.js +1 -1
- package/cspell.json +321 -0
- package/jest.config.js +6 -0
- package/package.json +5 -3
- package/test/dimensions/alignedDimension.test.js +17 -10
- package/test/dimensions/angularDimension.test.js +13 -13
- package/test/dimensions/diametricDimension.test.js +15 -15
- package/test/dimensions/dimension.test.js +12 -12
- package/test/dimensions/{baseDimension.test.js → dimensionBase.test.js} +73 -12
- package/test/dimensions/linearDimensionBase.test.js +62 -0
- package/test/dimensions/radialDimension.test.js +15 -15
- package/test/dimensions/rotatedDimension.test.js +18 -11
- package/test/entities/arc.test.js +83 -86
- package/test/entities/arctext.test.js +184 -57
- package/test/entities/circle.test.js +68 -96
- package/test/entities/entity.test.js +42 -8
- package/test/entities/hatch.test.js +569 -96
- package/test/entities/insert.test.js +99 -4
- package/test/entities/line.test.js +15 -41
- package/test/entities/lwpolyline.test.js +104 -0
- package/test/entities/point.test.js +3 -3
- package/test/entities/polyline.test.js +11 -0
- package/test/entities/{basePolyline.test.js → polylineBase.test.js} +192 -57
- package/test/entities/rectangle.test.js +11 -0
- package/test/entities/solid.test.js +1 -1
- package/test/entities/text.test.js +302 -77
- package/test/integration/exportIntegration.reference.dxf +9 -9
- package/test/integration/exportIntegration.test.js +5 -5
- package/test/integration/intersectionIntegration.test.js +4 -5
- package/test/integration/pdfRendererIntegration.reference.pdf +17709 -0
- package/test/integration/pdfRendererIntegration.test.js +61 -0
- package/test/integration/svgRendererIntegration.reference.svg +3343 -0
- package/test/integration/svgRendererIntegration.test.js +61 -0
- package/test/integration/userInputIntegration.reference.dxf +1165 -105
- package/test/integration/userInputIntegration.test.js +239 -132
- package/test/lib/boundingBox.test.js +3 -3
- package/test/lib/canvas.test.js +744 -125
- package/test/lib/constants.test.js +27 -0
- package/test/lib/entityManager.test.js +4 -4
- package/test/lib/inputManager.test.js +81 -20
- package/test/lib/intersect.test.js +83 -0
- package/test/lib/plotOptions.test.js +179 -0
- package/test/lib/rubberBand.test.js +84 -0
- package/test/lib/scene.test.js +9 -9
- package/test/lib/selectionManager.test.js +3 -3
- package/test/lib/settings.test.js +5 -6
- package/test/lib/snapping.test.js +72 -130
- package/test/lib/stateManager.test.js +7 -7
- package/test/lib/utils.test.js +36 -2
- package/test/properties/entityProperties.test.js +132 -0
- package/test/properties/property.test.js +53 -0
- package/test/properties/propertyManager.test.js +25 -25
- package/test/renderers/canvasRenderer.test.js +317 -0
- package/test/renderers/pdfRenderer.test.js +271 -0
- package/test/renderers/rendererBase.test.js +213 -0
- package/test/renderers/svgRenderer.test.js +326 -0
- package/test/tables/block.test.js +92 -13
- package/test/tables/endblk.test.js +2 -2
- package/test/tables/layer.test.js +30 -0
- package/test/tables/layerManager.test.js +2 -2
- package/test/test-helpers/hatchGridRenderer.js +180 -0
- package/test/test-helpers/test-helpers.js +158 -6
- package/test/tools/chamfer.test.js +273 -51
- package/test/tools/chamferFilletBase.test.js +125 -36
- package/test/tools/copy.test.js +8 -8
- package/test/tools/copybase.test.js +2 -2
- package/test/tools/copyclip.test.js +2 -2
- package/test/tools/cornerEntity.test.js +8 -8
- package/test/tools/cutclip.test.js +2 -2
- package/test/tools/erase.test.js +6 -6
- package/test/tools/explode.test.js +5 -5
- package/test/tools/extend.test.js +373 -42
- package/test/tools/fillet.test.js +230 -49
- package/test/tools/matchProp.test.js +11 -11
- package/test/tools/mirror.test.js +39 -39
- package/test/tools/move.test.js +7 -7
- package/test/tools/offset.test.js +222 -55
- package/test/tools/pasteclip.test.js +5 -5
- package/test/tools/purge.test.js +4 -4
- package/test/tools/rotate.test.js +39 -9
- package/test/tools/scale.test.js +33 -33
- package/test/tools/trim.test.js +579 -53
- package/test/tools/zoom.test.js +12 -12
- package/core/lib/selectionWindow.js +0 -83
package/test/tools/zoom.test.js
CHANGED
|
@@ -84,8 +84,8 @@ test('Test Zoom.action - Window mode with single point (should not zoom)', () =>
|
|
|
84
84
|
|
|
85
85
|
test('Test Zoom.action - All mode (calls zoomExtents)', () => {
|
|
86
86
|
// Add items to scene so extents exist
|
|
87
|
-
DesignCore.Scene.
|
|
88
|
-
DesignCore.Scene.
|
|
87
|
+
DesignCore.Scene.addEntity('Line', { points: [new Point(10, 10), new Point(100, 100)] });
|
|
88
|
+
DesignCore.Scene.addEntity('Circle', { points: [new Point(50, 50), new Point(60, 60)] });
|
|
89
89
|
|
|
90
90
|
core.canvas.width = 800;
|
|
91
91
|
core.canvas.height = 600;
|
|
@@ -109,15 +109,15 @@ test('Test Zoom.preview - Window mode with one point', () => {
|
|
|
109
109
|
// Mock mouse position
|
|
110
110
|
core.mouse.mouseMoved(50, 50);
|
|
111
111
|
|
|
112
|
-
const initialTempItemsCount = DesignCore.Scene.
|
|
112
|
+
const initialTempItemsCount = DesignCore.Scene.previewEntities.count();
|
|
113
113
|
|
|
114
114
|
zoom.preview();
|
|
115
115
|
|
|
116
116
|
// Should have added a polyline (rectangle preview)
|
|
117
|
-
expect(DesignCore.Scene.
|
|
117
|
+
expect(DesignCore.Scene.previewEntities.count()).toBe(initialTempItemsCount + 1);
|
|
118
118
|
|
|
119
119
|
// Verify it's a polyline
|
|
120
|
-
const tempItem = DesignCore.Scene.
|
|
120
|
+
const tempItem = DesignCore.Scene.previewEntities.get(DesignCore.Scene.previewEntities.count() - 1);
|
|
121
121
|
expect(tempItem.type).toBe('Polyline');
|
|
122
122
|
expect(tempItem.points.length).toBe(4); // Rectangle has 4 points (closed flag set)
|
|
123
123
|
});
|
|
@@ -126,12 +126,12 @@ test('Test Zoom.preview - Window mode with no points (should not preview)', () =
|
|
|
126
126
|
const zoom = new Zoom();
|
|
127
127
|
zoom.mode = 'Window';
|
|
128
128
|
|
|
129
|
-
const initialTempItemsCount = DesignCore.Scene.
|
|
129
|
+
const initialTempItemsCount = DesignCore.Scene.previewEntities.count();
|
|
130
130
|
|
|
131
131
|
zoom.preview();
|
|
132
132
|
|
|
133
133
|
// Should not add anything
|
|
134
|
-
expect(DesignCore.Scene.
|
|
134
|
+
expect(DesignCore.Scene.previewEntities.count()).toBe(initialTempItemsCount);
|
|
135
135
|
});
|
|
136
136
|
|
|
137
137
|
test('Test Zoom.preview - All mode (should not preview)', () => {
|
|
@@ -139,12 +139,12 @@ test('Test Zoom.preview - All mode (should not preview)', () => {
|
|
|
139
139
|
zoom.mode = 'All';
|
|
140
140
|
zoom.points.push(new Point(10, 10));
|
|
141
141
|
|
|
142
|
-
const initialTempItemsCount = DesignCore.Scene.
|
|
142
|
+
const initialTempItemsCount = DesignCore.Scene.previewEntities.count();
|
|
143
143
|
|
|
144
144
|
zoom.preview();
|
|
145
145
|
|
|
146
146
|
// Should not add anything for All/Extents modes
|
|
147
|
-
expect(DesignCore.Scene.
|
|
147
|
+
expect(DesignCore.Scene.previewEntities.count()).toBe(initialTempItemsCount);
|
|
148
148
|
});
|
|
149
149
|
|
|
150
150
|
test('Test Canvas.zoomToWindow - valid window', () => {
|
|
@@ -237,7 +237,7 @@ test('Test Canvas.zoomToWindow - same point (should not zoom)', () => {
|
|
|
237
237
|
|
|
238
238
|
test('Test Zoom.action - Object mode', () => {
|
|
239
239
|
// Add an object to the scene
|
|
240
|
-
const obj = DesignCore.Scene.
|
|
240
|
+
const obj = DesignCore.Scene.addEntity('Circle', { points: [new Point(20, 20), new Point(40, 40)] });
|
|
241
241
|
|
|
242
242
|
core.canvas.width = 800;
|
|
243
243
|
core.canvas.height = 600;
|
|
@@ -281,7 +281,7 @@ test('Zoom.action - Extents mode calls zoomExtents', () => {
|
|
|
281
281
|
core.canvas.height = 600;
|
|
282
282
|
core.canvas.matrix.scale(1, 1);
|
|
283
283
|
core.scene.clear();
|
|
284
|
-
core.scene.
|
|
284
|
+
core.scene.addEntity('Line', { points: [new Point(10, 10), new Point(50, 50)] });
|
|
285
285
|
|
|
286
286
|
const initialScale = core.canvas.getScale();
|
|
287
287
|
|
|
@@ -444,7 +444,7 @@ test('Zoom.execute Extents mode: calls executeCommand without extra point prompt
|
|
|
444
444
|
|
|
445
445
|
test('Zoom.execute Object mode: with existing selection calls executeCommand without prompting', async () => {
|
|
446
446
|
core.scene.clear();
|
|
447
|
-
const idx = core.scene.
|
|
447
|
+
const idx = core.scene.addEntity('Line', { points: [new Point(0, 0), new Point(10, 10)] });
|
|
448
448
|
core.scene.selectionManager.reset();
|
|
449
449
|
core.scene.selectionManager.addToSelectionSet(idx);
|
|
450
450
|
|
|
@@ -1,83 +0,0 @@
|
|
|
1
|
-
import { DesignCore } from '../designCore.js';
|
|
2
|
-
import { Point } from '../entities/point.js';
|
|
3
|
-
import { Colours } from './colours.js';
|
|
4
|
-
|
|
5
|
-
/** SelectionWindow Class */
|
|
6
|
-
export class SelectionWindow {
|
|
7
|
-
/**
|
|
8
|
-
* Create a SelectionWindow
|
|
9
|
-
* @param {Object} data
|
|
10
|
-
*/
|
|
11
|
-
constructor(data) {
|
|
12
|
-
this.colour = DesignCore.Settings.selectionWindow;
|
|
13
|
-
this.lineWidth = 1;
|
|
14
|
-
this.dashPattern = [];
|
|
15
|
-
|
|
16
|
-
if (data) {
|
|
17
|
-
if (data.hasOwnProperty('points')) {
|
|
18
|
-
if (data.points[1].y > data.points[0].y) {
|
|
19
|
-
this.colour = DesignCore.Settings.selectionWindow;
|
|
20
|
-
this.dashPattern = [5];
|
|
21
|
-
} else {
|
|
22
|
-
this.colour = DesignCore.Settings.crossingWindow;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
this.points = [];
|
|
26
|
-
const point1 = new Point(data.points[0].x, data.points[0].y);
|
|
27
|
-
const point2 = new Point(data.points[1].x, data.points[1].y);
|
|
28
|
-
|
|
29
|
-
this.points.push(point1);
|
|
30
|
-
this.points.push(point2);
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
* Draw the entity
|
|
37
|
-
* @param {Object} ctx - context
|
|
38
|
-
* @param {number} scale
|
|
39
|
-
*/
|
|
40
|
-
draw(ctx, scale) {
|
|
41
|
-
const colour = this.colour;
|
|
42
|
-
ctx.fillStyle = colour;
|
|
43
|
-
|
|
44
|
-
const scaledPattern = this.dashPattern.map((x) => x / scale);
|
|
45
|
-
|
|
46
|
-
try { // HTML Canvas
|
|
47
|
-
ctx.strokeStyle = Colours.rgbToString(colour);
|
|
48
|
-
ctx.fillStyle = Colours.rgbToString(colour);
|
|
49
|
-
ctx.lineWidth = this.lineWidth / scale;
|
|
50
|
-
ctx.beginPath();
|
|
51
|
-
ctx.globalAlpha = 0.2;
|
|
52
|
-
const width = this.points[1].x - this.points[0].x;
|
|
53
|
-
const height = this.points[1].y - this.points[0].y;
|
|
54
|
-
ctx.fillRect(this.points[0].x, this.points[0].y, width, height);
|
|
55
|
-
ctx.globalAlpha = 1.0;
|
|
56
|
-
this.drawRect(ctx);
|
|
57
|
-
ctx.setLineDash(scaledPattern);
|
|
58
|
-
ctx.stroke();
|
|
59
|
-
} catch { // Cairo
|
|
60
|
-
ctx.setLineWidth(this.lineWidth / scale);
|
|
61
|
-
const rgbColour = Colours.rgbToScaledRGB(colour);
|
|
62
|
-
ctx.setSourceRGBA(rgbColour.r, rgbColour.g, rgbColour.b, 0.2);
|
|
63
|
-
this.drawRect(ctx);
|
|
64
|
-
ctx.fillPreserve();
|
|
65
|
-
ctx.setSourceRGB(rgbColour.r, rgbColour.g, rgbColour.b);
|
|
66
|
-
|
|
67
|
-
ctx.setDash(scaledPattern, 1);
|
|
68
|
-
ctx.stroke();
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
/**
|
|
73
|
-
* Draw a rectangle
|
|
74
|
-
* @param {Object} ctx
|
|
75
|
-
*/
|
|
76
|
-
drawRect(ctx) {
|
|
77
|
-
ctx.moveTo(this.points[0].x, this.points[0].y);
|
|
78
|
-
ctx.lineTo(this.points[1].x, this.points[0].y);
|
|
79
|
-
ctx.lineTo(this.points[1].x, this.points[1].y);
|
|
80
|
-
ctx.lineTo(this.points[0].x, this.points[1].y);
|
|
81
|
-
ctx.lineTo(this.points[0].x, this.points[0].y);
|
|
82
|
-
}
|
|
83
|
-
}
|