@design-core/core 0.0.6 → 50.1.0

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 (173) hide show
  1. package/.eslintrc.json +4 -0
  2. package/.github/workflows/DesignCoreQA.yml +3 -0
  3. package/TODO.md +49 -6
  4. package/core/core/core.js +0 -3
  5. package/core/designCore.js +1 -1
  6. package/core/dimensions/alignedDimension.js +12 -11
  7. package/core/dimensions/angularDimension.js +38 -37
  8. package/core/dimensions/{baseCircularDimension.js → circularDimensionBase.js} +22 -21
  9. package/core/dimensions/diametricDimension.js +14 -13
  10. package/core/dimensions/dimension.js +62 -55
  11. package/core/dimensions/{baseDimension.js → dimensionBase.js} +73 -107
  12. package/core/dimensions/{baseLinearDimension.js → linearDimensionBase.js} +15 -14
  13. package/core/dimensions/radialDimension.js +12 -11
  14. package/core/dimensions/rotatedDimension.js +20 -19
  15. package/core/entities/arc.js +123 -156
  16. package/core/entities/arctext.js +222 -184
  17. package/core/entities/circle.js +77 -99
  18. package/core/entities/entity.js +114 -93
  19. package/core/entities/hatch.js +346 -273
  20. package/core/entities/insert.js +68 -83
  21. package/core/entities/line.js +21 -142
  22. package/core/entities/lwpolyline.js +16 -11
  23. package/core/entities/point.js +19 -19
  24. package/core/entities/polyline.js +7 -7
  25. package/core/entities/{basePolyline.js → polylineBase.js} +47 -299
  26. package/core/entities/rectangle.js +3 -1
  27. package/core/entities/solid.js +6 -15
  28. package/core/entities/text.js +190 -201
  29. package/core/lib/auxiliary/rubberBand.js +32 -0
  30. package/core/lib/auxiliary/selectionWindow.js +63 -0
  31. package/core/lib/auxiliary/snapPoint.js +113 -0
  32. package/core/lib/auxiliary/trackingLine.js +76 -0
  33. package/core/lib/boundingBox.js +11 -11
  34. package/core/lib/canvas.js +232 -168
  35. package/core/lib/clipboard.js +9 -3
  36. package/core/lib/colour.js +16 -0
  37. package/core/lib/commandLine.js +1 -6
  38. package/core/lib/commandManager.js +18 -8
  39. package/core/lib/constants.js +28 -0
  40. package/core/lib/dxf/dxf.js +15 -14
  41. package/core/lib/dxf/dxfIterator.js +2 -2
  42. package/core/lib/entityManager.js +33 -26
  43. package/core/lib/inputManager.js +36 -12
  44. package/core/lib/intersect.js +25 -0
  45. package/core/lib/matrix.js +1 -1
  46. package/core/lib/patterns.js +9 -2
  47. package/core/lib/plotOptions.js +67 -0
  48. package/core/lib/polylineUtils.js +75 -0
  49. package/core/lib/renderers/cairoRenderer.js +371 -0
  50. package/core/lib/renderers/canvasRenderer.js +315 -0
  51. package/core/lib/renderers/pdfRenderer.js +366 -0
  52. package/core/lib/renderers/rendererBase.js +284 -0
  53. package/core/lib/renderers/svgRenderer.js +343 -0
  54. package/core/lib/scene.js +28 -6
  55. package/core/lib/selectionManager.js +20 -20
  56. package/core/lib/settings.js +4 -2
  57. package/core/lib/snapping.js +4 -191
  58. package/core/lib/stateManager.js +30 -1
  59. package/core/lib/utils.js +26 -7
  60. package/core/properties/entityProperties.js +104 -0
  61. package/core/properties/property.js +106 -2
  62. package/core/properties/propertyManager.js +60 -44
  63. package/core/tables/block.js +50 -81
  64. package/core/tables/dimStyle.js +5 -5
  65. package/core/tables/endblk.js +1 -1
  66. package/core/tables/layer.js +8 -0
  67. package/core/tables/ltypeManager.js +1 -1
  68. package/core/tables/styleManagerBase.js +3 -2
  69. package/core/tables/tableManagerBase.js +8 -3
  70. package/core/tables/vport.js +2 -2
  71. package/core/tools/chamfer.js +117 -143
  72. package/core/tools/chamferFilletBase.js +138 -37
  73. package/core/tools/copy.js +11 -11
  74. package/core/tools/copybase.js +3 -3
  75. package/core/tools/copyclip.js +3 -3
  76. package/core/tools/cornerEntity.js +2 -2
  77. package/core/tools/cutclip.js +3 -3
  78. package/core/tools/explode.js +7 -7
  79. package/core/tools/extend.js +138 -25
  80. package/core/tools/fillet.js +92 -189
  81. package/core/tools/matchProp.js +3 -12
  82. package/core/tools/mirror.js +15 -14
  83. package/core/tools/move.js +8 -8
  84. package/core/tools/offset.js +31 -33
  85. package/core/tools/pasteclip.js +1 -1
  86. package/core/tools/purge.js +10 -10
  87. package/core/tools/rotate.js +19 -16
  88. package/core/tools/scale.js +7 -7
  89. package/core/tools/trim.js +271 -29
  90. package/core/tools/zoom.js +1 -1
  91. package/cspell.json +321 -0
  92. package/jest.config.js +6 -0
  93. package/package.json +5 -3
  94. package/test/dimensions/alignedDimension.test.js +17 -10
  95. package/test/dimensions/angularDimension.test.js +13 -13
  96. package/test/dimensions/diametricDimension.test.js +15 -15
  97. package/test/dimensions/dimension.test.js +12 -12
  98. package/test/dimensions/{baseDimension.test.js → dimensionBase.test.js} +73 -12
  99. package/test/dimensions/linearDimensionBase.test.js +62 -0
  100. package/test/dimensions/radialDimension.test.js +15 -15
  101. package/test/dimensions/rotatedDimension.test.js +18 -11
  102. package/test/entities/arc.test.js +83 -86
  103. package/test/entities/arctext.test.js +184 -57
  104. package/test/entities/circle.test.js +68 -96
  105. package/test/entities/entity.test.js +42 -8
  106. package/test/entities/hatch.test.js +569 -96
  107. package/test/entities/insert.test.js +99 -4
  108. package/test/entities/line.test.js +15 -41
  109. package/test/entities/lwpolyline.test.js +104 -0
  110. package/test/entities/point.test.js +3 -3
  111. package/test/entities/polyline.test.js +11 -0
  112. package/test/entities/{basePolyline.test.js → polylineBase.test.js} +192 -57
  113. package/test/entities/rectangle.test.js +11 -0
  114. package/test/entities/solid.test.js +1 -1
  115. package/test/entities/text.test.js +302 -77
  116. package/test/integration/exportIntegration.reference.dxf +9 -9
  117. package/test/integration/exportIntegration.test.js +5 -5
  118. package/test/integration/intersectionIntegration.test.js +4 -5
  119. package/test/integration/pdfRendererIntegration.reference.pdf +17709 -0
  120. package/test/integration/pdfRendererIntegration.test.js +61 -0
  121. package/test/integration/svgRendererIntegration.reference.svg +3343 -0
  122. package/test/integration/svgRendererIntegration.test.js +61 -0
  123. package/test/integration/userInputIntegration.reference.dxf +1165 -105
  124. package/test/integration/userInputIntegration.test.js +239 -132
  125. package/test/lib/boundingBox.test.js +3 -3
  126. package/test/lib/canvas.test.js +744 -125
  127. package/test/lib/constants.test.js +27 -0
  128. package/test/lib/entityManager.test.js +4 -4
  129. package/test/lib/inputManager.test.js +81 -20
  130. package/test/lib/intersect.test.js +83 -0
  131. package/test/lib/plotOptions.test.js +179 -0
  132. package/test/lib/rubberBand.test.js +84 -0
  133. package/test/lib/scene.test.js +9 -9
  134. package/test/lib/selectionManager.test.js +3 -3
  135. package/test/lib/settings.test.js +5 -6
  136. package/test/lib/snapping.test.js +72 -130
  137. package/test/lib/stateManager.test.js +7 -7
  138. package/test/lib/utils.test.js +36 -2
  139. package/test/properties/entityProperties.test.js +132 -0
  140. package/test/properties/property.test.js +53 -0
  141. package/test/properties/propertyManager.test.js +25 -25
  142. package/test/renderers/canvasRenderer.test.js +317 -0
  143. package/test/renderers/pdfRenderer.test.js +271 -0
  144. package/test/renderers/rendererBase.test.js +213 -0
  145. package/test/renderers/svgRenderer.test.js +326 -0
  146. package/test/tables/block.test.js +92 -13
  147. package/test/tables/endblk.test.js +2 -2
  148. package/test/tables/layer.test.js +30 -0
  149. package/test/tables/layerManager.test.js +2 -2
  150. package/test/test-helpers/hatchGridRenderer.js +180 -0
  151. package/test/test-helpers/test-helpers.js +158 -6
  152. package/test/tools/chamfer.test.js +273 -51
  153. package/test/tools/chamferFilletBase.test.js +125 -36
  154. package/test/tools/copy.test.js +8 -8
  155. package/test/tools/copybase.test.js +2 -2
  156. package/test/tools/copyclip.test.js +2 -2
  157. package/test/tools/cornerEntity.test.js +8 -8
  158. package/test/tools/cutclip.test.js +2 -2
  159. package/test/tools/erase.test.js +6 -6
  160. package/test/tools/explode.test.js +5 -5
  161. package/test/tools/extend.test.js +373 -42
  162. package/test/tools/fillet.test.js +230 -49
  163. package/test/tools/matchProp.test.js +11 -11
  164. package/test/tools/mirror.test.js +39 -39
  165. package/test/tools/move.test.js +7 -7
  166. package/test/tools/offset.test.js +222 -55
  167. package/test/tools/pasteclip.test.js +5 -5
  168. package/test/tools/purge.test.js +4 -4
  169. package/test/tools/rotate.test.js +39 -9
  170. package/test/tools/scale.test.js +33 -33
  171. package/test/tools/trim.test.js +579 -53
  172. package/test/tools/zoom.test.js +12 -12
  173. package/core/lib/selectionWindow.js +0 -83
