altium-toolkit 1.4.3 → 1.4.4
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/package.json
CHANGED
|
@@ -13,11 +13,13 @@ export class PcbSideResolvedRenderModel {
|
|
|
13
13
|
/**
|
|
14
14
|
* Resolves a normalized PCB model for the requested board side.
|
|
15
15
|
* @param {object | null} board
|
|
16
|
-
* @param {'front' | 'back' | { side?: 'front' | 'back' }} [options]
|
|
16
|
+
* @param {'front' | 'back' | { side?: 'front' | 'back', includeOppositeCopper?: boolean }} [options]
|
|
17
17
|
* @returns {object | null}
|
|
18
18
|
*/
|
|
19
19
|
static resolve(board, options = {}) {
|
|
20
20
|
const side = PcbSideResolvedRenderModel.#normalizeSide(options)
|
|
21
|
+
const includeOppositeCopper =
|
|
22
|
+
PcbSideResolvedRenderModel.#includeOppositeCopper(options)
|
|
21
23
|
const resolved = HistoricalPcbSideResolvedRenderModel.resolve(
|
|
22
24
|
board,
|
|
23
25
|
options
|
|
@@ -52,7 +54,13 @@ export class PcbSideResolvedRenderModel {
|
|
|
52
54
|
boardRegions: PcbSideResolvedRenderModel.#filterPrimitives(
|
|
53
55
|
pcb.boardRegions,
|
|
54
56
|
side
|
|
55
|
-
)
|
|
57
|
+
),
|
|
58
|
+
pads: includeOppositeCopper
|
|
59
|
+
? PcbSideResolvedRenderModel.#prepareContextPads(
|
|
60
|
+
board?.pcb?.pads,
|
|
61
|
+
side
|
|
62
|
+
)
|
|
63
|
+
: pcb.pads
|
|
56
64
|
}
|
|
57
65
|
}
|
|
58
66
|
}
|
|
@@ -68,7 +76,7 @@ export class PcbSideResolvedRenderModel {
|
|
|
68
76
|
|
|
69
77
|
/**
|
|
70
78
|
* Normalizes the caller side option.
|
|
71
|
-
* @param {'front' | 'back' | { side?: 'front' | 'back' }} options
|
|
79
|
+
* @param {'front' | 'back' | { side?: 'front' | 'back', includeOppositeCopper?: boolean }} options
|
|
72
80
|
* @returns {'front' | 'back'}
|
|
73
81
|
*/
|
|
74
82
|
static #normalizeSide(options) {
|
|
@@ -79,6 +87,102 @@ export class PcbSideResolvedRenderModel {
|
|
|
79
87
|
return 'front'
|
|
80
88
|
}
|
|
81
89
|
|
|
90
|
+
/**
|
|
91
|
+
* Checks whether the caller requested opposite-side copper context.
|
|
92
|
+
* @param {'front' | 'back' | { side?: 'front' | 'back', includeOppositeCopper?: boolean }} options
|
|
93
|
+
* @returns {boolean}
|
|
94
|
+
*/
|
|
95
|
+
static #includeOppositeCopper(options) {
|
|
96
|
+
return Boolean(
|
|
97
|
+
options &&
|
|
98
|
+
typeof options === 'object' &&
|
|
99
|
+
options.includeOppositeCopper === true
|
|
100
|
+
)
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* Projects every copper-bearing pad into the requested composite view.
|
|
105
|
+
* @param {readonly object[] | undefined} pads Source pads.
|
|
106
|
+
* @param {'front' | 'back'} side Requested board side.
|
|
107
|
+
* @returns {object[]}
|
|
108
|
+
*/
|
|
109
|
+
static #prepareContextPads(pads, side) {
|
|
110
|
+
return (pads || []).map((pad) =>
|
|
111
|
+
PcbSideResolvedRenderModel.#projectPadForTopRenderer(pad, side)
|
|
112
|
+
)
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* Projects the authored aperture for one pad into the top-oriented
|
|
117
|
+
* renderer while retaining front-only apertures as opposite-side context.
|
|
118
|
+
* @param {object} pad Source pad.
|
|
119
|
+
* @param {'front' | 'back'} side Requested board side.
|
|
120
|
+
* @returns {object}
|
|
121
|
+
*/
|
|
122
|
+
static #projectPadForTopRenderer(pad, side) {
|
|
123
|
+
const layerId = PcbSideResolvedRenderModel.#effectivePadLayerId(pad)
|
|
124
|
+
const apertureSide =
|
|
125
|
+
layerId === 1 ? 'front' : layerId === 32 ? 'back' : side
|
|
126
|
+
if (apertureSide !== 'back') return { ...pad }
|
|
127
|
+
|
|
128
|
+
return {
|
|
129
|
+
...pad,
|
|
130
|
+
sizeTopX: PcbSideResolvedRenderModel.#firstFiniteValue(
|
|
131
|
+
pad.sizeBottomX,
|
|
132
|
+
pad.sizeMidX,
|
|
133
|
+
pad.sizeTopX
|
|
134
|
+
),
|
|
135
|
+
sizeTopY: PcbSideResolvedRenderModel.#firstFiniteValue(
|
|
136
|
+
pad.sizeBottomY,
|
|
137
|
+
pad.sizeMidY,
|
|
138
|
+
pad.sizeTopY
|
|
139
|
+
),
|
|
140
|
+
shapeTop: PcbSideResolvedRenderModel.#firstFiniteValue(
|
|
141
|
+
pad.shapeBottom,
|
|
142
|
+
pad.shapeMid,
|
|
143
|
+
pad.shapeTop
|
|
144
|
+
),
|
|
145
|
+
roundedRectShapeTop: PcbSideResolvedRenderModel.#firstFiniteValue(
|
|
146
|
+
pad.roundedRectShapeBottom,
|
|
147
|
+
pad.roundedRectShapeMid,
|
|
148
|
+
pad.roundedRectShapeTop
|
|
149
|
+
),
|
|
150
|
+
cornerRadiusTop: PcbSideResolvedRenderModel.#firstFiniteValue(
|
|
151
|
+
pad.cornerRadiusBottom,
|
|
152
|
+
pad.cornerRadiusMid,
|
|
153
|
+
pad.cornerRadiusTop
|
|
154
|
+
)
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
/**
|
|
159
|
+
* Resolves the authored Altium layer id for a pad.
|
|
160
|
+
* @param {object | null} pad Pad to inspect.
|
|
161
|
+
* @returns {number | null}
|
|
162
|
+
*/
|
|
163
|
+
static #effectivePadLayerId(pad) {
|
|
164
|
+
const layerId = Number(pad?.layerId)
|
|
165
|
+
if (Number.isInteger(layerId) && layerId > 0) return layerId
|
|
166
|
+
|
|
167
|
+
const legacyLayerId = Number(pad?.legacyLayerId)
|
|
168
|
+
return Number.isInteger(legacyLayerId) && legacyLayerId > 0
|
|
169
|
+
? legacyLayerId
|
|
170
|
+
: null
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
/**
|
|
174
|
+
* Returns the first finite numeric value.
|
|
175
|
+
* @param {...unknown} values Values to inspect.
|
|
176
|
+
* @returns {number | undefined}
|
|
177
|
+
*/
|
|
178
|
+
static #firstFiniteValue(...values) {
|
|
179
|
+
for (const value of values) {
|
|
180
|
+
const number = Number(value)
|
|
181
|
+
if (Number.isFinite(number)) return number
|
|
182
|
+
}
|
|
183
|
+
return undefined
|
|
184
|
+
}
|
|
185
|
+
|
|
82
186
|
/**
|
|
83
187
|
* Filters one primitive collection to the requested surface.
|
|
84
188
|
* @param {readonly object[] | undefined} primitives
|
|
@@ -115,7 +219,7 @@ export class PcbSideResolvedRenderModel {
|
|
|
115
219
|
/**
|
|
116
220
|
* Resolves a normalized PCB model for the requested board side.
|
|
117
221
|
* @param {object | null} board
|
|
118
|
-
* @param {'front' | 'back' | { side?: 'front' | 'back' }} [options]
|
|
222
|
+
* @param {'front' | 'back' | { side?: 'front' | 'back', includeOppositeCopper?: boolean }} [options]
|
|
119
223
|
* @returns {object | null}
|
|
120
224
|
*/
|
|
121
225
|
export function preparePcbSideResolvedRenderModel(board, options = {}) {
|