@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/designCore.js
CHANGED
|
@@ -4,7 +4,7 @@ import { Input, PromptOptions } from '../lib/inputManager.js';
|
|
|
4
4
|
import { Logging } from '../lib/logging.js';
|
|
5
5
|
import { DXFFile } from '../lib/dxf/dxfFile.js';
|
|
6
6
|
import { Point } from '../entities/point.js';
|
|
7
|
-
import {
|
|
7
|
+
import { LinearDimensionBase } from './linearDimensionBase.js';
|
|
8
8
|
|
|
9
9
|
import { DesignCore } from '../designCore.js';
|
|
10
10
|
import { Property } from '../properties/property.js';
|
|
@@ -14,7 +14,7 @@ import { Property } from '../properties/property.js';
|
|
|
14
14
|
* Aligned Dimension Entity Class
|
|
15
15
|
* @extends LinearDimension
|
|
16
16
|
*/
|
|
17
|
-
export class AlignedDimension extends
|
|
17
|
+
export class AlignedDimension extends LinearDimensionBase {
|
|
18
18
|
/**
|
|
19
19
|
* Create an Aligned Dimension
|
|
20
20
|
* @param {Array} data
|
|
@@ -72,19 +72,19 @@ export class AlignedDimension extends BaseLinearDimension {
|
|
|
72
72
|
|
|
73
73
|
/**
|
|
74
74
|
* Get sequenced points from user selection
|
|
75
|
-
* @param {any}
|
|
75
|
+
* @param {any} entities
|
|
76
76
|
* @param {Point} textPos
|
|
77
77
|
* @return {Array} array of points
|
|
78
78
|
*/
|
|
79
|
-
static getPointsFromSelection(
|
|
79
|
+
static getPointsFromSelection(entities, textPos) {
|
|
80
80
|
const points = [];
|
|
81
|
-
const
|
|
81
|
+
const entity = entities[0];
|
|
82
82
|
|
|
83
|
-
const Pt13 =
|
|
83
|
+
const Pt13 = entity.points[0];
|
|
84
84
|
Pt13.sequence = 13;
|
|
85
85
|
points.push(Pt13);
|
|
86
86
|
|
|
87
|
-
const Pt14 =
|
|
87
|
+
const Pt14 = entity.points[1];
|
|
88
88
|
Pt14.sequence = 14;
|
|
89
89
|
points.push(Pt14);
|
|
90
90
|
|
|
@@ -2,12 +2,12 @@
|
|
|
2
2
|
import { Utils } from '../lib/utils.js';
|
|
3
3
|
import { Strings } from '../lib/strings.js';
|
|
4
4
|
import { Arc } from '../entities/arc.js';
|
|
5
|
-
import {
|
|
5
|
+
import { PolylineBase } from '../entities/polylineBase.js';
|
|
6
6
|
import { Line } from '../entities/line.js';
|
|
7
7
|
import { Input, PromptOptions } from '../lib/inputManager.js';
|
|
8
8
|
import { Logging } from '../lib/logging.js';
|
|
9
9
|
import { DXFFile } from '../lib/dxf/dxfFile.js';
|
|
10
|
-
import {
|
|
10
|
+
import { DimensionBase } from './dimensionBase.js';
|
|
11
11
|
import { Intersection } from '../lib/intersect.js';
|
|
12
12
|
import { Point } from '../entities/point.js';
|
|
13
13
|
|
|
@@ -18,9 +18,9 @@ import { Property } from '../properties/property.js';
|
|
|
18
18
|
|
|
19
19
|
/**
|
|
20
20
|
* Angular Dimension Entity Class
|
|
21
|
-
* @extends
|
|
21
|
+
* @extends DimensionBase
|
|
22
22
|
*/
|
|
23
|
-
export class AngularDimension extends
|
|
23
|
+
export class AngularDimension extends DimensionBase {
|
|
24
24
|
/**
|
|
25
25
|
* Create an Angular Dimension
|
|
26
26
|
* @param {Array} data
|
|
@@ -62,25 +62,25 @@ export class AngularDimension extends BaseDimension {
|
|
|
62
62
|
|
|
63
63
|
const op = new PromptOptions(Strings.Input.SELECT, [Input.Type.SINGLESELECTION]);
|
|
64
64
|
const selection = await DesignCore.Scene.inputManager.requestInput(op);
|
|
65
|
-
let
|
|
65
|
+
let selectedEntity = DesignCore.Scene.entities.get(selection.selectedEntityIndex);
|
|
66
66
|
|
|
67
|
-
if ([Line,
|
|
68
|
-
if (
|
|
67
|
+
if ([Line, PolylineBase].some((entity) => selectedEntity instanceof entity)) {
|
|
68
|
+
if (selectedEntity instanceof PolylineBase) {
|
|
69
69
|
// get the segment closest to the mouse point
|
|
70
|
-
const segment =
|
|
70
|
+
const segment = selectedEntity.getClosestSegment(selection.selectedPoint);
|
|
71
71
|
|
|
72
72
|
if (segment instanceof Line) {
|
|
73
|
-
// update the selected
|
|
74
|
-
|
|
73
|
+
// update the selected entity to be the polyline arc segment
|
|
74
|
+
selectedEntity = segment;
|
|
75
75
|
}
|
|
76
76
|
}
|
|
77
77
|
|
|
78
|
-
if (
|
|
79
|
-
Pt15 =
|
|
78
|
+
if (selectedEntity instanceof Line) {
|
|
79
|
+
Pt15 = selectedEntity.points[0];
|
|
80
80
|
Pt15.sequence = 15;
|
|
81
81
|
this.points.push(Pt15);
|
|
82
82
|
|
|
83
|
-
Pt10 =
|
|
83
|
+
Pt10 = selectedEntity.points[1];
|
|
84
84
|
Pt10.sequence = 10;
|
|
85
85
|
this.points.push(Pt10);
|
|
86
86
|
}
|
|
@@ -91,24 +91,24 @@ export class AngularDimension extends BaseDimension {
|
|
|
91
91
|
DesignCore.Scene.selectionManager.reset();
|
|
92
92
|
const op1 = new PromptOptions(Strings.Input.SELECT, [Input.Type.SINGLESELECTION]);
|
|
93
93
|
const selection2 = await DesignCore.Scene.inputManager.requestInput(op1);
|
|
94
|
-
let
|
|
94
|
+
let selectedEntity = DesignCore.Scene.entities.get(selection2.selectedEntityIndex);
|
|
95
95
|
|
|
96
|
-
if ([Line,
|
|
97
|
-
if (
|
|
96
|
+
if ([Line, PolylineBase].some((entity) => selectedEntity instanceof entity)) {
|
|
97
|
+
if (selectedEntity instanceof PolylineBase) {
|
|
98
98
|
// get the segment closest to the mouse point
|
|
99
|
-
const segment =
|
|
99
|
+
const segment = selectedEntity.getClosestSegment(selection2.selectedPoint);
|
|
100
100
|
|
|
101
101
|
if (segment instanceof Line) {
|
|
102
|
-
// update the selected
|
|
103
|
-
|
|
102
|
+
// update the selected entity to be the polyline arc segment
|
|
103
|
+
selectedEntity = segment;
|
|
104
104
|
}
|
|
105
105
|
}
|
|
106
|
-
if (
|
|
107
|
-
Pt13 =
|
|
106
|
+
if (selectedEntity instanceof Line) {
|
|
107
|
+
Pt13 = selectedEntity.points[0];
|
|
108
108
|
Pt13.sequence = 13;
|
|
109
109
|
this.points.push(Pt13);
|
|
110
110
|
|
|
111
|
-
Pt14 =
|
|
111
|
+
Pt14 = selectedEntity.points[1];
|
|
112
112
|
Pt14.sequence = 14;
|
|
113
113
|
this.points.push(Pt14);
|
|
114
114
|
}
|
|
@@ -153,23 +153,23 @@ export class AngularDimension extends BaseDimension {
|
|
|
153
153
|
|
|
154
154
|
/**
|
|
155
155
|
* Get sequenced points from user selection
|
|
156
|
-
* @param {any}
|
|
156
|
+
* @param {any} entities
|
|
157
157
|
* @param {Point} textPos
|
|
158
158
|
* @return {Array} array of points
|
|
159
159
|
*/
|
|
160
|
-
static getPointsFromSelection(
|
|
161
|
-
// Transform the
|
|
162
|
-
// Do nothing more than transform the
|
|
160
|
+
static getPointsFromSelection(entities, textPos) {
|
|
161
|
+
// Transform the entities into points
|
|
162
|
+
// Do nothing more than transform the entities into points
|
|
163
163
|
|
|
164
164
|
const points = [];
|
|
165
|
-
const
|
|
166
|
-
const
|
|
165
|
+
const entity1 = entities[0];
|
|
166
|
+
const entity2 = entities[1];
|
|
167
167
|
|
|
168
|
-
const tempPt15 =
|
|
169
|
-
const tempPt10 =
|
|
168
|
+
const tempPt15 = entity1.points[0];
|
|
169
|
+
const tempPt10 = entity1.points[1];
|
|
170
170
|
|
|
171
|
-
const tempPt13 =
|
|
172
|
-
const tempPt14 =
|
|
171
|
+
const tempPt13 = entity2.points[0];
|
|
172
|
+
const tempPt14 = entity2.points[1];
|
|
173
173
|
|
|
174
174
|
// Check the lines intersect
|
|
175
175
|
const intersect = Intersection.intersectSegmentSegment(tempPt15, tempPt10, tempPt13, tempPt14, false, true);
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import { Strings } from '../lib/strings.js';
|
|
2
2
|
import { Circle } from '../entities/circle.js';
|
|
3
3
|
import { Arc } from '../entities/arc.js';
|
|
4
|
-
import {
|
|
4
|
+
import { PolylineBase } from '../entities/polylineBase.js';
|
|
5
5
|
import { Line } from '../entities/line.js';
|
|
6
6
|
import { Text } from '../entities/text.js';
|
|
7
7
|
import { Point } from '../entities/point.js';
|
|
8
8
|
import { Intersection } from '../lib/intersect.js';
|
|
9
9
|
import { Input, PromptOptions } from '../lib/inputManager.js';
|
|
10
10
|
import { Logging } from '../lib/logging.js';
|
|
11
|
-
import {
|
|
11
|
+
import { DimensionBase } from './dimensionBase.js';
|
|
12
12
|
|
|
13
13
|
import { DesignCore } from '../designCore.js';
|
|
14
14
|
import { Property } from '../properties/property.js';
|
|
@@ -16,9 +16,9 @@ import { Property } from '../properties/property.js';
|
|
|
16
16
|
|
|
17
17
|
/**
|
|
18
18
|
* Base Class for Circular Dimensions - Radius and Diameter
|
|
19
|
-
* @extends
|
|
19
|
+
* @extends DimensionBase
|
|
20
20
|
*/
|
|
21
|
-
export class
|
|
21
|
+
export class CircularDimensionBase extends DimensionBase {
|
|
22
22
|
/**
|
|
23
23
|
* Circular Dimension Constructor
|
|
24
24
|
* @param {Array} data
|
|
@@ -44,25 +44,25 @@ export class BaseCircularDimension extends BaseDimension {
|
|
|
44
44
|
const op = new PromptOptions(Strings.Input.SELECT, [Input.Type.SINGLESELECTION]);
|
|
45
45
|
const selection = await DesignCore.Scene.inputManager.requestInput(op);
|
|
46
46
|
|
|
47
|
-
let
|
|
47
|
+
let selectedEntity = DesignCore.Scene.entities.get(selection.selectedEntityIndex);
|
|
48
48
|
|
|
49
|
-
if ([Circle, Arc,
|
|
50
|
-
if (
|
|
49
|
+
if ([Circle, Arc, PolylineBase].some((entity) => selectedEntity instanceof entity)) {
|
|
50
|
+
if (selectedEntity instanceof PolylineBase) {
|
|
51
51
|
// get the segment closest to the mouse point
|
|
52
|
-
const segment =
|
|
52
|
+
const segment = selectedEntity.getClosestSegment(selection.selectedPoint);
|
|
53
53
|
|
|
54
54
|
if (segment instanceof Arc) {
|
|
55
|
-
// update the selected
|
|
56
|
-
|
|
55
|
+
// update the selected entity to be the polyline arc segment
|
|
56
|
+
selectedEntity = segment;
|
|
57
57
|
}
|
|
58
58
|
}
|
|
59
59
|
|
|
60
|
-
if (
|
|
61
|
-
Pt15 =
|
|
60
|
+
if (selectedEntity instanceof Circle || selectedEntity instanceof Arc) {
|
|
61
|
+
Pt15 = selectedEntity.points[1];
|
|
62
62
|
Pt15.sequence = 15;
|
|
63
63
|
this.points.push(Pt15);
|
|
64
64
|
|
|
65
|
-
Pt10 =
|
|
65
|
+
Pt10 = selectedEntity.points[0];
|
|
66
66
|
Pt10.sequence = 10;
|
|
67
67
|
this.points.push(Pt10);
|
|
68
68
|
}
|
|
@@ -111,7 +111,7 @@ export class BaseCircularDimension extends BaseDimension {
|
|
|
111
111
|
const entities = [];
|
|
112
112
|
|
|
113
113
|
const Pt15 = this.getPointBySequence(this.points, 15); // radius point
|
|
114
|
-
const Pt10 = this.getPointBySequence(this.points, 10); //
|
|
114
|
+
const Pt10 = this.getPointBySequence(this.points, 10); // centre point for radial dim or radial point for diametric dim
|
|
115
115
|
let Pt11 = this.getPointBySequence(this.points, 11); // text position
|
|
116
116
|
|
|
117
117
|
// Style values
|
|
@@ -192,7 +192,7 @@ export class BaseCircularDimension extends BaseDimension {
|
|
|
192
192
|
|
|
193
193
|
// DIMTAD - Text vertical position
|
|
194
194
|
switch (DIMTAD) {
|
|
195
|
-
case 0: // 0 =
|
|
195
|
+
case 0: // 0 = Centres the dimension text between the extension lines.
|
|
196
196
|
break;
|
|
197
197
|
case 1: // 1 = Places the dimension text above the dimension line except when the dimension line is not horizontal and text inside the extension lines is forced horizontal ( DIMTIH = 1).
|
|
198
198
|
textPosition = textPosition.project(textAboveDirection, textAboveDistance);
|
|
@@ -231,13 +231,13 @@ export class BaseCircularDimension extends BaseDimension {
|
|
|
231
231
|
if (!DIMTOFL) {
|
|
232
232
|
// Add the centre mark for circular dimensions
|
|
233
233
|
|
|
234
|
-
let
|
|
234
|
+
let centre = Pt10;
|
|
235
235
|
|
|
236
|
-
//
|
|
236
|
+
// centre point is mid point for diametric dimensions
|
|
237
237
|
if (this.dimType.getBaseDimType() === 3) {
|
|
238
|
-
|
|
238
|
+
centre = Pt10.midPoint(Pt15);
|
|
239
239
|
}
|
|
240
|
-
entities.push(...this.getCentreMark(
|
|
240
|
+
entities.push(...this.getCentreMark(centre));
|
|
241
241
|
}
|
|
242
242
|
|
|
243
243
|
return entities;
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { DXFFile } from '../lib/dxf/dxfFile.js';
|
|
2
|
-
import {
|
|
2
|
+
import { CircularDimensionBase } from './circularDimensionBase.js';
|
|
3
3
|
import { Property } from '../properties/property.js';
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* Diametric Dimension Entity Class
|
|
7
|
-
* @extends
|
|
7
|
+
* @extends CircularDimensionBase
|
|
8
8
|
*/
|
|
9
|
-
export class DiametricDimension extends
|
|
9
|
+
export class DiametricDimension extends CircularDimensionBase {
|
|
10
10
|
/**
|
|
11
11
|
* Create a Diametric Dimension
|
|
12
12
|
* @param {Array} data
|
|
@@ -30,22 +30,22 @@ export class DiametricDimension extends BaseCircularDimension {
|
|
|
30
30
|
|
|
31
31
|
/**
|
|
32
32
|
* Get sequenced points from user selection
|
|
33
|
-
* @param {any}
|
|
33
|
+
* @param {any} entities
|
|
34
34
|
* @param {Point} textPos
|
|
35
35
|
* @return {Array} array of points
|
|
36
36
|
*/
|
|
37
|
-
static getPointsFromSelection(
|
|
38
|
-
const
|
|
39
|
-
const
|
|
37
|
+
static getPointsFromSelection(entities, textPos) {
|
|
38
|
+
const entity = entities[0];
|
|
39
|
+
const centre = entity.points[0];
|
|
40
40
|
|
|
41
41
|
const Pt11 = textPos;
|
|
42
42
|
Pt11.sequence = 11;
|
|
43
43
|
|
|
44
|
-
const angle = Pt11.angle(
|
|
45
|
-
const Pt10 =
|
|
44
|
+
const angle = Pt11.angle(centre);
|
|
45
|
+
const Pt10 = centre.project(angle, entity.getRadius());
|
|
46
46
|
Pt10.sequence = 10;
|
|
47
47
|
// Pt15 should be closest point to the text position
|
|
48
|
-
const Pt15 =
|
|
48
|
+
const Pt15 = centre.project(angle - Math.PI, entity.getRadius());
|
|
49
49
|
Pt15.sequence = 15;
|
|
50
50
|
|
|
51
51
|
const points = [Pt10, Pt15, Pt11];
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { DimensionBase } from './dimensionBase.js';
|
|
2
2
|
import { AlignedDimension } from './alignedDimension.js';
|
|
3
3
|
import { DiametricDimension } from './diametricDimension.js';
|
|
4
4
|
import { AngularDimension } from './angularDimension.js';
|
|
@@ -8,7 +8,7 @@ import { RotatedDimension } from './rotatedDimension.js';
|
|
|
8
8
|
import { Arc } from '../entities/arc.js';
|
|
9
9
|
import { Circle } from '../entities/circle.js';
|
|
10
10
|
import { Line } from '../entities/line.js';
|
|
11
|
-
import {
|
|
11
|
+
import { PolylineBase } from '../entities/polylineBase.js';
|
|
12
12
|
import { Point } from '../entities/point.js';
|
|
13
13
|
|
|
14
14
|
import { Strings } from '../lib/strings.js';
|
|
@@ -24,9 +24,9 @@ import { DimType } from '../properties/dimType.js';
|
|
|
24
24
|
|
|
25
25
|
/**
|
|
26
26
|
* Dimension Entity Class
|
|
27
|
-
* @extends
|
|
27
|
+
* @extends DimensionBase
|
|
28
28
|
*/
|
|
29
|
-
export class Dimension extends
|
|
29
|
+
export class Dimension extends DimensionBase {
|
|
30
30
|
/**
|
|
31
31
|
* Create a Dimension
|
|
32
32
|
* @param {Array} data
|
|
@@ -48,13 +48,13 @@ export class Dimension extends BaseDimension {
|
|
|
48
48
|
writable: true,
|
|
49
49
|
});
|
|
50
50
|
|
|
51
|
-
Object.defineProperty(this, '
|
|
51
|
+
Object.defineProperty(this, 'selectedEntities', {
|
|
52
52
|
value: [],
|
|
53
53
|
writable: true,
|
|
54
54
|
});
|
|
55
55
|
|
|
56
56
|
if (data) {
|
|
57
|
-
const
|
|
57
|
+
const entity = new this.dimensionMap[DimType.getBaseType(this.dimType.getBaseDimType())](data);
|
|
58
58
|
|
|
59
59
|
// find the block linked to this dimension
|
|
60
60
|
const linkedBlockIndex = DesignCore.Scene.entities.find('BLOCK', 'name', data[2]);
|
|
@@ -64,7 +64,7 @@ export class Dimension extends BaseDimension {
|
|
|
64
64
|
DesignCore.Scene.entities.remove(linkedBlockIndex[0]);
|
|
65
65
|
}
|
|
66
66
|
|
|
67
|
-
return
|
|
67
|
+
return entity;
|
|
68
68
|
}
|
|
69
69
|
}
|
|
70
70
|
|
|
@@ -104,51 +104,51 @@ export class Dimension extends BaseDimension {
|
|
|
104
104
|
if (pt14 === undefined) return;
|
|
105
105
|
// Create a temporary line using the selected points
|
|
106
106
|
const tempLine = new Line({ points: [input1, pt14] });
|
|
107
|
-
this.
|
|
107
|
+
this.selectedEntities.push(tempLine);
|
|
108
108
|
}
|
|
109
109
|
|
|
110
110
|
if (input1 instanceof SingleSelection) {
|
|
111
|
-
const
|
|
111
|
+
const selectedEntity = DesignCore.Scene.entities.get(input1.selectedEntityIndex);
|
|
112
112
|
|
|
113
113
|
// check the selected entity is supported
|
|
114
|
-
if ([Line, Circle, Arc,
|
|
114
|
+
if ([Line, Circle, Arc, PolylineBase].some((entity) => selectedEntity instanceof entity)) {
|
|
115
115
|
// set the dimension type
|
|
116
|
-
if (
|
|
116
|
+
if (selectedEntity instanceof Line) {
|
|
117
117
|
this.dimType.setDimType(1);
|
|
118
|
-
this.
|
|
118
|
+
this.selectedEntities.push(selectedEntity);
|
|
119
119
|
inputValid = true;
|
|
120
120
|
}
|
|
121
121
|
|
|
122
|
-
if (
|
|
122
|
+
if (selectedEntity instanceof Circle) {
|
|
123
123
|
this.dimType.setDimType(3);
|
|
124
|
-
this.
|
|
124
|
+
this.selectedEntities.push(selectedEntity);
|
|
125
125
|
inputValid = true;
|
|
126
126
|
}
|
|
127
127
|
|
|
128
|
-
if (
|
|
128
|
+
if (selectedEntity instanceof Arc) {
|
|
129
129
|
this.dimType.setDimType(4);
|
|
130
|
-
this.
|
|
130
|
+
this.selectedEntities.push(selectedEntity);
|
|
131
131
|
inputValid = true;
|
|
132
132
|
}
|
|
133
133
|
|
|
134
|
-
if (
|
|
134
|
+
if (selectedEntity instanceof PolylineBase) {
|
|
135
135
|
// get the segment closest to the mouse point
|
|
136
|
-
const segment =
|
|
136
|
+
const segment = selectedEntity.getClosestSegment(input1.selectedPoint);
|
|
137
137
|
|
|
138
138
|
if (segment instanceof Line) {
|
|
139
139
|
this.dimType.setDimType(1);
|
|
140
|
-
this.
|
|
140
|
+
this.selectedEntities.push(segment);
|
|
141
141
|
inputValid = true;
|
|
142
142
|
}
|
|
143
143
|
|
|
144
144
|
if (segment instanceof Arc) {
|
|
145
145
|
this.dimType.setDimType(4);
|
|
146
|
-
this.
|
|
146
|
+
this.selectedEntities.push(segment);
|
|
147
147
|
inputValid = true;
|
|
148
148
|
}
|
|
149
149
|
}
|
|
150
150
|
} else {
|
|
151
|
-
const msg = `${this.type} - ${Strings.Error.INVALIDTYPE}: ${
|
|
151
|
+
const msg = `${this.type} - ${Strings.Error.INVALIDTYPE}: ${selectedEntity.type}`;
|
|
152
152
|
DesignCore.Core.notify(msg);
|
|
153
153
|
DesignCore.Scene.selectionManager.reset();
|
|
154
154
|
}
|
|
@@ -162,12 +162,12 @@ export class Dimension extends BaseDimension {
|
|
|
162
162
|
let op2 = new PromptOptions(Strings.Input.DIMENSION, [Input.Type.POINT]);
|
|
163
163
|
|
|
164
164
|
// Angular dimension prompt: select a second line for an angular dimension or location for the text position
|
|
165
|
-
if ((this.
|
|
165
|
+
if ((this.selectedEntities[0] instanceof Line) && this.selectedEntities.length < 2) {
|
|
166
166
|
op2 = new PromptOptions(`${Strings.Input.DIMENSION} or ${Strings.Input.SELECT}`, [Input.Type.POINT, Input.Type.SINGLESELECTION]);
|
|
167
167
|
}
|
|
168
168
|
|
|
169
169
|
// diametric prompt: select radial or diametric type dimension or location for the the text position
|
|
170
|
-
if (this.
|
|
170
|
+
if (this.selectedEntities[0] instanceof Circle) {
|
|
171
171
|
const options = this.dimType.getBaseDimType() === 3 ? ['Radius'] : ['Diameter'];
|
|
172
172
|
op2 = new PromptOptions(`${Strings.Input.DIMENSION}`, [Input.Type.POINT], options);
|
|
173
173
|
}
|
|
@@ -178,19 +178,19 @@ export class Dimension extends BaseDimension {
|
|
|
178
178
|
if (Input.getType(input2) === Input.Type.POINT) {
|
|
179
179
|
const Pt11 = input2;
|
|
180
180
|
|
|
181
|
-
// if selected
|
|
182
|
-
// dimensions can be created from point selection only, therefore selected
|
|
183
|
-
if (this.
|
|
181
|
+
// if selected entities are available, get the points from the selected entities
|
|
182
|
+
// dimensions can be created from point selection only, therefore selected entities may not be available
|
|
183
|
+
if (this.selectedEntities.length) {
|
|
184
184
|
// for linear dimensions, determine if aligned or rotated based on mouse position
|
|
185
185
|
if (this.dimType.getBaseDimType() === 0 || this.dimType.getBaseDimType() === 1) {
|
|
186
|
-
const Pt13 = this.
|
|
187
|
-
const Pt14 = this.
|
|
186
|
+
const Pt13 = this.selectedEntities[0].points[0];
|
|
187
|
+
const Pt14 = this.selectedEntities[0].points[1];
|
|
188
188
|
const linearDimTypeNumber = this.getLinearDimensionType(Pt13, Pt14, Pt11);
|
|
189
189
|
this.dimType.setDimType(linearDimTypeNumber);
|
|
190
190
|
}
|
|
191
191
|
|
|
192
192
|
const dimensionType = this.dimensionMap[this.dimType.getBaseDimType()]; // TODO: use this.dimensionMap.name?
|
|
193
|
-
this.points.push(...dimensionType.getPointsFromSelection(this.
|
|
193
|
+
this.points.push(...dimensionType.getPointsFromSelection(this.selectedEntities, Pt11));
|
|
194
194
|
}
|
|
195
195
|
}
|
|
196
196
|
|
|
@@ -206,20 +206,20 @@ export class Dimension extends BaseDimension {
|
|
|
206
206
|
}
|
|
207
207
|
|
|
208
208
|
if (Input.getType(input2) === Input.Type.SINGLESELECTION) {
|
|
209
|
-
let
|
|
210
|
-
if ([Line,
|
|
209
|
+
let selectedEntity2 = DesignCore.Scene.entities.get(input2.selectedEntityIndex);
|
|
210
|
+
if ([Line, PolylineBase].some((entity) => selectedEntity2 instanceof entity)) {
|
|
211
211
|
// if a polyline is selected, get the segment closest to the mouse point
|
|
212
|
-
if (
|
|
212
|
+
if (selectedEntity2 instanceof PolylineBase) {
|
|
213
213
|
// get the segment closest to the mouse point
|
|
214
|
-
const segment =
|
|
214
|
+
const segment = selectedEntity2.getClosestSegment(input2.selectedPoint);
|
|
215
215
|
|
|
216
216
|
if (segment instanceof Line) {
|
|
217
|
-
|
|
217
|
+
selectedEntity2 = segment;
|
|
218
218
|
}
|
|
219
219
|
}
|
|
220
220
|
// Check lines intersect
|
|
221
|
-
const line1 = { start: this.
|
|
222
|
-
const line2 = { start:
|
|
221
|
+
const line1 = { start: this.selectedEntities[0].points[0], end: this.selectedEntities[0].points[1] };
|
|
222
|
+
const line2 = { start: selectedEntity2.points[0], end: selectedEntity2.points[1] };
|
|
223
223
|
|
|
224
224
|
// Check the lines are not parallel - Can't dimension parallel lines
|
|
225
225
|
const lineOneSlope = (line1.end.y - line1.start.y) / (line1.end.x - line1.start.x);
|
|
@@ -229,7 +229,7 @@ export class Dimension extends BaseDimension {
|
|
|
229
229
|
const intersect = Intersection.intersectSegmentSegment(line1.start, line1.end, line2.start, line2.end, false, true);
|
|
230
230
|
if (intersect.points.length >= 1) {
|
|
231
231
|
// add line to selection
|
|
232
|
-
this.
|
|
232
|
+
this.selectedEntities.push(selectedEntity2);
|
|
233
233
|
// Two lines selected - switch to angular dimension
|
|
234
234
|
this.dimType.setDimType(2);
|
|
235
235
|
}
|
|
@@ -239,7 +239,7 @@ export class Dimension extends BaseDimension {
|
|
|
239
239
|
DesignCore.Scene.selectionManager.removeLastSelection();
|
|
240
240
|
}
|
|
241
241
|
} else {
|
|
242
|
-
const msg = `${this.type} - ${Strings.Error.INVALIDTYPE}: ${
|
|
242
|
+
const msg = `${this.type} - ${Strings.Error.INVALIDTYPE}: ${selectedEntity2.type}`;
|
|
243
243
|
DesignCore.Core.notify(msg);
|
|
244
244
|
DesignCore.Scene.selectionManager.reset();
|
|
245
245
|
}
|
|
@@ -280,7 +280,7 @@ export class Dimension extends BaseDimension {
|
|
|
280
280
|
* Preview the entity during creation
|
|
281
281
|
*/
|
|
282
282
|
preview() {
|
|
283
|
-
if (this.
|
|
283
|
+
if (this.selectedEntities.length) {
|
|
284
284
|
let dimTypeNumber = this.dimType.getBaseDimType();
|
|
285
285
|
|
|
286
286
|
const Pt11 = DesignCore.Mouse.pointOnScene();
|
|
@@ -288,8 +288,8 @@ export class Dimension extends BaseDimension {
|
|
|
288
288
|
|
|
289
289
|
if (dimTypeNumber === 0 || dimTypeNumber === 1) {
|
|
290
290
|
// for linear dimensions, determine if aligned or rotated based on mouse position
|
|
291
|
-
const Pt13 = this.
|
|
292
|
-
const Pt14 = this.
|
|
291
|
+
const Pt13 = this.selectedEntities[0].points[0];
|
|
292
|
+
const Pt14 = this.selectedEntities[0].points[1];
|
|
293
293
|
dimTypeNumber = this.getLinearDimensionType(Pt13, Pt14, Pt11);
|
|
294
294
|
}
|
|
295
295
|
// get the dimension class
|
|
@@ -297,7 +297,7 @@ export class Dimension extends BaseDimension {
|
|
|
297
297
|
// get the dimension type as a string
|
|
298
298
|
const dimensionTypeString = dimensionType.register().command;
|
|
299
299
|
// get the points for the dimension
|
|
300
|
-
const points = dimensionType.getPointsFromSelection(this.
|
|
300
|
+
const points = dimensionType.getPointsFromSelection(this.selectedEntities, Pt11);
|
|
301
301
|
// create the temporary dimension
|
|
302
302
|
DesignCore.Scene.previewEntities.create(dimensionTypeString, { points: points, dimensionStyle: this.getProperty(Property.Names.DIMENSIONSTYLE) });
|
|
303
303
|
}
|