@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,114 @@
1
+
2
+ import { Colour, EntityColour } from '../../core/lib/colour.js';
3
+
4
+ test('Test Colour', () => {
5
+ const colour = new Colour();
6
+ expect(colour.aci).toEqual(7);
7
+ expect(colour.rgb).toEqual({ 'b': 254, 'g': 254, 'r': 254 });
8
+
9
+ const colour4 = new Colour(4);
10
+ expect(colour4.aci).toEqual(4);
11
+ expect(colour4.rgb).toEqual({ 'b': 255, 'g': 255, 'r': 0 });
12
+ });
13
+
14
+ test('Test Colour.isTrueColour', () => {
15
+ const colour = new Colour();
16
+ expect(colour.isTrueColour).toEqual(false);
17
+
18
+ const trueColour = new Colour();
19
+ trueColour.setColour({ r: 200, g: 100, b: 50 });
20
+ expect(trueColour.isTrueColour).toEqual(true);
21
+ });
22
+
23
+ test('Test Colour.getColour', () => {
24
+ const colour = new Colour();
25
+ expect(colour.getColour()).toEqual({ 'b': 254, 'g': 254, 'r': 254 });
26
+ });
27
+
28
+
29
+ test('Test Colour.setColour', () => {
30
+ const colour = new Colour();
31
+ colour.setColour({ r: 200, g: 100, b: 50 });
32
+ expect(colour.rgb).toEqual({ 'r': 200, 'g': 100, 'b': 50 });
33
+ expect(colour.aci).toEqual(7);
34
+
35
+ colour.setColour({ r: 0, g: 255, b: 255 });
36
+ expect(colour.rgb).toEqual({ 'r': 0, 'g': 255, 'b': 255 });
37
+ expect(colour.aci).toEqual(4);
38
+
39
+ colour.setColour({ r: 1, g: 2, b: 3 });
40
+ expect(colour.rgb).toEqual({ 'r': 1, 'g': 2, 'b': 3 });
41
+ expect(colour.aci).toEqual(7);
42
+
43
+ colour.setColour({ r: 1000, g: 2000, b: 3000 });
44
+ expect(colour.rgb).toEqual({ 'r': 1, 'g': 2, 'b': 3 });
45
+ expect(colour.aci).toEqual(7);
46
+ });
47
+
48
+ test('Test Colour.setColourFromACI', () => {
49
+ const colour = new Colour();
50
+ colour.setColourFromACI(7);
51
+ expect(colour.rgb).toEqual({ 'r': 254, 'g': 254, 'b': 254 });
52
+ expect(colour.aci).toEqual(7);
53
+
54
+ colour.setColourFromACI(50);
55
+ expect(colour.rgb).toEqual({ 'r': 254, 'g': 254, 'b': 0 });
56
+ expect(colour.aci).toEqual(50);
57
+
58
+ colour.setColourFromACI(-1);
59
+ expect(colour.rgb).toEqual({ 'r': 254, 'g': 254, 'b': 0 });
60
+ expect(colour.aci).toEqual(50);
61
+ });
62
+
63
+ /*
64
+ Entity Colour - Included byblock and bylayer
65
+ */
66
+ test('Test EntityColour.setColour', () => {
67
+ const colour = new EntityColour();
68
+
69
+ expect(colour.byLayer).toEqual(true);
70
+ expect(colour.byBlock).toEqual(false);
71
+
72
+ colour.setColour({ r: 200, g: 100, b: 50 });
73
+ expect(colour.rgb).toEqual({ 'r': 200, 'g': 100, 'b': 50 });
74
+ expect(colour.aci).toEqual(7);
75
+ expect(colour.byLayer).toEqual(false);
76
+ expect(colour.byBlock).toEqual(false);
77
+
78
+ colour.setColour({ r: 0, g: 0, b: 0 });
79
+ expect(colour.rgb).toEqual({ 'r': 0, 'g': 0, 'b': 0 });
80
+ expect(colour.aci).toEqual(0);
81
+ expect(colour.byLayer).toEqual(false);
82
+ expect(colour.byBlock).toEqual(true);
83
+
84
+ colour.setColour('BYLAYER');
85
+ expect(colour.aci).toEqual(256);
86
+ expect(colour.byLayer).toEqual(true);
87
+ expect(colour.byBlock).toEqual(false);
88
+
89
+ colour.setColour('BYBLOCK');
90
+ expect(colour.aci).toEqual(0);
91
+ expect(colour.byLayer).toEqual(false);
92
+ expect(colour.byBlock).toEqual(true);
93
+
94
+ colour.setColour('bylayer');
95
+ expect(colour.aci).toEqual(256);
96
+ expect(colour.byLayer).toEqual(true);
97
+ expect(colour.byBlock).toEqual(false);
98
+
99
+ colour.setColour('byblock');
100
+ expect(colour.aci).toEqual(0);
101
+ expect(colour.byLayer).toEqual(false);
102
+ expect(colour.byBlock).toEqual(true);
103
+ });
104
+
105
+
106
+ test('Colour Conversion Test', () => {
107
+ const colour = new EntityColour();
108
+
109
+ // Check the returned ACI is the same as the set ACI
110
+ for (let i = 0; i < 255; i++) {
111
+ colour.setColourFromACI(i);
112
+ expect(colour.aci).toEqual(i);
113
+ }
114
+ });
@@ -1,29 +1,74 @@
1
1
 
