@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
@@ -2,6 +2,7 @@ import { Tool } from './tool.js';
2
2
  import { Input, PromptOptions } from '../lib/inputManager.js';
3
3
  import { Strings } from '../lib/strings.js';
4
4
  import { Logging } from '../lib/logging.js';
5
+ import { Utils } from '../lib/utils.js';
5
6
  import { UpdateState } from '../lib/stateManager.js';
6
7
 
7
8
  import { DesignCore } from '../designCore.js';
@@ -21,8 +22,6 @@ export class MatchProp extends Tool {
21
22
  this.sourceIndex = null;
22
23
  // array of destination item indices
23
24
  this.destinationSetIndices = [];
24
- // properties to match
25
- this.properties = ['colour', 'layer', 'lineType', 'lineWidth', 'height', 'styleName', 'dimensionStyle'];
26
25
  }
27
26
 
28
27
  /**
@@ -49,7 +48,7 @@ export class MatchProp extends Tool {
49
48
  const sourceSelection = new PromptOptions(Strings.Input.SOURCE, [Input.Type.SINGLESELECTION], []);
50
49
  const input = await DesignCore.Scene.inputManager.requestInput(sourceSelection);
51
50
  if (input === undefined) return;
52
- this.sourceIndex = input.selectedItemIndex;
51
+ this.sourceIndex = input.selectedEntityIndex;
53
52
  }
54
53
 
55
54
  const destinationSelection = new PromptOptions(Strings.Input.DESTINATIONSET, [Input.Type.SELECTIONSET]);
@@ -76,21 +75,13 @@ export class MatchProp extends Tool {
76
75
 
77
76
  // get source item
78
77
  const sourceItem = DesignCore.Scene.entities.get(this.sourceIndex);
78
+ const propertySet = Utils.cloneProperties(sourceItem);
79
79
 
80
80
  const stateChanges = [];
81
81
 
82
82
  // loop through destination set
83
83
  for (let i = 0; i < this.destinationSetIndices.length; i++) {
84
84
  const targetItem = DesignCore.Scene.entities.get(this.destinationSetIndices[i]);
85
- const propertySet = {};
86
- // loop through properties and match
87
- for (let p = 0; p < this.properties.length; p++) {
88
- // check property exists on both items
89
- const prop = this.properties[p];
90
- if (sourceItem.hasOwnProperty(prop)) {
91
- propertySet[prop] = sourceItem[prop];
92
- }
93
- }
94
85
 
95
86
  // only add state change if there are properties to change
96
87
  if (Object.keys(propertySet).length > 0) {
@@ -7,6 +7,7 @@ import { Point } from '../entities/point.js';
7
7
  import { AddState, UpdateState } from '../lib/stateManager.js';
8
8
 
9
9
  import { DesignCore } from '../designCore.js';
10
+ import { RubberBand } from '../lib/auxiliary/rubberBand.js';
10
11
 
11
12
  /**
12
13
  * Mirror Command Class
@@ -74,18 +75,18 @@ export class Mirror extends Tool {
74
75
  const pt1 = this.points[0];
75
76
  const pt2 = this.points.length >= 2 ? this.points[1] : mousePoint;
76
77
 
77
- // Draw the mirror line
78
- DesignCore.Scene.tempEntities.create('Line', { points: [pt1, pt2] });
78
+ // Draw the mirror line as a rubber-band indicator
79
+ DesignCore.Scene.auxiliaryEntities.add(new RubberBand([pt1, pt2]));
79
80
 
80
81
  // Preview mirrored entities (skip if mirror line has zero length)
81
82
  if (!pt1.isSame(pt2)) {
82
- for (let i = 0; i < DesignCore.Scene.selectionManager.selectedItems.length; i++) {
83
- const item = DesignCore.Scene.selectionManager.selectedItems[i];
83
+ for (let i = 0; i < DesignCore.Scene.selectionManager.selectedEntities.length; i++) {
84
+ const entity = DesignCore.Scene.selectionManager.selectedEntities[i];
84
85
  const entityIndex = DesignCore.Scene.selectionManager.selectionSet.selectionSet[i];
85
- const originalItem = DesignCore.Scene.entities.get(entityIndex);
86
- item.setProperty('points', this.getMirroredPoints(originalItem.points, pt1, pt2));
87
- if (originalItem.direction !== undefined) {
88
- item.setProperty('direction', -originalItem.direction);
86
+ const originalEntity = DesignCore.Scene.entities.get(entityIndex);
87
+ entity.setProperty('points', this.getMirroredPoints(originalEntity.points, pt1, pt2));
88
+ if (originalEntity.properties?.has('direction')) {
89
+ entity.setProperty('direction', -originalEntity.getProperty('direction'));
89
90
  }
90
91
  }
91
92
  }
@@ -108,20 +109,20 @@ export class Mirror extends Tool {
108
109
 
109
110
  for (let i = 0; i < DesignCore.Scene.selectionManager.selectionSet.selectionSet.length; i++) {
110
111
  const entityIndex = DesignCore.Scene.selectionManager.selectionSet.selectionSet[i];
111
- const item = DesignCore.Scene.entities.get(entityIndex);
112
- const mirroredPoints = this.getMirroredPoints(item.points, pt1, pt2);
112
+ const entity = DesignCore.Scene.entities.get(entityIndex);
113
+ const mirroredPoints = this.getMirroredPoints(entity.points, pt1, pt2);
113
114
 
114
115
  if (this.eraseSource) {
115
116
  // Replace the original with its mirrored version
116
117
  const updates = { points: mirroredPoints };
117
- if (item.direction !== undefined) updates.direction = -item.direction;
118
- const stateChange = new UpdateState(item, updates);
118
+ if (entity.properties?.has('direction')) updates.direction = -entity.getProperty('direction');
119
+ const stateChange = new UpdateState(entity, updates);
119
120
  stateChanges.push(stateChange);
120
121
  } else {
121
122
  // Keep the original and add a mirrored copy
122
- const copyOfItem = Utils.cloneObject(item);
123
+ const copyOfItem = Utils.cloneObject(entity);
123
124
  copyOfItem.setProperty('points', mirroredPoints);
124
- if (copyOfItem.direction !== undefined) copyOfItem.setProperty('direction', -copyOfItem.direction);
125
+ if (copyOfItem.properties?.has('direction')) copyOfItem.setProperty('direction', -copyOfItem.getProperty('direction'));
125
126
  const stateChange = new AddState(copyOfItem);
126
127
  stateChanges.push(stateChange);
127
128
  }
@@ -6,6 +6,7 @@ import { Point } from '../entities/point.js';
6
6
 
7
7
  import { DesignCore } from '../designCore.js';
8
8
  import { UpdateState } from '../lib/stateManager.js';
9
+ import { RubberBand } from '../lib/auxiliary/rubberBand.js';
9
10
 
10
11
  /**
11
12
  * Move Command Class
@@ -66,17 +67,16 @@ export class Move extends Tool {
66
67
  if (this.points.length >= 1) {
67
68
  const mousePoint = DesignCore.Mouse.pointOnScene();
68
69
 
69
- // Draw a line
70
- const points = [this.points.at(-1), mousePoint];
71
- DesignCore.Scene.tempEntities.create('Line', { points: points });
70
+ // Draw a rubber-band line from base point to mouse
71
+ DesignCore.Scene.auxiliaryEntities.add(new RubberBand([this.points.at(-1), mousePoint]));
72
72
 
73
73
  // Get the delta from the last mouse point
74
74
  const delta = mousePoint.subtract(this.lastMousePoint || this.points[0]);
75
75
  this.lastMousePoint = mousePoint;
76
76
 
77
- for (let i = 0; i < DesignCore.Scene.selectionManager.selectedItems.length; i++) {
78
- const item = DesignCore.Scene.selectionManager.selectedItems[i];
79
- item.setProperty('points', this.getOffsetPoints(item.points, delta));
77
+ for (let i = 0; i < DesignCore.Scene.selectionManager.selectedEntities.length; i++) {
78
+ const entity = DesignCore.Scene.selectionManager.selectedEntities[i];
79
+ entity.setProperty('points', this.getOffsetPoints(entity.points, delta));
80
80
  }
81
81
  }
82
82
  }
@@ -94,8 +94,8 @@ export class Move extends Tool {
94
94
 
95
95
  for (let i = 0; i < DesignCore.Scene.selectionManager.selectionSet.selectionSet.length; i++) {
96
96
  const index = DesignCore.Scene.selectionManager.selectionSet.selectionSet[i];
97
- const item = DesignCore.Scene.entities.get(index);
98
- const stateChange = new UpdateState(item, { points: this.getOffsetPoints(item.points, delta) });
97
+ const entity = DesignCore.Scene.entities.get(index);
98
+ const stateChange = new UpdateState(entity, { points: this.getOffsetPoints(entity.points, delta) });
99
99
  stateChanges.push(stateChange);
100
100
  }
101
101
 
@@ -19,7 +19,7 @@ export class Offset extends Tool {
19
19
  /** Create an Offset command */
