@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
@@ -0,0 +1,187 @@
1
+ import { DXFFile } from '../lib/dxf/dxfFile.js';
2
+ import { DimStyle } from './dimStyle.js';
3
+ import { StyleManagerBase } from './styleManagerBase.js';
4
+
5
+ /**
6
+ * DimStyleManager Class
7
+ * @extends StyleManagerBase
8
+ */
9
+ export class DimStyleManager extends StyleManagerBase {
10
+ /** Create a DimStyleManager */
11
+ constructor() {
12
+ super();
13
+
14
+ this.indelibleItems.push('STANDARD');
15
+ this.itemProperty = 'dimensionStyle';
16
+ }
17
+
18
+ /** Get the item class */
19
+ get itemClass() {
20
+ return DimStyle;
21
+ }
22
+
23
+ /**
24
+ * Add standard dimension styles
25
+ */
26
+ addStandardItems() {
27
+ this.addItem({
28
+ // Add standard imperial dimension
29
+ 'name': 'STANDARD',
30
+ /*
31
+ Standard Defaults
32
+ 'DIMALTD': 2,
33
+ 'DIMAPOST': '',
34
+ 'DIMALTRND': 0,
35
+ 'DIMALTF': 25.4,
36
+ 'DIMALTTD': 2,
37
+ 'DIMALTTZ': 0,
38
+ 'DIMALTU': 2,
39
+ 'DIMALTMZF': 100,
40
+ 'DIMALTMZS': '',
41
+ 'DIMALTZ': 0,
42
+ 'DIMALT': 0,
43
+ 'DIMAUNIT': 0,
44
+ 'DIMADEC': 0,
45
+ 'DIMAZIN': 0,
46
+ 'DIMARCSYM': 0,
47
+ 'DIMBLK': 'ClosedFilled',
48
+ 'DIMBLK1': 'ClosedFilled',
49
+ 'DIMBLK2': 'ClosedFilled',
50
+ 'DIMASZ': 0.18,
51
+ 'DIMCEN': 0.09,
52
+ 'DIMDSEP': '.',
53
+ 'DIMCLRD': 'BYBLOCK',
54
+ 'DIMDLE': 0,
55
+ 'DIMTOFL': 0,
56
+ 'DIMLTYPE': 'BYBLOCK',
57
+ 'DIMLWD': -2,
58
+ 'DIMDLI': 0.38,
59
+ 'DIMTXTDIRECTION': 0,
60
+ 'DIMLTEX1': 'BYBLOCK',
61
+ 'DIMLTEX2': 'BYBLOCK',
62
+ 'DIMCLRE': 'BYBLOCK',
63
+ 'DIMEXE': 0.18,
64
+ 'DIMLWE': -2,
65
+ 'DIMEXO': 0.0625,
66
+ 'DIMATFIT': 3,
67
+ 'DIMTMOVE': 0,
68
+ 'DIMFXLON': 0,
69
+ 'DIMFXL': 1,
70
+ 'DIMFRAC': 0,
71
+ 'DIMJOGANG': 45,
72
+ 'DIMLDRBLK': 'ClosedFilled',
73
+ 'DIMLFAC': 1,
74
+ 'DIMLUNIT': 2,
75
+ 'DIMSD1': 0,
76
+ 'DIMSD2': 0,
77
+ 'DIMSOXD': 0,
78
+ 'DIMSE1': 0,
79
+ 'DIMSE2': 0,
80
+ 'DIMSCALE': 1,
81
+ 'DIMDEC': 4,
82
+ 'DIMRND': 0,
83
+ 'DIMSAH': 0,
84
+ 'DIMTFILLCLR': 'BYBLOCK',
85
+ 'DIMTFILL': 0,
86
+ 'DIMCLRT': 'BYBLOCK',
87
+ 'DIMTXT': 0.18,
88
+ 'DIMTIX': 0,
89
+ 'DIMTIH': 1,
90
+ 'DIMGAP': 0.09,
91
+ 'DIMTOH': 1,
92
+ 'DIMJUST': 0,
93
+ 'DIMTAD': 0,
94
+ 'DIMPOST': '',
95
+ 'DIMTXSTY': 'Standard',
96
+ 'DIMTM': 0,
97
+ 'DIMTP': 0,
98
+ 'DIMTOL': 0,
99
+ 'DIMLIM': 0,
100
+ 'DIMTOLJ': 1,
101
+ 'DIMTDEC': 4,
102
+ 'DIMTFAC': 1,
103
+ 'DIMTZIN': 0,
104
+ 'DIMMZF': 100,
105
+ 'DIMMZS': '',
106
+ 'DIMZIN': 0,
107
+ */
108
+
109
+ });
110
+
111
+ this.addItem({
112
+ // Add annotative dimension
113
+ // set the properties where they are different to STANDARD dimstyle
114
+ 'name': 'ANNOTATIVE',
115
+ 'DIMALTD': 3,
116
+ 'DIMALTF': 0.0394,
117
+ 'DIMALTTD': 3,
118
+ 'DIMASZ': 2.5,
119
+ 'DIMCEN': 2.5,
120
+ 'DIMDSEP': ',',
121
+ 'DIMTOFL': 1,
122
+ 'DIMDLI': 3.75,
123
+ 'DIMEXE': 1.25,
124
+ 'DIMEXO': 0.625,
125
+ 'DIMSCALE': 0,
126
+ 'DIMDEC': 2,
127
+ 'DIMTXT': 2.5,
128
+ 'DIMTIH': 0,
129
+ 'DIMGAP': 0.625,
130
+ 'DIMTOH': 0,
131
+ 'DIMTAD': 1,
132
+ 'DIMTOLJ': 0,
133
+ 'DIMTDEC': 2,
134
+ 'DIMTZIN': 8,
135
+ 'DIMZIN': 8,
136
+
137
+ });
138
+
139
+ this.addItem({
140
+ // Create standard metric dimension
141
+ // set the properties where they are different to STANDARD dimstyle
142
+ 'name': 'ISO-25',
143
+ 'DIMALTD': 3,
144
+ 'DIMALTF': 0.0394,
145
+ 'DIMALTTD': 3,
146
+ 'DIMASZ': 2.5,
147
+ 'DIMCEN': 2.5,
148
+ 'DIMDSEP': ',',
149
+ 'DIMTOFL': 1,
150
+ 'DIMDLI': 3.75,
151
+ 'DIMEXE': 1.25,
152
+ 'DIMEXO': 0.625,
153
+ 'DIMDEC': 2,
154
+ 'DIMTXT': 2.5,
155
+ 'DIMTIH': 0,
156
+ 'DIMGAP': 0.625,
157
+ 'DIMTOH': 0,
158
+ 'DIMTAD': 1,
159
+ 'DIMTOLJ': 0,
160
+ 'DIMTDEC': 2,
161
+ 'DIMTZIN': 8,
162
+ 'DIMZIN': 8,
163
+ });
164
+
165
+ // DesignCore.scene.saveRequired();
166
+ }
167
+
168
+ /**
169
+ * Write the entity to file in the dxf format
170
+ * @param {DXFFile} file
171
+ */
172
+ dxf(file) {
173
+ // Create table data for dimension styles
174
+ file.writeGroupCode('0', 'TABLE');
175
+ file.writeGroupCode('2', 'DIMSTYLE');
176
+ file.writeGroupCode('5', this.handle, DXFFile.Version.R2000);
177
+ file.writeGroupCode('100', 'AcDbSymbolTable', DXFFile.Version.R2000);
178
+ file.writeGroupCode('100', 'AcDbDimStyleTable', DXFFile.Version.R2000);
179
+ file.writeGroupCode('70', this.itemCount());
180
+
181
+ for (let i = 0; i < this.itemCount(); i++) {
182
+ this.getItemByIndex(i).dxf(file);
183
+ }
184
+
185
+ file.writeGroupCode('0', 'ENDTAB');
186
+ }
187
+ }
@@ -0,0 +1,28 @@
1
+ import { Entity } from '../entities/entity.js';
2
+ import { DXFFile } from '../lib/dxf/dxfFile.js';
3
+
4
+ /**
5
+ * EndBlock Entity Class
6
+ * @extends Entity
7
+ */
8
+ export class EndBlock extends Entity {
9
+ /**
10
+ * Create an EndBlock Entity
11
+ * @param {Array} data
12
+ */
13
+ constructor(data) {
14
+ super(data);
15
+ }
16
+
17
+ /**
18
+ * Write the entity to file in the dxf format
19
+ * @param {DXFFile} file
20
+ */
21
+ dxf(file) {
22
+ file.writeGroupCode('0', 'ENDBLK');
23
+ file.writeGroupCode('5', this.handle, DXFFile.Version.R2000); // Handle
24
+ file.writeGroupCode('100', 'AcDbEntity', DXFFile.Version.R2000);
25
+ // file.writeGroupCode('8', this.layer);
26
+ file.writeGroupCode('100', 'AcDbBlockEnd', DXFFile.Version.R2000);
27
+ }
28
+ }
@@ -0,0 +1,219 @@
1
+ import { Colours } from '../lib/colours.js';
2
+ import { Colour } from '../lib/colour.js';
3
+ import { DXFFile } from '../lib/dxf/dxfFile.js';
4
+ import { Flags } from '../properties/flags.js';
5
+ import { Property } from '../properties/property.js';
6
+
7
+ /** later Class */
8
+ export class Layer {
9
+ /**
10
+ * Create a new Layer
11
+ * @param {Object} data
12
+ */
13
+ constructor(data) {
14
+ // Define Properties
15
+ this.type = 'Layer';
16
+ this.name = '';
17
+ // this.frozen = false;
18
+ this.on = true;
19
+ // this.locked = false;
20
+ // this.trueColour; // undefined - only used when non-aci colours are set
21
+ this.lineType = 'CONTINUOUS';
22
+ this.lineWeight = 'DEFAULT';
23
+ this.plotting = true;
24
+
25
+ Object.defineProperty(this, 'colour', {
26
+ get: this.getColour,
27
+ set: this.setColour,
28
+ });
29
+
30
+ Object.defineProperty(this, 'layerColour', {
31
+ value: new Colour(),
32
+ writable: true,
33
+ });
34
+
35
+ Object.defineProperty(this, 'flags', {
36
+ value: new Flags(),
37
+ writable: true,
38
+ });
39
+
40
+ // DXF Groupcode 5 - Handle
41
+ this.handle = Property.loadValue([data?.handle, data?.[5]]);
42
+ // DXF Groupcode 390 - Plot style name handle
43
+ this.plotStyleHandle = Property.loadValue([data?.plotStyleHandle, data?.[390]], '0');
44
+
45
+ if (data) {
46
+ if (data.hasOwnProperty('name') || data.hasOwnProperty('2')) {
47
+ // DXF Groupcode 2 - Layer Name
48
+ this.name = data.name || data[2];
49
+ }
50
+
51
+ if (data.hasOwnProperty('flags') || data.hasOwnProperty('70')) {
52
+ // DXF Groupcode 70 - Layer Flags
53
+ // Standard flags (bit-coded values):
54
+ // 1 = Layer is frozen; otherwise layer is thawed
55
+ // 2 = Layer is frozen by default in new viewports
56
+ // 4 = Layer is locked
57
+ // 16 = If set, table entry is externally dependent on an xref
58
+ // 32 = If both this bit and bit 16 are set, the externally dependent xref has been successfully resolved
59
+ // 64 = If set, the table entry was referenced by at least one entity in the drawing the last time the drawing was edited.
60
+
61
+ this.flags.setFlagValue(Property.loadValue([data.flags, data[70]], 0));
62
+ }
63
+
64
+ if (data.hasOwnProperty('colour') || data.hasOwnProperty('62')) {
65
+ // DXF Groupcode 62 - Color Number(present if not BYLAYER)(optional);
66
+ // zero indicates the BYBLOCK
67
+ // 256 indicates BYLAYER;
68
+ // A negative value indicates that the layer is turned off
69
+
70
+ if (data.colour) {
71
+ if (Colours.isRGB(data.colour)) {
72
+ this.colour = data.colour;
73
+ }
74
+ } else if (data.hasOwnProperty('62')) {
75
+ this.layerColour.setColourFromACI(Math.abs(data[62]));
76
+ }
77
+ }
78
+
79
+ if (data.hasOwnProperty('lineType') || data.hasOwnProperty('6')) {
80
+ // DXF Groupcode 6 - Linetype Name
81
+ this.lineType = data.lineType || data[6];
82
+ }
83
+
84
+ if (data.hasOwnProperty('lineWeight') || data.hasOwnProperty('370')) {
85
+ // DXF Groupcode 370 - Linetype Weight
86
+ this.lineWeight = data.lineWeight || data[370];
87
+ }
88
+
89
+ if (data.hasOwnProperty('plotting') || data.hasOwnProperty('290')) {
90
+ // DXF Groupcode 290 - Plotting flag
91
+ // If set to 0, do not plot this layer
92
+ this.plotting = data.plotting || data[290];
93
+ }
94
+
95
+ if (data.hasOwnProperty('trueColour') || data.hasOwnProperty('420')) {
96
+ // DXF Groupcode 420 - true color
97
+ // A 24-bit color value that should be dealt with in terms of bytes with values
98
+ // of 0 to 255. The lowest byte is the blue value, the middle byte is the
99
+ // green value, and the third byte is the red value. The top byte is always
100
+ // 0. The group code cannot be used by custom entities for their own data
101
+ // because the group code is reserved for AcDbEntity, class-level color data
102
+ // and AcDbEntity, class-level transparency data
103
+ const trueColour = Colours.trueColourToRGB(Math.abs(data.trueColour || data[420]));
104
+ if (trueColour) {
105
+ this.colour = trueColour;
106
+ }
107
+ }
108
+ }
109
+ }
110
+
111
+ /**
112
+ * Get the frozen value
113
+ * @return {bool}
114
+ */
115
+ get frozen() {
116
+ // Frozen value is bitmasked in flags as value 1
117
+ return this.flags.hasFlag(1);
118
+ }
119
+
120
+ /**
121
+ * Set the frozen value
122
+ * @param {boolean} bool
123
+ */
124
+ set frozen(bool) {
125
+ if (bool) {
126
+ // Add flag
127
+ this.flags.addValue(1);
128
+ } else {
129
+ // remove flag
130
+ this.flags.removeValue(1);
131
+ }
132
+ }
133
+
134
+ /**
135
+ * Get the locked value
136
+ * @return {bool}
137
+ */
138
+ get locked() {
139
+ // locked value is bitmasked in flags as value 4
140
+ return this.flags.hasFlag(4);
141
+ }
142
+
143
+ /**
144
+ * Set the locked value
145
+ * @param {boolean} bool
146
+ */
147
+ set locked(bool) {
148
+ if (bool) {
149
+ // Add flag
150
+ this.flags.addValue(4);
151
+ } else {
152
+ // remove flag
153
+ this.flags.removeValue(4);
154
+ }
155
+ }
156
+
157
+ /**
158
+ * Determine if layer is visible
159
+ * @return {boolean}
160
+ */
161
+ get isVisible() {
162
+ if (this.on && !this.frozen) {
163
+ return true;
164
+ }
165
+
166
+ return false;
167
+ }
168
+
169
+ /**
170
+ * Determine if layer is selectable
171
+ * @return {boolean}
172
+ */
173
+ get isSelectable() {
174
+ if (this.isVisible && !this.locked) {
175
+ return true;
176
+ }
177
+
178
+ return false;
179
+ }
180
+
181
+ /**
182
+ * Get the layer colour
183
+ * @return {number} rgb colour
184
+ */
185
+ getColour() {
186
+ return this.layerColour.getColour();
187
+ }
188
+
189
+ /**
190
+ * Set the layer colour
191
+ * @param {Object} colour - rgb colour
192
+ */
193
+ setColour(colour) {
194
+ this.layerColour.setColour(colour);
195
+ }
196
+
197
+ /**
198
+ * Write the entity to file in the dxf format
199
+ * @param {DXFFile} file
200
+ */
201
+ dxf(file) {
202
+ file.writeGroupCode('0', 'LAYER');
203
+ file.writeGroupCode('5', this.handle, DXFFile.Version.R2000);
204
+ file.writeGroupCode('100', 'AcDbSymbolTableRecord', DXFFile.Version.R2000);
205
+ file.writeGroupCode('100', 'AcDbLayerTableRecord', DXFFile.Version.R2000);
206
+ file.writeGroupCode('2', this.name); // Layername
207
+ file.writeGroupCode('70', this.flags.getFlagValue()); // Flags
208
+ const colourValue = this.on ? this.layerColour.aci : (0 - this.layerColour.aci);
209
+ file.writeGroupCode('62', colourValue); // Colour: Negative if layer is off
210
+ if (this.layerColour.isTrueColour) {
211
+ file.writeGroupCode('420', Colours.rgbToTrueColour(this.colour));
212
+ }
213
+ file.writeGroupCode('6', this.lineType);
214
+ file.writeGroupCode('290', this.plotting ? 1 : 0); // plotting - required to be 0 for defpoints
215
+ file.writeGroupCode('390', this.plotStyleHandle, DXFFile.Version.R2000);
216
+
217
+ // file.writeGroupCode('370', 'this.lineWeight '); // lineWeight | These items codes don't seem to be supported in ACAD.
218
+ }
219
+ }
@@ -0,0 +1,47 @@
1
+ import { DXFFile } from '../lib/dxf/dxfFile.js';
2
+ import { Layer } from './layer.js';
3
+ import { StyleManagerBase } from './styleManagerBase.js';
4
+
5
+ /**
6
+ * LayerManager Class
7
+ * @extends StyleManagerBase
8
+ */
9
+ export class LayerManager extends StyleManagerBase {
10
+ /** Create a LayerManager */
11
+ constructor() {
12
+ super();
13
+
14
+ this.indelibleItems.push('0', 'DEFPOINTS');
15
+ this.itemProperty = 'layer';
16
+ }
17
+
18
+ /** Get the item class */
19
+ get itemClass() {
20
+ return Layer;
21
+ }
22
+
23
+ /** Add standard layers */
24
+ addStandardItems() {
25
+ this.addItem({ 'name': '0' });
26
+ this.addItem({ 'name': 'DEFPOINTS', 'plotting': false });
27
+ }
28
+
29
+ /**
30
+ * Write the entity to file in the dxf format
31
+ * @param {DXFFile} file
32
+ */
33
+ dxf(file) {
34
+ // Create table data for layers
35
+ file.writeGroupCode('0', 'TABLE');
36
+ file.writeGroupCode('2', 'LAYER');
37
+ file.writeGroupCode('5', this.handle, DXFFile.Version.R2000);
38
+ file.writeGroupCode('100', 'AcDbSymbolTable', DXFFile.Version.R2000);
39
+ file.writeGroupCode('70', this.itemCount());
40
+
41
+ for (let i = 0; i < this.itemCount(); i++) {
42
+ this.getItemByIndex(i).dxf(file);
43
+ }
44
+
45
+ file.writeGroupCode('0', 'ENDTAB');
46
+ }
47
+ }
@@ -0,0 +1,85 @@
1
+ import { DXFFile } from '../lib/dxf/dxfFile.js';
2
+ import { Flags } from '../properties/flags.js';
3
+ import { Property } from '../properties/property.js';
4
+
5
+ /** LineType Class */
6
+ export class LType {
7
+ /**
8
+ * Create a Line Type
9
+ * @param {Object} data
10
+ */
11
+ constructor(data) {
12
+ this.type = 'LType';
13
+ this.name = '';
14
+ this.description = '';
15
+ this.pattern = [];
16
+
17
+ Object.defineProperty(this, 'flags', {
18
+ value: new Flags(),
19
+ writable: true,
20
+ });
21
+
22
+ // DXF Groupcode 5 - Handle
23
+ this.handle = Property.loadValue([data?.handle, data?.[5]]);
24
+ // DXF Groupcode 2 - ltype name
25
+ this.name = Property.loadValue([data?.name, data?.[2]], '');
26
+ // DXF Groupcode 3 - description text
27
+ this.description = Property.loadValue([data?.description, data?.[3]], '');
28
+ // DXF Groupcode 49 - line type pattern
29
+ this.pattern = Property.loadValue([data?.pattern, data?.[49]], []);
30
+
31
+ if (data?.hasOwnProperty('73')) {
32
+ // DXF Groupcode 73 - number of line type elements in data[49]
33
+ if (data[73] !== this.pattern.length) {
34
+ throw Error('invalid line type pattern');
35
+ }
36
+ }
37
+
38
+ // DXF Groupcode 70 - Polyline flag (bit-coded; default = 0):
39
+ // 16 = If set, table entry is externally dependent on an xref
40
+ // 32 = If this bit and bit 16 are both set, the externally dependent xref has been successfully resolved
41
+ // 64 = line type was referenced by at least one entity in the drawing the last time the drawing was edited. (This flag can be ignored by most programs)
42
+ this.flags.setFlagValue(Property.loadValue([data?.flags, data?.[70]], 0));
43
+ }
44
+
45
+ /**
46
+ * Get a dash pattern that cairo and html canvas understand
47
+ * @param {Array} scale
48
+ * @return {Array} array for dash pattern
49
+ */
50
+ getPattern(scale) {
51
+ // DXF Patterns use -ve values for gaps and 0.0 for dots
52
+ // cairo and canvas require pattern to include +ve non-zero values
53
+ const pattern = this.pattern.map((x) => (Math.abs(x) + 1) / scale);
54
+ return pattern;
55
+ }
56
+
57
+ /**
58
+ * Write the dxf representation to file
59
+ * @param {DXFFile} file
60
+ */
61
+ dxf(file) {
62
+ file.writeGroupCode('0', 'LTYPE');
63
+ file.writeGroupCode('5', this.handle, DXFFile.Version.R2000);
64
+ file.writeGroupCode('100', 'AcDbSymbolTableRecord', DXFFile.Version.R2000);
65
+ file.writeGroupCode('100', 'AcDbLinetypeTableRecord', DXFFile.Version.R2000);
66
+ file.writeGroupCode('2', this.name);
67
+ file.writeGroupCode('70', this.flags.getFlagValue());
68
+ file.writeGroupCode('3', this.description);
69
+ file.writeGroupCode('72', 65); // Alignment code; value is always 65, the ASCII code for A
70
+ file.writeGroupCode('73', this.pattern.length);
71
+
72
+ let patternLength = 0;
73
+
74
+ if (this.pattern.length) {
75
+ patternLength = this.pattern.reduce((accumulator, patternValue) => accumulator + Math.abs(patternValue));
76
+ }
77
+
78
+ file.writeGroupCode('40', patternLength);
79
+
80
+ for (let i = 0; i < this.pattern.length; i++) {
81
+ file.writeGroupCode('49', this.pattern[i]);
82
+ file.writeGroupCode('74', '0', DXFFile.Version.R2000);
83
+ }
84
+ }
85
+ }
@@ -0,0 +1,65 @@
1
+ import { DXFFile } from '../lib/dxf/dxfFile.js';
2
+ import { StyleManagerBase } from './styleManagerBase.js';
3
+ import { LType } from './ltype.js';
4
+
5
+ /**
6
+ * Line Type Manager Class
7
+ * @extends StyleManagerBase
8
+ */
9
+ export class LTypeManager extends StyleManagerBase {
10
+ /** Create a LTypeManager */
11
+ constructor() {
12
+ super();
13
+
14
+ this.indelibleItems.push('CONTINUOUS', 'ByLayer', 'ByBlock');
15
+ this.itemProperty = 'lineType';
16
+ }
17
+
18
+ /** Get the item class */
19
+ get itemClass() {
20
+ return LType;
21
+ }
22
+
23
+ /** Add standard line types */
24
+ addStandardItems() {
25
+ this.addItem({ 'name': 'CONTINUOUS', 'description': 'Solid Line ________________________________________' });
26
+ this.addItem({ 'name': 'ByLayer' });
27
+ this.addItem({ 'name': 'ByBlock' });
28
+ }
29
+
30
+ /**
31
+ * Get a list of optional line types
32
+ * @return {Array}
33
+ */
34
+ getOptionalStyles() {
35
+ const styles = [];
36
+ styles.push({ 'name': 'CONTINUOUS', 'description': 'Solid Line ________________________________________' });
37
+ styles.push({ 'name': 'CENTER', 'pattern': [31.75, -6.35, 6.35, -6.35], 'description': 'Center ____ _ ____ _ ____ _ ____ _ ____ _ ____' });
38
+ styles.push({ 'name': 'DASHDOT', 'pattern': [12.7, -6.345, 0, -6.345], 'description': 'Dash dot __ . __ . __ . __ . __ . __ . __ . __' });
39
+ styles.push({ 'name': 'DOT', 'pattern': [0, -6.35], 'description': 'Dot . . . . . . . . . . . . . . . . . . . . . .' });
40
+ styles.push({ 'name': 'DASHED', 'pattern': [12.7, -6.35], 'description': 'Dashed __ __ __ __ __ __ __ __ __ __ __ __ __ _' });
41
+ styles.push({ 'name': 'HIDDEN', 'pattern': [6.35, -3.175], 'description': 'Hidden __ __ __ __ __ __ __ __ __ __ __ __ __ _' });
42
+ return styles;
43
+ }
44
+
45
+ /**
46
+ * Write the table to file in the dxf format
47
+ * @param {DXFFile} file
48
+ */
49
+ dxf(file) {
50
+ // Create table data for ltype styles
51
+ // The LTYPE Table must preceed the LAYER table
52
+ file.writeGroupCode('0', 'TABLE');
53
+ file.writeGroupCode('2', 'LTYPE');
54
+ file.writeGroupCode('5', this.handle, DXFFile.Version.R2000);
55
+ file.writeGroupCode('100', 'AcDbSymbolTable', DXFFile.Version.R2000);
56
+ file.writeGroupCode('70', this.itemCount());
57
+
58
+
59
+ for (let i = 0; i < this.itemCount(); i++) {
60
+ this.getItemByIndex(i).dxf(file);
61
+ }
62
+
63
+ file.writeGroupCode('0', 'ENDTAB');
64
+ }
65
+ }