@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/block.js
DELETED
|
@@ -1,247 +0,0 @@
|
|
|
1
|
-
import {Point} from './point.js';
|
|
2
|
-
import {Entity} from './entity.js';
|
|
3
|
-
import {DXFFile} from '../lib/dxf/dxfFile.js';
|
|
4
|
-
import {BoundingBox} from '../lib/boundingBox.js';
|
|
5
|
-
|
|
6
|
-
import {DesignCore} from '../designCore.js';
|
|
7
|
-
|
|
8
|
-
export class Block extends Entity {
|
|
9
|
-
constructor(data) {
|
|
10
|
-
super(data);
|
|
11
|
-
this.name = '';
|
|
12
|
-
|
|
13
|
-
Object.defineProperty(this, 'location', {
|
|
14
|
-
value: new Point(),
|
|
15
|
-
writable: true,
|
|
16
|
-
});
|
|
17
|
-
|
|
18
|
-
Object.defineProperty(this, 'flags', {
|
|
19
|
-
value: 1,
|
|
20
|
-
writable: true,
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
Object.defineProperty(this, 'items', {
|
|
24
|
-
value: [],
|
|
25
|
-
writable: true,
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
if (data) {
|
|
29
|
-
if (data.name || data[2]) {
|
|
30
|
-
// DXF Groupcode 2 - Block Name
|
|
31
|
-
this.name = data.name || data[2];
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
if (data.points) {
|
|
35
|
-
this.location = data.points[0];
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
if (data.items) {
|
|
39
|
-
this.items = data.items;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
if (data.flags || data[70]) {
|
|
43
|
-
// DXF Groupcode 70 - Block-type flags (bit-coded):
|
|
44
|
-
// 0 = Indicates none of the following flags apply
|
|
45
|
-
// 1 = This is an anonymous block generated by hatching, associative dimensioning, other internal operations, or an application
|
|
46
|
-
// 2 = This block has non-constant attribute definitions (this bit is not set if the block has any attribute definitions that are constant, or has no attribute definitions at all)
|
|
47
|
-
// 4 = This block is an external reference (xref)
|
|
48
|
-
// 8 = This block is an xref overlay
|
|
49
|
-
// 16 = This block is externally dependent
|
|
50
|
-
// 32 = This is a resolved external reference, or dependent of an external reference (ignored on input)
|
|
51
|
-
// 64 = This definition is a referenced external reference (ignored on input)
|
|
52
|
-
|
|
53
|
-
this.flags = data.flags || data[70];
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
static register() {
|
|
59
|
-
const command = {command: 'Block'};
|
|
60
|
-
return command;
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
setStandardFlags() {
|
|
64
|
-
// Set standard flags (bit-coded values)
|
|
65
|
-
this.flags = 1;
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
dxf(file) {
|
|
69
|
-
file.writeGroupCode('0', 'BLOCK');
|
|
70
|
-
file.writeGroupCode('5', file.nextHandle(), DXFFile.Version.R2000); // Handle
|
|
71
|
-
file.writeGroupCode('100', 'AcDbEntity', DXFFile.Version.R2000);
|
|
72
|
-
file.writeGroupCode('100', 'AcDbBlockBegin', DXFFile.Version.R2000);
|
|
73
|
-
file.writeGroupCode('8', this.layer);
|
|
74
|
-
file.writeGroupCode('2', this.name);
|
|
75
|
-
file.writeGroupCode('10', this.points[0].x);
|
|
76
|
-
file.writeGroupCode('20', this.points[0].y);
|
|
77
|
-
file.writeGroupCode('30', 0.0);
|
|
78
|
-
file.writeGroupCode('70', this.flags);
|
|
79
|
-
file.writeGroupCode('3', this.name); // Name again
|
|
80
|
-
file.writeGroupCode('1', '');
|
|
81
|
-
file.writeGroupCode('0', 'ENDBLK');
|
|
82
|
-
file.writeGroupCode('5', file.nextHandle(), DXFFile.Version.R2000); // Handle
|
|
83
|
-
file.writeGroupCode('100', 'AcDbEntity', DXFFile.Version.R2000);
|
|
84
|
-
file.writeGroupCode('100', 'AcDbBlockEnd', DXFFile.Version.R2000);
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
clearItems() {
|
|
88
|
-
this.items = [];
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
addItem(item) {
|
|
92
|
-
this.items.push(item);
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
addInsert(data) {
|
|
96
|
-
const point = new Point(data.points[0].x, data.points[0].y);
|
|
97
|
-
this.points[0] = point;
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
draw(ctx, scale) {
|
|
101
|
-
if (!this.items.length) {
|
|
102
|
-
// nothing to draw
|
|
103
|
-
return;
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
ctx.save();
|
|
107
|
-
|
|
108
|
-
// blocks are associated with an insert point.
|
|
109
|
-
// translate ctx by the insert location
|
|
110
|
-
// this allows the items to be draw without knowing the insert location of the parent block
|
|
111
|
-
ctx.translate(this.points[0].x, this.points[0].y);
|
|
112
|
-
|
|
113
|
-
for (let item = 0; item < this.items.length; item++) {
|
|
114
|
-
if (typeof this.items[item].draw == 'function') {
|
|
115
|
-
// handle item colour
|
|
116
|
-
const itemColour = this.items[item].colour;
|
|
117
|
-
if (itemColour === 'BYBLOCK') {
|
|
118
|
-
this.items[item].colour = colour;
|
|
119
|
-
}
|
|
120
|
-
this.items[item].draw(ctx, scale);
|
|
121
|
-
// reset item colour
|
|
122
|
-
this.items[item].colour = itemColour;
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
ctx.restore();
|
|
127
|
-
|
|
128
|
-
/*
|
|
129
|
-
//////////////////////////////////////////
|
|
130
|
-
// draw test point for location
|
|
131
|
-
ctx.strokeStyle = colour;
|
|
132
|
-
ctx.lineWidth = 1 / scale;
|
|
133
|
-
ctx.beginPath()
|
|
134
|
-
ctx.moveTo(this.points[0].x, this.points[0].y);
|
|
135
|
-
ctx.arc(this.points[0].x, this.points[0].y, 5 / scale, radians2degrees(0), radians2degrees(360), false);
|
|
136
|
-
ctx.stroke();
|
|
137
|
-
//////////////////////////////////////////
|
|
138
|
-
*/
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
snaps(mousePoint, delta) {
|
|
142
|
-
let snaps = [];
|
|
143
|
-
|
|
144
|
-
if (!this.items.length) {
|
|
145
|
-
// nothing to draw
|
|
146
|
-
return snaps;
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
snaps = [this.points[0]];
|
|
150
|
-
|
|
151
|
-
for (let item = 0; item < this.items.length; item++) {
|
|
152
|
-
// collect the child item snaps
|
|
153
|
-
const itemSnaps = this.items[item].snaps(mousePoint, delta);
|
|
154
|
-
|
|
155
|
-
for (let snap = 0; snap < itemSnaps.length; snap++) {
|
|
156
|
-
// offset the item snap point by the block insert location
|
|
157
|
-
let snapPoint = itemSnaps[snap];
|
|
158
|
-
snapPoint = snapPoint.add(this.points[0]);
|
|
159
|
-
snaps.push(snapPoint);
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
return snaps;
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
intersectPoints() {
|
|
167
|
-
return {
|
|
168
|
-
start: this.points[0],
|
|
169
|
-
end: this.points[0],
|
|
170
|
-
};
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
closestPoint(P) {
|
|
174
|
-
let distance = Infinity;
|
|
175
|
-
let minPnt = P;
|
|
176
|
-
|
|
177
|
-
if (!this.items.length) {
|
|
178
|
-
// nothing to draw
|
|
179
|
-
return [minPnt, distance];
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
// adjust the selection point to offset by the block insert position
|
|
183
|
-
const adjustedPoint = P.subtract(this.points[0]);
|
|
184
|
-
|
|
185
|
-
for (let idx = 0; idx < this.items.length; idx++) {
|
|
186
|
-
const itemClosestPoint = this.items[idx].closestPoint(adjustedPoint);
|
|
187
|
-
const itemPnt = itemClosestPoint[0].add(this.points[0]); // adjust by the block insert position
|
|
188
|
-
const itemDist = itemClosestPoint[1];
|
|
189
|
-
|
|
190
|
-
if (itemDist < distance) {
|
|
191
|
-
distance = itemDist;
|
|
192
|
-
minPnt = itemPnt;
|
|
193
|
-
}
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
return [minPnt, distance];
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
boundingBox() {
|
|
200
|
-
let xmin;
|
|
201
|
-
let xmax;
|
|
202
|
-
let ymin;
|
|
203
|
-
let ymax;
|
|
204
|
-
|
|
205
|
-
for (let idx = 0; idx < this.items.length; idx++) {
|
|
206
|
-
const itemBoundingBox = this.items[idx].boundingBox();
|
|
207
|
-
|
|
208
|
-
xmin = Math.min(xmin || Infinity, itemBoundingBox.xMin);
|
|
209
|
-
xmax = Math.max(xmax || -Infinity, itemBoundingBox.xMax);
|
|
210
|
-
ymin = Math.min(ymin || Infinity, itemBoundingBox.yMin);
|
|
211
|
-
ymax = Math.max(ymax || -Infinity, itemBoundingBox.yMax);
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
const topLeft = new Point(xmin, ymax);
|
|
215
|
-
const bottomRight = new Point(xmax, ymin);
|
|
216
|
-
|
|
217
|
-
return new BoundingBox(topLeft, bottomRight);
|
|
218
|
-
}
|
|
219
|
-
|
|
220
|
-
touched(selectionExtremes) {
|
|
221
|
-
if (!this.items.length) {
|
|
222
|
-
// nothing to draw
|
|
223
|
-
return false;
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
const layer = DesignCore.LayerManager.getStyleByName(this.layer);
|
|
227
|
-
|
|
228
|
-
if (!layer.isSelectable) {
|
|
229
|
-
return;
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
// Offset selectionExtremes by the block insert position
|
|
233
|
-
const adjustedSelectionExtremes = [
|
|
234
|
-
selectionExtremes[0] - this.points[0].x,
|
|
235
|
-
selectionExtremes[1] - this.points[0].x,
|
|
236
|
-
selectionExtremes[2] - this.points[0].y,
|
|
237
|
-
selectionExtremes[3] - this.points[0].y,
|
|
238
|
-
];
|
|
239
|
-
|
|
240
|
-
for (let idx = 0; idx < this.items.length; idx++) {
|
|
241
|
-
const touched = this.items[idx].touched(adjustedSelectionExtremes);
|
|
242
|
-
if (touched) {
|
|
243
|
-
return true;
|
|
244
|
-
}
|
|
245
|
-
}
|
|
246
|
-
}
|
|
247
|
-
}
|
|
@@ -1,133 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
import {Utils} from '../lib/utils.js';
|
|
3
|
-
import {Strings} from '../lib/strings.js';
|
|
4
|
-
import {Line} from './line.js';
|
|
5
|
-
import {Input, PromptOptions} from '../lib/inputManager.js';
|
|
6
|
-
import {Logging} from '../lib/logging.js';
|
|
7
|
-
import {DXFFile} from '../lib/dxf/dxfFile.js';
|
|
8
|
-
import {BaseDimension} from './baseDimension.js';
|
|
9
|
-
|
|
10
|
-
import {DesignCore} from '../designCore.js';
|
|
11
|
-
|
|
12
|
-
export class DiametricDimension extends BaseDimension {
|
|
13
|
-
constructor(data) {
|
|
14
|
-
super(data);
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
static register() {
|
|
18
|
-
const command = {command: 'DiametricDimension', shortcut: 'DIMDIA'};
|
|
19
|
-
return command;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
async execute() {
|
|
23
|
-
try {
|
|
24
|
-
const op = new PromptOptions(Strings.Input.SELECT, [Input.Type.SINGLESELECTION]);
|
|
25
|
-
|
|
26
|
-
if (!DesignCore.Scene.selectionManager.selectionSet.selectionSet.length) {
|
|
27
|
-
// const selection =
|
|
28
|
-
await DesignCore.Scene.inputManager.requestInput(op);
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
const op1 = new PromptOptions(Strings.Input.END, [Input.Type.POINT]);
|
|
32
|
-
const pt1 = await DesignCore.Scene.inputManager.requestInput(op1);
|
|
33
|
-
pt1.sequence = 11;
|
|
34
|
-
this.points.push(pt1);
|
|
35
|
-
const selectionPoints = DiametricDimension.getPointsFromSelection();
|
|
36
|
-
this.points.push(...selectionPoints);
|
|
37
|
-
|
|
38
|
-
DesignCore.Scene.inputManager.executeCommand(this);
|
|
39
|
-
} catch (err) {
|
|
40
|
-
Logging.instance.error(`${this.type} - ${err}`);
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
preview() {
|
|
45
|
-
if (DesignCore.Scene.selectionManager.selectionSet.selectionSet.length) {
|
|
46
|
-
const mousePoint = DesignCore.Mouse.pointOnScene();
|
|
47
|
-
mousePoint.sequence = 11;
|
|
48
|
-
|
|
49
|
-
const selectionPoints = DiametricDimension.getPointsFromSelection();
|
|
50
|
-
const points = [...selectionPoints, mousePoint];
|
|
51
|
-
DesignCore.Scene.createTempItem(this.type, {points: points});
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
static getPointsFromSelection(items) {
|
|
56
|
-
const item = items[0];
|
|
57
|
-
const center = item.points[0];
|
|
58
|
-
const mousePoint = DesignCore.Mouse.pointOnScene();
|
|
59
|
-
|
|
60
|
-
const angle = center.angle(mousePoint);
|
|
61
|
-
const radPoint = center.project(angle, item.getRadius());
|
|
62
|
-
radPoint.sequence = 15;
|
|
63
|
-
|
|
64
|
-
const angle2 = mousePoint.angle(center);
|
|
65
|
-
const radPoint2 = center.project(angle2, item.getRadius());
|
|
66
|
-
radPoint2.sequence = 10;
|
|
67
|
-
|
|
68
|
-
const points = [radPoint2, radPoint];
|
|
69
|
-
return points;
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
buildDimension() {
|
|
74
|
-
// Diameter
|
|
75
|
-
let dimension = 0;
|
|
76
|
-
const entities = [];
|
|
77
|
-
|
|
78
|
-
const Pt1 = this.getPointBySequence(15); // diameter point
|
|
79
|
-
const Pt2 = this.getPointBySequence(10); // diameter point
|
|
80
|
-
const Pt3 = this.getPointBySequence(11); // text position
|
|
81
|
-
|
|
82
|
-
this.text.points = [Pt3];
|
|
83
|
-
this.text.setRotation(Pt1.angle(Pt2));
|
|
84
|
-
const angle = Utils.radians2degrees(Pt1.angle(Pt2));
|
|
85
|
-
this.text.rotation = angle;
|
|
86
|
-
dimension = Pt1.distance(Pt2);
|
|
87
|
-
|
|
88
|
-
if (dimension < Pt1.distance(Pt3) || dimension < Pt2.distance(Pt3)) {
|
|
89
|
-
// Text is outside the radius
|
|
90
|
-
const endPoint = Pt1.project(Pt2.angle(Pt1), Pt1.distance(Pt3));
|
|
91
|
-
const line1 = new Line({points: [Pt2, endPoint]});
|
|
92
|
-
const arrowHead1 = this.getArrowHead(Pt1, Pt1.angle(Pt2), this.text.height / 2);
|
|
93
|
-
const arrowHead2 = this.getArrowHead(Pt2, Pt2.angle(Pt1), this.text.height / 2);
|
|
94
|
-
|
|
95
|
-
entities.push(line1, arrowHead1, arrowHead2);
|
|
96
|
-
} else {
|
|
97
|
-
// Text is inside the radius
|
|
98
|
-
const line1 = new Line({points: [Pt1, Pt3]});
|
|
99
|
-
const arrowHead1 = this.getArrowHead(Pt1, Pt1.angle(Pt3), this.text.height / 2);
|
|
100
|
-
entities.push(line1, arrowHead1);
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
this.text.string = `${Strings.Symbol.DIAMETER}${Math.abs(dimension.toFixed(2)).toString()}`;
|
|
105
|
-
|
|
106
|
-
return entities;
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
dxf(file) {
|
|
110
|
-
const Pt10 = this.getPointBySequence(10);
|
|
111
|
-
const Pt11 = this.text.points[0];
|
|
112
|
-
const Pt15 = this.getPointBySequence(15);
|
|
113
|
-
|
|
114
|
-
file.writeGroupCode('0', 'DIMENSION');
|
|
115
|
-
file.writeGroupCode('5', file.nextHandle(), DXFFile.Version.R2000); // Handle
|
|
116
|
-
file.writeGroupCode('100', 'AcDbEntity', DXFFile.Version.R2000);
|
|
117
|
-
file.writeGroupCode('100', 'AcDbDimension', DXFFile.Version.R2000);
|
|
118
|
-
file.writeGroupCode('8', this.layer);
|
|
119
|
-
// file.writeGroupCode('2', this.blockName); // Block not required
|
|
120
|
-
file.writeGroupCode('10', Pt10.x); // X - Start of Dimension Line
|
|
121
|
-
file.writeGroupCode('20', Pt10.y); // Y
|
|
122
|
-
file.writeGroupCode('30', '0.0'); // Z
|
|
123
|
-
file.writeGroupCode('11', Pt11.x); // X - Text Midpoint
|
|
124
|
-
file.writeGroupCode('21', Pt11.y); // Y
|
|
125
|
-
file.writeGroupCode('31', '0.0'); // Z
|
|
126
|
-
file.writeGroupCode('70', this.dimType); // DIMENSION TYPE
|
|
127
|
-
file.writeGroupCode('3', 'STANDARD'); // DIMENSION STYLE
|
|
128
|
-
file.writeGroupCode('100', 'AcDbDiametricDimension', DXFFile.Version.R2000);
|
|
129
|
-
file.writeGroupCode('15', Pt15.x); // X - End of Dimension Line
|
|
130
|
-
file.writeGroupCode('25', Pt15.y); // Y
|
|
131
|
-
file.writeGroupCode('35', '0.0'); // Z
|
|
132
|
-
}
|
|
133
|
-
}
|
|
@@ -1,202 +0,0 @@
|
|
|
1
|
-
import {BaseDimension} from './baseDimension.js';
|
|
2
|
-
import {AlignedDimension} from './alignedDimension.js';
|
|
3
|
-
import {DiametricDimension} from './diametricDimension.js';
|
|
4
|
-
import {AngularDimension} from './angularDimension.js';
|
|
5
|
-
import {RadialDimension} from './radialDimension.js';
|
|
6
|
-
|
|
7
|
-
import {Arc} from './arc.js';
|
|
8
|
-
import {Circle} from './circle.js';
|
|
9
|
-
import {Line} from './line.js';
|
|
10
|
-
import {Point} from './point.js';
|
|
11
|
-
|
|
12
|
-
import {Strings} from '../lib/strings.js';
|
|
13
|
-
import {Input, PromptOptions} from '../lib/inputManager.js';
|
|
14
|
-
import {Logging} from '../lib/logging.js';
|
|
15
|
-
|
|
16
|
-
import {DesignCore} from '../designCore.js';
|
|
17
|
-
import {SingleSelection} from '../lib/selectionManager.js';
|
|
18
|
-
|
|
19
|
-
export class Dimension extends BaseDimension {
|
|
20
|
-
constructor(data) {
|
|
21
|
-
super(data);
|
|
22
|
-
|
|
23
|
-
// map dimensions type to the class name
|
|
24
|
-
this.dimensionMap = {
|
|
25
|
-
0: AlignedDimension,
|
|
26
|
-
1: AlignedDimension,
|
|
27
|
-
2: AngularDimension,
|
|
28
|
-
3: DiametricDimension,
|
|
29
|
-
4: RadialDimension,
|
|
30
|
-
5: null, // 5 = Angular 3 point;
|
|
31
|
-
6: null, // 6 = Ordinate;
|
|
32
|
-
};
|
|
33
|
-
|
|
34
|
-
this.selectedItems = [];
|
|
35
|
-
|
|
36
|
-
if (data) {
|
|
37
|
-
const dimType = (data[70] || data.dimType) % 32;
|
|
38
|
-
|
|
39
|
-
if (Number.isInteger(dimType) && dimType >= 0 && dimType <= 6) {
|
|
40
|
-
const item = new this.dimensionMap[dimType](data);
|
|
41
|
-
|
|
42
|
-
// find the block linked to this dimension
|
|
43
|
-
const linkedBlockIndex = DesignCore.Scene.findItem('BLOCK', 'name', data[2]);
|
|
44
|
-
|
|
45
|
-
if (linkedBlockIndex.length) {
|
|
46
|
-
// remove the block from the scene, dimensions manage their block internally
|
|
47
|
-
// const removed =
|
|
48
|
-
DesignCore.Scene.removeItem(linkedBlockIndex[0]);
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
return item;
|
|
52
|
-
} else {
|
|
53
|
-
const msg = 'Invalid DimType';
|
|
54
|
-
const err = (`${this.type} - ${msg}`);
|
|
55
|
-
throw Error(err);
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
static register() {
|
|
61
|
-
const command = {command: 'Dimension', shortcut: 'DIM', type: 'Entity'};
|
|
62
|
-
return command;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
async execute() {
|
|
66
|
-
try {
|
|
67
|
-
let inputValid = false;
|
|
68
|
-
|
|
69
|
-
while (!inputValid) {
|
|
70
|
-
const options = new PromptOptions(`${Strings.Input.START} or ${Strings.Input.SELECT}`, [Input.Type.POINT, Input.Type.SINGLESELECTION]);
|
|
71
|
-
const input1 = await DesignCore.Scene.inputManager.requestInput(options);
|
|
72
|
-
|
|
73
|
-
if (input1 instanceof Point) {
|
|
74
|
-
inputValid = true;
|
|
75
|
-
|
|
76
|
-
this.dimType = 1;
|
|
77
|
-
|
|
78
|
-
input1.sequence = 13;
|
|
79
|
-
this.points.push(input1);
|
|
80
|
-
|
|
81
|
-
// select a second point to define the dimension
|
|
82
|
-
const op1 = new PromptOptions(Strings.Input.END, [Input.Type.POINT]);
|
|
83
|
-
const pt14 = await DesignCore.Scene.inputManager.requestInput(op1);
|
|
84
|
-
pt14.sequence = 14;
|
|
85
|
-
this.points.push(pt14);
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
if (input1 instanceof SingleSelection) {
|
|
89
|
-
const selectedItem = DesignCore.Scene.getItem(input1.selectedItemIndex);
|
|
90
|
-
|
|
91
|
-
// check the selected entity is supported
|
|
92
|
-
if ([Line, Circle, Arc].some((entity) => selectedItem instanceof entity)) {
|
|
93
|
-
this.selectedItems.push(selectedItem);
|
|
94
|
-
inputValid = true;
|
|
95
|
-
|
|
96
|
-
// set the dimension type
|
|
97
|
-
if (selectedItem instanceof Line) {
|
|
98
|
-
this.dimType = 1;
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
if (selectedItem instanceof Circle) {
|
|
102
|
-
this.dimType = 3;
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
if (selectedItem instanceof Arc) {
|
|
106
|
-
this.dimType = 4;
|
|
107
|
-
}
|
|
108
|
-
} else {
|
|
109
|
-
const msg = `${this.type} - Unsupported Type: ${selectedItem.type}`;
|
|
110
|
-
DesignCore.Core.notify(msg);
|
|
111
|
-
DesignCore.Scene.selectionManager.reset();
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
// select a second line to make a angular dimension or a point to position the dimension text
|
|
117
|
-
// loop until this.points contains a point with sequence 11 i.e. a text position
|
|
118
|
-
while (!this.points.some((point) => point.sequence === 11)) {
|
|
119
|
-
// default prompt: select a location for the text position
|
|
120
|
-
let op2 = new PromptOptions(Strings.Input.DIMENSION, [Input.Type.POINT]);
|
|
121
|
-
|
|
122
|
-
// Angular dimension prompt: select a second line for an angular dimension or location for the text position
|
|
123
|
-
if ((this.selectedItems[0] instanceof Line) && this.selectedItems.length < 2) {
|
|
124
|
-
op2 = new PromptOptions(`${Strings.Input.DIMENSION} or ${Strings.Input.SELECT}`, [Input.Type.POINT, Input.Type.SINGLESELECTION]);
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
// diametric prompt: select radial or diametric type dimension or location for the the text position
|
|
128
|
-
if (this.selectedItems[0] instanceof Circle ) {
|
|
129
|
-
const options = this.dimType === 3 ? ['Radius'] : ['Diameter'];
|
|
130
|
-
op2 = new PromptOptions(`${Strings.Input.DIMENSION} or ${Strings.Input.OPTION}`, [Input.Type.POINT], options);
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
const input2 = await DesignCore.Scene.inputManager.requestInput(op2);
|
|
134
|
-
|
|
135
|
-
if (Input.getType(input2) === Input.Type.POINT) {
|
|
136
|
-
const pt11 = input2;
|
|
137
|
-
pt11.sequence = 11;
|
|
138
|
-
this.points.push(pt11);
|
|
139
|
-
|
|
140
|
-
// if selected items are available, get the points from the selected items
|
|
141
|
-
// dimensions can be created from point selection only, therefore selected items may not be available
|
|
142
|
-
if (this.selectedItems.length) {
|
|
143
|
-
const dimensionType = this.dimensionMap[this.dimType];
|
|
144
|
-
this.points.push(...dimensionType.getPointsFromSelection(this.selectedItems));
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
if (Input.getType(input2) === Input.Type.STRING) {
|
|
149
|
-
// options are converted to input in the prompt options class
|
|
150
|
-
if (input2 === 'Diameter') {
|
|
151
|
-
this.dimType = 3;
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
if (input2 === 'Radius') {
|
|
155
|
-
this.dimType = 4;
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
if (Input.getType(input2) === Input.Type.SINGLESELECTION) {
|
|
160
|
-
const selectedItem2 = DesignCore.Scene.getItem(input2.selectedItemIndex);
|
|
161
|
-
if ([Line].some((entity) => selectedItem2 instanceof entity)) {
|
|
162
|
-
this.selectedItems.push(selectedItem2);
|
|
163
|
-
// Two lines selected - switch to angular dimension
|
|
164
|
-
this.dimType = 2;
|
|
165
|
-
} else {
|
|
166
|
-
const msg = `${this.type} - Unsupported Type: ${selectedItem2.type}`;
|
|
167
|
-
DesignCore.Core.notify(msg);
|
|
168
|
-
DesignCore.Scene.selectionManager.reset();
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
DesignCore.Scene.inputManager.executeCommand(this);
|
|
174
|
-
} catch (err) {
|
|
175
|
-
Logging.instance.error(`${this.type} - ${err}`);
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
preview() {
|
|
180
|
-
// get the dimension class
|
|
181
|
-
const dimensionType = this.dimensionMap[this.dimType];
|
|
182
|
-
// get the dimension type as a string
|
|
183
|
-
const dimensionTypeString = dimensionType.register().command;
|
|
184
|
-
|
|
185
|
-
if (this.selectedItems.length) {
|
|
186
|
-
const itemPoints = dimensionType.getPointsFromSelection(this.selectedItems);
|
|
187
|
-
|
|
188
|
-
const mousePoint = DesignCore.Mouse.pointOnScene();
|
|
189
|
-
mousePoint.sequence = 11;
|
|
190
|
-
|
|
191
|
-
const points = [...itemPoints, mousePoint];
|
|
192
|
-
DesignCore.Scene.createTempItem(dimensionTypeString, {points: points});
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
if (this.points.length > 1) {
|
|
196
|
-
const mousePoint = DesignCore.Mouse.pointOnScene();
|
|
197
|
-
mousePoint.sequence = 11;
|
|
198
|
-
const points = [...this.points, mousePoint];
|
|
199
|
-
DesignCore.Scene.createTempItem(dimensionTypeString, {points: points});
|
|
200
|
-
}
|
|
201
|
-
}
|
|
202
|
-
}
|