20
20
  constructor() {
21
21
  super();
22
- this.selectedItem = null;
22
+ this.selectedEntity = null;
23
23
  }
24
24
 
25
25
  /**
@@ -67,28 +67,28 @@ export class Offset extends Tool {
67
67
  while (true) {
68
68
  const preselected = DesignCore.Scene.selectionManager.selectionSet.selectionSet;
69
69
  if (preselected.length === 1) {
70
- this.selectedItem = DesignCore.Scene.entities.get(preselected[0]);
70
+ this.selectedEntity = DesignCore.Scene.entities.get(preselected[0]);
71
71
  DesignCore.Scene.selectionManager.reset();
72
72
  } else {
73
73
  DesignCore.Scene.selectionManager.reset();
74
74
  const selection = await DesignCore.Scene.inputManager.requestInput(op2);
75
75
  if (selection === undefined) break;
76
- this.selectedItem = DesignCore.Scene.entities.get(selection.selectedItemIndex);
76
+ this.selectedEntity = DesignCore.Scene.entities.get(selection.selectedEntityIndex);
77
77
  DesignCore.Scene.selectionManager.removeLastSelection();
78
78
  }
79
79
 
80
80
  const point = await DesignCore.Scene.inputManager.requestInput(op3);
81
81
  if (point === undefined) {
82
- this.selectedItem = null;
82
+ this.selectedEntity = null;
83
83
  break;
84
84
  }
85
85
 
86
86
  if (throughMode) {
87
- DesignCore.Scene.headers.offsetDistance = this.getThroughDistance(this.selectedItem, point);
87
+ DesignCore.Scene.headers.offsetDistance = this.getThroughDistance(this.selectedEntity, point);
88
88
  }
89
89
  this.points = [point];
90
90
  DesignCore.Scene.inputManager.actionCommand();
91
- this.selectedItem = null;
91
+ this.selectedEntity = null;
92
92
  }
93
93
 
94
94
  DesignCore.Scene.inputManager.reset();
@@ -102,14 +102,13 @@ export class Offset extends Tool {
102
102
  */
