@design-core/core 0.0.7 → 51.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/.github/workflows/DesignCoreQA.yml +3 -0
- package/core/designCore.js +1 -1
- package/core/dimensions/alignedDimension.js +7 -7
- package/core/dimensions/angularDimension.js +32 -32
- package/core/dimensions/{baseCircularDimension.js → circularDimensionBase.js} +19 -19
- package/core/dimensions/diametricDimension.js +10 -10
- package/core/dimensions/dimension.js +42 -42
- package/core/dimensions/{baseDimension.js → dimensionBase.js} +17 -17
- package/core/dimensions/{baseLinearDimension.js → linearDimensionBase.js} +9 -9
- package/core/dimensions/radialDimension.js +8 -8
- package/core/dimensions/rotatedDimension.js +8 -8
- package/core/entities/arc.js +22 -22
- package/core/entities/arctext.js +13 -13
- package/core/entities/circle.js +7 -7
- package/core/entities/hatch.js +210 -40
- package/core/entities/insert.js +11 -6
- package/core/entities/point.js +19 -19
- package/core/entities/polyline.js +3 -3
- package/core/entities/{basePolyline.js → polylineBase.js} +18 -18
- package/core/entities/text.js +4 -4
- package/core/lib/boundingBox.js +11 -11
- package/core/lib/canvas.js +13 -6
- package/core/lib/clipboard.js +2 -2
- package/core/lib/dxf/dxf.js +11 -11
- package/core/lib/dxf/dxfIterator.js +2 -2
- package/core/lib/entityManager.js +19 -19
- package/core/lib/inputManager.js +1 -1
- package/core/lib/matrix.js +1 -1
- package/core/lib/patterns.js +1 -1
- package/core/lib/polylineUtils.js +9 -9
- package/core/lib/renderers/cairoRenderer.js +5 -5
- package/core/lib/renderers/canvasRenderer.js +4 -4
- package/core/lib/renderers/pdfRenderer.js +7 -7
- package/core/lib/renderers/rendererBase.js +1 -1
- package/core/lib/scene.js +1 -1
- package/core/lib/selectionManager.js +18 -18
- package/core/lib/utils.js +5 -5
- package/core/properties/entityProperties.js +2 -1
- package/core/properties/flags.js +12 -0
- package/core/properties/property.js +8 -3
- package/core/properties/propertyManager.js +52 -37
- package/core/tables/block.js +50 -46
- package/core/tables/dimStyle.js +5 -5
- package/core/tables/ltypeManager.js +1 -1
- package/core/tables/vport.js +2 -2
- package/core/tools/chamfer.js +6 -6
- package/core/tools/chamferFilletBase.js +4 -4
- package/core/tools/copy.js +8 -8
- 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 +6 -6
- package/core/tools/extend.js +13 -13
- package/core/tools/fillet.js +6 -6
- package/core/tools/matchProp.js +1 -1
- package/core/tools/mirror.js +11 -11
- package/core/tools/move.js +5 -5
- package/core/tools/offset.js +29 -29
- package/core/tools/purge.js +10 -10
- package/core/tools/rotate.js +16 -16
- package/core/tools/scale.js +6 -6
- package/core/tools/trim.js +15 -15
- package/cspell.json +323 -0
- package/package.json +1 -1
- package/test/dimensions/alignedDimension.test.js +3 -3
- package/test/dimensions/angularDimension.test.js +7 -7
- package/test/dimensions/diametricDimension.test.js +9 -9
- package/test/dimensions/dimension.test.js +12 -12
- package/test/dimensions/{baseDimension.test.js → dimensionBase.test.js} +12 -12
- package/test/dimensions/{baseLinearDimension.test.js → linearDimensionBase.test.js} +7 -7
- package/test/dimensions/radialDimension.test.js +9 -9
- package/test/dimensions/rotatedDimension.test.js +4 -4
- package/test/entities/arc.test.js +10 -10
- package/test/entities/arctext.test.js +6 -6
- package/test/entities/circle.test.js +18 -18
- package/test/entities/hatch.test.js +362 -39
- package/test/entities/insert.test.js +9 -9
- package/test/entities/point.test.js +3 -3
- package/test/entities/{basePolyline.test.js → polylineBase.test.js} +131 -62
- package/test/entities/text.test.js +19 -19
- package/test/integration/exportIntegration.test.js +3 -3
- package/test/integration/userInputIntegration.test.js +5 -5
- package/test/lib/boundingBox.test.js +3 -3
- package/test/lib/canvas.test.js +9 -9
- package/test/lib/clipboard.test.js +73 -0
- package/test/lib/inputManager.test.js +4 -4
- package/test/lib/scene.test.js +9 -9
- package/test/lib/selectionManager.test.js +3 -3
- package/test/lib/snapping.test.js +1 -1
- package/test/properties/flags.test.js +24 -0
- package/test/properties/propertyManager.test.js +93 -22
- package/test/renderers/pdfRenderer.test.js +2 -2
- package/test/tables/block.test.js +63 -14
- package/test/tables/layerManager.test.js +2 -2
- package/test/test-helpers/hatchGridRenderer.js +3 -3
- package/test/test-helpers/test-helpers.js +6 -6
- package/test/tools/chamfer.test.js +60 -60
- package/test/tools/chamferFilletBase.test.js +36 -36
- package/test/tools/copy.test.js +6 -6
- 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 +2 -2
- package/test/tools/extend.test.js +84 -84
- package/test/tools/fillet.test.js +62 -62
- package/test/tools/matchProp.test.js +6 -6
- package/test/tools/mirror.test.js +26 -26
- package/test/tools/move.test.js +7 -7
- package/test/tools/offset.test.js +65 -65
- package/test/tools/purge.test.js +4 -4
- package/test/tools/rotate.test.js +10 -10
- package/test/tools/scale.test.js +28 -28
- package/test/tools/trim.test.js +109 -109
- package/test/tools/zoom.test.js +15 -17
package/core/tools/extend.js
CHANGED
|
@@ -19,7 +19,7 @@ export class Extend extends Tool {
|
|
|
19
19
|
/** Create an Extend command */
|
|
20
20
|
constructor() {
|
|
21
21
|
super();
|
|
22
|
-
this.
|
|
22
|
+
this.selectedEntity = null;
|
|
23
23
|
this.selectedBoundaryItems = [];
|
|
24
24
|
}
|
|
25
25
|
|
|
@@ -48,7 +48,7 @@ export class Extend extends Tool {
|
|
|
48
48
|
if (boundary === undefined) return;
|
|
49
49
|
}
|
|
50
50
|
|
|
51
|
-
// add all selected
|
|
51
|
+
// add all selected entities to boundary items
|
|
52
52
|
for (let i = 0; i < DesignCore.Scene.selectionManager.selectionSet.selectionSet.length; i++) {
|
|
53
53
|
const boundaryItem = DesignCore.Scene.entities.get(DesignCore.Scene.selectionManager.selectionSet.selectionSet[i]);
|
|
54
54
|
this.selectedBoundaryItems.push(boundaryItem);
|
|
@@ -58,7 +58,7 @@ export class Extend extends Tool {
|
|
|
58
58
|
while (true) {
|
|
59
59
|
const selection = await DesignCore.Scene.inputManager.requestInput(op2);
|
|
60
60
|
if (selection === undefined) break;
|
|
61
|
-
this.
|
|
61
|
+
this.selectedEntity = DesignCore.Scene.entities.get(selection.selectedEntityIndex);
|
|
62
62
|
DesignCore.Scene.selectionManager.removeLastSelection();
|
|
63
63
|
DesignCore.Scene.inputManager.actionCommand();
|
|
64
64
|
}
|
|
@@ -99,28 +99,28 @@ export class Extend extends Tool {
|
|
|
99
99
|
* Perform the command
|
|
100
100
|
*/
|
|
101
101
|
action() {
|
|
102
|
-
if (this.
|
|
103
|
-
if (typeof this.
|
|
104
|
-
DesignCore.Core.notify(`${this.type} - ${this.
|
|
105
|
-
this.
|
|
102
|
+
if (this.selectedEntity && this.selectedBoundaryItems.length) {
|
|
103
|
+
if (typeof this.selectedEntity.fromPolylinePoints !== 'function') {
|
|
104
|
+
DesignCore.Core.notify(`${this.type} - ${this.selectedEntity.type} ${Strings.Message.NOEXTEND}`);
|
|
105
|
+
this.selectedEntity = null;
|
|
106
106
|
return;
|
|
107
107
|
}
|
|
108
108
|
|
|
109
|
-
const intersectPoints = this.#collectIntersectPoints(this.
|
|
109
|
+
const intersectPoints = this.#collectIntersectPoints(this.selectedEntity);
|
|
110
110
|
|
|
111
111
|
if (intersectPoints.length) {
|
|
112
|
-
const stateChanges = this.#extendEntity(this.
|
|
112
|
+
const stateChanges = this.#extendEntity(this.selectedEntity, intersectPoints);
|
|
113
113
|
if (stateChanges?.length) {
|
|
114
114
|
DesignCore.Scene.commit(stateChanges);
|
|
115
115
|
} else {
|
|
116
|
-
DesignCore.Core.notify(`${this.type} - ${this.
|
|
116
|
+
DesignCore.Core.notify(`${this.type} - ${this.selectedEntity.type} ${Strings.Message.NOEXTEND}`);
|
|
117
117
|
}
|
|
118
118
|
} else {
|
|
119
|
-
DesignCore.Core.notify(`${this.type} - ${this.
|
|
119
|
+
DesignCore.Core.notify(`${this.type} - ${this.selectedEntity.type} ${Strings.Message.NOEXTEND}`);
|
|
120
120
|
}
|
|
121
121
|
}
|
|
122
122
|
|
|
123
|
-
this.
|
|
123
|
+
this.selectedEntity = null;
|
|
124
124
|
}
|
|
125
125
|
|
|
126
126
|
/**
|
|
@@ -147,7 +147,7 @@ export class Extend extends Tool {
|
|
|
147
147
|
* Compute a state change to extend entity to the nearest valid boundary
|
|
148
148
|
* intersection. Operates entirely in polyline-point space via
|
|
149
149
|
* entity.toPolylinePoints() / entity.fromPolylinePoints(), so it works for
|
|
150
|
-
* any entity that implements that protocol (Line,
|
|
150
|
+
* any entity that implements that protocol (Line, PolylineBase, and future
|
|
151
151
|
* entities such as Spline or Ellipse).
|
|
152
152
|
* Only straight end-segments (bulge === 0) can be extended.
|
|
153
153
|
* @param {Object} entity
|
package/core/tools/fillet.js
CHANGED
|
@@ -5,7 +5,7 @@ import { Logging } from '../lib/logging.js';
|
|
|
5
5
|
import { Constants } from '../lib/constants.js';
|
|
6
6
|
import { Utils } from '../lib/utils.js';
|
|
7
7
|
import { Line } from '../entities/line.js';
|
|
8
|
-
import {
|
|
8
|
+
import { PolylineBase } from '../entities/polylineBase.js';
|
|
9
9
|
import { AddState } from '../lib/stateManager.js';
|
|
10
10
|
import { Colour } from '../lib/colour.js';
|
|
11
11
|
|
|
@@ -65,9 +65,9 @@ export class Fillet extends ChamferFilletBase {
|
|
|
65
65
|
}
|
|
66
66
|
|
|
67
67
|
// input1 is a selection — validate and store first entity
|
|
68
|
-
const firstEntity = DesignCore.Scene.entities.get(input1.
|
|
68
|
+
const firstEntity = DesignCore.Scene.entities.get(input1.selectedEntityIndex);
|
|
69
69
|
DesignCore.Scene.selectionManager.removeLastSelection();
|
|
70
|
-
if (!(firstEntity instanceof Line) && !(firstEntity instanceof
|
|
70
|
+
if (!(firstEntity instanceof Line) && !(firstEntity instanceof PolylineBase)) {
|
|
71
71
|
DesignCore.Core.notify(`${this.type} - ${firstEntity.type} ${Strings.Message.NOFILLET}`);
|
|
72
72
|
continue;
|
|
73
73
|
}
|
|
@@ -79,16 +79,16 @@ export class Fillet extends ChamferFilletBase {
|
|
|
79
79
|
const input2 = await DesignCore.Scene.inputManager.requestInput(op2);
|
|
80
80
|
if (input2 === undefined) return;
|
|
81
81
|
|
|
82
|
-
const candidate = DesignCore.Scene.entities.get(input2.
|
|
82
|
+
const candidate = DesignCore.Scene.entities.get(input2.selectedEntityIndex);
|
|
83
83
|
DesignCore.Scene.selectionManager.removeLastSelection();
|
|
84
|
-
if (!(candidate instanceof Line) && !(candidate instanceof
|
|
84
|
+
if (!(candidate instanceof Line) && !(candidate instanceof PolylineBase)) {
|
|
85
85
|
DesignCore.Core.notify(`${this.type} - ${candidate.type} ${Strings.Message.NOFILLET}`);
|
|
86
86
|
continue;
|
|
87
87
|
}
|
|
88
88
|
if (!this.secondPick.setPick(candidate, input2.selectedPoint, `${Strings.Strings.ARC} - ${Strings.Message.NOFILLET}`)) continue;
|
|
89
89
|
// If both selections are the same polyline, segments must be consecutive
|
|
90
90
|
// or they must be the open-end segments of an open polyline.
|
|
91
|
-
if (candidate === firstEntity && firstEntity instanceof
|
|
91
|
+
if (candidate === firstEntity && firstEntity instanceof PolylineBase) {
|
|
92
92
|
const isConsecutive = firstEntity.areConsecutiveSegments(this.firstPick.segmentIndex, this.secondPick.segmentIndex);
|
|
93
93
|
const lastIdx = firstEntity.points.length - 1;
|
|
94
94
|
const isOpenEnds = !firstEntity.flags.hasFlag(1) &&
|
package/core/tools/matchProp.js
CHANGED
|
@@ -48,7 +48,7 @@ export class MatchProp extends Tool {
|
|
|
48
48
|
const sourceSelection = new PromptOptions(Strings.Input.SOURCE, [Input.Type.SINGLESELECTION], []);
|
|
49
49
|
const input = await DesignCore.Scene.inputManager.requestInput(sourceSelection);
|
|
50
50
|
if (input === undefined) return;
|
|
51
|
-
this.sourceIndex = input.
|
|
51
|
+
this.sourceIndex = input.selectedEntityIndex;
|
|
52
52
|
}
|
|
53
53
|
|
|
54
54
|
const destinationSelection = new PromptOptions(Strings.Input.DESTINATIONSET, [Input.Type.SELECTIONSET]);
|
package/core/tools/mirror.js
CHANGED
|
@@ -80,13 +80,13 @@ export class Mirror extends Tool {
|
|
|
80
80
|
|
|
81
81
|
// Preview mirrored entities (skip if mirror line has zero length)
|
|
82
82
|
if (!pt1.isSame(pt2)) {
|
|
83
|
-
for (let i = 0; i < DesignCore.Scene.selectionManager.
|
|
84
|
-
const
|
|
83
|
+
for (let i = 0; i < DesignCore.Scene.selectionManager.selectedEntities.length; i++) {
|
|
84
|
+
const entity = DesignCore.Scene.selectionManager.selectedEntities[i];
|
|
85
85
|
const entityIndex = DesignCore.Scene.selectionManager.selectionSet.selectionSet[i];
|
|
86
|
-
const
|
|
87
|
-
|
|
88
|
-
if (
|
|
89
|
-
|
|
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'));
|
|
90
90
|
}
|
|
91
91
|
}
|
|
92
92
|
}
|
|
@@ -109,18 +109,18 @@ export class Mirror extends Tool {
|
|
|
109
109
|
|
|
110
110
|
for (let i = 0; i < DesignCore.Scene.selectionManager.selectionSet.selectionSet.length; i++) {
|
|
111
111
|
const entityIndex = DesignCore.Scene.selectionManager.selectionSet.selectionSet[i];
|
|
112
|
-
const
|
|
113
|
-
const mirroredPoints = this.getMirroredPoints(
|
|
112
|
+
const entity = DesignCore.Scene.entities.get(entityIndex);
|
|
113
|
+
const mirroredPoints = this.getMirroredPoints(entity.points, pt1, pt2);
|
|
114
114
|
|
|
115
115
|
if (this.eraseSource) {
|
|
116
116
|
// Replace the original with its mirrored version
|
|
117
117
|
const updates = { points: mirroredPoints };
|
|
118
|
-
if (
|
|
119
|
-
const stateChange = new UpdateState(
|
|
118
|
+
if (entity.properties?.has('direction')) updates.direction = -entity.getProperty('direction');
|
|
119
|
+
const stateChange = new UpdateState(entity, updates);
|
|
120
120
|
stateChanges.push(stateChange);
|
|
121
121
|
} else {
|
|
122
122
|
// Keep the original and add a mirrored copy
|
|
123
|
-
const copyOfItem = Utils.cloneObject(
|
|
123
|
+
const copyOfItem = Utils.cloneObject(entity);
|
|
124
124
|
copyOfItem.setProperty('points', mirroredPoints);
|
|
125
125
|
if (copyOfItem.properties?.has('direction')) copyOfItem.setProperty('direction', -copyOfItem.getProperty('direction'));
|
|
126
126
|
const stateChange = new AddState(copyOfItem);
|
package/core/tools/move.js
CHANGED
|
@@ -74,9 +74,9 @@ export class Move extends Tool {
|
|
|
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,12 +102,12 @@ 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.
|
|
110
|
+
const previewEntity = Utils.cloneObject(this.selectedEntity).fromPolylinePoints(offsetPoints);
|
|
111
111
|
DesignCore.Scene.previewEntities.add(previewEntity);
|
|
112
112
|
}
|
|
113
113
|
}
|
|
@@ -118,10 +118,10 @@ export class Offset extends Tool {
|
|
|
118
118
|
*/
|
|
119
119
|
action() {
|
|
120
120
|
const offsetDistance = DesignCore.Scene.headers.offsetDistance;
|
|
121
|
-
if (!this.
|
|
121
|
+
if (!this.selectedEntity || offsetDistance <= 0) return;
|
|
122
122
|
|
|
123
123
|
const sidePoint = this.points[0];
|
|
124
|
-
const entity = this.
|
|
124
|
+
const entity = this.selectedEntity;
|
|
125
125
|
const offsetPoints = this.getOffsetPoints(entity, sidePoint, offsetDistance);
|
|
126
126
|
|
|
127
127
|
if (!offsetPoints) {
|
|
@@ -187,20 +187,20 @@ export class Offset extends Tool {
|
|
|
187
187
|
sign = cross >= 0 ? 1 : -1;
|
|
188
188
|
}
|
|
189
189
|
} else {
|
|
190
|
-
const
|
|
191
|
-
const currentRadius =
|
|
190
|
+
const centre = A.bulgeCentrePoint(B);
|
|
191
|
+
const currentRadius = centre.distance(A);
|
|
192
192
|
const arcDir = A.bulge > 0 ? 1 : -1;
|
|
193
|
-
const closestPt = sidePoint.closestPointOnArc(A, B,
|
|
193
|
+
const closestPt = sidePoint.closestPointOnArc(A, B, centre, arcDir);
|
|
194
194
|
if (closestPt === null) continue;
|
|
195
195
|
const dist = sidePoint.distance(closestPt);
|
|
196
196
|
if (dist < minDist) {
|
|
197
197
|
minDist = dist;
|
|
198
|
-
const
|
|
199
|
-
// For CCW arc (arcDir>0): left of travel = toward
|
|
200
|
-
// 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)
|
|
201
201
|
sign = arcDir > 0 ?
|
|
202
|
-
(
|
|
203
|
-
(
|
|
202
|
+
(distToCentre < currentRadius ? 1 : -1) :
|
|
203
|
+
(distToCentre >= currentRadius ? 1 : -1);
|
|
204
204
|
}
|
|
205
205
|
}
|
|
206
206
|
}
|
|
@@ -221,19 +221,19 @@ export class Offset extends Tool {
|
|
|
221
221
|
bulge: 0,
|
|
222
222
|
});
|
|
223
223
|
} else {
|
|
224
|
-
const
|
|
225
|
-
const currentRadius =
|
|
224
|
+
const centre = A.bulgeCentrePoint(B);
|
|
225
|
+
const currentRadius = centre.distance(A);
|
|
226
226
|
const arcDir = A.bulge > 0 ? 1 : -1;
|
|
227
227
|
const newRadius = currentRadius - arcDir * distance * sign;
|
|
228
228
|
if (newRadius <= 0) return null;
|
|
229
|
-
const startAngle = Math.atan2(A.y -
|
|
230
|
-
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);
|
|
231
231
|
offsetSegs.push({
|
|
232
232
|
type: 'arc',
|
|
233
|
-
A: new Point(
|
|
234
|
-
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)),
|
|
235
235
|
bulge: A.bulge,
|
|
236
|
-
|
|
236
|
+
centre,
|
|
237
237
|
radius: newRadius,
|
|
238
238
|
});
|
|
239
239
|
}
|
|
@@ -309,9 +309,9 @@ export class Offset extends Tool {
|
|
|
309
309
|
const dist = throughPoint.distance(closest);
|
|
310
310
|
if (dist < minDist) minDist = dist;
|
|
311
311
|
} else {
|
|
312
|
-
const
|
|
313
|
-
const radius =
|
|
314
|
-
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);
|
|
315
315
|
if (dist < minDist) minDist = dist;
|
|
316
316
|
}
|
|
317
317
|
}
|
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
|
@@ -73,7 +73,7 @@ export class Rotate extends Tool {
|
|
|
73
73
|
this.baseAngle = refBase.angle(refEnd);
|
|
74
74
|
// set the base point to null
|
|
75
75
|
this.basePoint = null;
|
|
76
|
-
// restore inputPoint to the rotation
|
|
76
|
+
// restore inputPoint to the rotation centre so the tracking line
|
|
77
77
|
// uses the correct origin for the final angle input
|
|
78
78
|
DesignCore.Scene.inputManager.inputPoint = this.points[0];
|
|
79
79
|
} else if (Input.getType(input2) === Input.Type.NUMBER) {
|
|
@@ -99,22 +99,22 @@ export class Rotate extends Tool {
|
|
|
99
99
|
const mousePoint = DesignCore.Mouse.pointOnScene();
|
|
100
100
|
|
|
101
101
|
if (this.points.length >= 1 && this.baseAngle !== null || this.basePoint !== null) {
|
|
102
|
-
// Draw a rubber-band line from
|
|
103
|
-
const
|
|
104
|
-
DesignCore.Scene.auxiliaryEntities.add(new RubberBand([
|
|
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]));
|
|
105
105
|
}
|
|
106
106
|
|
|
107
107
|
if (this.points.length >= 1) {
|
|
108
108
|
const ang = this.points[0].angle(mousePoint);
|
|
109
109
|
const theta = this.baseAngle === null ? 0 : ang - this.baseAngle;
|
|
110
|
-
const
|
|
110
|
+
const centre = this.points[0];
|
|
111
111
|
|
|
112
|
-
for (let i = 0; i < DesignCore.Scene.selectionManager.
|
|
113
|
-
const
|
|
112
|
+
for (let i = 0; i < DesignCore.Scene.selectionManager.selectedEntities.length; i++) {
|
|
113
|
+
const entity = DesignCore.Scene.selectionManager.selectedEntities[i];
|
|
114
114
|
// get the original points from the scene entities
|
|
115
115
|
const entityIndex = DesignCore.Scene.selectionManager.selectionSet.selectionSet[i];
|
|
116
|
-
const
|
|
117
|
-
|
|
116
|
+
const originalEntity = DesignCore.Scene.entities.get(entityIndex);
|
|
117
|
+
entity.setProperty('points', this.getRotatedPoints(originalEntity.points, centre, theta));
|
|
118
118
|
}
|
|
119
119
|
}
|
|
120
120
|
};
|
|
@@ -125,13 +125,13 @@ export class Rotate extends Tool {
|
|
|
125
125
|
action() {
|
|
126
126
|
const ang = this.points[0].angle(this.points[1]);
|
|
127
127
|
const theta = ang - this.baseAngle;
|
|
128
|
-
const
|
|
128
|
+
const centre = this.points[0];
|
|
129
129
|
|
|
130
130
|
const stateChanges = [];
|
|
131
131
|
|
|
132
132
|
for (let index = 0; index < DesignCore.Scene.selectionManager.selectionSet.selectionSet.length; index++) {
|
|
133
|
-
const
|
|
134
|
-
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) });
|
|
135
135
|
stateChanges.push(stateChange);
|
|
136
136
|
}
|
|
137
137
|
|
|
@@ -141,12 +141,12 @@ export class Rotate extends Tool {
|
|
|
141
141
|
/**
|
|
142
142
|
* Get rotated points
|
|
143
143
|
* @param {Array} points
|
|
144
|
-
* @param {Point}
|
|
145
|
-
* @param {
|
|
144
|
+
* @param {Point} centre
|
|
145
|
+
* @param {number} theta
|
|
146
146
|
* @return {Array} rotatedPoints
|
|
147
147
|
*/
|
|
148
|
-
getRotatedPoints(points,
|
|
149
|
-
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));
|
|
150
150
|
return rotatedPoints;
|
|
151
151
|
}
|
|
152
152
|
}
|
package/core/tools/scale.js
CHANGED
|
@@ -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
|
|
package/core/tools/trim.js
CHANGED
|
@@ -20,7 +20,7 @@ export class Trim extends Tool {
|
|
|
20
20
|
/** Create a Trim command */
|
|
21
21
|
constructor() {
|
|
22
22
|
super();
|
|
23
|
-
this.
|
|
23
|
+
this.selectedEntity = null;
|
|
24
24
|
this.selectedBoundaryItems = [];
|
|
25
25
|
}
|
|
26
26
|
|
|
@@ -49,7 +49,7 @@ export class Trim extends Tool {
|
|
|
49
49
|
if (boundary === undefined) return;
|
|
50
50
|
}
|
|
51
51
|
|
|
52
|
-
// add all selected
|
|
52
|
+
// add all selected entities to boundary items
|
|
53
53
|
for (let i = 0; i < DesignCore.Scene.selectionManager.selectionSet.selectionSet.length; i++) {
|
|
54
54
|
const boundaryItem = DesignCore.Scene.entities.get(DesignCore.Scene.selectionManager.selectionSet.selectionSet[i]);
|
|
55
55
|
this.selectedBoundaryItems.push(boundaryItem);
|
|
@@ -59,7 +59,7 @@ export class Trim extends Tool {
|
|
|
59
59
|
while (true) {
|
|
60
60
|
const selection = await DesignCore.Scene.inputManager.requestInput(selectOp);
|
|
61
61
|
if (selection === undefined) break;
|
|
62
|
-
this.
|
|
62
|
+
this.selectedEntity = DesignCore.Scene.entities.get(selection.selectedEntityIndex);
|
|
63
63
|
DesignCore.Scene.selectionManager.removeLastSelection();
|
|
64
64
|
DesignCore.Scene.inputManager.actionCommand();
|
|
65
65
|
}
|
|
@@ -103,26 +103,26 @@ export class Trim extends Tool {
|
|
|
103
103
|
* Perform the command
|
|
104
104
|
*/
|
|
105
105
|
action() {
|
|
106
|
-
if (this.
|
|
107
|
-
if (typeof this.
|
|
108
|
-
DesignCore.Core.notify(`${this.type} - ${this.
|
|
109
|
-
this.
|
|
106
|
+
if (this.selectedEntity && this.selectedBoundaryItems.length) {
|
|
107
|
+
if (typeof this.selectedEntity.fromPolylinePoints !== 'function') {
|
|
108
|
+
DesignCore.Core.notify(`${this.type} - ${this.selectedEntity.type} ${Strings.Message.NOTRIM}`);
|
|
109
|
+
this.selectedEntity = null;
|
|
110
110
|
return;
|
|
111
111
|
}
|
|
112
112
|
|
|
113
|
-
const intersectPoints = this.#collectIntersectPoints(this.
|
|
113
|
+
const intersectPoints = this.#collectIntersectPoints(this.selectedEntity);
|
|
114
114
|
|
|
115
115
|
if (intersectPoints.length) {
|
|
116
|
-
const stateChanges = this.#trimEntity(this.
|
|
116
|
+
const stateChanges = this.#trimEntity(this.selectedEntity, intersectPoints);
|
|
117
117
|
if (stateChanges?.length) {
|
|
118
118
|
DesignCore.Scene.commit(stateChanges);
|
|
119
119
|
}
|
|
120
120
|
} else {
|
|
121
|
-
DesignCore.Core.notify(`${this.type} - ${this.
|
|
121
|
+
DesignCore.Core.notify(`${this.type} - ${this.selectedEntity.type} ${Strings.Message.NOTRIM}`);
|
|
122
122
|
}
|
|
123
123
|
}
|
|
124
124
|
|
|
125
|
-
this.
|
|
125
|
+
this.selectedEntity = null;
|
|
126
126
|
}
|
|
127
127
|
|
|
128
128
|
/**
|
|
@@ -150,7 +150,7 @@ export class Trim extends Tool {
|
|
|
150
150
|
* surrounding the mouse position. Operates entirely in polyline-point space
|
|
151
151
|
* via entity.toPolylinePoints() / entity.fromPolylinePoints(), so it works
|
|
152
152
|
* for any entity that implements that protocol (Line, Arc, Circle,
|
|
153
|
-
*
|
|
153
|
+
* PolylineBase, and future entities such as Spline or Ellipse).
|
|
154
154
|
* @param {Object} entity
|
|
155
155
|
* @param {Array} intersectPoints
|
|
156
156
|
* @return {Array}
|
|
@@ -296,10 +296,10 @@ export class Trim extends Tool {
|
|
|
296
296
|
if (fromLoc.segmentIndex === toLoc.segmentIndex) {
|
|
297
297
|
const startPoint = fromLoc.point.clone();
|
|
298
298
|
if (fromSegStart.bulge !== 0 && fromSegStart.bulge !== undefined) {
|
|
299
|
-
const
|
|
299
|
+
const centre = fromSegStart.bulgeCentrePoint(fromSegEnd);
|
|
300
300
|
const direction = fromSegStart.bulge > 0 ? 1 : -1;
|
|
301
|
-
const startAngle =
|
|
302
|
-
const endAngle =
|
|
301
|
+
const startAngle = centre.angle(fromLoc.point);
|
|
302
|
+
const endAngle = centre.angle(toLoc.point);
|
|
303
303
|
const includedAngle = ((endAngle - startAngle) * direction + 4 * Math.PI) % (2 * Math.PI);
|
|
304
304
|
startPoint.bulge = Math.tan(includedAngle / 4) * direction;
|
|
305
305
|
}
|