@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,198 @@
|
|
|
1
|
+
import { BoundingBox } from './boundingBox.js';
|
|
2
|
+
import { Point } from '../entities/point.js';
|
|
3
|
+
import { Utils } from './utils.js';
|
|
4
|
+
import { DesignCore } from '../designCore.js';
|
|
5
|
+
import { Logging } from './logging.js';
|
|
6
|
+
import { Strings } from './strings.js';
|
|
7
|
+
|
|
8
|
+
/** Clipboard Class */
|
|
9
|
+
export class Clipboard {
|
|
10
|
+
// store the base point for pasting
|
|
11
|
+
#basePoint = new Point();
|
|
12
|
+
// store the entities being copied
|
|
13
|
+
#Entities = [];
|
|
14
|
+
/** Create Clipboard */
|
|
15
|
+
constructor() {
|
|
16
|
+
this.clipboardCallbackFunction; // set to external callback function
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Sets the commandline callback to an external function
|
|
21
|
+
* @param {function} callback
|
|
22
|
+
*/
|
|
23
|
+
setClipboardCallbackFunction(callback) {
|
|
24
|
+
// set the call
|
|
25
|
+
this.clipboardCallbackFunction = callback;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Get the current base point
|
|
30
|
+
* @return {Point} - base point
|
|
31
|
+
*/
|
|
32
|
+
get BasePoint() {
|
|
33
|
+
return this.#basePoint;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Set a new base point and notify external clipboard
|
|
38
|
+
* @param {Point} point - new base point
|
|
39
|
+
*/
|
|
40
|
+
set BasePoint(point) {
|
|
41
|
+
this.#basePoint = point;
|
|
42
|
+
|
|
43
|
+
// call the callback function to update external clipboard
|
|
44
|
+
if (this.clipboardCallbackFunction) {
|
|
45
|
+
this.clipboardCallbackFunction();
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Get the current entities in the clipboard
|
|
51
|
+
* @return {Array} - entities array
|
|
52
|
+
*/
|
|
53
|
+
get Entities() {
|
|
54
|
+
return this.#Entities;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Set new entities to the clipboard and notify external clipboard
|
|
59
|
+
* @param {Array} entities - new entities array
|
|
60
|
+
*/
|
|
61
|
+
set Entities(entities) {
|
|
62
|
+
if (!Array.isArray(entities)) {
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
if (entities.length === 0) {
|
|
67
|
+
this.#Entities = [];
|
|
68
|
+
this.#basePoint = new Point();
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
// copy the item to avoid mutation of originals
|
|
73
|
+
this.#Entities = entities.map((entity) => Utils.cloneObject(entity));
|
|
74
|
+
// set basepoint to bottom left of selection bounding box
|
|
75
|
+
const bbox = BoundingBox.fromEntities(entities);
|
|
76
|
+
const basePoint = new Point(bbox.xMin, bbox.yMin);
|
|
77
|
+
this.#basePoint = basePoint;
|
|
78
|
+
|
|
79
|
+
// call the callback function to update external clipboard
|
|
80
|
+
if (this.clipboardCallbackFunction) {
|
|
81
|
+
this.clipboardCallbackFunction();
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Parse clipboard data from JSON string
|
|
87
|
+
* @param {string} json
|
|
88
|
+
*/
|
|
89
|
+
parse(json) {
|
|
90
|
+
// clear clipboard - temp debugging?
|
|
91
|
+
this.#basePoint = new Point();
|
|
92
|
+
this.#Entities = [];
|
|
93
|
+
try {
|
|
94
|
+
const clipBoardData = JSON.parse(json);
|
|
95
|
+
const JsonBasePoint = clipBoardData.basePoint;
|
|
96
|
+
const JsonEntities = clipBoardData.Entities;
|
|
97
|
+
const entities = this.#parseEntities(JsonEntities);
|
|
98
|
+
|
|
99
|
+
if (entities.length === 0) {
|
|
100
|
+
throw Error('No valid entities in clipboard data');
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
this.#basePoint = new Point(JsonBasePoint.x, JsonBasePoint.y);
|
|
104
|
+
this.#Entities = entities;
|
|
105
|
+
} catch {
|
|
106
|
+
Logging.instance.error(`${this.constructor.name} - ${Strings.Error.INVALIDCLIPBOARD}`);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* parse json to entities
|
|
112
|
+
* @param {Array} jsonEntities
|
|
113
|
+
* @return {Array} - array of entities
|
|
114
|
+
*/
|
|
115
|
+
#parseEntities(jsonEntities) {
|
|
116
|
+
try {
|
|
117
|
+
const entities = [];
|
|
118
|
+
for (const jsonEntity of jsonEntities) {
|
|
119
|
+
// create point object for points
|
|
120
|
+
if (jsonEntity.type === 'Point') {
|
|
121
|
+
const point = new Point(jsonEntity.x, jsonEntity.y, jsonEntity.bulge, jsonEntity.sequence);
|
|
122
|
+
entities.push(point);
|
|
123
|
+
continue;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
// loop through properties to parse arrays of child objects
|
|
127
|
+
for (const [key, value] of Object.entries(jsonEntity)) {
|
|
128
|
+
if (Array.isArray(value)) {
|
|
129
|
+
const values = this.#parseEntities(jsonEntity[key]);
|
|
130
|
+
jsonEntity[key] = values;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
// check if the type is a valid entity
|
|
135
|
+
if (DesignCore.CommandManager.isCommand(jsonEntity.type)) {
|
|
136
|
+
const entity = DesignCore.CommandManager.createNew(jsonEntity.type, jsonEntity);
|
|
137
|
+
entities.push(entity);
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
return entities;
|
|
141
|
+
} catch (err) {
|
|
142
|
+
Logging.instance.error(`${this.constructor.name} - ${Strings.Error.INVALIDCLIPBOARD}: ${err}`);
|
|
143
|
+
return [];
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* Convert clipboard data to JSON string
|
|
149
|
+
* @return {string} - JSON string of clipboard data
|
|
150
|
+
*/
|
|
151
|
+
stringify() {
|
|
152
|
+
const clipboardData = { basePoint: undefined, Entities: undefined };
|
|
153
|
+
const jsonEntities = [];
|
|
154
|
+
|
|
155
|
+
// convert each entity to a simple object - this allows non-enumberable properties (like points) to be copied
|
|
156
|
+
for (const ent of this.#Entities) {
|
|
157
|
+
const jsonEntity = this.#simplify(ent);
|
|
158
|
+
jsonEntities.push(jsonEntity);
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
clipboardData.basePoint = this.#basePoint;
|
|
162
|
+
clipboardData.Entities = jsonEntities;
|
|
163
|
+
|
|
164
|
+
const clipboardJson = JSON.stringify(clipboardData);
|
|
165
|
+
return clipboardJson;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
/**
|
|
169
|
+
* Simplify an object by copying only its own properties
|
|
170
|
+
* @param {Object} original
|
|
171
|
+
* @return {Object} - simplified object
|
|
172
|
+
*/
|
|
173
|
+
#simplify(original) {
|
|
174
|
+
return Object.getOwnPropertyNames(original).reduce((simplified, property) => {
|
|
175
|
+
const value = original[property];
|
|
176
|
+
if (Array.isArray(value)) {
|
|
177
|
+
simplified[property] = original[property].map((item) => this.#simplify(item));
|
|
178
|
+
return simplified;
|
|
179
|
+
}
|
|
180
|
+
simplified[property] = original[property];
|
|
181
|
+
return simplified;
|
|
182
|
+
}, {});
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
/**
|
|
186
|
+
* Check if clipboard has valid data
|
|
187
|
+
* @return {boolean} - true if valid false if not
|
|
188
|
+
*/
|
|
189
|
+
get isValid() {
|
|
190
|
+
if (this.#Entities.length && this.#basePoint instanceof Point) {
|
|
191
|
+
return true;
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
return false;
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
import { Colours } from './colours.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Colour base class
|
|
5
|
+
* used by layers
|
|
6
|
+
*/
|
|
7
|
+
export class Colour {
|
|
8
|
+
/**
|
|
9
|
+
* Create Colour
|
|
10
|
+
* @param {number} aci
|
|
11
|
+
*/
|
|
12
|
+
constructor(aci = 7) {
|
|
13
|
+
this.aci = aci;
|
|
14
|
+
this.rgb = Colours.aciToRGB(this.aci);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Determine is colour uses dxf true colours
|
|
19
|
+
*/
|
|
20
|
+
get isTrueColour() {
|
|
21
|
+
const aci = Colours.rgbToACI(this.rgb);
|
|
22
|
+
if (aci != undefined) {
|
|
23
|
+
return false;
|
|
24
|
+
}
|
|
25
|
+
return true;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Get the colour
|
|
30
|
+
* @return {number}
|
|
31
|
+
*/
|
|
32
|
+
getColour() {
|
|
33
|
+
return this.rgb;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Set the colour
|
|
38
|
+
* @param {any} colour
|
|
39
|
+
*/
|
|
40
|
+
setColour(colour) {
|
|
41
|
+
if (Colours.isRGB(colour)) {
|
|
42
|
+
this.rgb = colour;
|
|
43
|
+
const aci = Colours.rgbToACI(colour);
|
|
44
|
+
if (aci !== undefined) {
|
|
45
|
+
this.aci = aci;
|
|
46
|
+
} else {
|
|
47
|
+
// fall back to aci 7 when non aci colours are selected
|
|
48
|
+
// e.g. when using truecolour
|
|
49
|
+
this.aci = 7;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Set rgb colour based on autocad colour index
|
|
56
|
+
* @param {number} aci
|
|
57
|
+
*/
|
|
58
|
+
setColourFromACI(aci) {
|
|
59
|
+
// try and get the rgb from the aci
|
|
60
|
+
const rgb = Colours.aciToRGB(aci);
|
|
61
|
+
if (rgb) {
|
|
62
|
+
this.aci = aci;
|
|
63
|
+
this.rgb = rgb;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Entity Colour class
|
|
70
|
+
* used by entities
|
|
71
|
+
* BYBLOCK aci = 0
|
|
72
|
+
* BYLAYER aci = 256
|
|
73
|
+
*/
|
|
74
|
+
export class EntityColour extends Colour {
|
|
75
|
+
/**
|
|
76
|
+
* Create an EntityColour
|
|
77
|
+
* @param {number} aci
|
|
78
|
+
*/
|
|
79
|
+
constructor(aci = 256) {
|
|
80
|
+
super(aci);
|
|
81
|
+
// default to aci 256 - ByLayer
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Determine if colour byLayer
|
|
86
|
+
* @return {boolean}
|
|
87
|
+
*/
|
|
88
|
+
get byLayer() {
|
|
89
|
+
if (this.aci === 256) {
|
|
90
|
+
return true;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
return false;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* Set if colour byLayer
|
|
98
|
+
* @param {boolean} bool
|
|
99
|
+
*/
|
|
100
|
+
set byLayer(bool) {
|
|
101
|
+
if (bool) {
|
|
102
|
+
this.aci = 256;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* Determine if colour byBlock
|
|
108
|
+
* @return {boolean}
|
|
109
|
+
*/
|
|
110
|
+
get byBlock() {
|
|
111
|
+
if (this.aci === 0) {
|
|
112
|
+
return true;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
return false;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* Set if colour byBlock
|
|
120
|
+
* @param {boolean} bool
|
|
121
|
+
*/
|
|
122
|
+
set byBlock(bool) {
|
|
123
|
+
if (bool) {
|
|
124
|
+
this.aci = 0;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* Set the colour
|
|
130
|
+
* @param {any} colour
|
|
131
|
+
*/
|
|
132
|
+
setColour(colour) {
|
|
133
|
+
if (typeof colour === 'string' || colour instanceof String) {
|
|
134
|
+
if (colour.toUpperCase() === 'BYLAYER') {
|
|
135
|
+
this.byLayer = true;
|
|
136
|
+
} else if (colour.toUpperCase() === 'BYBLOCK') {
|
|
137
|
+
this.byBlock = true;
|
|
138
|
+
}
|
|
139
|
+
} else if (Colours.isRGB(colour)) {
|
|
140
|
+
// set the colour on the base class
|
|
141
|
+
super.setColour(colour);
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
}
|