circuitscript 0.1.29 → 0.1.32

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.
Files changed (71) hide show
  1. package/dist/cjs/BaseVisitor.js +185 -22
  2. package/dist/cjs/RefdesAnnotationVisitor.js +27 -10
  3. package/dist/cjs/antlr/CircuitScriptLexer.js +241 -236
  4. package/dist/cjs/antlr/CircuitScriptParser.js +1197 -901
  5. package/dist/cjs/builtinMethods.js +6 -2
  6. package/dist/cjs/draw_symbols.js +38 -34
  7. package/dist/cjs/environment.js +28 -4
  8. package/dist/cjs/execute.js +195 -125
  9. package/dist/cjs/globals.js +6 -1
  10. package/dist/cjs/graph.js +14 -12
  11. package/dist/cjs/helpers.js +90 -17
  12. package/dist/cjs/layout.js +50 -25
  13. package/dist/cjs/main.js +16 -14
  14. package/dist/cjs/objects/ClassComponent.js +199 -30
  15. package/dist/cjs/objects/ExecutionScope.js +9 -0
  16. package/dist/cjs/objects/types.js +25 -2
  17. package/dist/cjs/parser.js +6 -2
  18. package/dist/cjs/regenerate-tests.js +3 -3
  19. package/dist/cjs/render.js +5 -3
  20. package/dist/cjs/rules-check/no-connect-on-connected-pin.js +9 -8
  21. package/dist/cjs/rules-check/rules.js +7 -2
  22. package/dist/cjs/rules-check/unconnected-pins.js +10 -8
  23. package/dist/cjs/utils.js +2 -1
  24. package/dist/cjs/validate/SymbolTable.js +7 -1
  25. package/dist/cjs/validate/SymbolValidatorVisitor.js +54 -17
  26. package/dist/cjs/visitor.js +299 -238
  27. package/dist/esm/BaseVisitor.js +187 -24
  28. package/dist/esm/RefdesAnnotationVisitor.js +27 -10
  29. package/dist/esm/antlr/CircuitScriptLexer.js +241 -236
  30. package/dist/esm/antlr/CircuitScriptParser.js +1196 -899
  31. package/dist/esm/antlr/CircuitScriptVisitor.js +4 -1
  32. package/dist/esm/builtinMethods.js +7 -3
  33. package/dist/esm/draw_symbols.js +38 -34
  34. package/dist/esm/environment.js +25 -1
  35. package/dist/esm/execute.js +197 -127
  36. package/dist/esm/globals.js +4 -0
  37. package/dist/esm/graph.js +14 -12
  38. package/dist/esm/helpers.js +91 -18
  39. package/dist/esm/layout.js +51 -26
  40. package/dist/esm/main.js +16 -14
  41. package/dist/esm/objects/ClassComponent.js +201 -30
  42. package/dist/esm/objects/ExecutionScope.js +9 -0
  43. package/dist/esm/objects/types.js +33 -1
  44. package/dist/esm/parser.js +6 -2
  45. package/dist/esm/regenerate-tests.js +3 -3
  46. package/dist/esm/render.js +5 -3
  47. package/dist/esm/rules-check/no-connect-on-connected-pin.js +9 -8
  48. package/dist/esm/rules-check/rules.js +7 -2
  49. package/dist/esm/rules-check/unconnected-pins.js +10 -8
  50. package/dist/esm/utils.js +2 -1
  51. package/dist/esm/validate/SymbolTable.js +5 -0
  52. package/dist/esm/validate/SymbolValidatorVisitor.js +53 -16
  53. package/dist/esm/visitor.js +201 -137
  54. package/dist/types/BaseVisitor.d.ts +27 -10
  55. package/dist/types/RefdesAnnotationVisitor.d.ts +2 -0
  56. package/dist/types/antlr/CircuitScriptLexer.d.ts +43 -42
  57. package/dist/types/antlr/CircuitScriptParser.d.ts +102 -58
  58. package/dist/types/antlr/CircuitScriptVisitor.d.ts +8 -2
  59. package/dist/types/environment.d.ts +8 -1
  60. package/dist/types/execute.d.ts +6 -3
  61. package/dist/types/globals.d.ts +4 -0
  62. package/dist/types/graph.d.ts +2 -2
  63. package/dist/types/helpers.d.ts +2 -1
  64. package/dist/types/layout.d.ts +5 -4
  65. package/dist/types/objects/ClassComponent.d.ts +34 -9
  66. package/dist/types/objects/ExecutionScope.d.ts +3 -1
  67. package/dist/types/objects/types.d.ts +40 -3
  68. package/dist/types/validate/SymbolTable.d.ts +1 -0
  69. package/dist/types/validate/SymbolValidatorVisitor.d.ts +6 -6
  70. package/dist/types/visitor.d.ts +10 -2
  71. package/package.json +4 -1