@@ -1,4 +1,4 @@
1
- import { BaseDimension } from './baseDimension.js';
1
+ import { DimensionBase } from './dimensionBase.js';
2
2
  import { AlignedDimension } from './alignedDimension.js';
3
3
  import { DiametricDimension } from './diametricDimension.js';
4
4
  import { AngularDimension } from './angularDimension.js';
@@ -8,7 +8,7 @@ import { RotatedDimension } from './rotatedDimension.js';
8
8
  import { Arc } from '../entities/arc.js';
9
9
  import { Circle } from '../entities/circle.js';
10
10
  import { Line } from '../entities/line.js';
11
- import { BasePolyline } from '../entities/basePolyline.js';
11
+ import { PolylineBase } from '../entities/polylineBase.js';
12
12
  import { Point } from '../entities/point.js';
13
13
 
14
14
  import { Strings } from '../lib/strings.js';
@@ -17,15 +17,16 @@ import { Logging } from '../lib/logging.js';
17
17
  import { Intersection } from '../lib/intersect.js';
18
18
 
19
19
  import { DesignCore } from '../designCore.js';
20
+ import { Property } from '../properties/property.js';
20
21
  import { SingleSelection } from '../lib/selectionManager.js';
21
22
  import { Utils } from '../lib/utils.js';
