@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/core/tools/matchProp.js
CHANGED
|
@@ -2,6 +2,7 @@ import { Tool } from './tool.js';
|
|
|
2
2
|
import { Input, PromptOptions } from '../lib/inputManager.js';
|
|
3
3
|
import { Strings } from '../lib/strings.js';
|
|
4
4
|
import { Logging } from '../lib/logging.js';
|
|
5
|
+
import { Utils } from '../lib/utils.js';
|
|
5
6
|
import { UpdateState } from '../lib/stateManager.js';
|
|
6
7
|
|
|
7
8
|
import { DesignCore } from '../designCore.js';
|
|
@@ -21,8 +22,6 @@ export class MatchProp extends Tool {
|
|
|
21
22
|
this.sourceIndex = null;
|
|
22
23
|
// array of destination item indices
|
|
23
24
|
this.destinationSetIndices = [];
|
|
24
|
-
// properties to match
|
|
25
|
-
this.properties = ['colour', 'layer', 'lineType', 'lineWidth', 'height', 'styleName', 'dimensionStyle'];
|
|
26
25
|
}
|
|
27
26
|
|
|
28
27
|
/**
|
|
@@ -49,7 +48,7 @@ export class MatchProp extends Tool {
|
|
|
49
48
|
const sourceSelection = new PromptOptions(Strings.Input.SOURCE, [Input.Type.SINGLESELECTION], []);
|
|
50
49
|
const input = await DesignCore.Scene.inputManager.requestInput(sourceSelection);
|
|
51
50
|
if (input === undefined) return;
|
|
52
|
-
this.sourceIndex = input.
|
|
51
|
+
this.sourceIndex = input.selectedEntityIndex;
|
|
53
52
|
}
|
|
54
53
|
|
|
55
54
|
const destinationSelection = new PromptOptions(Strings.Input.DESTINATIONSET, [Input.Type.SELECTIONSET]);
|
|
@@ -76,21 +75,13 @@ export class MatchProp extends Tool {
|
|
|
76
75
|
|
|
77
76
|
// get source item
|
|
78
77
|
const sourceItem = DesignCore.Scene.entities.get(this.sourceIndex);
|
|
78
|
+
const propertySet = Utils.cloneProperties(sourceItem);
|
|
79
79
|
|
|
80
80
|
const stateChanges = [];
|
|
81
81
|
|
|
82
82
|
// loop through destination set
|
|
83
83
|
for (let i = 0; i < this.destinationSetIndices.length; i++) {
|
|
84
84
|
const targetItem = DesignCore.Scene.entities.get(this.destinationSetIndices[i]);
|
|
85
|
-
const propertySet = {};
|
|
86
|
-
// loop through properties and match
|
|
87
|
-
for (let p = 0; p < this.properties.length; p++) {
|
|
88
|
-
// check property exists on both items
|
|
89
|
-
const prop = this.properties[p];
|
|
90
|
-
if (sourceItem.hasOwnProperty(prop)) {
|
|
91
|
-
propertySet[prop] = sourceItem[prop];
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
85
|
|
|
95
86
|
// only add state change if there are properties to change
|
|
96
87
|
if (Object.keys(propertySet).length > 0) {
|
package/core/tools/mirror.js
CHANGED
|
@@ -7,6 +7,7 @@ import { Point } from '../entities/point.js';
|
|
|
7
7
|
import { AddState, UpdateState } from '../lib/stateManager.js';
|
|
8
8
|
|
|
9
9
|
import { DesignCore } from '../designCore.js';
|
|
10
|
+
import { RubberBand } from '../lib/auxiliary/rubberBand.js';
|
|
10
11
|
|
|
11
12
|
/**
|
|
12
13
|
* Mirror Command Class
|
|
@@ -74,18 +75,18 @@ export class Mirror extends Tool {
|
|
|
74
75
|
const pt1 = this.points[0];
|
|
75
76
|
const pt2 = this.points.length >= 2 ? this.points[1] : mousePoint;
|
|
76
77
|
|
|
77
|
-
// Draw the mirror line
|
|
78
|
-
DesignCore.Scene.
|
|
78
|
+
// Draw the mirror line as a rubber-band indicator
|
|
79
|
+
DesignCore.Scene.auxiliaryEntities.add(new RubberBand([pt1, pt2]));
|
|
79
80
|
|
|
80
81
|
// Preview mirrored entities (skip if mirror line has zero length)
|
|
81
82
|
if (!pt1.isSame(pt2)) {
|
|
82
|
-
for (let i = 0; i < DesignCore.Scene.selectionManager.
|
|
83
|
-
const
|
|
83
|
+
for (let i = 0; i < DesignCore.Scene.selectionManager.selectedEntities.length; i++) {
|
|
84
|
+
const entity = DesignCore.Scene.selectionManager.selectedEntities[i];
|
|
84
85
|
const entityIndex = DesignCore.Scene.selectionManager.selectionSet.selectionSet[i];
|
|
85
|
-
const
|
|
86
|
-
|
|
87
|
-
if (
|
|
88
|
-
|
|
86
|
+
const originalEntity = DesignCore.Scene.entities.get(entityIndex);
|
|
87
|
+
entity.setProperty('points', this.getMirroredPoints(originalEntity.points, pt1, pt2));
|
|
88
|
+
if (originalEntity.properties?.has('direction')) {
|
|
89
|
+
entity.setProperty('direction', -originalEntity.getProperty('direction'));
|
|
89
90
|
}
|
|
90
91
|
}
|
|
91
92
|
}
|
|
@@ -108,20 +109,20 @@ export class Mirror extends Tool {
|
|
|
108
109
|
|
|
109
110
|
for (let i = 0; i < DesignCore.Scene.selectionManager.selectionSet.selectionSet.length; i++) {
|
|
110
111
|
const entityIndex = DesignCore.Scene.selectionManager.selectionSet.selectionSet[i];
|
|
111
|
-
const
|
|
112
|
-
const mirroredPoints = this.getMirroredPoints(
|
|
112
|
+
const entity = DesignCore.Scene.entities.get(entityIndex);
|
|
113
|
+
const mirroredPoints = this.getMirroredPoints(entity.points, pt1, pt2);
|
|
113
114
|
|
|
114
115
|
if (this.eraseSource) {
|
|
115
116
|
// Replace the original with its mirrored version
|
|
116
117
|
const updates = { points: mirroredPoints };
|
|
117
|
-
if (
|
|
118
|
-
const stateChange = new UpdateState(
|
|
118
|
+
if (entity.properties?.has('direction')) updates.direction = -entity.getProperty('direction');
|
|
119
|
+
const stateChange = new UpdateState(entity, updates);
|
|
119
120
|
stateChanges.push(stateChange);
|
|
120
121
|
} else {
|
|
121
122
|
// Keep the original and add a mirrored copy
|
|
122
|
-
const copyOfItem = Utils.cloneObject(
|
|
123
|
+
const copyOfItem = Utils.cloneObject(entity);
|
|
123
124
|
copyOfItem.setProperty('points', mirroredPoints);
|
|
124
|
-
if (copyOfItem.direction
|
|
125
|
+
if (copyOfItem.properties?.has('direction')) copyOfItem.setProperty('direction', -copyOfItem.getProperty('direction'));
|
|
125
126
|
const stateChange = new AddState(copyOfItem);
|
|
126
127
|
stateChanges.push(stateChange);
|
|
127
128
|
}
|
package/core/tools/move.js
CHANGED
|
@@ -6,6 +6,7 @@ import { Point } from '../entities/point.js';
|
|
|
6
6
|
|
|
7
7
|
import { DesignCore } from '../designCore.js';
|
|
8
8
|
import { UpdateState } from '../lib/stateManager.js';
|
|
9
|
+
import { RubberBand } from '../lib/auxiliary/rubberBand.js';
|
|
9
10
|
|
|
10
11
|
/**
|
|
11
12
|
* Move Command Class
|
|
@@ -66,17 +67,16 @@ export class Move extends Tool {
|
|
|
66
67
|
if (this.points.length >= 1) {
|
|
67
68
|
const mousePoint = DesignCore.Mouse.pointOnScene();
|
|
68
69
|
|
|
69
|
-
// Draw a line
|
|
70
|
-
|
|
71
|
-
DesignCore.Scene.tempEntities.create('Line', { points: points });
|
|
70
|
+
// Draw a rubber-band line from base point to mouse
|
|
71
|
+
DesignCore.Scene.auxiliaryEntities.add(new RubberBand([this.points.at(-1), mousePoint]));
|
|
72
72
|
|
|
73
73
|
// Get the delta from the last mouse point
|
|
74
74
|
const delta = mousePoint.subtract(this.lastMousePoint || this.points[0]);
|
|
75
75
|
this.lastMousePoint = mousePoint;
|
|
76
76
|
|
|
77
|
-
for (let i = 0; i < DesignCore.Scene.selectionManager.
|
|
78
|
-
const
|
|
79
|
-
|
|
77
|
+
for (let i = 0; i < DesignCore.Scene.selectionManager.selectedEntities.length; i++) {
|
|
78
|
+
const entity = DesignCore.Scene.selectionManager.selectedEntities[i];
|
|
79
|
+
entity.setProperty('points', this.getOffsetPoints(entity.points, delta));
|
|
80
80
|
}
|
|
81
81
|
}
|
|
82
82
|
}
|
|
@@ -94,8 +94,8 @@ export class Move extends Tool {
|
|
|
94
94
|
|
|
95
95
|
for (let i = 0; i < DesignCore.Scene.selectionManager.selectionSet.selectionSet.length; i++) {
|
|
96
96
|
const index = DesignCore.Scene.selectionManager.selectionSet.selectionSet[i];
|
|
97
|
-
const
|
|
98
|
-
const stateChange = new UpdateState(
|
|
97
|
+
const entity = DesignCore.Scene.entities.get(index);
|
|
98
|
+
const stateChange = new UpdateState(entity, { points: this.getOffsetPoints(entity.points, delta) });
|
|
99
99
|
stateChanges.push(stateChange);
|
|
100
100
|
}
|
|
101
101
|
|
package/core/tools/offset.js
CHANGED
|
@@ -19,7 +19,7 @@ export class Offset extends Tool {
|
|
|
19
19
|
/** Create an Offset command */
|
|
20
20
|
constructor() {
|
|
21
21
|
super();
|
|
22
|
-
this.
|
|
22
|
+
this.selectedEntity = null;
|
|
23
23
|
}
|
|
24
24
|
|
|
25
25
|
/**
|
|
@@ -67,28 +67,28 @@ export class Offset extends Tool {
|
|
|
67
67
|
while (true) {
|
|
68
68
|
const preselected = DesignCore.Scene.selectionManager.selectionSet.selectionSet;
|
|
69
69
|
if (preselected.length === 1) {
|
|
70
|
-
this.
|
|
70
|
+
this.selectedEntity = DesignCore.Scene.entities.get(preselected[0]);
|
|
71
71
|
DesignCore.Scene.selectionManager.reset();
|
|
72
72
|
} else {
|
|
73
73
|
DesignCore.Scene.selectionManager.reset();
|
|
74
74
|
const selection = await DesignCore.Scene.inputManager.requestInput(op2);
|
|
75
75
|
if (selection === undefined) break;
|
|
76
|
-
this.
|
|
76
|
+
this.selectedEntity = DesignCore.Scene.entities.get(selection.selectedEntityIndex);
|
|
77
77
|
DesignCore.Scene.selectionManager.removeLastSelection();
|
|
78
78
|
}
|
|
79
79
|
|
|
80
80
|
const point = await DesignCore.Scene.inputManager.requestInput(op3);
|
|
81
81
|
if (point === undefined) {
|
|
82
|
-
this.
|
|
82
|
+
this.selectedEntity = null;
|
|
83
83
|
break;
|
|
84
84
|
}
|
|
85
85
|
|
|
86
86
|
if (throughMode) {
|
|
87
|
-
DesignCore.Scene.headers.offsetDistance = this.getThroughDistance(this.
|
|
87
|
+
DesignCore.Scene.headers.offsetDistance = this.getThroughDistance(this.selectedEntity, point);
|
|
88
88
|
}
|
|
89
89
|
this.points = [point];
|
|
90
90
|
DesignCore.Scene.inputManager.actionCommand();
|
|
91
|
-
this.
|
|
91
|
+
this.selectedEntity = null;
|
|
92
92
|
}
|
|
93
93
|
|
|
94
94
|
DesignCore.Scene.inputManager.reset();
|
|
@@ -102,14 +102,13 @@ export class Offset extends Tool {
|
|
|
102
102
|
*/
|
|
103
103
|
preview() {
|
|
104
104
|
const offsetDistance = DesignCore.Scene.headers.offsetDistance;
|
|
105
|
-
if (this.
|
|
105
|
+
if (this.selectedEntity && offsetDistance > 0) {
|
|
106
106
|
const mousePoint = DesignCore.Mouse.pointOnScene();
|
|
107
|
-
const offsetPoints = this.getOffsetPoints(this.
|
|
107
|
+
const offsetPoints = this.getOffsetPoints(this.selectedEntity, mousePoint, offsetDistance);
|
|
108
108
|
|
|
109
109
|
if (offsetPoints) {
|
|
110
|
-
const previewEntity = Utils.cloneObject(this.
|
|
111
|
-
|
|
112
|
-
DesignCore.Scene.tempEntities.add(previewEntity);
|
|
110
|
+
const previewEntity = Utils.cloneObject(this.selectedEntity).fromPolylinePoints(offsetPoints);
|
|
111
|
+
DesignCore.Scene.previewEntities.add(previewEntity);
|
|
113
112
|
}
|
|
114
113
|
}
|
|
115
114
|
}
|
|
@@ -119,10 +118,10 @@ export class Offset extends Tool {
|
|
|
119
118
|
*/
|
|
120
119
|
action() {
|
|
121
120
|
const offsetDistance = DesignCore.Scene.headers.offsetDistance;
|
|
122
|
-
if (!this.
|
|
121
|
+
if (!this.selectedEntity || offsetDistance <= 0) return;
|
|
123
122
|
|
|
124
123
|
const sidePoint = this.points[0];
|
|
125
|
-
const entity = this.
|
|
124
|
+
const entity = this.selectedEntity;
|
|
126
125
|
const offsetPoints = this.getOffsetPoints(entity, sidePoint, offsetDistance);
|
|
127
126
|
|
|
128
127
|
if (!offsetPoints) {
|
|
@@ -130,8 +129,7 @@ export class Offset extends Tool {
|
|
|
130
129
|
return;
|
|
131
130
|
}
|
|
132
131
|
|
|
133
|
-
const offsetEntity = Utils.cloneObject(entity);
|
|
134
|
-
offsetEntity.fromPolylinePoints(offsetPoints);
|
|
132
|
+
const offsetEntity = Utils.cloneObject(entity).fromPolylinePoints(offsetPoints);
|
|
135
133
|
|
|
136
134
|
const stateChange = new AddState(offsetEntity);
|
|
137
135
|
DesignCore.Scene.commit([stateChange]);
|
|
@@ -189,20 +187,20 @@ export class Offset extends Tool {
|
|
|
189
187
|
sign = cross >= 0 ? 1 : -1;
|
|
190
188
|
}
|
|
191
189
|
} else {
|
|
192
|
-
const
|
|
193
|
-
const currentRadius =
|
|
190
|
+
const centre = A.bulgeCentrePoint(B);
|
|
191
|
+
const currentRadius = centre.distance(A);
|
|
194
192
|
const arcDir = A.bulge > 0 ? 1 : -1;
|
|
195
|
-
const closestPt = sidePoint.closestPointOnArc(A, B,
|
|
193
|
+
const closestPt = sidePoint.closestPointOnArc(A, B, centre, arcDir);
|
|
196
194
|
if (closestPt === null) continue;
|
|
197
195
|
const dist = sidePoint.distance(closestPt);
|
|
198
196
|
if (dist < minDist) {
|
|
199
197
|
minDist = dist;
|
|
200
|
-
const
|
|
201
|
-
// For CCW arc (arcDir>0): left of travel = toward
|
|
202
|
-
// For CW arc (arcDir<0): left of travel = away from
|
|
198
|
+
const distToCentre = centre.distance(sidePoint);
|
|
199
|
+
// For CCW arc (arcDir>0): left of travel = toward centre (smaller radius)
|
|
200
|
+
// For CW arc (arcDir<0): left of travel = away from centre (larger radius)
|
|
203
201
|
sign = arcDir > 0 ?
|
|
204
|
-
(
|
|
205
|
-
(
|
|
202
|
+
(distToCentre < currentRadius ? 1 : -1) :
|
|
203
|
+
(distToCentre >= currentRadius ? 1 : -1);
|
|
206
204
|
}
|
|
207
205
|
}
|
|
208
206
|
}
|
|
@@ -223,19 +221,19 @@ export class Offset extends Tool {
|
|
|
223
221
|
bulge: 0,
|
|
224
222
|
});
|
|
225
223
|
} else {
|
|
226
|
-
const
|
|
227
|
-
const currentRadius =
|
|
224
|
+
const centre = A.bulgeCentrePoint(B);
|
|
225
|
+
const currentRadius = centre.distance(A);
|
|
228
226
|
const arcDir = A.bulge > 0 ? 1 : -1;
|
|
229
227
|
const newRadius = currentRadius - arcDir * distance * sign;
|
|
230
228
|
if (newRadius <= 0) return null;
|
|
231
|
-
const startAngle = Math.atan2(A.y -
|
|
232
|
-
const endAngle = Math.atan2(B.y -
|
|
229
|
+
const startAngle = Math.atan2(A.y - centre.y, A.x - centre.x);
|
|
230
|
+
const endAngle = Math.atan2(B.y - centre.y, B.x - centre.x);
|
|
233
231
|
offsetSegs.push({
|
|
234
232
|
type: 'arc',
|
|
235
|
-
A: new Point(
|
|
236
|
-
B: new Point(
|
|
233
|
+
A: new Point(centre.x + newRadius * Math.cos(startAngle), centre.y + newRadius * Math.sin(startAngle)),
|
|
234
|
+
B: new Point(centre.x + newRadius * Math.cos(endAngle), centre.y + newRadius * Math.sin(endAngle)),
|
|
237
235
|
bulge: A.bulge,
|
|
238
|
-
|
|
236
|
+
centre,
|
|
239
237
|
radius: newRadius,
|
|
240
238
|
});
|
|
241
239
|
}
|
|
@@ -311,9 +309,9 @@ export class Offset extends Tool {
|
|
|
311
309
|
const dist = throughPoint.distance(closest);
|
|
312
310
|
if (dist < minDist) minDist = dist;
|
|
313
311
|
} else {
|
|
314
|
-
const
|
|
315
|
-
const radius =
|
|
316
|
-
const dist = Math.abs(
|
|
312
|
+
const centre = A.bulgeCentrePoint(B);
|
|
313
|
+
const radius = centre.distance(A);
|
|
314
|
+
const dist = Math.abs(centre.distance(throughPoint) - radius);
|
|
317
315
|
if (dist < minDist) minDist = dist;
|
|
318
316
|
}
|
|
319
317
|
}
|
package/core/tools/pasteclip.js
CHANGED
|
@@ -66,7 +66,7 @@ export class Pasteclip extends Tool {
|
|
|
66
66
|
const tempEntity = Utils.cloneObject(entity);
|
|
67
67
|
const offsetPoints = tempEntity.points.map((p) => new Point(p.x, p.y, p.bulge, p.sequence).add(delta));
|
|
68
68
|
tempEntity.setProperty('points', offsetPoints);
|
|
69
|
-
DesignCore.Scene.
|
|
69
|
+
DesignCore.Scene.previewEntities.add(tempEntity);
|
|
70
70
|
}
|
|
71
71
|
}
|
|
72
72
|
|
package/core/tools/purge.js
CHANGED
|
@@ -60,31 +60,31 @@ export class Purge extends Tool {
|
|
|
60
60
|
let purgedCount = 0;
|
|
61
61
|
|
|
62
62
|
if (this.option === 'Blocks' || this.option === 'All') {
|
|
63
|
-
const
|
|
63
|
+
const initialItemCount = DesignCore.Scene.blockManager.itemCount();
|
|
64
64
|
DesignCore.Scene.blockManager.purge();
|
|
65
|
-
const
|
|
66
|
-
purgedCount += (
|
|
65
|
+
const finalItemCount = DesignCore.Scene.blockManager.itemCount();
|
|
66
|
+
purgedCount += (initialItemCount - finalItemCount);
|
|
67
67
|
}
|
|
68
68
|
|
|
69
69
|
if (this.option === 'Dimstyles' || this.option === 'All') {
|
|
70
|
-
const
|
|
70
|
+
const initialItemCount = DesignCore.DimStyleManager.itemCount();
|
|
71
71
|
DesignCore.DimStyleManager.purge();
|
|
72
|
-
const
|
|
73
|
-
purgedCount += (
|
|
72
|
+
const finalItemCount = DesignCore.DimStyleManager.itemCount();
|
|
73
|
+
purgedCount += (initialItemCount - finalItemCount);
|
|
74
74
|
}
|
|
75
75
|
|
|
76
76
|
if (this.option === 'Layers' || this.option === 'All') {
|
|
77
|
-
const
|
|
77
|
+
const initialLayerCount = DesignCore.LayerManager.itemCount();
|
|
78
78
|
DesignCore.LayerManager.purge();
|
|
79
79
|
const finalLayerCount = DesignCore.LayerManager.itemCount();
|
|
80
|
-
purgedCount += (
|
|
80
|
+
purgedCount += (initialLayerCount - finalLayerCount);
|
|
81
81
|
}
|
|
82
82
|
|
|
83
83
|
if (this.option === 'LTypes' || this.option === 'All') {
|
|
84
|
-
const
|
|
84
|
+
const initialLTypeCount = DesignCore.LTypeManager.itemCount();
|
|
85
85
|
DesignCore.LTypeManager.purge();
|
|
86
86
|
const finalLTypeCount = DesignCore.LTypeManager.itemCount();
|
|
87
|
-
purgedCount += (
|
|
87
|
+
purgedCount += (initialLTypeCount - finalLTypeCount);
|
|
88
88
|
}
|
|
89
89
|
|
|
90
90
|
DesignCore.Core.notify(`${this.type} - ${this.option}: ${purgedCount} ${Strings.Strings.ITEMS} ${Strings.Strings.REMOVED}`);
|
package/core/tools/rotate.js
CHANGED
|
@@ -7,6 +7,7 @@ import { Point } from '../entities/point.js';
|
|
|
7
7
|
import { UpdateState } from '../lib/stateManager.js';
|
|
8
8
|
|
|
9
9
|
import { DesignCore } from '../designCore.js';
|
|
10
|
+
import { RubberBand } from '../lib/auxiliary/rubberBand.js';
|
|
10
11
|
|
|
11
12
|
/**
|
|
12
13
|
* Rotate Command Class
|
|
@@ -72,6 +73,9 @@ export class Rotate extends Tool {
|
|
|
72
73
|
this.baseAngle = refBase.angle(refEnd);
|
|
73
74
|
// set the base point to null
|
|
74
75
|
this.basePoint = null;
|
|
76
|
+
// restore inputPoint to the rotation centre so the tracking line
|
|
77
|
+
// uses the correct origin for the final angle input
|
|
78
|
+
DesignCore.Scene.inputManager.inputPoint = this.points[0];
|
|
75
79
|
} else if (Input.getType(input2) === Input.Type.NUMBER) {
|
|
76
80
|
const basePoint = this.points.at(0);
|
|
77
81
|
const angle = Utils.degrees2radians(input2);
|
|
@@ -95,23 +99,22 @@ export class Rotate extends Tool {
|
|
|
95
99
|
const mousePoint = DesignCore.Mouse.pointOnScene();
|
|
96
100
|
|
|
97
101
|
if (this.points.length >= 1 && this.baseAngle !== null || this.basePoint !== null) {
|
|
98
|
-
// Draw a line
|
|
99
|
-
const
|
|
100
|
-
|
|
101
|
-
DesignCore.Scene.tempEntities.create('Line', { points: points });
|
|
102
|
+
// Draw a rubber-band line from centre to mouse
|
|
103
|
+
const centre = this.basePoint === null ? this.points.at(0) : this.basePoint;
|
|
104
|
+
DesignCore.Scene.auxiliaryEntities.add(new RubberBand([centre, mousePoint]));
|
|
102
105
|
}
|
|
103
106
|
|
|
104
107
|
if (this.points.length >= 1) {
|
|
105
108
|
const ang = this.points[0].angle(mousePoint);
|
|
106
109
|
const theta = this.baseAngle === null ? 0 : ang - this.baseAngle;
|
|
107
|
-
const
|
|
110
|
+
const centre = this.points[0];
|
|
108
111
|
|
|
109
|
-
for (let i = 0; i < DesignCore.Scene.selectionManager.
|
|
110
|
-
const
|
|
112
|
+
for (let i = 0; i < DesignCore.Scene.selectionManager.selectedEntities.length; i++) {
|
|
113
|
+
const entity = DesignCore.Scene.selectionManager.selectedEntities[i];
|
|
111
114
|
// get the original points from the scene entities
|
|
112
115
|
const entityIndex = DesignCore.Scene.selectionManager.selectionSet.selectionSet[i];
|
|
113
|
-
const
|
|
114
|
-
|
|
116
|
+
const originalEntity = DesignCore.Scene.entities.get(entityIndex);
|
|
117
|
+
entity.setProperty('points', this.getRotatedPoints(originalEntity.points, centre, theta));
|
|
115
118
|
}
|
|
116
119
|
}
|
|
117
120
|
};
|
|
@@ -122,13 +125,13 @@ export class Rotate extends Tool {
|
|
|
122
125
|
action() {
|
|
123
126
|
const ang = this.points[0].angle(this.points[1]);
|
|
124
127
|
const theta = ang - this.baseAngle;
|
|
125
|
-
const
|
|
128
|
+
const centre = this.points[0];
|
|
126
129
|
|
|
127
130
|
const stateChanges = [];
|
|
128
131
|
|
|
129
132
|
for (let index = 0; index < DesignCore.Scene.selectionManager.selectionSet.selectionSet.length; index++) {
|
|
130
|
-
const
|
|
131
|
-
const stateChange = new UpdateState(
|
|
133
|
+
const entity = DesignCore.Scene.entities.get(DesignCore.Scene.selectionManager.selectionSet.selectionSet[index]);
|
|
134
|
+
const stateChange = new UpdateState(entity, { points: this.getRotatedPoints(entity.points, centre, theta) });
|
|
132
135
|
stateChanges.push(stateChange);
|
|
133
136
|
}
|
|
134
137
|
|
|
@@ -138,12 +141,12 @@ export class Rotate extends Tool {
|
|
|
138
141
|
/**
|
|
139
142
|
* Get rotated points
|
|
140
143
|
* @param {Array} points
|
|
141
|
-
* @param {Point}
|
|
142
|
-
* @param {
|
|
144
|
+
* @param {Point} centre
|
|
145
|
+
* @param {number} theta
|
|
143
146
|
* @return {Array} rotatedPoints
|
|
144
147
|
*/
|
|
145
|
-
getRotatedPoints(points,
|
|
146
|
-
const rotatedPoints = points.map((p) => new Point(p.x, p.y, p.bulge, p.sequence).rotate(
|
|
148
|
+
getRotatedPoints(points, centre, theta) {
|
|
149
|
+
const rotatedPoints = points.map((p) => new Point(p.x, p.y, p.bulge, p.sequence).rotate(centre, theta));
|
|
147
150
|
return rotatedPoints;
|
|
148
151
|
}
|
|
149
152
|
}
|
package/core/tools/scale.js
CHANGED
|
@@ -122,7 +122,7 @@ export class Scale extends Tool {
|
|
|
122
122
|
if (this.points.length >= 1 && this.referencePoint === null) {
|
|
123
123
|
// Draw a line from base point to mouse
|
|
124
124
|
const points = [this.points[0], mousePoint];
|
|
125
|
-
DesignCore.Scene.
|
|
125
|
+
DesignCore.Scene.previewEntities.create('Line', { points: points });
|
|
126
126
|
|
|
127
127
|
const base = this.points[0];
|
|
128
128
|
const distance = base.distance(mousePoint);
|
|
@@ -130,11 +130,11 @@ export class Scale extends Tool {
|
|
|
130
130
|
|
|
131
131
|
const factor = this.referenceLength !== null ? distance / this.referenceLength : distance;
|
|
132
132
|
|
|
133
|
-
for (let i = 0; i < DesignCore.Scene.selectionManager.
|
|
134
|
-
const
|
|
133
|
+
for (let i = 0; i < DesignCore.Scene.selectionManager.selectedEntities.length; i++) {
|
|
134
|
+
const entity = DesignCore.Scene.selectionManager.selectedEntities[i];
|
|
135
135
|
const entityIndex = DesignCore.Scene.selectionManager.selectionSet.selectionSet[i];
|
|
136
|
-
const
|
|
137
|
-
|
|
136
|
+
const originalEntity = DesignCore.Scene.entities.get(entityIndex);
|
|
137
|
+
entity.setProperty('points', this.getScaledPoints(originalEntity.points, base, factor));
|
|
138
138
|
}
|
|
139
139
|
}
|
|
140
140
|
}
|
|
@@ -147,8 +147,8 @@ export class Scale extends Tool {
|
|
|
147
147
|
const stateChanges = [];
|
|
148
148
|
|
|
149
149
|
for (let i = 0; i < DesignCore.Scene.selectionManager.selectionSet.selectionSet.length; i++) {
|
|
150
|
-
const
|
|
151
|
-
const stateChange = new UpdateState(
|
|
150
|
+
const entity = DesignCore.Scene.entities.get(DesignCore.Scene.selectionManager.selectionSet.selectionSet[i]);
|
|
151
|
+
const stateChange = new UpdateState(entity, { points: this.getScaledPoints(entity.points, base, this.scaleFactor) });
|
|
152
152
|
stateChanges.push(stateChange);
|
|
153
153
|
}
|
|
154
154
|
|