circuitscript 0.5.3 → 0.5.5

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 (74) hide show
  1. package/dist/cjs/BaseVisitor.js +11 -10
  2. package/dist/cjs/annotate/ComponentAnnotater.js +3 -2
  3. package/dist/cjs/builtinMethods.js +6 -5
  4. package/dist/cjs/environment/environment.js +2 -2
  5. package/dist/cjs/errors.js +140 -0
  6. package/dist/cjs/execute.js +12 -5
  7. package/dist/cjs/globals.js +10 -6
  8. package/dist/cjs/main.js +3 -2
  9. package/dist/cjs/objects/ClassComponent.js +4 -4
  10. package/dist/cjs/objects/ExecutionScope.js +2 -2
  11. package/dist/cjs/objects/Frame.js +7 -0
  12. package/dist/cjs/objects/NumericValue.js +15 -0
  13. package/dist/cjs/objects/PinDefinition.js +2 -2
  14. package/dist/cjs/objects/types.js +2 -2
  15. package/dist/cjs/parser.js +3 -2
  16. package/dist/cjs/pipeline.js +25 -15
  17. package/dist/cjs/regenerate-tests.js +6 -6
  18. package/dist/cjs/render/draw_symbols.js +40 -25
  19. package/dist/cjs/render/geometry.js +6 -6
  20. package/dist/cjs/render/graph.js +4 -0
  21. package/dist/cjs/render/layout.js +325 -253
  22. package/dist/cjs/render/render.js +38 -24
  23. package/dist/cjs/semantic-tokens/getSemanticTokens.js +2 -2
  24. package/dist/cjs/sizing.js +2 -2
  25. package/dist/cjs/styles.js +19 -0
  26. package/dist/cjs/utils.js +13 -110
  27. package/dist/cjs/validate/validateScript.js +2 -2
  28. package/dist/cjs/visitor.js +14 -12
  29. package/dist/esm/BaseVisitor.js +2 -1
  30. package/dist/esm/annotate/ComponentAnnotater.js +3 -2
  31. package/dist/esm/builtinMethods.js +6 -5
  32. package/dist/esm/environment/environment.js +1 -1
  33. package/dist/esm/errors.js +119 -0
  34. package/dist/esm/execute.js +10 -3
  35. package/dist/esm/globals.js +8 -4
  36. package/dist/esm/main.js +3 -2
  37. package/dist/esm/objects/ClassComponent.js +1 -1
  38. package/dist/esm/objects/ExecutionScope.js +1 -1
  39. package/dist/esm/objects/Frame.js +7 -0
  40. package/dist/esm/objects/NumericValue.js +15 -0
  41. package/dist/esm/objects/PinDefinition.js +1 -1
  42. package/dist/esm/objects/types.js +1 -1
  43. package/dist/esm/parser.js +2 -1
  44. package/dist/esm/pipeline.js +14 -4
  45. package/dist/esm/regenerate-tests.js +6 -6
  46. package/dist/esm/render/draw_symbols.js +41 -24
  47. package/dist/esm/render/geometry.js +6 -6
  48. package/dist/esm/render/graph.js +5 -0
  49. package/dist/esm/render/layout.js +325 -253
  50. package/dist/esm/render/render.js +38 -24
  51. package/dist/esm/semantic-tokens/getSemanticTokens.js +1 -1
  52. package/dist/esm/sizing.js +2 -2
  53. package/dist/esm/styles.js +20 -0
  54. package/dist/esm/utils.js +10 -95
  55. package/dist/esm/validate/validateScript.js +1 -1
  56. package/dist/esm/visitor.js +4 -2
  57. package/dist/libs/std.cst +37 -37
  58. package/dist/types/BaseVisitor.d.ts +3 -1
  59. package/dist/types/errors.d.ts +37 -0
  60. package/dist/types/execute.d.ts +1 -1
  61. package/dist/types/globals.d.ts +8 -4
  62. package/dist/types/helpers.d.ts +1 -1
  63. package/dist/types/objects/Frame.d.ts +7 -0
  64. package/dist/types/objects/NumericValue.d.ts +5 -1
  65. package/dist/types/render/draw_symbols.d.ts +8 -3
  66. package/dist/types/render/geometry.d.ts +4 -4
  67. package/dist/types/render/graph.d.ts +3 -0
  68. package/dist/types/render/layout.d.ts +7 -1
  69. package/dist/types/render/render.d.ts +2 -1
  70. package/dist/types/styles.d.ts +11 -0
  71. package/dist/types/utils.d.ts +2 -27
  72. package/dist/types/visitor.d.ts +1 -1
  73. package/libs/std.cst +37 -37
  74. package/package.json +1 -1
