circuitscript 0.0.37 → 0.1.0

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 (40) hide show
  1. package/dist/cjs/BaseVisitor.js +56 -38
  2. package/dist/cjs/SymbolValidatorVisitor.js +1 -1
  3. package/dist/cjs/antlr/CircuitScriptLexer.js +95 -90
  4. package/dist/cjs/antlr/CircuitScriptParser.js +350 -325
  5. package/dist/cjs/builtinMethods.js +5 -2
  6. package/dist/cjs/draw_symbols.js +63 -45
  7. package/dist/cjs/execute.js +29 -16
  8. package/dist/cjs/globals.js +2 -1
  9. package/dist/cjs/layout.js +14 -26
  10. package/dist/cjs/objects/Frame.js +2 -0
  11. package/dist/cjs/objects/types.js +41 -0
  12. package/dist/cjs/render.js +1 -0
  13. package/dist/cjs/utils.js +25 -1
  14. package/dist/cjs/visitor.js +73 -35
  15. package/dist/esm/BaseVisitor.mjs +56 -38
  16. package/dist/esm/SymbolValidatorVisitor.mjs +1 -1
  17. package/dist/esm/antlr/CircuitScriptLexer.mjs +95 -90
  18. package/dist/esm/antlr/CircuitScriptParser.mjs +350 -325
  19. package/dist/esm/builtinMethods.mjs +5 -2
  20. package/dist/esm/draw_symbols.mjs +67 -47
  21. package/dist/esm/execute.mjs +29 -16
  22. package/dist/esm/globals.mjs +1 -0
  23. package/dist/esm/layout.mjs +13 -26
  24. package/dist/esm/objects/Frame.mjs +2 -0
  25. package/dist/esm/objects/types.mjs +42 -0
  26. package/dist/esm/render.mjs +2 -1
  27. package/dist/esm/utils.mjs +22 -0
  28. package/dist/esm/visitor.mjs +74 -36
  29. package/dist/types/BaseVisitor.d.ts +2 -1
  30. package/dist/types/antlr/CircuitScriptParser.d.ts +3 -0
  31. package/dist/types/draw_symbols.d.ts +11 -5
  32. package/dist/types/execute.d.ts +1 -1
  33. package/dist/types/globals.d.ts +1 -0
  34. package/dist/types/layout.d.ts +1 -0
  35. package/dist/types/objects/Frame.d.ts +3 -1
  36. package/dist/types/objects/types.d.ts +7 -2
  37. package/dist/types/utils.d.ts +3 -0
  38. package/dist/types/visitor.d.ts +1 -0
  39. package/libs/lib.cst +88 -30
  40. package/package.json +1 -1
@@ -3,7 +3,7 @@ import { NumericValue, ParamDefinition } from './objects/ParamDefinition.mjs';
3
3
  import { PinDefinition, PinIdType } from './objects/PinDefinition.mjs';
4
4
  import { PinTypes } from './objects/PinTypes.mjs';
5
5
  import { DeclaredReference, UndeclaredReference } from './objects/types.mjs';
6
- import { BlockTypes, ComponentTypes, FrameType, GlobalDocumentName, NoNetText, ReferenceTypes, WireAutoDirection } from './globals.mjs';
6
+ import { BlockTypes, ComponentTypes, FrameType, GlobalDocumentName, ModuleContainsKeyword, NoNetText, ReferenceTypes, WireAutoDirection } from './globals.mjs';
7
7
  import { PlaceHolderCommands, SymbolDrawingCommands } from './draw_symbols.mjs';
8
8
  import { BaseVisitor } from './BaseVisitor.mjs';
9
9
  import { getPortType } from './utils.mjs';
@@ -152,10 +152,32 @@ export class ParserVisitor extends BaseVisitor {
152
152
  this.setResult(ctx, createdComponent);
153
153
  };