2
- import {Colours} from '../../core/lib/colours.js';
2
+ import { Colours } from '../../core/lib/colours.js';
3
3
 
4
- test('Test Colours.getHexColour', () => {
5
- expect(Colours.getHexColour(0)).toBe('BYBLOCK');
6
- expect(Colours.getHexColour(255)).toBe('#FFFFFF');
4
+ test('Test Colours.isRGB', () => {
5
+ expect(Colours.isRGB({ r: 255, g: 255, b: 255 })).toEqual(true);
6
+ expect(Colours.isRGB({ r: 255, b: 255 })).toEqual(false);
7
7
  });
8
8
 
9
- test('Test Colours.getACADColour', () => {
10
- expect(Colours.getACADColour('#FF0000')).toBe('1');
11
- expect(Colours.getACADColour('#00FF3F')).toBe('100');
9
+ test('Test Colours.aciToRGB', () => {
10
+ expect(Colours.aciToRGB(0)).toEqual({ r: 0, g: 0, b: 0 });
11
+ expect(Colours.aciToRGB(255)).toEqual({ r: 255, g: 255, b: 255 });
12
+
13
+ // aci 7 should change colour depending on the background colour
14
+ expect(Colours.aciToRGB(255)).toEqual({ r: 255, g: 255, b: 255 });
15
+ });
16
+
17
+ test('Test Colours.rgbToACI', () => {
18
+ expect(Colours.rgbToACI({ r: 0, g: 0, b: 0 })).toEqual(0);
19
+ expect(Colours.rgbToACI({ r: 254, g: 254, b: 254 })).toEqual(7);
20
+ });
21
+
22
+ test('Test Colours.rgbToString', () => {
23
+ expect(Colours.rgbToString({ r: 0, g: 0, b: 0 })).toEqual('rgb(0, 0, 0)');
24
+ expect(Colours.rgbToString({ r: 255, g: 255, b: 255 })).toEqual('rgb(255, 255, 255)');
25
+ });
26
+
27
+ test('Test Colours.rgbToScaledRGB', () => {
28
+ expect(Colours.rgbToScaledRGB({ r: 255, g: 255, b: 255 })).toEqual({ r: 1, g: 1, b: 1 });
29
+ expect(Colours.rgbToScaledRGB({ r: 100, g: 100, b: 100 })).toEqual({ r: 100 / 255, g: 100 / 255, b: 100 / 255 });
30
+ expect(Colours.rgbToScaledRGB({ r: 1, g: 1 })).toBeUndefined();
31
+ expect(Colours.rgbToScaledRGB({})).toBeUndefined();
32
+ });
33
+
34
+ test('Test Colours.trueColourToRGB', () => {
35
+ // rgb(200, 100,50)
36
+ // hex 0x00C86432
37
+ // int 13132850
38
+ const rgb = Colours.trueColourToRGB(13132850);
39
+ expect(rgb.r).toBe(200);
40
+ expect(rgb.g).toBe(100);
41
+ expect(rgb.b).toBe(50);
42
+
43
+ expect(Colours.trueColourToRGB()).toBeUndefined();
12
44
  });
13
45
 
14
- test('Test Colours.rgbToHex', () => {
15
- expect(Colours.rgbToHex(1, 1, 1)).toBe('#010101');
16
- expect(Colours.rgbToHex(100, 100, 100)).toBe('#646464');
46
+
47
+ test('Test Colours.rgbToTrueColour', () => {
48
+ // rgb(200, 100,50)
49
+ // hex 0x00C86432
50
+ // int 13132850
51
+ expect(Colours.rgbToTrueColour({ r: 200, g: 100, b: 50 })).toBe(13132850);
52
+ expect(Colours.rgbToTrueColour()).toBeUndefined();
17
53
  });
18
54
 
19
- test('Test Colours.hexToRGB', () => {
20
- expect(Colours.hexToRGB('#010101')).toEqual({r: 1, g: 1, b: 1});
21
- expect(Colours.hexToRGB('#646464')).toEqual({r: 100, g: 100, b: 100});
22
- expect(Colours.hexToRGB('12345')).toBe(null);
55
+ test('Test Colour Sequence', () => {
56
+ // loop through all colour values and check the ACI numbers
57
+ // ensure the numbers are sequential
58
+ let index = 0;
59
+
60
+ for (const key in Colours.rgb_conversion_table) {
61
+ if (!isNaN(key)) {
62
+ expect(parseInt(key)).toBe(index);
63
+ index++;
64
+ }
65
+ }
23
66
  });
24
67
 
25
- test('Test Colours.hexToScaledRGB', () => {
26
- expect(Colours.hexToScaledRGB('#010101')).toEqual({r: 1/255, g: 1/255, b: 1/255});
27
- expect(Colours.hexToScaledRGB('#646464')).toEqual({r: 100/255, g: 100/255, b: 100/255});
28
- expect(Colours.hexToScaledRGB('12345')).toBe(null);
68
+ test('Colours Conversion Test', () => {
69
+ // Check the returned ACI is the same as the set ACI
70
+ for (let i = 0; i < 255; i++) {
71
+ const rgb = Colours.aciToRGB(i);
72
+ expect(Colours.rgbToACI(rgb)).toEqual(i);
73
+ }
29
74
  });
@@ -1,6 +1,7 @@
1
- import {Core} from '../../core/core/core.js';
2
- import {Input, PromptOptions} from '../../core/lib/inputManager.js';
3
- import {Strings} from '../../core/lib/strings.js';
1
+ import { Core } from '../../core/core/core.js';
2
+ import { Input, PromptOptions } from '../../core/lib/inputManager.js';
3
+ import { Strings } from '../../core/lib/strings.js';
4
+ import { expect, jest } from '@jest/globals';
4
5
 
5
6
  const core = new Core();
6
7
  const commandline = core.commandLine; // new CommandLine();
@@ -16,24 +17,7 @@ test('Test Commandline.setPrompt', () => {
16
17
  const testText = 'TestTest';
17
18
  commandline.setPrompt(testText);
18
19
  expect(commandline.prompt).toBe(`${testText}:`);
19
-
20
- // test setPrompt with default - command should be set to default value
21
- const testTextWithDefault = 'TestTest <default>';
22
- commandline.setPrompt(testTextWithDefault);
23
- expect(commandline.prompt).toBe(`${testTextWithDefault}:`);
24
- expect(commandline.command).toBe('default');
25
- });
26
-
27
- test('Test Commandline.parseCommandDefault', () => {
28
- const commandDefault = ['<default>'];
29
- const defaultValue = commandline.parseCommandDefault(commandDefault);
30
- expect(defaultValue).toBe(`default`);
31
-
32
- // only a single default is valid
33
- commandDefault.push('<second value>');
34
- expect(() => {
35
- commandline.parseCommandDefault(commandDefault);
36
- }).toThrow();
20
+ expect(commandline.command).toBe('');
37
21
  });
38
22
 
39
23
  test('Test Commandline.update', () => {
@@ -139,7 +123,7 @@ test('Test CommandLine.parseInput', () => {
139
123
  expect(relPoint1.x).toBe(101);
140
124
  expect(relPoint1.y).toBe(102);
141
125
 
142
- core.scene.inputManager.initialiseItem('Line');
126
+ core.scene.inputManager.startCommand('Line');
143
127
  core.scene.inputManager.activeCommand.points.push(relPoint1);
144
128
  const relPoint2 = commandline.parseInput('@101,102');
145
129
  expect(relPoint2.constructor.name).toBe('Point');
@@ -215,6 +199,159 @@ test('Test CommandLine.addToCommandHistory', () => {
215
199
  commandline.lastCommand = [];
216
200
  });
217
201
 
202
+ test('Test CommandLine.setUpdateFunction registers callback and triggers it', () => {
203
+ const callback = jest.fn();
204
+ commandline.setUpdateFunction(callback);
205
+ expect(callback).toHaveBeenCalled();
206
+ commandline.setUpdateFunction(undefined);
207
+ });
208
+
209
+ test('Test CommandLine.escapePressed delegates to inputManager.onEscapePressed', () => {
210
+ const inputManager = core.scene.inputManager;
211
+ const spy = jest.spyOn(inputManager, 'onEscapePressed').mockImplementation(() => {});
212
+ commandline.escapePressed();
213
+ expect(spy).toHaveBeenCalled();
214
+ spy.mockRestore();
215
+ });
216
+
217
+ test('Test CommandLine.deletePressed delegates to inputManager.onCommand with Erase', () => {
218
+ const inputManager = core.scene.inputManager;
219
+ const spy = jest.spyOn(inputManager, 'onCommand').mockImplementation(() => {});
220
+ commandline.deletePressed();
221
+ expect(spy).toHaveBeenCalledWith('Erase');
222
+ spy.mockRestore();
223
+ });
224
+
225
+ test('Test CommandLine.enterPressed with empty command calls onEnterPressed', () => {
226
+ const inputManager = core.scene.inputManager;
227
+ commandline.resetPrompt();
228
+ const spy = jest.spyOn(inputManager, 'onEnterPressed').mockImplementation(() => {});
229
+ commandline.enterPressed();
230
+ expect(spy).toHaveBeenCalled();
231
+ spy.mockRestore();
232
+ });
233
+
234
+ test('Test CommandLine.enterPressed with command calls onCommand with parsed value', () => {
235
+ const inputManager = core.scene.inputManager;
236
+ commandline.resetPrompt();
237
+ commandline.handleKeys('42');
238
+ const spy = jest.spyOn(inputManager, 'onCommand').mockImplementation(() => {});
239
+ commandline.enterPressed();
240
+ expect(spy).toHaveBeenCalledWith(42);
241
+ spy.mockRestore();
242
+ commandline.resetPrompt();
243
+ });
244
+
245
+ test('Test CommandLine.handleKeys routes Backspace to backPressed', () => {
246
+ commandline.handleKeys('123');
247
+ commandline.handleKeys('Backspace');
248
+ expect(commandline.command).toBe('12');
249
+ commandline.resetPrompt();
250
+ });
251
+
252
+ test('Test CommandLine.handleKeys routes Enter to enterPressed', () => {
253
+ const spy = jest.spyOn(commandline, 'enterPressed').mockImplementation(() => {});
254
+ commandline.handleKeys('Enter');
255
+ expect(spy).toHaveBeenCalled();
256
+ spy.mockRestore();
257
+ });
258
+
259
+ test('Test CommandLine.handleKeys routes Escape to escapePressed', () => {
260
+ const spy = jest.spyOn(commandline, 'escapePressed').mockImplementation(() => {});
261
+ commandline.handleKeys('Escape');
262
+ expect(spy).toHaveBeenCalled();
263
+ spy.mockRestore();
264
+ });
265
+
266
+ test('Test CommandLine.handleKeys routes Space to spacePressed', () => {
267
+ const spy = jest.spyOn(commandline, 'spacePressed').mockImplementation(() => {});
268
+ commandline.handleKeys('Space');
269
+ expect(spy).toHaveBeenCalled();
270
+ spy.mockRestore();
271
+ });
272
+
273
+ test('Test CommandLine.handleKeys routes Delete to deletePressed', () => {
274
+ const spy = jest.spyOn(commandline, 'deletePressed').mockImplementation(() => {});
275
+ commandline.handleKeys('Delete');
276
+ expect(spy).toHaveBeenCalled();
277
+ spy.mockRestore();
278
+ });
279
+
280
+ test('Test CommandLine.handleKeys routes Up-Arrow to previousCommand up', () => {
281
+ const spy = jest.spyOn(commandline, 'previousCommand').mockImplementation(() => {});
282
+ commandline.handleKeys('Up-Arrow');
283
+ expect(spy).toHaveBeenCalledWith('up');
284
+ spy.mockRestore();
285
+ });
286
+
287
+ test('Test CommandLine.handleKeys routes Down-Arrow to previousCommand down', () => {
288
+ const spy = jest.spyOn(commandline, 'previousCommand').mockImplementation(() => {});
289
+ commandline.handleKeys('Down-Arrow');
290
+ expect(spy).toHaveBeenCalledWith('down');
291
+ spy.mockRestore();
292
+ });
293
+
294
+ test('Test CommandLine.handleKeys with undefined key does not change command', () => {
295
+ commandline.resetPrompt();
296
+ commandline.handleKeys(undefined);
297
+ expect(commandline.command).toBe('');
298
+ });
299
+
300
+ test('Test CommandLine.previousCommand cycles up through history', () => {
301
+ commandline.lastCommand = ['Circle', 'Line', 'Rect'];
302
+ commandline.lastCommandPosition = -1;
303
+
304
+ commandline.previousCommand('up');
305
+ expect(commandline.command).toBe('Circle');
306
+ expect(commandline.lastCommandPosition).toBe(0);
307
+
308
+ commandline.previousCommand('up');
309
+ expect(commandline.command).toBe('Line');
310
+ expect(commandline.lastCommandPosition).toBe(1);
311
+
312
+ commandline.previousCommand('up');
313
+ expect(commandline.command).toBe('Rect');
314
+ expect(commandline.lastCommandPosition).toBe(2);
315
+
316
+ // At end of history - stays at last entry
317
+ commandline.previousCommand('up');
318
+ expect(commandline.command).toBe('Rect');
319
+ expect(commandline.lastCommandPosition).toBe(2);
320
+
321
+ commandline.lastCommand = [];
322
+ commandline.resetPrompt();
323
+ });
324
+
325
+ test('Test CommandLine.previousCommand cycles down through history', () => {
326
+ commandline.lastCommand = ['Circle', 'Line', 'Rect'];
327
+ commandline.lastCommandPosition = 2;
328
+ commandline.command = 'Rect';
329
+
330
+ commandline.previousCommand('down');
331
+ expect(commandline.command).toBe('Line');
332
+ expect(commandline.lastCommandPosition).toBe(1);
333
+
334
+ commandline.previousCommand('down');
335
+ expect(commandline.command).toBe('Circle');
336
+ expect(commandline.lastCommandPosition).toBe(0);
337
+
338
+ // At position 0 going down resets the prompt
339
+ commandline.previousCommand('down');
340
+ expect(commandline.command).toBe('');
341
+ expect(commandline.lastCommandPosition).toBe(-1);
342
+
343
+ commandline.lastCommand = [];
344
+ });
345
+
346
+ test('Test CommandLine.previousCommand up with empty history is a no-op', () => {
347
+ commandline.lastCommand = [];
348
+ commandline.lastCommandPosition = -1;
349
+ commandline.command = '';
350
+ commandline.previousCommand('up');
351
+ expect(commandline.command).toBe('');
352
+ expect(commandline.lastCommandPosition).toBe(-1);
353
+ });
354
+
218
355
  test('Test CommandLine.addToCommandHistory', () => {
219
356
  commandline.addToCommandHistory('3');
220
357
  commandline.addToCommandHistory('2');
@@ -1,6 +1,6 @@
1
1
 
2
- import {Core} from '../../core/core/core.js';
3
- import {Point} from '../../core/entities/point.js';
2
+ import { Core } from '../../core/core/core.js';
3
+ import { Point } from '../../core/entities/point.js';
4
4
 
5
5
  const core = new Core();
6
6
  const commandManager = core.commandManager;
@@ -10,10 +10,10 @@ test('Test CommandManager.createNew', () => {
10
10
  const endPoint = new Point(10, 10);
11
11
  const points = [startPoint, endPoint];
12
12
 
13
- const line = commandManager.createNew('Line', {points: points});
13
+ const line = commandManager.createNew('Line', { points: points });
14
14
  expect(typeof line).toBe('object');
15
15
 
16
- const test = commandManager.createNew('test', {points: points});
16
+ const test = commandManager.createNew('test', { points: points });
17
17
  expect(typeof test).toBe('undefined');
18
18
  });
19
19
 
@@ -0,0 +1,9 @@
1
+ import { Constants } from '../../core/lib/constants.js';
2
+
3
+ test('Constants.Tolerance.EPSILON is 1e-10', () => {
4
+ expect(Constants.Tolerance.EPSILON).toBe(1e-10);
5
+ });
6
+
7
+ test('Constants.Precision.DECIMALPLACES is 5', () => {
8
+ expect(Constants.Precision.DECIMALPLACES).toBe(5);
9
+ });
@@ -1,4 +1,4 @@
1
- import {DXFFile} from '../../../core/lib/dxf/dxfFile.js';
1
+ import { DXFFile } from '../../../core/lib/dxf/dxfFile.js';
2
2
 
3
3
  const file = new DXFFile();
4
4
 
@@ -15,8 +15,12 @@ test('Test DXFFile.writeGroupCode', () => {
15
15
  file.writeGroupCode('groupCode', 'groupValue');
16
16
 
17
17
  const output = 'groupCode\ngroupValue\n';
18
-
19
18
  expect(file.contents).toEqual(output);
19
+
20
+ // throw on undefined values
21
+ expect(() => {
22
+ file.writeGroupCode('groupCode', undefined);
23
+ }).toThrow();
20
24
  });
21
25
 
22
26
  test('Test DXFFile.clearFile', () => {
@@ -1,4 +1,4 @@
1
- import {DxfIterator} from '../../../core/lib/dxf/dxfIterator.js';
1
+ import { DxfIterator } from '../../../core/lib/dxf/dxfIterator.js';
2
2
 
3
3
  const iterator = new DxfIterator();
4
4
  const string = '1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n0\nEOF';
@@ -0,0 +1,173 @@
1
+ import { DXFWriter } from '../../../core/lib/dxf/dxfWrite.js';
2
+ import { DXFFile } from '../../../core/lib/dxf/dxfFile.js';
3
+ import { DesignCore } from '../../../core/designCore.js';
4
+ import { jest } from '@jest/globals';
5
+
6
+ const createManager = (styleName = 'default') => ({
7
+ items: [],
8
+ getCstyle: jest.fn(() => styleName),
9
+ dxf: jest.fn(),
10
+ });
11
+
12
+ const createCoreMock = (options = {}) => {
13
+ const blocks = options.blocks || [];
14
+ const entities = options.entities || [];
15
+
16
+ return {
17
+ dxfVersion: options.dxfVersion || 'R2018',
18
+ handleManager: { next() {
19
+ return '1';
20
+ }, get handseed() {
21
+ return '1';
22
+ } },
23
+ layerManager: options.layerManager || createManager('Layer0'),
24
+ ltypeManager: options.ltypeManager || createManager('Continuous'),
25
+ styleManager: options.styleManager || createManager('Standard'),
26
+ dimStyleManager: options.dimStyleManager || createManager('ISO-25'),
27
+ viewManager: options.viewManager || { dxf: jest.fn() },
28
+ vportManager: options.vportManager || { dxf: jest.fn() },
29
+ ucsManager: options.ucsManager || { dxf: jest.fn() },
30
+ appIdManager: options.appIdManager || { dxf: jest.fn() },
31
+ blockRecordManager: options.blockRecordManager || { dxf: jest.fn() },
32
+ dictionaryManager: options.dictionaryManager || { dxf: jest.fn() },
33
+ scene: {
34
+ dxf: jest.fn(),
35
+ headers: { dxf: jest.fn(), dxfVersion: options.dxfVersion || 'R2018' },
36
+ entities: {
37
+ count: jest.fn(() => entities.length),
38
+ get: jest.fn((index) => entities[index]),
39
+ },
40
+ blockManager: {
41
+ items: blocks,
42
+ },
43
+ },
44
+ };
45
+ };
46
+
47
+ describe('DXFWriter', () => {
48
+ let originalCore;
49
+
50
+ beforeAll(() => {
51
+ originalCore = DesignCore._core;
52
+ });
53
+
54
+ afterAll(() => {
55
+ DesignCore.Core = originalCore;
56
+ });
57
+
58
+ test('Test DXFWriter.writeHeaders', () => {
59
+ const core = createCoreMock({
60
+ entities: [{}, {}],
61
+ blocks: [{ name: 'BlockA' }, { name: 'BlockB' }],
62
+ });
63
+
64
+ core.layerManager.items = [{}, {}, {}];
65
+ core.ltypeManager.items = [{}, {}, {}, {}];
66
+ core.styleManager.items = [{}, {}, {}, {}, {}];
67
+ core.dimStyleManager.items = [{}, {}, {}, {}, {}, {}];
68
+
69
+ DesignCore.Core = core;
70
+
71
+ const writer = new DXFWriter();
72
+ const file = new DXFFile('R2018');
73
+ writer.writeHeaders(file);
74
+
75
+ expect(file.contents).toContain('0\nSECTION\n2\nHEADER\n');
76
+ expect(core.scene.headers.dxf).toHaveBeenCalledWith(file);
77
+ expect(file.contents).toContain('0\nENDSEC\n');
78
+ });
79
+
80
+ test('Test DXFWriter.writeTables', () => {
81
+ const core = createCoreMock({
82
+ blocks: [{ name: 'BlockOne' }, { name: 'BlockTwo' }],
83
+ });
84
+ DesignCore.Core = core;
85
+
86
+ const writer = new DXFWriter();
87
+ const file = new DXFFile('R2018');
88
+ writer.writeTables(file);
89
+
90
+ expect(core.ltypeManager.dxf).toHaveBeenCalledWith(file);
91
+ expect(core.layerManager.dxf).toHaveBeenCalledWith(file);
92
+ expect(core.styleManager.dxf).toHaveBeenCalledWith(file);
93
+ expect(core.dimStyleManager.dxf).toHaveBeenCalledWith(file);
94
+ expect(core.vportManager.dxf).toHaveBeenCalledWith(file);
95
+ expect(core.viewManager.dxf).toHaveBeenCalledWith(file);
96
+ expect(core.ucsManager.dxf).toHaveBeenCalledWith(file);
97
+ expect(core.appIdManager.dxf).toHaveBeenCalledWith(file);
98
+ expect(core.blockRecordManager.dxf).toHaveBeenCalledWith(file);
99
+
100
+ expect(file.contents).toContain('0\nSECTION\n2\nTABLES\n');
101
+ expect(file.contents).toContain('0\nENDSEC\n');
102
+ });
103
+
104
+ test('Test DXFWriter.writeBlocks', () => {
105
+ const blockA = { dxf: jest.fn() };
106
+ const blockB = { dxf: jest.fn() };
107
+ const core = createCoreMock({
108
+ blocks: [blockA, blockB],
109
+ });
110
+ DesignCore.Core = core;
111
+
112
+ const writer = new DXFWriter();
113
+ const file = new DXFFile('R2018');
114
+ writer.writeBlocks(file);
115
+
116
+ expect(blockA.dxf).toHaveBeenCalledWith(file);
117
+ expect(blockB.dxf).toHaveBeenCalledWith(file);
118
+ expect(file.contents).toContain('0\nSECTION\n2\nBLOCKS\n');
119
+ expect(file.contents).toContain('0\nENDSEC\n');
120
+ });
121
+
122
+ test('Test DXFWriter.writeEntities', () => {
123
+ const entityA = { dxf: jest.fn() };
124
+ const entityB = { dxf: jest.fn() };
125
+ const core = createCoreMock({
126
+ entities: [entityA, entityB],
127
+ });
128
+ DesignCore.Core = core;
129
+
130
+ const writer = new DXFWriter();
131
+ const file = new DXFFile('R2018');
132
+ writer.writeEntities(file);
133
+
134
+ expect(entityA.dxf).toHaveBeenCalledWith(file);
135
+ expect(entityB.dxf).toHaveBeenCalledWith(file);
136
+ expect(file.contents).toContain('0\nSECTION\n2\nENTITIES\n');
137
+ expect(file.contents).toContain('0\nENDSEC\n');
138
+ });
139
+
140
+ test('Test DXFWriter.write default version from core', () => {
141
+ const core = createCoreMock({
142
+ dxfVersion: 'R12',
143
+ });
144
+ DesignCore.Core = core;
145
+
146
+ const writer = new DXFWriter();
147
+ const output = writer.write();
148
+
149
+ expect(output).toContain('999\nDXF created from Design-Core\n');
150
+ expect(output).toContain('2\nHEADER\n');
151
+ expect(output).toContain('2\nTABLES\n');
152
+ expect(output).toContain('2\nBLOCKS\n');
153
+ expect(output).toContain('2\nENTITIES\n');
154
+ expect(output).toContain('0\nEOF\n');
155
+
156
+ expect(output).not.toContain('2\nOBJECTS\n');
157
+ expect(output).not.toContain('0\nDICTIONARY\n');
158
+ });
159
+
160
+ test('Test DXFWriter.write supports explicit version', () => {
161
+ const core = createCoreMock({
162
+ dxfVersion: 'R12',
163
+ });
164
+ DesignCore.Core = core;
165
+
166
+ const writer = new DXFWriter();
167
+ const output = writer.write('R2018');
168
+
169
+ expect(output).toContain('2\nOBJECTS\n');
170
+ expect(core.dictionaryManager.dxf).toHaveBeenCalled();
171
+ expect(output).toContain('0\nEOF\n');
172
+ });
173
+ });