@@ -0,0 +1,119 @@
1
+ import { ParserRuleContext } from "antlr4ng";
2
+ export class BaseError extends Error {
3
+ name = 'BaseError';
4
+ message;
5
+ startToken;
6
+ endToken;
7
+ filePath;
8
+ constructor(message, startTokenOrCtx, endToken, filePath, options) {
9
+ super(message, options);
10
+ this.message = message;
11
+ if (startTokenOrCtx instanceof ParserRuleContext) {
12
+ this.startToken = startTokenOrCtx.start;
13
+ this.endToken = startTokenOrCtx.stop;
14
+ }
15
+ else {
16
+ this.startToken = startTokenOrCtx;
17
+ this.endToken = endToken;
18
+ }
19
+ this.filePath = filePath;
20
+ }
21
+ toString() {
22
+ const parts = [this.name];
23
+ const linePosition = getLinePositionAsString({
24
+ start: this.startToken,
25
+ stop: this.endToken
26
+ });
27
+ if (linePosition !== null) {
28
+ parts.push(linePosition);
29
+ }
30
+ parts.push(`: ${this.message}`);
31
+ return parts.join('');
32
+ }
33
+ }
34
+ export function getLinePositionAsString(ctx) {
35
+ if (ctx === null || ctx === undefined) {
36
+ return null;
37
+ }
38
+ const { start: startToken, stop: stopToken } = ctx;
39
+ let result = null;
40
+ if (startToken) {
41
+ const { line, column } = startToken;
42
+ let stopLine = 0;
43
+ let stopCol = 0;
44
+ if (stopToken && (stopToken.line !== startToken.line || stopToken.column !== startToken.column)) {
45
+ stopLine = stopToken.line;
46
+ stopCol = stopToken.column + (stopToken.stop - stopToken.start);
47
+ }
48
+ else if (startToken === stopToken || startToken) {
49
+ stopLine = line;
50
+ stopCol = column + 1 + (startToken.stop - startToken.start);
51
+ }
52
+ else {
53
+ stopCol = -1;
54
+ }
55
+ result = ` at ${line}:${column + 1}`;
56
+ if (stopCol !== -1) {
57
+ result += `-${stopLine}:${stopCol + 1}`;
58
+ }
59
+ }
60
+ return result;
61
+ }
62
+ export function throwWithContext(context, messageOrError) {
63
+ if (messageOrError instanceof BaseError) {
64
+ throw messageOrError;
65
+ }
66
+ throwWithTokenRange(messageOrError, context.start, context.stop);
67
+ }
68
+ export function throwWithTokenRange(message, startToken, endToken) {
69
+ throw new ParseError(message, startToken, endToken);
70
+ }
71
+ export class RenderError extends Error {
72
+ stage;
73
+ constructor(message, stage, options) {
74
+ super(message, options);
75
+ this.name = 'RenderError';
76
+ this.stage = stage;
77
+ }
78
+ }
79
+ export class AutoWireFailedError_ extends Error {
80
+ name = 'AutoWireFailedError_';
81
+ wire;
82
+ constructor(message, wire) {
83
+ super(message);
84
+ this.wire = wire;
85
+ }
86
+ }
87
+ export class AutoWireFailedError extends BaseError {
88
+ name = 'AutoWireFailedError';
89
+ }
90
+ export class RuntimeExecutionError extends BaseError {
91
+ name = 'RuntimeExecutionError';
92
+ }
93
+ export class ParseSyntaxError extends BaseError {
94
+ name = 'ParseSyntaxError';
95
+ }
96
+ export class ParseError extends ParseSyntaxError {
97
+ name = 'ParseError';
98
+ }
99
+ export function collectErrorChain(error) {
100
+ const items = [];
101
+ let currentError = error;
102
+ for (let i = 0; i < 100; i++) {
103
+ if (currentError.cause) {
104
+ items.push(currentError.cause);
105
+ currentError = currentError.cause;
106
+ }
107
+ else {
108
+ break;
109
+ }
110
+ }
111
+ return items;
112
+ }
113
+ export function printErrorChain(error) {
114
+ const errors = collectErrorChain(error);
115
+ errors.reverse();
116
+ for (const err of errors) {
117
+ console.log(" " + err.toString());
118
+ }
119
+ }
@@ -12,7 +12,8 @@ import { Frame } from './objects/Frame.js';
12
12
  import { CalculatePinPositions } from './render/layout.js';
13
13
  import { UnitDimension } from './helpers.js';
14
14
  import { PlaceHolderCommands, SymbolDrawingCommands } from './render/draw_symbols.js';
15
- import { getBlockTypeString, RuntimeExecutionError } from './utils.js';
15
+ import { getBlockTypeString } from './utils.js';
16
+ import { RuntimeExecutionError } from "./errors.js";
16
17
  export class ExecutionContext {
17
18
  name;
18
19
  namespace;
@@ -489,7 +490,13 @@ export class ExecutionContext {
489
490
  const { start_point: [component, pin,] } = stackRef;
490
491
  this.atComponent(component, pin, { addSequence: true });
491
492
  }
492
- this.scope.blockStack.delete(scopeLevel);
493
+ const scopeLevels = Array.from(this.scope.blockStack.keys());
494
+ for (const level of scopeLevels) {
495
+ if (level >= scopeLevel) {
496
+ this.log(`blockstack delete level ${level}`);
497
+ this.scope.blockStack.delete(level);
498
+ }
499
+ }
493
500
  this.log('exit blocks');
494
501
  }