103
103
  preview() {
104
104
  const offsetDistance = DesignCore.Scene.headers.offsetDistance;
105
- if (this.selectedItem && offsetDistance > 0) {
105
+ if (this.selectedEntity && offsetDistance > 0) {
106
106
  const mousePoint = DesignCore.Mouse.pointOnScene();
107
- const offsetPoints = this.getOffsetPoints(this.selectedItem, mousePoint, offsetDistance);
107
+ const offsetPoints = this.getOffsetPoints(this.selectedEntity, mousePoint, offsetDistance);
108
108
 
109
109
  if (offsetPoints) {
110
- const previewEntity = Utils.cloneObject(this.selectedItem);
111
- previewEntity.fromPolylinePoints(offsetPoints);
112
- DesignCore.Scene.tempEntities.add(previewEntity);
110
+ const previewEntity = Utils.cloneObject(this.selectedEntity).fromPolylinePoints(offsetPoints);
111
+ DesignCore.Scene.previewEntities.add(previewEntity);
113
112
  }
114
113
  }
115
114
  }
@@ -119,10 +118,10 @@ export class Offset extends Tool {
119
118
  */
120
119
  action() {
121
120
  const offsetDistance = DesignCore.Scene.headers.offsetDistance;
122
- if (!this.selectedItem || offsetDistance <= 0) return;
121
+ if (!this.selectedEntity || offsetDistance <= 0) return;
123
122
 
124
123
  const sidePoint = this.points[0];
125
- const entity = this.selectedItem;
124
+ const entity = this.selectedEntity;
126
125
  const offsetPoints = this.getOffsetPoints(entity, sidePoint, offsetDistance);
127
126
 
128
127
  if (!offsetPoints) {
@@ -130,8 +129,7 @@ export class Offset extends Tool {
130
129
  return;
131
130
  }
132
131
 
133
- const offsetEntity = Utils.cloneObject(entity);
134
- offsetEntity.fromPolylinePoints(offsetPoints);
132
+ const offsetEntity = Utils.cloneObject(entity).fromPolylinePoints(offsetPoints);
135
133
 
136
134
  const stateChange = new AddState(offsetEntity);
137
135
  DesignCore.Scene.commit([stateChange]);
@@ -189,20 +187,20 @@ export class Offset extends Tool {
189
187
  sign = cross >= 0 ? 1 : -1;
190
188
  }
191
189
  } else {
192
- const center = A.bulgeCentrePoint(B);
193
- const currentRadius = center.distance(A);
190
+ const centre = A.bulgeCentrePoint(B);
191
+ const currentRadius = centre.distance(A);
194
192
  const arcDir = A.bulge > 0 ? 1 : -1;
195
- const closestPt = sidePoint.closestPointOnArc(A, B, center, arcDir);
193
+ const closestPt = sidePoint.closestPointOnArc(A, B, centre, arcDir);
196
194
  if (closestPt === null) continue;
197
195
  const dist = sidePoint.distance(closestPt);
198
196
  if (dist < minDist) {
199
197
  minDist = dist;
200
- const distToCenter = center.distance(sidePoint);
201
- // For CCW arc (arcDir>0): left of travel = toward center (smaller radius)
202
- // For CW arc (arcDir<0): left of travel = away from center (larger radius)
198
+ const distToCentre = centre.distance(sidePoint);
199
+ // For CCW arc (arcDir>0): left of travel = toward centre (smaller radius)
200
+ // For CW arc (arcDir<0): left of travel = away from centre (larger radius)
203
201
  sign = arcDir > 0 ?
204
- (distToCenter < currentRadius ? 1 : -1) :
205
- (distToCenter >= currentRadius ? 1 : -1);
202
+ (distToCentre < currentRadius ? 1 : -1) :
203
+ (distToCentre >= currentRadius ? 1 : -1);
206
204
  }
207
205
  }
208
206
  }
@@ -223,19 +221,19 @@ export class Offset extends Tool {
223
221
  bulge: 0,
224
222
  });
225
223
  } else {
226
- const center = A.bulgeCentrePoint(B);
227
- const currentRadius = center.distance(A);
224
+ const centre = A.bulgeCentrePoint(B);
225
+ const currentRadius = centre.distance(A);
228
226
  const arcDir = A.bulge > 0 ? 1 : -1;
229
227
  const newRadius = currentRadius - arcDir * distance * sign;
230
228
  if (newRadius <= 0) return null;
231
- const startAngle = Math.atan2(A.y - center.y, A.x - center.x);
232
- const endAngle = Math.atan2(B.y - center.y, B.x - center.x);
229
+ const startAngle = Math.atan2(A.y - centre.y, A.x - centre.x);
230
+ const endAngle = Math.atan2(B.y - centre.y, B.x - centre.x);
233
231
  offsetSegs.push({
234
232
  type: 'arc',
235
- A: new Point(center.x + newRadius * Math.cos(startAngle), center.y + newRadius * Math.sin(startAngle)),
236
- B: new Point(center.x + newRadius * Math.cos(endAngle), center.y + newRadius * Math.sin(endAngle)),
233
+ A: new Point(centre.x + newRadius * Math.cos(startAngle), centre.y + newRadius * Math.sin(startAngle)),
234
+ B: new Point(centre.x + newRadius * Math.cos(endAngle), centre.y + newRadius * Math.sin(endAngle)),
237
235
  bulge: A.bulge,
238
- center,
236
+ centre,
239
237
  radius: newRadius,
240
238
  });
241
239
  }