22
23
  import { DimType } from '../properties/dimType.js';
23
24
 
24
25
  /**
25
26
  * Dimension Entity Class
26
- * @extends BaseDimension
27
+ * @extends DimensionBase
27
28
  */
28
- export class Dimension extends BaseDimension {
29
+ export class Dimension extends DimensionBase {
29
30
  /**
30
31
  * Create a Dimension
31
32
  * @param {Array} data
@@ -33,21 +34,27 @@ export class Dimension extends BaseDimension {
33
34
  constructor(data) {
34
35
  super(data);
35
36
 
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 = [];
37
+ // map dimensions type to the class name — non-enumerable: internal workflow state
38
+ Object.defineProperty(this, 'dimensionMap', {
39
+ value: {
40
+ 0: RotatedDimension,
41
+ 1: AlignedDimension,
42
+ 2: AngularDimension,
43
+ 3: DiametricDimension,
44
+ 4: RadialDimension,
45
+ 5: null, // 5 = Angular 3 point;
46
+ 6: null, // 6 = Ordinate;
47
+ },
48
+ writable: true,
49
+ });
50
+
51
+ Object.defineProperty(this, 'selectedEntities', {
52
+ value: [],
53
+ writable: true,
54
+ });
48
55
 
49
56
  if (data) {
50
- const item = new this.dimensionMap[DimType.getBaseType(this.dimType.getBaseDimType())](data);
57
+ const entity = new this.dimensionMap[DimType.getBaseType(this.dimType.getBaseDimType())](data);
51
58
 
52
59
  // find the block linked to this dimension
53
60
  const linkedBlockIndex = DesignCore.Scene.entities.find('BLOCK', 'name', data[2]);
@@ -57,7 +64,7 @@ export class Dimension extends BaseDimension {
57
64
  DesignCore.Scene.entities.remove(linkedBlockIndex[0]);
58
65
  }
59
66
 
60
- return item;
67
+ return entity;
61
68
  }
62
69
  }
63
70
 
@@ -80,7 +87,7 @@ export class Dimension extends BaseDimension {
80
87
  async execute() {
81
88
  try {
82
89
  let inputValid = false;
83
- this.dimensionStyle = DesignCore.DimStyleManager.getCstyle();
90
+ this.setProperty(Property.Names.DIMENSIONSTYLE, DesignCore.DimStyleManager.getCstyle());
84
91
 
85
92
  while (!inputValid) {
86
93
  DesignCore.Scene.selectionManager.reset();
@@ -97,51 +104,51 @@ export class Dimension extends BaseDimension {
97
104
  if (pt14 === undefined) return;
98
105
  // Create a temporary line using the selected points
99
106
  const tempLine = new Line({ points: [input1, pt14] });
100
- this.selectedItems.push(tempLine);
107
+ this.selectedEntities.push(tempLine);
101
108
  }
102
109
 
103
110
  if (input1 instanceof SingleSelection) {
104
- const selectedItem = DesignCore.Scene.entities.get(input1.selectedItemIndex);
111
+ const selectedEntity = DesignCore.Scene.entities.get(input1.selectedEntityIndex);
105
112
 
106
113
  // check the selected entity is supported
107
- if ([Line, Circle, Arc, BasePolyline].some((entity) => selectedItem instanceof entity)) {
114
+ if ([Line, Circle, Arc, PolylineBase].some((entity) => selectedEntity instanceof entity)) {
108
115
  // set the dimension type
109
- if (selectedItem instanceof Line) {
116
+ if (selectedEntity instanceof Line) {
110
117
  this.dimType.setDimType(1);
111
- this.selectedItems.push(selectedItem);
118
+ this.selectedEntities.push(selectedEntity);
112
119
  inputValid = true;
113
120
  }
114
121
 
115
- if (selectedItem instanceof Circle) {
122
+ if (selectedEntity instanceof Circle) {
116
123
  this.dimType.setDimType(3);
117
- this.selectedItems.push(selectedItem);
124
+ this.selectedEntities.push(selectedEntity);
118
125
  inputValid = true;
119
126
  }
120
127
 
121
- if (selectedItem instanceof Arc) {
128
+ if (selectedEntity instanceof Arc) {
122
129
  this.dimType.setDimType(4);
123
- this.selectedItems.push(selectedItem);
130
+ this.selectedEntities.push(selectedEntity);
124
131
  inputValid = true;
125
132
  }
126
133
 
127
- if (selectedItem instanceof BasePolyline) {
134
+ if (selectedEntity instanceof PolylineBase) {
128
135
  // get the segment closest to the mouse point
129
- const segment = selectedItem.getClosestSegment(input1.selectedPoint);
136
+ const segment = selectedEntity.getClosestSegment(input1.selectedPoint);
130
137
 
131
138
  if (segment instanceof Line) {
132
139
  this.dimType.setDimType(1);
133
- this.selectedItems.push(segment);
140
+ this.selectedEntities.push(segment);
134
141
  inputValid = true;
135
142
  }
136
143
 
137
144
  if (segment instanceof Arc) {
138
145
  this.dimType.setDimType(4);
139
- this.selectedItems.push(segment);
146
+ this.selectedEntities.push(segment);
140
147
  inputValid = true;
141
148
  }
142
149
  }
143
150
  } else {
144
- const msg = `${this.type} - ${Strings.Error.INVALIDTYPE}: ${selectedItem.type}`;
151
+ const msg = `${this.type} - ${Strings.Error.INVALIDTYPE}: ${selectedEntity.type}`;
145
152
  DesignCore.Core.notify(msg);
146
153
  DesignCore.Scene.selectionManager.reset();
147
154
  }
@@ -155,12 +162,12 @@ export class Dimension extends BaseDimension {
155
162
  let op2 = new PromptOptions(Strings.Input.DIMENSION, [Input.Type.POINT]);
156
163
 
157
164
  // 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) {
165
+ if ((this.selectedEntities[0] instanceof Line) && this.selectedEntities.length < 2) {
159
166
  op2 = new PromptOptions(`${Strings.Input.DIMENSION} or ${Strings.Input.SELECT}`, [Input.Type.POINT, Input.Type.SINGLESELECTION]);
160
167
  }
161
168
 
162
169
  // diametric prompt: select radial or diametric type dimension or location for the the text position
163
- if (this.selectedItems[0] instanceof Circle) {
170
+ if (this.selectedEntities[0] instanceof Circle) {
164
171
  const options = this.dimType.getBaseDimType() === 3 ? ['Radius'] : ['Diameter'];
165
172
  op2 = new PromptOptions(`${Strings.Input.DIMENSION}`, [Input.Type.POINT], options);
166
173
  }
@@ -171,19 +178,19 @@ export class Dimension extends BaseDimension {
171
178
  if (Input.getType(input2) === Input.Type.POINT) {
172
179
  const Pt11 = input2;
173
180
 
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) {
181
+ // if selected entities are available, get the points from the selected entities
182
+ // dimensions can be created from point selection only, therefore selected entities may not be available
183
+ if (this.selectedEntities.length) {
177
184
  // for linear dimensions, determine if aligned or rotated based on mouse position
178
185
  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];
186
+ const Pt13 = this.selectedEntities[0].points[0];
187
+ const Pt14 = this.selectedEntities[0].points[1];
181
188
  const linearDimTypeNumber = this.getLinearDimensionType(Pt13, Pt14, Pt11);
182
189
  this.dimType.setDimType(linearDimTypeNumber);
183
190
  }
184
191
 
185
192
  const dimensionType = this.dimensionMap[this.dimType.getBaseDimType()]; // TODO: use this.dimensionMap.name?
186
- this.points.push(...dimensionType.getPointsFromSelection(this.selectedItems, Pt11));
193
+ this.points.push(...dimensionType.getPointsFromSelection(this.selectedEntities, Pt11));
187
194
  }
188
195
  }
189
196
 
@@ -199,20 +206,20 @@ export class Dimension extends BaseDimension {
199
206
  }
200
207
 
201
208
  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)) {
209
+ let selectedEntity2 = DesignCore.Scene.entities.get(input2.selectedEntityIndex);
210
+ if ([Line, PolylineBase].some((entity) => selectedEntity2 instanceof entity)) {
204
211
  // if a polyline is selected, get the segment closest to the mouse point
205
- if (selectedItem2 instanceof BasePolyline) {
212
+ if (selectedEntity2 instanceof PolylineBase) {
206
213
  // get the segment closest to the mouse point
207
- const segment = selectedItem2.getClosestSegment(input2.selectedPoint);
214
+ const segment = selectedEntity2.getClosestSegment(input2.selectedPoint);
208
215
 
209
216
  if (segment instanceof Line) {
210
- selectedItem2 = segment;
217
+ selectedEntity2 = segment;
211
218
  }
212
219
  }
213
220
  // 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] };
221
+ const line1 = { start: this.selectedEntities[0].points[0], end: this.selectedEntities[0].points[1] };
222
+ const line2 = { start: selectedEntity2.points[0], end: selectedEntity2.points[1] };
216
223
 
217
224
  // Check the lines are not parallel - Can't dimension parallel lines
218
225
  const lineOneSlope = (line1.end.y - line1.start.y) / (line1.end.x - line1.start.x);
@@ -222,7 +229,7 @@ export class Dimension extends BaseDimension {
222
229
  const intersect = Intersection.intersectSegmentSegment(line1.start, line1.end, line2.start, line2.end, false, true);
223
230
  if (intersect.points.length >= 1) {
224
231
  // add line to selection
225
- this.selectedItems.push(selectedItem2);
232
+ this.selectedEntities.push(selectedEntity2);
226
233
  // Two lines selected - switch to angular dimension
227
234
  this.dimType.setDimType(2);
228
235
  }
@@ -232,7 +239,7 @@ export class Dimension extends BaseDimension {
232
239
  DesignCore.Scene.selectionManager.removeLastSelection();
233
240
  }
234
241
  } else {
235
- const msg = `${this.type} - ${Strings.Error.INVALIDTYPE}: ${selectedItem2.type}`;
242
+ const msg = `${this.type} - ${Strings.Error.INVALIDTYPE}: ${selectedEntity2.type}`;
236
243
  DesignCore.Core.notify(msg);
237
244
  DesignCore.Scene.selectionManager.reset();
238
245
  }
@@ -273,7 +280,7 @@ export class Dimension extends BaseDimension {
273
280
  * Preview the entity during creation
274
281
  */
275
282
  preview() {
276
- if (this.selectedItems.length) {
283
+ if (this.selectedEntities.length) {
277
284
  let dimTypeNumber = this.dimType.getBaseDimType();
278
285
 
279
286
  const Pt11 = DesignCore.Mouse.pointOnScene();
@@ -281,8 +288,8 @@ export class Dimension extends BaseDimension {
281
288
 
282
289
  if (dimTypeNumber === 0 || dimTypeNumber === 1) {
283
290
  // 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];
291
+ const Pt13 = this.selectedEntities[0].points[0];
292
+ const Pt14 = this.selectedEntities[0].points[1];
286
293
  dimTypeNumber = this.getLinearDimensionType(Pt13, Pt14, Pt11);
287
294
  }
288
295
  // get the dimension class
@@ -290,9 +297,9 @@ export class Dimension extends BaseDimension {
290
297
  // get the dimension type as a string
291
298
  const dimensionTypeString = dimensionType.register().command;
292
299
  // get the points for the dimension
293
- const points = dimensionType.getPointsFromSelection(this.selectedItems, Pt11);
300
+ const points = dimensionType.getPointsFromSelection(this.selectedEntities, Pt11);
294
301
  // create the temporary dimension
295
- DesignCore.Scene.tempEntities.create(dimensionTypeString, { points: points, dimensionStyle: this.dimensionStyle });
302
+ DesignCore.Scene.previewEntities.create(dimensionTypeString, { points: points, dimensionStyle: this.getProperty(Property.Names.DIMENSIONSTYLE) });
296
303
  }
297
304
  }
298
305
  }
@@ -16,7 +16,7 @@ import { DimType } from '../properties/dimType.js';
16
16
  * Base Dimension Entity Class
17
17
  * @extends Entity
18
18
  */
19
- export class BaseDimension extends Entity {
19
+ export class DimensionBase extends Entity {
20
20
  /**
21
21
  * Create a Base Dimension
22
22
  * @param {Array} data
@@ -24,91 +24,67 @@ export class BaseDimension extends Entity {
24
24
  constructor(data) {
25
25
  super(data);
26
26
 
27
- // hide inherited property
28
- // needs to be enumerable=false to not appear in the object props
29
- Object.defineProperty(this, 'lineType', {
30
- enumerable: false,
31
- });
27
+ // lineType and lineWidth not applicable to dimensions
28
+ this.properties.remove(Property.Names.LINETYPE);
29
+ this.properties.remove(Property.Names.LINEWIDTH);
32
30
 
33
- // hide inherited property
34
- Object.defineProperty(this, 'lineWidth', {
35
- enumerable: false,
31
+ // DXF Groupcode 1 - Dimension text override
32
+ this.properties.add(Property.Names.TEXTOVERRIDE, {
33
+ type: Property.Type.STRING,
34
+ value: Property.loadValue([data?.[1], data?.textOverride], ''),
35
+ dxfCode: 1,
36
36
  });
37
37
 
38
- Object.defineProperty(this, 'blockName', {
39
- value: '',
40
- writable: true,
38
+ // DXF Groupcode 2 - Block name
39
+ this.properties.add(Property.Names.BLOCKNAME, {
40
+ type: Property.Type.STRING,
41
+ value: Property.loadValue([data?.blockName, data?.[2]], ''),
42
+ dxfCode: 2,
43
+ visible: false,
41
44
  });
42
45
 
43
- Object.defineProperty(this, 'block', {
44
- value: new Block({ points: [new Point(), new Point()] }),
45
- writable: true,
46
- });
47
-
48
- /*
49
- Object.defineProperty(this, 'text', {
50
- value: new Text(),
51
- writable: true,
46
+ // DXF Groupcode 3 - Dimension Style Name
47
+ this.properties.add(Property.Names.DIMENSIONSTYLE, {
48
+ type: Property.Type.LIST,
49
+ value: Property.loadValue([data?.dimensionStyle, data?.[3]], 'STANDARD'),
50
+ dxfCode: 3,
52
51
  });
53
- */
54
52
 
55
- Object.defineProperty(this, 'textOverride', {
56
- value: '',
57
- writable: true,
58
- enumerable: true,
53
+ // DXF Groupcode 40 - Leader length for radius and diameter dimensions
54
+ this.properties.add(Property.Names.LEADERLENGTH, {
55
+ type: Property.Type.NUMBER,
56
+ value: Property.loadValue([data?.[40], data?.leaderLength], 0),
57
+ dxfCode: 40,
58
+ visible: false,
59
59
  });
60
60
 
61
- Object.defineProperty(this, 'dimType', {
62
- value: new DimType(),
63
- writable: true,
61
+ // DXF Groupcode 50 - Angle of rotated, horizontal, or vertical dimensions
62
+ this.properties.add(Property.Names.LINEARDIMANGLE, {
63
+ type: Property.Type.NUMBER,
64
+ value: Property.loadValue([data?.[50], data?.linearDimAngle], 0),
65
+ dxfCode: 50,
66
+ visible: false,
64
67
  });
65
68
 
66
- Object.defineProperty(this, 'dimensionStyle', {
67
- value: 'STANDARD',
68
- writable: true,
69
- enumerable: true,
69
+ // DXF Groupcode 53 - Rotation angle of dimension text away from default orientation
70
+ this.properties.add(Property.Names.ANGLE, {
71
+ type: Property.Type.NUMBER,
72
+ value: Property.loadValue([data?.[53], data?.angle], 0),
73
+ dxfCode: 53,
74
+ visible: false,
70
75
  });
71
76
 
72
- Object.defineProperty(this, 'leaderLength', {
73
- value: 0,
77
+ Object.defineProperty(this, 'block', {
78
+ value: new Block({ points: [new Point(), new Point()] }),
74
79
  writable: true,
75
80
  });
76
81
 
77
- Object.defineProperty(this, 'linearDimAngle', {
78
- value: 0,
82
+ Object.defineProperty(this, 'dimType', {
83
+ value: new DimType(),
79
84
  writable: true,
80
85
  });
81
86
 
82
87
  if (data) {
83
- if (data.hasOwnProperty('1')) {
84
- // DXF Groupcode 1 - Dimension text
85
- // The string explicitly entered by the user.
86
- // Optional; default is the measurement. If null or “<>”, the dimension measurement is drawn as the text,
87
- // if ““ (one blank space), the text is suppressed. Anything else is drawn as the text
88
- this.textOverride = Property.loadValue([data[1], data.textOverride], '');
89
- }
90
-
91
- /*
92
- if (data.hasOwnProperty('block')) {
93
- // Reference to block that contains the entities that make up this dimension
94
- this.block = data.block;
95
- }*/
96
-
97
- if (data.hasOwnProperty('blockName') || data.hasOwnProperty('2')) {
98
- // DXF Groupcode 2 - Blockname
99
- this.blockName = Property.loadValue([data.blockName, data[2]], '');
100
- }
101
-
102
- if (data.hasOwnProperty('dimensionStyle') || data.hasOwnProperty('3')) {
103
- // DXF Groupcode 3 - Dimension Style Name
104
- this.dimensionStyle = Property.loadValue([data.dimensionStyle, data[3]], 'STANDARD');
105
- }
106
-
107
- if (data.hasOwnProperty('40')) {
108
- // DXF Groupcode 40 - Leader length for radius and diameter dimensions
109
- this.leaderLength = data[40];
110
- }
111
-
112
88
  if (data.hasOwnProperty('41')) {
113
89
  // DXF Groupcode 41 - Line Spacing Factor
114
90
  // Percentage of default (3-on-5) line spacing to be applied.
@@ -124,11 +100,6 @@ export class BaseDimension extends Entity {
124
100
  Logging.instance.debug(`${this.type} - ${err}`);
125
101
  }
126
102
 
127
- if (data.hasOwnProperty('50')) {
128
- // DXF Groupcode 50 - Angle of rotated, horizontal, or vertical dimensions
129
- this.linearDimAngle = Property.loadValue([data[50]], 0);
130
- }
131
-
132
103
  if (data.hasOwnProperty('51')) {
133
104
  // DXF Groupcode 51 - Horizontal Direction
134
105
  // All dimension types have an optional 51 group code, which indicates the horizontal direction
@@ -140,12 +111,6 @@ export class BaseDimension extends Entity {
140
111
  Logging.instance.warn(`${this.type} - ${err}`);
141
112
  }
142
113
 
143
- if (data.hasOwnProperty('angle') || data.hasOwnProperty('53')) {
144
- // DXF Groupcode 53 - Rotation
145
- // rotation angle of the dimension text away from its default orientation
146
- this.angle = Property.loadValue([data.angle, data[53]], 0);
147
- }
148
-
149
114
  if (data.hasOwnProperty('dimType') || data.hasOwnProperty('70')) {
150
115
  // DXF Groupcode 70 - Dimension Type
151
116
  // Values 0-6 are integer values that represent the dimension type. Values 32, 64, and 128
@@ -183,9 +148,9 @@ export class BaseDimension extends Entity {
183
148
 
184
149
  if (data.hasOwnProperty('71')) {
185
150
  // DXF Groupcode 71 - Attachment Point
186
- // 1 = Top left; 2 = Top center; 3 = Top right
187
- // 4 = Middle left; 5 = Middle center; 6 = Middle right
188
- // 7 = Bottom left; 8 = Bottom center; 9 = Bottom right
151
+ // 1 = Top left; 2 = Top centre; 3 = Top right
152
+ // 4 = Middle left; 5 = Middle centre; 6 = Middle right
153
+ // 7 = Bottom left; 8 = Bottom centre; 9 = Bottom right
189
154
  const err = 'Groupcode 71 not implemented';
190
155
  Logging.instance.debug(`${this.type} - ${err}`);
191
156
  }
@@ -197,10 +162,6 @@ export class BaseDimension extends Entity {
197
162
  const err = 'Groupcode 72 not implemented';
198
163
  Logging.instance.debug(`${this.type} - ${err}`);
199
164
  }
200
-
201
- if (data.leaderLength) {
202
- this.leaderLength = data.leaderLength;
203
- }
204
165
  }
205
166
  }
206
167
 
@@ -280,8 +241,9 @@ export class BaseDimension extends Entity {
280
241
  }
281
242
 
282
243
  // Handle textOverride
283
- if (this.textOverride !== '') {
284
- formattedDimensionValue = this.textOverride.replace(/<>/g, formattedDimensionValue);
244
+ const textOverride = this.getProperty(Property.Names.TEXTOVERRIDE);
245
+ if (textOverride !== '') {
246
+ formattedDimensionValue = textOverride.replace(/<>/g, formattedDimensionValue);
285
247
  }
286
248
 
287
249
  // TODO: Implement prefix and postsuffix - DIMPOST
@@ -338,13 +300,13 @@ export class BaseDimension extends Entity {
338
300
  // get the text height
339
301
  const textHeight = this.getDimensionStyle().getValue('DIMTXT');
340
302
  // set the text height
341
- text.height = textHeight;
342
- // Always set text horizontal alignment to center
343
- text.horizontalAlignment = 1;
303
+ text.setProperty(Property.Names.HEIGHT, textHeight);
304
+ // Always set text horizontal alignment to centre
305
+ text.setProperty(Property.Names.HORIZONTALALIGNMENT, 1);
344
306
  // Always set text vertical alignment to middle
345
- text.verticalAlignment = 2;
307
+ text.setProperty(Property.Names.VERTICALALIGNMENT, 2);
346
308
  // set the text value
347
- text.string = this.getDimensionValue(textValue);
309
+ text.setProperty(Property.Names.STRING, this.getDimensionValue(textValue));
348
310
  // set the text position
349
311
  text.points = [textPosition];
350
312
  // set the text rotation
@@ -385,7 +347,7 @@ export class BaseDimension extends Entity {
385
347
  * @return {Object} - the dimension style object
386
348
  */
387
349
  getDimensionStyle() {
388
- return DesignCore.DimStyleManager.getItemByName(this.dimensionStyle);
350
+ return DesignCore.DimStyleManager.getItemByName(this.getProperty(Property.Names.DIMENSIONSTYLE));
389
351
  }
390
352
 
391
353
  /**
@@ -429,19 +391,19 @@ export class BaseDimension extends Entity {
429
391
 
430
392
  /**
431
393
  * Get the geometry for the centre mark
432
- * @param {Point} point centre point for center mark
433
- * @return {Array} array of entities representing the center mark
394
+ * @param {Point} point centre point for centre mark
395
+ * @return {Array} array of entities representing the centre mark
434
396
  */
435
397
  getCentreMark(point) {
436
398
  /*
437
399
  * DIMCEN value defines the centre mark type and size
438
- * 0 = No center marks or lines are drawn
439
- * <0 = Centerlines are drawn
440
- * >0 = Center marks are drawn
400
+ * 0 = No centre marks or lines are drawn
401
+ * <0 = Centrelines are drawn
402
+ * >0 = Centre marks are drawn
441
403
  */
442
404
 
443
405
  const centreMark = [];
444
- // get the center mark style
406
+ // get the centre mark style
445
407
  const markStyle = this.getDimensionStyle().getValue('DIMCENSTYL');
446
408
  // get the centre mark size
447
409
  const markSize = this.getDimensionStyle().getValue('DIMCENVALUE');
@@ -470,15 +432,15 @@ export class BaseDimension extends Entity {
470
432
 
471
433
  /**
472
434
  * Draw the entity
473
- * @param {Object} ctx - context
474
- * @param {number} scale
435
+ * @param {Object} renderer
436
+ * @return {Array} block entities for the canvas to render recursively
475
437
  */
476
- draw(ctx, scale) {
477
- if (this.block.items.length === 0) {
438
+ draw(renderer) {
439
+ if (this.block.entities.length === 0) {
478
440
  this.refresh();
479
441
  }
480
442
 
481
- this.block.draw(ctx, scale, this);
443
+ return this.block.entities;
482
444
  }
483
445
 
484
446
  /**
@@ -528,18 +490,18 @@ export class BaseDimension extends Entity {
528
490
  }
529
491
 
530
492
  /**
531
- * Refesh the dimension geometry
493
+ * Refresh the dimension geometry
532
494
  */
533
495
  refresh() {
534
496
  const entities = this.buildDimension();
535
497
 
536
498
  if (entities) {
537
- this.block.clearItems();
499
+ this.block.clearEntities();
538
500
 
539
501
  entities.forEach((element) => {
540
502
  // For colour BYBLOCK for dimensions
541
- element.setColour('BYBLOCK');
542
- this.block.addItem(element);
503
+ element.setProperty(Property.Names.COLOUR, 'BYBLOCK');
504
+ this.block.addEntity(element);
543
505
  });
544
506
  }
545
507
  }
@@ -550,6 +512,10 @@ export class BaseDimension extends Entity {
550
512
  * @param {any} value
551
513
  */
552
514
  setProperty(property, value) {
515
+ if (this.properties.has(property)) {
516
+ super.setProperty(property, value);
517
+ return;
518
+ }
553
519
  if (this.hasOwnProperty(property)) {
554
520
  this[property] = value;
555
521
  this.refresh();