154
154
  visitCreate_graphic_expr = (ctx) => {
155
- const graphicsExpressionsCtx = ctx.graphic_expressions_block();
156
- this.visit(graphicsExpressionsCtx);
157
- const commands = this.getResult(graphicsExpressionsCtx);
158
- const drawing = new SymbolDrawingCommands(commands);
155
+ const ctxId = ctx.ID();
156
+ const paramIds = [];
157
+ if (ctxId !== null) {
158
+ const varName = ctxId.getText();
159
+ paramIds.push(varName);
160
+ this.getExecutor().scope.variables.set(varName, {});
161
+ }
162
+ const executor = this.getExecutor();
163
+ const stack = [...this.executionStack];
164
+ const drawing = new SymbolDrawingCommands(variables => {
165
+ if (variables && paramIds.length > 0) {
166
+ const obj = {};
167
+ variables.forEach((value, key) => {
168
+ obj[key] = value;
169
+ });
170
+ executor.scope.variables.set(paramIds[0], obj);
171
+ }
172
+ const currentStack = this.executionStack.splice(0);
173
+ this.executionStack.push(...stack);
174
+ const graphicsExpressionsCtx = ctx.graphic_expressions_block();
175
+ this.visit(graphicsExpressionsCtx);
176
+ const commands = this.getResult(graphicsExpressionsCtx);
177
+ this.executionStack.splice(0);
178
+ this.executionStack.push(...currentStack);
179
+ return commands;
180
+ });
159
181
  drawing.source = ctx.getText();
160
182
  this.setResult(ctx, drawing);
161
183
  };
@@ -177,7 +199,7 @@ export class ParserVisitor extends BaseVisitor {
177
199
  }
178
200
  return accum;
179
201
  }, []);
180
- accum.push([commandName, positionParams, keywordParams]);
202
+ accum.push([commandName, positionParams, keywordParams, item]);
181
203
  }
182
204
  return accum;
183
205
  }, []);
