@design-core/core 0.0.7 → 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/.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 +28 -28
- package/core/entities/insert.js +5 -5
- 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 +6 -4
- 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/property.js +1 -1
- package/core/properties/propertyManager.js +37 -37
- package/core/tables/block.js +48 -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 +321 -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 +39 -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/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/propertyManager.test.js +22 -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 +5 -5
|
@@ -2,7 +2,7 @@ import { Tool } from './tool.js';
|
|
|
2
2
|
import { Strings } from '../lib/strings.js';
|
|
3
3
|
import { Constants } from '../lib/constants.js';
|
|
4
4
|
import { Line } from '../entities/line.js';
|
|
5
|
-
import {
|
|
5
|
+
import { PolylineBase } from '../entities/polylineBase.js';
|
|
6
6
|
import { AddState, RemoveState, UpdateState } from '../lib/stateManager.js';
|
|
7
7
|
import { CornerEntity } from './cornerEntity.js';
|
|
8
8
|
import { Intersection } from '../lib/intersect.js';
|
|
@@ -104,7 +104,7 @@ export class ChamferFilletBase extends Tool {
|
|
|
104
104
|
if (index === undefined) return null;
|
|
105
105
|
|
|
106
106
|
const candidate = DesignCore.Scene.entities.get(index);
|
|
107
|
-
if (!(candidate instanceof Line) && !(candidate instanceof
|
|
107
|
+
if (!(candidate instanceof Line) && !(candidate instanceof PolylineBase)) return null;
|
|
108
108
|
|
|
109
109
|
const tempSecond = new CornerEntity();
|
|
110
110
|
if (!tempSecond.setPick(candidate, mousePoint, '')) return null;
|
|
@@ -143,8 +143,8 @@ export class ChamferFilletBase extends Tool {
|
|
|
143
143
|
*/
|
|
144
144
|
applyCornerTrim(firstCornerPoint, secondCornerPoint, newEntity) {
|
|
145
145
|
const isSharpTrim = newEntity === null;
|
|
146
|
-
const firstIsPolyline = this.firstPick.entity instanceof
|
|
147
|
-
const secondIsPolyline = this.secondPick.entity instanceof
|
|
146
|
+
const firstIsPolyline = this.firstPick.entity instanceof PolylineBase;
|
|
147
|
+
const secondIsPolyline = this.secondPick.entity instanceof PolylineBase;
|
|
148
148
|
|
|
149
149
|
// Two standalone entities: update both, optionally add the new entity.
|
|
150
150
|
if (!firstIsPolyline && !secondIsPolyline) {
|
package/core/tools/copy.js
CHANGED
|
@@ -84,10 +84,10 @@ export class Copy extends Tool {
|
|
|
84
84
|
const delta = mousePoint.subtract(this.lastMousePoint || this.points[0]);
|
|
85
85
|
this.lastMousePoint = mousePoint;
|
|
86
86
|
|
|
87
|
-
for (let i = 0; i < DesignCore.Scene.selectionManager.
|
|
88
|
-
const
|
|
89
|
-
const offsetPoints =
|
|
90
|
-
|
|
87
|
+
for (let i = 0; i < DesignCore.Scene.selectionManager.selectedEntities.length; i++) {
|
|
88
|
+
const entity = DesignCore.Scene.selectionManager.selectedEntities[i];
|
|
89
|
+
const offsetPoints = entity.points.map((p) => new Point(p.x, p.y, p.bulge, p.sequence).add(delta));
|
|
90
|
+
entity.setProperty('points', offsetPoints);
|
|
91
91
|
}
|
|
92
92
|
}
|
|
93
93
|
}
|
|
@@ -103,10 +103,10 @@ export class Copy extends Tool {
|
|
|
103
103
|
const stateChanges = [];
|
|
104
104
|
|
|
105
105
|
for (let i = 0; i < DesignCore.Scene.selectionManager.selectionSet.selectionSet.length; i++) {
|
|
106
|
-
const
|
|
107
|
-
const offsetPoints =
|
|
108
|
-
|
|
109
|
-
const stateChange = new AddState(
|
|
106
|
+
const copyOfEntity = Utils.cloneObject(DesignCore.Scene.entities.get(DesignCore.Scene.selectionManager.selectionSet.selectionSet[i]));
|
|
107
|
+
const offsetPoints = copyOfEntity.points.map((p) => new Point(p.x, p.y, p.bulge, p.sequence).add(delta));
|
|
108
|
+
copyOfEntity.setProperty('points', offsetPoints);
|
|
109
|
+
const stateChange = new AddState(copyOfEntity);
|
|
110
110
|
stateChanges.push(stateChange);
|
|
111
111
|
}
|
|
112
112
|
|
package/core/tools/copybase.js
CHANGED
|
@@ -56,11 +56,11 @@ export class Copybase extends Tool {
|
|
|
56
56
|
* Perform the command
|
|
57
57
|
*/
|
|
58
58
|
action() {
|
|
59
|
-
// generate clipboard data from selected
|
|
60
|
-
const
|
|
59
|
+
// generate clipboard data from selected entities
|
|
60
|
+
const selectedEntities = DesignCore.Scene.selectionManager.selectedEntities;
|
|
61
61
|
|
|
62
62
|
// create clipboard data
|
|
63
|
-
DesignCore.Clipboard.Entities =
|
|
63
|
+
DesignCore.Clipboard.Entities = selectedEntities;
|
|
64
64
|
// set base point
|
|
65
65
|
DesignCore.Clipboard.BasePoint = this.points[0];
|
|
66
66
|
}
|
package/core/tools/copyclip.js
CHANGED
|
@@ -52,10 +52,10 @@ export class Copyclip extends Tool {
|
|
|
52
52
|
* Perform the command
|
|
53
53
|
*/
|
|
54
54
|
action() {
|
|
55
|
-
// generate clipboard data from selected
|
|
56
|
-
const
|
|
55
|
+
// generate clipboard data from selected entities
|
|
56
|
+
const selectedEntities = DesignCore.Scene.selectionManager.selectedEntities;
|
|
57
57
|
|
|
58
58
|
// create clipboard data
|
|
59
|
-
DesignCore.Clipboard.Entities =
|
|
59
|
+
DesignCore.Clipboard.Entities = selectedEntities;
|
|
60
60
|
}
|
|
61
61
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Line } from '../entities/line.js';
|
|
2
|
-
import {
|
|
2
|
+
import { PolylineBase } from '../entities/polylineBase.js';
|
|
3
3
|
|
|
4
4
|
import { DesignCore } from '../designCore.js';
|
|
5
5
|
|
|
@@ -61,7 +61,7 @@ export class CornerEntity {
|
|
|
61
61
|
setPick(entity, clickPoint, arcSegmentErrorMsg) {
|
|
62
62
|
this.entity = entity;
|
|
63
63
|
this.clickPoint = clickPoint;
|
|
64
|
-
if (!(this.entity instanceof
|
|
64
|
+
if (!(this.entity instanceof PolylineBase)) {
|
|
65
65
|
this.segment = null;
|
|
66
66
|
this.segmentIndex = null;
|
|
67
67
|
return true;
|
package/core/tools/cutclip.js
CHANGED
|
@@ -53,11 +53,11 @@ export class Cutclip extends Tool {
|
|
|
53
53
|
* Perform the command
|
|
54
54
|
*/
|
|
55
55
|
action() {
|
|
56
|
-
// generate clipboard data from selected
|
|
57
|
-
const
|
|
56
|
+
// generate clipboard data from selected entities
|
|
57
|
+
const selectedEntities = DesignCore.Scene.selectionManager.selectedEntities;
|
|
58
58
|
|
|
59
59
|
// create clipboard data
|
|
60
|
-
DesignCore.Clipboard.Entities =
|
|
60
|
+
DesignCore.Clipboard.Entities = selectedEntities;
|
|
61
61
|
// get a copy of the selection set
|
|
62
62
|
const selections = DesignCore.Scene.selectionManager.selectionSet.selectionSet.slice();
|
|
63
63
|
// create state changes for each of the selections
|
package/core/tools/explode.js
CHANGED
|
@@ -83,23 +83,23 @@ export class Explode extends Tool {
|
|
|
83
83
|
|
|
84
84
|
// check the insert has a block and
|
|
85
85
|
// check the block has items
|
|
86
|
-
if (insert.block === undefined || insert.block.
|
|
86
|
+
if (insert.block === undefined || insert.block.entities.length === 0) {
|
|
87
87
|
counter++;
|
|
88
88
|
continue;
|
|
89
89
|
}
|
|
90
90
|
|
|
91
91
|
const insertPoint = insert.points[0];
|
|
92
92
|
const block = insert.block;
|
|
93
|
-
const blockItems = block.
|
|
93
|
+
const blockItems = block.entities;
|
|
94
94
|
|
|
95
95
|
const rotation = Utils.degrees2radians(insert.getProperty('rotation'));
|
|
96
96
|
const origin = new Point(0, 0);
|
|
97
97
|
|
|
98
98
|
blockItems.forEach((blockItem) => {
|
|
99
|
-
const
|
|
100
|
-
const points =
|
|
101
|
-
|
|
102
|
-
const stateChange = new AddState(
|
|
99
|
+
const copyOfItem = Utils.cloneObject(blockItem);
|
|
100
|
+
const points = copyOfItem.points.map((p) => new Point(p.x, p.y, p.bulge, p.sequence).rotate(origin, rotation).add(insertPoint));
|
|
101
|
+
copyOfItem.points = points;
|
|
102
|
+
const stateChange = new AddState(copyOfItem);
|
|
103
103
|
stateChanges.push(stateChange);
|
|
104
104
|
});
|
|
105
105
|
|
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
|
|