@design-core/core 0.0.1 → 0.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (254) hide show
  1. package/.eslintrc.json +14 -7
  2. package/.github/workflows/DesignCoreQA.yml +3 -1
  3. package/README.md +11 -4
  4. package/TODO.md +19 -0
  5. package/core/core/core.js +49 -42
  6. package/core/designCore.js +61 -2
  7. package/core/dimensions/alignedDimension.js +142 -0
  8. package/core/dimensions/angularDimension.js +550 -0
  9. package/core/dimensions/baseCircularDimension.js +244 -0
  10. package/core/dimensions/baseDimension.js +558 -0
  11. package/core/dimensions/baseLinearDimension.js +371 -0
  12. package/core/dimensions/diametricDimension.js +82 -0
  13. package/core/dimensions/dimension.js +298 -0
  14. package/core/dimensions/linearDimension.js +29 -0
  15. package/core/dimensions/radialDimension.js +78 -0
  16. package/core/dimensions/rotatedDimension.js +167 -0
  17. package/core/entities/arc.js +314 -60
  18. package/core/entities/arctext.js +642 -0
  19. package/core/entities/basePolyline.js +553 -94
  20. package/core/entities/circle.js +181 -54
  21. package/core/entities/entity.js +154 -74
  22. package/core/entities/hatch.js +807 -0
  23. package/core/entities/insert.js +200 -39
  24. package/core/entities/line.js +196 -134
  25. package/core/entities/lwpolyline.js +21 -44
  26. package/core/entities/point.js +194 -29
  27. package/core/entities/polyline.js +54 -7
  28. package/core/entities/rectangle.js +43 -13
  29. package/core/entities/solid.js +43 -6
  30. package/core/entities/text.js +324 -181
  31. package/core/lib/boundingBox.js +73 -13
  32. package/core/lib/canvas.js +256 -65
  33. package/core/lib/clipboard.js +198 -0
  34. package/core/lib/colour.js +144 -0
  35. package/core/lib/colours.js +367 -301
  36. package/core/lib/commandLine.js +16 -28
  37. package/core/lib/commandManager.js +115 -58
  38. package/core/lib/constants.js +23 -0
  39. package/core/lib/dxf/dxf.js +249 -34
  40. package/core/lib/dxf/dxfFile.js +23 -38
  41. package/core/lib/dxf/dxfIterator.js +17 -5
  42. package/core/lib/dxf/dxfRead.js +23 -7
  43. package/core/lib/dxf/dxfWrite.js +39 -129
  44. package/core/lib/dxf/handleManager.js +97 -0
  45. package/core/lib/dxf/sections/blocks.js +16 -2
  46. package/core/lib/dxf/sections/entities.js +17 -3
  47. package/core/lib/dxf/sections/header.js +10 -1
  48. package/core/lib/dxf/sections/objects.js +36 -0
  49. package/core/lib/dxf/sections/section.js +43 -5
  50. package/core/lib/dxf/sections/tables.js +17 -3
  51. package/core/lib/entityManager.js +178 -0
  52. package/core/lib/fileio.js +14 -4
  53. package/core/lib/headers.js +229 -0
  54. package/core/lib/input.js +46 -0
  55. package/core/lib/inputManager.js +199 -194
  56. package/core/lib/intersect.js +341 -468
  57. package/core/lib/logging.js +25 -1
  58. package/core/lib/matrix.js +6 -8
  59. package/core/lib/mouse.js +24 -79
  60. package/core/lib/patterns.js +690 -0
  61. package/core/lib/promptOptions.js +133 -0
  62. package/core/lib/scene.js +71 -174
  63. package/core/lib/selectionManager.js +74 -48
  64. package/core/lib/selectionWindow.js +24 -10
  65. package/core/lib/settings.js +18 -11
  66. package/core/lib/snapping.js +129 -21
  67. package/core/lib/stateManager.js +288 -0
  68. package/core/lib/strings.js +57 -5
  69. package/core/lib/utils.js +95 -11
  70. package/core/objects/dictionary.js +43 -0
  71. package/core/objects/dictionaryManager.js +80 -0
  72. package/core/properties/dimType.js +117 -0
  73. package/core/properties/flags.js +66 -0
  74. package/core/properties/property.js +26 -0
  75. package/core/properties/propertyManager.js +65 -19
  76. package/core/tables/appId.js +31 -0
  77. package/core/tables/appIdManager.js +44 -0
  78. package/core/tables/block.js +323 -0
  79. package/core/tables/blockManager.js +48 -0
  80. package/core/tables/blockRecord.js +29 -0
  81. package/core/tables/blockRecordManager.js +37 -0
  82. package/core/tables/dimStyle.js +627 -0
  83. package/core/tables/dimStyleManager.js +187 -0
  84. package/core/tables/endblk.js +28 -0
  85. package/core/tables/layer.js +219 -0
  86. package/core/tables/layerManager.js +47 -0
  87. package/core/tables/ltype.js +85 -0
  88. package/core/tables/ltypeManager.js +65 -0
  89. package/core/tables/style.js +145 -0
  90. package/core/tables/styleManager.js +55 -0
  91. package/core/tables/styleManagerBase.js +110 -0
  92. package/core/tables/tableManagerBase.js +354 -0
  93. package/core/tables/ucs.js +28 -0
  94. package/core/tables/ucsManager.js +44 -0
  95. package/core/tables/view.js +28 -0
  96. package/core/tables/viewManager.js +44 -0
  97. package/core/tables/vport.js +70 -0
  98. package/core/tables/vportManager.js +65 -0
  99. package/core/tools/chamfer.js +343 -0
  100. package/core/tools/chamferFilletBase.js +162 -0
  101. package/core/tools/copy.js +68 -40
  102. package/core/tools/copybase.js +65 -0
  103. package/core/tools/copyclip.js +59 -0
  104. package/core/tools/cornerEntity.js +138 -0
  105. package/core/tools/cutclip.js +72 -0
  106. package/core/tools/distance.js +37 -9
  107. package/core/tools/erase.js +43 -13
  108. package/core/tools/explode.js +117 -0
  109. package/core/tools/extend.js +71 -32
  110. package/core/tools/fillet.js +336 -0
  111. package/core/tools/identify.js +33 -6
  112. package/core/tools/matchProp.js +106 -0
  113. package/core/tools/mirror.js +141 -0
  114. package/core/tools/move.js +65 -32
  115. package/core/tools/offset.js +321 -0
  116. package/core/tools/pan.js +54 -0
  117. package/core/tools/pasteclip.js +93 -0
  118. package/core/tools/purge.js +90 -0
  119. package/core/tools/rotate.js +105 -70
  120. package/core/tools/scale.js +166 -0
  121. package/core/tools/tool.js +14 -4
  122. package/core/tools/trim.js +71 -32
  123. package/core/tools/zoom.js +152 -0
  124. package/package.json +3 -305
  125. package/test/dimensions/alignedDimension.test.js +211 -0
  126. package/test/dimensions/angularDimension.test.js +243 -0
  127. package/test/dimensions/baseDimension.test.js +239 -0
  128. package/test/dimensions/diametricDimension.test.js +203 -0
  129. package/test/dimensions/dimension.test.js +102 -0
  130. package/test/dimensions/radialDimension.test.js +203 -0
  131. package/test/dimensions/rotatedDimension.test.js +224 -0
  132. package/test/entities/arc.test.js +463 -41
  133. package/test/entities/arctext.test.js +329 -0
  134. package/test/entities/basePolyline.test.js +459 -10
  135. package/test/entities/circle.test.js +312 -7
  136. package/test/entities/entity.test.js +28 -9
  137. package/test/entities/hatch.test.js +606 -0
  138. package/test/entities/insert.test.js +90 -0
  139. package/test/entities/line.test.js +182 -6
  140. package/test/entities/point.test.js +375 -37
  141. package/test/entities/solid.test.js +156 -0
  142. package/test/entities/text.test.js +533 -7
  143. package/test/integration/exportIntegration.reference.dxf +1706 -0
  144. package/test/integration/exportIntegration.test.js +186 -0
  145. package/test/integration/importExportIntegration.test.js +126 -0
  146. package/test/integration/intersectionIntegration.test.js +880 -0
  147. package/test/integration/userInputIntegration.reference.dxf +1410 -0
  148. package/test/integration/userInputIntegration.test.js +269 -0
  149. package/test/lib/boundingBox.test.js +26 -2
  150. package/test/lib/canvas.test.js +613 -5
  151. package/test/lib/clipboard.test.js +70 -0
  152. package/test/lib/colour.test.js +114 -0
  153. package/test/lib/colours.test.js +63 -18
  154. package/test/lib/commandLine.test.js +159 -22
  155. package/test/lib/commandManager.test.js +4 -4
  156. package/test/lib/constants.test.js +9 -0
  157. package/test/lib/dxf/dxfFile.test.js +6 -2
  158. package/test/lib/dxf/dxfIterator.test.js +1 -1
  159. package/test/lib/dxf/dxfWrite.test.js +173 -0
  160. package/test/lib/dxf/handleManager.test.js +137 -0
  161. package/test/lib/dxf/sections/blocks.test.js +5 -5
  162. package/test/lib/dxf/sections/entities.test.js +4 -4
  163. package/test/lib/dxf/sections/header.test.js +18 -4
  164. package/test/lib/dxf/sections/objects.test.js +132 -0
  165. package/test/lib/dxf/sections/section.test.js +29 -29
  166. package/test/lib/dxf/sections/tables.test.js +3 -3
  167. package/test/lib/entityManager.test.js +163 -0
  168. package/test/lib/headers.test.js +233 -0
  169. package/test/lib/inputManager.test.js +1144 -5
  170. package/test/lib/intersect.test.js +454 -331
  171. package/test/lib/logging.test.js +1 -1
  172. package/test/lib/matrix.test.js +1 -1
  173. package/test/lib/mouse.test.js +327 -4
  174. package/test/lib/patterns.test.js +105 -0
  175. package/test/lib/promptOptions.test.js +179 -0
  176. package/test/lib/scene.test.js +16 -52
  177. package/test/lib/selectionManager.test.js +17 -5
  178. package/test/lib/settings.test.js +111 -5
  179. package/test/lib/snapping.test.js +142 -4
  180. package/test/lib/stateManager.test.js +155 -0
  181. package/test/lib/utils.test.js +81 -1
  182. package/test/objects/dictionary.test.js +81 -0
  183. package/test/objects/dictionaryManager.test.js +34 -0
  184. package/test/properties/dimType.test.js +62 -0
  185. package/test/properties/flags.test.js +164 -0
  186. package/test/properties/property.test.js +13 -0
  187. package/test/properties/propertyManager.test.js +10 -11
  188. package/test/tables/appId.test.js +46 -0
  189. package/test/tables/appIdManager.test.js +72 -0
  190. package/test/tables/block.test.js +157 -0
  191. package/test/tables/blockManager.test.js +52 -0
  192. package/test/tables/blockRecord.test.js +39 -0
  193. package/test/tables/blockRecordManager.test.js +60 -0
  194. package/test/tables/dimstyle.test.js +72 -0
  195. package/test/tables/endblk.test.js +30 -0
  196. package/test/tables/layer.test.js +95 -0
  197. package/test/tables/layerManager.test.js +172 -0
  198. package/test/{styles → tables}/ltype.test.js +7 -7
  199. package/test/{styles → tables}/ltypeManager.test.js +2 -2
  200. package/test/tables/style.test.js +44 -0
  201. package/test/tables/stylemanagerbase.test.js +220 -0
  202. package/test/tables/tableManagerBase.test.js +194 -0
  203. package/test/tables/ucs.test.js +37 -0
  204. package/test/tables/ucsManager.test.js +48 -0
  205. package/test/tables/view.test.js +37 -0
  206. package/test/tables/viewManager.test.js +48 -0
  207. package/test/tables/vport.test.js +117 -0
  208. package/test/tables/vportManager.test.js +54 -0
  209. package/test/test-helpers/test-helpers.js +66 -0
  210. package/test/tools/chamfer.test.js +970 -0
  211. package/test/tools/chamferFilletBase.test.js +446 -0
  212. package/test/tools/copy.test.js +22 -14
  213. package/test/tools/copybase.test.js +93 -0
  214. package/test/tools/copyclip.test.js +92 -0
  215. package/test/tools/cornerEntity.test.js +201 -0
  216. package/test/tools/cutclip.test.js +94 -0
  217. package/test/tools/distance.test.js +140 -18
  218. package/test/tools/erase.test.js +12 -12
  219. package/test/tools/explode.test.js +45 -0
  220. package/test/tools/extend.test.js +326 -44
  221. package/test/tools/fillet.test.js +831 -0
  222. package/test/tools/identify.test.js +115 -16
  223. package/test/tools/matchProp.test.js +84 -0
  224. package/test/tools/mirror.test.js +475 -0
  225. package/test/tools/move.test.js +75 -19
  226. package/test/tools/offset.test.js +748 -0
  227. package/test/tools/pan.test.js +72 -0
  228. package/test/tools/pasteclip.test.js +100 -0
  229. package/test/tools/purge.test.js +89 -0
  230. package/test/tools/rotate.test.js +89 -23
  231. package/test/tools/scale.test.js +529 -0
  232. package/test/tools/trim.test.js +419 -84
  233. package/test/tools/zoom.test.js +504 -0
  234. package/core/entities/alignedDimension.js +0 -279
  235. package/core/entities/angularDimension.js +0 -194
  236. package/core/entities/baseDimension.js +0 -227
  237. package/core/entities/block.js +0 -247
  238. package/core/entities/diametricDimension.js +0 -133
  239. package/core/entities/dimension.js +0 -202
  240. package/core/entities/radialDimension.js +0 -126
  241. package/core/styles/dimStyle.js +0 -719
  242. package/core/styles/dimStyleManager.js +0 -47
  243. package/core/styles/layer.js +0 -133
  244. package/core/styles/layerManager.js +0 -40
  245. package/core/styles/ltype.js +0 -86
  246. package/core/styles/ltypeManager.js +0 -50
  247. package/core/styles/style.js +0 -158
  248. package/core/styles/styleManager.js +0 -43
  249. package/core/styles/styleManagerBase.js +0 -299
  250. package/test/entities/block.test.js +0 -22
  251. package/test/styles/dimstyle.test.js +0 -19
  252. package/test/styles/layerManager.test.js +0 -150
  253. package/test/styles/style.test.js +0 -33
  254. package/test/styles/stylemanagerbase.test.js +0 -219
