@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/lib/dxf/dxf.js
CHANGED
|
@@ -1,41 +1,68 @@
|
|
|
1
|
-
import {DXFReader} from './dxfRead.js';
|
|
2
|
-
import {DXFWriter} from './dxfWrite.js';
|
|
3
|
-
import {DXFFile} from './dxfFile.js';
|
|
4
|
-
import {Point} from '../../entities/point.js';
|
|
5
|
-
import {Strings} from '../strings.js';
|
|
6
|
-
import {Logging} from '../logging.js';
|
|
1
|
+
import { DXFReader } from './dxfRead.js';
|
|
2
|
+
import { DXFWriter } from './dxfWrite.js';
|
|
3
|
+
import { DXFFile } from './dxfFile.js';
|
|
4
|
+
import { Point } from '../../entities/point.js';
|
|
5
|
+
import { Strings } from '../strings.js';
|
|
6
|
+
import { Logging } from '../logging.js';
|
|
7
7
|
|
|
8
|
-
import {DesignCore} from '../../designCore.js';
|
|
8
|
+
import { DesignCore } from '../../designCore.js';
|
|
9
9
|
|
|
10
|
+
/** DXF Class */
|
|
10
11
|
export class DXF {
|
|
12
|
+
/** Create DXF */
|
|
11
13
|
constructor() {
|
|
12
14
|
this.reader;
|
|
13
15
|
this.writer;
|
|
14
16
|
|
|
15
17
|
// flag indicates if dxf contains unsupported elements
|
|
16
18
|
this.unsupportedElements = false;
|
|
19
|
+
|
|
20
|
+
// map of block name to block record handle
|
|
21
|
+
this.blockRecordHandles = {};
|
|
17
22
|
}
|
|
18
23
|
|
|
24
|
+
/**
|
|
25
|
+
* Read
|
|
26
|
+
* @param {Object} data
|
|
27
|
+
*/
|
|
19
28
|
read(data) {
|
|
20
29
|
this.reader = new DXFReader();
|
|
21
30
|
this.reader.read(data);
|
|
22
31
|
}
|
|
23
32
|
|
|
33
|
+
/**
|
|
34
|
+
* Write
|
|
35
|
+
* @param {string} version
|
|
36
|
+
* @return {Object}
|
|
37
|
+
*/
|
|
24
38
|
write(version) {
|
|
25
39
|
const writer = new DXFWriter();
|
|
26
40
|
const data = writer.write(version);
|
|
27
41
|
return data;
|
|
28
42
|
}
|
|
29
43
|
|
|
44
|
+
/**
|
|
45
|
+
* Load DXF
|
|
46
|
+
* @param {string} data
|
|
47
|
+
*/
|
|
30
48
|
loadDxf(data) {
|
|
31
49
|
Logging.instance.debug('Loading File');
|
|
32
50
|
this.read(data);
|
|
33
51
|
|
|
52
|
+
// Reset handles before loading
|
|
53
|
+
// This prevents handle collisions between init handles and file handles
|
|
54
|
+
DesignCore.HandleManager.reset();
|
|
55
|
+
|
|
56
|
+
// load handseed first to ensure the handle counter is correctly set
|
|
57
|
+
// before any new handles are assigned during table/block/entity loading
|
|
58
|
+
this.loadHandseed();
|
|
59
|
+
|
|
34
60
|
this.loadTables();
|
|
35
61
|
this.loadBlocks();
|
|
36
62
|
this.loadEntities();
|
|
63
|
+
this.loadObjects();
|
|
37
64
|
|
|
38
|
-
// load headers
|
|
65
|
+
// load headers for styles and version
|
|
39
66
|
this.loadHeader();
|
|
40
67
|
|
|
41
68
|
if (this.unsupportedElements) {
|
|
@@ -43,9 +70,38 @@ export class DXF {
|
|
|
43
70
|
}
|
|
44
71
|
}
|
|
45
72
|
|
|
73
|
+
/**
|
|
74
|
+
* Load Handseed from header
|
|
75
|
+
* Must be called before loading tables/blocks/entities
|
|
76
|
+
* to ensure the handle counter is set beyond all handles in the file
|
|
77
|
+
*/
|
|
78
|
+
loadHandseed() {
|
|
79
|
+
const header = this.reader.header;
|
|
80
|
+
|
|
81
|
+
if (header.hasOwnProperty('$HANDSEED')) {
|
|
82
|
+
const handseed = header['$HANDSEED'];
|
|
83
|
+
if (handseed.hasOwnProperty('5')) {
|
|
84
|
+
const maxHandseed = handseed['5'];
|
|
85
|
+
Logging.instance.debug(`Opening DXF Handseed: ${maxHandseed}`);
|
|
86
|
+
DesignCore.HandleManager.handseed = maxHandseed;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* Load Header
|
|
93
|
+
*/
|
|
46
94
|
loadHeader() {
|
|
47
95
|
const header = this.reader.header;
|
|
48
96
|
|
|
97
|
+
if (header.hasOwnProperty('$TEXTSTYLE')) {
|
|
98
|
+
const cstyle = header['$TEXTSTYLE'];
|
|
99
|
+
if (cstyle.hasOwnProperty('7')) {
|
|
100
|
+
const styleName = cstyle['7'];
|
|
101
|
+
DesignCore.StyleManager.setCstyle(styleName);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
49
105
|
if (header.hasOwnProperty('$CLAYER')) {
|
|
50
106
|
const clayer = header['$CLAYER'];
|
|
51
107
|
if (clayer.hasOwnProperty('8')) {
|
|
@@ -54,6 +110,14 @@ export class DXF {
|
|
|
54
110
|
}
|
|
55
111
|
}
|
|
56
112
|
|
|
113
|
+
if (header.hasOwnProperty('$DIMSTYLE')) {
|
|
114
|
+
const dimstyle = header['$DIMSTYLE'];
|
|
115
|
+
if (dimstyle.hasOwnProperty('2')) {
|
|
116
|
+
const styleName = dimstyle['2'];
|
|
117
|
+
DesignCore.DimStyleManager.setCstyle(styleName);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
|
|
57
121
|
if (header.hasOwnProperty('$ACADVER')) {
|
|
58
122
|
const version = header['$ACADVER'];
|
|
59
123
|
if (version.hasOwnProperty('1')) {
|
|
@@ -64,63 +128,154 @@ export class DXF {
|
|
|
64
128
|
DesignCore.Core.dxfVersion = versionNumber;
|
|
65
129
|
}
|
|
66
130
|
}
|
|
131
|
+
|
|
132
|
+
// Load drawing-level header variables into Scene.headers
|
|
133
|
+
DesignCore.Scene.headers.load(header);
|
|
67
134
|
}
|
|
68
135
|
|
|
69
136
|
|
|
137
|
+
/**
|
|
138
|
+
* Load Tables
|
|
139
|
+
*/
|
|
70
140
|
loadTables() {
|
|
71
141
|
const tables = this.reader.tables;
|
|
72
142
|
|
|
73
143
|
tables.forEach((table) => {
|
|
74
144
|
if (table[2] === 'LAYER') {
|
|
145
|
+
if (table[5]) {
|
|
146
|
+
DesignCore.HandleManager.checkHandle(table[5]);
|
|
147
|
+
DesignCore.LayerManager.handle = table[5];
|
|
148
|
+
}
|
|
149
|
+
if (table.children.length) {
|
|
150
|
+
DesignCore.LayerManager.clearItems();
|
|
151
|
+
}
|
|
75
152
|
table.children.forEach((layer) => {
|
|
76
|
-
DesignCore.LayerManager.
|
|
153
|
+
DesignCore.LayerManager.addItem(layer, true);
|
|
77
154
|
});
|
|
78
155
|
}
|
|
79
156
|
|
|
80
157
|
if (table[2] === 'LTYPE') {
|
|
158
|
+
if (table[5]) {
|
|
159
|
+
DesignCore.HandleManager.checkHandle(table[5]);
|
|
160
|
+
DesignCore.LTypeManager.handle = table[5];
|
|
161
|
+
}
|
|
162
|
+
if (table.children.length) {
|
|
163
|
+
DesignCore.LTypeManager.clearItems();
|
|
164
|
+
}
|
|
81
165
|
table.children.forEach((ltype) => {
|
|
82
|
-
DesignCore.LTypeManager.
|
|
166
|
+
DesignCore.LTypeManager.addItem(ltype, true);
|
|
83
167
|
});
|
|
84
168
|
}
|
|
85
169
|
|
|
86
170
|
if (table[2] === 'STYLE') {
|
|
171
|
+
if (table[5]) {
|
|
172
|
+
DesignCore.HandleManager.checkHandle(table[5]);
|
|
173
|
+
DesignCore.StyleManager.handle = table[5];
|
|
174
|
+
}
|
|
175
|
+
if (table.children.length) {
|
|
176
|
+
DesignCore.StyleManager.clearItems();
|
|
177
|
+
}
|
|
87
178
|
table.children.forEach((style) => {
|
|
88
|
-
DesignCore.StyleManager.
|
|
179
|
+
DesignCore.StyleManager.addItem(style, true);
|
|
89
180
|
});
|
|
90
181
|
}
|
|
91
182
|
|
|
92
183
|
if (table[2] === 'DIMSTYLE') {
|
|
184
|
+
if (table[5]) {
|
|
185
|
+
DesignCore.HandleManager.checkHandle(table[5]);
|
|
186
|
+
DesignCore.DimStyleManager.handle = table[5];
|
|
187
|
+
}
|
|
188
|
+
if (table.children.length) {
|
|
189
|
+
DesignCore.DimStyleManager.clearItems();
|
|
190
|
+
}
|
|
93
191
|
table.children.forEach((style) => {
|
|
94
|
-
DesignCore.DimStyleManager.
|
|
192
|
+
DesignCore.DimStyleManager.addItem(style, true);
|
|
193
|
+
});
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
if (table[2] === 'VPORT') {
|
|
197
|
+
if (table[5]) {
|
|
198
|
+
DesignCore.HandleManager.checkHandle(table[5]);
|
|
199
|
+
DesignCore.VPortManager.handle = table[5];
|
|
200
|
+
}
|
|
201
|
+
if (table.children.length) {
|
|
202
|
+
DesignCore.VPortManager.clearItems();
|
|
203
|
+
}
|
|
204
|
+
table.children.forEach((vport) => {
|
|
205
|
+
DesignCore.VPortManager.addItem(vport, true);
|
|
95
206
|
});
|
|
96
207
|
}
|
|
208
|
+
|
|
209
|
+
if (table[2] === 'VIEW') {
|
|
210
|
+
if (table[5]) {
|
|
211
|
+
DesignCore.HandleManager.checkHandle(table[5]);
|
|
212
|
+
DesignCore.ViewManager.handle = table[5];
|
|
213
|
+
}
|
|
214
|
+
if (table.children.length) {
|
|
215
|
+
DesignCore.ViewManager.clearItems();
|
|
216
|
+
}
|
|
217
|
+
table.children.forEach((view) => {
|
|
218
|
+
DesignCore.ViewManager.addItem(view, true);
|
|
219
|
+
});
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
if (table[2] === 'UCS') {
|
|
223
|
+
if (table[5]) {
|
|
224
|
+
DesignCore.HandleManager.checkHandle(table[5]);
|
|
225
|
+
DesignCore.UCSManager.handle = table[5];
|
|
226
|
+
}
|
|
227
|
+
if (table.children.length) {
|
|
228
|
+
DesignCore.UCSManager.clearItems();
|
|
229
|
+
}
|
|
230
|
+
table.children.forEach((ucs) => {
|
|
231
|
+
DesignCore.UCSManager.addItem(ucs, true);
|
|
232
|
+
});
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
if (table[2] === 'APPID') {
|
|
236
|
+
if (table[5]) {
|
|
237
|
+
DesignCore.HandleManager.checkHandle(table[5]);
|
|
238
|
+
DesignCore.AppIDManager.handle = table[5];
|
|
239
|
+
}
|
|
240
|
+
if (table.children.length) {
|
|
241
|
+
DesignCore.AppIDManager.clearItems();
|
|
242
|
+
}
|
|
243
|
+
table.children.forEach((appid) => {
|
|
244
|
+
DesignCore.AppIDManager.addItem(appid, true);
|
|
245
|
+
});
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
if (table[2] === 'BLOCK_RECORD') {
|
|
249
|
+
if (table[5]) {
|
|
250
|
+
DesignCore.HandleManager.checkHandle(table[5]);
|
|
251
|
+
DesignCore.BlockRecordManager.handle = table[5];
|
|
252
|
+
}
|
|
253
|
+
// Build a map of block name to block record handle
|
|
254
|
+
// This is used when loading blocks to assign the correct blockRecordHandle
|
|
255
|
+
|
|
256
|
+
if (table.children) {
|
|
257
|
+
table.children.forEach((record) => {
|
|
258
|
+
if (record[2] && record[5]) {
|
|
259
|
+
DesignCore.HandleManager.checkHandle(record[5]);
|
|
260
|
+
this.blockRecordHandles[record[2]] = record[5];
|
|
261
|
+
}
|
|
262
|
+
});
|
|
263
|
+
}
|
|
264
|
+
}
|
|
97
265
|
});
|
|
98
266
|
}
|
|
99
267
|
|
|
268
|
+
/**
|
|
269
|
+
* Load Blocks
|
|
270
|
+
*/
|
|
100
271
|
loadBlocks() {
|
|
101
272
|
const blocks = this.reader.blocks;
|
|
102
273
|
|
|
274
|
+
if (blocks.length) {
|
|
275
|
+
DesignCore.Scene.blockManager.clearItems();
|
|
276
|
+
}
|
|
277
|
+
|
|
103
278
|
blocks.forEach((block) => {
|
|
104
|
-
if (block.hasOwnProperty('2')) {
|
|
105
|
-
/*
|
|
106
|
-
Three empty definitions always appear in the BLOCKS section.
|
|
107
|
-
They are titled *Model_Space, *Paper_Space and *Paper_Space0.
|
|
108
|
-
These definitions manifest the representations of model space and paper space as block definitions internally.
|
|
109
|
-
The internal name of the first paper space layout is *Paper_Space,
|
|
110
|
-
the second is *Paper_Space0,
|
|
111
|
-
the third is *Paper_Space1,
|
|
112
|
-
and so on.
|
|
113
|
-
*/
|
|
114
|
-
if (block[2].toUpperCase().includes('MODEL_SPACE')) {
|
|
115
|
-
// skip model_space blocks
|
|
116
|
-
return;
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
if (block[2].toUpperCase().includes('PAPER_SPACE')) {
|
|
120
|
-
// skip paper_space blocks
|
|
121
|
-
return;
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
279
|
if (block.hasOwnProperty('points')) {
|
|
125
280
|
block.points = this.parsePoints(block.points);
|
|
126
281
|
}
|
|
@@ -131,6 +286,14 @@ export class DXF {
|
|
|
131
286
|
if (child.hasOwnProperty('0') === false) {
|
|
132
287
|
return;
|
|
133
288
|
}
|
|
289
|
+
|
|
290
|
+
// Extract the ENDBLK handle from the block children
|
|
291
|
+
if (child[0] === 'ENDBLK' && child[5]) {
|
|
292
|
+
DesignCore.HandleManager.checkHandle(child[5]);
|
|
293
|
+
block.endblkHandle = child[5];
|
|
294
|
+
return;
|
|
295
|
+
}
|
|
296
|
+
|
|
134
297
|
// Convert child points to design points
|
|
135
298
|
if (child.hasOwnProperty('points')) {
|
|
136
299
|
child.points = this.parsePoints(child.points);
|
|
@@ -142,6 +305,11 @@ export class DXF {
|
|
|
142
305
|
// create an instance of the child entity
|
|
143
306
|
const item = DesignCore.CommandManager.createNew(command, child);
|
|
144
307
|
|
|
308
|
+
// Register the child entity handle
|
|
309
|
+
if (item.handle) {
|
|
310
|
+
DesignCore.HandleManager.checkHandle(item.handle);
|
|
311
|
+
}
|
|
312
|
+
|
|
145
313
|
if (block.hasOwnProperty('items') === false) {
|
|
146
314
|
block.items = [];
|
|
147
315
|
}
|
|
@@ -154,13 +322,25 @@ export class DXF {
|
|
|
154
322
|
});
|
|
155
323
|
}
|
|
156
324
|
|
|
157
|
-
|
|
325
|
+
// Assign the block record handle from the BLOCK_RECORD table
|
|
326
|
+
if (block[2] && this.blockRecordHandles[block[2]]) {
|
|
327
|
+
block.blockRecordHandle = this.blockRecordHandles[block[2]];
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
DesignCore.Scene.blockManager.addItem(block, true);
|
|
158
331
|
});
|
|
159
332
|
}
|
|
160
333
|
|
|
334
|
+
/**
|
|
335
|
+
* Load Entities
|
|
336
|
+
*/
|
|
161
337
|
loadEntities() {
|
|
162
338
|
const entities = this.reader.entities;
|
|
163
339
|
|
|
340
|
+
if (entities.length) {
|
|
341
|
+
DesignCore.Scene.entities.clear();
|
|
342
|
+
}
|
|
343
|
+
|
|
164
344
|
entities.forEach((entity) => {
|
|
165
345
|
if (entity.hasOwnProperty('points')) {
|
|
166
346
|
entity.points = this.parsePoints(entity.points);
|
|
@@ -168,9 +348,38 @@ export class DXF {
|
|
|
168
348
|
|
|
169
349
|
this.addItem(entity);
|
|
170
350
|
});
|
|
351
|
+
|
|
352
|
+
// ensure all layers, ltypes, styles, dimstyles exist
|
|
353
|
+
DesignCore.LayerManager.checkItems();
|
|
354
|
+
DesignCore.LTypeManager.checkItems();
|
|
355
|
+
DesignCore.StyleManager.checkItems();
|
|
356
|
+
DesignCore.DimStyleManager.checkItems();
|
|
171
357
|
}
|
|
172
358
|
|
|
359
|
+
/**
|
|
360
|
+
* Load Objects
|
|
361
|
+
*/
|
|
362
|
+
loadObjects() {
|
|
363
|
+
const objects = this.reader.objects;
|
|
364
|
+
|
|
365
|
+
if (objects.length) {
|
|
366
|
+
DesignCore.DictionaryManager.clearItems();
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
objects.forEach((object) => {
|
|
370
|
+
if (object[0] === 'DICTIONARY') {
|
|
371
|
+
DesignCore.DictionaryManager.addItem(object);
|
|
372
|
+
}
|
|
373
|
+
});
|
|
374
|
+
|
|
375
|
+
// Ensure standard items exist
|
|
376
|
+
DesignCore.DictionaryManager.checkItems();
|
|
377
|
+
}
|
|
173
378
|
|
|
379
|
+
/**
|
|
380
|
+
* Add Item
|
|
381
|
+
* @param {Object} item
|
|
382
|
+
*/
|
|
174
383
|
addItem(item) {
|
|
175
384
|
if (item.hasOwnProperty('0') === false) {
|
|
176
385
|
return;
|
|
@@ -178,13 +387,19 @@ export class DXF {
|
|
|
178
387
|
|
|
179
388
|
const command = item[0];
|
|
180
389
|
if (DesignCore.CommandManager.isCommand(command)) {
|
|
181
|
-
DesignCore.
|
|
390
|
+
const entity = DesignCore.CommandManager.createNew(command, item);
|
|
391
|
+
DesignCore.Scene.entities.add(entity);
|
|
182
392
|
} else {
|
|
183
393
|
Logging.instance.warn(`${Strings.Message.UNKNOWNCOMMAND} ${command}`);
|
|
184
394
|
this.unsupportedElements = true;
|
|
185
395
|
}
|
|
186
396
|
}
|
|
187
397
|
|
|
398
|
+
/**
|
|
399
|
+
* Parse Points
|
|
400
|
+
* @param {Object} dxfPoints
|
|
401
|
+
* @return {Array}
|
|
402
|
+
*/
|
|
188
403
|
parsePoints(dxfPoints) {
|
|
189
404
|
const points = [];
|
|
190
405
|
dxfPoints.forEach((point) => {
|
package/core/lib/dxf/dxfFile.js
CHANGED
|
@@ -1,8 +1,13 @@
|
|
|
1
|
-
import {Logging} from '../logging.js';
|
|
2
|
-
import {Strings} from '../strings.js';
|
|
1
|
+
import { Logging } from '../logging.js';
|
|
2
|
+
import { Strings } from '../strings.js';
|
|
3
3
|
|
|
4
|
+
/** DXF File Class */
|
|
4
5
|
export class DXFFile {
|
|
5
|
-
|
|
6
|
+
/**
|
|
7
|
+
* Create DXFFile
|
|
8
|
+
* @param {string} version
|
|
9
|
+
*/
|
|
10
|
+
constructor(version = 'R2018') {
|
|
6
11
|
this.contents = '';
|
|
7
12
|
|
|
8
13
|
// Validate version
|
|
@@ -11,13 +16,12 @@ export class DXFFile {
|
|
|
11
16
|
}
|
|
12
17
|
|
|
13
18
|
this.version = DXFFile.Version[version];
|
|
14
|
-
this.handleCounter = 10;
|
|
15
19
|
}
|
|
16
20
|
|
|
17
21
|
/**
|
|
18
22
|
* Check if a dxf version is valid - 'AC1009' = valid, R12 = not valid
|
|
19
23
|
* @param {string} version
|
|
20
|
-
* @
|
|
24
|
+
* @return {boolean} - true if version is valid
|
|
21
25
|
*/
|
|
22
26
|
static validDxfVersion(version) {
|
|
23
27
|
if (Object.values(DXFFile.Version).indexOf(version) === -1) {
|
|
@@ -30,7 +34,7 @@ export class DXFFile {
|
|
|
30
34
|
/**
|
|
31
35
|
* Check if a dxf key is valid - R12 = valid, 'AC1009' = not valid
|
|
32
36
|
* @param {string} key
|
|
33
|
-
* @
|
|
37
|
+
* @return {boolean} - true if version is valid
|
|
34
38
|
*/
|
|
35
39
|
static validDxfKey(key) {
|
|
36
40
|
if (Object.keys(DXFFile.Version).indexOf(key) === -1) {
|
|
@@ -41,8 +45,8 @@ export class DXFFile {
|
|
|
41
45
|
|
|
42
46
|
/**
|
|
43
47
|
* Return the dxf key for the dxf version e.g key = R12 version = 'AC1009'
|
|
44
|
-
* @param {
|
|
45
|
-
* @
|
|
48
|
+
* @param {string} dxfVersion
|
|
49
|
+
* @return {string} dxf key (R Number) for valid dxf versions
|
|
46
50
|
*/
|
|
47
51
|
static getVersionKey(dxfVersion) {
|
|
48
52
|
if (DXFFile.validDxfVersion(dxfVersion)) {
|
|
@@ -77,52 +81,33 @@ export class DXFFile {
|
|
|
77
81
|
*/
|
|
78
82
|
clearFile() {
|
|
79
83
|
this.contents = '';
|
|
80
|
-
this.handleCounter = 10;
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
/**
|
|
84
|
-
* Returns the next available handle value
|
|
85
|
-
* R12 handles are optional.
|
|
86
|
-
* R13+ handles are mandatory.
|
|
87
|
-
* The header variable $HANDSEED must be greater than the largest handle value
|
|
88
|
-
* @returns handle value
|
|
89
|
-
*/
|
|
90
|
-
nextHandle() {
|
|
91
|
-
const handle = this.formatHandle(this.handleCounter);
|
|
92
|
-
this.handleCounter++;
|
|
93
|
-
return handle;
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
/**
|
|
97
|
-
* Format a handle value
|
|
98
|
-
* A handle is an arbitrary but unique hex value as string up to 16 hexadecimal digits (8 bytes).
|
|
99
|
-
* @param {number} value
|
|
100
|
-
* @returns handle hex value
|
|
101
|
-
*/
|
|
102
|
-
formatHandle(value) {
|
|
103
|
-
return value.toString(16).toUpperCase();
|
|
104
84
|
}
|
|
105
85
|
|
|
106
86
|
/**
|
|
107
87
|
* Write the group code and value to file
|
|
108
|
-
* @param {
|
|
109
|
-
* @param {
|
|
110
|
-
* @param {
|
|
111
|
-
* @returns
|
|
88
|
+
* @param {string} groupCode
|
|
89
|
+
* @param {string} groupValue
|
|
90
|
+
* @param {string} version - DXFFile.Version
|
|
112
91
|
*/
|
|
113
|
-
writeGroupCode(groupCode, groupValue, version=DXFFile.Version.R12) {
|
|
92
|
+
writeGroupCode(groupCode, groupValue, version = DXFFile.Version.R12) {
|
|
114
93
|
// return if the groupcode is required for a later version
|
|
115
94
|
if (version > this.version) {
|
|
116
95
|
return;
|
|
117
96
|
}
|
|
118
97
|
|
|
98
|
+
if (groupValue === undefined) {
|
|
99
|
+
const err = `Invalid groupvalue for dxf groupcode ${groupCode}`;
|
|
100
|
+
Logging.instance.error(`${this.type} - ${err}`);
|
|
101
|
+
throw Error(Strings.Error.INVALIDDXFFORMAT);
|
|
102
|
+
}
|
|
103
|
+
|
|
119
104
|
this.writeLine(groupCode);
|
|
120
105
|
this.writeLine(groupValue);
|
|
121
106
|
}
|
|
122
107
|
|
|
123
108
|
/**
|
|
124
109
|
* Write a new line to the contents
|
|
125
|
-
* @param {
|
|
110
|
+
* @param {string} value
|
|
126
111
|
*/
|
|
127
112
|
writeLine(value) {
|
|
128
113
|
this.contents = this.contents.concat(`${value}\n`);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {Strings} from '../strings.js';
|
|
1
|
+
import { Strings } from '../strings.js';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
This class is designed to iterate though an internal array of DXF groupcode and value pairs
|
|
@@ -23,9 +23,11 @@ Example DXF Entity Pairs:
|
|
|
23
23
|
value: 100.0 - y position
|
|
24
24
|
*/
|
|
25
25
|
|
|
26
|
+
/** DXF Interator Class */
|
|
26
27
|
export class DxfIterator {
|
|
27
28
|
static _instance;
|
|
28
29
|
|
|
30
|
+
/** Create DXFInterator */
|
|
29
31
|
constructor() {
|
|
30
32
|
this.currentIndex = 0;
|
|
31
33
|
this.lines = [];
|
|
@@ -38,6 +40,9 @@ export class DxfIterator {
|
|
|
38
40
|
return DxfIterator._instance;
|
|
39
41
|
}
|
|
40
42
|
|
|
43
|
+
/**
|
|
44
|
+
* Get Instance
|
|
45
|
+
*/
|
|
41
46
|
static get instance() {
|
|
42
47
|
if (this._instance === undefined) {
|
|
43
48
|
this._instance = new this();
|
|
@@ -47,7 +52,7 @@ export class DxfIterator {
|
|
|
47
52
|
|
|
48
53
|
/**
|
|
49
54
|
* Load a string object representing the dxf file
|
|
50
|
-
* @param {
|
|
55
|
+
* @param {string} file
|
|
51
56
|
*/
|
|
52
57
|
loadFile(file) {
|
|
53
58
|
// check there is data
|
|
@@ -82,7 +87,7 @@ export class DxfIterator {
|
|
|
82
87
|
|
|
83
88
|
/**
|
|
84
89
|
* Stop iteration and throw error
|
|
85
|
-
* @param {
|
|
90
|
+
* @param {string} msg - error message
|
|
86
91
|
*/
|
|
87
92
|
dxfError(msg) {
|
|
88
93
|
throw Error(`${msg} - ${Strings.Strings.LINE}: ${this.currentIndex + 1}`);
|
|
@@ -91,6 +96,7 @@ export class DxfIterator {
|
|
|
91
96
|
|
|
92
97
|
/**
|
|
93
98
|
* Format and return the current value
|
|
99
|
+
* @return {any}
|
|
94
100
|
*/
|
|
95
101
|
current() {
|
|
96
102
|
const current = this.formatted(this.lines[this.currentIndex]);
|
|
@@ -100,7 +106,8 @@ export class DxfIterator {
|
|
|
100
106
|
|
|
101
107
|
/**
|
|
102
108
|
* Format the input value removing line breaks
|
|
103
|
-
* @param {
|
|
109
|
+
* @param {string} value
|
|
110
|
+
* @return {string}
|
|
104
111
|
*/
|
|
105
112
|
formatted(value) {
|
|
106
113
|
return value.replace(/(\r\n|\n|\r)/gm, '');
|
|
@@ -108,6 +115,7 @@ export class DxfIterator {
|
|
|
108
115
|
|
|
109
116
|
/**
|
|
110
117
|
* Format and return the next value
|
|
118
|
+
* @return {any}
|
|
111
119
|
*/
|
|
112
120
|
nextValue() {
|
|
113
121
|
if (this.currentIndex < this.lines.length - 1) {
|
|
@@ -118,6 +126,7 @@ export class DxfIterator {
|
|
|
118
126
|
|
|
119
127
|
/**
|
|
120
128
|
* Format and return the previous value
|
|
129
|
+
* @return {any}
|
|
121
130
|
*/
|
|
122
131
|
prevValue() {
|
|
123
132
|
if (this.currentIndex > 0) {
|
|
@@ -128,6 +137,7 @@ export class DxfIterator {
|
|
|
128
137
|
|
|
129
138
|
/**
|
|
130
139
|
* Format and return the previous groupcode and value pair
|
|
140
|
+
* @return {Array}
|
|
131
141
|
*/
|
|
132
142
|
prevPair() {
|
|
133
143
|
if (this.currentIndex >= 2) {
|
|
@@ -140,13 +150,15 @@ export class DxfIterator {
|
|
|
140
150
|
|
|
141
151
|
/**
|
|
142
152
|
* Format and return the current groupcode and value pair
|
|
153
|
+
* @return {Array}
|
|
143
154
|
*/
|
|
144
155
|
currentPair() {
|
|
145
|
-
return {code: this.current().trim(), value: this.nextValue()};
|
|
156
|
+
return { code: this.current().trim(), value: this.nextValue() };
|
|
146
157
|
}
|
|
147
158
|
|
|
148
159
|
/**
|
|
149
160
|
* Format and return the next groupcode and value pair
|
|
161
|
+
* @return {Array}
|
|
150
162
|
*/
|
|
151
163
|
nextPair() {
|
|
152
164
|
if (this.currentIndex < this.lines.length - 2) {
|
package/core/lib/dxf/dxfRead.js
CHANGED
|
@@ -1,24 +1,35 @@
|
|
|
1
1
|
|
|
2
|
-
import {Header} from './sections/header.js';
|
|
3
|
-
import {Entities} from './sections/entities.js';
|
|
4
|
-
import {Blocks} from './sections/blocks.js';
|
|
5
|
-
import {Tables} from './sections/tables.js';
|
|
6
|
-
import {
|
|
2
|
+
import { Header } from './sections/header.js';
|
|
3
|
+
import { Entities } from './sections/entities.js';
|
|
4
|
+
import { Blocks } from './sections/blocks.js';
|
|
5
|
+
import { Tables } from './sections/tables.js';
|
|
6
|
+
import { Objects } from './sections/objects.js';
|
|
7
|
+
import { DxfIterator } from './dxfIterator.js';
|
|
7
8
|
|
|
9
|
+
/** DXF Reader Class */
|
|
8
10
|
export class DXFReader {
|
|
11
|
+
/** Create DXF Reader */
|
|
9
12
|
constructor() {
|
|
10
13
|
this.iterator = new DxfIterator();
|
|
11
14
|
this.blocks = [];
|
|
12
15
|
this.header = new Header();
|
|
13
16
|
this.entities = [];
|
|
14
17
|
this.tables = [];
|
|
18
|
+
this.objects = [];
|
|
15
19
|
}
|
|
16
20
|
|
|
21
|
+
/**
|
|
22
|
+
* Read
|
|
23
|
+
* @param {string} file
|
|
24
|
+
*/
|
|
17
25
|
read(file) {
|
|
18
26
|
this.iterator.loadFile(file);
|
|
19
27
|
this.parseFile();
|
|
20
28
|
}
|
|
21
29
|
|
|
30
|
+
/**
|
|
31
|
+
* Parse File
|
|
32
|
+
*/
|
|
22
33
|
parseFile() {
|
|
23
34
|
while (this.iterator.nextPair().value !== 'EOF') {
|
|
24
35
|
const currentPair = this.iterator.currentPair();
|
|
@@ -27,7 +38,7 @@ export class DXFReader {
|
|
|
27
38
|
this.header.read(this.iterator);
|
|
28
39
|
break;
|
|
29
40
|
|
|
30
|
-
case (currentPair.value ==='TABLES'):
|
|
41
|
+
case (currentPair.value === 'TABLES'):
|
|
31
42
|
const tables = new Tables();
|
|
32
43
|
this.tables = tables.read(this.iterator);
|
|
33
44
|
break;
|
|
@@ -37,10 +48,15 @@ export class DXFReader {
|
|
|
37
48
|
this.blocks = blocks.read(this.iterator);
|
|
38
49
|
break;
|
|
39
50
|
|
|
40
|
-
case (currentPair.value ==='ENTITIES'):
|
|
51
|
+
case (currentPair.value === 'ENTITIES'):
|
|
41
52
|
const entities = new Entities();
|
|
42
53
|
this.entities = entities.read(this.iterator);
|
|
43
54
|
break;
|
|
55
|
+
|
|
56
|
+
case (currentPair.value === 'OBJECTS'):
|
|
57
|
+
const objects = new Objects();
|
|
58
|
+
this.objects = objects.read(this.iterator);
|
|
59
|
+
break;
|
|
44
60
|
}
|
|
45
61
|
}
|
|
46
62
|
}
|