@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,627 @@
1
+
2
+ import { DXFFile } from '../lib/dxf/dxfFile.js';
3
+ import { Logging } from '../lib/logging.js';
4
+ import { Flags } from '../properties/flags.js';
5
+ import { Property } from '../properties/property.js';
6
+
7
+ /** DimStyle Class */
8
+ export class DimStyle {
9
+ /**
10
+ * Create a DimStyle
11
+ * @param {Object} data
12
+ */
13
+ constructor(data) {
14
+ // Define Properties
15
+ this.type = this.constructor.name;
16
+ this.standardFlags = new Flags();
17
+
18
+ // Add DIMCEN property with getter and setter
19
+ Object.defineProperty(this, 'DIMCEN', {
20
+ get: this.getDimcen,
21
+ set: this.setDimcen,
22
+ });
23
+
24
+ // Add two internal properties to manage the DIMCEN value
25
+ this.DIMCENSTYL = 1; // internal - Controls the DIMCEN style
26
+ this.DIMCENVALUE = 0.09;// internal - Holds the DIMCEN value
27
+
28
+
29
+ /*
30
+ The following properties are not implemented
31
+ DIMALTRND - R2000
32
+ DIMANNO - R2008
33
+ DIMARCSYM - R2007
34
+ DIMASSOC - 2002
35
+ DIMASO - OBSOLETE
36
+ DIMCONSTRAINTICON - R2010
37
+ DIMFXL - R2007
38
+ DIMFXLON - R2007
39
+ DIMJOGANG - R2007
40
+ DIMLTEX1 - R2007
41
+ DIMLTEX2 - R2007
42
+ DIMLTYPE - R2007
43
+ DIMSHO - OBSOLETE
44
+ DIMTFILL - R2007
45
+ DIMTFILLCLR - R2007
46
+ DIMTXTDIRECTION - R2010
47
+ */
48
+
49
+ // DXF Groupcode 105 - Handle (DIMSTYLE uses 105 instead of 5)
50
+ this.handle = Property.loadValue([data.handle, data[105]]);
51
+
52
+ // DXF Groupcode 2 - ltype name
53
+ this.name = Property.loadValue([data.name, data[2]], 'DimStyle');
54
+
55
+ // DXF Groupcode 3 - General dimensioning suffix
56
+ this.DIMPOST = Property.loadValue([data.DIMPOST, data[3]], '');
57
+
58
+ // DXF Groupcode 4 - Alternate dimensioning suffix
59
+ this.DIMAPOST = Property.loadValue([data.DIMAPOST, data[4]], '');
60
+
61
+ if (data.hasOwnProperty('DIMBLK') || data.hasOwnProperty('5')) {
62
+ // DXF Groupcode 5 - Arrow block name
63
+ const err = 'DXF Groupcode 5 - obsolete';
64
+ Logging.instance.warn(`${this.type} - ${err}`);
65
+ }
66
+ this.DIMBLK = Property.loadValue([data.DIMBLK, data[5]], 'CloseFilled');
67
+
68
+ if (data.hasOwnProperty('DIMBLK1') || data.hasOwnProperty('6')) {
69
+ // DXF Groupcode 6 - First arrow block name
70
+ const err = 'DXF Groupcode 6 - obsolete';
71
+ Logging.instance.warn(`${this.type} - ${err}`);
72
+ }
73
+ this.DIMBLK1 = Property.loadValue([data.DIMBLK1, data[6]], 'CloseFilled');
74
+
75
+ if (data.hasOwnProperty('DIMBLK2') || data.hasOwnProperty('7')) {
76
+ // DXF Groupcode 7 - Second arrow block name
77
+ const err = 'DXF Groupcode 7 - obsolete';
78
+ Logging.instance.warn(`${this.type} - ${err}`);
79
+ }
80
+ this.DIMBLK2 = Property.loadValue([data.DIMBLK2, data[7]], 'CloseFilled');
81
+
82
+ // DXF Groupcode 40 - dimension scale
83
+ /*
84
+ Sets the overall scale factor applied to dimensioning variables that specify sizes, distances, or offsets.
85
+ Also affects the leader objects with the LEADER command.
86
+ Use MLEADERSCALE to scale multileader objects created with the MLEADER command.
87
+ 0.0 = A reasonable default value is computed based on the scaling between the current model space viewport and paper space.
88
+ If you are in paper space or model space and not using the paper space feature, the scale factor is 1.0.
89
+ >0 = A scale factor is computed that leads text sizes, arrowhead sizes, and other scaled distances to plot at their face values.
90
+
91
+ DIMSCALE does not affect measured lengths, coordinates, or angles.
92
+ Use DIMSCALE to control the overall scale of dimensions.
93
+ However, if the current dimension style is annotative, DIMSCALE is automatically set to zero and the dimension scale is controlled by the CANNOSCALE system variable.
94
+ DIMSCALE cannot be set to a non-zero value when using annotative dimensions.
95
+ */
96
+ this.DIMSCALE = Property.loadValue([data.DIMSCALE, data[40]], 1);
97
+
98
+ // DXF Groupcode 41 - arrow size
99
+ this.DIMASZ = Property.loadValue([data.DIMASZ, data[41]], 0.18);
100
+
101
+ // DXF Groupcode 42 - offset from origin
102
+ this.DIMEXO = Property.loadValue([data.DIMEXO, data[42]], 0.0625);
103
+
104
+ // DXF Groupcode 43 - Baseline spacing
105
+ this.DIMDLI = Property.loadValue([data.DIMDLI, data[43]], 0.38);
106
+
107
+ // DXF Groupcode 44- extend beyond dim lines
108
+ this.DIMEXE = Property.loadValue([data.DIMEXE, data[44]], 0.18);
109
+
110
+ // DXF Groupcode 45 - Rounding value for dimension distances
111
+ // DIMRND set to 0.25, all distances round to the nearest 0.25.
112
+ // Note that the number of digits edited after the decimal point depends on the precision set by DIMDEC.
113
+ // DIMRND does not apply to angular dimensions.
114
+ this.DIMRND = Property.loadValue([data.DIMRND, data[45]], 0.0000);
115
+
116
+ // DXF Groupcode 46 - Dimension line extension
117
+ this.DIMDLE = Property.loadValue([data.DIMDLE, data[46]], 1);
118
+
119
+ // DXF Groupcode 47 - Plus tolerance
120
+ this.DIMTP = Property.loadValue([data.DIMTP, data[47]], 1);
121
+
122
+ // DXF Groupcode 48 - Minus tolerance
123
+ this.DIMTM = Property.loadValue([data.DIMTM, data[48]], 1);
124
+
125
+ // DXF Groupcode 140 - Dimensioning text height
126
+ this.DIMTXT = Property.loadValue([data.DIMTXT, data[140]], 0.18);
127
+
128
+ // DXF Groupcode 141 - centre marks
129
+ this.DIMCEN = Property.loadValue([data.DIMCEN, data[141]], 0.09);
130
+
131
+ // DXF Groupcode 142 - Dimensioning tick size; 0 = no ticks
132
+ // 0 = use arrow heads
133
+ // >0 = Draws oblique strokes instead of arrowheads. The size of the oblique strokes is determined by this value multiplied by the DIMSCALE value.
134
+ this.DIMTSZ = Property.loadValue([data.DIMTSZ, data[142]], 0);
135
+
136
+ // DXF Groupcode 143 - multiplier for alternate units
137
+ this.DIMALTF = Property.loadValue([data.DIMALTF, data[143]], 25.4);
138
+
139
+ // DXF Groupcode 144 - Measurement scale factor
140
+ this.DIMLFAC = Property.loadValue([data.DIMLFAC, data[144]], 1);
141
+
142
+ // DXF Groupcode 145 - Text vertical position
143
+ // The DIMTVP value is used when DIMTAD is off.
144
+ // The magnitude of the vertical offset of text is the product of the text height and DIMTVP.
145
+ // Setting DIMTVP to 1.0 is equivalent to setting DIMTAD to on.
146
+ // The dimension line splits to accommodate the text only if the absolute value of DIMTVP is less than 0.7.
147
+ this.DIMTVP = Property.loadValue([data.DIMTVP, data[145]], 0);
148
+
149
+ // DXF Groupcode 146 - Dimension tolerance display scale factor
150
+ this.DIMTFAC = Property.loadValue([data.DIMTFAC, data[146]], 1);
151
+
152
+ // DXF Groupcode 147 - offset from dimline
153
+ // The value of DIMGAP is also used as the minimum length of each segment of the dimension line.
154
+ // To locate the components of a linear dimension within the extension lines, enough space must be available for both arrowheads (2 x DIMASZ),
155
+ // both dimension line segments (2 x DIMGAP), a gap on either side of the dimension text (another 2 x DIMGAP), and the length of the dimension text,
156
+ // which depends on its size and number of decimal places displayed
157
+ this.DIMGAP = Property.loadValue([data.DIMGAP, data[147]], 0.09);
158
+
159
+ // DXF Groupcode 70 - standard flags
160
+ /*
161
+ 1 = If set, this entry describes a shape
162
+ 4 = Vertical text
163
+ 16 = If set, table entry is externally dependent on an xref
164
+ 32 = If this bit and bit 16 are both set, the externally dependent xref has been successfully resolved
165
+ 64 = If set, the table entry was referenced by at least one entity in the drawing the last time the drawing was edited.
166
+ This flag is for the benefit of AutoCAD commands. It can be ignored.
167
+ */
168
+ this.standardFlags.setFlagValue(Property.loadValue([data.standardFlags, data[70]], 0));
169
+
170
+ // DXF Groupcode 71 - Dimension tolerances generated if nonzero
171
+ // Setting DIMTOL to on (1) turns DIMLIM off (0)
172
+ this.DIMTOL = Property.loadValue([data.DIMTOL, data[71]], 0);
173
+
174
+ // DXF Groupcode 72 - Dimension limits generated if nonzero
175
+ // 0 = Dimension limits are not generated as default text
176
+ // 1 = Dimension limits are generated as default text
177
+ // Setting DIMLIM to on (1) turns DIMTOL off (0)
178
+ this.DIMLIM = Property.loadValue([data.DIMLIM, data[72]], 0);
179
+
180
+ // DXF Groupcode 73 - Text inside horizontal if nonzero
181
+ // 0 = Aligns text with the dimension line
182
+ // 1 = Draws text horizontally
183
+ this.DIMTIH = Property.loadValue([data.DIMTIH, data[73]], 1);
184
+
185
+ // DXF Groupcode 74 - Text outside horizontal if nonzero
186
+ // 0 = Aligns text with the dimension line
187
+ // 1 = Draws text horizontally
188
+ this.DIMTOH = Property.loadValue([data.DIMTOH, data[74]], 1);
189
+
190
+ // DXF Groupcode 75 - First extension line suppressed if nonzero
191
+ this.DIMSE1 = Boolean(Property.loadValue([data.DIMSE1, data[75]], 0));
192
+
193
+ // DXF Groupcode 76 - Second extension line suppressed if nonzero
194
+ this.DIMSE2 = Boolean(Property.loadValue([data.DIMSE2, data[76]], 0));
195
+
196
+ // DXF Groupcode 77 -Text above dimension line if nonzero
197
+ // 0 = Centers the dimension text between the extension lines.
198
+ // 1 = Places the dimension text above the dimension line except when the dimension line is not horizontal and text inside the extension lines is forced horizontal ( DIMTIH = 1). The distance from the dimension line to the baseline of the lowest line of text is the current DIMGAP value.
199
+ // 2 = Places the dimension text on the side of the dimension line farthest away from the defining points.
200
+ // 3 = Places the dimension text to conform to Japanese Industrial Standards (JIS).
201
+ // 4 = Places the dimension text below the dimension line.
202
+ this.DIMTAD = Property.loadValue([data.DIMTAD, data[77]], 0);
203
+
204
+ // DXF Groupcode 78 - Zero suppression for linear dimensions
205
+ /*
206
+ Values 0-3 affect feet-and-inch dimensions only:
207
+ 0 = Suppresses zero feet and precisely zero inches
208
+ 1 = Includes zero feet and precisely zero inches
209
+ 2 = Includes zero feet and suppresses zero inches
210
+ 3 = Includes zero inches and suppresses zero feet
211
+ 4 = Suppresses leading zeros in decimal dimensions (for example, 0.5000 becomes .5000)
212
+ 8 = Suppresses trailing zeros in decimal dimensions (for example, 12.5000 becomes 12.5)
213
+ 12 = Suppresses both leading and trailing zeros (for example, 0.5000 becomes .5)
214
+ */
215
+ this.DIMZIN = Property.loadValue([data.DIMZIN, data[78]], 0);
216
+
217
+
218
+ // DXF Groupcode 79 - Zero suppression for angular dimensions:
219
+ // 0 = Displays all leading and trailing zeros
220
+ // 1 = Suppresses leading zeros in decimal dimensions
221
+ // 2 = Suppresses trailing zeros in decimal dimensions
222
+ // 3 = Suppresses leading and trailing zeros
223
+ this.DIMAZIN = Property.loadValue([data.DIMAZIN, data[79]], 0);
224
+
225
+ // DXF Groupcode 170 - Alternate unit dimensioning performed if nonzero
226
+ this.DIMALT = Property.loadValue([data.DIMALT, data[170]], 0);
227
+
228
+ // DXF Groupcode 171 - Alternate unit decimal places
229
+ // If DIMALT is turned on, DIMALTD sets the number of digits displayed to the right of the decimal point in the alternate measurement.
230
+ this.DIMALTD = Property.loadValue([data.DIMALTD, data[171]], 2);
231
+
232
+ // DXF Groupcode 172 - If text outside extensions, force line extensions between extensions if nonzero
233
+ this.DIMTOFL = Boolean(Property.loadValue([data.DIMTOFL, data[172]], 0));
234
+
235
+ // DXF Groupcode 173 - Use separate arrow blocks if nonzero
236
+ /*
237
+ Off = Use arrowhead blocks set by DIMBLK
238
+ On = Use arrowhead blocks set by DIMBLK1 and DIMBLK2
239
+ */
240
+ this.DIMSAH = Property.loadValue([data.DIMSAH, data[173]], 0);
241
+
242
+ // DXF Groupcode 174 - Force text inside extensions if nonzero
243
+ /*
244
+ Off = Varies with the type of dimension.
245
+ For linear and angular dimensions, text is placed inside the extension lines if there is sufficient room.
246
+ For radius and diameter dimensions that don’t fit inside the circle or arc, DIMTIX has no effect and always forces the text outside the circle or arc.
247
+ On = Draws dimension text between the extension lines even if it would ordinarily be placed outside those lines
248
+ */
249
+ this.DIMTIX = Property.loadValue([data.DIMTIX, data[174]], 0);
250
+
251
+ // DXF Groupcode 175 - Suppress outside-extensions dimension lines if nonzero
252
+ /*
253
+ If not enough space is available inside the extension lines and DIMTIX is on, setting DIMSOXD to On suppresses the arrowheads.
254
+ If DIMTIX is off, DIMSOXD has no effect
255
+
256
+ Off = Arrowheads are not suppressed
257
+ On = Arrowheads are suppressed
258
+ */
259
+ this.DIMSOXD = Property.loadValue([data.DIMSOXD, data[175]], 0);
260
+
261
+ // DXF Groupcode 176 - Dimension line color, range is 0 = BYBLOCK, 256 = BYLAYER
262
+ this.DIMCLRD = Property.loadValue([data.DIMCLRD, data[176]], 0);
263
+
264
+ // DXF Groupcode 177 - Dimension extension line color, range is 0 = BYBLOCK, 256 = BYLAYER
265
+ this.DIMCLRE = Property.loadValue([data.DIMCLRE, data[177]], 0);
266
+
267
+ // DXF Groupcode 178 - Dimension text color, range is 0 = BYBLOCK, 256 = BYLAYER
268
+ this.DIMCLRT = Property.loadValue([data.DIMCLRT, data[178]], 0);
269
+
270
+ // DXF Groupcode 179 - Number of precision places displayed in angular dimensions
271
+ this.DIMADEC = Property.loadValue([data.DIMADEC, data[179]], 0);
272
+
273
+ if (data.hasOwnProperty('DIMUNIT') || data.hasOwnProperty('270')) {
274
+ // DXF Groupcode 270 - (obsolete, now use DIMLUNIT AND DIMFRAC)
275
+ const err = `obsolete group code - 270`;
276
+ Logging.instance.warn(`${this.type} - ${err}`);
277
+ }
278
+ this.DIMUNIT = Property.loadValue([data.DIMUNIT, data[270]], 0);
279
+
280
+ // DXF Groupcode 271 - Number of decimal places displayed for the primary units of a dimension.
281
+ // The precision is based on the units or angle format you have selected.
282
+ // Specified value is applied to angular dimensions when DIMADEC is set to -1.
283
+ this.DIMDEC = Property.loadValue([data.DIMDEC, data[271]], 4);
284
+
285
+ // DXF Groupcode 272 - Number of decimal places to display the tolerance values
286
+ // This system variable has no effect unless DIMTOL is set to On. The default for DIMTOL is Off
287
+ this.DIMTDEC = Property.loadValue([data.DIMTDEC, data[272]], 4);
288
+
289
+ // DXF Groupcode 273 - Units format for alternate units of all dimension style family members except angular:
290
+ // 1 = Scientific; 2 = Decimal; 3 = Engineering;
291
+ // 4 = Architectural (stacked); 5 = Fractional (stacked);
292
+ // 6 = Architectural; 7 = Fractional
293
+ this.DIMALTU = Property.loadValue([data.DIMALTU, data[273]], 2);
294
+
295
+ // DXF Groupcode 274 - Number of decimal places for tolerance values of an alternate units dimension
296
+ this.DIMALTTD = Property.loadValue([data.DIMALTTD, data[274]], 2);
297
+
298
+ // DXF Groupcode 275 - Angle format for angular dimensions:
299
+ // 0 = Decimal degrees; 1 = Degrees/minutes/seconds;
300
+ // 2 = Gradians; 3 = Radians; 4 = Surveyor’s units
301
+ this.DIMAUNIT = Property.loadValue([data.DIMAUNIT, data[275]], 0);
302
+
303
+ // DXF Groupcode 276 - Fraction format when DIMLUNIT is set to 4 (Architectural) or 5 (Fractional).
304
+ this.DIMFRAC = Property.loadValue([data.DIMFRAC, data[276]], 0);
305
+
306
+ // DXF Groupcode 277 - Sets units for all dimension types except Angular:
307
+ // 1 = Scientific; 2 = Decimal; 3 = Engineering;
308
+ // 4 = Architectural; 5 = Fractional; 6 = Windows desktop
309
+ this.DIMLUNIT = Property.loadValue([data.DIMLUNIT, data[277]], 2);
310
+
311
+ // DXF Groupcode 278 - Single-character decimal separator used when creating dimensions whose unit format is decimal
312
+ // Period - ?
313
+ // Comma - 44
314
+ // Space - 32
315
+ this.DIMDSEP = Property.loadValue([data.DIMDSEP, data[278]], '.');
316
+
317
+ // DXF Groupcode 279 - Dimension text movement rules:
318
+ // 0 = Moves the dimension line with dimension text
319
+ // 1 = Adds a leader when dimension text is moved
320
+ // 2 = Allows text to be moved freely without a leader
321
+ this.DIMTMOVE = Property.loadValue([data.DIMTMOVE, data[279]], 0);
322
+
323
+ // DXF Groupcode 280 - Horizontal dimension text position:
324
+ // 0 = Above dimension line and center-justified between extension lines
325
+ // 1 = Above dimension line and next to first extension line
326
+ // 2 = Above dimension line and next to second extension line
327
+ // 3 = Above and center-justified to first extension line
328
+ // 4 = Above and center-justified to second extension line
329
+ this.DIMJUST = Property.loadValue([data.DIMJUST, data[280]], 0);
330
+
331
+ // DXF Groupcode 281 - Suppression of first extension line:
332
+ // 0 = Not suppressed; 1 = Suppressed
333
+ this.DIMSD1 = Property.loadValue([data.DIMSD1, data[281]], 0);
334
+
335
+ // DXF Groupcode 282 - Suppression of second extension line:
336
+ // 0 = Not suppressed; 1 = Suppressed
337
+ this.DIMSD2 = Property.loadValue([data.DIMSD2, data[282]], 0);
338
+
339
+ // DXF Groupcode 283 - Vertical justification for tolerance values:
340
+ // 0 = Top; 1 = Middle; 2 = Bottom
341
+ this.DIMTOLJ = Property.loadValue([data.DIMTOLJ, data[283]], 1);
342
+
343
+ // DXF Groupcode 284 - Controls suppression of zeros for tolerance values:
344
+ // 0 = Suppresses zero feet and precisely zero inches
345
+ // 1 = Includes zero feet and precisely zero inches
346
+ // 2 = Includes zero feet and suppresses zero inches
347
+ // 3 = Includes zero inches and suppresses zero feet
348
+ this.DIMTZIN = Property.loadValue([data.DIMTZIN, data[284]], 1);
349
+
350
+ // DXF Groupcode 285 - Controls suppression of zeros for alternate unit dimension values:
351
+ // 0 = Suppresses zero feet and precisely zero inches
352
+ // 1 = Includes zero feet and precisely zero inches
353
+ // 2 = Includes zero feet and suppresses zero inches
354
+ // 3 = Includes zero inches and suppresses zero feet
355
+ this.DIMALTZ = Property.loadValue([data.DIMALTZ, data[285]], 0);
356
+
357
+ // DXF Groupcode 286 - Controls suppression of zeros for alternate tolerance values:
358
+ // 0 = Suppresses zero feet and precisely zero inches
359
+ // 1 = Includes zero feet and precisely zero inches
360
+ // 2 = Includes zero feet and suppresses zero inches
361
+ // 3 = Includes zero inches and suppresses zero feet
362
+ this.DIMALTTZ = Property.loadValue([data.DIMALTTZ, data[286]], 0);
363
+
364
+
365
+ if (data.hasOwnProperty('DIMFIT') || data.hasOwnProperty('287')) {
366
+ // DXF Groupcode 287 - (obsolete, now use DIMATFIT and DIMTMOVE)
367
+ const err = `obsolete group code - 287`;
368
+ Logging.instance.warn(`${this.type} - ${err}`);
369
+ }
370
+ this.DIMFIT = Property.loadValue([data.DIMFIT, data[287]], 0);
371
+
372
+ // DXF Groupcode 288 - Cursor functionality for user-positioned text:
373
+ // 0 = Controls only the dimension line location
374
+ // 1 = Controls the text position as well as the dimension line location
375
+ this.DIMUPT = Property.loadValue([data.DIMUPT, data[288]], 0);
376
+
377
+ // DXF Groupcode 289 - Controls dimension text and arrow placement when space is not sufficient to place both within the extension lines:
378
+ // 0 = Places both text and arrows outside extension lines
379
+ // 1 = Moves arrows first, then text
380
+ // 2 = Moves text first, then arrows
381
+ // 3 = Moves either text or arrows, whichever fits best AutoCAD adds a leader to moved dimension text when DIMTMOVE is set to 1
382
+ this.DIMATFIT = Property.loadValue([data.DIMATFIT, data[289]], 3);
383
+
384
+ // DXF Groupcode 340 - (handle of referenced STYLE)
385
+ this.DIMTXSTY = Property.loadValue([data.DIMTXSTY, data[340]], 'Standard');
386
+
387
+ // DXF Groupcode 341 - (handle of referenced BLOCK)
388
+ this.DIMLDRBLK = Property.loadValue([data.DIMLDRBLK, data[341]], 'ClosedFilled');
389
+
390
+ // DXF Groupcode 342 - (handle of referenced BLOCK)
391
+ /*
392
+ “” = closed filled
393
+ “_DOT” = dot
394
+ “_DOTSMALL” = dot small
395
+ “_DOTBLANK”= dot blank
396
+ “_ORIGIN” = origin indicator
397
+ “_ORIGIN2” = origin indicator 2
398
+ “_OPEN” = open
399
+ “_OPEN90” = right angle
400
+ “_OPEN30” = open 30
401
+ “_CLOSED” = closed
402
+ “_SMALL” = dot small blank
403
+ “_NONE” = none
404
+ “_OBLIQUE” = oblique
405
+ “_BOXFILLED” = box filled
406
+ “_BOXBLANK” = box
407
+ “_CLOSEDBLANK” = closed blank
408
+ “_DATUMFILLED” = datum triangle filled
409
+ “_DATUMBLANK” = datum triangle
410
+ “_INTEGRAL” = integral
411
+ “_ARCHTICK” = architectural tick
412
+ */
413
+ // this.DIMBLK = Property.loadValue([data.DIMBLK, data[342]], '');
414
+
415
+ // DXF Groupcode 343 - (handle of referenced BLOCK)
416
+ // this.DIMBLK1 = Property.loadValue([data.DIMBLK1, data[343]], '');
417
+
418
+ // DXF Groupcode 344 - (handle of referenced BLOCK)
419
+ // this.DIMBLK2 = Property.loadValue([data.DIMBLK2, data[344]], '');
420
+
421
+ // DXF Groupcode 371 - (lineweight enum value)
422
+ /*
423
+ -3 Default (the LWDEFAULT value)
424
+ -2 BYBLOCK
425
+ -1 BYLAYER
426
+ */
427
+ this.DIMLWD = Property.loadValue([data.DIMLWD, data[371]], -2);
428
+
429
+
430
+ // DXF Groupcode 372 - (lineweight enum value)
431
+ /*
432
+ -3 Default (the LWDEFAULT value)
433
+ -2 BYBLOCK
434
+ -1 BYLAYER
435
+ */
436
+ this.DIMLWE = Property.loadValue([data.DIMLWE, data[372]], -2);
437
+ }
438
+
439
+ /**
440
+ * Get valueName property value from dimstyle
441
+ * @param {string} valueName
442
+ * @return {any} value or undefined
443
+ */
444
+ getValue(valueName) {
445
+ if (this.hasOwnProperty(valueName)) {
446
+ if (typeof this[valueName] === 'boolean') {
447
+ return this[valueName] ? 1 : 0;
448
+ }
449
+
450
+ // if a value contains only digits, return it as a number
451
+ if (/^\d+$/.test(this[valueName])) {
452
+ // Ensure a number value is returned
453
+ return Number(this[valueName]);
454
+ } else {
455
+ return this[valueName];
456
+ }
457
+ }
458
+
459
+ const err = `Getting Value - ${valueName}`;
460
+ Logging.instance.warn(`${this.type} - ${err}`);
461
+ return;
462
+ }
463
+
464
+ /**
465
+ * Set a property value by name
466
+ * @param {string} valueName
467
+ * @param {any} value
468
+ */
469
+ setValue(valueName, value) {
470
+ if (typeof valueName !== 'string' || valueName.length === 0) {
471
+ const err = `Setting Value - Invalid property name: ${valueName}`;
472
+ Logging.instance.warn(`${this.type} - ${err}`);
473
+ return;
474
+ }
475
+
476
+ if (this.hasOwnProperty(valueName)) {
477
+ this[valueName] = value;
478
+ } else {
479
+ const err = `Setting Value - Property does not exist: ${valueName}`;
480
+ Logging.instance.warn(`${this.type} - ${err}`);
481
+ }
482
+ }
483
+
484
+
485
+ /**
486
+ * Get the vertical value
487
+ * @return {bool}
488
+ */
489
+ get vertical() {
490
+ // Vertical value is bitmasked in standardflags as value 4
491
+ return this.standardFlags.hasFlag(4);
492
+ }
493
+
494
+ /**
495
+ * Set the vertical value
496
+ * @param {boolean} bool
497
+ */
498
+ set vertical(bool) {
499
+ if (bool) {
500
+ // Add flag
501
+ this.standardFlags.addValue(4);
502
+ } else {
503
+ // remove flag
504
+ this.standardFlags.removeValue(4);
505
+ }
506
+ }
507
+
508
+ /**
509
+ * get the DIMCEN property for the center mark size
510
+ * @return {Number} DIMCEN value
511
+ * This uses two internal values to define the DIMCEN property
512
+ * DIMCENSTYL & DIMCENVALUE
513
+ * DIMCEN has 3 states:
514
+ * - Less than zero = Line Mode (Extended Cross)
515
+ * - Zero = Off
516
+ * - Greater than zero = Mark mode (Cross)
517
+ */
518
+ getDimcen() {
519
+ switch (this.DIMCENSTYL) {
520
+ case 0:
521
+ return 0;
522
+ case 1:
523
+ return Math.abs(this.DIMCENVALUE);
524
+ case 2:
525
+ return 0 - Math.abs(this.DIMCENVALUE);
526
+ default:
527
+ return 0;
528
+ }
529
+ }
530
+
531
+ /**
532
+ * set the DIMCEN value for the centre mark size
533
+ * @param {String} value
534
+ */
535
+ setDimcen(value) {
536
+ if (value === 0) {
537
+ this.DIMCENSTYL = 0;
538
+ } else if (value > 0) {
539
+ this.DIMCENSTYL = 1;
540
+ } else if (value < 0) {
541
+ this.DIMCENSTYL = 2;
542
+ }
543
+
544
+ this.DIMCENVALUE = Math.abs(value);
545
+ }
546
+
547
+ /**
548
+ * Write the entity to file in the dxf format
549
+ * @param {DXFFile} file
550
+ */
551
+ dxf(file) {
552
+ file.writeGroupCode('0', 'DIMSTYLE');
553
+ file.writeGroupCode('105', this.handle, DXFFile.Version.R2000); // Handle
554
+ file.writeGroupCode('100', 'AcDbSymbolTableRecord', DXFFile.Version.R2000);
555
+ file.writeGroupCode('100', 'AcDbDimStyleTableRecord', DXFFile.Version.R2000);
556
+ file.writeGroupCode('2', this.name); // Stylename
557
+ file.writeGroupCode('70', this.standardFlags.getFlagValue());
558
+ file.writeGroupCode('3', this.DIMPOST);
559
+ file.writeGroupCode('4', this.DIMAPOST);
560
+ file.writeGroupCode('5', this.DIMBLK);
561
+ file.writeGroupCode('6', this.DIMBLK1);
562
+ file.writeGroupCode('7', this.DIMBLK2);
563
+ file.writeGroupCode('40', this.DIMSCALE);
564
+ file.writeGroupCode('41', this.DIMASZ);
565
+ file.writeGroupCode('42', this.DIMEXO);
566
+ file.writeGroupCode('43', this.DIMDLI);
567
+ file.writeGroupCode('44', this.DIMEXE);
568
+ file.writeGroupCode('45', this.DIMRND);
569
+ file.writeGroupCode('46', this.DIMDLE);
570
+ file.writeGroupCode('47', this.DIMTP);
571
+ file.writeGroupCode('48', this.DIMTM);
572
+ file.writeGroupCode('140', this.DIMTXT);
573
+ file.writeGroupCode('141', this.DIMCEN);
574
+ file.writeGroupCode('142', this.DIMTSZ);
575
+ file.writeGroupCode('143', this.DIMALTF);
576
+ file.writeGroupCode('144', this.DIMLFAC);
577
+ file.writeGroupCode('145', this.DIMTVP);
578
+ file.writeGroupCode('146', this.DIMTFAC);
579
+ file.writeGroupCode('147', this.DIMGAP);
580
+ file.writeGroupCode('71', this.DIMTOL);
581
+ file.writeGroupCode('72', this.DIMLIM);
582
+ file.writeGroupCode('73', this.DIMTIH);
583
+ file.writeGroupCode('74', this.DIMTOH);
584
+ file.writeGroupCode('75', this.DIMSE1 ? 1 : 0); // convert bool to int
585
+ file.writeGroupCode('76', this.DIMSE2 ? 1 : 0); // convert bool to int
586
+ file.writeGroupCode('77', this.DIMTAD);
587
+ file.writeGroupCode('78', this.DIMZIN);
588
+ file.writeGroupCode('79', this.DIMAZIN);
589
+ file.writeGroupCode('170', this.DIMALT);
590
+ file.writeGroupCode('171', this.DIMALTD);
591
+ file.writeGroupCode('172', this.DIMTOFL ? 1 : 0); // convert bool to int
592
+ file.writeGroupCode('173', this.DIMSAH);
593
+ file.writeGroupCode('174', this.DIMTIX);
594
+ file.writeGroupCode('175', this.DIMSOXD);
595
+ file.writeGroupCode('176', this.DIMCLRD);
596
+ file.writeGroupCode('177', this.DIMCLRE);
597
+ file.writeGroupCode('178', this.DIMCLRT);
598
+ file.writeGroupCode('179', this.DIMADEC, DXFFile.Version.R14);
599
+ // file.writeGroupCode('270', this.DIMUNIT); // obsolete, now use DIMLUNIT AND DIMFRAC
600
+ file.writeGroupCode('271', this.DIMDEC);
601
+ file.writeGroupCode('272', this.DIMTDEC, DXFFile.Version.R13);
602
+ file.writeGroupCode('273', this.DIMALTU, DXFFile.Version.R13);
603
+ file.writeGroupCode('274', this.DIMALTTD, DXFFile.Version.R13);
604
+ file.writeGroupCode('275', this.DIMAUNIT, DXFFile.Version.R13);
605
+ file.writeGroupCode('276', this.DIMFRAC, DXFFile.Version.R2000);
606
+ file.writeGroupCode('277', this.DIMLUNIT, DXFFile.Version.R2000);
607
+ // file.writeGroupCode('278', this.DIMDSEP, DXFFile.Version.R14)); - TODO: AutoCAD uses a numberical description
608
+ file.writeGroupCode('279', this.DIMTMOVE, DXFFile.Version.R2000);
609
+ file.writeGroupCode('280', this.DIMJUST, DXFFile.Version.R13);
610
+ file.writeGroupCode('281', this.DIMSD1 ? 1 : 0, DXFFile.Version.R13); // convert bool to int
611
+ file.writeGroupCode('282', this.DIMSD2 ? 1 : 0, DXFFile.Version.R13); // convert bool to int
612
+ file.writeGroupCode('283', this.DIMTOLJ, DXFFile.Version.R13);
613
+ file.writeGroupCode('284', this.DIMTZIN, DXFFile.Version.R13);
614
+ file.writeGroupCode('285', this.DIMALTZ, DXFFile.Version.R13);
615
+ file.writeGroupCode('286', this.DIMALTTZ, DXFFile.Version.R13);
616
+ file.writeGroupCode('287', this.DIMFIT);
617
+ file.writeGroupCode('288', this.DIMUPT, DXFFile.Version.R13);
618
+ file.writeGroupCode('289', this.DIMATFIT, DXFFile.Version.R2000);
619
+ file.writeGroupCode('340', this.DIMTXSTY, DXFFile.Version.R13);
620
+ file.writeGroupCode('341', this.DIMLDRBLK, DXFFile.Version.R2000);
621
+ // file.writeGroupCode('342', this.DIMBLK);
622
+ // file.writeGroupCode('343', this.DIMBLK1);
623
+ // file.writeGroupCode('344', this.DIMBLK2);
624
+ file.writeGroupCode('371', this.DIMLWD, DXFFile.Version.R2000);
625
+ file.writeGroupCode('372', this.DIMLWE, DXFFile.Version.R2000);
626
+ }
627
+ }