495
502
  closeOpenPathBlocks() {
@@ -906,7 +913,7 @@ export class ExecutionContext {
906
913
  this.log('-- done merging scope --');
907
914
  return mergedInstances;
908
915
  }
909
- addWire(segments) {
916
+ addWire(segments, ctx) {
910
917
  if (this.scope.currentComponent === null) {
911
918
  throw "No current component";
912
919
  }
@@ -56,8 +56,11 @@ export const portHeight = 2;
56
56
  export const defaultGridSizeUnits = numeric(MilsToMM).mul(100).toNumber();
57
57
  export const defaultZoomScale = 2.5;
58
58
  export const fontDisplayScale = 0.032;
59
+ export const Defaults = {
60
+ WireLineWidth: numeric(6),
61
+ LineWidth: numeric(5),
62
+ };
59
63
  export const defaultSymbolLineWidth = numeric(MilsToMM).mul(6).toNumber();
60
- export const defaultWireLineWidth = numeric(MilsToMM).mul(6).toNumber();
61
64
  export const defaultPinNameTextSize = 40;
62
65
  export const defaultPinIdTextSize = 30;
63
66
  export const defaultPageMarginMM = 10;
@@ -103,10 +106,10 @@ export var ReferenceTypes;
103
106
  export var NetGraphicsParams;
104
107
  (function (NetGraphicsParams) {
105
108
  NetGraphicsParams["Color"] = "color";
106
- NetGraphicsParams["LineWidth"] = "lineWidth";
109
+ NetGraphicsParams["LineWidth"] = "line_width";
107
110
  NetGraphicsParams["Highlight"] = "highlight";
108
- NetGraphicsParams["HighlightWidth"] = "highlightWidth";
109
- NetGraphicsParams["HighlightOpacity"] = "highlightOpacity";
111
+ NetGraphicsParams["HighlightWidth"] = "highlight_width";
112
+ NetGraphicsParams["HighlightOpacity"] = "highlight_opacity";
110
113
  })(NetGraphicsParams || (NetGraphicsParams = {}));
111
114
  export var FrameType;
112
115
  (function (FrameType) {
@@ -115,6 +118,7 @@ export var FrameType;
115
118
  })(FrameType || (FrameType = {}));
116
119
  export const ModuleContainsKeyword = 'contains';
117
120
  export const GlobalDocumentName = 'document';
121
+ export const KeywordRefdesPrefix = 'refdes_prefix';
118
122
  export const RenderFlags = {
119
123
  ShowElementFrames: false,
120
124
  ShowOrigin: false,
package/dist/esm/main.js CHANGED
@@ -4,6 +4,7 @@ import figlet from 'figlet';
4
4
  import { watch } from 'fs';
5
5
  import { renderScript } from "./pipeline.js";
6
6
  import { NodeScriptEnvironment } from "./environment/environment.js";
7
+ import { printErrorChain } from './errors.js';
7
8
  export default async function main() {
8
9
  const env = new NodeScriptEnvironment();
9
10
  NodeScriptEnvironment.setInstance(env);
@@ -133,8 +134,8 @@ async function parseFile(scriptData, outputPath, scriptOptions) {
133
134
  return output;
134
135
  }
135
136
  catch (error) {
136
- console.error(`Unexpected Error: ${error}`);
137
- console.log(error.stack);
137
+ console.error(`Unexpected Error:`);
138
+ printErrorChain(error);
138
139
  }
139
140
  return null;
140
141
  }
@@ -2,7 +2,7 @@ import { SymbolDrawingCommands } from '../render/draw_symbols.js';
2
2
  import { PinDefinition, PinId, PinIdType } from './PinDefinition.js';
3
3
  import { PinTypes } from './PinTypes.js';
4
4
  import { DefaultComponentUnit, ParamKeys } from '../globals.js';
5
- import { RuntimeExecutionError } from '../utils.js';
5
+ import { RuntimeExecutionError } from "../errors.js";
6
6
  export class ComponentUnit {
7
7
  parent;
8
8
  unitId;
@@ -1,6 +1,6 @@
1
1
  import { Property_key_exprContext } from '../antlr/CircuitScriptParser.js';
2
2
  import { PinId } from './PinDefinition.js';
3
- import { RuntimeExecutionError } from '../utils.js';
3
+ import { RuntimeExecutionError } from "../errors.js";
4
4
  export class ExecutionScope {
5
5
  scopeId;
6
6
  nets = [];
@@ -25,6 +25,13 @@ export var FrameParamKeys;
25
25
  FrameParamKeys["SheetType"] = "sheet_type";
26
26
  FrameParamKeys["GridStyle"] = "grid_style";
27
27
  FrameParamKeys["GridColor"] = "grid_color";
28
+ FrameParamKeys["BackgroundColor"] = "background_color";
29
+ FrameParamKeys["LineColor"] = "line_color";
30
+ FrameParamKeys["LineWidth"] = "line_width";
31
+ FrameParamKeys["FillColor"] = "fill_color";
32
+ FrameParamKeys["TextColor"] = "text_color";
33
+ FrameParamKeys["WireColor"] = "wire_color";
34
+ FrameParamKeys["WireWidth"] = "wire_width";
28
35
  FrameParamKeys["TitleAlign"] = "title_align";
29
36
  FrameParamKeys["HorizontalAlign"] = "align";
30
37
  FrameParamKeys["VerticalAlign"] = "valign";
@@ -27,6 +27,9 @@ export class NumericValue {
27
27
  toString() {
28
28
  return 'numeric:' + this.value;
29
29
  }
30
+ copy() {
31
+ return this.add(0);
32
+ }
30
33
  toDisplayString() {
31
34
  if (typeof this.value === 'number') {
32
35
  return this.value.toString();
@@ -81,6 +84,15 @@ export class NumericValue {
81
84
  eq(value) {
82
85
  return this.toBigNumber().eq(value.toBigNumber());
83
86
  }
87
+ floor() {
88
+ return numeric(Math.floor(this.toNumber()));
89
+ }
90
+ ceil() {
91
+ return numeric(Math.ceil(this.toNumber()));
92
+ }
93
+ roundDp() {
94
+ return roundValue(this.toNumber());
95
+ }
84
96
  }
85
97
  export class NumberOperator {
86
98
  prepare(value) {
@@ -185,5 +197,8 @@ export function resolveToNumericValue(value) {
185
197
  return new NumericValue(useValue, prefixPart * 3);
186
198
  }
187
199
  export function roundValue(value) {
200
+ if (typeof value === "number") {
201
+ value = numeric(value);
202
+ }
188
203
  return resolveToNumericValue(new Big(value.toBigNumber().toFixed(7)));
189
204
  }
@@ -1,4 +1,4 @@
1
- import { RuntimeExecutionError } from '../utils.js';
1
+ import { RuntimeExecutionError } from "../errors.js";
2
2
  import { NumericValue } from './NumericValue.js';
3
3
  import { PinTypes } from './PinTypes.js';
4
4
  export class PinId {
@@ -1,5 +1,5 @@
1
1
  import { ReferenceTypes } from '../globals.js';
2
- import { RuntimeExecutionError } from '../utils.js';
2
+ import { RuntimeExecutionError } from "../errors.js";
3
3
  export class CFunctionEntry {
4
4
  name;
5
5
  namespace;
@@ -1,6 +1,7 @@
1
1
  import { CircuitScriptParser } from './antlr/CircuitScriptParser.js';
2
2
  import { MainLexer } from './lexer.js';
3
- import { ParseSyntaxError, RuntimeExecutionError, SimpleStopwatch } from './utils.js';
3
+ import { SimpleStopwatch } from './utils.js';
4
+ import { ParseSyntaxError, RuntimeExecutionError } from "./errors.js";
4
5
  import { CharStream, CommonTokenStream, PredictionMode } from 'antlr4ng';
5
6
  export function parseFileWithVisitor(visitor, data, options) {
6
7
  const lexerErrorListener = new CircuitscriptParserErrorListener(visitor.onErrorHandler);
@@ -12,8 +12,10 @@ import { parseFileWithVisitor } from "./parser.js";
12
12
  import { KiCadNetListOutputHandler } from "./render/KiCadNetListOutputHandler.js";
13
13
  import { renderSheetsToSVG, generateSvgOutput, generatePdfOutput } from "./render/render.js";
14
14
  import { EvaluateERCRules } from "./rules-check/rules.js";
15
- import { RuntimeExecutionError, ParseSyntaxError, ParseError, printWarnings, RenderError, generateDebugSequenceAction, sequenceActionString, SimpleStopwatch } from "./utils.js";
15
+ import { printWarnings, generateDebugSequenceAction, sequenceActionString, SimpleStopwatch } from "./utils.js";
16
16
  import { ParserVisitor } from "./visitor.js";
17
+ import { getStylesFromDocument } from "./styles.js";
18
+ import { RuntimeExecutionError, ParseSyntaxError, ParseError, RenderError, AutoWireFailedError, AutoWireFailedError_ } from "./errors.js";
17
19
  export async function renderScript(scriptData, outputPath, options) {
18
20
  const parseHandlers = [
19
21
  new KiCadNetListOutputHandler(),
@@ -187,8 +189,10 @@ export async function renderScriptCustom(scriptData, outputPath, options, parseH
187
189
  const graphEngine = new NetGraph(logger);
188
190
  const layoutEngine = new LayoutEngine(logger);
189
191
  const layoutTimer = new SimpleStopwatch();
192
+ const styles = getStylesFromDocument(documentVariable);
190
193
  let sheetFrames;
191
194
  try {
195
+ graphEngine.setStyles(styles);
192
196
  const { graph, containerFrames } = graphEngine.generateLayoutGraph(sequence, nets);
193
197
  sheetFrames = layoutEngine.runLayout(graph, containerFrames, nets);
194
198
  if (enableErc) {
@@ -205,7 +209,13 @@ export async function renderScriptCustom(scriptData, outputPath, options, parseH
205
209
  }
206
210
  }
207
211
  catch (err) {
208
- throw new RenderError(`Error during layout generation: ${err}`, 'layout');
212
+ let useErr = err;
213
+ if (err instanceof AutoWireFailedError_) {
214
+ const errCtx = visitor.wireCtxLinks.get(err.wire);
215
+ useErr = new AutoWireFailedError(err.message, errCtx.start, errCtx.stop);
216
+ }
217
+ dumpData && environment.writeFileSync(dumpDirectory + 'raw-layout.txt', layoutEngine.logger.dump());
218
+ throw new RenderError(`Error during layout generation`, 'layout', { cause: useErr });
209
219
  }
210
220
  layoutEngine.printWarnings();
211
221
  showStats && console.log('Layout took:', layoutTimer.lap());
@@ -214,7 +224,7 @@ export async function renderScriptCustom(scriptData, outputPath, options, parseH
214
224
  const renderLogger = new Logger();
215
225
  let svgCanvas;
216
226
  try {
217
- svgCanvas = renderSheetsToSVG(sheetFrames, renderLogger, documentVariable);
227
+ svgCanvas = renderSheetsToSVG(sheetFrames, renderLogger, documentVariable, styles);
218
228
  }
219
229
  catch (err) {
220
230
  throw new RenderError(`Error during SVG generation: ${err}`, 'svg_generation');
@@ -267,7 +277,7 @@ export async function renderScriptCustom(scriptData, outputPath, options, parseH
267
277
  }
268
278
  }
269
279
  catch (err) {
270
- throw new RenderError(`Error during rendering: ${err}`, 'output_generation');
280
+ throw new RenderError(`Error during rendering: ${err}`, 'output_generation', { cause: err });
271
281
  }
272
282
  }
273
283
  return {
@@ -40,14 +40,14 @@ async function regenerateTests(extra = "") {
40
40
  cstFiles.forEach(file => {
41
41
  const svg1 = 'svgs/' + file + '.svg';
42
42
  const svg2 = 'svgs/' + file + '.next.svg';
43
- const cleanedName = file.replace('script', '').replace('.cst', '');
44
- allFiles.push([file, svg1, svg2, cleanedName]);
43
+ const cleanedName = file.replace('script', '')
44
+ .replace('.cst', '')
45
+ .replace('.annotated', '');
46
+ allFiles.push([file, svg1, svg2, Number(cleanedName)]);
45
47
  });
46
48
  const sortedFiles = allFiles.sort((a, b) => {
47
- const nameA = a[3];
48
- const nameB = b[3];
49
- const indexA = Number(nameA);
50
- const indexB = Number(nameB);
49
+ const indexA = a[3];
50
+ const indexB = b[3];
51
51
  if (indexA > indexB) {
52
52
  return 1;
53
53
  }
@@ -1,8 +1,8 @@
1
1
  import { milsToMM } from "../helpers.js";
2
- import { ColorScheme, CustomSymbolParamTextSize, CustomSymbolPinIdSize, CustomSymbolPinTextSize, CustomSymbolRefDesSize, PinTypesList, PortArrowSize, PortPaddingHorizontal, PortPaddingVertical, ReferenceTypes, RenderFlags, SymbolPinSide, defaultFont, defaultPinIdTextSize, defaultPinNameTextSize, defaultSymbolLineWidth, fontDisplayScale } from "../globals.js";
2
+ import { ColorScheme, CustomSymbolParamTextSize, CustomSymbolPinIdSize, CustomSymbolPinTextSize, CustomSymbolRefDesSize, Defaults, PinTypesList, PortArrowSize, PortPaddingHorizontal, PortPaddingVertical, ReferenceTypes, RenderFlags, SymbolPinSide, defaultFont, defaultPinIdTextSize, defaultPinNameTextSize, defaultSymbolLineWidth, fontDisplayScale } from "../globals.js";
3
3
  import { Geometry, GeometryProp, HorizontalAlign, HorizontalAlignProp, Textbox, VerticalAlign, VerticalAlignProp } from "./geometry.js";
4
4
  import { PinTypes } from "../objects/PinTypes.js";
5
- import { RuntimeExecutionError, throwWithContext } from "../utils.js";
5
+ import { RuntimeExecutionError, throwWithContext } from "../errors.js";
6
6
  import { DeclaredReference, UndeclaredReference } from "../objects/types.js";
7
7
  import { NumericValue, numeric, roundValue } from "../objects/NumericValue.js";
8
8
  import { PinId } from "../objects/PinDefinition.js";
@@ -16,6 +16,7 @@ export class SymbolGraphic {
16
16
  width = numeric(-1);
17
17
  height = numeric(-1);
18
18
  labelTexts = new Map();
19
+ styles;
19
20
  constructor() {
20
21
  this.drawing = new SymbolDrawing();
21
22
  }
@@ -52,6 +53,9 @@ export class SymbolGraphic {
52
53
  height: this.height
53
54
  };
54
55
  }
56
+ setStyles(styles) {
57
+ this.styles = styles;
58
+ }
55
59
  size() {
56
60
  return {
57
61
  width: this.width.toNumber(),
@@ -149,7 +153,7 @@ export class SymbolGraphic {
149
153
  }
150
154
  const isHorizontalLabel = finalLabelAngle === 0 || finalLabelAngle === 180;
151
155
  const isVerticalLabel = finalLabelAngle === 90 || finalLabelAngle === -90;
152
- if (useAnchor === HorizontalAlign.Middle) {
156
+ if (useAnchor === HorizontalAlign.Center) {
153
157
  anchorStyle = HorizontalAlignProp.Middle;
154
158
  }
155
159
  else if (useAnchor === HorizontalAlign.Left) {
@@ -158,7 +162,7 @@ export class SymbolGraphic {
158
162
  else if (useAnchor === HorizontalAlign.Right) {
159
163
  anchorStyle = HorizontalAlignProp.End;
160
164
  }
161
- if (useDominantBaseline === VerticalAlign.Middle) {
165
+ if (useDominantBaseline === VerticalAlign.Center) {
162
166
  dominantBaseline = VerticalAlignProp.Central;
163
167
  }
164
168
  else if (useDominantBaseline === VerticalAlign.Top) {
@@ -326,7 +330,7 @@ export class SymbolGraphic {
326
330
  return HorizontalAlign.Left;
327
331
  }
328
332
  else {
329
- return HorizontalAlign.Middle;
333
+ return HorizontalAlign.Center;
330
334
  }
331
335
  }
332
336
  flipDominantBaseline(value) {
@@ -337,7 +341,7 @@ export class SymbolGraphic {
337
341
  return VerticalAlign.Top;
338
342
  }
339
343
  else {
340
- return VerticalAlign.Middle;
344
+ return VerticalAlign.Center;
341
345
  }
342
346
  }
343
347
  }
@@ -354,13 +358,14 @@ export class SymbolText extends SymbolGraphic {
354
358
  drawing.clear();
355
359
  drawing.addTextbox(numeric(0), numeric(0), this.text, {
356
360
  fontSize: this.fontSize,
357
- anchor: HorizontalAlign.Middle,
361
+ anchor: HorizontalAlign.Center,
358
362
  fontWeight: this.fontWeight,
359
363
  });
360
364
  this.drawing = drawing;
361
365
  }
362
366
  }
363
367
  export class SymbolPlaceholder extends SymbolGraphic {
368
+ styles;
364
369
  generateDrawing() {
365
370
  const drawing = this.drawing;
366
371
  drawing.log("=== start generate drawing ===");
@@ -368,16 +373,25 @@ export class SymbolPlaceholder extends SymbolGraphic {
368
373
  drawing.angle = this._angle;
369
374
  drawing.flipX = this._flipX;
370
375
  drawing.flipY = this._flipY;
376
+ const styles = this.styles ?? {
377
+ lineColor: ColorScheme.PinLineColor,
378
+ textColor: ColorScheme.PinNameColor,
379
+ lineWidth: Defaults.LineWidth,
380
+ };
381
+ const defaultLineColor = styles.lineColor;
382
+ const defaultLineWidth = styles.lineWidth;
383
+ const defaultTextColor = styles.textColor;
371
384
  const commands = [
372
385
  [PlaceHolderCommands.units, ['mils'], {}],
373
- [PlaceHolderCommands.lineColor, [ColorScheme.PinLineColor], {}],
374
- [PlaceHolderCommands.textColor, [ColorScheme.PinNameColor], {}],
375
- [PlaceHolderCommands.lineWidth, [numeric(5)], {}],
386
+ [PlaceHolderCommands.lineColor, [defaultLineColor], {}],
387
+ [PlaceHolderCommands.textColor, [defaultTextColor], {}],
388
+ [PlaceHolderCommands.lineWidth, [defaultLineWidth], {}],
389
+ [PlaceHolderCommands.fill, ['none']],
376
390
  ...drawing.getCommands()
377
391
  ];
378
392
  drawing.log('id: ', drawing.id, 'angle: ', this._angle, "commands:", commands.length);
379
- let lineColor = "#333";
380
- let textColor = "#333";
393
+ let lineColor = defaultLineColor;
394
+ let textColor = defaultTextColor;
381
395
  commands.forEach(([commandName, positionParams, keywordParams, ctx]) => {
382
396
  positionParams = positionParams.map(param => {
383
397
  return this.resolveReference(param);
@@ -632,7 +646,7 @@ export class SymbolPlaceholder extends SymbolGraphic {
632
646
  displayPinName && usePinName !== "" && drawing.addLabel(endX.add(pinNameOffsetX), endY.add(pinNameOffsetY), usePinName, {
633
647
  fontSize: numeric(defaultPinNameTextSize),
634
648
  anchor: pinNameAlignment,
635
- vanchor: VerticalAlign.Middle,
649
+ vanchor: VerticalAlign.Center,
636
650
  textColor: pinNameColor,
637
651
  angle: numeric(usePinIdAngle)
638
652
  });
@@ -650,6 +664,9 @@ export class SymbolPlaceholder extends SymbolGraphic {
650
664
  super();
651
665
  this.drawing = drawing;
652
666
  }
667
+ setStyles(styles) {
668
+ this.styles = styles;
669
+ }
653
670
  }
654
671
  export var PlaceHolderCommands;
655
672
  (function (PlaceHolderCommands) {
@@ -666,10 +683,10 @@ export var PlaceHolderCommands;
666
683
  PlaceHolderCommands["line"] = "line";
667
684
  PlaceHolderCommands["label"] = "label";
668
685
  PlaceHolderCommands["path"] = "path";
669
- PlaceHolderCommands["lineWidth"] = "lineWidth";
686
+ PlaceHolderCommands["lineWidth"] = "line_width";
670
687
  PlaceHolderCommands["fill"] = "fill";
671
- PlaceHolderCommands["lineColor"] = "lineColor";
672
- PlaceHolderCommands["textColor"] = "textColor";
688
+ PlaceHolderCommands["lineColor"] = "line_color";
689
+ PlaceHolderCommands["textColor"] = "text_color";
673
690
  PlaceHolderCommands["text"] = "text";
674
691
  PlaceHolderCommands["units"] = "units";
675
692
  PlaceHolderCommands["for"] = "for";
@@ -742,7 +759,7 @@ export class SymbolCustom extends SymbolGraphic {
742
759
  drawing.addLabel(leftPinStart.add(milsToMM(20)), pinY, pin.text, {
743
760
  fontSize: numeric(CustomSymbolPinTextSize),
744
761
  anchor: HorizontalAlign.Left,
745
- vanchor: VerticalAlign.Middle,
762
+ vanchor: VerticalAlign.Center,
746
763
  textColor: ColorScheme.PinNameColor,
747
764
  });
748
765
  drawing.addLabel(leftPinStart.sub(milsToMM(10)), pinY.sub(milsToMM(10)), pin.pinId.toString(), {
@@ -759,7 +776,7 @@ export class SymbolCustom extends SymbolGraphic {
759
776
  drawing.addLabel(rightPinStart.sub(milsToMM(20)), pinY, pin.text, {
760
777
  fontSize: numeric(CustomSymbolPinTextSize),
761
778
  anchor: HorizontalAlign.Right,
762
- vanchor: VerticalAlign.Middle,
779
+ vanchor: VerticalAlign.Center,
763
780
  textColor: ColorScheme.PinNameColor,
764
781
  });
765
782
  drawing.addLabel(rightPinStart.add(milsToMM(10)), pinY.sub(milsToMM(10)), pin.pinId.toString(), {
@@ -776,7 +793,7 @@ export class SymbolCustom extends SymbolGraphic {
776
793
  drawing.addLabel(pinX, topPinStart.add(milsToMM(20)), pin.text, {
777
794
  fontSize: numeric(CustomSymbolPinTextSize),
778
795
  anchor: HorizontalAlign.Right,
779
- vanchor: VerticalAlign.Middle,
796
+ vanchor: VerticalAlign.Center,
780
797
  textColor: ColorScheme.PinNameColor,
781
798
  angle: numeric(-90),
782
799
  });
@@ -795,7 +812,7 @@ export class SymbolCustom extends SymbolGraphic {
795
812
  drawing.addLabel(pinX, bottomPinStart.sub(milsToMM(20)), pin.text, {
796
813
  fontSize: numeric(CustomSymbolPinTextSize),
797
814
  anchor: HorizontalAlign.Left,
798
- vanchor: VerticalAlign.Middle,
815
+ vanchor: VerticalAlign.Center,
799
816
  textColor: ColorScheme.PinNameColor,
800
817
  angle: numeric(-90),
801
818
  });
@@ -878,7 +895,7 @@ export class SymbolCustomModule extends SymbolCustom {
878
895
  drawing.addLabel(leftPinStart.add(this.portWidth).add(milsToMM(20)), pinY, pin.text, {
879
896
  fontSize: numeric(40),
880
897
  anchor: HorizontalAlign.Left,
881
- vanchor: VerticalAlign.Middle,
898
+ vanchor: VerticalAlign.Center,
882
899
  textColor: ColorScheme.PinNameColor,
883
900
  });
884
901
  });
@@ -890,7 +907,7 @@ export class SymbolCustomModule extends SymbolCustom {
890
907
  drawing.addLabel(rightPinStart.sub(this.portWidth).sub(milsToMM(20)), pinY, pin.text, {
891
908
  fontSize: numeric(40),
892
909
  anchor: HorizontalAlign.Right,
893
- vanchor: VerticalAlign.Middle,
910
+ vanchor: VerticalAlign.Center,
894
911
  textColor: ColorScheme.PinNameColor,
895
912
  });
896
913
  });
@@ -902,7 +919,7 @@ export class SymbolCustomModule extends SymbolCustom {
902
919
  drawing.addLabel(pinX, topPinStart.add(this.portWidth).add(milsToMM(20)), pin.text, {
903
920
  fontSize: numeric(40),
904
921
  anchor: HorizontalAlign.Right,
905
- vanchor: VerticalAlign.Middle,
922
+ vanchor: VerticalAlign.Center,
906
923
  textColor: ColorScheme.PinNameColor,
907
924
  angle: numeric(-90),
908
925
  });
@@ -915,7 +932,7 @@ export class SymbolCustomModule extends SymbolCustom {
915
932
  drawing.addLabel(pinX, bottomPinStart.sub(this.portWidth).sub(milsToMM(20)), pin.text, {
916
933
  fontSize: numeric(40),
917
934
  anchor: HorizontalAlign.Left,
918
- vanchor: VerticalAlign.Middle,
935
+ vanchor: VerticalAlign.Center,
919
936
  textColor: ColorScheme.PinNameColor,
920
937
  angle: numeric(-90),
921
938
  });
@@ -464,7 +464,7 @@ function labelPolygonForAnchors(x, y, width, height, hAnchor, vAnchor) {
464
464
  [1, 1],
465
465
  ];
466
466
  }
467
- else if (vAnchor === VerticalAlign.Middle) {
467
+ else if (vAnchor === VerticalAlign.Center) {
468
468
  coordVectors = [
469
469
  [0, -0.5],
470
470
  [0, 0.5],
@@ -490,7 +490,7 @@ function labelPolygonForAnchors(x, y, width, height, hAnchor, vAnchor) {
490
490
  [0, -1],
491
491
  ];
492
492
  }
493
- else if (vAnchor === VerticalAlign.Middle) {
493
+ else if (vAnchor === VerticalAlign.Center) {
494
494
  coordVectors = [
495
495
  [0, -0.5],
496
496
  [0, 0.5],
@@ -507,7 +507,7 @@ function labelPolygonForAnchors(x, y, width, height, hAnchor, vAnchor) {
507
507
  ];
508
508
  }
509
509
  }
510
- else if (hAnchor === HorizontalAlign.Middle) {
510
+ else if (hAnchor === HorizontalAlign.Center) {
511
511
  if (vAnchor === VerticalAlign.Bottom) {
512
512
  coordVectors = [
513
513
  [-0.5, 0],
@@ -516,7 +516,7 @@ function labelPolygonForAnchors(x, y, width, height, hAnchor, vAnchor) {
516
516
  [0.5, 0]
517
517
  ];
518
518
  }
519
- else if (vAnchor === VerticalAlign.Middle) {
519
+ else if (vAnchor === VerticalAlign.Center) {
520
520
  coordVectors = [
521
521
  [-0.5, 0.5],
522
522
  [-0.5, -0.5],
@@ -543,13 +543,13 @@ function labelPolygonForAnchors(x, y, width, height, hAnchor, vAnchor) {
543
543
  export var HorizontalAlign;
544
544
  (function (HorizontalAlign) {
545
545
  HorizontalAlign["Left"] = "left";
546
- HorizontalAlign["Middle"] = "middle";
546
+ HorizontalAlign["Center"] = "center";
547
547
  HorizontalAlign["Right"] = "right";
548
548
  })(HorizontalAlign || (HorizontalAlign = {}));
549
549
  export var VerticalAlign;
550
550
  (function (VerticalAlign) {
551
551
  VerticalAlign["Top"] = "top";
552
- VerticalAlign["Middle"] = "middle";
552
+ VerticalAlign["Center"] = "center";
553
553
  VerticalAlign["Bottom"] = "bottom";
554
554
  })(VerticalAlign || (VerticalAlign = {}));
555
555
  export var HorizontalAlignProp;
@@ -11,9 +11,13 @@ import Matrix, { solve } from "ml-matrix";
11
11
  import { getPinDefinition, PinId } from "../objects/PinDefinition.js";
12
12
  export class NetGraph {
13
13
  logger;
14
+ styles;
14
15
  constructor(logger) {
15
16
  this.logger = logger;
16
17
  }
18
+ setStyles(styles) {
19
+ this.styles = styles;
20
+ }
17
21
  generateLayoutGraph(sequence, nets) {
18
22
  this.print('===== creating graph and populating with nodes =====');
19
23
  let previousNode = null;
@@ -47,6 +51,7 @@ export class NetGraph {
47
51
  let tmpSymbol;
48
52
  if (displayProp instanceof SymbolDrawing) {
49
53
  tmpSymbol = new SymbolPlaceholder(displayProp);
54
+ tmpSymbol.setStyles(this.styles);
50
55
  tmpSymbol.drawing.logger = this.logger;
51
56
  }
52
57
  else {