@@ -297,7 +319,7 @@ export class ParserVisitor extends BaseVisitor {
297
319
  const [firstBlock] = ctxPropertyBlock;
298
320
  this.visit(firstBlock);
299
321
  const [keyName, expressionsBlock] = this.getResult(firstBlock);
300
- if (keyName === 'contains') {
322
+ if (keyName === ModuleContainsKeyword) {
301
323
  createdComponent.moduleContainsExpressions = expressionsBlock;
302
324
  this.expandModuleContains(createdComponent, this.getExecutor().netNamespace);
303
325
  }
@@ -318,7 +340,8 @@ export class ParserVisitor extends BaseVisitor {
318
340
  this.visit(ctxPropertyValueExpr);
319
341
  const keyName = this.getResult(ctxPropertyKeyExpr);
320
342
  const value = this.getResult(ctxPropertyValueExpr);
321
- if (value instanceof UndeclaredReference) {
343
+ if (value instanceof UndeclaredReference && (value.reference.parentValue === undefined
344
+ && value.reference.value === undefined)) {
322
345
  throw value.throwMessage();
323
346
  }
324
347
  const map = new Map();
@@ -374,30 +397,34 @@ export class ParserVisitor extends BaseVisitor {
374
397
  };
375
398
  visitData_expr_with_assignment = (ctx) => {
376
399
  let component = null;
400
+ let componentCtx = null;
377
401
  const ctxDataExpr = ctx.data_expr();
378
402
  const ctxAssignmentExpr = ctx.assignment_expr();
379
403
  if (ctxDataExpr) {
380
404
  this.visit(ctxDataExpr);
381
405
  component = this.getResult(ctxDataExpr);
406
+ componentCtx = ctxDataExpr;
382
407
  if (component === null || component === undefined) {
383
- throw "Could not find component: " + ctxDataExpr.getText();
408
+ this.throwWithContext(ctxDataExpr, "Could not find component: " + ctxDataExpr.getText());
384
409
  }
385
410
  }
386
411
  else if (ctxAssignmentExpr) {
387
412
  this.visit(ctxAssignmentExpr);
388
413
  component = this.getResult(ctxAssignmentExpr);
414
+ componentCtx = ctxAssignmentExpr;
389
415
  }
390
416
  if (component instanceof ClassComponent
391
417
  && component.copyProp) {
392
418
  component = this.getExecutor().copyComponent(component);
393
419
  }
394
- if (component instanceof DeclaredReference
395
- && component.found
396
- && component.trailers
397
- && component.trailers.length > 0
398
- && component.trailers[0] === 'contains') {
399
- component = component.value;
400
- this.placeModuleContains(component);
420
+ if (component instanceof UndeclaredReference) {
421
+ const { reference: { trailers = [], parentValue = null } } = component;
422
+ if (parentValue instanceof ClassComponent
423
+ && trailers.length > 0
424
+ && trailers[0] === ModuleContainsKeyword) {
425
+ component = parentValue;
426
+ this.placeModuleContains(component);
427
+ }
401
428
  }
402
429
  if (component && component instanceof ClassComponent) {
403
430
  const modifiers = ctx.component_modifier_expr();
@@ -431,19 +458,7 @@ export class ParserVisitor extends BaseVisitor {
431
458
  shouldIgnoreWireOrientation = true;
432
459
  }
433
460
  else if (modifierText === 'anchor') {
434
- if (component.displayProp
435
- && component.displayProp instanceof SymbolDrawingCommands) {
436
- const commands = (component.displayProp)
437
- .getCommands();
438
- commands.forEach(command => {
439
- const positionParams = command[1];
440
- const keywordParams = command[2];
441
- if (command[0] === PlaceHolderCommands.label
442
- && positionParams[0] === 'value') {
443
- keywordParams.set('anchor', result);
444
- }
445
- });
446
- }
461
+ component.setParam('anchor', result);
447
462
  }
448
463
  if (shouldIgnoreWireOrientation) {
449
464
  component.useWireOrientationAngle = false;
@@ -462,7 +477,7 @@ export class ParserVisitor extends BaseVisitor {
462
477
  }
463
478
  else {
464
479
  const undeclaredRef = component;
465
- throw 'Invalid component: ' + undeclaredRef.reference.name;
480
+ this.throwWithContext(componentCtx, 'Invalid component: ' + undeclaredRef.reference.name);
466
481
  }
467
482
  }
468
483
  this.setResult(ctx, [component, pinValue]);
@@ -525,6 +540,9 @@ export class ParserVisitor extends BaseVisitor {
525
540
  if (typeof value === "boolean") {
526
541
  value = !value;
527
542
  }
543
+ else if (typeof value === "number") {
544
+ value = (value === 0) ? false : true;
545
+ }
528
546
  else {
529
547
  throw "Failed to do Not operator";
530
548
  }
@@ -822,7 +840,11 @@ export class ParserVisitor extends BaseVisitor {
822
840
  const ctxDataExpr = ctx.data_expr();
823
841
  this.visit(ctxDataExpr);
824
842
  const result = this.getResult(ctxDataExpr);
825
- if (result) {
843
+ let resultValue = result;
844
+ if (result instanceof UndeclaredReference) {
845
+ resultValue = false;
846
+ }
847
+ if (resultValue) {
826
848
  this.visit(ctx.expressions_block());
827
849
  }
828
850
  else {
@@ -928,10 +950,22 @@ export class ParserVisitor extends BaseVisitor {
928
950
  this.visit(data_expr);
929
951
  const value = this.getResult(data_expr);
930
952
  if (value instanceof UndeclaredReference) {
931
- throw value.throwMessage();
953
+ this.throwWithContext(data_expr, value.throwMessage());
954
+ }
955
+ else if (value instanceof DeclaredReference) {
956
+ return this.resolveDataValue(value);
932
957
  }
933
958
  return value;
934
959
  }
960
+ resolveDataValue(reference) {
961
+ const { value } = reference;
962
+ if (value instanceof NumericValue) {
963
+ return value.toDisplayString();
964
+ }
965
+ else {
966
+ return value;
967
+ }
968
+ }
935
969
  pinTypes = [
936
970
  PinTypes.Any,
937
971
  PinTypes.IO,
@@ -1131,10 +1165,14 @@ export class ParserVisitor extends BaseVisitor {
1131
1165
  let frameComponent = null;
1132
1166
  if (document && document[FrameParamKeys.SheetType]) {
1133
1167
  frameComponent = document[FrameParamKeys.SheetType];
1134
- baseScope.frames.forEach(item => {
1135
- if (item.frameType === FrameType.Sheet) {
1136
- item.parameters.set(FrameParamKeys.SheetType, frameComponent);
1137
- }
1168
+ const sheets = baseScope.frames.filter(item => {
1169
+ return item.frameType === FrameType.Sheet;
1170
+ });
1171
+ const totalSheets = sheets.length;
1172
+ sheets.forEach((item, index) => {
1173
+ item.parameters.set(FrameParamKeys.SheetType, frameComponent);
1174
+ item.parameters.set(FrameParamKeys.SheetNumber, index + 1);
1175
+ item.parameters.set(FrameParamKeys.SheetTotal, totalSheets);
1138
1176
  });
1139
1177
  }
1140
1178
  return {
@@ -54,7 +54,7 @@ export declare class BaseVisitor extends CircuitScriptVisitor<ComplexType | Refe
54
54
  visitArrayExpr: (ctx: ArrayExprContext) => void;
55
55
  protected setResult(ctx: ParserRuleContext, value: any): void;
56
56
  protected getResult(ctx: ParserRuleContext): any;
57
- protected handleImportFile(name: string, throwErrors?: boolean): {
57
+ protected handleImportFile(name: string, throwErrors?: boolean, ctx?: ParserRuleContext | null): {
58
58
  hasError: boolean;
59
59
  hasParseError: boolean;
60
60
  pathExists: boolean;
@@ -67,5 +67,6 @@ export declare class BaseVisitor extends CircuitScriptVisitor<ComplexType | Refe
67
67
  protected getInstanceParam<T>(object: ClassComponent, trailers: string[]): T;
68
68
  protected enterNewChildContext(executionStack: ExecutionContext[], parentContext: ExecutionContext, executionContextName: string, options: CFunctionOptions, funcDefinedParameters: FunctionDefinedParameter[], passedInParameters: CallableParameter[]): ExecutionContext;
69
69
  protected prepareStringValue(value: string): string;
70
+ protected throwWithContext(context: ParserRuleContext, message: string): void;
70
71
  }
71
72
  export type OnErrorCallback = (line: number, column: number, message: string, e: any | undefined) => void;
@@ -708,6 +708,9 @@ export declare class Create_graphic_exprContext extends antlr.ParserRuleContext
708
708
  Create(): antlr.TerminalNode;
709
709
  Graphic(): antlr.TerminalNode;
710
710
  graphic_expressions_block(): Graphic_expressions_blockContext;
711
+ OPEN_PAREN(): antlr.TerminalNode | null;
712
+ ID(): antlr.TerminalNode | null;
713
+ CLOSE_PAREN(): antlr.TerminalNode | null;
711
714
  get ruleIndex(): number;
712
715
  accept<Result>(visitor: CircuitScriptVisitor<Result>): Result | null;
713
716
  }
@@ -2,6 +2,7 @@ import { G } from "@svgdotjs/svg.js";
2
2
  import { Feature, GeometryProp, HorizontalAlign, LabelStyle, Textbox, VerticalAlign } from "./geometry.js";
3
3
  import { Logger } from "./logger.js";
4
4
  import { PinTypes } from "./objects/PinTypes.js";
5
+ import { ParserRuleContext } from "antlr4ng";
5
6
  export declare abstract class SymbolGraphic {
6
7
  drawPortsName: boolean;
7
8
  displayBounds: boolean;
@@ -12,6 +13,7 @@ export declare abstract class SymbolGraphic {
12
13
  width: number;
13
14
  height: number;
14
15
  labelTexts: Map<string, string>;
16
+ constructor();
15
17
  get angle(): number;
16
18
  set angle(value: number);
17
19
  get flipX(): number;
@@ -40,8 +42,6 @@ export declare abstract class SymbolGraphic {
40
42
  protected drawLabels(group: G): void;
41
43
  flipTextAnchor(value: HorizontalAlign): HorizontalAlign;
42
44
  flipDominantBaseline(value: VerticalAlign): VerticalAlign;
43
- setLabelValue(labelId: string, labelValue: string): void;
44
- getLabelValue(labelId: string): string;
45
45
  }
46
46
  export declare function SymbolFactory(name: string): SymbolGraphic;
47
47
  export declare class SymbolPointHidden extends SymbolGraphic {
@@ -56,6 +56,7 @@ export declare class SymbolText extends SymbolGraphic {
56
56
  }
57
57
  export declare class SymbolPlaceholder extends SymbolGraphic {
58
58
  generateDrawing(): void;
59
+ private resolveReference;
59
60
  parseLabelStyle(keywordParams: Map<string, any>): {
60
61
  [key: string]: any;
61
62
  };
@@ -113,6 +114,7 @@ export declare class SymbolDrawing {
113
114
  flipY: number;
114
115
  mainOrigin: [number, number];
115
116
  logger: Logger;
117
+ variables: Map<string, any>;
116
118
  clear(): void;
117
119
  log(...params: any[]): void;
118
120
  addLine(startX: number, startY: number, endX: number, endY: number): SymbolDrawing;
@@ -125,7 +127,7 @@ export declare class SymbolDrawing {
125
127
  addTriangle(startX: number, startY: number, endX: number, endY: number, width: number): SymbolDrawing;
126
128
  addRect2(x: number, y: number, x2: number, y2: number): SymbolDrawing;
127
129
  addLabel(x: number, y: number, textValue: string, style: LabelStyle): SymbolDrawing;
128
- addLabelId(id: string, x: number, y: number, textValue: string, style: LabelStyle): SymbolDrawing;
130
+ addLabelMils(x: number, y: number, textValue: string, style: LabelStyle): SymbolDrawing;
129
131
  addTextbox(x: number, y: number, textValue: string, style: LabelStyle): SymbolDrawing;
130
132
  addModulePort(x: number, y: number, width: number, height: number, portType?: PinTypes, scaleX?: number): SymbolDrawing;
131
133
  addPath(...pathParts: any): SymbolDrawing;
@@ -162,12 +164,16 @@ export declare class SymbolDrawing {
162
164
  export type GraphicExprCommand = [
163
165
  commandName: string,
164
166
  positionParams: any[],
165
- keywordParams: Map<string, any>
167
+ keywordParams: Map<string, any>,
168
+ ctx: ParserRuleContext
166
169
  ];
167
170
  export declare class SymbolDrawingCommands extends SymbolDrawing {
168
171
  id: string;
169
172
  private commands;
170
- constructor(commands: GraphicExprCommand[]);
173
+ paramIds: string[];
174
+ callback: (variables: Map<string, any>) => GraphicExprCommand[];
175
+ constructor(callback: (variables: Map<string, any>) => GraphicExprCommand[]);
176
+ runCommands(): void;
171
177
  getCommands(): GraphicExprCommand[];
172
178
  clone(): SymbolDrawingCommands;
173
179
  }
@@ -65,7 +65,7 @@ export declare class ExecutionContext {
65
65
  createFunction(functionName: string, __runFunc: CFunction): void;
66
66
  hasFunction(functionName: string): boolean;
67
67
  getFunction(functionName: string): CFunction;
68
- resolveVariable(executionStack: ExecutionContext[], idName: string): DeclaredReference;
68
+ resolveVariable(executionStack: ExecutionContext[], idName: string, trailers?: string[]): DeclaredReference;
69
69
  callFunction(functionName: string, functionParams: CallableParameter[], executionStack: ExecutionContext[], netNamespace: string): CFunctionResult;
70
70
  mergeScope(childScope: ExecutionScope, namespace: string): void;
71
71
  addWire(segments: [string, (number | UnitDimension)?][]): void;
@@ -87,6 +87,7 @@ export declare enum FrameType {
87
87
  Frame = 1,
88
88
  Sheet = 2
89
89
  }
90
+ export declare const ModuleContainsKeyword = "contains";
90
91
  export declare const GlobalDocumentName = "document";
91
92
  export declare const RenderFlags: {
92
93
  ShowElementFrames: boolean;
@@ -60,6 +60,7 @@ type EdgeValue = [
60
60
  priority: number
61
61
  ];
62
62
  type RenderItem = RenderComponent | RenderWire | RenderText;
63
+ export declare function applyComponentParamsToSymbol(component: ClassComponent, symbol: SymbolGraphic): void;
63
64
  export declare function getBounds(components: (RenderComponent | RenderText)[], wires: RenderWire[], junctions: RenderJunction[], frames: RenderFrame[]): BoundBox;
64
65
  export declare class RenderObject {
65
66
  x: number;
@@ -13,7 +13,9 @@ export declare enum FrameParamKeys {
13
13
  Width = "width",
14
14
  Height = "height",
15
15
  PaperSize = "paper_size",
16
- SheetType = "sheet_type"
16
+ SheetType = "sheet_type",
17
+ SheetNumber = "sheet_number",
18
+ SheetTotal = "sheet_total"
17
19
  }
18
20
  export declare enum FramePlotDirection {
19
21
  Row = "row",
@@ -40,22 +40,27 @@ export declare class UndeclaredReference {
40
40
  reference: ReferenceType;
41
41
  constructor(reference: ReferenceType);
42
42
  throwMessage(): string;
43
+ toString(): string;
44
+ nameString(): string;
43
45
  }
44
46
  export declare class DeclaredReference {
45
47
  found: boolean;
46
48
  name?: string;
47
49
  trailers?: string[];
48
- type?: string;
50
+ type?: 'value' | 'instance' | 'variable';
49
51
  value?: any;
52
+ parentValue?: any;
50
53
  constructor(refType: ReferenceType);
51
54
  toString(): string;
55
+ toDisplayString(): string;
52
56
  }
53
57
  export type ReferenceType = {
54
58
  found: boolean;
55
59
  name?: string;
56
60
  trailers?: string[];
57
- type?: string;
61
+ type?: 'value' | 'instance' | 'variable';
58
62
  value?: any;
63
+ parentValue?: any;
59
64
  };
60
65
  export declare enum ParseSymbolType {
61
66
  Variable = "variable",
@@ -1,3 +1,4 @@
1
+ import { ParserRuleContext } from "antlr4ng";
1
2
  import { ClassComponent } from "./objects/ClassComponent";
2
3
  export declare class SimpleStopwatch {
3
4
  startTime: Date;
@@ -20,3 +21,5 @@ export declare function getBoundsSize(bounds: BoundBox): {
20
21
  };
21
22
  export declare function getPortType(component: ClassComponent): string | null;
22
23
  export declare function roundValue(value: number): number;
24
+ export declare function throwWithContext(context: ParserRuleContext, message: string): void;
25
+ export declare function combineMaps(map1: Map<string, any>, map2: Map<string, any>): Map<string, any>;
@@ -55,6 +55,7 @@ export declare class ParserVisitor extends BaseVisitor {
55
55
  visitWhile_expr: (ctx: While_exprContext) => void;
56
56
  visitFor_expr: (ctx: For_exprContext) => void;
57
57
  private resolveDataExpr;
58
+ private resolveDataValue;
58
59
  pinTypes: PinTypes[];
59
60
  private parseCreateComponentPins;
60
61
  private parseCreateModulePorts;
package/libs/lib.cst CHANGED
@@ -5,10 +5,10 @@ def net(net_name):
5
5
  pins: 1
6
6
  copy: true
7
7
  angle: -90
8
- display: create graphic:
8
+ display: create graphic (params):
9
9
  hline: -50, 0, 100
10
10
  vpin: 1, 0, 50, -50, display_pin_id=false
11
- label: "net_name", 0, -15, net_name, fontSize=50, anchor="middle"
11
+ label: params.net_name, 0, -15, fontSize=50, anchor="middle"
12
12
  type: "net"
13
13
  params:
14
14
  net_name: net_name
@@ -19,10 +19,10 @@ def supply(net_name):
19
19
  pins: 1
20
20
  copy: true
21
21
  angle: -90
22
- display: create graphic:
22
+ display: create graphic (params):
23
23
  hline: -50, 0, 100
24
24
  vpin: 1, 0, 50, -50, display_pin_id=false
25
- label: "net_name", 0, -15, net_name, fontSize=50, anchor="middle"
25
+ label: params.net_name, 0, -15, fontSize=50, anchor="middle"
26
26
  type: "net"
27
27
  params:
28
28
  net_name: net_name
@@ -33,9 +33,9 @@ def label(value, anchor="left"):
33
33
  pins: 1
34
34
  copy: true
35
35
  followWireOrientation: false
36
- display: create graphic:
36
+ display: create graphic (params):
37
37
  textColor: "#222"
38
- label: "value", 0, -10, "?", fontSize=50, anchor=anchor
38
+ label: params.value, 0, -10, fontSize=50, anchor=anchor
39
39
  pin: 1, 0, 0, 0, 0, display_pin_id=false
40
40
  type: "label"
41
41
  params:
@@ -47,9 +47,9 @@ def port(value, portType="input"):
47
47
  return create component:
48
48
  pins: 1
49
49
  copy: true
50
- display: create graphic:
50
+ display: create graphic (params):
51
51
  textColor: "#222"
52
- label: "value", 0, 0, "?", fontSize=40, anchor="left", vanchor="middle", portType=portType
52
+ label: params.value, 0, 0, fontSize=40, anchor="left", vanchor="middle", portType=portType
53
53
  pin: 1, 0, 0, 0, 0, display_pin_id=false
54
54
  type: "port"
55
55
  params:
@@ -63,12 +63,12 @@ def res(value):
63
63
 
64
64
  return create component:
65
65
  pins: 2
66
- display: create graphic:
66
+ display: create graphic (params):
67
67
  rect: 0, 0, width, height
68
68
  hpin: 1, -width/2 - 30, 0, 30
69
69
  hpin: 2, width/2 + 30, 0, -30
70
- label: "refdes", -width/2, -height/2 - 20 , "?", fontSize=50, anchor="left"
71
- label: "value", 0, 4, value, fontSize=30, anchor="middle", vanchor="middle"
70
+ label: params.refdes, -width/2, -height/2 - 20, fontSize=50, anchor="left"
71
+ label: params.value, 0, 4, fontSize=30, anchor="middle", vanchor="middle"
72
72
  type: "res"
73
73
  params:
74
74
  value: value
@@ -82,14 +82,14 @@ def cap(value):
82
82
  return create component:
83
83
  pins: 2
84
84
  angle: 90
85
- display: create graphic:
85
+ display: create graphic (params):
86
86
  lineWidth: 13
87
87
  hline: -width/2, 20, width
88
88
  hline: -width/2, -20, width
89
89
  vpin: 1, 0, -100, 80
90
90
  vpin: 2, 0, 100, -80
91
- label: "refdes", 80, -30, "?", fontSize=50, anchor="left", vanchor="middle"
92
- label: "value", 80, 30, value, fontSize=50, anchor = "left", vanchor="middle"
91
+ label: params.refdes, 80, -30, fontSize=50, anchor="left", vanchor="middle"
92
+ label: params.value, 80, 30, fontSize=50, anchor = "left", vanchor="middle"
93
93
  type: "cap"
94
94
  params:
95
95
  value: value
@@ -103,15 +103,15 @@ def ind(value):
103
103
  return create component:
104
104
  pins: 2
105
105
  type: "ind"
106
- display: create graphic:
106
+ display: create graphic (params):
107
107
  arc: -15, 0, 5, 180, 360
108
108
  arc: -5, 0, 5, 180, 360
109
109
  arc: 5, 0, 5, 180, 360
110
110
  arc: 15, 0, 5, 180, 360
111
111
  hpin: 1, -width/2 - 20, 0, 20
112
112
  hpin: 2, width/2 + 20, 0, -20
113
- label: ("refdes", -width/2, -height/2 -5 , "?", fontSize=50, anchor="left")
114
- label: ("value", 0, 10, value, fontSize=50, anchor="middle", vanchor="middle")
113
+ label: (params.refdes, -width/2, -height/2 -5 , fontSize=50, anchor="left")
114
+ label: (params.value, 0, 10, fontSize=50, anchor="middle", vanchor="middle")
115
115
  params:
116
116
  value: value
117
117
 
@@ -124,12 +124,12 @@ def diode():
124
124
  return create component:
125
125
  pins: 2
126
126
  type: "diode"
127
- display: create graphic:
127
+ display: create graphic (params):
128
128
  triangle: -width/2, 0, width/2, 0, height
129
129
  vline: width/2, -height/2, height
130
130
  hpin: 1, -width/2-100, 0, 100 # anode
131
131
  hpin: 2, width/2 + 100, 0, -100 # cathode
132
- label: "refdes", 0, -100, "?", fontSize=50, anchor="middle", vanchor="top"
132
+ label: params.refdes, 0, -100, fontSize=50, anchor="middle", vanchor="top"
133
133
 
134
134
  def led(color):
135
135
  width = 100
@@ -140,7 +140,7 @@ def led(color):
140
140
  1: "cathode"
141
141
  2: "anode"
142
142
  type: "diode"
143
- display: create graphic:
143
+ display: create graphic (params):
144
144
  triangle: -width/2, 0, width/2, 0, height
145
145
  vline: width/2, -height/2, height
146
146
  path: ("M", 70, 30, "L", 130, 90,
@@ -149,10 +149,11 @@ def led(color):
149
149
  "M", 180, 60, "L", 180, 90, "L", 150, 90)
150
150
  hpin: 1, -width/2-100, 0, 100 # anode
151
151
  hpin: 2, width/2 + 100, 0, -100 # cathode
152
- label: "refdes", 0, -100, "?", fontSize=50, anchor="middle", vanchor="top"
153
- label: "color", 0, 100, color, fontSize=40, anchor="middle", vanchor="bottom"
152
+ label: params.refdes, 0, -100, fontSize=50, anchor="middle", vanchor="top"
153
+ label: params.color, 0, 100, fontSize=40, anchor="middle", vanchor="bottom"
154
154
  params:
155
155
  size: "0603"
156
+ color: color
156
157
  footprint: "LED_SMD:LED_0603_1608Metric_Pad1.05x0.95mm_HandSolder"
157
158
 
158
159
 
@@ -162,12 +163,12 @@ def cgnd():
162
163
  pins: 1
163
164
  copy: true
164
165
  angle: 90
165
- display: create graphic:
166
+ display: create graphic (params):
166
167
  hline: -15, 0, 30
167
168
  hline: -10, 5, 20
168
169
  hline: -5, 10, 10
169
170
  vpin: 1, 0, -10, 10, display_pin_id=false
170
- label: "net_name", 0, 22, net_name, fontSize=50, anchor="middle"
171
+ label: params.net_name, 0, 22, fontSize=50, anchor="middle"
171
172
  type: "net"
172
173
  params:
173
174
  net_name: net_name
@@ -181,10 +182,10 @@ def dgnd(net_name="GND"):
181
182
  pins: 1
182
183
  copy: true
183
184
  angle: 90
184
- display: create graphic:
185
+ display: create graphic (params):
185
186
  triangle: 0, 0, 0, height, width
186
187
  vpin: 1, 0, -50, 50, display_pin_id=false
187
- label: "net_name", 0, height + 50, net_name, fontSize=50, anchor="middle", vanchor="middle"
188
+ label: params.net_name, 0, height + 50, fontSize=50, anchor="middle", vanchor="middle"
188
189
  type: "net"
189
190
  params:
190
191
  net_name: net_name
@@ -230,6 +231,9 @@ def sheet_generator(paper_size_name, paper_width, paper_height, margin_x, margin
230
231
  vertical_1 = margin_y - inner_frame_margin
231
232
  vertical_2 = paper_height - margin_y + inner_frame_margin
232
233
 
234
+ inner_width = paper_width - 2 * margin_x
235
+ inner_height = paper_height - 2 * margin_y
236
+
233
237
  tmp_height = paper_height - margin_y * 2 + inner_frame_margin * 2
234
238
  tmp_y = margin_y - inner_frame_margin
235
239
 
@@ -244,9 +248,19 @@ def sheet_generator(paper_size_name, paper_width, paper_height, margin_x, margin
244
248
  ratio_x = 1 / num_columns
245
249
  ratio_y = 1 / num_rows
246
250
 
251
+ title_block_width = 2000
252
+ title_block_height = 350
253
+
254
+ # center of title_block
255
+ title_block_x = margin_x + inner_width - title_block_width
256
+ title_block_y = margin_y + inner_height - title_block_height
257
+
258
+ title_block_x2 = title_block_x + title_block_width
259
+ title_block_y2 = title_block_y + title_block_height
260
+
247
261
  return create component:
248
262
  type: "frame"
249
- display: create graphic:
263
+ display: create graphic (params):
250
264
  fill: "none"
251
265
 
252
266
  # outer rect
@@ -255,7 +269,7 @@ def sheet_generator(paper_size_name, paper_width, paper_height, margin_x, margin
255
269
 
256
270
  # inner rect
257
271
  lineColor: "#111111"
258
- rect: paper_width/2, paper_height/2, paper_width - 2 * margin_x, paper_height - 2 * margin_y
272
+ rect: paper_width/2, paper_height/2, inner_width, inner_height
259
273
 
260
274
  rect: (paper_width/2, paper_height/2,
261
275
  paper_width - 2 * margin_x + inner_frame_margin * 2,
@@ -300,7 +314,46 @@ def sheet_generator(paper_size_name, paper_width, paper_height, margin_x, margin
300
314
  anchor: "middle"
301
315
  vanchor: "middle"
302
316
 
317
+ # Draw title frame
318
+ text:
319
+ content: "Size: " + paper_size_name
320
+ offset: title_block_x + 20, title_block_y2 - 30
321
+ anchor: "left"
322
+ vanchor: "bottom"
323
+
324
+ text:
325
+ content: "Sheet: " + params.sheet_number + "/" + params.sheet_total
326
+ anchor: "left"
327
+ vanchor: "bottom"
328
+ offset: title_block_x + title_block_width / 2 + 20, title_block_y2 - 30
329
+
330
+ hline: title_block_x, title_block_y2 - 100, title_block_width
331
+ vline: title_block_x + title_block_width / 2, title_block_y2, -100
332
+
333
+ text:
334
+ content: "Rev: " + params.revision
335
+ anchor: "left"
336
+ vanchor: "bottom"
337
+ offset: title_block_x + 20 , title_block_y2 - 130
338
+
339
+ hline: title_block_x, title_block_y2 - 200, title_block_width
340
+
341
+ text:
342
+ content: params.title
343
+ offset: title_block_x + 20, title_block_y2 - 240
344
+ bold: true
345
+ fontSize: 60
346
+ anchor: "left"
347
+ vanchor: "bottom"
348
+
349
+ rect: title_block_x + title_block_width / 2, title_block_y + title_block_height / 2, title_block_width, title_block_height
350
+
303
351
  params:
352
+ title: "Sheet title"
353
+ revision: "V1"
354
+ sheet_number: 1
355
+ sheet_total: 1
356
+
304
357
  paper_size: paper_size_name
305
358
  paper_width: paper_width
306
359
  paper_height: paper_height
@@ -350,9 +403,14 @@ def sheet_A5():
350
403
 
351
404
  return sheet_generator("A5", paper_width, paper_height, margin, margin, range(1, 5), ["A", "B", "C"])
352
405
 
353
- def sheet_A6():
406
+ def sheet_A6(revision="V1"):
354
407
  paper_width = toMils(148)
355
408
  paper_height = toMils(105)
356
409
  margin = 400
357
410
 
358
- return sheet_generator("A6", paper_width, paper_height, margin, margin, range(1, 4), ["A", "B"])
411
+ tmp_sheet = sheet_generator("A6", paper_width, paper_height, margin, margin, range(1, 4), ["A", "B"])
412
+ tmp_sheet.revision = revision
413
+
414
+ return tmp_sheet
415
+
416
+ document.sheet_type = sheet_A4()