@design-core/core 0.0.1 → 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintrc.json +14 -7
- package/.github/workflows/DesignCoreQA.yml +3 -1
- package/README.md +11 -4
- package/TODO.md +19 -0
- package/core/core/core.js +49 -42
- package/core/designCore.js +61 -2
- package/core/dimensions/alignedDimension.js +142 -0
- package/core/dimensions/angularDimension.js +550 -0
- package/core/dimensions/baseCircularDimension.js +244 -0
- package/core/dimensions/baseDimension.js +558 -0
- package/core/dimensions/baseLinearDimension.js +371 -0
- package/core/dimensions/diametricDimension.js +82 -0
- package/core/dimensions/dimension.js +298 -0
- package/core/dimensions/linearDimension.js +29 -0
- package/core/dimensions/radialDimension.js +78 -0
- package/core/dimensions/rotatedDimension.js +167 -0
- package/core/entities/arc.js +314 -60
- package/core/entities/arctext.js +642 -0
- package/core/entities/basePolyline.js +553 -94
- package/core/entities/circle.js +181 -54
- package/core/entities/entity.js +154 -74
- package/core/entities/hatch.js +807 -0
- package/core/entities/insert.js +200 -39
- package/core/entities/line.js +196 -134
- package/core/entities/lwpolyline.js +21 -44
- package/core/entities/point.js +194 -29
- package/core/entities/polyline.js +54 -7
- package/core/entities/rectangle.js +43 -13
- package/core/entities/solid.js +43 -6
- package/core/entities/text.js +324 -181
- package/core/lib/boundingBox.js +73 -13
- package/core/lib/canvas.js +256 -65
- package/core/lib/clipboard.js +198 -0
- package/core/lib/colour.js +144 -0
- package/core/lib/colours.js +367 -301
- package/core/lib/commandLine.js +16 -28
- package/core/lib/commandManager.js +115 -58
- package/core/lib/constants.js +23 -0
- package/core/lib/dxf/dxf.js +249 -34
- package/core/lib/dxf/dxfFile.js +23 -38
- package/core/lib/dxf/dxfIterator.js +17 -5
- package/core/lib/dxf/dxfRead.js +23 -7
- package/core/lib/dxf/dxfWrite.js +39 -129
- package/core/lib/dxf/handleManager.js +97 -0
- package/core/lib/dxf/sections/blocks.js +16 -2
- package/core/lib/dxf/sections/entities.js +17 -3
- package/core/lib/dxf/sections/header.js +10 -1
- package/core/lib/dxf/sections/objects.js +36 -0
- package/core/lib/dxf/sections/section.js +43 -5
- package/core/lib/dxf/sections/tables.js +17 -3
- package/core/lib/entityManager.js +178 -0
- package/core/lib/fileio.js +14 -4
- package/core/lib/headers.js +229 -0
- package/core/lib/input.js +46 -0
- package/core/lib/inputManager.js +199 -194
- package/core/lib/intersect.js +341 -468
- package/core/lib/logging.js +25 -1
- package/core/lib/matrix.js +6 -8
- package/core/lib/mouse.js +24 -79
- package/core/lib/patterns.js +690 -0
- package/core/lib/promptOptions.js +133 -0
- package/core/lib/scene.js +71 -174
- package/core/lib/selectionManager.js +74 -48
- package/core/lib/selectionWindow.js +24 -10
- package/core/lib/settings.js +18 -11
- package/core/lib/snapping.js +129 -21
- package/core/lib/stateManager.js +288 -0
- package/core/lib/strings.js +57 -5
- package/core/lib/utils.js +95 -11
- package/core/objects/dictionary.js +43 -0
- package/core/objects/dictionaryManager.js +80 -0
- package/core/properties/dimType.js +117 -0
- package/core/properties/flags.js +66 -0
- package/core/properties/property.js +26 -0
- package/core/properties/propertyManager.js +65 -19
- package/core/tables/appId.js +31 -0
- package/core/tables/appIdManager.js +44 -0
- package/core/tables/block.js +323 -0
- package/core/tables/blockManager.js +48 -0
- package/core/tables/blockRecord.js +29 -0
- package/core/tables/blockRecordManager.js +37 -0
- package/core/tables/dimStyle.js +627 -0
- package/core/tables/dimStyleManager.js +187 -0
- package/core/tables/endblk.js +28 -0
- package/core/tables/layer.js +219 -0
- package/core/tables/layerManager.js +47 -0
- package/core/tables/ltype.js +85 -0
- package/core/tables/ltypeManager.js +65 -0
- package/core/tables/style.js +145 -0
- package/core/tables/styleManager.js +55 -0
- package/core/tables/styleManagerBase.js +110 -0
- package/core/tables/tableManagerBase.js +354 -0
- package/core/tables/ucs.js +28 -0
- package/core/tables/ucsManager.js +44 -0
- package/core/tables/view.js +28 -0
- package/core/tables/viewManager.js +44 -0
- package/core/tables/vport.js +70 -0
- package/core/tables/vportManager.js +65 -0
- package/core/tools/chamfer.js +343 -0
- package/core/tools/chamferFilletBase.js +162 -0
- package/core/tools/copy.js +68 -40
- package/core/tools/copybase.js +65 -0
- package/core/tools/copyclip.js +59 -0
- package/core/tools/cornerEntity.js +138 -0
- package/core/tools/cutclip.js +72 -0
- package/core/tools/distance.js +37 -9
- package/core/tools/erase.js +43 -13
- package/core/tools/explode.js +117 -0
- package/core/tools/extend.js +71 -32
- package/core/tools/fillet.js +336 -0
- package/core/tools/identify.js +33 -6
- package/core/tools/matchProp.js +106 -0
- package/core/tools/mirror.js +141 -0
- package/core/tools/move.js +65 -32
- package/core/tools/offset.js +321 -0
- package/core/tools/pan.js +54 -0
- package/core/tools/pasteclip.js +93 -0
- package/core/tools/purge.js +90 -0
- package/core/tools/rotate.js +105 -70
- package/core/tools/scale.js +166 -0
- package/core/tools/tool.js +14 -4
- package/core/tools/trim.js +71 -32
- package/core/tools/zoom.js +152 -0
- package/package.json +3 -305
- package/test/dimensions/alignedDimension.test.js +211 -0
- package/test/dimensions/angularDimension.test.js +243 -0
- package/test/dimensions/baseDimension.test.js +239 -0
- package/test/dimensions/diametricDimension.test.js +203 -0
- package/test/dimensions/dimension.test.js +102 -0
- package/test/dimensions/radialDimension.test.js +203 -0
- package/test/dimensions/rotatedDimension.test.js +224 -0
- package/test/entities/arc.test.js +463 -41
- package/test/entities/arctext.test.js +329 -0
- package/test/entities/basePolyline.test.js +459 -10
- package/test/entities/circle.test.js +312 -7
- package/test/entities/entity.test.js +28 -9
- package/test/entities/hatch.test.js +606 -0
- package/test/entities/insert.test.js +90 -0
- package/test/entities/line.test.js +182 -6
- package/test/entities/point.test.js +375 -37
- package/test/entities/solid.test.js +156 -0
- package/test/entities/text.test.js +533 -7
- package/test/integration/exportIntegration.reference.dxf +1706 -0
- package/test/integration/exportIntegration.test.js +186 -0
- package/test/integration/importExportIntegration.test.js +126 -0
- package/test/integration/intersectionIntegration.test.js +880 -0
- package/test/integration/userInputIntegration.reference.dxf +1410 -0
- package/test/integration/userInputIntegration.test.js +269 -0
- package/test/lib/boundingBox.test.js +26 -2
- package/test/lib/canvas.test.js +613 -5
- package/test/lib/clipboard.test.js +70 -0
- package/test/lib/colour.test.js +114 -0
- package/test/lib/colours.test.js +63 -18
- package/test/lib/commandLine.test.js +159 -22
- package/test/lib/commandManager.test.js +4 -4
- package/test/lib/constants.test.js +9 -0
- package/test/lib/dxf/dxfFile.test.js +6 -2
- package/test/lib/dxf/dxfIterator.test.js +1 -1
- package/test/lib/dxf/dxfWrite.test.js +173 -0
- package/test/lib/dxf/handleManager.test.js +137 -0
- package/test/lib/dxf/sections/blocks.test.js +5 -5
- package/test/lib/dxf/sections/entities.test.js +4 -4
- package/test/lib/dxf/sections/header.test.js +18 -4
- package/test/lib/dxf/sections/objects.test.js +132 -0
- package/test/lib/dxf/sections/section.test.js +29 -29
- package/test/lib/dxf/sections/tables.test.js +3 -3
- package/test/lib/entityManager.test.js +163 -0
- package/test/lib/headers.test.js +233 -0
- package/test/lib/inputManager.test.js +1144 -5
- package/test/lib/intersect.test.js +454 -331
- package/test/lib/logging.test.js +1 -1
- package/test/lib/matrix.test.js +1 -1
- package/test/lib/mouse.test.js +327 -4
- package/test/lib/patterns.test.js +105 -0
- package/test/lib/promptOptions.test.js +179 -0
- package/test/lib/scene.test.js +16 -52
- package/test/lib/selectionManager.test.js +17 -5
- package/test/lib/settings.test.js +111 -5
- package/test/lib/snapping.test.js +142 -4
- package/test/lib/stateManager.test.js +155 -0
- package/test/lib/utils.test.js +81 -1
- package/test/objects/dictionary.test.js +81 -0
- package/test/objects/dictionaryManager.test.js +34 -0
- package/test/properties/dimType.test.js +62 -0
- package/test/properties/flags.test.js +164 -0
- package/test/properties/property.test.js +13 -0
- package/test/properties/propertyManager.test.js +10 -11
- package/test/tables/appId.test.js +46 -0
- package/test/tables/appIdManager.test.js +72 -0
- package/test/tables/block.test.js +157 -0
- package/test/tables/blockManager.test.js +52 -0
- package/test/tables/blockRecord.test.js +39 -0
- package/test/tables/blockRecordManager.test.js +60 -0
- package/test/tables/dimstyle.test.js +72 -0
- package/test/tables/endblk.test.js +30 -0
- package/test/tables/layer.test.js +95 -0
- package/test/tables/layerManager.test.js +172 -0
- package/test/{styles → tables}/ltype.test.js +7 -7
- package/test/{styles → tables}/ltypeManager.test.js +2 -2
- package/test/tables/style.test.js +44 -0
- package/test/tables/stylemanagerbase.test.js +220 -0
- package/test/tables/tableManagerBase.test.js +194 -0
- package/test/tables/ucs.test.js +37 -0
- package/test/tables/ucsManager.test.js +48 -0
- package/test/tables/view.test.js +37 -0
- package/test/tables/viewManager.test.js +48 -0
- package/test/tables/vport.test.js +117 -0
- package/test/tables/vportManager.test.js +54 -0
- package/test/test-helpers/test-helpers.js +66 -0
- package/test/tools/chamfer.test.js +970 -0
- package/test/tools/chamferFilletBase.test.js +446 -0
- package/test/tools/copy.test.js +22 -14
- package/test/tools/copybase.test.js +93 -0
- package/test/tools/copyclip.test.js +92 -0
- package/test/tools/cornerEntity.test.js +201 -0
- package/test/tools/cutclip.test.js +94 -0
- package/test/tools/distance.test.js +140 -18
- package/test/tools/erase.test.js +12 -12
- package/test/tools/explode.test.js +45 -0
- package/test/tools/extend.test.js +326 -44
- package/test/tools/fillet.test.js +831 -0
- package/test/tools/identify.test.js +115 -16
- package/test/tools/matchProp.test.js +84 -0
- package/test/tools/mirror.test.js +475 -0
- package/test/tools/move.test.js +75 -19
- package/test/tools/offset.test.js +748 -0
- package/test/tools/pan.test.js +72 -0
- package/test/tools/pasteclip.test.js +100 -0
- package/test/tools/purge.test.js +89 -0
- package/test/tools/rotate.test.js +89 -23
- package/test/tools/scale.test.js +529 -0
- package/test/tools/trim.test.js +419 -84
- package/test/tools/zoom.test.js +504 -0
- package/core/entities/alignedDimension.js +0 -279
- package/core/entities/angularDimension.js +0 -194
- package/core/entities/baseDimension.js +0 -227
- package/core/entities/block.js +0 -247
- package/core/entities/diametricDimension.js +0 -133
- package/core/entities/dimension.js +0 -202
- package/core/entities/radialDimension.js +0 -126
- package/core/styles/dimStyle.js +0 -719
- package/core/styles/dimStyleManager.js +0 -47
- package/core/styles/layer.js +0 -133
- package/core/styles/layerManager.js +0 -40
- package/core/styles/ltype.js +0 -86
- package/core/styles/ltypeManager.js +0 -50
- package/core/styles/style.js +0 -158
- package/core/styles/styleManager.js +0 -43
- package/core/styles/styleManagerBase.js +0 -299
- package/test/entities/block.test.js +0 -22
- package/test/styles/dimstyle.test.js +0 -19
- package/test/styles/layerManager.test.js +0 -150
- package/test/styles/style.test.js +0 -33
- package/test/styles/stylemanagerbase.test.js +0 -219
package/core/entities/insert.js
CHANGED
|
@@ -1,65 +1,105 @@
|
|
|
1
|
-
import {Entity} from './entity.js';
|
|
2
|
-
import {
|
|
1
|
+
import { Entity } from './entity.js';
|
|
2
|
+
import { Strings } from '../lib/strings.js';
|
|
3
|
+
import { DXFFile } from '../lib/dxf/dxfFile.js';
|
|
4
|
+
import { Block } from '../tables/block.js';
|
|
5
|
+
import { BoundingBox } from '../lib/boundingBox.js';
|
|
6
|
+
import { Point } from './point.js';
|
|
7
|
+
import { Utils } from '../lib/utils.js';
|
|
8
|
+
import { Property } from '../properties/property.js';
|
|
9
|
+
import { Logging } from '../lib/logging.js';
|
|
3
10
|
|
|
11
|
+
import { DesignCore } from '../designCore.js';
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Insert Entity Class
|
|
16
|
+
* @extends Entity
|
|
17
|
+
*/
|
|
4
18
|
export class Insert extends Entity {
|
|
19
|
+
/**
|
|
20
|
+
* Create an Insert
|
|
21
|
+
* Inserts are used to define the location of blocks
|
|
22
|
+
* @param {Array} data
|
|
23
|
+
*/
|
|
5
24
|
constructor(data) {
|
|
6
25
|
super(data);
|
|
7
26
|
|
|
27
|
+
|
|
8
28
|
// add block property
|
|
9
29
|
Object.defineProperty(this, 'block', {
|
|
10
|
-
value:
|
|
30
|
+
value: new Block(),
|
|
11
31
|
writable: true,
|
|
12
32
|
});
|
|
13
33
|
|
|
34
|
+
// add rotation property with getter and setter
|
|
35
|
+
// needs to be enumerable to appear in the object props
|
|
36
|
+
Object.defineProperty(this, 'rotation', {
|
|
37
|
+
get: this.getRotation,
|
|
38
|
+
set: this.setRotation,
|
|
39
|
+
enumerable: true,
|
|
40
|
+
});
|
|
41
|
+
|
|
14
42
|
if (data) {
|
|
15
|
-
if (data.
|
|
43
|
+
if (data.hasOwnProperty('blockName') || data.hasOwnProperty('2')) {
|
|
16
44
|
// DXF Groupcode 2 - Block name
|
|
17
|
-
|
|
45
|
+
|
|
46
|
+
const blockName = data.blockName || data[2];
|
|
47
|
+
const block = DesignCore.Scene.blockManager.getItemByName(blockName);
|
|
48
|
+
this.block = block;
|
|
18
49
|
}
|
|
19
50
|
|
|
20
|
-
if (data
|
|
51
|
+
if (data.hasOwnProperty('41')) {
|
|
21
52
|
// DXF Groupcode 41 - X Scale Factor (optional, default = 1)
|
|
22
53
|
const err = 'Groupcode 41 not implemented';
|
|
23
54
|
Logging.instance.warn(`${this.type} - ${err}`);
|
|
24
55
|
}
|
|
25
56
|
|
|
26
|
-
if (data
|
|
57
|
+
if (data.hasOwnProperty('42')) {
|
|
27
58
|
// DXF Groupcode 42 - Y Scale Factor (optional, default = 1)
|
|
28
59
|
const err = 'Groupcode 42 not implemented';
|
|
29
60
|
Logging.instance.warn(`${this.type} - ${err}`);
|
|
30
61
|
}
|
|
31
62
|
|
|
32
|
-
if (data
|
|
63
|
+
if (data.hasOwnProperty('43')) {
|
|
33
64
|
// DXF Groupcode 43 - Z Scale Factor (optional, default = 1)
|
|
34
65
|
const err = 'Groupcode 43 not implemented';
|
|
35
66
|
Logging.instance.warn(`${this.type} - ${err}`);
|
|
36
67
|
}
|
|
37
68
|
|
|
38
|
-
if (data
|
|
69
|
+
if (data.hasOwnProperty('44')) {
|
|
39
70
|
// DXF Groupcode 44 - Column Spacing (optional, default = 0)
|
|
40
71
|
const err = 'Groupcode 44 not implemented';
|
|
41
72
|
Logging.instance.warn(`${this.type} - ${err}`);
|
|
42
73
|
}
|
|
43
74
|
|
|
44
|
-
if (data
|
|
75
|
+
if (data.hasOwnProperty('45')) {
|
|
45
76
|
// DXF Groupcode 45 - Row Spacing (optional, default = 0)
|
|
46
77
|
const err = 'Groupcode 45 not implemented';
|
|
47
78
|
Logging.instance.warn(`${this.type} - ${err}`);
|
|
48
79
|
}
|
|
49
80
|
|
|
50
|
-
if (data
|
|
51
|
-
// DXF Groupcode 50 - Rotation
|
|
52
|
-
|
|
53
|
-
|
|
81
|
+
if (data.hasOwnProperty('rotation') || data.hasOwnProperty('50')) {
|
|
82
|
+
// DXF Groupcode 50 - Text Rotation, angle in degrees
|
|
83
|
+
// if we get rotation data store this as a point[1] at an angle from point[0]
|
|
84
|
+
// this allows all the entities to be rotated by rotating the points i.e. not all entities have a rotation property
|
|
85
|
+
|
|
86
|
+
this.setRotation(Property.loadValue([data.rotation, data[50]], 0));
|
|
87
|
+
} else {
|
|
88
|
+
// create points[1] used to determine the rotation
|
|
89
|
+
if (this.points[0] === undefined) {
|
|
90
|
+
this.points.push(new Point());
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
this.points[1] = this.points[0].add(new Point(10, 0));
|
|
54
94
|
}
|
|
55
95
|
|
|
56
|
-
if (data
|
|
96
|
+
if (data.hasOwnProperty('70')) {
|
|
57
97
|
// DXF Groupcode 70 - Column Count (optional, default = 1)
|
|
58
98
|
const err = 'Groupcode 70 not implemented';
|
|
59
99
|
Logging.instance.warn(`${this.type} - ${err}`);
|
|
60
100
|
}
|
|
61
101
|
|
|
62
|
-
if (data
|
|
102
|
+
if (data.hasOwnProperty('71')) {
|
|
63
103
|
// DXF Groupcode 71 - Row Count(optional, default = 1)
|
|
64
104
|
const err = 'Groupcode 71 not implemented';
|
|
65
105
|
Logging.instance.warn(`${this.type} - ${err}`);
|
|
@@ -67,55 +107,176 @@ export class Insert extends Entity {
|
|
|
67
107
|
}
|
|
68
108
|
}
|
|
69
109
|
|
|
110
|
+
/**
|
|
111
|
+
* Register the command
|
|
112
|
+
* @return {Object}
|
|
113
|
+
* command = name of the command
|
|
114
|
+
* shortcut = shortcut for the command
|
|
115
|
+
* type = type to group command in toolbars (omitted if not shown)
|
|
116
|
+
*/
|
|
70
117
|
static register() {
|
|
71
|
-
const command = {command: 'Insert'};
|
|
118
|
+
const command = { command: 'Insert' };
|
|
72
119
|
return command;
|
|
73
120
|
}
|
|
74
121
|
|
|
122
|
+
/**
|
|
123
|
+
* Execute method
|
|
124
|
+
* executes the workflow, requesting input required to create an entity
|
|
125
|
+
*/
|
|
126
|
+
async execute() {
|
|
127
|
+
DesignCore.Core.notify(`${this.type} - ${Strings.Message.NOTIMPLEMENTED}`);
|
|
128
|
+
DesignCore.Scene.inputManager.reset();
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* Preview the entity during creation
|
|
133
|
+
*/
|
|
134
|
+
preview() {
|
|
135
|
+
// not implemented
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* Write the entity to file in the dxf format
|
|
140
|
+
* @param {DXFFile} file
|
|
141
|
+
*/
|
|
75
142
|
dxf(file) {
|
|
76
143
|
file.writeGroupCode('0', 'INSERT');
|
|
77
|
-
|
|
144
|
+
file.writeGroupCode('5', this.handle, DXFFile.Version.R2000); // Handle
|
|
145
|
+
file.writeGroupCode('100', 'AcDbEntity', DXFFile.Version.R2000);
|
|
78
146
|
file.writeGroupCode('8', this.layer);
|
|
79
|
-
|
|
147
|
+
this.writeDxfColour(file);
|
|
148
|
+
file.writeGroupCode('100', 'AcDbBlockReference', DXFFile.Version.R2000);
|
|
149
|
+
file.writeGroupCode('2', this.block.name);
|
|
80
150
|
file.writeGroupCode('10', this.points[0].x);
|
|
81
151
|
file.writeGroupCode('20', this.points[0].y);
|
|
82
152
|
file.writeGroupCode('30', '0.0');
|
|
153
|
+
if (this.rotation) {
|
|
154
|
+
file.writeGroupCode('50', this.rotation);
|
|
155
|
+
}
|
|
83
156
|
}
|
|
84
157
|
|
|
158
|
+
/**
|
|
159
|
+
* Draw the entity
|
|
160
|
+
* @param {Object} ctx - context
|
|
161
|
+
* @param {number} scale
|
|
162
|
+
*/
|
|
85
163
|
draw(ctx, scale) {
|
|
86
|
-
|
|
164
|
+
// blocks are associated with an insert point.
|
|
165
|
+
// translate ctx by the insert location
|
|
166
|
+
// this allows the block items to be draw without knowing the insert location
|
|
167
|
+
|
|
168
|
+
ctx.save();
|
|
169
|
+
ctx.translate(this.points[0].x, this.points[0].y);
|
|
170
|
+
const rotation = Utils.degrees2radians(this.rotation);
|
|
171
|
+
ctx.rotate(rotation);
|
|
172
|
+
// pass *this* to the block to allow colour ByBlock
|
|
173
|
+
this.block.draw(ctx, scale, this);
|
|
174
|
+
ctx.restore();
|
|
87
175
|
}
|
|
88
176
|
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
177
|
+
/**
|
|
178
|
+
* Set the insert rotation
|
|
179
|
+
* @param {number} angle - degrees
|
|
180
|
+
*/
|
|
181
|
+
setRotation(angle) {
|
|
182
|
+
// This overwrites the rotation rather than add to it.
|
|
183
|
+
|
|
184
|
+
if (angle === undefined) {
|
|
185
|
+
return;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
this.points[1] = this.points[0].project(Utils.degrees2radians(angle), 10);
|
|
92
189
|
}
|
|
93
190
|
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
191
|
+
/**
|
|
192
|
+
* Get the insert rotation
|
|
193
|
+
* @return {number} angle - degrees
|
|
194
|
+
*/
|
|
195
|
+
getRotation() {
|
|
196
|
+
if (this.points[1] !== undefined) {
|
|
197
|
+
const angle = Utils.radians2degrees(this.points[0].angle(this.points[1]));
|
|
198
|
+
return Utils.round(angle);
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
return 0;
|
|
97
202
|
}
|
|
98
203
|
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
204
|
+
/**
|
|
205
|
+
* Get snap points
|
|
206
|
+
* @param {Point} mousePoint
|
|
207
|
+
* @param {number} delta
|
|
208
|
+
* @return {Array} - array of snap points
|
|
209
|
+
*/
|
|
210
|
+
snaps(mousePoint, delta) {
|
|
211
|
+
const snaps = [];
|
|
212
|
+
const blockSnaps = this.block.snaps(mousePoint, delta);
|
|
213
|
+
|
|
214
|
+
for (let snap = 0; snap < blockSnaps.length; snap++) {
|
|
215
|
+
const snapPoint = blockSnaps[snap];
|
|
216
|
+
// offset the item snap point by the block insert location
|
|
217
|
+
const rotatedPoint = snapPoint.add(this.points[0]);
|
|
218
|
+
// rotate the snap point to match the item positions
|
|
219
|
+
const adjustedPoint = rotatedPoint.rotate(this.points[0], Utils.degrees2radians(this.rotation));
|
|
220
|
+
snaps.push(adjustedPoint);
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
return snaps;
|
|
104
224
|
}
|
|
105
225
|
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
226
|
+
/**
|
|
227
|
+
* Determine if the entity is within the selection
|
|
228
|
+
* @param {Object} selection - {min: Point, max: Point}
|
|
229
|
+
* @return {boolean} true if within
|
|
230
|
+
*/
|
|
231
|
+
within(selection) {
|
|
232
|
+
const pt = this.points[0];
|
|
233
|
+
return this.block.within({
|
|
234
|
+
min: selection.min.subtract(pt),
|
|
235
|
+
max: selection.max.subtract(pt),
|
|
236
|
+
});
|
|
237
|
+
}
|
|
109
238
|
|
|
110
|
-
|
|
239
|
+
/**
|
|
240
|
+
* Get closest point on entity
|
|
241
|
+
* @param {Point} P
|
|
242
|
+
* @return {Array} - [Point, distance]
|
|
243
|
+
*/
|
|
244
|
+
closestPoint(P) {
|
|
245
|
+
// get the closest point from the blocks entities
|
|
246
|
+
// rotate P to match the block rotation
|
|
247
|
+
const rotatedPoint = P.rotate(this.points[0], Utils.degrees2radians(-this.rotation));
|
|
248
|
+
// adjust P by the insert position
|
|
249
|
+
const adjustedPoint = rotatedPoint.subtract(this.points[0]);
|
|
250
|
+
return this.block.closestPoint(adjustedPoint);
|
|
111
251
|
}
|
|
112
252
|
|
|
253
|
+
/**
|
|
254
|
+
* Return boundingbox for entity
|
|
255
|
+
* @return {BoundingBox}
|
|
256
|
+
*/
|
|
113
257
|
boundingBox() {
|
|
114
|
-
|
|
258
|
+
const blockBB = this.block.boundingBox();
|
|
259
|
+
const topLeft = blockBB.pt1.add(this.points[0]);
|
|
260
|
+
const bottomRight = blockBB.pt2.add(this.points[0]);
|
|
261
|
+
return new BoundingBox(topLeft, bottomRight);
|
|
115
262
|
}
|
|
116
263
|
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
264
|
+
/**
|
|
265
|
+
* Determine if the entity is touch the selection window
|
|
266
|
+
* @param {Object} selection - {min: Point, max: Point}
|
|
267
|
+
* @return {boolean} true if touched
|
|
268
|
+
*/
|
|
269
|
+
touched(selection) {
|
|
270
|
+
const layer = DesignCore.LayerManager.getItemByName(this.layer);
|
|
271
|
+
|
|
272
|
+
if (!layer?.isSelectable) {
|
|
273
|
+
return;
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
const pt = this.points[0];
|
|
277
|
+
return this.block.touched({
|
|
278
|
+
min: selection.min.subtract(pt),
|
|
279
|
+
max: selection.max.subtract(pt),
|
|
280
|
+
});
|
|
120
281
|
}
|
|
121
282
|
}
|