circuitscript 0.1.0 → 0.1.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/dist/cjs/BaseVisitor.js +13 -8
- package/dist/cjs/antlr/CircuitScriptLexer.js +80 -80
- package/dist/cjs/antlr/CircuitScriptParser.js +599 -657
- package/dist/cjs/builtinMethods.js +27 -8
- package/dist/cjs/draw_symbols.js +320 -197
- package/dist/cjs/execute.js +114 -116
- package/dist/cjs/export.js +2 -4
- package/dist/cjs/geometry.js +52 -19
- package/dist/cjs/globals.js +17 -12
- package/dist/cjs/helpers.js +16 -3
- package/dist/cjs/layout.js +473 -354
- package/dist/cjs/logger.js +8 -1
- package/dist/cjs/objects/ClassComponent.js +22 -22
- package/dist/cjs/objects/ExecutionScope.js +10 -4
- package/dist/cjs/objects/Frame.js +11 -2
- package/dist/cjs/objects/ParamDefinition.js +123 -4
- package/dist/cjs/objects/PinDefinition.js +1 -4
- package/dist/cjs/render.js +76 -138
- package/dist/cjs/sizing.js +33 -7
- package/dist/cjs/utils.js +86 -2
- package/dist/cjs/visitor.js +224 -255
- package/dist/esm/BaseVisitor.mjs +15 -10
- package/dist/esm/antlr/CircuitScriptLexer.mjs +80 -80
- package/dist/esm/antlr/CircuitScriptParser.mjs +599 -657
- package/dist/esm/builtinMethods.mjs +24 -8
- package/dist/esm/draw_symbols.mjs +322 -200
- package/dist/esm/execute.mjs +116 -118
- package/dist/esm/export.mjs +2 -4
- package/dist/esm/geometry.mjs +52 -19
- package/dist/esm/globals.mjs +17 -12
- package/dist/esm/helpers.mjs +17 -4
- package/dist/esm/layout.mjs +479 -360
- package/dist/esm/logger.mjs +8 -1
- package/dist/esm/objects/ClassComponent.mjs +21 -26
- package/dist/esm/objects/ExecutionScope.mjs +10 -4
- package/dist/esm/objects/Frame.mjs +10 -1
- package/dist/esm/objects/ParamDefinition.mjs +122 -3
- package/dist/esm/objects/PinDefinition.mjs +0 -2
- package/dist/esm/render.mjs +79 -141
- package/dist/esm/sizing.mjs +34 -8
- package/dist/esm/utils.mjs +80 -1
- package/dist/esm/visitor.mjs +226 -257
- package/dist/types/BaseVisitor.d.ts +1 -1
- package/dist/types/antlr/CircuitScriptParser.d.ts +2 -3
- package/dist/types/draw_symbols.d.ts +72 -45
- package/dist/types/execute.d.ts +15 -10
- package/dist/types/geometry.d.ts +31 -19
- package/dist/types/globals.d.ts +15 -11
- package/dist/types/helpers.d.ts +2 -1
- package/dist/types/layout.d.ts +35 -54
- package/dist/types/logger.d.ts +1 -1
- package/dist/types/objects/ClassComponent.d.ts +19 -16
- package/dist/types/objects/ExecutionScope.d.ts +3 -2
- package/dist/types/objects/Frame.d.ts +9 -2
- package/dist/types/objects/ParamDefinition.d.ts +32 -2
- package/dist/types/objects/PinDefinition.d.ts +0 -2
- package/dist/types/render.d.ts +2 -1
- package/dist/types/utils.d.ts +14 -1
- package/dist/types/visitor.d.ts +4 -5
- package/libs/lib.cst +25 -8
- package/package.json +7 -3
package/dist/esm/execute.mjs
CHANGED
|
@@ -1,12 +1,15 @@
|
|
|
1
|
-
import { BlockTypes, ComponentTypes, GlobalNames, NoNetText, ParamKeys, ReferenceTypes } from './globals.mjs';
|
|
2
|
-
import { ClassComponent } from './objects/ClassComponent.mjs';
|
|
1
|
+
import { BlockTypes, ComponentTypes, GlobalNames, NoNetText, ParamKeys, ReferenceTypes, SymbolPinSide } from './globals.mjs';
|
|
2
|
+
import { ClassComponent, ModuleComponent } from './objects/ClassComponent.mjs';
|
|
3
3
|
import { ActiveObject, ExecutionScope, FrameAction, SequenceAction } from './objects/ExecutionScope.mjs';
|
|
4
4
|
import { Net } from './objects/Net.mjs';
|
|
5
|
+
import { numeric } from './objects/ParamDefinition.mjs';
|
|
5
6
|
import { PortSide } from './objects/PinDefinition.mjs';
|
|
6
7
|
import { DeclaredReference, Direction } from './objects/types.mjs';
|
|
7
8
|
import { Wire } from './objects/Wire.mjs';
|
|
8
9
|
import { Frame } from './objects/Frame.mjs';
|
|
9
10
|
import { CalculatePinPositions } from './layout.mjs';
|
|
11
|
+
import { UnitDimension } from './helpers.mjs';
|
|
12
|
+
import { PlaceHolderCommands, SymbolDrawingCommands } from './draw_symbols.mjs';
|
|
10
13
|
export class ExecutionContext {
|
|
11
14
|
name;
|
|
12
15
|
namespace;
|
|
@@ -55,28 +58,15 @@ export class ExecutionContext {
|
|
|
55
58
|
console.log.apply(null, args);
|
|
56
59
|
}
|
|
57
60
|
setupRoot() {
|
|
58
|
-
const componentRoot = ClassComponent.simple(GlobalNames.__root, 1
|
|
59
|
-
componentRoot.typeProp = ComponentTypes.
|
|
60
|
-
componentRoot.displayProp =
|
|
61
|
+
const componentRoot = ClassComponent.simple(GlobalNames.__root, 1);
|
|
62
|
+
componentRoot.typeProp = ComponentTypes.net;
|
|
63
|
+
componentRoot.displayProp = this.getPointSymbol();
|
|
61
64
|
this.scope.instances.set(GlobalNames.__root, componentRoot);
|
|
62
|
-
this.scope.
|
|
63
|
-
this.scope.currentPin = componentRoot.getDefaultPin();
|
|
65
|
+
this.scope.setCurrent(componentRoot);
|
|
64
66
|
this.scope.componentRoot = componentRoot;
|
|
65
67
|
}
|
|
66
|
-
getUniqueInstanceName(
|
|
67
|
-
|
|
68
|
-
switch (className) {
|
|
69
|
-
case GlobalNames.DefaultResistor:
|
|
70
|
-
extraPrefix = 'R_';
|
|
71
|
-
break;
|
|
72
|
-
case GlobalNames.DefaultCapacitor:
|
|
73
|
-
extraPrefix = 'C_';
|
|
74
|
-
break;
|
|
75
|
-
case GlobalNames.DefaultInductor:
|
|
76
|
-
extraPrefix = 'L_';
|
|
77
|
-
break;
|
|
78
|
-
}
|
|
79
|
-
const tmpName = extraPrefix + 'COMP_' + this.scope.unnamedCounter;
|
|
68
|
+
getUniqueInstanceName() {
|
|
69
|
+
const tmpName = 'COMP_' + this.scope.unnamedCounter;
|
|
80
70
|
this.scope.unnamedCounter += 1;
|
|
81
71
|
return tmpName;
|
|
82
72
|
}
|
|
@@ -89,14 +79,8 @@ export class ExecutionContext {
|
|
|
89
79
|
return [this.scope.currentComponent, this.scope.currentPin];
|
|
90
80
|
}
|
|
91
81
|
linkComponentPinNet(component1, component1Pin, component2, component2Pin) {
|
|
92
|
-
const
|
|
93
|
-
const
|
|
94
|
-
const net1 = net1_exists
|
|
95
|
-
? this.scope.getNet(component1, component1Pin)
|
|
96
|
-
: null;
|
|
97
|
-
const net2 = net2_exists
|
|
98
|
-
? this.scope.getNet(component2, component2Pin)
|
|
99
|
-
: null;
|
|
82
|
+
const net1 = this.scope.getNet(component1, component1Pin);
|
|
83
|
+
const net2 = this.scope.getNet(component2, component2Pin);
|
|
100
84
|
this.log('link nets', component1, component1Pin, net1, 'to', component2, component2Pin, net2);
|
|
101
85
|
let returnNet;
|
|
102
86
|
if (net1 === null && net2 === null) {
|
|
@@ -118,43 +102,43 @@ export class ExecutionContext {
|
|
|
118
102
|
returnNet = this.mergeNets(net1, net2);
|
|
119
103
|
}
|
|
120
104
|
else {
|
|
121
|
-
|
|
105
|
+
returnNet = net1;
|
|
122
106
|
}
|
|
123
107
|
}
|
|
108
|
+
this.log('final net after link: ', returnNet);
|
|
124
109
|
return returnNet;
|
|
125
110
|
}
|
|
126
111
|
mergeNets(net1, net2) {
|
|
127
112
|
if (net1 === net2) {
|
|
128
113
|
return net1;
|
|
129
114
|
}
|
|
130
|
-
let tmpNet;
|
|
131
115
|
if (net2.priority > net1.priority) {
|
|
132
|
-
tmpNet = net1;
|
|
116
|
+
const tmpNet = net1;
|
|
133
117
|
net1 = net2;
|
|
134
118
|
net2 = tmpNet;
|
|
135
119
|
}
|
|
136
|
-
|
|
137
|
-
scopeNets.forEach(([component, pin, net]) => {
|
|
120
|
+
this.scope.getNets().forEach(([component, pin, net]) => {
|
|
138
121
|
if (Net.isSame(net, net2)) {
|
|
139
122
|
this.scope.setNet(component, pin, net1);
|
|
140
123
|
}
|
|
141
124
|
});
|
|
142
125
|
return net1;
|
|
143
126
|
}
|
|
144
|
-
createComponent(instanceName, pins, params, props) {
|
|
145
|
-
const
|
|
146
|
-
const component = new
|
|
127
|
+
createComponent(instanceName, pins, params, props, isModule = false) {
|
|
128
|
+
const className = isModule ? ModuleComponent : ClassComponent;
|
|
129
|
+
const component = new className(instanceName, pins.length);
|
|
147
130
|
pins.forEach((pin) => {
|
|
148
131
|
component.pins.set(pin.id, pin);
|
|
149
132
|
});
|
|
150
133
|
component.arrangeProps = props.arrange ?? null;
|
|
151
134
|
component.displayProp = props.display ?? null;
|
|
152
135
|
component.widthProp = props.width ?? null;
|
|
136
|
+
component.heightProp = props.height ?? null;
|
|
153
137
|
component.typeProp = props.type ?? null;
|
|
154
138
|
component.copyProp = props.copy ?? false;
|
|
155
139
|
let useAngle = null;
|
|
156
140
|
if (props.angle) {
|
|
157
|
-
useAngle = props.angle % 360;
|
|
141
|
+
useAngle = props.angle.toNumber() % 360;
|
|
158
142
|
if (useAngle < 0) {
|
|
159
143
|
useAngle += 360;
|
|
160
144
|
}
|
|
@@ -166,10 +150,12 @@ export class ExecutionContext {
|
|
|
166
150
|
component.parameters.set(param.paramName, param.paramValue);
|
|
167
151
|
paramsMap.set(param.paramName, param.paramValue);
|
|
168
152
|
});
|
|
169
|
-
if (component.typeProp === ComponentTypes.net
|
|
170
|
-
|| component.typeProp === ComponentTypes.label) {
|
|
153
|
+
if (component.typeProp === ComponentTypes.net) {
|
|
171
154
|
const netName = paramsMap.get(ParamKeys.net_name);
|
|
172
|
-
|
|
155
|
+
let priority = 0;
|
|
156
|
+
if (paramsMap.has(ParamKeys.priority)) {
|
|
157
|
+
priority = paramsMap.get(ParamKeys.priority).toNumber();
|
|
158
|
+
}
|
|
173
159
|
const result = this.resolveNet(netName, this.netNamespace);
|
|
174
160
|
let tmpNet;
|
|
175
161
|
if (result.found) {
|
|
@@ -183,8 +169,9 @@ export class ExecutionContext {
|
|
|
183
169
|
this.scope.setNet(component, 1, tmpNet);
|
|
184
170
|
this.log('set net', netName, 'component', component);
|
|
185
171
|
}
|
|
186
|
-
const
|
|
187
|
-
|
|
172
|
+
const { pins: pinSides, maxPositions } = getPortSide(component.pins, component.arrangeProps);
|
|
173
|
+
component.pinsMaxPositions = maxPositions;
|
|
174
|
+
pinSides.forEach(({ pinId, side, position }) => {
|
|
188
175
|
if (component.pins.has(pinId)) {
|
|
189
176
|
const tmpPin = component.pins.get(pinId);
|
|
190
177
|
tmpPin.side = side;
|
|
@@ -215,10 +202,9 @@ export class ExecutionContext {
|
|
|
215
202
|
this.scope.currentPin + ' ' + netString);
|
|
216
203
|
}
|
|
217
204
|
addComponentExisting(component, pin) {
|
|
218
|
-
const
|
|
219
|
-
const nextPin = component.getNextPinAfter(startPin);
|
|
205
|
+
const nextPin = component.getNextPinAfter(pin);
|
|
220
206
|
this.applyComponentAngleFromWire(component, pin);
|
|
221
|
-
this.toComponent(component,
|
|
207
|
+
this.toComponent(component, pin, { addSequence: true });
|
|
222
208
|
this.log('move to next pin: ' + nextPin);
|
|
223
209
|
this.atComponent(component, nextPin, {
|
|
224
210
|
addSequence: true
|
|
@@ -254,13 +240,10 @@ export class ExecutionContext {
|
|
|
254
240
|
}
|
|
255
241
|
const linkedNet = this.linkComponentPinNet(this.scope.currentComponent, this.scope.currentPin, component, pinId);
|
|
256
242
|
this.applyComponentAngleFromWire(component, pinId);
|
|
257
|
-
this.scope.
|
|
258
|
-
this.scope.currentPin = pinId;
|
|
243
|
+
this.scope.setCurrent(component, pinId);
|
|
259
244
|
this.scope.clearActive();
|
|
260
245
|
if (addSequence) {
|
|
261
246
|
if (this.scope.sequence.length > 0) {
|
|
262
|
-
if (component.pinWires.has(pinId) && component.typeProp !== ComponentTypes.point) {
|
|
263
|
-
}
|
|
264
247
|
const [entryType, , segments] = this.scope.sequence[this.scope.sequence.length - 1];
|
|
265
248
|
if (entryType === SequenceAction.Wire && isWireSegmentsEndAuto(segments)) {
|
|
266
249
|
segments[segments.length - 1].until = [
|
|
@@ -278,7 +261,6 @@ export class ExecutionContext {
|
|
|
278
261
|
atComponent(component, pinId, options) {
|
|
279
262
|
this.log('at component');
|
|
280
263
|
const { addSequence = false } = options ?? {};
|
|
281
|
-
this.scope.currentComponent = component;
|
|
282
264
|
let usePinId;
|
|
283
265
|
if (pinId === null) {
|
|
284
266
|
usePinId = component.getDefaultPin();
|
|
@@ -291,9 +273,7 @@ export class ExecutionContext {
|
|
|
291
273
|
throw 'Invalid pin number ' + pinId + ' in ' + component;
|
|
292
274
|
}
|
|
293
275
|
}
|
|
294
|
-
|
|
295
|
-
this.scope.currentPin = usePinId;
|
|
296
|
-
}
|
|
276
|
+
this.scope.setCurrent(component, usePinId);
|
|
297
277
|
this.scope.clearActive();
|
|
298
278
|
if (addSequence) {
|
|
299
279
|
this.scope.sequence.push([SequenceAction.At,
|
|
@@ -320,12 +300,9 @@ export class ExecutionContext {
|
|
|
320
300
|
return componentCopy;
|
|
321
301
|
}
|
|
322
302
|
enterBlocks(blockType) {
|
|
323
|
-
if (blockType === BlockTypes.Point) {
|
|
324
|
-
|
|
325
|
-
this.tmpPointId
|
|
326
|
-
}
|
|
327
|
-
else if (blockType === BlockTypes.Parallel) {
|
|
328
|
-
this.addPoint(`_parallel.${this.name}.${this.tmpPointId}`, false);
|
|
303
|
+
if (blockType === BlockTypes.Point || blockType === BlockTypes.Parallel) {
|
|
304
|
+
const key = blockType === BlockTypes.Point ? 'point' : 'parallel';
|
|
305
|
+
this.addPoint(`_${key}.${this.name}.${this.tmpPointId}`, false);
|
|
329
306
|
this.tmpPointId += 1;
|
|
330
307
|
}
|
|
331
308
|
this.scope.blockStack.set(this.scope.indentLevel, {
|
|
@@ -346,8 +323,7 @@ export class ExecutionContext {
|
|
|
346
323
|
if (blockType === BlockTypes.Join || blockType === BlockTypes.Parallel) {
|
|
347
324
|
const { final_point: finalPoint } = stackRef;
|
|
348
325
|
const [component, pin, wireId] = finalPoint;
|
|
349
|
-
this.scope.
|
|
350
|
-
this.scope.currentPin = pin;
|
|
326
|
+
this.scope.setCurrent(component, pin);
|
|
351
327
|
this.scope.currentWireId = wireId;
|
|
352
328
|
if (wireId !== -1) {
|
|
353
329
|
this.scope.sequence.push([
|
|
@@ -370,8 +346,7 @@ export class ExecutionContext {
|
|
|
370
346
|
ignore_last_net: false,
|
|
371
347
|
});
|
|
372
348
|
if (blockType === BlockTypes.Join || blockType === BlockTypes.Point) {
|
|
373
|
-
this.scope.
|
|
374
|
-
this.scope.currentPin = null;
|
|
349
|
+
this.scope.setCurrent(null);
|
|
375
350
|
this.scope.currentWireId = -1;
|
|
376
351
|
}
|
|
377
352
|
else if (blockType === BlockTypes.Parallel) {
|
|
@@ -588,7 +563,6 @@ export class ExecutionContext {
|
|
|
588
563
|
}
|
|
589
564
|
const wireIdOffset = this.scope.wires.length;
|
|
590
565
|
const frameIdOffset = this.scope.frames.length;
|
|
591
|
-
let incrementGndLinkId = 0;
|
|
592
566
|
childScope.sequence.forEach(sequenceAction => {
|
|
593
567
|
const [action] = sequenceAction;
|
|
594
568
|
if (action === SequenceAction.Wire) {
|
|
@@ -601,20 +575,6 @@ export class ExecutionContext {
|
|
|
601
575
|
this.scope.sequence.push([SequenceAction.WireJump, jumpWireId, 1]);
|
|
602
576
|
}
|
|
603
577
|
else if (action === SequenceAction.At || action === SequenceAction.To) {
|
|
604
|
-
const tmpComponent = sequenceAction[1];
|
|
605
|
-
if (tmpComponent.typeProp === ComponentTypes.net
|
|
606
|
-
&& tmpComponent.parameters.get(ParamKeys.net_name) === 'gnd') {
|
|
607
|
-
tmpComponent._copyID = gndCopyIdOffset + incrementGndLinkId;
|
|
608
|
-
incrementGndLinkId += 1;
|
|
609
|
-
}
|
|
610
|
-
else if (tmpComponent === tmpRoot) {
|
|
611
|
-
if (currentWireId !== -1) {
|
|
612
|
-
sequenceAction = [SequenceAction.WireJump, currentWireId];
|
|
613
|
-
}
|
|
614
|
-
else {
|
|
615
|
-
sequenceAction = [action, currentComponent, currentPin];
|
|
616
|
-
}
|
|
617
|
-
}
|
|
618
578
|
this.scope.sequence.push(sequenceAction);
|
|
619
579
|
}
|
|
620
580
|
else if (action === SequenceAction.Frame) {
|
|
@@ -628,13 +588,11 @@ export class ExecutionContext {
|
|
|
628
588
|
}
|
|
629
589
|
});
|
|
630
590
|
if (childScope.currentComponent === childScope.componentRoot) {
|
|
631
|
-
this.scope.currentComponent
|
|
632
|
-
this.scope.currentPin = currentPin;
|
|
591
|
+
this.scope.setCurrent(currentComponent, currentPin);
|
|
633
592
|
this.scope.currentWireId = currentWireId;
|
|
634
593
|
}
|
|
635
594
|
else {
|
|
636
|
-
this.scope.currentComponent
|
|
637
|
-
this.scope.currentPin = childScope.currentPin;
|
|
595
|
+
this.scope.setCurrent(childScope.currentComponent, childScope.currentPin);
|
|
638
596
|
this.scope.currentWireId = childScope.currentWireId + wireIdOffset;
|
|
639
597
|
}
|
|
640
598
|
this.printPoint('resume at');
|
|
@@ -664,7 +622,15 @@ export class ExecutionContext {
|
|
|
664
622
|
this.scope.wires.push(new Wire(tmp));
|
|
665
623
|
const output = [];
|
|
666
624
|
segments.forEach(item => {
|
|
667
|
-
|
|
625
|
+
const tmpArray = item.map(item2 => {
|
|
626
|
+
if (item2 instanceof UnitDimension) {
|
|
627
|
+
return item2.value;
|
|
628
|
+
}
|
|
629
|
+
else {
|
|
630
|
+
return item2;
|
|
631
|
+
}
|
|
632
|
+
});
|
|
633
|
+
output.push(tmpArray.join(","));
|
|
668
634
|
});
|
|
669
635
|
this.log('add wire: ', output.join("|"));
|
|
670
636
|
this.scope.setActive(ActiveObject.Wire, wireId);
|
|
@@ -681,12 +647,26 @@ export class ExecutionContext {
|
|
|
681
647
|
}
|
|
682
648
|
const useName = userDefined ? 'point.' + pointId : pointId;
|
|
683
649
|
const componentPoint = ClassComponent.simple(useName, 1, "point");
|
|
684
|
-
componentPoint.displayProp =
|
|
685
|
-
componentPoint.typeProp = ComponentTypes.
|
|
650
|
+
componentPoint.displayProp = this.getPointSymbol();
|
|
651
|
+
componentPoint.typeProp = ComponentTypes.net;
|
|
686
652
|
this.scope.instances.set(pointId, componentPoint);
|
|
687
653
|
this.toComponent(componentPoint, 1, { addSequence: true });
|
|
688
654
|
return this.getCurrentPoint();
|
|
689
655
|
}
|
|
656
|
+
getPointSymbol() {
|
|
657
|
+
return new SymbolDrawingCommands(() => {
|
|
658
|
+
return [
|
|
659
|
+
[PlaceHolderCommands.pin,
|
|
660
|
+
[numeric(1), numeric(0), numeric(0),
|
|
661
|
+
numeric(0), numeric(0)],
|
|
662
|
+
new Map([
|
|
663
|
+
["display_pin_id", false]
|
|
664
|
+
]),
|
|
665
|
+
null
|
|
666
|
+
]
|
|
667
|
+
];
|
|
668
|
+
});
|
|
669
|
+
}
|
|
690
670
|
setProperty(nameWithProp, value) {
|
|
691
671
|
this.log('set property', nameWithProp, 'value', value);
|
|
692
672
|
let idName;
|
|
@@ -719,11 +699,6 @@ export class ExecutionContext {
|
|
|
719
699
|
}
|
|
720
700
|
}
|
|
721
701
|
}
|
|
722
|
-
setCurrentComponentStyle(styles) {
|
|
723
|
-
for (const key in styles) {
|
|
724
|
-
this.scope.currentComponent.styles[key] = styles[key];
|
|
725
|
-
}
|
|
726
|
-
}
|
|
727
702
|
applyComponentAngleFromWire(component, pin, opposite = false) {
|
|
728
703
|
if (this.componentAngleFollowsWire
|
|
729
704
|
&& component.followWireOrientationProp
|
|
@@ -774,23 +749,23 @@ export class ExecutionContext {
|
|
|
774
749
|
return;
|
|
775
750
|
}
|
|
776
751
|
this.log('set component angle from wire, target angle:', targetAngle, ', component angle:', component.angleProp, 'pin angle:', connectedPinPos.angle);
|
|
777
|
-
let useAngle = (targetAngle - connectedPinPos.angle) % 360;
|
|
752
|
+
let useAngle = (targetAngle - connectedPinPos.angle.toNumber()) % 360;
|
|
778
753
|
if (useAngle < 0) {
|
|
779
754
|
useAngle += 360;
|
|
780
755
|
}
|
|
781
756
|
if (useAngle === 90) {
|
|
782
|
-
component.setParam(
|
|
757
|
+
component.setParam(ParamKeys.angle, numeric(90));
|
|
783
758
|
}
|
|
784
759
|
else if (useAngle === 180) {
|
|
785
760
|
if (component.angleProp === 0 || component.angleProp === 180) {
|
|
786
|
-
component.setParam(
|
|
761
|
+
component.setParam(ParamKeys.flipX, 1);
|
|
787
762
|
}
|
|
788
763
|
else if (component.angleProp === 90 || component.angleProp === 270) {
|
|
789
|
-
component.setParam(
|
|
764
|
+
component.setParam(ParamKeys.flipY, 1);
|
|
790
765
|
}
|
|
791
766
|
}
|
|
792
767
|
else if (useAngle === 270) {
|
|
793
|
-
component.setParam(
|
|
768
|
+
component.setParam(ParamKeys.angle, numeric(270));
|
|
794
769
|
}
|
|
795
770
|
component.wireOrientationAngle = useAngle;
|
|
796
771
|
component.didSetWireOrientationAngle = true;
|
|
@@ -825,6 +800,12 @@ function isWireSegmentsEndAuto(segments) {
|
|
|
825
800
|
}
|
|
826
801
|
export function getPortSide(pins, arrangeProps) {
|
|
827
802
|
const result = [];
|
|
803
|
+
const maxPositions = {
|
|
804
|
+
[SymbolPinSide.Left]: 0,
|
|
805
|
+
[SymbolPinSide.Right]: 0,
|
|
806
|
+
[SymbolPinSide.Top]: 0,
|
|
807
|
+
[SymbolPinSide.Bottom]: 0,
|
|
808
|
+
};
|
|
828
809
|
if (arrangeProps === null) {
|
|
829
810
|
let counter = 0;
|
|
830
811
|
for (const [pinId] of pins) {
|
|
@@ -836,6 +817,14 @@ export function getPortSide(pins, arrangeProps) {
|
|
|
836
817
|
});
|
|
837
818
|
counter++;
|
|
838
819
|
}
|
|
820
|
+
const leftSideItems = result.filter(item => {
|
|
821
|
+
return item.side === PortSide.WEST;
|
|
822
|
+
});
|
|
823
|
+
const rightSideItems = result.filter(item => {
|
|
824
|
+
return item.side === PortSide.EAST;
|
|
825
|
+
});
|
|
826
|
+
maxPositions[SymbolPinSide.Left] = leftSideItems.length;
|
|
827
|
+
maxPositions[SymbolPinSide.Right] = rightSideItems.length;
|
|
839
828
|
}
|
|
840
829
|
else {
|
|
841
830
|
let counter = pins.size;
|
|
@@ -849,35 +838,44 @@ export function getPortSide(pins, arrangeProps) {
|
|
|
849
838
|
useItems = [...items];
|
|
850
839
|
}
|
|
851
840
|
let useSide = PortSide.WEST;
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
841
|
+
switch (key) {
|
|
842
|
+
case SymbolPinSide.Left:
|
|
843
|
+
useSide = PortSide.WEST;
|
|
844
|
+
break;
|
|
845
|
+
case SymbolPinSide.Right:
|
|
846
|
+
useSide = PortSide.EAST;
|
|
847
|
+
break;
|
|
848
|
+
case SymbolPinSide.Top:
|
|
849
|
+
useSide = PortSide.NORTH;
|
|
850
|
+
break;
|
|
851
|
+
case SymbolPinSide.Bottom:
|
|
852
|
+
useSide = PortSide.SOUTH;
|
|
853
|
+
break;
|
|
863
854
|
}
|
|
864
855
|
let position = 0;
|
|
865
856
|
useItems.forEach(item => {
|
|
866
857
|
if (typeof item === 'object' && Array.isArray(item)) {
|
|
867
|
-
position += item[0];
|
|
858
|
+
position += item[0].toNumber();
|
|
868
859
|
}
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
860
|
+
else {
|
|
861
|
+
const itemValue = item.toNumber();
|
|
862
|
+
if (existingPinIds.indexOf(itemValue) !== -1) {
|
|
863
|
+
result.push({
|
|
864
|
+
pinId: itemValue,
|
|
865
|
+
side: useSide,
|
|
866
|
+
position,
|
|
867
|
+
order: counter
|
|
868
|
+
});
|
|
869
|
+
counter--;
|
|
870
|
+
position += 1;
|
|
871
|
+
}
|
|
878
872
|
}
|
|
879
873
|
});
|
|
874
|
+
maxPositions[key] = position;
|
|
880
875
|
}
|
|
881
876
|
}
|
|
882
|
-
return
|
|
877
|
+
return {
|
|
878
|
+
pins: result,
|
|
879
|
+
maxPositions,
|
|
880
|
+
};
|
|
883
881
|
}
|
package/dist/esm/export.mjs
CHANGED
|
@@ -47,10 +47,8 @@ export function generateKiCADNetList(netlist) {
|
|
|
47
47
|
}
|
|
48
48
|
}
|
|
49
49
|
else {
|
|
50
|
-
if (instance.typeProp !== ComponentTypes.
|
|
51
|
-
instance.typeProp !== ComponentTypes.
|
|
52
|
-
instance.typeProp !== ComponentTypes.point &&
|
|
53
|
-
instance.typeProp !== ComponentTypes.frame &&
|
|
50
|
+
if (instance.typeProp !== ComponentTypes.net &&
|
|
51
|
+
instance.typeProp !== ComponentTypes.graphic &&
|
|
54
52
|
instance.typeProp !== null) {
|
|
55
53
|
console.log('Skipping', instance.instanceName);
|
|
56
54
|
}
|
package/dist/esm/geometry.mjs
CHANGED
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
import Flatten from '@flatten-js/core';
|
|
2
2
|
import { measureTextSize2 } from './sizing.mjs';
|
|
3
3
|
import { defaultFont, fontDisplayScale, PortArrowSize, PortPaddingHorizontal, PortPaddingVertical } from './globals.mjs';
|
|
4
|
-
import { NumericValue } from './objects/ParamDefinition.mjs';
|
|
4
|
+
import { numeric, NumericValue } from './objects/ParamDefinition.mjs';
|
|
5
5
|
import { AllPinTypes, PinTypes } from './objects/PinTypes.mjs';
|
|
6
6
|
import { roundValue } from './utils.mjs';
|
|
7
7
|
export class Textbox extends Flatten.Polygon {
|
|
8
8
|
id;
|
|
9
9
|
text;
|
|
10
|
-
anchorPoint = [
|
|
10
|
+
anchorPoint = [
|
|
11
|
+
numeric(0), numeric(0)
|
|
12
|
+
];
|
|
11
13
|
boundingBox = { width: -1, height: -1 };
|
|
12
14
|
polygon;
|
|
13
15
|
font = 'default';
|
|
@@ -43,8 +45,8 @@ export class Textbox extends Flatten.Polygon {
|
|
|
43
45
|
else {
|
|
44
46
|
throw 'Invalid string passed into textbox';
|
|
45
47
|
}
|
|
46
|
-
const { fontSize =
|
|
47
|
-
const {
|
|
48
|
+
const { fontSize = numeric(50), anchor = HorizontalAlign.Left, vanchor = VerticalAlign.Bottom, fontWeight = 'regular', portType = null, } = style ?? {};
|
|
49
|
+
const { box } = measureTextSize2(useText, defaultFont, fontSize.mul(fontDisplayScale).toNumber(), fontWeight, anchor, vanchor);
|
|
48
50
|
let polygonCoords = [];
|
|
49
51
|
let anchorOffsetX = 0;
|
|
50
52
|
let anchorOffsetY = 0;
|
|
@@ -103,20 +105,31 @@ export class Textbox extends Flatten.Polygon {
|
|
|
103
105
|
anchorOffsetY += paddingVert / 2;
|
|
104
106
|
}
|
|
105
107
|
const polygon = new Flatten.Polygon(polygonCoords);
|
|
106
|
-
return new Textbox(id, useText, [x
|
|
108
|
+
return new Textbox(id, useText, [x.add(anchorOffsetX), y.add(anchorOffsetY)], polygon, style, box, label);
|
|
107
109
|
}
|
|
108
110
|
rotate(angle, origin) {
|
|
109
111
|
const feature = super.rotate(angle, origin);
|
|
110
112
|
const newAnchorPoint = this.transformAnchorPoint(segment => segment.rotate(angle, origin));
|
|
111
|
-
|
|
113
|
+
const tmpAnchorPoint = [
|
|
114
|
+
numeric(newAnchorPoint[0]),
|
|
115
|
+
numeric(newAnchorPoint[1])
|
|
116
|
+
];
|
|
117
|
+
return new Textbox(this.id, this.text, tmpAnchorPoint, feature, this.style, this.textMeasurementBounds, this.label);
|
|
112
118
|
}
|
|
113
119
|
transform(matrix) {
|
|
114
120
|
const feature = super.transform(matrix);
|
|
115
121
|
const newAnchorPoint = this.transformAnchorPoint(segment => segment.transform(matrix));
|
|
116
|
-
|
|
122
|
+
const tmpAnchorPoint = [
|
|
123
|
+
numeric(newAnchorPoint[0]),
|
|
124
|
+
numeric(newAnchorPoint[1])
|
|
125
|
+
];
|
|
126
|
+
return new Textbox(this.id, this.text, tmpAnchorPoint, feature, this.style, this.textMeasurementBounds, this.label);
|
|
117
127
|
}
|
|
118
128
|
transformAnchorPoint(callback) {
|
|
119
|
-
const anchorPointSegment = new Flatten.Segment(new Flatten.Point(0, 0), new Flatten.Point(
|
|
129
|
+
const anchorPointSegment = new Flatten.Segment(new Flatten.Point(0, 0), new Flatten.Point([
|
|
130
|
+
this.anchorPoint[0].toNumber(),
|
|
131
|
+
this.anchorPoint[1].toNumber(),
|
|
132
|
+
]));
|
|
120
133
|
const newSegment = callback(anchorPointSegment);
|
|
121
134
|
const lastPoint = newSegment.vertices[newSegment.vertices.length - 1];
|
|
122
135
|
return [
|
|
@@ -137,7 +150,7 @@ export class GeometryProp {
|
|
|
137
150
|
}
|
|
138
151
|
export class Geometry {
|
|
139
152
|
static point(x, y) {
|
|
140
|
-
return new Flatten.Point(x, y);
|
|
153
|
+
return new Flatten.Point(x.toNumber(), y.toNumber());
|
|
141
154
|
}
|
|
142
155
|
static line(x1, y1, x2, y2) {
|
|
143
156
|
return new Flatten.Line(Geometry.point(x1, y1), Geometry.point(x2, y2));
|
|
@@ -152,7 +165,12 @@ export class Geometry {
|
|
|
152
165
|
return new Flatten.Segment(Geometry.point(start[0], start[1]), Geometry.point(end[0], end[1]));
|
|
153
166
|
}
|
|
154
167
|
static polygon(coords) {
|
|
155
|
-
return new Flatten.Polygon(coords
|
|
168
|
+
return new Flatten.Polygon(coords.map(item => {
|
|
169
|
+
return [
|
|
170
|
+
item[0].toNumber(),
|
|
171
|
+
item[1].toNumber(),
|
|
172
|
+
];
|
|
173
|
+
}));
|
|
156
174
|
}
|
|
157
175
|
static multiline(coords) {
|
|
158
176
|
const segments = [];
|
|
@@ -162,11 +180,13 @@ export class Geometry {
|
|
|
162
180
|
return new Flatten.Multiline(segments);
|
|
163
181
|
}
|
|
164
182
|
static arc(center, radius, startAngle, endAngle, sweepDirection) {
|
|
165
|
-
return new Flatten.Arc(Geometry.point(center[0], center[1]), radius, startAngle, endAngle, sweepDirection);
|
|
183
|
+
return new Flatten.Arc(Geometry.point(center[0], center[1]), radius.toNumber(), startAngle.toNumber(), endAngle.toNumber(), sweepDirection);
|
|
166
184
|
}
|
|
167
185
|
static getCoords(item) {
|
|
168
186
|
const points = item.vertices.map(vertex => {
|
|
169
|
-
return [
|
|
187
|
+
return [
|
|
188
|
+
numeric(vertex.x), numeric(vertex.y)
|
|
189
|
+
];
|
|
170
190
|
});
|
|
171
191
|
return points;
|
|
172
192
|
}
|
|
@@ -213,10 +233,10 @@ export class Geometry {
|
|
|
213
233
|
if (feature instanceof Textbox) {
|
|
214
234
|
const [x, y] = feature.anchorPoint;
|
|
215
235
|
box = {
|
|
216
|
-
xmin: box.xmin + x,
|
|
217
|
-
ymin: box.ymin + y,
|
|
218
|
-
xmax: box.xmax + x,
|
|
219
|
-
ymax: box.ymax + y
|
|
236
|
+
xmin: box.xmin + x.toNumber(),
|
|
237
|
+
ymin: box.ymin + y.toNumber(),
|
|
238
|
+
xmax: box.xmax + x.toNumber(),
|
|
239
|
+
ymax: box.ymax + y.toNumber()
|
|
220
240
|
};
|
|
221
241
|
}
|
|
222
242
|
if (box.xmin === undefined) {
|
|
@@ -274,7 +294,7 @@ export class Geometry {
|
|
|
274
294
|
for (let i = 0; i < coords.length; i++) {
|
|
275
295
|
const [x, y] = coords[i];
|
|
276
296
|
const command = (i === 0) ? 'M' : 'L';
|
|
277
|
-
path.push(`${command}`, x, y);
|
|
297
|
+
path.push(`${command}`, x.toNumber(), y.toNumber());
|
|
278
298
|
}
|
|
279
299
|
if (isClosedPolygon) {
|
|
280
300
|
path.push('Z');
|
|
@@ -307,8 +327,8 @@ export class Geometry {
|
|
|
307
327
|
const existingSegments = [];
|
|
308
328
|
wirePoints.forEach(points => {
|
|
309
329
|
const tmpPoints = points.map(pt => {
|
|
310
|
-
const roundedX = roundValue(pt.x);
|
|
311
|
-
const roundedY = roundValue(pt.y);
|
|
330
|
+
const roundedX = roundValue(pt.x).toNumber();
|
|
331
|
+
const roundedY = roundValue(pt.y).toNumber();
|
|
312
332
|
return new Flatten.Point(roundedX, roundedY);
|
|
313
333
|
});
|
|
314
334
|
for (let i = 0; i < tmpPoints.length - 1; i++) {
|
|
@@ -519,6 +539,19 @@ export var VerticalAlign;
|
|
|
519
539
|
VerticalAlign["Middle"] = "middle";
|
|
520
540
|
VerticalAlign["Bottom"] = "bottom";
|
|
521
541
|
})(VerticalAlign || (VerticalAlign = {}));
|
|
542
|
+
export var HorizontalAlignProp;
|
|
543
|
+
(function (HorizontalAlignProp) {
|
|
544
|
+
HorizontalAlignProp["Start"] = "start";
|
|
545
|
+
HorizontalAlignProp["Middle"] = "middle";
|
|
546
|
+
HorizontalAlignProp["End"] = "end";
|
|
547
|
+
})(HorizontalAlignProp || (HorizontalAlignProp = {}));
|
|
548
|
+
export var VerticalAlignProp;
|
|
549
|
+
(function (VerticalAlignProp) {
|
|
550
|
+
VerticalAlignProp["Hanging"] = "hanging";
|
|
551
|
+
VerticalAlignProp["Middle"] = "middle";
|
|
552
|
+
VerticalAlignProp["Central"] = "central";
|
|
553
|
+
VerticalAlignProp["TextTop"] = "text-top";
|
|
554
|
+
})(VerticalAlignProp || (VerticalAlignProp = {}));
|
|
522
555
|
function getArcPointRadians(centerX, centerY, radius, angleRads) {
|
|
523
556
|
const dx = Math.cos(angleRads);
|
|
524
557
|
const dy = Math.sin(angleRads);
|