@@ -311,9 +309,9 @@ export class Offset extends Tool {
311
309
  const dist = throughPoint.distance(closest);
312
310
  if (dist < minDist) minDist = dist;
313
311
  } else {
314
- const center = A.bulgeCentrePoint(B);
315
- const radius = center.distance(A);
316
- const dist = Math.abs(center.distance(throughPoint) - radius);
312
+ const centre = A.bulgeCentrePoint(B);
313
+ const radius = centre.distance(A);
314
+ const dist = Math.abs(centre.distance(throughPoint) - radius);
317
315
  if (dist < minDist) minDist = dist;
318
316
  }
319
317
  }
@@ -66,7 +66,7 @@ export class Pasteclip extends Tool {
66
66
  const tempEntity = Utils.cloneObject(entity);
67
67
  const offsetPoints = tempEntity.points.map((p) => new Point(p.x, p.y, p.bulge, p.sequence).add(delta));
68
68
  tempEntity.setProperty('points', offsetPoints);
69
- DesignCore.Scene.tempEntities.add(tempEntity);
69
+ DesignCore.Scene.previewEntities.add(tempEntity);
70
70
  }
71
71
  }
72
72
 
@@ -60,31 +60,31 @@ export class Purge extends Tool {
60
60
  let purgedCount = 0;
61
61
 
62
62
  if (this.option === 'Blocks' || this.option === 'All') {
63
- const intialitemCount = DesignCore.Scene.blockManager.itemCount();
63
+ const initialItemCount = DesignCore.Scene.blockManager.itemCount();
64
64
  DesignCore.Scene.blockManager.purge();
65
- const finalitemCount = DesignCore.Scene.blockManager.itemCount();
66
- purgedCount += (intialitemCount - finalitemCount);
65
+ const finalItemCount = DesignCore.Scene.blockManager.itemCount();
66
+ purgedCount += (initialItemCount - finalItemCount);
67
67
  }
68
68
 
69
69
  if (this.option === 'Dimstyles' || this.option === 'All') {
70
- const intialitemCount = DesignCore.DimStyleManager.itemCount();
70
+ const initialItemCount = DesignCore.DimStyleManager.itemCount();
71
71
  DesignCore.DimStyleManager.purge();
72
- const finalitemCount = DesignCore.DimStyleManager.itemCount();
73
- purgedCount += (intialitemCount - finalitemCount);
72
+ const finalItemCount = DesignCore.DimStyleManager.itemCount();
73
+ purgedCount += (initialItemCount - finalItemCount);
74
74
  }
75
75
 
76
76
  if (this.option === 'Layers' || this.option === 'All') {
77
- const intialLayerCount = DesignCore.LayerManager.itemCount();
77
+ const initialLayerCount = DesignCore.LayerManager.itemCount();
78
78
  DesignCore.LayerManager.purge();
79
79
  const finalLayerCount = DesignCore.LayerManager.itemCount();
80
- purgedCount += (intialLayerCount - finalLayerCount);
80
+ purgedCount += (initialLayerCount - finalLayerCount);
81
81
  }
82
82
 
83
83
  if (this.option === 'LTypes' || this.option === 'All') {
84
- const intialLTypeCount = DesignCore.LTypeManager.itemCount();
84
+ const initialLTypeCount = DesignCore.LTypeManager.itemCount();
85
85
  DesignCore.LTypeManager.purge();
86
86
  const finalLTypeCount = DesignCore.LTypeManager.itemCount();
87
- purgedCount += (intialLTypeCount - finalLTypeCount);
87
+ purgedCount += (initialLTypeCount - finalLTypeCount);
88
88
  }
89
89
 
90
90
  DesignCore.Core.notify(`${this.type} - ${this.option}: ${purgedCount} ${Strings.Strings.ITEMS} ${Strings.Strings.REMOVED}`);
@@ -7,6 +7,7 @@ import { Point } from '../entities/point.js';
7
7
  import { UpdateState } from '../lib/stateManager.js';
8
8
 
9
9
  import { DesignCore } from '../designCore.js';
10
+ import { RubberBand } from '../lib/auxiliary/rubberBand.js';
10
11
 
11
12
  /**
12
13
  * Rotate Command Class
@@ -72,6 +73,9 @@ export class Rotate extends Tool {
72
73
  this.baseAngle = refBase.angle(refEnd);
73
74
  // set the base point to null
74
75
  this.basePoint = null;
76
+ // restore inputPoint to the rotation centre so the tracking line
77
+ // uses the correct origin for the final angle input
78
+ DesignCore.Scene.inputManager.inputPoint = this.points[0];
75
79
  } else if (Input.getType(input2) === Input.Type.NUMBER) {
76
80
  const basePoint = this.points.at(0);
77
81
  const angle = Utils.degrees2radians(input2);
@@ -95,23 +99,22 @@ export class Rotate extends Tool {
95
99
  const mousePoint = DesignCore.Mouse.pointOnScene();
96
100
 
97
101
  if (this.points.length >= 1 && this.baseAngle !== null || this.basePoint !== null) {
98
- // Draw a line
99
- const center = this.basePoint === null ? this.points.at(0) : this.basePoint;
100
- const points = [center, mousePoint];
101
- DesignCore.Scene.tempEntities.create('Line', { points: points });
102
+ // Draw a rubber-band line from centre to mouse
103
+ const centre = this.basePoint === null ? this.points.at(0) : this.basePoint;
104
+ DesignCore.Scene.auxiliaryEntities.add(new RubberBand([centre, mousePoint]));
102
105
  }
103
106
 
104
107
  if (this.points.length >= 1) {
105
108
  const ang = this.points[0].angle(mousePoint);
106
109
  const theta = this.baseAngle === null ? 0 : ang - this.baseAngle;
107
- const center = this.points[0];
110
+ const centre = this.points[0];
108
111
 
109
- for (let i = 0; i < DesignCore.Scene.selectionManager.selectedItems.length; i++) {
110
- const item = DesignCore.Scene.selectionManager.selectedItems[i];
112
+ for (let i = 0; i < DesignCore.Scene.selectionManager.selectedEntities.length; i++) {
113
+ const entity = DesignCore.Scene.selectionManager.selectedEntities[i];
111
114
  // get the original points from the scene entities
112
115
  const entityIndex = DesignCore.Scene.selectionManager.selectionSet.selectionSet[i];
113
- const originalItem = DesignCore.Scene.entities.get(entityIndex);
114
- item.setProperty('points', this.getRotatedPoints(originalItem.points, center, theta));
116
+ const originalEntity = DesignCore.Scene.entities.get(entityIndex);
117
+ entity.setProperty('points', this.getRotatedPoints(originalEntity.points, centre, theta));
115
118
  }
116
119
  }
117
120
  };
@@ -122,13 +125,13 @@ export class Rotate extends Tool {
122
125
  action() {
123
126
  const ang = this.points[0].angle(this.points[1]);
124
127
  const theta = ang - this.baseAngle;
125
- const center = this.points[0];
128
+ const centre = this.points[0];
126
129
 
127
130
  const stateChanges = [];
128
131
 
129
132
  for (let index = 0; index < DesignCore.Scene.selectionManager.selectionSet.selectionSet.length; index++) {
130
- const item = DesignCore.Scene.entities.get(DesignCore.Scene.selectionManager.selectionSet.selectionSet[index]);
131
- const stateChange = new UpdateState(item, { points: this.getRotatedPoints(item.points, center, theta) });
133
+ const entity = DesignCore.Scene.entities.get(DesignCore.Scene.selectionManager.selectionSet.selectionSet[index]);
134
+ const stateChange = new UpdateState(entity, { points: this.getRotatedPoints(entity.points, centre, theta) });
132
135
  stateChanges.push(stateChange);
133
136
  }
134
137
 
@@ -138,12 +141,12 @@ export class Rotate extends Tool {
138
141
  /**
139
142
  * Get rotated points
140
143
  * @param {Array} points
141
- * @param {Point} center
142
- * @param {Point} theta
144
+ * @param {Point} centre
145
+ * @param {number} theta
143
146
  * @return {Array} rotatedPoints
144
147
  */
145
- getRotatedPoints(points, center, theta) {
146
- const rotatedPoints = points.map((p) => new Point(p.x, p.y, p.bulge, p.sequence).rotate(center, theta));
148
+ getRotatedPoints(points, centre, theta) {
149
+ const rotatedPoints = points.map((p) => new Point(p.x, p.y, p.bulge, p.sequence).rotate(centre, theta));
147
150
  return rotatedPoints;
148
151
  }
149
152
  }
@@ -122,7 +122,7 @@ export class Scale extends Tool {
122
122
  if (this.points.length >= 1 && this.referencePoint === null) {
123
123
  // Draw a line from base point to mouse
124
124
  const points = [this.points[0], mousePoint];
125
- DesignCore.Scene.tempEntities.create('Line', { points: points });
125
+ DesignCore.Scene.previewEntities.create('Line', { points: points });
126
126
 
127
127
  const base = this.points[0];
128
128
  const distance = base.distance(mousePoint);
@@ -130,11 +130,11 @@ export class Scale extends Tool {
130
130
 
131
131
  const factor = this.referenceLength !== null ? distance / this.referenceLength : distance;
132
132
 
133
- for (let i = 0; i < DesignCore.Scene.selectionManager.selectedItems.length; i++) {
134
- const item = DesignCore.Scene.selectionManager.selectedItems[i];
133
+ for (let i = 0; i < DesignCore.Scene.selectionManager.selectedEntities.length; i++) {
134
+ const entity = DesignCore.Scene.selectionManager.selectedEntities[i];
135
135
  const entityIndex = DesignCore.Scene.selectionManager.selectionSet.selectionSet[i];
136
- const originalItem = DesignCore.Scene.entities.get(entityIndex);
137
- item.setProperty('points', this.getScaledPoints(originalItem.points, base, factor));
136
+ const originalEntity = DesignCore.Scene.entities.get(entityIndex);
137
+ entity.setProperty('points', this.getScaledPoints(originalEntity.points, base, factor));
138
138
  }
139
139
  }
140
140
  }
@@ -147,8 +147,8 @@ export class Scale extends Tool {
147
147
  const stateChanges = [];
148
148
 
149
149
  for (let i = 0; i < DesignCore.Scene.selectionManager.selectionSet.selectionSet.length; i++) {
150
- const item = DesignCore.Scene.entities.get(DesignCore.Scene.selectionManager.selectionSet.selectionSet[i]);
151
- const stateChange = new UpdateState(item, { points: this.getScaledPoints(item.points, base, this.scaleFactor) });
150
+ const entity = DesignCore.Scene.entities.get(DesignCore.Scene.selectionManager.selectionSet.selectionSet[i]);
151
+ const stateChange = new UpdateState(entity, { points: this.getScaledPoints(entity.points, base, this.scaleFactor) });
152
152
  stateChanges.push(stateChange);
153
153
  }
154
154