@@ -1,299 +0,0 @@
1
- import {DesignCore} from '../designCore.js';
2
- import {Strings} from '../lib/strings.js';
3
-
4
- export class StyleManagerBase {
5
- constructor() {
6
- this.styles = [];
7
- this.addStandardStyles();
8
- // set the current style to the first available style
9
- this.currentstyle = this.styles[0].name;
10
-
11
- // list of mandatory styles or layers that cannot be deleted
12
- this.indelibleStyles = [];
13
- }
14
-
15
- /**
16
- * Get styles
17
- * @returns list of styles
18
- */
19
- getStyles() {
20
- return this.styles;
21
- }
22
-
23
- /**
24
- * Get style count
25
- * @returns number of styles
26
- */
27
- styleCount() {
28
- return this.styles.length;
29
- }
30
-
31
- /**
32
- * Adds a new style to the list of active styles
33
- */
34
- newStyle() {
35
- this.addStyle({
36
- 'name': this.getUniqueName('NEW_STYLE'),
37
- });
38
- }
39
-
40
- /**
41
- * Generate a unique name
42
- * @param {string} name
43
- * @returns unique name
44
- */
45
- getUniqueName(name) {
46
- let count = 0;
47
- let styStr = name.replace(/ /g, '_'); // .toUpperCase();
48
- for (let i = 0; i < this.styleCount(); i++) {
49
- const styleName = this.styles[i].name.toUpperCase();
50
- if (styleName.includes(styStr.toUpperCase())) {
51
- count = count + 1;
52
- }
53
- }
54
- if (count > 0) {
55
- styStr = styStr + '_' + count;
56
- }
57
-
58
- return styStr;
59
- };
60
-
61
- /**
62
- * Add a style to the list of styles
63
- * @param {style} style
64
- */
65
- addStyle(style, overwrite=false) {
66
- // Call the subclass to create a new typed style object
67
- const newStyle = this.createStyle(style);
68
- const newStyleName = newStyle.name;
69
- if (!this.styleExists(newStyleName)) {
70
- this.styles.push(newStyle);
71
- } else if (overwrite) {
72
- // Overwrite The style existing style
73
- // This is used when loading files;
74
- // Standard styles already exist but should be overwritten by the incoming style
75
- this.styles.splice(this.getStyleIndex(newStyleName), 1, newStyle);
76
- }
77
- // DesignCore.Scene.saveRequired();
78
- }
79
-
80
- /**
81
- * Delete a style using the style index
82
- * @param {number} styleIndex
83
- * @returns undefined
84
- */
85
- deleteStyle(styleIndex) {
86
- if (this.styles[styleIndex] === undefined) {
87
- return;
88
- }
89
-
90
- const styleToDelete = this.getStyleByIndex(styleIndex).name;
91
-
92
- // Can't delete indelible styles (Standard Text Style, Layer 0)
93
- if (this.indelibleStyles.some((style) => style.toUpperCase() === styleToDelete.toUpperCase())) {
94
- DesignCore.Core.notify(`${styleToDelete} ${Strings.Message.CANNOTBEDELETED}`);
95
- return;
96
- }
97
-
98
- // Can't delete current style
99
- if (styleToDelete.toUpperCase() === this.currentstyle.toUpperCase()) {
100
- DesignCore.Core.notify(Strings.Message.CSTYLEDELETE);
101
- return;
102
- }
103
-
104
- // delete all item using the selected style
105
- this.deleteStyleFromScene(styleToDelete);
106
-
107
- // Delete The style
108
- this.styles.splice(styleIndex, 1);
109
- }
110
-
111
- /**
112
- * Delete all items that use style
113
- * @param {string} style
114
- */
115
- deleteStyleFromScene(style) {
116
- const selectionSet = [];
117
-
118
- for (let i = 0; i <DesignCore.Scene.items.length; i++) {
119
- if (DesignCore.Scene.items[i][this.styleProperty] === style) {
120
- selectionSet.push(i);
121
- }
122
- }
123
-
124
- // sort the selection in descending order
125
- selectionSet.sort((a, b)=>b-a);
126
-
127
- for (let j = 0; j < selectionSet.length; j++) {
128
- DesignCore.Scene.items.splice((selectionSet[j]), 1);
129
- }
130
- }
131
-
132
- /**
133
- * Get the name of the current style
134
- */
135
- getCstyle() {
136
- return this.currentstyle;
137
- }
138
-
139
- /**
140
- * Set the current style
141
- * @param {string} cstyle
142
- */
143
- setCstyle(cstyle) {
144
- if (this.getStyleByName(cstyle) !== undefined) {
145
- this.currentstyle = cstyle;
146
- }
147
- }
148
-
149
- /**
150
- * Check if a style with styleName exists
151
- * @param {string} styleName
152
- * @returns true or false
153
- */
154
- styleExists(styleName) {
155
- const styleExists = this.styles.some((el) => el.name.toUpperCase() === styleName.toUpperCase());
156
- return styleExists;
157
- }
158
-
159
- /**
160
- * Ensure that used styles and default styles exist
161
- */
162
- checkStyles() {
163
- if (!this.styleCount()) {
164
- this.addStandardStyles();
165
- }
166
-
167
- for (let i = 0; i < DesignCore.Scene.items.length; i++) {
168
- const style = (DesignCore.Scene.getItem(i)[this.styleProperty]);
169
- this.addStyle({
170
- 'name': style,
171
- });
172
- }
173
- }
174
-
175
- /**
176
- * Clear all existing styles
177
- */
178
- clearStyles() {
179
- this.styles = [];
180
- }
181
-
182
- /**
183
- * Find the index of styleName
184
- * @param {string} styleName
185
- * @returns index of the style or -1 if style doesn't exist
186
- */
187
- getStyleIndex(styleName) {
188
- return this.styles.findIndex((style) => style.name.toUpperCase() === styleName.toUpperCase());
189
- }
190
-
191
- /**
192
- * get a style matching stylename
193
- * @param {string} styleName
194
- * @returns style object
195
- */
196
- getStyleByName(styleName) {
197
- for (let i = 0; i < this.styleCount(); i++) {
198
- if (this.styles[i].name.toUpperCase() === styleName.toUpperCase()) {
199
- return this.styles[i];
200
- }
201
- }
202
-
203
- const msg = 'Invalid Style Name';
204
- const err = (`${this.constructor.name} - ${msg}: ${styleName}`);
205
- throw Error(err);
206
-
207
- // return;
208
- }
209
-
210
- /**
211
- * Get the style from an index
212
- * @param {number} styleIndex
213
- * @returns
214
- */
215
- getStyleByIndex(styleIndex) {
216
- return this.styles[styleIndex];
217
- }
218
-
219
-
220
- /**
221
- * Rename the style at index with newName
222
- * @param {number} styleIndex
223
- * @param {string} newName
224
- * @returns undefined
225
- */
226
- renameStyle(styleIndex, newName) {
227
- const styleToRename = this.getStyleByIndex(styleIndex).name;
228
-
229
- // make sure it is a new name
230
- if (styleToRename.toUpperCase() === newName.toUpperCase()) {
231
- return;
232
- }
233
-
234
- // Can't rename indelible styles (Standard Text Style, Layer 0)
235
- if (this.indelibleStyles.some((style) => style.toUpperCase() === styleToRename.toUpperCase())) {
236
- DesignCore.Core.notify(`${styleToRename} ${Strings.Message.CANNOTBERENAMED}`);
237
- return;
238
- }
239
-
240
- // Can't rename indelible styles (Standard Text Style, Layer 0)
241
- if (this.indelibleStyles.some((style) => style.toUpperCase() === newName.toUpperCase())) {
242
- DesignCore.Core.notify(`${newName} ${Strings.Message.CANNOTBERENAMED}`);
243
- return;
244
- }
245
-
246
- const newUniqueName = this.getUniqueName(newName);
247
-
248
- const currentStyleName = this.styles[styleIndex].name;
249
- this.styles[styleIndex].name = newUniqueName;
250
-
251
- // update all scene items with the new style value
252
- this.updateSceneStyle(currentStyleName, newUniqueName);
253
-
254
- // if the style to change is the current style, update the currentstyle property
255
- if (currentStyleName === this.currentstyle) {
256
- this.setCstyle(newUniqueName);
257
- }
258
- }
259
-
260
- /**
261
- * Update all items that use style
262
- * @param {string} oldStyleName
263
- * @param {string} newStyleName
264
- */
265
- updateSceneStyle(oldStyleName, newStyleName) {
266
- for (let i = 0; i <DesignCore.Scene.items.length; i++) {
267
- if (DesignCore.Scene.items[i][this.styleProperty] === oldStyleName) {
268
- DesignCore.Scene.items[i][this.styleProperty] = newStyleName;
269
- }
270
- }
271
- }
272
-
273
- /**
274
- * Update the style property with value
275
- * @param {number} styleIndex
276
- * @param {string} property
277
- * @param {any} value
278
- */
279
- updateStyle(styleIndex, property, value) {
280
- // check of the index exists
281
- if (this.styles[styleIndex] === undefined) {
282
- const msg = 'Invalid Style Index';
283
- const err = (`${this.type} - ${msg}`);
284
- throw Error(err);
285
- }
286
-
287
- if (this.styles[styleIndex][property] === undefined) {
288
- const msg = 'Invalid Style Property';
289
- const err = (`${this.type} - ${msg}`);
290
- throw Error(err);
291
- }
292
-
293
- if (property.toUpperCase() === 'NAME') {
294
- this.renameStyle(styleIndex, value);
295
- } else {
296
- this.styles[styleIndex][property] = value;
297
- }
298
- }
299
- }
@@ -1,22 +0,0 @@
1
- import {Block} from '../../core/entities/block.js';
2
- import {Line} from '../../core/entities/line.js';
3
- import {Point} from '../../core/entities/point.js';
4
-
5
- test('Test Block.boundingBox', () => {
6
- const block = new Block();
7
- const line = new Line({points: [new Point(101, 102), new Point(201, 202)]});
8
- block.addItem(line);
9
-
10
- expect(block.boundingBox().xMin).toBeCloseTo(101);
11
- expect(block.boundingBox().xMax).toBeCloseTo(201);
12
- expect(block.boundingBox().yMin).toBeCloseTo(102);
13
- expect(block.boundingBox().yMax).toBeCloseTo(202);
14
-
15
- const line2 = new Line({points: [new Point(1001, 1002), new Point(2001, 2002)]});
16
- block.addItem(line2);
17
-
18
- expect(block.boundingBox().xMin).toBeCloseTo(101);
19
- expect(block.boundingBox().xMax).toBeCloseTo(2001);
20
- expect(block.boundingBox().yMin).toBeCloseTo(102);
21
- expect(block.boundingBox().yMax).toBeCloseTo(2002);
22
- });
@@ -1,19 +0,0 @@
1
- import {DimStyle} from '../../core/styles/dimStyle';
2
-
3
- test('Test DimStyle.getValue', () => {
4
- const style = new DimStyle();
5
- expect(style.getValue('DIMSE1')).toBe(false);
6
- expect(style.getValue('DIMASZ')).toBe(2.5);
7
- });
8
-
9
- test('Test DimStyle.vertical', () => {
10
- const style = new DimStyle();
11
- expect(style.vertical).toBe(false);
12
- expect(style.standardFlags).toBe(0);
13
-
14
- style.vertical = true;
15
- expect(style.vertical).toBe(true);
16
- expect(style.standardFlags).toBe(4);
17
- });
18
-
19
-
@@ -1,150 +0,0 @@
1
- import {Core} from '../../core/core/core.js';
2
- import {Point} from '../../core/entities/point.js';
3
-
4
- const core = new Core();
5
- const layerManager = core.layerManager;
6
-
7
- test('Test LayerManager.getStyles', () => {
8
- const layers = layerManager.getStyles();
9
- expect(layers).toHaveLength(2);
10
-
11
- expect(layers[0]).toHaveProperty('name', '0');
12
- expect(layers[1]).toHaveProperty('name', 'DEFPOINTS');
13
- });
14
-
15
- test('Test LayerManager.styleCount', () => {
16
- const count = layerManager.styleCount();
17
- expect(count).toBe(2);
18
- });
19
-
20
- test('Test LayerManager.newStyle', () => {
21
- const count = layerManager.styleCount();
22
- layerManager.newStyle();
23
- expect(layerManager.styleCount()).toBe(count + 1);
24
- });
25
-
26
- test('Test LayerManager.getUniqueName', () => {
27
- // existing defpoints layer
28
- let name = layerManager.getUniqueName('DEFPOINTS');
29
- expect(name).toBe('DEFPOINTS_1');
30
- // existing NEW_LAYER layer
31
- name = layerManager.getUniqueName('NEW_STYLE');
32
- expect(name).toBe('NEW_STYLE_1');
33
- // unique layer
34
- name = layerManager.getUniqueName('UNIQUE_LAYER');
35
- expect(name).toBe('UNIQUE_LAYER');
36
- });
37
-
38
- test('Test LayerManager.addStyle', () => {
39
- const count = layerManager.styleCount();
40
- layerManager.addStyle({'name': 'test', 'colour': '#00BFFF'});
41
- expect(layerManager.styleCount()).toBe(count + 1);
42
- });
43
-
44
- test('Test LayerManager.deleteStyle', () => {
45
- const count = layerManager.styleCount();
46
- // defpoints can't be deleted
47
- layerManager.deleteStyle('DEFPOINTS');
48
- expect(layerManager.styleCount()).toBe(count);
49
-
50
- // clayer can't be deleted
51
- layerManager.deleteStyle(layerManager.getCstyle());
52
- expect(layerManager.styleCount()).toBe(count);
53
-
54
- // test should be deleted
55
- layerManager.deleteStyle(layerManager.getStyleIndex('test'));
56
- expect(layerManager.styleCount()).toBe(count - 1);
57
- });
58
-
59
- test('Test LayerManager.deleteStyle', () => {
60
- const count = layerManager.styleCount();
61
- layerManager.deleteStyle(2);
62
- expect(layerManager.styleCount()).toBe(count - 1);
63
- });
64
-
65
- test('Test LayerManager.getCstyle', () => {
66
- const clayer = layerManager.getCstyle();
67
- expect(clayer).toBe('0');
68
- });
69
-
70
- test('Test LayerManager.setCstyle', () => {
71
- const layer = layerManager.getStyles().at(-1).name;
72
- layerManager.setCstyle(layer);
73
- expect(layerManager.getCstyle()).toBe(layer);
74
- });
75
-
76
- test('Test LayerManager.styleExists', () => {
77
- expect(layerManager.styleExists('DEFPOINTS')).toBe(true);
78
- expect(layerManager.styleExists('OBSCURE_LAYER_NAME')).toBe(false);
79
- });
80
-
81
- test('Test LayerManager.checkStyles', () => {
82
- layerManager.layers = [];
83
-
84
- const newStyleName = 'checkStyles';
85
- const startPoint = new Point();
86
- const endPoint = new Point(10, 10);
87
-
88
- const data = {
89
- points: [startPoint, endPoint],
90
- colour: '#FFFFFF',
91
- layer: newStyleName,
92
- };
93
-
94
- core.scene.addItem('Line', data, false);
95
-
96
- layerManager.checkStyles();
97
- const layers = layerManager.getStyles();
98
- expect(layers).toHaveLength(3);
99
-
100
- expect(layers[0]).toHaveProperty('name', '0');
101
- expect(layers[1]).toHaveProperty('name', 'DEFPOINTS');
102
- expect(layers[2]).toHaveProperty('name', newStyleName);
103
- });
104
-
105
- test('Test LayerManager.addStandardStyles', () => {
106
- layerManager.clearStyles();
107
-
108
- layerManager.addStandardStyles();
109
-
110
- const layers = layerManager.getStyles();
111
- expect(layers).toHaveLength(2);
112
-
113
- expect(layers[0]).toHaveProperty('name', '0');
114
- expect(layers[1]).toHaveProperty('name', 'DEFPOINTS');
115
- });
116
-
117
- test('Test LayerManager.getStyleIndex', () => {
118
- layerManager.addStyle({'name': 'addStyle', 'colour': '#00BFFF'});
119
- // get index for test layer - should be the last layer
120
- expect(layerManager.getStyleIndex('addStyle')).toBe(layerManager.styleCount() - 1);
121
- // get index for a layer that doesn't exist
122
- expect(layerManager.getStyleIndex('no-exist')).toBe(-1);
123
- });
124
-
125
- test('Test LayerManager.getStyleByName', () => {
126
- layerManager.addStyle({'name': 'test'});
127
- const layer = layerManager.getStyleByName('test');
128
- expect(layer.name).toBe('test');
129
- // get a layer that doesn't exist
130
- expect(() => {
131
- layerManager.getStyleByName('no-exist');
132
- }).toThrow();
133
- });
134
-
135
- test('Test LayerManager.getStyleByIndex', () => {
136
- const testLayer = layerManager.getStyleByName('test');
137
- const layer = layerManager.getStyleByIndex(layerManager.getStyleIndex('test'));
138
- expect(testLayer === layer).toBe(true);
139
- // get a layer that doesn't exist
140
- expect(layerManager.getStyleByIndex(1000)).toBeUndefined();
141
- });
142
-
143
- test('Test LayerManager.renameStyle', () => {
144
- const index = layerManager.getStyleIndex('test');
145
- const newStylename = 'RENAMED_TEST';
146
- layerManager.renameStyle(index, newStylename);
147
-
148
- expect(layerManager.getStyleIndex(newStylename)).toBe(index);
149
- expect(layerManager.getStyleIndex('test')).toBe(-1);
150
- });
@@ -1,33 +0,0 @@
1
- import {Style} from '../../core/styles/style';
2
-
3
- test('Test Style.vertical', () => {
4
- const style = new Style();
5
- expect(style.vertical).toBe(false);
6
- expect(style.standardFlags).toBe(0);
7
-
8
- style.vertical = true;
9
- expect(style.vertical).toBe(true);
10
- expect(style.standardFlags).toBe(4);
11
- });
12
-
13
-
14
- test('Test Style.backwards', () => {
15
- const style = new Style();
16
- expect(style.backwards).toBe(false);
17
- expect(style.flags).toBe(0);
18
-
19
- style.backwards = true;
20
- expect(style.backwards).toBe(true);
21
- expect(style.flags).toBe(2);
22
- });
23
-
24
- test('Test Style.upsideDown', () => {
25
- const style = new Style();
26
- expect(style.upsideDown).toBe(false);
27
- expect(style.flags).toBe(0);
28
-
29
- style.upsideDown = true;
30
- expect(style.upsideDown).toBe(true);
31
- expect(style.flags).toBe(4);
32
- });
33
-