@@ -34,7 +34,7 @@ class ExecutionContext {
34
34
  this.scope.scopeLevel = scopeLevel;
35
35
  this.setupRoot();
36
36
  this.silent = silent;
37
- this.log('create new execution context', this.namespace, this.name, this.scope.scopeLevel);
37
+ this.log(`create new execution context, namespace: ${this.namespace}, name: ${this.name}, level: ${this.scope.scopeLevel}`);
38
38
  this.parentContext = parent;
39
39
  this.warnings = warnings;
40
40
  }
@@ -60,7 +60,7 @@ class ExecutionContext {
60
60
  setupRoot() {
61
61
  const componentRoot = ClassComponent_js_1.ClassComponent.simple(globals_js_1.GlobalNames.__root, 1);
62
62
  componentRoot.typeProp = globals_js_1.ComponentTypes.net;
63
- componentRoot.displayProp = this.getPointSymbol();
63
+ componentRoot.addDefaultUnit(this.getPointSymbol());
64
64
  this.scope.instances.set(globals_js_1.GlobalNames.__root, componentRoot);
65
65
  this.scope.setCurrent(componentRoot);
66
66
  this.scope.componentRoot = componentRoot;
@@ -126,49 +126,13 @@ class ExecutionContext {
126
126
  }
127
127
  createComponent(instanceName, pins, params, props, isModule = false) {
128
128
  const className = isModule ? ClassComponent_js_1.ModuleComponent : ClassComponent_js_1.ClassComponent;
129
+ pins = this.extractPinsFromUnits(props.units);
129
130
  const component = new className(instanceName, pins.length);
130
131
  pins.forEach((pin) => {
131
132
  component.pins.set(pin.id, pin);
132
133
  });
133
- component.displayProp = props.display ?? null;
134
- component.widthProp = props.width ?? null;
135
- component.heightProp = props.height ?? null;
136
134
  component.typeProp = props.type ?? null;
137
135
  component.copyProp = props.copy ?? false;
138
- let useAngle = null;
139
- if (props.angle) {
140
- useAngle = props.angle.toNumber() % 360;
141
- if (useAngle < 0) {
142
- useAngle += 360;
143
- }
144
- }
145
- if (props.display === null && props.arrange === null) {
146
- const tmpArrangeLeft = [];
147
- const tmpArrangeRight = [];
148
- pins.forEach((pin, index) => {
149
- const useArray = (index % 2 === 0) ? tmpArrangeLeft : tmpArrangeRight;
150
- useArray.push(pin.id);
151
- });
152
- const arrangeProp = new Map([
153
- [globals_js_1.SymbolPinSide.Left, tmpArrangeLeft],
154
- [globals_js_1.SymbolPinSide.Right, tmpArrangeRight]
155
- ]);
156
- props.arrange = arrangeProp;
157
- }
158
- if (props.arrange !== null) {
159
- component.arrangeProps = this.removeArrangePropDuplicates(props.arrange);
160
- const arrangePropPins = this.getArrangePropPins(component.arrangeProps);
161
- pins.forEach(pin => {
162
- if (arrangePropPins.find(id => id.equals(pin.id)) === undefined) {
163
- this.logWarning(`Pin ${pin.id} is not specified in arrange property`);
164
- }
165
- });
166
- }
167
- else {
168
- component.arrangeProps = null;
169
- }
170
- component.angleProp = useAngle ?? 0;
171
- component.followWireOrientationProp = props.followWireOrientation;
172
136
  const paramsMap = new Map();
173
137
  params.forEach((param) => {
174
138
  component.parameters.set(param.paramName, param.paramValue);
@@ -195,27 +159,91 @@ class ExecutionContext {
195
159
  this.scope.setNet(component, defaultPin, tmpNet);
196
160
  this.log('set net', netName, 'component', component, defaultPin);
197
161
  }
198
- const { pins: pinSides, maxPositions } = getPortSide(component.pins, component.arrangeProps);
199
- component.pinsMaxPositions = maxPositions;
200
- const pinIdKeys = Array.from(component.pins.keys());
201
- pinSides.forEach(({ pinId, side, position }) => {
202
- const matchedPinId = pinIdKeys.find(id => id.equals(pinId));
203
- if (matchedPinId) {
204
- const tmpPin = component.pins.get(matchedPinId);
205
- tmpPin.side = side;
206
- tmpPin.position = position;
207
- }
208
- else {
209
- throw 'Not found!';
210
- }
211
- });
212
162
  this.scope.instances.set(instanceName, component);
213
163
  const pinsOutput = pins.map((pin) => {
214
164
  return pin.id + ':' + pin.name;
215
165
  });
216
166
  this.log('add symbol', instanceName, '[' + pinsOutput.join(', ') + ']');
167
+ component.units = this.generateComponentUnits(props.units, component);
168
+ component.refreshPinUnitMap();
217
169
  return component;
218
170
  }
171
+ extractPinsFromUnits(units) {
172
+ const pins = [];
173
+ units.forEach(([, definition]) => {
174
+ pins.push(...definition.pins);
175
+ });
176
+ return pins;
177
+ }
178
+ generateComponentUnits(units, parent) {
179
+ return units.map(([key, unitDef]) => {
180
+ unitDef = { ...unitDef };
181
+ let useAngle = null;
182
+ const { pins } = unitDef;
183
+ const pinsMap = new Map();
184
+ pins.forEach(pin => {
185
+ pinsMap.set(pin.id, pin);
186
+ });
187
+ if (unitDef.angle) {
188
+ useAngle = unitDef.angle.toNumber() % 360;
189
+ if (useAngle < 0) {
190
+ useAngle += 360;
191
+ }
192
+ }
193
+ if (unitDef.display === null && unitDef.arrange === null) {
194
+ const tmpArrangeLeft = [];
195
+ const tmpArrangeRight = [];
196
+ pins.forEach((pin, index) => {
197
+ const useArray = (index % 2 === 0) ? tmpArrangeLeft : tmpArrangeRight;
198
+ useArray.push(pin.id);
199
+ });
200
+ const arrangeProp = new Map([
201
+ [globals_js_1.SymbolPinSide.Left, tmpArrangeLeft],
202
+ [globals_js_1.SymbolPinSide.Right, tmpArrangeRight]
203
+ ]);
204
+ unitDef.arrange = arrangeProp;
205
+ }
206
+ if (unitDef.arrange !== null) {
207
+ unitDef.arrange = this.removeArrangePropDuplicates(unitDef.arrange);
208
+ const arrangePropPins = this.getArrangePropPins(unitDef.arrange);
209
+ pins.forEach(pin => {
210
+ if (arrangePropPins.find(id => id.equals(pin.id)) === undefined) {
211
+ this.logWarning(`Pin ${pin.id} is not specified in arrange property`);
212
+ }
213
+ });
214
+ }
215
+ else {
216
+ unitDef.arrange = null;
217
+ }
218
+ unitDef.angle = useAngle ?? 0;
219
+ const { pins: pinSides, maxPositions } = getPortSide(pinsMap, unitDef.arrange);
220
+ const pinIdKeys = Array.from(pinsMap.keys());
221
+ pinSides.forEach(({ pinId, side, position }) => {
222
+ const matchedPinId = pinIdKeys.find(id => id.equals(pinId));
223
+ if (matchedPinId) {
224
+ const tmpPin = pinsMap.get(matchedPinId);
225
+ tmpPin.side = side;
226
+ tmpPin.position = position;
227
+ }
228
+ else {
229
+ throw 'Not found!';
230
+ }
231
+ });
232
+ const componentUnit = new ClassComponent_js_1.ComponentUnit(key, parent);
233
+ componentUnit.widthProp = unitDef.width;
234
+ componentUnit.heightProp = unitDef.height;
235
+ componentUnit.angleProp = unitDef.angle;
236
+ componentUnit.followWireOrientationProp = unitDef.followWireOrientation;
237
+ componentUnit.pins = pinsMap;
238
+ componentUnit.pinsFlat = pins;
239
+ componentUnit.numPins = unitDef.pins.length;
240
+ componentUnit.pinsMaxPositions = maxPositions;
241
+ componentUnit.displayProp = unitDef.display;
242
+ componentUnit.arrangeProps = unitDef.arrange;
243
+ componentUnit.suffix = unitDef.suffix ?? null;
244
+ return componentUnit;
245
+ });
246
+ }
219
247
  removeArrangePropDuplicates(arrangeProp) {
220
248
  const sides = [
221
249
  globals_js_1.SymbolPinSide.Left,
@@ -586,10 +614,11 @@ class ExecutionContext {
586
614
  getBreakContext() {
587
615
  return this.scope.breakStack[this.scope.breakStack.length - 1];
588
616
  }
589
- createFunction(functionName, __runFunc, source, uniqueId) {
590
- this.scope.functions.set(functionName, new types_js_1.CFunctionEntry(functionName, __runFunc, source, uniqueId));
591
- this.__functionCache.set(functionName, __runFunc);
592
- this.log(`defined new function '${functionName}'`);
617
+ createFunction(namespace, functionName, __runFunc, source, uniqueId) {
618
+ const functionPath = `${namespace}${functionName}`;
619
+ this.scope.functions.set(functionPath, new types_js_1.CFunctionEntry(namespace, functionName, __runFunc, source, uniqueId));
620
+ this.__functionCache.set(functionPath, __runFunc);
621
+ this.log(`defined new function: ${functionPath}`);
593
622
  }
594
623
  hasFunction(functionName) {
595
624
  return this.scope.functions.has(functionName);
@@ -598,32 +627,63 @@ class ExecutionContext {
598
627
  return this.scope.functions.get(functionName);
599
628
  }
600
629
  resolveVariable(executionStack, idName, trailers = []) {
630
+ this.log('resolve variable name:', idName, 'trailers:', trailers);
601
631
  const reversed = [...executionStack].reverse();
602
632
  for (let i = 0; i < reversed.length; i++) {
603
633
  const context = reversed[i];
604
- if (context.hasFunction(idName)) {
634
+ const functionPath = `${context.namespace}${idName}`;
635
+ if (context.hasFunction(functionPath)) {
605
636
  return new types_js_1.DeclaredReference({
606
637
  found: true,
607
- value: context.getFunction(idName),
638
+ value: context.getFunction(functionPath),
608
639
  type: globals_js_1.ReferenceTypes.function,
609
640
  name: idName,
610
641
  });
611
642
  }
612
643
  else {
644
+ const modules = Array.from(context.scope.modules.values());
645
+ for (let j = 0; j < modules.length; j++) {
646
+ const module = modules[j];
647
+ if (module.importHandlingFlag === types_js_1.ImportFunctionHandling.AllMergeIntoNamespace ||
648
+ (module.importHandlingFlag === types_js_1.ImportFunctionHandling.SpecificMergeIntoNamespace
649
+ && module.specifiedImports.indexOf(idName) !== -1)) {
650
+ const moduleContext = module.context;
651
+ const functionPath = `${moduleContext.namespace}${idName}`;
652
+ if (module.context.hasFunction(functionPath)) {
653
+ return new types_js_1.DeclaredReference({
654
+ found: true,
655
+ rootValue: module,
656
+ value: module.context.getFunction(functionPath),
657
+ type: globals_js_1.ReferenceTypes.function,
658
+ name: idName,
659
+ trailerIndex: 1,
660
+ trailers: [idName],
661
+ });
662
+ }
663
+ }
664
+ }
665
+ let isModule = false;
666
+ if (context.scope.modules.has(idName)) {
667
+ const module = context.scope.modules.get(idName);
668
+ if (module.importHandlingFlag === types_js_1.ImportFunctionHandling.AllWithNamespace) {
669
+ isModule = true;
670
+ }
671
+ }
613
672
  let isVariable = context.scope.variables.has(idName);
614
673
  let isComponentInstance = context.scope.instances.has(idName);
615
- if (isVariable || isComponentInstance) {
616
- const scopeList = isVariable ? context.scope.variables
617
- : context.scope.instances;
674
+ if (isModule || isVariable || isComponentInstance) {
675
+ const scopeList = isModule ? context.scope.modules :
676
+ (isVariable ? context.scope.variables : context.scope.instances);
618
677
  const useValue = scopeList.get(idName);
619
678
  if (!isComponentInstance && (useValue instanceof ClassComponent_js_1.ClassComponent)) {
620
679
  isComponentInstance = true;
621
680
  isVariable = false;
622
681
  }
623
- const tmpReference = this.resolveTrailers(isVariable ? globals_js_1.ReferenceTypes.variable : globals_js_1.ReferenceTypes.instance, useValue, trailers);
682
+ const referenceType = isModule ? globals_js_1.ReferenceTypes.module :
683
+ (isVariable ? globals_js_1.ReferenceTypes.variable : globals_js_1.ReferenceTypes.instance);
684
+ const tmpReference = this.resolveTrailers(referenceType, useValue, trailers);
624
685
  return new types_js_1.DeclaredReference({
625
- type: isVariable ? globals_js_1.ReferenceTypes.variable
626
- : globals_js_1.ReferenceTypes.instance,
686
+ type: referenceType,
627
687
  found: (tmpReference.value !== undefined),
628
688
  rootValue: tmpReference.rootValue,
629
689
  value: tmpReference.value,
@@ -644,65 +704,63 @@ class ExecutionContext {
644
704
  if (trailers.length > 0) {
645
705
  rootValue = useValue;
646
706
  const trailersPath = trailers.join(".");
647
- if (type === globals_js_1.ReferenceTypes.variable) {
648
- useValue = rootValue;
649
- trailers.forEach(trailerPath => {
650
- useValue = useValue[trailerPath];
651
- });
652
- }
653
- else if (type === globals_js_1.ReferenceTypes.instance) {
654
- const tmpComponent = rootValue;
655
- if (tmpComponent.typeProp === globals_js_1.ComponentTypes.net) {
656
- const usedNet = this.scope.getNet(tmpComponent, new PinDefinition_js_1.PinId(1));
657
- if (usedNet) {
658
- const trailerValue = trailers.join(".");
659
- useValue = usedNet.params.get(trailerValue) ?? null;
707
+ switch (type) {
708
+ case globals_js_1.ReferenceTypes.variable:
709
+ useValue = rootValue;
710
+ trailers.forEach(trailerPath => {
711
+ useValue = useValue[trailerPath];
712
+ });
713
+ break;
714
+ case globals_js_1.ReferenceTypes.instance: {
715
+ const tmpComponent = rootValue;
716
+ if (tmpComponent.typeProp === globals_js_1.ComponentTypes.net) {
717
+ const usedNet = this.scope.getNet(tmpComponent, new PinDefinition_js_1.PinId(1));
718
+ if (usedNet) {
719
+ const trailerValue = trailers.join(".");
720
+ useValue = usedNet.params.get(trailerValue) ?? null;
721
+ }
722
+ }
723
+ else {
724
+ useValue = rootValue
725
+ .parameters.get(trailersPath);
660
726
  }
727
+ break;
661
728
  }
662
- else {
663
- useValue = rootValue
664
- .parameters.get(trailersPath);
729
+ case globals_js_1.ReferenceTypes.module: {
730
+ const funcName = trailers[0];
731
+ const module = rootValue;
732
+ const functionPath = `${module.moduleNamespace}${funcName}`;
733
+ if (module.context.hasFunction(functionPath)) {
734
+ const foundFunc = module.context.getFunction(functionPath);
735
+ return new types_js_1.AnyReference({
736
+ found: true,
737
+ type: globals_js_1.ReferenceTypes.function,
738
+ rootValue,
739
+ trailers,
740
+ trailerIndex: trailers.length,
741
+ value: foundFunc,
742
+ });
743
+ }
744
+ break;
665
745
  }
666
746
  }
667
747
  }
668
748
  let found = false;
669
- if (rootValue !== undefined && useValue !== undefined) {
749
+ if (useValue !== undefined) {
670
750
  found = true;
671
751
  }
672
752
  return new types_js_1.AnyReference({
673
753
  found,
674
- type: type,
754
+ type,
675
755
  rootValue,
676
756
  trailers,
677
757
  trailerIndex: trailers.length,
678
758
  value: useValue,
679
759
  });
680
760
  }
681
- callFunction(functionName, functionParams, executionStack, netNamespace) {
682
- let __runFunc = null;
683
- if (!this.__functionCache.has(functionName)) {
684
- if (this.hasFunction(functionName)) {
685
- const entry = this.getFunction(functionName);
686
- __runFunc = entry.execute;
687
- }
688
- if (__runFunc === null) {
689
- this.log(`searching for function ${functionName} in upper context`);
690
- const tmpResolveResult = this.resolveVariable(executionStack, functionName);
691
- if (tmpResolveResult.found) {
692
- const entry = tmpResolveResult.value;
693
- __runFunc = entry.execute;
694
- }
695
- else {
696
- throw `Invalid function ${functionName}`;
697
- }
698
- }
699
- this.log('save function to cache:', functionName);
700
- this.__functionCache.set(functionName, __runFunc);
701
- }
702
- else {
703
- this.log('found function in cache:', functionName);
704
- __runFunc = this.__functionCache.get(functionName);
705
- }
761
+ callFunction(functionReference, functionParams, executionStack, netNamespace) {
762
+ const functionEntry = functionReference.value;
763
+ const { name: functionName, execute: __runFunc } = functionEntry;
706
764
  if (__runFunc !== null) {
707
765
  let functionCallIndex = -1;
708
766
  if (!this.scope.functionCounter.has(__runFunc)) {
@@ -720,6 +778,7 @@ class ExecutionContext {
720
778
  return functionResult;
721
779
  }
722
780
  else {
781
+ this.log(`Invalid function: ${functionName}`);
723
782
  throw `Invalid function '${functionName}'`;
724
783
  }
725
784
  }
@@ -730,7 +789,7 @@ class ExecutionContext {
730
789
  const tmpNets = childScope.getNets();
731
790
  const mergedInstances = [];
732
791
  for (const [instanceName, component] of tmpInstances) {
733
- const newInstanceName = `${namespace}.${instanceName}`;
792
+ const newInstanceName = namespace !== "" ? `${namespace}.${instanceName}` : instanceName;
734
793
  component.instanceName = newInstanceName;
735
794
  if (component === childScope.componentRoot) {
736
795
  continue;
@@ -850,9 +909,10 @@ class ExecutionContext {
850
909
  this.scope.setActive(ExecutionScope_js_1.ActiveObject.Wire, wireId);
851
910
  this.scope.sequence.push([ExecutionScope_js_1.SequenceAction.Wire, wireId, tmp, newWire]);
852
911
  this.scope.currentComponent.pinWires.set(this.scope.currentPin, tmp);
853
- if (!this.scope.currentComponent.didSetWireOrientationAngle) {
912
+ const currentUnit = this.scope.currentComponent.getUnitForPin(this.scope.currentPin);
913
+ if (!currentUnit.didSetWireOrientationAngle) {
854
914
  this.applyComponentAngleFromWire(this.scope.currentComponent, this.scope.currentPin, true);
855
- this.scope.currentComponent.didSetWireOrientationAngle = true;
915
+ currentUnit.didSetWireOrientationAngle = true;
856
916
  }
857
917
  return newWire;
858
918
  }
@@ -862,7 +922,6 @@ class ExecutionContext {
862
922
  }
863
923
  const useName = userDefined ? 'point.' + pointId : pointId;
864
924
  const componentPoint = ClassComponent_js_1.ClassComponent.simple(useName, 1);
865
- componentPoint.displayProp = this.getPointSymbol(useName);
866
925
  componentPoint.typeProp = globals_js_1.ComponentTypes.net;
867
926
  let usePointLinkComponent = null;
868
927
  if (this.scope.currentComponent._pointLinkComponent) {
@@ -872,6 +931,7 @@ class ExecutionContext {
872
931
  usePointLinkComponent = this.scope.currentComponent;
873
932
  }
874
933
  componentPoint._pointLinkComponent = usePointLinkComponent;
934
+ componentPoint.addDefaultUnit(this.getPointSymbol(useName));
875
935
  this.scope.instances.set(pointId, componentPoint);
876
936
  this.toComponent(componentPoint, 1, { addSequence: true });
877
937
  return this.getCurrentPoint();
@@ -945,6 +1005,15 @@ class ExecutionContext {
945
1005
  if (this.scope.instances.has(idName)) {
946
1006
  const component = this.scope.instances.get(idName);
947
1007
  component.setParam(paramName, value);
1008
+ const unitModifiers = [
1009
+ globals_js_1.ParamKeys.angle,
1010
+ globals_js_1.ParamKeys.flip,
1011
+ globals_js_1.ParamKeys.flipX,
1012
+ globals_js_1.ParamKeys.flipY,
1013
+ ];
1014
+ if (unitModifiers.indexOf(paramName) !== -1) {
1015
+ component.getUnit().setParam(paramName, value);
1016
+ }
948
1017
  }
949
1018
  else if (this.scope.variables.has(idName)) {
950
1019
  throw "Not implemented yet!";
@@ -955,17 +1024,18 @@ class ExecutionContext {
955
1024
  }
956
1025
  }
957
1026
  applyComponentAngleFromWire(component, pin, opposite = false) {
1027
+ const targetUnit = component.getUnitForPin(pin);
958
1028
  if (this.componentAngleFollowsWire
959
- && component.followWireOrientationProp
960
- && component.useWireOrientationAngle
961
- && !component.didSetWireOrientationAngle
1029
+ && targetUnit.followWireOrientationProp
1030
+ && targetUnit.useWireOrientationAngle
1031
+ && !targetUnit.didSetWireOrientationAngle
962
1032
  && this.scope.currentWireId !== -1) {
963
1033
  const currentWire = this.scope.wires[this.scope.currentWireId];
964
1034
  let useSegment = currentWire.path[currentWire.path.length - 1];
965
1035
  if (opposite) {
966
1036
  useSegment = currentWire.path[0];
967
1037
  }
968
- const pinPositions = (0, layout_js_1.CalculatePinPositions)(component);
1038
+ const pinPositions = (0, layout_js_1.CalculatePinPositions)(targetUnit);
969
1039
  if (pinPositions.has(pin)) {
970
1040
  const connectedPinPos = pinPositions.get(pin);
971
1041
  let targetAngle = null;
@@ -1003,27 +1073,27 @@ class ExecutionContext {
1003
1073
  if (targetAngle === null) {
1004
1074
  return;
1005
1075
  }
1006
- this.log('set component angle from wire, target angle:', targetAngle, ', component angle:', component.angleProp, 'pin angle:', connectedPinPos.angle);
1076
+ this.log('set component unit angle from wire, target angle:', targetAngle, ', component unit angle:', targetUnit.angleProp, 'pin angle:', connectedPinPos.angle);
1007
1077
  let useAngle = (targetAngle - connectedPinPos.angle.toNumber()) % 360;
1008
1078
  if (useAngle < 0) {
1009
1079
  useAngle += 360;
1010
1080
  }
1011
1081
  if (useAngle === 90) {
1012
- component.setParam(globals_js_1.ParamKeys.angle, (0, ParamDefinition_js_1.numeric)(90));
1082
+ targetUnit.setParam(globals_js_1.ParamKeys.angle, (0, ParamDefinition_js_1.numeric)(90));
1013
1083
  }
1014
1084
  else if (useAngle === 180) {
1015
- if (component.angleProp === 0 || component.angleProp === 180) {
1016
- component.setParam(globals_js_1.ParamKeys.flipX, 1);
1085
+ if (targetUnit.angleProp === 0 || targetUnit.angleProp === 180) {
1086
+ targetUnit.setParam(globals_js_1.ParamKeys.flipX, (0, ParamDefinition_js_1.numeric)(1));
1017
1087
  }
1018
- else if (component.angleProp === 90 || component.angleProp === 270) {
1019
- component.setParam(globals_js_1.ParamKeys.flipY, 1);
1088
+ else if (targetUnit.angleProp === 90 || targetUnit.angleProp === 270) {
1089
+ targetUnit.setParam(globals_js_1.ParamKeys.flipY, (0, ParamDefinition_js_1.numeric)(1));
1020
1090
  }
1021
1091
  }
1022
1092
  else if (useAngle === 270) {
1023
- component.setParam(globals_js_1.ParamKeys.angle, (0, ParamDefinition_js_1.numeric)(270));
1093
+ targetUnit.setParam(globals_js_1.ParamKeys.angle, (0, ParamDefinition_js_1.numeric)(270));
1024
1094
  }
1025
- component.wireOrientationAngle = useAngle;
1026
- component.didSetWireOrientationAngle = true;
1095
+ targetUnit.wireOrientationAngle = useAngle;
1096
+ targetUnit.didSetWireOrientationAngle = true;
1027
1097
  }
1028
1098
  }
1029
1099
  }
@@ -1,10 +1,13 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.TrailerArrayIndex = exports.SymbolValidatorContext = exports.RenderFlags = exports.GlobalDocumentName = exports.ModuleContainsKeyword = exports.FrameType = exports.NetGraphicsParams = exports.BlockTypes = exports.ReferenceTypes = exports.ComponentTypes = exports.ColorScheme = exports.PortPaddingVertical = exports.PortPaddingHorizontal = exports.PortArrowSize = exports.junctionSize = exports.defaultFontSize = exports.defaultFontBold = exports.defaultFont = exports.displayUnits = exports.defaultFrameTitleTextSize = exports.CustomSymbolParamTextSize = exports.CustomSymbolRefDesSize = exports.CustomSymbolPinIdSize = exports.CustomSymbolPinTextSize = exports.defaultPageSpacingMM = exports.defaultPageMarginMM = exports.defaultPinIdTextSize = exports.defaultPinNameTextSize = exports.defaultWireLineWidth = exports.defaultSymbolLineWidth = exports.fontDisplayScale = exports.defaultZoomScale = exports.defaultGridSizeUnits = exports.portHeight = exports.portWidth = exports.PxToMM = exports.MMToPt = exports.MMToPx = exports.MilsToMM = exports.WireAutoDirection = exports.LengthUnit = exports.ValidPinSides = exports.SymbolPinSide = exports.LayoutDirection = exports.ParamKeys = exports.NoNetText = exports.GlobalNames = exports.DoubleDelimiter1 = exports.Delimiter1 = exports.TOOL_VERSION = void 0;
3
+ exports.RenderFlags = exports.GlobalDocumentName = exports.ModuleContainsKeyword = exports.FrameType = exports.NetGraphicsParams = exports.BlockTypes = exports.ReferenceTypes = exports.ComponentTypes = exports.ColorScheme = exports.PortPaddingVertical = exports.PortPaddingHorizontal = exports.PortArrowSize = exports.junctionSize = exports.defaultFontSize = exports.defaultFontBold = exports.defaultFont = exports.displayUnits = exports.defaultFrameTitleTextSize = exports.CustomSymbolParamTextSize = exports.CustomSymbolRefDesSize = exports.CustomSymbolPinIdSize = exports.CustomSymbolPinTextSize = exports.defaultPageSpacingMM = exports.defaultPageMarginMM = exports.defaultPinIdTextSize = exports.defaultPinNameTextSize = exports.defaultWireLineWidth = exports.defaultSymbolLineWidth = exports.fontDisplayScale = exports.defaultZoomScale = exports.defaultGridSizeUnits = exports.portHeight = exports.portWidth = exports.PxToMM = exports.MMToPt = exports.MMToPx = exports.MilsToMM = exports.WireAutoDirection = exports.LengthUnit = exports.ValidPinSides = exports.SymbolPinSide = exports.LayoutDirection = exports.ParamKeys = exports.NoNetText = exports.GlobalNames = exports.RefdesFileSuffix = exports.BaseNamespace = exports.DoubleDelimiter1 = exports.Delimiter1 = exports.TOOL_VERSION = void 0;
4
+ exports.DefaultComponentUnit = exports.TrailerArrayIndex = exports.SymbolValidatorContext = void 0;
4
5
  const ParamDefinition_js_1 = require("./objects/ParamDefinition.js");
5
6
  exports.TOOL_VERSION = '0.1.5';
6
7
  exports.Delimiter1 = '-';
7
8
  exports.DoubleDelimiter1 = `${exports.Delimiter1}${exports.Delimiter1}`;
9
+ exports.BaseNamespace = `${exports.DoubleDelimiter1}.`;
10
+ exports.RefdesFileSuffix = '.refdes.json';
8
11
  var GlobalNames;
9
12
  (function (GlobalNames) {
10
13
  GlobalNames["__root"] = "--root";
@@ -96,6 +99,7 @@ var ReferenceTypes;
96
99
  ReferenceTypes["variable"] = "variable";
97
100
  ReferenceTypes["instance"] = "instance";
98
101
  ReferenceTypes["pinType"] = "pinType";
102
+ ReferenceTypes["module"] = "module";
99
103
  ReferenceTypes["unknown"] = "unknown";
100
104
  })(ReferenceTypes || (exports.ReferenceTypes = ReferenceTypes = {}));
101
105
  var BlockTypes;
@@ -129,3 +133,4 @@ exports.RenderFlags = {
129
133
  };
130
134
  exports.SymbolValidatorContext = '_sym';
131
135
  exports.TrailerArrayIndex = 'index';
136
+ exports.DefaultComponentUnit = '__default';
package/dist/cjs/graph.js CHANGED
@@ -60,32 +60,33 @@ class NetGraph {
60
60
  case ExecutionScope_js_1.SequenceAction.At: {
61
61
  this.print(...sequenceStep);
62
62
  const [, component, pin] = sequenceStep;
63
- const tmpInstanceName = component.instanceName;
63
+ const componentUnit = component.getUnitForPin(pin);
64
+ const tmpInstanceName = componentUnit.instanceName;
64
65
  if (action === ExecutionScope_js_1.SequenceAction.At) {
65
66
  previousNode = null;
66
67
  previousPin = null;
67
68
  }
68
69
  if (!graph.hasNode(tmpInstanceName)) {
69
70
  this.print('create instance', tmpInstanceName);
70
- const { displayProp = null } = component;
71
+ const { displayProp = null } = componentUnit;
71
72
  let tmpSymbol;
72
73
  if (displayProp instanceof draw_symbols_js_1.SymbolDrawing) {
73
74
  tmpSymbol = new draw_symbols_js_1.SymbolPlaceholder(displayProp);
74
75
  tmpSymbol.drawing.logger = this.logger;
75
76
  }
76
77
  else {
77
- const symbolPinDefinitions = generateLayoutPinDefinition(component);
78
+ const symbolPinDefinitions = generateLayoutPinDefinition(componentUnit);
78
79
  if (component.typeProp === globals_js_1.ComponentTypes.module) {
79
- tmpSymbol = new draw_symbols_js_1.SymbolCustomModule(symbolPinDefinitions, component.pinsMaxPositions);
80
+ tmpSymbol = new draw_symbols_js_1.SymbolCustomModule(symbolPinDefinitions, componentUnit.pinsMaxPositions);
80
81
  }
81
82
  else {
82
- tmpSymbol = new draw_symbols_js_1.SymbolCustom(symbolPinDefinitions, component.pinsMaxPositions);
83
+ tmpSymbol = new draw_symbols_js_1.SymbolCustom(symbolPinDefinitions, componentUnit.pinsMaxPositions);
83
84
  }
84
85
  }
85
- (0, layout_js_1.applyComponentParamsToSymbol)(component, tmpSymbol);
86
+ (0, layout_js_1.applyComponentParamsToSymbol)(componentUnit, tmpSymbol);
86
87
  tmpSymbol.refreshDrawing();
87
88
  const { width: useWidth, height: useHeight } = tmpSymbol.size();
88
- tmpComponent = new layout_js_1.RenderComponent(component, useWidth, useHeight);
89
+ tmpComponent = new layout_js_1.RenderComponent(component, componentUnit.unitId, useWidth, useHeight);
89
90
  tmpComponent.symbol = tmpSymbol;
90
91
  graph.setNode(tmpInstanceName, [RenderItemType.Component, tmpComponent, index]);
91
92
  let useFrame = frameStack[frameStack.length - 1];
@@ -113,7 +114,8 @@ class NetGraph {
113
114
  const [prevNodeType, prevNodeItem] = graph.node(previousNode);
114
115
  if (prevNodeType === RenderItemType.Component) {
115
116
  const matchingItem = nets.find(([comp, pin]) => {
116
- return comp.instanceName === previousNode
117
+ const unit = comp.getUnitForPin(pin);
118
+ return unit.instanceName === previousNode
117
119
  && pin.equals(previousPin);
118
120
  });
119
121
  if (matchingItem !== undefined) {
@@ -348,11 +350,11 @@ function getWireName(wireId) {
348
350
  return 'wire:' + wireId;
349
351
  }
350
352
  exports.getWireName = getWireName;
351
- function generateLayoutPinDefinition(component) {
352
- const pins = component.pins;
353
+ function generateLayoutPinDefinition(componentUnit) {
354
+ const pins = componentUnit.pins;
353
355
  const symbolPinDefinitions = [];
354
356
  const existingPinIds = Array.from(pins.keys());
355
- const arrangeProps = component.arrangeProps ?? [];
357
+ const arrangeProps = componentUnit.arrangeProps ?? [];
356
358
  const addedPins = [];
357
359
  for (const [key, items] of arrangeProps) {
358
360
  let useItems;
@@ -381,7 +383,7 @@ function generateLayoutPinDefinition(component) {
381
383
  return addedPins.find(id => id.equals(pinId)) === undefined;
382
384
  });
383
385
  if (unplacedPins.length > 0) {
384
- component._unplacedPins = unplacedPins;
386
+ componentUnit._unplacedPins = unplacedPins;
385
387
  console.warn("Warning: There are unplaced pins: " + unplacedPins);
386
388
  }
387
389
  return symbolPinDefinitions;