@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
|
@@ -1,299 +0,0 @@
|
|
|
1
|
-
import {DesignCore} from '../designCore.js';
|
|
2
|
-
import {Strings} from '../lib/strings.js';
|
|
3
|
-
|
|
4
|
-
export class StyleManagerBase {
|
|
5
|
-
constructor() {
|
|
6
|
-
this.styles = [];
|
|
7
|
-
this.addStandardStyles();
|
|
8
|
-
// set the current style to the first available style
|
|
9
|
-
this.currentstyle = this.styles[0].name;
|
|
10
|
-
|
|
11
|
-
// list of mandatory styles or layers that cannot be deleted
|
|
12
|
-
this.indelibleStyles = [];
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* Get styles
|
|
17
|
-
* @returns list of styles
|
|
18
|
-
*/
|
|
19
|
-
getStyles() {
|
|
20
|
-
return this.styles;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* Get style count
|
|
25
|
-
* @returns number of styles
|
|
26
|
-
*/
|
|
27
|
-
styleCount() {
|
|
28
|
-
return this.styles.length;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
/**
|
|
32
|
-
* Adds a new style to the list of active styles
|
|
33
|
-
*/
|
|
34
|
-
newStyle() {
|
|
35
|
-
this.addStyle({
|
|
36
|
-
'name': this.getUniqueName('NEW_STYLE'),
|
|
37
|
-
});
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
/**
|
|
41
|
-
* Generate a unique name
|
|
42
|
-
* @param {string} name
|
|
43
|
-
* @returns unique name
|
|
44
|
-
*/
|
|
45
|
-
getUniqueName(name) {
|
|
46
|
-
let count = 0;
|
|
47
|
-
let styStr = name.replace(/ /g, '_'); // .toUpperCase();
|
|
48
|
-
for (let i = 0; i < this.styleCount(); i++) {
|
|
49
|
-
const styleName = this.styles[i].name.toUpperCase();
|
|
50
|
-
if (styleName.includes(styStr.toUpperCase())) {
|
|
51
|
-
count = count + 1;
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
if (count > 0) {
|
|
55
|
-
styStr = styStr + '_' + count;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
return styStr;
|
|
59
|
-
};
|
|
60
|
-
|
|
61
|
-
/**
|
|
62
|
-
* Add a style to the list of styles
|
|
63
|
-
* @param {style} style
|
|
64
|
-
*/
|
|
65
|
-
addStyle(style, overwrite=false) {
|
|
66
|
-
// Call the subclass to create a new typed style object
|
|
67
|
-
const newStyle = this.createStyle(style);
|
|
68
|
-
const newStyleName = newStyle.name;
|
|
69
|
-
if (!this.styleExists(newStyleName)) {
|
|
70
|
-
this.styles.push(newStyle);
|
|
71
|
-
} else if (overwrite) {
|
|
72
|
-
// Overwrite The style existing style
|
|
73
|
-
// This is used when loading files;
|
|
74
|
-
// Standard styles already exist but should be overwritten by the incoming style
|
|
75
|
-
this.styles.splice(this.getStyleIndex(newStyleName), 1, newStyle);
|
|
76
|
-
}
|
|
77
|
-
// DesignCore.Scene.saveRequired();
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
/**
|
|
81
|
-
* Delete a style using the style index
|
|
82
|
-
* @param {number} styleIndex
|
|
83
|
-
* @returns undefined
|
|
84
|
-
*/
|
|
85
|
-
deleteStyle(styleIndex) {
|
|
86
|
-
if (this.styles[styleIndex] === undefined) {
|
|
87
|
-
return;
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
const styleToDelete = this.getStyleByIndex(styleIndex).name;
|
|
91
|
-
|
|
92
|
-
// Can't delete indelible styles (Standard Text Style, Layer 0)
|
|
93
|
-
if (this.indelibleStyles.some((style) => style.toUpperCase() === styleToDelete.toUpperCase())) {
|
|
94
|
-
DesignCore.Core.notify(`${styleToDelete} ${Strings.Message.CANNOTBEDELETED}`);
|
|
95
|
-
return;
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
// Can't delete current style
|
|
99
|
-
if (styleToDelete.toUpperCase() === this.currentstyle.toUpperCase()) {
|
|
100
|
-
DesignCore.Core.notify(Strings.Message.CSTYLEDELETE);
|
|
101
|
-
return;
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
// delete all item using the selected style
|
|
105
|
-
this.deleteStyleFromScene(styleToDelete);
|
|
106
|
-
|
|
107
|
-
// Delete The style
|
|
108
|
-
this.styles.splice(styleIndex, 1);
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
/**
|
|
112
|
-
* Delete all items that use style
|
|
113
|
-
* @param {string} style
|
|
114
|
-
*/
|
|
115
|
-
deleteStyleFromScene(style) {
|
|
116
|
-
const selectionSet = [];
|
|
117
|
-
|
|
118
|
-
for (let i = 0; i <DesignCore.Scene.items.length; i++) {
|
|
119
|
-
if (DesignCore.Scene.items[i][this.styleProperty] === style) {
|
|
120
|
-
selectionSet.push(i);
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
// sort the selection in descending order
|
|
125
|
-
selectionSet.sort((a, b)=>b-a);
|
|
126
|
-
|
|
127
|
-
for (let j = 0; j < selectionSet.length; j++) {
|
|
128
|
-
DesignCore.Scene.items.splice((selectionSet[j]), 1);
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
/**
|
|
133
|
-
* Get the name of the current style
|
|
134
|
-
*/
|
|
135
|
-
getCstyle() {
|
|
136
|
-
return this.currentstyle;
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
/**
|
|
140
|
-
* Set the current style
|
|
141
|
-
* @param {string} cstyle
|
|
142
|
-
*/
|
|
143
|
-
setCstyle(cstyle) {
|
|
144
|
-
if (this.getStyleByName(cstyle) !== undefined) {
|
|
145
|
-
this.currentstyle = cstyle;
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
/**
|
|
150
|
-
* Check if a style with styleName exists
|
|
151
|
-
* @param {string} styleName
|
|
152
|
-
* @returns true or false
|
|
153
|
-
*/
|
|
154
|
-
styleExists(styleName) {
|
|
155
|
-
const styleExists = this.styles.some((el) => el.name.toUpperCase() === styleName.toUpperCase());
|
|
156
|
-
return styleExists;
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
/**
|
|
160
|
-
* Ensure that used styles and default styles exist
|
|
161
|
-
*/
|
|
162
|
-
checkStyles() {
|
|
163
|
-
if (!this.styleCount()) {
|
|
164
|
-
this.addStandardStyles();
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
for (let i = 0; i < DesignCore.Scene.items.length; i++) {
|
|
168
|
-
const style = (DesignCore.Scene.getItem(i)[this.styleProperty]);
|
|
169
|
-
this.addStyle({
|
|
170
|
-
'name': style,
|
|
171
|
-
});
|
|
172
|
-
}
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
/**
|
|
176
|
-
* Clear all existing styles
|
|
177
|
-
*/
|
|
178
|
-
clearStyles() {
|
|
179
|
-
this.styles = [];
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
/**
|
|
183
|
-
* Find the index of styleName
|
|
184
|
-
* @param {string} styleName
|
|
185
|
-
* @returns index of the style or -1 if style doesn't exist
|
|
186
|
-
*/
|
|
187
|
-
getStyleIndex(styleName) {
|
|
188
|
-
return this.styles.findIndex((style) => style.name.toUpperCase() === styleName.toUpperCase());
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
/**
|
|
192
|
-
* get a style matching stylename
|
|
193
|
-
* @param {string} styleName
|
|
194
|
-
* @returns style object
|
|
195
|
-
*/
|
|
196
|
-
getStyleByName(styleName) {
|
|
197
|
-
for (let i = 0; i < this.styleCount(); i++) {
|
|
198
|
-
if (this.styles[i].name.toUpperCase() === styleName.toUpperCase()) {
|
|
199
|
-
return this.styles[i];
|
|
200
|
-
}
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
const msg = 'Invalid Style Name';
|
|
204
|
-
const err = (`${this.constructor.name} - ${msg}: ${styleName}`);
|
|
205
|
-
throw Error(err);
|
|
206
|
-
|
|
207
|
-
// return;
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
/**
|
|
211
|
-
* Get the style from an index
|
|
212
|
-
* @param {number} styleIndex
|
|
213
|
-
* @returns
|
|
214
|
-
*/
|
|
215
|
-
getStyleByIndex(styleIndex) {
|
|
216
|
-
return this.styles[styleIndex];
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
/**
|
|
221
|
-
* Rename the style at index with newName
|
|
222
|
-
* @param {number} styleIndex
|
|
223
|
-
* @param {string} newName
|
|
224
|
-
* @returns undefined
|
|
225
|
-
*/
|
|
226
|
-
renameStyle(styleIndex, newName) {
|
|
227
|
-
const styleToRename = this.getStyleByIndex(styleIndex).name;
|
|
228
|
-
|
|
229
|
-
// make sure it is a new name
|
|
230
|
-
if (styleToRename.toUpperCase() === newName.toUpperCase()) {
|
|
231
|
-
return;
|
|
232
|
-
}
|
|
233
|
-
|
|
234
|
-
// Can't rename indelible styles (Standard Text Style, Layer 0)
|
|
235
|
-
if (this.indelibleStyles.some((style) => style.toUpperCase() === styleToRename.toUpperCase())) {
|
|
236
|
-
DesignCore.Core.notify(`${styleToRename} ${Strings.Message.CANNOTBERENAMED}`);
|
|
237
|
-
return;
|
|
238
|
-
}
|
|
239
|
-
|
|
240
|
-
// Can't rename indelible styles (Standard Text Style, Layer 0)
|
|
241
|
-
if (this.indelibleStyles.some((style) => style.toUpperCase() === newName.toUpperCase())) {
|
|
242
|
-
DesignCore.Core.notify(`${newName} ${Strings.Message.CANNOTBERENAMED}`);
|
|
243
|
-
return;
|
|
244
|
-
}
|
|
245
|
-
|
|
246
|
-
const newUniqueName = this.getUniqueName(newName);
|
|
247
|
-
|
|
248
|
-
const currentStyleName = this.styles[styleIndex].name;
|
|
249
|
-
this.styles[styleIndex].name = newUniqueName;
|
|
250
|
-
|
|
251
|
-
// update all scene items with the new style value
|
|
252
|
-
this.updateSceneStyle(currentStyleName, newUniqueName);
|
|
253
|
-
|
|
254
|
-
// if the style to change is the current style, update the currentstyle property
|
|
255
|
-
if (currentStyleName === this.currentstyle) {
|
|
256
|
-
this.setCstyle(newUniqueName);
|
|
257
|
-
}
|
|
258
|
-
}
|
|
259
|
-
|
|
260
|
-
/**
|
|
261
|
-
* Update all items that use style
|
|
262
|
-
* @param {string} oldStyleName
|
|
263
|
-
* @param {string} newStyleName
|
|
264
|
-
*/
|
|
265
|
-
updateSceneStyle(oldStyleName, newStyleName) {
|
|
266
|
-
for (let i = 0; i <DesignCore.Scene.items.length; i++) {
|
|
267
|
-
if (DesignCore.Scene.items[i][this.styleProperty] === oldStyleName) {
|
|
268
|
-
DesignCore.Scene.items[i][this.styleProperty] = newStyleName;
|
|
269
|
-
}
|
|
270
|
-
}
|
|
271
|
-
}
|
|
272
|
-
|
|
273
|
-
/**
|
|
274
|
-
* Update the style property with value
|
|
275
|
-
* @param {number} styleIndex
|
|
276
|
-
* @param {string} property
|
|
277
|
-
* @param {any} value
|
|
278
|
-
*/
|
|
279
|
-
updateStyle(styleIndex, property, value) {
|
|
280
|
-
// check of the index exists
|
|
281
|
-
if (this.styles[styleIndex] === undefined) {
|
|
282
|
-
const msg = 'Invalid Style Index';
|
|
283
|
-
const err = (`${this.type} - ${msg}`);
|
|
284
|
-
throw Error(err);
|
|
285
|
-
}
|
|
286
|
-
|
|
287
|
-
if (this.styles[styleIndex][property] === undefined) {
|
|
288
|
-
const msg = 'Invalid Style Property';
|
|
289
|
-
const err = (`${this.type} - ${msg}`);
|
|
290
|
-
throw Error(err);
|
|
291
|
-
}
|
|
292
|
-
|
|
293
|
-
if (property.toUpperCase() === 'NAME') {
|
|
294
|
-
this.renameStyle(styleIndex, value);
|
|
295
|
-
} else {
|
|
296
|
-
this.styles[styleIndex][property] = value;
|
|
297
|
-
}
|
|
298
|
-
}
|
|
299
|
-
}
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import {Block} from '../../core/entities/block.js';
|
|
2
|
-
import {Line} from '../../core/entities/line.js';
|
|
3
|
-
import {Point} from '../../core/entities/point.js';
|
|
4
|
-
|
|
5
|
-
test('Test Block.boundingBox', () => {
|
|
6
|
-
const block = new Block();
|
|
7
|
-
const line = new Line({points: [new Point(101, 102), new Point(201, 202)]});
|
|
8
|
-
block.addItem(line);
|
|
9
|
-
|
|
10
|
-
expect(block.boundingBox().xMin).toBeCloseTo(101);
|
|
11
|
-
expect(block.boundingBox().xMax).toBeCloseTo(201);
|
|
12
|
-
expect(block.boundingBox().yMin).toBeCloseTo(102);
|
|
13
|
-
expect(block.boundingBox().yMax).toBeCloseTo(202);
|
|
14
|
-
|
|
15
|
-
const line2 = new Line({points: [new Point(1001, 1002), new Point(2001, 2002)]});
|
|
16
|
-
block.addItem(line2);
|
|
17
|
-
|
|
18
|
-
expect(block.boundingBox().xMin).toBeCloseTo(101);
|
|
19
|
-
expect(block.boundingBox().xMax).toBeCloseTo(2001);
|
|
20
|
-
expect(block.boundingBox().yMin).toBeCloseTo(102);
|
|
21
|
-
expect(block.boundingBox().yMax).toBeCloseTo(2002);
|
|
22
|
-
});
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import {DimStyle} from '../../core/styles/dimStyle';
|
|
2
|
-
|
|
3
|
-
test('Test DimStyle.getValue', () => {
|
|
4
|
-
const style = new DimStyle();
|
|
5
|
-
expect(style.getValue('DIMSE1')).toBe(false);
|
|
6
|
-
expect(style.getValue('DIMASZ')).toBe(2.5);
|
|
7
|
-
});
|
|
8
|
-
|
|
9
|
-
test('Test DimStyle.vertical', () => {
|
|
10
|
-
const style = new DimStyle();
|
|
11
|
-
expect(style.vertical).toBe(false);
|
|
12
|
-
expect(style.standardFlags).toBe(0);
|
|
13
|
-
|
|
14
|
-
style.vertical = true;
|
|
15
|
-
expect(style.vertical).toBe(true);
|
|
16
|
-
expect(style.standardFlags).toBe(4);
|
|
17
|
-
});
|
|
18
|
-
|
|
19
|
-
|
|
@@ -1,150 +0,0 @@
|
|
|
1
|
-
import {Core} from '../../core/core/core.js';
|
|
2
|
-
import {Point} from '../../core/entities/point.js';
|
|
3
|
-
|
|
4
|
-
const core = new Core();
|
|
5
|
-
const layerManager = core.layerManager;
|
|
6
|
-
|
|
7
|
-
test('Test LayerManager.getStyles', () => {
|
|
8
|
-
const layers = layerManager.getStyles();
|
|
9
|
-
expect(layers).toHaveLength(2);
|
|
10
|
-
|
|
11
|
-
expect(layers[0]).toHaveProperty('name', '0');
|
|
12
|
-
expect(layers[1]).toHaveProperty('name', 'DEFPOINTS');
|
|
13
|
-
});
|
|
14
|
-
|
|
15
|
-
test('Test LayerManager.styleCount', () => {
|
|
16
|
-
const count = layerManager.styleCount();
|
|
17
|
-
expect(count).toBe(2);
|
|
18
|
-
});
|
|
19
|
-
|
|
20
|
-
test('Test LayerManager.newStyle', () => {
|
|
21
|
-
const count = layerManager.styleCount();
|
|
22
|
-
layerManager.newStyle();
|
|
23
|
-
expect(layerManager.styleCount()).toBe(count + 1);
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
test('Test LayerManager.getUniqueName', () => {
|
|
27
|
-
// existing defpoints layer
|
|
28
|
-
let name = layerManager.getUniqueName('DEFPOINTS');
|
|
29
|
-
expect(name).toBe('DEFPOINTS_1');
|
|
30
|
-
// existing NEW_LAYER layer
|
|
31
|
-
name = layerManager.getUniqueName('NEW_STYLE');
|
|
32
|
-
expect(name).toBe('NEW_STYLE_1');
|
|
33
|
-
// unique layer
|
|
34
|
-
name = layerManager.getUniqueName('UNIQUE_LAYER');
|
|
35
|
-
expect(name).toBe('UNIQUE_LAYER');
|
|
36
|
-
});
|
|
37
|
-
|
|
38
|
-
test('Test LayerManager.addStyle', () => {
|
|
39
|
-
const count = layerManager.styleCount();
|
|
40
|
-
layerManager.addStyle({'name': 'test', 'colour': '#00BFFF'});
|
|
41
|
-
expect(layerManager.styleCount()).toBe(count + 1);
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
test('Test LayerManager.deleteStyle', () => {
|
|
45
|
-
const count = layerManager.styleCount();
|
|
46
|
-
// defpoints can't be deleted
|
|
47
|
-
layerManager.deleteStyle('DEFPOINTS');
|
|
48
|
-
expect(layerManager.styleCount()).toBe(count);
|
|
49
|
-
|
|
50
|
-
// clayer can't be deleted
|
|
51
|
-
layerManager.deleteStyle(layerManager.getCstyle());
|
|
52
|
-
expect(layerManager.styleCount()).toBe(count);
|
|
53
|
-
|
|
54
|
-
// test should be deleted
|
|
55
|
-
layerManager.deleteStyle(layerManager.getStyleIndex('test'));
|
|
56
|
-
expect(layerManager.styleCount()).toBe(count - 1);
|
|
57
|
-
});
|
|
58
|
-
|
|
59
|
-
test('Test LayerManager.deleteStyle', () => {
|
|
60
|
-
const count = layerManager.styleCount();
|
|
61
|
-
layerManager.deleteStyle(2);
|
|
62
|
-
expect(layerManager.styleCount()).toBe(count - 1);
|
|
63
|
-
});
|
|
64
|
-
|
|
65
|
-
test('Test LayerManager.getCstyle', () => {
|
|
66
|
-
const clayer = layerManager.getCstyle();
|
|
67
|
-
expect(clayer).toBe('0');
|
|
68
|
-
});
|
|
69
|
-
|
|
70
|
-
test('Test LayerManager.setCstyle', () => {
|
|
71
|
-
const layer = layerManager.getStyles().at(-1).name;
|
|
72
|
-
layerManager.setCstyle(layer);
|
|
73
|
-
expect(layerManager.getCstyle()).toBe(layer);
|
|
74
|
-
});
|
|
75
|
-
|
|
76
|
-
test('Test LayerManager.styleExists', () => {
|
|
77
|
-
expect(layerManager.styleExists('DEFPOINTS')).toBe(true);
|
|
78
|
-
expect(layerManager.styleExists('OBSCURE_LAYER_NAME')).toBe(false);
|
|
79
|
-
});
|
|
80
|
-
|
|
81
|
-
test('Test LayerManager.checkStyles', () => {
|
|
82
|
-
layerManager.layers = [];
|
|
83
|
-
|
|
84
|
-
const newStyleName = 'checkStyles';
|
|
85
|
-
const startPoint = new Point();
|
|
86
|
-
const endPoint = new Point(10, 10);
|
|
87
|
-
|
|
88
|
-
const data = {
|
|
89
|
-
points: [startPoint, endPoint],
|
|
90
|
-
colour: '#FFFFFF',
|
|
91
|
-
layer: newStyleName,
|
|
92
|
-
};
|
|
93
|
-
|
|
94
|
-
core.scene.addItem('Line', data, false);
|
|
95
|
-
|
|
96
|
-
layerManager.checkStyles();
|
|
97
|
-
const layers = layerManager.getStyles();
|
|
98
|
-
expect(layers).toHaveLength(3);
|
|
99
|
-
|
|
100
|
-
expect(layers[0]).toHaveProperty('name', '0');
|
|
101
|
-
expect(layers[1]).toHaveProperty('name', 'DEFPOINTS');
|
|
102
|
-
expect(layers[2]).toHaveProperty('name', newStyleName);
|
|
103
|
-
});
|
|
104
|
-
|
|
105
|
-
test('Test LayerManager.addStandardStyles', () => {
|
|
106
|
-
layerManager.clearStyles();
|
|
107
|
-
|
|
108
|
-
layerManager.addStandardStyles();
|
|
109
|
-
|
|
110
|
-
const layers = layerManager.getStyles();
|
|
111
|
-
expect(layers).toHaveLength(2);
|
|
112
|
-
|
|
113
|
-
expect(layers[0]).toHaveProperty('name', '0');
|
|
114
|
-
expect(layers[1]).toHaveProperty('name', 'DEFPOINTS');
|
|
115
|
-
});
|
|
116
|
-
|
|
117
|
-
test('Test LayerManager.getStyleIndex', () => {
|
|
118
|
-
layerManager.addStyle({'name': 'addStyle', 'colour': '#00BFFF'});
|
|
119
|
-
// get index for test layer - should be the last layer
|
|
120
|
-
expect(layerManager.getStyleIndex('addStyle')).toBe(layerManager.styleCount() - 1);
|
|
121
|
-
// get index for a layer that doesn't exist
|
|
122
|
-
expect(layerManager.getStyleIndex('no-exist')).toBe(-1);
|
|
123
|
-
});
|
|
124
|
-
|
|
125
|
-
test('Test LayerManager.getStyleByName', () => {
|
|
126
|
-
layerManager.addStyle({'name': 'test'});
|
|
127
|
-
const layer = layerManager.getStyleByName('test');
|
|
128
|
-
expect(layer.name).toBe('test');
|
|
129
|
-
// get a layer that doesn't exist
|
|
130
|
-
expect(() => {
|
|
131
|
-
layerManager.getStyleByName('no-exist');
|
|
132
|
-
}).toThrow();
|
|
133
|
-
});
|
|
134
|
-
|
|
135
|
-
test('Test LayerManager.getStyleByIndex', () => {
|
|
136
|
-
const testLayer = layerManager.getStyleByName('test');
|
|
137
|
-
const layer = layerManager.getStyleByIndex(layerManager.getStyleIndex('test'));
|
|
138
|
-
expect(testLayer === layer).toBe(true);
|
|
139
|
-
// get a layer that doesn't exist
|
|
140
|
-
expect(layerManager.getStyleByIndex(1000)).toBeUndefined();
|
|
141
|
-
});
|
|
142
|
-
|
|
143
|
-
test('Test LayerManager.renameStyle', () => {
|
|
144
|
-
const index = layerManager.getStyleIndex('test');
|
|
145
|
-
const newStylename = 'RENAMED_TEST';
|
|
146
|
-
layerManager.renameStyle(index, newStylename);
|
|
147
|
-
|
|
148
|
-
expect(layerManager.getStyleIndex(newStylename)).toBe(index);
|
|
149
|
-
expect(layerManager.getStyleIndex('test')).toBe(-1);
|
|
150
|
-
});
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import {Style} from '../../core/styles/style';
|
|
2
|
-
|
|
3
|
-
test('Test Style.vertical', () => {
|
|
4
|
-
const style = new Style();
|
|
5
|
-
expect(style.vertical).toBe(false);
|
|
6
|
-
expect(style.standardFlags).toBe(0);
|
|
7
|
-
|
|
8
|
-
style.vertical = true;
|
|
9
|
-
expect(style.vertical).toBe(true);
|
|
10
|
-
expect(style.standardFlags).toBe(4);
|
|
11
|
-
});
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
test('Test Style.backwards', () => {
|
|
15
|
-
const style = new Style();
|
|
16
|
-
expect(style.backwards).toBe(false);
|
|
17
|
-
expect(style.flags).toBe(0);
|
|
18
|
-
|
|
19
|
-
style.backwards = true;
|
|
20
|
-
expect(style.backwards).toBe(true);
|
|
21
|
-
expect(style.flags).toBe(2);
|
|
22
|
-
});
|
|
23
|
-
|
|
24
|
-
test('Test Style.upsideDown', () => {
|
|
25
|
-
const style = new Style();
|
|
26
|
-
expect(style.upsideDown).toBe(false);
|
|
27
|
-
expect(style.flags).toBe(0);
|
|
28
|
-
|
|
29
|
-
style.upsideDown = true;
|
|
30
|
-
expect(style.upsideDown).toBe(true);
|
|
31
|
-
expect(style.flags).toBe(4);
|
|
32
|
-
});
|
|
33
|
-
|