@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.
- package/.eslintrc.json +14 -7
- package/.github/workflows/DesignCoreQA.yml +3 -1
- package/README.md +11 -4
- package/TODO.md +19 -0
- package/core/core/core.js +49 -42
- package/core/designCore.js +61 -2
- package/core/dimensions/alignedDimension.js +142 -0
- package/core/dimensions/angularDimension.js +550 -0
- package/core/dimensions/baseCircularDimension.js +244 -0
- package/core/dimensions/baseDimension.js +558 -0
- package/core/dimensions/baseLinearDimension.js +371 -0
- package/core/dimensions/diametricDimension.js +82 -0
- package/core/dimensions/dimension.js +298 -0
- package/core/dimensions/linearDimension.js +29 -0
- package/core/dimensions/radialDimension.js +78 -0
- package/core/dimensions/rotatedDimension.js +167 -0
- package/core/entities/arc.js +314 -60
- package/core/entities/arctext.js +642 -0
- package/core/entities/basePolyline.js +553 -94
- package/core/entities/circle.js +181 -54
- package/core/entities/entity.js +154 -74
- package/core/entities/hatch.js +807 -0
- package/core/entities/insert.js +200 -39
- package/core/entities/line.js +196 -134
- package/core/entities/lwpolyline.js +21 -44
- package/core/entities/point.js +194 -29
- package/core/entities/polyline.js +54 -7
- package/core/entities/rectangle.js +43 -13
- package/core/entities/solid.js +43 -6
- package/core/entities/text.js +324 -181
- package/core/lib/boundingBox.js +73 -13
- package/core/lib/canvas.js +256 -65
- package/core/lib/clipboard.js +198 -0
- package/core/lib/colour.js +144 -0
- package/core/lib/colours.js +367 -301
- package/core/lib/commandLine.js +16 -28
- package/core/lib/commandManager.js +115 -58
- package/core/lib/constants.js +23 -0
- package/core/lib/dxf/dxf.js +249 -34
- package/core/lib/dxf/dxfFile.js +23 -38
- package/core/lib/dxf/dxfIterator.js +17 -5
- package/core/lib/dxf/dxfRead.js +23 -7
- package/core/lib/dxf/dxfWrite.js +39 -129
- package/core/lib/dxf/handleManager.js +97 -0
- package/core/lib/dxf/sections/blocks.js +16 -2
- package/core/lib/dxf/sections/entities.js +17 -3
- package/core/lib/dxf/sections/header.js +10 -1
- package/core/lib/dxf/sections/objects.js +36 -0
- package/core/lib/dxf/sections/section.js +43 -5
- package/core/lib/dxf/sections/tables.js +17 -3
- package/core/lib/entityManager.js +178 -0
- package/core/lib/fileio.js +14 -4
- package/core/lib/headers.js +229 -0
- package/core/lib/input.js +46 -0
- package/core/lib/inputManager.js +199 -194
- package/core/lib/intersect.js +341 -468
- package/core/lib/logging.js +25 -1
- package/core/lib/matrix.js +6 -8
- package/core/lib/mouse.js +24 -79
- package/core/lib/patterns.js +690 -0
- package/core/lib/promptOptions.js +133 -0
- package/core/lib/scene.js +71 -174
- package/core/lib/selectionManager.js +74 -48
- package/core/lib/selectionWindow.js +24 -10
- package/core/lib/settings.js +18 -11
- package/core/lib/snapping.js +129 -21
- package/core/lib/stateManager.js +288 -0
- package/core/lib/strings.js +57 -5
- package/core/lib/utils.js +95 -11
- package/core/objects/dictionary.js +43 -0
- package/core/objects/dictionaryManager.js +80 -0
- package/core/properties/dimType.js +117 -0
- package/core/properties/flags.js +66 -0
- package/core/properties/property.js +26 -0
- package/core/properties/propertyManager.js +65 -19
- package/core/tables/appId.js +31 -0
- package/core/tables/appIdManager.js +44 -0
- package/core/tables/block.js +323 -0
- package/core/tables/blockManager.js +48 -0
- package/core/tables/blockRecord.js +29 -0
- package/core/tables/blockRecordManager.js +37 -0
- package/core/tables/dimStyle.js +627 -0
- package/core/tables/dimStyleManager.js +187 -0
- package/core/tables/endblk.js +28 -0
- package/core/tables/layer.js +219 -0
- package/core/tables/layerManager.js +47 -0
- package/core/tables/ltype.js +85 -0
- package/core/tables/ltypeManager.js +65 -0
- package/core/tables/style.js +145 -0
- package/core/tables/styleManager.js +55 -0
- package/core/tables/styleManagerBase.js +110 -0
- package/core/tables/tableManagerBase.js +354 -0
- package/core/tables/ucs.js +28 -0
- package/core/tables/ucsManager.js +44 -0
- package/core/tables/view.js +28 -0
- package/core/tables/viewManager.js +44 -0
- package/core/tables/vport.js +70 -0
- package/core/tables/vportManager.js +65 -0
- package/core/tools/chamfer.js +343 -0
- package/core/tools/chamferFilletBase.js +162 -0
- package/core/tools/copy.js +68 -40
- package/core/tools/copybase.js +65 -0
- package/core/tools/copyclip.js +59 -0
- package/core/tools/cornerEntity.js +138 -0
- package/core/tools/cutclip.js +72 -0
- package/core/tools/distance.js +37 -9
- package/core/tools/erase.js +43 -13
- package/core/tools/explode.js +117 -0
- package/core/tools/extend.js +71 -32
- package/core/tools/fillet.js +336 -0
- package/core/tools/identify.js +33 -6
- package/core/tools/matchProp.js +106 -0
- package/core/tools/mirror.js +141 -0
- package/core/tools/move.js +65 -32
- package/core/tools/offset.js +321 -0
- package/core/tools/pan.js +54 -0
- package/core/tools/pasteclip.js +93 -0
- package/core/tools/purge.js +90 -0
- package/core/tools/rotate.js +105 -70
- package/core/tools/scale.js +166 -0
- package/core/tools/tool.js +14 -4
- package/core/tools/trim.js +71 -32
- package/core/tools/zoom.js +152 -0
- package/package.json +3 -305
- package/test/dimensions/alignedDimension.test.js +211 -0
- package/test/dimensions/angularDimension.test.js +243 -0
- package/test/dimensions/baseDimension.test.js +239 -0
- package/test/dimensions/diametricDimension.test.js +203 -0
- package/test/dimensions/dimension.test.js +102 -0
- package/test/dimensions/radialDimension.test.js +203 -0
- package/test/dimensions/rotatedDimension.test.js +224 -0
- package/test/entities/arc.test.js +463 -41
- package/test/entities/arctext.test.js +329 -0
- package/test/entities/basePolyline.test.js +459 -10
- package/test/entities/circle.test.js +312 -7
- package/test/entities/entity.test.js +28 -9
- package/test/entities/hatch.test.js +606 -0
- package/test/entities/insert.test.js +90 -0
- package/test/entities/line.test.js +182 -6
- package/test/entities/point.test.js +375 -37
- package/test/entities/solid.test.js +156 -0
- package/test/entities/text.test.js +533 -7
- package/test/integration/exportIntegration.reference.dxf +1706 -0
- package/test/integration/exportIntegration.test.js +186 -0
- package/test/integration/importExportIntegration.test.js +126 -0
- package/test/integration/intersectionIntegration.test.js +880 -0
- package/test/integration/userInputIntegration.reference.dxf +1410 -0
- package/test/integration/userInputIntegration.test.js +269 -0
- package/test/lib/boundingBox.test.js +26 -2
- package/test/lib/canvas.test.js +613 -5
- package/test/lib/clipboard.test.js +70 -0
- package/test/lib/colour.test.js +114 -0
- package/test/lib/colours.test.js +63 -18
- package/test/lib/commandLine.test.js +159 -22
- package/test/lib/commandManager.test.js +4 -4
- package/test/lib/constants.test.js +9 -0
- package/test/lib/dxf/dxfFile.test.js +6 -2
- package/test/lib/dxf/dxfIterator.test.js +1 -1
- package/test/lib/dxf/dxfWrite.test.js +173 -0
- package/test/lib/dxf/handleManager.test.js +137 -0
- package/test/lib/dxf/sections/blocks.test.js +5 -5
- package/test/lib/dxf/sections/entities.test.js +4 -4
- package/test/lib/dxf/sections/header.test.js +18 -4
- package/test/lib/dxf/sections/objects.test.js +132 -0
- package/test/lib/dxf/sections/section.test.js +29 -29
- package/test/lib/dxf/sections/tables.test.js +3 -3
- package/test/lib/entityManager.test.js +163 -0
- package/test/lib/headers.test.js +233 -0
- package/test/lib/inputManager.test.js +1144 -5
- package/test/lib/intersect.test.js +454 -331
- package/test/lib/logging.test.js +1 -1
- package/test/lib/matrix.test.js +1 -1
- package/test/lib/mouse.test.js +327 -4
- package/test/lib/patterns.test.js +105 -0
- package/test/lib/promptOptions.test.js +179 -0
- package/test/lib/scene.test.js +16 -52
- package/test/lib/selectionManager.test.js +17 -5
- package/test/lib/settings.test.js +111 -5
- package/test/lib/snapping.test.js +142 -4
- package/test/lib/stateManager.test.js +155 -0
- package/test/lib/utils.test.js +81 -1
- package/test/objects/dictionary.test.js +81 -0
- package/test/objects/dictionaryManager.test.js +34 -0
- package/test/properties/dimType.test.js +62 -0
- package/test/properties/flags.test.js +164 -0
- package/test/properties/property.test.js +13 -0
- package/test/properties/propertyManager.test.js +10 -11
- package/test/tables/appId.test.js +46 -0
- package/test/tables/appIdManager.test.js +72 -0
- package/test/tables/block.test.js +157 -0
- package/test/tables/blockManager.test.js +52 -0
- package/test/tables/blockRecord.test.js +39 -0
- package/test/tables/blockRecordManager.test.js +60 -0
- package/test/tables/dimstyle.test.js +72 -0
- package/test/tables/endblk.test.js +30 -0
- package/test/tables/layer.test.js +95 -0
- package/test/tables/layerManager.test.js +172 -0
- package/test/{styles → tables}/ltype.test.js +7 -7
- package/test/{styles → tables}/ltypeManager.test.js +2 -2
- package/test/tables/style.test.js +44 -0
- package/test/tables/stylemanagerbase.test.js +220 -0
- package/test/tables/tableManagerBase.test.js +194 -0
- package/test/tables/ucs.test.js +37 -0
- package/test/tables/ucsManager.test.js +48 -0
- package/test/tables/view.test.js +37 -0
- package/test/tables/viewManager.test.js +48 -0
- package/test/tables/vport.test.js +117 -0
- package/test/tables/vportManager.test.js +54 -0
- package/test/test-helpers/test-helpers.js +66 -0
- package/test/tools/chamfer.test.js +970 -0
- package/test/tools/chamferFilletBase.test.js +446 -0
- package/test/tools/copy.test.js +22 -14
- package/test/tools/copybase.test.js +93 -0
- package/test/tools/copyclip.test.js +92 -0
- package/test/tools/cornerEntity.test.js +201 -0
- package/test/tools/cutclip.test.js +94 -0
- package/test/tools/distance.test.js +140 -18
- package/test/tools/erase.test.js +12 -12
- package/test/tools/explode.test.js +45 -0
- package/test/tools/extend.test.js +326 -44
- package/test/tools/fillet.test.js +831 -0
- package/test/tools/identify.test.js +115 -16
- package/test/tools/matchProp.test.js +84 -0
- package/test/tools/mirror.test.js +475 -0
- package/test/tools/move.test.js +75 -19
- package/test/tools/offset.test.js +748 -0
- package/test/tools/pan.test.js +72 -0
- package/test/tools/pasteclip.test.js +100 -0
- package/test/tools/purge.test.js +89 -0
- package/test/tools/rotate.test.js +89 -23
- package/test/tools/scale.test.js +529 -0
- package/test/tools/trim.test.js +419 -84
- package/test/tools/zoom.test.js +504 -0
- package/core/entities/alignedDimension.js +0 -279
- package/core/entities/angularDimension.js +0 -194
- package/core/entities/baseDimension.js +0 -227
- package/core/entities/block.js +0 -247
- package/core/entities/diametricDimension.js +0 -133
- package/core/entities/dimension.js +0 -202
- package/core/entities/radialDimension.js +0 -126
- package/core/styles/dimStyle.js +0 -719
- package/core/styles/dimStyleManager.js +0 -47
- package/core/styles/layer.js +0 -133
- package/core/styles/layerManager.js +0 -40
- package/core/styles/ltype.js +0 -86
- package/core/styles/ltypeManager.js +0 -50
- package/core/styles/style.js +0 -158
- package/core/styles/styleManager.js +0 -43
- package/core/styles/styleManagerBase.js +0 -299
- package/test/entities/block.test.js +0 -22
- package/test/styles/dimstyle.test.js +0 -19
- package/test/styles/layerManager.test.js +0 -150
- package/test/styles/style.test.js +0 -33
- package/test/styles/stylemanagerbase.test.js +0 -219
|
@@ -0,0 +1,558 @@
|
|
|
1
|
+
import { Point } from '../entities/point.js';
|
|
2
|
+
import { Block } from '../tables/block.js';
|
|
3
|
+
import { Text } from '../entities/text.js';
|
|
4
|
+
import { Solid } from '../entities/solid.js';
|
|
5
|
+
import { Line } from '../entities/line.js';
|
|
6
|
+
import { Entity } from '../entities/entity.js';
|
|
7
|
+
import { Logging } from '../lib/logging.js';
|
|
8
|
+
import { Property } from '../properties/property.js';
|
|
9
|
+
import { Strings } from '../lib/strings.js';
|
|
10
|
+
import { Utils } from '../lib/utils.js';
|
|
11
|
+
|
|
12
|
+
import { DesignCore } from '../designCore.js';
|
|
13
|
+
import { DimType } from '../properties/dimType.js';
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Base Dimension Entity Class
|
|
17
|
+
* @extends Entity
|
|
18
|
+
*/
|
|
19
|
+
export class BaseDimension extends Entity {
|
|
20
|
+
/**
|
|
21
|
+
* Create a Base Dimension
|
|
22
|
+
* @param {Array} data
|
|
23
|
+
*/
|
|
24
|
+
constructor(data) {
|
|
25
|
+
super(data);
|
|
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
|
+
});
|
|
32
|
+
|
|
33
|
+
// hide inherited property
|
|
34
|
+
Object.defineProperty(this, 'lineWidth', {
|
|
35
|
+
enumerable: false,
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
Object.defineProperty(this, 'blockName', {
|
|
39
|
+
value: '',
|
|
40
|
+
writable: true,
|
|
41
|
+
});
|
|
42
|
+
|
|
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,
|
|
52
|
+
});
|
|
53
|
+
*/
|
|
54
|
+
|
|
55
|
+
Object.defineProperty(this, 'textOverride', {
|
|
56
|
+
value: '',
|
|
57
|
+
writable: true,
|
|
58
|
+
enumerable: true,
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
Object.defineProperty(this, 'dimType', {
|
|
62
|
+
value: new DimType(),
|
|
63
|
+
writable: true,
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
Object.defineProperty(this, 'dimensionStyle', {
|
|
67
|
+
value: 'STANDARD',
|
|
68
|
+
writable: true,
|
|
69
|
+
enumerable: true,
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
Object.defineProperty(this, 'leaderLength', {
|
|
73
|
+
value: 0,
|
|
74
|
+
writable: true,
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
Object.defineProperty(this, 'linearDimAngle', {
|
|
78
|
+
value: 0,
|
|
79
|
+
writable: true,
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
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
|
+
if (data.hasOwnProperty('41')) {
|
|
113
|
+
// DXF Groupcode 41 - Line Spacing Factor
|
|
114
|
+
// Percentage of default (3-on-5) line spacing to be applied.
|
|
115
|
+
// Valid values range from 0.25 to 4.00
|
|
116
|
+
const err = 'Groupcode 41 not implemented';
|
|
117
|
+
Logging.instance.debug(`${this.type} - ${err}`);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
if (data.hasOwnProperty('42')) {
|
|
121
|
+
// DXF Groupcode 42 - Actual Measurement
|
|
122
|
+
// Read-only
|
|
123
|
+
const err = 'Groupcode 42 not implemented';
|
|
124
|
+
Logging.instance.debug(`${this.type} - ${err}`);
|
|
125
|
+
}
|
|
126
|
+
|
|
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
|
+
if (data.hasOwnProperty('51')) {
|
|
133
|
+
// DXF Groupcode 51 - Horizontal Direction
|
|
134
|
+
// All dimension types have an optional 51 group code, which indicates the horizontal direction
|
|
135
|
+
// for the dimension entity. The dimension entity determines the orientation of dimension
|
|
136
|
+
// text and lines for horizontal, vertical, and rotated linear dimensions
|
|
137
|
+
// This group value is the negative if the angle between the OCS X axis and the UCS X axis.
|
|
138
|
+
// It is always in the XY plane of the OCS
|
|
139
|
+
const err = 'Groupcode 51 not implemented';
|
|
140
|
+
Logging.instance.warn(`${this.type} - ${err}`);
|
|
141
|
+
}
|
|
142
|
+
|
|
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
|
+
if (data.hasOwnProperty('dimType') || data.hasOwnProperty('70')) {
|
|
150
|
+
// DXF Groupcode 70 - Dimension Type
|
|
151
|
+
// Values 0-6 are integer values that represent the dimension type. Values 32, 64, and 128
|
|
152
|
+
// are bit values, which are added to the integer values
|
|
153
|
+
// (value 32 is always set in R13 and later releases)
|
|
154
|
+
// 0 = Rotated, horizontal, or vertical;
|
|
155
|
+
// 1 = Aligned;
|
|
156
|
+
// 2 = Angular;
|
|
157
|
+
// 3 = Diameter;
|
|
158
|
+
// 4 = Radius;
|
|
159
|
+
// 5 = Angular 3 point;
|
|
160
|
+
// 6 = Ordinate;
|
|
161
|
+
// 32 = Indicates that the block reference (group code 2) is referenced by this dimension only
|
|
162
|
+
// 64 = Ordinate type. This is a bit value (bit 7) used only with integer value 6.
|
|
163
|
+
// If set, ordinate is X-type; if not set, ordinate is Y-type
|
|
164
|
+
// 128 = This is a bit value (bit 8) added to the other group 70 values if the dimension text
|
|
165
|
+
// has been positioned at a user-defined location rather than at the default location
|
|
166
|
+
|
|
167
|
+
let dimTypeValue = data.dimType;
|
|
168
|
+
|
|
169
|
+
if (data.dimType instanceof DimType) {
|
|
170
|
+
dimTypeValue = data.dimType.getBaseDimType();
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
const dimensionType = Property.loadValue([data[70], dimTypeValue], 0);
|
|
174
|
+
|
|
175
|
+
if (!DimType.isValidDimensionType(dimensionType)) {
|
|
176
|
+
const msg = 'Invalid Dimension Type';
|
|
177
|
+
const err = (`${this.type} - ${msg}: ${dimensionType}`);
|
|
178
|
+
throw Error(err);
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
this.dimType.setDimType(dimensionType);
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
if (data.hasOwnProperty('71')) {
|
|
185
|
+
// 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
|
|
189
|
+
const err = 'Groupcode 71 not implemented';
|
|
190
|
+
Logging.instance.debug(`${this.type} - ${err}`);
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
if (data.hasOwnProperty('72')) {
|
|
194
|
+
// DXF Groupcode 72 - Line Spacing
|
|
195
|
+
// 1 (or missing) = At least (taller characters will override)
|
|
196
|
+
// 2 = Exact (taller characters will not override)
|
|
197
|
+
const err = 'Groupcode 72 not implemented';
|
|
198
|
+
Logging.instance.debug(`${this.type} - ${err}`);
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
if (data.leaderLength) {
|
|
202
|
+
this.leaderLength = data.leaderLength;
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
/**
|
|
208
|
+
* Get the dimension value formatted according to the dimension style
|
|
209
|
+
* @param {number} dimensionValue - the value to format
|
|
210
|
+
* @return {string} - the formatted dimension value
|
|
211
|
+
*/
|
|
212
|
+
getDimensionValue(dimensionValue) {
|
|
213
|
+
// Formatted value to return
|
|
214
|
+
let formattedDimensionValue = '';
|
|
215
|
+
|
|
216
|
+
// Default precision from style
|
|
217
|
+
const precision = this.getDimensionStyle().getValue('DIMDEC');
|
|
218
|
+
const angularPrecision = this.getDimensionStyle().getValue('DIMADEC');
|
|
219
|
+
|
|
220
|
+
// Dimension Rounding - DIMRND
|
|
221
|
+
// rounding is not applied to angular dimensions
|
|
222
|
+
const DIMRND = this.getDimensionStyle().getValue('DIMRND');
|
|
223
|
+
if (DIMRND !== 0 && this.dimType.getBaseDimType() !== 2) {
|
|
224
|
+
dimensionValue = Math.round(dimensionValue / DIMRND) * DIMRND;
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
let linearDimensionValue = Math.abs(dimensionValue).toFixed(precision);
|
|
228
|
+
let angularDimensionValue = Math.abs(dimensionValue).toFixed(angularPrecision);
|
|
229
|
+
|
|
230
|
+
// Zero suppression
|
|
231
|
+
// Values 0-3 affect feet-and-inch dimensions only:
|
|
232
|
+
// 0 = Suppresses zero feet and precisely zero inches
|
|
233
|
+
// 1 = Includes zero feet and precisely zero inches
|
|
234
|
+
// 2 = Includes zero feet and suppresses zero inches
|
|
235
|
+
// 3 = Includes zero inches and suppresses zero feet
|
|
236
|
+
// 4 = Suppresses leading zeros in decimal dimensions (for example, 0.5000 becomes .5000)
|
|
237
|
+
// 8 = Suppresses trailing zeros in decimal dimensions (for example, 12.5000 becomes 12.5)
|
|
238
|
+
// 12 = Suppresses both leading and trailing zeros (for example, 0.5000 becomes .5)
|
|
239
|
+
|
|
240
|
+
const DIMZIN = this.getDimensionStyle().getValue('DIMZIN');
|
|
241
|
+
const suppressLeadingLinear = (DIMZIN === 4 || DIMZIN === 12);
|
|
242
|
+
const suppressTrailingLinear = (DIMZIN === 8 || DIMZIN === 12);
|
|
243
|
+
linearDimensionValue = this.suppressZeros(linearDimensionValue, suppressLeadingLinear, suppressTrailingLinear);
|
|
244
|
+
|
|
245
|
+
const DIMAZIN = this.getDimensionStyle().getValue('DIMAZIN');
|
|
246
|
+
const suppressLeadingAngular = (DIMAZIN === 1 || DIMAZIN === 3);
|
|
247
|
+
const suppressTrailingAngular = (DIMAZIN === 2 || DIMAZIN === 3);
|
|
248
|
+
angularDimensionValue = this.suppressZeros(angularDimensionValue, suppressLeadingAngular, suppressTrailingAngular);
|
|
249
|
+
|
|
250
|
+
switch (this.dimType.getBaseDimType()) {
|
|
251
|
+
case 0: // Rotated, horizontal, or vertical
|
|
252
|
+
case 1: // Aligned
|
|
253
|
+
formattedDimensionValue = `${linearDimensionValue}`;
|
|
254
|
+
break;
|
|
255
|
+
case 2: // Angular
|
|
256
|
+
formattedDimensionValue = `${angularDimensionValue}${Strings.Symbol.DEGREE}`;
|
|
257
|
+
break;
|
|
258
|
+
case 3: // Diameter
|
|
259
|
+
formattedDimensionValue = `${Strings.Symbol.DIAMETER}${linearDimensionValue}`;
|
|
260
|
+
break;
|
|
261
|
+
case 4: // Radius
|
|
262
|
+
formattedDimensionValue = `${Strings.Symbol.RADIUS}${linearDimensionValue}`;
|
|
263
|
+
break;
|
|
264
|
+
case 5: // Angular 3 point
|
|
265
|
+
formattedDimensionValue = `${angularDimensionValue}${Strings.Symbol.DEGREE}`;
|
|
266
|
+
break;
|
|
267
|
+
case 6: // Ordinate
|
|
268
|
+
// Ordinate dimensions are typically used to indicate the X or Y coordinate of a point
|
|
269
|
+
formattedDimensionValue = `${linearDimensionValue} ${Strings.Symbol.UNITS}`;
|
|
270
|
+
break;
|
|
271
|
+
default:
|
|
272
|
+
formattedDimensionValue = `${linearDimensionValue}`;
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
// Decimal separator - DIMDSEP
|
|
276
|
+
const DIMDSEP = this.getDimensionStyle().getValue('DIMDSEP');
|
|
277
|
+
// Replace dot with specified separator
|
|
278
|
+
if (DIMDSEP !== '.') {
|
|
279
|
+
formattedDimensionValue = formattedDimensionValue.replace('.', DIMDSEP);
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
// Handle textOverride
|
|
283
|
+
if (this.textOverride !== '') {
|
|
284
|
+
formattedDimensionValue = this.textOverride.replace(/<>/g, formattedDimensionValue);
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
// TODO: Implement prefix and postsuffix - DIMPOST
|
|
288
|
+
// prefix and suffix included in DIMPOST value separated by <>
|
|
289
|
+
// e.g. prefix<>suffix
|
|
290
|
+
// const DIMPOST = this.getDimensionStyle().getValue('DIMPOST');
|
|
291
|
+
// const DIMAPOST = this.getDimensionStyle().getValue('DIMAPOST');
|
|
292
|
+
|
|
293
|
+
// TODO: Implement Unit format - DIMLUNIT
|
|
294
|
+
// 1 = Scientific; 2 = Decimal; 3 = Engineering;
|
|
295
|
+
// 4 = Architectural; 5 = Fractional; 6 = Windows desktop
|
|
296
|
+
// const DIMLUNIT = this.getDimensionStyle().getValue('DIMLUNIT');
|
|
297
|
+
|
|
298
|
+
return formattedDimensionValue;
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
/**
|
|
302
|
+
* Suppress leading and/or trailing zeros from a dimension value
|
|
303
|
+
* @param {number} dimensionValue
|
|
304
|
+
* @param {boolean} suppressLeading
|
|
305
|
+
* @param {boolean} suppressTrailing
|
|
306
|
+
* @return {string} - the dimension value as a string with suppressed zeros
|
|
307
|
+
*/
|
|
308
|
+
suppressZeros(dimensionValue, suppressLeading, suppressTrailing) {
|
|
309
|
+
let numberString = dimensionValue.toString();
|
|
310
|
+
|
|
311
|
+
if (suppressLeading) {
|
|
312
|
+
// Suppress leading zeros
|
|
313
|
+
numberString = numberString.replace(/^0+/, '');
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
if (suppressTrailing) {
|
|
317
|
+
// Suppress trailing zeros
|
|
318
|
+
numberString = numberString.replace(/(\.\d*?[1-9])0+$/g, '$1').replace(/\.0+$/, '');
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
if (numberString === '') {
|
|
322
|
+
// If the result is an empty string return '0'
|
|
323
|
+
numberString = '0';
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
return numberString;
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
/**
|
|
330
|
+
* set the dimensions text value
|
|
331
|
+
* @param {string} textValue - the dimension value to set
|
|
332
|
+
* @param {Point} textPosition - the position of the text
|
|
333
|
+
* @param {number} textRotation - the rotation of the text (radians)
|
|
334
|
+
* @return {Text} Dimension Text
|
|
335
|
+
*/
|
|
336
|
+
getDimensionText(textValue, textPosition, textRotation) {
|
|
337
|
+
const text = new Text();
|
|
338
|
+
// get the text height
|
|
339
|
+
const textHeight = this.getDimensionStyle().getValue('DIMTXT');
|
|
340
|
+
// set the text height
|
|
341
|
+
text.height = textHeight;
|
|
342
|
+
// Always set text horizontal alignment to center
|
|
343
|
+
text.horizontalAlignment = 1;
|
|
344
|
+
// Always set text vertical alignment to middle
|
|
345
|
+
text.verticalAlignment = 2;
|
|
346
|
+
// set the text value
|
|
347
|
+
text.string = this.getDimensionValue(textValue);
|
|
348
|
+
// set the text position
|
|
349
|
+
text.points = [textPosition];
|
|
350
|
+
// set the text rotation
|
|
351
|
+
text.setRotation(Utils.radians2degrees(this.getTextDirection(textRotation)));
|
|
352
|
+
|
|
353
|
+
return text;
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
/**
|
|
357
|
+
* Get the text direction ensuring it is always oriented correctly
|
|
358
|
+
* @param {number} textDirection - the direction of the text (radians)
|
|
359
|
+
* @return {number} - the adjusted text direction (radians)
|
|
360
|
+
*/
|
|
361
|
+
getTextDirection(textDirection) {
|
|
362
|
+
// Ensure the text is orientated correctly
|
|
363
|
+
if (textDirection > Math.PI / 2 && textDirection <= Math.PI * 1.5) {
|
|
364
|
+
textDirection = textDirection + Math.PI;
|
|
365
|
+
}
|
|
366
|
+
return textDirection;
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
/**
|
|
370
|
+
* Check if two angles are aligned or opposite
|
|
371
|
+
* @param {number} angle1 in radians
|
|
372
|
+
* @param {number} angle2 in radians
|
|
373
|
+
* @return {boolean} true if aligned or opposite
|
|
374
|
+
*/
|
|
375
|
+
alignedOrOpposite(angle1, angle2) {
|
|
376
|
+
const firstAngle = Utils.round(angle1 % (Math.PI * 2));
|
|
377
|
+
const secondAngle = Utils.round(angle2 % (Math.PI * 2));
|
|
378
|
+
const reversedSecondAngle = Utils.round((angle2 + Math.PI) % (Math.PI * 2));
|
|
379
|
+
|
|
380
|
+
return (firstAngle === secondAngle || firstAngle === reversedSecondAngle);
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
/**
|
|
384
|
+
* Get the dimension style
|
|
385
|
+
* @return {Object} - the dimension style object
|
|
386
|
+
*/
|
|
387
|
+
getDimensionStyle() {
|
|
388
|
+
return DesignCore.DimStyleManager.getItemByName(this.dimensionStyle);
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
/**
|
|
392
|
+
* Get the point for the sequence number
|
|
393
|
+
* @param {Array} points - array of points to search
|
|
394
|
+
* @param {number} sequenceNumber
|
|
395
|
+
* @return {Point}
|
|
396
|
+
*/
|
|
397
|
+
getPointBySequence(points, sequenceNumber) {
|
|
398
|
+
const point = points.find((point) => point.sequence === sequenceNumber);
|
|
399
|
+
|
|
400
|
+
if (!point) {
|
|
401
|
+
return null;
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
return point;
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
/**
|
|
408
|
+
* Define the arrow head
|
|
409
|
+
* @param {Point} point
|
|
410
|
+
* @param {number} angle
|
|
411
|
+
* @return {Solid}
|
|
412
|
+
*/
|
|
413
|
+
getArrowHead(point, angle) {
|
|
414
|
+
// TODO: implement arrow styles
|
|
415
|
+
// get the arrow size
|
|
416
|
+
const arrowSize = this.getDimensionStyle().getValue('DIMASZ');
|
|
417
|
+
let p1 = new Point(point.x + arrowSize / 4, point.y + arrowSize);
|
|
418
|
+
let p2 = new Point(point.x - arrowSize / 4, point.y + arrowSize);
|
|
419
|
+
const ang = angle - Math.PI / 2;
|
|
420
|
+
p1 = p1.rotate(point, ang);
|
|
421
|
+
p2 = p2.rotate(point, ang);
|
|
422
|
+
|
|
423
|
+
const points = [point, p1, p2];
|
|
424
|
+
|
|
425
|
+
const arrowHead = new Solid({ points: points });
|
|
426
|
+
|
|
427
|
+
return arrowHead;
|
|
428
|
+
}
|
|
429
|
+
|
|
430
|
+
/**
|
|
431
|
+
* 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
|
|
434
|
+
*/
|
|
435
|
+
getCentreMark(point) {
|
|
436
|
+
/*
|
|
437
|
+
* 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
|
|
441
|
+
*/
|
|
442
|
+
|
|
443
|
+
const centreMark = [];
|
|
444
|
+
// get the center mark style
|
|
445
|
+
const markStyle = this.getDimensionStyle().getValue('DIMCENSTYL');
|
|
446
|
+
// get the centre mark size
|
|
447
|
+
const markSize = this.getDimensionStyle().getValue('DIMCENVALUE');
|
|
448
|
+
|
|
449
|
+
if (markStyle === 0) {
|
|
450
|
+
return centreMark;
|
|
451
|
+
}
|
|
452
|
+
|
|
453
|
+
if (markStyle > 0) {
|
|
454
|
+
const lineOne = new Line({ points: [new Point(point.x - markSize, point.y), new Point(point.x + markSize, point.y)] });
|
|
455
|
+
const lineTwo = new Line({ points: [new Point(point.x, point.y - markSize), new Point(point.x, point.y + markSize)] });
|
|
456
|
+
centreMark.push(lineOne, lineTwo);
|
|
457
|
+
|
|
458
|
+
if (markStyle > 1) {
|
|
459
|
+
const lineThree = new Line({ points: [new Point(point.x, point.y + markSize * 2), new Point(point.x, point.y + markSize * 5)] });
|
|
460
|
+
const lineFour = new Line({ points: [new Point(point.x - markSize * 2, point.y), new Point(point.x - markSize * 5, point.y)] });
|
|
461
|
+
const lineFive = new Line({ points: [new Point(point.x, point.y - markSize * 2), new Point(point.x, point.y - markSize * 5)] });
|
|
462
|
+
const lineSix = new Line({ points: [new Point(point.x + markSize * 2, point.y), new Point(point.x + markSize * 5, point.y)] });
|
|
463
|
+
|
|
464
|
+
centreMark.push(lineThree, lineFour, lineFive, lineSix);
|
|
465
|
+
}
|
|
466
|
+
}
|
|
467
|
+
|
|
468
|
+
return centreMark;
|
|
469
|
+
}
|
|
470
|
+
|
|
471
|
+
/**
|
|
472
|
+
* Draw the entity
|
|
473
|
+
* @param {Object} ctx - context
|
|
474
|
+
* @param {number} scale
|
|
475
|
+
*/
|
|
476
|
+
draw(ctx, scale) {
|
|
477
|
+
if (this.block.items.length === 0) {
|
|
478
|
+
this.refresh();
|
|
479
|
+
}
|
|
480
|
+
|
|
481
|
+
this.block.draw(ctx, scale, this);
|
|
482
|
+
}
|
|
483
|
+
|
|
484
|
+
/**
|
|
485
|
+
* Get snap points
|
|
486
|
+
* @param {Point} mousePoint
|
|
487
|
+
* @param {number} delta
|
|
488
|
+
* @return {Array} - array of snap points
|
|
489
|
+
*/
|
|
490
|
+
snaps(mousePoint, delta) {
|
|
491
|
+
const snaps = [];
|
|
492
|
+
return snaps;
|
|
493
|
+
}
|
|
494
|
+
|
|
495
|
+
/**
|
|
496
|
+
* Get closest point on entity
|
|
497
|
+
* @param {Point} P
|
|
498
|
+
* @return {Array} - [Point, distance]
|
|
499
|
+
*/
|
|
500
|
+
closestPoint(P) {
|
|
501
|
+
return this.block.closestPoint(P);
|
|
502
|
+
}
|
|
503
|
+
|
|
504
|
+
/**
|
|
505
|
+
* Return boundingbox for entity
|
|
506
|
+
* @return {BoundingBox}
|
|
507
|
+
*/
|
|
508
|
+
boundingBox() {
|
|
509
|
+
return this.block.boundingBox();
|
|
510
|
+
}
|
|
511
|
+
|
|
512
|
+
/**
|
|
513
|
+
* Determine if the entity is within the selection
|
|
514
|
+
* @param {Object} selection - {min: Point, max: Point}
|
|
515
|
+
* @return {boolean} true if within
|
|
516
|
+
*/
|
|
517
|
+
within(selection) {
|
|
518
|
+
return this.block.within(selection);
|
|
519
|
+
}
|
|
520
|
+
|
|
521
|
+
/**
|
|
522
|
+
* Determine if the entity is touch the selection window
|
|
523
|
+
* @param {Object} selection - {min: Point, max: Point}
|
|
524
|
+
* @return {boolean} true if touched
|
|
525
|
+
*/
|
|
526
|
+
touched(selection) {
|
|
527
|
+
return this.block.touched(selection);
|
|
528
|
+
}
|
|
529
|
+
|
|
530
|
+
/**
|
|
531
|
+
* Refesh the dimension geometry
|
|
532
|
+
*/
|
|
533
|
+
refresh() {
|
|
534
|
+
const entities = this.buildDimension();
|
|
535
|
+
|
|
536
|
+
if (entities) {
|
|
537
|
+
this.block.clearItems();
|
|
538
|
+
|
|
539
|
+
entities.forEach((element) => {
|
|
540
|
+
// For colour BYBLOCK for dimensions
|
|
541
|
+
element.setColour('BYBLOCK');
|
|
542
|
+
this.block.addItem(element);
|
|
543
|
+
});
|
|
544
|
+
}
|
|
545
|
+
}
|
|
546
|
+
|
|
547
|
+
/**
|
|
548
|
+
* Set a property if it exists
|
|
549
|
+
* @param {string} property
|
|
550
|
+
* @param {any} value
|
|
551
|
+
*/
|
|
552
|
+
setProperty(property, value) {
|
|
553
|
+
if (this.hasOwnProperty(property)) {
|
|
554
|
+
this[property] = value;
|
|
555
|
+
this.refresh();
|
|
556
|
+
}
|
|
557
|
+
}
|
|
558
|
+
}
|