@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.
Files changed (254) hide show
  1. package/.eslintrc.json +14 -7
  2. package/.github/workflows/DesignCoreQA.yml +3 -1
  3. package/README.md +11 -4
  4. package/TODO.md +19 -0
  5. package/core/core/core.js +49 -42
  6. package/core/designCore.js +61 -2
  7. package/core/dimensions/alignedDimension.js +142 -0
  8. package/core/dimensions/angularDimension.js +550 -0
  9. package/core/dimensions/baseCircularDimension.js +244 -0
  10. package/core/dimensions/baseDimension.js +558 -0
  11. package/core/dimensions/baseLinearDimension.js +371 -0
  12. package/core/dimensions/diametricDimension.js +82 -0
  13. package/core/dimensions/dimension.js +298 -0
  14. package/core/dimensions/linearDimension.js +29 -0
  15. package/core/dimensions/radialDimension.js +78 -0
  16. package/core/dimensions/rotatedDimension.js +167 -0
  17. package/core/entities/arc.js +314 -60
  18. package/core/entities/arctext.js +642 -0
  19. package/core/entities/basePolyline.js +553 -94
  20. package/core/entities/circle.js +181 -54
  21. package/core/entities/entity.js +154 -74
  22. package/core/entities/hatch.js +807 -0
  23. package/core/entities/insert.js +200 -39
  24. package/core/entities/line.js +196 -134
  25. package/core/entities/lwpolyline.js +21 -44
  26. package/core/entities/point.js +194 -29
  27. package/core/entities/polyline.js +54 -7
  28. package/core/entities/rectangle.js +43 -13
  29. package/core/entities/solid.js +43 -6
  30. package/core/entities/text.js +324 -181
  31. package/core/lib/boundingBox.js +73 -13
  32. package/core/lib/canvas.js +256 -65
  33. package/core/lib/clipboard.js +198 -0
  34. package/core/lib/colour.js +144 -0
  35. package/core/lib/colours.js +367 -301
  36. package/core/lib/commandLine.js +16 -28
  37. package/core/lib/commandManager.js +115 -58
  38. package/core/lib/constants.js +23 -0
  39. package/core/lib/dxf/dxf.js +249 -34
  40. package/core/lib/dxf/dxfFile.js +23 -38
  41. package/core/lib/dxf/dxfIterator.js +17 -5
  42. package/core/lib/dxf/dxfRead.js +23 -7
  43. package/core/lib/dxf/dxfWrite.js +39 -129
  44. package/core/lib/dxf/handleManager.js +97 -0
  45. package/core/lib/dxf/sections/blocks.js +16 -2
  46. package/core/lib/dxf/sections/entities.js +17 -3
  47. package/core/lib/dxf/sections/header.js +10 -1
  48. package/core/lib/dxf/sections/objects.js +36 -0
  49. package/core/lib/dxf/sections/section.js +43 -5
  50. package/core/lib/dxf/sections/tables.js +17 -3
  51. package/core/lib/entityManager.js +178 -0
  52. package/core/lib/fileio.js +14 -4
  53. package/core/lib/headers.js +229 -0
  54. package/core/lib/input.js +46 -0
  55. package/core/lib/inputManager.js +199 -194
  56. package/core/lib/intersect.js +341 -468
  57. package/core/lib/logging.js +25 -1
  58. package/core/lib/matrix.js +6 -8
  59. package/core/lib/mouse.js +24 -79
  60. package/core/lib/patterns.js +690 -0
  61. package/core/lib/promptOptions.js +133 -0
  62. package/core/lib/scene.js +71 -174
  63. package/core/lib/selectionManager.js +74 -48
  64. package/core/lib/selectionWindow.js +24 -10
  65. package/core/lib/settings.js +18 -11
  66. package/core/lib/snapping.js +129 -21
  67. package/core/lib/stateManager.js +288 -0
  68. package/core/lib/strings.js +57 -5
  69. package/core/lib/utils.js +95 -11
  70. package/core/objects/dictionary.js +43 -0
  71. package/core/objects/dictionaryManager.js +80 -0
  72. package/core/properties/dimType.js +117 -0
  73. package/core/properties/flags.js +66 -0
  74. package/core/properties/property.js +26 -0
  75. package/core/properties/propertyManager.js +65 -19
  76. package/core/tables/appId.js +31 -0
  77. package/core/tables/appIdManager.js +44 -0
  78. package/core/tables/block.js +323 -0
  79. package/core/tables/blockManager.js +48 -0
  80. package/core/tables/blockRecord.js +29 -0
  81. package/core/tables/blockRecordManager.js +37 -0
  82. package/core/tables/dimStyle.js +627 -0
  83. package/core/tables/dimStyleManager.js +187 -0
  84. package/core/tables/endblk.js +28 -0
  85. package/core/tables/layer.js +219 -0
  86. package/core/tables/layerManager.js +47 -0
  87. package/core/tables/ltype.js +85 -0
  88. package/core/tables/ltypeManager.js +65 -0
  89. package/core/tables/style.js +145 -0
  90. package/core/tables/styleManager.js +55 -0
  91. package/core/tables/styleManagerBase.js +110 -0
  92. package/core/tables/tableManagerBase.js +354 -0
  93. package/core/tables/ucs.js +28 -0
  94. package/core/tables/ucsManager.js +44 -0
  95. package/core/tables/view.js +28 -0
  96. package/core/tables/viewManager.js +44 -0
  97. package/core/tables/vport.js +70 -0
  98. package/core/tables/vportManager.js +65 -0
  99. package/core/tools/chamfer.js +343 -0
  100. package/core/tools/chamferFilletBase.js +162 -0
  101. package/core/tools/copy.js +68 -40
  102. package/core/tools/copybase.js +65 -0
  103. package/core/tools/copyclip.js +59 -0
  104. package/core/tools/cornerEntity.js +138 -0
  105. package/core/tools/cutclip.js +72 -0
  106. package/core/tools/distance.js +37 -9
  107. package/core/tools/erase.js +43 -13
  108. package/core/tools/explode.js +117 -0
  109. package/core/tools/extend.js +71 -32
  110. package/core/tools/fillet.js +336 -0
  111. package/core/tools/identify.js +33 -6
  112. package/core/tools/matchProp.js +106 -0
  113. package/core/tools/mirror.js +141 -0
  114. package/core/tools/move.js +65 -32
  115. package/core/tools/offset.js +321 -0
  116. package/core/tools/pan.js +54 -0
  117. package/core/tools/pasteclip.js +93 -0
  118. package/core/tools/purge.js +90 -0
  119. package/core/tools/rotate.js +105 -70
  120. package/core/tools/scale.js +166 -0
  121. package/core/tools/tool.js +14 -4
  122. package/core/tools/trim.js +71 -32
  123. package/core/tools/zoom.js +152 -0
  124. package/package.json +3 -305
  125. package/test/dimensions/alignedDimension.test.js +211 -0
  126. package/test/dimensions/angularDimension.test.js +243 -0
  127. package/test/dimensions/baseDimension.test.js +239 -0
  128. package/test/dimensions/diametricDimension.test.js +203 -0
  129. package/test/dimensions/dimension.test.js +102 -0
  130. package/test/dimensions/radialDimension.test.js +203 -0
  131. package/test/dimensions/rotatedDimension.test.js +224 -0
  132. package/test/entities/arc.test.js +463 -41
  133. package/test/entities/arctext.test.js +329 -0
  134. package/test/entities/basePolyline.test.js +459 -10
  135. package/test/entities/circle.test.js +312 -7
  136. package/test/entities/entity.test.js +28 -9
  137. package/test/entities/hatch.test.js +606 -0
  138. package/test/entities/insert.test.js +90 -0
  139. package/test/entities/line.test.js +182 -6
  140. package/test/entities/point.test.js +375 -37
  141. package/test/entities/solid.test.js +156 -0
  142. package/test/entities/text.test.js +533 -7
  143. package/test/integration/exportIntegration.reference.dxf +1706 -0
  144. package/test/integration/exportIntegration.test.js +186 -0
  145. package/test/integration/importExportIntegration.test.js +126 -0
  146. package/test/integration/intersectionIntegration.test.js +880 -0
  147. package/test/integration/userInputIntegration.reference.dxf +1410 -0
  148. package/test/integration/userInputIntegration.test.js +269 -0
  149. package/test/lib/boundingBox.test.js +26 -2
  150. package/test/lib/canvas.test.js +613 -5
  151. package/test/lib/clipboard.test.js +70 -0
  152. package/test/lib/colour.test.js +114 -0
  153. package/test/lib/colours.test.js +63 -18
  154. package/test/lib/commandLine.test.js +159 -22
  155. package/test/lib/commandManager.test.js +4 -4
  156. package/test/lib/constants.test.js +9 -0
  157. package/test/lib/dxf/dxfFile.test.js +6 -2
  158. package/test/lib/dxf/dxfIterator.test.js +1 -1
  159. package/test/lib/dxf/dxfWrite.test.js +173 -0
  160. package/test/lib/dxf/handleManager.test.js +137 -0
  161. package/test/lib/dxf/sections/blocks.test.js +5 -5
  162. package/test/lib/dxf/sections/entities.test.js +4 -4
  163. package/test/lib/dxf/sections/header.test.js +18 -4
  164. package/test/lib/dxf/sections/objects.test.js +132 -0
  165. package/test/lib/dxf/sections/section.test.js +29 -29
  166. package/test/lib/dxf/sections/tables.test.js +3 -3
  167. package/test/lib/entityManager.test.js +163 -0
  168. package/test/lib/headers.test.js +233 -0
  169. package/test/lib/inputManager.test.js +1144 -5
  170. package/test/lib/intersect.test.js +454 -331
  171. package/test/lib/logging.test.js +1 -1
  172. package/test/lib/matrix.test.js +1 -1
  173. package/test/lib/mouse.test.js +327 -4
  174. package/test/lib/patterns.test.js +105 -0
  175. package/test/lib/promptOptions.test.js +179 -0
  176. package/test/lib/scene.test.js +16 -52
  177. package/test/lib/selectionManager.test.js +17 -5
  178. package/test/lib/settings.test.js +111 -5
  179. package/test/lib/snapping.test.js +142 -4
  180. package/test/lib/stateManager.test.js +155 -0
  181. package/test/lib/utils.test.js +81 -1
  182. package/test/objects/dictionary.test.js +81 -0
  183. package/test/objects/dictionaryManager.test.js +34 -0
  184. package/test/properties/dimType.test.js +62 -0
  185. package/test/properties/flags.test.js +164 -0
  186. package/test/properties/property.test.js +13 -0
  187. package/test/properties/propertyManager.test.js +10 -11
  188. package/test/tables/appId.test.js +46 -0
  189. package/test/tables/appIdManager.test.js +72 -0
  190. package/test/tables/block.test.js +157 -0
  191. package/test/tables/blockManager.test.js +52 -0
  192. package/test/tables/blockRecord.test.js +39 -0
  193. package/test/tables/blockRecordManager.test.js +60 -0
  194. package/test/tables/dimstyle.test.js +72 -0
  195. package/test/tables/endblk.test.js +30 -0
  196. package/test/tables/layer.test.js +95 -0
  197. package/test/tables/layerManager.test.js +172 -0
  198. package/test/{styles → tables}/ltype.test.js +7 -7
  199. package/test/{styles → tables}/ltypeManager.test.js +2 -2
  200. package/test/tables/style.test.js +44 -0
  201. package/test/tables/stylemanagerbase.test.js +220 -0
  202. package/test/tables/tableManagerBase.test.js +194 -0
  203. package/test/tables/ucs.test.js +37 -0
  204. package/test/tables/ucsManager.test.js +48 -0
  205. package/test/tables/view.test.js +37 -0
  206. package/test/tables/viewManager.test.js +48 -0
  207. package/test/tables/vport.test.js +117 -0
  208. package/test/tables/vportManager.test.js +54 -0
  209. package/test/test-helpers/test-helpers.js +66 -0
  210. package/test/tools/chamfer.test.js +970 -0
  211. package/test/tools/chamferFilletBase.test.js +446 -0
  212. package/test/tools/copy.test.js +22 -14
  213. package/test/tools/copybase.test.js +93 -0
  214. package/test/tools/copyclip.test.js +92 -0
  215. package/test/tools/cornerEntity.test.js +201 -0
  216. package/test/tools/cutclip.test.js +94 -0
  217. package/test/tools/distance.test.js +140 -18
  218. package/test/tools/erase.test.js +12 -12
  219. package/test/tools/explode.test.js +45 -0
  220. package/test/tools/extend.test.js +326 -44
  221. package/test/tools/fillet.test.js +831 -0
  222. package/test/tools/identify.test.js +115 -16
  223. package/test/tools/matchProp.test.js +84 -0
  224. package/test/tools/mirror.test.js +475 -0
  225. package/test/tools/move.test.js +75 -19
  226. package/test/tools/offset.test.js +748 -0
  227. package/test/tools/pan.test.js +72 -0
  228. package/test/tools/pasteclip.test.js +100 -0
  229. package/test/tools/purge.test.js +89 -0
  230. package/test/tools/rotate.test.js +89 -23
  231. package/test/tools/scale.test.js +529 -0
  232. package/test/tools/trim.test.js +419 -84
  233. package/test/tools/zoom.test.js +504 -0
  234. package/core/entities/alignedDimension.js +0 -279
  235. package/core/entities/angularDimension.js +0 -194
  236. package/core/entities/baseDimension.js +0 -227
  237. package/core/entities/block.js +0 -247
  238. package/core/entities/diametricDimension.js +0 -133
  239. package/core/entities/dimension.js +0 -202
  240. package/core/entities/radialDimension.js +0 -126
  241. package/core/styles/dimStyle.js +0 -719
  242. package/core/styles/dimStyleManager.js +0 -47
  243. package/core/styles/layer.js +0 -133
  244. package/core/styles/layerManager.js +0 -40
  245. package/core/styles/ltype.js +0 -86
  246. package/core/styles/ltypeManager.js +0 -50
  247. package/core/styles/style.js +0 -158
  248. package/core/styles/styleManager.js +0 -43
  249. package/core/styles/styleManagerBase.js +0 -299
  250. package/test/entities/block.test.js +0 -22
  251. package/test/styles/dimstyle.test.js +0 -19
  252. package/test/styles/layerManager.test.js +0 -150
  253. package/test/styles/style.test.js +0 -33
  254. package/test/styles/stylemanagerbase.test.js +0 -219
@@ -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 last to ensure the elements and layers exist
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.addStyle(layer, true);
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.addStyle(ltype, true);
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.addStyle(style, true);
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.addStyle(style, true);
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
- this.addItem(block);
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.Scene.addItem(command, item);
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) => {
@@ -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
- constructor(version='R2018') {
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
- * @returns boolean - true if version is valid
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
- * @returns boolean - true if version is valid
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 {*} dxfVersion
45
- * @returns dxf key (R Number) for valid dxf versions
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 {String} groupCode
109
- * @param {String} groupValue
110
- * @param {String} version - DXFFile.Version
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 {String} value
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 {String} file
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 {String} msg - error message
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 {String} value
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) {
@@ -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 {DxfIterator} from './dxfIterator.js';
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
  }