@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,298 @@
1
+ import { BaseDimension } from './baseDimension.js';
2
+ import { AlignedDimension } from './alignedDimension.js';
3
+ import { DiametricDimension } from './diametricDimension.js';
4
+ import { AngularDimension } from './angularDimension.js';
5
+ import { RadialDimension } from './radialDimension.js';
6
+ import { RotatedDimension } from './rotatedDimension.js';
7
+
8
+ import { Arc } from '../entities/arc.js';
9
+ import { Circle } from '../entities/circle.js';
10
+ import { Line } from '../entities/line.js';
11
+ import { BasePolyline } from '../entities/basePolyline.js';
12
+ import { Point } from '../entities/point.js';
13
+
14
+ import { Strings } from '../lib/strings.js';
15
+ import { Input, PromptOptions } from '../lib/inputManager.js';
16
+ import { Logging } from '../lib/logging.js';
17
+ import { Intersection } from '../lib/intersect.js';
18
+
19
+ import { DesignCore } from '../designCore.js';
20
+ import { SingleSelection } from '../lib/selectionManager.js';
21
+ import { Utils } from '../lib/utils.js';
22
+ import { DimType } from '../properties/dimType.js';
23
+
24
+ /**
25
+ * Dimension Entity Class
26
+ * @extends BaseDimension
27
+ */
28
+ export class Dimension extends BaseDimension {
29
+ /**
30
+ * Create a Dimension
31
+ * @param {Array} data
32
+ */
33
+ constructor(data) {
34
+ super(data);
35
+
36
+ // map dimensions type to the class name
37
+ this.dimensionMap = {
38
+ 0: RotatedDimension,
39
+ 1: AlignedDimension,
40
+ 2: AngularDimension,
41
+ 3: DiametricDimension,
42
+ 4: RadialDimension,
43
+ 5: null, // 5 = Angular 3 point;
44
+ 6: null, // 6 = Ordinate;
45
+ };
46
+
47
+ this.selectedItems = [];
48
+
49
+ if (data) {
50
+ const item = new this.dimensionMap[DimType.getBaseType(this.dimType.getBaseDimType())](data);
51
+
52
+ // find the block linked to this dimension
53
+ const linkedBlockIndex = DesignCore.Scene.entities.find('BLOCK', 'name', data[2]);
54
+
55
+ if (linkedBlockIndex.length) {
56
+ // remove the block from the scene, dimensions manage their block internally
57
+ DesignCore.Scene.entities.remove(linkedBlockIndex[0]);
58
+ }
59
+
60
+ return item;
61
+ }
62
+ }
63
+
64
+ /**
65
+ * Register the command
66
+ * @return {Object}
67
+ * command = name of the command
68
+ * shortcut = shortcut for the command
69
+ * type = type to group command in toolbars (omitted if not shown)
70
+ */
71
+ static register() {
72
+ const command = { command: 'Dimension', shortcut: 'DIM' };
73
+ return command;
74
+ }
75
+
76
+ /**
77
+ * Execute method
78
+ * executes the workflow, requesting input required to create an entity
79
+ */
80
+ async execute() {
81
+ try {
82
+ let inputValid = false;
83
+ this.dimensionStyle = DesignCore.DimStyleManager.getCstyle();
84
+
85
+ while (!inputValid) {
86
+ DesignCore.Scene.selectionManager.reset();
87
+ const options = new PromptOptions(`${Strings.Input.START} ${Strings.Strings.OR} ${Strings.Input.SELECT}`, [Input.Type.POINT, Input.Type.SINGLESELECTION]);
88
+ const input1 = await DesignCore.Scene.inputManager.requestInput(options);
89
+ if (input1 === undefined) return;
90
+
91
+ if (input1 instanceof Point) {
92
+ inputValid = true;
93
+ this.dimType.setDimType(1);
94
+ // select a second point to define the dimension
95
+ const op1 = new PromptOptions(Strings.Input.END, [Input.Type.POINT]);
96
+ const pt14 = await DesignCore.Scene.inputManager.requestInput(op1);
97
+ if (pt14 === undefined) return;
98
+ // Create a temporary line using the selected points
99
+ const tempLine = new Line({ points: [input1, pt14] });
100
+ this.selectedItems.push(tempLine);
101
+ }
102
+
103
+ if (input1 instanceof SingleSelection) {
104
+ const selectedItem = DesignCore.Scene.entities.get(input1.selectedItemIndex);
105
+
106
+ // check the selected entity is supported
107
+ if ([Line, Circle, Arc, BasePolyline].some((entity) => selectedItem instanceof entity)) {
108
+ // set the dimension type
109
+ if (selectedItem instanceof Line) {
110
+ this.dimType.setDimType(1);
111
+ this.selectedItems.push(selectedItem);
112
+ inputValid = true;
113
+ }
114
+
115
+ if (selectedItem instanceof Circle) {
116
+ this.dimType.setDimType(3);
117
+ this.selectedItems.push(selectedItem);
118
+ inputValid = true;
119
+ }
120
+
121
+ if (selectedItem instanceof Arc) {
122
+ this.dimType.setDimType(4);
123
+ this.selectedItems.push(selectedItem);
124
+ inputValid = true;
125
+ }
126
+
127
+ if (selectedItem instanceof BasePolyline) {
128
+ // get the segment closest to the mouse point
129
+ const segment = selectedItem.getClosestSegment(input1.selectedPoint);
130
+
131
+ if (segment instanceof Line) {
132
+ this.dimType.setDimType(1);
133
+ this.selectedItems.push(segment);
134
+ inputValid = true;
135
+ }
136
+
137
+ if (segment instanceof Arc) {
138
+ this.dimType.setDimType(4);
139
+ this.selectedItems.push(segment);
140
+ inputValid = true;
141
+ }
142
+ }
143
+ } else {
144
+ const msg = `${this.type} - ${Strings.Error.INVALIDTYPE}: ${selectedItem.type}`;
145
+ DesignCore.Core.notify(msg);
146
+ DesignCore.Scene.selectionManager.reset();
147
+ }
148
+ }
149
+ }
150
+
151
+ // select a second line to make a angular dimension or a point to position the dimension text
152
+ // loop until this.points contains a point with sequence 11 i.e. a text position
153
+ while (!this.points.some((point) => point.sequence === 11)) {
154
+ // default prompt: select a location for the text position
155
+ let op2 = new PromptOptions(Strings.Input.DIMENSION, [Input.Type.POINT]);
156
+
157
+ // Angular dimension prompt: select a second line for an angular dimension or location for the text position
158
+ if ((this.selectedItems[0] instanceof Line) && this.selectedItems.length < 2) {
159
+ op2 = new PromptOptions(`${Strings.Input.DIMENSION} or ${Strings.Input.SELECT}`, [Input.Type.POINT, Input.Type.SINGLESELECTION]);
160
+ }
161
+
162
+ // diametric prompt: select radial or diametric type dimension or location for the the text position
163
+ if (this.selectedItems[0] instanceof Circle) {
164
+ const options = this.dimType.getBaseDimType() === 3 ? ['Radius'] : ['Diameter'];
165
+ op2 = new PromptOptions(`${Strings.Input.DIMENSION}`, [Input.Type.POINT], options);
166
+ }
167
+
168
+ const input2 = await DesignCore.Scene.inputManager.requestInput(op2);
169
+ if (input2 === undefined) return;
170
+
171
+ if (Input.getType(input2) === Input.Type.POINT) {
172
+ const Pt11 = input2;
173
+
174
+ // if selected items are available, get the points from the selected items
175
+ // dimensions can be created from point selection only, therefore selected items may not be available
176
+ if (this.selectedItems.length) {
177
+ // for linear dimensions, determine if aligned or rotated based on mouse position
178
+ if (this.dimType.getBaseDimType() === 0 || this.dimType.getBaseDimType() === 1) {
179
+ const Pt13 = this.selectedItems[0].points[0];
180
+ const Pt14 = this.selectedItems[0].points[1];
181
+ const linearDimTypeNumber = this.getLinearDimensionType(Pt13, Pt14, Pt11);
182
+ this.dimType.setDimType(linearDimTypeNumber);
183
+ }
184
+
185
+ const dimensionType = this.dimensionMap[this.dimType.getBaseDimType()]; // TODO: use this.dimensionMap.name?
186
+ this.points.push(...dimensionType.getPointsFromSelection(this.selectedItems, Pt11));
187
+ }
188
+ }
189
+
190
+ if (Input.getType(input2) === Input.Type.STRING) {
191
+ // options are converted to input in the prompt options class
192
+ if (input2 === 'Diameter') {
193
+ this.dimType.setDimType(3);
194
+ }
195
+
196
+ if (input2 === 'Radius') {
197
+ this.dimType.setDimType(4);
198
+ }
199
+ }
200
+
201
+ if (Input.getType(input2) === Input.Type.SINGLESELECTION) {
202
+ let selectedItem2 = DesignCore.Scene.entities.get(input2.selectedItemIndex);
203
+ if ([Line, BasePolyline].some((entity) => selectedItem2 instanceof entity)) {
204
+ // if a polyline is selected, get the segment closest to the mouse point
205
+ if (selectedItem2 instanceof BasePolyline) {
206
+ // get the segment closest to the mouse point
207
+ const segment = selectedItem2.getClosestSegment(input2.selectedPoint);
208
+
209
+ if (segment instanceof Line) {
210
+ selectedItem2 = segment;
211
+ }
212
+ }
213
+ // Check lines intersect
214
+ const line1 = { start: this.selectedItems[0].points[0], end: this.selectedItems[0].points[1] };
215
+ const line2 = { start: selectedItem2.points[0], end: selectedItem2.points[1] };
216
+
217
+ // Check the lines are not parallel - Can't dimension parallel lines
218
+ const lineOneSlope = (line1.end.y - line1.start.y) / (line1.end.x - line1.start.x);
219
+ const lineTwoSlope = (line2.end.y - line2.start.y) / (line2.end.x - line2.start.x);
220
+
221
+ if (Utils.round(lineOneSlope) !== Utils.round(lineTwoSlope)) {
222
+ const intersect = Intersection.intersectSegmentSegment(line1.start, line1.end, line2.start, line2.end, false, true);
223
+ if (intersect.points.length >= 1) {
224
+ // add line to selection
225
+ this.selectedItems.push(selectedItem2);
226
+ // Two lines selected - switch to angular dimension
227
+ this.dimType.setDimType(2);
228
+ }
229
+ } else {
230
+ const msg = `${this.type} - ${Strings.Error.SELECTION}: ${Strings.Error.PARALLELLINES}`;
231
+ DesignCore.Core.notify(msg);
232
+ DesignCore.Scene.selectionManager.removeLastSelection();
233
+ }
234
+ } else {
235
+ const msg = `${this.type} - ${Strings.Error.INVALIDTYPE}: ${selectedItem2.type}`;
236
+ DesignCore.Core.notify(msg);
237
+ DesignCore.Scene.selectionManager.reset();
238
+ }
239
+ }
240
+ }
241
+
242
+ DesignCore.Scene.inputManager.executeCommand(this);
243
+ } catch (err) {
244
+ Logging.instance.error(`${this.type} - ${err}`);
245
+ }
246
+ }
247
+
248
+ /**
249
+ * Determine if linear dimension is aligned or rotated
250
+ * @param {Point} Pt13 - start point
251
+ * @param {Point} Pt14 - end point
252
+ * @param {Point} Pt11 - text position
253
+ * @return {number} 0 = rotated, 1 = aligned
254
+ */
255
+ getLinearDimensionType(Pt13, Pt14, Pt11) {
256
+ // generate the x and y delta values
257
+ const dx = Pt14.x - Pt13.x;
258
+ const dy = Pt14.y - Pt13.y;
259
+
260
+ const pntPerp = Pt11.perpendicular(Pt13, Pt14);
261
+ const isAligned = pntPerp.isOnLine(Pt13, Pt14);
262
+
263
+ if (!isAligned || Utils.round(dx) === 0 || Utils.round(dy) === 0) {
264
+ // Rotated dimension
265
+ return 0;
266
+ } else {
267
+ // Aligned dimension
268
+ return 1;
269
+ }
270
+ }
271
+
272
+ /**
273
+ * Preview the entity during creation
274
+ */
275
+ preview() {
276
+ if (this.selectedItems.length) {
277
+ let dimTypeNumber = this.dimType.getBaseDimType();
278
+
279
+ const Pt11 = DesignCore.Mouse.pointOnScene();
280
+ Pt11.sequence = 11;
281
+
282
+ if (dimTypeNumber === 0 || dimTypeNumber === 1) {
283
+ // for linear dimensions, determine if aligned or rotated based on mouse position
284
+ const Pt13 = this.selectedItems[0].points[0];
285
+ const Pt14 = this.selectedItems[0].points[1];
286
+ dimTypeNumber = this.getLinearDimensionType(Pt13, Pt14, Pt11);
287
+ }
288
+ // get the dimension class
289
+ const dimensionType = this.dimensionMap[dimTypeNumber];
290
+ // get the dimension type as a string
291
+ const dimensionTypeString = dimensionType.register().command;
292
+ // get the points for the dimension
293
+ const points = dimensionType.getPointsFromSelection(this.selectedItems, Pt11);
294
+ // create the temporary dimension
295
+ DesignCore.Scene.tempEntities.create(dimensionTypeString, { points: points, dimensionStyle: this.dimensionStyle });
296
+ }
297
+ }
298
+ }
@@ -0,0 +1,29 @@
1
+
2
+ import { RotatedDimension } from './rotatedDimension.js';
3
+
4
+ /**
5
+ * Linear Dimension Entity Class
6
+ * This is a proxy command to the Rotated Dimension
7
+ */
8
+ export class LinearDimension {
9
+ /**
10
+ * Create an Linear Dimension
11
+ * @param {Array} data
12
+ */
13
+ constructor(data) {
14
+ const dimension = new RotatedDimension(data);
15
+ return dimension;
16
+ }
17
+
18
+ /**
19
+ * Register the command
20
+ * @return {Object}
21
+ * command = name of the command
22
+ * shortcut = shortcut for the command
23
+ * type = type to group command in toolbars (omitted if not shown)
24
+ */
25
+ static register() {
26
+ const command = { command: 'LinearDimension', shortcut: 'DIMLIN' };
27
+ return command;
28
+ }
29
+ }
@@ -0,0 +1,78 @@
1
+
2
+ import { DXFFile } from '../lib/dxf/dxfFile.js';
3
+ import { BaseCircularDimension } from './baseCircularDimension.js';
4
+
5
+ /**
6
+ * Radial Dimension Entity Class
7
+ * @extends BaseCircularDimension
8
+ */
9
+ export class RadialDimension extends BaseCircularDimension {
10
+ /**
11
+ * Create a Radial Dimension
12
+ * @param {Array} data
13
+ */
14
+ constructor(data) {
15
+ super(data);
16
+ this.dimType.setDimType(4); // Radial dimension
17
+ }
18
+
19
+ /**
20
+ * Register the command
21
+ * @return {Object}
22
+ * command = name of the command
23
+ * shortcut = shortcut for the command
24
+ * type = type to group command in toolbars (omitted if not shown)
25
+ */
26
+ static register() {
27
+ const command = { command: 'RadialDimension', shortcut: 'DIMRAD' };
28
+ return command;
29
+ }
30
+
31
+ /**
32
+ * Get sequenced points from user selection
33
+ * @param {any} items
34
+ * @param {Point} textPos
35
+ * @return {Array} array of points
36
+ */
37
+ static getPointsFromSelection(items, textPos) {
38
+ const item = items[0];
39
+ const Pt11 = textPos;
40
+ Pt11.sequence = 11;
41
+ const Pt10 = item.points[0]; // Centre
42
+ Pt10.sequence = 10;
43
+ const Pt15 = Pt10.project(Pt10.angle(Pt11), item.getRadius());// Radius
44
+ Pt15.sequence = 15;
45
+
46
+ const points = [Pt10, Pt15, Pt11];
47
+ return points;
48
+ }
49
+
50
+ /**
51
+ * Write the entity to file in the dxf format
52
+ * @param {DXFFile} file
53
+ */
54
+ dxf(file) {
55
+ const Pt10 = this.getPointBySequence(this.points, 10);
56
+ const Pt11 = this.getPointBySequence(this.points, 11);
57
+ const Pt15 = this.getPointBySequence(this.points, 15);
58
+
59
+ file.writeGroupCode('0', 'DIMENSION');
60
+ file.writeGroupCode('5', this.handle, DXFFile.Version.R2000); // Handle
61
+ file.writeGroupCode('100', 'AcDbEntity', DXFFile.Version.R2000);
62
+ file.writeGroupCode('100', 'AcDbDimension', DXFFile.Version.R2000);
63
+ file.writeGroupCode('8', this.layer);
64
+ // file.writeGroupCode('2', this.blockName); // Block not required
65
+ file.writeGroupCode('10', Pt10.x); // X - Start of Dimension Line
66
+ file.writeGroupCode('20', Pt10.y); // Y
67
+ file.writeGroupCode('30', '0.0'); // Z
68
+ file.writeGroupCode('11', Pt11.x); // X - Text Midpoint
69
+ file.writeGroupCode('21', Pt11.y); // Y
70
+ file.writeGroupCode('31', '0.0'); // Z
71
+ file.writeGroupCode('70', this.dimType.getDimType()); // DIMENSION TYPE
72
+ file.writeGroupCode('3', this.dimensionStyle); // DIMENSION STYLE
73
+ file.writeGroupCode('100', 'AcDbRadialDimension', DXFFile.Version.R2000);
74
+ file.writeGroupCode('15', Pt15.x); // X - End of Dimension Line
75
+ file.writeGroupCode('25', Pt15.y); // Y
76
+ file.writeGroupCode('35', '0.0'); // Z
77
+ }
78
+ }
@@ -0,0 +1,167 @@
1
+ import { Strings } from '../lib/strings.js';
2
+ import { Line } from '../entities/line.js';
3
+ import { Input, PromptOptions } from '../lib/inputManager.js';
4
+ import { Logging } from '../lib/logging.js';
5
+ import { DXFFile } from '../lib/dxf/dxfFile.js';
6
+ import { Point } from '../entities/point.js';
7
+ import { BaseLinearDimension } from './baseLinearDimension.js';
8
+
9
+ import { DesignCore } from '../designCore.js';
10
+
11
+
12
+ /**
13
+ * Rotated Dimension Entity Class
14
+ * @extends BaseLinearDimension
15
+ */
16
+ export class RotatedDimension extends BaseLinearDimension {
17
+ /**
18
+ * Create an Rotated Dimension
19
+ * @param {Array} data
20
+ */
21
+ constructor(data) {
22
+ super(data);
23
+ this.dimType.setDimType(0); // Rotated dimension
24
+ }
25
+
26
+ /**
27
+ * Register the command
28
+ * @return {Object}
29
+ * command = name of the command
30
+ * shortcut = shortcut for the command
31
+ * type = type to group command in toolbars (omitted if not shown)
32
+ */
33
+ static register() {
34
+ const command = { command: 'RotatedDimension', shortcut: 'DIMROT' };
35
+ return command;
36
+ }
37
+
38
+ /**
39
+ * Execute method
40
+ * executes the workflow, requesting input required to create an entity
41
+ */
42
+ async execute() {
43
+ try {
44
+ DesignCore.Scene.selectionManager.reset();
45
+ this.dimensionStyle = DesignCore.DimStyleManager.getCstyle();
46
+ this.dimType.setDimType(0); // Rotated dimension
47
+
48
+ const opAngle = new PromptOptions(Strings.Input.ROTATION, [Input.Type.NUMBER]);
49
+ const angleValue = await DesignCore.Scene.inputManager.requestInput(opAngle);
50
+ this.linearDimAngle = Number(angleValue) || 0;
51
+
52
+ const op = new PromptOptions(Strings.Input.START, [Input.Type.POINT]);
53
+ const pt13 = await DesignCore.Scene.inputManager.requestInput(op);
54
+ pt13.sequence = 13;
55
+ this.points.push(pt13);
56
+
57
+ const op1 = new PromptOptions(Strings.Input.END, [Input.Type.POINT]);
58
+ const pt14 = await DesignCore.Scene.inputManager.requestInput(op1);
59
+ pt14.sequence = 14;
60
+ this.points.push(pt14);
61
+
62
+ const op2 = new PromptOptions(Strings.Input.DIMENSION, [Input.Type.POINT]);
63
+ const pt11 = await DesignCore.Scene.inputManager.requestInput(op2);
64
+ pt11.sequence = 11;
65
+ this.points.push(pt11);
66
+
67
+ const tempLine = new Line({ points: [pt13, pt14] });
68
+ this.points = RotatedDimension.getPointsFromSelection([tempLine], pt11, this.linearDimAngle);
69
+
70
+ DesignCore.Scene.inputManager.executeCommand(this);
71
+ } catch (err) {
72
+ Logging.instance.error(`${this.type} - ${err}`);
73
+ }
74
+ }
75
+
76
+ /**
77
+ * Get sequenced points from user selection
78
+ * @param {any} items
79
+ * @param {Point} textPos
80
+ * @param {number} angle - rotation angle in degrees (default 0 = horizontal)
81
+ * @return {Array} array of points
82
+ */
83
+ static getPointsFromSelection(items, textPos, angle = 0) {
84
+ const points = [];
85
+ const item = items[0];
86
+
87
+ const Pt13 = item.points[0];
88
+ Pt13.sequence = 13;
89
+ points.push(Pt13);
90
+
91
+ const Pt14 = item.points[1];
92
+ Pt14.sequence = 14;
93
+ points.push(Pt14);
94
+
95
+ const Pt10 = new Point();
96
+ Pt10.sequence = 10;
97
+
98
+ const Pt11 = textPos;
99
+ Pt11.sequence = 11;
100
+ points.push(Pt11);
101
+
102
+ // Project Pt14 onto the dimension line through Pt11 at the rotation angle
103
+ // to find the arrow definition point Pt10
104
+ const angleRad = angle * (Math.PI / 180);
105
+ const dimLineDir = Pt11.project(angleRad, 1);
106
+ const projected = Pt14.perpendicular(Pt11, dimLineDir);
107
+ Pt10.x = projected.x;
108
+ Pt10.y = projected.y;
109
+
110
+ points.push(Pt10);
111
+ return points;
112
+ }
113
+
114
+ /**
115
+ * Preview the entity during creation
116
+ */
117
+ preview() {
118
+ if (this.points.length === 1) {
119
+ const mousePoint = DesignCore.Mouse.pointOnScene();
120
+ const points = [this.points.at(0), mousePoint];
121
+ DesignCore.Scene.tempEntities.create('Line', { points: points });
122
+ }
123
+
124
+ if (this.points.length > 1) {
125
+ const pt11 = DesignCore.Mouse.pointOnScene();
126
+ pt11.sequence = 11;
127
+ const tempLine = new Line({ points: [this.points[0], this.points[1]] });
128
+ const points = RotatedDimension.getPointsFromSelection([tempLine], pt11, this.linearDimAngle);
129
+ DesignCore.Scene.tempEntities.create(this.type, { points: points, dimensionStyle: this.dimensionStyle });
130
+ }
131
+ }
132
+
133
+ /**
134
+ * Write the entity to file in the dxf format
135
+ * @param {DXFFile} file
136
+ */
137
+ dxf(file) {
138
+ const Pt10 = this.getPointBySequence(this.points, 10);
139
+ const Pt11 = this.getPointBySequence(this.points, 11);
140
+ const Pt13 = this.getPointBySequence(this.points, 13);
141
+ const Pt14 = this.getPointBySequence(this.points, 14);
142
+
143
+ file.writeGroupCode('0', 'DIMENSION');
144
+ file.writeGroupCode('5', this.handle, DXFFile.Version.R2000); // Handle
145
+ file.writeGroupCode('100', 'AcDbEntity', DXFFile.Version.R2000);
146
+ file.writeGroupCode('100', 'AcDbDimension', DXFFile.Version.R2000);
147
+ file.writeGroupCode('8', this.layer);
148
+ // file.writeGroupCode('2', this.blockName); // Block not required
149
+ file.writeGroupCode('10', Pt10.x); // X - definition / arrow point
150
+ file.writeGroupCode('20', Pt10.y); // Y
151
+ file.writeGroupCode('30', '0.0'); // Z
152
+ file.writeGroupCode('11', Pt11.x); // X - text midpoint
153
+ file.writeGroupCode('21', Pt11.y); // Y
154
+ file.writeGroupCode('31', '0.0'); // Z
155
+ file.writeGroupCode('70', this.dimType.getDimType()); // DIMENSION TYPE
156
+ file.writeGroupCode('3', this.dimensionStyle); // DIMENSION STYLE
157
+ file.writeGroupCode('100', 'AcDbAlignedDimension', DXFFile.Version.R2000);
158
+ file.writeGroupCode('13', Pt13.x); // X - start point of first extension line
159
+ file.writeGroupCode('23', Pt13.y); // Y
160
+ file.writeGroupCode('33', '0.0'); // Z
161
+ file.writeGroupCode('14', Pt14.x); // X - start point of second extension line
162
+ file.writeGroupCode('24', Pt14.y); // Y
163
+ file.writeGroupCode('34', '0.0'); // Z
164
+ file.writeGroupCode('50', this.linearDimAngle); // Utils.radians2degrees(Pt13.angle(Pt14))); // Rotation angle
165
+ file.writeGroupCode('100', 'AcDbRotatedDimension', DXFFile.Version.R2000);
166
+ }
167
+ }